nsaccess.c 18.7 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7
/*******************************************************************************
 *
 * Module Name: nsaccess - Top-level functions for accessing ACPI namespace
 *
 ******************************************************************************/

/*
8
 * Copyright (C) 2000 - 2016, Intel Corp.
L
Linus Torvalds 已提交
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions, and the following disclaimer,
 *    without modification.
 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
 *    substantially similar to the "NO WARRANTY" disclaimer below
 *    ("Disclaimer") and any redistribution must be conditioned upon
 *    including a substantially similar Disclaimer requirement for further
 *    binary redistribution.
 * 3. Neither the names of the above-listed copyright holders nor the names
 *    of any contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * Alternatively, this software may be distributed under the terms of the
 * GNU General Public License ("GPL") version 2 as published by the Free
 * Software Foundation.
 *
 * NO WARRANTY
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES.
 */

#include <acpi/acpi.h>
L
Len Brown 已提交
45 46 47 48
#include "accommon.h"
#include "amlcode.h"
#include "acnamesp.h"
#include "acdispat.h"
L
Linus Torvalds 已提交
49 50

#define _COMPONENT          ACPI_NAMESPACE
L
Len Brown 已提交
51
ACPI_MODULE_NAME("nsaccess")
L
Linus Torvalds 已提交
52 53 54 55 56 57 58 59 60 61 62 63 64 65

/*******************************************************************************
 *
 * FUNCTION:    acpi_ns_root_initialize
 *
 * PARAMETERS:  None
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Allocate and initialize the default root named objects
 *
 * MUTEX:       Locks namespace for entire execution
 *
 ******************************************************************************/
L
Len Brown 已提交
66
acpi_status acpi_ns_root_initialize(void)
L
Linus Torvalds 已提交
67
{
L
Len Brown 已提交
68
	acpi_status status;
L
Linus Torvalds 已提交
69
	const struct acpi_predefined_names *init_val = NULL;
L
Len Brown 已提交
70 71 72
	struct acpi_namespace_node *new_node;
	union acpi_operand_object *obj_desc;
	acpi_string val = NULL;
L
Linus Torvalds 已提交
73

B
Bob Moore 已提交
74
	ACPI_FUNCTION_TRACE(ns_root_initialize);
L
Linus Torvalds 已提交
75

L
Len Brown 已提交
76 77 78
	status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
	}

	/*
	 * The global root ptr is initially NULL, so a non-NULL value indicates
	 * that acpi_ns_root_initialize() has already been called; just return.
	 */
	if (acpi_gbl_root_node) {
		status = AE_OK;
		goto unlock_and_exit;
	}

	/*
	 * Tell the rest of the subsystem that the root is initialized
	 * (This is OK because the namespace is locked)
	 */
	acpi_gbl_root_node = &acpi_gbl_root_node_struct;

	/* Enter the pre-defined names in the name table */

L
Len Brown 已提交
98 99
	ACPI_DEBUG_PRINT((ACPI_DB_INFO,
			  "Entering predefined entries into namespace\n"));
L
Linus Torvalds 已提交
100 101

	for (init_val = acpi_gbl_pre_defined_names; init_val->name; init_val++) {
B
Bob Moore 已提交
102

L
Linus Torvalds 已提交
103 104
		/* _OSI is optional for now, will be permanent later */

105
		if (!strcmp(init_val->name, "_OSI")
L
Len Brown 已提交
106
		    && !acpi_gbl_create_osi_method) {
L
Linus Torvalds 已提交
107 108 109
			continue;
		}

110 111 112 113
		status =
		    acpi_ns_lookup(NULL, (char *)init_val->name, init_val->type,
				   ACPI_IMODE_LOAD_PASS2, ACPI_NS_NO_UPSEARCH,
				   NULL, &new_node);
114
		if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
115 116 117
			ACPI_EXCEPTION((AE_INFO, status,
					"Could not create predefined name %s",
					init_val->name));
118
			continue;
L
Linus Torvalds 已提交
119 120 121
		}

		/*
122 123
		 * Name entered successfully. If entry in pre_defined_names[] specifies
		 * an initial value, create the initial value.
L
Linus Torvalds 已提交
124 125
		 */
		if (init_val->val) {
L
Len Brown 已提交
126 127
			status = acpi_os_predefined_override(init_val, &val);
			if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
128 129 130
				ACPI_ERROR((AE_INFO,
					    "Could not override predefined %s",
					    init_val->name));
L
Linus Torvalds 已提交
131 132 133 134 135 136 137 138 139 140
			}

			if (!val) {
				val = init_val->val;
			}

			/*
			 * Entry requests an initial value, allocate a
			 * descriptor for it.
			 */
