1100966Siwasaki/*******************************************************************************
2100966Siwasaki *
3100966Siwasaki * Module Name: dmbuffer - AML disassembler, buffer and string support
4100966Siwasaki *
5100966Siwasaki ******************************************************************************/
6100966Siwasaki
7316303Sjkim/******************************************************************************
8316303Sjkim *
9316303Sjkim * 1. Copyright Notice
10316303Sjkim *
11316303Sjkim * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp.
12100966Siwasaki * All rights reserved.
13100966Siwasaki *
14316303Sjkim * 2. License
15316303Sjkim *
16316303Sjkim * 2.1. This is your license from Intel Corp. under its intellectual property
17316303Sjkim * rights. You may have additional license terms from the party that provided
18316303Sjkim * you this software, covering your right to use that party's intellectual
19316303Sjkim * property rights.
20316303Sjkim *
21316303Sjkim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22316303Sjkim * copy of the source code appearing in this file ("Covered Code") an
23316303Sjkim * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24316303Sjkim * base code distributed originally by Intel ("Original Intel Code") to copy,
25316303Sjkim * make derivatives, distribute, use and display any portion of the Covered
26316303Sjkim * Code in any form, with the right to sublicense such rights; and
27316303Sjkim *
28316303Sjkim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29316303Sjkim * license (with the right to sublicense), under only those claims of Intel
30316303Sjkim * patents that are infringed by the Original Intel Code, to make, use, sell,
31316303Sjkim * offer to sell, and import the Covered Code and derivative works thereof
32316303Sjkim * solely to the minimum extent necessary to exercise the above copyright
33316303Sjkim * license, and in no event shall the patent license extend to any additions
34316303Sjkim * to or modifications of the Original Intel Code. No other license or right
35316303Sjkim * is granted directly or by implication, estoppel or otherwise;
36316303Sjkim *
37316303Sjkim * The above copyright and patent license is granted only if the following
38316303Sjkim * conditions are met:
39316303Sjkim *
40316303Sjkim * 3. Conditions
41316303Sjkim *
42316303Sjkim * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43316303Sjkim * Redistribution of source code of any substantial portion of the Covered
44316303Sjkim * Code or modification with rights to further distribute source must include
45316303Sjkim * the above Copyright Notice, the above License, this list of Conditions,
46316303Sjkim * and the following Disclaimer and Export Compliance provision. In addition,
47316303Sjkim * Licensee must cause all Covered Code to which Licensee contributes to
48316303Sjkim * contain a file documenting the changes Licensee made to create that Covered
49316303Sjkim * Code and the date of any change. Licensee must include in that file the
50316303Sjkim * documentation of any changes made by any predecessor Licensee. Licensee
51316303Sjkim * must include a prominent statement that the modification is derived,
52316303Sjkim * directly or indirectly, from Original Intel Code.
53316303Sjkim *
54316303Sjkim * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55316303Sjkim * Redistribution of source code of any substantial portion of the Covered
56316303Sjkim * Code or modification without rights to further distribute source must
57316303Sjkim * include the following Disclaimer and Export Compliance provision in the
58316303Sjkim * documentation and/or other materials provided with distribution. In
59316303Sjkim * addition, Licensee may not authorize further sublicense of source of any
60316303Sjkim * portion of the Covered Code, and must include terms to the effect that the
61316303Sjkim * license from Licensee to its licensee is limited to the intellectual
62316303Sjkim * property embodied in the software Licensee provides to its licensee, and
63316303Sjkim * not to intellectual property embodied in modifications its licensee may
64316303Sjkim * make.
65316303Sjkim *
66316303Sjkim * 3.3. Redistribution of Executable. Redistribution in executable form of any
67316303Sjkim * substantial portion of the Covered Code or modification must reproduce the
68316303Sjkim * above Copyright Notice, and the following Disclaimer and Export Compliance
69316303Sjkim * provision in the documentation and/or other materials provided with the
70316303Sjkim * distribution.
71316303Sjkim *
72316303Sjkim * 3.4. Intel retains all right, title, and interest in and to the Original
73316303Sjkim * Intel Code.
74316303Sjkim *
75316303Sjkim * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76316303Sjkim * Intel shall be used in advertising or otherwise to promote the sale, use or
77316303Sjkim * other dealings in products derived from or relating to the Covered Code
78316303Sjkim * without prior written authorization from Intel.
79316303Sjkim *
80316303Sjkim * 4. Disclaimer and Export Compliance
81316303Sjkim *
82316303Sjkim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83316303Sjkim * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84316303Sjkim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85316303Sjkim * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86316303Sjkim * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87316303Sjkim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88316303Sjkim * PARTICULAR PURPOSE.
89316303Sjkim *
90316303Sjkim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91316303Sjkim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92316303Sjkim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93316303Sjkim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94316303Sjkim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95316303Sjkim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96316303Sjkim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97316303Sjkim * LIMITED REMEDY.
98316303Sjkim *
99316303Sjkim * 4.3. Licensee shall not export, either directly or indirectly, any of this
100316303Sjkim * software or system incorporating such software without first obtaining any
101316303Sjkim * required license or other approval from the U. S. Department of Commerce or
102316303Sjkim * any other agency or department of the United States Government. In the
103316303Sjkim * event Licensee exports any such software from the United States or
104316303Sjkim * re-exports any such software from a foreign destination, Licensee shall
105316303Sjkim * ensure that the distribution and export/re-export of the software is in
106316303Sjkim * compliance with all laws, regulations, orders, or other restrictions of the
107316303Sjkim * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108316303Sjkim * any of its subsidiaries will export/re-export any technical data, process,
109316303Sjkim * software, or service, directly or indirectly, to any country for which the
110316303Sjkim * United States government or any agency thereof requires an export license,
111316303Sjkim * other governmental approval, or letter of assurance, without first obtaining
112316303Sjkim * such license, approval or letter.
113316303Sjkim *
114316303Sjkim *****************************************************************************
115316303Sjkim *
116316303Sjkim * Alternatively, you may choose to be licensed under the terms of the
117316303Sjkim * following license:
118316303Sjkim *
119217365Sjkim * Redistribution and use in source and binary forms, with or without
120217365Sjkim * modification, are permitted provided that the following conditions
121217365Sjkim * are met:
122217365Sjkim * 1. Redistributions of source code must retain the above copyright
123217365Sjkim *    notice, this list of conditions, and the following disclaimer,
124217365Sjkim *    without modification.
125217365Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126217365Sjkim *    substantially similar to the "NO WARRANTY" disclaimer below
127217365Sjkim *    ("Disclaimer") and any redistribution must be conditioned upon
128217365Sjkim *    including a substantially similar Disclaimer requirement for further
129217365Sjkim *    binary redistribution.
130217365Sjkim * 3. Neither the names of the above-listed copyright holders nor the names
131217365Sjkim *    of any contributors may be used to endorse or promote products derived
132217365Sjkim *    from this software without specific prior written permission.
133100966Siwasaki *
134316303Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135316303Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136316303Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137316303Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138316303Sjkim * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139316303Sjkim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140316303Sjkim * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141316303Sjkim * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142316303Sjkim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143316303Sjkim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144316303Sjkim * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145316303Sjkim *
146316303Sjkim * Alternatively, you may choose to be licensed under the terms of the
147217365Sjkim * GNU General Public License ("GPL") version 2 as published by the Free
148217365Sjkim * Software Foundation.
149100966Siwasaki *
150316303Sjkim *****************************************************************************/
151100966Siwasaki
152193341Sjkim#include <contrib/dev/acpica/include/acpi.h>
153193341Sjkim#include <contrib/dev/acpica/include/accommon.h>
154272444Sjkim#include <contrib/dev/acpica/include/acutils.h>
155193341Sjkim#include <contrib/dev/acpica/include/acdisasm.h>
156193341Sjkim#include <contrib/dev/acpica/include/acparser.h>
157193341Sjkim#include <contrib/dev/acpica/include/amlcode.h>
158272444Sjkim#include <contrib/dev/acpica/include/acinterp.h>
159100966Siwasaki
160100966Siwasaki
161102550Siwasaki#define _COMPONENT          ACPI_CA_DEBUGGER
162100966Siwasaki        ACPI_MODULE_NAME    ("dmbuffer")
163100966Siwasaki
164151937Sjkim/* Local prototypes */
165100966Siwasaki
166151937Sjkimstatic void
167272444SjkimAcpiDmUuid (
168272444Sjkim    ACPI_PARSE_OBJECT       *Op);
169272444Sjkim
170272444Sjkimstatic void
171151937SjkimAcpiDmUnicode (
172151937Sjkim    ACPI_PARSE_OBJECT       *Op);
173151937Sjkim
174193267Sjkimstatic void
175272444SjkimAcpiDmGetHardwareIdType (
176193267Sjkim    ACPI_PARSE_OBJECT       *Op);
177151937Sjkim
178239340Sjkimstatic void
179239340SjkimAcpiDmPldBuffer (
180239340Sjkim    UINT32                  Level,
181239340Sjkim    UINT8                   *ByteData,
182239340Sjkim    UINT32                  ByteCount);
183193267Sjkim
184298714Sjkimstatic const char *
185298714SjkimAcpiDmFindNameByIndex (
186298714Sjkim    UINT64                  Index,
187298714Sjkim    const char              **List);
188239340Sjkim
189298714Sjkim
190272444Sjkim#define ACPI_BUFFER_BYTES_PER_LINE      8
191272444Sjkim
192272444Sjkim
193100966Siwasaki/*******************************************************************************
194100966Siwasaki *
195100966Siwasaki * FUNCTION:    AcpiDmDisasmByteList
196100966Siwasaki *
197100966Siwasaki * PARAMETERS:  Level               - Current source code indentation level
198100966Siwasaki *              ByteData            - Pointer to the byte list
199100966Siwasaki *              ByteCount           - Length of the byte list
200100966Siwasaki *
201100966Siwasaki * RETURN:      None
202100966Siwasaki *
203167802Sjkim * DESCRIPTION: Dump an AML "ByteList" in Hex format. 8 bytes per line, prefixed
204167802Sjkim *              with the hex buffer offset.
205100966Siwasaki *
206100966Siwasaki ******************************************************************************/
207100966Siwasaki
208100966Siwasakivoid
209100966SiwasakiAcpiDmDisasmByteList (
210100966Siwasaki    UINT32                  Level,
211100966Siwasaki    UINT8                   *ByteData,
212100966Siwasaki    UINT32                  ByteCount)
213100966Siwasaki{
214100966Siwasaki    UINT32                  i;
215272444Sjkim    UINT32                  j;
216272444Sjkim    UINT32                  CurrentIndex;
217272444Sjkim    UINT8                   BufChar;
218100966Siwasaki
219100966Siwasaki
220167802Sjkim    if (!ByteCount)
221167802Sjkim    {
222167802Sjkim        return;
223167802Sjkim    }
224100966Siwasaki
225272444Sjkim    for (i = 0; i < ByteCount; i += ACPI_BUFFER_BYTES_PER_LINE)
226100966Siwasaki    {
227272444Sjkim        /* Line indent and offset prefix for each new line */
228167802Sjkim
229272444Sjkim        AcpiDmIndent (Level);
230272444Sjkim        if (ByteCount > ACPI_BUFFER_BYTES_PER_LINE)
231167802Sjkim        {
232272444Sjkim            AcpiOsPrintf ("/* %04X */ ", i);
233272444Sjkim        }
234272444Sjkim
235272444Sjkim        /* Dump the actual hex values */
236272444Sjkim
237272444Sjkim        for (j = 0; j < ACPI_BUFFER_BYTES_PER_LINE; j++)
238272444Sjkim        {
239272444Sjkim            CurrentIndex = i + j;
240272444Sjkim            if (CurrentIndex >= ByteCount)
241167802Sjkim            {
242272444Sjkim                /* Dump fill spaces */
243272444Sjkim
244272444Sjkim                AcpiOsPrintf ("      ");
245272444Sjkim                continue;
246167802Sjkim            }
247167802Sjkim
248272444Sjkim            AcpiOsPrintf (" 0x%2.2X", ByteData[CurrentIndex]);
249272444Sjkim
250272444Sjkim            /* Add comma if there are more bytes to display */
251272444Sjkim
252272444Sjkim            if (CurrentIndex < (ByteCount - 1))
253167802Sjkim            {
254272444Sjkim                AcpiOsPrintf (",");
255167802Sjkim            }
256272444Sjkim            else
257272444Sjkim            {
258272444Sjkim                AcpiOsPrintf (" ");
259272444Sjkim            }
260167802Sjkim        }
261167802Sjkim
262272444Sjkim        /* Dump the ASCII equivalents within a comment */
263100966Siwasaki
264322877Sjkim        AcpiOsPrintf ("  // ");
265272444Sjkim        for (j = 0; j < ACPI_BUFFER_BYTES_PER_LINE; j++)
266272444Sjkim        {
267272444Sjkim            CurrentIndex = i + j;
268272444Sjkim            if (CurrentIndex >= ByteCount)
269272444Sjkim            {
270272444Sjkim                break;
271272444Sjkim            }
272100966Siwasaki
273272444Sjkim            BufChar = ByteData[CurrentIndex];
274284583Sjkim            if (isprint (BufChar))
275272444Sjkim            {
276272444Sjkim                AcpiOsPrintf ("%c", BufChar);
277272444Sjkim            }
278272444Sjkim            else
279272444Sjkim            {
280272444Sjkim                AcpiOsPrintf (".");
281272444Sjkim            }
282100966Siwasaki        }
283100966Siwasaki
284272444Sjkim        /* Finished with this line */
285272444Sjkim
286322877Sjkim        AcpiOsPrintf ("\n");
287100966Siwasaki    }
288100966Siwasaki}
289100966Siwasaki
290100966Siwasaki
291100966Siwasaki/*******************************************************************************
292100966Siwasaki *
293100966Siwasaki * FUNCTION:    AcpiDmByteList
294100966Siwasaki *
295100966Siwasaki * PARAMETERS:  Info            - Parse tree walk info
296100966Siwasaki *              Op              - Byte list op
297100966Siwasaki *
298100966Siwasaki * RETURN:      None
299100966Siwasaki *
300100966Siwasaki * DESCRIPTION: Dump a buffer byte list, handling the various types of buffers.
301100966Siwasaki *              Buffer type must be already set in the Op DisasmOpcode.
302100966Siwasaki *
303100966Siwasaki ******************************************************************************/
304100966Siwasaki
305100966Siwasakivoid
306100966SiwasakiAcpiDmByteList (
307100966Siwasaki    ACPI_OP_WALK_INFO       *Info,
308100966Siwasaki    ACPI_PARSE_OBJECT       *Op)
309100966Siwasaki{
310100966Siwasaki    UINT8                   *ByteData;
311100966Siwasaki    UINT32                  ByteCount;
312100966Siwasaki
313100966Siwasaki
314100966Siwasaki    ByteData = Op->Named.Data;
315117521Snjl    ByteCount = (UINT32) Op->Common.Value.Integer;
316100966Siwasaki
317100966Siwasaki    /*
318100966Siwasaki     * The byte list belongs to a buffer, and can be produced by either
319100966Siwasaki     * a ResourceTemplate, Unicode, quoted string, or a plain byte list.
320100966Siwasaki     */
321100966Siwasaki    switch (Op->Common.Parent->Common.DisasmOpcode)
322100966Siwasaki    {
323100966Siwasaki    case ACPI_DASM_RESOURCE:
324100966Siwasaki
325298714Sjkim        AcpiDmResourceTemplate (
326298714Sjkim            Info, Op->Common.Parent, ByteData, ByteCount);
327100966Siwasaki        break;
328100966Siwasaki
329100966Siwasaki    case ACPI_DASM_STRING:
330100966Siwasaki
331100966Siwasaki        AcpiDmIndent (Info->Level);
332252279Sjkim        AcpiUtPrintString ((char *) ByteData, ACPI_UINT16_MAX);
333100966Siwasaki        AcpiOsPrintf ("\n");
334100966Siwasaki        break;
335100966Siwasaki
336272444Sjkim    case ACPI_DASM_UUID:
337272444Sjkim
338272444Sjkim        AcpiDmUuid (Op);
339272444Sjkim        break;
340272444Sjkim
341100966Siwasaki    case ACPI_DASM_UNICODE:
342100966Siwasaki
343100966Siwasaki        AcpiDmUnicode (Op);
344100966Siwasaki        break;
345100966Siwasaki
346239340Sjkim    case ACPI_DASM_PLD_METHOD:
347278970Sjkim#if 0
348239340Sjkim        AcpiDmDisasmByteList (Info->Level, ByteData, ByteCount);
349278970Sjkim#endif
350239340Sjkim        AcpiDmPldBuffer (Info->Level, ByteData, ByteCount);
351239340Sjkim        break;
352239340Sjkim
353100966Siwasaki    case ACPI_DASM_BUFFER:
354100966Siwasaki    default:
355100966Siwasaki        /*
356100966Siwasaki         * Not a resource, string, or unicode string.
357100966Siwasaki         * Just dump the buffer
358100966Siwasaki         */
359100966Siwasaki        AcpiDmDisasmByteList (Info->Level, ByteData, ByteCount);
360100966Siwasaki        break;
361100966Siwasaki    }
362100966Siwasaki}
363100966Siwasaki
364100966Siwasaki
365100966Siwasaki/*******************************************************************************
366100966Siwasaki *
367272444Sjkim * FUNCTION:    AcpiDmIsUuidBuffer
368272444Sjkim *
369272444Sjkim * PARAMETERS:  Op              - Buffer Object to be examined
370272444Sjkim *
371272444Sjkim * RETURN:      TRUE if buffer contains a UUID
372272444Sjkim *
373272444Sjkim * DESCRIPTION: Determine if a buffer Op contains a UUID
374272444Sjkim *
375272444Sjkim * To help determine whether the buffer is a UUID versus a raw data buffer,
376272444Sjkim * there a are a couple bytes we can look at:
377272444Sjkim *
378272444Sjkim *    xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx
379272444Sjkim *
380272444Sjkim * The variant covered by the UUID specification is indicated by the two most
381272444Sjkim * significant bits of N being 1 0 (i.e., the hexadecimal N will always be
382272444Sjkim * 8, 9, A, or B).
383272444Sjkim *
384272444Sjkim * The variant covered by the UUID specification has five versions. For this
385272444Sjkim * variant, the four bits of M indicates the UUID version (i.e., the
386272444Sjkim * hexadecimal M will be either 1, 2, 3, 4, or 5).
387272444Sjkim *
388272444Sjkim ******************************************************************************/
389272444Sjkim
390272444SjkimBOOLEAN
391272444SjkimAcpiDmIsUuidBuffer (
392272444Sjkim    ACPI_PARSE_OBJECT       *Op)
393272444Sjkim{
394272444Sjkim    UINT8                   *ByteData;
395272444Sjkim    UINT32                  ByteCount;
396272444Sjkim    ACPI_PARSE_OBJECT       *SizeOp;
397272444Sjkim    ACPI_PARSE_OBJECT       *NextOp;
398272444Sjkim
399272444Sjkim
400272444Sjkim    /* Buffer size is the buffer argument */
401272444Sjkim
402272444Sjkim    SizeOp = Op->Common.Value.Arg;
403272444Sjkim
404272444Sjkim    /* Next, the initializer byte list to examine */
405272444Sjkim
406272444Sjkim    NextOp = SizeOp->Common.Next;
407272444Sjkim    if (!NextOp)
408272444Sjkim    {
409272444Sjkim        return (FALSE);
410272444Sjkim    }
411272444Sjkim
412272444Sjkim    /* Extract the byte list info */
413272444Sjkim
414272444Sjkim    ByteData = NextOp->Named.Data;
415272444Sjkim    ByteCount = (UINT32) NextOp->Common.Value.Integer;
416272444Sjkim
417272444Sjkim    /* Byte count must be exactly 16 */
418272444Sjkim
419272444Sjkim    if (ByteCount != UUID_BUFFER_LENGTH)
420272444Sjkim    {
421272444Sjkim        return (FALSE);
422272444Sjkim    }
423272444Sjkim
424272444Sjkim    /* Check for valid "M" and "N" values (see function header above) */
425272444Sjkim
426272444Sjkim    if (((ByteData[7] & 0xF0) == 0x00) || /* M={1,2,3,4,5} */
427272444Sjkim        ((ByteData[7] & 0xF0) > 0x50)  ||
428272444Sjkim        ((ByteData[8] & 0xF0) < 0x80)  || /* N={8,9,A,B} */
429272444Sjkim        ((ByteData[8] & 0xF0) > 0xB0))
430272444Sjkim    {
431272444Sjkim        return (FALSE);
432272444Sjkim    }
433272444Sjkim
434272444Sjkim    /* Ignore the Size argument in the disassembly of this buffer op */
435272444Sjkim
436272444Sjkim    SizeOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
437272444Sjkim    return (TRUE);
438272444Sjkim}
439272444Sjkim
440272444Sjkim
441272444Sjkim/*******************************************************************************
442272444Sjkim *
443272444Sjkim * FUNCTION:    AcpiDmUuid
444272444Sjkim *
445272444Sjkim * PARAMETERS:  Op              - Byte List op containing a UUID
446272444Sjkim *
447272444Sjkim * RETURN:      None
448272444Sjkim *
449272444Sjkim * DESCRIPTION: Dump a buffer containing a UUID as a standard ASCII string.
450272444Sjkim *
451272444Sjkim * Output Format:
452272444Sjkim * In its canonical form, the UUID is represented by a string containing 32
453272444Sjkim * lowercase hexadecimal digits, displayed in 5 groups separated by hyphens.
454272444Sjkim * The complete form is 8-4-4-4-12 for a total of 36 characters (32
455272444Sjkim * alphanumeric characters representing hex digits and 4 hyphens). In bytes,
456272444Sjkim * 4-2-2-2-6. Example:
457272444Sjkim *
458272444Sjkim *    ToUUID ("107ededd-d381-4fd7-8da9-08e9a6c79644")
459272444Sjkim *
460272444Sjkim ******************************************************************************/
461272444Sjkim
462272444Sjkimstatic void
463272444SjkimAcpiDmUuid (
464272444Sjkim    ACPI_PARSE_OBJECT       *Op)
465272444Sjkim{
466272444Sjkim    UINT8                   *Data;
467272444Sjkim    const char              *Description;
468272444Sjkim
469272444Sjkim
470272444Sjkim    Data = ACPI_CAST_PTR (UINT8, Op->Named.Data);
471272444Sjkim
472272444Sjkim    /* Emit the 36-byte UUID string in the proper format/order */
473272444Sjkim
474272444Sjkim    AcpiOsPrintf (
475272444Sjkim        "\"%2.2x%2.2x%2.2x%2.2x-"
476272444Sjkim        "%2.2x%2.2x-"
477272444Sjkim        "%2.2x%2.2x-"
478272444Sjkim        "%2.2x%2.2x-"
479272444Sjkim        "%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\")",
480272444Sjkim        Data[3], Data[2], Data[1], Data[0],
481272444Sjkim        Data[5], Data[4],
482272444Sjkim        Data[7], Data[6],
483272444Sjkim        Data[8], Data[9],
484272444Sjkim        Data[10], Data[11], Data[12], Data[13], Data[14], Data[15]);
485272444Sjkim
486272444Sjkim    /* Dump the UUID description string if available */
487272444Sjkim
488272444Sjkim    Description = AcpiAhMatchUuid (Data);
489272444Sjkim    if (Description)
490272444Sjkim    {
491272444Sjkim        AcpiOsPrintf (" /* %s */", Description);
492272444Sjkim    }
493272444Sjkim}
494272444Sjkim
495272444Sjkim
496272444Sjkim/*******************************************************************************
497272444Sjkim *
498100966Siwasaki * FUNCTION:    AcpiDmIsUnicodeBuffer
499100966Siwasaki *
500100966Siwasaki * PARAMETERS:  Op              - Buffer Object to be examined
501100966Siwasaki *
502100966Siwasaki * RETURN:      TRUE if buffer contains a UNICODE string
503100966Siwasaki *
504100966Siwasaki * DESCRIPTION: Determine if a buffer Op contains a Unicode string
505100966Siwasaki *
506100966Siwasaki ******************************************************************************/
507100966Siwasaki
508100966SiwasakiBOOLEAN
509100966SiwasakiAcpiDmIsUnicodeBuffer (
510100966Siwasaki    ACPI_PARSE_OBJECT       *Op)
511100966Siwasaki{
512100966Siwasaki    UINT8                   *ByteData;
513100966Siwasaki    UINT32                  ByteCount;
514100966Siwasaki    UINT32                  WordCount;
515100966Siwasaki    ACPI_PARSE_OBJECT       *SizeOp;
516100966Siwasaki    ACPI_PARSE_OBJECT       *NextOp;
517193267Sjkim    UINT32                  i;
518100966Siwasaki
519100966Siwasaki
520100966Siwasaki    /* Buffer size is the buffer argument */
521100966Siwasaki
522100966Siwasaki    SizeOp = Op->Common.Value.Arg;
523100966Siwasaki
524100966Siwasaki    /* Next, the initializer byte list to examine */
525100966Siwasaki
526100966Siwasaki    NextOp = SizeOp->Common.Next;
527100966Siwasaki    if (!NextOp)
528100966Siwasaki    {
529100966Siwasaki        return (FALSE);
530100966Siwasaki    }
531100966Siwasaki
532100966Siwasaki    /* Extract the byte list info */
533100966Siwasaki
534100966Siwasaki    ByteData = NextOp->Named.Data;
535117521Snjl    ByteCount = (UINT32) NextOp->Common.Value.Integer;
536100966Siwasaki    WordCount = ACPI_DIV_2 (ByteCount);
537100966Siwasaki
538100966Siwasaki    /*
539100966Siwasaki     * Unicode string must have an even number of bytes and last
540100966Siwasaki     * word must be zero
541100966Siwasaki     */
542100966Siwasaki    if ((!ByteCount)     ||
543100966Siwasaki         (ByteCount < 4) ||
544100966Siwasaki         (ByteCount & 1) ||
545100966Siwasaki        ((UINT16 *) (void *) ByteData)[WordCount - 1] != 0)
546100966Siwasaki    {
547100966Siwasaki        return (FALSE);
548100966Siwasaki    }
549100966Siwasaki
550316303Sjkim    /*
551316303Sjkim     * For each word, 1st byte must be printable ascii, and the
552316303Sjkim     * 2nd byte must be zero. This does not allow for escape
553316303Sjkim     * sequences, but it is the most secure way to detect a
554316303Sjkim     * unicode string.
555316303Sjkim     */
556100966Siwasaki    for (i = 0; i < (ByteCount - 2); i += 2)
557100966Siwasaki    {
558278970Sjkim        if ((ByteData[i] == 0) ||
559316303Sjkim            !(isprint (ByteData[i])) ||
560193267Sjkim            (ByteData[(ACPI_SIZE) i + 1] != 0))
561100966Siwasaki        {
562100966Siwasaki            return (FALSE);
563100966Siwasaki        }
564100966Siwasaki    }
565100966Siwasaki
566100966Siwasaki    /* Ignore the Size argument in the disassembly of this buffer op */
567100966Siwasaki
568100966Siwasaki    SizeOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
569100966Siwasaki    return (TRUE);
570100966Siwasaki}
571100966Siwasaki
572100966Siwasaki
573100966Siwasaki/*******************************************************************************
574100966Siwasaki *
575100966Siwasaki * FUNCTION:    AcpiDmIsStringBuffer
576100966Siwasaki *
577100966Siwasaki * PARAMETERS:  Op              - Buffer Object to be examined
578100966Siwasaki *
579151937Sjkim * RETURN:      TRUE if buffer contains a ASCII string, FALSE otherwise
580100966Siwasaki *
581100966Siwasaki * DESCRIPTION: Determine if a buffer Op contains a ASCII string
582100966Siwasaki *
583100966Siwasaki ******************************************************************************/
584100966Siwasaki
585100966SiwasakiBOOLEAN
586100966SiwasakiAcpiDmIsStringBuffer (
587100966Siwasaki    ACPI_PARSE_OBJECT       *Op)
588100966Siwasaki{
589100966Siwasaki    UINT8                   *ByteData;
590100966Siwasaki    UINT32                  ByteCount;
591100966Siwasaki    ACPI_PARSE_OBJECT       *SizeOp;
592100966Siwasaki    ACPI_PARSE_OBJECT       *NextOp;
593100966Siwasaki    UINT32                  i;
594100966Siwasaki
595100966Siwasaki
596100966Siwasaki    /* Buffer size is the buffer argument */
597100966Siwasaki
598100966Siwasaki    SizeOp = Op->Common.Value.Arg;
599100966Siwasaki
600100966Siwasaki    /* Next, the initializer byte list to examine */
601100966Siwasaki
602100966Siwasaki    NextOp = SizeOp->Common.Next;
603100966Siwasaki    if (!NextOp)
604100966Siwasaki    {
605100966Siwasaki        return (FALSE);
606100966Siwasaki    }
607100966Siwasaki
608100966Siwasaki    /* Extract the byte list info */
609100966Siwasaki
610100966Siwasaki    ByteData = NextOp->Named.Data;
611117521Snjl    ByteCount = (UINT32) NextOp->Common.Value.Integer;
612100966Siwasaki
613100966Siwasaki    /* Last byte must be the null terminator */
614100966Siwasaki
615100966Siwasaki    if ((!ByteCount)     ||
616100966Siwasaki         (ByteCount < 2) ||
617100966Siwasaki         (ByteData[ByteCount-1] != 0))
618100966Siwasaki    {
619100966Siwasaki        return (FALSE);
620100966Siwasaki    }
621100966Siwasaki
622316303Sjkim    /*
623316303Sjkim     * Check for a possible standalone resource EndTag, ignore it
624316303Sjkim     * here. However, this sequence is also the string "Y", but
625316303Sjkim     * this seems rare enough to be acceptable.
626316303Sjkim     */
627316303Sjkim    if ((ByteCount == 2) && (ByteData[0] == 0x79))
628316303Sjkim    {
629316303Sjkim        return (FALSE);
630316303Sjkim    }
631316303Sjkim
632316303Sjkim    /* Check all bytes for ASCII */
633316303Sjkim
634100966Siwasaki    for (i = 0; i < (ByteCount - 1); i++)
635100966Siwasaki    {
636316303Sjkim        /*
637316303Sjkim         * TBD: allow some escapes (non-ascii chars).
638100966Siwasaki         * they will be handled in the string output routine
639100966Siwasaki         */
640100966Siwasaki
641316303Sjkim        /* Not a string if not printable ascii */
642316303Sjkim
643284583Sjkim        if (!isprint (ByteData[i]))
644100966Siwasaki        {
645100966Siwasaki            return (FALSE);
646100966Siwasaki        }
647100966Siwasaki    }
648100966Siwasaki
649100966Siwasaki    return (TRUE);
650100966Siwasaki}
651100966Siwasaki
652100966Siwasaki
653100966Siwasaki/*******************************************************************************
654100966Siwasaki *
655239340Sjkim * FUNCTION:    AcpiDmIsPldBuffer
656239340Sjkim *
657239340Sjkim * PARAMETERS:  Op                  - Buffer Object to be examined
658239340Sjkim *
659316303Sjkim * RETURN:      TRUE if buffer appears to contain data produced via the
660316303Sjkim *              ToPLD macro, FALSE otherwise
661239340Sjkim *
662239340Sjkim * DESCRIPTION: Determine if a buffer Op contains a _PLD structure
663239340Sjkim *
664239340Sjkim ******************************************************************************/
665239340Sjkim
666239340SjkimBOOLEAN
667239340SjkimAcpiDmIsPldBuffer (
668239340Sjkim    ACPI_PARSE_OBJECT       *Op)
669239340Sjkim{
670239340Sjkim    ACPI_NAMESPACE_NODE     *Node;
671278970Sjkim    ACPI_PARSE_OBJECT       *SizeOp;
672316303Sjkim    ACPI_PARSE_OBJECT       *ByteListOp;
673239340Sjkim    ACPI_PARSE_OBJECT       *ParentOp;
674316303Sjkim    UINT64                  BufferSize;
675316303Sjkim    UINT64                  InitializerSize;
676239340Sjkim
677239340Sjkim
678316303Sjkim    /*
679316303Sjkim     * Get the BufferSize argument - Buffer(BufferSize)
680316303Sjkim     * If the buffer was generated by the ToPld macro, it must
681316303Sjkim     * be a BYTE constant.
682316303Sjkim     */
683278970Sjkim    SizeOp = Op->Common.Value.Arg;
684316303Sjkim    if (SizeOp->Common.AmlOpcode != AML_BYTE_OP)
685316303Sjkim    {
686316303Sjkim        return (FALSE);
687316303Sjkim    }
688278970Sjkim
689316303Sjkim    /* Check the declared BufferSize, two possibilities */
690316303Sjkim
691316303Sjkim    BufferSize = SizeOp->Common.Value.Integer;
692316303Sjkim    if ((BufferSize != ACPI_PLD_REV1_BUFFER_SIZE) &&
693316303Sjkim        (BufferSize != ACPI_PLD_REV2_BUFFER_SIZE))
694316303Sjkim    {
695316303Sjkim        return (FALSE);
696316303Sjkim    }
697316303Sjkim
698316303Sjkim    /*
699316303Sjkim     * Check the initializer list length. This is the actual
700316303Sjkim     * number of bytes in the buffer as counted by the AML parser.
701316303Sjkim     * The declared BufferSize can be larger than the actual length.
702316303Sjkim     * However, for the ToPLD macro, the BufferSize will be the same
703316303Sjkim     * as the initializer list length.
704316303Sjkim     */
705316303Sjkim    ByteListOp = SizeOp->Common.Next;
706316303Sjkim    if (!ByteListOp)
707316303Sjkim    {
708316303Sjkim        return (FALSE); /* Zero-length buffer case */
709316303Sjkim    }
710316303Sjkim
711316303Sjkim    InitializerSize = ByteListOp->Common.Value.Integer;
712316303Sjkim    if ((InitializerSize != ACPI_PLD_REV1_BUFFER_SIZE) &&
713316303Sjkim        (InitializerSize != ACPI_PLD_REV2_BUFFER_SIZE))
714316303Sjkim    {
715316303Sjkim        return (FALSE);
716316303Sjkim    }
717316303Sjkim
718316303Sjkim    /* Final size check */
719316303Sjkim
720316303Sjkim    if (BufferSize != InitializerSize)
721316303Sjkim    {
722316303Sjkim        return (FALSE);
723316303Sjkim    }
724316303Sjkim
725316303Sjkim    /* Now examine the buffer parent */
726316303Sjkim
727239340Sjkim    ParentOp = Op->Common.Parent;
728239340Sjkim    if (!ParentOp)
729239340Sjkim    {
730239340Sjkim        return (FALSE);
731239340Sjkim    }
732239340Sjkim
733239340Sjkim    /* Check for form: Name(_PLD, Buffer() {}). Not legal, however */
734239340Sjkim
735239340Sjkim    if (ParentOp->Common.AmlOpcode == AML_NAME_OP)
736239340Sjkim    {
737239340Sjkim        Node = ParentOp->Common.Node;
738239340Sjkim
739239340Sjkim        if (ACPI_COMPARE_NAME (Node->Name.Ascii, METHOD_NAME__PLD))
740239340Sjkim        {
741278970Sjkim            /* Ignore the Size argument in the disassembly of this buffer op */
742278970Sjkim
743278970Sjkim            SizeOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
744239340Sjkim            return (TRUE);
745239340Sjkim        }
746239340Sjkim
747239340Sjkim        return (FALSE);
748239340Sjkim    }
749239340Sjkim
750316303Sjkim    /*
751316303Sjkim     * Check for proper form: Name(_PLD, Package() {ToPLD()})
752316303Sjkim     *
753316303Sjkim     * Note: All other forms such as
754316303Sjkim     *      Return (Package() {ToPLD()})
755316303Sjkim     *      Local0 = ToPLD()
756316303Sjkim     * etc. are not converted back to the ToPLD macro, because
757316303Sjkim     * there is really no deterministic way to disassemble the buffer
758316303Sjkim     * back to the ToPLD macro, other than trying to find the "_PLD"
759316303Sjkim     * name
760316303Sjkim     */
761239340Sjkim    if (ParentOp->Common.AmlOpcode == AML_PACKAGE_OP)
762239340Sjkim    {
763239340Sjkim        ParentOp = ParentOp->Common.Parent;
764239340Sjkim        if (!ParentOp)
765239340Sjkim        {
766239340Sjkim            return (FALSE);
767239340Sjkim        }
768239340Sjkim
769239340Sjkim        if (ParentOp->Common.AmlOpcode == AML_NAME_OP)
770239340Sjkim        {
771239340Sjkim            Node = ParentOp->Common.Node;
772239340Sjkim
773239340Sjkim            if (ACPI_COMPARE_NAME (Node->Name.Ascii, METHOD_NAME__PLD))
774239340Sjkim            {
775278970Sjkim                /* Ignore the Size argument in the disassembly of this buffer op */
776278970Sjkim
777278970Sjkim                SizeOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
778239340Sjkim                return (TRUE);
779239340Sjkim            }
780239340Sjkim        }
781239340Sjkim    }
782239340Sjkim
783239340Sjkim    return (FALSE);
784239340Sjkim}
785239340Sjkim
786239340Sjkim
787239340Sjkim/*******************************************************************************
788239340Sjkim *
789278970Sjkim * FUNCTION:    AcpiDmFindNameByIndex
790278970Sjkim *
791278970Sjkim * PARAMETERS:  Index               - Index of array to check
792278970Sjkim *              List                - Array to reference
793278970Sjkim *
794278970Sjkim * RETURN:      String from List or empty string
795278970Sjkim *
796278970Sjkim * DESCRIPTION: Finds and returns the char string located at the given index
797278970Sjkim *              position in List.
798278970Sjkim *
799278970Sjkim ******************************************************************************/
800278970Sjkim
801298714Sjkimstatic const char *
802278970SjkimAcpiDmFindNameByIndex (
803278970Sjkim    UINT64                  Index,
804298714Sjkim    const char              **List)
805278970Sjkim{
806298714Sjkim    const char              *NameString;
807298714Sjkim    UINT32                  i;
808278970Sjkim
809278970Sjkim
810278970Sjkim    /* Bounds check */
811278970Sjkim
812298714Sjkim    NameString = List[0];
813278970Sjkim    i = 0;
814278970Sjkim
815298714Sjkim    while (NameString)
816278970Sjkim    {
817278970Sjkim        i++;
818298714Sjkim        NameString = List[i];
819278970Sjkim    }
820278970Sjkim
821278970Sjkim    if (Index >= i)
822278970Sjkim    {
823278970Sjkim        /* TBD: Add error msg */
824278970Sjkim
825278970Sjkim        return ("");
826278970Sjkim    }
827278970Sjkim
828278970Sjkim    return (List[Index]);
829278970Sjkim}
830278970Sjkim
831278970Sjkim
832278970Sjkim/*******************************************************************************
833278970Sjkim *
834239340Sjkim * FUNCTION:    AcpiDmPldBuffer
835239340Sjkim *
836239340Sjkim * PARAMETERS:  Level               - Current source code indentation level
837239340Sjkim *              ByteData            - Pointer to the byte list
838239340Sjkim *              ByteCount           - Length of the byte list
839239340Sjkim *
840239340Sjkim * RETURN:      None
841239340Sjkim *
842239340Sjkim * DESCRIPTION: Dump and format the contents of a _PLD buffer object
843239340Sjkim *
844239340Sjkim ******************************************************************************/
845239340Sjkim
846298714Sjkim#define ACPI_PLD_OUTPUT08   "%*.s%-22s = 0x%X,\n", ACPI_MUL_4 (Level), " "
847298714Sjkim#define ACPI_PLD_OUTPUT08P  "%*.s%-22s = 0x%X)\n", ACPI_MUL_4 (Level), " "
848298714Sjkim#define ACPI_PLD_OUTPUT16   "%*.s%-22s = 0x%X,\n", ACPI_MUL_4 (Level), " "
849298714Sjkim#define ACPI_PLD_OUTPUT16P  "%*.s%-22s = 0x%X)\n", ACPI_MUL_4 (Level), " "
850298714Sjkim#define ACPI_PLD_OUTPUT24   "%*.s%-22s = 0x%X,\n", ACPI_MUL_4 (Level), " "
851298714Sjkim#define ACPI_PLD_OUTPUTSTR  "%*.s%-22s = \"%s\",\n", ACPI_MUL_4 (Level), " "
852239340Sjkim
853239340Sjkimstatic void
854239340SjkimAcpiDmPldBuffer (
855239340Sjkim    UINT32                  Level,
856239340Sjkim    UINT8                   *ByteData,
857239340Sjkim    UINT32                  ByteCount)
858239340Sjkim{
859239340Sjkim    ACPI_PLD_INFO           *PldInfo;
860239340Sjkim    ACPI_STATUS             Status;
861239340Sjkim
862239340Sjkim
863239340Sjkim    /* Check for valid byte count */
864239340Sjkim
865239340Sjkim    if (ByteCount < ACPI_PLD_REV1_BUFFER_SIZE)
866239340Sjkim    {
867239340Sjkim        return;
868239340Sjkim    }
869239340Sjkim
870239340Sjkim    /* Convert _PLD buffer to local _PLD struct */
871239340Sjkim
872239340Sjkim    Status = AcpiDecodePldBuffer (ByteData, ByteCount, &PldInfo);
873239340Sjkim    if (ACPI_FAILURE (Status))
874239340Sjkim    {
875239340Sjkim        return;
876239340Sjkim    }
877239340Sjkim
878278970Sjkim    AcpiOsPrintf ("\n");
879278970Sjkim
880239340Sjkim    /* First 32-bit dword */
881239340Sjkim
882278970Sjkim    AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_Revision", PldInfo->Revision);
883278970Sjkim    AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_IgnoreColor", PldInfo->IgnoreColor);
884278970Sjkim    AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_Red", PldInfo->Red);
885278970Sjkim    AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_Green", PldInfo->Green);
886278970Sjkim    AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_Blue", PldInfo->Blue);
887239340Sjkim
888239340Sjkim    /* Second 32-bit dword */
889239340Sjkim
890278970Sjkim    AcpiOsPrintf (ACPI_PLD_OUTPUT16,  "PLD_Width", PldInfo->Width);
891278970Sjkim    AcpiOsPrintf (ACPI_PLD_OUTPUT16,  "PLD_Height", PldInfo->Height);
892239340Sjkim
893239340Sjkim    /* Third 32-bit dword */
894239340Sjkim
895278970Sjkim    AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_UserVisible", PldInfo->UserVisible);
896278970Sjkim    AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_Dock", PldInfo->Dock);
897278970Sjkim    AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_Lid", PldInfo->Lid);
898278970Sjkim    AcpiOsPrintf (ACPI_PLD_OUTPUTSTR, "PLD_Panel",
899298714Sjkim        AcpiDmFindNameByIndex(PldInfo->Panel, AcpiGbl_PldPanelList));
900298714Sjkim
901278970Sjkim    AcpiOsPrintf (ACPI_PLD_OUTPUTSTR, "PLD_VerticalPosition",
902298714Sjkim        AcpiDmFindNameByIndex(PldInfo->VerticalPosition, AcpiGbl_PldVerticalPositionList));
903298714Sjkim
904278970Sjkim    AcpiOsPrintf (ACPI_PLD_OUTPUTSTR, "PLD_HorizontalPosition",
905298714Sjkim        AcpiDmFindNameByIndex(PldInfo->HorizontalPosition, AcpiGbl_PldHorizontalPositionList));
906298714Sjkim
907278970Sjkim    AcpiOsPrintf (ACPI_PLD_OUTPUTSTR, "PLD_Shape",
908298714Sjkim        AcpiDmFindNameByIndex(PldInfo->Shape, AcpiGbl_PldShapeList));
909278970Sjkim    AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_GroupOrientation", PldInfo->GroupOrientation);
910298714Sjkim
911278970Sjkim    AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_GroupToken", PldInfo->GroupToken);
912278970Sjkim    AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_GroupPosition", PldInfo->GroupPosition);
913278970Sjkim    AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_Bay", PldInfo->Bay);
914239340Sjkim
915239340Sjkim    /* Fourth 32-bit dword */
916239340Sjkim
917278970Sjkim    AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_Ejectable", PldInfo->Ejectable);
918278970Sjkim    AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_EjectRequired", PldInfo->OspmEjectRequired);
919278970Sjkim    AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_CabinetNumber", PldInfo->CabinetNumber);
920278970Sjkim    AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_CardCageNumber", PldInfo->CardCageNumber);
921278970Sjkim    AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_Reference", PldInfo->Reference);
922278970Sjkim    AcpiOsPrintf (ACPI_PLD_OUTPUT08,  "PLD_Rotation", PldInfo->Rotation);
923239340Sjkim
924287168Sjkim    if (ByteCount >= ACPI_PLD_REV2_BUFFER_SIZE)
925278970Sjkim    {
926278970Sjkim        AcpiOsPrintf (ACPI_PLD_OUTPUT08, "PLD_Order", PldInfo->Order);
927278970Sjkim
928287168Sjkim        /* Fifth 32-bit dword */
929239340Sjkim
930287168Sjkim        AcpiOsPrintf (ACPI_PLD_OUTPUT16,  "PLD_VerticalOffset", PldInfo->VerticalOffset);
931278970Sjkim        AcpiOsPrintf (ACPI_PLD_OUTPUT16P, "PLD_HorizontalOffset", PldInfo->HorizontalOffset);
932239340Sjkim    }
933287168Sjkim    else /* Rev 1 buffer */
934287168Sjkim    {
935287168Sjkim        AcpiOsPrintf (ACPI_PLD_OUTPUT08P, "PLD_Order", PldInfo->Order);
936287168Sjkim    }
937239340Sjkim
938239340Sjkim    ACPI_FREE (PldInfo);
939239340Sjkim}
940239340Sjkim
941239340Sjkim
942239340Sjkim/*******************************************************************************
943239340Sjkim *
944100966Siwasaki * FUNCTION:    AcpiDmUnicode
945100966Siwasaki *
946100966Siwasaki * PARAMETERS:  Op              - Byte List op containing Unicode string
947100966Siwasaki *
948100966Siwasaki * RETURN:      None
949100966Siwasaki *
950241973Sjkim * DESCRIPTION: Dump Unicode string as a standard ASCII string. (Remove
951100966Siwasaki *              the extra zero bytes).
952100966Siwasaki *
953100966Siwasaki ******************************************************************************/
954100966Siwasaki
955151937Sjkimstatic void
956100966SiwasakiAcpiDmUnicode (
957100966Siwasaki    ACPI_PARSE_OBJECT       *Op)
958100966Siwasaki{
959100966Siwasaki    UINT16                  *WordData;
960100966Siwasaki    UINT32                  WordCount;
961100966Siwasaki    UINT32                  i;
962278970Sjkim    int                     OutputValue;
963100966Siwasaki
964100966Siwasaki
965100966Siwasaki    /* Extract the buffer info as a WORD buffer */
966100966Siwasaki
967100966Siwasaki    WordData = ACPI_CAST_PTR (UINT16, Op->Named.Data);
968117521Snjl    WordCount = ACPI_DIV_2 (((UINT32) Op->Common.Value.Integer));
969100966Siwasaki
970252279Sjkim    /* Write every other byte as an ASCII character */
971100966Siwasaki
972100966Siwasaki    AcpiOsPrintf ("\"");
973100966Siwasaki    for (i = 0; i < (WordCount - 1); i++)
974100966Siwasaki    {
975278970Sjkim        OutputValue = (int) WordData[i];
976278970Sjkim
977278970Sjkim        /* Handle values that must be escaped */
978278970Sjkim
979278970Sjkim        if ((OutputValue == '\"') ||
980278970Sjkim            (OutputValue == '\\'))
981278970Sjkim        {
982278970Sjkim            AcpiOsPrintf ("\\%c", OutputValue);
983278970Sjkim        }
984284583Sjkim        else if (!isprint (OutputValue))
985278970Sjkim        {
986278970Sjkim            AcpiOsPrintf ("\\x%2.2X", OutputValue);
987278970Sjkim        }
988278970Sjkim        else
989278970Sjkim        {
990278970Sjkim            AcpiOsPrintf ("%c", OutputValue);
991278970Sjkim        }
992100966Siwasaki    }
993100966Siwasaki
994100966Siwasaki    AcpiOsPrintf ("\")");
995100966Siwasaki}
996100966Siwasaki
997100966Siwasaki
998100966Siwasaki/*******************************************************************************
999100966Siwasaki *
1000272444Sjkim * FUNCTION:    AcpiDmGetHardwareIdType
1001100966Siwasaki *
1002100966Siwasaki * PARAMETERS:  Op              - Op to be examined
1003100966Siwasaki *
1004100966Siwasaki * RETURN:      None
1005100966Siwasaki *
1006272444Sjkim * DESCRIPTION: Determine the type of the argument to a _HID or _CID
1007272444Sjkim *              1) Strings are allowed
1008272444Sjkim *              2) If Integer, determine if it is a valid EISAID
1009100966Siwasaki *
1010100966Siwasaki ******************************************************************************/
1011100966Siwasaki
1012193267Sjkimstatic void
1013272444SjkimAcpiDmGetHardwareIdType (
1014100966Siwasaki    ACPI_PARSE_OBJECT       *Op)
1015100966Siwasaki{
1016100966Siwasaki    UINT32                  BigEndianId;
1017100966Siwasaki    UINT32                  Prefix[3];
1018193267Sjkim    UINT32                  i;
1019100966Siwasaki
1020100966Siwasaki
1021272444Sjkim    switch (Op->Common.AmlOpcode)
1022100966Siwasaki    {
1023272444Sjkim    case AML_STRING_OP:
1024100966Siwasaki
1025272444Sjkim        /* Mark this string as an _HID/_CID string */
1026100966Siwasaki
1027272444Sjkim        Op->Common.DisasmOpcode = ACPI_DASM_HID_STRING;
1028272444Sjkim        break;
1029100966Siwasaki
1030272444Sjkim    case AML_WORD_OP:
1031272444Sjkim    case AML_DWORD_OP:
1032100966Siwasaki
1033272444Sjkim        /* Determine if a Word/Dword is a valid encoded EISAID */
1034100966Siwasaki
1035272444Sjkim        /* Swap from little-endian to big-endian to simplify conversion */
1036100966Siwasaki
1037272444Sjkim        BigEndianId = AcpiUtDwordByteSwap ((UINT32) Op->Common.Value.Integer);
1038272444Sjkim
1039272444Sjkim        /* Create the 3 leading ASCII letters */
1040272444Sjkim
1041272444Sjkim        Prefix[0] = ((BigEndianId >> 26) & 0x1F) + 0x40;
1042272444Sjkim        Prefix[1] = ((BigEndianId >> 21) & 0x1F) + 0x40;
1043272444Sjkim        Prefix[2] = ((BigEndianId >> 16) & 0x1F) + 0x40;
1044272444Sjkim
1045272444Sjkim        /* Verify that all 3 are ascii and alpha */
1046272444Sjkim
1047272444Sjkim        for (i = 0; i < 3; i++)
1048100966Siwasaki        {
1049272444Sjkim            if (!ACPI_IS_ASCII (Prefix[i]) ||
1050284583Sjkim                !isalpha (Prefix[i]))
1051272444Sjkim            {
1052272444Sjkim                return;
1053272444Sjkim            }
1054100966Siwasaki        }
1055100966Siwasaki
1056272444Sjkim        /* Mark this node as convertable to an EISA ID string */
1057100966Siwasaki
1058272444Sjkim        Op->Common.DisasmOpcode = ACPI_DASM_EISAID;
1059272444Sjkim        break;
1060272444Sjkim
1061272444Sjkim    default:
1062272444Sjkim        break;
1063272444Sjkim    }
1064100966Siwasaki}
1065100966Siwasaki
1066100966Siwasaki
1067100966Siwasaki/*******************************************************************************
1068100966Siwasaki *
1069272444Sjkim * FUNCTION:    AcpiDmCheckForHardwareId
1070193267Sjkim *
1071193267Sjkim * PARAMETERS:  Op              - Op to be examined
1072193267Sjkim *
1073193267Sjkim * RETURN:      None
1074193267Sjkim *
1075272444Sjkim * DESCRIPTION: Determine if a Name() Op is a _HID/_CID.
1076193267Sjkim *
1077193267Sjkim ******************************************************************************/
1078193267Sjkim
1079193267Sjkimvoid
1080272444SjkimAcpiDmCheckForHardwareId (
1081193267Sjkim    ACPI_PARSE_OBJECT       *Op)
1082193267Sjkim{
1083193267Sjkim    UINT32                  Name;
1084193267Sjkim    ACPI_PARSE_OBJECT       *NextOp;
1085193267Sjkim
1086193267Sjkim
1087193267Sjkim    /* Get the NameSegment */
1088193267Sjkim
1089193267Sjkim    Name = AcpiPsGetName (Op);
1090193267Sjkim    if (!Name)
1091193267Sjkim    {
1092193267Sjkim        return;
1093193267Sjkim    }
1094193267Sjkim
1095193267Sjkim    NextOp = AcpiPsGetDepthNext (NULL, Op);
1096193267Sjkim    if (!NextOp)
1097193267Sjkim    {
1098193267Sjkim        return;
1099193267Sjkim    }
1100193267Sjkim
1101193267Sjkim    /* Check for _HID - has one argument */
1102193267Sjkim
1103193267Sjkim    if (ACPI_COMPARE_NAME (&Name, METHOD_NAME__HID))
1104193267Sjkim    {
1105272444Sjkim        AcpiDmGetHardwareIdType (NextOp);
1106193267Sjkim        return;
1107193267Sjkim    }
1108193267Sjkim
1109193267Sjkim    /* Exit if not _CID */
1110193267Sjkim
1111193267Sjkim    if (!ACPI_COMPARE_NAME (&Name, METHOD_NAME__CID))
1112193267Sjkim    {
1113193267Sjkim        return;
1114193267Sjkim    }
1115193267Sjkim
1116193267Sjkim    /* _CID can contain a single argument or a package */
1117193267Sjkim
1118193267Sjkim    if (NextOp->Common.AmlOpcode != AML_PACKAGE_OP)
1119193267Sjkim    {
1120272444Sjkim        AcpiDmGetHardwareIdType (NextOp);
1121193267Sjkim        return;
1122193267Sjkim    }
1123193267Sjkim
1124272444Sjkim    /* _CID with Package: get the package length, check all elements */
1125193267Sjkim
1126193267Sjkim    NextOp = AcpiPsGetDepthNext (NULL, NextOp);
1127272444Sjkim    if (!NextOp)
1128272444Sjkim    {
1129272444Sjkim        return;
1130272444Sjkim    }
1131193267Sjkim
1132193267Sjkim    /* Don't need to use the length, just walk the peer list */
1133193267Sjkim
1134193267Sjkim    NextOp = NextOp->Common.Next;
1135193267Sjkim    while (NextOp)
1136193267Sjkim    {
1137272444Sjkim        AcpiDmGetHardwareIdType (NextOp);
1138193267Sjkim        NextOp = NextOp->Common.Next;
1139193267Sjkim    }
1140193267Sjkim}
1141193267Sjkim
1142193267Sjkim
1143193267Sjkim/*******************************************************************************
1144193267Sjkim *
1145272444Sjkim * FUNCTION:    AcpiDmDecompressEisaId
1146100966Siwasaki *
1147100966Siwasaki * PARAMETERS:  EncodedId       - Raw encoded EISA ID.
1148100966Siwasaki *
1149100966Siwasaki * RETURN:      None
1150100966Siwasaki *
1151272444Sjkim * DESCRIPTION: Convert an encoded EISAID back to the original ASCII String
1152272444Sjkim *              and emit the correct ASL statement. If the ID is known, emit
1153272444Sjkim *              a description of the ID as a comment.
1154100966Siwasaki *
1155100966Siwasaki ******************************************************************************/
1156100966Siwasaki
1157100966Siwasakivoid
1158272444SjkimAcpiDmDecompressEisaId (
1159100966Siwasaki    UINT32                  EncodedId)
1160100966Siwasaki{
1161272444Sjkim    char                    IdBuffer[ACPI_EISAID_STRING_SIZE];
1162272444Sjkim    const AH_DEVICE_ID      *Info;
1163100966Siwasaki
1164100966Siwasaki
1165272444Sjkim    /* Convert EISAID to a string an emit the statement */
1166100966Siwasaki
1167272444Sjkim    AcpiExEisaIdToString (IdBuffer, EncodedId);
1168272444Sjkim    AcpiOsPrintf ("EisaId (\"%s\")", IdBuffer);
1169100966Siwasaki
1170272444Sjkim    /* If we know about the ID, emit the description */
1171100966Siwasaki
1172272444Sjkim    Info = AcpiAhMatchHardwareId (IdBuffer);
1173272444Sjkim    if (Info)
1174272444Sjkim    {
1175272444Sjkim        AcpiOsPrintf (" /* %s */", Info->Description);
1176272444Sjkim    }
1177100966Siwasaki}
1178