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