1 /******************************************************************************
2  *
3  * Module Name: ahdecode - Operator/Opcode decoding for acpihelp utility
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 #define ACPI_CREATE_PREDEFINED_TABLE
45 #define ACPI_CREATE_RESOURCE_TABLE
46 
47 #include "acpihelp.h"
48 #include "acpredef.h"
49 
50 
51 #define AH_DISPLAY_EXCEPTION(Status, Name) \
52     printf ("%.4X: %s\n", Status, Name)
53 
54 #define AH_DISPLAY_EXCEPTION_TEXT(Status, Exception) \
55     printf ("%.4X: %-28s (%s)\n", Status, Exception->Name, Exception->Description)
56 
57 #define BUFFER_LENGTH           128
58 #define LINE_BUFFER_LENGTH      512
59 
60 static char         Gbl_Buffer[BUFFER_LENGTH];
61 static char         Gbl_LineBuffer[LINE_BUFFER_LENGTH];
62 
63 
64 /* Local prototypes */
65 
66 static BOOLEAN
67 AhDisplayPredefinedName (
68     char                    *Name,
69     UINT32                  Length);
70 
71 static void
72 AhDisplayPredefinedInfo (
73     char                    *Name);
74 
75 static void
76 AhDisplayResourceName (
77     const ACPI_PREDEFINED_INFO  *ThisName);
78 
79 static void
80 AhDisplayAmlOpcode (
81     const AH_AML_OPCODE     *Op);
82 
83 static void
84 AhDisplayAslOperator (
85     const AH_ASL_OPERATOR   *Op);
86 
87 static void
88 AhDisplayOperatorKeywords (
89     const AH_ASL_OPERATOR   *Op);
90 
91 static void
92 AhDisplayAslKeyword (
93     const AH_ASL_KEYWORD    *Op);
94 
95 static void
96 AhPrintOneField (
97     UINT32                  Indent,
98     UINT32                  CurrentPosition,
99     UINT32                  MaxPosition,
100     const char              *Field);
101 
102 
103 /*******************************************************************************
104  *
105  * FUNCTION:    AhDisplayDirectives
106  *
107  * PARAMETERS:  None
108  *
109  * RETURN:      None
110  *
111  * DESCRIPTION: Display all iASL preprocessor directives.
112  *
113  ******************************************************************************/
114 
115 void
116 AhDisplayDirectives (
117     void)
118 {
119     const AH_DIRECTIVE_INFO *Info;
120 
121 
122     printf ("iASL Preprocessor Directives\n\n");
123 
124     for (Info = PreprocessorDirectives; Info->Name; Info++)
125     {
126         printf ("  %-36s : %s\n", Info->Name, Info->Description);
127     }
128 }
129 
130 
131 /*******************************************************************************
132  *
133  * FUNCTION:    AhFindPredefinedNames (entry point for predefined name search)
134  *
135  * PARAMETERS:  NamePrefix          - Name or prefix to find. Must start with
136  *                                    an underscore. NULL means "find all"
137  *
138  * RETURN:      None
139  *
140  * DESCRIPTION: Find and display all ACPI predefined names that match the
141  *              input name or prefix. Includes the required number of arguments
142  *              and the expected return type, if any.
143  *
144  ******************************************************************************/
145 
146 void
147 AhFindPredefinedNames (
148     char                    *NamePrefix)
149 {
150     UINT32                  Length;
151     BOOLEAN                 Found;
152     char                    Name[9];
153 
154 
155     if (!NamePrefix)
156     {
157         Found = AhDisplayPredefinedName (NULL, 0);
158         return;
159     }
160 
161     /* Contruct a local name or name prefix */
162 
163     AcpiUtStrupr (NamePrefix);
164     if (*NamePrefix == '_')
165     {
166         NamePrefix++;
167     }
168 
169     Name[0] = '_';
170     strncpy (&Name[1], NamePrefix, 7);
171 
172     Length = strlen (Name);
173     if (Length > ACPI_NAME_SIZE)
174     {
175         printf ("%.8s: Predefined name must be 4 characters maximum\n", Name);
176         return;
177     }
178 
179     Found = AhDisplayPredefinedName (Name, Length);
180     if (!Found)
181     {
182         printf ("%s, no matching predefined names\n", Name);
183     }
184 }
185 
186 
187 /*******************************************************************************
188  *
189  * FUNCTION:    AhDisplayPredefinedName
190  *
191  * PARAMETERS:  Name                - Name or name prefix
192  *
193  * RETURN:      TRUE if any names matched, FALSE otherwise
194  *
195  * DESCRIPTION: Display information about ACPI predefined names that match
196  *              the input name or name prefix.
197  *
198  ******************************************************************************/
199 
200 static BOOLEAN
201 AhDisplayPredefinedName (
202     char                    *Name,
203     UINT32                  Length)
204 {
205     const AH_PREDEFINED_NAME    *Info;
206     BOOLEAN                     Found = FALSE;
207     BOOLEAN                     Matched;
208     UINT32                      i = 0;
209 
210 
211     /* Find/display all names that match the input name prefix */
212 
213     for (Info = AslPredefinedInfo; Info->Name; Info++)
214     {
215         if (!Name)
216         {
217             Found = TRUE;
218             printf ("%s: <%s>\n", Info->Name, Info->Description);
219             printf ("%*s%s\n", 6, " ", Info->Action);
220 
221             AhDisplayPredefinedInfo (Info->Name);
222             i++;
223             continue;
224         }
225 
226         Matched = TRUE;
227         for (i = 0; i < Length; i++)
228         {
229             if (Info->Name[i] != Name[i])
230             {
231                 Matched = FALSE;
232                 break;
233             }
234         }
235 
236         if (Matched)
237         {
238             Found = TRUE;
239             printf ("%s: <%s>\n", Info->Name, Info->Description);
240             printf ("%*s%s\n", 6, " ", Info->Action);
241 
242             AhDisplayPredefinedInfo (Info->Name);
243         }
244     }
245 
246     if (!Name)
247     {
248         printf ("\nFound %d Predefined ACPI Names\n", i);
249     }
250     return (Found);
251 }
252 
253 
254 /*******************************************************************************
255  *
256  * FUNCTION:    AhDisplayPredefinedInfo
257  *
258  * PARAMETERS:  Name                - Exact 4-character ACPI name.
259  *
260  * RETURN:      None
261  *
262  * DESCRIPTION: Find the name in the main ACPICA predefined info table and
263  *              display the # of arguments and the return value type.
264  *
265  *              Note: Resource Descriptor field names do not appear in this
266  *              table -- thus, nothing will be displayed for them.
267  *
268  ******************************************************************************/
269 
270 static void
271 AhDisplayPredefinedInfo (
272     char                        *Name)
273 {
274     const ACPI_PREDEFINED_INFO  *ThisName;
275 
276 
277     /* NOTE: we check both tables always because there are some dupes */
278 
279     /* Check against the predefine methods first */
280 
281     ThisName = AcpiUtMatchPredefinedMethod (Name);
282     if (ThisName)
283     {
284         AcpiUtDisplayPredefinedMethod (Gbl_Buffer, ThisName, TRUE);
285     }
286 
287     /* Check against the predefined resource descriptor names */
288 
289     ThisName = AcpiUtMatchResourceName (Name);
290     if (ThisName)
291     {
292         AhDisplayResourceName (ThisName);
293     }
294 }
295 
296 
297 /*******************************************************************************
298  *
299  * FUNCTION:    AhDisplayResourceName
300  *
301  * PARAMETERS:  ThisName            - Entry in the predefined method/name table
302  *
303  * RETURN:      None
304  *
305  * DESCRIPTION: Display information about a resource descriptor name.
306  *
307  ******************************************************************************/
308 
309 static void
310 AhDisplayResourceName (
311     const ACPI_PREDEFINED_INFO  *ThisName)
312 {
313     UINT32                      NumTypes;
314 
315 
316     NumTypes = AcpiUtGetResourceBitWidth (Gbl_Buffer,
317         ThisName->Info.ArgumentList);
318 
319     printf ("      %4.4s resource descriptor field is %s bits wide%s\n",
320         ThisName->Info.Name,
321         Gbl_Buffer,
322         (NumTypes > 1) ? " (depending on descriptor type)" : "");
323 }
324 
325 
326 /*******************************************************************************
327  *
328  * FUNCTION:    AhFindAmlOpcode (entry point for AML opcode name search)
329  *
330  * PARAMETERS:  Name                - Name or prefix for an AML opcode.
331  *                                    NULL means "find all"
332  *
333  * RETURN:      None
334  *
335  * DESCRIPTION: Find all AML opcodes that match the input Name or name
336  *              prefix.
337  *
338  ******************************************************************************/
339 
340 void
341 AhFindAmlOpcode (
342     char                    *Name)
343 {
344     const AH_AML_OPCODE     *Op;
345     BOOLEAN                 Found = FALSE;
346 
347 
348     AcpiUtStrupr (Name);
349 
350     /* Find/display all opcode names that match the input name prefix */
351 
352     for (Op = AmlOpcodeInfo; Op->OpcodeString; Op++)
353     {
354         if (!Op->OpcodeName) /* Unused opcodes */
355         {
356             continue;
357         }
358 
359         if (!Name)
360         {
361             AhDisplayAmlOpcode (Op);
362             Found = TRUE;
363             continue;
364         }
365 
366         /* Upper case the opcode name before substring compare */
367 
368         strcpy (Gbl_Buffer, Op->OpcodeName);
369         AcpiUtStrupr (Gbl_Buffer);
370 
371         if (strstr (Gbl_Buffer, Name) == Gbl_Buffer)
372         {
373             AhDisplayAmlOpcode (Op);
374             Found = TRUE;
375         }
376     }
377 
378     if (!Found)
379     {
380         printf ("%s, no matching AML operators\n", Name);
381     }
382 }
383 
384 
385 /*******************************************************************************
386  *
387  * FUNCTION:    AhDecodeAmlOpcode (entry point for AML opcode search)
388  *
389  * PARAMETERS:  OpcodeString        - String version of AML opcode
390  *
391  * RETURN:      None
392  *
393  * DESCRIPTION: Display information about the input AML opcode
394  *
395  ******************************************************************************/
396 
397 void
398 AhDecodeAmlOpcode (
399     char                    *OpcodeString)
400 {
401     const AH_AML_OPCODE     *Op;
402     UINT32                  Opcode;
403     UINT8                   Prefix;
404 
405 
406     if (!OpcodeString)
407     {
408         AhFindAmlOpcode (NULL);
409         return;
410     }
411 
412     Opcode = strtoul (OpcodeString, NULL, 16);
413     if (Opcode > ACPI_UINT16_MAX)
414     {
415         printf ("Invalid opcode (more than 16 bits)\n");
416         return;
417     }
418 
419     /* Only valid opcode extension is 0x5B */
420 
421     Prefix = (Opcode & 0x0000FF00) >> 8;
422     if (Prefix && (Prefix != 0x5B))
423     {
424         printf ("Invalid opcode (invalid extension prefix 0x%X)\n",
425             Prefix);
426         return;
427     }
428 
429     /* Find/Display the opcode. May fall within an opcode range */
430 
431     for (Op = AmlOpcodeInfo; Op->OpcodeString; Op++)
432     {
433         if ((Opcode >= Op->OpcodeRangeStart) &&
434             (Opcode <= Op->OpcodeRangeEnd))
435         {
436             AhDisplayAmlOpcode (Op);
437         }
438     }
439 }
440 
441 
442 /*******************************************************************************
443  *
444  * FUNCTION:    AhDisplayAmlOpcode
445  *
446  * PARAMETERS:  Op                  - An opcode info struct
447  *
448  * RETURN:      None
449  *
450  * DESCRIPTION: Display the contents of an AML opcode information struct
451  *
452  ******************************************************************************/
453 
454 static void
455 AhDisplayAmlOpcode (
456     const AH_AML_OPCODE     *Op)
457 {
458 
459     if (!Op->OpcodeName)
460     {
461         printf ("%18s: Opcode=%-9s\n", "Reserved opcode", Op->OpcodeString);
462         return;
463     }
464 
465     /* Opcode name and value(s) */
466 
467     printf ("%18s: Opcode=%-9s Type (%s)",
468         Op->OpcodeName, Op->OpcodeString, Op->Type);
469 
470     /* Optional fixed/static arguments */
471 
472     if (Op->FixedArguments)
473     {
474         printf (" FixedArgs (");
475         AhPrintOneField (37, 36 + 7 + strlen (Op->Type) + 12,
476             AH_MAX_AML_LINE_LENGTH, Op->FixedArguments);
477         printf (")");
478     }
479 
480     /* Optional variable-length argument list */
481 
482     if (Op->VariableArguments)
483     {
484         if (Op->FixedArguments)
485         {
486             printf ("\n%*s", 36, " ");
487         }
488         printf (" VariableArgs (");
489         AhPrintOneField (37, 15, AH_MAX_AML_LINE_LENGTH, Op->VariableArguments);
490         printf (")");
491     }
492     printf ("\n");
493 
494     /* Grammar specification */
495 
496     if (Op->Grammar)
497     {
498         AhPrintOneField (37, 0, AH_MAX_AML_LINE_LENGTH, Op->Grammar);
499         printf ("\n");
500     }
501 }
502 
503 
504 /*******************************************************************************
505  *
506  * FUNCTION:    AhFindAslKeywords (entry point for ASL keyword search)
507  *
508  * PARAMETERS:  Name                - Name or prefix for an ASL keyword.
509  *                                    NULL means "find all"
510  *
511  * RETURN:      None
512  *
513  * DESCRIPTION: Find all ASL keywords that match the input Name or name
514  *              prefix.
515  *
516  ******************************************************************************/
517 
518 void
519 AhFindAslKeywords (
520     char                    *Name)
521 {
522     const AH_ASL_KEYWORD    *Keyword;
523     BOOLEAN                 Found = FALSE;
524 
525 
526     AcpiUtStrupr (Name);
527 
528     for (Keyword = AslKeywordInfo; Keyword->Name; Keyword++)
529     {
530         if (!Name)
531         {
532             AhDisplayAslKeyword (Keyword);
533             Found = TRUE;
534             continue;
535         }
536 
537         /* Upper case the operator name before substring compare */
538 
539         strcpy (Gbl_Buffer, Keyword->Name);
540         AcpiUtStrupr (Gbl_Buffer);
541 
542         if (strstr (Gbl_Buffer, Name) == Gbl_Buffer)
543         {
544             AhDisplayAslKeyword (Keyword);
545             Found = TRUE;
546         }
547     }
548 
549     if (!Found)
550     {
551         printf ("%s, no matching ASL keywords\n", Name);
552     }
553 }
554 
555 
556 /*******************************************************************************
557  *
558  * FUNCTION:    AhDisplayAslKeyword
559  *
560  * PARAMETERS:  Op                  - Pointer to ASL keyword with syntax info
561  *
562  * RETURN:      None
563  *
564  * DESCRIPTION: Format and display syntax info for an ASL keyword. Splits
565  *              long lines appropriately for reading.
566  *
567  ******************************************************************************/
568 
569 static void
570 AhDisplayAslKeyword (
571     const AH_ASL_KEYWORD    *Op)
572 {
573 
574     /* ASL keyword name and description */
575 
576     printf ("%22s: %s\n", Op->Name, Op->Description);
577     if (!Op->KeywordList)
578     {
579         return;
580     }
581 
582     /* List of actual keywords */
583 
584     AhPrintOneField (24, 0, AH_MAX_ASL_LINE_LENGTH, Op->KeywordList);
585     printf ("\n");
586 }
587 
588 
589 /*******************************************************************************
590  *
591  * FUNCTION:    AhFindAslAndAmlOperators
592  *
593  * PARAMETERS:  Name                - Name or prefix for an ASL operator.
594  *                                    NULL means "find all"
595  *
596  * RETURN:      None
597  *
598  * DESCRIPTION: Find all ASL operators that match the input Name or name
599  *              prefix. Also displays the AML information if only one entry
600  *              matches.
601  *
602  ******************************************************************************/
603 
604 void
605 AhFindAslAndAmlOperators (
606     char                    *Name)
607 {
608     UINT32                  MatchCount;
609 
610 
611     MatchCount = AhFindAslOperators (Name);
612     if (MatchCount == 1)
613     {
614         AhFindAmlOpcode (Name);
615     }
616 }
617 
618 
619 /*******************************************************************************
620  *
621  * FUNCTION:    AhFindAslOperators (entry point for ASL operator search)
622  *
623  * PARAMETERS:  Name                - Name or prefix for an ASL operator.
624  *                                    NULL means "find all"
625  *
626  * RETURN:      Number of operators that matched the name prefix.
627  *
628  * DESCRIPTION: Find all ASL operators that match the input Name or name
629  *              prefix.
630  *
631  ******************************************************************************/
632 
633 UINT32
634 AhFindAslOperators (
635     char                    *Name)
636 {
637     const AH_ASL_OPERATOR   *Operator;
638     BOOLEAN                 MatchCount = 0;
639 
640 
641     AcpiUtStrupr (Name);
642 
643     /* Find/display all names that match the input name prefix */
644 
645     for (Operator = AslOperatorInfo; Operator->Name; Operator++)
646     {
647         if (!Name)
648         {
649             AhDisplayAslOperator (Operator);
650             MatchCount++;
651             continue;
652         }
653 
654         /* Upper case the operator name before substring compare */
655 
656         strcpy (Gbl_Buffer, Operator->Name);
657         AcpiUtStrupr (Gbl_Buffer);
658 
659         if (strstr (Gbl_Buffer, Name) == Gbl_Buffer)
660         {
661             AhDisplayAslOperator (Operator);
662             MatchCount++;
663         }
664     }
665 
666     if (!MatchCount)
667     {
668         printf ("%s, no matching ASL operators\n", Name);
669     }
670 
671     return (MatchCount);
672 }
673 
674 
675 /*******************************************************************************
676  *
677  * FUNCTION:    AhDisplayAslOperator
678  *
679  * PARAMETERS:  Op                  - Pointer to ASL operator with syntax info
680  *
681  * RETURN:      None
682  *
683  * DESCRIPTION: Format and display syntax info for an ASL operator. Splits
684  *              long lines appropriately for reading.
685  *
686  ******************************************************************************/
687 
688 static void
689 AhDisplayAslOperator (
690     const AH_ASL_OPERATOR   *Op)
691 {
692 
693     /* ASL operator name and description */
694 
695     printf ("%16s: %s\n", Op->Name, Op->Description);
696     if (!Op->Syntax)
697     {
698         return;
699     }
700 
701     /* Syntax for the operator */
702 
703     AhPrintOneField (18, 0, AH_MAX_ASL_LINE_LENGTH, Op->Syntax);
704     printf ("\n");
705 
706     AhDisplayOperatorKeywords (Op);
707     printf ("\n");
708 }
709 
710 
711 /*******************************************************************************
712  *
713  * FUNCTION:    AhDisplayOperatorKeywords
714  *
715  * PARAMETERS:  Op                  - Pointer to ASL keyword with syntax info
716  *
717  * RETURN:      None
718  *
719  * DESCRIPTION: Display any/all keywords that are associated with the ASL
720  *              operator.
721  *
722  ******************************************************************************/
723 
724 static void
725 AhDisplayOperatorKeywords (
726     const AH_ASL_OPERATOR   *Op)
727 {
728     char                    *Token;
729     char                    *Separators = "(){}, ";
730     BOOLEAN                 FirstKeyword = TRUE;
731 
732 
733     if (!Op || !Op->Syntax)
734     {
735         return;
736     }
737 
738     /*
739      * Find all parameters that have the word "keyword" within, and then
740      * display the info about that keyword
741      */
742     strcpy (Gbl_LineBuffer, Op->Syntax);
743     Token = strtok (Gbl_LineBuffer, Separators);
744     while (Token)
745     {
746         if (strstr (Token, "Keyword"))
747         {
748             if (FirstKeyword)
749             {
750                 printf ("\n");
751                 FirstKeyword = FALSE;
752             }
753 
754             /* Found a keyword, display keyword information */
755 
756             AhFindAslKeywords (Token);
757         }
758 
759         Token = strtok (NULL, Separators);
760     }
761 }
762 
763 
764 /*******************************************************************************
765  *
766  * FUNCTION:    AhPrintOneField
767  *
768  * PARAMETERS:  Indent              - Indent length for new line(s)
769  *              CurrentPosition     - Position on current line
770  *              MaxPosition         - Max allowed line length
771  *              Field               - Data to output
772  *
773  * RETURN:      Line position after field is written
774  *
775  * DESCRIPTION: Split long lines appropriately for ease of reading.
776  *
777  ******************************************************************************/
778 
779 static void
780 AhPrintOneField (
781     UINT32                  Indent,
782     UINT32                  CurrentPosition,
783     UINT32                  MaxPosition,
784     const char              *Field)
785 {
786     UINT32                  Position;
787     UINT32                  TokenLength;
788     const char              *This;
789     const char              *Next;
790     const char              *Last;
791 
792 
793     This = Field;
794     Position = CurrentPosition;
795 
796     if (Position == 0)
797     {
798         printf ("%*s", (int) Indent, " ");
799         Position = Indent;
800     }
801 
802     Last = This + strlen (This);
803     while ((Next = strpbrk (This, " ")))
804     {
805         TokenLength = Next - This;
806         Position += TokenLength;
807 
808         /* Split long lines */
809 
810         if (Position > MaxPosition)
811         {
812             printf ("\n%*s", (int) Indent, " ");
813             Position = TokenLength;
814         }
815 
816         printf ("%.*s ", (int) TokenLength, This);
817         This = Next + 1;
818     }
819 
820     /* Handle last token on the input line */
821 
822     TokenLength = Last - This;
823     if (TokenLength > 0)
824     {
825         Position += TokenLength;
826         if (Position > MaxPosition)
827         {
828             printf ("\n%*s", (int) Indent, " ");
829         }
830 
831         printf ("%s", This);
832     }
833 }
834 
835 
836 /*******************************************************************************
837  *
838  * FUNCTION:    AhDisplayDeviceIds
839  *
840  * PARAMETERS:  Name                - Device Hardware ID string.
841  *                                    NULL means "find all"
842  *
843  * RETURN:      None
844  *
845  * DESCRIPTION: Display PNP* and ACPI* device IDs.
846  *
847  ******************************************************************************/
848 
849 void
850 AhDisplayDeviceIds (
851     char                    *Name)
852 {
853     const AH_DEVICE_ID      *Info;
854     UINT32                  Length;
855     BOOLEAN                 Matched;
856     UINT32                  i;
857     BOOLEAN                 Found = FALSE;
858 
859 
860     /* Null input name indicates "display all" */
861 
862     if (!Name)
863     {
864         printf ("ACPI and PNP Device/Hardware IDs:\n\n");
865         for (Info = AslDeviceIds; Info->Name; Info++)
866         {
867             printf ("%8s   %s\n", Info->Name, Info->Description);
868         }
869 
870         return;
871     }
872 
873     Length = strlen (Name);
874     if (Length > 8)
875     {
876         printf ("%.8s: Hardware ID must be 8 characters maximum\n", Name);
877         return;
878     }
879 
880     /* Find/display all names that match the input name prefix */
881 
882     AcpiUtStrupr (Name);
883     for (Info = AslDeviceIds; Info->Name; Info++)
884     {
885         Matched = TRUE;
886         for (i = 0; i < Length; i++)
887         {
888             if (Info->Name[i] != Name[i])
889             {
890                 Matched = FALSE;
891                 break;
892             }
893         }
894 
895         if (Matched)
896         {
897             Found = TRUE;
898             printf ("%8s   %s\n", Info->Name, Info->Description);
899         }
900     }
901 
902     if (!Found)
903     {
904         printf ("%s, Hardware ID not found\n", Name);
905     }
906 }
907 
908 
909 /*******************************************************************************
910  *
911  * FUNCTION:    AhDisplayUuids
912  *
913  * PARAMETERS:  None
914  *
915  * RETURN:      None
916  *
917  * DESCRIPTION: Display all known UUIDs.
918  *
919  ******************************************************************************/
920 
921 void
922 AhDisplayUuids (
923     void)
924 {
925     const AH_UUID           *Info;
926 
927 
928     printf ("ACPI-related UUIDs/GUIDs:\n");
929 
930     /* Display entire table of known ACPI-related UUIDs/GUIDs */
931 
932     for (Info = AcpiUuids; Info->Description; Info++)
933     {
934         if (!Info->String) /* Null UUID string means group description */
935         {
936             printf ("\n%36s\n", Info->Description);
937         }
938         else
939         {
940             printf ("%32s : %s\n", Info->Description, Info->String);
941         }
942     }
943 
944     /* Help info on how UUIDs/GUIDs strings are encoded */
945 
946     printf ("\n\nByte encoding of UUID/GUID strings"
947         " into ACPI Buffer objects (use ToUUID from ASL):\n\n");
948 
949     printf ("%32s : %s\n", "Input UUID/GUID String format",
950         "aabbccdd-eeff-gghh-iijj-kkllmmnnoopp");
951 
952     printf ("%32s : %s\n", "Expected output ACPI buffer",
953         "dd,cc,bb,aa, ff,ee, hh,gg, ii,jj, kk,ll,mm,nn,oo,pp");
954 }
955 
956 
957 /*******************************************************************************
958  *
959  * FUNCTION:    AhDisplayTables
960  *
961  * PARAMETERS:  None
962  *
963  * RETURN:      None
964  *
965  * DESCRIPTION: Display all known ACPI tables
966  *
967  ******************************************************************************/
968 
969 void
970 AhDisplayTables (
971     void)
972 {
973     const AH_TABLE          *Info;
974     UINT32                  i = 0;
975 
976 
977     printf ("Known ACPI tables:\n");
978 
979     for (Info = AcpiSupportedTables; Info->Signature; Info++)
980     {
981         printf ("%8s : %s\n", Info->Signature, Info->Description);
982         i++;
983     }
984 
985     printf ("\nTotal %u ACPI tables\n\n", i);
986 }
987 
988 
989 /*******************************************************************************
990  *
991  * FUNCTION:    AhDecodeException
992  *
993  * PARAMETERS:  HexString           - ACPI status string from command line, in
994  *                                    hex. If null, display all exceptions.
995  *
996  * RETURN:      None
997  *
998  * DESCRIPTION: Decode and display an ACPI_STATUS exception code.
999  *
1000  ******************************************************************************/
1001 
1002 void
1003 AhDecodeException (
1004     char                    *HexString)
1005 {
1006     const ACPI_EXCEPTION_INFO   *ExceptionInfo;
1007     UINT32                      Status;
1008     UINT32                      i;
1009 
1010 
1011     /*
1012      * A null input string means to decode and display all known
1013      * exception codes.
1014      */
1015     if (!HexString)
1016     {
1017         printf ("All defined ACPICA exception codes:\n\n");
1018         AH_DISPLAY_EXCEPTION (0,
1019             "AE_OK                        (No error occurred)");
1020 
1021         /* Display codes in each block of exception types */
1022 
1023         for (i = 1; (i & AE_CODE_MASK) <= AE_CODE_MAX; i += 0x1000)
1024         {
1025             Status = i;
1026             do
1027             {
1028                 ExceptionInfo = AcpiUtValidateException ((ACPI_STATUS) Status);
1029                 if (ExceptionInfo)
1030                 {
1031                     AH_DISPLAY_EXCEPTION_TEXT (Status, ExceptionInfo);
1032                 }
1033 
1034                 Status++;
1035 
1036             } while (ExceptionInfo);
1037         }
1038         return;
1039     }
1040 
1041     /* Decode a single user-supplied exception code */
1042 
1043     Status = strtoul (HexString, NULL, 16);
1044     if (!Status)
1045     {
1046         printf ("%s: Invalid hexadecimal exception code value\n", HexString);
1047         return;
1048     }
1049 
1050     if (Status > ACPI_UINT16_MAX)
1051     {
1052         AH_DISPLAY_EXCEPTION (Status, "Invalid exception code (more than 16 bits)");
1053         return;
1054     }
1055 
1056     ExceptionInfo = AcpiUtValidateException ((ACPI_STATUS) Status);
1057     if (!ExceptionInfo)
1058     {
1059         AH_DISPLAY_EXCEPTION (Status, "Unknown exception code");
1060         return;
1061     }
1062 
1063     AH_DISPLAY_EXCEPTION_TEXT (Status, ExceptionInfo);
1064 }
1065