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