Update to 3.4-final.
[linux-flexiantxendom0-3.2.10.git] / drivers / xen / tpmback / common.h
1 /******************************************************************************
2  * drivers/xen/tpmback/common.h
3  */
4
5 #ifndef __TPM__BACKEND__COMMON_H__
6 #define __TPM__BACKEND__COMMON_H__
7
8 #include <linux/module.h>
9 #include <linux/interrupt.h>
10 #include <linux/mm.h>
11 #include <linux/slab.h>
12 #include <xen/xenbus.h>
13 #include <xen/interface/event_channel.h>
14 #include <xen/interface/io/tpmif.h>
15
16 #define DPRINTK(_f, _a...)                      \
17         pr_debug("(file=%s, line=%d) " _f,      \
18                  __FILE__ , __LINE__ , ## _a )
19
20 struct backend_info
21 {
22         struct xenbus_device *dev;
23
24         /* our communications channel */
25         struct tpmif_st *tpmif;
26
27         long int frontend_id;
28         long int instance; // instance of TPM
29         u8 is_instance_set;// whether instance number has been set
30
31         /* watch front end for changes */
32         struct xenbus_watch backend_watch;
33 };
34
35 typedef struct tpmif_st {
36         struct list_head tpmif_list;
37         /* Unique identifier for this interface. */
38         domid_t domid;
39         unsigned int handle;
40
41         /* Physical parameters of the comms window. */
42         unsigned int irq;
43
44         /* The shared rings and indexes. */
45         tpmif_tx_interface_t *tx;
46         struct vm_struct *tx_area;
47
48         /* Miscellaneous private stuff. */
49         enum { DISCONNECTED, DISCONNECTING, CONNECTED } status;
50         int active;
51
52         struct tpmif_st *hash_next;
53         struct list_head list;  /* scheduling list */
54         atomic_t refcnt;
55
56         struct backend_info *bi;
57
58         struct page **mmap_pages;
59
60         char devname[20];
61 } tpmif_t;
62
63 void tpmif_disconnect_complete(tpmif_t * tpmif);
64 tpmif_t *tpmif_find(domid_t domid, struct backend_info *bi);
65 int tpmif_interface_init(void);
66 void tpmif_interface_exit(void);
67 void tpmif_schedule_work(tpmif_t * tpmif);
68 void tpmif_deschedule_work(tpmif_t * tpmif);
69 int tpmif_xenbus_init(void);
70 void tpmif_xenbus_exit(void);
71 int tpmif_map(tpmif_t *, grant_ref_t, evtchn_port_t);
72 irqreturn_t tpmif_be_int(int irq, void *dev_id);
73
74 long int tpmback_get_instance(struct backend_info *bi);
75
76 int vtpm_release_packets(tpmif_t * tpmif, int send_msgs);
77
78
79 #define tpmif_get(_b) (atomic_inc(&(_b)->refcnt))
80 #define tpmif_put(_b)                                   \
81         do {                                            \
82                 if (atomic_dec_and_test(&(_b)->refcnt)) \
83                         tpmif_disconnect_complete(_b);  \
84         } while (0)
85
86 extern int num_frontends;
87
88 static inline unsigned long idx_to_kaddr(tpmif_t *t, unsigned int idx)
89 {
90         return (unsigned long)pfn_to_kaddr(page_to_pfn(t->mmap_pages[idx]));
91 }
92
93 #endif /* __TPMIF__BACKEND__COMMON_H__ */