win-pvdrivers

view common/include/xen_windows.h @ 626:1c466f05ad73

advance the pointer only by the number of bytes actually copied and not the length of the original string
author Amir Szekely <amir@neocleus.com>
date Mon Aug 17 14:36:11 2009 +0300 (2009-08-17)
parents a344955897dd
children 0351906626c2
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 #define IOCTL_XEN_RECONFIGURE CTL_CODE(0x8000, 0x800, METHOD_NEITHER, 0)
70 static __inline char **
71 SplitString(char *String, char Split, int MaxParts, int *Count)
72 {
73 char **RetVal;
74 char *first;
75 char *last;
77 //KdPrint((__DRIVER_NAME " a\n"));
79 *Count = 0;
81 RetVal = (char **)ExAllocatePoolWithTag(NonPagedPool, (MaxParts + 1) * sizeof(char *), SPLITSTRING_POOL_TAG);
82 last = String;
83 do
84 {
85 if (*Count == MaxParts)
86 break;
87 //KdPrint((__DRIVER_NAME " b - count = %d\n", *Count));
88 first = last;
89 for (last = first; *last != '\0' && *last != Split; last++);
90 RetVal[*Count] = (char *)ExAllocatePoolWithTag(NonPagedPool, last - first + 1, SPLITSTRING_POOL_TAG);
91 //KdPrint((__DRIVER_NAME " c - count = %d\n", *Count));
92 strncpy(RetVal[*Count], first, last - first);
93 RetVal[*Count][last - first] = 0;
94 //KdPrint((__DRIVER_NAME " d - count = %d\n", *Count));
95 (*Count)++;
96 //KdPrint((__DRIVER_NAME " e - count = %d\n", *Count));
97 if (*last == Split)
98 last++;
99 } while (*last != 0);
100 //KdPrint((__DRIVER_NAME " f - count = %d\n", *Count));
101 RetVal[*Count] = NULL;
102 return RetVal;
103 }
105 static __inline VOID
106 FreeSplitString(char **Bits, int Count)
107 {
108 int i;
110 for (i = 0; i < Count; i++)
111 ExFreePoolWithTag(Bits[i], SPLITSTRING_POOL_TAG);
112 ExFreePoolWithTag(Bits, SPLITSTRING_POOL_TAG);
113 }
115 #define ALLOCATE_PAGES_POOL_TAG (ULONG) 'APPT'
117 static PMDL
118 AllocatePagesExtra(int Pages, int ExtraSize)
119 {
120 PMDL Mdl;
121 PVOID Buf;
123 Buf = ExAllocatePoolWithTag(NonPagedPool, Pages * PAGE_SIZE, ALLOCATE_PAGES_POOL_TAG);
124 if (Buf == NULL)
125 {
126 KdPrint((__DRIVER_NAME " AllocatePages Failed at ExAllocatePoolWithTag\n"));
127 return NULL;
128 }
129 // KdPrint((__DRIVER_NAME " --- AllocatePages IRQL = %d, Buf = %p\n", KeGetCurrentIrql(), Buf));
130 Mdl = (PMDL)ExAllocatePoolWithTag(NonPagedPool, MmSizeOfMdl(Buf, Pages * PAGE_SIZE) + ExtraSize, ALLOCATE_PAGES_POOL_TAG);
131 //Mdl = IoAllocateMdl(Buf, Pages * PAGE_SIZE, FALSE, FALSE, NULL);
132 if (Mdl == NULL)
133 {
134 // free the memory here
135 KdPrint((__DRIVER_NAME " AllocatePages Failed at IoAllocateMdl\n"));
136 return NULL;
137 }
139 MmInitializeMdl(Mdl, Buf, Pages * PAGE_SIZE);
140 MmBuildMdlForNonPagedPool(Mdl);
142 return Mdl;
143 }
145 static __inline PMDL
146 AllocatePages(int Pages)
147 {
148 return AllocatePagesExtra(Pages, 0);
149 }
151 static __inline PMDL
152 AllocatePage()
153 {
154 return AllocatePagesExtra(1, 0);
155 }
157 static __inline PMDL
158 AllocateUncachedPage()
159 {
160 PMDL mdl;
161 PVOID buf;
163 buf = MmAllocateNonCachedMemory(PAGE_SIZE);
164 mdl = IoAllocateMdl(buf, PAGE_SIZE, FALSE, FALSE, NULL);
165 MmBuildMdlForNonPagedPool(mdl);
167 return mdl;
168 }
170 static __inline VOID
171 FreeUncachedPage(PMDL mdl)
172 {
173 PVOID buf = MmGetMdlVirtualAddress(mdl);
175 IoFreeMdl(mdl);
176 MmFreeNonCachedMemory(buf, PAGE_SIZE);
177 }
179 static __inline VOID
180 FreePages(PMDL Mdl)
181 {
182 PVOID Buf = MmGetMdlVirtualAddress(Mdl);
183 // KdPrint((__DRIVER_NAME " --- FreePages IRQL = %d, Buf = %p\n", KeGetCurrentIrql(), Buf));
184 // IoFreeMdl(Mdl);
185 ExFreePoolWithTag(Mdl, ALLOCATE_PAGES_POOL_TAG);
186 ExFreePoolWithTag(Buf, ALLOCATE_PAGES_POOL_TAG);
187 }
189 #define XEN_IOPORT_BASE 0x10
191 /*
192 define these as pointers so that the READ_PORT* functions complain if
193 the wrong width is used with the wrong defined port
194 */
196 #define XEN_IOPORT_MAGIC ((PUSHORT)UlongToPtr(XEN_IOPORT_BASE + 0))
197 #define XEN_IOPORT_LOG ((PUCHAR)UlongToPtr(XEN_IOPORT_BASE + 2))
198 #define XEN_IOPORT_VERSION ((PUCHAR)UlongToPtr(XEN_IOPORT_BASE + 2))
199 #define XEN_IOPORT_PRODUCT ((PUSHORT)UlongToPtr(XEN_IOPORT_BASE + 2))
200 #define XEN_IOPORT_BUILD ((PULONG)UlongToPtr(XEN_IOPORT_BASE + 0))
201 #define XEN_IOPORT_DEVICE_MASK ((PUSHORT)UlongToPtr(XEN_IOPORT_BASE + 0))
203 #define QEMU_UNPLUG_ALL_IDE_DISKS 1
204 #define QEMU_UNPLUG_ALL_NICS 2
205 #define QEMU_UNPLUG_AUX_IDE_DISKS 4
207 static BOOLEAN debug_port_probed = FALSE;
208 static BOOLEAN debug_port_enabled;
210 static void XenDbgPrint(PCHAR format, ...)
211 {
212 CHAR buf[512];
213 va_list ap;
214 ULONG i;
215 //int cpu;
216 KIRQL old_irql = 0;
218 if (!debug_port_probed)
219 {
220 if (READ_PORT_USHORT(XEN_IOPORT_MAGIC) == 0x49d2
221 || READ_PORT_USHORT(XEN_IOPORT_MAGIC) == 0xd249)
222 {
223 debug_port_enabled = TRUE;
224 }
225 else
226 {
227 debug_port_enabled = FALSE;
228 }
229 debug_port_probed = TRUE;
230 }
231 va_start(ap, format);
232 RtlStringCbVPrintfA(buf, ARRAY_SIZE(buf), format, ap);
233 va_end(ap);
234 DbgPrint(buf);
236 if (debug_port_enabled)
237 {
238 KeRaiseIrql(HIGH_LEVEL, &old_irql);
239 //cpu = KeGetCurrentProcessorNumber() & 0x07;
240 for (i = 0; i < strlen(buf); i++)
241 {
242 WRITE_PORT_UCHAR(XEN_IOPORT_LOG, buf[i]);
243 }
244 KeLowerIrql(old_irql);
245 }
246 }
248 static VOID
249 XenRtlAssert(PCHAR expr, PCHAR filename, ULONG line_number)
250 {
251 XenDbgPrint("Failed ASSERTion '%s' at %s:%d\n", expr, filename, line_number);
252 RtlAssert(expr, filename, line_number, NULL);
253 }
256 #if 1
257 #ifdef KdPrint
258 #undef KdPrint
259 #endif
260 #define KdPrint(_x_) XenDbgPrint _x_
261 #endif
263 #ifdef ASSERT
264 #undef ASSERT
265 #endif
266 #define ASSERT( exp ) ((!(exp)) ? (XenRtlAssert( #exp, __FILE__, __LINE__), FALSE) : TRUE)
268 #define FUNCTION_ENTER() XenDbgPrint(__DRIVER_NAME " --> %s\n", __FUNCTION__)
269 #define FUNCTION_EXIT() XenDbgPrint(__DRIVER_NAME " <-- %s\n", __FUNCTION__)
270 #define FUNCTION_EXIT_STATUS(_status) XenDbgPrint(__DRIVER_NAME " <-- %s, status = %08x\n", __FUNCTION__, _status)
271 #define FUNCTION_ERROR_EXIT() XenDbgPrint(__DRIVER_NAME " <-- %s (error path)\n", __FUNCTION__)
272 #define FUNCTION_CALLED() XenDbgPrint(__DRIVER_NAME " %s called (line %d)\n", __FUNCTION__, __LINE__)
273 #ifdef __MINGW32__
274 #define FUNCTION_MSG(_x) _FUNCTION_MSG _x
275 #define _FUNCTION_MSG(format, args...) XenDbgPrint(__DRIVER_NAME " %s called: " format, __FUNCTION__, ##args)
276 #else
277 #define FUNCTION_MSG(format, ...) XenDbgPrint(__DRIVER_NAME " " format, __VA_ARGS__)
278 #endif
280 #define INVALID_GRANT_REF 0xFFFFFFFF
282 typedef PHYSICAL_ADDRESS
283 (*PXEN_ALLOCMMIO)(PVOID Context, ULONG Length);
285 typedef void
286 (*PXEN_FREEMEM)(PVOID Ptr);
288 typedef VOID
289 (*PXEN_EVTCHN_SERVICE_ROUTINE)(PVOID Context);
291 typedef NTSTATUS
292 (*PXEN_EVTCHN_BIND)(PVOID Context, evtchn_port_t Port, PXEN_EVTCHN_SERVICE_ROUTINE ServiceRoutine, PVOID ServiceContext);
294 typedef NTSTATUS
295 (*PXEN_EVTCHN_UNBIND)(PVOID Context, evtchn_port_t Port);
297 typedef NTSTATUS
298 (*PXEN_EVTCHN_MASK)(PVOID Context, evtchn_port_t Port);
300 typedef NTSTATUS
301 (*PXEN_EVTCHN_UNMASK)(PVOID Context, evtchn_port_t Port);
303 typedef NTSTATUS
304 (*PXEN_EVTCHN_NOTIFY)(PVOID Context, evtchn_port_t Port);
306 typedef evtchn_port_t
307 (*PXEN_EVTCHN_ALLOCUNBOUND)(PVOID Context, domid_t Domain);
309 typedef BOOLEAN
310 (*PXEN_EVTCHN_ACK_EVENT)(PVOID context, evtchn_port_t port, BOOLEAN *last_interrupt);
312 typedef BOOLEAN
313 (*PXEN_EVTCHN_SYNC_ROUTINE)(PVOID sync_context);
315 typedef BOOLEAN
316 (*PXEN_EVTCHN_SYNC)(PVOID Context, PXEN_EVTCHN_SYNC_ROUTINE sync_routine, PVOID sync_context);
318 typedef grant_ref_t
319 (*PXEN_GNTTBL_GRANTACCESS)(PVOID Context, domid_t domid, uint32_t frame, int readonly, grant_ref_t ref);
321 typedef BOOLEAN
322 (*PXEN_GNTTBL_ENDACCESS)(PVOID Context, grant_ref_t ref, BOOLEAN keepref);
324 typedef VOID
325 (*PXEN_GNTTBL_PUTREF)(PVOID Context, grant_ref_t ref);
327 typedef grant_ref_t
328 (*PXEN_GNTTBL_GETREF)(PVOID Context);
331 typedef VOID
332 (*PXENBUS_WATCH_CALLBACK)(char *Path, PVOID ServiceContext);
334 typedef char *
335 (*PXEN_XENBUS_READ)(PVOID Context, xenbus_transaction_t xbt, char *path, char **value);
337 typedef char *
338 (*PXEN_XENBUS_WRITE)(PVOID Context, xenbus_transaction_t xbt, char *path, char *value);
340 typedef char *
341 (*PXEN_XENBUS_PRINTF)(PVOID Context, xenbus_transaction_t xbt, char *path, char *fmt, ...);
343 typedef char *
344 (*PXEN_XENBUS_STARTTRANSACTION)(PVOID Context, xenbus_transaction_t *xbt);
346 typedef char *
347 (*PXEN_XENBUS_ENDTRANSACTION)(PVOID Context, xenbus_transaction_t t, int abort, int *retry);
349 typedef char *
350 (*PXEN_XENBUS_LIST)(PVOID Context, xenbus_transaction_t xbt, char *prefix, char ***contents);
352 typedef char *
353 (*PXEN_XENBUS_ADDWATCH)(PVOID Context, xenbus_transaction_t xbt, char *Path, PXENBUS_WATCH_CALLBACK ServiceRoutine, PVOID ServiceContext);
355 typedef char *
356 (*PXEN_XENBUS_REMWATCH)(PVOID Context, xenbus_transaction_t xbt, char *Path, PXENBUS_WATCH_CALLBACK ServiceRoutine, PVOID ServiceContext);
358 typedef NTSTATUS
359 (*PXEN_XENPCI_XEN_CONFIG_DEVICE)(PVOID Context);
361 typedef NTSTATUS
362 (*PXEN_XENPCI_XEN_SHUTDOWN_DEVICE)(PVOID Context);
364 #ifndef XENPCI_POOL_TAG
365 #define XENPCI_POOL_TAG (ULONG) 'XenP'
366 #endif
368 static __inline VOID
369 XenPci_FreeMem(PVOID Ptr)
370 {
371 ExFreePoolWithTag(Ptr, XENPCI_POOL_TAG);
372 }
374 #define XEN_DATA_MAGIC 0x12345678
376 typedef struct {
377 ULONG magic;
378 USHORT length;
380 PVOID context;
381 PXEN_EVTCHN_BIND EvtChn_Bind;
382 PXEN_EVTCHN_BIND EvtChn_BindDpc;
383 PXEN_EVTCHN_UNBIND EvtChn_Unbind;
384 PXEN_EVTCHN_MASK EvtChn_Mask;
385 PXEN_EVTCHN_UNMASK EvtChn_Unmask;
386 PXEN_EVTCHN_NOTIFY EvtChn_Notify;
387 PXEN_EVTCHN_ACK_EVENT EvtChn_AckEvent;
388 PXEN_EVTCHN_SYNC EvtChn_Sync;
390 PXEN_GNTTBL_GETREF GntTbl_GetRef;
391 PXEN_GNTTBL_PUTREF GntTbl_PutRef;
392 PXEN_GNTTBL_GRANTACCESS GntTbl_GrantAccess;
393 PXEN_GNTTBL_ENDACCESS GntTbl_EndAccess;
395 PXEN_XENPCI_XEN_CONFIG_DEVICE XenPci_XenConfigDevice;
396 PXEN_XENPCI_XEN_SHUTDOWN_DEVICE XenPci_XenShutdownDevice;
398 CHAR path[128];
399 CHAR backend_path[128];
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 */
450 #define XEN_INIT_TYPE_EVENT_CHANNEL_DPC 16
452 #define XEN_INIT_MATCH_TYPE_IF_MATCH 0x0001
453 #define XEN_INIT_MATCH_TYPE_IF_NOT_MATCH 0x0000
454 #define XEN_INIT_MATCH_TYPE_ONLY_IF_QEMU_HIDE 0x0002 /* only if qemu hiding is supported */
455 #define XEN_INIT_MATCH_TYPE_SET_INACTIVE 0x0100
456 #define XEN_INIT_MATCH_TYPE_DONT_CONFIG 0x0200
459 static __inline VOID
460 __ADD_XEN_INIT_UCHAR(PUCHAR *ptr, UCHAR val)
461 {
462 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_UCHAR *ptr = %p, val = %d\n", *ptr, val));
463 *(PUCHAR)(*ptr) = val;
464 *ptr += sizeof(UCHAR);
465 }
467 static __inline VOID
468 __ADD_XEN_INIT_USHORT(PUCHAR *ptr, USHORT val)
469 {
470 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_USHORT *ptr = %p, val = %d\n", *ptr, val));
471 *(PUSHORT)(*ptr) = val;
472 *ptr += sizeof(USHORT);
473 }
475 static __inline VOID
476 __ADD_XEN_INIT_ULONG(PUCHAR *ptr, ULONG val)
477 {
478 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_ULONG *ptr = %p, val = %d\n", *ptr, val));
479 *(PULONG)(*ptr) = val;
480 *ptr += sizeof(ULONG);
481 }
483 static __inline VOID
484 __ADD_XEN_INIT_PTR(PUCHAR *ptr, PVOID val)
485 {
486 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_PTR *ptr = %p, val = %p\n", *ptr, val));
487 *(PVOID *)(*ptr) = val;
488 *ptr += sizeof(PVOID);
489 }
491 static __inline VOID
492 __ADD_XEN_INIT_STRING(PUCHAR *ptr, PCHAR val)
493 {
494 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_STRING *ptr = %p, val = %s\n", *ptr, val));
495 size_t max_string_size = PAGE_SIZE - (PtrToUlong(*ptr) & (PAGE_SIZE - 1));
496 RtlStringCbCopyA((PCHAR)*ptr, max_string_size, val);
497 *ptr += min(strlen(val) + 1, max_string_size);
498 }
500 static __inline UCHAR
501 __GET_XEN_INIT_UCHAR(PUCHAR *ptr)
502 {
503 UCHAR retval;
504 retval = **ptr;
505 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_UCHAR *ptr = %p, retval = %d\n", *ptr, retval));
506 *ptr += sizeof(UCHAR);
507 return retval;
508 }
510 static __inline USHORT
511 __GET_XEN_INIT_USHORT(PUCHAR *ptr)
512 {
513 USHORT retval;
514 retval = *(PUSHORT)*ptr;
515 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_USHORT *ptr = %p, retval = %d\n", *ptr, retval));
516 *ptr += sizeof(USHORT);
517 return retval;
518 }
520 static __inline ULONG
521 __GET_XEN_INIT_ULONG(PUCHAR *ptr)
522 {
523 ULONG retval;
524 retval = *(PLONG)*ptr;
525 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_ULONG *ptr = %p, retval = %d\n", *ptr, retval));
526 *ptr += sizeof(ULONG);
527 return retval;
528 }
530 static __inline PCHAR
531 __GET_XEN_INIT_STRING(PUCHAR *ptr)
532 {
533 PCHAR retval;
534 retval = (PCHAR)*ptr;
535 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_STRING *ptr = %p, retval = %s\n", *ptr, retval));
536 *ptr += strlen((PCHAR)*ptr) + 1;
537 return retval;
538 }
540 static __inline PVOID
541 __GET_XEN_INIT_PTR(PUCHAR *ptr)
542 {
543 PVOID retval;
544 retval = *(PVOID *)(*ptr);
545 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_PTR *ptr = %p, retval = %p\n", *ptr, retval));
546 *ptr += sizeof(PVOID);
547 return retval;
548 }
550 static __inline VOID
551 ADD_XEN_INIT_REQ(PUCHAR *ptr, UCHAR type, PVOID p1, PVOID p2, PVOID p3)
552 {
553 __ADD_XEN_INIT_UCHAR(ptr, type);
554 switch (type)
555 {
556 case XEN_INIT_TYPE_END:
557 case XEN_INIT_TYPE_VECTORS:
558 case XEN_INIT_TYPE_RUN:
559 case XEN_INIT_TYPE_STATE_PTR:
560 case XEN_INIT_TYPE_ACTIVE:
561 case XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION:
562 break;
563 case XEN_INIT_TYPE_WRITE_STRING:
564 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
565 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p2);
566 break;
567 case XEN_INIT_TYPE_MATCH_FRONT:
568 case XEN_INIT_TYPE_MATCH_BACK:
569 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
570 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p2);
571 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p3));
572 break;
573 case XEN_INIT_TYPE_RING:
574 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
575 case XEN_INIT_TYPE_READ_STRING_FRONT:
576 case XEN_INIT_TYPE_READ_STRING_BACK:
577 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
578 break;
579 case XEN_INIT_TYPE_EVENT_CHANNEL:
580 case XEN_INIT_TYPE_EVENT_CHANNEL_DPC:
581 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
582 __ADD_XEN_INIT_PTR(ptr, p2);
583 __ADD_XEN_INIT_PTR(ptr, p3);
584 break;
585 case XEN_INIT_TYPE_GRANT_ENTRIES:
586 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p2));
587 break;
588 // case XEN_INIT_TYPE_COPY_PTR:
589 // __ADD_XEN_INIT_STRING(ptr, p1);
590 // __ADD_XEN_INIT_PTR(ptr, p2);
591 // break;
592 }
593 }
595 static __inline UCHAR
596 GET_XEN_INIT_REQ(PUCHAR *ptr, PVOID *p1, PVOID *p2, PVOID *p3)
597 {
598 UCHAR retval;
600 retval = __GET_XEN_INIT_UCHAR(ptr);
601 switch (retval)
602 {
603 case XEN_INIT_TYPE_END:
604 case XEN_INIT_TYPE_VECTORS:
605 case XEN_INIT_TYPE_RUN:
606 case XEN_INIT_TYPE_STATE_PTR:
607 case XEN_INIT_TYPE_ACTIVE:
608 case XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION:
609 *p1 = NULL;
610 *p2 = NULL;
611 break;
612 case XEN_INIT_TYPE_WRITE_STRING:
613 *p1 = __GET_XEN_INIT_STRING(ptr);
614 *p2 = __GET_XEN_INIT_STRING(ptr);
615 break;
616 case XEN_INIT_TYPE_MATCH_FRONT:
617 case XEN_INIT_TYPE_MATCH_BACK:
618 *p1 = __GET_XEN_INIT_STRING(ptr);
619 *p2 = __GET_XEN_INIT_STRING(ptr);
620 *p3 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
621 break;
622 case XEN_INIT_TYPE_RING:
623 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
624 case XEN_INIT_TYPE_READ_STRING_FRONT:
625 case XEN_INIT_TYPE_READ_STRING_BACK:
626 *p1 = __GET_XEN_INIT_STRING(ptr);
627 *p2 = NULL;
628 break;
629 case XEN_INIT_TYPE_EVENT_CHANNEL:
630 case XEN_INIT_TYPE_EVENT_CHANNEL_DPC:
631 *p1 = __GET_XEN_INIT_STRING(ptr);
632 *p2 = __GET_XEN_INIT_PTR(ptr);
633 *p3 = __GET_XEN_INIT_PTR(ptr);
634 break;
635 case XEN_INIT_TYPE_GRANT_ENTRIES:
636 *p2 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
637 break;
638 // case XEN_INIT_TYPE_COPY_PTR:
639 // *p1 = __GET_XEN_INIT_STRING(ptr);
640 // *p2 = __GET_XEN_INIT_PTR(ptr);
641 // break;
642 }
643 return retval;
644 }
646 static __inline VOID
647 ADD_XEN_INIT_RSP(PUCHAR *ptr, UCHAR type, PVOID p1, PVOID p2, PVOID p3)
648 {
649 UNREFERENCED_PARAMETER(p3);
651 __ADD_XEN_INIT_UCHAR(ptr, type);
652 switch (type)
653 {
654 case XEN_INIT_TYPE_END:
655 case XEN_INIT_TYPE_WRITE_STRING: /* this shouldn't happen */
656 case XEN_INIT_TYPE_RUN:
657 case XEN_INIT_TYPE_ACTIVE:
658 break;
659 case XEN_INIT_TYPE_RING:
660 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
661 __ADD_XEN_INIT_PTR(ptr, p2);
662 break;
663 case XEN_INIT_TYPE_EVENT_CHANNEL:
664 case XEN_INIT_TYPE_EVENT_CHANNEL_DPC:
665 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
666 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
667 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p2));
668 break;
669 case XEN_INIT_TYPE_READ_STRING_FRONT:
670 case XEN_INIT_TYPE_READ_STRING_BACK:
671 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
672 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p2);
673 break;
674 case XEN_INIT_TYPE_VECTORS:
675 //__ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p1));
676 memcpy(*ptr, p2, sizeof(XENPCI_VECTORS));
677 *ptr += sizeof(XENPCI_VECTORS);
678 break;
679 case XEN_INIT_TYPE_GRANT_ENTRIES:
680 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p1));
681 memcpy(*ptr, p2, PtrToUlong(p1) * sizeof(grant_entry_t));
682 *ptr += PtrToUlong(p1) * sizeof(grant_entry_t);
683 break;
684 case XEN_INIT_TYPE_STATE_PTR:
685 __ADD_XEN_INIT_PTR(ptr, p2);
686 break;
687 case XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION:
688 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p2));
689 break;
690 // case XEN_INIT_TYPE_COPY_PTR:
691 // __ADD_XEN_INIT_STRING(ptr, p1);
692 // __ADD_XEN_INIT_PTR(ptr, p2);
693 // break;
694 }
695 }
697 static __inline UCHAR
698 GET_XEN_INIT_RSP(PUCHAR *ptr, PVOID *p1, PVOID *p2, PVOID *p3)
699 {
700 UCHAR retval;
702 UNREFERENCED_PARAMETER(p3);
704 retval = __GET_XEN_INIT_UCHAR(ptr);
705 switch (retval)
706 {
707 case XEN_INIT_TYPE_END:
708 case XEN_INIT_TYPE_RUN:
709 case XEN_INIT_TYPE_ACTIVE:
710 *p1 = NULL;
711 *p2 = NULL;
712 break;
713 case XEN_INIT_TYPE_WRITE_STRING:
714 // this shouldn't happen - no response here
715 break;
716 case XEN_INIT_TYPE_RING:
717 *p1 = __GET_XEN_INIT_STRING(ptr);
718 *p2 = __GET_XEN_INIT_PTR(ptr);
719 break;
720 case XEN_INIT_TYPE_EVENT_CHANNEL:
721 case XEN_INIT_TYPE_EVENT_CHANNEL_DPC:
722 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
723 *p1 = __GET_XEN_INIT_STRING(ptr);
724 *p2 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
725 break;
726 case XEN_INIT_TYPE_READ_STRING_FRONT:
727 *p1 = __GET_XEN_INIT_STRING(ptr);
728 *p2 = __GET_XEN_INIT_STRING(ptr);
729 break;
730 case XEN_INIT_TYPE_READ_STRING_BACK:
731 *p1 = __GET_XEN_INIT_STRING(ptr);
732 *p2 = __GET_XEN_INIT_STRING(ptr);
733 break;
734 case XEN_INIT_TYPE_VECTORS:
735 *p1 = NULL;
736 *p2 = *ptr;
737 *ptr += ((PXENPCI_VECTORS)*p2)->length;
738 break;
739 case XEN_INIT_TYPE_GRANT_ENTRIES:
740 *p1 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
741 *p2 = *ptr;
742 *ptr += PtrToUlong(*p1) * sizeof(grant_ref_t);
743 break;
744 case XEN_INIT_TYPE_STATE_PTR:
745 *p2 = __GET_XEN_INIT_PTR(ptr);
746 break;
747 case XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION:
748 *p2 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
749 break;
750 // case XEN_INIT_TYPE_COPY_PTR:
751 // *p1 = __GET_XEN_INIT_STRING(ptr);
752 // *p2 = __GET_XEN_INIT_PTR(ptr);
753 }
754 return retval;
755 }
757 typedef BOOLEAN
758 (*PXEN_DMA_NEED_VIRTUAL_ADDRESS)(PIRP irp);
760 typedef ULONG
761 (*PXEN_DMA_GET_ALIGNMENT)(PIRP irp);
763 typedef struct {
764 PXEN_DMA_NEED_VIRTUAL_ADDRESS need_virtual_address;
765 PXEN_DMA_GET_ALIGNMENT get_alignment;
766 ULONG max_sg_elements;
767 } dma_driver_extension_t;
769 #endif