Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * |
| 3 | * Module Name: nsaccess - Top-level functions for accessing ACPI namespace |
| 4 | * |
| 5 | ******************************************************************************/ |
| 6 | |
| 7 | /* |
Bob Moore | da6f832 | 2018-01-04 10:06:38 -0800 | [diff] [blame] | 8 | * Copyright (C) 2000 - 2018, 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 "amlcode.h" |
| 47 | #include "acnamesp.h" |
| 48 | #include "acdispat.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Erik Schmauss | a9d8ea7 | 2017-06-05 16:41:55 +0800 | [diff] [blame] | 50 | #ifdef ACPI_ASL_COMPILER |
| 51 | #include "acdisasm.h" |
| 52 | #endif |
| 53 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | #define _COMPONENT ACPI_NAMESPACE |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 55 | ACPI_MODULE_NAME("nsaccess") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
| 57 | /******************************************************************************* |
| 58 | * |
| 59 | * FUNCTION: acpi_ns_root_initialize |
| 60 | * |
| 61 | * PARAMETERS: None |
| 62 | * |
| 63 | * RETURN: Status |
| 64 | * |
| 65 | * DESCRIPTION: Allocate and initialize the default root named objects |
| 66 | * |
| 67 | * MUTEX: Locks namespace for entire execution |
| 68 | * |
| 69 | ******************************************************************************/ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 70 | acpi_status acpi_ns_root_initialize(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 72 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | const struct acpi_predefined_names *init_val = NULL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 74 | struct acpi_namespace_node *new_node; |
| 75 | union acpi_operand_object *obj_desc; |
| 76 | acpi_string val = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 78 | ACPI_FUNCTION_TRACE(ns_root_initialize); |
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 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
| 81 | if (ACPI_FAILURE(status)) { |
| 82 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | /* |
| 86 | * The global root ptr is initially NULL, so a non-NULL value indicates |
| 87 | * that acpi_ns_root_initialize() has already been called; just return. |
| 88 | */ |
| 89 | if (acpi_gbl_root_node) { |
| 90 | status = AE_OK; |
| 91 | goto unlock_and_exit; |
| 92 | } |
| 93 | |
| 94 | /* |
| 95 | * Tell the rest of the subsystem that the root is initialized |
| 96 | * (This is OK because the namespace is locked) |
| 97 | */ |
| 98 | acpi_gbl_root_node = &acpi_gbl_root_node_struct; |
| 99 | |
| 100 | /* Enter the pre-defined names in the name table */ |
| 101 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 102 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 103 | "Entering predefined entries into namespace\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | |
| 105 | for (init_val = acpi_gbl_pre_defined_names; init_val->name; init_val++) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 106 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | /* _OSI is optional for now, will be permanent later */ |
| 108 | |
Bob Moore | 4fa4616 | 2015-07-01 14:45:11 +0800 | [diff] [blame] | 109 | if (!strcmp(init_val->name, "_OSI") |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 110 | && !acpi_gbl_create_osi_method) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | continue; |
| 112 | } |
| 113 | |
Bob Moore | 0dfaaa3 | 2016-03-24 09:40:40 +0800 | [diff] [blame] | 114 | status = |
Jung-uk Kim | fee4ab9 | 2016-08-04 16:42:34 +0800 | [diff] [blame] | 115 | acpi_ns_lookup(NULL, ACPI_CAST_PTR(char, init_val->name), |
| 116 | init_val->type, ACPI_IMODE_LOAD_PASS2, |
| 117 | ACPI_NS_NO_UPSEARCH, NULL, &new_node); |
Robert Moore | 267d672 | 2012-10-31 02:26:36 +0000 | [diff] [blame] | 118 | if (ACPI_FAILURE(status)) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 119 | ACPI_EXCEPTION((AE_INFO, status, |
| 120 | "Could not create predefined name %s", |
| 121 | init_val->name)); |
Robert Moore | 267d672 | 2012-10-31 02:26:36 +0000 | [diff] [blame] | 122 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | /* |
Bob Moore | d4913dc | 2009-03-06 10:05:18 +0800 | [diff] [blame] | 126 | * Name entered successfully. If entry in pre_defined_names[] specifies |
| 127 | * an initial value, create the initial value. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | */ |
| 129 | if (init_val->val) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 130 | status = acpi_os_predefined_override(init_val, &val); |
| 131 | if (ACPI_FAILURE(status)) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 132 | ACPI_ERROR((AE_INFO, |
| 133 | "Could not override predefined %s", |
| 134 | init_val->name)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | if (!val) { |
| 138 | val = init_val->val; |
| 139 | } |
| 140 | |
| 141 | /* |
| 142 | * Entry requests an initial value, allocate a |
| 143 | * descriptor for it. |
| 144 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 145 | obj_desc = |
| 146 | acpi_ut_create_internal_object(init_val->type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | if (!obj_desc) { |
| 148 | status = AE_NO_MEMORY; |
| 149 | goto unlock_and_exit; |
| 150 | } |
| 151 | |
| 152 | /* |
| 153 | * Convert value string from table entry to |
| 154 | * internal representation. Only types actually |
| 155 | * used for initial values are implemented here. |
| 156 | */ |
| 157 | switch (init_val->type) { |
| 158 | case ACPI_TYPE_METHOD: |
Chao Guan | 1d1ea1b | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 159 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 160 | obj_desc->method.param_count = |
| 161 | (u8) ACPI_TO_INTEGER(val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | obj_desc->common.flags |= AOPOBJ_DATA_VALID; |
| 163 | |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 164 | #if defined (ACPI_ASL_COMPILER) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 166 | /* Save the parameter count for the iASL compiler */ |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 167 | |
| 168 | new_node->value = obj_desc->method.param_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | #else |
| 170 | /* Mark this as a very SPECIAL method */ |
| 171 | |
Lin Ming | 2629484 | 2011-01-12 09:19:43 +0800 | [diff] [blame] | 172 | obj_desc->method.info_flags = |
| 173 | ACPI_METHOD_INTERNAL_ONLY; |
| 174 | obj_desc->method.dispatch.implementation = |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 175 | acpi_ut_osi_implementation; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | #endif |
| 177 | break; |
| 178 | |
| 179 | case ACPI_TYPE_INTEGER: |
| 180 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 181 | obj_desc->integer.value = ACPI_TO_INTEGER(val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | break; |
| 183 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | case ACPI_TYPE_STRING: |
| 185 | |
Bob Moore | d4913dc | 2009-03-06 10:05:18 +0800 | [diff] [blame] | 186 | /* Build an object around the static string */ |
| 187 | |
Bob Moore | 4fa4616 | 2015-07-01 14:45:11 +0800 | [diff] [blame] | 188 | obj_desc->string.length = (u32)strlen(val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | obj_desc->string.pointer = val; |
| 190 | obj_desc->common.flags |= AOPOBJ_STATIC_POINTER; |
| 191 | break; |
| 192 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | case ACPI_TYPE_MUTEX: |
| 194 | |
| 195 | obj_desc->mutex.node = new_node; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 196 | obj_desc->mutex.sync_level = |
| 197 | (u8) (ACPI_TO_INTEGER(val) - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | |
Bob Moore | c81da66 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 199 | /* Create a mutex */ |
| 200 | |
| 201 | status = |
| 202 | acpi_os_create_mutex(&obj_desc->mutex. |
| 203 | os_mutex); |
| 204 | if (ACPI_FAILURE(status)) { |
| 205 | acpi_ut_remove_reference(obj_desc); |
| 206 | goto unlock_and_exit; |
| 207 | } |
| 208 | |
| 209 | /* Special case for ACPI Global Lock */ |
| 210 | |
Bob Moore | 4fa4616 | 2015-07-01 14:45:11 +0800 | [diff] [blame] | 211 | if (strcmp(init_val->name, "_GL_") == 0) { |
Bob Moore | ba886cd | 2008-04-10 19:06:37 +0400 | [diff] [blame] | 212 | acpi_gbl_global_lock_mutex = obj_desc; |
Bob Moore | 967440e3 | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 213 | |
Bob Moore | c81da66 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 214 | /* Create additional counting semaphore for global lock */ |
Bob Moore | 967440e3 | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 215 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 216 | status = |
Bob Moore | 73ca0fb | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 217 | acpi_os_create_semaphore(1, 0, |
Bob Moore | c81da66 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 218 | &acpi_gbl_global_lock_semaphore); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 219 | if (ACPI_FAILURE(status)) { |
| 220 | acpi_ut_remove_reference |
| 221 | (obj_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | goto unlock_and_exit; |
| 223 | } |
| 224 | } |
| 225 | break; |
| 226 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | default: |
| 228 | |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 229 | ACPI_ERROR((AE_INFO, |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 230 | "Unsupported initial type value 0x%X", |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 231 | init_val->type)); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 232 | acpi_ut_remove_reference(obj_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | obj_desc = NULL; |
| 234 | continue; |
| 235 | } |
| 236 | |
| 237 | /* Store pointer to value descriptor in the Node */ |
| 238 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 239 | status = acpi_ns_attach_object(new_node, obj_desc, |
Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 240 | obj_desc->common.type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | |
| 242 | /* Remove local reference to the object */ |
| 243 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 244 | acpi_ut_remove_reference(obj_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | } |
| 246 | } |
| 247 | |
Lv Zheng | 10622bf | 2013-10-29 09:30:02 +0800 | [diff] [blame] | 248 | unlock_and_exit: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 249 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | |
| 251 | /* Save a handle to "_GPE", it is always present */ |
| 252 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 253 | if (ACPI_SUCCESS(status)) { |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 254 | status = acpi_ns_get_node(NULL, "\\_GPE", ACPI_NS_NO_UPSEARCH, |
| 255 | &acpi_gbl_fadt_gpe_device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 258 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | } |
| 260 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | /******************************************************************************* |
| 262 | * |
| 263 | * FUNCTION: acpi_ns_lookup |
| 264 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 265 | * PARAMETERS: scope_info - Current scope info block |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 266 | * pathname - Search pathname, in internal format |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | * (as represented in the AML stream) |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 268 | * type - Type associated with name |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | * interpreter_mode - IMODE_LOAD_PASS2 => add name if not found |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 270 | * flags - Flags describing the search restrictions |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | * walk_state - Current state of the walk |
| 272 | * return_node - Where the Node is placed (if found |
| 273 | * or created successfully) |
| 274 | * |
| 275 | * RETURN: Status |
| 276 | * |
| 277 | * DESCRIPTION: Find or enter the passed name in the name space. |
| 278 | * Log an error if name not found in Exec mode. |
| 279 | * |
| 280 | * MUTEX: Assumes namespace is locked. |
| 281 | * |
| 282 | ******************************************************************************/ |
| 283 | |
| 284 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 285 | acpi_ns_lookup(union acpi_generic_state *scope_info, |
| 286 | char *pathname, |
| 287 | acpi_object_type type, |
| 288 | acpi_interpreter_mode interpreter_mode, |
| 289 | u32 flags, |
| 290 | struct acpi_walk_state *walk_state, |
| 291 | struct acpi_namespace_node **return_node) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 293 | acpi_status status; |
| 294 | char *path = pathname; |
Bob Moore | 6d9229d | 2017-08-03 14:26:31 +0800 | [diff] [blame] | 295 | char *external_path; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 296 | struct acpi_namespace_node *prefix_node; |
| 297 | struct acpi_namespace_node *current_node = NULL; |
| 298 | struct acpi_namespace_node *this_node = NULL; |
| 299 | u32 num_segments; |
| 300 | u32 num_carats; |
| 301 | acpi_name simple_name; |
| 302 | acpi_object_type type_to_check_for; |
| 303 | acpi_object_type this_search_type; |
| 304 | u32 search_parent_flag = ACPI_NS_SEARCH_PARENT; |
Bob Moore | 958dd24 | 2006-05-12 17:12:00 -0400 | [diff] [blame] | 305 | u32 local_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 307 | ACPI_FUNCTION_TRACE(ns_lookup); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | |
| 309 | if (!return_node) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 310 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | } |
| 312 | |
Lv Zheng | 8f6f036 | 2015-07-01 14:44:17 +0800 | [diff] [blame] | 313 | local_flags = flags & |
| 314 | ~(ACPI_NS_ERROR_IF_FOUND | ACPI_NS_OVERRIDE_IF_FOUND | |
| 315 | ACPI_NS_SEARCH_PARENT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | *return_node = ACPI_ENTRY_NOT_FOUND; |
Bob Moore | 958dd24 | 2006-05-12 17:12:00 -0400 | [diff] [blame] | 317 | acpi_gbl_ns_lookup_count++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | |
| 319 | if (!acpi_gbl_root_node) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 320 | return_ACPI_STATUS(AE_NO_NAMESPACE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | } |
| 322 | |
Bob Moore | d4913dc | 2009-03-06 10:05:18 +0800 | [diff] [blame] | 323 | /* Get the prefix scope. A null scope means use the root scope */ |
| 324 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 325 | if ((!scope_info) || (!scope_info->scope.node)) { |
| 326 | ACPI_DEBUG_PRINT((ACPI_DB_NAMES, |
| 327 | "Null scope prefix, using root node (%p)\n", |
| 328 | acpi_gbl_root_node)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | |
| 330 | prefix_node = acpi_gbl_root_node; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 331 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | prefix_node = scope_info->scope.node; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 333 | if (ACPI_GET_DESCRIPTOR_TYPE(prefix_node) != |
| 334 | ACPI_DESC_TYPE_NAMED) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 335 | ACPI_ERROR((AE_INFO, "%p is not a namespace node [%s]", |
| 336 | prefix_node, |
| 337 | acpi_ut_get_descriptor_name(prefix_node))); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 338 | return_ACPI_STATUS(AE_AML_INTERNAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | } |
| 340 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 341 | if (!(flags & ACPI_NS_PREFIX_IS_SCOPE)) { |
| 342 | /* |
| 343 | * This node might not be a actual "scope" node (such as a |
Bob Moore | d4913dc | 2009-03-06 10:05:18 +0800 | [diff] [blame] | 344 | * Device/Method, etc.) It could be a Package or other object |
| 345 | * node. Backup up the tree to find the containing scope node. |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 346 | */ |
| 347 | while (!acpi_ns_opens_scope(prefix_node->type) && |
| 348 | prefix_node->type != ACPI_TYPE_ANY) { |
Alexey Starikovskiy | c45b5c0 | 2010-05-26 11:53:07 +0800 | [diff] [blame] | 349 | prefix_node = prefix_node->parent; |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 350 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | } |
| 352 | } |
| 353 | |
Bob Moore | d4913dc | 2009-03-06 10:05:18 +0800 | [diff] [blame] | 354 | /* Save type. TBD: may be no longer necessary */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | |
| 356 | type_to_check_for = type; |
| 357 | |
| 358 | /* |
| 359 | * Begin examination of the actual pathname |
| 360 | */ |
| 361 | if (!pathname) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 362 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | /* A Null name_path is allowed and refers to the root */ |
| 364 | |
| 365 | num_segments = 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 366 | this_node = acpi_gbl_root_node; |
| 367 | path = ""; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 369 | ACPI_DEBUG_PRINT((ACPI_DB_NAMES, |
| 370 | "Null Pathname (Zero segments), Flags=%X\n", |
| 371 | flags)); |
| 372 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | /* |
| 374 | * Name pointer is valid (and must be in internal name format) |
| 375 | * |
| 376 | * Check for scope prefixes: |
| 377 | * |
| 378 | * As represented in the AML stream, a namepath consists of an |
| 379 | * optional scope prefix followed by a name segment part. |
| 380 | * |
| 381 | * If present, the scope prefix is either a Root Prefix (in |
| 382 | * which case the name is fully qualified), or one or more |
| 383 | * Parent Prefixes (in which case the name's scope is relative |
| 384 | * to the current scope). |
| 385 | */ |
| 386 | if (*path == (u8) AML_ROOT_PREFIX) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 387 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | /* Pathname is fully qualified, start from the root */ |
| 389 | |
| 390 | this_node = acpi_gbl_root_node; |
| 391 | search_parent_flag = ACPI_NS_NO_UPSEARCH; |
| 392 | |
| 393 | /* Point to name segment part */ |
| 394 | |
| 395 | path++; |
| 396 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 397 | ACPI_DEBUG_PRINT((ACPI_DB_NAMES, |
| 398 | "Path is absolute from root [%p]\n", |
| 399 | this_node)); |
| 400 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | /* Pathname is relative to current scope, start there */ |
| 402 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 403 | ACPI_DEBUG_PRINT((ACPI_DB_NAMES, |
| 404 | "Searching relative to prefix scope [%4.4s] (%p)\n", |
| 405 | acpi_ut_get_node_name(prefix_node), |
| 406 | prefix_node)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | |
| 408 | /* |
| 409 | * Handle multiple Parent Prefixes (carat) by just getting |
| 410 | * the parent node for each prefix instance. |
| 411 | */ |
| 412 | this_node = prefix_node; |
| 413 | num_carats = 0; |
| 414 | while (*path == (u8) AML_PARENT_PREFIX) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 415 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | /* Name is fully qualified, no search rules apply */ |
| 417 | |
| 418 | search_parent_flag = ACPI_NS_NO_UPSEARCH; |
Bob Moore | d4913dc | 2009-03-06 10:05:18 +0800 | [diff] [blame] | 419 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | /* |
| 421 | * Point past this prefix to the name segment |
| 422 | * part or the next Parent Prefix |
| 423 | */ |
| 424 | path++; |
| 425 | |
| 426 | /* Backup to the parent node */ |
| 427 | |
| 428 | num_carats++; |
Alexey Starikovskiy | c45b5c0 | 2010-05-26 11:53:07 +0800 | [diff] [blame] | 429 | this_node = this_node->parent; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | if (!this_node) { |
Bob Moore | 6d9229d | 2017-08-03 14:26:31 +0800 | [diff] [blame] | 431 | /* |
| 432 | * Current scope has no parent scope. Externalize |
| 433 | * the internal path for error message. |
| 434 | */ |
| 435 | status = |
| 436 | acpi_ns_externalize_name |
| 437 | (ACPI_UINT32_MAX, pathname, NULL, |
| 438 | &external_path); |
| 439 | if (ACPI_SUCCESS(status)) { |
| 440 | ACPI_ERROR((AE_INFO, |
| 441 | "%s: Path has too many parent prefixes (^)", |
| 442 | external_path)); |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 443 | |
Bob Moore | 6d9229d | 2017-08-03 14:26:31 +0800 | [diff] [blame] | 444 | ACPI_FREE(external_path); |
| 445 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 447 | return_ACPI_STATUS(AE_NOT_FOUND); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | } |
| 449 | } |
| 450 | |
| 451 | if (search_parent_flag == ACPI_NS_NO_UPSEARCH) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 452 | ACPI_DEBUG_PRINT((ACPI_DB_NAMES, |
Bob Moore | b27d659 | 2010-05-26 11:47:13 +0800 | [diff] [blame] | 453 | "Search scope is [%4.4s], path has %u carat(s)\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 454 | acpi_ut_get_node_name |
| 455 | (this_node), num_carats)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | } |
| 457 | } |
| 458 | |
| 459 | /* |
| 460 | * Determine the number of ACPI name segments in this pathname. |
| 461 | * |
| 462 | * The segment part consists of either: |
| 463 | * - A Null name segment (0) |
| 464 | * - A dual_name_prefix followed by two 4-byte name segments |
| 465 | * - A multi_name_prefix followed by a byte indicating the |
| 466 | * number of segments and the segments themselves. |
| 467 | * - A single 4-byte name segment |
| 468 | * |
| 469 | * Examine the name prefix opcode, if any, to determine the number of |
| 470 | * segments. |
| 471 | */ |
| 472 | switch (*path) { |
| 473 | case 0: |
| 474 | /* |
| 475 | * Null name after a root or parent prefixes. We already |
| 476 | * have the correct target node and there are no name segments. |
| 477 | */ |
| 478 | num_segments = 0; |
| 479 | type = this_node->type; |
| 480 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 481 | ACPI_DEBUG_PRINT((ACPI_DB_NAMES, |
| 482 | "Prefix-only Pathname (Zero name segments), Flags=%X\n", |
| 483 | flags)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | break; |
| 485 | |
| 486 | case AML_DUAL_NAME_PREFIX: |
| 487 | |
| 488 | /* More than one name_seg, search rules do not apply */ |
| 489 | |
| 490 | search_parent_flag = ACPI_NS_NO_UPSEARCH; |
| 491 | |
| 492 | /* Two segments, point to first name segment */ |
| 493 | |
| 494 | num_segments = 2; |
| 495 | path++; |
| 496 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 497 | ACPI_DEBUG_PRINT((ACPI_DB_NAMES, |
| 498 | "Dual Pathname (2 segments, Flags=%X)\n", |
| 499 | flags)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | break; |
| 501 | |
Bob Moore | 9ff5a21a | 2017-04-26 16:18:40 +0800 | [diff] [blame] | 502 | case AML_MULTI_NAME_PREFIX: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | |
| 504 | /* More than one name_seg, search rules do not apply */ |
| 505 | |
| 506 | search_parent_flag = ACPI_NS_NO_UPSEARCH; |
| 507 | |
| 508 | /* Extract segment count, point to first name segment */ |
| 509 | |
| 510 | path++; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 511 | num_segments = (u32) (u8) * path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | path++; |
| 513 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 514 | ACPI_DEBUG_PRINT((ACPI_DB_NAMES, |
Bob Moore | b27d659 | 2010-05-26 11:47:13 +0800 | [diff] [blame] | 515 | "Multi Pathname (%u Segments, Flags=%X)\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 516 | num_segments, flags)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | break; |
| 518 | |
| 519 | default: |
| 520 | /* |
| 521 | * Not a Null name, no Dual or Multi prefix, hence there is |
| 522 | * only one name segment and Pathname is already pointing to it. |
| 523 | */ |
| 524 | num_segments = 1; |
| 525 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 526 | ACPI_DEBUG_PRINT((ACPI_DB_NAMES, |
| 527 | "Simple Pathname (1 segment, Flags=%X)\n", |
| 528 | flags)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | break; |
| 530 | } |
| 531 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 532 | ACPI_DEBUG_EXEC(acpi_ns_print_pathname(num_segments, path)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | } |
| 534 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | /* |
Bob Moore | 319f8b8 | 2008-11-13 10:48:00 +0800 | [diff] [blame] | 536 | * Search namespace for each segment of the name. Loop through and |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | * verify (or add to the namespace) each name segment. |
| 538 | * |
| 539 | * The object type is significant only at the last name |
Bob Moore | 319f8b8 | 2008-11-13 10:48:00 +0800 | [diff] [blame] | 540 | * segment. (We don't care about the types along the path, only |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | * the type of the final target object.) |
| 542 | */ |
| 543 | this_search_type = ACPI_TYPE_ANY; |
| 544 | current_node = this_node; |
| 545 | while (num_segments && current_node) { |
| 546 | num_segments--; |
| 547 | if (!num_segments) { |
Bob Moore | d4913dc | 2009-03-06 10:05:18 +0800 | [diff] [blame] | 548 | |
| 549 | /* This is the last segment, enable typechecking */ |
| 550 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | this_search_type = type; |
| 552 | |
| 553 | /* |
| 554 | * Only allow automatic parent search (search rules) if the caller |
| 555 | * requested it AND we have a single, non-fully-qualified name_seg |
| 556 | */ |
| 557 | if ((search_parent_flag != ACPI_NS_NO_UPSEARCH) && |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 558 | (flags & ACPI_NS_SEARCH_PARENT)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | local_flags |= ACPI_NS_SEARCH_PARENT; |
| 560 | } |
| 561 | |
| 562 | /* Set error flag according to caller */ |
| 563 | |
| 564 | if (flags & ACPI_NS_ERROR_IF_FOUND) { |
| 565 | local_flags |= ACPI_NS_ERROR_IF_FOUND; |
| 566 | } |
Lv Zheng | 8f6f036 | 2015-07-01 14:44:17 +0800 | [diff] [blame] | 567 | |
| 568 | /* Set override flag according to caller */ |
| 569 | |
| 570 | if (flags & ACPI_NS_OVERRIDE_IF_FOUND) { |
| 571 | local_flags |= ACPI_NS_OVERRIDE_IF_FOUND; |
| 572 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | /* Extract one ACPI name from the front of the pathname */ |
| 576 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 577 | ACPI_MOVE_32_TO_32(&simple_name, path); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | |
| 579 | /* Try to find the single (4 character) ACPI name */ |
| 580 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 581 | status = |
| 582 | acpi_ns_search_and_enter(simple_name, walk_state, |
| 583 | current_node, interpreter_mode, |
| 584 | this_search_type, local_flags, |
| 585 | &this_node); |
| 586 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | if (status == AE_NOT_FOUND) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 588 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | /* Name not found in ACPI namespace */ |
| 590 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 591 | ACPI_DEBUG_PRINT((ACPI_DB_NAMES, |
| 592 | "Name [%4.4s] not found in scope [%4.4s] %p\n", |
| 593 | (char *)&simple_name, |
| 594 | (char *)¤t_node->name, |
| 595 | current_node)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | } |
Erik Schmauss | a9d8ea7 | 2017-06-05 16:41:55 +0800 | [diff] [blame] | 597 | #ifdef ACPI_ASL_COMPILER |
| 598 | /* |
| 599 | * If this ACPI name already exists within the namespace as an |
| 600 | * external declaration, then mark the external as a conflicting |
| 601 | * declaration and proceed to process the current node as if it did |
| 602 | * not exist in the namespace. If this node is not processed as |
| 603 | * normal, then it could cause improper namespace resolution |
| 604 | * by failing to open a new scope. |
| 605 | */ |
| 606 | if (acpi_gbl_disasm_flag && |
| 607 | (status == AE_ALREADY_EXISTS) && |
| 608 | ((this_node->flags & ANOBJ_IS_EXTERNAL) || |
| 609 | (walk_state |
| 610 | && walk_state->opcode == AML_EXTERNAL_OP))) { |
| 611 | this_node->flags &= ~ANOBJ_IS_EXTERNAL; |
| 612 | this_node->type = (u8)this_search_type; |
| 613 | if (walk_state->opcode != AML_EXTERNAL_OP) { |
| 614 | acpi_dm_mark_external_conflict |
| 615 | (this_node); |
| 616 | } |
| 617 | break; |
| 618 | } |
| 619 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | |
| 621 | *return_node = this_node; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 622 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | } |
| 624 | |
Bob Moore | 53cf174 | 2008-04-10 19:06:39 +0400 | [diff] [blame] | 625 | /* More segments to follow? */ |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 626 | |
Bob Moore | 53cf174 | 2008-04-10 19:06:39 +0400 | [diff] [blame] | 627 | if (num_segments > 0) { |
| 628 | /* |
| 629 | * If we have an alias to an object that opens a scope (such as a |
Bob Moore | d4913dc | 2009-03-06 10:05:18 +0800 | [diff] [blame] | 630 | * device or processor), we need to dereference the alias here so |
| 631 | * that we can access any children of the original node (via the |
| 632 | * remaining segments). |
Bob Moore | 53cf174 | 2008-04-10 19:06:39 +0400 | [diff] [blame] | 633 | */ |
| 634 | if (this_node->type == ACPI_TYPE_LOCAL_ALIAS) { |
Bob Moore | 5572a98 | 2008-11-13 10:51:49 +0800 | [diff] [blame] | 635 | if (!this_node->object) { |
| 636 | return_ACPI_STATUS(AE_NOT_EXIST); |
| 637 | } |
| 638 | |
Bob Moore | 53cf174 | 2008-04-10 19:06:39 +0400 | [diff] [blame] | 639 | if (acpi_ns_opens_scope |
Bob Moore | d4913dc | 2009-03-06 10:05:18 +0800 | [diff] [blame] | 640 | (((struct acpi_namespace_node *) |
| 641 | this_node->object)->type)) { |
Bob Moore | 53cf174 | 2008-04-10 19:06:39 +0400 | [diff] [blame] | 642 | this_node = |
| 643 | (struct acpi_namespace_node *) |
| 644 | this_node->object; |
| 645 | } |
| 646 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | } |
| 648 | |
Bob Moore | 53cf174 | 2008-04-10 19:06:39 +0400 | [diff] [blame] | 649 | /* Special handling for the last segment (num_segments == 0) */ |
| 650 | |
| 651 | else { |
Erik Schmauss | b43eac6 | 2017-11-17 15:40:21 -0800 | [diff] [blame] | 652 | #ifdef ACPI_ASL_COMPILER |
| 653 | if (!acpi_gbl_disasm_flag |
| 654 | && (this_node->flags & ANOBJ_IS_EXTERNAL)) { |
| 655 | this_node->flags &= ~IMPLICIT_EXTERNAL; |
| 656 | } |
| 657 | #endif |
| 658 | |
Bob Moore | 53cf174 | 2008-04-10 19:06:39 +0400 | [diff] [blame] | 659 | /* |
| 660 | * Sanity typecheck of the target object: |
| 661 | * |
| 662 | * If 1) This is the last segment (num_segments == 0) |
| 663 | * 2) And we are looking for a specific type |
| 664 | * (Not checking for TYPE_ANY) |
| 665 | * 3) Which is not an alias |
| 666 | * 4) Which is not a local type (TYPE_SCOPE) |
| 667 | * 5) And the type of target object is known (not TYPE_ANY) |
| 668 | * 6) And target object does not match what we are looking for |
| 669 | * |
| 670 | * Then we have a type mismatch. Just warn and ignore it. |
| 671 | */ |
| 672 | if ((type_to_check_for != ACPI_TYPE_ANY) && |
| 673 | (type_to_check_for != ACPI_TYPE_LOCAL_ALIAS) && |
| 674 | (type_to_check_for != ACPI_TYPE_LOCAL_METHOD_ALIAS) |
| 675 | && (type_to_check_for != ACPI_TYPE_LOCAL_SCOPE) |
| 676 | && (this_node->type != ACPI_TYPE_ANY) |
| 677 | && (this_node->type != type_to_check_for)) { |
| 678 | |
| 679 | /* Complain about a type mismatch */ |
| 680 | |
| 681 | ACPI_WARNING((AE_INFO, |
| 682 | "NsLookup: Type mismatch on %4.4s (%s), searching for (%s)", |
| 683 | ACPI_CAST_PTR(char, &simple_name), |
| 684 | acpi_ut_get_type_name(this_node-> |
| 685 | type), |
| 686 | acpi_ut_get_type_name |
| 687 | (type_to_check_for))); |
| 688 | } |
| 689 | |
| 690 | /* |
| 691 | * If this is the last name segment and we are not looking for a |
Bob Moore | d4913dc | 2009-03-06 10:05:18 +0800 | [diff] [blame] | 692 | * specific type, but the type of found object is known, use that |
| 693 | * type to (later) see if it opens a scope. |
Bob Moore | 53cf174 | 2008-04-10 19:06:39 +0400 | [diff] [blame] | 694 | */ |
| 695 | if (type == ACPI_TYPE_ANY) { |
| 696 | type = this_node->type; |
| 697 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | /* Point to next name segment and make this node current */ |
| 701 | |
| 702 | path += ACPI_NAME_SIZE; |
| 703 | current_node = this_node; |
| 704 | } |
| 705 | |
Bob Moore | d4913dc | 2009-03-06 10:05:18 +0800 | [diff] [blame] | 706 | /* Always check if we need to open a new scope */ |
| 707 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | if (!(flags & ACPI_NS_DONT_OPEN_SCOPE) && (walk_state)) { |
| 709 | /* |
| 710 | * If entry is a type which opens a scope, push the new scope on the |
| 711 | * scope stack. |
| 712 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 713 | if (acpi_ns_opens_scope(type)) { |
| 714 | status = |
| 715 | acpi_ds_scope_stack_push(this_node, type, |
| 716 | walk_state); |
| 717 | if (ACPI_FAILURE(status)) { |
| 718 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | } |
| 720 | } |
| 721 | } |
| 722 | |
| 723 | *return_node = this_node; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 724 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | } |