win-pvdrivers

view xenpci/xenpci.c @ 31:f56c47274c37

Automated merge with ssh://win-pvdrivers@xenbits.xensource.com/win-pvdrivers.hg
author Andy Grover <andy.grover@oracle.com>
date Mon Dec 03 23:05:02 2007 -0800 (2007-12-03)
parents 53fdfc9f5d56 28803c117324
children 3ac5c4431dbb
line source
1 /*
2 PV Drivers for Windows Xen HVM Domains
3 Copyright (C) 2007 James Harper
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
20 #include "xenpci.h"
21 #include "hypercall.h"
22 #include <stdlib.h>
24 #define SHUTDOWN_PATH "control/shutdown"
25 #define BALLOON_PATH "memory/target"
27 DRIVER_INITIALIZE DriverEntry;
28 static NTSTATUS
29 XenPCI_AddDevice(WDFDRIVER Driver, PWDFDEVICE_INIT DeviceInit);
30 static NTSTATUS
31 XenPCI_PrepareHardware(WDFDEVICE hDevice, WDFCMRESLIST Resources, WDFCMRESLIST ResourcesTranslated);
32 static NTSTATUS
33 XenPCI_ReleaseHardware(WDFDEVICE Device, WDFCMRESLIST ResourcesTranslated);
34 static NTSTATUS
35 XenPCI_D0Entry(WDFDEVICE Device, WDF_POWER_DEVICE_STATE PreviousState);
36 static NTSTATUS
37 XenPCI_D0EntryPostInterruptsEnabled(WDFDEVICE Device, WDF_POWER_DEVICE_STATE PreviousState);
38 static NTSTATUS
39 XenPCI_D0Exit(WDFDEVICE Device, WDF_POWER_DEVICE_STATE TargetState);
40 static NTSTATUS
41 XenPCI_D0ExitPreInterruptsDisabled(WDFDEVICE Device, WDF_POWER_DEVICE_STATE TargetState);
42 static VOID
43 XenPCI_IoDefault(WDFQUEUE Queue, WDFREQUEST Request);
44 static NTSTATUS
45 XenPCI_InterruptEnable(WDFINTERRUPT Interrupt, WDFDEVICE AssociatedDevice);
46 static NTSTATUS
47 XenPCI_InterruptDisable(WDFINTERRUPT Interrupt, WDFDEVICE AssociatedDevice);
48 static NTSTATUS
49 XenPCI_ChildListCreateDevice(WDFCHILDLIST ChildList, PWDF_CHILD_IDENTIFICATION_DESCRIPTION_HEADER IdentificationDescription, PWDFDEVICE_INIT ChildInit);
50 static NTSTATUS
51 XenPCI_DeviceResourceRequirementsQuery(WDFDEVICE Device, WDFIORESREQLIST IoResourceRequirementsList);
52 static NTSTATUS
53 XenPCI_FilterRemoveResourceRequirements(WDFDEVICE Device, WDFIORESREQLIST IoResourceRequirementsList);
54 static NTSTATUS
55 XenPCI_FilterAddResourceRequirements(WDFDEVICE Device, WDFIORESREQLIST RequirementsList);
56 static NTSTATUS
57 XenPCI_RemoveAddedResources(WDFDEVICE Device, WDFCMRESLIST ResourcesRaw, WDFCMRESLIST ResourcesTranslated);
59 static VOID
60 XenBus_ShutdownHandler(char *Path, PVOID Data);
61 static VOID
62 XenBus_BalloonHandler(char *Path, PVOID Data);
63 static VOID
64 XenPCI_XenBusWatchHandler(char *Path, PVOID Data);
66 #ifdef ALLOC_PRAGMA
67 #pragma alloc_text (INIT, DriverEntry)
68 #pragma alloc_text (PAGE, XenPCI_AddDevice)
69 #endif
71 /* Global (driver-wide) variables */
72 static BOOLEAN AutoEnumerate;
74 NTSTATUS
75 DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
76 {
77 WDF_DRIVER_CONFIG config;
78 NTSTATUS status;
79 UNICODE_STRING RegKeyName;
80 UNICODE_STRING RegValueName;
81 HANDLE RegHandle;
82 OBJECT_ATTRIBUTES RegObjectAttributes;
83 char Buf[200];
84 ULONG BufLen = 200;
85 PKEY_VALUE_PARTIAL_INFORMATION KeyPartialValue;
86 int State = 0;
87 int StartPos = 0;
88 WCHAR *SystemStartOptions;
89 size_t SystemStartOptionsLen;
90 size_t i;
92 KdPrint((__DRIVER_NAME " --> DriverEntry\n"));
94 RtlInitUnicodeString(&RegKeyName, L"\\Registry\\Machine\\System\\CurrentControlSet\\Control");
95 InitializeObjectAttributes(&RegObjectAttributes, &RegKeyName, OBJ_CASE_INSENSITIVE, NULL, NULL);
96 status = ZwOpenKey(&RegHandle, KEY_READ, &RegObjectAttributes);
97 if(!NT_SUCCESS(status))
98 {
99 KdPrint((__DRIVER_NAME " ZwOpenKey returned %08x\n", status));
100 }
102 RtlInitUnicodeString(&RegValueName, L"SystemStartOptions");
103 status = ZwQueryValueKey(RegHandle, &RegValueName, KeyValuePartialInformation, Buf, BufLen, &BufLen);
104 if(!NT_SUCCESS(status))
105 {
106 KdPrint((__DRIVER_NAME " ZwQueryKeyValue returned %08x\n", status));
107 }
108 //KdPrint((__DRIVER_NAME " BufLen = %d\n", BufLen));
109 KeyPartialValue = (PKEY_VALUE_PARTIAL_INFORMATION)Buf;
110 KdPrint((__DRIVER_NAME " Buf = %ws\n", KeyPartialValue->Data));
111 SystemStartOptions = (WCHAR *)KeyPartialValue->Data;
113 AutoEnumerate = FALSE;
115 RtlStringCbLengthW(SystemStartOptions, KeyPartialValue->DataLength, &SystemStartOptionsLen);
117 for (i = 0; i <= SystemStartOptionsLen/2; i++)
118 {
119 //KdPrint((__DRIVER_NAME " pos = %d, state = %d, char = '%wc' (%d)\n", i, State, SystemStartOptions[i], SystemStartOptions[i]));
121 switch (State)
122 {
123 case 0:
124 if (SystemStartOptions[i] == L'G')
125 {
126 StartPos = i;
127 State = 2;
128 } else if (SystemStartOptions[i] != L' ')
129 {
130 State = 1;
131 }
132 break;
133 case 1:
134 if (SystemStartOptions[i] == L' ')
135 State = 0;
136 break;
137 case 2:
138 if (SystemStartOptions[i] == L'P')
139 State = 3;
140 else
141 State = 0;
142 break;
143 case 3:
144 if (SystemStartOptions[i] == L'L')
145 State = 4;
146 else
147 State = 0;
148 break;
149 case 4:
150 if (SystemStartOptions[i] == L'P')
151 State = 5;
152 else
153 State = 0;
154 break;
155 case 5:
156 if (SystemStartOptions[i] == L'V')
157 State = 6;
158 else
159 State = 0;
160 break;
161 case 6:
162 if (SystemStartOptions[i] == L' ' || SystemStartOptions[i] == 0)
163 AutoEnumerate = TRUE;
164 State = 0;
165 break;
166 }
167 }
169 KdPrint((__DRIVER_NAME " AutoEnumerate = %d\n", AutoEnumerate));
171 WDF_DRIVER_CONFIG_INIT(&config, XenPCI_AddDevice);
172 status = WdfDriverCreate(
173 DriverObject,
174 RegistryPath,
175 WDF_NO_OBJECT_ATTRIBUTES,
176 &config,
177 WDF_NO_HANDLE);
178 if(!NT_SUCCESS(status))
179 {
180 KdPrint((__DRIVER_NAME " WdfDriverCreate failed with status 0x%08x\n", status));
181 }
183 KdPrint((__DRIVER_NAME " <-- DriverEntry\n"));
185 return status;
186 }
188 static NTSTATUS
189 get_hypercall_stubs(WDFDEVICE Device)
190 {
191 PXENPCI_DEVICE_DATA xpdd = GetDeviceData(Device);
192 DWORD32 cpuid_output[4];
193 char xensig[13];
194 ULONG i;
195 ULONG pages;
196 ULONG msr;
198 __cpuid(cpuid_output, 0x40000000);
199 *(ULONG*)(xensig + 0) = cpuid_output[1];
200 *(ULONG*)(xensig + 4) = cpuid_output[2];
201 *(ULONG*)(xensig + 8) = cpuid_output[3];
202 xensig[12] = '\0';
203 KdPrint((__DRIVER_NAME " Xen Signature = %s, EAX = 0x%08x\n", xensig, cpuid_output[0]));
205 __cpuid(cpuid_output, 0x40000002);
206 pages = cpuid_output[0];
207 msr = cpuid_output[1];
208 //KdPrint((__DRIVER_NAME " Hypercall area is %u pages.\n", pages));
210 xpdd->hypercall_stubs = ExAllocatePoolWithTag(NonPagedPool, pages * PAGE_SIZE, XENPCI_POOL_TAG);
211 //KdPrint((__DRIVER_NAME " Hypercall area at %08x\n", hypercall_stubs));
213 if (!xpdd->hypercall_stubs)
214 return 1;
215 for (i = 0; i < pages; i++) {
216 ULONG pfn;
217 //pfn = vmalloc_to_pfn((char *)hypercall_stubs + i * PAGE_SIZE);
218 pfn = (ULONG)(MmGetPhysicalAddress(xpdd->hypercall_stubs + i * PAGE_SIZE).QuadPart >> PAGE_SHIFT);
219 //KdPrint((__DRIVER_NAME " pfn = %08X\n", pfn));
220 __writemsr(msr, ((ULONGLONG)pfn << PAGE_SHIFT) + i);
221 }
222 return STATUS_SUCCESS;
223 }
225 PHYSICAL_ADDRESS
226 XenPCI_AllocMMIO(WDFDEVICE Device, ULONG len)
227 {
228 PXENPCI_DEVICE_DATA xpdd = GetDeviceData(Device);
230 PHYSICAL_ADDRESS addr;
232 addr = xpdd->platform_mmio_addr;
233 addr.QuadPart += xpdd->platform_mmio_alloc;
234 xpdd->platform_mmio_alloc += len;
236 return addr;
237 }
239 static int
240 init_xen_info(WDFDEVICE Device)
241 {
242 PXENPCI_DEVICE_DATA xpdd = GetDeviceData(Device);
243 struct xen_add_to_physmap xatp;
244 int ret;
245 PHYSICAL_ADDRESS shared_info_area_unmapped;
247 //setup_xen_features();
248 //KdPrint((__DRIVER_NAME " init_xen_info Hypercall area at %08x\n", hypercall_stubs));
250 shared_info_area_unmapped = XenPCI_AllocMMIO(Device, PAGE_SIZE);
251 xatp.domid = DOMID_SELF;
252 xatp.idx = 0;
253 xatp.space = XENMAPSPACE_shared_info;
254 xatp.gpfn = (xen_pfn_t)(shared_info_area_unmapped.QuadPart >> PAGE_SHIFT);
255 ret = HYPERVISOR_memory_op(Device, XENMEM_add_to_physmap, &xatp);
256 //KdPrint((__DRIVER_NAME " ret = %d\n", ret));
258 xpdd->shared_info_area = MmMapIoSpace(shared_info_area_unmapped,
259 PAGE_SIZE, MmNonCached);
261 return 0;
262 }
264 static int
265 set_callback_irq(WDFDEVICE Device, ULONGLONG irq)
266 {
267 struct xen_hvm_param a;
268 int retval;
270 //KdPrint((__DRIVER_NAME " --> set_callback_irq\n"));
271 a.domid = DOMID_SELF;
272 a.index = HVM_PARAM_CALLBACK_IRQ;
273 a.value = irq;
274 retval = HYPERVISOR_hvm_op(Device, HVMOP_set_param, &a);
275 //KdPrint((__DRIVER_NAME " HYPERVISOR_hvm_op retval = %d\n", retval));
276 //KdPrint((__DRIVER_NAME " <-- set_callback_irq\n"));
277 return retval;
278 }
280 static NTSTATUS
281 XenPCI_AddDevice(
282 IN WDFDRIVER Driver,
283 IN PWDFDEVICE_INIT DeviceInit
284 )
285 {
286 NTSTATUS status;
287 WDF_CHILD_LIST_CONFIG config;
288 WDF_OBJECT_ATTRIBUTES attributes;
289 WDF_PNPPOWER_EVENT_CALLBACKS pnpPowerCallbacks;
290 WDF_INTERRUPT_CONFIG interruptConfig;
291 PNP_BUS_INFORMATION busInfo;
292 BUS_INTERFACE_STANDARD BusInterface;
293 WDFDEVICE Device;
294 PXENPCI_DEVICE_DATA xpdd;
296 UNREFERENCED_PARAMETER(Driver);
298 KdPrint((__DRIVER_NAME " --> DeviceAdd\n"));
300 // get PDO
301 // get parent (should be PCI bus) (WdfPdoGetParent)
302 //
304 WdfDeviceInitSetDeviceType(DeviceInit, FILE_DEVICE_BUS_EXTENDER);
305 WDF_CHILD_LIST_CONFIG_INIT(&config, sizeof(XENPCI_IDENTIFICATION_DESCRIPTION), XenPCI_ChildListCreateDevice);
306 WdfFdoInitSetDefaultChildListConfig(DeviceInit, &config, WDF_NO_OBJECT_ATTRIBUTES);
308 // WDF_FDO_EVENT_CALLBACKS_INIT(&FdoCallbacks);
309 // FdoCallbacks.EvtDeviceFilterRemoveResourceRequirements = XenPCI_FilterRemoveResourceRequirements;
310 // FdoCallbacks.EvtDeviceFilterAddResourceRequirements = XenPCI_FilterAddResourceRequirements;
311 // FdoCallbacks.EvtDeviceRemoveAddedResources = XenPCI_RemoveAddedResources;
312 // WdfFdoInitSetEventCallbacks(DeviceInit, &FdoCallbacks);
314 WDF_PNPPOWER_EVENT_CALLBACKS_INIT(&pnpPowerCallbacks);
315 pnpPowerCallbacks.EvtDevicePrepareHardware = XenPCI_PrepareHardware;
316 pnpPowerCallbacks.EvtDeviceReleaseHardware = XenPCI_ReleaseHardware;
317 pnpPowerCallbacks.EvtDeviceD0Entry = XenPCI_D0Entry;
318 pnpPowerCallbacks.EvtDeviceD0EntryPostInterruptsEnabled
319 = XenPCI_D0EntryPostInterruptsEnabled;
320 pnpPowerCallbacks.EvtDeviceD0ExitPreInterruptsDisabled
321 = XenPCI_D0ExitPreInterruptsDisabled;
322 pnpPowerCallbacks.EvtDeviceD0Exit = XenPCI_D0Exit;
323 WdfDeviceInitSetPnpPowerEventCallbacks(DeviceInit, &pnpPowerCallbacks);
325 WdfDeviceInitSetIoType(DeviceInit, WdfDeviceIoBuffered);
327 /*initialize storage for the device context*/
328 WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&attributes, XENPCI_DEVICE_DATA);
330 /*create a device instance.*/
331 status = WdfDeviceCreate(&DeviceInit, &attributes, &Device);
332 if(!NT_SUCCESS(status))
333 {
334 KdPrint((__DRIVER_NAME " WdfDeviceCreate failed with status 0x%08x\n", status));
335 return status;
336 }
337 xpdd = GetDeviceData(Device);
338 xpdd->Device = Device;
340 WdfDeviceSetSpecialFileSupport(Device, WdfSpecialFilePaging, TRUE);
341 WdfDeviceSetSpecialFileSupport(Device, WdfSpecialFileHibernation, TRUE);
342 WdfDeviceSetSpecialFileSupport(Device, WdfSpecialFileDump, TRUE);
344 status = WdfFdoQueryForInterface(Device, &GUID_BUS_INTERFACE_STANDARD, (PINTERFACE) &BusInterface, sizeof(BUS_INTERFACE_STANDARD), 1, NULL);
345 if(!NT_SUCCESS(status))
346 {
347 KdPrint((__DRIVER_NAME " WdfFdoQueryForInterface (BusInterface) failed with status 0x%08x\n", status));
348 }
350 busInfo.BusTypeGuid = GUID_XENPCI_DEVCLASS;
351 busInfo.LegacyBusType = PNPBus;
352 busInfo.BusNumber = 0;
354 WdfDeviceSetBusInformationForChildren(Device, &busInfo);
356 WDF_INTERRUPT_CONFIG_INIT(&interruptConfig, EvtChn_Interrupt, NULL);
357 interruptConfig.EvtInterruptEnable = XenPCI_InterruptEnable;
358 interruptConfig.EvtInterruptDisable = XenPCI_InterruptDisable;
359 status = WdfInterruptCreate(Device, &interruptConfig, WDF_NO_OBJECT_ATTRIBUTES, &xpdd->XenInterrupt);
360 if (!NT_SUCCESS (status))
361 {
362 KdPrint((__DRIVER_NAME "WdfInterruptCreate failed 0x%08x\n", status));
363 return status;
364 }
366 KdPrint((__DRIVER_NAME " <-- DeviceAdd\n"));
367 return status;
368 }
370 static NTSTATUS
371 XenPCI_PrepareHardware(
372 IN WDFDEVICE Device,
373 IN WDFCMRESLIST ResourceList,
374 IN WDFCMRESLIST ResourceListTranslated)
375 {
376 NTSTATUS status = STATUS_SUCCESS;
377 PCM_PARTIAL_RESOURCE_DESCRIPTOR descriptor;
378 ULONG i;
379 PXENPCI_DEVICE_DATA xpdd = GetDeviceData(Device);
381 KdPrint((__DRIVER_NAME " --> EvtDevicePrepareHardware\n"));
383 for (i = 0; i < WdfCmResourceListGetCount(ResourceList); i++)
384 {
385 descriptor = WdfCmResourceListGetDescriptor(ResourceList, i);
386 if(!descriptor)
387 continue;
388 switch (descriptor->Type)
389 {
390 case CmResourceTypeInterrupt:
391 xpdd->irqNumber = descriptor->u.Interrupt.Vector;
392 break;
393 }
394 }
396 //KdPrint((__DRIVER_NAME " GSI = %d\n", irqNumber));
398 //KdPrint((__DRIVER_NAME " ResourceListTranslated\n"));
399 for (i = 0; i < WdfCmResourceListGetCount(ResourceListTranslated); i++)
400 {
401 descriptor = WdfCmResourceListGetDescriptor(ResourceListTranslated, i);
402 if(!descriptor)
403 {
404 KdPrint((__DRIVER_NAME " --> EvtDevicePrepareHardware (No descriptor)\n"));
405 return STATUS_DEVICE_CONFIGURATION_ERROR;
406 }
407 switch (descriptor->Type) {
408 case CmResourceTypePort:
409 //KdPrint((__DRIVER_NAME " I/O mapped CSR: (%x) Length: (%d)\n", descriptor->u.Port.Start.LowPart, descriptor->u.Port.Length));
410 // xpdd->IoBaseAddress = ULongToPtr(descriptor->u.Port.Start.LowPart);
411 // xpdd->IoRange = descriptor->u.Port.Length;
412 break;
413 case CmResourceTypeMemory:
414 KdPrint((__DRIVER_NAME " Memory mapped CSR:(%x:%x) Length:(%d)\n", descriptor->u.Memory.Start.LowPart, descriptor->u.Memory.Start.HighPart, descriptor->u.Memory.Length));
415 xpdd->platform_mmio_addr = descriptor->u.Memory.Start; //(ULONG)MmMapIoSpace(descriptor->u.Memory.Start, descriptor->u.Memory.Length, MmNonCached);
416 xpdd->platform_mmio_len = descriptor->u.Memory.Length;
417 xpdd->platform_mmio_alloc = 0;
418 break;
419 case CmResourceTypeInterrupt:
420 //KdPrint((__DRIVER_NAME " Interrupt level: 0x%0x, Vector: 0x%0x\n", descriptor->u.Interrupt.Level, descriptor->u.Interrupt.Vector));
421 break;
422 case CmResourceTypeDevicePrivate:
423 //KdPrint((__DRIVER_NAME " Private Data: 0x%02x 0x%02x 0x%02x\n", descriptor->u.DevicePrivate.Data[0], descriptor->u.DevicePrivate.Data[1], descriptor->u.DevicePrivate.Data[2] ));
424 break;
425 default:
426 //KdPrint((__DRIVER_NAME " Unhandled resource type (0x%x)\n", descriptor->Type));
427 break;
428 }
429 }
431 get_hypercall_stubs(Device);
433 init_xen_info(Device);
435 GntTbl_Init(Device);
437 EvtChn_Init(Device);
439 set_callback_irq(Device, xpdd->irqNumber);
441 XenBus_Init(Device);
443 //KdPrint((__DRIVER_NAME " upcall_pending = %d\n", shared_info_area->vcpu_info[0].evtchn_upcall_pending));
445 xpdd->shared_info_area->vcpu_info[0].evtchn_upcall_mask = 0;
447 //xen_reboot_init();
449 KdPrint((__DRIVER_NAME " <-- EvtDevicePrepareHardware\n"));
451 return status;
452 }
454 static NTSTATUS
455 XenPCI_ReleaseHardware(WDFDEVICE Device, WDFCMRESLIST ResourcesTranslated)
456 {
457 UNREFERENCED_PARAMETER(Device);
458 UNREFERENCED_PARAMETER(ResourcesTranslated);
460 return STATUS_SUCCESS;
461 }
463 static NTSTATUS
464 XenPCI_D0Entry(
465 IN WDFDEVICE Device,
466 IN WDF_POWER_DEVICE_STATE PreviousState
467 )
468 {
469 NTSTATUS status = STATUS_SUCCESS;
471 UNREFERENCED_PARAMETER(Device);
472 UNREFERENCED_PARAMETER(PreviousState);
474 KdPrint((__DRIVER_NAME " --> EvtDeviceD0Entry\n"));
476 KdPrint((__DRIVER_NAME " <-- EvtDeviceD0Entry\n"));
478 return status;
479 }
481 static NTSTATUS
482 XenPCI_D0EntryPostInterruptsEnabled(WDFDEVICE Device, WDF_POWER_DEVICE_STATE PreviousState)
483 {
484 NTSTATUS status = STATUS_SUCCESS;
485 //OBJECT_ATTRIBUTES oa;
486 char *response;
487 char *msgTypes;
488 char **Types;
489 int i;
490 char buffer[128];
492 UNREFERENCED_PARAMETER(PreviousState);
494 KdPrint((__DRIVER_NAME " --> EvtDeviceD0EntryPostInterruptsEnabled\n"));
496 XenBus_Start(Device);
498 KdPrint((__DRIVER_NAME " A\n"));
500 response = XenBus_AddWatch(Device, XBT_NIL, SHUTDOWN_PATH, XenBus_ShutdownHandler, Device);
501 KdPrint((__DRIVER_NAME " shutdown watch response = '%s'\n", response));
503 response = XenBus_AddWatch(Device, XBT_NIL, BALLOON_PATH, XenBus_BalloonHandler, Device);
504 KdPrint((__DRIVER_NAME " shutdown watch response = '%s'\n", response));
506 response = XenBus_AddWatch(Device, XBT_NIL, "device", XenPCI_XenBusWatchHandler, Device);
507 KdPrint((__DRIVER_NAME " device watch response = '%s'\n", response));
509 msgTypes = XenBus_List(Device, XBT_NIL, "device", &Types);
510 if (!msgTypes) {
511 for (i = 0; Types[i]; i++)
512 {
513 RtlStringCbPrintfA(buffer, ARRAY_SIZE(buffer), "device/%s", Types[i]);
514 //KdPrint((__DRIVER_NAME " ls device[%d] -> %s\n", i, Types[i]));
515 XenPCI_XenBusWatchHandler(buffer, Device);
516 ExFreePoolWithTag(Types[i], XENPCI_POOL_TAG);
517 }
518 }
519 KdPrint((__DRIVER_NAME " <-- EvtDeviceD0EntryPostInterruptsEnabled\n"));
521 return status;
522 }
524 static NTSTATUS
525 XenPCI_D0ExitPreInterruptsDisabled(WDFDEVICE Device, WDF_POWER_DEVICE_STATE TargetState)
526 {
527 NTSTATUS status = STATUS_SUCCESS;
529 UNREFERENCED_PARAMETER(TargetState);
531 XenBus_Stop(Device);
533 return status;
534 }
536 static NTSTATUS
537 XenPCI_D0Exit(WDFDEVICE Device, WDF_POWER_DEVICE_STATE TargetState)
538 {
539 NTSTATUS status = STATUS_SUCCESS;
541 UNREFERENCED_PARAMETER(Device);
542 UNREFERENCED_PARAMETER(TargetState);
544 KdPrint((__DRIVER_NAME " --> EvtDeviceD0Exit\n"));
546 KdPrint((__DRIVER_NAME " <-- EvtDeviceD0Exit\n"));
548 return status;
549 }
551 static VOID
552 XenPCI_IoDefault(
553 IN WDFQUEUE Queue,
554 IN WDFREQUEST Request
555 )
556 {
557 UNREFERENCED_PARAMETER(Queue);
559 KdPrint((__DRIVER_NAME " --> EvtDeviceIoDefault\n"));
561 WdfRequestComplete(Request, STATUS_NOT_IMPLEMENTED);
563 KdPrint((__DRIVER_NAME " <-- EvtDeviceIoDefault\n"));
564 }
566 static NTSTATUS
567 XenPCI_InterruptEnable(WDFINTERRUPT Interrupt, WDFDEVICE AssociatedDevice)
568 {
569 PXENPCI_DEVICE_DATA xpdd = GetDeviceData(AssociatedDevice);
570 UNREFERENCED_PARAMETER(Interrupt);
572 KdPrint((__DRIVER_NAME " --> EvtInterruptEnable\n"));
574 xpdd->shared_info_area->vcpu_info[0].evtchn_upcall_mask = 0;
576 KdPrint((__DRIVER_NAME " <-- EvtInterruptEnable\n"));
578 return STATUS_SUCCESS;
579 }
581 static NTSTATUS
582 XenPCI_InterruptDisable(WDFINTERRUPT Interrupt, WDFDEVICE AssociatedDevice)
583 {
584 PXENPCI_DEVICE_DATA xpdd = GetDeviceData(AssociatedDevice);
585 UNREFERENCED_PARAMETER(Interrupt);
587 //KdPrint((__DRIVER_NAME " --> EvtInterruptDisable\n"));
589 xpdd->shared_info_area->vcpu_info[0].evtchn_upcall_mask = 1;
590 // should we kick off any pending interrupts here?
592 //KdPrint((__DRIVER_NAME " <-- EvtInterruptDisable\n"));
594 return STATUS_SUCCESS;
595 }
597 static NTSTATUS
598 XenPCI_ChildListCreateDevice(
599 WDFCHILDLIST ChildList,
600 PWDF_CHILD_IDENTIFICATION_DESCRIPTION_HEADER IdentificationDescription,
601 PWDFDEVICE_INIT ChildInit)
602 {
603 NTSTATUS status;
604 WDFDEVICE ChildDevice = NULL;
605 PXENPCI_IDENTIFICATION_DESCRIPTION XenIdentificationDesc;
606 XEN_IFACE_EVTCHN EvtChnInterface;
607 XEN_IFACE_XENBUS XenBusInterface;
608 //XEN_IFACE_XEN XenInterface;
609 XEN_IFACE_GNTTBL GntTblInterface;
610 DECLARE_UNICODE_STRING_SIZE(buffer, 20);
611 WDF_OBJECT_ATTRIBUTES PdoAttributes;
612 DECLARE_CONST_UNICODE_STRING(DeviceLocation, L"Xen Bus");
613 WDF_QUERY_INTERFACE_CONFIG qiConfig;
614 PXENPCI_XEN_DEVICE_DATA ChildDeviceData = NULL;
616 UNREFERENCED_PARAMETER(ChildList);
618 //KdPrint((__DRIVER_NAME " --> ChildListCreateDevice\n"));
620 XenIdentificationDesc = CONTAINING_RECORD(IdentificationDescription, XENPCI_IDENTIFICATION_DESCRIPTION, Header);
622 //KdPrint((__DRIVER_NAME " Type = %wZ\n", &XenIdentificationDesc->DeviceType));
624 //DeviceInit = WdfPdoInitAllocate(Device);
625 WdfDeviceInitSetDeviceType(ChildInit, FILE_DEVICE_CONTROLLER);
627 status = RtlUnicodeStringPrintf(&buffer, L"Xen\\%wZ\0", &XenIdentificationDesc->DeviceType);
628 status = WdfPdoInitAssignDeviceID(ChildInit, &buffer);
629 status = WdfPdoInitAddHardwareID(ChildInit, &buffer);
630 status = WdfPdoInitAddCompatibleID(ChildInit, &buffer);
632 status = RtlUnicodeStringPrintf(&buffer, L"%02d", 0);
633 status = WdfPdoInitAssignInstanceID(ChildInit, &buffer);
635 status = RtlUnicodeStringPrintf( &buffer, L"%wZ", &XenIdentificationDesc->DeviceType);
636 status = WdfPdoInitAddDeviceText(ChildInit, &buffer, &DeviceLocation, 0x409);
638 WdfPdoInitSetDefaultLocale(ChildInit, 0x409);
640 WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&PdoAttributes, XENPCI_XEN_DEVICE_DATA);
642 // WDF_PDO_EVENT_CALLBACKS_INIT(&PdoCallbacks);
643 // PdoCallbacks.EvtDeviceResourceRequirementsQuery = XenPCI_DeviceResourceRequirementsQuery;
644 // WdfPdoInitSetEventCallbacks(ChildInit, &PdoCallbacks);
646 status = WdfDeviceCreate(&ChildInit, &PdoAttributes, &ChildDevice);
647 if (!NT_SUCCESS(status))
648 {
649 KdPrint((__DRIVER_NAME " WdfDeviceCreate status = %08X\n", status));
650 }
652 WdfDeviceSetSpecialFileSupport(ChildDevice, WdfSpecialFilePaging, TRUE);
653 WdfDeviceSetSpecialFileSupport(ChildDevice, WdfSpecialFileHibernation, TRUE);
654 WdfDeviceSetSpecialFileSupport(ChildDevice, WdfSpecialFileDump, TRUE);
656 ChildDeviceData = GetXenDeviceData(ChildDevice);
657 strncpy(ChildDeviceData->BasePath, XenIdentificationDesc->Path, 128);
659 RtlZeroMemory(&EvtChnInterface, sizeof(EvtChnInterface));
660 EvtChnInterface.InterfaceHeader.Size = sizeof(EvtChnInterface);
661 EvtChnInterface.InterfaceHeader.Version = 1;
662 EvtChnInterface.InterfaceHeader.Context = WdfPdoGetParent(ChildDevice);
663 EvtChnInterface.InterfaceHeader.InterfaceReference = WdfDeviceInterfaceReferenceNoOp;
664 EvtChnInterface.InterfaceHeader.InterfaceDereference = WdfDeviceInterfaceDereferenceNoOp;
665 EvtChnInterface.Bind = EvtChn_Bind;
666 EvtChnInterface.Unbind = EvtChn_Unbind;
667 EvtChnInterface.Mask = EvtChn_Mask;
668 EvtChnInterface.Unmask = EvtChn_Unmask;
669 EvtChnInterface.Notify = EvtChn_Notify;
670 EvtChnInterface.AllocUnbound = EvtChn_AllocUnbound;
671 WDF_QUERY_INTERFACE_CONFIG_INIT(&qiConfig, (PINTERFACE)&EvtChnInterface, &GUID_XEN_IFACE_EVTCHN, NULL);
672 status = WdfDeviceAddQueryInterface(ChildDevice, &qiConfig);
673 if (!NT_SUCCESS(status))
674 {
675 return status;
676 }
678 /* nobody uses this yet, maybe it isn't needed? */
679 #if 0
680 RtlZeroMemory(&XenInterface, sizeof(XenInterface));
681 XenInterface.InterfaceHeader.Size = sizeof(XenInterface);
682 XenInterface.InterfaceHeader.Version = 1;
683 XenInterface.InterfaceHeader.Context = WdfPdoGetParent(ChildDevice);
684 XenInterface.InterfaceHeader.InterfaceReference = WdfDeviceInterfaceReferenceNoOp;
685 XenInterface.InterfaceHeader.InterfaceDereference = WdfDeviceInterfaceDereferenceNoOp;
686 XenInterface.AllocMMIO = XenPCI_AllocMMIO;
687 WDF_QUERY_INTERFACE_CONFIG_INIT(&qiConfig, (PINTERFACE)&XenInterface, &GUID_XEN_IFACE_XEN, NULL);
688 status = WdfDeviceAddQueryInterface(ChildDevice, &qiConfig);
689 if (!NT_SUCCESS(status)) {
690 return status;
691 }
692 #endif
694 RtlZeroMemory(&GntTblInterface, sizeof(GntTblInterface));
695 GntTblInterface.InterfaceHeader.Size = sizeof(GntTblInterface);
696 GntTblInterface.InterfaceHeader.Version = 1;
697 GntTblInterface.InterfaceHeader.Context = WdfPdoGetParent(ChildDevice);
698 GntTblInterface.InterfaceHeader.InterfaceReference = WdfDeviceInterfaceReferenceNoOp;
699 GntTblInterface.InterfaceHeader.InterfaceDereference = WdfDeviceInterfaceDereferenceNoOp;
700 GntTblInterface.GrantAccess = GntTbl_GrantAccess;
701 GntTblInterface.EndAccess = GntTbl_EndAccess;
702 WDF_QUERY_INTERFACE_CONFIG_INIT(&qiConfig, (PINTERFACE)&GntTblInterface, &GUID_XEN_IFACE_GNTTBL, NULL);
703 status = WdfDeviceAddQueryInterface(ChildDevice, &qiConfig);
704 if (!NT_SUCCESS(status)) {
705 return status;
706 }
708 RtlZeroMemory(&XenBusInterface, sizeof(XenBusInterface));
710 XenBusInterface.InterfaceHeader.Size = sizeof(XenBusInterface);
711 XenBusInterface.InterfaceHeader.Version = 1;
712 XenBusInterface.InterfaceHeader.Context = WdfPdoGetParent(ChildDevice);
713 //XenBusInterface.InterfaceHeader.Context = ExAllocatePoolWithTag(NonPagedPool, (strlen(XenIdentificationDesc->Path) + 1), XENPCI_POOL_TAG);
714 //strcpy(XenBusInterface.InterfaceHeader.Context, XenIdentificationDesc->Path);
715 XenBusInterface.Read = XenBus_Read;
716 XenBusInterface.Write = XenBus_Write;
717 XenBusInterface.Printf = XenBus_Printf;
718 XenBusInterface.StartTransaction = XenBus_StartTransaction;
719 XenBusInterface.EndTransaction = XenBus_EndTransaction;
720 XenBusInterface.List = XenBus_List;
721 XenBusInterface.AddWatch = XenBus_AddWatch;
722 XenBusInterface.RemWatch = XenBus_RemWatch;
723 WDF_QUERY_INTERFACE_CONFIG_INIT(&qiConfig, (PINTERFACE)&XenBusInterface, &GUID_XEN_IFACE_XENBUS, NULL);
724 status = WdfDeviceAddQueryInterface(ChildDevice, &qiConfig);
725 if (!NT_SUCCESS(status)) {
726 return status;
727 }
729 //KdPrint((__DRIVER_NAME " <-- ChildListCreateDevice\n"));
731 return status;
732 }
734 VOID
735 XenPCI_XenBusWatchHandler(char *Path, PVOID Data)
736 {
737 XENPCI_IDENTIFICATION_DESCRIPTION description;
738 NTSTATUS status;
739 char **Bits;
740 int Count;
741 WDFDEVICE Device = Data;
742 WDFCHILDLIST ChildList;
743 WDF_CHILD_LIST_ITERATOR ChildIterator;
744 WDFDEVICE ChildDevice;
745 PXENPCI_XEN_DEVICE_DATA ChildDeviceData;
747 ANSI_STRING AnsiBuf;
749 UNREFERENCED_PARAMETER(Data);
751 KdPrint((__DRIVER_NAME " --> XenBusWatchHandle\n"));
753 //KdPrint((__DRIVER_NAME " %s\n", Path));
755 ChildList = WdfFdoGetDefaultChildList(Device);
757 Bits = SplitString(Path, '/', 3, &Count);
758 switch (Count)
759 {
760 case 0:
761 case 1:
762 break;
763 case 2:
764 // add or update the device node
765 WDF_CHILD_IDENTIFICATION_DESCRIPTION_HEADER_INIT(&description.Header, sizeof(description));
766 strncpy(description.Path, Path, 128);
767 RtlInitAnsiString(&AnsiBuf, Bits[1]);
768 //KdPrint((__DRIVER_NAME " Name = %s\n", Bits[1]));
769 RtlAnsiStringToUnicodeString(&description.DeviceType, &AnsiBuf, TRUE);
770 status = WdfChildListAddOrUpdateChildDescriptionAsPresent(ChildList, &description.Header, NULL);
771 break;
772 case 3:
773 WDF_CHILD_LIST_ITERATOR_INIT(&ChildIterator, WdfRetrievePresentChildren);
774 WdfChildListBeginIteration(ChildList, &ChildIterator);
775 while (NT_SUCCESS(WdfChildListRetrieveNextDevice(ChildList, &ChildIterator, &ChildDevice, NULL)))
776 {
777 ChildDeviceData = GetXenDeviceData(ChildDevice);
778 if (!ChildDeviceData)
779 {
780 KdPrint((__FUNCTION__ " No child device data, should never happen\n"));
781 continue;
782 }
783 if (strncmp(ChildDeviceData->BasePath, Path, strlen(ChildDeviceData->BasePath)) == 0 && Path[strlen(ChildDeviceData->BasePath)] == '/')
784 {
785 //KdPrint((__DRIVER_NAME " Child Path = %s (Match - WatchHandler = %08x)\n", ChildDeviceData->BasePath, ChildDeviceData->WatchHandler));
786 if (ChildDeviceData->WatchHandler != NULL)
787 ChildDeviceData->WatchHandler(Path, NULL);
788 }
789 else
790 {
791 //KdPrint((__DRIVER_NAME " Child Path = %s (No Match)\n", ChildDeviceData->BasePath));
792 }
793 }
794 WdfChildListEndIteration(ChildList, &ChildIterator);
795 break;
796 default:
797 KdPrint((__FUNCTION__ ": Unknown case %d\n", Count));
798 break;
799 }
801 FreeSplitString(Bits, Count);
803 KdPrint((__DRIVER_NAME " <-- XenBusWatchHandle\n"));
804 }
806 static void
807 XenBus_ShutdownHandler(char *Path, PVOID Data)
808 {
809 WDFDEVICE Device = Data;
810 char *value;
811 xenbus_transaction_t xbt;
812 int retry;
814 UNREFERENCED_PARAMETER(Path);
816 KdPrint((__DRIVER_NAME " --> XenBus_ShutdownHandler\n"));
818 XenBus_StartTransaction(Device, &xbt);
820 XenBus_Read(Device, XBT_NIL, SHUTDOWN_PATH, &value);
822 KdPrint((__DRIVER_NAME " Shutdown Value = %s\n", value));
824 // should check for error here... but why have we been called at all???
825 if (value != NULL && strlen(value) != 0)
826 XenBus_Write(Device, XBT_NIL, SHUTDOWN_PATH, "");
828 XenBus_EndTransaction(Device, xbt, 0, &retry);
830 KdPrint((__DRIVER_NAME " <-- XenBus_ShutdownHandler\n"));
831 }
833 static VOID
834 XenBus_BalloonHandler(char *Path, PVOID Data)
835 {
836 WDFDEVICE Device = Data;
837 char *value;
838 xenbus_transaction_t xbt;
839 int retry;
841 UNREFERENCED_PARAMETER(Path);
843 KdPrint((__DRIVER_NAME " --> XenBus_BalloonHandler\n"));
845 XenBus_StartTransaction(Device, &xbt);
847 XenBus_Read(Device, XBT_NIL, BALLOON_PATH, &value);
849 KdPrint((__DRIVER_NAME " Balloon Value = %s\n", value));
851 // use the memory_op(unsigned int op, void *arg) hypercall to adjust this
852 // use XENMEM_increase_reservation and XENMEM_decrease_reservation
854 XenBus_EndTransaction(Device, xbt, 0, &retry);
856 KdPrint((__DRIVER_NAME " <-- XenBus_BalloonHandler\n"));
857 }
859 /*
860 IO_RESOURCE_DESCRIPTOR MemoryDescriptor;
862 static NTSTATUS
863 XenPCI_FilterRemoveResourceRequirements(WDFDEVICE Device, WDFIORESREQLIST RequirementsList)
864 {
865 NTSTATUS status;
866 WDFIORESLIST ResourceList;
867 PIO_RESOURCE_DESCRIPTOR Descriptor;
869 int i, j;
870 int offset;
872 //KdPrint((__DRIVER_NAME " --> FilterRemoveResourceRequirements\n"));
874 for (i = 0; i < WdfIoResourceRequirementsListGetCount(RequirementsList); i++)
875 {
876 ResourceList = WdfIoResourceRequirementsListGetIoResList(RequirementsList, i);
877 //KdPrint((__DRIVER_NAME " Resource List %d\n", i));
878 //KdPrint((__DRIVER_NAME " %d resources in list\n", WdfIoResourceListGetCount(ResourceList)));
879 offset = 0;
880 for (j = 0; j < WdfIoResourceListGetCount(ResourceList); j++)
881 {
882 //KdPrint((__DRIVER_NAME " Resource %d\n", j));
883 Descriptor = WdfIoResourceListGetDescriptor(ResourceList, j - offset);
885 switch (Descriptor->Type) {
886 case CmResourceTypePort:
887 //KdPrint((__DRIVER_NAME " Port\n"));
888 break;
889 case CmResourceTypeMemory:
890 //KdPrint((__DRIVER_NAME " Memory %08X%08X - %08X%08X\n", Descriptor->u.Memory.MinimumAddress.HighPart, Descriptor->u.Memory.MinimumAddress.LowPart, Descriptor->u.Memory.MaximumAddress.HighPart, Descriptor->u.Memory.MaximumAddress.LowPart));
891 //KdPrint((__DRIVER_NAME " Length %08X\n", Descriptor->u.Memory.Length));
892 //KdPrint((__DRIVER_NAME " ShareDisposition %02X\n", Descriptor->ShareDisposition));
893 //KdPrint((__DRIVER_NAME " Option %02X\n", Descriptor->Option));
894 if (!Descriptor->Option || Descriptor->Option == IO_RESOURCE_PREFERRED) {
895 memcpy(&MemoryDescriptor, Descriptor, sizeof(IO_RESOURCE_DESCRIPTOR));
896 //platform_mmio_orig_len = MemoryDescriptor.u.Memory.Length;
897 //MemoryDescriptor.u.Memory.Length = PAGE_SIZE;
898 MemoryDescriptor.ShareDisposition = CmResourceShareShared;
899 }
900 WdfIoResourceListRemove(ResourceList, j - offset);
901 offset++;
902 break;
903 case CmResourceTypeInterrupt:
904 //KdPrint((__DRIVER_NAME " Interrupt\n"));
905 break;
906 case CmResourceTypeDevicePrivate:
907 //KdPrint((__DRIVER_NAME " Private\n"));
908 break;
909 default:
910 //KdPrint((__DRIVER_NAME " Unknown Type (0x%x)\n", Descriptor->Type));
911 break;
912 }
913 }
914 }
915 status = STATUS_SUCCESS;
917 KdPrint((__DRIVER_NAME " <-- FilterRemoveResourceRequirements\n"));
919 return status;
920 }
923 static NTSTATUS
924 XenPCI_FilterAddResourceRequirements(WDFDEVICE Device, WDFIORESREQLIST RequirementsList)
925 {
926 NTSTATUS status;
927 WDFIORESLIST ResourceList;
928 PIO_RESOURCE_DESCRIPTOR Descriptor;
930 int i, j;
932 KdPrint((__DRIVER_NAME " --> FilterAddResourceRequirements\n"));
935 for (i = 0; i < WdfIoResourceRequirementsListGetCount(RequirementsList); i++)
936 {
937 ResourceList = WdfIoResourceRequirementsListGetIoResList(RequirementsList, i);
938 //KdPrint((__DRIVER_NAME " Resource List %d\n", i));
939 //KdPrint((__DRIVER_NAME " %d resources in list\n", WdfIoResourceListGetCount(ResourceList)));
940 WdfIoResourceListAppendDescriptor(ResourceList, &MemoryDescriptor);
941 //KdPrint((__DRIVER_NAME " Memory %08X%08X - %08X%08X\n", MemoryDescriptor.u.Memory.MinimumAddress.HighPart, MemoryDescriptor.u.Memory.MinimumAddress.LowPart, MemoryDescriptor.u.Memory.MaximumAddress.HighPart, MemoryDescriptor.u.Memory.MaximumAddress.LowPart));
942 //KdPrint((__DRIVER_NAME " Length %08X\n", MemoryDescriptor.u.Memory.Length));
943 for (j = 0; j < WdfIoResourceListGetCount(ResourceList); j++)
944 {
945 //KdPrint((__DRIVER_NAME " Resource %d\n", j));
946 Descriptor = WdfIoResourceListGetDescriptor(ResourceList, j);
948 switch (Descriptor->Type) {
949 case CmResourceTypePort:
950 //KdPrint((__DRIVER_NAME " Port\n"));
951 break;
952 case CmResourceTypeMemory:
953 //KdPrint((__DRIVER_NAME " Memory %08X%08X - %08X%08X\n", Descriptor->u.Memory.MinimumAddress.HighPart, Descriptor->u.Memory.MinimumAddress.LowPart, Descriptor->u.Memory.MaximumAddress.HighPart, Descriptor->u.Memory.MaximumAddress.LowPart));
954 //KdPrint((__DRIVER_NAME " Length %08X\n", Descriptor->u.Memory.Length));
955 //KdPrint((__DRIVER_NAME " ShareDisposition %02X\n", Descriptor->ShareDisposition));
956 //Descriptor->ShareDisposition = CmResourceShareShared;
957 //memcpy(&MemoryDescriptor, Descriptor, sizeof(IO_RESOURCE_DESCRIPTOR));
958 //platform_mmio_orig_len = MemoryDescriptor.u.Memory.Length;
959 //MemoryDescriptor.u.Memory.Length = PAGE_SIZE;
960 //WdfIoResourceListRemove(ResourceList, j);
961 break;
962 case CmResourceTypeInterrupt:
963 //KdPrint((__DRIVER_NAME " Interrupt\n"));
964 break;
965 case CmResourceTypeDevicePrivate:
966 //KdPrint((__DRIVER_NAME " Private\n"));
967 break;
968 default:
969 //KdPrint((__DRIVER_NAME " Unknown Type (0x%x)\n", Descriptor->Type));
970 break;
971 }
972 }
973 }
974 status = STATUS_SUCCESS;
976 //KdPrint((__DRIVER_NAME " <-- FilterAddResourceRequirements\n"));
978 return status;
979 }
981 static NTSTATUS
982 XenPCI_RemoveAddedResources(WDFDEVICE Device, WDFCMRESLIST ResourcesRaw, WDFCMRESLIST ResourcesTranslated)
983 {
984 //KdPrint((__DRIVER_NAME " --> RemoveAddedResources\n"));
985 //KdPrint((__DRIVER_NAME " <-- RemoveAddedResources\n"));
987 return STATUS_SUCCESS;
988 }
990 */
992 static NTSTATUS
993 XenPCI_DeviceResourceRequirementsQuery(WDFDEVICE Device, WDFIORESREQLIST IoResourceRequirementsList)
994 {
995 NTSTATUS status;
996 WDFIORESLIST resourceList;
997 IO_RESOURCE_DESCRIPTOR descriptor;
998 PXENPCI_DEVICE_DATA xpdd = GetDeviceData(Device);
1000 //KdPrint((__DRIVER_NAME " --> DeviceResourceRequirementsQuery\n"));
1002 status = WdfIoResourceListCreate(IoResourceRequirementsList, WDF_NO_OBJECT_ATTRIBUTES, &resourceList);
1003 if (!NT_SUCCESS(status))
1004 return status;
1006 /*
1007 RtlZeroMemory(&descriptor, sizeof(descriptor));
1009 descriptor.Option = 0;
1010 descriptor.Type = CmResourceTypeInterrupt;
1011 descriptor.ShareDisposition = CmResourceShareDeviceExclusive;
1012 descriptor.Flags = CM_RESOURCE_MEMORY_READ_WRITE;
1013 descriptor.u.Interrupt.MinimumVector = 1024;
1014 descriptor.u.Interrupt.MaximumVector = 1024+255;
1016 //KdPrint((__DRIVER_NAME " MinimumVector = %d, MaximumVector = %d\n", descriptor.u.Interrupt.MinimumVector, descriptor.u.Interrupt.MaximumVector));
1018 status = WdfIoResourceListAppendDescriptor(resourceList, &descriptor);
1019 if (!NT_SUCCESS(status))
1020 return status;
1021 */
1023 RtlZeroMemory(&descriptor, sizeof(descriptor));
1025 descriptor.Option = 0;
1026 descriptor.Type = CmResourceTypeMemory;
1027 descriptor.ShareDisposition = CmResourceShareShared; //CmResourceShareDeviceExclusive;
1028 descriptor.Flags = CM_RESOURCE_MEMORY_READ_WRITE;
1029 descriptor.u.Memory.Length = PAGE_SIZE;
1030 descriptor.u.Memory.Alignment = PAGE_SIZE;
1031 descriptor.u.Memory.MinimumAddress.QuadPart
1032 = xpdd->platform_mmio_addr.QuadPart + PAGE_SIZE;
1033 descriptor.u.Memory.MaximumAddress.QuadPart
1034 = xpdd->platform_mmio_addr.QuadPart + xpdd->platform_mmio_len - 1;
1036 //KdPrint((__DRIVER_NAME " MinimumAddress = %08x, MaximumAddress = %08X\n", descriptor.u.Memory.MinimumAddress.LowPart, descriptor.u.Memory.MaximumAddress.LowPart));
1038 status = WdfIoResourceListAppendDescriptor(resourceList, &descriptor);
1039 if (!NT_SUCCESS(status))
1040 return status;
1042 status = WdfIoResourceRequirementsListAppendIoResList(IoResourceRequirementsList, resourceList);
1043 if (!NT_SUCCESS(status))
1044 return status;
1046 //KdPrint((__DRIVER_NAME " <-- DeviceResourceRequirementsQuery\n"));
1048 return status;