1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * osi.c - _OSI implementation
5 * Copyright (C) 2016 Intel Corporation
6 * Author: Lv Zheng <lv.zheng@intel.com>
9 /* Uncomment next line to get verbose printout */
11 #define pr_fmt(fmt) "ACPI: " fmt
13 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <linux/acpi.h>
16 #include <linux/dmi.h>
17 #include <linux/platform_data/x86/apple.h>
22 #define OSI_STRING_LENGTH_MAX 64
23 #define OSI_STRING_ENTRIES_MAX 16
25 struct acpi_osi_entry {
26 char string[OSI_STRING_LENGTH_MAX];
30 static struct acpi_osi_config {
32 unsigned int linux_enable:1;
33 unsigned int linux_dmi:1;
34 unsigned int linux_cmdline:1;
35 unsigned int darwin_enable:1;
36 unsigned int darwin_dmi:1;
37 unsigned int darwin_cmdline:1;
40 static struct acpi_osi_config osi_config;
41 static struct acpi_osi_entry
42 osi_setup_entries[OSI_STRING_ENTRIES_MAX] __initdata = {
43 {"Module Device", true},
44 {"Processor Device", true},
45 {"3.0 _SCP Extensions", true},
46 {"Processor Aggregator Device", true},
49 static u32 acpi_osi_handler(acpi_string interface, u32 supported)
51 if (!strcmp("Linux", interface)) {
53 "BIOS _OSI(Linux) query %s%s\n",
54 osi_config.linux_enable ? "honored" : "ignored",
55 osi_config.linux_cmdline ? " via cmdline" :
56 osi_config.linux_dmi ? " via DMI" : "");
58 if (!strcmp("Darwin", interface)) {
60 "BIOS _OSI(Darwin) query %s%s\n",
61 osi_config.darwin_enable ? "honored" : "ignored",
62 osi_config.darwin_cmdline ? " via cmdline" :
63 osi_config.darwin_dmi ? " via DMI" : "");
69 void __init acpi_osi_setup(char *str)
71 struct acpi_osi_entry *osi;
75 if (!acpi_gbl_create_osi_method)
78 if (str == NULL || *str == '\0') {
79 pr_info("_OSI method disabled\n");
80 acpi_gbl_create_osi_method = FALSE;
87 /* Do not override acpi_osi=!* */
88 if (!osi_config.default_disabling)
89 osi_config.default_disabling =
90 ACPI_DISABLE_ALL_VENDOR_STRINGS;
92 } else if (*str == '*') {
93 osi_config.default_disabling = ACPI_DISABLE_ALL_STRINGS;
94 for (i = 0; i < OSI_STRING_ENTRIES_MAX; i++) {
95 osi = &osi_setup_entries[i];
99 } else if (*str == '!') {
100 osi_config.default_disabling = 0;
106 for (i = 0; i < OSI_STRING_ENTRIES_MAX; i++) {
107 osi = &osi_setup_entries[i];
108 if (!strcmp(osi->string, str)) {
109 osi->enable = enable;
111 } else if (osi->string[0] == '\0') {
112 osi->enable = enable;
113 strncpy(osi->string, str, OSI_STRING_LENGTH_MAX);
119 static void __init __acpi_osi_setup_darwin(bool enable)
121 osi_config.darwin_enable = !!enable;
124 acpi_osi_setup("Darwin");
126 acpi_osi_setup("!!");
127 acpi_osi_setup("!Darwin");
131 static void __init acpi_osi_setup_darwin(bool enable)
133 /* Override acpi_osi_dmi_blacklisted() */
134 osi_config.darwin_dmi = 0;
135 osi_config.darwin_cmdline = 1;
136 __acpi_osi_setup_darwin(enable);
140 * The story of _OSI(Linux)
142 * From pre-history through Linux-2.6.22, Linux responded TRUE upon a BIOS
145 * Unfortunately, reference BIOS writers got wind of this and put
146 * OSI(Linux) in their example code, quickly exposing this string as
147 * ill-conceived and opening the door to an un-bounded number of BIOS
150 * For example, OSI(Linux) was used on resume to re-POST a video card on
151 * one system, because Linux at that time could not do a speedy restore in
152 * its native driver. But then upon gaining quick native restore
153 * capability, Linux has no way to tell the BIOS to skip the time-consuming
154 * POST -- putting Linux at a permanent performance disadvantage. On
155 * another system, the BIOS writer used OSI(Linux) to infer native OS
156 * support for IPMI! On other systems, OSI(Linux) simply got in the way of
157 * Linux claiming to be compatible with other operating systems, exposing
158 * BIOS issues such as skipped device initialization.
160 * So "Linux" turned out to be a really poor chose of OSI string, and from
161 * Linux-2.6.23 onward we respond FALSE.
163 * BIOS writers should NOT query _OSI(Linux) on future systems. Linux will
164 * complain on the console when it sees it, and return FALSE. To get Linux
165 * to return TRUE for your system will require a kernel source update to
166 * add a DMI entry, or boot with "acpi_osi=Linux"
168 static void __init __acpi_osi_setup_linux(bool enable)
170 osi_config.linux_enable = !!enable;
172 acpi_osi_setup("Linux");
174 acpi_osi_setup("!Linux");
177 static void __init acpi_osi_setup_linux(bool enable)
179 /* Override acpi_osi_dmi_blacklisted() */
180 osi_config.linux_dmi = 0;
181 osi_config.linux_cmdline = 1;
182 __acpi_osi_setup_linux(enable);
186 * Modify the list of "OS Interfaces" reported to BIOS via _OSI
188 * empty string disables _OSI
189 * string starting with '!' disables that string
190 * otherwise string is added to list, augmenting built-in strings
192 static void __init acpi_osi_setup_late(void)
194 struct acpi_osi_entry *osi;
199 if (osi_config.default_disabling) {
200 status = acpi_update_interfaces(osi_config.default_disabling);
201 if (ACPI_SUCCESS(status))
202 pr_info("Disabled all _OSI OS vendors%s\n",
203 osi_config.default_disabling ==
204 ACPI_DISABLE_ALL_STRINGS ?
205 " and feature groups" : "");
208 for (i = 0; i < OSI_STRING_ENTRIES_MAX; i++) {
209 osi = &osi_setup_entries[i];
214 status = acpi_install_interface(str);
215 if (ACPI_SUCCESS(status))
216 pr_info("Added _OSI(%s)\n", str);
218 status = acpi_remove_interface(str);
219 if (ACPI_SUCCESS(status))
220 pr_info("Deleted _OSI(%s)\n", str);
225 static int __init osi_setup(char *str)
227 if (str && !strcmp("Linux", str))
228 acpi_osi_setup_linux(true);
229 else if (str && !strcmp("!Linux", str))
230 acpi_osi_setup_linux(false);
231 else if (str && !strcmp("Darwin", str))
232 acpi_osi_setup_darwin(true);
233 else if (str && !strcmp("!Darwin", str))
234 acpi_osi_setup_darwin(false);
240 __setup("acpi_osi=", osi_setup);
242 bool acpi_osi_is_win8(void)
244 return acpi_gbl_osi_data >= ACPI_OSI_WIN_8;
246 EXPORT_SYMBOL(acpi_osi_is_win8);
248 static void __init acpi_osi_dmi_darwin(void)
250 pr_notice("DMI detected to setup _OSI(\"Darwin\"): Apple hardware\n");
251 osi_config.darwin_dmi = 1;
252 __acpi_osi_setup_darwin(true);
255 static void __init acpi_osi_dmi_linux(bool enable,
256 const struct dmi_system_id *d)
258 pr_notice("DMI detected to setup _OSI(\"Linux\"): %s\n", d->ident);
259 osi_config.linux_dmi = 1;
260 __acpi_osi_setup_linux(enable);
263 static int __init dmi_enable_osi_linux(const struct dmi_system_id *d)
265 acpi_osi_dmi_linux(true, d);
270 static int __init dmi_disable_osi_vista(const struct dmi_system_id *d)
272 pr_notice("DMI detected: %s\n", d->ident);
273 acpi_osi_setup("!Windows 2006");
274 acpi_osi_setup("!Windows 2006 SP1");
275 acpi_osi_setup("!Windows 2006 SP2");
280 static int __init dmi_disable_osi_win7(const struct dmi_system_id *d)
282 pr_notice("DMI detected: %s\n", d->ident);
283 acpi_osi_setup("!Windows 2009");
288 static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
290 pr_notice("DMI detected: %s\n", d->ident);
291 acpi_osi_setup("!Windows 2012");
297 * Linux default _OSI response behavior is determined by this DMI table.
299 * Note that _OSI("Linux")/_OSI("Darwin") determined here can be overridden
300 * by acpi_osi=!Linux/acpi_osi=!Darwin command line options.
302 static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
304 .callback = dmi_disable_osi_vista,
305 .ident = "Fujitsu Siemens",
307 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
308 DMI_MATCH(DMI_PRODUCT_NAME, "ESPRIMO Mobile V5505"),
313 * There have a NVIF method in MSI GX723 DSDT need call by Nvidia
314 * driver (e.g. nouveau) when user press brightness hotkey.
315 * Currently, nouveau driver didn't do the job and it causes there
316 * have a infinite while loop in DSDT when user press hotkey.
317 * We add MSI GX723's dmi information to this table for workaround
319 * Will remove MSI GX723 from the table after nouveau grows support.
321 .callback = dmi_disable_osi_vista,
322 .ident = "MSI GX723",
324 DMI_MATCH(DMI_SYS_VENDOR, "Micro-Star International"),
325 DMI_MATCH(DMI_PRODUCT_NAME, "GX723"),
329 .callback = dmi_disable_osi_vista,
330 .ident = "Sony VGN-NS10J_S",
332 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
333 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-NS10J_S"),
337 .callback = dmi_disable_osi_vista,
338 .ident = "Sony VGN-SR290J",
340 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
341 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-SR290J"),
345 .callback = dmi_disable_osi_vista,
346 .ident = "VGN-NS50B_L",
348 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
349 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-NS50B_L"),
353 .callback = dmi_disable_osi_vista,
354 .ident = "VGN-SR19XN",
356 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
357 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-SR19XN"),
361 .callback = dmi_disable_osi_vista,
362 .ident = "Toshiba Satellite L355",
364 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
365 DMI_MATCH(DMI_PRODUCT_VERSION, "Satellite L355"),
369 .callback = dmi_disable_osi_win7,
370 .ident = "ASUS K50IJ",
372 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
373 DMI_MATCH(DMI_PRODUCT_NAME, "K50IJ"),
377 .callback = dmi_disable_osi_vista,
378 .ident = "Toshiba P305D",
380 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
381 DMI_MATCH(DMI_PRODUCT_NAME, "Satellite P305D"),
385 .callback = dmi_disable_osi_vista,
386 .ident = "Toshiba NB100",
388 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
389 DMI_MATCH(DMI_PRODUCT_NAME, "NB100"),
394 * The wireless hotkey does not work on those machines when
395 * returning true for _OSI("Windows 2012")
398 .callback = dmi_disable_osi_win8,
399 .ident = "Dell Inspiron 7737",
401 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
402 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 7737"),
406 .callback = dmi_disable_osi_win8,
407 .ident = "Dell Inspiron 7537",
409 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
410 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 7537"),
414 .callback = dmi_disable_osi_win8,
415 .ident = "Dell Inspiron 5437",
417 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
418 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 5437"),
422 .callback = dmi_disable_osi_win8,
423 .ident = "Dell Inspiron 3437",
425 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
426 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 3437"),
430 .callback = dmi_disable_osi_win8,
431 .ident = "Dell Vostro 3446",
433 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
434 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3446"),
438 .callback = dmi_disable_osi_win8,
439 .ident = "Dell Vostro 3546",
441 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
442 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3546"),
447 * BIOS invocation of _OSI(Linux) is almost always a BIOS bug.
448 * Linux ignores it, except for the machines enumerated below.
452 * Without this EEEpc exports a non working WMI interface, with
453 * this it exports a working "good old" eeepc_laptop interface,
454 * fixing both brightness control, and rfkill not working.
457 .callback = dmi_enable_osi_linux,
458 .ident = "Asus EEE PC 1015PX",
460 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer INC."),
461 DMI_MATCH(DMI_PRODUCT_NAME, "1015PX"),
467 static __init void acpi_osi_dmi_blacklisted(void)
469 dmi_check_system(acpi_osi_dmi_table);
471 /* Enable _OSI("Darwin") for Apple platforms. */
472 if (x86_apple_machine)
473 acpi_osi_dmi_darwin();
476 int __init early_acpi_osi_init(void)
478 acpi_osi_dmi_blacklisted();
483 int __init acpi_osi_init(void)
485 acpi_install_interface_handler(acpi_osi_handler);
486 acpi_osi_setup_late();