Path: blob/main/sys/contrib/dev/acpica/compiler/aslresource.c
48371 views
/******************************************************************************1*2* Module Name: aslresource - Resource template/descriptor 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/compiler/aslcompiler.h>152#include "aslcompiler.y.h"153#include <contrib/dev/acpica/include/amlcode.h>154155156#define _COMPONENT ACPI_COMPILER157ACPI_MODULE_NAME ("aslresource")158159160/*******************************************************************************161*162* FUNCTION: RsSmallAddressCheck163*164* PARAMETERS: Minimum - Address Min value165* Maximum - Address Max value166* Length - Address range value167* Alignment - Address alignment value168* MinOp - Original Op for Address Min169* MaxOp - Original Op for Address Max170* LengthOp - Original Op for address range171* AlignOp - Original Op for address alignment. If172* NULL, means "zero value for alignment is173* OK, and means 64K alignment" (for174* Memory24 descriptor)175* Op - Parent Op for entire construct176*177* RETURN: None. Adds error messages to error log if necessary178*179* DESCRIPTION: Perform common value checks for "small" address descriptors.180* Currently:181* Io, Memory24, Memory32182*183******************************************************************************/184185void186RsSmallAddressCheck (187UINT8 Type,188UINT32 Minimum,189UINT32 Maximum,190UINT32 Length,191UINT32 Alignment,192ACPI_PARSE_OBJECT *MinOp,193ACPI_PARSE_OBJECT *MaxOp,194ACPI_PARSE_OBJECT *LengthOp,195ACPI_PARSE_OBJECT *AlignOp,196ACPI_PARSE_OBJECT *Op)197{198199if (AslGbl_NoResourceChecking)200{201return;202}203204/*205* Check for a so-called "null descriptor". These are descriptors that are206* created with most fields set to zero. The intent is that the descriptor207* will be updated/completed at runtime via a BufferField.208*209* If the descriptor does NOT have a resource tag, it cannot be referenced210* by a BufferField and we will flag this as an error. Conversely, if211* the descriptor has a resource tag, we will assume that a BufferField212* will be used to dynamically update it, so no error.213*214* A possible enhancement to this check would be to verify that in fact215* a BufferField is created using the resource tag, and perhaps even216* verify that a Store is performed to the BufferField.217*218* Note: for these descriptors, Alignment is allowed to be zero219*/220if (!Minimum && !Maximum && !Length)221{222if (!Op->Asl.ExternalName)223{224/* No resource tag. Descriptor is fixed and is also illegal */225226AslError (ASL_ERROR, ASL_MSG_NULL_DESCRIPTOR, Op, NULL);227}228229return;230}231232/*233* Range checks for Memory24 and Memory32.234* IO descriptor has different definition of min/max, don't check.235*/236if (Type != ACPI_RESOURCE_NAME_IO)237{238/* Basic checks on Min/Max/Length */239240if (Minimum > Maximum)241{242AslError (ASL_ERROR, ASL_MSG_INVALID_MIN_MAX, MinOp, NULL);243}244else if (Length > (Maximum - Minimum + 1))245{246AslError (ASL_ERROR, ASL_MSG_INVALID_LENGTH, LengthOp, NULL);247}248249/* Special case for Memory24, min/max values are compressed */250251if (Type == ACPI_RESOURCE_NAME_MEMORY24)252{253if (!Alignment) /* Alignment==0 means 64K alignment */254{255Alignment = ACPI_UINT16_MAX + 1;256}257258Minimum <<= 8;259Maximum <<= 8;260}261}262263/* Alignment of zero is not in ACPI spec, but is used to mean byte acc */264265if (!Alignment)266{267Alignment = 1;268}269270/* Addresses must be an exact multiple of the alignment value */271272if (Minimum % Alignment)273{274AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, MinOp, NULL);275}276if (Maximum % Alignment)277{278AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, MaxOp, NULL);279}280}281282283/*******************************************************************************284*285* FUNCTION: RsLargeAddressCheck286*287* PARAMETERS: Minimum - Address Min value288* Maximum - Address Max value289* Length - Address range value290* Granularity - Address granularity value291* Flags - General flags for address descriptors:292* _MIF, _MAF, _DEC293* MinOp - Original Op for Address Min294* MaxOp - Original Op for Address Max295* LengthOp - Original Op for address range296* GranOp - Original Op for address granularity297* Op - Parent Op for entire construct298*299* RETURN: None. Adds error messages to error log if necessary300*301* DESCRIPTION: Perform common value checks for "large" address descriptors.302* Currently:303* WordIo, WordBusNumber, WordSpace304* DWordIo, DWordMemory, DWordSpace305* QWordIo, QWordMemory, QWordSpace306* ExtendedIo, ExtendedMemory, ExtendedSpace307*308* _MIF flag set means that the minimum address is fixed and is not relocatable309* _MAF flag set means that the maximum address is fixed and is not relocatable310* Length of zero means that the record size is variable311*312* This function implements the LEN/MIF/MAF/MIN/MAX/GRA rules within Table 6-40313* of the ACPI 4.0a specification. Added 04/2010.314*315******************************************************************************/316317void318RsLargeAddressCheck (319UINT64 Minimum,320UINT64 Maximum,321UINT64 Length,322UINT64 Granularity,323UINT8 Flags,324ACPI_PARSE_OBJECT *MinOp,325ACPI_PARSE_OBJECT *MaxOp,326ACPI_PARSE_OBJECT *LengthOp,327ACPI_PARSE_OBJECT *GranOp,328ACPI_PARSE_OBJECT *Op)329{330331if (AslGbl_NoResourceChecking)332{333return;334}335336/*337* Check for a so-called "null descriptor". These are descriptors that are338* created with most fields set to zero. The intent is that the descriptor339* will be updated/completed at runtime via a BufferField.340*341* If the descriptor does NOT have a resource tag, it cannot be referenced342* by a BufferField and we will flag this as an error. Conversely, if343* the descriptor has a resource tag, we will assume that a BufferField344* will be used to dynamically update it, so no error.345*346* A possible enhancement to this check would be to verify that in fact347* a BufferField is created using the resource tag, and perhaps even348* verify that a Store is performed to the BufferField.349*/350if (!Minimum && !Maximum && !Length && !Granularity)351{352if (!Op->Asl.ExternalName)353{354/* No resource tag. Descriptor is fixed and is also illegal */355356AslError (ASL_ERROR, ASL_MSG_NULL_DESCRIPTOR, Op, NULL);357}358359return;360}361362/* Basic checks on Min/Max/Length */363364if (Minimum > Maximum)365{366AslError (ASL_ERROR, ASL_MSG_INVALID_MIN_MAX, MinOp, NULL);367return;368}369else if (Length > (Maximum - Minimum + 1))370{371AslError (ASL_ERROR, ASL_MSG_INVALID_LENGTH, LengthOp, NULL);372return;373}374375/* If specified (non-zero), ensure granularity is a power-of-two minus one */376377if (Granularity)378{379if ((Granularity + 1) &380Granularity)381{382AslError (ASL_ERROR, ASL_MSG_INVALID_GRANULARITY, GranOp, NULL);383return;384}385}386387/*388* Check the various combinations of Length, MinFixed, and MaxFixed389*/390if (Length)391{392/* Fixed non-zero length */393394switch (Flags & (ACPI_RESOURCE_FLAG_MIF | ACPI_RESOURCE_FLAG_MAF))395{396case 0:397/*398* Fixed length, variable locations (both _MIN and _MAX).399* Length must be a multiple of granularity400*/401if (Granularity & Length)402{403AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, LengthOp, NULL);404}405break;406407case (ACPI_RESOURCE_FLAG_MIF | ACPI_RESOURCE_FLAG_MAF):408409/* Fixed length, fixed location. Granularity must be zero */410411if (Granularity != 0)412{413AslError (ASL_ERROR, ASL_MSG_INVALID_GRAN_FIXED, GranOp, NULL);414}415416/* Length must be exactly the size of the min/max window */417418if (Length != (Maximum - Minimum + 1))419{420AslError (ASL_ERROR, ASL_MSG_INVALID_LENGTH_FIXED, LengthOp, NULL);421}422break;423424/* All other combinations are invalid */425426case ACPI_RESOURCE_FLAG_MIF:427case ACPI_RESOURCE_FLAG_MAF:428default:429430AslError (ASL_ERROR, ASL_MSG_INVALID_ADDR_FLAGS, LengthOp, NULL);431}432}433else434{435/* Variable length (length==0) */436437switch (Flags & (ACPI_RESOURCE_FLAG_MIF | ACPI_RESOURCE_FLAG_MAF))438{439case 0:440/*441* Both _MIN and _MAX are variable.442* No additional requirements, just exit443*/444break;445446case ACPI_RESOURCE_FLAG_MIF:447448/* _MIN is fixed. _MIN must be multiple of _GRA */449450/*451* The granularity is defined by the ACPI specification to be a452* power-of-two minus one, therefore the granularity is a453* bitmask which can be used to easily validate the addresses.454*/455if (Granularity & Minimum)456{457AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, MinOp, NULL);458}459break;460461case ACPI_RESOURCE_FLAG_MAF:462463/* _MAX is fixed. (_MAX + 1) must be multiple of _GRA */464465if (Granularity & (Maximum + 1))466{467AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, MaxOp, "-1");468}469break;470471/* Both MIF/MAF set is invalid if length is zero */472473case (ACPI_RESOURCE_FLAG_MIF | ACPI_RESOURCE_FLAG_MAF):474default:475476AslError (ASL_ERROR, ASL_MSG_INVALID_ADDR_FLAGS, LengthOp, NULL);477}478}479}480481482/*******************************************************************************483*484* FUNCTION: RsGetStringDataLength485*486* PARAMETERS: InitializerOp - Start of a subtree of init nodes487*488* RETURN: Valid string length if a string node is found (otherwise 0)489*490* DESCRIPTION: In a list of peer nodes, find the first one that contains a491* string and return the length of the string.492*493******************************************************************************/494495UINT16496RsGetStringDataLength (497ACPI_PARSE_OBJECT *InitializerOp)498{499500while (InitializerOp)501{502if (InitializerOp->Asl.ParseOpcode == PARSEOP_STRING_LITERAL)503{504return ((UINT16) (strlen (InitializerOp->Asl.Value.String) + 1));505}506507InitializerOp = ASL_GET_PEER_NODE (InitializerOp);508}509510return (0);511}512513514/*******************************************************************************515*516* FUNCTION: RsAllocateResourceNode517*518* PARAMETERS: Size - Size of node in bytes519*520* RETURN: The allocated node - aborts on allocation failure521*522* DESCRIPTION: Allocate a resource description node and the resource523* descriptor itself (the nodes are used to link descriptors).524*525******************************************************************************/526527ASL_RESOURCE_NODE *528RsAllocateResourceNode (529UINT32 Size)530{531ASL_RESOURCE_NODE *Rnode;532533534/* Allocate the node */535536Rnode = UtLocalCalloc (sizeof (ASL_RESOURCE_NODE));537538/* Allocate the resource descriptor itself */539540Rnode->Buffer = UtLocalCalloc (Size);541Rnode->BufferLength = Size;542return (Rnode);543}544545546/*******************************************************************************547*548* FUNCTION: RsCreateResourceField549*550* PARAMETERS: Op - Resource field node551* Name - Name of the field (Used only to reference552* the field in the ASL, not in the AML)553* ByteOffset - Offset from the field start554* BitOffset - Additional bit offset555* BitLength - Number of bits in the field556*557* RETURN: None, sets fields within the input node558*559* DESCRIPTION: Utility function to generate a named bit field within a560* resource descriptor. Mark a node as 1) a field in a resource561* descriptor, and 2) set the value to be a BIT offset562*563******************************************************************************/564565void566RsCreateResourceField (567ACPI_PARSE_OBJECT *Op,568char *Name,569UINT32 ByteOffset,570UINT32 BitOffset,571UINT32 BitLength)572{573574Op->Asl.ExternalName = Name;575Op->Asl.CompileFlags |= OP_IS_RESOURCE_FIELD;576577Op->Asl.Value.Tag.BitOffset = (ByteOffset * 8) + BitOffset;578Op->Asl.Value.Tag.BitLength = BitLength;579}580581582/*******************************************************************************583*584* FUNCTION: RsSetFlagBits585*586* PARAMETERS: *Flags - Pointer to the flag byte587* Op - Flag initialization node588* Position - Bit position within the flag byte589* Default - Used if the node is DEFAULT.590*591* RETURN: Sets bits within the *Flags output byte.592*593* DESCRIPTION: Set a bit in a cumulative flags word from an initialization594* node. Will use a default value if the node is DEFAULT, meaning595* that no value was specified in the ASL. Used to merge multiple596* keywords into a single flags byte.597*598******************************************************************************/599600void601RsSetFlagBits (602UINT8 *Flags,603ACPI_PARSE_OBJECT *Op,604UINT8 Position,605UINT8 DefaultBit)606{607608if (Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)609{610/* Use the default bit */611612*Flags |= (DefaultBit << Position);613}614else615{616/* Use the bit specified in the initialization node */617618*Flags |= (((UINT8) Op->Asl.Value.Integer) << Position);619}620}621622623void624RsSetFlagBits16 (625UINT16 *Flags,626ACPI_PARSE_OBJECT *Op,627UINT8 Position,628UINT8 DefaultBit)629{630631if (Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)632{633/* Use the default bit */634635*Flags |= (DefaultBit << Position);636}637else638{639/* Use the bit specified in the initialization node */640641*Flags |= (((UINT16) Op->Asl.Value.Integer) << Position);642}643}644645646/*******************************************************************************647*648* FUNCTION: RsCompleteNodeAndGetNext649*650* PARAMETERS: Op - Resource node to be completed651*652* RETURN: The next peer to the input node.653*654* DESCRIPTION: Mark the current node completed and return the next peer.655* The node ParseOpcode is set to DEFAULT_ARG, meaning that656* this node is to be ignored from now on.657*658******************************************************************************/659660ACPI_PARSE_OBJECT *661RsCompleteNodeAndGetNext (662ACPI_PARSE_OBJECT *Op)663{664665/* Mark this node unused */666667Op->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;668669/* Move on to the next peer node in the initializer list */670671return (ASL_GET_PEER_NODE (Op));672}673674675/*******************************************************************************676*677* FUNCTION: RsCheckListForDuplicates678*679* PARAMETERS: Op - First op in the initializer list680*681* RETURN: None682*683* DESCRIPTION: Check an initializer list for duplicate values. Emits an error684* if any duplicates are found.685*686******************************************************************************/687688void689RsCheckListForDuplicates (690ACPI_PARSE_OBJECT *Op)691{692ACPI_PARSE_OBJECT *NextValueOp = Op;693ACPI_PARSE_OBJECT *NextOp;694UINT32 Value;695696697if (!Op)698{699return;700}701702/* Search list once for each value in the list */703704while (NextValueOp)705{706Value = (UINT32) NextValueOp->Asl.Value.Integer;707708/* Compare this value to all remaining values in the list */709710NextOp = ASL_GET_PEER_NODE (NextValueOp);711while (NextOp)712{713if (NextOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)714{715/* Compare values */716717if (Value == (UINT32) NextOp->Asl.Value.Integer)718{719/* Emit error only once per duplicate node */720721if (!(NextOp->Asl.CompileFlags & OP_IS_DUPLICATE))722{723NextOp->Asl.CompileFlags |= OP_IS_DUPLICATE;724AslError (ASL_ERROR, ASL_MSG_DUPLICATE_ITEM,725NextOp, NULL);726}727}728}729730NextOp = ASL_GET_PEER_NODE (NextOp);731}732733NextValueOp = ASL_GET_PEER_NODE (NextValueOp);734}735}736737738/*******************************************************************************739*740* FUNCTION: RsDoOneResourceDescriptor741*742* PARAMETERS: DescriptorTypeOp - Parent parse node of the descriptor743* CurrentByteOffset - Offset in the resource descriptor744* buffer.745*746* RETURN: A valid resource node for the descriptor747*748* DESCRIPTION: Dispatches the processing of one resource descriptor749*750******************************************************************************/751752ASL_RESOURCE_NODE *753RsDoOneResourceDescriptor (754ASL_RESOURCE_INFO *Info,755UINT8 *State)756{757ASL_RESOURCE_NODE *Rnode = NULL;758759760/* Construct the resource */761762switch (Info->DescriptorTypeOp->Asl.ParseOpcode)763{764765case PARSEOP_CLOCKINPUT:766767Rnode = RsDoClockInputDescriptor(Info);768break;769770case PARSEOP_DMA:771772Rnode = RsDoDmaDescriptor (Info);773break;774775case PARSEOP_FIXEDDMA:776777Rnode = RsDoFixedDmaDescriptor (Info);778break;779780case PARSEOP_DWORDIO:781782Rnode = RsDoDwordIoDescriptor (Info);783break;784785case PARSEOP_DWORDMEMORY:786787Rnode = RsDoDwordMemoryDescriptor (Info);788break;789790case PARSEOP_DWORDPCC:791792Rnode = RsDoDwordPccDescriptor (Info);793break;794795case PARSEOP_DWORDSPACE:796797Rnode = RsDoDwordSpaceDescriptor (Info);798break;799800case PARSEOP_ENDDEPENDENTFN:801802switch (*State)803{804case ACPI_RSTATE_NORMAL:805806AslError (ASL_ERROR, ASL_MSG_MISSING_STARTDEPENDENT,807Info->DescriptorTypeOp, NULL);808break;809810case ACPI_RSTATE_START_DEPENDENT:811812AslError (ASL_ERROR, ASL_MSG_DEPENDENT_NESTING,813Info->DescriptorTypeOp, NULL);814break;815816case ACPI_RSTATE_DEPENDENT_LIST:817default:818819break;820}821822*State = ACPI_RSTATE_NORMAL;823Rnode = RsDoEndDependentDescriptor (Info);824break;825826case PARSEOP_ENDTAG:827828Rnode = RsDoEndTagDescriptor (Info);829break;830831case PARSEOP_EXTENDEDIO:832833Rnode = RsDoExtendedIoDescriptor (Info);834break;835836case PARSEOP_EXTENDEDMEMORY:837838Rnode = RsDoExtendedMemoryDescriptor (Info);839break;840841case PARSEOP_EXTENDEDSPACE:842843Rnode = RsDoExtendedSpaceDescriptor (Info);844break;845846case PARSEOP_FIXEDIO:847848Rnode = RsDoFixedIoDescriptor (Info);849break;850851case PARSEOP_INTERRUPT:852853Rnode = RsDoInterruptDescriptor (Info);854break;855856case PARSEOP_IO:857858Rnode = RsDoIoDescriptor (Info);859break;860861case PARSEOP_IRQ:862863Rnode = RsDoIrqDescriptor (Info);864break;865866case PARSEOP_IRQNOFLAGS:867868Rnode = RsDoIrqNoFlagsDescriptor (Info);869break;870871case PARSEOP_MEMORY24:872873Rnode = RsDoMemory24Descriptor (Info);874break;875876case PARSEOP_MEMORY32:877878Rnode = RsDoMemory32Descriptor (Info);879break;880881case PARSEOP_MEMORY32FIXED:882883Rnode = RsDoMemory32FixedDescriptor (Info);884break;885886case PARSEOP_QWORDIO:887888Rnode = RsDoQwordIoDescriptor (Info);889break;890891case PARSEOP_QWORDMEMORY:892893Rnode = RsDoQwordMemoryDescriptor (Info);894break;895896case PARSEOP_QWORDPCC:897898Rnode = RsDoQwordPccDescriptor (Info);899break;900901case PARSEOP_QWORDSPACE:902903Rnode = RsDoQwordSpaceDescriptor (Info);904break;905906case PARSEOP_REGISTER:907908Rnode = RsDoGeneralRegisterDescriptor (Info);909break;910911case PARSEOP_STARTDEPENDENTFN:912913switch (*State)914{915case ACPI_RSTATE_START_DEPENDENT:916917AslError (ASL_ERROR, ASL_MSG_DEPENDENT_NESTING,918Info->DescriptorTypeOp, NULL);919break;920921case ACPI_RSTATE_NORMAL:922case ACPI_RSTATE_DEPENDENT_LIST:923default:924925break;926}927928*State = ACPI_RSTATE_START_DEPENDENT;929Rnode = RsDoStartDependentDescriptor (Info);930*State = ACPI_RSTATE_DEPENDENT_LIST;931break;932933case PARSEOP_STARTDEPENDENTFN_NOPRI:934935switch (*State)936{937case ACPI_RSTATE_START_DEPENDENT:938939AslError (ASL_ERROR, ASL_MSG_DEPENDENT_NESTING,940Info->DescriptorTypeOp, NULL);941break;942943case ACPI_RSTATE_NORMAL:944case ACPI_RSTATE_DEPENDENT_LIST:945default:946947break;948}949950*State = ACPI_RSTATE_START_DEPENDENT;951Rnode = RsDoStartDependentNoPriDescriptor (Info);952*State = ACPI_RSTATE_DEPENDENT_LIST;953break;954955case PARSEOP_VENDORLONG:956957Rnode = RsDoVendorLargeDescriptor (Info);958break;959960case PARSEOP_VENDORSHORT:961962Rnode = RsDoVendorSmallDescriptor (Info);963break;964965case PARSEOP_WORDBUSNUMBER:966967Rnode = RsDoWordBusNumberDescriptor (Info);968break;969970case PARSEOP_WORDIO:971972Rnode = RsDoWordIoDescriptor (Info);973break;974975case PARSEOP_WORDPCC:976977Rnode = RsDoWordPccDescriptor (Info);978break;979980case PARSEOP_WORDSPACE:981982Rnode = RsDoWordSpaceDescriptor (Info);983break;984985case PARSEOP_GPIO_INT:986987Rnode = RsDoGpioIntDescriptor (Info);988break;989990case PARSEOP_GPIO_IO:991992Rnode = RsDoGpioIoDescriptor (Info);993break;994995case PARSEOP_I2C_SERIALBUS:996case PARSEOP_I2C_SERIALBUS_V2:997998Rnode = RsDoI2cSerialBusDescriptor (Info);999break;10001001case PARSEOP_SPI_SERIALBUS:1002case PARSEOP_SPI_SERIALBUS_V2:10031004Rnode = RsDoSpiSerialBusDescriptor (Info);1005break;10061007case PARSEOP_UART_SERIALBUS:1008case PARSEOP_UART_SERIALBUS_V2:10091010Rnode = RsDoUartSerialBusDescriptor (Info);1011break;10121013case PARSEOP_CSI2_SERIALBUS:10141015Rnode = RsDoCsi2SerialBusDescriptor (Info);1016break;10171018case PARSEOP_PINCONFIG:10191020Rnode = RsDoPinConfigDescriptor (Info);1021break;10221023case PARSEOP_PINFUNCTION:10241025Rnode = RsDoPinFunctionDescriptor (Info);1026break;10271028case PARSEOP_PINGROUP:10291030Rnode = RsDoPinGroupDescriptor (Info);1031break;10321033case PARSEOP_PINGROUPFUNCTION:10341035Rnode = RsDoPinGroupFunctionDescriptor (Info);1036break;10371038case PARSEOP_PINGROUPCONFIG:10391040Rnode = RsDoPinGroupConfigDescriptor (Info);1041break;10421043case PARSEOP_DEFAULT_ARG:10441045/* Just ignore any of these, they are used as fillers/placeholders */1046break;10471048default:10491050printf ("Unknown resource descriptor type [%s]\n",1051Info->DescriptorTypeOp->Asl.ParseOpName);1052break;1053}10541055/*1056* Mark original node as unused, but head of a resource descriptor.1057* This allows the resource to be installed in the namespace so that1058* references to the descriptor can be resolved.1059*/1060Info->DescriptorTypeOp->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;1061Info->DescriptorTypeOp->Asl.CompileFlags = OP_IS_RESOURCE_DESC;1062Info->DescriptorTypeOp->Asl.Value.Integer = Info->CurrentByteOffset;10631064if (Rnode)1065{1066Info->DescriptorTypeOp->Asl.FinalAmlLength = Rnode->BufferLength;1067Info->DescriptorTypeOp->Asl.Extra =1068((AML_RESOURCE *) Rnode->Buffer)->DescriptorType;1069}10701071return (Rnode);1072}107310741075/*******************************************************************************1076*1077* FUNCTION: RsLinkDescriptorChain1078*1079* PARAMETERS: PreviousRnode - Pointer to the node that will be previous1080* to the linked node, At exit, set to the1081* last node in the new chain.1082* Rnode - Resource node to link into the list1083*1084* RETURN: Cumulative buffer byte offset of the new segment of chain1085*1086* DESCRIPTION: Link a descriptor chain at the end of an existing chain.1087*1088******************************************************************************/10891090UINT321091RsLinkDescriptorChain (1092ASL_RESOURCE_NODE **PreviousRnode,1093ASL_RESOURCE_NODE *Rnode)1094{1095ASL_RESOURCE_NODE *LastRnode;1096UINT32 CurrentByteOffset;109710981099/* Anything to do? */11001101if (!Rnode)1102{1103return (0);1104}11051106/* Point the previous node to the new node */11071108(*PreviousRnode)->Next = Rnode;1109CurrentByteOffset = Rnode->BufferLength;11101111/* Walk to the end of the chain headed by Rnode */11121113LastRnode = Rnode;1114while (LastRnode->Next)1115{1116LastRnode = LastRnode->Next;1117CurrentByteOffset += LastRnode->BufferLength;1118}11191120/* Previous node becomes the last node in the chain */11211122*PreviousRnode = LastRnode;1123return (CurrentByteOffset);1124}112511261127/*******************************************************************************1128*1129* FUNCTION: RsDoResourceTemplate1130*1131* PARAMETERS: Op - Parent of a resource template list1132*1133* RETURN: None. Sets input node to point to a list of AML code1134*1135* DESCRIPTION: Merge a list of resource descriptors into a single AML buffer,1136* in preparation for output to the AML output file.1137*1138******************************************************************************/11391140void1141RsDoResourceTemplate (1142ACPI_PARSE_OBJECT *Op)1143{1144ACPI_PARSE_OBJECT *BufferLengthOp;1145ACPI_PARSE_OBJECT *BufferOp;1146ACPI_PARSE_OBJECT *DescriptorTypeOp;1147ACPI_PARSE_OBJECT *LastOp = NULL;1148UINT32 CurrentByteOffset = 0;1149ASL_RESOURCE_NODE HeadRnode;1150ASL_RESOURCE_NODE *PreviousRnode;1151ASL_RESOURCE_NODE *Rnode;1152ASL_RESOURCE_INFO Info;1153UINT8 State;115411551156/* Mark parent as containing a resource template */11571158if (Op->Asl.Parent)1159{1160Op->Asl.Parent->Asl.CompileFlags |= OP_IS_RESOURCE_DESC;1161}11621163/* ResourceTemplate Opcode is first (Op) */1164/* Buffer Length node is first child */11651166BufferLengthOp = ASL_GET_CHILD_NODE (Op);11671168/* Buffer Op is first peer */11691170BufferOp = ASL_GET_PEER_NODE (BufferLengthOp);11711172/* First Descriptor type is next */11731174DescriptorTypeOp = ASL_GET_PEER_NODE (BufferOp);11751176/* DEFAULT_ARG indicates null template - ResourceTemplate(){} */11771178if (DescriptorTypeOp->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)1179{1180AslError (ASL_WARNING, ASL_MSG_NULL_RESOURCE_TEMPLATE,1181DescriptorTypeOp, DescriptorTypeOp->Asl.Value.String);1182}11831184/*1185* Process all resource descriptors in the list1186* Note: It is assumed that the EndTag node has been automatically1187* inserted at the end of the template by the parser.1188*/1189State = ACPI_RSTATE_NORMAL;1190PreviousRnode = &HeadRnode;1191while (DescriptorTypeOp)1192{1193/* Save information for optional mapfile */11941195if (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONNECTION)1196{1197Info.MappingOp = Op->Asl.Parent;1198}1199else1200{1201Info.MappingOp = DescriptorTypeOp;1202}12031204Info.DescriptorTypeOp = DescriptorTypeOp;1205Info.CurrentByteOffset = CurrentByteOffset;12061207DescriptorTypeOp->Asl.CompileFlags |= OP_IS_RESOURCE_DESC;1208Rnode = RsDoOneResourceDescriptor (&Info, &State);12091210/*1211* Update current byte offset to indicate the number of bytes from the1212* start of the buffer. Buffer can include multiple descriptors, we1213* must keep track of the offset of not only each descriptor, but each1214* element (field) within each descriptor as well.1215*/1216CurrentByteOffset += RsLinkDescriptorChain (&PreviousRnode, Rnode);12171218/* Get the next descriptor in the list */12191220LastOp = DescriptorTypeOp;1221DescriptorTypeOp = ASL_GET_PEER_NODE (DescriptorTypeOp);1222}12231224if (State == ACPI_RSTATE_DEPENDENT_LIST)1225{1226if (LastOp)1227{1228LastOp = LastOp->Asl.Parent;1229}1230AslError (ASL_ERROR, ASL_MSG_MISSING_ENDDEPENDENT, LastOp, NULL);1231}12321233/*1234* Transform the nodes into the following1235*1236* Op -> AML_BUFFER_OP1237* First Child -> BufferLength1238* Second Child -> Descriptor Buffer (raw byte data)1239*/1240Op->Asl.ParseOpcode = PARSEOP_BUFFER;1241Op->Asl.AmlOpcode = AML_BUFFER_OP;1242Op->Asl.CompileFlags = OP_AML_PACKAGE | OP_IS_RESOURCE_DESC;1243UtSetParseOpName (Op);12441245BufferLengthOp->Asl.ParseOpcode = PARSEOP_INTEGER;1246BufferLengthOp->Asl.Value.Integer = CurrentByteOffset;1247(void) OpcSetOptimalIntegerSize (BufferLengthOp);1248UtSetParseOpName (BufferLengthOp);12491250BufferOp->Asl.ParseOpcode = PARSEOP_RAW_DATA;1251BufferOp->Asl.AmlOpcode = AML_RAW_DATA_CHAIN;1252BufferOp->Asl.AmlOpcodeLength = 0;1253BufferOp->Asl.AmlLength = CurrentByteOffset;1254BufferOp->Asl.Value.Buffer = ACPI_CAST_PTR (UINT8, HeadRnode.Next);1255BufferOp->Asl.CompileFlags |= OP_IS_RESOURCE_DATA;1256UtSetParseOpName (BufferOp);12571258return;1259}126012611262