Print this page
update to acpica-unix2-20140114
acpica-unix2-20130823
PANKOVs restructure
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/intel/io/acpica/namespace/nssearch.c
+++ new/usr/src/common/acpica/components/namespace/nssearch.c
1 1 /*******************************************************************************
2 2 *
3 3 * Module Name: nssearch - Namespace search
4 4 *
5 5 ******************************************************************************/
6 6
7 7 /*
8 - * Copyright (C) 2000 - 2011, Intel Corp.
8 + * Copyright (C) 2000 - 2014, Intel Corp.
9 9 * All rights reserved.
10 10 *
11 11 * Redistribution and use in source and binary forms, with or without
12 12 * modification, are permitted provided that the following conditions
13 13 * are met:
14 14 * 1. Redistributions of source code must retain the above copyright
15 15 * notice, this list of conditions, and the following disclaimer,
16 16 * without modification.
17 17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 18 * substantially similar to the "NO WARRANTY" disclaimer below
19 19 * ("Disclaimer") and any redistribution must be conditioned upon
20 20 * including a substantially similar Disclaimer requirement for further
21 21 * binary redistribution.
22 22 * 3. Neither the names of the above-listed copyright holders nor the names
23 23 * of any contributors may be used to endorse or promote products derived
24 24 * from this software without specific prior written permission.
25 25 *
26 26 * Alternatively, this software may be distributed under the terms of the
27 27 * GNU General Public License ("GPL") version 2 as published by the Free
28 28 * Software Foundation.
29 29 *
30 30 * NO WARRANTY
31 31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 41 * POSSIBILITY OF SUCH DAMAGES.
42 42 */
43 43
44 44 #define __NSSEARCH_C__
45 45
46 46 #include "acpi.h"
47 47 #include "accommon.h"
48 48 #include "acnamesp.h"
49 49
50 50 #ifdef ACPI_ASL_COMPILER
51 51 #include "amlcode.h"
52 52 #endif
53 53
54 54 #define _COMPONENT ACPI_NAMESPACE
55 55 ACPI_MODULE_NAME ("nssearch")
56 56
57 57 /* Local prototypes */
58 58
59 59 static ACPI_STATUS
60 60 AcpiNsSearchParentTree (
61 61 UINT32 TargetName,
62 62 ACPI_NAMESPACE_NODE *Node,
63 63 ACPI_OBJECT_TYPE Type,
64 64 ACPI_NAMESPACE_NODE **ReturnNode);
65 65
66 66
67 67 /*******************************************************************************
68 68 *
69 69 * FUNCTION: AcpiNsSearchOneScope
70 70 *
71 71 * PARAMETERS: TargetName - Ascii ACPI name to search for
72 72 * ParentNode - Starting node where search will begin
73 73 * Type - Object type to match
74 74 * ReturnNode - Where the matched Named obj is returned
75 75 *
76 76 * RETURN: Status
77 77 *
78 78 * DESCRIPTION: Search a single level of the namespace. Performs a
79 79 * simple search of the specified level, and does not add
80 80 * entries or search parents.
81 81 *
82 82 *
83 83 * Named object lists are built (and subsequently dumped) in the
84 84 * order in which the names are encountered during the namespace load;
85 85 *
86 86 * All namespace searching is linear in this implementation, but
87 87 * could be easily modified to support any improved search
88 88 * algorithm. However, the linear search was chosen for simplicity
89 89 * and because the trees are small and the other interpreter
90 90 * execution overhead is relatively high.
91 91 *
92 92 * Note: CPU execution analysis has shown that the AML interpreter spends
93 93 * a very small percentage of its time searching the namespace. Therefore,
94 94 * the linear search seems to be sufficient, as there would seem to be
95 95 * little value in improving the search.
96 96 *
97 97 ******************************************************************************/
98 98
99 99 ACPI_STATUS
100 100 AcpiNsSearchOneScope (
101 101 UINT32 TargetName,
102 102 ACPI_NAMESPACE_NODE *ParentNode,
103 103 ACPI_OBJECT_TYPE Type,
104 104 ACPI_NAMESPACE_NODE **ReturnNode)
105 105 {
106 106 ACPI_NAMESPACE_NODE *Node;
107 107
108 108
109 109 ACPI_FUNCTION_TRACE (NsSearchOneScope);
110 110
111 111
112 112 #ifdef ACPI_DEBUG_OUTPUT
113 113 if (ACPI_LV_NAMES & AcpiDbgLevel)
114 114 {
115 115 char *ScopeName;
116 116
117 117 ScopeName = AcpiNsGetExternalPathname (ParentNode);
118 118 if (ScopeName)
119 119 {
120 120 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
121 121 "Searching %s (%p) For [%4.4s] (%s)\n",
122 122 ScopeName, ParentNode, ACPI_CAST_PTR (char, &TargetName),
123 123 AcpiUtGetTypeName (Type)));
124 124
125 125 ACPI_FREE (ScopeName);
126 126 }
127 127 }
128 128 #endif
129 129
130 130 /*
131 131 * Search for name at this namespace level, which is to say that we
132 132 * must search for the name among the children of this object
133 133 */
134 134 Node = ParentNode->Child;
135 135 while (Node)
136 136 {
137 137 /* Check for match against the name */
138 138
139 139 if (Node->Name.Integer == TargetName)
140 140 {
141 141 /* Resolve a control method alias if any */
142 142
143 143 if (AcpiNsGetType (Node) == ACPI_TYPE_LOCAL_METHOD_ALIAS)
144 144 {
145 145 Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Node->Object);
146 146 }
147 147
148 148 /* Found matching entry */
149 149
150 150 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
151 151 "Name [%4.4s] (%s) %p found in scope [%4.4s] %p\n",
152 152 ACPI_CAST_PTR (char, &TargetName),
153 153 AcpiUtGetTypeName (Node->Type),
154 154 Node, AcpiUtGetNodeName (ParentNode), ParentNode));
155 155
156 156 *ReturnNode = Node;
157 157 return_ACPI_STATUS (AE_OK);
158 158 }
159 159
160 160 /* Didn't match name, move on to the next peer object */
161 161
162 162 Node = Node->Peer;
163 163 }
164 164
165 165 /* Searched entire namespace level, not found */
166 166
167 167 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
168 168 "Name [%4.4s] (%s) not found in search in scope [%4.4s] "
169 169 "%p first child %p\n",
170 170 ACPI_CAST_PTR (char, &TargetName), AcpiUtGetTypeName (Type),
171 171 AcpiUtGetNodeName (ParentNode), ParentNode, ParentNode->Child));
172 172
173 173 return_ACPI_STATUS (AE_NOT_FOUND);
174 174 }
175 175
176 176
177 177 /*******************************************************************************
178 178 *
179 179 * FUNCTION: AcpiNsSearchParentTree
180 180 *
181 181 * PARAMETERS: TargetName - Ascii ACPI name to search for
182 182 * Node - Starting node where search will begin
183 183 * Type - Object type to match
184 184 * ReturnNode - Where the matched Node is returned
185 185 *
186 186 * RETURN: Status
187 187 *
188 188 * DESCRIPTION: Called when a name has not been found in the current namespace
189 189 * level. Before adding it or giving up, ACPI scope rules require
190 190 * searching enclosing scopes in cases identified by AcpiNsLocal().
191 191 *
192 192 * "A name is located by finding the matching name in the current
193 193 * name space, and then in the parent name space. If the parent
194 194 * name space does not contain the name, the search continues
195 195 * recursively until either the name is found or the name space
196 196 * does not have a parent (the root of the name space). This
197 197 * indicates that the name is not found" (From ACPI Specification,
198 198 * section 5.3)
199 199 *
200 200 ******************************************************************************/
201 201
202 202 static ACPI_STATUS
203 203 AcpiNsSearchParentTree (
204 204 UINT32 TargetName,
205 205 ACPI_NAMESPACE_NODE *Node,
206 206 ACPI_OBJECT_TYPE Type,
207 207 ACPI_NAMESPACE_NODE **ReturnNode)
208 208 {
209 209 ACPI_STATUS Status;
210 210 ACPI_NAMESPACE_NODE *ParentNode;
211 211
212 212
213 213 ACPI_FUNCTION_TRACE (NsSearchParentTree);
214 214
215 215
216 216 ParentNode = Node->Parent;
217 217
218 218 /*
219 219 * If there is no parent (i.e., we are at the root) or type is "local",
220 220 * we won't be searching the parent tree.
221 221 */
222 222 if (!ParentNode)
223 223 {
224 224 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "[%4.4s] has no parent\n",
225 225 ACPI_CAST_PTR (char, &TargetName)));
226 226 return_ACPI_STATUS (AE_NOT_FOUND);
227 227 }
228 228
229 229 if (AcpiNsLocal (Type))
230 230 {
231 231 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
232 232 "[%4.4s] type [%s] must be local to this scope (no parent search)\n",
233 233 ACPI_CAST_PTR (char, &TargetName), AcpiUtGetTypeName (Type)));
234 234 return_ACPI_STATUS (AE_NOT_FOUND);
235 235 }
236 236
237 237 /* Search the parent tree */
238 238
239 239 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
240 240 "Searching parent [%4.4s] for [%4.4s]\n",
241 241 AcpiUtGetNodeName (ParentNode), ACPI_CAST_PTR (char, &TargetName)));
242 242
243 243 /* Search parents until target is found or we have backed up to the root */
244 244
245 245 while (ParentNode)
246 246 {
247 247 /*
248 248 * Search parent scope. Use TYPE_ANY because we don't care about the
249 249 * object type at this point, we only care about the existence of
250 250 * the actual name we are searching for. Typechecking comes later.
251 251 */
252 252 Status = AcpiNsSearchOneScope (
253 253 TargetName, ParentNode, ACPI_TYPE_ANY, ReturnNode);
254 254 if (ACPI_SUCCESS (Status))
255 255 {
256 256 return_ACPI_STATUS (Status);
257 257 }
258 258
259 259 /* Not found here, go up another level (until we reach the root) */
260 260
261 261 ParentNode = ParentNode->Parent;
262 262 }
263 263
264 264 /* Not found in parent tree */
265 265
266 266 return_ACPI_STATUS (AE_NOT_FOUND);
267 267 }
268 268
269 269
270 270 /*******************************************************************************
271 271 *
272 272 * FUNCTION: AcpiNsSearchAndEnter
273 273 *
274 274 * PARAMETERS: TargetName - Ascii ACPI name to search for (4 chars)
275 275 * WalkState - Current state of the walk
276 276 * Node - Starting node where search will begin
277 277 * InterpreterMode - Add names only in ACPI_MODE_LOAD_PASS_x.
278 278 * Otherwise,search only.
279 279 * Type - Object type to match
280 280 * Flags - Flags describing the search restrictions
281 281 * ReturnNode - Where the Node is returned
282 282 *
283 283 * RETURN: Status
284 284 *
285 285 * DESCRIPTION: Search for a name segment in a single namespace level,
286 286 * optionally adding it if it is not found. If the passed
287 287 * Type is not Any and the type previously stored in the
288 288 * entry was Any (i.e. unknown), update the stored type.
289 289 *
290 290 * In ACPI_IMODE_EXECUTE, search only.
291 291 * In other modes, search and add if not found.
292 292 *
293 293 ******************************************************************************/
294 294
295 295 ACPI_STATUS
296 296 AcpiNsSearchAndEnter (
297 297 UINT32 TargetName,
298 298 ACPI_WALK_STATE *WalkState,
299 299 ACPI_NAMESPACE_NODE *Node,
300 300 ACPI_INTERPRETER_MODE InterpreterMode,
301 301 ACPI_OBJECT_TYPE Type,
302 302 UINT32 Flags,
303 303 ACPI_NAMESPACE_NODE **ReturnNode)
304 304 {
305 305 ACPI_STATUS Status;
306 306 ACPI_NAMESPACE_NODE *NewNode;
307 307
308 308
309 309 ACPI_FUNCTION_TRACE (NsSearchAndEnter);
310 310
311 311
312 312 /* Parameter validation */
313 313
314 314 if (!Node || !TargetName || !ReturnNode)
315 315 {
316 316 ACPI_ERROR ((AE_INFO,
317 317 "Null parameter: Node %p Name 0x%X ReturnNode %p",
318 318 Node, TargetName, ReturnNode));
319 319 return_ACPI_STATUS (AE_BAD_PARAMETER);
320 320 }
321 321
322 322 /*
323 323 * Name must consist of valid ACPI characters. We will repair the name if
324 324 * necessary because we don't want to abort because of this, but we want
325 325 * all namespace names to be printable. A warning message is appropriate.
326 326 *
327 327 * This issue came up because there are in fact machines that exhibit
328 328 * this problem, and we want to be able to enable ACPI support for them,
329 329 * even though there are a few bad names.
330 330 */
331 331 AcpiUtRepairName (ACPI_CAST_PTR (char, &TargetName));
332 332
333 333 /* Try to find the name in the namespace level specified by the caller */
334 334
335 335 *ReturnNode = ACPI_ENTRY_NOT_FOUND;
336 336 Status = AcpiNsSearchOneScope (TargetName, Node, Type, ReturnNode);
337 337 if (Status != AE_NOT_FOUND)
338 338 {
339 339 /*
340 340 * If we found it AND the request specifies that a find is an error,
341 341 * return the error
342 342 */
343 343 if ((Status == AE_OK) &&
344 344 (Flags & ACPI_NS_ERROR_IF_FOUND))
345 345 {
346 346 Status = AE_ALREADY_EXISTS;
347 347 }
348 348
349 349 #ifdef ACPI_ASL_COMPILER
350 350 if (*ReturnNode && (*ReturnNode)->Type == ACPI_TYPE_ANY)
351 351 {
352 352 (*ReturnNode)->Flags |= ANOBJ_IS_EXTERNAL;
353 353 }
354 354 #endif
355 355
356 356 /* Either found it or there was an error: finished either way */
357 357
358 358 return_ACPI_STATUS (Status);
359 359 }
360 360
361 361 /*
362 362 * The name was not found. If we are NOT performing the first pass
363 363 * (name entry) of loading the namespace, search the parent tree (all the
364 364 * way to the root if necessary.) We don't want to perform the parent
365 365 * search when the namespace is actually being loaded. We want to perform
366 366 * the search when namespace references are being resolved (load pass 2)
367 367 * and during the execution phase.
368 368 */
369 369 if ((InterpreterMode != ACPI_IMODE_LOAD_PASS1) &&
370 370 (Flags & ACPI_NS_SEARCH_PARENT))
371 371 {
372 372 /*
373 373 * Not found at this level - search parent tree according to the
374 374 * ACPI specification
375 375 */
376 376 Status = AcpiNsSearchParentTree (TargetName, Node, Type, ReturnNode);
377 377 if (ACPI_SUCCESS (Status))
378 378 {
379 379 return_ACPI_STATUS (Status);
380 380 }
381 381 }
382 382
383 383 /* In execute mode, just search, never add names. Exit now */
384 384
385 385 if (InterpreterMode == ACPI_IMODE_EXECUTE)
386 386 {
387 387 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
388 388 "%4.4s Not found in %p [Not adding]\n",
389 389 ACPI_CAST_PTR (char, &TargetName), Node));
390 390
391 391 return_ACPI_STATUS (AE_NOT_FOUND);
392 392 }
393 393
394 394 /* Create the new named object */
395 395
396 396 NewNode = AcpiNsCreateNode (TargetName);
397 397 if (!NewNode)
398 398 {
399 399 return_ACPI_STATUS (AE_NO_MEMORY);
400 400 }
401 401
402 402 #ifdef ACPI_ASL_COMPILER
403 403
404 404 /* Node is an object defined by an External() statement */
405 405
406 406 if (Flags & ACPI_NS_EXTERNAL ||
407 407 (WalkState && WalkState->Opcode == AML_SCOPE_OP))
408 408 {
409 409 NewNode->Flags |= ANOBJ_IS_EXTERNAL;
410 410 }
411 411 #endif
412 412
413 413 if (Flags & ACPI_NS_TEMPORARY)
↓ open down ↓ |
395 lines elided |
↑ open up ↑ |
414 414 {
415 415 NewNode->Flags |= ANOBJ_TEMPORARY;
416 416 }
417 417
418 418 /* Install the new object into the parent's list of children */
419 419
420 420 AcpiNsInstallNode (WalkState, Node, NewNode, Type);
421 421 *ReturnNode = NewNode;
422 422 return_ACPI_STATUS (AE_OK);
423 423 }
424 -
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX