win-pvdrivers

view common/include/xen_windows.h @ 750:cb83af6bcdef

Include files changes for device hiding changes
author James Harper <james.harper@bendigoit.com.au>
date Sun Jan 10 10:11:16 2010 +1100 (2010-01-10)
parents 5bdb7251370c
children 467005e7f509
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 //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 #if 0
211 static BOOLEAN debug_port_probed = FALSE;
212 static BOOLEAN debug_port_enabled;
214 static void XenDbgPrintOld(PCHAR format, ...)
215 {
216 CHAR buf[512];
217 va_list ap;
218 ULONG i;
219 //int cpu;
220 KIRQL old_irql = 0;
222 if (!debug_port_probed)
223 {
224 if (READ_PORT_USHORT(XEN_IOPORT_MAGIC) == 0x49d2
225 || READ_PORT_USHORT(XEN_IOPORT_MAGIC) == 0xd249)
226 {
227 debug_port_enabled = TRUE;
228 }
229 else
230 {
231 debug_port_enabled = FALSE;
232 }
233 debug_port_probed = TRUE;
234 }
235 va_start(ap, format);
236 RtlStringCbVPrintfA(buf, ARRAY_SIZE(buf), format, ap);
237 va_end(ap);
238 DbgPrint(buf);
240 if (debug_port_enabled)
241 {
242 KeRaiseIrql(HIGH_LEVEL, &old_irql);
243 //cpu = KeGetCurrentProcessorNumber() & 0x07;
244 for (i = 0; i < strlen(buf); i++)
245 {
246 WRITE_PORT_UCHAR(XEN_IOPORT_LOG, buf[i]);
247 }
248 KeLowerIrql(old_irql);
249 }
250 }
253 static VOID
254 XenRtlAssert(PCHAR expr, PCHAR filename, ULONG line_number)
255 {
256 XenDbgPrintOld("Failed ASSERTion '%s' at %s:%d\n", expr, filename, line_number);
257 RtlAssert(expr, filename, line_number, NULL);
258 }
261 #if 1
262 #ifdef KdPrint
263 #undef KdPrint
264 #endif
265 #define KdPrint(_x_) XenDbgPrintOld _x_
266 #endif
268 #ifdef ASSERT
269 #undef ASSERT
270 #endif
271 #define ASSERT( exp ) ((!(exp)) ? (XenRtlAssert( #exp, __FILE__, __LINE__), FALSE) : TRUE)
273 #define FUNCTION_ENTER() XenDbgPrintOld(__DRIVER_NAME " --> %s\n", __FUNCTION__)
274 #define FUNCTION_EXIT() XenDbgPrintOld(__DRIVER_NAME " <-- %s\n", __FUNCTION__)
275 #define FUNCTION_EXIT_STATUS(_status) XenDbgPrintOld(__DRIVER_NAME " <-- %s, status = %08x\n", __FUNCTION__, _status)
276 #define FUNCTION_ERROR_EXIT() XenDbgPrintOld(__DRIVER_NAME " <-- %s (error path)\n", __FUNCTION__)
277 #define FUNCTION_CALLED() XenDbgPrintOld(__DRIVER_NAME " %s called (line %d)\n", __FUNCTION__, __LINE__)
278 #ifdef __MINGW32__
279 #define FUNCTION_MSG(_x) _FUNCTION_MSG _x
280 #define _FUNCTION_MSG(format, args...) XenDbgPrintOld(__DRIVER_NAME " %s called: " format, __FUNCTION__, ##args)
281 #else
282 #define FUNCTION_MSG(format, ...) XenDbgPrintOld(__DRIVER_NAME " " format, __VA_ARGS__)
283 #endif
285 #else
287 #define FUNCTION_ENTER() KdPrint((__DRIVER_NAME " --> %s\n", __FUNCTION__))
288 #define FUNCTION_EXIT() KdPrint((__DRIVER_NAME " <-- %s\n", __FUNCTION__))
289 #define FUNCTION_EXIT_STATUS(_status) KdPrint((__DRIVER_NAME " <-- %s, status = %08x\n", __FUNCTION__, _status))
290 #define FUNCTION_MSG(...) KdPrint((__DRIVER_NAME " " __VA_ARGS__))
292 #endif
295 #define INVALID_GRANT_REF 0xFFFFFFFF
297 typedef PHYSICAL_ADDRESS
298 (*PXEN_ALLOCMMIO)(PVOID Context, ULONG Length);
300 typedef void
301 (*PXEN_FREEMEM)(PVOID Ptr);
303 typedef VOID
304 (*PXEN_EVTCHN_SERVICE_ROUTINE)(PVOID Context);
306 typedef NTSTATUS
307 (*PXEN_EVTCHN_BIND)(PVOID Context, evtchn_port_t Port, PXEN_EVTCHN_SERVICE_ROUTINE ServiceRoutine, PVOID ServiceContext);
309 typedef NTSTATUS
310 (*PXEN_EVTCHN_UNBIND)(PVOID Context, evtchn_port_t Port);
312 typedef NTSTATUS
313 (*PXEN_EVTCHN_MASK)(PVOID Context, evtchn_port_t Port);
315 typedef NTSTATUS
316 (*PXEN_EVTCHN_UNMASK)(PVOID Context, evtchn_port_t Port);
318 typedef NTSTATUS
319 (*PXEN_EVTCHN_NOTIFY)(PVOID Context, evtchn_port_t Port);
321 typedef evtchn_port_t
322 (*PXEN_EVTCHN_ALLOCUNBOUND)(PVOID Context, domid_t Domain);
324 typedef BOOLEAN
325 (*PXEN_EVTCHN_ACK_EVENT)(PVOID context, evtchn_port_t port, BOOLEAN *last_interrupt);
327 typedef BOOLEAN
328 (*PXEN_EVTCHN_SYNC_ROUTINE)(PVOID sync_context);
330 typedef BOOLEAN
331 (*PXEN_EVTCHN_SYNC)(PVOID Context, PXEN_EVTCHN_SYNC_ROUTINE sync_routine, PVOID sync_context);
333 typedef grant_ref_t
334 (*PXEN_GNTTBL_GRANTACCESS)(PVOID Context, domid_t domid, uint32_t frame, int readonly, grant_ref_t ref);
336 typedef BOOLEAN
337 (*PXEN_GNTTBL_ENDACCESS)(PVOID Context, grant_ref_t ref, BOOLEAN keepref);
339 typedef VOID
340 (*PXEN_GNTTBL_PUTREF)(PVOID Context, grant_ref_t ref);
342 typedef grant_ref_t
343 (*PXEN_GNTTBL_GETREF)(PVOID Context);
346 typedef VOID
347 (*PXENBUS_WATCH_CALLBACK)(char *Path, PVOID ServiceContext);
349 typedef char *
350 (*PXEN_XENBUS_READ)(PVOID Context, xenbus_transaction_t xbt, char *path, char **value);
352 typedef char *
353 (*PXEN_XENBUS_WRITE)(PVOID Context, xenbus_transaction_t xbt, char *path, char *value);
355 typedef char *
356 (*PXEN_XENBUS_PRINTF)(PVOID Context, xenbus_transaction_t xbt, char *path, char *fmt, ...);
358 typedef char *
359 (*PXEN_XENBUS_STARTTRANSACTION)(PVOID Context, xenbus_transaction_t *xbt);
361 typedef char *
362 (*PXEN_XENBUS_ENDTRANSACTION)(PVOID Context, xenbus_transaction_t t, int abort, int *retry);
364 typedef char *
365 (*PXEN_XENBUS_LIST)(PVOID Context, xenbus_transaction_t xbt, char *prefix, char ***contents);
367 typedef char *
368 (*PXEN_XENBUS_ADDWATCH)(PVOID Context, xenbus_transaction_t xbt, char *Path, PXENBUS_WATCH_CALLBACK ServiceRoutine, PVOID ServiceContext);
370 typedef char *
371 (*PXEN_XENBUS_REMWATCH)(PVOID Context, xenbus_transaction_t xbt, char *Path, PXENBUS_WATCH_CALLBACK ServiceRoutine, PVOID ServiceContext);
373 typedef NTSTATUS
374 (*PXEN_XENPCI_XEN_CONFIG_DEVICE)(PVOID Context);
376 typedef NTSTATUS
377 (*PXEN_XENPCI_XEN_SHUTDOWN_DEVICE)(PVOID Context);
379 #ifndef XENPCI_POOL_TAG
380 #define XENPCI_POOL_TAG (ULONG) 'XenP'
381 #endif
383 static __inline VOID
384 XenPci_FreeMem(PVOID Ptr)
385 {
386 ExFreePoolWithTag(Ptr, XENPCI_POOL_TAG);
387 }
389 #define XEN_DATA_MAGIC 0x12345678
391 typedef struct {
392 ULONG magic;
393 USHORT length;
395 PVOID context;
396 PXEN_EVTCHN_BIND EvtChn_Bind;
397 PXEN_EVTCHN_BIND EvtChn_BindDpc;
398 PXEN_EVTCHN_UNBIND EvtChn_Unbind;
399 PXEN_EVTCHN_MASK EvtChn_Mask;
400 PXEN_EVTCHN_UNMASK EvtChn_Unmask;
401 PXEN_EVTCHN_NOTIFY EvtChn_Notify;
402 PXEN_EVTCHN_ACK_EVENT EvtChn_AckEvent;
403 PXEN_EVTCHN_SYNC EvtChn_Sync;
405 PXEN_GNTTBL_GETREF GntTbl_GetRef;
406 PXEN_GNTTBL_PUTREF GntTbl_PutRef;
407 PXEN_GNTTBL_GRANTACCESS GntTbl_GrantAccess;
408 PXEN_GNTTBL_ENDACCESS GntTbl_EndAccess;
410 PXEN_XENPCI_XEN_CONFIG_DEVICE XenPci_XenConfigDevice;
411 PXEN_XENPCI_XEN_SHUTDOWN_DEVICE XenPci_XenShutdownDevice;
413 CHAR path[128];
414 CHAR backend_path[128];
416 PXEN_XENBUS_READ XenBus_Read;
417 PXEN_XENBUS_WRITE XenBus_Write;
418 PXEN_XENBUS_PRINTF XenBus_Printf;
419 PXEN_XENBUS_STARTTRANSACTION XenBus_StartTransaction;
420 PXEN_XENBUS_ENDTRANSACTION XenBus_EndTransaction;
421 PXEN_XENBUS_LIST XenBus_List;
422 PXEN_XENBUS_ADDWATCH XenBus_AddWatch;
423 PXEN_XENBUS_REMWATCH XenBus_RemWatch;
425 } XENPCI_VECTORS, *PXENPCI_VECTORS;
427 /*
428 suspend_resume_state_xxx values
429 pdo will assert a value, and fdo will assert when complete
430 */
431 #define SR_STATE_RUNNING 0 /* normal working state */
432 #define SR_STATE_SUSPENDING 1 /* suspend has started */
433 #define SR_STATE_RESUMING 2 /* resume has started */
435 #define XEN_DEVICE_STATE_MAGIC ((ULONG)'XDST')
437 typedef struct {
438 ULONG magic;
439 USHORT length;
441 ULONG suspend_resume_state_pdo; /* only the PDO can touch this */
442 ULONG suspend_resume_state_fdo; /* only the FDO can touch this */
443 evtchn_port_t pdo_event_channel;
444 } XENPCI_DEVICE_STATE, *PXENPCI_DEVICE_STATE;
446 #define XEN_INIT_DRIVER_EXTENSION_MAGIC ((ULONG)'XCFG')
447 #define XEN_DMA_DRIVER_EXTENSION_MAGIC ((ULONG)'XDMA')
449 #define XEN_INIT_TYPE_END 0
450 #define XEN_INIT_TYPE_WRITE_STRING 1
451 #define XEN_INIT_TYPE_RING 2
452 #define XEN_INIT_TYPE_EVENT_CHANNEL 3
453 #define XEN_INIT_TYPE_EVENT_CHANNEL_IRQ 4
454 #define XEN_INIT_TYPE_READ_STRING_FRONT 5
455 #define XEN_INIT_TYPE_READ_STRING_BACK 6
456 #define XEN_INIT_TYPE_VECTORS 7
457 #define XEN_INIT_TYPE_GRANT_ENTRIES 8
458 //#define XEN_INIT_TYPE_COPY_PTR 9
459 #define XEN_INIT_TYPE_RUN 10
460 #define XEN_INIT_TYPE_STATE_PTR 11
461 //#define XEN_INIT_TYPE_ACTIVE 12
462 #define XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION 13
463 //#define XEN_INIT_TYPE_MATCH_FRONT 14 /* string, value, action */
464 //#define XEN_INIT_TYPE_MATCH_BACK 15 /* string, value, action */
465 #define XEN_INIT_TYPE_EVENT_CHANNEL_DPC 16
466 #define XEN_INIT_TYPE_QEMU_HIDE_FLAGS 17 /* qemu hide flags */
467 #define XEN_INIT_TYPE_QEMU_HIDE_FILTER 18 /* qemu device hidden by class filter */
469 #if 0
470 #define XEN_INIT_MATCH_TYPE_IF_MATCH 0x0001
471 #define XEN_INIT_MATCH_TYPE_IF_NOT_MATCH 0x0000
472 #define XEN_INIT_MATCH_TYPE_ONLY_IF_QEMU_HIDE 0x0002 /* only if qemu hiding is supported */
473 #define XEN_INIT_MATCH_TYPE_SET_INACTIVE 0x0100
474 #define XEN_INIT_MATCH_TYPE_DONT_CONFIG 0x0200
475 #endif
477 static __inline VOID
478 __ADD_XEN_INIT_UCHAR(PUCHAR *ptr, UCHAR val)
479 {
480 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_UCHAR *ptr = %p, val = %d\n", *ptr, val));
481 *(PUCHAR)(*ptr) = val;
482 *ptr += sizeof(UCHAR);
483 }
485 static __inline VOID
486 __ADD_XEN_INIT_USHORT(PUCHAR *ptr, USHORT val)
487 {
488 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_USHORT *ptr = %p, val = %d\n", *ptr, val));
489 *(PUSHORT)(*ptr) = val;
490 *ptr += sizeof(USHORT);
491 }
493 static __inline VOID
494 __ADD_XEN_INIT_ULONG(PUCHAR *ptr, ULONG val)
495 {
496 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_ULONG *ptr = %p, val = %d\n", *ptr, val));
497 *(PULONG)(*ptr) = val;
498 *ptr += sizeof(ULONG);
499 }
501 static __inline VOID
502 __ADD_XEN_INIT_PTR(PUCHAR *ptr, PVOID val)
503 {
504 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_PTR *ptr = %p, val = %p\n", *ptr, val));
505 *(PVOID *)(*ptr) = val;
506 *ptr += sizeof(PVOID);
507 }
509 static __inline VOID
510 __ADD_XEN_INIT_STRING(PUCHAR *ptr, PCHAR val)
511 {
512 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_STRING *ptr = %p, val = %s\n", *ptr, val));
513 size_t max_string_size = PAGE_SIZE - (PtrToUlong(*ptr) & (PAGE_SIZE - 1));
514 RtlStringCbCopyA((PCHAR)*ptr, max_string_size, val);
515 *ptr += min(strlen(val) + 1, max_string_size);
516 }
518 static __inline UCHAR
519 __GET_XEN_INIT_UCHAR(PUCHAR *ptr)
520 {
521 UCHAR retval;
522 retval = **ptr;
523 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_UCHAR *ptr = %p, retval = %d\n", *ptr, retval));
524 *ptr += sizeof(UCHAR);
525 return retval;
526 }
528 static __inline USHORT
529 __GET_XEN_INIT_USHORT(PUCHAR *ptr)
530 {
531 USHORT retval;
532 retval = *(PUSHORT)*ptr;
533 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_USHORT *ptr = %p, retval = %d\n", *ptr, retval));
534 *ptr += sizeof(USHORT);
535 return retval;
536 }
538 static __inline ULONG
539 __GET_XEN_INIT_ULONG(PUCHAR *ptr)
540 {
541 ULONG retval;
542 retval = *(PLONG)*ptr;
543 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_ULONG *ptr = %p, retval = %d\n", *ptr, retval));
544 *ptr += sizeof(ULONG);
545 return retval;
546 }
548 static __inline PCHAR
549 __GET_XEN_INIT_STRING(PUCHAR *ptr)
550 {
551 PCHAR retval;
552 retval = (PCHAR)*ptr;
553 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_STRING *ptr = %p, retval = %s\n", *ptr, retval));
554 *ptr += strlen((PCHAR)*ptr) + 1;
555 return retval;
556 }
558 static __inline PVOID
559 __GET_XEN_INIT_PTR(PUCHAR *ptr)
560 {
561 PVOID retval;
562 retval = *(PVOID *)(*ptr);
563 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_PTR *ptr = %p, retval = %p\n", *ptr, retval));
564 *ptr += sizeof(PVOID);
565 return retval;
566 }
568 static __inline VOID
569 ADD_XEN_INIT_REQ(PUCHAR *ptr, UCHAR type, PVOID p1, PVOID p2, PVOID p3)
570 {
571 __ADD_XEN_INIT_UCHAR(ptr, type);
572 switch (type)
573 {
574 case XEN_INIT_TYPE_END:
575 case XEN_INIT_TYPE_VECTORS:
576 case XEN_INIT_TYPE_RUN:
577 case XEN_INIT_TYPE_STATE_PTR:
578 // case XEN_INIT_TYPE_ACTIVE:
579 case XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION:
580 case XEN_INIT_TYPE_QEMU_HIDE_FLAGS:
581 case XEN_INIT_TYPE_QEMU_HIDE_FILTER:
582 break;
583 case XEN_INIT_TYPE_WRITE_STRING:
584 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
585 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p2);
586 break;
587 #if 0
588 case XEN_INIT_TYPE_MATCH_FRONT:
589 case XEN_INIT_TYPE_MATCH_BACK:
590 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
591 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p2);
592 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p3));
593 break;
594 #endif
595 case XEN_INIT_TYPE_RING:
596 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
597 case XEN_INIT_TYPE_READ_STRING_FRONT:
598 case XEN_INIT_TYPE_READ_STRING_BACK:
599 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
600 break;
601 case XEN_INIT_TYPE_EVENT_CHANNEL:
602 case XEN_INIT_TYPE_EVENT_CHANNEL_DPC:
603 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
604 __ADD_XEN_INIT_PTR(ptr, p2);
605 __ADD_XEN_INIT_PTR(ptr, p3);
606 break;
607 case XEN_INIT_TYPE_GRANT_ENTRIES:
608 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p2));
609 break;
610 // case XEN_INIT_TYPE_COPY_PTR:
611 // __ADD_XEN_INIT_STRING(ptr, p1);
612 // __ADD_XEN_INIT_PTR(ptr, p2);
613 // break;
614 }
615 }
617 static __inline UCHAR
618 GET_XEN_INIT_REQ(PUCHAR *ptr, PVOID *p1, PVOID *p2, PVOID *p3)
619 {
620 UCHAR retval;
622 retval = __GET_XEN_INIT_UCHAR(ptr);
623 switch (retval)
624 {
625 case XEN_INIT_TYPE_END:
626 case XEN_INIT_TYPE_VECTORS:
627 case XEN_INIT_TYPE_RUN:
628 case XEN_INIT_TYPE_STATE_PTR:
629 // case XEN_INIT_TYPE_ACTIVE:
630 case XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION:
631 *p1 = NULL;
632 *p2 = NULL;
633 break;
634 case XEN_INIT_TYPE_WRITE_STRING:
635 *p1 = __GET_XEN_INIT_STRING(ptr);
636 *p2 = __GET_XEN_INIT_STRING(ptr);
637 break;
638 #if 0
639 case XEN_INIT_TYPE_MATCH_FRONT:
640 case XEN_INIT_TYPE_MATCH_BACK:
641 *p1 = __GET_XEN_INIT_STRING(ptr);
642 *p2 = __GET_XEN_INIT_STRING(ptr);
643 *p3 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
644 break;
645 #endif
646 case XEN_INIT_TYPE_RING:
647 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
648 case XEN_INIT_TYPE_READ_STRING_FRONT:
649 case XEN_INIT_TYPE_READ_STRING_BACK:
650 *p1 = __GET_XEN_INIT_STRING(ptr);
651 *p2 = NULL;
652 break;
653 case XEN_INIT_TYPE_EVENT_CHANNEL:
654 case XEN_INIT_TYPE_EVENT_CHANNEL_DPC:
655 *p1 = __GET_XEN_INIT_STRING(ptr);
656 *p2 = __GET_XEN_INIT_PTR(ptr);
657 *p3 = __GET_XEN_INIT_PTR(ptr);
658 break;
659 case XEN_INIT_TYPE_GRANT_ENTRIES:
660 *p2 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
661 break;
662 // case XEN_INIT_TYPE_COPY_PTR:
663 // *p1 = __GET_XEN_INIT_STRING(ptr);
664 // *p2 = __GET_XEN_INIT_PTR(ptr);
665 // break;
666 }
667 return retval;
668 }
670 static __inline VOID
671 ADD_XEN_INIT_RSP(PUCHAR *ptr, UCHAR type, PVOID p1, PVOID p2, PVOID p3)
672 {
673 UNREFERENCED_PARAMETER(p3);
675 __ADD_XEN_INIT_UCHAR(ptr, type);
676 switch (type)
677 {
678 case XEN_INIT_TYPE_END:
679 case XEN_INIT_TYPE_WRITE_STRING: /* this shouldn't happen */
680 case XEN_INIT_TYPE_RUN:
681 // case XEN_INIT_TYPE_ACTIVE:
682 case XEN_INIT_TYPE_QEMU_HIDE_FILTER:
683 break;
684 case XEN_INIT_TYPE_RING:
685 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
686 __ADD_XEN_INIT_PTR(ptr, p2);
687 break;
688 case XEN_INIT_TYPE_EVENT_CHANNEL:
689 case XEN_INIT_TYPE_EVENT_CHANNEL_DPC:
690 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
691 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
692 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p2));
693 break;
694 case XEN_INIT_TYPE_READ_STRING_FRONT:
695 case XEN_INIT_TYPE_READ_STRING_BACK:
696 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
697 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p2);
698 break;
699 case XEN_INIT_TYPE_VECTORS:
700 //__ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p1));
701 memcpy(*ptr, p2, sizeof(XENPCI_VECTORS));
702 *ptr += sizeof(XENPCI_VECTORS);
703 break;
704 case XEN_INIT_TYPE_GRANT_ENTRIES:
705 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p1));
706 memcpy(*ptr, p2, PtrToUlong(p1) * sizeof(grant_entry_t));
707 *ptr += PtrToUlong(p1) * sizeof(grant_entry_t);
708 break;
709 case XEN_INIT_TYPE_QEMU_HIDE_FLAGS:
710 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p2));
711 break;
712 case XEN_INIT_TYPE_STATE_PTR:
713 __ADD_XEN_INIT_PTR(ptr, p2);
714 break;
715 case XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION:
716 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p2));
717 break;
718 // case XEN_INIT_TYPE_COPY_PTR:
719 // __ADD_XEN_INIT_STRING(ptr, p1);
720 // __ADD_XEN_INIT_PTR(ptr, p2);
721 // break;
722 }
723 }
725 static __inline UCHAR
726 GET_XEN_INIT_RSP(PUCHAR *ptr, PVOID *p1, PVOID *p2, PVOID *p3)
727 {
728 UCHAR retval;
730 UNREFERENCED_PARAMETER(p3);
732 retval = __GET_XEN_INIT_UCHAR(ptr);
733 switch (retval)
734 {
735 case XEN_INIT_TYPE_END:
736 case XEN_INIT_TYPE_RUN:
737 // case XEN_INIT_TYPE_ACTIVE:
738 case XEN_INIT_TYPE_QEMU_HIDE_FILTER:
739 *p1 = NULL;
740 *p2 = NULL;
741 break;
742 case XEN_INIT_TYPE_WRITE_STRING:
743 // this shouldn't happen - no response here
744 break;
745 case XEN_INIT_TYPE_RING:
746 *p1 = __GET_XEN_INIT_STRING(ptr);
747 *p2 = __GET_XEN_INIT_PTR(ptr);
748 break;
749 case XEN_INIT_TYPE_EVENT_CHANNEL:
750 case XEN_INIT_TYPE_EVENT_CHANNEL_DPC:
751 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
752 *p1 = __GET_XEN_INIT_STRING(ptr);
753 *p2 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
754 break;
755 case XEN_INIT_TYPE_READ_STRING_FRONT:
756 *p1 = __GET_XEN_INIT_STRING(ptr);
757 *p2 = __GET_XEN_INIT_STRING(ptr);
758 break;
759 case XEN_INIT_TYPE_READ_STRING_BACK:
760 *p1 = __GET_XEN_INIT_STRING(ptr);
761 *p2 = __GET_XEN_INIT_STRING(ptr);
762 break;
763 case XEN_INIT_TYPE_VECTORS:
764 *p1 = NULL;
765 *p2 = *ptr;
766 *ptr += ((PXENPCI_VECTORS)*p2)->length;
767 break;
768 case XEN_INIT_TYPE_GRANT_ENTRIES:
769 *p1 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
770 *p2 = *ptr;
771 *ptr += PtrToUlong(*p1) * sizeof(grant_ref_t);
772 break;
773 case XEN_INIT_TYPE_STATE_PTR:
774 *p2 = __GET_XEN_INIT_PTR(ptr);
775 break;
776 case XEN_INIT_TYPE_QEMU_HIDE_FLAGS:
777 *p2 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
778 break;
779 case XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION:
780 *p2 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
781 break;
782 // case XEN_INIT_TYPE_COPY_PTR:
783 // *p1 = __GET_XEN_INIT_STRING(ptr);
784 // *p2 = __GET_XEN_INIT_PTR(ptr);
785 }
786 return retval;
787 }
789 typedef BOOLEAN
790 (*PXEN_DMA_NEED_VIRTUAL_ADDRESS)(PIRP irp);
792 typedef ULONG
793 (*PXEN_DMA_GET_ALIGNMENT)(PIRP irp);
795 typedef struct {
796 PXEN_DMA_NEED_VIRTUAL_ADDRESS need_virtual_address;
797 PXEN_DMA_GET_ALIGNMENT get_alignment;
798 ULONG max_sg_elements;
799 } dma_driver_extension_t;
801 #endif