nsaccess.c revision 1.3.4.2 1 1.3.4.2 rmind /*******************************************************************************
2 1.3.4.2 rmind *
3 1.3.4.2 rmind * Module Name: nsaccess - Top-level functions for accessing ACPI namespace
4 1.3.4.2 rmind *
5 1.3.4.2 rmind ******************************************************************************/
6 1.3.4.2 rmind
7 1.3.4.2 rmind /*
8 1.3.4.2 rmind * Copyright (C) 2000 - 2011, Intel Corp.
9 1.3.4.2 rmind * All rights reserved.
10 1.3.4.2 rmind *
11 1.3.4.2 rmind * Redistribution and use in source and binary forms, with or without
12 1.3.4.2 rmind * modification, are permitted provided that the following conditions
13 1.3.4.2 rmind * are met:
14 1.3.4.2 rmind * 1. Redistributions of source code must retain the above copyright
15 1.3.4.2 rmind * notice, this list of conditions, and the following disclaimer,
16 1.3.4.2 rmind * without modification.
17 1.3.4.2 rmind * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.3.4.2 rmind * substantially similar to the "NO WARRANTY" disclaimer below
19 1.3.4.2 rmind * ("Disclaimer") and any redistribution must be conditioned upon
20 1.3.4.2 rmind * including a substantially similar Disclaimer requirement for further
21 1.3.4.2 rmind * binary redistribution.
22 1.3.4.2 rmind * 3. Neither the names of the above-listed copyright holders nor the names
23 1.3.4.2 rmind * of any contributors may be used to endorse or promote products derived
24 1.3.4.2 rmind * from this software without specific prior written permission.
25 1.3.4.2 rmind *
26 1.3.4.2 rmind * Alternatively, this software may be distributed under the terms of the
27 1.3.4.2 rmind * GNU General Public License ("GPL") version 2 as published by the Free
28 1.3.4.2 rmind * Software Foundation.
29 1.3.4.2 rmind *
30 1.3.4.2 rmind * NO WARRANTY
31 1.3.4.2 rmind * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.3.4.2 rmind * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.3.4.2 rmind * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.3.4.2 rmind * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.3.4.2 rmind * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.3.4.2 rmind * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.3.4.2 rmind * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.3.4.2 rmind * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.3.4.2 rmind * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.3.4.2 rmind * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.3.4.2 rmind * POSSIBILITY OF SUCH DAMAGES.
42 1.3.4.2 rmind */
43 1.3.4.2 rmind
44 1.3.4.2 rmind #define __NSACCESS_C__
45 1.3.4.2 rmind
46 1.3.4.2 rmind #include "acpi.h"
47 1.3.4.2 rmind #include "accommon.h"
48 1.3.4.2 rmind #include "amlcode.h"
49 1.3.4.2 rmind #include "acnamesp.h"
50 1.3.4.2 rmind #include "acdispat.h"
51 1.3.4.2 rmind
52 1.3.4.2 rmind
53 1.3.4.2 rmind #define _COMPONENT ACPI_NAMESPACE
54 1.3.4.2 rmind ACPI_MODULE_NAME ("nsaccess")
55 1.3.4.2 rmind
56 1.3.4.2 rmind
57 1.3.4.2 rmind /*******************************************************************************
58 1.3.4.2 rmind *
59 1.3.4.2 rmind * FUNCTION: AcpiNsRootInitialize
60 1.3.4.2 rmind *
61 1.3.4.2 rmind * PARAMETERS: None
62 1.3.4.2 rmind *
63 1.3.4.2 rmind * RETURN: Status
64 1.3.4.2 rmind *
65 1.3.4.2 rmind * DESCRIPTION: Allocate and initialize the default root named objects
66 1.3.4.2 rmind *
67 1.3.4.2 rmind * MUTEX: Locks namespace for entire execution
68 1.3.4.2 rmind *
69 1.3.4.2 rmind ******************************************************************************/
70 1.3.4.2 rmind
71 1.3.4.2 rmind ACPI_STATUS
72 1.3.4.2 rmind AcpiNsRootInitialize (
73 1.3.4.2 rmind void)
74 1.3.4.2 rmind {
75 1.3.4.2 rmind ACPI_STATUS Status;
76 1.3.4.2 rmind const ACPI_PREDEFINED_NAMES *InitVal = NULL;
77 1.3.4.2 rmind ACPI_NAMESPACE_NODE *NewNode;
78 1.3.4.2 rmind ACPI_OPERAND_OBJECT *ObjDesc;
79 1.3.4.2 rmind ACPI_STRING Val = NULL;
80 1.3.4.2 rmind
81 1.3.4.2 rmind
82 1.3.4.2 rmind ACPI_FUNCTION_TRACE (NsRootInitialize);
83 1.3.4.2 rmind
84 1.3.4.2 rmind
85 1.3.4.2 rmind Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
86 1.3.4.2 rmind if (ACPI_FAILURE (Status))
87 1.3.4.2 rmind {
88 1.3.4.2 rmind return_ACPI_STATUS (Status);
89 1.3.4.2 rmind }
90 1.3.4.2 rmind
91 1.3.4.2 rmind /*
92 1.3.4.2 rmind * The global root ptr is initially NULL, so a non-NULL value indicates
93 1.3.4.2 rmind * that AcpiNsRootInitialize() has already been called; just return.
94 1.3.4.2 rmind */
95 1.3.4.2 rmind if (AcpiGbl_RootNode)
96 1.3.4.2 rmind {
97 1.3.4.2 rmind Status = AE_OK;
98 1.3.4.2 rmind goto UnlockAndExit;
99 1.3.4.2 rmind }
100 1.3.4.2 rmind
101 1.3.4.2 rmind /*
102 1.3.4.2 rmind * Tell the rest of the subsystem that the root is initialized
103 1.3.4.2 rmind * (This is OK because the namespace is locked)
104 1.3.4.2 rmind */
105 1.3.4.2 rmind AcpiGbl_RootNode = &AcpiGbl_RootNodeStruct;
106 1.3.4.2 rmind
107 1.3.4.2 rmind /* Enter the pre-defined names in the name table */
108 1.3.4.2 rmind
109 1.3.4.2 rmind ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
110 1.3.4.2 rmind "Entering predefined entries into namespace\n"));
111 1.3.4.2 rmind
112 1.3.4.2 rmind for (InitVal = AcpiGbl_PreDefinedNames; InitVal->Name; InitVal++)
113 1.3.4.2 rmind {
114 1.3.4.2 rmind /* _OSI is optional for now, will be permanent later */
115 1.3.4.2 rmind
116 1.3.4.2 rmind if (!ACPI_STRCMP (InitVal->Name, "_OSI") && !AcpiGbl_CreateOsiMethod)
117 1.3.4.2 rmind {
118 1.3.4.2 rmind continue;
119 1.3.4.2 rmind }
120 1.3.4.2 rmind
121 1.3.4.2 rmind Status = AcpiNsLookup (NULL, __UNCONST(InitVal->Name), InitVal->Type,
122 1.3.4.2 rmind ACPI_IMODE_LOAD_PASS2, ACPI_NS_NO_UPSEARCH,
123 1.3.4.2 rmind NULL, &NewNode);
124 1.3.4.2 rmind
125 1.3.4.2 rmind if (ACPI_FAILURE (Status) || (!NewNode)) /* Must be on same line for code converter */
126 1.3.4.2 rmind {
127 1.3.4.2 rmind ACPI_EXCEPTION ((AE_INFO, Status,
128 1.3.4.2 rmind "Could not create predefined name %s",
129 1.3.4.2 rmind InitVal->Name));
130 1.3.4.2 rmind }
131 1.3.4.2 rmind
132 1.3.4.2 rmind /*
133 1.3.4.2 rmind * Name entered successfully. If entry in PreDefinedNames[] specifies
134 1.3.4.2 rmind * an initial value, create the initial value.
135 1.3.4.2 rmind */
136 1.3.4.2 rmind if (InitVal->Val)
137 1.3.4.2 rmind {
138 1.3.4.2 rmind Status = AcpiOsPredefinedOverride (InitVal, &Val);
139 1.3.4.2 rmind if (ACPI_FAILURE (Status))
140 1.3.4.2 rmind {
141 1.3.4.2 rmind ACPI_ERROR ((AE_INFO,
142 1.3.4.2 rmind "Could not override predefined %s",
143 1.3.4.2 rmind InitVal->Name));
144 1.3.4.2 rmind }
145 1.3.4.2 rmind
146 1.3.4.2 rmind if (!Val)
147 1.3.4.2 rmind {
148 1.3.4.2 rmind Val = __UNCONST(InitVal->Val);
149 1.3.4.2 rmind }
150 1.3.4.2 rmind
151 1.3.4.2 rmind /*
152 1.3.4.2 rmind * Entry requests an initial value, allocate a
153 1.3.4.2 rmind * descriptor for it.
154 1.3.4.2 rmind */
155 1.3.4.2 rmind ObjDesc = AcpiUtCreateInternalObject (InitVal->Type);
156 1.3.4.2 rmind if (!ObjDesc)
157 1.3.4.2 rmind {
158 1.3.4.2 rmind Status = AE_NO_MEMORY;
159 1.3.4.2 rmind goto UnlockAndExit;
160 1.3.4.2 rmind }
161 1.3.4.2 rmind
162 1.3.4.2 rmind /*
163 1.3.4.2 rmind * Convert value string from table entry to
164 1.3.4.2 rmind * internal representation. Only types actually
165 1.3.4.2 rmind * used for initial values are implemented here.
166 1.3.4.2 rmind */
167 1.3.4.2 rmind switch (InitVal->Type)
168 1.3.4.2 rmind {
169 1.3.4.2 rmind case ACPI_TYPE_METHOD:
170 1.3.4.2 rmind ObjDesc->Method.ParamCount = (UINT8) ACPI_TO_INTEGER (Val);
171 1.3.4.2 rmind ObjDesc->Common.Flags |= AOPOBJ_DATA_VALID;
172 1.3.4.2 rmind
173 1.3.4.2 rmind #if defined (ACPI_ASL_COMPILER)
174 1.3.4.2 rmind
175 1.3.4.2 rmind /* Save the parameter count for the iASL compiler */
176 1.3.4.2 rmind
177 1.3.4.2 rmind NewNode->Value = ObjDesc->Method.ParamCount;
178 1.3.4.2 rmind #else
179 1.3.4.2 rmind /* Mark this as a very SPECIAL method */
180 1.3.4.2 rmind
181 1.3.4.2 rmind ObjDesc->Method.InfoFlags = ACPI_METHOD_INTERNAL_ONLY;
182 1.3.4.2 rmind ObjDesc->Method.Dispatch.Implementation = AcpiUtOsiImplementation;
183 1.3.4.2 rmind #endif
184 1.3.4.2 rmind break;
185 1.3.4.2 rmind
186 1.3.4.2 rmind case ACPI_TYPE_INTEGER:
187 1.3.4.2 rmind
188 1.3.4.2 rmind ObjDesc->Integer.Value = ACPI_TO_INTEGER (Val);
189 1.3.4.2 rmind break;
190 1.3.4.2 rmind
191 1.3.4.2 rmind
192 1.3.4.2 rmind case ACPI_TYPE_STRING:
193 1.3.4.2 rmind
194 1.3.4.2 rmind /* Build an object around the static string */
195 1.3.4.2 rmind
196 1.3.4.2 rmind ObjDesc->String.Length = (UINT32) ACPI_STRLEN (Val);
197 1.3.4.2 rmind ObjDesc->String.Pointer = Val;
198 1.3.4.2 rmind ObjDesc->Common.Flags |= AOPOBJ_STATIC_POINTER;
199 1.3.4.2 rmind break;
200 1.3.4.2 rmind
201 1.3.4.2 rmind
202 1.3.4.2 rmind case ACPI_TYPE_MUTEX:
203 1.3.4.2 rmind
204 1.3.4.2 rmind ObjDesc->Mutex.Node = NewNode;
205 1.3.4.2 rmind ObjDesc->Mutex.SyncLevel = (UINT8) (ACPI_TO_INTEGER (Val) - 1);
206 1.3.4.2 rmind
207 1.3.4.2 rmind /* Create a mutex */
208 1.3.4.2 rmind
209 1.3.4.2 rmind Status = AcpiOsCreateMutex (&ObjDesc->Mutex.OsMutex);
210 1.3.4.2 rmind if (ACPI_FAILURE (Status))
211 1.3.4.2 rmind {
212 1.3.4.2 rmind AcpiUtRemoveReference (ObjDesc);
213 1.3.4.2 rmind goto UnlockAndExit;
214 1.3.4.2 rmind }
215 1.3.4.2 rmind
216 1.3.4.2 rmind /* Special case for ACPI Global Lock */
217 1.3.4.2 rmind
218 1.3.4.2 rmind if (ACPI_STRCMP (InitVal->Name, "_GL_") == 0)
219 1.3.4.2 rmind {
220 1.3.4.2 rmind AcpiGbl_GlobalLockMutex = ObjDesc;
221 1.3.4.2 rmind
222 1.3.4.2 rmind /* Create additional counting semaphore for global lock */
223 1.3.4.2 rmind
224 1.3.4.2 rmind Status = AcpiOsCreateSemaphore (
225 1.3.4.2 rmind 1, 0, &AcpiGbl_GlobalLockSemaphore);
226 1.3.4.2 rmind if (ACPI_FAILURE (Status))
227 1.3.4.2 rmind {
228 1.3.4.2 rmind AcpiUtRemoveReference (ObjDesc);
229 1.3.4.2 rmind goto UnlockAndExit;
230 1.3.4.2 rmind }
231 1.3.4.2 rmind }
232 1.3.4.2 rmind break;
233 1.3.4.2 rmind
234 1.3.4.2 rmind
235 1.3.4.2 rmind default:
236 1.3.4.2 rmind
237 1.3.4.2 rmind ACPI_ERROR ((AE_INFO, "Unsupported initial type value 0x%X",
238 1.3.4.2 rmind InitVal->Type));
239 1.3.4.2 rmind AcpiUtRemoveReference (ObjDesc);
240 1.3.4.2 rmind ObjDesc = NULL;
241 1.3.4.2 rmind continue;
242 1.3.4.2 rmind }
243 1.3.4.2 rmind
244 1.3.4.2 rmind /* Store pointer to value descriptor in the Node */
245 1.3.4.2 rmind
246 1.3.4.2 rmind Status = AcpiNsAttachObject (NewNode, ObjDesc,
247 1.3.4.2 rmind ObjDesc->Common.Type);
248 1.3.4.2 rmind
249 1.3.4.2 rmind /* Remove local reference to the object */
250 1.3.4.2 rmind
251 1.3.4.2 rmind AcpiUtRemoveReference (ObjDesc);
252 1.3.4.2 rmind }
253 1.3.4.2 rmind }
254 1.3.4.2 rmind
255 1.3.4.2 rmind
256 1.3.4.2 rmind UnlockAndExit:
257 1.3.4.2 rmind (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
258 1.3.4.2 rmind
259 1.3.4.2 rmind /* Save a handle to "_GPE", it is always present */
260 1.3.4.2 rmind
261 1.3.4.2 rmind if (ACPI_SUCCESS (Status))
262 1.3.4.2 rmind {
263 1.3.4.2 rmind Status = AcpiNsGetNode (NULL, "\\_GPE", ACPI_NS_NO_UPSEARCH,
264 1.3.4.2 rmind &AcpiGbl_FadtGpeDevice);
265 1.3.4.2 rmind }
266 1.3.4.2 rmind
267 1.3.4.2 rmind return_ACPI_STATUS (Status);
268 1.3.4.2 rmind }
269 1.3.4.2 rmind
270 1.3.4.2 rmind
271 1.3.4.2 rmind /*******************************************************************************
272 1.3.4.2 rmind *
273 1.3.4.2 rmind * FUNCTION: AcpiNsLookup
274 1.3.4.2 rmind *
275 1.3.4.2 rmind * PARAMETERS: ScopeInfo - Current scope info block
276 1.3.4.2 rmind * Pathname - Search pathname, in internal format
277 1.3.4.2 rmind * (as represented in the AML stream)
278 1.3.4.2 rmind * Type - Type associated with name
279 1.3.4.2 rmind * InterpreterMode - IMODE_LOAD_PASS2 => add name if not found
280 1.3.4.2 rmind * Flags - Flags describing the search restrictions
281 1.3.4.2 rmind * WalkState - Current state of the walk
282 1.3.4.2 rmind * ReturnNode - Where the Node is placed (if found
283 1.3.4.2 rmind * or created successfully)
284 1.3.4.2 rmind *
285 1.3.4.2 rmind * RETURN: Status
286 1.3.4.2 rmind *
287 1.3.4.2 rmind * DESCRIPTION: Find or enter the passed name in the name space.
288 1.3.4.2 rmind * Log an error if name not found in Exec mode.
289 1.3.4.2 rmind *
290 1.3.4.2 rmind * MUTEX: Assumes namespace is locked.
291 1.3.4.2 rmind *
292 1.3.4.2 rmind ******************************************************************************/
293 1.3.4.2 rmind
294 1.3.4.2 rmind ACPI_STATUS
295 1.3.4.2 rmind AcpiNsLookup (
296 1.3.4.2 rmind ACPI_GENERIC_STATE *ScopeInfo,
297 1.3.4.2 rmind char *Pathname,
298 1.3.4.2 rmind ACPI_OBJECT_TYPE Type,
299 1.3.4.2 rmind ACPI_INTERPRETER_MODE InterpreterMode,
300 1.3.4.2 rmind UINT32 Flags,
301 1.3.4.2 rmind ACPI_WALK_STATE *WalkState,
302 1.3.4.2 rmind ACPI_NAMESPACE_NODE **ReturnNode)
303 1.3.4.2 rmind {
304 1.3.4.2 rmind ACPI_STATUS Status;
305 1.3.4.2 rmind char *Path = Pathname;
306 1.3.4.2 rmind ACPI_NAMESPACE_NODE *PrefixNode;
307 1.3.4.2 rmind ACPI_NAMESPACE_NODE *CurrentNode = NULL;
308 1.3.4.2 rmind ACPI_NAMESPACE_NODE *ThisNode = NULL;
309 1.3.4.2 rmind UINT32 NumSegments;
310 1.3.4.2 rmind UINT32 NumCarats;
311 1.3.4.2 rmind ACPI_NAME SimpleName;
312 1.3.4.2 rmind ACPI_OBJECT_TYPE TypeToCheckFor;
313 1.3.4.2 rmind ACPI_OBJECT_TYPE ThisSearchType;
314 1.3.4.2 rmind UINT32 SearchParentFlag = ACPI_NS_SEARCH_PARENT;
315 1.3.4.2 rmind UINT32 LocalFlags;
316 1.3.4.2 rmind
317 1.3.4.2 rmind
318 1.3.4.2 rmind ACPI_FUNCTION_TRACE (NsLookup);
319 1.3.4.2 rmind
320 1.3.4.2 rmind
321 1.3.4.2 rmind if (!ReturnNode)
322 1.3.4.2 rmind {
323 1.3.4.2 rmind return_ACPI_STATUS (AE_BAD_PARAMETER);
324 1.3.4.2 rmind }
325 1.3.4.2 rmind
326 1.3.4.2 rmind LocalFlags = Flags & ~(ACPI_NS_ERROR_IF_FOUND | ACPI_NS_SEARCH_PARENT);
327 1.3.4.2 rmind *ReturnNode = ACPI_ENTRY_NOT_FOUND;
328 1.3.4.2 rmind AcpiGbl_NsLookupCount++;
329 1.3.4.2 rmind
330 1.3.4.2 rmind if (!AcpiGbl_RootNode)
331 1.3.4.2 rmind {
332 1.3.4.2 rmind return_ACPI_STATUS (AE_NO_NAMESPACE);
333 1.3.4.2 rmind }
334 1.3.4.2 rmind
335 1.3.4.2 rmind /* Get the prefix scope. A null scope means use the root scope */
336 1.3.4.2 rmind
337 1.3.4.2 rmind if ((!ScopeInfo) ||
338 1.3.4.2 rmind (!ScopeInfo->Scope.Node))
339 1.3.4.2 rmind {
340 1.3.4.2 rmind ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
341 1.3.4.2 rmind "Null scope prefix, using root node (%p)\n",
342 1.3.4.2 rmind AcpiGbl_RootNode));
343 1.3.4.2 rmind
344 1.3.4.2 rmind PrefixNode = AcpiGbl_RootNode;
345 1.3.4.2 rmind }
346 1.3.4.2 rmind else
347 1.3.4.2 rmind {
348 1.3.4.2 rmind PrefixNode = ScopeInfo->Scope.Node;
349 1.3.4.2 rmind if (ACPI_GET_DESCRIPTOR_TYPE (PrefixNode) != ACPI_DESC_TYPE_NAMED)
350 1.3.4.2 rmind {
351 1.3.4.2 rmind ACPI_ERROR ((AE_INFO, "%p is not a namespace node [%s]",
352 1.3.4.2 rmind PrefixNode, AcpiUtGetDescriptorName (PrefixNode)));
353 1.3.4.2 rmind return_ACPI_STATUS (AE_AML_INTERNAL);
354 1.3.4.2 rmind }
355 1.3.4.2 rmind
356 1.3.4.2 rmind if (!(Flags & ACPI_NS_PREFIX_IS_SCOPE))
357 1.3.4.2 rmind {
358 1.3.4.2 rmind /*
359 1.3.4.2 rmind * This node might not be a actual "scope" node (such as a
360 1.3.4.2 rmind * Device/Method, etc.) It could be a Package or other object
361 1.3.4.2 rmind * node. Backup up the tree to find the containing scope node.
362 1.3.4.2 rmind */
363 1.3.4.2 rmind while (!AcpiNsOpensScope (PrefixNode->Type) &&
364 1.3.4.2 rmind PrefixNode->Type != ACPI_TYPE_ANY)
365 1.3.4.2 rmind {
366 1.3.4.2 rmind PrefixNode = PrefixNode->Parent;
367 1.3.4.2 rmind }
368 1.3.4.2 rmind }
369 1.3.4.2 rmind }
370 1.3.4.2 rmind
371 1.3.4.2 rmind /* Save type. TBD: may be no longer necessary */
372 1.3.4.2 rmind
373 1.3.4.2 rmind TypeToCheckFor = Type;
374 1.3.4.2 rmind
375 1.3.4.2 rmind /*
376 1.3.4.2 rmind * Begin examination of the actual pathname
377 1.3.4.2 rmind */
378 1.3.4.2 rmind if (!Pathname)
379 1.3.4.2 rmind {
380 1.3.4.2 rmind /* A Null NamePath is allowed and refers to the root */
381 1.3.4.2 rmind
382 1.3.4.2 rmind NumSegments = 0;
383 1.3.4.2 rmind ThisNode = AcpiGbl_RootNode;
384 1.3.4.2 rmind Path = __UNCONST("");
385 1.3.4.2 rmind
386 1.3.4.2 rmind ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
387 1.3.4.2 rmind "Null Pathname (Zero segments), Flags=%X\n", Flags));
388 1.3.4.2 rmind }
389 1.3.4.2 rmind else
390 1.3.4.2 rmind {
391 1.3.4.2 rmind /*
392 1.3.4.2 rmind * Name pointer is valid (and must be in internal name format)
393 1.3.4.2 rmind *
394 1.3.4.2 rmind * Check for scope prefixes:
395 1.3.4.2 rmind *
396 1.3.4.2 rmind * As represented in the AML stream, a namepath consists of an
397 1.3.4.2 rmind * optional scope prefix followed by a name segment part.
398 1.3.4.2 rmind *
399 1.3.4.2 rmind * If present, the scope prefix is either a Root Prefix (in
400 1.3.4.2 rmind * which case the name is fully qualified), or one or more
401 1.3.4.2 rmind * Parent Prefixes (in which case the name's scope is relative
402 1.3.4.2 rmind * to the current scope).
403 1.3.4.2 rmind */
404 1.3.4.2 rmind if (*Path == (UINT8) AML_ROOT_PREFIX)
405 1.3.4.2 rmind {
406 1.3.4.2 rmind /* Pathname is fully qualified, start from the root */
407 1.3.4.2 rmind
408 1.3.4.2 rmind ThisNode = AcpiGbl_RootNode;
409 1.3.4.2 rmind SearchParentFlag = ACPI_NS_NO_UPSEARCH;
410 1.3.4.2 rmind
411 1.3.4.2 rmind /* Point to name segment part */
412 1.3.4.2 rmind
413 1.3.4.2 rmind Path++;
414 1.3.4.2 rmind
415 1.3.4.2 rmind ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
416 1.3.4.2 rmind "Path is absolute from root [%p]\n", ThisNode));
417 1.3.4.2 rmind }
418 1.3.4.2 rmind else
419 1.3.4.2 rmind {
420 1.3.4.2 rmind /* Pathname is relative to current scope, start there */
421 1.3.4.2 rmind
422 1.3.4.2 rmind ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
423 1.3.4.2 rmind "Searching relative to prefix scope [%4.4s] (%p)\n",
424 1.3.4.2 rmind AcpiUtGetNodeName (PrefixNode), PrefixNode));
425 1.3.4.2 rmind
426 1.3.4.2 rmind /*
427 1.3.4.2 rmind * Handle multiple Parent Prefixes (carat) by just getting
428 1.3.4.2 rmind * the parent node for each prefix instance.
429 1.3.4.2 rmind */
430 1.3.4.2 rmind ThisNode = PrefixNode;
431 1.3.4.2 rmind NumCarats = 0;
432 1.3.4.2 rmind while (*Path == (UINT8) AML_PARENT_PREFIX)
433 1.3.4.2 rmind {
434 1.3.4.2 rmind /* Name is fully qualified, no search rules apply */
435 1.3.4.2 rmind
436 1.3.4.2 rmind SearchParentFlag = ACPI_NS_NO_UPSEARCH;
437 1.3.4.2 rmind
438 1.3.4.2 rmind /*
439 1.3.4.2 rmind * Point past this prefix to the name segment
440 1.3.4.2 rmind * part or the next Parent Prefix
441 1.3.4.2 rmind */
442 1.3.4.2 rmind Path++;
443 1.3.4.2 rmind
444 1.3.4.2 rmind /* Backup to the parent node */
445 1.3.4.2 rmind
446 1.3.4.2 rmind NumCarats++;
447 1.3.4.2 rmind ThisNode = ThisNode->Parent;
448 1.3.4.2 rmind if (!ThisNode)
449 1.3.4.2 rmind {
450 1.3.4.2 rmind /* Current scope has no parent scope */
451 1.3.4.2 rmind
452 1.3.4.2 rmind ACPI_ERROR ((AE_INFO,
453 1.3.4.2 rmind "ACPI path has too many parent prefixes (^) "
454 1.3.4.2 rmind "- reached beyond root node"));
455 1.3.4.2 rmind return_ACPI_STATUS (AE_NOT_FOUND);
456 1.3.4.2 rmind }
457 1.3.4.2 rmind }
458 1.3.4.2 rmind
459 1.3.4.2 rmind if (SearchParentFlag == ACPI_NS_NO_UPSEARCH)
460 1.3.4.2 rmind {
461 1.3.4.2 rmind ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
462 1.3.4.2 rmind "Search scope is [%4.4s], path has %u carat(s)\n",
463 1.3.4.2 rmind AcpiUtGetNodeName (ThisNode), NumCarats));
464 1.3.4.2 rmind }
465 1.3.4.2 rmind }
466 1.3.4.2 rmind
467 1.3.4.2 rmind /*
468 1.3.4.2 rmind * Determine the number of ACPI name segments in this pathname.
469 1.3.4.2 rmind *
470 1.3.4.2 rmind * The segment part consists of either:
471 1.3.4.2 rmind * - A Null name segment (0)
472 1.3.4.2 rmind * - A DualNamePrefix followed by two 4-byte name segments
473 1.3.4.2 rmind * - A MultiNamePrefix followed by a byte indicating the
474 1.3.4.2 rmind * number of segments and the segments themselves.
475 1.3.4.2 rmind * - A single 4-byte name segment
476 1.3.4.2 rmind *
477 1.3.4.2 rmind * Examine the name prefix opcode, if any, to determine the number of
478 1.3.4.2 rmind * segments.
479 1.3.4.2 rmind */
480 1.3.4.2 rmind switch (*Path)
481 1.3.4.2 rmind {
482 1.3.4.2 rmind case 0:
483 1.3.4.2 rmind /*
484 1.3.4.2 rmind * Null name after a root or parent prefixes. We already
485 1.3.4.2 rmind * have the correct target node and there are no name segments.
486 1.3.4.2 rmind */
487 1.3.4.2 rmind NumSegments = 0;
488 1.3.4.2 rmind Type = ThisNode->Type;
489 1.3.4.2 rmind
490 1.3.4.2 rmind ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
491 1.3.4.2 rmind "Prefix-only Pathname (Zero name segments), Flags=%X\n",
492 1.3.4.2 rmind Flags));
493 1.3.4.2 rmind break;
494 1.3.4.2 rmind
495 1.3.4.2 rmind case AML_DUAL_NAME_PREFIX:
496 1.3.4.2 rmind
497 1.3.4.2 rmind /* More than one NameSeg, search rules do not apply */
498 1.3.4.2 rmind
499 1.3.4.2 rmind SearchParentFlag = ACPI_NS_NO_UPSEARCH;
500 1.3.4.2 rmind
501 1.3.4.2 rmind /* Two segments, point to first name segment */
502 1.3.4.2 rmind
503 1.3.4.2 rmind NumSegments = 2;
504 1.3.4.2 rmind Path++;
505 1.3.4.2 rmind
506 1.3.4.2 rmind ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
507 1.3.4.2 rmind "Dual Pathname (2 segments, Flags=%X)\n", Flags));
508 1.3.4.2 rmind break;
509 1.3.4.2 rmind
510 1.3.4.2 rmind case AML_MULTI_NAME_PREFIX_OP:
511 1.3.4.2 rmind
512 1.3.4.2 rmind /* More than one NameSeg, search rules do not apply */
513 1.3.4.2 rmind
514 1.3.4.2 rmind SearchParentFlag = ACPI_NS_NO_UPSEARCH;
515 1.3.4.2 rmind
516 1.3.4.2 rmind /* Extract segment count, point to first name segment */
517 1.3.4.2 rmind
518 1.3.4.2 rmind Path++;
519 1.3.4.2 rmind NumSegments = (UINT32) (UINT8) *Path;
520 1.3.4.2 rmind Path++;
521 1.3.4.2 rmind
522 1.3.4.2 rmind ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
523 1.3.4.2 rmind "Multi Pathname (%u Segments, Flags=%X)\n",
524 1.3.4.2 rmind NumSegments, Flags));
525 1.3.4.2 rmind break;
526 1.3.4.2 rmind
527 1.3.4.2 rmind default:
528 1.3.4.2 rmind /*
529 1.3.4.2 rmind * Not a Null name, no Dual or Multi prefix, hence there is
530 1.3.4.2 rmind * only one name segment and Pathname is already pointing to it.
531 1.3.4.2 rmind */
532 1.3.4.2 rmind NumSegments = 1;
533 1.3.4.2 rmind
534 1.3.4.2 rmind ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
535 1.3.4.2 rmind "Simple Pathname (1 segment, Flags=%X)\n", Flags));
536 1.3.4.2 rmind break;
537 1.3.4.2 rmind }
538 1.3.4.2 rmind
539 1.3.4.2 rmind ACPI_DEBUG_EXEC (AcpiNsPrintPathname (NumSegments, Path));
540 1.3.4.2 rmind }
541 1.3.4.2 rmind
542 1.3.4.2 rmind
543 1.3.4.2 rmind /*
544 1.3.4.2 rmind * Search namespace for each segment of the name. Loop through and
545 1.3.4.2 rmind * verify (or add to the namespace) each name segment.
546 1.3.4.2 rmind *
547 1.3.4.2 rmind * The object type is significant only at the last name
548 1.3.4.2 rmind * segment. (We don't care about the types along the path, only
549 1.3.4.2 rmind * the type of the final target object.)
550 1.3.4.2 rmind */
551 1.3.4.2 rmind ThisSearchType = ACPI_TYPE_ANY;
552 1.3.4.2 rmind CurrentNode = ThisNode;
553 1.3.4.2 rmind while (NumSegments && CurrentNode)
554 1.3.4.2 rmind {
555 1.3.4.2 rmind NumSegments--;
556 1.3.4.2 rmind if (!NumSegments)
557 1.3.4.2 rmind {
558 1.3.4.2 rmind /* This is the last segment, enable typechecking */
559 1.3.4.2 rmind
560 1.3.4.2 rmind ThisSearchType = Type;
561 1.3.4.2 rmind
562 1.3.4.2 rmind /*
563 1.3.4.2 rmind * Only allow automatic parent search (search rules) if the caller
564 1.3.4.2 rmind * requested it AND we have a single, non-fully-qualified NameSeg
565 1.3.4.2 rmind */
566 1.3.4.2 rmind if ((SearchParentFlag != ACPI_NS_NO_UPSEARCH) &&
567 1.3.4.2 rmind (Flags & ACPI_NS_SEARCH_PARENT))
568 1.3.4.2 rmind {
569 1.3.4.2 rmind LocalFlags |= ACPI_NS_SEARCH_PARENT;
570 1.3.4.2 rmind }
571 1.3.4.2 rmind
572 1.3.4.2 rmind /* Set error flag according to caller */
573 1.3.4.2 rmind
574 1.3.4.2 rmind if (Flags & ACPI_NS_ERROR_IF_FOUND)
575 1.3.4.2 rmind {
576 1.3.4.2 rmind LocalFlags |= ACPI_NS_ERROR_IF_FOUND;
577 1.3.4.2 rmind }
578 1.3.4.2 rmind }
579 1.3.4.2 rmind
580 1.3.4.2 rmind /* Extract one ACPI name from the front of the pathname */
581 1.3.4.2 rmind
582 1.3.4.2 rmind ACPI_MOVE_32_TO_32 (&SimpleName, Path);
583 1.3.4.2 rmind
584 1.3.4.2 rmind /* Try to find the single (4 character) ACPI name */
585 1.3.4.2 rmind
586 1.3.4.2 rmind Status = AcpiNsSearchAndEnter (SimpleName, WalkState, CurrentNode,
587 1.3.4.2 rmind InterpreterMode, ThisSearchType, LocalFlags, &ThisNode);
588 1.3.4.2 rmind if (ACPI_FAILURE (Status))
589 1.3.4.2 rmind {
590 1.3.4.2 rmind if (Status == AE_NOT_FOUND)
591 1.3.4.2 rmind {
592 1.3.4.2 rmind /* Name not found in ACPI namespace */
593 1.3.4.2 rmind
594 1.3.4.2 rmind ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
595 1.3.4.2 rmind "Name [%4.4s] not found in scope [%4.4s] %p\n",
596 1.3.4.2 rmind (char *) &SimpleName, (char *) &CurrentNode->Name,
597 1.3.4.2 rmind CurrentNode));
598 1.3.4.2 rmind }
599 1.3.4.2 rmind
600 1.3.4.2 rmind *ReturnNode = ThisNode;
601 1.3.4.2 rmind return_ACPI_STATUS (Status);
602 1.3.4.2 rmind }
603 1.3.4.2 rmind
604 1.3.4.2 rmind /* More segments to follow? */
605 1.3.4.2 rmind
606 1.3.4.2 rmind if (NumSegments > 0)
607 1.3.4.2 rmind {
608 1.3.4.2 rmind /*
609 1.3.4.2 rmind * If we have an alias to an object that opens a scope (such as a
610 1.3.4.2 rmind * device or processor), we need to dereference the alias here so
611 1.3.4.2 rmind * that we can access any children of the original node (via the
612 1.3.4.2 rmind * remaining segments).
613 1.3.4.2 rmind */
614 1.3.4.2 rmind if (ThisNode->Type == ACPI_TYPE_LOCAL_ALIAS)
615 1.3.4.2 rmind {
616 1.3.4.2 rmind if (!ThisNode->Object)
617 1.3.4.2 rmind {
618 1.3.4.2 rmind return_ACPI_STATUS (AE_NOT_EXIST);
619 1.3.4.2 rmind }
620 1.3.4.2 rmind
621 1.3.4.2 rmind if (AcpiNsOpensScope (((ACPI_NAMESPACE_NODE *)
622 1.3.4.2 rmind ThisNode->Object)->Type))
623 1.3.4.2 rmind {
624 1.3.4.2 rmind ThisNode = (ACPI_NAMESPACE_NODE *) ThisNode->Object;
625 1.3.4.2 rmind }
626 1.3.4.2 rmind }
627 1.3.4.2 rmind }
628 1.3.4.2 rmind
629 1.3.4.2 rmind /* Special handling for the last segment (NumSegments == 0) */
630 1.3.4.2 rmind
631 1.3.4.2 rmind else
632 1.3.4.2 rmind {
633 1.3.4.2 rmind /*
634 1.3.4.2 rmind * Sanity typecheck of the target object:
635 1.3.4.2 rmind *
636 1.3.4.2 rmind * If 1) This is the last segment (NumSegments == 0)
637 1.3.4.2 rmind * 2) And we are looking for a specific type
638 1.3.4.2 rmind * (Not checking for TYPE_ANY)
639 1.3.4.2 rmind * 3) Which is not an alias
640 1.3.4.2 rmind * 4) Which is not a local type (TYPE_SCOPE)
641 1.3.4.2 rmind * 5) And the type of target object is known (not TYPE_ANY)
642 1.3.4.2 rmind * 6) And target object does not match what we are looking for
643 1.3.4.2 rmind *
644 1.3.4.2 rmind * Then we have a type mismatch. Just warn and ignore it.
645 1.3.4.2 rmind */
646 1.3.4.2 rmind if ((TypeToCheckFor != ACPI_TYPE_ANY) &&
647 1.3.4.2 rmind (TypeToCheckFor != ACPI_TYPE_LOCAL_ALIAS) &&
648 1.3.4.2 rmind (TypeToCheckFor != ACPI_TYPE_LOCAL_METHOD_ALIAS) &&
649 1.3.4.2 rmind (TypeToCheckFor != ACPI_TYPE_LOCAL_SCOPE) &&
650 1.3.4.2 rmind (ThisNode->Type != ACPI_TYPE_ANY) &&
651 1.3.4.2 rmind (ThisNode->Type != TypeToCheckFor))
652 1.3.4.2 rmind {
653 1.3.4.2 rmind /* Complain about a type mismatch */
654 1.3.4.2 rmind
655 1.3.4.2 rmind ACPI_WARNING ((AE_INFO,
656 1.3.4.2 rmind "NsLookup: Type mismatch on %4.4s (%s), searching for (%s)",
657 1.3.4.2 rmind ACPI_CAST_PTR (char, &SimpleName),
658 1.3.4.2 rmind AcpiUtGetTypeName (ThisNode->Type),
659 1.3.4.2 rmind AcpiUtGetTypeName (TypeToCheckFor)));
660 1.3.4.2 rmind }
661 1.3.4.2 rmind
662 1.3.4.2 rmind /*
663 1.3.4.2 rmind * If this is the last name segment and we are not looking for a
664 1.3.4.2 rmind * specific type, but the type of found object is known, use that
665 1.3.4.2 rmind * type to (later) see if it opens a scope.
666 1.3.4.2 rmind */
667 1.3.4.2 rmind if (Type == ACPI_TYPE_ANY)
668 1.3.4.2 rmind {
669 1.3.4.2 rmind Type = ThisNode->Type;
670 1.3.4.2 rmind }
671 1.3.4.2 rmind }
672 1.3.4.2 rmind
673 1.3.4.2 rmind /* Point to next name segment and make this node current */
674 1.3.4.2 rmind
675 1.3.4.2 rmind Path += ACPI_NAME_SIZE;
676 1.3.4.2 rmind CurrentNode = ThisNode;
677 1.3.4.2 rmind }
678 1.3.4.2 rmind
679 1.3.4.2 rmind /* Always check if we need to open a new scope */
680 1.3.4.2 rmind
681 1.3.4.2 rmind if (!(Flags & ACPI_NS_DONT_OPEN_SCOPE) && (WalkState))
682 1.3.4.2 rmind {
683 1.3.4.2 rmind /*
684 1.3.4.2 rmind * If entry is a type which opens a scope, push the new scope on the
685 1.3.4.2 rmind * scope stack.
686 1.3.4.2 rmind */
687 1.3.4.2 rmind if (AcpiNsOpensScope (Type))
688 1.3.4.2 rmind {
689 1.3.4.2 rmind Status = AcpiDsScopeStackPush (ThisNode, Type, WalkState);
690 1.3.4.2 rmind if (ACPI_FAILURE (Status))
691 1.3.4.2 rmind {
692 1.3.4.2 rmind return_ACPI_STATUS (Status);
693 1.3.4.2 rmind }
694 1.3.4.2 rmind }
695 1.3.4.2 rmind }
696 1.3.4.2 rmind
697 1.3.4.2 rmind *ReturnNode = ThisNode;
698 1.3.4.2 rmind return_ACPI_STATUS (AE_OK);
699 1.3.4.2 rmind }
700 1.3.4.2 rmind
701