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