xref: /freebsd/sys/contrib/dev/acpica/components/debugger/dbmethod.c (revision a9d8d09c46ec699e45f3fd46ca9abcf02e5baca9)
1a159c266SJung-uk Kim /*******************************************************************************
2a159c266SJung-uk Kim  *
3a159c266SJung-uk Kim  * Module Name: dbmethod - Debug commands for control methods
4a159c266SJung-uk Kim  *
5a159c266SJung-uk Kim  ******************************************************************************/
6a159c266SJung-uk Kim 
7a159c266SJung-uk Kim /*
8efcc2a30SJung-uk Kim  * Copyright (C) 2000 - 2013, Intel Corp.
9a159c266SJung-uk Kim  * All rights reserved.
10a159c266SJung-uk Kim  *
11a159c266SJung-uk Kim  * Redistribution and use in source and binary forms, with or without
12a159c266SJung-uk Kim  * modification, are permitted provided that the following conditions
13a159c266SJung-uk Kim  * are met:
14a159c266SJung-uk Kim  * 1. Redistributions of source code must retain the above copyright
15a159c266SJung-uk Kim  *    notice, this list of conditions, and the following disclaimer,
16a159c266SJung-uk Kim  *    without modification.
17a159c266SJung-uk Kim  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18a159c266SJung-uk Kim  *    substantially similar to the "NO WARRANTY" disclaimer below
19a159c266SJung-uk Kim  *    ("Disclaimer") and any redistribution must be conditioned upon
20a159c266SJung-uk Kim  *    including a substantially similar Disclaimer requirement for further
21a159c266SJung-uk Kim  *    binary redistribution.
22a159c266SJung-uk Kim  * 3. Neither the names of the above-listed copyright holders nor the names
23a159c266SJung-uk Kim  *    of any contributors may be used to endorse or promote products derived
24a159c266SJung-uk Kim  *    from this software without specific prior written permission.
25a159c266SJung-uk Kim  *
26a159c266SJung-uk Kim  * Alternatively, this software may be distributed under the terms of the
27a159c266SJung-uk Kim  * GNU General Public License ("GPL") version 2 as published by the Free
28a159c266SJung-uk Kim  * Software Foundation.
29a159c266SJung-uk Kim  *
30a159c266SJung-uk Kim  * NO WARRANTY
31a159c266SJung-uk Kim  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32a159c266SJung-uk Kim  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33a159c266SJung-uk Kim  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34a159c266SJung-uk Kim  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35a159c266SJung-uk Kim  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36a159c266SJung-uk Kim  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37a159c266SJung-uk Kim  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38a159c266SJung-uk Kim  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39a159c266SJung-uk Kim  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40a159c266SJung-uk Kim  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41a159c266SJung-uk Kim  * POSSIBILITY OF SUCH DAMAGES.
42a159c266SJung-uk Kim  */
43a159c266SJung-uk Kim 
44a159c266SJung-uk Kim 
45a159c266SJung-uk Kim #include <contrib/dev/acpica/include/acpi.h>
46a159c266SJung-uk Kim #include <contrib/dev/acpica/include/accommon.h>
47a159c266SJung-uk Kim #include <contrib/dev/acpica/include/acdispat.h>
48a159c266SJung-uk Kim #include <contrib/dev/acpica/include/acnamesp.h>
49a159c266SJung-uk Kim #include <contrib/dev/acpica/include/acdebug.h>
50a159c266SJung-uk Kim #include <contrib/dev/acpica/include/acdisasm.h>
51a159c266SJung-uk Kim #include <contrib/dev/acpica/include/acparser.h>
52895f26a9SJung-uk Kim #include <contrib/dev/acpica/include/acpredef.h>
53a159c266SJung-uk Kim 
54a159c266SJung-uk Kim 
55a159c266SJung-uk Kim #ifdef ACPI_DEBUGGER
56a159c266SJung-uk Kim 
57a159c266SJung-uk Kim #define _COMPONENT          ACPI_CA_DEBUGGER
58a159c266SJung-uk Kim         ACPI_MODULE_NAME    ("dbmethod")
59a159c266SJung-uk Kim 
60a159c266SJung-uk Kim 
61a159c266SJung-uk Kim /* Local prototypes */
62a159c266SJung-uk Kim 
63a159c266SJung-uk Kim static ACPI_STATUS
64a159c266SJung-uk Kim AcpiDbWalkForExecute (
65a159c266SJung-uk Kim     ACPI_HANDLE             ObjHandle,
66a159c266SJung-uk Kim     UINT32                  NestingLevel,
67a159c266SJung-uk Kim     void                    *Context,
68a159c266SJung-uk Kim     void                    **ReturnValue);
69a159c266SJung-uk Kim 
70a159c266SJung-uk Kim 
71a159c266SJung-uk Kim /*******************************************************************************
72a159c266SJung-uk Kim  *
73a159c266SJung-uk Kim  * FUNCTION:    AcpiDbSetMethodBreakpoint
74a159c266SJung-uk Kim  *
75a159c266SJung-uk Kim  * PARAMETERS:  Location            - AML offset of breakpoint
76a159c266SJung-uk Kim  *              WalkState           - Current walk info
77a159c266SJung-uk Kim  *              Op                  - Current Op (from parse walk)
78a159c266SJung-uk Kim  *
79a159c266SJung-uk Kim  * RETURN:      None
80a159c266SJung-uk Kim  *
81a159c266SJung-uk Kim  * DESCRIPTION: Set a breakpoint in a control method at the specified
82a159c266SJung-uk Kim  *              AML offset
83a159c266SJung-uk Kim  *
84a159c266SJung-uk Kim  ******************************************************************************/
85a159c266SJung-uk Kim 
86a159c266SJung-uk Kim void
87a159c266SJung-uk Kim AcpiDbSetMethodBreakpoint (
88a159c266SJung-uk Kim     char                    *Location,
89a159c266SJung-uk Kim     ACPI_WALK_STATE         *WalkState,
90a159c266SJung-uk Kim     ACPI_PARSE_OBJECT       *Op)
91a159c266SJung-uk Kim {
92a159c266SJung-uk Kim     UINT32                  Address;
93a159c266SJung-uk Kim 
94a159c266SJung-uk Kim 
95a159c266SJung-uk Kim     if (!Op)
96a159c266SJung-uk Kim     {
97a159c266SJung-uk Kim         AcpiOsPrintf ("There is no method currently executing\n");
98a159c266SJung-uk Kim         return;
99a159c266SJung-uk Kim     }
100a159c266SJung-uk Kim 
101a159c266SJung-uk Kim     /* Get and verify the breakpoint address */
102a159c266SJung-uk Kim 
103a159c266SJung-uk Kim     Address = ACPI_STRTOUL (Location, NULL, 16);
104a159c266SJung-uk Kim     if (Address <= Op->Common.AmlOffset)
105a159c266SJung-uk Kim     {
106a159c266SJung-uk Kim         AcpiOsPrintf ("Breakpoint %X is beyond current address %X\n",
107a159c266SJung-uk Kim             Address, Op->Common.AmlOffset);
108a159c266SJung-uk Kim     }
109a159c266SJung-uk Kim 
110a159c266SJung-uk Kim     /* Save breakpoint in current walk */
111a159c266SJung-uk Kim 
112a159c266SJung-uk Kim     WalkState->UserBreakpoint = Address;
113a159c266SJung-uk Kim     AcpiOsPrintf ("Breakpoint set at AML offset %X\n", Address);
114a159c266SJung-uk Kim }
115a159c266SJung-uk Kim 
116a159c266SJung-uk Kim 
117a159c266SJung-uk Kim /*******************************************************************************
118a159c266SJung-uk Kim  *
119a159c266SJung-uk Kim  * FUNCTION:    AcpiDbSetMethodCallBreakpoint
120a159c266SJung-uk Kim  *
121a159c266SJung-uk Kim  * PARAMETERS:  Op                  - Current Op (from parse walk)
122a159c266SJung-uk Kim  *
123a159c266SJung-uk Kim  * RETURN:      None
124a159c266SJung-uk Kim  *
125a159c266SJung-uk Kim  * DESCRIPTION: Set a breakpoint in a control method at the specified
126a159c266SJung-uk Kim  *              AML offset
127a159c266SJung-uk Kim  *
128a159c266SJung-uk Kim  ******************************************************************************/
129a159c266SJung-uk Kim 
130a159c266SJung-uk Kim void
131a159c266SJung-uk Kim AcpiDbSetMethodCallBreakpoint (
132a159c266SJung-uk Kim     ACPI_PARSE_OBJECT       *Op)
133a159c266SJung-uk Kim {
134a159c266SJung-uk Kim 
135a159c266SJung-uk Kim 
136a159c266SJung-uk Kim     if (!Op)
137a159c266SJung-uk Kim     {
138a159c266SJung-uk Kim         AcpiOsPrintf ("There is no method currently executing\n");
139a159c266SJung-uk Kim         return;
140a159c266SJung-uk Kim     }
141a159c266SJung-uk Kim 
142a159c266SJung-uk Kim     AcpiGbl_StepToNextCall = TRUE;
143a159c266SJung-uk Kim }
144a159c266SJung-uk Kim 
145a159c266SJung-uk Kim 
146a159c266SJung-uk Kim /*******************************************************************************
147a159c266SJung-uk Kim  *
148a159c266SJung-uk Kim  * FUNCTION:    AcpiDbSetMethodData
149a159c266SJung-uk Kim  *
150a159c266SJung-uk Kim  * PARAMETERS:  TypeArg         - L for local, A for argument
151a159c266SJung-uk Kim  *              IndexArg        - which one
152a159c266SJung-uk Kim  *              ValueArg        - Value to set.
153a159c266SJung-uk Kim  *
154a159c266SJung-uk Kim  * RETURN:      None
155a159c266SJung-uk Kim  *
156a159c266SJung-uk Kim  * DESCRIPTION: Set a local or argument for the running control method.
157a159c266SJung-uk Kim  *              NOTE: only object supported is Number.
158a159c266SJung-uk Kim  *
159a159c266SJung-uk Kim  ******************************************************************************/
160a159c266SJung-uk Kim 
161a159c266SJung-uk Kim void
162a159c266SJung-uk Kim AcpiDbSetMethodData (
163a159c266SJung-uk Kim     char                    *TypeArg,
164a159c266SJung-uk Kim     char                    *IndexArg,
165a159c266SJung-uk Kim     char                    *ValueArg)
166a159c266SJung-uk Kim {
167a159c266SJung-uk Kim     char                    Type;
168a159c266SJung-uk Kim     UINT32                  Index;
169a159c266SJung-uk Kim     UINT32                  Value;
170a159c266SJung-uk Kim     ACPI_WALK_STATE         *WalkState;
171a159c266SJung-uk Kim     ACPI_OPERAND_OBJECT     *ObjDesc;
172a159c266SJung-uk Kim     ACPI_STATUS             Status;
173a159c266SJung-uk Kim     ACPI_NAMESPACE_NODE     *Node;
174a159c266SJung-uk Kim 
175a159c266SJung-uk Kim 
176a159c266SJung-uk Kim     /* Validate TypeArg */
177a159c266SJung-uk Kim 
178a159c266SJung-uk Kim     AcpiUtStrupr (TypeArg);
179a159c266SJung-uk Kim     Type = TypeArg[0];
180a159c266SJung-uk Kim     if ((Type != 'L') &&
181a159c266SJung-uk Kim         (Type != 'A') &&
182a159c266SJung-uk Kim         (Type != 'N'))
183a159c266SJung-uk Kim     {
184a159c266SJung-uk Kim         AcpiOsPrintf ("Invalid SET operand: %s\n", TypeArg);
185a159c266SJung-uk Kim         return;
186a159c266SJung-uk Kim     }
187a159c266SJung-uk Kim 
188a159c266SJung-uk Kim     Value = ACPI_STRTOUL (ValueArg, NULL, 16);
189a159c266SJung-uk Kim 
190a159c266SJung-uk Kim     if (Type == 'N')
191a159c266SJung-uk Kim     {
192a159c266SJung-uk Kim         Node = AcpiDbConvertToNode (IndexArg);
193a159c266SJung-uk Kim         if (Node->Type != ACPI_TYPE_INTEGER)
194a159c266SJung-uk Kim         {
195a159c266SJung-uk Kim             AcpiOsPrintf ("Can only set Integer nodes\n");
196a159c266SJung-uk Kim             return;
197a159c266SJung-uk Kim         }
198a159c266SJung-uk Kim         ObjDesc = Node->Object;
199a159c266SJung-uk Kim         ObjDesc->Integer.Value = Value;
200a159c266SJung-uk Kim         return;
201a159c266SJung-uk Kim     }
202a159c266SJung-uk Kim 
203a159c266SJung-uk Kim     /* Get the index and value */
204a159c266SJung-uk Kim 
205a159c266SJung-uk Kim     Index = ACPI_STRTOUL (IndexArg, NULL, 16);
206a159c266SJung-uk Kim 
207a159c266SJung-uk Kim     WalkState = AcpiDsGetCurrentWalkState (AcpiGbl_CurrentWalkList);
208a159c266SJung-uk Kim     if (!WalkState)
209a159c266SJung-uk Kim     {
210a159c266SJung-uk Kim         AcpiOsPrintf ("There is no method currently executing\n");
211a159c266SJung-uk Kim         return;
212a159c266SJung-uk Kim     }
213a159c266SJung-uk Kim 
214a159c266SJung-uk Kim     /* Create and initialize the new object */
215a159c266SJung-uk Kim 
216a159c266SJung-uk Kim     ObjDesc = AcpiUtCreateIntegerObject ((UINT64) Value);
217a159c266SJung-uk Kim     if (!ObjDesc)
218a159c266SJung-uk Kim     {
219a159c266SJung-uk Kim         AcpiOsPrintf ("Could not create an internal object\n");
220a159c266SJung-uk Kim         return;
221a159c266SJung-uk Kim     }
222a159c266SJung-uk Kim 
223a159c266SJung-uk Kim     /* Store the new object into the target */
224a159c266SJung-uk Kim 
225a159c266SJung-uk Kim     switch (Type)
226a159c266SJung-uk Kim     {
227a159c266SJung-uk Kim     case 'A':
228a159c266SJung-uk Kim 
229a159c266SJung-uk Kim         /* Set a method argument */
230a159c266SJung-uk Kim 
231a159c266SJung-uk Kim         if (Index > ACPI_METHOD_MAX_ARG)
232a159c266SJung-uk Kim         {
233a159c266SJung-uk Kim             AcpiOsPrintf ("Arg%u - Invalid argument name\n", Index);
234a159c266SJung-uk Kim             goto Cleanup;
235a159c266SJung-uk Kim         }
236a159c266SJung-uk Kim 
237a159c266SJung-uk Kim         Status = AcpiDsStoreObjectToLocal (ACPI_REFCLASS_ARG, Index, ObjDesc,
238a159c266SJung-uk Kim                     WalkState);
239a159c266SJung-uk Kim         if (ACPI_FAILURE (Status))
240a159c266SJung-uk Kim         {
241a159c266SJung-uk Kim             goto Cleanup;
242a159c266SJung-uk Kim         }
243a159c266SJung-uk Kim 
244a159c266SJung-uk Kim         ObjDesc = WalkState->Arguments[Index].Object;
245a159c266SJung-uk Kim 
246a159c266SJung-uk Kim         AcpiOsPrintf ("Arg%u: ", Index);
247a159c266SJung-uk Kim         AcpiDmDisplayInternalObject (ObjDesc, WalkState);
248a159c266SJung-uk Kim         break;
249a159c266SJung-uk Kim 
250a159c266SJung-uk Kim     case 'L':
251a159c266SJung-uk Kim 
252a159c266SJung-uk Kim         /* Set a method local */
253a159c266SJung-uk Kim 
254a159c266SJung-uk Kim         if (Index > ACPI_METHOD_MAX_LOCAL)
255a159c266SJung-uk Kim         {
256a159c266SJung-uk Kim             AcpiOsPrintf ("Local%u - Invalid local variable name\n", Index);
257a159c266SJung-uk Kim             goto Cleanup;
258a159c266SJung-uk Kim         }
259a159c266SJung-uk Kim 
260a159c266SJung-uk Kim         Status = AcpiDsStoreObjectToLocal (ACPI_REFCLASS_LOCAL, Index, ObjDesc,
261a159c266SJung-uk Kim                     WalkState);
262a159c266SJung-uk Kim         if (ACPI_FAILURE (Status))
263a159c266SJung-uk Kim         {
264a159c266SJung-uk Kim             goto Cleanup;
265a159c266SJung-uk Kim         }
266a159c266SJung-uk Kim 
267a159c266SJung-uk Kim         ObjDesc = WalkState->LocalVariables[Index].Object;
268a159c266SJung-uk Kim 
269a159c266SJung-uk Kim         AcpiOsPrintf ("Local%u: ", Index);
270a159c266SJung-uk Kim         AcpiDmDisplayInternalObject (ObjDesc, WalkState);
271a159c266SJung-uk Kim         break;
272a159c266SJung-uk Kim 
273a159c266SJung-uk Kim     default:
274*a9d8d09cSJung-uk Kim 
275a159c266SJung-uk Kim         break;
276a159c266SJung-uk Kim     }
277a159c266SJung-uk Kim 
278a159c266SJung-uk Kim Cleanup:
279a159c266SJung-uk Kim     AcpiUtRemoveReference (ObjDesc);
280a159c266SJung-uk Kim }
281a159c266SJung-uk Kim 
282a159c266SJung-uk Kim 
283a159c266SJung-uk Kim /*******************************************************************************
284a159c266SJung-uk Kim  *
285a159c266SJung-uk Kim  * FUNCTION:    AcpiDbDisassembleAml
286a159c266SJung-uk Kim  *
287a159c266SJung-uk Kim  * PARAMETERS:  Statements          - Number of statements to disassemble
288a159c266SJung-uk Kim  *              Op                  - Current Op (from parse walk)
289a159c266SJung-uk Kim  *
290a159c266SJung-uk Kim  * RETURN:      None
291a159c266SJung-uk Kim  *
292a159c266SJung-uk Kim  * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
293a159c266SJung-uk Kim  *              of statements specified.
294a159c266SJung-uk Kim  *
295a159c266SJung-uk Kim  ******************************************************************************/
296a159c266SJung-uk Kim 
297a159c266SJung-uk Kim void
298a159c266SJung-uk Kim AcpiDbDisassembleAml (
299a159c266SJung-uk Kim     char                    *Statements,
300a159c266SJung-uk Kim     ACPI_PARSE_OBJECT       *Op)
301a159c266SJung-uk Kim {
302a159c266SJung-uk Kim     UINT32                  NumStatements = 8;
303a159c266SJung-uk Kim 
304a159c266SJung-uk Kim 
305a159c266SJung-uk Kim     if (!Op)
306a159c266SJung-uk Kim     {
307a159c266SJung-uk Kim         AcpiOsPrintf ("There is no method currently executing\n");
308a159c266SJung-uk Kim         return;
309a159c266SJung-uk Kim     }
310a159c266SJung-uk Kim 
311a159c266SJung-uk Kim     if (Statements)
312a159c266SJung-uk Kim     {
313a159c266SJung-uk Kim         NumStatements = ACPI_STRTOUL (Statements, NULL, 0);
314a159c266SJung-uk Kim     }
315a159c266SJung-uk Kim 
316a159c266SJung-uk Kim #ifdef ACPI_DISASSEMBLER
317a159c266SJung-uk Kim     AcpiDmDisassemble (NULL, Op, NumStatements);
318a159c266SJung-uk Kim #endif
319a159c266SJung-uk Kim }
320a159c266SJung-uk Kim 
321a159c266SJung-uk Kim 
322a159c266SJung-uk Kim /*******************************************************************************
323a159c266SJung-uk Kim  *
324a159c266SJung-uk Kim  * FUNCTION:    AcpiDbDisassembleMethod
325a159c266SJung-uk Kim  *
326a159c266SJung-uk Kim  * PARAMETERS:  Name            - Name of control method
327a159c266SJung-uk Kim  *
328a159c266SJung-uk Kim  * RETURN:      None
329a159c266SJung-uk Kim  *
330a159c266SJung-uk Kim  * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
331a159c266SJung-uk Kim  *              of statements specified.
332a159c266SJung-uk Kim  *
333a159c266SJung-uk Kim  ******************************************************************************/
334a159c266SJung-uk Kim 
335a159c266SJung-uk Kim ACPI_STATUS
336a159c266SJung-uk Kim AcpiDbDisassembleMethod (
337a159c266SJung-uk Kim     char                    *Name)
338a159c266SJung-uk Kim {
339a159c266SJung-uk Kim     ACPI_STATUS             Status;
340a159c266SJung-uk Kim     ACPI_PARSE_OBJECT       *Op;
341a159c266SJung-uk Kim     ACPI_WALK_STATE         *WalkState;
342a159c266SJung-uk Kim     ACPI_OPERAND_OBJECT     *ObjDesc;
343a159c266SJung-uk Kim     ACPI_NAMESPACE_NODE     *Method;
344a159c266SJung-uk Kim 
345a159c266SJung-uk Kim 
346a159c266SJung-uk Kim     Method = AcpiDbConvertToNode (Name);
347a159c266SJung-uk Kim     if (!Method)
348a159c266SJung-uk Kim     {
349a159c266SJung-uk Kim         return (AE_BAD_PARAMETER);
350a159c266SJung-uk Kim     }
351a159c266SJung-uk Kim 
352ed17e06eSJung-uk Kim     if (Method->Type != ACPI_TYPE_METHOD)
353ed17e06eSJung-uk Kim     {
354ed17e06eSJung-uk Kim         ACPI_ERROR ((AE_INFO, "%s (%s): Object must be a control method",
355ed17e06eSJung-uk Kim             Name, AcpiUtGetTypeName (Method->Type)));
356ed17e06eSJung-uk Kim         return (AE_BAD_PARAMETER);
357ed17e06eSJung-uk Kim     }
358ed17e06eSJung-uk Kim 
359a159c266SJung-uk Kim     ObjDesc = Method->Object;
360a159c266SJung-uk Kim 
361a159c266SJung-uk Kim     Op = AcpiPsCreateScopeOp ();
362a159c266SJung-uk Kim     if (!Op)
363a159c266SJung-uk Kim     {
364a159c266SJung-uk Kim         return (AE_NO_MEMORY);
365a159c266SJung-uk Kim     }
366a159c266SJung-uk Kim 
367a159c266SJung-uk Kim     /* Create and initialize a new walk state */
368a159c266SJung-uk Kim 
369a159c266SJung-uk Kim     WalkState = AcpiDsCreateWalkState (0, Op, NULL, NULL);
370a159c266SJung-uk Kim     if (!WalkState)
371a159c266SJung-uk Kim     {
372a159c266SJung-uk Kim         return (AE_NO_MEMORY);
373a159c266SJung-uk Kim     }
374a159c266SJung-uk Kim 
375a159c266SJung-uk Kim     Status = AcpiDsInitAmlWalk (WalkState, Op, NULL,
376a159c266SJung-uk Kim         ObjDesc->Method.AmlStart,
377a159c266SJung-uk Kim         ObjDesc->Method.AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
378a159c266SJung-uk Kim     if (ACPI_FAILURE (Status))
379a159c266SJung-uk Kim     {
380a159c266SJung-uk Kim         return (Status);
381a159c266SJung-uk Kim     }
382a159c266SJung-uk Kim 
383ed17e06eSJung-uk Kim     Status = AcpiUtAllocateOwnerId (&ObjDesc->Method.OwnerId);
384ed17e06eSJung-uk Kim     WalkState->OwnerId = ObjDesc->Method.OwnerId;
385ed17e06eSJung-uk Kim 
386ed17e06eSJung-uk Kim     /* Push start scope on scope stack and make it current */
387ed17e06eSJung-uk Kim 
388ed17e06eSJung-uk Kim     Status = AcpiDsScopeStackPush (Method,
389ed17e06eSJung-uk Kim         Method->Type, WalkState);
390ed17e06eSJung-uk Kim     if (ACPI_FAILURE (Status))
391ed17e06eSJung-uk Kim     {
392ed17e06eSJung-uk Kim         return (Status);
393ed17e06eSJung-uk Kim     }
394ed17e06eSJung-uk Kim 
395ed17e06eSJung-uk Kim     /* Parse the entire method AML including deferred operators */
396a159c266SJung-uk Kim 
397a159c266SJung-uk Kim     WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
398a159c266SJung-uk Kim     WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
399a159c266SJung-uk Kim 
400ed17e06eSJung-uk Kim     Status = AcpiPsParseAml (WalkState);
401efcc2a30SJung-uk Kim     (void) AcpiDmParseDeferredOps (Op);
402ed17e06eSJung-uk Kim 
403ed17e06eSJung-uk Kim     /* Now we can disassemble the method */
404ed17e06eSJung-uk Kim 
405ed17e06eSJung-uk Kim     AcpiGbl_DbOpt_verbose = FALSE;
406a159c266SJung-uk Kim #ifdef ACPI_DISASSEMBLER
407a159c266SJung-uk Kim     AcpiDmDisassemble (NULL, Op, 0);
408a159c266SJung-uk Kim #endif
409ed17e06eSJung-uk Kim     AcpiGbl_DbOpt_verbose = TRUE;
410ed17e06eSJung-uk Kim 
411a159c266SJung-uk Kim     AcpiPsDeleteParseTree (Op);
412ed17e06eSJung-uk Kim 
413ed17e06eSJung-uk Kim     /* Method cleanup */
414ed17e06eSJung-uk Kim 
415ed17e06eSJung-uk Kim     AcpiNsDeleteNamespaceSubtree (Method);
416ed17e06eSJung-uk Kim     AcpiNsDeleteNamespaceByOwner (ObjDesc->Method.OwnerId);
417ed17e06eSJung-uk Kim     AcpiUtReleaseOwnerId (&ObjDesc->Method.OwnerId);
418a159c266SJung-uk Kim     return (AE_OK);
419a159c266SJung-uk Kim }
420a159c266SJung-uk Kim 
421a159c266SJung-uk Kim 
422a159c266SJung-uk Kim /*******************************************************************************
423a159c266SJung-uk Kim  *
424a159c266SJung-uk Kim  * FUNCTION:    AcpiDbWalkForExecute
425a159c266SJung-uk Kim  *
426a159c266SJung-uk Kim  * PARAMETERS:  Callback from WalkNamespace
427a159c266SJung-uk Kim  *
428a159c266SJung-uk Kim  * RETURN:      Status
429a159c266SJung-uk Kim  *
430a159c266SJung-uk Kim  * DESCRIPTION: Batch execution module. Currently only executes predefined
431a159c266SJung-uk Kim  *              ACPI names.
432a159c266SJung-uk Kim  *
433a159c266SJung-uk Kim  ******************************************************************************/
434a159c266SJung-uk Kim 
435a159c266SJung-uk Kim static ACPI_STATUS
436a159c266SJung-uk Kim AcpiDbWalkForExecute (
437a159c266SJung-uk Kim     ACPI_HANDLE             ObjHandle,
438a159c266SJung-uk Kim     UINT32                  NestingLevel,
439a159c266SJung-uk Kim     void                    *Context,
440a159c266SJung-uk Kim     void                    **ReturnValue)
441a159c266SJung-uk Kim {
442a159c266SJung-uk Kim     ACPI_NAMESPACE_NODE         *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
443042ff955SJung-uk Kim     ACPI_DB_EXECUTE_WALK        *Info = (ACPI_DB_EXECUTE_WALK *) Context;
444a159c266SJung-uk Kim     char                        *Pathname;
445895f26a9SJung-uk Kim     const ACPI_PREDEFINED_INFO  *Predefined;
446a159c266SJung-uk Kim     ACPI_DEVICE_INFO            *ObjInfo;
447a159c266SJung-uk Kim     ACPI_OBJECT_LIST            ParamObjects;
448a159c266SJung-uk Kim     ACPI_OBJECT                 Params[ACPI_METHOD_NUM_ARGS];
449895f26a9SJung-uk Kim     ACPI_OBJECT                 *ThisParam;
450895f26a9SJung-uk Kim     ACPI_BUFFER                 ReturnObj;
451895f26a9SJung-uk Kim     ACPI_STATUS                 Status;
452895f26a9SJung-uk Kim     UINT16                      ArgTypeList;
453895f26a9SJung-uk Kim     UINT8                       ArgCount;
454895f26a9SJung-uk Kim     UINT8                       ArgType;
455895f26a9SJung-uk Kim     UINT32                      i;
456a159c266SJung-uk Kim 
457a159c266SJung-uk Kim 
458895f26a9SJung-uk Kim     /* The name must be a predefined ACPI name */
459895f26a9SJung-uk Kim 
4609c7c683cSJung-uk Kim     Predefined = AcpiUtMatchPredefinedMethod (Node->Name.Ascii);
461a159c266SJung-uk Kim     if (!Predefined)
462a159c266SJung-uk Kim     {
463a159c266SJung-uk Kim         return (AE_OK);
464a159c266SJung-uk Kim     }
465a159c266SJung-uk Kim 
466a159c266SJung-uk Kim     if (Node->Type == ACPI_TYPE_LOCAL_SCOPE)
467a159c266SJung-uk Kim     {
468a159c266SJung-uk Kim         return (AE_OK);
469a159c266SJung-uk Kim     }
470a159c266SJung-uk Kim 
471a159c266SJung-uk Kim     Pathname = AcpiNsGetExternalPathname (Node);
472a159c266SJung-uk Kim     if (!Pathname)
473a159c266SJung-uk Kim     {
474a159c266SJung-uk Kim         return (AE_OK);
475a159c266SJung-uk Kim     }
476a159c266SJung-uk Kim 
477a159c266SJung-uk Kim     /* Get the object info for number of method parameters */
478a159c266SJung-uk Kim 
479a159c266SJung-uk Kim     Status = AcpiGetObjectInfo (ObjHandle, &ObjInfo);
480a159c266SJung-uk Kim     if (ACPI_FAILURE (Status))
481a159c266SJung-uk Kim     {
482a159c266SJung-uk Kim         return (Status);
483a159c266SJung-uk Kim     }
484a159c266SJung-uk Kim 
485a159c266SJung-uk Kim     ParamObjects.Count = 0;
486895f26a9SJung-uk Kim     ParamObjects.Pointer = NULL;
487a159c266SJung-uk Kim 
488a159c266SJung-uk Kim     if (ObjInfo->Type == ACPI_TYPE_METHOD)
489a159c266SJung-uk Kim     {
490895f26a9SJung-uk Kim         /* Setup default parameters (with proper types) */
491a159c266SJung-uk Kim 
492895f26a9SJung-uk Kim         ArgTypeList = Predefined->Info.ArgumentList;
493895f26a9SJung-uk Kim         ArgCount = METHOD_GET_ARG_COUNT (ArgTypeList);
494895f26a9SJung-uk Kim 
495895f26a9SJung-uk Kim         /*
496895f26a9SJung-uk Kim          * Setup the ACPI-required number of arguments, regardless of what
497895f26a9SJung-uk Kim          * the actual method defines. If there is a difference, then the
498895f26a9SJung-uk Kim          * method is wrong and a warning will be issued during execution.
499895f26a9SJung-uk Kim          */
500895f26a9SJung-uk Kim         ThisParam = Params;
501895f26a9SJung-uk Kim         for (i = 0; i < ArgCount; i++)
502a159c266SJung-uk Kim         {
503895f26a9SJung-uk Kim             ArgType = METHOD_GET_NEXT_TYPE (ArgTypeList);
504895f26a9SJung-uk Kim             ThisParam->Type = ArgType;
505895f26a9SJung-uk Kim 
506895f26a9SJung-uk Kim             switch (ArgType)
507895f26a9SJung-uk Kim             {
508895f26a9SJung-uk Kim             case ACPI_TYPE_INTEGER:
509*a9d8d09cSJung-uk Kim 
510895f26a9SJung-uk Kim                 ThisParam->Integer.Value = 1;
511895f26a9SJung-uk Kim                 break;
512895f26a9SJung-uk Kim 
513895f26a9SJung-uk Kim             case ACPI_TYPE_STRING:
514*a9d8d09cSJung-uk Kim 
515895f26a9SJung-uk Kim                 ThisParam->String.Pointer = "This is the default argument string";
516895f26a9SJung-uk Kim                 ThisParam->String.Length = ACPI_STRLEN (ThisParam->String.Pointer);
517895f26a9SJung-uk Kim                 break;
518895f26a9SJung-uk Kim 
519895f26a9SJung-uk Kim             case ACPI_TYPE_BUFFER:
520*a9d8d09cSJung-uk Kim 
521895f26a9SJung-uk Kim                 ThisParam->Buffer.Pointer = (UINT8 *) Params; /* just a garbage buffer */
522895f26a9SJung-uk Kim                 ThisParam->Buffer.Length = 48;
523895f26a9SJung-uk Kim                 break;
524895f26a9SJung-uk Kim 
525895f26a9SJung-uk Kim              case ACPI_TYPE_PACKAGE:
526*a9d8d09cSJung-uk Kim 
527895f26a9SJung-uk Kim                 ThisParam->Package.Elements = NULL;
528895f26a9SJung-uk Kim                 ThisParam->Package.Count = 0;
529895f26a9SJung-uk Kim                 break;
530895f26a9SJung-uk Kim 
531895f26a9SJung-uk Kim            default:
532*a9d8d09cSJung-uk Kim 
533895f26a9SJung-uk Kim                 AcpiOsPrintf ("%s: Unsupported argument type: %u\n",
534895f26a9SJung-uk Kim                     Pathname, ArgType);
535895f26a9SJung-uk Kim                 break;
536a159c266SJung-uk Kim             }
537a159c266SJung-uk Kim 
538895f26a9SJung-uk Kim             ThisParam++;
539895f26a9SJung-uk Kim         }
540895f26a9SJung-uk Kim 
541895f26a9SJung-uk Kim         ParamObjects.Count = ArgCount;
542a159c266SJung-uk Kim         ParamObjects.Pointer = Params;
543a159c266SJung-uk Kim     }
544a159c266SJung-uk Kim 
545a159c266SJung-uk Kim     ACPI_FREE (ObjInfo);
546a159c266SJung-uk Kim     ReturnObj.Pointer = NULL;
547a159c266SJung-uk Kim     ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
548a159c266SJung-uk Kim 
549a159c266SJung-uk Kim     /* Do the actual method execution */
550a159c266SJung-uk Kim 
551a159c266SJung-uk Kim     AcpiGbl_MethodExecuting = TRUE;
552a159c266SJung-uk Kim 
553a159c266SJung-uk Kim     Status = AcpiEvaluateObject (Node, NULL, &ParamObjects, &ReturnObj);
554a159c266SJung-uk Kim 
555a159c266SJung-uk Kim     AcpiOsPrintf ("%-32s returned %s\n", Pathname, AcpiFormatException (Status));
556a159c266SJung-uk Kim     AcpiGbl_MethodExecuting = FALSE;
557a159c266SJung-uk Kim     ACPI_FREE (Pathname);
558a159c266SJung-uk Kim 
559a159c266SJung-uk Kim     /* Ignore status from method execution */
560a159c266SJung-uk Kim 
561a159c266SJung-uk Kim     Status = AE_OK;
562a159c266SJung-uk Kim 
563a159c266SJung-uk Kim     /* Update count, check if we have executed enough methods */
564a159c266SJung-uk Kim 
565a159c266SJung-uk Kim     Info->Count++;
566a159c266SJung-uk Kim     if (Info->Count >= Info->MaxCount)
567a159c266SJung-uk Kim     {
568a159c266SJung-uk Kim         Status = AE_CTRL_TERMINATE;
569a159c266SJung-uk Kim     }
570a159c266SJung-uk Kim 
571a159c266SJung-uk Kim     return (Status);
572a159c266SJung-uk Kim }
573a159c266SJung-uk Kim 
574a159c266SJung-uk Kim 
575a159c266SJung-uk Kim /*******************************************************************************
576a159c266SJung-uk Kim  *
577a159c266SJung-uk Kim  * FUNCTION:    AcpiDbBatchExecute
578a159c266SJung-uk Kim  *
579a159c266SJung-uk Kim  * PARAMETERS:  CountArg            - Max number of methods to execute
580a159c266SJung-uk Kim  *
581a159c266SJung-uk Kim  * RETURN:      None
582a159c266SJung-uk Kim  *
583a159c266SJung-uk Kim  * DESCRIPTION: Namespace batch execution. Execute predefined names in the
584a159c266SJung-uk Kim  *              namespace, up to the max count, if specified.
585a159c266SJung-uk Kim  *
586a159c266SJung-uk Kim  ******************************************************************************/
587a159c266SJung-uk Kim 
588a159c266SJung-uk Kim void
589a159c266SJung-uk Kim AcpiDbBatchExecute (
590a159c266SJung-uk Kim     char                    *CountArg)
591a159c266SJung-uk Kim {
592042ff955SJung-uk Kim     ACPI_DB_EXECUTE_WALK    Info;
593a159c266SJung-uk Kim 
594a159c266SJung-uk Kim 
595a159c266SJung-uk Kim     Info.Count = 0;
596a159c266SJung-uk Kim     Info.MaxCount = ACPI_UINT32_MAX;
597a159c266SJung-uk Kim 
598a159c266SJung-uk Kim     if (CountArg)
599a159c266SJung-uk Kim     {
600a159c266SJung-uk Kim         Info.MaxCount = ACPI_STRTOUL (CountArg, NULL, 0);
601a159c266SJung-uk Kim     }
602a159c266SJung-uk Kim 
603a159c266SJung-uk Kim 
604a159c266SJung-uk Kim     /* Search all nodes in namespace */
605a159c266SJung-uk Kim 
606a159c266SJung-uk Kim     (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
607a159c266SJung-uk Kim                 AcpiDbWalkForExecute, NULL, (void *) &Info, NULL);
608a159c266SJung-uk Kim 
609042ff955SJung-uk Kim     AcpiOsPrintf ("Evaluated %u predefined names in the namespace\n", Info.Count);
610a159c266SJung-uk Kim }
611a159c266SJung-uk Kim 
612a159c266SJung-uk Kim #endif /* ACPI_DEBUGGER */
613