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