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