Back to home page

LXR

 
 

    


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

0001 /*******************************************************************************
0002  *
0003  * Module Name: rsxface - Public interfaces to the resource manager
0004  *
0005  ******************************************************************************/
0006 
0007 /******************************************************************************
0008  *
0009  * 1. Copyright Notice
0010  *
0011  * Some or all of this work - Copyright (c) 1999 - 2024, Intel Corp.
0012  * All rights reserved.
0013  *
0014  * 2. License
0015  *
0016  * 2.1. This is your license from Intel Corp. under its intellectual property
0017  * rights. You may have additional license terms from the party that provided
0018  * you this software, covering your right to use that party's intellectual
0019  * property rights.
0020  *
0021  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
0022  * copy of the source code appearing in this file ("Covered Code") an
0023  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
0024  * base code distributed originally by Intel ("Original Intel Code") to copy,
0025  * make derivatives, distribute, use and display any portion of the Covered
0026  * Code in any form, with the right to sublicense such rights; and
0027  *
0028  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
0029  * license (with the right to sublicense), under only those claims of Intel
0030  * patents that are infringed by the Original Intel Code, to make, use, sell,
0031  * offer to sell, and import the Covered Code and derivative works thereof
0032  * solely to the minimum extent necessary to exercise the above copyright
0033  * license, and in no event shall the patent license extend to any additions
0034  * to or modifications of the Original Intel Code. No other license or right
0035  * is granted directly or by implication, estoppel or otherwise;
0036  *
0037  * The above copyright and patent license is granted only if the following
0038  * conditions are met:
0039  *
0040  * 3. Conditions
0041  *
0042  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
0043  * Redistribution of source code of any substantial portion of the Covered
0044  * Code or modification with rights to further distribute source must include
0045  * the above Copyright Notice, the above License, this list of Conditions,
0046  * and the following Disclaimer and Export Compliance provision. In addition,
0047  * Licensee must cause all Covered Code to which Licensee contributes to
0048  * contain a file documenting the changes Licensee made to create that Covered
0049  * Code and the date of any change. Licensee must include in that file the
0050  * documentation of any changes made by any predecessor Licensee. Licensee
0051  * must include a prominent statement that the modification is derived,
0052  * directly or indirectly, from Original Intel Code.
0053  *
0054  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
0055  * Redistribution of source code of any substantial portion of the Covered
0056  * Code or modification without rights to further distribute source must
0057  * include the following Disclaimer and Export Compliance provision in the
0058  * documentation and/or other materials provided with distribution. In
0059  * addition, Licensee may not authorize further sublicense of source of any
0060  * portion of the Covered Code, and must include terms to the effect that the
0061  * license from Licensee to its licensee is limited to the intellectual
0062  * property embodied in the software Licensee provides to its licensee, and
0063  * not to intellectual property embodied in modifications its licensee may
0064  * make.
0065  *
0066  * 3.3. Redistribution of Executable. Redistribution in executable form of any
0067  * substantial portion of the Covered Code or modification must reproduce the
0068  * above Copyright Notice, and the following Disclaimer and Export Compliance
0069  * provision in the documentation and/or other materials provided with the
0070  * distribution.
0071  *
0072  * 3.4. Intel retains all right, title, and interest in and to the Original
0073  * Intel Code.
0074  *
0075  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
0076  * Intel shall be used in advertising or otherwise to promote the sale, use or
0077  * other dealings in products derived from or relating to the Covered Code
0078  * without prior written authorization from Intel.
0079  *
0080  * 4. Disclaimer and Export Compliance
0081  *
0082  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
0083  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
0084  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
0085  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
0086  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
0087  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
0088  * PARTICULAR PURPOSE.
0089  *
0090  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
0091  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
0092  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
0093  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
0094  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
0095  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
0096  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
0097  * LIMITED REMEDY.
0098  *
0099  * 4.3. Licensee shall not export, either directly or indirectly, any of this
0100  * software or system incorporating such software without first obtaining any
0101  * required license or other approval from the U. S. Department of Commerce or
0102  * any other agency or department of the United States Government. In the
0103  * event Licensee exports any such software from the United States or
0104  * re-exports any such software from a foreign destination, Licensee shall
0105  * ensure that the distribution and export/re-export of the software is in
0106  * compliance with all laws, regulations, orders, or other restrictions of the
0107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
0108  * any of its subsidiaries will export/re-export any technical data, process,
0109  * software, or service, directly or indirectly, to any country for which the
0110  * United States government or any agency thereof requires an export license,
0111  * other governmental approval, or letter of assurance, without first obtaining
0112  * such license, approval or letter.
0113  *
0114  *****************************************************************************
0115  *
0116  * Alternatively, you may choose to be licensed under the terms of the
0117  * following license:
0118  *
0119  * Redistribution and use in source and binary forms, with or without
0120  * modification, are permitted provided that the following conditions
0121  * are met:
0122  * 1. Redistributions of source code must retain the above copyright
0123  *    notice, this list of conditions, and the following disclaimer,
0124  *    without modification.
0125  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
0126  *    substantially similar to the "NO WARRANTY" disclaimer below
0127  *    ("Disclaimer") and any redistribution must be conditioned upon
0128  *    including a substantially similar Disclaimer requirement for further
0129  *    binary redistribution.
0130  * 3. Neither the names of the above-listed copyright holders nor the names
0131  *    of any contributors may be used to endorse or promote products derived
0132  *    from this software without specific prior written permission.
0133  *
0134  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0135  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0136  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
0137  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
0138  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0139  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0140  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0141  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0142  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0143  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0144  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0145  *
0146  * Alternatively, you may choose to be licensed under the terms of the
0147  * GNU General Public License ("GPL") version 2 as published by the Free
0148  * Software Foundation.
0149  *
0150  *****************************************************************************/
0151 
0152 #define EXPORT_ACPI_INTERFACES
0153 
0154 #include "acpi.h"
0155 #include "accommon.h"
0156 #include "acresrc.h"
0157 #include "acnamesp.h"
0158 
0159 #define _COMPONENT          ACPI_RESOURCES
0160         ACPI_MODULE_NAME    ("rsxface")
0161 
0162 /* Local macros for 16,32-bit to 64-bit conversion */
0163 
0164 #define ACPI_COPY_FIELD(Out, In, Field)  ((Out)->Field = (In)->Field)
0165 #define ACPI_COPY_ADDRESS(Out, In)                       \
0166     ACPI_COPY_FIELD(Out, In, ResourceType);              \
0167     ACPI_COPY_FIELD(Out, In, ProducerConsumer);          \
0168     ACPI_COPY_FIELD(Out, In, Decode);                    \
0169     ACPI_COPY_FIELD(Out, In, MinAddressFixed);           \
0170     ACPI_COPY_FIELD(Out, In, MaxAddressFixed);           \
0171     ACPI_COPY_FIELD(Out, In, Info);                      \
0172     ACPI_COPY_FIELD(Out, In, Address.Granularity);       \
0173     ACPI_COPY_FIELD(Out, In, Address.Minimum);           \
0174     ACPI_COPY_FIELD(Out, In, Address.Maximum);           \
0175     ACPI_COPY_FIELD(Out, In, Address.TranslationOffset); \
0176     ACPI_COPY_FIELD(Out, In, Address.AddressLength);     \
0177     ACPI_COPY_FIELD(Out, In, ResourceSource);
0178 
0179 
0180 /* Local prototypes */
0181 
0182 static ACPI_STATUS
0183 AcpiRsMatchVendorResource (
0184     ACPI_RESOURCE           *Resource,
0185     void                    *Context);
0186 
0187 static ACPI_STATUS
0188 AcpiRsValidateParameters (
0189     ACPI_HANDLE             DeviceHandle,
0190     ACPI_BUFFER             *Buffer,
0191     ACPI_NAMESPACE_NODE     **ReturnNode);
0192 
0193 
0194 /*******************************************************************************
0195  *
0196  * FUNCTION:    AcpiRsValidateParameters
0197  *
0198  * PARAMETERS:  DeviceHandle    - Handle to a device
0199  *              Buffer          - Pointer to a data buffer
0200  *              ReturnNode      - Pointer to where the device node is returned
0201  *
0202  * RETURN:      Status
0203  *
0204  * DESCRIPTION: Common parameter validation for resource interfaces
0205  *
0206  ******************************************************************************/
0207 
0208 static ACPI_STATUS
0209 AcpiRsValidateParameters (
0210     ACPI_HANDLE             DeviceHandle,
0211     ACPI_BUFFER             *Buffer,
0212     ACPI_NAMESPACE_NODE     **ReturnNode)
0213 {
0214     ACPI_STATUS             Status;
0215     ACPI_NAMESPACE_NODE     *Node;
0216 
0217 
0218     ACPI_FUNCTION_TRACE (RsValidateParameters);
0219 
0220 
0221     /*
0222      * Must have a valid handle to an ACPI device
0223      */
0224     if (!DeviceHandle)
0225     {
0226         return_ACPI_STATUS (AE_BAD_PARAMETER);
0227     }
0228 
0229     Node = AcpiNsValidateHandle (DeviceHandle);
0230     if (!Node)
0231     {
0232         return_ACPI_STATUS (AE_BAD_PARAMETER);
0233     }
0234 
0235     if (Node->Type != ACPI_TYPE_DEVICE)
0236     {
0237         return_ACPI_STATUS (AE_TYPE);
0238     }
0239 
0240     /*
0241      * Validate the user buffer object
0242      *
0243      * if there is a non-zero buffer length we also need a valid pointer in
0244      * the buffer. If it's a zero buffer length, we'll be returning the
0245      * needed buffer size (later), so keep going.
0246      */
0247     Status = AcpiUtValidateBuffer (Buffer);
0248     if (ACPI_FAILURE (Status))
0249     {
0250         return_ACPI_STATUS (Status);
0251     }
0252 
0253     *ReturnNode = Node;
0254     return_ACPI_STATUS (AE_OK);
0255 }
0256 
0257 
0258 /*******************************************************************************
0259  *
0260  * FUNCTION:    AcpiGetIrqRoutingTable
0261  *
0262  * PARAMETERS:  DeviceHandle    - Handle to the Bus device we are querying
0263  *              RetBuffer       - Pointer to a buffer to receive the
0264  *                                current resources for the device
0265  *
0266  * RETURN:      Status
0267  *
0268  * DESCRIPTION: This function is called to get the IRQ routing table for a
0269  *              specific bus. The caller must first acquire a handle for the
0270  *              desired bus. The routine table is placed in the buffer pointed
0271  *              to by the RetBuffer variable parameter.
0272  *
0273  *              If the function fails an appropriate status will be returned
0274  *              and the value of RetBuffer is undefined.
0275  *
0276  *              This function attempts to execute the _PRT method contained in
0277  *              the object indicated by the passed DeviceHandle.
0278  *
0279  ******************************************************************************/
0280 
0281 ACPI_STATUS
0282 AcpiGetIrqRoutingTable  (
0283     ACPI_HANDLE             DeviceHandle,
0284     ACPI_BUFFER             *RetBuffer)
0285 {
0286     ACPI_STATUS             Status;
0287     ACPI_NAMESPACE_NODE     *Node;
0288 
0289 
0290     ACPI_FUNCTION_TRACE (AcpiGetIrqRoutingTable);
0291 
0292 
0293     /* Validate parameters then dispatch to internal routine */
0294 
0295     Status = AcpiRsValidateParameters (DeviceHandle, RetBuffer, &Node);
0296     if (ACPI_FAILURE (Status))
0297     {
0298         return_ACPI_STATUS (Status);
0299     }
0300 
0301     Status = AcpiRsGetPrtMethodData (Node, RetBuffer);
0302     return_ACPI_STATUS (Status);
0303 }
0304 
0305 ACPI_EXPORT_SYMBOL (AcpiGetIrqRoutingTable)
0306 
0307 
0308 /*******************************************************************************
0309  *
0310  * FUNCTION:    AcpiGetCurrentResources
0311  *
0312  * PARAMETERS:  DeviceHandle    - Handle to the device object for the
0313  *                                device we are querying
0314  *              RetBuffer       - Pointer to a buffer to receive the
0315  *                                current resources for the device
0316  *
0317  * RETURN:      Status
0318  *
0319  * DESCRIPTION: This function is called to get the current resources for a
0320  *              specific device. The caller must first acquire a handle for
0321  *              the desired device. The resource data is placed in the buffer
0322  *              pointed to by the RetBuffer variable parameter.
0323  *
0324  *              If the function fails an appropriate status will be returned
0325  *              and the value of RetBuffer is undefined.
0326  *
0327  *              This function attempts to execute the _CRS method contained in
0328  *              the object indicated by the passed DeviceHandle.
0329  *
0330  ******************************************************************************/
0331 
0332 ACPI_STATUS
0333 AcpiGetCurrentResources (
0334     ACPI_HANDLE             DeviceHandle,
0335     ACPI_BUFFER             *RetBuffer)
0336 {
0337     ACPI_STATUS             Status;
0338     ACPI_NAMESPACE_NODE     *Node;
0339 
0340 
0341     ACPI_FUNCTION_TRACE (AcpiGetCurrentResources);
0342 
0343 
0344     /* Validate parameters then dispatch to internal routine */
0345 
0346     Status = AcpiRsValidateParameters (DeviceHandle, RetBuffer, &Node);
0347     if (ACPI_FAILURE (Status))
0348     {
0349         return_ACPI_STATUS (Status);
0350     }
0351 
0352     Status = AcpiRsGetCrsMethodData (Node, RetBuffer);
0353     return_ACPI_STATUS (Status);
0354 }
0355 
0356 ACPI_EXPORT_SYMBOL (AcpiGetCurrentResources)
0357 
0358 
0359 /*******************************************************************************
0360  *
0361  * FUNCTION:    AcpiGetPossibleResources
0362  *
0363  * PARAMETERS:  DeviceHandle    - Handle to the device object for the
0364  *                                device we are querying
0365  *              RetBuffer       - Pointer to a buffer to receive the
0366  *                                resources for the device
0367  *
0368  * RETURN:      Status
0369  *
0370  * DESCRIPTION: This function is called to get a list of the possible resources
0371  *              for a specific device. The caller must first acquire a handle
0372  *              for the desired device. The resource data is placed in the
0373  *              buffer pointed to by the RetBuffer variable.
0374  *
0375  *              If the function fails an appropriate status will be returned
0376  *              and the value of RetBuffer is undefined.
0377  *
0378  ******************************************************************************/
0379 
0380 ACPI_STATUS
0381 AcpiGetPossibleResources (
0382     ACPI_HANDLE             DeviceHandle,
0383     ACPI_BUFFER             *RetBuffer)
0384 {
0385     ACPI_STATUS             Status;
0386     ACPI_NAMESPACE_NODE     *Node;
0387 
0388 
0389     ACPI_FUNCTION_TRACE (AcpiGetPossibleResources);
0390 
0391 
0392     /* Validate parameters then dispatch to internal routine */
0393 
0394     Status = AcpiRsValidateParameters (DeviceHandle, RetBuffer, &Node);
0395     if (ACPI_FAILURE (Status))
0396     {
0397         return_ACPI_STATUS (Status);
0398     }
0399 
0400     Status = AcpiRsGetPrsMethodData (Node, RetBuffer);
0401     return_ACPI_STATUS (Status);
0402 }
0403 
0404 ACPI_EXPORT_SYMBOL (AcpiGetPossibleResources)
0405 
0406 
0407 /*******************************************************************************
0408  *
0409  * FUNCTION:    AcpiSetCurrentResources
0410  *
0411  * PARAMETERS:  DeviceHandle    - Handle to the device object for the
0412  *                                device we are setting resources
0413  *              InBuffer        - Pointer to a buffer containing the
0414  *                                resources to be set for the device
0415  *
0416  * RETURN:      Status
0417  *
0418  * DESCRIPTION: This function is called to set the current resources for a
0419  *              specific device. The caller must first acquire a handle for
0420  *              the desired device. The resource data is passed to the routine
0421  *              the buffer pointed to by the InBuffer variable.
0422  *
0423  ******************************************************************************/
0424 
0425 ACPI_STATUS
0426 AcpiSetCurrentResources (
0427     ACPI_HANDLE             DeviceHandle,
0428     ACPI_BUFFER             *InBuffer)
0429 {
0430     ACPI_STATUS             Status;
0431     ACPI_NAMESPACE_NODE     *Node;
0432 
0433 
0434     ACPI_FUNCTION_TRACE (AcpiSetCurrentResources);
0435 
0436 
0437     /* Validate the buffer, don't allow zero length */
0438 
0439     if ((!InBuffer) ||
0440         (!InBuffer->Pointer) ||
0441         (!InBuffer->Length))
0442     {
0443         return_ACPI_STATUS (AE_BAD_PARAMETER);
0444     }
0445 
0446     /* Validate parameters then dispatch to internal routine */
0447 
0448     Status = AcpiRsValidateParameters (DeviceHandle, InBuffer, &Node);
0449     if (ACPI_FAILURE (Status))
0450     {
0451         return_ACPI_STATUS (Status);
0452     }
0453 
0454     Status = AcpiRsSetSrsMethodData (Node, InBuffer);
0455     return_ACPI_STATUS (Status);
0456 }
0457 
0458 ACPI_EXPORT_SYMBOL (AcpiSetCurrentResources)
0459 
0460 
0461 /*******************************************************************************
0462  *
0463  * FUNCTION:    AcpiGetEventResources
0464  *
0465  * PARAMETERS:  DeviceHandle    - Handle to the device object for the
0466  *                                device we are getting resources
0467  *              InBuffer        - Pointer to a buffer containing the
0468  *                                resources to be set for the device
0469  *
0470  * RETURN:      Status
0471  *
0472  * DESCRIPTION: This function is called to get the event resources for a
0473  *              specific device. The caller must first acquire a handle for
0474  *              the desired device. The resource data is passed to the routine
0475  *              the buffer pointed to by the InBuffer variable. Uses the
0476  *              _AEI method.
0477  *
0478  ******************************************************************************/
0479 
0480 ACPI_STATUS
0481 AcpiGetEventResources (
0482     ACPI_HANDLE             DeviceHandle,
0483     ACPI_BUFFER             *RetBuffer)
0484 {
0485     ACPI_STATUS             Status;
0486     ACPI_NAMESPACE_NODE     *Node;
0487 
0488 
0489     ACPI_FUNCTION_TRACE (AcpiGetEventResources);
0490 
0491 
0492     /* Validate parameters then dispatch to internal routine */
0493 
0494     Status = AcpiRsValidateParameters (DeviceHandle, RetBuffer, &Node);
0495     if (ACPI_FAILURE (Status))
0496     {
0497         return_ACPI_STATUS (Status);
0498     }
0499 
0500     Status = AcpiRsGetAeiMethodData (Node, RetBuffer);
0501     return_ACPI_STATUS (Status);
0502 }
0503 
0504 ACPI_EXPORT_SYMBOL (AcpiGetEventResources)
0505 
0506 
0507 /******************************************************************************
0508  *
0509  * FUNCTION:    AcpiResourceToAddress64
0510  *
0511  * PARAMETERS:  Resource        - Pointer to a resource
0512  *              Out             - Pointer to the users's return buffer
0513  *                                (a struct acpi_resource_address64)
0514  *
0515  * RETURN:      Status
0516  *
0517  * DESCRIPTION: If the resource is an address16, address32, or address64,
0518  *              copy it to the address64 return buffer. This saves the
0519  *              caller from having to duplicate code for different-sized
0520  *              addresses.
0521  *
0522  ******************************************************************************/
0523 
0524 ACPI_STATUS
0525 AcpiResourceToAddress64 (
0526     ACPI_RESOURCE               *Resource,
0527     ACPI_RESOURCE_ADDRESS64     *Out)
0528 {
0529     ACPI_RESOURCE_ADDRESS16     *Address16;
0530     ACPI_RESOURCE_ADDRESS32     *Address32;
0531 
0532 
0533     if (!Resource || !Out)
0534     {
0535         return (AE_BAD_PARAMETER);
0536     }
0537 
0538     /* Convert 16 or 32 address descriptor to 64 */
0539 
0540     switch (Resource->Type)
0541     {
0542     case ACPI_RESOURCE_TYPE_ADDRESS16:
0543 
0544         Address16 = ACPI_CAST_PTR (
0545             ACPI_RESOURCE_ADDRESS16, &Resource->Data);
0546         ACPI_COPY_ADDRESS (Out, Address16);
0547         break;
0548 
0549     case ACPI_RESOURCE_TYPE_ADDRESS32:
0550 
0551         Address32 = ACPI_CAST_PTR (
0552             ACPI_RESOURCE_ADDRESS32, &Resource->Data);
0553         ACPI_COPY_ADDRESS (Out, Address32);
0554         break;
0555 
0556     case ACPI_RESOURCE_TYPE_ADDRESS64:
0557 
0558         /* Simple copy for 64 bit source */
0559 
0560         memcpy (Out, &Resource->Data, sizeof (ACPI_RESOURCE_ADDRESS64));
0561         break;
0562 
0563     default:
0564 
0565         return (AE_BAD_PARAMETER);
0566     }
0567 
0568     return (AE_OK);
0569 }
0570 
0571 ACPI_EXPORT_SYMBOL (AcpiResourceToAddress64)
0572 
0573 
0574 /*******************************************************************************
0575  *
0576  * FUNCTION:    AcpiGetVendorResource
0577  *
0578  * PARAMETERS:  DeviceHandle    - Handle for the parent device object
0579  *              Name            - Method name for the parent resource
0580  *                                (METHOD_NAME__CRS or METHOD_NAME__PRS)
0581  *              Uuid            - Pointer to the UUID to be matched.
0582  *                                includes both subtype and 16-byte UUID
0583  *              RetBuffer       - Where the vendor resource is returned
0584  *
0585  * RETURN:      Status
0586  *
0587  * DESCRIPTION: Walk a resource template for the specified device to find a
0588  *              vendor-defined resource that matches the supplied UUID and
0589  *              UUID subtype. Returns a ACPI_RESOURCE of type Vendor.
0590  *
0591  ******************************************************************************/
0592 
0593 ACPI_STATUS
0594 AcpiGetVendorResource (
0595     ACPI_HANDLE             DeviceHandle,
0596     char                    *Name,
0597     ACPI_VENDOR_UUID        *Uuid,
0598     ACPI_BUFFER             *RetBuffer)
0599 {
0600     ACPI_VENDOR_WALK_INFO   Info;
0601     ACPI_STATUS             Status;
0602 
0603 
0604     /* Other parameters are validated by AcpiWalkResources */
0605 
0606     if (!Uuid || !RetBuffer)
0607     {
0608         return (AE_BAD_PARAMETER);
0609     }
0610 
0611     Info.Uuid = Uuid;
0612     Info.Buffer = RetBuffer;
0613     Info.Status = AE_NOT_EXIST;
0614 
0615     /* Walk the _CRS or _PRS resource list for this device */
0616 
0617     Status = AcpiWalkResources (
0618         DeviceHandle, Name, AcpiRsMatchVendorResource, &Info);
0619     if (ACPI_FAILURE (Status))
0620     {
0621         return (Status);
0622     }
0623 
0624     return (Info.Status);
0625 }
0626 
0627 ACPI_EXPORT_SYMBOL (AcpiGetVendorResource)
0628 
0629 
0630 /*******************************************************************************
0631  *
0632  * FUNCTION:    AcpiRsMatchVendorResource
0633  *
0634  * PARAMETERS:  ACPI_WALK_RESOURCE_CALLBACK
0635  *
0636  * RETURN:      Status
0637  *
0638  * DESCRIPTION: Match a vendor resource via the ACPI 3.0 UUID
0639  *
0640  ******************************************************************************/
0641 
0642 static ACPI_STATUS
0643 AcpiRsMatchVendorResource (
0644     ACPI_RESOURCE           *Resource,
0645     void                    *Context)
0646 {
0647     ACPI_VENDOR_WALK_INFO       *Info = Context;
0648     ACPI_RESOURCE_VENDOR_TYPED  *Vendor;
0649     ACPI_BUFFER                 *Buffer;
0650     ACPI_STATUS                 Status;
0651 
0652 
0653     /* Ignore all descriptors except Vendor */
0654 
0655     if (Resource->Type != ACPI_RESOURCE_TYPE_VENDOR)
0656     {
0657         return (AE_OK);
0658     }
0659 
0660     Vendor = &Resource->Data.VendorTyped;
0661 
0662     /*
0663      * For a valid match, these conditions must hold:
0664      *
0665      * 1) Length of descriptor data must be at least as long as a UUID struct
0666      * 2) The UUID subtypes must match
0667      * 3) The UUID data must match
0668      */
0669     if ((Vendor->ByteLength < (ACPI_UUID_LENGTH + 1)) ||
0670         (Vendor->UuidSubtype != Info->Uuid->Subtype)  ||
0671         (memcmp (Vendor->Uuid, Info->Uuid->Data, ACPI_UUID_LENGTH)))
0672     {
0673         return (AE_OK);
0674     }
0675 
0676     /* Validate/Allocate/Clear caller buffer */
0677 
0678     Buffer = Info->Buffer;
0679     Status = AcpiUtInitializeBuffer (Buffer, Resource->Length);
0680     if (ACPI_FAILURE (Status))
0681     {
0682         return (Status);
0683     }
0684 
0685     /* Found the correct resource, copy and return it */
0686 
0687     memcpy (Buffer->Pointer, Resource, Resource->Length);
0688     Buffer->Length = Resource->Length;
0689 
0690     /* Found the desired descriptor, terminate resource walk */
0691 
0692     Info->Status = AE_OK;
0693     return (AE_CTRL_TERMINATE);
0694 }
0695 
0696 
0697 /*******************************************************************************
0698  *
0699  * FUNCTION:    AcpiWalkResourceBuffer
0700  *
0701  * PARAMETERS:  Buffer          - Formatted buffer returned by one of the
0702  *                                various Get*Resource functions
0703  *              UserFunction    - Called for each resource
0704  *              Context         - Passed to UserFunction
0705  *
0706  * RETURN:      Status
0707  *
0708  * DESCRIPTION: Walks the input resource template. The UserFunction is called
0709  *              once for each resource in the list.
0710  *
0711  ******************************************************************************/
0712 
0713 ACPI_STATUS
0714 AcpiWalkResourceBuffer (
0715     ACPI_BUFFER                 *Buffer,
0716     ACPI_WALK_RESOURCE_CALLBACK UserFunction,
0717     void                        *Context)
0718 {
0719     ACPI_STATUS                 Status = AE_OK;
0720     ACPI_RESOURCE               *Resource;
0721     ACPI_RESOURCE               *ResourceEnd;
0722 
0723 
0724     ACPI_FUNCTION_TRACE (AcpiWalkResourceBuffer);
0725 
0726 
0727     /* Parameter validation */
0728 
0729     if (!Buffer || !Buffer->Pointer || !UserFunction)
0730     {
0731         return_ACPI_STATUS (AE_BAD_PARAMETER);
0732     }
0733 
0734     /* Buffer contains the resource list and length */
0735 
0736     Resource = ACPI_CAST_PTR (ACPI_RESOURCE, Buffer->Pointer);
0737     ResourceEnd = ACPI_ADD_PTR (
0738         ACPI_RESOURCE, Buffer->Pointer, Buffer->Length);
0739 
0740     /* Walk the resource list until the EndTag is found (or buffer end) */
0741 
0742     while (Resource < ResourceEnd)
0743     {
0744         /* Sanity check the resource type */
0745 
0746         if (Resource->Type > ACPI_RESOURCE_TYPE_MAX)
0747         {
0748             Status = AE_AML_INVALID_RESOURCE_TYPE;
0749             break;
0750         }
0751 
0752         /* Sanity check the length. It must not be zero, or we loop forever */
0753 
0754         if (!Resource->Length)
0755         {
0756             return_ACPI_STATUS (AE_AML_BAD_RESOURCE_LENGTH);
0757         }
0758 
0759         /* Invoke the user function, abort on any error returned */
0760 
0761         Status = UserFunction (Resource, Context);
0762         if (ACPI_FAILURE (Status))
0763         {
0764             if (Status == AE_CTRL_TERMINATE)
0765             {
0766                 /* This is an OK termination by the user function */
0767 
0768                 Status = AE_OK;
0769             }
0770             break;
0771         }
0772 
0773         /* EndTag indicates end-of-list */
0774 
0775         if (Resource->Type == ACPI_RESOURCE_TYPE_END_TAG)
0776         {
0777             break;
0778         }
0779 
0780         /* Get the next resource descriptor */
0781 
0782         Resource = ACPI_NEXT_RESOURCE (Resource);
0783     }
0784 
0785     return_ACPI_STATUS (Status);
0786 }
0787 
0788 ACPI_EXPORT_SYMBOL (AcpiWalkResourceBuffer)
0789 
0790 
0791 /*******************************************************************************
0792  *
0793  * FUNCTION:    AcpiWalkResources
0794  *
0795  * PARAMETERS:  DeviceHandle    - Handle to the device object for the
0796  *                                device we are querying
0797  *              Name            - Method name of the resources we want.
0798  *                                (METHOD_NAME__CRS, METHOD_NAME__PRS, or
0799  *                                METHOD_NAME__AEI or METHOD_NAME__DMA)
0800  *              UserFunction    - Called for each resource
0801  *              Context         - Passed to UserFunction
0802  *
0803  * RETURN:      Status
0804  *
0805  * DESCRIPTION: Retrieves the current or possible resource list for the
0806  *              specified device. The UserFunction is called once for
0807  *              each resource in the list.
0808  *
0809  ******************************************************************************/
0810 
0811 ACPI_STATUS
0812 AcpiWalkResources (
0813     ACPI_HANDLE                 DeviceHandle,
0814     char                        *Name,
0815     ACPI_WALK_RESOURCE_CALLBACK UserFunction,
0816     void                        *Context)
0817 {
0818     ACPI_STATUS                 Status;
0819     ACPI_BUFFER                 Buffer;
0820 
0821 
0822     ACPI_FUNCTION_TRACE (AcpiWalkResources);
0823 
0824 
0825     /* Parameter validation */
0826 
0827     if (!DeviceHandle || !UserFunction || !Name ||
0828         (!ACPI_COMPARE_NAMESEG (Name, METHOD_NAME__CRS) &&
0829          !ACPI_COMPARE_NAMESEG (Name, METHOD_NAME__PRS) &&
0830          !ACPI_COMPARE_NAMESEG (Name, METHOD_NAME__AEI) &&
0831          !ACPI_COMPARE_NAMESEG (Name, METHOD_NAME__DMA)))
0832     {
0833         return_ACPI_STATUS (AE_BAD_PARAMETER);
0834     }
0835 
0836     /* Get the _CRS/_PRS/_AEI/_DMA resource list */
0837 
0838     Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
0839     Status = AcpiRsGetMethodData (DeviceHandle, Name, &Buffer);
0840     if (ACPI_FAILURE (Status))
0841     {
0842         return_ACPI_STATUS (Status);
0843     }
0844 
0845     /* Walk the resource list and cleanup */
0846 
0847     Status = AcpiWalkResourceBuffer (&Buffer, UserFunction, Context);
0848     ACPI_FREE (Buffer.Pointer);
0849     return_ACPI_STATUS (Status);
0850 }
0851 
0852 ACPI_EXPORT_SYMBOL (AcpiWalkResources)