1 /****************************************************************************** 2 * 3 * Module Name: uteval - Object evaluation 4 * 5 *****************************************************************************/ 6 7 /* 8 * Copyright (C) 2000 - 2008, Intel Corp. 9 * All rights reserved. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 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. 25 * 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. 29 * 30 * NO WARRANTY 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. 42 */ 43 44 #include <acpi/acpi.h> 45 #include "accommon.h" 46 #include "acnamesp.h" 47 48 #define _COMPONENT ACPI_UTILITIES 49 ACPI_MODULE_NAME("uteval") 50 51 /* 52 * Strings supported by the _OSI predefined (internal) method. 53 * 54 * March 2009: Removed "Linux" as this host no longer wants to respond true 55 * for this string. Basically, the only safe OS strings are windows-related 56 * and in many or most cases represent the only test path within the 57 * BIOS-provided ASL code. 58 * 59 * The second element of each entry is used to track the newest version of 60 * Windows that the BIOS has requested. 61 */ 62 static struct acpi_interface_info acpi_interfaces_supported[] = { 63 /* Operating System Vendor Strings */ 64 65 {"Windows 2000", ACPI_OSI_WIN_2000}, /* Windows 2000 */ 66 {"Windows 2001", ACPI_OSI_WIN_XP}, /* Windows XP */ 67 {"Windows 2001 SP1", ACPI_OSI_WIN_XP_SP1}, /* Windows XP SP1 */ 68 {"Windows 2001.1", ACPI_OSI_WINSRV_2003}, /* Windows Server 2003 */ 69 {"Windows 2001 SP2", ACPI_OSI_WIN_XP_SP2}, /* Windows XP SP2 */ 70 {"Windows 2001.1 SP1", ACPI_OSI_WINSRV_2003_SP1}, /* Windows Server 2003 SP1 - Added 03/2006 */ 71 {"Windows 2006", ACPI_OSI_WIN_VISTA}, /* Windows Vista - Added 03/2006 */ 72 {"Windows 2006.1", ACPI_OSI_WINSRV_2008}, /* Windows Server 2008 - Added 09/2009 */ 73 {"Windows 2006 SP1", ACPI_OSI_WIN_VISTA_SP1}, /* Windows Vista SP1 - Added 09/2009 */ 74 {"Windows 2009", ACPI_OSI_WIN_7}, /* Windows 7 and Server 2008 R2 - Added 09/2009 */ 75 76 /* Feature Group Strings */ 77 78 {"Extended Address Space Descriptor", 0} 79 80 /* 81 * All "optional" feature group strings (features that are implemented 82 * by the host) should be implemented in the host version of 83 * acpi_os_validate_interface and should not be added here. 84 */ 85 }; 86 87 /******************************************************************************* 88 * 89 * FUNCTION: acpi_ut_osi_implementation 90 * 91 * PARAMETERS: walk_state - Current walk state 92 * 93 * RETURN: Status 94 * 95 * DESCRIPTION: Implementation of the _OSI predefined control method 96 * 97 ******************************************************************************/ 98 99 acpi_status acpi_ut_osi_implementation(struct acpi_walk_state *walk_state) 100 { 101 acpi_status status; 102 union acpi_operand_object *string_desc; 103 union acpi_operand_object *return_desc; 104 u32 return_value; 105 u32 i; 106 107 ACPI_FUNCTION_TRACE(ut_osi_implementation); 108 109 /* Validate the string input argument */ 110 111 string_desc = walk_state->arguments[0].object; 112 if (!string_desc || (string_desc->common.type != ACPI_TYPE_STRING)) { 113 return_ACPI_STATUS(AE_TYPE); 114 } 115 116 /* Create a return object */ 117 118 return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER); 119 if (!return_desc) { 120 return_ACPI_STATUS(AE_NO_MEMORY); 121 } 122 123 /* Default return value is 0, NOT SUPPORTED */ 124 125 return_value = 0; 126 127 /* Compare input string to static table of supported interfaces */ 128 129 for (i = 0; i < ACPI_ARRAY_LENGTH(acpi_interfaces_supported); i++) { 130 if (!ACPI_STRCMP(string_desc->string.pointer, 131 acpi_interfaces_supported[i].name)) { 132 /* 133 * The interface is supported. 134 * Update the osi_data if necessary. We keep track of the latest 135 * version of Windows that has been requested by the BIOS. 136 */ 137 if (acpi_interfaces_supported[i].value > 138 acpi_gbl_osi_data) { 139 acpi_gbl_osi_data = 140 acpi_interfaces_supported[i].value; 141 } 142 143 return_value = ACPI_UINT32_MAX; 144 goto exit; 145 } 146 } 147 148 /* 149 * Did not match the string in the static table, call the host OSL to 150 * check for a match with one of the optional strings (such as 151 * "Module Device", "3.0 Thermal Model", etc.) 152 */ 153 status = acpi_os_validate_interface(string_desc->string.pointer); 154 if (ACPI_SUCCESS(status)) { 155 156 /* The interface is supported */ 157 158 return_value = ACPI_UINT32_MAX; 159 } 160 161 exit: 162 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, 163 "ACPI: BIOS _OSI(%s) is %ssupported\n", 164 string_desc->string.pointer, return_value == 0 ? "not " : "")); 165 166 /* Complete the return value */ 167 168 return_desc->integer.value = return_value; 169 walk_state->return_desc = return_desc; 170 return_ACPI_STATUS (AE_OK); 171 } 172 173 /******************************************************************************* 174 * 175 * FUNCTION: acpi_osi_invalidate 176 * 177 * PARAMETERS: interface_string 178 * 179 * RETURN: Status 180 * 181 * DESCRIPTION: invalidate string in pre-defiend _OSI string list 182 * 183 ******************************************************************************/ 184 185 acpi_status acpi_osi_invalidate(char *interface) 186 { 187 int i; 188 189 for (i = 0; i < ACPI_ARRAY_LENGTH(acpi_interfaces_supported); i++) { 190 if (!ACPI_STRCMP(interface, acpi_interfaces_supported[i].name)) { 191 *acpi_interfaces_supported[i].name = '\0'; 192 return AE_OK; 193 } 194 } 195 return AE_NOT_FOUND; 196 } 197 198 /******************************************************************************* 199 * 200 * FUNCTION: acpi_ut_evaluate_object 201 * 202 * PARAMETERS: prefix_node - Starting node 203 * Path - Path to object from starting node 204 * expected_return_types - Bitmap of allowed return types 205 * return_desc - Where a return value is stored 206 * 207 * RETURN: Status 208 * 209 * DESCRIPTION: Evaluates a namespace object and verifies the type of the 210 * return object. Common code that simplifies accessing objects 211 * that have required return objects of fixed types. 212 * 213 * NOTE: Internal function, no parameter validation 214 * 215 ******************************************************************************/ 216 217 acpi_status 218 acpi_ut_evaluate_object(struct acpi_namespace_node *prefix_node, 219 char *path, 220 u32 expected_return_btypes, 221 union acpi_operand_object **return_desc) 222 { 223 struct acpi_evaluate_info *info; 224 acpi_status status; 225 u32 return_btype; 226 227 ACPI_FUNCTION_TRACE(ut_evaluate_object); 228 229 /* Allocate the evaluation information block */ 230 231 info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info)); 232 if (!info) { 233 return_ACPI_STATUS(AE_NO_MEMORY); 234 } 235 236 info->prefix_node = prefix_node; 237 info->pathname = path; 238 239 /* Evaluate the object/method */ 240 241 status = acpi_ns_evaluate(info); 242 if (ACPI_FAILURE(status)) { 243 if (status == AE_NOT_FOUND) { 244 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, 245 "[%4.4s.%s] was not found\n", 246 acpi_ut_get_node_name(prefix_node), 247 path)); 248 } else { 249 ACPI_ERROR_METHOD("Method execution failed", 250 prefix_node, path, status); 251 } 252 253 goto cleanup; 254 } 255 256 /* Did we get a return object? */ 257 258 if (!info->return_object) { 259 if (expected_return_btypes) { 260 ACPI_ERROR_METHOD("No object was returned from", 261 prefix_node, path, AE_NOT_EXIST); 262 263 status = AE_NOT_EXIST; 264 } 265 266 goto cleanup; 267 } 268 269 /* Map the return object type to the bitmapped type */ 270 271 switch ((info->return_object)->common.type) { 272 case ACPI_TYPE_INTEGER: 273 return_btype = ACPI_BTYPE_INTEGER; 274 break; 275 276 case ACPI_TYPE_BUFFER: 277 return_btype = ACPI_BTYPE_BUFFER; 278 break; 279 280 case ACPI_TYPE_STRING: 281 return_btype = ACPI_BTYPE_STRING; 282 break; 283 284 case ACPI_TYPE_PACKAGE: 285 return_btype = ACPI_BTYPE_PACKAGE; 286 break; 287 288 default: 289 return_btype = 0; 290 break; 291 } 292 293 if ((acpi_gbl_enable_interpreter_slack) && (!expected_return_btypes)) { 294 /* 295 * We received a return object, but one was not expected. This can 296 * happen frequently if the "implicit return" feature is enabled. 297 * Just delete the return object and return AE_OK. 298 */ 299 acpi_ut_remove_reference(info->return_object); 300 goto cleanup; 301 } 302 303 /* Is the return object one of the expected types? */ 304 305 if (!(expected_return_btypes & return_btype)) { 306 ACPI_ERROR_METHOD("Return object type is incorrect", 307 prefix_node, path, AE_TYPE); 308 309 ACPI_ERROR((AE_INFO, 310 "Type returned from %s was incorrect: %s, expected Btypes: %X", 311 path, 312 acpi_ut_get_object_type_name(info->return_object), 313 expected_return_btypes)); 314 315 /* On error exit, we must delete the return object */ 316 317 acpi_ut_remove_reference(info->return_object); 318 status = AE_TYPE; 319 goto cleanup; 320 } 321 322 /* Object type is OK, return it */ 323 324 *return_desc = info->return_object; 325 326 cleanup: 327 ACPI_FREE(info); 328 return_ACPI_STATUS(status); 329 } 330 331 /******************************************************************************* 332 * 333 * FUNCTION: acpi_ut_evaluate_numeric_object 334 * 335 * PARAMETERS: object_name - Object name to be evaluated 336 * device_node - Node for the device 337 * Value - Where the value is returned 338 * 339 * RETURN: Status 340 * 341 * DESCRIPTION: Evaluates a numeric namespace object for a selected device 342 * and stores result in *Value. 343 * 344 * NOTE: Internal function, no parameter validation 345 * 346 ******************************************************************************/ 347 348 acpi_status 349 acpi_ut_evaluate_numeric_object(char *object_name, 350 struct acpi_namespace_node *device_node, 351 acpi_integer *value) 352 { 353 union acpi_operand_object *obj_desc; 354 acpi_status status; 355 356 ACPI_FUNCTION_TRACE(ut_evaluate_numeric_object); 357 358 status = acpi_ut_evaluate_object(device_node, object_name, 359 ACPI_BTYPE_INTEGER, &obj_desc); 360 if (ACPI_FAILURE(status)) { 361 return_ACPI_STATUS(status); 362 } 363 364 /* Get the returned Integer */ 365 366 *value = obj_desc->integer.value; 367 368 /* On exit, we must delete the return object */ 369 370 acpi_ut_remove_reference(obj_desc); 371 return_ACPI_STATUS(status); 372 } 373 374 /******************************************************************************* 375 * 376 * FUNCTION: acpi_ut_execute_STA 377 * 378 * PARAMETERS: device_node - Node for the device 379 * Flags - Where the status flags are returned 380 * 381 * RETURN: Status 382 * 383 * DESCRIPTION: Executes _STA for selected device and stores results in 384 * *Flags. 385 * 386 * NOTE: Internal function, no parameter validation 387 * 388 ******************************************************************************/ 389 390 acpi_status 391 acpi_ut_execute_STA(struct acpi_namespace_node *device_node, u32 * flags) 392 { 393 union acpi_operand_object *obj_desc; 394 acpi_status status; 395 396 ACPI_FUNCTION_TRACE(ut_execute_STA); 397 398 status = acpi_ut_evaluate_object(device_node, METHOD_NAME__STA, 399 ACPI_BTYPE_INTEGER, &obj_desc); 400 if (ACPI_FAILURE(status)) { 401 if (AE_NOT_FOUND == status) { 402 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, 403 "_STA on %4.4s was not found, assuming device is present\n", 404 acpi_ut_get_node_name(device_node))); 405 406 *flags = ACPI_UINT32_MAX; 407 status = AE_OK; 408 } 409 410 return_ACPI_STATUS(status); 411 } 412 413 /* Extract the status flags */ 414 415 *flags = (u32) obj_desc->integer.value; 416 417 /* On exit, we must delete the return object */ 418 419 acpi_ut_remove_reference(obj_desc); 420 return_ACPI_STATUS(status); 421 } 422 423 /******************************************************************************* 424 * 425 * FUNCTION: acpi_ut_execute_power_methods 426 * 427 * PARAMETERS: device_node - Node for the device 428 * method_names - Array of power method names 429 * method_count - Number of methods to execute 430 * out_values - Where the power method values are returned 431 * 432 * RETURN: Status, out_values 433 * 434 * DESCRIPTION: Executes the specified power methods for the device and returns 435 * the result(s). 436 * 437 * NOTE: Internal function, no parameter validation 438 * 439 ******************************************************************************/ 440 441 acpi_status 442 acpi_ut_execute_power_methods(struct acpi_namespace_node *device_node, 443 const char **method_names, 444 u8 method_count, u8 *out_values) 445 { 446 union acpi_operand_object *obj_desc; 447 acpi_status status; 448 acpi_status final_status = AE_NOT_FOUND; 449 u32 i; 450 451 ACPI_FUNCTION_TRACE(ut_execute_power_methods); 452 453 for (i = 0; i < method_count; i++) { 454 /* 455 * Execute the power method (_sx_d or _sx_w). The only allowable 456 * return type is an Integer. 457 */ 458 status = acpi_ut_evaluate_object(device_node, 459 ACPI_CAST_PTR(char, 460 method_names[i]), 461 ACPI_BTYPE_INTEGER, &obj_desc); 462 if (ACPI_SUCCESS(status)) { 463 out_values[i] = (u8)obj_desc->integer.value; 464 465 /* Delete the return object */ 466 467 acpi_ut_remove_reference(obj_desc); 468 final_status = AE_OK; /* At least one value is valid */ 469 continue; 470 } 471 472 out_values[i] = ACPI_UINT8_MAX; 473 if (status == AE_NOT_FOUND) { 474 continue; /* Ignore if not found */ 475 } 476 477 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, 478 "Failed %s on Device %4.4s, %s\n", 479 ACPI_CAST_PTR(char, method_names[i]), 480 acpi_ut_get_node_name(device_node), 481 acpi_format_exception(status))); 482 } 483 484 return_ACPI_STATUS(final_status); 485 } 486