Path: blob/main/sys/contrib/dev/acpica/components/utilities/utresrc.c
48406 views
/*******************************************************************************1*2* Module Name: utresrc - Resource management utilities3*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#include <contrib/dev/acpica/include/acpi.h>152#include <contrib/dev/acpica/include/accommon.h>153#include <contrib/dev/acpica/include/acresrc.h>154155156#define _COMPONENT ACPI_UTILITIES157ACPI_MODULE_NAME ("utresrc")158159160/*161* Base sizes of the raw AML resource descriptors, indexed by resource type.162* Zero indicates a reserved (and therefore invalid) resource type.163*/164const UINT8 AcpiGbl_ResourceAmlSizes[] =165{166/* Small descriptors */1671680,1690,1700,1710,172ACPI_AML_SIZE_SMALL (AML_RESOURCE_IRQ),173ACPI_AML_SIZE_SMALL (AML_RESOURCE_DMA),174ACPI_AML_SIZE_SMALL (AML_RESOURCE_START_DEPENDENT),175ACPI_AML_SIZE_SMALL (AML_RESOURCE_END_DEPENDENT),176ACPI_AML_SIZE_SMALL (AML_RESOURCE_IO),177ACPI_AML_SIZE_SMALL (AML_RESOURCE_FIXED_IO),178ACPI_AML_SIZE_SMALL (AML_RESOURCE_FIXED_DMA),1790,1800,1810,182ACPI_AML_SIZE_SMALL (AML_RESOURCE_VENDOR_SMALL),183ACPI_AML_SIZE_SMALL (AML_RESOURCE_END_TAG),184185/* Large descriptors */1861870,188ACPI_AML_SIZE_LARGE (AML_RESOURCE_MEMORY24),189ACPI_AML_SIZE_LARGE (AML_RESOURCE_GENERIC_REGISTER),1900,191ACPI_AML_SIZE_LARGE (AML_RESOURCE_VENDOR_LARGE),192ACPI_AML_SIZE_LARGE (AML_RESOURCE_MEMORY32),193ACPI_AML_SIZE_LARGE (AML_RESOURCE_FIXED_MEMORY32),194ACPI_AML_SIZE_LARGE (AML_RESOURCE_ADDRESS32),195ACPI_AML_SIZE_LARGE (AML_RESOURCE_ADDRESS16),196ACPI_AML_SIZE_LARGE (AML_RESOURCE_EXTENDED_IRQ),197ACPI_AML_SIZE_LARGE (AML_RESOURCE_ADDRESS64),198ACPI_AML_SIZE_LARGE (AML_RESOURCE_EXTENDED_ADDRESS64),199ACPI_AML_SIZE_LARGE (AML_RESOURCE_GPIO),200ACPI_AML_SIZE_LARGE (AML_RESOURCE_PIN_FUNCTION),201ACPI_AML_SIZE_LARGE (AML_RESOURCE_COMMON_SERIALBUS),202ACPI_AML_SIZE_LARGE (AML_RESOURCE_PIN_CONFIG),203ACPI_AML_SIZE_LARGE (AML_RESOURCE_PIN_GROUP),204ACPI_AML_SIZE_LARGE (AML_RESOURCE_PIN_GROUP_FUNCTION),205ACPI_AML_SIZE_LARGE (AML_RESOURCE_PIN_GROUP_CONFIG),206ACPI_AML_SIZE_LARGE (AML_RESOURCE_CLOCK_INPUT),207208};209210const UINT8 AcpiGbl_ResourceAmlSerialBusSizes[] =211{2120,213ACPI_AML_SIZE_LARGE (AML_RESOURCE_I2C_SERIALBUS),214ACPI_AML_SIZE_LARGE (AML_RESOURCE_SPI_SERIALBUS),215ACPI_AML_SIZE_LARGE (AML_RESOURCE_UART_SERIALBUS),216ACPI_AML_SIZE_LARGE (AML_RESOURCE_CSI2_SERIALBUS),217};218219220/*221* Resource types, used to validate the resource length field.222* The length of fixed-length types must match exactly, variable223* lengths must meet the minimum required length, etc.224* Zero indicates a reserved (and therefore invalid) resource type.225*/226static const UINT8 AcpiGbl_ResourceTypes[] =227{228/* Small descriptors */2292300,2310,2320,2330,234ACPI_SMALL_VARIABLE_LENGTH, /* 04 IRQ */235ACPI_FIXED_LENGTH, /* 05 DMA */236ACPI_SMALL_VARIABLE_LENGTH, /* 06 StartDependentFunctions */237ACPI_FIXED_LENGTH, /* 07 EndDependentFunctions */238ACPI_FIXED_LENGTH, /* 08 IO */239ACPI_FIXED_LENGTH, /* 09 FixedIO */240ACPI_FIXED_LENGTH, /* 0A FixedDMA */2410,2420,2430,244ACPI_VARIABLE_LENGTH, /* 0E VendorShort */245ACPI_FIXED_LENGTH, /* 0F EndTag */246247/* Large descriptors */2482490,250ACPI_FIXED_LENGTH, /* 01 Memory24 */251ACPI_FIXED_LENGTH, /* 02 GenericRegister */2520,253ACPI_VARIABLE_LENGTH, /* 04 VendorLong */254ACPI_FIXED_LENGTH, /* 05 Memory32 */255ACPI_FIXED_LENGTH, /* 06 Memory32Fixed */256ACPI_VARIABLE_LENGTH, /* 07 Dword* address */257ACPI_VARIABLE_LENGTH, /* 08 Word* address */258ACPI_VARIABLE_LENGTH, /* 09 ExtendedIRQ */259ACPI_VARIABLE_LENGTH, /* 0A Qword* address */260ACPI_FIXED_LENGTH, /* 0B Extended* address */261ACPI_VARIABLE_LENGTH, /* 0C Gpio* */262ACPI_VARIABLE_LENGTH, /* 0D PinFunction */263ACPI_VARIABLE_LENGTH, /* 0E *SerialBus */264ACPI_VARIABLE_LENGTH, /* 0F PinConfig */265ACPI_VARIABLE_LENGTH, /* 10 PinGroup */266ACPI_VARIABLE_LENGTH, /* 11 PinGroupFunction */267ACPI_VARIABLE_LENGTH, /* 12 PinGroupConfig */268ACPI_VARIABLE_LENGTH, /* 13 ClockInput */269};270271272/*******************************************************************************273*274* FUNCTION: AcpiUtWalkAmlResources275*276* PARAMETERS: WalkState - Current walk info277* PARAMETERS: Aml - Pointer to the raw AML resource template278* AmlLength - Length of the entire template279* UserFunction - Called once for each descriptor found. If280* NULL, a pointer to the EndTag is returned281* Context - Passed to UserFunction282*283* RETURN: Status284*285* DESCRIPTION: Walk a raw AML resource list(buffer). User function called286* once for each resource found.287*288******************************************************************************/289290ACPI_STATUS291AcpiUtWalkAmlResources (292ACPI_WALK_STATE *WalkState,293UINT8 *Aml,294ACPI_SIZE AmlLength,295ACPI_WALK_AML_CALLBACK UserFunction,296void **Context)297{298ACPI_STATUS Status;299UINT8 *EndAml;300UINT8 ResourceIndex;301UINT32 Length;302UINT32 Offset = 0;303UINT8 EndTag[2] = {0x79, 0x00};304305306ACPI_FUNCTION_TRACE (UtWalkAmlResources);307308309/* The absolute minimum resource template is one EndTag descriptor */310311if (AmlLength < sizeof (AML_RESOURCE_END_TAG))312{313return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);314}315316/* Point to the end of the resource template buffer */317318EndAml = Aml + AmlLength;319320/* Walk the byte list, abort on any invalid descriptor type or length */321322while (Aml < EndAml)323{324/* Validate the Resource Type and Resource Length */325326Status = AcpiUtValidateResource (WalkState, Aml, &ResourceIndex);327if (ACPI_FAILURE (Status))328{329/*330* Exit on failure. Cannot continue because the descriptor331* length may be bogus also.332*/333return_ACPI_STATUS (Status);334}335336/* Get the length of this descriptor */337338Length = AcpiUtGetDescriptorLength (Aml);339340/* Invoke the user function */341342if (UserFunction)343{344Status = UserFunction (345Aml, Length, Offset, ResourceIndex, Context);346if (ACPI_FAILURE (Status))347{348return_ACPI_STATUS (Status);349}350}351352/* An EndTag descriptor terminates this resource template */353354if (AcpiUtGetResourceType (Aml) == ACPI_RESOURCE_NAME_END_TAG)355{356/*357* There must be at least one more byte in the buffer for358* the 2nd byte of the EndTag359*/360if ((Aml + 1) >= EndAml)361{362return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);363}364365/*366* Don't attempt to perform any validation on the 2nd byte.367* Although all known ASL compilers insert a zero for the 2nd368* byte, it can also be a checksum (as per the ACPI spec),369* and this is occasionally seen in the field. July 2017.370*/371372/* Return the pointer to the EndTag if requested */373374if (!UserFunction)375{376*Context = Aml;377}378379/* Normal exit */380381return_ACPI_STATUS (AE_OK);382}383384Aml += Length;385Offset += Length;386}387388/* Did not find an EndTag descriptor */389390if (UserFunction)391{392/* Insert an EndTag anyway. AcpiRsGetListLength always leaves room */393394(void) AcpiUtValidateResource (WalkState, EndTag, &ResourceIndex);395Status = UserFunction (EndTag, 2, Offset, ResourceIndex, Context);396if (ACPI_FAILURE (Status))397{398return_ACPI_STATUS (Status);399}400}401402return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);403}404405406/*******************************************************************************407*408* FUNCTION: AcpiUtValidateResource409*410* PARAMETERS: WalkState - Current walk info411* Aml - Pointer to the raw AML resource descriptor412* ReturnIndex - Where the resource index is returned. NULL413* if the index is not required.414*415* RETURN: Status, and optionally the Index into the global resource tables416*417* DESCRIPTION: Validate an AML resource descriptor by checking the Resource418* Type and Resource Length. Returns an index into the global419* resource information/dispatch tables for later use.420*421******************************************************************************/422423ACPI_STATUS424AcpiUtValidateResource (425ACPI_WALK_STATE *WalkState,426void *Aml,427UINT8 *ReturnIndex)428{429AML_RESOURCE *AmlResource;430UINT8 ResourceType;431UINT8 ResourceIndex;432ACPI_RS_LENGTH ResourceLength;433ACPI_RS_LENGTH MinimumResourceLength;434435436ACPI_FUNCTION_ENTRY ();437438439/*440* 1) Validate the ResourceType field (Byte 0)441*/442ResourceType = ACPI_GET8 (Aml);443444/*445* Byte 0 contains the descriptor name (Resource Type)446* Examine the large/small bit in the resource header447*/448if (ResourceType & ACPI_RESOURCE_NAME_LARGE)449{450/* Verify the large resource type (name) against the max */451452if (ResourceType > ACPI_RESOURCE_NAME_LARGE_MAX)453{454goto InvalidResource;455}456457/*458* Large Resource Type -- bits 6:0 contain the name459* Translate range 0x80-0x8B to index range 0x10-0x1B460*/461ResourceIndex = (UINT8) (ResourceType - 0x70);462}463else464{465/*466* Small Resource Type -- bits 6:3 contain the name467* Shift range to index range 0x00-0x0F468*/469ResourceIndex = (UINT8)470((ResourceType & ACPI_RESOURCE_NAME_SMALL_MASK) >> 3);471}472473/*474* Check validity of the resource type, via AcpiGbl_ResourceTypes.475* Zero indicates an invalid resource.476*/477if (!AcpiGbl_ResourceTypes[ResourceIndex])478{479goto InvalidResource;480}481482/*483* Validate the ResourceLength field. This ensures that the length484* is at least reasonable, and guarantees that it is non-zero.485*/486ResourceLength = AcpiUtGetResourceLength (Aml);487MinimumResourceLength = AcpiGbl_ResourceAmlSizes[ResourceIndex];488489/* Validate based upon the type of resource - fixed length or variable */490491switch (AcpiGbl_ResourceTypes[ResourceIndex])492{493case ACPI_FIXED_LENGTH:494495/* Fixed length resource, length must match exactly */496497if (ResourceLength != MinimumResourceLength)498{499goto BadResourceLength;500}501break;502503case ACPI_VARIABLE_LENGTH:504505/* Variable length resource, length must be at least the minimum */506507if (ResourceLength < MinimumResourceLength)508{509goto BadResourceLength;510}511break;512513case ACPI_SMALL_VARIABLE_LENGTH:514515/* Small variable length resource, length can be (Min) or (Min-1) */516517if ((ResourceLength > MinimumResourceLength) ||518(ResourceLength < (MinimumResourceLength - 1)))519{520goto BadResourceLength;521}522break;523524default:525526/* Shouldn't happen (because of validation earlier), but be sure */527528goto InvalidResource;529}530531AmlResource = ACPI_CAST_PTR (AML_RESOURCE, Aml);532if (ResourceType == ACPI_RESOURCE_NAME_SERIAL_BUS)533{534/* Validate the BusType field */535536if ((AmlResource->CommonSerialBus.Type == 0) ||537(AmlResource->CommonSerialBus.Type > AML_RESOURCE_MAX_SERIALBUSTYPE))538{539if (WalkState)540{541ACPI_ERROR ((AE_INFO,542"Invalid/unsupported SerialBus resource descriptor: BusType 0x%2.2X",543AmlResource->CommonSerialBus.Type));544}545return (AE_AML_INVALID_RESOURCE_TYPE);546}547}548549/* Optionally return the resource table index */550551if (ReturnIndex)552{553*ReturnIndex = ResourceIndex;554}555556return (AE_OK);557558559InvalidResource:560561if (WalkState)562{563ACPI_ERROR ((AE_INFO,564"Invalid/unsupported resource descriptor: Type 0x%2.2X",565ResourceType));566}567return (AE_AML_INVALID_RESOURCE_TYPE);568569BadResourceLength:570571if (WalkState)572{573ACPI_ERROR ((AE_INFO,574"Invalid resource descriptor length: Type "575"0x%2.2X, Length 0x%4.4X, MinLength 0x%4.4X",576ResourceType, ResourceLength, MinimumResourceLength));577}578return (AE_AML_BAD_RESOURCE_LENGTH);579}580581582/*******************************************************************************583*584* FUNCTION: AcpiUtGetResourceType585*586* PARAMETERS: Aml - Pointer to the raw AML resource descriptor587*588* RETURN: The Resource Type with no extraneous bits (except the589* Large/Small descriptor bit -- this is left alone)590*591* DESCRIPTION: Extract the Resource Type/Name from the first byte of592* a resource descriptor.593*594******************************************************************************/595596UINT8597AcpiUtGetResourceType (598void *Aml)599{600ACPI_FUNCTION_ENTRY ();601602603/*604* Byte 0 contains the descriptor name (Resource Type)605* Examine the large/small bit in the resource header606*/607if (ACPI_GET8 (Aml) & ACPI_RESOURCE_NAME_LARGE)608{609/* Large Resource Type -- bits 6:0 contain the name */610611return (ACPI_GET8 (Aml));612}613else614{615/* Small Resource Type -- bits 6:3 contain the name */616617return ((UINT8) (ACPI_GET8 (Aml) & ACPI_RESOURCE_NAME_SMALL_MASK));618}619}620621622/*******************************************************************************623*624* FUNCTION: AcpiUtGetResourceLength625*626* PARAMETERS: Aml - Pointer to the raw AML resource descriptor627*628* RETURN: Byte Length629*630* DESCRIPTION: Get the "Resource Length" of a raw AML descriptor. By631* definition, this does not include the size of the descriptor632* header or the length field itself.633*634******************************************************************************/635636UINT16637AcpiUtGetResourceLength (638void *Aml)639{640ACPI_RS_LENGTH ResourceLength;641642643ACPI_FUNCTION_ENTRY ();644645646/*647* Byte 0 contains the descriptor name (Resource Type)648* Examine the large/small bit in the resource header649*/650if (ACPI_GET8 (Aml) & ACPI_RESOURCE_NAME_LARGE)651{652/* Large Resource type -- bytes 1-2 contain the 16-bit length */653654ACPI_MOVE_16_TO_16 (&ResourceLength, ACPI_ADD_PTR (UINT8, Aml, 1));655656}657else658{659/* Small Resource type -- bits 2:0 of byte 0 contain the length */660661ResourceLength = (UINT16) (ACPI_GET8 (Aml) &662ACPI_RESOURCE_NAME_SMALL_LENGTH_MASK);663}664665return (ResourceLength);666}667668669/*******************************************************************************670*671* FUNCTION: AcpiUtGetResourceHeaderLength672*673* PARAMETERS: Aml - Pointer to the raw AML resource descriptor674*675* RETURN: Length of the AML header (depends on large/small descriptor)676*677* DESCRIPTION: Get the length of the header for this resource.678*679******************************************************************************/680681UINT8682AcpiUtGetResourceHeaderLength (683void *Aml)684{685ACPI_FUNCTION_ENTRY ();686687688/* Examine the large/small bit in the resource header */689690if (ACPI_GET8 (Aml) & ACPI_RESOURCE_NAME_LARGE)691{692return (sizeof (AML_RESOURCE_LARGE_HEADER));693}694else695{696return (sizeof (AML_RESOURCE_SMALL_HEADER));697}698}699700701/*******************************************************************************702*703* FUNCTION: AcpiUtGetDescriptorLength704*705* PARAMETERS: Aml - Pointer to the raw AML resource descriptor706*707* RETURN: Byte length708*709* DESCRIPTION: Get the total byte length of a raw AML descriptor, including the710* length of the descriptor header and the length field itself.711* Used to walk descriptor lists.712*713******************************************************************************/714715UINT32716AcpiUtGetDescriptorLength (717void *Aml)718{719ACPI_FUNCTION_ENTRY ();720721722/*723* Get the Resource Length (does not include header length) and add724* the header length (depends on if this is a small or large resource)725*/726return (AcpiUtGetResourceLength (Aml) +727AcpiUtGetResourceHeaderLength (Aml));728}729730731/*******************************************************************************732*733* FUNCTION: AcpiUtGetResourceEndTag734*735* PARAMETERS: ObjDesc - The resource template buffer object736* EndTag - Where the pointer to the EndTag is returned737*738* RETURN: Status, pointer to the end tag739*740* DESCRIPTION: Find the EndTag resource descriptor in an AML resource template741* Note: allows a buffer length of zero.742*743******************************************************************************/744745ACPI_STATUS746AcpiUtGetResourceEndTag (747ACPI_OPERAND_OBJECT *ObjDesc,748UINT8 **EndTag)749{750ACPI_STATUS Status;751752753ACPI_FUNCTION_TRACE (UtGetResourceEndTag);754755756/* Allow a buffer length of zero */757758if (!ObjDesc->Buffer.Length)759{760*EndTag = ObjDesc->Buffer.Pointer;761return_ACPI_STATUS (AE_OK);762}763764/* Validate the template and get a pointer to the EndTag */765766Status = AcpiUtWalkAmlResources (NULL, ObjDesc->Buffer.Pointer,767ObjDesc->Buffer.Length, NULL, (void **) EndTag);768769return_ACPI_STATUS (Status);770}771772773