2 /******************************************************************************
4 * Module Name: aslresource - Resource template/descriptor utilities
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2011, Intel Corp.
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
46 #include <contrib/dev/acpica/compiler/aslcompiler.h>
47 #include "aslcompiler.y.h"
48 #include <contrib/dev/acpica/include/amlcode.h>
51 #define _COMPONENT ACPI_COMPILER
52 ACPI_MODULE_NAME ("aslresource")
55 /*******************************************************************************
57 * FUNCTION: RsSmallAddressCheck
59 * PARAMETERS: Minimum - Address Min value
60 * Maximum - Address Max value
61 * Length - Address range value
62 * Alignment - Address alignment value
63 * MinOp - Original Op for Address Min
64 * MaxOp - Original Op for Address Max
65 * LengthOp - Original Op for address range
66 * AlignOp - Original Op for address alignment. If
67 * NULL, means "zero value for alignment is
68 * OK, and means 64K alignment" (for
69 * Memory24 descriptor)
70 * Op - Parent Op for entire construct
72 * RETURN: None. Adds error messages to error log if necessary
74 * DESCRIPTION: Perform common value checks for "small" address descriptors.
76 * Io, Memory24, Memory32
78 ******************************************************************************/
87 ACPI_PARSE_OBJECT *MinOp,
88 ACPI_PARSE_OBJECT *MaxOp,
89 ACPI_PARSE_OBJECT *LengthOp,
90 ACPI_PARSE_OBJECT *AlignOp,
91 ACPI_PARSE_OBJECT *Op)
94 if (Gbl_NoResourceChecking)
100 * Check for a so-called "null descriptor". These are descriptors that are
101 * created with most fields set to zero. The intent is that the descriptor
102 * will be updated/completed at runtime via a BufferField.
104 * If the descriptor does NOT have a resource tag, it cannot be referenced
105 * by a BufferField and we will flag this as an error. Conversely, if
106 * the descriptor has a resource tag, we will assume that a BufferField
107 * will be used to dynamically update it, so no error.
109 * A possible enhancement to this check would be to verify that in fact
110 * a BufferField is created using the resource tag, and perhaps even
111 * verify that a Store is performed to the BufferField.
113 * Note: for these descriptors, Alignment is allowed to be zero
115 if (!Minimum && !Maximum && !Length)
117 if (!Op->Asl.ExternalName)
119 /* No resource tag. Descriptor is fixed and is also illegal */
121 AslError (ASL_ERROR, ASL_MSG_NULL_DESCRIPTOR, Op, NULL);
127 /* Special case for Memory24, values are compressed */
129 if (Type == ACPI_RESOURCE_NAME_MEMORY24)
131 if (!Alignment) /* Alignment==0 means 64K - no invalid alignment */
133 Alignment = ACPI_UINT16_MAX + 1;
141 /* IO descriptor has different definition of min/max, don't check */
143 if (Type != ACPI_RESOURCE_NAME_IO)
145 /* Basic checks on Min/Max/Length */
147 if (Minimum > Maximum)
149 AslError (ASL_ERROR, ASL_MSG_INVALID_MIN_MAX, MinOp, NULL);
151 else if (Length > (Maximum - Minimum + 1))
153 AslError (ASL_ERROR, ASL_MSG_INVALID_LENGTH, LengthOp, NULL);
157 /* Alignment of zero is not in ACPI spec, but is used to mean byte acc */
164 /* Addresses must be an exact multiple of the alignment value */
166 if (Minimum % Alignment)
168 AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, MinOp, NULL);
170 if (Maximum % Alignment)
172 AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, MaxOp, NULL);
177 /*******************************************************************************
179 * FUNCTION: RsLargeAddressCheck
181 * PARAMETERS: Minimum - Address Min value
182 * Maximum - Address Max value
183 * Length - Address range value
184 * Granularity - Address granularity value
185 * Flags - General flags for address descriptors:
187 * MinOp - Original Op for Address Min
188 * MaxOp - Original Op for Address Max
189 * LengthOp - Original Op for address range
190 * GranOp - Original Op for address granularity
191 * Op - Parent Op for entire construct
193 * RETURN: None. Adds error messages to error log if necessary
195 * DESCRIPTION: Perform common value checks for "large" address descriptors.
197 * WordIo, WordBusNumber, WordSpace
198 * DWordIo, DWordMemory, DWordSpace
199 * QWordIo, QWordMemory, QWordSpace
200 * ExtendedIo, ExtendedMemory, ExtendedSpace
202 * _MIF flag set means that the minimum address is fixed and is not relocatable
203 * _MAF flag set means that the maximum address is fixed and is not relocatable
204 * Length of zero means that the record size is variable
206 * This function implements the LEN/MIF/MAF/MIN/MAX/GRA rules within Table 6-40
207 * of the ACPI 4.0a specification. Added 04/2010.
209 ******************************************************************************/
212 RsLargeAddressCheck (
218 ACPI_PARSE_OBJECT *MinOp,
219 ACPI_PARSE_OBJECT *MaxOp,
220 ACPI_PARSE_OBJECT *LengthOp,
221 ACPI_PARSE_OBJECT *GranOp,
222 ACPI_PARSE_OBJECT *Op)
225 if (Gbl_NoResourceChecking)
231 * Check for a so-called "null descriptor". These are descriptors that are
232 * created with most fields set to zero. The intent is that the descriptor
233 * will be updated/completed at runtime via a BufferField.
235 * If the descriptor does NOT have a resource tag, it cannot be referenced
236 * by a BufferField and we will flag this as an error. Conversely, if
237 * the descriptor has a resource tag, we will assume that a BufferField
238 * will be used to dynamically update it, so no error.
240 * A possible enhancement to this check would be to verify that in fact
241 * a BufferField is created using the resource tag, and perhaps even
242 * verify that a Store is performed to the BufferField.
244 if (!Minimum && !Maximum && !Length && !Granularity)
246 if (!Op->Asl.ExternalName)
248 /* No resource tag. Descriptor is fixed and is also illegal */
250 AslError (ASL_ERROR, ASL_MSG_NULL_DESCRIPTOR, Op, NULL);
256 /* Basic checks on Min/Max/Length */
258 if (Minimum > Maximum)
260 AslError (ASL_ERROR, ASL_MSG_INVALID_MIN_MAX, MinOp, NULL);
263 else if (Length > (Maximum - Minimum + 1))
265 AslError (ASL_ERROR, ASL_MSG_INVALID_LENGTH, LengthOp, NULL);
269 /* If specified (non-zero), ensure granularity is a power-of-two minus one */
273 if ((Granularity + 1) &
276 AslError (ASL_ERROR, ASL_MSG_INVALID_GRANULARITY, GranOp, NULL);
282 * Check the various combinations of Length, MinFixed, and MaxFixed
286 /* Fixed non-zero length */
288 switch (Flags & (ACPI_RESOURCE_FLAG_MIF | ACPI_RESOURCE_FLAG_MAF))
292 * Fixed length, variable locations (both _MIN and _MAX).
293 * Length must be a multiple of granularity
295 if (Granularity & Length)
297 AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, LengthOp, NULL);
301 case (ACPI_RESOURCE_FLAG_MIF | ACPI_RESOURCE_FLAG_MAF):
303 /* Fixed length, fixed location. Granularity must be zero */
305 if (Granularity != 0)
307 AslError (ASL_ERROR, ASL_MSG_INVALID_GRAN_FIXED, GranOp, NULL);
310 /* Length must be exactly the size of the min/max window */
312 if (Length != (Maximum - Minimum + 1))
314 AslError (ASL_ERROR, ASL_MSG_INVALID_LENGTH_FIXED, LengthOp, NULL);
318 /* All other combinations are invalid */
320 case ACPI_RESOURCE_FLAG_MIF:
321 case ACPI_RESOURCE_FLAG_MAF:
323 AslError (ASL_ERROR, ASL_MSG_INVALID_ADDR_FLAGS, LengthOp, NULL);
328 /* Variable length (length==0) */
330 switch (Flags & (ACPI_RESOURCE_FLAG_MIF | ACPI_RESOURCE_FLAG_MAF))
334 * Both _MIN and _MAX are variable.
335 * No additional requirements, just exit
339 case ACPI_RESOURCE_FLAG_MIF:
341 /* _MIN is fixed. _MIN must be multiple of _GRA */
344 * The granularity is defined by the ACPI specification to be a
345 * power-of-two minus one, therefore the granularity is a
346 * bitmask which can be used to easily validate the addresses.
348 if (Granularity & Minimum)
350 AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, MinOp, NULL);
354 case ACPI_RESOURCE_FLAG_MAF:
356 /* _MAX is fixed. (_MAX + 1) must be multiple of _GRA */
358 if (Granularity & (Maximum + 1))
360 AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, MaxOp, "-1");
364 /* Both MIF/MAF set is invalid if length is zero */
366 case (ACPI_RESOURCE_FLAG_MIF | ACPI_RESOURCE_FLAG_MAF):
368 AslError (ASL_ERROR, ASL_MSG_INVALID_ADDR_FLAGS, LengthOp, NULL);
374 /*******************************************************************************
376 * FUNCTION: RsGetStringDataLength
378 * PARAMETERS: InitializerOp - Start of a subtree of init nodes
380 * RETURN: Valid string length if a string node is found (otherwise 0)
382 * DESCRIPTION: In a list of peer nodes, find the first one that contains a
383 * string and return the length of the string.
385 ******************************************************************************/
388 RsGetStringDataLength (
389 ACPI_PARSE_OBJECT *InitializerOp)
392 while (InitializerOp)
394 if (InitializerOp->Asl.ParseOpcode == PARSEOP_STRING_LITERAL)
396 return ((UINT16) (strlen (InitializerOp->Asl.Value.String) + 1));
398 InitializerOp = ASL_GET_PEER_NODE (InitializerOp);
405 /*******************************************************************************
407 * FUNCTION: RsAllocateResourceNode
409 * PARAMETERS: Size - Size of node in bytes
411 * RETURN: The allocated node - aborts on allocation failure
413 * DESCRIPTION: Allocate a resource description node and the resource
414 * descriptor itself (the nodes are used to link descriptors).
416 ******************************************************************************/
419 RsAllocateResourceNode (
422 ASL_RESOURCE_NODE *Rnode;
425 /* Allocate the node */
427 Rnode = UtLocalCalloc (sizeof (ASL_RESOURCE_NODE));
429 /* Allocate the resource descriptor itself */
431 Rnode->Buffer = UtLocalCalloc (Size);
432 Rnode->BufferLength = Size;
438 /*******************************************************************************
440 * FUNCTION: RsCreateBitField
442 * PARAMETERS: Op - Resource field node
443 * Name - Name of the field (Used only to reference
444 * the field in the ASL, not in the AML)
445 * ByteOffset - Offset from the field start
446 * BitOffset - Additional bit offset
448 * RETURN: None, sets fields within the input node
450 * DESCRIPTION: Utility function to generate a named bit field within a
451 * resource descriptor. Mark a node as 1) a field in a resource
452 * descriptor, and 2) set the value to be a BIT offset
454 ******************************************************************************/
458 ACPI_PARSE_OBJECT *Op,
464 Op->Asl.ExternalName = Name;
465 Op->Asl.Value.Integer = ((UINT64) ByteOffset * 8) + BitOffset;
466 Op->Asl.CompileFlags |= (NODE_IS_RESOURCE_FIELD | NODE_IS_BIT_OFFSET);
470 /*******************************************************************************
472 * FUNCTION: RsCreateByteField
474 * PARAMETERS: Op - Resource field node
475 * Name - Name of the field (Used only to reference
476 * the field in the ASL, not in the AML)
477 * ByteOffset - Offset from the field start
479 * RETURN: None, sets fields within the input node
481 * DESCRIPTION: Utility function to generate a named byte field within a
482 * resource descriptor. Mark a node as 1) a field in a resource
483 * descriptor, and 2) set the value to be a BYTE offset
485 ******************************************************************************/
489 ACPI_PARSE_OBJECT *Op,
494 Op->Asl.ExternalName = Name;
495 Op->Asl.Value.Integer = ByteOffset;
496 Op->Asl.CompileFlags |= NODE_IS_RESOURCE_FIELD;
500 /*******************************************************************************
502 * FUNCTION: RsSetFlagBits
504 * PARAMETERS: *Flags - Pointer to the flag byte
505 * Op - Flag initialization node
506 * Position - Bit position within the flag byte
507 * Default - Used if the node is DEFAULT.
509 * RETURN: Sets bits within the *Flags output byte.
511 * DESCRIPTION: Set a bit in a cumulative flags word from an initialization
512 * node. Will use a default value if the node is DEFAULT, meaning
513 * that no value was specified in the ASL. Used to merge multiple
514 * keywords into a single flags byte.
516 ******************************************************************************/
521 ACPI_PARSE_OBJECT *Op,
526 if (Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)
528 /* Use the default bit */
530 *Flags |= (DefaultBit << Position);
534 /* Use the bit specified in the initialization node */
536 *Flags |= (((UINT8) Op->Asl.Value.Integer) << Position);
541 /*******************************************************************************
543 * FUNCTION: RsCompleteNodeAndGetNext
545 * PARAMETERS: Op - Resource node to be completed
547 * RETURN: The next peer to the input node.
549 * DESCRIPTION: Mark the current node completed and return the next peer.
550 * The node ParseOpcode is set to DEFAULT_ARG, meaning that
551 * this node is to be ignored from now on.
553 ******************************************************************************/
556 RsCompleteNodeAndGetNext (
557 ACPI_PARSE_OBJECT *Op)
560 /* Mark this node unused */
562 Op->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
564 /* Move on to the next peer node in the initializer list */
566 return (ASL_GET_PEER_NODE (Op));
570 /*******************************************************************************
572 * FUNCTION: RsCheckListForDuplicates
574 * PARAMETERS: Op - First op in the initializer list
578 * DESCRIPTION: Check an initializer list for duplicate values. Emits an error
579 * if any duplicates are found.
581 ******************************************************************************/
584 RsCheckListForDuplicates (
585 ACPI_PARSE_OBJECT *Op)
587 ACPI_PARSE_OBJECT *NextValueOp = Op;
588 ACPI_PARSE_OBJECT *NextOp;
597 /* Search list once for each value in the list */
601 Value = (UINT32) NextValueOp->Asl.Value.Integer;
603 /* Compare this value to all remaining values in the list */
605 NextOp = ASL_GET_PEER_NODE (NextValueOp);
608 if (NextOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
612 if (Value == (UINT32) NextOp->Asl.Value.Integer)
614 /* Emit error only once per duplicate node */
616 if (!(NextOp->Asl.CompileFlags & NODE_IS_DUPLICATE))
618 NextOp->Asl.CompileFlags |= NODE_IS_DUPLICATE;
619 AslError (ASL_ERROR, ASL_MSG_DUPLICATE_ITEM,
625 NextOp = ASL_GET_PEER_NODE (NextOp);
628 NextValueOp = ASL_GET_PEER_NODE (NextValueOp);
633 /*******************************************************************************
635 * FUNCTION: RsDoOneResourceDescriptor
637 * PARAMETERS: DescriptorTypeOp - Parent parse node of the descriptor
638 * CurrentByteOffset - Offset in the resource descriptor
641 * RETURN: A valid resource node for the descriptor
643 * DESCRIPTION: Dispatches the processing of one resource descriptor
645 ******************************************************************************/
648 RsDoOneResourceDescriptor (
649 ACPI_PARSE_OBJECT *DescriptorTypeOp,
650 UINT32 CurrentByteOffset,
653 ASL_RESOURCE_NODE *Rnode = NULL;
656 /* Construct the resource */
658 switch (DescriptorTypeOp->Asl.ParseOpcode)
661 Rnode = RsDoDmaDescriptor (DescriptorTypeOp,
665 case PARSEOP_DWORDIO:
666 Rnode = RsDoDwordIoDescriptor (DescriptorTypeOp,
670 case PARSEOP_DWORDMEMORY:
671 Rnode = RsDoDwordMemoryDescriptor (DescriptorTypeOp,
675 case PARSEOP_DWORDSPACE:
676 Rnode = RsDoDwordSpaceDescriptor (DescriptorTypeOp,
680 case PARSEOP_ENDDEPENDENTFN:
683 case ACPI_RSTATE_NORMAL:
684 AslError (ASL_ERROR, ASL_MSG_MISSING_STARTDEPENDENT,
685 DescriptorTypeOp, NULL);
688 case ACPI_RSTATE_START_DEPENDENT:
689 AslError (ASL_ERROR, ASL_MSG_DEPENDENT_NESTING,
690 DescriptorTypeOp, NULL);
693 case ACPI_RSTATE_DEPENDENT_LIST:
698 *State = ACPI_RSTATE_NORMAL;
699 Rnode = RsDoEndDependentDescriptor (DescriptorTypeOp,
704 Rnode = RsDoEndTagDescriptor (DescriptorTypeOp,
708 case PARSEOP_EXTENDEDIO:
709 Rnode = RsDoExtendedIoDescriptor (DescriptorTypeOp,
713 case PARSEOP_EXTENDEDMEMORY:
714 Rnode = RsDoExtendedMemoryDescriptor (DescriptorTypeOp,
718 case PARSEOP_EXTENDEDSPACE:
719 Rnode = RsDoExtendedSpaceDescriptor (DescriptorTypeOp,
723 case PARSEOP_FIXEDIO:
724 Rnode = RsDoFixedIoDescriptor (DescriptorTypeOp,
728 case PARSEOP_INTERRUPT:
729 Rnode = RsDoInterruptDescriptor (DescriptorTypeOp,
734 Rnode = RsDoIoDescriptor (DescriptorTypeOp,
739 Rnode = RsDoIrqDescriptor (DescriptorTypeOp,
743 case PARSEOP_IRQNOFLAGS:
744 Rnode = RsDoIrqNoFlagsDescriptor (DescriptorTypeOp,
748 case PARSEOP_MEMORY24:
749 Rnode = RsDoMemory24Descriptor (DescriptorTypeOp,
753 case PARSEOP_MEMORY32:
754 Rnode = RsDoMemory32Descriptor (DescriptorTypeOp,
758 case PARSEOP_MEMORY32FIXED:
759 Rnode = RsDoMemory32FixedDescriptor (DescriptorTypeOp,
763 case PARSEOP_QWORDIO:
764 Rnode = RsDoQwordIoDescriptor (DescriptorTypeOp,
768 case PARSEOP_QWORDMEMORY:
769 Rnode = RsDoQwordMemoryDescriptor (DescriptorTypeOp,
773 case PARSEOP_QWORDSPACE:
774 Rnode = RsDoQwordSpaceDescriptor (DescriptorTypeOp,
778 case PARSEOP_REGISTER:
779 Rnode = RsDoGeneralRegisterDescriptor (DescriptorTypeOp,
783 case PARSEOP_STARTDEPENDENTFN:
786 case ACPI_RSTATE_START_DEPENDENT:
787 AslError (ASL_ERROR, ASL_MSG_DEPENDENT_NESTING,
788 DescriptorTypeOp, NULL);
791 case ACPI_RSTATE_NORMAL:
792 case ACPI_RSTATE_DEPENDENT_LIST:
797 *State = ACPI_RSTATE_START_DEPENDENT;
798 Rnode = RsDoStartDependentDescriptor (DescriptorTypeOp,
800 *State = ACPI_RSTATE_DEPENDENT_LIST;
803 case PARSEOP_STARTDEPENDENTFN_NOPRI:
806 case ACPI_RSTATE_START_DEPENDENT:
807 AslError (ASL_ERROR, ASL_MSG_DEPENDENT_NESTING,
808 DescriptorTypeOp, NULL);
811 case ACPI_RSTATE_NORMAL:
812 case ACPI_RSTATE_DEPENDENT_LIST:
817 *State = ACPI_RSTATE_START_DEPENDENT;
818 Rnode = RsDoStartDependentNoPriDescriptor (DescriptorTypeOp,
820 *State = ACPI_RSTATE_DEPENDENT_LIST;
823 case PARSEOP_VENDORLONG:
824 Rnode = RsDoVendorLargeDescriptor (DescriptorTypeOp,
828 case PARSEOP_VENDORSHORT:
829 Rnode = RsDoVendorSmallDescriptor (DescriptorTypeOp,
833 case PARSEOP_WORDBUSNUMBER:
834 Rnode = RsDoWordBusNumberDescriptor (DescriptorTypeOp,
839 Rnode = RsDoWordIoDescriptor (DescriptorTypeOp,
843 case PARSEOP_WORDSPACE:
844 Rnode = RsDoWordSpaceDescriptor (DescriptorTypeOp,
848 case PARSEOP_DEFAULT_ARG:
849 /* Just ignore any of these, they are used as fillers/placeholders */
853 printf ("Unknown resource descriptor type [%s]\n",
854 DescriptorTypeOp->Asl.ParseOpName);
859 * Mark original node as unused, but head of a resource descriptor.
860 * This allows the resource to be installed in the namespace so that
861 * references to the descriptor can be resolved.
863 DescriptorTypeOp->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
864 DescriptorTypeOp->Asl.CompileFlags = NODE_IS_RESOURCE_DESC;
865 DescriptorTypeOp->Asl.Value.Integer = CurrentByteOffset;
869 DescriptorTypeOp->Asl.FinalAmlLength = Rnode->BufferLength;
876 /*******************************************************************************
878 * FUNCTION: RsLinkDescriptorChain
880 * PARAMETERS: PreviousRnode - Pointer to the node that will be previous
881 * to the linked node, At exit, set to the
882 * last node in the new chain.
883 * Rnode - Resource node to link into the list
885 * RETURN: Cumulative buffer byte offset of the new segment of chain
887 * DESCRIPTION: Link a descriptor chain at the end of an existing chain.
889 ******************************************************************************/
892 RsLinkDescriptorChain (
893 ASL_RESOURCE_NODE **PreviousRnode,
894 ASL_RESOURCE_NODE *Rnode)
896 ASL_RESOURCE_NODE *LastRnode;
897 UINT32 CurrentByteOffset;
900 /* Anything to do? */
907 /* Point the previous node to the new node */
909 (*PreviousRnode)->Next = Rnode;
910 CurrentByteOffset = Rnode->BufferLength;
912 /* Walk to the end of the chain headed by Rnode */
915 while (LastRnode->Next)
917 LastRnode = LastRnode->Next;
918 CurrentByteOffset += LastRnode->BufferLength;
921 /* Previous node becomes the last node in the chain */
923 *PreviousRnode = LastRnode;
924 return CurrentByteOffset;
928 /*******************************************************************************
930 * FUNCTION: RsDoResourceTemplate
932 * PARAMETERS: Op - Parent of a resource template list
934 * RETURN: None. Sets input node to point to a list of AML code
936 * DESCRIPTION: Merge a list of resource descriptors into a single AML buffer,
937 * in preparation for output to the AML output file.
939 ******************************************************************************/
942 RsDoResourceTemplate (
943 ACPI_PARSE_OBJECT *Op)
945 ACPI_PARSE_OBJECT *BufferLengthOp;
946 ACPI_PARSE_OBJECT *BufferOp;
947 ACPI_PARSE_OBJECT *DescriptorTypeOp;
948 ACPI_PARSE_OBJECT *LastOp = NULL;
949 UINT32 CurrentByteOffset = 0;
950 ASL_RESOURCE_NODE HeadRnode;
951 ASL_RESOURCE_NODE *PreviousRnode;
952 ASL_RESOURCE_NODE *Rnode;
956 /* Mark parent as containing a resource template */
960 Op->Asl.Parent->Asl.CompileFlags |= NODE_IS_RESOURCE_DESC;
963 /* ResourceTemplate Opcode is first (Op) */
964 /* Buffer Length node is first child */
966 BufferLengthOp = ASL_GET_CHILD_NODE (Op);
968 /* Buffer Op is first peer */
970 BufferOp = ASL_GET_PEER_NODE (BufferLengthOp);
972 /* First Descriptor type is next */
974 DescriptorTypeOp = ASL_GET_PEER_NODE (BufferOp);
977 * Process all resource descriptors in the list
978 * Note: It is assumed that the EndTag node has been automatically
979 * inserted at the end of the template by the parser.
981 State = ACPI_RSTATE_NORMAL;
982 PreviousRnode = &HeadRnode;
983 while (DescriptorTypeOp)
985 DescriptorTypeOp->Asl.CompileFlags |= NODE_IS_RESOURCE_DESC;
986 Rnode = RsDoOneResourceDescriptor (DescriptorTypeOp, CurrentByteOffset,
990 * Update current byte offset to indicate the number of bytes from the
991 * start of the buffer. Buffer can include multiple descriptors, we
992 * must keep track of the offset of not only each descriptor, but each
993 * element (field) within each descriptor as well.
995 CurrentByteOffset += RsLinkDescriptorChain (&PreviousRnode, Rnode);
997 /* Get the next descriptor in the list */
999 LastOp = DescriptorTypeOp;
1000 DescriptorTypeOp = ASL_GET_PEER_NODE (DescriptorTypeOp);
1003 if (State == ACPI_RSTATE_DEPENDENT_LIST)
1007 LastOp = LastOp->Asl.Parent;
1009 AslError (ASL_ERROR, ASL_MSG_MISSING_ENDDEPENDENT, LastOp, NULL);
1013 * Transform the nodes into the following
1015 * Op -> AML_BUFFER_OP
1016 * First Child -> BufferLength
1017 * Second Child -> Descriptor Buffer (raw byte data)
1019 Op->Asl.ParseOpcode = PARSEOP_BUFFER;
1020 Op->Asl.AmlOpcode = AML_BUFFER_OP;
1021 Op->Asl.CompileFlags = NODE_AML_PACKAGE | NODE_IS_RESOURCE_DESC;
1023 BufferLengthOp->Asl.ParseOpcode = PARSEOP_INTEGER;
1024 BufferLengthOp->Asl.Value.Integer = CurrentByteOffset;
1025 (void) OpcSetOptimalIntegerSize (BufferLengthOp);
1027 BufferOp->Asl.ParseOpcode = PARSEOP_RAW_DATA;
1028 BufferOp->Asl.AmlOpcode = AML_RAW_DATA_CHAIN;
1029 BufferOp->Asl.AmlOpcodeLength = 0;
1030 BufferOp->Asl.AmlLength = CurrentByteOffset;
1031 BufferOp->Asl.Value.Buffer = (UINT8 *) HeadRnode.Next;
1032 BufferOp->Asl.CompileFlags |= NODE_IS_RESOURCE_DATA;