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 /* Check we didnt add this already */
41 for (entry
= FdoData
->ListOfPDOs
.Flink
;
42 entry
!= &FdoData
->ListOfPDOs
; entry
= entry
->Flink
)
44 pdoData
= CONTAINING_RECORD (entry
, PDO_DEVICE_DATA
, Link
);
45 //dont duplicate devices
46 if(pdoData
->AcpiHandle
== Device
->handle
)
47 return STATUS_SUCCESS
;
50 DPRINT("Exposing PDO\n"
51 "======AcpiHandle: %p\n"
52 "======HardwareId: %s\n",
54 Device
->pnp
.hardware_id
);
61 DPRINT("FdoData->NextLowerDriver = 0x%p\n", FdoData
->NextLowerDriver
);
63 status
= IoCreateDevice(FdoData
->Common
.Self
->DriverObject
,
64 sizeof(PDO_DEVICE_DATA
),
66 FILE_DEVICE_CONTROLLER
,
67 FILE_AUTOGENERATED_DEVICE_NAME
,
71 if (!NT_SUCCESS (status
)) {
75 pdoData
= (PPDO_DEVICE_DATA
) pdo
->DeviceExtension
;
76 pdoData
->AcpiHandle
= Device
->handle
;
79 // Copy the hardware IDs
82 index
+= swprintf(&temp
[index
],
84 Device
->pnp
.hardware_id
);
87 index
+= swprintf(&temp
[index
],
89 Device
->pnp
.hardware_id
);
91 temp
[index
] = UNICODE_NULL
;
93 pdoData
->HardwareIDs
= ExAllocatePool(NonPagedPool
, index
*sizeof(WCHAR
));
96 if (!pdoData
->HardwareIDs
) {
98 return STATUS_INSUFFICIENT_RESOURCES
;
101 RtlCopyMemory (pdoData
->HardwareIDs
, temp
, index
*sizeof(WCHAR
));
102 Bus_InitializePdo (pdo
, FdoData
);
105 // Device Relation changes if a new pdo is created. So let
106 // the PNP system now about that. This forces it to send bunch of pnp
107 // queries and cause the function driver to be loaded.
110 //IoInvalidateDeviceRelations (FdoData->UnderlyingPDO, BusRelations);
116 /* looks alot like acpi_bus_walk doesnt it */
118 ACPIEnumerateDevices(PFDO_DEVICE_DATA DeviceExtension
)
121 struct acpi_device
*Device
= acpi_root
;
125 if (Device
->status
.present
&& Device
->status
.enabled
&&
126 Device
->flags
.hardware_id
)
128 Bus_PlugInDevice(Device
, DeviceExtension
);
132 if (HAS_CHILDREN(Device
)) {
133 Device
= NODE_TO_DEVICE(Device
->children
.next
);
136 if (HAS_SIBLINGS(Device
)) {
137 Device
= NODE_TO_DEVICE(Device
->node
.next
);
140 while ((Device
= Device
->parent
)) {
141 if (HAS_SIBLINGS(Device
)) {
142 Device
= NODE_TO_DEVICE(Device
->node
.next
);
147 DPRINT("acpi device count: %d\n", Count
);
148 return STATUS_SUCCESS
;