Home | History | Annotate | Line # | Download | only in resources
rsxface.c revision 1.13
      1   1.1    jruoho /*******************************************************************************
      2   1.1    jruoho  *
      3   1.1    jruoho  * Module Name: rsxface - Public interfaces to the resource manager
      4   1.1    jruoho  *
      5   1.1    jruoho  ******************************************************************************/
      6   1.1    jruoho 
      7   1.3    jruoho /*
      8  1.13  christos  * Copyright (C) 2000 - 2020, Intel Corp.
      9   1.1    jruoho  * All rights reserved.
     10   1.1    jruoho  *
     11   1.3    jruoho  * Redistribution and use in source and binary forms, with or without
     12   1.3    jruoho  * modification, are permitted provided that the following conditions
     13   1.3    jruoho  * are met:
     14   1.3    jruoho  * 1. Redistributions of source code must retain the above copyright
     15   1.3    jruoho  *    notice, this list of conditions, and the following disclaimer,
     16   1.3    jruoho  *    without modification.
     17   1.3    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18   1.3    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19   1.3    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20   1.3    jruoho  *    including a substantially similar Disclaimer requirement for further
     21   1.3    jruoho  *    binary redistribution.
     22   1.3    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23   1.3    jruoho  *    of any contributors may be used to endorse or promote products derived
     24   1.3    jruoho  *    from this software without specific prior written permission.
     25   1.3    jruoho  *
     26   1.3    jruoho  * Alternatively, this software may be distributed under the terms of the
     27   1.3    jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28   1.3    jruoho  * Software Foundation.
     29   1.3    jruoho  *
     30   1.3    jruoho  * NO WARRANTY
     31   1.3    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32   1.3    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33   1.3    jruoho  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34   1.3    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35   1.3    jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36   1.3    jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37   1.3    jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38   1.3    jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39   1.3    jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40   1.3    jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41   1.3    jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42   1.3    jruoho  */
     43   1.1    jruoho 
     44   1.4  christos #define EXPORT_ACPI_INTERFACES
     45   1.1    jruoho 
     46   1.1    jruoho #include "acpi.h"
     47   1.1    jruoho #include "accommon.h"
     48   1.1    jruoho #include "acresrc.h"
     49   1.1    jruoho #include "acnamesp.h"
     50   1.1    jruoho 
     51   1.1    jruoho #define _COMPONENT          ACPI_RESOURCES
     52   1.1    jruoho         ACPI_MODULE_NAME    ("rsxface")
     53   1.1    jruoho 
     54   1.1    jruoho /* Local macros for 16,32-bit to 64-bit conversion */
     55   1.1    jruoho 
     56   1.1    jruoho #define ACPI_COPY_FIELD(Out, In, Field)  ((Out)->Field = (In)->Field)
     57   1.8  christos #define ACPI_COPY_ADDRESS(Out, In)                       \
     58   1.1    jruoho     ACPI_COPY_FIELD(Out, In, ResourceType);              \
     59   1.1    jruoho     ACPI_COPY_FIELD(Out, In, ProducerConsumer);          \
     60   1.1    jruoho     ACPI_COPY_FIELD(Out, In, Decode);                    \
     61   1.1    jruoho     ACPI_COPY_FIELD(Out, In, MinAddressFixed);           \
     62   1.1    jruoho     ACPI_COPY_FIELD(Out, In, MaxAddressFixed);           \
     63   1.1    jruoho     ACPI_COPY_FIELD(Out, In, Info);                      \
     64   1.6  christos     ACPI_COPY_FIELD(Out, In, Address.Granularity);       \
     65   1.6  christos     ACPI_COPY_FIELD(Out, In, Address.Minimum);           \
     66   1.6  christos     ACPI_COPY_FIELD(Out, In, Address.Maximum);           \
     67   1.6  christos     ACPI_COPY_FIELD(Out, In, Address.TranslationOffset); \
     68   1.6  christos     ACPI_COPY_FIELD(Out, In, Address.AddressLength);     \
     69   1.1    jruoho     ACPI_COPY_FIELD(Out, In, ResourceSource);
     70   1.1    jruoho 
     71   1.1    jruoho 
     72   1.1    jruoho /* Local prototypes */
     73   1.1    jruoho 
     74   1.1    jruoho static ACPI_STATUS
     75   1.1    jruoho AcpiRsMatchVendorResource (
     76   1.1    jruoho     ACPI_RESOURCE           *Resource,
     77   1.1    jruoho     void                    *Context);
     78   1.1    jruoho 
     79   1.1    jruoho static ACPI_STATUS
     80   1.1    jruoho AcpiRsValidateParameters (
     81   1.1    jruoho     ACPI_HANDLE             DeviceHandle,
     82   1.1    jruoho     ACPI_BUFFER             *Buffer,
     83   1.1    jruoho     ACPI_NAMESPACE_NODE     **ReturnNode);
     84   1.1    jruoho 
     85   1.1    jruoho 
     86   1.1    jruoho /*******************************************************************************
     87   1.1    jruoho  *
     88   1.1    jruoho  * FUNCTION:    AcpiRsValidateParameters
     89   1.1    jruoho  *
     90   1.1    jruoho  * PARAMETERS:  DeviceHandle    - Handle to a device
     91   1.1    jruoho  *              Buffer          - Pointer to a data buffer
     92   1.1    jruoho  *              ReturnNode      - Pointer to where the device node is returned
     93   1.1    jruoho  *
     94   1.1    jruoho  * RETURN:      Status
     95   1.1    jruoho  *
     96   1.1    jruoho  * DESCRIPTION: Common parameter validation for resource interfaces
     97   1.1    jruoho  *
     98   1.1    jruoho  ******************************************************************************/
     99   1.1    jruoho 
    100   1.1    jruoho static ACPI_STATUS
    101   1.1    jruoho AcpiRsValidateParameters (
    102   1.1    jruoho     ACPI_HANDLE             DeviceHandle,
    103   1.1    jruoho     ACPI_BUFFER             *Buffer,
    104   1.1    jruoho     ACPI_NAMESPACE_NODE     **ReturnNode)
    105   1.1    jruoho {
    106   1.1    jruoho     ACPI_STATUS             Status;
    107   1.1    jruoho     ACPI_NAMESPACE_NODE     *Node;
    108   1.1    jruoho 
    109   1.1    jruoho 
    110   1.1    jruoho     ACPI_FUNCTION_TRACE (RsValidateParameters);
    111   1.1    jruoho 
    112   1.1    jruoho 
    113   1.1    jruoho     /*
    114   1.1    jruoho      * Must have a valid handle to an ACPI device
    115   1.1    jruoho      */
    116   1.1    jruoho     if (!DeviceHandle)
    117   1.1    jruoho     {
    118   1.1    jruoho         return_ACPI_STATUS (AE_BAD_PARAMETER);
    119   1.1    jruoho     }
    120   1.1    jruoho 
    121   1.1    jruoho     Node = AcpiNsValidateHandle (DeviceHandle);
    122   1.1    jruoho     if (!Node)
    123   1.1    jruoho     {
    124   1.1    jruoho         return_ACPI_STATUS (AE_BAD_PARAMETER);
    125   1.1    jruoho     }
    126   1.1    jruoho 
    127   1.1    jruoho     if (Node->Type != ACPI_TYPE_DEVICE)
    128   1.1    jruoho     {
    129   1.1    jruoho         return_ACPI_STATUS (AE_TYPE);
    130   1.1    jruoho     }
    131   1.1    jruoho 
    132   1.1    jruoho     /*
    133   1.1    jruoho      * Validate the user buffer object
    134   1.1    jruoho      *
    135   1.1    jruoho      * if there is a non-zero buffer length we also need a valid pointer in
    136   1.1    jruoho      * the buffer. If it's a zero buffer length, we'll be returning the
    137   1.1    jruoho      * needed buffer size (later), so keep going.
    138   1.1    jruoho      */
    139   1.1    jruoho     Status = AcpiUtValidateBuffer (Buffer);
    140   1.1    jruoho     if (ACPI_FAILURE (Status))
    141   1.1    jruoho     {
    142   1.1    jruoho         return_ACPI_STATUS (Status);
    143   1.1    jruoho     }
    144   1.1    jruoho 
    145   1.1    jruoho     *ReturnNode = Node;
    146   1.1    jruoho     return_ACPI_STATUS (AE_OK);
    147   1.1    jruoho }
    148   1.1    jruoho 
    149   1.1    jruoho 
    150   1.1    jruoho /*******************************************************************************
    151   1.1    jruoho  *
    152   1.1    jruoho  * FUNCTION:    AcpiGetIrqRoutingTable
    153   1.1    jruoho  *
    154   1.1    jruoho  * PARAMETERS:  DeviceHandle    - Handle to the Bus device we are querying
    155   1.1    jruoho  *              RetBuffer       - Pointer to a buffer to receive the
    156   1.1    jruoho  *                                current resources for the device
    157   1.1    jruoho  *
    158   1.1    jruoho  * RETURN:      Status
    159   1.1    jruoho  *
    160   1.1    jruoho  * DESCRIPTION: This function is called to get the IRQ routing table for a
    161   1.1    jruoho  *              specific bus. The caller must first acquire a handle for the
    162   1.1    jruoho  *              desired bus. The routine table is placed in the buffer pointed
    163   1.1    jruoho  *              to by the RetBuffer variable parameter.
    164   1.1    jruoho  *
    165   1.1    jruoho  *              If the function fails an appropriate status will be returned
    166   1.1    jruoho  *              and the value of RetBuffer is undefined.
    167   1.1    jruoho  *
    168   1.1    jruoho  *              This function attempts to execute the _PRT method contained in
    169   1.1    jruoho  *              the object indicated by the passed DeviceHandle.
    170   1.1    jruoho  *
    171   1.1    jruoho  ******************************************************************************/
    172   1.1    jruoho 
    173   1.1    jruoho ACPI_STATUS
    174   1.1    jruoho AcpiGetIrqRoutingTable  (
    175   1.1    jruoho     ACPI_HANDLE             DeviceHandle,
    176   1.1    jruoho     ACPI_BUFFER             *RetBuffer)
    177   1.1    jruoho {
    178   1.1    jruoho     ACPI_STATUS             Status;
    179   1.1    jruoho     ACPI_NAMESPACE_NODE     *Node;
    180   1.1    jruoho 
    181   1.1    jruoho 
    182   1.1    jruoho     ACPI_FUNCTION_TRACE (AcpiGetIrqRoutingTable);
    183   1.1    jruoho 
    184   1.1    jruoho 
    185   1.1    jruoho     /* Validate parameters then dispatch to internal routine */
    186   1.1    jruoho 
    187   1.1    jruoho     Status = AcpiRsValidateParameters (DeviceHandle, RetBuffer, &Node);
    188   1.1    jruoho     if (ACPI_FAILURE (Status))
    189   1.1    jruoho     {
    190   1.1    jruoho         return_ACPI_STATUS (Status);
    191   1.1    jruoho     }
    192   1.1    jruoho 
    193   1.1    jruoho     Status = AcpiRsGetPrtMethodData (Node, RetBuffer);
    194   1.1    jruoho     return_ACPI_STATUS (Status);
    195   1.1    jruoho }
    196   1.1    jruoho 
    197   1.1    jruoho ACPI_EXPORT_SYMBOL (AcpiGetIrqRoutingTable)
    198   1.1    jruoho 
    199   1.1    jruoho 
    200   1.1    jruoho /*******************************************************************************
    201   1.1    jruoho  *
    202   1.1    jruoho  * FUNCTION:    AcpiGetCurrentResources
    203   1.1    jruoho  *
    204   1.1    jruoho  * PARAMETERS:  DeviceHandle    - Handle to the device object for the
    205   1.1    jruoho  *                                device we are querying
    206   1.1    jruoho  *              RetBuffer       - Pointer to a buffer to receive the
    207   1.1    jruoho  *                                current resources for the device
    208   1.1    jruoho  *
    209   1.1    jruoho  * RETURN:      Status
    210   1.1    jruoho  *
    211   1.1    jruoho  * DESCRIPTION: This function is called to get the current resources for a
    212   1.1    jruoho  *              specific device. The caller must first acquire a handle for
    213   1.1    jruoho  *              the desired device. The resource data is placed in the buffer
    214   1.1    jruoho  *              pointed to by the RetBuffer variable parameter.
    215   1.1    jruoho  *
    216   1.1    jruoho  *              If the function fails an appropriate status will be returned
    217   1.1    jruoho  *              and the value of RetBuffer is undefined.
    218   1.1    jruoho  *
    219   1.1    jruoho  *              This function attempts to execute the _CRS method contained in
    220   1.1    jruoho  *              the object indicated by the passed DeviceHandle.
    221   1.1    jruoho  *
    222   1.1    jruoho  ******************************************************************************/
    223   1.1    jruoho 
    224   1.1    jruoho ACPI_STATUS
    225   1.1    jruoho AcpiGetCurrentResources (
    226   1.1    jruoho     ACPI_HANDLE             DeviceHandle,
    227   1.1    jruoho     ACPI_BUFFER             *RetBuffer)
    228   1.1    jruoho {
    229   1.1    jruoho     ACPI_STATUS             Status;
    230   1.1    jruoho     ACPI_NAMESPACE_NODE     *Node;
    231   1.1    jruoho 
    232   1.1    jruoho 
    233   1.1    jruoho     ACPI_FUNCTION_TRACE (AcpiGetCurrentResources);
    234   1.1    jruoho 
    235   1.1    jruoho 
    236   1.1    jruoho     /* Validate parameters then dispatch to internal routine */
    237   1.1    jruoho 
    238   1.1    jruoho     Status = AcpiRsValidateParameters (DeviceHandle, RetBuffer, &Node);
    239   1.1    jruoho     if (ACPI_FAILURE (Status))
    240   1.1    jruoho     {
    241   1.1    jruoho         return_ACPI_STATUS (Status);
    242   1.1    jruoho     }
    243   1.1    jruoho 
    244   1.1    jruoho     Status = AcpiRsGetCrsMethodData (Node, RetBuffer);
    245   1.1    jruoho     return_ACPI_STATUS (Status);
    246   1.1    jruoho }
    247   1.1    jruoho 
    248   1.1    jruoho ACPI_EXPORT_SYMBOL (AcpiGetCurrentResources)
    249   1.1    jruoho 
    250   1.1    jruoho 
    251   1.1    jruoho /*******************************************************************************
    252   1.1    jruoho  *
    253   1.1    jruoho  * FUNCTION:    AcpiGetPossibleResources
    254   1.1    jruoho  *
    255   1.1    jruoho  * PARAMETERS:  DeviceHandle    - Handle to the device object for the
    256   1.1    jruoho  *                                device we are querying
    257   1.1    jruoho  *              RetBuffer       - Pointer to a buffer to receive the
    258   1.1    jruoho  *                                resources for the device
    259   1.1    jruoho  *
    260   1.1    jruoho  * RETURN:      Status
    261   1.1    jruoho  *
    262   1.1    jruoho  * DESCRIPTION: This function is called to get a list of the possible resources
    263   1.1    jruoho  *              for a specific device. The caller must first acquire a handle
    264   1.1    jruoho  *              for the desired device. The resource data is placed in the
    265   1.1    jruoho  *              buffer pointed to by the RetBuffer variable.
    266   1.1    jruoho  *
    267   1.1    jruoho  *              If the function fails an appropriate status will be returned
    268   1.1    jruoho  *              and the value of RetBuffer is undefined.
    269   1.1    jruoho  *
    270   1.1    jruoho  ******************************************************************************/
    271   1.1    jruoho 
    272   1.1    jruoho ACPI_STATUS
    273   1.1    jruoho AcpiGetPossibleResources (
    274   1.1    jruoho     ACPI_HANDLE             DeviceHandle,
    275   1.1    jruoho     ACPI_BUFFER             *RetBuffer)
    276   1.1    jruoho {
    277   1.1    jruoho     ACPI_STATUS             Status;
    278   1.1    jruoho     ACPI_NAMESPACE_NODE     *Node;
    279   1.1    jruoho 
    280   1.1    jruoho 
    281   1.1    jruoho     ACPI_FUNCTION_TRACE (AcpiGetPossibleResources);
    282   1.1    jruoho 
    283   1.1    jruoho 
    284   1.1    jruoho     /* Validate parameters then dispatch to internal routine */
    285   1.1    jruoho 
    286   1.1    jruoho     Status = AcpiRsValidateParameters (DeviceHandle, RetBuffer, &Node);
    287   1.1    jruoho     if (ACPI_FAILURE (Status))
    288   1.1    jruoho     {
    289   1.1    jruoho         return_ACPI_STATUS (Status);
    290   1.1    jruoho     }
    291   1.1    jruoho 
    292   1.1    jruoho     Status = AcpiRsGetPrsMethodData (Node, RetBuffer);
    293   1.1    jruoho     return_ACPI_STATUS (Status);
    294   1.1    jruoho }
    295   1.1    jruoho 
    296   1.1    jruoho ACPI_EXPORT_SYMBOL (AcpiGetPossibleResources)
    297   1.1    jruoho 
    298   1.1    jruoho 
    299   1.1    jruoho /*******************************************************************************
    300   1.1    jruoho  *
    301   1.1    jruoho  * FUNCTION:    AcpiSetCurrentResources
    302   1.1    jruoho  *
    303   1.1    jruoho  * PARAMETERS:  DeviceHandle    - Handle to the device object for the
    304   1.1    jruoho  *                                device we are setting resources
    305   1.1    jruoho  *              InBuffer        - Pointer to a buffer containing the
    306   1.1    jruoho  *                                resources to be set for the device
    307   1.1    jruoho  *
    308   1.1    jruoho  * RETURN:      Status
    309   1.1    jruoho  *
    310   1.1    jruoho  * DESCRIPTION: This function is called to set the current resources for a
    311   1.1    jruoho  *              specific device. The caller must first acquire a handle for
    312   1.1    jruoho  *              the desired device. The resource data is passed to the routine
    313   1.1    jruoho  *              the buffer pointed to by the InBuffer variable.
    314   1.1    jruoho  *
    315   1.1    jruoho  ******************************************************************************/
    316   1.1    jruoho 
    317   1.1    jruoho ACPI_STATUS
    318   1.1    jruoho AcpiSetCurrentResources (
    319   1.1    jruoho     ACPI_HANDLE             DeviceHandle,
    320   1.1    jruoho     ACPI_BUFFER             *InBuffer)
    321   1.1    jruoho {
    322   1.1    jruoho     ACPI_STATUS             Status;
    323   1.1    jruoho     ACPI_NAMESPACE_NODE     *Node;
    324   1.1    jruoho 
    325   1.1    jruoho 
    326   1.1    jruoho     ACPI_FUNCTION_TRACE (AcpiSetCurrentResources);
    327   1.1    jruoho 
    328   1.1    jruoho 
    329   1.1    jruoho     /* Validate the buffer, don't allow zero length */
    330   1.1    jruoho 
    331   1.1    jruoho     if ((!InBuffer) ||
    332   1.1    jruoho         (!InBuffer->Pointer) ||
    333   1.1    jruoho         (!InBuffer->Length))
    334   1.1    jruoho     {
    335   1.1    jruoho         return_ACPI_STATUS (AE_BAD_PARAMETER);
    336   1.1    jruoho     }
    337   1.1    jruoho 
    338   1.1    jruoho     /* Validate parameters then dispatch to internal routine */
    339   1.1    jruoho 
    340   1.1    jruoho     Status = AcpiRsValidateParameters (DeviceHandle, InBuffer, &Node);
    341   1.1    jruoho     if (ACPI_FAILURE (Status))
    342   1.1    jruoho     {
    343   1.1    jruoho         return_ACPI_STATUS (Status);
    344   1.1    jruoho     }
    345   1.1    jruoho 
    346   1.1    jruoho     Status = AcpiRsSetSrsMethodData (Node, InBuffer);
    347   1.1    jruoho     return_ACPI_STATUS (Status);
    348   1.1    jruoho }
    349   1.1    jruoho 
    350   1.1    jruoho ACPI_EXPORT_SYMBOL (AcpiSetCurrentResources)
    351   1.1    jruoho 
    352   1.1    jruoho 
    353   1.4  christos /*******************************************************************************
    354   1.4  christos  *
    355   1.4  christos  * FUNCTION:    AcpiGetEventResources
    356   1.4  christos  *
    357   1.4  christos  * PARAMETERS:  DeviceHandle    - Handle to the device object for the
    358   1.4  christos  *                                device we are getting resources
    359   1.4  christos  *              InBuffer        - Pointer to a buffer containing the
    360   1.4  christos  *                                resources to be set for the device
    361   1.4  christos  *
    362   1.4  christos  * RETURN:      Status
    363   1.4  christos  *
    364   1.4  christos  * DESCRIPTION: This function is called to get the event resources for a
    365   1.4  christos  *              specific device. The caller must first acquire a handle for
    366   1.4  christos  *              the desired device. The resource data is passed to the routine
    367   1.4  christos  *              the buffer pointed to by the InBuffer variable. Uses the
    368   1.4  christos  *              _AEI method.
    369   1.4  christos  *
    370   1.4  christos  ******************************************************************************/
    371   1.4  christos 
    372   1.4  christos ACPI_STATUS
    373   1.4  christos AcpiGetEventResources (
    374   1.4  christos     ACPI_HANDLE             DeviceHandle,
    375   1.4  christos     ACPI_BUFFER             *RetBuffer)
    376   1.4  christos {
    377   1.4  christos     ACPI_STATUS             Status;
    378   1.4  christos     ACPI_NAMESPACE_NODE     *Node;
    379   1.4  christos 
    380   1.4  christos 
    381   1.4  christos     ACPI_FUNCTION_TRACE (AcpiGetEventResources);
    382   1.4  christos 
    383   1.4  christos 
    384   1.4  christos     /* Validate parameters then dispatch to internal routine */
    385   1.4  christos 
    386   1.4  christos     Status = AcpiRsValidateParameters (DeviceHandle, RetBuffer, &Node);
    387   1.4  christos     if (ACPI_FAILURE (Status))
    388   1.4  christos     {
    389   1.4  christos         return_ACPI_STATUS (Status);
    390   1.4  christos     }
    391   1.4  christos 
    392   1.4  christos     Status = AcpiRsGetAeiMethodData (Node, RetBuffer);
    393   1.4  christos     return_ACPI_STATUS (Status);
    394   1.4  christos }
    395   1.4  christos 
    396   1.4  christos ACPI_EXPORT_SYMBOL (AcpiGetEventResources)
    397   1.4  christos 
    398   1.4  christos 
    399   1.1    jruoho /******************************************************************************
    400   1.1    jruoho  *
    401   1.1    jruoho  * FUNCTION:    AcpiResourceToAddress64
    402   1.1    jruoho  *
    403   1.1    jruoho  * PARAMETERS:  Resource        - Pointer to a resource
    404   1.1    jruoho  *              Out             - Pointer to the users's return buffer
    405   1.1    jruoho  *                                (a struct acpi_resource_address64)
    406   1.1    jruoho  *
    407   1.1    jruoho  * RETURN:      Status
    408   1.1    jruoho  *
    409   1.1    jruoho  * DESCRIPTION: If the resource is an address16, address32, or address64,
    410   1.1    jruoho  *              copy it to the address64 return buffer. This saves the
    411   1.1    jruoho  *              caller from having to duplicate code for different-sized
    412   1.1    jruoho  *              addresses.
    413   1.1    jruoho  *
    414   1.1    jruoho  ******************************************************************************/
    415   1.1    jruoho 
    416   1.1    jruoho ACPI_STATUS
    417   1.1    jruoho AcpiResourceToAddress64 (
    418   1.1    jruoho     ACPI_RESOURCE               *Resource,
    419   1.1    jruoho     ACPI_RESOURCE_ADDRESS64     *Out)
    420   1.1    jruoho {
    421   1.1    jruoho     ACPI_RESOURCE_ADDRESS16     *Address16;
    422   1.1    jruoho     ACPI_RESOURCE_ADDRESS32     *Address32;
    423   1.1    jruoho 
    424   1.1    jruoho 
    425   1.1    jruoho     if (!Resource || !Out)
    426   1.1    jruoho     {
    427   1.1    jruoho         return (AE_BAD_PARAMETER);
    428   1.1    jruoho     }
    429   1.1    jruoho 
    430   1.1    jruoho     /* Convert 16 or 32 address descriptor to 64 */
    431   1.1    jruoho 
    432   1.1    jruoho     switch (Resource->Type)
    433   1.1    jruoho     {
    434   1.1    jruoho     case ACPI_RESOURCE_TYPE_ADDRESS16:
    435   1.1    jruoho 
    436   1.8  christos         Address16 = ACPI_CAST_PTR (
    437   1.8  christos             ACPI_RESOURCE_ADDRESS16, &Resource->Data);
    438   1.1    jruoho         ACPI_COPY_ADDRESS (Out, Address16);
    439   1.1    jruoho         break;
    440   1.1    jruoho 
    441   1.1    jruoho     case ACPI_RESOURCE_TYPE_ADDRESS32:
    442   1.1    jruoho 
    443   1.8  christos         Address32 = ACPI_CAST_PTR (
    444   1.8  christos             ACPI_RESOURCE_ADDRESS32, &Resource->Data);
    445   1.1    jruoho         ACPI_COPY_ADDRESS (Out, Address32);
    446   1.1    jruoho         break;
    447   1.1    jruoho 
    448   1.1    jruoho     case ACPI_RESOURCE_TYPE_ADDRESS64:
    449   1.1    jruoho 
    450   1.1    jruoho         /* Simple copy for 64 bit source */
    451   1.1    jruoho 
    452   1.7  christos         memcpy (Out, &Resource->Data, sizeof (ACPI_RESOURCE_ADDRESS64));
    453   1.1    jruoho         break;
    454   1.1    jruoho 
    455   1.1    jruoho     default:
    456   1.4  christos 
    457   1.1    jruoho         return (AE_BAD_PARAMETER);
    458   1.1    jruoho     }
    459   1.1    jruoho 
    460   1.1    jruoho     return (AE_OK);
    461   1.1    jruoho }
    462   1.1    jruoho 
    463   1.1    jruoho ACPI_EXPORT_SYMBOL (AcpiResourceToAddress64)
    464   1.1    jruoho 
    465   1.1    jruoho 
    466   1.1    jruoho /*******************************************************************************
    467   1.1    jruoho  *
    468   1.1    jruoho  * FUNCTION:    AcpiGetVendorResource
    469   1.1    jruoho  *
    470   1.1    jruoho  * PARAMETERS:  DeviceHandle    - Handle for the parent device object
    471   1.1    jruoho  *              Name            - Method name for the parent resource
    472   1.1    jruoho  *                                (METHOD_NAME__CRS or METHOD_NAME__PRS)
    473   1.1    jruoho  *              Uuid            - Pointer to the UUID to be matched.
    474   1.1    jruoho  *                                includes both subtype and 16-byte UUID
    475   1.1    jruoho  *              RetBuffer       - Where the vendor resource is returned
    476   1.1    jruoho  *
    477   1.1    jruoho  * RETURN:      Status
    478   1.1    jruoho  *
    479   1.4  christos  * DESCRIPTION: Walk a resource template for the specified device to find a
    480   1.1    jruoho  *              vendor-defined resource that matches the supplied UUID and
    481   1.1    jruoho  *              UUID subtype. Returns a ACPI_RESOURCE of type Vendor.
    482   1.1    jruoho  *
    483   1.1    jruoho  ******************************************************************************/
    484   1.1    jruoho 
    485   1.1    jruoho ACPI_STATUS
    486   1.1    jruoho AcpiGetVendorResource (
    487   1.1    jruoho     ACPI_HANDLE             DeviceHandle,
    488   1.1    jruoho     char                    *Name,
    489   1.1    jruoho     ACPI_VENDOR_UUID        *Uuid,
    490   1.1    jruoho     ACPI_BUFFER             *RetBuffer)
    491   1.1    jruoho {
    492   1.1    jruoho     ACPI_VENDOR_WALK_INFO   Info;
    493   1.1    jruoho     ACPI_STATUS             Status;
    494   1.1    jruoho 
    495   1.1    jruoho 
    496   1.1    jruoho     /* Other parameters are validated by AcpiWalkResources */
    497   1.1    jruoho 
    498   1.1    jruoho     if (!Uuid || !RetBuffer)
    499   1.1    jruoho     {
    500   1.1    jruoho         return (AE_BAD_PARAMETER);
    501   1.1    jruoho     }
    502   1.1    jruoho 
    503   1.1    jruoho     Info.Uuid = Uuid;
    504   1.1    jruoho     Info.Buffer = RetBuffer;
    505   1.1    jruoho     Info.Status = AE_NOT_EXIST;
    506   1.1    jruoho 
    507   1.1    jruoho     /* Walk the _CRS or _PRS resource list for this device */
    508   1.1    jruoho 
    509   1.8  christos     Status = AcpiWalkResources (
    510   1.8  christos         DeviceHandle, Name, AcpiRsMatchVendorResource, &Info);
    511   1.1    jruoho     if (ACPI_FAILURE (Status))
    512   1.1    jruoho     {
    513   1.1    jruoho         return (Status);
    514   1.1    jruoho     }
    515   1.1    jruoho 
    516   1.1    jruoho     return (Info.Status);
    517   1.1    jruoho }
    518   1.1    jruoho 
    519   1.1    jruoho ACPI_EXPORT_SYMBOL (AcpiGetVendorResource)
    520   1.1    jruoho 
    521   1.1    jruoho 
    522   1.1    jruoho /*******************************************************************************
    523   1.1    jruoho  *
    524   1.1    jruoho  * FUNCTION:    AcpiRsMatchVendorResource
    525   1.1    jruoho  *
    526   1.1    jruoho  * PARAMETERS:  ACPI_WALK_RESOURCE_CALLBACK
    527   1.1    jruoho  *
    528   1.1    jruoho  * RETURN:      Status
    529   1.1    jruoho  *
    530   1.1    jruoho  * DESCRIPTION: Match a vendor resource via the ACPI 3.0 UUID
    531   1.1    jruoho  *
    532   1.1    jruoho  ******************************************************************************/
    533   1.1    jruoho 
    534   1.1    jruoho static ACPI_STATUS
    535   1.1    jruoho AcpiRsMatchVendorResource (
    536   1.1    jruoho     ACPI_RESOURCE           *Resource,
    537   1.1    jruoho     void                    *Context)
    538   1.1    jruoho {
    539   1.1    jruoho     ACPI_VENDOR_WALK_INFO       *Info = Context;
    540   1.1    jruoho     ACPI_RESOURCE_VENDOR_TYPED  *Vendor;
    541   1.1    jruoho     ACPI_BUFFER                 *Buffer;
    542   1.1    jruoho     ACPI_STATUS                 Status;
    543   1.1    jruoho 
    544   1.1    jruoho 
    545   1.1    jruoho     /* Ignore all descriptors except Vendor */
    546   1.1    jruoho 
    547   1.1    jruoho     if (Resource->Type != ACPI_RESOURCE_TYPE_VENDOR)
    548   1.1    jruoho     {
    549   1.1    jruoho         return (AE_OK);
    550   1.1    jruoho     }
    551   1.1    jruoho 
    552   1.1    jruoho     Vendor = &Resource->Data.VendorTyped;
    553   1.1    jruoho 
    554   1.1    jruoho     /*
    555   1.1    jruoho      * For a valid match, these conditions must hold:
    556   1.1    jruoho      *
    557   1.1    jruoho      * 1) Length of descriptor data must be at least as long as a UUID struct
    558   1.1    jruoho      * 2) The UUID subtypes must match
    559   1.1    jruoho      * 3) The UUID data must match
    560   1.1    jruoho      */
    561   1.1    jruoho     if ((Vendor->ByteLength < (ACPI_UUID_LENGTH + 1)) ||
    562   1.1    jruoho         (Vendor->UuidSubtype != Info->Uuid->Subtype)  ||
    563   1.7  christos         (memcmp (Vendor->Uuid, Info->Uuid->Data, ACPI_UUID_LENGTH)))
    564   1.1    jruoho     {
    565   1.1    jruoho         return (AE_OK);
    566   1.1    jruoho     }
    567   1.1    jruoho 
    568   1.1    jruoho     /* Validate/Allocate/Clear caller buffer */
    569   1.1    jruoho 
    570   1.1    jruoho     Buffer = Info->Buffer;
    571   1.1    jruoho     Status = AcpiUtInitializeBuffer (Buffer, Resource->Length);
    572   1.1    jruoho     if (ACPI_FAILURE (Status))
    573   1.1    jruoho     {
    574   1.1    jruoho         return (Status);
    575   1.1    jruoho     }
    576   1.1    jruoho 
    577   1.1    jruoho     /* Found the correct resource, copy and return it */
    578   1.1    jruoho 
    579   1.7  christos     memcpy (Buffer->Pointer, Resource, Resource->Length);
    580   1.1    jruoho     Buffer->Length = Resource->Length;
    581   1.1    jruoho 
    582   1.1    jruoho     /* Found the desired descriptor, terminate resource walk */
    583   1.1    jruoho 
    584   1.1    jruoho     Info->Status = AE_OK;
    585   1.1    jruoho     return (AE_CTRL_TERMINATE);
    586   1.1    jruoho }
    587   1.1    jruoho 
    588   1.1    jruoho 
    589   1.1    jruoho /*******************************************************************************
    590   1.1    jruoho  *
    591   1.4  christos  * FUNCTION:    AcpiWalkResourceBuffer
    592   1.1    jruoho  *
    593   1.4  christos  * PARAMETERS:  Buffer          - Formatted buffer returned by one of the
    594   1.4  christos  *                                various Get*Resource functions
    595   1.1    jruoho  *              UserFunction    - Called for each resource
    596   1.1    jruoho  *              Context         - Passed to UserFunction
    597   1.1    jruoho  *
    598   1.1    jruoho  * RETURN:      Status
    599   1.1    jruoho  *
    600   1.4  christos  * DESCRIPTION: Walks the input resource template. The UserFunction is called
    601   1.4  christos  *              once for each resource in the list.
    602   1.1    jruoho  *
    603   1.1    jruoho  ******************************************************************************/
    604   1.1    jruoho 
    605   1.1    jruoho ACPI_STATUS
    606   1.4  christos AcpiWalkResourceBuffer (
    607   1.4  christos     ACPI_BUFFER                 *Buffer,
    608   1.1    jruoho     ACPI_WALK_RESOURCE_CALLBACK UserFunction,
    609   1.1    jruoho     void                        *Context)
    610   1.1    jruoho {
    611   1.4  christos     ACPI_STATUS                 Status = AE_OK;
    612   1.1    jruoho     ACPI_RESOURCE               *Resource;
    613   1.1    jruoho     ACPI_RESOURCE               *ResourceEnd;
    614   1.1    jruoho 
    615   1.4  christos     ACPI_FUNCTION_TRACE (AcpiWalkResourceBuffer);
    616   1.1    jruoho 
    617   1.1    jruoho 
    618   1.1    jruoho     /* Parameter validation */
    619   1.1    jruoho 
    620   1.4  christos     if (!Buffer || !Buffer->Pointer || !UserFunction)
    621   1.1    jruoho     {
    622   1.1    jruoho         return_ACPI_STATUS (AE_BAD_PARAMETER);
    623   1.1    jruoho     }
    624   1.1    jruoho 
    625   1.4  christos     /* Buffer contains the resource list and length */
    626   1.1    jruoho 
    627   1.4  christos     Resource = ACPI_CAST_PTR (ACPI_RESOURCE, Buffer->Pointer);
    628   1.8  christos     ResourceEnd = ACPI_ADD_PTR (
    629   1.8  christos         ACPI_RESOURCE, Buffer->Pointer, Buffer->Length);
    630   1.1    jruoho 
    631   1.1    jruoho     /* Walk the resource list until the EndTag is found (or buffer end) */
    632   1.1    jruoho 
    633   1.1    jruoho     while (Resource < ResourceEnd)
    634   1.1    jruoho     {
    635   1.4  christos         /* Sanity check the resource type */
    636   1.1    jruoho 
    637   1.1    jruoho         if (Resource->Type > ACPI_RESOURCE_TYPE_MAX)
    638   1.1    jruoho         {
    639   1.1    jruoho             Status = AE_AML_INVALID_RESOURCE_TYPE;
    640   1.1    jruoho             break;
    641   1.1    jruoho         }
    642   1.1    jruoho 
    643   1.4  christos         /* Sanity check the length. It must not be zero, or we loop forever */
    644   1.4  christos 
    645   1.4  christos         if (!Resource->Length)
    646   1.4  christos         {
    647   1.4  christos             return_ACPI_STATUS (AE_AML_BAD_RESOURCE_LENGTH);
    648   1.4  christos         }
    649   1.4  christos 
    650   1.1    jruoho         /* Invoke the user function, abort on any error returned */
    651   1.1    jruoho 
    652   1.1    jruoho         Status = UserFunction (Resource, Context);
    653   1.1    jruoho         if (ACPI_FAILURE (Status))
    654   1.1    jruoho         {
    655   1.1    jruoho             if (Status == AE_CTRL_TERMINATE)
    656   1.1    jruoho             {
    657   1.1    jruoho                 /* This is an OK termination by the user function */
    658   1.1    jruoho 
    659   1.1    jruoho                 Status = AE_OK;
    660   1.1    jruoho             }
    661   1.1    jruoho             break;
    662   1.1    jruoho         }
    663   1.1    jruoho 
    664   1.1    jruoho         /* EndTag indicates end-of-list */
    665   1.1    jruoho 
    666   1.1    jruoho         if (Resource->Type == ACPI_RESOURCE_TYPE_END_TAG)
    667   1.1    jruoho         {
    668   1.1    jruoho             break;
    669   1.1    jruoho         }
    670   1.1    jruoho 
    671   1.1    jruoho         /* Get the next resource descriptor */
    672   1.1    jruoho 
    673   1.4  christos         Resource = ACPI_NEXT_RESOURCE (Resource);
    674   1.1    jruoho     }
    675   1.1    jruoho 
    676   1.4  christos     return_ACPI_STATUS (Status);
    677   1.4  christos }
    678   1.4  christos 
    679   1.4  christos ACPI_EXPORT_SYMBOL (AcpiWalkResourceBuffer)
    680   1.4  christos 
    681   1.4  christos 
    682   1.4  christos /*******************************************************************************
    683   1.4  christos  *
    684   1.4  christos  * FUNCTION:    AcpiWalkResources
    685   1.4  christos  *
    686   1.4  christos  * PARAMETERS:  DeviceHandle    - Handle to the device object for the
    687   1.4  christos  *                                device we are querying
    688   1.4  christos  *              Name            - Method name of the resources we want.
    689   1.4  christos  *                                (METHOD_NAME__CRS, METHOD_NAME__PRS, or
    690  1.10  christos  *                                METHOD_NAME__AEI or METHOD_NAME__DMA)
    691   1.4  christos  *              UserFunction    - Called for each resource
    692   1.4  christos  *              Context         - Passed to UserFunction
    693   1.4  christos  *
    694   1.4  christos  * RETURN:      Status
    695   1.4  christos  *
    696   1.4  christos  * DESCRIPTION: Retrieves the current or possible resource list for the
    697   1.4  christos  *              specified device. The UserFunction is called once for
    698   1.4  christos  *              each resource in the list.
    699   1.4  christos  *
    700   1.4  christos  ******************************************************************************/
    701   1.4  christos 
    702   1.4  christos ACPI_STATUS
    703   1.4  christos AcpiWalkResources (
    704   1.4  christos     ACPI_HANDLE                 DeviceHandle,
    705   1.4  christos     const char                  *Name,
    706   1.4  christos     ACPI_WALK_RESOURCE_CALLBACK UserFunction,
    707   1.4  christos     void                        *Context)
    708   1.4  christos {
    709   1.4  christos     ACPI_STATUS                 Status;
    710   1.4  christos     ACPI_BUFFER                 Buffer;
    711   1.4  christos 
    712   1.4  christos 
    713   1.4  christos     ACPI_FUNCTION_TRACE (AcpiWalkResources);
    714   1.4  christos 
    715   1.4  christos 
    716   1.4  christos     /* Parameter validation */
    717   1.4  christos 
    718   1.4  christos     if (!DeviceHandle || !UserFunction || !Name ||
    719  1.12  christos         (!ACPI_COMPARE_NAMESEG (Name, METHOD_NAME__CRS) &&
    720  1.12  christos          !ACPI_COMPARE_NAMESEG (Name, METHOD_NAME__PRS) &&
    721  1.12  christos          !ACPI_COMPARE_NAMESEG (Name, METHOD_NAME__AEI) &&
    722  1.12  christos          !ACPI_COMPARE_NAMESEG (Name, METHOD_NAME__DMA)))
    723   1.4  christos     {
    724   1.4  christos         return_ACPI_STATUS (AE_BAD_PARAMETER);
    725   1.4  christos     }
    726   1.4  christos 
    727  1.10  christos     /* Get the _CRS/_PRS/_AEI/_DMA resource list */
    728   1.4  christos 
    729   1.4  christos     Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
    730   1.4  christos     Status = AcpiRsGetMethodData (DeviceHandle, __UNCONST(Name), &Buffer);
    731   1.4  christos     if (ACPI_FAILURE (Status))
    732   1.4  christos     {
    733   1.4  christos         return_ACPI_STATUS (Status);
    734   1.4  christos     }
    735   1.4  christos 
    736   1.4  christos     /* Walk the resource list and cleanup */
    737   1.4  christos 
    738   1.4  christos     Status = AcpiWalkResourceBuffer (&Buffer, UserFunction, Context);
    739   1.1    jruoho     ACPI_FREE (Buffer.Pointer);
    740   1.1    jruoho     return_ACPI_STATUS (Status);
    741   1.1    jruoho }
    742   1.1    jruoho 
    743   1.1    jruoho ACPI_EXPORT_SYMBOL (AcpiWalkResources)
    744