2 /******************************************************************************
4 * Module Name: aslresource - Resource template/descriptor utilities
6 *****************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2010, 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/compiler/aslcompiler.h>
119 #include "aslcompiler.y.h"
120 #include <contrib/dev/acpica/include/amlcode.h>
123 #define _COMPONENT ACPI_COMPILER
124 ACPI_MODULE_NAME ("aslresource")
127 /*******************************************************************************
129 * FUNCTION: RsSmallAddressCheck
131 * PARAMETERS: Minimum - Address Min value
132 * Maximum - Address Max value
133 * Length - Address range value
134 * Alignment - Address alignment value
135 * MinOp - Original Op for Address Min
136 * MaxOp - Original Op for Address Max
137 * LengthOp - Original Op for address range
138 * AlignOp - Original Op for address alignment. If
139 * NULL, means "zero value for alignment is
140 * OK, and means 64K alignment" (for
141 * Memory24 descriptor)
143 * RETURN: None. Adds error messages to error log if necessary
145 * DESCRIPTION: Perform common value checks for "small" address descriptors.
147 * Io, Memory24, Memory32
149 ******************************************************************************/
152 RsSmallAddressCheck (
158 ACPI_PARSE_OBJECT *MinOp,
159 ACPI_PARSE_OBJECT *MaxOp,
160 ACPI_PARSE_OBJECT *LengthOp,
161 ACPI_PARSE_OBJECT *AlignOp)
164 if (Gbl_NoResourceChecking)
169 /* Special case for Memory24, values are compressed */
171 if (Type == ACPI_RESOURCE_NAME_MEMORY24)
173 if (!Alignment) /* Alignment==0 means 64K - no invalid alignment */
175 Alignment = ACPI_UINT16_MAX + 1;
183 /* IO descriptor has different definition of min/max, don't check */
185 if (Type != ACPI_RESOURCE_NAME_IO)
187 /* Basic checks on Min/Max/Length */
189 if (Minimum > Maximum)
191 AslError (ASL_ERROR, ASL_MSG_INVALID_MIN_MAX, MinOp, NULL);
193 else if (Length > (Maximum - Minimum + 1))
195 AslError (ASL_ERROR, ASL_MSG_INVALID_LENGTH, LengthOp, NULL);
199 /* Alignment of zero is not in ACPI spec, but is used to mean byte acc */
206 /* Addresses must be an exact multiple of the alignment value */
208 if (Minimum % Alignment)
210 AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, MinOp, NULL);
212 if (Maximum % Alignment)
214 AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, MaxOp, NULL);
219 /*******************************************************************************
221 * FUNCTION: RsLargeAddressCheck
223 * PARAMETERS: Minimum - Address Min value
224 * Maximum - Address Max value
225 * Length - Address range value
226 * Granularity - Address granularity value
227 * Flags - General flags for address descriptors:
229 * MinOp - Original Op for Address Min
230 * MaxOp - Original Op for Address Max
231 * LengthOp - Original Op for address range
232 * GranOp - Original Op for address granularity
234 * RETURN: None. Adds error messages to error log if necessary
236 * DESCRIPTION: Perform common value checks for "large" address descriptors.
238 * WordIo, WordBusNumber, WordSpace
239 * DWordIo, DWordMemory, DWordSpace
240 * QWordIo, QWordMemory, QWordSpace
241 * ExtendedIo, ExtendedMemory, ExtendedSpace
243 * _MIF flag set means that the minimum address is fixed and is not relocatable
244 * _MAF flag set means that the maximum address is fixed and is not relocatable
245 * Length of zero means that the record size is variable
247 * This function implements the LEN/MIF/MAF/MIN/MAX/GRA rules within Table 6-40
248 * of the ACPI 4.0a specification. Added 04/2010.
250 ******************************************************************************/
253 RsLargeAddressCheck (
259 ACPI_PARSE_OBJECT *MinOp,
260 ACPI_PARSE_OBJECT *MaxOp,
261 ACPI_PARSE_OBJECT *LengthOp,
262 ACPI_PARSE_OBJECT *GranOp)
265 if (Gbl_NoResourceChecking)
270 /* Basic checks on Min/Max/Length */
272 if (Minimum > Maximum)
274 AslError (ASL_ERROR, ASL_MSG_INVALID_MIN_MAX, MinOp, NULL);
277 else if (Length > (Maximum - Minimum + 1))
279 AslError (ASL_ERROR, ASL_MSG_INVALID_LENGTH, LengthOp, NULL);
283 /* If specified (non-zero), ensure granularity is a power-of-two minus one */
287 if ((Granularity + 1) &
290 AslError (ASL_ERROR, ASL_MSG_INVALID_GRANULARITY, GranOp, NULL);
296 * Check the various combinations of Length, MinFixed, and MaxFixed
300 /* Fixed non-zero length */
302 switch (Flags & (ACPI_RESOURCE_FLAG_MIF | ACPI_RESOURCE_FLAG_MAF))
306 * Fixed length, variable locations (both _MIN and _MAX).
307 * Length must be a multiple of granularity
309 if (Granularity & Length)
311 AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, LengthOp, NULL);
315 case (ACPI_RESOURCE_FLAG_MIF | ACPI_RESOURCE_FLAG_MAF):
317 /* Fixed length, fixed location. Granularity must be zero */
319 if (Granularity != 0)
321 AslError (ASL_ERROR, ASL_MSG_INVALID_GRAN_FIXED, GranOp, NULL);
324 /* Length must be exactly the size of the min/max window */
326 if (Length != (Maximum - Minimum + 1))
328 AslError (ASL_ERROR, ASL_MSG_INVALID_LENGTH_FIXED, LengthOp, NULL);
332 /* All other combinations are invalid */
334 case ACPI_RESOURCE_FLAG_MIF:
335 case ACPI_RESOURCE_FLAG_MAF:
337 AslError (ASL_ERROR, ASL_MSG_INVALID_ADDR_FLAGS, LengthOp, NULL);
342 /* Variable length (length==0) */
344 switch (Flags & (ACPI_RESOURCE_FLAG_MIF | ACPI_RESOURCE_FLAG_MAF))
348 * Both _MIN and _MAX are variable.
349 * No additional requirements, just exit
353 case ACPI_RESOURCE_FLAG_MIF:
355 /* _MIN is fixed. _MIN must be multiple of _GRA */
358 * The granularity is defined by the ACPI specification to be a
359 * power-of-two minus one, therefore the granularity is a
360 * bitmask which can be used to easily validate the addresses.
362 if (Granularity & Minimum)
364 AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, MinOp, NULL);
368 case ACPI_RESOURCE_FLAG_MAF:
370 /* _MAX is fixed. (_MAX + 1) must be multiple of _GRA */
372 if (Granularity & (Maximum + 1))
374 AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, MaxOp, "-1");
378 /* Both MIF/MAF set is invalid if length is zero */
380 case (ACPI_RESOURCE_FLAG_MIF | ACPI_RESOURCE_FLAG_MAF):
382 AslError (ASL_ERROR, ASL_MSG_INVALID_ADDR_FLAGS, LengthOp, NULL);
388 /*******************************************************************************
390 * FUNCTION: RsGetStringDataLength
392 * PARAMETERS: InitializerOp - Start of a subtree of init nodes
394 * RETURN: Valid string length if a string node is found (otherwise 0)
396 * DESCRIPTION: In a list of peer nodes, find the first one that contains a
397 * string and return the length of the string.
399 ******************************************************************************/
402 RsGetStringDataLength (
403 ACPI_PARSE_OBJECT *InitializerOp)
406 while (InitializerOp)
408 if (InitializerOp->Asl.ParseOpcode == PARSEOP_STRING_LITERAL)
410 return ((UINT16) (strlen (InitializerOp->Asl.Value.String) + 1));
412 InitializerOp = ASL_GET_PEER_NODE (InitializerOp);
419 /*******************************************************************************
421 * FUNCTION: RsAllocateResourceNode
423 * PARAMETERS: Size - Size of node in bytes
425 * RETURN: The allocated node - aborts on allocation failure
427 * DESCRIPTION: Allocate a resource description node and the resource
428 * descriptor itself (the nodes are used to link descriptors).
430 ******************************************************************************/
433 RsAllocateResourceNode (
436 ASL_RESOURCE_NODE *Rnode;
439 /* Allocate the node */
441 Rnode = UtLocalCalloc (sizeof (ASL_RESOURCE_NODE));
443 /* Allocate the resource descriptor itself */
445 Rnode->Buffer = UtLocalCalloc (Size);
446 Rnode->BufferLength = Size;
452 /*******************************************************************************
454 * FUNCTION: RsCreateBitField
456 * PARAMETERS: Op - Resource field node
457 * Name - Name of the field (Used only to reference
458 * the field in the ASL, not in the AML)
459 * ByteOffset - Offset from the field start
460 * BitOffset - Additional bit offset
462 * RETURN: None, sets fields within the input node
464 * DESCRIPTION: Utility function to generate a named bit field within a
465 * resource descriptor. Mark a node as 1) a field in a resource
466 * descriptor, and 2) set the value to be a BIT offset
468 ******************************************************************************/
472 ACPI_PARSE_OBJECT *Op,
478 Op->Asl.ExternalName = Name;
479 Op->Asl.Value.Integer = ((UINT64) ByteOffset * 8) + BitOffset;
480 Op->Asl.CompileFlags |= (NODE_IS_RESOURCE_FIELD | NODE_IS_BIT_OFFSET);
484 /*******************************************************************************
486 * FUNCTION: RsCreateByteField
488 * PARAMETERS: Op - Resource field node
489 * Name - Name of the field (Used only to reference
490 * the field in the ASL, not in the AML)
491 * ByteOffset - Offset from the field start
493 * RETURN: None, sets fields within the input node
495 * DESCRIPTION: Utility function to generate a named byte field within a
496 * resource descriptor. Mark a node as 1) a field in a resource
497 * descriptor, and 2) set the value to be a BYTE offset
499 ******************************************************************************/
503 ACPI_PARSE_OBJECT *Op,
508 Op->Asl.ExternalName = Name;
509 Op->Asl.Value.Integer = ByteOffset;
510 Op->Asl.CompileFlags |= NODE_IS_RESOURCE_FIELD;
514 /*******************************************************************************
516 * FUNCTION: RsSetFlagBits
518 * PARAMETERS: *Flags - Pointer to the flag byte
519 * Op - Flag initialization node
520 * Position - Bit position within the flag byte
521 * Default - Used if the node is DEFAULT.
523 * RETURN: Sets bits within the *Flags output byte.
525 * DESCRIPTION: Set a bit in a cumulative flags word from an initialization
526 * node. Will use a default value if the node is DEFAULT, meaning
527 * that no value was specified in the ASL. Used to merge multiple
528 * keywords into a single flags byte.
530 ******************************************************************************/
535 ACPI_PARSE_OBJECT *Op,
540 if (Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)
542 /* Use the default bit */
544 *Flags |= (DefaultBit << Position);
548 /* Use the bit specified in the initialization node */
550 *Flags |= (((UINT8) Op->Asl.Value.Integer) << Position);
555 /*******************************************************************************
557 * FUNCTION: RsCompleteNodeAndGetNext
559 * PARAMETERS: Op - Resource node to be completed
561 * RETURN: The next peer to the input node.
563 * DESCRIPTION: Mark the current node completed and return the next peer.
564 * The node ParseOpcode is set to DEFAULT_ARG, meaning that
565 * this node is to be ignored from now on.
567 ******************************************************************************/
570 RsCompleteNodeAndGetNext (
571 ACPI_PARSE_OBJECT *Op)
574 /* Mark this node unused */
576 Op->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
578 /* Move on to the next peer node in the initializer list */
580 return (ASL_GET_PEER_NODE (Op));
584 /*******************************************************************************
586 * FUNCTION: RsCheckListForDuplicates
588 * PARAMETERS: Op - First op in the initializer list
592 * DESCRIPTION: Check an initializer list for duplicate values. Emits an error
593 * if any duplicates are found.
595 ******************************************************************************/
598 RsCheckListForDuplicates (
599 ACPI_PARSE_OBJECT *Op)
601 ACPI_PARSE_OBJECT *NextValueOp = Op;
602 ACPI_PARSE_OBJECT *NextOp;
611 /* Search list once for each value in the list */
615 Value = (UINT32) NextValueOp->Asl.Value.Integer;
617 /* Compare this value to all remaining values in the list */
619 NextOp = ASL_GET_PEER_NODE (NextValueOp);
622 if (NextOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
626 if (Value == (UINT32) NextOp->Asl.Value.Integer)
628 /* Emit error only once per duplicate node */
630 if (!(NextOp->Asl.CompileFlags & NODE_IS_DUPLICATE))
632 NextOp->Asl.CompileFlags |= NODE_IS_DUPLICATE;
633 AslError (ASL_ERROR, ASL_MSG_DUPLICATE_ITEM,
639 NextOp = ASL_GET_PEER_NODE (NextOp);
642 NextValueOp = ASL_GET_PEER_NODE (NextValueOp);
647 /*******************************************************************************
649 * FUNCTION: RsDoOneResourceDescriptor
651 * PARAMETERS: DescriptorTypeOp - Parent parse node of the descriptor
652 * CurrentByteOffset - Offset in the resource descriptor
655 * RETURN: A valid resource node for the descriptor
657 * DESCRIPTION: Dispatches the processing of one resource descriptor
659 ******************************************************************************/
662 RsDoOneResourceDescriptor (
663 ACPI_PARSE_OBJECT *DescriptorTypeOp,
664 UINT32 CurrentByteOffset,
667 ASL_RESOURCE_NODE *Rnode = NULL;
670 /* Construct the resource */
672 switch (DescriptorTypeOp->Asl.ParseOpcode)
675 Rnode = RsDoDmaDescriptor (DescriptorTypeOp,
679 case PARSEOP_DWORDIO:
680 Rnode = RsDoDwordIoDescriptor (DescriptorTypeOp,
684 case PARSEOP_DWORDMEMORY:
685 Rnode = RsDoDwordMemoryDescriptor (DescriptorTypeOp,
689 case PARSEOP_DWORDSPACE:
690 Rnode = RsDoDwordSpaceDescriptor (DescriptorTypeOp,
694 case PARSEOP_ENDDEPENDENTFN:
697 case ACPI_RSTATE_NORMAL:
698 AslError (ASL_ERROR, ASL_MSG_MISSING_STARTDEPENDENT,
699 DescriptorTypeOp, NULL);
702 case ACPI_RSTATE_START_DEPENDENT:
703 AslError (ASL_ERROR, ASL_MSG_DEPENDENT_NESTING,
704 DescriptorTypeOp, NULL);
707 case ACPI_RSTATE_DEPENDENT_LIST:
712 *State = ACPI_RSTATE_NORMAL;
713 Rnode = RsDoEndDependentDescriptor (DescriptorTypeOp,
718 Rnode = RsDoEndTagDescriptor (DescriptorTypeOp,
722 case PARSEOP_EXTENDEDIO:
723 Rnode = RsDoExtendedIoDescriptor (DescriptorTypeOp,
727 case PARSEOP_EXTENDEDMEMORY:
728 Rnode = RsDoExtendedMemoryDescriptor (DescriptorTypeOp,
732 case PARSEOP_EXTENDEDSPACE:
733 Rnode = RsDoExtendedSpaceDescriptor (DescriptorTypeOp,
737 case PARSEOP_FIXEDIO:
738 Rnode = RsDoFixedIoDescriptor (DescriptorTypeOp,
742 case PARSEOP_INTERRUPT:
743 Rnode = RsDoInterruptDescriptor (DescriptorTypeOp,
748 Rnode = RsDoIoDescriptor (DescriptorTypeOp,
753 Rnode = RsDoIrqDescriptor (DescriptorTypeOp,
757 case PARSEOP_IRQNOFLAGS:
758 Rnode = RsDoIrqNoFlagsDescriptor (DescriptorTypeOp,
762 case PARSEOP_MEMORY24:
763 Rnode = RsDoMemory24Descriptor (DescriptorTypeOp,
767 case PARSEOP_MEMORY32:
768 Rnode = RsDoMemory32Descriptor (DescriptorTypeOp,
772 case PARSEOP_MEMORY32FIXED:
773 Rnode = RsDoMemory32FixedDescriptor (DescriptorTypeOp,
777 case PARSEOP_QWORDIO:
778 Rnode = RsDoQwordIoDescriptor (DescriptorTypeOp,
782 case PARSEOP_QWORDMEMORY:
783 Rnode = RsDoQwordMemoryDescriptor (DescriptorTypeOp,
787 case PARSEOP_QWORDSPACE:
788 Rnode = RsDoQwordSpaceDescriptor (DescriptorTypeOp,
792 case PARSEOP_REGISTER:
793 Rnode = RsDoGeneralRegisterDescriptor (DescriptorTypeOp,
797 case PARSEOP_STARTDEPENDENTFN:
800 case ACPI_RSTATE_START_DEPENDENT:
801 AslError (ASL_ERROR, ASL_MSG_DEPENDENT_NESTING,
802 DescriptorTypeOp, NULL);
805 case ACPI_RSTATE_NORMAL:
806 case ACPI_RSTATE_DEPENDENT_LIST:
811 *State = ACPI_RSTATE_START_DEPENDENT;
812 Rnode = RsDoStartDependentDescriptor (DescriptorTypeOp,
814 *State = ACPI_RSTATE_DEPENDENT_LIST;
817 case PARSEOP_STARTDEPENDENTFN_NOPRI:
820 case ACPI_RSTATE_START_DEPENDENT:
821 AslError (ASL_ERROR, ASL_MSG_DEPENDENT_NESTING,
822 DescriptorTypeOp, NULL);
825 case ACPI_RSTATE_NORMAL:
826 case ACPI_RSTATE_DEPENDENT_LIST:
831 *State = ACPI_RSTATE_START_DEPENDENT;
832 Rnode = RsDoStartDependentNoPriDescriptor (DescriptorTypeOp,
834 *State = ACPI_RSTATE_DEPENDENT_LIST;
837 case PARSEOP_VENDORLONG:
838 Rnode = RsDoVendorLargeDescriptor (DescriptorTypeOp,
842 case PARSEOP_VENDORSHORT:
843 Rnode = RsDoVendorSmallDescriptor (DescriptorTypeOp,
847 case PARSEOP_WORDBUSNUMBER:
848 Rnode = RsDoWordBusNumberDescriptor (DescriptorTypeOp,
853 Rnode = RsDoWordIoDescriptor (DescriptorTypeOp,
857 case PARSEOP_WORDSPACE:
858 Rnode = RsDoWordSpaceDescriptor (DescriptorTypeOp,
862 case PARSEOP_DEFAULT_ARG:
863 /* Just ignore any of these, they are used as fillers/placeholders */
867 printf ("Unknown resource descriptor type [%s]\n",
868 DescriptorTypeOp->Asl.ParseOpName);
873 * Mark original node as unused, but head of a resource descriptor.
874 * This allows the resource to be installed in the namespace so that
875 * references to the descriptor can be resolved.
877 DescriptorTypeOp->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
878 DescriptorTypeOp->Asl.CompileFlags = NODE_IS_RESOURCE_DESC;
879 DescriptorTypeOp->Asl.Value.Integer = CurrentByteOffset;
883 DescriptorTypeOp->Asl.FinalAmlLength = Rnode->BufferLength;
890 /*******************************************************************************
892 * FUNCTION: RsLinkDescriptorChain
894 * PARAMETERS: PreviousRnode - Pointer to the node that will be previous
895 * to the linked node, At exit, set to the
896 * last node in the new chain.
897 * Rnode - Resource node to link into the list
899 * RETURN: Cumulative buffer byte offset of the new segment of chain
901 * DESCRIPTION: Link a descriptor chain at the end of an existing chain.
903 ******************************************************************************/
906 RsLinkDescriptorChain (
907 ASL_RESOURCE_NODE **PreviousRnode,
908 ASL_RESOURCE_NODE *Rnode)
910 ASL_RESOURCE_NODE *LastRnode;
911 UINT32 CurrentByteOffset;
914 /* Anything to do? */
921 /* Point the previous node to the new node */
923 (*PreviousRnode)->Next = Rnode;
924 CurrentByteOffset = Rnode->BufferLength;
926 /* Walk to the end of the chain headed by Rnode */
929 while (LastRnode->Next)
931 LastRnode = LastRnode->Next;
932 CurrentByteOffset += LastRnode->BufferLength;
935 /* Previous node becomes the last node in the chain */
937 *PreviousRnode = LastRnode;
938 return CurrentByteOffset;
942 /*******************************************************************************
944 * FUNCTION: RsDoResourceTemplate
946 * PARAMETERS: Op - Parent of a resource template list
948 * RETURN: None. Sets input node to point to a list of AML code
950 * DESCRIPTION: Merge a list of resource descriptors into a single AML buffer,
951 * in preparation for output to the AML output file.
953 ******************************************************************************/
956 RsDoResourceTemplate (
957 ACPI_PARSE_OBJECT *Op)
959 ACPI_PARSE_OBJECT *BufferLengthOp;
960 ACPI_PARSE_OBJECT *BufferOp;
961 ACPI_PARSE_OBJECT *DescriptorTypeOp;
962 ACPI_PARSE_OBJECT *LastOp = NULL;
963 UINT32 CurrentByteOffset = 0;
964 ASL_RESOURCE_NODE HeadRnode;
965 ASL_RESOURCE_NODE *PreviousRnode;
966 ASL_RESOURCE_NODE *Rnode;
970 /* Mark parent as containing a resource template */
974 Op->Asl.Parent->Asl.CompileFlags |= NODE_IS_RESOURCE_DESC;
977 /* ResourceTemplate Opcode is first (Op) */
978 /* Buffer Length node is first child */
980 BufferLengthOp = ASL_GET_CHILD_NODE (Op);
982 /* Buffer Op is first peer */
984 BufferOp = ASL_GET_PEER_NODE (BufferLengthOp);
986 /* First Descriptor type is next */
988 DescriptorTypeOp = ASL_GET_PEER_NODE (BufferOp);
991 * Process all resource descriptors in the list
992 * Note: It is assumed that the EndTag node has been automatically
993 * inserted at the end of the template by the parser.
995 State = ACPI_RSTATE_NORMAL;
996 PreviousRnode = &HeadRnode;
997 while (DescriptorTypeOp)
999 DescriptorTypeOp->Asl.CompileFlags |= NODE_IS_RESOURCE_DESC;
1000 Rnode = RsDoOneResourceDescriptor (DescriptorTypeOp, CurrentByteOffset,
1004 * Update current byte offset to indicate the number of bytes from the
1005 * start of the buffer. Buffer can include multiple descriptors, we
1006 * must keep track of the offset of not only each descriptor, but each
1007 * element (field) within each descriptor as well.
1009 CurrentByteOffset += RsLinkDescriptorChain (&PreviousRnode, Rnode);
1011 /* Get the next descriptor in the list */
1013 LastOp = DescriptorTypeOp;
1014 DescriptorTypeOp = ASL_GET_PEER_NODE (DescriptorTypeOp);
1017 if (State == ACPI_RSTATE_DEPENDENT_LIST)
1021 LastOp = LastOp->Asl.Parent;
1023 AslError (ASL_ERROR, ASL_MSG_MISSING_ENDDEPENDENT, LastOp, NULL);
1027 * Transform the nodes into the following
1029 * Op -> AML_BUFFER_OP
1030 * First Child -> BufferLength
1031 * Second Child -> Descriptor Buffer (raw byte data)
1033 Op->Asl.ParseOpcode = PARSEOP_BUFFER;
1034 Op->Asl.AmlOpcode = AML_BUFFER_OP;
1035 Op->Asl.CompileFlags = NODE_AML_PACKAGE | NODE_IS_RESOURCE_DESC;
1037 BufferLengthOp->Asl.ParseOpcode = PARSEOP_INTEGER;
1038 BufferLengthOp->Asl.Value.Integer = CurrentByteOffset;
1039 (void) OpcSetOptimalIntegerSize (BufferLengthOp);
1041 BufferOp->Asl.ParseOpcode = PARSEOP_RAW_DATA;
1042 BufferOp->Asl.AmlOpcode = AML_RAW_DATA_CHAIN;
1043 BufferOp->Asl.AmlOpcodeLength = 0;
1044 BufferOp->Asl.AmlLength = CurrentByteOffset;
1045 BufferOp->Asl.Value.Buffer = (UINT8 *) HeadRnode.Next;
1046 BufferOp->Asl.CompileFlags |= NODE_IS_RESOURCE_DATA;