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