blob: f029a3da67eb4991c53a8aa18786330f7a681a65 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: nsinit - namespace initialization
4 *
5 *****************************************************************************/
6
7/*
Bob Moorec8100dc2016-01-15 08:17:03 +08008 * Copyright (C) 2000 - 2016, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * All rights reserved.
10 *
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.
25 *
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.
29 *
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.
42 */
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050045#include "accommon.h"
46#include "acnamesp.h"
47#include "acdispat.h"
48#include "acinterp.h"
Lv Zhengced04362016-02-19 14:17:15 +080049#include "acevents.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
51#define _COMPONENT ACPI_NAMESPACE
Len Brown4be44fc2005-08-05 00:44:28 -040052ACPI_MODULE_NAME("nsinit")
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Robert Moore44f6c012005-04-18 22:49:35 -040054/* Local prototypes */
Len Brown4be44fc2005-08-05 00:44:28 -040055static acpi_status
56acpi_ns_init_one_object(acpi_handle obj_handle,
57 u32 level, void *context, void **return_value);
Robert Moore44f6c012005-04-18 22:49:35 -040058
59static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040060acpi_ns_init_one_device(acpi_handle obj_handle,
61 u32 nesting_level, void *context, void **return_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Bob Mooreb229cf92006-04-21 17:15:00 -040063static acpi_status
64acpi_ns_find_ini_methods(acpi_handle obj_handle,
65 u32 nesting_level, void *context, void **return_value);
66
Linus Torvalds1da177e2005-04-16 15:20:36 -070067/*******************************************************************************
68 *
69 * FUNCTION: acpi_ns_initialize_objects
70 *
71 * PARAMETERS: None
72 *
73 * RETURN: Status
74 *
75 * DESCRIPTION: Walk the entire namespace and perform any necessary
76 * initialization on the objects found therein
77 *
78 ******************************************************************************/
79
Len Brown4be44fc2005-08-05 00:44:28 -040080acpi_status acpi_ns_initialize_objects(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070081{
Len Brown4be44fc2005-08-05 00:44:28 -040082 acpi_status status;
83 struct acpi_init_walk_info info;
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
Bob Mooreb229cf92006-04-21 17:15:00 -040085 ACPI_FUNCTION_TRACE(ns_initialize_objects);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
Len Brown4be44fc2005-08-05 00:44:28 -040087 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
88 "**** Starting initialization of namespace objects ****\n"));
89 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
Bob Moore2fae3e52012-12-31 00:07:08 +000090 "Completing Region/Field/Buffer/Package initialization:\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92 /* Set all init info to zero */
93
Bob Moore4fa46162015-07-01 14:45:11 +080094 memset(&info, 0, sizeof(struct acpi_init_walk_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
96 /* Walk entire namespace from the supplied root */
97
Len Brown4be44fc2005-08-05 00:44:28 -040098 status = acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
Lv Zheng1f86e8c2012-10-31 02:25:45 +000099 ACPI_UINT32_MAX, acpi_ns_init_one_object,
100 NULL, &info, NULL);
Len Brown4be44fc2005-08-05 00:44:28 -0400101 if (ACPI_FAILURE(status)) {
Bob Mooreb229cf92006-04-21 17:15:00 -0400102 ACPI_EXCEPTION((AE_INFO, status, "During WalkNamespace"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 }
104
Len Brown4be44fc2005-08-05 00:44:28 -0400105 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
Bob Moore3e5621a2012-12-31 00:07:13 +0000106 " Initialized %u/%u Regions %u/%u Fields %u/%u "
Alexey Starikovskiy96b7b7a2010-05-26 11:20:47 +0800107 "Buffers %u/%u Packages (%u nodes)\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400108 info.op_region_init, info.op_region_count,
109 info.field_init, info.field_count,
110 info.buffer_init, info.buffer_count,
111 info.package_init, info.package_count,
112 info.object_count));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
Len Brown4be44fc2005-08-05 00:44:28 -0400114 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
Bob Moore22b5afc2014-03-24 14:49:00 +0800115 "%u Control Methods found\n%u Op Regions found\n",
116 info.method_count, info.op_region_count));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
Len Brown4be44fc2005-08-05 00:44:28 -0400118 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119}
120
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121/*******************************************************************************
122 *
123 * FUNCTION: acpi_ns_initialize_devices
124 *
125 * PARAMETERS: None
126 *
127 * RETURN: acpi_status
128 *
129 * DESCRIPTION: Walk the entire namespace and initialize all ACPI devices.
130 * This means running _INI on all present devices.
131 *
132 * Note: We install PCI config space handler on region access,
133 * not here.
134 *
135 ******************************************************************************/
136
Lv Zhengced04362016-02-19 14:17:15 +0800137acpi_status acpi_ns_initialize_devices(u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138{
Lv Zhengebc3c9b2016-02-19 14:17:22 +0800139 acpi_status status = AE_OK;
Len Brown4be44fc2005-08-05 00:44:28 -0400140 struct acpi_device_walk_info info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
Bob Mooreb229cf92006-04-21 17:15:00 -0400142 ACPI_FUNCTION_TRACE(ns_initialize_devices);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
Lv Zhengced04362016-02-19 14:17:15 +0800144 if (!(flags & ACPI_NO_DEVICE_INIT)) {
145 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
146 "[Init] Initializing ACPI Devices\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
Lv Zhengced04362016-02-19 14:17:15 +0800148 /* Init counters */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
Lv Zhengced04362016-02-19 14:17:15 +0800150 info.device_count = 0;
151 info.num_STA = 0;
152 info.num_INI = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
Lv Zhengced04362016-02-19 14:17:15 +0800154 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
155 "Initializing Device/Processor/Thermal objects "
156 "and executing _INI/_STA methods:\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
Lv Zhengced04362016-02-19 14:17:15 +0800158 /* Tree analysis: find all subtrees that contain _INI methods */
Bob Moore41195322006-05-26 16:36:00 -0400159
Lv Zhengced04362016-02-19 14:17:15 +0800160 status = acpi_ns_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
161 ACPI_UINT32_MAX, FALSE,
162 acpi_ns_find_ini_methods, NULL,
163 &info, NULL);
164 if (ACPI_FAILURE(status)) {
165 goto error_exit;
166 }
Bob Moore41195322006-05-26 16:36:00 -0400167
Lv Zhengced04362016-02-19 14:17:15 +0800168 /* Allocate the evaluation information block */
169
170 info.evaluate_info =
171 ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
172 if (!info.evaluate_info) {
173 status = AE_NO_MEMORY;
174 goto error_exit;
175 }
176
177 /*
178 * Execute the "global" _INI method that may appear at the root.
179 * This support is provided for Windows compatibility (Vista+) and
180 * is not part of the ACPI specification.
181 */
182 info.evaluate_info->prefix_node = acpi_gbl_root_node;
183 info.evaluate_info->relative_pathname = METHOD_NAME__INI;
184 info.evaluate_info->parameters = NULL;
185 info.evaluate_info->flags = ACPI_IGNORE_RETURN_VALUE;
186
187 status = acpi_ns_evaluate(info.evaluate_info);
188 if (ACPI_SUCCESS(status)) {
189 info.num_INI++;
190 }
Bob Mooreb229cf92006-04-21 17:15:00 -0400191 }
192
Bob Moore9e641552009-09-03 10:21:03 +0800193 /*
Lv Zhengced04362016-02-19 14:17:15 +0800194 * Run all _REG methods
195 *
196 * Note: Any objects accessed by the _REG methods will be automatically
197 * initialized, even if they contain executable AML (see the call to
198 * acpi_ns_initialize_objects below).
Bob Moore9e641552009-09-03 10:21:03 +0800199 */
Lv Zhengced04362016-02-19 14:17:15 +0800200 if (!(flags & ACPI_NO_ADDRESS_SPACE_INIT)) {
201 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
202 "[Init] Executing _REG OpRegion methods\n"));
Bob Moore9e641552009-09-03 10:21:03 +0800203
Lv Zhengced04362016-02-19 14:17:15 +0800204 status = acpi_ev_initialize_op_regions();
205 if (ACPI_FAILURE(status)) {
206 goto error_exit;
207 }
Bob Moore9e641552009-09-03 10:21:03 +0800208 }
209
Lv Zhengced04362016-02-19 14:17:15 +0800210 if (!(flags & ACPI_NO_DEVICE_INIT)) {
Bob Mooreb229cf92006-04-21 17:15:00 -0400211
Lv Zhengced04362016-02-19 14:17:15 +0800212 /* Walk namespace to execute all _INIs on present devices */
Bob Moore41195322006-05-26 16:36:00 -0400213
Lv Zhengced04362016-02-19 14:17:15 +0800214 status = acpi_ns_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
215 ACPI_UINT32_MAX, FALSE,
216 acpi_ns_init_one_device, NULL,
217 &info, NULL);
218
219 /*
220 * Any _OSI requests should be completed by now. If the BIOS has
221 * requested any Windows OSI strings, we will always truncate
222 * I/O addresses to 16 bits -- for Windows compatibility.
223 */
224 if (acpi_gbl_osi_data >= ACPI_OSI_WIN_2000) {
225 acpi_gbl_truncate_io_addresses = TRUE;
226 }
227
228 ACPI_FREE(info.evaluate_info);
229 if (ACPI_FAILURE(status)) {
230 goto error_exit;
231 }
232
233 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT,
234 " Executed %u _INI methods requiring %u _STA executions "
235 "(examined %u objects)\n",
236 info.num_INI, info.num_STA,
237 info.device_count));
Matthew Garrettb681f7d2010-05-26 11:50:48 +0800238 }
239
Len Brown4be44fc2005-08-05 00:44:28 -0400240 return_ACPI_STATUS(status);
Bob Moore41195322006-05-26 16:36:00 -0400241
Lv Zheng10622bf2013-10-29 09:30:02 +0800242error_exit:
Bob Moore41195322006-05-26 16:36:00 -0400243 ACPI_EXCEPTION((AE_INFO, status, "During device initialization"));
244 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245}
246
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247/*******************************************************************************
248 *
249 * FUNCTION: acpi_ns_init_one_object
250 *
251 * PARAMETERS: obj_handle - Node
Bob Mooreba494be2012-07-12 09:40:10 +0800252 * level - Current nesting level
253 * context - Points to a init info struct
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 * return_value - Not used
255 *
256 * RETURN: Status
257 *
258 * DESCRIPTION: Callback from acpi_walk_namespace. Invoked for every object
259 * within the namespace.
260 *
261 * Currently, the only objects that require initialization are:
262 * 1) Methods
263 * 2) Op Regions
264 *
265 ******************************************************************************/
266
Robert Moore44f6c012005-04-18 22:49:35 -0400267static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400268acpi_ns_init_one_object(acpi_handle obj_handle,
269 u32 level, void *context, void **return_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270{
Len Brown4be44fc2005-08-05 00:44:28 -0400271 acpi_object_type type;
Len Brown4d2acd92007-05-09 22:56:38 -0400272 acpi_status status = AE_OK;
Len Brown4be44fc2005-08-05 00:44:28 -0400273 struct acpi_init_walk_info *info =
274 (struct acpi_init_walk_info *)context;
275 struct acpi_namespace_node *node =
276 (struct acpi_namespace_node *)obj_handle;
277 union acpi_operand_object *obj_desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
Bob Mooreb229cf92006-04-21 17:15:00 -0400279 ACPI_FUNCTION_NAME(ns_init_one_object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
281 info->object_count++;
282
283 /* And even then, we are only interested in a few object types */
284
Len Brown4be44fc2005-08-05 00:44:28 -0400285 type = acpi_ns_get_type(obj_handle);
286 obj_desc = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 if (!obj_desc) {
288 return (AE_OK);
289 }
290
291 /* Increment counters for object types we are looking for */
292
293 switch (type) {
294 case ACPI_TYPE_REGION:
Chao Guan1d1ea1b72013-06-08 00:58:14 +0000295
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 info->op_region_count++;
297 break;
298
299 case ACPI_TYPE_BUFFER_FIELD:
Chao Guan1d1ea1b72013-06-08 00:58:14 +0000300
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 info->field_count++;
302 break;
303
Lin Mingef805d92008-04-10 19:06:41 +0400304 case ACPI_TYPE_LOCAL_BANK_FIELD:
Chao Guan1d1ea1b72013-06-08 00:58:14 +0000305
Lin Mingef805d92008-04-10 19:06:41 +0400306 info->field_count++;
307 break;
308
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 case ACPI_TYPE_BUFFER:
Chao Guan1d1ea1b72013-06-08 00:58:14 +0000310
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 info->buffer_count++;
312 break;
313
314 case ACPI_TYPE_PACKAGE:
Chao Guan1d1ea1b72013-06-08 00:58:14 +0000315
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 info->package_count++;
317 break;
318
319 default:
320
321 /* No init required, just exit now */
Chao Guan1d1ea1b72013-06-08 00:58:14 +0000322
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 return (AE_OK);
324 }
325
Bob Moored4913dc2009-03-06 10:05:18 +0800326 /* If the object is already initialized, nothing else to do */
327
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
329 return (AE_OK);
330 }
331
Bob Moored4913dc2009-03-06 10:05:18 +0800332 /* Must lock the interpreter before executing AML code */
333
Len Brown4d2acd92007-05-09 22:56:38 -0400334 acpi_ex_enter_interpreter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
336 /*
337 * Each of these types can contain executable AML code within the
338 * declaration.
339 */
340 switch (type) {
341 case ACPI_TYPE_REGION:
342
343 info->op_region_init++;
Len Brown4be44fc2005-08-05 00:44:28 -0400344 status = acpi_ds_get_region_arguments(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 break;
346
347 case ACPI_TYPE_BUFFER_FIELD:
348
349 info->field_init++;
Len Brown4be44fc2005-08-05 00:44:28 -0400350 status = acpi_ds_get_buffer_field_arguments(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 break;
352
Lin Mingef805d92008-04-10 19:06:41 +0400353 case ACPI_TYPE_LOCAL_BANK_FIELD:
354
355 info->field_init++;
356 status = acpi_ds_get_bank_field_arguments(obj_desc);
357 break;
358
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 case ACPI_TYPE_BUFFER:
360
361 info->buffer_init++;
Len Brown4be44fc2005-08-05 00:44:28 -0400362 status = acpi_ds_get_buffer_arguments(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 break;
364
365 case ACPI_TYPE_PACKAGE:
366
367 info->package_init++;
Len Brown4be44fc2005-08-05 00:44:28 -0400368 status = acpi_ds_get_package_arguments(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 break;
370
371 default:
Chao Guan1d1ea1b72013-06-08 00:58:14 +0000372
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 /* No other types can get here */
Chao Guan1d1ea1b72013-06-08 00:58:14 +0000374
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 break;
376 }
377
Len Brown4be44fc2005-08-05 00:44:28 -0400378 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500379 ACPI_EXCEPTION((AE_INFO, status,
380 "Could not execute arguments for [%4.4s] (%s)",
381 acpi_ut_get_node_name(node),
382 acpi_ut_get_type_name(type)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 }
384
385 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 * We ignore errors from above, and always return OK, since we don't want
387 * to abort the walk on any single error.
388 */
Len Brown4be44fc2005-08-05 00:44:28 -0400389 acpi_ex_exit_interpreter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 return (AE_OK);
391}
392
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393/*******************************************************************************
394 *
Bob Mooreb229cf92006-04-21 17:15:00 -0400395 * FUNCTION: acpi_ns_find_ini_methods
396 *
397 * PARAMETERS: acpi_walk_callback
398 *
399 * RETURN: acpi_status
400 *
401 * DESCRIPTION: Called during namespace walk. Finds objects named _INI under
402 * device/processor/thermal objects, and marks the entire subtree
403 * with a SUBTREE_HAS_INI flag. This flag is used during the
404 * subsequent device initialization walk to avoid entire subtrees
405 * that do not contain an _INI.
406 *
407 ******************************************************************************/
408
409static acpi_status
410acpi_ns_find_ini_methods(acpi_handle obj_handle,
411 u32 nesting_level, void *context, void **return_value)
412{
413 struct acpi_device_walk_info *info =
414 ACPI_CAST_PTR(struct acpi_device_walk_info, context);
415 struct acpi_namespace_node *node;
416 struct acpi_namespace_node *parent_node;
417
418 /* Keep count of device/processor/thermal objects */
419
420 node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_handle);
421 if ((node->type == ACPI_TYPE_DEVICE) ||
422 (node->type == ACPI_TYPE_PROCESSOR) ||
423 (node->type == ACPI_TYPE_THERMAL)) {
424 info->device_count++;
425 return (AE_OK);
426 }
427
428 /* We are only looking for methods named _INI */
429
430 if (!ACPI_COMPARE_NAME(node->name.ascii, METHOD_NAME__INI)) {
431 return (AE_OK);
432 }
433
434 /*
435 * The only _INI methods that we care about are those that are
436 * present under Device, Processor, and Thermal objects.
437 */
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +0800438 parent_node = node->parent;
Bob Mooreb229cf92006-04-21 17:15:00 -0400439 switch (parent_node->type) {
440 case ACPI_TYPE_DEVICE:
441 case ACPI_TYPE_PROCESSOR:
442 case ACPI_TYPE_THERMAL:
443
444 /* Mark parent and bubble up the INI present flag to the root */
445
446 while (parent_node) {
447 parent_node->flags |= ANOBJ_SUBTREE_HAS_INI;
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +0800448 parent_node = parent_node->parent;
Bob Mooreb229cf92006-04-21 17:15:00 -0400449 }
450 break;
451
452 default:
Chao Guan1d1ea1b72013-06-08 00:58:14 +0000453
Bob Mooreb229cf92006-04-21 17:15:00 -0400454 break;
455 }
456
457 return (AE_OK);
458}
459
460/*******************************************************************************
461 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 * FUNCTION: acpi_ns_init_one_device
463 *
464 * PARAMETERS: acpi_walk_callback
465 *
466 * RETURN: acpi_status
467 *
468 * DESCRIPTION: This is called once per device soon after ACPI is enabled
469 * to initialize each device. It determines if the device is
470 * present, and if so, calls _INI.
471 *
472 ******************************************************************************/
473
Robert Moore44f6c012005-04-18 22:49:35 -0400474static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400475acpi_ns_init_one_device(acpi_handle obj_handle,
476 u32 nesting_level, void *context, void **return_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477{
Bob Moore41195322006-05-26 16:36:00 -0400478 struct acpi_device_walk_info *walk_info =
Bob Mooreb229cf92006-04-21 17:15:00 -0400479 ACPI_CAST_PTR(struct acpi_device_walk_info, context);
Bob Moore41195322006-05-26 16:36:00 -0400480 struct acpi_evaluate_info *info = walk_info->evaluate_info;
Len Brown4be44fc2005-08-05 00:44:28 -0400481 u32 flags;
482 acpi_status status;
Bob Mooredefba1d2005-12-16 17:05:00 -0500483 struct acpi_namespace_node *device_node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
Bob Mooreb229cf92006-04-21 17:15:00 -0400485 ACPI_FUNCTION_TRACE(ns_init_one_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
Bob Mooreb229cf92006-04-21 17:15:00 -0400487 /* We are interested in Devices, Processors and thermal_zones only */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
Bob Mooreb229cf92006-04-21 17:15:00 -0400489 device_node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_handle);
Bob Mooredefba1d2005-12-16 17:05:00 -0500490 if ((device_node->type != ACPI_TYPE_DEVICE) &&
491 (device_node->type != ACPI_TYPE_PROCESSOR) &&
492 (device_node->type != ACPI_TYPE_THERMAL)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400493 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 }
495
Bob Mooreb229cf92006-04-21 17:15:00 -0400496 /*
497 * Because of an earlier namespace analysis, all subtrees that contain an
498 * _INI method are tagged.
499 *
500 * If this device subtree does not contain any _INI methods, we
501 * can exit now and stop traversing this entire subtree.
502 */
503 if (!(device_node->flags & ANOBJ_SUBTREE_HAS_INI)) {
504 return_ACPI_STATUS(AE_CTRL_DEPTH);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 }
506
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 /*
Bob Mooreb229cf92006-04-21 17:15:00 -0400508 * Run _STA to determine if this device is present and functioning. We
509 * must know this information for two important reasons (from ACPI spec):
510 *
511 * 1) We can only run _INI if the device is present.
512 * 2) We must abort the device tree walk on this subtree if the device is
513 * not present and is not functional (we will not examine the children)
514 *
515 * The _STA method is not required to be present under the device, we
516 * assume the device is present if _STA does not exist.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 */
Bob Mooreb229cf92006-04-21 17:15:00 -0400518 ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname
519 (ACPI_TYPE_METHOD, device_node, METHOD_NAME__STA));
520
521 status = acpi_ut_execute_STA(device_node, &flags);
Len Brown4be44fc2005-08-05 00:44:28 -0400522 if (ACPI_FAILURE(status)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400523
Bob Mooreb229cf92006-04-21 17:15:00 -0400524 /* Ignore error and move on to next device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
Bob Mooredefba1d2005-12-16 17:05:00 -0500526 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 }
528
529 /*
Bob Mooreb229cf92006-04-21 17:15:00 -0400530 * Flags == -1 means that _STA was not found. In this case, we assume that
531 * the device is both present and functional.
532 *
533 * From the ACPI spec, description of _STA:
534 *
535 * "If a device object (including the processor object) does not have an
536 * _STA object, then OSPM assumes that all of the above bits are set (in
537 * other words, the device is present, ..., and functioning)"
Bob Mooredefba1d2005-12-16 17:05:00 -0500538 */
Bob Mooreb229cf92006-04-21 17:15:00 -0400539 if (flags != ACPI_UINT32_MAX) {
Bob Moore41195322006-05-26 16:36:00 -0400540 walk_info->num_STA++;
Bob Mooreb229cf92006-04-21 17:15:00 -0400541 }
542
543 /*
544 * Examine the PRESENT and FUNCTIONING status bits
545 *
546 * Note: ACPI spec does not seem to specify behavior for the present but
547 * not functioning case, so we assume functioning if present.
548 */
549 if (!(flags & ACPI_STA_DEVICE_PRESENT)) {
550
551 /* Device is not present, we must examine the Functioning bit */
552
553 if (flags & ACPI_STA_DEVICE_FUNCTIONING) {
554 /*
555 * Device is not present but is "functioning". In this case,
556 * we will not run _INI, but we continue to examine the children
557 * of this device.
558 *
Bob Mooreba494be2012-07-12 09:40:10 +0800559 * From the ACPI spec, description of _STA: (note - no mention
Bob Mooreb229cf92006-04-21 17:15:00 -0400560 * of whether to run _INI or not on the device in question)
561 *
562 * "_STA may return bit 0 clear (not present) with bit 3 set
563 * (device is functional). This case is used to indicate a valid
564 * device for which no device driver should be loaded (for example,
565 * a bridge device.) Children of this device may be present and
566 * valid. OSPM should continue enumeration below a device whose
567 * _STA returns this bit combination"
568 */
569 return_ACPI_STATUS(AE_OK);
570 } else {
571 /*
572 * Device is not present and is not functioning. We must abort the
573 * walk of this subtree immediately -- don't look at the children
574 * of such a device.
575 *
576 * From the ACPI spec, description of _INI:
577 *
578 * "If the _STA method indicates that the device is not present,
579 * OSPM will not run the _INI and will not examine the children
580 * of the device for _INI methods"
581 */
582 return_ACPI_STATUS(AE_CTRL_DEPTH);
583 }
584 }
585
586 /*
587 * The device is present or is assumed present if no _STA exists.
588 * Run the _INI if it exists (not required to exist)
589 *
590 * Note: We know there is an _INI within this subtree, but it may not be
591 * under this particular device, it may be lower in the branch.
592 */
593 ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname
594 (ACPI_TYPE_METHOD, device_node, METHOD_NAME__INI));
Bob Mooredefba1d2005-12-16 17:05:00 -0500595
Bob Moore4fa46162015-07-01 14:45:11 +0800596 memset(info, 0, sizeof(struct acpi_evaluate_info));
Bob Moore41195322006-05-26 16:36:00 -0400597 info->prefix_node = device_node;
Bob Moore29a241c2013-05-30 10:00:01 +0800598 info->relative_pathname = METHOD_NAME__INI;
Bob Moore41195322006-05-26 16:36:00 -0400599 info->parameters = NULL;
Bob Moore41195322006-05-26 16:36:00 -0400600 info->flags = ACPI_IGNORE_RETURN_VALUE;
Bob Mooredefba1d2005-12-16 17:05:00 -0500601
Bob Moore41195322006-05-26 16:36:00 -0400602 status = acpi_ns_evaluate(info);
Ingo Molnar5d0e6002007-02-13 13:26:24 +0100603
Bob Mooreb229cf92006-04-21 17:15:00 -0400604 if (ACPI_SUCCESS(status)) {
Bob Moore41195322006-05-26 16:36:00 -0400605 walk_info->num_INI++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 }
Bob Mooreb229cf92006-04-21 17:15:00 -0400607#ifdef ACPI_DEBUG_OUTPUT
608 else if (status != AE_NOT_FOUND) {
609
610 /* Ignore error and move on to next device */
611
Lv Zheng0e166e42015-12-29 13:53:50 +0800612 char *scope_name =
613 acpi_ns_get_normalized_pathname(device_node, TRUE);
Bob Mooreb229cf92006-04-21 17:15:00 -0400614
615 ACPI_EXCEPTION((AE_INFO, status, "during %s._INI execution",
616 scope_name));
617 ACPI_FREE(scope_name);
618 }
619#endif
620
Bob Moore4c90ece2006-06-08 16:29:00 -0400621 /* Ignore errors from above */
622
623 status = AE_OK;
624
Bob Moore41195322006-05-26 16:36:00 -0400625 /*
626 * The _INI method has been run if present; call the Global Initialization
627 * Handler for this device.
628 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 if (acpi_gbl_init_handler) {
Len Brown4be44fc2005-08-05 00:44:28 -0400630 status =
Bob Moore41195322006-05-26 16:36:00 -0400631 acpi_gbl_init_handler(device_node, ACPI_INIT_DEVICE_INI);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 }
633
Bob Moore41195322006-05-26 16:36:00 -0400634 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635}