utosi.c 12 KB

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