Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:03

0001 /*******************************************************************************
0002  *
0003  * Module Name: rsmisc - Miscellaneous resource descriptors
0004  *
0005  ******************************************************************************/
0006 
0007 /******************************************************************************
0008  *
0009  * 1. Copyright Notice
0010  *
0011  * Some or all of this work - Copyright (c) 1999 - 2024, Intel Corp.
0012  * All rights reserved.
0013  *
0014  * 2. License
0015  *
0016  * 2.1. This is your license from Intel Corp. under its intellectual property
0017  * rights. You may have additional license terms from the party that provided
0018  * you this software, covering your right to use that party's intellectual
0019  * property rights.
0020  *
0021  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
0022  * copy of the source code appearing in this file ("Covered Code") an
0023  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
0024  * base code distributed originally by Intel ("Original Intel Code") to copy,
0025  * make derivatives, distribute, use and display any portion of the Covered
0026  * Code in any form, with the right to sublicense such rights; and
0027  *
0028  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
0029  * license (with the right to sublicense), under only those claims of Intel
0030  * patents that are infringed by the Original Intel Code, to make, use, sell,
0031  * offer to sell, and import the Covered Code and derivative works thereof
0032  * solely to the minimum extent necessary to exercise the above copyright
0033  * license, and in no event shall the patent license extend to any additions
0034  * to or modifications of the Original Intel Code. No other license or right
0035  * is granted directly or by implication, estoppel or otherwise;
0036  *
0037  * The above copyright and patent license is granted only if the following
0038  * conditions are met:
0039  *
0040  * 3. Conditions
0041  *
0042  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
0043  * Redistribution of source code of any substantial portion of the Covered
0044  * Code or modification with rights to further distribute source must include
0045  * the above Copyright Notice, the above License, this list of Conditions,
0046  * and the following Disclaimer and Export Compliance provision. In addition,
0047  * Licensee must cause all Covered Code to which Licensee contributes to
0048  * contain a file documenting the changes Licensee made to create that Covered
0049  * Code and the date of any change. Licensee must include in that file the
0050  * documentation of any changes made by any predecessor Licensee. Licensee
0051  * must include a prominent statement that the modification is derived,
0052  * directly or indirectly, from Original Intel Code.
0053  *
0054  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
0055  * Redistribution of source code of any substantial portion of the Covered
0056  * Code or modification without rights to further distribute source must
0057  * include the following Disclaimer and Export Compliance provision in the
0058  * documentation and/or other materials provided with distribution. In
0059  * addition, Licensee may not authorize further sublicense of source of any
0060  * portion of the Covered Code, and must include terms to the effect that the
0061  * license from Licensee to its licensee is limited to the intellectual
0062  * property embodied in the software Licensee provides to its licensee, and
0063  * not to intellectual property embodied in modifications its licensee may
0064  * make.
0065  *
0066  * 3.3. Redistribution of Executable. Redistribution in executable form of any
0067  * substantial portion of the Covered Code or modification must reproduce the
0068  * above Copyright Notice, and the following Disclaimer and Export Compliance
0069  * provision in the documentation and/or other materials provided with the
0070  * distribution.
0071  *
0072  * 3.4. Intel retains all right, title, and interest in and to the Original
0073  * Intel Code.
0074  *
0075  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
0076  * Intel shall be used in advertising or otherwise to promote the sale, use or
0077  * other dealings in products derived from or relating to the Covered Code
0078  * without prior written authorization from Intel.
0079  *
0080  * 4. Disclaimer and Export Compliance
0081  *
0082  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
0083  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
0084  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
0085  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
0086  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
0087  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
0088  * PARTICULAR PURPOSE.
0089  *
0090  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
0091  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
0092  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
0093  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
0094  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
0095  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
0096  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
0097  * LIMITED REMEDY.
0098  *
0099  * 4.3. Licensee shall not export, either directly or indirectly, any of this
0100  * software or system incorporating such software without first obtaining any
0101  * required license or other approval from the U. S. Department of Commerce or
0102  * any other agency or department of the United States Government. In the
0103  * event Licensee exports any such software from the United States or
0104  * re-exports any such software from a foreign destination, Licensee shall
0105  * ensure that the distribution and export/re-export of the software is in
0106  * compliance with all laws, regulations, orders, or other restrictions of the
0107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
0108  * any of its subsidiaries will export/re-export any technical data, process,
0109  * software, or service, directly or indirectly, to any country for which the
0110  * United States government or any agency thereof requires an export license,
0111  * other governmental approval, or letter of assurance, without first obtaining
0112  * such license, approval or letter.
0113  *
0114  *****************************************************************************
0115  *
0116  * Alternatively, you may choose to be licensed under the terms of the
0117  * following license:
0118  *
0119  * Redistribution and use in source and binary forms, with or without
0120  * modification, are permitted provided that the following conditions
0121  * are met:
0122  * 1. Redistributions of source code must retain the above copyright
0123  *    notice, this list of conditions, and the following disclaimer,
0124  *    without modification.
0125  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
0126  *    substantially similar to the "NO WARRANTY" disclaimer below
0127  *    ("Disclaimer") and any redistribution must be conditioned upon
0128  *    including a substantially similar Disclaimer requirement for further
0129  *    binary redistribution.
0130  * 3. Neither the names of the above-listed copyright holders nor the names
0131  *    of any contributors may be used to endorse or promote products derived
0132  *    from this software without specific prior written permission.
0133  *
0134  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0135  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0136  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
0137  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
0138  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0139  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0140  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0141  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0142  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0143  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0144  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0145  *
0146  * Alternatively, you may choose to be licensed under the terms of the
0147  * GNU General Public License ("GPL") version 2 as published by the Free
0148  * Software Foundation.
0149  *
0150  *****************************************************************************/
0151 
0152 #include "acpi.h"
0153 #include "accommon.h"
0154 #include "acresrc.h"
0155 
0156 #define _COMPONENT          ACPI_RESOURCES
0157         ACPI_MODULE_NAME    ("rsmisc")
0158 
0159 
0160 #define INIT_RESOURCE_TYPE(i)       i->ResourceOffset
0161 #define INIT_RESOURCE_LENGTH(i)     i->AmlOffset
0162 #define INIT_TABLE_LENGTH(i)        i->Value
0163 
0164 #define COMPARE_OPCODE(i)           i->ResourceOffset
0165 #define COMPARE_TARGET(i)           i->AmlOffset
0166 #define COMPARE_VALUE(i)            i->Value
0167 
0168 
0169 /*******************************************************************************
0170  *
0171  * FUNCTION:    AcpiRsConvertAmlToResource
0172  *
0173  * PARAMETERS:  Resource            - Pointer to the resource descriptor
0174  *              Aml                 - Where the AML descriptor is returned
0175  *              Info                - Pointer to appropriate conversion table
0176  *
0177  * RETURN:      Status
0178  *
0179  * DESCRIPTION: Convert an external AML resource descriptor to the corresponding
0180  *              internal resource descriptor
0181  *
0182  ******************************************************************************/
0183 
0184 ACPI_STATUS
0185 AcpiRsConvertAmlToResource (
0186     ACPI_RESOURCE           *Resource,
0187     AML_RESOURCE            *Aml,
0188     ACPI_RSCONVERT_INFO     *Info)
0189 {
0190     ACPI_RS_LENGTH          AmlResourceLength;
0191     void                    *Source;
0192     void                    *Destination;
0193     char                    *Target;
0194     UINT8                   Count;
0195     UINT8                   FlagsMode = FALSE;
0196     UINT16                  ItemCount = 0;
0197     UINT16                  Temp16 = 0;
0198 
0199 
0200     ACPI_FUNCTION_TRACE (RsConvertAmlToResource);
0201 
0202 
0203     if (!Info)
0204     {
0205         return_ACPI_STATUS (AE_BAD_PARAMETER);
0206     }
0207 
0208     if (((ACPI_SIZE) Resource) & 0x3)
0209     {
0210         /* Each internal resource struct is expected to be 32-bit aligned */
0211 
0212         ACPI_WARNING ((AE_INFO,
0213             "Misaligned resource pointer (get): %p Type 0x%2.2X Length %u",
0214             Resource, Resource->Type, Resource->Length));
0215     }
0216 
0217     /* Extract the resource Length field (does not include header length) */
0218 
0219     AmlResourceLength = AcpiUtGetResourceLength (Aml);
0220 
0221     /*
0222      * First table entry must be ACPI_RSC_INITxxx and must contain the
0223      * table length (# of table entries)
0224      */
0225     Count = INIT_TABLE_LENGTH (Info);
0226     while (Count)
0227     {
0228         Target = NULL;
0229 
0230         /*
0231          * Source is the external AML byte stream buffer,
0232          * destination is the internal resource descriptor
0233          */
0234         Source = ACPI_ADD_PTR (void, Aml, Info->AmlOffset);
0235         Destination = ACPI_ADD_PTR (void, Resource, Info->ResourceOffset);
0236 
0237         switch (Info->Opcode)
0238         {
0239         case ACPI_RSC_INITGET:
0240             /*
0241              * Get the resource type and the initial (minimum) length
0242              */
0243             memset (Resource, 0, INIT_RESOURCE_LENGTH (Info));
0244             Resource->Type = INIT_RESOURCE_TYPE (Info);
0245             Resource->Length = INIT_RESOURCE_LENGTH (Info);
0246             break;
0247 
0248         case ACPI_RSC_INITSET:
0249             break;
0250 
0251         case ACPI_RSC_FLAGINIT:
0252 
0253             FlagsMode = TRUE;
0254             break;
0255 
0256         case ACPI_RSC_1BITFLAG:
0257             /*
0258              * Mask and shift the flag bit
0259              */
0260             ACPI_SET8 (Destination,
0261                 ((ACPI_GET8 (Source) >> Info->Value) & 0x01));
0262             break;
0263 
0264         case ACPI_RSC_2BITFLAG:
0265             /*
0266              * Mask and shift the flag bits
0267              */
0268             ACPI_SET8 (Destination,
0269                 ((ACPI_GET8 (Source) >> Info->Value) & 0x03));
0270             break;
0271 
0272         case ACPI_RSC_3BITFLAG:
0273             /*
0274              * Mask and shift the flag bits
0275              */
0276             ACPI_SET8 (Destination,
0277                 ((ACPI_GET8 (Source) >> Info->Value) & 0x07));
0278             break;
0279 
0280         case ACPI_RSC_6BITFLAG:
0281             /*
0282              * Mask and shift the flag bits
0283              */
0284             ACPI_SET8 (Destination,
0285                 ((ACPI_GET8 (Source) >> Info->Value) & 0x3F));
0286             break;
0287 
0288         case ACPI_RSC_COUNT:
0289 
0290             ItemCount = ACPI_GET8 (Source);
0291             ACPI_SET8 (Destination, ItemCount);
0292 
0293             Resource->Length = Resource->Length +
0294                 (Info->Value * (ItemCount - 1));
0295             break;
0296 
0297         case ACPI_RSC_COUNT16:
0298 
0299             ItemCount = AmlResourceLength;
0300             ACPI_SET16 (Destination, ItemCount);
0301 
0302             Resource->Length = Resource->Length +
0303                 (Info->Value * (ItemCount - 1));
0304             break;
0305 
0306         case ACPI_RSC_COUNT_GPIO_PIN:
0307 
0308             Target = ACPI_ADD_PTR (void, Aml, Info->Value);
0309             ItemCount = ACPI_GET16 (Target) - ACPI_GET16 (Source);
0310 
0311             Resource->Length = Resource->Length + ItemCount;
0312             ItemCount = ItemCount / 2;
0313             ACPI_SET16 (Destination, ItemCount);
0314             break;
0315 
0316         case ACPI_RSC_COUNT_GPIO_VEN:
0317 
0318             ItemCount = ACPI_GET8 (Source);
0319             ACPI_SET8 (Destination, ItemCount);
0320 
0321             Resource->Length = Resource->Length + (Info->Value * ItemCount);
0322             break;
0323 
0324         case ACPI_RSC_COUNT_GPIO_RES:
0325             /*
0326              * Vendor data is optional (length/offset may both be zero)
0327              * Examine vendor data length field first
0328              */
0329             Target = ACPI_ADD_PTR (void, Aml, (Info->Value + 2));
0330             if (ACPI_GET16 (Target))
0331             {
0332                 /* Use vendor offset to get resource source length */
0333 
0334                 Target = ACPI_ADD_PTR (void, Aml, Info->Value);
0335                 ItemCount = ACPI_GET16 (Target) - ACPI_GET16 (Source);
0336             }
0337             else
0338             {
0339                 /* No vendor data to worry about */
0340 
0341                 ItemCount = Aml->LargeHeader.ResourceLength +
0342                     sizeof (AML_RESOURCE_LARGE_HEADER) -
0343                     ACPI_GET16 (Source);
0344             }
0345 
0346             Resource->Length = Resource->Length + ItemCount;
0347             ACPI_SET16 (Destination, ItemCount);
0348             break;
0349 
0350         case ACPI_RSC_COUNT_SERIAL_VEN:
0351 
0352             ACPI_MOVE_16_TO_16(&Temp16, Source);
0353             ItemCount = Temp16 - Info->Value;
0354 
0355             Resource->Length = Resource->Length + ItemCount;
0356             ACPI_SET16 (Destination, ItemCount);
0357             break;
0358 
0359         case ACPI_RSC_COUNT_SERIAL_RES:
0360 
0361             ACPI_MOVE_16_TO_16(&Temp16, Source);
0362             ItemCount = (AmlResourceLength +
0363                 sizeof (AML_RESOURCE_LARGE_HEADER)) -
0364                 Temp16 - Info->Value;
0365 
0366             Resource->Length = Resource->Length + ItemCount;
0367             ACPI_SET16 (Destination, ItemCount);
0368             break;
0369 
0370         case ACPI_RSC_LENGTH:
0371 
0372             Resource->Length = Resource->Length + Info->Value;
0373             break;
0374 
0375         case ACPI_RSC_MOVE8:
0376         case ACPI_RSC_MOVE16:
0377         case ACPI_RSC_MOVE32:
0378         case ACPI_RSC_MOVE64:
0379             /*
0380              * Raw data move. Use the Info value field unless ItemCount has
0381              * been previously initialized via a COUNT opcode
0382              */
0383             if (Info->Value)
0384             {
0385                 ItemCount = Info->Value;
0386             }
0387             AcpiRsMoveData (Destination, Source, ItemCount, Info->Opcode);
0388             break;
0389 
0390         case ACPI_RSC_MOVE_GPIO_PIN:
0391 
0392             /* Generate and set the PIN data pointer */
0393 
0394             Target = (char *) ACPI_ADD_PTR (void, Resource,
0395                 (Resource->Length - ItemCount * 2));
0396             *(UINT16 **) Destination = ACPI_CAST_PTR (UINT16, Target);
0397 
0398             /* Copy the PIN data */
0399 
0400             Source = ACPI_ADD_PTR (void, Aml, ACPI_GET16 (Source));
0401             AcpiRsMoveData (Target, Source, ItemCount, Info->Opcode);
0402             break;
0403 
0404         case ACPI_RSC_MOVE_GPIO_RES:
0405 
0406             /* Generate and set the ResourceSource string pointer */
0407 
0408             Target = (char *) ACPI_ADD_PTR (void, Resource,
0409                 (Resource->Length - ItemCount));
0410             *(UINT8 **) Destination = ACPI_CAST_PTR (UINT8, Target);
0411 
0412             /* Copy the ResourceSource string */
0413 
0414             Source = ACPI_ADD_PTR (void, Aml, ACPI_GET16 (Source));
0415             AcpiRsMoveData (Target, Source, ItemCount, Info->Opcode);
0416             break;
0417 
0418         case ACPI_RSC_MOVE_SERIAL_VEN:
0419 
0420             /* Generate and set the Vendor Data pointer */
0421 
0422             Target = (char *) ACPI_ADD_PTR (void, Resource,
0423                 (Resource->Length - ItemCount));
0424             *(UINT8 **) Destination = ACPI_CAST_PTR (UINT8, Target);
0425 
0426             /* Copy the Vendor Data */
0427 
0428             Source = ACPI_ADD_PTR (void, Aml, Info->Value);
0429             AcpiRsMoveData (Target, Source, ItemCount, Info->Opcode);
0430             break;
0431 
0432         case ACPI_RSC_MOVE_SERIAL_RES:
0433 
0434             /* Generate and set the ResourceSource string pointer */
0435 
0436             Target = (char *) ACPI_ADD_PTR (void, Resource,
0437                 (Resource->Length - ItemCount));
0438             *(UINT8 **) Destination = ACPI_CAST_PTR (UINT8, Target);
0439 
0440             /* Copy the ResourceSource string */
0441 
0442             ACPI_MOVE_16_TO_16 (&Temp16, Source);
0443             Source = ACPI_ADD_PTR (
0444                 void, Aml, (Temp16 + Info->Value));
0445             AcpiRsMoveData (Target, Source, ItemCount, Info->Opcode);
0446             break;
0447 
0448         case ACPI_RSC_SET8:
0449 
0450             memset (Destination, Info->AmlOffset, Info->Value);
0451             break;
0452 
0453         case ACPI_RSC_DATA8:
0454 
0455             Target = ACPI_ADD_PTR (char, Resource, Info->Value);
0456             memcpy (Destination, Source,  ACPI_GET16 (Target));
0457             break;
0458 
0459         case ACPI_RSC_ADDRESS:
0460             /*
0461              * Common handler for address descriptor flags
0462              */
0463             if (!AcpiRsGetAddressCommon (Resource, Aml))
0464             {
0465                 return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE);
0466             }
0467             break;
0468 
0469         case ACPI_RSC_SOURCE:
0470             /*
0471              * Optional ResourceSource (Index and String)
0472              */
0473             Resource->Length +=
0474                 AcpiRsGetResourceSource (AmlResourceLength, Info->Value,
0475                     Destination, Aml, NULL);
0476             break;
0477 
0478         case ACPI_RSC_SOURCEX:
0479             /*
0480              * Optional ResourceSource (Index and String). This is the more
0481              * complicated case used by the Interrupt() macro
0482              */
0483             Target = ACPI_ADD_PTR (char, Resource,
0484                 Info->AmlOffset + (ItemCount * 4));
0485 
0486             Resource->Length +=
0487                 AcpiRsGetResourceSource (AmlResourceLength, (ACPI_RS_LENGTH)
0488                     (((ItemCount - 1) * sizeof (UINT32)) + Info->Value),
0489                     Destination, Aml, Target);
0490             break;
0491 
0492         case ACPI_RSC_BITMASK:
0493             /*
0494              * 8-bit encoded bitmask (DMA macro)
0495              */
0496             ItemCount = AcpiRsDecodeBitmask (ACPI_GET8 (Source), Destination);
0497             if (ItemCount)
0498             {
0499                 Resource->Length += (ItemCount - 1);
0500             }
0501 
0502             Target = ACPI_ADD_PTR (char, Resource, Info->Value);
0503             ACPI_SET8 (Target, ItemCount);
0504             break;
0505 
0506         case ACPI_RSC_BITMASK16:
0507             /*
0508              * 16-bit encoded bitmask (IRQ macro)
0509              */
0510             ACPI_MOVE_16_TO_16 (&Temp16, Source);
0511 
0512             ItemCount = AcpiRsDecodeBitmask (Temp16, Destination);
0513             if (ItemCount)
0514             {
0515                 Resource->Length += (ItemCount - 1);
0516             }
0517 
0518             Target = ACPI_ADD_PTR (char, Resource, Info->Value);
0519             ACPI_SET8 (Target, ItemCount);
0520             break;
0521 
0522         case ACPI_RSC_EXIT_NE:
0523             /*
0524              * Control - Exit conversion if not equal
0525              */
0526             switch (Info->ResourceOffset)
0527             {
0528             case ACPI_RSC_COMPARE_AML_LENGTH:
0529 
0530                 if (AmlResourceLength != Info->Value)
0531                 {
0532                     goto Exit;
0533                 }
0534                 break;
0535 
0536             case ACPI_RSC_COMPARE_VALUE:
0537 
0538                 if (ACPI_GET8 (Source) != Info->Value)
0539                 {
0540                     goto Exit;
0541                 }
0542                 break;
0543 
0544             default:
0545 
0546                 ACPI_ERROR ((AE_INFO, "Invalid conversion sub-opcode"));
0547                 return_ACPI_STATUS (AE_BAD_PARAMETER);
0548             }
0549             break;
0550 
0551         default:
0552 
0553             ACPI_ERROR ((AE_INFO, "Invalid conversion opcode"));
0554             return_ACPI_STATUS (AE_BAD_PARAMETER);
0555         }
0556 
0557         Count--;
0558         Info++;
0559     }
0560 
0561 Exit:
0562     if (!FlagsMode)
0563     {
0564         /* Round the resource struct length up to the next boundary (32 or 64) */
0565 
0566         Resource->Length = (UINT32)
0567             ACPI_ROUND_UP_TO_NATIVE_WORD (Resource->Length);
0568     }
0569     return_ACPI_STATUS (AE_OK);
0570 }
0571 
0572 
0573 /*******************************************************************************
0574  *
0575  * FUNCTION:    AcpiRsConvertResourceToAml
0576  *
0577  * PARAMETERS:  Resource            - Pointer to the resource descriptor
0578  *              Aml                 - Where the AML descriptor is returned
0579  *              Info                - Pointer to appropriate conversion table
0580  *
0581  * RETURN:      Status
0582  *
0583  * DESCRIPTION: Convert an internal resource descriptor to the corresponding
0584  *              external AML resource descriptor.
0585  *
0586  ******************************************************************************/
0587 
0588 ACPI_STATUS
0589 AcpiRsConvertResourceToAml (
0590     ACPI_RESOURCE           *Resource,
0591     AML_RESOURCE            *Aml,
0592     ACPI_RSCONVERT_INFO     *Info)
0593 {
0594     void                    *Source = NULL;
0595     void                    *Destination;
0596     char                    *Target;
0597     ACPI_RSDESC_SIZE        AmlLength = 0;
0598     UINT8                   Count;
0599     UINT16                  Temp16 = 0;
0600     UINT16                  ItemCount = 0;
0601 
0602 
0603     ACPI_FUNCTION_TRACE (RsConvertResourceToAml);
0604 
0605 
0606     if (!Info)
0607     {
0608         return_ACPI_STATUS (AE_BAD_PARAMETER);
0609     }
0610 
0611     /*
0612      * First table entry must be ACPI_RSC_INITxxx and must contain the
0613      * table length (# of table entries)
0614      */
0615     Count = INIT_TABLE_LENGTH (Info);
0616 
0617     while (Count)
0618     {
0619         /*
0620          * Source is the internal resource descriptor,
0621          * destination is the external AML byte stream buffer
0622          */
0623         Source = ACPI_ADD_PTR (void, Resource, Info->ResourceOffset);
0624         Destination = ACPI_ADD_PTR (void, Aml, Info->AmlOffset);
0625 
0626         switch (Info->Opcode)
0627         {
0628         case ACPI_RSC_INITSET:
0629 
0630             memset (Aml, 0, INIT_RESOURCE_LENGTH (Info));
0631             AmlLength = INIT_RESOURCE_LENGTH (Info);
0632             AcpiRsSetResourceHeader (
0633                 INIT_RESOURCE_TYPE (Info), AmlLength, Aml);
0634             break;
0635 
0636         case ACPI_RSC_INITGET:
0637             break;
0638 
0639         case ACPI_RSC_FLAGINIT:
0640             /*
0641              * Clear the flag byte
0642              */
0643             ACPI_SET8 (Destination, 0);
0644             break;
0645 
0646         case ACPI_RSC_1BITFLAG:
0647             /*
0648              * Mask and shift the flag bit
0649              */
0650             ACPI_SET_BIT (*ACPI_CAST8 (Destination), (UINT8)
0651                 ((ACPI_GET8 (Source) & 0x01) << Info->Value));
0652             break;
0653 
0654         case ACPI_RSC_2BITFLAG:
0655             /*
0656              * Mask and shift the flag bits
0657              */
0658             ACPI_SET_BIT (*ACPI_CAST8 (Destination), (UINT8)
0659                 ((ACPI_GET8 (Source) & 0x03) << Info->Value));
0660             break;
0661 
0662         case ACPI_RSC_3BITFLAG:
0663             /*
0664              * Mask and shift the flag bits
0665              */
0666             ACPI_SET_BIT (*ACPI_CAST8 (Destination), (UINT8)
0667                 ((ACPI_GET8 (Source) & 0x07) << Info->Value));
0668             break;
0669 
0670         case ACPI_RSC_6BITFLAG:
0671             /*
0672              * Mask and shift the flag bits
0673              */
0674             ACPI_SET_BIT (*ACPI_CAST8 (Destination), (UINT8)
0675                 ((ACPI_GET8 (Source) & 0x3F) << Info->Value));
0676             break;
0677 
0678         case ACPI_RSC_COUNT:
0679 
0680             ItemCount = ACPI_GET8 (Source);
0681             ACPI_SET8 (Destination, ItemCount);
0682 
0683             AmlLength = (UINT16)
0684                 (AmlLength + (Info->Value * (ItemCount - 1)));
0685             break;
0686 
0687         case ACPI_RSC_COUNT16:
0688 
0689             ItemCount = ACPI_GET16 (Source);
0690             AmlLength = (UINT16) (AmlLength + ItemCount);
0691             AcpiRsSetResourceLength (AmlLength, Aml);
0692             break;
0693 
0694         case ACPI_RSC_COUNT_GPIO_PIN:
0695 
0696             ItemCount = ACPI_GET16 (Source);
0697             ACPI_SET16 (Destination, AmlLength);
0698 
0699             AmlLength = (UINT16) (AmlLength + ItemCount * 2);
0700             Target = ACPI_ADD_PTR (void, Aml, Info->Value);
0701             ACPI_SET16 (Target, AmlLength);
0702             AcpiRsSetResourceLength (AmlLength, Aml);
0703             break;
0704 
0705         case ACPI_RSC_COUNT_GPIO_VEN:
0706 
0707             ItemCount = ACPI_GET16 (Source);
0708             ACPI_SET16 (Destination, ItemCount);
0709 
0710             AmlLength = (UINT16) (
0711                 AmlLength + (Info->Value * ItemCount));
0712             AcpiRsSetResourceLength (AmlLength, Aml);
0713             break;
0714 
0715         case ACPI_RSC_COUNT_GPIO_RES:
0716 
0717             /* Set resource source string length */
0718 
0719             ItemCount = ACPI_GET16 (Source);
0720             ACPI_SET16 (Destination, AmlLength);
0721 
0722             /* Compute offset for the Vendor Data */
0723 
0724             AmlLength = (UINT16) (AmlLength + ItemCount);
0725             Target = ACPI_ADD_PTR (void, Aml, Info->Value);
0726 
0727             /* Set vendor offset only if there is vendor data */
0728 
0729             ACPI_SET16 (Target, AmlLength);
0730 
0731             AcpiRsSetResourceLength (AmlLength, Aml);
0732             break;
0733 
0734         case ACPI_RSC_COUNT_SERIAL_VEN:
0735 
0736             ItemCount = ACPI_GET16 (Source);
0737             ACPI_SET16 (Destination, ItemCount + Info->Value);
0738             AmlLength = (UINT16) (AmlLength + ItemCount);
0739             AcpiRsSetResourceLength (AmlLength, Aml);
0740             break;
0741 
0742         case ACPI_RSC_COUNT_SERIAL_RES:
0743 
0744             ItemCount = ACPI_GET16 (Source);
0745             AmlLength = (UINT16) (AmlLength + ItemCount);
0746             AcpiRsSetResourceLength (AmlLength, Aml);
0747             break;
0748 
0749         case ACPI_RSC_LENGTH:
0750 
0751             AcpiRsSetResourceLength (Info->Value, Aml);
0752             break;
0753 
0754         case ACPI_RSC_MOVE8:
0755         case ACPI_RSC_MOVE16:
0756         case ACPI_RSC_MOVE32:
0757         case ACPI_RSC_MOVE64:
0758 
0759             if (Info->Value)
0760             {
0761                 ItemCount = Info->Value;
0762             }
0763             AcpiRsMoveData (Destination, Source, ItemCount, Info->Opcode);
0764             break;
0765 
0766         case ACPI_RSC_MOVE_GPIO_PIN:
0767 
0768             Destination = (char *) ACPI_ADD_PTR (void, Aml,
0769                 ACPI_GET16 (Destination));
0770             Source = * (UINT16 **) Source;
0771             AcpiRsMoveData (Destination, Source, ItemCount, Info->Opcode);
0772             break;
0773 
0774         case ACPI_RSC_MOVE_GPIO_RES:
0775 
0776             /* Used for both ResourceSource string and VendorData */
0777 
0778             Destination = (char *) ACPI_ADD_PTR (void, Aml,
0779                 ACPI_GET16 (Destination));
0780             Source = * (UINT8 **) Source;
0781             AcpiRsMoveData (Destination, Source, ItemCount, Info->Opcode);
0782             break;
0783 
0784         case ACPI_RSC_MOVE_SERIAL_VEN:
0785 
0786             Destination = (char *) ACPI_ADD_PTR (void, Aml,
0787                 (AmlLength - ItemCount));
0788             Source = * (UINT8 **) Source;
0789             AcpiRsMoveData (Destination, Source, ItemCount, Info->Opcode);
0790             break;
0791 
0792         case ACPI_RSC_MOVE_SERIAL_RES:
0793 
0794             Destination = (char *) ACPI_ADD_PTR (void, Aml,
0795                 (AmlLength - ItemCount));
0796             Source = * (UINT8 **) Source;
0797             AcpiRsMoveData (Destination, Source, ItemCount, Info->Opcode);
0798             break;
0799 
0800         case ACPI_RSC_ADDRESS:
0801 
0802             /* Set the Resource Type, General Flags, and Type-Specific Flags */
0803 
0804             AcpiRsSetAddressCommon (Aml, Resource);
0805             break;
0806 
0807         case ACPI_RSC_SOURCEX:
0808             /*
0809              * Optional ResourceSource (Index and String)
0810              */
0811             AmlLength = AcpiRsSetResourceSource (
0812                 Aml, (ACPI_RS_LENGTH) AmlLength, Source);
0813             AcpiRsSetResourceLength (AmlLength, Aml);
0814             break;
0815 
0816         case ACPI_RSC_SOURCE:
0817             /*
0818              * Optional ResourceSource (Index and String). This is the more
0819              * complicated case used by the Interrupt() macro
0820              */
0821             AmlLength = AcpiRsSetResourceSource (Aml, Info->Value, Source);
0822             AcpiRsSetResourceLength (AmlLength, Aml);
0823             break;
0824 
0825         case ACPI_RSC_BITMASK:
0826             /*
0827              * 8-bit encoded bitmask (DMA macro)
0828              */
0829             ACPI_SET8 (Destination,
0830                 AcpiRsEncodeBitmask (Source,
0831                     *ACPI_ADD_PTR (UINT8, Resource, Info->Value)));
0832             break;
0833 
0834         case ACPI_RSC_BITMASK16:
0835             /*
0836              * 16-bit encoded bitmask (IRQ macro)
0837              */
0838             Temp16 = AcpiRsEncodeBitmask (
0839                 Source, *ACPI_ADD_PTR (UINT8, Resource, Info->Value));
0840             ACPI_MOVE_16_TO_16 (Destination, &Temp16);
0841             break;
0842 
0843         case ACPI_RSC_EXIT_LE:
0844             /*
0845              * Control - Exit conversion if less than or equal
0846              */
0847             if (ItemCount <= Info->Value)
0848             {
0849                 goto Exit;
0850             }
0851             break;
0852 
0853         case ACPI_RSC_EXIT_NE:
0854             /*
0855              * Control - Exit conversion if not equal
0856              */
0857             switch (COMPARE_OPCODE (Info))
0858             {
0859             case ACPI_RSC_COMPARE_VALUE:
0860 
0861                 if (*ACPI_ADD_PTR (UINT8, Resource,
0862                     COMPARE_TARGET (Info)) != COMPARE_VALUE (Info))
0863                 {
0864                     goto Exit;
0865                 }
0866                 break;
0867 
0868             default:
0869 
0870                 ACPI_ERROR ((AE_INFO, "Invalid conversion sub-opcode"));
0871                 return_ACPI_STATUS (AE_BAD_PARAMETER);
0872             }
0873             break;
0874 
0875         case ACPI_RSC_EXIT_EQ:
0876             /*
0877              * Control - Exit conversion if equal
0878              */
0879             if (*ACPI_ADD_PTR (UINT8, Resource,
0880                 COMPARE_TARGET (Info)) == COMPARE_VALUE (Info))
0881             {
0882                 goto Exit;
0883             }
0884             break;
0885 
0886         default:
0887 
0888             ACPI_ERROR ((AE_INFO, "Invalid conversion opcode"));
0889             return_ACPI_STATUS (AE_BAD_PARAMETER);
0890         }
0891 
0892         Count--;
0893         Info++;
0894     }
0895 
0896 Exit:
0897     return_ACPI_STATUS (AE_OK);
0898 }
0899 
0900 
0901 #if 0
0902 /* Previous resource validations */
0903 
0904     if (Aml->ExtAddress64.RevisionID !=
0905         AML_RESOURCE_EXTENDED_ADDRESS_REVISION)
0906     {
0907         return_ACPI_STATUS (AE_SUPPORT);
0908     }
0909 
0910     if (Resource->Data.StartDpf.PerformanceRobustness >= 3)
0911     {
0912         return_ACPI_STATUS (AE_AML_BAD_RESOURCE_VALUE);
0913     }
0914 
0915     if (((Aml->Irq.Flags & 0x09) == 0x00) ||
0916         ((Aml->Irq.Flags & 0x09) == 0x09))
0917     {
0918         /*
0919          * Only [ActiveHigh, EdgeSensitive] or [ActiveLow, LevelSensitive]
0920          * polarity/trigger interrupts are allowed (ACPI spec, section
0921          * "IRQ Format"), so 0x00 and 0x09 are illegal.
0922          */
0923         ACPI_ERROR ((AE_INFO,
0924             "Invalid interrupt polarity/trigger in resource list, 0x%X",
0925             Aml->Irq.Flags));
0926         return_ACPI_STATUS (AE_BAD_DATA);
0927     }
0928 
0929     Resource->Data.ExtendedIrq.InterruptCount = Temp8;
0930     if (Temp8 < 1)
0931     {
0932         /* Must have at least one IRQ */
0933 
0934         return_ACPI_STATUS (AE_AML_BAD_RESOURCE_LENGTH);
0935     }
0936 
0937     if (Resource->Data.Dma.Transfer == 0x03)
0938     {
0939         ACPI_ERROR ((AE_INFO,
0940             "Invalid DMA.Transfer preference (3)"));
0941         return_ACPI_STATUS (AE_BAD_DATA);
0942     }
0943 #endif