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);
74 #define ACPI_BUFFER_BYTES_PER_LINE 8
77 /*******************************************************************************
79 * FUNCTION: AcpiDmDisasmByteList
81 * PARAMETERS: Level - Current source code indentation level
82 * ByteData - Pointer to the byte list
83 * ByteCount - Length of the byte list
87 * DESCRIPTION: Dump an AML "ByteList" in Hex format. 8 bytes per line, prefixed
88 * with the hex buffer offset.
90 ******************************************************************************/
93 AcpiDmDisasmByteList (
109 for (i = 0; i < ByteCount; i += ACPI_BUFFER_BYTES_PER_LINE)
111 /* Line indent and offset prefix for each new line */
113 AcpiDmIndent (Level);
114 if (ByteCount > ACPI_BUFFER_BYTES_PER_LINE)
116 AcpiOsPrintf ("/* %04X */ ", i);
119 /* Dump the actual hex values */
121 for (j = 0; j < ACPI_BUFFER_BYTES_PER_LINE; j++)
123 CurrentIndex = i + j;
124 if (CurrentIndex >= ByteCount)
126 /* Dump fill spaces */
132 AcpiOsPrintf (" 0x%2.2X", ByteData[CurrentIndex]);
134 /* Add comma if there are more bytes to display */
136 if (CurrentIndex < (ByteCount - 1))
146 /* Dump the ASCII equivalents within a comment */
148 AcpiOsPrintf (" /* ");
149 for (j = 0; j < ACPI_BUFFER_BYTES_PER_LINE; j++)
151 CurrentIndex = i + j;
152 if (CurrentIndex >= ByteCount)
157 BufChar = ByteData[CurrentIndex];
158 if (ACPI_IS_PRINT (BufChar))
160 AcpiOsPrintf ("%c", BufChar);
168 /* Finished with this line */
170 AcpiOsPrintf (" */\n");
175 /*******************************************************************************
177 * FUNCTION: AcpiDmByteList
179 * PARAMETERS: Info - Parse tree walk info
184 * DESCRIPTION: Dump a buffer byte list, handling the various types of buffers.
185 * Buffer type must be already set in the Op DisasmOpcode.
187 ******************************************************************************/
191 ACPI_OP_WALK_INFO *Info,
192 ACPI_PARSE_OBJECT *Op)
198 ByteData = Op->Named.Data;
199 ByteCount = (UINT32) Op->Common.Value.Integer;
202 * The byte list belongs to a buffer, and can be produced by either
203 * a ResourceTemplate, Unicode, quoted string, or a plain byte list.
205 switch (Op->Common.Parent->Common.DisasmOpcode)
207 case ACPI_DASM_RESOURCE:
209 AcpiDmResourceTemplate (Info, Op->Common.Parent, ByteData, ByteCount);
212 case ACPI_DASM_STRING:
214 AcpiDmIndent (Info->Level);
215 AcpiUtPrintString ((char *) ByteData, ACPI_UINT16_MAX);
219 case ACPI_DASM_UNICODE:
224 case ACPI_DASM_PLD_METHOD:
226 AcpiDmDisasmByteList (Info->Level, ByteData, ByteCount);
227 AcpiDmPldBuffer (Info->Level, ByteData, ByteCount);
230 case ACPI_DASM_BUFFER:
233 * Not a resource, string, or unicode string.
234 * Just dump the buffer
236 AcpiDmDisasmByteList (Info->Level, ByteData, ByteCount);
242 /*******************************************************************************
244 * FUNCTION: AcpiDmIsUnicodeBuffer
246 * PARAMETERS: Op - Buffer Object to be examined
248 * RETURN: TRUE if buffer contains a UNICODE string
250 * DESCRIPTION: Determine if a buffer Op contains a Unicode string
252 ******************************************************************************/
255 AcpiDmIsUnicodeBuffer (
256 ACPI_PARSE_OBJECT *Op)
261 ACPI_PARSE_OBJECT *SizeOp;
262 ACPI_PARSE_OBJECT *NextOp;
266 /* Buffer size is the buffer argument */
268 SizeOp = Op->Common.Value.Arg;
270 /* Next, the initializer byte list to examine */
272 NextOp = SizeOp->Common.Next;
278 /* Extract the byte list info */
280 ByteData = NextOp->Named.Data;
281 ByteCount = (UINT32) NextOp->Common.Value.Integer;
282 WordCount = ACPI_DIV_2 (ByteCount);
285 * Unicode string must have an even number of bytes and last
291 ((UINT16 *) (void *) ByteData)[WordCount - 1] != 0)
296 /* For each word, 1st byte must be ascii, 2nd byte must be zero */
298 for (i = 0; i < (ByteCount - 2); i += 2)
300 if ((!ACPI_IS_PRINT (ByteData[i])) ||
301 (ByteData[(ACPI_SIZE) i + 1] != 0))
307 /* Ignore the Size argument in the disassembly of this buffer op */
309 SizeOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
314 /*******************************************************************************
316 * FUNCTION: AcpiDmIsStringBuffer
318 * PARAMETERS: Op - Buffer Object to be examined
320 * RETURN: TRUE if buffer contains a ASCII string, FALSE otherwise
322 * DESCRIPTION: Determine if a buffer Op contains a ASCII string
324 ******************************************************************************/
327 AcpiDmIsStringBuffer (
328 ACPI_PARSE_OBJECT *Op)
332 ACPI_PARSE_OBJECT *SizeOp;
333 ACPI_PARSE_OBJECT *NextOp;
337 /* Buffer size is the buffer argument */
339 SizeOp = Op->Common.Value.Arg;
341 /* Next, the initializer byte list to examine */
343 NextOp = SizeOp->Common.Next;
349 /* Extract the byte list info */
351 ByteData = NextOp->Named.Data;
352 ByteCount = (UINT32) NextOp->Common.Value.Integer;
354 /* Last byte must be the null terminator */
358 (ByteData[ByteCount-1] != 0))
363 for (i = 0; i < (ByteCount - 1); i++)
365 /* TBD: allow some escapes (non-ascii chars).
366 * they will be handled in the string output routine
369 if (!ACPI_IS_PRINT (ByteData[i]))
379 /*******************************************************************************
381 * FUNCTION: AcpiDmIsPldBuffer
383 * PARAMETERS: Op - Buffer Object to be examined
385 * RETURN: TRUE if buffer contains a ASCII string, FALSE otherwise
387 * DESCRIPTION: Determine if a buffer Op contains a _PLD structure
389 ******************************************************************************/
393 ACPI_PARSE_OBJECT *Op)
395 ACPI_NAMESPACE_NODE *Node;
396 ACPI_PARSE_OBJECT *ParentOp;
399 ParentOp = Op->Common.Parent;
405 /* Check for form: Name(_PLD, Buffer() {}). Not legal, however */
407 if (ParentOp->Common.AmlOpcode == AML_NAME_OP)
409 Node = ParentOp->Common.Node;
411 if (ACPI_COMPARE_NAME (Node->Name.Ascii, METHOD_NAME__PLD))
419 /* Check for proper form: Name(_PLD, Package() {Buffer() {}}) */
421 if (ParentOp->Common.AmlOpcode == AML_PACKAGE_OP)
423 ParentOp = ParentOp->Common.Parent;
429 if (ParentOp->Common.AmlOpcode == AML_NAME_OP)
431 Node = ParentOp->Common.Node;
433 if (ACPI_COMPARE_NAME (Node->Name.Ascii, METHOD_NAME__PLD))
444 /*******************************************************************************
446 * FUNCTION: AcpiDmPldBuffer
448 * PARAMETERS: Level - Current source code indentation level
449 * ByteData - Pointer to the byte list
450 * ByteCount - Length of the byte list
454 * DESCRIPTION: Dump and format the contents of a _PLD buffer object
456 ******************************************************************************/
458 #define ACPI_PLD_OUTPUT08 "%*.s/* %18s : %-6.2X */\n", ACPI_MUL_4 (Level), " "
459 #define ACPI_PLD_OUTPUT16 "%*.s/* %18s : %-6.4X */\n", ACPI_MUL_4 (Level), " "
460 #define ACPI_PLD_OUTPUT24 "%*.s/* %18s : %-6.6X */\n", ACPI_MUL_4 (Level), " "
468 ACPI_PLD_INFO *PldInfo;
472 /* Check for valid byte count */
474 if (ByteCount < ACPI_PLD_REV1_BUFFER_SIZE)
479 /* Convert _PLD buffer to local _PLD struct */
481 Status = AcpiDecodePldBuffer (ByteData, ByteCount, &PldInfo);
482 if (ACPI_FAILURE (Status))
487 /* First 32-bit dword */
489 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "Revision", PldInfo->Revision);
490 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "IgnoreColor", PldInfo->IgnoreColor);
491 AcpiOsPrintf (ACPI_PLD_OUTPUT24,"Color", PldInfo->Color);
493 /* Second 32-bit dword */
495 AcpiOsPrintf (ACPI_PLD_OUTPUT16,"Width", PldInfo->Width);
496 AcpiOsPrintf (ACPI_PLD_OUTPUT16,"Height", PldInfo->Height);
498 /* Third 32-bit dword */
500 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "UserVisible", PldInfo->UserVisible);
501 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "Dock", PldInfo->Dock);
502 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "Lid", PldInfo->Lid);
503 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "Panel", PldInfo->Panel);
504 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "VerticalPosition", PldInfo->VerticalPosition);
505 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "HorizontalPosition", PldInfo->HorizontalPosition);
506 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "Shape", PldInfo->Shape);
507 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "GroupOrientation", PldInfo->GroupOrientation);
508 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "GroupToken", PldInfo->GroupToken);
509 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "GroupPosition", PldInfo->GroupPosition);
510 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "Bay", PldInfo->Bay);
512 /* Fourth 32-bit dword */
514 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "Ejectable", PldInfo->Ejectable);
515 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "OspmEjectRequired", PldInfo->OspmEjectRequired);
516 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "CabinetNumber", PldInfo->CabinetNumber);
517 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "CardCageNumber", PldInfo->CardCageNumber);
518 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "Reference", PldInfo->Reference);
519 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "Rotation", PldInfo->Rotation);
520 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "Order", PldInfo->Order);
522 /* Fifth 32-bit dword */
524 if (ByteCount >= ACPI_PLD_REV1_BUFFER_SIZE)
526 AcpiOsPrintf (ACPI_PLD_OUTPUT16,"VerticalOffset", PldInfo->VerticalOffset);
527 AcpiOsPrintf (ACPI_PLD_OUTPUT16,"HorizontalOffset", PldInfo->HorizontalOffset);
534 /*******************************************************************************
536 * FUNCTION: AcpiDmUnicode
538 * PARAMETERS: Op - Byte List op containing Unicode string
542 * DESCRIPTION: Dump Unicode string as a standard ASCII string. (Remove
543 * the extra zero bytes).
545 ******************************************************************************/
549 ACPI_PARSE_OBJECT *Op)
556 /* Extract the buffer info as a WORD buffer */
558 WordData = ACPI_CAST_PTR (UINT16, Op->Named.Data);
559 WordCount = ACPI_DIV_2 (((UINT32) Op->Common.Value.Integer));
561 /* Write every other byte as an ASCII character */
564 for (i = 0; i < (WordCount - 1); i++)
566 AcpiOsPrintf ("%c", (int) WordData[i]);
569 AcpiOsPrintf ("\")");
573 /*******************************************************************************
575 * FUNCTION: AcpiDmGetHardwareIdType
577 * PARAMETERS: Op - Op to be examined
581 * DESCRIPTION: Determine the type of the argument to a _HID or _CID
582 * 1) Strings are allowed
583 * 2) If Integer, determine if it is a valid EISAID
585 ******************************************************************************/
588 AcpiDmGetHardwareIdType (
589 ACPI_PARSE_OBJECT *Op)
596 switch (Op->Common.AmlOpcode)
600 /* Mark this string as an _HID/_CID string */
602 Op->Common.DisasmOpcode = ACPI_DASM_HID_STRING;
608 /* Determine if a Word/Dword is a valid encoded EISAID */
610 /* Swap from little-endian to big-endian to simplify conversion */
612 BigEndianId = AcpiUtDwordByteSwap ((UINT32) Op->Common.Value.Integer);
614 /* Create the 3 leading ASCII letters */
616 Prefix[0] = ((BigEndianId >> 26) & 0x1F) + 0x40;
617 Prefix[1] = ((BigEndianId >> 21) & 0x1F) + 0x40;
618 Prefix[2] = ((BigEndianId >> 16) & 0x1F) + 0x40;
620 /* Verify that all 3 are ascii and alpha */
622 for (i = 0; i < 3; i++)
624 if (!ACPI_IS_ASCII (Prefix[i]) ||
625 !ACPI_IS_ALPHA (Prefix[i]))
631 /* Mark this node as convertable to an EISA ID string */
633 Op->Common.DisasmOpcode = ACPI_DASM_EISAID;
642 /*******************************************************************************
644 * FUNCTION: AcpiDmCheckForHardwareId
646 * PARAMETERS: Op - Op to be examined
650 * DESCRIPTION: Determine if a Name() Op is a _HID/_CID.
652 ******************************************************************************/
655 AcpiDmCheckForHardwareId (
656 ACPI_PARSE_OBJECT *Op)
659 ACPI_PARSE_OBJECT *NextOp;
662 /* Get the NameSegment */
664 Name = AcpiPsGetName (Op);
670 NextOp = AcpiPsGetDepthNext (NULL, Op);
676 /* Check for _HID - has one argument */
678 if (ACPI_COMPARE_NAME (&Name, METHOD_NAME__HID))
680 AcpiDmGetHardwareIdType (NextOp);
684 /* Exit if not _CID */
686 if (!ACPI_COMPARE_NAME (&Name, METHOD_NAME__CID))
691 /* _CID can contain a single argument or a package */
693 if (NextOp->Common.AmlOpcode != AML_PACKAGE_OP)
695 AcpiDmGetHardwareIdType (NextOp);
699 /* _CID with Package: get the package length, check all elements */
701 NextOp = AcpiPsGetDepthNext (NULL, NextOp);
703 /* Don't need to use the length, just walk the peer list */
705 NextOp = NextOp->Common.Next;
708 AcpiDmGetHardwareIdType (NextOp);
709 NextOp = NextOp->Common.Next;
714 /*******************************************************************************
716 * FUNCTION: AcpiDmDecompressEisaId
718 * PARAMETERS: EncodedId - Raw encoded EISA ID.
722 * DESCRIPTION: Convert an encoded EISAID back to the original ASCII String
723 * and emit the correct ASL statement. If the ID is known, emit
724 * a description of the ID as a comment.
726 ******************************************************************************/
729 AcpiDmDecompressEisaId (
732 char IdBuffer[ACPI_EISAID_STRING_SIZE];
733 const AH_DEVICE_ID *Info;
736 /* Convert EISAID to a string an emit the statement */
738 AcpiExEisaIdToString (IdBuffer, EncodedId);
739 AcpiOsPrintf ("EisaId (\"%s\")", IdBuffer);
741 /* If we know about the ID, emit the description */
743 Info = AcpiAhMatchHardwareId (IdBuffer);
746 AcpiOsPrintf (" /* %s */", Info->Description);