xref: /freebsd/sys/contrib/dev/acpica/compiler/aslresource.c (revision 39ee7a7a6bdd1557b1c3532abf60d139798ac88b)
1 /******************************************************************************
2  *
3  * Module Name: aslresource - Resource template/descriptor utilities
4  *
5  *****************************************************************************/
6 
7 /*
8  * Copyright (C) 2000 - 2015, Intel Corp.
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
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.
25  *
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.
29  *
30  * NO WARRANTY
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.
42  */
43 
44 #include <contrib/dev/acpica/compiler/aslcompiler.h>
45 #include "aslcompiler.y.h"
46 #include <contrib/dev/acpica/include/amlcode.h>
47 
48 
49 #define _COMPONENT          ACPI_COMPILER
50         ACPI_MODULE_NAME    ("aslresource")
51 
52 
53 /*******************************************************************************
54  *
55  * FUNCTION:    RsSmallAddressCheck
56  *
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
69  *
70  * RETURN:      None. Adds error messages to error log if necessary
71  *
72  * DESCRIPTION: Perform common value checks for "small" address descriptors.
73  *              Currently:
74  *                  Io, Memory24, Memory32
75  *
76  ******************************************************************************/
77 
78 void
79 RsSmallAddressCheck (
80     UINT8                   Type,
81     UINT32                  Minimum,
82     UINT32                  Maximum,
83     UINT32                  Length,
84     UINT32                  Alignment,
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)
90 {
91 
92     if (Gbl_NoResourceChecking)
93     {
94         return;
95     }
96 
97     /*
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.
101      *
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.
106      *
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.
110      *
111      * Note: for these descriptors, Alignment is allowed to be zero
112      */
113     if (!Minimum && !Maximum && !Length)
114     {
115         if (!Op->Asl.ExternalName)
116         {
117             /* No resource tag. Descriptor is fixed and is also illegal */
118 
119             AslError (ASL_ERROR, ASL_MSG_NULL_DESCRIPTOR, Op, NULL);
120         }
121 
122         return;
123     }
124 
125     /*
126      * Range checks for Memory24 and Memory32.
127      * IO descriptor has different definition of min/max, don't check.
128      */
129     if (Type != ACPI_RESOURCE_NAME_IO)
130     {
131         /* Basic checks on Min/Max/Length */
132 
133         if (Minimum > Maximum)
134         {
135             AslError (ASL_ERROR, ASL_MSG_INVALID_MIN_MAX, MinOp, NULL);
136         }
137         else if (Length > (Maximum - Minimum + 1))
138         {
139             AslError (ASL_ERROR, ASL_MSG_INVALID_LENGTH, LengthOp, NULL);
140         }
141 
142         /* Special case for Memory24, min/max values are compressed */
143 
144         if (Type == ACPI_RESOURCE_NAME_MEMORY24)
145         {
146             if (!Alignment) /* Alignment==0 means 64K alignment */
147             {
148                 Alignment = ACPI_UINT16_MAX + 1;
149             }
150 
151             Minimum <<= 8;
152             Maximum <<= 8;
153         }
154     }
155 
156     /* Alignment of zero is not in ACPI spec, but is used to mean byte acc */
157 
158     if (!Alignment)
159     {
160         Alignment = 1;
161     }
162 
163     /* Addresses must be an exact multiple of the alignment value */
164 
165     if (Minimum % Alignment)
166     {
167         AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, MinOp, NULL);
168     }
169     if (Maximum % Alignment)
170     {
171         AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, MaxOp, NULL);
172     }
173 }
174 
175 
176 /*******************************************************************************
177  *
178  * FUNCTION:    RsLargeAddressCheck
179  *
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:
185  *                                    _MIF, _MAF, _DEC
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
191  *
192  * RETURN:      None. Adds error messages to error log if necessary
193  *
194  * DESCRIPTION: Perform common value checks for "large" address descriptors.
195  *              Currently:
196  *                  WordIo,     WordBusNumber,  WordSpace
197  *                  DWordIo,    DWordMemory,    DWordSpace
198  *                  QWordIo,    QWordMemory,    QWordSpace
199  *                  ExtendedIo, ExtendedMemory, ExtendedSpace
200  *
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
204  *
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.
207  *
208  ******************************************************************************/
209 
210 void
211 RsLargeAddressCheck (
212     UINT64                  Minimum,
213     UINT64                  Maximum,
214     UINT64                  Length,
215     UINT64                  Granularity,
216     UINT8                   Flags,
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)
222 {
223 
224     if (Gbl_NoResourceChecking)
225     {
226         return;
227     }
228 
229     /*
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.
233      *
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.
238      *
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.
242      */
243     if (!Minimum && !Maximum && !Length && !Granularity)
244     {
245         if (!Op->Asl.ExternalName)
246         {
247             /* No resource tag. Descriptor is fixed and is also illegal */
248 
249             AslError (ASL_ERROR, ASL_MSG_NULL_DESCRIPTOR, Op, NULL);
250         }
251 
252         return;
253     }
254 
255     /* Basic checks on Min/Max/Length */
256 
257     if (Minimum > Maximum)
258     {
259         AslError (ASL_ERROR, ASL_MSG_INVALID_MIN_MAX, MinOp, NULL);
260         return;
261     }
262     else if (Length > (Maximum - Minimum + 1))
263     {
264         AslError (ASL_ERROR, ASL_MSG_INVALID_LENGTH, LengthOp, NULL);
265         return;
266     }
267 
268     /* If specified (non-zero), ensure granularity is a power-of-two minus one */
269 
270     if (Granularity)
271     {
272         if ((Granularity + 1) &
273              Granularity)
274         {
275             AslError (ASL_ERROR, ASL_MSG_INVALID_GRANULARITY, GranOp, NULL);
276             return;
277         }
278     }
279 
280     /*
281      * Check the various combinations of Length, MinFixed, and MaxFixed
282      */
283     if (Length)
284     {
285         /* Fixed non-zero length */
286 
287         switch (Flags & (ACPI_RESOURCE_FLAG_MIF | ACPI_RESOURCE_FLAG_MAF))
288         {
289         case 0:
290             /*
291              * Fixed length, variable locations (both _MIN and _MAX).
292              * Length must be a multiple of granularity
293              */
294             if (Granularity & Length)
295             {
296                 AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, LengthOp, NULL);
297             }
298             break;
299 
300         case (ACPI_RESOURCE_FLAG_MIF | ACPI_RESOURCE_FLAG_MAF):
301 
302             /* Fixed length, fixed location. Granularity must be zero */
303 
304             if (Granularity != 0)
305             {
306                 AslError (ASL_ERROR, ASL_MSG_INVALID_GRAN_FIXED, GranOp, NULL);
307             }
308 
309             /* Length must be exactly the size of the min/max window */
310 
311             if (Length != (Maximum - Minimum + 1))
312             {
313                 AslError (ASL_ERROR, ASL_MSG_INVALID_LENGTH_FIXED, LengthOp, NULL);
314             }
315             break;
316 
317         /* All other combinations are invalid */
318 
319         case ACPI_RESOURCE_FLAG_MIF:
320         case ACPI_RESOURCE_FLAG_MAF:
321         default:
322 
323             AslError (ASL_ERROR, ASL_MSG_INVALID_ADDR_FLAGS, LengthOp, NULL);
324         }
325     }
326     else
327     {
328         /* Variable length (length==0) */
329 
330         switch (Flags & (ACPI_RESOURCE_FLAG_MIF | ACPI_RESOURCE_FLAG_MAF))
331         {
332         case 0:
333             /*
334              * Both _MIN and _MAX are variable.
335              * No additional requirements, just exit
336              */
337             break;
338 
339         case ACPI_RESOURCE_FLAG_MIF:
340 
341             /* _MIN is fixed. _MIN must be multiple of _GRA */
342 
343             /*
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.
347              */
348             if (Granularity & Minimum)
349             {
350                 AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, MinOp, NULL);
351             }
352             break;
353 
354         case ACPI_RESOURCE_FLAG_MAF:
355 
356             /* _MAX is fixed. (_MAX + 1) must be multiple of _GRA */
357 
358             if (Granularity & (Maximum + 1))
359             {
360                 AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, MaxOp, "-1");
361             }
362             break;
363 
364         /* Both MIF/MAF set is invalid if length is zero */
365 
366         case (ACPI_RESOURCE_FLAG_MIF | ACPI_RESOURCE_FLAG_MAF):
367         default:
368 
369             AslError (ASL_ERROR, ASL_MSG_INVALID_ADDR_FLAGS, LengthOp, NULL);
370         }
371     }
372 }
373 
374 
375 /*******************************************************************************
376  *
377  * FUNCTION:    RsGetStringDataLength
378  *
379  * PARAMETERS:  InitializerOp     - Start of a subtree of init nodes
380  *
381  * RETURN:      Valid string length if a string node is found (otherwise 0)
382  *
383  * DESCRIPTION: In a list of peer nodes, find the first one that contains a
384  *              string and return the length of the string.
385  *
386  ******************************************************************************/
387 
388 UINT16
389 RsGetStringDataLength (
390     ACPI_PARSE_OBJECT       *InitializerOp)
391 {
392 
393     while (InitializerOp)
394     {
395         if (InitializerOp->Asl.ParseOpcode == PARSEOP_STRING_LITERAL)
396         {
397             return ((UINT16) (strlen (InitializerOp->Asl.Value.String) + 1));
398         }
399         InitializerOp = ASL_GET_PEER_NODE (InitializerOp);
400     }
401 
402     return (0);
403 }
404 
405 
406 /*******************************************************************************
407  *
408  * FUNCTION:    RsAllocateResourceNode
409  *
410  * PARAMETERS:  Size        - Size of node in bytes
411  *
412  * RETURN:      The allocated node - aborts on allocation failure
413  *
414  * DESCRIPTION: Allocate a resource description node and the resource
415  *              descriptor itself (the nodes are used to link descriptors).
416  *
417  ******************************************************************************/
418 
419 ASL_RESOURCE_NODE *
420 RsAllocateResourceNode (
421     UINT32                  Size)
422 {
423     ASL_RESOURCE_NODE       *Rnode;
424 
425 
426     /* Allocate the node */
427 
428     Rnode = UtLocalCalloc (sizeof (ASL_RESOURCE_NODE));
429 
430     /* Allocate the resource descriptor itself */
431 
432     Rnode->Buffer = UtLocalCalloc (Size);
433     Rnode->BufferLength = Size;
434 
435     return (Rnode);
436 }
437 
438 
439 /*******************************************************************************
440  *
441  * FUNCTION:    RsCreateResourceField
442  *
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
449  *
450  * RETURN:      None, sets fields within the input node
451  *
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
455  *
456  ******************************************************************************/
457 
458 void
459 RsCreateResourceField (
460     ACPI_PARSE_OBJECT       *Op,
461     char                    *Name,
462     UINT32                  ByteOffset,
463     UINT32                  BitOffset,
464     UINT32                  BitLength)
465 {
466 
467     Op->Asl.ExternalName = Name;
468     Op->Asl.CompileFlags |= NODE_IS_RESOURCE_FIELD;
469 
470 
471     Op->Asl.Value.Tag.BitOffset = (ByteOffset * 8) + BitOffset;
472     Op->Asl.Value.Tag.BitLength = BitLength;
473 }
474 
475 
476 /*******************************************************************************
477  *
478  * FUNCTION:    RsSetFlagBits
479  *
480  * PARAMETERS:  *Flags          - Pointer to the flag byte
481  *              Op              - Flag initialization node
482  *              Position        - Bit position within the flag byte
483  *              Default         - Used if the node is DEFAULT.
484  *
485  * RETURN:      Sets bits within the *Flags output byte.
486  *
487  * DESCRIPTION: Set a bit in a cumulative flags word from an initialization
488  *              node. Will use a default value if the node is DEFAULT, meaning
489  *              that no value was specified in the ASL. Used to merge multiple
490  *              keywords into a single flags byte.
491  *
492  ******************************************************************************/
493 
494 void
495 RsSetFlagBits (
496     UINT8                   *Flags,
497     ACPI_PARSE_OBJECT       *Op,
498     UINT8                   Position,
499     UINT8                   DefaultBit)
500 {
501 
502     if (Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)
503     {
504         /* Use the default bit */
505 
506         *Flags |= (DefaultBit << Position);
507     }
508     else
509     {
510         /* Use the bit specified in the initialization node */
511 
512         *Flags |= (((UINT8) Op->Asl.Value.Integer) << Position);
513     }
514 }
515 
516 
517 void
518 RsSetFlagBits16 (
519     UINT16                  *Flags,
520     ACPI_PARSE_OBJECT       *Op,
521     UINT8                   Position,
522     UINT8                   DefaultBit)
523 {
524 
525     if (Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)
526     {
527         /* Use the default bit */
528 
529         *Flags |= (DefaultBit << Position);
530     }
531     else
532     {
533         /* Use the bit specified in the initialization node */
534 
535         *Flags |= (((UINT16) Op->Asl.Value.Integer) << Position);
536     }
537 }
538 
539 
540 /*******************************************************************************
541  *
542  * FUNCTION:    RsCompleteNodeAndGetNext
543  *
544  * PARAMETERS:  Op            - Resource node to be completed
545  *
546  * RETURN:      The next peer to the input node.
547  *
548  * DESCRIPTION: Mark the current node completed and return the next peer.
549  *              The node ParseOpcode is set to DEFAULT_ARG, meaning that
550  *              this node is to be ignored from now on.
551  *
552  ******************************************************************************/
553 
554 ACPI_PARSE_OBJECT *
555 RsCompleteNodeAndGetNext (
556     ACPI_PARSE_OBJECT       *Op)
557 {
558 
559     /* Mark this node unused */
560 
561     Op->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
562 
563     /* Move on to the next peer node in the initializer list */
564 
565     return (ASL_GET_PEER_NODE (Op));
566 }
567 
568 
569 /*******************************************************************************
570  *
571  * FUNCTION:    RsCheckListForDuplicates
572  *
573  * PARAMETERS:  Op                  - First op in the initializer list
574  *
575  * RETURN:      None
576  *
577  * DESCRIPTION: Check an initializer list for duplicate values. Emits an error
578  *              if any duplicates are found.
579  *
580  ******************************************************************************/
581 
582 void
583 RsCheckListForDuplicates (
584     ACPI_PARSE_OBJECT       *Op)
585 {
586     ACPI_PARSE_OBJECT       *NextValueOp = Op;
587     ACPI_PARSE_OBJECT       *NextOp;
588     UINT32                  Value;
589 
590 
591     if (!Op)
592     {
593         return;
594     }
595 
596     /* Search list once for each value in the list */
597 
598     while (NextValueOp)
599     {
600         Value = (UINT32) NextValueOp->Asl.Value.Integer;
601 
602         /* Compare this value to all remaining values in the list */
603 
604         NextOp = ASL_GET_PEER_NODE (NextValueOp);
605         while (NextOp)
606         {
607             if (NextOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
608             {
609                 /* Compare values */
610 
611                 if (Value == (UINT32) NextOp->Asl.Value.Integer)
612                 {
613                     /* Emit error only once per duplicate node */
614 
615                     if (!(NextOp->Asl.CompileFlags & NODE_IS_DUPLICATE))
616                     {
617                         NextOp->Asl.CompileFlags |= NODE_IS_DUPLICATE;
618                         AslError (ASL_ERROR, ASL_MSG_DUPLICATE_ITEM,
619                             NextOp, NULL);
620                     }
621                 }
622             }
623 
624             NextOp = ASL_GET_PEER_NODE (NextOp);
625         }
626 
627         NextValueOp = ASL_GET_PEER_NODE (NextValueOp);
628     }
629 }
630 
631 
632 /*******************************************************************************
633  *
634  * FUNCTION:    RsDoOneResourceDescriptor
635  *
636  * PARAMETERS:  DescriptorTypeOp    - Parent parse node of the descriptor
637  *              CurrentByteOffset   - Offset in the resource descriptor
638  *                                    buffer.
639  *
640  * RETURN:      A valid resource node for the descriptor
641  *
642  * DESCRIPTION: Dispatches the processing of one resource descriptor
643  *
644  ******************************************************************************/
645 
646 ASL_RESOURCE_NODE *
647 RsDoOneResourceDescriptor (
648     ASL_RESOURCE_INFO       *Info,
649     UINT8                   *State)
650 {
651     ASL_RESOURCE_NODE       *Rnode = NULL;
652 
653 
654     /* Construct the resource */
655 
656     switch (Info->DescriptorTypeOp->Asl.ParseOpcode)
657     {
658     case PARSEOP_DMA:
659 
660         Rnode = RsDoDmaDescriptor (Info);
661         break;
662 
663     case PARSEOP_FIXEDDMA:
664 
665         Rnode = RsDoFixedDmaDescriptor (Info);
666         break;
667 
668     case PARSEOP_DWORDIO:
669 
670         Rnode = RsDoDwordIoDescriptor (Info);
671         break;
672 
673     case PARSEOP_DWORDMEMORY:
674 
675         Rnode = RsDoDwordMemoryDescriptor (Info);
676         break;
677 
678     case PARSEOP_DWORDSPACE:
679 
680         Rnode = RsDoDwordSpaceDescriptor (Info);
681         break;
682 
683     case PARSEOP_ENDDEPENDENTFN:
684 
685         switch (*State)
686         {
687         case ACPI_RSTATE_NORMAL:
688 
689             AslError (ASL_ERROR, ASL_MSG_MISSING_STARTDEPENDENT,
690                 Info->DescriptorTypeOp, NULL);
691             break;
692 
693         case ACPI_RSTATE_START_DEPENDENT:
694 
695             AslError (ASL_ERROR, ASL_MSG_DEPENDENT_NESTING,
696                 Info->DescriptorTypeOp, NULL);
697             break;
698 
699         case ACPI_RSTATE_DEPENDENT_LIST:
700         default:
701 
702             break;
703         }
704 
705         *State = ACPI_RSTATE_NORMAL;
706         Rnode = RsDoEndDependentDescriptor (Info);
707         break;
708 
709     case PARSEOP_ENDTAG:
710 
711         Rnode = RsDoEndTagDescriptor (Info);
712         break;
713 
714     case PARSEOP_EXTENDEDIO:
715 
716         Rnode = RsDoExtendedIoDescriptor (Info);
717         break;
718 
719     case PARSEOP_EXTENDEDMEMORY:
720 
721         Rnode = RsDoExtendedMemoryDescriptor (Info);
722         break;
723 
724     case PARSEOP_EXTENDEDSPACE:
725 
726         Rnode = RsDoExtendedSpaceDescriptor (Info);
727         break;
728 
729     case PARSEOP_FIXEDIO:
730 
731         Rnode = RsDoFixedIoDescriptor (Info);
732         break;
733 
734     case PARSEOP_INTERRUPT:
735 
736         Rnode = RsDoInterruptDescriptor (Info);
737         break;
738 
739     case PARSEOP_IO:
740 
741         Rnode = RsDoIoDescriptor (Info);
742         break;
743 
744     case PARSEOP_IRQ:
745 
746         Rnode = RsDoIrqDescriptor (Info);
747         break;
748 
749     case PARSEOP_IRQNOFLAGS:
750 
751         Rnode = RsDoIrqNoFlagsDescriptor (Info);
752         break;
753 
754     case PARSEOP_MEMORY24:
755 
756         Rnode = RsDoMemory24Descriptor (Info);
757         break;
758 
759     case PARSEOP_MEMORY32:
760 
761         Rnode = RsDoMemory32Descriptor (Info);
762         break;
763 
764     case PARSEOP_MEMORY32FIXED:
765 
766         Rnode = RsDoMemory32FixedDescriptor (Info);
767         break;
768 
769     case PARSEOP_QWORDIO:
770 
771         Rnode = RsDoQwordIoDescriptor (Info);
772         break;
773 
774     case PARSEOP_QWORDMEMORY:
775 
776         Rnode = RsDoQwordMemoryDescriptor (Info);
777         break;
778 
779     case PARSEOP_QWORDSPACE:
780 
781         Rnode = RsDoQwordSpaceDescriptor (Info);
782         break;
783 
784     case PARSEOP_REGISTER:
785 
786         Rnode = RsDoGeneralRegisterDescriptor (Info);
787         break;
788 
789     case PARSEOP_STARTDEPENDENTFN:
790 
791         switch (*State)
792         {
793         case ACPI_RSTATE_START_DEPENDENT:
794 
795             AslError (ASL_ERROR, ASL_MSG_DEPENDENT_NESTING,
796                 Info->DescriptorTypeOp, NULL);
797             break;
798 
799         case ACPI_RSTATE_NORMAL:
800         case ACPI_RSTATE_DEPENDENT_LIST:
801         default:
802 
803             break;
804         }
805 
806         *State = ACPI_RSTATE_START_DEPENDENT;
807         Rnode = RsDoStartDependentDescriptor (Info);
808         *State = ACPI_RSTATE_DEPENDENT_LIST;
809         break;
810 
811     case PARSEOP_STARTDEPENDENTFN_NOPRI:
812 
813         switch (*State)
814         {
815         case ACPI_RSTATE_START_DEPENDENT:
816 
817             AslError (ASL_ERROR, ASL_MSG_DEPENDENT_NESTING,
818                 Info->DescriptorTypeOp, NULL);
819             break;
820 
821         case ACPI_RSTATE_NORMAL:
822         case ACPI_RSTATE_DEPENDENT_LIST:
823         default:
824 
825             break;
826         }
827 
828         *State = ACPI_RSTATE_START_DEPENDENT;
829         Rnode = RsDoStartDependentNoPriDescriptor (Info);
830         *State = ACPI_RSTATE_DEPENDENT_LIST;
831         break;
832 
833     case PARSEOP_VENDORLONG:
834 
835         Rnode = RsDoVendorLargeDescriptor (Info);
836         break;
837 
838     case PARSEOP_VENDORSHORT:
839 
840         Rnode = RsDoVendorSmallDescriptor (Info);
841         break;
842 
843     case PARSEOP_WORDBUSNUMBER:
844 
845         Rnode = RsDoWordBusNumberDescriptor (Info);
846         break;
847 
848     case PARSEOP_WORDIO:
849 
850         Rnode = RsDoWordIoDescriptor (Info);
851         break;
852 
853     case PARSEOP_WORDSPACE:
854 
855         Rnode = RsDoWordSpaceDescriptor (Info);
856         break;
857 
858     case PARSEOP_GPIO_INT:
859 
860         Rnode = RsDoGpioIntDescriptor (Info);
861         break;
862 
863     case PARSEOP_GPIO_IO:
864 
865         Rnode = RsDoGpioIoDescriptor (Info);
866         break;
867 
868     case PARSEOP_I2C_SERIALBUS:
869 
870         Rnode = RsDoI2cSerialBusDescriptor (Info);
871         break;
872 
873     case PARSEOP_SPI_SERIALBUS:
874 
875         Rnode = RsDoSpiSerialBusDescriptor (Info);
876         break;
877 
878     case PARSEOP_UART_SERIALBUS:
879 
880         Rnode = RsDoUartSerialBusDescriptor (Info);
881         break;
882 
883     case PARSEOP_DEFAULT_ARG:
884 
885         /* Just ignore any of these, they are used as fillers/placeholders */
886         break;
887 
888     default:
889 
890         printf ("Unknown resource descriptor type [%s]\n",
891                     Info->DescriptorTypeOp->Asl.ParseOpName);
892         break;
893     }
894 
895     /*
896      * Mark original node as unused, but head of a resource descriptor.
897      * This allows the resource to be installed in the namespace so that
898      * references to the descriptor can be resolved.
899      */
900     Info->DescriptorTypeOp->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
901     Info->DescriptorTypeOp->Asl.CompileFlags = NODE_IS_RESOURCE_DESC;
902     Info->DescriptorTypeOp->Asl.Value.Integer = Info->CurrentByteOffset;
903 
904     if (Rnode)
905     {
906         Info->DescriptorTypeOp->Asl.FinalAmlLength = Rnode->BufferLength;
907         Info->DescriptorTypeOp->Asl.Extra = ((AML_RESOURCE *) Rnode->Buffer)->DescriptorType;
908     }
909 
910     return (Rnode);
911 }
912 
913 
914 /*******************************************************************************
915  *
916  * FUNCTION:    RsLinkDescriptorChain
917  *
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
922  *
923  * RETURN:      Cumulative buffer byte offset of the new segment of chain
924  *
925  * DESCRIPTION: Link a descriptor chain at the end of an existing chain.
926  *
927  ******************************************************************************/
928 
929 UINT32
930 RsLinkDescriptorChain (
931     ASL_RESOURCE_NODE       **PreviousRnode,
932     ASL_RESOURCE_NODE       *Rnode)
933 {
934     ASL_RESOURCE_NODE       *LastRnode;
935     UINT32                  CurrentByteOffset;
936 
937 
938     /* Anything to do? */
939 
940     if (!Rnode)
941     {
942         return (0);
943     }
944 
945     /* Point the previous node to the new node */
946 
947     (*PreviousRnode)->Next = Rnode;
948     CurrentByteOffset = Rnode->BufferLength;
949 
950     /* Walk to the end of the chain headed by Rnode */
951 
952     LastRnode = Rnode;
953     while (LastRnode->Next)
954     {
955         LastRnode = LastRnode->Next;
956         CurrentByteOffset += LastRnode->BufferLength;
957     }
958 
959     /* Previous node becomes the last node in the chain */
960 
961     *PreviousRnode = LastRnode;
962     return (CurrentByteOffset);
963 }
964 
965 
966 /*******************************************************************************
967  *
968  * FUNCTION:    RsDoResourceTemplate
969  *
970  * PARAMETERS:  Op        - Parent of a resource template list
971  *
972  * RETURN:      None. Sets input node to point to a list of AML code
973  *
974  * DESCRIPTION: Merge a list of resource descriptors into a single AML buffer,
975  *              in preparation for output to the AML output file.
976  *
977  ******************************************************************************/
978 
979 void
980 RsDoResourceTemplate (
981     ACPI_PARSE_OBJECT       *Op)
982 {
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;
992     UINT8                   State;
993 
994 
995     /* Mark parent as containing a resource template */
996 
997     if (Op->Asl.Parent)
998     {
999         Op->Asl.Parent->Asl.CompileFlags |= NODE_IS_RESOURCE_DESC;
1000     }
1001 
1002     /* ResourceTemplate Opcode is first (Op) */
1003     /* Buffer Length node is first child */
1004 
1005     BufferLengthOp = ASL_GET_CHILD_NODE (Op);
1006 
1007     /* Buffer Op is first peer */
1008 
1009     BufferOp = ASL_GET_PEER_NODE (BufferLengthOp);
1010 
1011     /* First Descriptor type is next */
1012 
1013     DescriptorTypeOp = ASL_GET_PEER_NODE (BufferOp);
1014 
1015     /*
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.
1019      */
1020     State = ACPI_RSTATE_NORMAL;
1021     PreviousRnode = &HeadRnode;
1022     while (DescriptorTypeOp)
1023     {
1024         /* Save information for optional mapfile */
1025 
1026         if (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONNECTION)
1027         {
1028             Info.MappingOp = Op->Asl.Parent;
1029         }
1030         else
1031         {
1032             Info.MappingOp = DescriptorTypeOp;
1033         }
1034 
1035         Info.DescriptorTypeOp = DescriptorTypeOp;
1036         Info.CurrentByteOffset = CurrentByteOffset;
1037 
1038         DescriptorTypeOp->Asl.CompileFlags |= NODE_IS_RESOURCE_DESC;
1039         Rnode = RsDoOneResourceDescriptor (&Info, &State);
1040 
1041         /*
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.
1046          */
1047         CurrentByteOffset += RsLinkDescriptorChain (&PreviousRnode, Rnode);
1048 
1049         /* Get the next descriptor in the list */
1050 
1051         LastOp = DescriptorTypeOp;
1052         DescriptorTypeOp = ASL_GET_PEER_NODE (DescriptorTypeOp);
1053     }
1054 
1055     if (State == ACPI_RSTATE_DEPENDENT_LIST)
1056     {
1057         if (LastOp)
1058         {
1059             LastOp = LastOp->Asl.Parent;
1060         }
1061         AslError (ASL_ERROR, ASL_MSG_MISSING_ENDDEPENDENT, LastOp, NULL);
1062     }
1063 
1064     /*
1065      * Transform the nodes into the following
1066      *
1067      * Op           -> AML_BUFFER_OP
1068      * First Child  -> BufferLength
1069      * Second Child -> Descriptor Buffer (raw byte data)
1070      */
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);
1075 
1076     BufferLengthOp->Asl.ParseOpcode   = PARSEOP_INTEGER;
1077     BufferLengthOp->Asl.Value.Integer = CurrentByteOffset;
1078     (void) OpcSetOptimalIntegerSize (BufferLengthOp);
1079     UtSetParseOpName (BufferLengthOp);
1080 
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);
1088 
1089     return;
1090 }
1091