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.
44 #include <acpi/acpi.h>
49 #define _COMPONENT ACPI_NAMESPACE
50 ACPI_MODULE_NAME("nsarguments")
52 /*******************************************************************************
54 * FUNCTION: acpi_ns_check_argument_types
56 * PARAMETERS: info - Method execution information block
60 * DESCRIPTION: Check the incoming argument count and all argument types
61 * against the argument type list for a predefined name.
63 ******************************************************************************/
64 void acpi_ns_check_argument_types(struct acpi_evaluate_info
*info
)
72 /* If not a predefined name, cannot typecheck args */
74 if (!info
->predefined
) {
78 arg_type_list
= info
->predefined
->info
.argument_list
;
79 arg_count
= METHOD_GET_ARG_COUNT(arg_type_list
);
81 /* Typecheck all arguments */
83 for (i
= 0; ((i
< arg_count
) && (i
< info
->param_count
)); i
++) {
84 arg_type
= METHOD_GET_NEXT_TYPE(arg_type_list
);
85 user_arg_type
= info
->parameters
[i
]->common
.type
;
87 if (user_arg_type
!= arg_type
) {
88 ACPI_WARN_PREDEFINED((AE_INFO
, info
->full_pathname
,
90 "Argument #%u type mismatch - "
91 "Found [%s], ACPI requires [%s]",
95 acpi_ut_get_type_name(arg_type
)));
100 /*******************************************************************************
102 * FUNCTION: acpi_ns_check_acpi_compliance
104 * PARAMETERS: pathname - Full pathname to the node (for error msgs)
105 * node - Namespace node for the method/object
106 * predefined - Pointer to entry in predefined name table
110 * DESCRIPTION: Check that the declared parameter count (in ASL/AML) for a
111 * predefined name is what is expected (matches what is defined in
112 * the ACPI specification for this predefined name.)
114 ******************************************************************************/
117 acpi_ns_check_acpi_compliance(char *pathname
,
118 struct acpi_namespace_node
*node
,
119 const union acpi_predefined_info
*predefined
)
122 u32 required_param_count
;
128 /* Get the ACPI-required arg count from the predefined info table */
130 required_param_count
=
131 METHOD_GET_ARG_COUNT(predefined
->info
.argument_list
);
134 * If this object is not a control method, we can check if the ACPI
135 * spec requires that it be a method.
137 if (node
->type
!= ACPI_TYPE_METHOD
) {
138 if (required_param_count
> 0) {
140 /* Object requires args, must be implemented as a method */
142 ACPI_BIOS_ERROR_PREDEFINED((AE_INFO
, pathname
,
144 "Object (%s) must be a control method with %u arguments",
145 acpi_ut_get_type_name(node
->
147 required_param_count
));
148 } else if (!required_param_count
149 && !predefined
->info
.expected_btypes
) {
151 /* Object requires no args and no return value, must be a method */
153 ACPI_BIOS_ERROR_PREDEFINED((AE_INFO
, pathname
,
155 "Object (%s) must be a control method "
156 "with no arguments and no return value",
157 acpi_ut_get_type_name(node
->
165 * This is a control method.
166 * Check that the ASL/AML-defined parameter count for this method
167 * matches the ACPI-required parameter count
169 * Some methods are allowed to have a "minimum" number of args (_SCP)
170 * because their definition in ACPI has changed over time.
172 * Note: These are BIOS errors in the declaration of the object
174 aml_param_count
= node
->object
->method
.param_count
;
176 if (aml_param_count
< required_param_count
) {
177 ACPI_BIOS_ERROR_PREDEFINED((AE_INFO
, pathname
, ACPI_WARN_ALWAYS
,
178 "Insufficient arguments - "
179 "ASL declared %u, ACPI requires %u",
181 required_param_count
));
182 } else if ((aml_param_count
> required_param_count
)
183 && !(predefined
->info
.
184 argument_list
& ARG_COUNT_IS_MINIMUM
)) {
185 ACPI_BIOS_ERROR_PREDEFINED((AE_INFO
, pathname
, ACPI_WARN_ALWAYS
,
186 "Excess arguments - "
187 "ASL declared %u, ACPI requires %u",
189 required_param_count
));
193 /*******************************************************************************
195 * FUNCTION: acpi_ns_check_argument_count
197 * PARAMETERS: pathname - Full pathname to the node (for error msgs)
198 * node - Namespace node for the method/object
199 * user_param_count - Number of args passed in by the caller
200 * predefined - Pointer to entry in predefined name table
204 * DESCRIPTION: Check that incoming argument count matches the declared
205 * parameter count (in the ASL/AML) for an object.
207 ******************************************************************************/
210 acpi_ns_check_argument_count(char *pathname
,
211 struct acpi_namespace_node
*node
,
212 u32 user_param_count
,
213 const union acpi_predefined_info
*predefined
)
216 u32 required_param_count
;
220 * Not a predefined name. Check the incoming user argument count
221 * against the count that is specified in the method/object.
223 if (node
->type
!= ACPI_TYPE_METHOD
) {
224 if (user_param_count
) {
225 ACPI_INFO_PREDEFINED((AE_INFO
, pathname
,
227 "%u arguments were passed to a non-method ACPI object (%s)",
229 acpi_ut_get_type_name
237 * This is a control method. Check the parameter count.
238 * We can only check the incoming argument count against the
239 * argument count declared for the method in the ASL/AML.
241 * Emit a message if too few or too many arguments have been passed
244 * Note: Too many arguments will not cause the method to
245 * fail. However, the method will fail if there are too few
246 * arguments and the method attempts to use one of the missing ones.
248 aml_param_count
= node
->object
->method
.param_count
;
250 if (user_param_count
< aml_param_count
) {
251 ACPI_WARN_PREDEFINED((AE_INFO
, pathname
,
253 "Insufficient arguments - "
254 "Caller passed %u, method requires %u",
257 } else if (user_param_count
> aml_param_count
) {
258 ACPI_INFO_PREDEFINED((AE_INFO
, pathname
,
260 "Excess arguments - "
261 "Caller passed %u, method requires %u",
270 * This is a predefined name. Validate the user-supplied parameter
271 * count against the ACPI specification. We don't validate against
272 * the method itself because what is important here is that the
273 * caller is in conformance with the spec. (The arg count for the
274 * method was checked against the ACPI spec earlier.)
276 * Some methods are allowed to have a "minimum" number of args (_SCP)
277 * because their definition in ACPI has changed over time.
279 required_param_count
=
280 METHOD_GET_ARG_COUNT(predefined
->info
.argument_list
);
282 if (user_param_count
< required_param_count
) {
283 ACPI_WARN_PREDEFINED((AE_INFO
, pathname
, ACPI_WARN_ALWAYS
,
284 "Insufficient arguments - "
285 "Caller passed %u, ACPI requires %u",
286 user_param_count
, required_param_count
));
287 } else if ((user_param_count
> required_param_count
) &&
288 !(predefined
->info
.argument_list
& ARG_COUNT_IS_MINIMUM
)) {
289 ACPI_INFO_PREDEFINED((AE_INFO
, pathname
, ACPI_WARN_ALWAYS
,
290 "Excess arguments - "
291 "Caller passed %u, ACPI requires %u",
292 user_param_count
, required_param_count
));