1 /******************************************************************************
3 * Module Name: ahdecode - Operator/Opcode decoding for acpihelp utility
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2013, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
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.
44 #define ACPI_CREATE_PREDEFINED_TABLE
45 #define ACPI_CREATE_RESOURCE_TABLE
51 /* Device IDs defined in the ACPI specification */
53 static const AH_DEVICE_ID AhDeviceIds
[] =
55 {"PNP0A05", "Generic Container Device"},
56 {"PNP0A06", "Generic Container Device"},
57 {"PNP0C08", "ACPI core hardware"},
58 {"PNP0C09", "Embedded Controller Device"},
59 {"PNP0C0A", "Control Method Battery"},
61 {"PNP0C0C", "Power Button Device"},
62 {"PNP0C0D", "Lid Device"},
63 {"PNP0C0E", "Sleep Button Device"},
64 {"PNP0C0F", "PCI Interrupt Link Device"},
65 {"PNP0C80", "Memory Device"},
67 {"ACPI0001", "SMBus 1.0 Host Controller"},
68 {"ACPI0002", "Smart Battery Subsystem"},
69 {"ACPI0003", "Power Source Device"},
70 {"ACPI0004", "Module Device"},
71 {"ACPI0005", "SMBus 2.0 Host Controller"},
72 {"ACPI0006", "GPE Block Device"},
73 {"ACPI0007", "Processor Device"},
74 {"ACPI0008", "Ambient Light Sensor Device"},
75 {"ACPI0009", "I/O xAPIC Device"},
76 {"ACPI000A", "I/O APIC Device"},
77 {"ACPI000B", "I/O SAPIC Device"},
78 {"ACPI000C", "Processor Aggregator Device"},
79 {"ACPI000D", "Power Meter Device"},
80 {"ACPI000E", "Time/Alarm Device"},
81 {"ACPI000F", "User Presence Detection Device"},
86 #define AH_DISPLAY_EXCEPTION(Status, Name) \
87 printf ("%.4X: %s\n", Status, Name)
89 #define AH_DISPLAY_EXCEPTION_TEXT(Status, Exception) \
90 printf ("%.4X: %-28s (%s)\n", Status, Exception->Name, Exception->Description)
92 #define BUFFER_LENGTH 128
93 #define LINE_BUFFER_LENGTH 512
95 static char Gbl_Buffer
[BUFFER_LENGTH
];
96 static char Gbl_LineBuffer
[LINE_BUFFER_LENGTH
];
98 /* Local prototypes */
101 AhDisplayPredefinedName (
106 AhDisplayPredefinedInfo (
110 AhDisplayResourceName (
111 const ACPI_PREDEFINED_INFO
*ThisName
);
115 const AH_AML_OPCODE
*Op
);
118 AhDisplayAslOperator (
119 const AH_ASL_OPERATOR
*Op
);
122 AhDisplayOperatorKeywords (
123 const AH_ASL_OPERATOR
*Op
);
126 AhDisplayAslKeyword (
127 const AH_ASL_KEYWORD
*Op
);
132 UINT32 CurrentPosition
,
137 /*******************************************************************************
139 * FUNCTION: AhFindPredefinedNames (entry point for predefined name search)
141 * PARAMETERS: NamePrefix - Name or prefix to find. Must start with
142 * an underscore. NULL means "find all"
146 * DESCRIPTION: Find and display all ACPI predefined names that match the
147 * input name or prefix. Includes the required number of arguments
148 * and the expected return type, if any.
150 ******************************************************************************/
153 AhFindPredefinedNames (
163 Found
= AhDisplayPredefinedName (Name
, 0);
167 /* Contruct a local name or name prefix */
169 AhStrupr (NamePrefix
);
170 if (*NamePrefix
== '_')
176 strncpy (&Name
[1], NamePrefix
, 7);
178 Length
= strlen (Name
);
181 printf ("%.8s: Predefined name must be 4 characters maximum\n", Name
);
185 Found
= AhDisplayPredefinedName (Name
, Length
);
188 printf ("%s, no matching predefined names\n", Name
);
193 /*******************************************************************************
195 * FUNCTION: AhDisplayPredefinedName
197 * PARAMETERS: Name - Name or name prefix
199 * RETURN: TRUE if any names matched, FALSE otherwise
201 * DESCRIPTION: Display information about ACPI predefined names that match
202 * the input name or name prefix.
204 ******************************************************************************/
207 AhDisplayPredefinedName (
211 const AH_PREDEFINED_NAME
*Info
;
212 BOOLEAN Found
= FALSE
;
217 /* Find/display all names that match the input name prefix */
219 for (Info
= AslPredefinedInfo
; Info
->Name
; Info
++)
224 printf ("%s: <%s>\n", Info
->Name
, Info
->Description
);
225 printf ("%*s%s\n", 6, " ", Info
->Action
);
227 AhDisplayPredefinedInfo (Info
->Name
);
232 for (i
= 0; i
< Length
; i
++)
234 if (Info
->Name
[i
] != Name
[i
])
244 printf ("%s: <%s>\n", Info
->Name
, Info
->Description
);
245 printf ("%*s%s\n", 6, " ", Info
->Action
);
247 AhDisplayPredefinedInfo (Info
->Name
);
255 /*******************************************************************************
257 * FUNCTION: AhDisplayPredefinedInfo
259 * PARAMETERS: Name - Exact 4-character ACPI name.
263 * DESCRIPTION: Find the name in the main ACPICA predefined info table and
264 * display the # of arguments and the return value type.
266 * Note: Resource Descriptor field names do not appear in this
267 * table -- thus, nothing will be displayed for them.
269 ******************************************************************************/
272 AhDisplayPredefinedInfo (
275 const ACPI_PREDEFINED_INFO
*ThisName
;
278 /* NOTE: we check both tables always because there are some dupes */
280 /* Check against the predefine methods first */
282 ThisName
= AcpiUtMatchPredefinedMethod (Name
);
285 AcpiUtDisplayPredefinedMethod (Gbl_Buffer
, ThisName
, TRUE
);
288 /* Check against the predefined resource descriptor names */
290 ThisName
= AcpiUtMatchResourceName (Name
);
293 AhDisplayResourceName (ThisName
);
298 /*******************************************************************************
300 * FUNCTION: AhDisplayResourceName
302 * PARAMETERS: ThisName - Entry in the predefined method/name table
306 * DESCRIPTION: Display information about a resource descriptor name.
308 ******************************************************************************/
311 AhDisplayResourceName (
312 const ACPI_PREDEFINED_INFO
*ThisName
)
317 NumTypes
= AcpiUtGetResourceBitWidth (Gbl_Buffer
,
318 ThisName
->Info
.ArgumentList
);
320 printf (" %4.4s resource descriptor field is %s bits wide%s\n",
323 (NumTypes
> 1) ? " (depending on descriptor type)" : "");
327 /*******************************************************************************
329 * FUNCTION: AhFindAmlOpcode (entry point for AML opcode name search)
331 * PARAMETERS: Name - Name or prefix for an AML opcode.
332 * NULL means "find all"
336 * DESCRIPTION: Find all AML opcodes that match the input Name or name
339 ******************************************************************************/
345 const AH_AML_OPCODE
*Op
;
346 BOOLEAN Found
= FALSE
;
351 /* Find/display all opcode names that match the input name prefix */
353 for (Op
= AmlOpcodeInfo
; Op
->OpcodeString
; Op
++)
355 if (!Op
->OpcodeName
) /* Unused opcodes */
362 AhDisplayAmlOpcode (Op
);
367 /* Upper case the opcode name before substring compare */
369 strcpy (Gbl_Buffer
, Op
->OpcodeName
);
370 AhStrupr (Gbl_Buffer
);
372 if (strstr (Gbl_Buffer
, Name
) == Gbl_Buffer
)
374 AhDisplayAmlOpcode (Op
);
381 printf ("%s, no matching AML operators\n", Name
);
386 /*******************************************************************************
388 * FUNCTION: AhDecodeAmlOpcode (entry point for AML opcode search)
390 * PARAMETERS: OpcodeString - String version of AML opcode
394 * DESCRIPTION: Display information about the input AML opcode
396 ******************************************************************************/
402 const AH_AML_OPCODE
*Op
;
409 AhFindAmlOpcode (NULL
);
413 Opcode
= ACPI_STRTOUL (OpcodeString
, NULL
, 16);
414 if (Opcode
> ACPI_UINT16_MAX
)
416 printf ("Invalid opcode (more than 16 bits)\n");
420 /* Only valid opcode extension is 0x5B */
422 Prefix
= (Opcode
& 0x0000FF00) >> 8;
423 if (Prefix
&& (Prefix
!= 0x5B))
425 printf ("Invalid opcode (invalid extension prefix 0x%X)\n",
430 /* Find/Display the opcode. May fall within an opcode range */
432 for (Op
= AmlOpcodeInfo
; Op
->OpcodeString
; Op
++)
434 if ((Opcode
>= Op
->OpcodeRangeStart
) &&
435 (Opcode
<= Op
->OpcodeRangeEnd
))
437 AhDisplayAmlOpcode (Op
);
443 /*******************************************************************************
445 * FUNCTION: AhDisplayAmlOpcode
447 * PARAMETERS: Op - An opcode info struct
451 * DESCRIPTION: Display the contents of an AML opcode information struct
453 ******************************************************************************/
457 const AH_AML_OPCODE
*Op
)
462 printf ("%18s: Opcode=%-9s\n", "Reserved opcode", Op
->OpcodeString
);
466 /* Opcode name and value(s) */
468 printf ("%18s: Opcode=%-9s Type (%s)",
469 Op
->OpcodeName
, Op
->OpcodeString
, Op
->Type
);
471 /* Optional fixed/static arguments */
473 if (Op
->FixedArguments
)
475 printf (" FixedArgs (");
476 AhPrintOneField (37, 36 + 7 + strlen (Op
->Type
) + 12,
477 AH_MAX_AML_LINE_LENGTH
, Op
->FixedArguments
);
481 /* Optional variable-length argument list */
483 if (Op
->VariableArguments
)
485 if (Op
->FixedArguments
)
487 printf ("\n%*s", 36, " ");
489 printf (" VariableArgs (");
490 AhPrintOneField (37, 15, AH_MAX_AML_LINE_LENGTH
, Op
->VariableArguments
);
495 /* Grammar specification */
499 AhPrintOneField (37, 0, AH_MAX_AML_LINE_LENGTH
, Op
->Grammar
);
505 /*******************************************************************************
507 * FUNCTION: AhFindAslKeywords (entry point for ASL keyword search)
509 * PARAMETERS: Name - Name or prefix for an ASL keyword.
510 * NULL means "find all"
514 * DESCRIPTION: Find all ASL keywords that match the input Name or name
517 ******************************************************************************/
523 const AH_ASL_KEYWORD
*Keyword
;
524 BOOLEAN Found
= FALSE
;
529 for (Keyword
= AslKeywordInfo
; Keyword
->Name
; Keyword
++)
533 AhDisplayAslKeyword (Keyword
);
538 /* Upper case the operator name before substring compare */
540 strcpy (Gbl_Buffer
, Keyword
->Name
);
541 AhStrupr (Gbl_Buffer
);
543 if (strstr (Gbl_Buffer
, Name
) == Gbl_Buffer
)
545 AhDisplayAslKeyword (Keyword
);
552 printf ("%s, no matching ASL keywords\n", Name
);
557 /*******************************************************************************
559 * FUNCTION: AhDisplayAslKeyword
561 * PARAMETERS: Op - Pointer to ASL keyword with syntax info
565 * DESCRIPTION: Format and display syntax info for an ASL keyword. Splits
566 * long lines appropriately for reading.
568 ******************************************************************************/
571 AhDisplayAslKeyword (
572 const AH_ASL_KEYWORD
*Op
)
575 /* ASL keyword name and description */
577 printf ("%22s: %s\n", Op
->Name
, Op
->Description
);
578 if (!Op
->KeywordList
)
583 /* List of actual keywords */
585 AhPrintOneField (24, 0, AH_MAX_ASL_LINE_LENGTH
, Op
->KeywordList
);
590 /*******************************************************************************
592 * FUNCTION: AhFindAslOperators (entry point for ASL operator search)
594 * PARAMETERS: Name - Name or prefix for an ASL operator.
595 * NULL means "find all"
599 * DESCRIPTION: Find all ASL operators that match the input Name or name
602 ******************************************************************************/
608 const AH_ASL_OPERATOR
*Operator
;
609 BOOLEAN Found
= FALSE
;
614 /* Find/display all names that match the input name prefix */
616 for (Operator
= AslOperatorInfo
; Operator
->Name
; Operator
++)
620 AhDisplayAslOperator (Operator
);
625 /* Upper case the operator name before substring compare */
627 strcpy (Gbl_Buffer
, Operator
->Name
);
628 AhStrupr (Gbl_Buffer
);
630 if (strstr (Gbl_Buffer
, Name
) == Gbl_Buffer
)
632 AhDisplayAslOperator (Operator
);
639 printf ("%s, no matching ASL operators\n", Name
);
644 /*******************************************************************************
646 * FUNCTION: AhDisplayAslOperator
648 * PARAMETERS: Op - Pointer to ASL operator with syntax info
652 * DESCRIPTION: Format and display syntax info for an ASL operator. Splits
653 * long lines appropriately for reading.
655 ******************************************************************************/
658 AhDisplayAslOperator (
659 const AH_ASL_OPERATOR
*Op
)
662 /* ASL operator name and description */
664 printf ("%16s: %s\n", Op
->Name
, Op
->Description
);
670 /* Syntax for the operator */
672 AhPrintOneField (18, 0, AH_MAX_ASL_LINE_LENGTH
, Op
->Syntax
);
675 AhDisplayOperatorKeywords (Op
);
680 /*******************************************************************************
682 * FUNCTION: AhDisplayOperatorKeywords
684 * PARAMETERS: Op - Pointer to ASL keyword with syntax info
688 * DESCRIPTION: Display any/all keywords that are associated with the ASL
691 ******************************************************************************/
694 AhDisplayOperatorKeywords (
695 const AH_ASL_OPERATOR
*Op
)
698 char *Separators
= "(){}, ";
699 BOOLEAN FirstKeyword
= TRUE
;
702 if (!Op
|| !Op
->Syntax
)
708 * Find all parameters that have the word "keyword" within, and then
709 * display the info about that keyword
711 strcpy (Gbl_LineBuffer
, Op
->Syntax
);
712 Token
= strtok (Gbl_LineBuffer
, Separators
);
715 if (strstr (Token
, "Keyword"))
720 FirstKeyword
= FALSE
;
723 /* Found a keyword, display keyword information */
725 AhFindAslKeywords (Token
);
728 Token
= strtok (NULL
, Separators
);
733 /*******************************************************************************
735 * FUNCTION: AhPrintOneField
737 * PARAMETERS: Indent - Indent length for new line(s)
738 * CurrentPosition - Position on current line
739 * MaxPosition - Max allowed line length
740 * Field - Data to output
742 * RETURN: Line position after field is written
744 * DESCRIPTION: Split long lines appropriately for ease of reading.
746 ******************************************************************************/
751 UINT32 CurrentPosition
,
763 Position
= CurrentPosition
;
767 printf ("%*s", (int) Indent
, " ");
771 Last
= This
+ strlen (This
);
772 while ((Next
= strpbrk (This
, " ")))
774 TokenLength
= Next
- This
;
775 Position
+= TokenLength
;
777 /* Split long lines */
779 if (Position
> MaxPosition
)
781 printf ("\n%*s", (int) Indent
, " ");
782 Position
= TokenLength
;
785 printf ("%.*s ", (int) TokenLength
, This
);
789 /* Handle last token on the input line */
791 TokenLength
= Last
- This
;
794 Position
+= TokenLength
;
795 if (Position
> MaxPosition
)
797 printf ("\n%*s", (int) Indent
, " ");
804 /*******************************************************************************
806 * FUNCTION: AhDisplayDeviceIds
812 * DESCRIPTION: Display all PNP* and ACPI* device IDs defined in the ACPI spec.
814 ******************************************************************************/
820 const AH_DEVICE_ID
*DeviceId
= AhDeviceIds
;
823 printf ("ACPI and PNP Device IDs defined in the ACPI specification:\n\n");
824 while (DeviceId
->Name
)
826 printf ("%8s %s\n", DeviceId
->Name
, DeviceId
->Description
);
832 /*******************************************************************************
834 * FUNCTION: AhDecodeException
836 * PARAMETERS: HexString - ACPI status string from command line, in
837 * hex. If null, display all exceptions.
841 * DESCRIPTION: Decode and display an ACPI_STATUS exception code.
843 ******************************************************************************/
849 const ACPI_EXCEPTION_INFO
*ExceptionInfo
;
855 * A null input string means to decode and display all known
860 printf ("All defined ACPICA exception codes:\n\n");
861 AH_DISPLAY_EXCEPTION (0, "AE_OK (No error occurred)");
863 /* Display codes in each block of exception types */
865 for (i
= 1; (i
& AE_CODE_MASK
) <= AE_CODE_MAX
; i
+= 0x1000)
870 ExceptionInfo
= AcpiUtValidateException ((ACPI_STATUS
) Status
);
873 AH_DISPLAY_EXCEPTION_TEXT (Status
, ExceptionInfo
);
877 } while (ExceptionInfo
);
882 /* Decode a single user-supplied exception code */
884 Status
= ACPI_STRTOUL (HexString
, NULL
, 16);
887 printf ("%s: Invalid hexadecimal exception code value\n", HexString
);
891 if (Status
> ACPI_UINT16_MAX
)
893 AH_DISPLAY_EXCEPTION (Status
, "Invalid exception code (more than 16 bits)");
897 ExceptionInfo
= AcpiUtValidateException ((ACPI_STATUS
) Status
);
900 AH_DISPLAY_EXCEPTION (Status
, "Unknown exception code");
904 AH_DISPLAY_EXCEPTION_TEXT (Status
, ExceptionInfo
);