2 /******************************************************************************
4 * Module Name: aslresource - Resource templates and descriptors
7 *****************************************************************************/
9 /******************************************************************************
13 * Some or all of this work - Copyright (c) 1999 - 2004, Intel Corp.
14 * All rights reserved.
18 * 2.1. This is your license from Intel Corp. under its intellectual property
19 * rights. You may have additional license terms from the party that provided
20 * you this software, covering your right to use that party's intellectual
23 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
24 * copy of the source code appearing in this file ("Covered Code") an
25 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
26 * base code distributed originally by Intel ("Original Intel Code") to copy,
27 * make derivatives, distribute, use and display any portion of the Covered
28 * Code in any form, with the right to sublicense such rights; and
30 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
31 * license (with the right to sublicense), under only those claims of Intel
32 * patents that are infringed by the Original Intel Code, to make, use, sell,
33 * offer to sell, and import the Covered Code and derivative works thereof
34 * solely to the minimum extent necessary to exercise the above copyright
35 * license, and in no event shall the patent license extend to any additions
36 * to or modifications of the Original Intel Code. No other license or right
37 * is granted directly or by implication, estoppel or otherwise;
39 * The above copyright and patent license is granted only if the following
44 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
45 * Redistribution of source code of any substantial portion of the Covered
46 * Code or modification with rights to further distribute source must include
47 * the above Copyright Notice, the above License, this list of Conditions,
48 * and the following Disclaimer and Export Compliance provision. In addition,
49 * Licensee must cause all Covered Code to which Licensee contributes to
50 * contain a file documenting the changes Licensee made to create that Covered
51 * Code and the date of any change. Licensee must include in that file the
52 * documentation of any changes made by any predecessor Licensee. Licensee
53 * must include a prominent statement that the modification is derived,
54 * directly or indirectly, from Original Intel Code.
56 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
57 * Redistribution of source code of any substantial portion of the Covered
58 * Code or modification without rights to further distribute source must
59 * include the following Disclaimer and Export Compliance provision in the
60 * documentation and/or other materials provided with distribution. In
61 * addition, Licensee may not authorize further sublicense of source of any
62 * portion of the Covered Code, and must include terms to the effect that the
63 * license from Licensee to its licensee is limited to the intellectual
64 * property embodied in the software Licensee provides to its licensee, and
65 * not to intellectual property embodied in modifications its licensee may
68 * 3.3. Redistribution of Executable. Redistribution in executable form of any
69 * substantial portion of the Covered Code or modification must reproduce the
70 * above Copyright Notice, and the following Disclaimer and Export Compliance
71 * provision in the documentation and/or other materials provided with the
74 * 3.4. Intel retains all right, title, and interest in and to the Original
77 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
78 * Intel shall be used in advertising or otherwise to promote the sale, use or
79 * other dealings in products derived from or relating to the Covered Code
80 * without prior written authorization from Intel.
82 * 4. Disclaimer and Export Compliance
84 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
85 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
86 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
87 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
88 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
89 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
92 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
93 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
94 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
95 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
96 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
97 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
98 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
101 * 4.3. Licensee shall not export, either directly or indirectly, any of this
102 * software or system incorporating such software without first obtaining any
103 * required license or other approval from the U. S. Department of Commerce or
104 * any other agency or department of the United States Government. In the
105 * event Licensee exports any such software from the United States or
106 * re-exports any such software from a foreign destination, Licensee shall
107 * ensure that the distribution and export/re-export of the software is in
108 * compliance with all laws, regulations, orders, or other restrictions of the
109 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
110 * any of its subsidiaries will export/re-export any technical data, process,
111 * software, or service, directly or indirectly, to any country for which the
112 * United States government or any agency thereof requires an export license,
113 * other governmental approval, or letter of assurance, without first obtaining
114 * such license, approval or letter.
116 *****************************************************************************/
119 #include "aslcompiler.h"
120 #include "aslcompiler.y.h"
124 #define _COMPONENT ACPI_COMPILER
125 ACPI_MODULE_NAME ("aslresource")
128 /*******************************************************************************
130 * FUNCTION: RsAllocateResourceNode
132 * PARAMETERS: Size - Size of node in bytes
134 * RETURN: The allocated node - aborts on allocation failure
136 * DESCRIPTION: Allocate a resource description node and the resource
137 * descriptor itself (the nodes are used to link descriptors).
139 ******************************************************************************/
142 RsAllocateResourceNode (
145 ASL_RESOURCE_NODE *Rnode;
148 /* Allocate the node */
150 Rnode = UtLocalCalloc (sizeof (ASL_RESOURCE_NODE));
152 /* Allocate the resource descriptor itself */
154 Rnode->Buffer = UtLocalCalloc (Size);
155 Rnode->BufferLength = Size;
161 /*******************************************************************************
163 * FUNCTION: RsCreateBitField
165 * PARAMETERS: Op - Resource field node
166 * Name - Name of the field (Used only to reference
167 * the field in the ASL, not in the AML)
168 * ByteOffset - Offset from the field start
169 * BitOffset - Additional bit offset
171 * RETURN: None, sets fields within the input node
173 * DESCRIPTION: Utility function to generate a named bit field within a
174 * resource descriptor. Mark a node as 1) a field in a resource
175 * descriptor, and 2) set the value to be a BIT offset
177 ******************************************************************************/
181 ACPI_PARSE_OBJECT *Op,
187 Op->Asl.ExternalName = Name;
188 Op->Asl.Value.Integer = (ByteOffset * 8) + BitOffset;
189 Op->Asl.CompileFlags |= (NODE_IS_RESOURCE_FIELD | NODE_IS_BIT_OFFSET);
193 /*******************************************************************************
195 * FUNCTION: RsCreateByteField
197 * PARAMETERS: Op - Resource field node
198 * Name - Name of the field (Used only to reference
199 * the field in the ASL, not in the AML)
200 * ByteOffset - Offset from the field start
202 * RETURN: None, sets fields within the input node
204 * DESCRIPTION: Utility function to generate a named byte field within a
205 * resource descriptor. Mark a node as 1) a field in a resource
206 * descriptor, and 2) set the value to be a BYTE offset
208 ******************************************************************************/
212 ACPI_PARSE_OBJECT *Op,
217 Op->Asl.ExternalName = Name;
218 Op->Asl.Value.Integer = ByteOffset;
219 Op->Asl.CompileFlags |= NODE_IS_RESOURCE_FIELD;
223 /*******************************************************************************
225 * FUNCTION: RsSetFlagBits
227 * PARAMETERS: *Flags - Pointer to the flag byte
228 * Op - Flag initialization node
229 * Position - Bit position within the flag byte
230 * Default - Used if the node is DEFAULT.
232 * RETURN: Sets bits within the *Flags output byte.
234 * DESCRIPTION: Set a bit in a cumulative flags word from an initialization
235 * node. Will use a default value if the node is DEFAULT, meaning
236 * that no value was specified in the ASL. Used to merge multiple
237 * keywords into a single flags byte.
239 ******************************************************************************/
244 ACPI_PARSE_OBJECT *Op,
249 if (Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)
251 /* Use the default bit */
253 *Flags |= (DefaultBit << Position);
257 /* Use the bit specified in the initialization node */
259 *Flags |= (((UINT8) Op->Asl.Value.Integer) << Position);
264 /*******************************************************************************
266 * FUNCTION: RsCompleteNodeAndGetNext
268 * PARAMETERS: Op - Resource node to be completed
270 * RETURN: The next peer to the input node.
272 * DESCRIPTION: Mark the current node completed and return the next peer.
273 * The node ParseOpcode is set to DEFAULT_ARG, meaning that
274 * this node is to be ignored from now on.
276 ******************************************************************************/
279 RsCompleteNodeAndGetNext (
280 ACPI_PARSE_OBJECT *Op)
283 /* Mark this node unused */
285 Op->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
287 /* Move on to the next peer node in the initializer list */
289 return (ASL_GET_PEER_NODE (Op));
293 /*******************************************************************************
295 * FUNCTION: RsDoOneResourceDescriptor
297 * PARAMETERS: DescriptorTypeOp - Parent parse node of the descriptor
298 * CurrentByteOffset - Offset in the resource descriptor
301 * RETURN: A valid resource node for the descriptor
303 * DESCRIPTION: Dispatches the processing of one resource descriptor
305 ******************************************************************************/
308 RsDoOneResourceDescriptor (
309 ACPI_PARSE_OBJECT *DescriptorTypeOp,
310 UINT32 CurrentByteOffset,
313 ASL_RESOURCE_NODE *Rnode = NULL;
316 /* Determine type of resource */
318 switch (DescriptorTypeOp->Asl.ParseOpcode)
321 Rnode = RsDoDmaDescriptor (DescriptorTypeOp, CurrentByteOffset);
324 case PARSEOP_DWORDIO:
325 Rnode = RsDoDwordIoDescriptor (DescriptorTypeOp, CurrentByteOffset);
328 case PARSEOP_DWORDMEMORY:
329 Rnode = RsDoDwordMemoryDescriptor (DescriptorTypeOp, CurrentByteOffset);
332 case PARSEOP_ENDDEPENDENTFN:
335 case ACPI_RSTATE_NORMAL:
336 AslError (ASL_ERROR, ASL_MSG_MISSING_STARTDEPENDENT, DescriptorTypeOp, NULL);
339 case ACPI_RSTATE_START_DEPENDENT:
340 AslError (ASL_ERROR, ASL_MSG_DEPENDENT_NESTING, DescriptorTypeOp, NULL);
343 case ACPI_RSTATE_DEPENDENT_LIST:
348 *State = ACPI_RSTATE_NORMAL;
349 Rnode = RsDoEndDependentDescriptor (DescriptorTypeOp, CurrentByteOffset);
352 case PARSEOP_FIXEDIO:
353 Rnode = RsDoFixedIoDescriptor (DescriptorTypeOp, CurrentByteOffset);
356 case PARSEOP_INTERRUPT:
357 Rnode = RsDoInterruptDescriptor (DescriptorTypeOp, CurrentByteOffset);
361 Rnode = RsDoIoDescriptor (DescriptorTypeOp, CurrentByteOffset);
365 Rnode = RsDoIrqDescriptor (DescriptorTypeOp, CurrentByteOffset);
368 case PARSEOP_IRQNOFLAGS:
369 Rnode = RsDoIrqNoFlagsDescriptor (DescriptorTypeOp, CurrentByteOffset);
372 case PARSEOP_MEMORY24:
373 Rnode = RsDoMemory24Descriptor (DescriptorTypeOp, CurrentByteOffset);
376 case PARSEOP_MEMORY32:
377 Rnode = RsDoMemory32Descriptor (DescriptorTypeOp, CurrentByteOffset);
380 case PARSEOP_MEMORY32FIXED:
381 Rnode = RsDoMemory32FixedDescriptor (DescriptorTypeOp, CurrentByteOffset);
384 case PARSEOP_QWORDIO:
385 Rnode = RsDoQwordIoDescriptor (DescriptorTypeOp, CurrentByteOffset);
388 case PARSEOP_QWORDMEMORY:
389 Rnode = RsDoQwordMemoryDescriptor (DescriptorTypeOp, CurrentByteOffset);
392 case PARSEOP_REGISTER:
393 Rnode = RsDoGeneralRegisterDescriptor (DescriptorTypeOp, CurrentByteOffset);
396 case PARSEOP_STARTDEPENDENTFN:
399 case ACPI_RSTATE_START_DEPENDENT:
400 AslError (ASL_ERROR, ASL_MSG_DEPENDENT_NESTING, DescriptorTypeOp, NULL);
403 case ACPI_RSTATE_NORMAL:
404 case ACPI_RSTATE_DEPENDENT_LIST:
409 *State = ACPI_RSTATE_START_DEPENDENT;
410 Rnode = RsDoStartDependentDescriptor (DescriptorTypeOp, CurrentByteOffset);
411 *State = ACPI_RSTATE_DEPENDENT_LIST;
414 case PARSEOP_STARTDEPENDENTFN_NOPRI:
417 case ACPI_RSTATE_START_DEPENDENT:
418 AslError (ASL_ERROR, ASL_MSG_DEPENDENT_NESTING, DescriptorTypeOp, NULL);
421 case ACPI_RSTATE_NORMAL:
422 case ACPI_RSTATE_DEPENDENT_LIST:
427 *State = ACPI_RSTATE_START_DEPENDENT;
428 Rnode = RsDoStartDependentNoPriDescriptor (DescriptorTypeOp, CurrentByteOffset);
429 *State = ACPI_RSTATE_DEPENDENT_LIST;
432 case PARSEOP_VENDORLONG:
433 Rnode = RsDoVendorLargeDescriptor (DescriptorTypeOp, CurrentByteOffset);
436 case PARSEOP_VENDORSHORT:
437 Rnode = RsDoVendorSmallDescriptor (DescriptorTypeOp, CurrentByteOffset);
440 case PARSEOP_WORDBUSNUMBER:
441 Rnode = RsDoWordBusNumberDescriptor (DescriptorTypeOp, CurrentByteOffset);
445 Rnode = RsDoWordIoDescriptor (DescriptorTypeOp, CurrentByteOffset);
448 case PARSEOP_DEFAULT_ARG:
449 /* Just ignore any of these, they are used as fillers/placeholders */
453 printf ("Unknown resource descriptor type [%s]\n",
454 DescriptorTypeOp->Asl.ParseOpName);
459 * Mark original node as unused, but head of a resource descriptor.
460 * This allows the resource to be installed in the namespace so that
461 * references to the descriptor can be resolved.
463 DescriptorTypeOp->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
464 DescriptorTypeOp->Asl.CompileFlags = NODE_IS_RESOURCE_DESC;
470 /*******************************************************************************
472 * FUNCTION: RsLinkDescriptorChain
474 * PARAMETERS: PreviousRnode - Pointer to the node that will be previous
475 * to the linked node, At exit, set to the
476 * last node in the new chain.
477 * Rnode - Resource node to link into the list
479 * RETURN: Cumulative buffer byte offset of the new segment of chain
481 * DESCRIPTION: Link a descriptor chain at the end of an existing chain.
483 ******************************************************************************/
486 RsLinkDescriptorChain (
487 ASL_RESOURCE_NODE **PreviousRnode,
488 ASL_RESOURCE_NODE *Rnode)
490 ASL_RESOURCE_NODE *LastRnode;
491 UINT32 CurrentByteOffset;
494 /* Anything to do? */
501 /* Point the previous node to the new node */
503 (*PreviousRnode)->Next = Rnode;
504 CurrentByteOffset = Rnode->BufferLength;
506 /* Walk to the end of the chain headed by Rnode */
509 while (LastRnode->Next)
511 LastRnode = LastRnode->Next;
512 CurrentByteOffset += LastRnode->BufferLength;
515 /* Previous node becomes the last node in the chain */
517 *PreviousRnode = LastRnode;
518 return CurrentByteOffset;
522 /*******************************************************************************
524 * FUNCTION: RsDoResourceTemplate
526 * PARAMETERS: Op - Parent of a resource template list
528 * RETURN: None. Sets input node to point to a list of AML code
530 * DESCRIPTION: Merge a list of resource descriptors into a single AML buffer,
531 * in preparation for output to the AML output file.
533 ******************************************************************************/
536 RsDoResourceTemplate (
537 ACPI_PARSE_OBJECT *Op)
539 ACPI_PARSE_OBJECT *BufferLengthOp;
540 ACPI_PARSE_OBJECT *BufferOp;
541 ACPI_PARSE_OBJECT *DescriptorTypeOp;
542 ACPI_PARSE_OBJECT *LastOp = NULL;
543 ASL_RESOURCE_DESC *Descriptor;
544 UINT32 CurrentByteOffset = 0;
545 ASL_RESOURCE_NODE HeadRnode;
546 ASL_RESOURCE_NODE *PreviousRnode;
547 ASL_RESOURCE_NODE *Rnode;
551 /* ResourceTemplate Opcode is first (Op) */
552 /* Buffer Length node is first child */
554 BufferLengthOp = ASL_GET_CHILD_NODE (Op);
556 /* Buffer Op is first peer */
558 BufferOp = ASL_GET_PEER_NODE (BufferLengthOp);
560 /* First Descriptor type is next */
562 DescriptorTypeOp = ASL_GET_PEER_NODE (BufferOp);
564 /* Process all resource descriptors in the list */
566 State = ACPI_RSTATE_NORMAL;
567 PreviousRnode = &HeadRnode;
568 while (DescriptorTypeOp)
570 Rnode = RsDoOneResourceDescriptor (DescriptorTypeOp, CurrentByteOffset, &State);
573 * Update current byte offset to indicate the number of bytes from the
574 * start of the buffer. Buffer can include multiple descriptors, we
575 * must keep track of the offset of not only each descriptor, but each
576 * element (field) within each descriptor as well.
578 CurrentByteOffset += RsLinkDescriptorChain (&PreviousRnode, Rnode);
580 /* Get the next descriptor in the list */
582 LastOp = DescriptorTypeOp;
583 DescriptorTypeOp = ASL_GET_PEER_NODE (DescriptorTypeOp);
586 if (State == ACPI_RSTATE_DEPENDENT_LIST)
590 LastOp = LastOp->Asl.Parent;
592 AslError (ASL_ERROR, ASL_MSG_MISSING_ENDDEPENDENT, LastOp, NULL);
596 * Insert the EndTag descriptor after all other descriptors have been processed
598 Rnode = RsAllocateResourceNode (sizeof (ASL_END_TAG_DESC));
600 Descriptor = Rnode->Buffer;
601 Descriptor->Et.DescriptorType = ACPI_RDESC_TYPE_END_TAG |
602 ASL_RDESC_END_TAG_SIZE;
603 Descriptor->Et.Checksum = 0;
605 CurrentByteOffset += RsLinkDescriptorChain (&PreviousRnode, Rnode);
608 * Transform the nodes into the following
610 * Op -> AML_BUFFER_OP
611 * First Child -> BufferLength
612 * Second Child -> Descriptor Buffer (raw byte data)
614 Op->Asl.ParseOpcode = PARSEOP_BUFFER;
615 Op->Asl.AmlOpcode = AML_BUFFER_OP;
616 Op->Asl.CompileFlags = NODE_AML_PACKAGE;
618 BufferLengthOp->Asl.ParseOpcode = PARSEOP_INTEGER;
619 BufferLengthOp->Asl.Value.Integer = CurrentByteOffset;
621 (void) OpcSetOptimalIntegerSize (BufferLengthOp);
623 BufferOp->Asl.ParseOpcode = PARSEOP_RAW_DATA;
624 BufferOp->Asl.AmlOpcode = AML_RAW_DATA_CHAIN;
625 BufferOp->Asl.AmlOpcodeLength = 0;
626 BufferOp->Asl.AmlLength = CurrentByteOffset;
627 BufferOp->Asl.Value.Buffer = (UINT8 *) HeadRnode.Next;