1 /******************************************************************************
3 * Module Name: aslresource - Resource template/descriptor utilities
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2015, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #include "aslcompiler.h"
45 #include "aslcompiler.y.h"
49 #define _COMPONENT ACPI_COMPILER
50 ACPI_MODULE_NAME ("aslresource")
53 /*******************************************************************************
55 * FUNCTION: RsSmallAddressCheck
57 * PARAMETERS: Minimum - Address Min value
58 * Maximum - Address Max value
59 * Length - Address range value
60 * Alignment - Address alignment value
61 * MinOp - Original Op for Address Min
62 * MaxOp - Original Op for Address Max
63 * LengthOp - Original Op for address range
64 * AlignOp - Original Op for address alignment. If
65 * NULL, means "zero value for alignment is
66 * OK, and means 64K alignment" (for
67 * Memory24 descriptor)
68 * Op - Parent Op for entire construct
70 * RETURN: None. Adds error messages to error log if necessary
72 * DESCRIPTION: Perform common value checks for "small" address descriptors.
74 * Io, Memory24, Memory32
76 ******************************************************************************/
85 ACPI_PARSE_OBJECT *MinOp,
86 ACPI_PARSE_OBJECT *MaxOp,
87 ACPI_PARSE_OBJECT *LengthOp,
88 ACPI_PARSE_OBJECT *AlignOp,
89 ACPI_PARSE_OBJECT *Op)
92 if (Gbl_NoResourceChecking)
98 * Check for a so-called "null descriptor". These are descriptors that are
99 * created with most fields set to zero. The intent is that the descriptor
100 * will be updated/completed at runtime via a BufferField.
102 * If the descriptor does NOT have a resource tag, it cannot be referenced
103 * by a BufferField and we will flag this as an error. Conversely, if
104 * the descriptor has a resource tag, we will assume that a BufferField
105 * will be used to dynamically update it, so no error.
107 * A possible enhancement to this check would be to verify that in fact
108 * a BufferField is created using the resource tag, and perhaps even
109 * verify that a Store is performed to the BufferField.
111 * Note: for these descriptors, Alignment is allowed to be zero
113 if (!Minimum && !Maximum && !Length)
115 if (!Op->Asl.ExternalName)
117 /* No resource tag. Descriptor is fixed and is also illegal */
119 AslError (ASL_ERROR, ASL_MSG_NULL_DESCRIPTOR, Op, NULL);
126 * Range checks for Memory24 and Memory32.
127 * IO descriptor has different definition of min/max, don't check.
129 if (Type != ACPI_RESOURCE_NAME_IO)
131 /* Basic checks on Min/Max/Length */
133 if (Minimum > Maximum)
135 AslError (ASL_ERROR, ASL_MSG_INVALID_MIN_MAX, MinOp, NULL);
137 else if (Length > (Maximum - Minimum + 1))
139 AslError (ASL_ERROR, ASL_MSG_INVALID_LENGTH, LengthOp, NULL);
142 /* Special case for Memory24, min/max values are compressed */
144 if (Type == ACPI_RESOURCE_NAME_MEMORY24)
146 if (!Alignment) /* Alignment==0 means 64K alignment */
148 Alignment = ACPI_UINT16_MAX + 1;
156 /* Alignment of zero is not in ACPI spec, but is used to mean byte acc */
163 /* Addresses must be an exact multiple of the alignment value */
165 if (Minimum % Alignment)
167 AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, MinOp, NULL);
169 if (Maximum % Alignment)
171 AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, MaxOp, NULL);
176 /*******************************************************************************
178 * FUNCTION: RsLargeAddressCheck
180 * PARAMETERS: Minimum - Address Min value
181 * Maximum - Address Max value
182 * Length - Address range value
183 * Granularity - Address granularity value
184 * Flags - General flags for address descriptors:
186 * MinOp - Original Op for Address Min
187 * MaxOp - Original Op for Address Max
188 * LengthOp - Original Op for address range
189 * GranOp - Original Op for address granularity
190 * Op - Parent Op for entire construct
192 * RETURN: None. Adds error messages to error log if necessary
194 * DESCRIPTION: Perform common value checks for "large" address descriptors.
196 * WordIo, WordBusNumber, WordSpace
197 * DWordIo, DWordMemory, DWordSpace
198 * QWordIo, QWordMemory, QWordSpace
199 * ExtendedIo, ExtendedMemory, ExtendedSpace
201 * _MIF flag set means that the minimum address is fixed and is not relocatable
202 * _MAF flag set means that the maximum address is fixed and is not relocatable
203 * Length of zero means that the record size is variable
205 * This function implements the LEN/MIF/MAF/MIN/MAX/GRA rules within Table 6-40
206 * of the ACPI 4.0a specification. Added 04/2010.
208 ******************************************************************************/
211 RsLargeAddressCheck (
217 ACPI_PARSE_OBJECT *MinOp,
218 ACPI_PARSE_OBJECT *MaxOp,
219 ACPI_PARSE_OBJECT *LengthOp,
220 ACPI_PARSE_OBJECT *GranOp,
221 ACPI_PARSE_OBJECT *Op)
224 if (Gbl_NoResourceChecking)
230 * Check for a so-called "null descriptor". These are descriptors that are
231 * created with most fields set to zero. The intent is that the descriptor
232 * will be updated/completed at runtime via a BufferField.
234 * If the descriptor does NOT have a resource tag, it cannot be referenced
235 * by a BufferField and we will flag this as an error. Conversely, if
236 * the descriptor has a resource tag, we will assume that a BufferField
237 * will be used to dynamically update it, so no error.
239 * A possible enhancement to this check would be to verify that in fact
240 * a BufferField is created using the resource tag, and perhaps even
241 * verify that a Store is performed to the BufferField.
243 if (!Minimum && !Maximum && !Length && !Granularity)
245 if (!Op->Asl.ExternalName)
247 /* No resource tag. Descriptor is fixed and is also illegal */
249 AslError (ASL_ERROR, ASL_MSG_NULL_DESCRIPTOR, Op, NULL);
255 /* Basic checks on Min/Max/Length */
257 if (Minimum > Maximum)
259 AslError (ASL_ERROR, ASL_MSG_INVALID_MIN_MAX, MinOp, NULL);
262 else if (Length > (Maximum - Minimum + 1))
264 AslError (ASL_ERROR, ASL_MSG_INVALID_LENGTH, LengthOp, NULL);
268 /* If specified (non-zero), ensure granularity is a power-of-two minus one */
272 if ((Granularity + 1) &
275 AslError (ASL_ERROR, ASL_MSG_INVALID_GRANULARITY, GranOp, NULL);
281 * Check the various combinations of Length, MinFixed, and MaxFixed
285 /* Fixed non-zero length */
287 switch (Flags & (ACPI_RESOURCE_FLAG_MIF | ACPI_RESOURCE_FLAG_MAF))
291 * Fixed length, variable locations (both _MIN and _MAX).
292 * Length must be a multiple of granularity
294 if (Granularity & Length)
296 AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, LengthOp, NULL);
300 case (ACPI_RESOURCE_FLAG_MIF | ACPI_RESOURCE_FLAG_MAF):
302 /* Fixed length, fixed location. Granularity must be zero */
304 if (Granularity != 0)
306 AslError (ASL_ERROR, ASL_MSG_INVALID_GRAN_FIXED, GranOp, NULL);
309 /* Length must be exactly the size of the min/max window */
311 if (Length != (Maximum - Minimum + 1))
313 AslError (ASL_ERROR, ASL_MSG_INVALID_LENGTH_FIXED, LengthOp, NULL);
317 /* All other combinations are invalid */
319 case ACPI_RESOURCE_FLAG_MIF:
320 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):
369 AslError (ASL_ERROR, ASL_MSG_INVALID_ADDR_FLAGS, LengthOp, NULL);
375 /*******************************************************************************
377 * FUNCTION: RsGetStringDataLength
379 * PARAMETERS: InitializerOp - Start of a subtree of init nodes
381 * RETURN: Valid string length if a string node is found (otherwise 0)
383 * DESCRIPTION: In a list of peer nodes, find the first one that contains a
384 * string and return the length of the string.
386 ******************************************************************************/
389 RsGetStringDataLength (
390 ACPI_PARSE_OBJECT *InitializerOp)
393 while (InitializerOp)
395 if (InitializerOp->Asl.ParseOpcode == PARSEOP_STRING_LITERAL)
397 return ((UINT16) (strlen (InitializerOp->Asl.Value.String) + 1));
400 InitializerOp = ASL_GET_PEER_NODE (InitializerOp);
407 /*******************************************************************************
409 * FUNCTION: RsAllocateResourceNode
411 * PARAMETERS: Size - Size of node in bytes
413 * RETURN: The allocated node - aborts on allocation failure
415 * DESCRIPTION: Allocate a resource description node and the resource
416 * descriptor itself (the nodes are used to link descriptors).
418 ******************************************************************************/
421 RsAllocateResourceNode (
424 ASL_RESOURCE_NODE *Rnode;
427 /* Allocate the node */
429 Rnode = UtLocalCalloc (sizeof (ASL_RESOURCE_NODE));
431 /* Allocate the resource descriptor itself */
433 Rnode->Buffer = UtLocalCalloc (Size);
434 Rnode->BufferLength = Size;
439 /*******************************************************************************
441 * FUNCTION: RsCreateResourceField
443 * PARAMETERS: Op - Resource field node
444 * Name - Name of the field (Used only to reference
445 * the field in the ASL, not in the AML)
446 * ByteOffset - Offset from the field start
447 * BitOffset - Additional bit offset
448 * BitLength - Number of bits in the field
450 * RETURN: None, sets fields within the input node
452 * DESCRIPTION: Utility function to generate a named bit field within a
453 * resource descriptor. Mark a node as 1) a field in a resource
454 * descriptor, and 2) set the value to be a BIT offset
456 ******************************************************************************/
459 RsCreateResourceField (
460 ACPI_PARSE_OBJECT *Op,
467 Op->Asl.ExternalName = Name;
468 Op->Asl.CompileFlags |= NODE_IS_RESOURCE_FIELD;
470 Op->Asl.Value.Tag.BitOffset = (ByteOffset * 8) + BitOffset;
471 Op->Asl.Value.Tag.BitLength = BitLength;
475 /*******************************************************************************
477 * FUNCTION: RsSetFlagBits
479 * PARAMETERS: *Flags - Pointer to the flag byte
480 * Op - Flag initialization node
481 * Position - Bit position within the flag byte
482 * Default - Used if the node is DEFAULT.
484 * RETURN: Sets bits within the *Flags output byte.
486 * DESCRIPTION: Set a bit in a cumulative flags word from an initialization
487 * node. Will use a default value if the node is DEFAULT, meaning
488 * that no value was specified in the ASL. Used to merge multiple
489 * keywords into a single flags byte.
491 ******************************************************************************/
496 ACPI_PARSE_OBJECT *Op,
501 if (Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)
503 /* Use the default bit */
505 *Flags |= (DefaultBit << Position);
509 /* Use the bit specified in the initialization node */
511 *Flags |= (((UINT8) Op->Asl.Value.Integer) << Position);
519 ACPI_PARSE_OBJECT *Op,
524 if (Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)
526 /* Use the default bit */
528 *Flags |= (DefaultBit << Position);
532 /* Use the bit specified in the initialization node */
534 *Flags |= (((UINT16) Op->Asl.Value.Integer) << Position);
539 /*******************************************************************************
541 * FUNCTION: RsCompleteNodeAndGetNext
543 * PARAMETERS: Op - Resource node to be completed
545 * RETURN: The next peer to the input node.
547 * DESCRIPTION: Mark the current node completed and return the next peer.
548 * The node ParseOpcode is set to DEFAULT_ARG, meaning that
549 * this node is to be ignored from now on.
551 ******************************************************************************/
554 RsCompleteNodeAndGetNext (
555 ACPI_PARSE_OBJECT *Op)
558 /* Mark this node unused */
560 Op->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
562 /* Move on to the next peer node in the initializer list */
564 return (ASL_GET_PEER_NODE (Op));
568 /*******************************************************************************
570 * FUNCTION: RsCheckListForDuplicates
572 * PARAMETERS: Op - First op in the initializer list
576 * DESCRIPTION: Check an initializer list for duplicate values. Emits an error
577 * if any duplicates are found.
579 ******************************************************************************/
582 RsCheckListForDuplicates (
583 ACPI_PARSE_OBJECT *Op)
585 ACPI_PARSE_OBJECT *NextValueOp = Op;
586 ACPI_PARSE_OBJECT *NextOp;
595 /* Search list once for each value in the list */
599 Value = (UINT32) NextValueOp->Asl.Value.Integer;
601 /* Compare this value to all remaining values in the list */
603 NextOp = ASL_GET_PEER_NODE (NextValueOp);
606 if (NextOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
610 if (Value == (UINT32) NextOp->Asl.Value.Integer)
612 /* Emit error only once per duplicate node */
614 if (!(NextOp->Asl.CompileFlags & NODE_IS_DUPLICATE))
616 NextOp->Asl.CompileFlags |= NODE_IS_DUPLICATE;
617 AslError (ASL_ERROR, ASL_MSG_DUPLICATE_ITEM,
623 NextOp = ASL_GET_PEER_NODE (NextOp);
626 NextValueOp = ASL_GET_PEER_NODE (NextValueOp);
631 /*******************************************************************************
633 * FUNCTION: RsDoOneResourceDescriptor
635 * PARAMETERS: DescriptorTypeOp - Parent parse node of the descriptor
636 * CurrentByteOffset - Offset in the resource descriptor
639 * RETURN: A valid resource node for the descriptor
641 * DESCRIPTION: Dispatches the processing of one resource descriptor
643 ******************************************************************************/
646 RsDoOneResourceDescriptor (
647 ASL_RESOURCE_INFO *Info,
650 ASL_RESOURCE_NODE *Rnode = NULL;
653 /* Construct the resource */
655 switch (Info->DescriptorTypeOp->Asl.ParseOpcode)
659 Rnode = RsDoDmaDescriptor (Info);
662 case PARSEOP_FIXEDDMA:
664 Rnode = RsDoFixedDmaDescriptor (Info);
667 case PARSEOP_DWORDIO:
669 Rnode = RsDoDwordIoDescriptor (Info);
672 case PARSEOP_DWORDMEMORY:
674 Rnode = RsDoDwordMemoryDescriptor (Info);
677 case PARSEOP_DWORDSPACE:
679 Rnode = RsDoDwordSpaceDescriptor (Info);
682 case PARSEOP_ENDDEPENDENTFN:
686 case ACPI_RSTATE_NORMAL:
688 AslError (ASL_ERROR, ASL_MSG_MISSING_STARTDEPENDENT,
689 Info->DescriptorTypeOp, NULL);
692 case ACPI_RSTATE_START_DEPENDENT:
694 AslError (ASL_ERROR, ASL_MSG_DEPENDENT_NESTING,
695 Info->DescriptorTypeOp, NULL);
698 case ACPI_RSTATE_DEPENDENT_LIST:
704 *State = ACPI_RSTATE_NORMAL;
705 Rnode = RsDoEndDependentDescriptor (Info);
710 Rnode = RsDoEndTagDescriptor (Info);
713 case PARSEOP_EXTENDEDIO:
715 Rnode = RsDoExtendedIoDescriptor (Info);
718 case PARSEOP_EXTENDEDMEMORY:
720 Rnode = RsDoExtendedMemoryDescriptor (Info);
723 case PARSEOP_EXTENDEDSPACE:
725 Rnode = RsDoExtendedSpaceDescriptor (Info);
728 case PARSEOP_FIXEDIO:
730 Rnode = RsDoFixedIoDescriptor (Info);
733 case PARSEOP_INTERRUPT:
735 Rnode = RsDoInterruptDescriptor (Info);
740 Rnode = RsDoIoDescriptor (Info);
745 Rnode = RsDoIrqDescriptor (Info);
748 case PARSEOP_IRQNOFLAGS:
750 Rnode = RsDoIrqNoFlagsDescriptor (Info);
753 case PARSEOP_MEMORY24:
755 Rnode = RsDoMemory24Descriptor (Info);
758 case PARSEOP_MEMORY32:
760 Rnode = RsDoMemory32Descriptor (Info);
763 case PARSEOP_MEMORY32FIXED:
765 Rnode = RsDoMemory32FixedDescriptor (Info);
768 case PARSEOP_QWORDIO:
770 Rnode = RsDoQwordIoDescriptor (Info);
773 case PARSEOP_QWORDMEMORY:
775 Rnode = RsDoQwordMemoryDescriptor (Info);
778 case PARSEOP_QWORDSPACE:
780 Rnode = RsDoQwordSpaceDescriptor (Info);
783 case PARSEOP_REGISTER:
785 Rnode = RsDoGeneralRegisterDescriptor (Info);
788 case PARSEOP_STARTDEPENDENTFN:
792 case ACPI_RSTATE_START_DEPENDENT:
794 AslError (ASL_ERROR, ASL_MSG_DEPENDENT_NESTING,
795 Info->DescriptorTypeOp, NULL);
798 case ACPI_RSTATE_NORMAL:
799 case ACPI_RSTATE_DEPENDENT_LIST:
805 *State = ACPI_RSTATE_START_DEPENDENT;
806 Rnode = RsDoStartDependentDescriptor (Info);
807 *State = ACPI_RSTATE_DEPENDENT_LIST;
810 case PARSEOP_STARTDEPENDENTFN_NOPRI:
814 case ACPI_RSTATE_START_DEPENDENT:
816 AslError (ASL_ERROR, ASL_MSG_DEPENDENT_NESTING,
817 Info->DescriptorTypeOp, NULL);
820 case ACPI_RSTATE_NORMAL:
821 case ACPI_RSTATE_DEPENDENT_LIST:
827 *State = ACPI_RSTATE_START_DEPENDENT;
828 Rnode = RsDoStartDependentNoPriDescriptor (Info);
829 *State = ACPI_RSTATE_DEPENDENT_LIST;
832 case PARSEOP_VENDORLONG:
834 Rnode = RsDoVendorLargeDescriptor (Info);
837 case PARSEOP_VENDORSHORT:
839 Rnode = RsDoVendorSmallDescriptor (Info);
842 case PARSEOP_WORDBUSNUMBER:
844 Rnode = RsDoWordBusNumberDescriptor (Info);
849 Rnode = RsDoWordIoDescriptor (Info);
852 case PARSEOP_WORDSPACE:
854 Rnode = RsDoWordSpaceDescriptor (Info);
857 case PARSEOP_GPIO_INT:
859 Rnode = RsDoGpioIntDescriptor (Info);
862 case PARSEOP_GPIO_IO:
864 Rnode = RsDoGpioIoDescriptor (Info);
867 case PARSEOP_I2C_SERIALBUS:
869 Rnode = RsDoI2cSerialBusDescriptor (Info);
872 case PARSEOP_SPI_SERIALBUS:
874 Rnode = RsDoSpiSerialBusDescriptor (Info);
877 case PARSEOP_UART_SERIALBUS:
879 Rnode = RsDoUartSerialBusDescriptor (Info);
882 case PARSEOP_DEFAULT_ARG:
884 /* Just ignore any of these, they are used as fillers/placeholders */
889 printf ("Unknown resource descriptor type [%s]\n",
890 Info->DescriptorTypeOp->Asl.ParseOpName);
895 * Mark original node as unused, but head of a resource descriptor.
896 * This allows the resource to be installed in the namespace so that
897 * references to the descriptor can be resolved.
899 Info->DescriptorTypeOp->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
900 Info->DescriptorTypeOp->Asl.CompileFlags = NODE_IS_RESOURCE_DESC;
901 Info->DescriptorTypeOp->Asl.Value.Integer = Info->CurrentByteOffset;
905 Info->DescriptorTypeOp->Asl.FinalAmlLength = Rnode->BufferLength;
906 Info->DescriptorTypeOp->Asl.Extra =
907 ((AML_RESOURCE *) Rnode->Buffer)->DescriptorType;
914 /*******************************************************************************
916 * FUNCTION: RsLinkDescriptorChain
918 * PARAMETERS: PreviousRnode - Pointer to the node that will be previous
919 * to the linked node, At exit, set to the
920 * last node in the new chain.
921 * Rnode - Resource node to link into the list
923 * RETURN: Cumulative buffer byte offset of the new segment of chain
925 * DESCRIPTION: Link a descriptor chain at the end of an existing chain.
927 ******************************************************************************/
930 RsLinkDescriptorChain (
931 ASL_RESOURCE_NODE **PreviousRnode,
932 ASL_RESOURCE_NODE *Rnode)
934 ASL_RESOURCE_NODE *LastRnode;
935 UINT32 CurrentByteOffset;
938 /* Anything to do? */
945 /* Point the previous node to the new node */
947 (*PreviousRnode)->Next = Rnode;
948 CurrentByteOffset = Rnode->BufferLength;
950 /* Walk to the end of the chain headed by Rnode */
953 while (LastRnode->Next)
955 LastRnode = LastRnode->Next;
956 CurrentByteOffset += LastRnode->BufferLength;
959 /* Previous node becomes the last node in the chain */
961 *PreviousRnode = LastRnode;
962 return (CurrentByteOffset);
966 /*******************************************************************************
968 * FUNCTION: RsDoResourceTemplate
970 * PARAMETERS: Op - Parent of a resource template list
972 * RETURN: None. Sets input node to point to a list of AML code
974 * DESCRIPTION: Merge a list of resource descriptors into a single AML buffer,
975 * in preparation for output to the AML output file.
977 ******************************************************************************/
980 RsDoResourceTemplate (
981 ACPI_PARSE_OBJECT *Op)
983 ACPI_PARSE_OBJECT *BufferLengthOp;
984 ACPI_PARSE_OBJECT *BufferOp;
985 ACPI_PARSE_OBJECT *DescriptorTypeOp;
986 ACPI_PARSE_OBJECT *LastOp = NULL;
987 UINT32 CurrentByteOffset = 0;
988 ASL_RESOURCE_NODE HeadRnode;
989 ASL_RESOURCE_NODE *PreviousRnode;
990 ASL_RESOURCE_NODE *Rnode;
991 ASL_RESOURCE_INFO Info;
995 /* Mark parent as containing a resource template */
999 Op->Asl.Parent->Asl.CompileFlags |= NODE_IS_RESOURCE_DESC;
1002 /* ResourceTemplate Opcode is first (Op) */
1003 /* Buffer Length node is first child */
1005 BufferLengthOp = ASL_GET_CHILD_NODE (Op);
1007 /* Buffer Op is first peer */
1009 BufferOp = ASL_GET_PEER_NODE (BufferLengthOp);
1011 /* First Descriptor type is next */
1013 DescriptorTypeOp = ASL_GET_PEER_NODE (BufferOp);
1016 * Process all resource descriptors in the list
1017 * Note: It is assumed that the EndTag node has been automatically
1018 * inserted at the end of the template by the parser.
1020 State = ACPI_RSTATE_NORMAL;
1021 PreviousRnode = &HeadRnode;
1022 while (DescriptorTypeOp)
1024 /* Save information for optional mapfile */
1026 if (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONNECTION)
1028 Info.MappingOp = Op->Asl.Parent;
1032 Info.MappingOp = DescriptorTypeOp;
1035 Info.DescriptorTypeOp = DescriptorTypeOp;
1036 Info.CurrentByteOffset = CurrentByteOffset;
1038 DescriptorTypeOp->Asl.CompileFlags |= NODE_IS_RESOURCE_DESC;
1039 Rnode = RsDoOneResourceDescriptor (&Info, &State);
1042 * Update current byte offset to indicate the number of bytes from the
1043 * start of the buffer. Buffer can include multiple descriptors, we
1044 * must keep track of the offset of not only each descriptor, but each
1045 * element (field) within each descriptor as well.
1047 CurrentByteOffset += RsLinkDescriptorChain (&PreviousRnode, Rnode);
1049 /* Get the next descriptor in the list */
1051 LastOp = DescriptorTypeOp;
1052 DescriptorTypeOp = ASL_GET_PEER_NODE (DescriptorTypeOp);
1055 if (State == ACPI_RSTATE_DEPENDENT_LIST)
1059 LastOp = LastOp->Asl.Parent;
1061 AslError (ASL_ERROR, ASL_MSG_MISSING_ENDDEPENDENT, LastOp, NULL);
1065 * Transform the nodes into the following
1067 * Op -> AML_BUFFER_OP
1068 * First Child -> BufferLength
1069 * Second Child -> Descriptor Buffer (raw byte data)
1071 Op->Asl.ParseOpcode = PARSEOP_BUFFER;
1072 Op->Asl.AmlOpcode = AML_BUFFER_OP;
1073 Op->Asl.CompileFlags = NODE_AML_PACKAGE | NODE_IS_RESOURCE_DESC;
1074 UtSetParseOpName (Op);
1076 BufferLengthOp->Asl.ParseOpcode = PARSEOP_INTEGER;
1077 BufferLengthOp->Asl.Value.Integer = CurrentByteOffset;
1078 (void) OpcSetOptimalIntegerSize (BufferLengthOp);
1079 UtSetParseOpName (BufferLengthOp);
1081 BufferOp->Asl.ParseOpcode = PARSEOP_RAW_DATA;
1082 BufferOp->Asl.AmlOpcode = AML_RAW_DATA_CHAIN;
1083 BufferOp->Asl.AmlOpcodeLength = 0;
1084 BufferOp->Asl.AmlLength = CurrentByteOffset;
1085 BufferOp->Asl.Value.Buffer = (UINT8 *) HeadRnode.Next;
1086 BufferOp->Asl.CompileFlags |= NODE_IS_RESOURCE_DATA;
1087 UtSetParseOpName (BufferOp);