ia64/xen-unstable

view tools/blktap/lib/blktaplib.h @ 15783:c93e2a822d6f

[xen, xencomm] xencomm multiple page support
Current implementation doesn't allow struct xencomm_desc::address
array to be more than single page. On IA64 it causes 64GB+ domain
creation failure. This patch generalizes xencomm to allow multipage

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
author kfraser@localhost.localdomain
date Tue Aug 28 15:32:27 2007 +0100 (2007-08-28)
parents ad9a79db3839
children 1b863ae2bf1e
line source
1 /* blktaplib.h
2 *
3 * Blktap library userspace code.
4 *
5 * (c) 2005 Andrew Warfield and Julian Chesterfield
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License version 2
9 * as published by the Free Software Foundation; or, when distributed
10 * separately from the Linux kernel or incorporated into other
11 * software packages, subject to the following license:
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining a copy
14 * of this source file (the "Software"), to deal in the Software without
15 * restriction, including without limitation the rights to use, copy, modify,
16 * merge, publish, distribute, sublicense, and/or sell copies of the Software,
17 * and to permit persons to whom the Software is furnished to do so, subject to
18 * the following conditions:
19 *
20 * The above copyright notice and this permission notice shall be included in
21 * all copies or substantial portions of the Software.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
29 * IN THE SOFTWARE.
30 */
32 #ifndef __BLKTAPLIB_H__
33 #define __BLKTAPLIB_H__
35 #include <xenctrl.h>
36 #include <sys/user.h>
37 #include <xen/xen.h>
38 #include <xen/io/blkif.h>
39 #include <xen/io/ring.h>
40 #include <xs.h>
41 #include <sys/types.h>
42 #include <unistd.h>
44 #define BLK_RING_SIZE __RING_SIZE((blkif_sring_t *)0, XC_PAGE_SIZE)
46 /* size of the extra VMA area to map in attached pages. */
47 #define BLKTAP_VMA_PAGES BLK_RING_SIZE
49 /* blktap IOCTLs: These must correspond with the blktap driver ioctls*/
50 #define BLKTAP_IOCTL_KICK_FE 1
51 #define BLKTAP_IOCTL_KICK_BE 2
52 #define BLKTAP_IOCTL_SETMODE 3
53 #define BLKTAP_IOCTL_SENDPID 4
54 #define BLKTAP_IOCTL_NEWINTF 5
55 #define BLKTAP_IOCTL_MINOR 6
56 #define BLKTAP_IOCTL_MAJOR 7
57 #define BLKTAP_QUERY_ALLOC_REQS 8
58 #define BLKTAP_IOCTL_FREEINTF 9
59 #define BLKTAP_IOCTL_PRINT_IDXS 100
61 /* blktap switching modes: (Set with BLKTAP_IOCTL_SETMODE) */
62 #define BLKTAP_MODE_PASSTHROUGH 0x00000000 /* default */
63 #define BLKTAP_MODE_INTERCEPT_FE 0x00000001
64 #define BLKTAP_MODE_INTERCEPT_BE 0x00000002
66 #define BLKTAP_MODE_INTERPOSE \
67 (BLKTAP_MODE_INTERCEPT_FE | BLKTAP_MODE_INTERCEPT_BE)
69 static inline int BLKTAP_MODE_VALID(unsigned long arg)
70 {
71 return (
72 ( arg == BLKTAP_MODE_PASSTHROUGH ) ||
73 ( arg == BLKTAP_MODE_INTERCEPT_FE ) ||
74 ( arg == BLKTAP_MODE_INTERPOSE ) );
75 }
77 #define MAX_REQUESTS BLK_RING_SIZE
79 #define BLKTAP_IOCTL_KICK 1
80 #define MAX_PENDING_REQS BLK_RING_SIZE
81 #define BLKTAP_DEV_DIR "/dev/xen"
82 #define BLKTAP_DEV_NAME "blktap"
83 #define BLKTAP_DEV_MINOR 0
84 #define BLKTAP_CTRL_DIR "/var/run/tap"
86 extern int blktap_major;
88 #define BLKTAP_RING_PAGES 1 /* Front */
89 #define BLKTAP_MMAP_REGION_SIZE (BLKTAP_RING_PAGES + MMAP_PAGES)
91 struct blkif;
93 typedef struct {
94 blkif_request_t req;
95 struct blkif *blkif;
96 int submitting;
97 int secs_pending;
98 int16_t status;
99 } pending_req_t;
101 struct blkif_ops {
102 unsigned long long (*get_size)(struct blkif *blkif);
103 unsigned long (*get_secsize)(struct blkif *blkif);
104 unsigned int (*get_info)(struct blkif *blkif);
105 };
107 typedef struct blkif {
108 domid_t domid;
109 long int handle;
111 long int pdev;
112 long int readonly;
114 enum { DISCONNECTED, DISCONNECTING, CONNECTED } state;
116 struct blkif_ops *ops;
117 struct blkif *hash_next;
119 void *prv; /* device-specific data */
120 void *info; /*Image parameter passing */
121 pending_req_t pending_list[MAX_REQUESTS];
122 int devnum;
123 int fds[2];
124 int be_id;
125 int major;
126 int minor;
127 pid_t tappid;
128 int drivertype;
129 uint16_t cookie;
130 } blkif_t;
132 typedef struct blkif_info {
133 char *params;
134 } blkif_info_t;
136 void register_new_devmap_hook(int (*fn)(blkif_t *blkif));
137 void register_new_unmap_hook(int (*fn)(blkif_t *blkif));
138 void register_new_blkif_hook(int (*fn)(blkif_t *blkif));
139 blkif_t *blkif_find_by_handle(domid_t domid, unsigned int handle);
140 blkif_t *alloc_blkif(domid_t domid);
141 int blkif_init(blkif_t *blkif, long int handle, long int pdev,
142 long int readonly);
143 void free_blkif(blkif_t *blkif);
144 void __init_blkif(void);
146 typedef struct busy_state {
147 int seg_idx;
148 blkif_request_t *req;
149 } busy_state_t;
151 typedef struct tapdev_info {
152 int fd;
153 char *mem;
154 blkif_sring_t *sring;
155 blkif_back_ring_t fe_ring;
156 unsigned long vstart;
157 blkif_t *blkif;
158 busy_state_t busy;
159 } tapdev_info_t;
161 typedef struct domid_translate {
162 unsigned short domid;
163 unsigned short busid;
164 } domid_translate_t ;
166 typedef struct image {
167 unsigned long long size;
168 unsigned long secsize;
169 unsigned int info;
170 } image_t;
172 /* 16-byte message header, immediately followed by message payload. */
173 typedef struct msg_hdr {
174 uint16_t type;
175 uint16_t len;
176 uint16_t drivertype;
177 uint16_t cookie;
178 uint8_t readonly;
179 uint8_t pad[7];
180 } msg_hdr_t;
182 typedef struct msg_newdev {
183 uint8_t devnum;
184 uint16_t domid;
185 } msg_newdev_t;
187 typedef struct msg_pid {
188 pid_t pid;
189 } msg_pid_t;
191 #define READ 0
192 #define WRITE 1
194 /*Control Messages between manager and tapdev*/
195 #define CTLMSG_PARAMS 1
196 #define CTLMSG_IMG 2
197 #define CTLMSG_IMG_FAIL 3
198 #define CTLMSG_NEWDEV 4
199 #define CTLMSG_NEWDEV_RSP 5
200 #define CTLMSG_NEWDEV_FAIL 6
201 #define CTLMSG_CLOSE 7
202 #define CTLMSG_CLOSE_RSP 8
203 #define CTLMSG_PID 9
204 #define CTLMSG_PID_RSP 10
206 /* xenstore/xenbus: */
207 #define DOMNAME "Domain-0"
208 int setup_probe_watch(struct xs_handle *h);
209 int xs_fire_next_watch(struct xs_handle *h);
212 /* Abitrary values, must match the underlying driver... */
213 #define MAX_TAP_DEV 100
215 /* Accessing attached data page mappings */
216 #define MMAP_PAGES \
217 (MAX_PENDING_REQS * BLKIF_MAX_SEGMENTS_PER_REQUEST)
218 #define MMAP_VADDR(_vstart,_req,_seg) \
219 ((_vstart) + \
220 ((_req) * BLKIF_MAX_SEGMENTS_PER_REQUEST * getpagesize()) + \
221 ((_seg) * getpagesize()))
223 /* Defines that are only used by library clients */
225 #ifndef __COMPILING_BLKTAP_LIB
227 static char *blkif_op_name[] = {
228 [BLKIF_OP_READ] = "READ",
229 [BLKIF_OP_WRITE] = "WRITE",
230 };
232 #endif /* __COMPILING_BLKTAP_LIB */
234 #endif /* __BLKTAPLIB_H__ */