initial commit with v2.6.9
[linux-2.6.9-moxart.git] / drivers / acpi / namespace / nsinit.c
blob861787520957d32ee087a062c2d715b749617609
1 /******************************************************************************
3 * Module Name: nsinit - namespace initialization
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2004, R. Byron Moore
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
45 #include <acpi/acpi.h>
46 #include <acpi/acnamesp.h>
47 #include <acpi/acdispat.h>
48 #include <acpi/acinterp.h>
50 #define _COMPONENT ACPI_NAMESPACE
51 ACPI_MODULE_NAME ("nsinit")
54 /*******************************************************************************
56 * FUNCTION: acpi_ns_initialize_objects
58 * PARAMETERS: None
60 * RETURN: Status
62 * DESCRIPTION: Walk the entire namespace and perform any necessary
63 * initialization on the objects found therein
65 ******************************************************************************/
67 acpi_status
68 acpi_ns_initialize_objects (
69 void)
71 acpi_status status;
72 struct acpi_init_walk_info info;
75 ACPI_FUNCTION_TRACE ("ns_initialize_objects");
78 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
79 "**** Starting initialization of namespace objects ****\n"));
80 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT, "Completing Region/Field/Buffer/Package initialization:"));
82 /* Set all init info to zero */
84 ACPI_MEMSET (&info, 0, sizeof (struct acpi_init_walk_info));
86 /* Walk entire namespace from the supplied root */
88 status = acpi_walk_namespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
89 ACPI_UINT32_MAX, acpi_ns_init_one_object,
90 &info, NULL);
91 if (ACPI_FAILURE (status)) {
92 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "walk_namespace failed! %s\n",
93 acpi_format_exception (status)));
96 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
97 "\nInitialized %hd/%hd Regions %hd/%hd Fields %hd/%hd Buffers %hd/%hd Packages (%hd nodes)\n",
98 info.op_region_init, info.op_region_count,
99 info.field_init, info.field_count,
100 info.buffer_init, info.buffer_count,
101 info.package_init, info.package_count, info.object_count));
103 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
104 "%hd Control Methods found\n", info.method_count));
105 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
106 "%hd Op Regions found\n", info.op_region_count));
108 return_ACPI_STATUS (AE_OK);
112 /*******************************************************************************
114 * FUNCTION: acpi_ns_initialize_devices
116 * PARAMETERS: None
118 * RETURN: acpi_status
120 * DESCRIPTION: Walk the entire namespace and initialize all ACPI devices.
121 * This means running _INI on all present devices.
123 * Note: We install PCI config space handler on region access,
124 * not here.
126 ******************************************************************************/
128 acpi_status
129 acpi_ns_initialize_devices (
130 void)
132 acpi_status status;
133 struct acpi_device_walk_info info;
136 ACPI_FUNCTION_TRACE ("ns_initialize_devices");
139 /* Init counters */
141 info.device_count = 0;
142 info.num_STA = 0;
143 info.num_INI = 0;
145 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT, "Executing all Device _STA and_INI methods:"));
147 status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
148 if (ACPI_FAILURE (status)) {
149 return_ACPI_STATUS (status);
152 /* Walk namespace for all objects */
154 status = acpi_ns_walk_namespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
155 ACPI_UINT32_MAX, TRUE, acpi_ns_init_one_device, &info, NULL);
157 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
159 if (ACPI_FAILURE (status)) {
160 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "walk_namespace failed! %s\n",
161 acpi_format_exception (status)));
164 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
165 "\n%hd Devices found containing: %hd _STA, %hd _INI methods\n",
166 info.device_count, info.num_STA, info.num_INI));
168 return_ACPI_STATUS (status);
172 /*******************************************************************************
174 * FUNCTION: acpi_ns_init_one_object
176 * PARAMETERS: obj_handle - Node
177 * Level - Current nesting level
178 * Context - Points to a init info struct
179 * return_value - Not used
181 * RETURN: Status
183 * DESCRIPTION: Callback from acpi_walk_namespace. Invoked for every object
184 * within the namespace.
186 * Currently, the only objects that require initialization are:
187 * 1) Methods
188 * 2) Op Regions
190 ******************************************************************************/
192 acpi_status
193 acpi_ns_init_one_object (
194 acpi_handle obj_handle,
195 u32 level,
196 void *context,
197 void **return_value)
199 acpi_object_type type;
200 acpi_status status;
201 struct acpi_init_walk_info *info = (struct acpi_init_walk_info *) context;
202 struct acpi_namespace_node *node = (struct acpi_namespace_node *) obj_handle;
203 union acpi_operand_object *obj_desc;
206 ACPI_FUNCTION_NAME ("ns_init_one_object");
209 info->object_count++;
211 /* And even then, we are only interested in a few object types */
213 type = acpi_ns_get_type (obj_handle);
214 obj_desc = acpi_ns_get_attached_object (node);
215 if (!obj_desc) {
216 return (AE_OK);
219 /* Increment counters for object types we are looking for */
221 switch (type) {
222 case ACPI_TYPE_REGION:
223 info->op_region_count++;
224 break;
226 case ACPI_TYPE_BUFFER_FIELD:
227 info->field_count++;
228 break;
230 case ACPI_TYPE_BUFFER:
231 info->buffer_count++;
232 break;
234 case ACPI_TYPE_PACKAGE:
235 info->package_count++;
236 break;
238 default:
240 /* No init required, just exit now */
241 return (AE_OK);
245 * If the object is already initialized, nothing else to do
247 if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
248 return (AE_OK);
252 * Must lock the interpreter before executing AML code
254 status = acpi_ex_enter_interpreter ();
255 if (ACPI_FAILURE (status)) {
256 return (status);
260 * Each of these types can contain executable AML code within
261 * the declaration.
263 switch (type) {
264 case ACPI_TYPE_REGION:
266 info->op_region_init++;
267 status = acpi_ds_get_region_arguments (obj_desc);
268 break;
271 case ACPI_TYPE_BUFFER_FIELD:
273 info->field_init++;
274 status = acpi_ds_get_buffer_field_arguments (obj_desc);
275 break;
278 case ACPI_TYPE_BUFFER:
280 info->buffer_init++;
281 status = acpi_ds_get_buffer_arguments (obj_desc);
282 break;
285 case ACPI_TYPE_PACKAGE:
287 info->package_init++;
288 status = acpi_ds_get_package_arguments (obj_desc);
289 break;
291 default:
292 /* No other types can get here */
293 break;
296 if (ACPI_FAILURE (status)) {
297 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_ERROR, "\n"));
298 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
299 "Could not execute arguments for [%4.4s] (%s), %s\n",
300 acpi_ut_get_node_name (node), acpi_ut_get_type_name (type),
301 acpi_format_exception (status)));
304 /* Print a dot for each object unless we are going to print the entire pathname */
306 if (!(acpi_dbg_level & ACPI_LV_INIT_NAMES)) {
307 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT, "."));
311 * We ignore errors from above, and always return OK, since
312 * we don't want to abort the walk on any single error.
314 acpi_ex_exit_interpreter ();
315 return (AE_OK);
319 /*******************************************************************************
321 * FUNCTION: acpi_ns_init_one_device
323 * PARAMETERS: acpi_walk_callback
325 * RETURN: acpi_status
327 * DESCRIPTION: This is called once per device soon after ACPI is enabled
328 * to initialize each device. It determines if the device is
329 * present, and if so, calls _INI.
331 ******************************************************************************/
333 acpi_status
334 acpi_ns_init_one_device (
335 acpi_handle obj_handle,
336 u32 nesting_level,
337 void *context,
338 void **return_value)
340 struct acpi_device_walk_info *info = (struct acpi_device_walk_info *) context;
341 struct acpi_parameter_info pinfo;
342 u32 flags;
343 acpi_status status;
346 ACPI_FUNCTION_TRACE ("ns_init_one_device");
349 pinfo.parameters = NULL;
350 pinfo.parameter_type = ACPI_PARAM_ARGS;
352 pinfo.node = acpi_ns_map_handle_to_node (obj_handle);
353 if (!pinfo.node) {
354 return_ACPI_STATUS (AE_BAD_PARAMETER);
358 * We will run _STA/_INI on Devices, Processors and thermal_zones only
360 if ((pinfo.node->type != ACPI_TYPE_DEVICE) &&
361 (pinfo.node->type != ACPI_TYPE_PROCESSOR) &&
362 (pinfo.node->type != ACPI_TYPE_THERMAL)) {
363 return_ACPI_STATUS (AE_OK);
366 if ((acpi_dbg_level <= ACPI_LV_ALL_EXCEPTIONS) && (!(acpi_dbg_level & ACPI_LV_INFO))) {
367 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT, "."));
370 info->device_count++;
373 * Run _STA to determine if we can run _INI on the device.
375 ACPI_DEBUG_EXEC (acpi_ut_display_init_pathname (ACPI_TYPE_METHOD, pinfo.node, "_STA"));
376 status = acpi_ut_execute_STA (pinfo.node, &flags);
378 if (ACPI_FAILURE (status)) {
379 if (pinfo.node->type == ACPI_TYPE_DEVICE) {
380 /* Ignore error and move on to next device */
382 return_ACPI_STATUS (AE_OK);
385 /* _STA is not required for Processor or thermal_zone objects */
387 else {
388 info->num_STA++;
390 if (!(flags & 0x01)) {
391 /* Don't look at children of a not present device */
393 return_ACPI_STATUS(AE_CTRL_DEPTH);
398 * The device is present. Run _INI.
400 ACPI_DEBUG_EXEC (acpi_ut_display_init_pathname (ACPI_TYPE_METHOD, pinfo.node, "_INI"));
401 status = acpi_ns_evaluate_relative ("_INI", &pinfo);
402 if (ACPI_FAILURE (status)) {
403 /* No _INI (AE_NOT_FOUND) means device requires no initialization */
405 if (status != AE_NOT_FOUND) {
406 /* Ignore error and move on to next device */
408 #ifdef ACPI_DEBUG_OUTPUT
409 char *scope_name = acpi_ns_get_external_pathname (pinfo.node);
411 ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "%s._INI failed: %s\n",
412 scope_name, acpi_format_exception (status)));
414 ACPI_MEM_FREE (scope_name);
415 #endif
418 status = AE_OK;
420 else {
421 /* Count of successful INIs */
423 info->num_INI++;
426 if (acpi_gbl_init_handler) {
427 /* External initialization handler is present, call it */
429 status = acpi_gbl_init_handler (pinfo.node, ACPI_INIT_DEVICE_INI);
433 return_ACPI_STATUS (status);