1 /*******************************************************************************
3 * Module Name: nsaccess - Top-level functions for accessing ACPI namespace
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2018, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
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.
50 #ifdef ACPI_ASL_COMPILER
54 #define _COMPONENT ACPI_NAMESPACE
55 ACPI_MODULE_NAME ("nsaccess")
58 /*******************************************************************************
60 * FUNCTION: AcpiNsRootInitialize
66 * DESCRIPTION: Allocate and initialize the default root named objects
68 * MUTEX: Locks namespace for entire execution
70 ******************************************************************************/
73 AcpiNsRootInitialize (
77 const ACPI_PREDEFINED_NAMES
*InitVal
= NULL
;
78 ACPI_NAMESPACE_NODE
*NewNode
;
79 ACPI_OPERAND_OBJECT
*ObjDesc
;
80 ACPI_STRING Val
= NULL
;
83 ACPI_FUNCTION_TRACE (NsRootInitialize
);
86 Status
= AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE
);
87 if (ACPI_FAILURE (Status
))
89 return_ACPI_STATUS (Status
);
93 * The global root ptr is initially NULL, so a non-NULL value indicates
94 * that AcpiNsRootInitialize() has already been called; just return.
103 * Tell the rest of the subsystem that the root is initialized
104 * (This is OK because the namespace is locked)
106 AcpiGbl_RootNode
= &AcpiGbl_RootNodeStruct
;
108 /* Enter the pre-defined names in the name table */
110 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,
111 "Entering predefined entries into namespace\n"));
113 for (InitVal
= AcpiGbl_PreDefinedNames
; InitVal
->Name
; InitVal
++)
115 /* _OSI is optional for now, will be permanent later */
117 if (!strcmp (InitVal
->Name
, "_OSI") && !AcpiGbl_CreateOsiMethod
)
122 Status
= AcpiNsLookup (NULL
, ACPI_CAST_PTR (char, InitVal
->Name
),
123 InitVal
->Type
, ACPI_IMODE_LOAD_PASS2
, ACPI_NS_NO_UPSEARCH
,
125 if (ACPI_FAILURE (Status
))
127 ACPI_EXCEPTION ((AE_INFO
, Status
,
128 "Could not create predefined name %s",
134 * Name entered successfully. If entry in PreDefinedNames[] specifies
135 * an initial value, create the initial value.
139 Status
= AcpiOsPredefinedOverride (InitVal
, &Val
);
140 if (ACPI_FAILURE (Status
))
142 ACPI_ERROR ((AE_INFO
,
143 "Could not override predefined %s",
153 * Entry requests an initial value, allocate a
156 ObjDesc
= AcpiUtCreateInternalObject (InitVal
->Type
);
159 Status
= AE_NO_MEMORY
;
164 * Convert value string from table entry to
165 * internal representation. Only types actually
166 * used for initial values are implemented here.
168 switch (InitVal
->Type
)
170 case ACPI_TYPE_METHOD
:
172 ObjDesc
->Method
.ParamCount
= (UINT8
) ACPI_TO_INTEGER (Val
);
173 ObjDesc
->Common
.Flags
|= AOPOBJ_DATA_VALID
;
175 #if defined (ACPI_ASL_COMPILER)
177 /* Save the parameter count for the iASL compiler */
179 NewNode
->Value
= ObjDesc
->Method
.ParamCount
;
181 /* Mark this as a very SPECIAL method */
183 ObjDesc
->Method
.InfoFlags
= ACPI_METHOD_INTERNAL_ONLY
;
184 ObjDesc
->Method
.Dispatch
.Implementation
= AcpiUtOsiImplementation
;
188 case ACPI_TYPE_INTEGER
:
190 ObjDesc
->Integer
.Value
= ACPI_TO_INTEGER (Val
);
193 case ACPI_TYPE_STRING
:
195 /* Build an object around the static string */
197 ObjDesc
->String
.Length
= (UINT32
) strlen (Val
);
198 ObjDesc
->String
.Pointer
= Val
;
199 ObjDesc
->Common
.Flags
|= AOPOBJ_STATIC_POINTER
;
202 case ACPI_TYPE_MUTEX
:
204 ObjDesc
->Mutex
.Node
= NewNode
;
205 ObjDesc
->Mutex
.SyncLevel
= (UINT8
) (ACPI_TO_INTEGER (Val
) - 1);
209 Status
= AcpiOsCreateMutex (&ObjDesc
->Mutex
.OsMutex
);
210 if (ACPI_FAILURE (Status
))
212 AcpiUtRemoveReference (ObjDesc
);
216 /* Special case for ACPI Global Lock */
218 if (strcmp (InitVal
->Name
, "_GL_") == 0)
220 AcpiGbl_GlobalLockMutex
= ObjDesc
;
222 /* Create additional counting semaphore for global lock */
224 Status
= AcpiOsCreateSemaphore (
225 1, 0, &AcpiGbl_GlobalLockSemaphore
);
226 if (ACPI_FAILURE (Status
))
228 AcpiUtRemoveReference (ObjDesc
);
236 ACPI_ERROR ((AE_INFO
, "Unsupported initial type value 0x%X",
238 AcpiUtRemoveReference (ObjDesc
);
243 /* Store pointer to value descriptor in the Node */
245 Status
= AcpiNsAttachObject (NewNode
, ObjDesc
,
246 ObjDesc
->Common
.Type
);
248 /* Remove local reference to the object */
250 AcpiUtRemoveReference (ObjDesc
);
256 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE
);
258 /* Save a handle to "_GPE", it is always present */
260 if (ACPI_SUCCESS (Status
))
262 Status
= AcpiNsGetNode (NULL
, "\\_GPE", ACPI_NS_NO_UPSEARCH
,
263 &AcpiGbl_FadtGpeDevice
);
266 return_ACPI_STATUS (Status
);
270 /*******************************************************************************
272 * FUNCTION: AcpiNsLookup
274 * PARAMETERS: ScopeInfo - Current scope info block
275 * Pathname - Search pathname, in internal format
276 * (as represented in the AML stream)
277 * Type - Type associated with name
278 * InterpreterMode - IMODE_LOAD_PASS2 => add name if not found
279 * Flags - Flags describing the search restrictions
280 * WalkState - Current state of the walk
281 * ReturnNode - Where the Node is placed (if found
282 * or created successfully)
286 * DESCRIPTION: Find or enter the passed name in the name space.
287 * Log an error if name not found in Exec mode.
289 * MUTEX: Assumes namespace is locked.
291 ******************************************************************************/
295 ACPI_GENERIC_STATE
*ScopeInfo
,
297 ACPI_OBJECT_TYPE Type
,
298 ACPI_INTERPRETER_MODE InterpreterMode
,
300 ACPI_WALK_STATE
*WalkState
,
301 ACPI_NAMESPACE_NODE
**ReturnNode
)
304 char *Path
= Pathname
;
306 ACPI_NAMESPACE_NODE
*PrefixNode
;
307 ACPI_NAMESPACE_NODE
*CurrentNode
= NULL
;
308 ACPI_NAMESPACE_NODE
*ThisNode
= NULL
;
311 ACPI_NAME SimpleName
;
312 ACPI_OBJECT_TYPE TypeToCheckFor
;
313 ACPI_OBJECT_TYPE ThisSearchType
;
314 UINT32 SearchParentFlag
= ACPI_NS_SEARCH_PARENT
;
318 ACPI_FUNCTION_TRACE (NsLookup
);
323 return_ACPI_STATUS (AE_BAD_PARAMETER
);
327 ~(ACPI_NS_ERROR_IF_FOUND
| ACPI_NS_OVERRIDE_IF_FOUND
|
328 ACPI_NS_SEARCH_PARENT
);
329 *ReturnNode
= ACPI_ENTRY_NOT_FOUND
;
330 AcpiGbl_NsLookupCount
++;
332 if (!AcpiGbl_RootNode
)
334 return_ACPI_STATUS (AE_NO_NAMESPACE
);
337 /* Get the prefix scope. A null scope means use the root scope */
340 (!ScopeInfo
->Scope
.Node
))
342 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES
,
343 "Null scope prefix, using root node (%p)\n",
346 PrefixNode
= AcpiGbl_RootNode
;
350 PrefixNode
= ScopeInfo
->Scope
.Node
;
351 if (ACPI_GET_DESCRIPTOR_TYPE (PrefixNode
) != ACPI_DESC_TYPE_NAMED
)
353 ACPI_ERROR ((AE_INFO
, "%p is not a namespace node [%s]",
354 PrefixNode
, AcpiUtGetDescriptorName (PrefixNode
)));
355 return_ACPI_STATUS (AE_AML_INTERNAL
);
358 if (!(Flags
& ACPI_NS_PREFIX_IS_SCOPE
))
361 * This node might not be a actual "scope" node (such as a
362 * Device/Method, etc.) It could be a Package or other object
363 * node. Backup up the tree to find the containing scope node.
365 while (!AcpiNsOpensScope (PrefixNode
->Type
) &&
366 PrefixNode
->Type
!= ACPI_TYPE_ANY
)
368 PrefixNode
= PrefixNode
->Parent
;
373 /* Save type. TBD: may be no longer necessary */
375 TypeToCheckFor
= Type
;
378 * Begin examination of the actual pathname
382 /* A Null NamePath is allowed and refers to the root */
385 ThisNode
= AcpiGbl_RootNode
;
388 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES
,
389 "Null Pathname (Zero segments), Flags=%X\n", Flags
));
394 * Name pointer is valid (and must be in internal name format)
396 * Check for scope prefixes:
398 * As represented in the AML stream, a namepath consists of an
399 * optional scope prefix followed by a name segment part.
401 * If present, the scope prefix is either a Root Prefix (in
402 * which case the name is fully qualified), or one or more
403 * Parent Prefixes (in which case the name's scope is relative
404 * to the current scope).
406 if (*Path
== (UINT8
) AML_ROOT_PREFIX
)
408 /* Pathname is fully qualified, start from the root */
410 ThisNode
= AcpiGbl_RootNode
;
411 SearchParentFlag
= ACPI_NS_NO_UPSEARCH
;
413 /* Point to name segment part */
417 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES
,
418 "Path is absolute from root [%p]\n", ThisNode
));
422 /* Pathname is relative to current scope, start there */
424 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES
,
425 "Searching relative to prefix scope [%4.4s] (%p)\n",
426 AcpiUtGetNodeName (PrefixNode
), PrefixNode
));
429 * Handle multiple Parent Prefixes (carat) by just getting
430 * the parent node for each prefix instance.
432 ThisNode
= PrefixNode
;
434 while (*Path
== (UINT8
) AML_PARENT_PREFIX
)
436 /* Name is fully qualified, no search rules apply */
438 SearchParentFlag
= ACPI_NS_NO_UPSEARCH
;
441 * Point past this prefix to the name segment
442 * part or the next Parent Prefix
446 /* Backup to the parent node */
449 ThisNode
= ThisNode
->Parent
;
453 * Current scope has no parent scope. Externalize
454 * the internal path for error message.
456 Status
= AcpiNsExternalizeName (ACPI_UINT32_MAX
, Pathname
,
457 NULL
, &ExternalPath
);
458 if (ACPI_SUCCESS (Status
))
460 ACPI_ERROR ((AE_INFO
,
461 "%s: Path has too many parent prefixes (^)",
464 ACPI_FREE (ExternalPath
);
467 return_ACPI_STATUS (AE_NOT_FOUND
);
471 if (SearchParentFlag
== ACPI_NS_NO_UPSEARCH
)
473 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES
,
474 "Search scope is [%4.4s], path has %u carat(s)\n",
475 AcpiUtGetNodeName (ThisNode
), NumCarats
));
480 * Determine the number of ACPI name segments in this pathname.
482 * The segment part consists of either:
483 * - A Null name segment (0)
484 * - A DualNamePrefix followed by two 4-byte name segments
485 * - A MultiNamePrefix followed by a byte indicating the
486 * number of segments and the segments themselves.
487 * - A single 4-byte name segment
489 * Examine the name prefix opcode, if any, to determine the number of
496 * Null name after a root or parent prefixes. We already
497 * have the correct target node and there are no name segments.
500 Type
= ThisNode
->Type
;
502 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES
,
503 "Prefix-only Pathname (Zero name segments), Flags=%X\n",
507 case AML_DUAL_NAME_PREFIX
:
509 /* More than one NameSeg, search rules do not apply */
511 SearchParentFlag
= ACPI_NS_NO_UPSEARCH
;
513 /* Two segments, point to first name segment */
518 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES
,
519 "Dual Pathname (2 segments, Flags=%X)\n", Flags
));
522 case AML_MULTI_NAME_PREFIX
:
524 /* More than one NameSeg, search rules do not apply */
526 SearchParentFlag
= ACPI_NS_NO_UPSEARCH
;
528 /* Extract segment count, point to first name segment */
531 NumSegments
= (UINT32
) (UINT8
) *Path
;
534 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES
,
535 "Multi Pathname (%u Segments, Flags=%X)\n",
536 NumSegments
, Flags
));
541 * Not a Null name, no Dual or Multi prefix, hence there is
542 * only one name segment and Pathname is already pointing to it.
546 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES
,
547 "Simple Pathname (1 segment, Flags=%X)\n", Flags
));
551 ACPI_DEBUG_EXEC (AcpiNsPrintPathname (NumSegments
, Path
));
556 * Search namespace for each segment of the name. Loop through and
557 * verify (or add to the namespace) each name segment.
559 * The object type is significant only at the last name
560 * segment. (We don't care about the types along the path, only
561 * the type of the final target object.)
563 ThisSearchType
= ACPI_TYPE_ANY
;
564 CurrentNode
= ThisNode
;
565 while (NumSegments
&& CurrentNode
)
570 /* This is the last segment, enable typechecking */
572 ThisSearchType
= Type
;
575 * Only allow automatic parent search (search rules) if the caller
576 * requested it AND we have a single, non-fully-qualified NameSeg
578 if ((SearchParentFlag
!= ACPI_NS_NO_UPSEARCH
) &&
579 (Flags
& ACPI_NS_SEARCH_PARENT
))
581 LocalFlags
|= ACPI_NS_SEARCH_PARENT
;
584 /* Set error flag according to caller */
586 if (Flags
& ACPI_NS_ERROR_IF_FOUND
)
588 LocalFlags
|= ACPI_NS_ERROR_IF_FOUND
;
591 /* Set override flag according to caller */
593 if (Flags
& ACPI_NS_OVERRIDE_IF_FOUND
)
595 LocalFlags
|= ACPI_NS_OVERRIDE_IF_FOUND
;
599 /* Extract one ACPI name from the front of the pathname */
601 ACPI_MOVE_32_TO_32 (&SimpleName
, Path
);
603 /* Try to find the single (4 character) ACPI name */
605 Status
= AcpiNsSearchAndEnter (SimpleName
, WalkState
, CurrentNode
,
606 InterpreterMode
, ThisSearchType
, LocalFlags
, &ThisNode
);
607 if (ACPI_FAILURE (Status
))
609 if (Status
== AE_NOT_FOUND
)
611 /* Name not found in ACPI namespace */
613 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES
,
614 "Name [%4.4s] not found in scope [%4.4s] %p\n",
615 (char *) &SimpleName
, (char *) &CurrentNode
->Name
,
620 if ((Status
== AE_ALREADY_EXISTS
) &&
621 (ThisNode
->Flags
& ANOBJ_NODE_EARLY_INIT
))
623 ThisNode
->Flags
&= ~ANOBJ_NODE_EARLY_INIT
;
628 #ifdef ACPI_ASL_COMPILER
630 * If this ACPI name already exists within the namespace as an
631 * external declaration, then mark the external as a conflicting
632 * declaration and proceed to process the current node as if it did
633 * not exist in the namespace. If this node is not processed as
634 * normal, then it could cause improper namespace resolution
635 * by failing to open a new scope.
637 if (AcpiGbl_DisasmFlag
&&
638 (Status
== AE_ALREADY_EXISTS
) &&
639 ((ThisNode
->Flags
& ANOBJ_IS_EXTERNAL
) ||
640 (WalkState
&& WalkState
->Opcode
== AML_EXTERNAL_OP
)))
642 ThisNode
->Flags
&= ~ANOBJ_IS_EXTERNAL
;
643 ThisNode
->Type
= (UINT8
)ThisSearchType
;
644 if (WalkState
->Opcode
!= AML_EXTERNAL_OP
)
646 AcpiDmMarkExternalConflict (ThisNode
);
652 *ReturnNode
= ThisNode
;
653 return_ACPI_STATUS (Status
);
656 /* More segments to follow? */
661 * If we have an alias to an object that opens a scope (such as a
662 * device or processor), we need to dereference the alias here so
663 * that we can access any children of the original node (via the
664 * remaining segments).
666 if (ThisNode
->Type
== ACPI_TYPE_LOCAL_ALIAS
)
668 if (!ThisNode
->Object
)
670 return_ACPI_STATUS (AE_NOT_EXIST
);
673 if (AcpiNsOpensScope (((ACPI_NAMESPACE_NODE
*)
674 ThisNode
->Object
)->Type
))
676 ThisNode
= (ACPI_NAMESPACE_NODE
*) ThisNode
->Object
;
681 /* Special handling for the last segment (NumSegments == 0) */
686 * Sanity typecheck of the target object:
688 * If 1) This is the last segment (NumSegments == 0)
689 * 2) And we are looking for a specific type
690 * (Not checking for TYPE_ANY)
691 * 3) Which is not an alias
692 * 4) Which is not a local type (TYPE_SCOPE)
693 * 5) And the type of target object is known (not TYPE_ANY)
694 * 6) And target object does not match what we are looking for
696 * Then we have a type mismatch. Just warn and ignore it.
698 if ((TypeToCheckFor
!= ACPI_TYPE_ANY
) &&
699 (TypeToCheckFor
!= ACPI_TYPE_LOCAL_ALIAS
) &&
700 (TypeToCheckFor
!= ACPI_TYPE_LOCAL_METHOD_ALIAS
) &&
701 (TypeToCheckFor
!= ACPI_TYPE_LOCAL_SCOPE
) &&
702 (ThisNode
->Type
!= ACPI_TYPE_ANY
) &&
703 (ThisNode
->Type
!= TypeToCheckFor
))
705 /* Complain about a type mismatch */
707 ACPI_WARNING ((AE_INFO
,
708 "NsLookup: Type mismatch on %4.4s (%s), searching for (%s)",
709 ACPI_CAST_PTR (char, &SimpleName
),
710 AcpiUtGetTypeName (ThisNode
->Type
),
711 AcpiUtGetTypeName (TypeToCheckFor
)));
715 * If this is the last name segment and we are not looking for a
716 * specific type, but the type of found object is known, use that
717 * type to (later) see if it opens a scope.
719 if (Type
== ACPI_TYPE_ANY
)
721 Type
= ThisNode
->Type
;
725 /* Point to next name segment and make this node current */
727 Path
+= ACPI_NAME_SIZE
;
728 CurrentNode
= ThisNode
;
731 /* Always check if we need to open a new scope */
733 if (!(Flags
& ACPI_NS_DONT_OPEN_SCOPE
) && (WalkState
))
736 * If entry is a type which opens a scope, push the new scope on the
739 if (AcpiNsOpensScope (Type
))
741 Status
= AcpiDsScopeStackPush (ThisNode
, Type
, WalkState
);
742 if (ACPI_FAILURE (Status
))
744 return_ACPI_STATUS (Status
);
750 if (Flags
& ACPI_NS_EARLY_INIT
)
752 ThisNode
->Flags
|= ANOBJ_NODE_EARLY_INIT
;
756 *ReturnNode
= ThisNode
;
757 return_ACPI_STATUS (AE_OK
);