Indentation fix, cleanup.
[AROS.git] / arch / all-pc / acpica / source / components / disassembler / dmbuffer.c
bloba9496a958d21bdf97578e4a24407bce7e5a9286f
1 /*******************************************************************************
3 * Module Name: dmbuffer - AML disassembler, buffer and string support
5 ******************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2013, Intel Corp.
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
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.
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
45 #include "acpi.h"
46 #include "accommon.h"
47 #include "acdisasm.h"
48 #include "acparser.h"
49 #include "amlcode.h"
52 #ifdef ACPI_DISASSEMBLER
54 #define _COMPONENT ACPI_CA_DEBUGGER
55 ACPI_MODULE_NAME ("dmbuffer")
57 /* Local prototypes */
59 static void
60 AcpiDmUnicode (
61 ACPI_PARSE_OBJECT *Op);
63 static void
64 AcpiDmIsEisaIdElement (
65 ACPI_PARSE_OBJECT *Op);
67 static void
68 AcpiDmPldBuffer (
69 UINT32 Level,
70 UINT8 *ByteData,
71 UINT32 ByteCount);
74 /*******************************************************************************
76 * FUNCTION: AcpiDmDisasmByteList
78 * PARAMETERS: Level - Current source code indentation level
79 * ByteData - Pointer to the byte list
80 * ByteCount - Length of the byte list
82 * RETURN: None
84 * DESCRIPTION: Dump an AML "ByteList" in Hex format. 8 bytes per line, prefixed
85 * with the hex buffer offset.
87 ******************************************************************************/
89 void
90 AcpiDmDisasmByteList (
91 UINT32 Level,
92 UINT8 *ByteData,
93 UINT32 ByteCount)
95 UINT32 i;
98 if (!ByteCount)
100 return;
103 /* Dump the byte list */
105 for (i = 0; i < ByteCount; i++)
107 /* New line every 8 bytes */
109 if (((i % 8) == 0) && (i < ByteCount))
111 if (i > 0)
113 AcpiOsPrintf ("\n");
116 AcpiDmIndent (Level);
117 if (ByteCount > 8)
119 AcpiOsPrintf ("/* %04X */ ", i);
123 AcpiOsPrintf (" 0x%2.2X", (UINT32) ByteData[i]);
125 /* Add comma if there are more bytes to display */
127 if (i < (ByteCount -1))
129 AcpiOsPrintf (",");
133 if (Level)
135 AcpiOsPrintf ("\n");
140 /*******************************************************************************
142 * FUNCTION: AcpiDmByteList
144 * PARAMETERS: Info - Parse tree walk info
145 * Op - Byte list op
147 * RETURN: None
149 * DESCRIPTION: Dump a buffer byte list, handling the various types of buffers.
150 * Buffer type must be already set in the Op DisasmOpcode.
152 ******************************************************************************/
154 void
155 AcpiDmByteList (
156 ACPI_OP_WALK_INFO *Info,
157 ACPI_PARSE_OBJECT *Op)
159 UINT8 *ByteData;
160 UINT32 ByteCount;
163 ByteData = Op->Named.Data;
164 ByteCount = (UINT32) Op->Common.Value.Integer;
167 * The byte list belongs to a buffer, and can be produced by either
168 * a ResourceTemplate, Unicode, quoted string, or a plain byte list.
170 switch (Op->Common.Parent->Common.DisasmOpcode)
172 case ACPI_DASM_RESOURCE:
174 AcpiDmResourceTemplate (Info, Op->Common.Parent, ByteData, ByteCount);
175 break;
177 case ACPI_DASM_STRING:
179 AcpiDmIndent (Info->Level);
180 AcpiUtPrintString ((char *) ByteData, ACPI_UINT16_MAX);
181 AcpiOsPrintf ("\n");
182 break;
184 case ACPI_DASM_UNICODE:
186 AcpiDmUnicode (Op);
187 break;
189 case ACPI_DASM_PLD_METHOD:
191 AcpiDmDisasmByteList (Info->Level, ByteData, ByteCount);
192 AcpiDmPldBuffer (Info->Level, ByteData, ByteCount);
193 break;
195 case ACPI_DASM_BUFFER:
196 default:
198 * Not a resource, string, or unicode string.
199 * Just dump the buffer
201 AcpiDmDisasmByteList (Info->Level, ByteData, ByteCount);
202 break;
207 /*******************************************************************************
209 * FUNCTION: AcpiDmIsUnicodeBuffer
211 * PARAMETERS: Op - Buffer Object to be examined
213 * RETURN: TRUE if buffer contains a UNICODE string
215 * DESCRIPTION: Determine if a buffer Op contains a Unicode string
217 ******************************************************************************/
219 BOOLEAN
220 AcpiDmIsUnicodeBuffer (
221 ACPI_PARSE_OBJECT *Op)
223 UINT8 *ByteData;
224 UINT32 ByteCount;
225 UINT32 WordCount;
226 ACPI_PARSE_OBJECT *SizeOp;
227 ACPI_PARSE_OBJECT *NextOp;
228 UINT32 i;
231 /* Buffer size is the buffer argument */
233 SizeOp = Op->Common.Value.Arg;
235 /* Next, the initializer byte list to examine */
237 NextOp = SizeOp->Common.Next;
238 if (!NextOp)
240 return (FALSE);
243 /* Extract the byte list info */
245 ByteData = NextOp->Named.Data;
246 ByteCount = (UINT32) NextOp->Common.Value.Integer;
247 WordCount = ACPI_DIV_2 (ByteCount);
250 * Unicode string must have an even number of bytes and last
251 * word must be zero
253 if ((!ByteCount) ||
254 (ByteCount < 4) ||
255 (ByteCount & 1) ||
256 ((UINT16 *) (void *) ByteData)[WordCount - 1] != 0)
258 return (FALSE);
261 /* For each word, 1st byte must be ascii, 2nd byte must be zero */
263 for (i = 0; i < (ByteCount - 2); i += 2)
265 if ((!ACPI_IS_PRINT (ByteData[i])) ||
266 (ByteData[(ACPI_SIZE) i + 1] != 0))
268 return (FALSE);
272 /* Ignore the Size argument in the disassembly of this buffer op */
274 SizeOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
275 return (TRUE);
279 /*******************************************************************************
281 * FUNCTION: AcpiDmIsStringBuffer
283 * PARAMETERS: Op - Buffer Object to be examined
285 * RETURN: TRUE if buffer contains a ASCII string, FALSE otherwise
287 * DESCRIPTION: Determine if a buffer Op contains a ASCII string
289 ******************************************************************************/
291 BOOLEAN
292 AcpiDmIsStringBuffer (
293 ACPI_PARSE_OBJECT *Op)
295 UINT8 *ByteData;
296 UINT32 ByteCount;
297 ACPI_PARSE_OBJECT *SizeOp;
298 ACPI_PARSE_OBJECT *NextOp;
299 UINT32 i;
302 /* Buffer size is the buffer argument */
304 SizeOp = Op->Common.Value.Arg;
306 /* Next, the initializer byte list to examine */
308 NextOp = SizeOp->Common.Next;
309 if (!NextOp)
311 return (FALSE);
314 /* Extract the byte list info */
316 ByteData = NextOp->Named.Data;
317 ByteCount = (UINT32) NextOp->Common.Value.Integer;
319 /* Last byte must be the null terminator */
321 if ((!ByteCount) ||
322 (ByteCount < 2) ||
323 (ByteData[ByteCount-1] != 0))
325 return (FALSE);
328 for (i = 0; i < (ByteCount - 1); i++)
330 /* TBD: allow some escapes (non-ascii chars).
331 * they will be handled in the string output routine
334 if (!ACPI_IS_PRINT (ByteData[i]))
336 return (FALSE);
340 return (TRUE);
344 /*******************************************************************************
346 * FUNCTION: AcpiDmIsPldBuffer
348 * PARAMETERS: Op - Buffer Object to be examined
350 * RETURN: TRUE if buffer contains a ASCII string, FALSE otherwise
352 * DESCRIPTION: Determine if a buffer Op contains a _PLD structure
354 ******************************************************************************/
356 BOOLEAN
357 AcpiDmIsPldBuffer (
358 ACPI_PARSE_OBJECT *Op)
360 ACPI_NAMESPACE_NODE *Node;
361 ACPI_PARSE_OBJECT *ParentOp;
364 ParentOp = Op->Common.Parent;
365 if (!ParentOp)
367 return (FALSE);
370 /* Check for form: Name(_PLD, Buffer() {}). Not legal, however */
372 if (ParentOp->Common.AmlOpcode == AML_NAME_OP)
374 Node = ParentOp->Common.Node;
376 if (ACPI_COMPARE_NAME (Node->Name.Ascii, METHOD_NAME__PLD))
378 return (TRUE);
381 return (FALSE);
384 /* Check for proper form: Name(_PLD, Package() {Buffer() {}}) */
386 if (ParentOp->Common.AmlOpcode == AML_PACKAGE_OP)
388 ParentOp = ParentOp->Common.Parent;
389 if (!ParentOp)
391 return (FALSE);
394 if (ParentOp->Common.AmlOpcode == AML_NAME_OP)
396 Node = ParentOp->Common.Node;
398 if (ACPI_COMPARE_NAME (Node->Name.Ascii, METHOD_NAME__PLD))
400 return (TRUE);
405 return (FALSE);
409 /*******************************************************************************
411 * FUNCTION: AcpiDmPldBuffer
413 * PARAMETERS: Level - Current source code indentation level
414 * ByteData - Pointer to the byte list
415 * ByteCount - Length of the byte list
417 * RETURN: None
419 * DESCRIPTION: Dump and format the contents of a _PLD buffer object
421 ******************************************************************************/
423 #define ACPI_PLD_OUTPUT08 "%*.s/* %18s : %-6.2X */\n", ACPI_MUL_4 (Level), " "
424 #define ACPI_PLD_OUTPUT16 "%*.s/* %18s : %-6.4X */\n", ACPI_MUL_4 (Level), " "
425 #define ACPI_PLD_OUTPUT24 "%*.s/* %18s : %-6.6X */\n", ACPI_MUL_4 (Level), " "
427 static void
428 AcpiDmPldBuffer (
429 UINT32 Level,
430 UINT8 *ByteData,
431 UINT32 ByteCount)
433 ACPI_PLD_INFO *PldInfo;
434 ACPI_STATUS Status;
437 /* Check for valid byte count */
439 if (ByteCount < ACPI_PLD_REV1_BUFFER_SIZE)
441 return;
444 /* Convert _PLD buffer to local _PLD struct */
446 Status = AcpiDecodePldBuffer (ByteData, ByteCount, &PldInfo);
447 if (ACPI_FAILURE (Status))
449 return;
452 /* First 32-bit dword */
454 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "Revision", PldInfo->Revision);
455 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "IgnoreColor", PldInfo->IgnoreColor);
456 AcpiOsPrintf (ACPI_PLD_OUTPUT24,"Color", PldInfo->Color);
458 /* Second 32-bit dword */
460 AcpiOsPrintf (ACPI_PLD_OUTPUT16,"Width", PldInfo->Width);
461 AcpiOsPrintf (ACPI_PLD_OUTPUT16,"Height", PldInfo->Height);
463 /* Third 32-bit dword */
465 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "UserVisible", PldInfo->UserVisible);
466 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "Dock", PldInfo->Dock);
467 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "Lid", PldInfo->Lid);
468 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "Panel", PldInfo->Panel);
469 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "VerticalPosition", PldInfo->VerticalPosition);
470 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "HorizontalPosition", PldInfo->HorizontalPosition);
471 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "Shape", PldInfo->Shape);
472 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "GroupOrientation", PldInfo->GroupOrientation);
473 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "GroupToken", PldInfo->GroupToken);
474 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "GroupPosition", PldInfo->GroupPosition);
475 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "Bay", PldInfo->Bay);
477 /* Fourth 32-bit dword */
479 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "Ejectable", PldInfo->Ejectable);
480 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "OspmEjectRequired", PldInfo->OspmEjectRequired);
481 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "CabinetNumber", PldInfo->CabinetNumber);
482 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "CardCageNumber", PldInfo->CardCageNumber);
483 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "Reference", PldInfo->Reference);
484 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "Rotation", PldInfo->Rotation);
485 AcpiOsPrintf (ACPI_PLD_OUTPUT08, "Order", PldInfo->Order);
487 /* Fifth 32-bit dword */
489 if (ByteCount >= ACPI_PLD_REV1_BUFFER_SIZE)
491 AcpiOsPrintf (ACPI_PLD_OUTPUT16,"VerticalOffset", PldInfo->VerticalOffset);
492 AcpiOsPrintf (ACPI_PLD_OUTPUT16,"HorizontalOffset", PldInfo->HorizontalOffset);
495 ACPI_FREE (PldInfo);
499 /*******************************************************************************
501 * FUNCTION: AcpiDmUnicode
503 * PARAMETERS: Op - Byte List op containing Unicode string
505 * RETURN: None
507 * DESCRIPTION: Dump Unicode string as a standard ASCII string. (Remove
508 * the extra zero bytes).
510 ******************************************************************************/
512 static void
513 AcpiDmUnicode (
514 ACPI_PARSE_OBJECT *Op)
516 UINT16 *WordData;
517 UINT32 WordCount;
518 UINT32 i;
521 /* Extract the buffer info as a WORD buffer */
523 WordData = ACPI_CAST_PTR (UINT16, Op->Named.Data);
524 WordCount = ACPI_DIV_2 (((UINT32) Op->Common.Value.Integer));
526 /* Write every other byte as an ASCII character */
528 AcpiOsPrintf ("\"");
529 for (i = 0; i < (WordCount - 1); i++)
531 AcpiOsPrintf ("%c", (int) WordData[i]);
534 AcpiOsPrintf ("\")");
538 /*******************************************************************************
540 * FUNCTION: AcpiDmIsEisaIdElement
542 * PARAMETERS: Op - Op to be examined
544 * RETURN: None
546 * DESCRIPTION: Determine if an Op (argument to _HID or _CID) can be converted
547 * to an EISA ID.
549 ******************************************************************************/
551 static void
552 AcpiDmIsEisaIdElement (
553 ACPI_PARSE_OBJECT *Op)
555 UINT32 BigEndianId;
556 UINT32 Prefix[3];
557 UINT32 i;
560 /* The parameter must be either a word or a dword */
562 if ((Op->Common.AmlOpcode != AML_DWORD_OP) &&
563 (Op->Common.AmlOpcode != AML_WORD_OP))
565 return;
568 /* Swap from little-endian to big-endian to simplify conversion */
570 BigEndianId = AcpiUtDwordByteSwap ((UINT32) Op->Common.Value.Integer);
572 /* Create the 3 leading ASCII letters */
574 Prefix[0] = ((BigEndianId >> 26) & 0x1F) + 0x40;
575 Prefix[1] = ((BigEndianId >> 21) & 0x1F) + 0x40;
576 Prefix[2] = ((BigEndianId >> 16) & 0x1F) + 0x40;
578 /* Verify that all 3 are ascii and alpha */
580 for (i = 0; i < 3; i++)
582 if (!ACPI_IS_ASCII (Prefix[i]) ||
583 !ACPI_IS_ALPHA (Prefix[i]))
585 return;
589 /* OK - mark this node as convertable to an EISA ID */
591 Op->Common.DisasmOpcode = ACPI_DASM_EISAID;
595 /*******************************************************************************
597 * FUNCTION: AcpiDmIsEisaId
599 * PARAMETERS: Op - Op to be examined
601 * RETURN: None
603 * DESCRIPTION: Determine if a Name() Op can be converted to an EisaId.
605 ******************************************************************************/
607 void
608 AcpiDmIsEisaId (
609 ACPI_PARSE_OBJECT *Op)
611 UINT32 Name;
612 ACPI_PARSE_OBJECT *NextOp;
615 /* Get the NameSegment */
617 Name = AcpiPsGetName (Op);
618 if (!Name)
620 return;
623 NextOp = AcpiPsGetDepthNext (NULL, Op);
624 if (!NextOp)
626 return;
629 /* Check for _HID - has one argument */
631 if (ACPI_COMPARE_NAME (&Name, METHOD_NAME__HID))
633 AcpiDmIsEisaIdElement (NextOp);
634 return;
637 /* Exit if not _CID */
639 if (!ACPI_COMPARE_NAME (&Name, METHOD_NAME__CID))
641 return;
644 /* _CID can contain a single argument or a package */
646 if (NextOp->Common.AmlOpcode != AML_PACKAGE_OP)
648 AcpiDmIsEisaIdElement (NextOp);
649 return;
652 /* _CID with Package: get the package length */
654 NextOp = AcpiPsGetDepthNext (NULL, NextOp);
656 /* Don't need to use the length, just walk the peer list */
658 NextOp = NextOp->Common.Next;
659 while (NextOp)
661 AcpiDmIsEisaIdElement (NextOp);
662 NextOp = NextOp->Common.Next;
667 /*******************************************************************************
669 * FUNCTION: AcpiDmEisaId
671 * PARAMETERS: EncodedId - Raw encoded EISA ID.
673 * RETURN: None
675 * DESCRIPTION: Convert an encoded EISAID back to the original ASCII String.
677 ******************************************************************************/
679 void
680 AcpiDmEisaId (
681 UINT32 EncodedId)
683 UINT32 BigEndianId;
686 /* Swap from little-endian to big-endian to simplify conversion */
688 BigEndianId = AcpiUtDwordByteSwap (EncodedId);
691 /* Split to form "AAANNNN" string */
693 AcpiOsPrintf ("EisaId (\"%c%c%c%4.4X\")",
695 /* Three Alpha characters (AAA), 5 bits each */
697 (int) ((BigEndianId >> 26) & 0x1F) + 0x40,
698 (int) ((BigEndianId >> 21) & 0x1F) + 0x40,
699 (int) ((BigEndianId >> 16) & 0x1F) + 0x40,
701 /* Numeric part (NNNN) is simply the lower 16 bits */
703 (UINT32) (BigEndianId & 0xFFFF));
706 #endif