1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 2 /****************************************************************************** 3 * 4 * Module Name: utosi - Support for the _OSI predefined control method 5 * 6 * Copyright (C) 2000 - 2018, Intel Corp. 7 * 8 *****************************************************************************/ 9 10 #include <acpi/acpi.h> 11 #include "accommon.h" 12 13 #define _COMPONENT ACPI_UTILITIES 14 ACPI_MODULE_NAME("utosi") 15 16 /****************************************************************************** 17 * 18 * ACPICA policy for new _OSI strings: 19 * 20 * It is the stated policy of ACPICA that new _OSI strings will be integrated 21 * into this module as soon as possible after they are defined. It is strongly 22 * recommended that all ACPICA hosts mirror this policy and integrate any 23 * changes to this module as soon as possible. There are several historical 24 * reasons behind this policy: 25 * 26 * 1) New BIOSs tend to test only the case where the host responds TRUE to 27 * the latest version of Windows, which would respond to the latest/newest 28 * _OSI string. Not responding TRUE to the latest version of Windows will 29 * risk executing untested code paths throughout the DSDT and SSDTs. 30 * 31 * 2) If a new _OSI string is recognized only after a significant delay, this 32 * has the potential to cause problems on existing working machines because 33 * of the possibility that a new and different path through the ASL code 34 * will be executed. 35 * 36 * 3) New _OSI strings are tending to come out about once per year. A delay 37 * in recognizing a new string for a significant amount of time risks the 38 * release of another string which only compounds the initial problem. 39 * 40 *****************************************************************************/ 41 /* 42 * Strings supported by the _OSI predefined control method (which is 43 * implemented internally within this module.) 44 * 45 * March 2009: Removed "Linux" as this host no longer wants to respond true 46 * for this string. Basically, the only safe OS strings are windows-related 47 * and in many or most cases represent the only test path within the 48 * BIOS-provided ASL code. 49 * 50 * The last element of each entry is used to track the newest version of 51 * Windows that the BIOS has requested. 52 */ 53 static struct acpi_interface_info acpi_default_supported_interfaces[] = { 54 /* Operating System Vendor Strings */ 55 56 {"Windows 2000", NULL, 0, ACPI_OSI_WIN_2000}, /* Windows 2000 */ 57 {"Windows 2001", NULL, 0, ACPI_OSI_WIN_XP}, /* Windows XP */ 58 {"Windows 2001 SP1", NULL, 0, ACPI_OSI_WIN_XP_SP1}, /* Windows XP SP1 */ 59 {"Windows 2001.1", NULL, 0, ACPI_OSI_WINSRV_2003}, /* Windows Server 2003 */ 60 {"Windows 2001 SP2", NULL, 0, ACPI_OSI_WIN_XP_SP2}, /* Windows XP SP2 */ 61 {"Windows 2001.1 SP1", NULL, 0, ACPI_OSI_WINSRV_2003_SP1}, /* Windows Server 2003 SP1 - Added 03/2006 */ 62 {"Windows 2006", NULL, 0, ACPI_OSI_WIN_VISTA}, /* Windows vista - Added 03/2006 */ 63 {"Windows 2006.1", NULL, 0, ACPI_OSI_WINSRV_2008}, /* Windows Server 2008 - Added 09/2009 */ 64 {"Windows 2006 SP1", NULL, 0, ACPI_OSI_WIN_VISTA_SP1}, /* Windows Vista SP1 - Added 09/2009 */ 65 {"Windows 2006 SP2", NULL, 0, ACPI_OSI_WIN_VISTA_SP2}, /* Windows Vista SP2 - Added 09/2010 */ 66 {"Windows 2009", NULL, 0, ACPI_OSI_WIN_7}, /* Windows 7 and Server 2008 R2 - Added 09/2009 */ 67 {"Windows 2012", NULL, 0, ACPI_OSI_WIN_8}, /* Windows 8 and Server 2012 - Added 08/2012 */ 68 {"Windows 2013", NULL, 0, ACPI_OSI_WIN_8}, /* Windows 8.1 and Server 2012 R2 - Added 01/2014 */ 69 {"Windows 2015", NULL, 0, ACPI_OSI_WIN_10}, /* Windows 10 - Added 03/2015 */ 70 {"Windows 2016", NULL, 0, ACPI_OSI_WIN_10_RS1}, /* Windows 10 version 1607 - Added 12/2017 */ 71 {"Windows 2017", NULL, 0, ACPI_OSI_WIN_10_RS2}, /* Windows 10 version 1703 - Added 12/2017 */ 72 73 /* Feature Group Strings */ 74 75 {"Extended Address Space Descriptor", NULL, ACPI_OSI_FEATURE, 0}, 76 77 /* 78 * All "optional" feature group strings (features that are implemented 79 * by the host) should be dynamically modified to VALID by the host via 80 * acpi_install_interface or acpi_update_interfaces. Such optional feature 81 * group strings are set as INVALID by default here. 82 */ 83 84 {"Module Device", NULL, ACPI_OSI_OPTIONAL_FEATURE, 0}, 85 {"Processor Device", NULL, ACPI_OSI_OPTIONAL_FEATURE, 0}, 86 {"3.0 Thermal Model", NULL, ACPI_OSI_OPTIONAL_FEATURE, 0}, 87 {"3.0 _SCP Extensions", NULL, ACPI_OSI_OPTIONAL_FEATURE, 0}, 88 {"Processor Aggregator Device", NULL, ACPI_OSI_OPTIONAL_FEATURE, 0} 89 }; 90 91 /******************************************************************************* 92 * 93 * FUNCTION: acpi_ut_initialize_interfaces 94 * 95 * PARAMETERS: None 96 * 97 * RETURN: Status 98 * 99 * DESCRIPTION: Initialize the global _OSI supported interfaces list 100 * 101 ******************************************************************************/ 102 103 acpi_status acpi_ut_initialize_interfaces(void) 104 { 105 acpi_status status; 106 u32 i; 107 108 status = acpi_os_acquire_mutex(acpi_gbl_osi_mutex, ACPI_WAIT_FOREVER); 109 if (ACPI_FAILURE(status)) { 110 return (status); 111 } 112 113 acpi_gbl_supported_interfaces = acpi_default_supported_interfaces; 114 115 /* Link the static list of supported interfaces */ 116 117 for (i = 0; 118 i < (ACPI_ARRAY_LENGTH(acpi_default_supported_interfaces) - 1); 119 i++) { 120 acpi_default_supported_interfaces[i].next = 121 &acpi_default_supported_interfaces[(acpi_size)i + 1]; 122 } 123 124 acpi_os_release_mutex(acpi_gbl_osi_mutex); 125 return (AE_OK); 126 } 127 128 /******************************************************************************* 129 * 130 * FUNCTION: acpi_ut_interface_terminate 131 * 132 * PARAMETERS: None 133 * 134 * RETURN: Status 135 * 136 * DESCRIPTION: Delete all interfaces in the global list. Sets 137 * acpi_gbl_supported_interfaces to NULL. 138 * 139 ******************************************************************************/ 140 141 acpi_status acpi_ut_interface_terminate(void) 142 { 143 acpi_status status; 144 struct acpi_interface_info *next_interface; 145 146 status = acpi_os_acquire_mutex(acpi_gbl_osi_mutex, ACPI_WAIT_FOREVER); 147 if (ACPI_FAILURE(status)) { 148 return (status); 149 } 150 151 next_interface = acpi_gbl_supported_interfaces; 152 while (next_interface) { 153 acpi_gbl_supported_interfaces = next_interface->next; 154 155 if (next_interface->flags & ACPI_OSI_DYNAMIC) { 156 157 /* Only interfaces added at runtime can be freed */ 158 159 ACPI_FREE(next_interface->name); 160 ACPI_FREE(next_interface); 161 } else { 162 /* Interface is in static list. Reset it to invalid or valid. */ 163 164 if (next_interface->flags & ACPI_OSI_DEFAULT_INVALID) { 165 next_interface->flags |= ACPI_OSI_INVALID; 166 } else { 167 next_interface->flags &= ~ACPI_OSI_INVALID; 168 } 169 } 170 171 next_interface = acpi_gbl_supported_interfaces; 172 } 173 174 acpi_os_release_mutex(acpi_gbl_osi_mutex); 175 return (AE_OK); 176 } 177 178 /******************************************************************************* 179 * 180 * FUNCTION: acpi_ut_install_interface 181 * 182 * PARAMETERS: interface_name - The interface to install 183 * 184 * RETURN: Status 185 * 186 * DESCRIPTION: Install the interface into the global interface list. 187 * Caller MUST hold acpi_gbl_osi_mutex 188 * 189 ******************************************************************************/ 190 191 acpi_status acpi_ut_install_interface(acpi_string interface_name) 192 { 193 struct acpi_interface_info *interface_info; 194 195 /* Allocate info block and space for the name string */ 196 197 interface_info = 198 ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_interface_info)); 199 if (!interface_info) { 200 return (AE_NO_MEMORY); 201 } 202 203 interface_info->name = ACPI_ALLOCATE_ZEROED(strlen(interface_name) + 1); 204 if (!interface_info->name) { 205 ACPI_FREE(interface_info); 206 return (AE_NO_MEMORY); 207 } 208 209 /* Initialize new info and insert at the head of the global list */ 210 211 strcpy(interface_info->name, interface_name); 212 interface_info->flags = ACPI_OSI_DYNAMIC; 213 interface_info->next = acpi_gbl_supported_interfaces; 214 215 acpi_gbl_supported_interfaces = interface_info; 216 return (AE_OK); 217 } 218 219 /******************************************************************************* 220 * 221 * FUNCTION: acpi_ut_remove_interface 222 * 223 * PARAMETERS: interface_name - The interface to remove 224 * 225 * RETURN: Status 226 * 227 * DESCRIPTION: Remove the interface from the global interface list. 228 * Caller MUST hold acpi_gbl_osi_mutex 229 * 230 ******************************************************************************/ 231 232 acpi_status acpi_ut_remove_interface(acpi_string interface_name) 233 { 234 struct acpi_interface_info *previous_interface; 235 struct acpi_interface_info *next_interface; 236 237 previous_interface = next_interface = acpi_gbl_supported_interfaces; 238 while (next_interface) { 239 if (!strcmp(interface_name, next_interface->name)) { 240 /* 241 * Found: name is in either the static list 242 * or was added at runtime 243 */ 244 if (next_interface->flags & ACPI_OSI_DYNAMIC) { 245 246 /* Interface was added dynamically, remove and free it */ 247 248 if (previous_interface == next_interface) { 249 acpi_gbl_supported_interfaces = 250 next_interface->next; 251 } else { 252 previous_interface->next = 253 next_interface->next; 254 } 255 256 ACPI_FREE(next_interface->name); 257 ACPI_FREE(next_interface); 258 } else { 259 /* 260 * Interface is in static list. If marked invalid, then 261 * it does not actually exist. Else, mark it invalid. 262 */ 263 if (next_interface->flags & ACPI_OSI_INVALID) { 264 return (AE_NOT_EXIST); 265 } 266 267 next_interface->flags |= ACPI_OSI_INVALID; 268 } 269 270 return (AE_OK); 271 } 272 273 previous_interface = next_interface; 274 next_interface = next_interface->next; 275 } 276 277 /* Interface was not found */ 278 279 return (AE_NOT_EXIST); 280 } 281 282 /******************************************************************************* 283 * 284 * FUNCTION: acpi_ut_update_interfaces 285 * 286 * PARAMETERS: action - Actions to be performed during the 287 * update 288 * 289 * RETURN: Status 290 * 291 * DESCRIPTION: Update _OSI interface strings, disabling or enabling OS vendor 292 * strings or/and feature group strings. 293 * Caller MUST hold acpi_gbl_osi_mutex 294 * 295 ******************************************************************************/ 296 297 acpi_status acpi_ut_update_interfaces(u8 action) 298 { 299 struct acpi_interface_info *next_interface; 300 301 next_interface = acpi_gbl_supported_interfaces; 302 while (next_interface) { 303 if (((next_interface->flags & ACPI_OSI_FEATURE) && 304 (action & ACPI_FEATURE_STRINGS)) || 305 (!(next_interface->flags & ACPI_OSI_FEATURE) && 306 (action & ACPI_VENDOR_STRINGS))) { 307 if (action & ACPI_DISABLE_INTERFACES) { 308 309 /* Mark the interfaces as invalid */ 310 311 next_interface->flags |= ACPI_OSI_INVALID; 312 } else { 313 /* Mark the interfaces as valid */ 314 315 next_interface->flags &= ~ACPI_OSI_INVALID; 316 } 317 } 318 319 next_interface = next_interface->next; 320 } 321 322 return (AE_OK); 323 } 324 325 /******************************************************************************* 326 * 327 * FUNCTION: acpi_ut_get_interface 328 * 329 * PARAMETERS: interface_name - The interface to find 330 * 331 * RETURN: struct acpi_interface_info if found. NULL if not found. 332 * 333 * DESCRIPTION: Search for the specified interface name in the global list. 334 * Caller MUST hold acpi_gbl_osi_mutex 335 * 336 ******************************************************************************/ 337 338 struct acpi_interface_info *acpi_ut_get_interface(acpi_string interface_name) 339 { 340 struct acpi_interface_info *next_interface; 341 342 next_interface = acpi_gbl_supported_interfaces; 343 while (next_interface) { 344 if (!strcmp(interface_name, next_interface->name)) { 345 return (next_interface); 346 } 347 348 next_interface = next_interface->next; 349 } 350 351 return (NULL); 352 } 353 354 /******************************************************************************* 355 * 356 * FUNCTION: acpi_ut_osi_implementation 357 * 358 * PARAMETERS: walk_state - Current walk state 359 * 360 * RETURN: Status 361 * Integer: TRUE (0) if input string is matched 362 * FALSE (-1) if string is not matched 363 * 364 * DESCRIPTION: Implementation of the _OSI predefined control method. When 365 * an invocation of _OSI is encountered in the system AML, 366 * control is transferred to this function. 367 * 368 * (August 2016) 369 * Note: _OSI is now defined to return "Ones" to indicate a match, for 370 * compatibility with other ACPI implementations. On a 32-bit DSDT, Ones 371 * is 0xFFFFFFFF. On a 64-bit DSDT, Ones is 0xFFFFFFFFFFFFFFFF 372 * (ACPI_UINT64_MAX). 373 * 374 * This function always returns ACPI_UINT64_MAX for TRUE, and later code 375 * will truncate this to 32 bits if necessary. 376 * 377 ******************************************************************************/ 378 379 acpi_status acpi_ut_osi_implementation(struct acpi_walk_state *walk_state) 380 { 381 union acpi_operand_object *string_desc; 382 union acpi_operand_object *return_desc; 383 struct acpi_interface_info *interface_info; 384 acpi_interface_handler interface_handler; 385 acpi_status status; 386 u64 return_value; 387 388 ACPI_FUNCTION_TRACE(ut_osi_implementation); 389 390 /* Validate the string input argument (from the AML caller) */ 391 392 string_desc = walk_state->arguments[0].object; 393 if (!string_desc || (string_desc->common.type != ACPI_TYPE_STRING)) { 394 return_ACPI_STATUS(AE_TYPE); 395 } 396 397 /* Create a return object */ 398 399 return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER); 400 if (!return_desc) { 401 return_ACPI_STATUS(AE_NO_MEMORY); 402 } 403 404 /* Default return value is 0, NOT SUPPORTED */ 405 406 return_value = 0; 407 status = acpi_os_acquire_mutex(acpi_gbl_osi_mutex, ACPI_WAIT_FOREVER); 408 if (ACPI_FAILURE(status)) { 409 acpi_ut_remove_reference(return_desc); 410 return_ACPI_STATUS(status); 411 } 412 413 /* Lookup the interface in the global _OSI list */ 414 415 interface_info = acpi_ut_get_interface(string_desc->string.pointer); 416 if (interface_info && !(interface_info->flags & ACPI_OSI_INVALID)) { 417 /* 418 * The interface is supported. 419 * Update the osi_data if necessary. We keep track of the latest 420 * version of Windows that has been requested by the BIOS. 421 */ 422 if (interface_info->value > acpi_gbl_osi_data) { 423 acpi_gbl_osi_data = interface_info->value; 424 } 425 426 return_value = ACPI_UINT64_MAX; 427 } 428 429 acpi_os_release_mutex(acpi_gbl_osi_mutex); 430 431 /* 432 * Invoke an optional _OSI interface handler. The host OS may wish 433 * to do some interface-specific handling. For example, warn about 434 * certain interfaces or override the true/false support value. 435 */ 436 interface_handler = acpi_gbl_interface_handler; 437 if (interface_handler) { 438 if (interface_handler 439 (string_desc->string.pointer, (u32)return_value)) { 440 return_value = ACPI_UINT64_MAX; 441 } 442 } 443 444 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INFO, 445 "ACPI: BIOS _OSI(\"%s\") is %ssupported\n", 446 string_desc->string.pointer, 447 return_value == 0 ? "not " : "")); 448 449 /* Complete the return object */ 450 451 return_desc->integer.value = return_value; 452 walk_state->return_desc = return_desc; 453 return_ACPI_STATUS(AE_OK); 454 } 455