win-pvdrivers

view common/include/xen_windows.h @ 911:60e760e70c21

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