Deleted Added
sdiff udiff text old ( 77424 ) new ( 82367 )
full compact
1/******************************************************************************
2 *
3 * Module Name: dsmethod - Parser/Interpreter interface - control method parsing
4 * $Revision: 63 $
5 *
6 *****************************************************************************/
7
8/******************************************************************************
9 *
10 * 1. Copyright Notice
11 *
12 * Some or all of this work - Copyright (c) 1999, 2000, 2001, Intel Corp.
13 * All rights reserved.
14 *
15 * 2. License
16 *
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
20 * property rights.
21 *
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
28 *
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
37 *
38 * The above copyright and patent license is granted only if the following
39 * conditions are met:
40 *
41 * 3. Conditions
42 *
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
54 *
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
65 * make.
66 *
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3.4. Intel retains all right, title, and interest in and to the Original
74 * Intel Code.
75 *
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
80 *
81 * 4. Disclaimer and Export Compliance
82 *
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89 * PARTICULAR PURPOSE.
90 *
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98 * LIMITED REMEDY.
99 *
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
114 *
115 *****************************************************************************/
116
117#define __DSMETHOD_C__
118
119#include "acpi.h"
120#include "acparser.h"
121#include "amlcode.h"
122#include "acdispat.h"
123#include "acinterp.h"
124#include "acnamesp.h"
125#include "actables.h"
126#include "acdebug.h"
127
128
129#define _COMPONENT ACPI_DISPATCHER
130 MODULE_NAME ("dsmethod")
131
132
133/*******************************************************************************
134 *
135 * FUNCTION: AcpiDsParseMethod
136 *
137 * PARAMETERS: ObjHandle - Node of the method
138 * Level - Current nesting level
139 * Context - Points to a method counter
140 * ReturnValue - Not used
141 *
142 * RETURN: Status
143 *
144 * DESCRIPTION: Call the parser and parse the AML that is
145 * associated with the method.
146 *
147 * MUTEX: Assumes parser is locked
148 *
149 ******************************************************************************/
150
151ACPI_STATUS
152AcpiDsParseMethod (
153 ACPI_HANDLE ObjHandle)
154{
155 ACPI_STATUS Status;
156 ACPI_OPERAND_OBJECT *ObjDesc;
157 ACPI_PARSE_OBJECT *Op;
158 ACPI_NAMESPACE_NODE *Node;
159 ACPI_OWNER_ID OwnerId;
160
161
162 FUNCTION_TRACE_PTR ("DsParseMethod", ObjHandle);
163
164
165 /* Parameter Validation */
166
167 if (!ObjHandle)
168 {
169 return_ACPI_STATUS (AE_NULL_ENTRY);
170 }
171
172 DEBUG_PRINTP (ACPI_INFO, ("**** Parsing [%4.4s] **** NamedObj=%p\n",
173 &((ACPI_NAMESPACE_NODE *)ObjHandle)->Name, ObjHandle));
174
175
176 /* Extract the method object from the method Node */
177
178 Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
179 ObjDesc = Node->Object;
180 if (!ObjDesc)
181 {
182 return_ACPI_STATUS (AE_NULL_OBJECT);
183 }
184
185 /* Create a mutex for the method if there is a concurrency limit */
186
187 if ((ObjDesc->Method.Concurrency != INFINITE_CONCURRENCY) &&
188 (!ObjDesc->Method.Semaphore))
189 {
190 Status = AcpiOsCreateSemaphore (ObjDesc->Method.Concurrency,
191 ObjDesc->Method.Concurrency,
192 &ObjDesc->Method.Semaphore);
193 if (ACPI_FAILURE (Status))
194 {
195 return_ACPI_STATUS (Status);
196 }
197 }
198
199 /*
200 * Allocate a new parser op to be the root of the parsed
201 * method tree
202 */
203 Op = AcpiPsAllocOp (AML_METHOD_OP);
204 if (!Op)
205 {
206 return_ACPI_STATUS (AE_NO_MEMORY);
207 }
208
209 /* Init new op with the method name and pointer back to the Node */
210
211 AcpiPsSetName (Op, Node->Name);
212 Op->Node = Node;
213
214
215 /*
216 * Parse the method, first pass
217 *
218 * The first pass load is where newly declared named objects are
219 * added into the namespace. Actual evaluation of
220 * the named objects (what would be called a "second
221 * pass") happens during the actual execution of the
222 * method so that operands to the named objects can
223 * take on dynamic run-time values.
224 */
225 Status = AcpiPsParseAml (Op, ObjDesc->Method.Pcode,
226 ObjDesc->Method.PcodeLength,
227 ACPI_PARSE_LOAD_PASS1 | ACPI_PARSE_DELETE_TREE,
228 Node, NULL, NULL,
229 AcpiDsLoad1BeginOp, AcpiDsLoad1EndOp);
230
231 if (ACPI_FAILURE (Status))
232 {
233 return_ACPI_STATUS (Status);
234 }
235
236 /* Get a new OwnerId for objects created by this method */
237
238 OwnerId = AcpiUtAllocateOwnerId (OWNER_TYPE_METHOD);
239 ObjDesc->Method.OwningId = OwnerId;
240
241 DEBUG_PRINTP (ACPI_INFO, ("**** [%4.4s] Parsed **** NamedObj=%p Op=%p\n",
242 &((ACPI_NAMESPACE_NODE *)ObjHandle)->Name, ObjHandle, Op));
243
244 /* Install the parsed tree in the method object */
245 /* TBD: [Restructure] Obsolete field? */
246
247 AcpiPsDeleteParseTree (Op);
248
249 return_ACPI_STATUS (Status);
250}
251
252
253/*******************************************************************************
254 *
255 * FUNCTION: AcpiDsBeginMethodExecution
256 *
257 * PARAMETERS: MethodNode - Node of the method
258 * ObjDesc - The method object
259 * CallingMethodNode - Caller of this method (if non-null)
260 *
261 * RETURN: Status
262 *
263 * DESCRIPTION: Prepare a method for execution. Parses the method if necessary,
264 * increments the thread count, and waits at the method semaphore
265 * for clearance to execute.
266 *
267 * MUTEX: Locks/unlocks parser.
268 *
269 ******************************************************************************/
270
271ACPI_STATUS
272AcpiDsBeginMethodExecution (
273 ACPI_NAMESPACE_NODE *MethodNode,
274 ACPI_OPERAND_OBJECT *ObjDesc,
275 ACPI_NAMESPACE_NODE *CallingMethodNode)
276{
277 ACPI_STATUS Status = AE_OK;
278
279
280 FUNCTION_TRACE_PTR ("DsBeginMethodExecution", MethodNode);
281
282
283 if (!MethodNode)
284 {
285 return_ACPI_STATUS (AE_NULL_ENTRY);
286 }
287
288
289 /*
290 * If there is a concurrency limit on this method, we need to
291 * obtain a unit from the method semaphore.
292 */
293 if (ObjDesc->Method.Semaphore)
294 {
295 /*
296 * Allow recursive method calls, up to the reentrancy/concurrency
297 * limit imposed by the SERIALIZED rule and the SyncLevel method
298 * parameter.
299 *
300 * The point of this code is to avoid permanently blocking a
301 * thread that is making recursive method calls.
302 */
303 if (MethodNode == CallingMethodNode)
304 {
305 if (ObjDesc->Method.ThreadCount >= ObjDesc->Method.Concurrency)
306 {
307 return_ACPI_STATUS (AE_AML_METHOD_LIMIT);
308 }
309 }
310
311 /*
312 * Get a unit from the method semaphore. This releases the
313 * interpreter if we block
314 */
315 Status = AcpiExSystemWaitSemaphore (ObjDesc->Method.Semaphore,
316 WAIT_FOREVER);
317 }
318
319
320 /*
321 * Increment the method parse tree thread count since it has been
322 * reentered one more time (even if it is the same thread)
323 */
324 ObjDesc->Method.ThreadCount++;
325
326 return_ACPI_STATUS (Status);
327}
328
329
330/*******************************************************************************
331 *
332 * FUNCTION: AcpiDsCallControlMethod
333 *
334 * PARAMETERS: WalkState - Current state of the walk
335 * Op - Current Op to be walked
336 *
337 * RETURN: Status
338 *
339 * DESCRIPTION: Transfer execution to a called control method
340 *
341 ******************************************************************************/
342
343ACPI_STATUS
344AcpiDsCallControlMethod (
345 ACPI_WALK_LIST *WalkList,
346 ACPI_WALK_STATE *ThisWalkState,
347 ACPI_PARSE_OBJECT *Op)
348{
349 ACPI_STATUS Status;
350 ACPI_NAMESPACE_NODE *MethodNode;
351 ACPI_OPERAND_OBJECT *ObjDesc;
352 ACPI_WALK_STATE *NextWalkState;
353 ACPI_PARSE_STATE *ParserState;
354 UINT32 i;
355
356
357 FUNCTION_TRACE_PTR ("DsCallControlMethod", ThisWalkState);
358
359 DEBUG_PRINTP (TRACE_DISPATCH, ("Execute method %p, currentstate=%p\n",
360 ThisWalkState->PrevOp, ThisWalkState));
361
362 /*
363 * Get the namespace entry for the control method we are about to call
364 */
365 MethodNode = ThisWalkState->MethodCallNode;
366 if (!MethodNode)
367 {
368 return_ACPI_STATUS (AE_NULL_ENTRY);
369 }
370
371 ObjDesc = AcpiNsGetAttachedObject (MethodNode);
372 if (!ObjDesc)
373 {
374 return_ACPI_STATUS (AE_NULL_OBJECT);
375 }
376
377
378 /* Init for new method, wait on concurrency semaphore */
379
380 Status = AcpiDsBeginMethodExecution (MethodNode, ObjDesc,
381 ThisWalkState->MethodNode);
382 if (ACPI_FAILURE (Status))
383 {
384 return_ACPI_STATUS (Status);
385 }
386
387 /* Create and initialize a new parser state */
388
389 ParserState = AcpiPsCreateState (ObjDesc->Method.Pcode,
390 ObjDesc->Method.PcodeLength);
391 if (!ParserState)
392 {
393 return_ACPI_STATUS (AE_NO_MEMORY);
394 }
395
396 AcpiPsInitScope (ParserState, NULL);
397 ParserState->StartNode = MethodNode;
398
399
400 /* Create a new state for the preempting walk */
401
402 NextWalkState = AcpiDsCreateWalkState (ObjDesc->Method.OwningId,
403 NULL, ObjDesc, WalkList);
404 if (!NextWalkState)
405 {
406 /* TBD: delete parser state */
407
408 return_ACPI_STATUS (AE_NO_MEMORY);
409 }
410
411 NextWalkState->WalkType = WALK_METHOD;
412 NextWalkState->MethodNode = MethodNode;
413 NextWalkState->ParserState = ParserState;
414 NextWalkState->ParseFlags = ThisWalkState->ParseFlags;
415 NextWalkState->DescendingCallback = ThisWalkState->DescendingCallback;
416 NextWalkState->AscendingCallback = ThisWalkState->AscendingCallback;
417
418 /* The NextOp of the NextWalk will be the beginning of the method */
419 /* TBD: [Restructure] -- obsolete? */
420
421 NextWalkState->NextOp = NULL;
422
423 /* Open a new scope */
424
425 Status = AcpiDsScopeStackPush (MethodNode,
426 ACPI_TYPE_METHOD, NextWalkState);
427 if (ACPI_FAILURE (Status))
428 {
429 goto Cleanup;
430 }
431
432
433 /*
434 * Initialize the arguments for the method. The resolved
435 * arguments were put on the previous walk state's operand
436 * stack. Operands on the previous walk state stack always
437 * start at index 0.
438 */
439 Status = AcpiDsMethodDataInitArgs (&ThisWalkState->Operands[0],
440 ThisWalkState->NumOperands,
441 NextWalkState);
442 if (ACPI_FAILURE (Status))
443 {
444 goto Cleanup;
445 }
446
447
448 /* Create and init a Root Node */
449
450 Op = AcpiPsAllocOp (AML_SCOPE_OP);
451 if (!Op)
452 {
453 return_ACPI_STATUS (AE_NO_MEMORY);
454 }
455
456 Status = AcpiPsParseAml (Op, ObjDesc->Method.Pcode,
457 ObjDesc->Method.PcodeLength,
458 ACPI_PARSE_LOAD_PASS1 | ACPI_PARSE_DELETE_TREE,
459 MethodNode, NULL, NULL,
460 AcpiDsLoad1BeginOp, AcpiDsLoad1EndOp);
461 AcpiPsDeleteParseTree (Op);
462
463
464 /*
465 * Delete the operands on the previous walkstate operand stack
466 * (they were copied to new objects)
467 */
468 for (i = 0; i < ObjDesc->Method.ParamCount; i++)
469 {
470 AcpiUtRemoveReference (ThisWalkState->Operands [i]);
471 ThisWalkState->Operands [i] = NULL;
472 }
473
474 /* Clear the operand stack */
475
476 ThisWalkState->NumOperands = 0;
477
478
479 DEBUG_PRINTP (TRACE_DISPATCH, ("Starting nested execution, newstate=%p\n",
480 NextWalkState));
481
482 return_ACPI_STATUS (AE_OK);
483
484
485 /* On error, we must delete the new walk state */
486
487Cleanup:
488 AcpiDsTerminateControlMethod (NextWalkState);
489 AcpiDsDeleteWalkState (NextWalkState);
490 return_ACPI_STATUS (Status);
491
492}
493
494
495/*******************************************************************************
496 *
497 * FUNCTION: AcpiDsRestartControlMethod
498 *
499 * PARAMETERS: WalkState - State of the method when it was preempted
500 * Op - Pointer to new current op
501 *
502 * RETURN: Status
503 *
504 * DESCRIPTION: Restart a method that was preempted
505 *
506 ******************************************************************************/
507
508ACPI_STATUS
509AcpiDsRestartControlMethod (
510 ACPI_WALK_STATE *WalkState,
511 ACPI_OPERAND_OBJECT *ReturnDesc)
512{
513 ACPI_STATUS Status;
514
515
516 FUNCTION_TRACE_PTR ("DsRestartControlMethod", WalkState);
517
518
519 if (ReturnDesc)
520 {
521 if (WalkState->ReturnUsed)
522 {
523 /*
524 * Get the return value (if any) from the previous method.
525 * NULL if no return value
526 */
527 Status = AcpiDsResultPush (ReturnDesc, WalkState);
528 if (ACPI_FAILURE (Status))
529 {
530 AcpiUtRemoveReference (ReturnDesc);
531 return_ACPI_STATUS (Status);
532 }
533 }
534
535 else
536 {
537 /*
538 * Delete the return value if it will not be used by the
539 * calling method
540 */
541 AcpiUtRemoveReference (ReturnDesc);
542 }
543
544 }
545
546 DEBUG_PRINTP (TRACE_DISPATCH,
547 ("Method=%p Return=%p ReturnUsed?=%X ResStack=%p State=%p\n",
548 WalkState->MethodCallOp, ReturnDesc, WalkState->ReturnUsed,
549 WalkState->Results, WalkState));
550
551
552 return_ACPI_STATUS (AE_OK);
553}
554
555
556/*******************************************************************************
557 *
558 * FUNCTION: AcpiDsTerminateControlMethod
559 *
560 * PARAMETERS: WalkState - State of the method
561 *
562 * RETURN: Status
563 *
564 * DESCRIPTION: Terminate a control method. Delete everything that the method
565 * created, delete all locals and arguments, and delete the parse
566 * tree if requested.
567 *
568 ******************************************************************************/
569
570ACPI_STATUS
571AcpiDsTerminateControlMethod (
572 ACPI_WALK_STATE *WalkState)
573{
574 ACPI_OPERAND_OBJECT *ObjDesc;
575 ACPI_NAMESPACE_NODE *MethodNode;
576
577
578 FUNCTION_TRACE_PTR ("DsTerminateControlMethod", WalkState);
579
580
581 /* The method object should be stored in the walk state */
582
583 ObjDesc = WalkState->MethodDesc;
584 if (!ObjDesc)
585 {
586 return_ACPI_STATUS (AE_OK);
587 }
588
589 /* Delete all arguments and locals */
590
591 AcpiDsMethodDataDeleteAll (WalkState);
592
593 /*
594 * Lock the parser while we terminate this method.
595 * If this is the last thread executing the method,
596 * we have additional cleanup to perform
597 */
598 AcpiUtAcquireMutex (ACPI_MTX_PARSER);
599
600
601 /* Signal completion of the execution of this method if necessary */
602
603 if (WalkState->MethodDesc->Method.Semaphore)
604 {
605 AcpiOsSignalSemaphore (
606 WalkState->MethodDesc->Method.Semaphore, 1);
607 }
608
609 /* Decrement the thread count on the method parse tree */
610
611 WalkState->MethodDesc->Method.ThreadCount--;
612 if (!WalkState->MethodDesc->Method.ThreadCount)
613 {
614 /*
615 * There are no more threads executing this method. Perform
616 * additional cleanup.
617 *
618 * The method Node is stored in the walk state
619 */
620 MethodNode = WalkState->MethodNode;
621
622 /*
623 * Delete any namespace entries created immediately underneath
624 * the method
625 */
626 AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
627 if (MethodNode->Child)
628 {
629 AcpiNsDeleteNamespaceSubtree (MethodNode);
630 }
631
632 /*
633 * Delete any namespace entries created anywhere else within
634 * the namespace
635 */
636 AcpiNsDeleteNamespaceByOwner (WalkState->MethodDesc->Method.OwningId);
637 AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
638 }
639
640 AcpiUtReleaseMutex (ACPI_MTX_PARSER);
641 return_ACPI_STATUS (AE_OK);
642}
643
644