Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Module Name: dsinit - Object initialization namespace walk |
| 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 | |
| 44 | |
| 45 | #include <acpi/acpi.h> |
| 46 | #include <acpi/acdispat.h> |
| 47 | #include <acpi/acnamesp.h> |
| 48 | |
| 49 | #define _COMPONENT ACPI_DISPATCHER |
| 50 | ACPI_MODULE_NAME ("dsinit") |
| 51 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 52 | /* Local prototypes */ |
| 53 | |
| 54 | static acpi_status |
| 55 | acpi_ds_init_one_object ( |
| 56 | acpi_handle obj_handle, |
| 57 | u32 level, |
| 58 | void *context, |
| 59 | void **return_value); |
| 60 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
| 62 | /******************************************************************************* |
| 63 | * |
| 64 | * FUNCTION: acpi_ds_init_one_object |
| 65 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 66 | * PARAMETERS: obj_handle - Node for the object |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | * Level - Current nesting level |
| 68 | * Context - Points to a init info struct |
| 69 | * return_value - Not used |
| 70 | * |
| 71 | * RETURN: Status |
| 72 | * |
| 73 | * DESCRIPTION: Callback from acpi_walk_namespace. Invoked for every object |
| 74 | * within the namespace. |
| 75 | * |
| 76 | * Currently, the only objects that require initialization are: |
| 77 | * 1) Methods |
| 78 | * 2) Operation Regions |
| 79 | * |
| 80 | ******************************************************************************/ |
| 81 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 82 | static acpi_status |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | acpi_ds_init_one_object ( |
| 84 | acpi_handle obj_handle, |
| 85 | u32 level, |
| 86 | void *context, |
| 87 | void **return_value) |
| 88 | { |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 89 | struct acpi_init_walk_info *info = (struct acpi_init_walk_info *) context; |
| 90 | struct acpi_namespace_node *node = (struct acpi_namespace_node *) obj_handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | acpi_object_type type; |
| 92 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
| 94 | |
| 95 | ACPI_FUNCTION_NAME ("ds_init_one_object"); |
| 96 | |
| 97 | |
| 98 | /* |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 99 | * We are only interested in NS nodes owned by the table that |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | * was just loaded |
| 101 | */ |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 102 | if (node->owner_id != info->table_desc->owner_id) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | return (AE_OK); |
| 104 | } |
| 105 | |
| 106 | info->object_count++; |
| 107 | |
| 108 | /* And even then, we are only interested in a few object types */ |
| 109 | |
| 110 | type = acpi_ns_get_type (obj_handle); |
| 111 | |
| 112 | switch (type) { |
| 113 | case ACPI_TYPE_REGION: |
| 114 | |
| 115 | status = acpi_ds_initialize_region (obj_handle); |
| 116 | if (ACPI_FAILURE (status)) { |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 117 | ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, |
| 118 | "Region %p [%4.4s] - Init failure, %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | obj_handle, acpi_ut_get_node_name (obj_handle), |
| 120 | acpi_format_exception (status))); |
| 121 | } |
| 122 | |
| 123 | info->op_region_count++; |
| 124 | break; |
| 125 | |
| 126 | |
| 127 | case ACPI_TYPE_METHOD: |
| 128 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 129 | /* |
| 130 | * Print a dot for each method unless we are going to print |
| 131 | * the entire pathname |
| 132 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | if (!(acpi_dbg_level & ACPI_LV_INIT_NAMES)) { |
| 134 | ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT, ".")); |
| 135 | } |
| 136 | |
| 137 | /* |
| 138 | * Set the execution data width (32 or 64) based upon the |
| 139 | * revision number of the parent ACPI table. |
| 140 | * TBD: This is really for possible future support of integer width |
| 141 | * on a per-table basis. Currently, we just use a global for the width. |
| 142 | */ |
| 143 | if (info->table_desc->pointer->revision == 1) { |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 144 | node->flags |= ANOBJ_DATA_WIDTH_32; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | /* |
| 148 | * Always parse methods to detect errors, we will delete |
| 149 | * the parse tree below |
| 150 | */ |
| 151 | status = acpi_ds_parse_method (obj_handle); |
| 152 | if (ACPI_FAILURE (status)) { |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 153 | ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 154 | "\n+Method %p [%4.4s] - parse failure, %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | obj_handle, acpi_ut_get_node_name (obj_handle), |
| 156 | acpi_format_exception (status))); |
| 157 | |
| 158 | /* This parse failed, but we will continue parsing more methods */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | } |
| 160 | |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 161 | info->method_count++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | break; |
| 163 | |
| 164 | |
| 165 | case ACPI_TYPE_DEVICE: |
| 166 | |
| 167 | info->device_count++; |
| 168 | break; |
| 169 | |
| 170 | |
| 171 | default: |
| 172 | break; |
| 173 | } |
| 174 | |
| 175 | /* |
| 176 | * We ignore errors from above, and always return OK, since |
| 177 | * we don't want to abort the walk on a single error. |
| 178 | */ |
| 179 | return (AE_OK); |
| 180 | } |
| 181 | |
| 182 | |
| 183 | /******************************************************************************* |
| 184 | * |
| 185 | * FUNCTION: acpi_ds_initialize_objects |
| 186 | * |
| 187 | * PARAMETERS: table_desc - Descriptor for parent ACPI table |
| 188 | * start_node - Root of subtree to be initialized. |
| 189 | * |
| 190 | * RETURN: Status |
| 191 | * |
| 192 | * DESCRIPTION: Walk the namespace starting at "start_node" and perform any |
| 193 | * necessary initialization on the objects found therein |
| 194 | * |
| 195 | ******************************************************************************/ |
| 196 | |
| 197 | acpi_status |
| 198 | acpi_ds_initialize_objects ( |
| 199 | struct acpi_table_desc *table_desc, |
| 200 | struct acpi_namespace_node *start_node) |
| 201 | { |
| 202 | acpi_status status; |
| 203 | struct acpi_init_walk_info info; |
| 204 | |
| 205 | |
| 206 | ACPI_FUNCTION_TRACE ("ds_initialize_objects"); |
| 207 | |
| 208 | |
| 209 | ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, |
| 210 | "**** Starting initialization of namespace objects ****\n")); |
| 211 | ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT, "Parsing all Control Methods:")); |
| 212 | |
| 213 | info.method_count = 0; |
| 214 | info.op_region_count = 0; |
| 215 | info.object_count = 0; |
| 216 | info.device_count = 0; |
| 217 | info.table_desc = table_desc; |
| 218 | |
| 219 | /* Walk entire namespace from the supplied root */ |
| 220 | |
| 221 | status = acpi_walk_namespace (ACPI_TYPE_ANY, start_node, ACPI_UINT32_MAX, |
| 222 | acpi_ds_init_one_object, &info, NULL); |
| 223 | if (ACPI_FAILURE (status)) { |
| 224 | ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "walk_namespace failed, %s\n", |
| 225 | acpi_format_exception (status))); |
| 226 | } |
| 227 | |
| 228 | ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT, |
| 229 | "\nTable [%4.4s](id %4.4X) - %hd Objects with %hd Devices %hd Methods %hd Regions\n", |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 230 | table_desc->pointer->signature, table_desc->owner_id, info.object_count, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | info.device_count, info.method_count, info.op_region_count)); |
| 232 | |
| 233 | ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, |
| 234 | "%hd Methods, %hd Regions\n", info.method_count, info.op_region_count)); |
| 235 | |
| 236 | return_ACPI_STATUS (AE_OK); |
| 237 | } |
| 238 | |
| 239 | |