| 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 | /* | 
| Bob Moore | 6c9deb7 | 2007-02-02 19:48:24 +0300 | [diff] [blame] | 8 | * Copyright (C) 2000 - 2007, 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/acdispat.h> | 
|  | 46 | #include <acpi/acnamesp.h> | 
| Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 47 | #include <acpi/actables.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 |  | 
|  | 49 | #define _COMPONENT          ACPI_DISPATCHER | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 50 | ACPI_MODULE_NAME("dsinit") | 
| 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 */ | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 53 | static acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 54 | acpi_ds_init_one_object(acpi_handle obj_handle, | 
|  | 55 | u32 level, void *context, void **return_value); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 |  | 
|  | 57 | /******************************************************************************* | 
|  | 58 | * | 
|  | 59 | * FUNCTION:    acpi_ds_init_one_object | 
|  | 60 | * | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 61 | * PARAMETERS:  obj_handle      - Node for the object | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | *              Level           - Current nesting level | 
|  | 63 | *              Context         - Points to a init info struct | 
|  | 64 | *              return_value    - Not used | 
|  | 65 | * | 
|  | 66 | * RETURN:      Status | 
|  | 67 | * | 
|  | 68 | * DESCRIPTION: Callback from acpi_walk_namespace. Invoked for every object | 
|  | 69 | *              within the namespace. | 
|  | 70 | * | 
|  | 71 | *              Currently, the only objects that require initialization are: | 
|  | 72 | *              1) Methods | 
|  | 73 | *              2) Operation Regions | 
|  | 74 | * | 
|  | 75 | ******************************************************************************/ | 
|  | 76 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 77 | static acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 78 | acpi_ds_init_one_object(acpi_handle obj_handle, | 
|  | 79 | u32 level, void *context, void **return_value) | 
| 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 | struct acpi_init_walk_info *info = | 
|  | 82 | (struct acpi_init_walk_info *)context; | 
|  | 83 | struct acpi_namespace_node *node = | 
|  | 84 | (struct acpi_namespace_node *)obj_handle; | 
|  | 85 | acpi_object_type type; | 
|  | 86 | acpi_status status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 |  | 
| Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame] | 88 | ACPI_FUNCTION_ENTRY(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 |  | 
|  | 90 | /* | 
| Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 91 | * We are only interested in NS nodes owned by the table that | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | * was just loaded | 
|  | 93 | */ | 
| Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 94 | if (node->owner_id != info->owner_id) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | return (AE_OK); | 
|  | 96 | } | 
|  | 97 |  | 
|  | 98 | info->object_count++; | 
|  | 99 |  | 
|  | 100 | /* And even then, we are only interested in a few object types */ | 
|  | 101 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 102 | type = acpi_ns_get_type(obj_handle); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 |  | 
|  | 104 | switch (type) { | 
|  | 105 | case ACPI_TYPE_REGION: | 
|  | 106 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 107 | status = acpi_ds_initialize_region(obj_handle); | 
|  | 108 | if (ACPI_FAILURE(status)) { | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 109 | ACPI_EXCEPTION((AE_INFO, status, | 
|  | 110 | "During Region initialization %p [%4.4s]", | 
|  | 111 | obj_handle, | 
|  | 112 | acpi_ut_get_node_name(obj_handle))); | 
| 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 | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 120 | info->method_count++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | break; | 
|  | 122 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | case ACPI_TYPE_DEVICE: | 
|  | 124 |  | 
|  | 125 | info->device_count++; | 
|  | 126 | break; | 
|  | 127 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | default: | 
|  | 129 | break; | 
|  | 130 | } | 
|  | 131 |  | 
|  | 132 | /* | 
|  | 133 | * We ignore errors from above, and always return OK, since | 
|  | 134 | * we don't want to abort the walk on a single error. | 
|  | 135 | */ | 
|  | 136 | return (AE_OK); | 
|  | 137 | } | 
|  | 138 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | /******************************************************************************* | 
|  | 140 | * | 
|  | 141 | * FUNCTION:    acpi_ds_initialize_objects | 
|  | 142 | * | 
|  | 143 | * PARAMETERS:  table_desc      - Descriptor for parent ACPI table | 
|  | 144 | *              start_node      - Root of subtree to be initialized. | 
|  | 145 | * | 
|  | 146 | * RETURN:      Status | 
|  | 147 | * | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 148 | * DESCRIPTION: Walk the namespace starting at "StartNode" and perform any | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | *              necessary initialization on the objects found therein | 
|  | 150 | * | 
|  | 151 | ******************************************************************************/ | 
|  | 152 |  | 
|  | 153 | acpi_status | 
| Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 154 | acpi_ds_initialize_objects(acpi_native_uint table_index, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 155 | struct acpi_namespace_node * start_node) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 157 | acpi_status status; | 
|  | 158 | struct acpi_init_walk_info info; | 
| Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 159 | struct acpi_table_header *table; | 
|  | 160 | acpi_owner_id owner_id; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 162 | ACPI_FUNCTION_TRACE(ds_initialize_objects); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 |  | 
| Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 164 | status = acpi_tb_get_owner_id(table_index, &owner_id); | 
|  | 165 | if (ACPI_FAILURE(status)) { | 
|  | 166 | return_ACPI_STATUS(status); | 
|  | 167 | } | 
|  | 168 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 169 | ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, | 
|  | 170 | "**** Starting initialization of namespace objects ****\n")); | 
|  | 171 | ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, "Parsing all Control Methods:")); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 173 | info.method_count = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | info.op_region_count = 0; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 175 | info.object_count = 0; | 
|  | 176 | info.device_count = 0; | 
| Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 177 | info.table_index = table_index; | 
|  | 178 | info.owner_id = owner_id; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 |  | 
|  | 180 | /* Walk entire namespace from the supplied root */ | 
|  | 181 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 182 | status = acpi_walk_namespace(ACPI_TYPE_ANY, start_node, ACPI_UINT32_MAX, | 
|  | 183 | acpi_ds_init_one_object, &info, NULL); | 
|  | 184 | if (ACPI_FAILURE(status)) { | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 185 | ACPI_EXCEPTION((AE_INFO, status, "During WalkNamespace")); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | } | 
|  | 187 |  | 
| Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 188 | status = acpi_get_table_by_index(table_index, &table); | 
|  | 189 | if (ACPI_FAILURE(status)) { | 
|  | 190 | return_ACPI_STATUS(status); | 
|  | 191 | } | 
|  | 192 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 193 | ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, | 
|  | 194 | "\nTable [%4.4s](id %4.4X) - %hd Objects with %hd Devices %hd Methods %hd Regions\n", | 
| Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 195 | table->signature, owner_id, info.object_count, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 196 | info.device_count, info.method_count, | 
|  | 197 | info.op_region_count)); | 
| 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 | ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, | 
|  | 200 | "%hd Methods, %hd Regions\n", info.method_count, | 
|  | 201 | info.op_region_count)); | 
| 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 | return_ACPI_STATUS(AE_OK); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | } |