utosi.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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, 0, 0}
  74. /*
  75. * All "optional" feature group strings (features that are implemented
  76. * by the host) should be dynamically added by the host via
  77. * acpi_install_interface and should not be manually added here.
  78. *
  79. * Examples of optional feature group strings:
  80. *
  81. * "Module Device"
  82. * "Processor Device"
  83. * "3.0 Thermal Model"
  84. * "3.0 _SCP Extensions"
  85. * "Processor Aggregator Device"
  86. */
  87. };
  88. /*******************************************************************************
  89. *
  90. * FUNCTION: acpi_ut_initialize_interfaces
  91. *
  92. * PARAMETERS: None
  93. *
  94. * RETURN: Status
  95. *
  96. * DESCRIPTION: Initialize the global _OSI supported interfaces list
  97. *
  98. ******************************************************************************/
  99. acpi_status acpi_ut_initialize_interfaces(void)
  100. {
  101. acpi_status status;
  102. u32 i;
  103. status = acpi_os_acquire_mutex(acpi_gbl_osi_mutex, ACPI_WAIT_FOREVER);
  104. if (ACPI_FAILURE(status)) {
  105. return (status);
  106. }
  107. acpi_gbl_supported_interfaces = acpi_default_supported_interfaces;
  108. /* Link the static list of supported interfaces */
  109. for (i = 0;
  110. i < (ACPI_ARRAY_LENGTH(acpi_default_supported_interfaces) - 1);
  111. i++) {
  112. acpi_default_supported_interfaces[i].next =
  113. &acpi_default_supported_interfaces[(acpi_size) i + 1];
  114. }
  115. acpi_os_release_mutex(acpi_gbl_osi_mutex);
  116. return (AE_OK);
  117. }
  118. /*******************************************************************************
  119. *
  120. * FUNCTION: acpi_ut_interface_terminate
  121. *
  122. * PARAMETERS: None
  123. *
  124. * RETURN: Status
  125. *
  126. * DESCRIPTION: Delete all interfaces in the global list. Sets
  127. * acpi_gbl_supported_interfaces to NULL.
  128. *
  129. ******************************************************************************/
  130. acpi_status acpi_ut_interface_terminate(void)
  131. {
  132. acpi_status status;
  133. struct acpi_interface_info *next_interface;
  134. status = acpi_os_acquire_mutex(acpi_gbl_osi_mutex, ACPI_WAIT_FOREVER);
  135. if (ACPI_FAILURE(status)) {
  136. return (status);
  137. }
  138. next_interface = acpi_gbl_supported_interfaces;
  139. while (next_interface) {
  140. acpi_gbl_supported_interfaces = next_interface->next;
  141. /* Only interfaces added at runtime can be freed */
  142. if (next_interface->flags & ACPI_OSI_DYNAMIC) {
  143. ACPI_FREE(next_interface->name);
  144. ACPI_FREE(next_interface);
  145. }
  146. next_interface = acpi_gbl_supported_interfaces;
  147. }
  148. acpi_os_release_mutex(acpi_gbl_osi_mutex);
  149. return (AE_OK);
  150. }
  151. /*******************************************************************************
  152. *
  153. * FUNCTION: acpi_ut_install_interface
  154. *
  155. * PARAMETERS: interface_name - The interface to install
  156. *
  157. * RETURN: Status
  158. *
  159. * DESCRIPTION: Install the interface into the global interface list.
  160. * Caller MUST hold acpi_gbl_osi_mutex
  161. *
  162. ******************************************************************************/
  163. acpi_status acpi_ut_install_interface(acpi_string interface_name)
  164. {
  165. struct acpi_interface_info *interface_info;
  166. /* Allocate info block and space for the name string */
  167. interface_info =
  168. ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_interface_info));
  169. if (!interface_info) {
  170. return (AE_NO_MEMORY);
  171. }
  172. interface_info->name =
  173. ACPI_ALLOCATE_ZEROED(ACPI_STRLEN(interface_name) + 1);
  174. if (!interface_info->name) {
  175. ACPI_FREE(interface_info);
  176. return (AE_NO_MEMORY);
  177. }
  178. /* Initialize new info and insert at the head of the global list */
  179. ACPI_STRCPY(interface_info->name, interface_name);
  180. interface_info->flags = ACPI_OSI_DYNAMIC;
  181. interface_info->next = acpi_gbl_supported_interfaces;
  182. acpi_gbl_supported_interfaces = interface_info;
  183. return (AE_OK);
  184. }
  185. /*******************************************************************************
  186. *
  187. * FUNCTION: acpi_ut_remove_interface
  188. *
  189. * PARAMETERS: interface_name - The interface to remove
  190. *
  191. * RETURN: Status
  192. *
  193. * DESCRIPTION: Remove the interface from the global interface list.
  194. * Caller MUST hold acpi_gbl_osi_mutex
  195. *
  196. ******************************************************************************/
  197. acpi_status acpi_ut_remove_interface(acpi_string interface_name)
  198. {
  199. struct acpi_interface_info *previous_interface;
  200. struct acpi_interface_info *next_interface;
  201. previous_interface = next_interface = acpi_gbl_supported_interfaces;
  202. while (next_interface) {
  203. if (!ACPI_STRCMP(interface_name, next_interface->name)) {
  204. /* Found: name is in either the static list or was added at runtime */
  205. if (next_interface->flags & ACPI_OSI_DYNAMIC) {
  206. /* Interface was added dynamically, remove and free it */
  207. if (previous_interface == next_interface) {
  208. acpi_gbl_supported_interfaces =
  209. next_interface->next;
  210. } else {
  211. previous_interface->next =
  212. next_interface->next;
  213. }
  214. ACPI_FREE(next_interface->name);
  215. ACPI_FREE(next_interface);
  216. } else {
  217. /*
  218. * Interface is in static list. If marked invalid, then it
  219. * does not actually exist. Else, mark it invalid.
  220. */
  221. if (next_interface->flags & ACPI_OSI_INVALID) {
  222. return (AE_NOT_EXIST);
  223. }
  224. next_interface->flags |= ACPI_OSI_INVALID;
  225. }
  226. return (AE_OK);
  227. }
  228. previous_interface = next_interface;
  229. next_interface = next_interface->next;
  230. }
  231. /* Interface was not found */
  232. return (AE_NOT_EXIST);
  233. }
  234. /*******************************************************************************
  235. *
  236. * FUNCTION: acpi_ut_get_interface
  237. *
  238. * PARAMETERS: interface_name - The interface to find
  239. *
  240. * RETURN: struct acpi_interface_info if found. NULL if not found.
  241. *
  242. * DESCRIPTION: Search for the specified interface name in the global list.
  243. * Caller MUST hold acpi_gbl_osi_mutex
  244. *
  245. ******************************************************************************/
  246. struct acpi_interface_info *acpi_ut_get_interface(acpi_string interface_name)
  247. {
  248. struct acpi_interface_info *next_interface;
  249. next_interface = acpi_gbl_supported_interfaces;
  250. while (next_interface) {
  251. if (!ACPI_STRCMP(interface_name, next_interface->name)) {
  252. return (next_interface);
  253. }
  254. next_interface = next_interface->next;
  255. }
  256. return (NULL);
  257. }
  258. /*******************************************************************************
  259. *
  260. * FUNCTION: acpi_ut_osi_implementation
  261. *
  262. * PARAMETERS: walk_state - Current walk state
  263. *
  264. * RETURN: Status
  265. *
  266. * DESCRIPTION: Implementation of the _OSI predefined control method. When
  267. * an invocation of _OSI is encountered in the system AML,
  268. * control is transferred to this function.
  269. *
  270. ******************************************************************************/
  271. acpi_status acpi_ut_osi_implementation(struct acpi_walk_state * walk_state)
  272. {
  273. union acpi_operand_object *string_desc;
  274. union acpi_operand_object *return_desc;
  275. struct acpi_interface_info *interface_info;
  276. acpi_interface_handler interface_handler;
  277. acpi_status status;
  278. u32 return_value;
  279. ACPI_FUNCTION_TRACE(ut_osi_implementation);
  280. /* Validate the string input argument (from the AML caller) */
  281. string_desc = walk_state->arguments[0].object;
  282. if (!string_desc || (string_desc->common.type != ACPI_TYPE_STRING)) {
  283. return_ACPI_STATUS(AE_TYPE);
  284. }
  285. /* Create a return object */
  286. return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
  287. if (!return_desc) {
  288. return_ACPI_STATUS(AE_NO_MEMORY);
  289. }
  290. /* Default return value is 0, NOT SUPPORTED */
  291. return_value = 0;
  292. status = acpi_os_acquire_mutex(acpi_gbl_osi_mutex, ACPI_WAIT_FOREVER);
  293. if (ACPI_FAILURE(status)) {
  294. acpi_ut_remove_reference(return_desc);
  295. return_ACPI_STATUS(status);
  296. }
  297. /* Lookup the interface in the global _OSI list */
  298. interface_info = acpi_ut_get_interface(string_desc->string.pointer);
  299. if (interface_info && !(interface_info->flags & ACPI_OSI_INVALID)) {
  300. /*
  301. * The interface is supported.
  302. * Update the osi_data if necessary. We keep track of the latest
  303. * version of Windows that has been requested by the BIOS.
  304. */
  305. if (interface_info->value > acpi_gbl_osi_data) {
  306. acpi_gbl_osi_data = interface_info->value;
  307. }
  308. return_value = ACPI_UINT32_MAX;
  309. }
  310. acpi_os_release_mutex(acpi_gbl_osi_mutex);
  311. /*
  312. * Invoke an optional _OSI interface handler. The host OS may wish
  313. * to do some interface-specific handling. For example, warn about
  314. * certain interfaces or override the true/false support value.
  315. */
  316. interface_handler = acpi_gbl_interface_handler;
  317. if (interface_handler) {
  318. return_value =
  319. interface_handler(string_desc->string.pointer,
  320. return_value);
  321. }
  322. ACPI_DEBUG_PRINT_RAW((ACPI_DB_INFO,
  323. "ACPI: BIOS _OSI(\"%s\") is %ssupported\n",
  324. string_desc->string.pointer,
  325. return_value == 0 ? "not " : ""));
  326. /* Complete the return object */
  327. return_desc->integer.value = return_value;
  328. walk_state->return_desc = return_desc;
  329. return_ACPI_STATUS(AE_OK);
  330. }