blob: e5f4fa496572859ec507a859242be913c36884d1 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*******************************************************************************
2 *
3 * Module Name: nsaccess - Top-level functions for accessing ACPI namespace
4 *
5 ******************************************************************************/
6
7/*
Bob Moore7735ca02017-02-08 11:00:08 +08008 * Copyright (C) 2000 - 2017, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * 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 Torvalds1da177e2005-04-16 15:20:36 -070044#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050045#include "accommon.h"
46#include "amlcode.h"
47#include "acnamesp.h"
48#include "acdispat.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Erik Schmaussa9d8ea72017-06-05 16:41:55 +080050#ifdef ACPI_ASL_COMPILER
51#include "acdisasm.h"
52#endif
53
Linus Torvalds1da177e2005-04-16 15:20:36 -070054#define _COMPONENT ACPI_NAMESPACE
Len Brown4be44fc2005-08-05 00:44:28 -040055ACPI_MODULE_NAME("nsaccess")
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
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 Brown4be44fc2005-08-05 00:44:28 -040070acpi_status acpi_ns_root_initialize(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070071{
Len Brown4be44fc2005-08-05 00:44:28 -040072 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 const struct acpi_predefined_names *init_val = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -040074 struct acpi_namespace_node *new_node;
75 union acpi_operand_object *obj_desc;
76 acpi_string val = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
Bob Mooreb229cf92006-04-21 17:15:00 -040078 ACPI_FUNCTION_TRACE(ns_root_initialize);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
Len Brown4be44fc2005-08-05 00:44:28 -040080 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
81 if (ACPI_FAILURE(status)) {
82 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 }
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 Brown4be44fc2005-08-05 00:44:28 -0400102 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
103 "Entering predefined entries into namespace\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
105 for (init_val = acpi_gbl_pre_defined_names; init_val->name; init_val++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 /* _OSI is optional for now, will be permanent later */
108
Bob Moore4fa46162015-07-01 14:45:11 +0800109 if (!strcmp(init_val->name, "_OSI")
Len Brown4be44fc2005-08-05 00:44:28 -0400110 && !acpi_gbl_create_osi_method) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 continue;
112 }
113
Bob Moore0dfaaa32016-03-24 09:40:40 +0800114 status =
Jung-uk Kimfee4ab92016-08-04 16:42:34 +0800115 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 Moore267d6722012-10-31 02:26:36 +0000118 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500119 ACPI_EXCEPTION((AE_INFO, status,
120 "Could not create predefined name %s",
121 init_val->name));
Robert Moore267d6722012-10-31 02:26:36 +0000122 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 }
124
125 /*
Bob Moored4913dc2009-03-06 10:05:18 +0800126 * Name entered successfully. If entry in pre_defined_names[] specifies
127 * an initial value, create the initial value.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 */
129 if (init_val->val) {
Len Brown4be44fc2005-08-05 00:44:28 -0400130 status = acpi_os_predefined_override(init_val, &val);
131 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500132 ACPI_ERROR((AE_INFO,
133 "Could not override predefined %s",
134 init_val->name));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 }
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 Brown4be44fc2005-08-05 00:44:28 -0400145 obj_desc =
146 acpi_ut_create_internal_object(init_val->type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 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 Guan1d1ea1b2013-06-08 00:58:14 +0000159
Len Brown4be44fc2005-08-05 00:44:28 -0400160 obj_desc->method.param_count =
161 (u8) ACPI_TO_INTEGER(val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 obj_desc->common.flags |= AOPOBJ_DATA_VALID;
163
Robert Moore0c9938c2005-07-29 15:15:00 -0700164#if defined (ACPI_ASL_COMPILER)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
Bob Mooreba494be2012-07-12 09:40:10 +0800166 /* Save the parameter count for the iASL compiler */
Robert Moore0c9938c2005-07-29 15:15:00 -0700167
168 new_node->value = obj_desc->method.param_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169#else
170 /* Mark this as a very SPECIAL method */
171
Lin Ming26294842011-01-12 09:19:43 +0800172 obj_desc->method.info_flags =
173 ACPI_METHOD_INTERNAL_ONLY;
174 obj_desc->method.dispatch.implementation =
Len Brown4be44fc2005-08-05 00:44:28 -0400175 acpi_ut_osi_implementation;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176#endif
177 break;
178
179 case ACPI_TYPE_INTEGER:
180
Len Brown4be44fc2005-08-05 00:44:28 -0400181 obj_desc->integer.value = ACPI_TO_INTEGER(val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 break;
183
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 case ACPI_TYPE_STRING:
185
Bob Moored4913dc2009-03-06 10:05:18 +0800186 /* Build an object around the static string */
187
Bob Moore4fa46162015-07-01 14:45:11 +0800188 obj_desc->string.length = (u32)strlen(val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 obj_desc->string.pointer = val;
190 obj_desc->common.flags |= AOPOBJ_STATIC_POINTER;
191 break;
192
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 case ACPI_TYPE_MUTEX:
194
195 obj_desc->mutex.node = new_node;
Len Brown4be44fc2005-08-05 00:44:28 -0400196 obj_desc->mutex.sync_level =
197 (u8) (ACPI_TO_INTEGER(val) - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
Bob Moorec81da662007-02-02 19:48:18 +0300199 /* 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 Moore4fa46162015-07-01 14:45:11 +0800211 if (strcmp(init_val->name, "_GL_") == 0) {
Bob Mooreba886cd2008-04-10 19:06:37 +0400212 acpi_gbl_global_lock_mutex = obj_desc;
Bob Moore967440e32006-06-23 17:04:00 -0400213
Bob Moorec81da662007-02-02 19:48:18 +0300214 /* Create additional counting semaphore for global lock */
Bob Moore967440e32006-06-23 17:04:00 -0400215
Len Brown4be44fc2005-08-05 00:44:28 -0400216 status =
Bob Moore73ca0fb2007-02-02 19:48:21 +0300217 acpi_os_create_semaphore(1, 0,
Bob Moorec81da662007-02-02 19:48:18 +0300218 &acpi_gbl_global_lock_semaphore);
Len Brown4be44fc2005-08-05 00:44:28 -0400219 if (ACPI_FAILURE(status)) {
220 acpi_ut_remove_reference
221 (obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 goto unlock_and_exit;
223 }
224 }
225 break;
226
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 default:
228
Bob Mooreb8e4d892006-01-27 16:43:00 -0500229 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800230 "Unsupported initial type value 0x%X",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500231 init_val->type));
Len Brown4be44fc2005-08-05 00:44:28 -0400232 acpi_ut_remove_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 obj_desc = NULL;
234 continue;
235 }
236
237 /* Store pointer to value descriptor in the Node */
238
Len Brown4be44fc2005-08-05 00:44:28 -0400239 status = acpi_ns_attach_object(new_node, obj_desc,
Bob Moore3371c192009-02-18 14:44:03 +0800240 obj_desc->common.type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241
242 /* Remove local reference to the object */
243
Len Brown4be44fc2005-08-05 00:44:28 -0400244 acpi_ut_remove_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 }
246 }
247
Lv Zheng10622bf2013-10-29 09:30:02 +0800248unlock_and_exit:
Len Brown4be44fc2005-08-05 00:44:28 -0400249 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250
251 /* Save a handle to "_GPE", it is always present */
252
Len Brown4be44fc2005-08-05 00:44:28 -0400253 if (ACPI_SUCCESS(status)) {
Bob Moore41195322006-05-26 16:36:00 -0400254 status = acpi_ns_get_node(NULL, "\\_GPE", ACPI_NS_NO_UPSEARCH,
255 &acpi_gbl_fadt_gpe_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 }
257
Len Brown4be44fc2005-08-05 00:44:28 -0400258 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259}
260
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261/*******************************************************************************
262 *
263 * FUNCTION: acpi_ns_lookup
264 *
Robert Moore44f6c012005-04-18 22:49:35 -0400265 * PARAMETERS: scope_info - Current scope info block
Bob Mooreba494be2012-07-12 09:40:10 +0800266 * pathname - Search pathname, in internal format
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 * (as represented in the AML stream)
Bob Mooreba494be2012-07-12 09:40:10 +0800268 * type - Type associated with name
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 * interpreter_mode - IMODE_LOAD_PASS2 => add name if not found
Bob Mooreba494be2012-07-12 09:40:10 +0800270 * flags - Flags describing the search restrictions
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 * 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
284acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400285acpi_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 Torvalds1da177e2005-04-16 15:20:36 -0700292{
Len Brown4be44fc2005-08-05 00:44:28 -0400293 acpi_status status;
294 char *path = pathname;
295 struct acpi_namespace_node *prefix_node;
296 struct acpi_namespace_node *current_node = NULL;
297 struct acpi_namespace_node *this_node = NULL;
298 u32 num_segments;
299 u32 num_carats;
300 acpi_name simple_name;
301 acpi_object_type type_to_check_for;
302 acpi_object_type this_search_type;
303 u32 search_parent_flag = ACPI_NS_SEARCH_PARENT;
Bob Moore958dd242006-05-12 17:12:00 -0400304 u32 local_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
Bob Mooreb229cf92006-04-21 17:15:00 -0400306 ACPI_FUNCTION_TRACE(ns_lookup);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
308 if (!return_node) {
Len Brown4be44fc2005-08-05 00:44:28 -0400309 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 }
311
Lv Zheng8f6f0362015-07-01 14:44:17 +0800312 local_flags = flags &
313 ~(ACPI_NS_ERROR_IF_FOUND | ACPI_NS_OVERRIDE_IF_FOUND |
314 ACPI_NS_SEARCH_PARENT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 *return_node = ACPI_ENTRY_NOT_FOUND;
Bob Moore958dd242006-05-12 17:12:00 -0400316 acpi_gbl_ns_lookup_count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317
318 if (!acpi_gbl_root_node) {
Len Brown4be44fc2005-08-05 00:44:28 -0400319 return_ACPI_STATUS(AE_NO_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 }
321
Bob Moored4913dc2009-03-06 10:05:18 +0800322 /* Get the prefix scope. A null scope means use the root scope */
323
Len Brown4be44fc2005-08-05 00:44:28 -0400324 if ((!scope_info) || (!scope_info->scope.node)) {
325 ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
326 "Null scope prefix, using root node (%p)\n",
327 acpi_gbl_root_node));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
329 prefix_node = acpi_gbl_root_node;
Len Brown4be44fc2005-08-05 00:44:28 -0400330 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 prefix_node = scope_info->scope.node;
Len Brown4be44fc2005-08-05 00:44:28 -0400332 if (ACPI_GET_DESCRIPTOR_TYPE(prefix_node) !=
333 ACPI_DESC_TYPE_NAMED) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500334 ACPI_ERROR((AE_INFO, "%p is not a namespace node [%s]",
335 prefix_node,
336 acpi_ut_get_descriptor_name(prefix_node)));
Len Brown4be44fc2005-08-05 00:44:28 -0400337 return_ACPI_STATUS(AE_AML_INTERNAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 }
339
Bob Moore83135242006-10-03 00:00:00 -0400340 if (!(flags & ACPI_NS_PREFIX_IS_SCOPE)) {
341 /*
342 * This node might not be a actual "scope" node (such as a
Bob Moored4913dc2009-03-06 10:05:18 +0800343 * Device/Method, etc.) It could be a Package or other object
344 * node. Backup up the tree to find the containing scope node.
Bob Moore83135242006-10-03 00:00:00 -0400345 */
346 while (!acpi_ns_opens_scope(prefix_node->type) &&
347 prefix_node->type != ACPI_TYPE_ANY) {
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +0800348 prefix_node = prefix_node->parent;
Bob Moore83135242006-10-03 00:00:00 -0400349 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 }
351 }
352
Bob Moored4913dc2009-03-06 10:05:18 +0800353 /* Save type. TBD: may be no longer necessary */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
355 type_to_check_for = type;
356
357 /*
358 * Begin examination of the actual pathname
359 */
360 if (!pathname) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400361
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 /* A Null name_path is allowed and refers to the root */
363
364 num_segments = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400365 this_node = acpi_gbl_root_node;
366 path = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
Len Brown4be44fc2005-08-05 00:44:28 -0400368 ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
369 "Null Pathname (Zero segments), Flags=%X\n",
370 flags));
371 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 /*
373 * Name pointer is valid (and must be in internal name format)
374 *
375 * Check for scope prefixes:
376 *
377 * As represented in the AML stream, a namepath consists of an
378 * optional scope prefix followed by a name segment part.
379 *
380 * If present, the scope prefix is either a Root Prefix (in
381 * which case the name is fully qualified), or one or more
382 * Parent Prefixes (in which case the name's scope is relative
383 * to the current scope).
384 */
385 if (*path == (u8) AML_ROOT_PREFIX) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400386
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 /* Pathname is fully qualified, start from the root */
388
389 this_node = acpi_gbl_root_node;
390 search_parent_flag = ACPI_NS_NO_UPSEARCH;
391
392 /* Point to name segment part */
393
394 path++;
395
Len Brown4be44fc2005-08-05 00:44:28 -0400396 ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
397 "Path is absolute from root [%p]\n",
398 this_node));
399 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 /* Pathname is relative to current scope, start there */
401
Len Brown4be44fc2005-08-05 00:44:28 -0400402 ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
403 "Searching relative to prefix scope [%4.4s] (%p)\n",
404 acpi_ut_get_node_name(prefix_node),
405 prefix_node));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
407 /*
408 * Handle multiple Parent Prefixes (carat) by just getting
409 * the parent node for each prefix instance.
410 */
411 this_node = prefix_node;
412 num_carats = 0;
413 while (*path == (u8) AML_PARENT_PREFIX) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400414
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 /* Name is fully qualified, no search rules apply */
416
417 search_parent_flag = ACPI_NS_NO_UPSEARCH;
Bob Moored4913dc2009-03-06 10:05:18 +0800418
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 /*
420 * Point past this prefix to the name segment
421 * part or the next Parent Prefix
422 */
423 path++;
424
425 /* Backup to the parent node */
426
427 num_carats++;
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +0800428 this_node = this_node->parent;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 if (!this_node) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400430
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 /* Current scope has no parent scope */
432
Bob Mooreb8e4d892006-01-27 16:43:00 -0500433 ACPI_ERROR((AE_INFO,
Bob Mooref28eb9f2013-09-23 09:51:13 +0800434 "%s: Path has too many parent prefixes (^) "
435 "- reached beyond root node",
436 pathname));
Len Brown4be44fc2005-08-05 00:44:28 -0400437 return_ACPI_STATUS(AE_NOT_FOUND);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 }
439 }
440
441 if (search_parent_flag == ACPI_NS_NO_UPSEARCH) {
Len Brown4be44fc2005-08-05 00:44:28 -0400442 ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
Bob Mooreb27d6592010-05-26 11:47:13 +0800443 "Search scope is [%4.4s], path has %u carat(s)\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400444 acpi_ut_get_node_name
445 (this_node), num_carats));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 }
447 }
448
449 /*
450 * Determine the number of ACPI name segments in this pathname.
451 *
452 * The segment part consists of either:
453 * - A Null name segment (0)
454 * - A dual_name_prefix followed by two 4-byte name segments
455 * - A multi_name_prefix followed by a byte indicating the
456 * number of segments and the segments themselves.
457 * - A single 4-byte name segment
458 *
459 * Examine the name prefix opcode, if any, to determine the number of
460 * segments.
461 */
462 switch (*path) {
463 case 0:
464 /*
465 * Null name after a root or parent prefixes. We already
466 * have the correct target node and there are no name segments.
467 */
468 num_segments = 0;
469 type = this_node->type;
470
Len Brown4be44fc2005-08-05 00:44:28 -0400471 ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
472 "Prefix-only Pathname (Zero name segments), Flags=%X\n",
473 flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 break;
475
476 case AML_DUAL_NAME_PREFIX:
477
478 /* More than one name_seg, search rules do not apply */
479
480 search_parent_flag = ACPI_NS_NO_UPSEARCH;
481
482 /* Two segments, point to first name segment */
483
484 num_segments = 2;
485 path++;
486
Len Brown4be44fc2005-08-05 00:44:28 -0400487 ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
488 "Dual Pathname (2 segments, Flags=%X)\n",
489 flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 break;
491
Bob Moore9ff5a21a2017-04-26 16:18:40 +0800492 case AML_MULTI_NAME_PREFIX:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493
494 /* More than one name_seg, search rules do not apply */
495
496 search_parent_flag = ACPI_NS_NO_UPSEARCH;
497
498 /* Extract segment count, point to first name segment */
499
500 path++;
Len Brown4be44fc2005-08-05 00:44:28 -0400501 num_segments = (u32) (u8) * path;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 path++;
503
Len Brown4be44fc2005-08-05 00:44:28 -0400504 ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
Bob Mooreb27d6592010-05-26 11:47:13 +0800505 "Multi Pathname (%u Segments, Flags=%X)\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400506 num_segments, flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 break;
508
509 default:
510 /*
511 * Not a Null name, no Dual or Multi prefix, hence there is
512 * only one name segment and Pathname is already pointing to it.
513 */
514 num_segments = 1;
515
Len Brown4be44fc2005-08-05 00:44:28 -0400516 ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
517 "Simple Pathname (1 segment, Flags=%X)\n",
518 flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 break;
520 }
521
Len Brown4be44fc2005-08-05 00:44:28 -0400522 ACPI_DEBUG_EXEC(acpi_ns_print_pathname(num_segments, path));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 }
524
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 /*
Bob Moore319f8b82008-11-13 10:48:00 +0800526 * Search namespace for each segment of the name. Loop through and
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 * verify (or add to the namespace) each name segment.
528 *
529 * The object type is significant only at the last name
Bob Moore319f8b82008-11-13 10:48:00 +0800530 * segment. (We don't care about the types along the path, only
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 * the type of the final target object.)
532 */
533 this_search_type = ACPI_TYPE_ANY;
534 current_node = this_node;
535 while (num_segments && current_node) {
536 num_segments--;
537 if (!num_segments) {
Bob Moored4913dc2009-03-06 10:05:18 +0800538
539 /* This is the last segment, enable typechecking */
540
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 this_search_type = type;
542
543 /*
544 * Only allow automatic parent search (search rules) if the caller
545 * requested it AND we have a single, non-fully-qualified name_seg
546 */
547 if ((search_parent_flag != ACPI_NS_NO_UPSEARCH) &&
Len Brown4be44fc2005-08-05 00:44:28 -0400548 (flags & ACPI_NS_SEARCH_PARENT)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 local_flags |= ACPI_NS_SEARCH_PARENT;
550 }
551
552 /* Set error flag according to caller */
553
554 if (flags & ACPI_NS_ERROR_IF_FOUND) {
555 local_flags |= ACPI_NS_ERROR_IF_FOUND;
556 }
Lv Zheng8f6f0362015-07-01 14:44:17 +0800557
558 /* Set override flag according to caller */
559
560 if (flags & ACPI_NS_OVERRIDE_IF_FOUND) {
561 local_flags |= ACPI_NS_OVERRIDE_IF_FOUND;
562 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 }
564
565 /* Extract one ACPI name from the front of the pathname */
566
Len Brown4be44fc2005-08-05 00:44:28 -0400567 ACPI_MOVE_32_TO_32(&simple_name, path);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568
569 /* Try to find the single (4 character) ACPI name */
570
Len Brown4be44fc2005-08-05 00:44:28 -0400571 status =
572 acpi_ns_search_and_enter(simple_name, walk_state,
573 current_node, interpreter_mode,
574 this_search_type, local_flags,
575 &this_node);
576 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 if (status == AE_NOT_FOUND) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400578
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 /* Name not found in ACPI namespace */
580
Len Brown4be44fc2005-08-05 00:44:28 -0400581 ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
582 "Name [%4.4s] not found in scope [%4.4s] %p\n",
583 (char *)&simple_name,
584 (char *)&current_node->name,
585 current_node));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 }
Erik Schmaussa9d8ea72017-06-05 16:41:55 +0800587#ifdef ACPI_ASL_COMPILER
588 /*
589 * If this ACPI name already exists within the namespace as an
590 * external declaration, then mark the external as a conflicting
591 * declaration and proceed to process the current node as if it did
592 * not exist in the namespace. If this node is not processed as
593 * normal, then it could cause improper namespace resolution
594 * by failing to open a new scope.
595 */
596 if (acpi_gbl_disasm_flag &&
597 (status == AE_ALREADY_EXISTS) &&
598 ((this_node->flags & ANOBJ_IS_EXTERNAL) ||
599 (walk_state
600 && walk_state->opcode == AML_EXTERNAL_OP))) {
601 this_node->flags &= ~ANOBJ_IS_EXTERNAL;
602 this_node->type = (u8)this_search_type;
603 if (walk_state->opcode != AML_EXTERNAL_OP) {
604 acpi_dm_mark_external_conflict
605 (this_node);
606 }
607 break;
608 }
609#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610
611 *return_node = this_node;
Len Brown4be44fc2005-08-05 00:44:28 -0400612 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 }
614
Bob Moore53cf1742008-04-10 19:06:39 +0400615 /* More segments to follow? */
Bob Moore52fc0b02006-10-02 00:00:00 -0400616
Bob Moore53cf1742008-04-10 19:06:39 +0400617 if (num_segments > 0) {
618 /*
619 * If we have an alias to an object that opens a scope (such as a
Bob Moored4913dc2009-03-06 10:05:18 +0800620 * device or processor), we need to dereference the alias here so
621 * that we can access any children of the original node (via the
622 * remaining segments).
Bob Moore53cf1742008-04-10 19:06:39 +0400623 */
624 if (this_node->type == ACPI_TYPE_LOCAL_ALIAS) {
Bob Moore5572a982008-11-13 10:51:49 +0800625 if (!this_node->object) {
626 return_ACPI_STATUS(AE_NOT_EXIST);
627 }
628
Bob Moore53cf1742008-04-10 19:06:39 +0400629 if (acpi_ns_opens_scope
Bob Moored4913dc2009-03-06 10:05:18 +0800630 (((struct acpi_namespace_node *)
631 this_node->object)->type)) {
Bob Moore53cf1742008-04-10 19:06:39 +0400632 this_node =
633 (struct acpi_namespace_node *)
634 this_node->object;
635 }
636 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 }
638
Bob Moore53cf1742008-04-10 19:06:39 +0400639 /* Special handling for the last segment (num_segments == 0) */
640
641 else {
642 /*
643 * Sanity typecheck of the target object:
644 *
645 * If 1) This is the last segment (num_segments == 0)
646 * 2) And we are looking for a specific type
647 * (Not checking for TYPE_ANY)
648 * 3) Which is not an alias
649 * 4) Which is not a local type (TYPE_SCOPE)
650 * 5) And the type of target object is known (not TYPE_ANY)
651 * 6) And target object does not match what we are looking for
652 *
653 * Then we have a type mismatch. Just warn and ignore it.
654 */
655 if ((type_to_check_for != ACPI_TYPE_ANY) &&
656 (type_to_check_for != ACPI_TYPE_LOCAL_ALIAS) &&
657 (type_to_check_for != ACPI_TYPE_LOCAL_METHOD_ALIAS)
658 && (type_to_check_for != ACPI_TYPE_LOCAL_SCOPE)
659 && (this_node->type != ACPI_TYPE_ANY)
660 && (this_node->type != type_to_check_for)) {
661
662 /* Complain about a type mismatch */
663
664 ACPI_WARNING((AE_INFO,
665 "NsLookup: Type mismatch on %4.4s (%s), searching for (%s)",
666 ACPI_CAST_PTR(char, &simple_name),
667 acpi_ut_get_type_name(this_node->
668 type),
669 acpi_ut_get_type_name
670 (type_to_check_for)));
671 }
672
673 /*
674 * If this is the last name segment and we are not looking for a
Bob Moored4913dc2009-03-06 10:05:18 +0800675 * specific type, but the type of found object is known, use that
676 * type to (later) see if it opens a scope.
Bob Moore53cf1742008-04-10 19:06:39 +0400677 */
678 if (type == ACPI_TYPE_ANY) {
679 type = this_node->type;
680 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 }
682
683 /* Point to next name segment and make this node current */
684
685 path += ACPI_NAME_SIZE;
686 current_node = this_node;
687 }
688
Bob Moored4913dc2009-03-06 10:05:18 +0800689 /* Always check if we need to open a new scope */
690
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 if (!(flags & ACPI_NS_DONT_OPEN_SCOPE) && (walk_state)) {
692 /*
693 * If entry is a type which opens a scope, push the new scope on the
694 * scope stack.
695 */
Len Brown4be44fc2005-08-05 00:44:28 -0400696 if (acpi_ns_opens_scope(type)) {
697 status =
698 acpi_ds_scope_stack_push(this_node, type,
699 walk_state);
700 if (ACPI_FAILURE(status)) {
701 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 }
703 }
704 }
705
706 *return_node = this_node;
Len Brown4be44fc2005-08-05 00:44:28 -0400707 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708}