OSDN Git Service

klibc基本機能実装. ACPICAの準備
[vaneos/DivergeMirror.git] / drivers / acpi / tools / acpihelp / ahdecode.c
1 /******************************************************************************
2  *
3  * Module Name: ahdecode - Operator/Opcode decoding for acpihelp utility
4  *
5  *****************************************************************************/
6
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2015, Intel Corp.
12  * All rights reserved.
13  *
14  * 2. License
15  *
16  * 2.1. This is your license from Intel Corp. under its intellectual property
17  * rights. You may have additional license terms from the party that provided
18  * you this software, covering your right to use that party's intellectual
19  * property rights.
20  *
21  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22  * copy of the source code appearing in this file ("Covered Code") an
23  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24  * base code distributed originally by Intel ("Original Intel Code") to copy,
25  * make derivatives, distribute, use and display any portion of the Covered
26  * Code in any form, with the right to sublicense such rights; and
27  *
28  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29  * license (with the right to sublicense), under only those claims of Intel
30  * patents that are infringed by the Original Intel Code, to make, use, sell,
31  * offer to sell, and import the Covered Code and derivative works thereof
32  * solely to the minimum extent necessary to exercise the above copyright
33  * license, and in no event shall the patent license extend to any additions
34  * to or modifications of the Original Intel Code. No other license or right
35  * is granted directly or by implication, estoppel or otherwise;
36  *
37  * The above copyright and patent license is granted only if the following
38  * conditions are met:
39  *
40  * 3. Conditions
41  *
42  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43  * Redistribution of source code of any substantial portion of the Covered
44  * Code or modification with rights to further distribute source must include
45  * the above Copyright Notice, the above License, this list of Conditions,
46  * and the following Disclaimer and Export Compliance provision. In addition,
47  * Licensee must cause all Covered Code to which Licensee contributes to
48  * contain a file documenting the changes Licensee made to create that Covered
49  * Code and the date of any change. Licensee must include in that file the
50  * documentation of any changes made by any predecessor Licensee. Licensee
51  * must include a prominent statement that the modification is derived,
52  * directly or indirectly, from Original Intel Code.
53  *
54  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55  * Redistribution of source code of any substantial portion of the Covered
56  * Code or modification without rights to further distribute source must
57  * include the following Disclaimer and Export Compliance provision in the
58  * documentation and/or other materials provided with distribution. In
59  * addition, Licensee may not authorize further sublicense of source of any
60  * portion of the Covered Code, and must include terms to the effect that the
61  * license from Licensee to its licensee is limited to the intellectual
62  * property embodied in the software Licensee provides to its licensee, and
63  * not to intellectual property embodied in modifications its licensee may
64  * make.
65  *
66  * 3.3. Redistribution of Executable. Redistribution in executable form of any
67  * substantial portion of the Covered Code or modification must reproduce the
68  * above Copyright Notice, and the following Disclaimer and Export Compliance
69  * provision in the documentation and/or other materials provided with the
70  * distribution.
71  *
72  * 3.4. Intel retains all right, title, and interest in and to the Original
73  * Intel Code.
74  *
75  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76  * Intel shall be used in advertising or otherwise to promote the sale, use or
77  * other dealings in products derived from or relating to the Covered Code
78  * without prior written authorization from Intel.
79  *
80  * 4. Disclaimer and Export Compliance
81  *
82  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88  * PARTICULAR PURPOSE.
89  *
90  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97  * LIMITED REMEDY.
98  *
99  * 4.3. Licensee shall not export, either directly or indirectly, any of this
100  * software or system incorporating such software without first obtaining any
101  * required license or other approval from the U. S. Department of Commerce or
102  * any other agency or department of the United States Government. In the
103  * event Licensee exports any such software from the United States or
104  * re-exports any such software from a foreign destination, Licensee shall
105  * ensure that the distribution and export/re-export of the software is in
106  * compliance with all laws, regulations, orders, or other restrictions of the
107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108  * any of its subsidiaries will export/re-export any technical data, process,
109  * software, or service, directly or indirectly, to any country for which the
110  * United States government or any agency thereof requires an export license,
111  * other governmental approval, or letter of assurance, without first obtaining
112  * such license, approval or letter.
113  *
114  *****************************************************************************/
115
116 #define ACPI_CREATE_PREDEFINED_TABLE
117 #define ACPI_CREATE_RESOURCE_TABLE
118
119 #include "acpihelp.h"
120 #include "acpredef.h"
121
122
123 #define AH_DISPLAY_EXCEPTION(Status, Name) \
124     printf ("%.4X: %s\n", Status, Name)
125
126 #define AH_DISPLAY_EXCEPTION_TEXT(Status, Exception) \
127     printf ("%.4X: %-28s (%s)\n", Status, Exception->Name, Exception->Description)
128
129 #define BUFFER_LENGTH           128
130 #define LINE_BUFFER_LENGTH      512
131
132 static char         Gbl_Buffer[BUFFER_LENGTH];
133 static char         Gbl_LineBuffer[LINE_BUFFER_LENGTH];
134
135
136 /* Local prototypes */
137
138 static BOOLEAN
139 AhDisplayPredefinedName (
140     char                    *Name,
141     UINT32                  Length);
142
143 static void
144 AhDisplayPredefinedInfo (
145     char                    *Name);
146
147 static void
148 AhDisplayResourceName (
149     const ACPI_PREDEFINED_INFO  *ThisName);
150
151 static void
152 AhDisplayAmlOpcode (
153     const AH_AML_OPCODE     *Op);
154
155 static void
156 AhDisplayAslOperator (
157     const AH_ASL_OPERATOR   *Op);
158
159 static void
160 AhDisplayOperatorKeywords (
161     const AH_ASL_OPERATOR   *Op);
162
163 static void
164 AhDisplayAslKeyword (
165     const AH_ASL_KEYWORD    *Op);
166
167 static void
168 AhPrintOneField (
169     UINT32                  Indent,
170     UINT32                  CurrentPosition,
171     UINT32                  MaxPosition,
172     const char              *Field);
173
174
175 void
176 AhDisplayDirectives (
177     void)
178 {
179     const AH_DIRECTIVE_INFO *Info;
180
181
182     printf ("iASL Preprocessor directives:\n\n");
183
184     for (Info = PreprocessorDirectives; Info->Name; Info++)
185     {
186         printf ("%16s : %s\n", Info->Name, Info->Operands);
187     }
188 }
189
190
191 /*******************************************************************************
192  *
193  * FUNCTION:    AhFindPredefinedNames (entry point for predefined name search)
194  *
195  * PARAMETERS:  NamePrefix          - Name or prefix to find. Must start with
196  *                                    an underscore. NULL means "find all"
197  *
198  * RETURN:      None
199  *
200  * DESCRIPTION: Find and display all ACPI predefined names that match the
201  *              input name or prefix. Includes the required number of arguments
202  *              and the expected return type, if any.
203  *
204  ******************************************************************************/
205
206 void
207 AhFindPredefinedNames (
208     char                    *NamePrefix)
209 {
210     UINT32                  Length;
211     BOOLEAN                 Found;
212     char                    Name[9];
213
214
215     if (!NamePrefix)
216     {
217         Found = AhDisplayPredefinedName (NULL, 0);
218         return;
219     }
220
221     /* Contruct a local name or name prefix */
222
223     AhStrupr (NamePrefix);
224     if (*NamePrefix == '_')
225     {
226         NamePrefix++;
227     }
228
229     Name[0] = '_';
230     strncpy (&Name[1], NamePrefix, 7);
231
232     Length = strlen (Name);
233     if (Length > 4)
234     {
235         printf ("%.8s: Predefined name must be 4 characters maximum\n", Name);
236         return;
237     }
238
239     Found = AhDisplayPredefinedName (Name, Length);
240     if (!Found)
241     {
242         printf ("%s, no matching predefined names\n", Name);
243     }
244 }
245
246
247 /*******************************************************************************
248  *
249  * FUNCTION:    AhDisplayPredefinedName
250  *
251  * PARAMETERS:  Name                - Name or name prefix
252  *
253  * RETURN:      TRUE if any names matched, FALSE otherwise
254  *
255  * DESCRIPTION: Display information about ACPI predefined names that match
256  *              the input name or name prefix.
257  *
258  ******************************************************************************/
259
260 static BOOLEAN
261 AhDisplayPredefinedName (
262     char                    *Name,
263     UINT32                  Length)
264 {
265     const AH_PREDEFINED_NAME    *Info;
266     BOOLEAN                     Found = FALSE;
267     BOOLEAN                     Matched;
268     UINT32                      i = 0;
269
270
271     /* Find/display all names that match the input name prefix */
272
273     for (Info = AslPredefinedInfo; Info->Name; Info++)
274     {
275         if (!Name)
276         {
277             Found = TRUE;
278             printf ("%s: <%s>\n", Info->Name, Info->Description);
279             printf ("%*s%s\n", 6, " ", Info->Action);
280
281             AhDisplayPredefinedInfo (Info->Name);
282             i++;
283             continue;
284         }
285
286         Matched = TRUE;
287         for (i = 0; i < Length; i++)
288         {
289             if (Info->Name[i] != Name[i])
290             {
291                 Matched = FALSE;
292                 break;
293             }
294         }
295
296         if (Matched)
297         {
298             Found = TRUE;
299             printf ("%s: <%s>\n", Info->Name, Info->Description);
300             printf ("%*s%s\n", 6, " ", Info->Action);
301
302             AhDisplayPredefinedInfo (Info->Name);
303         }
304     }
305
306     if (!Name)
307     {
308         printf ("\nFound %d Predefined ACPI Names\n", i);
309     }
310     return (Found);
311 }
312
313
314 /*******************************************************************************
315  *
316  * FUNCTION:    AhDisplayPredefinedInfo
317  *
318  * PARAMETERS:  Name                - Exact 4-character ACPI name.
319  *
320  * RETURN:      None
321  *
322  * DESCRIPTION: Find the name in the main ACPICA predefined info table and
323  *              display the # of arguments and the return value type.
324  *
325  *              Note: Resource Descriptor field names do not appear in this
326  *              table -- thus, nothing will be displayed for them.
327  *
328  ******************************************************************************/
329
330 static void
331 AhDisplayPredefinedInfo (
332     char                        *Name)
333 {
334     const ACPI_PREDEFINED_INFO  *ThisName;
335
336
337     /* NOTE: we check both tables always because there are some dupes */
338
339     /* Check against the predefine methods first */
340
341     ThisName = AcpiUtMatchPredefinedMethod (Name);
342     if (ThisName)
343     {
344         AcpiUtDisplayPredefinedMethod (Gbl_Buffer, ThisName, TRUE);
345     }
346
347     /* Check against the predefined resource descriptor names */
348
349     ThisName = AcpiUtMatchResourceName (Name);
350     if (ThisName)
351     {
352         AhDisplayResourceName (ThisName);
353     }
354 }
355
356
357 /*******************************************************************************
358  *
359  * FUNCTION:    AhDisplayResourceName
360  *
361  * PARAMETERS:  ThisName            - Entry in the predefined method/name table
362  *
363  * RETURN:      None
364  *
365  * DESCRIPTION: Display information about a resource descriptor name.
366  *
367  ******************************************************************************/
368
369 static void
370 AhDisplayResourceName (
371     const ACPI_PREDEFINED_INFO  *ThisName)
372 {
373     UINT32                      NumTypes;
374
375
376     NumTypes = AcpiUtGetResourceBitWidth (Gbl_Buffer,
377         ThisName->Info.ArgumentList);
378
379     printf ("      %4.4s resource descriptor field is %s bits wide%s\n",
380         ThisName->Info.Name,
381         Gbl_Buffer,
382         (NumTypes > 1) ? " (depending on descriptor type)" : "");
383 }
384
385
386 /*******************************************************************************
387  *
388  * FUNCTION:    AhFindAmlOpcode (entry point for AML opcode name search)
389  *
390  * PARAMETERS:  Name                - Name or prefix for an AML opcode.
391  *                                    NULL means "find all"
392  *
393  * RETURN:      None
394  *
395  * DESCRIPTION: Find all AML opcodes that match the input Name or name
396  *              prefix.
397  *
398  ******************************************************************************/
399
400 void
401 AhFindAmlOpcode (
402     char                    *Name)
403 {
404     const AH_AML_OPCODE     *Op;
405     BOOLEAN                 Found = FALSE;
406
407
408     AhStrupr (Name);
409
410     /* Find/display all opcode names that match the input name prefix */
411
412     for (Op = AmlOpcodeInfo; Op->OpcodeString; Op++)
413     {
414         if (!Op->OpcodeName) /* Unused opcodes */
415         {
416             continue;
417         }
418
419         if (!Name)
420         {
421             AhDisplayAmlOpcode (Op);
422             Found = TRUE;
423             continue;
424         }
425
426         /* Upper case the opcode name before substring compare */
427
428         strcpy (Gbl_Buffer, Op->OpcodeName);
429         AhStrupr (Gbl_Buffer);
430
431         if (strstr (Gbl_Buffer, Name) == Gbl_Buffer)
432         {
433             AhDisplayAmlOpcode (Op);
434             Found = TRUE;
435         }
436     }
437
438     if (!Found)
439     {
440         printf ("%s, no matching AML operators\n", Name);
441     }
442 }
443
444
445 /*******************************************************************************
446  *
447  * FUNCTION:    AhDecodeAmlOpcode (entry point for AML opcode search)
448  *
449  * PARAMETERS:  OpcodeString        - String version of AML opcode
450  *
451  * RETURN:      None
452  *
453  * DESCRIPTION: Display information about the input AML opcode
454  *
455  ******************************************************************************/
456
457 void
458 AhDecodeAmlOpcode (
459     char                    *OpcodeString)
460 {
461     const AH_AML_OPCODE     *Op;
462     UINT32                  Opcode;
463     UINT8                   Prefix;
464
465
466     if (!OpcodeString)
467     {
468         AhFindAmlOpcode (NULL);
469         return;
470     }
471
472     Opcode = ACPI_STRTOUL (OpcodeString, NULL, 16);
473     if (Opcode > ACPI_UINT16_MAX)
474     {
475         printf ("Invalid opcode (more than 16 bits)\n");
476         return;
477     }
478
479     /* Only valid opcode extension is 0x5B */
480
481     Prefix = (Opcode & 0x0000FF00) >> 8;
482     if (Prefix && (Prefix != 0x5B))
483     {
484         printf ("Invalid opcode (invalid extension prefix 0x%X)\n",
485             Prefix);
486         return;
487     }
488
489     /* Find/Display the opcode. May fall within an opcode range */
490
491     for (Op = AmlOpcodeInfo; Op->OpcodeString; Op++)
492     {
493         if ((Opcode >= Op->OpcodeRangeStart) &&
494             (Opcode <= Op->OpcodeRangeEnd))
495         {
496             AhDisplayAmlOpcode (Op);
497         }
498     }
499 }
500
501
502 /*******************************************************************************
503  *
504  * FUNCTION:    AhDisplayAmlOpcode
505  *
506  * PARAMETERS:  Op                  - An opcode info struct
507  *
508  * RETURN:      None
509  *
510  * DESCRIPTION: Display the contents of an AML opcode information struct
511  *
512  ******************************************************************************/
513
514 static void
515 AhDisplayAmlOpcode (
516     const AH_AML_OPCODE     *Op)
517 {
518
519     if (!Op->OpcodeName)
520     {
521         printf ("%18s: Opcode=%-9s\n", "Reserved opcode", Op->OpcodeString);
522         return;
523     }
524
525     /* Opcode name and value(s) */
526
527     printf ("%18s: Opcode=%-9s Type (%s)",
528         Op->OpcodeName, Op->OpcodeString, Op->Type);
529
530     /* Optional fixed/static arguments */
531
532     if (Op->FixedArguments)
533     {
534         printf (" FixedArgs (");
535         AhPrintOneField (37, 36 + 7 + strlen (Op->Type) + 12,
536             AH_MAX_AML_LINE_LENGTH, Op->FixedArguments);
537         printf (")");
538     }
539
540     /* Optional variable-length argument list */
541
542     if (Op->VariableArguments)
543     {
544         if (Op->FixedArguments)
545         {
546             printf ("\n%*s", 36, " ");
547         }
548         printf (" VariableArgs (");
549         AhPrintOneField (37, 15, AH_MAX_AML_LINE_LENGTH, Op->VariableArguments);
550         printf (")");
551     }
552     printf ("\n");
553
554     /* Grammar specification */
555
556     if (Op->Grammar)
557     {
558         AhPrintOneField (37, 0, AH_MAX_AML_LINE_LENGTH, Op->Grammar);
559         printf ("\n");
560     }
561 }
562
563
564 /*******************************************************************************
565  *
566  * FUNCTION:    AhFindAslKeywords (entry point for ASL keyword search)
567  *
568  * PARAMETERS:  Name                - Name or prefix for an ASL keyword.
569  *                                    NULL means "find all"
570  *
571  * RETURN:      None
572  *
573  * DESCRIPTION: Find all ASL keywords that match the input Name or name
574  *              prefix.
575  *
576  ******************************************************************************/
577
578 void
579 AhFindAslKeywords (
580     char                    *Name)
581 {
582     const AH_ASL_KEYWORD    *Keyword;
583     BOOLEAN                 Found = FALSE;
584
585
586     AhStrupr (Name);
587
588     for (Keyword = AslKeywordInfo; Keyword->Name; Keyword++)
589     {
590         if (!Name)
591         {
592             AhDisplayAslKeyword (Keyword);
593             Found = TRUE;
594             continue;
595         }
596
597         /* Upper case the operator name before substring compare */
598
599         strcpy (Gbl_Buffer, Keyword->Name);
600         AhStrupr (Gbl_Buffer);
601
602         if (strstr (Gbl_Buffer, Name) == Gbl_Buffer)
603         {
604             AhDisplayAslKeyword (Keyword);
605             Found = TRUE;
606         }
607     }
608
609     if (!Found)
610     {
611         printf ("%s, no matching ASL keywords\n", Name);
612     }
613 }
614
615
616 /*******************************************************************************
617  *
618  * FUNCTION:    AhDisplayAslKeyword
619  *
620  * PARAMETERS:  Op                  - Pointer to ASL keyword with syntax info
621  *
622  * RETURN:      None
623  *
624  * DESCRIPTION: Format and display syntax info for an ASL keyword. Splits
625  *              long lines appropriately for reading.
626  *
627  ******************************************************************************/
628
629 static void
630 AhDisplayAslKeyword (
631     const AH_ASL_KEYWORD    *Op)
632 {
633
634     /* ASL keyword name and description */
635
636     printf ("%22s: %s\n", Op->Name, Op->Description);
637     if (!Op->KeywordList)
638     {
639         return;
640     }
641
642     /* List of actual keywords */
643
644     AhPrintOneField (24, 0, AH_MAX_ASL_LINE_LENGTH, Op->KeywordList);
645     printf ("\n");
646 }
647
648
649 /*******************************************************************************
650  *
651  * FUNCTION:    AhFindAslAndAmlOperators
652  *
653  * PARAMETERS:  Name                - Name or prefix for an ASL operator.
654  *                                    NULL means "find all"
655  *
656  * RETURN:      None
657  *
658  * DESCRIPTION: Find all ASL operators that match the input Name or name
659  *              prefix. Also displays the AML information if only one entry
660  *              matches.
661  *
662  ******************************************************************************/
663
664 void
665 AhFindAslAndAmlOperators (
666     char                    *Name)
667 {
668     UINT32                  MatchCount;
669
670
671     MatchCount = AhFindAslOperators (Name);
672     if (MatchCount == 1)
673     {
674         AhFindAmlOpcode (Name);
675     }
676 }
677
678
679 /*******************************************************************************
680  *
681  * FUNCTION:    AhFindAslOperators (entry point for ASL operator search)
682  *
683  * PARAMETERS:  Name                - Name or prefix for an ASL operator.
684  *                                    NULL means "find all"
685  *
686  * RETURN:      Number of operators that matched the name prefix.
687  *
688  * DESCRIPTION: Find all ASL operators that match the input Name or name
689  *              prefix.
690  *
691  ******************************************************************************/
692
693 UINT32
694 AhFindAslOperators (
695     char                    *Name)
696 {
697     const AH_ASL_OPERATOR   *Operator;
698     BOOLEAN                 MatchCount = 0;
699
700
701     AhStrupr (Name);
702
703     /* Find/display all names that match the input name prefix */
704
705     for (Operator = AslOperatorInfo; Operator->Name; Operator++)
706     {
707         if (!Name)
708         {
709             AhDisplayAslOperator (Operator);
710             MatchCount++;
711             continue;
712         }
713
714         /* Upper case the operator name before substring compare */
715
716         strcpy (Gbl_Buffer, Operator->Name);
717         AhStrupr (Gbl_Buffer);
718
719         if (strstr (Gbl_Buffer, Name) == Gbl_Buffer)
720         {
721             AhDisplayAslOperator (Operator);
722             MatchCount++;
723         }
724     }
725
726     if (!MatchCount)
727     {
728         printf ("%s, no matching ASL operators\n", Name);
729     }
730
731     return (MatchCount);
732 }
733
734
735 /*******************************************************************************
736  *
737  * FUNCTION:    AhDisplayAslOperator
738  *
739  * PARAMETERS:  Op                  - Pointer to ASL operator with syntax info
740  *
741  * RETURN:      None
742  *
743  * DESCRIPTION: Format and display syntax info for an ASL operator. Splits
744  *              long lines appropriately for reading.
745  *
746  ******************************************************************************/
747
748 static void
749 AhDisplayAslOperator (
750     const AH_ASL_OPERATOR   *Op)
751 {
752
753     /* ASL operator name and description */
754
755     printf ("%16s: %s\n", Op->Name, Op->Description);
756     if (!Op->Syntax)
757     {
758         return;
759     }
760
761     /* Syntax for the operator */
762
763     AhPrintOneField (18, 0, AH_MAX_ASL_LINE_LENGTH, Op->Syntax);
764     printf ("\n");
765
766     AhDisplayOperatorKeywords (Op);
767     printf ("\n");
768 }
769
770
771 /*******************************************************************************
772  *
773  * FUNCTION:    AhDisplayOperatorKeywords
774  *
775  * PARAMETERS:  Op                  - Pointer to ASL keyword with syntax info
776  *
777  * RETURN:      None
778  *
779  * DESCRIPTION: Display any/all keywords that are associated with the ASL
780  *              operator.
781  *
782  ******************************************************************************/
783
784 static void
785 AhDisplayOperatorKeywords (
786     const AH_ASL_OPERATOR   *Op)
787 {
788     char                    *Token;
789     char                    *Separators = "(){}, ";
790     BOOLEAN                 FirstKeyword = TRUE;
791
792
793     if (!Op || !Op->Syntax)
794     {
795         return;
796     }
797
798     /*
799      * Find all parameters that have the word "keyword" within, and then
800      * display the info about that keyword
801      */
802     strcpy (Gbl_LineBuffer, Op->Syntax);
803     Token = strtok (Gbl_LineBuffer, Separators);
804     while (Token)
805     {
806         if (strstr (Token, "Keyword"))
807         {
808             if (FirstKeyword)
809             {
810                 printf ("\n");
811                 FirstKeyword = FALSE;
812             }
813
814             /* Found a keyword, display keyword information */
815
816             AhFindAslKeywords (Token);
817         }
818
819         Token = strtok (NULL, Separators);
820     }
821 }
822
823
824 /*******************************************************************************
825  *
826  * FUNCTION:    AhPrintOneField
827  *
828  * PARAMETERS:  Indent              - Indent length for new line(s)
829  *              CurrentPosition     - Position on current line
830  *              MaxPosition         - Max allowed line length
831  *              Field               - Data to output
832  *
833  * RETURN:      Line position after field is written
834  *
835  * DESCRIPTION: Split long lines appropriately for ease of reading.
836  *
837  ******************************************************************************/
838
839 static void
840 AhPrintOneField (
841     UINT32                  Indent,
842     UINT32                  CurrentPosition,
843     UINT32                  MaxPosition,
844     const char              *Field)
845 {
846     UINT32                  Position;
847     UINT32                  TokenLength;
848     const char              *This;
849     const char              *Next;
850     const char              *Last;
851
852
853     This = Field;
854     Position = CurrentPosition;
855
856     if (Position == 0)
857     {
858         printf ("%*s", (int) Indent, " ");
859         Position = Indent;
860     }
861
862     Last = This + strlen (This);
863     while ((Next = strpbrk (This, " ")))
864     {
865         TokenLength = Next - This;
866         Position += TokenLength;
867
868         /* Split long lines */
869
870         if (Position > MaxPosition)
871         {
872             printf ("\n%*s", (int) Indent, " ");
873             Position = TokenLength;
874         }
875
876         printf ("%.*s ", (int) TokenLength, This);
877         This = Next + 1;
878     }
879
880     /* Handle last token on the input line */
881
882     TokenLength = Last - This;
883     if (TokenLength > 0)
884     {
885         Position += TokenLength;
886         if (Position > MaxPosition)
887         {
888             printf ("\n%*s", (int) Indent, " ");
889         }
890         printf ("%s", This);
891     }
892 }
893
894
895 /*******************************************************************************
896  *
897  * FUNCTION:    AhDisplayDeviceIds
898  *
899  * PARAMETERS:  Name                - Device Hardware ID string.
900  *                                    NULL means "find all"
901  *
902  * RETURN:      None
903  *
904  * DESCRIPTION: Display PNP* and ACPI* device IDs.
905  *
906  ******************************************************************************/
907
908 void
909 AhDisplayDeviceIds (
910     char                    *Name)
911 {
912     const AH_DEVICE_ID      *Info;
913     UINT32                  Length;
914     BOOLEAN                 Matched;
915     UINT32                  i;
916     BOOLEAN                 Found = FALSE;
917
918
919     /* Null input name indicates "display all" */
920
921     if (!Name)
922     {
923         printf ("ACPI and PNP Device/Hardware IDs:\n\n");
924         for (Info = AslDeviceIds; Info->Name; Info++)
925         {
926             printf ("%8s   %s\n", Info->Name, Info->Description);
927         }
928
929         return;
930     }
931
932     Length = strlen (Name);
933     if (Length > 8)
934     {
935         printf ("%.8s: Hardware ID must be 8 characters maximum\n", Name);
936         return;
937     }
938
939     /* Find/display all names that match the input name prefix */
940
941     AhStrupr (Name);
942     for (Info = AslDeviceIds; Info->Name; Info++)
943     {
944         Matched = TRUE;
945         for (i = 0; i < Length; i++)
946         {
947             if (Info->Name[i] != Name[i])
948             {
949                 Matched = FALSE;
950                 break;
951             }
952         }
953
954         if (Matched)
955         {
956             Found = TRUE;
957             printf ("%8s   %s\n", Info->Name, Info->Description);
958         }
959     }
960
961     if (!Found)
962     {
963         printf ("%s, Hardware ID not found\n", Name);
964     }
965 }
966
967
968 /*******************************************************************************
969  *
970  * FUNCTION:    AhDisplayUuids
971  *
972  * PARAMETERS:  None
973  *
974  * RETURN:      None
975  *
976  * DESCRIPTION: Display all known UUIDs.
977  *
978  ******************************************************************************/
979
980 void
981 AhDisplayUuids (
982     void)
983 {
984     const AH_UUID           *Info;
985
986
987     printf ("ACPI-related UUIDs:\n\n");
988
989     for (Info = AcpiUuids; Info->Description; Info++)
990     {
991         printf ("%32s : %s\n", Info->Description, Info->String);
992     }
993 }
994
995
996 /*******************************************************************************
997  *
998  * FUNCTION:    AhDisplayTables
999  *
1000  * PARAMETERS:  None
1001  *
1002  * RETURN:      None
1003  *
1004  * DESCRIPTION: Display all known ACPI tables
1005  *
1006  ******************************************************************************/
1007
1008 void
1009 AhDisplayTables (
1010     void)
1011 {
1012     const AH_TABLE          *Info;
1013     UINT32                  i = 0;
1014
1015
1016     printf ("Known ACPI tables:\n");
1017
1018     for (Info = AcpiSupportedTables; Info->Signature; Info++)
1019     {
1020         printf ("%8s : %s\n", Info->Signature, Info->Description);
1021         i++;
1022     }
1023
1024     printf ("\nTotal %u ACPI tables\n\n", i);
1025 }
1026
1027
1028 /*******************************************************************************
1029  *
1030  * FUNCTION:    AhDecodeException
1031  *
1032  * PARAMETERS:  HexString           - ACPI status string from command line, in
1033  *                                    hex. If null, display all exceptions.
1034  *
1035  * RETURN:      None
1036  *
1037  * DESCRIPTION: Decode and display an ACPI_STATUS exception code.
1038  *
1039  ******************************************************************************/
1040
1041 void
1042 AhDecodeException (
1043     char                    *HexString)
1044 {
1045     const ACPI_EXCEPTION_INFO   *ExceptionInfo;
1046     UINT32                      Status;
1047     UINT32                      i;
1048
1049
1050     /*
1051      * A null input string means to decode and display all known
1052      * exception codes.
1053      */
1054     if (!HexString)
1055     {
1056         printf ("All defined ACPICA exception codes:\n\n");
1057         AH_DISPLAY_EXCEPTION (0, "AE_OK                        (No error occurred)");
1058
1059         /* Display codes in each block of exception types */
1060
1061         for (i = 1; (i & AE_CODE_MASK) <= AE_CODE_MAX; i += 0x1000)
1062         {
1063             Status = i;
1064             do
1065             {
1066                 ExceptionInfo = AcpiUtValidateException ((ACPI_STATUS) Status);
1067                 if (ExceptionInfo)
1068                 {
1069                     AH_DISPLAY_EXCEPTION_TEXT (Status, ExceptionInfo);
1070                 }
1071                 Status++;
1072
1073             } while (ExceptionInfo);
1074         }
1075         return;
1076     }
1077
1078     /* Decode a single user-supplied exception code */
1079
1080     Status = ACPI_STRTOUL (HexString, NULL, 16);
1081     if (!Status)
1082     {
1083         printf ("%s: Invalid hexadecimal exception code value\n", HexString);
1084         return;
1085     }
1086
1087     if (Status > ACPI_UINT16_MAX)
1088     {
1089         AH_DISPLAY_EXCEPTION (Status, "Invalid exception code (more than 16 bits)");
1090         return;
1091     }
1092
1093     ExceptionInfo = AcpiUtValidateException ((ACPI_STATUS) Status);
1094     if (!ExceptionInfo)
1095     {
1096         AH_DISPLAY_EXCEPTION (Status, "Unknown exception code");
1097         return;
1098     }
1099
1100     AH_DISPLAY_EXCEPTION_TEXT (Status, ExceptionInfo);
1101 }