1a159c266SJung-uk Kim /*******************************************************************************
2a159c266SJung-uk Kim *
3a159c266SJung-uk Kim * Module Name: nsaccess - Top-level functions for accessing ACPI namespace
4a159c266SJung-uk Kim *
5a159c266SJung-uk Kim ******************************************************************************/
6a159c266SJung-uk Kim
70d84335fSJung-uk Kim /******************************************************************************
80d84335fSJung-uk Kim *
90d84335fSJung-uk Kim * 1. Copyright Notice
100d84335fSJung-uk Kim *
11*58308fadSJung-uk Kim * Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.
12a159c266SJung-uk Kim * All rights reserved.
13a159c266SJung-uk Kim *
140d84335fSJung-uk Kim * 2. License
150d84335fSJung-uk Kim *
160d84335fSJung-uk Kim * 2.1. This is your license from Intel Corp. under its intellectual property
170d84335fSJung-uk Kim * rights. You may have additional license terms from the party that provided
180d84335fSJung-uk Kim * you this software, covering your right to use that party's intellectual
190d84335fSJung-uk Kim * property rights.
200d84335fSJung-uk Kim *
210d84335fSJung-uk Kim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
220d84335fSJung-uk Kim * copy of the source code appearing in this file ("Covered Code") an
230d84335fSJung-uk Kim * irrevocable, perpetual, worldwide license under Intel's copyrights in the
240d84335fSJung-uk Kim * base code distributed originally by Intel ("Original Intel Code") to copy,
250d84335fSJung-uk Kim * make derivatives, distribute, use and display any portion of the Covered
260d84335fSJung-uk Kim * Code in any form, with the right to sublicense such rights; and
270d84335fSJung-uk Kim *
280d84335fSJung-uk Kim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
290d84335fSJung-uk Kim * license (with the right to sublicense), under only those claims of Intel
300d84335fSJung-uk Kim * patents that are infringed by the Original Intel Code, to make, use, sell,
310d84335fSJung-uk Kim * offer to sell, and import the Covered Code and derivative works thereof
320d84335fSJung-uk Kim * solely to the minimum extent necessary to exercise the above copyright
330d84335fSJung-uk Kim * license, and in no event shall the patent license extend to any additions
340d84335fSJung-uk Kim * to or modifications of the Original Intel Code. No other license or right
350d84335fSJung-uk Kim * is granted directly or by implication, estoppel or otherwise;
360d84335fSJung-uk Kim *
370d84335fSJung-uk Kim * The above copyright and patent license is granted only if the following
380d84335fSJung-uk Kim * conditions are met:
390d84335fSJung-uk Kim *
400d84335fSJung-uk Kim * 3. Conditions
410d84335fSJung-uk Kim *
420d84335fSJung-uk Kim * 3.1. Redistribution of Source with Rights to Further Distribute Source.
430d84335fSJung-uk Kim * Redistribution of source code of any substantial portion of the Covered
440d84335fSJung-uk Kim * Code or modification with rights to further distribute source must include
450d84335fSJung-uk Kim * the above Copyright Notice, the above License, this list of Conditions,
460d84335fSJung-uk Kim * and the following Disclaimer and Export Compliance provision. In addition,
470d84335fSJung-uk Kim * Licensee must cause all Covered Code to which Licensee contributes to
480d84335fSJung-uk Kim * contain a file documenting the changes Licensee made to create that Covered
490d84335fSJung-uk Kim * Code and the date of any change. Licensee must include in that file the
500d84335fSJung-uk Kim * documentation of any changes made by any predecessor Licensee. Licensee
510d84335fSJung-uk Kim * must include a prominent statement that the modification is derived,
520d84335fSJung-uk Kim * directly or indirectly, from Original Intel Code.
530d84335fSJung-uk Kim *
540d84335fSJung-uk Kim * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
550d84335fSJung-uk Kim * Redistribution of source code of any substantial portion of the Covered
560d84335fSJung-uk Kim * Code or modification without rights to further distribute source must
570d84335fSJung-uk Kim * include the following Disclaimer and Export Compliance provision in the
580d84335fSJung-uk Kim * documentation and/or other materials provided with distribution. In
590d84335fSJung-uk Kim * addition, Licensee may not authorize further sublicense of source of any
600d84335fSJung-uk Kim * portion of the Covered Code, and must include terms to the effect that the
610d84335fSJung-uk Kim * license from Licensee to its licensee is limited to the intellectual
620d84335fSJung-uk Kim * property embodied in the software Licensee provides to its licensee, and
630d84335fSJung-uk Kim * not to intellectual property embodied in modifications its licensee may
640d84335fSJung-uk Kim * make.
650d84335fSJung-uk Kim *
660d84335fSJung-uk Kim * 3.3. Redistribution of Executable. Redistribution in executable form of any
670d84335fSJung-uk Kim * substantial portion of the Covered Code or modification must reproduce the
680d84335fSJung-uk Kim * above Copyright Notice, and the following Disclaimer and Export Compliance
690d84335fSJung-uk Kim * provision in the documentation and/or other materials provided with the
700d84335fSJung-uk Kim * distribution.
710d84335fSJung-uk Kim *
720d84335fSJung-uk Kim * 3.4. Intel retains all right, title, and interest in and to the Original
730d84335fSJung-uk Kim * Intel Code.
740d84335fSJung-uk Kim *
750d84335fSJung-uk Kim * 3.5. Neither the name Intel nor any other trademark owned or controlled by
760d84335fSJung-uk Kim * Intel shall be used in advertising or otherwise to promote the sale, use or
770d84335fSJung-uk Kim * other dealings in products derived from or relating to the Covered Code
780d84335fSJung-uk Kim * without prior written authorization from Intel.
790d84335fSJung-uk Kim *
800d84335fSJung-uk Kim * 4. Disclaimer and Export Compliance
810d84335fSJung-uk Kim *
820d84335fSJung-uk Kim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
830d84335fSJung-uk Kim * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
840d84335fSJung-uk Kim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
850d84335fSJung-uk Kim * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
860d84335fSJung-uk Kim * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
870d84335fSJung-uk Kim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
880d84335fSJung-uk Kim * PARTICULAR PURPOSE.
890d84335fSJung-uk Kim *
900d84335fSJung-uk Kim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
910d84335fSJung-uk Kim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
920d84335fSJung-uk Kim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
930d84335fSJung-uk Kim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
940d84335fSJung-uk Kim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
950d84335fSJung-uk Kim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
960d84335fSJung-uk Kim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
970d84335fSJung-uk Kim * LIMITED REMEDY.
980d84335fSJung-uk Kim *
990d84335fSJung-uk Kim * 4.3. Licensee shall not export, either directly or indirectly, any of this
1000d84335fSJung-uk Kim * software or system incorporating such software without first obtaining any
1010d84335fSJung-uk Kim * required license or other approval from the U. S. Department of Commerce or
1020d84335fSJung-uk Kim * any other agency or department of the United States Government. In the
1030d84335fSJung-uk Kim * event Licensee exports any such software from the United States or
1040d84335fSJung-uk Kim * re-exports any such software from a foreign destination, Licensee shall
1050d84335fSJung-uk Kim * ensure that the distribution and export/re-export of the software is in
1060d84335fSJung-uk Kim * compliance with all laws, regulations, orders, or other restrictions of the
1070d84335fSJung-uk Kim * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1080d84335fSJung-uk Kim * any of its subsidiaries will export/re-export any technical data, process,
1090d84335fSJung-uk Kim * software, or service, directly or indirectly, to any country for which the
1100d84335fSJung-uk Kim * United States government or any agency thereof requires an export license,
1110d84335fSJung-uk Kim * other governmental approval, or letter of assurance, without first obtaining
1120d84335fSJung-uk Kim * such license, approval or letter.
1130d84335fSJung-uk Kim *
1140d84335fSJung-uk Kim *****************************************************************************
1150d84335fSJung-uk Kim *
1160d84335fSJung-uk Kim * Alternatively, you may choose to be licensed under the terms of the
1170d84335fSJung-uk Kim * following license:
1180d84335fSJung-uk Kim *
119a159c266SJung-uk Kim * Redistribution and use in source and binary forms, with or without
120a159c266SJung-uk Kim * modification, are permitted provided that the following conditions
121a159c266SJung-uk Kim * are met:
122a159c266SJung-uk Kim * 1. Redistributions of source code must retain the above copyright
123a159c266SJung-uk Kim * notice, this list of conditions, and the following disclaimer,
124a159c266SJung-uk Kim * without modification.
125a159c266SJung-uk Kim * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126a159c266SJung-uk Kim * substantially similar to the "NO WARRANTY" disclaimer below
127a159c266SJung-uk Kim * ("Disclaimer") and any redistribution must be conditioned upon
128a159c266SJung-uk Kim * including a substantially similar Disclaimer requirement for further
129a159c266SJung-uk Kim * binary redistribution.
130a159c266SJung-uk Kim * 3. Neither the names of the above-listed copyright holders nor the names
131a159c266SJung-uk Kim * of any contributors may be used to endorse or promote products derived
132a159c266SJung-uk Kim * from this software without specific prior written permission.
133a159c266SJung-uk Kim *
1340d84335fSJung-uk Kim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1350d84335fSJung-uk Kim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1360d84335fSJung-uk Kim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1370d84335fSJung-uk Kim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1380d84335fSJung-uk Kim * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1390d84335fSJung-uk Kim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1400d84335fSJung-uk Kim * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1410d84335fSJung-uk Kim * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1420d84335fSJung-uk Kim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1430d84335fSJung-uk Kim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1440d84335fSJung-uk Kim * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1450d84335fSJung-uk Kim *
1460d84335fSJung-uk Kim * Alternatively, you may choose to be licensed under the terms of the
147a159c266SJung-uk Kim * GNU General Public License ("GPL") version 2 as published by the Free
148a159c266SJung-uk Kim * Software Foundation.
149a159c266SJung-uk Kim *
1500d84335fSJung-uk Kim *****************************************************************************/
151a159c266SJung-uk Kim
152a159c266SJung-uk Kim #include <contrib/dev/acpica/include/acpi.h>
153a159c266SJung-uk Kim #include <contrib/dev/acpica/include/accommon.h>
154a159c266SJung-uk Kim #include <contrib/dev/acpica/include/amlcode.h>
155a159c266SJung-uk Kim #include <contrib/dev/acpica/include/acnamesp.h>
156a159c266SJung-uk Kim #include <contrib/dev/acpica/include/acdispat.h>
157a159c266SJung-uk Kim
158af051161SJung-uk Kim #ifdef ACPI_ASL_COMPILER
159af051161SJung-uk Kim #include <contrib/dev/acpica/include/acdisasm.h>
160af051161SJung-uk Kim #endif
161a159c266SJung-uk Kim
162a159c266SJung-uk Kim #define _COMPONENT ACPI_NAMESPACE
163a159c266SJung-uk Kim ACPI_MODULE_NAME ("nsaccess")
164a159c266SJung-uk Kim
165a159c266SJung-uk Kim
166a159c266SJung-uk Kim /*******************************************************************************
167a159c266SJung-uk Kim *
168a159c266SJung-uk Kim * FUNCTION: AcpiNsRootInitialize
169a159c266SJung-uk Kim *
170a159c266SJung-uk Kim * PARAMETERS: None
171a159c266SJung-uk Kim *
172a159c266SJung-uk Kim * RETURN: Status
173a159c266SJung-uk Kim *
174a159c266SJung-uk Kim * DESCRIPTION: Allocate and initialize the default root named objects
175a159c266SJung-uk Kim *
176a159c266SJung-uk Kim * MUTEX: Locks namespace for entire execution
177a159c266SJung-uk Kim *
178a159c266SJung-uk Kim ******************************************************************************/
179a159c266SJung-uk Kim
180a159c266SJung-uk Kim ACPI_STATUS
AcpiNsRootInitialize(void)181a159c266SJung-uk Kim AcpiNsRootInitialize (
182a159c266SJung-uk Kim void)
183a159c266SJung-uk Kim {
184a159c266SJung-uk Kim ACPI_STATUS Status;
185a159c266SJung-uk Kim const ACPI_PREDEFINED_NAMES *InitVal = NULL;
186a159c266SJung-uk Kim ACPI_NAMESPACE_NODE *NewNode;
18737d7a5bcSJung-uk Kim ACPI_NAMESPACE_NODE *PrevNode = NULL;
188a159c266SJung-uk Kim ACPI_OPERAND_OBJECT *ObjDesc;
189a159c266SJung-uk Kim ACPI_STRING Val = NULL;
190a159c266SJung-uk Kim
191a159c266SJung-uk Kim
192a159c266SJung-uk Kim ACPI_FUNCTION_TRACE (NsRootInitialize);
193a159c266SJung-uk Kim
194a159c266SJung-uk Kim
195a159c266SJung-uk Kim Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
196a159c266SJung-uk Kim if (ACPI_FAILURE (Status))
197a159c266SJung-uk Kim {
198a159c266SJung-uk Kim return_ACPI_STATUS (Status);
199a159c266SJung-uk Kim }
200a159c266SJung-uk Kim
201a159c266SJung-uk Kim /*
202a159c266SJung-uk Kim * The global root ptr is initially NULL, so a non-NULL value indicates
203a159c266SJung-uk Kim * that AcpiNsRootInitialize() has already been called; just return.
204a159c266SJung-uk Kim */
205a159c266SJung-uk Kim if (AcpiGbl_RootNode)
206a159c266SJung-uk Kim {
207a159c266SJung-uk Kim Status = AE_OK;
208a159c266SJung-uk Kim goto UnlockAndExit;
209a159c266SJung-uk Kim }
210a159c266SJung-uk Kim
211a159c266SJung-uk Kim /*
212a159c266SJung-uk Kim * Tell the rest of the subsystem that the root is initialized
213a159c266SJung-uk Kim * (This is OK because the namespace is locked)
214a159c266SJung-uk Kim */
215a159c266SJung-uk Kim AcpiGbl_RootNode = &AcpiGbl_RootNodeStruct;
216a159c266SJung-uk Kim
21737d7a5bcSJung-uk Kim /* Enter the predefined names in the name table */
218a159c266SJung-uk Kim
219a159c266SJung-uk Kim ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
220a159c266SJung-uk Kim "Entering predefined entries into namespace\n"));
221a159c266SJung-uk Kim
22237d7a5bcSJung-uk Kim /*
22337d7a5bcSJung-uk Kim * Create the initial (default) namespace.
22437d7a5bcSJung-uk Kim * This namespace looks like something similar to this:
22537d7a5bcSJung-uk Kim *
22637d7a5bcSJung-uk Kim * ACPI Namespace (from Namespace Root):
22737d7a5bcSJung-uk Kim * 0 _GPE Scope 00203160 00
22837d7a5bcSJung-uk Kim * 0 _PR_ Scope 002031D0 00
22937d7a5bcSJung-uk Kim * 0 _SB_ Device 00203240 00 Notify Object: 0020ADD8
23037d7a5bcSJung-uk Kim * 0 _SI_ Scope 002032B0 00
23137d7a5bcSJung-uk Kim * 0 _TZ_ Device 00203320 00
23237d7a5bcSJung-uk Kim * 0 _REV Integer 00203390 00 = 0000000000000002
23337d7a5bcSJung-uk Kim * 0 _OS_ String 00203488 00 Len 14 "Microsoft Windows NT"
23437d7a5bcSJung-uk Kim * 0 _GL_ Mutex 00203580 00 Object 002035F0
23537d7a5bcSJung-uk Kim * 0 _OSI Method 00203678 00 Args 1 Len 0000 Aml 00000000
23637d7a5bcSJung-uk Kim */
237a159c266SJung-uk Kim for (InitVal = AcpiGbl_PreDefinedNames; InitVal->Name; InitVal++)
238a159c266SJung-uk Kim {
23937d7a5bcSJung-uk Kim Status = AE_OK;
24037d7a5bcSJung-uk Kim
241a159c266SJung-uk Kim /* _OSI is optional for now, will be permanent later */
242a159c266SJung-uk Kim
2435ef50723SJung-uk Kim if (!strcmp (InitVal->Name, "_OSI") && !AcpiGbl_CreateOsiMethod)
244a159c266SJung-uk Kim {
245a159c266SJung-uk Kim continue;
246a159c266SJung-uk Kim }
247a159c266SJung-uk Kim
24837d7a5bcSJung-uk Kim /*
24937d7a5bcSJung-uk Kim * Create, init, and link the new predefined name
25037d7a5bcSJung-uk Kim * Note: No need to use AcpiNsLookup here because all the
25137d7a5bcSJung-uk Kim * predefined names are at the root level. It is much easier to
25237d7a5bcSJung-uk Kim * just create and link the new node(s) here.
25337d7a5bcSJung-uk Kim */
254cfd1ed46SJung-uk Kim NewNode = AcpiNsCreateNode (*ACPI_CAST_PTR (UINT32, InitVal->Name));
25537d7a5bcSJung-uk Kim if (!NewNode)
256a159c266SJung-uk Kim {
25737d7a5bcSJung-uk Kim Status = AE_NO_MEMORY;
25837d7a5bcSJung-uk Kim goto UnlockAndExit;
259a159c266SJung-uk Kim }
260a159c266SJung-uk Kim
26137d7a5bcSJung-uk Kim NewNode->DescriptorType = ACPI_DESC_TYPE_NAMED;
26237d7a5bcSJung-uk Kim NewNode->Type = InitVal->Type;
26337d7a5bcSJung-uk Kim
26437d7a5bcSJung-uk Kim if (!PrevNode)
26537d7a5bcSJung-uk Kim {
26637d7a5bcSJung-uk Kim AcpiGbl_RootNodeStruct.Child = NewNode;
26737d7a5bcSJung-uk Kim }
26837d7a5bcSJung-uk Kim else
26937d7a5bcSJung-uk Kim {
27037d7a5bcSJung-uk Kim PrevNode->Peer = NewNode;
27137d7a5bcSJung-uk Kim }
27237d7a5bcSJung-uk Kim
27337d7a5bcSJung-uk Kim NewNode->Parent = &AcpiGbl_RootNodeStruct;
27437d7a5bcSJung-uk Kim PrevNode = NewNode;
27537d7a5bcSJung-uk Kim
276a159c266SJung-uk Kim /*
277a159c266SJung-uk Kim * Name entered successfully. If entry in PreDefinedNames[] specifies
278a159c266SJung-uk Kim * an initial value, create the initial value.
279a159c266SJung-uk Kim */
280a159c266SJung-uk Kim if (InitVal->Val)
281a159c266SJung-uk Kim {
282a159c266SJung-uk Kim Status = AcpiOsPredefinedOverride (InitVal, &Val);
283a159c266SJung-uk Kim if (ACPI_FAILURE (Status))
284a159c266SJung-uk Kim {
285a159c266SJung-uk Kim ACPI_ERROR ((AE_INFO,
286a159c266SJung-uk Kim "Could not override predefined %s",
287a159c266SJung-uk Kim InitVal->Name));
288a159c266SJung-uk Kim }
289a159c266SJung-uk Kim
290a159c266SJung-uk Kim if (!Val)
291a159c266SJung-uk Kim {
292a159c266SJung-uk Kim Val = InitVal->Val;
293a159c266SJung-uk Kim }
294a159c266SJung-uk Kim
295a159c266SJung-uk Kim /*
296a159c266SJung-uk Kim * Entry requests an initial value, allocate a
297a159c266SJung-uk Kim * descriptor for it.
298a159c266SJung-uk Kim */
299a159c266SJung-uk Kim ObjDesc = AcpiUtCreateInternalObject (InitVal->Type);
300a159c266SJung-uk Kim if (!ObjDesc)
301a159c266SJung-uk Kim {
302a159c266SJung-uk Kim Status = AE_NO_MEMORY;
303a159c266SJung-uk Kim goto UnlockAndExit;
304a159c266SJung-uk Kim }
305a159c266SJung-uk Kim
306a159c266SJung-uk Kim /*
307a159c266SJung-uk Kim * Convert value string from table entry to
308a159c266SJung-uk Kim * internal representation. Only types actually
309a159c266SJung-uk Kim * used for initial values are implemented here.
310a159c266SJung-uk Kim */
311a159c266SJung-uk Kim switch (InitVal->Type)
312a159c266SJung-uk Kim {
313a159c266SJung-uk Kim case ACPI_TYPE_METHOD:
314a9d8d09cSJung-uk Kim
315a159c266SJung-uk Kim ObjDesc->Method.ParamCount = (UINT8) ACPI_TO_INTEGER (Val);
316a159c266SJung-uk Kim ObjDesc->Common.Flags |= AOPOBJ_DATA_VALID;
317a159c266SJung-uk Kim
318a159c266SJung-uk Kim #if defined (ACPI_ASL_COMPILER)
319a159c266SJung-uk Kim
320a159c266SJung-uk Kim /* Save the parameter count for the iASL compiler */
321a159c266SJung-uk Kim
322a159c266SJung-uk Kim NewNode->Value = ObjDesc->Method.ParamCount;
323a159c266SJung-uk Kim #else
32437d7a5bcSJung-uk Kim /* Mark this as a very SPECIAL method (_OSI) */
325a159c266SJung-uk Kim
326a159c266SJung-uk Kim ObjDesc->Method.InfoFlags = ACPI_METHOD_INTERNAL_ONLY;
327a159c266SJung-uk Kim ObjDesc->Method.Dispatch.Implementation = AcpiUtOsiImplementation;
328a159c266SJung-uk Kim #endif
329a159c266SJung-uk Kim break;
330a159c266SJung-uk Kim
331a159c266SJung-uk Kim case ACPI_TYPE_INTEGER:
332a159c266SJung-uk Kim
333a159c266SJung-uk Kim ObjDesc->Integer.Value = ACPI_TO_INTEGER (Val);
334a159c266SJung-uk Kim break;
335a159c266SJung-uk Kim
336a159c266SJung-uk Kim case ACPI_TYPE_STRING:
337a159c266SJung-uk Kim
338a159c266SJung-uk Kim /* Build an object around the static string */
339a159c266SJung-uk Kim
3405ef50723SJung-uk Kim ObjDesc->String.Length = (UINT32) strlen (Val);
341a159c266SJung-uk Kim ObjDesc->String.Pointer = Val;
342a159c266SJung-uk Kim ObjDesc->Common.Flags |= AOPOBJ_STATIC_POINTER;
343a159c266SJung-uk Kim break;
344a159c266SJung-uk Kim
345a159c266SJung-uk Kim case ACPI_TYPE_MUTEX:
346a159c266SJung-uk Kim
347a159c266SJung-uk Kim ObjDesc->Mutex.Node = NewNode;
348a159c266SJung-uk Kim ObjDesc->Mutex.SyncLevel = (UINT8) (ACPI_TO_INTEGER (Val) - 1);
349a159c266SJung-uk Kim
350a159c266SJung-uk Kim /* Create a mutex */
351a159c266SJung-uk Kim
352a159c266SJung-uk Kim Status = AcpiOsCreateMutex (&ObjDesc->Mutex.OsMutex);
353a159c266SJung-uk Kim if (ACPI_FAILURE (Status))
354a159c266SJung-uk Kim {
355a159c266SJung-uk Kim AcpiUtRemoveReference (ObjDesc);
356a159c266SJung-uk Kim goto UnlockAndExit;
357a159c266SJung-uk Kim }
358a159c266SJung-uk Kim
359a159c266SJung-uk Kim /* Special case for ACPI Global Lock */
360a159c266SJung-uk Kim
3615ef50723SJung-uk Kim if (strcmp (InitVal->Name, "_GL_") == 0)
362a159c266SJung-uk Kim {
363a159c266SJung-uk Kim AcpiGbl_GlobalLockMutex = ObjDesc;
364a159c266SJung-uk Kim
365a159c266SJung-uk Kim /* Create additional counting semaphore for global lock */
366a159c266SJung-uk Kim
367a159c266SJung-uk Kim Status = AcpiOsCreateSemaphore (
368a159c266SJung-uk Kim 1, 0, &AcpiGbl_GlobalLockSemaphore);
369a159c266SJung-uk Kim if (ACPI_FAILURE (Status))
370a159c266SJung-uk Kim {
371a159c266SJung-uk Kim AcpiUtRemoveReference (ObjDesc);
372a159c266SJung-uk Kim goto UnlockAndExit;
373a159c266SJung-uk Kim }
374a159c266SJung-uk Kim }
375a159c266SJung-uk Kim break;
376a159c266SJung-uk Kim
377a159c266SJung-uk Kim default:
378a159c266SJung-uk Kim
379a159c266SJung-uk Kim ACPI_ERROR ((AE_INFO, "Unsupported initial type value 0x%X",
380a159c266SJung-uk Kim InitVal->Type));
381a159c266SJung-uk Kim AcpiUtRemoveReference (ObjDesc);
382a159c266SJung-uk Kim ObjDesc = NULL;
383a159c266SJung-uk Kim continue;
384a159c266SJung-uk Kim }
385a159c266SJung-uk Kim
386a159c266SJung-uk Kim /* Store pointer to value descriptor in the Node */
387a159c266SJung-uk Kim
388a159c266SJung-uk Kim Status = AcpiNsAttachObject (NewNode, ObjDesc,
389a159c266SJung-uk Kim ObjDesc->Common.Type);
390a159c266SJung-uk Kim
391a159c266SJung-uk Kim /* Remove local reference to the object */
392a159c266SJung-uk Kim
393a159c266SJung-uk Kim AcpiUtRemoveReference (ObjDesc);
394a159c266SJung-uk Kim }
395a159c266SJung-uk Kim }
396a159c266SJung-uk Kim
397a159c266SJung-uk Kim UnlockAndExit:
398a159c266SJung-uk Kim (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
399a159c266SJung-uk Kim
400a159c266SJung-uk Kim /* Save a handle to "_GPE", it is always present */
401a159c266SJung-uk Kim
402a159c266SJung-uk Kim if (ACPI_SUCCESS (Status))
403a159c266SJung-uk Kim {
404a159c266SJung-uk Kim Status = AcpiNsGetNode (NULL, "\\_GPE", ACPI_NS_NO_UPSEARCH,
405a159c266SJung-uk Kim &AcpiGbl_FadtGpeDevice);
406a159c266SJung-uk Kim }
407a159c266SJung-uk Kim
408a159c266SJung-uk Kim return_ACPI_STATUS (Status);
409a159c266SJung-uk Kim }
410a159c266SJung-uk Kim
411a159c266SJung-uk Kim
412a159c266SJung-uk Kim /*******************************************************************************
413a159c266SJung-uk Kim *
414a159c266SJung-uk Kim * FUNCTION: AcpiNsLookup
415a159c266SJung-uk Kim *
416a159c266SJung-uk Kim * PARAMETERS: ScopeInfo - Current scope info block
417a159c266SJung-uk Kim * Pathname - Search pathname, in internal format
418a159c266SJung-uk Kim * (as represented in the AML stream)
419a159c266SJung-uk Kim * Type - Type associated with name
420a159c266SJung-uk Kim * InterpreterMode - IMODE_LOAD_PASS2 => add name if not found
421a159c266SJung-uk Kim * Flags - Flags describing the search restrictions
422a159c266SJung-uk Kim * WalkState - Current state of the walk
423a159c266SJung-uk Kim * ReturnNode - Where the Node is placed (if found
424a159c266SJung-uk Kim * or created successfully)
425a159c266SJung-uk Kim *
426a159c266SJung-uk Kim * RETURN: Status
427a159c266SJung-uk Kim *
428a159c266SJung-uk Kim * DESCRIPTION: Find or enter the passed name in the name space.
429a159c266SJung-uk Kim * Log an error if name not found in Exec mode.
430a159c266SJung-uk Kim *
431a159c266SJung-uk Kim * MUTEX: Assumes namespace is locked.
432a159c266SJung-uk Kim *
433a159c266SJung-uk Kim ******************************************************************************/
434a159c266SJung-uk Kim
435a159c266SJung-uk Kim ACPI_STATUS
AcpiNsLookup(ACPI_GENERIC_STATE * ScopeInfo,char * Pathname,ACPI_OBJECT_TYPE Type,ACPI_INTERPRETER_MODE InterpreterMode,UINT32 Flags,ACPI_WALK_STATE * WalkState,ACPI_NAMESPACE_NODE ** ReturnNode)436a159c266SJung-uk Kim AcpiNsLookup (
437a159c266SJung-uk Kim ACPI_GENERIC_STATE *ScopeInfo,
438a159c266SJung-uk Kim char *Pathname,
439a159c266SJung-uk Kim ACPI_OBJECT_TYPE Type,
440a159c266SJung-uk Kim ACPI_INTERPRETER_MODE InterpreterMode,
441a159c266SJung-uk Kim UINT32 Flags,
442a159c266SJung-uk Kim ACPI_WALK_STATE *WalkState,
443a159c266SJung-uk Kim ACPI_NAMESPACE_NODE **ReturnNode)
444a159c266SJung-uk Kim {
445a159c266SJung-uk Kim ACPI_STATUS Status;
446a159c266SJung-uk Kim char *Path = Pathname;
4475f9b24faSJung-uk Kim char *ExternalPath;
448a159c266SJung-uk Kim ACPI_NAMESPACE_NODE *PrefixNode;
449a159c266SJung-uk Kim ACPI_NAMESPACE_NODE *CurrentNode = NULL;
450a159c266SJung-uk Kim ACPI_NAMESPACE_NODE *ThisNode = NULL;
451a159c266SJung-uk Kim UINT32 NumSegments;
45262e841ccSJung-uk Kim #ifdef ACPI_DEBUG_OUTPUT
453a159c266SJung-uk Kim UINT32 NumCarats;
45462e841ccSJung-uk Kim #endif
455a159c266SJung-uk Kim ACPI_NAME SimpleName;
456a159c266SJung-uk Kim ACPI_OBJECT_TYPE TypeToCheckFor;
457a159c266SJung-uk Kim ACPI_OBJECT_TYPE ThisSearchType;
458a159c266SJung-uk Kim UINT32 SearchParentFlag = ACPI_NS_SEARCH_PARENT;
459a159c266SJung-uk Kim UINT32 LocalFlags;
4604a38ee6dSJung-uk Kim ACPI_INTERPRETER_MODE LocalInterpreterMode;
461a159c266SJung-uk Kim
462a159c266SJung-uk Kim
463a159c266SJung-uk Kim ACPI_FUNCTION_TRACE (NsLookup);
464a159c266SJung-uk Kim
465a159c266SJung-uk Kim
466a159c266SJung-uk Kim if (!ReturnNode)
467a159c266SJung-uk Kim {
468a159c266SJung-uk Kim return_ACPI_STATUS (AE_BAD_PARAMETER);
469a159c266SJung-uk Kim }
470a159c266SJung-uk Kim
4715ef50723SJung-uk Kim LocalFlags = Flags &
4725ef50723SJung-uk Kim ~(ACPI_NS_ERROR_IF_FOUND | ACPI_NS_OVERRIDE_IF_FOUND |
4735ef50723SJung-uk Kim ACPI_NS_SEARCH_PARENT);
474a159c266SJung-uk Kim *ReturnNode = ACPI_ENTRY_NOT_FOUND;
475a159c266SJung-uk Kim AcpiGbl_NsLookupCount++;
476a159c266SJung-uk Kim
477a159c266SJung-uk Kim if (!AcpiGbl_RootNode)
478a159c266SJung-uk Kim {
479a159c266SJung-uk Kim return_ACPI_STATUS (AE_NO_NAMESPACE);
480a159c266SJung-uk Kim }
481a159c266SJung-uk Kim
482a159c266SJung-uk Kim /* Get the prefix scope. A null scope means use the root scope */
483a159c266SJung-uk Kim
484a159c266SJung-uk Kim if ((!ScopeInfo) ||
485a159c266SJung-uk Kim (!ScopeInfo->Scope.Node))
486a159c266SJung-uk Kim {
487a159c266SJung-uk Kim ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
488a159c266SJung-uk Kim "Null scope prefix, using root node (%p)\n",
489a159c266SJung-uk Kim AcpiGbl_RootNode));
490a159c266SJung-uk Kim
491a159c266SJung-uk Kim PrefixNode = AcpiGbl_RootNode;
492a159c266SJung-uk Kim }
493a159c266SJung-uk Kim else
494a159c266SJung-uk Kim {
495a159c266SJung-uk Kim PrefixNode = ScopeInfo->Scope.Node;
496a159c266SJung-uk Kim if (ACPI_GET_DESCRIPTOR_TYPE (PrefixNode) != ACPI_DESC_TYPE_NAMED)
497a159c266SJung-uk Kim {
498a159c266SJung-uk Kim ACPI_ERROR ((AE_INFO, "%p is not a namespace node [%s]",
499a159c266SJung-uk Kim PrefixNode, AcpiUtGetDescriptorName (PrefixNode)));
500a159c266SJung-uk Kim return_ACPI_STATUS (AE_AML_INTERNAL);
501a159c266SJung-uk Kim }
502a159c266SJung-uk Kim
503a159c266SJung-uk Kim if (!(Flags & ACPI_NS_PREFIX_IS_SCOPE))
504a159c266SJung-uk Kim {
505a159c266SJung-uk Kim /*
506a159c266SJung-uk Kim * This node might not be a actual "scope" node (such as a
507a159c266SJung-uk Kim * Device/Method, etc.) It could be a Package or other object
508a159c266SJung-uk Kim * node. Backup up the tree to find the containing scope node.
509a159c266SJung-uk Kim */
510a159c266SJung-uk Kim while (!AcpiNsOpensScope (PrefixNode->Type) &&
511a159c266SJung-uk Kim PrefixNode->Type != ACPI_TYPE_ANY)
512a159c266SJung-uk Kim {
513a159c266SJung-uk Kim PrefixNode = PrefixNode->Parent;
514a159c266SJung-uk Kim }
515a159c266SJung-uk Kim }
516a159c266SJung-uk Kim }
517a159c266SJung-uk Kim
518a159c266SJung-uk Kim /* Save type. TBD: may be no longer necessary */
519a159c266SJung-uk Kim
520a159c266SJung-uk Kim TypeToCheckFor = Type;
521a159c266SJung-uk Kim
522a159c266SJung-uk Kim /*
523a159c266SJung-uk Kim * Begin examination of the actual pathname
524a159c266SJung-uk Kim */
525a159c266SJung-uk Kim if (!Pathname)
526a159c266SJung-uk Kim {
527a159c266SJung-uk Kim /* A Null NamePath is allowed and refers to the root */
528a159c266SJung-uk Kim
529a159c266SJung-uk Kim NumSegments = 0;
530a159c266SJung-uk Kim ThisNode = AcpiGbl_RootNode;
531a159c266SJung-uk Kim Path = "";
532a159c266SJung-uk Kim
533a159c266SJung-uk Kim ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
534a159c266SJung-uk Kim "Null Pathname (Zero segments), Flags=%X\n", Flags));
535a159c266SJung-uk Kim }
536a159c266SJung-uk Kim else
537a159c266SJung-uk Kim {
538a159c266SJung-uk Kim /*
539a159c266SJung-uk Kim * Name pointer is valid (and must be in internal name format)
540a159c266SJung-uk Kim *
541a159c266SJung-uk Kim * Check for scope prefixes:
542a159c266SJung-uk Kim *
543a159c266SJung-uk Kim * As represented in the AML stream, a namepath consists of an
544a159c266SJung-uk Kim * optional scope prefix followed by a name segment part.
545a159c266SJung-uk Kim *
546a159c266SJung-uk Kim * If present, the scope prefix is either a Root Prefix (in
547a159c266SJung-uk Kim * which case the name is fully qualified), or one or more
548a159c266SJung-uk Kim * Parent Prefixes (in which case the name's scope is relative
549a159c266SJung-uk Kim * to the current scope).
550a159c266SJung-uk Kim */
551a159c266SJung-uk Kim if (*Path == (UINT8) AML_ROOT_PREFIX)
552a159c266SJung-uk Kim {
553a159c266SJung-uk Kim /* Pathname is fully qualified, start from the root */
554a159c266SJung-uk Kim
555a159c266SJung-uk Kim ThisNode = AcpiGbl_RootNode;
556a159c266SJung-uk Kim SearchParentFlag = ACPI_NS_NO_UPSEARCH;
557a159c266SJung-uk Kim
558a159c266SJung-uk Kim /* Point to name segment part */
559a159c266SJung-uk Kim
560a159c266SJung-uk Kim Path++;
561a159c266SJung-uk Kim
562a159c266SJung-uk Kim ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
563a159c266SJung-uk Kim "Path is absolute from root [%p]\n", ThisNode));
564a159c266SJung-uk Kim }
565a159c266SJung-uk Kim else
566a159c266SJung-uk Kim {
567a159c266SJung-uk Kim /* Pathname is relative to current scope, start there */
568a159c266SJung-uk Kim
569a159c266SJung-uk Kim ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
570a159c266SJung-uk Kim "Searching relative to prefix scope [%4.4s] (%p)\n",
571a159c266SJung-uk Kim AcpiUtGetNodeName (PrefixNode), PrefixNode));
572a159c266SJung-uk Kim
573a159c266SJung-uk Kim /*
574a159c266SJung-uk Kim * Handle multiple Parent Prefixes (carat) by just getting
575a159c266SJung-uk Kim * the parent node for each prefix instance.
576a159c266SJung-uk Kim */
577a159c266SJung-uk Kim ThisNode = PrefixNode;
57862e841ccSJung-uk Kim #ifdef ACPI_DEBUG_OUTPUT
579a159c266SJung-uk Kim NumCarats = 0;
58062e841ccSJung-uk Kim #endif
581a159c266SJung-uk Kim while (*Path == (UINT8) AML_PARENT_PREFIX)
582a159c266SJung-uk Kim {
583a159c266SJung-uk Kim /* Name is fully qualified, no search rules apply */
584a159c266SJung-uk Kim
585a159c266SJung-uk Kim SearchParentFlag = ACPI_NS_NO_UPSEARCH;
586a159c266SJung-uk Kim
587a159c266SJung-uk Kim /*
588a159c266SJung-uk Kim * Point past this prefix to the name segment
589a159c266SJung-uk Kim * part or the next Parent Prefix
590a159c266SJung-uk Kim */
591a159c266SJung-uk Kim Path++;
592a159c266SJung-uk Kim
593a159c266SJung-uk Kim /* Backup to the parent node */
594a159c266SJung-uk Kim
59562e841ccSJung-uk Kim #ifdef ACPI_DEBUG_OUTPUT
596a159c266SJung-uk Kim NumCarats++;
59762e841ccSJung-uk Kim #endif
598a159c266SJung-uk Kim ThisNode = ThisNode->Parent;
599a159c266SJung-uk Kim if (!ThisNode)
600a159c266SJung-uk Kim {
6015f9b24faSJung-uk Kim /*
6025f9b24faSJung-uk Kim * Current scope has no parent scope. Externalize
6035f9b24faSJung-uk Kim * the internal path for error message.
6045f9b24faSJung-uk Kim */
6055f9b24faSJung-uk Kim Status = AcpiNsExternalizeName (ACPI_UINT32_MAX, Pathname,
6065f9b24faSJung-uk Kim NULL, &ExternalPath);
6075f9b24faSJung-uk Kim if (ACPI_SUCCESS (Status))
6085f9b24faSJung-uk Kim {
609a159c266SJung-uk Kim ACPI_ERROR ((AE_INFO,
6105f9b24faSJung-uk Kim "%s: Path has too many parent prefixes (^)",
6115f9b24faSJung-uk Kim ExternalPath));
6125f9b24faSJung-uk Kim
6135f9b24faSJung-uk Kim ACPI_FREE (ExternalPath);
6145f9b24faSJung-uk Kim }
6155f9b24faSJung-uk Kim
616a159c266SJung-uk Kim return_ACPI_STATUS (AE_NOT_FOUND);
617a159c266SJung-uk Kim }
618a159c266SJung-uk Kim }
619a159c266SJung-uk Kim
62062e841ccSJung-uk Kim #ifdef ACPI_DEBUG_OUTPUT
621a159c266SJung-uk Kim if (SearchParentFlag == ACPI_NS_NO_UPSEARCH)
622a159c266SJung-uk Kim {
623a159c266SJung-uk Kim ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
624a159c266SJung-uk Kim "Search scope is [%4.4s], path has %u carat(s)\n",
625a159c266SJung-uk Kim AcpiUtGetNodeName (ThisNode), NumCarats));
626a159c266SJung-uk Kim }
62762e841ccSJung-uk Kim #endif
628a159c266SJung-uk Kim }
629a159c266SJung-uk Kim
630a159c266SJung-uk Kim /*
631a159c266SJung-uk Kim * Determine the number of ACPI name segments in this pathname.
632a159c266SJung-uk Kim *
633a159c266SJung-uk Kim * The segment part consists of either:
634a159c266SJung-uk Kim * - A Null name segment (0)
635a159c266SJung-uk Kim * - A DualNamePrefix followed by two 4-byte name segments
636a159c266SJung-uk Kim * - A MultiNamePrefix followed by a byte indicating the
637a159c266SJung-uk Kim * number of segments and the segments themselves.
638a159c266SJung-uk Kim * - A single 4-byte name segment
639a159c266SJung-uk Kim *
640a159c266SJung-uk Kim * Examine the name prefix opcode, if any, to determine the number of
641a159c266SJung-uk Kim * segments.
642a159c266SJung-uk Kim */
643a159c266SJung-uk Kim switch (*Path)
644a159c266SJung-uk Kim {
645a159c266SJung-uk Kim case 0:
646a159c266SJung-uk Kim /*
647a159c266SJung-uk Kim * Null name after a root or parent prefixes. We already
648a159c266SJung-uk Kim * have the correct target node and there are no name segments.
649a159c266SJung-uk Kim */
650a159c266SJung-uk Kim NumSegments = 0;
651a159c266SJung-uk Kim Type = ThisNode->Type;
652a159c266SJung-uk Kim
653a159c266SJung-uk Kim ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
654a159c266SJung-uk Kim "Prefix-only Pathname (Zero name segments), Flags=%X\n",
655a159c266SJung-uk Kim Flags));
656a159c266SJung-uk Kim break;
657a159c266SJung-uk Kim
658a159c266SJung-uk Kim case AML_DUAL_NAME_PREFIX:
659a159c266SJung-uk Kim
660a159c266SJung-uk Kim /* More than one NameSeg, search rules do not apply */
661a159c266SJung-uk Kim
662a159c266SJung-uk Kim SearchParentFlag = ACPI_NS_NO_UPSEARCH;
663a159c266SJung-uk Kim
664a159c266SJung-uk Kim /* Two segments, point to first name segment */
665a159c266SJung-uk Kim
666a159c266SJung-uk Kim NumSegments = 2;
667a159c266SJung-uk Kim Path++;
668a159c266SJung-uk Kim
669a159c266SJung-uk Kim ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
670a159c266SJung-uk Kim "Dual Pathname (2 segments, Flags=%X)\n", Flags));
671a159c266SJung-uk Kim break;
672a159c266SJung-uk Kim
6730d84335fSJung-uk Kim case AML_MULTI_NAME_PREFIX:
674a159c266SJung-uk Kim
675a159c266SJung-uk Kim /* More than one NameSeg, search rules do not apply */
676a159c266SJung-uk Kim
677a159c266SJung-uk Kim SearchParentFlag = ACPI_NS_NO_UPSEARCH;
678a159c266SJung-uk Kim
679a159c266SJung-uk Kim /* Extract segment count, point to first name segment */
680a159c266SJung-uk Kim
681a159c266SJung-uk Kim Path++;
682a159c266SJung-uk Kim NumSegments = (UINT32) (UINT8) *Path;
683a159c266SJung-uk Kim Path++;
684a159c266SJung-uk Kim
685a159c266SJung-uk Kim ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
686a159c266SJung-uk Kim "Multi Pathname (%u Segments, Flags=%X)\n",
687a159c266SJung-uk Kim NumSegments, Flags));
688a159c266SJung-uk Kim break;
689a159c266SJung-uk Kim
690a159c266SJung-uk Kim default:
691a159c266SJung-uk Kim /*
692a159c266SJung-uk Kim * Not a Null name, no Dual or Multi prefix, hence there is
693a159c266SJung-uk Kim * only one name segment and Pathname is already pointing to it.
694a159c266SJung-uk Kim */
695a159c266SJung-uk Kim NumSegments = 1;
696a159c266SJung-uk Kim
697a159c266SJung-uk Kim ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
698a159c266SJung-uk Kim "Simple Pathname (1 segment, Flags=%X)\n", Flags));
699a159c266SJung-uk Kim break;
700a159c266SJung-uk Kim }
701a159c266SJung-uk Kim
702a159c266SJung-uk Kim ACPI_DEBUG_EXEC (AcpiNsPrintPathname (NumSegments, Path));
703a159c266SJung-uk Kim }
704a159c266SJung-uk Kim
705a159c266SJung-uk Kim
706a159c266SJung-uk Kim /*
707a159c266SJung-uk Kim * Search namespace for each segment of the name. Loop through and
708a159c266SJung-uk Kim * verify (or add to the namespace) each name segment.
709a159c266SJung-uk Kim *
710a159c266SJung-uk Kim * The object type is significant only at the last name
711a159c266SJung-uk Kim * segment. (We don't care about the types along the path, only
712a159c266SJung-uk Kim * the type of the final target object.)
713a159c266SJung-uk Kim */
714a159c266SJung-uk Kim ThisSearchType = ACPI_TYPE_ANY;
715a159c266SJung-uk Kim CurrentNode = ThisNode;
7164a38ee6dSJung-uk Kim
717a159c266SJung-uk Kim while (NumSegments && CurrentNode)
718a159c266SJung-uk Kim {
719a159c266SJung-uk Kim NumSegments--;
720a159c266SJung-uk Kim if (!NumSegments)
721a159c266SJung-uk Kim {
722a159c266SJung-uk Kim /* This is the last segment, enable typechecking */
723a159c266SJung-uk Kim
724a159c266SJung-uk Kim ThisSearchType = Type;
725a159c266SJung-uk Kim
726a159c266SJung-uk Kim /*
727a159c266SJung-uk Kim * Only allow automatic parent search (search rules) if the caller
728a159c266SJung-uk Kim * requested it AND we have a single, non-fully-qualified NameSeg
729a159c266SJung-uk Kim */
730a159c266SJung-uk Kim if ((SearchParentFlag != ACPI_NS_NO_UPSEARCH) &&
731a159c266SJung-uk Kim (Flags & ACPI_NS_SEARCH_PARENT))
732a159c266SJung-uk Kim {
733a159c266SJung-uk Kim LocalFlags |= ACPI_NS_SEARCH_PARENT;
734a159c266SJung-uk Kim }
735a159c266SJung-uk Kim
736a159c266SJung-uk Kim /* Set error flag according to caller */
737a159c266SJung-uk Kim
738a159c266SJung-uk Kim if (Flags & ACPI_NS_ERROR_IF_FOUND)
739a159c266SJung-uk Kim {
740a159c266SJung-uk Kim LocalFlags |= ACPI_NS_ERROR_IF_FOUND;
741a159c266SJung-uk Kim }
7425ef50723SJung-uk Kim
7435ef50723SJung-uk Kim /* Set override flag according to caller */
7445ef50723SJung-uk Kim
7455ef50723SJung-uk Kim if (Flags & ACPI_NS_OVERRIDE_IF_FOUND)
7465ef50723SJung-uk Kim {
7475ef50723SJung-uk Kim LocalFlags |= ACPI_NS_OVERRIDE_IF_FOUND;
7485ef50723SJung-uk Kim }
749a159c266SJung-uk Kim }
750a159c266SJung-uk Kim
7514a38ee6dSJung-uk Kim /* Handle opcodes that create a new NameSeg via a full NamePath */
7524a38ee6dSJung-uk Kim
7534a38ee6dSJung-uk Kim LocalInterpreterMode = InterpreterMode;
7544a38ee6dSJung-uk Kim if ((Flags & ACPI_NS_PREFIX_MUST_EXIST) && (NumSegments > 0))
7554a38ee6dSJung-uk Kim {
7564a38ee6dSJung-uk Kim /* Every element of the path must exist (except for the final NameSeg) */
7574a38ee6dSJung-uk Kim
7584a38ee6dSJung-uk Kim LocalInterpreterMode = ACPI_IMODE_EXECUTE;
7594a38ee6dSJung-uk Kim }
7604a38ee6dSJung-uk Kim
761a159c266SJung-uk Kim /* Extract one ACPI name from the front of the pathname */
762a159c266SJung-uk Kim
763a159c266SJung-uk Kim ACPI_MOVE_32_TO_32 (&SimpleName, Path);
764a159c266SJung-uk Kim
765a159c266SJung-uk Kim /* Try to find the single (4 character) ACPI name */
766a159c266SJung-uk Kim
767a159c266SJung-uk Kim Status = AcpiNsSearchAndEnter (SimpleName, WalkState, CurrentNode,
7684a38ee6dSJung-uk Kim LocalInterpreterMode, ThisSearchType, LocalFlags, &ThisNode);
769a159c266SJung-uk Kim if (ACPI_FAILURE (Status))
770a159c266SJung-uk Kim {
771a159c266SJung-uk Kim if (Status == AE_NOT_FOUND)
772a159c266SJung-uk Kim {
7734a38ee6dSJung-uk Kim #if !defined ACPI_ASL_COMPILER /* Note: iASL reports this error by itself, not needed here */
7744a38ee6dSJung-uk Kim if (Flags & ACPI_NS_PREFIX_MUST_EXIST)
7754a38ee6dSJung-uk Kim {
7764a38ee6dSJung-uk Kim AcpiOsPrintf (ACPI_MSG_BIOS_ERROR
777a009b7dcSJung-uk Kim "Object does not exist: %4.4s\n", (char *) &SimpleName);
7784a38ee6dSJung-uk Kim }
7794a38ee6dSJung-uk Kim #endif
780a159c266SJung-uk Kim /* Name not found in ACPI namespace */
781a159c266SJung-uk Kim
782a159c266SJung-uk Kim ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
783a159c266SJung-uk Kim "Name [%4.4s] not found in scope [%4.4s] %p\n",
784a159c266SJung-uk Kim (char *) &SimpleName, (char *) &CurrentNode->Name,
785a159c266SJung-uk Kim CurrentNode));
786a159c266SJung-uk Kim }
787a159c266SJung-uk Kim
78851f42badSJung-uk Kim #ifdef ACPI_EXEC_APP
78951f42badSJung-uk Kim if ((Status == AE_ALREADY_EXISTS) &&
79051f42badSJung-uk Kim (ThisNode->Flags & ANOBJ_NODE_EARLY_INIT))
79151f42badSJung-uk Kim {
79251f42badSJung-uk Kim ThisNode->Flags &= ~ANOBJ_NODE_EARLY_INIT;
79351f42badSJung-uk Kim Status = AE_OK;
79451f42badSJung-uk Kim }
79551f42badSJung-uk Kim #endif
79651f42badSJung-uk Kim
797af051161SJung-uk Kim #ifdef ACPI_ASL_COMPILER
798af051161SJung-uk Kim /*
799af051161SJung-uk Kim * If this ACPI name already exists within the namespace as an
800af051161SJung-uk Kim * external declaration, then mark the external as a conflicting
801af051161SJung-uk Kim * declaration and proceed to process the current node as if it did
802af051161SJung-uk Kim * not exist in the namespace. If this node is not processed as
803af051161SJung-uk Kim * normal, then it could cause improper namespace resolution
804af051161SJung-uk Kim * by failing to open a new scope.
805af051161SJung-uk Kim */
806af051161SJung-uk Kim if (AcpiGbl_DisasmFlag &&
807af051161SJung-uk Kim (Status == AE_ALREADY_EXISTS) &&
808af051161SJung-uk Kim ((ThisNode->Flags & ANOBJ_IS_EXTERNAL) ||
809af051161SJung-uk Kim (WalkState && WalkState->Opcode == AML_EXTERNAL_OP)))
810af051161SJung-uk Kim {
811af051161SJung-uk Kim ThisNode->Flags &= ~ANOBJ_IS_EXTERNAL;
812af051161SJung-uk Kim ThisNode->Type = (UINT8)ThisSearchType;
813af051161SJung-uk Kim if (WalkState->Opcode != AML_EXTERNAL_OP)
814af051161SJung-uk Kim {
815af051161SJung-uk Kim AcpiDmMarkExternalConflict (ThisNode);
816af051161SJung-uk Kim }
817af051161SJung-uk Kim break;
818af051161SJung-uk Kim }
819af051161SJung-uk Kim #endif
820af051161SJung-uk Kim
821a159c266SJung-uk Kim *ReturnNode = ThisNode;
822a159c266SJung-uk Kim return_ACPI_STATUS (Status);
823a159c266SJung-uk Kim }
824a159c266SJung-uk Kim
825a159c266SJung-uk Kim /* More segments to follow? */
826a159c266SJung-uk Kim
827a159c266SJung-uk Kim if (NumSegments > 0)
828a159c266SJung-uk Kim {
829a159c266SJung-uk Kim /*
830a159c266SJung-uk Kim * If we have an alias to an object that opens a scope (such as a
831a159c266SJung-uk Kim * device or processor), we need to dereference the alias here so
832a159c266SJung-uk Kim * that we can access any children of the original node (via the
833a159c266SJung-uk Kim * remaining segments).
834a159c266SJung-uk Kim */
835a159c266SJung-uk Kim if (ThisNode->Type == ACPI_TYPE_LOCAL_ALIAS)
836a159c266SJung-uk Kim {
837a159c266SJung-uk Kim if (!ThisNode->Object)
838a159c266SJung-uk Kim {
839a159c266SJung-uk Kim return_ACPI_STATUS (AE_NOT_EXIST);
840a159c266SJung-uk Kim }
841a159c266SJung-uk Kim
842a159c266SJung-uk Kim if (AcpiNsOpensScope (((ACPI_NAMESPACE_NODE *)
843a159c266SJung-uk Kim ThisNode->Object)->Type))
844a159c266SJung-uk Kim {
845a159c266SJung-uk Kim ThisNode = (ACPI_NAMESPACE_NODE *) ThisNode->Object;
846a159c266SJung-uk Kim }
847a159c266SJung-uk Kim }
848a159c266SJung-uk Kim }
849a159c266SJung-uk Kim
850a159c266SJung-uk Kim /* Special handling for the last segment (NumSegments == 0) */
851a159c266SJung-uk Kim
852a159c266SJung-uk Kim else
853a159c266SJung-uk Kim {
854a159c266SJung-uk Kim /*
855a159c266SJung-uk Kim * Sanity typecheck of the target object:
856a159c266SJung-uk Kim *
857a159c266SJung-uk Kim * If 1) This is the last segment (NumSegments == 0)
858a159c266SJung-uk Kim * 2) And we are looking for a specific type
859a159c266SJung-uk Kim * (Not checking for TYPE_ANY)
860a159c266SJung-uk Kim * 3) Which is not an alias
861a159c266SJung-uk Kim * 4) Which is not a local type (TYPE_SCOPE)
862a159c266SJung-uk Kim * 5) And the type of target object is known (not TYPE_ANY)
863a159c266SJung-uk Kim * 6) And target object does not match what we are looking for
864a159c266SJung-uk Kim *
865a159c266SJung-uk Kim * Then we have a type mismatch. Just warn and ignore it.
866a159c266SJung-uk Kim */
867a159c266SJung-uk Kim if ((TypeToCheckFor != ACPI_TYPE_ANY) &&
868a159c266SJung-uk Kim (TypeToCheckFor != ACPI_TYPE_LOCAL_ALIAS) &&
869a159c266SJung-uk Kim (TypeToCheckFor != ACPI_TYPE_LOCAL_METHOD_ALIAS) &&
870a159c266SJung-uk Kim (TypeToCheckFor != ACPI_TYPE_LOCAL_SCOPE) &&
871a159c266SJung-uk Kim (ThisNode->Type != ACPI_TYPE_ANY) &&
872a159c266SJung-uk Kim (ThisNode->Type != TypeToCheckFor))
873a159c266SJung-uk Kim {
874a159c266SJung-uk Kim /* Complain about a type mismatch */
875a159c266SJung-uk Kim
876a159c266SJung-uk Kim ACPI_WARNING ((AE_INFO,
877a159c266SJung-uk Kim "NsLookup: Type mismatch on %4.4s (%s), searching for (%s)",
878a159c266SJung-uk Kim ACPI_CAST_PTR (char, &SimpleName),
879a159c266SJung-uk Kim AcpiUtGetTypeName (ThisNode->Type),
880a159c266SJung-uk Kim AcpiUtGetTypeName (TypeToCheckFor)));
881a159c266SJung-uk Kim }
882a159c266SJung-uk Kim
883a159c266SJung-uk Kim /*
884a159c266SJung-uk Kim * If this is the last name segment and we are not looking for a
885a159c266SJung-uk Kim * specific type, but the type of found object is known, use that
886a159c266SJung-uk Kim * type to (later) see if it opens a scope.
887a159c266SJung-uk Kim */
888a159c266SJung-uk Kim if (Type == ACPI_TYPE_ANY)
889a159c266SJung-uk Kim {
890a159c266SJung-uk Kim Type = ThisNode->Type;
891a159c266SJung-uk Kim }
892a159c266SJung-uk Kim }
893a159c266SJung-uk Kim
894a159c266SJung-uk Kim /* Point to next name segment and make this node current */
895a159c266SJung-uk Kim
896278f0de6SJung-uk Kim Path += ACPI_NAMESEG_SIZE;
897a159c266SJung-uk Kim CurrentNode = ThisNode;
898a159c266SJung-uk Kim }
899a159c266SJung-uk Kim
900a159c266SJung-uk Kim /* Always check if we need to open a new scope */
901a159c266SJung-uk Kim
902a159c266SJung-uk Kim if (!(Flags & ACPI_NS_DONT_OPEN_SCOPE) && (WalkState))
903a159c266SJung-uk Kim {
904a159c266SJung-uk Kim /*
905a159c266SJung-uk Kim * If entry is a type which opens a scope, push the new scope on the
906a159c266SJung-uk Kim * scope stack.
907a159c266SJung-uk Kim */
908a159c266SJung-uk Kim if (AcpiNsOpensScope (Type))
909a159c266SJung-uk Kim {
910a159c266SJung-uk Kim Status = AcpiDsScopeStackPush (ThisNode, Type, WalkState);
911a159c266SJung-uk Kim if (ACPI_FAILURE (Status))
912a159c266SJung-uk Kim {
913a159c266SJung-uk Kim return_ACPI_STATUS (Status);
914a159c266SJung-uk Kim }
915a159c266SJung-uk Kim }
916a159c266SJung-uk Kim }
917a159c266SJung-uk Kim
91851f42badSJung-uk Kim #ifdef ACPI_EXEC_APP
91951f42badSJung-uk Kim if (Flags & ACPI_NS_EARLY_INIT)
92051f42badSJung-uk Kim {
92151f42badSJung-uk Kim ThisNode->Flags |= ANOBJ_NODE_EARLY_INIT;
92251f42badSJung-uk Kim }
92351f42badSJung-uk Kim #endif
92451f42badSJung-uk Kim
925a159c266SJung-uk Kim *ReturnNode = ThisNode;
926a159c266SJung-uk Kim return_ACPI_STATUS (AE_OK);
927a159c266SJung-uk Kim }
928