win-pvdrivers

view xenpci/xenpci.c @ 6:8f643f8e229b

Bug Fixes... trying to find a problem that turned out to be me running an old version of xen by mistake!
author James Harper <james.harper@bendigoit.com.au>
date Mon Nov 12 22:26:30 2007 +1100 (2007-11-12)
parents 3bf1f48005d8
children d25a6f733a8e
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 shared_info_t *shared_info_area;
72 static ULONG irqNumber = 0;
74 static BOOLEAN AutoEnumerate;
76 static WDFDEVICE Device;
78 NTSTATUS
79 DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
80 {
81 WDF_DRIVER_CONFIG config;
82 NTSTATUS status;
83 UNICODE_STRING RegKeyName;
84 UNICODE_STRING RegValueName;
85 HANDLE RegHandle;
86 OBJECT_ATTRIBUTES RegObjectAttributes;
87 char Buf[200];
88 ULONG BufLen = 200;
89 PKEY_VALUE_PARTIAL_INFORMATION KeyPartialValue;
90 int State = 0;
91 int StartPos = 0;
92 WCHAR *SystemStartOptions;
93 size_t SystemStartOptionsLen;
94 size_t i;
96 KdPrint((__DRIVER_NAME " --> DriverEntry\n"));
98 RtlInitUnicodeString(&RegKeyName, L"\\Registry\\Machine\\System\\CurrentControlSet\\Control");
99 InitializeObjectAttributes(&RegObjectAttributes, &RegKeyName, OBJ_CASE_INSENSITIVE, NULL, NULL);
100 status = ZwOpenKey(&RegHandle, KEY_READ, &RegObjectAttributes);
101 if(!NT_SUCCESS(status))
102 {
103 KdPrint((__DRIVER_NAME " ZwOpenKey returned %08x\n", status));
104 }
106 RtlInitUnicodeString(&RegValueName, L"SystemStartOptions");
107 status = ZwQueryValueKey(RegHandle, &RegValueName, KeyValuePartialInformation, Buf, BufLen, &BufLen);
108 if(!NT_SUCCESS(status))
109 {
110 KdPrint((__DRIVER_NAME " ZwQueryKeyValue returned %08x\n", status));
111 }
112 //KdPrint((__DRIVER_NAME " BufLen = %d\n", BufLen));
113 KeyPartialValue = (PKEY_VALUE_PARTIAL_INFORMATION)Buf;
114 KdPrint((__DRIVER_NAME " Buf = %ws\n", KeyPartialValue->Data));
115 SystemStartOptions = (WCHAR *)KeyPartialValue->Data;
117 AutoEnumerate = FALSE;
119 RtlStringCbLengthW(SystemStartOptions, KeyPartialValue->DataLength, &SystemStartOptionsLen);
121 for (i = 0; i <= SystemStartOptionsLen/2; i++)
122 {
123 //KdPrint((__DRIVER_NAME " pos = %d, state = %d, char = '%wc' (%d)\n", i, State, SystemStartOptions[i], SystemStartOptions[i]));
125 switch (State)
126 {
127 case 0:
128 if (SystemStartOptions[i] == L'G')
129 {
130 StartPos = i;
131 State = 2;
132 } else if (SystemStartOptions[i] != L' ')
133 {
134 State = 1;
135 }
136 break;
137 case 1:
138 if (SystemStartOptions[i] == L' ')
139 State = 0;
140 break;
141 case 2:
142 if (SystemStartOptions[i] == L'P')
143 State = 3;
144 else
145 State = 0;
146 break;
147 case 3:
148 if (SystemStartOptions[i] == L'L')
149 State = 4;
150 else
151 State = 0;
152 break;
153 case 4:
154 if (SystemStartOptions[i] == L'P')
155 State = 5;
156 else
157 State = 0;
158 break;
159 case 5:
160 if (SystemStartOptions[i] == L'V')
161 State = 6;
162 else
163 State = 0;
164 break;
165 case 6:
166 if (SystemStartOptions[i] == L' ' || SystemStartOptions[i] == 0)
167 AutoEnumerate = TRUE;
168 State = 0;
169 break;
170 }
171 }
173 KdPrint((__DRIVER_NAME " AutoEnumerate = %d\n", AutoEnumerate));
175 WDF_DRIVER_CONFIG_INIT(&config, XenPCI_AddDevice);
176 status = WdfDriverCreate(
177 DriverObject,
178 RegistryPath,
179 WDF_NO_OBJECT_ATTRIBUTES,
180 &config,
181 WDF_NO_HANDLE);
182 if(!NT_SUCCESS(status))
183 {
184 KdPrint((__DRIVER_NAME " WdfDriverCreate failed with status 0x%08x\n", status));
185 }
187 KdPrint((__DRIVER_NAME " <-- DriverEntry\n"));
189 return status;
190 }
192 static void WRMSR(unsigned int msr, ULONGLONG val)
193 {
194 ULONG lo, hi;
195 lo = (ULONG)val;
196 hi = (ULONG)(val >> 32);
197 __asm {
198 mov ecx, msr
199 mov eax, lo
200 mov edx, hi
201 wrmsr
202 }
203 }
205 static int
206 get_hypercall_stubs()
207 {
208 DWORD32 cpuid_output[4];
209 char xensig[13];
210 ULONG i;
211 ULONG pages;
212 ULONG msr;
214 __cpuid(cpuid_output, 0x40000000);
215 *(ULONG*)(xensig + 0) = cpuid_output[1];
216 *(ULONG*)(xensig + 4) = cpuid_output[2];
217 *(ULONG*)(xensig + 8) = cpuid_output[3];
218 xensig[12] = '\0';
219 KdPrint((__DRIVER_NAME " Xen Signature = %s, EAX = 0x%08x\n", xensig, cpuid_output[0]));
221 __cpuid(cpuid_output, 0x40000002);
222 pages = cpuid_output[0];
223 msr = cpuid_output[1];
224 //KdPrint((__DRIVER_NAME " Hypercall area is %u pages.\n", pages));
226 hypercall_stubs = ExAllocatePoolWithTag(NonPagedPool, pages * PAGE_SIZE, XENPCI_POOL_TAG);
227 //KdPrint((__DRIVER_NAME " Hypercall area at %08x\n", hypercall_stubs));
229 if (hypercall_stubs == NULL)
230 return 1;
231 for (i = 0; i < pages; i++) {
232 ULONG pfn;
233 //pfn = vmalloc_to_pfn((char *)hypercall_stubs + i * PAGE_SIZE);
234 pfn = (ULONG)(MmGetPhysicalAddress(hypercall_stubs + i * PAGE_SIZE).QuadPart >> PAGE_SHIFT);
235 //KdPrint((__DRIVER_NAME " pfn = %08X\n", pfn));
236 WRMSR(msr, ((ULONGLONG)pfn << PAGE_SHIFT) + i);
237 }
238 return STATUS_SUCCESS;
239 }
241 static ULONG PciBusNumber;
242 static USHORT PciFunctionNumber, PciDeviceNumber;
243 static USHORT PciPinNumber;
245 static WDFINTERRUPT XenInterrupt;
247 static PHYSICAL_ADDRESS platform_mmio_addr;
248 static ULONG platform_mmio_orig_len;
249 static ULONG platform_mmio_len;
250 static ULONG platform_mmio_alloc;
252 PHYSICAL_ADDRESS
253 XenPCI_AllocMMIO(ULONG len)
254 {
255 PHYSICAL_ADDRESS addr;
257 addr = platform_mmio_addr;
258 addr.QuadPart += platform_mmio_alloc;
259 platform_mmio_alloc += len;
261 return addr;
262 }
264 static int
265 init_xen_info()
266 {
267 struct xen_add_to_physmap xatp;
268 int ret;
269 PHYSICAL_ADDRESS shared_info_area_unmapped;
271 //setup_xen_features();
272 //KdPrint((__DRIVER_NAME " init_xen_info Hypercall area at %08x\n", hypercall_stubs));
274 shared_info_area_unmapped = XenPCI_AllocMMIO(PAGE_SIZE);
275 xatp.domid = DOMID_SELF;
276 xatp.idx = 0;
277 xatp.space = XENMAPSPACE_shared_info;
278 xatp.gpfn = (xen_pfn_t)(shared_info_area_unmapped.QuadPart >> PAGE_SHIFT);
279 ret = HYPERVISOR_memory_op(XENMEM_add_to_physmap, &xatp);
280 //KdPrint((__DRIVER_NAME " ret = %d\n", ret));
282 shared_info_area = (shared_info_t *)MmMapIoSpace(shared_info_area_unmapped, PAGE_SIZE, MmNonCached);
284 return 0;
285 }
287 static PKINTERRUPT interrupt;
289 static int
290 set_callback_irq(ULONGLONG irq)
291 {
292 struct xen_hvm_param a;
293 int retval;
295 //KdPrint((__DRIVER_NAME " --> set_callback_irq\n"));
296 a.domid = DOMID_SELF;
297 a.index = HVM_PARAM_CALLBACK_IRQ;
298 a.value = irq;
299 retval = HYPERVISOR_hvm_op(HVMOP_set_param, &a);
300 //KdPrint((__DRIVER_NAME " HYPERVISOR_hvm_op retval = %d\n", retval));
301 //KdPrint((__DRIVER_NAME " <-- set_callback_irq\n"));
302 return retval;
303 }
305 static NTSTATUS
306 XenPCI_AddDevice(
307 IN WDFDRIVER Driver,
308 IN PWDFDEVICE_INIT DeviceInit
309 )
310 {
311 NTSTATUS status;
312 WDF_CHILD_LIST_CONFIG config;
313 PXENPCI_DEVICE_DATA devData = NULL;
314 WDF_OBJECT_ATTRIBUTES attributes;
315 WDF_PNPPOWER_EVENT_CALLBACKS pnpPowerCallbacks;
316 WDF_IO_QUEUE_CONFIG ioQConfig;
317 WDF_INTERRUPT_CONFIG interruptConfig;
318 PNP_BUS_INFORMATION busInfo;
319 BUS_INTERFACE_STANDARD BusInterface;
320 //WDFDEVICE Parent;
322 //PDEVICE_OBJECT pdo;
323 //ULONG propertyAddress, length;
325 UNREFERENCED_PARAMETER(Driver);
327 KdPrint((__DRIVER_NAME " --> DeviceAdd\n"));
329 // get PDO
330 // get parent (should be PCI bus) (WdfPdoGetParent)
331 //
333 WdfDeviceInitSetDeviceType(DeviceInit, FILE_DEVICE_BUS_EXTENDER);
334 WDF_CHILD_LIST_CONFIG_INIT(&config, sizeof(XENPCI_IDENTIFICATION_DESCRIPTION), XenPCI_ChildListCreateDevice);
335 WdfFdoInitSetDefaultChildListConfig(DeviceInit, &config, WDF_NO_OBJECT_ATTRIBUTES);
337 // WDF_FDO_EVENT_CALLBACKS_INIT(&FdoCallbacks);
338 // FdoCallbacks.EvtDeviceFilterRemoveResourceRequirements = XenPCI_FilterRemoveResourceRequirements;
339 // FdoCallbacks.EvtDeviceFilterAddResourceRequirements = XenPCI_FilterAddResourceRequirements;
340 // FdoCallbacks.EvtDeviceRemoveAddedResources = XenPCI_RemoveAddedResources;
341 // WdfFdoInitSetEventCallbacks(DeviceInit, &FdoCallbacks);
343 WDF_PNPPOWER_EVENT_CALLBACKS_INIT(&pnpPowerCallbacks);
344 pnpPowerCallbacks.EvtDevicePrepareHardware = XenPCI_PrepareHardware;
345 pnpPowerCallbacks.EvtDeviceReleaseHardware = XenPCI_ReleaseHardware;
346 pnpPowerCallbacks.EvtDeviceD0Entry = XenPCI_D0Entry;
347 pnpPowerCallbacks.EvtDeviceD0EntryPostInterruptsEnabled = XenPCI_D0EntryPostInterruptsEnabled;
348 pnpPowerCallbacks.EvtDeviceD0ExitPreInterruptsDisabled = XenPCI_D0ExitPreInterruptsDisabled;
349 pnpPowerCallbacks.EvtDeviceD0Exit = XenPCI_D0Exit;
350 WdfDeviceInitSetPnpPowerEventCallbacks(DeviceInit, &pnpPowerCallbacks);
352 WdfDeviceInitSetIoType(DeviceInit, WdfDeviceIoBuffered);
354 /*initialize storage for the device context*/
355 WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&attributes, XENPCI_DEVICE_DATA);
357 /*create a device instance.*/
358 status = WdfDeviceCreate(&DeviceInit, &attributes, &Device);
359 if(!NT_SUCCESS(status))
360 {
361 KdPrint((__DRIVER_NAME " WdfDeviceCreate failed with status 0x%08x\n", status));
362 return status;
363 }
365 status = WdfFdoQueryForInterface(Device, &GUID_BUS_INTERFACE_STANDARD, (PINTERFACE) &BusInterface, sizeof(BUS_INTERFACE_STANDARD), 1, NULL);
366 if(!NT_SUCCESS(status))
367 {
368 KdPrint((__DRIVER_NAME " WdfFdoQueryForInterface (BusInterface) failed with status 0x%08x\n", status));
369 }
371 //BusInterface.GetBusData(NULL, PCI_WHICHSPACE_CONFIG, buf,
374 busInfo.BusTypeGuid = GUID_XENPCI_DEVCLASS;
375 busInfo.LegacyBusType = PNPBus;
376 busInfo.BusNumber = 0;
378 WdfDeviceSetBusInformationForChildren(Device, &busInfo);
380 /*create the default IO queue. this one will
381 be used for all requests*/
382 /*
383 WDF_IO_QUEUE_CONFIG_INIT_DEFAULT_QUEUE(&ioQConfig,
384 WdfIoQueueDispatchSequential);
385 ioQConfig.EvtIoDefault = XenPCI_IoDefault;
386 status = WdfIoQueueCreate(Device, &ioQConfig,
387 WDF_NO_OBJECT_ATTRIBUTES,
388 &devData->IoDefaultQueue);
389 if(!NT_SUCCESS(status))
390 {
391 KdPrint((__DRIVER_NAME " WdfIoQueueCreate failed with status 0x%08x\n", status));
392 return status;
393 }
394 */
395 /*
396 status = WdfDeviceCreateDeviceInterface(Device, &GUID_INTERFACE_XENPCI, NULL);
397 if(!NT_SUCCESS(status))
398 {
399 KdPrint((__DRIVER_NAME "WdfDeviceCreateDeviceInterface failed with status 0x%08x\n", status));
400 return status;
401 }
402 */
404 WDF_INTERRUPT_CONFIG_INIT(&interruptConfig, EvtChn_Interrupt, NULL); //EvtChn_InterruptDpc);
405 interruptConfig.EvtInterruptEnable = XenPCI_InterruptEnable;
406 interruptConfig.EvtInterruptDisable = XenPCI_InterruptDisable;
407 status = WdfInterruptCreate(Device, &interruptConfig, WDF_NO_OBJECT_ATTRIBUTES, &XenInterrupt);
408 if (!NT_SUCCESS (status))
409 {
410 KdPrint((__DRIVER_NAME "WdfInterruptCreate failed 0x%08x\n", status));
411 return status;
412 }
414 KdPrint((__DRIVER_NAME " <-- DeviceAdd\n"));
415 return status;
416 }
418 static NTSTATUS
419 XenPCI_PrepareHardware(
420 IN WDFDEVICE Device,
421 IN WDFCMRESLIST ResourceList,
422 IN WDFCMRESLIST ResourceListTranslated)
423 {
424 NTSTATUS status = STATUS_SUCCESS;
425 PCM_PARTIAL_RESOURCE_DESCRIPTOR descriptor;
426 ULONG i;
428 UNREFERENCED_PARAMETER(Device);
430 KdPrint((__DRIVER_NAME " --> EvtDevicePrepareHardware\n"));
432 for (i = 0; i < WdfCmResourceListGetCount(ResourceList); i++)
433 {
434 descriptor = WdfCmResourceListGetDescriptor(ResourceList, i);
435 if(!descriptor)
436 continue;
437 switch (descriptor->Type)
438 {
439 case CmResourceTypeInterrupt:
440 irqNumber = descriptor->u.Interrupt.Vector;
441 break;
442 }
443 }
445 //KdPrint((__DRIVER_NAME " GSI = %d\n", irqNumber));
447 //KdPrint((__DRIVER_NAME " ResourceListTranslated\n"));
448 for (i = 0; i < WdfCmResourceListGetCount(ResourceListTranslated); i++)
449 {
450 descriptor = WdfCmResourceListGetDescriptor(ResourceListTranslated, i);
451 if(!descriptor)
452 {
453 KdPrint((__DRIVER_NAME " --> EvtDevicePrepareHardware (No descriptor)\n"));
454 return STATUS_DEVICE_CONFIGURATION_ERROR;
455 }
456 switch (descriptor->Type) {
457 case CmResourceTypePort:
458 //KdPrint((__DRIVER_NAME " I/O mapped CSR: (%x) Length: (%d)\n", descriptor->u.Port.Start.LowPart, descriptor->u.Port.Length));
459 // deviceData->IoBaseAddress = ULongToPtr(descriptor->u.Port.Start.LowPart);
460 // deviceData->IoRange = descriptor->u.Port.Length;
461 break;
462 case CmResourceTypeMemory:
463 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));
464 platform_mmio_addr = descriptor->u.Memory.Start; //(ULONG)MmMapIoSpace(descriptor->u.Memory.Start, descriptor->u.Memory.Length, MmNonCached);
465 platform_mmio_len = descriptor->u.Memory.Length;
466 platform_mmio_alloc = 0;
467 break;
468 case CmResourceTypeInterrupt:
469 //KdPrint((__DRIVER_NAME " Interrupt level: 0x%0x, Vector: 0x%0x\n", descriptor->u.Interrupt.Level, descriptor->u.Interrupt.Vector));
470 break;
471 case CmResourceTypeDevicePrivate:
472 //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] ));
473 break;
474 default:
475 //KdPrint((__DRIVER_NAME " Unhandled resource type (0x%x)\n", descriptor->Type));
476 break;
477 }
478 }
480 get_hypercall_stubs();
482 init_xen_info();
484 GntTbl_Init();
486 EvtChn_Init();
488 set_callback_irq(irqNumber);
490 XenBus_Init();
492 //KdPrint((__DRIVER_NAME " upcall_pending = %d\n", shared_info_area->vcpu_info[0].evtchn_upcall_pending));
494 shared_info_area->vcpu_info[0].evtchn_upcall_mask = 0;
496 //xen_reboot_init();
498 KdPrint((__DRIVER_NAME " <-- EvtDevicePrepareHardware\n"));
500 return status;
501 }
503 static NTSTATUS
504 XenPCI_ReleaseHardware(WDFDEVICE Device, WDFCMRESLIST ResourcesTranslated)
505 {
506 UNREFERENCED_PARAMETER(Device);
507 UNREFERENCED_PARAMETER(ResourcesTranslated);
509 return STATUS_SUCCESS;
510 }
512 static NTSTATUS
513 XenPCI_D0Entry(
514 IN WDFDEVICE Device,
515 IN WDF_POWER_DEVICE_STATE PreviousState
516 )
517 {
518 NTSTATUS status = STATUS_SUCCESS;
520 UNREFERENCED_PARAMETER(Device);
521 UNREFERENCED_PARAMETER(PreviousState);
523 KdPrint((__DRIVER_NAME " --> EvtDeviceD0Entry\n"));
525 KdPrint((__DRIVER_NAME " <-- EvtDeviceD0Entry\n"));
527 return status;
528 }
530 static HANDLE ThreadHandle;
532 static NTSTATUS
533 XenPCI_D0EntryPostInterruptsEnabled(WDFDEVICE Device, WDF_POWER_DEVICE_STATE PreviousState)
534 {
535 NTSTATUS status = STATUS_SUCCESS;
536 //OBJECT_ATTRIBUTES oa;
537 char *response;
538 char *msgTypes;
539 char **Types;
540 int i;
541 char buffer[128];
543 UNREFERENCED_PARAMETER(Device);
544 UNREFERENCED_PARAMETER(PreviousState);
546 KdPrint((__DRIVER_NAME " --> EvtDeviceD0EntryPostInterruptsEnabled\n"));
548 XenBus_Start();
550 KdPrint((__DRIVER_NAME " A\n"));
552 response = XenBus_AddWatch(XBT_NIL, SHUTDOWN_PATH, XenBus_ShutdownHandler, NULL);
553 KdPrint((__DRIVER_NAME " shutdown watch response = '%s'\n", response));
555 response = XenBus_AddWatch(XBT_NIL, BALLOON_PATH, XenBus_BalloonHandler, NULL);
556 KdPrint((__DRIVER_NAME " shutdown watch response = '%s'\n", response));
558 response = XenBus_AddWatch(XBT_NIL, "device", XenPCI_XenBusWatchHandler, NULL);
559 KdPrint((__DRIVER_NAME " device watch response = '%s'\n", response));
561 msgTypes = XenBus_List(XBT_NIL, "device", &Types);
562 if (!msgTypes) {
563 for (i = 0; Types[i]; i++)
564 {
565 RtlStringCbPrintfA(buffer, ARRAY_SIZE(buffer), "device/%s", Types[i]);
566 //KdPrint((__DRIVER_NAME " ls device[%d] -> %s\n", i, Types[i]));
567 XenPCI_XenBusWatchHandler(buffer, NULL);
568 ExFreePoolWithTag(Types[i], XENPCI_POOL_TAG);
569 }
570 }
571 KdPrint((__DRIVER_NAME " <-- EvtDeviceD0EntryPostInterruptsEnabled\n"));
573 return status;
574 }
576 static NTSTATUS
577 XenPCI_D0ExitPreInterruptsDisabled(WDFDEVICE Device, WDF_POWER_DEVICE_STATE TargetState)
578 {
579 NTSTATUS status = STATUS_SUCCESS;
581 UNREFERENCED_PARAMETER(Device);
582 UNREFERENCED_PARAMETER(TargetState);
584 XenBus_Stop();
586 return status;
587 }
589 static NTSTATUS
590 XenPCI_D0Exit(WDFDEVICE Device, WDF_POWER_DEVICE_STATE TargetState)
591 {
592 NTSTATUS status = STATUS_SUCCESS;
594 UNREFERENCED_PARAMETER(Device);
595 UNREFERENCED_PARAMETER(TargetState);
597 KdPrint((__DRIVER_NAME " --> EvtDeviceD0Exit\n"));
599 KdPrint((__DRIVER_NAME " <-- EvtDeviceD0Exit\n"));
601 return status;
602 }
604 static VOID
605 XenPCI_IoDefault(
606 IN WDFQUEUE Queue,
607 IN WDFREQUEST Request
608 )
609 {
610 UNREFERENCED_PARAMETER(Queue);
612 KdPrint((__DRIVER_NAME " --> EvtDeviceIoDefault\n"));
614 WdfRequestComplete(Request, STATUS_NOT_IMPLEMENTED);
616 KdPrint((__DRIVER_NAME " <-- EvtDeviceIoDefault\n"));
617 }
619 static NTSTATUS
620 XenPCI_InterruptEnable(WDFINTERRUPT Interrupt, WDFDEVICE AssociatedDevice)
621 {
622 UNREFERENCED_PARAMETER(Interrupt);
623 UNREFERENCED_PARAMETER(AssociatedDevice);
625 KdPrint((__DRIVER_NAME " --> EvtInterruptEnable\n"));
627 shared_info_area->vcpu_info[0].evtchn_upcall_mask = 0;
629 KdPrint((__DRIVER_NAME " <-- EvtInterruptEnable\n"));
631 return STATUS_SUCCESS;
632 }
634 static NTSTATUS
635 XenPCI_InterruptDisable(WDFINTERRUPT Interrupt, WDFDEVICE AssociatedDevice)
636 {
637 UNREFERENCED_PARAMETER(Interrupt);
638 UNREFERENCED_PARAMETER(AssociatedDevice);
640 //KdPrint((__DRIVER_NAME " --> EvtInterruptDisable\n"));
642 shared_info_area->vcpu_info[0].evtchn_upcall_mask = 1;
643 // should we kick off any pending interrupts here?
645 //KdPrint((__DRIVER_NAME " <-- EvtInterruptDisable\n"));
647 return STATUS_SUCCESS;
648 }
650 static NTSTATUS
651 XenPCI_ChildListCreateDevice(WDFCHILDLIST ChildList, PWDF_CHILD_IDENTIFICATION_DESCRIPTION_HEADER IdentificationDescription, PWDFDEVICE_INIT ChildInit)
652 {
653 NTSTATUS status;
654 WDFDEVICE ChildDevice = NULL;
655 PXENPCI_IDENTIFICATION_DESCRIPTION XenIdentificationDesc;
656 XEN_IFACE_EVTCHN EvtChnInterface;
657 XEN_IFACE_XENBUS XenBusInterface;
658 XEN_IFACE_XEN XenInterface;
659 XEN_IFACE_GNTTBL GntTblInterface;
660 //UNICODE_STRING DeviceId;
661 DECLARE_UNICODE_STRING_SIZE(buffer, 20);
662 WDF_OBJECT_ATTRIBUTES PdoAttributes;
663 DECLARE_CONST_UNICODE_STRING(DeviceLocation, L"Xen Bus");
664 WDF_QUERY_INTERFACE_CONFIG qiConfig;
665 //WDF_PDO_EVENT_CALLBACKS PdoCallbacks;
666 PXENPCI_XEN_DEVICE_DATA ChildDeviceData = NULL;
667 //size_t path_len;
669 UNREFERENCED_PARAMETER(ChildList);
671 //KdPrint((__DRIVER_NAME " --> ChildListCreateDevice\n"));
673 XenIdentificationDesc = CONTAINING_RECORD(IdentificationDescription, XENPCI_IDENTIFICATION_DESCRIPTION, Header);
675 //KdPrint((__DRIVER_NAME " Type = %wZ\n", &XenIdentificationDesc->DeviceType));
677 //DeviceInit = WdfPdoInitAllocate(Device);
678 WdfDeviceInitSetDeviceType(ChildInit, FILE_DEVICE_CONTROLLER);
680 status = RtlUnicodeStringPrintf(&buffer, L"Xen\\%wZ\0", &XenIdentificationDesc->DeviceType);
681 status = WdfPdoInitAssignDeviceID(ChildInit, &buffer);
682 status = WdfPdoInitAddHardwareID(ChildInit, &buffer);
683 status = WdfPdoInitAddCompatibleID(ChildInit, &buffer);
685 status = RtlUnicodeStringPrintf(&buffer, L"%02d", 0);
686 status = WdfPdoInitAssignInstanceID(ChildInit, &buffer);
688 status = RtlUnicodeStringPrintf( &buffer, L"%wZ", &XenIdentificationDesc->DeviceType);
689 status = WdfPdoInitAddDeviceText(ChildInit, &buffer, &DeviceLocation, 0x409);
691 WdfPdoInitSetDefaultLocale(ChildInit, 0x409);
693 WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&PdoAttributes, XENPCI_XEN_DEVICE_DATA);
695 // WDF_PDO_EVENT_CALLBACKS_INIT(&PdoCallbacks);
696 // PdoCallbacks.EvtDeviceResourceRequirementsQuery = XenPCI_DeviceResourceRequirementsQuery;
697 // WdfPdoInitSetEventCallbacks(ChildInit, &PdoCallbacks);
699 status = WdfDeviceCreate(&ChildInit, &PdoAttributes, &ChildDevice);
700 if (!NT_SUCCESS(status))
701 {
702 KdPrint((__DRIVER_NAME " WdfDeviceCreate status = %08X\n", status));
703 }
705 ChildDeviceData = GetXenDeviceData(ChildDevice);
706 strncpy(ChildDeviceData->BasePath, XenIdentificationDesc->Path, 128);
708 RtlZeroMemory(&EvtChnInterface, sizeof(EvtChnInterface));
709 EvtChnInterface.InterfaceHeader.Size = sizeof(EvtChnInterface);
710 EvtChnInterface.InterfaceHeader.Version = 1;
711 EvtChnInterface.InterfaceHeader.Context = NULL;
712 EvtChnInterface.InterfaceHeader.InterfaceReference = WdfDeviceInterfaceReferenceNoOp;
713 EvtChnInterface.InterfaceHeader.InterfaceDereference = WdfDeviceInterfaceDereferenceNoOp;
714 EvtChnInterface.Bind = EvtChn_Bind;
715 EvtChnInterface.Unbind = EvtChn_Unbind;
716 EvtChnInterface.Mask = EvtChn_Mask;
717 EvtChnInterface.Unmask = EvtChn_Unmask;
718 EvtChnInterface.Notify = EvtChn_Notify;
719 EvtChnInterface.AllocUnbound = EvtChn_AllocUnbound;
720 WDF_QUERY_INTERFACE_CONFIG_INIT(&qiConfig, (PINTERFACE)&EvtChnInterface, &GUID_XEN_IFACE_EVTCHN, NULL);
721 status = WdfDeviceAddQueryInterface(ChildDevice, &qiConfig);
722 if (!NT_SUCCESS(status))
723 {
724 return status;
725 }
727 RtlZeroMemory(&XenInterface, sizeof(XenInterface));
728 XenInterface.InterfaceHeader.Size = sizeof(XenInterface);
729 XenInterface.InterfaceHeader.Version = 1;
730 XenInterface.InterfaceHeader.Context = NULL;
731 XenInterface.InterfaceHeader.InterfaceReference = WdfDeviceInterfaceReferenceNoOp;
732 XenInterface.InterfaceHeader.InterfaceDereference = WdfDeviceInterfaceDereferenceNoOp;
733 XenInterface.AllocMMIO = XenPCI_AllocMMIO;
734 WDF_QUERY_INTERFACE_CONFIG_INIT(&qiConfig, (PINTERFACE)&XenInterface, &GUID_XEN_IFACE_XEN, NULL);
735 status = WdfDeviceAddQueryInterface(ChildDevice, &qiConfig);
736 if (!NT_SUCCESS(status)) {
737 return status;
738 }
740 RtlZeroMemory(&GntTblInterface, sizeof(GntTblInterface));
741 GntTblInterface.InterfaceHeader.Size = sizeof(GntTblInterface);
742 GntTblInterface.InterfaceHeader.Version = 1;
743 GntTblInterface.InterfaceHeader.Context = NULL;
744 GntTblInterface.InterfaceHeader.InterfaceReference = WdfDeviceInterfaceReferenceNoOp;
745 GntTblInterface.InterfaceHeader.InterfaceDereference = WdfDeviceInterfaceDereferenceNoOp;
746 GntTblInterface.GrantAccess = GntTbl_GrantAccess;
747 GntTblInterface.EndAccess = GntTbl_EndAccess;
748 WDF_QUERY_INTERFACE_CONFIG_INIT(&qiConfig, (PINTERFACE)&GntTblInterface, &GUID_XEN_IFACE_GNTTBL, NULL);
749 status = WdfDeviceAddQueryInterface(ChildDevice, &qiConfig);
750 if (!NT_SUCCESS(status)) {
751 return status;
752 }
754 RtlZeroMemory(&XenBusInterface, sizeof(XenBusInterface));
756 XenBusInterface.InterfaceHeader.Size = sizeof(XenBusInterface);
757 XenBusInterface.InterfaceHeader.Version = 1;
758 XenBusInterface.InterfaceHeader.Context = NULL;
759 //XenBusInterface.InterfaceHeader.Context = ExAllocatePoolWithTag(NonPagedPool, (strlen(XenIdentificationDesc->Path) + 1), XENPCI_POOL_TAG);
760 //strcpy(XenBusInterface.InterfaceHeader.Context, XenIdentificationDesc->Path);
761 XenBusInterface.Read = XenBus_Read;
762 XenBusInterface.Write = XenBus_Write;
763 XenBusInterface.Printf = XenBus_Printf;
764 XenBusInterface.StartTransaction = XenBus_StartTransaction;
765 XenBusInterface.EndTransaction = XenBus_EndTransaction;
766 XenBusInterface.List = XenBus_List;
767 XenBusInterface.AddWatch = XenBus_AddWatch;
768 XenBusInterface.RemWatch = XenBus_RemWatch;
769 WDF_QUERY_INTERFACE_CONFIG_INIT(&qiConfig, (PINTERFACE)&XenBusInterface, &GUID_XEN_IFACE_XENBUS, NULL);
770 status = WdfDeviceAddQueryInterface(ChildDevice, &qiConfig);
771 if (!NT_SUCCESS(status)) {
772 return status;
773 }
775 //KdPrint((__DRIVER_NAME " <-- ChildListCreateDevice\n"));
777 return status;
778 }
780 VOID
781 XenPCI_XenBusWatchHandler(char *Path, PVOID Data)
782 {
783 XENPCI_IDENTIFICATION_DESCRIPTION description;
784 NTSTATUS status;
785 char **Bits;
786 int Count;
787 WDFCHILDLIST ChildList;
788 WDF_CHILD_LIST_ITERATOR ChildIterator;
789 WDFDEVICE ChildDevice;
790 PXENPCI_XEN_DEVICE_DATA ChildDeviceData;
792 ANSI_STRING AnsiBuf;
794 UNREFERENCED_PARAMETER(Data);
796 KdPrint((__DRIVER_NAME " --> XenBusWatchHandle\n"));
798 //KdPrint((__DRIVER_NAME " %s\n", Path));
800 ChildList = WdfFdoGetDefaultChildList(Device);
802 Bits = SplitString(Path, '/', 3, &Count);
803 switch (Count)
804 {
805 case 0:
806 case 1:
807 break;
808 case 2:
809 // add or update the device node
810 WDF_CHILD_IDENTIFICATION_DESCRIPTION_HEADER_INIT(&description.Header, sizeof(description));
811 strncpy(description.Path, Path, 128);
812 RtlInitAnsiString(&AnsiBuf, Bits[1]);
813 //KdPrint((__DRIVER_NAME " Name = %s\n", Bits[1]));
814 RtlAnsiStringToUnicodeString(&description.DeviceType, &AnsiBuf, TRUE);
815 status = WdfChildListAddOrUpdateChildDescriptionAsPresent(ChildList, &description.Header, NULL);
816 break;
817 default:
818 WDF_CHILD_LIST_ITERATOR_INIT(&ChildIterator, WdfRetrievePresentChildren);
819 WdfChildListBeginIteration(ChildList, &ChildIterator);
820 while(NT_SUCCESS(WdfChildListRetrieveNextDevice(ChildList, &ChildIterator, &ChildDevice, NULL)))
821 {
822 ChildDeviceData = GetXenDeviceData(ChildDevice);
823 if (!ChildDeviceData)
824 continue;
825 if (strncmp(ChildDeviceData->BasePath, Path, strlen(ChildDeviceData->BasePath)) == 0 && Path[strlen(ChildDeviceData->BasePath)] == '/')
826 {
827 //KdPrint((__DRIVER_NAME " Child Path = %s (Match - WatchHandler = %08x)\n", ChildDeviceData->BasePath, ChildDeviceData->WatchHandler));
828 if (ChildDeviceData->WatchHandler != NULL)
829 ChildDeviceData->WatchHandler(Path, NULL);
830 }
831 else
832 {
833 //KdPrint((__DRIVER_NAME " Child Path = %s (No Match)\n", ChildDeviceData->BasePath));
834 }
835 }
836 WdfChildListEndIteration(ChildList, &ChildIterator);
837 break;
838 }
840 FreeSplitString(Bits, Count);
842 KdPrint((__DRIVER_NAME " <-- XenBusWatchHandle\n"));
843 }
845 static void
846 XenBus_ShutdownHandler(char *Path, PVOID Data)
847 {
848 char *value;
849 xenbus_transaction_t xbt;
850 int retry;
852 UNREFERENCED_PARAMETER(Path);
853 UNREFERENCED_PARAMETER(Data);
855 KdPrint((__DRIVER_NAME " --> XenBus_ShutdownHandler\n"));
857 XenBus_StartTransaction(&xbt);
859 XenBus_Read(XBT_NIL, SHUTDOWN_PATH, &value);
861 KdPrint((__DRIVER_NAME " Shutdown Value = %s\n", value));
863 // should check for error here... but why have we been called at all???
864 if (value != NULL && strlen(value) != 0)
865 XenBus_Write(XBT_NIL, SHUTDOWN_PATH, "");
867 XenBus_EndTransaction(xbt, 0, &retry);
869 KdPrint((__DRIVER_NAME " <-- XenBus_ShutdownHandler\n"));
870 }
872 static VOID
873 XenBus_BalloonHandler(char *Path, PVOID Data)
874 {
875 char *value;
876 xenbus_transaction_t xbt;
877 int retry;
879 UNREFERENCED_PARAMETER(Path);
880 UNREFERENCED_PARAMETER(Data);
882 KdPrint((__DRIVER_NAME " --> XenBus_BalloonHandler\n"));
884 XenBus_StartTransaction(&xbt);
886 XenBus_Read(XBT_NIL, BALLOON_PATH, &value);
888 KdPrint((__DRIVER_NAME " Balloon Value = %s\n", value));
890 // use the memory_op(unsigned int op, void *arg) hypercall to adjust this
891 // use XENMEM_increase_reservation and XENMEM_decrease_reservation
893 XenBus_EndTransaction(xbt, 0, &retry);
895 KdPrint((__DRIVER_NAME " <-- XenBus_BalloonHandler\n"));
896 }
898 /*
899 IO_RESOURCE_DESCRIPTOR MemoryDescriptor;
901 static NTSTATUS
902 XenPCI_FilterRemoveResourceRequirements(WDFDEVICE Device, WDFIORESREQLIST RequirementsList)
903 {
904 NTSTATUS status;
905 WDFIORESLIST ResourceList;
906 PIO_RESOURCE_DESCRIPTOR Descriptor;
908 int i, j;
909 int offset;
911 //KdPrint((__DRIVER_NAME " --> FilterRemoveResourceRequirements\n"));
913 for (i = 0; i < WdfIoResourceRequirementsListGetCount(RequirementsList); i++)
914 {
915 ResourceList = WdfIoResourceRequirementsListGetIoResList(RequirementsList, i);
916 //KdPrint((__DRIVER_NAME " Resource List %d\n", i));
917 //KdPrint((__DRIVER_NAME " %d resources in list\n", WdfIoResourceListGetCount(ResourceList)));
918 offset = 0;
919 for (j = 0; j < WdfIoResourceListGetCount(ResourceList); j++)
920 {
921 //KdPrint((__DRIVER_NAME " Resource %d\n", j));
922 Descriptor = WdfIoResourceListGetDescriptor(ResourceList, j - offset);
924 switch (Descriptor->Type) {
925 case CmResourceTypePort:
926 //KdPrint((__DRIVER_NAME " Port\n"));
927 break;
928 case CmResourceTypeMemory:
929 //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));
930 //KdPrint((__DRIVER_NAME " Length %08X\n", Descriptor->u.Memory.Length));
931 //KdPrint((__DRIVER_NAME " ShareDisposition %02X\n", Descriptor->ShareDisposition));
932 //KdPrint((__DRIVER_NAME " Option %02X\n", Descriptor->Option));
933 if (!Descriptor->Option || Descriptor->Option == IO_RESOURCE_PREFERRED) {
934 memcpy(&MemoryDescriptor, Descriptor, sizeof(IO_RESOURCE_DESCRIPTOR));
935 //platform_mmio_orig_len = MemoryDescriptor.u.Memory.Length;
936 //MemoryDescriptor.u.Memory.Length = PAGE_SIZE;
937 MemoryDescriptor.ShareDisposition = CmResourceShareShared;
938 }
939 WdfIoResourceListRemove(ResourceList, j - offset);
940 offset++;
941 break;
942 case CmResourceTypeInterrupt:
943 //KdPrint((__DRIVER_NAME " Interrupt\n"));
944 break;
945 case CmResourceTypeDevicePrivate:
946 //KdPrint((__DRIVER_NAME " Private\n"));
947 break;
948 default:
949 //KdPrint((__DRIVER_NAME " Unknown Type (0x%x)\n", Descriptor->Type));
950 break;
951 }
952 }
953 }
954 status = STATUS_SUCCESS;
956 KdPrint((__DRIVER_NAME " <-- FilterRemoveResourceRequirements\n"));
958 return status;
959 }
962 static NTSTATUS
963 XenPCI_FilterAddResourceRequirements(WDFDEVICE Device, WDFIORESREQLIST RequirementsList)
964 {
965 NTSTATUS status;
966 WDFIORESLIST ResourceList;
967 PIO_RESOURCE_DESCRIPTOR Descriptor;
969 int i, j;
971 KdPrint((__DRIVER_NAME " --> FilterAddResourceRequirements\n"));
974 for (i = 0; i < WdfIoResourceRequirementsListGetCount(RequirementsList); i++)
975 {
976 ResourceList = WdfIoResourceRequirementsListGetIoResList(RequirementsList, i);
977 //KdPrint((__DRIVER_NAME " Resource List %d\n", i));
978 //KdPrint((__DRIVER_NAME " %d resources in list\n", WdfIoResourceListGetCount(ResourceList)));
979 WdfIoResourceListAppendDescriptor(ResourceList, &MemoryDescriptor);
980 //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));
981 //KdPrint((__DRIVER_NAME " Length %08X\n", MemoryDescriptor.u.Memory.Length));
982 for (j = 0; j < WdfIoResourceListGetCount(ResourceList); j++)
983 {
984 //KdPrint((__DRIVER_NAME " Resource %d\n", j));
985 Descriptor = WdfIoResourceListGetDescriptor(ResourceList, j);
987 switch (Descriptor->Type) {
988 case CmResourceTypePort:
989 //KdPrint((__DRIVER_NAME " Port\n"));
990 break;
991 case CmResourceTypeMemory:
992 //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));
993 //KdPrint((__DRIVER_NAME " Length %08X\n", Descriptor->u.Memory.Length));
994 //KdPrint((__DRIVER_NAME " ShareDisposition %02X\n", Descriptor->ShareDisposition));
995 //Descriptor->ShareDisposition = CmResourceShareShared;
996 //memcpy(&MemoryDescriptor, Descriptor, sizeof(IO_RESOURCE_DESCRIPTOR));
997 //platform_mmio_orig_len = MemoryDescriptor.u.Memory.Length;
998 //MemoryDescriptor.u.Memory.Length = PAGE_SIZE;
999 //WdfIoResourceListRemove(ResourceList, j);
1000 break;
1001 case CmResourceTypeInterrupt:
1002 //KdPrint((__DRIVER_NAME " Interrupt\n"));
1003 break;
1004 case CmResourceTypeDevicePrivate:
1005 //KdPrint((__DRIVER_NAME " Private\n"));
1006 break;
1007 default:
1008 //KdPrint((__DRIVER_NAME " Unknown Type (0x%x)\n", Descriptor->Type));
1009 break;
1013 status = STATUS_SUCCESS;
1015 //KdPrint((__DRIVER_NAME " <-- FilterAddResourceRequirements\n"));
1017 return status;
1020 static NTSTATUS
1021 XenPCI_RemoveAddedResources(WDFDEVICE Device, WDFCMRESLIST ResourcesRaw, WDFCMRESLIST ResourcesTranslated)
1023 //KdPrint((__DRIVER_NAME " --> RemoveAddedResources\n"));
1024 //KdPrint((__DRIVER_NAME " <-- RemoveAddedResources\n"));
1026 return STATUS_SUCCESS;
1029 */
1031 static NTSTATUS
1032 XenPCI_DeviceResourceRequirementsQuery(WDFDEVICE Device, WDFIORESREQLIST IoResourceRequirementsList)
1034 NTSTATUS status;
1035 WDFIORESLIST resourceList;
1036 IO_RESOURCE_DESCRIPTOR descriptor;
1038 UNREFERENCED_PARAMETER(Device);
1040 //KdPrint((__DRIVER_NAME " --> DeviceResourceRequirementsQuery\n"));
1042 status = WdfIoResourceListCreate(IoResourceRequirementsList, WDF_NO_OBJECT_ATTRIBUTES, &resourceList);
1043 if (!NT_SUCCESS(status))
1044 return status;
1046 /*
1047 RtlZeroMemory(&descriptor, sizeof(descriptor));
1049 descriptor.Option = 0;
1050 descriptor.Type = CmResourceTypeInterrupt;
1051 descriptor.ShareDisposition = CmResourceShareDeviceExclusive;
1052 descriptor.Flags = CM_RESOURCE_MEMORY_READ_WRITE;
1053 descriptor.u.Interrupt.MinimumVector = 1024;
1054 descriptor.u.Interrupt.MaximumVector = 1024+255;
1056 //KdPrint((__DRIVER_NAME " MinimumVector = %d, MaximumVector = %d\n", descriptor.u.Interrupt.MinimumVector, descriptor.u.Interrupt.MaximumVector));
1058 status = WdfIoResourceListAppendDescriptor(resourceList, &descriptor);
1059 if (!NT_SUCCESS(status))
1060 return status;
1061 */
1063 RtlZeroMemory(&descriptor, sizeof(descriptor));
1065 descriptor.Option = 0;
1066 descriptor.Type = CmResourceTypeMemory;
1067 descriptor.ShareDisposition = CmResourceShareShared; //CmResourceShareDeviceExclusive;
1068 descriptor.Flags = CM_RESOURCE_MEMORY_READ_WRITE;
1069 descriptor.u.Memory.Length = PAGE_SIZE;
1070 descriptor.u.Memory.Alignment = PAGE_SIZE;
1071 descriptor.u.Memory.MinimumAddress.QuadPart = platform_mmio_addr.QuadPart + PAGE_SIZE;
1072 descriptor.u.Memory.MaximumAddress.QuadPart = platform_mmio_addr.QuadPart + platform_mmio_len - 1;
1074 //KdPrint((__DRIVER_NAME " MinimumAddress = %08x, MaximumAddress = %08X\n", descriptor.u.Memory.MinimumAddress.LowPart, descriptor.u.Memory.MaximumAddress.LowPart));
1076 status = WdfIoResourceListAppendDescriptor(resourceList, &descriptor);
1077 if (!NT_SUCCESS(status))
1078 return status;
1080 status = WdfIoResourceRequirementsListAppendIoResList(IoResourceRequirementsList, resourceList);
1081 if (!NT_SUCCESS(status))
1082 return status;
1084 //KdPrint((__DRIVER_NAME " <-- DeviceResourceRequirementsQuery\n"));
1086 return status;