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 | fbb7a2d | 2014-02-08 09:42:25 +0800 | [diff] [blame] | 8 | * Copyright (C) 2000 - 2014, Intel Corp. |
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> |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 45 | #include "accommon.h" |
| 46 | #include "acdispat.h" |
| 47 | #include "acnamesp.h" |
| 48 | #include "actables.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
| 50 | #define _COMPONENT ACPI_DISPATCHER |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 51 | ACPI_MODULE_NAME("dsinit") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 53 | /* Local prototypes */ |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 54 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 55 | acpi_ds_init_one_object(acpi_handle obj_handle, |
| 56 | u32 level, void *context, void **return_value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
| 58 | /******************************************************************************* |
| 59 | * |
| 60 | * FUNCTION: acpi_ds_init_one_object |
| 61 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 62 | * PARAMETERS: obj_handle - Node for the object |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 63 | * level - Current nesting level |
| 64 | * context - Points to a init info struct |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | * return_value - Not used |
| 66 | * |
| 67 | * RETURN: Status |
| 68 | * |
| 69 | * DESCRIPTION: Callback from acpi_walk_namespace. Invoked for every object |
| 70 | * within the namespace. |
| 71 | * |
| 72 | * Currently, the only objects that require initialization are: |
| 73 | * 1) Methods |
| 74 | * 2) Operation Regions |
| 75 | * |
| 76 | ******************************************************************************/ |
| 77 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 78 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 79 | acpi_ds_init_one_object(acpi_handle obj_handle, |
| 80 | u32 level, void *context, void **return_value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 82 | struct acpi_init_walk_info *info = |
| 83 | (struct acpi_init_walk_info *)context; |
| 84 | struct acpi_namespace_node *node = |
| 85 | (struct acpi_namespace_node *)obj_handle; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 86 | acpi_status status; |
Bob Moore | 22b5afc | 2014-03-24 14:49:00 +0800 | [diff] [blame] | 87 | union acpi_operand_object *obj_desc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame] | 89 | ACPI_FUNCTION_ENTRY(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | |
| 91 | /* |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 92 | * We are only interested in NS nodes owned by the table that |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | * was just loaded |
| 94 | */ |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 95 | if (node->owner_id != info->owner_id) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | return (AE_OK); |
| 97 | } |
| 98 | |
| 99 | info->object_count++; |
| 100 | |
| 101 | /* And even then, we are only interested in a few object types */ |
| 102 | |
Bob Moore | 22b5afc | 2014-03-24 14:49:00 +0800 | [diff] [blame] | 103 | switch (acpi_ns_get_type(obj_handle)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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)) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 108 | ACPI_EXCEPTION((AE_INFO, status, |
| 109 | "During Region initialization %p [%4.4s]", |
| 110 | obj_handle, |
| 111 | acpi_ut_get_node_name(obj_handle))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | info->op_region_count++; |
| 115 | break; |
| 116 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | case ACPI_TYPE_METHOD: |
Bob Moore | 22b5afc | 2014-03-24 14:49:00 +0800 | [diff] [blame] | 118 | /* |
| 119 | * Auto-serialization support. We will examine each method that is |
| 120 | * not_serialized to determine if it creates any Named objects. If |
| 121 | * it does, it will be marked serialized to prevent problems if |
| 122 | * the method is entered by two or more threads and an attempt is |
| 123 | * made to create the same named object twice -- which results in |
| 124 | * an AE_ALREADY_EXISTS exception and method abort. |
| 125 | */ |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 126 | info->method_count++; |
Bob Moore | 22b5afc | 2014-03-24 14:49:00 +0800 | [diff] [blame] | 127 | obj_desc = acpi_ns_get_attached_object(node); |
| 128 | if (!obj_desc) { |
| 129 | break; |
| 130 | } |
| 131 | |
| 132 | /* Ignore if already serialized */ |
| 133 | |
| 134 | if (obj_desc->method.info_flags & ACPI_METHOD_SERIALIZED) { |
| 135 | info->serial_method_count++; |
| 136 | break; |
| 137 | } |
| 138 | |
| 139 | if (acpi_gbl_auto_serialize_methods) { |
| 140 | |
| 141 | /* Parse/scan method and serialize it if necessary */ |
| 142 | |
| 143 | acpi_ds_auto_serialize_method(node, obj_desc); |
| 144 | if (obj_desc->method. |
| 145 | info_flags & ACPI_METHOD_SERIALIZED) { |
| 146 | |
| 147 | /* Method was just converted to Serialized */ |
| 148 | |
| 149 | info->serial_method_count++; |
| 150 | info->serialized_method_count++; |
| 151 | break; |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | info->non_serial_method_count++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | break; |
| 157 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | case ACPI_TYPE_DEVICE: |
| 159 | |
| 160 | info->device_count++; |
| 161 | break; |
| 162 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | default: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 164 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | break; |
| 166 | } |
| 167 | |
| 168 | /* |
| 169 | * We ignore errors from above, and always return OK, since |
| 170 | * we don't want to abort the walk on a single error. |
| 171 | */ |
| 172 | return (AE_OK); |
| 173 | } |
| 174 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | /******************************************************************************* |
| 176 | * |
| 177 | * FUNCTION: acpi_ds_initialize_objects |
| 178 | * |
| 179 | * PARAMETERS: table_desc - Descriptor for parent ACPI table |
| 180 | * start_node - Root of subtree to be initialized. |
| 181 | * |
| 182 | * RETURN: Status |
| 183 | * |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 184 | * DESCRIPTION: Walk the namespace starting at "StartNode" and perform any |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | * necessary initialization on the objects found therein |
| 186 | * |
| 187 | ******************************************************************************/ |
| 188 | |
| 189 | acpi_status |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 190 | acpi_ds_initialize_objects(u32 table_index, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 191 | struct acpi_namespace_node * start_node) |
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_status status; |
| 194 | struct acpi_init_walk_info info; |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 195 | struct acpi_table_header *table; |
| 196 | acpi_owner_id owner_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 198 | ACPI_FUNCTION_TRACE(ds_initialize_objects); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 200 | status = acpi_tb_get_owner_id(table_index, &owner_id); |
| 201 | if (ACPI_FAILURE(status)) { |
| 202 | return_ACPI_STATUS(status); |
| 203 | } |
| 204 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 205 | ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, |
| 206 | "**** Starting initialization of namespace objects ****\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
Alexey Starikovskiy | 96b7b7a | 2010-05-26 11:20:47 +0800 | [diff] [blame] | 208 | /* Set all init info to zero */ |
| 209 | |
| 210 | ACPI_MEMSET(&info, 0, sizeof(struct acpi_init_walk_info)); |
| 211 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 212 | info.owner_id = owner_id; |
Alexey Starikovskiy | 96b7b7a | 2010-05-26 11:20:47 +0800 | [diff] [blame] | 213 | info.table_index = table_index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | |
| 215 | /* Walk entire namespace from the supplied root */ |
| 216 | |
Bob Moore | 8a335a23 | 2009-03-09 16:31:04 +0800 | [diff] [blame] | 217 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
| 218 | if (ACPI_FAILURE(status)) { |
| 219 | return_ACPI_STATUS(status); |
| 220 | } |
| 221 | |
| 222 | /* |
| 223 | * We don't use acpi_walk_namespace since we do not want to acquire |
| 224 | * the namespace reader lock. |
| 225 | */ |
| 226 | status = |
| 227 | acpi_ns_walk_namespace(ACPI_TYPE_ANY, start_node, ACPI_UINT32_MAX, |
| 228 | ACPI_NS_WALK_UNLOCK, acpi_ds_init_one_object, |
Lin Ming | 2263576 | 2009-11-13 10:06:08 +0800 | [diff] [blame] | 229 | NULL, &info, NULL); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 230 | if (ACPI_FAILURE(status)) { |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 231 | ACPI_EXCEPTION((AE_INFO, status, "During WalkNamespace")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | } |
Bob Moore | 8a335a23 | 2009-03-09 16:31:04 +0800 | [diff] [blame] | 233 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 235 | status = acpi_get_table_by_index(table_index, &table); |
| 236 | if (ACPI_FAILURE(status)) { |
| 237 | return_ACPI_STATUS(status); |
| 238 | } |
| 239 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 240 | ACPI_DEBUG_PRINT_RAW((ACPI_DB_INIT, |
Bob Moore | 22b5afc | 2014-03-24 14:49:00 +0800 | [diff] [blame] | 241 | "Table [%4.4s] (id %4.4X) - %4u Objects with %3u Devices, " |
| 242 | "%3u Regions, %3u Methods (%u/%u/%u Serial/Non/Cvt)\n", |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 243 | table->signature, owner_id, info.object_count, |
Bob Moore | 22b5afc | 2014-03-24 14:49:00 +0800 | [diff] [blame] | 244 | info.device_count, info.op_region_count, |
| 245 | info.method_count, info.serial_method_count, |
| 246 | info.non_serial_method_count, |
| 247 | info.serialized_method_count)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | |
Bob Moore | 22b5afc | 2014-03-24 14:49:00 +0800 | [diff] [blame] | 249 | ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "%u Methods, %u Regions\n", |
| 250 | info.method_count, info.op_region_count)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 252 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | } |