1 /*******************************************************************************
3 * Module Name: nsaccess - Top-level functions for accessing ACPI namespace
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2016, 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.
51 #define _COMPONENT ACPI_NAMESPACE
52 ACPI_MODULE_NAME ("nsaccess")
55 /*******************************************************************************
57 * FUNCTION: AcpiNsRootInitialize
63 * DESCRIPTION: Allocate and initialize the default root named objects
65 * MUTEX: Locks namespace for entire execution
67 ******************************************************************************/
70 AcpiNsRootInitialize (
74 const ACPI_PREDEFINED_NAMES
*InitVal
= NULL
;
75 ACPI_NAMESPACE_NODE
*NewNode
;
76 ACPI_OPERAND_OBJECT
*ObjDesc
;
77 ACPI_STRING Val
= NULL
;
80 ACPI_FUNCTION_TRACE (NsRootInitialize
);
83 Status
= AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE
);
84 if (ACPI_FAILURE (Status
))
86 return_ACPI_STATUS (Status
);
90 * The global root ptr is initially NULL, so a non-NULL value indicates
91 * that AcpiNsRootInitialize() has already been called; just return.
100 * Tell the rest of the subsystem that the root is initialized
101 * (This is OK because the namespace is locked)
103 AcpiGbl_RootNode
= &AcpiGbl_RootNodeStruct
;
105 /* Enter the pre-defined names in the name table */
107 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,
108 "Entering predefined entries into namespace\n"));
110 for (InitVal
= AcpiGbl_PreDefinedNames
; InitVal
->Name
; InitVal
++)
112 /* _OSI is optional for now, will be permanent later */
114 if (!strcmp (InitVal
->Name
, "_OSI") && !AcpiGbl_CreateOsiMethod
)
119 Status
= AcpiNsLookup (NULL
, ACPI_CAST_PTR (char, InitVal
->Name
),
120 InitVal
->Type
, ACPI_IMODE_LOAD_PASS2
, ACPI_NS_NO_UPSEARCH
,
122 if (ACPI_FAILURE (Status
))
124 ACPI_EXCEPTION ((AE_INFO
, Status
,
125 "Could not create predefined name %s",
131 * Name entered successfully. If entry in PreDefinedNames[] specifies
132 * an initial value, create the initial value.
136 Status
= AcpiOsPredefinedOverride (InitVal
, &Val
);
137 if (ACPI_FAILURE (Status
))
139 ACPI_ERROR ((AE_INFO
,
140 "Could not override predefined %s",
150 * Entry requests an initial value, allocate a
153 ObjDesc
= AcpiUtCreateInternalObject (InitVal
->Type
);
156 Status
= AE_NO_MEMORY
;
161 * Convert value string from table entry to
162 * internal representation. Only types actually
163 * used for initial values are implemented here.
165 switch (InitVal
->Type
)
167 case ACPI_TYPE_METHOD
:
169 ObjDesc
->Method
.ParamCount
= (UINT8
) ACPI_TO_INTEGER (Val
);
170 ObjDesc
->Common
.Flags
|= AOPOBJ_DATA_VALID
;
172 #if defined (ACPI_ASL_COMPILER)
174 /* Save the parameter count for the iASL compiler */
176 NewNode
->Value
= ObjDesc
->Method
.ParamCount
;
178 /* Mark this as a very SPECIAL method */
180 ObjDesc
->Method
.InfoFlags
= ACPI_METHOD_INTERNAL_ONLY
;
181 ObjDesc
->Method
.Dispatch
.Implementation
= AcpiUtOsiImplementation
;
185 case ACPI_TYPE_INTEGER
:
187 ObjDesc
->Integer
.Value
= ACPI_TO_INTEGER (Val
);
190 case ACPI_TYPE_STRING
:
192 /* Build an object around the static string */
194 ObjDesc
->String
.Length
= (UINT32
) strlen (Val
);
195 ObjDesc
->String
.Pointer
= Val
;
196 ObjDesc
->Common
.Flags
|= AOPOBJ_STATIC_POINTER
;
199 case ACPI_TYPE_MUTEX
:
201 ObjDesc
->Mutex
.Node
= NewNode
;
202 ObjDesc
->Mutex
.SyncLevel
= (UINT8
) (ACPI_TO_INTEGER (Val
) - 1);
206 Status
= AcpiOsCreateMutex (&ObjDesc
->Mutex
.OsMutex
);
207 if (ACPI_FAILURE (Status
))
209 AcpiUtRemoveReference (ObjDesc
);
213 /* Special case for ACPI Global Lock */
215 if (strcmp (InitVal
->Name
, "_GL_") == 0)
217 AcpiGbl_GlobalLockMutex
= ObjDesc
;
219 /* Create additional counting semaphore for global lock */
221 Status
= AcpiOsCreateSemaphore (
222 1, 0, &AcpiGbl_GlobalLockSemaphore
);
223 if (ACPI_FAILURE (Status
))
225 AcpiUtRemoveReference (ObjDesc
);
233 ACPI_ERROR ((AE_INFO
, "Unsupported initial type value 0x%X",
235 AcpiUtRemoveReference (ObjDesc
);
240 /* Store pointer to value descriptor in the Node */
242 Status
= AcpiNsAttachObject (NewNode
, ObjDesc
,
243 ObjDesc
->Common
.Type
);
245 /* Remove local reference to the object */
247 AcpiUtRemoveReference (ObjDesc
);
253 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE
);
255 /* Save a handle to "_GPE", it is always present */
257 if (ACPI_SUCCESS (Status
))
259 Status
= AcpiNsGetNode (NULL
, "\\_GPE", ACPI_NS_NO_UPSEARCH
,
260 &AcpiGbl_FadtGpeDevice
);
263 return_ACPI_STATUS (Status
);
267 /*******************************************************************************
269 * FUNCTION: AcpiNsLookup
271 * PARAMETERS: ScopeInfo - Current scope info block
272 * Pathname - Search pathname, in internal format
273 * (as represented in the AML stream)
274 * Type - Type associated with name
275 * InterpreterMode - IMODE_LOAD_PASS2 => add name if not found
276 * Flags - Flags describing the search restrictions
277 * WalkState - Current state of the walk
278 * ReturnNode - Where the Node is placed (if found
279 * or created successfully)
283 * DESCRIPTION: Find or enter the passed name in the name space.
284 * Log an error if name not found in Exec mode.
286 * MUTEX: Assumes namespace is locked.
288 ******************************************************************************/
292 ACPI_GENERIC_STATE
*ScopeInfo
,
294 ACPI_OBJECT_TYPE Type
,
295 ACPI_INTERPRETER_MODE InterpreterMode
,
297 ACPI_WALK_STATE
*WalkState
,
298 ACPI_NAMESPACE_NODE
**ReturnNode
)
301 char *Path
= Pathname
;
302 ACPI_NAMESPACE_NODE
*PrefixNode
;
303 ACPI_NAMESPACE_NODE
*CurrentNode
= NULL
;
304 ACPI_NAMESPACE_NODE
*ThisNode
= NULL
;
307 ACPI_NAME SimpleName
;
308 ACPI_OBJECT_TYPE TypeToCheckFor
;
309 ACPI_OBJECT_TYPE ThisSearchType
;
310 UINT32 SearchParentFlag
= ACPI_NS_SEARCH_PARENT
;
314 ACPI_FUNCTION_TRACE (NsLookup
);
319 return_ACPI_STATUS (AE_BAD_PARAMETER
);
323 ~(ACPI_NS_ERROR_IF_FOUND
| ACPI_NS_OVERRIDE_IF_FOUND
|
324 ACPI_NS_SEARCH_PARENT
);
325 *ReturnNode
= ACPI_ENTRY_NOT_FOUND
;
326 AcpiGbl_NsLookupCount
++;
328 if (!AcpiGbl_RootNode
)
330 return_ACPI_STATUS (AE_NO_NAMESPACE
);
333 /* Get the prefix scope. A null scope means use the root scope */
336 (!ScopeInfo
->Scope
.Node
))
338 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES
,
339 "Null scope prefix, using root node (%p)\n",
342 PrefixNode
= AcpiGbl_RootNode
;
346 PrefixNode
= ScopeInfo
->Scope
.Node
;
347 if (ACPI_GET_DESCRIPTOR_TYPE (PrefixNode
) != ACPI_DESC_TYPE_NAMED
)
349 ACPI_ERROR ((AE_INFO
, "%p is not a namespace node [%s]",
350 PrefixNode
, AcpiUtGetDescriptorName (PrefixNode
)));
351 return_ACPI_STATUS (AE_AML_INTERNAL
);
354 if (!(Flags
& ACPI_NS_PREFIX_IS_SCOPE
))
357 * This node might not be a actual "scope" node (such as a
358 * Device/Method, etc.) It could be a Package or other object
359 * node. Backup up the tree to find the containing scope node.
361 while (!AcpiNsOpensScope (PrefixNode
->Type
) &&
362 PrefixNode
->Type
!= ACPI_TYPE_ANY
)
364 PrefixNode
= PrefixNode
->Parent
;
369 /* Save type. TBD: may be no longer necessary */
371 TypeToCheckFor
= Type
;
374 * Begin examination of the actual pathname
378 /* A Null NamePath is allowed and refers to the root */
381 ThisNode
= AcpiGbl_RootNode
;
384 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES
,
385 "Null Pathname (Zero segments), Flags=%X\n", Flags
));
390 * Name pointer is valid (and must be in internal name format)
392 * Check for scope prefixes:
394 * As represented in the AML stream, a namepath consists of an
395 * optional scope prefix followed by a name segment part.
397 * If present, the scope prefix is either a Root Prefix (in
398 * which case the name is fully qualified), or one or more
399 * Parent Prefixes (in which case the name's scope is relative
400 * to the current scope).
402 if (*Path
== (UINT8
) AML_ROOT_PREFIX
)
404 /* Pathname is fully qualified, start from the root */
406 ThisNode
= AcpiGbl_RootNode
;
407 SearchParentFlag
= ACPI_NS_NO_UPSEARCH
;
409 /* Point to name segment part */
413 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES
,
414 "Path is absolute from root [%p]\n", ThisNode
));
418 /* Pathname is relative to current scope, start there */
420 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES
,
421 "Searching relative to prefix scope [%4.4s] (%p)\n",
422 AcpiUtGetNodeName (PrefixNode
), PrefixNode
));
425 * Handle multiple Parent Prefixes (carat) by just getting
426 * the parent node for each prefix instance.
428 ThisNode
= PrefixNode
;
430 while (*Path
== (UINT8
) AML_PARENT_PREFIX
)
432 /* Name is fully qualified, no search rules apply */
434 SearchParentFlag
= ACPI_NS_NO_UPSEARCH
;
437 * Point past this prefix to the name segment
438 * part or the next Parent Prefix
442 /* Backup to the parent node */
445 ThisNode
= ThisNode
->Parent
;
448 /* Current scope has no parent scope */
450 ACPI_ERROR ((AE_INFO
,
451 "%s: Path has too many parent prefixes (^) "
452 "- reached beyond root node", Pathname
));
453 return_ACPI_STATUS (AE_NOT_FOUND
);
457 if (SearchParentFlag
== ACPI_NS_NO_UPSEARCH
)
459 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES
,
460 "Search scope is [%4.4s], path has %u carat(s)\n",
461 AcpiUtGetNodeName (ThisNode
), NumCarats
));
466 * Determine the number of ACPI name segments in this pathname.
468 * The segment part consists of either:
469 * - A Null name segment (0)
470 * - A DualNamePrefix followed by two 4-byte name segments
471 * - A MultiNamePrefix followed by a byte indicating the
472 * number of segments and the segments themselves.
473 * - A single 4-byte name segment
475 * Examine the name prefix opcode, if any, to determine the number of
482 * Null name after a root or parent prefixes. We already
483 * have the correct target node and there are no name segments.
486 Type
= ThisNode
->Type
;
488 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES
,
489 "Prefix-only Pathname (Zero name segments), Flags=%X\n",
493 case AML_DUAL_NAME_PREFIX
:
495 /* More than one NameSeg, search rules do not apply */
497 SearchParentFlag
= ACPI_NS_NO_UPSEARCH
;
499 /* Two segments, point to first name segment */
504 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES
,
505 "Dual Pathname (2 segments, Flags=%X)\n", Flags
));
508 case AML_MULTI_NAME_PREFIX_OP
:
510 /* More than one NameSeg, search rules do not apply */
512 SearchParentFlag
= ACPI_NS_NO_UPSEARCH
;
514 /* Extract segment count, point to first name segment */
517 NumSegments
= (UINT32
) (UINT8
) *Path
;
520 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES
,
521 "Multi Pathname (%u Segments, Flags=%X)\n",
522 NumSegments
, Flags
));
527 * Not a Null name, no Dual or Multi prefix, hence there is
528 * only one name segment and Pathname is already pointing to it.
532 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES
,
533 "Simple Pathname (1 segment, Flags=%X)\n", Flags
));
537 ACPI_DEBUG_EXEC (AcpiNsPrintPathname (NumSegments
, Path
));
542 * Search namespace for each segment of the name. Loop through and
543 * verify (or add to the namespace) each name segment.
545 * The object type is significant only at the last name
546 * segment. (We don't care about the types along the path, only
547 * the type of the final target object.)
549 ThisSearchType
= ACPI_TYPE_ANY
;
550 CurrentNode
= ThisNode
;
551 while (NumSegments
&& CurrentNode
)
556 /* This is the last segment, enable typechecking */
558 ThisSearchType
= Type
;
561 * Only allow automatic parent search (search rules) if the caller
562 * requested it AND we have a single, non-fully-qualified NameSeg
564 if ((SearchParentFlag
!= ACPI_NS_NO_UPSEARCH
) &&
565 (Flags
& ACPI_NS_SEARCH_PARENT
))
567 LocalFlags
|= ACPI_NS_SEARCH_PARENT
;
570 /* Set error flag according to caller */
572 if (Flags
& ACPI_NS_ERROR_IF_FOUND
)
574 LocalFlags
|= ACPI_NS_ERROR_IF_FOUND
;
577 /* Set override flag according to caller */
579 if (Flags
& ACPI_NS_OVERRIDE_IF_FOUND
)
581 LocalFlags
|= ACPI_NS_OVERRIDE_IF_FOUND
;
585 /* Extract one ACPI name from the front of the pathname */
587 ACPI_MOVE_32_TO_32 (&SimpleName
, Path
);
589 /* Try to find the single (4 character) ACPI name */
591 Status
= AcpiNsSearchAndEnter (SimpleName
, WalkState
, CurrentNode
,
592 InterpreterMode
, ThisSearchType
, LocalFlags
, &ThisNode
);
593 if (ACPI_FAILURE (Status
))
595 if (Status
== AE_NOT_FOUND
)
597 /* Name not found in ACPI namespace */
599 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES
,
600 "Name [%4.4s] not found in scope [%4.4s] %p\n",
601 (char *) &SimpleName
, (char *) &CurrentNode
->Name
,
605 *ReturnNode
= ThisNode
;
606 return_ACPI_STATUS (Status
);
609 /* More segments to follow? */
614 * If we have an alias to an object that opens a scope (such as a
615 * device or processor), we need to dereference the alias here so
616 * that we can access any children of the original node (via the
617 * remaining segments).
619 if (ThisNode
->Type
== ACPI_TYPE_LOCAL_ALIAS
)
621 if (!ThisNode
->Object
)
623 return_ACPI_STATUS (AE_NOT_EXIST
);
626 if (AcpiNsOpensScope (((ACPI_NAMESPACE_NODE
*)
627 ThisNode
->Object
)->Type
))
629 ThisNode
= (ACPI_NAMESPACE_NODE
*) ThisNode
->Object
;
634 /* Special handling for the last segment (NumSegments == 0) */
639 * Sanity typecheck of the target object:
641 * If 1) This is the last segment (NumSegments == 0)
642 * 2) And we are looking for a specific type
643 * (Not checking for TYPE_ANY)
644 * 3) Which is not an alias
645 * 4) Which is not a local type (TYPE_SCOPE)
646 * 5) And the type of target object is known (not TYPE_ANY)
647 * 6) And target object does not match what we are looking for
649 * Then we have a type mismatch. Just warn and ignore it.
651 if ((TypeToCheckFor
!= ACPI_TYPE_ANY
) &&
652 (TypeToCheckFor
!= ACPI_TYPE_LOCAL_ALIAS
) &&
653 (TypeToCheckFor
!= ACPI_TYPE_LOCAL_METHOD_ALIAS
) &&
654 (TypeToCheckFor
!= ACPI_TYPE_LOCAL_SCOPE
) &&
655 (ThisNode
->Type
!= ACPI_TYPE_ANY
) &&
656 (ThisNode
->Type
!= TypeToCheckFor
))
658 /* Complain about a type mismatch */
660 ACPI_WARNING ((AE_INFO
,
661 "NsLookup: Type mismatch on %4.4s (%s), searching for (%s)",
662 ACPI_CAST_PTR (char, &SimpleName
),
663 AcpiUtGetTypeName (ThisNode
->Type
),
664 AcpiUtGetTypeName (TypeToCheckFor
)));
668 * If this is the last name segment and we are not looking for a
669 * specific type, but the type of found object is known, use that
670 * type to (later) see if it opens a scope.
672 if (Type
== ACPI_TYPE_ANY
)
674 Type
= ThisNode
->Type
;
678 /* Point to next name segment and make this node current */
680 Path
+= ACPI_NAME_SIZE
;
681 CurrentNode
= ThisNode
;
684 /* Always check if we need to open a new scope */
686 if (!(Flags
& ACPI_NS_DONT_OPEN_SCOPE
) && (WalkState
))
689 * If entry is a type which opens a scope, push the new scope on the
692 if (AcpiNsOpensScope (Type
))
694 Status
= AcpiDsScopeStackPush (ThisNode
, Type
, WalkState
);
695 if (ACPI_FAILURE (Status
))
697 return_ACPI_STATUS (Status
);
702 *ReturnNode
= ThisNode
;
703 return_ACPI_STATUS (AE_OK
);