debuggers.hg

view linux-2.6.10-xen-sparse/drivers/xen/blktap/blktap.h @ 3370:72b23176fb04

bitkeeper revision 1.1159.1.506 (41d00f89OifvQoN_EcnO5XuQN0RRjA)

Update to Linux 2.6.10.
author cl349@arcadians.cl.cam.ac.uk
date Mon Dec 27 13:35:05 2004 +0000 (2004-12-27)
parents
children 70b803ca7d24 671aaec9d333 9e77c2678efa
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>
27 /* -------[ debug / pretty printing ]--------------------------------- */
29 #if 0
30 #define ASSERT(_p) \
31 if ( !(_p) ) { printk("Assertion '%s' failed, line %d, file %s", #_p , \
32 __LINE__, __FILE__); *(int*)0=0; }
33 #define DPRINTK(_f, _a...) printk(KERN_ALERT "(file=%s, line=%d) " _f, \
34 __FILE__ , __LINE__ , ## _a )
35 #else
36 #define ASSERT(_p) ((void)0)
37 #define DPRINTK(_f, _a...) ((void)0)
38 #endif
40 #define WPRINTK(fmt, args...) printk(KERN_WARNING "blk_tap: " fmt, ##args)
42 /* -------[ connection / request tracking ]--------------------------- */
44 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
45 #define VMALLOC_VMADDR(x) ((unsigned long)(x))
46 #endif
48 extern spinlock_t blkif_io_lock;
50 typedef struct blkif_st {
51 /* Unique identifier for this interface. */
52 domid_t domid;
53 unsigned int handle;
54 /* Physical parameters of the comms window. */
55 unsigned long shmem_frame;
56 unsigned int evtchn;
57 int irq;
58 /* Comms information. */
59 blkif_ring_t *blk_ring_base; /* ioremap()'ed ptr to shmem_frame. */
60 BLKIF_RING_IDX blk_req_cons; /* Request consumer. */
61 BLKIF_RING_IDX blk_resp_prod; /* Private version of resp. producer. */
63 enum { DISCONNECTED, DISCONNECTING, CONNECTED } status;
64 /*
65 * DISCONNECT response is deferred until pending requests are ack'ed.
66 * We therefore need to store the id from the original request.
67 */ u8 disconnect_rspid;
68 struct blkif_st *hash_next;
69 struct list_head blkdev_list;
70 spinlock_t blk_ring_lock;
71 atomic_t refcnt;
73 struct work_struct work;
74 } blkif_t;
76 typedef struct {
77 blkif_t *blkif;
78 unsigned long id;
79 int nr_pages;
80 unsigned long mach_fas[BLKIF_MAX_SEGMENTS_PER_REQUEST];
81 unsigned long virt_fas[BLKIF_MAX_SEGMENTS_PER_REQUEST];
82 int next_free;
83 } active_req_t;
86 /* -------[ block ring structs ]-------------------------------------- */
88 /* Types of ring. */
89 #define BLKIF_REQ_RING_TYPE 1
90 #define BLKIF_RSP_RING_TYPE 2
92 /* generic ring struct. */
93 typedef struct blkif_generic_ring_struct {
94 int type;
95 } blkif_generic_ring_t;
97 /* A requestor's view of a ring. */
98 typedef struct blkif_req_ring_struct {
100 int type; /* Will be BLKIF_REQ_RING_TYPE */
101 BLKIF_RING_IDX req_prod; /* PRIVATE req_prod index */
102 BLKIF_RING_IDX rsp_cons; /* Response consumer index */
103 blkif_ring_t *ring; /* Pointer to shared ring struct */
105 } blkif_req_ring_t;
107 #define BLKIF_REQ_RING_INIT { BLKIF_REQ_RING_TYPE, 0, 0, 0 }
109 /* A responder's view of a ring. */
110 typedef struct blkif_rsp_ring_struct {
112 int type;
113 BLKIF_RING_IDX rsp_prod; /* PRIVATE rsp_prod index */
114 BLKIF_RING_IDX req_cons; /* Request consumer index */
115 blkif_ring_t *ring; /* Pointer to shared ring struct */
117 } blkif_rsp_ring_t;
119 #define BLKIF_RSP_RING_INIT = { BLKIF_RSP_RING_TYPE, 0, 0, 0 }
121 #define RING(a) (blkif_generic_ring_t *)(a)
123 inline int BLKTAP_RING_FULL(blkif_generic_ring_t *ring);
126 /* -------[ interposition -> character device interface ]------------- */
128 /* /dev/xen/blktap resides at device number major=10, minor=200 */
129 #define BLKTAP_MINOR 202
131 /* size of the extra VMA area to map in attached pages. */
132 #define BLKTAP_VMA_PAGES BLKIF_RING_SIZE
134 /* blktap IOCTLs: */
135 #define BLKTAP_IOCTL_KICK_FE 1
136 #define BLKTAP_IOCTL_KICK_BE 2
137 #define BLKTAP_IOCTL_SETMODE 3
139 /* blktap switching modes: (Set with BLKTAP_IOCTL_SETMODE) */
140 #define BLKTAP_MODE_PASSTHROUGH 0x00000000 /* default */
141 #define BLKTAP_MODE_INTERCEPT_FE 0x00000001
142 #define BLKTAP_MODE_INTERCEPT_BE 0x00000002
143 #define BLKTAP_MODE_COPY_FE 0x00000004
144 #define BLKTAP_MODE_COPY_BE 0x00000008
145 #define BLKTAP_MODE_COPY_FE_PAGES 0x00000010
146 #define BLKTAP_MODE_COPY_BE_PAGES 0x00000020
148 #define BLKTAP_MODE_INTERPOSE \
149 (BLKTAP_MODE_INTERCEPT_FE | BLKTAP_MODE_INTERCEPT_BE)
151 #define BLKTAP_MODE_COPY_BOTH \
152 (BLKTAP_MODE_COPY_FE | BLKTAP_MODE_COPY_BE)
154 #define BLKTAP_MODE_COPY_BOTH_PAGES \
155 (BLKTAP_MODE_COPY_FE_PAGES | BLKTAP_MODE_COPY_BE_PAGES)
157 static inline int BLKTAP_MODE_VALID(unsigned long arg)
158 {
159 return (
160 ( arg == BLKTAP_MODE_PASSTHROUGH ) ||
161 ( arg == BLKTAP_MODE_INTERCEPT_FE ) ||
162 ( arg == BLKTAP_MODE_INTERCEPT_BE ) ||
163 ( arg == BLKTAP_MODE_INTERPOSE ) ||
164 ( (arg & ~BLKTAP_MODE_COPY_FE_PAGES) == BLKTAP_MODE_COPY_FE ) ||
165 ( (arg & ~BLKTAP_MODE_COPY_BE_PAGES) == BLKTAP_MODE_COPY_BE ) ||
166 ( (arg & ~BLKTAP_MODE_COPY_BOTH_PAGES) == BLKTAP_MODE_COPY_BOTH )
167 );
168 }
172 /* -------[ Mappings to User VMA ]------------------------------------ */
173 #define MAX_PENDING_REQS 64
174 #define BATCH_PER_DOMAIN 16
175 extern struct vm_area_struct *blktap_vma;
177 /* The following are from blkback.c and should probably be put in a
178 * header and included from there.
179 * The mmap area described here is where attached data pages eill be mapped.
180 */
182 extern unsigned long mmap_vstart;
183 #define MMAP_PAGES_PER_REQUEST \
184 (BLKIF_MAX_SEGMENTS_PER_REQUEST + 1)
185 #define MMAP_PAGES \
186 (MAX_PENDING_REQS * MMAP_PAGES_PER_REQUEST)
187 #define MMAP_VADDR(_req,_seg) \
188 (mmap_vstart + \
189 ((_req) * MMAP_PAGES_PER_REQUEST * PAGE_SIZE) + \
190 ((_seg) * PAGE_SIZE))
192 /* immediately before the mmap area, we have a bunch of pages reserved
193 * for shared memory rings.
194 */
196 #define RING_PAGES 128
197 extern unsigned long rings_vstart;
199 /* -------[ Here be globals ]----------------------------------------- */
201 extern unsigned long blktap_mode;
204 /* blkif struct, containing ring to FE domain */
205 extern blkif_t ptfe_blkif;
207 /* Connection to a single backend domain. */
208 extern blkif_ring_t *blk_ptbe_ring; /* Ring from the PT to the BE dom */
209 extern BLKIF_RING_IDX ptbe_resp_cons; /* Response consumer for comms ring. */
210 extern BLKIF_RING_IDX ptbe_req_prod; /* Private request producer. */
212 /* Rings up to user space. */
213 extern blkif_req_ring_t fe_ring;// = BLKIF_REQ_RING_INIT;
214 extern blkif_rsp_ring_t be_ring;// = BLKIF_RSP_RING_INIT;
216 /* Event channel to backend domain. */
217 extern unsigned int blkif_ptbe_evtchn;
219 /* User ring status... this will soon vanish into a ring struct. */
220 extern unsigned long blktap_ring_ok;
222 /* -------[ ...and function prototypes. ]----------------------------- */
224 /* init function for character device interface. */
225 int blktap_init(void);
227 /* interfaces to the char driver, passing messages to and from apps. */
228 void blktap_kick_user(void);
229 int blktap_write_to_ring(blkif_request_t *req);
232 /* user ring access functions: */
233 int blktap_write_fe_ring(blkif_request_t *req);
234 int blktap_write_be_ring(blkif_response_t *rsp);
235 int blktap_read_fe_ring(void);
236 int blktap_read_be_ring(void);
238 /* and the helpers they call: */
239 inline int write_resp_to_fe_ring(blkif_response_t *rsp);
240 inline void kick_fe_domain(void);
242 inline int write_req_to_be_ring(blkif_request_t *req);
243 inline void kick_be_domain(void);
245 /* Interrupt handlers. */
246 irqreturn_t blkif_ptbe_int(int irq, void *dev_id,
247 struct pt_regs *ptregs);
248 irqreturn_t blkif_ptfe_int(int irq, void *dev_id, struct pt_regs *regs);
250 /* Control message receiver. */
251 extern void blkif_ctrlif_rx(ctrl_msg_t *msg, unsigned long id);
253 #define __BLKINT_H__
254 #endif