win-pvdrivers

view common/include/xen_windows.h @ 615:0436238bcda5

Fix a crash when an incorrectly formatted TCP packet is sent/forwarded by Dom0
author James Harper <james.harper@bendigoit.com.au>
date Sat Jul 18 09:24:52 2009 +1000 (2009-07-18)
parents 3ac377a8136c
children a344955897dd
line source
1 #if !defined(_XEN_WINDOWS_H_)
2 #define _XEN_WINDOWS_H_
4 #pragma warning( disable : 4201 ) // nonstandard extension used : nameless struct/union
5 #pragma warning( disable : 4214 ) // nonstandard extension used : bit field types other than int
6 #pragma warning( disable : 4505 ) // 'XenDbgPrint' : unreferenced local function has been removed
8 #define __XEN_INTERFACE_VERSION__ 0x00030205
9 #if defined(_AMD64_)
10 #define __x86_64__
11 #elif defined(_IA64_)
12 #define __ia64__
13 #elif defined(__MINGW32__)
14 /* __i386__ already defined */
15 #elif defined(_X86_)
16 #define __i386__
17 #else
18 #error Unknown architecture
19 #endif
21 #ifdef __MINGW32__
22 typedef signed char int8_t;
23 typedef unsigned char uint8_t;
24 typedef signed short int16_t;
25 typedef unsigned short uint16_t;
26 typedef signed int int32_t;
27 typedef unsigned int uint32_t;
28 typedef unsigned long long uint64_t;
29 #else
30 typedef INT8 int8_t;
31 typedef UINT8 uint8_t;
32 typedef INT16 int16_t;
33 typedef UINT16 uint16_t;
34 typedef INT32 int32_t;
35 typedef UINT32 uint32_t;
36 typedef UINT64 uint64_t;
37 #endif
39 #include <xen.h>
40 #include <grant_table.h>
41 #include <event_channel.h>
42 #include <xen_guids.h>
44 #define _PAGE_PRESENT 0x001UL
45 #define _PAGE_RW 0x002UL
46 #define _PAGE_USER 0x004UL
47 #define _PAGE_PWT 0x008UL
48 #define _PAGE_PCD 0x010UL
49 #define _PAGE_ACCESSED 0x020UL
50 #define _PAGE_DIRTY 0x040UL
51 #define _PAGE_PAT 0x080UL
52 #define _PAGE_PSE 0x080UL
53 #define _PAGE_GLOBAL 0x100UL
55 #define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED)
57 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
59 typedef unsigned long xenbus_transaction_t;
61 #define XBT_NIL ((xenbus_transaction_t)0)
63 #define SPLITSTRING_POOL_TAG (ULONG) 'SSPT'
65 #define wmb() KeMemoryBarrier()
66 #define mb() KeMemoryBarrier()
68 static __inline char **
69 SplitString(char *String, char Split, int MaxParts, int *Count)
70 {
71 char **RetVal;
72 char *first;
73 char *last;
75 //KdPrint((__DRIVER_NAME " a\n"));
77 *Count = 0;
79 RetVal = (char **)ExAllocatePoolWithTag(NonPagedPool, (MaxParts + 1) * sizeof(char *), SPLITSTRING_POOL_TAG);
80 last = String;
81 do
82 {
83 if (*Count == MaxParts)
84 break;
85 //KdPrint((__DRIVER_NAME " b - count = %d\n", *Count));
86 first = last;
87 for (last = first; *last != '\0' && *last != Split; last++);
88 RetVal[*Count] = (char *)ExAllocatePoolWithTag(NonPagedPool, last - first + 1, SPLITSTRING_POOL_TAG);
89 //KdPrint((__DRIVER_NAME " c - count = %d\n", *Count));
90 strncpy(RetVal[*Count], first, last - first);
91 RetVal[*Count][last - first] = 0;
92 //KdPrint((__DRIVER_NAME " d - count = %d\n", *Count));
93 (*Count)++;
94 //KdPrint((__DRIVER_NAME " e - count = %d\n", *Count));
95 if (*last == Split)
96 last++;
97 } while (*last != 0);
98 //KdPrint((__DRIVER_NAME " f - count = %d\n", *Count));
99 RetVal[*Count] = NULL;
100 return RetVal;
101 }
103 static __inline VOID
104 FreeSplitString(char **Bits, int Count)
105 {
106 int i;
108 for (i = 0; i < Count; i++)
109 ExFreePoolWithTag(Bits[i], SPLITSTRING_POOL_TAG);
110 ExFreePoolWithTag(Bits, SPLITSTRING_POOL_TAG);
111 }
113 #define ALLOCATE_PAGES_POOL_TAG (ULONG) 'APPT'
115 static PMDL
116 AllocatePagesExtra(int Pages, int ExtraSize)
117 {
118 PMDL Mdl;
119 PVOID Buf;
121 Buf = ExAllocatePoolWithTag(NonPagedPool, Pages * PAGE_SIZE, ALLOCATE_PAGES_POOL_TAG);
122 if (Buf == NULL)
123 {
124 KdPrint((__DRIVER_NAME " AllocatePages Failed at ExAllocatePoolWithTag\n"));
125 return NULL;
126 }
127 // KdPrint((__DRIVER_NAME " --- AllocatePages IRQL = %d, Buf = %p\n", KeGetCurrentIrql(), Buf));
128 Mdl = (PMDL)ExAllocatePoolWithTag(NonPagedPool, MmSizeOfMdl(Buf, Pages * PAGE_SIZE) + ExtraSize, ALLOCATE_PAGES_POOL_TAG);
129 //Mdl = IoAllocateMdl(Buf, Pages * PAGE_SIZE, FALSE, FALSE, NULL);
130 if (Mdl == NULL)
131 {
132 // free the memory here
133 KdPrint((__DRIVER_NAME " AllocatePages Failed at IoAllocateMdl\n"));
134 return NULL;
135 }
137 MmInitializeMdl(Mdl, Buf, Pages * PAGE_SIZE);
138 MmBuildMdlForNonPagedPool(Mdl);
140 return Mdl;
141 }
143 static __inline PMDL
144 AllocatePages(int Pages)
145 {
146 return AllocatePagesExtra(Pages, 0);
147 }
149 static __inline PMDL
150 AllocatePage()
151 {
152 return AllocatePagesExtra(1, 0);
153 }
155 static __inline PMDL
156 AllocateUncachedPage()
157 {
158 PMDL mdl;
159 PVOID buf;
161 buf = MmAllocateNonCachedMemory(PAGE_SIZE);
162 mdl = IoAllocateMdl(buf, PAGE_SIZE, FALSE, FALSE, NULL);
163 MmBuildMdlForNonPagedPool(mdl);
165 return mdl;
166 }
168 static __inline VOID
169 FreeUncachedPage(PMDL mdl)
170 {
171 PVOID buf = MmGetMdlVirtualAddress(mdl);
173 IoFreeMdl(mdl);
174 MmFreeNonCachedMemory(buf, PAGE_SIZE);
175 }
177 static __inline VOID
178 FreePages(PMDL Mdl)
179 {
180 PVOID Buf = MmGetMdlVirtualAddress(Mdl);
181 // KdPrint((__DRIVER_NAME " --- FreePages IRQL = %d, Buf = %p\n", KeGetCurrentIrql(), Buf));
182 // IoFreeMdl(Mdl);
183 ExFreePoolWithTag(Mdl, ALLOCATE_PAGES_POOL_TAG);
184 ExFreePoolWithTag(Buf, ALLOCATE_PAGES_POOL_TAG);
185 }
187 #define XEN_IOPORT_BASE 0x10
189 /*
190 define these as pointers so that the READ_PORT* functions complain if
191 the wrong width is used with the wrong defined port
192 */
194 #define XEN_IOPORT_MAGIC ((PUSHORT)UlongToPtr(XEN_IOPORT_BASE + 0))
195 #define XEN_IOPORT_LOG ((PUCHAR)UlongToPtr(XEN_IOPORT_BASE + 2))
196 #define XEN_IOPORT_VERSION ((PUCHAR)UlongToPtr(XEN_IOPORT_BASE + 2))
197 #define XEN_IOPORT_PRODUCT ((PUSHORT)UlongToPtr(XEN_IOPORT_BASE + 2))
198 #define XEN_IOPORT_BUILD ((PULONG)UlongToPtr(XEN_IOPORT_BASE + 0))
199 #define XEN_IOPORT_DEVICE_MASK ((PUSHORT)UlongToPtr(XEN_IOPORT_BASE + 0))
201 #define QEMU_UNPLUG_ALL_IDE_DISKS 1
202 #define QEMU_UNPLUG_ALL_NICS 2
203 #define QEMU_UNPLUG_AUX_IDE_DISKS 4
205 static BOOLEAN debug_port_probed = FALSE;
206 static BOOLEAN debug_port_enabled;
208 static void XenDbgPrint(PCHAR format, ...)
209 {
210 CHAR buf[512];
211 va_list ap;
212 ULONG i;
213 //int cpu;
214 KIRQL old_irql = 0;
216 if (!debug_port_probed)
217 {
218 if (READ_PORT_USHORT(XEN_IOPORT_MAGIC) == 0x49d2
219 || READ_PORT_USHORT(XEN_IOPORT_MAGIC) == 0xd249)
220 {
221 debug_port_enabled = TRUE;
222 }
223 else
224 {
225 debug_port_enabled = FALSE;
226 }
227 debug_port_probed = TRUE;
228 }
229 va_start(ap, format);
230 RtlStringCbVPrintfA(buf, ARRAY_SIZE(buf), format, ap);
231 va_end(ap);
232 DbgPrint(buf);
234 if (debug_port_enabled)
235 {
236 KeRaiseIrql(HIGH_LEVEL, &old_irql);
237 //cpu = KeGetCurrentProcessorNumber() & 0x07;
238 for (i = 0; i < strlen(buf); i++)
239 {
240 WRITE_PORT_UCHAR(XEN_IOPORT_LOG, buf[i]);
241 }
242 KeLowerIrql(old_irql);
243 }
244 }
246 static VOID
247 XenRtlAssert(PCHAR expr, PCHAR filename, ULONG line_number)
248 {
249 XenDbgPrint("Failed ASSERTion '%s' at %s:%d\n", expr, filename, line_number);
250 RtlAssert(expr, filename, line_number, NULL);
251 }
254 #if 1
255 #ifdef KdPrint
256 #undef KdPrint
257 #endif
258 #define KdPrint(_x_) XenDbgPrint _x_
259 #endif
261 #ifdef ASSERT
262 #undef ASSERT
263 #endif
264 #define ASSERT( exp ) ((!(exp)) ? (XenRtlAssert( #exp, __FILE__, __LINE__), FALSE) : TRUE)
266 #define FUNCTION_ENTER() XenDbgPrint(__DRIVER_NAME " --> %s\n", __FUNCTION__)
267 #define FUNCTION_EXIT() XenDbgPrint(__DRIVER_NAME " <-- %s\n", __FUNCTION__)
268 #define FUNCTION_EXIT_STATUS(_status) XenDbgPrint(__DRIVER_NAME " <-- %s, status = %08x\n", __FUNCTION__, _status)
269 #define FUNCTION_ERROR_EXIT() XenDbgPrint(__DRIVER_NAME " <-- %s (error path)\n", __FUNCTION__)
270 #define FUNCTION_CALLED() XenDbgPrint(__DRIVER_NAME " %s called (line %d)\n", __FUNCTION__, __LINE__)
271 #ifdef __MINGW32__
272 #define FUNCTION_MSG(_x) _FUNCTION_MSG _x
273 #define _FUNCTION_MSG(format, args...) XenDbgPrint(__DRIVER_NAME " %s called: " format, __FUNCTION__, ##args)
274 #else
275 #define FUNCTION_MSG(format, ...) XenDbgPrint(__DRIVER_NAME " " format, __VA_ARGS__)
276 #endif
278 #define INVALID_GRANT_REF 0xFFFFFFFF
280 typedef PHYSICAL_ADDRESS
281 (*PXEN_ALLOCMMIO)(PVOID Context, ULONG Length);
283 typedef void
284 (*PXEN_FREEMEM)(PVOID Ptr);
286 typedef VOID
287 (*PXEN_EVTCHN_SERVICE_ROUTINE)(PVOID Context);
289 typedef NTSTATUS
290 (*PXEN_EVTCHN_BIND)(PVOID Context, evtchn_port_t Port, PXEN_EVTCHN_SERVICE_ROUTINE ServiceRoutine, PVOID ServiceContext);
292 typedef NTSTATUS
293 (*PXEN_EVTCHN_UNBIND)(PVOID Context, evtchn_port_t Port);
295 typedef NTSTATUS
296 (*PXEN_EVTCHN_MASK)(PVOID Context, evtchn_port_t Port);
298 typedef NTSTATUS
299 (*PXEN_EVTCHN_UNMASK)(PVOID Context, evtchn_port_t Port);
301 typedef NTSTATUS
302 (*PXEN_EVTCHN_NOTIFY)(PVOID Context, evtchn_port_t Port);
304 typedef evtchn_port_t
305 (*PXEN_EVTCHN_ALLOCUNBOUND)(PVOID Context, domid_t Domain);
307 typedef BOOLEAN
308 (*PXEN_EVTCHN_ACK_EVENT)(PVOID context, evtchn_port_t port, BOOLEAN *last_interrupt);
310 typedef BOOLEAN
311 (*PXEN_EVTCHN_SYNC_ROUTINE)(PVOID sync_context);
313 typedef BOOLEAN
314 (*PXEN_EVTCHN_SYNC)(PVOID Context, PXEN_EVTCHN_SYNC_ROUTINE sync_routine, PVOID sync_context);
316 typedef grant_ref_t
317 (*PXEN_GNTTBL_GRANTACCESS)(PVOID Context, domid_t domid, uint32_t frame, int readonly, grant_ref_t ref);
319 typedef BOOLEAN
320 (*PXEN_GNTTBL_ENDACCESS)(PVOID Context, grant_ref_t ref, BOOLEAN keepref);
322 typedef VOID
323 (*PXEN_GNTTBL_PUTREF)(PVOID Context, grant_ref_t ref);
325 typedef grant_ref_t
326 (*PXEN_GNTTBL_GETREF)(PVOID Context);
329 typedef VOID
330 (*PXENBUS_WATCH_CALLBACK)(char *Path, PVOID ServiceContext);
332 typedef char *
333 (*PXEN_XENBUS_READ)(PVOID Context, xenbus_transaction_t xbt, char *path, char **value);
335 typedef char *
336 (*PXEN_XENBUS_WRITE)(PVOID Context, xenbus_transaction_t xbt, char *path, char *value);
338 typedef char *
339 (*PXEN_XENBUS_PRINTF)(PVOID Context, xenbus_transaction_t xbt, char *path, char *fmt, ...);
341 typedef char *
342 (*PXEN_XENBUS_STARTTRANSACTION)(PVOID Context, xenbus_transaction_t *xbt);
344 typedef char *
345 (*PXEN_XENBUS_ENDTRANSACTION)(PVOID Context, xenbus_transaction_t t, int abort, int *retry);
347 typedef char *
348 (*PXEN_XENBUS_LIST)(PVOID Context, xenbus_transaction_t xbt, char *prefix, char ***contents);
350 typedef char *
351 (*PXEN_XENBUS_ADDWATCH)(PVOID Context, xenbus_transaction_t xbt, char *Path, PXENBUS_WATCH_CALLBACK ServiceRoutine, PVOID ServiceContext);
353 typedef char *
354 (*PXEN_XENBUS_REMWATCH)(PVOID Context, xenbus_transaction_t xbt, char *Path, PXENBUS_WATCH_CALLBACK ServiceRoutine, PVOID ServiceContext);
356 typedef NTSTATUS
357 (*PXEN_XENPCI_XEN_CONFIG_DEVICE)(PVOID Context);
359 typedef NTSTATUS
360 (*PXEN_XENPCI_XEN_SHUTDOWN_DEVICE)(PVOID Context);
362 #ifndef XENPCI_POOL_TAG
363 #define XENPCI_POOL_TAG (ULONG) 'XenP'
364 #endif
366 static __inline VOID
367 XenPci_FreeMem(PVOID Ptr)
368 {
369 ExFreePoolWithTag(Ptr, XENPCI_POOL_TAG);
370 }
372 #define XEN_DATA_MAGIC 0x12345678
374 typedef struct {
375 ULONG magic;
376 USHORT length;
378 PVOID context;
379 PXEN_EVTCHN_BIND EvtChn_Bind;
380 PXEN_EVTCHN_BIND EvtChn_BindDpc;
381 PXEN_EVTCHN_UNBIND EvtChn_Unbind;
382 PXEN_EVTCHN_MASK EvtChn_Mask;
383 PXEN_EVTCHN_UNMASK EvtChn_Unmask;
384 PXEN_EVTCHN_NOTIFY EvtChn_Notify;
385 PXEN_EVTCHN_ACK_EVENT EvtChn_AckEvent;
386 PXEN_EVTCHN_SYNC EvtChn_Sync;
388 PXEN_GNTTBL_GETREF GntTbl_GetRef;
389 PXEN_GNTTBL_PUTREF GntTbl_PutRef;
390 PXEN_GNTTBL_GRANTACCESS GntTbl_GrantAccess;
391 PXEN_GNTTBL_ENDACCESS GntTbl_EndAccess;
393 PXEN_XENPCI_XEN_CONFIG_DEVICE XenPci_XenConfigDevice;
394 PXEN_XENPCI_XEN_SHUTDOWN_DEVICE XenPci_XenShutdownDevice;
396 CHAR path[128];
397 CHAR backend_path[128];
399 //evtchn_port_t pdo_event_channel;
401 PXEN_XENBUS_READ XenBus_Read;
402 PXEN_XENBUS_WRITE XenBus_Write;
403 PXEN_XENBUS_PRINTF XenBus_Printf;
404 PXEN_XENBUS_STARTTRANSACTION XenBus_StartTransaction;
405 PXEN_XENBUS_ENDTRANSACTION XenBus_EndTransaction;
406 PXEN_XENBUS_LIST XenBus_List;
407 PXEN_XENBUS_ADDWATCH XenBus_AddWatch;
408 PXEN_XENBUS_REMWATCH XenBus_RemWatch;
410 } XENPCI_VECTORS, *PXENPCI_VECTORS;
412 /*
413 suspend_resume_state_xxx values
414 pdo will assert a value, and fdo will assert when complete
415 */
416 #define SR_STATE_RUNNING 0 /* normal working state */
417 #define SR_STATE_SUSPENDING 1 /* suspend has started */
418 #define SR_STATE_RESUMING 2 /* resume has started */
420 #define XEN_DEVICE_STATE_MAGIC ((ULONG)'XDST')
422 typedef struct {
423 ULONG magic;
424 USHORT length;
426 ULONG suspend_resume_state_pdo; /* only the PDO can touch this */
427 ULONG suspend_resume_state_fdo; /* only the FDO can touch this */
428 evtchn_port_t pdo_event_channel;
429 } XENPCI_DEVICE_STATE, *PXENPCI_DEVICE_STATE;
431 #define XEN_INIT_DRIVER_EXTENSION_MAGIC ((ULONG)'XCFG')
432 #define XEN_DMA_DRIVER_EXTENSION_MAGIC ((ULONG)'XDMA')
434 #define XEN_INIT_TYPE_END 0
435 #define XEN_INIT_TYPE_WRITE_STRING 1
436 #define XEN_INIT_TYPE_RING 2
437 #define XEN_INIT_TYPE_EVENT_CHANNEL 3
438 #define XEN_INIT_TYPE_EVENT_CHANNEL_IRQ 4
439 #define XEN_INIT_TYPE_READ_STRING_FRONT 5
440 #define XEN_INIT_TYPE_READ_STRING_BACK 6
441 #define XEN_INIT_TYPE_VECTORS 7
442 #define XEN_INIT_TYPE_GRANT_ENTRIES 8
443 //#define XEN_INIT_TYPE_COPY_PTR 9
444 #define XEN_INIT_TYPE_RUN 10
445 #define XEN_INIT_TYPE_STATE_PTR 11
446 #define XEN_INIT_TYPE_ACTIVE 12
447 #define XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION 13
448 #define XEN_INIT_TYPE_MATCH_FRONT 14 /* string, value, action */
449 #define XEN_INIT_TYPE_MATCH_BACK 15 /* string, value, action */
451 #define XEN_INIT_MATCH_TYPE_IF_MATCH 0x0001
452 #define XEN_INIT_MATCH_TYPE_IF_NOT_MATCH 0x0000
453 #define XEN_INIT_MATCH_TYPE_ONLY_IF_QEMU_HIDE 0x0002 /* only if qemu hiding is supported */
454 #define XEN_INIT_MATCH_TYPE_SET_INACTIVE 0x0100
455 #define XEN_INIT_MATCH_TYPE_DONT_CONFIG 0x0200
458 static __inline VOID
459 __ADD_XEN_INIT_UCHAR(PUCHAR *ptr, UCHAR val)
460 {
461 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_UCHAR *ptr = %p, val = %d\n", *ptr, val));
462 *(PUCHAR)(*ptr) = val;
463 *ptr += sizeof(UCHAR);
464 }
466 static __inline VOID
467 __ADD_XEN_INIT_USHORT(PUCHAR *ptr, USHORT val)
468 {
469 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_USHORT *ptr = %p, val = %d\n", *ptr, val));
470 *(PUSHORT)(*ptr) = val;
471 *ptr += sizeof(USHORT);
472 }
474 static __inline VOID
475 __ADD_XEN_INIT_ULONG(PUCHAR *ptr, ULONG val)
476 {
477 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_ULONG *ptr = %p, val = %d\n", *ptr, val));
478 *(PULONG)(*ptr) = val;
479 *ptr += sizeof(ULONG);
480 }
482 static __inline VOID
483 __ADD_XEN_INIT_PTR(PUCHAR *ptr, PVOID val)
484 {
485 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_PTR *ptr = %p, val = %p\n", *ptr, val));
486 *(PVOID *)(*ptr) = val;
487 *ptr += sizeof(PVOID);
488 }
490 static __inline VOID
491 __ADD_XEN_INIT_STRING(PUCHAR *ptr, PCHAR val)
492 {
493 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_STRING *ptr = %p, val = %s\n", *ptr, val));
494 RtlStringCbCopyA((PCHAR)*ptr, PAGE_SIZE - (PtrToUlong(*ptr) & (PAGE_SIZE - 1)), val);
495 *ptr += strlen(val) + 1;
496 }
498 static __inline UCHAR
499 __GET_XEN_INIT_UCHAR(PUCHAR *ptr)
500 {
501 UCHAR retval;
502 retval = **ptr;
503 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_UCHAR *ptr = %p, retval = %d\n", *ptr, retval));
504 *ptr += sizeof(UCHAR);
505 return retval;
506 }
508 static __inline USHORT
509 __GET_XEN_INIT_USHORT(PUCHAR *ptr)
510 {
511 USHORT retval;
512 retval = *(PUSHORT)*ptr;
513 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_USHORT *ptr = %p, retval = %d\n", *ptr, retval));
514 *ptr += sizeof(USHORT);
515 return retval;
516 }
518 static __inline ULONG
519 __GET_XEN_INIT_ULONG(PUCHAR *ptr)
520 {
521 ULONG retval;
522 retval = *(PLONG)*ptr;
523 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_ULONG *ptr = %p, retval = %d\n", *ptr, retval));
524 *ptr += sizeof(ULONG);
525 return retval;
526 }
528 static __inline PCHAR
529 __GET_XEN_INIT_STRING(PUCHAR *ptr)
530 {
531 PCHAR retval;
532 retval = (PCHAR)*ptr;
533 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_STRING *ptr = %p, retval = %s\n", *ptr, retval));
534 *ptr += strlen((PCHAR)*ptr) + 1;
535 return retval;
536 }
538 static __inline PVOID
539 __GET_XEN_INIT_PTR(PUCHAR *ptr)
540 {
541 PVOID retval;
542 retval = *(PVOID *)(*ptr);
543 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_PTR *ptr = %p, retval = %p\n", *ptr, retval));
544 *ptr += sizeof(PVOID);
545 return retval;
546 }
548 static __inline VOID
549 ADD_XEN_INIT_REQ(PUCHAR *ptr, UCHAR type, PVOID p1, PVOID p2, PVOID p3)
550 {
551 __ADD_XEN_INIT_UCHAR(ptr, type);
552 switch (type)
553 {
554 case XEN_INIT_TYPE_END:
555 case XEN_INIT_TYPE_VECTORS:
556 case XEN_INIT_TYPE_RUN:
557 case XEN_INIT_TYPE_STATE_PTR:
558 case XEN_INIT_TYPE_ACTIVE:
559 case XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION:
560 break;
561 case XEN_INIT_TYPE_WRITE_STRING:
562 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
563 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p2);
564 break;
565 case XEN_INIT_TYPE_MATCH_FRONT:
566 case XEN_INIT_TYPE_MATCH_BACK:
567 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
568 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p2);
569 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p3));
570 break;
571 case XEN_INIT_TYPE_RING:
572 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
573 case XEN_INIT_TYPE_READ_STRING_FRONT:
574 case XEN_INIT_TYPE_READ_STRING_BACK:
575 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
576 break;
577 case XEN_INIT_TYPE_EVENT_CHANNEL:
578 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
579 __ADD_XEN_INIT_PTR(ptr, p2);
580 __ADD_XEN_INIT_PTR(ptr, p3);
581 break;
582 case XEN_INIT_TYPE_GRANT_ENTRIES:
583 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p2));
584 break;
585 // case XEN_INIT_TYPE_COPY_PTR:
586 // __ADD_XEN_INIT_STRING(ptr, p1);
587 // __ADD_XEN_INIT_PTR(ptr, p2);
588 // break;
589 }
590 }
592 static __inline UCHAR
593 GET_XEN_INIT_REQ(PUCHAR *ptr, PVOID *p1, PVOID *p2, PVOID *p3)
594 {
595 UCHAR retval;
597 retval = __GET_XEN_INIT_UCHAR(ptr);
598 switch (retval)
599 {
600 case XEN_INIT_TYPE_END:
601 case XEN_INIT_TYPE_VECTORS:
602 case XEN_INIT_TYPE_RUN:
603 case XEN_INIT_TYPE_STATE_PTR:
604 case XEN_INIT_TYPE_ACTIVE:
605 case XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION:
606 *p1 = NULL;
607 *p2 = NULL;
608 break;
609 case XEN_INIT_TYPE_WRITE_STRING:
610 *p1 = __GET_XEN_INIT_STRING(ptr);
611 *p2 = __GET_XEN_INIT_STRING(ptr);
612 break;
613 case XEN_INIT_TYPE_MATCH_FRONT:
614 case XEN_INIT_TYPE_MATCH_BACK:
615 *p1 = __GET_XEN_INIT_STRING(ptr);
616 *p2 = __GET_XEN_INIT_STRING(ptr);
617 *p3 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
618 break;
619 case XEN_INIT_TYPE_RING:
620 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
621 case XEN_INIT_TYPE_READ_STRING_FRONT:
622 case XEN_INIT_TYPE_READ_STRING_BACK:
623 *p1 = __GET_XEN_INIT_STRING(ptr);
624 *p2 = NULL;
625 break;
626 case XEN_INIT_TYPE_EVENT_CHANNEL:
627 *p1 = __GET_XEN_INIT_STRING(ptr);
628 *p2 = __GET_XEN_INIT_PTR(ptr);
629 *p3 = __GET_XEN_INIT_PTR(ptr);
630 break;
631 case XEN_INIT_TYPE_GRANT_ENTRIES:
632 *p2 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
633 break;
634 // case XEN_INIT_TYPE_COPY_PTR:
635 // *p1 = __GET_XEN_INIT_STRING(ptr);
636 // *p2 = __GET_XEN_INIT_PTR(ptr);
637 // break;
638 }
639 return retval;
640 }
642 static __inline VOID
643 ADD_XEN_INIT_RSP(PUCHAR *ptr, UCHAR type, PVOID p1, PVOID p2, PVOID p3)
644 {
645 UNREFERENCED_PARAMETER(p3);
647 __ADD_XEN_INIT_UCHAR(ptr, type);
648 switch (type)
649 {
650 case XEN_INIT_TYPE_END:
651 case XEN_INIT_TYPE_WRITE_STRING: /* this shouldn't happen */
652 case XEN_INIT_TYPE_RUN:
653 case XEN_INIT_TYPE_ACTIVE:
654 break;
655 case XEN_INIT_TYPE_RING:
656 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
657 __ADD_XEN_INIT_PTR(ptr, p2);
658 break;
659 case XEN_INIT_TYPE_EVENT_CHANNEL:
660 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
661 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
662 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p2));
663 break;
664 case XEN_INIT_TYPE_READ_STRING_FRONT:
665 case XEN_INIT_TYPE_READ_STRING_BACK:
666 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
667 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p2);
668 break;
669 case XEN_INIT_TYPE_VECTORS:
670 //__ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p1));
671 memcpy(*ptr, p2, sizeof(XENPCI_VECTORS));
672 *ptr += sizeof(XENPCI_VECTORS);
673 break;
674 case XEN_INIT_TYPE_GRANT_ENTRIES:
675 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p1));
676 memcpy(*ptr, p2, PtrToUlong(p1) * sizeof(grant_entry_t));
677 *ptr += PtrToUlong(p1) * sizeof(grant_entry_t);
678 break;
679 case XEN_INIT_TYPE_STATE_PTR:
680 __ADD_XEN_INIT_PTR(ptr, p2);
681 break;
682 case XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION:
683 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p2));
684 break;
685 // case XEN_INIT_TYPE_COPY_PTR:
686 // __ADD_XEN_INIT_STRING(ptr, p1);
687 // __ADD_XEN_INIT_PTR(ptr, p2);
688 // break;
689 }
690 }
692 static __inline UCHAR
693 GET_XEN_INIT_RSP(PUCHAR *ptr, PVOID *p1, PVOID *p2, PVOID *p3)
694 {
695 UCHAR retval;
697 UNREFERENCED_PARAMETER(p3);
699 retval = __GET_XEN_INIT_UCHAR(ptr);
700 switch (retval)
701 {
702 case XEN_INIT_TYPE_END:
703 case XEN_INIT_TYPE_RUN:
704 case XEN_INIT_TYPE_ACTIVE:
705 *p1 = NULL;
706 *p2 = NULL;
707 break;
708 case XEN_INIT_TYPE_WRITE_STRING:
709 // this shouldn't happen - no response here
710 break;
711 case XEN_INIT_TYPE_RING:
712 *p1 = __GET_XEN_INIT_STRING(ptr);
713 *p2 = __GET_XEN_INIT_PTR(ptr);
714 break;
715 case XEN_INIT_TYPE_EVENT_CHANNEL:
716 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
717 *p1 = __GET_XEN_INIT_STRING(ptr);
718 *p2 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
719 break;
720 case XEN_INIT_TYPE_READ_STRING_FRONT:
721 *p1 = __GET_XEN_INIT_STRING(ptr);
722 *p2 = __GET_XEN_INIT_STRING(ptr);
723 break;
724 case XEN_INIT_TYPE_READ_STRING_BACK:
725 *p1 = __GET_XEN_INIT_STRING(ptr);
726 *p2 = __GET_XEN_INIT_STRING(ptr);
727 break;
728 case XEN_INIT_TYPE_VECTORS:
729 *p1 = NULL;
730 *p2 = *ptr;
731 *ptr += ((PXENPCI_VECTORS)*p2)->length;
732 break;
733 case XEN_INIT_TYPE_GRANT_ENTRIES:
734 *p1 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
735 *p2 = *ptr;
736 *ptr += PtrToUlong(*p1) * sizeof(grant_ref_t);
737 break;
738 case XEN_INIT_TYPE_STATE_PTR:
739 *p2 = __GET_XEN_INIT_PTR(ptr);
740 break;
741 case XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION:
742 *p2 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
743 break;
744 // case XEN_INIT_TYPE_COPY_PTR:
745 // *p1 = __GET_XEN_INIT_STRING(ptr);
746 // *p2 = __GET_XEN_INIT_PTR(ptr);
747 }
748 return retval;
749 }
751 typedef BOOLEAN
752 (*PXEN_DMA_NEED_VIRTUAL_ADDRESS)(PIRP irp);
754 typedef ULONG
755 (*PXEN_DMA_GET_ALIGNMENT)(PIRP irp);
757 typedef struct {
758 PXEN_DMA_NEED_VIRTUAL_ADDRESS need_virtual_address;
759 PXEN_DMA_GET_ALIGNMENT get_alignment;
760 ULONG max_sg_elements;
761 } dma_driver_extension_t;
763 #endif