1 /*******************************************************************************
2  *
3  * Module Name: dbdisply - debug display commands
4  *
5  ******************************************************************************/
6 
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp.
12  * All rights reserved.
13  *
14  * 2. License
15  *
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.
20  *
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
27  *
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;
36  *
37  * The above copyright and patent license is granted only if the following
38  * conditions are met:
39  *
40  * 3. Conditions
41  *
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.
53  *
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.
65  *
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.
71  *
72  * 3.4. Intel retains all right, title, and interest in and to the Original
73  * Intel Code.
74  *
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.
79  *
80  * 4. Disclaimer and Export Compliance
81  *
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.
89  *
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.
98  *
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.
113  *
114  *****************************************************************************
115  *
116  * Alternatively, you may choose to be licensed under the terms of the
117  * following license:
118  *
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.
133  *
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.
145  *
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.
149  *
150  *****************************************************************************/
151 
152 #include "acpi.h"
153 #include "accommon.h"
154 #include "amlcode.h"
155 #include "acdispat.h"
156 #include "acnamesp.h"
157 #include "acparser.h"
158 #include "acinterp.h"
159 #include "acevents.h"
160 #include "acdebug.h"
161 
162 
163 #ifdef ACPI_DEBUGGER
164 
165 #define _COMPONENT          ACPI_CA_DEBUGGER
166         ACPI_MODULE_NAME    ("dbdisply")
167 
168 /* Local prototypes */
169 
170 static void
171 AcpiDbDumpParserDescriptor (
172     ACPI_PARSE_OBJECT       *Op);
173 
174 static void *
175 AcpiDbGetPointer (
176     void                    *Target);
177 
178 static ACPI_STATUS
179 AcpiDbDisplayNonRootHandlers (
180     ACPI_HANDLE             ObjHandle,
181     UINT32                  NestingLevel,
182     void                    *Context,
183     void                    **ReturnValue);
184 
185 /*
186  * System handler information.
187  * Used for Handlers command, in AcpiDbDisplayHandlers.
188  */
189 #define ACPI_PREDEFINED_PREFIX          "%25s (%.2X) : "
190 #define ACPI_HANDLER_NAME_STRING               "%30s : "
191 #define ACPI_HANDLER_PRESENT_STRING                    "%-9s (%p)\n"
192 #define ACPI_HANDLER_PRESENT_STRING2                   "%-9s (%p)"
193 #define ACPI_HANDLER_NOT_PRESENT_STRING                "%-9s\n"
194 
195 /* All predefined Address Space IDs */
196 
197 static ACPI_ADR_SPACE_TYPE  AcpiGbl_SpaceIdList[] =
198 {
199     ACPI_ADR_SPACE_SYSTEM_MEMORY,
200     ACPI_ADR_SPACE_SYSTEM_IO,
201     ACPI_ADR_SPACE_PCI_CONFIG,
202     ACPI_ADR_SPACE_EC,
203     ACPI_ADR_SPACE_SMBUS,
204     ACPI_ADR_SPACE_CMOS,
205     ACPI_ADR_SPACE_PCI_BAR_TARGET,
206     ACPI_ADR_SPACE_IPMI,
207     ACPI_ADR_SPACE_GPIO,
208     ACPI_ADR_SPACE_GSBUS,
209     ACPI_ADR_SPACE_DATA_TABLE,
210     ACPI_ADR_SPACE_FIXED_HARDWARE
211 };
212 
213 /* Global handler information */
214 
215 typedef struct acpi_handler_info
216 {
217     void                    *Handler;
218     char                    *Name;
219 
220 } ACPI_HANDLER_INFO;
221 
222 static ACPI_HANDLER_INFO    AcpiGbl_HandlerList[] =
223 {
224     {&AcpiGbl_GlobalNotify[0].Handler,  "System Notifications"},
225     {&AcpiGbl_GlobalNotify[1].Handler,  "Device Notifications"},
226     {&AcpiGbl_TableHandler,             "ACPI Table Events"},
227     {&AcpiGbl_ExceptionHandler,         "Control Method Exceptions"},
228     {&AcpiGbl_InterfaceHandler,         "OSI Invocations"}
229 };
230 
231 
232 /*******************************************************************************
233  *
234  * FUNCTION:    AcpiDbGetPointer
235  *
236  * PARAMETERS:  Target          - Pointer to string to be converted
237  *
238  * RETURN:      Converted pointer
239  *
240  * DESCRIPTION: Convert an ascii pointer value to a real value
241  *
242  ******************************************************************************/
243 
244 static void *
245 AcpiDbGetPointer (
246     void                    *Target)
247 {
248     void                    *ObjPtr;
249     ACPI_SIZE               Address;
250 
251 
252     Address = strtoul (Target, NULL, 16);
253     ObjPtr = ACPI_TO_POINTER (Address);
254     return (ObjPtr);
255 }
256 
257 
258 /*******************************************************************************
259  *
260  * FUNCTION:    AcpiDbDumpParserDescriptor
261  *
262  * PARAMETERS:  Op              - A parser Op descriptor
263  *
264  * RETURN:      None
265  *
266  * DESCRIPTION: Display a formatted parser object
267  *
268  ******************************************************************************/
269 
270 static void
271 AcpiDbDumpParserDescriptor (
272     ACPI_PARSE_OBJECT       *Op)
273 {
274     const ACPI_OPCODE_INFO  *Info;
275 
276 
277     Info = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
278 
279     AcpiOsPrintf ("Parser Op Descriptor:\n");
280     AcpiOsPrintf ("%20.20s : %4.4X\n", "Opcode", Op->Common.AmlOpcode);
281 
282     ACPI_DEBUG_ONLY_MEMBERS (AcpiOsPrintf ("%20.20s : %s\n", "Opcode Name",
283         Info->Name));
284 
285     AcpiOsPrintf ("%20.20s : %p\n", "Value/ArgList", Op->Common.Value.Arg);
286     AcpiOsPrintf ("%20.20s : %p\n", "Parent", Op->Common.Parent);
287     AcpiOsPrintf ("%20.20s : %p\n", "NextOp", Op->Common.Next);
288 }
289 
290 
291 /*******************************************************************************
292  *
293  * FUNCTION:    AcpiDbDecodeAndDisplayObject
294  *
295  * PARAMETERS:  Target          - String with object to be displayed. Names
296  *                                and hex pointers are supported.
297  *              OutputType      - Byte, Word, Dword, or Qword (B|W|D|Q)
298  *
299  * RETURN:      None
300  *
301  * DESCRIPTION: Display a formatted ACPI object
302  *
303  ******************************************************************************/
304 
305 void
306 AcpiDbDecodeAndDisplayObject (
307     char                    *Target,
308     char                    *OutputType)
309 {
310     void                    *ObjPtr;
311     ACPI_NAMESPACE_NODE     *Node;
312     ACPI_OPERAND_OBJECT     *ObjDesc;
313     UINT32                  Display = DB_BYTE_DISPLAY;
314     char                    Buffer[80];
315     ACPI_BUFFER             RetBuf;
316     ACPI_STATUS             Status;
317     UINT32                  Size;
318 
319 
320     if (!Target)
321     {
322         return;
323     }
324 
325     /* Decode the output type */
326 
327     if (OutputType)
328     {
329         AcpiUtStrupr (OutputType);
330         if (OutputType[0] == 'W')
331         {
332             Display = DB_WORD_DISPLAY;
333         }
334         else if (OutputType[0] == 'D')
335         {
336             Display = DB_DWORD_DISPLAY;
337         }
338         else if (OutputType[0] == 'Q')
339         {
340             Display = DB_QWORD_DISPLAY;
341         }
342     }
343 
344     RetBuf.Length = sizeof (Buffer);
345     RetBuf.Pointer = Buffer;
346 
347     /* Differentiate between a number and a name */
348 
349     if ((Target[0] >= 0x30) && (Target[0] <= 0x39))
350     {
351         ObjPtr = AcpiDbGetPointer (Target);
352         if (!AcpiOsReadable (ObjPtr, 16))
353         {
354             AcpiOsPrintf (
355                 "Address %p is invalid in this address space\n",
356                 ObjPtr);
357             return;
358         }
359 
360         /* Decode the object type */
361 
362         switch (ACPI_GET_DESCRIPTOR_TYPE (ObjPtr))
363         {
364         case ACPI_DESC_TYPE_NAMED:
365 
366             /* This is a namespace Node */
367 
368             if (!AcpiOsReadable (ObjPtr, sizeof (ACPI_NAMESPACE_NODE)))
369             {
370                 AcpiOsPrintf (
371                     "Cannot read entire Named object at address %p\n",
372                     ObjPtr);
373                 return;
374             }
375 
376             Node = ObjPtr;
377             goto DumpNode;
378 
379         case ACPI_DESC_TYPE_OPERAND:
380 
381             /* This is a ACPI OPERAND OBJECT */
382 
383             if (!AcpiOsReadable (ObjPtr, sizeof (ACPI_OPERAND_OBJECT)))
384             {
385                 AcpiOsPrintf (
386                     "Cannot read entire ACPI object at address %p\n",
387                     ObjPtr);
388                 return;
389             }
390 
391             AcpiUtDebugDumpBuffer (ObjPtr, sizeof (ACPI_OPERAND_OBJECT),
392                 Display, ACPI_UINT32_MAX);
393             AcpiExDumpObjectDescriptor (ObjPtr, 1);
394             break;
395 
396         case ACPI_DESC_TYPE_PARSER:
397 
398             /* This is a Parser Op object */
399 
400             if (!AcpiOsReadable (ObjPtr, sizeof (ACPI_PARSE_OBJECT)))
401             {
402                 AcpiOsPrintf (
403                     "Cannot read entire Parser object at address %p\n",
404                     ObjPtr);
405                 return;
406             }
407 
408             AcpiUtDebugDumpBuffer (ObjPtr, sizeof (ACPI_PARSE_OBJECT),
409                 Display, ACPI_UINT32_MAX);
410             AcpiDbDumpParserDescriptor ((ACPI_PARSE_OBJECT *) ObjPtr);
411             break;
412 
413         default:
414 
415             /* Is not a recognizeable object */
416 
417             AcpiOsPrintf (
418                 "Not a known ACPI internal object, descriptor type %2.2X\n",
419                 ACPI_GET_DESCRIPTOR_TYPE (ObjPtr));
420 
421             Size = 16;
422             if (AcpiOsReadable (ObjPtr, 64))
423             {
424                 Size = 64;
425             }
426 
427             /* Just dump some memory */
428 
429             AcpiUtDebugDumpBuffer (ObjPtr, Size, Display, ACPI_UINT32_MAX);
430             break;
431         }
432 
433         return;
434     }
435 
436     /* The parameter is a name string that must be resolved to a Named obj */
437 
438     Node = AcpiDbLocalNsLookup (Target);
439     if (!Node)
440     {
441         return;
442     }
443 
444 
445 DumpNode:
446     /* Now dump the NS node */
447 
448     Status = AcpiGetName (Node, ACPI_FULL_PATHNAME_NO_TRAILING, &RetBuf);
449     if (ACPI_FAILURE (Status))
450     {
451         AcpiOsPrintf ("Could not convert name to pathname\n");
452     }
453 
454     else
455     {
456         AcpiOsPrintf ("Object %p: Namespace Node - Pathname: %s\n",
457             Node, (char *) RetBuf.Pointer);
458     }
459 
460     if (!AcpiOsReadable (Node, sizeof (ACPI_NAMESPACE_NODE)))
461     {
462         AcpiOsPrintf ("Invalid Named object at address %p\n", Node);
463         return;
464     }
465 
466     AcpiUtDebugDumpBuffer ((void *) Node, sizeof (ACPI_NAMESPACE_NODE),
467         Display, ACPI_UINT32_MAX);
468     AcpiExDumpNamespaceNode (Node, 1);
469 
470     ObjDesc = AcpiNsGetAttachedObject (Node);
471     if (ObjDesc)
472     {
473         AcpiOsPrintf ("\nAttached Object %p:", ObjDesc);
474         if (!AcpiOsReadable (ObjDesc, sizeof (ACPI_OPERAND_OBJECT)))
475         {
476             AcpiOsPrintf ("Invalid internal ACPI Object at address %p\n",
477                 ObjDesc);
478             return;
479         }
480 
481         if (ACPI_GET_DESCRIPTOR_TYPE (
482             ((ACPI_NAMESPACE_NODE *) ObjDesc)) == ACPI_DESC_TYPE_NAMED)
483         {
484             AcpiOsPrintf (" Namespace Node - ");
485             Status = AcpiGetName ((ACPI_NAMESPACE_NODE *) ObjDesc,
486                 ACPI_FULL_PATHNAME_NO_TRAILING, &RetBuf);
487             if (ACPI_FAILURE (Status))
488             {
489                 AcpiOsPrintf ("Could not convert name to pathname\n");
490             }
491             else
492             {
493                 AcpiOsPrintf ("Pathname: %s",
494                     (char *) RetBuf.Pointer);
495             }
496 
497             AcpiOsPrintf ("\n");
498             AcpiUtDebugDumpBuffer ((void *) ObjDesc,
499                 sizeof (ACPI_NAMESPACE_NODE), Display, ACPI_UINT32_MAX);
500         }
501         else
502         {
503             AcpiOsPrintf ("\n");
504             AcpiUtDebugDumpBuffer ((void *) ObjDesc,
505                 sizeof (ACPI_OPERAND_OBJECT), Display, ACPI_UINT32_MAX);
506         }
507 
508         AcpiExDumpObjectDescriptor (ObjDesc, 1);
509     }
510 }
511 
512 
513 /*******************************************************************************
514  *
515  * FUNCTION:    AcpiDbDisplayMethodInfo
516  *
517  * PARAMETERS:  StartOp         - Root of the control method parse tree
518  *
519  * RETURN:      None
520  *
521  * DESCRIPTION: Display information about the current method
522  *
523  ******************************************************************************/
524 
525 void
526 AcpiDbDisplayMethodInfo (
527     ACPI_PARSE_OBJECT       *StartOp)
528 {
529     ACPI_WALK_STATE         *WalkState;
530     ACPI_OPERAND_OBJECT     *ObjDesc;
531     ACPI_NAMESPACE_NODE     *Node;
532     ACPI_PARSE_OBJECT       *RootOp;
533     ACPI_PARSE_OBJECT       *Op;
534     const ACPI_OPCODE_INFO  *OpInfo;
535     UINT32                  NumOps = 0;
536     UINT32                  NumOperands = 0;
537     UINT32                  NumOperators = 0;
538     UINT32                  NumRemainingOps = 0;
539     UINT32                  NumRemainingOperands = 0;
540     UINT32                  NumRemainingOperators = 0;
541     BOOLEAN                 CountRemaining = FALSE;
542 
543 
544     WalkState = AcpiDsGetCurrentWalkState (AcpiGbl_CurrentWalkList);
545     if (!WalkState)
546     {
547         AcpiOsPrintf ("There is no method currently executing\n");
548         return;
549     }
550 
551     ObjDesc = WalkState->MethodDesc;
552     Node = WalkState->MethodNode;
553 
554     AcpiOsPrintf ("Currently executing control method is [%4.4s]\n",
555         AcpiUtGetNodeName (Node));
556     AcpiOsPrintf ("%X Arguments, SyncLevel = %X\n",
557         (UINT32) ObjDesc->Method.ParamCount,
558         (UINT32) ObjDesc->Method.SyncLevel);
559 
560     RootOp = StartOp;
561     while (RootOp->Common.Parent)
562     {
563         RootOp = RootOp->Common.Parent;
564     }
565 
566     Op = RootOp;
567 
568     while (Op)
569     {
570         if (Op == StartOp)
571         {
572             CountRemaining = TRUE;
573         }
574 
575         NumOps++;
576         if (CountRemaining)
577         {
578             NumRemainingOps++;
579         }
580 
581         /* Decode the opcode */
582 
583         OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
584         switch (OpInfo->Class)
585         {
586         case AML_CLASS_ARGUMENT:
587 
588             if (CountRemaining)
589             {
590                 NumRemainingOperands++;
591             }
592 
593             NumOperands++;
594             break;
595 
596         case AML_CLASS_UNKNOWN:
597 
598             /* Bad opcode or ASCII character */
599 
600             continue;
601 
602         default:
603 
604             if (CountRemaining)
605             {
606                 NumRemainingOperators++;
607             }
608 
609             NumOperators++;
610             break;
611         }
612 
613         Op = AcpiPsGetDepthNext (StartOp, Op);
614     }
615 
616     AcpiOsPrintf (
617         "Method contains:       %X AML Opcodes - %X Operators, %X Operands\n",
618         NumOps, NumOperators, NumOperands);
619 
620     AcpiOsPrintf (
621         "Remaining to execute:  %X AML Opcodes - %X Operators, %X Operands\n",
622         NumRemainingOps, NumRemainingOperators, NumRemainingOperands);
623 }
624 
625 
626 /*******************************************************************************
627  *
628  * FUNCTION:    AcpiDbDisplayLocals
629  *
630  * PARAMETERS:  None
631  *
632  * RETURN:      None
633  *
634  * DESCRIPTION: Display all locals for the currently running control method
635  *
636  ******************************************************************************/
637 
638 void
639 AcpiDbDisplayLocals (
640     void)
641 {
642     ACPI_WALK_STATE         *WalkState;
643 
644 
645     WalkState = AcpiDsGetCurrentWalkState (AcpiGbl_CurrentWalkList);
646     if (!WalkState)
647     {
648         AcpiOsPrintf ("There is no method currently executing\n");
649         return;
650     }
651 
652     AcpiDbDecodeLocals (WalkState);
653 }
654 
655 
656 /*******************************************************************************
657  *
658  * FUNCTION:    AcpiDbDisplayArguments
659  *
660  * PARAMETERS:  None
661  *
662  * RETURN:      None
663  *
664  * DESCRIPTION: Display all arguments for the currently running control method
665  *
666  ******************************************************************************/
667 
668 void
669 AcpiDbDisplayArguments (
670     void)
671 {
672     ACPI_WALK_STATE         *WalkState;
673 
674 
675     WalkState = AcpiDsGetCurrentWalkState (AcpiGbl_CurrentWalkList);
676     if (!WalkState)
677     {
678         AcpiOsPrintf ("There is no method currently executing\n");
679         return;
680     }
681 
682     AcpiDbDecodeArguments (WalkState);
683 }
684 
685 
686 /*******************************************************************************
687  *
688  * FUNCTION:    AcpiDbDisplayResults
689  *
690  * PARAMETERS:  None
691  *
692  * RETURN:      None
693  *
694  * DESCRIPTION: Display current contents of a method result stack
695  *
696  ******************************************************************************/
697 
698 void
699 AcpiDbDisplayResults (
700     void)
701 {
702     UINT32                  i;
703     ACPI_WALK_STATE         *WalkState;
704     ACPI_OPERAND_OBJECT     *ObjDesc;
705     UINT32                  ResultCount = 0;
706     ACPI_NAMESPACE_NODE     *Node;
707     ACPI_GENERIC_STATE      *Frame;
708     UINT32                  Index; /* Index onto current frame */
709 
710 
711     WalkState = AcpiDsGetCurrentWalkState (AcpiGbl_CurrentWalkList);
712     if (!WalkState)
713     {
714         AcpiOsPrintf ("There is no method currently executing\n");
715         return;
716     }
717 
718     ObjDesc = WalkState->MethodDesc;
719     Node  = WalkState->MethodNode;
720 
721     if (WalkState->Results)
722     {
723         ResultCount = WalkState->ResultCount;
724     }
725 
726     AcpiOsPrintf ("Method [%4.4s] has %X stacked result objects\n",
727         AcpiUtGetNodeName (Node), ResultCount);
728 
729     /* From the top element of result stack */
730 
731     Frame = WalkState->Results;
732     Index = (ResultCount - 1) % ACPI_RESULTS_FRAME_OBJ_NUM;
733 
734     for (i = 0; i < ResultCount; i++)
735     {
736         ObjDesc = Frame->Results.ObjDesc[Index];
737         AcpiOsPrintf ("Result%u: ", i);
738         AcpiDbDisplayInternalObject (ObjDesc, WalkState);
739 
740         if (Index == 0)
741         {
742             Frame = Frame->Results.Next;
743             Index = ACPI_RESULTS_FRAME_OBJ_NUM;
744         }
745 
746         Index--;
747     }
748 }
749 
750 
751 /*******************************************************************************
752  *
753  * FUNCTION:    AcpiDbDisplayCallingTree
754  *
755  * PARAMETERS:  None
756  *
757  * RETURN:      None
758  *
759  * DESCRIPTION: Display current calling tree of nested control methods
760  *
761  ******************************************************************************/
762 
763 void
764 AcpiDbDisplayCallingTree (
765     void)
766 {
767     ACPI_WALK_STATE         *WalkState;
768     ACPI_NAMESPACE_NODE     *Node;
769 
770 
771     WalkState = AcpiDsGetCurrentWalkState (AcpiGbl_CurrentWalkList);
772     if (!WalkState)
773     {
774         AcpiOsPrintf ("There is no method currently executing\n");
775         return;
776     }
777 
778     Node = WalkState->MethodNode;
779     AcpiOsPrintf ("Current Control Method Call Tree\n");
780 
781     while (WalkState)
782     {
783         Node = WalkState->MethodNode;
784         AcpiOsPrintf ("    [%4.4s]\n", AcpiUtGetNodeName (Node));
785 
786         WalkState = WalkState->Next;
787     }
788 }
789 
790 
791 /*******************************************************************************
792  *
793  * FUNCTION:    AcpiDbDisplayObjectType
794  *
795  * PARAMETERS:  ObjectArg       - User entered NS node handle
796  *
797  * RETURN:      None
798  *
799  * DESCRIPTION: Display type of an arbitrary NS node
800  *
801  ******************************************************************************/
802 
803 void
804 AcpiDbDisplayObjectType (
805     char                    *ObjectArg)
806 {
807     ACPI_SIZE               Arg;
808     ACPI_HANDLE             Handle;
809     ACPI_DEVICE_INFO        *Info;
810     ACPI_STATUS             Status;
811     UINT32                  i;
812 
813 
814     Arg = strtoul (ObjectArg, NULL, 16);
815     Handle = ACPI_TO_POINTER (Arg);
816 
817     Status = AcpiGetObjectInfo (Handle, &Info);
818     if (ACPI_FAILURE (Status))
819     {
820         AcpiOsPrintf ("Could not get object info, %s\n",
821             AcpiFormatException (Status));
822         return;
823     }
824 
825     AcpiOsPrintf ("ADR: %8.8X%8.8X, STA: %8.8X, Flags: %X\n",
826         ACPI_FORMAT_UINT64 (Info->Address),
827         Info->CurrentStatus, Info->Flags);
828 
829     AcpiOsPrintf ("S1D-%2.2X S2D-%2.2X S3D-%2.2X S4D-%2.2X\n",
830         Info->HighestDstates[0], Info->HighestDstates[1],
831         Info->HighestDstates[2], Info->HighestDstates[3]);
832 
833     AcpiOsPrintf ("S0W-%2.2X S1W-%2.2X S2W-%2.2X S3W-%2.2X S4W-%2.2X\n",
834         Info->LowestDstates[0], Info->LowestDstates[1],
835         Info->LowestDstates[2], Info->LowestDstates[3],
836         Info->LowestDstates[4]);
837 
838     if (Info->Valid & ACPI_VALID_HID)
839     {
840         AcpiOsPrintf ("HID: %s\n", Info->HardwareId.String);
841     }
842 
843     if (Info->Valid & ACPI_VALID_UID)
844     {
845         AcpiOsPrintf ("UID: %s\n", Info->UniqueId.String);
846     }
847 
848     if (Info->Valid & ACPI_VALID_CID)
849     {
850         for (i = 0; i < Info->CompatibleIdList.Count; i++)
851         {
852             AcpiOsPrintf ("CID %u: %s\n", i,
853                 Info->CompatibleIdList.Ids[i].String);
854         }
855     }
856 
857     ACPI_FREE (Info);
858 }
859 
860 
861 /*******************************************************************************
862  *
863  * FUNCTION:    AcpiDbDisplayResultObject
864  *
865  * PARAMETERS:  ObjDesc         - Object to be displayed
866  *              WalkState       - Current walk state
867  *
868  * RETURN:      None
869  *
870  * DESCRIPTION: Display the result of an AML opcode
871  *
872  * Note: Curently only displays the result object if we are single stepping.
873  * However, this output may be useful in other contexts and could be enabled
874  * to do so if needed.
875  *
876  ******************************************************************************/
877 
878 void
879 AcpiDbDisplayResultObject (
880     ACPI_OPERAND_OBJECT     *ObjDesc,
881     ACPI_WALK_STATE         *WalkState)
882 {
883 
884 #ifndef ACPI_APPLICATION
885     if (AcpiGbl_DbThreadId != AcpiOsGetThreadId())
886     {
887         return;
888     }
889 #endif
890 
891     /* Only display if single stepping */
892 
893     if (!AcpiGbl_CmSingleStep)
894     {
895         return;
896     }
897 
898     AcpiOsPrintf ("ResultObj: ");
899     AcpiDbDisplayInternalObject (ObjDesc, WalkState);
900     AcpiOsPrintf ("\n");
901 }
902 
903 
904 /*******************************************************************************
905  *
906  * FUNCTION:    AcpiDbDisplayArgumentObject
907  *
908  * PARAMETERS:  ObjDesc         - Object to be displayed
909  *              WalkState       - Current walk state
910  *
911  * RETURN:      None
912  *
913  * DESCRIPTION: Display the result of an AML opcode
914  *
915  ******************************************************************************/
916 
917 void
918 AcpiDbDisplayArgumentObject (
919     ACPI_OPERAND_OBJECT     *ObjDesc,
920     ACPI_WALK_STATE         *WalkState)
921 {
922 
923 #ifndef ACPI_APPLICATION
924     if (AcpiGbl_DbThreadId != AcpiOsGetThreadId())
925     {
926         return;
927     }
928 #endif
929 
930     if (!AcpiGbl_CmSingleStep)
931     {
932         return;
933     }
934 
935     AcpiOsPrintf ("ArgObj:    ");
936     AcpiDbDisplayInternalObject (ObjDesc, WalkState);
937 }
938 
939 
940 #if (!ACPI_REDUCED_HARDWARE)
941 /*******************************************************************************
942  *
943  * FUNCTION:    AcpiDbDisplayGpes
944  *
945  * PARAMETERS:  None
946  *
947  * RETURN:      None
948  *
949  * DESCRIPTION: Display the current GPE structures
950  *
951  ******************************************************************************/
952 
953 void
954 AcpiDbDisplayGpes (
955     void)
956 {
957     ACPI_GPE_BLOCK_INFO     *GpeBlock;
958     ACPI_GPE_XRUPT_INFO     *GpeXruptInfo;
959     ACPI_GPE_EVENT_INFO     *GpeEventInfo;
960     ACPI_GPE_REGISTER_INFO  *GpeRegisterInfo;
961     char                    *GpeType;
962     ACPI_GPE_NOTIFY_INFO    *Notify;
963     UINT32                  GpeIndex;
964     UINT32                  Block = 0;
965     UINT32                  i;
966     UINT32                  j;
967     UINT32                  Count;
968     char                    Buffer[80];
969     ACPI_BUFFER             RetBuf;
970     ACPI_STATUS             Status;
971 
972 
973     RetBuf.Length = sizeof (Buffer);
974     RetBuf.Pointer = Buffer;
975 
976     Block = 0;
977 
978     /* Walk the GPE lists */
979 
980     GpeXruptInfo = AcpiGbl_GpeXruptListHead;
981     while (GpeXruptInfo)
982     {
983         GpeBlock = GpeXruptInfo->GpeBlockListHead;
984         while (GpeBlock)
985         {
986             Status = AcpiGetName (GpeBlock->Node,
987                 ACPI_FULL_PATHNAME_NO_TRAILING, &RetBuf);
988             if (ACPI_FAILURE (Status))
989             {
990                 AcpiOsPrintf ("Could not convert name to pathname\n");
991             }
992 
993             if (GpeBlock->Node == AcpiGbl_FadtGpeDevice)
994             {
995                 GpeType = "FADT-defined GPE block";
996             }
997             else
998             {
999                 GpeType = "GPE Block Device";
1000             }
1001 
1002             AcpiOsPrintf (
1003                 "\nBlock %u - Info %p  DeviceNode %p [%s] - %s\n",
1004                 Block, GpeBlock, GpeBlock->Node, Buffer, GpeType);
1005 
1006             AcpiOsPrintf (
1007                 "    Registers:    %u (%u GPEs)\n",
1008                 GpeBlock->RegisterCount, GpeBlock->GpeCount);
1009 
1010             AcpiOsPrintf (
1011                 "    GPE range:    0x%X to 0x%X on interrupt %u\n",
1012                 GpeBlock->BlockBaseNumber,
1013                 GpeBlock->BlockBaseNumber + (GpeBlock->GpeCount - 1),
1014                 GpeXruptInfo->InterruptNumber);
1015 
1016             AcpiOsPrintf (
1017                 "    RegisterInfo: %p  Status %8.8X%8.8X Enable %8.8X%8.8X\n",
1018                 GpeBlock->RegisterInfo,
1019                 ACPI_FORMAT_UINT64 (
1020                     GpeBlock->RegisterInfo->StatusAddress.Address),
1021                 ACPI_FORMAT_UINT64 (
1022                     GpeBlock->RegisterInfo->EnableAddress.Address));
1023 
1024             AcpiOsPrintf ("    EventInfo:    %p\n", GpeBlock->EventInfo);
1025 
1026             /* Examine each GPE Register within the block */
1027 
1028             for (i = 0; i < GpeBlock->RegisterCount; i++)
1029             {
1030                 GpeRegisterInfo = &GpeBlock->RegisterInfo[i];
1031 
1032                 AcpiOsPrintf (
1033                     "    Reg %u: (GPE %.2X-%.2X)  "
1034                     "RunEnable %2.2X WakeEnable %2.2X"
1035                     " Status %8.8X%8.8X Enable %8.8X%8.8X\n",
1036                     i, GpeRegisterInfo->BaseGpeNumber,
1037                     GpeRegisterInfo->BaseGpeNumber +
1038                         (ACPI_GPE_REGISTER_WIDTH - 1),
1039                     GpeRegisterInfo->EnableForRun,
1040                     GpeRegisterInfo->EnableForWake,
1041                     ACPI_FORMAT_UINT64 (
1042                         GpeRegisterInfo->StatusAddress.Address),
1043                     ACPI_FORMAT_UINT64 (
1044                         GpeRegisterInfo->EnableAddress.Address));
1045 
1046                 /* Now look at the individual GPEs in this byte register */
1047 
1048                 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++)
1049                 {
1050                     GpeIndex = (i * ACPI_GPE_REGISTER_WIDTH) + j;
1051                     GpeEventInfo = &GpeBlock->EventInfo[GpeIndex];
1052 
1053                     if (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) ==
1054                         ACPI_GPE_DISPATCH_NONE)
1055                     {
1056                         /* This GPE is not used (no method or handler), ignore it */
1057 
1058                         continue;
1059                     }
1060 
1061                     AcpiOsPrintf (
1062                         "        GPE %.2X: %p  RunRefs %2.2X Flags %2.2X (",
1063                         GpeBlock->BlockBaseNumber + GpeIndex, GpeEventInfo,
1064                         GpeEventInfo->RuntimeCount, GpeEventInfo->Flags);
1065 
1066                     /* Decode the flags byte */
1067 
1068                     if (GpeEventInfo->Flags & ACPI_GPE_LEVEL_TRIGGERED)
1069                     {
1070                         AcpiOsPrintf ("Level, ");
1071                     }
1072                     else
1073                     {
1074                         AcpiOsPrintf ("Edge,  ");
1075                     }
1076 
1077                     if (GpeEventInfo->Flags & ACPI_GPE_CAN_WAKE)
1078                     {
1079                         AcpiOsPrintf ("CanWake, ");
1080                     }
1081                     else
1082                     {
1083                         AcpiOsPrintf ("RunOnly, ");
1084                     }
1085 
1086                     switch (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags))
1087                     {
1088                     case ACPI_GPE_DISPATCH_NONE:
1089 
1090                         AcpiOsPrintf ("NotUsed");
1091                         break;
1092 
1093                     case ACPI_GPE_DISPATCH_METHOD:
1094 
1095                         AcpiOsPrintf ("Method");
1096                         break;
1097 
1098                     case ACPI_GPE_DISPATCH_HANDLER:
1099 
1100                         AcpiOsPrintf ("Handler");
1101                         break;
1102 
1103                     case ACPI_GPE_DISPATCH_NOTIFY:
1104 
1105                         Count = 0;
1106                         Notify = GpeEventInfo->Dispatch.NotifyList;
1107                         while (Notify)
1108                         {
1109                             Count++;
1110                             Notify = Notify->Next;
1111                         }
1112 
1113                         AcpiOsPrintf ("Implicit Notify on %u devices",
1114                             Count);
1115                         break;
1116 
1117                     case ACPI_GPE_DISPATCH_RAW_HANDLER:
1118 
1119                         AcpiOsPrintf ("RawHandler");
1120                         break;
1121 
1122                     default:
1123 
1124                         AcpiOsPrintf ("UNKNOWN: %X",
1125                             ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags));
1126                         break;
1127                     }
1128 
1129                     AcpiOsPrintf (")\n");
1130                 }
1131             }
1132 
1133             Block++;
1134             GpeBlock = GpeBlock->Next;
1135         }
1136 
1137         GpeXruptInfo = GpeXruptInfo->Next;
1138     }
1139 }
1140 #endif /* !ACPI_REDUCED_HARDWARE */
1141 
1142 
1143 /*******************************************************************************
1144  *
1145  * FUNCTION:    AcpiDbDisplayHandlers
1146  *
1147  * PARAMETERS:  None
1148  *
1149  * RETURN:      None
1150  *
1151  * DESCRIPTION: Display the currently installed global handlers
1152  *
1153  ******************************************************************************/
1154 
1155 void
1156 AcpiDbDisplayHandlers (
1157     void)
1158 {
1159     ACPI_OPERAND_OBJECT     *ObjDesc;
1160     ACPI_OPERAND_OBJECT     *HandlerObj;
1161     ACPI_ADR_SPACE_TYPE     SpaceId;
1162     UINT32                  i;
1163 
1164 
1165     /* Operation region handlers */
1166 
1167     AcpiOsPrintf ("\nOperation Region Handlers at the namespace root:\n");
1168 
1169     ObjDesc = AcpiNsGetAttachedObject (AcpiGbl_RootNode);
1170     if (ObjDesc)
1171     {
1172         for (i = 0; i < ACPI_ARRAY_LENGTH (AcpiGbl_SpaceIdList); i++)
1173         {
1174             SpaceId = AcpiGbl_SpaceIdList[i];
1175 
1176             AcpiOsPrintf (ACPI_PREDEFINED_PREFIX,
1177                 AcpiUtGetRegionName ((UINT8) SpaceId), SpaceId);
1178 
1179             HandlerObj = AcpiEvFindRegionHandler (
1180                 SpaceId, ObjDesc->CommonNotify.Handler);
1181             if (HandlerObj)
1182             {
1183                 AcpiOsPrintf (ACPI_HANDLER_PRESENT_STRING,
1184                     (HandlerObj->AddressSpace.HandlerFlags &
1185                         ACPI_ADDR_HANDLER_DEFAULT_INSTALLED) ?
1186                         "Default" : "User",
1187                     HandlerObj->AddressSpace.Handler);
1188 
1189                 goto FoundHandler;
1190             }
1191 
1192             /* There is no handler for this SpaceId */
1193 
1194             AcpiOsPrintf ("None\n");
1195 
1196         FoundHandler:;
1197         }
1198 
1199         /* Find all handlers for user-defined SpaceIDs */
1200 
1201         HandlerObj = ObjDesc->CommonNotify.Handler;
1202         while (HandlerObj)
1203         {
1204             if (HandlerObj->AddressSpace.SpaceId >= ACPI_USER_REGION_BEGIN)
1205             {
1206                 AcpiOsPrintf (ACPI_PREDEFINED_PREFIX,
1207                     "User-defined ID", HandlerObj->AddressSpace.SpaceId);
1208                 AcpiOsPrintf (ACPI_HANDLER_PRESENT_STRING,
1209                     (HandlerObj->AddressSpace.HandlerFlags &
1210                         ACPI_ADDR_HANDLER_DEFAULT_INSTALLED) ?
1211                         "Default" : "User",
1212                     HandlerObj->AddressSpace.Handler);
1213             }
1214 
1215             HandlerObj = HandlerObj->AddressSpace.Next;
1216         }
1217     }
1218 
1219 #if (!ACPI_REDUCED_HARDWARE)
1220 
1221     /* Fixed event handlers */
1222 
1223     AcpiOsPrintf ("\nFixed Event Handlers:\n");
1224 
1225     for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++)
1226     {
1227         AcpiOsPrintf (ACPI_PREDEFINED_PREFIX, AcpiUtGetEventName (i), i);
1228         if (AcpiGbl_FixedEventHandlers[i].Handler)
1229         {
1230             AcpiOsPrintf (ACPI_HANDLER_PRESENT_STRING, "User",
1231                 AcpiGbl_FixedEventHandlers[i].Handler);
1232         }
1233         else
1234         {
1235             AcpiOsPrintf (ACPI_HANDLER_NOT_PRESENT_STRING, "None");
1236         }
1237     }
1238 
1239 #endif /* !ACPI_REDUCED_HARDWARE */
1240 
1241     /* Miscellaneous global handlers */
1242 
1243     AcpiOsPrintf ("\nMiscellaneous Global Handlers:\n");
1244 
1245     for (i = 0; i < ACPI_ARRAY_LENGTH (AcpiGbl_HandlerList); i++)
1246     {
1247         AcpiOsPrintf (ACPI_HANDLER_NAME_STRING,
1248             AcpiGbl_HandlerList[i].Name);
1249 
1250         if (AcpiGbl_HandlerList[i].Handler)
1251         {
1252             AcpiOsPrintf (ACPI_HANDLER_PRESENT_STRING, "User",
1253                 AcpiGbl_HandlerList[i].Handler);
1254         }
1255         else
1256         {
1257             AcpiOsPrintf (ACPI_HANDLER_NOT_PRESENT_STRING, "None");
1258         }
1259     }
1260 
1261 
1262     /* Other handlers that are installed throughout the namespace */
1263 
1264     AcpiOsPrintf ("\nOperation Region Handlers for specific devices:\n");
1265 
1266     (void) AcpiWalkNamespace (ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
1267         ACPI_UINT32_MAX, AcpiDbDisplayNonRootHandlers,
1268         NULL, NULL, NULL);
1269 }
1270 
1271 
1272 /*******************************************************************************
1273  *
1274  * FUNCTION:    AcpiDbDisplayNonRootHandlers
1275  *
1276  * PARAMETERS:  ACPI_WALK_CALLBACK
1277  *
1278  * RETURN:      Status
1279  *
1280  * DESCRIPTION: Display information about all handlers installed for a
1281  *              device object.
1282  *
1283  ******************************************************************************/
1284 
1285 static ACPI_STATUS
1286 AcpiDbDisplayNonRootHandlers (
1287     ACPI_HANDLE             ObjHandle,
1288     UINT32                  NestingLevel,
1289     void                    *Context,
1290     void                    **ReturnValue)
1291 {
1292     ACPI_NAMESPACE_NODE     *Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle);
1293     ACPI_OPERAND_OBJECT     *ObjDesc;
1294     ACPI_OPERAND_OBJECT     *HandlerObj;
1295     char                    *Pathname;
1296 
1297 
1298     ObjDesc = AcpiNsGetAttachedObject (Node);
1299     if (!ObjDesc)
1300     {
1301         return (AE_OK);
1302     }
1303 
1304     Pathname = AcpiNsGetNormalizedPathname (Node, TRUE);
1305     if (!Pathname)
1306     {
1307         return (AE_OK);
1308     }
1309 
1310     /* Display all handlers associated with this device */
1311 
1312     HandlerObj = ObjDesc->CommonNotify.Handler;
1313     while (HandlerObj)
1314     {
1315         AcpiOsPrintf (ACPI_PREDEFINED_PREFIX,
1316             AcpiUtGetRegionName ((UINT8) HandlerObj->AddressSpace.SpaceId),
1317             HandlerObj->AddressSpace.SpaceId);
1318 
1319         AcpiOsPrintf (ACPI_HANDLER_PRESENT_STRING2,
1320             (HandlerObj->AddressSpace.HandlerFlags &
1321                 ACPI_ADDR_HANDLER_DEFAULT_INSTALLED) ? "Default" : "User",
1322             HandlerObj->AddressSpace.Handler);
1323 
1324         AcpiOsPrintf (" Device Name: %s (%p)\n", Pathname, Node);
1325 
1326         HandlerObj = HandlerObj->AddressSpace.Next;
1327     }
1328 
1329     ACPI_FREE (Pathname);
1330     return (AE_OK);
1331 }
1332 
1333 #endif /* ACPI_DEBUGGER */
1334