1 /******************************************************************************
3 * Module Name: dmrestag - Add tags to resource descriptors (Application-level)
6 *****************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2007, Intel Corp.
13 * All rights reserved.
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
38 * The above copyright and patent license is granted only if the following
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
73 * 3.4. Intel retains all right, title, and interest in and to the Original
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
81 * 4. Disclaimer and Export Compliance
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
115 *****************************************************************************/
118 #include <contrib/dev/acpica/acpi.h>
119 #include <contrib/dev/acpica/acparser.h>
120 #include <contrib/dev/acpica/acdisasm.h>
121 #include <contrib/dev/acpica/acnamesp.h>
122 #include <contrib/dev/acpica/amlcode.h>
124 /* This module used for application-level code only */
126 #define _COMPONENT ACPI_CA_DISASSEMBLER
127 ACPI_MODULE_NAME ("dmrestag")
129 /* Local prototypes */
132 AcpiDmUpdateResourceName (
133 ACPI_NAMESPACE_NODE *ResourceNode);
136 AcpiDmSearchTagList (
138 ACPI_RESOURCE_TAG *TagList);
141 AcpiDmGetResourceTag (
143 AML_RESOURCE *Resource,
144 UINT8 ResourceIndex);
148 ACPI_NAMESPACE_NODE *BufferNode,
149 ACPI_NAMESPACE_NODE *ResourceNode,
152 static ACPI_NAMESPACE_NODE *
153 AcpiDmGetResourceNode (
154 ACPI_NAMESPACE_NODE *BufferNode,
158 AcpiDmAddResourceToNamespace (
166 AcpiDmAddResourcesToNamespace (
167 ACPI_NAMESPACE_NODE *BufferNode,
168 ACPI_PARSE_OBJECT *Op);
171 /******************************************************************************
173 * Resource Tag tables
175 * These are the predefined tags that refer to elements of a resource
176 * descriptor. Each name and offset is defined in the ACPI specification.
178 * Each table entry contains the bit offset of the field and the associated
181 ******************************************************************************/
183 static ACPI_RESOURCE_TAG AcpiDmIrqTags[] =
185 {( 1 * 8), ACPI_RESTAG_INTERRUPT},
186 {( 3 * 8) + 0, ACPI_RESTAG_INTERRUPTTYPE},
187 {( 3 * 8) + 3, ACPI_RESTAG_INTERRUPTLEVEL},
188 {( 3 * 8) + 4, ACPI_RESTAG_INTERRUPTSHARE},
192 static ACPI_RESOURCE_TAG AcpiDmDmaTags[] =
194 {( 1 * 8), ACPI_RESTAG_DMA},
195 {( 2 * 8) + 0, ACPI_RESTAG_XFERTYPE},
196 {( 2 * 8) + 2, ACPI_RESTAG_BUSMASTER},
197 {( 2 * 8) + 5, ACPI_RESTAG_DMATYPE},
201 static ACPI_RESOURCE_TAG AcpiDmIoTags[] =
203 {( 1 * 8) + 0, ACPI_RESTAG_DECODE},
204 {( 2 * 8), ACPI_RESTAG_MINADDR},
205 {( 4 * 8), ACPI_RESTAG_MAXADDR},
206 {( 6 * 8), ACPI_RESTAG_ALIGNMENT},
207 {( 7 * 8), ACPI_RESTAG_LENGTH},
211 static ACPI_RESOURCE_TAG AcpiDmFixedIoTags[] =
213 {( 1 * 8), ACPI_RESTAG_BASEADDRESS},
214 {( 3 * 8), ACPI_RESTAG_LENGTH},
218 static ACPI_RESOURCE_TAG AcpiDmMemory24Tags[] =
220 {( 3 * 8) + 0, ACPI_RESTAG_READWRITETYPE},
221 {( 4 * 8), ACPI_RESTAG_MINADDR},
222 {( 6 * 8), ACPI_RESTAG_MAXADDR},
223 {( 8 * 8), ACPI_RESTAG_ALIGNMENT},
224 {(10 * 8), ACPI_RESTAG_LENGTH},
228 static ACPI_RESOURCE_TAG AcpiDmRegisterTags[] =
230 {( 3 * 8), ACPI_RESTAG_ADDRESSSPACE},
231 {( 4 * 8), ACPI_RESTAG_REGISTERBITWIDTH},
232 {( 5 * 8), ACPI_RESTAG_REGISTERBITOFFSET},
233 {( 6 * 8), ACPI_RESTAG_ACCESSSIZE},
234 {( 7 * 8), ACPI_RESTAG_ADDRESS},
238 static ACPI_RESOURCE_TAG AcpiDmMemory32Tags[] =
240 {( 3 * 8) + 0, ACPI_RESTAG_READWRITETYPE},
241 {( 4 * 8), ACPI_RESTAG_MINADDR},
242 {( 8 * 8), ACPI_RESTAG_MAXADDR},
243 {(12 * 8), ACPI_RESTAG_ALIGNMENT},
244 {(16 * 8), ACPI_RESTAG_LENGTH},
248 static ACPI_RESOURCE_TAG AcpiDmFixedMemory32Tags[] =
250 {( 3 * 8) + 0, ACPI_RESTAG_READWRITETYPE},
251 {( 4 * 8), ACPI_RESTAG_BASEADDRESS},
252 {( 8 * 8), ACPI_RESTAG_LENGTH},
256 static ACPI_RESOURCE_TAG AcpiDmInterruptTags[] =
258 {( 3 * 8) + 1, ACPI_RESTAG_INTERRUPTTYPE},
259 {( 3 * 8) + 2, ACPI_RESTAG_INTERRUPTLEVEL},
260 {( 3 * 8) + 3, ACPI_RESTAG_INTERRUPTSHARE},
261 {( 5 * 8), ACPI_RESTAG_INTERRUPT},
265 static ACPI_RESOURCE_TAG AcpiDmAddress16Tags[] =
267 {( 4 * 8) + 1, ACPI_RESTAG_DECODE},
268 {( 4 * 8) + 2, ACPI_RESTAG_MINTYPE},
269 {( 4 * 8) + 3, ACPI_RESTAG_MAXTYPE},
270 {( 6 * 8), ACPI_RESTAG_GRANULARITY},
271 {( 8 * 8), ACPI_RESTAG_MINADDR},
272 {(10 * 8), ACPI_RESTAG_MAXADDR},
273 {(12 * 8), ACPI_RESTAG_TRANSLATION},
274 {(14 * 8), ACPI_RESTAG_LENGTH},
278 static ACPI_RESOURCE_TAG AcpiDmAddress32Tags[] =
280 {( 4 * 8) + 1, ACPI_RESTAG_DECODE},
281 {( 4 * 8) + 2, ACPI_RESTAG_MINTYPE},
282 {( 4 * 8) + 3, ACPI_RESTAG_MAXTYPE},
283 {( 6 * 8), ACPI_RESTAG_GRANULARITY},
284 {(10 * 8), ACPI_RESTAG_MINADDR},
285 {(14 * 8), ACPI_RESTAG_MAXADDR},
286 {(18 * 8), ACPI_RESTAG_TRANSLATION},
287 {(22 * 8), ACPI_RESTAG_LENGTH},
291 static ACPI_RESOURCE_TAG AcpiDmAddress64Tags[] =
293 {( 4 * 8) + 1, ACPI_RESTAG_DECODE},
294 {( 4 * 8) + 2, ACPI_RESTAG_MINTYPE},
295 {( 4 * 8) + 3, ACPI_RESTAG_MAXTYPE},
296 {( 6 * 8), ACPI_RESTAG_GRANULARITY},
297 {(14 * 8), ACPI_RESTAG_MINADDR},
298 {(22 * 8), ACPI_RESTAG_MAXADDR},
299 {(30 * 8), ACPI_RESTAG_TRANSLATION},
300 {(38 * 8), ACPI_RESTAG_LENGTH},
304 static ACPI_RESOURCE_TAG AcpiDmExtendedAddressTags[] =
306 {( 4 * 8) + 1, ACPI_RESTAG_DECODE},
307 {( 4 * 8) + 2, ACPI_RESTAG_MINTYPE},
308 {( 4 * 8) + 3, ACPI_RESTAG_MAXTYPE},
309 {( 8 * 8), ACPI_RESTAG_GRANULARITY},
310 {(16 * 8), ACPI_RESTAG_MINADDR},
311 {(24 * 8), ACPI_RESTAG_MAXADDR},
312 {(32 * 8), ACPI_RESTAG_TRANSLATION},
313 {(40 * 8), ACPI_RESTAG_LENGTH},
314 {(48 * 8), ACPI_RESTAG_TYPESPECIFICATTRIBUTES},
318 /* Special-case tables for the type-specific flags */
320 static ACPI_RESOURCE_TAG AcpiDmMemoryFlagTags[] =
322 {( 5 * 8) + 0, ACPI_RESTAG_READWRITETYPE},
323 {( 5 * 8) + 1, ACPI_RESTAG_MEMTYPE},
324 {( 5 * 8) + 3, ACPI_RESTAG_MEMATTRIBUTES},
325 {( 5 * 8) + 5, ACPI_RESTAG_TYPE},
329 static ACPI_RESOURCE_TAG AcpiDmIoFlagTags[] =
331 {( 5 * 8) + 0, ACPI_RESTAG_RANGETYPE},
332 {( 5 * 8) + 4, ACPI_RESTAG_TYPE},
333 {( 5 * 8) + 5, ACPI_RESTAG_TRANSTYPE},
338 /* Dispatch table used to obtain the correct tag table for a descriptor */
340 static ACPI_RESOURCE_TAG *AcpiGbl_ResourceTags [] =
342 /* Small descriptors */
344 NULL, /* 0x00, Reserved */
345 NULL, /* 0x01, Reserved */
346 NULL, /* 0x02, Reserved */
347 NULL, /* 0x03, Reserved */
348 AcpiDmIrqTags, /* 0x04, ACPI_RESOURCE_NAME_IRQ_FORMAT */
349 AcpiDmDmaTags, /* 0x05, ACPI_RESOURCE_NAME_DMA_FORMAT */
350 NULL, /* 0x06, ACPI_RESOURCE_NAME_START_DEPENDENT */
351 NULL, /* 0x07, ACPI_RESOURCE_NAME_END_DEPENDENT */
352 AcpiDmIoTags, /* 0x08, ACPI_RESOURCE_NAME_IO_PORT */
353 AcpiDmFixedIoTags, /* 0x09, ACPI_RESOURCE_NAME_FIXED_IO_PORT */
354 NULL, /* 0x0A, Reserved */
355 NULL, /* 0x0B, Reserved */
356 NULL, /* 0x0C, Reserved */
357 NULL, /* 0x0D, Reserved */
358 NULL, /* 0x0E, ACPI_RESOURCE_NAME_SMALL_VENDOR */
359 NULL, /* 0x0F, ACPI_RESOURCE_NAME_END_TAG (not used) */
361 /* Large descriptors */
363 NULL, /* 0x00, Reserved */
364 AcpiDmMemory24Tags, /* 0x01, ACPI_RESOURCE_NAME_MEMORY_24 */
365 AcpiDmRegisterTags, /* 0x02, ACPI_RESOURCE_NAME_GENERIC_REGISTER */
366 NULL, /* 0x03, Reserved */
367 NULL, /* 0x04, ACPI_RESOURCE_NAME_LARGE_VENDOR */
368 AcpiDmMemory32Tags, /* 0x05, ACPI_RESOURCE_NAME_MEMORY_32 */
369 AcpiDmFixedMemory32Tags, /* 0x06, ACPI_RESOURCE_NAME_FIXED_MEMORY_32 */
370 AcpiDmAddress32Tags, /* 0x07, ACPI_RESOURCE_NAME_DWORD_ADDRESS_SPACE */
371 AcpiDmAddress16Tags, /* 0x08, ACPI_RESOURCE_NAME_WORD_ADDRESS_SPACE */
372 AcpiDmInterruptTags, /* 0x09, ACPI_RESOURCE_NAME_EXTENDED_XRUPT */
373 AcpiDmAddress64Tags, /* 0x0A, ACPI_RESOURCE_NAME_QWORD_ADDRESS_SPACE */
374 AcpiDmExtendedAddressTags /* 0x0B, ACPI_RESOURCE_NAME_EXTENDED_ADDRESS_SPACE */
379 * Globals used to generate unique resource descriptor names. We use names that
380 * start with underscore and a prefix letter that is not used by other ACPI
381 * reserved names. To this, we append hex 0x00 through 0xFF. These 5 prefixes
382 * allow for 5*256 = 1280 unique names, probably sufficient for any single ASL
383 * file. If this becomes too small, we can use alpha+numerals for a total
386 #define ACPI_NUM_RES_PREFIX 5
388 static UINT32 AcpiGbl_NextResourceId = 0;
389 static UINT8 AcpiGbl_NextPrefix = 0;
390 static UINT8 AcpiGbl_Prefix[ACPI_NUM_RES_PREFIX] =
391 {'Y','Z','J','K','X'};
394 /*******************************************************************************
396 * FUNCTION: AcpiDmCheckResourceReference
398 * PARAMETERS: Op - Parse Op for the AML opcode
399 * WalkState - Current walk state (with valid scope)
403 * DESCRIPTION: Convert a reference to a resource descriptor to a symbolic
404 * reference if possible
406 * NOTE: Bit index is used to transparently handle both resource bit
407 * fields and byte fields.
409 ******************************************************************************/
412 AcpiDmCheckResourceReference (
413 ACPI_PARSE_OBJECT *Op,
414 ACPI_WALK_STATE *WalkState)
417 ACPI_PARSE_OBJECT *BufferNameOp;
418 ACPI_PARSE_OBJECT *IndexOp;
419 ACPI_NAMESPACE_NODE *BufferNode;
420 ACPI_NAMESPACE_NODE *ResourceNode;
421 const ACPI_OPCODE_INFO *OpInfo;
426 /* We are only interested in the CreateXxxxField opcodes */
428 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
429 if (OpInfo->Type != AML_TYPE_CREATE_FIELD)
434 /* Get the buffer term operand */
436 BufferNameOp = AcpiPsGetDepthNext (NULL, Op);
438 /* Must be a named buffer, not an arg or local or method call */
440 if (BufferNameOp->Common.AmlOpcode != AML_INT_NAMEPATH_OP)
445 /* Get the Index term, must be an integer constant to convert */
447 IndexOp = BufferNameOp->Common.Next;
448 OpInfo = AcpiPsGetOpcodeInfo (IndexOp->Common.AmlOpcode);
449 if (OpInfo->ObjectType != ACPI_TYPE_INTEGER)
454 /* Get the bit offset of the descriptor within the buffer */
456 if ((Op->Common.AmlOpcode == AML_CREATE_BIT_FIELD_OP) ||
457 (Op->Common.AmlOpcode == AML_CREATE_FIELD_OP))
459 /* Index operand is a bit offset */
461 BitIndex = (UINT32) IndexOp->Common.Value.Integer;
465 /* Index operand is a byte offset, convert to bits */
467 BitIndex = (UINT32) ACPI_MUL_8 (IndexOp->Common.Value.Integer);
470 /* Lookup the buffer in the namespace */
472 Status = AcpiNsLookup (WalkState->ScopeInfo,
473 BufferNameOp->Common.Value.String, ACPI_TYPE_BUFFER,
474 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, WalkState,
476 if (ACPI_FAILURE (Status))
481 /* Validate object type, we must have a buffer */
483 if (BufferNode->Type != ACPI_TYPE_BUFFER)
488 /* Find the resource descriptor node corresponding to the index */
490 ResourceNode = AcpiDmGetResourceNode (BufferNode, BitIndex);
496 /* Translate the Index to a resource tag pathname */
498 Pathname = AcpiGetTagPathname (BufferNode, ResourceNode, BitIndex);
501 /* Complete the conversion of the Index to a symbol */
503 IndexOp->Common.AmlOpcode = AML_INT_NAMEPATH_OP;
504 IndexOp->Common.Value.String = Pathname;
509 /*******************************************************************************
511 * FUNCTION: AcpiDmGetResourceNode
513 * PARAMETERS: BufferNode - Node for the parent buffer
514 * BitIndex - Index into the resource descriptor
516 * RETURN: Namespace node for the resource descriptor. NULL if not found
518 * DESCRIPTION: Find a resource descriptor that corresponds to the bit index
520 ******************************************************************************/
522 static ACPI_NAMESPACE_NODE *
523 AcpiDmGetResourceNode (
524 ACPI_NAMESPACE_NODE *BufferNode,
527 ACPI_NAMESPACE_NODE *Node;
528 UINT32 ByteIndex = ACPI_DIV_8 (BitIndex);
532 * Child list contains an entry for each resource descriptor. Find
533 * the descriptor that corresponds to the Index.
535 * If there are no children, this is not a resource template
537 Node = BufferNode->Child;
541 * Check if the Index falls within this resource.
543 * Value contains the resource offset, Object contains the resource
544 * length (both in bytes)
546 if ((ByteIndex >= Node->Value) &&
547 (ByteIndex < (Node->Value + Node->Length)))
552 /* List is circular, this flag marks the end */
554 if (Node->Flags & ANOBJ_END_OF_PEER_LIST)
566 /*******************************************************************************
568 * FUNCTION: AcpiGetTagPathname
570 * PARAMETERS: BufferNode - Node for the parent buffer
571 * ResourceNode - Node for a resource descriptor
572 * BitIndex - Index into the resource descriptor
574 * RETURN: Full pathname for a resource tag. NULL if no match.
575 * Path is returned in AML (packed) format.
577 * DESCRIPTION: Convert a BitIndex into a symbolic resource tag (full pathname)
579 ******************************************************************************/
583 ACPI_NAMESPACE_NODE *BufferNode,
584 ACPI_NAMESPACE_NODE *ResourceNode,
588 UINT32 ResourceBitIndex;
589 UINT8 ResourceTableIndex;
590 ACPI_SIZE RequiredSize;
593 ACPI_PARSE_OBJECT *Op;
598 /* Get the Op that contains the actual buffer data */
600 Op = BufferNode->Op->Common.Value.Arg;
601 Op = Op->Common.Next;
607 /* Get the individual resource descriptor and validate it */
609 Aml = ACPI_CAST_PTR (AML_RESOURCE,
610 &Op->Named.Data[ResourceNode->Value]);
612 Status = AcpiUtValidateResource (Aml, &ResourceTableIndex);
613 if (ACPI_FAILURE (Status))
618 /* Get offset into this descriptor (from offset into entire buffer) */
620 ResourceBitIndex = BitIndex - ACPI_MUL_8 (ResourceNode->Value);
622 /* Get the tag associated with this resource descriptor and offset */
624 Tag = AcpiDmGetResourceTag (ResourceBitIndex, Aml, ResourceTableIndex);
631 * Now that we know that we have a reference that can be converted to a
632 * symbol, change the name of the resource to a unique name.
634 AcpiDmUpdateResourceName (ResourceNode);
636 /* Get the full pathname to the parent buffer */
638 RequiredSize = AcpiNsGetPathnameLength (BufferNode);
639 Pathname = ACPI_ALLOCATE_ZEROED (RequiredSize + ACPI_PATH_SEGMENT_LENGTH);
645 AcpiNsBuildExternalPath (BufferNode, RequiredSize, Pathname);
648 * Create the full path to the resource and tag by: remove the buffer name,
649 * append the resource descriptor name, append a dot, append the tag name.
651 * TBD: Always using the full path is a bit brute force, the path can be
652 * often be optimized with carats (if the original buffer namepath is a
653 * single nameseg). This doesn't really matter, because these paths do not
654 * end up in the final compiled AML, it's just an appearance issue for the
657 Pathname[ACPI_STRLEN (Pathname) - ACPI_NAME_SIZE] = 0;
658 ACPI_STRNCAT (Pathname, ResourceNode->Name.Ascii, ACPI_NAME_SIZE);
659 ACPI_STRCAT (Pathname, ".");
660 ACPI_STRNCAT (Pathname, Tag, ACPI_NAME_SIZE);
662 /* Internalize the namepath to AML format */
664 AcpiNsInternalizeName (Pathname, &InternalPath);
665 ACPI_FREE (Pathname);
666 return (InternalPath);
670 /*******************************************************************************
672 * FUNCTION: AcpiDmUpdateResourceName
674 * PARAMETERS: ResourceNode - Node for a resource descriptor
676 * RETURN: Stores new name in the ResourceNode
678 * DESCRIPTION: Create a new, unique name for a resource descriptor. Used by
679 * both the disassembly of the descriptor itself and any symbolic
680 * references to the descriptor. Ignored if a unique name has
681 * already been assigned to the resource.
683 * NOTE: Single threaded, suitable for applications only!
685 ******************************************************************************/
688 AcpiDmUpdateResourceName (
689 ACPI_NAMESPACE_NODE *ResourceNode)
691 char Name[ACPI_NAME_SIZE];
694 /* Ignore if a unique name has already been assigned */
696 if (ResourceNode->Name.Integer != ACPI_DEFAULT_RESNAME)
701 /* Generate a new ACPI name for the descriptor */
704 Name[1] = AcpiGbl_Prefix[AcpiGbl_NextPrefix];
705 Name[2] = AcpiUtHexToAsciiChar (AcpiGbl_NextResourceId, 4);
706 Name[3] = AcpiUtHexToAsciiChar (AcpiGbl_NextResourceId, 0);
708 /* Update globals for next name */
710 AcpiGbl_NextResourceId++;
711 if (AcpiGbl_NextResourceId >= 256)
713 AcpiGbl_NextResourceId = 0;
714 AcpiGbl_NextPrefix++;
715 if (AcpiGbl_NextPrefix > ACPI_NUM_RES_PREFIX)
717 AcpiGbl_NextPrefix = 0;
721 /* Change the resource descriptor name */
723 ResourceNode->Name.Integer = *(UINT32 *) Name;
727 /*******************************************************************************
729 * FUNCTION: AcpiDmGetResourceTag
731 * PARAMETERS: BitIndex - Index into the resource descriptor
732 * Resource - Pointer to the raw resource data
733 * ResourceIndex - Index correspoinding to the resource type
735 * RETURN: Pointer to the resource tag (ACPI_NAME). NULL if no match.
737 * DESCRIPTION: Convert a BitIndex into a symbolic resource tag.
739 ******************************************************************************/
742 AcpiDmGetResourceTag (
744 AML_RESOURCE *Resource,
747 ACPI_RESOURCE_TAG *TagList;
751 /* Get the tag list for this resource descriptor type */
753 TagList = AcpiGbl_ResourceTags[ResourceIndex];
756 /* There are no tags for this resource type */
762 * Handle the type-specific flags field for the address descriptors.
763 * Kindof brute force, but just blindly search for an index match.
765 switch (Resource->DescriptorType)
767 case ACPI_RESOURCE_NAME_ADDRESS16:
768 case ACPI_RESOURCE_NAME_ADDRESS32:
769 case ACPI_RESOURCE_NAME_ADDRESS64:
770 case ACPI_RESOURCE_NAME_EXTENDED_ADDRESS64:
772 if (Resource->Address.ResourceType == ACPI_ADDRESS_TYPE_MEMORY_RANGE)
774 Tag = AcpiDmSearchTagList (BitIndex, AcpiDmMemoryFlagTags);
776 else if (Resource->Address.ResourceType == ACPI_ADDRESS_TYPE_IO_RANGE)
778 Tag = AcpiDmSearchTagList (BitIndex, AcpiDmIoFlagTags);
781 /* If we found a match, all done. Else, drop to normal search below */
793 /* Search the tag list for this descriptor type */
795 Tag = AcpiDmSearchTagList (BitIndex, TagList);
800 /*******************************************************************************
802 * FUNCTION: AcpiDmSearchTagList
804 * PARAMETERS: BitIndex - Index into the resource descriptor
805 * TagList - List to search
807 * RETURN: Pointer to a tag (ACPI_NAME). NULL if no match found.
809 * DESCRIPTION: Search a tag list for a match to the input BitIndex. Matches
810 * a fixed offset to a symbolic resource tag name.
812 ******************************************************************************/
815 AcpiDmSearchTagList (
817 ACPI_RESOURCE_TAG *TagList)
821 * Walk the null-terminated tag list to find a matching bit offset.
822 * We are looking for an exact match.
824 for ( ; TagList->Tag; TagList++)
826 if (BitIndex == TagList->BitIndex)
828 return (TagList->Tag);
832 /* A matching offset was not found */
838 /*******************************************************************************
840 * FUNCTION: AcpiDmFindResources
842 * PARAMETERS: Root - Root of the parse tree
846 * DESCRIPTION: Add all ResourceTemplate declarations to the namespace. Each
847 * resource descriptor in each template is given a node -- used
848 * for later conversion of resource references to symbolic refs.
850 ******************************************************************************/
853 AcpiDmFindResources (
854 ACPI_PARSE_OBJECT *Root)
856 ACPI_PARSE_OBJECT *Op = Root;
857 ACPI_PARSE_OBJECT *Parent;
860 /* Walk the entire parse tree */
864 /* We are interested in Buffer() declarations */
866 if (Op->Common.AmlOpcode == AML_BUFFER_OP)
868 /* And only declarations of the form Name (XXXX, Buffer()... ) */
870 Parent = Op->Common.Parent;
871 if (Parent->Common.AmlOpcode == AML_NAME_OP)
874 * If the buffer is a resource template, add the individual
875 * resource descriptors to the namespace, as children of the
878 if (ACPI_SUCCESS (AcpiDmIsResourceTemplate (Op)))
880 Op->Common.DisasmOpcode = ACPI_DASM_RESOURCE;
881 AcpiDmAddResourcesToNamespace (Parent->Common.Node, Op);
886 Op = AcpiPsGetDepthNext (Root, Op);
891 /*******************************************************************************
893 * FUNCTION: AcpiDmAddResourcesToNamespace
895 * PARAMETERS: BufferNode - Node for the parent buffer
896 * Op - Parse op for the buffer
900 * DESCRIPTION: Add an entire resource template to the namespace. Each
901 * resource descriptor is added as a namespace node.
903 ******************************************************************************/
906 AcpiDmAddResourcesToNamespace (
907 ACPI_NAMESPACE_NODE *BufferNode,
908 ACPI_PARSE_OBJECT *Op)
910 ACPI_PARSE_OBJECT *NextOp;
913 /* Get to the ByteData list */
915 NextOp = Op->Common.Value.Arg;
916 NextOp = NextOp->Common.Next;
922 /* Set Node and Op to point to each other */
925 Op->Common.Node = BufferNode;
928 * Insert each resource into the namespace
929 * NextOp contains the Aml pointer and the Aml length
931 AcpiUtWalkAmlResources ((UINT8 *) NextOp->Named.Data,
932 (ACPI_SIZE) NextOp->Common.Value.Integer,
933 AcpiDmAddResourceToNamespace, BufferNode);
937 /*******************************************************************************
939 * FUNCTION: AcpiDmAddResourceToNamespace
941 * PARAMETERS: ACPI_WALK_AML_CALLBACK
942 * BufferNode - Node for the parent buffer
946 * DESCRIPTION: Add one resource descriptor to the namespace as a child of the
947 * parent buffer. The same name is used for each descriptor. This
948 * is changed later to a unique name if the resource is actually
949 * referenced by an AML operator.
951 ******************************************************************************/
954 AcpiDmAddResourceToNamespace (
962 ACPI_GENERIC_STATE ScopeInfo;
963 ACPI_NAMESPACE_NODE *Node;
966 /* TBD: Don't need to add descriptors that have no tags defined? */
968 /* Add the resource to the namespace, as child of the buffer */
970 ScopeInfo.Scope.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Context);
971 Status = AcpiNsLookup (&ScopeInfo, "_TMP", ACPI_TYPE_LOCAL_RESOURCE,
972 ACPI_IMODE_LOAD_PASS2,
973 ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE | ACPI_NS_PREFIX_IS_SCOPE,
975 if (ACPI_FAILURE (Status))
980 /* Set the name to the default, changed later if resource is referenced */
982 Node->Name.Integer = ACPI_DEFAULT_RESNAME;
984 /* Save the offset of the descriptor (within the original buffer) */
986 Node->Value = Offset;
987 Node->Length = Length;