L
Len Brown 已提交
141 142
			obj_desc =
			    acpi_ut_create_internal_object(init_val->type);
L
Linus Torvalds 已提交
143 144 145 146 147 148 149 150 151 152 153 154
			if (!obj_desc) {
				status = AE_NO_MEMORY;
				goto unlock_and_exit;
			}

			/*
			 * Convert value string from table entry to
			 * internal representation. Only types actually
			 * used for initial values are implemented here.
			 */
			switch (init_val->type) {
			case ACPI_TYPE_METHOD:
155

L
Len Brown 已提交
156 157
				obj_desc->method.param_count =
				    (u8) ACPI_TO_INTEGER(val);
L
Linus Torvalds 已提交
158 159
				obj_desc->common.flags |= AOPOBJ_DATA_VALID;

160
#if defined (ACPI_ASL_COMPILER)
L
Linus Torvalds 已提交
161

162
				/* Save the parameter count for the iASL compiler */
163 164

				new_node->value = obj_desc->method.param_count;
L
Linus Torvalds 已提交
165 166 167
#else
				/* Mark this as a very SPECIAL method */

168 169 170
				obj_desc->method.info_flags =
				    ACPI_METHOD_INTERNAL_ONLY;
				obj_desc->method.dispatch.implementation =
L
Len Brown 已提交
171
				    acpi_ut_osi_implementation;
L
Linus Torvalds 已提交
172 173 174 175 176
#endif
				break;

			case ACPI_TYPE_INTEGER:

L
Len Brown 已提交
177
				obj_desc->integer.value = ACPI_TO_INTEGER(val);
L
Linus Torvalds 已提交
178 179 180 181
				break;

			case ACPI_TYPE_STRING:

182 183
				/* Build an object around the static string */

184
				obj_desc->string.length = (u32)strlen(val);
L
Linus Torvalds 已提交
185 186 187 188 189 190 191
				obj_desc->string.pointer = val;
				obj_desc->common.flags |= AOPOBJ_STATIC_POINTER;
				break;

			case ACPI_TYPE_MUTEX:

				obj_desc->mutex.node = new_node;
L
Len Brown 已提交
192 193
				obj_desc->mutex.sync_level =
				    (u8) (ACPI_TO_INTEGER(val) - 1);
L
Linus Torvalds 已提交
194

195 196 197 198 199 200 201 202 203
				/* Create a mutex */

				status =
				    acpi_os_create_mutex(&obj_desc->mutex.
							 os_mutex);
				if (ACPI_FAILURE(status)) {
					acpi_ut_remove_reference(obj_desc);
					goto unlock_and_exit;
				}
B
Bob Moore 已提交
204

205
				/* Special case for ACPI Global Lock */
L
Linus Torvalds 已提交
206

207
				if (strcmp(init_val->name, "_GL_") == 0) {
208
					acpi_gbl_global_lock_mutex = obj_desc;
B
Bob Moore 已提交
209

210
					/* Create additional counting semaphore for global lock */
L
Linus Torvalds 已提交
211

B
Bob Moore 已提交
212
					status =
213
					    acpi_os_create_semaphore(1, 0,
214
								     &acpi_gbl_global_lock_semaphore);
L
Len Brown 已提交
215 216 217
					if (ACPI_FAILURE(status)) {
						acpi_ut_remove_reference
						    (obj_desc);
L
Linus Torvalds 已提交
218 219 220 221 222 223 224
						goto unlock_and_exit;
					}
				}
				break;

			default:

B
Bob Moore 已提交
225
				ACPI_ERROR((AE_INFO,
226
					    "Unsupported initial type value 0x%X",
B
Bob Moore 已提交
227
					    init_val->type));
L
Len Brown 已提交
228
				acpi_ut_remove_reference(obj_desc);
L
Linus Torvalds 已提交
229 230 231 232 233 234
				obj_desc = NULL;
				continue;
			}

			/* Store pointer to value descriptor in the Node */

L
Len Brown 已提交
235
			status = acpi_ns_attach_object(new_node, obj_desc,
236
						       obj_desc->common.type);
L
Linus Torvalds 已提交
237 238 239

			/* Remove local reference to the object */

L
Len Brown 已提交
240
			acpi_ut_remove_reference(obj_desc);
L
Linus Torvalds 已提交
241 242 243
		}
	}

