intel_opregion.c 33 KB

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