Print this page
update to acpica-unix2-20131218
acpica-unix2-20130823
PANKOVs restructure
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/intel/io/acpica/dispatcher/dswload.c
+++ new/usr/src/common/acpica/components/dispatcher/dswload.c
1 1 /******************************************************************************
2 2 *
3 3 * Module Name: dswload - Dispatcher first pass namespace load callbacks
4 4 *
5 5 *****************************************************************************/
6 6
7 7 /*
8 - * Copyright (C) 2000 - 2011, Intel Corp.
8 + * Copyright (C) 2000 - 2013, 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 __DSWLOAD_C__
45 45
46 46 #include "acpi.h"
47 47 #include "accommon.h"
48 48 #include "acparser.h"
49 49 #include "amlcode.h"
50 50 #include "acdispat.h"
51 51 #include "acinterp.h"
52 52 #include "acnamesp.h"
53 53
54 54 #ifdef ACPI_ASL_COMPILER
55 55 #include "acdisasm.h"
56 56 #endif
57 57
58 58 #define _COMPONENT ACPI_DISPATCHER
59 59 ACPI_MODULE_NAME ("dswload")
60 60
61 61
62 62 /*******************************************************************************
63 63 *
64 64 * FUNCTION: AcpiDsInitCallbacks
65 65 *
66 66 * PARAMETERS: WalkState - Current state of the parse tree walk
67 67 * PassNumber - 1, 2, or 3
68 68 *
69 69 * RETURN: Status
70 70 *
71 71 * DESCRIPTION: Init walk state callbacks
72 72 *
73 73 ******************************************************************************/
↓ open down ↓ |
55 lines elided |
↑ open up ↑ |
74 74
75 75 ACPI_STATUS
76 76 AcpiDsInitCallbacks (
77 77 ACPI_WALK_STATE *WalkState,
78 78 UINT32 PassNumber)
79 79 {
80 80
81 81 switch (PassNumber)
82 82 {
83 83 case 1:
84 +
84 85 WalkState->ParseFlags = ACPI_PARSE_LOAD_PASS1 |
85 86 ACPI_PARSE_DELETE_TREE;
86 87 WalkState->DescendingCallback = AcpiDsLoad1BeginOp;
87 88 WalkState->AscendingCallback = AcpiDsLoad1EndOp;
88 89 break;
89 90
90 91 case 2:
92 +
91 93 WalkState->ParseFlags = ACPI_PARSE_LOAD_PASS1 |
92 94 ACPI_PARSE_DELETE_TREE;
93 95 WalkState->DescendingCallback = AcpiDsLoad2BeginOp;
94 96 WalkState->AscendingCallback = AcpiDsLoad2EndOp;
95 97 break;
96 98
97 99 case 3:
100 +
98 101 #ifndef ACPI_NO_METHOD_EXECUTION
99 102 WalkState->ParseFlags |= ACPI_PARSE_EXECUTE |
100 103 ACPI_PARSE_DELETE_TREE;
101 104 WalkState->DescendingCallback = AcpiDsExecBeginOp;
102 105 WalkState->AscendingCallback = AcpiDsExecEndOp;
103 106 #endif
104 107 break;
105 108
106 109 default:
110 +
107 111 return (AE_BAD_PARAMETER);
108 112 }
109 113
110 114 return (AE_OK);
111 115 }
112 116
113 117
114 118 /*******************************************************************************
115 119 *
116 120 * FUNCTION: AcpiDsLoad1BeginOp
117 121 *
118 122 * PARAMETERS: WalkState - Current state of the parse tree walk
119 123 * OutOp - Where to return op if a new one is created
120 124 *
121 125 * RETURN: Status
122 126 *
123 127 * DESCRIPTION: Descending callback used during the loading of ACPI tables.
124 128 *
125 129 ******************************************************************************/
126 130
127 131 ACPI_STATUS
128 132 AcpiDsLoad1BeginOp (
129 133 ACPI_WALK_STATE *WalkState,
130 134 ACPI_PARSE_OBJECT **OutOp)
131 135 {
132 136 ACPI_PARSE_OBJECT *Op;
133 137 ACPI_NAMESPACE_NODE *Node;
134 138 ACPI_STATUS Status;
135 139 ACPI_OBJECT_TYPE ObjectType;
136 140 char *Path;
137 141 UINT32 Flags;
138 142
139 143
140 144 ACPI_FUNCTION_TRACE (DsLoad1BeginOp);
141 145
142 146
143 147 Op = WalkState->Op;
144 148 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState));
145 149
146 150 /* We are only interested in opcodes that have an associated name */
147 151
148 152 if (Op)
149 153 {
150 154 if (!(WalkState->OpInfo->Flags & AML_NAMED))
151 155 {
152 156 *OutOp = Op;
153 157 return_ACPI_STATUS (AE_OK);
154 158 }
155 159
156 160 /* Check if this object has already been installed in the namespace */
157 161
158 162 if (Op->Common.Node)
159 163 {
160 164 *OutOp = Op;
161 165 return_ACPI_STATUS (AE_OK);
162 166 }
163 167 }
164 168
165 169 Path = AcpiPsGetNextNamestring (&WalkState->ParserState);
166 170
↓ open down ↓ |
50 lines elided |
↑ open up ↑ |
167 171 /* Map the raw opcode into an internal object type */
168 172
169 173 ObjectType = WalkState->OpInfo->ObjectType;
170 174
171 175 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
172 176 "State=%p Op=%p [%s]\n", WalkState, Op, AcpiUtGetTypeName (ObjectType)));
173 177
174 178 switch (WalkState->Opcode)
175 179 {
176 180 case AML_SCOPE_OP:
177 -
178 181 /*
179 182 * The target name of the Scope() operator must exist at this point so
180 183 * that we can actually open the scope to enter new names underneath it.
181 184 * Allow search-to-root for single namesegs.
182 185 */
183 186 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
184 187 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, WalkState, &(Node));
185 188 #ifdef ACPI_ASL_COMPILER
186 189 if (Status == AE_NOT_FOUND)
187 190 {
188 191 /*
189 192 * Table disassembly:
190 193 * Target of Scope() not found. Generate an External for it, and
191 194 * insert the name into the namespace.
192 195 */
193 - AcpiDmAddToExternalList (Op, Path, ACPI_TYPE_DEVICE, 0);
196 + AcpiDmAddOpToExternalList (Op, Path, ACPI_TYPE_DEVICE, 0, 0);
194 197 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
195 198 ACPI_IMODE_LOAD_PASS1, ACPI_NS_SEARCH_PARENT,
196 199 WalkState, &Node);
197 200 }
198 201 #endif
199 202 if (ACPI_FAILURE (Status))
200 203 {
201 204 ACPI_ERROR_NAMESPACE (Path, Status);
202 205 return_ACPI_STATUS (Status);
203 206 }
204 207
205 208 /*
206 209 * Check to make sure that the target is
207 210 * one of the opcodes that actually opens a scope
208 211 */
209 212 switch (Node->Type)
210 213 {
211 214 case ACPI_TYPE_ANY:
212 215 case ACPI_TYPE_LOCAL_SCOPE: /* Scope */
213 216 case ACPI_TYPE_DEVICE:
↓ open down ↓ |
10 lines elided |
↑ open up ↑ |
214 217 case ACPI_TYPE_POWER:
215 218 case ACPI_TYPE_PROCESSOR:
216 219 case ACPI_TYPE_THERMAL:
217 220
218 221 /* These are acceptable types */
219 222 break;
220 223
221 224 case ACPI_TYPE_INTEGER:
222 225 case ACPI_TYPE_STRING:
223 226 case ACPI_TYPE_BUFFER:
224 -
225 227 /*
226 228 * These types we will allow, but we will change the type.
227 229 * This enables some existing code of the form:
228 230 *
229 231 * Name (DEB, 0)
230 232 * Scope (DEB) { ... }
231 233 *
232 234 * Note: silently change the type here. On the second pass,
233 235 * we will report a warning
234 236 */
235 237 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
236 238 "Type override - [%4.4s] had invalid type (%s) "
237 239 "for Scope operator, changed to type ANY\n",
238 240 AcpiUtGetNodeName (Node), AcpiUtGetTypeName (Node->Type)));
239 241
240 242 Node->Type = ACPI_TYPE_ANY;
241 243 WalkState->ScopeInfo->Common.Value = ACPI_TYPE_ANY;
242 244 break;
243 245
246 + case ACPI_TYPE_METHOD:
247 + /*
248 + * Allow scope change to root during execution of module-level
249 + * code. Root is typed METHOD during this time.
250 + */
251 + if ((Node == AcpiGbl_RootNode) &&
252 + (WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL))
253 + {
254 + break;
255 + }
256 +
257 + /*lint -fallthrough */
258 +
244 259 default:
245 260
246 261 /* All other types are an error */
247 262
248 263 ACPI_ERROR ((AE_INFO,
249 264 "Invalid type (%s) for target of "
250 265 "Scope operator [%4.4s] (Cannot override)",
251 266 AcpiUtGetTypeName (Node->Type), AcpiUtGetNodeName (Node)));
252 267
253 268 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
254 269 }
255 270 break;
256 271
257 -
258 272 default:
259 273 /*
260 274 * For all other named opcodes, we will enter the name into
261 275 * the namespace.
262 276 *
263 277 * Setup the search flags.
264 278 * Since we are entering a name into the namespace, we do not want to
265 279 * enable the search-to-root upsearch.
266 280 *
267 281 * There are only two conditions where it is acceptable that the name
268 282 * already exists:
269 283 * 1) the Scope() operator can reopen a scoping object that was
270 284 * previously defined (Scope, Method, Device, etc.)
271 285 * 2) Whenever we are parsing a deferred opcode (OpRegion, Buffer,
272 286 * BufferField, or Package), the name of the object is already
273 287 * in the namespace.
274 288 */
275 289 if (WalkState->DeferredNode)
276 290 {
277 291 /* This name is already in the namespace, get the node */
278 292
279 293 Node = WalkState->DeferredNode;
280 294 Status = AE_OK;
281 295 break;
282 296 }
283 297
284 298 /*
285 299 * If we are executing a method, do not create any namespace objects
286 300 * during the load phase, only during execution.
287 301 */
288 302 if (WalkState->MethodNode)
289 303 {
290 304 Node = NULL;
291 305 Status = AE_OK;
292 306 break;
293 307 }
294 308
295 309 Flags = ACPI_NS_NO_UPSEARCH;
296 310 if ((WalkState->Opcode != AML_SCOPE_OP) &&
297 311 (!(WalkState->ParseFlags & ACPI_PARSE_DEFERRED_OP)))
298 312 {
299 313 Flags |= ACPI_NS_ERROR_IF_FOUND;
300 314 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[%s] Cannot already exist\n",
301 315 AcpiUtGetTypeName (ObjectType)));
302 316 }
303 317 else
304 318 {
305 319 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
306 320 "[%s] Both Find or Create allowed\n",
307 321 AcpiUtGetTypeName (ObjectType)));
308 322 }
309 323
310 324 /*
311 325 * Enter the named type into the internal namespace. We enter the name
312 326 * as we go downward in the parse tree. Any necessary subobjects that
313 327 * involve arguments to the opcode must be created as we go back up the
314 328 * parse tree later.
315 329 */
316 330 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
317 331 ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &Node);
318 332 if (ACPI_FAILURE (Status))
319 333 {
320 334 if (Status == AE_ALREADY_EXISTS)
321 335 {
322 336 /* The name already exists in this scope */
323 337
324 338 if (Node->Flags & ANOBJ_IS_EXTERNAL)
325 339 {
326 340 /*
327 341 * Allow one create on an object or segment that was
328 342 * previously declared External
329 343 */
330 344 Node->Flags &= ~ANOBJ_IS_EXTERNAL;
331 345 Node->Type = (UINT8) ObjectType;
332 346
333 347 /* Just retyped a node, probably will need to open a scope */
334 348
335 349 if (AcpiNsOpensScope (ObjectType))
336 350 {
337 351 Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
338 352 if (ACPI_FAILURE (Status))
339 353 {
340 354 return_ACPI_STATUS (Status);
341 355 }
342 356 }
343 357
344 358 Status = AE_OK;
345 359 }
346 360 }
347 361
348 362 if (ACPI_FAILURE (Status))
349 363 {
350 364 ACPI_ERROR_NAMESPACE (Path, Status);
351 365 return_ACPI_STATUS (Status);
352 366 }
353 367 }
354 368 break;
355 369 }
356 370
357 371 /* Common exit */
358 372
359 373 if (!Op)
360 374 {
361 375 /* Create a new op */
362 376
363 377 Op = AcpiPsAllocOp (WalkState->Opcode);
364 378 if (!Op)
365 379 {
366 380 return_ACPI_STATUS (AE_NO_MEMORY);
367 381 }
368 382 }
369 383
370 384 /* Initialize the op */
371 385
372 386 #if (defined (ACPI_NO_METHOD_EXECUTION) || defined (ACPI_CONSTANT_EVAL_ONLY))
373 387 Op->Named.Path = ACPI_CAST_PTR (UINT8, Path);
374 388 #endif
375 389
376 390 if (Node)
377 391 {
378 392 /*
379 393 * Put the Node in the "op" object that the parser uses, so we
380 394 * can get it again quickly when this scope is closed
381 395 */
382 396 Op->Common.Node = Node;
383 397 Op->Named.Name = Node->Name.Integer;
384 398 }
385 399
386 400 AcpiPsAppendArg (AcpiPsGetParentScope (&WalkState->ParserState), Op);
387 401 *OutOp = Op;
388 402 return_ACPI_STATUS (Status);
389 403 }
390 404
391 405
392 406 /*******************************************************************************
393 407 *
394 408 * FUNCTION: AcpiDsLoad1EndOp
395 409 *
396 410 * PARAMETERS: WalkState - Current state of the parse tree walk
397 411 *
398 412 * RETURN: Status
399 413 *
400 414 * DESCRIPTION: Ascending callback used during the loading of the namespace,
401 415 * both control methods and everything else.
402 416 *
403 417 ******************************************************************************/
404 418
405 419 ACPI_STATUS
406 420 AcpiDsLoad1EndOp (
407 421 ACPI_WALK_STATE *WalkState)
408 422 {
409 423 ACPI_PARSE_OBJECT *Op;
410 424 ACPI_OBJECT_TYPE ObjectType;
411 425 ACPI_STATUS Status = AE_OK;
412 426
413 427
414 428 ACPI_FUNCTION_TRACE (DsLoad1EndOp);
415 429
416 430
417 431 Op = WalkState->Op;
418 432 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState));
419 433
420 434 /* We are only interested in opcodes that have an associated name */
421 435
422 436 if (!(WalkState->OpInfo->Flags & (AML_NAMED | AML_FIELD)))
423 437 {
424 438 return_ACPI_STATUS (AE_OK);
425 439 }
426 440
427 441 /* Get the object type to determine if we should pop the scope */
428 442
429 443 ObjectType = WalkState->OpInfo->ObjectType;
430 444
431 445 #ifndef ACPI_NO_METHOD_EXECUTION
432 446 if (WalkState->OpInfo->Flags & AML_FIELD)
433 447 {
434 448 /*
435 449 * If we are executing a method, do not create any namespace objects
436 450 * during the load phase, only during execution.
437 451 */
438 452 if (!WalkState->MethodNode)
439 453 {
440 454 if (WalkState->Opcode == AML_FIELD_OP ||
441 455 WalkState->Opcode == AML_BANK_FIELD_OP ||
442 456 WalkState->Opcode == AML_INDEX_FIELD_OP)
443 457 {
444 458 Status = AcpiDsInitFieldObjects (Op, WalkState);
445 459 }
446 460 }
447 461 return_ACPI_STATUS (Status);
448 462 }
449 463
450 464 /*
451 465 * If we are executing a method, do not create any namespace objects
452 466 * during the load phase, only during execution.
453 467 */
454 468 if (!WalkState->MethodNode)
455 469 {
456 470 if (Op->Common.AmlOpcode == AML_REGION_OP)
457 471 {
458 472 Status = AcpiExCreateRegion (Op->Named.Data, Op->Named.Length,
459 473 (ACPI_ADR_SPACE_TYPE) ((Op->Common.Value.Arg)->Common.Value.Integer),
460 474 WalkState);
461 475 if (ACPI_FAILURE (Status))
462 476 {
463 477 return_ACPI_STATUS (Status);
464 478 }
465 479 }
466 480 else if (Op->Common.AmlOpcode == AML_DATA_REGION_OP)
467 481 {
468 482 Status = AcpiExCreateRegion (Op->Named.Data, Op->Named.Length,
469 483 ACPI_ADR_SPACE_DATA_TABLE, WalkState);
470 484 if (ACPI_FAILURE (Status))
471 485 {
472 486 return_ACPI_STATUS (Status);
473 487 }
474 488 }
475 489 }
476 490 #endif
477 491
478 492 if (Op->Common.AmlOpcode == AML_NAME_OP)
479 493 {
480 494 /* For Name opcode, get the object type from the argument */
481 495
482 496 if (Op->Common.Value.Arg)
483 497 {
484 498 ObjectType = (AcpiPsGetOpcodeInfo (
485 499 (Op->Common.Value.Arg)->Common.AmlOpcode))->ObjectType;
486 500
487 501 /* Set node type if we have a namespace node */
488 502
489 503 if (Op->Common.Node)
490 504 {
491 505 Op->Common.Node->Type = (UINT8) ObjectType;
492 506 }
493 507 }
494 508 }
495 509
496 510 /*
497 511 * If we are executing a method, do not create any namespace objects
498 512 * during the load phase, only during execution.
499 513 */
500 514 if (!WalkState->MethodNode)
501 515 {
502 516 if (Op->Common.AmlOpcode == AML_METHOD_OP)
503 517 {
504 518 /*
505 519 * MethodOp PkgLength NameString MethodFlags TermList
506 520 *
507 521 * Note: We must create the method node/object pair as soon as we
508 522 * see the method declaration. This allows later pass1 parsing
509 523 * of invocations of the method (need to know the number of
510 524 * arguments.)
511 525 */
512 526 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
513 527 "LOADING-Method: State=%p Op=%p NamedObj=%p\n",
514 528 WalkState, Op, Op->Named.Node));
515 529
516 530 if (!AcpiNsGetAttachedObject (Op->Named.Node))
517 531 {
518 532 WalkState->Operands[0] = ACPI_CAST_PTR (void, Op->Named.Node);
519 533 WalkState->NumOperands = 1;
520 534
521 535 Status = AcpiDsCreateOperands (WalkState, Op->Common.Value.Arg);
522 536 if (ACPI_SUCCESS (Status))
523 537 {
524 538 Status = AcpiExCreateMethod (Op->Named.Data,
525 539 Op->Named.Length, WalkState);
526 540 }
527 541
528 542 WalkState->Operands[0] = NULL;
529 543 WalkState->NumOperands = 0;
530 544
531 545 if (ACPI_FAILURE (Status))
532 546 {
533 547 return_ACPI_STATUS (Status);
534 548 }
535 549 }
536 550 }
537 551 }
538 552
539 553 /* Pop the scope stack (only if loading a table) */
540 554
541 555 if (!WalkState->MethodNode &&
542 556 AcpiNsOpensScope (ObjectType))
543 557 {
544 558 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "(%s): Popping scope for Op %p\n",
545 559 AcpiUtGetTypeName (ObjectType), Op));
546 560
547 561 Status = AcpiDsScopeStackPop (WalkState);
548 562 }
549 563
550 564 return_ACPI_STATUS (Status);
551 565 }
↓ open down ↓ |
284 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX