Sync ACPICA with Intel's version 20180810:
[dragonfly.git] / sys / contrib / dev / acpica / source / components / debugger / dbmethod.c
blob68e503e59a64a0df5cd4257ad2f02334974a5083
1 /*******************************************************************************
3 * Module Name: dbmethod - Debug commands for control methods
5 ******************************************************************************/
7 /******************************************************************************
9 * 1. Copyright Notice
11 * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
12 * All rights reserved.
14 * 2. License
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
19 * property rights.
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
38 * conditions are met:
40 * 3. Conditions
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
64 * make.
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
70 * distribution.
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88 * PARTICULAR PURPOSE.
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97 * LIMITED REMEDY.
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************
116 * Alternatively, you may choose to be licensed under the terms of the
117 * following license:
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
121 * are met:
122 * 1. Redistributions of source code must retain the above copyright
123 * notice, this list of conditions, and the following disclaimer,
124 * without modification.
125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 * substantially similar to the "NO WARRANTY" disclaimer below
127 * ("Disclaimer") and any redistribution must be conditioned upon
128 * including a substantially similar Disclaimer requirement for further
129 * binary redistribution.
130 * 3. Neither the names of the above-listed copyright holders nor the names
131 * of any contributors may be used to endorse or promote products derived
132 * from this software without specific prior written permission.
134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146 * Alternatively, you may choose to be licensed under the terms of the
147 * GNU General Public License ("GPL") version 2 as published by the Free
148 * Software Foundation.
150 *****************************************************************************/
152 #include "acpi.h"
153 #include "accommon.h"
154 #include "acdispat.h"
155 #include "acnamesp.h"
156 #include "acdebug.h"
157 #include "acparser.h"
158 #include "acpredef.h"
161 #ifdef ACPI_DEBUGGER
163 #define _COMPONENT ACPI_CA_DEBUGGER
164 ACPI_MODULE_NAME ("dbmethod")
166 /* Local prototypes */
168 static ACPI_STATUS
169 AcpiDbWalkForExecute (
170 ACPI_HANDLE ObjHandle,
171 UINT32 NestingLevel,
172 void *Context,
173 void **ReturnValue);
176 /*******************************************************************************
178 * FUNCTION: AcpiDbSetMethodBreakpoint
180 * PARAMETERS: Location - AML offset of breakpoint
181 * WalkState - Current walk info
182 * Op - Current Op (from parse walk)
184 * RETURN: None
186 * DESCRIPTION: Set a breakpoint in a control method at the specified
187 * AML offset
189 ******************************************************************************/
191 void
192 AcpiDbSetMethodBreakpoint (
193 char *Location,
194 ACPI_WALK_STATE *WalkState,
195 ACPI_PARSE_OBJECT *Op)
197 UINT32 Address;
198 UINT32 AmlOffset;
201 if (!Op)
203 AcpiOsPrintf ("There is no method currently executing\n");
204 return;
207 /* Get and verify the breakpoint address */
209 Address = strtoul (Location, NULL, 16);
210 AmlOffset = (UINT32) ACPI_PTR_DIFF (Op->Common.Aml,
211 WalkState->ParserState.AmlStart);
212 if (Address <= AmlOffset)
214 AcpiOsPrintf ("Breakpoint %X is beyond current address %X\n",
215 Address, AmlOffset);
218 /* Save breakpoint in current walk */
220 WalkState->UserBreakpoint = Address;
221 AcpiOsPrintf ("Breakpoint set at AML offset %X\n", Address);
225 /*******************************************************************************
227 * FUNCTION: AcpiDbSetMethodCallBreakpoint
229 * PARAMETERS: Op - Current Op (from parse walk)
231 * RETURN: None
233 * DESCRIPTION: Set a breakpoint in a control method at the specified
234 * AML offset
236 ******************************************************************************/
238 void
239 AcpiDbSetMethodCallBreakpoint (
240 ACPI_PARSE_OBJECT *Op)
244 if (!Op)
246 AcpiOsPrintf ("There is no method currently executing\n");
247 return;
250 AcpiGbl_StepToNextCall = TRUE;
254 /*******************************************************************************
256 * FUNCTION: AcpiDbSetMethodData
258 * PARAMETERS: TypeArg - L for local, A for argument
259 * IndexArg - which one
260 * ValueArg - Value to set.
262 * RETURN: None
264 * DESCRIPTION: Set a local or argument for the running control method.
265 * NOTE: only object supported is Number.
267 ******************************************************************************/
269 void
270 AcpiDbSetMethodData (
271 char *TypeArg,
272 char *IndexArg,
273 char *ValueArg)
275 char Type;
276 UINT32 Index;
277 UINT32 Value;
278 ACPI_WALK_STATE *WalkState;
279 ACPI_OPERAND_OBJECT *ObjDesc;
280 ACPI_STATUS Status;
281 ACPI_NAMESPACE_NODE *Node;
284 /* Validate TypeArg */
286 AcpiUtStrupr (TypeArg);
287 Type = TypeArg[0];
288 if ((Type != 'L') &&
289 (Type != 'A') &&
290 (Type != 'N'))
292 AcpiOsPrintf ("Invalid SET operand: %s\n", TypeArg);
293 return;
296 Value = strtoul (ValueArg, NULL, 16);
298 if (Type == 'N')
300 Node = AcpiDbConvertToNode (IndexArg);
301 if (!Node)
303 return;
306 if (Node->Type != ACPI_TYPE_INTEGER)
308 AcpiOsPrintf ("Can only set Integer nodes\n");
309 return;
311 ObjDesc = Node->Object;
312 ObjDesc->Integer.Value = Value;
313 return;
316 /* Get the index and value */
318 Index = strtoul (IndexArg, NULL, 16);
320 WalkState = AcpiDsGetCurrentWalkState (AcpiGbl_CurrentWalkList);
321 if (!WalkState)
323 AcpiOsPrintf ("There is no method currently executing\n");
324 return;
327 /* Create and initialize the new object */
329 ObjDesc = AcpiUtCreateIntegerObject ((UINT64) Value);
330 if (!ObjDesc)
332 AcpiOsPrintf ("Could not create an internal object\n");
333 return;
336 /* Store the new object into the target */
338 switch (Type)
340 case 'A':
342 /* Set a method argument */
344 if (Index > ACPI_METHOD_MAX_ARG)
346 AcpiOsPrintf ("Arg%u - Invalid argument name\n",
347 Index);
348 goto Cleanup;
351 Status = AcpiDsStoreObjectToLocal (ACPI_REFCLASS_ARG,
352 Index, ObjDesc, WalkState);
353 if (ACPI_FAILURE (Status))
355 goto Cleanup;
358 ObjDesc = WalkState->Arguments[Index].Object;
360 AcpiOsPrintf ("Arg%u: ", Index);
361 AcpiDbDisplayInternalObject (ObjDesc, WalkState);
362 break;
364 case 'L':
366 /* Set a method local */
368 if (Index > ACPI_METHOD_MAX_LOCAL)
370 AcpiOsPrintf ("Local%u - Invalid local variable name\n",
371 Index);
372 goto Cleanup;
375 Status = AcpiDsStoreObjectToLocal (ACPI_REFCLASS_LOCAL,
376 Index, ObjDesc, WalkState);
377 if (ACPI_FAILURE (Status))
379 goto Cleanup;
382 ObjDesc = WalkState->LocalVariables[Index].Object;
384 AcpiOsPrintf ("Local%u: ", Index);
385 AcpiDbDisplayInternalObject (ObjDesc, WalkState);
386 break;
388 default:
390 break;
393 Cleanup:
394 AcpiUtRemoveReference (ObjDesc);
398 #ifdef ACPI_DISASSEMBLER
399 /*******************************************************************************
401 * FUNCTION: AcpiDbDisassembleAml
403 * PARAMETERS: Statements - Number of statements to disassemble
404 * Op - Current Op (from parse walk)
406 * RETURN: None
408 * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
409 * of statements specified.
411 ******************************************************************************/
413 void
414 AcpiDbDisassembleAml (
415 char *Statements,
416 ACPI_PARSE_OBJECT *Op)
418 UINT32 NumStatements = 8;
421 if (!Op)
423 AcpiOsPrintf ("There is no method currently executing\n");
424 return;
427 if (Statements)
429 NumStatements = strtoul (Statements, NULL, 0);
432 AcpiDmDisassemble (NULL, Op, NumStatements);
436 /*******************************************************************************
438 * FUNCTION: AcpiDbDisassembleMethod
440 * PARAMETERS: Name - Name of control method
442 * RETURN: None
444 * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
445 * of statements specified.
447 ******************************************************************************/
449 ACPI_STATUS
450 AcpiDbDisassembleMethod (
451 char *Name)
453 ACPI_STATUS Status;
454 ACPI_PARSE_OBJECT *Op;
455 ACPI_WALK_STATE *WalkState;
456 ACPI_OPERAND_OBJECT *ObjDesc;
457 ACPI_NAMESPACE_NODE *Method;
460 Method = AcpiDbConvertToNode (Name);
461 if (!Method)
463 return (AE_BAD_PARAMETER);
466 if (Method->Type != ACPI_TYPE_METHOD)
468 ACPI_ERROR ((AE_INFO, "%s (%s): Object must be a control method",
469 Name, AcpiUtGetTypeName (Method->Type)));
470 return (AE_BAD_PARAMETER);
473 ObjDesc = Method->Object;
475 Op = AcpiPsCreateScopeOp (ObjDesc->Method.AmlStart);
476 if (!Op)
478 return (AE_NO_MEMORY);
481 /* Create and initialize a new walk state */
483 WalkState = AcpiDsCreateWalkState (0, Op, NULL, NULL);
484 if (!WalkState)
486 return (AE_NO_MEMORY);
489 Status = AcpiDsInitAmlWalk (WalkState, Op, NULL,
490 ObjDesc->Method.AmlStart,
491 ObjDesc->Method.AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
492 if (ACPI_FAILURE (Status))
494 return (Status);
497 Status = AcpiUtAllocateOwnerId (&ObjDesc->Method.OwnerId);
498 WalkState->OwnerId = ObjDesc->Method.OwnerId;
500 /* Push start scope on scope stack and make it current */
502 Status = AcpiDsScopeStackPush (Method,
503 Method->Type, WalkState);
504 if (ACPI_FAILURE (Status))
506 return (Status);
509 /* Parse the entire method AML including deferred operators */
511 WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
512 WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
514 Status = AcpiPsParseAml (WalkState);
515 (void) AcpiDmParseDeferredOps (Op);
517 /* Now we can disassemble the method */
519 AcpiGbl_DmOpt_Verbose = FALSE;
520 AcpiDmDisassemble (NULL, Op, 0);
521 AcpiGbl_DmOpt_Verbose = TRUE;
523 AcpiPsDeleteParseTree (Op);
525 /* Method cleanup */
527 AcpiNsDeleteNamespaceSubtree (Method);
528 AcpiNsDeleteNamespaceByOwner (ObjDesc->Method.OwnerId);
529 AcpiUtReleaseOwnerId (&ObjDesc->Method.OwnerId);
530 return (AE_OK);
532 #endif
535 /*******************************************************************************
537 * FUNCTION: AcpiDbWalkForExecute
539 * PARAMETERS: Callback from WalkNamespace
541 * RETURN: Status
543 * DESCRIPTION: Batch execution module. Currently only executes predefined
544 * ACPI names.
546 ******************************************************************************/
548 static ACPI_STATUS
549 AcpiDbWalkForExecute (
550 ACPI_HANDLE ObjHandle,
551 UINT32 NestingLevel,
552 void *Context,
553 void **ReturnValue)
555 ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
556 ACPI_DB_EXECUTE_WALK *Info = (ACPI_DB_EXECUTE_WALK *) Context;
557 ACPI_BUFFER ReturnObj;
558 ACPI_STATUS Status;
559 char *Pathname;
560 UINT32 i;
561 ACPI_DEVICE_INFO *ObjInfo;
562 ACPI_OBJECT_LIST ParamObjects;
563 ACPI_OBJECT Params[ACPI_METHOD_NUM_ARGS];
564 const ACPI_PREDEFINED_INFO *Predefined;
567 Predefined = AcpiUtMatchPredefinedMethod (Node->Name.Ascii);
568 if (!Predefined)
570 return (AE_OK);
573 if (Node->Type == ACPI_TYPE_LOCAL_SCOPE)
575 return (AE_OK);
578 Pathname = AcpiNsGetExternalPathname (Node);
579 if (!Pathname)
581 return (AE_OK);
584 /* Get the object info for number of method parameters */
586 Status = AcpiGetObjectInfo (ObjHandle, &ObjInfo);
587 if (ACPI_FAILURE (Status))
589 ACPI_FREE (Pathname);
590 return (Status);
593 ParamObjects.Pointer = NULL;
594 ParamObjects.Count = 0;
596 if (ObjInfo->Type == ACPI_TYPE_METHOD)
598 /* Setup default parameters */
600 for (i = 0; i < ObjInfo->ParamCount; i++)
602 Params[i].Type = ACPI_TYPE_INTEGER;
603 Params[i].Integer.Value = 1;
606 ParamObjects.Pointer = Params;
607 ParamObjects.Count = ObjInfo->ParamCount;
610 ACPI_FREE (ObjInfo);
611 ReturnObj.Pointer = NULL;
612 ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
614 /* Do the actual method execution */
616 AcpiGbl_MethodExecuting = TRUE;
618 Status = AcpiEvaluateObject (Node, NULL, &ParamObjects, &ReturnObj);
620 AcpiOsPrintf ("%-32s returned %s\n", Pathname, AcpiFormatException (Status));
621 AcpiGbl_MethodExecuting = FALSE;
622 ACPI_FREE (Pathname);
624 /* Ignore status from method execution */
626 Status = AE_OK;
628 /* Update count, check if we have executed enough methods */
630 Info->Count++;
631 if (Info->Count >= Info->MaxCount)
633 Status = AE_CTRL_TERMINATE;
636 return (Status);
640 /*******************************************************************************
642 * FUNCTION: AcpiDbEvaluatePredefinedNames
644 * PARAMETERS: None
646 * RETURN: None
648 * DESCRIPTION: Namespace batch execution. Execute predefined names in the
649 * namespace, up to the max count, if specified.
651 ******************************************************************************/
653 void
654 AcpiDbEvaluatePredefinedNames (
655 void)
657 ACPI_DB_EXECUTE_WALK Info;
660 Info.Count = 0;
661 Info.MaxCount = ACPI_UINT32_MAX;
663 /* Search all nodes in namespace */
665 (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
666 AcpiDbWalkForExecute, NULL, (void *) &Info, NULL);
668 AcpiOsPrintf ("Evaluated %u predefined names in the namespace\n", Info.Count);
671 #endif /* ACPI_DEBUGGER */