xref: /freebsd/sys/contrib/dev/acpica/components/resources/rsmisc.c (revision 8bcb0991864975618c09697b1aca10683346d9f0)
1 /*******************************************************************************
2  *
3  * Module Name: rsmisc - Miscellaneous resource descriptors
4  *
5  ******************************************************************************/
6 
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2020, Intel Corp.
12  * All rights reserved.
13  *
14  * 2. License
15  *
16  * 2.1. This is your license from Intel Corp. under its intellectual property
17  * rights. You may have additional license terms from the party that provided
18  * you this software, covering your right to use that party's intellectual
19  * property rights.
20  *
21  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22  * copy of the source code appearing in this file ("Covered Code") an
23  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24  * base code distributed originally by Intel ("Original Intel Code") to copy,
25  * make derivatives, distribute, use and display any portion of the Covered
26  * Code in any form, with the right to sublicense such rights; and
27  *
28  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29  * license (with the right to sublicense), under only those claims of Intel
30  * patents that are infringed by the Original Intel Code, to make, use, sell,
31  * offer to sell, and import the Covered Code and derivative works thereof
32  * solely to the minimum extent necessary to exercise the above copyright
33  * license, and in no event shall the patent license extend to any additions
34  * to or modifications of the Original Intel Code. No other license or right
35  * is granted directly or by implication, estoppel or otherwise;
36  *
37  * The above copyright and patent license is granted only if the following
38  * conditions are met:
39  *
40  * 3. Conditions
41  *
42  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43  * Redistribution of source code of any substantial portion of the Covered
44  * Code or modification with rights to further distribute source must include
45  * the above Copyright Notice, the above License, this list of Conditions,
46  * and the following Disclaimer and Export Compliance provision. In addition,
47  * Licensee must cause all Covered Code to which Licensee contributes to
48  * contain a file documenting the changes Licensee made to create that Covered
49  * Code and the date of any change. Licensee must include in that file the
50  * documentation of any changes made by any predecessor Licensee. Licensee
51  * must include a prominent statement that the modification is derived,
52  * directly or indirectly, from Original Intel Code.
53  *
54  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55  * Redistribution of source code of any substantial portion of the Covered
56  * Code or modification without rights to further distribute source must
57  * include the following Disclaimer and Export Compliance provision in the
58  * documentation and/or other materials provided with distribution. In
59  * addition, Licensee may not authorize further sublicense of source of any
60  * portion of the Covered Code, and must include terms to the effect that the
61  * license from Licensee to its licensee is limited to the intellectual
62  * property embodied in the software Licensee provides to its licensee, and
63  * not to intellectual property embodied in modifications its licensee may
64  * make.
65  *
66  * 3.3. Redistribution of Executable. Redistribution in executable form of any
67  * substantial portion of the Covered Code or modification must reproduce the
68  * above Copyright Notice, and the following Disclaimer and Export Compliance
69  * provision in the documentation and/or other materials provided with the
70  * distribution.
71  *
72  * 3.4. Intel retains all right, title, and interest in and to the Original
73  * Intel Code.
74  *
75  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76  * Intel shall be used in advertising or otherwise to promote the sale, use or
77  * other dealings in products derived from or relating to the Covered Code
78  * without prior written authorization from Intel.
79  *
80  * 4. Disclaimer and Export Compliance
81  *
82  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88  * PARTICULAR PURPOSE.
89  *
90  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97  * LIMITED REMEDY.
98  *
99  * 4.3. Licensee shall not export, either directly or indirectly, any of this
100  * software or system incorporating such software without first obtaining any
101  * required license or other approval from the U. S. Department of Commerce or
102  * any other agency or department of the United States Government. In the
103  * event Licensee exports any such software from the United States or
104  * re-exports any such software from a foreign destination, Licensee shall
105  * ensure that the distribution and export/re-export of the software is in
106  * compliance with all laws, regulations, orders, or other restrictions of the
107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108  * any of its subsidiaries will export/re-export any technical data, process,
109  * software, or service, directly or indirectly, to any country for which the
110  * United States government or any agency thereof requires an export license,
111  * other governmental approval, or letter of assurance, without first obtaining
112  * such license, approval or letter.
113  *
114  *****************************************************************************
115  *
116  * Alternatively, you may choose to be licensed under the terms of the
117  * following license:
118  *
119  * Redistribution and use in source and binary forms, with or without
120  * modification, are permitted provided that the following conditions
121  * are met:
122  * 1. Redistributions of source code must retain the above copyright
123  *    notice, this list of conditions, and the following disclaimer,
124  *    without modification.
125  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126  *    substantially similar to the "NO WARRANTY" disclaimer below
127  *    ("Disclaimer") and any redistribution must be conditioned upon
128  *    including a substantially similar Disclaimer requirement for further
129  *    binary redistribution.
130  * 3. Neither the names of the above-listed copyright holders nor the names
131  *    of any contributors may be used to endorse or promote products derived
132  *    from this software without specific prior written permission.
133  *
134  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145  *
146  * Alternatively, you may choose to be licensed under the terms of the
147  * GNU General Public License ("GPL") version 2 as published by the Free
148  * Software Foundation.
149  *
150  *****************************************************************************/
151 
152 #include <contrib/dev/acpica/include/acpi.h>
153 #include <contrib/dev/acpica/include/accommon.h>
154 #include <contrib/dev/acpica/include/acresrc.h>
155 
156 #define _COMPONENT          ACPI_RESOURCES
157         ACPI_MODULE_NAME    ("rsmisc")
158 
159 
160 #define INIT_RESOURCE_TYPE(i)       i->ResourceOffset
161 #define INIT_RESOURCE_LENGTH(i)     i->AmlOffset
162 #define INIT_TABLE_LENGTH(i)        i->Value
163 
164 #define COMPARE_OPCODE(i)           i->ResourceOffset
165 #define COMPARE_TARGET(i)           i->AmlOffset
166 #define COMPARE_VALUE(i)            i->Value
167 
168 
169 /*******************************************************************************
170  *
171  * FUNCTION:    AcpiRsConvertAmlToResource
172  *
173  * PARAMETERS:  Resource            - Pointer to the resource descriptor
174  *              Aml                 - Where the AML descriptor is returned
175  *              Info                - Pointer to appropriate conversion table
176  *
177  * RETURN:      Status
178  *
179  * DESCRIPTION: Convert an external AML resource descriptor to the corresponding
180  *              internal resource descriptor
181  *
182  ******************************************************************************/
183 
184 ACPI_STATUS
185 AcpiRsConvertAmlToResource (
186     ACPI_RESOURCE           *Resource,
187     AML_RESOURCE            *Aml,
188     ACPI_RSCONVERT_INFO     *Info)
189 {
190     ACPI_RS_LENGTH          AmlResourceLength;
191     void                    *Source;
192     void                    *Destination;
193     char                    *Target;
194     UINT8                   Count;
195     UINT8                   FlagsMode = FALSE;
196     UINT16                  ItemCount = 0;
197     UINT16                  Temp16 = 0;
198 
199 
200     ACPI_FUNCTION_TRACE (RsConvertAmlToResource);
201 
202 
203     if (!Info)
204     {
205         return_ACPI_STATUS (AE_BAD_PARAMETER);
206     }
207 
208     if (((ACPI_SIZE) Resource) & 0x3)
209     {
210         /* Each internal resource struct is expected to be 32-bit aligned */
211 
212         ACPI_WARNING ((AE_INFO,
213             "Misaligned resource pointer (get): %p Type 0x%2.2X Length %u",
214             Resource, Resource->Type, Resource->Length));
215     }
216 
217     /* Extract the resource Length field (does not include header length) */
218 
219     AmlResourceLength = AcpiUtGetResourceLength (Aml);
220 
221     /*
222      * First table entry must be ACPI_RSC_INITxxx and must contain the
223      * table length (# of table entries)
224      */
225     Count = INIT_TABLE_LENGTH (Info);
226     while (Count)
227     {
228         /*
229          * Source is the external AML byte stream buffer,
230          * destination is the internal resource descriptor
231          */
232         Source = ACPI_ADD_PTR (void, Aml, Info->AmlOffset);
233         Destination = ACPI_ADD_PTR (void, Resource, Info->ResourceOffset);
234 
235         switch (Info->Opcode)
236         {
237         case ACPI_RSC_INITGET:
238             /*
239              * Get the resource type and the initial (minimum) length
240              */
241             memset (Resource, 0, INIT_RESOURCE_LENGTH (Info));
242             Resource->Type = INIT_RESOURCE_TYPE (Info);
243             Resource->Length = INIT_RESOURCE_LENGTH (Info);
244             break;
245 
246         case ACPI_RSC_INITSET:
247             break;
248 
249         case ACPI_RSC_FLAGINIT:
250 
251             FlagsMode = TRUE;
252             break;
253 
254         case ACPI_RSC_1BITFLAG:
255             /*
256              * Mask and shift the flag bit
257              */
258             ACPI_SET8 (Destination,
259                 ((ACPI_GET8 (Source) >> Info->Value) & 0x01));
260             break;
261 
262         case ACPI_RSC_2BITFLAG:
263             /*
264              * Mask and shift the flag bits
265              */
266             ACPI_SET8 (Destination,
267                 ((ACPI_GET8 (Source) >> Info->Value) & 0x03));
268             break;
269 
270         case ACPI_RSC_3BITFLAG:
271             /*
272              * Mask and shift the flag bits
273              */
274             ACPI_SET8 (Destination,
275                 ((ACPI_GET8 (Source) >> Info->Value) & 0x07));
276             break;
277 
278         case ACPI_RSC_COUNT:
279 
280             ItemCount = ACPI_GET8 (Source);
281             ACPI_SET8 (Destination, ItemCount);
282 
283             Resource->Length = Resource->Length +
284                 (Info->Value * (ItemCount - 1));
285             break;
286 
287         case ACPI_RSC_COUNT16:
288 
289             ItemCount = AmlResourceLength;
290             ACPI_SET16 (Destination, ItemCount);
291 
292             Resource->Length = Resource->Length +
293                 (Info->Value * (ItemCount - 1));
294             break;
295 
296         case ACPI_RSC_COUNT_GPIO_PIN:
297 
298             Target = ACPI_ADD_PTR (void, Aml, Info->Value);
299             ItemCount = ACPI_GET16 (Target) - ACPI_GET16 (Source);
300 
301             Resource->Length = Resource->Length + ItemCount;
302             ItemCount = ItemCount / 2;
303             ACPI_SET16 (Destination, ItemCount);
304             break;
305 
306         case ACPI_RSC_COUNT_GPIO_VEN:
307 
308             ItemCount = ACPI_GET8 (Source);
309             ACPI_SET8 (Destination, ItemCount);
310 
311             Resource->Length = Resource->Length + (Info->Value * ItemCount);
312             break;
313 
314         case ACPI_RSC_COUNT_GPIO_RES:
315             /*
316              * Vendor data is optional (length/offset may both be zero)
317              * Examine vendor data length field first
318              */
319             Target = ACPI_ADD_PTR (void, Aml, (Info->Value + 2));
320             if (ACPI_GET16 (Target))
321             {
322                 /* Use vendor offset to get resource source length */
323 
324                 Target = ACPI_ADD_PTR (void, Aml, Info->Value);
325                 ItemCount = ACPI_GET16 (Target) - ACPI_GET16 (Source);
326             }
327             else
328             {
329                 /* No vendor data to worry about */
330 
331                 ItemCount = Aml->LargeHeader.ResourceLength +
332                     sizeof (AML_RESOURCE_LARGE_HEADER) -
333                     ACPI_GET16 (Source);
334             }
335 
336             Resource->Length = Resource->Length + ItemCount;
337             ACPI_SET16 (Destination, ItemCount);
338             break;
339 
340         case ACPI_RSC_COUNT_SERIAL_VEN:
341 
342             ItemCount = ACPI_GET16 (Source) - Info->Value;
343 
344             Resource->Length = Resource->Length + ItemCount;
345             ACPI_SET16 (Destination, ItemCount);
346             break;
347 
348         case ACPI_RSC_COUNT_SERIAL_RES:
349 
350             ItemCount = (AmlResourceLength +
351                 sizeof (AML_RESOURCE_LARGE_HEADER)) -
352                 ACPI_GET16 (Source) - Info->Value;
353 
354             Resource->Length = Resource->Length + ItemCount;
355             ACPI_SET16 (Destination, ItemCount);
356             break;
357 
358         case ACPI_RSC_LENGTH:
359 
360             Resource->Length = Resource->Length + Info->Value;
361             break;
362 
363         case ACPI_RSC_MOVE8:
364         case ACPI_RSC_MOVE16:
365         case ACPI_RSC_MOVE32:
366         case ACPI_RSC_MOVE64:
367             /*
368              * Raw data move. Use the Info value field unless ItemCount has
369              * been previously initialized via a COUNT opcode
370              */
371             if (Info->Value)
372             {
373                 ItemCount = Info->Value;
374             }
375             AcpiRsMoveData (Destination, Source, ItemCount, Info->Opcode);
376             break;
377 
378         case ACPI_RSC_MOVE_GPIO_PIN:
379 
380             /* Generate and set the PIN data pointer */
381 
382             Target = (char *) ACPI_ADD_PTR (void, Resource,
383                 (Resource->Length - ItemCount * 2));
384             *(UINT16 **) Destination = ACPI_CAST_PTR (UINT16, Target);
385 
386             /* Copy the PIN data */
387 
388             Source = ACPI_ADD_PTR (void, Aml, ACPI_GET16 (Source));
389             AcpiRsMoveData (Target, Source, ItemCount, Info->Opcode);
390             break;
391 
392         case ACPI_RSC_MOVE_GPIO_RES:
393 
394             /* Generate and set the ResourceSource string pointer */
395 
396             Target = (char *) ACPI_ADD_PTR (void, Resource,
397                 (Resource->Length - ItemCount));
398             *(UINT8 **) Destination = ACPI_CAST_PTR (UINT8, Target);
399 
400             /* Copy the ResourceSource string */
401 
402             Source = ACPI_ADD_PTR (void, Aml, ACPI_GET16 (Source));
403             AcpiRsMoveData (Target, Source, ItemCount, Info->Opcode);
404             break;
405 
406         case ACPI_RSC_MOVE_SERIAL_VEN:
407 
408             /* Generate and set the Vendor Data pointer */
409 
410             Target = (char *) ACPI_ADD_PTR (void, Resource,
411                 (Resource->Length - ItemCount));
412             *(UINT8 **) Destination = ACPI_CAST_PTR (UINT8, Target);
413 
414             /* Copy the Vendor Data */
415 
416             Source = ACPI_ADD_PTR (void, Aml, Info->Value);
417             AcpiRsMoveData (Target, Source, ItemCount, Info->Opcode);
418             break;
419 
420         case ACPI_RSC_MOVE_SERIAL_RES:
421 
422             /* Generate and set the ResourceSource string pointer */
423 
424             Target = (char *) ACPI_ADD_PTR (void, Resource,
425                 (Resource->Length - ItemCount));
426             *(UINT8 **) Destination = ACPI_CAST_PTR (UINT8, Target);
427 
428             /* Copy the ResourceSource string */
429 
430             Source = ACPI_ADD_PTR (
431                 void, Aml, (ACPI_GET16 (Source) + Info->Value));
432             AcpiRsMoveData (Target, Source, ItemCount, Info->Opcode);
433             break;
434 
435         case ACPI_RSC_SET8:
436 
437             memset (Destination, Info->AmlOffset, Info->Value);
438             break;
439 
440         case ACPI_RSC_DATA8:
441 
442             Target = ACPI_ADD_PTR (char, Resource, Info->Value);
443             memcpy (Destination, Source,  ACPI_GET16 (Target));
444             break;
445 
446         case ACPI_RSC_ADDRESS:
447             /*
448              * Common handler for address descriptor flags
449              */
450             if (!AcpiRsGetAddressCommon (Resource, Aml))
451             {
452                 return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE);
453             }
454             break;
455 
456         case ACPI_RSC_SOURCE:
457             /*
458              * Optional ResourceSource (Index and String)
459              */
460             Resource->Length +=
461                 AcpiRsGetResourceSource (AmlResourceLength, Info->Value,
462                     Destination, Aml, NULL);
463             break;
464 
465         case ACPI_RSC_SOURCEX:
466             /*
467              * Optional ResourceSource (Index and String). This is the more
468              * complicated case used by the Interrupt() macro
469              */
470             Target = ACPI_ADD_PTR (char, Resource,
471                 Info->AmlOffset + (ItemCount * 4));
472 
473             Resource->Length +=
474                 AcpiRsGetResourceSource (AmlResourceLength, (ACPI_RS_LENGTH)
475                     (((ItemCount - 1) * sizeof (UINT32)) + Info->Value),
476                     Destination, Aml, Target);
477             break;
478 
479         case ACPI_RSC_BITMASK:
480             /*
481              * 8-bit encoded bitmask (DMA macro)
482              */
483             ItemCount = AcpiRsDecodeBitmask (ACPI_GET8 (Source), Destination);
484             if (ItemCount)
485             {
486                 Resource->Length += (ItemCount - 1);
487             }
488 
489             Target = ACPI_ADD_PTR (char, Resource, Info->Value);
490             ACPI_SET8 (Target, ItemCount);
491             break;
492 
493         case ACPI_RSC_BITMASK16:
494             /*
495              * 16-bit encoded bitmask (IRQ macro)
496              */
497             ACPI_MOVE_16_TO_16 (&Temp16, Source);
498 
499             ItemCount = AcpiRsDecodeBitmask (Temp16, Destination);
500             if (ItemCount)
501             {
502                 Resource->Length += (ItemCount - 1);
503             }
504 
505             Target = ACPI_ADD_PTR (char, Resource, Info->Value);
506             ACPI_SET8 (Target, ItemCount);
507             break;
508 
509         case ACPI_RSC_EXIT_NE:
510             /*
511              * Control - Exit conversion if not equal
512              */
513             switch (Info->ResourceOffset)
514             {
515             case ACPI_RSC_COMPARE_AML_LENGTH:
516 
517                 if (AmlResourceLength != Info->Value)
518                 {
519                     goto Exit;
520                 }
521                 break;
522 
523             case ACPI_RSC_COMPARE_VALUE:
524 
525                 if (ACPI_GET8 (Source) != Info->Value)
526                 {
527                     goto Exit;
528                 }
529                 break;
530 
531             default:
532 
533                 ACPI_ERROR ((AE_INFO, "Invalid conversion sub-opcode"));
534                 return_ACPI_STATUS (AE_BAD_PARAMETER);
535             }
536             break;
537 
538         default:
539 
540             ACPI_ERROR ((AE_INFO, "Invalid conversion opcode"));
541             return_ACPI_STATUS (AE_BAD_PARAMETER);
542         }
543 
544         Count--;
545         Info++;
546     }
547 
548 Exit:
549     if (!FlagsMode)
550     {
551         /* Round the resource struct length up to the next boundary (32 or 64) */
552 
553         Resource->Length = (UINT32)
554             ACPI_ROUND_UP_TO_NATIVE_WORD (Resource->Length);
555     }
556     return_ACPI_STATUS (AE_OK);
557 }
558 
559 
560 /*******************************************************************************
561  *
562  * FUNCTION:    AcpiRsConvertResourceToAml
563  *
564  * PARAMETERS:  Resource            - Pointer to the resource descriptor
565  *              Aml                 - Where the AML descriptor is returned
566  *              Info                - Pointer to appropriate conversion table
567  *
568  * RETURN:      Status
569  *
570  * DESCRIPTION: Convert an internal resource descriptor to the corresponding
571  *              external AML resource descriptor.
572  *
573  ******************************************************************************/
574 
575 ACPI_STATUS
576 AcpiRsConvertResourceToAml (
577     ACPI_RESOURCE           *Resource,
578     AML_RESOURCE            *Aml,
579     ACPI_RSCONVERT_INFO     *Info)
580 {
581     void                    *Source = NULL;
582     void                    *Destination;
583     char                    *Target;
584     ACPI_RSDESC_SIZE        AmlLength = 0;
585     UINT8                   Count;
586     UINT16                  Temp16 = 0;
587     UINT16                  ItemCount = 0;
588 
589 
590     ACPI_FUNCTION_TRACE (RsConvertResourceToAml);
591 
592 
593     if (!Info)
594     {
595         return_ACPI_STATUS (AE_BAD_PARAMETER);
596     }
597 
598     /*
599      * First table entry must be ACPI_RSC_INITxxx and must contain the
600      * table length (# of table entries)
601      */
602     Count = INIT_TABLE_LENGTH (Info);
603 
604     while (Count)
605     {
606         /*
607          * Source is the internal resource descriptor,
608          * destination is the external AML byte stream buffer
609          */
610         Source = ACPI_ADD_PTR (void, Resource, Info->ResourceOffset);
611         Destination = ACPI_ADD_PTR (void, Aml, Info->AmlOffset);
612 
613         switch (Info->Opcode)
614         {
615         case ACPI_RSC_INITSET:
616 
617             memset (Aml, 0, INIT_RESOURCE_LENGTH (Info));
618             AmlLength = INIT_RESOURCE_LENGTH (Info);
619             AcpiRsSetResourceHeader (
620                 INIT_RESOURCE_TYPE (Info), AmlLength, Aml);
621             break;
622 
623         case ACPI_RSC_INITGET:
624             break;
625 
626         case ACPI_RSC_FLAGINIT:
627             /*
628              * Clear the flag byte
629              */
630             ACPI_SET8 (Destination, 0);
631             break;
632 
633         case ACPI_RSC_1BITFLAG:
634             /*
635              * Mask and shift the flag bit
636              */
637             ACPI_SET_BIT (*ACPI_CAST8 (Destination), (UINT8)
638                 ((ACPI_GET8 (Source) & 0x01) << Info->Value));
639             break;
640 
641         case ACPI_RSC_2BITFLAG:
642             /*
643              * Mask and shift the flag bits
644              */
645             ACPI_SET_BIT (*ACPI_CAST8 (Destination), (UINT8)
646                 ((ACPI_GET8 (Source) & 0x03) << Info->Value));
647             break;
648 
649         case ACPI_RSC_3BITFLAG:
650             /*
651              * Mask and shift the flag bits
652              */
653             ACPI_SET_BIT (*ACPI_CAST8 (Destination), (UINT8)
654                 ((ACPI_GET8 (Source) & 0x07) << Info->Value));
655             break;
656 
657         case ACPI_RSC_COUNT:
658 
659             ItemCount = ACPI_GET8 (Source);
660             ACPI_SET8 (Destination, ItemCount);
661 
662             AmlLength = (UINT16)
663                 (AmlLength + (Info->Value * (ItemCount - 1)));
664             break;
665 
666         case ACPI_RSC_COUNT16:
667 
668             ItemCount = ACPI_GET16 (Source);
669             AmlLength = (UINT16) (AmlLength + ItemCount);
670             AcpiRsSetResourceLength (AmlLength, Aml);
671             break;
672 
673         case ACPI_RSC_COUNT_GPIO_PIN:
674 
675             ItemCount = ACPI_GET16 (Source);
676             ACPI_SET16 (Destination, AmlLength);
677 
678             AmlLength = (UINT16) (AmlLength + ItemCount * 2);
679             Target = ACPI_ADD_PTR (void, Aml, Info->Value);
680             ACPI_SET16 (Target, AmlLength);
681             AcpiRsSetResourceLength (AmlLength, Aml);
682             break;
683 
684         case ACPI_RSC_COUNT_GPIO_VEN:
685 
686             ItemCount = ACPI_GET16 (Source);
687             ACPI_SET16 (Destination, ItemCount);
688 
689             AmlLength = (UINT16) (
690                 AmlLength + (Info->Value * ItemCount));
691             AcpiRsSetResourceLength (AmlLength, Aml);
692             break;
693 
694         case ACPI_RSC_COUNT_GPIO_RES:
695 
696             /* Set resource source string length */
697 
698             ItemCount = ACPI_GET16 (Source);
699             ACPI_SET16 (Destination, AmlLength);
700 
701             /* Compute offset for the Vendor Data */
702 
703             AmlLength = (UINT16) (AmlLength + ItemCount);
704             Target = ACPI_ADD_PTR (void, Aml, Info->Value);
705 
706             /* Set vendor offset only if there is vendor data */
707 
708             ACPI_SET16 (Target, AmlLength);
709 
710             AcpiRsSetResourceLength (AmlLength, Aml);
711             break;
712 
713         case ACPI_RSC_COUNT_SERIAL_VEN:
714 
715             ItemCount = ACPI_GET16 (Source);
716             ACPI_SET16 (Destination, ItemCount + Info->Value);
717             AmlLength = (UINT16) (AmlLength + ItemCount);
718             AcpiRsSetResourceLength (AmlLength, Aml);
719             break;
720 
721         case ACPI_RSC_COUNT_SERIAL_RES:
722 
723             ItemCount = ACPI_GET16 (Source);
724             AmlLength = (UINT16) (AmlLength + ItemCount);
725             AcpiRsSetResourceLength (AmlLength, Aml);
726             break;
727 
728         case ACPI_RSC_LENGTH:
729 
730             AcpiRsSetResourceLength (Info->Value, Aml);
731             break;
732 
733         case ACPI_RSC_MOVE8:
734         case ACPI_RSC_MOVE16:
735         case ACPI_RSC_MOVE32:
736         case ACPI_RSC_MOVE64:
737 
738             if (Info->Value)
739             {
740                 ItemCount = Info->Value;
741             }
742             AcpiRsMoveData (Destination, Source, ItemCount, Info->Opcode);
743             break;
744 
745         case ACPI_RSC_MOVE_GPIO_PIN:
746 
747             Destination = (char *) ACPI_ADD_PTR (void, Aml,
748                 ACPI_GET16 (Destination));
749             Source = * (UINT16 **) Source;
750             AcpiRsMoveData (Destination, Source, ItemCount, Info->Opcode);
751             break;
752 
753         case ACPI_RSC_MOVE_GPIO_RES:
754 
755             /* Used for both ResourceSource string and VendorData */
756 
757             Destination = (char *) ACPI_ADD_PTR (void, Aml,
758                 ACPI_GET16 (Destination));
759             Source = * (UINT8 **) Source;
760             AcpiRsMoveData (Destination, Source, ItemCount, Info->Opcode);
761             break;
762 
763         case ACPI_RSC_MOVE_SERIAL_VEN:
764 
765             Destination = (char *) ACPI_ADD_PTR (void, Aml,
766                 (AmlLength - ItemCount));
767             Source = * (UINT8 **) Source;
768             AcpiRsMoveData (Destination, Source, ItemCount, Info->Opcode);
769             break;
770 
771         case ACPI_RSC_MOVE_SERIAL_RES:
772 
773             Destination = (char *) ACPI_ADD_PTR (void, Aml,
774                 (AmlLength - ItemCount));
775             Source = * (UINT8 **) Source;
776             AcpiRsMoveData (Destination, Source, ItemCount, Info->Opcode);
777             break;
778 
779         case ACPI_RSC_ADDRESS:
780 
781             /* Set the Resource Type, General Flags, and Type-Specific Flags */
782 
783             AcpiRsSetAddressCommon (Aml, Resource);
784             break;
785 
786         case ACPI_RSC_SOURCEX:
787             /*
788              * Optional ResourceSource (Index and String)
789              */
790             AmlLength = AcpiRsSetResourceSource (
791                 Aml, (ACPI_RS_LENGTH) AmlLength, Source);
792             AcpiRsSetResourceLength (AmlLength, Aml);
793             break;
794 
795         case ACPI_RSC_SOURCE:
796             /*
797              * Optional ResourceSource (Index and String). This is the more
798              * complicated case used by the Interrupt() macro
799              */
800             AmlLength = AcpiRsSetResourceSource (Aml, Info->Value, Source);
801             AcpiRsSetResourceLength (AmlLength, Aml);
802             break;
803 
804         case ACPI_RSC_BITMASK:
805             /*
806              * 8-bit encoded bitmask (DMA macro)
807              */
808             ACPI_SET8 (Destination,
809                 AcpiRsEncodeBitmask (Source,
810                     *ACPI_ADD_PTR (UINT8, Resource, Info->Value)));
811             break;
812 
813         case ACPI_RSC_BITMASK16:
814             /*
815              * 16-bit encoded bitmask (IRQ macro)
816              */
817             Temp16 = AcpiRsEncodeBitmask (
818                 Source, *ACPI_ADD_PTR (UINT8, Resource, Info->Value));
819             ACPI_MOVE_16_TO_16 (Destination, &Temp16);
820             break;
821 
822         case ACPI_RSC_EXIT_LE:
823             /*
824              * Control - Exit conversion if less than or equal
825              */
826             if (ItemCount <= Info->Value)
827             {
828                 goto Exit;
829             }
830             break;
831 
832         case ACPI_RSC_EXIT_NE:
833             /*
834              * Control - Exit conversion if not equal
835              */
836             switch (COMPARE_OPCODE (Info))
837             {
838             case ACPI_RSC_COMPARE_VALUE:
839 
840                 if (*ACPI_ADD_PTR (UINT8, Resource,
841                     COMPARE_TARGET (Info)) != COMPARE_VALUE (Info))
842                 {
843                     goto Exit;
844                 }
845                 break;
846 
847             default:
848 
849                 ACPI_ERROR ((AE_INFO, "Invalid conversion sub-opcode"));
850                 return_ACPI_STATUS (AE_BAD_PARAMETER);
851             }
852             break;
853 
854         case ACPI_RSC_EXIT_EQ:
855             /*
856              * Control - Exit conversion if equal
857              */
858             if (*ACPI_ADD_PTR (UINT8, Resource,
859                 COMPARE_TARGET (Info)) == COMPARE_VALUE (Info))
860             {
861                 goto Exit;
862             }
863             break;
864 
865         default:
866 
867             ACPI_ERROR ((AE_INFO, "Invalid conversion opcode"));
868             return_ACPI_STATUS (AE_BAD_PARAMETER);
869         }
870 
871         Count--;
872         Info++;
873     }
874 
875 Exit:
876     return_ACPI_STATUS (AE_OK);
877 }
878 
879 
880 #if 0
881 /* Previous resource validations */
882 
883     if (Aml->ExtAddress64.RevisionID !=
884         AML_RESOURCE_EXTENDED_ADDRESS_REVISION)
885     {
886         return_ACPI_STATUS (AE_SUPPORT);
887     }
888 
889     if (Resource->Data.StartDpf.PerformanceRobustness >= 3)
890     {
891         return_ACPI_STATUS (AE_AML_BAD_RESOURCE_VALUE);
892     }
893 
894     if (((Aml->Irq.Flags & 0x09) == 0x00) ||
895         ((Aml->Irq.Flags & 0x09) == 0x09))
896     {
897         /*
898          * Only [ActiveHigh, EdgeSensitive] or [ActiveLow, LevelSensitive]
899          * polarity/trigger interrupts are allowed (ACPI spec, section
900          * "IRQ Format"), so 0x00 and 0x09 are illegal.
901          */
902         ACPI_ERROR ((AE_INFO,
903             "Invalid interrupt polarity/trigger in resource list, 0x%X",
904             Aml->Irq.Flags));
905         return_ACPI_STATUS (AE_BAD_DATA);
906     }
907 
908     Resource->Data.ExtendedIrq.InterruptCount = Temp8;
909     if (Temp8 < 1)
910     {
911         /* Must have at least one IRQ */
912 
913         return_ACPI_STATUS (AE_AML_BAD_RESOURCE_LENGTH);
914     }
915 
916     if (Resource->Data.Dma.Transfer == 0x03)
917     {
918         ACPI_ERROR ((AE_INFO,
919             "Invalid DMA.Transfer preference (3)"));
920         return_ACPI_STATUS (AE_BAD_DATA);
921     }
922 #endif
923