blob: fc9096a187ef6db549b3115d2be8e821ee4d0b76 [file] [log] [blame]
Adrian Danisd64c6652020-02-12 11:24:47 +11001/******************************************************************************
2 *
3 * Module Name: ahdecode - Miscellaneous decoding for acpihelp utility
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2020, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * NO WARRANTY
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
30 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
35 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
36 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGES.
38 */
39
40#define ACPI_CREATE_PREDEFINED_TABLE
41#define ACPI_CREATE_RESOURCE_TABLE
42
43#include "acpihelp.h"
44#include "acpredef.h"
45
46
47/* Local prototypes */
48
49static BOOLEAN
50AhDisplayPredefinedName (
51 char *Name,
52 UINT32 Length);
53
54static void
55AhDisplayPredefinedInfo (
56 char *Name);
57
58static void
59AhDoSpecialNames (
60 char *Name);
61
62static void
63AhDisplayResourceName (
64 const ACPI_PREDEFINED_INFO *ThisName);
65
66
67/*******************************************************************************
68 *
69 * FUNCTION: AhPrintOneField
70 *
71 * PARAMETERS: Indent - Indent length for new line(s)
72 * CurrentPosition - Position on current line
73 * MaxPosition - Max allowed line length
74 * Field - Data to output
75 *
76 * RETURN: Line position after field is written
77 *
78 * DESCRIPTION: Split long lines appropriately for ease of reading.
79 *
80 ******************************************************************************/
81
82void
83AhPrintOneField (
84 UINT32 Indent,
85 UINT32 CurrentPosition,
86 UINT32 MaxPosition,
87 const char *Field)
88{
89 UINT32 Position;
90 UINT32 TokenLength;
91 const char *This;
92 const char *Next;
93 const char *Last;
94
95
96 This = Field;
97 Position = CurrentPosition;
98
99 if (Position == 0)
100 {
101 printf ("%*s", (int) Indent, " ");
102 Position = Indent;
103 }
104
105 Last = This + strlen (This);
106 while ((Next = strpbrk (This, " ")))
107 {
108 TokenLength = Next - This;
109 Position += TokenLength;
110
111 /* Split long lines */
112
113 if (Position > MaxPosition)
114 {
115 printf ("\n%*s", (int) Indent, " ");
116 Position = TokenLength;
117 }
118
119 printf ("%.*s ", (int) TokenLength, This);
120 This = Next + 1;
121 }
122
123 /* Handle last token on the input line */
124
125 TokenLength = Last - This;
126 if (TokenLength > 0)
127 {
128 Position += TokenLength;
129 if (Position > MaxPosition)
130 {
131 printf ("\n%*s", (int) Indent, " ");
132 }
133
134 printf ("%s", This);
135 }
136}
137
138
139/*******************************************************************************
140 *
141 * FUNCTION: AhDisplayDirectives
142 *
143 * PARAMETERS: None
144 *
145 * RETURN: None
146 *
147 * DESCRIPTION: Display all iASL preprocessor directives.
148 *
149 ******************************************************************************/
150
151void
152AhDisplayDirectives (
153 void)
154{
155 const AH_DIRECTIVE_INFO *Info;
156
157
158 printf ("iASL Preprocessor Directives\n\n");
159
160 for (Info = Gbl_PreprocessorDirectives; Info->Name; Info++)
161 {
162 printf (" %-36s : %s\n", Info->Name, Info->Description);
163 }
164}
165
166
167/*******************************************************************************
168 *
169 * FUNCTION: AhFindPredefinedNames (entry point for predefined name search)
170 *
171 * PARAMETERS: NamePrefix - Name or prefix to find. Must start with
172 * an underscore. NULL means "find all"
173 *
174 * RETURN: None
175 *
176 * DESCRIPTION: Find and display all ACPI predefined names that match the
177 * input name or prefix. Includes the required number of arguments
178 * and the expected return type, if any.
179 *
180 ******************************************************************************/
181
182void
183AhFindPredefinedNames (
184 char *NamePrefix)
185{
186 UINT32 Length;
187 BOOLEAN Found;
188 char Name[ACPI_NAMESEG_SIZE + 1];
189
190
191 if (!NamePrefix || (*NamePrefix == '*'))
192 {
193 (void) AhDisplayPredefinedName (NULL, 0);
194 return;
195 }
196
197 Length = strlen (NamePrefix);
198 if (Length > ACPI_NAMESEG_SIZE)
199 {
200 printf ("%.8s: Predefined name must be 4 characters maximum\n",
201 NamePrefix);
202 return;
203 }
204
205 /* Construct a local name or name prefix */
206
207 AcpiUtStrupr (NamePrefix);
208 if (*NamePrefix == '_')
209 {
210 NamePrefix++;
211 }
212
213 Name[0] = '_';
214 AcpiUtSafeStrncpy (&Name[1], NamePrefix, 4);
215
216 /* Check for special names such as _Exx, _ACx, etc. */
217
218 AhDoSpecialNames (Name);
219
220 /* Lookup and display the name(s) */
221
222 Found = AhDisplayPredefinedName (Name, Length);
223 if (!Found)
224 {
225 printf ("%s, no matching predefined names\n", Name);
226 }
227}
228
229
230/*******************************************************************************
231 *
232 * FUNCTION: AhDoSpecialNames
233 *
234 * PARAMETERS: Name - Name or prefix to find
235 *
236 * RETURN: None
237 *
238 * DESCRIPTION: Detect and handle the "special" names such as _Exx, _ACx, etc.
239 *
240 * Current support:
241 * _EJx
242 * _Exx
243 * _Lxx
244 * _Qxx
245 * _Wxx
246 * _ACx
247 * _ALx
248 * _T_x
249 *
250 ******************************************************************************/
251
252static void
253AhDoSpecialNames (
254 char *Name)
255{
256
257 /*
258 * Check for the special names that have one or more numeric
259 * suffixes. For example, _Lxx can have 256 different flavors,
260 * from _L00 to _LFF.
261 */
262 switch (Name[1])
263 {
264 case 'E':
265 if (Name[2] == 'J')
266 {
267 if (isdigit (Name[3]) || (Name[3] == 'X'))
268 {
269 /* _EJx */
270
271 Name[3] = 'x';
272 break;
273 }
274 }
275
276 /* Fallthrough */
277
278 case 'L':
279 case 'Q':
280 case 'W':
281 if ((isxdigit (Name[2]) && isxdigit (Name[3]))
282 ||
283 ((Name[2] == 'X') && (Name[3] == 'X')))
284 {
285 /* _Exx, _Lxx, _Qxx, or _Wxx */
286
287 Name[2] = 'x';
288 Name[3] = 'x';
289 }
290 break;
291
292 case 'A':
293 if ((Name[2] == 'C') || (Name[2] == 'L'))
294 {
295 if (isdigit (Name[3]) || (Name[3] == 'X'))
296 {
297 /* _ACx or _ALx */
298
299 Name[3] = 'x';
300 }
301 }
302 break;
303
304 case 'T':
305 if (Name[2] == '_')
306 {
307 /* _T_x (Reserved for iASL compiler */
308
309 Name[3] = 'x';
310 }
311 break;
312
313 default:
314 break;
315 }
316}
317
318
319/*******************************************************************************
320 *
321 * FUNCTION: AhDisplayPredefinedName
322 *
323 * PARAMETERS: Name - Name or name prefix
324 *
325 * RETURN: TRUE if any names matched, FALSE otherwise
326 *
327 * DESCRIPTION: Display information about ACPI predefined names that match
328 * the input name or name prefix.
329 *
330 ******************************************************************************/
331
332static BOOLEAN
333AhDisplayPredefinedName (
334 char *Name,
335 UINT32 Length)
336{
337 const AH_PREDEFINED_NAME *Info;
338 BOOLEAN Found = FALSE;
339 BOOLEAN Matched;
340 UINT32 i = 0;
341
342
343 /* Find/display all names that match the input name prefix */
344
345 for (Info = AslPredefinedInfo; Info->Name; Info++)
346 {
347 if (!Name)
348 {
349 Found = TRUE;
350 printf ("%s: <%s>\n", Info->Name, Info->Description);
351 printf ("%*s%s\n", 6, " ", Info->Action);
352
353 AhDisplayPredefinedInfo (Info->Name);
354 i++;
355 continue;
356 }
357
358 Matched = TRUE;
359 for (i = 0; i < Length; i++)
360 {
361 if (Info->Name[i] != Name[i])
362 {
363 Matched = FALSE;
364 break;
365 }
366 }
367
368 if (Matched)
369 {
370 Found = TRUE;
371 printf ("%s: <%s>\n", Info->Name, Info->Description);
372 printf ("%*s%s\n", 6, " ", Info->Action);
373
374 AhDisplayPredefinedInfo (Info->Name);
375 }
376 }
377
378 if (!Name)
379 {
380 printf ("\nFound %d Predefined ACPI Names\n", i);
381 }
382 return (Found);
383}
384
385
386/*******************************************************************************
387 *
388 * FUNCTION: AhDisplayPredefinedInfo
389 *
390 * PARAMETERS: Name - Exact 4-character ACPI name.
391 *
392 * RETURN: None
393 *
394 * DESCRIPTION: Find the name in the main ACPICA predefined info table and
395 * display the # of arguments and the return value type.
396 *
397 * Note: Resource Descriptor field names do not appear in this
398 * table -- thus, nothing will be displayed for them.
399 *
400 ******************************************************************************/
401
402static void
403AhDisplayPredefinedInfo (
404 char *Name)
405{
406 const ACPI_PREDEFINED_INFO *ThisName;
407
408
409 /* NOTE: we check both tables always because there are some dupes */
410
411 /* Check against the predefined methods first */
412
413 ThisName = AcpiUtMatchPredefinedMethod (Name);
414 if (ThisName)
415 {
416 AcpiUtDisplayPredefinedMethod (Gbl_Buffer, ThisName, TRUE);
417 }
418
419 /* Check against the predefined resource descriptor names */
420
421 ThisName = AcpiUtMatchResourceName (Name);
422 if (ThisName)
423 {
424 AhDisplayResourceName (ThisName);
425 }
426}
427
428
429/*******************************************************************************
430 *
431 * FUNCTION: AhDisplayResourceName
432 *
433 * PARAMETERS: ThisName - Entry in the predefined method/name table
434 *
435 * RETURN: None
436 *
437 * DESCRIPTION: Display information about a resource descriptor name.
438 *
439 ******************************************************************************/
440
441static void
442AhDisplayResourceName (
443 const ACPI_PREDEFINED_INFO *ThisName)
444{
445 UINT32 NumTypes;
446
447
448 NumTypes = AcpiUtGetResourceBitWidth (Gbl_Buffer,
449 ThisName->Info.ArgumentList);
450
451 printf (" %4.4s resource descriptor field is %s bits wide%s\n",
452 ThisName->Info.Name,
453 Gbl_Buffer,
454 (NumTypes > 1) ? " (depending on descriptor type)" : "");
455}
456
457
458/*******************************************************************************
459 *
460 * FUNCTION: AhDisplayDeviceIds
461 *
462 * PARAMETERS: Name - Device Hardware ID string.
463 * NULL means "find all"
464 *
465 * RETURN: None
466 *
467 * DESCRIPTION: Display PNP* and ACPI* device IDs.
468 *
469 ******************************************************************************/
470
471void
472AhDisplayDeviceIds (
473 char *Name)
474{
475 const AH_DEVICE_ID *Info;
476 UINT32 Length;
477 BOOLEAN Matched;
478 UINT32 i;
479 BOOLEAN Found = FALSE;
480
481
482 /* Null input name indicates "display all" */
483
484 if (!Name || (Name[0] == '*'))
485 {
486 printf ("ACPI and PNP Device/Hardware IDs:\n\n");
487 for (Info = AslDeviceIds; Info->Name; Info++)
488 {
489 printf ("%8s %s\n", Info->Name, Info->Description);
490 }
491
492 return;
493 }
494
495 Length = strlen (Name);
496 if (Length > 8)
497 {
498 printf ("%.8s: Hardware ID must be 8 characters maximum\n", Name);
499 return;
500 }
501
502 /* Find/display all names that match the input name prefix */
503
504 AcpiUtStrupr (Name);
505 for (Info = AslDeviceIds; Info->Name; Info++)
506 {
507 Matched = TRUE;
508 for (i = 0; i < Length; i++)
509 {
510 if (Info->Name[i] != Name[i])
511 {
512 Matched = FALSE;
513 break;
514 }
515 }
516
517 if (Matched)
518 {
519 Found = TRUE;
520 printf ("%8s %s\n", Info->Name, Info->Description);
521 }
522 }
523
524 if (!Found)
525 {
526 printf ("%s, Hardware ID not found\n", Name);
527 }
528}
529
530
531/*******************************************************************************
532 *
533 * FUNCTION: AhDisplayUuids
534 *
535 * PARAMETERS: None
536 *
537 * RETURN: None
538 *
539 * DESCRIPTION: Display all known UUIDs.
540 *
541 ******************************************************************************/
542
543void
544AhDisplayUuids (
545 void)
546{
547 const AH_UUID *Info;
548
549
550 printf ("ACPI-related UUIDs/GUIDs:\n");
551
552 /* Display entire table of known ACPI-related UUIDs/GUIDs */
553
554 for (Info = Gbl_AcpiUuids; Info->Description; Info++)
555 {
556 if (!Info->String) /* Null UUID string means group description */
557 {
558 printf ("\n%36s\n", Info->Description);
559 }
560 else
561 {
562 printf ("%32s : %s\n", Info->Description, Info->String);
563 }
564 }
565
566 /* Help info on how UUIDs/GUIDs strings are encoded */
567
568 printf ("\n\nByte encoding of UUID/GUID strings"
569 " into ACPI Buffer objects (use ToUUID from ASL):\n\n");
570
571 printf ("%32s : %s\n", "Input UUID/GUID String format",
572 "aabbccdd-eeff-gghh-iijj-kkllmmnnoopp");
573
574 printf ("%32s : %s\n", "Expected output ACPI buffer",
575 "dd,cc,bb,aa, ff,ee, hh,gg, ii,jj, kk,ll,mm,nn,oo,pp");
576}
577
578
579/*******************************************************************************
580 *
581 * FUNCTION: AhDisplayTables
582 *
583 * PARAMETERS: None
584 *
585 * RETURN: None
586 *
587 * DESCRIPTION: Display all known ACPI tables
588 *
589 ******************************************************************************/
590
591void
592AhDisplayTables (
593 void)
594{
595 const AH_TABLE *Info;
596 UINT32 i = 0;
597
598
599 printf ("Known ACPI tables:\n");
600
601 for (Info = AcpiGbl_SupportedTables; Info->Signature; Info++)
602 {
603 printf ("%8s : %s\n", Info->Signature, Info->Description);
604 i++;
605 }
606
607 printf ("\nTotal %u ACPI tables\n\n", i);
608}
609
610
611/*******************************************************************************
612 *
613 * FUNCTION: AhDecodeException
614 *
615 * PARAMETERS: HexString - ACPI status string from command line, in
616 * hex. If null, display all exceptions.
617 *
618 * RETURN: None
619 *
620 * DESCRIPTION: Decode and display an ACPI_STATUS exception code.
621 *
622 ******************************************************************************/
623
624void
625AhDecodeException (
626 char *HexString)
627{
628 const ACPI_EXCEPTION_INFO *ExceptionInfo;
629 UINT32 Status;
630 UINT32 i;
631
632
633 /*
634 * A null input string means to decode and display all known
635 * exception codes.
636 */
637 if (!HexString)
638 {
639 printf ("All defined ACPICA exception codes:\n\n");
640 AH_DISPLAY_EXCEPTION (0,
641 "AE_OK (No error occurred)");
642
643 /* Display codes in each block of exception types */
644
645 for (i = 1; (i & AE_CODE_MASK) <= AE_CODE_MAX; i += 0x1000)
646 {
647 Status = i;
648 do
649 {
650 ExceptionInfo = AcpiUtValidateException ((ACPI_STATUS) Status);
651 if (ExceptionInfo)
652 {
653 AH_DISPLAY_EXCEPTION_TEXT (Status, ExceptionInfo);
654 }
655
656 Status++;
657
658 } while (ExceptionInfo);
659 }
660 return;
661 }
662
663 /* Decode a single user-supplied exception code */
664
665 Status = strtoul (HexString, NULL, 16);
666 if (!Status)
667 {
668 printf ("%s: Invalid hexadecimal exception code value\n", HexString);
669 return;
670 }
671
672 if (Status > ACPI_UINT16_MAX)
673 {
674 AH_DISPLAY_EXCEPTION (Status, "Invalid exception code (more than 16 bits)");
675 return;
676 }
677
678 ExceptionInfo = AcpiUtValidateException ((ACPI_STATUS) Status);
679 if (!ExceptionInfo)
680 {
681 AH_DISPLAY_EXCEPTION (Status, "Unknown exception code");
682 return;
683 }
684
685 AH_DISPLAY_EXCEPTION_TEXT (Status, ExceptionInfo);
686}
OSZAR »