win-pvdrivers

view common/include/xen_windows.h @ 802:05bab5b47a93

Fix backend state transition problems.
Cleanup.
author James Harper <james.harper@bendigoit.com.au>
date Sat Jun 26 23:17:31 2010 +1000 (2010-06-26)
parents 467005e7f509
children 2f4e64007b0f
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 #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, domid_t domid, 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 #define XEN_DATA_MAGIC 0x12345679
310 typedef struct {
311 ULONG magic;
312 USHORT length;
314 PVOID context;
315 PXEN_EVTCHN_BIND EvtChn_Bind;
316 PXEN_EVTCHN_BIND EvtChn_BindDpc;
317 PXEN_EVTCHN_UNBIND EvtChn_Unbind;
318 PXEN_EVTCHN_MASK EvtChn_Mask;
319 PXEN_EVTCHN_UNMASK EvtChn_Unmask;
320 PXEN_EVTCHN_NOTIFY EvtChn_Notify;
321 PXEN_EVTCHN_ACK_EVENT EvtChn_AckEvent;
322 PXEN_EVTCHN_SYNC EvtChn_Sync;
324 PXEN_GNTTBL_GETREF GntTbl_GetRef;
325 PXEN_GNTTBL_PUTREF GntTbl_PutRef;
326 PXEN_GNTTBL_GRANTACCESS GntTbl_GrantAccess;
327 PXEN_GNTTBL_ENDACCESS GntTbl_EndAccess;
329 PXEN_XENPCI_XEN_CONFIG_DEVICE XenPci_XenConfigDevice;
330 PXEN_XENPCI_XEN_SHUTDOWN_DEVICE XenPci_XenShutdownDevice;
332 CHAR path[128];
333 CHAR backend_path[128];
335 PXEN_XENBUS_READ XenBus_Read;
336 PXEN_XENBUS_WRITE XenBus_Write;
337 PXEN_XENBUS_PRINTF XenBus_Printf;
338 PXEN_XENBUS_STARTTRANSACTION XenBus_StartTransaction;
339 PXEN_XENBUS_ENDTRANSACTION XenBus_EndTransaction;
340 PXEN_XENBUS_LIST XenBus_List;
341 PXEN_XENBUS_ADDWATCH XenBus_AddWatch;
342 PXEN_XENBUS_REMWATCH XenBus_RemWatch;
344 } XENPCI_VECTORS, *PXENPCI_VECTORS;
346 /*
347 suspend_resume_state_xxx values
348 pdo will assert a value, and fdo will assert when complete
349 */
350 #define SR_STATE_RUNNING 0 /* normal working state */
351 #define SR_STATE_SUSPENDING 1 /* suspend has started */
352 #define SR_STATE_RESUMING 2 /* resume has started */
354 #define XEN_DEVICE_STATE_MAGIC ((ULONG)'XDST')
356 typedef struct {
357 ULONG magic;
358 USHORT length;
360 ULONG suspend_resume_state_pdo; /* only the PDO can touch this */
361 ULONG suspend_resume_state_fdo; /* only the FDO can touch this */
362 evtchn_port_t pdo_event_channel;
363 } XENPCI_DEVICE_STATE, *PXENPCI_DEVICE_STATE;
365 #define XEN_INIT_DRIVER_EXTENSION_MAGIC ((ULONG)'XCFG')
366 #define XEN_DMA_DRIVER_EXTENSION_MAGIC ((ULONG)'XDMA')
368 #define XEN_INIT_TYPE_END 0
369 #define XEN_INIT_TYPE_WRITE_STRING 1
370 #define XEN_INIT_TYPE_RING 2
371 #define XEN_INIT_TYPE_EVENT_CHANNEL 3
372 #define XEN_INIT_TYPE_EVENT_CHANNEL_IRQ 4
373 #define XEN_INIT_TYPE_READ_STRING_FRONT 5
374 #define XEN_INIT_TYPE_READ_STRING_BACK 6
375 #define XEN_INIT_TYPE_VECTORS 7
376 #define XEN_INIT_TYPE_GRANT_ENTRIES 8
377 #define XEN_INIT_TYPE_STATE_PTR 11
378 #define XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION 13
379 #define XEN_INIT_TYPE_EVENT_CHANNEL_DPC 16
380 #define XEN_INIT_TYPE_QEMU_HIDE_FLAGS 17 /* qemu hide flags */
381 #define XEN_INIT_TYPE_QEMU_HIDE_FILTER 18 /* qemu device hidden by class filter */
382 /*
383 state maps consist of 3 bytes: (maximum of 4 x 3 bytes)
384 front - state to set frontend to
385 back - state to expect from backend
386 wait - time in 100ms intervals to wait for backend
387 a single 0 byte terminates the list
388 */
389 #define XEN_INIT_TYPE_XB_STATE_MAP_PRE_CONNECT 19
390 #define XEN_INIT_TYPE_XB_STATE_MAP_POST_CONNECT 20
391 #define XEN_INIT_TYPE_XB_STATE_MAP_SHUTDOWN 21
393 static __inline VOID
394 __ADD_XEN_INIT_UCHAR(PUCHAR *ptr, UCHAR val)
395 {
396 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_UCHAR *ptr = %p, val = %d\n", *ptr, val));
397 *(PUCHAR)(*ptr) = val;
398 *ptr += sizeof(UCHAR);
399 }
401 static __inline VOID
402 __ADD_XEN_INIT_USHORT(PUCHAR *ptr, USHORT val)
403 {
404 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_USHORT *ptr = %p, val = %d\n", *ptr, val));
405 *(PUSHORT)(*ptr) = val;
406 *ptr += sizeof(USHORT);
407 }
409 static __inline VOID
410 __ADD_XEN_INIT_ULONG(PUCHAR *ptr, ULONG val)
411 {
412 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_ULONG *ptr = %p, val = %d\n", *ptr, val));
413 *(PULONG)(*ptr) = val;
414 *ptr += sizeof(ULONG);
415 }
417 static __inline VOID
418 __ADD_XEN_INIT_PTR(PUCHAR *ptr, PVOID val)
419 {
420 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_PTR *ptr = %p, val = %p\n", *ptr, val));
421 *(PVOID *)(*ptr) = val;
422 *ptr += sizeof(PVOID);
423 }
425 static __inline VOID
426 __ADD_XEN_INIT_STRING(PUCHAR *ptr, PCHAR val)
427 {
428 // KdPrint((__DRIVER_NAME " ADD_XEN_INIT_STRING *ptr = %p, val = %s\n", *ptr, val));
429 size_t max_string_size = PAGE_SIZE - (PtrToUlong(*ptr) & (PAGE_SIZE - 1));
430 RtlStringCbCopyA((PCHAR)*ptr, max_string_size, val);
431 *ptr += min(strlen(val) + 1, max_string_size);
432 }
434 static __inline UCHAR
435 __GET_XEN_INIT_UCHAR(PUCHAR *ptr)
436 {
437 UCHAR retval;
438 retval = **ptr;
439 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_UCHAR *ptr = %p, retval = %d\n", *ptr, retval));
440 *ptr += sizeof(UCHAR);
441 return retval;
442 }
444 static __inline USHORT
445 __GET_XEN_INIT_USHORT(PUCHAR *ptr)
446 {
447 USHORT retval;
448 retval = *(PUSHORT)*ptr;
449 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_USHORT *ptr = %p, retval = %d\n", *ptr, retval));
450 *ptr += sizeof(USHORT);
451 return retval;
452 }
454 static __inline ULONG
455 __GET_XEN_INIT_ULONG(PUCHAR *ptr)
456 {
457 ULONG retval;
458 retval = *(PLONG)*ptr;
459 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_ULONG *ptr = %p, retval = %d\n", *ptr, retval));
460 *ptr += sizeof(ULONG);
461 return retval;
462 }
464 static __inline PCHAR
465 __GET_XEN_INIT_STRING(PUCHAR *ptr)
466 {
467 PCHAR retval;
468 retval = (PCHAR)*ptr;
469 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_STRING *ptr = %p, retval = %s\n", *ptr, retval));
470 *ptr += strlen((PCHAR)*ptr) + 1;
471 return retval;
472 }
474 static __inline PVOID
475 __GET_XEN_INIT_PTR(PUCHAR *ptr)
476 {
477 PVOID retval;
478 retval = *(PVOID *)(*ptr);
479 // KdPrint((__DRIVER_NAME " GET_XEN_INIT_PTR *ptr = %p, retval = %p\n", *ptr, retval));
480 *ptr += sizeof(PVOID);
481 return retval;
482 }
484 static __inline VOID
485 ADD_XEN_INIT_REQ(PUCHAR *ptr, UCHAR type, PVOID p1, PVOID p2, PVOID p3)
486 {
487 __ADD_XEN_INIT_UCHAR(ptr, type);
488 switch (type)
489 {
490 case XEN_INIT_TYPE_END:
491 case XEN_INIT_TYPE_VECTORS:
492 case XEN_INIT_TYPE_STATE_PTR:
493 case XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION:
494 case XEN_INIT_TYPE_QEMU_HIDE_FLAGS:
495 case XEN_INIT_TYPE_QEMU_HIDE_FILTER:
496 case XEN_INIT_TYPE_XB_STATE_MAP_PRE_CONNECT:
497 case XEN_INIT_TYPE_XB_STATE_MAP_POST_CONNECT:
498 case XEN_INIT_TYPE_XB_STATE_MAP_SHUTDOWN:
499 break;
500 case XEN_INIT_TYPE_WRITE_STRING:
501 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
502 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p2);
503 break;
504 case XEN_INIT_TYPE_RING:
505 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
506 case XEN_INIT_TYPE_READ_STRING_FRONT:
507 case XEN_INIT_TYPE_READ_STRING_BACK:
508 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
509 break;
510 case XEN_INIT_TYPE_EVENT_CHANNEL:
511 case XEN_INIT_TYPE_EVENT_CHANNEL_DPC:
512 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
513 __ADD_XEN_INIT_PTR(ptr, p2);
514 __ADD_XEN_INIT_PTR(ptr, p3);
515 break;
516 case XEN_INIT_TYPE_GRANT_ENTRIES:
517 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p2));
518 break;
519 // case XEN_INIT_TYPE_COPY_PTR:
520 // __ADD_XEN_INIT_STRING(ptr, p1);
521 // __ADD_XEN_INIT_PTR(ptr, p2);
522 // break;
523 }
524 }
526 static __inline UCHAR
527 GET_XEN_INIT_REQ(PUCHAR *ptr, PVOID *p1, PVOID *p2, PVOID *p3)
528 {
529 UCHAR retval;
531 retval = __GET_XEN_INIT_UCHAR(ptr);
532 switch (retval)
533 {
534 case XEN_INIT_TYPE_END:
535 case XEN_INIT_TYPE_VECTORS:
536 case XEN_INIT_TYPE_STATE_PTR:
537 case XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION:
538 case XEN_INIT_TYPE_XB_STATE_MAP_PRE_CONNECT:
539 case XEN_INIT_TYPE_XB_STATE_MAP_POST_CONNECT:
540 case XEN_INIT_TYPE_XB_STATE_MAP_SHUTDOWN:
541 *p1 = NULL;
542 *p2 = NULL;
543 break;
544 case XEN_INIT_TYPE_WRITE_STRING:
545 *p1 = __GET_XEN_INIT_STRING(ptr);
546 *p2 = __GET_XEN_INIT_STRING(ptr);
547 break;
548 case XEN_INIT_TYPE_RING:
549 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
550 case XEN_INIT_TYPE_READ_STRING_FRONT:
551 case XEN_INIT_TYPE_READ_STRING_BACK:
552 *p1 = __GET_XEN_INIT_STRING(ptr);
553 *p2 = NULL;
554 break;
555 case XEN_INIT_TYPE_EVENT_CHANNEL:
556 case XEN_INIT_TYPE_EVENT_CHANNEL_DPC:
557 *p1 = __GET_XEN_INIT_STRING(ptr);
558 *p2 = __GET_XEN_INIT_PTR(ptr);
559 *p3 = __GET_XEN_INIT_PTR(ptr);
560 break;
561 case XEN_INIT_TYPE_GRANT_ENTRIES:
562 *p2 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
563 break;
564 }
565 return retval;
566 }
568 static __inline VOID
569 ADD_XEN_INIT_RSP(PUCHAR *ptr, UCHAR type, PVOID p1, PVOID p2, PVOID p3)
570 {
571 UNREFERENCED_PARAMETER(p3);
573 __ADD_XEN_INIT_UCHAR(ptr, type);
574 switch (type)
575 {
576 case XEN_INIT_TYPE_END:
577 case XEN_INIT_TYPE_WRITE_STRING: /* this shouldn't happen */
578 case XEN_INIT_TYPE_QEMU_HIDE_FILTER:
579 break;
580 case XEN_INIT_TYPE_RING:
581 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
582 __ADD_XEN_INIT_PTR(ptr, p2);
583 break;
584 case XEN_INIT_TYPE_EVENT_CHANNEL:
585 case XEN_INIT_TYPE_EVENT_CHANNEL_DPC:
586 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
587 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
588 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p2));
589 break;
590 case XEN_INIT_TYPE_READ_STRING_FRONT:
591 case XEN_INIT_TYPE_READ_STRING_BACK:
592 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p1);
593 __ADD_XEN_INIT_STRING(ptr, (PCHAR) p2);
594 break;
595 case XEN_INIT_TYPE_VECTORS:
596 //__ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p1));
597 memcpy(*ptr, p2, sizeof(XENPCI_VECTORS));
598 *ptr += sizeof(XENPCI_VECTORS);
599 break;
600 case XEN_INIT_TYPE_GRANT_ENTRIES:
601 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p1));
602 memcpy(*ptr, p2, PtrToUlong(p1) * sizeof(grant_entry_t));
603 *ptr += PtrToUlong(p1) * sizeof(grant_entry_t);
604 break;
605 case XEN_INIT_TYPE_QEMU_HIDE_FLAGS:
606 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p2));
607 break;
608 case XEN_INIT_TYPE_STATE_PTR:
609 __ADD_XEN_INIT_PTR(ptr, p2);
610 break;
611 case XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION:
612 __ADD_XEN_INIT_ULONG(ptr, PtrToUlong(p2));
613 break;
614 }
615 }
617 static __inline UCHAR
618 GET_XEN_INIT_RSP(PUCHAR *ptr, PVOID *p1, PVOID *p2, PVOID *p3)
619 {
620 UCHAR retval;
622 UNREFERENCED_PARAMETER(p3);
624 retval = __GET_XEN_INIT_UCHAR(ptr);
625 switch (retval)
626 {
627 case XEN_INIT_TYPE_END:
628 case XEN_INIT_TYPE_QEMU_HIDE_FILTER:
629 *p1 = NULL;
630 *p2 = NULL;
631 break;
632 case XEN_INIT_TYPE_WRITE_STRING:
633 // this shouldn't happen - no response here
634 break;
635 case XEN_INIT_TYPE_RING:
636 *p1 = __GET_XEN_INIT_STRING(ptr);
637 *p2 = __GET_XEN_INIT_PTR(ptr);
638 break;
639 case XEN_INIT_TYPE_EVENT_CHANNEL:
640 case XEN_INIT_TYPE_EVENT_CHANNEL_DPC:
641 case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ:
642 *p1 = __GET_XEN_INIT_STRING(ptr);
643 *p2 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
644 break;
645 case XEN_INIT_TYPE_READ_STRING_FRONT:
646 *p1 = __GET_XEN_INIT_STRING(ptr);
647 *p2 = __GET_XEN_INIT_STRING(ptr);
648 break;
649 case XEN_INIT_TYPE_READ_STRING_BACK:
650 *p1 = __GET_XEN_INIT_STRING(ptr);
651 *p2 = __GET_XEN_INIT_STRING(ptr);
652 break;
653 case XEN_INIT_TYPE_VECTORS:
654 *p1 = NULL;
655 *p2 = *ptr;
656 *ptr += ((PXENPCI_VECTORS)*p2)->length;
657 break;
658 case XEN_INIT_TYPE_GRANT_ENTRIES:
659 *p1 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
660 *p2 = *ptr;
661 *ptr += PtrToUlong(*p1) * sizeof(grant_ref_t);
662 break;
663 case XEN_INIT_TYPE_STATE_PTR:
664 *p2 = __GET_XEN_INIT_PTR(ptr);
665 break;
666 case XEN_INIT_TYPE_QEMU_HIDE_FLAGS:
667 *p2 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
668 break;
669 case XEN_INIT_TYPE_QEMU_PROTOCOL_VERSION:
670 *p2 = UlongToPtr(__GET_XEN_INIT_ULONG(ptr));
671 break;
672 }
673 return retval;
674 }
676 typedef BOOLEAN
677 (*PXEN_DMA_NEED_VIRTUAL_ADDRESS)(PIRP irp);
679 typedef ULONG
680 (*PXEN_DMA_GET_ALIGNMENT)(PIRP irp);
682 typedef struct {
683 PXEN_DMA_NEED_VIRTUAL_ADDRESS need_virtual_address;
684 PXEN_DMA_GET_ALIGNMENT get_alignment;
685 ULONG max_sg_elements;
686 } dma_driver_extension_t;
688 #endif