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. static void __init acpi_osi_dmi_linux(bool enable,
  242. const struct dmi_system_id *d)
  243. {
  244. pr_notice("DMI detected to setup _OSI(\"Linux\"): %s\n", d->ident);
  245. osi_config.linux_dmi = 1;
  246. __acpi_osi_setup_linux(enable);
  247. }
  248. static int __init dmi_enable_osi_darwin(const struct dmi_system_id *d)
  249. {
  250. acpi_osi_dmi_darwin(true, d);
  251. return 0;
  252. }
  253. static int __init dmi_enable_osi_linux(const struct dmi_system_id *d)
  254. {
  255. acpi_osi_dmi_linux(true, d);
  256. return 0;
  257. }
  258. static int __init dmi_disable_osi_vista(const struct dmi_system_id *d)
  259. {
  260. pr_notice("DMI detected: %s\n", d->ident);
  261. acpi_osi_setup("!Windows 2006");
  262. acpi_osi_setup("!Windows 2006 SP1");
  263. acpi_osi_setup("!Windows 2006 SP2");
  264. return 0;
  265. }
  266. static int __init dmi_disable_osi_win7(const struct dmi_system_id *d)
  267. {
  268. pr_notice("DMI detected: %s\n", d->ident);
  269. acpi_osi_setup("!Windows 2009");
  270. return 0;
  271. }
  272. static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
  273. {
  274. pr_notice("DMI detected: %s\n", d->ident);
  275. acpi_osi_setup("!Windows 2012");
  276. return 0;
  277. }
  278. /*
  279. * Linux default _OSI response behavior is determined by this DMI table.
  280. *
  281. * Note that _OSI("Linux")/_OSI("Darwin") determined here can be overridden
  282. * by acpi_osi=!Linux/acpi_osi=!Darwin command line options.
  283. */
  284. static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
  285. {
  286. .callback = dmi_disable_osi_vista,
  287. .ident = "Fujitsu Siemens",
  288. .matches = {
  289. DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
  290. DMI_MATCH(DMI_PRODUCT_NAME, "ESPRIMO Mobile V5505"),
  291. },
  292. },
  293. {
  294. /*
  295. * There have a NVIF method in MSI GX723 DSDT need call by Nvidia
  296. * driver (e.g. nouveau) when user press brightness hotkey.
  297. * Currently, nouveau driver didn't do the job and it causes there
  298. * have a infinite while loop in DSDT when user press hotkey.
  299. * We add MSI GX723's dmi information to this table for workaround
  300. * this issue.
  301. * Will remove MSI GX723 from the table after nouveau grows support.
  302. */
  303. .callback = dmi_disable_osi_vista,
  304. .ident = "MSI GX723",
  305. .matches = {
  306. DMI_MATCH(DMI_SYS_VENDOR, "Micro-Star International"),
  307. DMI_MATCH(DMI_PRODUCT_NAME, "GX723"),
  308. },
  309. },
  310. {
  311. .callback = dmi_disable_osi_vista,
  312. .ident = "Sony VGN-NS10J_S",
  313. .matches = {
  314. DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
  315. DMI_MATCH(DMI_PRODUCT_NAME, "VGN-NS10J_S"),
  316. },
  317. },
  318. {
  319. .callback = dmi_disable_osi_vista,
  320. .ident = "Sony VGN-SR290J",
  321. .matches = {
  322. DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
  323. DMI_MATCH(DMI_PRODUCT_NAME, "VGN-SR290J"),
  324. },
  325. },
  326. {
  327. .callback = dmi_disable_osi_vista,
  328. .ident = "VGN-NS50B_L",
  329. .matches = {
  330. DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
  331. DMI_MATCH(DMI_PRODUCT_NAME, "VGN-NS50B_L"),
  332. },
  333. },
  334. {
  335. .callback = dmi_disable_osi_vista,
  336. .ident = "VGN-SR19XN",
  337. .matches = {
  338. DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
  339. DMI_MATCH(DMI_PRODUCT_NAME, "VGN-SR19XN"),
  340. },
  341. },
  342. {
  343. .callback = dmi_disable_osi_vista,
  344. .ident = "Toshiba Satellite L355",
  345. .matches = {
  346. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  347. DMI_MATCH(DMI_PRODUCT_VERSION, "Satellite L355"),
  348. },
  349. },
  350. {
  351. .callback = dmi_disable_osi_win7,
  352. .ident = "ASUS K50IJ",
  353. .matches = {
  354. DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
  355. DMI_MATCH(DMI_PRODUCT_NAME, "K50IJ"),
  356. },
  357. },
  358. {
  359. .callback = dmi_disable_osi_vista,
  360. .ident = "Toshiba P305D",
  361. .matches = {
  362. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  363. DMI_MATCH(DMI_PRODUCT_NAME, "Satellite P305D"),
  364. },
  365. },
  366. {
  367. .callback = dmi_disable_osi_vista,
  368. .ident = "Toshiba NB100",
  369. .matches = {
  370. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  371. DMI_MATCH(DMI_PRODUCT_NAME, "NB100"),
  372. },
  373. },
  374. /*
  375. * The wireless hotkey does not work on those machines when
  376. * returning true for _OSI("Windows 2012")
  377. */
  378. {
  379. .callback = dmi_disable_osi_win8,
  380. .ident = "Dell Inspiron 7737",
  381. .matches = {
  382. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  383. DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 7737"),
  384. },
  385. },
  386. {
  387. .callback = dmi_disable_osi_win8,
  388. .ident = "Dell Inspiron 7537",
  389. .matches = {
  390. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  391. DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 7537"),
  392. },
  393. },
  394. {
  395. .callback = dmi_disable_osi_win8,
  396. .ident = "Dell Inspiron 5437",
  397. .matches = {
  398. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  399. DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 5437"),
  400. },
  401. },
  402. {
  403. .callback = dmi_disable_osi_win8,
  404. .ident = "Dell Inspiron 3437",
  405. .matches = {
  406. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  407. DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 3437"),
  408. },
  409. },
  410. {
  411. .callback = dmi_disable_osi_win8,
  412. .ident = "Dell Vostro 3446",
  413. .matches = {
  414. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  415. DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3446"),
  416. },
  417. },
  418. {
  419. .callback = dmi_disable_osi_win8,
  420. .ident = "Dell Vostro 3546",
  421. .matches = {
  422. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  423. DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3546"),
  424. },
  425. },
  426. /*
  427. * BIOS invocation of _OSI(Linux) is almost always a BIOS bug.
  428. * Linux ignores it, except for the machines enumerated below.
  429. */
  430. /*
  431. * Without this this EEEpc exports a non working WMI interface, with
  432. * this it exports a working "good old" eeepc_laptop interface, fixing
  433. * both brightness control, and rfkill not working.
  434. */
  435. {
  436. .callback = dmi_enable_osi_linux,
  437. .ident = "Asus EEE PC 1015PX",
  438. .matches = {
  439. DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer INC."),
  440. DMI_MATCH(DMI_PRODUCT_NAME, "1015PX"),
  441. },
  442. },
  443. /*
  444. * Enable _OSI("Darwin") for all apple platforms.
  445. */
  446. {
  447. .callback = dmi_enable_osi_darwin,
  448. .ident = "Apple hardware",
  449. .matches = {
  450. DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
  451. },
  452. },
  453. {
  454. .callback = dmi_enable_osi_darwin,
  455. .ident = "Apple hardware",
  456. .matches = {
  457. DMI_MATCH(DMI_SYS_VENDOR, "Apple Computer, Inc."),
  458. },
  459. },
  460. {}
  461. };
  462. static __init void acpi_osi_dmi_blacklisted(void)
  463. {
  464. dmi_check_system(acpi_osi_dmi_table);
  465. }
  466. int __init early_acpi_osi_init(void)
  467. {
  468. acpi_osi_dmi_blacklisted();
  469. return 0;
  470. }
  471. int __init acpi_osi_init(void)
  472. {
  473. acpi_install_interface_handler(acpi_osi_handler);
  474. acpi_osi_setup_late();
  475. return 0;
  476. }