a698e01c648d3992cb9ad2016716e9ab6786b598
[linux-2.6.git] / drivers / xen / blkback / common.h
1
2 #ifndef __BLKIF__BACKEND__COMMON_H__
3 #define __BLKIF__BACKEND__COMMON_H__
4
5 #include <linux/config.h>
6 #include <linux/version.h>
7 #include <linux/module.h>
8 #include <linux/rbtree.h>
9 #include <linux/interrupt.h>
10 #include <linux/slab.h>
11 #include <linux/blkdev.h>
12 #include <asm/io.h>
13 #include <asm/setup.h>
14 #include <asm/pgalloc.h>
15 #include <asm-xen/ctrl_if.h>
16 #include <asm-xen/hypervisor.h>
17 #include <asm-xen/xen-public/io/blkif.h>
18 #include <asm-xen/xen-public/io/ring.h>
19
20 #if 0
21 #define ASSERT(_p) \
22     if ( !(_p) ) { printk("Assertion '%s' failed, line %d, file %s", #_p , \
23     __LINE__, __FILE__); *(int*)0=0; }
24 #define DPRINTK(_f, _a...) printk(KERN_ALERT "(file=%s, line=%d) " _f, \
25                            __FILE__ , __LINE__ , ## _a )
26 #else
27 #define ASSERT(_p) ((void)0)
28 #define DPRINTK(_f, _a...) ((void)0)
29 #endif
30
31 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
32 typedef struct rb_root rb_root_t;
33 typedef struct rb_node rb_node_t;
34 #else
35 struct block_device;
36 #endif
37
38 typedef struct blkif_st {
39     /* Unique identifier for this interface. */
40     domid_t           domid;
41     unsigned int      handle;
42     /* Physical parameters of the comms window. */
43     unsigned long     shmem_frame;
44     unsigned int      evtchn;
45     int               irq;
46     /* Comms information. */
47     blkif_back_ring_t blk_ring;
48     /* VBDs attached to this interface. */
49     rb_root_t         vbd_rb;        /* Mapping from 16-bit vdevices to VBDs.*/
50     spinlock_t        vbd_lock;      /* Protects VBD mapping. */
51     /* Private fields. */
52     enum { DISCONNECTED, DISCONNECTING, CONNECTED } status;
53     /*
54      * DISCONNECT response is deferred until pending requests are ack'ed.
55      * We therefore need to store the id from the original request.
56      */
57     u8               disconnect_rspid;
58 #ifdef CONFIG_XEN_BLKDEV_TAP_BE
59     /* Is this a blktap frontend */
60     unsigned int     is_blktap;
61 #endif
62     struct blkif_st *hash_next;
63     struct list_head blkdev_list;
64     spinlock_t       blk_ring_lock;
65     atomic_t         refcnt;
66
67     struct work_struct work;
68 } blkif_t;
69
70 void blkif_create(blkif_be_create_t *create);
71 void blkif_destroy(blkif_be_destroy_t *destroy);
72 void blkif_connect(blkif_be_connect_t *connect);
73 int  blkif_disconnect(blkif_be_disconnect_t *disconnect, u8 rsp_id);
74 void blkif_disconnect_complete(blkif_t *blkif);
75 blkif_t *blkif_find_by_handle(domid_t domid, unsigned int handle);
76 #define blkif_get(_b) (atomic_inc(&(_b)->refcnt))
77 #define blkif_put(_b)                             \
78     do {                                          \
79         if ( atomic_dec_and_test(&(_b)->refcnt) ) \
80             blkif_disconnect_complete(_b);        \
81     } while (0)
82
83 void vbd_create(blkif_be_vbd_create_t *create); 
84 void vbd_destroy(blkif_be_vbd_destroy_t *delete); 
85 int vbd_probe(blkif_t *blkif, vdisk_t *vbd_info, int max_vbds);
86 void destroy_all_vbds(blkif_t *blkif);
87
88 struct phys_req {
89     unsigned short       dev;
90     unsigned short       nr_sects;
91     struct block_device *bdev;
92     blkif_sector_t       sector_number;
93 };
94
95 int vbd_translate(struct phys_req *req, blkif_t *blkif, int operation); 
96
97 void blkif_interface_init(void);
98 void blkif_ctrlif_init(void);
99
100 void blkif_deschedule(blkif_t *blkif);
101
102 irqreturn_t blkif_be_int(int irq, void *dev_id, struct pt_regs *regs);
103
104 #endif /* __BLKIF__BACKEND__COMMON_H__ */