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 | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame] | 8 | * Copyright (C) 2000 - 2006, R. Byron Moore |
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> |
| 45 | #include <acpi/acnamesp.h> |
| 46 | #include <acpi/acdispat.h> |
| 47 | #include <acpi/acinterp.h> |
| 48 | |
| 49 | #define _COMPONENT ACPI_NAMESPACE |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 50 | ACPI_MODULE_NAME("nsinit") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 52 | /* Local prototypes */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 53 | static acpi_status |
| 54 | acpi_ns_init_one_object(acpi_handle obj_handle, |
| 55 | u32 level, void *context, void **return_value); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 56 | |
| 57 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 58 | acpi_ns_init_one_device(acpi_handle obj_handle, |
| 59 | u32 nesting_level, void *context, void **return_value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
| 61 | /******************************************************************************* |
| 62 | * |
| 63 | * FUNCTION: acpi_ns_initialize_objects |
| 64 | * |
| 65 | * PARAMETERS: None |
| 66 | * |
| 67 | * RETURN: Status |
| 68 | * |
| 69 | * DESCRIPTION: Walk the entire namespace and perform any necessary |
| 70 | * initialization on the objects found therein |
| 71 | * |
| 72 | ******************************************************************************/ |
| 73 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 74 | acpi_status acpi_ns_initialize_objects(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 76 | acpi_status status; |
| 77 | struct acpi_init_walk_info info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 79 | ACPI_FUNCTION_TRACE("ns_initialize_objects"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 81 | ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, |
| 82 | "**** Starting initialization of namespace objects ****\n")); |
| 83 | ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, |
| 84 | "Completing Region/Field/Buffer/Package initialization:")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | |
| 86 | /* Set all init info to zero */ |
| 87 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 88 | ACPI_MEMSET(&info, 0, sizeof(struct acpi_init_walk_info)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
| 90 | /* Walk entire namespace from the supplied root */ |
| 91 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 92 | status = acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, |
| 93 | ACPI_UINT32_MAX, acpi_ns_init_one_object, |
| 94 | &info, NULL); |
| 95 | if (ACPI_FAILURE(status)) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 96 | ACPI_EXCEPTION((AE_INFO, status, "During walk_namespace")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | } |
| 98 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 99 | ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, |
| 100 | "\nInitialized %hd/%hd Regions %hd/%hd Fields %hd/%hd Buffers %hd/%hd Packages (%hd nodes)\n", |
| 101 | info.op_region_init, info.op_region_count, |
| 102 | info.field_init, info.field_count, |
| 103 | info.buffer_init, info.buffer_count, |
| 104 | info.package_init, info.package_count, |
| 105 | info.object_count)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 107 | ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, |
| 108 | "%hd Control Methods found\n", info.method_count)); |
| 109 | ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, |
| 110 | "%hd Op Regions found\n", info.op_region_count)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 112 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | /******************************************************************************* |
| 116 | * |
| 117 | * FUNCTION: acpi_ns_initialize_devices |
| 118 | * |
| 119 | * PARAMETERS: None |
| 120 | * |
| 121 | * RETURN: acpi_status |
| 122 | * |
| 123 | * DESCRIPTION: Walk the entire namespace and initialize all ACPI devices. |
| 124 | * This means running _INI on all present devices. |
| 125 | * |
| 126 | * Note: We install PCI config space handler on region access, |
| 127 | * not here. |
| 128 | * |
| 129 | ******************************************************************************/ |
| 130 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 131 | acpi_status acpi_ns_initialize_devices(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 133 | acpi_status status; |
| 134 | struct acpi_device_walk_info info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 136 | ACPI_FUNCTION_TRACE("ns_initialize_devices"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
| 138 | /* Init counters */ |
| 139 | |
| 140 | info.device_count = 0; |
| 141 | info.num_STA = 0; |
| 142 | info.num_INI = 0; |
| 143 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 144 | ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, |
| 145 | "Executing all Device _STA and_INI methods:")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 147 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
| 148 | if (ACPI_FAILURE(status)) { |
| 149 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | /* Walk namespace for all objects */ |
| 153 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 154 | status = acpi_ns_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, |
| 155 | ACPI_UINT32_MAX, TRUE, |
| 156 | acpi_ns_init_one_device, &info, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 158 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 160 | if (ACPI_FAILURE(status)) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 161 | ACPI_EXCEPTION((AE_INFO, status, "During walk_namespace")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 164 | ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 165 | "\n%hd Devices found - executed %hd _STA, %hd _INI methods\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 166 | info.device_count, info.num_STA, info.num_INI)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 168 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | /******************************************************************************* |
| 172 | * |
| 173 | * FUNCTION: acpi_ns_init_one_object |
| 174 | * |
| 175 | * PARAMETERS: obj_handle - Node |
| 176 | * Level - Current nesting level |
| 177 | * Context - Points to a init info struct |
| 178 | * return_value - Not used |
| 179 | * |
| 180 | * RETURN: Status |
| 181 | * |
| 182 | * DESCRIPTION: Callback from acpi_walk_namespace. Invoked for every object |
| 183 | * within the namespace. |
| 184 | * |
| 185 | * Currently, the only objects that require initialization are: |
| 186 | * 1) Methods |
| 187 | * 2) Op Regions |
| 188 | * |
| 189 | ******************************************************************************/ |
| 190 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 191 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 192 | acpi_ns_init_one_object(acpi_handle obj_handle, |
| 193 | u32 level, void *context, void **return_value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 195 | acpi_object_type type; |
| 196 | acpi_status status; |
| 197 | struct acpi_init_walk_info *info = |
| 198 | (struct acpi_init_walk_info *)context; |
| 199 | struct acpi_namespace_node *node = |
| 200 | (struct acpi_namespace_node *)obj_handle; |
| 201 | union acpi_operand_object *obj_desc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 203 | ACPI_FUNCTION_NAME("ns_init_one_object"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | |
| 205 | info->object_count++; |
| 206 | |
| 207 | /* And even then, we are only interested in a few object types */ |
| 208 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 209 | type = acpi_ns_get_type(obj_handle); |
| 210 | obj_desc = acpi_ns_get_attached_object(node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | if (!obj_desc) { |
| 212 | return (AE_OK); |
| 213 | } |
| 214 | |
| 215 | /* Increment counters for object types we are looking for */ |
| 216 | |
| 217 | switch (type) { |
| 218 | case ACPI_TYPE_REGION: |
| 219 | info->op_region_count++; |
| 220 | break; |
| 221 | |
| 222 | case ACPI_TYPE_BUFFER_FIELD: |
| 223 | info->field_count++; |
| 224 | break; |
| 225 | |
| 226 | case ACPI_TYPE_BUFFER: |
| 227 | info->buffer_count++; |
| 228 | break; |
| 229 | |
| 230 | case ACPI_TYPE_PACKAGE: |
| 231 | info->package_count++; |
| 232 | break; |
| 233 | |
| 234 | default: |
| 235 | |
| 236 | /* No init required, just exit now */ |
| 237 | return (AE_OK); |
| 238 | } |
| 239 | |
| 240 | /* |
| 241 | * If the object is already initialized, nothing else to do |
| 242 | */ |
| 243 | if (obj_desc->common.flags & AOPOBJ_DATA_VALID) { |
| 244 | return (AE_OK); |
| 245 | } |
| 246 | |
| 247 | /* |
| 248 | * Must lock the interpreter before executing AML code |
| 249 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 250 | status = acpi_ex_enter_interpreter(); |
| 251 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | return (status); |
| 253 | } |
| 254 | |
| 255 | /* |
| 256 | * Each of these types can contain executable AML code within the |
| 257 | * declaration. |
| 258 | */ |
| 259 | switch (type) { |
| 260 | case ACPI_TYPE_REGION: |
| 261 | |
| 262 | info->op_region_init++; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 263 | status = acpi_ds_get_region_arguments(obj_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | break; |
| 265 | |
| 266 | case ACPI_TYPE_BUFFER_FIELD: |
| 267 | |
| 268 | info->field_init++; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 269 | status = acpi_ds_get_buffer_field_arguments(obj_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | break; |
| 271 | |
| 272 | case ACPI_TYPE_BUFFER: |
| 273 | |
| 274 | info->buffer_init++; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 275 | status = acpi_ds_get_buffer_arguments(obj_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | break; |
| 277 | |
| 278 | case ACPI_TYPE_PACKAGE: |
| 279 | |
| 280 | info->package_init++; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 281 | status = acpi_ds_get_package_arguments(obj_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | break; |
| 283 | |
| 284 | default: |
| 285 | /* No other types can get here */ |
| 286 | break; |
| 287 | } |
| 288 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 289 | if (ACPI_FAILURE(status)) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 290 | ACPI_EXCEPTION((AE_INFO, status, |
| 291 | "Could not execute arguments for [%4.4s] (%s)", |
| 292 | acpi_ut_get_node_name(node), |
| 293 | acpi_ut_get_type_name(type))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | /* |
| 297 | * Print a dot for each object unless we are going to print the entire |
| 298 | * pathname |
| 299 | */ |
| 300 | if (!(acpi_dbg_level & ACPI_LV_INIT_NAMES)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 301 | ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, ".")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | /* |
| 305 | * We ignore errors from above, and always return OK, since we don't want |
| 306 | * to abort the walk on any single error. |
| 307 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 308 | acpi_ex_exit_interpreter(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | return (AE_OK); |
| 310 | } |
| 311 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | /******************************************************************************* |
| 313 | * |
| 314 | * FUNCTION: acpi_ns_init_one_device |
| 315 | * |
| 316 | * PARAMETERS: acpi_walk_callback |
| 317 | * |
| 318 | * RETURN: acpi_status |
| 319 | * |
| 320 | * DESCRIPTION: This is called once per device soon after ACPI is enabled |
| 321 | * to initialize each device. It determines if the device is |
| 322 | * present, and if so, calls _INI. |
| 323 | * |
| 324 | ******************************************************************************/ |
| 325 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 326 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 327 | acpi_ns_init_one_device(acpi_handle obj_handle, |
| 328 | u32 nesting_level, void *context, void **return_value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 330 | struct acpi_device_walk_info *info = |
| 331 | (struct acpi_device_walk_info *)context; |
| 332 | struct acpi_parameter_info pinfo; |
| 333 | u32 flags; |
| 334 | acpi_status status; |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 335 | struct acpi_namespace_node *ini_node; |
| 336 | struct acpi_namespace_node *device_node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 338 | ACPI_FUNCTION_TRACE("ns_init_one_device"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 340 | device_node = acpi_ns_map_handle_to_node(obj_handle); |
| 341 | if (!device_node) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 342 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | /* |
| 346 | * We will run _STA/_INI on Devices, Processors and thermal_zones only |
| 347 | */ |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 348 | if ((device_node->type != ACPI_TYPE_DEVICE) && |
| 349 | (device_node->type != ACPI_TYPE_PROCESSOR) && |
| 350 | (device_node->type != ACPI_TYPE_THERMAL)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 351 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | if ((acpi_dbg_level <= ACPI_LV_ALL_EXCEPTIONS) && |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 355 | (!(acpi_dbg_level & ACPI_LV_INFO))) { |
| 356 | ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, ".")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | info->device_count++; |
| 360 | |
| 361 | /* |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 362 | * Check if the _INI method exists for this device - |
| 363 | * if _INI does not exist, there is no need to run _STA |
| 364 | * No _INI means device requires no initialization |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | */ |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 366 | status = acpi_ns_search_node(*ACPI_CAST_PTR(u32, METHOD_NAME__INI), |
| 367 | device_node, ACPI_TYPE_METHOD, &ini_node); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 368 | if (ACPI_FAILURE(status)) { |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 369 | /* No _INI method found - move on to next device */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 371 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | /* |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 375 | * Run _STA to determine if we can run _INI on the device - |
| 376 | * the device must be present before _INI can be run. |
| 377 | * However, _STA is not required - assume device present if no _STA |
| 378 | */ |
| 379 | ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname(ACPI_TYPE_METHOD, |
| 380 | device_node, |
| 381 | METHOD_NAME__STA)); |
| 382 | |
| 383 | pinfo.node = device_node; |
| 384 | pinfo.parameters = NULL; |
| 385 | pinfo.parameter_type = ACPI_PARAM_ARGS; |
| 386 | |
| 387 | status = acpi_ut_execute_STA(pinfo.node, &flags); |
| 388 | if (ACPI_FAILURE(status)) { |
| 389 | /* Ignore error and move on to next device */ |
| 390 | |
| 391 | return_ACPI_STATUS(AE_OK); |
| 392 | } |
| 393 | |
| 394 | if (flags != ACPI_UINT32_MAX) { |
| 395 | info->num_STA++; |
| 396 | } |
| 397 | |
| 398 | if (!(flags & ACPI_STA_DEVICE_PRESENT)) { |
| 399 | /* Don't look at children of a not present device */ |
| 400 | |
| 401 | return_ACPI_STATUS(AE_CTRL_DEPTH); |
| 402 | } |
| 403 | |
| 404 | /* |
| 405 | * The device is present and _INI exists. Run the _INI method. |
| 406 | * (We already have the _INI node from above) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 408 | ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname(ACPI_TYPE_METHOD, |
| 409 | pinfo.node, |
| 410 | METHOD_NAME__INI)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 412 | pinfo.node = ini_node; |
| 413 | status = acpi_ns_evaluate_by_handle(&pinfo); |
| 414 | if (ACPI_FAILURE(status)) { |
| 415 | /* Ignore error and move on to next device */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | |
| 417 | #ifdef ACPI_DEBUG_OUTPUT |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 418 | char *scope_name = acpi_ns_get_external_pathname(ini_node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 420 | ACPI_WARNING((AE_INFO, "%s._INI failed: %s", |
| 421 | scope_name, acpi_format_exception(status))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 423 | ACPI_MEM_FREE(scope_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | #endif |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 425 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | /* Delete any return object (especially if implicit_return is enabled) */ |
| 427 | |
| 428 | if (pinfo.return_object) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 429 | acpi_ut_remove_reference(pinfo.return_object); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | /* Count of successful INIs */ |
| 433 | |
| 434 | info->num_INI++; |
| 435 | } |
| 436 | |
| 437 | if (acpi_gbl_init_handler) { |
| 438 | /* External initialization handler is present, call it */ |
| 439 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 440 | status = |
| 441 | acpi_gbl_init_handler(pinfo.node, ACPI_INIT_DEVICE_INI); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | } |
| 443 | |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 444 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | } |