^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Module Name: nspredef - Validation of ACPI predefined methods and objects
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2000 - 2020, Intel Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *****************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #define ACPI_CREATE_PREDEFINED_TABLE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <acpi/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include "accommon.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "acnamesp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include "acpredef.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define _COMPONENT ACPI_NAMESPACE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) ACPI_MODULE_NAME("nspredef")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * This module validates predefined ACPI objects that appear in the namespace,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * at the time they are evaluated (via acpi_evaluate_object). The purpose of this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * validation is to detect problems with BIOS-exposed predefined ACPI objects
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * before the results are returned to the ACPI-related drivers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * There are several areas that are validated:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * 1) The number of input arguments as defined by the method/object in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * ASL is validated against the ACPI specification.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * 2) The type of the return object (if any) is validated against the ACPI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * specification.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * 3) For returned package objects, the count of package elements is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * validated, as well as the type of each package element. Nested
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * packages are supported.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * For any problems found, a warning message is issued.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) /* Local prototypes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) static acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) acpi_ns_check_reference(struct acpi_evaluate_info *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) union acpi_operand_object *return_object);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static u32 acpi_ns_get_bitmapped_type(union acpi_operand_object *return_object);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * FUNCTION: acpi_ns_check_return_value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * PARAMETERS: node - Namespace node for the method/object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * info - Method execution information block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * user_param_count - Number of parameters actually passed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * return_status - Status from the object evaluation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * return_object_ptr - Pointer to the object returned from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * evaluation of a method or object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * DESCRIPTION: Check the value returned from a predefined name.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) acpi_ns_check_return_value(struct acpi_namespace_node *node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) struct acpi_evaluate_info *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) u32 user_param_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) acpi_status return_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) union acpi_operand_object **return_object_ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) const union acpi_predefined_info *predefined;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) /* If not a predefined name, we cannot validate the return object */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) predefined = info->predefined;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) if (!predefined) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) return (AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * If the method failed or did not actually return an object, we cannot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * validate the return object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) if ((return_status != AE_OK) && (return_status != AE_CTRL_RETURN_VALUE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) return (AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * Return value validation and possible repair.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * 1) Don't perform return value validation/repair if this feature
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * has been disabled via a global option.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) * 2) We have a return value, but if one wasn't expected, just exit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) * this is not a problem. For example, if the "Implicit Return"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) * feature is enabled, methods will always return a value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) * 3) If the return value can be of any type, then we cannot perform
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * any validation, just exit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) if (acpi_gbl_disable_auto_repair ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) (!predefined->info.expected_btypes) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) (predefined->info.expected_btypes == ACPI_RTYPE_ALL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) return (AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) * Check that the type of the main return object is what is expected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * for this predefined name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) status = acpi_ns_check_object_type(info, return_object_ptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) predefined->info.expected_btypes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) ACPI_NOT_PACKAGE_ELEMENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) * 4) If there is no return value and it is optional, just return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) * AE_OK (_WAK).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) if (!(*return_object_ptr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) * For returned Package objects, check the type of all sub-objects.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * Note: Package may have been newly created by call above.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) if ((*return_object_ptr)->common.type == ACPI_TYPE_PACKAGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) info->parent_package = *return_object_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) status = acpi_ns_check_package(info, return_object_ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) /* We might be able to fix some errors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) if ((status != AE_AML_OPERAND_TYPE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) (status != AE_AML_OPERAND_VALUE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) * The return object was OK, or it was successfully repaired above.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) * Now make some additional checks such as verifying that package
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) * objects are sorted correctly (if required) or buffer objects have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) * the correct data width (bytes vs. dwords). These repairs are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) * performed on a per-name basis, i.e., the code is specific to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) * particular predefined names.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) status = acpi_ns_complex_repairs(info, node, status, return_object_ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) * If the object validation failed or if we successfully repaired one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) * or more objects, mark the parent node to suppress further warning
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * messages during the next evaluation of the same method/object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) if (ACPI_FAILURE(status) || (info->return_flags & ACPI_OBJECT_REPAIRED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) node->flags |= ANOBJ_EVALUATED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) return (status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) * FUNCTION: acpi_ns_check_object_type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * PARAMETERS: info - Method execution information block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) * return_object_ptr - Pointer to the object returned from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) * evaluation of a method or object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) * expected_btypes - Bitmap of expected return type(s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * package_index - Index of object within parent package (if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) * applicable - ACPI_NOT_PACKAGE_ELEMENT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) * otherwise)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) * DESCRIPTION: Check the type of the return object against the expected object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) * type(s). Use of Btype allows multiple expected object types.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) acpi_ns_check_object_type(struct acpi_evaluate_info *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) union acpi_operand_object **return_object_ptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) u32 expected_btypes, u32 package_index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) union acpi_operand_object *return_object = *return_object_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) acpi_status status = AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) char type_buffer[96]; /* Room for 10 types */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) /* A Namespace node should not get here, but make sure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) if (return_object &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) ACPI_GET_DESCRIPTOR_TYPE(return_object) == ACPI_DESC_TYPE_NAMED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) info->node_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) "Invalid return type - Found a Namespace node [%4.4s] type %s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) return_object->node.name.ascii,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) acpi_ut_get_type_name(return_object->node.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) type)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) return (AE_AML_OPERAND_TYPE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) * Convert the object type (ACPI_TYPE_xxx) to a bitmapped object type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) * The bitmapped type allows multiple possible return types.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) * Note, the cases below must handle all of the possible types returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) * from all of the predefined names (including elements of returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) * packages)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) info->return_btype = acpi_ns_get_bitmapped_type(return_object);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) if (info->return_btype == ACPI_RTYPE_ANY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) /* Not one of the supported objects, must be incorrect */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) goto type_error_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) /* For reference objects, check that the reference type is correct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) if ((info->return_btype & expected_btypes) == ACPI_RTYPE_REFERENCE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) status = acpi_ns_check_reference(info, return_object);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) return (status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) /* Attempt simple repair of the returned object if necessary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) status = acpi_ns_simple_repair(info, expected_btypes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) package_index, return_object_ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) if (ACPI_SUCCESS(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) return (AE_OK); /* Successful repair */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) type_error_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) /* Create a string with all expected types for this predefined object */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) acpi_ut_get_expected_return_types(type_buffer, expected_btypes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) if (!return_object) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) info->node_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) "Expected return object of type %s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) type_buffer));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) } else if (package_index == ACPI_NOT_PACKAGE_ELEMENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) info->node_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) "Return type mismatch - found %s, expected %s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) acpi_ut_get_object_type_name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) (return_object), type_buffer));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) info->node_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) "Return Package type mismatch at index %u - "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) "found %s, expected %s", package_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) acpi_ut_get_object_type_name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) (return_object), type_buffer));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) return (AE_AML_OPERAND_TYPE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) * FUNCTION: acpi_ns_check_reference
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) * PARAMETERS: info - Method execution information block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) * return_object - Object returned from the evaluation of a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) * method or object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) * RETURN: Status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) * DESCRIPTION: Check a returned reference object for the correct reference
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) * type. The only reference type that can be returned from a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) * predefined method is a named reference. All others are invalid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) static acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) acpi_ns_check_reference(struct acpi_evaluate_info *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) union acpi_operand_object *return_object)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) * Check the reference object for the correct reference type (opcode).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) * The only type of reference that can be converted to a union acpi_object is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) * a reference to a named object (reference class: NAME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) if (return_object->reference.class == ACPI_REFCLASS_NAME) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) return (AE_OK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname, info->node_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) "Return type mismatch - unexpected reference object type [%s] %2.2X",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) acpi_ut_get_reference_name(return_object),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) return_object->reference.class));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) return (AE_AML_OPERAND_TYPE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) /*******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) * FUNCTION: acpi_ns_get_bitmapped_type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) * PARAMETERS: return_object - Object returned from method/obj evaluation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) * RETURN: Object return type. ACPI_RTYPE_ANY indicates that the object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) * type is not supported. ACPI_RTYPE_NONE indicates that no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) * object was returned (return_object is NULL).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) * DESCRIPTION: Convert object type into a bitmapped object return type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) static u32 acpi_ns_get_bitmapped_type(union acpi_operand_object *return_object)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) u32 return_btype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) if (!return_object) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) return (ACPI_RTYPE_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) /* Map acpi_object_type to internal bitmapped type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) switch (return_object->common.type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) case ACPI_TYPE_INTEGER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) return_btype = ACPI_RTYPE_INTEGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) case ACPI_TYPE_BUFFER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) return_btype = ACPI_RTYPE_BUFFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) case ACPI_TYPE_STRING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) return_btype = ACPI_RTYPE_STRING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) case ACPI_TYPE_PACKAGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) return_btype = ACPI_RTYPE_PACKAGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) case ACPI_TYPE_LOCAL_REFERENCE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) return_btype = ACPI_RTYPE_REFERENCE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) /* Not one of the supported objects, must be incorrect */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) return_btype = ACPI_RTYPE_ANY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) return (return_btype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) }