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