intel_opregion.c 33 KB

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