Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
0002 /******************************************************************************
0003  *
0004  * Module Name: nsarguments - Validation of args for ACPI predefined methods
0005  *
0006  * Copyright (C) 2000 - 2022, Intel Corp.
0007  *
0008  *****************************************************************************/
0009 
0010 #include <acpi/acpi.h>
0011 #include "accommon.h"
0012 #include "acnamesp.h"
0013 #include "acpredef.h"
0014 
0015 #define _COMPONENT          ACPI_NAMESPACE
0016 ACPI_MODULE_NAME("nsarguments")
0017 
0018 /*******************************************************************************
0019  *
0020  * FUNCTION:    acpi_ns_check_argument_types
0021  *
0022  * PARAMETERS:  info            - Method execution information block
0023  *
0024  * RETURN:      None
0025  *
0026  * DESCRIPTION: Check the incoming argument count and all argument types
0027  *              against the argument type list for a predefined name.
0028  *
0029  ******************************************************************************/
0030 void acpi_ns_check_argument_types(struct acpi_evaluate_info *info)
0031 {
0032     u16 arg_type_list;
0033     u8 arg_count;
0034     u8 arg_type;
0035     u8 user_arg_type;
0036     u32 i;
0037 
0038     /*
0039      * If not a predefined name, cannot typecheck args, because
0040      * we have no idea what argument types are expected.
0041      * Also, ignore typecheck if warnings/errors if this method
0042      * has already been evaluated at least once -- in order
0043      * to suppress repetitive messages.
0044      */
0045     if (!info->predefined || (info->node->flags & ANOBJ_EVALUATED)) {
0046         return;
0047     }
0048 
0049     arg_type_list = info->predefined->info.argument_list;
0050     arg_count = METHOD_GET_ARG_COUNT(arg_type_list);
0051 
0052     /* Typecheck all arguments */
0053 
0054     for (i = 0; ((i < arg_count) && (i < info->param_count)); i++) {
0055         arg_type = METHOD_GET_NEXT_TYPE(arg_type_list);
0056         user_arg_type = info->parameters[i]->common.type;
0057 
0058         /* No typechecking for ACPI_TYPE_ANY */
0059 
0060         if ((user_arg_type != arg_type) && (arg_type != ACPI_TYPE_ANY)) {
0061             ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
0062                           ACPI_WARN_ALWAYS,
0063                           "Argument #%u type mismatch - "
0064                           "Found [%s], ACPI requires [%s]",
0065                           (i + 1),
0066                           acpi_ut_get_type_name
0067                           (user_arg_type),
0068                           acpi_ut_get_type_name(arg_type)));
0069 
0070             /* Prevent any additional typechecking for this method */
0071 
0072             info->node->flags |= ANOBJ_EVALUATED;
0073         }
0074     }
0075 }
0076 
0077 /*******************************************************************************
0078  *
0079  * FUNCTION:    acpi_ns_check_acpi_compliance
0080  *
0081  * PARAMETERS:  pathname        - Full pathname to the node (for error msgs)
0082  *              node            - Namespace node for the method/object
0083  *              predefined      - Pointer to entry in predefined name table
0084  *
0085  * RETURN:      None
0086  *
0087  * DESCRIPTION: Check that the declared parameter count (in ASL/AML) for a
0088  *              predefined name is what is expected (matches what is defined in
0089  *              the ACPI specification for this predefined name.)
0090  *
0091  ******************************************************************************/
0092 
0093 void
0094 acpi_ns_check_acpi_compliance(char *pathname,
0095                   struct acpi_namespace_node *node,
0096                   const union acpi_predefined_info *predefined)
0097 {
0098     u32 aml_param_count;
0099     u32 required_param_count;
0100 
0101     if (!predefined || (node->flags & ANOBJ_EVALUATED)) {
0102         return;
0103     }
0104 
0105     /* Get the ACPI-required arg count from the predefined info table */
0106 
0107     required_param_count =
0108         METHOD_GET_ARG_COUNT(predefined->info.argument_list);
0109 
0110     /*
0111      * If this object is not a control method, we can check if the ACPI
0112      * spec requires that it be a method.
0113      */
0114     if (node->type != ACPI_TYPE_METHOD) {
0115         if (required_param_count > 0) {
0116 
0117             /* Object requires args, must be implemented as a method */
0118 
0119             ACPI_BIOS_ERROR_PREDEFINED((AE_INFO, pathname,
0120                             ACPI_WARN_ALWAYS,
0121                             "Object (%s) must be a control method with %u arguments",
0122                             acpi_ut_get_type_name(node->
0123                                       type),
0124                             required_param_count));
0125         } else if (!required_param_count
0126                && !predefined->info.expected_btypes) {
0127 
0128             /* Object requires no args and no return value, must be a method */
0129 
0130             ACPI_BIOS_ERROR_PREDEFINED((AE_INFO, pathname,
0131                             ACPI_WARN_ALWAYS,
0132                             "Object (%s) must be a control method "
0133                             "with no arguments and no return value",
0134                             acpi_ut_get_type_name(node->
0135                                       type)));
0136         }
0137 
0138         return;
0139     }
0140 
0141     /*
0142      * This is a control method.
0143      * Check that the ASL/AML-defined parameter count for this method
0144      * matches the ACPI-required parameter count
0145      *
0146      * Some methods are allowed to have a "minimum" number of args (_SCP)
0147      * because their definition in ACPI has changed over time.
0148      *
0149      * Note: These are BIOS errors in the declaration of the object
0150      */
0151     aml_param_count = node->object->method.param_count;
0152 
0153     if (aml_param_count < required_param_count) {
0154         ACPI_BIOS_ERROR_PREDEFINED((AE_INFO, pathname, ACPI_WARN_ALWAYS,
0155                         "Insufficient arguments - "
0156                         "ASL declared %u, ACPI requires %u",
0157                         aml_param_count,
0158                         required_param_count));
0159     } else if ((aml_param_count > required_param_count)
0160            && !(predefined->info.
0161             argument_list & ARG_COUNT_IS_MINIMUM)) {
0162         ACPI_BIOS_ERROR_PREDEFINED((AE_INFO, pathname, ACPI_WARN_ALWAYS,
0163                         "Excess arguments - "
0164                         "ASL declared %u, ACPI requires %u",
0165                         aml_param_count,
0166                         required_param_count));
0167     }
0168 }
0169 
0170 /*******************************************************************************
0171  *
0172  * FUNCTION:    acpi_ns_check_argument_count
0173  *
0174  * PARAMETERS:  pathname        - Full pathname to the node (for error msgs)
0175  *              node            - Namespace node for the method/object
0176  *              user_param_count - Number of args passed in by the caller
0177  *              predefined      - Pointer to entry in predefined name table
0178  *
0179  * RETURN:      None
0180  *
0181  * DESCRIPTION: Check that incoming argument count matches the declared
0182  *              parameter count (in the ASL/AML) for an object.
0183  *
0184  ******************************************************************************/
0185 
0186 void
0187 acpi_ns_check_argument_count(char *pathname,
0188                  struct acpi_namespace_node *node,
0189                  u32 user_param_count,
0190                  const union acpi_predefined_info *predefined)
0191 {
0192     u32 aml_param_count;
0193     u32 required_param_count;
0194 
0195     if (node->flags & ANOBJ_EVALUATED) {
0196         return;
0197     }
0198 
0199     if (!predefined) {
0200         /*
0201          * Not a predefined name. Check the incoming user argument count
0202          * against the count that is specified in the method/object.
0203          */
0204         if (node->type != ACPI_TYPE_METHOD) {
0205             if (user_param_count) {
0206                 ACPI_INFO_PREDEFINED((AE_INFO, pathname,
0207                               ACPI_WARN_ALWAYS,
0208                               "%u arguments were passed to a non-method ACPI object (%s)",
0209                               user_param_count,
0210                               acpi_ut_get_type_name
0211                               (node->type)));
0212             }
0213 
0214             return;
0215         }
0216 
0217         /*
0218          * This is a control method. Check the parameter count.
0219          * We can only check the incoming argument count against the
0220          * argument count declared for the method in the ASL/AML.
0221          *
0222          * Emit a message if too few or too many arguments have been passed
0223          * by the caller.
0224          *
0225          * Note: Too many arguments will not cause the method to
0226          * fail. However, the method will fail if there are too few
0227          * arguments and the method attempts to use one of the missing ones.
0228          */
0229         aml_param_count = node->object->method.param_count;
0230 
0231         if (user_param_count < aml_param_count) {
0232             ACPI_WARN_PREDEFINED((AE_INFO, pathname,
0233                           ACPI_WARN_ALWAYS,
0234                           "Insufficient arguments - "
0235                           "Caller passed %u, method requires %u",
0236                           user_param_count,
0237                           aml_param_count));
0238         } else if (user_param_count > aml_param_count) {
0239             ACPI_INFO_PREDEFINED((AE_INFO, pathname,
0240                           ACPI_WARN_ALWAYS,
0241                           "Excess arguments - "
0242                           "Caller passed %u, method requires %u",
0243                           user_param_count,
0244                           aml_param_count));
0245         }
0246 
0247         return;
0248     }
0249 
0250     /*
0251      * This is a predefined name. Validate the user-supplied parameter
0252      * count against the ACPI specification. We don't validate against
0253      * the method itself because what is important here is that the
0254      * caller is in conformance with the spec. (The arg count for the
0255      * method was checked against the ACPI spec earlier.)
0256      *
0257      * Some methods are allowed to have a "minimum" number of args (_SCP)
0258      * because their definition in ACPI has changed over time.
0259      */
0260     required_param_count =
0261         METHOD_GET_ARG_COUNT(predefined->info.argument_list);
0262 
0263     if (user_param_count < required_param_count) {
0264         ACPI_WARN_PREDEFINED((AE_INFO, pathname, ACPI_WARN_ALWAYS,
0265                       "Insufficient arguments - "
0266                       "Caller passed %u, ACPI requires %u",
0267                       user_param_count, required_param_count));
0268     } else if ((user_param_count > required_param_count) &&
0269            !(predefined->info.argument_list & ARG_COUNT_IS_MINIMUM)) {
0270         ACPI_INFO_PREDEFINED((AE_INFO, pathname, ACPI_WARN_ALWAYS,
0271                       "Excess arguments - "
0272                       "Caller passed %u, ACPI requires %u",
0273                       user_param_count, required_param_count));
0274     }
0275 }