244
unlock_and_exit:
L
Len Brown 已提交
245
	(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
L
Linus Torvalds 已提交
246 247 248

	/* Save a handle to "_GPE", it is always present */

L
Len Brown 已提交
249
	if (ACPI_SUCCESS(status)) {
B
Bob Moore 已提交
250 251
		status = acpi_ns_get_node(NULL, "\\_GPE", ACPI_NS_NO_UPSEARCH,
					  &acpi_gbl_fadt_gpe_device);
L
Linus Torvalds 已提交
252 253
	}

L
Len Brown 已提交
254
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
255 256 257 258 259 260
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ns_lookup
 *
R
Robert Moore 已提交
261
 * PARAMETERS:  scope_info      - Current scope info block
262
 *              pathname        - Search pathname, in internal format
L
Linus Torvalds 已提交
263
 *                                (as represented in the AML stream)
264
 *              type            - Type associated with name
L
Linus Torvalds 已提交
265
 *              interpreter_mode - IMODE_LOAD_PASS2 => add name if not found
266
 *              flags           - Flags describing the search restrictions
L
Linus Torvalds 已提交
267 268 269 270 271 272 273 274 275 276 277 278 279 280
 *              walk_state      - Current state of the walk
 *              return_node     - Where the Node is placed (if found
 *                                or created successfully)
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Find or enter the passed name in the name space.
 *              Log an error if name not found in Exec mode.
 *
 * MUTEX:       Assumes namespace is locked.
 *
 ******************************************************************************/

acpi_status
L
Len Brown 已提交
281 282 283 284 285 286 287
acpi_ns_lookup(union acpi_generic_state *scope_info,
	       char *pathname,
	       acpi_object_type type,
	       acpi_interpreter_mode interpreter_mode,
	       u32 flags,
	       struct acpi_walk_state *walk_state,
	       struct acpi_namespace_node **return_node)
L
Linus Torvalds 已提交
288
{
L
Len Brown 已提交
289 290 291 292 293 294 295 296 297 298 299
	acpi_status status;
	char *path = pathname;
	struct acpi_namespace_node *prefix_node;
	struct acpi_namespace_node *current_node = NULL;
	struct acpi_namespace_node *this_node = NULL;
	u32 num_segments;
	u32 num_carats;
	acpi_name simple_name;
	acpi_object_type type_to_check_for;
	acpi_object_type this_search_type;
	u32 search_parent_flag = ACPI_NS_SEARCH_PARENT;
B
Bob Moore 已提交
300
	u32 local_flags;
L
Len Brown 已提交
301

B
Bob Moore 已提交
302
	ACPI_FUNCTION_TRACE(ns_lookup);
L
Linus Torvalds 已提交
303 304

	if (!return_node) {
L
Len Brown 已提交
305
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
306 307
	}

308 309 310
	local_flags = flags &
	    ~(ACPI_NS_ERROR_IF_FOUND | ACPI_NS_OVERRIDE_IF_FOUND |
	      ACPI_NS_SEARCH_PARENT);
L
Linus Torvalds 已提交
311
	*return_node = ACPI_ENTRY_NOT_FOUND;
B
Bob Moore 已提交
312
	acpi_gbl_ns_lookup_count++;
L
Linus Torvalds 已提交
313 314

	if (!acpi_gbl_root_node) {
L
Len Brown 已提交
315
		return_ACPI_STATUS(AE_NO_NAMESPACE);
L
Linus Torvalds 已提交
316 317
	}

318 319
	/* Get the prefix scope. A null scope means use the root scope */

L
Len Brown 已提交
320 321 322 323
	if ((!scope_info) || (!scope_info->scope.node)) {
		ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
				  "Null scope prefix, using root node (%p)\n",
				  acpi_gbl_root_node));
L
Linus Torvalds 已提交
324 325

		prefix_node = acpi_gbl_root_node;
L
Len Brown 已提交
326
	} else {
L
Linus Torvalds 已提交
327
		prefix_node = scope_info->scope.node;
L
Len Brown 已提交
328 329
		if (ACPI_GET_DESCRIPTOR_TYPE(prefix_node) !=
		    ACPI_DESC_TYPE_NAMED) {
B
Bob Moore 已提交
330 331 332
			ACPI_ERROR((AE_INFO, "%p is not a namespace node [%s]",
				    prefix_node,
				    acpi_ut_get_descriptor_name(prefix_node)));
L
Len Brown 已提交
333
			return_ACPI_STATUS(AE_AML_INTERNAL);
L
Linus Torvalds 已提交
334 335
		}

B
Bob Moore 已提交
336 337 338
		if (!(flags & ACPI_NS_PREFIX_IS_SCOPE)) {
			/*
			 * This node might not be a actual "scope" node (such as a
339 340
			 * Device/Method, etc.)  It could be a Package or other object
			 * node. Backup up the tree to find the containing scope node.
B
Bob Moore 已提交
341 342 343
			 */
			while (!acpi_ns_opens_scope(prefix_node->type) &&
			       prefix_node->type != ACPI_TYPE_ANY) {
344
				prefix_node = prefix_node->parent;
B
Bob Moore 已提交
345
			}
L
Linus Torvalds 已提交
346 347 348
		}
	}

