Sync ACPICA with Intel's version 20161117.
[dragonfly.git] / sys / contrib / dev / acpica / source / components / disassembler / dmbuffer.c
blob139398212f8f620e5a5f9f8215740f9d7d151fd0
1 /*******************************************************************************
3 * Module Name: dmbuffer - AML disassembler, buffer and string support
5 ******************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2016, Intel Corp.
9 * All rights reserved.
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.
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.
30 * NO WARRANTY
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 #include "acpi.h"
45 #include "accommon.h"
46 #include "acutils.h"
47 #include "acdisasm.h"
48 #include "acparser.h"
49 #include "amlcode.h"
50 #include "acinterp.h"
53 #ifdef ACPI_DISASSEMBLER
55 #define _COMPONENT ACPI_CA_DEBUGGER
56 ACPI_MODULE_NAME ("dmbuffer")
58 /* Local prototypes */
60 static void
61 AcpiDmUuid (
62 ACPI_PARSE_OBJECT *Op);
64 static void
65 AcpiDmUnicode (
66 ACPI_PARSE_OBJECT *Op);
68 static void
69 AcpiDmGetHardwareIdType (
70 ACPI_PARSE_OBJECT *Op);
72 static void
73 AcpiDmPldBuffer (
74 UINT32 Level,
75 UINT8 *ByteData,
76 UINT32 ByteCount);
78 static const char *
79 AcpiDmFindNameByIndex (
80 UINT64 Index,
81 const char **List);
84 #define ACPI_BUFFER_BYTES_PER_LINE 8
87 /*******************************************************************************
89 * FUNCTION: AcpiDmDisasmByteList
91 * PARAMETERS: Level - Current source code indentation level
92 * ByteData - Pointer to the byte list
93 * ByteCount - Length of the byte list
95 * RETURN: None
97 * DESCRIPTION: Dump an AML "ByteList" in Hex format. 8 bytes per line, prefixed
98 * with the hex buffer offset.
100 ******************************************************************************/
102 void
103 AcpiDmDisasmByteList (
104 UINT32 Level,
105 UINT8 *ByteData,
106 UINT32 ByteCount)
108 UINT32 i;
109 UINT32 j;
110 UINT32 CurrentIndex;
111 UINT8 BufChar;
114 if (!ByteCount)
116 return;
119 for (i = 0; i < ByteCount; i += ACPI_BUFFER_BYTES_PER_LINE)
121 /* Line indent and offset prefix for each new line */
123 AcpiDmIndent (Level);
124 if (ByteCount > ACPI_BUFFER_BYTES_PER_LINE)
126 AcpiOsPrintf ("/* %04X */ ", i);
129 /* Dump the actual hex values */
131 for (j = 0; j < ACPI_BUFFER_BYTES_PER_LINE; j++)
133 CurrentIndex = i + j;
134 if (CurrentIndex >= ByteCount)
136 /* Dump fill spaces */
138 AcpiOsPrintf (" ");
139 continue;
142 AcpiOsPrintf (" 0x%2.2X", ByteData[CurrentIndex]);
144 /* Add comma if there are more bytes to display */
146 if (CurrentIndex < (ByteCount - 1))
148 AcpiOsPrintf (",");
150 else
152 AcpiOsPrintf (" ");
156 /* Dump the ASCII equivalents within a comment */
158 AcpiOsPrintf (" /* ");
159 for (j = 0; j < ACPI_BUFFER_BYTES_PER_LINE; j++)
161 CurrentIndex = i + j;
162 if (CurrentIndex >= ByteCount)
164 break;
167 BufChar = ByteData[CurrentIndex];
168 if (isprint (BufChar))
170 AcpiOsPrintf ("%c", BufChar);
172 else
174 AcpiOsPrintf (".");
178 /* Finished with this line */
180 AcpiOsPrintf (" */\n");
185 /*******************************************************************************
187 * FUNCTION: AcpiDmByteList
189 * PARAMETERS: Info - Parse tree walk info
190 * Op - Byte list op
192 * RETURN: None
194 * DESCRIPTION: Dump a buffer byte list, handling the various types of buffers.
195 * Buffer type must be already set in the Op DisasmOpcode.
197 ******************************************************************************/
199 void
200 AcpiDmByteList (
201 ACPI_OP_WALK_INFO *Info,
202 ACPI_PARSE_OBJECT *Op)
204 UINT8 *ByteData;
205 UINT32 ByteCount;
208 ByteData = Op->Named.Data;
209 ByteCount = (UINT32) Op->Common.Value.Integer;
212 * The byte list belongs to a buffer, and can be produced by either
213 * a ResourceTemplate, Unicode, quoted string, or a plain byte list.
215 switch (Op->Common.Parent->Common.DisasmOpcode)
217 case ACPI_DASM_RESOURCE:
219 AcpiDmResourceTemplate (
220 Info, Op->Common.Parent, ByteData, ByteCount);
221 break;
223 case ACPI_DASM_STRING:
225 AcpiDmIndent (Info->Level);
226 AcpiUtPrintString ((char *) ByteData, ACPI_UINT16_MAX);
227 AcpiOsPrintf ("\n");
228 break;
230 case ACPI_DASM_UUID:
232 AcpiDmUuid (Op);
233 break;
235 case ACPI_DASM_UNICODE:
237 AcpiDmUnicode (Op);
238 break;
240 case ACPI_DASM_PLD_METHOD:
241 #if 0
242 AcpiDmDisasmByteList (Info->Level, ByteData, ByteCount);
243 #endif
244 AcpiDmPldBuffer (Info->Level, ByteData, ByteCount);
245 break;
247 case ACPI_DASM_BUFFER:
248 default:
250 * Not a resource, string, or unicode string.
251 * Just dump the buffer
253 AcpiDmDisasmByteList (Info->Level, ByteData, ByteCount);
254 break;
259 /*******************************************************************************
261 * FUNCTION: AcpiDmIsUuidBuffer
263 * PARAMETERS: Op - Buffer Object to be examined
265 * RETURN: TRUE if buffer contains a UUID
267 * DESCRIPTION: Determine if a buffer Op contains a UUID
269 * To help determine whether the buffer is a UUID versus a raw data buffer,
270 * there a are a couple bytes we can look at:
272 * xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx
274 * The variant covered by the UUID specification is indicated by the two most
275 * significant bits of N being 1 0 (i.e., the hexadecimal N will always be
276 * 8, 9, A, or B).
278 * The variant covered by the UUID specification has five versions. For this
279 * variant, the four bits of M indicates the UUID version (i.e., the
280 * hexadecimal M will be either 1, 2, 3, 4, or 5).
282 ******************************************************************************/
284 BOOLEAN
285 AcpiDmIsUuidBuffer (
286 ACPI_PARSE_OBJECT *Op)
288 UINT8 *ByteData;
289 UINT32 ByteCount;
290 ACPI_PARSE_OBJECT *SizeOp;
291 ACPI_PARSE_OBJECT *NextOp;
294 /* Buffer size is the buffer argument */
296 SizeOp = Op->Common.Value.Arg;
298 /* Next, the initializer byte list to examine */
300 NextOp = SizeOp->Common.Next;
301 if (!NextOp)
303 return (FALSE);
306 /* Extract the byte list info */
308 ByteData = NextOp->Named.Data;
309 ByteCount = (UINT32) NextOp->Common.Value.Integer;
311 /* Byte count must be exactly 16 */
313 if (ByteCount != UUID_BUFFER_LENGTH)
315 return (FALSE);
318 /* Check for valid "M" and "N" values (see function header above) */
320 if (((ByteData[7] & 0xF0) == 0x00) || /* M={1,2,3,4,5} */
321 ((ByteData[7] & 0xF0) > 0x50) ||
322 ((ByteData[8] & 0xF0) < 0x80) || /* N={8,9,A,B} */
323 ((ByteData[8] & 0xF0) > 0xB0))
325 return (FALSE);
328 /* Ignore the Size argument in the disassembly of this buffer op */
330 SizeOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
331 return (TRUE);
335 /*******************************************************************************
337 * FUNCTION: AcpiDmUuid
339 * PARAMETERS: Op - Byte List op containing a UUID
341 * RETURN: None
343 * DESCRIPTION: Dump a buffer containing a UUID as a standard ASCII string.
345 * Output Format:
346 * In its canonical form, the UUID is represented by a string containing 32
347 * lowercase hexadecimal digits, displayed in 5 groups separated by hyphens.
348 * The complete form is 8-4-4-4-12 for a total of 36 characters (32
349 * alphanumeric characters representing hex digits and 4 hyphens). In bytes,
350 * 4-2-2-2-6. Example:
352 * ToUUID ("107ededd-d381-4fd7-8da9-08e9a6c79644")
354 ******************************************************************************/
356 static void
357 AcpiDmUuid (
358 ACPI_PARSE_OBJECT *Op)
360 UINT8 *Data;
361 const char *Description;
364 Data = ACPI_CAST_PTR (UINT8, Op->Named.Data);
366 /* Emit the 36-byte UUID string in the proper format/order */
368 AcpiOsPrintf (
369 "\"%2.2x%2.2x%2.2x%2.2x-"
370 "%2.2x%2.2x-"
371 "%2.2x%2.2x-"
372 "%2.2x%2.2x-"
373 "%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\")",
374 Data[3], Data[2], Data[1], Data[0],
375 Data[5], Data[4],
376 Data[7], Data[6],
377 Data[8], Data[9],
378 Data[10], Data[11], Data[12], Data[13], Data[14], Data[15]);
380 /* Dump the UUID description string if available */
382 Description = AcpiAhMatchUuid (Data);
383 if (Description)
385 AcpiOsPrintf (" /* %s */", Description);
390 /*******************************************************************************
392 * FUNCTION: AcpiDmIsUnicodeBuffer
394 * PARAMETERS: Op - Buffer Object to be examined
396 * RETURN: TRUE if buffer contains a UNICODE string
398 * DESCRIPTION: Determine if a buffer Op contains a Unicode string
400 ******************************************************************************/
402 BOOLEAN
403 AcpiDmIsUnicodeBuffer (
404 ACPI_PARSE_OBJECT *Op)
406 UINT8 *ByteData;
407 UINT32 ByteCount;
408 UINT32 WordCount;
409 ACPI_PARSE_OBJECT *SizeOp;
410 ACPI_PARSE_OBJECT *NextOp;
411 UINT32 i;
414 /* Buffer size is the buffer argument */
416 SizeOp = Op->Common.Value.Arg;
418 /* Next, the initializer byte list to examine */
420 NextOp = SizeOp->Common.Next;
421 if (!NextOp)
423 return (FALSE);
426 /* Extract the byte list info */
428 ByteData = NextOp->Named.Data;
429 ByteCount = (UINT32) NextOp->Common.Value.Integer;
430 WordCount = ACPI_DIV_2 (ByteCount);
433 * Unicode string must have an even number of bytes and last
434 * word must be zero
436 if ((!ByteCount) ||
437 (ByteCount < 4) ||
438 (ByteCount & 1) ||
439 ((UINT16 *) (void *) ByteData)[WordCount - 1] != 0)
441 return (FALSE);
445 * For each word, 1st byte must be printable ascii, and the
446 * 2nd byte must be zero. This does not allow for escape
447 * sequences, but it is the most secure way to detect a
448 * unicode string.
450 for (i = 0; i < (ByteCount - 2); i += 2)
452 if ((ByteData[i] == 0) ||
453 !(isprint (ByteData[i])) ||
454 (ByteData[(ACPI_SIZE) i + 1] != 0))
456 return (FALSE);
460 /* Ignore the Size argument in the disassembly of this buffer op */
462 SizeOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
463 return (TRUE);
467 /*******************************************************************************
469 * FUNCTION: AcpiDmIsStringBuffer
471 * PARAMETERS: Op - Buffer Object to be examined
473 * RETURN: TRUE if buffer contains a ASCII string, FALSE otherwise
475 * DESCRIPTION: Determine if a buffer Op contains a ASCII string
477 ******************************************************************************/
479 BOOLEAN
480 AcpiDmIsStringBuffer (
481 ACPI_PARSE_OBJECT *Op)
483 UINT8 *ByteData;
484 UINT32 ByteCount;
485 ACPI_PARSE_OBJECT *SizeOp;
486 ACPI_PARSE_OBJECT *NextOp;
487 UINT32 i;
490 /* Buffer size is the buffer argument */
492 SizeOp = Op->Common.Value.Arg;
494 /* Next, the initializer byte list to examine */
496 NextOp = SizeOp->Common.Next;
497 if (!NextOp)
499 return (FALSE);
502 /* Extract the byte list info */
504 ByteData = NextOp->Named.Data;
505 ByteCount = (UINT32) NextOp->Common.Value.Integer;
507 /* Last byte must be the null terminator */
509 if ((!ByteCount) ||
510 (ByteCount < 2) ||
511 (ByteData[ByteCount-1] != 0))
513 return (FALSE);
517 * Check for a possible standalone resource EndTag, ignore it
518 * here. However, this sequence is also the string "Y", but
519 * this seems rare enough to be acceptable.
521 if ((ByteCount == 2) && (ByteData[0] == 0x79))
523 return (FALSE);
526 /* Check all bytes for ASCII */
528 for (i = 0; i < (ByteCount - 1); i++)
531 * TBD: allow some escapes (non-ascii chars).
532 * they will be handled in the string output routine
535 /* Not a string if not printable ascii */
537 if (!isprint (ByteData[i]))
539 return (FALSE);
543 return (TRUE);
547 /*******************************************************************************
549 * FUNCTION: AcpiDmIsPldBuffer
551 * PARAMETERS: Op - Buffer Object to be examined
553 * RETURN: TRUE if buffer appears to contain data produced via the
554 * ToPLD macro, FALSE otherwise
556 * DESCRIPTION: Determine if a buffer Op contains a _PLD structure
558 ******************************************************************************/
560 BOOLEAN
561 AcpiDmIsPldBuffer (
562 ACPI_PARSE_OBJECT *Op)
564 ACPI_NAMESPACE_NODE *Node;
565 ACPI_PARSE_OBJECT *SizeOp;
566 ACPI_PARSE_OBJECT *ByteListOp;
567 ACPI_PARSE_OBJECT *ParentOp;
568 UINT64 BufferSize;
569 UINT64 InitializerSize;
573 * Get the BufferSize argument - Buffer(BufferSize)
574 * If the buffer was generated by the ToPld macro, it must
575 * be a BYTE constant.
577 SizeOp = Op->Common.Value.Arg;
578 if (SizeOp->Common.AmlOpcode != AML_BYTE_OP)
580 return (FALSE);
583 /* Check the declared BufferSize, two possibilities */
585 BufferSize = SizeOp->Common.Value.Integer;
586 if ((BufferSize != ACPI_PLD_REV1_BUFFER_SIZE) &&
587 (BufferSize != ACPI_PLD_REV2_BUFFER_SIZE))
589 return (FALSE);
593 * Check the initializer list length. This is the actual
594 * number of bytes in the buffer as counted by the AML parser.
595 * The declared BufferSize can be larger than the actual length.
596 * However, for the ToPLD macro, the BufferSize will be the same
597 * as the initializer list length.
599 ByteListOp = SizeOp->Common.Next;
600 if (!ByteListOp)
602 return (FALSE); /* Zero-length buffer case */
605 InitializerSize = ByteListOp->Common.Value.Integer;
606 if ((InitializerSize != ACPI_PLD_REV1_BUFFER_SIZE) &&
607 (InitializerSize != ACPI_PLD_REV2_BUFFER_SIZE))
609 return (FALSE);
612 /* Final size check */
614 if (BufferSize != InitializerSize)
616 return (FALSE);
619 /* Now examine the buffer parent */
621 ParentOp = Op->Common.Parent;
622 if (!ParentOp)
624 return (FALSE);
627 /* Check for form: Name(_PLD, Buffer() {}). Not legal, however */
629 if (ParentOp->Common.AmlOpcode == AML_NAME_OP)
631 Node = ParentOp->Common.Node;
633 if (ACPI_COMPARE_NAME (Node->Name.Ascii, METHOD_NAME__PLD))
635 /* Ignore the Size argument in the disassembly of this buffer op */
637 SizeOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
638 return (TRUE);
641 return (FALSE);
645 * Check for proper form: Name(_PLD, Package() {ToPLD()})
647 * Note: All other forms such as
648 * Return (Package() {ToPLD()})
649 * Local0 = ToPLD()
650 * etc. are not converted back to the ToPLD macro, because
651 * there is really no deterministic way to disassemble the buffer
652 * back to the ToPLD macro, other than trying to find the "_PLD"
653 * name
655 if (ParentOp->Common.AmlOpcode == AML_PACKAGE_OP)
657 ParentOp = ParentOp->Common.Parent;
658 if (!ParentOp)
660 return (FALSE);
663 if (ParentOp->Common.AmlOpcode == AML_NAME_OP)
665 Node = ParentOp->Common.Node;
667 if (ACPI_COMPARE_NAME (Node->Name.Ascii, METHOD_NAME__PLD))
669 /* Ignore the Size argument in the disassembly of this buffer op */
671 SizeOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
672 return (TRUE);
677 return (FALSE);
681 /*******************************************************************************
683 * FUNCTION: AcpiDmFindNameByIndex
685 * PARAMETERS: Index - Index of array to check
686 * List - Array to reference
688 * RETURN: String from List or empty string
690 * DESCRIPTION: Finds and returns the char string located at the given index
691 * position in List.
693 ******************************************************************************/
695 static const char *
696 AcpiDmFindNameByIndex (
697 UINT64 Index,
698 const char **List)
700 const char *NameString;
701 UINT32 i;
704 /* Bounds check */
706 NameString = List[0];
707 i = 0;
709 while (NameString)
711 i++;
712 NameString = List[i];
715 if (Index >= i)
717 /* TBD: Add error msg */
719 return ("");
722 return (List[Index]);
726 /*******************************************************************************
728 * FUNCTION: AcpiDmPldBuffer
730 * PARAMETERS: Level - Current source code indentation level
731 * ByteData - Pointer to the byte list
732 * ByteCount - Length of the byte list
734 * RETURN: None
736 * DESCRIPTION: Dump and format the contents of a _PLD buffer object
738 ******************************************************************************/
740 #define ACPI_PLD_OUTPUT08 "%*.s%-22s = 0x%X,\n", ACPI_MUL_4 (Level), " "
741 #define ACPI_PLD_OUTPUT08P "%*.s%-22s = 0x%X)\n", ACPI_MUL_4 (Level), " "
742 #define ACPI_PLD_OUTPUT16 "%*.s%-22s = 0x%X,\n", ACPI_MUL_4 (Level), " "
743 #define ACPI_PLD_OUTPUT16P "%*.s%-22s = 0x%X)\n", ACPI_MUL_4 (Level), " "
744 #define ACPI_PLD_OUTPUT24 "%*.s%-22s = 0x%X,\n", ACPI_MUL_4 (Level), " "
745 #define ACPI_PLD_OUTPUTSTR "%*.s%-22s = \"%s\",\n", ACPI_MUL_4 (Level), " "
747 static void
748 AcpiDmPldBuffer (
749 UINT32 Level,
750 UINT8 *ByteData,
751 UINT32 ByteCount)
753 ACPI_PLD_INFO *PldInfo;
754 ACPI_STATUS Status;
757 /* Check for valid byte count */
759 if (ByteCount < ACPI_PLD_REV1_BUFFER_SIZE)
761 return;
764 /* Convert _PLD buffer to local _PLD struct */
766 Status = AcpiDecodePldBuffer (ByteData, ByteCount, &PldInfo);
767 if (ACPI_FAILURE (Status))
769 return;
772 AcpiOsPrintf ("\n");
774 /* First 32-bit dword */
776 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "PLD_Revision", PldInfo->Revision);
777 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "PLD_IgnoreColor", PldInfo->IgnoreColor);
778 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "PLD_Red", PldInfo->Red);
779 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "PLD_Green", PldInfo->Green);
780 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "PLD_Blue", PldInfo->Blue);
782 /* Second 32-bit dword */
784 AcpiOsPrintf (ACPI_PLD_OUTPUT16, "PLD_Width", PldInfo->Width);
785 AcpiOsPrintf (ACPI_PLD_OUTPUT16, "PLD_Height", PldInfo->Height);
787 /* Third 32-bit dword */
789 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "PLD_UserVisible", PldInfo->UserVisible);
790 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "PLD_Dock", PldInfo->Dock);
791 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "PLD_Lid", PldInfo->Lid);
792 AcpiOsPrintf (ACPI_PLD_OUTPUTSTR, "PLD_Panel",
793 AcpiDmFindNameByIndex(PldInfo->Panel, AcpiGbl_PldPanelList));
795 AcpiOsPrintf (ACPI_PLD_OUTPUTSTR, "PLD_VerticalPosition",
796 AcpiDmFindNameByIndex(PldInfo->VerticalPosition, AcpiGbl_PldVerticalPositionList));
798 AcpiOsPrintf (ACPI_PLD_OUTPUTSTR, "PLD_HorizontalPosition",
799 AcpiDmFindNameByIndex(PldInfo->HorizontalPosition, AcpiGbl_PldHorizontalPositionList));
801 AcpiOsPrintf (ACPI_PLD_OUTPUTSTR, "PLD_Shape",
802 AcpiDmFindNameByIndex(PldInfo->Shape, AcpiGbl_PldShapeList));
803 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "PLD_GroupOrientation", PldInfo->GroupOrientation);
805 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "PLD_GroupToken", PldInfo->GroupToken);
806 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "PLD_GroupPosition", PldInfo->GroupPosition);
807 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "PLD_Bay", PldInfo->Bay);
809 /* Fourth 32-bit dword */
811 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "PLD_Ejectable", PldInfo->Ejectable);
812 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "PLD_EjectRequired", PldInfo->OspmEjectRequired);
813 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "PLD_CabinetNumber", PldInfo->CabinetNumber);
814 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "PLD_CardCageNumber", PldInfo->CardCageNumber);
815 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "PLD_Reference", PldInfo->Reference);
816 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "PLD_Rotation", PldInfo->Rotation);
818 if (ByteCount >= ACPI_PLD_REV2_BUFFER_SIZE)
820 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "PLD_Order", PldInfo->Order);
822 /* Fifth 32-bit dword */
824 AcpiOsPrintf (ACPI_PLD_OUTPUT16, "PLD_VerticalOffset", PldInfo->VerticalOffset);
825 AcpiOsPrintf (ACPI_PLD_OUTPUT16P, "PLD_HorizontalOffset", PldInfo->HorizontalOffset);
827 else /* Rev 1 buffer */
829 AcpiOsPrintf (ACPI_PLD_OUTPUT08P, "PLD_Order", PldInfo->Order);
832 ACPI_FREE (PldInfo);
836 /*******************************************************************************
838 * FUNCTION: AcpiDmUnicode
840 * PARAMETERS: Op - Byte List op containing Unicode string
842 * RETURN: None
844 * DESCRIPTION: Dump Unicode string as a standard ASCII string. (Remove
845 * the extra zero bytes).
847 ******************************************************************************/
849 static void
850 AcpiDmUnicode (
851 ACPI_PARSE_OBJECT *Op)
853 UINT16 *WordData;
854 UINT32 WordCount;
855 UINT32 i;
856 int OutputValue;
859 /* Extract the buffer info as a WORD buffer */
861 WordData = ACPI_CAST_PTR (UINT16, Op->Named.Data);
862 WordCount = ACPI_DIV_2 (((UINT32) Op->Common.Value.Integer));
864 /* Write every other byte as an ASCII character */
866 AcpiOsPrintf ("\"");
867 for (i = 0; i < (WordCount - 1); i++)
869 OutputValue = (int) WordData[i];
871 /* Handle values that must be escaped */
873 if ((OutputValue == '\"') ||
874 (OutputValue == '\\'))
876 AcpiOsPrintf ("\\%c", OutputValue);
878 else if (!isprint (OutputValue))
880 AcpiOsPrintf ("\\x%2.2X", OutputValue);
882 else
884 AcpiOsPrintf ("%c", OutputValue);
888 AcpiOsPrintf ("\")");
892 /*******************************************************************************
894 * FUNCTION: AcpiDmGetHardwareIdType
896 * PARAMETERS: Op - Op to be examined
898 * RETURN: None
900 * DESCRIPTION: Determine the type of the argument to a _HID or _CID
901 * 1) Strings are allowed
902 * 2) If Integer, determine if it is a valid EISAID
904 ******************************************************************************/
906 static void
907 AcpiDmGetHardwareIdType (
908 ACPI_PARSE_OBJECT *Op)
910 UINT32 BigEndianId;
911 UINT32 Prefix[3];
912 UINT32 i;
915 switch (Op->Common.AmlOpcode)
917 case AML_STRING_OP:
919 /* Mark this string as an _HID/_CID string */
921 Op->Common.DisasmOpcode = ACPI_DASM_HID_STRING;
922 break;
924 case AML_WORD_OP:
925 case AML_DWORD_OP:
927 /* Determine if a Word/Dword is a valid encoded EISAID */
929 /* Swap from little-endian to big-endian to simplify conversion */
931 BigEndianId = AcpiUtDwordByteSwap ((UINT32) Op->Common.Value.Integer);
933 /* Create the 3 leading ASCII letters */
935 Prefix[0] = ((BigEndianId >> 26) & 0x1F) + 0x40;
936 Prefix[1] = ((BigEndianId >> 21) & 0x1F) + 0x40;
937 Prefix[2] = ((BigEndianId >> 16) & 0x1F) + 0x40;
939 /* Verify that all 3 are ascii and alpha */
941 for (i = 0; i < 3; i++)
943 if (!ACPI_IS_ASCII (Prefix[i]) ||
944 !isalpha (Prefix[i]))
946 return;
950 /* Mark this node as convertable to an EISA ID string */
952 Op->Common.DisasmOpcode = ACPI_DASM_EISAID;
953 break;
955 default:
956 break;
961 /*******************************************************************************
963 * FUNCTION: AcpiDmCheckForHardwareId
965 * PARAMETERS: Op - Op to be examined
967 * RETURN: None
969 * DESCRIPTION: Determine if a Name() Op is a _HID/_CID.
971 ******************************************************************************/
973 void
974 AcpiDmCheckForHardwareId (
975 ACPI_PARSE_OBJECT *Op)
977 UINT32 Name;
978 ACPI_PARSE_OBJECT *NextOp;
981 /* Get the NameSegment */
983 Name = AcpiPsGetName (Op);
984 if (!Name)
986 return;
989 NextOp = AcpiPsGetDepthNext (NULL, Op);
990 if (!NextOp)
992 return;
995 /* Check for _HID - has one argument */
997 if (ACPI_COMPARE_NAME (&Name, METHOD_NAME__HID))
999 AcpiDmGetHardwareIdType (NextOp);
1000 return;
1003 /* Exit if not _CID */
1005 if (!ACPI_COMPARE_NAME (&Name, METHOD_NAME__CID))
1007 return;
1010 /* _CID can contain a single argument or a package */
1012 if (NextOp->Common.AmlOpcode != AML_PACKAGE_OP)
1014 AcpiDmGetHardwareIdType (NextOp);
1015 return;
1018 /* _CID with Package: get the package length, check all elements */
1020 NextOp = AcpiPsGetDepthNext (NULL, NextOp);
1021 if (!NextOp)
1023 return;
1026 /* Don't need to use the length, just walk the peer list */
1028 NextOp = NextOp->Common.Next;
1029 while (NextOp)
1031 AcpiDmGetHardwareIdType (NextOp);
1032 NextOp = NextOp->Common.Next;
1037 /*******************************************************************************
1039 * FUNCTION: AcpiDmDecompressEisaId
1041 * PARAMETERS: EncodedId - Raw encoded EISA ID.
1043 * RETURN: None
1045 * DESCRIPTION: Convert an encoded EISAID back to the original ASCII String
1046 * and emit the correct ASL statement. If the ID is known, emit
1047 * a description of the ID as a comment.
1049 ******************************************************************************/
1051 void
1052 AcpiDmDecompressEisaId (
1053 UINT32 EncodedId)
1055 char IdBuffer[ACPI_EISAID_STRING_SIZE];
1056 const AH_DEVICE_ID *Info;
1059 /* Convert EISAID to a string an emit the statement */
1061 AcpiExEisaIdToString (IdBuffer, EncodedId);
1062 AcpiOsPrintf ("EisaId (\"%s\")", IdBuffer);
1064 /* If we know about the ID, emit the description */
1066 Info = AcpiAhMatchHardwareId (IdBuffer);
1067 if (Info)
1069 AcpiOsPrintf (" /* %s */", Info->Description);
1073 #endif