Home | History | Annotate | Line # | Download | only in resources
      1 /*******************************************************************************
      2  *
      3  * Module Name: rsxface - Public interfaces to the resource manager
      4  *
      5  ******************************************************************************/
      6 
      7 /******************************************************************************
      8  *
      9  * 1. Copyright Notice
     10  *
     11  * Some or all of this work - Copyright (c) 1999 - 2025, 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 #define EXPORT_ACPI_INTERFACES
    153 
    154 #include "acpi.h"
    155 #include "accommon.h"
    156 #include "acresrc.h"
    157 #include "acnamesp.h"
    158 
    159 #define _COMPONENT          ACPI_RESOURCES
    160         ACPI_MODULE_NAME    ("rsxface")
    161 
    162 /* Local macros for 16,32-bit to 64-bit conversion */
    163 
    164 #define ACPI_COPY_FIELD(Out, In, Field)  ((Out)->Field = (In)->Field)
    165 #define ACPI_COPY_ADDRESS(Out, In)                       \
    166     ACPI_COPY_FIELD(Out, In, ResourceType);              \
    167     ACPI_COPY_FIELD(Out, In, ProducerConsumer);          \
    168     ACPI_COPY_FIELD(Out, In, Decode);                    \
    169     ACPI_COPY_FIELD(Out, In, MinAddressFixed);           \
    170     ACPI_COPY_FIELD(Out, In, MaxAddressFixed);           \
    171     ACPI_COPY_FIELD(Out, In, Info);                      \
    172     ACPI_COPY_FIELD(Out, In, Address.Granularity);       \
    173     ACPI_COPY_FIELD(Out, In, Address.Minimum);           \
    174     ACPI_COPY_FIELD(Out, In, Address.Maximum);           \
    175     ACPI_COPY_FIELD(Out, In, Address.TranslationOffset); \
    176     ACPI_COPY_FIELD(Out, In, Address.AddressLength);     \
    177     ACPI_COPY_FIELD(Out, In, ResourceSource);
    178 
    179 
    180 /* Local prototypes */
    181 
    182 static ACPI_STATUS
    183 AcpiRsMatchVendorResource (
    184     ACPI_RESOURCE           *Resource,
    185     void                    *Context);
    186 
    187 static ACPI_STATUS
    188 AcpiRsValidateParameters (
    189     ACPI_HANDLE             DeviceHandle,
    190     ACPI_BUFFER             *Buffer,
    191     ACPI_NAMESPACE_NODE     **ReturnNode);
    192 
    193 
    194 /*******************************************************************************
    195  *
    196  * FUNCTION:    AcpiRsValidateParameters
    197  *
    198  * PARAMETERS:  DeviceHandle    - Handle to a device
    199  *              Buffer          - Pointer to a data buffer
    200  *              ReturnNode      - Pointer to where the device node is returned
    201  *
    202  * RETURN:      Status
    203  *
    204  * DESCRIPTION: Common parameter validation for resource interfaces
    205  *
    206  ******************************************************************************/
    207 
    208 static ACPI_STATUS
    209 AcpiRsValidateParameters (
    210     ACPI_HANDLE             DeviceHandle,
    211     ACPI_BUFFER             *Buffer,
    212     ACPI_NAMESPACE_NODE     **ReturnNode)
    213 {
    214     ACPI_STATUS             Status;
    215     ACPI_NAMESPACE_NODE     *Node;
    216 
    217 
    218     ACPI_FUNCTION_TRACE (RsValidateParameters);
    219 
    220 
    221     /*
    222      * Must have a valid handle to an ACPI device
    223      */
    224     if (!DeviceHandle)
    225     {
    226         return_ACPI_STATUS (AE_BAD_PARAMETER);
    227     }
    228 
    229     Node = AcpiNsValidateHandle (DeviceHandle);
    230     if (!Node)
    231     {
    232         return_ACPI_STATUS (AE_BAD_PARAMETER);
    233     }
    234 
    235     if (Node->Type != ACPI_TYPE_DEVICE)
    236     {
    237         return_ACPI_STATUS (AE_TYPE);
    238     }
    239 
    240     /*
    241      * Validate the user buffer object
    242      *
    243      * if there is a non-zero buffer length we also need a valid pointer in
    244      * the buffer. If it's a zero buffer length, we'll be returning the
    245      * needed buffer size (later), so keep going.
    246      */
    247     Status = AcpiUtValidateBuffer (Buffer);
    248     if (ACPI_FAILURE (Status))
    249     {
    250         return_ACPI_STATUS (Status);
    251     }
    252 
    253     *ReturnNode = Node;
    254     return_ACPI_STATUS (AE_OK);
    255 }
    256 
    257 
    258 /*******************************************************************************
    259  *
    260  * FUNCTION:    AcpiGetIrqRoutingTable
    261  *
    262  * PARAMETERS:  DeviceHandle    - Handle to the Bus device we are querying
    263  *              RetBuffer       - Pointer to a buffer to receive the
    264  *                                current resources for the device
    265  *
    266  * RETURN:      Status
    267  *
    268  * DESCRIPTION: This function is called to get the IRQ routing table for a
    269  *              specific bus. The caller must first acquire a handle for the
    270  *              desired bus. The routine table is placed in the buffer pointed
    271  *              to by the RetBuffer variable parameter.
    272  *
    273  *              If the function fails an appropriate status will be returned
    274  *              and the value of RetBuffer is undefined.
    275  *
    276  *              This function attempts to execute the _PRT method contained in
    277  *              the object indicated by the passed DeviceHandle.
    278  *
    279  ******************************************************************************/
    280 
    281 ACPI_STATUS
    282 AcpiGetIrqRoutingTable  (
    283     ACPI_HANDLE             DeviceHandle,
    284     ACPI_BUFFER             *RetBuffer)
    285 {
    286     ACPI_STATUS             Status;
    287     ACPI_NAMESPACE_NODE     *Node;
    288 
    289 
    290     ACPI_FUNCTION_TRACE (AcpiGetIrqRoutingTable);
    291 
    292 
    293     /* Validate parameters then dispatch to internal routine */
    294 
    295     Status = AcpiRsValidateParameters (DeviceHandle, RetBuffer, &Node);
    296     if (ACPI_FAILURE (Status))
    297     {
    298         return_ACPI_STATUS (Status);
    299     }
    300 
    301     Status = AcpiRsGetPrtMethodData (Node, RetBuffer);
    302     return_ACPI_STATUS (Status);
    303 }
    304 
    305 ACPI_EXPORT_SYMBOL (AcpiGetIrqRoutingTable)
    306 
    307 
    308 /*******************************************************************************
    309  *
    310  * FUNCTION:    AcpiGetCurrentResources
    311  *
    312  * PARAMETERS:  DeviceHandle    - Handle to the device object for the
    313  *                                device we are querying
    314  *              RetBuffer       - Pointer to a buffer to receive the
    315  *                                current resources for the device
    316  *
    317  * RETURN:      Status
    318  *
    319  * DESCRIPTION: This function is called to get the current resources for a
    320  *              specific device. The caller must first acquire a handle for
    321  *              the desired device. The resource data is placed in the buffer
    322  *              pointed to by the RetBuffer variable parameter.
    323  *
    324  *              If the function fails an appropriate status will be returned
    325  *              and the value of RetBuffer is undefined.
    326  *
    327  *              This function attempts to execute the _CRS method contained in
    328  *              the object indicated by the passed DeviceHandle.
    329  *
    330  ******************************************************************************/
    331 
    332 ACPI_STATUS
    333 AcpiGetCurrentResources (
    334     ACPI_HANDLE             DeviceHandle,
    335     ACPI_BUFFER             *RetBuffer)
    336 {
    337     ACPI_STATUS             Status;
    338     ACPI_NAMESPACE_NODE     *Node;
    339 
    340 
    341     ACPI_FUNCTION_TRACE (AcpiGetCurrentResources);
    342 
    343 
    344     /* Validate parameters then dispatch to internal routine */
    345 
    346     Status = AcpiRsValidateParameters (DeviceHandle, RetBuffer, &Node);
    347     if (ACPI_FAILURE (Status))
    348     {
    349         return_ACPI_STATUS (Status);
    350     }
    351 
    352     Status = AcpiRsGetCrsMethodData (Node, RetBuffer);
    353     return_ACPI_STATUS (Status);
    354 }
    355 
    356 ACPI_EXPORT_SYMBOL (AcpiGetCurrentResources)
    357 
    358 
    359 /*******************************************************************************
    360  *
    361  * FUNCTION:    AcpiGetPossibleResources
    362  *
    363  * PARAMETERS:  DeviceHandle    - Handle to the device object for the
    364  *                                device we are querying
    365  *              RetBuffer       - Pointer to a buffer to receive the
    366  *                                resources for the device
    367  *
    368  * RETURN:      Status
    369  *
    370  * DESCRIPTION: This function is called to get a list of the possible resources
    371  *              for a specific device. The caller must first acquire a handle
    372  *              for the desired device. The resource data is placed in the
    373  *              buffer pointed to by the RetBuffer variable.
    374  *
    375  *              If the function fails an appropriate status will be returned
    376  *              and the value of RetBuffer is undefined.
    377  *
    378  ******************************************************************************/
    379 
    380 ACPI_STATUS
    381 AcpiGetPossibleResources (
    382     ACPI_HANDLE             DeviceHandle,
    383     ACPI_BUFFER             *RetBuffer)
    384 {
    385     ACPI_STATUS             Status;
    386     ACPI_NAMESPACE_NODE     *Node;
    387 
    388 
    389     ACPI_FUNCTION_TRACE (AcpiGetPossibleResources);
    390 
    391 
    392     /* Validate parameters then dispatch to internal routine */
    393 
    394     Status = AcpiRsValidateParameters (DeviceHandle, RetBuffer, &Node);
    395     if (ACPI_FAILURE (Status))
    396     {
    397         return_ACPI_STATUS (Status);
    398     }
    399 
    400     Status = AcpiRsGetPrsMethodData (Node, RetBuffer);
    401     return_ACPI_STATUS (Status);
    402 }
    403 
    404 ACPI_EXPORT_SYMBOL (AcpiGetPossibleResources)
    405 
    406 
    407 /*******************************************************************************
    408  *
    409  * FUNCTION:    AcpiSetCurrentResources
    410  *
    411  * PARAMETERS:  DeviceHandle    - Handle to the device object for the
    412  *                                device we are setting resources
    413  *              InBuffer        - Pointer to a buffer containing the
    414  *                                resources to be set for the device
    415  *
    416  * RETURN:      Status
    417  *
    418  * DESCRIPTION: This function is called to set the current resources for a
    419  *              specific device. The caller must first acquire a handle for
    420  *              the desired device. The resource data is passed to the routine
    421  *              the buffer pointed to by the InBuffer variable.
    422  *
    423  ******************************************************************************/
    424 
    425 ACPI_STATUS
    426 AcpiSetCurrentResources (
    427     ACPI_HANDLE             DeviceHandle,
    428     ACPI_BUFFER             *InBuffer)
    429 {
    430     ACPI_STATUS             Status;
    431     ACPI_NAMESPACE_NODE     *Node;
    432 
    433 
    434     ACPI_FUNCTION_TRACE (AcpiSetCurrentResources);
    435 
    436 
    437     /* Validate the buffer, don't allow zero length */
    438 
    439     if ((!InBuffer) ||
    440         (!InBuffer->Pointer) ||
    441         (!InBuffer->Length))
    442     {
    443         return_ACPI_STATUS (AE_BAD_PARAMETER);
    444     }
    445 
    446     /* Validate parameters then dispatch to internal routine */
    447 
    448     Status = AcpiRsValidateParameters (DeviceHandle, InBuffer, &Node);
    449     if (ACPI_FAILURE (Status))
    450     {
    451         return_ACPI_STATUS (Status);
    452     }
    453 
    454     Status = AcpiRsSetSrsMethodData (Node, InBuffer);
    455     return_ACPI_STATUS (Status);
    456 }
    457 
    458 ACPI_EXPORT_SYMBOL (AcpiSetCurrentResources)
    459 
    460 
    461 /*******************************************************************************
    462  *
    463  * FUNCTION:    AcpiGetEventResources
    464  *
    465  * PARAMETERS:  DeviceHandle    - Handle to the device object for the
    466  *                                device we are getting resources
    467  *              InBuffer        - Pointer to a buffer containing the
    468  *                                resources to be set for the device
    469  *
    470  * RETURN:      Status
    471  *
    472  * DESCRIPTION: This function is called to get the event resources for a
    473  *              specific device. The caller must first acquire a handle for
    474  *              the desired device. The resource data is passed to the routine
    475  *              the buffer pointed to by the InBuffer variable. Uses the
    476  *              _AEI method.
    477  *
    478  ******************************************************************************/
    479 
    480 ACPI_STATUS
    481 AcpiGetEventResources (
    482     ACPI_HANDLE             DeviceHandle,
    483     ACPI_BUFFER             *RetBuffer)
    484 {
    485     ACPI_STATUS             Status;
    486     ACPI_NAMESPACE_NODE     *Node;
    487 
    488 
    489     ACPI_FUNCTION_TRACE (AcpiGetEventResources);
    490 
    491 
    492     /* Validate parameters then dispatch to internal routine */
    493 
    494     Status = AcpiRsValidateParameters (DeviceHandle, RetBuffer, &Node);
    495     if (ACPI_FAILURE (Status))
    496     {
    497         return_ACPI_STATUS (Status);
    498     }
    499 
    500     Status = AcpiRsGetAeiMethodData (Node, RetBuffer);
    501     return_ACPI_STATUS (Status);
    502 }
    503 
    504 ACPI_EXPORT_SYMBOL (AcpiGetEventResources)
    505 
    506 
    507 /******************************************************************************
    508  *
    509  * FUNCTION:    AcpiResourceToAddress64
    510  *
    511  * PARAMETERS:  Resource        - Pointer to a resource
    512  *              Out             - Pointer to the users's return buffer
    513  *                                (a struct acpi_resource_address64)
    514  *
    515  * RETURN:      Status
    516  *
    517  * DESCRIPTION: If the resource is an address16, address32, or address64,
    518  *              copy it to the address64 return buffer. This saves the
    519  *              caller from having to duplicate code for different-sized
    520  *              addresses.
    521  *
    522  ******************************************************************************/
    523 
    524 ACPI_STATUS
    525 AcpiResourceToAddress64 (
    526     ACPI_RESOURCE               *Resource,
    527     ACPI_RESOURCE_ADDRESS64     *Out)
    528 {
    529     ACPI_RESOURCE_ADDRESS16     *Address16;
    530     ACPI_RESOURCE_ADDRESS32     *Address32;
    531 
    532 
    533     if (!Resource || !Out)
    534     {
    535         return (AE_BAD_PARAMETER);
    536     }
    537 
    538     /* Convert 16 or 32 address descriptor to 64 */
    539 
    540     switch (Resource->Type)
    541     {
    542     case ACPI_RESOURCE_TYPE_ADDRESS16:
    543 
    544         Address16 = ACPI_CAST_PTR (
    545             ACPI_RESOURCE_ADDRESS16, &Resource->Data);
    546         ACPI_COPY_ADDRESS (Out, Address16);
    547         break;
    548 
    549     case ACPI_RESOURCE_TYPE_ADDRESS32:
    550 
    551         Address32 = ACPI_CAST_PTR (
    552             ACPI_RESOURCE_ADDRESS32, &Resource->Data);
    553         ACPI_COPY_ADDRESS (Out, Address32);
    554         break;
    555 
    556     case ACPI_RESOURCE_TYPE_ADDRESS64:
    557 
    558         /* Simple copy for 64 bit source */
    559 
    560         memcpy (Out, &Resource->Data, sizeof (ACPI_RESOURCE_ADDRESS64));
    561         break;
    562 
    563     default:
    564 
    565         return (AE_BAD_PARAMETER);
    566     }
    567 
    568     return (AE_OK);
    569 }
    570 
    571 ACPI_EXPORT_SYMBOL (AcpiResourceToAddress64)
    572 
    573 
    574 /*******************************************************************************
    575  *
    576  * FUNCTION:    AcpiGetVendorResource
    577  *
    578  * PARAMETERS:  DeviceHandle    - Handle for the parent device object
    579  *              Name            - Method name for the parent resource
    580  *                                (METHOD_NAME__CRS or METHOD_NAME__PRS)
    581  *              Uuid            - Pointer to the UUID to be matched.
    582  *                                includes both subtype and 16-byte UUID
    583  *              RetBuffer       - Where the vendor resource is returned
    584  *
    585  * RETURN:      Status
    586  *
    587  * DESCRIPTION: Walk a resource template for the specified device to find a
    588  *              vendor-defined resource that matches the supplied UUID and
    589  *              UUID subtype. Returns a ACPI_RESOURCE of type Vendor.
    590  *
    591  ******************************************************************************/
    592 
    593 ACPI_STATUS
    594 AcpiGetVendorResource (
    595     ACPI_HANDLE             DeviceHandle,
    596     char                    *Name,
    597     ACPI_VENDOR_UUID        *Uuid,
    598     ACPI_BUFFER             *RetBuffer)
    599 {
    600     ACPI_VENDOR_WALK_INFO   Info;
    601     ACPI_STATUS             Status;
    602 
    603 
    604     /* Other parameters are validated by AcpiWalkResources */
    605 
    606     if (!Uuid || !RetBuffer)
    607     {
    608         return (AE_BAD_PARAMETER);
    609     }
    610 
    611     Info.Uuid = Uuid;
    612     Info.Buffer = RetBuffer;
    613     Info.Status = AE_NOT_EXIST;
    614 
    615     /* Walk the _CRS or _PRS resource list for this device */
    616 
    617     Status = AcpiWalkResources (
    618         DeviceHandle, Name, AcpiRsMatchVendorResource, &Info);
    619     if (ACPI_FAILURE (Status))
    620     {
    621         return (Status);
    622     }
    623 
    624     return (Info.Status);
    625 }
    626 
    627 ACPI_EXPORT_SYMBOL (AcpiGetVendorResource)
    628 
    629 
    630 /*******************************************************************************
    631  *
    632  * FUNCTION:    AcpiRsMatchVendorResource
    633  *
    634  * PARAMETERS:  ACPI_WALK_RESOURCE_CALLBACK
    635  *
    636  * RETURN:      Status
    637  *
    638  * DESCRIPTION: Match a vendor resource via the ACPI 3.0 UUID
    639  *
    640  ******************************************************************************/
    641 
    642 static ACPI_STATUS
    643 AcpiRsMatchVendorResource (
    644     ACPI_RESOURCE           *Resource,
    645     void                    *Context)
    646 {
    647     ACPI_VENDOR_WALK_INFO       *Info = Context;
    648     ACPI_RESOURCE_VENDOR_TYPED  *Vendor;
    649     ACPI_BUFFER                 *Buffer;
    650     ACPI_STATUS                 Status;
    651 
    652 
    653     /* Ignore all descriptors except Vendor */
    654 
    655     if (Resource->Type != ACPI_RESOURCE_TYPE_VENDOR)
    656     {
    657         return (AE_OK);
    658     }
    659 
    660     Vendor = &Resource->Data.VendorTyped;
    661 
    662     /*
    663      * For a valid match, these conditions must hold:
    664      *
    665      * 1) Length of descriptor data must be at least as long as a UUID struct
    666      * 2) The UUID subtypes must match
    667      * 3) The UUID data must match
    668      */
    669     if ((Vendor->ByteLength < (ACPI_UUID_LENGTH + 1)) ||
    670         (Vendor->UuidSubtype != Info->Uuid->Subtype)  ||
    671         (memcmp (Vendor->Uuid, Info->Uuid->Data, ACPI_UUID_LENGTH)))
    672     {
    673         return (AE_OK);
    674     }
    675 
    676     /* Validate/Allocate/Clear caller buffer */
    677 
    678     Buffer = Info->Buffer;
    679     Status = AcpiUtInitializeBuffer (Buffer, Resource->Length);
    680     if (ACPI_FAILURE (Status))
    681     {
    682         return (Status);
    683     }
    684 
    685     /* Found the correct resource, copy and return it */
    686 
    687     memcpy (Buffer->Pointer, Resource, Resource->Length);
    688     Buffer->Length = Resource->Length;
    689 
    690     /* Found the desired descriptor, terminate resource walk */
    691 
    692     Info->Status = AE_OK;
    693     return (AE_CTRL_TERMINATE);
    694 }
    695 
    696 
    697 /*******************************************************************************
    698  *
    699  * FUNCTION:    AcpiWalkResourceBuffer
    700  *
    701  * PARAMETERS:  Buffer          - Formatted buffer returned by one of the
    702  *                                various Get*Resource functions
    703  *              UserFunction    - Called for each resource
    704  *              Context         - Passed to UserFunction
    705  *
    706  * RETURN:      Status
    707  *
    708  * DESCRIPTION: Walks the input resource template. The UserFunction is called
    709  *              once for each resource in the list.
    710  *
    711  ******************************************************************************/
    712 
    713 ACPI_STATUS
    714 AcpiWalkResourceBuffer (
    715     ACPI_BUFFER                 *Buffer,
    716     ACPI_WALK_RESOURCE_CALLBACK UserFunction,
    717     void                        *Context)
    718 {
    719     ACPI_STATUS                 Status = AE_OK;
    720     ACPI_RESOURCE               *Resource;
    721     ACPI_RESOURCE               *ResourceEnd;
    722 
    723 
    724     ACPI_FUNCTION_TRACE (AcpiWalkResourceBuffer);
    725 
    726 
    727     /* Parameter validation */
    728 
    729     if (!Buffer || !Buffer->Pointer || !UserFunction)
    730     {
    731         return_ACPI_STATUS (AE_BAD_PARAMETER);
    732     }
    733 
    734     /* Buffer contains the resource list and length */
    735 
    736     Resource = ACPI_CAST_PTR (ACPI_RESOURCE, Buffer->Pointer);
    737     ResourceEnd = ACPI_ADD_PTR (
    738         ACPI_RESOURCE, Buffer->Pointer, Buffer->Length);
    739 
    740     /* Walk the resource list until the EndTag is found (or buffer end) */
    741 
    742     while (Resource < ResourceEnd)
    743     {
    744         /* Sanity check the resource type */
    745 
    746         if (Resource->Type > ACPI_RESOURCE_TYPE_MAX)
    747         {
    748             Status = AE_AML_INVALID_RESOURCE_TYPE;
    749             break;
    750         }
    751 
    752         /* Sanity check the length. It must not be zero, or we loop forever */
    753 
    754         if (!Resource->Length)
    755         {
    756             return_ACPI_STATUS (AE_AML_BAD_RESOURCE_LENGTH);
    757         }
    758 
    759         /* Invoke the user function, abort on any error returned */
    760 
    761         Status = UserFunction (Resource, Context);
    762         if (ACPI_FAILURE (Status))
    763         {
    764             if (Status == AE_CTRL_TERMINATE)
    765             {
    766                 /* This is an OK termination by the user function */
    767 
    768                 Status = AE_OK;
    769             }
    770             break;
    771         }
    772 
    773         /* EndTag indicates end-of-list */
    774 
    775         if (Resource->Type == ACPI_RESOURCE_TYPE_END_TAG)
    776         {
    777             break;
    778         }
    779 
    780         /* Get the next resource descriptor */
    781 
    782         Resource = ACPI_NEXT_RESOURCE (Resource);
    783     }
    784 
    785     return_ACPI_STATUS (Status);
    786 }
    787 
    788 ACPI_EXPORT_SYMBOL (AcpiWalkResourceBuffer)
    789 
    790 
    791 /*******************************************************************************
    792  *
    793  * FUNCTION:    AcpiWalkResources
    794  *
    795  * PARAMETERS:  DeviceHandle    - Handle to the device object for the
    796  *                                device we are querying
    797  *              Name            - Method name of the resources we want.
    798  *                                (METHOD_NAME__CRS, METHOD_NAME__PRS, or
    799  *                                METHOD_NAME__AEI or METHOD_NAME__DMA)
    800  *              UserFunction    - Called for each resource
    801  *              Context         - Passed to UserFunction
    802  *
    803  * RETURN:      Status
    804  *
    805  * DESCRIPTION: Retrieves the current or possible resource list for the
    806  *              specified device. The UserFunction is called once for
    807  *              each resource in the list.
    808  *
    809  ******************************************************************************/
    810 
    811 ACPI_STATUS
    812 AcpiWalkResources (
    813     ACPI_HANDLE                 DeviceHandle,
    814     const char                  *Name,
    815     ACPI_WALK_RESOURCE_CALLBACK UserFunction,
    816     void                        *Context)
    817 {
    818     ACPI_STATUS                 Status;
    819     ACPI_BUFFER                 Buffer;
    820 
    821 
    822     ACPI_FUNCTION_TRACE (AcpiWalkResources);
    823 
    824 
    825     /* Parameter validation */
    826 
    827     if (!DeviceHandle || !UserFunction || !Name ||
    828         (!ACPI_COMPARE_NAMESEG (Name, METHOD_NAME__CRS) &&
    829          !ACPI_COMPARE_NAMESEG (Name, METHOD_NAME__PRS) &&
    830          !ACPI_COMPARE_NAMESEG (Name, METHOD_NAME__AEI) &&
    831          !ACPI_COMPARE_NAMESEG (Name, METHOD_NAME__DMA)))
    832     {
    833         return_ACPI_STATUS (AE_BAD_PARAMETER);
    834     }
    835 
    836     /* Get the _CRS/_PRS/_AEI/_DMA resource list */
    837 
    838     Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
    839     Status = AcpiRsGetMethodData (DeviceHandle, __UNCONST(Name), &Buffer);
    840     if (ACPI_FAILURE (Status))
    841     {
    842         return_ACPI_STATUS (Status);
    843     }
    844 
    845     /* Walk the resource list and cleanup */
    846 
    847     Status = AcpiWalkResourceBuffer (&Buffer, UserFunction, Context);
    848     ACPI_FREE (Buffer.Pointer);
    849     return_ACPI_STATUS (Status);
    850 }
    851 
    852 ACPI_EXPORT_SYMBOL (AcpiWalkResources)
    853