Linux 3.12.49
[linux/fpc-iii.git] / drivers / acpi / acpica / utosi.c
blobb2c044031692d403e6b221909aa6020a3ea61d8b
1 /******************************************************************************
3 * Module Name: utosi - Support for the _OSI predefined control method
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2013, Intel Corp.
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #include <acpi/acpi.h>
45 #include "accommon.h"
47 #define _COMPONENT ACPI_UTILITIES
48 ACPI_MODULE_NAME("utosi")
51 * Strings supported by the _OSI predefined control method (which is
52 * implemented internally within this module.)
54 * March 2009: Removed "Linux" as this host no longer wants to respond true
55 * for this string. Basically, the only safe OS strings are windows-related
56 * and in many or most cases represent the only test path within the
57 * BIOS-provided ASL code.
59 * The last element of each entry is used to track the newest version of
60 * Windows that the BIOS has requested.
62 static struct acpi_interface_info acpi_default_supported_interfaces[] = {
63 /* Operating System Vendor Strings */
65 {"Windows 2000", NULL, 0, ACPI_OSI_WIN_2000}, /* Windows 2000 */
66 {"Windows 2001", NULL, 0, ACPI_OSI_WIN_XP}, /* Windows XP */
67 {"Windows 2001 SP1", NULL, 0, ACPI_OSI_WIN_XP_SP1}, /* Windows XP SP1 */
68 {"Windows 2001.1", NULL, 0, ACPI_OSI_WINSRV_2003}, /* Windows Server 2003 */
69 {"Windows 2001 SP2", NULL, 0, ACPI_OSI_WIN_XP_SP2}, /* Windows XP SP2 */
70 {"Windows 2001.1 SP1", NULL, 0, ACPI_OSI_WINSRV_2003_SP1}, /* Windows Server 2003 SP1 - Added 03/2006 */
71 {"Windows 2006", NULL, 0, ACPI_OSI_WIN_VISTA}, /* Windows vista - Added 03/2006 */
72 {"Windows 2006.1", NULL, 0, ACPI_OSI_WINSRV_2008}, /* Windows Server 2008 - Added 09/2009 */
73 {"Windows 2006 SP1", NULL, 0, ACPI_OSI_WIN_VISTA_SP1}, /* Windows Vista SP1 - Added 09/2009 */
74 {"Windows 2006 SP2", NULL, 0, ACPI_OSI_WIN_VISTA_SP2}, /* Windows Vista SP2 - Added 09/2010 */
75 {"Windows 2009", NULL, 0, ACPI_OSI_WIN_7}, /* Windows 7 and Server 2008 R2 - Added 09/2009 */
76 {"Windows 2012", NULL, 0, ACPI_OSI_WIN_8}, /* Windows 8 and Server 2012 - Added 08/2012 */
77 {"Windows 2013", NULL, 0, ACPI_OSI_WIN_8}, /* Windows 8.1 and Server 2012 R2 - Added 01/2014 */
79 /* Feature Group Strings */
81 {"Extended Address Space Descriptor", NULL, ACPI_OSI_FEATURE, 0},
84 * All "optional" feature group strings (features that are implemented
85 * by the host) should be dynamically modified to VALID by the host via
86 * acpi_install_interface or acpi_update_interfaces. Such optional feature
87 * group strings are set as INVALID by default here.
90 {"Module Device", NULL, ACPI_OSI_OPTIONAL_FEATURE, 0},
91 {"Processor Device", NULL, ACPI_OSI_OPTIONAL_FEATURE, 0},
92 {"3.0 Thermal Model", NULL, ACPI_OSI_OPTIONAL_FEATURE, 0},
93 {"3.0 _SCP Extensions", NULL, ACPI_OSI_OPTIONAL_FEATURE, 0},
94 {"Processor Aggregator Device", NULL, ACPI_OSI_OPTIONAL_FEATURE, 0}
97 /*******************************************************************************
99 * FUNCTION: acpi_ut_initialize_interfaces
101 * PARAMETERS: None
103 * RETURN: Status
105 * DESCRIPTION: Initialize the global _OSI supported interfaces list
107 ******************************************************************************/
109 acpi_status acpi_ut_initialize_interfaces(void)
111 acpi_status status;
112 u32 i;
114 status = acpi_os_acquire_mutex(acpi_gbl_osi_mutex, ACPI_WAIT_FOREVER);
115 if (ACPI_FAILURE(status)) {
116 return (status);
119 acpi_gbl_supported_interfaces = acpi_default_supported_interfaces;
121 /* Link the static list of supported interfaces */
123 for (i = 0;
124 i < (ACPI_ARRAY_LENGTH(acpi_default_supported_interfaces) - 1);
125 i++) {
126 acpi_default_supported_interfaces[i].next =
127 &acpi_default_supported_interfaces[(acpi_size) i + 1];
130 acpi_os_release_mutex(acpi_gbl_osi_mutex);
131 return (AE_OK);
134 /*******************************************************************************
136 * FUNCTION: acpi_ut_interface_terminate
138 * PARAMETERS: None
140 * RETURN: Status
142 * DESCRIPTION: Delete all interfaces in the global list. Sets
143 * acpi_gbl_supported_interfaces to NULL.
145 ******************************************************************************/
147 acpi_status acpi_ut_interface_terminate(void)
149 acpi_status status;
150 struct acpi_interface_info *next_interface;
152 status = acpi_os_acquire_mutex(acpi_gbl_osi_mutex, ACPI_WAIT_FOREVER);
153 if (ACPI_FAILURE(status)) {
154 return (status);
157 next_interface = acpi_gbl_supported_interfaces;
158 while (next_interface) {
159 acpi_gbl_supported_interfaces = next_interface->next;
161 if (next_interface->flags & ACPI_OSI_DYNAMIC) {
163 /* Only interfaces added at runtime can be freed */
165 ACPI_FREE(next_interface->name);
166 ACPI_FREE(next_interface);
167 } else {
168 /* Interface is in static list. Reset it to invalid or valid. */
170 if (next_interface->flags & ACPI_OSI_DEFAULT_INVALID) {
171 next_interface->flags |= ACPI_OSI_INVALID;
172 } else {
173 next_interface->flags &= ~ACPI_OSI_INVALID;
177 next_interface = acpi_gbl_supported_interfaces;
180 acpi_os_release_mutex(acpi_gbl_osi_mutex);
181 return (AE_OK);
184 /*******************************************************************************
186 * FUNCTION: acpi_ut_install_interface
188 * PARAMETERS: interface_name - The interface to install
190 * RETURN: Status
192 * DESCRIPTION: Install the interface into the global interface list.
193 * Caller MUST hold acpi_gbl_osi_mutex
195 ******************************************************************************/
197 acpi_status acpi_ut_install_interface(acpi_string interface_name)
199 struct acpi_interface_info *interface_info;
201 /* Allocate info block and space for the name string */
203 interface_info =
204 ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_interface_info));
205 if (!interface_info) {
206 return (AE_NO_MEMORY);
209 interface_info->name =
210 ACPI_ALLOCATE_ZEROED(ACPI_STRLEN(interface_name) + 1);
211 if (!interface_info->name) {
212 ACPI_FREE(interface_info);
213 return (AE_NO_MEMORY);
216 /* Initialize new info and insert at the head of the global list */
218 ACPI_STRCPY(interface_info->name, interface_name);
219 interface_info->flags = ACPI_OSI_DYNAMIC;
220 interface_info->next = acpi_gbl_supported_interfaces;
222 acpi_gbl_supported_interfaces = interface_info;
223 return (AE_OK);
226 /*******************************************************************************
228 * FUNCTION: acpi_ut_remove_interface
230 * PARAMETERS: interface_name - The interface to remove
232 * RETURN: Status
234 * DESCRIPTION: Remove the interface from the global interface list.
235 * Caller MUST hold acpi_gbl_osi_mutex
237 ******************************************************************************/
239 acpi_status acpi_ut_remove_interface(acpi_string interface_name)
241 struct acpi_interface_info *previous_interface;
242 struct acpi_interface_info *next_interface;
244 previous_interface = next_interface = acpi_gbl_supported_interfaces;
245 while (next_interface) {
246 if (!ACPI_STRCMP(interface_name, next_interface->name)) {
248 /* Found: name is in either the static list or was added at runtime */
250 if (next_interface->flags & ACPI_OSI_DYNAMIC) {
252 /* Interface was added dynamically, remove and free it */
254 if (previous_interface == next_interface) {
255 acpi_gbl_supported_interfaces =
256 next_interface->next;
257 } else {
258 previous_interface->next =
259 next_interface->next;
262 ACPI_FREE(next_interface->name);
263 ACPI_FREE(next_interface);
264 } else {
266 * Interface is in static list. If marked invalid, then it
267 * does not actually exist. Else, mark it invalid.
269 if (next_interface->flags & ACPI_OSI_INVALID) {
270 return (AE_NOT_EXIST);
273 next_interface->flags |= ACPI_OSI_INVALID;
276 return (AE_OK);
279 previous_interface = next_interface;
280 next_interface = next_interface->next;
283 /* Interface was not found */
285 return (AE_NOT_EXIST);
288 /*******************************************************************************
290 * FUNCTION: acpi_ut_update_interfaces
292 * PARAMETERS: action - Actions to be performed during the
293 * update
295 * RETURN: Status
297 * DESCRIPTION: Update _OSI interface strings, disabling or enabling OS vendor
298 * strings or/and feature group strings.
299 * Caller MUST hold acpi_gbl_osi_mutex
301 ******************************************************************************/
303 acpi_status acpi_ut_update_interfaces(u8 action)
305 struct acpi_interface_info *next_interface;
307 next_interface = acpi_gbl_supported_interfaces;
308 while (next_interface) {
309 if (((next_interface->flags & ACPI_OSI_FEATURE) &&
310 (action & ACPI_FEATURE_STRINGS)) ||
311 (!(next_interface->flags & ACPI_OSI_FEATURE) &&
312 (action & ACPI_VENDOR_STRINGS))) {
313 if (action & ACPI_DISABLE_INTERFACES) {
315 /* Mark the interfaces as invalid */
317 next_interface->flags |= ACPI_OSI_INVALID;
318 } else {
319 /* Mark the interfaces as valid */
321 next_interface->flags &= ~ACPI_OSI_INVALID;
325 next_interface = next_interface->next;
328 return (AE_OK);
331 /*******************************************************************************
333 * FUNCTION: acpi_ut_get_interface
335 * PARAMETERS: interface_name - The interface to find
337 * RETURN: struct acpi_interface_info if found. NULL if not found.
339 * DESCRIPTION: Search for the specified interface name in the global list.
340 * Caller MUST hold acpi_gbl_osi_mutex
342 ******************************************************************************/
344 struct acpi_interface_info *acpi_ut_get_interface(acpi_string interface_name)
346 struct acpi_interface_info *next_interface;
348 next_interface = acpi_gbl_supported_interfaces;
349 while (next_interface) {
350 if (!ACPI_STRCMP(interface_name, next_interface->name)) {
351 return (next_interface);
354 next_interface = next_interface->next;
357 return (NULL);
360 /*******************************************************************************
362 * FUNCTION: acpi_ut_osi_implementation
364 * PARAMETERS: walk_state - Current walk state
366 * RETURN: Status
368 * DESCRIPTION: Implementation of the _OSI predefined control method. When
369 * an invocation of _OSI is encountered in the system AML,
370 * control is transferred to this function.
372 ******************************************************************************/
374 acpi_status acpi_ut_osi_implementation(struct acpi_walk_state * walk_state)
376 union acpi_operand_object *string_desc;
377 union acpi_operand_object *return_desc;
378 struct acpi_interface_info *interface_info;
379 acpi_interface_handler interface_handler;
380 acpi_status status;
381 u32 return_value;
383 ACPI_FUNCTION_TRACE(ut_osi_implementation);
385 /* Validate the string input argument (from the AML caller) */
387 string_desc = walk_state->arguments[0].object;
388 if (!string_desc || (string_desc->common.type != ACPI_TYPE_STRING)) {
389 return_ACPI_STATUS(AE_TYPE);
392 /* Create a return object */
394 return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
395 if (!return_desc) {
396 return_ACPI_STATUS(AE_NO_MEMORY);
399 /* Default return value is 0, NOT SUPPORTED */
401 return_value = 0;
402 status = acpi_os_acquire_mutex(acpi_gbl_osi_mutex, ACPI_WAIT_FOREVER);
403 if (ACPI_FAILURE(status)) {
404 acpi_ut_remove_reference(return_desc);
405 return_ACPI_STATUS(status);
408 /* Lookup the interface in the global _OSI list */
410 interface_info = acpi_ut_get_interface(string_desc->string.pointer);
411 if (interface_info && !(interface_info->flags & ACPI_OSI_INVALID)) {
413 * The interface is supported.
414 * Update the osi_data if necessary. We keep track of the latest
415 * version of Windows that has been requested by the BIOS.
417 if (interface_info->value > acpi_gbl_osi_data) {
418 acpi_gbl_osi_data = interface_info->value;
421 return_value = ACPI_UINT32_MAX;
424 acpi_os_release_mutex(acpi_gbl_osi_mutex);
427 * Invoke an optional _OSI interface handler. The host OS may wish
428 * to do some interface-specific handling. For example, warn about
429 * certain interfaces or override the true/false support value.
431 interface_handler = acpi_gbl_interface_handler;
432 if (interface_handler) {
433 return_value =
434 interface_handler(string_desc->string.pointer,
435 return_value);
438 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INFO,
439 "ACPI: BIOS _OSI(\"%s\") is %ssupported\n",
440 string_desc->string.pointer,
441 return_value == 0 ? "not " : ""));
443 /* Complete the return object */
445 return_desc->integer.value = return_value;
446 walk_state->return_desc = return_desc;
447 return_ACPI_STATUS(AE_OK);