win-pvdrivers

view common/include/xen_windows.h @ 859:658d20a31016

cleanup
author James Harper <james.harper@bendigoit.com.au>
date Sun Feb 27 11:14:20 2011 +1100 (2011-02-27)
parents 1b1fde762e0c
children 60e760e70c21
line source
1 #if !defined(_XEN_WINDOWS_H_)
2 #define _XEN_WINDOWS_H_
4 #include "gplpv_version.h"
6 #pragma warning( disable : 4201 ) // nonstandard extension used : nameless struct/union
7 #pragma warning( disable : 4214 ) // nonstandard extension used : bit field types other than int
8 #pragma warning( disable : 4505 ) // 'XenDbgPrint' : unreferenced local function has been removed
10 #define __XEN_INTERFACE_VERSION__ 0x00030205
11 #if defined(_AMD64_)
12 #define __x86_64__
13 #elif defined(_IA64_)
14 #define __ia64__
15 #elif defined(__MINGW32__)
16 /* __i386__ already defined */
17 #elif defined(_X86_)
18 #define __i386__
19 #else
20 #error Unknown architecture
21 #endif
23 #ifdef __MINGW32__
24 typedef signed char int8_t;
25 typedef unsigned char uint8_t;
26 typedef signed short int16_t;
27 typedef unsigned short uint16_t;
28 typedef signed int int32_t;
29 typedef unsigned int uint32_t;
30 typedef unsigned long long uint64_t;
31 #else
32 typedef INT8 int8_t;
33 typedef UINT8 uint8_t;
34 typedef INT16 int16_t;
35 typedef UINT16 uint16_t;
36 typedef INT32 int32_t;
37 typedef UINT32 uint32_t;
38 typedef UINT64 uint64_t;
39 #endif
41 #include <xen.h>
42 #include <grant_table.h>
43 #include <event_channel.h>
44 #include <xen_guids.h>
46 #define _PAGE_PRESENT 0x001UL
47 #define _PAGE_RW 0x002UL
48 #define _PAGE_USER 0x004UL
49 #define _PAGE_PWT 0x008UL
50 #define _PAGE_PCD 0x010UL
51 #define _PAGE_ACCESSED 0x020UL
52 #define _PAGE_DIRTY 0x040UL
53 #define _PAGE_PAT 0x080UL
54 #define _PAGE_PSE 0x080UL
55 #define _PAGE_GLOBAL 0x100UL
57 #define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED)
59 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
61 typedef unsigned long xenbus_transaction_t;
63 #define XBT_NIL ((xenbus_transaction_t)0)
65 #define SPLITSTRING_POOL_TAG (ULONG) 'SSPT'
67 #define wmb() KeMemoryBarrier()
68 #define mb() KeMemoryBarrier()
70 #define IOCTL_XEN_RECONFIGURE CTL_CODE(0x8000, 0x800, METHOD_NEITHER, 0)
72 static __inline char **
73 SplitString(char *String, char Split, int MaxParts, int *Count)
74 {
75 char **RetVal;
76 char *first;
77 char *last;
79 //KdPrint((__DRIVER_NAME " a\n"));
81 *Count = 0;
83 RetVal = (char **)ExAllocatePoolWithTag(NonPagedPool, (MaxParts + 1) * sizeof(char *), SPLITSTRING_POOL_TAG);
84 last = String;
85 do
86 {
87 if (*Count == MaxParts)
88 break;
89 //KdPrint((__DRIVER_NAME " b - count = %d\n", *Count));
90 first = last;
91 for (last = first; *last != '\0' && *last != Split; last++);
92 RetVal[*Count] = (char *)ExAllocatePoolWithTag(NonPagedPool, last - first + 1, SPLITSTRING_POOL_TAG);
93 //KdPrint((__DRIVER_NAME " c - count = %d\n", *Count));
94 RtlStringCbCopyNA(RetVal[*Count], last - first + 1, first, last - first);
95 RetVal[*Count][last - first] = 0;
96 //KdPrint((__DRIVER_NAME " d - count = %d\n", *Count));
97 (*Count)++;
98 //KdPrint((__DRIVER_NAME " e - count = %d\n", *Count));
99 if (*last == Split)
100 last++;
101 } while (*last != 0);
102 //KdPrint((__DRIVER_NAME " f - count = %d\n", *Count));
103 RetVal[*Count] = NULL;
104 return RetVal;
105 }
107 static __inline VOID
108 FreeSplitString(char **Bits, int Count)
109 {
110 int i;
112 for (i = 0; i < Count; i++)
113 ExFreePoolWithTag(Bits[i], SPLITSTRING_POOL_TAG);
114 ExFreePoolWithTag(Bits, SPLITSTRING_POOL_TAG);
115 }
117 #define ALLOCATE_PAGES_POOL_TAG (ULONG) 'APPT'
119 static PMDL
120 AllocatePagesExtra(int Pages, int ExtraSize)
121 {
122 PMDL Mdl;
123 PVOID Buf;
125 Buf = ExAllocatePoolWithTag(NonPagedPool, Pages * PAGE_SIZE, ALLOCATE_PAGES_POOL_TAG);
126 if (Buf == NULL)
127 {
128 KdPrint((__DRIVER_NAME " AllocatePages Failed at ExAllocatePoolWithTag\n"));
129 return NULL;
130 }
131 // KdPrint((__DRIVER_NAME " --- AllocatePages IRQL = %d, Buf = %p\n", KeGetCurrentIrql(), Buf));
132 Mdl = (PMDL)ExAllocatePoolWithTag(NonPagedPool, MmSizeOfMdl(Buf, Pages * PAGE_SIZE) + ExtraSize, ALLOCATE_PAGES_POOL_TAG);
133 if (Mdl == NULL)
134 {
135 // free the memory here
136 KdPrint((__DRIVER_NAME " AllocatePages Failed at IoAllocateMdl\n"));
137 return NULL;
138 }
140 MmInitializeMdl(Mdl, Buf, Pages * PAGE_SIZE);
141 MmBuildMdlForNonPagedPool(Mdl);
143 return Mdl;
144 }
146 static __inline PMDL
147 AllocatePages(int Pages)
148 {
149 return AllocatePagesExtra(Pages, 0);
150 }
152 static __inline PMDL
153 AllocatePage()
154 {
155 return AllocatePagesExtra(1, 0);
156 }
158 static __inline PMDL
159 AllocateUncachedPage()
160 {
161 PMDL mdl;
162 PVOID buf;
164 buf = MmAllocateNonCachedMemory(PAGE_SIZE);
165 mdl = IoAllocateMdl(buf, PAGE_SIZE, FALSE, FALSE, NULL);
166 MmBuildMdlForNonPagedPool(mdl);
168 return mdl;
169 }
171 static __inline VOID
172 FreeUncachedPage(PMDL mdl)
173 {
174 PVOID buf = MmGetMdlVirtualAddress(mdl);
176 IoFreeMdl(mdl);
177 MmFreeNonCachedMemory(buf, PAGE_SIZE);
178 }
180 static __inline VOID
181 FreePages(PMDL Mdl)
182 {
183 PVOID Buf = MmGetMdlVirtualAddress(Mdl);
184 // KdPrint((__DRIVER_NAME " --- FreePages IRQL = %d, Buf = %p\n", KeGetCurrentIrql(), Buf));
185 // IoFreeMdl(Mdl);
186 ExFreePoolWithTag(Mdl, ALLOCATE_PAGES_POOL_TAG);
187 ExFreePoolWithTag(Buf, ALLOCATE_PAGES_POOL_TAG);
188 }
190 #define XEN_IOPORT_BASE 0x10
192 /*
193 define these as pointers so that the READ_PORT* functions complain if
194 the wrong width is used with the wrong defined port
195 */
197 #define XEN_IOPORT_MAGIC ((PUSHORT)UlongToPtr(XEN_IOPORT_BASE + 0))
198 #define XEN_IOPORT_LOG ((PUCHAR)UlongToPtr(XEN_IOPORT_BASE + 2))
199 #define XEN_IOPORT_VERSION ((PUCHAR)UlongToPtr(XEN_IOPORT_BASE + 2))
200 #define XEN_IOPORT_PRODUCT ((PUSHORT)UlongToPtr(XEN_IOPORT_BASE + 2))
201 #define XEN_IOPORT_BUILD ((PULONG)UlongToPtr(XEN_IOPORT_BASE + 0))
202 #define XEN_IOPORT_DEVICE_MASK ((PUSHORT)UlongToPtr(XEN_IOPORT_BASE + 0))
204 #define QEMU_UNPLUG_ALL_IDE_DISKS 1
205 #define QEMU_UNPLUG_ALL_NICS 2
206 #define QEMU_UNPLUG_AUX_IDE_DISKS 4
208 #define FUNCTION_ENTER() KdPrint((__DRIVER_NAME " --> %s\n", __FUNCTION__))
209 #define FUNCTION_EXIT() KdPrint((__DRIVER_NAME " <-- %s\n", __FUNCTION__))
210 #define FUNCTION_EXIT_STATUS(_status) KdPrint((__DRIVER_NAME " <-- %s, status = %08x\n", __FUNCTION__, _status))
211 #define FUNCTION_MSG(...) KdPrint((__DRIVER_NAME " " __VA_ARGS__))
213 #define INVALID_GRANT_REF 0xFFFFFFFF
215 typedef PHYSICAL_ADDRESS
216 (*PXEN_ALLOCMMIO)(PVOID Context, ULONG Length);
218 typedef void
219 (*PXEN_FREEMEM)(PVOID Ptr);
221 typedef VOID
222 (*PXEN_EVTCHN_SERVICE_ROUTINE)(PVOID Context);
224 typedef NTSTATUS
225 (*PXEN_EVTCHN_BIND)(PVOID Context, evtchn_port_t Port, PXEN_EVTCHN_SERVICE_ROUTINE ServiceRoutine, PVOID ServiceContext);
227 typedef NTSTATUS
228 (*PXEN_EVTCHN_UNBIND)(PVOID Context, evtchn_port_t Port);
230 typedef NTSTATUS
231 (*PXEN_EVTCHN_MASK)(PVOID Context, evtchn_port_t Port);
233 typedef NTSTATUS
234 (*PXEN_EVTCHN_UNMASK)(PVOID Context, evtchn_port_t Port);
236 typedef NTSTATUS
237 (*PXEN_EVTCHN_NOTIFY)(PVOID Context, evtchn_port_t Port);
239 typedef evtchn_port_t
240 (*PXEN_EVTCHN_ALLOCUNBOUND)(PVOID Context, domid_t Domain);
242 typedef BOOLEAN
243 (*PXEN_EVTCHN_ACK_EVENT)(PVOID context, evtchn_port_t port, BOOLEAN *last_interrupt);
245 typedef BOOLEAN
246 (*PXEN_EVTCHN_SYNC_ROUTINE)(PVOID sync_context);
248 typedef BOOLEAN
249 (*PXEN_EVTCHN_SYNC)(PVOID Context, PXEN_EVTCHN_SYNC_ROUTINE sync_routine, PVOID sync_context);
251 typedef grant_ref_t
252 (*PXEN_GNTTBL_GRANTACCESS)(PVOID Context, domid_t domid, uint32_t frame, int readonly, grant_ref_t ref, ULONG tag);
254 typedef BOOLEAN
255 (*PXEN_GNTTBL_ENDACCESS)(PVOID Context, grant_ref_t ref, BOOLEAN keepref, ULONG tag);
257 typedef VOID
258 (*PXEN_GNTTBL_PUTREF)(PVOID Context, grant_ref_t ref, ULONG tag);
260 typedef grant_ref_t
261 (*PXEN_GNTTBL_GETREF)(PVOID Context, ULONG tag);
264 typedef VOID
265 (*PXENBUS_WATCH_CALLBACK)(char *Path, PVOID ServiceContext);
267 typedef char *
268 (*PXEN_XENBUS_READ)(PVOID Context, xenbus_transaction_t xbt, char *path, char **value);
270 typedef char *
271 (*PXEN_XENBUS_WRITE)(PVOID Context, xenbus_transaction_t xbt, char *path, char *value);
273 typedef char *
274 (*PXEN_XENBUS_PRINTF)(PVOID Context, xenbus_transaction_t xbt, char *path, char *fmt, ...);
276 typedef char *
277 (*PXEN_XENBUS_STARTTRANSACTION)(PVOID Context, xenbus_transaction_t *xbt);
279 typedef char *
280 (*PXEN_XENBUS_ENDTRANSACTION)(PVOID Context, xenbus_transaction_t t, int abort, int *retry);
282 typedef char *
283 (*PXEN_XENBUS_LIST)(PVOID Context, xenbus_transaction_t xbt, char *prefix, char ***contents);
285 typedef char *
286 (*PXEN_XENBUS_ADDWATCH)(PVOID Context, xenbus_transaction_t xbt, char *Path, PXENBUS_WATCH_CALLBACK ServiceRoutine, PVOID ServiceContext);
288 typedef char *
289 (*PXEN_XENBUS_REMWATCH)(PVOID Context, xenbus_transaction_t xbt, char *Path, PXENBUS_WATCH_CALLBACK ServiceRoutine, PVOID ServiceContext);
291 typedef NTSTATUS
292 (*PXEN_XENPCI_XEN_CONFIG_DEVICE)(PVOID Context);
294 typedef NTSTATUS
295 (*PXEN_XENPCI_XEN_SHUTDOWN_DEVICE)(PVOID Context);
297 #ifndef XENPCI_POOL_TAG
298 #define XENPCI_POOL_TAG (ULONG) 'XenP'
299 #endif
301 static __inline VOID
302 XenPci_FreeMem(PVOID Ptr)
303 {
304 ExFreePoolWithTag(Ptr, XENPCI_POOL_TAG);
305 }
307 #define XEN_DATA_MAGIC 0x12345679
309 typedef struct {
310 ULONG magic;
311 USHORT length;
313 PVOID context;
314 PXEN_EVTCHN_BIND EvtChn_Bind;
315 PXEN_EVTCHN_BIND EvtChn_BindDpc;
316 PXEN_EVTCHN_UNBIND EvtChn_Unbind;
317 PXEN_EVTCHN_MASK EvtChn_Mask;
318 PXEN_EVTCHN_UNMASK EvtChn_Unmask;
319 PXEN_EVTCHN_NOTIFY EvtChn_Notify;
320 PXEN_EVTCHN_ACK_EVENT EvtChn_AckEvent;
321 PXEN_EVTCHN_SYNC EvtChn_Sync;
323 PXEN_GNTTBL_GETREF GntTbl_GetRef;
324 PXEN_GNTTBL_PUTREF GntTbl_PutRef;
325 PXEN_GNTTBL_GRANTACCESS GntTbl_GrantAccess;
326 PXEN_GNTTBL_ENDACCESS GntTbl_EndAccess;
328 PXEN_XENPCI_XEN_CONFIG_DEVICE XenPci_XenConfigDevice;
329 PXEN_XENPCI_XEN_SHUTDOWN_DEVICE XenPci_XenShutdownDevice;
331 CHAR path[128];
332 CHAR backend_path[128];
334 PXEN_XENBUS_READ XenBus_Read;
335 PXEN_XENBUS_WRITE XenBus_Write;
336 PXEN_XENBUS_PRINTF XenBus_Printf;
337 PXEN_XENBUS_STARTTRANSACTION XenBus_StartTransaction;
338 PXEN_XENBUS_ENDTRANSACTION XenBus_EndTransaction;
339 PXEN_XENBUS_LIST XenBus_List;
340 PXEN_XENBUS_ADDWATCH XenBus_AddWatch;
341 PXEN_XENBUS_REMWATCH XenBus_RemWatch;
343 } XENPCI_VECTORS, *PXENPCI_VECTORS;
345 /*
346 suspend_resume_state_xxx values
347 pdo will assert a value, and fdo will assert when complete
348 */
349 #define SR_STATE_RUNNING 0 /* normal working state */
350 #define SR_STATE_SUSPENDING 1 /* suspend has started */
351 #define SR_STATE_RESUMING 2 /* resume has started */
353 #define XEN_DEVICE_STATE_MAGIC ((ULONG)'XDST')
355 typedef struct {
356 ULONG magic;
357 USHORT length;
359 ULONG suspend_resume_state_pdo; /* only the PDO can touch this */
360 ULONG suspend_resume_state_fdo; /* only the FDO can touch this */
361 evtchn_port_t pdo_event_channel;
362 } XENPCI_DEVICE_STATE, *PXENPCI_DEVICE_STATE;
364 #define XEN_INIT_DRIVER_EXTENSION_MAGIC ((ULONG)'XCFG')
365 #define XEN_DMA_DRIVER_EXTENSION_MAGIC ((ULONG)'XDMA')
367 #define XEN_INIT_TYPE_END 0
368 #define XEN_INIT_TYPE_WRITE_STRING 1
369 #define XEN_INIT_TYPE_RING 2
370 #define XEN_INIT_TYPE_EVENT_CHANNEL 3
371 #define XEN_INIT_TYPE_EVENT_CHANNEL_IRQ 4
372 #define XEN_INIT_TYPE_READ_STRING_FRONT 5
373 #define XEN_INIT_TYPE_READ_STRING_BACK 6
374 #define XEN_INIT_TYPE_VECTORS 7
375 #define XEN_INIT_TYPE_GRANT_ENTRIES 8
376 #define XEN_INIT_TYPE_STATE_PTR 11
377 #define XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION 13
378 #define XEN_INIT_TYPE_EVENT_CHANNEL_DPC 16
379 #define XEN_INIT_TYPE_QEMU_HIDE_FLAGS 17 /* qemu hide flags */
380 #define XEN_INIT_TYPE_QEMU_HIDE_FILTER 18 /* qemu device hidden by class filter */
381 /*
382 state maps consist of 3 bytes: (maximum of 4 x 3 bytes)
383 front - state to set frontend to
384 back - state to expect from backend
385 wait - time in 100ms intervals to wait for backend
386 a single 0 byte terminates the list
387 */
388 #define XEN_INIT_TYPE_XB_STATE_MAP_PRE_CONNECT 19
389 #define XEN_INIT_TYPE_XB_STATE_MAP_POST_CONNECT 20
390 #define XEN_INIT_TYPE_XB_STATE_MAP_SHUTDOWN 21
392 static __inline VOID
393 __ADD_XEN_INIT_UCHAR(PUCHAR *ptr, UCHAR val)
394 {
395 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_UCHAR *ptr = %p, val = %d\n", *ptr, val));
396 *(PUCHAR)(*ptr) = val;
397 *ptr += sizeof(UCHAR);
398 }
400 static __inline VOID
401 __ADD_XEN_INIT_USHORT(PUCHAR *ptr, USHORT val)
402 {
403 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_USHORT *ptr = %p, val = %d\n", *ptr, val));
404 *(PUSHORT)(*ptr) = val;
405 *ptr += sizeof(USHORT);
406 }
408 static __inline VOID
409 __ADD_XEN_INIT_ULONG(PUCHAR *ptr, ULONG val)
410 {
411 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_ULONG *ptr = %p, val = %d\n", *ptr, val));
412 *(PULONG)(*ptr) = val;
413 *ptr += sizeof(ULONG);
414 }
416 static __inline VOID
417 __ADD_XEN_INIT_PTR(PUCHAR *ptr, PVOID val)
418 {
419 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_PTR *ptr = %p, val = %p\n", *ptr, val));
420 *(PVOID *)(*ptr) = val;
421 *ptr += sizeof(PVOID);
422 }
424 static __inline VOID
425 __ADD_XEN_INIT_STRING(PUCHAR *ptr, PCHAR val)
426 {
427 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_STRING *ptr = %p, val = %s\n", *ptr, val));
428 size_t max_string_size = PAGE_SIZE - (PtrToUlong(*ptr) & (PAGE_SIZE - 1));
429 RtlStringCbCopyA((PCHAR)*ptr, max_string_size, val);
430 *ptr += min(strlen(val) + 1, max_string_size);
431 }
433 static __inline UCHAR
434 __GET_XEN_INIT_UCHAR(PUCHAR *ptr)
435 {
436 UCHAR retval;
437 retval = **ptr;
438 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_UCHAR *ptr = %p, retval = %d\n", *ptr, retval));
439 *ptr += sizeof(UCHAR);
440 return retval;
441 }
443 static __inline USHORT
444 __GET_XEN_INIT_USHORT(PUCHAR *ptr)
445 {
446 USHORT retval;
447 retval = *(PUSHORT)*ptr;
448 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_USHORT *ptr = %p, retval = %d\n", *ptr, retval));
449 *ptr += sizeof(USHORT);
450 return retval;
451 }
453 static __inline ULONG
454 __GET_XEN_INIT_ULONG(PUCHAR *ptr)
455 {
456 ULONG retval;
457 retval = *(PLONG)*ptr;
458 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_ULONG *ptr = %p, retval = %d\n", *ptr, retval));
459 *ptr += sizeof(ULONG);
460 return retval;
461 }
463 static __inline PCHAR
464 __GET_XEN_INIT_STRING(PUCHAR *ptr)
465 {
466 PCHAR retval;
467 retval = (PCHAR)*ptr;
468 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_STRING *ptr = %p, retval = %s\n", *ptr, retval));
469 *ptr += strlen((PCHAR)*ptr) + 1;
470 return retval;
471 }
473 static __inline PVOID
474 __GET_XEN_INIT_PTR(PUCHAR *ptr)
475 {
476 PVOID retval;
477 retval = *(PVOID *)(*ptr);
478 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_PTR *ptr = %p, retval = %p\n", *ptr, retval));
479 *ptr += sizeof(PVOID);
480 return retval;
481 }
483 static __inline VOID
484 ADD_XEN_INIT_REQ(PUCHAR *ptr, UCHAR type, PVOID p1, PVOID p2, PVOID p3)
485 {
486 __ADD_XEN_INIT_UCHAR(ptr, type);
487 switch (type)
488 {
489 case XEN_INIT_TYPE_END:
490 case XEN_INIT_TYPE_VECTORS:
491 case XEN_INIT_TYPE_STATE_PTR:
492 case XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION:
493 case XEN_INIT_TYPE_QEMU_HIDE_FLAGS:
494 case XEN_INIT_TYPE_QEMU_HIDE_FILTER:
495 case XEN_INIT_TYPE_XB_STATE_MAP_PRE_CONNECT:
496 case XEN_INIT_TYPE_XB_STATE_MAP_POST_CONNECT:
497 case XEN_INIT_TYPE_XB_STATE_MAP_SHUTDOWN:
498 break;
499 case XEN_INIT_TYPE_WRITE_STRING:
500 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
501 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p2);
502 break;
503 case XEN_INIT_TYPE_RING:
504 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
505 case XEN_INIT_TYPE_READ_STRING_FRONT:
506 case XEN_INIT_TYPE_READ_STRING_BACK:
507 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
508 break;
509 case XEN_INIT_TYPE_EVENT_CHANNEL:
510 case XEN_INIT_TYPE_EVENT_CHANNEL_DPC:
511 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
512 __ADD_XEN_INIT_PTR(ptr, p2);
513 __ADD_XEN_INIT_PTR(ptr, p3);
514 break;
515 case XEN_INIT_TYPE_GRANT_ENTRIES:
516 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p1));
517 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p2));
518 break;
519 // case XEN_INIT_TYPE_COPY_PTR:
520 // __ADD_XEN_INIT_STRING(ptr, p1);
521 // __ADD_XEN_INIT_PTR(ptr, p2);
522 // break;
523 }
524 }
526 static __inline UCHAR
527 GET_XEN_INIT_REQ(PUCHAR *ptr, PVOID *p1, PVOID *p2, PVOID *p3)
528 {
529 UCHAR retval;
531 retval = __GET_XEN_INIT_UCHAR(ptr);
532 switch (retval)
533 {
534 case XEN_INIT_TYPE_END:
535 case XEN_INIT_TYPE_VECTORS:
536 case XEN_INIT_TYPE_STATE_PTR:
537 case XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION:
538 case XEN_INIT_TYPE_XB_STATE_MAP_PRE_CONNECT:
539 case XEN_INIT_TYPE_XB_STATE_MAP_POST_CONNECT:
540 case XEN_INIT_TYPE_XB_STATE_MAP_SHUTDOWN:
541 *p1 = NULL;
542 *p2 = NULL;
543 break;
544 case XEN_INIT_TYPE_WRITE_STRING:
545 *p1 = __GET_XEN_INIT_STRING(ptr);
546 *p2 = __GET_XEN_INIT_STRING(ptr);
547 break;
548 case XEN_INIT_TYPE_RING:
549 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
550 case XEN_INIT_TYPE_READ_STRING_FRONT:
551 case XEN_INIT_TYPE_READ_STRING_BACK:
552 *p1 = __GET_XEN_INIT_STRING(ptr);
553 *p2 = NULL;
554 break;
555 case XEN_INIT_TYPE_EVENT_CHANNEL:
556 case XEN_INIT_TYPE_EVENT_CHANNEL_DPC:
557 *p1 = __GET_XEN_INIT_STRING(ptr);
558 *p2 = __GET_XEN_INIT_PTR(ptr);
559 *p3 = __GET_XEN_INIT_PTR(ptr);
560 break;
561 case XEN_INIT_TYPE_GRANT_ENTRIES:
562 *p1 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
563 *p2 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
564 break;
565 }
566 return retval;
567 }
569 static __inline VOID
570 ADD_XEN_INIT_RSP(PUCHAR *ptr, UCHAR type, PVOID p1, PVOID p2, PVOID p3)
571 {
572 UNREFERENCED_PARAMETER(p3);
574 __ADD_XEN_INIT_UCHAR(ptr, type);
575 switch (type)
576 {
577 case XEN_INIT_TYPE_END:
578 case XEN_INIT_TYPE_WRITE_STRING: /* this shouldn't happen */
579 case XEN_INIT_TYPE_QEMU_HIDE_FILTER:
580 break;
581 case XEN_INIT_TYPE_RING:
582 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
583 __ADD_XEN_INIT_PTR(ptr, p2);
584 break;
585 case XEN_INIT_TYPE_EVENT_CHANNEL:
586 case XEN_INIT_TYPE_EVENT_CHANNEL_DPC:
587 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
588 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
589 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p2));
590 break;
591 case XEN_INIT_TYPE_READ_STRING_FRONT:
592 case XEN_INIT_TYPE_READ_STRING_BACK:
593 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
594 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p2);
595 break;
596 case XEN_INIT_TYPE_VECTORS:
597 //__ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p1));
598 memcpy(*ptr, p2, sizeof(XENPCI_VECTORS));
599 *ptr += sizeof(XENPCI_VECTORS);
600 break;
601 case XEN_INIT_TYPE_GRANT_ENTRIES:
602 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p1));
603 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p2));
604 memcpy(*ptr, p3, PtrToUlong(p2) * sizeof(grant_entry_t));
605 *ptr += PtrToUlong(p2) * sizeof(grant_entry_t);
606 break;
607 case XEN_INIT_TYPE_QEMU_HIDE_FLAGS:
608 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p2));
609 break;
610 case XEN_INIT_TYPE_STATE_PTR:
611 __ADD_XEN_INIT_PTR(ptr, p2);
612 break;
613 case XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION:
614 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p2));
615 break;
616 }
617 }
619 static __inline UCHAR
620 GET_XEN_INIT_RSP(PUCHAR *ptr, PVOID *p1, PVOID *p2, PVOID *p3)
621 {
622 UCHAR retval;
624 UNREFERENCED_PARAMETER(p3);
626 retval = __GET_XEN_INIT_UCHAR(ptr);
627 switch (retval)
628 {
629 case XEN_INIT_TYPE_END:
630 case XEN_INIT_TYPE_QEMU_HIDE_FILTER:
631 *p1 = NULL;
632 *p2 = NULL;
633 break;
634 case XEN_INIT_TYPE_WRITE_STRING:
635 // this shouldn't happen - no response here
636 break;
637 case XEN_INIT_TYPE_RING:
638 *p1 = __GET_XEN_INIT_STRING(ptr);
639 *p2 = __GET_XEN_INIT_PTR(ptr);
640 break;
641 case XEN_INIT_TYPE_EVENT_CHANNEL:
642 case XEN_INIT_TYPE_EVENT_CHANNEL_DPC:
643 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
644 *p1 = __GET_XEN_INIT_STRING(ptr);
645 *p2 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
646 break;
647 case XEN_INIT_TYPE_READ_STRING_FRONT:
648 *p1 = __GET_XEN_INIT_STRING(ptr);
649 *p2 = __GET_XEN_INIT_STRING(ptr);
650 break;
651 case XEN_INIT_TYPE_READ_STRING_BACK:
652 *p1 = __GET_XEN_INIT_STRING(ptr);
653 *p2 = __GET_XEN_INIT_STRING(ptr);
654 break;
655 case XEN_INIT_TYPE_VECTORS:
656 *p1 = NULL;
657 *p2 = *ptr;
658 *ptr += ((PXENPCI_VECTORS)*p2)->length;
659 break;
660 case XEN_INIT_TYPE_GRANT_ENTRIES:
661 *p1 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
662 *p2 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
663 *p3 = *ptr;
664 *ptr += PtrToUlong(*p2) * sizeof(grant_ref_t);
665 break;
666 case XEN_INIT_TYPE_STATE_PTR:
667 *p2 = __GET_XEN_INIT_PTR(ptr);
668 break;
669 case XEN_INIT_TYPE_QEMU_HIDE_FLAGS:
670 *p2 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
671 break;
672 case XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION:
673 *p2 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
674 break;
675 }
676 return retval;
677 }
679 typedef BOOLEAN
680 (*PXEN_DMA_NEED_VIRTUAL_ADDRESS)(PIRP irp);
682 typedef ULONG
683 (*PXEN_DMA_GET_ALIGNMENT)(PIRP irp);
685 typedef struct {
686 PXEN_DMA_NEED_VIRTUAL_ADDRESS need_virtual_address;
687 PXEN_DMA_GET_ALIGNMENT get_alignment;
688 ULONG max_sg_elements;
689 } dma_driver_extension_t;
691 #endif