utosi.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. /******************************************************************************
  2. *
  3. * Module Name: utosi - Support for the _OSI predefined control method
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2013, 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. * Strings supported by the _OSI predefined control method (which is
  48. * implemented internally within this module.)
  49. *
  50. * March 2009: Removed "Linux" as this host no longer wants to respond true
  51. * for this string. Basically, the only safe OS strings are windows-related
  52. * and in many or most cases represent the only test path within the
  53. * BIOS-provided ASL code.
  54. *
  55. * The last element of each entry is used to track the newest version of
  56. * Windows that the BIOS has requested.
  57. */
  58. static struct acpi_interface_info acpi_default_supported_interfaces[] = {
  59. /* Operating System Vendor Strings */
  60. {"Windows 2000", NULL, 0, ACPI_OSI_WIN_2000}, /* Windows 2000 */
  61. {"Windows 2001", NULL, 0, ACPI_OSI_WIN_XP}, /* Windows XP */
  62. {"Windows 2001 SP1", NULL, 0, ACPI_OSI_WIN_XP_SP1}, /* Windows XP SP1 */
  63. {"Windows 2001.1", NULL, 0, ACPI_OSI_WINSRV_2003}, /* Windows Server 2003 */
  64. {"Windows 2001 SP2", NULL, 0, ACPI_OSI_WIN_XP_SP2}, /* Windows XP SP2 */
  65. {"Windows 2001.1 SP1", NULL, 0, ACPI_OSI_WINSRV_2003_SP1}, /* Windows Server 2003 SP1 - Added 03/2006 */
  66. {"Windows 2006", NULL, 0, ACPI_OSI_WIN_VISTA}, /* Windows vista - Added 03/2006 */
  67. {"Windows 2006.1", NULL, 0, ACPI_OSI_WINSRV_2008}, /* Windows Server 2008 - Added 09/2009 */
  68. {"Windows 2006 SP1", NULL, 0, ACPI_OSI_WIN_VISTA_SP1}, /* Windows Vista SP1 - Added 09/2009 */
  69. {"Windows 2006 SP2", NULL, 0, ACPI_OSI_WIN_VISTA_SP2}, /* Windows Vista SP2 - Added 09/2010 */
  70. {"Windows 2009", NULL, 0, ACPI_OSI_WIN_7}, /* Windows 7 and Server 2008 R2 - Added 09/2009 */
  71. {"Windows 2012", NULL, 0, ACPI_OSI_WIN_8}, /* Windows 8 and Server 2012 - Added 08/2012 */
  72. /* Feature Group Strings */
  73. {"Extended Address Space Descriptor", NULL, ACPI_OSI_FEATURE, 0},
  74. /*
  75. * All "optional" feature group strings (features that are implemented
  76. * by the host) should be dynamically modified to VALID by the host via
  77. * acpi_install_interface or acpi_update_interfaces. Such optional feature
  78. * group strings are set as INVALID by default here.
  79. */
  80. {"Module Device", NULL, ACPI_OSI_OPTIONAL_FEATURE, 0},
  81. {"Processor Device", NULL, ACPI_OSI_OPTIONAL_FEATURE, 0},
  82. {"3.0 Thermal Model", NULL, ACPI_OSI_OPTIONAL_FEATURE, 0},
  83. {"3.0 _SCP Extensions", NULL, ACPI_OSI_OPTIONAL_FEATURE, 0},
  84. {"Processor Aggregator Device", NULL, ACPI_OSI_OPTIONAL_FEATURE, 0}
  85. };
  86. /*******************************************************************************
  87. *
  88. * FUNCTION: acpi_ut_initialize_interfaces
  89. *
  90. * PARAMETERS: None
  91. *
  92. * RETURN: Status
  93. *
  94. * DESCRIPTION: Initialize the global _OSI supported interfaces list
  95. *
  96. ******************************************************************************/
  97. acpi_status acpi_ut_initialize_interfaces(void)
  98. {
  99. acpi_status status;
  100. u32 i;
  101. status = acpi_os_acquire_mutex(acpi_gbl_osi_mutex, ACPI_WAIT_FOREVER);
  102. if (ACPI_FAILURE(status)) {
  103. return (status);
  104. }
  105. acpi_gbl_supported_interfaces = acpi_default_supported_interfaces;
  106. /* Link the static list of supported interfaces */
  107. for (i = 0;
  108. i < (ACPI_ARRAY_LENGTH(acpi_default_supported_interfaces) - 1);
  109. i++) {
  110. acpi_default_supported_interfaces[i].next =
  111. &acpi_default_supported_interfaces[(acpi_size) i + 1];
  112. }
  113. acpi_os_release_mutex(acpi_gbl_osi_mutex);
  114. return (AE_OK);
  115. }
  116. /*******************************************************************************
  117. *
  118. * FUNCTION: acpi_ut_interface_terminate
  119. *
  120. * PARAMETERS: None
  121. *
  122. * RETURN: Status
  123. *
  124. * DESCRIPTION: Delete all interfaces in the global list. Sets
  125. * acpi_gbl_supported_interfaces to NULL.
  126. *
  127. ******************************************************************************/
  128. acpi_status acpi_ut_interface_terminate(void)
  129. {
  130. acpi_status status;
  131. struct acpi_interface_info *next_interface;
  132. status = acpi_os_acquire_mutex(acpi_gbl_osi_mutex, ACPI_WAIT_FOREVER);
  133. if (ACPI_FAILURE(status)) {
  134. return (status);
  135. }
  136. next_interface = acpi_gbl_supported_interfaces;
  137. while (next_interface) {
  138. acpi_gbl_supported_interfaces = next_interface->next;
  139. if (next_interface->flags & ACPI_OSI_DYNAMIC) {
  140. /* Only interfaces added at runtime can be freed */
  141. ACPI_FREE(next_interface->name);
  142. ACPI_FREE(next_interface);
  143. } else {
  144. /* Interface is in static list. Reset it to invalid or valid. */
  145. if (next_interface->flags & ACPI_OSI_DEFAULT_INVALID) {
  146. next_interface->flags |= ACPI_OSI_INVALID;
  147. } else {
  148. next_interface->flags &= ~ACPI_OSI_INVALID;
  149. }
  150. }
  151. next_interface = acpi_gbl_supported_interfaces;
  152. }
  153. acpi_os_release_mutex(acpi_gbl_osi_mutex);
  154. return (AE_OK);
  155. }
  156. /*******************************************************************************
  157. *
  158. * FUNCTION: acpi_ut_install_interface
  159. *
  160. * PARAMETERS: interface_name - The interface to install
  161. *
  162. * RETURN: Status
  163. *
  164. * DESCRIPTION: Install the interface into the global interface list.
  165. * Caller MUST hold acpi_gbl_osi_mutex
  166. *
  167. ******************************************************************************/
  168. acpi_status acpi_ut_install_interface(acpi_string interface_name)
  169. {
  170. struct acpi_interface_info *interface_info;
  171. /* Allocate info block and space for the name string */
  172. interface_info =
  173. ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_interface_info));
  174. if (!interface_info) {
  175. return (AE_NO_MEMORY);
  176. }
  177. interface_info->name =
  178. ACPI_ALLOCATE_ZEROED(ACPI_STRLEN(interface_name) + 1);
  179. if (!interface_info->name) {
  180. ACPI_FREE(interface_info);
  181. return (AE_NO_MEMORY);
  182. }
  183. /* Initialize new info and insert at the head of the global list */
  184. ACPI_STRCPY(interface_info->name, interface_name);
  185. interface_info->flags = ACPI_OSI_DYNAMIC;
  186. interface_info->next = acpi_gbl_supported_interfaces;
  187. acpi_gbl_supported_interfaces = interface_info;
  188. return (AE_OK);
  189. }
  190. /*******************************************************************************
  191. *
  192. * FUNCTION: acpi_ut_remove_interface
  193. *
  194. * PARAMETERS: interface_name - The interface to remove
  195. *
  196. * RETURN: Status
  197. *
  198. * DESCRIPTION: Remove the interface from the global interface list.
  199. * Caller MUST hold acpi_gbl_osi_mutex
  200. *
  201. ******************************************************************************/
  202. acpi_status acpi_ut_remove_interface(acpi_string interface_name)
  203. {
  204. struct acpi_interface_info *previous_interface;
  205. struct acpi_interface_info *next_interface;
  206. previous_interface = next_interface = acpi_gbl_supported_interfaces;
  207. while (next_interface) {
  208. if (!ACPI_STRCMP(interface_name, next_interface->name)) {
  209. /* Found: name is in either the static list or was added at runtime */
  210. if (next_interface->flags & ACPI_OSI_DYNAMIC) {
  211. /* Interface was added dynamically, remove and free it */
  212. if (previous_interface == next_interface) {
  213. acpi_gbl_supported_interfaces =
  214. next_interface->next;
  215. } else {
  216. previous_interface->next =
  217. next_interface->next;
  218. }
  219. ACPI_FREE(next_interface->name);
  220. ACPI_FREE(next_interface);
  221. } else {
  222. /*
  223. * Interface is in static list. If marked invalid, then it
  224. * does not actually exist. Else, mark it invalid.
  225. */
  226. if (next_interface->flags & ACPI_OSI_INVALID) {
  227. return (AE_NOT_EXIST);
  228. }
  229. next_interface->flags |= ACPI_OSI_INVALID;
  230. }
  231. return (AE_OK);
  232. }
  233. previous_interface = next_interface;
  234. next_interface = next_interface->next;
  235. }
  236. /* Interface was not found */
  237. return (AE_NOT_EXIST);
  238. }
  239. /*******************************************************************************
  240. *
  241. * FUNCTION: acpi_ut_update_interfaces
  242. *
  243. * PARAMETERS: action - Actions to be performed during the
  244. * update
  245. *
  246. * RETURN: Status
  247. *
  248. * DESCRIPTION: Update _OSI interface strings, disabling or enabling OS vendor
  249. * strings or/and feature group strings.
  250. * Caller MUST hold acpi_gbl_osi_mutex
  251. *
  252. ******************************************************************************/
  253. acpi_status acpi_ut_update_interfaces(u8 action)
  254. {
  255. struct acpi_interface_info *next_interface;
  256. next_interface = acpi_gbl_supported_interfaces;
  257. while (next_interface) {
  258. if (((next_interface->flags & ACPI_OSI_FEATURE) &&
  259. (action & ACPI_FEATURE_STRINGS)) ||
  260. (!(next_interface->flags & ACPI_OSI_FEATURE) &&
  261. (action & ACPI_VENDOR_STRINGS))) {
  262. if (action & ACPI_DISABLE_INTERFACES) {
  263. /* Mark the interfaces as invalid */
  264. next_interface->flags |= ACPI_OSI_INVALID;
  265. } else {
  266. /* Mark the interfaces as valid */
  267. next_interface->flags &= ~ACPI_OSI_INVALID;
  268. }
  269. }
  270. next_interface = next_interface->next;
  271. }
  272. return (AE_OK);
  273. }
  274. /*******************************************************************************
  275. *
  276. * FUNCTION: acpi_ut_get_interface
  277. *
  278. * PARAMETERS: interface_name - The interface to find
  279. *
  280. * RETURN: struct acpi_interface_info if found. NULL if not found.
  281. *
  282. * DESCRIPTION: Search for the specified interface name in the global list.
  283. * Caller MUST hold acpi_gbl_osi_mutex
  284. *
  285. ******************************************************************************/
  286. struct acpi_interface_info *acpi_ut_get_interface(acpi_string interface_name)
  287. {
  288. struct acpi_interface_info *next_interface;
  289. next_interface = acpi_gbl_supported_interfaces;
  290. while (next_interface) {
  291. if (!ACPI_STRCMP(interface_name, next_interface->name)) {
  292. return (next_interface);
  293. }
  294. next_interface = next_interface->next;
  295. }
  296. return (NULL);
  297. }
  298. /*******************************************************************************
  299. *
  300. * FUNCTION: acpi_ut_osi_implementation
  301. *
  302. * PARAMETERS: walk_state - Current walk state
  303. *
  304. * RETURN: Status
  305. *
  306. * DESCRIPTION: Implementation of the _OSI predefined control method. When
  307. * an invocation of _OSI is encountered in the system AML,
  308. * control is transferred to this function.
  309. *
  310. ******************************************************************************/
  311. acpi_status acpi_ut_osi_implementation(struct acpi_walk_state * walk_state)
  312. {
  313. union acpi_operand_object *string_desc;
  314. union acpi_operand_object *return_desc;
  315. struct acpi_interface_info *interface_info;
  316. acpi_interface_handler interface_handler;
  317. acpi_status status;
  318. u32 return_value;
  319. ACPI_FUNCTION_TRACE(ut_osi_implementation);
  320. /* Validate the string input argument (from the AML caller) */
  321. string_desc = walk_state->arguments[0].object;
  322. if (!string_desc || (string_desc->common.type != ACPI_TYPE_STRING)) {
  323. return_ACPI_STATUS(AE_TYPE);
  324. }
  325. /* Create a return object */
  326. return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
  327. if (!return_desc) {
  328. return_ACPI_STATUS(AE_NO_MEMORY);
  329. }
  330. /* Default return value is 0, NOT SUPPORTED */
  331. return_value = 0;
  332. status = acpi_os_acquire_mutex(acpi_gbl_osi_mutex, ACPI_WAIT_FOREVER);
  333. if (ACPI_FAILURE(status)) {
  334. acpi_ut_remove_reference(return_desc);
  335. return_ACPI_STATUS(status);
  336. }
  337. /* Lookup the interface in the global _OSI list */
  338. interface_info = acpi_ut_get_interface(string_desc->string.pointer);
  339. if (interface_info && !(interface_info->flags & ACPI_OSI_INVALID)) {
  340. /*
  341. * The interface is supported.
  342. * Update the osi_data if necessary. We keep track of the latest
  343. * version of Windows that has been requested by the BIOS.
  344. */
  345. if (interface_info->value > acpi_gbl_osi_data) {
  346. acpi_gbl_osi_data = interface_info->value;
  347. }
  348. return_value = ACPI_UINT32_MAX;
  349. }
  350. acpi_os_release_mutex(acpi_gbl_osi_mutex);
  351. /*
  352. * Invoke an optional _OSI interface handler. The host OS may wish
  353. * to do some interface-specific handling. For example, warn about
  354. * certain interfaces or override the true/false support value.
  355. */
  356. interface_handler = acpi_gbl_interface_handler;
  357. if (interface_handler) {
  358. return_value =
  359. interface_handler(string_desc->string.pointer,
  360. return_value);
  361. }
  362. ACPI_DEBUG_PRINT_RAW((ACPI_DB_INFO,
  363. "ACPI: BIOS _OSI(\"%s\") is %ssupported\n",
  364. string_desc->string.pointer,
  365. return_value == 0 ? "not " : ""));
  366. /* Complete the return object */
  367. return_desc->integer.value = return_value;
  368. walk_state->return_desc = return_desc;
  369. return_ACPI_STATUS(AE_OK);
  370. }