intel_opregion.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087
  1. /*
  2. * Copyright 2008 Intel Corporation <hong.liu@intel.com>
  3. * Copyright 2008 Red Hat <mjg@redhat.com>
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining
  6. * a copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sub license, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject to
  11. * the following conditions:
  12. *
  13. * The above copyright notice and this permission notice (including the
  14. * next paragraph) shall be included in all copies or substantial
  15. * portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  20. * NON-INFRINGEMENT. IN NO EVENT SHALL INTEL AND/OR ITS SUPPLIERS BE
  21. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  22. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  23. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  24. * SOFTWARE.
  25. *
  26. */
  27. #include <linux/acpi.h>
  28. #include <linux/dmi.h>
  29. #include <acpi/video.h>
  30. #include <drm/drmP.h>
  31. #include <drm/i915_drm.h>
  32. #include "i915_drv.h"
  33. #include "intel_drv.h"
  34. #define OPREGION_HEADER_OFFSET 0
  35. #define OPREGION_ACPI_OFFSET 0x100
  36. #define ACPI_CLID 0x01ac /* current lid state indicator */
  37. #define ACPI_CDCK 0x01b0 /* current docking state indicator */
  38. #define OPREGION_SWSCI_OFFSET 0x200
  39. #define OPREGION_ASLE_OFFSET 0x300
  40. #define OPREGION_VBT_OFFSET 0x400
  41. #define OPREGION_ASLE_EXT_OFFSET 0x1C00
  42. #define OPREGION_SIGNATURE "IntelGraphicsMem"
  43. #define MBOX_ACPI (1<<0)
  44. #define MBOX_SWSCI (1<<1)
  45. #define MBOX_ASLE (1<<2)
  46. #define MBOX_ASLE_EXT (1<<4)
  47. struct opregion_header {
  48. u8 signature[16];
  49. u32 size;
  50. u32 opregion_ver;
  51. u8 bios_ver[32];
  52. u8 vbios_ver[16];
  53. u8 driver_ver[16];
  54. u32 mboxes;
  55. u32 driver_model;
  56. u32 pcon;
  57. u8 dver[32];
  58. u8 rsvd[124];
  59. } __packed;
  60. /* OpRegion mailbox #1: public ACPI methods */
  61. struct opregion_acpi {
  62. u32 drdy; /* driver readiness */
  63. u32 csts; /* notification status */
  64. u32 cevt; /* current event */
  65. u8 rsvd1[20];
  66. u32 didl[8]; /* supported display devices ID list */
  67. u32 cpdl[8]; /* currently presented display list */
  68. u32 cadl[8]; /* currently active display list */
  69. u32 nadl[8]; /* next active devices list */
  70. u32 aslp; /* ASL sleep time-out */
  71. u32 tidx; /* toggle table index */
  72. u32 chpd; /* current hotplug enable indicator */
  73. u32 clid; /* current lid state*/
  74. u32 cdck; /* current docking state */
  75. u32 sxsw; /* Sx state resume */
  76. u32 evts; /* ASL supported events */
  77. u32 cnot; /* current OS notification */
  78. u32 nrdy; /* driver status */
  79. u32 did2[7]; /* extended supported display devices ID list */
  80. u32 cpd2[7]; /* extended attached display devices list */
  81. u8 rsvd2[4];
  82. } __packed;
  83. /* OpRegion mailbox #2: SWSCI */
  84. struct opregion_swsci {
  85. u32 scic; /* SWSCI command|status|data */
  86. u32 parm; /* command parameters */
  87. u32 dslp; /* driver sleep time-out */
  88. u8 rsvd[244];
  89. } __packed;
  90. /* OpRegion mailbox #3: ASLE */
  91. struct opregion_asle {
  92. u32 ardy; /* driver readiness */
  93. u32 aslc; /* ASLE interrupt command */
  94. u32 tche; /* technology enabled indicator */
  95. u32 alsi; /* current ALS illuminance reading */
  96. u32 bclp; /* backlight brightness to set */
  97. u32 pfit; /* panel fitting state */
  98. u32 cblv; /* current brightness level */
  99. u16 bclm[20]; /* backlight level duty cycle mapping table */
  100. u32 cpfm; /* current panel fitting mode */
  101. u32 epfm; /* enabled panel fitting modes */
  102. u8 plut[74]; /* panel LUT and identifier */
  103. u32 pfmb; /* PWM freq and min brightness */
  104. u32 cddv; /* color correction default values */
  105. u32 pcft; /* power conservation features */
  106. u32 srot; /* supported rotation angles */
  107. u32 iuer; /* IUER events */
  108. u64 fdss;
  109. u32 fdsp;
  110. u32 stat;
  111. u64 rvda; /* Physical address of raw vbt data */
  112. u32 rvds; /* Size of raw vbt data */
  113. u8 rsvd[58];
  114. } __packed;
  115. /* OpRegion mailbox #5: ASLE ext */
  116. struct opregion_asle_ext {
  117. u32 phed; /* Panel Header */
  118. u8 bddc[256]; /* Panel EDID */
  119. u8 rsvd[764];
  120. } __packed;
  121. /* Driver readiness indicator */
  122. #define ASLE_ARDY_READY (1 << 0)
  123. #define ASLE_ARDY_NOT_READY (0 << 0)
  124. /* ASLE Interrupt Command (ASLC) bits */
  125. #define ASLC_SET_ALS_ILLUM (1 << 0)
  126. #define ASLC_SET_BACKLIGHT (1 << 1)
  127. #define ASLC_SET_PFIT (1 << 2)
  128. #define ASLC_SET_PWM_FREQ (1 << 3)
  129. #define ASLC_SUPPORTED_ROTATION_ANGLES (1 << 4)
  130. #define ASLC_BUTTON_ARRAY (1 << 5)
  131. #define ASLC_CONVERTIBLE_INDICATOR (1 << 6)
  132. #define ASLC_DOCKING_INDICATOR (1 << 7)
  133. #define ASLC_ISCT_STATE_CHANGE (1 << 8)
  134. #define ASLC_REQ_MSK 0x1ff
  135. /* response bits */
  136. #define ASLC_ALS_ILLUM_FAILED (1 << 10)
  137. #define ASLC_BACKLIGHT_FAILED (1 << 12)
  138. #define ASLC_PFIT_FAILED (1 << 14)
  139. #define ASLC_PWM_FREQ_FAILED (1 << 16)
  140. #define ASLC_ROTATION_ANGLES_FAILED (1 << 18)
  141. #define ASLC_BUTTON_ARRAY_FAILED (1 << 20)
  142. #define ASLC_CONVERTIBLE_FAILED (1 << 22)
  143. #define ASLC_DOCKING_FAILED (1 << 24)
  144. #define ASLC_ISCT_STATE_FAILED (1 << 26)
  145. /* Technology enabled indicator */
  146. #define ASLE_TCHE_ALS_EN (1 << 0)
  147. #define ASLE_TCHE_BLC_EN (1 << 1)
  148. #define ASLE_TCHE_PFIT_EN (1 << 2)
  149. #define ASLE_TCHE_PFMB_EN (1 << 3)
  150. /* ASLE backlight brightness to set */
  151. #define ASLE_BCLP_VALID (1<<31)
  152. #define ASLE_BCLP_MSK (~(1<<31))
  153. /* ASLE panel fitting request */
  154. #define ASLE_PFIT_VALID (1<<31)
  155. #define ASLE_PFIT_CENTER (1<<0)
  156. #define ASLE_PFIT_STRETCH_TEXT (1<<1)
  157. #define ASLE_PFIT_STRETCH_GFX (1<<2)
  158. /* PWM frequency and minimum brightness */
  159. #define ASLE_PFMB_BRIGHTNESS_MASK (0xff)
  160. #define ASLE_PFMB_BRIGHTNESS_VALID (1<<8)
  161. #define ASLE_PFMB_PWM_MASK (0x7ffffe00)
  162. #define ASLE_PFMB_PWM_VALID (1<<31)
  163. #define ASLE_CBLV_VALID (1<<31)
  164. /* IUER */
  165. #define ASLE_IUER_DOCKING (1 << 7)
  166. #define ASLE_IUER_CONVERTIBLE (1 << 6)
  167. #define ASLE_IUER_ROTATION_LOCK_BTN (1 << 4)
  168. #define ASLE_IUER_VOLUME_DOWN_BTN (1 << 3)
  169. #define ASLE_IUER_VOLUME_UP_BTN (1 << 2)
  170. #define ASLE_IUER_WINDOWS_BTN (1 << 1)
  171. #define ASLE_IUER_POWER_BTN (1 << 0)
  172. /* Software System Control Interrupt (SWSCI) */
  173. #define SWSCI_SCIC_INDICATOR (1 << 0)
  174. #define SWSCI_SCIC_MAIN_FUNCTION_SHIFT 1
  175. #define SWSCI_SCIC_MAIN_FUNCTION_MASK (0xf << 1)
  176. #define SWSCI_SCIC_SUB_FUNCTION_SHIFT 8
  177. #define SWSCI_SCIC_SUB_FUNCTION_MASK (0xff << 8)
  178. #define SWSCI_SCIC_EXIT_PARAMETER_SHIFT 8
  179. #define SWSCI_SCIC_EXIT_PARAMETER_MASK (0xff << 8)
  180. #define SWSCI_SCIC_EXIT_STATUS_SHIFT 5
  181. #define SWSCI_SCIC_EXIT_STATUS_MASK (7 << 5)
  182. #define SWSCI_SCIC_EXIT_STATUS_SUCCESS 1
  183. #define SWSCI_FUNCTION_CODE(main, sub) \
  184. ((main) << SWSCI_SCIC_MAIN_FUNCTION_SHIFT | \
  185. (sub) << SWSCI_SCIC_SUB_FUNCTION_SHIFT)
  186. /* SWSCI: Get BIOS Data (GBDA) */
  187. #define SWSCI_GBDA 4
  188. #define SWSCI_GBDA_SUPPORTED_CALLS SWSCI_FUNCTION_CODE(SWSCI_GBDA, 0)
  189. #define SWSCI_GBDA_REQUESTED_CALLBACKS SWSCI_FUNCTION_CODE(SWSCI_GBDA, 1)
  190. #define SWSCI_GBDA_BOOT_DISPLAY_PREF SWSCI_FUNCTION_CODE(SWSCI_GBDA, 4)
  191. #define SWSCI_GBDA_PANEL_DETAILS SWSCI_FUNCTION_CODE(SWSCI_GBDA, 5)
  192. #define SWSCI_GBDA_TV_STANDARD SWSCI_FUNCTION_CODE(SWSCI_GBDA, 6)
  193. #define SWSCI_GBDA_INTERNAL_GRAPHICS SWSCI_FUNCTION_CODE(SWSCI_GBDA, 7)
  194. #define SWSCI_GBDA_SPREAD_SPECTRUM SWSCI_FUNCTION_CODE(SWSCI_GBDA, 10)
  195. /* SWSCI: System BIOS Callbacks (SBCB) */
  196. #define SWSCI_SBCB 6
  197. #define SWSCI_SBCB_SUPPORTED_CALLBACKS SWSCI_FUNCTION_CODE(SWSCI_SBCB, 0)
  198. #define SWSCI_SBCB_INIT_COMPLETION SWSCI_FUNCTION_CODE(SWSCI_SBCB, 1)
  199. #define SWSCI_SBCB_PRE_HIRES_SET_MODE SWSCI_FUNCTION_CODE(SWSCI_SBCB, 3)
  200. #define SWSCI_SBCB_POST_HIRES_SET_MODE SWSCI_FUNCTION_CODE(SWSCI_SBCB, 4)
  201. #define SWSCI_SBCB_DISPLAY_SWITCH SWSCI_FUNCTION_CODE(SWSCI_SBCB, 5)
  202. #define SWSCI_SBCB_SET_TV_FORMAT SWSCI_FUNCTION_CODE(SWSCI_SBCB, 6)
  203. #define SWSCI_SBCB_ADAPTER_POWER_STATE SWSCI_FUNCTION_CODE(SWSCI_SBCB, 7)
  204. #define SWSCI_SBCB_DISPLAY_POWER_STATE SWSCI_FUNCTION_CODE(SWSCI_SBCB, 8)
  205. #define SWSCI_SBCB_SET_BOOT_DISPLAY SWSCI_FUNCTION_CODE(SWSCI_SBCB, 9)
  206. #define SWSCI_SBCB_SET_PANEL_DETAILS SWSCI_FUNCTION_CODE(SWSCI_SBCB, 10)
  207. #define SWSCI_SBCB_SET_INTERNAL_GFX SWSCI_FUNCTION_CODE(SWSCI_SBCB, 11)
  208. #define SWSCI_SBCB_POST_HIRES_TO_DOS_FS SWSCI_FUNCTION_CODE(SWSCI_SBCB, 16)
  209. #define SWSCI_SBCB_SUSPEND_RESUME SWSCI_FUNCTION_CODE(SWSCI_SBCB, 17)
  210. #define SWSCI_SBCB_SET_SPREAD_SPECTRUM SWSCI_FUNCTION_CODE(SWSCI_SBCB, 18)
  211. #define SWSCI_SBCB_POST_VBE_PM SWSCI_FUNCTION_CODE(SWSCI_SBCB, 19)
  212. #define SWSCI_SBCB_ENABLE_DISABLE_AUDIO SWSCI_FUNCTION_CODE(SWSCI_SBCB, 21)
  213. /*
  214. * ACPI Specification, Revision 5.0, Appendix B.3.2 _DOD (Enumerate All Devices
  215. * Attached to the Display Adapter).
  216. */
  217. #define ACPI_DISPLAY_INDEX_SHIFT 0
  218. #define ACPI_DISPLAY_INDEX_MASK (0xf << 0)
  219. #define ACPI_DISPLAY_PORT_ATTACHMENT_SHIFT 4
  220. #define ACPI_DISPLAY_PORT_ATTACHMENT_MASK (0xf << 4)
  221. #define ACPI_DISPLAY_TYPE_SHIFT 8
  222. #define ACPI_DISPLAY_TYPE_MASK (0xf << 8)
  223. #define ACPI_DISPLAY_TYPE_OTHER (0 << 8)
  224. #define ACPI_DISPLAY_TYPE_VGA (1 << 8)
  225. #define ACPI_DISPLAY_TYPE_TV (2 << 8)
  226. #define ACPI_DISPLAY_TYPE_EXTERNAL_DIGITAL (3 << 8)
  227. #define ACPI_DISPLAY_TYPE_INTERNAL_DIGITAL (4 << 8)
  228. #define ACPI_VENDOR_SPECIFIC_SHIFT 12
  229. #define ACPI_VENDOR_SPECIFIC_MASK (0xf << 12)
  230. #define ACPI_BIOS_CAN_DETECT (1 << 16)
  231. #define ACPI_DEPENDS_ON_VGA (1 << 17)
  232. #define ACPI_PIPE_ID_SHIFT 18
  233. #define ACPI_PIPE_ID_MASK (7 << 18)
  234. #define ACPI_DEVICE_ID_SCHEME (1 << 31)
  235. #define MAX_DSLP 1500
  236. static int swsci(struct drm_i915_private *dev_priv,
  237. u32 function, u32 parm, u32 *parm_out)
  238. {
  239. struct opregion_swsci *swsci = dev_priv->opregion.swsci;
  240. struct pci_dev *pdev = dev_priv->drm.pdev;
  241. u32 main_function, sub_function, scic;
  242. u16 swsci_val;
  243. u32 dslp;
  244. if (!swsci)
  245. return -ENODEV;
  246. main_function = (function & SWSCI_SCIC_MAIN_FUNCTION_MASK) >>
  247. SWSCI_SCIC_MAIN_FUNCTION_SHIFT;
  248. sub_function = (function & SWSCI_SCIC_SUB_FUNCTION_MASK) >>
  249. SWSCI_SCIC_SUB_FUNCTION_SHIFT;
  250. /* Check if we can call the function. See swsci_setup for details. */
  251. if (main_function == SWSCI_SBCB) {
  252. if ((dev_priv->opregion.swsci_sbcb_sub_functions &
  253. (1 << sub_function)) == 0)
  254. return -EINVAL;
  255. } else if (main_function == SWSCI_GBDA) {
  256. if ((dev_priv->opregion.swsci_gbda_sub_functions &
  257. (1 << sub_function)) == 0)
  258. return -EINVAL;
  259. }
  260. /* Driver sleep timeout in ms. */
  261. dslp = swsci->dslp;
  262. if (!dslp) {
  263. /* The spec says 2ms should be the default, but it's too small
  264. * for some machines. */
  265. dslp = 50;
  266. } else if (dslp > MAX_DSLP) {
  267. /* Hey bios, trust must be earned. */
  268. DRM_INFO_ONCE("ACPI BIOS requests an excessive sleep of %u ms, "
  269. "using %u ms instead\n", dslp, MAX_DSLP);
  270. dslp = MAX_DSLP;
  271. }
  272. /* The spec tells us to do this, but we are the only user... */
  273. scic = swsci->scic;
  274. if (scic & SWSCI_SCIC_INDICATOR) {
  275. DRM_DEBUG_DRIVER("SWSCI request already in progress\n");
  276. return -EBUSY;
  277. }
  278. scic = function | SWSCI_SCIC_INDICATOR;
  279. swsci->parm = parm;
  280. swsci->scic = scic;
  281. /* Ensure SCI event is selected and event trigger is cleared. */
  282. pci_read_config_word(pdev, SWSCI, &swsci_val);
  283. if (!(swsci_val & SWSCI_SCISEL) || (swsci_val & SWSCI_GSSCIE)) {
  284. swsci_val |= SWSCI_SCISEL;
  285. swsci_val &= ~SWSCI_GSSCIE;
  286. pci_write_config_word(pdev, SWSCI, swsci_val);
  287. }
  288. /* Use event trigger to tell bios to check the mail. */
  289. swsci_val |= SWSCI_GSSCIE;
  290. pci_write_config_word(pdev, SWSCI, swsci_val);
  291. /* Poll for the result. */
  292. #define C (((scic = swsci->scic) & SWSCI_SCIC_INDICATOR) == 0)
  293. if (wait_for(C, dslp)) {
  294. DRM_DEBUG_DRIVER("SWSCI request timed out\n");
  295. return -ETIMEDOUT;
  296. }
  297. scic = (scic & SWSCI_SCIC_EXIT_STATUS_MASK) >>
  298. SWSCI_SCIC_EXIT_STATUS_SHIFT;
  299. /* Note: scic == 0 is an error! */
  300. if (scic != SWSCI_SCIC_EXIT_STATUS_SUCCESS) {
  301. DRM_DEBUG_DRIVER("SWSCI request error %u\n", scic);
  302. return -EIO;
  303. }
  304. if (parm_out)
  305. *parm_out = swsci->parm;
  306. return 0;
  307. #undef C
  308. }
  309. #define DISPLAY_TYPE_CRT 0
  310. #define DISPLAY_TYPE_TV 1
  311. #define DISPLAY_TYPE_EXTERNAL_FLAT_PANEL 2
  312. #define DISPLAY_TYPE_INTERNAL_FLAT_PANEL 3
  313. int intel_opregion_notify_encoder(struct intel_encoder *intel_encoder,
  314. bool enable)
  315. {
  316. struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
  317. u32 parm = 0;
  318. u32 type = 0;
  319. u32 port;
  320. /* don't care about old stuff for now */
  321. if (!HAS_DDI(dev_priv))
  322. return 0;
  323. if (intel_encoder->type == INTEL_OUTPUT_DSI)
  324. port = 0;
  325. else
  326. port = intel_ddi_get_encoder_port(intel_encoder);
  327. if (port == PORT_E) {
  328. port = 0;
  329. } else {
  330. parm |= 1 << port;
  331. port++;
  332. }
  333. if (!enable)
  334. parm |= 4 << 8;
  335. switch (intel_encoder->type) {
  336. case INTEL_OUTPUT_ANALOG:
  337. type = DISPLAY_TYPE_CRT;
  338. break;
  339. case INTEL_OUTPUT_UNKNOWN:
  340. case INTEL_OUTPUT_DP:
  341. case INTEL_OUTPUT_HDMI:
  342. case INTEL_OUTPUT_DP_MST:
  343. type = DISPLAY_TYPE_EXTERNAL_FLAT_PANEL;
  344. break;
  345. case INTEL_OUTPUT_EDP:
  346. case INTEL_OUTPUT_DSI:
  347. type = DISPLAY_TYPE_INTERNAL_FLAT_PANEL;
  348. break;
  349. default:
  350. WARN_ONCE(1, "unsupported intel_encoder type %d\n",
  351. intel_encoder->type);
  352. return -EINVAL;
  353. }
  354. parm |= type << (16 + port * 3);
  355. return swsci(dev_priv, SWSCI_SBCB_DISPLAY_POWER_STATE, parm, NULL);
  356. }
  357. static const struct {
  358. pci_power_t pci_power_state;
  359. u32 parm;
  360. } power_state_map[] = {
  361. { PCI_D0, 0x00 },
  362. { PCI_D1, 0x01 },
  363. { PCI_D2, 0x02 },
  364. { PCI_D3hot, 0x04 },
  365. { PCI_D3cold, 0x04 },
  366. };
  367. int intel_opregion_notify_adapter(struct drm_i915_private *dev_priv,
  368. pci_power_t state)
  369. {
  370. int i;
  371. if (!HAS_DDI(dev_priv))
  372. return 0;
  373. for (i = 0; i < ARRAY_SIZE(power_state_map); i++) {
  374. if (state == power_state_map[i].pci_power_state)
  375. return swsci(dev_priv, SWSCI_SBCB_ADAPTER_POWER_STATE,
  376. power_state_map[i].parm, NULL);
  377. }
  378. return -EINVAL;
  379. }
  380. static u32 asle_set_backlight(struct drm_i915_private *dev_priv, u32 bclp)
  381. {
  382. struct intel_connector *connector;
  383. struct opregion_asle *asle = dev_priv->opregion.asle;
  384. struct drm_device *dev = &dev_priv->drm;
  385. DRM_DEBUG_DRIVER("bclp = 0x%08x\n", bclp);
  386. if (acpi_video_get_backlight_type() == acpi_backlight_native) {
  387. DRM_DEBUG_KMS("opregion backlight request ignored\n");
  388. return 0;
  389. }
  390. if (!(bclp & ASLE_BCLP_VALID))
  391. return ASLC_BACKLIGHT_FAILED;
  392. bclp &= ASLE_BCLP_MSK;
  393. if (bclp > 255)
  394. return ASLC_BACKLIGHT_FAILED;
  395. drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
  396. /*
  397. * Update backlight on all connectors that support backlight (usually
  398. * only one).
  399. */
  400. DRM_DEBUG_KMS("updating opregion backlight %d/255\n", bclp);
  401. for_each_intel_connector(dev, connector)
  402. intel_panel_set_backlight_acpi(connector, bclp, 255);
  403. asle->cblv = DIV_ROUND_UP(bclp * 100, 255) | ASLE_CBLV_VALID;
  404. drm_modeset_unlock(&dev->mode_config.connection_mutex);
  405. return 0;
  406. }
  407. static u32 asle_set_als_illum(struct drm_i915_private *dev_priv, u32 alsi)
  408. {
  409. /* alsi is the current ALS reading in lux. 0 indicates below sensor
  410. range, 0xffff indicates above sensor range. 1-0xfffe are valid */
  411. DRM_DEBUG_DRIVER("Illum is not supported\n");
  412. return ASLC_ALS_ILLUM_FAILED;
  413. }
  414. static u32 asle_set_pwm_freq(struct drm_i915_private *dev_priv, u32 pfmb)
  415. {
  416. DRM_DEBUG_DRIVER("PWM freq is not supported\n");
  417. return ASLC_PWM_FREQ_FAILED;
  418. }
  419. static u32 asle_set_pfit(struct drm_i915_private *dev_priv, u32 pfit)
  420. {
  421. /* Panel fitting is currently controlled by the X code, so this is a
  422. noop until modesetting support works fully */
  423. DRM_DEBUG_DRIVER("Pfit is not supported\n");
  424. return ASLC_PFIT_FAILED;
  425. }
  426. static u32 asle_set_supported_rotation_angles(struct drm_i915_private *dev_priv, u32 srot)
  427. {
  428. DRM_DEBUG_DRIVER("SROT is not supported\n");
  429. return ASLC_ROTATION_ANGLES_FAILED;
  430. }
  431. static u32 asle_set_button_array(struct drm_i915_private *dev_priv, u32 iuer)
  432. {
  433. if (!iuer)
  434. DRM_DEBUG_DRIVER("Button array event is not supported (nothing)\n");
  435. if (iuer & ASLE_IUER_ROTATION_LOCK_BTN)
  436. DRM_DEBUG_DRIVER("Button array event is not supported (rotation lock)\n");
  437. if (iuer & ASLE_IUER_VOLUME_DOWN_BTN)
  438. DRM_DEBUG_DRIVER("Button array event is not supported (volume down)\n");
  439. if (iuer & ASLE_IUER_VOLUME_UP_BTN)
  440. DRM_DEBUG_DRIVER("Button array event is not supported (volume up)\n");
  441. if (iuer & ASLE_IUER_WINDOWS_BTN)
  442. DRM_DEBUG_DRIVER("Button array event is not supported (windows)\n");
  443. if (iuer & ASLE_IUER_POWER_BTN)
  444. DRM_DEBUG_DRIVER("Button array event is not supported (power)\n");
  445. return ASLC_BUTTON_ARRAY_FAILED;
  446. }
  447. static u32 asle_set_convertible(struct drm_i915_private *dev_priv, u32 iuer)
  448. {
  449. if (iuer & ASLE_IUER_CONVERTIBLE)
  450. DRM_DEBUG_DRIVER("Convertible is not supported (clamshell)\n");
  451. else
  452. DRM_DEBUG_DRIVER("Convertible is not supported (slate)\n");
  453. return ASLC_CONVERTIBLE_FAILED;
  454. }
  455. static u32 asle_set_docking(struct drm_i915_private *dev_priv, u32 iuer)
  456. {
  457. if (iuer & ASLE_IUER_DOCKING)
  458. DRM_DEBUG_DRIVER("Docking is not supported (docked)\n");
  459. else
  460. DRM_DEBUG_DRIVER("Docking is not supported (undocked)\n");
  461. return ASLC_DOCKING_FAILED;
  462. }
  463. static u32 asle_isct_state(struct drm_i915_private *dev_priv)
  464. {
  465. DRM_DEBUG_DRIVER("ISCT is not supported\n");
  466. return ASLC_ISCT_STATE_FAILED;
  467. }
  468. static void asle_work(struct work_struct *work)
  469. {
  470. struct intel_opregion *opregion =
  471. container_of(work, struct intel_opregion, asle_work);
  472. struct drm_i915_private *dev_priv =
  473. container_of(opregion, struct drm_i915_private, opregion);
  474. struct opregion_asle *asle = dev_priv->opregion.asle;
  475. u32 aslc_stat = 0;
  476. u32 aslc_req;
  477. if (!asle)
  478. return;
  479. aslc_req = asle->aslc;
  480. if (!(aslc_req & ASLC_REQ_MSK)) {
  481. DRM_DEBUG_DRIVER("No request on ASLC interrupt 0x%08x\n",
  482. aslc_req);
  483. return;
  484. }
  485. if (aslc_req & ASLC_SET_ALS_ILLUM)
  486. aslc_stat |= asle_set_als_illum(dev_priv, asle->alsi);
  487. if (aslc_req & ASLC_SET_BACKLIGHT)
  488. aslc_stat |= asle_set_backlight(dev_priv, asle->bclp);
  489. if (aslc_req & ASLC_SET_PFIT)
  490. aslc_stat |= asle_set_pfit(dev_priv, asle->pfit);
  491. if (aslc_req & ASLC_SET_PWM_FREQ)
  492. aslc_stat |= asle_set_pwm_freq(dev_priv, asle->pfmb);
  493. if (aslc_req & ASLC_SUPPORTED_ROTATION_ANGLES)
  494. aslc_stat |= asle_set_supported_rotation_angles(dev_priv,
  495. asle->srot);
  496. if (aslc_req & ASLC_BUTTON_ARRAY)
  497. aslc_stat |= asle_set_button_array(dev_priv, asle->iuer);
  498. if (aslc_req & ASLC_CONVERTIBLE_INDICATOR)
  499. aslc_stat |= asle_set_convertible(dev_priv, asle->iuer);
  500. if (aslc_req & ASLC_DOCKING_INDICATOR)
  501. aslc_stat |= asle_set_docking(dev_priv, asle->iuer);
  502. if (aslc_req & ASLC_ISCT_STATE_CHANGE)
  503. aslc_stat |= asle_isct_state(dev_priv);
  504. asle->aslc = aslc_stat;
  505. }
  506. void intel_opregion_asle_intr(struct drm_i915_private *dev_priv)
  507. {
  508. if (dev_priv->opregion.asle)
  509. schedule_work(&dev_priv->opregion.asle_work);
  510. }
  511. #define ACPI_EV_DISPLAY_SWITCH (1<<0)
  512. #define ACPI_EV_LID (1<<1)
  513. #define ACPI_EV_DOCK (1<<2)
  514. static struct intel_opregion *system_opregion;
  515. static int intel_opregion_video_event(struct notifier_block *nb,
  516. unsigned long val, void *data)
  517. {
  518. /* The only video events relevant to opregion are 0x80. These indicate
  519. either a docking event, lid switch or display switch request. In
  520. Linux, these are handled by the dock, button and video drivers.
  521. */
  522. struct acpi_bus_event *event = data;
  523. struct opregion_acpi *acpi;
  524. int ret = NOTIFY_OK;
  525. if (strcmp(event->device_class, ACPI_VIDEO_CLASS) != 0)
  526. return NOTIFY_DONE;
  527. if (!system_opregion)
  528. return NOTIFY_DONE;
  529. acpi = system_opregion->acpi;
  530. if (event->type == 0x80 && ((acpi->cevt & 1) == 0))
  531. ret = NOTIFY_BAD;
  532. acpi->csts = 0;
  533. return ret;
  534. }
  535. static struct notifier_block intel_opregion_notifier = {
  536. .notifier_call = intel_opregion_video_event,
  537. };
  538. /*
  539. * Initialise the DIDL field in opregion. This passes a list of devices to
  540. * the firmware. Values are defined by section B.4.2 of the ACPI specification
  541. * (version 3)
  542. */
  543. static u32 get_did(struct intel_opregion *opregion, int i)
  544. {
  545. u32 did;
  546. if (i < ARRAY_SIZE(opregion->acpi->didl)) {
  547. did = opregion->acpi->didl[i];
  548. } else {
  549. i -= ARRAY_SIZE(opregion->acpi->didl);
  550. if (WARN_ON(i >= ARRAY_SIZE(opregion->acpi->did2)))
  551. return 0;
  552. did = opregion->acpi->did2[i];
  553. }
  554. return did;
  555. }
  556. static void set_did(struct intel_opregion *opregion, int i, u32 val)
  557. {
  558. if (i < ARRAY_SIZE(opregion->acpi->didl)) {
  559. opregion->acpi->didl[i] = val;
  560. } else {
  561. i -= ARRAY_SIZE(opregion->acpi->didl);
  562. if (WARN_ON(i >= ARRAY_SIZE(opregion->acpi->did2)))
  563. return;
  564. opregion->acpi->did2[i] = val;
  565. }
  566. }
  567. static u32 acpi_display_type(struct drm_connector *connector)
  568. {
  569. u32 display_type;
  570. switch (connector->connector_type) {
  571. case DRM_MODE_CONNECTOR_VGA:
  572. case DRM_MODE_CONNECTOR_DVIA:
  573. display_type = ACPI_DISPLAY_TYPE_VGA;
  574. break;
  575. case DRM_MODE_CONNECTOR_Composite:
  576. case DRM_MODE_CONNECTOR_SVIDEO:
  577. case DRM_MODE_CONNECTOR_Component:
  578. case DRM_MODE_CONNECTOR_9PinDIN:
  579. case DRM_MODE_CONNECTOR_TV:
  580. display_type = ACPI_DISPLAY_TYPE_TV;
  581. break;
  582. case DRM_MODE_CONNECTOR_DVII:
  583. case DRM_MODE_CONNECTOR_DVID:
  584. case DRM_MODE_CONNECTOR_DisplayPort:
  585. case DRM_MODE_CONNECTOR_HDMIA:
  586. case DRM_MODE_CONNECTOR_HDMIB:
  587. display_type = ACPI_DISPLAY_TYPE_EXTERNAL_DIGITAL;
  588. break;
  589. case DRM_MODE_CONNECTOR_LVDS:
  590. case DRM_MODE_CONNECTOR_eDP:
  591. case DRM_MODE_CONNECTOR_DSI:
  592. display_type = ACPI_DISPLAY_TYPE_INTERNAL_DIGITAL;
  593. break;
  594. case DRM_MODE_CONNECTOR_Unknown:
  595. case DRM_MODE_CONNECTOR_VIRTUAL:
  596. display_type = ACPI_DISPLAY_TYPE_OTHER;
  597. break;
  598. default:
  599. MISSING_CASE(connector->connector_type);
  600. display_type = ACPI_DISPLAY_TYPE_OTHER;
  601. break;
  602. }
  603. return display_type;
  604. }
  605. static void intel_didl_outputs(struct drm_i915_private *dev_priv)
  606. {
  607. struct intel_opregion *opregion = &dev_priv->opregion;
  608. struct pci_dev *pdev = dev_priv->drm.pdev;
  609. struct drm_connector *connector;
  610. acpi_handle handle;
  611. struct acpi_device *acpi_dev, *acpi_cdev, *acpi_video_bus = NULL;
  612. unsigned long long device_id;
  613. acpi_status status;
  614. u32 temp, max_outputs;
  615. int i = 0;
  616. handle = ACPI_HANDLE(&pdev->dev);
  617. if (!handle || acpi_bus_get_device(handle, &acpi_dev))
  618. return;
  619. if (acpi_is_video_device(handle))
  620. acpi_video_bus = acpi_dev;
  621. else {
  622. list_for_each_entry(acpi_cdev, &acpi_dev->children, node) {
  623. if (acpi_is_video_device(acpi_cdev->handle)) {
  624. acpi_video_bus = acpi_cdev;
  625. break;
  626. }
  627. }
  628. }
  629. if (!acpi_video_bus) {
  630. DRM_DEBUG_KMS("No ACPI video bus found\n");
  631. return;
  632. }
  633. /*
  634. * In theory, did2, the extended didl, gets added at opregion version
  635. * 3.0. In practice, however, we're supposed to set it for earlier
  636. * versions as well, since a BIOS that doesn't understand did2 should
  637. * not look at it anyway. Use a variable so we can tweak this if a need
  638. * arises later.
  639. */
  640. max_outputs = ARRAY_SIZE(opregion->acpi->didl) +
  641. ARRAY_SIZE(opregion->acpi->did2);
  642. list_for_each_entry(acpi_cdev, &acpi_video_bus->children, node) {
  643. if (i >= max_outputs) {
  644. DRM_DEBUG_KMS("More than %u outputs detected via ACPI\n",
  645. max_outputs);
  646. return;
  647. }
  648. status = acpi_evaluate_integer(acpi_cdev->handle, "_ADR",
  649. NULL, &device_id);
  650. if (ACPI_SUCCESS(status)) {
  651. if (!device_id)
  652. goto blind_set;
  653. set_did(opregion, i++, (u32)(device_id & 0x0f0f));
  654. }
  655. }
  656. end:
  657. DRM_DEBUG_KMS("%d outputs detected\n", i);
  658. /* If fewer than max outputs, the list must be null terminated */
  659. if (i < max_outputs)
  660. set_did(opregion, i, 0);
  661. return;
  662. blind_set:
  663. i = 0;
  664. list_for_each_entry(connector,
  665. &dev_priv->drm.mode_config.connector_list, head) {
  666. int display_type = acpi_display_type(connector);
  667. if (i >= max_outputs) {
  668. DRM_DEBUG_KMS("More than %u outputs in connector list\n",
  669. max_outputs);
  670. return;
  671. }
  672. temp = get_did(opregion, i);
  673. set_did(opregion, i, temp | (1 << 31) | display_type | i);
  674. i++;
  675. }
  676. goto end;
  677. }
  678. static void intel_setup_cadls(struct drm_i915_private *dev_priv)
  679. {
  680. struct intel_opregion *opregion = &dev_priv->opregion;
  681. int i = 0;
  682. u32 disp_id;
  683. /* Initialize the CADL field by duplicating the DIDL values.
  684. * Technically, this is not always correct as display outputs may exist,
  685. * but not active. This initialization is necessary for some Clevo
  686. * laptops that check this field before processing the brightness and
  687. * display switching hotkeys. Just like DIDL, CADL is NULL-terminated if
  688. * there are less than eight devices. */
  689. do {
  690. disp_id = get_did(opregion, i);
  691. opregion->acpi->cadl[i] = disp_id;
  692. } while (++i < 8 && disp_id != 0);
  693. }
  694. void intel_opregion_register(struct drm_i915_private *dev_priv)
  695. {
  696. struct intel_opregion *opregion = &dev_priv->opregion;
  697. if (!opregion->header)
  698. return;
  699. if (opregion->acpi) {
  700. intel_didl_outputs(dev_priv);
  701. intel_setup_cadls(dev_priv);
  702. /* Notify BIOS we are ready to handle ACPI video ext notifs.
  703. * Right now, all the events are handled by the ACPI video module.
  704. * We don't actually need to do anything with them. */
  705. opregion->acpi->csts = 0;
  706. opregion->acpi->drdy = 1;
  707. system_opregion = opregion;
  708. register_acpi_notifier(&intel_opregion_notifier);
  709. }
  710. if (opregion->asle) {
  711. opregion->asle->tche = ASLE_TCHE_BLC_EN;
  712. opregion->asle->ardy = ASLE_ARDY_READY;
  713. }
  714. }
  715. void intel_opregion_unregister(struct drm_i915_private *dev_priv)
  716. {
  717. struct intel_opregion *opregion = &dev_priv->opregion;
  718. if (!opregion->header)
  719. return;
  720. if (opregion->asle)
  721. opregion->asle->ardy = ASLE_ARDY_NOT_READY;
  722. cancel_work_sync(&dev_priv->opregion.asle_work);
  723. if (opregion->acpi) {
  724. opregion->acpi->drdy = 0;
  725. system_opregion = NULL;
  726. unregister_acpi_notifier(&intel_opregion_notifier);
  727. }
  728. /* just clear all opregion memory pointers now */
  729. memunmap(opregion->header);
  730. if (opregion->rvda) {
  731. memunmap(opregion->rvda);
  732. opregion->rvda = NULL;
  733. }
  734. opregion->header = NULL;
  735. opregion->acpi = NULL;
  736. opregion->swsci = NULL;
  737. opregion->asle = NULL;
  738. opregion->vbt = NULL;
  739. opregion->lid_state = NULL;
  740. }
  741. static void swsci_setup(struct drm_i915_private *dev_priv)
  742. {
  743. struct intel_opregion *opregion = &dev_priv->opregion;
  744. bool requested_callbacks = false;
  745. u32 tmp;
  746. /* Sub-function code 0 is okay, let's allow them. */
  747. opregion->swsci_gbda_sub_functions = 1;
  748. opregion->swsci_sbcb_sub_functions = 1;
  749. /* We use GBDA to ask for supported GBDA calls. */
  750. if (swsci(dev_priv, SWSCI_GBDA_SUPPORTED_CALLS, 0, &tmp) == 0) {
  751. /* make the bits match the sub-function codes */
  752. tmp <<= 1;
  753. opregion->swsci_gbda_sub_functions |= tmp;
  754. }
  755. /*
  756. * We also use GBDA to ask for _requested_ SBCB callbacks. The driver
  757. * must not call interfaces that are not specifically requested by the
  758. * bios.
  759. */
  760. if (swsci(dev_priv, SWSCI_GBDA_REQUESTED_CALLBACKS, 0, &tmp) == 0) {
  761. /* here, the bits already match sub-function codes */
  762. opregion->swsci_sbcb_sub_functions |= tmp;
  763. requested_callbacks = true;
  764. }
  765. /*
  766. * But we use SBCB to ask for _supported_ SBCB calls. This does not mean
  767. * the callback is _requested_. But we still can't call interfaces that
  768. * are not requested.
  769. */
  770. if (swsci(dev_priv, SWSCI_SBCB_SUPPORTED_CALLBACKS, 0, &tmp) == 0) {
  771. /* make the bits match the sub-function codes */
  772. u32 low = tmp & 0x7ff;
  773. u32 high = tmp & ~0xfff; /* bit 11 is reserved */
  774. tmp = (high << 4) | (low << 1) | 1;
  775. /* best guess what to do with supported wrt requested */
  776. if (requested_callbacks) {
  777. u32 req = opregion->swsci_sbcb_sub_functions;
  778. if ((req & tmp) != req)
  779. DRM_DEBUG_DRIVER("SWSCI BIOS requested (%08x) SBCB callbacks that are not supported (%08x)\n", req, tmp);
  780. /* XXX: for now, trust the requested callbacks */
  781. /* opregion->swsci_sbcb_sub_functions &= tmp; */
  782. } else {
  783. opregion->swsci_sbcb_sub_functions |= tmp;
  784. }
  785. }
  786. DRM_DEBUG_DRIVER("SWSCI GBDA callbacks %08x, SBCB callbacks %08x\n",
  787. opregion->swsci_gbda_sub_functions,
  788. opregion->swsci_sbcb_sub_functions);
  789. }
  790. static int intel_no_opregion_vbt_callback(const struct dmi_system_id *id)
  791. {
  792. DRM_DEBUG_KMS("Falling back to manually reading VBT from "
  793. "VBIOS ROM for %s\n", id->ident);
  794. return 1;
  795. }
  796. static const struct dmi_system_id intel_no_opregion_vbt[] = {
  797. {
  798. .callback = intel_no_opregion_vbt_callback,
  799. .ident = "ThinkCentre A57",
  800. .matches = {
  801. DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
  802. DMI_MATCH(DMI_PRODUCT_NAME, "97027RG"),
  803. },
  804. },
  805. { }
  806. };
  807. int intel_opregion_setup(struct drm_i915_private *dev_priv)
  808. {
  809. struct intel_opregion *opregion = &dev_priv->opregion;
  810. struct pci_dev *pdev = dev_priv->drm.pdev;
  811. u32 asls, mboxes;
  812. char buf[sizeof(OPREGION_SIGNATURE)];
  813. int err = 0;
  814. void *base;
  815. BUILD_BUG_ON(sizeof(struct opregion_header) != 0x100);
  816. BUILD_BUG_ON(sizeof(struct opregion_acpi) != 0x100);
  817. BUILD_BUG_ON(sizeof(struct opregion_swsci) != 0x100);
  818. BUILD_BUG_ON(sizeof(struct opregion_asle) != 0x100);
  819. BUILD_BUG_ON(sizeof(struct opregion_asle_ext) != 0x400);
  820. pci_read_config_dword(pdev, ASLS, &asls);
  821. DRM_DEBUG_DRIVER("graphic opregion physical addr: 0x%x\n", asls);
  822. if (asls == 0) {
  823. DRM_DEBUG_DRIVER("ACPI OpRegion not supported!\n");
  824. return -ENOTSUPP;
  825. }
  826. INIT_WORK(&opregion->asle_work, asle_work);
  827. base = memremap(asls, OPREGION_SIZE, MEMREMAP_WB);
  828. if (!base)
  829. return -ENOMEM;
  830. memcpy(buf, base, sizeof(buf));
  831. if (memcmp(buf, OPREGION_SIGNATURE, 16)) {
  832. DRM_DEBUG_DRIVER("opregion signature mismatch\n");
  833. err = -EINVAL;
  834. goto err_out;
  835. }
  836. opregion->header = base;
  837. opregion->lid_state = base + ACPI_CLID;
  838. mboxes = opregion->header->mboxes;
  839. if (mboxes & MBOX_ACPI) {
  840. DRM_DEBUG_DRIVER("Public ACPI methods supported\n");
  841. opregion->acpi = base + OPREGION_ACPI_OFFSET;
  842. }
  843. if (mboxes & MBOX_SWSCI) {
  844. DRM_DEBUG_DRIVER("SWSCI supported\n");
  845. opregion->swsci = base + OPREGION_SWSCI_OFFSET;
  846. swsci_setup(dev_priv);
  847. }
  848. if (mboxes & MBOX_ASLE) {
  849. DRM_DEBUG_DRIVER("ASLE supported\n");
  850. opregion->asle = base + OPREGION_ASLE_OFFSET;
  851. opregion->asle->ardy = ASLE_ARDY_NOT_READY;
  852. }
  853. if (mboxes & MBOX_ASLE_EXT)
  854. DRM_DEBUG_DRIVER("ASLE extension supported\n");
  855. if (!dmi_check_system(intel_no_opregion_vbt)) {
  856. const void *vbt = NULL;
  857. u32 vbt_size = 0;
  858. if (opregion->header->opregion_ver >= 2 && opregion->asle &&
  859. opregion->asle->rvda && opregion->asle->rvds) {
  860. opregion->rvda = memremap(opregion->asle->rvda,
  861. opregion->asle->rvds,
  862. MEMREMAP_WB);
  863. vbt = opregion->rvda;
  864. vbt_size = opregion->asle->rvds;
  865. }
  866. if (intel_bios_is_valid_vbt(vbt, vbt_size)) {
  867. DRM_DEBUG_KMS("Found valid VBT in ACPI OpRegion (RVDA)\n");
  868. opregion->vbt = vbt;
  869. opregion->vbt_size = vbt_size;
  870. } else {
  871. vbt = base + OPREGION_VBT_OFFSET;
  872. vbt_size = OPREGION_ASLE_EXT_OFFSET - OPREGION_VBT_OFFSET;
  873. if (intel_bios_is_valid_vbt(vbt, vbt_size)) {
  874. DRM_DEBUG_KMS("Found valid VBT in ACPI OpRegion (Mailbox #4)\n");
  875. opregion->vbt = vbt;
  876. opregion->vbt_size = vbt_size;
  877. }
  878. }
  879. }
  880. return 0;
  881. err_out:
  882. memunmap(base);
  883. return err;
  884. }
  885. int
  886. intel_opregion_get_panel_type(struct drm_i915_private *dev_priv)
  887. {
  888. u32 panel_details;
  889. int ret;
  890. ret = swsci(dev_priv, SWSCI_GBDA_PANEL_DETAILS, 0x0, &panel_details);
  891. if (ret) {
  892. DRM_DEBUG_KMS("Failed to get panel details from OpRegion (%d)\n",
  893. ret);
  894. return ret;
  895. }
  896. ret = (panel_details >> 8) & 0xff;
  897. if (ret > 0x10) {
  898. DRM_DEBUG_KMS("Invalid OpRegion panel type 0x%x\n", ret);
  899. return -EINVAL;
  900. }
  901. /* fall back to VBT panel type? */
  902. if (ret == 0x0) {
  903. DRM_DEBUG_KMS("No panel type in OpRegion\n");
  904. return -ENODEV;
  905. }
  906. /*
  907. * FIXME On Dell XPS 13 9350 the OpRegion panel type (0) gives us
  908. * low vswing for eDP, whereas the VBT panel type (2) gives us normal
  909. * vswing instead. Low vswing results in some display flickers, so
  910. * let's simply ignore the OpRegion panel type on SKL for now.
  911. */
  912. if (IS_SKYLAKE(dev_priv)) {
  913. DRM_DEBUG_KMS("Ignoring OpRegion panel type (%d)\n", ret - 1);
  914. return -ENODEV;
  915. }
  916. return ret - 1;
  917. }