1 /*******************************************************************************
3 * Module Name: dmresrc.c - Resource Descriptor disassembly
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2016, 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.
50 #define _COMPONENT ACPI_CA_DEBUGGER
51 ACPI_MODULE_NAME ("dbresrc")
54 /* Dispatch tables for Resource disassembly functions */
56 static ACPI_RESOURCE_HANDLER AcpiGbl_DmResourceDispatch [] =
58 /* Small descriptors */
60 NULL, /* 0x00, Reserved */
61 NULL, /* 0x01, Reserved */
62 NULL, /* 0x02, Reserved */
63 NULL, /* 0x03, Reserved */
64 AcpiDmIrqDescriptor, /* 0x04, ACPI_RESOURCE_NAME_IRQ_FORMAT */
65 AcpiDmDmaDescriptor, /* 0x05, ACPI_RESOURCE_NAME_DMA_FORMAT */
66 AcpiDmStartDependentDescriptor, /* 0x06, ACPI_RESOURCE_NAME_START_DEPENDENT */
67 AcpiDmEndDependentDescriptor, /* 0x07, ACPI_RESOURCE_NAME_END_DEPENDENT */
68 AcpiDmIoDescriptor, /* 0x08, ACPI_RESOURCE_NAME_IO_PORT */
69 AcpiDmFixedIoDescriptor, /* 0x09, ACPI_RESOURCE_NAME_FIXED_IO_PORT */
70 AcpiDmFixedDmaDescriptor, /* 0x0A, ACPI_RESOURCE_NAME_FIXED_DMA */
71 NULL, /* 0x0B, Reserved */
72 NULL, /* 0x0C, Reserved */
73 NULL, /* 0x0D, Reserved */
74 AcpiDmVendorSmallDescriptor, /* 0x0E, ACPI_RESOURCE_NAME_SMALL_VENDOR */
75 NULL, /* 0x0F, ACPI_RESOURCE_NAME_END_TAG (not used) */
77 /* Large descriptors */
79 NULL, /* 0x00, Reserved */
80 AcpiDmMemory24Descriptor, /* 0x01, ACPI_RESOURCE_NAME_MEMORY_24 */
81 AcpiDmGenericRegisterDescriptor,/* 0x02, ACPI_RESOURCE_NAME_GENERIC_REGISTER */
82 NULL, /* 0x03, Reserved */
83 AcpiDmVendorLargeDescriptor, /* 0x04, ACPI_RESOURCE_NAME_LARGE_VENDOR */
84 AcpiDmMemory32Descriptor, /* 0x05, ACPI_RESOURCE_NAME_MEMORY_32 */
85 AcpiDmFixedMemory32Descriptor, /* 0x06, ACPI_RESOURCE_NAME_FIXED_MEMORY_32 */
86 AcpiDmDwordDescriptor, /* 0x07, ACPI_RESOURCE_NAME_DWORD_ADDRESS_SPACE */
87 AcpiDmWordDescriptor, /* 0x08, ACPI_RESOURCE_NAME_WORD_ADDRESS_SPACE */
88 AcpiDmInterruptDescriptor, /* 0x09, ACPI_RESOURCE_NAME_EXTENDED_XRUPT */
89 AcpiDmQwordDescriptor, /* 0x0A, ACPI_RESOURCE_NAME_QWORD_ADDRESS_SPACE */
90 AcpiDmExtendedDescriptor, /* 0x0B, ACPI_RESOURCE_NAME_EXTENDED_ADDRESS_SPACE */
91 AcpiDmGpioDescriptor, /* 0x0C, ACPI_RESOURCE_NAME_GPIO */
92 NULL, /* 0x0D, Reserved */
93 AcpiDmSerialBusDescriptor /* 0x0E, ACPI_RESOURCE_NAME_SERIAL_BUS */
97 /* Only used for single-threaded applications */
98 /* TBD: remove when name is passed as parameter to the dump functions */
100 static UINT32 ResourceName;
103 /*******************************************************************************
105 * FUNCTION: AcpiDmDescriptorName
111 * DESCRIPTION: Emit a name for the descriptor if one is present (indicated
112 * by the name being changed from the default name.) A name is only
113 * emitted if a reference to the descriptor has been made somewhere
114 * in the original ASL code.
116 ******************************************************************************/
119 AcpiDmDescriptorName (
123 if (ResourceName == ACPI_DEFAULT_RESNAME)
128 AcpiOsPrintf ("%4.4s", (char *) &ResourceName);
132 /*******************************************************************************
134 * FUNCTION: AcpiDmDumpInteger*
136 * PARAMETERS: Value - Value to emit
137 * Name - Associated name (emitted as a comment)
141 * DESCRIPTION: Integer output helper functions
143 ******************************************************************************/
150 AcpiOsPrintf ("0x%2.2X, // %s\n", Value, Name);
154 AcpiDmDumpInteger16 (
158 AcpiOsPrintf ("0x%4.4X, // %s\n", Value, Name);
162 AcpiDmDumpInteger32 (
166 AcpiOsPrintf ("0x%8.8X, // %s\n", Value, Name);
170 AcpiDmDumpInteger64 (
174 AcpiOsPrintf ("0x%8.8X%8.8X, // %s\n", ACPI_FORMAT_UINT64 (Value), Name);
178 /*******************************************************************************
180 * FUNCTION: AcpiDmBitList
182 * PARAMETERS: Mask - 16-bit value corresponding to 16 interrupt
187 * DESCRIPTION: Dump a bit mask as a list of individual interrupt/DMA levels.
189 ******************************************************************************/
196 BOOLEAN Previous = FALSE;
199 /* Open the initializer list */
203 /* Examine each bit */
205 for (i = 0; i < 16; i++)
207 /* Only interested in bits that are set to 1 */
217 AcpiOsPrintf ("%u", i);
225 AcpiOsPrintf ("}\n");
229 /*******************************************************************************
231 * FUNCTION: AcpiDmResourceTemplate
233 * PARAMETERS: Info - Curent parse tree walk info
234 * ByteData - Pointer to the byte list data
235 * ByteCount - Length of the byte list
239 * DESCRIPTION: Dump the contents of a Resource Template containing a set of
240 * Resource Descriptors.
242 ******************************************************************************/
245 AcpiDmResourceTemplate (
246 ACPI_OP_WALK_INFO *Info,
247 ACPI_PARSE_OBJECT *Op,
252 UINT32 CurrentByteOffset;
254 UINT32 ResourceLength;
257 BOOLEAN DependentFns = FALSE;
259 ACPI_NAMESPACE_NODE *Node;
262 if (Op->Asl.AmlOpcode != AML_FIELD_OP)
264 Info->MappingOp = Op;
268 ResourceName = ACPI_DEFAULT_RESNAME;
269 Node = Op->Common.Node;
275 for (CurrentByteOffset = 0; CurrentByteOffset < ByteCount;)
277 Aml = &ByteData[CurrentByteOffset];
279 /* Get the descriptor type and length */
281 ResourceType = AcpiUtGetResourceType (Aml);
282 ResourceLength = AcpiUtGetResourceLength (Aml);
284 /* Validate the Resource Type and Resource Length */
286 Status = AcpiUtValidateResource (NULL, Aml, &ResourceIndex);
287 if (ACPI_FAILURE (Status))
290 "/*** Could not validate Resource, type (%X) %s***/\n",
291 ResourceType, AcpiFormatException (Status));
295 /* Point to next descriptor */
297 CurrentByteOffset += AcpiUtGetDescriptorLength (Aml);
299 /* Descriptor pre-processing */
301 switch (ResourceType)
303 case ACPI_RESOURCE_NAME_START_DEPENDENT:
305 /* Finish a previous StartDependentFns */
310 AcpiDmIndent (Level);
311 AcpiOsPrintf ("}\n");
315 case ACPI_RESOURCE_NAME_END_DEPENDENT:
318 DependentFns = FALSE;
321 case ACPI_RESOURCE_NAME_END_TAG:
323 /* Normal exit, the resource list is finished */
328 * Close an open StartDependentDescriptor. This indicates a
329 * missing EndDependentDescriptor.
332 DependentFns = FALSE;
334 /* Go ahead and insert EndDependentFn() */
336 AcpiDmEndDependentDescriptor (Info, Aml, ResourceLength, Level);
338 AcpiDmIndent (Level);
340 "/*** Disassembler: inserted "
341 "missing EndDependentFn () ***/\n");
350 /* Disassemble the resource structure */
354 ResourceName = Node->Name.Integer;
358 AcpiGbl_DmResourceDispatch [ResourceIndex] (
359 Info, Aml, ResourceLength, Level);
361 /* Descriptor post-processing */
363 if (ResourceType == ACPI_RESOURCE_NAME_START_DEPENDENT)
372 /*******************************************************************************
374 * FUNCTION: AcpiDmIsResourceTemplate
376 * PARAMETERS: WalkState - Current walk info
377 * Op - Buffer Op to be examined
379 * RETURN: Status. AE_OK if valid template
381 * DESCRIPTION: Walk a byte list to determine if it consists of a valid set
382 * of resource descriptors. Nothing is output.
384 ******************************************************************************/
387 AcpiDmIsResourceTemplate (
388 ACPI_WALK_STATE *WalkState,
389 ACPI_PARSE_OBJECT *Op)
392 ACPI_PARSE_OBJECT *NextOp;
396 UINT32 DeclaredBufferLength;
399 /* This op must be a buffer */
401 if (Op->Common.AmlOpcode != AML_BUFFER_OP)
407 * Get the declared length of the buffer.
408 * This is the nn in "Buffer (nn)"
410 NextOp = Op->Common.Value.Arg;
413 AcpiOsPrintf ("NULL byte list in buffer\n");
417 DeclaredBufferLength = NextOp->Common.Value.Size;
419 /* Get the length of the raw initialization byte list */
421 NextOp = NextOp->Common.Next;
427 Aml = NextOp->Named.Data;
428 BufferLength = NextOp->Common.Value.Size;
431 * Not a template if declared buffer length != actual length of the
432 * intialization byte list. Because the resource macros will create
433 * a buffer of the exact required length (buffer length will be equal
434 * to the actual length).
436 if (DeclaredBufferLength != BufferLength)
441 /* Walk the byte list, abort on any invalid descriptor type or length */
443 Status = AcpiUtWalkAmlResources (WalkState, Aml, BufferLength,
444 NULL, ACPI_CAST_INDIRECT_PTR (void, &EndAml));
445 if (ACPI_FAILURE (Status))
451 * For the resource template to be valid, one EndTag must appear
452 * at the very end of the ByteList, not before. (For proper disassembly
453 * of a ResourceTemplate, the buffer must not have any extra data after
456 if ((Aml + BufferLength - sizeof (AML_RESOURCE_END_TAG)) != EndAml)
458 return (AE_AML_NO_RESOURCE_END_TAG);
462 * All resource descriptors are valid, therefore this list appears
463 * to be a valid resource template