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