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