xref: /titanic_50/usr/src/uts/intel/io/acpica/disassembler/dmbuffer.c (revision 8a790dc67da1bad097488e7ad4a58af32d7ab24d)
1 /*******************************************************************************
2  *
3  * Module Name: dmbuffer - AML disassembler, buffer and string support
4  *
5  ******************************************************************************/
6 
7 /*
8  * Copyright (C) 2000 - 2016, 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  * 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.
29  *
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.
42  */
43 
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"
51 
52 
53 #define _COMPONENT          ACPI_CA_DEBUGGER
54         ACPI_MODULE_NAME    ("dmbuffer")
55 
56 /* Local prototypes */
57 
58 static void
59 AcpiDmUuid (
60     ACPI_PARSE_OBJECT       *Op);
61 
62 static void
63 AcpiDmUnicode (
64     ACPI_PARSE_OBJECT       *Op);
65 
66 static void
67 AcpiDmGetHardwareIdType (
68     ACPI_PARSE_OBJECT       *Op);
69 
70 static void
71 AcpiDmPldBuffer (
72     UINT32                  Level,
73     UINT8                   *ByteData,
74     UINT32                  ByteCount);
75 
76 static const char *
77 AcpiDmFindNameByIndex (
78     UINT64                  Index,
79     const char              **List);
80 
81 
82 #define ACPI_BUFFER_BYTES_PER_LINE      8
83 
84 
85 /*******************************************************************************
86  *
87  * FUNCTION:    AcpiDmDisasmByteList
88  *
89  * PARAMETERS:  Level               - Current source code indentation level
90  *              ByteData            - Pointer to the byte list
91  *              ByteCount           - Length of the byte list
92  *
93  * RETURN:      None
94  *
95  * DESCRIPTION: Dump an AML "ByteList" in Hex format. 8 bytes per line, prefixed
96  *              with the hex buffer offset.
97  *
98  ******************************************************************************/
99 
100 void
101 AcpiDmDisasmByteList (
102     UINT32                  Level,
103     UINT8                   *ByteData,
104     UINT32                  ByteCount)
105 {
106     UINT32                  i;
107     UINT32                  j;
108     UINT32                  CurrentIndex;
109     UINT8                   BufChar;
110 
111 
112     if (!ByteCount)
113     {
114         return;
115     }
116 
117     for (i = 0; i < ByteCount; i += ACPI_BUFFER_BYTES_PER_LINE)
118     {
119         /* Line indent and offset prefix for each new line */
120 
121         AcpiDmIndent (Level);
122         if (ByteCount > ACPI_BUFFER_BYTES_PER_LINE)
123         {
124             AcpiOsPrintf ("/* %04X */ ", i);
125         }
126 
127         /* Dump the actual hex values */
128 
129         for (j = 0; j < ACPI_BUFFER_BYTES_PER_LINE; j++)
130         {
131             CurrentIndex = i + j;
132             if (CurrentIndex >= ByteCount)
133             {
134                 /* Dump fill spaces */
135 
136                 AcpiOsPrintf ("      ");
137                 continue;
138             }
139 
140             AcpiOsPrintf (" 0x%2.2X", ByteData[CurrentIndex]);
141 
142             /* Add comma if there are more bytes to display */
143 
144             if (CurrentIndex < (ByteCount - 1))
145             {
146                 AcpiOsPrintf (",");
147             }
148             else
149             {
150                 AcpiOsPrintf (" ");
151             }
152         }
153 
154         /* Dump the ASCII equivalents within a comment */
155 
156         AcpiOsPrintf ("  /* ");
157         for (j = 0; j < ACPI_BUFFER_BYTES_PER_LINE; j++)
158         {
159             CurrentIndex = i + j;
160             if (CurrentIndex >= ByteCount)
161             {
162                 break;
163             }
164 
165             BufChar = ByteData[CurrentIndex];
166             if (isprint (BufChar))
167             {
168                 AcpiOsPrintf ("%c", BufChar);
169             }
170             else
171             {
172                 AcpiOsPrintf (".");
173             }
174         }
175 
176         /* Finished with this line */
177 
178         AcpiOsPrintf (" */\n");
179     }
180 }
181 
182 
183 /*******************************************************************************
184  *
185  * FUNCTION:    AcpiDmByteList
186  *
187  * PARAMETERS:  Info            - Parse tree walk info
188  *              Op              - Byte list op
189  *
190  * RETURN:      None
191  *
192  * DESCRIPTION: Dump a buffer byte list, handling the various types of buffers.
193  *              Buffer type must be already set in the Op DisasmOpcode.
194  *
195  ******************************************************************************/
196 
197 void
198 AcpiDmByteList (
199     ACPI_OP_WALK_INFO       *Info,
200     ACPI_PARSE_OBJECT       *Op)
201 {
202     UINT8                   *ByteData;
203     UINT32                  ByteCount;
204 
205 
206     ByteData = Op->Named.Data;
207     ByteCount = (UINT32) Op->Common.Value.Integer;
208 
209     /*
210      * The byte list belongs to a buffer, and can be produced by either
211      * a ResourceTemplate, Unicode, quoted string, or a plain byte list.
212      */
213     switch (Op->Common.Parent->Common.DisasmOpcode)
214     {
215     case ACPI_DASM_RESOURCE:
216 
217         AcpiDmResourceTemplate (
218             Info, Op->Common.Parent, ByteData, ByteCount);
219         break;
220 
221     case ACPI_DASM_STRING:
222 
223         AcpiDmIndent (Info->Level);
224         AcpiUtPrintString ((char *) ByteData, ACPI_UINT16_MAX);
225         AcpiOsPrintf ("\n");
226         break;
227 
228     case ACPI_DASM_UUID:
229 
230         AcpiDmUuid (Op);
231         break;
232 
233     case ACPI_DASM_UNICODE:
234 
235         AcpiDmUnicode (Op);
236         break;
237 
238     case ACPI_DASM_PLD_METHOD:
239 #if 0
240         AcpiDmDisasmByteList (Info->Level, ByteData, ByteCount);
241 #endif
242         AcpiDmPldBuffer (Info->Level, ByteData, ByteCount);
243         break;
244 
245     case ACPI_DASM_BUFFER:
246     default:
247         /*
248          * Not a resource, string, or unicode string.
249          * Just dump the buffer
250          */
251         AcpiDmDisasmByteList (Info->Level, ByteData, ByteCount);
252         break;
253     }
254 }
255 
256 
257 /*******************************************************************************
258  *
259  * FUNCTION:    AcpiDmIsUuidBuffer
260  *
261  * PARAMETERS:  Op              - Buffer Object to be examined
262  *
263  * RETURN:      TRUE if buffer contains a UUID
264  *
265  * DESCRIPTION: Determine if a buffer Op contains a UUID
266  *
267  * To help determine whether the buffer is a UUID versus a raw data buffer,
268  * there a are a couple bytes we can look at:
269  *
270  *    xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx
271  *
272  * The variant covered by the UUID specification is indicated by the two most
273  * significant bits of N being 1 0 (i.e., the hexadecimal N will always be
274  * 8, 9, A, or B).
275  *
276  * The variant covered by the UUID specification has five versions. For this
277  * variant, the four bits of M indicates the UUID version (i.e., the
278  * hexadecimal M will be either 1, 2, 3, 4, or 5).
279  *
280  ******************************************************************************/
281 
282 BOOLEAN
283 AcpiDmIsUuidBuffer (
284     ACPI_PARSE_OBJECT       *Op)
285 {
286     UINT8                   *ByteData;
287     UINT32                  ByteCount;
288     ACPI_PARSE_OBJECT       *SizeOp;
289     ACPI_PARSE_OBJECT       *NextOp;
290 
291 
292     /* Buffer size is the buffer argument */
293 
294     SizeOp = Op->Common.Value.Arg;
295 
296     /* Next, the initializer byte list to examine */
297 
298     NextOp = SizeOp->Common.Next;
299     if (!NextOp)
300     {
301         return (FALSE);
302     }
303 
304     /* Extract the byte list info */
305 
306     ByteData = NextOp->Named.Data;
307     ByteCount = (UINT32) NextOp->Common.Value.Integer;
308 
309     /* Byte count must be exactly 16 */
310 
311     if (ByteCount != UUID_BUFFER_LENGTH)
312     {
313         return (FALSE);
314     }
315 
316     /* Check for valid "M" and "N" values (see function header above) */
317 
318     if (((ByteData[7] & 0xF0) == 0x00) || /* M={1,2,3,4,5} */
319         ((ByteData[7] & 0xF0) > 0x50)  ||
320         ((ByteData[8] & 0xF0) < 0x80)  || /* N={8,9,A,B} */
321         ((ByteData[8] & 0xF0) > 0xB0))
322     {
323         return (FALSE);
324     }
325 
326     /* Ignore the Size argument in the disassembly of this buffer op */
327 
328     SizeOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
329     return (TRUE);
330 }
331 
332 
333 /*******************************************************************************
334  *
335  * FUNCTION:    AcpiDmUuid
336  *
337  * PARAMETERS:  Op              - Byte List op containing a UUID
338  *
339  * RETURN:      None
340  *
341  * DESCRIPTION: Dump a buffer containing a UUID as a standard ASCII string.
342  *
343  * Output Format:
344  * In its canonical form, the UUID is represented by a string containing 32
345  * lowercase hexadecimal digits, displayed in 5 groups separated by hyphens.
346  * The complete form is 8-4-4-4-12 for a total of 36 characters (32
347  * alphanumeric characters representing hex digits and 4 hyphens). In bytes,
348  * 4-2-2-2-6. Example:
349  *
350  *    ToUUID ("107ededd-d381-4fd7-8da9-08e9a6c79644")
351  *
352  ******************************************************************************/
353 
354 static void
355 AcpiDmUuid (
356     ACPI_PARSE_OBJECT       *Op)
357 {
358     UINT8                   *Data;
359     const char              *Description;
360 
361 
362     Data = ACPI_CAST_PTR (UINT8, Op->Named.Data);
363 
364     /* Emit the 36-byte UUID string in the proper format/order */
365 
366     AcpiOsPrintf (
367         "\"%2.2x%2.2x%2.2x%2.2x-"
368         "%2.2x%2.2x-"
369         "%2.2x%2.2x-"
370         "%2.2x%2.2x-"
371         "%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\")",
372         Data[3], Data[2], Data[1], Data[0],
373         Data[5], Data[4],
374         Data[7], Data[6],
375         Data[8], Data[9],
376         Data[10], Data[11], Data[12], Data[13], Data[14], Data[15]);
377 
378 #ifdef ACPI_APPLICATION
379     /* Dump the UUID description string if available */
380 
381     Description = AcpiAhMatchUuid (Data);
382     if (Description)
383     {
384         AcpiOsPrintf (" /* %s */", Description);
385     }
386 #endif
387 }
388 
389 
390 /*******************************************************************************
391  *
392  * FUNCTION:    AcpiDmIsUnicodeBuffer
393  *
394  * PARAMETERS:  Op              - Buffer Object to be examined
395  *
396  * RETURN:      TRUE if buffer contains a UNICODE string
397  *
398  * DESCRIPTION: Determine if a buffer Op contains a Unicode string
399  *
400  ******************************************************************************/
401 
402 BOOLEAN
403 AcpiDmIsUnicodeBuffer (
404     ACPI_PARSE_OBJECT       *Op)
405 {
406     UINT8                   *ByteData;
407     UINT32                  ByteCount;
408     UINT32                  WordCount;
409     ACPI_PARSE_OBJECT       *SizeOp;
410     ACPI_PARSE_OBJECT       *NextOp;
411     UINT32                  i;
412 
413 
414     /* Buffer size is the buffer argument */
415 
416     SizeOp = Op->Common.Value.Arg;
417 
418     /* Next, the initializer byte list to examine */
419 
420     NextOp = SizeOp->Common.Next;
421     if (!NextOp)
422     {
423         return (FALSE);
424     }
425 
426     /* Extract the byte list info */
427 
428     ByteData = NextOp->Named.Data;
429     ByteCount = (UINT32) NextOp->Common.Value.Integer;
430     WordCount = ACPI_DIV_2 (ByteCount);
431 
432     /*
433      * Unicode string must have an even number of bytes and last
434      * word must be zero
435      */
436     if ((!ByteCount)     ||
437          (ByteCount < 4) ||
438          (ByteCount & 1) ||
439         ((UINT16 *) (void *) ByteData)[WordCount - 1] != 0)
440     {
441         return (FALSE);
442     }
443 
444     /* For each word, 1st byte must be ascii (1-0x7F), 2nd byte must be zero */
445 
446     for (i = 0; i < (ByteCount - 2); i += 2)
447     {
448         if ((ByteData[i] == 0) ||
449             (ByteData[i] > 0x7F) ||
450             (ByteData[(ACPI_SIZE) i + 1] != 0))
451         {
452             return (FALSE);
453         }
454     }
455 
456     /* Ignore the Size argument in the disassembly of this buffer op */
457 
458     SizeOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
459     return (TRUE);
460 }
461 
462 
463 /*******************************************************************************
464  *
465  * FUNCTION:    AcpiDmIsStringBuffer
466  *
467  * PARAMETERS:  Op              - Buffer Object to be examined
468  *
469  * RETURN:      TRUE if buffer contains a ASCII string, FALSE otherwise
470  *
471  * DESCRIPTION: Determine if a buffer Op contains a ASCII string
472  *
473  ******************************************************************************/
474 
475 BOOLEAN
476 AcpiDmIsStringBuffer (
477     ACPI_PARSE_OBJECT       *Op)
478 {
479     UINT8                   *ByteData;
480     UINT32                  ByteCount;
481     ACPI_PARSE_OBJECT       *SizeOp;
482     ACPI_PARSE_OBJECT       *NextOp;
483     UINT32                  i;
484 
485 
486     /* Buffer size is the buffer argument */
487 
488     SizeOp = Op->Common.Value.Arg;
489 
490     /* Next, the initializer byte list to examine */
491 
492     NextOp = SizeOp->Common.Next;
493     if (!NextOp)
494     {
495         return (FALSE);
496     }
497 
498     /* Extract the byte list info */
499 
500     ByteData = NextOp->Named.Data;
501     ByteCount = (UINT32) NextOp->Common.Value.Integer;
502 
503     /* Last byte must be the null terminator */
504 
505     if ((!ByteCount)     ||
506          (ByteCount < 2) ||
507          (ByteData[ByteCount-1] != 0))
508     {
509         return (FALSE);
510     }
511 
512     for (i = 0; i < (ByteCount - 1); i++)
513     {
514         /* TBD: allow some escapes (non-ascii chars).
515          * they will be handled in the string output routine
516          */
517 
518         if (!isprint (ByteData[i]))
519         {
520             return (FALSE);
521         }
522     }
523 
524     return (TRUE);
525 }
526 
527 
528 /*******************************************************************************
529  *
530  * FUNCTION:    AcpiDmIsPldBuffer
531  *
532  * PARAMETERS:  Op                  - Buffer Object to be examined
533  *
534  * RETURN:      TRUE if buffer contains a ASCII string, FALSE otherwise
535  *
536  * DESCRIPTION: Determine if a buffer Op contains a _PLD structure
537  *
538  ******************************************************************************/
539 
540 BOOLEAN
541 AcpiDmIsPldBuffer (
542     ACPI_PARSE_OBJECT       *Op)
543 {
544     ACPI_NAMESPACE_NODE     *Node;
545     ACPI_PARSE_OBJECT       *SizeOp;
546     ACPI_PARSE_OBJECT       *ParentOp;
547 
548 
549     /* Buffer size is the buffer argument */
550 
551     SizeOp = Op->Common.Value.Arg;
552 
553     ParentOp = Op->Common.Parent;
554     if (!ParentOp)
555     {
556         return (FALSE);
557     }
558 
559     /* Check for form: Name(_PLD, Buffer() {}). Not legal, however */
560 
561     if (ParentOp->Common.AmlOpcode == AML_NAME_OP)
562     {
563         Node = ParentOp->Common.Node;
564 
565         if (ACPI_COMPARE_NAME (Node->Name.Ascii, METHOD_NAME__PLD))
566         {
567             /* Ignore the Size argument in the disassembly of this buffer op */
568 
569             SizeOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
570             return (TRUE);
571         }
572 
573         return (FALSE);
574     }
575 
576     /* Check for proper form: Name(_PLD, Package() {Buffer() {}}) */
577 
578     if (ParentOp->Common.AmlOpcode == AML_PACKAGE_OP)
579     {
580         ParentOp = ParentOp->Common.Parent;
581         if (!ParentOp)
582         {
583             return (FALSE);
584         }
585 
586         if (ParentOp->Common.AmlOpcode == AML_NAME_OP)
587         {
588             Node = ParentOp->Common.Node;
589 
590             if (ACPI_COMPARE_NAME (Node->Name.Ascii, METHOD_NAME__PLD))
591             {
592                 /* Ignore the Size argument in the disassembly of this buffer op */
593 
594                 SizeOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
595                 return (TRUE);
596             }
597         }
598     }
599 
600     return (FALSE);
601 }
602 
603 
604 /*******************************************************************************
605  *
606  * FUNCTION:    AcpiDmFindNameByIndex
607  *
608  * PARAMETERS:  Index               - Index of array to check
609  *              List                - Array to reference
610  *
611  * RETURN:      String from List or empty string
612  *
613  * DESCRIPTION: Finds and returns the char string located at the given index
614  *              position in List.
615  *
616  ******************************************************************************/
617 
618 static const char *
619 AcpiDmFindNameByIndex (
620     UINT64                  Index,
621     const char              **List)
622 {
623     const char              *NameString;
624     UINT32                  i;
625 
626 
627     /* Bounds check */
628 
629     NameString = List[0];
630     i = 0;
631 
632     while (NameString)
633     {
634         i++;
635         NameString = List[i];
636     }
637 
638     if (Index >= i)
639     {
640         /* TBD: Add error msg */
641 
642         return ("");
643     }
644 
645     return (List[Index]);
646 }
647 
648 
649 /*******************************************************************************
650  *
651  * FUNCTION:    AcpiDmPldBuffer
652  *
653  * PARAMETERS:  Level               - Current source code indentation level
654  *              ByteData            - Pointer to the byte list
655  *              ByteCount           - Length of the byte list
656  *
657  * RETURN:      None
658  *
659  * DESCRIPTION: Dump and format the contents of a _PLD buffer object
660  *
661  ******************************************************************************/
662 
663 #define ACPI_PLD_OUTPUT08   "%*.s%-22s = 0x%X,\n", ACPI_MUL_4 (Level), " "
664 #define ACPI_PLD_OUTPUT08P  "%*.s%-22s = 0x%X)\n", ACPI_MUL_4 (Level), " "
665 #define ACPI_PLD_OUTPUT16   "%*.s%-22s = 0x%X,\n", ACPI_MUL_4 (Level), " "
666 #define ACPI_PLD_OUTPUT16P  "%*.s%-22s = 0x%X)\n", ACPI_MUL_4 (Level), " "
667 #define ACPI_PLD_OUTPUT24   "%*.s%-22s = 0x%X,\n", ACPI_MUL_4 (Level), " "
668 #define ACPI_PLD_OUTPUTSTR  "%*.s%-22s = \"%s\",\n", ACPI_MUL_4 (Level), " "
669 
670 static void
671 AcpiDmPldBuffer (
672     UINT32                  Level,
673     UINT8                   *ByteData,
674     UINT32                  ByteCount)
675 {
676     ACPI_PLD_INFO           *PldInfo;
677     ACPI_STATUS             Status;
678 
679 
680     /* Check for valid byte count */
681 
682     if (ByteCount < ACPI_PLD_REV1_BUFFER_SIZE)
683     {
684         return;
685     }
686 
687     /* Convert _PLD buffer to local _PLD struct */
688 
689     Status = AcpiDecodePldBuffer (ByteData, ByteCount, &PldInfo);
690     if (ACPI_FAILURE (Status))
691     {
692         return;
693     }
694 
695     AcpiOsPrintf ("\n");
696 
697     /* First 32-bit dword */
698 
699     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_Revision", PldInfo->Revision);
700     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_IgnoreColor", PldInfo->IgnoreColor);
701     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_Red", PldInfo->Red);
702     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_Green", PldInfo->Green);
703     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_Blue", PldInfo->Blue);
704 
705     /* Second 32-bit dword */
706 
707     AcpiOsPrintf (ACPI_PLD_OUTPUT16,  "PLD_Width", PldInfo->Width);
708     AcpiOsPrintf (ACPI_PLD_OUTPUT16,  "PLD_Height", PldInfo->Height);
709 
710     /* Third 32-bit dword */
711 
712     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_UserVisible", PldInfo->UserVisible);
713     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_Dock", PldInfo->Dock);
714     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_Lid", PldInfo->Lid);
715     AcpiOsPrintf (ACPI_PLD_OUTPUTSTR, "PLD_Panel",
716         AcpiDmFindNameByIndex(PldInfo->Panel, AcpiGbl_PldPanelList));
717 
718     AcpiOsPrintf (ACPI_PLD_OUTPUTSTR, "PLD_VerticalPosition",
719         AcpiDmFindNameByIndex(PldInfo->VerticalPosition, AcpiGbl_PldVerticalPositionList));
720 
721     AcpiOsPrintf (ACPI_PLD_OUTPUTSTR, "PLD_HorizontalPosition",
722         AcpiDmFindNameByIndex(PldInfo->HorizontalPosition, AcpiGbl_PldHorizontalPositionList));
723 
724     AcpiOsPrintf (ACPI_PLD_OUTPUTSTR, "PLD_Shape",
725         AcpiDmFindNameByIndex(PldInfo->Shape, AcpiGbl_PldShapeList));
726     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_GroupOrientation", PldInfo->GroupOrientation);
727 
728     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_GroupToken", PldInfo->GroupToken);
729     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_GroupPosition", PldInfo->GroupPosition);
730     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_Bay", PldInfo->Bay);
731 
732     /* Fourth 32-bit dword */
733 
734     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_Ejectable", PldInfo->Ejectable);
735     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_EjectRequired", PldInfo->OspmEjectRequired);
736     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_CabinetNumber", PldInfo->CabinetNumber);
737     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_CardCageNumber", PldInfo->CardCageNumber);
738     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_Reference", PldInfo->Reference);
739     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_Rotation", PldInfo->Rotation);
740 
741     if (ByteCount >= ACPI_PLD_REV2_BUFFER_SIZE)
742     {
743         AcpiOsPrintf (ACPI_PLD_OUTPUT08, "PLD_Order", PldInfo->Order);
744 
745         /* Fifth 32-bit dword */
746 
747         AcpiOsPrintf (ACPI_PLD_OUTPUT16,  "PLD_VerticalOffset", PldInfo->VerticalOffset);
748         AcpiOsPrintf (ACPI_PLD_OUTPUT16P, "PLD_HorizontalOffset", PldInfo->HorizontalOffset);
749     }
750     else /* Rev 1 buffer */
751     {
752         AcpiOsPrintf (ACPI_PLD_OUTPUT08P, "PLD_Order", PldInfo->Order);
753     }
754 
755     ACPI_FREE (PldInfo);
756 }
757 
758 
759 /*******************************************************************************
760  *
761  * FUNCTION:    AcpiDmUnicode
762  *
763  * PARAMETERS:  Op              - Byte List op containing Unicode string
764  *
765  * RETURN:      None
766  *
767  * DESCRIPTION: Dump Unicode string as a standard ASCII string. (Remove
768  *              the extra zero bytes).
769  *
770  ******************************************************************************/
771 
772 static void
773 AcpiDmUnicode (
774     ACPI_PARSE_OBJECT       *Op)
775 {
776     UINT16                  *WordData;
777     UINT32                  WordCount;
778     UINT32                  i;
779     int                     OutputValue;
780 
781 
782     /* Extract the buffer info as a WORD buffer */
783 
784     WordData = ACPI_CAST_PTR (UINT16, Op->Named.Data);
785     WordCount = ACPI_DIV_2 (((UINT32) Op->Common.Value.Integer));
786 
787     /* Write every other byte as an ASCII character */
788 
789     AcpiOsPrintf ("\"");
790     for (i = 0; i < (WordCount - 1); i++)
791     {
792         OutputValue = (int) WordData[i];
793 
794         /* Handle values that must be escaped */
795 
796         if ((OutputValue == '\"') ||
797             (OutputValue == '\\'))
798         {
799             AcpiOsPrintf ("\\%c", OutputValue);
800         }
801         else if (!isprint (OutputValue))
802         {
803             AcpiOsPrintf ("\\x%2.2X", OutputValue);
804         }
805         else
806         {
807             AcpiOsPrintf ("%c", OutputValue);
808         }
809     }
810 
811     AcpiOsPrintf ("\")");
812 }
813 
814 
815 /*******************************************************************************
816  *
817  * FUNCTION:    AcpiDmGetHardwareIdType
818  *
819  * PARAMETERS:  Op              - Op to be examined
820  *
821  * RETURN:      None
822  *
823  * DESCRIPTION: Determine the type of the argument to a _HID or _CID
824  *              1) Strings are allowed
825  *              2) If Integer, determine if it is a valid EISAID
826  *
827  ******************************************************************************/
828 
829 static void
830 AcpiDmGetHardwareIdType (
831     ACPI_PARSE_OBJECT       *Op)
832 {
833     UINT32                  BigEndianId;
834     UINT32                  Prefix[3];
835     UINT32                  i;
836 
837 
838     switch (Op->Common.AmlOpcode)
839     {
840     case AML_STRING_OP:
841 
842         /* Mark this string as an _HID/_CID string */
843 
844         Op->Common.DisasmOpcode = ACPI_DASM_HID_STRING;
845         break;
846 
847     case AML_WORD_OP:
848     case AML_DWORD_OP:
849 
850         /* Determine if a Word/Dword is a valid encoded EISAID */
851 
852         /* Swap from little-endian to big-endian to simplify conversion */
853 
854         BigEndianId = AcpiUtDwordByteSwap ((UINT32) Op->Common.Value.Integer);
855 
856         /* Create the 3 leading ASCII letters */
857 
858         Prefix[0] = ((BigEndianId >> 26) & 0x1F) + 0x40;
859         Prefix[1] = ((BigEndianId >> 21) & 0x1F) + 0x40;
860         Prefix[2] = ((BigEndianId >> 16) & 0x1F) + 0x40;
861 
862         /* Verify that all 3 are ascii and alpha */
863 
864         for (i = 0; i < 3; i++)
865         {
866             if (!ACPI_IS_ASCII (Prefix[i]) ||
867                 !isalpha (Prefix[i]))
868             {
869                 return;
870             }
871         }
872 
873         /* Mark this node as convertable to an EISA ID string */
874 
875         Op->Common.DisasmOpcode = ACPI_DASM_EISAID;
876         break;
877 
878     default:
879         break;
880     }
881 }
882 
883 
884 /*******************************************************************************
885  *
886  * FUNCTION:    AcpiDmCheckForHardwareId
887  *
888  * PARAMETERS:  Op              - Op to be examined
889  *
890  * RETURN:      None
891  *
892  * DESCRIPTION: Determine if a Name() Op is a _HID/_CID.
893  *
894  ******************************************************************************/
895 
896 void
897 AcpiDmCheckForHardwareId (
898     ACPI_PARSE_OBJECT       *Op)
899 {
900     UINT32                  Name;
901     ACPI_PARSE_OBJECT       *NextOp;
902 
903 
904     /* Get the NameSegment */
905 
906     Name = AcpiPsGetName (Op);
907     if (!Name)
908     {
909         return;
910     }
911 
912     NextOp = AcpiPsGetDepthNext (NULL, Op);
913     if (!NextOp)
914     {
915         return;
916     }
917 
918     /* Check for _HID - has one argument */
919 
920     if (ACPI_COMPARE_NAME (&Name, METHOD_NAME__HID))
921     {
922         AcpiDmGetHardwareIdType (NextOp);
923         return;
924     }
925 
926     /* Exit if not _CID */
927 
928     if (!ACPI_COMPARE_NAME (&Name, METHOD_NAME__CID))
929     {
930         return;
931     }
932 
933     /* _CID can contain a single argument or a package */
934 
935     if (NextOp->Common.AmlOpcode != AML_PACKAGE_OP)
936     {
937         AcpiDmGetHardwareIdType (NextOp);
938         return;
939     }
940 
941     /* _CID with Package: get the package length, check all elements */
942 
943     NextOp = AcpiPsGetDepthNext (NULL, NextOp);
944     if (!NextOp)
945     {
946         return;
947     }
948 
949     /* Don't need to use the length, just walk the peer list */
950 
951     NextOp = NextOp->Common.Next;
952     while (NextOp)
953     {
954         AcpiDmGetHardwareIdType (NextOp);
955         NextOp = NextOp->Common.Next;
956     }
957 }
958 
959 
960 /*******************************************************************************
961  *
962  * FUNCTION:    AcpiDmDecompressEisaId
963  *
964  * PARAMETERS:  EncodedId       - Raw encoded EISA ID.
965  *
966  * RETURN:      None
967  *
968  * DESCRIPTION: Convert an encoded EISAID back to the original ASCII String
969  *              and emit the correct ASL statement. If the ID is known, emit
970  *              a description of the ID as a comment.
971  *
972  ******************************************************************************/
973 
974 void
975 AcpiDmDecompressEisaId (
976     UINT32                  EncodedId)
977 {
978     char                    IdBuffer[ACPI_EISAID_STRING_SIZE];
979     const AH_DEVICE_ID      *Info;
980 
981 
982     /* Convert EISAID to a string an emit the statement */
983 
984     AcpiExEisaIdToString (IdBuffer, EncodedId);
985     AcpiOsPrintf ("EisaId (\"%s\")", IdBuffer);
986 
987     /* If we know about the ID, emit the description */
988 
989     Info = AcpiAhMatchHardwareId (IdBuffer);
990     if (Info)
991     {
992         AcpiOsPrintf (" /* %s */", Info->Description);
993     }
994 }
995