ia64/xen-unstable

view linux-2.6-xen-sparse/drivers/xen/blktap/blktap.h @ 6689:7d0fb56b4a91

merge?
author cl349@firebug.cl.cam.ac.uk
date Wed Sep 07 19:01:31 2005 +0000 (2005-09-07)
parents 549f4256ab3c dd668f7527cb
children b2f4823b6ff0 b35215021b32 1936ccaccf5e
line source
1 /*
2 * blktap.h
3 *
4 * Interfaces for the Xen block tap driver.
5 *
6 * (c) 2004, Andrew Warfield, University of Cambridge
7 *
8 */
10 #ifndef __BLKTAP_H__
11 #define __BLKTAP_H__
13 #include <linux/version.h>
14 #include <linux/blkdev.h>
15 #include <linux/config.h>
16 #include <linux/sched.h>
17 #include <linux/interrupt.h>
18 #include <linux/slab.h>
19 #include <linux/blkdev.h>
20 #include <asm/io.h>
21 #include <asm/setup.h>
22 #include <asm/pgalloc.h>
23 #include <asm-xen/hypervisor.h>
24 #include <asm-xen/xen-public/io/blkif.h>
25 #include <asm-xen/xen-public/io/ring.h>
27 /* Used to signal to the backend that this is a tap domain. */
28 #define BLKTAP_COOKIE 0xbeadfeed
30 /* -------[ debug / pretty printing ]--------------------------------- */
32 #define PRINTK(_f, _a...) printk(KERN_ALERT "(file=%s, line=%d) " _f, \
33 __FILE__ , __LINE__ , ## _a )
34 #if 0
35 #define DPRINTK(_f, _a...) printk(KERN_ALERT "(file=%s, line=%d) " _f, \
36 __FILE__ , __LINE__ , ## _a )
37 #else
38 #define DPRINTK(_f, _a...) ((void)0)
39 #endif
41 #if 1
42 #define ASSERT(_p) \
43 if ( !(_p) ) { printk("Assertion '%s' failed, line %d, file %s", #_p , \
44 __LINE__, __FILE__); *(int*)0=0; }
45 #else
46 #define ASSERT(_p) ((void)0)
47 #endif
49 #define WPRINTK(fmt, args...) printk(KERN_WARNING "blk_tap: " fmt, ##args)
52 /* -------[ state descriptors ]--------------------------------------- */
54 #define BLKIF_STATE_CLOSED 0
55 #define BLKIF_STATE_DISCONNECTED 1
56 #define BLKIF_STATE_CONNECTED 2
58 /* -------[ connection tracking ]------------------------------------- */
60 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
61 #define VMALLOC_VMADDR(x) ((unsigned long)(x))
62 #endif
64 extern spinlock_t blkif_io_lock;
66 typedef struct blkif_st {
67 /* Unique identifier for this interface. */
68 domid_t domid;
69 unsigned int handle;
70 /* Physical parameters of the comms window. */
71 unsigned long shmem_frame;
72 unsigned int evtchn;
73 /* Comms information. */
74 blkif_back_ring_t blk_ring;
76 enum { DISCONNECTED, DISCONNECTING, CONNECTED } status;
77 /*
78 * DISCONNECT response is deferred until pending requests are ack'ed.
79 * We therefore need to store the id from the original request.
80 */
81 u8 disconnect_rspid;
82 struct blkif_st *hash_next;
83 struct list_head blkdev_list;
84 spinlock_t blk_ring_lock;
85 atomic_t refcnt;
86 struct work_struct work;
87 #ifdef CONFIG_XEN_BLKDEV_GRANT
88 u16 shmem_handle;
89 unsigned long shmem_vaddr;
90 grant_ref_t shmem_ref;
91 #endif
92 } blkif_t;
94 blkif_t *blkif_find_by_handle(domid_t domid, unsigned int handle);
95 void blkif_disconnect_complete(blkif_t *blkif);
96 #define blkif_get(_b) (atomic_inc(&(_b)->refcnt))
97 #define blkif_put(_b) \
98 do { \
99 if ( atomic_dec_and_test(&(_b)->refcnt) ) \
100 blkif_disconnect_complete(_b); \
101 } while (0)
104 /* -------[ active request tracking ]--------------------------------- */
106 typedef struct {
107 blkif_t *blkif;
108 unsigned long id;
109 int nr_pages;
110 int next_free;
111 } active_req_t;
113 typedef unsigned int ACTIVE_RING_IDX;
115 active_req_t *lookup_active_req(ACTIVE_RING_IDX idx);
117 extern inline unsigned int ID_TO_IDX(unsigned long id)
118 {
119 return ( id & 0x0000ffff );
120 }
122 extern inline domid_t ID_TO_DOM(unsigned long id)
123 {
124 return (id >> 16);
125 }
127 void active_reqs_init(void);
129 /* -------[ interposition -> character device interface ]------------- */
131 /* /dev/xen/blktap resides at device number major=10, minor=200 */
132 #define BLKTAP_MINOR 202
134 /* size of the extra VMA area to map in attached pages. */
135 #define BLKTAP_VMA_PAGES BLKIF_RING_SIZE
137 /* blktap IOCTLs: */
138 #define BLKTAP_IOCTL_KICK_FE 1
139 #define BLKTAP_IOCTL_KICK_BE 2
140 #define BLKTAP_IOCTL_SETMODE 3
141 #define BLKTAP_IOCTL_PRINT_IDXS 100
143 /* blktap switching modes: (Set with BLKTAP_IOCTL_SETMODE) */
144 #define BLKTAP_MODE_PASSTHROUGH 0x00000000 /* default */
145 #define BLKTAP_MODE_INTERCEPT_FE 0x00000001
146 #define BLKTAP_MODE_INTERCEPT_BE 0x00000002
147 #define BLKTAP_MODE_COPY_FE 0x00000004
148 #define BLKTAP_MODE_COPY_BE 0x00000008
149 #define BLKTAP_MODE_COPY_FE_PAGES 0x00000010
150 #define BLKTAP_MODE_COPY_BE_PAGES 0x00000020
152 #define BLKTAP_MODE_INTERPOSE \
153 (BLKTAP_MODE_INTERCEPT_FE | BLKTAP_MODE_INTERCEPT_BE)
155 #define BLKTAP_MODE_COPY_BOTH \
156 (BLKTAP_MODE_COPY_FE | BLKTAP_MODE_COPY_BE)
158 #define BLKTAP_MODE_COPY_BOTH_PAGES \
159 (BLKTAP_MODE_COPY_FE_PAGES | BLKTAP_MODE_COPY_BE_PAGES)
161 static inline int BLKTAP_MODE_VALID(unsigned long arg)
162 {
163 return (
164 ( arg == BLKTAP_MODE_PASSTHROUGH ) ||
165 ( arg == BLKTAP_MODE_INTERCEPT_FE ) ||
166 ( arg == BLKTAP_MODE_INTERCEPT_BE ) ||
167 ( arg == BLKTAP_MODE_INTERPOSE ) ||
168 ( (arg & ~BLKTAP_MODE_COPY_FE_PAGES) == BLKTAP_MODE_COPY_FE ) ||
169 ( (arg & ~BLKTAP_MODE_COPY_BE_PAGES) == BLKTAP_MODE_COPY_BE ) ||
170 ( (arg & ~BLKTAP_MODE_COPY_BOTH_PAGES) == BLKTAP_MODE_COPY_BOTH )
171 );
172 }
176 /* -------[ Mappings to User VMA ]------------------------------------ */
177 #define BATCH_PER_DOMAIN 16
179 /* -------[ Here be globals ]----------------------------------------- */
180 extern unsigned long blktap_mode;
182 /* Connection to a single backend domain. */
183 extern blkif_front_ring_t blktap_be_ring;
184 extern unsigned int blktap_be_evtchn;
185 extern unsigned int blktap_be_state;
187 /* User ring status. */
188 extern unsigned long blktap_ring_ok;
190 /* -------[ ...and function prototypes. ]----------------------------- */
192 /* init function for character device interface. */
193 int blktap_init(void);
195 /* init function for the blkif cache. */
196 void __init blkif_interface_init(void);
197 void __init blkdev_schedule_init(void);
198 void blkif_deschedule(blkif_t *blkif);
200 /* interfaces to the char driver, passing messages to and from apps. */
201 void blktap_kick_user(void);
203 /* user ring access functions: */
204 int blktap_write_fe_ring(blkif_request_t *req);
205 int blktap_write_be_ring(blkif_response_t *rsp);
206 int blktap_write_ctrl_ring(ctrl_msg_t *msg);
208 /* fe/be ring access functions: */
209 int write_resp_to_fe_ring(blkif_t *blkif, blkif_response_t *rsp);
210 int write_req_to_be_ring(blkif_request_t *req);
212 /* event notification functions */
213 void kick_fe_domain(blkif_t *blkif);
214 void kick_be_domain(void);
216 /* Interrupt handlers. */
217 irqreturn_t blkif_ptbe_int(int irq, void *dev_id,
218 struct pt_regs *ptregs);
219 irqreturn_t blkif_ptfe_int(int irq, void *dev_id, struct pt_regs *regs);
221 /* Control message receiver. */
222 extern void blkif_ctrlif_rx(ctrl_msg_t *msg, unsigned long id);
224 /* debug */
225 void print_fe_ring_idxs(void);
226 void print_be_ring_idxs(void);
228 #define __BLKINT_H__
229 #endif