- Kai Germaschewski: ISDN update (including Makefiles)
[davej-history.git] / drivers / acpi / namespace / nsaccess.c
blob4b420edff12c5cc6ddb848e9344e09e7fc7b3289
1 /*******************************************************************************
3 * Module Name: nsaccess - Top-level functions for accessing ACPI namespace
4 * $Revision: 115 $
6 ******************************************************************************/
8 /*
9 * Copyright (C) 2000 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
27 #include "acpi.h"
28 #include "amlcode.h"
29 #include "acinterp.h"
30 #include "acnamesp.h"
31 #include "acdispat.h"
34 #define _COMPONENT NAMESPACE
35 MODULE_NAME ("nsaccess")
38 /*******************************************************************************
40 * FUNCTION: Acpi_ns_root_initialize
42 * PARAMETERS: None
44 * RETURN: Status
46 * DESCRIPTION: Allocate and initialize the default root named objects
48 * MUTEX: Locks namespace for entire execution
50 ******************************************************************************/
52 ACPI_STATUS
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) {
69 status = AE_OK;
70 goto unlock_and_exit;
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,
88 NULL, &new_node);
92 * Name entered successfully.
93 * If entry in Pre_defined_names[] specifies an
94 * initial value, create the initial value.
97 if (init_val->val) {
99 * Entry requests an initial value, allocate a
100 * descriptor for it.
103 obj_desc = acpi_cm_create_internal_object (
104 (OBJECT_TYPE_INTERNAL) init_val->type);
106 if (!obj_desc) {
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)
120 case ACPI_TYPE_NUMBER:
122 obj_desc->number.value =
123 (ACPI_INTEGER) STRTOUL (init_val->val, NULL, 10);
124 break;
127 case ACPI_TYPE_STRING:
129 obj_desc->string.length =
130 (u16) STRLEN (init_val->val);
133 * Allocate a buffer for the string. All
134 * String.Pointers must be allocated buffers!
135 * (makes deletion simpler)
137 obj_desc->string.pointer = acpi_cm_allocate (
138 (obj_desc->string.length + 1));
139 if (!obj_desc->string.pointer) {
140 acpi_cm_remove_reference (obj_desc);
141 status = AE_NO_MEMORY;
142 goto unlock_and_exit;
145 STRCPY (obj_desc->string.pointer, init_val->val);
146 break;
149 case ACPI_TYPE_MUTEX:
151 obj_desc->mutex.sync_level =
152 (u16) STRTOUL (init_val->val, NULL, 10);
154 if (STRCMP (init_val->name, "_GL_") == 0) {
156 * Create a counting semaphore for the
157 * global lock
159 status = acpi_os_create_semaphore (ACPI_NO_UNIT_LIMIT,
160 1, &obj_desc->mutex.semaphore);
162 if (ACPI_FAILURE (status)) {
163 goto unlock_and_exit;
166 * We just created the mutex for the
167 * global lock, save it
170 acpi_gbl_global_lock_semaphore = obj_desc->mutex.semaphore;
173 else {
174 /* Create a mutex */
176 status = acpi_os_create_semaphore (1, 1,
177 &obj_desc->mutex.semaphore);
179 if (ACPI_FAILURE (status)) {
180 goto unlock_and_exit;
183 break;
186 default:
187 REPORT_ERROR (("Unsupported initial type value %X\n",
188 init_val->type));
189 acpi_cm_remove_reference (obj_desc);
190 obj_desc = NULL;
191 continue;
194 /* Store pointer to value descriptor in the Node */
196 acpi_ns_attach_object (new_node, obj_desc,
197 obj_desc->common.type);
202 unlock_and_exit:
203 acpi_cm_release_mutex (ACPI_MTX_NAMESPACE);
204 return (status);
208 /*******************************************************************************
210 * FUNCTION: Acpi_ns_lookup
212 * PARAMETERS: Prefix_node - Search scope if name is not fully qualified
213 * Pathname - Search pathname, in internal format
214 * (as represented in the AML stream)
215 * Type - Type associated with name
216 * Interpreter_mode - IMODE_LOAD_PASS2 => add name if not found
217 * Flags - Flags describing the search restrictions
218 * Walk_state - Current state of the walk
219 * Return_node - Where the Node is placed (if found
220 * or created successfully)
222 * RETURN: Status
224 * DESCRIPTION: Find or enter the passed name in the name space.
225 * Log an error if name not found in Exec mode.
227 * MUTEX: Assumes namespace is locked.
229 ******************************************************************************/
231 ACPI_STATUS
232 acpi_ns_lookup (
233 ACPI_GENERIC_STATE *scope_info,
234 NATIVE_CHAR *pathname,
235 OBJECT_TYPE_INTERNAL type,
236 OPERATING_MODE interpreter_mode,
237 u32 flags,
238 ACPI_WALK_STATE *walk_state,
239 ACPI_NAMESPACE_NODE **return_node)
241 ACPI_STATUS status;
242 ACPI_NAMESPACE_NODE *prefix_node;
243 ACPI_NAMESPACE_NODE *current_node = NULL;
244 ACPI_NAMESPACE_NODE *scope_to_push = NULL;
245 ACPI_NAMESPACE_NODE *this_node = NULL;
246 u32 num_segments;
247 ACPI_NAME simple_name;
248 u8 null_name_path = FALSE;
249 OBJECT_TYPE_INTERNAL type_to_check_for;
250 OBJECT_TYPE_INTERNAL this_search_type;
252 DEBUG_ONLY_MEMBERS (u32 i)
255 if (!return_node) {
256 return (AE_BAD_PARAMETER);
260 acpi_gbl_ns_lookup_count++;
262 *return_node = ENTRY_NOT_FOUND;
265 if (!acpi_gbl_root_node) {
266 return (AE_NO_NAMESPACE);
270 * Get the prefix scope.
271 * A null scope means use the root scope
274 if ((!scope_info) ||
275 (!scope_info->scope.node))
277 prefix_node = acpi_gbl_root_node;
279 else {
280 prefix_node = scope_info->scope.node;
285 * This check is explicitly split provide relax the Type_to_check_for
286 * conditions for Bank_field_defn. Originally, both Bank_field_defn and
287 * Def_field_defn caused Type_to_check_for to be set to ACPI_TYPE_REGION,
288 * but the Bank_field_defn may also check for a Field definition as well
289 * as an Operation_region.
292 if (INTERNAL_TYPE_DEF_FIELD_DEFN == type) {
293 /* Def_field_defn defines fields in a Region */
295 type_to_check_for = ACPI_TYPE_REGION;
298 else if (INTERNAL_TYPE_BANK_FIELD_DEFN == type) {
299 /* Bank_field_defn defines data fields in a Field Object */
301 type_to_check_for = ACPI_TYPE_ANY;
304 else {
305 type_to_check_for = type;
309 /* TBD: [Restructure] - Move the pathname stuff into a new procedure */
311 /* Examine the name pointer */
313 if (!pathname) {
314 /* 8-12-98 ASL Grammar Update supports null Name_path */
316 null_name_path = TRUE;
317 num_segments = 0;
318 this_node = acpi_gbl_root_node;
322 else {
324 * Valid name pointer (Internal name format)
326 * Check for prefixes. As represented in the AML stream, a
327 * Pathname consists of an optional scope prefix followed by
328 * a segment part.
330 * If present, the scope prefix is either a Root_prefix (in
331 * which case the name is fully qualified), or zero or more
332 * Parent_prefixes (in which case the name's scope is relative
333 * to the current scope).
335 * The segment part consists of either:
336 * - A single 4-byte name segment, or
337 * - A Dual_name_prefix followed by two 4-byte name segments, or
338 * - A Multi_name_prefix_op, followed by a byte indicating the
339 * number of segments and the segments themselves.
342 if (*pathname == AML_ROOT_PREFIX) {
343 /* Pathname is fully qualified, look in root name table */
345 current_node = acpi_gbl_root_node;
347 /* point to segment part */
349 pathname++;
351 /* Direct reference to root, "\" */
353 if (!(*pathname)) {
354 this_node = acpi_gbl_root_node;
355 goto check_for_new_scope_and_exit;
359 else {
360 /* Pathname is relative to current scope, start there */
362 current_node = prefix_node;
365 * Handle up-prefix (carat). More than one prefix
366 * is supported
369 while (*pathname == AML_PARENT_PREFIX) {
370 /* Point to segment part or next Parent_prefix */
372 pathname++;
374 /* Backup to the parent's scope */
376 this_node = acpi_ns_get_parent_object (current_node);
377 if (!this_node) {
378 /* Current scope has no parent scope */
380 REPORT_ERROR (("Too many parent prefixes (^) - reached root\n"));
381 return (AE_NOT_FOUND);
384 current_node = this_node;
390 * Examine the name prefix opcode, if any,
391 * to determine the number of segments
394 if (*pathname == AML_DUAL_NAME_PREFIX) {
395 num_segments = 2;
397 /* point to first segment */
399 pathname++;
403 else if (*pathname == AML_MULTI_NAME_PREFIX_OP) {
404 num_segments = (u32)* (u8 *) ++pathname;
406 /* point to first segment */
408 pathname++;
412 else {
414 * No Dual or Multi prefix, hence there is only one
415 * segment and Pathname is already pointing to it.
417 num_segments = 1;
425 * Search namespace for each segment of the name.
426 * Loop through and verify/add each name segment.
430 while (num_segments-- && current_node) {
432 * Search for the current name segment under the current
433 * named object. The Type is significant only at the last (topmost)
434 * level. (We don't care about the types along the path, only
435 * the type of the final target object.)
437 this_search_type = ACPI_TYPE_ANY;
438 if (!num_segments) {
439 this_search_type = type;
442 /* Pluck one ACPI name from the front of the pathname */
444 MOVE_UNALIGNED32_TO_32 (&simple_name, pathname);
446 /* Try to find the ACPI name */
448 status = acpi_ns_search_and_enter (simple_name, walk_state,
449 current_node, interpreter_mode,
450 this_search_type, flags,
451 &this_node);
453 if (ACPI_FAILURE (status)) {
454 if (status == AE_NOT_FOUND) {
455 /* Name not found in ACPI namespace */
459 return (status);
464 * If 1) This is the last segment (Num_segments == 0)
465 * 2) and looking for a specific type
466 * (Not checking for TYPE_ANY)
467 * 3) Which is not an alias
468 * 4) which is not a local type (TYPE_DEF_ANY)
469 * 5) which is not a local type (TYPE_SCOPE)
470 * 6) which is not a local type (TYPE_INDEX_FIELD_DEFN)
471 * 7) and type of object is known (not TYPE_ANY)
472 * 8) and object does not match request
474 * Then we have a type mismatch. Just warn and ignore it.
476 if ((num_segments == 0) &&
477 (type_to_check_for != ACPI_TYPE_ANY) &&
478 (type_to_check_for != INTERNAL_TYPE_ALIAS) &&
479 (type_to_check_for != INTERNAL_TYPE_DEF_ANY) &&
480 (type_to_check_for != INTERNAL_TYPE_SCOPE) &&
481 (type_to_check_for != INTERNAL_TYPE_INDEX_FIELD_DEFN) &&
482 (this_node->type != ACPI_TYPE_ANY) &&
483 (this_node->type != type_to_check_for))
485 /* Complain about a type mismatch */
487 REPORT_WARNING (
488 ("Ns_lookup: %4.4s, type %X, checking for type %X\n",
489 &simple_name, this_node->type, type_to_check_for));
493 * If this is the last name segment and we are not looking for a
494 * specific type, but the type of found object is known, use that type
495 * to see if it opens a scope.
498 if ((0 == num_segments) && (ACPI_TYPE_ANY == type)) {
499 type = this_node->type;
502 if ((num_segments || acpi_ns_opens_scope (type)) &&
503 (this_node->child == NULL))
506 * More segments or the type implies enclosed scope,
507 * and the next scope has not been allocated.
512 current_node = this_node;
514 /* point to next name segment */
516 pathname += ACPI_NAME_SIZE;
521 * Always check if we need to open a new scope
524 check_for_new_scope_and_exit:
526 if (!(flags & NS_DONT_OPEN_SCOPE) && (walk_state)) {
528 * If entry is a type which opens a scope,
529 * push the new scope on the scope stack.
532 if (acpi_ns_opens_scope (type_to_check_for)) {
533 /* 8-12-98 ASL Grammar Update supports null Name_path */
535 if (null_name_path) {
536 /* TBD: [Investigate] - is this the correct thing to do? */
538 scope_to_push = NULL;
540 else {
541 scope_to_push = this_node;
544 status = acpi_ds_scope_stack_push (scope_to_push, type,
545 walk_state);
546 if (ACPI_FAILURE (status)) {
547 return (status);
553 *return_node = this_node;
554 return (AE_OK);