195b482a8SLen Brown /****************************************************************************** 295b482a8SLen Brown * 395b482a8SLen Brown * Module Name: nsinit - namespace initialization 495b482a8SLen Brown * 595b482a8SLen Brown *****************************************************************************/ 695b482a8SLen Brown 795b482a8SLen Brown /* 8c8100dc4SBob Moore * Copyright (C) 2000 - 2016, Intel Corp. 995b482a8SLen Brown * All rights reserved. 1095b482a8SLen Brown * 1195b482a8SLen Brown * Redistribution and use in source and binary forms, with or without 1295b482a8SLen Brown * modification, are permitted provided that the following conditions 1395b482a8SLen Brown * are met: 1495b482a8SLen Brown * 1. Redistributions of source code must retain the above copyright 1595b482a8SLen Brown * notice, this list of conditions, and the following disclaimer, 1695b482a8SLen Brown * without modification. 1795b482a8SLen Brown * 2. Redistributions in binary form must reproduce at minimum a disclaimer 1895b482a8SLen Brown * substantially similar to the "NO WARRANTY" disclaimer below 1995b482a8SLen Brown * ("Disclaimer") and any redistribution must be conditioned upon 2095b482a8SLen Brown * including a substantially similar Disclaimer requirement for further 2195b482a8SLen Brown * binary redistribution. 2295b482a8SLen Brown * 3. Neither the names of the above-listed copyright holders nor the names 2395b482a8SLen Brown * of any contributors may be used to endorse or promote products derived 2495b482a8SLen Brown * from this software without specific prior written permission. 2595b482a8SLen Brown * 2695b482a8SLen Brown * Alternatively, this software may be distributed under the terms of the 2795b482a8SLen Brown * GNU General Public License ("GPL") version 2 as published by the Free 2895b482a8SLen Brown * Software Foundation. 2995b482a8SLen Brown * 3095b482a8SLen Brown * NO WARRANTY 3195b482a8SLen Brown * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 3295b482a8SLen Brown * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 3395b482a8SLen Brown * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 3495b482a8SLen Brown * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 3595b482a8SLen Brown * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 3695b482a8SLen Brown * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3795b482a8SLen Brown * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3895b482a8SLen Brown * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 3995b482a8SLen Brown * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 4095b482a8SLen Brown * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 4195b482a8SLen Brown * POSSIBILITY OF SUCH DAMAGES. 4295b482a8SLen Brown */ 4395b482a8SLen Brown 4495b482a8SLen Brown #include <acpi/acpi.h> 45e2f7a777SLen Brown #include "accommon.h" 46e2f7a777SLen Brown #include "acnamesp.h" 47e2f7a777SLen Brown #include "acdispat.h" 48e2f7a777SLen Brown #include "acinterp.h" 49ced04366SLv Zheng #include "acevents.h" 5095b482a8SLen Brown 5195b482a8SLen Brown #define _COMPONENT ACPI_NAMESPACE 5295b482a8SLen Brown ACPI_MODULE_NAME("nsinit") 5395b482a8SLen Brown 5495b482a8SLen Brown /* Local prototypes */ 5595b482a8SLen Brown static acpi_status 5695b482a8SLen Brown acpi_ns_init_one_object(acpi_handle obj_handle, 5795b482a8SLen Brown u32 level, void *context, void **return_value); 5895b482a8SLen Brown 5995b482a8SLen Brown static acpi_status 6095b482a8SLen Brown acpi_ns_init_one_device(acpi_handle obj_handle, 6195b482a8SLen Brown u32 nesting_level, void *context, void **return_value); 6295b482a8SLen Brown 6395b482a8SLen Brown static acpi_status 6495b482a8SLen Brown acpi_ns_find_ini_methods(acpi_handle obj_handle, 6595b482a8SLen Brown u32 nesting_level, void *context, void **return_value); 6695b482a8SLen Brown 6795b482a8SLen Brown /******************************************************************************* 6895b482a8SLen Brown * 6995b482a8SLen Brown * FUNCTION: acpi_ns_initialize_objects 7095b482a8SLen Brown * 7195b482a8SLen Brown * PARAMETERS: None 7295b482a8SLen Brown * 7395b482a8SLen Brown * RETURN: Status 7495b482a8SLen Brown * 7595b482a8SLen Brown * DESCRIPTION: Walk the entire namespace and perform any necessary 7695b482a8SLen Brown * initialization on the objects found therein 7795b482a8SLen Brown * 7895b482a8SLen Brown ******************************************************************************/ 7995b482a8SLen Brown 8095b482a8SLen Brown acpi_status acpi_ns_initialize_objects(void) 8195b482a8SLen Brown { 8295b482a8SLen Brown acpi_status status; 8395b482a8SLen Brown struct acpi_init_walk_info info; 8495b482a8SLen Brown 8595b482a8SLen Brown ACPI_FUNCTION_TRACE(ns_initialize_objects); 8695b482a8SLen Brown 8795b482a8SLen Brown ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, 8895b482a8SLen Brown "**** Starting initialization of namespace objects ****\n")); 8995b482a8SLen Brown ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, 902fae3e56SBob Moore "Completing Region/Field/Buffer/Package initialization:\n")); 9195b482a8SLen Brown 9295b482a8SLen Brown /* Set all init info to zero */ 9395b482a8SLen Brown 944fa4616eSBob Moore memset(&info, 0, sizeof(struct acpi_init_walk_info)); 9595b482a8SLen Brown 9695b482a8SLen Brown /* Walk entire namespace from the supplied root */ 9795b482a8SLen Brown 9895b482a8SLen Brown status = acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, 991f86e8c1SLv Zheng ACPI_UINT32_MAX, acpi_ns_init_one_object, 1001f86e8c1SLv Zheng NULL, &info, NULL); 10195b482a8SLen Brown if (ACPI_FAILURE(status)) { 10295b482a8SLen Brown ACPI_EXCEPTION((AE_INFO, status, "During WalkNamespace")); 10395b482a8SLen Brown } 10495b482a8SLen Brown 10595b482a8SLen Brown ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, 1062fae3e56SBob Moore " Initialized %u/%u Regions %u/%u Fields %u/%u " 10796b7b7adSAlexey Starikovskiy "Buffers %u/%u Packages (%u nodes)\n", 10895b482a8SLen Brown info.op_region_init, info.op_region_count, 10995b482a8SLen Brown info.field_init, info.field_count, 11095b482a8SLen Brown info.buffer_init, info.buffer_count, 11195b482a8SLen Brown info.package_init, info.package_count, 11295b482a8SLen Brown info.object_count)); 11395b482a8SLen Brown 11495b482a8SLen Brown ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, 11522b5afceSBob Moore "%u Control Methods found\n%u Op Regions found\n", 11622b5afceSBob Moore info.method_count, info.op_region_count)); 11795b482a8SLen Brown 11895b482a8SLen Brown return_ACPI_STATUS(AE_OK); 11995b482a8SLen Brown } 12095b482a8SLen Brown 12195b482a8SLen Brown /******************************************************************************* 12295b482a8SLen Brown * 12395b482a8SLen Brown * FUNCTION: acpi_ns_initialize_devices 12495b482a8SLen Brown * 12595b482a8SLen Brown * PARAMETERS: None 12695b482a8SLen Brown * 12795b482a8SLen Brown * RETURN: acpi_status 12895b482a8SLen Brown * 12995b482a8SLen Brown * DESCRIPTION: Walk the entire namespace and initialize all ACPI devices. 13095b482a8SLen Brown * This means running _INI on all present devices. 13195b482a8SLen Brown * 13295b482a8SLen Brown * Note: We install PCI config space handler on region access, 13395b482a8SLen Brown * not here. 13495b482a8SLen Brown * 13595b482a8SLen Brown ******************************************************************************/ 13695b482a8SLen Brown 137ced04366SLv Zheng acpi_status acpi_ns_initialize_devices(u32 flags) 13895b482a8SLen Brown { 139*ebc3c9bbSLv Zheng acpi_status status = AE_OK; 14095b482a8SLen Brown struct acpi_device_walk_info info; 14195b482a8SLen Brown 14295b482a8SLen Brown ACPI_FUNCTION_TRACE(ns_initialize_devices); 14395b482a8SLen Brown 144ced04366SLv Zheng if (!(flags & ACPI_NO_DEVICE_INIT)) { 145ced04366SLv Zheng ACPI_DEBUG_PRINT((ACPI_DB_EXEC, 146ced04366SLv Zheng "[Init] Initializing ACPI Devices\n")); 147ced04366SLv Zheng 14895b482a8SLen Brown /* Init counters */ 14995b482a8SLen Brown 15095b482a8SLen Brown info.device_count = 0; 15195b482a8SLen Brown info.num_STA = 0; 15295b482a8SLen Brown info.num_INI = 0; 15395b482a8SLen Brown 15495b482a8SLen Brown ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, 155d4913dc6SBob Moore "Initializing Device/Processor/Thermal objects " 1563e5621a7SBob Moore "and executing _INI/_STA methods:\n")); 15795b482a8SLen Brown 15895b482a8SLen Brown /* Tree analysis: find all subtrees that contain _INI methods */ 15995b482a8SLen Brown 16095b482a8SLen Brown status = acpi_ns_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, 16195b482a8SLen Brown ACPI_UINT32_MAX, FALSE, 162ced04366SLv Zheng acpi_ns_find_ini_methods, NULL, 163ced04366SLv Zheng &info, NULL); 16495b482a8SLen Brown if (ACPI_FAILURE(status)) { 16595b482a8SLen Brown goto error_exit; 16695b482a8SLen Brown } 16795b482a8SLen Brown 16895b482a8SLen Brown /* Allocate the evaluation information block */ 16995b482a8SLen Brown 17095b482a8SLen Brown info.evaluate_info = 17195b482a8SLen Brown ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info)); 17295b482a8SLen Brown if (!info.evaluate_info) { 17395b482a8SLen Brown status = AE_NO_MEMORY; 17495b482a8SLen Brown goto error_exit; 17595b482a8SLen Brown } 17695b482a8SLen Brown 1779e64155eSBob Moore /* 178ced04366SLv Zheng * Execute the "global" _INI method that may appear at the root. 179ced04366SLv Zheng * This support is provided for Windows compatibility (Vista+) and 180ced04366SLv Zheng * is not part of the ACPI specification. 1819e64155eSBob Moore */ 1829e64155eSBob Moore info.evaluate_info->prefix_node = acpi_gbl_root_node; 18329a241ccSBob Moore info.evaluate_info->relative_pathname = METHOD_NAME__INI; 1849e64155eSBob Moore info.evaluate_info->parameters = NULL; 1859e64155eSBob Moore info.evaluate_info->flags = ACPI_IGNORE_RETURN_VALUE; 1869e64155eSBob Moore 1879e64155eSBob Moore status = acpi_ns_evaluate(info.evaluate_info); 1889e64155eSBob Moore if (ACPI_SUCCESS(status)) { 1899e64155eSBob Moore info.num_INI++; 1909e64155eSBob Moore } 191ced04366SLv Zheng } 192ced04366SLv Zheng 193ced04366SLv Zheng /* 194ced04366SLv Zheng * Run all _REG methods 195ced04366SLv Zheng * 196ced04366SLv Zheng * Note: Any objects accessed by the _REG methods will be automatically 197ced04366SLv Zheng * initialized, even if they contain executable AML (see the call to 198ced04366SLv Zheng * acpi_ns_initialize_objects below). 199ced04366SLv Zheng */ 200ced04366SLv Zheng if (!(flags & ACPI_NO_ADDRESS_SPACE_INIT)) { 201ced04366SLv Zheng ACPI_DEBUG_PRINT((ACPI_DB_EXEC, 202ced04366SLv Zheng "[Init] Executing _REG OpRegion methods\n")); 203ced04366SLv Zheng 204ced04366SLv Zheng status = acpi_ev_initialize_op_regions(); 205ced04366SLv Zheng if (ACPI_FAILURE(status)) { 206ced04366SLv Zheng goto error_exit; 207ced04366SLv Zheng } 208ced04366SLv Zheng } 209ced04366SLv Zheng 210ced04366SLv Zheng if (!(flags & ACPI_NO_DEVICE_INIT)) { 2119e64155eSBob Moore 21295b482a8SLen Brown /* Walk namespace to execute all _INIs on present devices */ 21395b482a8SLen Brown 21495b482a8SLen Brown status = acpi_ns_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, 21595b482a8SLen Brown ACPI_UINT32_MAX, FALSE, 216ced04366SLv Zheng acpi_ns_init_one_device, NULL, 217ced04366SLv Zheng &info, NULL); 21895b482a8SLen Brown 219b681f7d9SMatthew Garrett /* 220b681f7d9SMatthew Garrett * Any _OSI requests should be completed by now. If the BIOS has 221b681f7d9SMatthew Garrett * requested any Windows OSI strings, we will always truncate 222b681f7d9SMatthew Garrett * I/O addresses to 16 bits -- for Windows compatibility. 223b681f7d9SMatthew Garrett */ 224b681f7d9SMatthew Garrett if (acpi_gbl_osi_data >= ACPI_OSI_WIN_2000) { 225b681f7d9SMatthew Garrett acpi_gbl_truncate_io_addresses = TRUE; 226b681f7d9SMatthew Garrett } 227b681f7d9SMatthew Garrett 22895b482a8SLen Brown ACPI_FREE(info.evaluate_info); 22995b482a8SLen Brown if (ACPI_FAILURE(status)) { 23095b482a8SLen Brown goto error_exit; 23195b482a8SLen Brown } 23295b482a8SLen Brown 23395b482a8SLen Brown ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, 2342fae3e56SBob Moore " Executed %u _INI methods requiring %u _STA executions " 2355821f754SBob Moore "(examined %u objects)\n", 236ced04366SLv Zheng info.num_INI, info.num_STA, 237ced04366SLv Zheng info.device_count)); 238ced04366SLv Zheng } 23995b482a8SLen Brown 24095b482a8SLen Brown return_ACPI_STATUS(status); 24195b482a8SLen Brown 24295b482a8SLen Brown error_exit: 24395b482a8SLen Brown ACPI_EXCEPTION((AE_INFO, status, "During device initialization")); 24495b482a8SLen Brown return_ACPI_STATUS(status); 24595b482a8SLen Brown } 24695b482a8SLen Brown 24795b482a8SLen Brown /******************************************************************************* 24895b482a8SLen Brown * 24995b482a8SLen Brown * FUNCTION: acpi_ns_init_one_object 25095b482a8SLen Brown * 25195b482a8SLen Brown * PARAMETERS: obj_handle - Node 252ba494beeSBob Moore * level - Current nesting level 253ba494beeSBob Moore * context - Points to a init info struct 25495b482a8SLen Brown * return_value - Not used 25595b482a8SLen Brown * 25695b482a8SLen Brown * RETURN: Status 25795b482a8SLen Brown * 25895b482a8SLen Brown * DESCRIPTION: Callback from acpi_walk_namespace. Invoked for every object 25995b482a8SLen Brown * within the namespace. 26095b482a8SLen Brown * 26195b482a8SLen Brown * Currently, the only objects that require initialization are: 26295b482a8SLen Brown * 1) Methods 26395b482a8SLen Brown * 2) Op Regions 26495b482a8SLen Brown * 26595b482a8SLen Brown ******************************************************************************/ 26695b482a8SLen Brown 26795b482a8SLen Brown static acpi_status 26895b482a8SLen Brown acpi_ns_init_one_object(acpi_handle obj_handle, 26995b482a8SLen Brown u32 level, void *context, void **return_value) 27095b482a8SLen Brown { 27195b482a8SLen Brown acpi_object_type type; 27295b482a8SLen Brown acpi_status status = AE_OK; 27395b482a8SLen Brown struct acpi_init_walk_info *info = 27495b482a8SLen Brown (struct acpi_init_walk_info *)context; 27595b482a8SLen Brown struct acpi_namespace_node *node = 27695b482a8SLen Brown (struct acpi_namespace_node *)obj_handle; 27795b482a8SLen Brown union acpi_operand_object *obj_desc; 27895b482a8SLen Brown 27995b482a8SLen Brown ACPI_FUNCTION_NAME(ns_init_one_object); 28095b482a8SLen Brown 28195b482a8SLen Brown info->object_count++; 28295b482a8SLen Brown 28395b482a8SLen Brown /* And even then, we are only interested in a few object types */ 28495b482a8SLen Brown 28595b482a8SLen Brown type = acpi_ns_get_type(obj_handle); 28695b482a8SLen Brown obj_desc = acpi_ns_get_attached_object(node); 28795b482a8SLen Brown if (!obj_desc) { 28895b482a8SLen Brown return (AE_OK); 28995b482a8SLen Brown } 29095b482a8SLen Brown 29195b482a8SLen Brown /* Increment counters for object types we are looking for */ 29295b482a8SLen Brown 29395b482a8SLen Brown switch (type) { 29495b482a8SLen Brown case ACPI_TYPE_REGION: 2951d1ea1b7SChao Guan 29695b482a8SLen Brown info->op_region_count++; 29795b482a8SLen Brown break; 29895b482a8SLen Brown 29995b482a8SLen Brown case ACPI_TYPE_BUFFER_FIELD: 3001d1ea1b7SChao Guan 30195b482a8SLen Brown info->field_count++; 30295b482a8SLen Brown break; 30395b482a8SLen Brown 30495b482a8SLen Brown case ACPI_TYPE_LOCAL_BANK_FIELD: 3051d1ea1b7SChao Guan 30695b482a8SLen Brown info->field_count++; 30795b482a8SLen Brown break; 30895b482a8SLen Brown 30995b482a8SLen Brown case ACPI_TYPE_BUFFER: 3101d1ea1b7SChao Guan 31195b482a8SLen Brown info->buffer_count++; 31295b482a8SLen Brown break; 31395b482a8SLen Brown 31495b482a8SLen Brown case ACPI_TYPE_PACKAGE: 3151d1ea1b7SChao Guan 31695b482a8SLen Brown info->package_count++; 31795b482a8SLen Brown break; 31895b482a8SLen Brown 31995b482a8SLen Brown default: 32095b482a8SLen Brown 32195b482a8SLen Brown /* No init required, just exit now */ 3221d1ea1b7SChao Guan 32395b482a8SLen Brown return (AE_OK); 32495b482a8SLen Brown } 32595b482a8SLen Brown 326d4913dc6SBob Moore /* If the object is already initialized, nothing else to do */ 327d4913dc6SBob Moore 32895b482a8SLen Brown if (obj_desc->common.flags & AOPOBJ_DATA_VALID) { 32995b482a8SLen Brown return (AE_OK); 33095b482a8SLen Brown } 33195b482a8SLen Brown 332d4913dc6SBob Moore /* Must lock the interpreter before executing AML code */ 333d4913dc6SBob Moore 33495b482a8SLen Brown acpi_ex_enter_interpreter(); 33595b482a8SLen Brown 33695b482a8SLen Brown /* 33795b482a8SLen Brown * Each of these types can contain executable AML code within the 33895b482a8SLen Brown * declaration. 33995b482a8SLen Brown */ 34095b482a8SLen Brown switch (type) { 34195b482a8SLen Brown case ACPI_TYPE_REGION: 34295b482a8SLen Brown 34395b482a8SLen Brown info->op_region_init++; 34495b482a8SLen Brown status = acpi_ds_get_region_arguments(obj_desc); 34595b482a8SLen Brown break; 34695b482a8SLen Brown 34795b482a8SLen Brown case ACPI_TYPE_BUFFER_FIELD: 34895b482a8SLen Brown 34995b482a8SLen Brown info->field_init++; 35095b482a8SLen Brown status = acpi_ds_get_buffer_field_arguments(obj_desc); 35195b482a8SLen Brown break; 35295b482a8SLen Brown 35395b482a8SLen Brown case ACPI_TYPE_LOCAL_BANK_FIELD: 35495b482a8SLen Brown 35595b482a8SLen Brown info->field_init++; 35695b482a8SLen Brown status = acpi_ds_get_bank_field_arguments(obj_desc); 35795b482a8SLen Brown break; 35895b482a8SLen Brown 35995b482a8SLen Brown case ACPI_TYPE_BUFFER: 36095b482a8SLen Brown 36195b482a8SLen Brown info->buffer_init++; 36295b482a8SLen Brown status = acpi_ds_get_buffer_arguments(obj_desc); 36395b482a8SLen Brown break; 36495b482a8SLen Brown 36595b482a8SLen Brown case ACPI_TYPE_PACKAGE: 36695b482a8SLen Brown 36795b482a8SLen Brown info->package_init++; 36895b482a8SLen Brown status = acpi_ds_get_package_arguments(obj_desc); 36995b482a8SLen Brown break; 37095b482a8SLen Brown 37195b482a8SLen Brown default: 3721d1ea1b7SChao Guan 37395b482a8SLen Brown /* No other types can get here */ 3741d1ea1b7SChao Guan 37595b482a8SLen Brown break; 37695b482a8SLen Brown } 37795b482a8SLen Brown 37895b482a8SLen Brown if (ACPI_FAILURE(status)) { 37995b482a8SLen Brown ACPI_EXCEPTION((AE_INFO, status, 38095b482a8SLen Brown "Could not execute arguments for [%4.4s] (%s)", 38195b482a8SLen Brown acpi_ut_get_node_name(node), 38295b482a8SLen Brown acpi_ut_get_type_name(type))); 38395b482a8SLen Brown } 38495b482a8SLen Brown 38595b482a8SLen Brown /* 38695b482a8SLen Brown * We ignore errors from above, and always return OK, since we don't want 38795b482a8SLen Brown * to abort the walk on any single error. 38895b482a8SLen Brown */ 38995b482a8SLen Brown acpi_ex_exit_interpreter(); 39095b482a8SLen Brown return (AE_OK); 39195b482a8SLen Brown } 39295b482a8SLen Brown 39395b482a8SLen Brown /******************************************************************************* 39495b482a8SLen Brown * 39595b482a8SLen Brown * FUNCTION: acpi_ns_find_ini_methods 39695b482a8SLen Brown * 39795b482a8SLen Brown * PARAMETERS: acpi_walk_callback 39895b482a8SLen Brown * 39995b482a8SLen Brown * RETURN: acpi_status 40095b482a8SLen Brown * 40195b482a8SLen Brown * DESCRIPTION: Called during namespace walk. Finds objects named _INI under 40295b482a8SLen Brown * device/processor/thermal objects, and marks the entire subtree 40395b482a8SLen Brown * with a SUBTREE_HAS_INI flag. This flag is used during the 40495b482a8SLen Brown * subsequent device initialization walk to avoid entire subtrees 40595b482a8SLen Brown * that do not contain an _INI. 40695b482a8SLen Brown * 40795b482a8SLen Brown ******************************************************************************/ 40895b482a8SLen Brown 40995b482a8SLen Brown static acpi_status 41095b482a8SLen Brown acpi_ns_find_ini_methods(acpi_handle obj_handle, 41195b482a8SLen Brown u32 nesting_level, void *context, void **return_value) 41295b482a8SLen Brown { 41395b482a8SLen Brown struct acpi_device_walk_info *info = 41495b482a8SLen Brown ACPI_CAST_PTR(struct acpi_device_walk_info, context); 41595b482a8SLen Brown struct acpi_namespace_node *node; 41695b482a8SLen Brown struct acpi_namespace_node *parent_node; 41795b482a8SLen Brown 41895b482a8SLen Brown /* Keep count of device/processor/thermal objects */ 41995b482a8SLen Brown 42095b482a8SLen Brown node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_handle); 42195b482a8SLen Brown if ((node->type == ACPI_TYPE_DEVICE) || 42295b482a8SLen Brown (node->type == ACPI_TYPE_PROCESSOR) || 42395b482a8SLen Brown (node->type == ACPI_TYPE_THERMAL)) { 42495b482a8SLen Brown info->device_count++; 42595b482a8SLen Brown return (AE_OK); 42695b482a8SLen Brown } 42795b482a8SLen Brown 42895b482a8SLen Brown /* We are only looking for methods named _INI */ 42995b482a8SLen Brown 43095b482a8SLen Brown if (!ACPI_COMPARE_NAME(node->name.ascii, METHOD_NAME__INI)) { 43195b482a8SLen Brown return (AE_OK); 43295b482a8SLen Brown } 43395b482a8SLen Brown 43495b482a8SLen Brown /* 43595b482a8SLen Brown * The only _INI methods that we care about are those that are 43695b482a8SLen Brown * present under Device, Processor, and Thermal objects. 43795b482a8SLen Brown */ 438c45b5c09SAlexey Starikovskiy parent_node = node->parent; 43995b482a8SLen Brown switch (parent_node->type) { 44095b482a8SLen Brown case ACPI_TYPE_DEVICE: 44195b482a8SLen Brown case ACPI_TYPE_PROCESSOR: 44295b482a8SLen Brown case ACPI_TYPE_THERMAL: 44395b482a8SLen Brown 44495b482a8SLen Brown /* Mark parent and bubble up the INI present flag to the root */ 44595b482a8SLen Brown 44695b482a8SLen Brown while (parent_node) { 44795b482a8SLen Brown parent_node->flags |= ANOBJ_SUBTREE_HAS_INI; 448c45b5c09SAlexey Starikovskiy parent_node = parent_node->parent; 44995b482a8SLen Brown } 45095b482a8SLen Brown break; 45195b482a8SLen Brown 45295b482a8SLen Brown default: 4531d1ea1b7SChao Guan 45495b482a8SLen Brown break; 45595b482a8SLen Brown } 45695b482a8SLen Brown 45795b482a8SLen Brown return (AE_OK); 45895b482a8SLen Brown } 45995b482a8SLen Brown 46095b482a8SLen Brown /******************************************************************************* 46195b482a8SLen Brown * 46295b482a8SLen Brown * FUNCTION: acpi_ns_init_one_device 46395b482a8SLen Brown * 46495b482a8SLen Brown * PARAMETERS: acpi_walk_callback 46595b482a8SLen Brown * 46695b482a8SLen Brown * RETURN: acpi_status 46795b482a8SLen Brown * 46895b482a8SLen Brown * DESCRIPTION: This is called once per device soon after ACPI is enabled 46995b482a8SLen Brown * to initialize each device. It determines if the device is 47095b482a8SLen Brown * present, and if so, calls _INI. 47195b482a8SLen Brown * 47295b482a8SLen Brown ******************************************************************************/ 47395b482a8SLen Brown 47495b482a8SLen Brown static acpi_status 47595b482a8SLen Brown acpi_ns_init_one_device(acpi_handle obj_handle, 47695b482a8SLen Brown u32 nesting_level, void *context, void **return_value) 47795b482a8SLen Brown { 47895b482a8SLen Brown struct acpi_device_walk_info *walk_info = 47995b482a8SLen Brown ACPI_CAST_PTR(struct acpi_device_walk_info, context); 48095b482a8SLen Brown struct acpi_evaluate_info *info = walk_info->evaluate_info; 48195b482a8SLen Brown u32 flags; 48295b482a8SLen Brown acpi_status status; 48395b482a8SLen Brown struct acpi_namespace_node *device_node; 48495b482a8SLen Brown 48595b482a8SLen Brown ACPI_FUNCTION_TRACE(ns_init_one_device); 48695b482a8SLen Brown 48795b482a8SLen Brown /* We are interested in Devices, Processors and thermal_zones only */ 48895b482a8SLen Brown 48995b482a8SLen Brown device_node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_handle); 49095b482a8SLen Brown if ((device_node->type != ACPI_TYPE_DEVICE) && 49195b482a8SLen Brown (device_node->type != ACPI_TYPE_PROCESSOR) && 49295b482a8SLen Brown (device_node->type != ACPI_TYPE_THERMAL)) { 49395b482a8SLen Brown return_ACPI_STATUS(AE_OK); 49495b482a8SLen Brown } 49595b482a8SLen Brown 49695b482a8SLen Brown /* 49795b482a8SLen Brown * Because of an earlier namespace analysis, all subtrees that contain an 49895b482a8SLen Brown * _INI method are tagged. 49995b482a8SLen Brown * 50095b482a8SLen Brown * If this device subtree does not contain any _INI methods, we 50195b482a8SLen Brown * can exit now and stop traversing this entire subtree. 50295b482a8SLen Brown */ 50395b482a8SLen Brown if (!(device_node->flags & ANOBJ_SUBTREE_HAS_INI)) { 50495b482a8SLen Brown return_ACPI_STATUS(AE_CTRL_DEPTH); 50595b482a8SLen Brown } 50695b482a8SLen Brown 50795b482a8SLen Brown /* 50895b482a8SLen Brown * Run _STA to determine if this device is present and functioning. We 50995b482a8SLen Brown * must know this information for two important reasons (from ACPI spec): 51095b482a8SLen Brown * 51195b482a8SLen Brown * 1) We can only run _INI if the device is present. 51295b482a8SLen Brown * 2) We must abort the device tree walk on this subtree if the device is 51395b482a8SLen Brown * not present and is not functional (we will not examine the children) 51495b482a8SLen Brown * 51595b482a8SLen Brown * The _STA method is not required to be present under the device, we 51695b482a8SLen Brown * assume the device is present if _STA does not exist. 51795b482a8SLen Brown */ 51895b482a8SLen Brown ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname 51995b482a8SLen Brown (ACPI_TYPE_METHOD, device_node, METHOD_NAME__STA)); 52095b482a8SLen Brown 52195b482a8SLen Brown status = acpi_ut_execute_STA(device_node, &flags); 52295b482a8SLen Brown if (ACPI_FAILURE(status)) { 52395b482a8SLen Brown 52495b482a8SLen Brown /* Ignore error and move on to next device */ 52595b482a8SLen Brown 52695b482a8SLen Brown return_ACPI_STATUS(AE_OK); 52795b482a8SLen Brown } 52895b482a8SLen Brown 52995b482a8SLen Brown /* 53095b482a8SLen Brown * Flags == -1 means that _STA was not found. In this case, we assume that 53195b482a8SLen Brown * the device is both present and functional. 53295b482a8SLen Brown * 53395b482a8SLen Brown * From the ACPI spec, description of _STA: 53495b482a8SLen Brown * 53595b482a8SLen Brown * "If a device object (including the processor object) does not have an 53695b482a8SLen Brown * _STA object, then OSPM assumes that all of the above bits are set (in 53795b482a8SLen Brown * other words, the device is present, ..., and functioning)" 53895b482a8SLen Brown */ 53995b482a8SLen Brown if (flags != ACPI_UINT32_MAX) { 54095b482a8SLen Brown walk_info->num_STA++; 54195b482a8SLen Brown } 54295b482a8SLen Brown 54395b482a8SLen Brown /* 54495b482a8SLen Brown * Examine the PRESENT and FUNCTIONING status bits 54595b482a8SLen Brown * 54695b482a8SLen Brown * Note: ACPI spec does not seem to specify behavior for the present but 54795b482a8SLen Brown * not functioning case, so we assume functioning if present. 54895b482a8SLen Brown */ 54995b482a8SLen Brown if (!(flags & ACPI_STA_DEVICE_PRESENT)) { 55095b482a8SLen Brown 55195b482a8SLen Brown /* Device is not present, we must examine the Functioning bit */ 55295b482a8SLen Brown 55395b482a8SLen Brown if (flags & ACPI_STA_DEVICE_FUNCTIONING) { 55495b482a8SLen Brown /* 55595b482a8SLen Brown * Device is not present but is "functioning". In this case, 55695b482a8SLen Brown * we will not run _INI, but we continue to examine the children 55795b482a8SLen Brown * of this device. 55895b482a8SLen Brown * 559ba494beeSBob Moore * From the ACPI spec, description of _STA: (note - no mention 56095b482a8SLen Brown * of whether to run _INI or not on the device in question) 56195b482a8SLen Brown * 56295b482a8SLen Brown * "_STA may return bit 0 clear (not present) with bit 3 set 56395b482a8SLen Brown * (device is functional). This case is used to indicate a valid 56495b482a8SLen Brown * device for which no device driver should be loaded (for example, 56595b482a8SLen Brown * a bridge device.) Children of this device may be present and 56695b482a8SLen Brown * valid. OSPM should continue enumeration below a device whose 56795b482a8SLen Brown * _STA returns this bit combination" 56895b482a8SLen Brown */ 56995b482a8SLen Brown return_ACPI_STATUS(AE_OK); 57095b482a8SLen Brown } else { 57195b482a8SLen Brown /* 57295b482a8SLen Brown * Device is not present and is not functioning. We must abort the 57395b482a8SLen Brown * walk of this subtree immediately -- don't look at the children 57495b482a8SLen Brown * of such a device. 57595b482a8SLen Brown * 57695b482a8SLen Brown * From the ACPI spec, description of _INI: 57795b482a8SLen Brown * 57895b482a8SLen Brown * "If the _STA method indicates that the device is not present, 57995b482a8SLen Brown * OSPM will not run the _INI and will not examine the children 58095b482a8SLen Brown * of the device for _INI methods" 58195b482a8SLen Brown */ 58295b482a8SLen Brown return_ACPI_STATUS(AE_CTRL_DEPTH); 58395b482a8SLen Brown } 58495b482a8SLen Brown } 58595b482a8SLen Brown 58695b482a8SLen Brown /* 58795b482a8SLen Brown * The device is present or is assumed present if no _STA exists. 58895b482a8SLen Brown * Run the _INI if it exists (not required to exist) 58995b482a8SLen Brown * 59095b482a8SLen Brown * Note: We know there is an _INI within this subtree, but it may not be 59195b482a8SLen Brown * under this particular device, it may be lower in the branch. 59295b482a8SLen Brown */ 59395b482a8SLen Brown ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname 59495b482a8SLen Brown (ACPI_TYPE_METHOD, device_node, METHOD_NAME__INI)); 59595b482a8SLen Brown 5964fa4616eSBob Moore memset(info, 0, sizeof(struct acpi_evaluate_info)); 59795b482a8SLen Brown info->prefix_node = device_node; 59829a241ccSBob Moore info->relative_pathname = METHOD_NAME__INI; 59995b482a8SLen Brown info->parameters = NULL; 60095b482a8SLen Brown info->flags = ACPI_IGNORE_RETURN_VALUE; 60195b482a8SLen Brown 60295b482a8SLen Brown status = acpi_ns_evaluate(info); 60395b482a8SLen Brown 60495b482a8SLen Brown if (ACPI_SUCCESS(status)) { 60595b482a8SLen Brown walk_info->num_INI++; 60695b482a8SLen Brown } 60795b482a8SLen Brown #ifdef ACPI_DEBUG_OUTPUT 60895b482a8SLen Brown else if (status != AE_NOT_FOUND) { 60995b482a8SLen Brown 61095b482a8SLen Brown /* Ignore error and move on to next device */ 61195b482a8SLen Brown 6120e166e4fSLv Zheng char *scope_name = 6130e166e4fSLv Zheng acpi_ns_get_normalized_pathname(device_node, TRUE); 61495b482a8SLen Brown 61595b482a8SLen Brown ACPI_EXCEPTION((AE_INFO, status, "during %s._INI execution", 61695b482a8SLen Brown scope_name)); 61795b482a8SLen Brown ACPI_FREE(scope_name); 61895b482a8SLen Brown } 61995b482a8SLen Brown #endif 62095b482a8SLen Brown 62195b482a8SLen Brown /* Ignore errors from above */ 62295b482a8SLen Brown 62395b482a8SLen Brown status = AE_OK; 62495b482a8SLen Brown 62595b482a8SLen Brown /* 62695b482a8SLen Brown * The _INI method has been run if present; call the Global Initialization 62795b482a8SLen Brown * Handler for this device. 62895b482a8SLen Brown */ 62995b482a8SLen Brown if (acpi_gbl_init_handler) { 63095b482a8SLen Brown status = 63195b482a8SLen Brown acpi_gbl_init_handler(device_node, ACPI_INIT_DEVICE_INI); 63295b482a8SLen Brown } 63395b482a8SLen Brown 63495b482a8SLen Brown return_ACPI_STATUS(status); 63595b482a8SLen Brown } 636