xref: /freebsd/sys/contrib/dev/acpica/components/resources/rsmisc.c (revision 59c8e88e72633afbc47a4ace0d2170d00d51f7dc)
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 - 2023, 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         Target = NULL;
229 
230         /*
231          * Source is the external AML byte stream buffer,
232          * destination is the internal resource descriptor
233          */
234         Source = ACPI_ADD_PTR (void, Aml, Info->AmlOffset);
235         Destination = ACPI_ADD_PTR (void, Resource, Info->ResourceOffset);
236 
237         switch (Info->Opcode)
238         {
239         case ACPI_RSC_INITGET:
240             /*
241              * Get the resource type and the initial (minimum) length
242              */
243             memset (Resource, 0, INIT_RESOURCE_LENGTH (Info));
244             Resource->Type = INIT_RESOURCE_TYPE (Info);
245             Resource->Length = INIT_RESOURCE_LENGTH (Info);
246             break;
247 
248         case ACPI_RSC_INITSET:
249             break;
250 
251         case ACPI_RSC_FLAGINIT:
252 
253             FlagsMode = TRUE;
254             break;
255 
256         case ACPI_RSC_1BITFLAG:
257             /*
258              * Mask and shift the flag bit
259              */
260             ACPI_SET8 (Destination,
261                 ((ACPI_GET8 (Source) >> Info->Value) & 0x01));
262             break;
263 
264         case ACPI_RSC_2BITFLAG:
265             /*
266              * Mask and shift the flag bits
267              */
268             ACPI_SET8 (Destination,
269                 ((ACPI_GET8 (Source) >> Info->Value) & 0x03));
270             break;
271 
272         case ACPI_RSC_3BITFLAG:
273             /*
274              * Mask and shift the flag bits
275              */
276             ACPI_SET8 (Destination,
277                 ((ACPI_GET8 (Source) >> Info->Value) & 0x07));
278             break;
279 
280         case ACPI_RSC_6BITFLAG:
281             /*
282              * Mask and shift the flag bits
283              */
284             ACPI_SET8 (Destination,
285                 ((ACPI_GET8 (Source) >> Info->Value) & 0x3F));
286             break;
287 
288         case ACPI_RSC_COUNT:
289 
290             ItemCount = ACPI_GET8 (Source);
291             ACPI_SET8 (Destination, ItemCount);
292 
293             Resource->Length = Resource->Length +
294                 (Info->Value * (ItemCount - 1));
295             break;
296 
297         case ACPI_RSC_COUNT16:
298 
299             ItemCount = AmlResourceLength;
300             ACPI_SET16 (Destination, ItemCount);
301 
302             Resource->Length = Resource->Length +
303                 (Info->Value * (ItemCount - 1));
304             break;
305 
306         case ACPI_RSC_COUNT_GPIO_PIN:
307 
308             Target = ACPI_ADD_PTR (void, Aml, Info->Value);
309             ItemCount = ACPI_GET16 (Target) - ACPI_GET16 (Source);
310 
311             Resource->Length = Resource->Length + ItemCount;
312             ItemCount = ItemCount / 2;
313             ACPI_SET16 (Destination, ItemCount);
314             break;
315 
316         case ACPI_RSC_COUNT_GPIO_VEN:
317 
318             ItemCount = ACPI_GET8 (Source);
319             ACPI_SET8 (Destination, ItemCount);
320 
321             Resource->Length = Resource->Length + (Info->Value * ItemCount);
322             break;
323 
324         case ACPI_RSC_COUNT_GPIO_RES:
325             /*
326              * Vendor data is optional (length/offset may both be zero)
327              * Examine vendor data length field first
328              */
329             Target = ACPI_ADD_PTR (void, Aml, (Info->Value + 2));
330             if (ACPI_GET16 (Target))
331             {
332                 /* Use vendor offset to get resource source length */
333 
334                 Target = ACPI_ADD_PTR (void, Aml, Info->Value);
335                 ItemCount = ACPI_GET16 (Target) - ACPI_GET16 (Source);
336             }
337             else
338             {
339                 /* No vendor data to worry about */
340 
341                 ItemCount = Aml->LargeHeader.ResourceLength +
342                     sizeof (AML_RESOURCE_LARGE_HEADER) -
343                     ACPI_GET16 (Source);
344             }
345 
346             Resource->Length = Resource->Length + ItemCount;
347             ACPI_SET16 (Destination, ItemCount);
348             break;
349 
350         case ACPI_RSC_COUNT_SERIAL_VEN:
351 
352             ACPI_MOVE_16_TO_16(&Temp16, Source);
353             ItemCount = Temp16 - Info->Value;
354 
355             Resource->Length = Resource->Length + ItemCount;
356             ACPI_SET16 (Destination, ItemCount);
357             break;
358 
359         case ACPI_RSC_COUNT_SERIAL_RES:
360 
361             ACPI_MOVE_16_TO_16(&Temp16, Source);
362             ItemCount = (AmlResourceLength +
363                 sizeof (AML_RESOURCE_LARGE_HEADER)) -
364                 Temp16 - Info->Value;
365 
366             Resource->Length = Resource->Length + ItemCount;
367             ACPI_SET16 (Destination, ItemCount);
368             break;
369 
370         case ACPI_RSC_LENGTH:
371 
372             Resource->Length = Resource->Length + Info->Value;
373             break;
374 
375         case ACPI_RSC_MOVE8:
376         case ACPI_RSC_MOVE16:
377         case ACPI_RSC_MOVE32:
378         case ACPI_RSC_MOVE64:
379             /*
380              * Raw data move. Use the Info value field unless ItemCount has
381              * been previously initialized via a COUNT opcode
382              */
383             if (Info->Value)
384             {
385                 ItemCount = Info->Value;
386             }
387             AcpiRsMoveData (Destination, Source, ItemCount, Info->Opcode);
388             break;
389 
390         case ACPI_RSC_MOVE_GPIO_PIN:
391 
392             /* Generate and set the PIN data pointer */
393 
394             Target = (char *) ACPI_ADD_PTR (void, Resource,
395                 (Resource->Length - ItemCount * 2));
396             *(UINT16 **) Destination = ACPI_CAST_PTR (UINT16, Target);
397 
398             /* Copy the PIN data */
399 
400             Source = ACPI_ADD_PTR (void, Aml, ACPI_GET16 (Source));
401             AcpiRsMoveData (Target, Source, ItemCount, Info->Opcode);
402             break;
403 
404         case ACPI_RSC_MOVE_GPIO_RES:
405 
406             /* Generate and set the ResourceSource string pointer */
407 
408             Target = (char *) ACPI_ADD_PTR (void, Resource,
409                 (Resource->Length - ItemCount));
410             *(UINT8 **) Destination = ACPI_CAST_PTR (UINT8, Target);
411 
412             /* Copy the ResourceSource string */
413 
414             Source = ACPI_ADD_PTR (void, Aml, ACPI_GET16 (Source));
415             AcpiRsMoveData (Target, Source, ItemCount, Info->Opcode);
416             break;
417 
418         case ACPI_RSC_MOVE_SERIAL_VEN:
419 
420             /* Generate and set the Vendor Data pointer */
421 
422             Target = (char *) ACPI_ADD_PTR (void, Resource,
423                 (Resource->Length - ItemCount));
424             *(UINT8 **) Destination = ACPI_CAST_PTR (UINT8, Target);
425 
426             /* Copy the Vendor Data */
427 
428             Source = ACPI_ADD_PTR (void, Aml, Info->Value);
429             AcpiRsMoveData (Target, Source, ItemCount, Info->Opcode);
430             break;
431 
432         case ACPI_RSC_MOVE_SERIAL_RES:
433 
434             /* Generate and set the ResourceSource string pointer */
435 
436             Target = (char *) ACPI_ADD_PTR (void, Resource,
437                 (Resource->Length - ItemCount));
438             *(UINT8 **) Destination = ACPI_CAST_PTR (UINT8, Target);
439 
440             /* Copy the ResourceSource string */
441 
442             ACPI_MOVE_16_TO_16 (&Temp16, Source);
443             Source = ACPI_ADD_PTR (
444                 void, Aml, (Temp16 + Info->Value));
445             AcpiRsMoveData (Target, Source, ItemCount, Info->Opcode);
446             break;
447 
448         case ACPI_RSC_SET8:
449 
450             memset (Destination, Info->AmlOffset, Info->Value);
451             break;
452 
453         case ACPI_RSC_DATA8:
454 
455             Target = ACPI_ADD_PTR (char, Resource, Info->Value);
456             memcpy (Destination, Source,  ACPI_GET16 (Target));
457             break;
458 
459         case ACPI_RSC_ADDRESS:
460             /*
461              * Common handler for address descriptor flags
462              */
463             if (!AcpiRsGetAddressCommon (Resource, Aml))
464             {
465                 return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE);
466             }
467             break;
468 
469         case ACPI_RSC_SOURCE:
470             /*
471              * Optional ResourceSource (Index and String)
472              */
473             Resource->Length +=
474                 AcpiRsGetResourceSource (AmlResourceLength, Info->Value,
475                     Destination, Aml, NULL);
476             break;
477 
478         case ACPI_RSC_SOURCEX:
479             /*
480              * Optional ResourceSource (Index and String). This is the more
481              * complicated case used by the Interrupt() macro
482              */
483             Target = ACPI_ADD_PTR (char, Resource,
484                 Info->AmlOffset + (ItemCount * 4));
485 
486             Resource->Length +=
487                 AcpiRsGetResourceSource (AmlResourceLength, (ACPI_RS_LENGTH)
488                     (((ItemCount - 1) * sizeof (UINT32)) + Info->Value),
489                     Destination, Aml, Target);
490             break;
491 
492         case ACPI_RSC_BITMASK:
493             /*
494              * 8-bit encoded bitmask (DMA macro)
495              */
496             ItemCount = AcpiRsDecodeBitmask (ACPI_GET8 (Source), Destination);
497             if (ItemCount)
498             {
499                 Resource->Length += (ItemCount - 1);
500             }
501 
502             Target = ACPI_ADD_PTR (char, Resource, Info->Value);
503             ACPI_SET8 (Target, ItemCount);
504             break;
505 
506         case ACPI_RSC_BITMASK16:
507             /*
508              * 16-bit encoded bitmask (IRQ macro)
509              */
510             ACPI_MOVE_16_TO_16 (&Temp16, Source);
511 
512             ItemCount = AcpiRsDecodeBitmask (Temp16, Destination);
513             if (ItemCount)
514             {
515                 Resource->Length += (ItemCount - 1);
516             }
517 
518             Target = ACPI_ADD_PTR (char, Resource, Info->Value);
519             ACPI_SET8 (Target, ItemCount);
520             break;
521 
522         case ACPI_RSC_EXIT_NE:
523             /*
524              * Control - Exit conversion if not equal
525              */
526             switch (Info->ResourceOffset)
527             {
528             case ACPI_RSC_COMPARE_AML_LENGTH:
529 
530                 if (AmlResourceLength != Info->Value)
531                 {
532                     goto Exit;
533                 }
534                 break;
535 
536             case ACPI_RSC_COMPARE_VALUE:
537 
538                 if (ACPI_GET8 (Source) != Info->Value)
539                 {
540                     goto Exit;
541                 }
542                 break;
543 
544             default:
545 
546                 ACPI_ERROR ((AE_INFO, "Invalid conversion sub-opcode"));
547                 return_ACPI_STATUS (AE_BAD_PARAMETER);
548             }
549             break;
550 
551         default:
552 
553             ACPI_ERROR ((AE_INFO, "Invalid conversion opcode"));
554             return_ACPI_STATUS (AE_BAD_PARAMETER);
555         }
556 
557         Count--;
558         Info++;
559     }
560 
561 Exit:
562     if (!FlagsMode)
563     {
564         /* Round the resource struct length up to the next boundary (32 or 64) */
565 
566         Resource->Length = (UINT32)
567             ACPI_ROUND_UP_TO_NATIVE_WORD (Resource->Length);
568     }
569     return_ACPI_STATUS (AE_OK);
570 }
571 
572 
573 /*******************************************************************************
574  *
575  * FUNCTION:    AcpiRsConvertResourceToAml
576  *
577  * PARAMETERS:  Resource            - Pointer to the resource descriptor
578  *              Aml                 - Where the AML descriptor is returned
579  *              Info                - Pointer to appropriate conversion table
580  *
581  * RETURN:      Status
582  *
583  * DESCRIPTION: Convert an internal resource descriptor to the corresponding
584  *              external AML resource descriptor.
585  *
586  ******************************************************************************/
587 
588 ACPI_STATUS
589 AcpiRsConvertResourceToAml (
590     ACPI_RESOURCE           *Resource,
591     AML_RESOURCE            *Aml,
592     ACPI_RSCONVERT_INFO     *Info)
593 {
594     void                    *Source = NULL;
595     void                    *Destination;
596     char                    *Target;
597     ACPI_RSDESC_SIZE        AmlLength = 0;
598     UINT8                   Count;
599     UINT16                  Temp16 = 0;
600     UINT16                  ItemCount = 0;
601 
602 
603     ACPI_FUNCTION_TRACE (RsConvertResourceToAml);
604 
605 
606     if (!Info)
607     {
608         return_ACPI_STATUS (AE_BAD_PARAMETER);
609     }
610 
611     /*
612      * First table entry must be ACPI_RSC_INITxxx and must contain the
613      * table length (# of table entries)
614      */
615     Count = INIT_TABLE_LENGTH (Info);
616 
617     while (Count)
618     {
619         /*
620          * Source is the internal resource descriptor,
621          * destination is the external AML byte stream buffer
622          */
623         Source = ACPI_ADD_PTR (void, Resource, Info->ResourceOffset);
624         Destination = ACPI_ADD_PTR (void, Aml, Info->AmlOffset);
625 
626         switch (Info->Opcode)
627         {
628         case ACPI_RSC_INITSET:
629 
630             memset (Aml, 0, INIT_RESOURCE_LENGTH (Info));
631             AmlLength = INIT_RESOURCE_LENGTH (Info);
632             AcpiRsSetResourceHeader (
633                 INIT_RESOURCE_TYPE (Info), AmlLength, Aml);
634             break;
635 
636         case ACPI_RSC_INITGET:
637             break;
638 
639         case ACPI_RSC_FLAGINIT:
640             /*
641              * Clear the flag byte
642              */
643             ACPI_SET8 (Destination, 0);
644             break;
645 
646         case ACPI_RSC_1BITFLAG:
647             /*
648              * Mask and shift the flag bit
649              */
650             ACPI_SET_BIT (*ACPI_CAST8 (Destination), (UINT8)
651                 ((ACPI_GET8 (Source) & 0x01) << Info->Value));
652             break;
653 
654         case ACPI_RSC_2BITFLAG:
655             /*
656              * Mask and shift the flag bits
657              */
658             ACPI_SET_BIT (*ACPI_CAST8 (Destination), (UINT8)
659                 ((ACPI_GET8 (Source) & 0x03) << Info->Value));
660             break;
661 
662         case ACPI_RSC_3BITFLAG:
663             /*
664              * Mask and shift the flag bits
665              */
666             ACPI_SET_BIT (*ACPI_CAST8 (Destination), (UINT8)
667                 ((ACPI_GET8 (Source) & 0x07) << Info->Value));
668             break;
669 
670         case ACPI_RSC_6BITFLAG:
671             /*
672              * Mask and shift the flag bits
673              */
674             ACPI_SET_BIT (*ACPI_CAST8 (Destination), (UINT8)
675                 ((ACPI_GET8 (Source) & 0x3F) << Info->Value));
676             break;
677 
678         case ACPI_RSC_COUNT:
679 
680             ItemCount = ACPI_GET8 (Source);
681             ACPI_SET8 (Destination, ItemCount);
682 
683             AmlLength = (UINT16)
684                 (AmlLength + (Info->Value * (ItemCount - 1)));
685             break;
686 
687         case ACPI_RSC_COUNT16:
688 
689             ItemCount = ACPI_GET16 (Source);
690             AmlLength = (UINT16) (AmlLength + ItemCount);
691             AcpiRsSetResourceLength (AmlLength, Aml);
692             break;
693 
694         case ACPI_RSC_COUNT_GPIO_PIN:
695 
696             ItemCount = ACPI_GET16 (Source);
697             ACPI_SET16 (Destination, AmlLength);
698 
699             AmlLength = (UINT16) (AmlLength + ItemCount * 2);
700             Target = ACPI_ADD_PTR (void, Aml, Info->Value);
701             ACPI_SET16 (Target, AmlLength);
702             AcpiRsSetResourceLength (AmlLength, Aml);
703             break;
704 
705         case ACPI_RSC_COUNT_GPIO_VEN:
706 
707             ItemCount = ACPI_GET16 (Source);
708             ACPI_SET16 (Destination, ItemCount);
709 
710             AmlLength = (UINT16) (
711                 AmlLength + (Info->Value * ItemCount));
712             AcpiRsSetResourceLength (AmlLength, Aml);
713             break;
714 
715         case ACPI_RSC_COUNT_GPIO_RES:
716 
717             /* Set resource source string length */
718 
719             ItemCount = ACPI_GET16 (Source);
720             ACPI_SET16 (Destination, AmlLength);
721 
722             /* Compute offset for the Vendor Data */
723 
724             AmlLength = (UINT16) (AmlLength + ItemCount);
725             Target = ACPI_ADD_PTR (void, Aml, Info->Value);
726 
727             /* Set vendor offset only if there is vendor data */
728 
729             ACPI_SET16 (Target, AmlLength);
730 
731             AcpiRsSetResourceLength (AmlLength, Aml);
732             break;
733 
734         case ACPI_RSC_COUNT_SERIAL_VEN:
735 
736             ItemCount = ACPI_GET16 (Source);
737             ACPI_SET16 (Destination, ItemCount + Info->Value);
738             AmlLength = (UINT16) (AmlLength + ItemCount);
739             AcpiRsSetResourceLength (AmlLength, Aml);
740             break;
741 
742         case ACPI_RSC_COUNT_SERIAL_RES:
743 
744             ItemCount = ACPI_GET16 (Source);
745             AmlLength = (UINT16) (AmlLength + ItemCount);
746             AcpiRsSetResourceLength (AmlLength, Aml);
747             break;
748 
749         case ACPI_RSC_LENGTH:
750 
751             AcpiRsSetResourceLength (Info->Value, Aml);
752             break;
753 
754         case ACPI_RSC_MOVE8:
755         case ACPI_RSC_MOVE16:
756         case ACPI_RSC_MOVE32:
757         case ACPI_RSC_MOVE64:
758 
759             if (Info->Value)
760             {
761                 ItemCount = Info->Value;
762             }
763             AcpiRsMoveData (Destination, Source, ItemCount, Info->Opcode);
764             break;
765 
766         case ACPI_RSC_MOVE_GPIO_PIN:
767 
768             Destination = (char *) ACPI_ADD_PTR (void, Aml,
769                 ACPI_GET16 (Destination));
770             Source = * (UINT16 **) Source;
771             AcpiRsMoveData (Destination, Source, ItemCount, Info->Opcode);
772             break;
773 
774         case ACPI_RSC_MOVE_GPIO_RES:
775 
776             /* Used for both ResourceSource string and VendorData */
777 
778             Destination = (char *) ACPI_ADD_PTR (void, Aml,
779                 ACPI_GET16 (Destination));
780             Source = * (UINT8 **) Source;
781             AcpiRsMoveData (Destination, Source, ItemCount, Info->Opcode);
782             break;
783 
784         case ACPI_RSC_MOVE_SERIAL_VEN:
785 
786             Destination = (char *) ACPI_ADD_PTR (void, Aml,
787                 (AmlLength - ItemCount));
788             Source = * (UINT8 **) Source;
789             AcpiRsMoveData (Destination, Source, ItemCount, Info->Opcode);
790             break;
791 
792         case ACPI_RSC_MOVE_SERIAL_RES:
793 
794             Destination = (char *) ACPI_ADD_PTR (void, Aml,
795                 (AmlLength - ItemCount));
796             Source = * (UINT8 **) Source;
797             AcpiRsMoveData (Destination, Source, ItemCount, Info->Opcode);
798             break;
799 
800         case ACPI_RSC_ADDRESS:
801 
802             /* Set the Resource Type, General Flags, and Type-Specific Flags */
803 
804             AcpiRsSetAddressCommon (Aml, Resource);
805             break;
806 
807         case ACPI_RSC_SOURCEX:
808             /*
809              * Optional ResourceSource (Index and String)
810              */
811             AmlLength = AcpiRsSetResourceSource (
812                 Aml, (ACPI_RS_LENGTH) AmlLength, Source);
813             AcpiRsSetResourceLength (AmlLength, Aml);
814             break;
815 
816         case ACPI_RSC_SOURCE:
817             /*
818              * Optional ResourceSource (Index and String). This is the more
819              * complicated case used by the Interrupt() macro
820              */
821             AmlLength = AcpiRsSetResourceSource (Aml, Info->Value, Source);
822             AcpiRsSetResourceLength (AmlLength, Aml);
823             break;
824 
825         case ACPI_RSC_BITMASK:
826             /*
827              * 8-bit encoded bitmask (DMA macro)
828              */
829             ACPI_SET8 (Destination,
830                 AcpiRsEncodeBitmask (Source,
831                     *ACPI_ADD_PTR (UINT8, Resource, Info->Value)));
832             break;
833 
834         case ACPI_RSC_BITMASK16:
835             /*
836              * 16-bit encoded bitmask (IRQ macro)
837              */
838             Temp16 = AcpiRsEncodeBitmask (
839                 Source, *ACPI_ADD_PTR (UINT8, Resource, Info->Value));
840             ACPI_MOVE_16_TO_16 (Destination, &Temp16);
841             break;
842 
843         case ACPI_RSC_EXIT_LE:
844             /*
845              * Control - Exit conversion if less than or equal
846              */
847             if (ItemCount <= Info->Value)
848             {
849                 goto Exit;
850             }
851             break;
852 
853         case ACPI_RSC_EXIT_NE:
854             /*
855              * Control - Exit conversion if not equal
856              */
857             switch (COMPARE_OPCODE (Info))
858             {
859             case ACPI_RSC_COMPARE_VALUE:
860 
861                 if (*ACPI_ADD_PTR (UINT8, Resource,
862                     COMPARE_TARGET (Info)) != COMPARE_VALUE (Info))
863                 {
864                     goto Exit;
865                 }
866                 break;
867 
868             default:
869 
870                 ACPI_ERROR ((AE_INFO, "Invalid conversion sub-opcode"));
871                 return_ACPI_STATUS (AE_BAD_PARAMETER);
872             }
873             break;
874 
875         case ACPI_RSC_EXIT_EQ:
876             /*
877              * Control - Exit conversion if equal
878              */
879             if (*ACPI_ADD_PTR (UINT8, Resource,
880                 COMPARE_TARGET (Info)) == COMPARE_VALUE (Info))
881             {
882                 goto Exit;
883             }
884             break;
885 
886         default:
887 
888             ACPI_ERROR ((AE_INFO, "Invalid conversion opcode"));
889             return_ACPI_STATUS (AE_BAD_PARAMETER);
890         }
891 
892         Count--;
893         Info++;
894     }
895 
896 Exit:
897     return_ACPI_STATUS (AE_OK);
898 }
899 
900 
901 #if 0
902 /* Previous resource validations */
903 
904     if (Aml->ExtAddress64.RevisionID !=
905         AML_RESOURCE_EXTENDED_ADDRESS_REVISION)
906     {
907         return_ACPI_STATUS (AE_SUPPORT);
908     }
909 
910     if (Resource->Data.StartDpf.PerformanceRobustness >= 3)
911     {
912         return_ACPI_STATUS (AE_AML_BAD_RESOURCE_VALUE);
913     }
914 
915     if (((Aml->Irq.Flags & 0x09) == 0x00) ||
916         ((Aml->Irq.Flags & 0x09) == 0x09))
917     {
918         /*
919          * Only [ActiveHigh, EdgeSensitive] or [ActiveLow, LevelSensitive]
920          * polarity/trigger interrupts are allowed (ACPI spec, section
921          * "IRQ Format"), so 0x00 and 0x09 are illegal.
922          */
923         ACPI_ERROR ((AE_INFO,
924             "Invalid interrupt polarity/trigger in resource list, 0x%X",
925             Aml->Irq.Flags));
926         return_ACPI_STATUS (AE_BAD_DATA);
927     }
928 
929     Resource->Data.ExtendedIrq.InterruptCount = Temp8;
930     if (Temp8 < 1)
931     {
932         /* Must have at least one IRQ */
933 
934         return_ACPI_STATUS (AE_AML_BAD_RESOURCE_LENGTH);
935     }
936 
937     if (Resource->Data.Dma.Transfer == 0x03)
938     {
939         ACPI_ERROR ((AE_INFO,
940             "Invalid DMA.Transfer preference (3)"));
941         return_ACPI_STATUS (AE_BAD_DATA);
942     }
943 #endif
944