xref: /freebsd/sys/contrib/dev/acpica/components/debugger/dbmethod.c (revision 51f42bad71b9a5aaa55198cf4ce28093fa8ce7d7)
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 
70d84335fSJung-uk Kim /******************************************************************************
80d84335fSJung-uk Kim  *
90d84335fSJung-uk Kim  * 1. Copyright Notice
100d84335fSJung-uk Kim  *
1132ac4016SJung-uk Kim  * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
12a159c266SJung-uk Kim  * All rights reserved.
13a159c266SJung-uk Kim  *
140d84335fSJung-uk Kim  * 2. License
150d84335fSJung-uk Kim  *
160d84335fSJung-uk Kim  * 2.1. This is your license from Intel Corp. under its intellectual property
170d84335fSJung-uk Kim  * rights. You may have additional license terms from the party that provided
180d84335fSJung-uk Kim  * you this software, covering your right to use that party's intellectual
190d84335fSJung-uk Kim  * property rights.
200d84335fSJung-uk Kim  *
210d84335fSJung-uk Kim  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
220d84335fSJung-uk Kim  * copy of the source code appearing in this file ("Covered Code") an
230d84335fSJung-uk Kim  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
240d84335fSJung-uk Kim  * base code distributed originally by Intel ("Original Intel Code") to copy,
250d84335fSJung-uk Kim  * make derivatives, distribute, use and display any portion of the Covered
260d84335fSJung-uk Kim  * Code in any form, with the right to sublicense such rights; and
270d84335fSJung-uk Kim  *
280d84335fSJung-uk Kim  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
290d84335fSJung-uk Kim  * license (with the right to sublicense), under only those claims of Intel
300d84335fSJung-uk Kim  * patents that are infringed by the Original Intel Code, to make, use, sell,
310d84335fSJung-uk Kim  * offer to sell, and import the Covered Code and derivative works thereof
320d84335fSJung-uk Kim  * solely to the minimum extent necessary to exercise the above copyright
330d84335fSJung-uk Kim  * license, and in no event shall the patent license extend to any additions
340d84335fSJung-uk Kim  * to or modifications of the Original Intel Code. No other license or right
350d84335fSJung-uk Kim  * is granted directly or by implication, estoppel or otherwise;
360d84335fSJung-uk Kim  *
370d84335fSJung-uk Kim  * The above copyright and patent license is granted only if the following
380d84335fSJung-uk Kim  * conditions are met:
390d84335fSJung-uk Kim  *
400d84335fSJung-uk Kim  * 3. Conditions
410d84335fSJung-uk Kim  *
420d84335fSJung-uk Kim  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
430d84335fSJung-uk Kim  * Redistribution of source code of any substantial portion of the Covered
440d84335fSJung-uk Kim  * Code or modification with rights to further distribute source must include
450d84335fSJung-uk Kim  * the above Copyright Notice, the above License, this list of Conditions,
460d84335fSJung-uk Kim  * and the following Disclaimer and Export Compliance provision. In addition,
470d84335fSJung-uk Kim  * Licensee must cause all Covered Code to which Licensee contributes to
480d84335fSJung-uk Kim  * contain a file documenting the changes Licensee made to create that Covered
490d84335fSJung-uk Kim  * Code and the date of any change. Licensee must include in that file the
500d84335fSJung-uk Kim  * documentation of any changes made by any predecessor Licensee. Licensee
510d84335fSJung-uk Kim  * must include a prominent statement that the modification is derived,
520d84335fSJung-uk Kim  * directly or indirectly, from Original Intel Code.
530d84335fSJung-uk Kim  *
540d84335fSJung-uk Kim  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
550d84335fSJung-uk Kim  * Redistribution of source code of any substantial portion of the Covered
560d84335fSJung-uk Kim  * Code or modification without rights to further distribute source must
570d84335fSJung-uk Kim  * include the following Disclaimer and Export Compliance provision in the
580d84335fSJung-uk Kim  * documentation and/or other materials provided with distribution. In
590d84335fSJung-uk Kim  * addition, Licensee may not authorize further sublicense of source of any
600d84335fSJung-uk Kim  * portion of the Covered Code, and must include terms to the effect that the
610d84335fSJung-uk Kim  * license from Licensee to its licensee is limited to the intellectual
620d84335fSJung-uk Kim  * property embodied in the software Licensee provides to its licensee, and
630d84335fSJung-uk Kim  * not to intellectual property embodied in modifications its licensee may
640d84335fSJung-uk Kim  * make.
650d84335fSJung-uk Kim  *
660d84335fSJung-uk Kim  * 3.3. Redistribution of Executable. Redistribution in executable form of any
670d84335fSJung-uk Kim  * substantial portion of the Covered Code or modification must reproduce the
680d84335fSJung-uk Kim  * above Copyright Notice, and the following Disclaimer and Export Compliance
690d84335fSJung-uk Kim  * provision in the documentation and/or other materials provided with the
700d84335fSJung-uk Kim  * distribution.
710d84335fSJung-uk Kim  *
720d84335fSJung-uk Kim  * 3.4. Intel retains all right, title, and interest in and to the Original
730d84335fSJung-uk Kim  * Intel Code.
740d84335fSJung-uk Kim  *
750d84335fSJung-uk Kim  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
760d84335fSJung-uk Kim  * Intel shall be used in advertising or otherwise to promote the sale, use or
770d84335fSJung-uk Kim  * other dealings in products derived from or relating to the Covered Code
780d84335fSJung-uk Kim  * without prior written authorization from Intel.
790d84335fSJung-uk Kim  *
800d84335fSJung-uk Kim  * 4. Disclaimer and Export Compliance
810d84335fSJung-uk Kim  *
820d84335fSJung-uk Kim  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
830d84335fSJung-uk Kim  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
840d84335fSJung-uk Kim  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
850d84335fSJung-uk Kim  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
860d84335fSJung-uk Kim  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
870d84335fSJung-uk Kim  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
880d84335fSJung-uk Kim  * PARTICULAR PURPOSE.
890d84335fSJung-uk Kim  *
900d84335fSJung-uk Kim  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
910d84335fSJung-uk Kim  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
920d84335fSJung-uk Kim  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
930d84335fSJung-uk Kim  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
940d84335fSJung-uk Kim  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
950d84335fSJung-uk Kim  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
960d84335fSJung-uk Kim  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
970d84335fSJung-uk Kim  * LIMITED REMEDY.
980d84335fSJung-uk Kim  *
990d84335fSJung-uk Kim  * 4.3. Licensee shall not export, either directly or indirectly, any of this
1000d84335fSJung-uk Kim  * software or system incorporating such software without first obtaining any
1010d84335fSJung-uk Kim  * required license or other approval from the U. S. Department of Commerce or
1020d84335fSJung-uk Kim  * any other agency or department of the United States Government. In the
1030d84335fSJung-uk Kim  * event Licensee exports any such software from the United States or
1040d84335fSJung-uk Kim  * re-exports any such software from a foreign destination, Licensee shall
1050d84335fSJung-uk Kim  * ensure that the distribution and export/re-export of the software is in
1060d84335fSJung-uk Kim  * compliance with all laws, regulations, orders, or other restrictions of the
1070d84335fSJung-uk Kim  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1080d84335fSJung-uk Kim  * any of its subsidiaries will export/re-export any technical data, process,
1090d84335fSJung-uk Kim  * software, or service, directly or indirectly, to any country for which the
1100d84335fSJung-uk Kim  * United States government or any agency thereof requires an export license,
1110d84335fSJung-uk Kim  * other governmental approval, or letter of assurance, without first obtaining
1120d84335fSJung-uk Kim  * such license, approval or letter.
1130d84335fSJung-uk Kim  *
1140d84335fSJung-uk Kim  *****************************************************************************
1150d84335fSJung-uk Kim  *
1160d84335fSJung-uk Kim  * Alternatively, you may choose to be licensed under the terms of the
1170d84335fSJung-uk Kim  * following license:
1180d84335fSJung-uk Kim  *
119a159c266SJung-uk Kim  * Redistribution and use in source and binary forms, with or without
120a159c266SJung-uk Kim  * modification, are permitted provided that the following conditions
121a159c266SJung-uk Kim  * are met:
122a159c266SJung-uk Kim  * 1. Redistributions of source code must retain the above copyright
123a159c266SJung-uk Kim  *    notice, this list of conditions, and the following disclaimer,
124a159c266SJung-uk Kim  *    without modification.
125a159c266SJung-uk Kim  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126a159c266SJung-uk Kim  *    substantially similar to the "NO WARRANTY" disclaimer below
127a159c266SJung-uk Kim  *    ("Disclaimer") and any redistribution must be conditioned upon
128a159c266SJung-uk Kim  *    including a substantially similar Disclaimer requirement for further
129a159c266SJung-uk Kim  *    binary redistribution.
130a159c266SJung-uk Kim  * 3. Neither the names of the above-listed copyright holders nor the names
131a159c266SJung-uk Kim  *    of any contributors may be used to endorse or promote products derived
132a159c266SJung-uk Kim  *    from this software without specific prior written permission.
133a159c266SJung-uk Kim  *
1340d84335fSJung-uk Kim  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1350d84335fSJung-uk Kim  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1360d84335fSJung-uk Kim  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1370d84335fSJung-uk Kim  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1380d84335fSJung-uk Kim  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1390d84335fSJung-uk Kim  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1400d84335fSJung-uk Kim  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1410d84335fSJung-uk Kim  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1420d84335fSJung-uk Kim  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1430d84335fSJung-uk Kim  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1440d84335fSJung-uk Kim  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1450d84335fSJung-uk Kim  *
1460d84335fSJung-uk Kim  * Alternatively, you may choose to be licensed under the terms of the
147a159c266SJung-uk Kim  * GNU General Public License ("GPL") version 2 as published by the Free
148a159c266SJung-uk Kim  * Software Foundation.
149a159c266SJung-uk Kim  *
1500d84335fSJung-uk Kim  *****************************************************************************/
151a159c266SJung-uk Kim 
152a159c266SJung-uk Kim #include <contrib/dev/acpica/include/acpi.h>
153a159c266SJung-uk Kim #include <contrib/dev/acpica/include/accommon.h>
154a159c266SJung-uk Kim #include <contrib/dev/acpica/include/acdispat.h>
155a159c266SJung-uk Kim #include <contrib/dev/acpica/include/acnamesp.h>
156a159c266SJung-uk Kim #include <contrib/dev/acpica/include/acdebug.h>
157a159c266SJung-uk Kim #include <contrib/dev/acpica/include/acparser.h>
158895f26a9SJung-uk Kim #include <contrib/dev/acpica/include/acpredef.h>
159a159c266SJung-uk Kim 
160a159c266SJung-uk Kim 
161a159c266SJung-uk Kim #define _COMPONENT          ACPI_CA_DEBUGGER
162a159c266SJung-uk Kim         ACPI_MODULE_NAME    ("dbmethod")
163a159c266SJung-uk Kim 
164493deb39SJung-uk Kim /* Local prototypes */
165493deb39SJung-uk Kim 
166493deb39SJung-uk Kim static ACPI_STATUS
167493deb39SJung-uk Kim AcpiDbWalkForExecute (
168493deb39SJung-uk Kim     ACPI_HANDLE             ObjHandle,
169493deb39SJung-uk Kim     UINT32                  NestingLevel,
170493deb39SJung-uk Kim     void                    *Context,
171493deb39SJung-uk Kim     void                    **ReturnValue);
172493deb39SJung-uk Kim 
173a159c266SJung-uk Kim 
174a159c266SJung-uk Kim /*******************************************************************************
175a159c266SJung-uk Kim  *
176a159c266SJung-uk Kim  * FUNCTION:    AcpiDbSetMethodBreakpoint
177a159c266SJung-uk Kim  *
178a159c266SJung-uk Kim  * PARAMETERS:  Location            - AML offset of breakpoint
179a159c266SJung-uk Kim  *              WalkState           - Current walk info
180a159c266SJung-uk Kim  *              Op                  - Current Op (from parse walk)
181a159c266SJung-uk Kim  *
182a159c266SJung-uk Kim  * RETURN:      None
183a159c266SJung-uk Kim  *
184a159c266SJung-uk Kim  * DESCRIPTION: Set a breakpoint in a control method at the specified
185a159c266SJung-uk Kim  *              AML offset
186a159c266SJung-uk Kim  *
187a159c266SJung-uk Kim  ******************************************************************************/
188a159c266SJung-uk Kim 
189a159c266SJung-uk Kim void
190a159c266SJung-uk Kim AcpiDbSetMethodBreakpoint (
191a159c266SJung-uk Kim     char                    *Location,
192a159c266SJung-uk Kim     ACPI_WALK_STATE         *WalkState,
193a159c266SJung-uk Kim     ACPI_PARSE_OBJECT       *Op)
194a159c266SJung-uk Kim {
195a159c266SJung-uk Kim     UINT32                  Address;
196fe0f0bbbSJung-uk Kim     UINT32                  AmlOffset;
197a159c266SJung-uk Kim 
198a159c266SJung-uk Kim 
199a159c266SJung-uk Kim     if (!Op)
200a159c266SJung-uk Kim     {
201a159c266SJung-uk Kim         AcpiOsPrintf ("There is no method currently executing\n");
202a159c266SJung-uk Kim         return;
203a159c266SJung-uk Kim     }
204a159c266SJung-uk Kim 
205a159c266SJung-uk Kim     /* Get and verify the breakpoint address */
206a159c266SJung-uk Kim 
2075ef50723SJung-uk Kim     Address = strtoul (Location, NULL, 16);
208fe0f0bbbSJung-uk Kim     AmlOffset = (UINT32) ACPI_PTR_DIFF (Op->Common.Aml,
209fe0f0bbbSJung-uk Kim         WalkState->ParserState.AmlStart);
210fe0f0bbbSJung-uk Kim     if (Address <= AmlOffset)
211a159c266SJung-uk Kim     {
212a159c266SJung-uk Kim         AcpiOsPrintf ("Breakpoint %X is beyond current address %X\n",
213fe0f0bbbSJung-uk Kim             Address, AmlOffset);
214a159c266SJung-uk Kim     }
215a159c266SJung-uk Kim 
216a159c266SJung-uk Kim     /* Save breakpoint in current walk */
217a159c266SJung-uk Kim 
218a159c266SJung-uk Kim     WalkState->UserBreakpoint = Address;
219a159c266SJung-uk Kim     AcpiOsPrintf ("Breakpoint set at AML offset %X\n", Address);
220a159c266SJung-uk Kim }
221a159c266SJung-uk Kim 
222a159c266SJung-uk Kim 
223a159c266SJung-uk Kim /*******************************************************************************
224a159c266SJung-uk Kim  *
225a159c266SJung-uk Kim  * FUNCTION:    AcpiDbSetMethodCallBreakpoint
226a159c266SJung-uk Kim  *
227a159c266SJung-uk Kim  * PARAMETERS:  Op                  - Current Op (from parse walk)
228a159c266SJung-uk Kim  *
229a159c266SJung-uk Kim  * RETURN:      None
230a159c266SJung-uk Kim  *
231a159c266SJung-uk Kim  * DESCRIPTION: Set a breakpoint in a control method at the specified
232a159c266SJung-uk Kim  *              AML offset
233a159c266SJung-uk Kim  *
234a159c266SJung-uk Kim  ******************************************************************************/
235a159c266SJung-uk Kim 
236a159c266SJung-uk Kim void
237a159c266SJung-uk Kim AcpiDbSetMethodCallBreakpoint (
238a159c266SJung-uk Kim     ACPI_PARSE_OBJECT       *Op)
239a159c266SJung-uk Kim {
240a159c266SJung-uk Kim 
241a159c266SJung-uk Kim 
242a159c266SJung-uk Kim     if (!Op)
243a159c266SJung-uk Kim     {
244a159c266SJung-uk Kim         AcpiOsPrintf ("There is no method currently executing\n");
245a159c266SJung-uk Kim         return;
246a159c266SJung-uk Kim     }
247a159c266SJung-uk Kim 
248a159c266SJung-uk Kim     AcpiGbl_StepToNextCall = TRUE;
249a159c266SJung-uk Kim }
250a159c266SJung-uk Kim 
251a159c266SJung-uk Kim 
252a159c266SJung-uk Kim /*******************************************************************************
253a159c266SJung-uk Kim  *
254a159c266SJung-uk Kim  * FUNCTION:    AcpiDbSetMethodData
255a159c266SJung-uk Kim  *
256a159c266SJung-uk Kim  * PARAMETERS:  TypeArg         - L for local, A for argument
257a159c266SJung-uk Kim  *              IndexArg        - which one
258a159c266SJung-uk Kim  *              ValueArg        - Value to set.
259a159c266SJung-uk Kim  *
260a159c266SJung-uk Kim  * RETURN:      None
261a159c266SJung-uk Kim  *
262a159c266SJung-uk Kim  * DESCRIPTION: Set a local or argument for the running control method.
263a159c266SJung-uk Kim  *              NOTE: only object supported is Number.
264a159c266SJung-uk Kim  *
265a159c266SJung-uk Kim  ******************************************************************************/
266a159c266SJung-uk Kim 
267a159c266SJung-uk Kim void
268a159c266SJung-uk Kim AcpiDbSetMethodData (
269a159c266SJung-uk Kim     char                    *TypeArg,
270a159c266SJung-uk Kim     char                    *IndexArg,
271a159c266SJung-uk Kim     char                    *ValueArg)
272a159c266SJung-uk Kim {
273a159c266SJung-uk Kim     char                    Type;
274a159c266SJung-uk Kim     UINT32                  Index;
275a159c266SJung-uk Kim     UINT32                  Value;
276a159c266SJung-uk Kim     ACPI_WALK_STATE         *WalkState;
277a159c266SJung-uk Kim     ACPI_OPERAND_OBJECT     *ObjDesc;
278a159c266SJung-uk Kim     ACPI_STATUS             Status;
279a159c266SJung-uk Kim     ACPI_NAMESPACE_NODE     *Node;
280a159c266SJung-uk Kim 
281a159c266SJung-uk Kim 
282a159c266SJung-uk Kim     /* Validate TypeArg */
283a159c266SJung-uk Kim 
284a159c266SJung-uk Kim     AcpiUtStrupr (TypeArg);
285a159c266SJung-uk Kim     Type = TypeArg[0];
286a159c266SJung-uk Kim     if ((Type != 'L') &&
287a159c266SJung-uk Kim         (Type != 'A') &&
288a159c266SJung-uk Kim         (Type != 'N'))
289a159c266SJung-uk Kim     {
290a159c266SJung-uk Kim         AcpiOsPrintf ("Invalid SET operand: %s\n", TypeArg);
291a159c266SJung-uk Kim         return;
292a159c266SJung-uk Kim     }
293a159c266SJung-uk Kim 
2945ef50723SJung-uk Kim     Value = strtoul (ValueArg, NULL, 16);
295a159c266SJung-uk Kim 
296a159c266SJung-uk Kim     if (Type == 'N')
297a159c266SJung-uk Kim     {
298a159c266SJung-uk Kim         Node = AcpiDbConvertToNode (IndexArg);
299313a0c13SJung-uk Kim         if (!Node)
300313a0c13SJung-uk Kim         {
301313a0c13SJung-uk Kim             return;
302313a0c13SJung-uk Kim         }
303313a0c13SJung-uk Kim 
304a159c266SJung-uk Kim         if (Node->Type != ACPI_TYPE_INTEGER)
305a159c266SJung-uk Kim         {
306a159c266SJung-uk Kim             AcpiOsPrintf ("Can only set Integer nodes\n");
307a159c266SJung-uk Kim             return;
308a159c266SJung-uk Kim         }
309a159c266SJung-uk Kim         ObjDesc = Node->Object;
310a159c266SJung-uk Kim         ObjDesc->Integer.Value = Value;
311a159c266SJung-uk Kim         return;
312a159c266SJung-uk Kim     }
313a159c266SJung-uk Kim 
314a159c266SJung-uk Kim     /* Get the index and value */
315a159c266SJung-uk Kim 
3165ef50723SJung-uk Kim     Index = strtoul (IndexArg, NULL, 16);
317a159c266SJung-uk Kim 
318a159c266SJung-uk Kim     WalkState = AcpiDsGetCurrentWalkState (AcpiGbl_CurrentWalkList);
319a159c266SJung-uk Kim     if (!WalkState)
320a159c266SJung-uk Kim     {
321a159c266SJung-uk Kim         AcpiOsPrintf ("There is no method currently executing\n");
322a159c266SJung-uk Kim         return;
323a159c266SJung-uk Kim     }
324a159c266SJung-uk Kim 
325a159c266SJung-uk Kim     /* Create and initialize the new object */
326a159c266SJung-uk Kim 
327a159c266SJung-uk Kim     ObjDesc = AcpiUtCreateIntegerObject ((UINT64) Value);
328a159c266SJung-uk Kim     if (!ObjDesc)
329a159c266SJung-uk Kim     {
330a159c266SJung-uk Kim         AcpiOsPrintf ("Could not create an internal object\n");
331a159c266SJung-uk Kim         return;
332a159c266SJung-uk Kim     }
333a159c266SJung-uk Kim 
334a159c266SJung-uk Kim     /* Store the new object into the target */
335a159c266SJung-uk Kim 
336a159c266SJung-uk Kim     switch (Type)
337a159c266SJung-uk Kim     {
338a159c266SJung-uk Kim     case 'A':
339a159c266SJung-uk Kim 
340a159c266SJung-uk Kim         /* Set a method argument */
341a159c266SJung-uk Kim 
342a159c266SJung-uk Kim         if (Index > ACPI_METHOD_MAX_ARG)
343a159c266SJung-uk Kim         {
34470e6ab8fSJung-uk Kim             AcpiOsPrintf ("Arg%u - Invalid argument name\n",
34570e6ab8fSJung-uk Kim                 Index);
346a159c266SJung-uk Kim             goto Cleanup;
347a159c266SJung-uk Kim         }
348a159c266SJung-uk Kim 
34970e6ab8fSJung-uk Kim         Status = AcpiDsStoreObjectToLocal (ACPI_REFCLASS_ARG,
35070e6ab8fSJung-uk Kim             Index, ObjDesc, WalkState);
351a159c266SJung-uk Kim         if (ACPI_FAILURE (Status))
352a159c266SJung-uk Kim         {
353a159c266SJung-uk Kim             goto Cleanup;
354a159c266SJung-uk Kim         }
355a159c266SJung-uk Kim 
356a159c266SJung-uk Kim         ObjDesc = WalkState->Arguments[Index].Object;
357a159c266SJung-uk Kim 
358a159c266SJung-uk Kim         AcpiOsPrintf ("Arg%u: ", Index);
359fe0f0bbbSJung-uk Kim         AcpiDbDisplayInternalObject (ObjDesc, WalkState);
360a159c266SJung-uk Kim         break;
361a159c266SJung-uk Kim 
362a159c266SJung-uk Kim     case 'L':
363a159c266SJung-uk Kim 
364a159c266SJung-uk Kim         /* Set a method local */
365a159c266SJung-uk Kim 
366a159c266SJung-uk Kim         if (Index > ACPI_METHOD_MAX_LOCAL)
367a159c266SJung-uk Kim         {
36870e6ab8fSJung-uk Kim             AcpiOsPrintf ("Local%u - Invalid local variable name\n",
36970e6ab8fSJung-uk Kim                 Index);
370a159c266SJung-uk Kim             goto Cleanup;
371a159c266SJung-uk Kim         }
372a159c266SJung-uk Kim 
37370e6ab8fSJung-uk Kim         Status = AcpiDsStoreObjectToLocal (ACPI_REFCLASS_LOCAL,
37470e6ab8fSJung-uk Kim             Index, ObjDesc, WalkState);
375a159c266SJung-uk Kim         if (ACPI_FAILURE (Status))
376a159c266SJung-uk Kim         {
377a159c266SJung-uk Kim             goto Cleanup;
378a159c266SJung-uk Kim         }
379a159c266SJung-uk Kim 
380a159c266SJung-uk Kim         ObjDesc = WalkState->LocalVariables[Index].Object;
381a159c266SJung-uk Kim 
382a159c266SJung-uk Kim         AcpiOsPrintf ("Local%u: ", Index);
383fe0f0bbbSJung-uk Kim         AcpiDbDisplayInternalObject (ObjDesc, WalkState);
384a159c266SJung-uk Kim         break;
385a159c266SJung-uk Kim 
386a159c266SJung-uk Kim     default:
387a9d8d09cSJung-uk Kim 
388a159c266SJung-uk Kim         break;
389a159c266SJung-uk Kim     }
390a159c266SJung-uk Kim 
391a159c266SJung-uk Kim Cleanup:
392a159c266SJung-uk Kim     AcpiUtRemoveReference (ObjDesc);
393a159c266SJung-uk Kim }
394a159c266SJung-uk Kim 
395a159c266SJung-uk Kim 
396*51f42badSJung-uk Kim #ifdef ACPI_DISASSEMBLER
397a159c266SJung-uk Kim /*******************************************************************************
398a159c266SJung-uk Kim  *
399a159c266SJung-uk Kim  * FUNCTION:    AcpiDbDisassembleAml
400a159c266SJung-uk Kim  *
401a159c266SJung-uk Kim  * PARAMETERS:  Statements          - Number of statements to disassemble
402a159c266SJung-uk Kim  *              Op                  - Current Op (from parse walk)
403a159c266SJung-uk Kim  *
404a159c266SJung-uk Kim  * RETURN:      None
405a159c266SJung-uk Kim  *
406a159c266SJung-uk Kim  * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
407a159c266SJung-uk Kim  *              of statements specified.
408a159c266SJung-uk Kim  *
409a159c266SJung-uk Kim  ******************************************************************************/
410a159c266SJung-uk Kim 
411a159c266SJung-uk Kim void
412a159c266SJung-uk Kim AcpiDbDisassembleAml (
413a159c266SJung-uk Kim     char                    *Statements,
414a159c266SJung-uk Kim     ACPI_PARSE_OBJECT       *Op)
415a159c266SJung-uk Kim {
416a159c266SJung-uk Kim     UINT32                  NumStatements = 8;
417a159c266SJung-uk Kim 
418a159c266SJung-uk Kim 
419a159c266SJung-uk Kim     if (!Op)
420a159c266SJung-uk Kim     {
421a159c266SJung-uk Kim         AcpiOsPrintf ("There is no method currently executing\n");
422a159c266SJung-uk Kim         return;
423a159c266SJung-uk Kim     }
424a159c266SJung-uk Kim 
425a159c266SJung-uk Kim     if (Statements)
426a159c266SJung-uk Kim     {
4275ef50723SJung-uk Kim         NumStatements = strtoul (Statements, NULL, 0);
428a159c266SJung-uk Kim     }
429a159c266SJung-uk Kim 
430a159c266SJung-uk Kim     AcpiDmDisassemble (NULL, Op, NumStatements);
431a159c266SJung-uk Kim }
432a159c266SJung-uk Kim 
433a159c266SJung-uk Kim 
434a159c266SJung-uk Kim /*******************************************************************************
435a159c266SJung-uk Kim  *
436a159c266SJung-uk Kim  * FUNCTION:    AcpiDbDisassembleMethod
437a159c266SJung-uk Kim  *
438a159c266SJung-uk Kim  * PARAMETERS:  Name            - Name of control method
439a159c266SJung-uk Kim  *
440a159c266SJung-uk Kim  * RETURN:      None
441a159c266SJung-uk Kim  *
442a159c266SJung-uk Kim  * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
443a159c266SJung-uk Kim  *              of statements specified.
444a159c266SJung-uk Kim  *
445a159c266SJung-uk Kim  ******************************************************************************/
446a159c266SJung-uk Kim 
447a159c266SJung-uk Kim ACPI_STATUS
448a159c266SJung-uk Kim AcpiDbDisassembleMethod (
449a159c266SJung-uk Kim     char                    *Name)
450a159c266SJung-uk Kim {
451a159c266SJung-uk Kim     ACPI_STATUS             Status;
452a159c266SJung-uk Kim     ACPI_PARSE_OBJECT       *Op;
453a159c266SJung-uk Kim     ACPI_WALK_STATE         *WalkState;
454a159c266SJung-uk Kim     ACPI_OPERAND_OBJECT     *ObjDesc;
455a159c266SJung-uk Kim     ACPI_NAMESPACE_NODE     *Method;
456a159c266SJung-uk Kim 
457a159c266SJung-uk Kim 
458a159c266SJung-uk Kim     Method = AcpiDbConvertToNode (Name);
459a159c266SJung-uk Kim     if (!Method)
460a159c266SJung-uk Kim     {
461a159c266SJung-uk Kim         return (AE_BAD_PARAMETER);
462a159c266SJung-uk Kim     }
463a159c266SJung-uk Kim 
464ed17e06eSJung-uk Kim     if (Method->Type != ACPI_TYPE_METHOD)
465ed17e06eSJung-uk Kim     {
466ed17e06eSJung-uk Kim         ACPI_ERROR ((AE_INFO, "%s (%s): Object must be a control method",
467ed17e06eSJung-uk Kim             Name, AcpiUtGetTypeName (Method->Type)));
468ed17e06eSJung-uk Kim         return (AE_BAD_PARAMETER);
469ed17e06eSJung-uk Kim     }
470ed17e06eSJung-uk Kim 
471a159c266SJung-uk Kim     ObjDesc = Method->Object;
472a159c266SJung-uk Kim 
473fe0f0bbbSJung-uk Kim     Op = AcpiPsCreateScopeOp (ObjDesc->Method.AmlStart);
474a159c266SJung-uk Kim     if (!Op)
475a159c266SJung-uk Kim     {
476a159c266SJung-uk Kim         return (AE_NO_MEMORY);
477a159c266SJung-uk Kim     }
478a159c266SJung-uk Kim 
479a159c266SJung-uk Kim     /* Create and initialize a new walk state */
480a159c266SJung-uk Kim 
481a159c266SJung-uk Kim     WalkState = AcpiDsCreateWalkState (0, Op, NULL, NULL);
482a159c266SJung-uk Kim     if (!WalkState)
483a159c266SJung-uk Kim     {
484a159c266SJung-uk Kim         return (AE_NO_MEMORY);
485a159c266SJung-uk Kim     }
486a159c266SJung-uk Kim 
487a159c266SJung-uk Kim     Status = AcpiDsInitAmlWalk (WalkState, Op, NULL,
488a159c266SJung-uk Kim         ObjDesc->Method.AmlStart,
489a159c266SJung-uk Kim         ObjDesc->Method.AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
490a159c266SJung-uk Kim     if (ACPI_FAILURE (Status))
491a159c266SJung-uk Kim     {
492a159c266SJung-uk Kim         return (Status);
493a159c266SJung-uk Kim     }
494a159c266SJung-uk Kim 
495ed17e06eSJung-uk Kim     Status = AcpiUtAllocateOwnerId (&ObjDesc->Method.OwnerId);
496ed17e06eSJung-uk Kim     WalkState->OwnerId = ObjDesc->Method.OwnerId;
497ed17e06eSJung-uk Kim 
498ed17e06eSJung-uk Kim     /* Push start scope on scope stack and make it current */
499ed17e06eSJung-uk Kim 
500ed17e06eSJung-uk Kim     Status = AcpiDsScopeStackPush (Method,
501ed17e06eSJung-uk Kim         Method->Type, WalkState);
502ed17e06eSJung-uk Kim     if (ACPI_FAILURE (Status))
503ed17e06eSJung-uk Kim     {
504ed17e06eSJung-uk Kim         return (Status);
505ed17e06eSJung-uk Kim     }
506ed17e06eSJung-uk Kim 
507ed17e06eSJung-uk Kim     /* Parse the entire method AML including deferred operators */
508a159c266SJung-uk Kim 
509a159c266SJung-uk Kim     WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
510a159c266SJung-uk Kim     WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
511a159c266SJung-uk Kim 
512ed17e06eSJung-uk Kim     Status = AcpiPsParseAml (WalkState);
513efcc2a30SJung-uk Kim     (void) AcpiDmParseDeferredOps (Op);
514ed17e06eSJung-uk Kim 
515ed17e06eSJung-uk Kim     /* Now we can disassemble the method */
516ed17e06eSJung-uk Kim 
51770e6ab8fSJung-uk Kim     AcpiGbl_DmOpt_Verbose = FALSE;
518a159c266SJung-uk Kim     AcpiDmDisassemble (NULL, Op, 0);
51970e6ab8fSJung-uk Kim     AcpiGbl_DmOpt_Verbose = TRUE;
520ed17e06eSJung-uk Kim 
521a159c266SJung-uk Kim     AcpiPsDeleteParseTree (Op);
522ed17e06eSJung-uk Kim 
523ed17e06eSJung-uk Kim     /* Method cleanup */
524ed17e06eSJung-uk Kim 
525ed17e06eSJung-uk Kim     AcpiNsDeleteNamespaceSubtree (Method);
526ed17e06eSJung-uk Kim     AcpiNsDeleteNamespaceByOwner (ObjDesc->Method.OwnerId);
527ed17e06eSJung-uk Kim     AcpiUtReleaseOwnerId (&ObjDesc->Method.OwnerId);
528a159c266SJung-uk Kim     return (AE_OK);
529a159c266SJung-uk Kim }
530*51f42badSJung-uk Kim #endif
531493deb39SJung-uk Kim 
532493deb39SJung-uk Kim 
533493deb39SJung-uk Kim /*******************************************************************************
534493deb39SJung-uk Kim  *
535493deb39SJung-uk Kim  * FUNCTION:    AcpiDbWalkForExecute
536493deb39SJung-uk Kim  *
537493deb39SJung-uk Kim  * PARAMETERS:  Callback from WalkNamespace
538493deb39SJung-uk Kim  *
539493deb39SJung-uk Kim  * RETURN:      Status
540493deb39SJung-uk Kim  *
541493deb39SJung-uk Kim  * DESCRIPTION: Batch execution module. Currently only executes predefined
542493deb39SJung-uk Kim  *              ACPI names.
543493deb39SJung-uk Kim  *
544493deb39SJung-uk Kim  ******************************************************************************/
545493deb39SJung-uk Kim 
546493deb39SJung-uk Kim static ACPI_STATUS
547493deb39SJung-uk Kim AcpiDbWalkForExecute (
548493deb39SJung-uk Kim     ACPI_HANDLE             ObjHandle,
549493deb39SJung-uk Kim     UINT32                  NestingLevel,
550493deb39SJung-uk Kim     void                    *Context,
551493deb39SJung-uk Kim     void                    **ReturnValue)
552493deb39SJung-uk Kim {
553493deb39SJung-uk Kim     ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
554493deb39SJung-uk Kim     ACPI_DB_EXECUTE_WALK    *Info = (ACPI_DB_EXECUTE_WALK *) Context;
555493deb39SJung-uk Kim     ACPI_BUFFER             ReturnObj;
556493deb39SJung-uk Kim     ACPI_STATUS             Status;
557493deb39SJung-uk Kim     char                    *Pathname;
558493deb39SJung-uk Kim     UINT32                  i;
559493deb39SJung-uk Kim     ACPI_DEVICE_INFO        *ObjInfo;
560493deb39SJung-uk Kim     ACPI_OBJECT_LIST        ParamObjects;
561493deb39SJung-uk Kim     ACPI_OBJECT             Params[ACPI_METHOD_NUM_ARGS];
562493deb39SJung-uk Kim     const ACPI_PREDEFINED_INFO *Predefined;
563493deb39SJung-uk Kim 
564493deb39SJung-uk Kim 
565493deb39SJung-uk Kim     Predefined = AcpiUtMatchPredefinedMethod (Node->Name.Ascii);
566493deb39SJung-uk Kim     if (!Predefined)
567493deb39SJung-uk Kim     {
568493deb39SJung-uk Kim         return (AE_OK);
569493deb39SJung-uk Kim     }
570493deb39SJung-uk Kim 
571493deb39SJung-uk Kim     if (Node->Type == ACPI_TYPE_LOCAL_SCOPE)
572493deb39SJung-uk Kim     {
573493deb39SJung-uk Kim         return (AE_OK);
574493deb39SJung-uk Kim     }
575493deb39SJung-uk Kim 
576493deb39SJung-uk Kim     Pathname = AcpiNsGetExternalPathname (Node);
577493deb39SJung-uk Kim     if (!Pathname)
578493deb39SJung-uk Kim     {
579493deb39SJung-uk Kim         return (AE_OK);
580493deb39SJung-uk Kim     }
581493deb39SJung-uk Kim 
582493deb39SJung-uk Kim     /* Get the object info for number of method parameters */
583493deb39SJung-uk Kim 
584493deb39SJung-uk Kim     Status = AcpiGetObjectInfo (ObjHandle, &ObjInfo);
585493deb39SJung-uk Kim     if (ACPI_FAILURE (Status))
586493deb39SJung-uk Kim     {
5870d84335fSJung-uk Kim         ACPI_FREE (Pathname);
588493deb39SJung-uk Kim         return (Status);
589493deb39SJung-uk Kim     }
590493deb39SJung-uk Kim 
591493deb39SJung-uk Kim     ParamObjects.Pointer = NULL;
592493deb39SJung-uk Kim     ParamObjects.Count   = 0;
593493deb39SJung-uk Kim 
594493deb39SJung-uk Kim     if (ObjInfo->Type == ACPI_TYPE_METHOD)
595493deb39SJung-uk Kim     {
596493deb39SJung-uk Kim         /* Setup default parameters */
597493deb39SJung-uk Kim 
598493deb39SJung-uk Kim         for (i = 0; i < ObjInfo->ParamCount; i++)
599493deb39SJung-uk Kim         {
600493deb39SJung-uk Kim             Params[i].Type           = ACPI_TYPE_INTEGER;
601493deb39SJung-uk Kim             Params[i].Integer.Value  = 1;
602493deb39SJung-uk Kim         }
603493deb39SJung-uk Kim 
604493deb39SJung-uk Kim         ParamObjects.Pointer     = Params;
605493deb39SJung-uk Kim         ParamObjects.Count       = ObjInfo->ParamCount;
606493deb39SJung-uk Kim     }
607493deb39SJung-uk Kim 
608493deb39SJung-uk Kim     ACPI_FREE (ObjInfo);
609493deb39SJung-uk Kim     ReturnObj.Pointer = NULL;
610493deb39SJung-uk Kim     ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
611493deb39SJung-uk Kim 
612493deb39SJung-uk Kim     /* Do the actual method execution */
613493deb39SJung-uk Kim 
614493deb39SJung-uk Kim     AcpiGbl_MethodExecuting = TRUE;
615493deb39SJung-uk Kim 
616493deb39SJung-uk Kim     Status = AcpiEvaluateObject (Node, NULL, &ParamObjects, &ReturnObj);
617493deb39SJung-uk Kim 
618493deb39SJung-uk Kim     AcpiOsPrintf ("%-32s returned %s\n", Pathname, AcpiFormatException (Status));
619493deb39SJung-uk Kim     AcpiGbl_MethodExecuting = FALSE;
620493deb39SJung-uk Kim     ACPI_FREE (Pathname);
621493deb39SJung-uk Kim 
622493deb39SJung-uk Kim     /* Ignore status from method execution */
623493deb39SJung-uk Kim 
624493deb39SJung-uk Kim     Status = AE_OK;
625493deb39SJung-uk Kim 
626493deb39SJung-uk Kim     /* Update count, check if we have executed enough methods */
627493deb39SJung-uk Kim 
628493deb39SJung-uk Kim     Info->Count++;
629493deb39SJung-uk Kim     if (Info->Count >= Info->MaxCount)
630493deb39SJung-uk Kim     {
631493deb39SJung-uk Kim         Status = AE_CTRL_TERMINATE;
632493deb39SJung-uk Kim     }
633493deb39SJung-uk Kim 
634493deb39SJung-uk Kim     return (Status);
635493deb39SJung-uk Kim }
636493deb39SJung-uk Kim 
637493deb39SJung-uk Kim 
638493deb39SJung-uk Kim /*******************************************************************************
639493deb39SJung-uk Kim  *
640493deb39SJung-uk Kim  * FUNCTION:    AcpiDbEvaluatePredefinedNames
641493deb39SJung-uk Kim  *
642493deb39SJung-uk Kim  * PARAMETERS:  None
643493deb39SJung-uk Kim  *
644493deb39SJung-uk Kim  * RETURN:      None
645493deb39SJung-uk Kim  *
646493deb39SJung-uk Kim  * DESCRIPTION: Namespace batch execution. Execute predefined names in the
647493deb39SJung-uk Kim  *              namespace, up to the max count, if specified.
648493deb39SJung-uk Kim  *
649493deb39SJung-uk Kim  ******************************************************************************/
650493deb39SJung-uk Kim 
651493deb39SJung-uk Kim void
652493deb39SJung-uk Kim AcpiDbEvaluatePredefinedNames (
653493deb39SJung-uk Kim     void)
654493deb39SJung-uk Kim {
655493deb39SJung-uk Kim     ACPI_DB_EXECUTE_WALK    Info;
656493deb39SJung-uk Kim 
657493deb39SJung-uk Kim 
658493deb39SJung-uk Kim     Info.Count = 0;
659493deb39SJung-uk Kim     Info.MaxCount = ACPI_UINT32_MAX;
660493deb39SJung-uk Kim 
661493deb39SJung-uk Kim     /* Search all nodes in namespace */
662493deb39SJung-uk Kim 
663493deb39SJung-uk Kim     (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
664493deb39SJung-uk Kim                 AcpiDbWalkForExecute, NULL, (void *) &Info, NULL);
665493deb39SJung-uk Kim 
666493deb39SJung-uk Kim     AcpiOsPrintf ("Evaluated %u predefined names in the namespace\n", Info.Count);
667493deb39SJung-uk Kim }
668