1 /******************************************************************************
3 * Module Name: nsinit - namespace initialization
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2006, R. Byron Moore
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
44 #include <acpi/acpi.h>
45 #include <acpi/acnamesp.h>
46 #include <acpi/acdispat.h>
47 #include <acpi/acinterp.h>
49 #define _COMPONENT ACPI_NAMESPACE
50 ACPI_MODULE_NAME("nsinit")
52 /* Local prototypes */
54 acpi_ns_init_one_object(acpi_handle obj_handle
,
55 u32 level
, void *context
, void **return_value
);
58 acpi_ns_init_one_device(acpi_handle obj_handle
,
59 u32 nesting_level
, void *context
, void **return_value
);
61 /*******************************************************************************
63 * FUNCTION: acpi_ns_initialize_objects
69 * DESCRIPTION: Walk the entire namespace and perform any necessary
70 * initialization on the objects found therein
72 ******************************************************************************/
74 acpi_status
acpi_ns_initialize_objects(void)
77 struct acpi_init_walk_info info
;
79 ACPI_FUNCTION_TRACE("ns_initialize_objects");
81 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
,
82 "**** Starting initialization of namespace objects ****\n"));
83 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT
,
84 "Completing Region/Field/Buffer/Package initialization:"));
86 /* Set all init info to zero */
88 ACPI_MEMSET(&info
, 0, sizeof(struct acpi_init_walk_info
));
90 /* Walk entire namespace from the supplied root */
92 status
= acpi_walk_namespace(ACPI_TYPE_ANY
, ACPI_ROOT_OBJECT
,
93 ACPI_UINT32_MAX
, acpi_ns_init_one_object
,
95 if (ACPI_FAILURE(status
)) {
96 ACPI_REPORT_ERROR(("walk_namespace failed! %s\n",
97 acpi_format_exception(status
)));
100 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT
,
101 "\nInitialized %hd/%hd Regions %hd/%hd Fields %hd/%hd Buffers %hd/%hd Packages (%hd nodes)\n",
102 info
.op_region_init
, info
.op_region_count
,
103 info
.field_init
, info
.field_count
,
104 info
.buffer_init
, info
.buffer_count
,
105 info
.package_init
, info
.package_count
,
108 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
,
109 "%hd Control Methods found\n", info
.method_count
));
110 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH
,
111 "%hd Op Regions found\n", info
.op_region_count
));
113 return_ACPI_STATUS(AE_OK
);
116 /*******************************************************************************
118 * FUNCTION: acpi_ns_initialize_devices
122 * RETURN: acpi_status
124 * DESCRIPTION: Walk the entire namespace and initialize all ACPI devices.
125 * This means running _INI on all present devices.
127 * Note: We install PCI config space handler on region access,
130 ******************************************************************************/
132 acpi_status
acpi_ns_initialize_devices(void)
135 struct acpi_device_walk_info info
;
137 ACPI_FUNCTION_TRACE("ns_initialize_devices");
141 info
.device_count
= 0;
145 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT
,
146 "Executing all Device _STA and_INI methods:"));
148 status
= acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE
);
149 if (ACPI_FAILURE(status
)) {
150 return_ACPI_STATUS(status
);
153 /* Walk namespace for all objects */
155 status
= acpi_ns_walk_namespace(ACPI_TYPE_ANY
, ACPI_ROOT_OBJECT
,
156 ACPI_UINT32_MAX
, TRUE
,
157 acpi_ns_init_one_device
, &info
, NULL
);
159 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
161 if (ACPI_FAILURE(status
)) {
162 ACPI_REPORT_ERROR(("walk_namespace failed! %s\n",
163 acpi_format_exception(status
)));
166 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT
,
167 "\n%hd Devices found containing: %hd _STA, %hd _INI methods\n",
168 info
.device_count
, info
.num_STA
, info
.num_INI
));
170 return_ACPI_STATUS(status
);
173 /*******************************************************************************
175 * FUNCTION: acpi_ns_init_one_object
177 * PARAMETERS: obj_handle - Node
178 * Level - Current nesting level
179 * Context - Points to a init info struct
180 * return_value - Not used
184 * DESCRIPTION: Callback from acpi_walk_namespace. Invoked for every object
185 * within the namespace.
187 * Currently, the only objects that require initialization are:
191 ******************************************************************************/
194 acpi_ns_init_one_object(acpi_handle obj_handle
,
195 u32 level
, void *context
, void **return_value
)
197 acpi_object_type type
;
199 struct acpi_init_walk_info
*info
=
200 (struct acpi_init_walk_info
*)context
;
201 struct acpi_namespace_node
*node
=
202 (struct acpi_namespace_node
*)obj_handle
;
203 union acpi_operand_object
*obj_desc
;
205 ACPI_FUNCTION_NAME("ns_init_one_object");
207 info
->object_count
++;
209 /* And even then, we are only interested in a few object types */
211 type
= acpi_ns_get_type(obj_handle
);
212 obj_desc
= acpi_ns_get_attached_object(node
);
217 /* Increment counters for object types we are looking for */
220 case ACPI_TYPE_REGION
:
221 info
->op_region_count
++;
224 case ACPI_TYPE_BUFFER_FIELD
:
228 case ACPI_TYPE_BUFFER
:
229 info
->buffer_count
++;
232 case ACPI_TYPE_PACKAGE
:
233 info
->package_count
++;
238 /* No init required, just exit now */
243 * If the object is already initialized, nothing else to do
245 if (obj_desc
->common
.flags
& AOPOBJ_DATA_VALID
) {
250 * Must lock the interpreter before executing AML code
252 status
= acpi_ex_enter_interpreter();
253 if (ACPI_FAILURE(status
)) {
258 * Each of these types can contain executable AML code within the
262 case ACPI_TYPE_REGION
:
264 info
->op_region_init
++;
265 status
= acpi_ds_get_region_arguments(obj_desc
);
268 case ACPI_TYPE_BUFFER_FIELD
:
271 status
= acpi_ds_get_buffer_field_arguments(obj_desc
);
274 case ACPI_TYPE_BUFFER
:
277 status
= acpi_ds_get_buffer_arguments(obj_desc
);
280 case ACPI_TYPE_PACKAGE
:
282 info
->package_init
++;
283 status
= acpi_ds_get_package_arguments(obj_desc
);
287 /* No other types can get here */
291 if (ACPI_FAILURE(status
)) {
292 ACPI_REPORT_ERROR(("\nCould not execute arguments for [%4.4s] (%s), %s\n", acpi_ut_get_node_name(node
), acpi_ut_get_type_name(type
), acpi_format_exception(status
)));
296 * Print a dot for each object unless we are going to print the entire
299 if (!(acpi_dbg_level
& ACPI_LV_INIT_NAMES
)) {
300 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT
, "."));
304 * We ignore errors from above, and always return OK, since we don't want
305 * to abort the walk on any single error.
307 acpi_ex_exit_interpreter();
311 /*******************************************************************************
313 * FUNCTION: acpi_ns_init_one_device
315 * PARAMETERS: acpi_walk_callback
317 * RETURN: acpi_status
319 * DESCRIPTION: This is called once per device soon after ACPI is enabled
320 * to initialize each device. It determines if the device is
321 * present, and if so, calls _INI.
323 ******************************************************************************/
326 acpi_ns_init_one_device(acpi_handle obj_handle
,
327 u32 nesting_level
, void *context
, void **return_value
)
329 struct acpi_device_walk_info
*info
=
330 (struct acpi_device_walk_info
*)context
;
331 struct acpi_parameter_info pinfo
;
334 struct acpi_namespace_node
*ini_node
;
335 struct acpi_namespace_node
*device_node
;
337 ACPI_FUNCTION_TRACE("ns_init_one_device");
339 device_node
= acpi_ns_map_handle_to_node(obj_handle
);
341 return_ACPI_STATUS(AE_BAD_PARAMETER
);
345 * We will run _STA/_INI on Devices, Processors and thermal_zones only
347 if ((device_node
->type
!= ACPI_TYPE_DEVICE
) &&
348 (device_node
->type
!= ACPI_TYPE_PROCESSOR
) &&
349 (device_node
->type
!= ACPI_TYPE_THERMAL
)) {
350 return_ACPI_STATUS(AE_OK
);
353 if ((acpi_dbg_level
<= ACPI_LV_ALL_EXCEPTIONS
) &&
354 (!(acpi_dbg_level
& ACPI_LV_INFO
))) {
355 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT
, "."));
358 info
->device_count
++;
361 * Check if the _INI method exists for this device -
362 * if _INI does not exist, there is no need to run _STA
363 * No _INI means device requires no initialization
365 status
= acpi_ns_search_node(*ACPI_CAST_PTR(u32
, METHOD_NAME__INI
),
366 device_node
, ACPI_TYPE_METHOD
, &ini_node
);
367 if (ACPI_FAILURE(status
)) {
368 /* No _INI method found - move on to next device */
370 return_ACPI_STATUS(AE_OK
);
374 * Run _STA to determine if we can run _INI on the device -
375 * the device must be present before _INI can be run.
376 * However, _STA is not required - assume device present if no _STA
378 ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname(ACPI_TYPE_METHOD
,
382 pinfo
.node
= device_node
;
383 pinfo
.parameters
= NULL
;
384 pinfo
.parameter_type
= ACPI_PARAM_ARGS
;
386 status
= acpi_ut_execute_STA(pinfo
.node
, &flags
);
387 if (ACPI_FAILURE(status
)) {
388 /* Ignore error and move on to next device */
390 return_ACPI_STATUS(AE_OK
);
393 if (flags
!= ACPI_UINT32_MAX
) {
397 if (!(flags
& ACPI_STA_DEVICE_PRESENT
)) {
398 /* Don't look at children of a not present device */
400 return_ACPI_STATUS(AE_CTRL_DEPTH
);
404 * The device is present and _INI exists. Run the _INI method.
405 * (We already have the _INI node from above)
407 ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname(ACPI_TYPE_METHOD
,
411 pinfo
.node
= ini_node
;
412 status
= acpi_ns_evaluate_by_handle(&pinfo
);
413 if (ACPI_FAILURE(status
)) {
414 /* Ignore error and move on to next device */
416 #ifdef ACPI_DEBUG_OUTPUT
417 char *scope_name
= acpi_ns_get_external_pathname(ini_node
);
419 ACPI_REPORT_WARNING(("%s._INI failed: %s\n",
421 acpi_format_exception(status
)));
423 ACPI_MEM_FREE(scope_name
);
426 /* Delete any return object (especially if implicit_return is enabled) */
428 if (pinfo
.return_object
) {
429 acpi_ut_remove_reference(pinfo
.return_object
);
432 /* Count of successful INIs */
437 if (acpi_gbl_init_handler
) {
438 /* External initialization handler is present, call it */
441 acpi_gbl_init_handler(pinfo
.node
, ACPI_INIT_DEVICE_INI
);
444 return_ACPI_STATUS(AE_OK
);