Merge branch 'akpm'
[linux-2.6/next.git] / drivers / acpi / acpica / utosi.c
blob1fb10cb8f11dfdaa660c0bf4ee9095a79986bd55
1 /******************************************************************************
3 * Module Name: utosi - Support for the _OSI predefined control method
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2011, 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 */
77 /* Feature Group Strings */
79 {"Extended Address Space Descriptor", NULL, 0, 0}
82 * All "optional" feature group strings (features that are implemented
83 * by the host) should be dynamically added by the host via
84 * acpi_install_interface and should not be manually added here.
86 * Examples of optional feature group strings:
88 * "Module Device"
89 * "Processor Device"
90 * "3.0 Thermal Model"
91 * "3.0 _SCP Extensions"
92 * "Processor Aggregator Device"
96 /*******************************************************************************
98 * FUNCTION: acpi_ut_initialize_interfaces
100 * PARAMETERS: None
102 * RETURN: Status
104 * DESCRIPTION: Initialize the global _OSI supported interfaces list
106 ******************************************************************************/
108 acpi_status acpi_ut_initialize_interfaces(void)
110 u32 i;
112 (void)acpi_os_acquire_mutex(acpi_gbl_osi_mutex, ACPI_WAIT_FOREVER);
113 acpi_gbl_supported_interfaces = acpi_default_supported_interfaces;
115 /* Link the static list of supported interfaces */
117 for (i = 0;
118 i < (ACPI_ARRAY_LENGTH(acpi_default_supported_interfaces) - 1);
119 i++) {
120 acpi_default_supported_interfaces[i].next =
121 &acpi_default_supported_interfaces[(acpi_size) i + 1];
124 acpi_os_release_mutex(acpi_gbl_osi_mutex);
125 return (AE_OK);
128 /*******************************************************************************
130 * FUNCTION: acpi_ut_interface_terminate
132 * PARAMETERS: None
134 * RETURN: None
136 * DESCRIPTION: Delete all interfaces in the global list. Sets
137 * acpi_gbl_supported_interfaces to NULL.
139 ******************************************************************************/
141 void acpi_ut_interface_terminate(void)
143 struct acpi_interface_info *next_interface;
145 (void)acpi_os_acquire_mutex(acpi_gbl_osi_mutex, ACPI_WAIT_FOREVER);
146 next_interface = acpi_gbl_supported_interfaces;
148 while (next_interface) {
149 acpi_gbl_supported_interfaces = next_interface->next;
151 /* Only interfaces added at runtime can be freed */
153 if (next_interface->flags & ACPI_OSI_DYNAMIC) {
154 ACPI_FREE(next_interface->name);
155 ACPI_FREE(next_interface);
158 next_interface = acpi_gbl_supported_interfaces;
161 acpi_os_release_mutex(acpi_gbl_osi_mutex);
164 /*******************************************************************************
166 * FUNCTION: acpi_ut_install_interface
168 * PARAMETERS: interface_name - The interface to install
170 * RETURN: Status
172 * DESCRIPTION: Install the interface into the global interface list.
173 * Caller MUST hold acpi_gbl_osi_mutex
175 ******************************************************************************/
177 acpi_status acpi_ut_install_interface(acpi_string interface_name)
179 struct acpi_interface_info *interface_info;
181 /* Allocate info block and space for the name string */
183 interface_info =
184 ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_interface_info));
185 if (!interface_info) {
186 return (AE_NO_MEMORY);
189 interface_info->name =
190 ACPI_ALLOCATE_ZEROED(ACPI_STRLEN(interface_name) + 1);
191 if (!interface_info->name) {
192 ACPI_FREE(interface_info);
193 return (AE_NO_MEMORY);
196 /* Initialize new info and insert at the head of the global list */
198 ACPI_STRCPY(interface_info->name, interface_name);
199 interface_info->flags = ACPI_OSI_DYNAMIC;
200 interface_info->next = acpi_gbl_supported_interfaces;
202 acpi_gbl_supported_interfaces = interface_info;
203 return (AE_OK);
206 /*******************************************************************************
208 * FUNCTION: acpi_ut_remove_interface
210 * PARAMETERS: interface_name - The interface to remove
212 * RETURN: Status
214 * DESCRIPTION: Remove the interface from the global interface list.
215 * Caller MUST hold acpi_gbl_osi_mutex
217 ******************************************************************************/
219 acpi_status acpi_ut_remove_interface(acpi_string interface_name)
221 struct acpi_interface_info *previous_interface;
222 struct acpi_interface_info *next_interface;
224 previous_interface = next_interface = acpi_gbl_supported_interfaces;
225 while (next_interface) {
226 if (!ACPI_STRCMP(interface_name, next_interface->name)) {
228 /* Found: name is in either the static list or was added at runtime */
230 if (next_interface->flags & ACPI_OSI_DYNAMIC) {
232 /* Interface was added dynamically, remove and free it */
234 if (previous_interface == next_interface) {
235 acpi_gbl_supported_interfaces =
236 next_interface->next;
237 } else {
238 previous_interface->next =
239 next_interface->next;
242 ACPI_FREE(next_interface->name);
243 ACPI_FREE(next_interface);
244 } else {
246 * Interface is in static list. If marked invalid, then it
247 * does not actually exist. Else, mark it invalid.
249 if (next_interface->flags & ACPI_OSI_INVALID) {
250 return (AE_NOT_EXIST);
253 next_interface->flags |= ACPI_OSI_INVALID;
256 return (AE_OK);
259 previous_interface = next_interface;
260 next_interface = next_interface->next;
263 /* Interface was not found */
265 return (AE_NOT_EXIST);
268 /*******************************************************************************
270 * FUNCTION: acpi_ut_get_interface
272 * PARAMETERS: interface_name - The interface to find
274 * RETURN: struct acpi_interface_info if found. NULL if not found.
276 * DESCRIPTION: Search for the specified interface name in the global list.
277 * Caller MUST hold acpi_gbl_osi_mutex
279 ******************************************************************************/
281 struct acpi_interface_info *acpi_ut_get_interface(acpi_string interface_name)
283 struct acpi_interface_info *next_interface;
285 next_interface = acpi_gbl_supported_interfaces;
286 while (next_interface) {
287 if (!ACPI_STRCMP(interface_name, next_interface->name)) {
288 return (next_interface);
291 next_interface = next_interface->next;
294 return (NULL);
297 /*******************************************************************************
299 * FUNCTION: acpi_ut_osi_implementation
301 * PARAMETERS: walk_state - Current walk state
303 * RETURN: Status
305 * DESCRIPTION: Implementation of the _OSI predefined control method. When
306 * an invocation of _OSI is encountered in the system AML,
307 * control is transferred to this function.
309 ******************************************************************************/
311 acpi_status acpi_ut_osi_implementation(struct acpi_walk_state * walk_state)
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 u32 return_value;
319 ACPI_FUNCTION_TRACE(ut_osi_implementation);
321 /* Validate the string input argument (from the AML caller) */
323 string_desc = walk_state->arguments[0].object;
324 if (!string_desc || (string_desc->common.type != ACPI_TYPE_STRING)) {
325 return_ACPI_STATUS(AE_TYPE);
328 /* Create a return object */
330 return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
331 if (!return_desc) {
332 return_ACPI_STATUS(AE_NO_MEMORY);
335 /* Default return value is 0, NOT SUPPORTED */
337 return_value = 0;
338 (void)acpi_os_acquire_mutex(acpi_gbl_osi_mutex, ACPI_WAIT_FOREVER);
340 /* Lookup the interface in the global _OSI list */
342 interface_info = acpi_ut_get_interface(string_desc->string.pointer);
343 if (interface_info && !(interface_info->flags & ACPI_OSI_INVALID)) {
345 * The interface is supported.
346 * Update the osi_data if necessary. We keep track of the latest
347 * version of Windows that has been requested by the BIOS.
349 if (interface_info->value > acpi_gbl_osi_data) {
350 acpi_gbl_osi_data = interface_info->value;
353 return_value = ACPI_UINT32_MAX;
356 acpi_os_release_mutex(acpi_gbl_osi_mutex);
359 * Invoke an optional _OSI interface handler. The host OS may wish
360 * to do some interface-specific handling. For example, warn about
361 * certain interfaces or override the true/false support value.
363 interface_handler = acpi_gbl_interface_handler;
364 if (interface_handler) {
365 return_value =
366 interface_handler(string_desc->string.pointer,
367 return_value);
370 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INFO,
371 "ACPI: BIOS _OSI(\"%s\") is %ssupported\n",
372 string_desc->string.pointer,
373 return_value == 0 ? "not " : ""));
375 /* Complete the return object */
377 return_desc->integer.value = return_value;
378 walk_state->return_desc = return_desc;
379 return_ACPI_STATUS(AE_OK);