OSDN Git Service

klibc基本機能実装. ACPICAの準備
[vaneos/DivergeMirror.git] / drivers / acpi / components / disassembler / dmbuffer.c
1 /*******************************************************************************
2  *
3  * Module Name: dmbuffer - AML disassembler, buffer and string support
4  *
5  ******************************************************************************/
6
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2015, Intel Corp.
12  * All rights reserved.
13  *
14  * 2. License
15  *
16  * 2.1. This is your license from Intel Corp. under its intellectual property
17  * rights. You may have additional license terms from the party that provided
18  * you this software, covering your right to use that party's intellectual
19  * property rights.
20  *
21  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22  * copy of the source code appearing in this file ("Covered Code") an
23  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24  * base code distributed originally by Intel ("Original Intel Code") to copy,
25  * make derivatives, distribute, use and display any portion of the Covered
26  * Code in any form, with the right to sublicense such rights; and
27  *
28  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29  * license (with the right to sublicense), under only those claims of Intel
30  * patents that are infringed by the Original Intel Code, to make, use, sell,
31  * offer to sell, and import the Covered Code and derivative works thereof
32  * solely to the minimum extent necessary to exercise the above copyright
33  * license, and in no event shall the patent license extend to any additions
34  * to or modifications of the Original Intel Code. No other license or right
35  * is granted directly or by implication, estoppel or otherwise;
36  *
37  * The above copyright and patent license is granted only if the following
38  * conditions are met:
39  *
40  * 3. Conditions
41  *
42  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43  * Redistribution of source code of any substantial portion of the Covered
44  * Code or modification with rights to further distribute source must include
45  * the above Copyright Notice, the above License, this list of Conditions,
46  * and the following Disclaimer and Export Compliance provision. In addition,
47  * Licensee must cause all Covered Code to which Licensee contributes to
48  * contain a file documenting the changes Licensee made to create that Covered
49  * Code and the date of any change. Licensee must include in that file the
50  * documentation of any changes made by any predecessor Licensee. Licensee
51  * must include a prominent statement that the modification is derived,
52  * directly or indirectly, from Original Intel Code.
53  *
54  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55  * Redistribution of source code of any substantial portion of the Covered
56  * Code or modification without rights to further distribute source must
57  * include the following Disclaimer and Export Compliance provision in the
58  * documentation and/or other materials provided with distribution. In
59  * addition, Licensee may not authorize further sublicense of source of any
60  * portion of the Covered Code, and must include terms to the effect that the
61  * license from Licensee to its licensee is limited to the intellectual
62  * property embodied in the software Licensee provides to its licensee, and
63  * not to intellectual property embodied in modifications its licensee may
64  * make.
65  *
66  * 3.3. Redistribution of Executable. Redistribution in executable form of any
67  * substantial portion of the Covered Code or modification must reproduce the
68  * above Copyright Notice, and the following Disclaimer and Export Compliance
69  * provision in the documentation and/or other materials provided with the
70  * distribution.
71  *
72  * 3.4. Intel retains all right, title, and interest in and to the Original
73  * Intel Code.
74  *
75  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76  * Intel shall be used in advertising or otherwise to promote the sale, use or
77  * other dealings in products derived from or relating to the Covered Code
78  * without prior written authorization from Intel.
79  *
80  * 4. Disclaimer and Export Compliance
81  *
82  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88  * PARTICULAR PURPOSE.
89  *
90  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97  * LIMITED REMEDY.
98  *
99  * 4.3. Licensee shall not export, either directly or indirectly, any of this
100  * software or system incorporating such software without first obtaining any
101  * required license or other approval from the U. S. Department of Commerce or
102  * any other agency or department of the United States Government. In the
103  * event Licensee exports any such software from the United States or
104  * re-exports any such software from a foreign destination, Licensee shall
105  * ensure that the distribution and export/re-export of the software is in
106  * compliance with all laws, regulations, orders, or other restrictions of the
107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108  * any of its subsidiaries will export/re-export any technical data, process,
109  * software, or service, directly or indirectly, to any country for which the
110  * United States government or any agency thereof requires an export license,
111  * other governmental approval, or letter of assurance, without first obtaining
112  * such license, approval or letter.
113  *
114  *****************************************************************************/
115
116 #include "acpi.h"
117 #include "accommon.h"
118 #include "acutils.h"
119 #include "acdisasm.h"
120 #include "acparser.h"
121 #include "amlcode.h"
122 #include "acinterp.h"
123
124
125 #ifdef ACPI_DISASSEMBLER
126
127 #define _COMPONENT          ACPI_CA_DEBUGGER
128         ACPI_MODULE_NAME    ("dmbuffer")
129
130 /* Local prototypes */
131
132 static void
133 AcpiDmUuid (
134     ACPI_PARSE_OBJECT       *Op);
135
136 static void
137 AcpiDmUnicode (
138     ACPI_PARSE_OBJECT       *Op);
139
140 static void
141 AcpiDmGetHardwareIdType (
142     ACPI_PARSE_OBJECT       *Op);
143
144 static void
145 AcpiDmPldBuffer (
146     UINT32                  Level,
147     UINT8                   *ByteData,
148     UINT32                  ByteCount);
149
150
151 #define ACPI_BUFFER_BYTES_PER_LINE      8
152
153
154 /* Strings for ToPld */
155
156 static char *DmPanelList[] =
157 {
158     "TOP",
159     "BOTTOM",
160     "LEFT",
161     "RIGHT",
162     "FRONT",
163     "BACK",
164     "UNKNOWN",
165     NULL
166 };
167
168 static char *DmVerticalPositionList[] =
169 {
170     "UPPER",
171     "CENTER",
172     "LOWER",
173     NULL
174 };
175
176 static char *DmHorizontalPositionList[] =
177 {
178     "LEFT",
179     "CENTER",
180     "RIGHT",
181     NULL
182 };
183
184 static char *DmShapeList[] =
185 {
186     "ROUND",
187     "OVAL",
188     "SQUARE",
189     "VERTICALRECTANGLE",
190     "HORIZONTALRECTANGLE",
191     "VERTICALTRAPEZOID",
192     "HORIZONTALTRAPEZOID",
193     "UNKNOWN",
194     "CHAMFERED",
195     NULL
196 };
197
198
199 /*******************************************************************************
200  *
201  * FUNCTION:    AcpiDmDisasmByteList
202  *
203  * PARAMETERS:  Level               - Current source code indentation level
204  *              ByteData            - Pointer to the byte list
205  *              ByteCount           - Length of the byte list
206  *
207  * RETURN:      None
208  *
209  * DESCRIPTION: Dump an AML "ByteList" in Hex format. 8 bytes per line, prefixed
210  *              with the hex buffer offset.
211  *
212  ******************************************************************************/
213
214 void
215 AcpiDmDisasmByteList (
216     UINT32                  Level,
217     UINT8                   *ByteData,
218     UINT32                  ByteCount)
219 {
220     UINT32                  i;
221     UINT32                  j;
222     UINT32                  CurrentIndex;
223     UINT8                   BufChar;
224
225
226     if (!ByteCount)
227     {
228         return;
229     }
230
231     for (i = 0; i < ByteCount; i += ACPI_BUFFER_BYTES_PER_LINE)
232     {
233         /* Line indent and offset prefix for each new line */
234
235         AcpiDmIndent (Level);
236         if (ByteCount > ACPI_BUFFER_BYTES_PER_LINE)
237         {
238             AcpiOsPrintf ("/* %04X */ ", i);
239         }
240
241         /* Dump the actual hex values */
242
243         for (j = 0; j < ACPI_BUFFER_BYTES_PER_LINE; j++)
244         {
245             CurrentIndex = i + j;
246             if (CurrentIndex >= ByteCount)
247             {
248                 /* Dump fill spaces */
249
250                 AcpiOsPrintf ("      ");
251                 continue;
252             }
253
254             AcpiOsPrintf (" 0x%2.2X", ByteData[CurrentIndex]);
255
256             /* Add comma if there are more bytes to display */
257
258             if (CurrentIndex < (ByteCount - 1))
259             {
260                 AcpiOsPrintf (",");
261             }
262             else
263             {
264                 AcpiOsPrintf (" ");
265             }
266         }
267
268         /* Dump the ASCII equivalents within a comment */
269
270         AcpiOsPrintf ("  /* ");
271         for (j = 0; j < ACPI_BUFFER_BYTES_PER_LINE; j++)
272         {
273             CurrentIndex = i + j;
274             if (CurrentIndex >= ByteCount)
275             {
276                 break;
277             }
278
279             BufChar = ByteData[CurrentIndex];
280             if (ACPI_IS_PRINT (BufChar))
281             {
282                 AcpiOsPrintf ("%c", BufChar);
283             }
284             else
285             {
286                 AcpiOsPrintf (".");
287             }
288         }
289
290         /* Finished with this line */
291
292         AcpiOsPrintf (" */\n");
293     }
294 }
295
296
297 /*******************************************************************************
298  *
299  * FUNCTION:    AcpiDmByteList
300  *
301  * PARAMETERS:  Info            - Parse tree walk info
302  *              Op              - Byte list op
303  *
304  * RETURN:      None
305  *
306  * DESCRIPTION: Dump a buffer byte list, handling the various types of buffers.
307  *              Buffer type must be already set in the Op DisasmOpcode.
308  *
309  ******************************************************************************/
310
311 void
312 AcpiDmByteList (
313     ACPI_OP_WALK_INFO       *Info,
314     ACPI_PARSE_OBJECT       *Op)
315 {
316     UINT8                   *ByteData;
317     UINT32                  ByteCount;
318
319
320     ByteData = Op->Named.Data;
321     ByteCount = (UINT32) Op->Common.Value.Integer;
322
323     /*
324      * The byte list belongs to a buffer, and can be produced by either
325      * a ResourceTemplate, Unicode, quoted string, or a plain byte list.
326      */
327     switch (Op->Common.Parent->Common.DisasmOpcode)
328     {
329     case ACPI_DASM_RESOURCE:
330
331         AcpiDmResourceTemplate (Info, Op->Common.Parent, ByteData, ByteCount);
332         break;
333
334     case ACPI_DASM_STRING:
335
336         AcpiDmIndent (Info->Level);
337         AcpiUtPrintString ((char *) ByteData, ACPI_UINT16_MAX);
338         AcpiOsPrintf ("\n");
339         break;
340
341     case ACPI_DASM_UUID:
342
343         AcpiDmUuid (Op);
344         break;
345
346     case ACPI_DASM_UNICODE:
347
348         AcpiDmUnicode (Op);
349         break;
350
351     case ACPI_DASM_PLD_METHOD:
352 #if 0
353         AcpiDmDisasmByteList (Info->Level, ByteData, ByteCount);
354 #endif
355         AcpiDmPldBuffer (Info->Level, ByteData, ByteCount);
356         break;
357
358     case ACPI_DASM_BUFFER:
359     default:
360         /*
361          * Not a resource, string, or unicode string.
362          * Just dump the buffer
363          */
364         AcpiDmDisasmByteList (Info->Level, ByteData, ByteCount);
365         break;
366     }
367 }
368
369
370 /*******************************************************************************
371  *
372  * FUNCTION:    AcpiDmIsUuidBuffer
373  *
374  * PARAMETERS:  Op              - Buffer Object to be examined
375  *
376  * RETURN:      TRUE if buffer contains a UUID
377  *
378  * DESCRIPTION: Determine if a buffer Op contains a UUID
379  *
380  * To help determine whether the buffer is a UUID versus a raw data buffer,
381  * there a are a couple bytes we can look at:
382  *
383  *    xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx
384  *
385  * The variant covered by the UUID specification is indicated by the two most
386  * significant bits of N being 1 0 (i.e., the hexadecimal N will always be
387  * 8, 9, A, or B).
388  *
389  * The variant covered by the UUID specification has five versions. For this
390  * variant, the four bits of M indicates the UUID version (i.e., the
391  * hexadecimal M will be either 1, 2, 3, 4, or 5).
392  *
393  ******************************************************************************/
394
395 BOOLEAN
396 AcpiDmIsUuidBuffer (
397     ACPI_PARSE_OBJECT       *Op)
398 {
399     UINT8                   *ByteData;
400     UINT32                  ByteCount;
401     ACPI_PARSE_OBJECT       *SizeOp;
402     ACPI_PARSE_OBJECT       *NextOp;
403
404
405     /* Buffer size is the buffer argument */
406
407     SizeOp = Op->Common.Value.Arg;
408
409     /* Next, the initializer byte list to examine */
410
411     NextOp = SizeOp->Common.Next;
412     if (!NextOp)
413     {
414         return (FALSE);
415     }
416
417     /* Extract the byte list info */
418
419     ByteData = NextOp->Named.Data;
420     ByteCount = (UINT32) NextOp->Common.Value.Integer;
421
422     /* Byte count must be exactly 16 */
423
424     if (ByteCount != UUID_BUFFER_LENGTH)
425     {
426         return (FALSE);
427     }
428
429     /* Check for valid "M" and "N" values (see function header above) */
430
431     if (((ByteData[7] & 0xF0) == 0x00) || /* M={1,2,3,4,5} */
432         ((ByteData[7] & 0xF0) > 0x50)  ||
433         ((ByteData[8] & 0xF0) < 0x80)  || /* N={8,9,A,B} */
434         ((ByteData[8] & 0xF0) > 0xB0))
435     {
436         return (FALSE);
437     }
438
439     /* Ignore the Size argument in the disassembly of this buffer op */
440
441     SizeOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
442     return (TRUE);
443 }
444
445
446 /*******************************************************************************
447  *
448  * FUNCTION:    AcpiDmUuid
449  *
450  * PARAMETERS:  Op              - Byte List op containing a UUID
451  *
452  * RETURN:      None
453  *
454  * DESCRIPTION: Dump a buffer containing a UUID as a standard ASCII string.
455  *
456  * Output Format:
457  * In its canonical form, the UUID is represented by a string containing 32
458  * lowercase hexadecimal digits, displayed in 5 groups separated by hyphens.
459  * The complete form is 8-4-4-4-12 for a total of 36 characters (32
460  * alphanumeric characters representing hex digits and 4 hyphens). In bytes,
461  * 4-2-2-2-6. Example:
462  *
463  *    ToUUID ("107ededd-d381-4fd7-8da9-08e9a6c79644")
464  *
465  ******************************************************************************/
466
467 static void
468 AcpiDmUuid (
469     ACPI_PARSE_OBJECT       *Op)
470 {
471     UINT8                   *Data;
472     const char              *Description;
473
474
475     Data = ACPI_CAST_PTR (UINT8, Op->Named.Data);
476
477     /* Emit the 36-byte UUID string in the proper format/order */
478
479     AcpiOsPrintf (
480         "\"%2.2x%2.2x%2.2x%2.2x-"
481         "%2.2x%2.2x-"
482         "%2.2x%2.2x-"
483         "%2.2x%2.2x-"
484         "%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\")",
485         Data[3], Data[2], Data[1], Data[0],
486         Data[5], Data[4],
487         Data[7], Data[6],
488         Data[8], Data[9],
489         Data[10], Data[11], Data[12], Data[13], Data[14], Data[15]);
490
491     /* Dump the UUID description string if available */
492
493     Description = AcpiAhMatchUuid (Data);
494     if (Description)
495     {
496         AcpiOsPrintf (" /* %s */", Description);
497     }
498 }
499
500
501 /*******************************************************************************
502  *
503  * FUNCTION:    AcpiDmIsUnicodeBuffer
504  *
505  * PARAMETERS:  Op              - Buffer Object to be examined
506  *
507  * RETURN:      TRUE if buffer contains a UNICODE string
508  *
509  * DESCRIPTION: Determine if a buffer Op contains a Unicode string
510  *
511  ******************************************************************************/
512
513 BOOLEAN
514 AcpiDmIsUnicodeBuffer (
515     ACPI_PARSE_OBJECT       *Op)
516 {
517     UINT8                   *ByteData;
518     UINT32                  ByteCount;
519     UINT32                  WordCount;
520     ACPI_PARSE_OBJECT       *SizeOp;
521     ACPI_PARSE_OBJECT       *NextOp;
522     UINT32                  i;
523
524
525     /* Buffer size is the buffer argument */
526
527     SizeOp = Op->Common.Value.Arg;
528
529     /* Next, the initializer byte list to examine */
530
531     NextOp = SizeOp->Common.Next;
532     if (!NextOp)
533     {
534         return (FALSE);
535     }
536
537     /* Extract the byte list info */
538
539     ByteData = NextOp->Named.Data;
540     ByteCount = (UINT32) NextOp->Common.Value.Integer;
541     WordCount = ACPI_DIV_2 (ByteCount);
542
543     /*
544      * Unicode string must have an even number of bytes and last
545      * word must be zero
546      */
547     if ((!ByteCount)     ||
548          (ByteCount < 4) ||
549          (ByteCount & 1) ||
550         ((UINT16 *) (void *) ByteData)[WordCount - 1] != 0)
551     {
552         return (FALSE);
553     }
554
555     /* For each word, 1st byte must be ascii (1-0x7F), 2nd byte must be zero */
556
557     for (i = 0; i < (ByteCount - 2); i += 2)
558     {
559         if ((ByteData[i] == 0) ||
560             (ByteData[i] > 0x7F) ||
561             (ByteData[(ACPI_SIZE) i + 1] != 0))
562         {
563             return (FALSE);
564         }
565     }
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
574 /*******************************************************************************
575  *
576  * FUNCTION:    AcpiDmIsStringBuffer
577  *
578  * PARAMETERS:  Op              - Buffer Object to be examined
579  *
580  * RETURN:      TRUE if buffer contains a ASCII string, FALSE otherwise
581  *
582  * DESCRIPTION: Determine if a buffer Op contains a ASCII string
583  *
584  ******************************************************************************/
585
586 BOOLEAN
587 AcpiDmIsStringBuffer (
588     ACPI_PARSE_OBJECT       *Op)
589 {
590     UINT8                   *ByteData;
591     UINT32                  ByteCount;
592     ACPI_PARSE_OBJECT       *SizeOp;
593     ACPI_PARSE_OBJECT       *NextOp;
594     UINT32                  i;
595
596
597     /* Buffer size is the buffer argument */
598
599     SizeOp = Op->Common.Value.Arg;
600
601     /* Next, the initializer byte list to examine */
602
603     NextOp = SizeOp->Common.Next;
604     if (!NextOp)
605     {
606         return (FALSE);
607     }
608
609     /* Extract the byte list info */
610
611     ByteData = NextOp->Named.Data;
612     ByteCount = (UINT32) NextOp->Common.Value.Integer;
613
614     /* Last byte must be the null terminator */
615
616     if ((!ByteCount)     ||
617          (ByteCount < 2) ||
618          (ByteData[ByteCount-1] != 0))
619     {
620         return (FALSE);
621     }
622
623     for (i = 0; i < (ByteCount - 1); i++)
624     {
625         /* TBD: allow some escapes (non-ascii chars).
626          * they will be handled in the string output routine
627          */
628
629         if (!ACPI_IS_PRINT (ByteData[i]))
630         {
631             return (FALSE);
632         }
633     }
634
635     return (TRUE);
636 }
637
638
639 /*******************************************************************************
640  *
641  * FUNCTION:    AcpiDmIsPldBuffer
642  *
643  * PARAMETERS:  Op                  - Buffer Object to be examined
644  *
645  * RETURN:      TRUE if buffer contains a ASCII string, FALSE otherwise
646  *
647  * DESCRIPTION: Determine if a buffer Op contains a _PLD structure
648  *
649  ******************************************************************************/
650
651 BOOLEAN
652 AcpiDmIsPldBuffer (
653     ACPI_PARSE_OBJECT       *Op)
654 {
655     ACPI_NAMESPACE_NODE     *Node;
656     ACPI_PARSE_OBJECT       *SizeOp;
657     ACPI_PARSE_OBJECT       *ParentOp;
658
659
660     /* Buffer size is the buffer argument */
661
662     SizeOp = Op->Common.Value.Arg;
663
664     ParentOp = Op->Common.Parent;
665     if (!ParentOp)
666     {
667         return (FALSE);
668     }
669
670     /* Check for form: Name(_PLD, Buffer() {}). Not legal, however */
671
672     if (ParentOp->Common.AmlOpcode == AML_NAME_OP)
673     {
674         Node = ParentOp->Common.Node;
675
676         if (ACPI_COMPARE_NAME (Node->Name.Ascii, METHOD_NAME__PLD))
677         {
678             /* Ignore the Size argument in the disassembly of this buffer op */
679
680             SizeOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
681             return (TRUE);
682         }
683
684         return (FALSE);
685     }
686
687     /* Check for proper form: Name(_PLD, Package() {Buffer() {}}) */
688
689     if (ParentOp->Common.AmlOpcode == AML_PACKAGE_OP)
690     {
691         ParentOp = ParentOp->Common.Parent;
692         if (!ParentOp)
693         {
694             return (FALSE);
695         }
696
697         if (ParentOp->Common.AmlOpcode == AML_NAME_OP)
698         {
699             Node = ParentOp->Common.Node;
700
701             if (ACPI_COMPARE_NAME (Node->Name.Ascii, METHOD_NAME__PLD))
702             {
703                 /* Ignore the Size argument in the disassembly of this buffer op */
704
705                 SizeOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
706                 return (TRUE);
707             }
708         }
709     }
710
711     return (FALSE);
712 }
713
714
715 /*******************************************************************************
716  *
717  * FUNCTION:    AcpiDmFindNameByIndex
718  *
719  * PARAMETERS:  Index               - Index of array to check
720  *              List                - Array to reference
721  *
722  * RETURN:      String from List or empty string
723  *
724  * DESCRIPTION: Finds and returns the char string located at the given index
725  *              position in List.
726  *
727  ******************************************************************************/
728
729 static char *
730 AcpiDmFindNameByIndex (
731     UINT64                  Index,
732     char                    **List)
733 {
734     char                     *Str;
735     UINT32                   i;
736
737
738     /* Bounds check */
739
740     Str = List[0];
741     i = 0;
742
743     while(Str)
744     {
745         i++;
746         Str = List[i];
747     }
748
749     if (Index >= i)
750     {
751         /* TBD: Add error msg */
752
753         return ("");
754     }
755
756     return (List[Index]);
757 }
758
759
760 /*******************************************************************************
761  *
762  * FUNCTION:    AcpiDmPldBuffer
763  *
764  * PARAMETERS:  Level               - Current source code indentation level
765  *              ByteData            - Pointer to the byte list
766  *              ByteCount           - Length of the byte list
767  *
768  * RETURN:      None
769  *
770  * DESCRIPTION: Dump and format the contents of a _PLD buffer object
771  *
772  ******************************************************************************/
773
774 #define ACPI_PLD_OUTPUT08   "%*.s%-18s = 0x%X,\n", ACPI_MUL_4 (Level), " "
775 #define ACPI_PLD_OUTPUT08P  "%*.s%-18s = 0x%X)\n", ACPI_MUL_4 (Level), " "
776 #define ACPI_PLD_OUTPUT16   "%*.s%-18s = 0x%X,\n", ACPI_MUL_4 (Level), " "
777 #define ACPI_PLD_OUTPUT16P  "%*.s%-18s = 0x%X)\n", ACPI_MUL_4 (Level), " "
778 #define ACPI_PLD_OUTPUT24   "%*.s%-18s = 0x%X,\n", ACPI_MUL_4 (Level), " "
779 #define ACPI_PLD_OUTPUTSTR  "%*.s%-18s = \"%s\",\n", ACPI_MUL_4 (Level), " "
780
781 static void
782 AcpiDmPldBuffer (
783     UINT32                  Level,
784     UINT8                   *ByteData,
785     UINT32                  ByteCount)
786 {
787     ACPI_PLD_INFO           *PldInfo;
788     ACPI_STATUS             Status;
789
790
791     /* Check for valid byte count */
792
793     if (ByteCount < ACPI_PLD_REV1_BUFFER_SIZE)
794     {
795         return;
796     }
797
798     /* Convert _PLD buffer to local _PLD struct */
799
800     Status = AcpiDecodePldBuffer (ByteData, ByteCount, &PldInfo);
801     if (ACPI_FAILURE (Status))
802     {
803         return;
804     }
805
806     AcpiOsPrintf ("\n");
807
808     /* First 32-bit dword */
809
810     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_Revision", PldInfo->Revision);
811     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_IgnoreColor", PldInfo->IgnoreColor);
812     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_Red", PldInfo->Red);
813     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_Green", PldInfo->Green);
814     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_Blue", PldInfo->Blue);
815
816     /* Second 32-bit dword */
817
818     AcpiOsPrintf (ACPI_PLD_OUTPUT16,  "PLD_Width", PldInfo->Width);
819     AcpiOsPrintf (ACPI_PLD_OUTPUT16,  "PLD_Height", PldInfo->Height);
820
821     /* Third 32-bit dword */
822
823     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_UserVisible", PldInfo->UserVisible);
824     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_Dock", PldInfo->Dock);
825     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_Lid", PldInfo->Lid);
826     AcpiOsPrintf (ACPI_PLD_OUTPUTSTR, "PLD_Panel",
827         AcpiDmFindNameByIndex(PldInfo->Panel, DmPanelList));
828     AcpiOsPrintf (ACPI_PLD_OUTPUTSTR, "PLD_VerticalPosition",
829         AcpiDmFindNameByIndex(PldInfo->VerticalPosition, DmVerticalPositionList));
830     AcpiOsPrintf (ACPI_PLD_OUTPUTSTR, "PLD_HorizontalPosition",
831         AcpiDmFindNameByIndex(PldInfo->HorizontalPosition, DmHorizontalPositionList));
832     AcpiOsPrintf (ACPI_PLD_OUTPUTSTR, "PLD_Shape",
833         AcpiDmFindNameByIndex(PldInfo->Shape, DmShapeList));
834     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_GroupOrientation", PldInfo->GroupOrientation);
835     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_GroupToken", PldInfo->GroupToken);
836     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_GroupPosition", PldInfo->GroupPosition);
837     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_Bay", PldInfo->Bay);
838
839     /* Fourth 32-bit dword */
840
841     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_Ejectable", PldInfo->Ejectable);
842     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_EjectRequired", PldInfo->OspmEjectRequired);
843     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_CabinetNumber", PldInfo->CabinetNumber);
844     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_CardCageNumber", PldInfo->CardCageNumber);
845     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_Reference", PldInfo->Reference);
846     AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_Rotation", PldInfo->Rotation);
847
848     if (ByteCount < ACPI_PLD_REV1_BUFFER_SIZE)
849     {
850         AcpiOsPrintf (ACPI_PLD_OUTPUT08P, "PLD_Order", PldInfo->Order);
851     }
852     else
853     {
854         AcpiOsPrintf (ACPI_PLD_OUTPUT08, "PLD_Order", PldInfo->Order);
855     }
856
857     /* Fifth 32-bit dword */
858
859     if (ByteCount >= ACPI_PLD_REV1_BUFFER_SIZE)
860     {
861         AcpiOsPrintf (ACPI_PLD_OUTPUT16, "PLD_VerticalOffset", PldInfo->VerticalOffset);
862         AcpiOsPrintf (ACPI_PLD_OUTPUT16P, "PLD_HorizontalOffset", PldInfo->HorizontalOffset);
863     }
864
865     ACPI_FREE (PldInfo);
866 }
867
868
869 /*******************************************************************************
870  *
871  * FUNCTION:    AcpiDmUnicode
872  *
873  * PARAMETERS:  Op              - Byte List op containing Unicode string
874  *
875  * RETURN:      None
876  *
877  * DESCRIPTION: Dump Unicode string as a standard ASCII string. (Remove
878  *              the extra zero bytes).
879  *
880  ******************************************************************************/
881
882 static void
883 AcpiDmUnicode (
884     ACPI_PARSE_OBJECT       *Op)
885 {
886     UINT16                  *WordData;
887     UINT32                  WordCount;
888     UINT32                  i;
889     int                     OutputValue;
890
891
892     /* Extract the buffer info as a WORD buffer */
893
894     WordData = ACPI_CAST_PTR (UINT16, Op->Named.Data);
895     WordCount = ACPI_DIV_2 (((UINT32) Op->Common.Value.Integer));
896
897     /* Write every other byte as an ASCII character */
898
899     AcpiOsPrintf ("\"");
900     for (i = 0; i < (WordCount - 1); i++)
901     {
902         OutputValue = (int) WordData[i];
903
904         /* Handle values that must be escaped */
905
906         if ((OutputValue == '\"') ||
907             (OutputValue == '\\'))
908         {
909             AcpiOsPrintf ("\\%c", OutputValue);
910         }
911         else if (!ACPI_IS_PRINT (OutputValue))
912         {
913             AcpiOsPrintf ("\\x%2.2X", OutputValue);
914         }
915         else
916         {
917             AcpiOsPrintf ("%c", OutputValue);
918         }
919     }
920
921     AcpiOsPrintf ("\")");
922 }
923
924
925 /*******************************************************************************
926  *
927  * FUNCTION:    AcpiDmGetHardwareIdType
928  *
929  * PARAMETERS:  Op              - Op to be examined
930  *
931  * RETURN:      None
932  *
933  * DESCRIPTION: Determine the type of the argument to a _HID or _CID
934  *              1) Strings are allowed
935  *              2) If Integer, determine if it is a valid EISAID
936  *
937  ******************************************************************************/
938
939 static void
940 AcpiDmGetHardwareIdType (
941     ACPI_PARSE_OBJECT       *Op)
942 {
943     UINT32                  BigEndianId;
944     UINT32                  Prefix[3];
945     UINT32                  i;
946
947
948     switch (Op->Common.AmlOpcode)
949     {
950     case AML_STRING_OP:
951
952         /* Mark this string as an _HID/_CID string */
953
954         Op->Common.DisasmOpcode = ACPI_DASM_HID_STRING;
955         break;
956
957     case AML_WORD_OP:
958     case AML_DWORD_OP:
959
960         /* Determine if a Word/Dword is a valid encoded EISAID */
961
962         /* Swap from little-endian to big-endian to simplify conversion */
963
964         BigEndianId = AcpiUtDwordByteSwap ((UINT32) Op->Common.Value.Integer);
965
966         /* Create the 3 leading ASCII letters */
967
968         Prefix[0] = ((BigEndianId >> 26) & 0x1F) + 0x40;
969         Prefix[1] = ((BigEndianId >> 21) & 0x1F) + 0x40;
970         Prefix[2] = ((BigEndianId >> 16) & 0x1F) + 0x40;
971
972         /* Verify that all 3 are ascii and alpha */
973
974         for (i = 0; i < 3; i++)
975         {
976             if (!ACPI_IS_ASCII (Prefix[i]) ||
977                 !ACPI_IS_ALPHA (Prefix[i]))
978             {
979                 return;
980             }
981         }
982
983         /* Mark this node as convertable to an EISA ID string */
984
985         Op->Common.DisasmOpcode = ACPI_DASM_EISAID;
986         break;
987
988     default:
989         break;
990     }
991 }
992
993
994 /*******************************************************************************
995  *
996  * FUNCTION:    AcpiDmCheckForHardwareId
997  *
998  * PARAMETERS:  Op              - Op to be examined
999  *
1000  * RETURN:      None
1001  *
1002  * DESCRIPTION: Determine if a Name() Op is a _HID/_CID.
1003  *
1004  ******************************************************************************/
1005
1006 void
1007 AcpiDmCheckForHardwareId (
1008     ACPI_PARSE_OBJECT       *Op)
1009 {
1010     UINT32                  Name;
1011     ACPI_PARSE_OBJECT       *NextOp;
1012
1013
1014     /* Get the NameSegment */
1015
1016     Name = AcpiPsGetName (Op);
1017     if (!Name)
1018     {
1019         return;
1020     }
1021
1022     NextOp = AcpiPsGetDepthNext (NULL, Op);
1023     if (!NextOp)
1024     {
1025         return;
1026     }
1027
1028     /* Check for _HID - has one argument */
1029
1030     if (ACPI_COMPARE_NAME (&Name, METHOD_NAME__HID))
1031     {
1032         AcpiDmGetHardwareIdType (NextOp);
1033         return;
1034     }
1035
1036     /* Exit if not _CID */
1037
1038     if (!ACPI_COMPARE_NAME (&Name, METHOD_NAME__CID))
1039     {
1040         return;
1041     }
1042
1043     /* _CID can contain a single argument or a package */
1044
1045     if (NextOp->Common.AmlOpcode != AML_PACKAGE_OP)
1046     {
1047         AcpiDmGetHardwareIdType (NextOp);
1048         return;
1049     }
1050
1051     /* _CID with Package: get the package length, check all elements */
1052
1053     NextOp = AcpiPsGetDepthNext (NULL, NextOp);
1054     if (!NextOp)
1055     {
1056         return;
1057     }
1058
1059     /* Don't need to use the length, just walk the peer list */
1060
1061     NextOp = NextOp->Common.Next;
1062     while (NextOp)
1063     {
1064         AcpiDmGetHardwareIdType (NextOp);
1065         NextOp = NextOp->Common.Next;
1066     }
1067 }
1068
1069
1070 /*******************************************************************************
1071  *
1072  * FUNCTION:    AcpiDmDecompressEisaId
1073  *
1074  * PARAMETERS:  EncodedId       - Raw encoded EISA ID.
1075  *
1076  * RETURN:      None
1077  *
1078  * DESCRIPTION: Convert an encoded EISAID back to the original ASCII String
1079  *              and emit the correct ASL statement. If the ID is known, emit
1080  *              a description of the ID as a comment.
1081  *
1082  ******************************************************************************/
1083
1084 void
1085 AcpiDmDecompressEisaId (
1086     UINT32                  EncodedId)
1087 {
1088     char                    IdBuffer[ACPI_EISAID_STRING_SIZE];
1089     const AH_DEVICE_ID      *Info;
1090
1091
1092     /* Convert EISAID to a string an emit the statement */
1093
1094     AcpiExEisaIdToString (IdBuffer, EncodedId);
1095     AcpiOsPrintf ("EisaId (\"%s\")", IdBuffer);
1096
1097     /* If we know about the ID, emit the description */
1098
1099     Info = AcpiAhMatchHardwareId (IdBuffer);
1100     if (Info)
1101     {
1102         AcpiOsPrintf (" /* %s */", Info->Description);
1103     }
1104 }
1105
1106 #endif