win-pvdrivers

view common/include/xen_windows.h @ 982:e9011a1ba5bb

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