- Kai Germaschewski: ISDN update (including Makefiles)
[davej-history.git] / drivers / acpi / namespace / nsinit.c
blobddacd7b8caf868588024fbe6958f8440df59e472
1 /******************************************************************************
3 * Module Name: nsinit - namespace initialization
4 * $Revision: 9 $
6 *****************************************************************************/
8 /*
9 * Copyright (C) 2000 R. Byron Moore
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "acpi.h"
28 #include "acnamesp.h"
29 #include "acdispat.h"
31 #define _COMPONENT NAMESPACE
32 MODULE_NAME ("nsinit")
35 /*******************************************************************************
37 * FUNCTION: Acpi_ns_initialize_objects
39 * PARAMETERS: None
41 * RETURN: Status
43 * DESCRIPTION: Walk the entire namespace and perform any necessary
44 * initialization on the objects found therein
46 ******************************************************************************/
48 ACPI_STATUS
49 acpi_ns_initialize_objects (
50 void)
52 ACPI_STATUS status;
53 ACPI_INIT_WALK_INFO info;
56 info.field_count = 0;
57 info.field_init = 0;
58 info.op_region_count = 0;
59 info.op_region_init = 0;
60 info.object_count = 0;
63 /* Walk entire namespace from the supplied root */
65 status = acpi_walk_namespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
66 ACPI_UINT32_MAX, acpi_ns_init_one_object,
67 &info, NULL);
69 return (AE_OK);
73 /******************************************************************************
75 * FUNCTION: Acpi_ns_initialize_devices
77 * PARAMETERS: None
79 * RETURN: ACPI_STATUS
81 * DESCRIPTION: Walk the entire namespace and initialize all ACPI devices.
82 * This means running _INI on all present devices.
84 * Also: Install PCI config space handler for all PCI root bridges.
85 * A PCI root bridge is found by searching for devices containing
86 * a HID with the value EISAID("PNP0A03")
88 *****************************************************************************/
90 ACPI_STATUS
91 acpi_ns_initialize_devices (
92 u32 flags)
94 ACPI_STATUS status;
95 ACPI_DEVICE_WALK_INFO info;
98 info.flags = flags;
99 info.device_count = 0;
100 info.num_STA = 0;
101 info.num_INI = 0;
104 status = acpi_ns_walk_namespace (ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
105 FALSE, acpi_ns_init_one_device, &info, NULL);
109 return (status);
113 /*******************************************************************************
115 * FUNCTION: Acpi_ns_init_one_object
117 * PARAMETERS: Obj_handle - Node
118 * Level - Current nesting level
119 * Context - Points to a init info struct
120 * Return_value - Not used
122 * RETURN: Status
124 * DESCRIPTION: Callback from Acpi_walk_namespace. Invoked for every object
125 * within the namespace.
127 * Currently, the only objects that require initialization are:
128 * 1) Methods
129 * 2) Op Regions
131 ******************************************************************************/
133 ACPI_STATUS
134 acpi_ns_init_one_object (
135 ACPI_HANDLE obj_handle,
136 u32 level,
137 void *context,
138 void **return_value)
140 OBJECT_TYPE_INTERNAL type;
141 ACPI_STATUS status;
142 ACPI_INIT_WALK_INFO *info = (ACPI_INIT_WALK_INFO *) context;
143 ACPI_NAMESPACE_NODE *node = (ACPI_NAMESPACE_NODE *) obj_handle;
144 ACPI_OPERAND_OBJECT *obj_desc;
147 info->object_count++;
150 /* And even then, we are only interested in a few object types */
152 type = acpi_ns_get_type (obj_handle);
153 obj_desc = node->object;
154 if (!obj_desc) {
155 return (AE_OK);
158 switch (type)
161 case ACPI_TYPE_REGION:
163 info->op_region_count++;
164 if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
165 break;
168 info->op_region_init++;
169 status = acpi_ds_get_region_arguments (obj_desc);
171 break;
174 case ACPI_TYPE_FIELD_UNIT:
176 info->field_count++;
177 if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
178 break;
181 info->field_init++;
182 status = acpi_ds_get_field_unit_arguments (obj_desc);
183 break;
185 default:
186 break;
190 * We ignore errors from above, and always return OK, since
191 * we don't want to abort the walk on a single error.
193 return (AE_OK);
197 /******************************************************************************
199 * FUNCTION: Acpi_ns_init_one_device
201 * PARAMETERS: The usual "I'm a namespace callback" stuff
203 * RETURN: ACPI_STATUS
205 * DESCRIPTION: This is called once per device soon after ACPI is enabled
206 * to initialize each device. It determines if the device is
207 * present, and if so, calls _INI.
209 *****************************************************************************/
211 ACPI_STATUS
212 acpi_ns_init_one_device (
213 ACPI_HANDLE obj_handle,
214 u32 nesting_level,
215 void *context,
216 void **return_value)
218 ACPI_STATUS status;
219 ACPI_NAMESPACE_NODE *node;
220 u32 flags;
221 ACPI_DEVICE_WALK_INFO *info = (ACPI_DEVICE_WALK_INFO *) context;
224 info->device_count++;
226 acpi_cm_acquire_mutex (ACPI_MTX_NAMESPACE);
228 node = acpi_ns_convert_handle_to_entry (obj_handle);
229 if (!node) {
230 acpi_cm_release_mutex (ACPI_MTX_NAMESPACE);
231 return (AE_BAD_PARAMETER);
234 acpi_cm_release_mutex (ACPI_MTX_NAMESPACE);
237 * Run _STA to determine if we can run _INI on the device.
240 status = acpi_cm_execute_STA (node, &flags);
241 if (ACPI_FAILURE (status)) {
242 return (status);
245 info->num_STA++;
247 if (!(flags & 0x01)) {
248 /* don't look at children of a not present device */
249 return(AE_CTRL_DEPTH);
253 * The device is present. Run _INI.
256 status = acpi_ns_evaluate_relative (obj_handle, "_INI", NULL, NULL);
257 if (AE_NOT_FOUND == status) {
258 /* No _INI means device requires no initialization */
259 status = AE_OK;
262 else if (ACPI_FAILURE (status)) {
263 return (status);
266 else {
267 info->num_INI++;
270 return (status);