win-pvdrivers

view common/include/xen_public.h @ 504:cb0b2da68686

big changes to xenbus interface. simplified it a bit. started work on userspace interface.
author James Harper <james.harper@bendigoit.com.au>
date Mon Dec 22 22:34:52 2008 +1100 (2008-12-22)
parents 312a41f82b8f
children d62254d4ba64
line source
1 /*
2 PV Drivers for Windows Xen HVM Domains
3 Copyright (C) 2007 James Harper
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
20 #if !defined(_XEN_PUBLIC_H_)
21 #define _XEN_PUBLIC_H_
23 #include <grant_table.h>
24 #include <event_channel.h>
25 #include <xen_guids.h>
27 // {5C568AC5-9DDF-4FA5-A94A-39D67077819C}
28 DEFINE_GUID(GUID_XEN_IFACE, 0x5C568AC5, 0x9DDF, 0x4FA5, 0xA9, 0x4A, 0x39, 0xD6, 0x70, 0x77, 0x81, 0x9C);
30 // {14CE175A-3EE2-4fae-9252-00DBD84F018E}
31 DEFINE_GUID(GUID_XENBUS_IFACE, 0x14ce175a, 0x3ee2, 0x4fae, 0x92, 0x52, 0x0, 0xdb, 0xd8, 0x4f, 0x1, 0x8e);
33 #define INVALID_GRANT_REF 0xFFFFFFFF
35 typedef PHYSICAL_ADDRESS
36 (*PXEN_ALLOCMMIO)(PVOID Context, ULONG Length);
38 typedef void
39 (*PXEN_FREEMEM)(PVOID Ptr);
41 typedef NTSTATUS
42 (*PXEN_EVTCHN_BIND)(PVOID Context, evtchn_port_t Port, PKSERVICE_ROUTINE ServiceRoutine, PVOID ServiceContext);
44 typedef NTSTATUS
45 (*PXEN_EVTCHN_UNBIND)(PVOID Context, evtchn_port_t Port);
47 typedef NTSTATUS
48 (*PXEN_EVTCHN_MASK)(PVOID Context, evtchn_port_t Port);
50 typedef NTSTATUS
51 (*PXEN_EVTCHN_UNMASK)(PVOID Context, evtchn_port_t Port);
53 typedef NTSTATUS
54 (*PXEN_EVTCHN_NOTIFY)(PVOID Context, evtchn_port_t Port);
56 typedef evtchn_port_t
57 (*PXEN_EVTCHN_ALLOCUNBOUND)(PVOID Context, domid_t Domain);
59 typedef BOOLEAN
60 (*PXEN_EVTCHN_ACK_EVENT)(PVOID context, evtchn_port_t port);
62 typedef grant_ref_t
63 (*PXEN_GNTTBL_GRANTACCESS)(PVOID Context, domid_t domid, uint32_t frame, int readonly, grant_ref_t ref);
65 typedef BOOLEAN
66 (*PXEN_GNTTBL_ENDACCESS)(PVOID Context, grant_ref_t ref, BOOLEAN keepref);
68 typedef VOID
69 (*PXEN_GNTTBL_PUTREF)(PVOID Context, grant_ref_t ref);
71 typedef grant_ref_t
72 (*PXEN_GNTTBL_GETREF)(PVOID Context);
75 typedef VOID
76 (*PXENBUS_WATCH_CALLBACK)(char *Path, PVOID ServiceContext);
78 typedef char *
79 (*PXEN_XENBUS_READ)(PVOID Context, xenbus_transaction_t xbt, char *path, char **value);
81 typedef char *
82 (*PXEN_XENBUS_WRITE)(PVOID Context, xenbus_transaction_t xbt, char *path, char *value);
84 typedef char *
85 (*PXEN_XENBUS_PRINTF)(PVOID Context, xenbus_transaction_t xbt, char *path, char *fmt, ...);
87 typedef char *
88 (*PXEN_XENBUS_STARTTRANSACTION)(PVOID Context, xenbus_transaction_t *xbt);
90 typedef char *
91 (*PXEN_XENBUS_ENDTRANSACTION)(PVOID Context, xenbus_transaction_t t, int abort, int *retry);
93 typedef char *
94 (*PXEN_XENBUS_LIST)(PVOID Context, xenbus_transaction_t xbt, char *prefix, char ***contents);
96 typedef char *
97 (*PXEN_XENBUS_ADDWATCH)(PVOID Context, xenbus_transaction_t xbt, char *Path, PXENBUS_WATCH_CALLBACK ServiceRoutine, PVOID ServiceContext);
99 typedef char *
100 (*PXEN_XENBUS_REMWATCH)(PVOID Context, xenbus_transaction_t xbt, char *Path, PXENBUS_WATCH_CALLBACK ServiceRoutine, PVOID ServiceContext);
102 typedef NTSTATUS
103 (*PXEN_XENPCI_XEN_CONFIG_DEVICE)(PVOID Context);
105 typedef NTSTATUS
106 (*PXEN_XENPCI_XEN_SHUTDOWN_DEVICE)(PVOID Context);
108 #ifndef XENPCI_POOL_TAG
109 #define XENPCI_POOL_TAG (ULONG) 'XenP'
110 #endif
112 static __inline VOID
113 XenPci_FreeMem(PVOID Ptr)
114 {
115 ExFreePoolWithTag(Ptr, XENPCI_POOL_TAG);
116 }
118 #define XEN_DATA_MAGIC 0x12345678
120 typedef struct {
121 ULONG magic;
122 USHORT length;
124 PVOID context;
125 PXEN_EVTCHN_BIND EvtChn_Bind;
126 PXEN_EVTCHN_BIND EvtChn_BindDpc;
127 PXEN_EVTCHN_UNBIND EvtChn_Unbind;
128 PXEN_EVTCHN_MASK EvtChn_Mask;
129 PXEN_EVTCHN_UNMASK EvtChn_Unmask;
130 PXEN_EVTCHN_NOTIFY EvtChn_Notify;
131 PXEN_EVTCHN_ACK_EVENT EvtChn_AckEvent;
133 PXEN_GNTTBL_GETREF GntTbl_GetRef;
134 PXEN_GNTTBL_PUTREF GntTbl_PutRef;
135 PXEN_GNTTBL_GRANTACCESS GntTbl_GrantAccess;
136 PXEN_GNTTBL_ENDACCESS GntTbl_EndAccess;
138 PXEN_XENPCI_XEN_CONFIG_DEVICE XenPci_XenConfigDevice;
139 PXEN_XENPCI_XEN_SHUTDOWN_DEVICE XenPci_XenShutdownDevice;
141 CHAR path[128];
142 CHAR backend_path[128];
144 evtchn_port_t pdo_event_channel;
146 PXEN_XENBUS_READ XenBus_Read;
147 PXEN_XENBUS_WRITE XenBus_Write;
148 PXEN_XENBUS_PRINTF XenBus_Printf;
149 PXEN_XENBUS_STARTTRANSACTION XenBus_StartTransaction;
150 PXEN_XENBUS_ENDTRANSACTION XenBus_EndTransaction;
151 PXEN_XENBUS_LIST XenBus_List;
152 PXEN_XENBUS_ADDWATCH XenBus_AddWatch;
153 PXEN_XENBUS_REMWATCH XenBus_RemWatch;
155 } XENPCI_VECTORS, *PXENPCI_VECTORS;
157 #define RESUME_STATE_RUNNING 0
158 #define RESUME_STATE_SUSPENDING 1
159 #define RESUME_STATE_BACKEND_RESUME 2
160 #define RESUME_STATE_FRONTEND_RESUME 3
162 typedef struct {
163 ULONG magic;
164 USHORT length;
166 ULONG resume_state;
167 ULONG resume_state_ack;
168 } XENPCI_DEVICE_STATE, *PXENPCI_DEVICE_STATE;
170 #define XEN_INIT_DRIVER_EXTENSION_MAGIC ((ULONG)'XCFG')
172 #define XEN_INIT_TYPE_END 0
173 #define XEN_INIT_TYPE_WRITE_STRING 1
174 #define XEN_INIT_TYPE_RING 2
175 #define XEN_INIT_TYPE_EVENT_CHANNEL 3
176 #define XEN_INIT_TYPE_EVENT_CHANNEL_IRQ 4
177 #define XEN_INIT_TYPE_READ_STRING_FRONT 5
178 #define XEN_INIT_TYPE_READ_STRING_BACK 6
179 #define XEN_INIT_TYPE_VECTORS 7
180 #define XEN_INIT_TYPE_GRANT_ENTRIES 8
181 //#define XEN_INIT_TYPE_COPY_PTR 9
182 #define XEN_INIT_TYPE_RUN 10
183 #define XEN_INIT_TYPE_STATE_PTR 11
184 #define XEN_INIT_TYPE_ACTIVE 12
185 #define XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION 13
187 static __inline VOID
188 __ADD_XEN_INIT_UCHAR(PUCHAR *ptr, UCHAR val)
189 {
190 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_UCHAR *ptr = %p, val = %d\n", *ptr, val));
191 *(PUCHAR)(*ptr) = val;
192 *ptr += sizeof(UCHAR);
193 }
195 static __inline VOID
196 __ADD_XEN_INIT_USHORT(PUCHAR *ptr, USHORT val)
197 {
198 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_USHORT *ptr = %p, val = %d\n", *ptr, val));
199 *(PUSHORT)(*ptr) = val;
200 *ptr += sizeof(USHORT);
201 }
203 static __inline VOID
204 __ADD_XEN_INIT_ULONG(PUCHAR *ptr, ULONG val)
205 {
206 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_ULONG *ptr = %p, val = %d\n", *ptr, val));
207 *(PULONG)(*ptr) = val;
208 *ptr += sizeof(ULONG);
209 }
211 static __inline VOID
212 __ADD_XEN_INIT_PTR(PUCHAR *ptr, PVOID val)
213 {
214 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_PTR *ptr = %p, val = %p\n", *ptr, val));
215 *(PVOID *)(*ptr) = val;
216 *ptr += sizeof(PVOID);
217 }
219 static __inline VOID
220 __ADD_XEN_INIT_STRING(PUCHAR *ptr, PCHAR val)
221 {
222 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_STRING *ptr = %p, val = %s\n", *ptr, val));
223 RtlStringCbCopyA((PCHAR)*ptr, PAGE_SIZE - (PtrToUlong(*ptr) & (PAGE_SIZE - 1)), val);
224 *ptr += strlen(val) + 1;
225 }
227 static __inline UCHAR
228 __GET_XEN_INIT_UCHAR(PUCHAR *ptr)
229 {
230 UCHAR retval;
231 retval = **ptr;
232 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_UCHAR *ptr = %p, retval = %d\n", *ptr, retval));
233 *ptr += sizeof(UCHAR);
234 return retval;
235 }
237 static __inline USHORT
238 __GET_XEN_INIT_USHORT(PUCHAR *ptr)
239 {
240 USHORT retval;
241 retval = *(PUSHORT)*ptr;
242 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_USHORT *ptr = %p, retval = %d\n", *ptr, retval));
243 *ptr += sizeof(USHORT);
244 return retval;
245 }
247 static __inline ULONG
248 __GET_XEN_INIT_ULONG(PUCHAR *ptr)
249 {
250 ULONG retval;
251 retval = *(PLONG)*ptr;
252 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_ULONG *ptr = %p, retval = %d\n", *ptr, retval));
253 *ptr += sizeof(ULONG);
254 return retval;
255 }
257 static __inline PCHAR
258 __GET_XEN_INIT_STRING(PUCHAR *ptr)
259 {
260 PCHAR retval;
261 retval = (PCHAR)*ptr;
262 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_STRING *ptr = %p, retval = %s\n", *ptr, retval));
263 *ptr += strlen((PCHAR)*ptr) + 1;
264 return retval;
265 }
267 static __inline PVOID
268 __GET_XEN_INIT_PTR(PUCHAR *ptr)
269 {
270 PVOID retval;
271 retval = *(PVOID *)(*ptr);
272 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_PTR *ptr = %p, retval = %p\n", *ptr, retval));
273 *ptr += sizeof(PVOID);
274 return retval;
275 }
277 static __inline VOID
278 ADD_XEN_INIT_REQ(PUCHAR *ptr, UCHAR type, PVOID p1, PVOID p2)
279 {
280 __ADD_XEN_INIT_UCHAR(ptr, type);
281 switch (type)
282 {
283 case XEN_INIT_TYPE_END:
284 case XEN_INIT_TYPE_VECTORS:
285 case XEN_INIT_TYPE_RUN:
286 case XEN_INIT_TYPE_STATE_PTR:
287 case XEN_INIT_TYPE_ACTIVE:
288 case XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION:
289 break;
290 case XEN_INIT_TYPE_WRITE_STRING:
291 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
292 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p2);
293 break;
294 case XEN_INIT_TYPE_RING:
295 case XEN_INIT_TYPE_EVENT_CHANNEL:
296 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
297 case XEN_INIT_TYPE_READ_STRING_FRONT:
298 case XEN_INIT_TYPE_READ_STRING_BACK:
299 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
300 break;
301 case XEN_INIT_TYPE_GRANT_ENTRIES:
302 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p2));
303 break;
304 // case XEN_INIT_TYPE_COPY_PTR:
305 // __ADD_XEN_INIT_STRING(ptr, p1);
306 // __ADD_XEN_INIT_PTR(ptr, p2);
307 // break;
308 }
309 }
311 static __inline UCHAR
312 GET_XEN_INIT_REQ(PUCHAR *ptr, PVOID *p1, PVOID *p2)
313 {
314 UCHAR retval;
316 retval = __GET_XEN_INIT_UCHAR(ptr);
317 switch (retval)
318 {
319 case XEN_INIT_TYPE_END:
320 case XEN_INIT_TYPE_VECTORS:
321 case XEN_INIT_TYPE_RUN:
322 case XEN_INIT_TYPE_STATE_PTR:
323 case XEN_INIT_TYPE_ACTIVE:
324 case XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION:
325 *p1 = NULL;
326 *p2 = NULL;
327 break;
328 case XEN_INIT_TYPE_WRITE_STRING:
329 *p1 = __GET_XEN_INIT_STRING(ptr);
330 *p2 = __GET_XEN_INIT_STRING(ptr);
331 break;
332 case XEN_INIT_TYPE_RING:
333 case XEN_INIT_TYPE_EVENT_CHANNEL:
334 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
335 case XEN_INIT_TYPE_READ_STRING_FRONT:
336 case XEN_INIT_TYPE_READ_STRING_BACK:
337 *p1 = __GET_XEN_INIT_STRING(ptr);
338 *p2 = NULL;
339 break;
340 case XEN_INIT_TYPE_GRANT_ENTRIES:
341 *p2 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
342 break;
343 // case XEN_INIT_TYPE_COPY_PTR:
344 // *p1 = __GET_XEN_INIT_STRING(ptr);
345 // *p2 = __GET_XEN_INIT_PTR(ptr);
346 // break;
347 }
348 return retval;
349 }
351 static __inline VOID
352 ADD_XEN_INIT_RSP(PUCHAR *ptr, UCHAR type, PVOID p1, PVOID p2)
353 {
354 __ADD_XEN_INIT_UCHAR(ptr, type);
355 switch (type)
356 {
357 case XEN_INIT_TYPE_END:
358 case XEN_INIT_TYPE_WRITE_STRING: /* this shouldn't happen */
359 case XEN_INIT_TYPE_RUN:
360 case XEN_INIT_TYPE_ACTIVE:
361 break;
362 case XEN_INIT_TYPE_RING:
363 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
364 __ADD_XEN_INIT_PTR(ptr, p2);
365 break;
366 case XEN_INIT_TYPE_EVENT_CHANNEL:
367 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
368 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
369 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p2));
370 break;
371 case XEN_INIT_TYPE_READ_STRING_FRONT:
372 case XEN_INIT_TYPE_READ_STRING_BACK:
373 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
374 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p2);
375 break;
376 case XEN_INIT_TYPE_VECTORS:
377 //__ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p1));
378 memcpy(*ptr, p2, sizeof(XENPCI_VECTORS));
379 *ptr += sizeof(XENPCI_VECTORS);
380 break;
381 case XEN_INIT_TYPE_GRANT_ENTRIES:
382 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p1));
383 memcpy(*ptr, p2, PtrToUlong(p1) * sizeof(grant_entry_t));
384 *ptr += PtrToUlong(p1) * sizeof(grant_entry_t);
385 break;
386 case XEN_INIT_TYPE_STATE_PTR:
387 __ADD_XEN_INIT_PTR(ptr, p2);
388 break;
389 case XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION:
390 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p2));
391 break;
392 // case XEN_INIT_TYPE_COPY_PTR:
393 // __ADD_XEN_INIT_STRING(ptr, p1);
394 // __ADD_XEN_INIT_PTR(ptr, p2);
395 // break;
396 }
397 }
399 static __inline UCHAR
400 GET_XEN_INIT_RSP(PUCHAR *ptr, PVOID *p1, PVOID *p2)
401 {
402 UCHAR retval;
404 retval = __GET_XEN_INIT_UCHAR(ptr);
405 switch (retval)
406 {
407 case XEN_INIT_TYPE_END:
408 case XEN_INIT_TYPE_RUN:
409 case XEN_INIT_TYPE_ACTIVE:
410 *p1 = NULL;
411 *p2 = NULL;
412 break;
413 case XEN_INIT_TYPE_WRITE_STRING:
414 // this shouldn't happen - no response here
415 break;
416 case XEN_INIT_TYPE_RING:
417 *p1 = __GET_XEN_INIT_STRING(ptr);
418 *p2 = __GET_XEN_INIT_PTR(ptr);
419 break;
420 case XEN_INIT_TYPE_EVENT_CHANNEL:
421 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
422 *p1 = __GET_XEN_INIT_STRING(ptr);
423 *p2 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
424 break;
425 case XEN_INIT_TYPE_READ_STRING_FRONT:
426 *p1 = __GET_XEN_INIT_STRING(ptr);
427 *p2 = __GET_XEN_INIT_STRING(ptr);
428 break;
429 case XEN_INIT_TYPE_READ_STRING_BACK:
430 *p1 = __GET_XEN_INIT_STRING(ptr);
431 *p2 = __GET_XEN_INIT_STRING(ptr);
432 break;
433 case XEN_INIT_TYPE_VECTORS:
434 *p1 = NULL;
435 *p2 = *ptr;
436 *ptr += ((PXENPCI_VECTORS)*p2)->length;
437 break;
438 case XEN_INIT_TYPE_GRANT_ENTRIES:
439 *p1 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
440 *p2 = *ptr;
441 *ptr += PtrToUlong(*p1) * sizeof(grant_ref_t);
442 break;
443 case XEN_INIT_TYPE_STATE_PTR:
444 *p2 = __GET_XEN_INIT_PTR(ptr);
445 break;
446 case XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION:
447 *p2 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
448 break;
449 // case XEN_INIT_TYPE_COPY_PTR:
450 // *p1 = __GET_XEN_INIT_STRING(ptr);
451 // *p2 = __GET_XEN_INIT_PTR(ptr);
452 }
453 return retval;
454 }
456 #endif