Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
utosi.c
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * Module Name: utosi - Support for the _OSI predefined control method
4  *
5  *****************************************************************************/
6 
7 /*
8  * Copyright (C) 2000 - 2012, Intel Corp.
9  * All rights reserved.
10  *
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.
25  *
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.
29  *
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.
42  */
43 
44 #include <acpi/acpi.h>
45 #include "accommon.h"
46 
47 #define _COMPONENT ACPI_UTILITIES
48 ACPI_MODULE_NAME("utosi")
49 
50 /*
51  * Strings supported by the _OSI predefined control method (which is
52  * implemented internally within this module.)
53  *
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.
58  *
59  * The last element of each entry is used to track the newest version of
60  * Windows that the BIOS has requested.
61  */
62 static struct acpi_interface_info acpi_default_supported_interfaces[] = {
63  /* Operating System Vendor Strings */
64 
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 
78  /* Feature Group Strings */
79 
80  {"Extended Address Space Descriptor", NULL, 0, 0}
81 
82  /*
83  * All "optional" feature group strings (features that are implemented
84  * by the host) should be dynamically added by the host via
85  * acpi_install_interface and should not be manually added here.
86  *
87  * Examples of optional feature group strings:
88  *
89  * "Module Device"
90  * "Processor Device"
91  * "3.0 Thermal Model"
92  * "3.0 _SCP Extensions"
93  * "Processor Aggregator Device"
94  */
95 };
96 
97 /*******************************************************************************
98  *
99  * FUNCTION: acpi_ut_initialize_interfaces
100  *
101  * PARAMETERS: None
102  *
103  * RETURN: Status
104  *
105  * DESCRIPTION: Initialize the global _OSI supported interfaces list
106  *
107  ******************************************************************************/
108 
110 {
111  u32 i;
112 
114  acpi_gbl_supported_interfaces = acpi_default_supported_interfaces;
115 
116  /* Link the static list of supported interfaces */
117 
118  for (i = 0;
119  i < (ACPI_ARRAY_LENGTH(acpi_default_supported_interfaces) - 1);
120  i++) {
121  acpi_default_supported_interfaces[i].next =
122  &acpi_default_supported_interfaces[(acpi_size) i + 1];
123  }
124 
126  return (AE_OK);
127 }
128 
129 /*******************************************************************************
130  *
131  * FUNCTION: acpi_ut_interface_terminate
132  *
133  * PARAMETERS: None
134  *
135  * RETURN: None
136  *
137  * DESCRIPTION: Delete all interfaces in the global list. Sets
138  * acpi_gbl_supported_interfaces to NULL.
139  *
140  ******************************************************************************/
141 
143 {
144  struct acpi_interface_info *next_interface;
145 
147  next_interface = acpi_gbl_supported_interfaces;
148 
149  while (next_interface) {
150  acpi_gbl_supported_interfaces = next_interface->next;
151 
152  /* Only interfaces added at runtime can be freed */
153 
154  if (next_interface->flags & ACPI_OSI_DYNAMIC) {
155  ACPI_FREE(next_interface->name);
156  ACPI_FREE(next_interface);
157  }
158 
159  next_interface = acpi_gbl_supported_interfaces;
160  }
161 
163 }
164 
165 /*******************************************************************************
166  *
167  * FUNCTION: acpi_ut_install_interface
168  *
169  * PARAMETERS: interface_name - The interface to install
170  *
171  * RETURN: Status
172  *
173  * DESCRIPTION: Install the interface into the global interface list.
174  * Caller MUST hold acpi_gbl_osi_mutex
175  *
176  ******************************************************************************/
177 
179 {
180  struct acpi_interface_info *interface_info;
181 
182  /* Allocate info block and space for the name string */
183 
184  interface_info =
186  if (!interface_info) {
187  return (AE_NO_MEMORY);
188  }
189 
190  interface_info->name =
191  ACPI_ALLOCATE_ZEROED(ACPI_STRLEN(interface_name) + 1);
192  if (!interface_info->name) {
193  ACPI_FREE(interface_info);
194  return (AE_NO_MEMORY);
195  }
196 
197  /* Initialize new info and insert at the head of the global list */
198 
199  ACPI_STRCPY(interface_info->name, interface_name);
200  interface_info->flags = ACPI_OSI_DYNAMIC;
201  interface_info->next = acpi_gbl_supported_interfaces;
202 
203  acpi_gbl_supported_interfaces = interface_info;
204  return (AE_OK);
205 }
206 
207 /*******************************************************************************
208  *
209  * FUNCTION: acpi_ut_remove_interface
210  *
211  * PARAMETERS: interface_name - The interface to remove
212  *
213  * RETURN: Status
214  *
215  * DESCRIPTION: Remove the interface from the global interface list.
216  * Caller MUST hold acpi_gbl_osi_mutex
217  *
218  ******************************************************************************/
219 
221 {
222  struct acpi_interface_info *previous_interface;
223  struct acpi_interface_info *next_interface;
224 
225  previous_interface = next_interface = acpi_gbl_supported_interfaces;
226  while (next_interface) {
227  if (!ACPI_STRCMP(interface_name, next_interface->name)) {
228 
229  /* Found: name is in either the static list or was added at runtime */
230 
231  if (next_interface->flags & ACPI_OSI_DYNAMIC) {
232 
233  /* Interface was added dynamically, remove and free it */
234 
235  if (previous_interface == next_interface) {
237  next_interface->next;
238  } else {
239  previous_interface->next =
240  next_interface->next;
241  }
242 
243  ACPI_FREE(next_interface->name);
244  ACPI_FREE(next_interface);
245  } else {
246  /*
247  * Interface is in static list. If marked invalid, then it
248  * does not actually exist. Else, mark it invalid.
249  */
250  if (next_interface->flags & ACPI_OSI_INVALID) {
251  return (AE_NOT_EXIST);
252  }
253 
254  next_interface->flags |= ACPI_OSI_INVALID;
255  }
256 
257  return (AE_OK);
258  }
259 
260  previous_interface = next_interface;
261  next_interface = next_interface->next;
262  }
263 
264  /* Interface was not found */
265 
266  return (AE_NOT_EXIST);
267 }
268 
269 /*******************************************************************************
270  *
271  * FUNCTION: acpi_ut_get_interface
272  *
273  * PARAMETERS: interface_name - The interface to find
274  *
275  * RETURN: struct acpi_interface_info if found. NULL if not found.
276  *
277  * DESCRIPTION: Search for the specified interface name in the global list.
278  * Caller MUST hold acpi_gbl_osi_mutex
279  *
280  ******************************************************************************/
281 
283 {
284  struct acpi_interface_info *next_interface;
285 
286  next_interface = acpi_gbl_supported_interfaces;
287  while (next_interface) {
288  if (!ACPI_STRCMP(interface_name, next_interface->name)) {
289  return (next_interface);
290  }
291 
292  next_interface = next_interface->next;
293  }
294 
295  return (NULL);
296 }
297 
298 /*******************************************************************************
299  *
300  * FUNCTION: acpi_ut_osi_implementation
301  *
302  * PARAMETERS: walk_state - Current walk state
303  *
304  * RETURN: Status
305  *
306  * DESCRIPTION: Implementation of the _OSI predefined control method. When
307  * an invocation of _OSI is encountered in the system AML,
308  * control is transferred to this function.
309  *
310  ******************************************************************************/
311 
313 {
314  union acpi_operand_object *string_desc;
315  union acpi_operand_object *return_desc;
316  struct acpi_interface_info *interface_info;
317  acpi_interface_handler interface_handler;
319 
320  ACPI_FUNCTION_TRACE(ut_osi_implementation);
321 
322  /* Validate the string input argument (from the AML caller) */
323 
324  string_desc = walk_state->arguments[0].object;
325  if (!string_desc || (string_desc->common.type != ACPI_TYPE_STRING)) {
327  }
328 
329  /* Create a return object */
330 
332  if (!return_desc) {
334  }
335 
336  /* Default return value is 0, NOT SUPPORTED */
337 
338  return_value = 0;
340 
341  /* Lookup the interface in the global _OSI list */
342 
343  interface_info = acpi_ut_get_interface(string_desc->string.pointer);
344  if (interface_info && !(interface_info->flags & ACPI_OSI_INVALID)) {
345  /*
346  * The interface is supported.
347  * Update the osi_data if necessary. We keep track of the latest
348  * version of Windows that has been requested by the BIOS.
349  */
350  if (interface_info->value > acpi_gbl_osi_data) {
351  acpi_gbl_osi_data = interface_info->value;
352  }
353 
354  return_value = ACPI_UINT32_MAX;
355  }
356 
358 
359  /*
360  * Invoke an optional _OSI interface handler. The host OS may wish
361  * to do some interface-specific handling. For example, warn about
362  * certain interfaces or override the true/false support value.
363  */
364  interface_handler = acpi_gbl_interface_handler;
365  if (interface_handler) {
366  return_value =
367  interface_handler(string_desc->string.pointer,
368  return_value);
369  }
370 
372  "ACPI: BIOS _OSI(\"%s\") is %ssupported\n",
373  string_desc->string.pointer,
374  return_value == 0 ? "not " : ""));
375 
376  /* Complete the return object */
377 
378  return_desc->integer.value = return_value;
379  walk_state->return_desc = return_desc;
381 }