intel_opregion.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077
  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 drm_connector_list_iter conn_iter;
  384. struct opregion_asle *asle = dev_priv->opregion.asle;
  385. struct drm_device *dev = &dev_priv->drm;
  386. DRM_DEBUG_DRIVER("bclp = 0x%08x\n", bclp);
  387. if (acpi_video_get_backlight_type() == acpi_backlight_native) {
  388. DRM_DEBUG_KMS("opregion backlight request ignored\n");
  389. return 0;
  390. }
  391. if (!(bclp & ASLE_BCLP_VALID))
  392. return ASLC_BACKLIGHT_FAILED;
  393. bclp &= ASLE_BCLP_MSK;
  394. if (bclp > 255)
  395. return ASLC_BACKLIGHT_FAILED;
  396. drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
  397. /*
  398. * Update backlight on all connectors that support backlight (usually
  399. * only one).
  400. */
  401. DRM_DEBUG_KMS("updating opregion backlight %d/255\n", bclp);
  402. drm_connector_list_iter_begin(dev, &conn_iter);
  403. for_each_intel_connector_iter(connector, &conn_iter)
  404. intel_panel_set_backlight_acpi(connector, bclp, 255);
  405. drm_connector_list_iter_end(&conn_iter);
  406. asle->cblv = DIV_ROUND_UP(bclp * 100, 255) | ASLE_CBLV_VALID;
  407. drm_modeset_unlock(&dev->mode_config.connection_mutex);
  408. return 0;
  409. }
  410. static u32 asle_set_als_illum(struct drm_i915_private *dev_priv, u32 alsi)
  411. {
  412. /* alsi is the current ALS reading in lux. 0 indicates below sensor
  413. range, 0xffff indicates above sensor range. 1-0xfffe are valid */
  414. DRM_DEBUG_DRIVER("Illum is not supported\n");
  415. return ASLC_ALS_ILLUM_FAILED;
  416. }
  417. static u32 asle_set_pwm_freq(struct drm_i915_private *dev_priv, u32 pfmb)
  418. {
  419. DRM_DEBUG_DRIVER("PWM freq is not supported\n");
  420. return ASLC_PWM_FREQ_FAILED;
  421. }
  422. static u32 asle_set_pfit(struct drm_i915_private *dev_priv, u32 pfit)
  423. {
  424. /* Panel fitting is currently controlled by the X code, so this is a
  425. noop until modesetting support works fully */
  426. DRM_DEBUG_DRIVER("Pfit is not supported\n");
  427. return ASLC_PFIT_FAILED;
  428. }
  429. static u32 asle_set_supported_rotation_angles(struct drm_i915_private *dev_priv, u32 srot)
  430. {
  431. DRM_DEBUG_DRIVER("SROT is not supported\n");
  432. return ASLC_ROTATION_ANGLES_FAILED;
  433. }
  434. static u32 asle_set_button_array(struct drm_i915_private *dev_priv, u32 iuer)
  435. {
  436. if (!iuer)
  437. DRM_DEBUG_DRIVER("Button array event is not supported (nothing)\n");
  438. if (iuer & ASLE_IUER_ROTATION_LOCK_BTN)
  439. DRM_DEBUG_DRIVER("Button array event is not supported (rotation lock)\n");
  440. if (iuer & ASLE_IUER_VOLUME_DOWN_BTN)
  441. DRM_DEBUG_DRIVER("Button array event is not supported (volume down)\n");
  442. if (iuer & ASLE_IUER_VOLUME_UP_BTN)
  443. DRM_DEBUG_DRIVER("Button array event is not supported (volume up)\n");
  444. if (iuer & ASLE_IUER_WINDOWS_BTN)
  445. DRM_DEBUG_DRIVER("Button array event is not supported (windows)\n");
  446. if (iuer & ASLE_IUER_POWER_BTN)
  447. DRM_DEBUG_DRIVER("Button array event is not supported (power)\n");
  448. return ASLC_BUTTON_ARRAY_FAILED;
  449. }
  450. static u32 asle_set_convertible(struct drm_i915_private *dev_priv, u32 iuer)
  451. {
  452. if (iuer & ASLE_IUER_CONVERTIBLE)
  453. DRM_DEBUG_DRIVER("Convertible is not supported (clamshell)\n");
  454. else
  455. DRM_DEBUG_DRIVER("Convertible is not supported (slate)\n");
  456. return ASLC_CONVERTIBLE_FAILED;
  457. }
  458. static u32 asle_set_docking(struct drm_i915_private *dev_priv, u32 iuer)
  459. {
  460. if (iuer & ASLE_IUER_DOCKING)
  461. DRM_DEBUG_DRIVER("Docking is not supported (docked)\n");
  462. else
  463. DRM_DEBUG_DRIVER("Docking is not supported (undocked)\n");
  464. return ASLC_DOCKING_FAILED;
  465. }
  466. static u32 asle_isct_state(struct drm_i915_private *dev_priv)
  467. {
  468. DRM_DEBUG_DRIVER("ISCT is not supported\n");
  469. return ASLC_ISCT_STATE_FAILED;
  470. }
  471. static void asle_work(struct work_struct *work)
  472. {
  473. struct intel_opregion *opregion =
  474. container_of(work, struct intel_opregion, asle_work);
  475. struct drm_i915_private *dev_priv =
  476. container_of(opregion, struct drm_i915_private, opregion);
  477. struct opregion_asle *asle = dev_priv->opregion.asle;
  478. u32 aslc_stat = 0;
  479. u32 aslc_req;
  480. if (!asle)
  481. return;
  482. aslc_req = asle->aslc;
  483. if (!(aslc_req & ASLC_REQ_MSK)) {
  484. DRM_DEBUG_DRIVER("No request on ASLC interrupt 0x%08x\n",
  485. aslc_req);
  486. return;
  487. }
  488. if (aslc_req & ASLC_SET_ALS_ILLUM)
  489. aslc_stat |= asle_set_als_illum(dev_priv, asle->alsi);
  490. if (aslc_req & ASLC_SET_BACKLIGHT)
  491. aslc_stat |= asle_set_backlight(dev_priv, asle->bclp);
  492. if (aslc_req & ASLC_SET_PFIT)
  493. aslc_stat |= asle_set_pfit(dev_priv, asle->pfit);
  494. if (aslc_req & ASLC_SET_PWM_FREQ)
  495. aslc_stat |= asle_set_pwm_freq(dev_priv, asle->pfmb);
  496. if (aslc_req & ASLC_SUPPORTED_ROTATION_ANGLES)
  497. aslc_stat |= asle_set_supported_rotation_angles(dev_priv,
  498. asle->srot);
  499. if (aslc_req & ASLC_BUTTON_ARRAY)
  500. aslc_stat |= asle_set_button_array(dev_priv, asle->iuer);
  501. if (aslc_req & ASLC_CONVERTIBLE_INDICATOR)
  502. aslc_stat |= asle_set_convertible(dev_priv, asle->iuer);
  503. if (aslc_req & ASLC_DOCKING_INDICATOR)
  504. aslc_stat |= asle_set_docking(dev_priv, asle->iuer);
  505. if (aslc_req & ASLC_ISCT_STATE_CHANGE)
  506. aslc_stat |= asle_isct_state(dev_priv);
  507. asle->aslc = aslc_stat;
  508. }
  509. void intel_opregion_asle_intr(struct drm_i915_private *dev_priv)
  510. {
  511. if (dev_priv->opregion.asle)
  512. schedule_work(&dev_priv->opregion.asle_work);
  513. }
  514. #define ACPI_EV_DISPLAY_SWITCH (1<<0)
  515. #define ACPI_EV_LID (1<<1)
  516. #define ACPI_EV_DOCK (1<<2)
  517. static struct intel_opregion *system_opregion;
  518. static int intel_opregion_video_event(struct notifier_block *nb,
  519. unsigned long val, void *data)
  520. {
  521. /* The only video events relevant to opregion are 0x80. These indicate
  522. either a docking event, lid switch or display switch request. In
  523. Linux, these are handled by the dock, button and video drivers.
  524. */
  525. struct acpi_bus_event *event = data;
  526. struct opregion_acpi *acpi;
  527. int ret = NOTIFY_OK;
  528. if (strcmp(event->device_class, ACPI_VIDEO_CLASS) != 0)
  529. return NOTIFY_DONE;
  530. if (!system_opregion)
  531. return NOTIFY_DONE;
  532. acpi = system_opregion->acpi;
  533. if (event->type == 0x80 && ((acpi->cevt & 1) == 0))
  534. ret = NOTIFY_BAD;
  535. acpi->csts = 0;
  536. return ret;
  537. }
  538. static struct notifier_block intel_opregion_notifier = {
  539. .notifier_call = intel_opregion_video_event,
  540. };
  541. /*
  542. * Initialise the DIDL field in opregion. This passes a list of devices to
  543. * the firmware. Values are defined by section B.4.2 of the ACPI specification
  544. * (version 3)
  545. */
  546. static void set_did(struct intel_opregion *opregion, int i, u32 val)
  547. {
  548. if (i < ARRAY_SIZE(opregion->acpi->didl)) {
  549. opregion->acpi->didl[i] = val;
  550. } else {
  551. i -= ARRAY_SIZE(opregion->acpi->didl);
  552. if (WARN_ON(i >= ARRAY_SIZE(opregion->acpi->did2)))
  553. return;
  554. opregion->acpi->did2[i] = val;
  555. }
  556. }
  557. static u32 acpi_display_type(struct intel_connector *connector)
  558. {
  559. u32 display_type;
  560. switch (connector->base.connector_type) {
  561. case DRM_MODE_CONNECTOR_VGA:
  562. case DRM_MODE_CONNECTOR_DVIA:
  563. display_type = ACPI_DISPLAY_TYPE_VGA;
  564. break;
  565. case DRM_MODE_CONNECTOR_Composite:
  566. case DRM_MODE_CONNECTOR_SVIDEO:
  567. case DRM_MODE_CONNECTOR_Component:
  568. case DRM_MODE_CONNECTOR_9PinDIN:
  569. case DRM_MODE_CONNECTOR_TV:
  570. display_type = ACPI_DISPLAY_TYPE_TV;
  571. break;
  572. case DRM_MODE_CONNECTOR_DVII:
  573. case DRM_MODE_CONNECTOR_DVID:
  574. case DRM_MODE_CONNECTOR_DisplayPort:
  575. case DRM_MODE_CONNECTOR_HDMIA:
  576. case DRM_MODE_CONNECTOR_HDMIB:
  577. display_type = ACPI_DISPLAY_TYPE_EXTERNAL_DIGITAL;
  578. break;
  579. case DRM_MODE_CONNECTOR_LVDS:
  580. case DRM_MODE_CONNECTOR_eDP:
  581. case DRM_MODE_CONNECTOR_DSI:
  582. display_type = ACPI_DISPLAY_TYPE_INTERNAL_DIGITAL;
  583. break;
  584. case DRM_MODE_CONNECTOR_Unknown:
  585. case DRM_MODE_CONNECTOR_VIRTUAL:
  586. display_type = ACPI_DISPLAY_TYPE_OTHER;
  587. break;
  588. default:
  589. MISSING_CASE(connector->base.connector_type);
  590. display_type = ACPI_DISPLAY_TYPE_OTHER;
  591. break;
  592. }
  593. return display_type;
  594. }
  595. static void intel_didl_outputs(struct drm_i915_private *dev_priv)
  596. {
  597. struct intel_opregion *opregion = &dev_priv->opregion;
  598. struct intel_connector *connector;
  599. struct drm_connector_list_iter conn_iter;
  600. int i = 0, max_outputs;
  601. int display_index[16] = {};
  602. /*
  603. * In theory, did2, the extended didl, gets added at opregion version
  604. * 3.0. In practice, however, we're supposed to set it for earlier
  605. * versions as well, since a BIOS that doesn't understand did2 should
  606. * not look at it anyway. Use a variable so we can tweak this if a need
  607. * arises later.
  608. */
  609. max_outputs = ARRAY_SIZE(opregion->acpi->didl) +
  610. ARRAY_SIZE(opregion->acpi->did2);
  611. drm_connector_list_iter_begin(&dev_priv->drm, &conn_iter);
  612. for_each_intel_connector_iter(connector, &conn_iter) {
  613. u32 device_id, type;
  614. device_id = acpi_display_type(connector);
  615. /* Use display type specific display index. */
  616. type = (device_id & ACPI_DISPLAY_TYPE_MASK)
  617. >> ACPI_DISPLAY_TYPE_SHIFT;
  618. device_id |= display_index[type]++ << ACPI_DISPLAY_INDEX_SHIFT;
  619. connector->acpi_device_id = device_id;
  620. if (i < max_outputs)
  621. set_did(opregion, i, device_id);
  622. i++;
  623. }
  624. drm_connector_list_iter_end(&conn_iter);
  625. DRM_DEBUG_KMS("%d outputs detected\n", i);
  626. if (i > max_outputs)
  627. DRM_ERROR("More than %d outputs in connector list\n",
  628. max_outputs);
  629. /* If fewer than max outputs, the list must be null terminated */
  630. if (i < max_outputs)
  631. set_did(opregion, i, 0);
  632. }
  633. static void intel_setup_cadls(struct drm_i915_private *dev_priv)
  634. {
  635. struct intel_opregion *opregion = &dev_priv->opregion;
  636. struct intel_connector *connector;
  637. struct drm_connector_list_iter conn_iter;
  638. int i = 0;
  639. /*
  640. * Initialize the CADL field from the connector device ids. This is
  641. * essentially the same as copying from the DIDL. Technically, this is
  642. * not always correct as display outputs may exist, but not active. This
  643. * initialization is necessary for some Clevo laptops that check this
  644. * field before processing the brightness and display switching hotkeys.
  645. *
  646. * Note that internal panels should be at the front of the connector
  647. * list already, ensuring they're not left out.
  648. */
  649. drm_connector_list_iter_begin(&dev_priv->drm, &conn_iter);
  650. for_each_intel_connector_iter(connector, &conn_iter) {
  651. if (i >= ARRAY_SIZE(opregion->acpi->cadl))
  652. break;
  653. opregion->acpi->cadl[i++] = connector->acpi_device_id;
  654. }
  655. drm_connector_list_iter_end(&conn_iter);
  656. /* If fewer than 8 active devices, the list must be null terminated */
  657. if (i < ARRAY_SIZE(opregion->acpi->cadl))
  658. opregion->acpi->cadl[i] = 0;
  659. }
  660. void intel_opregion_register(struct drm_i915_private *dev_priv)
  661. {
  662. struct intel_opregion *opregion = &dev_priv->opregion;
  663. if (!opregion->header)
  664. return;
  665. if (opregion->acpi) {
  666. intel_didl_outputs(dev_priv);
  667. intel_setup_cadls(dev_priv);
  668. /* Notify BIOS we are ready to handle ACPI video ext notifs.
  669. * Right now, all the events are handled by the ACPI video module.
  670. * We don't actually need to do anything with them. */
  671. opregion->acpi->csts = 0;
  672. opregion->acpi->drdy = 1;
  673. system_opregion = opregion;
  674. register_acpi_notifier(&intel_opregion_notifier);
  675. }
  676. if (opregion->asle) {
  677. opregion->asle->tche = ASLE_TCHE_BLC_EN;
  678. opregion->asle->ardy = ASLE_ARDY_READY;
  679. }
  680. }
  681. void intel_opregion_unregister(struct drm_i915_private *dev_priv)
  682. {
  683. struct intel_opregion *opregion = &dev_priv->opregion;
  684. if (!opregion->header)
  685. return;
  686. if (opregion->asle)
  687. opregion->asle->ardy = ASLE_ARDY_NOT_READY;
  688. cancel_work_sync(&dev_priv->opregion.asle_work);
  689. if (opregion->acpi) {
  690. opregion->acpi->drdy = 0;
  691. system_opregion = NULL;
  692. unregister_acpi_notifier(&intel_opregion_notifier);
  693. }
  694. /* just clear all opregion memory pointers now */
  695. memunmap(opregion->header);
  696. if (opregion->rvda) {
  697. memunmap(opregion->rvda);
  698. opregion->rvda = NULL;
  699. }
  700. opregion->header = NULL;
  701. opregion->acpi = NULL;
  702. opregion->swsci = NULL;
  703. opregion->asle = NULL;
  704. opregion->vbt = NULL;
  705. opregion->lid_state = NULL;
  706. }
  707. static void swsci_setup(struct drm_i915_private *dev_priv)
  708. {
  709. struct intel_opregion *opregion = &dev_priv->opregion;
  710. bool requested_callbacks = false;
  711. u32 tmp;
  712. /* Sub-function code 0 is okay, let's allow them. */
  713. opregion->swsci_gbda_sub_functions = 1;
  714. opregion->swsci_sbcb_sub_functions = 1;
  715. /* We use GBDA to ask for supported GBDA calls. */
  716. if (swsci(dev_priv, SWSCI_GBDA_SUPPORTED_CALLS, 0, &tmp) == 0) {
  717. /* make the bits match the sub-function codes */
  718. tmp <<= 1;
  719. opregion->swsci_gbda_sub_functions |= tmp;
  720. }
  721. /*
  722. * We also use GBDA to ask for _requested_ SBCB callbacks. The driver
  723. * must not call interfaces that are not specifically requested by the
  724. * bios.
  725. */
  726. if (swsci(dev_priv, SWSCI_GBDA_REQUESTED_CALLBACKS, 0, &tmp) == 0) {
  727. /* here, the bits already match sub-function codes */
  728. opregion->swsci_sbcb_sub_functions |= tmp;
  729. requested_callbacks = true;
  730. }
  731. /*
  732. * But we use SBCB to ask for _supported_ SBCB calls. This does not mean
  733. * the callback is _requested_. But we still can't call interfaces that
  734. * are not requested.
  735. */
  736. if (swsci(dev_priv, SWSCI_SBCB_SUPPORTED_CALLBACKS, 0, &tmp) == 0) {
  737. /* make the bits match the sub-function codes */
  738. u32 low = tmp & 0x7ff;
  739. u32 high = tmp & ~0xfff; /* bit 11 is reserved */
  740. tmp = (high << 4) | (low << 1) | 1;
  741. /* best guess what to do with supported wrt requested */
  742. if (requested_callbacks) {
  743. u32 req = opregion->swsci_sbcb_sub_functions;
  744. if ((req & tmp) != req)
  745. DRM_DEBUG_DRIVER("SWSCI BIOS requested (%08x) SBCB callbacks that are not supported (%08x)\n", req, tmp);
  746. /* XXX: for now, trust the requested callbacks */
  747. /* opregion->swsci_sbcb_sub_functions &= tmp; */
  748. } else {
  749. opregion->swsci_sbcb_sub_functions |= tmp;
  750. }
  751. }
  752. DRM_DEBUG_DRIVER("SWSCI GBDA callbacks %08x, SBCB callbacks %08x\n",
  753. opregion->swsci_gbda_sub_functions,
  754. opregion->swsci_sbcb_sub_functions);
  755. }
  756. static int intel_no_opregion_vbt_callback(const struct dmi_system_id *id)
  757. {
  758. DRM_DEBUG_KMS("Falling back to manually reading VBT from "
  759. "VBIOS ROM for %s\n", id->ident);
  760. return 1;
  761. }
  762. static const struct dmi_system_id intel_no_opregion_vbt[] = {
  763. {
  764. .callback = intel_no_opregion_vbt_callback,
  765. .ident = "ThinkCentre A57",
  766. .matches = {
  767. DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
  768. DMI_MATCH(DMI_PRODUCT_NAME, "97027RG"),
  769. },
  770. },
  771. { }
  772. };
  773. int intel_opregion_setup(struct drm_i915_private *dev_priv)
  774. {
  775. struct intel_opregion *opregion = &dev_priv->opregion;
  776. struct pci_dev *pdev = dev_priv->drm.pdev;
  777. u32 asls, mboxes;
  778. char buf[sizeof(OPREGION_SIGNATURE)];
  779. int err = 0;
  780. void *base;
  781. const void *vbt;
  782. u32 vbt_size;
  783. BUILD_BUG_ON(sizeof(struct opregion_header) != 0x100);
  784. BUILD_BUG_ON(sizeof(struct opregion_acpi) != 0x100);
  785. BUILD_BUG_ON(sizeof(struct opregion_swsci) != 0x100);
  786. BUILD_BUG_ON(sizeof(struct opregion_asle) != 0x100);
  787. BUILD_BUG_ON(sizeof(struct opregion_asle_ext) != 0x400);
  788. pci_read_config_dword(pdev, ASLS, &asls);
  789. DRM_DEBUG_DRIVER("graphic opregion physical addr: 0x%x\n", asls);
  790. if (asls == 0) {
  791. DRM_DEBUG_DRIVER("ACPI OpRegion not supported!\n");
  792. return -ENOTSUPP;
  793. }
  794. INIT_WORK(&opregion->asle_work, asle_work);
  795. base = memremap(asls, OPREGION_SIZE, MEMREMAP_WB);
  796. if (!base)
  797. return -ENOMEM;
  798. memcpy(buf, base, sizeof(buf));
  799. if (memcmp(buf, OPREGION_SIGNATURE, 16)) {
  800. DRM_DEBUG_DRIVER("opregion signature mismatch\n");
  801. err = -EINVAL;
  802. goto err_out;
  803. }
  804. opregion->header = base;
  805. opregion->lid_state = base + ACPI_CLID;
  806. mboxes = opregion->header->mboxes;
  807. if (mboxes & MBOX_ACPI) {
  808. DRM_DEBUG_DRIVER("Public ACPI methods supported\n");
  809. opregion->acpi = base + OPREGION_ACPI_OFFSET;
  810. }
  811. if (mboxes & MBOX_SWSCI) {
  812. DRM_DEBUG_DRIVER("SWSCI supported\n");
  813. opregion->swsci = base + OPREGION_SWSCI_OFFSET;
  814. swsci_setup(dev_priv);
  815. }
  816. if (mboxes & MBOX_ASLE) {
  817. DRM_DEBUG_DRIVER("ASLE supported\n");
  818. opregion->asle = base + OPREGION_ASLE_OFFSET;
  819. opregion->asle->ardy = ASLE_ARDY_NOT_READY;
  820. }
  821. if (mboxes & MBOX_ASLE_EXT)
  822. DRM_DEBUG_DRIVER("ASLE extension supported\n");
  823. if (dmi_check_system(intel_no_opregion_vbt))
  824. goto out;
  825. if (opregion->header->opregion_ver >= 2 && opregion->asle &&
  826. opregion->asle->rvda && opregion->asle->rvds) {
  827. opregion->rvda = memremap(opregion->asle->rvda,
  828. opregion->asle->rvds,
  829. MEMREMAP_WB);
  830. vbt = opregion->rvda;
  831. vbt_size = opregion->asle->rvds;
  832. if (intel_bios_is_valid_vbt(vbt, vbt_size)) {
  833. DRM_DEBUG_KMS("Found valid VBT in ACPI OpRegion (RVDA)\n");
  834. opregion->vbt = vbt;
  835. opregion->vbt_size = vbt_size;
  836. goto out;
  837. } else {
  838. DRM_DEBUG_KMS("Invalid VBT in ACPI OpRegion (RVDA)\n");
  839. }
  840. }
  841. vbt = base + OPREGION_VBT_OFFSET;
  842. /*
  843. * The VBT specification says that if the ASLE ext mailbox is not used
  844. * its area is reserved, but on some CHT boards the VBT extends into the
  845. * ASLE ext area. Allow this even though it is against the spec, so we
  846. * do not end up rejecting the VBT on those boards (and end up not
  847. * finding the LCD panel because of this).
  848. */
  849. vbt_size = (mboxes & MBOX_ASLE_EXT) ?
  850. OPREGION_ASLE_EXT_OFFSET : OPREGION_SIZE;
  851. vbt_size -= OPREGION_VBT_OFFSET;
  852. if (intel_bios_is_valid_vbt(vbt, vbt_size)) {
  853. DRM_DEBUG_KMS("Found valid VBT in ACPI OpRegion (Mailbox #4)\n");
  854. opregion->vbt = vbt;
  855. opregion->vbt_size = vbt_size;
  856. } else {
  857. DRM_DEBUG_KMS("Invalid VBT in ACPI OpRegion (Mailbox #4)\n");
  858. }
  859. out:
  860. return 0;
  861. err_out:
  862. memunmap(base);
  863. return err;
  864. }
  865. static int intel_use_opregion_panel_type_callback(const struct dmi_system_id *id)
  866. {
  867. DRM_INFO("Using panel type from OpRegion on %s\n", id->ident);
  868. return 1;
  869. }
  870. static const struct dmi_system_id intel_use_opregion_panel_type[] = {
  871. {
  872. .callback = intel_use_opregion_panel_type_callback,
  873. .ident = "Conrac GmbH IX45GM2",
  874. .matches = {DMI_MATCH(DMI_SYS_VENDOR, "Conrac GmbH"),
  875. DMI_MATCH(DMI_PRODUCT_NAME, "IX45GM2"),
  876. },
  877. },
  878. { }
  879. };
  880. int
  881. intel_opregion_get_panel_type(struct drm_i915_private *dev_priv)
  882. {
  883. u32 panel_details;
  884. int ret;
  885. ret = swsci(dev_priv, SWSCI_GBDA_PANEL_DETAILS, 0x0, &panel_details);
  886. if (ret) {
  887. DRM_DEBUG_KMS("Failed to get panel details from OpRegion (%d)\n",
  888. ret);
  889. return ret;
  890. }
  891. ret = (panel_details >> 8) & 0xff;
  892. if (ret > 0x10) {
  893. DRM_DEBUG_KMS("Invalid OpRegion panel type 0x%x\n", ret);
  894. return -EINVAL;
  895. }
  896. /* fall back to VBT panel type? */
  897. if (ret == 0x0) {
  898. DRM_DEBUG_KMS("No panel type in OpRegion\n");
  899. return -ENODEV;
  900. }
  901. /*
  902. * So far we know that some machined must use it, others must not use it.
  903. * There doesn't seem to be any way to determine which way to go, except
  904. * via a quirk list :(
  905. */
  906. if (!dmi_check_system(intel_use_opregion_panel_type)) {
  907. DRM_DEBUG_KMS("Ignoring OpRegion panel type (%d)\n", ret - 1);
  908. return -ENODEV;
  909. }
  910. return ret - 1;
  911. }