1895f26a9SJung-uk Kim /******************************************************************************
2895f26a9SJung-uk Kim  *
3895f26a9SJung-uk Kim  * Module Name: nsarguments - Validation of args for ACPI predefined methods
4895f26a9SJung-uk Kim  *
5895f26a9SJung-uk Kim  *****************************************************************************/
6895f26a9SJung-uk Kim 
70d84335fSJung-uk Kim /******************************************************************************
80d84335fSJung-uk Kim  *
90d84335fSJung-uk Kim  * 1. Copyright Notice
100d84335fSJung-uk Kim  *
11722b1667SJung-uk Kim  * Some or all of this work - Copyright (c) 1999 - 2023, Intel Corp.
12895f26a9SJung-uk Kim  * All rights reserved.
13895f26a9SJung-uk Kim  *
140d84335fSJung-uk Kim  * 2. License
150d84335fSJung-uk Kim  *
160d84335fSJung-uk Kim  * 2.1. This is your license from Intel Corp. under its intellectual property
170d84335fSJung-uk Kim  * rights. You may have additional license terms from the party that provided
180d84335fSJung-uk Kim  * you this software, covering your right to use that party's intellectual
190d84335fSJung-uk Kim  * property rights.
200d84335fSJung-uk Kim  *
210d84335fSJung-uk Kim  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
220d84335fSJung-uk Kim  * copy of the source code appearing in this file ("Covered Code") an
230d84335fSJung-uk Kim  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
240d84335fSJung-uk Kim  * base code distributed originally by Intel ("Original Intel Code") to copy,
250d84335fSJung-uk Kim  * make derivatives, distribute, use and display any portion of the Covered
260d84335fSJung-uk Kim  * Code in any form, with the right to sublicense such rights; and
270d84335fSJung-uk Kim  *
280d84335fSJung-uk Kim  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
290d84335fSJung-uk Kim  * license (with the right to sublicense), under only those claims of Intel
300d84335fSJung-uk Kim  * patents that are infringed by the Original Intel Code, to make, use, sell,
310d84335fSJung-uk Kim  * offer to sell, and import the Covered Code and derivative works thereof
320d84335fSJung-uk Kim  * solely to the minimum extent necessary to exercise the above copyright
330d84335fSJung-uk Kim  * license, and in no event shall the patent license extend to any additions
340d84335fSJung-uk Kim  * to or modifications of the Original Intel Code. No other license or right
350d84335fSJung-uk Kim  * is granted directly or by implication, estoppel or otherwise;
360d84335fSJung-uk Kim  *
370d84335fSJung-uk Kim  * The above copyright and patent license is granted only if the following
380d84335fSJung-uk Kim  * conditions are met:
390d84335fSJung-uk Kim  *
400d84335fSJung-uk Kim  * 3. Conditions
410d84335fSJung-uk Kim  *
420d84335fSJung-uk Kim  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
430d84335fSJung-uk Kim  * Redistribution of source code of any substantial portion of the Covered
440d84335fSJung-uk Kim  * Code or modification with rights to further distribute source must include
450d84335fSJung-uk Kim  * the above Copyright Notice, the above License, this list of Conditions,
460d84335fSJung-uk Kim  * and the following Disclaimer and Export Compliance provision. In addition,
470d84335fSJung-uk Kim  * Licensee must cause all Covered Code to which Licensee contributes to
480d84335fSJung-uk Kim  * contain a file documenting the changes Licensee made to create that Covered
490d84335fSJung-uk Kim  * Code and the date of any change. Licensee must include in that file the
500d84335fSJung-uk Kim  * documentation of any changes made by any predecessor Licensee. Licensee
510d84335fSJung-uk Kim  * must include a prominent statement that the modification is derived,
520d84335fSJung-uk Kim  * directly or indirectly, from Original Intel Code.
530d84335fSJung-uk Kim  *
540d84335fSJung-uk Kim  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
550d84335fSJung-uk Kim  * Redistribution of source code of any substantial portion of the Covered
560d84335fSJung-uk Kim  * Code or modification without rights to further distribute source must
570d84335fSJung-uk Kim  * include the following Disclaimer and Export Compliance provision in the
580d84335fSJung-uk Kim  * documentation and/or other materials provided with distribution. In
590d84335fSJung-uk Kim  * addition, Licensee may not authorize further sublicense of source of any
600d84335fSJung-uk Kim  * portion of the Covered Code, and must include terms to the effect that the
610d84335fSJung-uk Kim  * license from Licensee to its licensee is limited to the intellectual
620d84335fSJung-uk Kim  * property embodied in the software Licensee provides to its licensee, and
630d84335fSJung-uk Kim  * not to intellectual property embodied in modifications its licensee may
640d84335fSJung-uk Kim  * make.
650d84335fSJung-uk Kim  *
660d84335fSJung-uk Kim  * 3.3. Redistribution of Executable. Redistribution in executable form of any
670d84335fSJung-uk Kim  * substantial portion of the Covered Code or modification must reproduce the
680d84335fSJung-uk Kim  * above Copyright Notice, and the following Disclaimer and Export Compliance
690d84335fSJung-uk Kim  * provision in the documentation and/or other materials provided with the
700d84335fSJung-uk Kim  * distribution.
710d84335fSJung-uk Kim  *
720d84335fSJung-uk Kim  * 3.4. Intel retains all right, title, and interest in and to the Original
730d84335fSJung-uk Kim  * Intel Code.
740d84335fSJung-uk Kim  *
750d84335fSJung-uk Kim  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
760d84335fSJung-uk Kim  * Intel shall be used in advertising or otherwise to promote the sale, use or
770d84335fSJung-uk Kim  * other dealings in products derived from or relating to the Covered Code
780d84335fSJung-uk Kim  * without prior written authorization from Intel.
790d84335fSJung-uk Kim  *
800d84335fSJung-uk Kim  * 4. Disclaimer and Export Compliance
810d84335fSJung-uk Kim  *
820d84335fSJung-uk Kim  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
830d84335fSJung-uk Kim  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
840d84335fSJung-uk Kim  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
850d84335fSJung-uk Kim  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
860d84335fSJung-uk Kim  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
870d84335fSJung-uk Kim  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
880d84335fSJung-uk Kim  * PARTICULAR PURPOSE.
890d84335fSJung-uk Kim  *
900d84335fSJung-uk Kim  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
910d84335fSJung-uk Kim  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
920d84335fSJung-uk Kim  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
930d84335fSJung-uk Kim  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
940d84335fSJung-uk Kim  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
950d84335fSJung-uk Kim  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
960d84335fSJung-uk Kim  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
970d84335fSJung-uk Kim  * LIMITED REMEDY.
980d84335fSJung-uk Kim  *
990d84335fSJung-uk Kim  * 4.3. Licensee shall not export, either directly or indirectly, any of this
1000d84335fSJung-uk Kim  * software or system incorporating such software without first obtaining any
1010d84335fSJung-uk Kim  * required license or other approval from the U. S. Department of Commerce or
1020d84335fSJung-uk Kim  * any other agency or department of the United States Government. In the
1030d84335fSJung-uk Kim  * event Licensee exports any such software from the United States or
1040d84335fSJung-uk Kim  * re-exports any such software from a foreign destination, Licensee shall
1050d84335fSJung-uk Kim  * ensure that the distribution and export/re-export of the software is in
1060d84335fSJung-uk Kim  * compliance with all laws, regulations, orders, or other restrictions of the
1070d84335fSJung-uk Kim  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1080d84335fSJung-uk Kim  * any of its subsidiaries will export/re-export any technical data, process,
1090d84335fSJung-uk Kim  * software, or service, directly or indirectly, to any country for which the
1100d84335fSJung-uk Kim  * United States government or any agency thereof requires an export license,
1110d84335fSJung-uk Kim  * other governmental approval, or letter of assurance, without first obtaining
1120d84335fSJung-uk Kim  * such license, approval or letter.
1130d84335fSJung-uk Kim  *
1140d84335fSJung-uk Kim  *****************************************************************************
1150d84335fSJung-uk Kim  *
1160d84335fSJung-uk Kim  * Alternatively, you may choose to be licensed under the terms of the
1170d84335fSJung-uk Kim  * following license:
1180d84335fSJung-uk Kim  *
119895f26a9SJung-uk Kim  * Redistribution and use in source and binary forms, with or without
120895f26a9SJung-uk Kim  * modification, are permitted provided that the following conditions
121895f26a9SJung-uk Kim  * are met:
122895f26a9SJung-uk Kim  * 1. Redistributions of source code must retain the above copyright
123895f26a9SJung-uk Kim  *    notice, this list of conditions, and the following disclaimer,
124895f26a9SJung-uk Kim  *    without modification.
125895f26a9SJung-uk Kim  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126895f26a9SJung-uk Kim  *    substantially similar to the "NO WARRANTY" disclaimer below
127895f26a9SJung-uk Kim  *    ("Disclaimer") and any redistribution must be conditioned upon
128895f26a9SJung-uk Kim  *    including a substantially similar Disclaimer requirement for further
129895f26a9SJung-uk Kim  *    binary redistribution.
130895f26a9SJung-uk Kim  * 3. Neither the names of the above-listed copyright holders nor the names
131895f26a9SJung-uk Kim  *    of any contributors may be used to endorse or promote products derived
132895f26a9SJung-uk Kim  *    from this software without specific prior written permission.
133895f26a9SJung-uk Kim  *
1340d84335fSJung-uk Kim  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1350d84335fSJung-uk Kim  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1360d84335fSJung-uk Kim  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1370d84335fSJung-uk Kim  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1380d84335fSJung-uk Kim  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1390d84335fSJung-uk Kim  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1400d84335fSJung-uk Kim  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1410d84335fSJung-uk Kim  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1420d84335fSJung-uk Kim  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1430d84335fSJung-uk Kim  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1440d84335fSJung-uk Kim  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1450d84335fSJung-uk Kim  *
1460d84335fSJung-uk Kim  * Alternatively, you may choose to be licensed under the terms of the
147895f26a9SJung-uk Kim  * GNU General Public License ("GPL") version 2 as published by the Free
148895f26a9SJung-uk Kim  * Software Foundation.
149895f26a9SJung-uk Kim  *
1500d84335fSJung-uk Kim  *****************************************************************************/
151895f26a9SJung-uk Kim 
152895f26a9SJung-uk Kim #include <contrib/dev/acpica/include/acpi.h>
153895f26a9SJung-uk Kim #include <contrib/dev/acpica/include/accommon.h>
154895f26a9SJung-uk Kim #include <contrib/dev/acpica/include/acnamesp.h>
155895f26a9SJung-uk Kim #include <contrib/dev/acpica/include/acpredef.h>
156895f26a9SJung-uk Kim 
157895f26a9SJung-uk Kim 
158895f26a9SJung-uk Kim #define _COMPONENT          ACPI_NAMESPACE
159895f26a9SJung-uk Kim         ACPI_MODULE_NAME    ("nsarguments")
160895f26a9SJung-uk Kim 
161895f26a9SJung-uk Kim 
162895f26a9SJung-uk Kim /*******************************************************************************
163895f26a9SJung-uk Kim  *
164895f26a9SJung-uk Kim  * FUNCTION:    AcpiNsCheckArgumentTypes
165895f26a9SJung-uk Kim  *
166895f26a9SJung-uk Kim  * PARAMETERS:  Info            - Method execution information block
167895f26a9SJung-uk Kim  *
168895f26a9SJung-uk Kim  * RETURN:      None
169895f26a9SJung-uk Kim  *
170895f26a9SJung-uk Kim  * DESCRIPTION: Check the incoming argument count and all argument types
171895f26a9SJung-uk Kim  *              against the argument type list for a predefined name.
172895f26a9SJung-uk Kim  *
173895f26a9SJung-uk Kim  ******************************************************************************/
174895f26a9SJung-uk Kim 
175895f26a9SJung-uk Kim void
AcpiNsCheckArgumentTypes(ACPI_EVALUATE_INFO * Info)176895f26a9SJung-uk Kim AcpiNsCheckArgumentTypes (
177895f26a9SJung-uk Kim     ACPI_EVALUATE_INFO          *Info)
178895f26a9SJung-uk Kim {
179895f26a9SJung-uk Kim     UINT16                      ArgTypeList;
180895f26a9SJung-uk Kim     UINT8                       ArgCount;
181895f26a9SJung-uk Kim     UINT8                       ArgType;
182895f26a9SJung-uk Kim     UINT8                       UserArgType;
183895f26a9SJung-uk Kim     UINT32                      i;
184895f26a9SJung-uk Kim 
185895f26a9SJung-uk Kim 
1865f9b24faSJung-uk Kim     /*
1875f9b24faSJung-uk Kim      * If not a predefined name, cannot typecheck args, because
1885f9b24faSJung-uk Kim      * we have no idea what argument types are expected.
1895f9b24faSJung-uk Kim      * Also, ignore typecheck if warnings/errors if this method
1905f9b24faSJung-uk Kim      * has already been evaluated at least once -- in order
1915f9b24faSJung-uk Kim      * to suppress repetitive messages.
1925f9b24faSJung-uk Kim      */
1935f9b24faSJung-uk Kim     if (!Info->Predefined || (Info->Node->Flags & ANOBJ_EVALUATED))
194895f26a9SJung-uk Kim     {
195895f26a9SJung-uk Kim         return;
196895f26a9SJung-uk Kim     }
197895f26a9SJung-uk Kim 
198895f26a9SJung-uk Kim     ArgTypeList = Info->Predefined->Info.ArgumentList;
199895f26a9SJung-uk Kim     ArgCount = METHOD_GET_ARG_COUNT (ArgTypeList);
200895f26a9SJung-uk Kim 
201895f26a9SJung-uk Kim     /* Typecheck all arguments */
202895f26a9SJung-uk Kim 
203895f26a9SJung-uk Kim     for (i = 0; ((i < ArgCount) && (i < Info->ParamCount)); i++)
204895f26a9SJung-uk Kim     {
205895f26a9SJung-uk Kim         ArgType = METHOD_GET_NEXT_TYPE (ArgTypeList);
206895f26a9SJung-uk Kim         UserArgType = Info->Parameters[i]->Common.Type;
207895f26a9SJung-uk Kim 
208f15e9afbSJung-uk Kim         /* No typechecking for ACPI_TYPE_ANY */
209f15e9afbSJung-uk Kim 
210f15e9afbSJung-uk Kim         if ((UserArgType != ArgType) && (ArgType != ACPI_TYPE_ANY))
211895f26a9SJung-uk Kim         {
212895f26a9SJung-uk Kim             ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, ACPI_WARN_ALWAYS,
213895f26a9SJung-uk Kim                 "Argument #%u type mismatch - "
214895f26a9SJung-uk Kim                 "Found [%s], ACPI requires [%s]", (i + 1),
215895f26a9SJung-uk Kim                 AcpiUtGetTypeName (UserArgType),
216895f26a9SJung-uk Kim                 AcpiUtGetTypeName (ArgType)));
2175f9b24faSJung-uk Kim 
2185f9b24faSJung-uk Kim             /* Prevent any additional typechecking for this method */
2195f9b24faSJung-uk Kim 
2205f9b24faSJung-uk Kim             Info->Node->Flags |= ANOBJ_EVALUATED;
221895f26a9SJung-uk Kim         }
222895f26a9SJung-uk Kim     }
223895f26a9SJung-uk Kim }
224895f26a9SJung-uk Kim 
225895f26a9SJung-uk Kim 
226895f26a9SJung-uk Kim /*******************************************************************************
227895f26a9SJung-uk Kim  *
228895f26a9SJung-uk Kim  * FUNCTION:    AcpiNsCheckAcpiCompliance
229895f26a9SJung-uk Kim  *
230895f26a9SJung-uk Kim  * PARAMETERS:  Pathname        - Full pathname to the node (for error msgs)
231895f26a9SJung-uk Kim  *              Node            - Namespace node for the method/object
232895f26a9SJung-uk Kim  *              Predefined      - Pointer to entry in predefined name table
233895f26a9SJung-uk Kim  *
234895f26a9SJung-uk Kim  * RETURN:      None
235895f26a9SJung-uk Kim  *
236895f26a9SJung-uk Kim  * DESCRIPTION: Check that the declared parameter count (in ASL/AML) for a
237895f26a9SJung-uk Kim  *              predefined name is what is expected (matches what is defined in
238895f26a9SJung-uk Kim  *              the ACPI specification for this predefined name.)
239895f26a9SJung-uk Kim  *
240895f26a9SJung-uk Kim  ******************************************************************************/
241895f26a9SJung-uk Kim 
242895f26a9SJung-uk Kim void
AcpiNsCheckAcpiCompliance(char * Pathname,ACPI_NAMESPACE_NODE * Node,const ACPI_PREDEFINED_INFO * Predefined)243895f26a9SJung-uk Kim AcpiNsCheckAcpiCompliance (
244895f26a9SJung-uk Kim     char                        *Pathname,
245895f26a9SJung-uk Kim     ACPI_NAMESPACE_NODE         *Node,
246895f26a9SJung-uk Kim     const ACPI_PREDEFINED_INFO  *Predefined)
247895f26a9SJung-uk Kim {
248895f26a9SJung-uk Kim     UINT32                      AmlParamCount;
249895f26a9SJung-uk Kim     UINT32                      RequiredParamCount;
250895f26a9SJung-uk Kim 
251895f26a9SJung-uk Kim 
2525f9b24faSJung-uk Kim     if (!Predefined || (Node->Flags & ANOBJ_EVALUATED))
253895f26a9SJung-uk Kim     {
254895f26a9SJung-uk Kim         return;
255895f26a9SJung-uk Kim     }
256895f26a9SJung-uk Kim 
257895f26a9SJung-uk Kim     /* Get the ACPI-required arg count from the predefined info table */
258895f26a9SJung-uk Kim 
259f8146b88SJung-uk Kim     RequiredParamCount =
260f8146b88SJung-uk Kim         METHOD_GET_ARG_COUNT (Predefined->Info.ArgumentList);
261895f26a9SJung-uk Kim 
262895f26a9SJung-uk Kim     /*
263895f26a9SJung-uk Kim      * If this object is not a control method, we can check if the ACPI
264895f26a9SJung-uk Kim      * spec requires that it be a method.
265895f26a9SJung-uk Kim      */
266895f26a9SJung-uk Kim     if (Node->Type != ACPI_TYPE_METHOD)
267895f26a9SJung-uk Kim     {
268895f26a9SJung-uk Kim         if (RequiredParamCount > 0)
269895f26a9SJung-uk Kim         {
270895f26a9SJung-uk Kim             /* Object requires args, must be implemented as a method */
271895f26a9SJung-uk Kim 
272895f26a9SJung-uk Kim             ACPI_BIOS_ERROR_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,
273895f26a9SJung-uk Kim                 "Object (%s) must be a control method with %u arguments",
274895f26a9SJung-uk Kim                 AcpiUtGetTypeName (Node->Type), RequiredParamCount));
275895f26a9SJung-uk Kim         }
276895f26a9SJung-uk Kim         else if (!RequiredParamCount && !Predefined->Info.ExpectedBtypes)
277895f26a9SJung-uk Kim         {
278895f26a9SJung-uk Kim             /* Object requires no args and no return value, must be a method */
279895f26a9SJung-uk Kim 
280895f26a9SJung-uk Kim             ACPI_BIOS_ERROR_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,
281895f26a9SJung-uk Kim                 "Object (%s) must be a control method "
282895f26a9SJung-uk Kim                 "with no arguments and no return value",
283895f26a9SJung-uk Kim                 AcpiUtGetTypeName (Node->Type)));
284895f26a9SJung-uk Kim         }
285895f26a9SJung-uk Kim 
286895f26a9SJung-uk Kim         return;
287895f26a9SJung-uk Kim     }
288895f26a9SJung-uk Kim 
289895f26a9SJung-uk Kim     /*
290895f26a9SJung-uk Kim      * This is a control method.
291895f26a9SJung-uk Kim      * Check that the ASL/AML-defined parameter count for this method
292895f26a9SJung-uk Kim      * matches the ACPI-required parameter count
293895f26a9SJung-uk Kim      *
294895f26a9SJung-uk Kim      * Some methods are allowed to have a "minimum" number of args (_SCP)
295895f26a9SJung-uk Kim      * because their definition in ACPI has changed over time.
296895f26a9SJung-uk Kim      *
297895f26a9SJung-uk Kim      * Note: These are BIOS errors in the declaration of the object
298895f26a9SJung-uk Kim      */
299895f26a9SJung-uk Kim     AmlParamCount = Node->Object->Method.ParamCount;
300895f26a9SJung-uk Kim 
301895f26a9SJung-uk Kim     if (AmlParamCount < RequiredParamCount)
302895f26a9SJung-uk Kim     {
303895f26a9SJung-uk Kim         ACPI_BIOS_ERROR_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,
304895f26a9SJung-uk Kim             "Insufficient arguments - "
305895f26a9SJung-uk Kim             "ASL declared %u, ACPI requires %u",
306895f26a9SJung-uk Kim             AmlParamCount, RequiredParamCount));
307895f26a9SJung-uk Kim     }
308895f26a9SJung-uk Kim     else if ((AmlParamCount > RequiredParamCount) &&
309895f26a9SJung-uk Kim         !(Predefined->Info.ArgumentList & ARG_COUNT_IS_MINIMUM))
310895f26a9SJung-uk Kim     {
311895f26a9SJung-uk Kim         ACPI_BIOS_ERROR_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,
312895f26a9SJung-uk Kim             "Excess arguments - "
313895f26a9SJung-uk Kim             "ASL declared %u, ACPI requires %u",
314895f26a9SJung-uk Kim             AmlParamCount, RequiredParamCount));
315895f26a9SJung-uk Kim     }
316895f26a9SJung-uk Kim }
317895f26a9SJung-uk Kim 
318895f26a9SJung-uk Kim 
319895f26a9SJung-uk Kim /*******************************************************************************
320895f26a9SJung-uk Kim  *
321895f26a9SJung-uk Kim  * FUNCTION:    AcpiNsCheckArgumentCount
322895f26a9SJung-uk Kim  *
323895f26a9SJung-uk Kim  * PARAMETERS:  Pathname        - Full pathname to the node (for error msgs)
324895f26a9SJung-uk Kim  *              Node            - Namespace node for the method/object
325895f26a9SJung-uk Kim  *              UserParamCount  - Number of args passed in by the caller
326895f26a9SJung-uk Kim  *              Predefined      - Pointer to entry in predefined name table
327895f26a9SJung-uk Kim  *
328895f26a9SJung-uk Kim  * RETURN:      None
329895f26a9SJung-uk Kim  *
330895f26a9SJung-uk Kim  * DESCRIPTION: Check that incoming argument count matches the declared
331895f26a9SJung-uk Kim  *              parameter count (in the ASL/AML) for an object.
332895f26a9SJung-uk Kim  *
333895f26a9SJung-uk Kim  ******************************************************************************/
334895f26a9SJung-uk Kim 
335895f26a9SJung-uk Kim void
AcpiNsCheckArgumentCount(char * Pathname,ACPI_NAMESPACE_NODE * Node,UINT32 UserParamCount,const ACPI_PREDEFINED_INFO * Predefined)336895f26a9SJung-uk Kim AcpiNsCheckArgumentCount (
337895f26a9SJung-uk Kim     char                        *Pathname,
338895f26a9SJung-uk Kim     ACPI_NAMESPACE_NODE         *Node,
339895f26a9SJung-uk Kim     UINT32                      UserParamCount,
340895f26a9SJung-uk Kim     const ACPI_PREDEFINED_INFO  *Predefined)
341895f26a9SJung-uk Kim {
342895f26a9SJung-uk Kim     UINT32                      AmlParamCount;
343895f26a9SJung-uk Kim     UINT32                      RequiredParamCount;
344895f26a9SJung-uk Kim 
345895f26a9SJung-uk Kim 
3465f9b24faSJung-uk Kim     if (Node->Flags & ANOBJ_EVALUATED)
3475f9b24faSJung-uk Kim     {
3485f9b24faSJung-uk Kim         return;
3495f9b24faSJung-uk Kim     }
3505f9b24faSJung-uk Kim 
351895f26a9SJung-uk Kim     if (!Predefined)
352895f26a9SJung-uk Kim     {
353895f26a9SJung-uk Kim         /*
354895f26a9SJung-uk Kim          * Not a predefined name. Check the incoming user argument count
355895f26a9SJung-uk Kim          * against the count that is specified in the method/object.
356895f26a9SJung-uk Kim          */
357895f26a9SJung-uk Kim         if (Node->Type != ACPI_TYPE_METHOD)
358895f26a9SJung-uk Kim         {
359895f26a9SJung-uk Kim             if (UserParamCount)
360895f26a9SJung-uk Kim             {
361895f26a9SJung-uk Kim                 ACPI_INFO_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,
362895f26a9SJung-uk Kim                     "%u arguments were passed to a non-method ACPI object (%s)",
363895f26a9SJung-uk Kim                     UserParamCount, AcpiUtGetTypeName (Node->Type)));
364895f26a9SJung-uk Kim             }
365895f26a9SJung-uk Kim 
366895f26a9SJung-uk Kim             return;
367895f26a9SJung-uk Kim         }
368895f26a9SJung-uk Kim 
369895f26a9SJung-uk Kim         /*
370895f26a9SJung-uk Kim          * This is a control method. Check the parameter count.
371895f26a9SJung-uk Kim          * We can only check the incoming argument count against the
372895f26a9SJung-uk Kim          * argument count declared for the method in the ASL/AML.
373895f26a9SJung-uk Kim          *
374895f26a9SJung-uk Kim          * Emit a message if too few or too many arguments have been passed
375895f26a9SJung-uk Kim          * by the caller.
376895f26a9SJung-uk Kim          *
377895f26a9SJung-uk Kim          * Note: Too many arguments will not cause the method to
378895f26a9SJung-uk Kim          * fail. However, the method will fail if there are too few
379895f26a9SJung-uk Kim          * arguments and the method attempts to use one of the missing ones.
380895f26a9SJung-uk Kim          */
381895f26a9SJung-uk Kim         AmlParamCount = Node->Object->Method.ParamCount;
382895f26a9SJung-uk Kim 
383895f26a9SJung-uk Kim         if (UserParamCount < AmlParamCount)
384895f26a9SJung-uk Kim         {
385895f26a9SJung-uk Kim             ACPI_WARN_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,
386895f26a9SJung-uk Kim                 "Insufficient arguments - "
387895f26a9SJung-uk Kim                 "Caller passed %u, method requires %u",
388895f26a9SJung-uk Kim                 UserParamCount, AmlParamCount));
389895f26a9SJung-uk Kim         }
390895f26a9SJung-uk Kim         else if (UserParamCount > AmlParamCount)
391895f26a9SJung-uk Kim         {
392895f26a9SJung-uk Kim             ACPI_INFO_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,
393895f26a9SJung-uk Kim                 "Excess arguments - "
394895f26a9SJung-uk Kim                 "Caller passed %u, method requires %u",
395895f26a9SJung-uk Kim                 UserParamCount, AmlParamCount));
396895f26a9SJung-uk Kim         }
397895f26a9SJung-uk Kim 
398895f26a9SJung-uk Kim         return;
399895f26a9SJung-uk Kim     }
400895f26a9SJung-uk Kim 
401895f26a9SJung-uk Kim     /*
402895f26a9SJung-uk Kim      * This is a predefined name. Validate the user-supplied parameter
403895f26a9SJung-uk Kim      * count against the ACPI specification. We don't validate against
404895f26a9SJung-uk Kim      * the method itself because what is important here is that the
405895f26a9SJung-uk Kim      * caller is in conformance with the spec. (The arg count for the
406895f26a9SJung-uk Kim      * method was checked against the ACPI spec earlier.)
407895f26a9SJung-uk Kim      *
408895f26a9SJung-uk Kim      * Some methods are allowed to have a "minimum" number of args (_SCP)
409895f26a9SJung-uk Kim      * because their definition in ACPI has changed over time.
410895f26a9SJung-uk Kim      */
411f8146b88SJung-uk Kim     RequiredParamCount =
412f8146b88SJung-uk Kim         METHOD_GET_ARG_COUNT (Predefined->Info.ArgumentList);
413895f26a9SJung-uk Kim 
414895f26a9SJung-uk Kim     if (UserParamCount < RequiredParamCount)
415895f26a9SJung-uk Kim     {
416895f26a9SJung-uk Kim         ACPI_WARN_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,
417895f26a9SJung-uk Kim             "Insufficient arguments - "
418895f26a9SJung-uk Kim             "Caller passed %u, ACPI requires %u",
419895f26a9SJung-uk Kim             UserParamCount, RequiredParamCount));
420895f26a9SJung-uk Kim     }
421895f26a9SJung-uk Kim     else if ((UserParamCount > RequiredParamCount) &&
422895f26a9SJung-uk Kim         !(Predefined->Info.ArgumentList & ARG_COUNT_IS_MINIMUM))
423895f26a9SJung-uk Kim     {
424895f26a9SJung-uk Kim         ACPI_INFO_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,
425895f26a9SJung-uk Kim             "Excess arguments - "
426895f26a9SJung-uk Kim             "Caller passed %u, ACPI requires %u",
427895f26a9SJung-uk Kim             UserParamCount, RequiredParamCount));
428895f26a9SJung-uk Kim     }
429895f26a9SJung-uk Kim }
430