Path: blob/main/sys/contrib/dev/acpica/components/parser/psxface.c
48524 views
/******************************************************************************1*2* Module Name: psxface - Parser external interfaces3*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/acparser.h>154#include <contrib/dev/acpica/include/acdispat.h>155#include <contrib/dev/acpica/include/acinterp.h>156#include <contrib/dev/acpica/include/actables.h>157#include <contrib/dev/acpica/include/acnamesp.h>158159160#define _COMPONENT ACPI_PARSER161ACPI_MODULE_NAME ("psxface")162163/* Local Prototypes */164165static void166AcpiPsUpdateParameterList (167ACPI_EVALUATE_INFO *Info,168UINT16 Action);169170171/*******************************************************************************172*173* FUNCTION: AcpiDebugTrace174*175* PARAMETERS: MethodName - Valid ACPI name string176* DebugLevel - Optional level mask. 0 to use default177* DebugLayer - Optional layer mask. 0 to use default178* Flags - bit 1: one shot(1) or persistent(0)179*180* RETURN: Status181*182* DESCRIPTION: External interface to enable debug tracing during control183* method execution184*185******************************************************************************/186187ACPI_STATUS188AcpiDebugTrace (189const char *Name,190UINT32 DebugLevel,191UINT32 DebugLayer,192UINT32 Flags)193{194ACPI_STATUS Status;195196197Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);198if (ACPI_FAILURE (Status))199{200return (Status);201}202203AcpiGbl_TraceMethodName = Name;204AcpiGbl_TraceFlags = Flags;205AcpiGbl_TraceDbgLevel = DebugLevel;206AcpiGbl_TraceDbgLayer = DebugLayer;207Status = AE_OK;208209(void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);210return (Status);211}212213214/*******************************************************************************215*216* FUNCTION: AcpiPsExecuteMethod217*218* PARAMETERS: Info - Method info block, contains:219* Node - Method Node to execute220* ObjDesc - Method object221* Parameters - List of parameters to pass to the method,222* terminated by NULL. Params itself may be223* NULL if no parameters are being passed.224* ReturnObject - Where to put method's return value (if225* any). If NULL, no value is returned.226* ParameterType - Type of Parameter list227* ReturnObject - Where to put method's return value (if228* any). If NULL, no value is returned.229* PassNumber - Parse or execute pass230*231* RETURN: Status232*233* DESCRIPTION: Execute a control method234*235******************************************************************************/236237ACPI_STATUS238AcpiPsExecuteMethod (239ACPI_EVALUATE_INFO *Info)240{241ACPI_STATUS Status;242ACPI_PARSE_OBJECT *Op;243ACPI_WALK_STATE *WalkState;244245246ACPI_FUNCTION_TRACE (PsExecuteMethod);247248249/* Quick validation of DSDT header */250251AcpiTbCheckDsdtHeader ();252253/* Validate the Info and method Node */254255if (!Info || !Info->Node)256{257return_ACPI_STATUS (AE_NULL_ENTRY);258}259260/* Init for new method, wait on concurrency semaphore */261262Status = AcpiDsBeginMethodExecution (Info->Node, Info->ObjDesc, NULL);263if (ACPI_FAILURE (Status))264{265return_ACPI_STATUS (Status);266}267268/*269* The caller "owns" the parameters, so give each one an extra reference270*/271AcpiPsUpdateParameterList (Info, REF_INCREMENT);272273/*274* Execute the method. Performs parse simultaneously275*/276ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,277"**** Begin Method Parse/Execute [%4.4s] **** Node=%p Obj=%p\n",278Info->Node->Name.Ascii, Info->Node, Info->ObjDesc));279280/* Create and init a Root Node */281282Op = AcpiPsCreateScopeOp (Info->ObjDesc->Method.AmlStart);283if (!Op)284{285Status = AE_NO_MEMORY;286goto Cleanup;287}288289/* Create and initialize a new walk state */290291Info->PassNumber = ACPI_IMODE_EXECUTE;292WalkState = AcpiDsCreateWalkState (293Info->ObjDesc->Method.OwnerId, NULL, NULL, NULL);294if (!WalkState)295{296Status = AE_NO_MEMORY;297goto Cleanup;298}299300Status = AcpiDsInitAmlWalk (WalkState, Op, Info->Node,301Info->ObjDesc->Method.AmlStart,302Info->ObjDesc->Method.AmlLength, Info, Info->PassNumber);303if (ACPI_FAILURE (Status))304{305AcpiDsDeleteWalkState (WalkState);306goto Cleanup;307}308309WalkState->MethodPathname = Info->FullPathname;310WalkState->MethodIsNested = FALSE;311312if (Info->ObjDesc->Method.InfoFlags & ACPI_METHOD_MODULE_LEVEL)313{314WalkState->ParseFlags |= ACPI_PARSE_MODULE_LEVEL;315}316317/* Invoke an internal method if necessary */318319if (Info->ObjDesc->Method.InfoFlags & ACPI_METHOD_INTERNAL_ONLY)320{321Status = Info->ObjDesc->Method.Dispatch.Implementation (WalkState);322Info->ReturnObject = WalkState->ReturnDesc;323324/* Cleanup states */325326AcpiDsScopeStackClear (WalkState);327AcpiPsCleanupScope (&WalkState->ParserState);328AcpiDsTerminateControlMethod (WalkState->MethodDesc, WalkState);329AcpiDsDeleteWalkState (WalkState);330goto Cleanup;331}332333/*334* Start method evaluation with an implicit return of zero.335* This is done for Windows compatibility.336*/337if (AcpiGbl_EnableInterpreterSlack)338{339WalkState->ImplicitReturnObj =340AcpiUtCreateIntegerObject ((UINT64) 0);341if (!WalkState->ImplicitReturnObj)342{343Status = AE_NO_MEMORY;344AcpiDsDeleteWalkState (WalkState);345goto Cleanup;346}347}348349/* Parse the AML */350351Status = AcpiPsParseAml (WalkState);352353/* WalkState was deleted by ParseAml */354355Cleanup:356AcpiPsDeleteParseTree (Op);357358/* Take away the extra reference that we gave the parameters above */359360AcpiPsUpdateParameterList (Info, REF_DECREMENT);361362/* Exit now if error above */363364if (ACPI_FAILURE (Status))365{366return_ACPI_STATUS (Status);367}368369/*370* If the method has returned an object, signal this to the caller with371* a control exception code372*/373if (Info->ReturnObject)374{375ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Method returned ObjDesc=%p\n",376Info->ReturnObject));377ACPI_DUMP_STACK_ENTRY (Info->ReturnObject);378379Status = AE_CTRL_RETURN_VALUE;380}381382return_ACPI_STATUS (Status);383}384385386/*******************************************************************************387*388* FUNCTION: AcpiPsExecuteTable389*390* PARAMETERS: Info - Method info block, contains:391* Node - Node to where the is entered into the392* namespace393* ObjDesc - Pseudo method object describing the AML394* code of the entire table395* PassNumber - Parse or execute pass396*397* RETURN: Status398*399* DESCRIPTION: Execute a table400*401******************************************************************************/402403ACPI_STATUS404AcpiPsExecuteTable (405ACPI_EVALUATE_INFO *Info)406{407ACPI_STATUS Status;408ACPI_PARSE_OBJECT *Op = NULL;409ACPI_WALK_STATE *WalkState = NULL;410411412ACPI_FUNCTION_TRACE (PsExecuteTable);413414415/* Create and init a Root Node */416417Op = AcpiPsCreateScopeOp (Info->ObjDesc->Method.AmlStart);418if (!Op)419{420Status = AE_NO_MEMORY;421goto Cleanup;422}423424/* Create and initialize a new walk state */425426WalkState = AcpiDsCreateWalkState (427Info->ObjDesc->Method.OwnerId, NULL, NULL, NULL);428if (!WalkState)429{430Status = AE_NO_MEMORY;431goto Cleanup;432}433434Status = AcpiDsInitAmlWalk (WalkState, Op, Info->Node,435Info->ObjDesc->Method.AmlStart,436Info->ObjDesc->Method.AmlLength, Info, Info->PassNumber);437if (ACPI_FAILURE (Status))438{439goto Cleanup;440}441442WalkState->MethodPathname = Info->FullPathname;443WalkState->MethodIsNested = FALSE;444445if (Info->ObjDesc->Method.InfoFlags & ACPI_METHOD_MODULE_LEVEL)446{447WalkState->ParseFlags |= ACPI_PARSE_MODULE_LEVEL;448}449450/* Info->Node is the default location to load the table */451452if (Info->Node && Info->Node != AcpiGbl_RootNode)453{454Status = AcpiDsScopeStackPush (455Info->Node, ACPI_TYPE_METHOD, WalkState);456if (ACPI_FAILURE (Status))457{458goto Cleanup;459}460}461462/*463* Parse the AML, WalkState will be deleted by ParseAml464*/465AcpiExEnterInterpreter ();466Status = AcpiPsParseAml (WalkState);467AcpiExExitInterpreter ();468WalkState = NULL;469470Cleanup:471if (WalkState)472{473AcpiDsDeleteWalkState (WalkState);474}475if (Op)476{477AcpiPsDeleteParseTree (Op);478}479return_ACPI_STATUS (Status);480}481482483/*******************************************************************************484*485* FUNCTION: AcpiPsUpdateParameterList486*487* PARAMETERS: Info - See ACPI_EVALUATE_INFO488* (Used: ParameterType and Parameters)489* Action - Add or Remove reference490*491* RETURN: Status492*493* DESCRIPTION: Update reference count on all method parameter objects494*495******************************************************************************/496497static void498AcpiPsUpdateParameterList (499ACPI_EVALUATE_INFO *Info,500UINT16 Action)501{502UINT32 i;503504505if (Info->Parameters)506{507/* Update reference count for each parameter */508509for (i = 0; Info->Parameters[i]; i++)510{511/* Ignore errors, just do them all */512513(void) AcpiUtUpdateObjectReference (514Info->Parameters[i], Action);515}516}517}518519520