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