utosi.c 16 KB

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