Path: blob/main/sys/contrib/dev/acpica/components/resources/rsxface.c
48406 views
/*******************************************************************************1*2* Module Name: rsxface - Public interfaces to the resource manager3*4******************************************************************************/56/******************************************************************************7*8* 1. Copyright Notice9*10* Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.11* All rights reserved.12*13* 2. License14*15* 2.1. This is your license from Intel Corp. under its intellectual property16* rights. You may have additional license terms from the party that provided17* you this software, covering your right to use that party's intellectual18* property rights.19*20* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a21* copy of the source code appearing in this file ("Covered Code") an22* irrevocable, perpetual, worldwide license under Intel's copyrights in the23* base code distributed originally by Intel ("Original Intel Code") to copy,24* make derivatives, distribute, use and display any portion of the Covered25* Code in any form, with the right to sublicense such rights; and26*27* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent28* license (with the right to sublicense), under only those claims of Intel29* patents that are infringed by the Original Intel Code, to make, use, sell,30* offer to sell, and import the Covered Code and derivative works thereof31* solely to the minimum extent necessary to exercise the above copyright32* license, and in no event shall the patent license extend to any additions33* to or modifications of the Original Intel Code. No other license or right34* is granted directly or by implication, estoppel or otherwise;35*36* The above copyright and patent license is granted only if the following37* conditions are met:38*39* 3. Conditions40*41* 3.1. Redistribution of Source with Rights to Further Distribute Source.42* Redistribution of source code of any substantial portion of the Covered43* Code or modification with rights to further distribute source must include44* the above Copyright Notice, the above License, this list of Conditions,45* and the following Disclaimer and Export Compliance provision. In addition,46* Licensee must cause all Covered Code to which Licensee contributes to47* contain a file documenting the changes Licensee made to create that Covered48* Code and the date of any change. Licensee must include in that file the49* documentation of any changes made by any predecessor Licensee. Licensee50* must include a prominent statement that the modification is derived,51* directly or indirectly, from Original Intel Code.52*53* 3.2. Redistribution of Source with no Rights to Further Distribute Source.54* Redistribution of source code of any substantial portion of the Covered55* Code or modification without rights to further distribute source must56* include the following Disclaimer and Export Compliance provision in the57* documentation and/or other materials provided with distribution. In58* addition, Licensee may not authorize further sublicense of source of any59* portion of the Covered Code, and must include terms to the effect that the60* license from Licensee to its licensee is limited to the intellectual61* property embodied in the software Licensee provides to its licensee, and62* not to intellectual property embodied in modifications its licensee may63* make.64*65* 3.3. Redistribution of Executable. Redistribution in executable form of any66* substantial portion of the Covered Code or modification must reproduce the67* above Copyright Notice, and the following Disclaimer and Export Compliance68* provision in the documentation and/or other materials provided with the69* distribution.70*71* 3.4. Intel retains all right, title, and interest in and to the Original72* Intel Code.73*74* 3.5. Neither the name Intel nor any other trademark owned or controlled by75* Intel shall be used in advertising or otherwise to promote the sale, use or76* other dealings in products derived from or relating to the Covered Code77* without prior written authorization from Intel.78*79* 4. Disclaimer and Export Compliance80*81* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED82* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE83* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,84* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY85* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY86* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A87* PARTICULAR PURPOSE.88*89* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES90* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR91* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,92* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY93* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL94* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS95* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY96* LIMITED REMEDY.97*98* 4.3. Licensee shall not export, either directly or indirectly, any of this99* software or system incorporating such software without first obtaining any100* required license or other approval from the U. S. Department of Commerce or101* any other agency or department of the United States Government. In the102* event Licensee exports any such software from the United States or103* re-exports any such software from a foreign destination, Licensee shall104* ensure that the distribution and export/re-export of the software is in105* compliance with all laws, regulations, orders, or other restrictions of the106* U.S. Export Administration Regulations. Licensee agrees that neither it nor107* any of its subsidiaries will export/re-export any technical data, process,108* software, or service, directly or indirectly, to any country for which the109* United States government or any agency thereof requires an export license,110* other governmental approval, or letter of assurance, without first obtaining111* such license, approval or letter.112*113*****************************************************************************114*115* Alternatively, you may choose to be licensed under the terms of the116* following license:117*118* Redistribution and use in source and binary forms, with or without119* modification, are permitted provided that the following conditions120* are met:121* 1. Redistributions of source code must retain the above copyright122* notice, this list of conditions, and the following disclaimer,123* without modification.124* 2. Redistributions in binary form must reproduce at minimum a disclaimer125* substantially similar to the "NO WARRANTY" disclaimer below126* ("Disclaimer") and any redistribution must be conditioned upon127* including a substantially similar Disclaimer requirement for further128* binary redistribution.129* 3. Neither the names of the above-listed copyright holders nor the names130* of any contributors may be used to endorse or promote products derived131* from this software without specific prior written permission.132*133* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS134* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT135* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR136* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT137* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,138* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT139* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,140* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY141* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT142* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE143* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.144*145* Alternatively, you may choose to be licensed under the terms of the146* GNU General Public License ("GPL") version 2 as published by the Free147* Software Foundation.148*149*****************************************************************************/150151#define EXPORT_ACPI_INTERFACES152153#include <contrib/dev/acpica/include/acpi.h>154#include <contrib/dev/acpica/include/accommon.h>155#include <contrib/dev/acpica/include/acresrc.h>156#include <contrib/dev/acpica/include/acnamesp.h>157158#define _COMPONENT ACPI_RESOURCES159ACPI_MODULE_NAME ("rsxface")160161/* Local macros for 16,32-bit to 64-bit conversion */162163#define ACPI_COPY_FIELD(Out, In, Field) ((Out)->Field = (In)->Field)164#define ACPI_COPY_ADDRESS(Out, In) \165ACPI_COPY_FIELD(Out, In, ResourceType); \166ACPI_COPY_FIELD(Out, In, ProducerConsumer); \167ACPI_COPY_FIELD(Out, In, Decode); \168ACPI_COPY_FIELD(Out, In, MinAddressFixed); \169ACPI_COPY_FIELD(Out, In, MaxAddressFixed); \170ACPI_COPY_FIELD(Out, In, Info); \171ACPI_COPY_FIELD(Out, In, Address.Granularity); \172ACPI_COPY_FIELD(Out, In, Address.Minimum); \173ACPI_COPY_FIELD(Out, In, Address.Maximum); \174ACPI_COPY_FIELD(Out, In, Address.TranslationOffset); \175ACPI_COPY_FIELD(Out, In, Address.AddressLength); \176ACPI_COPY_FIELD(Out, In, ResourceSource);177178179/* Local prototypes */180181static ACPI_STATUS182AcpiRsMatchVendorResource (183ACPI_RESOURCE *Resource,184void *Context);185186static ACPI_STATUS187AcpiRsValidateParameters (188ACPI_HANDLE DeviceHandle,189ACPI_BUFFER *Buffer,190ACPI_NAMESPACE_NODE **ReturnNode);191192193/*******************************************************************************194*195* FUNCTION: AcpiRsValidateParameters196*197* PARAMETERS: DeviceHandle - Handle to a device198* Buffer - Pointer to a data buffer199* ReturnNode - Pointer to where the device node is returned200*201* RETURN: Status202*203* DESCRIPTION: Common parameter validation for resource interfaces204*205******************************************************************************/206207static ACPI_STATUS208AcpiRsValidateParameters (209ACPI_HANDLE DeviceHandle,210ACPI_BUFFER *Buffer,211ACPI_NAMESPACE_NODE **ReturnNode)212{213ACPI_STATUS Status;214ACPI_NAMESPACE_NODE *Node;215216217ACPI_FUNCTION_TRACE (RsValidateParameters);218219220/*221* Must have a valid handle to an ACPI device222*/223if (!DeviceHandle)224{225return_ACPI_STATUS (AE_BAD_PARAMETER);226}227228Node = AcpiNsValidateHandle (DeviceHandle);229if (!Node)230{231return_ACPI_STATUS (AE_BAD_PARAMETER);232}233234if (Node->Type != ACPI_TYPE_DEVICE)235{236return_ACPI_STATUS (AE_TYPE);237}238239/*240* Validate the user buffer object241*242* if there is a non-zero buffer length we also need a valid pointer in243* the buffer. If it's a zero buffer length, we'll be returning the244* needed buffer size (later), so keep going.245*/246Status = AcpiUtValidateBuffer (Buffer);247if (ACPI_FAILURE (Status))248{249return_ACPI_STATUS (Status);250}251252*ReturnNode = Node;253return_ACPI_STATUS (AE_OK);254}255256257/*******************************************************************************258*259* FUNCTION: AcpiGetIrqRoutingTable260*261* PARAMETERS: DeviceHandle - Handle to the Bus device we are querying262* RetBuffer - Pointer to a buffer to receive the263* current resources for the device264*265* RETURN: Status266*267* DESCRIPTION: This function is called to get the IRQ routing table for a268* specific bus. The caller must first acquire a handle for the269* desired bus. The routine table is placed in the buffer pointed270* to by the RetBuffer variable parameter.271*272* If the function fails an appropriate status will be returned273* and the value of RetBuffer is undefined.274*275* This function attempts to execute the _PRT method contained in276* the object indicated by the passed DeviceHandle.277*278******************************************************************************/279280ACPI_STATUS281AcpiGetIrqRoutingTable (282ACPI_HANDLE DeviceHandle,283ACPI_BUFFER *RetBuffer)284{285ACPI_STATUS Status;286ACPI_NAMESPACE_NODE *Node;287288289ACPI_FUNCTION_TRACE (AcpiGetIrqRoutingTable);290291292/* Validate parameters then dispatch to internal routine */293294Status = AcpiRsValidateParameters (DeviceHandle, RetBuffer, &Node);295if (ACPI_FAILURE (Status))296{297return_ACPI_STATUS (Status);298}299300Status = AcpiRsGetPrtMethodData (Node, RetBuffer);301return_ACPI_STATUS (Status);302}303304ACPI_EXPORT_SYMBOL (AcpiGetIrqRoutingTable)305306307/*******************************************************************************308*309* FUNCTION: AcpiGetCurrentResources310*311* PARAMETERS: DeviceHandle - Handle to the device object for the312* device we are querying313* RetBuffer - Pointer to a buffer to receive the314* current resources for the device315*316* RETURN: Status317*318* DESCRIPTION: This function is called to get the current resources for a319* specific device. The caller must first acquire a handle for320* the desired device. The resource data is placed in the buffer321* pointed to by the RetBuffer variable parameter.322*323* If the function fails an appropriate status will be returned324* and the value of RetBuffer is undefined.325*326* This function attempts to execute the _CRS method contained in327* the object indicated by the passed DeviceHandle.328*329******************************************************************************/330331ACPI_STATUS332AcpiGetCurrentResources (333ACPI_HANDLE DeviceHandle,334ACPI_BUFFER *RetBuffer)335{336ACPI_STATUS Status;337ACPI_NAMESPACE_NODE *Node;338339340ACPI_FUNCTION_TRACE (AcpiGetCurrentResources);341342343/* Validate parameters then dispatch to internal routine */344345Status = AcpiRsValidateParameters (DeviceHandle, RetBuffer, &Node);346if (ACPI_FAILURE (Status))347{348return_ACPI_STATUS (Status);349}350351Status = AcpiRsGetCrsMethodData (Node, RetBuffer);352return_ACPI_STATUS (Status);353}354355ACPI_EXPORT_SYMBOL (AcpiGetCurrentResources)356357358/*******************************************************************************359*360* FUNCTION: AcpiGetPossibleResources361*362* PARAMETERS: DeviceHandle - Handle to the device object for the363* device we are querying364* RetBuffer - Pointer to a buffer to receive the365* resources for the device366*367* RETURN: Status368*369* DESCRIPTION: This function is called to get a list of the possible resources370* for a specific device. The caller must first acquire a handle371* for the desired device. The resource data is placed in the372* buffer pointed to by the RetBuffer variable.373*374* If the function fails an appropriate status will be returned375* and the value of RetBuffer is undefined.376*377******************************************************************************/378379ACPI_STATUS380AcpiGetPossibleResources (381ACPI_HANDLE DeviceHandle,382ACPI_BUFFER *RetBuffer)383{384ACPI_STATUS Status;385ACPI_NAMESPACE_NODE *Node;386387388ACPI_FUNCTION_TRACE (AcpiGetPossibleResources);389390391/* Validate parameters then dispatch to internal routine */392393Status = AcpiRsValidateParameters (DeviceHandle, RetBuffer, &Node);394if (ACPI_FAILURE (Status))395{396return_ACPI_STATUS (Status);397}398399Status = AcpiRsGetPrsMethodData (Node, RetBuffer);400return_ACPI_STATUS (Status);401}402403ACPI_EXPORT_SYMBOL (AcpiGetPossibleResources)404405406/*******************************************************************************407*408* FUNCTION: AcpiSetCurrentResources409*410* PARAMETERS: DeviceHandle - Handle to the device object for the411* device we are setting resources412* InBuffer - Pointer to a buffer containing the413* resources to be set for the device414*415* RETURN: Status416*417* DESCRIPTION: This function is called to set the current resources for a418* specific device. The caller must first acquire a handle for419* the desired device. The resource data is passed to the routine420* the buffer pointed to by the InBuffer variable.421*422******************************************************************************/423424ACPI_STATUS425AcpiSetCurrentResources (426ACPI_HANDLE DeviceHandle,427ACPI_BUFFER *InBuffer)428{429ACPI_STATUS Status;430ACPI_NAMESPACE_NODE *Node;431432433ACPI_FUNCTION_TRACE (AcpiSetCurrentResources);434435436/* Validate the buffer, don't allow zero length */437438if ((!InBuffer) ||439(!InBuffer->Pointer) ||440(!InBuffer->Length))441{442return_ACPI_STATUS (AE_BAD_PARAMETER);443}444445/* Validate parameters then dispatch to internal routine */446447Status = AcpiRsValidateParameters (DeviceHandle, InBuffer, &Node);448if (ACPI_FAILURE (Status))449{450return_ACPI_STATUS (Status);451}452453Status = AcpiRsSetSrsMethodData (Node, InBuffer);454return_ACPI_STATUS (Status);455}456457ACPI_EXPORT_SYMBOL (AcpiSetCurrentResources)458459460/*******************************************************************************461*462* FUNCTION: AcpiGetEventResources463*464* PARAMETERS: DeviceHandle - Handle to the device object for the465* device we are getting resources466* InBuffer - Pointer to a buffer containing the467* resources to be set for the device468*469* RETURN: Status470*471* DESCRIPTION: This function is called to get the event resources for a472* specific device. The caller must first acquire a handle for473* the desired device. The resource data is passed to the routine474* the buffer pointed to by the InBuffer variable. Uses the475* _AEI method.476*477******************************************************************************/478479ACPI_STATUS480AcpiGetEventResources (481ACPI_HANDLE DeviceHandle,482ACPI_BUFFER *RetBuffer)483{484ACPI_STATUS Status;485ACPI_NAMESPACE_NODE *Node;486487488ACPI_FUNCTION_TRACE (AcpiGetEventResources);489490491/* Validate parameters then dispatch to internal routine */492493Status = AcpiRsValidateParameters (DeviceHandle, RetBuffer, &Node);494if (ACPI_FAILURE (Status))495{496return_ACPI_STATUS (Status);497}498499Status = AcpiRsGetAeiMethodData (Node, RetBuffer);500return_ACPI_STATUS (Status);501}502503ACPI_EXPORT_SYMBOL (AcpiGetEventResources)504505506/******************************************************************************507*508* FUNCTION: AcpiResourceToAddress64509*510* PARAMETERS: Resource - Pointer to a resource511* Out - Pointer to the users's return buffer512* (a struct acpi_resource_address64)513*514* RETURN: Status515*516* DESCRIPTION: If the resource is an address16, address32, or address64,517* copy it to the address64 return buffer. This saves the518* caller from having to duplicate code for different-sized519* addresses.520*521******************************************************************************/522523ACPI_STATUS524AcpiResourceToAddress64 (525ACPI_RESOURCE *Resource,526ACPI_RESOURCE_ADDRESS64 *Out)527{528ACPI_RESOURCE_ADDRESS16 *Address16;529ACPI_RESOURCE_ADDRESS32 *Address32;530531532if (!Resource || !Out)533{534return (AE_BAD_PARAMETER);535}536537/* Convert 16 or 32 address descriptor to 64 */538539switch (Resource->Type)540{541case ACPI_RESOURCE_TYPE_ADDRESS16:542543Address16 = ACPI_CAST_PTR (544ACPI_RESOURCE_ADDRESS16, &Resource->Data);545ACPI_COPY_ADDRESS (Out, Address16);546break;547548case ACPI_RESOURCE_TYPE_ADDRESS32:549550Address32 = ACPI_CAST_PTR (551ACPI_RESOURCE_ADDRESS32, &Resource->Data);552ACPI_COPY_ADDRESS (Out, Address32);553break;554555case ACPI_RESOURCE_TYPE_ADDRESS64:556557/* Simple copy for 64 bit source */558559memcpy (Out, &Resource->Data, sizeof (ACPI_RESOURCE_ADDRESS64));560break;561562default:563564return (AE_BAD_PARAMETER);565}566567return (AE_OK);568}569570ACPI_EXPORT_SYMBOL (AcpiResourceToAddress64)571572573/*******************************************************************************574*575* FUNCTION: AcpiGetVendorResource576*577* PARAMETERS: DeviceHandle - Handle for the parent device object578* Name - Method name for the parent resource579* (METHOD_NAME__CRS or METHOD_NAME__PRS)580* Uuid - Pointer to the UUID to be matched.581* includes both subtype and 16-byte UUID582* RetBuffer - Where the vendor resource is returned583*584* RETURN: Status585*586* DESCRIPTION: Walk a resource template for the specified device to find a587* vendor-defined resource that matches the supplied UUID and588* UUID subtype. Returns a ACPI_RESOURCE of type Vendor.589*590******************************************************************************/591592ACPI_STATUS593AcpiGetVendorResource (594ACPI_HANDLE DeviceHandle,595char *Name,596ACPI_VENDOR_UUID *Uuid,597ACPI_BUFFER *RetBuffer)598{599ACPI_VENDOR_WALK_INFO Info;600ACPI_STATUS Status;601602603/* Other parameters are validated by AcpiWalkResources */604605if (!Uuid || !RetBuffer)606{607return (AE_BAD_PARAMETER);608}609610Info.Uuid = Uuid;611Info.Buffer = RetBuffer;612Info.Status = AE_NOT_EXIST;613614/* Walk the _CRS or _PRS resource list for this device */615616Status = AcpiWalkResources (617DeviceHandle, Name, AcpiRsMatchVendorResource, &Info);618if (ACPI_FAILURE (Status))619{620return (Status);621}622623return (Info.Status);624}625626ACPI_EXPORT_SYMBOL (AcpiGetVendorResource)627628629/*******************************************************************************630*631* FUNCTION: AcpiRsMatchVendorResource632*633* PARAMETERS: ACPI_WALK_RESOURCE_CALLBACK634*635* RETURN: Status636*637* DESCRIPTION: Match a vendor resource via the ACPI 3.0 UUID638*639******************************************************************************/640641static ACPI_STATUS642AcpiRsMatchVendorResource (643ACPI_RESOURCE *Resource,644void *Context)645{646ACPI_VENDOR_WALK_INFO *Info = Context;647ACPI_RESOURCE_VENDOR_TYPED *Vendor;648ACPI_BUFFER *Buffer;649ACPI_STATUS Status;650651652/* Ignore all descriptors except Vendor */653654if (Resource->Type != ACPI_RESOURCE_TYPE_VENDOR)655{656return (AE_OK);657}658659Vendor = &Resource->Data.VendorTyped;660661/*662* For a valid match, these conditions must hold:663*664* 1) Length of descriptor data must be at least as long as a UUID struct665* 2) The UUID subtypes must match666* 3) The UUID data must match667*/668if ((Vendor->ByteLength < (ACPI_UUID_LENGTH + 1)) ||669(Vendor->UuidSubtype != Info->Uuid->Subtype) ||670(memcmp (Vendor->Uuid, Info->Uuid->Data, ACPI_UUID_LENGTH)))671{672return (AE_OK);673}674675/* Validate/Allocate/Clear caller buffer */676677Buffer = Info->Buffer;678Status = AcpiUtInitializeBuffer (Buffer, Resource->Length);679if (ACPI_FAILURE (Status))680{681return (Status);682}683684/* Found the correct resource, copy and return it */685686memcpy (Buffer->Pointer, Resource, Resource->Length);687Buffer->Length = Resource->Length;688689/* Found the desired descriptor, terminate resource walk */690691Info->Status = AE_OK;692return (AE_CTRL_TERMINATE);693}694695696/*******************************************************************************697*698* FUNCTION: AcpiWalkResourceBuffer699*700* PARAMETERS: Buffer - Formatted buffer returned by one of the701* various Get*Resource functions702* UserFunction - Called for each resource703* Context - Passed to UserFunction704*705* RETURN: Status706*707* DESCRIPTION: Walks the input resource template. The UserFunction is called708* once for each resource in the list.709*710******************************************************************************/711712ACPI_STATUS713AcpiWalkResourceBuffer (714ACPI_BUFFER *Buffer,715ACPI_WALK_RESOURCE_CALLBACK UserFunction,716void *Context)717{718ACPI_STATUS Status = AE_OK;719ACPI_RESOURCE *Resource;720ACPI_RESOURCE *ResourceEnd;721722723ACPI_FUNCTION_TRACE (AcpiWalkResourceBuffer);724725726/* Parameter validation */727728if (!Buffer || !Buffer->Pointer || !UserFunction)729{730return_ACPI_STATUS (AE_BAD_PARAMETER);731}732733/* Buffer contains the resource list and length */734735Resource = ACPI_CAST_PTR (ACPI_RESOURCE, Buffer->Pointer);736ResourceEnd = ACPI_ADD_PTR (737ACPI_RESOURCE, Buffer->Pointer, Buffer->Length);738739/* Walk the resource list until the EndTag is found (or buffer end) */740741while (Resource < ResourceEnd)742{743/* Sanity check the resource type */744745if (Resource->Type > ACPI_RESOURCE_TYPE_MAX)746{747Status = AE_AML_INVALID_RESOURCE_TYPE;748break;749}750751/* Sanity check the length. It must not be zero, or we loop forever */752753if (!Resource->Length)754{755return_ACPI_STATUS (AE_AML_BAD_RESOURCE_LENGTH);756}757758/* Invoke the user function, abort on any error returned */759760Status = UserFunction (Resource, Context);761if (ACPI_FAILURE (Status))762{763if (Status == AE_CTRL_TERMINATE)764{765/* This is an OK termination by the user function */766767Status = AE_OK;768}769break;770}771772/* EndTag indicates end-of-list */773774if (Resource->Type == ACPI_RESOURCE_TYPE_END_TAG)775{776break;777}778779/* Get the next resource descriptor */780781Resource = ACPI_NEXT_RESOURCE (Resource);782}783784return_ACPI_STATUS (Status);785}786787ACPI_EXPORT_SYMBOL (AcpiWalkResourceBuffer)788789790/*******************************************************************************791*792* FUNCTION: AcpiWalkResources793*794* PARAMETERS: DeviceHandle - Handle to the device object for the795* device we are querying796* Name - Method name of the resources we want.797* (METHOD_NAME__CRS, METHOD_NAME__PRS, or798* METHOD_NAME__AEI or METHOD_NAME__DMA)799* UserFunction - Called for each resource800* Context - Passed to UserFunction801*802* RETURN: Status803*804* DESCRIPTION: Retrieves the current or possible resource list for the805* specified device. The UserFunction is called once for806* each resource in the list.807*808******************************************************************************/809810ACPI_STATUS811AcpiWalkResources (812ACPI_HANDLE DeviceHandle,813char *Name,814ACPI_WALK_RESOURCE_CALLBACK UserFunction,815void *Context)816{817ACPI_STATUS Status;818ACPI_BUFFER Buffer;819820821ACPI_FUNCTION_TRACE (AcpiWalkResources);822823824/* Parameter validation */825826if (!DeviceHandle || !UserFunction || !Name ||827(!ACPI_COMPARE_NAMESEG (Name, METHOD_NAME__CRS) &&828!ACPI_COMPARE_NAMESEG (Name, METHOD_NAME__PRS) &&829!ACPI_COMPARE_NAMESEG (Name, METHOD_NAME__AEI) &&830!ACPI_COMPARE_NAMESEG (Name, METHOD_NAME__DMA)))831{832return_ACPI_STATUS (AE_BAD_PARAMETER);833}834835/* Get the _CRS/_PRS/_AEI/_DMA resource list */836837Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;838Status = AcpiRsGetMethodData (DeviceHandle, Name, &Buffer);839if (ACPI_FAILURE (Status))840{841return_ACPI_STATUS (Status);842}843844/* Walk the resource list and cleanup */845846Status = AcpiWalkResourceBuffer (&Buffer, UserFunction, Context);847ACPI_FREE (Buffer.Pointer);848return_ACPI_STATUS (Status);849}850851ACPI_EXPORT_SYMBOL (AcpiWalkResources)852853854