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;
69 status
= STATUS_SUCCESS
;
73 status
= IoRegisterDeviceInterface(DeviceData
->Common
.Self
,
74 &GUID_DEVICE_SYS_BUTTON
,
76 &DeviceData
->InterfaceName
);
78 else if (device
->flags
.hardware_id
&&
79 strstr(device
->pnp
.hardware_id
, ACPI_THERMAL_HID
))
81 status
= IoRegisterDeviceInterface(DeviceData
->Common
.Self
,
82 &GUID_DEVICE_THERMAL_ZONE
,
84 &DeviceData
->InterfaceName
);
86 else if (device
->flags
.hardware_id
&&
87 strstr(device
->pnp
.hardware_id
, ACPI_BUTTON_HID_LID
))
89 status
= IoRegisterDeviceInterface(DeviceData
->Common
.Self
,
92 &DeviceData
->InterfaceName
);
94 else if (device
->flags
.hardware_id
&&
95 strstr(device
->pnp
.hardware_id
, ACPI_PROCESSOR_HID
))
97 status
= IoRegisterDeviceInterface(DeviceData
->Common
.Self
,
98 &GUID_DEVICE_PROCESSOR
,
100 &DeviceData
->InterfaceName
);
103 /* Failure to register an interface is not a fatal failure so don't return a failure status */
104 if (NT_SUCCESS(status
) && DeviceData
->InterfaceName
.Length
!= 0)
105 IoSetDeviceInterfaceState(&DeviceData
->InterfaceName
, TRUE
);
107 state
.DeviceState
= PowerDeviceD0
;
108 PoSetPowerState(DeviceData
->Common
.Self
, DevicePowerState
, state
);
109 DeviceData
->Common
.DevicePowerState
= PowerDeviceD0
;
110 SET_NEW_PNP_STATE(DeviceData
->Common
, Started
);
111 status
= STATUS_SUCCESS
;
114 case IRP_MN_STOP_DEVICE
:
116 if (DeviceData
->InterfaceName
.Length
!= 0)
117 IoSetDeviceInterfaceState(&DeviceData
->InterfaceName
, FALSE
);
120 // Here we shut down the device and give up and unmap any resources
121 // we acquired for the device.
123 if (DeviceData
->AcpiHandle
&& acpi_bus_power_manageable(DeviceData
->AcpiHandle
) &&
124 !ACPI_SUCCESS(acpi_bus_set_power(DeviceData
->AcpiHandle
, ACPI_STATE_D3
)))
126 DPRINT1("Device %x failed to stop!\n", DeviceData
->AcpiHandle
);
127 status
= STATUS_UNSUCCESSFUL
;
131 state
.DeviceState
= PowerDeviceD3
;
132 PoSetPowerState(DeviceData
->Common
.Self
, DevicePowerState
, state
);
133 DeviceData
->Common
.DevicePowerState
= PowerDeviceD3
;
134 SET_NEW_PNP_STATE(DeviceData
->Common
, Stopped
);
135 status
= STATUS_SUCCESS
;
139 case IRP_MN_QUERY_STOP_DEVICE
:
142 // No reason here why we can't stop the device.
143 // If there were a reason we should speak now, because answering success
144 // here may result in a stop device irp.
147 SET_NEW_PNP_STATE(DeviceData
->Common
, StopPending
);
148 status
= STATUS_SUCCESS
;
151 case IRP_MN_CANCEL_STOP_DEVICE
:
154 // The stop was canceled. Whatever state we set, or resources we put
155 // on hold in anticipation of the forthcoming STOP device IRP should be
156 // put back to normal. Someone, in the long list of concerned parties,
157 // has failed the stop device query.
161 // First check to see whether you have received cancel-stop
162 // without first receiving a query-stop. This could happen if someone
163 // above us fails a query-stop and passes down the subsequent
167 if (StopPending
== DeviceData
->Common
.DevicePnPState
)
170 // We did receive a query-stop, so restore.
172 RESTORE_PREVIOUS_PNP_STATE(DeviceData
->Common
);
174 status
= STATUS_SUCCESS
;// We must not fail this IRP.
176 case IRP_MN_QUERY_CAPABILITIES
:
179 // Return the capabilities of a device, such as whether the device
180 // can be locked or ejected..etc
183 status
= Bus_PDO_QueryDeviceCaps(DeviceData
, Irp
);
187 case IRP_MN_QUERY_ID
:
189 // Query the IDs of the device
190 status
= Bus_PDO_QueryDeviceId(DeviceData
, Irp
);
194 case IRP_MN_QUERY_DEVICE_RELATIONS
:
196 DPRINT("\tQueryDeviceRelation Type: %s\n",DbgDeviceRelationString(\
197 IrpStack
->Parameters
.QueryDeviceRelations
.Type
));
199 status
= Bus_PDO_QueryDeviceRelations(DeviceData
, Irp
);
203 case IRP_MN_QUERY_DEVICE_TEXT
:
205 status
= Bus_PDO_QueryDeviceText(DeviceData
, Irp
);
209 case IRP_MN_QUERY_RESOURCES
:
211 status
= Bus_PDO_QueryResources(DeviceData
, Irp
);
215 case IRP_MN_QUERY_RESOURCE_REQUIREMENTS
:
217 status
= Bus_PDO_QueryResourceRequirements(DeviceData
, Irp
);
221 case IRP_MN_QUERY_BUS_INFORMATION
:
223 status
= Bus_PDO_QueryBusInformation(DeviceData
, Irp
);
227 case IRP_MN_QUERY_INTERFACE
:
229 status
= Bus_PDO_QueryInterface(DeviceData
, Irp
);
234 case IRP_MN_FILTER_RESOURCE_REQUIREMENTS
:
237 // OPTIONAL for bus drivers.
238 // The PnP Manager sends this IRP to a device
239 // stack so filter and function drivers can adjust the
240 // resources required by the device, if appropriate.
245 //case IRP_MN_QUERY_PNP_DEVICE_STATE:
248 // OPTIONAL for bus drivers.
249 // The PnP Manager sends this IRP after the drivers for
250 // a device return success from the IRP_MN_START_DEVICE
251 // request. The PnP Manager also sends this IRP when a
252 // driver for the device calls IoInvalidateDeviceState.
257 //case IRP_MN_READ_CONFIG:
258 //case IRP_MN_WRITE_CONFIG:
261 // Bus drivers for buses with configuration space must handle
262 // this request for their child devices. Our devices don't
263 // have a config space.
268 //case IRP_MN_SET_LOCK:
275 // For PnP requests to the PDO that we do not understand we should
276 // return the IRP WITHOUT setting the status or information fields.
277 // These fields may have already been set by a filter (eg acpi).
278 status
= Irp
->IoStatus
.Status
;
283 Irp
->IoStatus
.Status
= status
;
284 IoCompleteRequest (Irp
, IO_NO_INCREMENT
);
290 Bus_PDO_QueryDeviceCaps(
291 PPDO_DEVICE_DATA DeviceData
,
295 PIO_STACK_LOCATION stack
;
296 PDEVICE_CAPABILITIES deviceCapabilities
;
297 struct acpi_device
*device
= NULL
;
302 if (DeviceData
->AcpiHandle
)
303 acpi_bus_get_device(DeviceData
->AcpiHandle
, &device
);
305 stack
= IoGetCurrentIrpStackLocation (Irp
);
310 deviceCapabilities
=stack
->Parameters
.DeviceCapabilities
.Capabilities
;
313 // Set the capabilities.
316 if (deviceCapabilities
->Version
!= 1 ||
317 deviceCapabilities
->Size
< sizeof(DEVICE_CAPABILITIES
))
319 return STATUS_UNSUCCESSFUL
;
322 deviceCapabilities
->D1Latency
= 0;
323 deviceCapabilities
->D2Latency
= 0;
324 deviceCapabilities
->D3Latency
= 0;
326 deviceCapabilities
->DeviceState
[PowerSystemWorking
] = PowerDeviceD0
;
327 deviceCapabilities
->DeviceState
[PowerSystemSleeping1
] = PowerDeviceD3
;
328 deviceCapabilities
->DeviceState
[PowerSystemSleeping2
] = PowerDeviceD3
;
329 deviceCapabilities
->DeviceState
[PowerSystemSleeping3
] = PowerDeviceD3
;
331 for (i
= 0; i
< ACPI_D_STATE_COUNT
&& device
; i
++)
333 if (!device
->power
.states
[i
].flags
.valid
)
339 deviceCapabilities
->DeviceState
[PowerSystemWorking
] = PowerDeviceD0
;
343 deviceCapabilities
->DeviceState
[PowerSystemSleeping1
] = PowerDeviceD1
;
344 deviceCapabilities
->D1Latency
= device
->power
.states
[i
].latency
;
348 deviceCapabilities
->DeviceState
[PowerSystemSleeping2
] = PowerDeviceD2
;
349 deviceCapabilities
->D2Latency
= device
->power
.states
[i
].latency
;
353 deviceCapabilities
->DeviceState
[PowerSystemSleeping3
] = PowerDeviceD3
;
354 deviceCapabilities
->D3Latency
= device
->power
.states
[i
].latency
;
359 // We can wake the system from D1
360 deviceCapabilities
->DeviceWake
= PowerDeviceD1
;
363 deviceCapabilities
->DeviceD1
=
364 (deviceCapabilities
->DeviceState
[PowerSystemSleeping1
] == PowerDeviceD1
) ? TRUE
: FALSE
;
365 deviceCapabilities
->DeviceD2
=
366 (deviceCapabilities
->DeviceState
[PowerSystemSleeping2
] == PowerDeviceD2
) ? TRUE
: FALSE
;
368 deviceCapabilities
->WakeFromD0
= FALSE
;
369 deviceCapabilities
->WakeFromD1
= TRUE
; //Yes we can
370 deviceCapabilities
->WakeFromD2
= FALSE
;
371 deviceCapabilities
->WakeFromD3
= FALSE
;
375 deviceCapabilities
->LockSupported
= device
->flags
.lockable
;
376 deviceCapabilities
->EjectSupported
= device
->flags
.ejectable
;
377 deviceCapabilities
->HardwareDisabled
= !device
->status
.enabled
&& !device
->status
.functional
;
378 deviceCapabilities
->Removable
= device
->flags
.removable
;
379 deviceCapabilities
->SurpriseRemovalOK
= device
->flags
.suprise_removal_ok
;
380 deviceCapabilities
->UniqueID
= device
->flags
.unique_id
;
381 deviceCapabilities
->NoDisplayInUI
= !device
->status
.show_in_ui
;
382 deviceCapabilities
->Address
= device
->pnp
.bus_address
;
386 (device
->flags
.hardware_id
&&
387 (strstr(device
->pnp
.hardware_id
, ACPI_BUTTON_HID_LID
) ||
388 strstr(device
->pnp
.hardware_id
, ACPI_THERMAL_HID
) ||
389 strstr(device
->pnp
.hardware_id
, ACPI_PROCESSOR_HID
))))
391 /* Allow ACPI to control the device if it is a lid button,
392 * a thermal zone, a processor, or a fixed feature button */
393 deviceCapabilities
->RawDeviceOK
= TRUE
;
396 deviceCapabilities
->SilentInstall
= FALSE
;
397 deviceCapabilities
->UINumber
= (ULONG
)-1;
399 return STATUS_SUCCESS
;
404 Bus_PDO_QueryDeviceId(
405 PPDO_DEVICE_DATA DeviceData
,
408 PIO_STACK_LOCATION stack
;
412 NTSTATUS status
= STATUS_SUCCESS
;
413 struct acpi_device
*Device
;
417 stack
= IoGetCurrentIrpStackLocation (Irp
);
419 switch (stack
->Parameters
.QueryId
.IdType
) {
421 case BusQueryDeviceID
:
422 if (DeviceData
->AcpiHandle
)
424 acpi_bus_get_device(DeviceData
->AcpiHandle
, &Device
);
426 length
= swprintf(temp
,
428 Device
->pnp
.hardware_id
);
432 /* We know it's a fixed feature button because
433 * these are direct children of the ACPI root device
434 * and therefore have no handle
436 length
= swprintf(temp
,
437 L
"ACPI\\FixedButton");
440 temp
[++length
] = UNICODE_NULL
;
442 buffer
= ExAllocatePoolWithTag (PagedPool
, length
* sizeof(WCHAR
), 'IPCA');
445 status
= STATUS_INSUFFICIENT_RESOURCES
;
449 RtlCopyMemory (buffer
, temp
, length
* sizeof(WCHAR
));
450 Irp
->IoStatus
.Information
= (ULONG_PTR
) buffer
;
451 DPRINT("BusQueryDeviceID: %ls\n",buffer
);
454 case BusQueryInstanceID
:
455 /* See comment in BusQueryDeviceID case */
456 if(DeviceData
->AcpiHandle
)
458 acpi_bus_get_device(DeviceData
->AcpiHandle
, &Device
);
460 if (Device
->flags
.unique_id
)
461 length
= swprintf(temp
,
463 Device
->pnp
.unique_id
);
465 /* FIXME: Generate unique id! */
466 length
= swprintf(temp
, L
"%ls", L
"0000");
469 /* FIXME: Generate unique id! */
470 length
= swprintf(temp
, L
"%ls", L
"0000");
472 temp
[++length
] = UNICODE_NULL
;
474 buffer
= ExAllocatePoolWithTag (PagedPool
, length
* sizeof (WCHAR
), 'IPCA');
476 status
= STATUS_INSUFFICIENT_RESOURCES
;
480 RtlCopyMemory (buffer
, temp
, length
* sizeof (WCHAR
));
481 DPRINT("BusQueryInstanceID: %ls\n",buffer
);
482 Irp
->IoStatus
.Information
= (ULONG_PTR
) buffer
;
485 case BusQueryHardwareIDs
:
488 /* See comment in BusQueryDeviceID case */
489 if (DeviceData
->AcpiHandle
)
491 acpi_bus_get_device(DeviceData
->AcpiHandle
, &Device
);
493 DPRINT1("Device name: %s\n", Device
->pnp
.device_name
);
494 DPRINT1("Hardware ID: %s\n", Device
->pnp
.hardware_id
);
496 if (strcmp(Device
->pnp
.hardware_id
, "Processor") == 0)
499 length += swprintf(&temp[length],
501 ProcessorVendorIdentifier, ProcessorIdentifier);
504 length += swprintf(&temp[length],
506 ProcessorVendorIdentifier, ProcessorIdentifier);
509 length
= ProcessorHardwareIds
.Length
/ sizeof(WCHAR
);
510 src
= ProcessorHardwareIds
.Buffer
;
514 length
+= swprintf(&temp
[length
],
516 Device
->pnp
.hardware_id
);
519 length
+= swprintf(&temp
[length
],
521 Device
->pnp
.hardware_id
);
524 temp
[length
] = UNICODE_NULL
;
528 temp
[length
] = UNICODE_NULL
;
535 length
+= swprintf(&temp
[length
],
536 L
"ACPI\\FixedButton");
539 length
+= swprintf(&temp
[length
],
543 temp
[length
] = UNICODE_NULL
;
547 temp
[length
] = UNICODE_NULL
;
552 buffer
= ExAllocatePoolWithTag (PagedPool
, length
* sizeof(WCHAR
), 'IPCA');
555 status
= STATUS_INSUFFICIENT_RESOURCES
;
559 RtlCopyMemory (buffer
, src
, length
* sizeof(WCHAR
));
560 Irp
->IoStatus
.Information
= (ULONG_PTR
) buffer
;
561 DPRINT("BusQueryHardwareIDs: %ls\n",buffer
);
564 case BusQueryCompatibleIDs
:
566 status
= STATUS_NOT_SUPPORTED
;
568 /* See comment in BusQueryDeviceID case */
569 if (DeviceData
->AcpiHandle
)
571 acpi_bus_get_device(DeviceData
->AcpiHandle
, &Device
);
573 if (strcmp(Device
->pnp
.hardware_id
, "Processor") == 0)
575 DPRINT("Device name: %s\n", Device
->pnp
.device_name
);
576 DPRINT("Hardware ID: %s\n", Device
->pnp
.hardware_id
);
578 length
+= swprintf(&temp
[length
],
580 Device
->pnp
.hardware_id
);
583 length
+= swprintf(&temp
[length
],
585 Device
->pnp
.hardware_id
);
588 temp
[length
] = UNICODE_NULL
;
592 temp
[length
] = UNICODE_NULL
;
594 buffer
= ExAllocatePoolWithTag (PagedPool
, length
* sizeof(WCHAR
), 'IPCA');
597 status
= STATUS_INSUFFICIENT_RESOURCES
;
601 RtlCopyMemory (buffer
, temp
, length
* sizeof(WCHAR
));
602 Irp
->IoStatus
.Information
= (ULONG_PTR
) buffer
;
603 DPRINT("BusQueryHardwareIDs: %ls\n",buffer
);
604 status
= STATUS_SUCCESS
;
610 status
= Irp
->IoStatus
.Status
;
616 Bus_PDO_QueryDeviceText(
617 PPDO_DEVICE_DATA DeviceData
,
621 PIO_STACK_LOCATION stack
;
622 NTSTATUS status
= Irp
->IoStatus
.Status
;
625 stack
= IoGetCurrentIrpStackLocation (Irp
);
627 switch (stack
->Parameters
.QueryDeviceText
.DeviceTextType
) {
629 case DeviceTextDescription
:
631 if (!Irp
->IoStatus
.Information
) {
632 if (wcsstr (DeviceData
->HardwareIDs
, L
"PNP000") != 0)
633 Temp
= L
"Programmable interrupt controller";
634 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNP010") != 0)
635 Temp
= L
"System timer";
636 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNP020") != 0)
637 Temp
= L
"DMA controller";
638 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNP03") != 0)
640 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNP040") != 0)
641 Temp
= L
"Parallel port";
642 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNP05") != 0)
643 Temp
= L
"Serial port";
644 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNP06") != 0)
645 Temp
= L
"Disk controller";
646 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNP07") != 0)
647 Temp
= L
"Disk controller";
648 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNP09") != 0)
649 Temp
= L
"Display adapter";
650 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNP0A0") != 0)
651 Temp
= L
"Bus controller";
652 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNP0E0") != 0)
653 Temp
= L
"PCMCIA controller";
654 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNP0F") != 0)
655 Temp
= L
"Mouse device";
656 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNP8") != 0)
657 Temp
= L
"Network adapter";
658 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNPA0") != 0)
659 Temp
= L
"SCSI controller";
660 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNPB0") != 0)
661 Temp
= L
"Multimedia device";
662 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNPC00") != 0)
664 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNP0C0C") != 0)
665 Temp
= L
"Power Button";
666 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNP0C0E") != 0)
667 Temp
= L
"Sleep Button";
668 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNP0C0D") != 0)
669 Temp
= L
"Lid Switch";
670 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNP0C09") != 0)
671 Temp
= L
"ACPI Embedded Controller";
672 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNP0C0B") != 0)
674 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNP0A03") != 0 ||
675 wcsstr(DeviceData
->HardwareIDs
, L
"PNP0A08") != 0 )
676 Temp
= L
"PCI Root Bridge";
677 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNP0C0A") != 0)
678 Temp
= L
"ACPI Battery";
679 else if (wcsstr(DeviceData
->HardwareIDs
, L
"PNP0C0F") != 0)
680 Temp
= L
"PCI Interrupt Link";
681 else if (wcsstr(DeviceData
->HardwareIDs
, L
"ACPI_PWR") != 0)
682 Temp
= L
"ACPI Power Resource";
683 else if (wcsstr(DeviceData
->HardwareIDs
, L
"Processor") != 0)
685 if (ProcessorNameString
!= NULL
)
686 Temp
= ProcessorNameString
;
690 else if (wcsstr(DeviceData
->HardwareIDs
, L
"ThermalZone") != 0)
691 Temp
= L
"ACPI Thermal Zone";
692 else if (wcsstr(DeviceData
->HardwareIDs
, L
"ACPI0002") != 0)
693 Temp
= L
"Smart Battery";
694 else if (wcsstr(DeviceData
->HardwareIDs
, L
"ACPI0003") != 0)
695 Temp
= L
"AC Adapter";
696 /* Simply checking if AcpiHandle is NULL eliminates the need to check
697 * for the 4 different names that ACPI knows the fixed feature button as internally
699 else if (!DeviceData
->AcpiHandle
)
700 Temp
= L
"ACPI Fixed Feature Button";
702 Temp
= L
"Other ACPI device";
704 Buffer
= ExAllocatePoolWithTag (PagedPool
, (wcslen(Temp
) + 1) * sizeof(WCHAR
), 'IPCA');
707 status
= STATUS_INSUFFICIENT_RESOURCES
;
711 RtlCopyMemory (Buffer
, Temp
, (wcslen(Temp
) + 1) * sizeof(WCHAR
));
713 DPRINT("\tDeviceTextDescription :%ws\n", Buffer
);
715 Irp
->IoStatus
.Information
= (ULONG_PTR
) Buffer
;
716 status
= STATUS_SUCCESS
;
729 Bus_PDO_QueryResources(
730 PPDO_DEVICE_DATA DeviceData
,
733 ULONG NumberOfResources
= 0;
734 PCM_RESOURCE_LIST ResourceList
;
735 PCM_PARTIAL_RESOURCE_DESCRIPTOR ResourceDescriptor
;
736 ACPI_STATUS AcpiStatus
;
738 ACPI_RESOURCE
* resource
;
739 ULONG ResourceListSize
;
742 struct acpi_device
*device
;
744 if (!DeviceData
->AcpiHandle
)
746 return Irp
->IoStatus
.Status
;
749 /* A bus number resource is not included in the list of current resources
750 * for the root PCI bus so we manually query one here and if we find it
751 * we create a resource list and add a bus number descriptor to it */
752 if (wcsstr(DeviceData
->HardwareIDs
, L
"PNP0A03") != 0 ||
753 wcsstr(DeviceData
->HardwareIDs
, L
"PNP0A08") != 0)
755 acpi_bus_get_device(DeviceData
->AcpiHandle
, &device
);
757 AcpiStatus
= acpi_evaluate_integer(DeviceData
->AcpiHandle
, "_BBN", NULL
, &BusNumber
);
758 if (AcpiStatus
!= AE_OK
)
761 if (device
->flags
.unique_id
)
763 /* FIXME: Try the unique ID */
769 DPRINT1("Failed to find a bus number\n");
774 DPRINT1("Using _BBN for bus number\n");
777 DPRINT1("Found PCI root hub: %d\n", BusNumber
);
779 ResourceListSize
= sizeof(CM_RESOURCE_LIST
);
780 ResourceList
= (PCM_RESOURCE_LIST
)ExAllocatePoolWithTag(PagedPool
, ResourceListSize
, 'IPCA');
782 return STATUS_INSUFFICIENT_RESOURCES
;
784 ResourceList
->Count
= 1;
785 ResourceList
->List
[0].InterfaceType
= Internal
;
786 ResourceList
->List
[0].BusNumber
= 0;
787 ResourceList
->List
[0].PartialResourceList
.Version
= 1;
788 ResourceList
->List
[0].PartialResourceList
.Revision
= 1;
789 ResourceList
->List
[0].PartialResourceList
.Count
= 1;
790 ResourceDescriptor
= ResourceList
->List
[0].PartialResourceList
.PartialDescriptors
;
792 ResourceDescriptor
->Type
= CmResourceTypeBusNumber
;
793 ResourceDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
794 ResourceDescriptor
->u
.BusNumber
.Start
= BusNumber
;
795 ResourceDescriptor
->u
.BusNumber
.Length
= 1;
797 Irp
->IoStatus
.Information
= (ULONG_PTR
)ResourceList
;
798 return STATUS_SUCCESS
;
801 /* Get current resources */
803 AcpiStatus
= AcpiGetCurrentResources(DeviceData
->AcpiHandle
, &Buffer
);
804 if ((!ACPI_SUCCESS(AcpiStatus
) && AcpiStatus
!= AE_BUFFER_OVERFLOW
) ||
807 return Irp
->IoStatus
.Status
;
810 Buffer
.Pointer
= ExAllocatePoolWithTag(PagedPool
, Buffer
.Length
, 'IPCA');
812 return STATUS_INSUFFICIENT_RESOURCES
;
814 AcpiStatus
= AcpiGetCurrentResources(DeviceData
->AcpiHandle
, &Buffer
);
815 if (!ACPI_SUCCESS(AcpiStatus
))
817 DPRINT1("AcpiGetCurrentResources #2 failed (0x%x)\n", AcpiStatus
);
819 return STATUS_UNSUCCESSFUL
;
822 resource
= Buffer
.Pointer
;
823 /* Count number of resources */
824 while (resource
->Type
!= ACPI_RESOURCE_TYPE_END_TAG
)
826 switch (resource
->Type
)
828 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ
:
830 ACPI_RESOURCE_EXTENDED_IRQ
*irq_data
= (ACPI_RESOURCE_EXTENDED_IRQ
*) &resource
->Data
;
831 if (irq_data
->ProducerConsumer
== ACPI_PRODUCER
)
833 NumberOfResources
+= irq_data
->InterruptCount
;
836 case ACPI_RESOURCE_TYPE_IRQ
:
838 ACPI_RESOURCE_IRQ
*irq_data
= (ACPI_RESOURCE_IRQ
*) &resource
->Data
;
839 NumberOfResources
+= irq_data
->InterruptCount
;
842 case ACPI_RESOURCE_TYPE_DMA
:
844 ACPI_RESOURCE_DMA
*dma_data
= (ACPI_RESOURCE_DMA
*) &resource
->Data
;
845 NumberOfResources
+= dma_data
->ChannelCount
;
848 case ACPI_RESOURCE_TYPE_ADDRESS16
:
849 case ACPI_RESOURCE_TYPE_ADDRESS32
:
850 case ACPI_RESOURCE_TYPE_ADDRESS64
:
851 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64
:
853 ACPI_RESOURCE_ADDRESS
*addr_res
= (ACPI_RESOURCE_ADDRESS
*) &resource
->Data
;
854 if (addr_res
->ProducerConsumer
== ACPI_PRODUCER
)
859 case ACPI_RESOURCE_TYPE_MEMORY24
:
860 case ACPI_RESOURCE_TYPE_MEMORY32
:
861 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32
:
862 case ACPI_RESOURCE_TYPE_FIXED_IO
:
863 case ACPI_RESOURCE_TYPE_IO
:
870 DPRINT1("Unknown resource type: %d\n", resource
->Type
);
874 resource
= ACPI_NEXT_RESOURCE(resource
);
877 /* Allocate memory */
878 ResourceListSize
= sizeof(CM_RESOURCE_LIST
) + sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR
) * (NumberOfResources
- 1);
879 ResourceList
= (PCM_RESOURCE_LIST
)ExAllocatePoolWithTag(PagedPool
, ResourceListSize
, 'IPCA');
883 ExFreePoolWithTag(Buffer
.Pointer
, 'IPCA');
884 return STATUS_INSUFFICIENT_RESOURCES
;
886 ResourceList
->Count
= 1;
887 ResourceList
->List
[0].InterfaceType
= Internal
; /* FIXME */
888 ResourceList
->List
[0].BusNumber
= 0; /* We're the only ACPI bus device in the system */
889 ResourceList
->List
[0].PartialResourceList
.Version
= 1;
890 ResourceList
->List
[0].PartialResourceList
.Revision
= 1;
891 ResourceList
->List
[0].PartialResourceList
.Count
= NumberOfResources
;
892 ResourceDescriptor
= ResourceList
->List
[0].PartialResourceList
.PartialDescriptors
;
894 /* Fill resources list structure */
895 resource
= Buffer
.Pointer
;
896 while (resource
->Type
!= ACPI_RESOURCE_TYPE_END_TAG
)
898 switch (resource
->Type
)
900 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ
:
902 ACPI_RESOURCE_EXTENDED_IRQ
*irq_data
= (ACPI_RESOURCE_EXTENDED_IRQ
*) &resource
->Data
;
903 if (irq_data
->ProducerConsumer
== ACPI_PRODUCER
)
905 for (i
= 0; i
< irq_data
->InterruptCount
; i
++)
907 ResourceDescriptor
->Type
= CmResourceTypeInterrupt
;
909 ResourceDescriptor
->ShareDisposition
=
910 (irq_data
->Sharable
== ACPI_SHARED
? CmResourceShareShared
: CmResourceShareDeviceExclusive
);
911 ResourceDescriptor
->Flags
=
912 (irq_data
->Triggering
== ACPI_LEVEL_SENSITIVE
? CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE
: CM_RESOURCE_INTERRUPT_LATCHED
);
913 ResourceDescriptor
->u
.Interrupt
.Level
=
914 ResourceDescriptor
->u
.Interrupt
.Vector
= irq_data
->Interrupts
[i
];
915 ResourceDescriptor
->u
.Interrupt
.Affinity
= (KAFFINITY
)(-1);
917 ResourceDescriptor
++;
921 case ACPI_RESOURCE_TYPE_IRQ
:
923 ACPI_RESOURCE_IRQ
*irq_data
= (ACPI_RESOURCE_IRQ
*) &resource
->Data
;
924 for (i
= 0; i
< irq_data
->InterruptCount
; i
++)
926 ResourceDescriptor
->Type
= CmResourceTypeInterrupt
;
928 ResourceDescriptor
->ShareDisposition
=
929 (irq_data
->Sharable
== ACPI_SHARED
? CmResourceShareShared
: CmResourceShareDeviceExclusive
);
930 ResourceDescriptor
->Flags
=
931 (irq_data
->Triggering
== ACPI_LEVEL_SENSITIVE
? CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE
: CM_RESOURCE_INTERRUPT_LATCHED
);
932 ResourceDescriptor
->u
.Interrupt
.Level
=
933 ResourceDescriptor
->u
.Interrupt
.Vector
= irq_data
->Interrupts
[i
];
934 ResourceDescriptor
->u
.Interrupt
.Affinity
= (KAFFINITY
)(-1);
936 ResourceDescriptor
++;
940 case ACPI_RESOURCE_TYPE_DMA
:
942 ACPI_RESOURCE_DMA
*dma_data
= (ACPI_RESOURCE_DMA
*) &resource
->Data
;
943 for (i
= 0; i
< dma_data
->ChannelCount
; i
++)
945 ResourceDescriptor
->Type
= CmResourceTypeDma
;
946 ResourceDescriptor
->Flags
= 0;
947 switch (dma_data
->Type
)
949 case ACPI_TYPE_A
: ResourceDescriptor
->Flags
|= CM_RESOURCE_DMA_TYPE_A
; break;
950 case ACPI_TYPE_B
: ResourceDescriptor
->Flags
|= CM_RESOURCE_DMA_TYPE_B
; break;
951 case ACPI_TYPE_F
: ResourceDescriptor
->Flags
|= CM_RESOURCE_DMA_TYPE_F
; break;
953 if (dma_data
->BusMaster
== ACPI_BUS_MASTER
)
954 ResourceDescriptor
->Flags
|= CM_RESOURCE_DMA_BUS_MASTER
;
955 switch (dma_data
->Transfer
)
957 case ACPI_TRANSFER_8
: ResourceDescriptor
->Flags
|= CM_RESOURCE_DMA_8
; break;
958 case ACPI_TRANSFER_16
: ResourceDescriptor
->Flags
|= CM_RESOURCE_DMA_16
; break;
959 case ACPI_TRANSFER_8_16
: ResourceDescriptor
->Flags
|= CM_RESOURCE_DMA_8_AND_16
; break;
961 ResourceDescriptor
->u
.Dma
.Channel
= dma_data
->Channels
[i
];
963 ResourceDescriptor
++;
967 case ACPI_RESOURCE_TYPE_IO
:
969 ACPI_RESOURCE_IO
*io_data
= (ACPI_RESOURCE_IO
*) &resource
->Data
;
970 ResourceDescriptor
->Type
= CmResourceTypePort
;
971 ResourceDescriptor
->ShareDisposition
= CmResourceShareDriverExclusive
;
972 ResourceDescriptor
->Flags
= CM_RESOURCE_PORT_IO
;
973 if (io_data
->IoDecode
== ACPI_DECODE_16
)
974 ResourceDescriptor
->Flags
|= CM_RESOURCE_PORT_16_BIT_DECODE
;
976 ResourceDescriptor
->Flags
|= CM_RESOURCE_PORT_10_BIT_DECODE
;
977 ResourceDescriptor
->u
.Port
.Start
.QuadPart
= io_data
->Minimum
;
978 ResourceDescriptor
->u
.Port
.Length
= io_data
->AddressLength
;
980 ResourceDescriptor
++;
983 case ACPI_RESOURCE_TYPE_FIXED_IO
:
985 ACPI_RESOURCE_FIXED_IO
*io_data
= (ACPI_RESOURCE_FIXED_IO
*) &resource
->Data
;
986 ResourceDescriptor
->Type
= CmResourceTypePort
;
987 ResourceDescriptor
->ShareDisposition
= CmResourceShareDriverExclusive
;
988 ResourceDescriptor
->Flags
= CM_RESOURCE_PORT_IO
;
989 ResourceDescriptor
->u
.Port
.Start
.QuadPart
= io_data
->Address
;
990 ResourceDescriptor
->u
.Port
.Length
= io_data
->AddressLength
;
992 ResourceDescriptor
++;
995 case ACPI_RESOURCE_TYPE_ADDRESS16
:
997 ACPI_RESOURCE_ADDRESS16
*addr16_data
= (ACPI_RESOURCE_ADDRESS16
*) &resource
->Data
;
998 if (addr16_data
->ProducerConsumer
== ACPI_PRODUCER
)
1000 if (addr16_data
->ResourceType
== ACPI_BUS_NUMBER_RANGE
)
1002 ResourceDescriptor
->Type
= CmResourceTypeBusNumber
;
1003 ResourceDescriptor
->ShareDisposition
= CmResourceShareShared
;
1004 ResourceDescriptor
->Flags
= 0;
1005 ResourceDescriptor
->u
.BusNumber
.Start
= addr16_data
->Minimum
;
1006 ResourceDescriptor
->u
.BusNumber
.Length
= addr16_data
->AddressLength
;
1008 else if (addr16_data
->ResourceType
== ACPI_IO_RANGE
)
1010 ResourceDescriptor
->Type
= CmResourceTypePort
;
1011 ResourceDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
1012 ResourceDescriptor
->Flags
= CM_RESOURCE_PORT_IO
;
1013 if (addr16_data
->Decode
== ACPI_POS_DECODE
)
1014 ResourceDescriptor
->Flags
|= CM_RESOURCE_PORT_POSITIVE_DECODE
;
1015 ResourceDescriptor
->u
.Port
.Start
.QuadPart
= addr16_data
->Minimum
;
1016 ResourceDescriptor
->u
.Port
.Length
= addr16_data
->AddressLength
;
1020 ResourceDescriptor
->Type
= CmResourceTypeMemory
;
1021 ResourceDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
1022 ResourceDescriptor
->Flags
= 0;
1023 if (addr16_data
->Info
.Mem
.WriteProtect
== ACPI_READ_ONLY_MEMORY
)
1024 ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_ONLY
;
1026 ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_WRITE
;
1027 switch (addr16_data
->Info
.Mem
.Caching
)
1029 case ACPI_CACHABLE_MEMORY
: ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_CACHEABLE
; break;
1030 case ACPI_WRITE_COMBINING_MEMORY
: ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_COMBINEDWRITE
; break;
1031 case ACPI_PREFETCHABLE_MEMORY
: ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_PREFETCHABLE
; break;
1033 ResourceDescriptor
->u
.Memory
.Start
.QuadPart
= addr16_data
->Minimum
;
1034 ResourceDescriptor
->u
.Memory
.Length
= addr16_data
->AddressLength
;
1036 ResourceDescriptor
++;
1039 case ACPI_RESOURCE_TYPE_ADDRESS32
:
1041 ACPI_RESOURCE_ADDRESS32
*addr32_data
= (ACPI_RESOURCE_ADDRESS32
*) &resource
->Data
;
1042 if (addr32_data
->ProducerConsumer
== ACPI_PRODUCER
)
1044 if (addr32_data
->ResourceType
== ACPI_BUS_NUMBER_RANGE
)
1046 ResourceDescriptor
->Type
= CmResourceTypeBusNumber
;
1047 ResourceDescriptor
->ShareDisposition
= CmResourceShareShared
;
1048 ResourceDescriptor
->Flags
= 0;
1049 ResourceDescriptor
->u
.BusNumber
.Start
= addr32_data
->Minimum
;
1050 ResourceDescriptor
->u
.BusNumber
.Length
= addr32_data
->AddressLength
;
1052 else if (addr32_data
->ResourceType
== ACPI_IO_RANGE
)
1054 ResourceDescriptor
->Type
= CmResourceTypePort
;
1055 ResourceDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
1056 ResourceDescriptor
->Flags
= CM_RESOURCE_PORT_IO
;
1057 if (addr32_data
->Decode
== ACPI_POS_DECODE
)
1058 ResourceDescriptor
->Flags
|= CM_RESOURCE_PORT_POSITIVE_DECODE
;
1059 ResourceDescriptor
->u
.Port
.Start
.QuadPart
= addr32_data
->Minimum
;
1060 ResourceDescriptor
->u
.Port
.Length
= addr32_data
->AddressLength
;
1064 ResourceDescriptor
->Type
= CmResourceTypeMemory
;
1065 ResourceDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
1066 ResourceDescriptor
->Flags
= 0;
1067 if (addr32_data
->Info
.Mem
.WriteProtect
== ACPI_READ_ONLY_MEMORY
)
1068 ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_ONLY
;
1070 ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_WRITE
;
1071 switch (addr32_data
->Info
.Mem
.Caching
)
1073 case ACPI_CACHABLE_MEMORY
: ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_CACHEABLE
; break;
1074 case ACPI_WRITE_COMBINING_MEMORY
: ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_COMBINEDWRITE
; break;
1075 case ACPI_PREFETCHABLE_MEMORY
: ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_PREFETCHABLE
; break;
1077 ResourceDescriptor
->u
.Memory
.Start
.QuadPart
= addr32_data
->Minimum
;
1078 ResourceDescriptor
->u
.Memory
.Length
= addr32_data
->AddressLength
;
1080 ResourceDescriptor
++;
1083 case ACPI_RESOURCE_TYPE_ADDRESS64
:
1085 ACPI_RESOURCE_ADDRESS64
*addr64_data
= (ACPI_RESOURCE_ADDRESS64
*) &resource
->Data
;
1086 if (addr64_data
->ProducerConsumer
== ACPI_PRODUCER
)
1088 if (addr64_data
->ResourceType
== ACPI_BUS_NUMBER_RANGE
)
1090 DPRINT1("64-bit bus address is not supported!\n");
1091 ResourceDescriptor
->Type
= CmResourceTypeBusNumber
;
1092 ResourceDescriptor
->ShareDisposition
= CmResourceShareShared
;
1093 ResourceDescriptor
->Flags
= 0;
1094 ResourceDescriptor
->u
.BusNumber
.Start
= (ULONG
)addr64_data
->Minimum
;
1095 ResourceDescriptor
->u
.BusNumber
.Length
= addr64_data
->AddressLength
;
1097 else if (addr64_data
->ResourceType
== ACPI_IO_RANGE
)
1099 ResourceDescriptor
->Type
= CmResourceTypePort
;
1100 ResourceDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
1101 ResourceDescriptor
->Flags
= CM_RESOURCE_PORT_IO
;
1102 if (addr64_data
->Decode
== ACPI_POS_DECODE
)
1103 ResourceDescriptor
->Flags
|= CM_RESOURCE_PORT_POSITIVE_DECODE
;
1104 ResourceDescriptor
->u
.Port
.Start
.QuadPart
= addr64_data
->Minimum
;
1105 ResourceDescriptor
->u
.Port
.Length
= addr64_data
->AddressLength
;
1109 ResourceDescriptor
->Type
= CmResourceTypeMemory
;
1110 ResourceDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
1111 ResourceDescriptor
->Flags
= 0;
1112 if (addr64_data
->Info
.Mem
.WriteProtect
== ACPI_READ_ONLY_MEMORY
)
1113 ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_ONLY
;
1115 ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_WRITE
;
1116 switch (addr64_data
->Info
.Mem
.Caching
)
1118 case ACPI_CACHABLE_MEMORY
: ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_CACHEABLE
; break;
1119 case ACPI_WRITE_COMBINING_MEMORY
: ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_COMBINEDWRITE
; break;
1120 case ACPI_PREFETCHABLE_MEMORY
: ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_PREFETCHABLE
; break;
1122 ResourceDescriptor
->u
.Memory
.Start
.QuadPart
= addr64_data
->Minimum
;
1123 ResourceDescriptor
->u
.Memory
.Length
= addr64_data
->AddressLength
;
1125 ResourceDescriptor
++;
1128 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64
:
1130 ACPI_RESOURCE_EXTENDED_ADDRESS64
*addr64_data
= (ACPI_RESOURCE_EXTENDED_ADDRESS64
*) &resource
->Data
;
1131 if (addr64_data
->ProducerConsumer
== ACPI_PRODUCER
)
1133 if (addr64_data
->ResourceType
== ACPI_BUS_NUMBER_RANGE
)
1135 DPRINT1("64-bit bus address is not supported!\n");
1136 ResourceDescriptor
->Type
= CmResourceTypeBusNumber
;
1137 ResourceDescriptor
->ShareDisposition
= CmResourceShareShared
;
1138 ResourceDescriptor
->Flags
= 0;
1139 ResourceDescriptor
->u
.BusNumber
.Start
= (ULONG
)addr64_data
->Minimum
;
1140 ResourceDescriptor
->u
.BusNumber
.Length
= addr64_data
->AddressLength
;
1142 else if (addr64_data
->ResourceType
== ACPI_IO_RANGE
)
1144 ResourceDescriptor
->Type
= CmResourceTypePort
;
1145 ResourceDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
1146 ResourceDescriptor
->Flags
= CM_RESOURCE_PORT_IO
;
1147 if (addr64_data
->Decode
== ACPI_POS_DECODE
)
1148 ResourceDescriptor
->Flags
|= CM_RESOURCE_PORT_POSITIVE_DECODE
;
1149 ResourceDescriptor
->u
.Port
.Start
.QuadPart
= addr64_data
->Minimum
;
1150 ResourceDescriptor
->u
.Port
.Length
= addr64_data
->AddressLength
;
1154 ResourceDescriptor
->Type
= CmResourceTypeMemory
;
1155 ResourceDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
1156 ResourceDescriptor
->Flags
= 0;
1157 if (addr64_data
->Info
.Mem
.WriteProtect
== ACPI_READ_ONLY_MEMORY
)
1158 ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_ONLY
;
1160 ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_WRITE
;
1161 switch (addr64_data
->Info
.Mem
.Caching
)
1163 case ACPI_CACHABLE_MEMORY
: ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_CACHEABLE
; break;
1164 case ACPI_WRITE_COMBINING_MEMORY
: ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_COMBINEDWRITE
; break;
1165 case ACPI_PREFETCHABLE_MEMORY
: ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_PREFETCHABLE
; break;
1167 ResourceDescriptor
->u
.Memory
.Start
.QuadPart
= addr64_data
->Minimum
;
1168 ResourceDescriptor
->u
.Memory
.Length
= addr64_data
->AddressLength
;
1170 ResourceDescriptor
++;
1173 case ACPI_RESOURCE_TYPE_MEMORY24
:
1175 ACPI_RESOURCE_MEMORY24
*mem24_data
= (ACPI_RESOURCE_MEMORY24
*) &resource
->Data
;
1176 ResourceDescriptor
->Type
= CmResourceTypeMemory
;
1177 ResourceDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
1178 ResourceDescriptor
->Flags
= CM_RESOURCE_MEMORY_24
;
1179 if (mem24_data
->WriteProtect
== ACPI_READ_ONLY_MEMORY
)
1180 ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_ONLY
;
1182 ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_WRITE
;
1183 ResourceDescriptor
->u
.Memory
.Start
.QuadPart
= mem24_data
->Minimum
;
1184 ResourceDescriptor
->u
.Memory
.Length
= mem24_data
->AddressLength
;
1186 ResourceDescriptor
++;
1189 case ACPI_RESOURCE_TYPE_MEMORY32
:
1191 ACPI_RESOURCE_MEMORY32
*mem32_data
= (ACPI_RESOURCE_MEMORY32
*) &resource
->Data
;
1192 ResourceDescriptor
->Type
= CmResourceTypeMemory
;
1193 ResourceDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
1194 ResourceDescriptor
->Flags
= 0;
1195 if (mem32_data
->WriteProtect
== ACPI_READ_ONLY_MEMORY
)
1196 ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_ONLY
;
1198 ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_WRITE
;
1199 ResourceDescriptor
->u
.Memory
.Start
.QuadPart
= mem32_data
->Minimum
;
1200 ResourceDescriptor
->u
.Memory
.Length
= mem32_data
->AddressLength
;
1202 ResourceDescriptor
++;
1205 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32
:
1207 ACPI_RESOURCE_FIXED_MEMORY32
*memfixed32_data
= (ACPI_RESOURCE_FIXED_MEMORY32
*) &resource
->Data
;
1208 ResourceDescriptor
->Type
= CmResourceTypeMemory
;
1209 ResourceDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
1210 ResourceDescriptor
->Flags
= 0;
1211 if (memfixed32_data
->WriteProtect
== ACPI_READ_ONLY_MEMORY
)
1212 ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_ONLY
;
1214 ResourceDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_WRITE
;
1215 ResourceDescriptor
->u
.Memory
.Start
.QuadPart
= memfixed32_data
->Address
;
1216 ResourceDescriptor
->u
.Memory
.Length
= memfixed32_data
->AddressLength
;
1218 ResourceDescriptor
++;
1226 resource
= ACPI_NEXT_RESOURCE(resource
);
1229 ExFreePoolWithTag(Buffer
.Pointer
, 'IPCA');
1230 Irp
->IoStatus
.Information
= (ULONG_PTR
)ResourceList
;
1231 return STATUS_SUCCESS
;
1235 Bus_PDO_QueryResourceRequirements(
1236 PPDO_DEVICE_DATA DeviceData
,
1239 ULONG NumberOfResources
= 0;
1240 ACPI_STATUS AcpiStatus
;
1242 ACPI_RESOURCE
* resource
;
1243 ULONG i
, RequirementsListSize
;
1244 PIO_RESOURCE_REQUIREMENTS_LIST RequirementsList
;
1245 PIO_RESOURCE_DESCRIPTOR RequirementDescriptor
;
1246 BOOLEAN CurrentRes
= FALSE
;
1250 if (!DeviceData
->AcpiHandle
)
1252 return Irp
->IoStatus
.Status
;
1255 /* Handle the PCI root manually */
1256 if (wcsstr(DeviceData
->HardwareIDs
, L
"PNP0A03") != 0 ||
1257 wcsstr(DeviceData
->HardwareIDs
, L
"PNP0A08") != 0)
1259 return Irp
->IoStatus
.Status
;
1262 /* Get current resources */
1267 AcpiStatus
= AcpiGetCurrentResources(DeviceData
->AcpiHandle
, &Buffer
);
1269 AcpiStatus
= AcpiGetPossibleResources(DeviceData
->AcpiHandle
, &Buffer
);
1270 if ((!ACPI_SUCCESS(AcpiStatus
) && AcpiStatus
!= AE_BUFFER_OVERFLOW
) ||
1276 return Irp
->IoStatus
.Status
;
1282 Buffer
.Pointer
= ExAllocatePoolWithTag(PagedPool
, Buffer
.Length
, 'IPCA');
1283 if (!Buffer
.Pointer
)
1284 return STATUS_INSUFFICIENT_RESOURCES
;
1287 AcpiStatus
= AcpiGetCurrentResources(DeviceData
->AcpiHandle
, &Buffer
);
1289 AcpiStatus
= AcpiGetPossibleResources(DeviceData
->AcpiHandle
, &Buffer
);
1290 if (!ACPI_SUCCESS(AcpiStatus
))
1292 DPRINT1("AcpiGetCurrentResources #2 failed (0x%x)\n", AcpiStatus
);
1294 return STATUS_UNSUCCESSFUL
;
1297 resource
= Buffer
.Pointer
;
1298 /* Count number of resources */
1299 while (resource
->Type
!= ACPI_RESOURCE_TYPE_END_TAG
)
1301 switch (resource
->Type
)
1303 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ
:
1305 ACPI_RESOURCE_EXTENDED_IRQ
*irq_data
= (ACPI_RESOURCE_EXTENDED_IRQ
*) &resource
->Data
;
1306 if (irq_data
->ProducerConsumer
== ACPI_PRODUCER
)
1308 NumberOfResources
+= irq_data
->InterruptCount
;
1311 case ACPI_RESOURCE_TYPE_IRQ
:
1313 ACPI_RESOURCE_IRQ
*irq_data
= (ACPI_RESOURCE_IRQ
*) &resource
->Data
;
1314 NumberOfResources
+= irq_data
->InterruptCount
;
1317 case ACPI_RESOURCE_TYPE_DMA
:
1319 ACPI_RESOURCE_DMA
*dma_data
= (ACPI_RESOURCE_DMA
*) &resource
->Data
;
1320 NumberOfResources
+= dma_data
->ChannelCount
;
1323 case ACPI_RESOURCE_TYPE_ADDRESS16
:
1324 case ACPI_RESOURCE_TYPE_ADDRESS32
:
1325 case ACPI_RESOURCE_TYPE_ADDRESS64
:
1326 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64
:
1328 ACPI_RESOURCE_ADDRESS
*res_addr
= (ACPI_RESOURCE_ADDRESS
*) &resource
->Data
;
1329 if (res_addr
->ProducerConsumer
== ACPI_PRODUCER
)
1331 NumberOfResources
++;
1334 case ACPI_RESOURCE_TYPE_MEMORY24
:
1335 case ACPI_RESOURCE_TYPE_MEMORY32
:
1336 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32
:
1337 case ACPI_RESOURCE_TYPE_FIXED_IO
:
1338 case ACPI_RESOURCE_TYPE_IO
:
1340 NumberOfResources
++;
1348 resource
= ACPI_NEXT_RESOURCE(resource
);
1351 RequirementsListSize
= sizeof(IO_RESOURCE_REQUIREMENTS_LIST
) + sizeof(IO_RESOURCE_DESCRIPTOR
) * (NumberOfResources
- 1);
1352 RequirementsList
= (PIO_RESOURCE_REQUIREMENTS_LIST
)ExAllocatePoolWithTag(PagedPool
, RequirementsListSize
, 'IPCA');
1354 if (!RequirementsList
)
1356 ExFreePoolWithTag(Buffer
.Pointer
, 'IPCA');
1357 return STATUS_INSUFFICIENT_RESOURCES
;
1359 RequirementsList
->ListSize
= RequirementsListSize
;
1360 RequirementsList
->InterfaceType
= Internal
;
1361 RequirementsList
->BusNumber
= 0;
1362 RequirementsList
->SlotNumber
= 0; /* Not used by WDM drivers */
1363 RequirementsList
->AlternativeLists
= 1;
1364 RequirementsList
->List
[0].Version
= 1;
1365 RequirementsList
->List
[0].Revision
= 1;
1366 RequirementsList
->List
[0].Count
= NumberOfResources
;
1367 RequirementDescriptor
= RequirementsList
->List
[0].Descriptors
;
1369 /* Fill resources list structure */
1370 resource
= Buffer
.Pointer
;
1371 while (resource
->Type
!= ACPI_RESOURCE_TYPE_END_TAG
&& resource
->Type
!= ACPI_RESOURCE_TYPE_END_DEPENDENT
)
1373 switch (resource
->Type
)
1375 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ
:
1377 ACPI_RESOURCE_EXTENDED_IRQ
*irq_data
= (ACPI_RESOURCE_EXTENDED_IRQ
*) &resource
->Data
;
1378 if (irq_data
->ProducerConsumer
== ACPI_PRODUCER
)
1380 for (i
= 0; i
< irq_data
->InterruptCount
; i
++)
1382 RequirementDescriptor
->Option
= (i
== 0) ? IO_RESOURCE_PREFERRED
: IO_RESOURCE_ALTERNATIVE
;
1383 RequirementDescriptor
->Type
= CmResourceTypeInterrupt
;
1384 RequirementDescriptor
->ShareDisposition
= (irq_data
->Sharable
== ACPI_SHARED
? CmResourceShareShared
: CmResourceShareDeviceExclusive
);
1385 RequirementDescriptor
->Flags
=(irq_data
->Triggering
== ACPI_LEVEL_SENSITIVE
? CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE
: CM_RESOURCE_INTERRUPT_LATCHED
);
1386 RequirementDescriptor
->u
.Interrupt
.MinimumVector
=
1387 RequirementDescriptor
->u
.Interrupt
.MaximumVector
= irq_data
->Interrupts
[i
];
1389 RequirementDescriptor
++;
1393 case ACPI_RESOURCE_TYPE_IRQ
:
1395 ACPI_RESOURCE_IRQ
*irq_data
= (ACPI_RESOURCE_IRQ
*) &resource
->Data
;
1396 for (i
= 0; i
< irq_data
->InterruptCount
; i
++)
1398 RequirementDescriptor
->Option
= (i
== 0) ? IO_RESOURCE_PREFERRED
: IO_RESOURCE_ALTERNATIVE
;
1399 RequirementDescriptor
->Type
= CmResourceTypeInterrupt
;
1400 RequirementDescriptor
->ShareDisposition
= (irq_data
->Sharable
== ACPI_SHARED
? CmResourceShareShared
: CmResourceShareDeviceExclusive
);
1401 RequirementDescriptor
->Flags
=(irq_data
->Triggering
== ACPI_LEVEL_SENSITIVE
? CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE
: CM_RESOURCE_INTERRUPT_LATCHED
);
1402 RequirementDescriptor
->u
.Interrupt
.MinimumVector
=
1403 RequirementDescriptor
->u
.Interrupt
.MaximumVector
= irq_data
->Interrupts
[i
];
1405 RequirementDescriptor
++;
1409 case ACPI_RESOURCE_TYPE_DMA
:
1411 ACPI_RESOURCE_DMA
*dma_data
= (ACPI_RESOURCE_DMA
*) &resource
->Data
;
1412 for (i
= 0; i
< dma_data
->ChannelCount
; i
++)
1414 RequirementDescriptor
->Type
= CmResourceTypeDma
;
1415 RequirementDescriptor
->Flags
= 0;
1416 switch (dma_data
->Type
)
1418 case ACPI_TYPE_A
: RequirementDescriptor
->Flags
|= CM_RESOURCE_DMA_TYPE_A
; break;
1419 case ACPI_TYPE_B
: RequirementDescriptor
->Flags
|= CM_RESOURCE_DMA_TYPE_B
; break;
1420 case ACPI_TYPE_F
: RequirementDescriptor
->Flags
|= CM_RESOURCE_DMA_TYPE_F
; break;
1422 if (dma_data
->BusMaster
== ACPI_BUS_MASTER
)
1423 RequirementDescriptor
->Flags
|= CM_RESOURCE_DMA_BUS_MASTER
;
1424 switch (dma_data
->Transfer
)
1426 case ACPI_TRANSFER_8
: RequirementDescriptor
->Flags
|= CM_RESOURCE_DMA_8
; break;
1427 case ACPI_TRANSFER_16
: RequirementDescriptor
->Flags
|= CM_RESOURCE_DMA_16
; break;
1428 case ACPI_TRANSFER_8_16
: RequirementDescriptor
->Flags
|= CM_RESOURCE_DMA_8_AND_16
; break;
1431 RequirementDescriptor
->Option
= (i
== 0) ? IO_RESOURCE_PREFERRED
: IO_RESOURCE_ALTERNATIVE
;
1432 RequirementDescriptor
->ShareDisposition
= CmResourceShareDriverExclusive
;
1433 RequirementDescriptor
->u
.Dma
.MinimumChannel
=
1434 RequirementDescriptor
->u
.Dma
.MaximumChannel
= dma_data
->Channels
[i
];
1435 RequirementDescriptor
++;
1439 case ACPI_RESOURCE_TYPE_IO
:
1441 ACPI_RESOURCE_IO
*io_data
= (ACPI_RESOURCE_IO
*) &resource
->Data
;
1442 RequirementDescriptor
->Flags
= CM_RESOURCE_PORT_IO
;
1443 if (io_data
->IoDecode
== ACPI_DECODE_16
)
1444 RequirementDescriptor
->Flags
|= CM_RESOURCE_PORT_16_BIT_DECODE
;
1446 RequirementDescriptor
->Flags
|= CM_RESOURCE_PORT_10_BIT_DECODE
;
1447 RequirementDescriptor
->u
.Port
.Length
= io_data
->AddressLength
;
1448 RequirementDescriptor
->Option
= CurrentRes
? 0 : IO_RESOURCE_PREFERRED
;
1449 RequirementDescriptor
->Type
= CmResourceTypePort
;
1450 RequirementDescriptor
->ShareDisposition
= CmResourceShareDriverExclusive
;
1451 RequirementDescriptor
->u
.Port
.Alignment
= io_data
->Alignment
;
1452 RequirementDescriptor
->u
.Port
.MinimumAddress
.QuadPart
= io_data
->Minimum
;
1453 RequirementDescriptor
->u
.Port
.MaximumAddress
.QuadPart
= io_data
->Maximum
+ io_data
->AddressLength
- 1;
1455 RequirementDescriptor
++;
1458 case ACPI_RESOURCE_TYPE_FIXED_IO
:
1460 ACPI_RESOURCE_FIXED_IO
*io_data
= (ACPI_RESOURCE_FIXED_IO
*) &resource
->Data
;
1461 RequirementDescriptor
->Flags
= CM_RESOURCE_PORT_IO
;
1462 RequirementDescriptor
->u
.Port
.Length
= io_data
->AddressLength
;
1463 RequirementDescriptor
->Option
= CurrentRes
? 0 : IO_RESOURCE_PREFERRED
;
1464 RequirementDescriptor
->Type
= CmResourceTypePort
;
1465 RequirementDescriptor
->ShareDisposition
= CmResourceShareDriverExclusive
;
1466 RequirementDescriptor
->u
.Port
.Alignment
= 1;
1467 RequirementDescriptor
->u
.Port
.MinimumAddress
.QuadPart
= io_data
->Address
;
1468 RequirementDescriptor
->u
.Port
.MaximumAddress
.QuadPart
= io_data
->Address
+ io_data
->AddressLength
- 1;
1470 RequirementDescriptor
++;
1473 case ACPI_RESOURCE_TYPE_ADDRESS16
:
1475 ACPI_RESOURCE_ADDRESS16
*addr16_data
= (ACPI_RESOURCE_ADDRESS16
*) &resource
->Data
;
1476 if (addr16_data
->ProducerConsumer
== ACPI_PRODUCER
)
1478 RequirementDescriptor
->Option
= CurrentRes
? 0 : IO_RESOURCE_PREFERRED
;
1479 if (addr16_data
->ResourceType
== ACPI_BUS_NUMBER_RANGE
)
1481 RequirementDescriptor
->Type
= CmResourceTypeBusNumber
;
1482 RequirementDescriptor
->ShareDisposition
= CmResourceShareShared
;
1483 RequirementDescriptor
->Flags
= 0;
1484 RequirementDescriptor
->u
.BusNumber
.MinBusNumber
= addr16_data
->Minimum
;
1485 RequirementDescriptor
->u
.BusNumber
.MaxBusNumber
= addr16_data
->Maximum
+ addr16_data
->AddressLength
- 1;
1486 RequirementDescriptor
->u
.BusNumber
.Length
= addr16_data
->AddressLength
;
1488 else if (addr16_data
->ResourceType
== ACPI_IO_RANGE
)
1490 RequirementDescriptor
->Type
= CmResourceTypePort
;
1491 RequirementDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
1492 RequirementDescriptor
->Flags
= CM_RESOURCE_PORT_IO
;
1493 if (addr16_data
->Decode
== ACPI_POS_DECODE
)
1494 RequirementDescriptor
->Flags
|= CM_RESOURCE_PORT_POSITIVE_DECODE
;
1495 RequirementDescriptor
->u
.Port
.MinimumAddress
.QuadPart
= addr16_data
->Minimum
;
1496 RequirementDescriptor
->u
.Port
.MaximumAddress
.QuadPart
= addr16_data
->Maximum
+ addr16_data
->AddressLength
- 1;
1497 RequirementDescriptor
->u
.Port
.Length
= addr16_data
->AddressLength
;
1501 RequirementDescriptor
->Type
= CmResourceTypeMemory
;
1502 RequirementDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
1503 RequirementDescriptor
->Flags
= 0;
1504 if (addr16_data
->Info
.Mem
.WriteProtect
== ACPI_READ_ONLY_MEMORY
)
1505 RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_ONLY
;
1507 RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_WRITE
;
1508 switch (addr16_data
->Info
.Mem
.Caching
)
1510 case ACPI_CACHABLE_MEMORY
: RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_CACHEABLE
; break;
1511 case ACPI_WRITE_COMBINING_MEMORY
: RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_COMBINEDWRITE
; break;
1512 case ACPI_PREFETCHABLE_MEMORY
: RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_PREFETCHABLE
; break;
1514 RequirementDescriptor
->u
.Memory
.MinimumAddress
.QuadPart
= addr16_data
->Minimum
;
1515 RequirementDescriptor
->u
.Memory
.MaximumAddress
.QuadPart
= addr16_data
->Maximum
+ addr16_data
->AddressLength
- 1;
1516 RequirementDescriptor
->u
.Memory
.Length
= addr16_data
->AddressLength
;
1518 RequirementDescriptor
++;
1521 case ACPI_RESOURCE_TYPE_ADDRESS32
:
1523 ACPI_RESOURCE_ADDRESS32
*addr32_data
= (ACPI_RESOURCE_ADDRESS32
*) &resource
->Data
;
1524 if (addr32_data
->ProducerConsumer
== ACPI_PRODUCER
)
1526 RequirementDescriptor
->Option
= CurrentRes
? 0 : IO_RESOURCE_PREFERRED
;
1527 if (addr32_data
->ResourceType
== ACPI_BUS_NUMBER_RANGE
)
1529 RequirementDescriptor
->Type
= CmResourceTypeBusNumber
;
1530 RequirementDescriptor
->ShareDisposition
= CmResourceShareShared
;
1531 RequirementDescriptor
->Flags
= 0;
1532 RequirementDescriptor
->u
.BusNumber
.MinBusNumber
= addr32_data
->Minimum
;
1533 RequirementDescriptor
->u
.BusNumber
.MaxBusNumber
= addr32_data
->Maximum
+ addr32_data
->AddressLength
- 1;
1534 RequirementDescriptor
->u
.BusNumber
.Length
= addr32_data
->AddressLength
;
1536 else if (addr32_data
->ResourceType
== ACPI_IO_RANGE
)
1538 RequirementDescriptor
->Type
= CmResourceTypePort
;
1539 RequirementDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
1540 RequirementDescriptor
->Flags
= CM_RESOURCE_PORT_IO
;
1541 if (addr32_data
->Decode
== ACPI_POS_DECODE
)
1542 RequirementDescriptor
->Flags
|= CM_RESOURCE_PORT_POSITIVE_DECODE
;
1543 RequirementDescriptor
->u
.Port
.MinimumAddress
.QuadPart
= addr32_data
->Minimum
;
1544 RequirementDescriptor
->u
.Port
.MaximumAddress
.QuadPart
= addr32_data
->Maximum
+ addr32_data
->AddressLength
- 1;
1545 RequirementDescriptor
->u
.Port
.Length
= addr32_data
->AddressLength
;
1549 RequirementDescriptor
->Type
= CmResourceTypeMemory
;
1550 RequirementDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
1551 RequirementDescriptor
->Flags
= 0;
1552 if (addr32_data
->Info
.Mem
.WriteProtect
== ACPI_READ_ONLY_MEMORY
)
1553 RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_ONLY
;
1555 RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_WRITE
;
1556 switch (addr32_data
->Info
.Mem
.Caching
)
1558 case ACPI_CACHABLE_MEMORY
: RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_CACHEABLE
; break;
1559 case ACPI_WRITE_COMBINING_MEMORY
: RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_COMBINEDWRITE
; break;
1560 case ACPI_PREFETCHABLE_MEMORY
: RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_PREFETCHABLE
; break;
1562 RequirementDescriptor
->u
.Memory
.MinimumAddress
.QuadPart
= addr32_data
->Minimum
;
1563 RequirementDescriptor
->u
.Memory
.MaximumAddress
.QuadPart
= addr32_data
->Maximum
+ addr32_data
->AddressLength
- 1;
1564 RequirementDescriptor
->u
.Memory
.Length
= addr32_data
->AddressLength
;
1566 RequirementDescriptor
++;
1569 case ACPI_RESOURCE_TYPE_ADDRESS64
:
1571 ACPI_RESOURCE_ADDRESS64
*addr64_data
= (ACPI_RESOURCE_ADDRESS64
*) &resource
->Data
;
1572 if (addr64_data
->ProducerConsumer
== ACPI_PRODUCER
)
1574 RequirementDescriptor
->Option
= CurrentRes
? 0 : IO_RESOURCE_PREFERRED
;
1575 if (addr64_data
->ResourceType
== ACPI_BUS_NUMBER_RANGE
)
1577 DPRINT1("64-bit bus address is not supported!\n");
1578 RequirementDescriptor
->Type
= CmResourceTypeBusNumber
;
1579 RequirementDescriptor
->ShareDisposition
= CmResourceShareShared
;
1580 RequirementDescriptor
->Flags
= 0;
1581 RequirementDescriptor
->u
.BusNumber
.MinBusNumber
= (ULONG
)addr64_data
->Minimum
;
1582 RequirementDescriptor
->u
.BusNumber
.MaxBusNumber
= (ULONG
)addr64_data
->Maximum
+ addr64_data
->AddressLength
- 1;
1583 RequirementDescriptor
->u
.BusNumber
.Length
= addr64_data
->AddressLength
;
1585 else if (addr64_data
->ResourceType
== ACPI_IO_RANGE
)
1587 RequirementDescriptor
->Type
= CmResourceTypePort
;
1588 RequirementDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
1589 RequirementDescriptor
->Flags
= CM_RESOURCE_PORT_IO
;
1590 if (addr64_data
->Decode
== ACPI_POS_DECODE
)
1591 RequirementDescriptor
->Flags
|= CM_RESOURCE_PORT_POSITIVE_DECODE
;
1592 RequirementDescriptor
->u
.Port
.MinimumAddress
.QuadPart
= addr64_data
->Minimum
;
1593 RequirementDescriptor
->u
.Port
.MaximumAddress
.QuadPart
= addr64_data
->Maximum
+ addr64_data
->AddressLength
- 1;
1594 RequirementDescriptor
->u
.Port
.Length
= addr64_data
->AddressLength
;
1598 RequirementDescriptor
->Type
= CmResourceTypeMemory
;
1599 RequirementDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
1600 RequirementDescriptor
->Flags
= 0;
1601 if (addr64_data
->Info
.Mem
.WriteProtect
== ACPI_READ_ONLY_MEMORY
)
1602 RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_ONLY
;
1604 RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_WRITE
;
1605 switch (addr64_data
->Info
.Mem
.Caching
)
1607 case ACPI_CACHABLE_MEMORY
: RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_CACHEABLE
; break;
1608 case ACPI_WRITE_COMBINING_MEMORY
: RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_COMBINEDWRITE
; break;
1609 case ACPI_PREFETCHABLE_MEMORY
: RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_PREFETCHABLE
; break;
1611 RequirementDescriptor
->u
.Memory
.MinimumAddress
.QuadPart
= addr64_data
->Minimum
;
1612 RequirementDescriptor
->u
.Memory
.MaximumAddress
.QuadPart
= addr64_data
->Maximum
+ addr64_data
->AddressLength
- 1;
1613 RequirementDescriptor
->u
.Memory
.Length
= addr64_data
->AddressLength
;
1615 RequirementDescriptor
++;
1618 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64
:
1620 ACPI_RESOURCE_EXTENDED_ADDRESS64
*addr64_data
= (ACPI_RESOURCE_EXTENDED_ADDRESS64
*) &resource
->Data
;
1621 if (addr64_data
->ProducerConsumer
== ACPI_PRODUCER
)
1623 RequirementDescriptor
->Option
= CurrentRes
? 0 : IO_RESOURCE_PREFERRED
;
1624 if (addr64_data
->ResourceType
== ACPI_BUS_NUMBER_RANGE
)
1626 DPRINT1("64-bit bus address is not supported!\n");
1627 RequirementDescriptor
->Type
= CmResourceTypeBusNumber
;
1628 RequirementDescriptor
->ShareDisposition
= CmResourceShareShared
;
1629 RequirementDescriptor
->Flags
= 0;
1630 RequirementDescriptor
->u
.BusNumber
.MinBusNumber
= (ULONG
)addr64_data
->Minimum
;
1631 RequirementDescriptor
->u
.BusNumber
.MaxBusNumber
= (ULONG
)addr64_data
->Maximum
+ addr64_data
->AddressLength
- 1;
1632 RequirementDescriptor
->u
.BusNumber
.Length
= addr64_data
->AddressLength
;
1634 else if (addr64_data
->ResourceType
== ACPI_IO_RANGE
)
1636 RequirementDescriptor
->Type
= CmResourceTypePort
;
1637 RequirementDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
1638 RequirementDescriptor
->Flags
= CM_RESOURCE_PORT_IO
;
1639 if (addr64_data
->Decode
== ACPI_POS_DECODE
)
1640 RequirementDescriptor
->Flags
|= CM_RESOURCE_PORT_POSITIVE_DECODE
;
1641 RequirementDescriptor
->u
.Port
.MinimumAddress
.QuadPart
= addr64_data
->Minimum
;
1642 RequirementDescriptor
->u
.Port
.MaximumAddress
.QuadPart
= addr64_data
->Maximum
+ addr64_data
->AddressLength
- 1;
1643 RequirementDescriptor
->u
.Port
.Length
= addr64_data
->AddressLength
;
1647 RequirementDescriptor
->Type
= CmResourceTypeMemory
;
1648 RequirementDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
1649 RequirementDescriptor
->Flags
= 0;
1650 if (addr64_data
->Info
.Mem
.WriteProtect
== ACPI_READ_ONLY_MEMORY
)
1651 RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_ONLY
;
1653 RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_WRITE
;
1654 switch (addr64_data
->Info
.Mem
.Caching
)
1656 case ACPI_CACHABLE_MEMORY
: RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_CACHEABLE
; break;
1657 case ACPI_WRITE_COMBINING_MEMORY
: RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_COMBINEDWRITE
; break;
1658 case ACPI_PREFETCHABLE_MEMORY
: RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_PREFETCHABLE
; break;
1660 RequirementDescriptor
->u
.Memory
.MinimumAddress
.QuadPart
= addr64_data
->Minimum
;
1661 RequirementDescriptor
->u
.Memory
.MaximumAddress
.QuadPart
= addr64_data
->Maximum
+ addr64_data
->AddressLength
- 1;
1662 RequirementDescriptor
->u
.Memory
.Length
= addr64_data
->AddressLength
;
1664 RequirementDescriptor
++;
1667 case ACPI_RESOURCE_TYPE_MEMORY24
:
1669 ACPI_RESOURCE_MEMORY24
*mem24_data
= (ACPI_RESOURCE_MEMORY24
*) &resource
->Data
;
1670 RequirementDescriptor
->Option
= CurrentRes
? 0 : IO_RESOURCE_PREFERRED
;
1671 RequirementDescriptor
->Type
= CmResourceTypeMemory
;
1672 RequirementDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
1673 RequirementDescriptor
->Flags
= CM_RESOURCE_MEMORY_24
;
1674 if (mem24_data
->WriteProtect
== ACPI_READ_ONLY_MEMORY
)
1675 RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_ONLY
;
1677 RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_WRITE
;
1678 RequirementDescriptor
->u
.Memory
.MinimumAddress
.QuadPart
= mem24_data
->Minimum
;
1679 RequirementDescriptor
->u
.Memory
.MaximumAddress
.QuadPart
= mem24_data
->Maximum
+ mem24_data
->AddressLength
- 1;
1680 RequirementDescriptor
->u
.Memory
.Length
= mem24_data
->AddressLength
;
1682 RequirementDescriptor
++;
1685 case ACPI_RESOURCE_TYPE_MEMORY32
:
1687 ACPI_RESOURCE_MEMORY32
*mem32_data
= (ACPI_RESOURCE_MEMORY32
*) &resource
->Data
;
1688 RequirementDescriptor
->Option
= CurrentRes
? 0 : IO_RESOURCE_PREFERRED
;
1689 RequirementDescriptor
->Type
= CmResourceTypeMemory
;
1690 RequirementDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
1691 RequirementDescriptor
->Flags
= 0;
1692 if (mem32_data
->WriteProtect
== ACPI_READ_ONLY_MEMORY
)
1693 RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_ONLY
;
1695 RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_WRITE
;
1696 RequirementDescriptor
->u
.Memory
.MinimumAddress
.QuadPart
= mem32_data
->Minimum
;
1697 RequirementDescriptor
->u
.Memory
.MaximumAddress
.QuadPart
= mem32_data
->Maximum
+ mem32_data
->AddressLength
- 1;
1698 RequirementDescriptor
->u
.Memory
.Length
= mem32_data
->AddressLength
;
1700 RequirementDescriptor
++;
1703 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32
:
1705 ACPI_RESOURCE_FIXED_MEMORY32
*fixedmem32_data
= (ACPI_RESOURCE_FIXED_MEMORY32
*) &resource
->Data
;
1706 RequirementDescriptor
->Option
= CurrentRes
? 0 : IO_RESOURCE_PREFERRED
;
1707 RequirementDescriptor
->Type
= CmResourceTypeMemory
;
1708 RequirementDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
1709 RequirementDescriptor
->Flags
= 0;
1710 if (fixedmem32_data
->WriteProtect
== ACPI_READ_ONLY_MEMORY
)
1711 RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_ONLY
;
1713 RequirementDescriptor
->Flags
|= CM_RESOURCE_MEMORY_READ_WRITE
;
1714 RequirementDescriptor
->u
.Memory
.MinimumAddress
.QuadPart
= fixedmem32_data
->Address
;
1715 RequirementDescriptor
->u
.Memory
.MaximumAddress
.QuadPart
= fixedmem32_data
->Address
+ fixedmem32_data
->AddressLength
- 1;
1716 RequirementDescriptor
->u
.Memory
.Length
= fixedmem32_data
->AddressLength
;
1718 RequirementDescriptor
++;
1726 resource
= ACPI_NEXT_RESOURCE(resource
);
1728 ExFreePoolWithTag(Buffer
.Pointer
, 'IPCA');
1730 Irp
->IoStatus
.Information
= (ULONG_PTR
)RequirementsList
;
1732 return STATUS_SUCCESS
;
1736 Bus_PDO_QueryDeviceRelations(
1737 PPDO_DEVICE_DATA DeviceData
,
1741 Routine Description:
1743 The PnP Manager sends this IRP to gather information about
1744 devices with a relationship to the specified device.
1745 Bus drivers must handle this request for TargetDeviceRelation
1746 for their child devices (child PDOs).
1748 If a driver returns relations in response to this IRP,
1749 it allocates a DEVICE_RELATIONS structure from paged
1750 memory containing a count and the appropriate number of
1751 device object pointers. The PnP Manager frees the structure
1752 when it is no longer needed. If a driver replaces a
1753 DEVICE_RELATIONS structure allocated by another driver,
1754 it must free the previous structure.
1756 A driver must reference the PDO of any device that it
1757 reports in this IRP (ObReferenceObject). The PnP Manager
1758 removes the reference when appropriate.
1762 DeviceData - Pointer to the PDO's device extension.
1763 Irp - Pointer to the irp.
1772 PIO_STACK_LOCATION stack
;
1773 PDEVICE_RELATIONS deviceRelations
;
1778 stack
= IoGetCurrentIrpStackLocation (Irp
);
1780 switch (stack
->Parameters
.QueryDeviceRelations
.Type
) {
1782 case TargetDeviceRelation
:
1784 deviceRelations
= (PDEVICE_RELATIONS
) Irp
->IoStatus
.Information
;
1785 if (deviceRelations
) {
1787 // Only PDO can handle this request. Somebody above
1788 // is not playing by rule.
1790 ASSERTMSG("Someone above is handling TargetDeviceRelation", !deviceRelations
);
1793 deviceRelations
= (PDEVICE_RELATIONS
)
1794 ExAllocatePoolWithTag (PagedPool
,
1795 sizeof(DEVICE_RELATIONS
),
1797 if (!deviceRelations
) {
1798 status
= STATUS_INSUFFICIENT_RESOURCES
;
1803 // There is only one PDO pointer in the structure
1804 // for this relation type. The PnP Manager removes
1805 // the reference to the PDO when the driver or application
1806 // un-registers for notification on the device.
1809 deviceRelations
->Count
= 1;
1810 deviceRelations
->Objects
[0] = DeviceData
->Common
.Self
;
1811 ObReferenceObject(DeviceData
->Common
.Self
);
1813 status
= STATUS_SUCCESS
;
1814 Irp
->IoStatus
.Information
= (ULONG_PTR
) deviceRelations
;
1817 case BusRelations
: // Not handled by PDO
1818 case EjectionRelations
: // optional for PDO
1819 case RemovalRelations
: // // optional for PDO
1821 status
= Irp
->IoStatus
.Status
;
1828 Bus_PDO_QueryBusInformation(
1829 PPDO_DEVICE_DATA DeviceData
,
1833 Routine Description:
1835 The PnP Manager uses this IRP to request the type and
1836 instance number of a device's parent bus. Bus drivers
1837 should handle this request for their child devices (PDOs).
1841 DeviceData - Pointer to the PDO's device extension.
1842 Irp - Pointer to the irp.
1851 PPNP_BUS_INFORMATION busInfo
;
1855 busInfo
= ExAllocatePoolWithTag (PagedPool
, sizeof(PNP_BUS_INFORMATION
),
1858 if (busInfo
== NULL
) {
1859 return STATUS_INSUFFICIENT_RESOURCES
;
1862 busInfo
->BusTypeGuid
= GUID_ACPI_INTERFACE_STANDARD
;
1864 busInfo
->LegacyBusType
= InternalPowerBus
;
1866 busInfo
->BusNumber
= 0; //fixme
1868 Irp
->IoStatus
.Information
= (ULONG_PTR
)busInfo
;
1870 return STATUS_SUCCESS
;
1875 Bus_GetDeviceCapabilities(
1876 PDEVICE_OBJECT DeviceObject
,
1877 PDEVICE_CAPABILITIES DeviceCapabilities
1880 IO_STATUS_BLOCK ioStatus
;
1883 PDEVICE_OBJECT targetObject
;
1884 PIO_STACK_LOCATION irpStack
;
1890 // Initialize the capabilities that we will send down
1892 RtlZeroMemory( DeviceCapabilities
, sizeof(DEVICE_CAPABILITIES
) );
1893 DeviceCapabilities
->Size
= sizeof(DEVICE_CAPABILITIES
);
1894 DeviceCapabilities
->Version
= 1;
1895 DeviceCapabilities
->Address
= -1;
1896 DeviceCapabilities
->UINumber
= -1;
1899 // Initialize the event
1901 KeInitializeEvent( &pnpEvent
, NotificationEvent
, FALSE
);
1903 targetObject
= IoGetAttachedDeviceReference( DeviceObject
);
1908 pnpIrp
= IoBuildSynchronousFsdRequest(
1917 if (pnpIrp
== NULL
) {
1919 status
= STATUS_INSUFFICIENT_RESOURCES
;
1920 goto GetDeviceCapabilitiesExit
;
1925 // Pnp Irps all begin life as STATUS_NOT_SUPPORTED;
1927 pnpIrp
->IoStatus
.Status
= STATUS_NOT_SUPPORTED
;
1930 // Get the top of stack
1932 irpStack
= IoGetNextIrpStackLocation( pnpIrp
);
1935 // Set the top of stack
1937 RtlZeroMemory( irpStack
, sizeof(IO_STACK_LOCATION
) );
1938 irpStack
->MajorFunction
= IRP_MJ_PNP
;
1939 irpStack
->MinorFunction
= IRP_MN_QUERY_CAPABILITIES
;
1940 irpStack
->Parameters
.DeviceCapabilities
.Capabilities
= DeviceCapabilities
;
1945 status
= IoCallDriver( targetObject
, pnpIrp
);
1946 if (status
== STATUS_PENDING
) {
1949 // Block until the irp comes back.
1950 // Important thing to note here is when you allocate
1951 // the memory for an event in the stack you must do a
1952 // KernelMode wait instead of UserMode to prevent
1953 // the stack from getting paged out.
1956 KeWaitForSingleObject(
1963 status
= ioStatus
.Status
;
1967 GetDeviceCapabilitiesExit
:
1969 // Done with reference
1971 ObDereferenceObject( targetObject
);