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