1 /******************************************************************************
3 * Module Name: dmrestag - Add tags to resource descriptors (Application-level)
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp.
12 * All rights reserved.
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
72 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************
116 * Alternatively, you may choose to be licensed under the terms of the
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
122 * 1. Redistributions of source code must retain the above copyright
123 * notice, this list of conditions, and the following disclaimer,
124 * without modification.
125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 * substantially similar to the "NO WARRANTY" disclaimer below
127 * ("Disclaimer") and any redistribution must be conditioned upon
128 * including a substantially similar Disclaimer requirement for further
129 * binary redistribution.
130 * 3. Neither the names of the above-listed copyright holders nor the names
131 * of any contributors may be used to endorse or promote products derived
132 * from this software without specific prior written permission.
134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146 * Alternatively, you may choose to be licensed under the terms of the
147 * GNU General Public License ("GPL") version 2 as published by the Free
148 * Software Foundation.
150 *****************************************************************************/
152 #include <contrib/dev/acpica/include/acpi.h>
153 #include <contrib/dev/acpica/include/accommon.h>
154 #include <contrib/dev/acpica/include/acparser.h>
155 #include <contrib/dev/acpica/include/acdisasm.h>
156 #include <contrib/dev/acpica/include/acnamesp.h>
157 #include <contrib/dev/acpica/include/amlcode.h>
159 /* This module used for application-level code only */
161 #define _COMPONENT ACPI_CA_DISASSEMBLER
162 ACPI_MODULE_NAME ("dmrestag")
164 /* Local prototypes */
167 AcpiDmUpdateResourceName (
168 ACPI_NAMESPACE_NODE *ResourceNode);
171 AcpiDmSearchTagList (
173 const ACPI_RESOURCE_TAG *TagList);
176 AcpiDmGetResourceTag (
178 AML_RESOURCE *Resource,
179 UINT8 ResourceIndex);
183 ACPI_PARSE_OBJECT *Op,
184 ACPI_NAMESPACE_NODE *BufferNode,
185 ACPI_NAMESPACE_NODE *ResourceNode,
188 static ACPI_NAMESPACE_NODE *
189 AcpiDmGetResourceNode (
190 ACPI_NAMESPACE_NODE *BufferNode,
194 AcpiDmAddResourceToNamespace (
202 AcpiDmAddResourcesToNamespace (
203 ACPI_NAMESPACE_NODE *BufferNode,
204 ACPI_PARSE_OBJECT *Op);
207 /******************************************************************************
209 * Resource Tag tables
211 * These are the predefined tags that refer to elements of a resource
212 * descriptor. Each name and offset is defined in the ACPI specification.
214 * Each table entry contains the bit offset of the field and the associated
217 ******************************************************************************/
219 static const ACPI_RESOURCE_TAG AcpiDmIrqTags[] =
221 {( 1 * 8), ACPI_RESTAG_INTERRUPT},
222 {( 3 * 8) + 0, ACPI_RESTAG_INTERRUPTTYPE},
223 {( 3 * 8) + 3, ACPI_RESTAG_INTERRUPTLEVEL},
224 {( 3 * 8) + 4, ACPI_RESTAG_INTERRUPTSHARE},
228 static const ACPI_RESOURCE_TAG AcpiDmDmaTags[] =
230 {( 1 * 8), ACPI_RESTAG_DMA},
231 {( 2 * 8) + 0, ACPI_RESTAG_XFERTYPE},
232 {( 2 * 8) + 2, ACPI_RESTAG_BUSMASTER},
233 {( 2 * 8) + 5, ACPI_RESTAG_DMATYPE},
237 static const ACPI_RESOURCE_TAG AcpiDmIoTags[] =
239 {( 1 * 8) + 0, ACPI_RESTAG_DECODE},
240 {( 2 * 8), ACPI_RESTAG_MINADDR},
241 {( 4 * 8), ACPI_RESTAG_MAXADDR},
242 {( 6 * 8), ACPI_RESTAG_ALIGNMENT},
243 {( 7 * 8), ACPI_RESTAG_LENGTH},
247 static const ACPI_RESOURCE_TAG AcpiDmFixedIoTags[] =
249 {( 1 * 8), ACPI_RESTAG_BASEADDRESS},
250 {( 3 * 8), ACPI_RESTAG_LENGTH},
254 static const ACPI_RESOURCE_TAG AcpiDmFixedDmaTags[] =
256 {( 1 * 8), ACPI_RESTAG_DMA},
257 {( 3 * 8), ACPI_RESTAG_DMATYPE},
258 {( 5 * 8), ACPI_RESTAG_XFERTYPE},
262 static const ACPI_RESOURCE_TAG AcpiDmMemory24Tags[] =
264 {( 3 * 8) + 0, ACPI_RESTAG_READWRITETYPE},
265 {( 4 * 8), ACPI_RESTAG_MINADDR},
266 {( 6 * 8), ACPI_RESTAG_MAXADDR},
267 {( 8 * 8), ACPI_RESTAG_ALIGNMENT},
268 {(10 * 8), ACPI_RESTAG_LENGTH},
272 static const ACPI_RESOURCE_TAG AcpiDmRegisterTags[] =
274 {( 3 * 8), ACPI_RESTAG_ADDRESSSPACE},
275 {( 4 * 8), ACPI_RESTAG_REGISTERBITWIDTH},
276 {( 5 * 8), ACPI_RESTAG_REGISTERBITOFFSET},
277 {( 6 * 8), ACPI_RESTAG_ACCESSSIZE},
278 {( 7 * 8), ACPI_RESTAG_ADDRESS},
282 static const ACPI_RESOURCE_TAG AcpiDmMemory32Tags[] =
284 {( 3 * 8) + 0, ACPI_RESTAG_READWRITETYPE},
285 {( 4 * 8), ACPI_RESTAG_MINADDR},
286 {( 8 * 8), ACPI_RESTAG_MAXADDR},
287 {(12 * 8), ACPI_RESTAG_ALIGNMENT},
288 {(16 * 8), ACPI_RESTAG_LENGTH},
292 static const ACPI_RESOURCE_TAG AcpiDmFixedMemory32Tags[] =
294 {( 3 * 8) + 0, ACPI_RESTAG_READWRITETYPE},
295 {( 4 * 8), ACPI_RESTAG_BASEADDRESS},
296 {( 8 * 8), ACPI_RESTAG_LENGTH},
300 static const ACPI_RESOURCE_TAG AcpiDmInterruptTags[] =
302 {( 3 * 8) + 1, ACPI_RESTAG_INTERRUPTTYPE},
303 {( 3 * 8) + 2, ACPI_RESTAG_INTERRUPTLEVEL},
304 {( 3 * 8) + 3, ACPI_RESTAG_INTERRUPTSHARE},
305 {( 5 * 8), ACPI_RESTAG_INTERRUPT},
309 static const ACPI_RESOURCE_TAG AcpiDmAddress16Tags[] =
311 {( 4 * 8) + 1, ACPI_RESTAG_DECODE},
312 {( 4 * 8) + 2, ACPI_RESTAG_MINTYPE},
313 {( 4 * 8) + 3, ACPI_RESTAG_MAXTYPE},
314 {( 6 * 8), ACPI_RESTAG_GRANULARITY},
315 {( 8 * 8), ACPI_RESTAG_MINADDR},
316 {(10 * 8), ACPI_RESTAG_MAXADDR},
317 {(12 * 8), ACPI_RESTAG_TRANSLATION},
318 {(14 * 8), ACPI_RESTAG_LENGTH},
322 static const ACPI_RESOURCE_TAG AcpiDmAddress32Tags[] =
324 {( 4 * 8) + 1, ACPI_RESTAG_DECODE},
325 {( 4 * 8) + 2, ACPI_RESTAG_MINTYPE},
326 {( 4 * 8) + 3, ACPI_RESTAG_MAXTYPE},
327 {( 6 * 8), ACPI_RESTAG_GRANULARITY},
328 {(10 * 8), ACPI_RESTAG_MINADDR},
329 {(14 * 8), ACPI_RESTAG_MAXADDR},
330 {(18 * 8), ACPI_RESTAG_TRANSLATION},
331 {(22 * 8), ACPI_RESTAG_LENGTH},
335 static const ACPI_RESOURCE_TAG AcpiDmAddress64Tags[] =
337 {( 4 * 8) + 1, ACPI_RESTAG_DECODE},
338 {( 4 * 8) + 2, ACPI_RESTAG_MINTYPE},
339 {( 4 * 8) + 3, ACPI_RESTAG_MAXTYPE},
340 {( 6 * 8), ACPI_RESTAG_GRANULARITY},
341 {(14 * 8), ACPI_RESTAG_MINADDR},
342 {(22 * 8), ACPI_RESTAG_MAXADDR},
343 {(30 * 8), ACPI_RESTAG_TRANSLATION},
344 {(38 * 8), ACPI_RESTAG_LENGTH},
348 static const ACPI_RESOURCE_TAG AcpiDmExtendedAddressTags[] =
350 {( 4 * 8) + 1, ACPI_RESTAG_DECODE},
351 {( 4 * 8) + 2, ACPI_RESTAG_MINTYPE},
352 {( 4 * 8) + 3, ACPI_RESTAG_MAXTYPE},
353 {( 8 * 8), ACPI_RESTAG_GRANULARITY},
354 {(16 * 8), ACPI_RESTAG_MINADDR},
355 {(24 * 8), ACPI_RESTAG_MAXADDR},
356 {(32 * 8), ACPI_RESTAG_TRANSLATION},
357 {(40 * 8), ACPI_RESTAG_LENGTH},
358 {(48 * 8), ACPI_RESTAG_TYPESPECIFICATTRIBUTES},
362 /* Subtype tables for GPIO descriptors */
364 static const ACPI_RESOURCE_TAG AcpiDmGpioIntTags[] =
366 {( 7 * 8) + 0, ACPI_RESTAG_MODE},
367 {( 7 * 8) + 1, ACPI_RESTAG_POLARITY},
368 {( 7 * 8) + 3, ACPI_RESTAG_INTERRUPTSHARE},
369 {( 9 * 8), ACPI_RESTAG_PINCONFIG},
370 {(10 * 8), ACPI_RESTAG_DRIVESTRENGTH},
371 {(12 * 8), ACPI_RESTAG_DEBOUNCETIME},
375 static const ACPI_RESOURCE_TAG AcpiDmGpioIoTags[] =
377 {( 7 * 8) + 0, ACPI_RESTAG_IORESTRICTION},
378 {( 7 * 8) + 3, ACPI_RESTAG_INTERRUPTSHARE},
379 {( 9 * 8), ACPI_RESTAG_PINCONFIG},
380 {(10 * 8), ACPI_RESTAG_DRIVESTRENGTH},
381 {(12 * 8), ACPI_RESTAG_DEBOUNCETIME},
385 /* Subtype tables for SerialBus descriptors */
387 static const ACPI_RESOURCE_TAG AcpiDmI2cSerialBusTags[] =
389 {( 6 * 8) + 0, ACPI_RESTAG_SLAVEMODE},
390 {( 6 * 8) + 2, ACPI_RESTAG_INTERRUPTSHARE}, /* V2 - ACPI 6.0 */
391 {( 7 * 8) + 0, ACPI_RESTAG_MODE},
392 {(12 * 8), ACPI_RESTAG_SPEED},
393 {(16 * 8), ACPI_RESTAG_ADDRESS},
397 static const ACPI_RESOURCE_TAG AcpiDmSpiSerialBusTags[] =
399 {( 6 * 8) + 0, ACPI_RESTAG_SLAVEMODE},
400 {( 6 * 8) + 2, ACPI_RESTAG_INTERRUPTSHARE}, /* V2 - ACPI 6.0 */
401 {( 7 * 8) + 0, ACPI_RESTAG_MODE},
402 {( 7 * 8) + 1, ACPI_RESTAG_DEVICEPOLARITY},
403 {(12 * 8), ACPI_RESTAG_SPEED},
404 {(16 * 8), ACPI_RESTAG_LENGTH},
405 {(17 * 8), ACPI_RESTAG_PHASE},
406 {(18 * 8), ACPI_RESTAG_POLARITY},
407 {(19 * 8), ACPI_RESTAG_ADDRESS},
411 static const ACPI_RESOURCE_TAG AcpiDmUartSerialBusTags[] =
413 {( 6 * 8) + 0, ACPI_RESTAG_SLAVEMODE}, /* Note: not part of original macro */
414 {( 6 * 8) + 2, ACPI_RESTAG_INTERRUPTSHARE}, /* V2 - ACPI 6.0 */
415 {( 7 * 8) + 0, ACPI_RESTAG_FLOWCONTROL},
416 {( 7 * 8) + 2, ACPI_RESTAG_STOPBITS},
417 {( 7 * 8) + 4, ACPI_RESTAG_LENGTH},
418 {( 7 * 8) + 7, ACPI_RESTAG_ENDIANNESS},
419 {(12 * 8), ACPI_RESTAG_SPEED},
420 {(16 * 8), ACPI_RESTAG_LENGTH_RX},
421 {(18 * 8), ACPI_RESTAG_LENGTH_TX},
422 {(20 * 8), ACPI_RESTAG_PARITY},
423 {(21 * 8), ACPI_RESTAG_LINE},
427 /* Subtype tables for Address descriptor type-specific flags */
429 static const ACPI_RESOURCE_TAG AcpiDmMemoryFlagTags[] =
431 {( 5 * 8) + 0, ACPI_RESTAG_READWRITETYPE},
432 {( 5 * 8) + 1, ACPI_RESTAG_MEMTYPE},
433 {( 5 * 8) + 3, ACPI_RESTAG_MEMATTRIBUTES},
434 {( 5 * 8) + 5, ACPI_RESTAG_TYPE},
438 static const ACPI_RESOURCE_TAG AcpiDmIoFlagTags[] =
440 {( 5 * 8) + 0, ACPI_RESTAG_RANGETYPE},
441 {( 5 * 8) + 4, ACPI_RESTAG_TYPE},
442 {( 5 * 8) + 5, ACPI_RESTAG_TRANSTYPE},
448 * Dispatch table used to obtain the correct tag table for a descriptor.
450 * A NULL in this table means one of three things:
451 * 1) The descriptor ID is reserved and invalid
452 * 2) The descriptor has no tags associated with it
453 * 3) The descriptor has subtypes and a separate table will be used.
455 static const ACPI_RESOURCE_TAG *AcpiGbl_ResourceTags[] =
457 /* Small descriptors */
459 NULL, /* 0x00, Reserved */
460 NULL, /* 0x01, Reserved */
461 NULL, /* 0x02, Reserved */
462 NULL, /* 0x03, Reserved */
463 AcpiDmIrqTags, /* 0x04, ACPI_RESOURCE_NAME_IRQ_FORMAT */
464 AcpiDmDmaTags, /* 0x05, ACPI_RESOURCE_NAME_DMA_FORMAT */
465 NULL, /* 0x06, ACPI_RESOURCE_NAME_START_DEPENDENT */
466 NULL, /* 0x07, ACPI_RESOURCE_NAME_END_DEPENDENT */
467 AcpiDmIoTags, /* 0x08, ACPI_RESOURCE_NAME_IO_PORT */
468 AcpiDmFixedIoTags, /* 0x09, ACPI_RESOURCE_NAME_FIXED_IO_PORT */
469 AcpiDmFixedDmaTags, /* 0x0A, ACPI_RESOURCE_NAME_FIXED_DMA */
470 NULL, /* 0x0B, Reserved */
471 NULL, /* 0x0C, Reserved */
472 NULL, /* 0x0D, Reserved */
473 NULL, /* 0x0E, ACPI_RESOURCE_NAME_SMALL_VENDOR */
474 NULL, /* 0x0F, ACPI_RESOURCE_NAME_END_TAG (not used) */
476 /* Large descriptors */
478 NULL, /* 0x00, Reserved */
479 AcpiDmMemory24Tags, /* 0x01, ACPI_RESOURCE_NAME_MEMORY_24 */
480 AcpiDmRegisterTags, /* 0x02, ACPI_RESOURCE_NAME_GENERIC_REGISTER */
481 NULL, /* 0x03, Reserved */
482 NULL, /* 0x04, ACPI_RESOURCE_NAME_LARGE_VENDOR */
483 AcpiDmMemory32Tags, /* 0x05, ACPI_RESOURCE_NAME_MEMORY_32 */
484 AcpiDmFixedMemory32Tags, /* 0x06, ACPI_RESOURCE_NAME_FIXED_MEMORY_32 */
485 AcpiDmAddress32Tags, /* 0x07, ACPI_RESOURCE_NAME_DWORD_ADDRESS_SPACE */
486 AcpiDmAddress16Tags, /* 0x08, ACPI_RESOURCE_NAME_WORD_ADDRESS_SPACE */
487 AcpiDmInterruptTags, /* 0x09, ACPI_RESOURCE_NAME_EXTENDED_XRUPT */
488 AcpiDmAddress64Tags, /* 0x0A, ACPI_RESOURCE_NAME_QWORD_ADDRESS_SPACE */
489 AcpiDmExtendedAddressTags, /* 0x0B, ACPI_RESOURCE_NAME_EXTENDED_ADDRESS_SPACE */
490 NULL, /* 0x0C, ACPI_RESOURCE_NAME_GPIO - Use Subtype table below */
491 NULL, /* 0x0D, Reserved */
492 NULL /* 0x0E, ACPI_RESOURCE_NAME_SERIAL_BUS - Use Subtype table below */
497 static const ACPI_RESOURCE_TAG *AcpiGbl_GpioResourceTags[] =
499 AcpiDmGpioIntTags, /* 0x00 Interrupt Connection */
500 AcpiDmGpioIoTags /* 0x01 I/O Connection */
503 /* Serial Bus Subtypes */
505 static const ACPI_RESOURCE_TAG *AcpiGbl_SerialResourceTags[] =
507 NULL, /* 0x00 Reserved */
508 AcpiDmI2cSerialBusTags, /* 0x01 I2C SerialBus */
509 AcpiDmSpiSerialBusTags, /* 0x02 SPI SerialBus */
510 AcpiDmUartSerialBusTags /* 0x03 UART SerialBus */
514 * Globals used to generate unique resource descriptor names. We use names that
515 * start with underscore and a prefix letter that is not used by other ACPI
516 * reserved names. To this, we append hex 0x00 through 0xFF. These 5 prefixes
517 * allow for 5*256 = 1280 unique names, probably sufficient for any single ASL
518 * file. If this becomes too small, we can use alpha+numerals for a total
521 #define ACPI_NUM_RES_PREFIX 5
523 static UINT32 AcpiGbl_NextResourceId = 0;
524 static UINT8 AcpiGbl_NextPrefix = 0;
525 static char AcpiGbl_Prefix[ACPI_NUM_RES_PREFIX] =
526 {'Y','Z','J','K','X'};
529 /*******************************************************************************
531 * FUNCTION: AcpiDmCheckResourceReference
533 * PARAMETERS: Op - Parse Op for the AML opcode
534 * WalkState - Current walk state (with valid scope)
538 * DESCRIPTION: Convert a reference to a resource descriptor to a symbolic
539 * reference if possible
541 * NOTE: Bit index is used to transparently handle both resource bit
542 * fields and byte fields.
544 ******************************************************************************/
547 AcpiDmCheckResourceReference (
548 ACPI_PARSE_OBJECT *Op,
549 ACPI_WALK_STATE *WalkState)
552 ACPI_PARSE_OBJECT *BufferNameOp;
553 ACPI_PARSE_OBJECT *IndexOp;
554 ACPI_NAMESPACE_NODE *BufferNode;
555 ACPI_NAMESPACE_NODE *ResourceNode;
556 const ACPI_OPCODE_INFO *OpInfo;
560 /* We are only interested in the CreateXxxxField opcodes */
562 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
563 if (OpInfo->Type != AML_TYPE_CREATE_FIELD)
568 /* Get the buffer term operand */
570 BufferNameOp = AcpiPsGetDepthNext (NULL, Op);
572 /* Must be a named buffer, not an arg or local or method call */
574 if (BufferNameOp->Common.AmlOpcode != AML_INT_NAMEPATH_OP)
579 /* Get the Index term, must be an integer constant to convert */
581 IndexOp = BufferNameOp->Common.Next;
583 /* Major cheat: The Node field is also used for the Tag ptr. Clear it now */
585 IndexOp->Common.Node = NULL;
587 OpInfo = AcpiPsGetOpcodeInfo (IndexOp->Common.AmlOpcode);
588 if (OpInfo->ObjectType != ACPI_TYPE_INTEGER)
593 /* Get the bit offset of the descriptor within the buffer */
595 if ((Op->Common.AmlOpcode == AML_CREATE_BIT_FIELD_OP) ||
596 (Op->Common.AmlOpcode == AML_CREATE_FIELD_OP))
598 /* Index operand is a bit offset */
600 BitIndex = (UINT32) IndexOp->Common.Value.Integer;
604 /* Index operand is a byte offset, convert to bits */
606 BitIndex = (UINT32) ACPI_MUL_8 (IndexOp->Common.Value.Integer);
609 /* Lookup the buffer in the namespace */
611 Status = AcpiNsLookup (WalkState->ScopeInfo,
612 BufferNameOp->Common.Value.String, ACPI_TYPE_BUFFER,
613 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, WalkState,
615 if (ACPI_FAILURE (Status))
620 /* Validate object type, we must have a buffer */
622 if (BufferNode->Type != ACPI_TYPE_BUFFER)
627 /* Find the resource descriptor node corresponding to the index */
629 ResourceNode = AcpiDmGetResourceNode (BufferNode, BitIndex);
635 /* Translate the Index to a resource tag pathname */
637 AcpiGetTagPathname (IndexOp, BufferNode, ResourceNode, BitIndex);
641 /*******************************************************************************
643 * FUNCTION: AcpiDmGetResourceNode
645 * PARAMETERS: BufferNode - Node for the parent buffer
646 * BitIndex - Index into the resource descriptor
648 * RETURN: Namespace node for the resource descriptor. NULL if not found
650 * DESCRIPTION: Find a resource descriptor that corresponds to the bit index
652 ******************************************************************************/
654 static ACPI_NAMESPACE_NODE *
655 AcpiDmGetResourceNode (
656 ACPI_NAMESPACE_NODE *BufferNode,
659 ACPI_NAMESPACE_NODE *Node;
660 UINT32 ByteIndex = ACPI_DIV_8 (BitIndex);
664 * Child list contains an entry for each resource descriptor. Find
665 * the descriptor that corresponds to the Index.
667 * If there are no children, this is not a resource template
669 Node = BufferNode->Child;
673 * Check if the Index falls within this resource.
675 * Value contains the resource offset, Object contains the resource
676 * length (both in bytes)
678 if ((ByteIndex >= Node->Value) &&
679 (ByteIndex < (Node->Value + Node->Length)))
691 /*******************************************************************************
693 * FUNCTION: AcpiGetTagPathname
695 * PARAMETERS: BufferNode - Node for the parent buffer
696 * ResourceNode - Node for a resource descriptor
697 * BitIndex - Index into the resource descriptor
699 * RETURN: Full pathname for a resource tag. NULL if no match.
700 * Path is returned in AML (packed) format.
702 * DESCRIPTION: Convert a BitIndex into a symbolic resource tag (full pathname)
704 ******************************************************************************/
708 ACPI_PARSE_OBJECT *IndexOp,
709 ACPI_NAMESPACE_NODE *BufferNode,
710 ACPI_NAMESPACE_NODE *ResourceNode,
714 UINT32 ResourceBitIndex;
715 UINT8 ResourceTableIndex;
716 ACPI_SIZE RequiredSize;
719 ACPI_PARSE_OBJECT *Op;
724 /* Get the Op that contains the actual buffer data */
726 Op = BufferNode->Op->Common.Value.Arg;
727 Op = Op->Common.Next;
733 /* Get the individual resource descriptor and validate it */
735 Aml = ACPI_CAST_PTR (
736 AML_RESOURCE, &Op->Named.Data[ResourceNode->Value]);
738 Status = AcpiUtValidateResource (NULL, Aml, &ResourceTableIndex);
739 if (ACPI_FAILURE (Status))
744 /* Get offset into this descriptor (from offset into entire buffer) */
746 ResourceBitIndex = BitIndex - ACPI_MUL_8 (ResourceNode->Value);
748 /* Get the tag associated with this resource descriptor and offset */
750 Tag = AcpiDmGetResourceTag (ResourceBitIndex, Aml, ResourceTableIndex);
757 * Now that we know that we have a reference that can be converted to a
758 * symbol, change the name of the resource to a unique name.
760 AcpiDmUpdateResourceName (ResourceNode);
762 /* Get the full pathname to the parent buffer */
764 RequiredSize = AcpiNsBuildNormalizedPath (BufferNode, NULL, 0, FALSE);
770 Pathname = ACPI_ALLOCATE_ZEROED (RequiredSize + ACPI_PATH_SEGMENT_LENGTH);
776 (void) AcpiNsBuildNormalizedPath (BufferNode, Pathname,
777 RequiredSize, FALSE);
780 * Create the full path to the resource and tag by: remove the buffer name,
781 * append the resource descriptor name, append a dot, append the tag name.
783 * TBD: Always using the full path is a bit brute force, the path can be
784 * often be optimized with carats (if the original buffer namepath is a
785 * single nameseg). This doesn't really matter, because these paths do not
786 * end up in the final compiled AML, it's just an appearance issue for the
789 Pathname[strlen (Pathname) - ACPI_NAME_SIZE] = 0;
790 strncat (Pathname, ResourceNode->Name.Ascii, ACPI_NAME_SIZE);
791 strcat (Pathname, ".");
792 strncat (Pathname, Tag, ACPI_NAME_SIZE);
794 /* Internalize the namepath to AML format */
796 AcpiNsInternalizeName (Pathname, &InternalPath);
797 ACPI_FREE (Pathname);
799 /* Update the Op with the symbol */
801 AcpiPsInitOp (IndexOp, AML_INT_NAMEPATH_OP);
802 IndexOp->Common.Value.String = InternalPath;
805 * We will need the tag later. Cheat by putting it in the Node field.
806 * Note, Tag is a const that is part of a lookup table.
808 IndexOp->Common.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Tag);
809 return (InternalPath);
813 /*******************************************************************************
815 * FUNCTION: AcpiDmUpdateResourceName
817 * PARAMETERS: ResourceNode - Node for a resource descriptor
819 * RETURN: Stores new name in the ResourceNode
821 * DESCRIPTION: Create a new, unique name for a resource descriptor. Used by
822 * both the disassembly of the descriptor itself and any symbolic
823 * references to the descriptor. Ignored if a unique name has
824 * already been assigned to the resource.
826 * NOTE: Single threaded, suitable for applications only!
828 ******************************************************************************/
831 AcpiDmUpdateResourceName (
832 ACPI_NAMESPACE_NODE *ResourceNode)
834 char Name[ACPI_NAME_SIZE];
837 /* Ignore if a unique name has already been assigned */
839 if (ResourceNode->Name.Integer != ACPI_DEFAULT_RESNAME)
844 /* Generate a new ACPI name for the descriptor */
847 Name[1] = AcpiGbl_Prefix[AcpiGbl_NextPrefix];
848 Name[2] = AcpiUtHexToAsciiChar ((UINT64) AcpiGbl_NextResourceId, 4);
849 Name[3] = AcpiUtHexToAsciiChar ((UINT64) AcpiGbl_NextResourceId, 0);
851 /* Update globals for next name */
853 AcpiGbl_NextResourceId++;
854 if (AcpiGbl_NextResourceId >= 256)
856 AcpiGbl_NextResourceId = 0;
857 AcpiGbl_NextPrefix++;
859 if (AcpiGbl_NextPrefix > ACPI_NUM_RES_PREFIX)
861 AcpiGbl_NextPrefix = 0;
865 /* Change the resource descriptor name */
867 ResourceNode->Name.Integer = *ACPI_CAST_PTR (UINT32, &Name[0]);
871 /*******************************************************************************
873 * FUNCTION: AcpiDmGetResourceTag
875 * PARAMETERS: BitIndex - Index into the resource descriptor
876 * Resource - Pointer to the raw resource data
877 * ResourceIndex - Index correspoinding to the resource type
879 * RETURN: Pointer to the resource tag (ACPI_NAME). NULL if no match.
881 * DESCRIPTION: Convert a BitIndex into a symbolic resource tag.
883 * Note: ResourceIndex should be previously validated and guaranteed to ve
886 ******************************************************************************/
889 AcpiDmGetResourceTag (
891 AML_RESOURCE *Resource,
894 const ACPI_RESOURCE_TAG *TagList;
898 /* Get the tag list for this resource descriptor type */
900 TagList = AcpiGbl_ResourceTags[ResourceIndex];
903 * Handle descriptors that have multiple subtypes
905 switch (Resource->DescriptorType)
907 case ACPI_RESOURCE_NAME_ADDRESS16:
908 case ACPI_RESOURCE_NAME_ADDRESS32:
909 case ACPI_RESOURCE_NAME_ADDRESS64:
910 case ACPI_RESOURCE_NAME_EXTENDED_ADDRESS64:
912 * Subtype differentiation is the flags.
913 * Kindof brute force, but just blindly search for an index match
915 if (Resource->Address.ResourceType == ACPI_ADDRESS_TYPE_MEMORY_RANGE)
917 Tag = AcpiDmSearchTagList (BitIndex, AcpiDmMemoryFlagTags);
919 else if (Resource->Address.ResourceType == ACPI_ADDRESS_TYPE_IO_RANGE)
921 Tag = AcpiDmSearchTagList (BitIndex, AcpiDmIoFlagTags);
924 /* If we found a match, all done. Else, drop to normal search below */
932 case ACPI_RESOURCE_NAME_GPIO:
934 /* GPIO connection has 2 subtypes: Interrupt and I/O */
936 if (Resource->Gpio.ConnectionType > AML_RESOURCE_MAX_GPIOTYPE)
941 TagList = AcpiGbl_GpioResourceTags[Resource->Gpio.ConnectionType];
944 case ACPI_RESOURCE_NAME_SERIAL_BUS:
946 /* SerialBus has 3 subtypes: I2C, SPI, and UART */
948 if ((Resource->CommonSerialBus.Type == 0) ||
949 (Resource->CommonSerialBus.Type > AML_RESOURCE_MAX_SERIALBUSTYPE))
954 TagList = AcpiGbl_SerialResourceTags[Resource->CommonSerialBus.Type];
962 /* Search for a match against the BitIndex */
966 Tag = AcpiDmSearchTagList (BitIndex, TagList);
973 /*******************************************************************************
975 * FUNCTION: AcpiDmSearchTagList
977 * PARAMETERS: BitIndex - Index into the resource descriptor
978 * TagList - List to search
980 * RETURN: Pointer to a tag (ACPI_NAME). NULL if no match found.
982 * DESCRIPTION: Search a tag list for a match to the input BitIndex. Matches
983 * a fixed offset to a symbolic resource tag name.
985 ******************************************************************************/
988 AcpiDmSearchTagList (
990 const ACPI_RESOURCE_TAG *TagList)
994 * Walk the null-terminated tag list to find a matching bit offset.
995 * We are looking for an exact match.
997 for ( ; TagList->Tag; TagList++)
999 if (BitIndex == TagList->BitIndex)
1001 return (TagList->Tag);
1005 /* A matching offset was not found */
1011 /*******************************************************************************
1013 * FUNCTION: AcpiDmFindResources
1015 * PARAMETERS: Root - Root of the parse tree
1019 * DESCRIPTION: Add all ResourceTemplate declarations to the namespace. Each
1020 * resource descriptor in each template is given a node -- used
1021 * for later conversion of resource references to symbolic refs.
1023 ******************************************************************************/
1026 AcpiDmFindResources (
1027 ACPI_PARSE_OBJECT *Root)
1029 ACPI_PARSE_OBJECT *Op = Root;
1030 ACPI_PARSE_OBJECT *Parent;
1033 /* Walk the entire parse tree */
1037 /* We are interested in Buffer() declarations */
1039 if (Op->Common.AmlOpcode == AML_BUFFER_OP)
1041 /* And only declarations of the form Name (XXXX, Buffer()... ) */
1043 Parent = Op->Common.Parent;
1044 if (Parent->Common.AmlOpcode == AML_NAME_OP)
1047 * If the buffer is a resource template, add the individual
1048 * resource descriptors to the namespace, as children of the
1051 if (ACPI_SUCCESS (AcpiDmIsResourceTemplate (NULL, Op)))
1053 Op->Common.DisasmOpcode = ACPI_DASM_RESOURCE;
1054 AcpiDmAddResourcesToNamespace (Parent->Common.Node, Op);
1059 Op = AcpiPsGetDepthNext (Root, Op);
1064 /*******************************************************************************
1066 * FUNCTION: AcpiDmAddResourcesToNamespace
1068 * PARAMETERS: BufferNode - Node for the parent buffer
1069 * Op - Parse op for the buffer
1073 * DESCRIPTION: Add an entire resource template to the namespace. Each
1074 * resource descriptor is added as a namespace node.
1076 ******************************************************************************/
1079 AcpiDmAddResourcesToNamespace (
1080 ACPI_NAMESPACE_NODE *BufferNode,
1081 ACPI_PARSE_OBJECT *Op)
1083 ACPI_PARSE_OBJECT *NextOp;
1086 /* Get to the ByteData list */
1088 NextOp = Op->Common.Value.Arg;
1089 NextOp = NextOp->Common.Next;
1095 /* Set Node and Op to point to each other */
1097 BufferNode->Op = Op;
1098 Op->Common.Node = BufferNode;
1101 * Insert each resource into the namespace
1102 * NextOp contains the Aml pointer and the Aml length
1104 AcpiUtWalkAmlResources (NULL, (UINT8 *) NextOp->Named.Data,
1105 (ACPI_SIZE) NextOp->Common.Value.Integer,
1106 AcpiDmAddResourceToNamespace, (void **) BufferNode);
1110 /*******************************************************************************
1112 * FUNCTION: AcpiDmAddResourceToNamespace
1114 * PARAMETERS: ACPI_WALK_AML_CALLBACK
1115 * BufferNode - Node for the parent buffer
1119 * DESCRIPTION: Add one resource descriptor to the namespace as a child of the
1120 * parent buffer. The same name is used for each descriptor. This
1121 * is changed later to a unique name if the resource is actually
1122 * referenced by an AML operator.
1124 ******************************************************************************/
1127 AcpiDmAddResourceToNamespace (
1131 UINT8 ResourceIndex,
1135 ACPI_GENERIC_STATE ScopeInfo;
1136 ACPI_NAMESPACE_NODE *Node;
1139 /* TBD: Don't need to add descriptors that have no tags defined? */
1141 /* Add the resource to the namespace, as child of the buffer */
1143 ScopeInfo.Scope.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Context);
1144 Status = AcpiNsLookup (&ScopeInfo, "_TMP", ACPI_TYPE_LOCAL_RESOURCE,
1145 ACPI_IMODE_LOAD_PASS2,
1146 ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE | ACPI_NS_PREFIX_IS_SCOPE,
1148 if (ACPI_FAILURE (Status))
1153 /* Set the name to the default, changed later if resource is referenced */
1155 Node->Name.Integer = ACPI_DEFAULT_RESNAME;
1157 /* Save the offset of the descriptor (within the original buffer) */
1159 Node->Value = Offset;
1160 Node->Length = Length;