1 /*******************************************************************************
3 * Module Name: dmbuffer - AML disassembler, buffer and string support
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2014, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
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.
53 #ifdef ACPI_DISASSEMBLER
55 #define _COMPONENT ACPI_CA_DEBUGGER
56 ACPI_MODULE_NAME ("dmbuffer")
58 /* Local prototypes */
62 ACPI_PARSE_OBJECT *Op);
65 AcpiDmGetHardwareIdType (
66 ACPI_PARSE_OBJECT *Op);
75 /*******************************************************************************
77 * FUNCTION: AcpiDmDisasmByteList
79 * PARAMETERS: Level - Current source code indentation level
80 * ByteData - Pointer to the byte list
81 * ByteCount - Length of the byte list
85 * DESCRIPTION: Dump an AML "ByteList" in Hex format. 8 bytes per line, prefixed
86 * with the hex buffer offset.
88 ******************************************************************************/
91 AcpiDmDisasmByteList (
104 /* Dump the byte list */
106 for (i = 0; i < ByteCount; i++)
108 /* New line every 8 bytes */
110 if (((i % 8) == 0) && (i < ByteCount))
117 AcpiDmIndent (Level);
120 AcpiOsPrintf ("/* %04X */ ", i);
124 AcpiOsPrintf (" 0x%2.2X", (UINT32) ByteData[i]);
126 /* Add comma if there are more bytes to display */
128 if (i < (ByteCount -1))
141 /*******************************************************************************
143 * FUNCTION: AcpiDmByteList
145 * PARAMETERS: Info - Parse tree walk info
150 * DESCRIPTION: Dump a buffer byte list, handling the various types of buffers.
151 * Buffer type must be already set in the Op DisasmOpcode.
153 ******************************************************************************/
157 ACPI_OP_WALK_INFO *Info,
158 ACPI_PARSE_OBJECT *Op)
164 ByteData = Op->Named.Data;
165 ByteCount = (UINT32) Op->Common.Value.Integer;
168 * The byte list belongs to a buffer, and can be produced by either
169 * a ResourceTemplate, Unicode, quoted string, or a plain byte list.
171 switch (Op->Common.Parent->Common.DisasmOpcode)
173 case ACPI_DASM_RESOURCE:
175 AcpiDmResourceTemplate (Info, Op->Common.Parent, ByteData, ByteCount);
178 case ACPI_DASM_STRING:
180 AcpiDmIndent (Info->Level);
181 AcpiUtPrintString ((char *) ByteData, ACPI_UINT16_MAX);
185 case ACPI_DASM_UNICODE:
190 case ACPI_DASM_PLD_METHOD:
192 AcpiDmDisasmByteList (Info->Level, ByteData, ByteCount);
193 AcpiDmPldBuffer (Info->Level, ByteData, ByteCount);
196 case ACPI_DASM_BUFFER:
199 * Not a resource, string, or unicode string.
200 * Just dump the buffer
202 AcpiDmDisasmByteList (Info->Level, ByteData, ByteCount);
208 /*******************************************************************************
210 * FUNCTION: AcpiDmIsUnicodeBuffer
212 * PARAMETERS: Op - Buffer Object to be examined
214 * RETURN: TRUE if buffer contains a UNICODE string
216 * DESCRIPTION: Determine if a buffer Op contains a Unicode string
218 ******************************************************************************/
221 AcpiDmIsUnicodeBuffer (
222 ACPI_PARSE_OBJECT *Op)
227 ACPI_PARSE_OBJECT *SizeOp;
228 ACPI_PARSE_OBJECT *NextOp;
232 /* Buffer size is the buffer argument */
234 SizeOp = Op->Common.Value.Arg;
236 /* Next, the initializer byte list to examine */
238 NextOp = SizeOp->Common.Next;
244 /* Extract the byte list info */
246 ByteData = NextOp->Named.Data;
247 ByteCount = (UINT32) NextOp->Common.Value.Integer;
248 WordCount = ACPI_DIV_2 (ByteCount);
251 * Unicode string must have an even number of bytes and last
257 ((UINT16 *) (void *) ByteData)[WordCount - 1] != 0)
262 /* For each word, 1st byte must be ascii, 2nd byte must be zero */
264 for (i = 0; i < (ByteCount - 2); i += 2)
266 if ((!ACPI_IS_PRINT (ByteData[i])) ||
267 (ByteData[(ACPI_SIZE) i + 1] != 0))
273 /* Ignore the Size argument in the disassembly of this buffer op */
275 SizeOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
280 /*******************************************************************************
282 * FUNCTION: AcpiDmIsStringBuffer
284 * PARAMETERS: Op - Buffer Object to be examined
286 * RETURN: TRUE if buffer contains a ASCII string, FALSE otherwise
288 * DESCRIPTION: Determine if a buffer Op contains a ASCII string
290 ******************************************************************************/
293 AcpiDmIsStringBuffer (
294 ACPI_PARSE_OBJECT *Op)
298 ACPI_PARSE_OBJECT *SizeOp;
299 ACPI_PARSE_OBJECT *NextOp;
303 /* Buffer size is the buffer argument */
305 SizeOp = Op->Common.Value.Arg;
307 /* Next, the initializer byte list to examine */
309 NextOp = SizeOp->Common.Next;
315 /* Extract the byte list info */
317 ByteData = NextOp->Named.Data;
318 ByteCount = (UINT32) NextOp->Common.Value.Integer;
320 /* Last byte must be the null terminator */
324 (ByteData[ByteCount-1] != 0))
329 for (i = 0; i < (ByteCount - 1); i++)
331 /* TBD: allow some escapes (non-ascii chars).
332 * they will be handled in the string output routine
335 if (!ACPI_IS_PRINT (ByteData[i]))
345 /*******************************************************************************
347 * FUNCTION: AcpiDmIsPldBuffer
349 * PARAMETERS: Op - Buffer Object to be examined
351 * RETURN: TRUE if buffer contains a ASCII string, FALSE otherwise
353 * DESCRIPTION: Determine if a buffer Op contains a _PLD structure
355 ******************************************************************************/
359 ACPI_PARSE_OBJECT *Op)
361 ACPI_NAMESPACE_NODE *Node;
362 ACPI_PARSE_OBJECT *ParentOp;
365 ParentOp = Op->Common.Parent;
371 /* Check for form: Name(_PLD, Buffer() {}). Not legal, however */
373 if (ParentOp->Common.AmlOpcode == AML_NAME_OP)
375 Node = ParentOp->Common.Node;
377 if (ACPI_COMPARE_NAME (Node->Name.Ascii, METHOD_NAME__PLD))
385 /* Check for proper form: Name(_PLD, Package() {Buffer() {}}) */
387 if (ParentOp->Common.AmlOpcode == AML_PACKAGE_OP)
389 ParentOp = ParentOp->Common.Parent;
395 if (ParentOp->Common.AmlOpcode == AML_NAME_OP)
397 Node = ParentOp->Common.Node;
399 if (ACPI_COMPARE_NAME (Node->Name.Ascii, METHOD_NAME__PLD))
410 /*******************************************************************************
412 * FUNCTION: AcpiDmPldBuffer
414 * PARAMETERS: Level - Current source code indentation level
415 * ByteData - Pointer to the byte list
416 * ByteCount - Length of the byte list
420 * DESCRIPTION: Dump and format the contents of a _PLD buffer object
422 ******************************************************************************/
424 #define ACPI_PLD_OUTPUT08 "%*.s/* %18s : %-6.2X */\n", ACPI_MUL_4 (Level), " "
425 #define ACPI_PLD_OUTPUT16 "%*.s/* %18s : %-6.4X */\n", ACPI_MUL_4 (Level), " "
426 #define ACPI_PLD_OUTPUT24 "%*.s/* %18s : %-6.6X */\n", ACPI_MUL_4 (Level), " "
434 ACPI_PLD_INFO *PldInfo;
438 /* Check for valid byte count */
440 if (ByteCount < ACPI_PLD_REV1_BUFFER_SIZE)
445 /* Convert _PLD buffer to local _PLD struct */
447 Status = AcpiDecodePldBuffer (ByteData, ByteCount, &PldInfo);
448 if (ACPI_FAILURE (Status))
453 /* First 32-bit dword */
455 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "Revision", PldInfo->Revision);
456 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "IgnoreColor", PldInfo->IgnoreColor);
457 AcpiOsPrintf (ACPI_PLD_OUTPUT24,"Color", PldInfo->Color);
459 /* Second 32-bit dword */
461 AcpiOsPrintf (ACPI_PLD_OUTPUT16,"Width", PldInfo->Width);
462 AcpiOsPrintf (ACPI_PLD_OUTPUT16,"Height", PldInfo->Height);
464 /* Third 32-bit dword */
466 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "UserVisible", PldInfo->UserVisible);
467 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "Dock", PldInfo->Dock);
468 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "Lid", PldInfo->Lid);
469 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "Panel", PldInfo->Panel);
470 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "VerticalPosition", PldInfo->VerticalPosition);
471 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "HorizontalPosition", PldInfo->HorizontalPosition);
472 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "Shape", PldInfo->Shape);
473 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "GroupOrientation", PldInfo->GroupOrientation);
474 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "GroupToken", PldInfo->GroupToken);
475 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "GroupPosition", PldInfo->GroupPosition);
476 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "Bay", PldInfo->Bay);
478 /* Fourth 32-bit dword */
480 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "Ejectable", PldInfo->Ejectable);
481 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "OspmEjectRequired", PldInfo->OspmEjectRequired);
482 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "CabinetNumber", PldInfo->CabinetNumber);
483 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "CardCageNumber", PldInfo->CardCageNumber);
484 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "Reference", PldInfo->Reference);
485 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "Rotation", PldInfo->Rotation);
486 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "Order", PldInfo->Order);
488 /* Fifth 32-bit dword */
490 if (ByteCount >= ACPI_PLD_REV1_BUFFER_SIZE)
492 AcpiOsPrintf (ACPI_PLD_OUTPUT16,"VerticalOffset", PldInfo->VerticalOffset);
493 AcpiOsPrintf (ACPI_PLD_OUTPUT16,"HorizontalOffset", PldInfo->HorizontalOffset);
500 /*******************************************************************************
502 * FUNCTION: AcpiDmUnicode
504 * PARAMETERS: Op - Byte List op containing Unicode string
508 * DESCRIPTION: Dump Unicode string as a standard ASCII string. (Remove
509 * the extra zero bytes).
511 ******************************************************************************/
515 ACPI_PARSE_OBJECT *Op)
522 /* Extract the buffer info as a WORD buffer */
524 WordData = ACPI_CAST_PTR (UINT16, Op->Named.Data);
525 WordCount = ACPI_DIV_2 (((UINT32) Op->Common.Value.Integer));
527 /* Write every other byte as an ASCII character */
530 for (i = 0; i < (WordCount - 1); i++)
532 AcpiOsPrintf ("%c", (int) WordData[i]);
535 AcpiOsPrintf ("\")");
539 /*******************************************************************************
541 * FUNCTION: AcpiDmGetHardwareIdType
543 * PARAMETERS: Op - Op to be examined
547 * DESCRIPTION: Determine the type of the argument to a _HID or _CID
548 * 1) Strings are allowed
549 * 2) If Integer, determine if it is a valid EISAID
551 ******************************************************************************/
554 AcpiDmGetHardwareIdType (
555 ACPI_PARSE_OBJECT *Op)
562 switch (Op->Common.AmlOpcode)
566 /* Mark this string as an _HID/_CID string */
568 Op->Common.DisasmOpcode = ACPI_DASM_HID_STRING;
574 /* Determine if a Word/Dword is a valid encoded EISAID */
576 /* Swap from little-endian to big-endian to simplify conversion */
578 BigEndianId = AcpiUtDwordByteSwap ((UINT32) Op->Common.Value.Integer);
580 /* Create the 3 leading ASCII letters */
582 Prefix[0] = ((BigEndianId >> 26) & 0x1F) + 0x40;
583 Prefix[1] = ((BigEndianId >> 21) & 0x1F) + 0x40;
584 Prefix[2] = ((BigEndianId >> 16) & 0x1F) + 0x40;
586 /* Verify that all 3 are ascii and alpha */
588 for (i = 0; i < 3; i++)
590 if (!ACPI_IS_ASCII (Prefix[i]) ||
591 !ACPI_IS_ALPHA (Prefix[i]))
597 /* Mark this node as convertable to an EISA ID string */
599 Op->Common.DisasmOpcode = ACPI_DASM_EISAID;
608 /*******************************************************************************
610 * FUNCTION: AcpiDmCheckForHardwareId
612 * PARAMETERS: Op - Op to be examined
616 * DESCRIPTION: Determine if a Name() Op is a _HID/_CID.
618 ******************************************************************************/
621 AcpiDmCheckForHardwareId (
622 ACPI_PARSE_OBJECT *Op)
625 ACPI_PARSE_OBJECT *NextOp;
628 /* Get the NameSegment */
630 Name = AcpiPsGetName (Op);
636 NextOp = AcpiPsGetDepthNext (NULL, Op);
642 /* Check for _HID - has one argument */
644 if (ACPI_COMPARE_NAME (&Name, METHOD_NAME__HID))
646 AcpiDmGetHardwareIdType (NextOp);
650 /* Exit if not _CID */
652 if (!ACPI_COMPARE_NAME (&Name, METHOD_NAME__CID))
657 /* _CID can contain a single argument or a package */
659 if (NextOp->Common.AmlOpcode != AML_PACKAGE_OP)
661 AcpiDmGetHardwareIdType (NextOp);
665 /* _CID with Package: get the package length, check all elements */
667 NextOp = AcpiPsGetDepthNext (NULL, NextOp);
669 /* Don't need to use the length, just walk the peer list */
671 NextOp = NextOp->Common.Next;
674 AcpiDmGetHardwareIdType (NextOp);
675 NextOp = NextOp->Common.Next;
680 /*******************************************************************************
682 * FUNCTION: AcpiDmDecompressEisaId
684 * PARAMETERS: EncodedId - Raw encoded EISA ID.
688 * DESCRIPTION: Convert an encoded EISAID back to the original ASCII String
689 * and emit the correct ASL statement. If the ID is known, emit
690 * a description of the ID as a comment.
692 ******************************************************************************/
695 AcpiDmDecompressEisaId (
698 char IdBuffer[ACPI_EISAID_STRING_SIZE];
699 const AH_DEVICE_ID *Info;
702 /* Convert EISAID to a string an emit the statement */
704 AcpiExEisaIdToString (IdBuffer, EncodedId);
705 AcpiOsPrintf ("EisaId (\"%s\")", IdBuffer);
707 /* If we know about the ID, emit the description */
709 Info = AcpiAhMatchHardwareId (IdBuffer);
712 AcpiOsPrintf (" /* %s */", Info->Description);