ia64/xen-unstable

view linux-2.6-xen-sparse/drivers/xen/blktap/blktap.h @ 6316:f7dfaa2af90c

merge?
author cl349@firebug.cl.cam.ac.uk
date Sun Aug 21 11:02:00 2005 +0000 (2005-08-21)
parents 1872e09bfba3
children 6721abf6b16d
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 <asm-xen/ctrl_if.h>
19 #include <linux/slab.h>
20 #include <linux/blkdev.h>
21 #include <asm/io.h>
22 #include <asm/setup.h>
23 #include <asm/pgalloc.h>
24 #include <asm-xen/hypervisor.h>
25 #include <asm-xen/xen-public/io/blkif.h>
26 #include <asm-xen/xen-public/io/ring.h>
28 /* Used to signal to the backend that this is a tap domain. */
29 #define BLKTAP_COOKIE 0xbeadfeed
31 /* -------[ debug / pretty printing ]--------------------------------- */
33 #define PRINTK(_f, _a...) printk(KERN_ALERT "(file=%s, line=%d) " _f, \
34 __FILE__ , __LINE__ , ## _a )
35 #if 0
36 #define DPRINTK(_f, _a...) printk(KERN_ALERT "(file=%s, line=%d) " _f, \
37 __FILE__ , __LINE__ , ## _a )
38 #else
39 #define DPRINTK(_f, _a...) ((void)0)
40 #endif
42 #if 1
43 #define ASSERT(_p) \
44 if ( !(_p) ) { printk("Assertion '%s' failed, line %d, file %s", #_p , \
45 __LINE__, __FILE__); *(int*)0=0; }
46 #else
47 #define ASSERT(_p) ((void)0)
48 #endif
50 #define WPRINTK(fmt, args...) printk(KERN_WARNING "blk_tap: " fmt, ##args)
53 /* -------[ state descriptors ]--------------------------------------- */
55 #define BLKIF_STATE_CLOSED 0
56 #define BLKIF_STATE_DISCONNECTED 1
57 #define BLKIF_STATE_CONNECTED 2
59 /* -------[ connection tracking ]------------------------------------- */
61 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
62 #define VMALLOC_VMADDR(x) ((unsigned long)(x))
63 #endif
65 extern spinlock_t blkif_io_lock;
67 typedef struct blkif_st {
68 /* Unique identifier for this interface. */
69 domid_t domid;
70 unsigned int handle;
71 /* Physical parameters of the comms window. */
72 unsigned long shmem_frame;
73 unsigned int evtchn;
74 /* Comms information. */
75 blkif_back_ring_t blk_ring;
77 enum { DISCONNECTED, DISCONNECTING, CONNECTED } status;
78 /*
79 * DISCONNECT response is deferred until pending requests are ack'ed.
80 * We therefore need to store the id from the original request.
81 */
82 u8 disconnect_rspid;
83 struct blkif_st *hash_next;
84 struct list_head blkdev_list;
85 spinlock_t blk_ring_lock;
86 atomic_t refcnt;
87 struct work_struct work;
88 #ifdef CONFIG_XEN_BLKDEV_GRANT
89 u16 shmem_handle;
90 unsigned long shmem_vaddr;
91 grant_ref_t shmem_ref;
92 #endif
93 } blkif_t;
95 blkif_t *blkif_find_by_handle(domid_t domid, unsigned int handle);
96 void blkif_disconnect_complete(blkif_t *blkif);
97 #define blkif_get(_b) (atomic_inc(&(_b)->refcnt))
98 #define blkif_put(_b) \
99 do { \
100 if ( atomic_dec_and_test(&(_b)->refcnt) ) \
101 blkif_disconnect_complete(_b); \
102 } while (0)
105 /* -------[ active request tracking ]--------------------------------- */
107 typedef struct {
108 blkif_t *blkif;
109 unsigned long id;
110 int nr_pages;
111 int next_free;
112 } active_req_t;
114 typedef unsigned int ACTIVE_RING_IDX;
116 active_req_t *lookup_active_req(ACTIVE_RING_IDX idx);
118 extern inline unsigned int ID_TO_IDX(unsigned long id)
119 {
120 return ( id & 0x0000ffff );
121 }
123 extern inline domid_t ID_TO_DOM(unsigned long id)
124 {
125 return (id >> 16);
126 }
128 void active_reqs_init(void);
130 /* -------[ interposition -> character device interface ]------------- */
132 /* /dev/xen/blktap resides at device number major=10, minor=200 */
133 #define BLKTAP_MINOR 202
135 /* size of the extra VMA area to map in attached pages. */
136 #define BLKTAP_VMA_PAGES BLKIF_RING_SIZE
138 /* blktap IOCTLs: */
139 #define BLKTAP_IOCTL_KICK_FE 1
140 #define BLKTAP_IOCTL_KICK_BE 2
141 #define BLKTAP_IOCTL_SETMODE 3
142 #define BLKTAP_IOCTL_PRINT_IDXS 100
144 /* blktap switching modes: (Set with BLKTAP_IOCTL_SETMODE) */
145 #define BLKTAP_MODE_PASSTHROUGH 0x00000000 /* default */
146 #define BLKTAP_MODE_INTERCEPT_FE 0x00000001
147 #define BLKTAP_MODE_INTERCEPT_BE 0x00000002
148 #define BLKTAP_MODE_COPY_FE 0x00000004
149 #define BLKTAP_MODE_COPY_BE 0x00000008
150 #define BLKTAP_MODE_COPY_FE_PAGES 0x00000010
151 #define BLKTAP_MODE_COPY_BE_PAGES 0x00000020
153 #define BLKTAP_MODE_INTERPOSE \
154 (BLKTAP_MODE_INTERCEPT_FE | BLKTAP_MODE_INTERCEPT_BE)
156 #define BLKTAP_MODE_COPY_BOTH \
157 (BLKTAP_MODE_COPY_FE | BLKTAP_MODE_COPY_BE)
159 #define BLKTAP_MODE_COPY_BOTH_PAGES \
160 (BLKTAP_MODE_COPY_FE_PAGES | BLKTAP_MODE_COPY_BE_PAGES)
162 static inline int BLKTAP_MODE_VALID(unsigned long arg)
163 {
164 return (
165 ( arg == BLKTAP_MODE_PASSTHROUGH ) ||
166 ( arg == BLKTAP_MODE_INTERCEPT_FE ) ||
167 ( arg == BLKTAP_MODE_INTERCEPT_BE ) ||
168 ( arg == BLKTAP_MODE_INTERPOSE ) ||
169 ( (arg & ~BLKTAP_MODE_COPY_FE_PAGES) == BLKTAP_MODE_COPY_FE ) ||
170 ( (arg & ~BLKTAP_MODE_COPY_BE_PAGES) == BLKTAP_MODE_COPY_BE ) ||
171 ( (arg & ~BLKTAP_MODE_COPY_BOTH_PAGES) == BLKTAP_MODE_COPY_BOTH )
172 );
173 }
177 /* -------[ Mappings to User VMA ]------------------------------------ */
178 #define BATCH_PER_DOMAIN 16
180 /* -------[ Here be globals ]----------------------------------------- */
181 extern unsigned long blktap_mode;
183 /* Connection to a single backend domain. */
184 extern blkif_front_ring_t blktap_be_ring;
185 extern unsigned int blktap_be_evtchn;
186 extern unsigned int blktap_be_state;
188 /* User ring status. */
189 extern unsigned long blktap_ring_ok;
191 /* -------[ ...and function prototypes. ]----------------------------- */
193 /* init function for character device interface. */
194 int blktap_init(void);
196 /* init function for the blkif cache. */
197 void __init blkif_interface_init(void);
198 void __init blkdev_schedule_init(void);
199 void blkif_deschedule(blkif_t *blkif);
201 /* interfaces to the char driver, passing messages to and from apps. */
202 void blktap_kick_user(void);
204 /* user ring access functions: */
205 int blktap_write_fe_ring(blkif_request_t *req);
206 int blktap_write_be_ring(blkif_response_t *rsp);
207 int blktap_write_ctrl_ring(ctrl_msg_t *msg);
209 /* fe/be ring access functions: */
210 int write_resp_to_fe_ring(blkif_t *blkif, blkif_response_t *rsp);
211 int write_req_to_be_ring(blkif_request_t *req);
213 /* event notification functions */
214 void kick_fe_domain(blkif_t *blkif);
215 void kick_be_domain(void);
217 /* Interrupt handlers. */
218 irqreturn_t blkif_ptbe_int(int irq, void *dev_id,
219 struct pt_regs *ptregs);
220 irqreturn_t blkif_ptfe_int(int irq, void *dev_id, struct pt_regs *regs);
222 /* Control message receiver. */
223 extern void blkif_ctrlif_rx(ctrl_msg_t *msg, unsigned long id);
225 /* debug */
226 void print_fe_ring_idxs(void);
227 void print_be_ring_idxs(void);
229 #define __BLKINT_H__
230 #endif