349
	/* Save type. TBD: may be no longer necessary */
L
Linus Torvalds 已提交
350 351 352 353 354 355 356

	type_to_check_for = type;

	/*
	 * Begin examination of the actual pathname
	 */
	if (!pathname) {
B
Bob Moore 已提交
357

L
Linus Torvalds 已提交
358 359 360
		/* A Null name_path is allowed and refers to the root */

		num_segments = 0;
L
Len Brown 已提交
361 362
		this_node = acpi_gbl_root_node;
		path = "";
L
Linus Torvalds 已提交
363

L
Len Brown 已提交
364 365 366 367
		ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
				  "Null Pathname (Zero segments), Flags=%X\n",
				  flags));
	} else {
L
Linus Torvalds 已提交
368 369 370 371 372 373 374 375 376 377 378 379 380 381
		/*
		 * Name pointer is valid (and must be in internal name format)
		 *
		 * Check for scope prefixes:
		 *
		 * As represented in the AML stream, a namepath consists of an
		 * optional scope prefix followed by a name segment part.
		 *
		 * If present, the scope prefix is either a Root Prefix (in
		 * which case the name is fully qualified), or one or more
		 * Parent Prefixes (in which case the name's scope is relative
		 * to the current scope).
		 */
		if (*path == (u8) AML_ROOT_PREFIX) {
B
Bob Moore 已提交
382

L
Linus Torvalds 已提交
383 384 385 386 387 388 389 390 391
			/* Pathname is fully qualified, start from the root */

			this_node = acpi_gbl_root_node;
			search_parent_flag = ACPI_NS_NO_UPSEARCH;

			/* Point to name segment part */

			path++;

L
Len Brown 已提交
392 393 394 395
			ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
					  "Path is absolute from root [%p]\n",
					  this_node));
		} else {
L
Linus Torvalds 已提交
396 397
			/* Pathname is relative to current scope, start there */

L
Len Brown 已提交
398 399 400 401
			ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
					  "Searching relative to prefix scope [%4.4s] (%p)\n",
					  acpi_ut_get_node_name(prefix_node),
					  prefix_node));
L
Linus Torvalds 已提交
402 403 404 405 406 407 408 409

			/*
			 * Handle multiple Parent Prefixes (carat) by just getting
			 * the parent node for each prefix instance.
			 */
			this_node = prefix_node;
			num_carats = 0;
			while (*path == (u8) AML_PARENT_PREFIX) {
B
Bob Moore 已提交
410

L
Linus Torvalds 已提交
411 412 413
				/* Name is fully qualified, no search rules apply */

				search_parent_flag = ACPI_NS_NO_UPSEARCH;
414

L
Linus Torvalds 已提交
415 416 417 418 419 420 421 422 423
				/*
				 * Point past this prefix to the name segment
				 * part or the next Parent Prefix
				 */
				path++;

				/* Backup to the parent node */

				num_carats++;
424
				this_node = this_node->parent;
L
Linus Torvalds 已提交
425
				if (!this_node) {
B
Bob Moore 已提交
426

L
Linus Torvalds 已提交
427 428
					/* Current scope has no parent scope */

B
Bob Moore 已提交
429
					ACPI_ERROR((AE_INFO,
430 431 432
						    "%s: Path has too many parent prefixes (^) "
						    "- reached beyond root node",
						    pathname));
L
Len Brown 已提交
433
					return_ACPI_STATUS(AE_NOT_FOUND);
L
Linus Torvalds 已提交
434 435 436 437
				}
			}

			if (search_parent_flag == ACPI_NS_NO_UPSEARCH) {
L
Len Brown 已提交
438
				ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
439
						  "Search scope is [%4.4s], path has %u carat(s)\n",
L
Len Brown 已提交
440 441
						  acpi_ut_get_node_name
						  (this_node), num_carats));
