]> Pileus Git - ~andy/linux/blob - drivers/acpi/acpica/utosi.c
net: mvneta: use devm_ioremap_resource() instead of of_iomap()
[~andy/linux] / drivers / acpi / acpica / utosi.c
1 /******************************************************************************
2  *
3  * Module Name: utosi - Support for the _OSI predefined control method
4  *
5  *****************************************************************************/
6
7 /*
8  * Copyright (C) 2000 - 2013, 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, ACPI_OSI_FEATURE, 0},
81
82         /*
83          * All "optional" feature group strings (features that are implemented
84          * by the host) should be dynamically modified to VALID by the host via
85          * acpi_install_interface or acpi_update_interfaces. Such optional feature
86          * group strings are set as INVALID by default here.
87          */
88
89         {"Module Device", NULL, ACPI_OSI_OPTIONAL_FEATURE, 0},
90         {"Processor Device", NULL, ACPI_OSI_OPTIONAL_FEATURE, 0},
91         {"3.0 Thermal Model", NULL, ACPI_OSI_OPTIONAL_FEATURE, 0},
92         {"3.0 _SCP Extensions", NULL, ACPI_OSI_OPTIONAL_FEATURE, 0},
93         {"Processor Aggregator Device", NULL, ACPI_OSI_OPTIONAL_FEATURE, 0}
94 };
95
96 /*******************************************************************************
97  *
98  * FUNCTION:    acpi_ut_initialize_interfaces
99  *
100  * PARAMETERS:  None
101  *
102  * RETURN:      Status
103  *
104  * DESCRIPTION: Initialize the global _OSI supported interfaces list
105  *
106  ******************************************************************************/
107
108 acpi_status acpi_ut_initialize_interfaces(void)
109 {
110         acpi_status status;
111         u32 i;
112
113         status = acpi_os_acquire_mutex(acpi_gbl_osi_mutex, ACPI_WAIT_FOREVER);
114         if (ACPI_FAILURE(status)) {
115                 return (status);
116         }
117
118         acpi_gbl_supported_interfaces = acpi_default_supported_interfaces;
119
120         /* Link the static list of supported interfaces */
121
122         for (i = 0;
123              i < (ACPI_ARRAY_LENGTH(acpi_default_supported_interfaces) - 1);
124              i++) {
125                 acpi_default_supported_interfaces[i].next =
126                     &acpi_default_supported_interfaces[(acpi_size) i + 1];
127         }
128
129         acpi_os_release_mutex(acpi_gbl_osi_mutex);
130         return (AE_OK);
131 }
132
133 /*******************************************************************************
134  *
135  * FUNCTION:    acpi_ut_interface_terminate
136  *
137  * PARAMETERS:  None
138  *
139  * RETURN:      Status
140  *
141  * DESCRIPTION: Delete all interfaces in the global list. Sets
142  *              acpi_gbl_supported_interfaces to NULL.
143  *
144  ******************************************************************************/
145
146 acpi_status acpi_ut_interface_terminate(void)
147 {
148         acpi_status status;
149         struct acpi_interface_info *next_interface;
150
151         status = acpi_os_acquire_mutex(acpi_gbl_osi_mutex, ACPI_WAIT_FOREVER);
152         if (ACPI_FAILURE(status)) {
153                 return (status);
154         }
155
156         next_interface = acpi_gbl_supported_interfaces;
157         while (next_interface) {
158                 acpi_gbl_supported_interfaces = next_interface->next;
159
160                 if (next_interface->flags & ACPI_OSI_DYNAMIC) {
161
162                         /* Only interfaces added at runtime can be freed */
163
164                         ACPI_FREE(next_interface->name);
165                         ACPI_FREE(next_interface);
166                 } else {
167                         /* Interface is in static list. Reset it to invalid or valid. */
168
169                         if (next_interface->flags & ACPI_OSI_DEFAULT_INVALID) {
170                                 next_interface->flags |= ACPI_OSI_INVALID;
171                         } else {
172                                 next_interface->flags &= ~ACPI_OSI_INVALID;
173                         }
174                 }
175
176                 next_interface = acpi_gbl_supported_interfaces;
177         }
178
179         acpi_os_release_mutex(acpi_gbl_osi_mutex);
180         return (AE_OK);
181 }
182
183 /*******************************************************************************
184  *
185  * FUNCTION:    acpi_ut_install_interface
186  *
187  * PARAMETERS:  interface_name      - The interface to install
188  *
189  * RETURN:      Status
190  *
191  * DESCRIPTION: Install the interface into the global interface list.
192  *              Caller MUST hold acpi_gbl_osi_mutex
193  *
194  ******************************************************************************/
195
196 acpi_status acpi_ut_install_interface(acpi_string interface_name)
197 {
198         struct acpi_interface_info *interface_info;
199
200         /* Allocate info block and space for the name string */
201
202         interface_info =
203             ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_interface_info));
204         if (!interface_info) {
205                 return (AE_NO_MEMORY);
206         }
207
208         interface_info->name =
209             ACPI_ALLOCATE_ZEROED(ACPI_STRLEN(interface_name) + 1);
210         if (!interface_info->name) {
211                 ACPI_FREE(interface_info);
212                 return (AE_NO_MEMORY);
213         }
214
215         /* Initialize new info and insert at the head of the global list */
216
217         ACPI_STRCPY(interface_info->name, interface_name);
218         interface_info->flags = ACPI_OSI_DYNAMIC;
219         interface_info->next = acpi_gbl_supported_interfaces;
220
221         acpi_gbl_supported_interfaces = interface_info;
222         return (AE_OK);
223 }
224
225 /*******************************************************************************
226  *
227  * FUNCTION:    acpi_ut_remove_interface
228  *
229  * PARAMETERS:  interface_name      - The interface to remove
230  *
231  * RETURN:      Status
232  *
233  * DESCRIPTION: Remove the interface from the global interface list.
234  *              Caller MUST hold acpi_gbl_osi_mutex
235  *
236  ******************************************************************************/
237
238 acpi_status acpi_ut_remove_interface(acpi_string interface_name)
239 {
240         struct acpi_interface_info *previous_interface;
241         struct acpi_interface_info *next_interface;
242
243         previous_interface = next_interface = acpi_gbl_supported_interfaces;
244         while (next_interface) {
245                 if (!ACPI_STRCMP(interface_name, next_interface->name)) {
246
247                         /* Found: name is in either the static list or was added at runtime */
248
249                         if (next_interface->flags & ACPI_OSI_DYNAMIC) {
250
251                                 /* Interface was added dynamically, remove and free it */
252
253                                 if (previous_interface == next_interface) {
254                                         acpi_gbl_supported_interfaces =
255                                             next_interface->next;
256                                 } else {
257                                         previous_interface->next =
258                                             next_interface->next;
259                                 }
260
261                                 ACPI_FREE(next_interface->name);
262                                 ACPI_FREE(next_interface);
263                         } else {
264                                 /*
265                                  * Interface is in static list. If marked invalid, then it
266                                  * does not actually exist. Else, mark it invalid.
267                                  */
268                                 if (next_interface->flags & ACPI_OSI_INVALID) {
269                                         return (AE_NOT_EXIST);
270                                 }
271
272                                 next_interface->flags |= ACPI_OSI_INVALID;
273                         }
274
275                         return (AE_OK);
276                 }
277
278                 previous_interface = next_interface;
279                 next_interface = next_interface->next;
280         }
281
282         /* Interface was not found */
283
284         return (AE_NOT_EXIST);
285 }
286
287 /*******************************************************************************
288  *
289  * FUNCTION:    acpi_ut_update_interfaces
290  *
291  * PARAMETERS:  action              - Actions to be performed during the
292  *                                    update
293  *
294  * RETURN:      Status
295  *
296  * DESCRIPTION: Update _OSI interface strings, disabling or enabling OS vendor
297  *              strings or/and feature group strings.
298  *              Caller MUST hold acpi_gbl_osi_mutex
299  *
300  ******************************************************************************/
301
302 acpi_status acpi_ut_update_interfaces(u8 action)
303 {
304         struct acpi_interface_info *next_interface;
305
306         next_interface = acpi_gbl_supported_interfaces;
307         while (next_interface) {
308                 if (((next_interface->flags & ACPI_OSI_FEATURE) &&
309                      (action & ACPI_FEATURE_STRINGS)) ||
310                     (!(next_interface->flags & ACPI_OSI_FEATURE) &&
311                      (action & ACPI_VENDOR_STRINGS))) {
312                         if (action & ACPI_DISABLE_INTERFACES) {
313
314                                 /* Mark the interfaces as invalid */
315
316                                 next_interface->flags |= ACPI_OSI_INVALID;
317                         } else {
318                                 /* Mark the interfaces as valid */
319
320                                 next_interface->flags &= ~ACPI_OSI_INVALID;
321                         }
322                 }
323
324                 next_interface = next_interface->next;
325         }
326
327         return (AE_OK);
328 }
329
330 /*******************************************************************************
331  *
332  * FUNCTION:    acpi_ut_get_interface
333  *
334  * PARAMETERS:  interface_name      - The interface to find
335  *
336  * RETURN:      struct acpi_interface_info if found. NULL if not found.
337  *
338  * DESCRIPTION: Search for the specified interface name in the global list.
339  *              Caller MUST hold acpi_gbl_osi_mutex
340  *
341  ******************************************************************************/
342
343 struct acpi_interface_info *acpi_ut_get_interface(acpi_string interface_name)
344 {
345         struct acpi_interface_info *next_interface;
346
347         next_interface = acpi_gbl_supported_interfaces;
348         while (next_interface) {
349                 if (!ACPI_STRCMP(interface_name, next_interface->name)) {
350                         return (next_interface);
351                 }
352
353                 next_interface = next_interface->next;
354         }
355
356         return (NULL);
357 }
358
359 /*******************************************************************************
360  *
361  * FUNCTION:    acpi_ut_osi_implementation
362  *
363  * PARAMETERS:  walk_state          - Current walk state
364  *
365  * RETURN:      Status
366  *
367  * DESCRIPTION: Implementation of the _OSI predefined control method. When
368  *              an invocation of _OSI is encountered in the system AML,
369  *              control is transferred to this function.
370  *
371  ******************************************************************************/
372
373 acpi_status acpi_ut_osi_implementation(struct acpi_walk_state * walk_state)
374 {
375         union acpi_operand_object *string_desc;
376         union acpi_operand_object *return_desc;
377         struct acpi_interface_info *interface_info;
378         acpi_interface_handler interface_handler;
379         acpi_status status;
380         u32 return_value;
381
382         ACPI_FUNCTION_TRACE(ut_osi_implementation);
383
384         /* Validate the string input argument (from the AML caller) */
385
386         string_desc = walk_state->arguments[0].object;
387         if (!string_desc || (string_desc->common.type != ACPI_TYPE_STRING)) {
388                 return_ACPI_STATUS(AE_TYPE);
389         }
390
391         /* Create a return object */
392
393         return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
394         if (!return_desc) {
395                 return_ACPI_STATUS(AE_NO_MEMORY);
396         }
397
398         /* Default return value is 0, NOT SUPPORTED */
399
400         return_value = 0;
401         status = acpi_os_acquire_mutex(acpi_gbl_osi_mutex, ACPI_WAIT_FOREVER);
402         if (ACPI_FAILURE(status)) {
403                 acpi_ut_remove_reference(return_desc);
404                 return_ACPI_STATUS(status);
405         }
406
407         /* Lookup the interface in the global _OSI list */
408
409         interface_info = acpi_ut_get_interface(string_desc->string.pointer);
410         if (interface_info && !(interface_info->flags & ACPI_OSI_INVALID)) {
411                 /*
412                  * The interface is supported.
413                  * Update the osi_data if necessary. We keep track of the latest
414                  * version of Windows that has been requested by the BIOS.
415                  */
416                 if (interface_info->value > acpi_gbl_osi_data) {
417                         acpi_gbl_osi_data = interface_info->value;
418                 }
419
420                 return_value = ACPI_UINT32_MAX;
421         }
422
423         acpi_os_release_mutex(acpi_gbl_osi_mutex);
424
425         /*
426          * Invoke an optional _OSI interface handler. The host OS may wish
427          * to do some interface-specific handling. For example, warn about
428          * certain interfaces or override the true/false support value.
429          */
430         interface_handler = acpi_gbl_interface_handler;
431         if (interface_handler) {
432                 return_value =
433                     interface_handler(string_desc->string.pointer,
434                                       return_value);
435         }
436
437         ACPI_DEBUG_PRINT_RAW((ACPI_DB_INFO,
438                               "ACPI: BIOS _OSI(\"%s\") is %ssupported\n",
439                               string_desc->string.pointer,
440                               return_value == 0 ? "not " : ""));
441
442         /* Complete the return object */
443
444         return_desc->integer.value = return_value;
445         walk_state->return_desc = return_desc;
446         return_ACPI_STATUS(AE_OK);
447 }