1 /******************************************************************************
3 * Module Name: dmrestag - Add tags to resource descriptors (Application-level)
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2012, 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/acparser.h>
48 #include <contrib/dev/acpica/include/acdisasm.h>
49 #include <contrib/dev/acpica/include/acnamesp.h>
50 #include <contrib/dev/acpica/include/amlcode.h>
52 /* This module used for application-level code only */
54 #define _COMPONENT ACPI_CA_DISASSEMBLER
55 ACPI_MODULE_NAME ("dmrestag")
57 /* Local prototypes */
60 AcpiDmUpdateResourceName (
61 ACPI_NAMESPACE_NODE *ResourceNode);
66 const ACPI_RESOURCE_TAG *TagList);
69 AcpiDmGetResourceTag (
71 AML_RESOURCE *Resource,
76 ACPI_PARSE_OBJECT *Op,
77 ACPI_NAMESPACE_NODE *BufferNode,
78 ACPI_NAMESPACE_NODE *ResourceNode,
81 static ACPI_NAMESPACE_NODE *
82 AcpiDmGetResourceNode (
83 ACPI_NAMESPACE_NODE *BufferNode,
87 AcpiDmAddResourceToNamespace (
95 AcpiDmAddResourcesToNamespace (
96 ACPI_NAMESPACE_NODE *BufferNode,
97 ACPI_PARSE_OBJECT *Op);
100 /******************************************************************************
102 * Resource Tag tables
104 * These are the predefined tags that refer to elements of a resource
105 * descriptor. Each name and offset is defined in the ACPI specification.
107 * Each table entry contains the bit offset of the field and the associated
110 ******************************************************************************/
112 static const ACPI_RESOURCE_TAG AcpiDmIrqTags[] =
114 {( 1 * 8), ACPI_RESTAG_INTERRUPT},
115 {( 3 * 8) + 0, ACPI_RESTAG_INTERRUPTTYPE},
116 {( 3 * 8) + 3, ACPI_RESTAG_INTERRUPTLEVEL},
117 {( 3 * 8) + 4, ACPI_RESTAG_INTERRUPTSHARE},
121 static const ACPI_RESOURCE_TAG AcpiDmDmaTags[] =
123 {( 1 * 8), ACPI_RESTAG_DMA},
124 {( 2 * 8) + 0, ACPI_RESTAG_XFERTYPE},
125 {( 2 * 8) + 2, ACPI_RESTAG_BUSMASTER},
126 {( 2 * 8) + 5, ACPI_RESTAG_DMATYPE},
130 static const ACPI_RESOURCE_TAG AcpiDmIoTags[] =
132 {( 1 * 8) + 0, ACPI_RESTAG_DECODE},
133 {( 2 * 8), ACPI_RESTAG_MINADDR},
134 {( 4 * 8), ACPI_RESTAG_MAXADDR},
135 {( 6 * 8), ACPI_RESTAG_ALIGNMENT},
136 {( 7 * 8), ACPI_RESTAG_LENGTH},
140 static const ACPI_RESOURCE_TAG AcpiDmFixedIoTags[] =
142 {( 1 * 8), ACPI_RESTAG_BASEADDRESS},
143 {( 3 * 8), ACPI_RESTAG_LENGTH},
147 static const ACPI_RESOURCE_TAG AcpiDmFixedDmaTags[] =
149 {( 1 * 8), ACPI_RESTAG_DMA},
150 {( 3 * 8), ACPI_RESTAG_DMATYPE},
151 {( 5 * 8), ACPI_RESTAG_XFERTYPE},
155 static const ACPI_RESOURCE_TAG AcpiDmMemory24Tags[] =
157 {( 3 * 8) + 0, ACPI_RESTAG_READWRITETYPE},
158 {( 4 * 8), ACPI_RESTAG_MINADDR},
159 {( 6 * 8), ACPI_RESTAG_MAXADDR},
160 {( 8 * 8), ACPI_RESTAG_ALIGNMENT},
161 {(10 * 8), ACPI_RESTAG_LENGTH},
165 static const ACPI_RESOURCE_TAG AcpiDmRegisterTags[] =
167 {( 3 * 8), ACPI_RESTAG_ADDRESSSPACE},
168 {( 4 * 8), ACPI_RESTAG_REGISTERBITWIDTH},
169 {( 5 * 8), ACPI_RESTAG_REGISTERBITOFFSET},
170 {( 6 * 8), ACPI_RESTAG_ACCESSSIZE},
171 {( 7 * 8), ACPI_RESTAG_ADDRESS},
175 static const ACPI_RESOURCE_TAG AcpiDmMemory32Tags[] =
177 {( 3 * 8) + 0, ACPI_RESTAG_READWRITETYPE},
178 {( 4 * 8), ACPI_RESTAG_MINADDR},
179 {( 8 * 8), ACPI_RESTAG_MAXADDR},
180 {(12 * 8), ACPI_RESTAG_ALIGNMENT},
181 {(16 * 8), ACPI_RESTAG_LENGTH},
185 static const ACPI_RESOURCE_TAG AcpiDmFixedMemory32Tags[] =
187 {( 3 * 8) + 0, ACPI_RESTAG_READWRITETYPE},
188 {( 4 * 8), ACPI_RESTAG_BASEADDRESS},
189 {( 8 * 8), ACPI_RESTAG_LENGTH},
193 static const ACPI_RESOURCE_TAG AcpiDmInterruptTags[] =
195 {( 3 * 8) + 1, ACPI_RESTAG_INTERRUPTTYPE},
196 {( 3 * 8) + 2, ACPI_RESTAG_INTERRUPTLEVEL},
197 {( 3 * 8) + 3, ACPI_RESTAG_INTERRUPTSHARE},
198 {( 5 * 8), ACPI_RESTAG_INTERRUPT},
202 static const ACPI_RESOURCE_TAG AcpiDmAddress16Tags[] =
204 {( 4 * 8) + 1, ACPI_RESTAG_DECODE},
205 {( 4 * 8) + 2, ACPI_RESTAG_MINTYPE},
206 {( 4 * 8) + 3, ACPI_RESTAG_MAXTYPE},
207 {( 6 * 8), ACPI_RESTAG_GRANULARITY},
208 {( 8 * 8), ACPI_RESTAG_MINADDR},
209 {(10 * 8), ACPI_RESTAG_MAXADDR},
210 {(12 * 8), ACPI_RESTAG_TRANSLATION},
211 {(14 * 8), ACPI_RESTAG_LENGTH},
215 static const ACPI_RESOURCE_TAG AcpiDmAddress32Tags[] =
217 {( 4 * 8) + 1, ACPI_RESTAG_DECODE},
218 {( 4 * 8) + 2, ACPI_RESTAG_MINTYPE},
219 {( 4 * 8) + 3, ACPI_RESTAG_MAXTYPE},
220 {( 6 * 8), ACPI_RESTAG_GRANULARITY},
221 {(10 * 8), ACPI_RESTAG_MINADDR},
222 {(14 * 8), ACPI_RESTAG_MAXADDR},
223 {(18 * 8), ACPI_RESTAG_TRANSLATION},
224 {(22 * 8), ACPI_RESTAG_LENGTH},
228 static const ACPI_RESOURCE_TAG AcpiDmAddress64Tags[] =
230 {( 4 * 8) + 1, ACPI_RESTAG_DECODE},
231 {( 4 * 8) + 2, ACPI_RESTAG_MINTYPE},
232 {( 4 * 8) + 3, ACPI_RESTAG_MAXTYPE},
233 {( 6 * 8), ACPI_RESTAG_GRANULARITY},
234 {(14 * 8), ACPI_RESTAG_MINADDR},
235 {(22 * 8), ACPI_RESTAG_MAXADDR},
236 {(30 * 8), ACPI_RESTAG_TRANSLATION},
237 {(38 * 8), ACPI_RESTAG_LENGTH},
241 static const ACPI_RESOURCE_TAG AcpiDmExtendedAddressTags[] =
243 {( 4 * 8) + 1, ACPI_RESTAG_DECODE},
244 {( 4 * 8) + 2, ACPI_RESTAG_MINTYPE},
245 {( 4 * 8) + 3, ACPI_RESTAG_MAXTYPE},
246 {( 8 * 8), ACPI_RESTAG_GRANULARITY},
247 {(16 * 8), ACPI_RESTAG_MINADDR},
248 {(24 * 8), ACPI_RESTAG_MAXADDR},
249 {(32 * 8), ACPI_RESTAG_TRANSLATION},
250 {(40 * 8), ACPI_RESTAG_LENGTH},
251 {(48 * 8), ACPI_RESTAG_TYPESPECIFICATTRIBUTES},
255 /* Subtype tables for GPIO descriptors */
257 static const ACPI_RESOURCE_TAG AcpiDmGpioIntTags[] =
259 {( 7 * 8) + 0, ACPI_RESTAG_MODE},
260 {( 7 * 8) + 1, ACPI_RESTAG_POLARITY},
261 {( 7 * 8) + 3, ACPI_RESTAG_INTERRUPTSHARE},
262 {( 9 * 8), ACPI_RESTAG_PINCONFIG},
263 {(10 * 8), ACPI_RESTAG_DRIVESTRENGTH},
264 {(12 * 8), ACPI_RESTAG_DEBOUNCETIME},
268 static const ACPI_RESOURCE_TAG AcpiDmGpioIoTags[] =
270 {( 7 * 8) + 0, ACPI_RESTAG_IORESTRICTION},
271 {( 7 * 8) + 3, ACPI_RESTAG_INTERRUPTSHARE},
272 {( 9 * 8), ACPI_RESTAG_PINCONFIG},
273 {(10 * 8), ACPI_RESTAG_DRIVESTRENGTH},
274 {(12 * 8), ACPI_RESTAG_DEBOUNCETIME},
278 /* Subtype tables for SerialBus descriptors */
280 static const ACPI_RESOURCE_TAG AcpiDmI2cSerialBusTags[] =
282 {( 6 * 8) + 0, ACPI_RESTAG_SLAVEMODE},
283 {( 7 * 8) + 0, ACPI_RESTAG_MODE},
284 {(12 * 8), ACPI_RESTAG_SPEED},
285 {(16 * 8), ACPI_RESTAG_ADDRESS},
289 static const ACPI_RESOURCE_TAG AcpiDmSpiSerialBusTags[] =
291 {( 6 * 8) + 0, ACPI_RESTAG_SLAVEMODE},
292 {( 7 * 8) + 0, ACPI_RESTAG_MODE},
293 {( 7 * 8) + 1, ACPI_RESTAG_DEVICEPOLARITY},
294 {(12 * 8), ACPI_RESTAG_SPEED},
295 {(16 * 8), ACPI_RESTAG_LENGTH},
296 {(17 * 8), ACPI_RESTAG_PHASE},
297 {(18 * 8), ACPI_RESTAG_POLARITY},
298 {(19 * 8), ACPI_RESTAG_ADDRESS},
302 static const ACPI_RESOURCE_TAG AcpiDmUartSerialBusTags[] =
304 {( 6 * 8) + 0, ACPI_RESTAG_SLAVEMODE}, /* Note: not part of original macro */
305 {( 7 * 8) + 0, ACPI_RESTAG_FLOWCONTROL},
306 {( 7 * 8) + 2, ACPI_RESTAG_STOPBITS},
307 {( 7 * 8) + 4, ACPI_RESTAG_LENGTH},
308 {( 7 * 8) + 7, ACPI_RESTAG_ENDIANNESS},
309 {(12 * 8), ACPI_RESTAG_SPEED},
310 {(16 * 8), ACPI_RESTAG_LENGTH_RX},
311 {(18 * 8), ACPI_RESTAG_LENGTH_TX},
312 {(20 * 8), ACPI_RESTAG_PARITY},
313 {(21 * 8), ACPI_RESTAG_LINE},
317 /* Subtype tables for Address descriptor type-specific flags */
319 static const ACPI_RESOURCE_TAG AcpiDmMemoryFlagTags[] =
321 {( 5 * 8) + 0, ACPI_RESTAG_READWRITETYPE},
322 {( 5 * 8) + 1, ACPI_RESTAG_MEMTYPE},
323 {( 5 * 8) + 3, ACPI_RESTAG_MEMATTRIBUTES},
324 {( 5 * 8) + 5, ACPI_RESTAG_TYPE},
328 static const ACPI_RESOURCE_TAG AcpiDmIoFlagTags[] =
330 {( 5 * 8) + 0, ACPI_RESTAG_RANGETYPE},
331 {( 5 * 8) + 4, ACPI_RESTAG_TYPE},
332 {( 5 * 8) + 5, ACPI_RESTAG_TRANSTYPE},
338 * Dispatch table used to obtain the correct tag table for a descriptor.
340 * A NULL in this table means one of three things:
341 * 1) The descriptor ID is reserved and invalid
342 * 2) The descriptor has no tags associated with it
343 * 3) The descriptor has subtypes and a separate table will be used.
345 static const ACPI_RESOURCE_TAG *AcpiGbl_ResourceTags[] =
347 /* Small descriptors */
349 NULL, /* 0x00, Reserved */
350 NULL, /* 0x01, Reserved */
351 NULL, /* 0x02, Reserved */
352 NULL, /* 0x03, Reserved */
353 AcpiDmIrqTags, /* 0x04, ACPI_RESOURCE_NAME_IRQ_FORMAT */
354 AcpiDmDmaTags, /* 0x05, ACPI_RESOURCE_NAME_DMA_FORMAT */
355 NULL, /* 0x06, ACPI_RESOURCE_NAME_START_DEPENDENT */
356 NULL, /* 0x07, ACPI_RESOURCE_NAME_END_DEPENDENT */
357 AcpiDmIoTags, /* 0x08, ACPI_RESOURCE_NAME_IO_PORT */
358 AcpiDmFixedIoTags, /* 0x09, ACPI_RESOURCE_NAME_FIXED_IO_PORT */
359 AcpiDmFixedDmaTags, /* 0x0A, ACPI_RESOURCE_NAME_FIXED_DMA */
360 NULL, /* 0x0B, Reserved */
361 NULL, /* 0x0C, Reserved */
362 NULL, /* 0x0D, Reserved */
363 NULL, /* 0x0E, ACPI_RESOURCE_NAME_SMALL_VENDOR */
364 NULL, /* 0x0F, ACPI_RESOURCE_NAME_END_TAG (not used) */
366 /* Large descriptors */
368 NULL, /* 0x00, Reserved */
369 AcpiDmMemory24Tags, /* 0x01, ACPI_RESOURCE_NAME_MEMORY_24 */
370 AcpiDmRegisterTags, /* 0x02, ACPI_RESOURCE_NAME_GENERIC_REGISTER */
371 NULL, /* 0x03, Reserved */
372 NULL, /* 0x04, ACPI_RESOURCE_NAME_LARGE_VENDOR */
373 AcpiDmMemory32Tags, /* 0x05, ACPI_RESOURCE_NAME_MEMORY_32 */
374 AcpiDmFixedMemory32Tags, /* 0x06, ACPI_RESOURCE_NAME_FIXED_MEMORY_32 */
375 AcpiDmAddress32Tags, /* 0x07, ACPI_RESOURCE_NAME_DWORD_ADDRESS_SPACE */
376 AcpiDmAddress16Tags, /* 0x08, ACPI_RESOURCE_NAME_WORD_ADDRESS_SPACE */
377 AcpiDmInterruptTags, /* 0x09, ACPI_RESOURCE_NAME_EXTENDED_XRUPT */
378 AcpiDmAddress64Tags, /* 0x0A, ACPI_RESOURCE_NAME_QWORD_ADDRESS_SPACE */
379 AcpiDmExtendedAddressTags, /* 0x0B, ACPI_RESOURCE_NAME_EXTENDED_ADDRESS_SPACE */
380 NULL, /* 0x0C, ACPI_RESOURCE_NAME_GPIO - Use Subtype table below */
381 NULL, /* 0x0D, Reserved */
382 NULL /* 0x0E, ACPI_RESOURCE_NAME_SERIAL_BUS - Use Subtype table below */
387 static const ACPI_RESOURCE_TAG *AcpiGbl_GpioResourceTags[] =
389 AcpiDmGpioIntTags, /* 0x00 Interrupt Connection */
390 AcpiDmGpioIoTags /* 0x01 I/O Connection */
393 /* Serial Bus Subtypes */
395 static const ACPI_RESOURCE_TAG *AcpiGbl_SerialResourceTags[] =
397 NULL, /* 0x00 Reserved */
398 AcpiDmI2cSerialBusTags, /* 0x01 I2C SerialBus */
399 AcpiDmSpiSerialBusTags, /* 0x02 SPI SerialBus */
400 AcpiDmUartSerialBusTags /* 0x03 UART SerialBus */
404 * Globals used to generate unique resource descriptor names. We use names that
405 * start with underscore and a prefix letter that is not used by other ACPI
406 * reserved names. To this, we append hex 0x00 through 0xFF. These 5 prefixes
407 * allow for 5*256 = 1280 unique names, probably sufficient for any single ASL
408 * file. If this becomes too small, we can use alpha+numerals for a total
411 #define ACPI_NUM_RES_PREFIX 5
413 static UINT32 AcpiGbl_NextResourceId = 0;
414 static UINT8 AcpiGbl_NextPrefix = 0;
415 static char AcpiGbl_Prefix[ACPI_NUM_RES_PREFIX] =
416 {'Y','Z','J','K','X'};
419 /*******************************************************************************
421 * FUNCTION: AcpiDmCheckResourceReference
423 * PARAMETERS: Op - Parse Op for the AML opcode
424 * WalkState - Current walk state (with valid scope)
428 * DESCRIPTION: Convert a reference to a resource descriptor to a symbolic
429 * reference if possible
431 * NOTE: Bit index is used to transparently handle both resource bit
432 * fields and byte fields.
434 ******************************************************************************/
437 AcpiDmCheckResourceReference (
438 ACPI_PARSE_OBJECT *Op,
439 ACPI_WALK_STATE *WalkState)
442 ACPI_PARSE_OBJECT *BufferNameOp;
443 ACPI_PARSE_OBJECT *IndexOp;
444 ACPI_NAMESPACE_NODE *BufferNode;
445 ACPI_NAMESPACE_NODE *ResourceNode;
446 const ACPI_OPCODE_INFO *OpInfo;
450 /* We are only interested in the CreateXxxxField opcodes */
452 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
453 if (OpInfo->Type != AML_TYPE_CREATE_FIELD)
458 /* Get the buffer term operand */
460 BufferNameOp = AcpiPsGetDepthNext (NULL, Op);
462 /* Must be a named buffer, not an arg or local or method call */
464 if (BufferNameOp->Common.AmlOpcode != AML_INT_NAMEPATH_OP)
469 /* Get the Index term, must be an integer constant to convert */
471 IndexOp = BufferNameOp->Common.Next;
472 OpInfo = AcpiPsGetOpcodeInfo (IndexOp->Common.AmlOpcode);
473 if (OpInfo->ObjectType != ACPI_TYPE_INTEGER)
478 /* Get the bit offset of the descriptor within the buffer */
480 if ((Op->Common.AmlOpcode == AML_CREATE_BIT_FIELD_OP) ||
481 (Op->Common.AmlOpcode == AML_CREATE_FIELD_OP))
483 /* Index operand is a bit offset */
485 BitIndex = (UINT32) IndexOp->Common.Value.Integer;
489 /* Index operand is a byte offset, convert to bits */
491 BitIndex = (UINT32) ACPI_MUL_8 (IndexOp->Common.Value.Integer);
494 /* Lookup the buffer in the namespace */
496 Status = AcpiNsLookup (WalkState->ScopeInfo,
497 BufferNameOp->Common.Value.String, ACPI_TYPE_BUFFER,
498 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, WalkState,
500 if (ACPI_FAILURE (Status))
505 /* Validate object type, we must have a buffer */
507 if (BufferNode->Type != ACPI_TYPE_BUFFER)
512 /* Find the resource descriptor node corresponding to the index */
514 ResourceNode = AcpiDmGetResourceNode (BufferNode, BitIndex);
520 /* Translate the Index to a resource tag pathname */
522 AcpiGetTagPathname (IndexOp, BufferNode, ResourceNode, BitIndex);
526 /*******************************************************************************
528 * FUNCTION: AcpiDmGetResourceNode
530 * PARAMETERS: BufferNode - Node for the parent buffer
531 * BitIndex - Index into the resource descriptor
533 * RETURN: Namespace node for the resource descriptor. NULL if not found
535 * DESCRIPTION: Find a resource descriptor that corresponds to the bit index
537 ******************************************************************************/
539 static ACPI_NAMESPACE_NODE *
540 AcpiDmGetResourceNode (
541 ACPI_NAMESPACE_NODE *BufferNode,
544 ACPI_NAMESPACE_NODE *Node;
545 UINT32 ByteIndex = ACPI_DIV_8 (BitIndex);
549 * Child list contains an entry for each resource descriptor. Find
550 * the descriptor that corresponds to the Index.
552 * If there are no children, this is not a resource template
554 Node = BufferNode->Child;
558 * Check if the Index falls within this resource.
560 * Value contains the resource offset, Object contains the resource
561 * length (both in bytes)
563 if ((ByteIndex >= Node->Value) &&
564 (ByteIndex < (Node->Value + Node->Length)))
576 /*******************************************************************************
578 * FUNCTION: AcpiGetTagPathname
580 * PARAMETERS: BufferNode - Node for the parent buffer
581 * ResourceNode - Node for a resource descriptor
582 * BitIndex - Index into the resource descriptor
584 * RETURN: Full pathname for a resource tag. NULL if no match.
585 * Path is returned in AML (packed) format.
587 * DESCRIPTION: Convert a BitIndex into a symbolic resource tag (full pathname)
589 ******************************************************************************/
593 ACPI_PARSE_OBJECT *IndexOp,
594 ACPI_NAMESPACE_NODE *BufferNode,
595 ACPI_NAMESPACE_NODE *ResourceNode,
599 UINT32 ResourceBitIndex;
600 UINT8 ResourceTableIndex;
601 ACPI_SIZE RequiredSize;
604 ACPI_PARSE_OBJECT *Op;
609 /* Get the Op that contains the actual buffer data */
611 Op = BufferNode->Op->Common.Value.Arg;
612 Op = Op->Common.Next;
618 /* Get the individual resource descriptor and validate it */
620 Aml = ACPI_CAST_PTR (AML_RESOURCE,
621 &Op->Named.Data[ResourceNode->Value]);
623 Status = AcpiUtValidateResource (Aml, &ResourceTableIndex);
624 if (ACPI_FAILURE (Status))
629 /* Get offset into this descriptor (from offset into entire buffer) */
631 ResourceBitIndex = BitIndex - ACPI_MUL_8 (ResourceNode->Value);
633 /* Get the tag associated with this resource descriptor and offset */
635 Tag = AcpiDmGetResourceTag (ResourceBitIndex, Aml, ResourceTableIndex);
642 * Now that we know that we have a reference that can be converted to a
643 * symbol, change the name of the resource to a unique name.
645 AcpiDmUpdateResourceName (ResourceNode);
647 /* Get the full pathname to the parent buffer */
649 RequiredSize = AcpiNsGetPathnameLength (BufferNode);
655 Pathname = ACPI_ALLOCATE_ZEROED (RequiredSize + ACPI_PATH_SEGMENT_LENGTH);
661 Status = AcpiNsBuildExternalPath (BufferNode, RequiredSize, Pathname);
662 if (ACPI_FAILURE (Status))
668 * Create the full path to the resource and tag by: remove the buffer name,
669 * append the resource descriptor name, append a dot, append the tag name.
671 * TBD: Always using the full path is a bit brute force, the path can be
672 * often be optimized with carats (if the original buffer namepath is a
673 * single nameseg). This doesn't really matter, because these paths do not
674 * end up in the final compiled AML, it's just an appearance issue for the
677 Pathname[ACPI_STRLEN (Pathname) - ACPI_NAME_SIZE] = 0;
678 ACPI_STRNCAT (Pathname, ResourceNode->Name.Ascii, ACPI_NAME_SIZE);
679 ACPI_STRCAT (Pathname, ".");
680 ACPI_STRNCAT (Pathname, Tag, ACPI_NAME_SIZE);
682 /* Internalize the namepath to AML format */
684 AcpiNsInternalizeName (Pathname, &InternalPath);
685 ACPI_FREE (Pathname);
687 /* Update the Op with the symbol */
689 AcpiPsInitOp (IndexOp, AML_INT_NAMEPATH_OP);
690 IndexOp->Common.Value.String = InternalPath;
692 /* We will need the tag later. Cheat by putting it in the Node field */
694 IndexOp->Common.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Tag);
695 return (InternalPath);
699 /*******************************************************************************
701 * FUNCTION: AcpiDmUpdateResourceName
703 * PARAMETERS: ResourceNode - Node for a resource descriptor
705 * RETURN: Stores new name in the ResourceNode
707 * DESCRIPTION: Create a new, unique name for a resource descriptor. Used by
708 * both the disassembly of the descriptor itself and any symbolic
709 * references to the descriptor. Ignored if a unique name has
710 * already been assigned to the resource.
712 * NOTE: Single threaded, suitable for applications only!
714 ******************************************************************************/
717 AcpiDmUpdateResourceName (
718 ACPI_NAMESPACE_NODE *ResourceNode)
720 char Name[ACPI_NAME_SIZE];
723 /* Ignore if a unique name has already been assigned */
725 if (ResourceNode->Name.Integer != ACPI_DEFAULT_RESNAME)
730 /* Generate a new ACPI name for the descriptor */
733 Name[1] = AcpiGbl_Prefix[AcpiGbl_NextPrefix];
734 Name[2] = AcpiUtHexToAsciiChar ((UINT64) AcpiGbl_NextResourceId, 4);
735 Name[3] = AcpiUtHexToAsciiChar ((UINT64) AcpiGbl_NextResourceId, 0);
737 /* Update globals for next name */
739 AcpiGbl_NextResourceId++;
740 if (AcpiGbl_NextResourceId >= 256)
742 AcpiGbl_NextResourceId = 0;
743 AcpiGbl_NextPrefix++;
744 if (AcpiGbl_NextPrefix > ACPI_NUM_RES_PREFIX)
746 AcpiGbl_NextPrefix = 0;
750 /* Change the resource descriptor name */
752 ResourceNode->Name.Integer = *ACPI_CAST_PTR (UINT32, &Name[0]);
756 /*******************************************************************************
758 * FUNCTION: AcpiDmGetResourceTag
760 * PARAMETERS: BitIndex - Index into the resource descriptor
761 * Resource - Pointer to the raw resource data
762 * ResourceIndex - Index correspoinding to the resource type
764 * RETURN: Pointer to the resource tag (ACPI_NAME). NULL if no match.
766 * DESCRIPTION: Convert a BitIndex into a symbolic resource tag.
768 * Note: ResourceIndex should be previously validated and guaranteed to ve
771 ******************************************************************************/
774 AcpiDmGetResourceTag (
776 AML_RESOURCE *Resource,
779 const ACPI_RESOURCE_TAG *TagList;
783 /* Get the tag list for this resource descriptor type */
785 TagList = AcpiGbl_ResourceTags[ResourceIndex];
788 * Handle descriptors that have multiple subtypes
790 switch (Resource->DescriptorType)
792 case ACPI_RESOURCE_NAME_ADDRESS16:
793 case ACPI_RESOURCE_NAME_ADDRESS32:
794 case ACPI_RESOURCE_NAME_ADDRESS64:
795 case ACPI_RESOURCE_NAME_EXTENDED_ADDRESS64:
798 * Subtype differentiation is the flags.
799 * Kindof brute force, but just blindly search for an index match
801 if (Resource->Address.ResourceType == ACPI_ADDRESS_TYPE_MEMORY_RANGE)
803 Tag = AcpiDmSearchTagList (BitIndex, AcpiDmMemoryFlagTags);
805 else if (Resource->Address.ResourceType == ACPI_ADDRESS_TYPE_IO_RANGE)
807 Tag = AcpiDmSearchTagList (BitIndex, AcpiDmIoFlagTags);
810 /* If we found a match, all done. Else, drop to normal search below */
818 case ACPI_RESOURCE_NAME_GPIO:
820 /* GPIO connection has 2 subtypes: Interrupt and I/O */
822 if (Resource->Gpio.ConnectionType > AML_RESOURCE_MAX_GPIOTYPE)
827 TagList = AcpiGbl_GpioResourceTags[Resource->Gpio.ConnectionType];
830 case ACPI_RESOURCE_NAME_SERIAL_BUS:
832 /* SerialBus has 3 subtypes: I2C, SPI, and UART */
834 if ((Resource->CommonSerialBus.Type == 0) ||
835 (Resource->CommonSerialBus.Type > AML_RESOURCE_MAX_SERIALBUSTYPE))
840 TagList = AcpiGbl_SerialResourceTags[Resource->CommonSerialBus.Type];
847 /* Search for a match against the BitIndex */
851 Tag = AcpiDmSearchTagList (BitIndex, TagList);
858 /*******************************************************************************
860 * FUNCTION: AcpiDmSearchTagList
862 * PARAMETERS: BitIndex - Index into the resource descriptor
863 * TagList - List to search
865 * RETURN: Pointer to a tag (ACPI_NAME). NULL if no match found.
867 * DESCRIPTION: Search a tag list for a match to the input BitIndex. Matches
868 * a fixed offset to a symbolic resource tag name.
870 ******************************************************************************/
873 AcpiDmSearchTagList (
875 const ACPI_RESOURCE_TAG *TagList)
879 * Walk the null-terminated tag list to find a matching bit offset.
880 * We are looking for an exact match.
882 for ( ; TagList->Tag; TagList++)
884 if (BitIndex == TagList->BitIndex)
886 return (TagList->Tag);
890 /* A matching offset was not found */
896 /*******************************************************************************
898 * FUNCTION: AcpiDmFindResources
900 * PARAMETERS: Root - Root of the parse tree
904 * DESCRIPTION: Add all ResourceTemplate declarations to the namespace. Each
905 * resource descriptor in each template is given a node -- used
906 * for later conversion of resource references to symbolic refs.
908 ******************************************************************************/
911 AcpiDmFindResources (
912 ACPI_PARSE_OBJECT *Root)
914 ACPI_PARSE_OBJECT *Op = Root;
915 ACPI_PARSE_OBJECT *Parent;
918 /* Walk the entire parse tree */
922 /* We are interested in Buffer() declarations */
924 if (Op->Common.AmlOpcode == AML_BUFFER_OP)
926 /* And only declarations of the form Name (XXXX, Buffer()... ) */
928 Parent = Op->Common.Parent;
929 if (Parent->Common.AmlOpcode == AML_NAME_OP)
932 * If the buffer is a resource template, add the individual
933 * resource descriptors to the namespace, as children of the
936 if (ACPI_SUCCESS (AcpiDmIsResourceTemplate (Op)))
938 Op->Common.DisasmOpcode = ACPI_DASM_RESOURCE;
939 AcpiDmAddResourcesToNamespace (Parent->Common.Node, Op);
944 Op = AcpiPsGetDepthNext (Root, Op);
949 /*******************************************************************************
951 * FUNCTION: AcpiDmAddResourcesToNamespace
953 * PARAMETERS: BufferNode - Node for the parent buffer
954 * Op - Parse op for the buffer
958 * DESCRIPTION: Add an entire resource template to the namespace. Each
959 * resource descriptor is added as a namespace node.
961 ******************************************************************************/
964 AcpiDmAddResourcesToNamespace (
965 ACPI_NAMESPACE_NODE *BufferNode,
966 ACPI_PARSE_OBJECT *Op)
968 ACPI_PARSE_OBJECT *NextOp;
971 /* Get to the ByteData list */
973 NextOp = Op->Common.Value.Arg;
974 NextOp = NextOp->Common.Next;
980 /* Set Node and Op to point to each other */
983 Op->Common.Node = BufferNode;
986 * Insert each resource into the namespace
987 * NextOp contains the Aml pointer and the Aml length
989 AcpiUtWalkAmlResources ((UINT8 *) NextOp->Named.Data,
990 (ACPI_SIZE) NextOp->Common.Value.Integer,
991 AcpiDmAddResourceToNamespace, BufferNode);
995 /*******************************************************************************
997 * FUNCTION: AcpiDmAddResourceToNamespace
999 * PARAMETERS: ACPI_WALK_AML_CALLBACK
1000 * BufferNode - Node for the parent buffer
1004 * DESCRIPTION: Add one resource descriptor to the namespace as a child of the
1005 * parent buffer. The same name is used for each descriptor. This
1006 * is changed later to a unique name if the resource is actually
1007 * referenced by an AML operator.
1009 ******************************************************************************/
1012 AcpiDmAddResourceToNamespace (
1016 UINT8 ResourceIndex,
1020 ACPI_GENERIC_STATE ScopeInfo;
1021 ACPI_NAMESPACE_NODE *Node;
1024 /* TBD: Don't need to add descriptors that have no tags defined? */
1026 /* Add the resource to the namespace, as child of the buffer */
1028 ScopeInfo.Scope.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Context);
1029 Status = AcpiNsLookup (&ScopeInfo, "_TMP", ACPI_TYPE_LOCAL_RESOURCE,
1030 ACPI_IMODE_LOAD_PASS2,
1031 ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE | ACPI_NS_PREFIX_IS_SCOPE,
1033 if (ACPI_FAILURE (Status))
1038 /* Set the name to the default, changed later if resource is referenced */
1040 Node->Name.Integer = ACPI_DEFAULT_RESNAME;
1042 /* Save the offset of the descriptor (within the original buffer) */
1044 Node->Value = Offset;
1045 Node->Length = Length;