Home | History | Annotate | Line # | Download | only in resources
rsxface.c revision 1.7
      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.6  christos  * Copyright (C) 2000 - 2015, 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.1    jruoho #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.1    jruoho         Address16 = ACPI_CAST_PTR (ACPI_RESOURCE_ADDRESS16, &Resource->Data);
    437  1.1    jruoho         ACPI_COPY_ADDRESS (Out, Address16);
    438  1.1    jruoho         break;
    439  1.1    jruoho 
    440  1.1    jruoho     case ACPI_RESOURCE_TYPE_ADDRESS32:
    441  1.1    jruoho 
    442  1.1    jruoho         Address32 = ACPI_CAST_PTR (ACPI_RESOURCE_ADDRESS32, &Resource->Data);
    443  1.1    jruoho         ACPI_COPY_ADDRESS (Out, Address32);
    444  1.1    jruoho         break;
    445  1.1    jruoho 
    446  1.1    jruoho     case ACPI_RESOURCE_TYPE_ADDRESS64:
    447  1.1    jruoho 
    448  1.1    jruoho         /* Simple copy for 64 bit source */
    449  1.1    jruoho 
    450  1.7  christos         memcpy (Out, &Resource->Data, sizeof (ACPI_RESOURCE_ADDRESS64));
    451  1.1    jruoho         break;
    452  1.1    jruoho 
    453  1.1    jruoho     default:
    454  1.4  christos 
    455  1.1    jruoho         return (AE_BAD_PARAMETER);
    456  1.1    jruoho     }
    457  1.1    jruoho 
    458  1.1    jruoho     return (AE_OK);
    459  1.1    jruoho }
    460  1.1    jruoho 
    461  1.1    jruoho ACPI_EXPORT_SYMBOL (AcpiResourceToAddress64)
    462  1.1    jruoho 
    463  1.1    jruoho 
    464  1.1    jruoho /*******************************************************************************
    465  1.1    jruoho  *
    466  1.1    jruoho  * FUNCTION:    AcpiGetVendorResource
    467  1.1    jruoho  *
    468  1.1    jruoho  * PARAMETERS:  DeviceHandle    - Handle for the parent device object
    469  1.1    jruoho  *              Name            - Method name for the parent resource
    470  1.1    jruoho  *                                (METHOD_NAME__CRS or METHOD_NAME__PRS)
    471  1.1    jruoho  *              Uuid            - Pointer to the UUID to be matched.
    472  1.1    jruoho  *                                includes both subtype and 16-byte UUID
    473  1.1    jruoho  *              RetBuffer       - Where the vendor resource is returned
    474  1.1    jruoho  *
    475  1.1    jruoho  * RETURN:      Status
    476  1.1    jruoho  *
    477  1.4  christos  * DESCRIPTION: Walk a resource template for the specified device to find a
    478  1.1    jruoho  *              vendor-defined resource that matches the supplied UUID and
    479  1.1    jruoho  *              UUID subtype. Returns a ACPI_RESOURCE of type Vendor.
    480  1.1    jruoho  *
    481  1.1    jruoho  ******************************************************************************/
    482  1.1    jruoho 
    483  1.1    jruoho ACPI_STATUS
    484  1.1    jruoho AcpiGetVendorResource (
    485  1.1    jruoho     ACPI_HANDLE             DeviceHandle,
    486  1.1    jruoho     char                    *Name,
    487  1.1    jruoho     ACPI_VENDOR_UUID        *Uuid,
    488  1.1    jruoho     ACPI_BUFFER             *RetBuffer)
    489  1.1    jruoho {
    490  1.1    jruoho     ACPI_VENDOR_WALK_INFO   Info;
    491  1.1    jruoho     ACPI_STATUS             Status;
    492  1.1    jruoho 
    493  1.1    jruoho 
    494  1.1    jruoho     /* Other parameters are validated by AcpiWalkResources */
    495  1.1    jruoho 
    496  1.1    jruoho     if (!Uuid || !RetBuffer)
    497  1.1    jruoho     {
    498  1.1    jruoho         return (AE_BAD_PARAMETER);
    499  1.1    jruoho     }
    500  1.1    jruoho 
    501  1.1    jruoho     Info.Uuid = Uuid;
    502  1.1    jruoho     Info.Buffer = RetBuffer;
    503  1.1    jruoho     Info.Status = AE_NOT_EXIST;
    504  1.1    jruoho 
    505  1.1    jruoho     /* Walk the _CRS or _PRS resource list for this device */
    506  1.1    jruoho 
    507  1.1    jruoho     Status = AcpiWalkResources (DeviceHandle, Name, AcpiRsMatchVendorResource,
    508  1.1    jruoho                 &Info);
    509  1.1    jruoho     if (ACPI_FAILURE (Status))
    510  1.1    jruoho     {
    511  1.1    jruoho         return (Status);
    512  1.1    jruoho     }
    513  1.1    jruoho 
    514  1.1    jruoho     return (Info.Status);
    515  1.1    jruoho }
    516  1.1    jruoho 
    517  1.1    jruoho ACPI_EXPORT_SYMBOL (AcpiGetVendorResource)
    518  1.1    jruoho 
    519  1.1    jruoho 
    520  1.1    jruoho /*******************************************************************************
    521  1.1    jruoho  *
    522  1.1    jruoho  * FUNCTION:    AcpiRsMatchVendorResource
    523  1.1    jruoho  *
    524  1.1    jruoho  * PARAMETERS:  ACPI_WALK_RESOURCE_CALLBACK
    525  1.1    jruoho  *
    526  1.1    jruoho  * RETURN:      Status
    527  1.1    jruoho  *
    528  1.1    jruoho  * DESCRIPTION: Match a vendor resource via the ACPI 3.0 UUID
    529  1.1    jruoho  *
    530  1.1    jruoho  ******************************************************************************/
    531  1.1    jruoho 
    532  1.1    jruoho static ACPI_STATUS
    533  1.1    jruoho AcpiRsMatchVendorResource (
    534  1.1    jruoho     ACPI_RESOURCE           *Resource,
    535  1.1    jruoho     void                    *Context)
    536  1.1    jruoho {
    537  1.1    jruoho     ACPI_VENDOR_WALK_INFO       *Info = Context;
    538  1.1    jruoho     ACPI_RESOURCE_VENDOR_TYPED  *Vendor;
    539  1.1    jruoho     ACPI_BUFFER                 *Buffer;
    540  1.1    jruoho     ACPI_STATUS                 Status;
    541  1.1    jruoho 
    542  1.1    jruoho 
    543  1.1    jruoho     /* Ignore all descriptors except Vendor */
    544  1.1    jruoho 
    545  1.1    jruoho     if (Resource->Type != ACPI_RESOURCE_TYPE_VENDOR)
    546  1.1    jruoho     {
    547  1.1    jruoho         return (AE_OK);
    548  1.1    jruoho     }
    549  1.1    jruoho 
    550  1.1    jruoho     Vendor = &Resource->Data.VendorTyped;
    551  1.1    jruoho 
    552  1.1    jruoho     /*
    553  1.1    jruoho      * For a valid match, these conditions must hold:
    554  1.1    jruoho      *
    555  1.1    jruoho      * 1) Length of descriptor data must be at least as long as a UUID struct
    556  1.1    jruoho      * 2) The UUID subtypes must match
    557  1.1    jruoho      * 3) The UUID data must match
    558  1.1    jruoho      */
    559  1.1    jruoho     if ((Vendor->ByteLength < (ACPI_UUID_LENGTH + 1)) ||
    560  1.1    jruoho         (Vendor->UuidSubtype != Info->Uuid->Subtype)  ||
    561  1.7  christos         (memcmp (Vendor->Uuid, Info->Uuid->Data, ACPI_UUID_LENGTH)))
    562  1.1    jruoho     {
    563  1.1    jruoho         return (AE_OK);
    564  1.1    jruoho     }
    565  1.1    jruoho 
    566  1.1    jruoho     /* Validate/Allocate/Clear caller buffer */
    567  1.1    jruoho 
    568  1.1    jruoho     Buffer = Info->Buffer;
    569  1.1    jruoho     Status = AcpiUtInitializeBuffer (Buffer, Resource->Length);
    570  1.1    jruoho     if (ACPI_FAILURE (Status))
    571  1.1    jruoho     {
    572  1.1    jruoho         return (Status);
    573  1.1    jruoho     }
    574  1.1    jruoho 
    575  1.1    jruoho     /* Found the correct resource, copy and return it */
    576  1.1    jruoho 
    577  1.7  christos     memcpy (Buffer->Pointer, Resource, Resource->Length);
    578  1.1    jruoho     Buffer->Length = Resource->Length;
    579  1.1    jruoho 
    580  1.1    jruoho     /* Found the desired descriptor, terminate resource walk */
    581  1.1    jruoho 
    582  1.1    jruoho     Info->Status = AE_OK;
    583  1.1    jruoho     return (AE_CTRL_TERMINATE);
    584  1.1    jruoho }
    585  1.1    jruoho 
    586  1.1    jruoho 
    587  1.1    jruoho /*******************************************************************************
    588  1.1    jruoho  *
    589  1.4  christos  * FUNCTION:    AcpiWalkResourceBuffer
    590  1.1    jruoho  *
    591  1.4  christos  * PARAMETERS:  Buffer          - Formatted buffer returned by one of the
    592  1.4  christos  *                                various Get*Resource functions
    593  1.1    jruoho  *              UserFunction    - Called for each resource
    594  1.1    jruoho  *              Context         - Passed to UserFunction
    595  1.1    jruoho  *
    596  1.1    jruoho  * RETURN:      Status
    597  1.1    jruoho  *
    598  1.4  christos  * DESCRIPTION: Walks the input resource template. The UserFunction is called
    599  1.4  christos  *              once for each resource in the list.
    600  1.1    jruoho  *
    601  1.1    jruoho  ******************************************************************************/
    602  1.1    jruoho 
    603  1.1    jruoho ACPI_STATUS
    604  1.4  christos AcpiWalkResourceBuffer (
    605  1.4  christos     ACPI_BUFFER                 *Buffer,
    606  1.1    jruoho     ACPI_WALK_RESOURCE_CALLBACK UserFunction,
    607  1.1    jruoho     void                        *Context)
    608  1.1    jruoho {
    609  1.4  christos     ACPI_STATUS                 Status = AE_OK;
    610  1.1    jruoho     ACPI_RESOURCE               *Resource;
    611  1.1    jruoho     ACPI_RESOURCE               *ResourceEnd;
    612  1.1    jruoho 
    613  1.4  christos     ACPI_FUNCTION_TRACE (AcpiWalkResourceBuffer);
    614  1.1    jruoho 
    615  1.1    jruoho 
    616  1.1    jruoho     /* Parameter validation */
    617  1.1    jruoho 
    618  1.4  christos     if (!Buffer || !Buffer->Pointer || !UserFunction)
    619  1.1    jruoho     {
    620  1.1    jruoho         return_ACPI_STATUS (AE_BAD_PARAMETER);
    621  1.1    jruoho     }
    622  1.1    jruoho 
    623  1.4  christos     /* Buffer contains the resource list and length */
    624  1.1    jruoho 
    625  1.4  christos     Resource = ACPI_CAST_PTR (ACPI_RESOURCE, Buffer->Pointer);
    626  1.4  christos     ResourceEnd = ACPI_ADD_PTR (ACPI_RESOURCE, Buffer->Pointer, Buffer->Length);
    627  1.1    jruoho 
    628  1.1    jruoho     /* Walk the resource list until the EndTag is found (or buffer end) */
    629  1.1    jruoho 
    630  1.1    jruoho     while (Resource < ResourceEnd)
    631  1.1    jruoho     {
    632  1.4  christos         /* Sanity check the resource type */
    633  1.1    jruoho 
    634  1.1    jruoho         if (Resource->Type > ACPI_RESOURCE_TYPE_MAX)
    635  1.1    jruoho         {
    636  1.1    jruoho             Status = AE_AML_INVALID_RESOURCE_TYPE;
    637  1.1    jruoho             break;
    638  1.1    jruoho         }
    639  1.1    jruoho 
    640  1.4  christos         /* Sanity check the length. It must not be zero, or we loop forever */
    641  1.4  christos 
    642  1.4  christos         if (!Resource->Length)
    643  1.4  christos         {
    644  1.4  christos             return_ACPI_STATUS (AE_AML_BAD_RESOURCE_LENGTH);
    645  1.4  christos         }
    646  1.4  christos 
    647  1.1    jruoho         /* Invoke the user function, abort on any error returned */
    648  1.1    jruoho 
    649  1.1    jruoho         Status = UserFunction (Resource, Context);
    650  1.1    jruoho         if (ACPI_FAILURE (Status))
    651  1.1    jruoho         {
    652  1.1    jruoho             if (Status == AE_CTRL_TERMINATE)
    653  1.1    jruoho             {
    654  1.1    jruoho                 /* This is an OK termination by the user function */
    655  1.1    jruoho 
    656  1.1    jruoho                 Status = AE_OK;
    657  1.1    jruoho             }
    658  1.1    jruoho             break;
    659  1.1    jruoho         }
    660  1.1    jruoho 
    661  1.1    jruoho         /* EndTag indicates end-of-list */
    662  1.1    jruoho 
    663  1.1    jruoho         if (Resource->Type == ACPI_RESOURCE_TYPE_END_TAG)
    664  1.1    jruoho         {
    665  1.1    jruoho             break;
    666  1.1    jruoho         }
    667  1.1    jruoho 
    668  1.1    jruoho         /* Get the next resource descriptor */
    669  1.1    jruoho 
    670  1.4  christos         Resource = ACPI_NEXT_RESOURCE (Resource);
    671  1.1    jruoho     }
    672  1.1    jruoho 
    673  1.4  christos     return_ACPI_STATUS (Status);
    674  1.4  christos }
    675  1.4  christos 
    676  1.4  christos ACPI_EXPORT_SYMBOL (AcpiWalkResourceBuffer)
    677  1.4  christos 
    678  1.4  christos 
    679  1.4  christos /*******************************************************************************
    680  1.4  christos  *
    681  1.4  christos  * FUNCTION:    AcpiWalkResources
    682  1.4  christos  *
    683  1.4  christos  * PARAMETERS:  DeviceHandle    - Handle to the device object for the
    684  1.4  christos  *                                device we are querying
    685  1.4  christos  *              Name            - Method name of the resources we want.
    686  1.4  christos  *                                (METHOD_NAME__CRS, METHOD_NAME__PRS, or
    687  1.4  christos  *                                METHOD_NAME__AEI)
    688  1.4  christos  *              UserFunction    - Called for each resource
    689  1.4  christos  *              Context         - Passed to UserFunction
    690  1.4  christos  *
    691  1.4  christos  * RETURN:      Status
    692  1.4  christos  *
    693  1.4  christos  * DESCRIPTION: Retrieves the current or possible resource list for the
    694  1.4  christos  *              specified device. The UserFunction is called once for
    695  1.4  christos  *              each resource in the list.
    696  1.4  christos  *
    697  1.4  christos  ******************************************************************************/
    698  1.4  christos 
    699  1.4  christos ACPI_STATUS
    700  1.4  christos AcpiWalkResources (
    701  1.4  christos     ACPI_HANDLE                 DeviceHandle,
    702  1.4  christos     const char                  *Name,
    703  1.4  christos     ACPI_WALK_RESOURCE_CALLBACK UserFunction,
    704  1.4  christos     void                        *Context)
    705  1.4  christos {
    706  1.4  christos     ACPI_STATUS                 Status;
    707  1.4  christos     ACPI_BUFFER                 Buffer;
    708  1.4  christos 
    709  1.4  christos 
    710  1.4  christos     ACPI_FUNCTION_TRACE (AcpiWalkResources);
    711  1.4  christos 
    712  1.4  christos 
    713  1.4  christos     /* Parameter validation */
    714  1.4  christos 
    715  1.4  christos     if (!DeviceHandle || !UserFunction || !Name ||
    716  1.4  christos         (!ACPI_COMPARE_NAME (Name, METHOD_NAME__CRS) &&
    717  1.4  christos          !ACPI_COMPARE_NAME (Name, METHOD_NAME__PRS) &&
    718  1.4  christos          !ACPI_COMPARE_NAME (Name, METHOD_NAME__AEI)))
    719  1.4  christos     {
    720  1.4  christos         return_ACPI_STATUS (AE_BAD_PARAMETER);
    721  1.4  christos     }
    722  1.4  christos 
    723  1.4  christos     /* Get the _CRS/_PRS/_AEI resource list */
    724  1.4  christos 
    725  1.4  christos     Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
    726  1.4  christos     Status = AcpiRsGetMethodData (DeviceHandle, __UNCONST(Name), &Buffer);
    727  1.4  christos     if (ACPI_FAILURE (Status))
    728  1.4  christos     {
    729  1.4  christos         return_ACPI_STATUS (Status);
    730  1.4  christos     }
    731  1.4  christos 
    732  1.4  christos     /* Walk the resource list and cleanup */
    733  1.4  christos 
    734  1.4  christos     Status = AcpiWalkResourceBuffer (&Buffer, UserFunction, Context);
    735  1.1    jruoho     ACPI_FREE (Buffer.Pointer);
    736  1.1    jruoho     return_ACPI_STATUS (Status);
    737  1.1    jruoho }
    738  1.1    jruoho 
    739  1.1    jruoho ACPI_EXPORT_SYMBOL (AcpiWalkResources)
    740