]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sys/contrib/dev/acpica/compiler/aslresource.c
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / sys / contrib / dev / acpica / compiler / aslresource.c
1
2 /******************************************************************************
3  *
4  * Module Name: aslresource - Resource templates and descriptors
5  *              $Revision: 1.43 $
6  *
7  *****************************************************************************/
8
9 /******************************************************************************
10  *
11  * 1. Copyright Notice
12  *
13  * Some or all of this work - Copyright (c) 1999 - 2007, Intel Corp.
14  * All rights reserved.
15  *
16  * 2. License
17  *
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
21  * property rights.
22  *
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
29  *
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;
38  *
39  * The above copyright and patent license is granted only if the following
40  * conditions are met:
41  *
42  * 3. Conditions
43  *
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.
55  *
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
66  * make.
67  *
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
72  * distribution.
73  *
74  * 3.4. Intel retains all right, title, and interest in and to the Original
75  * Intel Code.
76  *
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.
81  *
82  * 4. Disclaimer and Export Compliance
83  *
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
90  * PARTICULAR PURPOSE.
91  *
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
99  * LIMITED REMEDY.
100  *
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.
115  *
116  *****************************************************************************/
117
118
119 #include <contrib/dev/acpica/compiler/aslcompiler.h>
120 #include "aslcompiler.y.h"
121 #include <contrib/dev/acpica/amlcode.h>
122
123
124 #define _COMPONENT          ACPI_COMPILER
125         ACPI_MODULE_NAME    ("aslresource")
126
127
128 /*******************************************************************************
129  *
130  * FUNCTION:    RsAllocateResourceNode
131  *
132  * PARAMETERS:  Size        - Size of node in bytes
133  *
134  * RETURN:      The allocated node - aborts on allocation failure
135  *
136  * DESCRIPTION: Allocate a resource description node and the resource
137  *              descriptor itself (the nodes are used to link descriptors).
138  *
139  ******************************************************************************/
140
141 ASL_RESOURCE_NODE *
142 RsAllocateResourceNode (
143     UINT32                  Size)
144 {
145     ASL_RESOURCE_NODE       *Rnode;
146
147
148     /* Allocate the node */
149
150     Rnode = UtLocalCalloc (sizeof (ASL_RESOURCE_NODE));
151
152     /* Allocate the resource descriptor itself */
153
154     Rnode->Buffer = UtLocalCalloc (Size);
155     Rnode->BufferLength = Size;
156
157     return (Rnode);
158 }
159
160
161 /*******************************************************************************
162  *
163  * FUNCTION:    RsCreateBitField
164  *
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
170  *
171  * RETURN:      None, sets fields within the input node
172  *
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
176  *
177  ******************************************************************************/
178
179 void
180 RsCreateBitField (
181     ACPI_PARSE_OBJECT       *Op,
182     char                    *Name,
183     UINT32                  ByteOffset,
184     UINT32                  BitOffset)
185 {
186
187     Op->Asl.ExternalName      = Name;
188     Op->Asl.Value.Integer     = ((ACPI_INTEGER) ByteOffset * 8) + BitOffset;
189     Op->Asl.CompileFlags     |= (NODE_IS_RESOURCE_FIELD | NODE_IS_BIT_OFFSET);
190 }
191
192
193 /*******************************************************************************
194  *
195  * FUNCTION:    RsCreateByteField
196  *
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
201  *
202  * RETURN:      None, sets fields within the input node
203  *
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
207  *
208  ******************************************************************************/
209
210 void
211 RsCreateByteField (
212     ACPI_PARSE_OBJECT       *Op,
213     char                    *Name,
214     UINT32                  ByteOffset)
215 {
216
217     Op->Asl.ExternalName      = Name;
218     Op->Asl.Value.Integer     = ByteOffset;
219     Op->Asl.CompileFlags     |= NODE_IS_RESOURCE_FIELD;
220 }
221
222
223 /*******************************************************************************
224  *
225  * FUNCTION:    RsSetFlagBits
226  *
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.
231  *
232  * RETURN:      Sets bits within the *Flags output byte.
233  *
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.
238  *
239  ******************************************************************************/
240
241 void
242 RsSetFlagBits (
243     UINT8                   *Flags,
244     ACPI_PARSE_OBJECT       *Op,
245     UINT8                   Position,
246     UINT8                   DefaultBit)
247 {
248
249     if (Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)
250     {
251         /* Use the default bit */
252
253         *Flags |= (DefaultBit << Position);
254     }
255     else
256     {
257         /* Use the bit specified in the initialization node */
258
259         *Flags |= (((UINT8) Op->Asl.Value.Integer) << Position);
260     }
261 }
262
263
264 /*******************************************************************************
265  *
266  * FUNCTION:    RsCompleteNodeAndGetNext
267  *
268  * PARAMETERS:  Op            - Resource node to be completed
269  *
270  * RETURN:      The next peer to the input node.
271  *
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.
275  *
276  ******************************************************************************/
277
278 ACPI_PARSE_OBJECT *
279 RsCompleteNodeAndGetNext (
280     ACPI_PARSE_OBJECT       *Op)
281 {
282
283     /* Mark this node unused */
284
285     Op->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
286
287     /* Move on to the next peer node in the initializer list */
288
289     return (ASL_GET_PEER_NODE (Op));
290 }
291
292
293 /*******************************************************************************
294  *
295  * FUNCTION:    RsCheckListForDuplicates
296  *
297  * PARAMETERS:  Op                  - First op in the initializer list
298  *
299  * RETURN:      None
300  *
301  * DESCRIPTION: Check an initializer list for duplicate values. Emits an error
302  *              if any duplicates are found.
303  *
304  ******************************************************************************/
305
306 void
307 RsCheckListForDuplicates (
308     ACPI_PARSE_OBJECT       *Op)
309 {
310     ACPI_PARSE_OBJECT       *NextValueOp = Op;
311     ACPI_PARSE_OBJECT       *NextOp;
312     UINT32                  Value;
313
314
315     if (!Op)
316     {
317         return;
318     }
319
320     /* Search list once for each value in the list */
321
322     while (NextValueOp)
323     {
324         Value = (UINT32) NextValueOp->Asl.Value.Integer;
325
326         /* Compare this value to all remaining values in the list */
327
328         NextOp = ASL_GET_PEER_NODE (NextValueOp);
329         while (NextOp)
330         {
331             if (NextOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
332             {
333                 /* Compare values */
334
335                 if (Value == (UINT32) NextOp->Asl.Value.Integer)
336                 {
337                     /* Emit error only once per duplicate node */
338
339                     if (!(NextOp->Asl.CompileFlags & NODE_IS_DUPLICATE))
340                     {
341                         NextOp->Asl.CompileFlags |= NODE_IS_DUPLICATE;
342                         AslError (ASL_ERROR, ASL_MSG_DUPLICATE_ITEM,
343                             NextOp, NULL);
344                     }
345                 }
346             }
347
348             NextOp = ASL_GET_PEER_NODE (NextOp);
349         }
350
351         NextValueOp = ASL_GET_PEER_NODE (NextValueOp);
352     }
353 }
354
355
356 /*******************************************************************************
357  *
358  * FUNCTION:    RsDoOneResourceDescriptor
359  *
360  * PARAMETERS:  DescriptorTypeOp    - Parent parse node of the descriptor
361  *              CurrentByteOffset   - Offset in the resource descriptor
362  *                                    buffer.
363  *
364  * RETURN:      A valid resource node for the descriptor
365  *
366  * DESCRIPTION: Dispatches the processing of one resource descriptor
367  *
368  ******************************************************************************/
369
370 ASL_RESOURCE_NODE *
371 RsDoOneResourceDescriptor (
372     ACPI_PARSE_OBJECT       *DescriptorTypeOp,
373     UINT32                  CurrentByteOffset,
374     UINT8                   *State)
375 {
376     ASL_RESOURCE_NODE       *Rnode = NULL;
377
378
379     /* Construct the resource */
380
381     switch (DescriptorTypeOp->Asl.ParseOpcode)
382     {
383     case PARSEOP_DMA:
384         Rnode = RsDoDmaDescriptor (DescriptorTypeOp,
385                     CurrentByteOffset);
386         break;
387
388     case PARSEOP_DWORDIO:
389         Rnode = RsDoDwordIoDescriptor (DescriptorTypeOp,
390                     CurrentByteOffset);
391         break;
392
393     case PARSEOP_DWORDMEMORY:
394         Rnode = RsDoDwordMemoryDescriptor (DescriptorTypeOp,
395                     CurrentByteOffset);
396         break;
397
398     case PARSEOP_DWORDSPACE:
399         Rnode = RsDoDwordSpaceDescriptor (DescriptorTypeOp,
400                     CurrentByteOffset);
401         break;
402
403     case PARSEOP_ENDDEPENDENTFN:
404         switch (*State)
405         {
406         case ACPI_RSTATE_NORMAL:
407             AslError (ASL_ERROR, ASL_MSG_MISSING_STARTDEPENDENT,
408                 DescriptorTypeOp, NULL);
409             break;
410
411         case ACPI_RSTATE_START_DEPENDENT:
412             AslError (ASL_ERROR, ASL_MSG_DEPENDENT_NESTING,
413                 DescriptorTypeOp, NULL);
414             break;
415
416         case ACPI_RSTATE_DEPENDENT_LIST:
417         default:
418             break;
419         }
420
421         *State = ACPI_RSTATE_NORMAL;
422         Rnode = RsDoEndDependentDescriptor (DescriptorTypeOp,
423                     CurrentByteOffset);
424         break;
425
426     case PARSEOP_ENDTAG:
427         Rnode = RsDoEndTagDescriptor (DescriptorTypeOp,
428                     CurrentByteOffset);
429         break;
430
431     case PARSEOP_EXTENDEDIO:
432         Rnode = RsDoExtendedIoDescriptor (DescriptorTypeOp,
433                     CurrentByteOffset);
434         break;
435
436     case PARSEOP_EXTENDEDMEMORY:
437         Rnode = RsDoExtendedMemoryDescriptor (DescriptorTypeOp,
438                     CurrentByteOffset);
439         break;
440
441     case PARSEOP_EXTENDEDSPACE:
442         Rnode = RsDoExtendedSpaceDescriptor (DescriptorTypeOp,
443                     CurrentByteOffset);
444         break;
445
446     case PARSEOP_FIXEDIO:
447         Rnode = RsDoFixedIoDescriptor (DescriptorTypeOp,
448                     CurrentByteOffset);
449         break;
450
451     case PARSEOP_INTERRUPT:
452         Rnode = RsDoInterruptDescriptor (DescriptorTypeOp,
453                     CurrentByteOffset);
454         break;
455
456     case PARSEOP_IO:
457         Rnode = RsDoIoDescriptor (DescriptorTypeOp,
458                     CurrentByteOffset);
459         break;
460
461     case PARSEOP_IRQ:
462         Rnode = RsDoIrqDescriptor (DescriptorTypeOp,
463                     CurrentByteOffset);
464         break;
465
466     case PARSEOP_IRQNOFLAGS:
467         Rnode = RsDoIrqNoFlagsDescriptor (DescriptorTypeOp,
468                     CurrentByteOffset);
469         break;
470
471     case PARSEOP_MEMORY24:
472         Rnode = RsDoMemory24Descriptor (DescriptorTypeOp,
473                     CurrentByteOffset);
474         break;
475
476     case PARSEOP_MEMORY32:
477         Rnode = RsDoMemory32Descriptor (DescriptorTypeOp,
478                     CurrentByteOffset);
479         break;
480
481     case PARSEOP_MEMORY32FIXED:
482         Rnode = RsDoMemory32FixedDescriptor (DescriptorTypeOp,
483                     CurrentByteOffset);
484         break;
485
486     case PARSEOP_QWORDIO:
487         Rnode = RsDoQwordIoDescriptor (DescriptorTypeOp,
488                     CurrentByteOffset);
489         break;
490
491     case PARSEOP_QWORDMEMORY:
492         Rnode = RsDoQwordMemoryDescriptor (DescriptorTypeOp,
493                     CurrentByteOffset);
494         break;
495
496     case PARSEOP_QWORDSPACE:
497         Rnode = RsDoQwordSpaceDescriptor (DescriptorTypeOp,
498                     CurrentByteOffset);
499         break;
500
501     case PARSEOP_REGISTER:
502         Rnode = RsDoGeneralRegisterDescriptor (DescriptorTypeOp,
503                     CurrentByteOffset);
504         break;
505
506     case PARSEOP_STARTDEPENDENTFN:
507         switch (*State)
508         {
509         case ACPI_RSTATE_START_DEPENDENT:
510             AslError (ASL_ERROR, ASL_MSG_DEPENDENT_NESTING,
511                 DescriptorTypeOp, NULL);
512             break;
513
514         case ACPI_RSTATE_NORMAL:
515         case ACPI_RSTATE_DEPENDENT_LIST:
516         default:
517             break;
518         }
519
520         *State = ACPI_RSTATE_START_DEPENDENT;
521         Rnode = RsDoStartDependentDescriptor (DescriptorTypeOp,
522                     CurrentByteOffset);
523         *State = ACPI_RSTATE_DEPENDENT_LIST;
524         break;
525
526     case PARSEOP_STARTDEPENDENTFN_NOPRI:
527         switch (*State)
528         {
529         case ACPI_RSTATE_START_DEPENDENT:
530             AslError (ASL_ERROR, ASL_MSG_DEPENDENT_NESTING,
531                 DescriptorTypeOp, NULL);
532             break;
533
534         case ACPI_RSTATE_NORMAL:
535         case ACPI_RSTATE_DEPENDENT_LIST:
536         default:
537             break;
538         }
539
540         *State = ACPI_RSTATE_START_DEPENDENT;
541         Rnode = RsDoStartDependentNoPriDescriptor (DescriptorTypeOp,
542                     CurrentByteOffset);
543         *State = ACPI_RSTATE_DEPENDENT_LIST;
544         break;
545
546     case PARSEOP_VENDORLONG:
547         Rnode = RsDoVendorLargeDescriptor (DescriptorTypeOp,
548                     CurrentByteOffset);
549         break;
550
551     case PARSEOP_VENDORSHORT:
552         Rnode = RsDoVendorSmallDescriptor (DescriptorTypeOp,
553                     CurrentByteOffset);
554         break;
555
556     case PARSEOP_WORDBUSNUMBER:
557         Rnode = RsDoWordBusNumberDescriptor (DescriptorTypeOp,
558                     CurrentByteOffset);
559         break;
560
561     case PARSEOP_WORDIO:
562         Rnode = RsDoWordIoDescriptor (DescriptorTypeOp,
563                     CurrentByteOffset);
564         break;
565
566     case PARSEOP_WORDSPACE:
567         Rnode = RsDoWordSpaceDescriptor (DescriptorTypeOp,
568                     CurrentByteOffset);
569         break;
570
571     case PARSEOP_DEFAULT_ARG:
572         /* Just ignore any of these, they are used as fillers/placeholders */
573         break;
574
575     default:
576         printf ("Unknown resource descriptor type [%s]\n",
577                     DescriptorTypeOp->Asl.ParseOpName);
578         break;
579     }
580
581     /*
582      * Mark original node as unused, but head of a resource descriptor.
583      * This allows the resource to be installed in the namespace so that
584      * references to the descriptor can be resolved.
585      */
586     DescriptorTypeOp->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
587     DescriptorTypeOp->Asl.CompileFlags = NODE_IS_RESOURCE_DESC;
588     DescriptorTypeOp->Asl.Value.Integer = CurrentByteOffset;
589
590     if (Rnode)
591     {
592         DescriptorTypeOp->Asl.FinalAmlLength = Rnode->BufferLength;
593     }
594
595     return (Rnode);
596 }
597
598
599 /*******************************************************************************
600  *
601  * FUNCTION:    RsLinkDescriptorChain
602  *
603  * PARAMETERS:  PreviousRnode       - Pointer to the node that will be previous
604  *                                    to the linked node,  At exit, set to the
605  *                                    last node in the new chain.
606  *              Rnode               - Resource node to link into the list
607  *
608  * RETURN:      Cumulative buffer byte offset of the new segment of chain
609  *
610  * DESCRIPTION: Link a descriptor chain at the end of an existing chain.
611  *
612  ******************************************************************************/
613
614 UINT32
615 RsLinkDescriptorChain (
616     ASL_RESOURCE_NODE       **PreviousRnode,
617     ASL_RESOURCE_NODE       *Rnode)
618 {
619     ASL_RESOURCE_NODE       *LastRnode;
620     UINT32                  CurrentByteOffset;
621
622
623     /* Anything to do? */
624
625     if (!Rnode)
626     {
627         return 0;
628     }
629
630     /* Point the previous node to the new node */
631
632     (*PreviousRnode)->Next = Rnode;
633     CurrentByteOffset = Rnode->BufferLength;
634
635     /* Walk to the end of the chain headed by Rnode */
636
637     LastRnode = Rnode;
638     while (LastRnode->Next)
639     {
640         LastRnode = LastRnode->Next;
641         CurrentByteOffset += LastRnode->BufferLength;
642     }
643
644     /* Previous node becomes the last node in the chain */
645
646     *PreviousRnode = LastRnode;
647     return CurrentByteOffset;
648 }
649
650
651 /*******************************************************************************
652  *
653  * FUNCTION:    RsDoResourceTemplate
654  *
655  * PARAMETERS:  Op        - Parent of a resource template list
656  *
657  * RETURN:      None.  Sets input node to point to a list of AML code
658  *
659  * DESCRIPTION: Merge a list of resource descriptors into a single AML buffer,
660  *              in preparation for output to the AML output file.
661  *
662  ******************************************************************************/
663
664 void
665 RsDoResourceTemplate (
666     ACPI_PARSE_OBJECT       *Op)
667 {
668     ACPI_PARSE_OBJECT       *BufferLengthOp;
669     ACPI_PARSE_OBJECT       *BufferOp;
670     ACPI_PARSE_OBJECT       *DescriptorTypeOp;
671     ACPI_PARSE_OBJECT       *LastOp = NULL;
672     UINT32                  CurrentByteOffset = 0;
673     ASL_RESOURCE_NODE       HeadRnode;
674     ASL_RESOURCE_NODE       *PreviousRnode;
675     ASL_RESOURCE_NODE       *Rnode;
676     UINT8                   State;
677
678
679     /* Mark parent as containing a resource template */
680
681     if (Op->Asl.Parent)
682     {
683         Op->Asl.Parent->Asl.CompileFlags |= NODE_IS_RESOURCE_DESC;
684     }
685
686     /* ResourceTemplate Opcode is first (Op) */
687     /* Buffer Length node is first child */
688
689     BufferLengthOp = ASL_GET_CHILD_NODE (Op);
690
691     /* Buffer Op is first peer */
692
693     BufferOp = ASL_GET_PEER_NODE (BufferLengthOp);
694
695     /* First Descriptor type is next */
696
697     DescriptorTypeOp = ASL_GET_PEER_NODE (BufferOp);
698
699     /*
700      * Process all resource descriptors in the list
701      * Note: It is assumed that the EndTag node has been automatically
702      * inserted at the end of the template by the parser.
703      */
704     State = ACPI_RSTATE_NORMAL;
705     PreviousRnode = &HeadRnode;
706     while (DescriptorTypeOp)
707     {
708         DescriptorTypeOp->Asl.CompileFlags |= NODE_IS_RESOURCE_DESC;
709         Rnode = RsDoOneResourceDescriptor (DescriptorTypeOp, CurrentByteOffset,
710                     &State);
711
712         /*
713          * Update current byte offset to indicate the number of bytes from the
714          * start of the buffer.  Buffer can include multiple descriptors, we
715          * must keep track of the offset of not only each descriptor, but each
716          * element (field) within each descriptor as well.
717          */
718         CurrentByteOffset += RsLinkDescriptorChain (&PreviousRnode, Rnode);
719
720         /* Get the next descriptor in the list */
721
722         LastOp = DescriptorTypeOp;
723         DescriptorTypeOp = ASL_GET_PEER_NODE (DescriptorTypeOp);
724     }
725
726     if (State == ACPI_RSTATE_DEPENDENT_LIST)
727     {
728         if (LastOp)
729         {
730             LastOp = LastOp->Asl.Parent;
731         }
732         AslError (ASL_ERROR, ASL_MSG_MISSING_ENDDEPENDENT, LastOp, NULL);
733     }
734
735     /*
736      * Transform the nodes into the following
737      *
738      * Op           -> AML_BUFFER_OP
739      * First Child  -> BufferLength
740      * Second Child -> Descriptor Buffer (raw byte data)
741      */
742     Op->Asl.ParseOpcode               = PARSEOP_BUFFER;
743     Op->Asl.AmlOpcode                 = AML_BUFFER_OP;
744     Op->Asl.CompileFlags              = NODE_AML_PACKAGE | NODE_IS_RESOURCE_DESC;
745
746     BufferLengthOp->Asl.ParseOpcode   = PARSEOP_INTEGER;
747     BufferLengthOp->Asl.Value.Integer = CurrentByteOffset;
748     (void) OpcSetOptimalIntegerSize (BufferLengthOp);
749
750     BufferOp->Asl.ParseOpcode         = PARSEOP_RAW_DATA;
751     BufferOp->Asl.AmlOpcode           = AML_RAW_DATA_CHAIN;
752     BufferOp->Asl.AmlOpcodeLength     = 0;
753     BufferOp->Asl.AmlLength           = CurrentByteOffset;
754     BufferOp->Asl.Value.Buffer        = (UINT8 *) HeadRnode.Next;
755     BufferOp->Asl.CompileFlags       |= NODE_IS_RESOURCE_DATA;
756
757     return;
758 }
759
760