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: Namespace Node - 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:", 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         if (ACPI_GET_DESCRIPTOR_TYPE (
480             ((ACPI_NAMESPACE_NODE *) ObjDesc)) == ACPI_DESC_TYPE_NAMED)
481         {
482             AcpiOsPrintf (" Namespace Node - ");
483             Status = AcpiGetName ((ACPI_NAMESPACE_NODE *) ObjDesc,
484                 ACPI_FULL_PATHNAME_NO_TRAILING, &RetBuf);
485             if (ACPI_FAILURE (Status))
486             {
487                 AcpiOsPrintf ("Could not convert name to pathname\n");
488             }
489             else
490             {
491                 AcpiOsPrintf ("Pathname: %s",
492                     (char *) RetBuf.Pointer);
493             }
494 
495             AcpiOsPrintf ("\n");
496             AcpiUtDebugDumpBuffer ((void *) ObjDesc,
497                 sizeof (ACPI_NAMESPACE_NODE), Display, ACPI_UINT32_MAX);
498         }
499         else
500         {
501             AcpiOsPrintf ("\n");
502             AcpiUtDebugDumpBuffer ((void *) ObjDesc,
503                 sizeof (ACPI_OPERAND_OBJECT), Display, ACPI_UINT32_MAX);
504         }
505 
506         AcpiExDumpObjectDescriptor (ObjDesc, 1);
507     }
508 }
509 
510 
511 /*******************************************************************************
512  *
513  * FUNCTION:    AcpiDbDisplayMethodInfo
514  *
515  * PARAMETERS:  StartOp         - Root of the control method parse tree
516  *
517  * RETURN:      None
518  *
519  * DESCRIPTION: Display information about the current method
520  *
521  ******************************************************************************/
522 
523 void
524 AcpiDbDisplayMethodInfo (
525     ACPI_PARSE_OBJECT       *StartOp)
526 {
527     ACPI_WALK_STATE         *WalkState;
528     ACPI_OPERAND_OBJECT     *ObjDesc;
529     ACPI_NAMESPACE_NODE     *Node;
530     ACPI_PARSE_OBJECT       *RootOp;
531     ACPI_PARSE_OBJECT       *Op;
532     const ACPI_OPCODE_INFO  *OpInfo;
533     UINT32                  NumOps = 0;
534     UINT32                  NumOperands = 0;
535     UINT32                  NumOperators = 0;
536     UINT32                  NumRemainingOps = 0;
537     UINT32                  NumRemainingOperands = 0;
538     UINT32                  NumRemainingOperators = 0;
539     BOOLEAN                 CountRemaining = FALSE;
540 
541 
542     WalkState = AcpiDsGetCurrentWalkState (AcpiGbl_CurrentWalkList);
543     if (!WalkState)
544     {
545         AcpiOsPrintf ("There is no method currently executing\n");
546         return;
547     }
548 
549     ObjDesc = WalkState->MethodDesc;
550     Node = WalkState->MethodNode;
551 
552     AcpiOsPrintf ("Currently executing control method is [%4.4s]\n",
553         AcpiUtGetNodeName (Node));
554     AcpiOsPrintf ("%X Arguments, SyncLevel = %X\n",
555         (UINT32) ObjDesc->Method.ParamCount,
556         (UINT32) ObjDesc->Method.SyncLevel);
557 
558     RootOp = StartOp;
559     while (RootOp->Common.Parent)
560     {
561         RootOp = RootOp->Common.Parent;
562     }
563 
564     Op = RootOp;
565 
566     while (Op)
567     {
568         if (Op == StartOp)
569         {
570             CountRemaining = TRUE;
571         }
572 
573         NumOps++;
574         if (CountRemaining)
575         {
576             NumRemainingOps++;
577         }
578 
579         /* Decode the opcode */
580 
581         OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
582         switch (OpInfo->Class)
583         {
584         case AML_CLASS_ARGUMENT:
585 
586             if (CountRemaining)
587             {
588                 NumRemainingOperands++;
589             }
590 
591             NumOperands++;
592             break;
593 
594         case AML_CLASS_UNKNOWN:
595 
596             /* Bad opcode or ASCII character */
597 
598             continue;
599 
600         default:
601 
602             if (CountRemaining)
603             {
604                 NumRemainingOperators++;
605             }
606 
607             NumOperators++;
608             break;
609         }
610 
611         Op = AcpiPsGetDepthNext (StartOp, Op);
612     }
613 
614     AcpiOsPrintf (
615         "Method contains:       %X AML Opcodes - %X Operators, %X Operands\n",
616         NumOps, NumOperators, NumOperands);
617 
618     AcpiOsPrintf (
619         "Remaining to execute:  %X AML Opcodes - %X Operators, %X Operands\n",
620         NumRemainingOps, NumRemainingOperators, NumRemainingOperands);
621 }
622 
623 
624 /*******************************************************************************
625  *
626  * FUNCTION:    AcpiDbDisplayLocals
627  *
628  * PARAMETERS:  None
629  *
630  * RETURN:      None
631  *
632  * DESCRIPTION: Display all locals for the currently running control method
633  *
634  ******************************************************************************/
635 
636 void
637 AcpiDbDisplayLocals (
638     void)
639 {
640     ACPI_WALK_STATE         *WalkState;
641 
642 
643     WalkState = AcpiDsGetCurrentWalkState (AcpiGbl_CurrentWalkList);
644     if (!WalkState)
645     {
646         AcpiOsPrintf ("There is no method currently executing\n");
647         return;
648     }
649 
650     AcpiDbDecodeLocals (WalkState);
651 }
652 
653 
654 /*******************************************************************************
655  *
656  * FUNCTION:    AcpiDbDisplayArguments
657  *
658  * PARAMETERS:  None
659  *
660  * RETURN:      None
661  *
662  * DESCRIPTION: Display all arguments for the currently running control method
663  *
664  ******************************************************************************/
665 
666 void
667 AcpiDbDisplayArguments (
668     void)
669 {
670     ACPI_WALK_STATE         *WalkState;
671 
672 
673     WalkState = AcpiDsGetCurrentWalkState (AcpiGbl_CurrentWalkList);
674     if (!WalkState)
675     {
676         AcpiOsPrintf ("There is no method currently executing\n");
677         return;
678     }
679 
680     AcpiDbDecodeArguments (WalkState);
681 }
682 
683 
684 /*******************************************************************************
685  *
686  * FUNCTION:    AcpiDbDisplayResults
687  *
688  * PARAMETERS:  None
689  *
690  * RETURN:      None
691  *
692  * DESCRIPTION: Display current contents of a method result stack
693  *
694  ******************************************************************************/
695 
696 void
697 AcpiDbDisplayResults (
698     void)
699 {
700     UINT32                  i;
701     ACPI_WALK_STATE         *WalkState;
702     ACPI_OPERAND_OBJECT     *ObjDesc;
703     UINT32                  ResultCount = 0;
704     ACPI_NAMESPACE_NODE     *Node;
705     ACPI_GENERIC_STATE      *Frame;
706     UINT32                  Index; /* Index onto current frame */
707 
708 
709     WalkState = AcpiDsGetCurrentWalkState (AcpiGbl_CurrentWalkList);
710     if (!WalkState)
711     {
712         AcpiOsPrintf ("There is no method currently executing\n");
713         return;
714     }
715 
716     ObjDesc = WalkState->MethodDesc;
717     Node  = WalkState->MethodNode;
718 
719     if (WalkState->Results)
720     {
721         ResultCount = WalkState->ResultCount;
722     }
723 
724     AcpiOsPrintf ("Method [%4.4s] has %X stacked result objects\n",
725         AcpiUtGetNodeName (Node), ResultCount);
726 
727     /* From the top element of result stack */
728 
729     Frame = WalkState->Results;
730     Index = (ResultCount - 1) % ACPI_RESULTS_FRAME_OBJ_NUM;
731 
732     for (i = 0; i < ResultCount; i++)
733     {
734         ObjDesc = Frame->Results.ObjDesc[Index];
735         AcpiOsPrintf ("Result%u: ", i);
736         AcpiDbDisplayInternalObject (ObjDesc, WalkState);
737 
738         if (Index == 0)
739         {
740             Frame = Frame->Results.Next;
741             Index = ACPI_RESULTS_FRAME_OBJ_NUM;
742         }
743 
744         Index--;
745     }
746 }
747 
748 
749 /*******************************************************************************
750  *
751  * FUNCTION:    AcpiDbDisplayCallingTree
752  *
753  * PARAMETERS:  None
754  *
755  * RETURN:      None
756  *
757  * DESCRIPTION: Display current calling tree of nested control methods
758  *
759  ******************************************************************************/
760 
761 void
762 AcpiDbDisplayCallingTree (
763     void)
764 {
765     ACPI_WALK_STATE         *WalkState;
766     ACPI_NAMESPACE_NODE     *Node;
767 
768 
769     WalkState = AcpiDsGetCurrentWalkState (AcpiGbl_CurrentWalkList);
770     if (!WalkState)
771     {
772         AcpiOsPrintf ("There is no method currently executing\n");
773         return;
774     }
775 
776     Node = WalkState->MethodNode;
777     AcpiOsPrintf ("Current Control Method Call Tree\n");
778 
779     while (WalkState)
780     {
781         Node = WalkState->MethodNode;
782         AcpiOsPrintf ("    [%4.4s]\n", AcpiUtGetNodeName (Node));
783 
784         WalkState = WalkState->Next;
785     }
786 }
787 
788 
789 /*******************************************************************************
790  *
791  * FUNCTION:    AcpiDbDisplayObjectType
792  *
793  * PARAMETERS:  ObjectArg       - User entered NS node handle
794  *
795  * RETURN:      None
796  *
797  * DESCRIPTION: Display type of an arbitrary NS node
798  *
799  ******************************************************************************/
800 
801 void
802 AcpiDbDisplayObjectType (
803     char                    *ObjectArg)
804 {
805     ACPI_SIZE               Arg;
806     ACPI_HANDLE             Handle;
807     ACPI_DEVICE_INFO        *Info;
808     ACPI_STATUS             Status;
809     UINT32                  i;
810 
811 
812     Arg = strtoul (ObjectArg, NULL, 16);
813     Handle = ACPI_TO_POINTER (Arg);
814 
815     Status = AcpiGetObjectInfo (Handle, &Info);
816     if (ACPI_FAILURE (Status))
817     {
818         AcpiOsPrintf ("Could not get object info, %s\n",
819             AcpiFormatException (Status));
820         return;
821     }
822 
823     AcpiOsPrintf ("ADR: %8.8X%8.8X, STA: %8.8X, Flags: %X\n",
824         ACPI_FORMAT_UINT64 (Info->Address),
825         Info->CurrentStatus, Info->Flags);
826 
827     AcpiOsPrintf ("S1D-%2.2X S2D-%2.2X S3D-%2.2X S4D-%2.2X\n",
828         Info->HighestDstates[0], Info->HighestDstates[1],
829         Info->HighestDstates[2], Info->HighestDstates[3]);
830 
831     AcpiOsPrintf ("S0W-%2.2X S1W-%2.2X S2W-%2.2X S3W-%2.2X S4W-%2.2X\n",
832         Info->LowestDstates[0], Info->LowestDstates[1],
833         Info->LowestDstates[2], Info->LowestDstates[3],
834         Info->LowestDstates[4]);
835 
836     if (Info->Valid & ACPI_VALID_HID)
837     {
838         AcpiOsPrintf ("HID: %s\n", Info->HardwareId.String);
839     }
840 
841     if (Info->Valid & ACPI_VALID_UID)
842     {
843         AcpiOsPrintf ("UID: %s\n", Info->UniqueId.String);
844     }
845 
846     if (Info->Valid & ACPI_VALID_CID)
847     {
848         for (i = 0; i < Info->CompatibleIdList.Count; i++)
849         {
850             AcpiOsPrintf ("CID %u: %s\n", i,
851                 Info->CompatibleIdList.Ids[i].String);
852         }
853     }
854 
855     ACPI_FREE (Info);
856 }
857 
858 
859 /*******************************************************************************
860  *
861  * FUNCTION:    AcpiDbDisplayResultObject
862  *
863  * PARAMETERS:  ObjDesc         - Object to be displayed
864  *              WalkState       - Current walk state
865  *
866  * RETURN:      None
867  *
868  * DESCRIPTION: Display the result of an AML opcode
869  *
870  * Note: Curently only displays the result object if we are single stepping.
871  * However, this output may be useful in other contexts and could be enabled
872  * to do so if needed.
873  *
874  ******************************************************************************/
875 
876 void
877 AcpiDbDisplayResultObject (
878     ACPI_OPERAND_OBJECT     *ObjDesc,
879     ACPI_WALK_STATE         *WalkState)
880 {
881 
882 #ifndef ACPI_APPLICATION
883     if (AcpiGbl_DbThreadId != AcpiOsGetThreadId())
884     {
885         return;
886     }
887 #endif
888 
889     /* Only display if single stepping */
890 
891     if (!AcpiGbl_CmSingleStep)
892     {
893         return;
894     }
895 
896     AcpiOsPrintf ("ResultObj: ");
897     AcpiDbDisplayInternalObject (ObjDesc, WalkState);
898     AcpiOsPrintf ("\n");
899 }
900 
901 
902 /*******************************************************************************
903  *
904  * FUNCTION:    AcpiDbDisplayArgumentObject
905  *
906  * PARAMETERS:  ObjDesc         - Object to be displayed
907  *              WalkState       - Current walk state
908  *
909  * RETURN:      None
910  *
911  * DESCRIPTION: Display the result of an AML opcode
912  *
913  ******************************************************************************/
914 
915 void
916 AcpiDbDisplayArgumentObject (
917     ACPI_OPERAND_OBJECT     *ObjDesc,
918     ACPI_WALK_STATE         *WalkState)
919 {
920 
921 #ifndef ACPI_APPLICATION
922     if (AcpiGbl_DbThreadId != AcpiOsGetThreadId())
923     {
924         return;
925     }
926 #endif
927 
928     if (!AcpiGbl_CmSingleStep)
929     {
930         return;
931     }
932 
933     AcpiOsPrintf ("ArgObj:    ");
934     AcpiDbDisplayInternalObject (ObjDesc, WalkState);
935 }
936 
937 
938 #if (!ACPI_REDUCED_HARDWARE)
939 /*******************************************************************************
940  *
941  * FUNCTION:    AcpiDbDisplayGpes
942  *
943  * PARAMETERS:  None
944  *
945  * RETURN:      None
946  *
947  * DESCRIPTION: Display the current GPE structures
948  *
949  ******************************************************************************/
950 
951 void
952 AcpiDbDisplayGpes (
953     void)
954 {
955     ACPI_GPE_BLOCK_INFO     *GpeBlock;
956     ACPI_GPE_XRUPT_INFO     *GpeXruptInfo;
957     ACPI_GPE_EVENT_INFO     *GpeEventInfo;
958     ACPI_GPE_REGISTER_INFO  *GpeRegisterInfo;
959     char                    *GpeType;
960     ACPI_GPE_NOTIFY_INFO    *Notify;
961     UINT32                  GpeIndex;
962     UINT32                  Block = 0;
963     UINT32                  i;
964     UINT32                  j;
965     UINT32                  Count;
966     char                    Buffer[80];
967     ACPI_BUFFER             RetBuf;
968     ACPI_STATUS             Status;
969 
970 
971     RetBuf.Length = sizeof (Buffer);
972     RetBuf.Pointer = Buffer;
973 
974     Block = 0;
975 
976     /* Walk the GPE lists */
977 
978     GpeXruptInfo = AcpiGbl_GpeXruptListHead;
979     while (GpeXruptInfo)
980     {
981         GpeBlock = GpeXruptInfo->GpeBlockListHead;
982         while (GpeBlock)
983         {
984             Status = AcpiGetName (GpeBlock->Node,
985                 ACPI_FULL_PATHNAME_NO_TRAILING, &RetBuf);
986             if (ACPI_FAILURE (Status))
987             {
988                 AcpiOsPrintf ("Could not convert name to pathname\n");
989             }
990 
991             if (GpeBlock->Node == AcpiGbl_FadtGpeDevice)
992             {
993                 GpeType = "FADT-defined GPE block";
994             }
995             else
996             {
997                 GpeType = "GPE Block Device";
998             }
999 
1000             AcpiOsPrintf (
1001                 "\nBlock %u - Info %p  DeviceNode %p [%s] - %s\n",
1002                 Block, GpeBlock, GpeBlock->Node, Buffer, GpeType);
1003 
1004             AcpiOsPrintf (
1005                 "    Registers:    %u (%u GPEs)\n",
1006                 GpeBlock->RegisterCount, GpeBlock->GpeCount);
1007 
1008             AcpiOsPrintf (
1009                 "    GPE range:    0x%X to 0x%X on interrupt %u\n",
1010                 GpeBlock->BlockBaseNumber,
1011                 GpeBlock->BlockBaseNumber + (GpeBlock->GpeCount - 1),
1012                 GpeXruptInfo->InterruptNumber);
1013 
1014             AcpiOsPrintf (
1015                 "    RegisterInfo: %p  Status %8.8X%8.8X Enable %8.8X%8.8X\n",
1016                 GpeBlock->RegisterInfo,
1017                 ACPI_FORMAT_UINT64 (
1018                     GpeBlock->RegisterInfo->StatusAddress.Address),
1019                 ACPI_FORMAT_UINT64 (
1020                     GpeBlock->RegisterInfo->EnableAddress.Address));
1021 
1022             AcpiOsPrintf ("    EventInfo:    %p\n", GpeBlock->EventInfo);
1023 
1024             /* Examine each GPE Register within the block */
1025 
1026             for (i = 0; i < GpeBlock->RegisterCount; i++)
1027             {
1028                 GpeRegisterInfo = &GpeBlock->RegisterInfo[i];
1029 
1030                 AcpiOsPrintf (
1031                     "    Reg %u: (GPE %.2X-%.2X)  "
1032                     "RunEnable %2.2X WakeEnable %2.2X"
1033                     " Status %8.8X%8.8X Enable %8.8X%8.8X\n",
1034                     i, GpeRegisterInfo->BaseGpeNumber,
1035                     GpeRegisterInfo->BaseGpeNumber +
1036                         (ACPI_GPE_REGISTER_WIDTH - 1),
1037                     GpeRegisterInfo->EnableForRun,
1038                     GpeRegisterInfo->EnableForWake,
1039                     ACPI_FORMAT_UINT64 (
1040                         GpeRegisterInfo->StatusAddress.Address),
1041                     ACPI_FORMAT_UINT64 (
1042                         GpeRegisterInfo->EnableAddress.Address));
1043 
1044                 /* Now look at the individual GPEs in this byte register */
1045 
1046                 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++)
1047                 {
1048                     GpeIndex = (i * ACPI_GPE_REGISTER_WIDTH) + j;
1049                     GpeEventInfo = &GpeBlock->EventInfo[GpeIndex];
1050 
1051                     if (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) ==
1052                         ACPI_GPE_DISPATCH_NONE)
1053                     {
1054                         /* This GPE is not used (no method or handler), ignore it */
1055 
1056                         continue;
1057                     }
1058 
1059                     AcpiOsPrintf (
1060                         "        GPE %.2X: %p  RunRefs %2.2X Flags %2.2X (",
1061                         GpeBlock->BlockBaseNumber + GpeIndex, GpeEventInfo,
1062                         GpeEventInfo->RuntimeCount, GpeEventInfo->Flags);
1063 
1064                     /* Decode the flags byte */
1065 
1066                     if (GpeEventInfo->Flags & ACPI_GPE_LEVEL_TRIGGERED)
1067                     {
1068                         AcpiOsPrintf ("Level, ");
1069                     }
1070                     else
1071                     {
1072                         AcpiOsPrintf ("Edge,  ");
1073                     }
1074 
1075                     if (GpeEventInfo->Flags & ACPI_GPE_CAN_WAKE)
1076                     {
1077                         AcpiOsPrintf ("CanWake, ");
1078                     }
1079                     else
1080                     {
1081                         AcpiOsPrintf ("RunOnly, ");
1082                     }
1083 
1084                     switch (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags))
1085                     {
1086                     case ACPI_GPE_DISPATCH_NONE:
1087 
1088                         AcpiOsPrintf ("NotUsed");
1089                         break;
1090 
1091                     case ACPI_GPE_DISPATCH_METHOD:
1092 
1093                         AcpiOsPrintf ("Method");
1094                         break;
1095 
1096                     case ACPI_GPE_DISPATCH_HANDLER:
1097 
1098                         AcpiOsPrintf ("Handler");
1099                         break;
1100 
1101                     case ACPI_GPE_DISPATCH_NOTIFY:
1102 
1103                         Count = 0;
1104                         Notify = GpeEventInfo->Dispatch.NotifyList;
1105                         while (Notify)
1106                         {
1107                             Count++;
1108                             Notify = Notify->Next;
1109                         }
1110 
1111                         AcpiOsPrintf ("Implicit Notify on %u devices",
1112                             Count);
1113                         break;
1114 
1115                     case ACPI_GPE_DISPATCH_RAW_HANDLER:
1116 
1117                         AcpiOsPrintf ("RawHandler");
1118                         break;
1119 
1120                     default:
1121 
1122                         AcpiOsPrintf ("UNKNOWN: %X",
1123                             ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags));
1124                         break;
1125                     }
1126 
1127                     AcpiOsPrintf (")\n");
1128                 }
1129             }
1130 
1131             Block++;
1132             GpeBlock = GpeBlock->Next;
1133         }
1134 
1135         GpeXruptInfo = GpeXruptInfo->Next;
1136     }
1137 }
1138 #endif /* !ACPI_REDUCED_HARDWARE */
1139 
1140 
1141 /*******************************************************************************
1142  *
1143  * FUNCTION:    AcpiDbDisplayHandlers
1144  *
1145  * PARAMETERS:  None
1146  *
1147  * RETURN:      None
1148  *
1149  * DESCRIPTION: Display the currently installed global handlers
1150  *
1151  ******************************************************************************/
1152 
1153 void
1154 AcpiDbDisplayHandlers (
1155     void)
1156 {
1157     ACPI_OPERAND_OBJECT     *ObjDesc;
1158     ACPI_OPERAND_OBJECT     *HandlerObj;
1159     ACPI_ADR_SPACE_TYPE     SpaceId;
1160     UINT32                  i;
1161 
1162 
1163     /* Operation region handlers */
1164 
1165     AcpiOsPrintf ("\nOperation Region Handlers at the namespace root:\n");
1166 
1167     ObjDesc = AcpiNsGetAttachedObject (AcpiGbl_RootNode);
1168     if (ObjDesc)
1169     {
1170         for (i = 0; i < ACPI_ARRAY_LENGTH (AcpiGbl_SpaceIdList); i++)
1171         {
1172             SpaceId = AcpiGbl_SpaceIdList[i];
1173 
1174             AcpiOsPrintf (ACPI_PREDEFINED_PREFIX,
1175                 AcpiUtGetRegionName ((UINT8) SpaceId), SpaceId);
1176 
1177             HandlerObj = AcpiEvFindRegionHandler (
1178                 SpaceId, ObjDesc->CommonNotify.Handler);
1179             if (HandlerObj)
1180             {
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                 goto FoundHandler;
1188             }
1189 
1190             /* There is no handler for this SpaceId */
1191 
1192             AcpiOsPrintf ("None\n");
1193 
1194         FoundHandler:;
1195         }
1196 
1197         /* Find all handlers for user-defined SpaceIDs */
1198 
1199         HandlerObj = ObjDesc->CommonNotify.Handler;
1200         while (HandlerObj)
1201         {
1202             if (HandlerObj->AddressSpace.SpaceId >= ACPI_USER_REGION_BEGIN)
1203             {
1204                 AcpiOsPrintf (ACPI_PREDEFINED_PREFIX,
1205                     "User-defined ID", HandlerObj->AddressSpace.SpaceId);
1206                 AcpiOsPrintf (ACPI_HANDLER_PRESENT_STRING,
1207                     (HandlerObj->AddressSpace.HandlerFlags &
1208                         ACPI_ADDR_HANDLER_DEFAULT_INSTALLED) ?
1209                         "Default" : "User",
1210                     HandlerObj->AddressSpace.Handler);
1211             }
1212 
1213             HandlerObj = HandlerObj->AddressSpace.Next;
1214         }
1215     }
1216 
1217 #if (!ACPI_REDUCED_HARDWARE)
1218 
1219     /* Fixed event handlers */
1220 
1221     AcpiOsPrintf ("\nFixed Event Handlers:\n");
1222 
1223     for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++)
1224     {
1225         AcpiOsPrintf (ACPI_PREDEFINED_PREFIX, AcpiUtGetEventName (i), i);
1226         if (AcpiGbl_FixedEventHandlers[i].Handler)
1227         {
1228             AcpiOsPrintf (ACPI_HANDLER_PRESENT_STRING, "User",
1229                 AcpiGbl_FixedEventHandlers[i].Handler);
1230         }
1231         else
1232         {
1233             AcpiOsPrintf (ACPI_HANDLER_NOT_PRESENT_STRING, "None");
1234         }
1235     }
1236 
1237 #endif /* !ACPI_REDUCED_HARDWARE */
1238 
1239     /* Miscellaneous global handlers */
1240 
1241     AcpiOsPrintf ("\nMiscellaneous Global Handlers:\n");
1242 
1243     for (i = 0; i < ACPI_ARRAY_LENGTH (AcpiGbl_HandlerList); i++)
1244     {
1245         AcpiOsPrintf (ACPI_HANDLER_NAME_STRING,
1246             AcpiGbl_HandlerList[i].Name);
1247 
1248         if (AcpiGbl_HandlerList[i].Handler)
1249         {
1250             AcpiOsPrintf (ACPI_HANDLER_PRESENT_STRING, "User",
1251                 AcpiGbl_HandlerList[i].Handler);
1252         }
1253         else
1254         {
1255             AcpiOsPrintf (ACPI_HANDLER_NOT_PRESENT_STRING, "None");
1256         }
1257     }
1258 
1259 
1260     /* Other handlers that are installed throughout the namespace */
1261 
1262     AcpiOsPrintf ("\nOperation Region Handlers for specific devices:\n");
1263 
1264     (void) AcpiWalkNamespace (ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
1265         ACPI_UINT32_MAX, AcpiDbDisplayNonRootHandlers,
1266         NULL, NULL, NULL);
1267 }
1268 
1269 
1270 /*******************************************************************************
1271  *
1272  * FUNCTION:    AcpiDbDisplayNonRootHandlers
1273  *
1274  * PARAMETERS:  ACPI_WALK_CALLBACK
1275  *
1276  * RETURN:      Status
1277  *
1278  * DESCRIPTION: Display information about all handlers installed for a
1279  *              device object.
1280  *
1281  ******************************************************************************/
1282 
1283 static ACPI_STATUS
1284 AcpiDbDisplayNonRootHandlers (
1285     ACPI_HANDLE             ObjHandle,
1286     UINT32                  NestingLevel,
1287     void                    *Context,
1288     void                    **ReturnValue)
1289 {
1290     ACPI_NAMESPACE_NODE     *Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle);
1291     ACPI_OPERAND_OBJECT     *ObjDesc;
1292     ACPI_OPERAND_OBJECT     *HandlerObj;
1293     char                    *Pathname;
1294 
1295 
1296     ObjDesc = AcpiNsGetAttachedObject (Node);
1297     if (!ObjDesc)
1298     {
1299         return (AE_OK);
1300     }
1301 
1302     Pathname = AcpiNsGetNormalizedPathname (Node, TRUE);
1303     if (!Pathname)
1304     {
1305         return (AE_OK);
1306     }
1307 
1308     /* Display all handlers associated with this device */
1309 
1310     HandlerObj = ObjDesc->CommonNotify.Handler;
1311     while (HandlerObj)
1312     {
1313         AcpiOsPrintf (ACPI_PREDEFINED_PREFIX,
1314             AcpiUtGetRegionName ((UINT8) HandlerObj->AddressSpace.SpaceId),
1315             HandlerObj->AddressSpace.SpaceId);
1316 
1317         AcpiOsPrintf (ACPI_HANDLER_PRESENT_STRING2,
1318             (HandlerObj->AddressSpace.HandlerFlags &
1319                 ACPI_ADDR_HANDLER_DEFAULT_INSTALLED) ? "Default" : "User",
1320             HandlerObj->AddressSpace.Handler);
1321 
1322         AcpiOsPrintf (" Device Name: %s (%p)\n", Pathname, Node);
1323 
1324         HandlerObj = HandlerObj->AddressSpace.Next;
1325     }
1326 
1327     ACPI_FREE (Pathname);
1328     return (AE_OK);
1329 }
1330