9 #include <acpi_drivers.h>
18 #pragma alloc_text (PAGE, Bus_PDO_PnP)
19 #pragma alloc_text (PAGE, Bus_PDO_QueryDeviceCaps)
20 #pragma alloc_text (PAGE, Bus_PDO_QueryDeviceId)
21 #pragma alloc_text (PAGE, Bus_PDO_QueryDeviceText)
22 #pragma alloc_text (PAGE, Bus_PDO_QueryResources)
23 #pragma alloc_text (PAGE, Bus_PDO_QueryResourceRequirements)
24 #pragma alloc_text (PAGE, Bus_PDO_QueryDeviceRelations)
25 #pragma alloc_text (PAGE, Bus_PDO_QueryBusInformation)
26 #pragma alloc_text (PAGE, Bus_GetDeviceCapabilities)
31 PDEVICE_OBJECT DeviceObject
,
33 PIO_STACK_LOCATION IrpStack
,
34 PPDO_DEVICE_DATA DeviceData
39 struct acpi_device
*device
= NULL
;
43 if (DeviceData
->AcpiHandle
)
44 acpi_bus_get_device(DeviceData
->AcpiHandle
, &device
);
47 // NB: Because we are a bus enumerator, we have no one to whom we could
48 // defer these irps. Therefore we do not pass them down but merely
52 switch (IrpStack
->MinorFunction
) {
54 case IRP_MN_START_DEVICE
:
56 // Here we do what ever initialization and ``turning on'' that is
57 // required to allow others to access this device.
58 // Power up the device.
60 if (DeviceData
->AcpiHandle
&& acpi_bus_power_manageable(DeviceData
->AcpiHandle
) &&
61 !ACPI_SUCCESS(acpi_bus_set_power(DeviceData
->AcpiHandle
, ACPI_STATE_D0
)))
63 DPRINT1("Device %x failed to start!\n", DeviceData
->AcpiHandle
);
64 status
= STATUS_UNSUCCESSFUL
;
68 DeviceData
->InterfaceName
.Length
= 0;
72 IoRegisterDeviceInterface(DeviceData
->Common
.Self
,
73 &GUID_DEVICE_SYS_BUTTON
,
75 &DeviceData
->InterfaceName
);
77 else if (device
->flags
.hardware_id
&&
78 strstr(device
->pnp
.hardware_id
, ACPI_THERMAL_HID
))
80 IoRegisterDeviceInterface(DeviceData
->Common
.Self
,
81 &GUID_DEVICE_THERMAL_ZONE
,
83 &DeviceData
->InterfaceName
);
85 else if (device
->flags
.hardware_id
&&
86 strstr(device
->pnp
.hardware_id
, ACPI_BUTTON_HID_LID
))
88 IoRegisterDeviceInterface(DeviceData
->Common
.Self
,
91 &DeviceData
->InterfaceName
);
93 else if (device
->flags
.hardware_id
&&
94 strstr(device
->pnp
.hardware_id
, ACPI_PROCESSOR_HID
))
96 IoRegisterDeviceInterface(DeviceData
->Common
.Self
,
97 &GUID_DEVICE_PROCESSOR
,
99 &DeviceData
->InterfaceName
);
102 if (DeviceData
->InterfaceName
.Length
!= 0)
103 IoSetDeviceInterfaceState(&DeviceData
->InterfaceName
, TRUE
);
105 state
.DeviceState
= PowerDeviceD0
;
106 PoSetPowerState(DeviceData
->Common
.Self
, DevicePowerState
, state
);
107 DeviceData
->Common
.DevicePowerState
= PowerDeviceD0
;
108 SET_NEW_PNP_STATE(DeviceData
->Common
, Started
);
109 status
= STATUS_SUCCESS
;
112 case IRP_MN_STOP_DEVICE
:
114 if (DeviceData
->InterfaceName
.Length
!= 0)
115 IoSetDeviceInterfaceState(&DeviceData
->InterfaceName
, FALSE
);
118 // Here we shut down the device and give up and unmap any resources
119 // we acquired for the device.
121 if (DeviceData
->AcpiHandle
&& acpi_bus_power_manageable(DeviceData
->AcpiHandle
) &&
122 !ACPI_SUCCESS(acpi_bus_set_power(DeviceData
->AcpiHandle
, ACPI_STATE_D3
)))
124 DPRINT1("Device %x failed to stop!\n", DeviceData
->AcpiHandle
);
125 status
= STATUS_UNSUCCESSFUL
;
129 state
.DeviceState
= PowerDeviceD3
;
130 PoSetPowerState(DeviceData
->Common
.Self
, DevicePowerState
, state
);
131 DeviceData
->Common
.DevicePowerState
= PowerDeviceD3
;
132 SET_NEW_PNP_STATE(DeviceData
->Common
, Stopped
);
133 status
= STATUS_SUCCESS
;
137 case IRP_MN_QUERY_STOP_DEVICE
:
140 // No reason here why we can't stop the device.
141 // If there were a reason we should speak now, because answering success
142 // here may result in a stop device irp.
145 SET_NEW_PNP_STATE(DeviceData
->Common
, StopPending
);
146 status
= STATUS_SUCCESS
;
149 case IRP_MN_CANCEL_STOP_DEVICE
:
152 // The stop was canceled. Whatever state we set, or resources we put
153 // on hold in anticipation of the forthcoming STOP device IRP should be
154 // put back to normal. Someone, in the long list of concerned parties,
155 // has failed the stop device query.
159 // First check to see whether you have received cancel-stop
160 // without first receiving a query-stop. This could happen if someone
161 // above us fails a query-stop and passes down the subsequent
165 if (StopPending
== DeviceData
->Common
.DevicePnPState
)
168 // We did receive a query-stop, so restore.
170 RESTORE_PREVIOUS_PNP_STATE(DeviceData
->Common
);
172 status
= STATUS_SUCCESS
;// We must not fail this IRP.
174 case IRP_MN_QUERY_CAPABILITIES
:
177 // Return the capabilities of a device, such as whether the device
178 // can be locked or ejected..etc
181 status
= Bus_PDO_QueryDeviceCaps(DeviceData
, Irp
);
185 case IRP_MN_QUERY_ID
:
187 // Query the IDs of the device
188 status
= Bus_PDO_QueryDeviceId(DeviceData
, Irp
);
192 case IRP_MN_QUERY_DEVICE_RELATIONS
:
194 DPRINT("\tQueryDeviceRelation Type: %s\n",DbgDeviceRelationString(\
195 IrpStack
->Parameters
.QueryDeviceRelations
.Type
));
197 status
= Bus_PDO_QueryDeviceRelations(DeviceData
, Irp
);
201 case IRP_MN_QUERY_DEVICE_TEXT
:
203 status
= Bus_PDO_QueryDeviceText(DeviceData
, Irp
);
207 case IRP_MN_QUERY_RESOURCES
:
209 status
= Bus_PDO_QueryResources(DeviceData
, Irp
);
213 case IRP_MN_QUERY_RESOURCE_REQUIREMENTS
:
215 status
= Bus_PDO_QueryResourceRequirements(DeviceData
, Irp
);
219 case IRP_MN_QUERY_BUS_INFORMATION
:
221 status
= Bus_PDO_QueryBusInformation(DeviceData
, Irp
);
225 case IRP_MN_QUERY_INTERFACE
:
227 status
= Bus_PDO_QueryInterface(DeviceData
, Irp
);
232 case IRP_MN_FILTER_RESOURCE_REQUIREMENTS
:
235 // OPTIONAL for bus drivers.
236 // The PnP Manager sends this IRP to a device
237 // stack so filter and function drivers can adjust the
238 // resources required by the device, if appropriate.
243 //case IRP_MN_QUERY_PNP_DEVICE_STATE:
246 // OPTIONAL for bus drivers.
247 // The PnP Manager sends this IRP after the drivers for
248 // a device return success from the IRP_MN_START_DEVICE
249 // request. The PnP Manager also sends this IRP when a
250 // driver for the device calls IoInvalidateDeviceState.
255 //case IRP_MN_READ_CONFIG:
256 //case IRP_MN_WRITE_CONFIG:
259 // Bus drivers for buses with configuration space must handle
260 // this request for their child devices. Our devices don't
261 // have a config space.
266 //case IRP_MN_SET_LOCK:
273 // For PnP requests to the PDO that we do not understand we should
274 // return the IRP WITHOUT setting the status or information fields.
275 // These fields may have already been set by a filter (eg acpi).
276 status
= Irp
->IoStatus
.Status
;
281 Irp
->IoStatus
.Status
= status
;
282 IoCompleteRequest (Irp
, IO_NO_INCREMENT
);
288 Bus_PDO_QueryDeviceCaps(
289 PPDO_DEVICE_DATA DeviceData
,
293 PIO_STACK_LOCATION stack
;
294 PDEVICE_CAPABILITIES deviceCapabilities
;
295 struct acpi_device
*device
= NULL
;
300 if (DeviceData
->AcpiHandle
)
301 acpi_bus_get_device(DeviceData
->AcpiHandle
, &device
);
303 stack
= IoGetCurrentIrpStackLocation (Irp
);
308 deviceCapabilities
=stack
->Parameters
.DeviceCapabilities
.Capabilities
;
311 // Set the capabilities.
314 if (deviceCapabilities
->Version
!= 1 ||
315 deviceCapabilities
->Size
< sizeof(DEVICE_CAPABILITIES
))
317 return STATUS_UNSUCCESSFUL
;
320 deviceCapabilities
->D1Latency
= 0;
321 deviceCapabilities
->D2Latency
= 0;
322 deviceCapabilities
->D3Latency
= 0;
324 deviceCapabilities
->DeviceState
[PowerSystemWorking
] = PowerDeviceD0
;
325 deviceCapabilities
->DeviceState
[PowerSystemSleeping1
] = PowerDeviceD3
;
326 deviceCapabilities
->DeviceState
[PowerSystemSleeping2
] = PowerDeviceD3
;
327 deviceCapabilities
->DeviceState
[PowerSystemSleeping3
] = PowerDeviceD3
;
329 for (i
= 0; i
< ACPI_D_STATE_COUNT
&& device
; i
++)
331 if (!device
->power
.states
[i
].flags
.valid
)
337 deviceCapabilities
->DeviceState
[PowerSystemWorking
] = PowerDeviceD0
;
341 deviceCapabilities
->DeviceState
[PowerSystemSleeping1
] = PowerDeviceD1
;
342 deviceCapabilities
->D1Latency
= device
->power
.states
[i
].latency
;
346 deviceCapabilities
->DeviceState
[PowerSystemSleeping2
] = PowerDeviceD2
;
347 deviceCapabilities
->D2Latency
= device
->power
.states
[i
].latency
;
351 deviceCapabilities
->DeviceState
[PowerSystemSleeping3
] = PowerDeviceD3
;
352 deviceCapabilities
->D3Latency
= device
->power
.states
[i
].latency
;
357 // We can wake the system from D1
358 deviceCapabilities
->DeviceWake
= PowerDeviceD1
;
361 deviceCapabilities
->DeviceD1
=
362 (deviceCapabilities
->DeviceState
[PowerSystemSleeping1
] == PowerDeviceD1
) ? TRUE
: FALSE
;
363 deviceCapabilities
->DeviceD2
=
364 (deviceCapabilities
->DeviceState
[PowerSystemSleeping2
] == PowerDeviceD2
) ? TRUE
: FALSE
;
366 deviceCapabilities
->WakeFromD0
= FALSE
;
367 deviceCapabilities
->WakeFromD1
= TRUE
; //Yes we can
368 deviceCapabilities
->WakeFromD2
= FALSE
;
369 deviceCapabilities
->WakeFromD3
= FALSE
;
373 deviceCapabilities
->EjectSupported
= device
->flags
.ejectable
;
374 deviceCapabilities
->HardwareDisabled
= !device
->status
.enabled
;
375 deviceCapabilities
->Removable
= device
->flags
.removable
;
376 deviceCapabilities
->SurpriseRemovalOK
= device
->flags
.suprise_removal_ok
;
377 deviceCapabilities
->UniqueID
= device
->flags
.unique_id
;
378 deviceCapabilities
->NoDisplayInUI
= !device
->status
.show_in_ui
;
379 deviceCapabilities
->Address
= device
->pnp
.bus_address
;
383 (device
->flags
.hardware_id
&&
384 (strstr(device
->pnp
.hardware_id
, ACPI_BUTTON_HID_LID
) ||
385 strstr(device
->pnp
.hardware_id
, ACPI_THERMAL_HID
) ||
386 strstr(device
->pnp
.hardware_id
, ACPI_PROCESSOR_HID
))))
388 /* Allow ACPI to control the device if it is a lid button,
389 * a thermal zone, a processor, or a fixed feature button */
390 deviceCapabilities
->RawDeviceOK
= TRUE
;
393 deviceCapabilities
->SilentInstall
= FALSE
;
394 deviceCapabilities
->UINumber
= (ULONG
)-1;
396 return STATUS_SUCCESS
;
401 Bus_PDO_QueryDeviceId(
402 PPDO_DEVICE_DATA DeviceData
,
405 PIO_STACK_LOCATION stack
;
409 NTSTATUS status
= STATUS_SUCCESS
;
410 struct acpi_device
*Device
;
414 stack
= IoGetCurrentIrpStackLocation (Irp
);
416 switch (stack
->Parameters
.QueryId
.IdType
) {
418 case BusQueryDeviceID
:
419 if (DeviceData
->AcpiHandle
)
421 acpi_bus_get_device(DeviceData
->AcpiHandle
, &Device
);
423 length
= swprintf(temp
,
425 Device
->pnp
.hardware_id
);
429 /* We know it's a fixed feature button because
430 * these are direct children of the ACPI root device
431 * and therefore have no handle
433 length
= swprintf(temp
,
434 L
"ACPI\\FixedButton");
437 temp
[++length
] = UNICODE_NULL
;
439 buffer
= ExAllocatePoolWithTag (PagedPool
, length
* sizeof(WCHAR
), 'IPCA');
442 status
= STATUS_INSUFFICIENT_RESOURCES
;
446 RtlCopyMemory (buffer
, temp
, length
* sizeof(WCHAR
));
447 Irp
->IoStatus
.Information
= (ULONG_PTR
) buffer
;
448 DPRINT("BusQueryDeviceID: %ls\n",buffer
);
451 case BusQueryInstanceID
:
452 /* See comment in BusQueryDeviceID case */
453 if(DeviceData
->AcpiHandle
)
455 acpi_bus_get_device(DeviceData
->AcpiHandle
, &Device
);
457 if (Device
->flags
.unique_id
)
458 length
= swprintf(temp
,
460 Device
->pnp
.unique_id
);
462 /* FIXME: Generate unique id! */
463 length
= swprintf(temp
, L
"%ls", L
"0000");
466 /* FIXME: Generate unique id! */
467 length
= swprintf(temp
, L
"%ls", L
"0000");
469 temp
[++length
] = UNICODE_NULL
;
471 buffer
= ExAllocatePoolWithTag (PagedPool
, length
* sizeof (WCHAR
), 'IPCA');
473 status
= STATUS_INSUFFICIENT_RESOURCES
;
477 RtlCopyMemory (buffer
, temp
, length
* sizeof (WCHAR
));
478 DPRINT("BusQueryInstanceID: %ls\n",buffer
);
479 Irp
->IoStatus
.Information
= (ULONG_PTR
) buffer
;
482 case BusQueryHardwareIDs
:
485 /* See comment in BusQueryDeviceID case */
486 if (DeviceData
->AcpiHandle
)
488 acpi_bus_get_device(DeviceData
->AcpiHandle
, &Device
);
490 length
+= swprintf(&temp
[length
],
492 Device
->pnp
.hardware_id
);
495 length
+= swprintf(&temp
[length
],
497 Device
->pnp
.hardware_id
);
502 length
+= swprintf(&temp
[length
],
503 L
"ACPI\\FixedButton");
506 length
+= swprintf(&temp
[length
],
511 temp
[length
] = UNICODE_NULL
;
515 temp
[length
] = UNICODE_NULL
;
517 buffer
= ExAllocatePoolWithTag (PagedPool
, length
* sizeof(WCHAR
), 'IPCA');
520 status
= STATUS_INSUFFICIENT_RESOURCES
;
524 RtlCopyMemory (buffer
, temp
, length
* sizeof(WCHAR
));
525 Irp
->IoStatus
.Information
= (ULONG_PTR
) buffer
;
526 DPRINT("BusQueryHardwareIDs: %ls\n",buffer
);
530 status
= Irp
->IoStatus
.Status
;
536 Bus_PDO_QueryDeviceText(
537 PPDO_DEVICE_DATA DeviceData
,
541 PIO_STACK_LOCATION stack
;
545 stack
= IoGetCurrentIrpStackLocation (Irp
);
547 switch (stack
->Parameters
.QueryDeviceText
.DeviceTextType
) {
549 case DeviceTextDescription
:
551 if (!Irp
->IoStatus
.Information
) {
552 if (wcsstr (DeviceData
->HardwareIDs
, L
"PNP000") != 0)
553 Buffer
= L
"Programmable interrupt controller";
554 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNP010") != 0)
555 Buffer
= L
"System timer";
556 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNP020") != 0)
557 Buffer
= L
"DMA controller";
558 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNP03") != 0)
559 Buffer
= L
"Keyboard";
560 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNP040") != 0)
561 Buffer
= L
"Parallel port";
562 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNP05") != 0)
563 Buffer
= L
"Serial port";
564 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNP06") != 0)
565 Buffer
= L
"Disk controller";
566 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNP07") != 0)
567 Buffer
= L
"Disk controller";
568 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNP09") != 0)
569 Buffer
= L
"Display adapter";
570 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNP0A0") != 0)
571 Buffer
= L
"Bus controller";
572 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNP0E0") != 0)
573 Buffer
= L
"PCMCIA controller";
574 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNP0F") != 0)
575 Buffer
= L
"Mouse device";
576 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNP8") != 0)
577 Buffer
= L
"Network adapter";
578 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNPA0") != 0)
579 Buffer
= L
"SCSI controller";
580 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNPB0") != 0)
581 Buffer
= L
"Multimedia device";
582 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNPC00") != 0)
584 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNP0C0C") != 0)
585 Buffer
= L
"Power Button";
586 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNP0C0E") != 0)
587 Buffer
= L
"Sleep Button";
588 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNP0C0D") != 0)
589 Buffer
= L
"Lid Switch";
590 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNP0C09") != 0)
591 Buffer
= L
"ACPI Embedded Controller";
592 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNP0C0B") != 0)
593 Buffer
= L
"ACPI Fan";
594 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNP0A03") != 0)
595 Buffer
= L
"PCI Root Bridge";
596 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNP0C0A") != 0)
597 Buffer
= L
"ACPI Battery";
598 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNP0C0F") != 0)
599 Buffer
= L
"PCI Interrupt Link";
600 else if (wcsstr(DeviceData
->HardwareIDs
, L
"ACPI_PWR") != 0)
601 Buffer
= L
"ACPI Power Resource";
602 else if (wcsstr(DeviceData
->HardwareIDs
, L
"Processor") != 0)
603 Buffer
= L
"Processor";
604 else if (wcsstr(DeviceData
->HardwareIDs
, L
"ThermalZone") != 0)
605 Buffer
= L
"ACPI Thermal Zone";
606 else if (wcsstr(DeviceData
->HardwareIDs
, L
"ACPI0002") != 0)
607 Buffer
= L
"Smart Battery";
608 else if (wcsstr(DeviceData
->HardwareIDs
, L
"ACPI0003") != 0)
609 Buffer
= L
"AC Adapter";
610 /* Simply checking if AcpiHandle is NULL eliminates the need to check
611 * for the 4 different names that ACPI knows the fixed feature button as internally
613 else if (!DeviceData
->AcpiHandle
)
614 Buffer
= L
"ACPI Fixed Feature Button";
616 Buffer
= L
"Other ACPI device";
618 DPRINT("\tDeviceTextDescription :%ws\n", Buffer
);
620 Irp
->IoStatus
.Information
= (ULONG_PTR
) Buffer
;
622 status
= STATUS_SUCCESS
;
626 status
= Irp
->IoStatus
.Status
;
635 Bus_PDO_QueryResources(
636 PPDO_DEVICE_DATA DeviceData
,
639 ULONG NumberOfResources
= 0;
640 PCM_RESOURCE_LIST ResourceList
;
641 PCM_PARTIAL_RESOURCE_DESCRIPTOR ResourceDescriptor
;
642 ACPI_STATUS AcpiStatus
;
644 ACPI_RESOURCE
* resource
;
645 ULONG ResourceListSize
;
648 /* Get current resources */
650 AcpiStatus
= AcpiGetCurrentResources(DeviceData
->AcpiHandle
, &Buffer
);
651 if ((!ACPI_SUCCESS(AcpiStatus
) && AcpiStatus
!= AE_BUFFER_OVERFLOW
) ||
654 return Irp
->IoStatus
.Status
;
657 Buffer
.Pointer
= ExAllocatePool(PagedPool
, Buffer
.Length
);
659 return STATUS_INSUFFICIENT_RESOURCES
;
661 AcpiStatus
= AcpiGetCurrentResources(DeviceData
->AcpiHandle
, &Buffer
);
662 if (!ACPI_SUCCESS(AcpiStatus
))
664 DPRINT1("AcpiGetCurrentResources #2 failed (0x%x)\n", AcpiStatus
);
666 return STATUS_UNSUCCESSFUL
;
669 resource
= Buffer
.Pointer
;
670 /* Count number of resources */
671 while (resource
->Type
!= ACPI_RESOURCE_TYPE_END_TAG
)
673 switch (resource
->Type
)
675 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ
:
677 ACPI_RESOURCE_EXTENDED_IRQ
*irq_data
= (ACPI_RESOURCE_EXTENDED_IRQ
*) &resource
->Data
;
678 NumberOfResources
+= irq_data
->InterruptCount
;
681 case ACPI_RESOURCE_TYPE_IRQ
:
683 ACPI_RESOURCE_IRQ
*irq_data
= (ACPI_RESOURCE_IRQ
*) &resource
->Data
;
684 NumberOfResources
+= irq_data
->InterruptCount
;
687 case ACPI_RESOURCE_TYPE_DMA
:
689 ACPI_RESOURCE_DMA
*dma_data
= (ACPI_RESOURCE_DMA
*) &resource
->Data
;
690 NumberOfResources
+= dma_data
->ChannelCount
;
693 case ACPI_RESOURCE_TYPE_ADDRESS16
:
694 case ACPI_RESOURCE_TYPE_ADDRESS32
:
695 case ACPI_RESOURCE_TYPE_ADDRESS64
:
696 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64
:
697 case ACPI_RESOURCE_TYPE_MEMORY24
:
698 case ACPI_RESOURCE_TYPE_MEMORY32
:
699 case ACPI_RESOURCE_TYPE_IO
:
706 DPRINT1("Unknown resource type: %d\n", resource
->Type
);
710 resource
= ACPI_NEXT_RESOURCE(resource
);
713 /* Allocate memory */
714 ResourceListSize
= sizeof(CM_RESOURCE_LIST
) + sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR
) * (NumberOfResources
- 1);
715 ResourceList
= (PCM_RESOURCE_LIST
)ExAllocatePool(PagedPool
, ResourceListSize
);
719 ExFreePool(Buffer
.Pointer
);
720 return STATUS_INSUFFICIENT_RESOURCES
;
722 ResourceList
->Count
= 1;
723 ResourceList
->List
[0].InterfaceType
= Internal
; /* FIXME */
724 ResourceList
->List
[0].BusNumber
= 0; /* We're the only ACPI bus device in the system */
725 ResourceList
->List
[0].PartialResourceList
.Version
= 1;
726 ResourceList
->List
[0].PartialResourceList
.Revision
= 1;
727 ResourceList
->List
[0].PartialResourceList
.Count
= NumberOfResources
;
728 ResourceDescriptor
= ResourceList
->List
[0].PartialResourceList
.PartialDescriptors
;
730 /* Fill resources list structure */
731 resource
= Buffer
.Pointer
;
732 while (resource
->Type
!= ACPI_RESOURCE_TYPE_END_TAG
)
734 switch (resource
->Type
)
736 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ
:
738 ACPI_RESOURCE_EXTENDED_IRQ
*irq_data
= (ACPI_RESOURCE_EXTENDED_IRQ
*) &resource
->Data
;
739 for (i
= 0; i
< irq_data
->InterruptCount
; i
++)
741 ResourceDescriptor
->Type
= CmResourceTypeInterrupt
;
743 ResourceDescriptor
->ShareDisposition
=
744 (irq_data
->Sharable
== ACPI_SHARED
? CmResourceShareShared
: CmResourceShareDeviceExclusive
);
745 ResourceDescriptor
->Flags
=
746 (irq_data
->Triggering
== ACPI_LEVEL_SENSITIVE
? CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE
: CM_RESOURCE_INTERRUPT_LATCHED
);
747 ResourceDescriptor
->u
.Interrupt
.Level
= irq_data
->Interrupts
[i
];
748 ResourceDescriptor
->u
.Interrupt
.Vector
= 0;
749 ResourceDescriptor
->u
.Interrupt
.Affinity
= (KAFFINITY
)(-1);
751 ResourceDescriptor
++;
755 case ACPI_RESOURCE_TYPE_IRQ
:
757 ACPI_RESOURCE_IRQ
*irq_data
= (ACPI_RESOURCE_IRQ
*) &resource
->Data
;
758 for (i
= 0; i
< irq_data
->InterruptCount
; i
++)
760 ResourceDescriptor
->Type
= CmResourceTypeInterrupt
;
762 ResourceDescriptor
->ShareDisposition
=
763 (irq_data
->Sharable
== ACPI_SHARED
? CmResourceShareShared
: CmResourceShareDeviceExclusive
);
764 ResourceDescriptor
->Flags
=
765 (irq_data
->Triggering
== ACPI_LEVEL_SENSITIVE
? CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE
: CM_RESOURCE_INTERRUPT_LATCHED
);
766 ResourceDescriptor
->u
.Interrupt
.Level
= irq_data
->Interrupts
[i
];
767 ResourceDescriptor
->u
.Interrupt
.Vector
= 0;
768 ResourceDescriptor
->u
.Interrupt
.Affinity
= (KAFFINITY
)(-1);
770 ResourceDescriptor
++;
774 case ACPI_RESOURCE_TYPE_DMA
:
776 ACPI_RESOURCE_DMA
*dma_data
= (ACPI_RESOURCE_DMA
*) &resource
->Data
;
777 for (i
= 0; i
< dma_data
->ChannelCount
; i
++)
779 ResourceDescriptor
->Type
= CmResourceTypeDma
;
780 ResourceDescriptor
->Flags
= 0;
781 switch (dma_data
->Type
)
783 case ACPI_TYPE_A
: ResourceDescriptor
->Flags
|= CM_RESOURCE_DMA_TYPE_A
; break;
784 case ACPI_TYPE_B
: ResourceDescriptor
->Flags
|= CM_RESOURCE_DMA_TYPE_B
; break;
785 case ACPI_TYPE_F
: ResourceDescriptor
->Flags
|= CM_RESOURCE_DMA_TYPE_F
; break;
787 if (dma_data
->BusMaster
== ACPI_BUS_MASTER
)
788 ResourceDescriptor
->Flags
|= CM_RESOURCE_DMA_BUS_MASTER
;
789 switch (dma_data
->Transfer
)
791 case ACPI_TRANSFER_8
: ResourceDescriptor
->Flags
|= CM_RESOURCE_DMA_8
; break;
792 case ACPI_TRANSFER_16
: ResourceDescriptor
->Flags
|= CM_RESOURCE_DMA_16
; break;
793 case ACPI_TRANSFER_8_16
: ResourceDescriptor
->Flags
|= CM_RESOURCE_DMA_8_AND_16
; break;
795 ResourceDescriptor
->u
.Dma
.Channel
= dma_data
->Channels
[i
];
797 ResourceDescriptor
++;
801 case ACPI_RESOURCE_TYPE_IO
:
803 ACPI_RESOURCE_IO
*io_data
= (ACPI_RESOURCE_IO
*) &resource
->Data
;
804 ResourceDescriptor
->Type
= CmResourceTypePort
;
805 ResourceDescriptor
->ShareDisposition
= CmResourceShareDriverExclusive
;
806 ResourceDescriptor
->Flags
= CM_RESOURCE_PORT_IO
;
807 if (io_data
->IoDecode
== ACPI_DECODE_16
)
808 ResourceDescriptor
->Flags
|= CM_RESOURCE_PORT_16_BIT_DECODE
;
810 ResourceDescriptor
->Flags
|= CM_RESOURCE_PORT_10_BIT_DECODE
;
811 ResourceDescriptor
->u
.Port
.Start
.QuadPart
= io_data
->Minimum
;
812 ResourceDescriptor
->u
.Port
.Length
= io_data
->AddressLength
;
814 ResourceDescriptor
++;
817 case ACPI_RESOURCE_TYPE_ADDRESS16
:
819 ACPI_RESOURCE_ADDRESS16
*addr16_data
= (ACPI_RESOURCE_ADDRESS16
*) &resource
->Data
;
820 if (addr16_data
->ResourceType
== ACPI_BUS_NUMBER_RANGE
)
822 ResourceDescriptor
->Type
= CmResourceTypeBusNumber
;
823 ResourceDescriptor
->ShareDisposition
= CmResourceShareShared
;
824 ResourceDescriptor
->Flags
= 0;
825 ResourceDescriptor
->u
.BusNumber
.Start
= addr16_data
->Minimum
;
826 ResourceDescriptor
->u
.BusNumber
.Length
= addr16_data
->AddressLength
;
828 else if (addr16_data
->ResourceType
== ACPI_IO_RANGE
)
830 ResourceDescriptor
->Type
= CmResourceTypePort
;
831 ResourceDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
832 ResourceDescriptor
->Flags
= CM_RESOURCE_PORT_IO
;
833 if (addr16_data
->Decode
== ACPI_POS_DECODE
)
834 ResourceDescriptor
->Flags
|= CM_RESOURCE_PORT_POSITIVE_DECODE
;
835 ResourceDescriptor
->u
.Port
.Start
.QuadPart
= addr16_data
->Minimum
;
836 ResourceDescriptor
->u
.Port
.Length
= addr16_data
->AddressLength
;
840 ResourceDescriptor
->Type
= CmResourceTypeMemory
;
841 ResourceDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
842 ResourceDescriptor
->Flags
= 0;
843 if (addr16_data
->Info
.Mem
.WriteProtect
== ACPI_READ_ONLY_MEMORY
)
844 ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_ONLY
;
846 ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_WRITE
;
847 switch (addr16_data
->Info
.Mem
.Caching
)
849 case ACPI_CACHABLE_MEMORY
: ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_CACHEABLE
; break;
850 case ACPI_WRITE_COMBINING_MEMORY
: ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_COMBINEDWRITE
; break;
851 case ACPI_PREFETCHABLE_MEMORY
: ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_PREFETCHABLE
; break;
853 ResourceDescriptor
->u
.Memory
.Start
.QuadPart
= addr16_data
->Minimum
;
854 ResourceDescriptor
->u
.Memory
.Length
= addr16_data
->AddressLength
;
856 ResourceDescriptor
++;
859 case ACPI_RESOURCE_TYPE_ADDRESS32
:
861 ACPI_RESOURCE_ADDRESS32
*addr32_data
= (ACPI_RESOURCE_ADDRESS32
*) &resource
->Data
;
862 if (addr32_data
->ResourceType
== ACPI_BUS_NUMBER_RANGE
)
864 ResourceDescriptor
->Type
= CmResourceTypeBusNumber
;
865 ResourceDescriptor
->ShareDisposition
= CmResourceShareShared
;
866 ResourceDescriptor
->Flags
= 0;
867 ResourceDescriptor
->u
.BusNumber
.Start
= addr32_data
->Minimum
;
868 ResourceDescriptor
->u
.BusNumber
.Length
= addr32_data
->AddressLength
;
870 else if (addr32_data
->ResourceType
== ACPI_IO_RANGE
)
872 ResourceDescriptor
->Type
= CmResourceTypePort
;
873 ResourceDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
874 ResourceDescriptor
->Flags
= CM_RESOURCE_PORT_IO
;
875 if (addr32_data
->Decode
== ACPI_POS_DECODE
)
876 ResourceDescriptor
->Flags
|= CM_RESOURCE_PORT_POSITIVE_DECODE
;
877 ResourceDescriptor
->u
.Port
.Start
.QuadPart
= addr32_data
->Minimum
;
878 ResourceDescriptor
->u
.Port
.Length
= addr32_data
->AddressLength
;
882 ResourceDescriptor
->Type
= CmResourceTypeMemory
;
883 ResourceDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
884 ResourceDescriptor
->Flags
= 0;
885 if (addr32_data
->Info
.Mem
.WriteProtect
== ACPI_READ_ONLY_MEMORY
)
886 ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_ONLY
;
888 ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_WRITE
;
889 switch (addr32_data
->Info
.Mem
.Caching
)
891 case ACPI_CACHABLE_MEMORY
: ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_CACHEABLE
; break;
892 case ACPI_WRITE_COMBINING_MEMORY
: ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_COMBINEDWRITE
; break;
893 case ACPI_PREFETCHABLE_MEMORY
: ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_PREFETCHABLE
; break;
895 ResourceDescriptor
->u
.Memory
.Start
.QuadPart
= addr32_data
->Minimum
;
896 ResourceDescriptor
->u
.Memory
.Length
= addr32_data
->AddressLength
;
898 ResourceDescriptor
++;
901 case ACPI_RESOURCE_TYPE_ADDRESS64
:
903 ACPI_RESOURCE_ADDRESS64
*addr64_data
= (ACPI_RESOURCE_ADDRESS64
*) &resource
->Data
;
904 if (addr64_data
->ResourceType
== ACPI_BUS_NUMBER_RANGE
)
906 DPRINT1("64-bit bus address is not supported!\n");
907 ResourceDescriptor
->Type
= CmResourceTypeBusNumber
;
908 ResourceDescriptor
->ShareDisposition
= CmResourceShareShared
;
909 ResourceDescriptor
->Flags
= 0;
910 ResourceDescriptor
->u
.BusNumber
.Start
= (ULONG
)addr64_data
->Minimum
;
911 ResourceDescriptor
->u
.BusNumber
.Length
= addr64_data
->AddressLength
;
913 else if (addr64_data
->ResourceType
== ACPI_IO_RANGE
)
915 ResourceDescriptor
->Type
= CmResourceTypePort
;
916 ResourceDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
917 ResourceDescriptor
->Flags
= CM_RESOURCE_PORT_IO
;
918 if (addr64_data
->Decode
== ACPI_POS_DECODE
)
919 ResourceDescriptor
->Flags
|= CM_RESOURCE_PORT_POSITIVE_DECODE
;
920 ResourceDescriptor
->u
.Port
.Start
.QuadPart
= addr64_data
->Minimum
;
921 ResourceDescriptor
->u
.Port
.Length
= addr64_data
->AddressLength
;
925 ResourceDescriptor
->Type
= CmResourceTypeMemory
;
926 ResourceDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
927 ResourceDescriptor
->Flags
= 0;
928 if (addr64_data
->Info
.Mem
.WriteProtect
== ACPI_READ_ONLY_MEMORY
)
929 ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_ONLY
;
931 ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_WRITE
;
932 switch (addr64_data
->Info
.Mem
.Caching
)
934 case ACPI_CACHABLE_MEMORY
: ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_CACHEABLE
; break;
935 case ACPI_WRITE_COMBINING_MEMORY
: ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_COMBINEDWRITE
; break;
936 case ACPI_PREFETCHABLE_MEMORY
: ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_PREFETCHABLE
; break;
938 ResourceDescriptor
->u
.Memory
.Start
.QuadPart
= addr64_data
->Minimum
;
939 ResourceDescriptor
->u
.Memory
.Length
= addr64_data
->AddressLength
;
941 ResourceDescriptor
++;
944 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64
:
946 ACPI_RESOURCE_EXTENDED_ADDRESS64
*addr64_data
= (ACPI_RESOURCE_EXTENDED_ADDRESS64
*) &resource
->Data
;
947 if (addr64_data
->ResourceType
== ACPI_BUS_NUMBER_RANGE
)
949 DPRINT1("64-bit bus address is not supported!\n");
950 ResourceDescriptor
->Type
= CmResourceTypeBusNumber
;
951 ResourceDescriptor
->ShareDisposition
= CmResourceShareShared
;
952 ResourceDescriptor
->Flags
= 0;
953 ResourceDescriptor
->u
.BusNumber
.Start
= (ULONG
)addr64_data
->Minimum
;
954 ResourceDescriptor
->u
.BusNumber
.Length
= addr64_data
->AddressLength
;
956 else if (addr64_data
->ResourceType
== ACPI_IO_RANGE
)
958 ResourceDescriptor
->Type
= CmResourceTypePort
;
959 ResourceDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
960 ResourceDescriptor
->Flags
= CM_RESOURCE_PORT_IO
;
961 if (addr64_data
->Decode
== ACPI_POS_DECODE
)
962 ResourceDescriptor
->Flags
|= CM_RESOURCE_PORT_POSITIVE_DECODE
;
963 ResourceDescriptor
->u
.Port
.Start
.QuadPart
= addr64_data
->Minimum
;
964 ResourceDescriptor
->u
.Port
.Length
= addr64_data
->AddressLength
;
968 ResourceDescriptor
->Type
= CmResourceTypeMemory
;
969 ResourceDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
970 ResourceDescriptor
->Flags
= 0;
971 if (addr64_data
->Info
.Mem
.WriteProtect
== ACPI_READ_ONLY_MEMORY
)
972 ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_ONLY
;
974 ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_WRITE
;
975 switch (addr64_data
->Info
.Mem
.Caching
)
977 case ACPI_CACHABLE_MEMORY
: ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_CACHEABLE
; break;
978 case ACPI_WRITE_COMBINING_MEMORY
: ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_COMBINEDWRITE
; break;
979 case ACPI_PREFETCHABLE_MEMORY
: ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_PREFETCHABLE
; break;
981 ResourceDescriptor
->u
.Memory
.Start
.QuadPart
= addr64_data
->Minimum
;
982 ResourceDescriptor
->u
.Memory
.Length
= addr64_data
->AddressLength
;
984 ResourceDescriptor
++;
987 case ACPI_RESOURCE_TYPE_MEMORY24
:
989 ACPI_RESOURCE_MEMORY24
*mem24_data
= (ACPI_RESOURCE_MEMORY24
*) &resource
->Data
;
990 ResourceDescriptor
->Type
= CmResourceTypeMemory
;
991 ResourceDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
992 ResourceDescriptor
->Flags
= CM_RESOURCE_MEMORY_24
;
993 if (mem24_data
->WriteProtect
== ACPI_READ_ONLY_MEMORY
)
994 ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_ONLY
;
996 ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_WRITE
;
997 ResourceDescriptor
->u
.Memory
.Start
.QuadPart
= mem24_data
->Minimum
;
998 ResourceDescriptor
->u
.Memory
.Length
= mem24_data
->AddressLength
;
1000 ResourceDescriptor
++;
1003 case ACPI_RESOURCE_TYPE_MEMORY32
:
1005 ACPI_RESOURCE_MEMORY32
*mem32_data
= (ACPI_RESOURCE_MEMORY32
*) &resource
->Data
;
1006 ResourceDescriptor
->Type
= CmResourceTypeMemory
;
1007 ResourceDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
1008 ResourceDescriptor
->Flags
= 0;
1009 if (mem32_data
->WriteProtect
== ACPI_READ_ONLY_MEMORY
)
1010 ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_ONLY
;
1012 ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_WRITE
;
1013 ResourceDescriptor
->u
.Memory
.Start
.QuadPart
= mem32_data
->Minimum
;
1014 ResourceDescriptor
->u
.Memory
.Length
= mem32_data
->AddressLength
;
1016 ResourceDescriptor
++;
1024 resource
= ACPI_NEXT_RESOURCE(resource
);
1027 ExFreePool(Buffer
.Pointer
);
1028 Irp
->IoStatus
.Information
= (ULONG_PTR
)ResourceList
;
1029 return STATUS_SUCCESS
;
1033 Bus_PDO_QueryResourceRequirements(
1034 PPDO_DEVICE_DATA DeviceData
,
1037 ULONG NumberOfResources
= 0;
1038 ACPI_STATUS AcpiStatus
;
1040 ACPI_RESOURCE
* resource
;
1041 ULONG i
, RequirementsListSize
;
1042 PIO_RESOURCE_REQUIREMENTS_LIST RequirementsList
;
1043 PIO_RESOURCE_DESCRIPTOR RequirementDescriptor
;
1044 BOOLEAN CurrentRes
= FALSE
;
1049 /* Get current resources */
1054 AcpiStatus
= AcpiGetCurrentResources(DeviceData
->AcpiHandle
, &Buffer
);
1056 AcpiStatus
= AcpiGetPossibleResources(DeviceData
->AcpiHandle
, &Buffer
);
1057 if ((!ACPI_SUCCESS(AcpiStatus
) && AcpiStatus
!= AE_BUFFER_OVERFLOW
) ||
1063 return Irp
->IoStatus
.Status
;
1069 Buffer
.Pointer
= ExAllocatePool(PagedPool
, Buffer
.Length
);
1070 if (!Buffer
.Pointer
)
1071 return STATUS_INSUFFICIENT_RESOURCES
;
1074 AcpiStatus
= AcpiGetCurrentResources(DeviceData
->AcpiHandle
, &Buffer
);
1076 AcpiStatus
= AcpiGetPossibleResources(DeviceData
->AcpiHandle
, &Buffer
);
1077 if (!ACPI_SUCCESS(AcpiStatus
))
1079 DPRINT1("AcpiGetCurrentResources #2 failed (0x%x)\n", AcpiStatus
);
1081 return STATUS_UNSUCCESSFUL
;
1084 resource
= Buffer
.Pointer
;
1085 /* Count number of resources */
1086 while (resource
->Type
!= ACPI_RESOURCE_TYPE_END_TAG
)
1088 switch (resource
->Type
)
1090 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ
:
1092 ACPI_RESOURCE_EXTENDED_IRQ
*irq_data
= (ACPI_RESOURCE_EXTENDED_IRQ
*) &resource
->Data
;
1093 NumberOfResources
+= irq_data
->InterruptCount
;
1096 case ACPI_RESOURCE_TYPE_IRQ
:
1098 ACPI_RESOURCE_IRQ
*irq_data
= (ACPI_RESOURCE_IRQ
*) &resource
->Data
;
1099 NumberOfResources
+= irq_data
->InterruptCount
;
1102 case ACPI_RESOURCE_TYPE_DMA
:
1104 ACPI_RESOURCE_DMA
*dma_data
= (ACPI_RESOURCE_DMA
*) &resource
->Data
;
1105 NumberOfResources
+= dma_data
->ChannelCount
;
1108 case ACPI_RESOURCE_TYPE_ADDRESS16
:
1109 case ACPI_RESOURCE_TYPE_ADDRESS32
:
1110 case ACPI_RESOURCE_TYPE_ADDRESS64
:
1111 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64
:
1112 case ACPI_RESOURCE_TYPE_MEMORY24
:
1113 case ACPI_RESOURCE_TYPE_MEMORY32
:
1114 case ACPI_RESOURCE_TYPE_IO
:
1116 NumberOfResources
++;
1124 resource
= ACPI_NEXT_RESOURCE(resource
);
1127 RequirementsListSize
= sizeof(IO_RESOURCE_REQUIREMENTS_LIST
) + sizeof(IO_RESOURCE_DESCRIPTOR
) * (NumberOfResources
- 1);
1128 RequirementsList
= (PIO_RESOURCE_REQUIREMENTS_LIST
)ExAllocatePool(PagedPool
, RequirementsListSize
);
1130 if (!RequirementsList
)
1132 ExFreePool(Buffer
.Pointer
);
1133 return STATUS_INSUFFICIENT_RESOURCES
;
1135 RequirementsList
->ListSize
= RequirementsListSize
;
1136 RequirementsList
->InterfaceType
= Internal
;
1137 RequirementsList
->BusNumber
= 0;
1138 RequirementsList
->SlotNumber
= 0; /* Not used by WDM drivers */
1139 RequirementsList
->AlternativeLists
= 1;
1140 RequirementsList
->List
[0].Version
= 1;
1141 RequirementsList
->List
[0].Revision
= 1;
1142 RequirementsList
->List
[0].Count
= NumberOfResources
;
1143 RequirementDescriptor
= RequirementsList
->List
[0].Descriptors
;
1145 /* Fill resources list structure */
1146 resource
= Buffer
.Pointer
;
1147 while (resource
->Type
!= ACPI_RESOURCE_TYPE_END_TAG
)
1149 switch (resource
->Type
)
1151 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ
:
1153 ACPI_RESOURCE_EXTENDED_IRQ
*irq_data
= (ACPI_RESOURCE_EXTENDED_IRQ
*) &resource
->Data
;
1154 for (i
= 0; i
< irq_data
->InterruptCount
; i
++)
1156 RequirementDescriptor
->Option
= CurrentRes
? 0 : IO_RESOURCE_PREFERRED
;
1157 RequirementDescriptor
->Type
= CmResourceTypeInterrupt
;
1158 RequirementDescriptor
->ShareDisposition
= (irq_data
->Sharable
== ACPI_SHARED
? CmResourceShareShared
: CmResourceShareDeviceExclusive
);
1159 RequirementDescriptor
->Flags
=(irq_data
->Triggering
== ACPI_LEVEL_SENSITIVE
? CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE
: CM_RESOURCE_INTERRUPT_LATCHED
);
1160 RequirementDescriptor
->u
.Interrupt
.MinimumVector
=
1161 RequirementDescriptor
->u
.Interrupt
.MaximumVector
= irq_data
->Interrupts
[i
];
1163 RequirementDescriptor
++;
1167 case ACPI_RESOURCE_TYPE_IRQ
:
1169 ACPI_RESOURCE_IRQ
*irq_data
= (ACPI_RESOURCE_IRQ
*) &resource
->Data
;
1170 for (i
= 0; i
< irq_data
->InterruptCount
; i
++)
1172 RequirementDescriptor
->Option
= CurrentRes
? 0 : IO_RESOURCE_PREFERRED
;
1173 RequirementDescriptor
->Type
= CmResourceTypeInterrupt
;
1174 RequirementDescriptor
->ShareDisposition
= (irq_data
->Sharable
== ACPI_SHARED
? CmResourceShareShared
: CmResourceShareDeviceExclusive
);
1175 RequirementDescriptor
->Flags
=(irq_data
->Triggering
== ACPI_LEVEL_SENSITIVE
? CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE
: CM_RESOURCE_INTERRUPT_LATCHED
);
1176 RequirementDescriptor
->u
.Interrupt
.MinimumVector
=
1177 RequirementDescriptor
->u
.Interrupt
.MaximumVector
= irq_data
->Interrupts
[i
];
1179 RequirementDescriptor
++;
1183 case ACPI_RESOURCE_TYPE_DMA
:
1185 ACPI_RESOURCE_DMA
*dma_data
= (ACPI_RESOURCE_DMA
*) &resource
->Data
;
1186 for (i
= 0; i
< dma_data
->ChannelCount
; i
++)
1188 RequirementDescriptor
->Type
= CmResourceTypeDma
;
1189 RequirementDescriptor
->Flags
= 0;
1190 switch (dma_data
->Type
)
1192 case ACPI_TYPE_A
: RequirementDescriptor
->Flags
|= CM_RESOURCE_DMA_TYPE_A
; break;
1193 case ACPI_TYPE_B
: RequirementDescriptor
->Flags
|= CM_RESOURCE_DMA_TYPE_B
; break;
1194 case ACPI_TYPE_F
: RequirementDescriptor
->Flags
|= CM_RESOURCE_DMA_TYPE_F
; break;
1196 if (dma_data
->BusMaster
== ACPI_BUS_MASTER
)
1197 RequirementDescriptor
->Flags
|= CM_RESOURCE_DMA_BUS_MASTER
;
1198 switch (dma_data
->Transfer
)
1200 case ACPI_TRANSFER_8
: RequirementDescriptor
->Flags
|= CM_RESOURCE_DMA_8
; break;
1201 case ACPI_TRANSFER_16
: RequirementDescriptor
->Flags
|= CM_RESOURCE_DMA_16
; break;
1202 case ACPI_TRANSFER_8_16
: RequirementDescriptor
->Flags
|= CM_RESOURCE_DMA_8_AND_16
; break;
1205 RequirementDescriptor
->Option
= CurrentRes
? 0 : IO_RESOURCE_PREFERRED
;
1206 RequirementDescriptor
->ShareDisposition
= CmResourceShareDriverExclusive
;
1207 RequirementDescriptor
->u
.Dma
.MinimumChannel
=
1208 RequirementDescriptor
->u
.Dma
.MaximumChannel
= dma_data
->Channels
[i
];
1209 RequirementDescriptor
++;
1213 case ACPI_RESOURCE_TYPE_IO
:
1215 ACPI_RESOURCE_IO
*io_data
= (ACPI_RESOURCE_IO
*) &resource
->Data
;
1216 RequirementDescriptor
->Flags
= CM_RESOURCE_PORT_IO
;
1217 if (io_data
->IoDecode
== ACPI_DECODE_16
)
1218 RequirementDescriptor
->Flags
|= CM_RESOURCE_PORT_16_BIT_DECODE
;
1220 RequirementDescriptor
->Flags
|= CM_RESOURCE_PORT_10_BIT_DECODE
;
1221 RequirementDescriptor
->u
.Port
.Length
= io_data
->AddressLength
;
1222 RequirementDescriptor
->Option
= CurrentRes
? 0 : IO_RESOURCE_PREFERRED
;
1223 RequirementDescriptor
->Type
= CmResourceTypePort
;
1224 RequirementDescriptor
->ShareDisposition
= CmResourceShareDriverExclusive
;
1225 RequirementDescriptor
->u
.Port
.Alignment
= io_data
->Alignment
;
1226 RequirementDescriptor
->u
.Port
.MinimumAddress
.QuadPart
= io_data
->Minimum
;
1227 RequirementDescriptor
->u
.Port
.MaximumAddress
.QuadPart
= io_data
->Maximum
;
1229 RequirementDescriptor
++;
1232 case ACPI_RESOURCE_TYPE_ADDRESS16
:
1234 ACPI_RESOURCE_ADDRESS16
*addr16_data
= (ACPI_RESOURCE_ADDRESS16
*) &resource
->Data
;
1235 RequirementDescriptor
->Option
= CurrentRes
? 0 : IO_RESOURCE_PREFERRED
;
1236 if (addr16_data
->ResourceType
== ACPI_BUS_NUMBER_RANGE
)
1238 RequirementDescriptor
->Type
= CmResourceTypeBusNumber
;
1239 RequirementDescriptor
->ShareDisposition
= CmResourceShareShared
;
1240 RequirementDescriptor
->Flags
= 0;
1241 RequirementDescriptor
->u
.BusNumber
.MinBusNumber
= addr16_data
->Minimum
;
1242 RequirementDescriptor
->u
.BusNumber
.MaxBusNumber
= addr16_data
->Maximum
;
1243 RequirementDescriptor
->u
.BusNumber
.Length
= addr16_data
->AddressLength
;
1245 else if (addr16_data
->ResourceType
== ACPI_IO_RANGE
)
1247 RequirementDescriptor
->Type
= CmResourceTypePort
;
1248 RequirementDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
1249 RequirementDescriptor
->Flags
= CM_RESOURCE_PORT_IO
;
1250 if (addr16_data
->Decode
== ACPI_POS_DECODE
)
1251 RequirementDescriptor
->Flags
|= CM_RESOURCE_PORT_POSITIVE_DECODE
;
1252 RequirementDescriptor
->u
.Port
.MinimumAddress
.QuadPart
= addr16_data
->Minimum
;
1253 RequirementDescriptor
->u
.Port
.MaximumAddress
.QuadPart
= addr16_data
->Maximum
;
1254 RequirementDescriptor
->u
.Port
.Length
= addr16_data
->AddressLength
;
1258 RequirementDescriptor
->Type
= CmResourceTypeMemory
;
1259 RequirementDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
1260 RequirementDescriptor
->Flags
= 0;
1261 if (addr16_data
->Info
.Mem
.WriteProtect
== ACPI_READ_ONLY_MEMORY
)
1262 RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_ONLY
;
1264 RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_WRITE
;
1265 switch (addr16_data
->Info
.Mem
.Caching
)
1267 case ACPI_CACHABLE_MEMORY
: RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_CACHEABLE
; break;
1268 case ACPI_WRITE_COMBINING_MEMORY
: RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_COMBINEDWRITE
; break;
1269 case ACPI_PREFETCHABLE_MEMORY
: RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_PREFETCHABLE
; break;
1271 RequirementDescriptor
->u
.Memory
.MinimumAddress
.QuadPart
= addr16_data
->Minimum
;
1272 RequirementDescriptor
->u
.Memory
.MaximumAddress
.QuadPart
= addr16_data
->Maximum
;
1273 RequirementDescriptor
->u
.Memory
.Length
= addr16_data
->AddressLength
;
1275 RequirementDescriptor
++;
1278 case ACPI_RESOURCE_TYPE_ADDRESS32
:
1280 ACPI_RESOURCE_ADDRESS32
*addr32_data
= (ACPI_RESOURCE_ADDRESS32
*) &resource
->Data
;
1281 RequirementDescriptor
->Option
= CurrentRes
? 0 : IO_RESOURCE_PREFERRED
;
1282 if (addr32_data
->ResourceType
== ACPI_BUS_NUMBER_RANGE
)
1284 RequirementDescriptor
->Type
= CmResourceTypeBusNumber
;
1285 RequirementDescriptor
->ShareDisposition
= CmResourceShareShared
;
1286 RequirementDescriptor
->Flags
= 0;
1287 RequirementDescriptor
->u
.BusNumber
.MinBusNumber
= addr32_data
->Minimum
;
1288 RequirementDescriptor
->u
.BusNumber
.MaxBusNumber
= addr32_data
->Maximum
;
1289 RequirementDescriptor
->u
.BusNumber
.Length
= addr32_data
->AddressLength
;
1291 else if (addr32_data
->ResourceType
== ACPI_IO_RANGE
)
1293 RequirementDescriptor
->Type
= CmResourceTypePort
;
1294 RequirementDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
1295 RequirementDescriptor
->Flags
= CM_RESOURCE_PORT_IO
;
1296 if (addr32_data
->Decode
== ACPI_POS_DECODE
)
1297 RequirementDescriptor
->Flags
|= CM_RESOURCE_PORT_POSITIVE_DECODE
;
1298 RequirementDescriptor
->u
.Port
.MinimumAddress
.QuadPart
= addr32_data
->Minimum
;
1299 RequirementDescriptor
->u
.Port
.MaximumAddress
.QuadPart
= addr32_data
->Maximum
;
1300 RequirementDescriptor
->u
.Port
.Length
= addr32_data
->AddressLength
;
1304 RequirementDescriptor
->Type
= CmResourceTypeMemory
;
1305 RequirementDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
1306 RequirementDescriptor
->Flags
= 0;
1307 if (addr32_data
->Info
.Mem
.WriteProtect
== ACPI_READ_ONLY_MEMORY
)
1308 RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_ONLY
;
1310 RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_WRITE
;
1311 switch (addr32_data
->Info
.Mem
.Caching
)
1313 case ACPI_CACHABLE_MEMORY
: RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_CACHEABLE
; break;
1314 case ACPI_WRITE_COMBINING_MEMORY
: RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_COMBINEDWRITE
; break;
1315 case ACPI_PREFETCHABLE_MEMORY
: RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_PREFETCHABLE
; break;
1317 RequirementDescriptor
->u
.Memory
.MinimumAddress
.QuadPart
= addr32_data
->Minimum
;
1318 RequirementDescriptor
->u
.Memory
.MaximumAddress
.QuadPart
= addr32_data
->Maximum
;
1319 RequirementDescriptor
->u
.Memory
.Length
= addr32_data
->AddressLength
;
1321 RequirementDescriptor
++;
1324 case ACPI_RESOURCE_TYPE_ADDRESS64
:
1326 ACPI_RESOURCE_ADDRESS64
*addr64_data
= (ACPI_RESOURCE_ADDRESS64
*) &resource
->Data
;
1327 RequirementDescriptor
->Option
= CurrentRes
? 0 : IO_RESOURCE_PREFERRED
;
1328 if (addr64_data
->ResourceType
== ACPI_BUS_NUMBER_RANGE
)
1330 DPRINT1("64-bit bus address is not supported!\n");
1331 RequirementDescriptor
->Type
= CmResourceTypeBusNumber
;
1332 RequirementDescriptor
->ShareDisposition
= CmResourceShareShared
;
1333 RequirementDescriptor
->Flags
= 0;
1334 RequirementDescriptor
->u
.BusNumber
.MinBusNumber
= (ULONG
)addr64_data
->Minimum
;
1335 RequirementDescriptor
->u
.BusNumber
.MaxBusNumber
= (ULONG
)addr64_data
->Maximum
;
1336 RequirementDescriptor
->u
.BusNumber
.Length
= addr64_data
->AddressLength
;
1338 else if (addr64_data
->ResourceType
== ACPI_IO_RANGE
)
1340 RequirementDescriptor
->Type
= CmResourceTypePort
;
1341 RequirementDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
1342 RequirementDescriptor
->Flags
= CM_RESOURCE_PORT_IO
;
1343 if (addr64_data
->Decode
== ACPI_POS_DECODE
)
1344 RequirementDescriptor
->Flags
|= CM_RESOURCE_PORT_POSITIVE_DECODE
;
1345 RequirementDescriptor
->u
.Port
.MinimumAddress
.QuadPart
= addr64_data
->Minimum
;
1346 RequirementDescriptor
->u
.Port
.MaximumAddress
.QuadPart
= addr64_data
->Maximum
;
1347 RequirementDescriptor
->u
.Port
.Length
= addr64_data
->AddressLength
;
1351 RequirementDescriptor
->Type
= CmResourceTypeMemory
;
1352 RequirementDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
1353 RequirementDescriptor
->Flags
= 0;
1354 if (addr64_data
->Info
.Mem
.WriteProtect
== ACPI_READ_ONLY_MEMORY
)
1355 RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_ONLY
;
1357 RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_WRITE
;
1358 switch (addr64_data
->Info
.Mem
.Caching
)
1360 case ACPI_CACHABLE_MEMORY
: RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_CACHEABLE
; break;
1361 case ACPI_WRITE_COMBINING_MEMORY
: RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_COMBINEDWRITE
; break;
1362 case ACPI_PREFETCHABLE_MEMORY
: RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_PREFETCHABLE
; break;
1364 RequirementDescriptor
->u
.Memory
.MinimumAddress
.QuadPart
= addr64_data
->Minimum
;
1365 RequirementDescriptor
->u
.Memory
.MaximumAddress
.QuadPart
= addr64_data
->Maximum
;
1366 RequirementDescriptor
->u
.Memory
.Length
= addr64_data
->AddressLength
;
1368 RequirementDescriptor
++;
1371 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64
:
1373 ACPI_RESOURCE_EXTENDED_ADDRESS64
*addr64_data
= (ACPI_RESOURCE_EXTENDED_ADDRESS64
*) &resource
->Data
;
1374 RequirementDescriptor
->Option
= CurrentRes
? 0 : IO_RESOURCE_PREFERRED
;
1375 if (addr64_data
->ResourceType
== ACPI_BUS_NUMBER_RANGE
)
1377 DPRINT1("64-bit bus address is not supported!\n");
1378 RequirementDescriptor
->Type
= CmResourceTypeBusNumber
;
1379 RequirementDescriptor
->ShareDisposition
= CmResourceShareShared
;
1380 RequirementDescriptor
->Flags
= 0;
1381 RequirementDescriptor
->u
.BusNumber
.MinBusNumber
= (ULONG
)addr64_data
->Minimum
;
1382 RequirementDescriptor
->u
.BusNumber
.MaxBusNumber
= (ULONG
)addr64_data
->Maximum
;
1383 RequirementDescriptor
->u
.BusNumber
.Length
= addr64_data
->AddressLength
;
1385 else if (addr64_data
->ResourceType
== ACPI_IO_RANGE
)
1387 RequirementDescriptor
->Type
= CmResourceTypePort
;
1388 RequirementDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
1389 RequirementDescriptor
->Flags
= CM_RESOURCE_PORT_IO
;
1390 if (addr64_data
->Decode
== ACPI_POS_DECODE
)
1391 RequirementDescriptor
->Flags
|= CM_RESOURCE_PORT_POSITIVE_DECODE
;
1392 RequirementDescriptor
->u
.Port
.MinimumAddress
.QuadPart
= addr64_data
->Minimum
;
1393 RequirementDescriptor
->u
.Port
.MaximumAddress
.QuadPart
= addr64_data
->Maximum
;
1394 RequirementDescriptor
->u
.Port
.Length
= addr64_data
->AddressLength
;
1398 RequirementDescriptor
->Type
= CmResourceTypeMemory
;
1399 RequirementDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
1400 RequirementDescriptor
->Flags
= 0;
1401 if (addr64_data
->Info
.Mem
.WriteProtect
== ACPI_READ_ONLY_MEMORY
)
1402 RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_ONLY
;
1404 RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_WRITE
;
1405 switch (addr64_data
->Info
.Mem
.Caching
)
1407 case ACPI_CACHABLE_MEMORY
: RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_CACHEABLE
; break;
1408 case ACPI_WRITE_COMBINING_MEMORY
: RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_COMBINEDWRITE
; break;
1409 case ACPI_PREFETCHABLE_MEMORY
: RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_PREFETCHABLE
; break;
1411 RequirementDescriptor
->u
.Memory
.MinimumAddress
.QuadPart
= addr64_data
->Minimum
;
1412 RequirementDescriptor
->u
.Memory
.MaximumAddress
.QuadPart
= addr64_data
->Maximum
;
1413 RequirementDescriptor
->u
.Memory
.Length
= addr64_data
->AddressLength
;
1415 RequirementDescriptor
++;
1418 case ACPI_RESOURCE_TYPE_MEMORY24
:
1420 ACPI_RESOURCE_MEMORY24
*mem24_data
= (ACPI_RESOURCE_MEMORY24
*) &resource
->Data
;
1421 RequirementDescriptor
->Option
= CurrentRes
? 0 : IO_RESOURCE_PREFERRED
;
1422 RequirementDescriptor
->Type
= CmResourceTypeMemory
;
1423 RequirementDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
1424 RequirementDescriptor
->Flags
= CM_RESOURCE_MEMORY_24
;
1425 if (mem24_data
->WriteProtect
== ACPI_READ_ONLY_MEMORY
)
1426 RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_ONLY
;
1428 RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_WRITE
;
1429 RequirementDescriptor
->u
.Memory
.MinimumAddress
.QuadPart
= mem24_data
->Minimum
;
1430 RequirementDescriptor
->u
.Memory
.MaximumAddress
.QuadPart
= mem24_data
->Maximum
;
1431 RequirementDescriptor
->u
.Memory
.Length
= mem24_data
->AddressLength
;
1433 RequirementDescriptor
++;
1436 case ACPI_RESOURCE_TYPE_MEMORY32
:
1438 ACPI_RESOURCE_MEMORY32
*mem32_data
= (ACPI_RESOURCE_MEMORY32
*) &resource
->Data
;
1439 RequirementDescriptor
->Option
= CurrentRes
? 0 : IO_RESOURCE_PREFERRED
;
1440 RequirementDescriptor
->Type
= CmResourceTypeMemory
;
1441 RequirementDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
1442 RequirementDescriptor
->Flags
= 0;
1443 if (mem32_data
->WriteProtect
== ACPI_READ_ONLY_MEMORY
)
1444 RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_ONLY
;
1446 RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_WRITE
;
1447 RequirementDescriptor
->u
.Memory
.MinimumAddress
.QuadPart
= mem32_data
->Minimum
;
1448 RequirementDescriptor
->u
.Memory
.MaximumAddress
.QuadPart
= mem32_data
->Maximum
;
1449 RequirementDescriptor
->u
.Memory
.Length
= mem32_data
->AddressLength
;
1451 RequirementDescriptor
++;
1459 resource
= ACPI_NEXT_RESOURCE(resource
);
1461 ExFreePool(Buffer
.Pointer
);
1463 Irp
->IoStatus
.Information
= (ULONG_PTR
)RequirementsList
;
1465 return STATUS_SUCCESS
;
1469 Bus_PDO_QueryDeviceRelations(
1470 PPDO_DEVICE_DATA DeviceData
,
1474 Routine Description:
1476 The PnP Manager sends this IRP to gather information about
1477 devices with a relationship to the specified device.
1478 Bus drivers must handle this request for TargetDeviceRelation
1479 for their child devices (child PDOs).
1481 If a driver returns relations in response to this IRP,
1482 it allocates a DEVICE_RELATIONS structure from paged
1483 memory containing a count and the appropriate number of
1484 device object pointers. The PnP Manager frees the structure
1485 when it is no longer needed. If a driver replaces a
1486 DEVICE_RELATIONS structure allocated by another driver,
1487 it must free the previous structure.
1489 A driver must reference the PDO of any device that it
1490 reports in this IRP (ObReferenceObject). The PnP Manager
1491 removes the reference when appropriate.
1495 DeviceData - Pointer to the PDO's device extension.
1496 Irp - Pointer to the irp.
1505 PIO_STACK_LOCATION stack
;
1506 PDEVICE_RELATIONS deviceRelations
;
1511 stack
= IoGetCurrentIrpStackLocation (Irp
);
1513 switch (stack
->Parameters
.QueryDeviceRelations
.Type
) {
1515 case TargetDeviceRelation
:
1517 deviceRelations
= (PDEVICE_RELATIONS
) Irp
->IoStatus
.Information
;
1518 if (deviceRelations
) {
1520 // Only PDO can handle this request. Somebody above
1521 // is not playing by rule.
1523 ASSERTMSG("Someone above is handling TargetDeviceRelation", !deviceRelations
);
1526 deviceRelations
= (PDEVICE_RELATIONS
)
1527 ExAllocatePoolWithTag (PagedPool
,
1528 sizeof(DEVICE_RELATIONS
),
1530 if (!deviceRelations
) {
1531 status
= STATUS_INSUFFICIENT_RESOURCES
;
1536 // There is only one PDO pointer in the structure
1537 // for this relation type. The PnP Manager removes
1538 // the reference to the PDO when the driver or application
1539 // un-registers for notification on the device.
1542 deviceRelations
->Count
= 1;
1543 deviceRelations
->Objects
[0] = DeviceData
->Common
.Self
;
1544 ObReferenceObject(DeviceData
->Common
.Self
);
1546 status
= STATUS_SUCCESS
;
1547 Irp
->IoStatus
.Information
= (ULONG_PTR
) deviceRelations
;
1550 case BusRelations
: // Not handled by PDO
1551 case EjectionRelations
: // optional for PDO
1552 case RemovalRelations
: // // optional for PDO
1554 status
= Irp
->IoStatus
.Status
;
1561 Bus_PDO_QueryBusInformation(
1562 PPDO_DEVICE_DATA DeviceData
,
1566 Routine Description:
1568 The PnP Manager uses this IRP to request the type and
1569 instance number of a device's parent bus. Bus drivers
1570 should handle this request for their child devices (PDOs).
1574 DeviceData - Pointer to the PDO's device extension.
1575 Irp - Pointer to the irp.
1584 PPNP_BUS_INFORMATION busInfo
;
1588 busInfo
= ExAllocatePoolWithTag (PagedPool
, sizeof(PNP_BUS_INFORMATION
),
1591 if (busInfo
== NULL
) {
1592 return STATUS_INSUFFICIENT_RESOURCES
;
1595 busInfo
->BusTypeGuid
= GUID_ACPI_INTERFACE_STANDARD
;
1597 busInfo
->LegacyBusType
= InternalPowerBus
;
1599 busInfo
->BusNumber
= 0; //fixme
1601 Irp
->IoStatus
.Information
= (ULONG_PTR
)busInfo
;
1603 return STATUS_SUCCESS
;
1608 Bus_GetDeviceCapabilities(
1609 PDEVICE_OBJECT DeviceObject
,
1610 PDEVICE_CAPABILITIES DeviceCapabilities
1613 IO_STATUS_BLOCK ioStatus
;
1616 PDEVICE_OBJECT targetObject
;
1617 PIO_STACK_LOCATION irpStack
;
1623 // Initialize the capabilities that we will send down
1625 RtlZeroMemory( DeviceCapabilities
, sizeof(DEVICE_CAPABILITIES
) );
1626 DeviceCapabilities
->Size
= sizeof(DEVICE_CAPABILITIES
);
1627 DeviceCapabilities
->Version
= 1;
1628 DeviceCapabilities
->Address
= -1;
1629 DeviceCapabilities
->UINumber
= -1;
1632 // Initialize the event
1634 KeInitializeEvent( &pnpEvent
, NotificationEvent
, FALSE
);
1636 targetObject
= IoGetAttachedDeviceReference( DeviceObject
);
1641 pnpIrp
= IoBuildSynchronousFsdRequest(
1650 if (pnpIrp
== NULL
) {
1652 status
= STATUS_INSUFFICIENT_RESOURCES
;
1653 goto GetDeviceCapabilitiesExit
;
1658 // Pnp Irps all begin life as STATUS_NOT_SUPPORTED;
1660 pnpIrp
->IoStatus
.Status
= STATUS_NOT_SUPPORTED
;
1663 // Get the top of stack
1665 irpStack
= IoGetNextIrpStackLocation( pnpIrp
);
1668 // Set the top of stack
1670 RtlZeroMemory( irpStack
, sizeof(IO_STACK_LOCATION
) );
1671 irpStack
->MajorFunction
= IRP_MJ_PNP
;
1672 irpStack
->MinorFunction
= IRP_MN_QUERY_CAPABILITIES
;
1673 irpStack
->Parameters
.DeviceCapabilities
.Capabilities
= DeviceCapabilities
;
1678 status
= IoCallDriver( targetObject
, pnpIrp
);
1679 if (status
== STATUS_PENDING
) {
1682 // Block until the irp comes back.
1683 // Important thing to note here is when you allocate
1684 // the memory for an event in the stack you must do a
1685 // KernelMode wait instead of UserMode to prevent
1686 // the stack from getting paged out.
1689 KeWaitForSingleObject(
1696 status
= ioStatus
.Status
;
1700 GetDeviceCapabilitiesExit
:
1702 // Done with reference
1704 ObDereferenceObject( targetObject
);