osi.c 13 KB

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