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