win-pvdrivers

view xenpci/xenpci.c @ 15:7f0f866dced6

wean xenbus.c off of global variables

rename some variables from deviceData to xpdd for brevity
some whitespace fixes
author Andy Grover <andy@groveronline.com>
date Wed Nov 28 16:49:26 2007 -0800 (2007-11-28)
parents be8c09632f31
children 53fdfc9f5d56
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 deviceData = 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 deviceData->hypercall_stubs = ExAllocatePoolWithTag(NonPagedPool, pages * PAGE_SIZE, XENPCI_POOL_TAG);
211 //KdPrint((__DRIVER_NAME " Hypercall area at %08x\n", hypercall_stubs));
213 if (!deviceData->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(deviceData->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 deviceData = GetDeviceData(Device);
230 PHYSICAL_ADDRESS addr;
232 addr = deviceData->platform_mmio_addr;
233 addr.QuadPart += deviceData->platform_mmio_alloc;
234 deviceData->platform_mmio_alloc += len;
236 return addr;
237 }
239 static int
240 init_xen_info(WDFDEVICE Device)
241 {
242 PXENPCI_DEVICE_DATA deviceData = 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 deviceData->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 deviceData;
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 deviceData = GetDeviceData(Device);
338 deviceData->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, &deviceData->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 deviceData;
381 KdPrint((__DRIVER_NAME " --> EvtDevicePrepareHardware\n"));
383 deviceData = GetDeviceData(Device);
385 for (i = 0; i < WdfCmResourceListGetCount(ResourceList); i++)
386 {
387 descriptor = WdfCmResourceListGetDescriptor(ResourceList, i);
388 if(!descriptor)
389 continue;
390 switch (descriptor->Type)
391 {
392 case CmResourceTypeInterrupt:
393 deviceData->irqNumber = descriptor->u.Interrupt.Vector;
394 break;
395 }
396 }
398 //KdPrint((__DRIVER_NAME " GSI = %d\n", irqNumber));
400 //KdPrint((__DRIVER_NAME " ResourceListTranslated\n"));
401 for (i = 0; i < WdfCmResourceListGetCount(ResourceListTranslated); i++)
402 {
403 descriptor = WdfCmResourceListGetDescriptor(ResourceListTranslated, i);
404 if(!descriptor)
405 {
406 KdPrint((__DRIVER_NAME " --> EvtDevicePrepareHardware (No descriptor)\n"));
407 return STATUS_DEVICE_CONFIGURATION_ERROR;
408 }
409 switch (descriptor->Type) {
410 case CmResourceTypePort:
411 //KdPrint((__DRIVER_NAME " I/O mapped CSR: (%x) Length: (%d)\n", descriptor->u.Port.Start.LowPart, descriptor->u.Port.Length));
412 // deviceData->IoBaseAddress = ULongToPtr(descriptor->u.Port.Start.LowPart);
413 // deviceData->IoRange = descriptor->u.Port.Length;
414 break;
415 case CmResourceTypeMemory:
416 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));
417 deviceData->platform_mmio_addr = descriptor->u.Memory.Start; //(ULONG)MmMapIoSpace(descriptor->u.Memory.Start, descriptor->u.Memory.Length, MmNonCached);
418 deviceData->platform_mmio_len = descriptor->u.Memory.Length;
419 deviceData->platform_mmio_alloc = 0;
420 break;
421 case CmResourceTypeInterrupt:
422 //KdPrint((__DRIVER_NAME " Interrupt level: 0x%0x, Vector: 0x%0x\n", descriptor->u.Interrupt.Level, descriptor->u.Interrupt.Vector));
423 break;
424 case CmResourceTypeDevicePrivate:
425 //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] ));
426 break;
427 default:
428 //KdPrint((__DRIVER_NAME " Unhandled resource type (0x%x)\n", descriptor->Type));
429 break;
430 }
431 }
433 get_hypercall_stubs(Device);
435 init_xen_info(Device);
437 GntTbl_Init(Device);
439 EvtChn_Init(Device);
441 set_callback_irq(Device, deviceData->irqNumber);
443 XenBus_Init(Device);
445 //KdPrint((__DRIVER_NAME " upcall_pending = %d\n", shared_info_area->vcpu_info[0].evtchn_upcall_pending));
447 deviceData->shared_info_area->vcpu_info[0].evtchn_upcall_mask = 0;
449 //xen_reboot_init();
451 KdPrint((__DRIVER_NAME " <-- EvtDevicePrepareHardware\n"));
453 return status;
454 }
456 static NTSTATUS
457 XenPCI_ReleaseHardware(WDFDEVICE Device, WDFCMRESLIST ResourcesTranslated)
458 {
459 UNREFERENCED_PARAMETER(Device);
460 UNREFERENCED_PARAMETER(ResourcesTranslated);
462 return STATUS_SUCCESS;
463 }
465 static NTSTATUS
466 XenPCI_D0Entry(
467 IN WDFDEVICE Device,
468 IN WDF_POWER_DEVICE_STATE PreviousState
469 )
470 {
471 NTSTATUS status = STATUS_SUCCESS;
473 UNREFERENCED_PARAMETER(Device);
474 UNREFERENCED_PARAMETER(PreviousState);
476 KdPrint((__DRIVER_NAME " --> EvtDeviceD0Entry\n"));
478 KdPrint((__DRIVER_NAME " <-- EvtDeviceD0Entry\n"));
480 return status;
481 }
483 static NTSTATUS
484 XenPCI_D0EntryPostInterruptsEnabled(WDFDEVICE Device, WDF_POWER_DEVICE_STATE PreviousState)
485 {
486 NTSTATUS status = STATUS_SUCCESS;
487 //OBJECT_ATTRIBUTES oa;
488 char *response;
489 char *msgTypes;
490 char **Types;
491 int i;
492 char buffer[128];
494 UNREFERENCED_PARAMETER(PreviousState);
496 KdPrint((__DRIVER_NAME " --> EvtDeviceD0EntryPostInterruptsEnabled\n"));
498 XenBus_Start(Device);
500 KdPrint((__DRIVER_NAME " A\n"));
502 response = XenBus_AddWatch(Device, XBT_NIL, SHUTDOWN_PATH, XenBus_ShutdownHandler, Device);
503 KdPrint((__DRIVER_NAME " shutdown watch response = '%s'\n", response));
505 response = XenBus_AddWatch(Device, XBT_NIL, BALLOON_PATH, XenBus_BalloonHandler, Device);
506 KdPrint((__DRIVER_NAME " shutdown watch response = '%s'\n", response));
508 response = XenBus_AddWatch(Device, XBT_NIL, "device", XenPCI_XenBusWatchHandler, Device);
509 KdPrint((__DRIVER_NAME " device watch response = '%s'\n", response));
511 msgTypes = XenBus_List(Device, XBT_NIL, "device", &Types);
512 if (!msgTypes) {
513 for (i = 0; Types[i]; i++)
514 {
515 RtlStringCbPrintfA(buffer, ARRAY_SIZE(buffer), "device/%s", Types[i]);
516 //KdPrint((__DRIVER_NAME " ls device[%d] -> %s\n", i, Types[i]));
517 XenPCI_XenBusWatchHandler(buffer, Device);
518 ExFreePoolWithTag(Types[i], XENPCI_POOL_TAG);
519 }
520 }
521 KdPrint((__DRIVER_NAME " <-- EvtDeviceD0EntryPostInterruptsEnabled\n"));
523 return status;
524 }
526 static NTSTATUS
527 XenPCI_D0ExitPreInterruptsDisabled(WDFDEVICE Device, WDF_POWER_DEVICE_STATE TargetState)
528 {
529 NTSTATUS status = STATUS_SUCCESS;
531 UNREFERENCED_PARAMETER(TargetState);
533 XenBus_Stop(Device);
535 return status;
536 }
538 static NTSTATUS
539 XenPCI_D0Exit(WDFDEVICE Device, WDF_POWER_DEVICE_STATE TargetState)
540 {
541 NTSTATUS status = STATUS_SUCCESS;
543 UNREFERENCED_PARAMETER(Device);
544 UNREFERENCED_PARAMETER(TargetState);
546 KdPrint((__DRIVER_NAME " --> EvtDeviceD0Exit\n"));
548 KdPrint((__DRIVER_NAME " <-- EvtDeviceD0Exit\n"));
550 return status;
551 }
553 static VOID
554 XenPCI_IoDefault(
555 IN WDFQUEUE Queue,
556 IN WDFREQUEST Request
557 )
558 {
559 UNREFERENCED_PARAMETER(Queue);
561 KdPrint((__DRIVER_NAME " --> EvtDeviceIoDefault\n"));
563 WdfRequestComplete(Request, STATUS_NOT_IMPLEMENTED);
565 KdPrint((__DRIVER_NAME " <-- EvtDeviceIoDefault\n"));
566 }
568 static NTSTATUS
569 XenPCI_InterruptEnable(WDFINTERRUPT Interrupt, WDFDEVICE AssociatedDevice)
570 {
571 PXENPCI_DEVICE_DATA deviceData = GetDeviceData(AssociatedDevice);
572 UNREFERENCED_PARAMETER(Interrupt);
574 KdPrint((__DRIVER_NAME " --> EvtInterruptEnable\n"));
576 deviceData->shared_info_area->vcpu_info[0].evtchn_upcall_mask = 0;
578 KdPrint((__DRIVER_NAME " <-- EvtInterruptEnable\n"));
580 return STATUS_SUCCESS;
581 }
583 static NTSTATUS
584 XenPCI_InterruptDisable(WDFINTERRUPT Interrupt, WDFDEVICE AssociatedDevice)
585 {
586 PXENPCI_DEVICE_DATA deviceData = GetDeviceData(AssociatedDevice);
587 UNREFERENCED_PARAMETER(Interrupt);
589 //KdPrint((__DRIVER_NAME " --> EvtInterruptDisable\n"));
591 deviceData->shared_info_area->vcpu_info[0].evtchn_upcall_mask = 1;
592 // should we kick off any pending interrupts here?
594 //KdPrint((__DRIVER_NAME " <-- EvtInterruptDisable\n"));
596 return STATUS_SUCCESS;
597 }
599 static NTSTATUS
600 XenPCI_ChildListCreateDevice(
601 WDFCHILDLIST ChildList,
602 PWDF_CHILD_IDENTIFICATION_DESCRIPTION_HEADER IdentificationDescription,
603 PWDFDEVICE_INIT ChildInit)
604 {
605 NTSTATUS status;
606 WDFDEVICE ChildDevice = NULL;
607 PXENPCI_IDENTIFICATION_DESCRIPTION XenIdentificationDesc;
608 XEN_IFACE_EVTCHN EvtChnInterface;
609 XEN_IFACE_XENBUS XenBusInterface;
610 //XEN_IFACE_XEN XenInterface;
611 XEN_IFACE_GNTTBL GntTblInterface;
612 DECLARE_UNICODE_STRING_SIZE(buffer, 20);
613 WDF_OBJECT_ATTRIBUTES PdoAttributes;
614 DECLARE_CONST_UNICODE_STRING(DeviceLocation, L"Xen Bus");
615 WDF_QUERY_INTERFACE_CONFIG qiConfig;
616 PXENPCI_XEN_DEVICE_DATA ChildDeviceData = NULL;
618 UNREFERENCED_PARAMETER(ChildList);
620 //KdPrint((__DRIVER_NAME " --> ChildListCreateDevice\n"));
622 XenIdentificationDesc = CONTAINING_RECORD(IdentificationDescription, XENPCI_IDENTIFICATION_DESCRIPTION, Header);
624 //KdPrint((__DRIVER_NAME " Type = %wZ\n", &XenIdentificationDesc->DeviceType));
626 //DeviceInit = WdfPdoInitAllocate(Device);
627 WdfDeviceInitSetDeviceType(ChildInit, FILE_DEVICE_CONTROLLER);
629 status = RtlUnicodeStringPrintf(&buffer, L"Xen\\%wZ\0", &XenIdentificationDesc->DeviceType);
630 status = WdfPdoInitAssignDeviceID(ChildInit, &buffer);
631 status = WdfPdoInitAddHardwareID(ChildInit, &buffer);
632 status = WdfPdoInitAddCompatibleID(ChildInit, &buffer);
634 status = RtlUnicodeStringPrintf(&buffer, L"%02d", 0);
635 status = WdfPdoInitAssignInstanceID(ChildInit, &buffer);
637 status = RtlUnicodeStringPrintf( &buffer, L"%wZ", &XenIdentificationDesc->DeviceType);
638 status = WdfPdoInitAddDeviceText(ChildInit, &buffer, &DeviceLocation, 0x409);
640 WdfPdoInitSetDefaultLocale(ChildInit, 0x409);
642 WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&PdoAttributes, XENPCI_XEN_DEVICE_DATA);
644 // WDF_PDO_EVENT_CALLBACKS_INIT(&PdoCallbacks);
645 // PdoCallbacks.EvtDeviceResourceRequirementsQuery = XenPCI_DeviceResourceRequirementsQuery;
646 // WdfPdoInitSetEventCallbacks(ChildInit, &PdoCallbacks);
648 status = WdfDeviceCreate(&ChildInit, &PdoAttributes, &ChildDevice);
649 if (!NT_SUCCESS(status))
650 {
651 KdPrint((__DRIVER_NAME " WdfDeviceCreate status = %08X\n", status));
652 }
654 WdfDeviceSetSpecialFileSupport(ChildDevice, WdfSpecialFilePaging, TRUE);
655 WdfDeviceSetSpecialFileSupport(ChildDevice, WdfSpecialFileHibernation, TRUE);
656 WdfDeviceSetSpecialFileSupport(ChildDevice, WdfSpecialFileDump, TRUE);
658 ChildDeviceData = GetXenDeviceData(ChildDevice);
659 strncpy(ChildDeviceData->BasePath, XenIdentificationDesc->Path, 128);
661 RtlZeroMemory(&EvtChnInterface, sizeof(EvtChnInterface));
662 EvtChnInterface.InterfaceHeader.Size = sizeof(EvtChnInterface);
663 EvtChnInterface.InterfaceHeader.Version = 1;
664 EvtChnInterface.InterfaceHeader.Context = WdfPdoGetParent(ChildDevice);
665 EvtChnInterface.InterfaceHeader.InterfaceReference = WdfDeviceInterfaceReferenceNoOp;
666 EvtChnInterface.InterfaceHeader.InterfaceDereference = WdfDeviceInterfaceDereferenceNoOp;
667 EvtChnInterface.Bind = EvtChn_Bind;
668 EvtChnInterface.Unbind = EvtChn_Unbind;
669 EvtChnInterface.Mask = EvtChn_Mask;
670 EvtChnInterface.Unmask = EvtChn_Unmask;
671 EvtChnInterface.Notify = EvtChn_Notify;
672 EvtChnInterface.AllocUnbound = EvtChn_AllocUnbound;
673 WDF_QUERY_INTERFACE_CONFIG_INIT(&qiConfig, (PINTERFACE)&EvtChnInterface, &GUID_XEN_IFACE_EVTCHN, NULL);
674 status = WdfDeviceAddQueryInterface(ChildDevice, &qiConfig);
675 if (!NT_SUCCESS(status))
676 {
677 return status;
678 }
680 /* nobody uses this yet, maybe it isn't needed? */
681 #if 0
682 RtlZeroMemory(&XenInterface, sizeof(XenInterface));
683 XenInterface.InterfaceHeader.Size = sizeof(XenInterface);
684 XenInterface.InterfaceHeader.Version = 1;
685 XenInterface.InterfaceHeader.Context = WdfPdoGetParent(ChildDevice);
686 XenInterface.InterfaceHeader.InterfaceReference = WdfDeviceInterfaceReferenceNoOp;
687 XenInterface.InterfaceHeader.InterfaceDereference = WdfDeviceInterfaceDereferenceNoOp;
688 XenInterface.AllocMMIO = XenPCI_AllocMMIO;
689 WDF_QUERY_INTERFACE_CONFIG_INIT(&qiConfig, (PINTERFACE)&XenInterface, &GUID_XEN_IFACE_XEN, NULL);
690 status = WdfDeviceAddQueryInterface(ChildDevice, &qiConfig);
691 if (!NT_SUCCESS(status)) {
692 return status;
693 }
694 #endif
696 RtlZeroMemory(&GntTblInterface, sizeof(GntTblInterface));
697 GntTblInterface.InterfaceHeader.Size = sizeof(GntTblInterface);
698 GntTblInterface.InterfaceHeader.Version = 1;
699 GntTblInterface.InterfaceHeader.Context = WdfPdoGetParent(ChildDevice);
700 GntTblInterface.InterfaceHeader.InterfaceReference = WdfDeviceInterfaceReferenceNoOp;
701 GntTblInterface.InterfaceHeader.InterfaceDereference = WdfDeviceInterfaceDereferenceNoOp;
702 GntTblInterface.GrantAccess = GntTbl_GrantAccess;
703 GntTblInterface.EndAccess = GntTbl_EndAccess;
704 WDF_QUERY_INTERFACE_CONFIG_INIT(&qiConfig, (PINTERFACE)&GntTblInterface, &GUID_XEN_IFACE_GNTTBL, NULL);
705 status = WdfDeviceAddQueryInterface(ChildDevice, &qiConfig);
706 if (!NT_SUCCESS(status)) {
707 return status;
708 }
710 RtlZeroMemory(&XenBusInterface, sizeof(XenBusInterface));
712 XenBusInterface.InterfaceHeader.Size = sizeof(XenBusInterface);
713 XenBusInterface.InterfaceHeader.Version = 1;
714 XenBusInterface.InterfaceHeader.Context = WdfPdoGetParent(ChildDevice);
715 //XenBusInterface.InterfaceHeader.Context = ExAllocatePoolWithTag(NonPagedPool, (strlen(XenIdentificationDesc->Path) + 1), XENPCI_POOL_TAG);
716 //strcpy(XenBusInterface.InterfaceHeader.Context, XenIdentificationDesc->Path);
717 XenBusInterface.Read = XenBus_Read;
718 XenBusInterface.Write = XenBus_Write;
719 XenBusInterface.Printf = XenBus_Printf;
720 XenBusInterface.StartTransaction = XenBus_StartTransaction;
721 XenBusInterface.EndTransaction = XenBus_EndTransaction;
722 XenBusInterface.List = XenBus_List;
723 XenBusInterface.AddWatch = XenBus_AddWatch;
724 XenBusInterface.RemWatch = XenBus_RemWatch;
725 WDF_QUERY_INTERFACE_CONFIG_INIT(&qiConfig, (PINTERFACE)&XenBusInterface, &GUID_XEN_IFACE_XENBUS, NULL);
726 status = WdfDeviceAddQueryInterface(ChildDevice, &qiConfig);
727 if (!NT_SUCCESS(status)) {
728 return status;
729 }
731 //KdPrint((__DRIVER_NAME " <-- ChildListCreateDevice\n"));
733 return status;
734 }
736 VOID
737 XenPCI_XenBusWatchHandler(char *Path, PVOID Data)
738 {
739 XENPCI_IDENTIFICATION_DESCRIPTION description;
740 NTSTATUS status;
741 char **Bits;
742 int Count;
743 WDFDEVICE Device = Data;
744 WDFCHILDLIST ChildList;
745 WDF_CHILD_LIST_ITERATOR ChildIterator;
746 WDFDEVICE ChildDevice;
747 PXENPCI_XEN_DEVICE_DATA ChildDeviceData;
749 ANSI_STRING AnsiBuf;
751 UNREFERENCED_PARAMETER(Data);
753 KdPrint((__DRIVER_NAME " --> XenBusWatchHandle\n"));
755 //KdPrint((__DRIVER_NAME " %s\n", Path));
757 ChildList = WdfFdoGetDefaultChildList(Device);
759 Bits = SplitString(Path, '/', 3, &Count);
760 switch (Count)
761 {
762 case 0:
763 case 1:
764 break;
765 case 2:
766 // add or update the device node
767 WDF_CHILD_IDENTIFICATION_DESCRIPTION_HEADER_INIT(&description.Header, sizeof(description));
768 strncpy(description.Path, Path, 128);
769 RtlInitAnsiString(&AnsiBuf, Bits[1]);
770 //KdPrint((__DRIVER_NAME " Name = %s\n", Bits[1]));
771 RtlAnsiStringToUnicodeString(&description.DeviceType, &AnsiBuf, TRUE);
772 status = WdfChildListAddOrUpdateChildDescriptionAsPresent(ChildList, &description.Header, NULL);
773 break;
774 case 3:
775 WDF_CHILD_LIST_ITERATOR_INIT(&ChildIterator, WdfRetrievePresentChildren);
776 WdfChildListBeginIteration(ChildList, &ChildIterator);
777 while (NT_SUCCESS(WdfChildListRetrieveNextDevice(ChildList, &ChildIterator, &ChildDevice, NULL)))
778 {
779 ChildDeviceData = GetXenDeviceData(ChildDevice);
780 if (!ChildDeviceData)
781 {
782 KdPrint((__FUNCTION__ " No child device data, should never happen\n"));
783 continue;
784 }
785 if (strncmp(ChildDeviceData->BasePath, Path, strlen(ChildDeviceData->BasePath)) == 0 && Path[strlen(ChildDeviceData->BasePath)] == '/')
786 {
787 //KdPrint((__DRIVER_NAME " Child Path = %s (Match - WatchHandler = %08x)\n", ChildDeviceData->BasePath, ChildDeviceData->WatchHandler));
788 if (ChildDeviceData->WatchHandler != NULL)
789 ChildDeviceData->WatchHandler(Path, NULL);
790 }
791 else
792 {
793 //KdPrint((__DRIVER_NAME " Child Path = %s (No Match)\n", ChildDeviceData->BasePath));
794 }
795 }
796 WdfChildListEndIteration(ChildList, &ChildIterator);
797 break;
798 default:
799 KdPrint((__FUNCTION__ ": Unknown case %d\n", Count));
800 break;
801 }
803 FreeSplitString(Bits, Count);
805 KdPrint((__DRIVER_NAME " <-- XenBusWatchHandle\n"));
806 }
808 static void
809 XenBus_ShutdownHandler(char *Path, PVOID Data)
810 {
811 WDFDEVICE Device = Data;
812 char *value;
813 xenbus_transaction_t xbt;
814 int retry;
816 UNREFERENCED_PARAMETER(Path);
818 KdPrint((__DRIVER_NAME " --> XenBus_ShutdownHandler\n"));
820 XenBus_StartTransaction(Device, &xbt);
822 XenBus_Read(Device, XBT_NIL, SHUTDOWN_PATH, &value);
824 KdPrint((__DRIVER_NAME " Shutdown Value = %s\n", value));
826 // should check for error here... but why have we been called at all???
827 if (value != NULL && strlen(value) != 0)
828 XenBus_Write(Device, XBT_NIL, SHUTDOWN_PATH, "");
830 XenBus_EndTransaction(Device, xbt, 0, &retry);
832 KdPrint((__DRIVER_NAME " <-- XenBus_ShutdownHandler\n"));
833 }
835 static VOID
836 XenBus_BalloonHandler(char *Path, PVOID Data)
837 {
838 WDFDEVICE Device = Data;
839 char *value;
840 xenbus_transaction_t xbt;
841 int retry;
843 UNREFERENCED_PARAMETER(Path);
845 KdPrint((__DRIVER_NAME " --> XenBus_BalloonHandler\n"));
847 XenBus_StartTransaction(Device, &xbt);
849 XenBus_Read(Device, XBT_NIL, BALLOON_PATH, &value);
851 KdPrint((__DRIVER_NAME " Balloon Value = %s\n", value));
853 // use the memory_op(unsigned int op, void *arg) hypercall to adjust this
854 // use XENMEM_increase_reservation and XENMEM_decrease_reservation
856 XenBus_EndTransaction(Device, xbt, 0, &retry);
858 KdPrint((__DRIVER_NAME " <-- XenBus_BalloonHandler\n"));
859 }
861 /*
862 IO_RESOURCE_DESCRIPTOR MemoryDescriptor;
864 static NTSTATUS
865 XenPCI_FilterRemoveResourceRequirements(WDFDEVICE Device, WDFIORESREQLIST RequirementsList)
866 {
867 NTSTATUS status;
868 WDFIORESLIST ResourceList;
869 PIO_RESOURCE_DESCRIPTOR Descriptor;
871 int i, j;
872 int offset;
874 //KdPrint((__DRIVER_NAME " --> FilterRemoveResourceRequirements\n"));
876 for (i = 0; i < WdfIoResourceRequirementsListGetCount(RequirementsList); i++)
877 {
878 ResourceList = WdfIoResourceRequirementsListGetIoResList(RequirementsList, i);
879 //KdPrint((__DRIVER_NAME " Resource List %d\n", i));
880 //KdPrint((__DRIVER_NAME " %d resources in list\n", WdfIoResourceListGetCount(ResourceList)));
881 offset = 0;
882 for (j = 0; j < WdfIoResourceListGetCount(ResourceList); j++)
883 {
884 //KdPrint((__DRIVER_NAME " Resource %d\n", j));
885 Descriptor = WdfIoResourceListGetDescriptor(ResourceList, j - offset);
887 switch (Descriptor->Type) {
888 case CmResourceTypePort:
889 //KdPrint((__DRIVER_NAME " Port\n"));
890 break;
891 case CmResourceTypeMemory:
892 //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));
893 //KdPrint((__DRIVER_NAME " Length %08X\n", Descriptor->u.Memory.Length));
894 //KdPrint((__DRIVER_NAME " ShareDisposition %02X\n", Descriptor->ShareDisposition));
895 //KdPrint((__DRIVER_NAME " Option %02X\n", Descriptor->Option));
896 if (!Descriptor->Option || Descriptor->Option == IO_RESOURCE_PREFERRED) {
897 memcpy(&MemoryDescriptor, Descriptor, sizeof(IO_RESOURCE_DESCRIPTOR));
898 //platform_mmio_orig_len = MemoryDescriptor.u.Memory.Length;
899 //MemoryDescriptor.u.Memory.Length = PAGE_SIZE;
900 MemoryDescriptor.ShareDisposition = CmResourceShareShared;
901 }
902 WdfIoResourceListRemove(ResourceList, j - offset);
903 offset++;
904 break;
905 case CmResourceTypeInterrupt:
906 //KdPrint((__DRIVER_NAME " Interrupt\n"));
907 break;
908 case CmResourceTypeDevicePrivate:
909 //KdPrint((__DRIVER_NAME " Private\n"));
910 break;
911 default:
912 //KdPrint((__DRIVER_NAME " Unknown Type (0x%x)\n", Descriptor->Type));
913 break;
914 }
915 }
916 }
917 status = STATUS_SUCCESS;
919 KdPrint((__DRIVER_NAME " <-- FilterRemoveResourceRequirements\n"));
921 return status;
922 }
925 static NTSTATUS
926 XenPCI_FilterAddResourceRequirements(WDFDEVICE Device, WDFIORESREQLIST RequirementsList)
927 {
928 NTSTATUS status;
929 WDFIORESLIST ResourceList;
930 PIO_RESOURCE_DESCRIPTOR Descriptor;
932 int i, j;
934 KdPrint((__DRIVER_NAME " --> FilterAddResourceRequirements\n"));
937 for (i = 0; i < WdfIoResourceRequirementsListGetCount(RequirementsList); i++)
938 {
939 ResourceList = WdfIoResourceRequirementsListGetIoResList(RequirementsList, i);
940 //KdPrint((__DRIVER_NAME " Resource List %d\n", i));
941 //KdPrint((__DRIVER_NAME " %d resources in list\n", WdfIoResourceListGetCount(ResourceList)));
942 WdfIoResourceListAppendDescriptor(ResourceList, &MemoryDescriptor);
943 //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));
944 //KdPrint((__DRIVER_NAME " Length %08X\n", MemoryDescriptor.u.Memory.Length));
945 for (j = 0; j < WdfIoResourceListGetCount(ResourceList); j++)
946 {
947 //KdPrint((__DRIVER_NAME " Resource %d\n", j));
948 Descriptor = WdfIoResourceListGetDescriptor(ResourceList, j);
950 switch (Descriptor->Type) {
951 case CmResourceTypePort:
952 //KdPrint((__DRIVER_NAME " Port\n"));
953 break;
954 case CmResourceTypeMemory:
955 //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));
956 //KdPrint((__DRIVER_NAME " Length %08X\n", Descriptor->u.Memory.Length));
957 //KdPrint((__DRIVER_NAME " ShareDisposition %02X\n", Descriptor->ShareDisposition));
958 //Descriptor->ShareDisposition = CmResourceShareShared;
959 //memcpy(&MemoryDescriptor, Descriptor, sizeof(IO_RESOURCE_DESCRIPTOR));
960 //platform_mmio_orig_len = MemoryDescriptor.u.Memory.Length;
961 //MemoryDescriptor.u.Memory.Length = PAGE_SIZE;
962 //WdfIoResourceListRemove(ResourceList, j);
963 break;
964 case CmResourceTypeInterrupt:
965 //KdPrint((__DRIVER_NAME " Interrupt\n"));
966 break;
967 case CmResourceTypeDevicePrivate:
968 //KdPrint((__DRIVER_NAME " Private\n"));
969 break;
970 default:
971 //KdPrint((__DRIVER_NAME " Unknown Type (0x%x)\n", Descriptor->Type));
972 break;
973 }
974 }
975 }
976 status = STATUS_SUCCESS;
978 //KdPrint((__DRIVER_NAME " <-- FilterAddResourceRequirements\n"));
980 return status;
981 }
983 static NTSTATUS
984 XenPCI_RemoveAddedResources(WDFDEVICE Device, WDFCMRESLIST ResourcesRaw, WDFCMRESLIST ResourcesTranslated)
985 {
986 //KdPrint((__DRIVER_NAME " --> RemoveAddedResources\n"));
987 //KdPrint((__DRIVER_NAME " <-- RemoveAddedResources\n"));
989 return STATUS_SUCCESS;
990 }
992 */
994 static NTSTATUS
995 XenPCI_DeviceResourceRequirementsQuery(WDFDEVICE Device, WDFIORESREQLIST IoResourceRequirementsList)
996 {
997 NTSTATUS status;
998 WDFIORESLIST resourceList;
999 IO_RESOURCE_DESCRIPTOR descriptor;
1000 PXENPCI_DEVICE_DATA deviceData = GetDeviceData(Device);
1002 //KdPrint((__DRIVER_NAME " --> DeviceResourceRequirementsQuery\n"));
1004 status = WdfIoResourceListCreate(IoResourceRequirementsList, WDF_NO_OBJECT_ATTRIBUTES, &resourceList);
1005 if (!NT_SUCCESS(status))
1006 return status;
1008 /*
1009 RtlZeroMemory(&descriptor, sizeof(descriptor));
1011 descriptor.Option = 0;
1012 descriptor.Type = CmResourceTypeInterrupt;
1013 descriptor.ShareDisposition = CmResourceShareDeviceExclusive;
1014 descriptor.Flags = CM_RESOURCE_MEMORY_READ_WRITE;
1015 descriptor.u.Interrupt.MinimumVector = 1024;
1016 descriptor.u.Interrupt.MaximumVector = 1024+255;
1018 //KdPrint((__DRIVER_NAME " MinimumVector = %d, MaximumVector = %d\n", descriptor.u.Interrupt.MinimumVector, descriptor.u.Interrupt.MaximumVector));
1020 status = WdfIoResourceListAppendDescriptor(resourceList, &descriptor);
1021 if (!NT_SUCCESS(status))
1022 return status;
1023 */
1025 RtlZeroMemory(&descriptor, sizeof(descriptor));
1027 descriptor.Option = 0;
1028 descriptor.Type = CmResourceTypeMemory;
1029 descriptor.ShareDisposition = CmResourceShareShared; //CmResourceShareDeviceExclusive;
1030 descriptor.Flags = CM_RESOURCE_MEMORY_READ_WRITE;
1031 descriptor.u.Memory.Length = PAGE_SIZE;
1032 descriptor.u.Memory.Alignment = PAGE_SIZE;
1033 descriptor.u.Memory.MinimumAddress.QuadPart
1034 = deviceData->platform_mmio_addr.QuadPart + PAGE_SIZE;
1035 descriptor.u.Memory.MaximumAddress.QuadPart
1036 = deviceData->platform_mmio_addr.QuadPart + deviceData->platform_mmio_len - 1;
1038 //KdPrint((__DRIVER_NAME " MinimumAddress = %08x, MaximumAddress = %08X\n", descriptor.u.Memory.MinimumAddress.LowPart, descriptor.u.Memory.MaximumAddress.LowPart));
1040 status = WdfIoResourceListAppendDescriptor(resourceList, &descriptor);
1041 if (!NT_SUCCESS(status))
1042 return status;
1044 status = WdfIoResourceRequirementsListAppendIoResList(IoResourceRequirementsList, resourceList);
1045 if (!NT_SUCCESS(status))
1046 return status;
1048 //KdPrint((__DRIVER_NAME " <-- DeviceResourceRequirementsQuery\n"));
1050 return status;