win-pvdrivers

view common/include/xen_windows.h @ 670:b59c7dfdee9b

Updates to support latest pre-release version of pvusb. No longer compatible with current version.
author James Harper <james.harper@bendigoit.com.au>
date Wed Sep 23 17:06:30 2009 +1000 (2009-09-23)
parents 0351906626c2
children bdabcc424aec
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 strncpy(RetVal[*Count], 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 //Mdl = IoAllocateMdl(Buf, Pages * PAGE_SIZE, FALSE, FALSE, NULL);
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 static BOOLEAN debug_port_probed = FALSE;
210 static BOOLEAN debug_port_enabled;
212 static void XenDbgPrint(PCHAR format, ...)
213 {
214 CHAR buf[512];
215 va_list ap;
216 ULONG i;
217 //int cpu;
218 KIRQL old_irql = 0;
220 if (!debug_port_probed)
221 {
222 if (READ_PORT_USHORT(XEN_IOPORT_MAGIC) == 0x49d2
223 || READ_PORT_USHORT(XEN_IOPORT_MAGIC) == 0xd249)
224 {
225 debug_port_enabled = TRUE;
226 }
227 else
228 {
229 debug_port_enabled = FALSE;
230 }
231 debug_port_probed = TRUE;
232 }
233 va_start(ap, format);
234 RtlStringCbVPrintfA(buf, ARRAY_SIZE(buf), format, ap);
235 va_end(ap);
236 DbgPrint(buf);
238 if (debug_port_enabled)
239 {
240 KeRaiseIrql(HIGH_LEVEL, &old_irql);
241 //cpu = KeGetCurrentProcessorNumber() & 0x07;
242 for (i = 0; i < strlen(buf); i++)
243 {
244 WRITE_PORT_UCHAR(XEN_IOPORT_LOG, buf[i]);
245 }
246 KeLowerIrql(old_irql);
247 }
248 }
250 static VOID
251 XenRtlAssert(PCHAR expr, PCHAR filename, ULONG line_number)
252 {
253 XenDbgPrint("Failed ASSERTion '%s' at %s:%d\n", expr, filename, line_number);
254 RtlAssert(expr, filename, line_number, NULL);
255 }
258 #if 1
259 #ifdef KdPrint
260 #undef KdPrint
261 #endif
262 #define KdPrint(_x_) XenDbgPrint _x_
263 #endif
265 #ifdef ASSERT
266 #undef ASSERT
267 #endif
268 #define ASSERT( exp ) ((!(exp)) ? (XenRtlAssert( #exp, __FILE__, __LINE__), FALSE) : TRUE)
270 #define FUNCTION_ENTER() XenDbgPrint(__DRIVER_NAME " --> %s\n", __FUNCTION__)
271 #define FUNCTION_EXIT() XenDbgPrint(__DRIVER_NAME " <-- %s\n", __FUNCTION__)
272 #define FUNCTION_EXIT_STATUS(_status) XenDbgPrint(__DRIVER_NAME " <-- %s, status = %08x\n", __FUNCTION__, _status)
273 #define FUNCTION_ERROR_EXIT() XenDbgPrint(__DRIVER_NAME " <-- %s (error path)\n", __FUNCTION__)
274 #define FUNCTION_CALLED() XenDbgPrint(__DRIVER_NAME " %s called (line %d)\n", __FUNCTION__, __LINE__)
275 #ifdef __MINGW32__
276 #define FUNCTION_MSG(_x) _FUNCTION_MSG _x
277 #define _FUNCTION_MSG(format, args...) XenDbgPrint(__DRIVER_NAME " %s called: " format, __FUNCTION__, ##args)
278 #else
279 #define FUNCTION_MSG(format, ...) XenDbgPrint(__DRIVER_NAME " " format, __VA_ARGS__)
280 #endif
282 #define INVALID_GRANT_REF 0xFFFFFFFF
284 typedef PHYSICAL_ADDRESS
285 (*PXEN_ALLOCMMIO)(PVOID Context, ULONG Length);
287 typedef void
288 (*PXEN_FREEMEM)(PVOID Ptr);
290 typedef VOID
291 (*PXEN_EVTCHN_SERVICE_ROUTINE)(PVOID Context);
293 typedef NTSTATUS
294 (*PXEN_EVTCHN_BIND)(PVOID Context, evtchn_port_t Port, PXEN_EVTCHN_SERVICE_ROUTINE ServiceRoutine, PVOID ServiceContext);
296 typedef NTSTATUS
297 (*PXEN_EVTCHN_UNBIND)(PVOID Context, evtchn_port_t Port);
299 typedef NTSTATUS
300 (*PXEN_EVTCHN_MASK)(PVOID Context, evtchn_port_t Port);
302 typedef NTSTATUS
303 (*PXEN_EVTCHN_UNMASK)(PVOID Context, evtchn_port_t Port);
305 typedef NTSTATUS
306 (*PXEN_EVTCHN_NOTIFY)(PVOID Context, evtchn_port_t Port);
308 typedef evtchn_port_t
309 (*PXEN_EVTCHN_ALLOCUNBOUND)(PVOID Context, domid_t Domain);
311 typedef BOOLEAN
312 (*PXEN_EVTCHN_ACK_EVENT)(PVOID context, evtchn_port_t port, BOOLEAN *last_interrupt);
314 typedef BOOLEAN
315 (*PXEN_EVTCHN_SYNC_ROUTINE)(PVOID sync_context);
317 typedef BOOLEAN
318 (*PXEN_EVTCHN_SYNC)(PVOID Context, PXEN_EVTCHN_SYNC_ROUTINE sync_routine, PVOID sync_context);
320 typedef grant_ref_t
321 (*PXEN_GNTTBL_GRANTACCESS)(PVOID Context, domid_t domid, uint32_t frame, int readonly, grant_ref_t ref);
323 typedef BOOLEAN
324 (*PXEN_GNTTBL_ENDACCESS)(PVOID Context, grant_ref_t ref, BOOLEAN keepref);
326 typedef VOID
327 (*PXEN_GNTTBL_PUTREF)(PVOID Context, grant_ref_t ref);
329 typedef grant_ref_t
330 (*PXEN_GNTTBL_GETREF)(PVOID Context);
333 typedef VOID
334 (*PXENBUS_WATCH_CALLBACK)(char *Path, PVOID ServiceContext);
336 typedef char *
337 (*PXEN_XENBUS_READ)(PVOID Context, xenbus_transaction_t xbt, char *path, char **value);
339 typedef char *
340 (*PXEN_XENBUS_WRITE)(PVOID Context, xenbus_transaction_t xbt, char *path, char *value);
342 typedef char *
343 (*PXEN_XENBUS_PRINTF)(PVOID Context, xenbus_transaction_t xbt, char *path, char *fmt, ...);
345 typedef char *
346 (*PXEN_XENBUS_STARTTRANSACTION)(PVOID Context, xenbus_transaction_t *xbt);
348 typedef char *
349 (*PXEN_XENBUS_ENDTRANSACTION)(PVOID Context, xenbus_transaction_t t, int abort, int *retry);
351 typedef char *
352 (*PXEN_XENBUS_LIST)(PVOID Context, xenbus_transaction_t xbt, char *prefix, char ***contents);
354 typedef char *
355 (*PXEN_XENBUS_ADDWATCH)(PVOID Context, xenbus_transaction_t xbt, char *Path, PXENBUS_WATCH_CALLBACK ServiceRoutine, PVOID ServiceContext);
357 typedef char *
358 (*PXEN_XENBUS_REMWATCH)(PVOID Context, xenbus_transaction_t xbt, char *Path, PXENBUS_WATCH_CALLBACK ServiceRoutine, PVOID ServiceContext);
360 typedef NTSTATUS
361 (*PXEN_XENPCI_XEN_CONFIG_DEVICE)(PVOID Context);
363 typedef NTSTATUS
364 (*PXEN_XENPCI_XEN_SHUTDOWN_DEVICE)(PVOID Context);
366 #ifndef XENPCI_POOL_TAG
367 #define XENPCI_POOL_TAG (ULONG) 'XenP'
368 #endif
370 static __inline VOID
371 XenPci_FreeMem(PVOID Ptr)
372 {
373 ExFreePoolWithTag(Ptr, XENPCI_POOL_TAG);
374 }
376 #define XEN_DATA_MAGIC 0x12345678
378 typedef struct {
379 ULONG magic;
380 USHORT length;
382 PVOID context;
383 PXEN_EVTCHN_BIND EvtChn_Bind;
384 PXEN_EVTCHN_BIND EvtChn_BindDpc;
385 PXEN_EVTCHN_UNBIND EvtChn_Unbind;
386 PXEN_EVTCHN_MASK EvtChn_Mask;
387 PXEN_EVTCHN_UNMASK EvtChn_Unmask;
388 PXEN_EVTCHN_NOTIFY EvtChn_Notify;
389 PXEN_EVTCHN_ACK_EVENT EvtChn_AckEvent;
390 PXEN_EVTCHN_SYNC EvtChn_Sync;
392 PXEN_GNTTBL_GETREF GntTbl_GetRef;
393 PXEN_GNTTBL_PUTREF GntTbl_PutRef;
394 PXEN_GNTTBL_GRANTACCESS GntTbl_GrantAccess;
395 PXEN_GNTTBL_ENDACCESS GntTbl_EndAccess;
397 PXEN_XENPCI_XEN_CONFIG_DEVICE XenPci_XenConfigDevice;
398 PXEN_XENPCI_XEN_SHUTDOWN_DEVICE XenPci_XenShutdownDevice;
400 CHAR path[128];
401 CHAR backend_path[128];
403 PXEN_XENBUS_READ XenBus_Read;
404 PXEN_XENBUS_WRITE XenBus_Write;
405 PXEN_XENBUS_PRINTF XenBus_Printf;
406 PXEN_XENBUS_STARTTRANSACTION XenBus_StartTransaction;
407 PXEN_XENBUS_ENDTRANSACTION XenBus_EndTransaction;
408 PXEN_XENBUS_LIST XenBus_List;
409 PXEN_XENBUS_ADDWATCH XenBus_AddWatch;
410 PXEN_XENBUS_REMWATCH XenBus_RemWatch;
412 } XENPCI_VECTORS, *PXENPCI_VECTORS;
414 /*
415 suspend_resume_state_xxx values
416 pdo will assert a value, and fdo will assert when complete
417 */
418 #define SR_STATE_RUNNING 0 /* normal working state */
419 #define SR_STATE_SUSPENDING 1 /* suspend has started */
420 #define SR_STATE_RESUMING 2 /* resume has started */
422 #define XEN_DEVICE_STATE_MAGIC ((ULONG)'XDST')
424 typedef struct {
425 ULONG magic;
426 USHORT length;
428 ULONG suspend_resume_state_pdo; /* only the PDO can touch this */
429 ULONG suspend_resume_state_fdo; /* only the FDO can touch this */
430 evtchn_port_t pdo_event_channel;
431 } XENPCI_DEVICE_STATE, *PXENPCI_DEVICE_STATE;
433 #define XEN_INIT_DRIVER_EXTENSION_MAGIC ((ULONG)'XCFG')
434 #define XEN_DMA_DRIVER_EXTENSION_MAGIC ((ULONG)'XDMA')
436 #define XEN_INIT_TYPE_END 0
437 #define XEN_INIT_TYPE_WRITE_STRING 1
438 #define XEN_INIT_TYPE_RING 2
439 #define XEN_INIT_TYPE_EVENT_CHANNEL 3
440 #define XEN_INIT_TYPE_EVENT_CHANNEL_IRQ 4
441 #define XEN_INIT_TYPE_READ_STRING_FRONT 5
442 #define XEN_INIT_TYPE_READ_STRING_BACK 6
443 #define XEN_INIT_TYPE_VECTORS 7
444 #define XEN_INIT_TYPE_GRANT_ENTRIES 8
445 //#define XEN_INIT_TYPE_COPY_PTR 9
446 #define XEN_INIT_TYPE_RUN 10
447 #define XEN_INIT_TYPE_STATE_PTR 11
448 #define XEN_INIT_TYPE_ACTIVE 12
449 #define XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION 13
450 #define XEN_INIT_TYPE_MATCH_FRONT 14 /* string, value, action */
451 #define XEN_INIT_TYPE_MATCH_BACK 15 /* string, value, action */
452 #define XEN_INIT_TYPE_EVENT_CHANNEL_DPC 16
454 #define XEN_INIT_MATCH_TYPE_IF_MATCH 0x0001
455 #define XEN_INIT_MATCH_TYPE_IF_NOT_MATCH 0x0000
456 #define XEN_INIT_MATCH_TYPE_ONLY_IF_QEMU_HIDE 0x0002 /* only if qemu hiding is supported */
457 #define XEN_INIT_MATCH_TYPE_SET_INACTIVE 0x0100
458 #define XEN_INIT_MATCH_TYPE_DONT_CONFIG 0x0200
461 static __inline VOID
462 __ADD_XEN_INIT_UCHAR(PUCHAR *ptr, UCHAR val)
463 {
464 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_UCHAR *ptr = %p, val = %d\n", *ptr, val));
465 *(PUCHAR)(*ptr) = val;
466 *ptr += sizeof(UCHAR);
467 }
469 static __inline VOID
470 __ADD_XEN_INIT_USHORT(PUCHAR *ptr, USHORT val)
471 {
472 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_USHORT *ptr = %p, val = %d\n", *ptr, val));
473 *(PUSHORT)(*ptr) = val;
474 *ptr += sizeof(USHORT);
475 }
477 static __inline VOID
478 __ADD_XEN_INIT_ULONG(PUCHAR *ptr, ULONG val)
479 {
480 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_ULONG *ptr = %p, val = %d\n", *ptr, val));
481 *(PULONG)(*ptr) = val;
482 *ptr += sizeof(ULONG);
483 }
485 static __inline VOID
486 __ADD_XEN_INIT_PTR(PUCHAR *ptr, PVOID val)
487 {
488 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_PTR *ptr = %p, val = %p\n", *ptr, val));
489 *(PVOID *)(*ptr) = val;
490 *ptr += sizeof(PVOID);
491 }
493 static __inline VOID
494 __ADD_XEN_INIT_STRING(PUCHAR *ptr, PCHAR val)
495 {
496 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_STRING *ptr = %p, val = %s\n", *ptr, val));
497 size_t max_string_size = PAGE_SIZE - (PtrToUlong(*ptr) & (PAGE_SIZE - 1));
498 RtlStringCbCopyA((PCHAR)*ptr, max_string_size, val);
499 *ptr += min(strlen(val) + 1, max_string_size);
500 }
502 static __inline UCHAR
503 __GET_XEN_INIT_UCHAR(PUCHAR *ptr)
504 {
505 UCHAR retval;
506 retval = **ptr;
507 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_UCHAR *ptr = %p, retval = %d\n", *ptr, retval));
508 *ptr += sizeof(UCHAR);
509 return retval;
510 }
512 static __inline USHORT
513 __GET_XEN_INIT_USHORT(PUCHAR *ptr)
514 {
515 USHORT retval;
516 retval = *(PUSHORT)*ptr;
517 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_USHORT *ptr = %p, retval = %d\n", *ptr, retval));
518 *ptr += sizeof(USHORT);
519 return retval;
520 }
522 static __inline ULONG
523 __GET_XEN_INIT_ULONG(PUCHAR *ptr)
524 {
525 ULONG retval;
526 retval = *(PLONG)*ptr;
527 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_ULONG *ptr = %p, retval = %d\n", *ptr, retval));
528 *ptr += sizeof(ULONG);
529 return retval;
530 }
532 static __inline PCHAR
533 __GET_XEN_INIT_STRING(PUCHAR *ptr)
534 {
535 PCHAR retval;
536 retval = (PCHAR)*ptr;
537 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_STRING *ptr = %p, retval = %s\n", *ptr, retval));
538 *ptr += strlen((PCHAR)*ptr) + 1;
539 return retval;
540 }
542 static __inline PVOID
543 __GET_XEN_INIT_PTR(PUCHAR *ptr)
544 {
545 PVOID retval;
546 retval = *(PVOID *)(*ptr);
547 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_PTR *ptr = %p, retval = %p\n", *ptr, retval));
548 *ptr += sizeof(PVOID);
549 return retval;
550 }
552 static __inline VOID
553 ADD_XEN_INIT_REQ(PUCHAR *ptr, UCHAR type, PVOID p1, PVOID p2, PVOID p3)
554 {
555 __ADD_XEN_INIT_UCHAR(ptr, type);
556 switch (type)
557 {
558 case XEN_INIT_TYPE_END:
559 case XEN_INIT_TYPE_VECTORS:
560 case XEN_INIT_TYPE_RUN:
561 case XEN_INIT_TYPE_STATE_PTR:
562 case XEN_INIT_TYPE_ACTIVE:
563 case XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION:
564 break;
565 case XEN_INIT_TYPE_WRITE_STRING:
566 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
567 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p2);
568 break;
569 case XEN_INIT_TYPE_MATCH_FRONT:
570 case XEN_INIT_TYPE_MATCH_BACK:
571 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
572 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p2);
573 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p3));
574 break;
575 case XEN_INIT_TYPE_RING:
576 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
577 case XEN_INIT_TYPE_READ_STRING_FRONT:
578 case XEN_INIT_TYPE_READ_STRING_BACK:
579 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
580 break;
581 case XEN_INIT_TYPE_EVENT_CHANNEL:
582 case XEN_INIT_TYPE_EVENT_CHANNEL_DPC:
583 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
584 __ADD_XEN_INIT_PTR(ptr, p2);
585 __ADD_XEN_INIT_PTR(ptr, p3);
586 break;
587 case XEN_INIT_TYPE_GRANT_ENTRIES:
588 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p2));
589 break;
590 // case XEN_INIT_TYPE_COPY_PTR:
591 // __ADD_XEN_INIT_STRING(ptr, p1);
592 // __ADD_XEN_INIT_PTR(ptr, p2);
593 // break;
594 }
595 }
597 static __inline UCHAR
598 GET_XEN_INIT_REQ(PUCHAR *ptr, PVOID *p1, PVOID *p2, PVOID *p3)
599 {
600 UCHAR retval;
602 retval = __GET_XEN_INIT_UCHAR(ptr);
603 switch (retval)
604 {
605 case XEN_INIT_TYPE_END:
606 case XEN_INIT_TYPE_VECTORS:
607 case XEN_INIT_TYPE_RUN:
608 case XEN_INIT_TYPE_STATE_PTR:
609 case XEN_INIT_TYPE_ACTIVE:
610 case XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION:
611 *p1 = NULL;
612 *p2 = NULL;
613 break;
614 case XEN_INIT_TYPE_WRITE_STRING:
615 *p1 = __GET_XEN_INIT_STRING(ptr);
616 *p2 = __GET_XEN_INIT_STRING(ptr);
617 break;
618 case XEN_INIT_TYPE_MATCH_FRONT:
619 case XEN_INIT_TYPE_MATCH_BACK:
620 *p1 = __GET_XEN_INIT_STRING(ptr);
621 *p2 = __GET_XEN_INIT_STRING(ptr);
622 *p3 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
623 break;
624 case XEN_INIT_TYPE_RING:
625 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
626 case XEN_INIT_TYPE_READ_STRING_FRONT:
627 case XEN_INIT_TYPE_READ_STRING_BACK:
628 *p1 = __GET_XEN_INIT_STRING(ptr);
629 *p2 = NULL;
630 break;
631 case XEN_INIT_TYPE_EVENT_CHANNEL:
632 case XEN_INIT_TYPE_EVENT_CHANNEL_DPC:
633 *p1 = __GET_XEN_INIT_STRING(ptr);
634 *p2 = __GET_XEN_INIT_PTR(ptr);
635 *p3 = __GET_XEN_INIT_PTR(ptr);
636 break;
637 case XEN_INIT_TYPE_GRANT_ENTRIES:
638 *p2 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
639 break;
640 // case XEN_INIT_TYPE_COPY_PTR:
641 // *p1 = __GET_XEN_INIT_STRING(ptr);
642 // *p2 = __GET_XEN_INIT_PTR(ptr);
643 // break;
644 }
645 return retval;
646 }
648 static __inline VOID
649 ADD_XEN_INIT_RSP(PUCHAR *ptr, UCHAR type, PVOID p1, PVOID p2, PVOID p3)
650 {
651 UNREFERENCED_PARAMETER(p3);
653 __ADD_XEN_INIT_UCHAR(ptr, type);
654 switch (type)
655 {
656 case XEN_INIT_TYPE_END:
657 case XEN_INIT_TYPE_WRITE_STRING: /* this shouldn't happen */
658 case XEN_INIT_TYPE_RUN:
659 case XEN_INIT_TYPE_ACTIVE:
660 break;
661 case XEN_INIT_TYPE_RING:
662 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
663 __ADD_XEN_INIT_PTR(ptr, p2);
664 break;
665 case XEN_INIT_TYPE_EVENT_CHANNEL:
666 case XEN_INIT_TYPE_EVENT_CHANNEL_DPC:
667 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
668 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
669 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p2));
670 break;
671 case XEN_INIT_TYPE_READ_STRING_FRONT:
672 case XEN_INIT_TYPE_READ_STRING_BACK:
673 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
674 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p2);
675 break;
676 case XEN_INIT_TYPE_VECTORS:
677 //__ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p1));
678 memcpy(*ptr, p2, sizeof(XENPCI_VECTORS));
679 *ptr += sizeof(XENPCI_VECTORS);
680 break;
681 case XEN_INIT_TYPE_GRANT_ENTRIES:
682 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p1));
683 memcpy(*ptr, p2, PtrToUlong(p1) * sizeof(grant_entry_t));
684 *ptr += PtrToUlong(p1) * sizeof(grant_entry_t);
685 break;
686 case XEN_INIT_TYPE_STATE_PTR:
687 __ADD_XEN_INIT_PTR(ptr, p2);
688 break;
689 case XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION:
690 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p2));
691 break;
692 // case XEN_INIT_TYPE_COPY_PTR:
693 // __ADD_XEN_INIT_STRING(ptr, p1);
694 // __ADD_XEN_INIT_PTR(ptr, p2);
695 // break;
696 }
697 }
699 static __inline UCHAR
700 GET_XEN_INIT_RSP(PUCHAR *ptr, PVOID *p1, PVOID *p2, PVOID *p3)
701 {
702 UCHAR retval;
704 UNREFERENCED_PARAMETER(p3);
706 retval = __GET_XEN_INIT_UCHAR(ptr);
707 switch (retval)
708 {
709 case XEN_INIT_TYPE_END:
710 case XEN_INIT_TYPE_RUN:
711 case XEN_INIT_TYPE_ACTIVE:
712 *p1 = NULL;
713 *p2 = NULL;
714 break;
715 case XEN_INIT_TYPE_WRITE_STRING:
716 // this shouldn't happen - no response here
717 break;
718 case XEN_INIT_TYPE_RING:
719 *p1 = __GET_XEN_INIT_STRING(ptr);
720 *p2 = __GET_XEN_INIT_PTR(ptr);
721 break;
722 case XEN_INIT_TYPE_EVENT_CHANNEL:
723 case XEN_INIT_TYPE_EVENT_CHANNEL_DPC:
724 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
725 *p1 = __GET_XEN_INIT_STRING(ptr);
726 *p2 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
727 break;
728 case XEN_INIT_TYPE_READ_STRING_FRONT:
729 *p1 = __GET_XEN_INIT_STRING(ptr);
730 *p2 = __GET_XEN_INIT_STRING(ptr);
731 break;
732 case XEN_INIT_TYPE_READ_STRING_BACK:
733 *p1 = __GET_XEN_INIT_STRING(ptr);
734 *p2 = __GET_XEN_INIT_STRING(ptr);
735 break;
736 case XEN_INIT_TYPE_VECTORS:
737 *p1 = NULL;
738 *p2 = *ptr;
739 *ptr += ((PXENPCI_VECTORS)*p2)->length;
740 break;
741 case XEN_INIT_TYPE_GRANT_ENTRIES:
742 *p1 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
743 *p2 = *ptr;
744 *ptr += PtrToUlong(*p1) * sizeof(grant_ref_t);
745 break;
746 case XEN_INIT_TYPE_STATE_PTR:
747 *p2 = __GET_XEN_INIT_PTR(ptr);
748 break;
749 case XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION:
750 *p2 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
751 break;
752 // case XEN_INIT_TYPE_COPY_PTR:
753 // *p1 = __GET_XEN_INIT_STRING(ptr);
754 // *p2 = __GET_XEN_INIT_PTR(ptr);
755 }
756 return retval;
757 }
759 typedef BOOLEAN
760 (*PXEN_DMA_NEED_VIRTUAL_ADDRESS)(PIRP irp);
762 typedef ULONG
763 (*PXEN_DMA_GET_ALIGNMENT)(PIRP irp);
765 typedef struct {
766 PXEN_DMA_NEED_VIRTUAL_ADDRESS need_virtual_address;
767 PXEN_DMA_GET_ALIGNMENT get_alignment;
768 ULONG max_sg_elements;
769 } dma_driver_extension_t;
771 #endif