L
Linus Torvalds 已提交
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466
			}
		}

		/*
		 * Determine the number of ACPI name segments in this pathname.
		 *
		 * The segment part consists of either:
		 *  - A Null name segment (0)
		 *  - A dual_name_prefix followed by two 4-byte name segments
		 *  - A multi_name_prefix followed by a byte indicating the
		 *      number of segments and the segments themselves.
		 *  - A single 4-byte name segment
		 *
		 * Examine the name prefix opcode, if any, to determine the number of
		 * segments.
		 */
		switch (*path) {
		case 0:
			/*
			 * Null name after a root or parent prefixes. We already
			 * have the correct target node and there are no name segments.
			 */
			num_segments = 0;
			type = this_node->type;

L
Len Brown 已提交
467 468 469
			ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
					  "Prefix-only Pathname (Zero name segments), Flags=%X\n",
					  flags));
L
Linus Torvalds 已提交
470 471 472 473 474 475 476 477 478 479 480 481 482
			break;

		case AML_DUAL_NAME_PREFIX:

			/* More than one name_seg, search rules do not apply */

			search_parent_flag = ACPI_NS_NO_UPSEARCH;

			/* Two segments, point to first name segment */

			num_segments = 2;
			path++;

L
Len Brown 已提交
483 484 485
			ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
					  "Dual Pathname (2 segments, Flags=%X)\n",
					  flags));
L
Linus Torvalds 已提交
486 487 488 489 490 491 492 493 494 495 496
			break;

		case AML_MULTI_NAME_PREFIX_OP:

			/* More than one name_seg, search rules do not apply */

			search_parent_flag = ACPI_NS_NO_UPSEARCH;

			/* Extract segment count, point to first name segment */

			path++;
L
Len Brown 已提交
497
			num_segments = (u32) (u8) * path;
L
Linus Torvalds 已提交
498 499
			path++;

L
Len Brown 已提交
500
			ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
501
					  "Multi Pathname (%u Segments, Flags=%X)\n",
L
Len Brown 已提交
502
					  num_segments, flags));
L
Linus Torvalds 已提交
503 504 505 506 507 508 509 510 511
			break;

		default:
			/*
			 * Not a Null name, no Dual or Multi prefix, hence there is
			 * only one name segment and Pathname is already pointing to it.
			 */
			num_segments = 1;

L
Len Brown 已提交
512 513 514
			ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
					  "Simple Pathname (1 segment, Flags=%X)\n",
					  flags));
L
Linus Torvalds 已提交
515 516 517
			break;
		}

L
Len Brown 已提交
518
		ACPI_DEBUG_EXEC(acpi_ns_print_pathname(num_segments, path));
L
Linus Torvalds 已提交
519 520 521
	}

	/*
522
	 * Search namespace for each segment of the name. Loop through and
L
Linus Torvalds 已提交
523 524 525
	 * verify (or add to the namespace) each name segment.
	 *
	 * The object type is significant only at the last name
526
	 * segment. (We don't care about the types along the path, only
L
Linus Torvalds 已提交
527 528 529 530 531 532 533
	 * the type of the final target object.)
	 */
	this_search_type = ACPI_TYPE_ANY;
	current_node = this_node;
	while (num_segments && current_node) {
		num_segments--;
		if (!num_segments) {
534 535 536

			/* This is the last segment, enable typechecking */

L
Linus Torvalds 已提交
537 538 539 540 541 542 543
			this_search_type = type;

			/*
			 * Only allow automatic parent search (search rules) if the caller
			 * requested it AND we have a single, non-fully-qualified name_seg
			 */
			if ((search_parent_flag != ACPI_NS_NO_UPSEARCH) &&
L
Len Brown 已提交
544
			    (flags & ACPI_NS_SEARCH_PARENT)) {
L
Linus Torvalds 已提交
545 546 547 548 549 550 551 552
				local_flags |= ACPI_NS_SEARCH_PARENT;
			}

			/* Set error flag according to caller */

			if (flags & ACPI_NS_ERROR_IF_FOUND) {
				local_flags |= ACPI_NS_ERROR_IF_FOUND;
			}
553 554 555 556 557 558

			/* Set override flag according to caller */

			if (flags & ACPI_NS_OVERRIDE_IF_FOUND) {
				local_flags |= ACPI_NS_OVERRIDE_IF_FOUND;
			}
L
Linus Torvalds 已提交
559 560 561 562
		}

		/* Extract one ACPI name from the front of the pathname */

L
Len Brown 已提交
563
		ACPI_MOVE_32_TO_32(&simple_name, path);
L
Linus Torvalds 已提交
564 565 566

		/* Try to find the single (4 character) ACPI name */

L
Len Brown 已提交
567 568 569 570 571 572
		status =
		    acpi_ns_search_and_enter(simple_name, walk_state,
					     current_node, interpreter_mode,
					     this_search_type, local_flags,
					     &this_node);
		if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
573
			if (status == AE_NOT_FOUND) {
B
Bob Moore 已提交
574

L
Linus Torvalds 已提交
575 576
				/* Name not found in ACPI namespace */

L
Len Brown 已提交
577 578 579 580 581
				ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
						  "Name [%4.4s] not found in scope [%4.4s] %p\n",
						  (char *)&simple_name,
						  (char *)&current_node->name,
						  current_node));
