1 /* $Id: acpienum.c 21698 2006-04-22 05:55:17Z tretiakov $
3 * PROJECT: ReactOS ACPI bus driver
4 * FILE: acpi/ospm/acpienum.c
5 * PURPOSE: ACPI namespace enumerator
6 * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
8 * 01-05-2001 CSH Created
13 #include <acpi_drivers.h>
19 #define HAS_CHILDREN(d) ((d)->children.next != &((d)->children))
20 #define HAS_SIBLINGS(d) (((d)->parent) && ((d)->node.next != &(d)->parent->children))
21 #define NODE_TO_DEVICE(n) (list_entry(n, struct acpi_device, node))
23 extern struct acpi_device
*acpi_root
;
27 struct acpi_device
*Device
,
28 PFDO_DEVICE_DATA FdoData
32 PPDO_DEVICE_DATA pdoData
;
40 //Don't enumerate the root device
41 if (Device
->handle
== ACPI_ROOT_OBJECT
)
42 return STATUS_SUCCESS
;
44 /* Check we didnt add this already */
45 for (entry
= FdoData
->ListOfPDOs
.Flink
;
46 entry
!= &FdoData
->ListOfPDOs
; entry
= entry
->Flink
)
48 pdoData
= CONTAINING_RECORD (entry
, PDO_DEVICE_DATA
, Link
);
49 //dont duplicate devices
50 if(pdoData
->AcpiHandle
== Device
->handle
)
51 return STATUS_SUCCESS
;
54 DPRINT("Exposing PDO\n"
55 "======AcpiHandle: %p\n"
56 "======HardwareId: %s\n",
58 Device
->pnp
.hardware_id
);
65 DPRINT("FdoData->NextLowerDriver = 0x%p\n", FdoData
->NextLowerDriver
);
67 status
= IoCreateDevice(FdoData
->Common
.Self
->DriverObject
,
68 sizeof(PDO_DEVICE_DATA
),
70 FILE_DEVICE_CONTROLLER
,
71 FILE_AUTOGENERATED_DEVICE_NAME
,
75 if (!NT_SUCCESS (status
)) {
79 pdoData
= (PPDO_DEVICE_DATA
) pdo
->DeviceExtension
;
80 pdoData
->AcpiHandle
= Device
->handle
;
83 // Copy the hardware IDs
86 index
+= swprintf(&temp
[index
],
88 Device
->pnp
.hardware_id
);
91 index
+= swprintf(&temp
[index
],
93 Device
->pnp
.hardware_id
);
95 temp
[index
] = UNICODE_NULL
;
97 pdoData
->HardwareIDs
= ExAllocatePool(NonPagedPool
, index
*sizeof(WCHAR
));
100 if (!pdoData
->HardwareIDs
) {
102 return STATUS_INSUFFICIENT_RESOURCES
;
105 RtlCopyMemory (pdoData
->HardwareIDs
, temp
, index
*sizeof(WCHAR
));
106 Bus_InitializePdo (pdo
, FdoData
);
109 // Device Relation changes if a new pdo is created. So let
110 // the PNP system now about that. This forces it to send bunch of pnp
111 // queries and cause the function driver to be loaded.
114 //IoInvalidateDeviceRelations (FdoData->UnderlyingPDO, BusRelations);
120 /* looks alot like acpi_bus_walk doesnt it */
122 ACPIEnumerateDevices(PFDO_DEVICE_DATA DeviceExtension
)
125 struct acpi_device
*Device
= acpi_root
;
129 if (Device
->status
.present
&& Device
->status
.enabled
&&
130 Device
->flags
.hardware_id
)
132 Bus_PlugInDevice(Device
, DeviceExtension
);
136 if (HAS_CHILDREN(Device
)) {
137 Device
= NODE_TO_DEVICE(Device
->children
.next
);
140 if (HAS_SIBLINGS(Device
)) {
141 Device
= NODE_TO_DEVICE(Device
->node
.next
);
144 while ((Device
= Device
->parent
)) {
145 if (HAS_SIBLINGS(Device
)) {
146 Device
= NODE_TO_DEVICE(Device
->node
.next
);
151 DPRINT("acpi device count: %d\n", Count
);
152 return STATUS_SUCCESS
;