1 /*******************************************************************************
3 * Module Name: dmresrc.c - Resource Descriptor disassembly
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2011, 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.
45 #include <contrib/dev/acpica/include/acpi.h>
46 #include <contrib/dev/acpica/include/accommon.h>
47 #include <contrib/dev/acpica/include/amlcode.h>
48 #include <contrib/dev/acpica/include/acdisasm.h>
50 #ifdef ACPI_DISASSEMBLER
52 #define _COMPONENT ACPI_CA_DEBUGGER
53 ACPI_MODULE_NAME ("dbresrc")
56 /* Dispatch tables for Resource disassembly functions */
59 void (*ACPI_RESOURCE_HANDLER) (
60 AML_RESOURCE *Resource,
64 static ACPI_RESOURCE_HANDLER AcpiGbl_DmResourceDispatch [] =
66 /* Small descriptors */
68 NULL, /* 0x00, Reserved */
69 NULL, /* 0x01, Reserved */
70 NULL, /* 0x02, Reserved */
71 NULL, /* 0x03, Reserved */
72 AcpiDmIrqDescriptor, /* 0x04, ACPI_RESOURCE_NAME_IRQ_FORMAT */
73 AcpiDmDmaDescriptor, /* 0x05, ACPI_RESOURCE_NAME_DMA_FORMAT */
74 AcpiDmStartDependentDescriptor, /* 0x06, ACPI_RESOURCE_NAME_START_DEPENDENT */
75 AcpiDmEndDependentDescriptor, /* 0x07, ACPI_RESOURCE_NAME_END_DEPENDENT */
76 AcpiDmIoDescriptor, /* 0x08, ACPI_RESOURCE_NAME_IO_PORT */
77 AcpiDmFixedIoDescriptor, /* 0x09, ACPI_RESOURCE_NAME_FIXED_IO_PORT */
78 NULL, /* 0x0A, Reserved */
79 NULL, /* 0x0B, Reserved */
80 NULL, /* 0x0C, Reserved */
81 NULL, /* 0x0D, Reserved */
82 AcpiDmVendorSmallDescriptor, /* 0x0E, ACPI_RESOURCE_NAME_SMALL_VENDOR */
83 NULL, /* 0x0F, ACPI_RESOURCE_NAME_END_TAG (not used) */
85 /* Large descriptors */
87 NULL, /* 0x00, Reserved */
88 AcpiDmMemory24Descriptor, /* 0x01, ACPI_RESOURCE_NAME_MEMORY_24 */
89 AcpiDmGenericRegisterDescriptor,/* 0x02, ACPI_RESOURCE_NAME_GENERIC_REGISTER */
90 NULL, /* 0x03, Reserved */
91 AcpiDmVendorLargeDescriptor, /* 0x04, ACPI_RESOURCE_NAME_LARGE_VENDOR */
92 AcpiDmMemory32Descriptor, /* 0x05, ACPI_RESOURCE_NAME_MEMORY_32 */
93 AcpiDmFixedMemory32Descriptor, /* 0x06, ACPI_RESOURCE_NAME_FIXED_MEMORY_32 */
94 AcpiDmDwordDescriptor, /* 0x07, ACPI_RESOURCE_NAME_DWORD_ADDRESS_SPACE */
95 AcpiDmWordDescriptor, /* 0x08, ACPI_RESOURCE_NAME_WORD_ADDRESS_SPACE */
96 AcpiDmInterruptDescriptor, /* 0x09, ACPI_RESOURCE_NAME_EXTENDED_XRUPT */
97 AcpiDmQwordDescriptor, /* 0x0A, ACPI_RESOURCE_NAME_QWORD_ADDRESS_SPACE */
98 AcpiDmExtendedDescriptor /* 0x0B, ACPI_RESOURCE_NAME_EXTENDED_ADDRESS_SPACE */
102 /* Only used for single-threaded applications */
103 /* TBD: remove when name is passed as parameter to the dump functions */
105 static UINT32 ResourceName;
108 /*******************************************************************************
110 * FUNCTION: AcpiDmDescriptorName
116 * DESCRIPTION: Emit a name for the descriptor if one is present (indicated
117 * by the name being changed from the default name.) A name is only
118 * emitted if a reference to the descriptor has been made somewhere
119 * in the original ASL code.
121 ******************************************************************************/
124 AcpiDmDescriptorName (
128 if (ResourceName == ACPI_DEFAULT_RESNAME)
133 AcpiOsPrintf ("%4.4s", (char *) &ResourceName);
137 /*******************************************************************************
139 * FUNCTION: AcpiDmDumpInteger*
141 * PARAMETERS: Value - Value to emit
142 * Name - Associated name (emitted as a comment)
146 * DESCRIPTION: Integer output helper functions
148 ******************************************************************************/
155 AcpiOsPrintf ("0x%2.2X, // %s\n", Value, Name);
159 AcpiDmDumpInteger16 (
163 AcpiOsPrintf ("0x%4.4X, // %s\n", Value, Name);
167 AcpiDmDumpInteger32 (
171 AcpiOsPrintf ("0x%8.8X, // %s\n", Value, Name);
175 AcpiDmDumpInteger64 (
179 AcpiOsPrintf ("0x%8.8X%8.8X, // %s\n", ACPI_FORMAT_UINT64 (Value), Name);
183 /*******************************************************************************
185 * FUNCTION: AcpiDmBitList
187 * PARAMETERS: Mask - 16-bit value corresponding to 16 interrupt
192 * DESCRIPTION: Dump a bit mask as a list of individual interrupt/DMA levels.
194 ******************************************************************************/
201 BOOLEAN Previous = FALSE;
204 /* Open the initializer list */
208 /* Examine each bit */
210 for (i = 0; i < 16; i++)
212 /* Only interested in bits that are set to 1 */
221 AcpiOsPrintf ("%u", i);
229 AcpiOsPrintf ("}\n");
233 /*******************************************************************************
235 * FUNCTION: AcpiDmResourceTemplate
237 * PARAMETERS: Info - Curent parse tree walk info
238 * ByteData - Pointer to the byte list data
239 * ByteCount - Length of the byte list
243 * DESCRIPTION: Dump the contents of a Resource Template containing a set of
244 * Resource Descriptors.
246 ******************************************************************************/
249 AcpiDmResourceTemplate (
250 ACPI_OP_WALK_INFO *Info,
251 ACPI_PARSE_OBJECT *Op,
256 UINT32 CurrentByteOffset;
258 UINT32 ResourceLength;
261 BOOLEAN DependentFns = FALSE;
263 ACPI_NAMESPACE_NODE *Node;
267 ResourceName = ACPI_DEFAULT_RESNAME;
268 Node = Op->Common.Node;
274 for (CurrentByteOffset = 0; CurrentByteOffset < ByteCount;)
276 Aml = &ByteData[CurrentByteOffset];
278 /* Get the descriptor type and length */
280 ResourceType = AcpiUtGetResourceType (Aml);
281 ResourceLength = AcpiUtGetResourceLength (Aml);
283 /* Validate the Resource Type and Resource Length */
285 Status = AcpiUtValidateResource (Aml, &ResourceIndex);
286 if (ACPI_FAILURE (Status))
288 AcpiOsPrintf ("/*** Could not validate Resource, type (%X) %s***/\n",
289 ResourceType, AcpiFormatException (Status));
293 /* Point to next descriptor */
295 CurrentByteOffset += AcpiUtGetDescriptorLength (Aml);
297 /* Descriptor pre-processing */
299 switch (ResourceType)
301 case ACPI_RESOURCE_NAME_START_DEPENDENT:
303 /* Finish a previous StartDependentFns */
308 AcpiDmIndent (Level);
309 AcpiOsPrintf ("}\n");
313 case ACPI_RESOURCE_NAME_END_DEPENDENT:
316 DependentFns = FALSE;
319 case ACPI_RESOURCE_NAME_END_TAG:
321 /* Normal exit, the resource list is finished */
326 * Close an open StartDependentDescriptor. This indicates a
327 * missing EndDependentDescriptor.
330 DependentFns = FALSE;
332 /* Go ahead and insert EndDependentFn() */
334 AcpiDmEndDependentDescriptor (Aml, ResourceLength, Level);
336 AcpiDmIndent (Level);
338 "/*** Disassembler: inserted missing EndDependentFn () ***/\n");
346 /* Disassemble the resource structure */
350 ResourceName = Node->Name.Integer;
354 AcpiGbl_DmResourceDispatch [ResourceIndex] (
355 Aml, ResourceLength, Level);
357 /* Descriptor post-processing */
359 if (ResourceType == ACPI_RESOURCE_NAME_START_DEPENDENT)
368 /*******************************************************************************
370 * FUNCTION: AcpiDmIsResourceTemplate
372 * PARAMETERS: Op - Buffer Op to be examined
374 * RETURN: Status. AE_OK if valid template
376 * DESCRIPTION: Walk a byte list to determine if it consists of a valid set
377 * of resource descriptors. Nothing is output.
379 ******************************************************************************/
382 AcpiDmIsResourceTemplate (
383 ACPI_PARSE_OBJECT *Op)
386 ACPI_PARSE_OBJECT *NextOp;
392 /* This op must be a buffer */
394 if (Op->Common.AmlOpcode != AML_BUFFER_OP)
399 /* Get the ByteData list and length */
401 NextOp = Op->Common.Value.Arg;
402 NextOp = NextOp->Common.Next;
408 Aml = NextOp->Named.Data;
409 Length = (ACPI_SIZE) NextOp->Common.Value.Integer;
411 /* Walk the byte list, abort on any invalid descriptor type or length */
413 Status = AcpiUtWalkAmlResources (Aml, Length, NULL, &EndAml);
414 if (ACPI_FAILURE (Status))
420 * For the resource template to be valid, one EndTag must appear
421 * at the very end of the ByteList, not before. (For proper disassembly
422 * of a ResourceTemplate, the buffer must not have any extra data after
425 if ((Aml + Length - sizeof (AML_RESOURCE_END_TAG)) != EndAml)
427 return (AE_AML_NO_RESOURCE_END_TAG);
431 * All resource descriptors are valid, therefore this list appears
432 * to be a valid resource template