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 87*5508df89SLv Zheng ACPI_DEBUG_PRINT((ACPI_DB_EXEC, 88*5508df89SLv Zheng "[Init] Completing Initialization of ACPI Objects\n")); 8995b482a8SLen Brown ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, 9095b482a8SLen Brown "**** Starting initialization of namespace objects ****\n")); 9195b482a8SLen Brown ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, 922fae3e56SBob Moore "Completing Region/Field/Buffer/Package initialization:\n")); 9395b482a8SLen Brown 9495b482a8SLen Brown /* Set all init info to zero */ 9595b482a8SLen Brown 964fa4616eSBob Moore memset(&info, 0, sizeof(struct acpi_init_walk_info)); 9795b482a8SLen Brown 9895b482a8SLen Brown /* Walk entire namespace from the supplied root */ 9995b482a8SLen Brown 10095b482a8SLen Brown status = acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, 1011f86e8c1SLv Zheng ACPI_UINT32_MAX, acpi_ns_init_one_object, 1021f86e8c1SLv Zheng NULL, &info, NULL); 10395b482a8SLen Brown if (ACPI_FAILURE(status)) { 10495b482a8SLen Brown ACPI_EXCEPTION((AE_INFO, status, "During WalkNamespace")); 10595b482a8SLen Brown } 10695b482a8SLen Brown 10795b482a8SLen Brown ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, 1082fae3e56SBob Moore " Initialized %u/%u Regions %u/%u Fields %u/%u " 10996b7b7adSAlexey Starikovskiy "Buffers %u/%u Packages (%u nodes)\n", 11095b482a8SLen Brown info.op_region_init, info.op_region_count, 11195b482a8SLen Brown info.field_init, info.field_count, 11295b482a8SLen Brown info.buffer_init, info.buffer_count, 11395b482a8SLen Brown info.package_init, info.package_count, 11495b482a8SLen Brown info.object_count)); 11595b482a8SLen Brown 11695b482a8SLen Brown ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, 11722b5afceSBob Moore "%u Control Methods found\n%u Op Regions found\n", 11822b5afceSBob Moore info.method_count, info.op_region_count)); 11995b482a8SLen Brown 12095b482a8SLen Brown return_ACPI_STATUS(AE_OK); 12195b482a8SLen Brown } 12295b482a8SLen Brown 12395b482a8SLen Brown /******************************************************************************* 12495b482a8SLen Brown * 12595b482a8SLen Brown * FUNCTION: acpi_ns_initialize_devices 12695b482a8SLen Brown * 12795b482a8SLen Brown * PARAMETERS: None 12895b482a8SLen Brown * 12995b482a8SLen Brown * RETURN: acpi_status 13095b482a8SLen Brown * 13195b482a8SLen Brown * DESCRIPTION: Walk the entire namespace and initialize all ACPI devices. 13295b482a8SLen Brown * This means running _INI on all present devices. 13395b482a8SLen Brown * 13495b482a8SLen Brown * Note: We install PCI config space handler on region access, 13595b482a8SLen Brown * not here. 13695b482a8SLen Brown * 13795b482a8SLen Brown ******************************************************************************/ 13895b482a8SLen Brown 139ced04366SLv Zheng acpi_status acpi_ns_initialize_devices(u32 flags) 14095b482a8SLen Brown { 141ebc3c9bbSLv Zheng acpi_status status = AE_OK; 14295b482a8SLen Brown struct acpi_device_walk_info info; 14395b482a8SLen Brown 14495b482a8SLen Brown ACPI_FUNCTION_TRACE(ns_initialize_devices); 14595b482a8SLen Brown 146ced04366SLv Zheng if (!(flags & ACPI_NO_DEVICE_INIT)) { 147ced04366SLv Zheng ACPI_DEBUG_PRINT((ACPI_DB_EXEC, 148ced04366SLv Zheng "[Init] Initializing ACPI Devices\n")); 149ced04366SLv Zheng 15095b482a8SLen Brown /* Init counters */ 15195b482a8SLen Brown 15295b482a8SLen Brown info.device_count = 0; 15395b482a8SLen Brown info.num_STA = 0; 15495b482a8SLen Brown info.num_INI = 0; 15595b482a8SLen Brown 15695b482a8SLen Brown ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, 157d4913dc6SBob Moore "Initializing Device/Processor/Thermal objects " 1583e5621a7SBob Moore "and executing _INI/_STA methods:\n")); 15995b482a8SLen Brown 16095b482a8SLen Brown /* Tree analysis: find all subtrees that contain _INI methods */ 16195b482a8SLen Brown 16295b482a8SLen Brown status = acpi_ns_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, 16395b482a8SLen Brown ACPI_UINT32_MAX, FALSE, 164ced04366SLv Zheng acpi_ns_find_ini_methods, NULL, 165ced04366SLv Zheng &info, NULL); 16695b482a8SLen Brown if (ACPI_FAILURE(status)) { 16795b482a8SLen Brown goto error_exit; 16895b482a8SLen Brown } 16995b482a8SLen Brown 17095b482a8SLen Brown /* Allocate the evaluation information block */ 17195b482a8SLen Brown 17295b482a8SLen Brown info.evaluate_info = 17395b482a8SLen Brown ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info)); 17495b482a8SLen Brown if (!info.evaluate_info) { 17595b482a8SLen Brown status = AE_NO_MEMORY; 17695b482a8SLen Brown goto error_exit; 17795b482a8SLen Brown } 17895b482a8SLen Brown 1799e64155eSBob Moore /* 180ced04366SLv Zheng * Execute the "global" _INI method that may appear at the root. 181ced04366SLv Zheng * This support is provided for Windows compatibility (Vista+) and 182ced04366SLv Zheng * is not part of the ACPI specification. 1839e64155eSBob Moore */ 1849e64155eSBob Moore info.evaluate_info->prefix_node = acpi_gbl_root_node; 18529a241ccSBob Moore info.evaluate_info->relative_pathname = METHOD_NAME__INI; 1869e64155eSBob Moore info.evaluate_info->parameters = NULL; 1879e64155eSBob Moore info.evaluate_info->flags = ACPI_IGNORE_RETURN_VALUE; 1889e64155eSBob Moore 1899e64155eSBob Moore status = acpi_ns_evaluate(info.evaluate_info); 1909e64155eSBob Moore if (ACPI_SUCCESS(status)) { 1919e64155eSBob Moore info.num_INI++; 1929e64155eSBob Moore } 193ced04366SLv Zheng } 194ced04366SLv Zheng 195ced04366SLv Zheng /* 196ced04366SLv Zheng * Run all _REG methods 197ced04366SLv Zheng * 198ced04366SLv Zheng * Note: Any objects accessed by the _REG methods will be automatically 199ced04366SLv Zheng * initialized, even if they contain executable AML (see the call to 200ced04366SLv Zheng * acpi_ns_initialize_objects below). 201ced04366SLv Zheng */ 202ced04366SLv Zheng if (!(flags & ACPI_NO_ADDRESS_SPACE_INIT)) { 203ced04366SLv Zheng ACPI_DEBUG_PRINT((ACPI_DB_EXEC, 204ced04366SLv Zheng "[Init] Executing _REG OpRegion methods\n")); 205ced04366SLv Zheng 206ced04366SLv Zheng status = acpi_ev_initialize_op_regions(); 207ced04366SLv Zheng if (ACPI_FAILURE(status)) { 208ced04366SLv Zheng goto error_exit; 209ced04366SLv Zheng } 210ced04366SLv Zheng } 211ced04366SLv Zheng 212ced04366SLv Zheng if (!(flags & ACPI_NO_DEVICE_INIT)) { 2139e64155eSBob Moore 21495b482a8SLen Brown /* Walk namespace to execute all _INIs on present devices */ 21595b482a8SLen Brown 21695b482a8SLen Brown status = acpi_ns_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, 21795b482a8SLen Brown ACPI_UINT32_MAX, FALSE, 218ced04366SLv Zheng acpi_ns_init_one_device, NULL, 219ced04366SLv Zheng &info, NULL); 22095b482a8SLen Brown 221b681f7d9SMatthew Garrett /* 222b681f7d9SMatthew Garrett * Any _OSI requests should be completed by now. If the BIOS has 223b681f7d9SMatthew Garrett * requested any Windows OSI strings, we will always truncate 224b681f7d9SMatthew Garrett * I/O addresses to 16 bits -- for Windows compatibility. 225b681f7d9SMatthew Garrett */ 226b681f7d9SMatthew Garrett if (acpi_gbl_osi_data >= ACPI_OSI_WIN_2000) { 227b681f7d9SMatthew Garrett acpi_gbl_truncate_io_addresses = TRUE; 228b681f7d9SMatthew Garrett } 229b681f7d9SMatthew Garrett 23095b482a8SLen Brown ACPI_FREE(info.evaluate_info); 23195b482a8SLen Brown if (ACPI_FAILURE(status)) { 23295b482a8SLen Brown goto error_exit; 23395b482a8SLen Brown } 23495b482a8SLen Brown 23595b482a8SLen Brown ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, 2362fae3e56SBob Moore " Executed %u _INI methods requiring %u _STA executions " 2375821f754SBob Moore "(examined %u objects)\n", 238ced04366SLv Zheng info.num_INI, info.num_STA, 239ced04366SLv Zheng info.device_count)); 240ced04366SLv Zheng } 24195b482a8SLen Brown 24295b482a8SLen Brown return_ACPI_STATUS(status); 24395b482a8SLen Brown 24495b482a8SLen Brown error_exit: 24595b482a8SLen Brown ACPI_EXCEPTION((AE_INFO, status, "During device initialization")); 24695b482a8SLen Brown return_ACPI_STATUS(status); 24795b482a8SLen Brown } 24895b482a8SLen Brown 24995b482a8SLen Brown /******************************************************************************* 25095b482a8SLen Brown * 25195b482a8SLen Brown * FUNCTION: acpi_ns_init_one_object 25295b482a8SLen Brown * 25395b482a8SLen Brown * PARAMETERS: obj_handle - Node 254ba494beeSBob Moore * level - Current nesting level 255ba494beeSBob Moore * context - Points to a init info struct 25695b482a8SLen Brown * return_value - Not used 25795b482a8SLen Brown * 25895b482a8SLen Brown * RETURN: Status 25995b482a8SLen Brown * 26095b482a8SLen Brown * DESCRIPTION: Callback from acpi_walk_namespace. Invoked for every object 26195b482a8SLen Brown * within the namespace. 26295b482a8SLen Brown * 26395b482a8SLen Brown * Currently, the only objects that require initialization are: 26495b482a8SLen Brown * 1) Methods 26595b482a8SLen Brown * 2) Op Regions 26695b482a8SLen Brown * 26795b482a8SLen Brown ******************************************************************************/ 26895b482a8SLen Brown 26995b482a8SLen Brown static acpi_status 27095b482a8SLen Brown acpi_ns_init_one_object(acpi_handle obj_handle, 27195b482a8SLen Brown u32 level, void *context, void **return_value) 27295b482a8SLen Brown { 27395b482a8SLen Brown acpi_object_type type; 27495b482a8SLen Brown acpi_status status = AE_OK; 27595b482a8SLen Brown struct acpi_init_walk_info *info = 27695b482a8SLen Brown (struct acpi_init_walk_info *)context; 27795b482a8SLen Brown struct acpi_namespace_node *node = 27895b482a8SLen Brown (struct acpi_namespace_node *)obj_handle; 27995b482a8SLen Brown union acpi_operand_object *obj_desc; 28095b482a8SLen Brown 28195b482a8SLen Brown ACPI_FUNCTION_NAME(ns_init_one_object); 28295b482a8SLen Brown 28395b482a8SLen Brown info->object_count++; 28495b482a8SLen Brown 28595b482a8SLen Brown /* And even then, we are only interested in a few object types */ 28695b482a8SLen Brown 28795b482a8SLen Brown type = acpi_ns_get_type(obj_handle); 28895b482a8SLen Brown obj_desc = acpi_ns_get_attached_object(node); 28995b482a8SLen Brown if (!obj_desc) { 29095b482a8SLen Brown return (AE_OK); 29195b482a8SLen Brown } 29295b482a8SLen Brown 29395b482a8SLen Brown /* Increment counters for object types we are looking for */ 29495b482a8SLen Brown 29595b482a8SLen Brown switch (type) { 29695b482a8SLen Brown case ACPI_TYPE_REGION: 2971d1ea1b7SChao Guan 29895b482a8SLen Brown info->op_region_count++; 29995b482a8SLen Brown break; 30095b482a8SLen Brown 30195b482a8SLen Brown case ACPI_TYPE_BUFFER_FIELD: 3021d1ea1b7SChao Guan 30395b482a8SLen Brown info->field_count++; 30495b482a8SLen Brown break; 30595b482a8SLen Brown 30695b482a8SLen Brown case ACPI_TYPE_LOCAL_BANK_FIELD: 3071d1ea1b7SChao Guan 30895b482a8SLen Brown info->field_count++; 30995b482a8SLen Brown break; 31095b482a8SLen Brown 31195b482a8SLen Brown case ACPI_TYPE_BUFFER: 3121d1ea1b7SChao Guan 31395b482a8SLen Brown info->buffer_count++; 31495b482a8SLen Brown break; 31595b482a8SLen Brown 31695b482a8SLen Brown case ACPI_TYPE_PACKAGE: 3171d1ea1b7SChao Guan 31895b482a8SLen Brown info->package_count++; 31995b482a8SLen Brown break; 32095b482a8SLen Brown 32195b482a8SLen Brown default: 32295b482a8SLen Brown 32395b482a8SLen Brown /* No init required, just exit now */ 3241d1ea1b7SChao Guan 32595b482a8SLen Brown return (AE_OK); 32695b482a8SLen Brown } 32795b482a8SLen Brown 328d4913dc6SBob Moore /* If the object is already initialized, nothing else to do */ 329d4913dc6SBob Moore 33095b482a8SLen Brown if (obj_desc->common.flags & AOPOBJ_DATA_VALID) { 33195b482a8SLen Brown return (AE_OK); 33295b482a8SLen Brown } 33395b482a8SLen Brown 334d4913dc6SBob Moore /* Must lock the interpreter before executing AML code */ 335d4913dc6SBob Moore 33695b482a8SLen Brown acpi_ex_enter_interpreter(); 33795b482a8SLen Brown 33895b482a8SLen Brown /* 33995b482a8SLen Brown * Each of these types can contain executable AML code within the 34095b482a8SLen Brown * declaration. 34195b482a8SLen Brown */ 34295b482a8SLen Brown switch (type) { 34395b482a8SLen Brown case ACPI_TYPE_REGION: 34495b482a8SLen Brown 34595b482a8SLen Brown info->op_region_init++; 34695b482a8SLen Brown status = acpi_ds_get_region_arguments(obj_desc); 34795b482a8SLen Brown break; 34895b482a8SLen Brown 34995b482a8SLen Brown case ACPI_TYPE_BUFFER_FIELD: 35095b482a8SLen Brown 35195b482a8SLen Brown info->field_init++; 35295b482a8SLen Brown status = acpi_ds_get_buffer_field_arguments(obj_desc); 35395b482a8SLen Brown break; 35495b482a8SLen Brown 35595b482a8SLen Brown case ACPI_TYPE_LOCAL_BANK_FIELD: 35695b482a8SLen Brown 35795b482a8SLen Brown info->field_init++; 35895b482a8SLen Brown status = acpi_ds_get_bank_field_arguments(obj_desc); 35995b482a8SLen Brown break; 36095b482a8SLen Brown 36195b482a8SLen Brown case ACPI_TYPE_BUFFER: 36295b482a8SLen Brown 36395b482a8SLen Brown info->buffer_init++; 36495b482a8SLen Brown status = acpi_ds_get_buffer_arguments(obj_desc); 36595b482a8SLen Brown break; 36695b482a8SLen Brown 36795b482a8SLen Brown case ACPI_TYPE_PACKAGE: 36895b482a8SLen Brown 36995b482a8SLen Brown info->package_init++; 37095b482a8SLen Brown status = acpi_ds_get_package_arguments(obj_desc); 37195b482a8SLen Brown break; 37295b482a8SLen Brown 37395b482a8SLen Brown default: 3741d1ea1b7SChao Guan 37595b482a8SLen Brown /* No other types can get here */ 3761d1ea1b7SChao Guan 37795b482a8SLen Brown break; 37895b482a8SLen Brown } 37995b482a8SLen Brown 38095b482a8SLen Brown if (ACPI_FAILURE(status)) { 38195b482a8SLen Brown ACPI_EXCEPTION((AE_INFO, status, 38295b482a8SLen Brown "Could not execute arguments for [%4.4s] (%s)", 38395b482a8SLen Brown acpi_ut_get_node_name(node), 38495b482a8SLen Brown acpi_ut_get_type_name(type))); 38595b482a8SLen Brown } 38695b482a8SLen Brown 38795b482a8SLen Brown /* 38895b482a8SLen Brown * We ignore errors from above, and always return OK, since we don't want 38995b482a8SLen Brown * to abort the walk on any single error. 39095b482a8SLen Brown */ 39195b482a8SLen Brown acpi_ex_exit_interpreter(); 39295b482a8SLen Brown return (AE_OK); 39395b482a8SLen Brown } 39495b482a8SLen Brown 39595b482a8SLen Brown /******************************************************************************* 39695b482a8SLen Brown * 39795b482a8SLen Brown * FUNCTION: acpi_ns_find_ini_methods 39895b482a8SLen Brown * 39995b482a8SLen Brown * PARAMETERS: acpi_walk_callback 40095b482a8SLen Brown * 40195b482a8SLen Brown * RETURN: acpi_status 40295b482a8SLen Brown * 40395b482a8SLen Brown * DESCRIPTION: Called during namespace walk. Finds objects named _INI under 40495b482a8SLen Brown * device/processor/thermal objects, and marks the entire subtree 40595b482a8SLen Brown * with a SUBTREE_HAS_INI flag. This flag is used during the 40695b482a8SLen Brown * subsequent device initialization walk to avoid entire subtrees 40795b482a8SLen Brown * that do not contain an _INI. 40895b482a8SLen Brown * 40995b482a8SLen Brown ******************************************************************************/ 41095b482a8SLen Brown 41195b482a8SLen Brown static acpi_status 41295b482a8SLen Brown acpi_ns_find_ini_methods(acpi_handle obj_handle, 41395b482a8SLen Brown u32 nesting_level, void *context, void **return_value) 41495b482a8SLen Brown { 41595b482a8SLen Brown struct acpi_device_walk_info *info = 41695b482a8SLen Brown ACPI_CAST_PTR(struct acpi_device_walk_info, context); 41795b482a8SLen Brown struct acpi_namespace_node *node; 41895b482a8SLen Brown struct acpi_namespace_node *parent_node; 41995b482a8SLen Brown 42095b482a8SLen Brown /* Keep count of device/processor/thermal objects */ 42195b482a8SLen Brown 42295b482a8SLen Brown node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_handle); 42395b482a8SLen Brown if ((node->type == ACPI_TYPE_DEVICE) || 42495b482a8SLen Brown (node->type == ACPI_TYPE_PROCESSOR) || 42595b482a8SLen Brown (node->type == ACPI_TYPE_THERMAL)) { 42695b482a8SLen Brown info->device_count++; 42795b482a8SLen Brown return (AE_OK); 42895b482a8SLen Brown } 42995b482a8SLen Brown 43095b482a8SLen Brown /* We are only looking for methods named _INI */ 43195b482a8SLen Brown 43295b482a8SLen Brown if (!ACPI_COMPARE_NAME(node->name.ascii, METHOD_NAME__INI)) { 43395b482a8SLen Brown return (AE_OK); 43495b482a8SLen Brown } 43595b482a8SLen Brown 43695b482a8SLen Brown /* 43795b482a8SLen Brown * The only _INI methods that we care about are those that are 43895b482a8SLen Brown * present under Device, Processor, and Thermal objects. 43995b482a8SLen Brown */ 440c45b5c09SAlexey Starikovskiy parent_node = node->parent; 44195b482a8SLen Brown switch (parent_node->type) { 44295b482a8SLen Brown case ACPI_TYPE_DEVICE: 44395b482a8SLen Brown case ACPI_TYPE_PROCESSOR: 44495b482a8SLen Brown case ACPI_TYPE_THERMAL: 44595b482a8SLen Brown 44695b482a8SLen Brown /* Mark parent and bubble up the INI present flag to the root */ 44795b482a8SLen Brown 44895b482a8SLen Brown while (parent_node) { 44995b482a8SLen Brown parent_node->flags |= ANOBJ_SUBTREE_HAS_INI; 450c45b5c09SAlexey Starikovskiy parent_node = parent_node->parent; 45195b482a8SLen Brown } 45295b482a8SLen Brown break; 45395b482a8SLen Brown 45495b482a8SLen Brown default: 4551d1ea1b7SChao Guan 45695b482a8SLen Brown break; 45795b482a8SLen Brown } 45895b482a8SLen Brown 45995b482a8SLen Brown return (AE_OK); 46095b482a8SLen Brown } 46195b482a8SLen Brown 46295b482a8SLen Brown /******************************************************************************* 46395b482a8SLen Brown * 46495b482a8SLen Brown * FUNCTION: acpi_ns_init_one_device 46595b482a8SLen Brown * 46695b482a8SLen Brown * PARAMETERS: acpi_walk_callback 46795b482a8SLen Brown * 46895b482a8SLen Brown * RETURN: acpi_status 46995b482a8SLen Brown * 47095b482a8SLen Brown * DESCRIPTION: This is called once per device soon after ACPI is enabled 47195b482a8SLen Brown * to initialize each device. It determines if the device is 47295b482a8SLen Brown * present, and if so, calls _INI. 47395b482a8SLen Brown * 47495b482a8SLen Brown ******************************************************************************/ 47595b482a8SLen Brown 47695b482a8SLen Brown static acpi_status 47795b482a8SLen Brown acpi_ns_init_one_device(acpi_handle obj_handle, 47895b482a8SLen Brown u32 nesting_level, void *context, void **return_value) 47995b482a8SLen Brown { 48095b482a8SLen Brown struct acpi_device_walk_info *walk_info = 48195b482a8SLen Brown ACPI_CAST_PTR(struct acpi_device_walk_info, context); 48295b482a8SLen Brown struct acpi_evaluate_info *info = walk_info->evaluate_info; 48395b482a8SLen Brown u32 flags; 48495b482a8SLen Brown acpi_status status; 48595b482a8SLen Brown struct acpi_namespace_node *device_node; 48695b482a8SLen Brown 48795b482a8SLen Brown ACPI_FUNCTION_TRACE(ns_init_one_device); 48895b482a8SLen Brown 48995b482a8SLen Brown /* We are interested in Devices, Processors and thermal_zones only */ 49095b482a8SLen Brown 49195b482a8SLen Brown device_node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_handle); 49295b482a8SLen Brown if ((device_node->type != ACPI_TYPE_DEVICE) && 49395b482a8SLen Brown (device_node->type != ACPI_TYPE_PROCESSOR) && 49495b482a8SLen Brown (device_node->type != ACPI_TYPE_THERMAL)) { 49595b482a8SLen Brown return_ACPI_STATUS(AE_OK); 49695b482a8SLen Brown } 49795b482a8SLen Brown 49895b482a8SLen Brown /* 49995b482a8SLen Brown * Because of an earlier namespace analysis, all subtrees that contain an 50095b482a8SLen Brown * _INI method are tagged. 50195b482a8SLen Brown * 50295b482a8SLen Brown * If this device subtree does not contain any _INI methods, we 50395b482a8SLen Brown * can exit now and stop traversing this entire subtree. 50495b482a8SLen Brown */ 50595b482a8SLen Brown if (!(device_node->flags & ANOBJ_SUBTREE_HAS_INI)) { 50695b482a8SLen Brown return_ACPI_STATUS(AE_CTRL_DEPTH); 50795b482a8SLen Brown } 50895b482a8SLen Brown 50995b482a8SLen Brown /* 51095b482a8SLen Brown * Run _STA to determine if this device is present and functioning. We 51195b482a8SLen Brown * must know this information for two important reasons (from ACPI spec): 51295b482a8SLen Brown * 51395b482a8SLen Brown * 1) We can only run _INI if the device is present. 51495b482a8SLen Brown * 2) We must abort the device tree walk on this subtree if the device is 51595b482a8SLen Brown * not present and is not functional (we will not examine the children) 51695b482a8SLen Brown * 51795b482a8SLen Brown * The _STA method is not required to be present under the device, we 51895b482a8SLen Brown * assume the device is present if _STA does not exist. 51995b482a8SLen Brown */ 52095b482a8SLen Brown ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname 52195b482a8SLen Brown (ACPI_TYPE_METHOD, device_node, METHOD_NAME__STA)); 52295b482a8SLen Brown 52395b482a8SLen Brown status = acpi_ut_execute_STA(device_node, &flags); 52495b482a8SLen Brown if (ACPI_FAILURE(status)) { 52595b482a8SLen Brown 52695b482a8SLen Brown /* Ignore error and move on to next device */ 52795b482a8SLen Brown 52895b482a8SLen Brown return_ACPI_STATUS(AE_OK); 52995b482a8SLen Brown } 53095b482a8SLen Brown 53195b482a8SLen Brown /* 53295b482a8SLen Brown * Flags == -1 means that _STA was not found. In this case, we assume that 53395b482a8SLen Brown * the device is both present and functional. 53495b482a8SLen Brown * 53595b482a8SLen Brown * From the ACPI spec, description of _STA: 53695b482a8SLen Brown * 53795b482a8SLen Brown * "If a device object (including the processor object) does not have an 53895b482a8SLen Brown * _STA object, then OSPM assumes that all of the above bits are set (in 53995b482a8SLen Brown * other words, the device is present, ..., and functioning)" 54095b482a8SLen Brown */ 54195b482a8SLen Brown if (flags != ACPI_UINT32_MAX) { 54295b482a8SLen Brown walk_info->num_STA++; 54395b482a8SLen Brown } 54495b482a8SLen Brown 54595b482a8SLen Brown /* 54695b482a8SLen Brown * Examine the PRESENT and FUNCTIONING status bits 54795b482a8SLen Brown * 54895b482a8SLen Brown * Note: ACPI spec does not seem to specify behavior for the present but 54995b482a8SLen Brown * not functioning case, so we assume functioning if present. 55095b482a8SLen Brown */ 55195b482a8SLen Brown if (!(flags & ACPI_STA_DEVICE_PRESENT)) { 55295b482a8SLen Brown 55395b482a8SLen Brown /* Device is not present, we must examine the Functioning bit */ 55495b482a8SLen Brown 55595b482a8SLen Brown if (flags & ACPI_STA_DEVICE_FUNCTIONING) { 55695b482a8SLen Brown /* 55795b482a8SLen Brown * Device is not present but is "functioning". In this case, 55895b482a8SLen Brown * we will not run _INI, but we continue to examine the children 55995b482a8SLen Brown * of this device. 56095b482a8SLen Brown * 561ba494beeSBob Moore * From the ACPI spec, description of _STA: (note - no mention 56295b482a8SLen Brown * of whether to run _INI or not on the device in question) 56395b482a8SLen Brown * 56495b482a8SLen Brown * "_STA may return bit 0 clear (not present) with bit 3 set 56595b482a8SLen Brown * (device is functional). This case is used to indicate a valid 56695b482a8SLen Brown * device for which no device driver should be loaded (for example, 56795b482a8SLen Brown * a bridge device.) Children of this device may be present and 56895b482a8SLen Brown * valid. OSPM should continue enumeration below a device whose 56995b482a8SLen Brown * _STA returns this bit combination" 57095b482a8SLen Brown */ 57195b482a8SLen Brown return_ACPI_STATUS(AE_OK); 57295b482a8SLen Brown } else { 57395b482a8SLen Brown /* 57495b482a8SLen Brown * Device is not present and is not functioning. We must abort the 57595b482a8SLen Brown * walk of this subtree immediately -- don't look at the children 57695b482a8SLen Brown * of such a device. 57795b482a8SLen Brown * 57895b482a8SLen Brown * From the ACPI spec, description of _INI: 57995b482a8SLen Brown * 58095b482a8SLen Brown * "If the _STA method indicates that the device is not present, 58195b482a8SLen Brown * OSPM will not run the _INI and will not examine the children 58295b482a8SLen Brown * of the device for _INI methods" 58395b482a8SLen Brown */ 58495b482a8SLen Brown return_ACPI_STATUS(AE_CTRL_DEPTH); 58595b482a8SLen Brown } 58695b482a8SLen Brown } 58795b482a8SLen Brown 58895b482a8SLen Brown /* 58995b482a8SLen Brown * The device is present or is assumed present if no _STA exists. 59095b482a8SLen Brown * Run the _INI if it exists (not required to exist) 59195b482a8SLen Brown * 59295b482a8SLen Brown * Note: We know there is an _INI within this subtree, but it may not be 59395b482a8SLen Brown * under this particular device, it may be lower in the branch. 59495b482a8SLen Brown */ 59595b482a8SLen Brown ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname 59695b482a8SLen Brown (ACPI_TYPE_METHOD, device_node, METHOD_NAME__INI)); 59795b482a8SLen Brown 5984fa4616eSBob Moore memset(info, 0, sizeof(struct acpi_evaluate_info)); 59995b482a8SLen Brown info->prefix_node = device_node; 60029a241ccSBob Moore info->relative_pathname = METHOD_NAME__INI; 60195b482a8SLen Brown info->parameters = NULL; 60295b482a8SLen Brown info->flags = ACPI_IGNORE_RETURN_VALUE; 60395b482a8SLen Brown 60495b482a8SLen Brown status = acpi_ns_evaluate(info); 60595b482a8SLen Brown 60695b482a8SLen Brown if (ACPI_SUCCESS(status)) { 60795b482a8SLen Brown walk_info->num_INI++; 60895b482a8SLen Brown } 60995b482a8SLen Brown #ifdef ACPI_DEBUG_OUTPUT 61095b482a8SLen Brown else if (status != AE_NOT_FOUND) { 61195b482a8SLen Brown 61295b482a8SLen Brown /* Ignore error and move on to next device */ 61395b482a8SLen Brown 6140e166e4fSLv Zheng char *scope_name = 6150e166e4fSLv Zheng acpi_ns_get_normalized_pathname(device_node, TRUE); 61695b482a8SLen Brown 61795b482a8SLen Brown ACPI_EXCEPTION((AE_INFO, status, "during %s._INI execution", 61895b482a8SLen Brown scope_name)); 61995b482a8SLen Brown ACPI_FREE(scope_name); 62095b482a8SLen Brown } 62195b482a8SLen Brown #endif 62295b482a8SLen Brown 62395b482a8SLen Brown /* Ignore errors from above */ 62495b482a8SLen Brown 62595b482a8SLen Brown status = AE_OK; 62695b482a8SLen Brown 62795b482a8SLen Brown /* 62895b482a8SLen Brown * The _INI method has been run if present; call the Global Initialization 62995b482a8SLen Brown * Handler for this device. 63095b482a8SLen Brown */ 63195b482a8SLen Brown if (acpi_gbl_init_handler) { 63295b482a8SLen Brown status = 63395b482a8SLen Brown acpi_gbl_init_handler(device_node, ACPI_INIT_DEVICE_INI); 63495b482a8SLen Brown } 63595b482a8SLen Brown 63695b482a8SLen Brown return_ACPI_STATUS(status); 63795b482a8SLen Brown } 638