Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Module Name: nsinit - namespace initialization |
| 4 | * |
| 5 | *****************************************************************************/ |
| 6 | |
| 7 | /* |
Bob Moore | c8100dc | 2016-01-15 08:17:03 +0800 | [diff] [blame] | 8 | * Copyright (C) 2000 - 2016, Intel Corp. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #include <acpi/acpi.h> |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 45 | #include "accommon.h" |
| 46 | #include "acnamesp.h" |
| 47 | #include "acdispat.h" |
| 48 | #include "acinterp.h" |
Lv Zheng | ced0436 | 2016-02-19 14:17:15 +0800 | [diff] [blame] | 49 | #include "acevents.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
| 51 | #define _COMPONENT ACPI_NAMESPACE |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 52 | ACPI_MODULE_NAME("nsinit") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 54 | /* Local prototypes */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 55 | static acpi_status |
| 56 | acpi_ns_init_one_object(acpi_handle obj_handle, |
| 57 | u32 level, void *context, void **return_value); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 58 | |
| 59 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 60 | acpi_ns_init_one_device(acpi_handle obj_handle, |
| 61 | u32 nesting_level, void *context, void **return_value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 63 | static acpi_status |
| 64 | acpi_ns_find_ini_methods(acpi_handle obj_handle, |
| 65 | u32 nesting_level, void *context, void **return_value); |
| 66 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | /******************************************************************************* |
| 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 Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 80 | acpi_status acpi_ns_initialize_objects(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 82 | acpi_status status; |
| 83 | struct acpi_init_walk_info info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 85 | ACPI_FUNCTION_TRACE(ns_initialize_objects); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 87 | ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, |
| 88 | "**** Starting initialization of namespace objects ****\n")); |
| 89 | ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, |
Bob Moore | 2fae3e5 | 2012-12-31 00:07:08 +0000 | [diff] [blame] | 90 | "Completing Region/Field/Buffer/Package initialization:\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
| 92 | /* Set all init info to zero */ |
| 93 | |
Bob Moore | 4fa4616 | 2015-07-01 14:45:11 +0800 | [diff] [blame] | 94 | memset(&info, 0, sizeof(struct acpi_init_walk_info)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
| 96 | /* Walk entire namespace from the supplied root */ |
| 97 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 98 | status = acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, |
Lv Zheng | 1f86e8c | 2012-10-31 02:25:45 +0000 | [diff] [blame] | 99 | ACPI_UINT32_MAX, acpi_ns_init_one_object, |
| 100 | NULL, &info, NULL); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 101 | if (ACPI_FAILURE(status)) { |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 102 | ACPI_EXCEPTION((AE_INFO, status, "During WalkNamespace")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | } |
| 104 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 105 | ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, |
Bob Moore | 3e5621a | 2012-12-31 00:07:13 +0000 | [diff] [blame] | 106 | " Initialized %u/%u Regions %u/%u Fields %u/%u " |
Alexey Starikovskiy | 96b7b7a | 2010-05-26 11:20:47 +0800 | [diff] [blame] | 107 | "Buffers %u/%u Packages (%u nodes)\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 108 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 114 | ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, |
Bob Moore | 22b5afc | 2014-03-24 14:49:00 +0800 | [diff] [blame] | 115 | "%u Control Methods found\n%u Op Regions found\n", |
| 116 | info.method_count, info.op_region_count)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 118 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | /******************************************************************************* |
| 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 Zheng | ced0436 | 2016-02-19 14:17:15 +0800 | [diff] [blame] | 137 | acpi_status acpi_ns_initialize_devices(u32 flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | { |
Lv Zheng | ebc3c9b | 2016-02-19 14:17:22 +0800 | [diff] [blame^] | 139 | acpi_status status = AE_OK; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 140 | struct acpi_device_walk_info info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 142 | ACPI_FUNCTION_TRACE(ns_initialize_devices); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | |
Lv Zheng | ced0436 | 2016-02-19 14:17:15 +0800 | [diff] [blame] | 144 | if (!(flags & ACPI_NO_DEVICE_INIT)) { |
| 145 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
| 146 | "[Init] Initializing ACPI Devices\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
Lv Zheng | ced0436 | 2016-02-19 14:17:15 +0800 | [diff] [blame] | 148 | /* Init counters */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | |
Lv Zheng | ced0436 | 2016-02-19 14:17:15 +0800 | [diff] [blame] | 150 | info.device_count = 0; |
| 151 | info.num_STA = 0; |
| 152 | info.num_INI = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | |
Lv Zheng | ced0436 | 2016-02-19 14:17:15 +0800 | [diff] [blame] | 154 | ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, |
| 155 | "Initializing Device/Processor/Thermal objects " |
| 156 | "and executing _INI/_STA methods:\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | |
Lv Zheng | ced0436 | 2016-02-19 14:17:15 +0800 | [diff] [blame] | 158 | /* Tree analysis: find all subtrees that contain _INI methods */ |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 159 | |
Lv Zheng | ced0436 | 2016-02-19 14:17:15 +0800 | [diff] [blame] | 160 | 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 Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 167 | |
Lv Zheng | ced0436 | 2016-02-19 14:17:15 +0800 | [diff] [blame] | 168 | /* 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 Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 191 | } |
| 192 | |
Bob Moore | 9e64155 | 2009-09-03 10:21:03 +0800 | [diff] [blame] | 193 | /* |
Lv Zheng | ced0436 | 2016-02-19 14:17:15 +0800 | [diff] [blame] | 194 | * 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 Moore | 9e64155 | 2009-09-03 10:21:03 +0800 | [diff] [blame] | 199 | */ |
Lv Zheng | ced0436 | 2016-02-19 14:17:15 +0800 | [diff] [blame] | 200 | if (!(flags & ACPI_NO_ADDRESS_SPACE_INIT)) { |
| 201 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
| 202 | "[Init] Executing _REG OpRegion methods\n")); |
Bob Moore | 9e64155 | 2009-09-03 10:21:03 +0800 | [diff] [blame] | 203 | |
Lv Zheng | ced0436 | 2016-02-19 14:17:15 +0800 | [diff] [blame] | 204 | status = acpi_ev_initialize_op_regions(); |
| 205 | if (ACPI_FAILURE(status)) { |
| 206 | goto error_exit; |
| 207 | } |
Bob Moore | 9e64155 | 2009-09-03 10:21:03 +0800 | [diff] [blame] | 208 | } |
| 209 | |
Lv Zheng | ced0436 | 2016-02-19 14:17:15 +0800 | [diff] [blame] | 210 | if (!(flags & ACPI_NO_DEVICE_INIT)) { |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 211 | |
Lv Zheng | ced0436 | 2016-02-19 14:17:15 +0800 | [diff] [blame] | 212 | /* Walk namespace to execute all _INIs on present devices */ |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 213 | |
Lv Zheng | ced0436 | 2016-02-19 14:17:15 +0800 | [diff] [blame] | 214 | 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 Garrett | b681f7d | 2010-05-26 11:50:48 +0800 | [diff] [blame] | 238 | } |
| 239 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 240 | return_ACPI_STATUS(status); |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 241 | |
Lv Zheng | 10622bf | 2013-10-29 09:30:02 +0800 | [diff] [blame] | 242 | error_exit: |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 243 | ACPI_EXCEPTION((AE_INFO, status, "During device initialization")); |
| 244 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | } |
| 246 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | /******************************************************************************* |
| 248 | * |
| 249 | * FUNCTION: acpi_ns_init_one_object |
| 250 | * |
| 251 | * PARAMETERS: obj_handle - Node |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 252 | * level - Current nesting level |
| 253 | * context - Points to a init info struct |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | * 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 Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 267 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 268 | acpi_ns_init_one_object(acpi_handle obj_handle, |
| 269 | u32 level, void *context, void **return_value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 271 | acpi_object_type type; |
Len Brown | 4d2acd9 | 2007-05-09 22:56:38 -0400 | [diff] [blame] | 272 | acpi_status status = AE_OK; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 273 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 279 | ACPI_FUNCTION_NAME(ns_init_one_object); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | |
| 281 | info->object_count++; |
| 282 | |
| 283 | /* And even then, we are only interested in a few object types */ |
| 284 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 285 | type = acpi_ns_get_type(obj_handle); |
| 286 | obj_desc = acpi_ns_get_attached_object(node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | 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 Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 295 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | info->op_region_count++; |
| 297 | break; |
| 298 | |
| 299 | case ACPI_TYPE_BUFFER_FIELD: |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 300 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | info->field_count++; |
| 302 | break; |
| 303 | |
Lin Ming | ef805d9 | 2008-04-10 19:06:41 +0400 | [diff] [blame] | 304 | case ACPI_TYPE_LOCAL_BANK_FIELD: |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 305 | |
Lin Ming | ef805d9 | 2008-04-10 19:06:41 +0400 | [diff] [blame] | 306 | info->field_count++; |
| 307 | break; |
| 308 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | case ACPI_TYPE_BUFFER: |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 310 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | info->buffer_count++; |
| 312 | break; |
| 313 | |
| 314 | case ACPI_TYPE_PACKAGE: |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 315 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | info->package_count++; |
| 317 | break; |
| 318 | |
| 319 | default: |
| 320 | |
| 321 | /* No init required, just exit now */ |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 322 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | return (AE_OK); |
| 324 | } |
| 325 | |
Bob Moore | d4913dc | 2009-03-06 10:05:18 +0800 | [diff] [blame] | 326 | /* If the object is already initialized, nothing else to do */ |
| 327 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | if (obj_desc->common.flags & AOPOBJ_DATA_VALID) { |
| 329 | return (AE_OK); |
| 330 | } |
| 331 | |
Bob Moore | d4913dc | 2009-03-06 10:05:18 +0800 | [diff] [blame] | 332 | /* Must lock the interpreter before executing AML code */ |
| 333 | |
Len Brown | 4d2acd9 | 2007-05-09 22:56:38 -0400 | [diff] [blame] | 334 | acpi_ex_enter_interpreter(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | |
| 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 Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 344 | status = acpi_ds_get_region_arguments(obj_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | break; |
| 346 | |
| 347 | case ACPI_TYPE_BUFFER_FIELD: |
| 348 | |
| 349 | info->field_init++; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 350 | status = acpi_ds_get_buffer_field_arguments(obj_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | break; |
| 352 | |
Lin Ming | ef805d9 | 2008-04-10 19:06:41 +0400 | [diff] [blame] | 353 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | case ACPI_TYPE_BUFFER: |
| 360 | |
| 361 | info->buffer_init++; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 362 | status = acpi_ds_get_buffer_arguments(obj_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | break; |
| 364 | |
| 365 | case ACPI_TYPE_PACKAGE: |
| 366 | |
| 367 | info->package_init++; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 368 | status = acpi_ds_get_package_arguments(obj_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | break; |
| 370 | |
| 371 | default: |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 372 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | /* No other types can get here */ |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 374 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | break; |
| 376 | } |
| 377 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 378 | if (ACPI_FAILURE(status)) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 379 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | * 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 Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 389 | acpi_ex_exit_interpreter(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | return (AE_OK); |
| 391 | } |
| 392 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | /******************************************************************************* |
| 394 | * |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 395 | * 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 | |
| 409 | static acpi_status |
| 410 | acpi_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 Starikovskiy | c45b5c0 | 2010-05-26 11:53:07 +0800 | [diff] [blame] | 438 | parent_node = node->parent; |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 439 | 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 Starikovskiy | c45b5c0 | 2010-05-26 11:53:07 +0800 | [diff] [blame] | 448 | parent_node = parent_node->parent; |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 449 | } |
| 450 | break; |
| 451 | |
| 452 | default: |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 453 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 454 | break; |
| 455 | } |
| 456 | |
| 457 | return (AE_OK); |
| 458 | } |
| 459 | |
| 460 | /******************************************************************************* |
| 461 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | * 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 Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 474 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 475 | acpi_ns_init_one_device(acpi_handle obj_handle, |
| 476 | u32 nesting_level, void *context, void **return_value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | { |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 478 | struct acpi_device_walk_info *walk_info = |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 479 | ACPI_CAST_PTR(struct acpi_device_walk_info, context); |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 480 | struct acpi_evaluate_info *info = walk_info->evaluate_info; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 481 | u32 flags; |
| 482 | acpi_status status; |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 483 | struct acpi_namespace_node *device_node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 485 | ACPI_FUNCTION_TRACE(ns_init_one_device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 487 | /* We are interested in Devices, Processors and thermal_zones only */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 489 | device_node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_handle); |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 490 | if ((device_node->type != ACPI_TYPE_DEVICE) && |
| 491 | (device_node->type != ACPI_TYPE_PROCESSOR) && |
| 492 | (device_node->type != ACPI_TYPE_THERMAL)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 493 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | } |
| 495 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 496 | /* |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | } |
| 506 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | /* |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 508 | * 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | */ |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 518 | 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 Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 522 | if (ACPI_FAILURE(status)) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 523 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 524 | /* Ignore error and move on to next device */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 526 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | /* |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 530 | * 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 Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 538 | */ |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 539 | if (flags != ACPI_UINT32_MAX) { |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 540 | walk_info->num_STA++; |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 541 | } |
| 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 Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 559 | * From the ACPI spec, description of _STA: (note - no mention |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 560 | * 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 Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 595 | |
Bob Moore | 4fa4616 | 2015-07-01 14:45:11 +0800 | [diff] [blame] | 596 | memset(info, 0, sizeof(struct acpi_evaluate_info)); |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 597 | info->prefix_node = device_node; |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame] | 598 | info->relative_pathname = METHOD_NAME__INI; |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 599 | info->parameters = NULL; |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 600 | info->flags = ACPI_IGNORE_RETURN_VALUE; |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 601 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 602 | status = acpi_ns_evaluate(info); |
Ingo Molnar | 5d0e600 | 2007-02-13 13:26:24 +0100 | [diff] [blame] | 603 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 604 | if (ACPI_SUCCESS(status)) { |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 605 | walk_info->num_INI++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | } |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 607 | #ifdef ACPI_DEBUG_OUTPUT |
| 608 | else if (status != AE_NOT_FOUND) { |
| 609 | |
| 610 | /* Ignore error and move on to next device */ |
| 611 | |
Lv Zheng | 0e166e4 | 2015-12-29 13:53:50 +0800 | [diff] [blame] | 612 | char *scope_name = |
| 613 | acpi_ns_get_normalized_pathname(device_node, TRUE); |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 614 | |
| 615 | ACPI_EXCEPTION((AE_INFO, status, "during %s._INI execution", |
| 616 | scope_name)); |
| 617 | ACPI_FREE(scope_name); |
| 618 | } |
| 619 | #endif |
| 620 | |
Bob Moore | 4c90ece | 2006-06-08 16:29:00 -0400 | [diff] [blame] | 621 | /* Ignore errors from above */ |
| 622 | |
| 623 | status = AE_OK; |
| 624 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 625 | /* |
| 626 | * The _INI method has been run if present; call the Global Initialization |
| 627 | * Handler for this device. |
| 628 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | if (acpi_gbl_init_handler) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 630 | status = |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 631 | acpi_gbl_init_handler(device_node, ACPI_INIT_DEVICE_INI); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | } |
| 633 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 634 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | } |