Sync ACPICA with Intel's version 20180508 (from previously 20170831).
[dragonfly.git] / sys / contrib / dev / acpica / source / tools / acpihelp / ahdecode.c
blobbec66864fde1a2b68c3cc2a3e978ff5167d14fd5
1 /******************************************************************************
3 * Module Name: ahdecode - Miscellaneous decoding for acpihelp utility
5 *****************************************************************************/
7 /******************************************************************************
9 * 1. Copyright Notice
11 * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
12 * All rights reserved.
14 * 2. License
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.
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
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;
37 * The above copyright and patent license is granted only if the following
38 * conditions are met:
40 * 3. Conditions
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.
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.
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.
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
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.
80 * 4. Disclaimer and Export Compliance
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.
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.
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.
114 *****************************************************************************
116 * Alternatively, you may choose to be licensed under the terms of the
117 * following license:
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
121 * are met:
122 * 1. Redistributions of source code must retain the above copyright
123 * notice, this list of conditions, and the following disclaimer,
124 * without modification.
125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 * substantially similar to the "NO WARRANTY" disclaimer below
127 * ("Disclaimer") and any redistribution must be conditioned upon
128 * including a substantially similar Disclaimer requirement for further
129 * binary redistribution.
130 * 3. Neither the names of the above-listed copyright holders nor the names
131 * of any contributors may be used to endorse or promote products derived
132 * from this software without specific prior written permission.
134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146 * Alternatively, you may choose to be licensed under the terms of the
147 * GNU General Public License ("GPL") version 2 as published by the Free
148 * Software Foundation.
150 *****************************************************************************/
152 #define ACPI_CREATE_PREDEFINED_TABLE
153 #define ACPI_CREATE_RESOURCE_TABLE
155 #include "acpihelp.h"
156 #include "acpredef.h"
159 /* Local prototypes */
161 static BOOLEAN
162 AhDisplayPredefinedName (
163 char *Name,
164 UINT32 Length);
166 static void
167 AhDisplayPredefinedInfo (
168 char *Name);
170 static void
171 AhDisplayResourceName (
172 const ACPI_PREDEFINED_INFO *ThisName);
175 /*******************************************************************************
177 * FUNCTION: AhPrintOneField
179 * PARAMETERS: Indent - Indent length for new line(s)
180 * CurrentPosition - Position on current line
181 * MaxPosition - Max allowed line length
182 * Field - Data to output
184 * RETURN: Line position after field is written
186 * DESCRIPTION: Split long lines appropriately for ease of reading.
188 ******************************************************************************/
190 void
191 AhPrintOneField (
192 UINT32 Indent,
193 UINT32 CurrentPosition,
194 UINT32 MaxPosition,
195 const char *Field)
197 UINT32 Position;
198 UINT32 TokenLength;
199 const char *This;
200 const char *Next;
201 const char *Last;
204 This = Field;
205 Position = CurrentPosition;
207 if (Position == 0)
209 printf ("%*s", (int) Indent, " ");
210 Position = Indent;
213 Last = This + strlen (This);
214 while ((Next = strpbrk (This, " ")))
216 TokenLength = Next - This;
217 Position += TokenLength;
219 /* Split long lines */
221 if (Position > MaxPosition)
223 printf ("\n%*s", (int) Indent, " ");
224 Position = TokenLength;
227 printf ("%.*s ", (int) TokenLength, This);
228 This = Next + 1;
231 /* Handle last token on the input line */
233 TokenLength = Last - This;
234 if (TokenLength > 0)
236 Position += TokenLength;
237 if (Position > MaxPosition)
239 printf ("\n%*s", (int) Indent, " ");
242 printf ("%s", This);
247 /*******************************************************************************
249 * FUNCTION: AhDisplayDirectives
251 * PARAMETERS: None
253 * RETURN: None
255 * DESCRIPTION: Display all iASL preprocessor directives.
257 ******************************************************************************/
259 void
260 AhDisplayDirectives (
261 void)
263 const AH_DIRECTIVE_INFO *Info;
266 printf ("iASL Preprocessor Directives\n\n");
268 for (Info = Gbl_PreprocessorDirectives; Info->Name; Info++)
270 printf (" %-36s : %s\n", Info->Name, Info->Description);
275 /*******************************************************************************
277 * FUNCTION: AhFindPredefinedNames (entry point for predefined name search)
279 * PARAMETERS: NamePrefix - Name or prefix to find. Must start with
280 * an underscore. NULL means "find all"
282 * RETURN: None
284 * DESCRIPTION: Find and display all ACPI predefined names that match the
285 * input name or prefix. Includes the required number of arguments
286 * and the expected return type, if any.
288 ******************************************************************************/
290 void
291 AhFindPredefinedNames (
292 char *NamePrefix)
294 UINT32 Length;
295 BOOLEAN Found;
296 char Name[9];
299 if (!NamePrefix || (NamePrefix[0] == '*'))
301 Found = AhDisplayPredefinedName (NULL, 0);
302 return;
305 /* Contruct a local name or name prefix */
307 AcpiUtStrupr (NamePrefix);
308 if (*NamePrefix == '_')
310 NamePrefix++;
313 Name[0] = '_';
314 AcpiUtSafeStrncpy (&Name[1], NamePrefix, 7);
316 Length = strlen (Name);
317 if (Length > ACPI_NAME_SIZE)
319 printf ("%.8s: Predefined name must be 4 characters maximum\n", Name);
320 return;
323 Found = AhDisplayPredefinedName (Name, Length);
324 if (!Found)
326 printf ("%s, no matching predefined names\n", Name);
331 /*******************************************************************************
333 * FUNCTION: AhDisplayPredefinedName
335 * PARAMETERS: Name - Name or name prefix
337 * RETURN: TRUE if any names matched, FALSE otherwise
339 * DESCRIPTION: Display information about ACPI predefined names that match
340 * the input name or name prefix.
342 ******************************************************************************/
344 static BOOLEAN
345 AhDisplayPredefinedName (
346 char *Name,
347 UINT32 Length)
349 const AH_PREDEFINED_NAME *Info;
350 BOOLEAN Found = FALSE;
351 BOOLEAN Matched;
352 UINT32 i = 0;
355 /* Find/display all names that match the input name prefix */
357 for (Info = AslPredefinedInfo; Info->Name; Info++)
359 if (!Name)
361 Found = TRUE;
362 printf ("%s: <%s>\n", Info->Name, Info->Description);
363 printf ("%*s%s\n", 6, " ", Info->Action);
365 AhDisplayPredefinedInfo (Info->Name);
366 i++;
367 continue;
370 Matched = TRUE;
371 for (i = 0; i < Length; i++)
373 if (Info->Name[i] != Name[i])
375 Matched = FALSE;
376 break;
380 if (Matched)
382 Found = TRUE;
383 printf ("%s: <%s>\n", Info->Name, Info->Description);
384 printf ("%*s%s\n", 6, " ", Info->Action);
386 AhDisplayPredefinedInfo (Info->Name);
390 if (!Name)
392 printf ("\nFound %d Predefined ACPI Names\n", i);
394 return (Found);
398 /*******************************************************************************
400 * FUNCTION: AhDisplayPredefinedInfo
402 * PARAMETERS: Name - Exact 4-character ACPI name.
404 * RETURN: None
406 * DESCRIPTION: Find the name in the main ACPICA predefined info table and
407 * display the # of arguments and the return value type.
409 * Note: Resource Descriptor field names do not appear in this
410 * table -- thus, nothing will be displayed for them.
412 ******************************************************************************/
414 static void
415 AhDisplayPredefinedInfo (
416 char *Name)
418 const ACPI_PREDEFINED_INFO *ThisName;
421 /* NOTE: we check both tables always because there are some dupes */
423 /* Check against the predefine methods first */
425 ThisName = AcpiUtMatchPredefinedMethod (Name);
426 if (ThisName)
428 AcpiUtDisplayPredefinedMethod (Gbl_Buffer, ThisName, TRUE);
431 /* Check against the predefined resource descriptor names */
433 ThisName = AcpiUtMatchResourceName (Name);
434 if (ThisName)
436 AhDisplayResourceName (ThisName);
441 /*******************************************************************************
443 * FUNCTION: AhDisplayResourceName
445 * PARAMETERS: ThisName - Entry in the predefined method/name table
447 * RETURN: None
449 * DESCRIPTION: Display information about a resource descriptor name.
451 ******************************************************************************/
453 static void
454 AhDisplayResourceName (
455 const ACPI_PREDEFINED_INFO *ThisName)
457 UINT32 NumTypes;
460 NumTypes = AcpiUtGetResourceBitWidth (Gbl_Buffer,
461 ThisName->Info.ArgumentList);
463 printf (" %4.4s resource descriptor field is %s bits wide%s\n",
464 ThisName->Info.Name,
465 Gbl_Buffer,
466 (NumTypes > 1) ? " (depending on descriptor type)" : "");
470 /*******************************************************************************
472 * FUNCTION: AhDisplayDeviceIds
474 * PARAMETERS: Name - Device Hardware ID string.
475 * NULL means "find all"
477 * RETURN: None
479 * DESCRIPTION: Display PNP* and ACPI* device IDs.
481 ******************************************************************************/
483 void
484 AhDisplayDeviceIds (
485 char *Name)
487 const AH_DEVICE_ID *Info;
488 UINT32 Length;
489 BOOLEAN Matched;
490 UINT32 i;
491 BOOLEAN Found = FALSE;
494 /* Null input name indicates "display all" */
496 if (!Name || (Name[0] == '*'))
498 printf ("ACPI and PNP Device/Hardware IDs:\n\n");
499 for (Info = AslDeviceIds; Info->Name; Info++)
501 printf ("%8s %s\n", Info->Name, Info->Description);
504 return;
507 Length = strlen (Name);
508 if (Length > 8)
510 printf ("%.8s: Hardware ID must be 8 characters maximum\n", Name);
511 return;
514 /* Find/display all names that match the input name prefix */
516 AcpiUtStrupr (Name);
517 for (Info = AslDeviceIds; Info->Name; Info++)
519 Matched = TRUE;
520 for (i = 0; i < Length; i++)
522 if (Info->Name[i] != Name[i])
524 Matched = FALSE;
525 break;
529 if (Matched)
531 Found = TRUE;
532 printf ("%8s %s\n", Info->Name, Info->Description);
536 if (!Found)
538 printf ("%s, Hardware ID not found\n", Name);
543 /*******************************************************************************
545 * FUNCTION: AhDisplayUuids
547 * PARAMETERS: None
549 * RETURN: None
551 * DESCRIPTION: Display all known UUIDs.
553 ******************************************************************************/
555 void
556 AhDisplayUuids (
557 void)
559 const AH_UUID *Info;
562 printf ("ACPI-related UUIDs/GUIDs:\n");
564 /* Display entire table of known ACPI-related UUIDs/GUIDs */
566 for (Info = Gbl_AcpiUuids; Info->Description; Info++)
568 if (!Info->String) /* Null UUID string means group description */
570 printf ("\n%36s\n", Info->Description);
572 else
574 printf ("%32s : %s\n", Info->Description, Info->String);
578 /* Help info on how UUIDs/GUIDs strings are encoded */
580 printf ("\n\nByte encoding of UUID/GUID strings"
581 " into ACPI Buffer objects (use ToUUID from ASL):\n\n");
583 printf ("%32s : %s\n", "Input UUID/GUID String format",
584 "aabbccdd-eeff-gghh-iijj-kkllmmnnoopp");
586 printf ("%32s : %s\n", "Expected output ACPI buffer",
587 "dd,cc,bb,aa, ff,ee, hh,gg, ii,jj, kk,ll,mm,nn,oo,pp");
591 /*******************************************************************************
593 * FUNCTION: AhDisplayTables
595 * PARAMETERS: None
597 * RETURN: None
599 * DESCRIPTION: Display all known ACPI tables
601 ******************************************************************************/
603 void
604 AhDisplayTables (
605 void)
607 const AH_TABLE *Info;
608 UINT32 i = 0;
611 printf ("Known ACPI tables:\n");
613 for (Info = Gbl_AcpiSupportedTables; Info->Signature; Info++)
615 printf ("%8s : %s\n", Info->Signature, Info->Description);
616 i++;
619 printf ("\nTotal %u ACPI tables\n\n", i);
623 /*******************************************************************************
625 * FUNCTION: AhDecodeException
627 * PARAMETERS: HexString - ACPI status string from command line, in
628 * hex. If null, display all exceptions.
630 * RETURN: None
632 * DESCRIPTION: Decode and display an ACPI_STATUS exception code.
634 ******************************************************************************/
636 void
637 AhDecodeException (
638 char *HexString)
640 const ACPI_EXCEPTION_INFO *ExceptionInfo;
641 UINT32 Status;
642 UINT32 i;
646 * A null input string means to decode and display all known
647 * exception codes.
649 if (!HexString)
651 printf ("All defined ACPICA exception codes:\n\n");
652 AH_DISPLAY_EXCEPTION (0,
653 "AE_OK (No error occurred)");
655 /* Display codes in each block of exception types */
657 for (i = 1; (i & AE_CODE_MASK) <= AE_CODE_MAX; i += 0x1000)
659 Status = i;
662 ExceptionInfo = AcpiUtValidateException ((ACPI_STATUS) Status);
663 if (ExceptionInfo)
665 AH_DISPLAY_EXCEPTION_TEXT (Status, ExceptionInfo);
668 Status++;
670 } while (ExceptionInfo);
672 return;
675 /* Decode a single user-supplied exception code */
677 Status = strtoul (HexString, NULL, 16);
678 if (!Status)
680 printf ("%s: Invalid hexadecimal exception code value\n", HexString);
681 return;
684 if (Status > ACPI_UINT16_MAX)
686 AH_DISPLAY_EXCEPTION (Status, "Invalid exception code (more than 16 bits)");
687 return;
690 ExceptionInfo = AcpiUtValidateException ((ACPI_STATUS) Status);
691 if (!ExceptionInfo)
693 AH_DISPLAY_EXCEPTION (Status, "Unknown exception code");
694 return;
697 AH_DISPLAY_EXCEPTION_TEXT (Status, ExceptionInfo);