1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /******************************************************************************
4 * Module Name: nsarguments - Validation of args for ACPI predefined methods
6 * Copyright (C) 2000 - 2019, Intel Corp.
8 *****************************************************************************/
10 #include <acpi/acpi.h>
15 #define _COMPONENT ACPI_NAMESPACE
16 ACPI_MODULE_NAME("nsarguments")
18 /*******************************************************************************
20 * FUNCTION: acpi_ns_check_argument_types
22 * PARAMETERS: info - Method execution information block
26 * DESCRIPTION: Check the incoming argument count and all argument types
27 * against the argument type list for a predefined name.
29 ******************************************************************************/
30 void acpi_ns_check_argument_types(struct acpi_evaluate_info *info)
39 * If not a predefined name, cannot typecheck args, because
40 * we have no idea what argument types are expected.
41 * Also, ignore typecheck if warnings/errors if this method
42 * has already been evaluated at least once -- in order
43 * to suppress repetitive messages.
45 if (!info->predefined || (info->node->flags & ANOBJ_EVALUATED)) {
49 arg_type_list = info->predefined->info.argument_list;
50 arg_count = METHOD_GET_ARG_COUNT(arg_type_list);
52 /* Typecheck all arguments */
54 for (i = 0; ((i < arg_count) && (i < info->param_count)); i++) {
55 arg_type = METHOD_GET_NEXT_TYPE(arg_type_list);
56 user_arg_type = info->parameters[i]->common.type;
58 if (user_arg_type != arg_type) {
59 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
61 "Argument #%u type mismatch - "
62 "Found [%s], ACPI requires [%s]",
66 acpi_ut_get_type_name(arg_type)));
68 /* Prevent any additional typechecking for this method */
70 info->node->flags |= ANOBJ_EVALUATED;
75 /*******************************************************************************
77 * FUNCTION: acpi_ns_check_acpi_compliance
79 * PARAMETERS: pathname - Full pathname to the node (for error msgs)
80 * node - Namespace node for the method/object
81 * predefined - Pointer to entry in predefined name table
85 * DESCRIPTION: Check that the declared parameter count (in ASL/AML) for a
86 * predefined name is what is expected (matches what is defined in
87 * the ACPI specification for this predefined name.)
89 ******************************************************************************/
92 acpi_ns_check_acpi_compliance(char *pathname,
93 struct acpi_namespace_node *node,
94 const union acpi_predefined_info *predefined)
97 u32 required_param_count;
99 if (!predefined || (node->flags & ANOBJ_EVALUATED)) {
103 /* Get the ACPI-required arg count from the predefined info table */
105 required_param_count =
106 METHOD_GET_ARG_COUNT(predefined->info.argument_list);
109 * If this object is not a control method, we can check if the ACPI
110 * spec requires that it be a method.
112 if (node->type != ACPI_TYPE_METHOD) {
113 if (required_param_count > 0) {
115 /* Object requires args, must be implemented as a method */
117 ACPI_BIOS_ERROR_PREDEFINED((AE_INFO, pathname,
119 "Object (%s) must be a control method with %u arguments",
120 acpi_ut_get_type_name(node->
122 required_param_count));
123 } else if (!required_param_count
124 && !predefined->info.expected_btypes) {
126 /* Object requires no args and no return value, must be a method */
128 ACPI_BIOS_ERROR_PREDEFINED((AE_INFO, pathname,
130 "Object (%s) must be a control method "
131 "with no arguments and no return value",
132 acpi_ut_get_type_name(node->
140 * This is a control method.
141 * Check that the ASL/AML-defined parameter count for this method
142 * matches the ACPI-required parameter count
144 * Some methods are allowed to have a "minimum" number of args (_SCP)
145 * because their definition in ACPI has changed over time.
147 * Note: These are BIOS errors in the declaration of the object
149 aml_param_count = node->object->method.param_count;
151 if (aml_param_count < required_param_count) {
152 ACPI_BIOS_ERROR_PREDEFINED((AE_INFO, pathname, ACPI_WARN_ALWAYS,
153 "Insufficient arguments - "
154 "ASL declared %u, ACPI requires %u",
156 required_param_count));
157 } else if ((aml_param_count > required_param_count)
158 && !(predefined->info.
159 argument_list & ARG_COUNT_IS_MINIMUM)) {
160 ACPI_BIOS_ERROR_PREDEFINED((AE_INFO, pathname, ACPI_WARN_ALWAYS,
161 "Excess arguments - "
162 "ASL declared %u, ACPI requires %u",
164 required_param_count));
168 /*******************************************************************************
170 * FUNCTION: acpi_ns_check_argument_count
172 * PARAMETERS: pathname - Full pathname to the node (for error msgs)
173 * node - Namespace node for the method/object
174 * user_param_count - Number of args passed in by the caller
175 * predefined - Pointer to entry in predefined name table
179 * DESCRIPTION: Check that incoming argument count matches the declared
180 * parameter count (in the ASL/AML) for an object.
182 ******************************************************************************/
185 acpi_ns_check_argument_count(char *pathname,
186 struct acpi_namespace_node *node,
187 u32 user_param_count,
188 const union acpi_predefined_info *predefined)
191 u32 required_param_count;
193 if (node->flags & ANOBJ_EVALUATED) {
199 * Not a predefined name. Check the incoming user argument count
200 * against the count that is specified in the method/object.
202 if (node->type != ACPI_TYPE_METHOD) {
203 if (user_param_count) {
204 ACPI_INFO_PREDEFINED((AE_INFO, pathname,
206 "%u arguments were passed to a non-method ACPI object (%s)",
208 acpi_ut_get_type_name
216 * This is a control method. Check the parameter count.
217 * We can only check the incoming argument count against the
218 * argument count declared for the method in the ASL/AML.
220 * Emit a message if too few or too many arguments have been passed
223 * Note: Too many arguments will not cause the method to
224 * fail. However, the method will fail if there are too few
225 * arguments and the method attempts to use one of the missing ones.
227 aml_param_count = node->object->method.param_count;
229 if (user_param_count < aml_param_count) {
230 ACPI_WARN_PREDEFINED((AE_INFO, pathname,
232 "Insufficient arguments - "
233 "Caller passed %u, method requires %u",
236 } else if (user_param_count > aml_param_count) {
237 ACPI_INFO_PREDEFINED((AE_INFO, pathname,
239 "Excess arguments - "
240 "Caller passed %u, method requires %u",
249 * This is a predefined name. Validate the user-supplied parameter
250 * count against the ACPI specification. We don't validate against
251 * the method itself because what is important here is that the
252 * caller is in conformance with the spec. (The arg count for the
253 * method was checked against the ACPI spec earlier.)
255 * Some methods are allowed to have a "minimum" number of args (_SCP)
256 * because their definition in ACPI has changed over time.
258 required_param_count =
259 METHOD_GET_ARG_COUNT(predefined->info.argument_list);
261 if (user_param_count < required_param_count) {
262 ACPI_WARN_PREDEFINED((AE_INFO, pathname, ACPI_WARN_ALWAYS,
263 "Insufficient arguments - "
264 "Caller passed %u, ACPI requires %u",
265 user_param_count, required_param_count));
266 } else if ((user_param_count > required_param_count) &&
267 !(predefined->info.argument_list & ARG_COUNT_IS_MINIMUM)) {
268 ACPI_INFO_PREDEFINED((AE_INFO, pathname, ACPI_WARN_ALWAYS,
269 "Excess arguments - "
270 "Caller passed %u, ACPI requires %u",
271 user_param_count, required_param_count));