Path: blob/main/sys/contrib/dev/acpica/components/executer/exoparg6.c
48521 views
/******************************************************************************1*2* Module Name: exoparg6 - AML execution - opcodes with 6 arguments3*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 ANY8586* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY87* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A88* PARTICULAR PURPOSE.89*90* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES91* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR92* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,93* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY94* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL95* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS96* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY97* LIMITED REMEDY.98*99* 4.3. Licensee shall not export, either directly or indirectly, any of this100* software or system incorporating such software without first obtaining any101* required license or other approval from the U. S. Department of Commerce or102* any other agency or department of the United States Government. In the103* event Licensee exports any such software from the United States or104* re-exports any such software from a foreign destination, Licensee shall105* ensure that the distribution and export/re-export of the software is in106* compliance with all laws, regulations, orders, or other restrictions of the107* U.S. Export Administration Regulations. Licensee agrees that neither it nor108* any of its subsidiaries will export/re-export any technical data, process,109* software, or service, directly or indirectly, to any country for which the110* United States government or any agency thereof requires an export license,111* other governmental approval, or letter of assurance, without first obtaining112* such license, approval or letter.113*114*****************************************************************************115*116* Alternatively, you may choose to be licensed under the terms of the117* following license:118*119* Redistribution and use in source and binary forms, with or without120* modification, are permitted provided that the following conditions121* are met:122* 1. Redistributions of source code must retain the above copyright123* notice, this list of conditions, and the following disclaimer,124* without modification.125* 2. Redistributions in binary form must reproduce at minimum a disclaimer126* substantially similar to the "NO WARRANTY" disclaimer below127* ("Disclaimer") and any redistribution must be conditioned upon128* including a substantially similar Disclaimer requirement for further129* binary redistribution.130* 3. Neither the names of the above-listed copyright holders nor the names131* of any contributors may be used to endorse or promote products derived132* from this software without specific prior written permission.133*134* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS135* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT136* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR137* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT138* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,139* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT140* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,141* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY142* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT143* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE144* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.145*146* Alternatively, you may choose to be licensed under the terms of the147* GNU General Public License ("GPL") version 2 as published by the Free148* Software Foundation.149*150*****************************************************************************/151152#include <contrib/dev/acpica/include/acpi.h>153#include <contrib/dev/acpica/include/accommon.h>154#include <contrib/dev/acpica/include/acinterp.h>155#include <contrib/dev/acpica/include/acparser.h>156#include <contrib/dev/acpica/include/amlcode.h>157158159#define _COMPONENT ACPI_EXECUTER160ACPI_MODULE_NAME ("exoparg6")161162163/*!164* Naming convention for AML interpreter execution routines.165*166* The routines that begin execution of AML opcodes are named with a common167* convention based upon the number of arguments, the number of target operands,168* and whether or not a value is returned:169*170* AcpiExOpcode_xA_yT_zR171*172* Where:173*174* xA - ARGUMENTS: The number of arguments (input operands) that are175* required for this opcode type (1 through 6 args).176* yT - TARGETS: The number of targets (output operands) that are required177* for this opcode type (0, 1, or 2 targets).178* zR - RETURN VALUE: Indicates whether this opcode type returns a value179* as the function return (0 or 1).180*181* The AcpiExOpcode* functions are called via the Dispatcher component with182* fully resolved operands.183!*/184185/* Local prototypes */186187static BOOLEAN188AcpiExDoMatch (189UINT32 MatchOp,190ACPI_OPERAND_OBJECT *PackageObj,191ACPI_OPERAND_OBJECT *MatchObj);192193194/*******************************************************************************195*196* FUNCTION: AcpiExDoMatch197*198* PARAMETERS: MatchOp - The AML match operand199* PackageObj - Object from the target package200* MatchObj - Object to be matched201*202* RETURN: TRUE if the match is successful, FALSE otherwise203*204* DESCRIPTION: Implements the low-level match for the ASL Match operator.205* Package elements will be implicitly converted to the type of206* the match object (Integer/Buffer/String).207*208******************************************************************************/209210static BOOLEAN211AcpiExDoMatch (212UINT32 MatchOp,213ACPI_OPERAND_OBJECT *PackageObj,214ACPI_OPERAND_OBJECT *MatchObj)215{216BOOLEAN LogicalResult = TRUE;217ACPI_STATUS Status;218219220/*221* Note: Since the PackageObj/MatchObj ordering is opposite to that of222* the standard logical operators, we have to reverse them when we call223* DoLogicalOp in order to make the implicit conversion rules work224* correctly. However, this means we have to flip the entire equation225* also. A bit ugly perhaps, but overall, better than fussing the226* parameters around at runtime, over and over again.227*228* Below, P[i] refers to the package element, M refers to the Match object.229*/230switch (MatchOp)231{232case MATCH_MTR:233234/* Always true */235236break;237238case MATCH_MEQ:239/*240* True if equal: (P[i] == M)241* Change to: (M == P[i])242*/243Status = AcpiExDoLogicalOp (244AML_LOGICAL_EQUAL_OP, MatchObj, PackageObj, &LogicalResult);245if (ACPI_FAILURE (Status))246{247return (FALSE);248}249break;250251case MATCH_MLE:252/*253* True if less than or equal: (P[i] <= M) (P[i] NotGreater than M)254* Change to: (M >= P[i]) (M NotLess than P[i])255*/256Status = AcpiExDoLogicalOp (257AML_LOGICAL_LESS_OP, MatchObj, PackageObj, &LogicalResult);258if (ACPI_FAILURE (Status))259{260return (FALSE);261}262LogicalResult = (BOOLEAN) !LogicalResult;263break;264265case MATCH_MLT:266/*267* True if less than: (P[i] < M)268* Change to: (M > P[i])269*/270Status = AcpiExDoLogicalOp (271AML_LOGICAL_GREATER_OP, MatchObj, PackageObj, &LogicalResult);272if (ACPI_FAILURE (Status))273{274return (FALSE);275}276break;277278case MATCH_MGE:279/*280* True if greater than or equal: (P[i] >= M) (P[i] NotLess than M)281* Change to: (M <= P[i]) (M NotGreater than P[i])282*/283Status = AcpiExDoLogicalOp (284AML_LOGICAL_GREATER_OP, MatchObj, PackageObj, &LogicalResult);285if (ACPI_FAILURE (Status))286{287return (FALSE);288}289LogicalResult = (BOOLEAN)!LogicalResult;290break;291292case MATCH_MGT:293/*294* True if greater than: (P[i] > M)295* Change to: (M < P[i])296*/297Status = AcpiExDoLogicalOp (298AML_LOGICAL_LESS_OP, MatchObj, PackageObj, &LogicalResult);299if (ACPI_FAILURE (Status))300{301return (FALSE);302}303break;304305default:306307/* Undefined */308309return (FALSE);310}311312return (LogicalResult);313}314315316/*******************************************************************************317*318* FUNCTION: AcpiExOpcode_6A_0T_1R319*320* PARAMETERS: WalkState - Current walk state321*322* RETURN: Status323*324* DESCRIPTION: Execute opcode with 6 arguments, no target, and a return value325*326******************************************************************************/327328ACPI_STATUS329AcpiExOpcode_6A_0T_1R (330ACPI_WALK_STATE *WalkState)331{332ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];333ACPI_OPERAND_OBJECT *ReturnDesc = NULL;334ACPI_STATUS Status = AE_OK;335UINT64 Index;336ACPI_OPERAND_OBJECT *ThisElement;337338339ACPI_FUNCTION_TRACE_STR (ExOpcode_6A_0T_1R,340AcpiPsGetOpcodeName (WalkState->Opcode));341342343switch (WalkState->Opcode)344{345case AML_MATCH_OP:346/*347* Match (SearchPkg[0], MatchOp1[1], MatchObj1[2],348* MatchOp2[3], MatchObj2[4], StartIndex[5])349*/350351/* Validate both Match Term Operators (MTR, MEQ, etc.) */352353if ((Operand[1]->Integer.Value > MAX_MATCH_OPERATOR) ||354(Operand[3]->Integer.Value > MAX_MATCH_OPERATOR))355{356ACPI_ERROR ((AE_INFO, "Match operator out of range"));357Status = AE_AML_OPERAND_VALUE;358goto Cleanup;359}360361/* Get the package StartIndex, validate against the package length */362363Index = Operand[5]->Integer.Value;364if (Index >= Operand[0]->Package.Count)365{366ACPI_ERROR ((AE_INFO,367"Index (0x%8.8X%8.8X) beyond package end (0x%X)",368ACPI_FORMAT_UINT64 (Index), Operand[0]->Package.Count));369Status = AE_AML_PACKAGE_LIMIT;370goto Cleanup;371}372373/* Create an integer for the return value */374/* Default return value is ACPI_UINT64_MAX if no match found */375376ReturnDesc = AcpiUtCreateIntegerObject (ACPI_UINT64_MAX);377if (!ReturnDesc)378{379Status = AE_NO_MEMORY;380goto Cleanup;381382}383384/*385* Examine each element until a match is found. Both match conditions386* must be satisfied for a match to occur. Within the loop,387* "continue" signifies that the current element does not match388* and the next should be examined.389*390* Upon finding a match, the loop will terminate via "break" at391* the bottom. If it terminates "normally", MatchValue will be392* ACPI_UINT64_MAX (Ones) (its initial value) indicating that no393* match was found.394*/395for ( ; Index < Operand[0]->Package.Count; Index++)396{397/* Get the current package element */398399ThisElement = Operand[0]->Package.Elements[Index];400401/* Treat any uninitialized (NULL) elements as non-matching */402403if (!ThisElement)404{405continue;406}407408/*409* Both match conditions must be satisfied. Execution of a continue410* (proceed to next iteration of enclosing for loop) signifies a411* non-match.412*/413if (!AcpiExDoMatch ((UINT32) Operand[1]->Integer.Value,414ThisElement, Operand[2]))415{416continue;417}418419if (!AcpiExDoMatch ((UINT32) Operand[3]->Integer.Value,420ThisElement, Operand[4]))421{422continue;423}424425/* Match found: Index is the return value */426427ReturnDesc->Integer.Value = Index;428break;429}430break;431432case AML_LOAD_TABLE_OP:433434Status = AcpiExLoadTableOp (WalkState, &ReturnDesc);435break;436437default:438439ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",440WalkState->Opcode));441442Status = AE_AML_BAD_OPCODE;443goto Cleanup;444}445446447Cleanup:448449/* Delete return object on error */450451if (ACPI_FAILURE (Status))452{453AcpiUtRemoveReference (ReturnDesc);454}455456/* Save return object on success */457458else459{460WalkState->ResultObj = ReturnDesc;461}462463return_ACPI_STATUS (Status);464}465466467