ACPICA: Add "Windows 2018" string in the _OSI support
[linux-2.6-microblaze.git] / drivers / acpi / acpica / utosi.c
1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /******************************************************************************
3  *
4  * Module Name: utosi - Support for the _OSI predefined control method
5  *
6  * Copyright (C) 2000 - 2018, Intel Corp.
7  *
8  *****************************************************************************/
9
10 #include <acpi/acpi.h>
11 #include "accommon.h"
12
13 #define _COMPONENT          ACPI_UTILITIES
14 ACPI_MODULE_NAME("utosi")
15
16 /******************************************************************************
17  *
18  * ACPICA policy for new _OSI strings:
19  *
20  * It is the stated policy of ACPICA that new _OSI strings will be integrated
21  * into this module as soon as possible after they are defined. It is strongly
22  * recommended that all ACPICA hosts mirror this policy and integrate any
23  * changes to this module as soon as possible. There are several historical
24  * reasons behind this policy:
25  *
26  * 1) New BIOSs tend to test only the case where the host responds TRUE to
27  *    the latest version of Windows, which would respond to the latest/newest
28  *    _OSI string. Not responding TRUE to the latest version of Windows will
29  *    risk executing untested code paths throughout the DSDT and SSDTs.
30  *
31  * 2) If a new _OSI string is recognized only after a significant delay, this
32  *    has the potential to cause problems on existing working machines because
33  *    of the possibility that a new and different path through the ASL code
34  *    will be executed.
35  *
36  * 3) New _OSI strings are tending to come out about once per year. A delay
37  *    in recognizing a new string for a significant amount of time risks the
38  *    release of another string which only compounds the initial problem.
39  *
40  *****************************************************************************/
41 /*
42  * Strings supported by the _OSI predefined control method (which is
43  * implemented internally within this module.)
44  *
45  * March 2009: Removed "Linux" as this host no longer wants to respond true
46  * for this string. Basically, the only safe OS strings are windows-related
47  * and in many or most cases represent the only test path within the
48  * BIOS-provided ASL code.
49  *
50  * The last element of each entry is used to track the newest version of
51  * Windows that the BIOS has requested.
52  */
53 static struct acpi_interface_info acpi_default_supported_interfaces[] = {
54         /* Operating System Vendor Strings */
55
56         {"Windows 2000", NULL, 0, ACPI_OSI_WIN_2000},   /* Windows 2000 */
57         {"Windows 2001", NULL, 0, ACPI_OSI_WIN_XP},     /* Windows XP */
58         {"Windows 2001 SP1", NULL, 0, ACPI_OSI_WIN_XP_SP1},     /* Windows XP SP1 */
59         {"Windows 2001.1", NULL, 0, ACPI_OSI_WINSRV_2003},      /* Windows Server 2003 */
60         {"Windows 2001 SP2", NULL, 0, ACPI_OSI_WIN_XP_SP2},     /* Windows XP SP2 */
61         {"Windows 2001.1 SP1", NULL, 0, ACPI_OSI_WINSRV_2003_SP1},      /* Windows Server 2003 SP1 - Added 03/2006 */
62         {"Windows 2006", NULL, 0, ACPI_OSI_WIN_VISTA},  /* Windows vista - Added 03/2006 */
63         {"Windows 2006.1", NULL, 0, ACPI_OSI_WINSRV_2008},      /* Windows Server 2008 - Added 09/2009 */
64         {"Windows 2006 SP1", NULL, 0, ACPI_OSI_WIN_VISTA_SP1},  /* Windows Vista SP1 - Added 09/2009 */
65         {"Windows 2006 SP2", NULL, 0, ACPI_OSI_WIN_VISTA_SP2},  /* Windows Vista SP2 - Added 09/2010 */
66         {"Windows 2009", NULL, 0, ACPI_OSI_WIN_7},      /* Windows 7 and Server 2008 R2 - Added 09/2009 */
67         {"Windows 2012", NULL, 0, ACPI_OSI_WIN_8},      /* Windows 8 and Server 2012 - Added 08/2012 */
68         {"Windows 2013", NULL, 0, ACPI_OSI_WIN_8},      /* Windows 8.1 and Server 2012 R2 - Added 01/2014 */
69         {"Windows 2015", NULL, 0, ACPI_OSI_WIN_10},     /* Windows 10 - Added 03/2015 */
70         {"Windows 2016", NULL, 0, ACPI_OSI_WIN_10_RS1}, /* Windows 10 version 1607 - Added 12/2017 */
71         {"Windows 2017", NULL, 0, ACPI_OSI_WIN_10_RS2}, /* Windows 10 version 1703 - Added 12/2017 */
72         {"Windows 2017.2", NULL, 0, ACPI_OSI_WIN_10_RS3},       /* Windows 10 version 1709 - Added 02/2018 */
73         {"Windows 2018", NULL, 0, ACPI_OSI_WIN_10_RS4}, /* Windows 10 version 1803 - Added 11/2018 */
74
75         /* Feature Group Strings */
76
77         {"Extended Address Space Descriptor", NULL, ACPI_OSI_FEATURE, 0},
78
79         /*
80          * All "optional" feature group strings (features that are implemented
81          * by the host) should be dynamically modified to VALID by the host via
82          * acpi_install_interface or acpi_update_interfaces. Such optional feature
83          * group strings are set as INVALID by default here.
84          */
85
86         {"Module Device", NULL, ACPI_OSI_OPTIONAL_FEATURE, 0},
87         {"Processor Device", NULL, ACPI_OSI_OPTIONAL_FEATURE, 0},
88         {"3.0 Thermal Model", NULL, ACPI_OSI_OPTIONAL_FEATURE, 0},
89         {"3.0 _SCP Extensions", NULL, ACPI_OSI_OPTIONAL_FEATURE, 0},
90         {"Processor Aggregator Device", NULL, ACPI_OSI_OPTIONAL_FEATURE, 0}
91 };
92
93 /*******************************************************************************
94  *
95  * FUNCTION:    acpi_ut_initialize_interfaces
96  *
97  * PARAMETERS:  None
98  *
99  * RETURN:      Status
100  *
101  * DESCRIPTION: Initialize the global _OSI supported interfaces list
102  *
103  ******************************************************************************/
104
105 acpi_status acpi_ut_initialize_interfaces(void)
106 {
107         acpi_status status;
108         u32 i;
109
110         status = acpi_os_acquire_mutex(acpi_gbl_osi_mutex, ACPI_WAIT_FOREVER);
111         if (ACPI_FAILURE(status)) {
112                 return (status);
113         }
114
115         acpi_gbl_supported_interfaces = acpi_default_supported_interfaces;
116
117         /* Link the static list of supported interfaces */
118
119         for (i = 0;
120              i < (ACPI_ARRAY_LENGTH(acpi_default_supported_interfaces) - 1);
121              i++) {
122                 acpi_default_supported_interfaces[i].next =
123                     &acpi_default_supported_interfaces[(acpi_size)i + 1];
124         }
125
126         acpi_os_release_mutex(acpi_gbl_osi_mutex);
127         return (AE_OK);
128 }
129
130 /*******************************************************************************
131  *
132  * FUNCTION:    acpi_ut_interface_terminate
133  *
134  * PARAMETERS:  None
135  *
136  * RETURN:      Status
137  *
138  * DESCRIPTION: Delete all interfaces in the global list. Sets
139  *              acpi_gbl_supported_interfaces to NULL.
140  *
141  ******************************************************************************/
142
143 acpi_status acpi_ut_interface_terminate(void)
144 {
145         acpi_status status;
146         struct acpi_interface_info *next_interface;
147
148         status = acpi_os_acquire_mutex(acpi_gbl_osi_mutex, ACPI_WAIT_FOREVER);
149         if (ACPI_FAILURE(status)) {
150                 return (status);
151         }
152
153         next_interface = acpi_gbl_supported_interfaces;
154         while (next_interface) {
155                 acpi_gbl_supported_interfaces = next_interface->next;
156
157                 if (next_interface->flags & ACPI_OSI_DYNAMIC) {
158
159                         /* Only interfaces added at runtime can be freed */
160
161                         ACPI_FREE(next_interface->name);
162                         ACPI_FREE(next_interface);
163                 } else {
164                         /* Interface is in static list. Reset it to invalid or valid. */
165
166                         if (next_interface->flags & ACPI_OSI_DEFAULT_INVALID) {
167                                 next_interface->flags |= ACPI_OSI_INVALID;
168                         } else {
169                                 next_interface->flags &= ~ACPI_OSI_INVALID;
170                         }
171                 }
172
173                 next_interface = acpi_gbl_supported_interfaces;
174         }
175
176         acpi_os_release_mutex(acpi_gbl_osi_mutex);
177         return (AE_OK);
178 }
179
180 /*******************************************************************************
181  *
182  * FUNCTION:    acpi_ut_install_interface
183  *
184  * PARAMETERS:  interface_name      - The interface to install
185  *
186  * RETURN:      Status
187  *
188  * DESCRIPTION: Install the interface into the global interface list.
189  *              Caller MUST hold acpi_gbl_osi_mutex
190  *
191  ******************************************************************************/
192
193 acpi_status acpi_ut_install_interface(acpi_string interface_name)
194 {
195         struct acpi_interface_info *interface_info;
196
197         /* Allocate info block and space for the name string */
198
199         interface_info =
200             ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_interface_info));
201         if (!interface_info) {
202                 return (AE_NO_MEMORY);
203         }
204
205         interface_info->name = ACPI_ALLOCATE_ZEROED(strlen(interface_name) + 1);
206         if (!interface_info->name) {
207                 ACPI_FREE(interface_info);
208                 return (AE_NO_MEMORY);
209         }
210
211         /* Initialize new info and insert at the head of the global list */
212
213         strcpy(interface_info->name, interface_name);
214         interface_info->flags = ACPI_OSI_DYNAMIC;
215         interface_info->next = acpi_gbl_supported_interfaces;
216
217         acpi_gbl_supported_interfaces = interface_info;
218         return (AE_OK);
219 }
220
221 /*******************************************************************************
222  *
223  * FUNCTION:    acpi_ut_remove_interface
224  *
225  * PARAMETERS:  interface_name      - The interface to remove
226  *
227  * RETURN:      Status
228  *
229  * DESCRIPTION: Remove the interface from the global interface list.
230  *              Caller MUST hold acpi_gbl_osi_mutex
231  *
232  ******************************************************************************/
233
234 acpi_status acpi_ut_remove_interface(acpi_string interface_name)
235 {
236         struct acpi_interface_info *previous_interface;
237         struct acpi_interface_info *next_interface;
238
239         previous_interface = next_interface = acpi_gbl_supported_interfaces;
240         while (next_interface) {
241                 if (!strcmp(interface_name, next_interface->name)) {
242                         /*
243                          * Found: name is in either the static list
244                          * or was added at runtime
245                          */
246                         if (next_interface->flags & ACPI_OSI_DYNAMIC) {
247
248                                 /* Interface was added dynamically, remove and free it */
249
250                                 if (previous_interface == next_interface) {
251                                         acpi_gbl_supported_interfaces =
252                                             next_interface->next;
253                                 } else {
254                                         previous_interface->next =
255                                             next_interface->next;
256                                 }
257
258                                 ACPI_FREE(next_interface->name);
259                                 ACPI_FREE(next_interface);
260                         } else {
261                                 /*
262                                  * Interface is in static list. If marked invalid, then
263                                  * it does not actually exist. Else, mark it invalid.
264                                  */
265                                 if (next_interface->flags & ACPI_OSI_INVALID) {
266                                         return (AE_NOT_EXIST);
267                                 }
268
269                                 next_interface->flags |= ACPI_OSI_INVALID;
270                         }
271
272                         return (AE_OK);
273                 }
274
275                 previous_interface = next_interface;
276                 next_interface = next_interface->next;
277         }
278
279         /* Interface was not found */
280
281         return (AE_NOT_EXIST);
282 }
283
284 /*******************************************************************************
285  *
286  * FUNCTION:    acpi_ut_update_interfaces
287  *
288  * PARAMETERS:  action              - Actions to be performed during the
289  *                                    update
290  *
291  * RETURN:      Status
292  *
293  * DESCRIPTION: Update _OSI interface strings, disabling or enabling OS vendor
294  *              strings or/and feature group strings.
295  *              Caller MUST hold acpi_gbl_osi_mutex
296  *
297  ******************************************************************************/
298
299 acpi_status acpi_ut_update_interfaces(u8 action)
300 {
301         struct acpi_interface_info *next_interface;
302
303         next_interface = acpi_gbl_supported_interfaces;
304         while (next_interface) {
305                 if (((next_interface->flags & ACPI_OSI_FEATURE) &&
306                      (action & ACPI_FEATURE_STRINGS)) ||
307                     (!(next_interface->flags & ACPI_OSI_FEATURE) &&
308                      (action & ACPI_VENDOR_STRINGS))) {
309                         if (action & ACPI_DISABLE_INTERFACES) {
310
311                                 /* Mark the interfaces as invalid */
312
313                                 next_interface->flags |= ACPI_OSI_INVALID;
314                         } else {
315                                 /* Mark the interfaces as valid */
316
317                                 next_interface->flags &= ~ACPI_OSI_INVALID;
318                         }
319                 }
320
321                 next_interface = next_interface->next;
322         }
323
324         return (AE_OK);
325 }
326
327 /*******************************************************************************
328  *
329  * FUNCTION:    acpi_ut_get_interface
330  *
331  * PARAMETERS:  interface_name      - The interface to find
332  *
333  * RETURN:      struct acpi_interface_info if found. NULL if not found.
334  *
335  * DESCRIPTION: Search for the specified interface name in the global list.
336  *              Caller MUST hold acpi_gbl_osi_mutex
337  *
338  ******************************************************************************/
339
340 struct acpi_interface_info *acpi_ut_get_interface(acpi_string interface_name)
341 {
342         struct acpi_interface_info *next_interface;
343
344         next_interface = acpi_gbl_supported_interfaces;
345         while (next_interface) {
346                 if (!strcmp(interface_name, next_interface->name)) {
347                         return (next_interface);
348                 }
349
350                 next_interface = next_interface->next;
351         }
352
353         return (NULL);
354 }
355
356 /*******************************************************************************
357  *
358  * FUNCTION:    acpi_ut_osi_implementation
359  *
360  * PARAMETERS:  walk_state          - Current walk state
361  *
362  * RETURN:      Status
363  *              Integer: TRUE (0) if input string is matched
364  *                       FALSE (-1) if string is not matched
365  *
366  * DESCRIPTION: Implementation of the _OSI predefined control method. When
367  *              an invocation of _OSI is encountered in the system AML,
368  *              control is transferred to this function.
369  *
370  * (August 2016)
371  * Note:  _OSI is now defined to return "Ones" to indicate a match, for
372  * compatibility with other ACPI implementations. On a 32-bit DSDT, Ones
373  * is 0xFFFFFFFF. On a 64-bit DSDT, Ones is 0xFFFFFFFFFFFFFFFF
374  * (ACPI_UINT64_MAX).
375  *
376  * This function always returns ACPI_UINT64_MAX for TRUE, and later code
377  * will truncate this to 32 bits if necessary.
378  *
379  ******************************************************************************/
380
381 acpi_status acpi_ut_osi_implementation(struct acpi_walk_state *walk_state)
382 {
383         union acpi_operand_object *string_desc;
384         union acpi_operand_object *return_desc;
385         struct acpi_interface_info *interface_info;
386         acpi_interface_handler interface_handler;
387         acpi_status status;
388         u64 return_value;
389
390         ACPI_FUNCTION_TRACE(ut_osi_implementation);
391
392         /* Validate the string input argument (from the AML caller) */
393
394         string_desc = walk_state->arguments[0].object;
395         if (!string_desc || (string_desc->common.type != ACPI_TYPE_STRING)) {
396                 return_ACPI_STATUS(AE_TYPE);
397         }
398
399         /* Create a return object */
400
401         return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
402         if (!return_desc) {
403                 return_ACPI_STATUS(AE_NO_MEMORY);
404         }
405
406         /* Default return value is 0, NOT SUPPORTED */
407
408         return_value = 0;
409         status = acpi_os_acquire_mutex(acpi_gbl_osi_mutex, ACPI_WAIT_FOREVER);
410         if (ACPI_FAILURE(status)) {
411                 acpi_ut_remove_reference(return_desc);
412                 return_ACPI_STATUS(status);
413         }
414
415         /* Lookup the interface in the global _OSI list */
416
417         interface_info = acpi_ut_get_interface(string_desc->string.pointer);
418         if (interface_info && !(interface_info->flags & ACPI_OSI_INVALID)) {
419                 /*
420                  * The interface is supported.
421                  * Update the osi_data if necessary. We keep track of the latest
422                  * version of Windows that has been requested by the BIOS.
423                  */
424                 if (interface_info->value > acpi_gbl_osi_data) {
425                         acpi_gbl_osi_data = interface_info->value;
426                 }
427
428                 return_value = ACPI_UINT64_MAX;
429         }
430
431         acpi_os_release_mutex(acpi_gbl_osi_mutex);
432
433         /*
434          * Invoke an optional _OSI interface handler. The host OS may wish
435          * to do some interface-specific handling. For example, warn about
436          * certain interfaces or override the true/false support value.
437          */
438         interface_handler = acpi_gbl_interface_handler;
439         if (interface_handler) {
440                 if (interface_handler
441                     (string_desc->string.pointer, (u32)return_value)) {
442                         return_value = ACPI_UINT64_MAX;
443                 }
444         }
445
446         ACPI_DEBUG_PRINT_RAW((ACPI_DB_INFO,
447                               "ACPI: BIOS _OSI(\"%s\") is %ssupported\n",
448                               string_desc->string.pointer,
449                               return_value == 0 ? "not " : ""));
450
451         /* Complete the return object */
452
453         return_desc->integer.value = return_value;
454         walk_state->return_desc = return_desc;
455         return_ACPI_STATUS(AE_OK);
456 }