1 /*******************************************************************************
3 * Module Name: nsaccess - Top-level functions for accessing ACPI namespace
6 ******************************************************************************/
9 * Copyright (C) 2000, 2001 R. Byron Moore
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 #define _COMPONENT ACPI_NAMESPACE
35 MODULE_NAME ("nsaccess")
38 /*******************************************************************************
40 * FUNCTION: Acpi_ns_root_initialize
46 * DESCRIPTION: Allocate and initialize the default root named objects
48 * MUTEX: Locks namespace for entire execution
50 ******************************************************************************/
53 acpi_ns_root_initialize (void)
55 ACPI_STATUS status = AE_OK;
56 PREDEFINED_NAMES *init_val = NULL;
57 ACPI_NAMESPACE_NODE *new_node;
58 ACPI_OPERAND_OBJECT *obj_desc;
61 acpi_cm_acquire_mutex (ACPI_MTX_NAMESPACE);
64 * The global root ptr is initially NULL, so a non-NULL value indicates
65 * that Acpi_ns_root_initialize() has already been called; just return.
68 if (acpi_gbl_root_node) {
75 * Tell the rest of the subsystem that the root is initialized
76 * (This is OK because the namespace is locked)
79 acpi_gbl_root_node = &acpi_gbl_root_node_struct;
82 /* Enter the pre-defined names in the name table */
84 for (init_val = acpi_gbl_pre_defined_names; init_val->name; init_val++) {
85 status = acpi_ns_lookup (NULL, init_val->name,
86 (OBJECT_TYPE_INTERNAL) init_val->type,
87 IMODE_LOAD_PASS2, NS_NO_UPSEARCH,
92 * Name entered successfully.
93 * If entry in Pre_defined_names[] specifies an
94 * initial value, create the initial value.
99 * Entry requests an initial value, allocate a
103 obj_desc = acpi_cm_create_internal_object (
104 (OBJECT_TYPE_INTERNAL) init_val->type);
107 status = AE_NO_MEMORY;
108 goto unlock_and_exit;
112 * Convert value string from table entry to
113 * internal representation. Only types actually
114 * used for initial values are implemented here.
117 switch (init_val->type) {
119 case ACPI_TYPE_INTEGER:
121 obj_desc->integer.value =
122 (ACPI_INTEGER) STRTOUL (init_val->val, NULL, 10);
126 case ACPI_TYPE_STRING:
128 obj_desc->string.length = STRLEN (init_val->val);
131 * Allocate a buffer for the string. All
132 * String.Pointers must be allocated buffers!
133 * (makes deletion simpler)
135 obj_desc->string.pointer = acpi_cm_allocate (
136 (obj_desc->string.length + 1));
137 if (!obj_desc->string.pointer) {
138 acpi_cm_remove_reference (obj_desc);
139 status = AE_NO_MEMORY;
140 goto unlock_and_exit;
143 STRCPY (obj_desc->string.pointer, init_val->val);
147 case ACPI_TYPE_MUTEX:
149 obj_desc->mutex.sync_level =
150 (u16) STRTOUL (init_val->val, NULL, 10);
152 if (STRCMP (init_val->name, "_GL_") == 0) {
154 * Create a counting semaphore for the
157 status = acpi_os_create_semaphore (ACPI_NO_UNIT_LIMIT,
158 1, &obj_desc->mutex.semaphore);
160 if (ACPI_FAILURE (status)) {
161 goto unlock_and_exit;
164 * We just created the mutex for the
165 * global lock, save it
168 acpi_gbl_global_lock_semaphore = obj_desc->mutex.semaphore;
174 status = acpi_os_create_semaphore (1, 1,
175 &obj_desc->mutex.semaphore);
177 if (ACPI_FAILURE (status)) {
178 goto unlock_and_exit;
185 REPORT_ERROR (("Unsupported initial type value %X\n",
187 acpi_cm_remove_reference (obj_desc);
192 /* Store pointer to value descriptor in the Node */
194 acpi_ns_attach_object (new_node, obj_desc, obj_desc->common.type);
200 acpi_cm_release_mutex (ACPI_MTX_NAMESPACE);
205 /*******************************************************************************
207 * FUNCTION: Acpi_ns_lookup
209 * PARAMETERS: Prefix_node - Search scope if name is not fully qualified
210 * Pathname - Search pathname, in internal format
211 * (as represented in the AML stream)
212 * Type - Type associated with name
213 * Interpreter_mode - IMODE_LOAD_PASS2 => add name if not found
214 * Flags - Flags describing the search restrictions
215 * Walk_state - Current state of the walk
216 * Return_node - Where the Node is placed (if found
217 * or created successfully)
221 * DESCRIPTION: Find or enter the passed name in the name space.
222 * Log an error if name not found in Exec mode.
224 * MUTEX: Assumes namespace is locked.
226 ******************************************************************************/
230 ACPI_GENERIC_STATE *scope_info,
231 NATIVE_CHAR *pathname,
232 OBJECT_TYPE_INTERNAL type,
233 OPERATING_MODE interpreter_mode,
235 ACPI_WALK_STATE *walk_state,
236 ACPI_NAMESPACE_NODE **return_node)
239 ACPI_NAMESPACE_NODE *prefix_node;
240 ACPI_NAMESPACE_NODE *current_node = NULL;
241 ACPI_NAMESPACE_NODE *scope_to_push = NULL;
242 ACPI_NAMESPACE_NODE *this_node = NULL;
244 ACPI_NAME simple_name;
245 u8 null_name_path = FALSE;
246 OBJECT_TYPE_INTERNAL type_to_check_for;
247 OBJECT_TYPE_INTERNAL this_search_type;
248 u32 local_flags = flags & ~NS_ERROR_IF_FOUND;
252 return (AE_BAD_PARAMETER);
256 acpi_gbl_ns_lookup_count++;
258 *return_node = ENTRY_NOT_FOUND;
261 if (!acpi_gbl_root_node) {
262 return (AE_NO_NAMESPACE);
266 * Get the prefix scope.
267 * A null scope means use the root scope
271 (!scope_info->scope.node)) {
272 prefix_node = acpi_gbl_root_node;
275 prefix_node = scope_info->scope.node;
280 * This check is explicitly split provide relax the Type_to_check_for
281 * conditions for Bank_field_defn. Originally, both Bank_field_defn and
282 * Def_field_defn caused Type_to_check_for to be set to ACPI_TYPE_REGION,
283 * but the Bank_field_defn may also check for a Field definition as well
284 * as an Operation_region.
287 if (INTERNAL_TYPE_DEF_FIELD_DEFN == type) {
288 /* Def_field_defn defines fields in a Region */
290 type_to_check_for = ACPI_TYPE_REGION;
293 else if (INTERNAL_TYPE_BANK_FIELD_DEFN == type) {
294 /* Bank_field_defn defines data fields in a Field Object */
296 type_to_check_for = ACPI_TYPE_ANY;
300 type_to_check_for = type;
304 /* TBD: [Restructure] - Move the pathname stuff into a new procedure */
306 /* Examine the name pointer */
309 /* 8-12-98 ASL Grammar Update supports null Name_path */
311 null_name_path = TRUE;
313 this_node = acpi_gbl_root_node;
319 * Valid name pointer (Internal name format)
321 * Check for prefixes. As represented in the AML stream, a
322 * Pathname consists of an optional scope prefix followed by
325 * If present, the scope prefix is either a Root_prefix (in
326 * which case the name is fully qualified), or zero or more
327 * Parent_prefixes (in which case the name's scope is relative
328 * to the current scope).
330 * The segment part consists of either:
331 * - A single 4-byte name segment, or
332 * - A Dual_name_prefix followed by two 4-byte name segments, or
333 * - A Multi_name_prefix_op, followed by a byte indicating the
334 * number of segments and the segments themselves.
337 if (*pathname == AML_ROOT_PREFIX) {
338 /* Pathname is fully qualified, look in root name table */
340 current_node = acpi_gbl_root_node;
342 /* point to segment part */
346 /* Direct reference to root, "\" */
349 this_node = acpi_gbl_root_node;
350 goto check_for_new_scope_and_exit;
355 /* Pathname is relative to current scope, start there */
357 current_node = prefix_node;
360 * Handle up-prefix (carat). More than one prefix
364 while (*pathname == AML_PARENT_PREFIX) {
365 /* Point to segment part or next Parent_prefix */
369 /* Backup to the parent's scope */
371 this_node = acpi_ns_get_parent_object (current_node);
373 /* Current scope has no parent scope */
376 ("Too many parent prefixes (^) - reached root\n"));
377 return (AE_NOT_FOUND);
380 current_node = this_node;
386 * Examine the name prefix opcode, if any,
387 * to determine the number of segments
390 if (*pathname == AML_DUAL_NAME_PREFIX) {
393 /* point to first segment */
399 else if (*pathname == AML_MULTI_NAME_PREFIX_OP) {
400 num_segments = (u32)* (u8 *) ++pathname;
402 /* point to first segment */
410 * No Dual or Multi prefix, hence there is only one
411 * segment and Pathname is already pointing to it.
421 * Search namespace for each segment of the name.
422 * Loop through and verify/add each name segment.
426 while (num_segments-- && current_node) {
428 * Search for the current name segment under the current
429 * named object. The Type is significant only at the last (topmost)
430 * level. (We don't care about the types along the path, only
431 * the type of the final target object.)
433 this_search_type = ACPI_TYPE_ANY;
435 this_search_type = type;
439 /* Pluck one ACPI name from the front of the pathname */
441 MOVE_UNALIGNED32_TO_32 (&simple_name, pathname);
443 /* Try to find the ACPI name */
445 status = acpi_ns_search_and_enter (simple_name, walk_state,
446 current_node, interpreter_mode,
447 this_search_type, local_flags,
450 if (ACPI_FAILURE (status)) {
451 if (status == AE_NOT_FOUND) {
452 /* Name not found in ACPI namespace */
461 * If 1) This is the last segment (Num_segments == 0)
462 * 2) and looking for a specific type
463 * (Not checking for TYPE_ANY)
464 * 3) Which is not an alias
465 * 4) which is not a local type (TYPE_DEF_ANY)
466 * 5) which is not a local type (TYPE_SCOPE)
467 * 6) which is not a local type (TYPE_INDEX_FIELD_DEFN)
468 * 7) and type of object is known (not TYPE_ANY)
469 * 8) and object does not match request
471 * Then we have a type mismatch. Just warn and ignore it.
473 if ((num_segments == 0) &&
474 (type_to_check_for != ACPI_TYPE_ANY) &&
475 (type_to_check_for != INTERNAL_TYPE_ALIAS) &&
476 (type_to_check_for != INTERNAL_TYPE_DEF_ANY) &&
477 (type_to_check_for != INTERNAL_TYPE_SCOPE) &&
478 (type_to_check_for != INTERNAL_TYPE_INDEX_FIELD_DEFN) &&
479 (this_node->type != ACPI_TYPE_ANY) &&
480 (this_node->type != type_to_check_for)) {
481 /* Complain about a type mismatch */
484 ("Ns_lookup: %4.4s, type %X, checking for type %X\n",
485 &simple_name, this_node->type, type_to_check_for));
489 * If this is the last name segment and we are not looking for a
490 * specific type, but the type of found object is known, use that type
491 * to see if it opens a scope.
494 if ((0 == num_segments) && (ACPI_TYPE_ANY == type)) {
495 type = this_node->type;
498 if ((num_segments || acpi_ns_opens_scope (type)) &&
499 (this_node->child == NULL)) {
501 * More segments or the type implies enclosed scope,
502 * and the next scope has not been allocated.
507 current_node = this_node;
509 /* point to next name segment */
511 pathname += ACPI_NAME_SIZE;
516 * Always check if we need to open a new scope
519 check_for_new_scope_and_exit:
521 if (!(flags & NS_DONT_OPEN_SCOPE) && (walk_state)) {
523 * If entry is a type which opens a scope,
524 * push the new scope on the scope stack.
527 if (acpi_ns_opens_scope (type_to_check_for)) {
528 /* 8-12-98 ASL Grammar Update supports null Name_path */
530 if (null_name_path) {
531 /* TBD: [Investigate] - is this the correct thing to do? */
533 scope_to_push = NULL;
536 scope_to_push = this_node;
539 status = acpi_ds_scope_stack_push (scope_to_push, type,
541 if (ACPI_FAILURE (status)) {
548 *return_node = this_node;