1 /******************************************************************************
3 * Module Name: nsarguments - Validation of args for ACPI predefined methods
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2016, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
50 #define _COMPONENT ACPI_NAMESPACE
51 ACPI_MODULE_NAME ("nsarguments")
54 /*******************************************************************************
56 * FUNCTION: AcpiNsCheckArgumentTypes
58 * PARAMETERS: Info - Method execution information block
62 * DESCRIPTION: Check the incoming argument count and all argument types
63 * against the argument type list for a predefined name.
65 ******************************************************************************/
68 AcpiNsCheckArgumentTypes (
69 ACPI_EVALUATE_INFO *Info)
78 /* If not a predefined name, cannot typecheck args */
80 if (!Info->Predefined)
85 ArgTypeList = Info->Predefined->Info.ArgumentList;
86 ArgCount = METHOD_GET_ARG_COUNT (ArgTypeList);
88 /* Typecheck all arguments */
90 for (i = 0; ((i < ArgCount) && (i < Info->ParamCount)); i++)
92 ArgType = METHOD_GET_NEXT_TYPE (ArgTypeList);
93 UserArgType = Info->Parameters[i]->Common.Type;
95 if (UserArgType != ArgType)
97 ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, ACPI_WARN_ALWAYS,
98 "Argument #%u type mismatch - "
99 "Found [%s], ACPI requires [%s]", (i + 1),
100 AcpiUtGetTypeName (UserArgType),
101 AcpiUtGetTypeName (ArgType)));
107 /*******************************************************************************
109 * FUNCTION: AcpiNsCheckAcpiCompliance
111 * PARAMETERS: Pathname - Full pathname to the node (for error msgs)
112 * Node - Namespace node for the method/object
113 * Predefined - Pointer to entry in predefined name table
117 * DESCRIPTION: Check that the declared parameter count (in ASL/AML) for a
118 * predefined name is what is expected (matches what is defined in
119 * the ACPI specification for this predefined name.)
121 ******************************************************************************/
124 AcpiNsCheckAcpiCompliance (
126 ACPI_NAMESPACE_NODE *Node,
127 const ACPI_PREDEFINED_INFO *Predefined)
129 UINT32 AmlParamCount;
130 UINT32 RequiredParamCount;
138 /* Get the ACPI-required arg count from the predefined info table */
141 METHOD_GET_ARG_COUNT (Predefined->Info.ArgumentList);
144 * If this object is not a control method, we can check if the ACPI
145 * spec requires that it be a method.
147 if (Node->Type != ACPI_TYPE_METHOD)
149 if (RequiredParamCount > 0)
151 /* Object requires args, must be implemented as a method */
153 ACPI_BIOS_ERROR_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,
154 "Object (%s) must be a control method with %u arguments",
155 AcpiUtGetTypeName (Node->Type), RequiredParamCount));
157 else if (!RequiredParamCount && !Predefined->Info.ExpectedBtypes)
159 /* Object requires no args and no return value, must be a method */
161 ACPI_BIOS_ERROR_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,
162 "Object (%s) must be a control method "
163 "with no arguments and no return value",
164 AcpiUtGetTypeName (Node->Type)));
171 * This is a control method.
172 * Check that the ASL/AML-defined parameter count for this method
173 * matches the ACPI-required parameter count
175 * Some methods are allowed to have a "minimum" number of args (_SCP)
176 * because their definition in ACPI has changed over time.
178 * Note: These are BIOS errors in the declaration of the object
180 AmlParamCount = Node->Object->Method.ParamCount;
182 if (AmlParamCount < RequiredParamCount)
184 ACPI_BIOS_ERROR_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,
185 "Insufficient arguments - "
186 "ASL declared %u, ACPI requires %u",
187 AmlParamCount, RequiredParamCount));
189 else if ((AmlParamCount > RequiredParamCount) &&
190 !(Predefined->Info.ArgumentList & ARG_COUNT_IS_MINIMUM))
192 ACPI_BIOS_ERROR_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,
193 "Excess arguments - "
194 "ASL declared %u, ACPI requires %u",
195 AmlParamCount, RequiredParamCount));
200 /*******************************************************************************
202 * FUNCTION: AcpiNsCheckArgumentCount
204 * PARAMETERS: Pathname - Full pathname to the node (for error msgs)
205 * Node - Namespace node for the method/object
206 * UserParamCount - Number of args passed in by the caller
207 * Predefined - Pointer to entry in predefined name table
211 * DESCRIPTION: Check that incoming argument count matches the declared
212 * parameter count (in the ASL/AML) for an object.
214 ******************************************************************************/
217 AcpiNsCheckArgumentCount (
219 ACPI_NAMESPACE_NODE *Node,
220 UINT32 UserParamCount,
221 const ACPI_PREDEFINED_INFO *Predefined)
223 UINT32 AmlParamCount;
224 UINT32 RequiredParamCount;
230 * Not a predefined name. Check the incoming user argument count
231 * against the count that is specified in the method/object.
233 if (Node->Type != ACPI_TYPE_METHOD)
237 ACPI_INFO_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,
238 "%u arguments were passed to a non-method ACPI object (%s)",
239 UserParamCount, AcpiUtGetTypeName (Node->Type)));
246 * This is a control method. Check the parameter count.
247 * We can only check the incoming argument count against the
248 * argument count declared for the method in the ASL/AML.
250 * Emit a message if too few or too many arguments have been passed
253 * Note: Too many arguments will not cause the method to
254 * fail. However, the method will fail if there are too few
255 * arguments and the method attempts to use one of the missing ones.
257 AmlParamCount = Node->Object->Method.ParamCount;
259 if (UserParamCount < AmlParamCount)
261 ACPI_WARN_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,
262 "Insufficient arguments - "
263 "Caller passed %u, method requires %u",
264 UserParamCount, AmlParamCount));
266 else if (UserParamCount > AmlParamCount)
268 ACPI_INFO_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,
269 "Excess arguments - "
270 "Caller passed %u, method requires %u",
271 UserParamCount, AmlParamCount));
278 * This is a predefined name. Validate the user-supplied parameter
279 * count against the ACPI specification. We don't validate against
280 * the method itself because what is important here is that the
281 * caller is in conformance with the spec. (The arg count for the
282 * method was checked against the ACPI spec earlier.)
284 * Some methods are allowed to have a "minimum" number of args (_SCP)
285 * because their definition in ACPI has changed over time.
288 METHOD_GET_ARG_COUNT (Predefined->Info.ArgumentList);
290 if (UserParamCount < RequiredParamCount)
292 ACPI_WARN_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,
293 "Insufficient arguments - "
294 "Caller passed %u, ACPI requires %u",
295 UserParamCount, RequiredParamCount));
297 else if ((UserParamCount > RequiredParamCount) &&
298 !(Predefined->Info.ArgumentList & ARG_COUNT_IS_MINIMUM))
300 ACPI_INFO_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,
301 "Excess arguments - "
302 "Caller passed %u, ACPI requires %u",
303 UserParamCount, RequiredParamCount));