L
Linus Torvalds 已提交
582 583 584
			}

			*return_node = this_node;
L
Len Brown 已提交
585
			return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
586 587
		}

588 589 590 591 592
		/* More segments to follow? */

		if (num_segments > 0) {
			/*
			 * If we have an alias to an object that opens a scope (such as a
593 594 595
			 * device or processor), we need to dereference the alias here so
			 * that we can access any children of the original node (via the
			 * remaining segments).
596 597
			 */
			if (this_node->type == ACPI_TYPE_LOCAL_ALIAS) {
598 599 600 601
				if (!this_node->object) {
					return_ACPI_STATUS(AE_NOT_EXIST);
				}

602
				if (acpi_ns_opens_scope
603 604
				    (((struct acpi_namespace_node *)
				      this_node->object)->type)) {
605 606 607 608 609
					this_node =
					    (struct acpi_namespace_node *)
					    this_node->object;
				}
			}
L
Linus Torvalds 已提交
610 611
		}

612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647
		/* Special handling for the last segment (num_segments == 0) */

		else {
			/*
			 * Sanity typecheck of the target object:
			 *
			 * If 1) This is the last segment (num_segments == 0)
			 *    2) And we are looking for a specific type
			 *       (Not checking for TYPE_ANY)
			 *    3) Which is not an alias
			 *    4) Which is not a local type (TYPE_SCOPE)
			 *    5) And the type of target object is known (not TYPE_ANY)
			 *    6) And target object does not match what we are looking for
			 *
			 * Then we have a type mismatch. Just warn and ignore it.
			 */
			if ((type_to_check_for != ACPI_TYPE_ANY) &&
			    (type_to_check_for != ACPI_TYPE_LOCAL_ALIAS) &&
			    (type_to_check_for != ACPI_TYPE_LOCAL_METHOD_ALIAS)
			    && (type_to_check_for != ACPI_TYPE_LOCAL_SCOPE)
			    && (this_node->type != ACPI_TYPE_ANY)
			    && (this_node->type != type_to_check_for)) {

				/* Complain about a type mismatch */

				ACPI_WARNING((AE_INFO,
					      "NsLookup: Type mismatch on %4.4s (%s), searching for (%s)",
					      ACPI_CAST_PTR(char, &simple_name),
					      acpi_ut_get_type_name(this_node->
								    type),
					      acpi_ut_get_type_name
					      (type_to_check_for)));
			}

			/*
			 * If this is the last name segment and we are not looking for a
648 649
			 * specific type, but the type of found object is known, use that
			 * type to (later) see if it opens a scope.
650 651 652 653
			 */
			if (type == ACPI_TYPE_ANY) {
				type = this_node->type;
			}
L
Linus Torvalds 已提交
654 655 656 657 658 659 660 661
		}

		/* Point to next name segment and make this node current */

		path += ACPI_NAME_SIZE;
		current_node = this_node;
	}

662 663
	/* Always check if we need to open a new scope */

L
Linus Torvalds 已提交
664 665 666 667 668
	if (!(flags & ACPI_NS_DONT_OPEN_SCOPE) && (walk_state)) {
		/*
		 * If entry is a type which opens a scope, push the new scope on the
		 * scope stack.
		 */
L
Len Brown 已提交
669 670 671 672 673 674
		if (acpi_ns_opens_scope(type)) {
			status =
			    acpi_ds_scope_stack_push(this_node, type,
						     walk_state);
			if (ACPI_FAILURE(status)) {
				return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
675 676 677 678 679
			}
		}
	}

	*return_node = this_node;
L
Len Brown 已提交
680
	return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
681
}