migrate substitution keywords to SVN
[reactos.git] / reactos / drivers / bus / acpi / ospm / acpienum.c
1 /* $Id$
2 *
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)
7 * UPDATE HISTORY:
8 * 01-05-2001 CSH Created
9 */
10 #include <acpisys.h>
11 #include <bm.h>
12
13 #define NDEBUG
14 #include <debug.h>
15
16
17 #ifndef NDEBUG
18 static void
19 bm_print1 (
20 BM_NODE *node,
21 u32 flags)
22 {
23 ACPI_BUFFER buffer;
24 BM_DEVICE *device = NULL;
25 char *type_string = NULL;
26
27 if (!node)
28 {
29 return;
30 }
31
32 device = &(node->device);
33
34 if (flags & BM_PRINT_PRESENT)
35 {
36 if (!BM_DEVICE_PRESENT(device))
37 {
38 return;
39 }
40 }
41
42 buffer.length = 256;
43 buffer.pointer = acpi_os_callocate(buffer.length);
44 if (!buffer.pointer)
45 {
46 return;
47 }
48
49 acpi_get_name(device->acpi_handle, ACPI_FULL_PATHNAME, &buffer);
50
51 switch(device->id.type)
52 {
53 case BM_TYPE_SYSTEM:
54 type_string = "System";
55 break;
56
57 case BM_TYPE_SCOPE:
58 type_string = "Scope";
59 break;
60
61 case BM_TYPE_PROCESSOR:
62 type_string = "Processor";
63 break;
64
65 case BM_TYPE_THERMAL_ZONE:
66 type_string = "ThermalZone";
67 break;
68
69 case BM_TYPE_POWER_RESOURCE:
70 type_string = "PowerResource";
71 break;
72
73 case BM_TYPE_FIXED_BUTTON:
74 type_string = "Button";
75 break;
76
77 case BM_TYPE_DEVICE:
78 type_string = "Device";
79 break;
80
81 default:
82 type_string = "Unknown";
83 break;
84 }
85
86 if (!(flags & BM_PRINT_GROUP))
87 {
88 DbgPrint("+------------------------------------------------------------\n");
89 }
90
91 DbgPrint("%s[0x%02x] hid[%s] %s\n", type_string, device->handle, device->id.hid, buffer.pointer);
92 DbgPrint(" acpi_handle[0x%08x] flags[0x%02x] status[0x%02x]\n", device->acpi_handle, device->flags, device->status);
93
94 if (flags & BM_PRINT_IDENTIFICATION)
95 {
96 DbgPrint(" identification: uid[%s] adr[0x%08x]\n", device->id.uid, device->id.adr);
97 }
98
99 if (flags & BM_PRINT_LINKAGE)
100 {
101 DbgPrint(" linkage: this[%p] parent[%p] next[%p]\n", node, node->parent, node->next);
102 DbgPrint(" scope.head[%p] scope.tail[%p]\n", node->scope.head, node->scope.tail);
103 }
104
105 if (flags & BM_PRINT_POWER)
106 {
107 DbgPrint(" power: state[D%d] flags[0x%08X]\n", device->power.state, device->power.flags);
108 DbgPrint(" S0[0x%02x] S1[0x%02x] S2[0x%02x]\n", device->power.dx_supported[0], device->power.dx_supported[1], device->power.dx_supported[2]);
109 DbgPrint(" S3[0x%02x] S4[0x%02x] S5[0x%02x]\n", device->power.dx_supported[3], device->power.dx_supported[4], device->power.dx_supported[5]);
110 }
111
112 if (!(flags & BM_PRINT_GROUP))
113 {
114 DbgPrint("+------------------------------------------------------------\n");
115 }
116
117 acpi_os_free(buffer.pointer);
118
119 return;
120 }
121 #endif
122
123
124 NTSTATUS
125 ACPIEnumerateDevices(PFDO_DEVICE_EXTENSION DeviceExtension)
126 {
127 BM_HANDLE_LIST HandleList;
128 PACPI_DEVICE AcpiDevice;
129 ACPI_STATUS AcpiStatus;
130 BM_DEVICE_ID Criteria;
131 BM_NODE *Node;
132 KIRQL OldIrql;
133 ULONG i;
134
135 DPRINT("Called\n");
136
137 RtlZeroMemory(&Criteria, sizeof(BM_DEVICE_ID));
138 Criteria.type = BM_TYPE_ALL;
139
140 AcpiStatus = bm_search(BM_HANDLE_ROOT, &Criteria, &HandleList);
141 if (ACPI_SUCCESS(AcpiStatus))
142 {
143 DPRINT("Got %d devices\n", HandleList.count);
144
145 for (i = 0; i < HandleList.count; i++)
146 {
147 AcpiStatus = bm_get_node(HandleList.handles[i], 0, &Node);
148 if (ACPI_SUCCESS(AcpiStatus))
149 {
150 DPRINT("Got BM node information: (Node 0x%X)\n", Node);
151
152 if ((Node->device.flags & BM_FLAGS_IDENTIFIABLE) &&
153 (Node->device.id.hid[0] != 0))
154 {
155 #ifndef NDEBUG
156 bm_print1(Node, BM_PRINT_ALL - BM_PRINT_PRESENT);
157 #endif
158
159 AcpiDevice = (PACPI_DEVICE)ExAllocatePool(NonPagedPool,
160 sizeof(ACPI_DEVICE));
161 if (AcpiDevice == NULL)
162 {
163 return STATUS_INSUFFICIENT_RESOURCES;
164 }
165
166 RtlZeroMemory(AcpiDevice, sizeof(ACPI_DEVICE));
167
168 AcpiDevice->Pdo = NULL;
169 AcpiDevice->BmHandle = HandleList.handles[i];
170
171 KeAcquireSpinLock(&DeviceExtension->DeviceListLock, &OldIrql);
172 InsertHeadList(&DeviceExtension->DeviceListHead,
173 &AcpiDevice->DeviceListEntry);
174 DeviceExtension->DeviceListCount++;
175 KeReleaseSpinLock(&DeviceExtension->DeviceListLock, OldIrql);
176 }
177 }
178 else
179 {
180 DPRINT("Could not get BM node\n");
181 }
182 }
183 }
184 else
185 {
186 DPRINT("Got no devices (Status 0x%X)\n", AcpiStatus);
187 }
188
189 return STATUS_SUCCESS;
190 }
191
192 /* EOF */