Path: blob/main/sys/contrib/dev/acpica/components/namespace/nsarguments.c
48524 views
/******************************************************************************1*2* Module Name: nsarguments - Validation of args for ACPI predefined methods3*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/acnamesp.h>154#include <contrib/dev/acpica/include/acpredef.h>155156157#define _COMPONENT ACPI_NAMESPACE158ACPI_MODULE_NAME ("nsarguments")159160161/*******************************************************************************162*163* FUNCTION: AcpiNsCheckArgumentTypes164*165* PARAMETERS: Info - Method execution information block166*167* RETURN: None168*169* DESCRIPTION: Check the incoming argument count and all argument types170* against the argument type list for a predefined name.171*172******************************************************************************/173174void175AcpiNsCheckArgumentTypes (176ACPI_EVALUATE_INFO *Info)177{178UINT16 ArgTypeList;179UINT8 ArgCount;180UINT8 ArgType;181UINT8 UserArgType;182UINT32 i;183184185/*186* If not a predefined name, cannot typecheck args, because187* we have no idea what argument types are expected.188* Also, ignore typecheck if warnings/errors if this method189* has already been evaluated at least once -- in order190* to suppress repetitive messages.191*/192if (!Info->Predefined || (Info->Node->Flags & ANOBJ_EVALUATED))193{194return;195}196197ArgTypeList = Info->Predefined->Info.ArgumentList;198ArgCount = METHOD_GET_ARG_COUNT (ArgTypeList);199200/* Typecheck all arguments */201202for (i = 0; ((i < ArgCount) && (i < Info->ParamCount)); i++)203{204ArgType = METHOD_GET_NEXT_TYPE (ArgTypeList);205UserArgType = Info->Parameters[i]->Common.Type;206207/* No typechecking for ACPI_TYPE_ANY */208209if ((UserArgType != ArgType) && (ArgType != ACPI_TYPE_ANY))210{211ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, ACPI_WARN_ALWAYS,212"Argument #%u type mismatch - "213"Found [%s], ACPI requires [%s]", (i + 1),214AcpiUtGetTypeName (UserArgType),215AcpiUtGetTypeName (ArgType)));216217/* Prevent any additional typechecking for this method */218219Info->Node->Flags |= ANOBJ_EVALUATED;220}221}222}223224225/*******************************************************************************226*227* FUNCTION: AcpiNsCheckAcpiCompliance228*229* PARAMETERS: Pathname - Full pathname to the node (for error msgs)230* Node - Namespace node for the method/object231* Predefined - Pointer to entry in predefined name table232*233* RETURN: None234*235* DESCRIPTION: Check that the declared parameter count (in ASL/AML) for a236* predefined name is what is expected (matches what is defined in237* the ACPI specification for this predefined name.)238*239******************************************************************************/240241void242AcpiNsCheckAcpiCompliance (243char *Pathname,244ACPI_NAMESPACE_NODE *Node,245const ACPI_PREDEFINED_INFO *Predefined)246{247UINT32 AmlParamCount;248UINT32 RequiredParamCount;249250251if (!Predefined || (Node->Flags & ANOBJ_EVALUATED))252{253return;254}255256/* Get the ACPI-required arg count from the predefined info table */257258RequiredParamCount =259METHOD_GET_ARG_COUNT (Predefined->Info.ArgumentList);260261/*262* If this object is not a control method, we can check if the ACPI263* spec requires that it be a method.264*/265if (Node->Type != ACPI_TYPE_METHOD)266{267if (RequiredParamCount > 0)268{269/* Object requires args, must be implemented as a method */270271ACPI_BIOS_ERROR_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,272"Object (%s) must be a control method with %u arguments",273AcpiUtGetTypeName (Node->Type), RequiredParamCount));274}275else if (!RequiredParamCount && !Predefined->Info.ExpectedBtypes)276{277/* Object requires no args and no return value, must be a method */278279ACPI_BIOS_ERROR_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,280"Object (%s) must be a control method "281"with no arguments and no return value",282AcpiUtGetTypeName (Node->Type)));283}284285return;286}287288/*289* This is a control method.290* Check that the ASL/AML-defined parameter count for this method291* matches the ACPI-required parameter count292*293* Some methods are allowed to have a "minimum" number of args (_SCP)294* because their definition in ACPI has changed over time.295*296* Note: These are BIOS errors in the declaration of the object297*/298AmlParamCount = Node->Object->Method.ParamCount;299300if (AmlParamCount < RequiredParamCount)301{302ACPI_BIOS_ERROR_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,303"Insufficient arguments - "304"ASL declared %u, ACPI requires %u",305AmlParamCount, RequiredParamCount));306}307else if ((AmlParamCount > RequiredParamCount) &&308!(Predefined->Info.ArgumentList & ARG_COUNT_IS_MINIMUM))309{310ACPI_BIOS_ERROR_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,311"Excess arguments - "312"ASL declared %u, ACPI requires %u",313AmlParamCount, RequiredParamCount));314}315}316317318/*******************************************************************************319*320* FUNCTION: AcpiNsCheckArgumentCount321*322* PARAMETERS: Pathname - Full pathname to the node (for error msgs)323* Node - Namespace node for the method/object324* UserParamCount - Number of args passed in by the caller325* Predefined - Pointer to entry in predefined name table326*327* RETURN: None328*329* DESCRIPTION: Check that incoming argument count matches the declared330* parameter count (in the ASL/AML) for an object.331*332******************************************************************************/333334void335AcpiNsCheckArgumentCount (336char *Pathname,337ACPI_NAMESPACE_NODE *Node,338UINT32 UserParamCount,339const ACPI_PREDEFINED_INFO *Predefined)340{341UINT32 AmlParamCount;342UINT32 RequiredParamCount;343344345if (Node->Flags & ANOBJ_EVALUATED)346{347return;348}349350if (!Predefined)351{352/*353* Not a predefined name. Check the incoming user argument count354* against the count that is specified in the method/object.355*/356if (Node->Type != ACPI_TYPE_METHOD)357{358if (UserParamCount)359{360ACPI_INFO_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,361"%u arguments were passed to a non-method ACPI object (%s)",362UserParamCount, AcpiUtGetTypeName (Node->Type)));363}364365return;366}367368/*369* This is a control method. Check the parameter count.370* We can only check the incoming argument count against the371* argument count declared for the method in the ASL/AML.372*373* Emit a message if too few or too many arguments have been passed374* by the caller.375*376* Note: Too many arguments will not cause the method to377* fail. However, the method will fail if there are too few378* arguments and the method attempts to use one of the missing ones.379*/380AmlParamCount = Node->Object->Method.ParamCount;381382if (UserParamCount < AmlParamCount)383{384ACPI_WARN_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,385"Insufficient arguments - "386"Caller passed %u, method requires %u",387UserParamCount, AmlParamCount));388}389else if (UserParamCount > AmlParamCount)390{391ACPI_INFO_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,392"Excess arguments - "393"Caller passed %u, method requires %u",394UserParamCount, AmlParamCount));395}396397return;398}399400/*401* This is a predefined name. Validate the user-supplied parameter402* count against the ACPI specification. We don't validate against403* the method itself because what is important here is that the404* caller is in conformance with the spec. (The arg count for the405* method was checked against the ACPI spec earlier.)406*407* Some methods are allowed to have a "minimum" number of args (_SCP)408* because their definition in ACPI has changed over time.409*/410RequiredParamCount =411METHOD_GET_ARG_COUNT (Predefined->Info.ArgumentList);412413if (UserParamCount < RequiredParamCount)414{415ACPI_WARN_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,416"Insufficient arguments - "417"Caller passed %u, ACPI requires %u",418UserParamCount, RequiredParamCount));419}420else if ((UserParamCount > RequiredParamCount) &&421!(Predefined->Info.ArgumentList & ARG_COUNT_IS_MINIMUM))422{423ACPI_INFO_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,424"Excess arguments - "425"Caller passed %u, ACPI requires %u",426UserParamCount, RequiredParamCount));427}428}429430431