Sync ACPICA with Intel's version 20150717.
[dragonfly.git] / sys / contrib / dev / acpica / source / tools / acpihelp / ahdecode.c
1 /******************************************************************************
2  *
3  * Module Name: ahdecode - Operator/Opcode decoding for acpihelp utility
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 #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 > 4)
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         printf ("%s", This);
831     }
832 }
833
834
835 /*******************************************************************************
836  *
837  * FUNCTION:    AhDisplayDeviceIds
838  *
839  * PARAMETERS:  Name                - Device Hardware ID string.
840  *                                    NULL means "find all"
841  *
842  * RETURN:      None
843  *
844  * DESCRIPTION: Display PNP* and ACPI* device IDs.
845  *
846  ******************************************************************************/
847
848 void
849 AhDisplayDeviceIds (
850     char                    *Name)
851 {
852     const AH_DEVICE_ID      *Info;
853     UINT32                  Length;
854     BOOLEAN                 Matched;
855     UINT32                  i;
856     BOOLEAN                 Found = FALSE;
857
858
859     /* Null input name indicates "display all" */
860
861     if (!Name)
862     {
863         printf ("ACPI and PNP Device/Hardware IDs:\n\n");
864         for (Info = AslDeviceIds; Info->Name; Info++)
865         {
866             printf ("%8s   %s\n", Info->Name, Info->Description);
867         }
868
869         return;
870     }
871
872     Length = strlen (Name);
873     if (Length > 8)
874     {
875         printf ("%.8s: Hardware ID must be 8 characters maximum\n", Name);
876         return;
877     }
878
879     /* Find/display all names that match the input name prefix */
880
881     AcpiUtStrupr (Name);
882     for (Info = AslDeviceIds; Info->Name; Info++)
883     {
884         Matched = TRUE;
885         for (i = 0; i < Length; i++)
886         {
887             if (Info->Name[i] != Name[i])
888             {
889                 Matched = FALSE;
890                 break;
891             }
892         }
893
894         if (Matched)
895         {
896             Found = TRUE;
897             printf ("%8s   %s\n", Info->Name, Info->Description);
898         }
899     }
900
901     if (!Found)
902     {
903         printf ("%s, Hardware ID not found\n", Name);
904     }
905 }
906
907
908 /*******************************************************************************
909  *
910  * FUNCTION:    AhDisplayUuids
911  *
912  * PARAMETERS:  None
913  *
914  * RETURN:      None
915  *
916  * DESCRIPTION: Display all known UUIDs.
917  *
918  ******************************************************************************/
919
920 void
921 AhDisplayUuids (
922     void)
923 {
924     const AH_UUID           *Info;
925
926
927     printf ("ACPI-related UUIDs/GUIDs:\n");
928
929     /* Display entire table of known ACPI-related UUIDs/GUIDs */
930
931     for (Info = AcpiUuids; Info->Description; Info++)
932     {
933         if (!Info->String) /* Null UUID string means group description */
934         {
935             printf ("\n%36s\n", Info->Description);
936         }
937         else
938         {
939             printf ("%32s : %s\n", Info->Description, Info->String);
940         }
941     }
942
943     /* Help info on how UUIDs/GUIDs strings are encoded */
944
945     printf ("\n\nByte encoding of UUID/GUID strings"
946         " into ACPI Buffer objects (use ToUUID from ASL):\n\n");
947
948     printf ("%32s : %s\n", "Input UUID/GUID String format",
949         "aabbccdd-eeff-gghh-iijj-kkllmmnnoopp");
950
951     printf ("%32s : %s\n", "Expected output ACPI buffer",
952         "dd,cc,bb,aa, ff,ee, hh,gg, ii,jj, kk,ll,mm,nn,oo,pp");
953 }
954
955
956 /*******************************************************************************
957  *
958  * FUNCTION:    AhDisplayTables
959  *
960  * PARAMETERS:  None
961  *
962  * RETURN:      None
963  *
964  * DESCRIPTION: Display all known ACPI tables
965  *
966  ******************************************************************************/
967
968 void
969 AhDisplayTables (
970     void)
971 {
972     const AH_TABLE          *Info;
973     UINT32                  i = 0;
974
975
976     printf ("Known ACPI tables:\n");
977
978     for (Info = AcpiSupportedTables; Info->Signature; Info++)
979     {
980         printf ("%8s : %s\n", Info->Signature, Info->Description);
981         i++;
982     }
983
984     printf ("\nTotal %u ACPI tables\n\n", i);
985 }
986
987
988 /*******************************************************************************
989  *
990  * FUNCTION:    AhDecodeException
991  *
992  * PARAMETERS:  HexString           - ACPI status string from command line, in
993  *                                    hex. If null, display all exceptions.
994  *
995  * RETURN:      None
996  *
997  * DESCRIPTION: Decode and display an ACPI_STATUS exception code.
998  *
999  ******************************************************************************/
1000
1001 void
1002 AhDecodeException (
1003     char                    *HexString)
1004 {
1005     const ACPI_EXCEPTION_INFO   *ExceptionInfo;
1006     UINT32                      Status;
1007     UINT32                      i;
1008
1009
1010     /*
1011      * A null input string means to decode and display all known
1012      * exception codes.
1013      */
1014     if (!HexString)
1015     {
1016         printf ("All defined ACPICA exception codes:\n\n");
1017         AH_DISPLAY_EXCEPTION (0, "AE_OK                        (No error occurred)");
1018
1019         /* Display codes in each block of exception types */
1020
1021         for (i = 1; (i & AE_CODE_MASK) <= AE_CODE_MAX; i += 0x1000)
1022         {
1023             Status = i;
1024             do
1025             {
1026                 ExceptionInfo = AcpiUtValidateException ((ACPI_STATUS) Status);
1027                 if (ExceptionInfo)
1028                 {
1029                     AH_DISPLAY_EXCEPTION_TEXT (Status, ExceptionInfo);
1030                 }
1031                 Status++;
1032
1033             } while (ExceptionInfo);
1034         }
1035         return;
1036     }
1037
1038     /* Decode a single user-supplied exception code */
1039
1040     Status = strtoul (HexString, NULL, 16);
1041     if (!Status)
1042     {
1043         printf ("%s: Invalid hexadecimal exception code value\n", HexString);
1044         return;
1045     }
1046
1047     if (Status > ACPI_UINT16_MAX)
1048     {
1049         AH_DISPLAY_EXCEPTION (Status, "Invalid exception code (more than 16 bits)");
1050         return;
1051     }
1052
1053     ExceptionInfo = AcpiUtValidateException ((ACPI_STATUS) Status);
1054     if (!ExceptionInfo)
1055     {
1056         AH_DISPLAY_EXCEPTION (Status, "Unknown exception code");
1057         return;
1058     }
1059
1060     AH_DISPLAY_EXCEPTION_TEXT (Status, ExceptionInfo);
1061 }