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 - 2020, 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 /* No typechecking for ACPI_TYPE_ANY */
60 if ((user_arg_type
!= arg_type
) && (arg_type
!= ACPI_TYPE_ANY
)) {
61 ACPI_WARN_PREDEFINED((AE_INFO
, info
->full_pathname
,
63 "Argument #%u type mismatch - "
64 "Found [%s], ACPI requires [%s]",
68 acpi_ut_get_type_name(arg_type
)));
70 /* Prevent any additional typechecking for this method */
72 info
->node
->flags
|= ANOBJ_EVALUATED
;
77 /*******************************************************************************
79 * FUNCTION: acpi_ns_check_acpi_compliance
81 * PARAMETERS: pathname - Full pathname to the node (for error msgs)
82 * node - Namespace node for the method/object
83 * predefined - Pointer to entry in predefined name table
87 * DESCRIPTION: Check that the declared parameter count (in ASL/AML) for a
88 * predefined name is what is expected (matches what is defined in
89 * the ACPI specification for this predefined name.)
91 ******************************************************************************/
94 acpi_ns_check_acpi_compliance(char *pathname
,
95 struct acpi_namespace_node
*node
,
96 const union acpi_predefined_info
*predefined
)
99 u32 required_param_count
;
101 if (!predefined
|| (node
->flags
& ANOBJ_EVALUATED
)) {
105 /* Get the ACPI-required arg count from the predefined info table */
107 required_param_count
=
108 METHOD_GET_ARG_COUNT(predefined
->info
.argument_list
);
111 * If this object is not a control method, we can check if the ACPI
112 * spec requires that it be a method.
114 if (node
->type
!= ACPI_TYPE_METHOD
) {
115 if (required_param_count
> 0) {
117 /* Object requires args, must be implemented as a method */
119 ACPI_BIOS_ERROR_PREDEFINED((AE_INFO
, pathname
,
121 "Object (%s) must be a control method with %u arguments",
122 acpi_ut_get_type_name(node
->
124 required_param_count
));
125 } else if (!required_param_count
126 && !predefined
->info
.expected_btypes
) {
128 /* Object requires no args and no return value, must be a method */
130 ACPI_BIOS_ERROR_PREDEFINED((AE_INFO
, pathname
,
132 "Object (%s) must be a control method "
133 "with no arguments and no return value",
134 acpi_ut_get_type_name(node
->
142 * This is a control method.
143 * Check that the ASL/AML-defined parameter count for this method
144 * matches the ACPI-required parameter count
146 * Some methods are allowed to have a "minimum" number of args (_SCP)
147 * because their definition in ACPI has changed over time.
149 * Note: These are BIOS errors in the declaration of the object
151 aml_param_count
= node
->object
->method
.param_count
;
153 if (aml_param_count
< required_param_count
) {
154 ACPI_BIOS_ERROR_PREDEFINED((AE_INFO
, pathname
, ACPI_WARN_ALWAYS
,
155 "Insufficient arguments - "
156 "ASL declared %u, ACPI requires %u",
158 required_param_count
));
159 } else if ((aml_param_count
> required_param_count
)
160 && !(predefined
->info
.
161 argument_list
& ARG_COUNT_IS_MINIMUM
)) {
162 ACPI_BIOS_ERROR_PREDEFINED((AE_INFO
, pathname
, ACPI_WARN_ALWAYS
,
163 "Excess arguments - "
164 "ASL declared %u, ACPI requires %u",
166 required_param_count
));
170 /*******************************************************************************
172 * FUNCTION: acpi_ns_check_argument_count
174 * PARAMETERS: pathname - Full pathname to the node (for error msgs)
175 * node - Namespace node for the method/object
176 * user_param_count - Number of args passed in by the caller
177 * predefined - Pointer to entry in predefined name table
181 * DESCRIPTION: Check that incoming argument count matches the declared
182 * parameter count (in the ASL/AML) for an object.
184 ******************************************************************************/
187 acpi_ns_check_argument_count(char *pathname
,
188 struct acpi_namespace_node
*node
,
189 u32 user_param_count
,
190 const union acpi_predefined_info
*predefined
)
193 u32 required_param_count
;
195 if (node
->flags
& ANOBJ_EVALUATED
) {
201 * Not a predefined name. Check the incoming user argument count
202 * against the count that is specified in the method/object.
204 if (node
->type
!= ACPI_TYPE_METHOD
) {
205 if (user_param_count
) {
206 ACPI_INFO_PREDEFINED((AE_INFO
, pathname
,
208 "%u arguments were passed to a non-method ACPI object (%s)",
210 acpi_ut_get_type_name
218 * This is a control method. Check the parameter count.
219 * We can only check the incoming argument count against the
220 * argument count declared for the method in the ASL/AML.
222 * Emit a message if too few or too many arguments have been passed
225 * Note: Too many arguments will not cause the method to
226 * fail. However, the method will fail if there are too few
227 * arguments and the method attempts to use one of the missing ones.
229 aml_param_count
= node
->object
->method
.param_count
;
231 if (user_param_count
< aml_param_count
) {
232 ACPI_WARN_PREDEFINED((AE_INFO
, pathname
,
234 "Insufficient arguments - "
235 "Caller passed %u, method requires %u",
238 } else if (user_param_count
> aml_param_count
) {
239 ACPI_INFO_PREDEFINED((AE_INFO
, pathname
,
241 "Excess arguments - "
242 "Caller passed %u, method requires %u",
251 * This is a predefined name. Validate the user-supplied parameter
252 * count against the ACPI specification. We don't validate against
253 * the method itself because what is important here is that the
254 * caller is in conformance with the spec. (The arg count for the
255 * method was checked against the ACPI spec earlier.)
257 * Some methods are allowed to have a "minimum" number of args (_SCP)
258 * because their definition in ACPI has changed over time.
260 required_param_count
=
261 METHOD_GET_ARG_COUNT(predefined
->info
.argument_list
);
263 if (user_param_count
< required_param_count
) {
264 ACPI_WARN_PREDEFINED((AE_INFO
, pathname
, ACPI_WARN_ALWAYS
,
265 "Insufficient arguments - "
266 "Caller passed %u, ACPI requires %u",
267 user_param_count
, required_param_count
));
268 } else if ((user_param_count
> required_param_count
) &&
269 !(predefined
->info
.argument_list
& ARG_COUNT_IS_MINIMUM
)) {
270 ACPI_INFO_PREDEFINED((AE_INFO
, pathname
, ACPI_WARN_ALWAYS
,
271 "Excess arguments - "
272 "Caller passed %u, ACPI requires %u",
273 user_param_count
, required_param_count
));