xref: /openbmc/linux/drivers/acpi/osi.c (revision cce8e04c)
1 /*
2  *  osi.c - _OSI implementation
3  *
4  *  Copyright (C) 2016 Intel Corporation
5  *    Author: Lv Zheng <lv.zheng@intel.com>
6  *
7  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8  *
9  *  This program is free software; you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License as published by
11  *  the Free Software Foundation; either version 2 of the License, or (at
12  *  your option) any later version.
13  *
14  *  This program is distributed in the hope that it will be useful, but
15  *  WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  *  General Public License for more details.
18  *
19  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20  */
21 
22 /* Uncomment next line to get verbose printout */
23 /* #define DEBUG */
24 #define pr_fmt(fmt) "ACPI: " fmt
25 
26 #include <linux/module.h>
27 #include <linux/kernel.h>
28 #include <linux/acpi.h>
29 #include <linux/dmi.h>
30 #include <linux/platform_data/x86/apple.h>
31 
32 #include "internal.h"
33 
34 
35 #define OSI_STRING_LENGTH_MAX	64
36 #define OSI_STRING_ENTRIES_MAX	16
37 
38 struct acpi_osi_entry {
39 	char string[OSI_STRING_LENGTH_MAX];
40 	bool enable;
41 };
42 
43 static struct acpi_osi_config {
44 	u8		default_disabling;
45 	unsigned int	linux_enable:1;
46 	unsigned int	linux_dmi:1;
47 	unsigned int	linux_cmdline:1;
48 	unsigned int	darwin_enable:1;
49 	unsigned int	darwin_dmi:1;
50 	unsigned int	darwin_cmdline:1;
51 } osi_config;
52 
53 static struct acpi_osi_config osi_config;
54 static struct acpi_osi_entry
55 osi_setup_entries[OSI_STRING_ENTRIES_MAX] __initdata = {
56 	{"Module Device", true},
57 	{"Processor Device", true},
58 	{"3.0 _SCP Extensions", true},
59 	{"Processor Aggregator Device", true},
60 	/*
61 	 * Linux-Dell-Video is used by BIOS to disable RTD3 for NVidia graphics
62 	 * cards as RTD3 is not supported by drivers now.  Systems with NVidia
63 	 * cards will hang without RTD3 disabled.
64 	 *
65 	 * Once NVidia drivers officially support RTD3, this _OSI strings can
66 	 * be removed if both new and old graphics cards are supported.
67 	 */
68 	{"Linux-Dell-Video", true},
69 	/*
70 	 * Linux-Lenovo-NV-HDMI-Audio is used by BIOS to power on NVidia's HDMI
71 	 * audio device which is turned off for power-saving in Windows OS.
72 	 * This power management feature observed on some Lenovo Thinkpad
73 	 * systems which will not be able to output audio via HDMI without
74 	 * a BIOS workaround.
75 	 */
76 	{"Linux-Lenovo-NV-HDMI-Audio", true},
77 	/*
78 	 * Linux-HPI-Hybrid-Graphics is used by BIOS to enable dGPU to
79 	 * output video directly to external monitors on HP Inc. mobile
80 	 * workstations as Nvidia and AMD VGA drivers provide limited
81 	 * hybrid graphics supports.
82 	 */
83 	{"Linux-HPI-Hybrid-Graphics", true},
84 };
85 
86 static u32 acpi_osi_handler(acpi_string interface, u32 supported)
87 {
88 	if (!strcmp("Linux", interface)) {
89 		pr_notice_once(FW_BUG
90 			"BIOS _OSI(Linux) query %s%s\n",
91 			osi_config.linux_enable ? "honored" : "ignored",
92 			osi_config.linux_cmdline ? " via cmdline" :
93 			osi_config.linux_dmi ? " via DMI" : "");
94 	}
95 	if (!strcmp("Darwin", interface)) {
96 		pr_notice_once(
97 			"BIOS _OSI(Darwin) query %s%s\n",
98 			osi_config.darwin_enable ? "honored" : "ignored",
99 			osi_config.darwin_cmdline ? " via cmdline" :
100 			osi_config.darwin_dmi ? " via DMI" : "");
101 	}
102 
103 	return supported;
104 }
105 
106 void __init acpi_osi_setup(char *str)
107 {
108 	struct acpi_osi_entry *osi;
109 	bool enable = true;
110 	int i;
111 
112 	if (!acpi_gbl_create_osi_method)
113 		return;
114 
115 	if (str == NULL || *str == '\0') {
116 		pr_info("_OSI method disabled\n");
117 		acpi_gbl_create_osi_method = FALSE;
118 		return;
119 	}
120 
121 	if (*str == '!') {
122 		str++;
123 		if (*str == '\0') {
124 			/* Do not override acpi_osi=!* */
125 			if (!osi_config.default_disabling)
126 				osi_config.default_disabling =
127 					ACPI_DISABLE_ALL_VENDOR_STRINGS;
128 			return;
129 		} else if (*str == '*') {
130 			osi_config.default_disabling = ACPI_DISABLE_ALL_STRINGS;
131 			for (i = 0; i < OSI_STRING_ENTRIES_MAX; i++) {
132 				osi = &osi_setup_entries[i];
133 				osi->enable = false;
134 			}
135 			return;
136 		} else if (*str == '!') {
137 			osi_config.default_disabling = 0;
138 			return;
139 		}
140 		enable = false;
141 	}
142 
143 	for (i = 0; i < OSI_STRING_ENTRIES_MAX; i++) {
144 		osi = &osi_setup_entries[i];
145 		if (!strcmp(osi->string, str)) {
146 			osi->enable = enable;
147 			break;
148 		} else if (osi->string[0] == '\0') {
149 			osi->enable = enable;
150 			strncpy(osi->string, str, OSI_STRING_LENGTH_MAX);
151 			break;
152 		}
153 	}
154 }
155 
156 static void __init __acpi_osi_setup_darwin(bool enable)
157 {
158 	osi_config.darwin_enable = !!enable;
159 	if (enable) {
160 		acpi_osi_setup("!");
161 		acpi_osi_setup("Darwin");
162 	} else {
163 		acpi_osi_setup("!!");
164 		acpi_osi_setup("!Darwin");
165 	}
166 }
167 
168 static void __init acpi_osi_setup_darwin(bool enable)
169 {
170 	/* Override acpi_osi_dmi_blacklisted() */
171 	osi_config.darwin_dmi = 0;
172 	osi_config.darwin_cmdline = 1;
173 	__acpi_osi_setup_darwin(enable);
174 }
175 
176 /*
177  * The story of _OSI(Linux)
178  *
179  * From pre-history through Linux-2.6.22, Linux responded TRUE upon a BIOS
180  * OSI(Linux) query.
181  *
182  * Unfortunately, reference BIOS writers got wind of this and put
183  * OSI(Linux) in their example code, quickly exposing this string as
184  * ill-conceived and opening the door to an un-bounded number of BIOS
185  * incompatibilities.
186  *
187  * For example, OSI(Linux) was used on resume to re-POST a video card on
188  * one system, because Linux at that time could not do a speedy restore in
189  * its native driver. But then upon gaining quick native restore
190  * capability, Linux has no way to tell the BIOS to skip the time-consuming
191  * POST -- putting Linux at a permanent performance disadvantage. On
192  * another system, the BIOS writer used OSI(Linux) to infer native OS
193  * support for IPMI!  On other systems, OSI(Linux) simply got in the way of
194  * Linux claiming to be compatible with other operating systems, exposing
195  * BIOS issues such as skipped device initialization.
196  *
197  * So "Linux" turned out to be a really poor chose of OSI string, and from
198  * Linux-2.6.23 onward we respond FALSE.
199  *
200  * BIOS writers should NOT query _OSI(Linux) on future systems. Linux will
201  * complain on the console when it sees it, and return FALSE. To get Linux
202  * to return TRUE for your system  will require a kernel source update to
203  * add a DMI entry, or boot with "acpi_osi=Linux"
204  */
205 static void __init __acpi_osi_setup_linux(bool enable)
206 {
207 	osi_config.linux_enable = !!enable;
208 	if (enable)
209 		acpi_osi_setup("Linux");
210 	else
211 		acpi_osi_setup("!Linux");
212 }
213 
214 static void __init acpi_osi_setup_linux(bool enable)
215 {
216 	/* Override acpi_osi_dmi_blacklisted() */
217 	osi_config.linux_dmi = 0;
218 	osi_config.linux_cmdline = 1;
219 	__acpi_osi_setup_linux(enable);
220 }
221 
222 /*
223  * Modify the list of "OS Interfaces" reported to BIOS via _OSI
224  *
225  * empty string disables _OSI
226  * string starting with '!' disables that string
227  * otherwise string is added to list, augmenting built-in strings
228  */
229 static void __init acpi_osi_setup_late(void)
230 {
231 	struct acpi_osi_entry *osi;
232 	char *str;
233 	int i;
234 	acpi_status status;
235 
236 	if (osi_config.default_disabling) {
237 		status = acpi_update_interfaces(osi_config.default_disabling);
238 		if (ACPI_SUCCESS(status))
239 			pr_info("Disabled all _OSI OS vendors%s\n",
240 				osi_config.default_disabling ==
241 				ACPI_DISABLE_ALL_STRINGS ?
242 				" and feature groups" : "");
243 	}
244 
245 	for (i = 0; i < OSI_STRING_ENTRIES_MAX; i++) {
246 		osi = &osi_setup_entries[i];
247 		str = osi->string;
248 		if (*str == '\0')
249 			break;
250 		if (osi->enable) {
251 			status = acpi_install_interface(str);
252 			if (ACPI_SUCCESS(status))
253 				pr_info("Added _OSI(%s)\n", str);
254 		} else {
255 			status = acpi_remove_interface(str);
256 			if (ACPI_SUCCESS(status))
257 				pr_info("Deleted _OSI(%s)\n", str);
258 		}
259 	}
260 }
261 
262 static int __init osi_setup(char *str)
263 {
264 	if (str && !strcmp("Linux", str))
265 		acpi_osi_setup_linux(true);
266 	else if (str && !strcmp("!Linux", str))
267 		acpi_osi_setup_linux(false);
268 	else if (str && !strcmp("Darwin", str))
269 		acpi_osi_setup_darwin(true);
270 	else if (str && !strcmp("!Darwin", str))
271 		acpi_osi_setup_darwin(false);
272 	else
273 		acpi_osi_setup(str);
274 
275 	return 1;
276 }
277 __setup("acpi_osi=", osi_setup);
278 
279 bool acpi_osi_is_win8(void)
280 {
281 	return acpi_gbl_osi_data >= ACPI_OSI_WIN_8;
282 }
283 EXPORT_SYMBOL(acpi_osi_is_win8);
284 
285 static void __init acpi_osi_dmi_darwin(void)
286 {
287 	pr_notice("DMI detected to setup _OSI(\"Darwin\"): Apple hardware\n");
288 	osi_config.darwin_dmi = 1;
289 	__acpi_osi_setup_darwin(true);
290 }
291 
292 static void __init acpi_osi_dmi_linux(bool enable,
293 				      const struct dmi_system_id *d)
294 {
295 	pr_notice("DMI detected to setup _OSI(\"Linux\"): %s\n", d->ident);
296 	osi_config.linux_dmi = 1;
297 	__acpi_osi_setup_linux(enable);
298 }
299 
300 static int __init dmi_enable_osi_linux(const struct dmi_system_id *d)
301 {
302 	acpi_osi_dmi_linux(true, d);
303 
304 	return 0;
305 }
306 
307 static int __init dmi_disable_osi_vista(const struct dmi_system_id *d)
308 {
309 	pr_notice("DMI detected: %s\n", d->ident);
310 	acpi_osi_setup("!Windows 2006");
311 	acpi_osi_setup("!Windows 2006 SP1");
312 	acpi_osi_setup("!Windows 2006 SP2");
313 
314 	return 0;
315 }
316 
317 static int __init dmi_disable_osi_win7(const struct dmi_system_id *d)
318 {
319 	pr_notice("DMI detected: %s\n", d->ident);
320 	acpi_osi_setup("!Windows 2009");
321 
322 	return 0;
323 }
324 
325 static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
326 {
327 	pr_notice("DMI detected: %s\n", d->ident);
328 	acpi_osi_setup("!Windows 2012");
329 
330 	return 0;
331 }
332 
333 /*
334  * Linux default _OSI response behavior is determined by this DMI table.
335  *
336  * Note that _OSI("Linux")/_OSI("Darwin") determined here can be overridden
337  * by acpi_osi=!Linux/acpi_osi=!Darwin command line options.
338  */
339 static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
340 	{
341 	.callback = dmi_disable_osi_vista,
342 	.ident = "Fujitsu Siemens",
343 	.matches = {
344 		     DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
345 		     DMI_MATCH(DMI_PRODUCT_NAME, "ESPRIMO Mobile V5505"),
346 		},
347 	},
348 	{
349 	/*
350 	 * There have a NVIF method in MSI GX723 DSDT need call by Nvidia
351 	 * driver (e.g. nouveau) when user press brightness hotkey.
352 	 * Currently, nouveau driver didn't do the job and it causes there
353 	 * have a infinite while loop in DSDT when user press hotkey.
354 	 * We add MSI GX723's dmi information to this table for workaround
355 	 * this issue.
356 	 * Will remove MSI GX723 from the table after nouveau grows support.
357 	 */
358 	.callback = dmi_disable_osi_vista,
359 	.ident = "MSI GX723",
360 	.matches = {
361 		     DMI_MATCH(DMI_SYS_VENDOR, "Micro-Star International"),
362 		     DMI_MATCH(DMI_PRODUCT_NAME, "GX723"),
363 		},
364 	},
365 	{
366 	.callback = dmi_disable_osi_vista,
367 	.ident = "Sony VGN-NS10J_S",
368 	.matches = {
369 		     DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
370 		     DMI_MATCH(DMI_PRODUCT_NAME, "VGN-NS10J_S"),
371 		},
372 	},
373 	{
374 	.callback = dmi_disable_osi_vista,
375 	.ident = "Sony VGN-SR290J",
376 	.matches = {
377 		     DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
378 		     DMI_MATCH(DMI_PRODUCT_NAME, "VGN-SR290J"),
379 		},
380 	},
381 	{
382 	.callback = dmi_disable_osi_vista,
383 	.ident = "VGN-NS50B_L",
384 	.matches = {
385 		     DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
386 		     DMI_MATCH(DMI_PRODUCT_NAME, "VGN-NS50B_L"),
387 		},
388 	},
389 	{
390 	.callback = dmi_disable_osi_vista,
391 	.ident = "VGN-SR19XN",
392 	.matches = {
393 		     DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
394 		     DMI_MATCH(DMI_PRODUCT_NAME, "VGN-SR19XN"),
395 		},
396 	},
397 	{
398 	.callback = dmi_disable_osi_vista,
399 	.ident = "Toshiba Satellite L355",
400 	.matches = {
401 		     DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
402 		     DMI_MATCH(DMI_PRODUCT_VERSION, "Satellite L355"),
403 		},
404 	},
405 	{
406 	.callback = dmi_disable_osi_win7,
407 	.ident = "ASUS K50IJ",
408 	.matches = {
409 		     DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
410 		     DMI_MATCH(DMI_PRODUCT_NAME, "K50IJ"),
411 		},
412 	},
413 	{
414 	.callback = dmi_disable_osi_vista,
415 	.ident = "Toshiba P305D",
416 	.matches = {
417 		     DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
418 		     DMI_MATCH(DMI_PRODUCT_NAME, "Satellite P305D"),
419 		},
420 	},
421 	{
422 	.callback = dmi_disable_osi_vista,
423 	.ident = "Toshiba NB100",
424 	.matches = {
425 		     DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
426 		     DMI_MATCH(DMI_PRODUCT_NAME, "NB100"),
427 		},
428 	},
429 
430 	/*
431 	 * The wireless hotkey does not work on those machines when
432 	 * returning true for _OSI("Windows 2012")
433 	 */
434 	{
435 	.callback = dmi_disable_osi_win8,
436 	.ident = "Dell Inspiron 7737",
437 	.matches = {
438 		    DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
439 		    DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 7737"),
440 		},
441 	},
442 	{
443 	.callback = dmi_disable_osi_win8,
444 	.ident = "Dell Inspiron 7537",
445 	.matches = {
446 		    DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
447 		    DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 7537"),
448 		},
449 	},
450 	{
451 	.callback = dmi_disable_osi_win8,
452 	.ident = "Dell Inspiron 5437",
453 	.matches = {
454 		    DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
455 		    DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 5437"),
456 		},
457 	},
458 	{
459 	.callback = dmi_disable_osi_win8,
460 	.ident = "Dell Inspiron 3437",
461 	.matches = {
462 		    DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
463 		    DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 3437"),
464 		},
465 	},
466 	{
467 	.callback = dmi_disable_osi_win8,
468 	.ident = "Dell Vostro 3446",
469 	.matches = {
470 		    DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
471 		    DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3446"),
472 		},
473 	},
474 	{
475 	.callback = dmi_disable_osi_win8,
476 	.ident = "Dell Vostro 3546",
477 	.matches = {
478 		    DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
479 		    DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3546"),
480 		},
481 	},
482 
483 	/*
484 	 * BIOS invocation of _OSI(Linux) is almost always a BIOS bug.
485 	 * Linux ignores it, except for the machines enumerated below.
486 	 */
487 
488 	/*
489 	 * Without this this EEEpc exports a non working WMI interface, with
490 	 * this it exports a working "good old" eeepc_laptop interface, fixing
491 	 * both brightness control, and rfkill not working.
492 	 */
493 	{
494 	.callback = dmi_enable_osi_linux,
495 	.ident = "Asus EEE PC 1015PX",
496 	.matches = {
497 		     DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer INC."),
498 		     DMI_MATCH(DMI_PRODUCT_NAME, "1015PX"),
499 		},
500 	},
501 	{}
502 };
503 
504 static __init void acpi_osi_dmi_blacklisted(void)
505 {
506 	dmi_check_system(acpi_osi_dmi_table);
507 
508 	/* Enable _OSI("Darwin") for Apple platforms. */
509 	if (x86_apple_machine)
510 		acpi_osi_dmi_darwin();
511 }
512 
513 int __init early_acpi_osi_init(void)
514 {
515 	acpi_osi_dmi_blacklisted();
516 
517 	return 0;
518 }
519 
520 int __init acpi_osi_init(void)
521 {
522 	acpi_install_interface_handler(acpi_osi_handler);
523 	acpi_osi_setup_late();
524 
525 	return 0;
526 }
527