xref: /onnv-gate/usr/src/uts/intel/io/acpica/resources/rsxface.c (revision 9980:13d7f3eec672)
13446Smrj /*******************************************************************************
23446Smrj  *
33446Smrj  * Module Name: rsxface - Public interfaces to the resource manager
43446Smrj  *
53446Smrj  ******************************************************************************/
63446Smrj 
73446Smrj /******************************************************************************
83446Smrj  *
93446Smrj  * 1. Copyright Notice
103446Smrj  *
11*9980SDana.Myers@Sun.COM  * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
123446Smrj  * All rights reserved.
133446Smrj  *
143446Smrj  * 2. License
153446Smrj  *
163446Smrj  * 2.1. This is your license from Intel Corp. under its intellectual property
173446Smrj  * rights.  You may have additional license terms from the party that provided
183446Smrj  * you this software, covering your right to use that party's intellectual
193446Smrj  * property rights.
203446Smrj  *
213446Smrj  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
223446Smrj  * copy of the source code appearing in this file ("Covered Code") an
233446Smrj  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
243446Smrj  * base code distributed originally by Intel ("Original Intel Code") to copy,
253446Smrj  * make derivatives, distribute, use and display any portion of the Covered
263446Smrj  * Code in any form, with the right to sublicense such rights; and
273446Smrj  *
283446Smrj  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
293446Smrj  * license (with the right to sublicense), under only those claims of Intel
303446Smrj  * patents that are infringed by the Original Intel Code, to make, use, sell,
313446Smrj  * offer to sell, and import the Covered Code and derivative works thereof
323446Smrj  * solely to the minimum extent necessary to exercise the above copyright
333446Smrj  * license, and in no event shall the patent license extend to any additions
343446Smrj  * to or modifications of the Original Intel Code.  No other license or right
353446Smrj  * is granted directly or by implication, estoppel or otherwise;
363446Smrj  *
373446Smrj  * The above copyright and patent license is granted only if the following
383446Smrj  * conditions are met:
393446Smrj  *
403446Smrj  * 3. Conditions
413446Smrj  *
423446Smrj  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
433446Smrj  * Redistribution of source code of any substantial portion of the Covered
443446Smrj  * Code or modification with rights to further distribute source must include
453446Smrj  * the above Copyright Notice, the above License, this list of Conditions,
463446Smrj  * and the following Disclaimer and Export Compliance provision.  In addition,
473446Smrj  * Licensee must cause all Covered Code to which Licensee contributes to
483446Smrj  * contain a file documenting the changes Licensee made to create that Covered
493446Smrj  * Code and the date of any change.  Licensee must include in that file the
503446Smrj  * documentation of any changes made by any predecessor Licensee.  Licensee
513446Smrj  * must include a prominent statement that the modification is derived,
523446Smrj  * directly or indirectly, from Original Intel Code.
533446Smrj  *
543446Smrj  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
553446Smrj  * Redistribution of source code of any substantial portion of the Covered
563446Smrj  * Code or modification without rights to further distribute source must
573446Smrj  * include the following Disclaimer and Export Compliance provision in the
583446Smrj  * documentation and/or other materials provided with distribution.  In
593446Smrj  * addition, Licensee may not authorize further sublicense of source of any
603446Smrj  * portion of the Covered Code, and must include terms to the effect that the
613446Smrj  * license from Licensee to its licensee is limited to the intellectual
623446Smrj  * property embodied in the software Licensee provides to its licensee, and
633446Smrj  * not to intellectual property embodied in modifications its licensee may
643446Smrj  * make.
653446Smrj  *
663446Smrj  * 3.3. Redistribution of Executable. Redistribution in executable form of any
673446Smrj  * substantial portion of the Covered Code or modification must reproduce the
683446Smrj  * above Copyright Notice, and the following Disclaimer and Export Compliance
693446Smrj  * provision in the documentation and/or other materials provided with the
703446Smrj  * distribution.
713446Smrj  *
723446Smrj  * 3.4. Intel retains all right, title, and interest in and to the Original
733446Smrj  * Intel Code.
743446Smrj  *
753446Smrj  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
763446Smrj  * Intel shall be used in advertising or otherwise to promote the sale, use or
773446Smrj  * other dealings in products derived from or relating to the Covered Code
783446Smrj  * without prior written authorization from Intel.
793446Smrj  *
803446Smrj  * 4. Disclaimer and Export Compliance
813446Smrj  *
823446Smrj  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
833446Smrj  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
843446Smrj  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
853446Smrj  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
863446Smrj  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
873446Smrj  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
883446Smrj  * PARTICULAR PURPOSE.
893446Smrj  *
903446Smrj  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
913446Smrj  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
923446Smrj  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
933446Smrj  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
943446Smrj  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
953446Smrj  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
963446Smrj  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
973446Smrj  * LIMITED REMEDY.
983446Smrj  *
993446Smrj  * 4.3. Licensee shall not export, either directly or indirectly, any of this
1003446Smrj  * software or system incorporating such software without first obtaining any
1013446Smrj  * required license or other approval from the U. S. Department of Commerce or
1023446Smrj  * any other agency or department of the United States Government.  In the
1033446Smrj  * event Licensee exports any such software from the United States or
1043446Smrj  * re-exports any such software from a foreign destination, Licensee shall
1053446Smrj  * ensure that the distribution and export/re-export of the software is in
1063446Smrj  * compliance with all laws, regulations, orders, or other restrictions of the
1073446Smrj  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1083446Smrj  * any of its subsidiaries will export/re-export any technical data, process,
1093446Smrj  * software, or service, directly or indirectly, to any country for which the
1103446Smrj  * United States government or any agency thereof requires an export license,
1113446Smrj  * other governmental approval, or letter of assurance, without first obtaining
1123446Smrj  * such license, approval or letter.
1133446Smrj  *
1143446Smrj  *****************************************************************************/
1153446Smrj 
1163446Smrj 
1173446Smrj #define __RSXFACE_C__
1183446Smrj 
1193446Smrj #include "acpi.h"
120*9980SDana.Myers@Sun.COM #include "accommon.h"
1213446Smrj #include "acresrc.h"
1223446Smrj #include "acnamesp.h"
1233446Smrj 
1243446Smrj #define _COMPONENT          ACPI_RESOURCES
1253446Smrj         ACPI_MODULE_NAME    ("rsxface")
1263446Smrj 
1273446Smrj /* Local macros for 16,32-bit to 64-bit conversion */
1283446Smrj 
1293446Smrj #define ACPI_COPY_FIELD(Out, In, Field)  ((Out)->Field = (In)->Field)
1303446Smrj #define ACPI_COPY_ADDRESS(Out, In)                      \
1313446Smrj     ACPI_COPY_FIELD(Out, In, ResourceType);              \
1323446Smrj     ACPI_COPY_FIELD(Out, In, ProducerConsumer);          \
1333446Smrj     ACPI_COPY_FIELD(Out, In, Decode);                    \
1343446Smrj     ACPI_COPY_FIELD(Out, In, MinAddressFixed);           \
1353446Smrj     ACPI_COPY_FIELD(Out, In, MaxAddressFixed);           \
1363446Smrj     ACPI_COPY_FIELD(Out, In, Info);                      \
1373446Smrj     ACPI_COPY_FIELD(Out, In, Granularity);               \
1383446Smrj     ACPI_COPY_FIELD(Out, In, Minimum);                   \
1393446Smrj     ACPI_COPY_FIELD(Out, In, Maximum);                   \
1403446Smrj     ACPI_COPY_FIELD(Out, In, TranslationOffset);         \
1413446Smrj     ACPI_COPY_FIELD(Out, In, AddressLength);             \
1423446Smrj     ACPI_COPY_FIELD(Out, In, ResourceSource);
1433446Smrj 
1443446Smrj 
1453446Smrj /* Local prototypes */
1463446Smrj 
1473446Smrj static ACPI_STATUS
1483446Smrj AcpiRsMatchVendorResource (
1493446Smrj     ACPI_RESOURCE           *Resource,
1503446Smrj     void                    *Context);
1513446Smrj 
1523446Smrj static ACPI_STATUS
1533446Smrj AcpiRsValidateParameters (
1543446Smrj     ACPI_HANDLE             DeviceHandle,
1553446Smrj     ACPI_BUFFER             *Buffer,
1563446Smrj     ACPI_NAMESPACE_NODE     **ReturnNode);
1573446Smrj 
1583446Smrj 
1593446Smrj /*******************************************************************************
1603446Smrj  *
1613446Smrj  * FUNCTION:    AcpiRsValidateParameters
1623446Smrj  *
1633446Smrj  * PARAMETERS:  DeviceHandle    - Handle to a device
1643446Smrj  *              Buffer          - Pointer to a data buffer
1653446Smrj  *              ReturnNode      - Pointer to where the device node is returned
1663446Smrj  *
1673446Smrj  * RETURN:      Status
1683446Smrj  *
1693446Smrj  * DESCRIPTION: Common parameter validation for resource interfaces
1703446Smrj  *
1713446Smrj  ******************************************************************************/
1723446Smrj 
1733446Smrj static ACPI_STATUS
AcpiRsValidateParameters(ACPI_HANDLE DeviceHandle,ACPI_BUFFER * Buffer,ACPI_NAMESPACE_NODE ** ReturnNode)1743446Smrj AcpiRsValidateParameters (
1753446Smrj     ACPI_HANDLE             DeviceHandle,
1763446Smrj     ACPI_BUFFER             *Buffer,
1773446Smrj     ACPI_NAMESPACE_NODE     **ReturnNode)
1783446Smrj {
1793446Smrj     ACPI_STATUS             Status;
1803446Smrj     ACPI_NAMESPACE_NODE     *Node;
1813446Smrj 
1823446Smrj 
1833446Smrj     ACPI_FUNCTION_TRACE (RsValidateParameters);
1843446Smrj 
1853446Smrj 
1863446Smrj     /*
1873446Smrj      * Must have a valid handle to an ACPI device
1883446Smrj      */
1893446Smrj     if (!DeviceHandle)
1903446Smrj     {
1913446Smrj         return_ACPI_STATUS (AE_BAD_PARAMETER);
1923446Smrj     }
1933446Smrj 
1943446Smrj     Node = AcpiNsMapHandleToNode (DeviceHandle);
1953446Smrj     if (!Node)
1963446Smrj     {
1973446Smrj         return_ACPI_STATUS (AE_BAD_PARAMETER);
1983446Smrj     }
1993446Smrj 
2003446Smrj     if (Node->Type != ACPI_TYPE_DEVICE)
2013446Smrj     {
2023446Smrj         return_ACPI_STATUS (AE_TYPE);
2033446Smrj     }
2043446Smrj 
2053446Smrj     /*
2063446Smrj      * Validate the user buffer object
2073446Smrj      *
2083446Smrj      * if there is a non-zero buffer length we also need a valid pointer in
2093446Smrj      * the buffer. If it's a zero buffer length, we'll be returning the
2103446Smrj      * needed buffer size (later), so keep going.
2113446Smrj      */
2123446Smrj     Status = AcpiUtValidateBuffer (Buffer);
2133446Smrj     if (ACPI_FAILURE (Status))
2143446Smrj     {
2153446Smrj         return_ACPI_STATUS (Status);
2163446Smrj     }
2173446Smrj 
2183446Smrj     *ReturnNode = Node;
2193446Smrj     return_ACPI_STATUS (AE_OK);
2203446Smrj }
2213446Smrj 
2223446Smrj 
2233446Smrj /*******************************************************************************
2243446Smrj  *
2253446Smrj  * FUNCTION:    AcpiGetIrqRoutingTable
2263446Smrj  *
2273446Smrj  * PARAMETERS:  DeviceHandle    - Handle to the Bus device we are querying
2283446Smrj  *              RetBuffer       - Pointer to a buffer to receive the
2293446Smrj  *                                current resources for the device
2303446Smrj  *
2313446Smrj  * RETURN:      Status
2323446Smrj  *
2333446Smrj  * DESCRIPTION: This function is called to get the IRQ routing table for a
2343446Smrj  *              specific bus. The caller must first acquire a handle for the
2353446Smrj  *              desired bus. The routine table is placed in the buffer pointed
2363446Smrj  *              to by the RetBuffer variable parameter.
2373446Smrj  *
2383446Smrj  *              If the function fails an appropriate status will be returned
2393446Smrj  *              and the value of RetBuffer is undefined.
2403446Smrj  *
2413446Smrj  *              This function attempts to execute the _PRT method contained in
2423446Smrj  *              the object indicated by the passed DeviceHandle.
2433446Smrj  *
2443446Smrj  ******************************************************************************/
2453446Smrj 
2463446Smrj ACPI_STATUS
AcpiGetIrqRoutingTable(ACPI_HANDLE DeviceHandle,ACPI_BUFFER * RetBuffer)2473446Smrj AcpiGetIrqRoutingTable  (
2483446Smrj     ACPI_HANDLE             DeviceHandle,
2493446Smrj     ACPI_BUFFER             *RetBuffer)
2503446Smrj {
2513446Smrj     ACPI_STATUS             Status;
2523446Smrj     ACPI_NAMESPACE_NODE     *Node;
2533446Smrj 
2543446Smrj 
2553446Smrj     ACPI_FUNCTION_TRACE (AcpiGetIrqRoutingTable);
2563446Smrj 
2573446Smrj 
2583446Smrj     /* Validate parameters then dispatch to internal routine */
2593446Smrj 
2603446Smrj     Status = AcpiRsValidateParameters (DeviceHandle, RetBuffer, &Node);
2613446Smrj     if (ACPI_FAILURE (Status))
2623446Smrj     {
2633446Smrj         return_ACPI_STATUS (Status);
2643446Smrj     }
2653446Smrj 
2663446Smrj     Status = AcpiRsGetPrtMethodData (Node, RetBuffer);
2673446Smrj     return_ACPI_STATUS (Status);
2683446Smrj }
2693446Smrj 
ACPI_EXPORT_SYMBOL(AcpiGetIrqRoutingTable)2703446Smrj ACPI_EXPORT_SYMBOL (AcpiGetIrqRoutingTable)
2713446Smrj 
2723446Smrj 
2733446Smrj /*******************************************************************************
2743446Smrj  *
2753446Smrj  * FUNCTION:    AcpiGetCurrentResources
2763446Smrj  *
2773446Smrj  * PARAMETERS:  DeviceHandle    - Handle to the device object for the
2783446Smrj  *                                device we are querying
2793446Smrj  *              RetBuffer       - Pointer to a buffer to receive the
2803446Smrj  *                                current resources for the device
2813446Smrj  *
2823446Smrj  * RETURN:      Status
2833446Smrj  *
2843446Smrj  * DESCRIPTION: This function is called to get the current resources for a
2853446Smrj  *              specific device. The caller must first acquire a handle for
2863446Smrj  *              the desired device. The resource data is placed in the buffer
2873446Smrj  *              pointed to by the RetBuffer variable parameter.
2883446Smrj  *
2893446Smrj  *              If the function fails an appropriate status will be returned
2903446Smrj  *              and the value of RetBuffer is undefined.
2913446Smrj  *
2923446Smrj  *              This function attempts to execute the _CRS method contained in
2933446Smrj  *              the object indicated by the passed DeviceHandle.
2943446Smrj  *
2953446Smrj  ******************************************************************************/
2963446Smrj 
2973446Smrj ACPI_STATUS
2983446Smrj AcpiGetCurrentResources (
2993446Smrj     ACPI_HANDLE             DeviceHandle,
3003446Smrj     ACPI_BUFFER             *RetBuffer)
3013446Smrj {
3023446Smrj     ACPI_STATUS             Status;
3033446Smrj     ACPI_NAMESPACE_NODE     *Node;
3043446Smrj 
3053446Smrj 
3063446Smrj     ACPI_FUNCTION_TRACE (AcpiGetCurrentResources);
3073446Smrj 
3083446Smrj 
3093446Smrj     /* Validate parameters then dispatch to internal routine */
3103446Smrj 
3113446Smrj     Status = AcpiRsValidateParameters (DeviceHandle, RetBuffer, &Node);
3123446Smrj     if (ACPI_FAILURE (Status))
3133446Smrj     {
3143446Smrj         return_ACPI_STATUS (Status);
3153446Smrj     }
3163446Smrj 
3173446Smrj     Status = AcpiRsGetCrsMethodData (Node, RetBuffer);
3183446Smrj     return_ACPI_STATUS (Status);
3193446Smrj }
3203446Smrj 
ACPI_EXPORT_SYMBOL(AcpiGetCurrentResources)3213446Smrj ACPI_EXPORT_SYMBOL (AcpiGetCurrentResources)
3223446Smrj 
3233446Smrj 
3243446Smrj /*******************************************************************************
3253446Smrj  *
3263446Smrj  * FUNCTION:    AcpiGetPossibleResources
3273446Smrj  *
3283446Smrj  * PARAMETERS:  DeviceHandle    - Handle to the device object for the
3293446Smrj  *                                device we are querying
3303446Smrj  *              RetBuffer       - Pointer to a buffer to receive the
3313446Smrj  *                                resources for the device
3323446Smrj  *
3333446Smrj  * RETURN:      Status
3343446Smrj  *
3353446Smrj  * DESCRIPTION: This function is called to get a list of the possible resources
3363446Smrj  *              for a specific device. The caller must first acquire a handle
3373446Smrj  *              for the desired device. The resource data is placed in the
3383446Smrj  *              buffer pointed to by the RetBuffer variable.
3393446Smrj  *
3403446Smrj  *              If the function fails an appropriate status will be returned
3413446Smrj  *              and the value of RetBuffer is undefined.
3423446Smrj  *
3433446Smrj  ******************************************************************************/
3443446Smrj 
3453446Smrj ACPI_STATUS
3463446Smrj AcpiGetPossibleResources (
3473446Smrj     ACPI_HANDLE             DeviceHandle,
3483446Smrj     ACPI_BUFFER             *RetBuffer)
3493446Smrj {
3503446Smrj     ACPI_STATUS             Status;
3513446Smrj     ACPI_NAMESPACE_NODE     *Node;
3523446Smrj 
3533446Smrj 
3543446Smrj     ACPI_FUNCTION_TRACE (AcpiGetPossibleResources);
3553446Smrj 
3563446Smrj 
3573446Smrj     /* Validate parameters then dispatch to internal routine */
3583446Smrj 
3593446Smrj     Status = AcpiRsValidateParameters (DeviceHandle, RetBuffer, &Node);
3603446Smrj     if (ACPI_FAILURE (Status))
3613446Smrj     {
3623446Smrj         return_ACPI_STATUS (Status);
3633446Smrj     }
3643446Smrj 
3653446Smrj     Status = AcpiRsGetPrsMethodData (Node, RetBuffer);
3663446Smrj     return_ACPI_STATUS (Status);
3673446Smrj }
3683446Smrj 
ACPI_EXPORT_SYMBOL(AcpiGetPossibleResources)3693446Smrj ACPI_EXPORT_SYMBOL (AcpiGetPossibleResources)
3703446Smrj 
3713446Smrj 
3723446Smrj /*******************************************************************************
3733446Smrj  *
3743446Smrj  * FUNCTION:    AcpiSetCurrentResources
3753446Smrj  *
3763446Smrj  * PARAMETERS:  DeviceHandle    - Handle to the device object for the
3773446Smrj  *                                device we are setting resources
3783446Smrj  *              InBuffer        - Pointer to a buffer containing the
3793446Smrj  *                                resources to be set for the device
3803446Smrj  *
3813446Smrj  * RETURN:      Status
3823446Smrj  *
3833446Smrj  * DESCRIPTION: This function is called to set the current resources for a
3843446Smrj  *              specific device. The caller must first acquire a handle for
3853446Smrj  *              the desired device. The resource data is passed to the routine
3863446Smrj  *              the buffer pointed to by the InBuffer variable.
3873446Smrj  *
3883446Smrj  ******************************************************************************/
3893446Smrj 
3903446Smrj ACPI_STATUS
3913446Smrj AcpiSetCurrentResources (
3923446Smrj     ACPI_HANDLE             DeviceHandle,
3933446Smrj     ACPI_BUFFER             *InBuffer)
3943446Smrj {
3953446Smrj     ACPI_STATUS             Status;
3963446Smrj     ACPI_NAMESPACE_NODE     *Node;
3973446Smrj 
3983446Smrj 
3993446Smrj     ACPI_FUNCTION_TRACE (AcpiSetCurrentResources);
4003446Smrj 
4013446Smrj 
4023446Smrj     /* Validate the buffer, don't allow zero length */
4033446Smrj 
4043446Smrj     if ((!InBuffer) ||
4053446Smrj         (!InBuffer->Pointer) ||
4063446Smrj         (!InBuffer->Length))
4073446Smrj     {
4083446Smrj         return_ACPI_STATUS (AE_BAD_PARAMETER);
4093446Smrj     }
4103446Smrj 
4113446Smrj     /* Validate parameters then dispatch to internal routine */
4123446Smrj 
4133446Smrj     Status = AcpiRsValidateParameters (DeviceHandle, InBuffer, &Node);
4143446Smrj     if (ACPI_FAILURE (Status))
4153446Smrj     {
4163446Smrj         return_ACPI_STATUS (Status);
4173446Smrj     }
4183446Smrj 
4193446Smrj     Status = AcpiRsSetSrsMethodData (Node, InBuffer);
4203446Smrj     return_ACPI_STATUS (Status);
4213446Smrj }
4223446Smrj 
ACPI_EXPORT_SYMBOL(AcpiSetCurrentResources)4233446Smrj ACPI_EXPORT_SYMBOL (AcpiSetCurrentResources)
4243446Smrj 
4253446Smrj 
4263446Smrj /******************************************************************************
4273446Smrj  *
4283446Smrj  * FUNCTION:    AcpiResourceToAddress64
4293446Smrj  *
4303446Smrj  * PARAMETERS:  Resource        - Pointer to a resource
4313446Smrj  *              Out             - Pointer to the users's return buffer
4323446Smrj  *                                (a struct acpi_resource_address64)
4333446Smrj  *
4343446Smrj  * RETURN:      Status
4353446Smrj  *
4363446Smrj  * DESCRIPTION: If the resource is an address16, address32, or address64,
4373446Smrj  *              copy it to the address64 return buffer. This saves the
4383446Smrj  *              caller from having to duplicate code for different-sized
4393446Smrj  *              addresses.
4403446Smrj  *
4413446Smrj  ******************************************************************************/
4423446Smrj 
4433446Smrj ACPI_STATUS
4443446Smrj AcpiResourceToAddress64 (
4453446Smrj     ACPI_RESOURCE               *Resource,
4463446Smrj     ACPI_RESOURCE_ADDRESS64     *Out)
4473446Smrj {
4483446Smrj     ACPI_RESOURCE_ADDRESS16     *Address16;
4493446Smrj     ACPI_RESOURCE_ADDRESS32     *Address32;
4503446Smrj 
4513446Smrj 
4523446Smrj     if (!Resource || !Out)
4533446Smrj     {
4543446Smrj         return (AE_BAD_PARAMETER);
4553446Smrj     }
4563446Smrj 
4573446Smrj     /* Convert 16 or 32 address descriptor to 64 */
4583446Smrj 
4593446Smrj     switch (Resource->Type)
4603446Smrj     {
4613446Smrj     case ACPI_RESOURCE_TYPE_ADDRESS16:
4623446Smrj 
463*9980SDana.Myers@Sun.COM         Address16 = ACPI_CAST_PTR (ACPI_RESOURCE_ADDRESS16, &Resource->Data);
4643446Smrj         ACPI_COPY_ADDRESS (Out, Address16);
4653446Smrj         break;
4663446Smrj 
4673446Smrj     case ACPI_RESOURCE_TYPE_ADDRESS32:
4683446Smrj 
469*9980SDana.Myers@Sun.COM         Address32 = ACPI_CAST_PTR (ACPI_RESOURCE_ADDRESS32, &Resource->Data);
4703446Smrj         ACPI_COPY_ADDRESS (Out, Address32);
4713446Smrj         break;
4723446Smrj 
4733446Smrj     case ACPI_RESOURCE_TYPE_ADDRESS64:
4743446Smrj 
4753446Smrj         /* Simple copy for 64 bit source */
4763446Smrj 
4773446Smrj         ACPI_MEMCPY (Out, &Resource->Data, sizeof (ACPI_RESOURCE_ADDRESS64));
4783446Smrj         break;
4793446Smrj 
4803446Smrj     default:
4813446Smrj         return (AE_BAD_PARAMETER);
4823446Smrj     }
4833446Smrj 
4843446Smrj     return (AE_OK);
4853446Smrj }
4863446Smrj 
ACPI_EXPORT_SYMBOL(AcpiResourceToAddress64)4873446Smrj ACPI_EXPORT_SYMBOL (AcpiResourceToAddress64)
4883446Smrj 
4893446Smrj 
4903446Smrj /*******************************************************************************
4913446Smrj  *
4923446Smrj  * FUNCTION:    AcpiGetVendorResource
4933446Smrj  *
4943446Smrj  * PARAMETERS:  DeviceHandle    - Handle for the parent device object
4953446Smrj  *              Name            - Method name for the parent resource
4963446Smrj  *                                (METHOD_NAME__CRS or METHOD_NAME__PRS)
4973446Smrj  *              Uuid            - Pointer to the UUID to be matched.
4983446Smrj  *                                includes both subtype and 16-byte UUID
4993446Smrj  *              RetBuffer       - Where the vendor resource is returned
5003446Smrj  *
5013446Smrj  * RETURN:      Status
5023446Smrj  *
5033446Smrj  * DESCRIPTION: Walk a resource template for the specified evice to find a
5043446Smrj  *              vendor-defined resource that matches the supplied UUID and
5053446Smrj  *              UUID subtype. Returns a ACPI_RESOURCE of type Vendor.
5063446Smrj  *
5073446Smrj  ******************************************************************************/
5083446Smrj 
5093446Smrj ACPI_STATUS
5103446Smrj AcpiGetVendorResource (
5113446Smrj     ACPI_HANDLE             DeviceHandle,
5123446Smrj     char                    *Name,
5133446Smrj     ACPI_VENDOR_UUID        *Uuid,
5143446Smrj     ACPI_BUFFER             *RetBuffer)
5153446Smrj {
5163446Smrj     ACPI_VENDOR_WALK_INFO   Info;
5173446Smrj     ACPI_STATUS             Status;
5183446Smrj 
5193446Smrj 
5203446Smrj     /* Other parameters are validated by AcpiWalkResources */
5213446Smrj 
5223446Smrj     if (!Uuid || !RetBuffer)
5233446Smrj     {
5243446Smrj         return (AE_BAD_PARAMETER);
5253446Smrj     }
5263446Smrj 
5273446Smrj     Info.Uuid = Uuid;
5283446Smrj     Info.Buffer = RetBuffer;
5293446Smrj     Info.Status = AE_NOT_EXIST;
5303446Smrj 
5313446Smrj     /* Walk the _CRS or _PRS resource list for this device */
5323446Smrj 
5333446Smrj     Status = AcpiWalkResources (DeviceHandle, Name, AcpiRsMatchVendorResource,
5343446Smrj                 &Info);
5353446Smrj     if (ACPI_FAILURE (Status))
5363446Smrj     {
5373446Smrj         return (Status);
5383446Smrj     }
5393446Smrj 
5403446Smrj     return (Info.Status);
5413446Smrj }
5423446Smrj 
ACPI_EXPORT_SYMBOL(AcpiGetVendorResource)5433446Smrj ACPI_EXPORT_SYMBOL (AcpiGetVendorResource)
5443446Smrj 
5453446Smrj 
5463446Smrj /*******************************************************************************
5473446Smrj  *
5483446Smrj  * FUNCTION:    AcpiRsMatchVendorResource
5493446Smrj  *
5503446Smrj  * PARAMETERS:  ACPI_WALK_RESOURCE_CALLBACK
5513446Smrj  *
5523446Smrj  * RETURN:      Status
5533446Smrj  *
5543446Smrj  * DESCRIPTION: Match a vendor resource via the ACPI 3.0 UUID
5553446Smrj  *
5563446Smrj  ******************************************************************************/
5573446Smrj 
5583446Smrj static ACPI_STATUS
5593446Smrj AcpiRsMatchVendorResource (
5603446Smrj     ACPI_RESOURCE           *Resource,
5613446Smrj     void                    *Context)
5623446Smrj {
5633446Smrj     ACPI_VENDOR_WALK_INFO       *Info = Context;
5643446Smrj     ACPI_RESOURCE_VENDOR_TYPED  *Vendor;
5653446Smrj     ACPI_BUFFER                 *Buffer;
5663446Smrj     ACPI_STATUS                 Status;
5673446Smrj 
5683446Smrj 
5693446Smrj     /* Ignore all descriptors except Vendor */
5703446Smrj 
5713446Smrj     if (Resource->Type != ACPI_RESOURCE_TYPE_VENDOR)
5723446Smrj     {
5733446Smrj         return (AE_OK);
5743446Smrj     }
5753446Smrj 
5763446Smrj     Vendor = &Resource->Data.VendorTyped;
5773446Smrj 
5783446Smrj     /*
5793446Smrj      * For a valid match, these conditions must hold:
5803446Smrj      *
5813446Smrj      * 1) Length of descriptor data must be at least as long as a UUID struct
5823446Smrj      * 2) The UUID subtypes must match
5833446Smrj      * 3) The UUID data must match
5843446Smrj      */
5853446Smrj     if ((Vendor->ByteLength < (ACPI_UUID_LENGTH + 1)) ||
5863446Smrj         (Vendor->UuidSubtype != Info->Uuid->Subtype)  ||
5873446Smrj         (ACPI_MEMCMP (Vendor->Uuid, Info->Uuid->Data, ACPI_UUID_LENGTH)))
5883446Smrj     {
5893446Smrj         return (AE_OK);
5903446Smrj     }
5913446Smrj 
5923446Smrj     /* Validate/Allocate/Clear caller buffer */
5933446Smrj 
5943446Smrj     Buffer = Info->Buffer;
5953446Smrj     Status = AcpiUtInitializeBuffer (Buffer, Resource->Length);
5963446Smrj     if (ACPI_FAILURE (Status))
5973446Smrj     {
5983446Smrj         return (Status);
5993446Smrj     }
6003446Smrj 
6013446Smrj     /* Found the correct resource, copy and return it */
6023446Smrj 
6033446Smrj     ACPI_MEMCPY (Buffer->Pointer, Resource, Resource->Length);
6043446Smrj     Buffer->Length = Resource->Length;
6053446Smrj 
6063446Smrj     /* Found the desired descriptor, terminate resource walk */
6073446Smrj 
6083446Smrj     Info->Status = AE_OK;
6093446Smrj     return (AE_CTRL_TERMINATE);
6103446Smrj }
6113446Smrj 
6123446Smrj 
6133446Smrj /*******************************************************************************
6143446Smrj  *
6153446Smrj  * FUNCTION:    AcpiWalkResources
6163446Smrj  *
6173446Smrj  * PARAMETERS:  DeviceHandle    - Handle to the device object for the
6183446Smrj  *                                device we are querying
6193446Smrj  *              Name            - Method name of the resources we want
6203446Smrj  *                                (METHOD_NAME__CRS or METHOD_NAME__PRS)
6213446Smrj  *              UserFunction    - Called for each resource
6223446Smrj  *              Context         - Passed to UserFunction
6233446Smrj  *
6243446Smrj  * RETURN:      Status
6253446Smrj  *
6263446Smrj  * DESCRIPTION: Retrieves the current or possible resource list for the
6273446Smrj  *              specified device. The UserFunction is called once for
6283446Smrj  *              each resource in the list.
6293446Smrj  *
6303446Smrj  ******************************************************************************/
6313446Smrj 
6323446Smrj ACPI_STATUS
AcpiWalkResources(ACPI_HANDLE DeviceHandle,char * Name,ACPI_WALK_RESOURCE_CALLBACK UserFunction,void * Context)6333446Smrj AcpiWalkResources (
6343446Smrj     ACPI_HANDLE                 DeviceHandle,
6353446Smrj     char                        *Name,
6363446Smrj     ACPI_WALK_RESOURCE_CALLBACK UserFunction,
6373446Smrj     void                        *Context)
6383446Smrj {
6393446Smrj     ACPI_STATUS                 Status;
6403446Smrj     ACPI_BUFFER                 Buffer;
6413446Smrj     ACPI_RESOURCE               *Resource;
6423446Smrj     ACPI_RESOURCE               *ResourceEnd;
6433446Smrj 
6443446Smrj 
6453446Smrj     ACPI_FUNCTION_TRACE (AcpiWalkResources);
6463446Smrj 
6473446Smrj 
6483446Smrj     /* Parameter validation */
6493446Smrj 
6503446Smrj     if (!DeviceHandle || !UserFunction || !Name ||
6513446Smrj         (!ACPI_COMPARE_NAME (Name, METHOD_NAME__CRS) &&
6523446Smrj          !ACPI_COMPARE_NAME (Name, METHOD_NAME__PRS)))
6533446Smrj     {
6543446Smrj         return_ACPI_STATUS (AE_BAD_PARAMETER);
6553446Smrj     }
6563446Smrj 
6573446Smrj     /* Get the _CRS or _PRS resource list */
6583446Smrj 
6593446Smrj     Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
6603446Smrj     Status = AcpiRsGetMethodData (DeviceHandle, Name, &Buffer);
6613446Smrj     if (ACPI_FAILURE (Status))
6623446Smrj     {
6633446Smrj         return_ACPI_STATUS (Status);
6643446Smrj     }
6653446Smrj 
6663446Smrj     /* Buffer now contains the resource list */
6673446Smrj 
6683446Smrj     Resource = ACPI_CAST_PTR (ACPI_RESOURCE, Buffer.Pointer);
6693446Smrj     ResourceEnd = ACPI_ADD_PTR (ACPI_RESOURCE, Buffer.Pointer, Buffer.Length);
6703446Smrj 
6713446Smrj     /* Walk the resource list until the EndTag is found (or buffer end) */
6723446Smrj 
6733446Smrj     while (Resource < ResourceEnd)
6743446Smrj     {
6753446Smrj         /* Sanity check the resource */
6763446Smrj 
6773446Smrj         if (Resource->Type > ACPI_RESOURCE_TYPE_MAX)
6783446Smrj         {
6793446Smrj             Status = AE_AML_INVALID_RESOURCE_TYPE;
6803446Smrj             break;
6813446Smrj         }
6823446Smrj 
6833446Smrj         /* Invoke the user function, abort on any error returned */
6843446Smrj 
6853446Smrj         Status = UserFunction (Resource, Context);
6863446Smrj         if (ACPI_FAILURE (Status))
6873446Smrj         {
6883446Smrj             if (Status == AE_CTRL_TERMINATE)
6893446Smrj             {
6903446Smrj                 /* This is an OK termination by the user function */
6913446Smrj 
6923446Smrj                 Status = AE_OK;
6933446Smrj             }
6943446Smrj             break;
6953446Smrj         }
6963446Smrj 
6973446Smrj         /* EndTag indicates end-of-list */
6983446Smrj 
6993446Smrj         if (Resource->Type == ACPI_RESOURCE_TYPE_END_TAG)
7003446Smrj         {
7013446Smrj             break;
7023446Smrj         }
7033446Smrj 
7043446Smrj         /* Get the next resource descriptor */
7053446Smrj 
7063446Smrj         Resource = ACPI_ADD_PTR (ACPI_RESOURCE, Resource, Resource->Length);
7073446Smrj     }
7083446Smrj 
7093446Smrj     ACPI_FREE (Buffer.Pointer);
7103446Smrj     return_ACPI_STATUS (Status);
7113446Smrj }
7123446Smrj 
7133446Smrj ACPI_EXPORT_SYMBOL (AcpiWalkResources)
714