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