2 /******************************************************************************
4 * Module Name: aslresource - Resource templates and descriptors
6 *****************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2009, 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 "aslcompiler.h"
119 #include "aslcompiler.y.h"
123 #define _COMPONENT ACPI_COMPILER
124 ACPI_MODULE_NAME ("aslresource")
127 /*******************************************************************************
129 * FUNCTION: RsAllocateResourceNode
131 * PARAMETERS: Size - Size of node in bytes
133 * RETURN: The allocated node - aborts on allocation failure
135 * DESCRIPTION: Allocate a resource description node and the resource
136 * descriptor itself (the nodes are used to link descriptors).
138 ******************************************************************************/
141 RsAllocateResourceNode (
144 ASL_RESOURCE_NODE *Rnode;
147 /* Allocate the node */
149 Rnode = UtLocalCalloc (sizeof (ASL_RESOURCE_NODE));
151 /* Allocate the resource descriptor itself */
153 Rnode->Buffer = UtLocalCalloc (Size);
154 Rnode->BufferLength = Size;
160 /*******************************************************************************
162 * FUNCTION: RsCreateBitField
164 * PARAMETERS: Op - Resource field node
165 * Name - Name of the field (Used only to reference
166 * the field in the ASL, not in the AML)
167 * ByteOffset - Offset from the field start
168 * BitOffset - Additional bit offset
170 * RETURN: None, sets fields within the input node
172 * DESCRIPTION: Utility function to generate a named bit field within a
173 * resource descriptor. Mark a node as 1) a field in a resource
174 * descriptor, and 2) set the value to be a BIT offset
176 ******************************************************************************/
180 ACPI_PARSE_OBJECT *Op,
186 Op->Asl.ExternalName = Name;
187 Op->Asl.Value.Integer = ((ACPI_INTEGER) ByteOffset * 8) + BitOffset;
188 Op->Asl.CompileFlags |= (NODE_IS_RESOURCE_FIELD | NODE_IS_BIT_OFFSET);
192 /*******************************************************************************
194 * FUNCTION: RsCreateByteField
196 * PARAMETERS: Op - Resource field node
197 * Name - Name of the field (Used only to reference
198 * the field in the ASL, not in the AML)
199 * ByteOffset - Offset from the field start
201 * RETURN: None, sets fields within the input node
203 * DESCRIPTION: Utility function to generate a named byte field within a
204 * resource descriptor. Mark a node as 1) a field in a resource
205 * descriptor, and 2) set the value to be a BYTE offset
207 ******************************************************************************/
211 ACPI_PARSE_OBJECT *Op,
216 Op->Asl.ExternalName = Name;
217 Op->Asl.Value.Integer = ByteOffset;
218 Op->Asl.CompileFlags |= NODE_IS_RESOURCE_FIELD;
222 /*******************************************************************************
224 * FUNCTION: RsSetFlagBits
226 * PARAMETERS: *Flags - Pointer to the flag byte
227 * Op - Flag initialization node
228 * Position - Bit position within the flag byte
229 * Default - Used if the node is DEFAULT.
231 * RETURN: Sets bits within the *Flags output byte.
233 * DESCRIPTION: Set a bit in a cumulative flags word from an initialization
234 * node. Will use a default value if the node is DEFAULT, meaning
235 * that no value was specified in the ASL. Used to merge multiple
236 * keywords into a single flags byte.
238 ******************************************************************************/
243 ACPI_PARSE_OBJECT *Op,
248 if (Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)
250 /* Use the default bit */
252 *Flags |= (DefaultBit << Position);
256 /* Use the bit specified in the initialization node */
258 *Flags |= (((UINT8) Op->Asl.Value.Integer) << Position);
263 /*******************************************************************************
265 * FUNCTION: RsCompleteNodeAndGetNext
267 * PARAMETERS: Op - Resource node to be completed
269 * RETURN: The next peer to the input node.
271 * DESCRIPTION: Mark the current node completed and return the next peer.
272 * The node ParseOpcode is set to DEFAULT_ARG, meaning that
273 * this node is to be ignored from now on.
275 ******************************************************************************/
278 RsCompleteNodeAndGetNext (
279 ACPI_PARSE_OBJECT *Op)
282 /* Mark this node unused */
284 Op->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
286 /* Move on to the next peer node in the initializer list */
288 return (ASL_GET_PEER_NODE (Op));
292 /*******************************************************************************
294 * FUNCTION: RsCheckListForDuplicates
296 * PARAMETERS: Op - First op in the initializer list
300 * DESCRIPTION: Check an initializer list for duplicate values. Emits an error
301 * if any duplicates are found.
303 ******************************************************************************/
306 RsCheckListForDuplicates (
307 ACPI_PARSE_OBJECT *Op)
309 ACPI_PARSE_OBJECT *NextValueOp = Op;
310 ACPI_PARSE_OBJECT *NextOp;
319 /* Search list once for each value in the list */
323 Value = (UINT32) NextValueOp->Asl.Value.Integer;
325 /* Compare this value to all remaining values in the list */
327 NextOp = ASL_GET_PEER_NODE (NextValueOp);
330 if (NextOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
334 if (Value == (UINT32) NextOp->Asl.Value.Integer)
336 /* Emit error only once per duplicate node */
338 if (!(NextOp->Asl.CompileFlags & NODE_IS_DUPLICATE))
340 NextOp->Asl.CompileFlags |= NODE_IS_DUPLICATE;
341 AslError (ASL_ERROR, ASL_MSG_DUPLICATE_ITEM,
347 NextOp = ASL_GET_PEER_NODE (NextOp);
350 NextValueOp = ASL_GET_PEER_NODE (NextValueOp);
355 /*******************************************************************************
357 * FUNCTION: RsDoOneResourceDescriptor
359 * PARAMETERS: DescriptorTypeOp - Parent parse node of the descriptor
360 * CurrentByteOffset - Offset in the resource descriptor
363 * RETURN: A valid resource node for the descriptor
365 * DESCRIPTION: Dispatches the processing of one resource descriptor
367 ******************************************************************************/
370 RsDoOneResourceDescriptor (
371 ACPI_PARSE_OBJECT *DescriptorTypeOp,
372 UINT32 CurrentByteOffset,
375 ASL_RESOURCE_NODE *Rnode = NULL;
378 /* Construct the resource */
380 switch (DescriptorTypeOp->Asl.ParseOpcode)
383 Rnode = RsDoDmaDescriptor (DescriptorTypeOp,
387 case PARSEOP_DWORDIO:
388 Rnode = RsDoDwordIoDescriptor (DescriptorTypeOp,
392 case PARSEOP_DWORDMEMORY:
393 Rnode = RsDoDwordMemoryDescriptor (DescriptorTypeOp,
397 case PARSEOP_DWORDSPACE:
398 Rnode = RsDoDwordSpaceDescriptor (DescriptorTypeOp,
402 case PARSEOP_ENDDEPENDENTFN:
405 case ACPI_RSTATE_NORMAL:
406 AslError (ASL_ERROR, ASL_MSG_MISSING_STARTDEPENDENT,
407 DescriptorTypeOp, NULL);
410 case ACPI_RSTATE_START_DEPENDENT:
411 AslError (ASL_ERROR, ASL_MSG_DEPENDENT_NESTING,
412 DescriptorTypeOp, NULL);
415 case ACPI_RSTATE_DEPENDENT_LIST:
420 *State = ACPI_RSTATE_NORMAL;
421 Rnode = RsDoEndDependentDescriptor (DescriptorTypeOp,
426 Rnode = RsDoEndTagDescriptor (DescriptorTypeOp,
430 case PARSEOP_EXTENDEDIO:
431 Rnode = RsDoExtendedIoDescriptor (DescriptorTypeOp,
435 case PARSEOP_EXTENDEDMEMORY:
436 Rnode = RsDoExtendedMemoryDescriptor (DescriptorTypeOp,
440 case PARSEOP_EXTENDEDSPACE:
441 Rnode = RsDoExtendedSpaceDescriptor (DescriptorTypeOp,
445 case PARSEOP_FIXEDIO:
446 Rnode = RsDoFixedIoDescriptor (DescriptorTypeOp,
450 case PARSEOP_INTERRUPT:
451 Rnode = RsDoInterruptDescriptor (DescriptorTypeOp,
456 Rnode = RsDoIoDescriptor (DescriptorTypeOp,
461 Rnode = RsDoIrqDescriptor (DescriptorTypeOp,
465 case PARSEOP_IRQNOFLAGS:
466 Rnode = RsDoIrqNoFlagsDescriptor (DescriptorTypeOp,
470 case PARSEOP_MEMORY24:
471 Rnode = RsDoMemory24Descriptor (DescriptorTypeOp,
475 case PARSEOP_MEMORY32:
476 Rnode = RsDoMemory32Descriptor (DescriptorTypeOp,
480 case PARSEOP_MEMORY32FIXED:
481 Rnode = RsDoMemory32FixedDescriptor (DescriptorTypeOp,
485 case PARSEOP_QWORDIO:
486 Rnode = RsDoQwordIoDescriptor (DescriptorTypeOp,
490 case PARSEOP_QWORDMEMORY:
491 Rnode = RsDoQwordMemoryDescriptor (DescriptorTypeOp,
495 case PARSEOP_QWORDSPACE:
496 Rnode = RsDoQwordSpaceDescriptor (DescriptorTypeOp,
500 case PARSEOP_REGISTER:
501 Rnode = RsDoGeneralRegisterDescriptor (DescriptorTypeOp,
505 case PARSEOP_STARTDEPENDENTFN:
508 case ACPI_RSTATE_START_DEPENDENT:
509 AslError (ASL_ERROR, ASL_MSG_DEPENDENT_NESTING,
510 DescriptorTypeOp, NULL);
513 case ACPI_RSTATE_NORMAL:
514 case ACPI_RSTATE_DEPENDENT_LIST:
519 *State = ACPI_RSTATE_START_DEPENDENT;
520 Rnode = RsDoStartDependentDescriptor (DescriptorTypeOp,
522 *State = ACPI_RSTATE_DEPENDENT_LIST;
525 case PARSEOP_STARTDEPENDENTFN_NOPRI:
528 case ACPI_RSTATE_START_DEPENDENT:
529 AslError (ASL_ERROR, ASL_MSG_DEPENDENT_NESTING,
530 DescriptorTypeOp, NULL);
533 case ACPI_RSTATE_NORMAL:
534 case ACPI_RSTATE_DEPENDENT_LIST:
539 *State = ACPI_RSTATE_START_DEPENDENT;
540 Rnode = RsDoStartDependentNoPriDescriptor (DescriptorTypeOp,
542 *State = ACPI_RSTATE_DEPENDENT_LIST;
545 case PARSEOP_VENDORLONG:
546 Rnode = RsDoVendorLargeDescriptor (DescriptorTypeOp,
550 case PARSEOP_VENDORSHORT:
551 Rnode = RsDoVendorSmallDescriptor (DescriptorTypeOp,
555 case PARSEOP_WORDBUSNUMBER:
556 Rnode = RsDoWordBusNumberDescriptor (DescriptorTypeOp,
561 Rnode = RsDoWordIoDescriptor (DescriptorTypeOp,
565 case PARSEOP_WORDSPACE:
566 Rnode = RsDoWordSpaceDescriptor (DescriptorTypeOp,
570 case PARSEOP_DEFAULT_ARG:
571 /* Just ignore any of these, they are used as fillers/placeholders */
575 printf ("Unknown resource descriptor type [%s]\n",
576 DescriptorTypeOp->Asl.ParseOpName);
581 * Mark original node as unused, but head of a resource descriptor.
582 * This allows the resource to be installed in the namespace so that
583 * references to the descriptor can be resolved.
585 DescriptorTypeOp->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
586 DescriptorTypeOp->Asl.CompileFlags = NODE_IS_RESOURCE_DESC;
587 DescriptorTypeOp->Asl.Value.Integer = CurrentByteOffset;
591 DescriptorTypeOp->Asl.FinalAmlLength = Rnode->BufferLength;
598 /*******************************************************************************
600 * FUNCTION: RsLinkDescriptorChain
602 * PARAMETERS: PreviousRnode - Pointer to the node that will be previous
603 * to the linked node, At exit, set to the
604 * last node in the new chain.
605 * Rnode - Resource node to link into the list
607 * RETURN: Cumulative buffer byte offset of the new segment of chain
609 * DESCRIPTION: Link a descriptor chain at the end of an existing chain.
611 ******************************************************************************/
614 RsLinkDescriptorChain (
615 ASL_RESOURCE_NODE **PreviousRnode,
616 ASL_RESOURCE_NODE *Rnode)
618 ASL_RESOURCE_NODE *LastRnode;
619 UINT32 CurrentByteOffset;
622 /* Anything to do? */
629 /* Point the previous node to the new node */
631 (*PreviousRnode)->Next = Rnode;
632 CurrentByteOffset = Rnode->BufferLength;
634 /* Walk to the end of the chain headed by Rnode */
637 while (LastRnode->Next)
639 LastRnode = LastRnode->Next;
640 CurrentByteOffset += LastRnode->BufferLength;
643 /* Previous node becomes the last node in the chain */
645 *PreviousRnode = LastRnode;
646 return CurrentByteOffset;
650 /*******************************************************************************
652 * FUNCTION: RsDoResourceTemplate
654 * PARAMETERS: Op - Parent of a resource template list
656 * RETURN: None. Sets input node to point to a list of AML code
658 * DESCRIPTION: Merge a list of resource descriptors into a single AML buffer,
659 * in preparation for output to the AML output file.
661 ******************************************************************************/
664 RsDoResourceTemplate (
665 ACPI_PARSE_OBJECT *Op)
667 ACPI_PARSE_OBJECT *BufferLengthOp;
668 ACPI_PARSE_OBJECT *BufferOp;
669 ACPI_PARSE_OBJECT *DescriptorTypeOp;
670 ACPI_PARSE_OBJECT *LastOp = NULL;
671 UINT32 CurrentByteOffset = 0;
672 ASL_RESOURCE_NODE HeadRnode;
673 ASL_RESOURCE_NODE *PreviousRnode;
674 ASL_RESOURCE_NODE *Rnode;
678 /* Mark parent as containing a resource template */
682 Op->Asl.Parent->Asl.CompileFlags |= NODE_IS_RESOURCE_DESC;
685 /* ResourceTemplate Opcode is first (Op) */
686 /* Buffer Length node is first child */
688 BufferLengthOp = ASL_GET_CHILD_NODE (Op);
690 /* Buffer Op is first peer */
692 BufferOp = ASL_GET_PEER_NODE (BufferLengthOp);
694 /* First Descriptor type is next */
696 DescriptorTypeOp = ASL_GET_PEER_NODE (BufferOp);
699 * Process all resource descriptors in the list
700 * Note: It is assumed that the EndTag node has been automatically
701 * inserted at the end of the template by the parser.
703 State = ACPI_RSTATE_NORMAL;
704 PreviousRnode = &HeadRnode;
705 while (DescriptorTypeOp)
707 DescriptorTypeOp->Asl.CompileFlags |= NODE_IS_RESOURCE_DESC;
708 Rnode = RsDoOneResourceDescriptor (DescriptorTypeOp, CurrentByteOffset,
712 * Update current byte offset to indicate the number of bytes from the
713 * start of the buffer. Buffer can include multiple descriptors, we
714 * must keep track of the offset of not only each descriptor, but each
715 * element (field) within each descriptor as well.
717 CurrentByteOffset += RsLinkDescriptorChain (&PreviousRnode, Rnode);
719 /* Get the next descriptor in the list */
721 LastOp = DescriptorTypeOp;
722 DescriptorTypeOp = ASL_GET_PEER_NODE (DescriptorTypeOp);
725 if (State == ACPI_RSTATE_DEPENDENT_LIST)
729 LastOp = LastOp->Asl.Parent;
731 AslError (ASL_ERROR, ASL_MSG_MISSING_ENDDEPENDENT, LastOp, NULL);
735 * Transform the nodes into the following
737 * Op -> AML_BUFFER_OP
738 * First Child -> BufferLength
739 * Second Child -> Descriptor Buffer (raw byte data)
741 Op->Asl.ParseOpcode = PARSEOP_BUFFER;
742 Op->Asl.AmlOpcode = AML_BUFFER_OP;
743 Op->Asl.CompileFlags = NODE_AML_PACKAGE | NODE_IS_RESOURCE_DESC;
745 BufferLengthOp->Asl.ParseOpcode = PARSEOP_INTEGER;
746 BufferLengthOp->Asl.Value.Integer = CurrentByteOffset;
747 (void) OpcSetOptimalIntegerSize (BufferLengthOp);
749 BufferOp->Asl.ParseOpcode = PARSEOP_RAW_DATA;
750 BufferOp->Asl.AmlOpcode = AML_RAW_DATA_CHAIN;
751 BufferOp->Asl.AmlOpcodeLength = 0;
752 BufferOp->Asl.AmlLength = CurrentByteOffset;
753 BufferOp->Asl.Value.Buffer = (UINT8 *) HeadRnode.Next;
754 BufferOp->Asl.CompileFlags |= NODE_IS_RESOURCE_DATA;