intel_bios.c 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399
  1. /*
  2. * Copyright © 2006 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. * SOFTWARE.
  22. *
  23. * Authors:
  24. * Eric Anholt <eric@anholt.net>
  25. *
  26. */
  27. #include <linux/dmi.h>
  28. #include <drm/drm_dp_helper.h>
  29. #include <drm/drmP.h>
  30. #include <drm/i915_drm.h>
  31. #include "i915_drv.h"
  32. #include "intel_bios.h"
  33. #define SLAVE_ADDR1 0x70
  34. #define SLAVE_ADDR2 0x72
  35. static int panel_type;
  36. static const void *
  37. find_section(const void *_bdb, int section_id)
  38. {
  39. const struct bdb_header *bdb = _bdb;
  40. const u8 *base = _bdb;
  41. int index = 0;
  42. u32 total, current_size;
  43. u8 current_id;
  44. /* skip to first section */
  45. index += bdb->header_size;
  46. total = bdb->bdb_size;
  47. /* walk the sections looking for section_id */
  48. while (index + 3 < total) {
  49. current_id = *(base + index);
  50. index++;
  51. current_size = *((const u16 *)(base + index));
  52. index += 2;
  53. /* The MIPI Sequence Block v3+ has a separate size field. */
  54. if (current_id == BDB_MIPI_SEQUENCE && *(base + index) >= 3)
  55. current_size = *((const u32 *)(base + index + 1));
  56. if (index + current_size > total)
  57. return NULL;
  58. if (current_id == section_id)
  59. return base + index;
  60. index += current_size;
  61. }
  62. return NULL;
  63. }
  64. static u16
  65. get_blocksize(const void *p)
  66. {
  67. u16 *block_ptr, block_size;
  68. block_ptr = (u16 *)((char *)p - 2);
  69. block_size = *block_ptr;
  70. return block_size;
  71. }
  72. static void
  73. fill_detail_timing_data(struct drm_display_mode *panel_fixed_mode,
  74. const struct lvds_dvo_timing *dvo_timing)
  75. {
  76. panel_fixed_mode->hdisplay = (dvo_timing->hactive_hi << 8) |
  77. dvo_timing->hactive_lo;
  78. panel_fixed_mode->hsync_start = panel_fixed_mode->hdisplay +
  79. ((dvo_timing->hsync_off_hi << 8) | dvo_timing->hsync_off_lo);
  80. panel_fixed_mode->hsync_end = panel_fixed_mode->hsync_start +
  81. dvo_timing->hsync_pulse_width;
  82. panel_fixed_mode->htotal = panel_fixed_mode->hdisplay +
  83. ((dvo_timing->hblank_hi << 8) | dvo_timing->hblank_lo);
  84. panel_fixed_mode->vdisplay = (dvo_timing->vactive_hi << 8) |
  85. dvo_timing->vactive_lo;
  86. panel_fixed_mode->vsync_start = panel_fixed_mode->vdisplay +
  87. dvo_timing->vsync_off;
  88. panel_fixed_mode->vsync_end = panel_fixed_mode->vsync_start +
  89. dvo_timing->vsync_pulse_width;
  90. panel_fixed_mode->vtotal = panel_fixed_mode->vdisplay +
  91. ((dvo_timing->vblank_hi << 8) | dvo_timing->vblank_lo);
  92. panel_fixed_mode->clock = dvo_timing->clock * 10;
  93. panel_fixed_mode->type = DRM_MODE_TYPE_PREFERRED;
  94. if (dvo_timing->hsync_positive)
  95. panel_fixed_mode->flags |= DRM_MODE_FLAG_PHSYNC;
  96. else
  97. panel_fixed_mode->flags |= DRM_MODE_FLAG_NHSYNC;
  98. if (dvo_timing->vsync_positive)
  99. panel_fixed_mode->flags |= DRM_MODE_FLAG_PVSYNC;
  100. else
  101. panel_fixed_mode->flags |= DRM_MODE_FLAG_NVSYNC;
  102. /* Some VBTs have bogus h/vtotal values */
  103. if (panel_fixed_mode->hsync_end > panel_fixed_mode->htotal)
  104. panel_fixed_mode->htotal = panel_fixed_mode->hsync_end + 1;
  105. if (panel_fixed_mode->vsync_end > panel_fixed_mode->vtotal)
  106. panel_fixed_mode->vtotal = panel_fixed_mode->vsync_end + 1;
  107. drm_mode_set_name(panel_fixed_mode);
  108. }
  109. static const struct lvds_dvo_timing *
  110. get_lvds_dvo_timing(const struct bdb_lvds_lfp_data *lvds_lfp_data,
  111. const struct bdb_lvds_lfp_data_ptrs *lvds_lfp_data_ptrs,
  112. int index)
  113. {
  114. /*
  115. * the size of fp_timing varies on the different platform.
  116. * So calculate the DVO timing relative offset in LVDS data
  117. * entry to get the DVO timing entry
  118. */
  119. int lfp_data_size =
  120. lvds_lfp_data_ptrs->ptr[1].dvo_timing_offset -
  121. lvds_lfp_data_ptrs->ptr[0].dvo_timing_offset;
  122. int dvo_timing_offset =
  123. lvds_lfp_data_ptrs->ptr[0].dvo_timing_offset -
  124. lvds_lfp_data_ptrs->ptr[0].fp_timing_offset;
  125. char *entry = (char *)lvds_lfp_data->data + lfp_data_size * index;
  126. return (struct lvds_dvo_timing *)(entry + dvo_timing_offset);
  127. }
  128. /* get lvds_fp_timing entry
  129. * this function may return NULL if the corresponding entry is invalid
  130. */
  131. static const struct lvds_fp_timing *
  132. get_lvds_fp_timing(const struct bdb_header *bdb,
  133. const struct bdb_lvds_lfp_data *data,
  134. const struct bdb_lvds_lfp_data_ptrs *ptrs,
  135. int index)
  136. {
  137. size_t data_ofs = (const u8 *)data - (const u8 *)bdb;
  138. u16 data_size = ((const u16 *)data)[-1]; /* stored in header */
  139. size_t ofs;
  140. if (index >= ARRAY_SIZE(ptrs->ptr))
  141. return NULL;
  142. ofs = ptrs->ptr[index].fp_timing_offset;
  143. if (ofs < data_ofs ||
  144. ofs + sizeof(struct lvds_fp_timing) > data_ofs + data_size)
  145. return NULL;
  146. return (const struct lvds_fp_timing *)((const u8 *)bdb + ofs);
  147. }
  148. /* Try to find integrated panel data */
  149. static void
  150. parse_lfp_panel_data(struct drm_i915_private *dev_priv,
  151. const struct bdb_header *bdb)
  152. {
  153. const struct bdb_lvds_options *lvds_options;
  154. const struct bdb_lvds_lfp_data *lvds_lfp_data;
  155. const struct bdb_lvds_lfp_data_ptrs *lvds_lfp_data_ptrs;
  156. const struct lvds_dvo_timing *panel_dvo_timing;
  157. const struct lvds_fp_timing *fp_timing;
  158. struct drm_display_mode *panel_fixed_mode;
  159. int drrs_mode;
  160. lvds_options = find_section(bdb, BDB_LVDS_OPTIONS);
  161. if (!lvds_options)
  162. return;
  163. dev_priv->vbt.lvds_dither = lvds_options->pixel_dither;
  164. if (lvds_options->panel_type == 0xff)
  165. return;
  166. panel_type = lvds_options->panel_type;
  167. drrs_mode = (lvds_options->dps_panel_type_bits
  168. >> (panel_type * 2)) & MODE_MASK;
  169. /*
  170. * VBT has static DRRS = 0 and seamless DRRS = 2.
  171. * The below piece of code is required to adjust vbt.drrs_type
  172. * to match the enum drrs_support_type.
  173. */
  174. switch (drrs_mode) {
  175. case 0:
  176. dev_priv->vbt.drrs_type = STATIC_DRRS_SUPPORT;
  177. DRM_DEBUG_KMS("DRRS supported mode is static\n");
  178. break;
  179. case 2:
  180. dev_priv->vbt.drrs_type = SEAMLESS_DRRS_SUPPORT;
  181. DRM_DEBUG_KMS("DRRS supported mode is seamless\n");
  182. break;
  183. default:
  184. dev_priv->vbt.drrs_type = DRRS_NOT_SUPPORTED;
  185. DRM_DEBUG_KMS("DRRS not supported (VBT input)\n");
  186. break;
  187. }
  188. lvds_lfp_data = find_section(bdb, BDB_LVDS_LFP_DATA);
  189. if (!lvds_lfp_data)
  190. return;
  191. lvds_lfp_data_ptrs = find_section(bdb, BDB_LVDS_LFP_DATA_PTRS);
  192. if (!lvds_lfp_data_ptrs)
  193. return;
  194. dev_priv->vbt.lvds_vbt = 1;
  195. panel_dvo_timing = get_lvds_dvo_timing(lvds_lfp_data,
  196. lvds_lfp_data_ptrs,
  197. lvds_options->panel_type);
  198. panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL);
  199. if (!panel_fixed_mode)
  200. return;
  201. fill_detail_timing_data(panel_fixed_mode, panel_dvo_timing);
  202. dev_priv->vbt.lfp_lvds_vbt_mode = panel_fixed_mode;
  203. DRM_DEBUG_KMS("Found panel mode in BIOS VBT tables:\n");
  204. drm_mode_debug_printmodeline(panel_fixed_mode);
  205. fp_timing = get_lvds_fp_timing(bdb, lvds_lfp_data,
  206. lvds_lfp_data_ptrs,
  207. lvds_options->panel_type);
  208. if (fp_timing) {
  209. /* check the resolution, just to be sure */
  210. if (fp_timing->x_res == panel_fixed_mode->hdisplay &&
  211. fp_timing->y_res == panel_fixed_mode->vdisplay) {
  212. dev_priv->vbt.bios_lvds_val = fp_timing->lvds_reg_val;
  213. DRM_DEBUG_KMS("VBT initial LVDS value %x\n",
  214. dev_priv->vbt.bios_lvds_val);
  215. }
  216. }
  217. }
  218. static void
  219. parse_lfp_backlight(struct drm_i915_private *dev_priv,
  220. const struct bdb_header *bdb)
  221. {
  222. const struct bdb_lfp_backlight_data *backlight_data;
  223. const struct bdb_lfp_backlight_data_entry *entry;
  224. backlight_data = find_section(bdb, BDB_LVDS_BACKLIGHT);
  225. if (!backlight_data)
  226. return;
  227. if (backlight_data->entry_size != sizeof(backlight_data->data[0])) {
  228. DRM_DEBUG_KMS("Unsupported backlight data entry size %u\n",
  229. backlight_data->entry_size);
  230. return;
  231. }
  232. entry = &backlight_data->data[panel_type];
  233. dev_priv->vbt.backlight.present = entry->type == BDB_BACKLIGHT_TYPE_PWM;
  234. if (!dev_priv->vbt.backlight.present) {
  235. DRM_DEBUG_KMS("PWM backlight not present in VBT (type %u)\n",
  236. entry->type);
  237. return;
  238. }
  239. dev_priv->vbt.backlight.pwm_freq_hz = entry->pwm_freq_hz;
  240. dev_priv->vbt.backlight.active_low_pwm = entry->active_low_pwm;
  241. dev_priv->vbt.backlight.min_brightness = entry->min_brightness;
  242. DRM_DEBUG_KMS("VBT backlight PWM modulation frequency %u Hz, "
  243. "active %s, min brightness %u, level %u\n",
  244. dev_priv->vbt.backlight.pwm_freq_hz,
  245. dev_priv->vbt.backlight.active_low_pwm ? "low" : "high",
  246. dev_priv->vbt.backlight.min_brightness,
  247. backlight_data->level[panel_type]);
  248. }
  249. /* Try to find sdvo panel data */
  250. static void
  251. parse_sdvo_panel_data(struct drm_i915_private *dev_priv,
  252. const struct bdb_header *bdb)
  253. {
  254. const struct lvds_dvo_timing *dvo_timing;
  255. struct drm_display_mode *panel_fixed_mode;
  256. int index;
  257. index = i915.vbt_sdvo_panel_type;
  258. if (index == -2) {
  259. DRM_DEBUG_KMS("Ignore SDVO panel mode from BIOS VBT tables.\n");
  260. return;
  261. }
  262. if (index == -1) {
  263. const struct bdb_sdvo_lvds_options *sdvo_lvds_options;
  264. sdvo_lvds_options = find_section(bdb, BDB_SDVO_LVDS_OPTIONS);
  265. if (!sdvo_lvds_options)
  266. return;
  267. index = sdvo_lvds_options->panel_type;
  268. }
  269. dvo_timing = find_section(bdb, BDB_SDVO_PANEL_DTDS);
  270. if (!dvo_timing)
  271. return;
  272. panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL);
  273. if (!panel_fixed_mode)
  274. return;
  275. fill_detail_timing_data(panel_fixed_mode, dvo_timing + index);
  276. dev_priv->vbt.sdvo_lvds_vbt_mode = panel_fixed_mode;
  277. DRM_DEBUG_KMS("Found SDVO panel mode in BIOS VBT tables:\n");
  278. drm_mode_debug_printmodeline(panel_fixed_mode);
  279. }
  280. static int intel_bios_ssc_frequency(struct drm_device *dev,
  281. bool alternate)
  282. {
  283. switch (INTEL_INFO(dev)->gen) {
  284. case 2:
  285. return alternate ? 66667 : 48000;
  286. case 3:
  287. case 4:
  288. return alternate ? 100000 : 96000;
  289. default:
  290. return alternate ? 100000 : 120000;
  291. }
  292. }
  293. static void
  294. parse_general_features(struct drm_i915_private *dev_priv,
  295. const struct bdb_header *bdb)
  296. {
  297. struct drm_device *dev = dev_priv->dev;
  298. const struct bdb_general_features *general;
  299. general = find_section(bdb, BDB_GENERAL_FEATURES);
  300. if (general) {
  301. dev_priv->vbt.int_tv_support = general->int_tv_support;
  302. dev_priv->vbt.int_crt_support = general->int_crt_support;
  303. dev_priv->vbt.lvds_use_ssc = general->enable_ssc;
  304. dev_priv->vbt.lvds_ssc_freq =
  305. intel_bios_ssc_frequency(dev, general->ssc_freq);
  306. dev_priv->vbt.display_clock_mode = general->display_clock_mode;
  307. dev_priv->vbt.fdi_rx_polarity_inverted = general->fdi_rx_polarity_inverted;
  308. DRM_DEBUG_KMS("BDB_GENERAL_FEATURES int_tv_support %d int_crt_support %d lvds_use_ssc %d lvds_ssc_freq %d display_clock_mode %d fdi_rx_polarity_inverted %d\n",
  309. dev_priv->vbt.int_tv_support,
  310. dev_priv->vbt.int_crt_support,
  311. dev_priv->vbt.lvds_use_ssc,
  312. dev_priv->vbt.lvds_ssc_freq,
  313. dev_priv->vbt.display_clock_mode,
  314. dev_priv->vbt.fdi_rx_polarity_inverted);
  315. }
  316. }
  317. static void
  318. parse_general_definitions(struct drm_i915_private *dev_priv,
  319. const struct bdb_header *bdb)
  320. {
  321. const struct bdb_general_definitions *general;
  322. general = find_section(bdb, BDB_GENERAL_DEFINITIONS);
  323. if (general) {
  324. u16 block_size = get_blocksize(general);
  325. if (block_size >= sizeof(*general)) {
  326. int bus_pin = general->crt_ddc_gmbus_pin;
  327. DRM_DEBUG_KMS("crt_ddc_bus_pin: %d\n", bus_pin);
  328. if (intel_gmbus_is_valid_pin(dev_priv, bus_pin))
  329. dev_priv->vbt.crt_ddc_pin = bus_pin;
  330. } else {
  331. DRM_DEBUG_KMS("BDB_GD too small (%d). Invalid.\n",
  332. block_size);
  333. }
  334. }
  335. }
  336. static const union child_device_config *
  337. child_device_ptr(const struct bdb_general_definitions *p_defs, int i)
  338. {
  339. return (const void *) &p_defs->devices[i * p_defs->child_dev_size];
  340. }
  341. static void
  342. parse_sdvo_device_mapping(struct drm_i915_private *dev_priv,
  343. const struct bdb_header *bdb)
  344. {
  345. struct sdvo_device_mapping *p_mapping;
  346. const struct bdb_general_definitions *p_defs;
  347. const struct old_child_dev_config *child; /* legacy */
  348. int i, child_device_num, count;
  349. u16 block_size;
  350. p_defs = find_section(bdb, BDB_GENERAL_DEFINITIONS);
  351. if (!p_defs) {
  352. DRM_DEBUG_KMS("No general definition block is found, unable to construct sdvo mapping.\n");
  353. return;
  354. }
  355. /*
  356. * Only parse SDVO mappings when the general definitions block child
  357. * device size matches that of the *legacy* child device config
  358. * struct. Thus, SDVO mapping will be skipped for newer VBT.
  359. */
  360. if (p_defs->child_dev_size != sizeof(*child)) {
  361. DRM_DEBUG_KMS("Unsupported child device size for SDVO mapping.\n");
  362. return;
  363. }
  364. /* get the block size of general definitions */
  365. block_size = get_blocksize(p_defs);
  366. /* get the number of child device */
  367. child_device_num = (block_size - sizeof(*p_defs)) /
  368. p_defs->child_dev_size;
  369. count = 0;
  370. for (i = 0; i < child_device_num; i++) {
  371. child = &child_device_ptr(p_defs, i)->old;
  372. if (!child->device_type) {
  373. /* skip the device block if device type is invalid */
  374. continue;
  375. }
  376. if (child->slave_addr != SLAVE_ADDR1 &&
  377. child->slave_addr != SLAVE_ADDR2) {
  378. /*
  379. * If the slave address is neither 0x70 nor 0x72,
  380. * it is not a SDVO device. Skip it.
  381. */
  382. continue;
  383. }
  384. if (child->dvo_port != DEVICE_PORT_DVOB &&
  385. child->dvo_port != DEVICE_PORT_DVOC) {
  386. /* skip the incorrect SDVO port */
  387. DRM_DEBUG_KMS("Incorrect SDVO port. Skip it\n");
  388. continue;
  389. }
  390. DRM_DEBUG_KMS("the SDVO device with slave addr %2x is found on"
  391. " %s port\n",
  392. child->slave_addr,
  393. (child->dvo_port == DEVICE_PORT_DVOB) ?
  394. "SDVOB" : "SDVOC");
  395. p_mapping = &(dev_priv->sdvo_mappings[child->dvo_port - 1]);
  396. if (!p_mapping->initialized) {
  397. p_mapping->dvo_port = child->dvo_port;
  398. p_mapping->slave_addr = child->slave_addr;
  399. p_mapping->dvo_wiring = child->dvo_wiring;
  400. p_mapping->ddc_pin = child->ddc_pin;
  401. p_mapping->i2c_pin = child->i2c_pin;
  402. p_mapping->initialized = 1;
  403. DRM_DEBUG_KMS("SDVO device: dvo=%x, addr=%x, wiring=%d, ddc_pin=%d, i2c_pin=%d\n",
  404. p_mapping->dvo_port,
  405. p_mapping->slave_addr,
  406. p_mapping->dvo_wiring,
  407. p_mapping->ddc_pin,
  408. p_mapping->i2c_pin);
  409. } else {
  410. DRM_DEBUG_KMS("Maybe one SDVO port is shared by "
  411. "two SDVO device.\n");
  412. }
  413. if (child->slave2_addr) {
  414. /* Maybe this is a SDVO device with multiple inputs */
  415. /* And the mapping info is not added */
  416. DRM_DEBUG_KMS("there exists the slave2_addr. Maybe this"
  417. " is a SDVO device with multiple inputs.\n");
  418. }
  419. count++;
  420. }
  421. if (!count) {
  422. /* No SDVO device info is found */
  423. DRM_DEBUG_KMS("No SDVO device info is found in VBT\n");
  424. }
  425. return;
  426. }
  427. static void
  428. parse_driver_features(struct drm_i915_private *dev_priv,
  429. const struct bdb_header *bdb)
  430. {
  431. const struct bdb_driver_features *driver;
  432. driver = find_section(bdb, BDB_DRIVER_FEATURES);
  433. if (!driver)
  434. return;
  435. if (driver->lvds_config == BDB_DRIVER_FEATURE_EDP)
  436. dev_priv->vbt.edp_support = 1;
  437. if (driver->dual_frequency)
  438. dev_priv->render_reclock_avail = true;
  439. DRM_DEBUG_KMS("DRRS State Enabled:%d\n", driver->drrs_enabled);
  440. /*
  441. * If DRRS is not supported, drrs_type has to be set to 0.
  442. * This is because, VBT is configured in such a way that
  443. * static DRRS is 0 and DRRS not supported is represented by
  444. * driver->drrs_enabled=false
  445. */
  446. if (!driver->drrs_enabled)
  447. dev_priv->vbt.drrs_type = DRRS_NOT_SUPPORTED;
  448. }
  449. static void
  450. parse_edp(struct drm_i915_private *dev_priv, const struct bdb_header *bdb)
  451. {
  452. const struct bdb_edp *edp;
  453. const struct edp_power_seq *edp_pps;
  454. const struct edp_link_params *edp_link_params;
  455. edp = find_section(bdb, BDB_EDP);
  456. if (!edp) {
  457. if (dev_priv->vbt.edp_support)
  458. DRM_DEBUG_KMS("No eDP BDB found but eDP panel supported.\n");
  459. return;
  460. }
  461. switch ((edp->color_depth >> (panel_type * 2)) & 3) {
  462. case EDP_18BPP:
  463. dev_priv->vbt.edp_bpp = 18;
  464. break;
  465. case EDP_24BPP:
  466. dev_priv->vbt.edp_bpp = 24;
  467. break;
  468. case EDP_30BPP:
  469. dev_priv->vbt.edp_bpp = 30;
  470. break;
  471. }
  472. /* Get the eDP sequencing and link info */
  473. edp_pps = &edp->power_seqs[panel_type];
  474. edp_link_params = &edp->link_params[panel_type];
  475. dev_priv->vbt.edp_pps = *edp_pps;
  476. switch (edp_link_params->rate) {
  477. case EDP_RATE_1_62:
  478. dev_priv->vbt.edp_rate = DP_LINK_BW_1_62;
  479. break;
  480. case EDP_RATE_2_7:
  481. dev_priv->vbt.edp_rate = DP_LINK_BW_2_7;
  482. break;
  483. default:
  484. DRM_DEBUG_KMS("VBT has unknown eDP link rate value %u\n",
  485. edp_link_params->rate);
  486. break;
  487. }
  488. switch (edp_link_params->lanes) {
  489. case EDP_LANE_1:
  490. dev_priv->vbt.edp_lanes = 1;
  491. break;
  492. case EDP_LANE_2:
  493. dev_priv->vbt.edp_lanes = 2;
  494. break;
  495. case EDP_LANE_4:
  496. dev_priv->vbt.edp_lanes = 4;
  497. break;
  498. default:
  499. DRM_DEBUG_KMS("VBT has unknown eDP lane count value %u\n",
  500. edp_link_params->lanes);
  501. break;
  502. }
  503. switch (edp_link_params->preemphasis) {
  504. case EDP_PREEMPHASIS_NONE:
  505. dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_0;
  506. break;
  507. case EDP_PREEMPHASIS_3_5dB:
  508. dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_1;
  509. break;
  510. case EDP_PREEMPHASIS_6dB:
  511. dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_2;
  512. break;
  513. case EDP_PREEMPHASIS_9_5dB:
  514. dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_3;
  515. break;
  516. default:
  517. DRM_DEBUG_KMS("VBT has unknown eDP pre-emphasis value %u\n",
  518. edp_link_params->preemphasis);
  519. break;
  520. }
  521. switch (edp_link_params->vswing) {
  522. case EDP_VSWING_0_4V:
  523. dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_0;
  524. break;
  525. case EDP_VSWING_0_6V:
  526. dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_1;
  527. break;
  528. case EDP_VSWING_0_8V:
  529. dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
  530. break;
  531. case EDP_VSWING_1_2V:
  532. dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
  533. break;
  534. default:
  535. DRM_DEBUG_KMS("VBT has unknown eDP voltage swing value %u\n",
  536. edp_link_params->vswing);
  537. break;
  538. }
  539. if (bdb->version >= 173) {
  540. uint8_t vswing;
  541. /* Don't read from VBT if module parameter has valid value*/
  542. if (i915.edp_vswing) {
  543. dev_priv->edp_low_vswing = i915.edp_vswing == 1;
  544. } else {
  545. vswing = (edp->edp_vswing_preemph >> (panel_type * 4)) & 0xF;
  546. dev_priv->edp_low_vswing = vswing == 0;
  547. }
  548. }
  549. }
  550. static void
  551. parse_psr(struct drm_i915_private *dev_priv, const struct bdb_header *bdb)
  552. {
  553. const struct bdb_psr *psr;
  554. const struct psr_table *psr_table;
  555. psr = find_section(bdb, BDB_PSR);
  556. if (!psr) {
  557. DRM_DEBUG_KMS("No PSR BDB found.\n");
  558. return;
  559. }
  560. psr_table = &psr->psr_table[panel_type];
  561. dev_priv->vbt.psr.full_link = psr_table->full_link;
  562. dev_priv->vbt.psr.require_aux_wakeup = psr_table->require_aux_to_wakeup;
  563. /* Allowed VBT values goes from 0 to 15 */
  564. dev_priv->vbt.psr.idle_frames = psr_table->idle_frames < 0 ? 0 :
  565. psr_table->idle_frames > 15 ? 15 : psr_table->idle_frames;
  566. switch (psr_table->lines_to_wait) {
  567. case 0:
  568. dev_priv->vbt.psr.lines_to_wait = PSR_0_LINES_TO_WAIT;
  569. break;
  570. case 1:
  571. dev_priv->vbt.psr.lines_to_wait = PSR_1_LINE_TO_WAIT;
  572. break;
  573. case 2:
  574. dev_priv->vbt.psr.lines_to_wait = PSR_4_LINES_TO_WAIT;
  575. break;
  576. case 3:
  577. dev_priv->vbt.psr.lines_to_wait = PSR_8_LINES_TO_WAIT;
  578. break;
  579. default:
  580. DRM_DEBUG_KMS("VBT has unknown PSR lines to wait %u\n",
  581. psr_table->lines_to_wait);
  582. break;
  583. }
  584. dev_priv->vbt.psr.tp1_wakeup_time = psr_table->tp1_wakeup_time;
  585. dev_priv->vbt.psr.tp2_tp3_wakeup_time = psr_table->tp2_tp3_wakeup_time;
  586. }
  587. static u8 *goto_next_sequence(u8 *data, int *size)
  588. {
  589. u16 len;
  590. int tmp = *size;
  591. if (--tmp < 0)
  592. return NULL;
  593. /* goto first element */
  594. data++;
  595. while (1) {
  596. switch (*data) {
  597. case MIPI_SEQ_ELEM_SEND_PKT:
  598. /*
  599. * skip by this element payload size
  600. * skip elem id, command flag and data type
  601. */
  602. tmp -= 5;
  603. if (tmp < 0)
  604. return NULL;
  605. data += 3;
  606. len = *((u16 *)data);
  607. tmp -= len;
  608. if (tmp < 0)
  609. return NULL;
  610. /* skip by len */
  611. data = data + 2 + len;
  612. break;
  613. case MIPI_SEQ_ELEM_DELAY:
  614. /* skip by elem id, and delay is 4 bytes */
  615. tmp -= 5;
  616. if (tmp < 0)
  617. return NULL;
  618. data += 5;
  619. break;
  620. case MIPI_SEQ_ELEM_GPIO:
  621. tmp -= 3;
  622. if (tmp < 0)
  623. return NULL;
  624. data += 3;
  625. break;
  626. default:
  627. DRM_ERROR("Unknown element\n");
  628. return NULL;
  629. }
  630. /* end of sequence ? */
  631. if (*data == 0)
  632. break;
  633. }
  634. /* goto next sequence or end of block byte */
  635. if (--tmp < 0)
  636. return NULL;
  637. data++;
  638. /* update amount of data left for the sequence block to be parsed */
  639. *size = tmp;
  640. return data;
  641. }
  642. static void
  643. parse_mipi(struct drm_i915_private *dev_priv, const struct bdb_header *bdb)
  644. {
  645. const struct bdb_mipi_config *start;
  646. const struct bdb_mipi_sequence *sequence;
  647. const struct mipi_config *config;
  648. const struct mipi_pps_data *pps;
  649. u8 *data;
  650. const u8 *seq_data;
  651. int i, panel_id, seq_size;
  652. u16 block_size;
  653. /* parse MIPI blocks only if LFP type is MIPI */
  654. if (!dev_priv->vbt.has_mipi)
  655. return;
  656. /* Initialize this to undefined indicating no generic MIPI support */
  657. dev_priv->vbt.dsi.panel_id = MIPI_DSI_UNDEFINED_PANEL_ID;
  658. /* Block #40 is already parsed and panel_fixed_mode is
  659. * stored in dev_priv->lfp_lvds_vbt_mode
  660. * resuse this when needed
  661. */
  662. /* Parse #52 for panel index used from panel_type already
  663. * parsed
  664. */
  665. start = find_section(bdb, BDB_MIPI_CONFIG);
  666. if (!start) {
  667. DRM_DEBUG_KMS("No MIPI config BDB found");
  668. return;
  669. }
  670. DRM_DEBUG_DRIVER("Found MIPI Config block, panel index = %d\n",
  671. panel_type);
  672. /*
  673. * get hold of the correct configuration block and pps data as per
  674. * the panel_type as index
  675. */
  676. config = &start->config[panel_type];
  677. pps = &start->pps[panel_type];
  678. /* store as of now full data. Trim when we realise all is not needed */
  679. dev_priv->vbt.dsi.config = kmemdup(config, sizeof(struct mipi_config), GFP_KERNEL);
  680. if (!dev_priv->vbt.dsi.config)
  681. return;
  682. dev_priv->vbt.dsi.pps = kmemdup(pps, sizeof(struct mipi_pps_data), GFP_KERNEL);
  683. if (!dev_priv->vbt.dsi.pps) {
  684. kfree(dev_priv->vbt.dsi.config);
  685. return;
  686. }
  687. /* We have mandatory mipi config blocks. Initialize as generic panel */
  688. dev_priv->vbt.dsi.panel_id = MIPI_DSI_GENERIC_PANEL_ID;
  689. /* Check if we have sequence block as well */
  690. sequence = find_section(bdb, BDB_MIPI_SEQUENCE);
  691. if (!sequence) {
  692. DRM_DEBUG_KMS("No MIPI Sequence found, parsing complete\n");
  693. return;
  694. }
  695. /* Fail gracefully for forward incompatible sequence block. */
  696. if (sequence->version >= 3) {
  697. DRM_ERROR("Unable to parse MIPI Sequence Block v3+\n");
  698. return;
  699. }
  700. DRM_DEBUG_DRIVER("Found MIPI sequence block\n");
  701. block_size = get_blocksize(sequence);
  702. /*
  703. * parse the sequence block for individual sequences
  704. */
  705. dev_priv->vbt.dsi.seq_version = sequence->version;
  706. seq_data = &sequence->data[0];
  707. /*
  708. * sequence block is variable length and hence we need to parse and
  709. * get the sequence data for specific panel id
  710. */
  711. for (i = 0; i < MAX_MIPI_CONFIGURATIONS; i++) {
  712. panel_id = *seq_data;
  713. seq_size = *((u16 *) (seq_data + 1));
  714. if (panel_id == panel_type)
  715. break;
  716. /* skip the sequence including seq header of 3 bytes */
  717. seq_data = seq_data + 3 + seq_size;
  718. if ((seq_data - &sequence->data[0]) > block_size) {
  719. DRM_ERROR("Sequence start is beyond sequence block size, corrupted sequence block\n");
  720. return;
  721. }
  722. }
  723. if (i == MAX_MIPI_CONFIGURATIONS) {
  724. DRM_ERROR("Sequence block detected but no valid configuration\n");
  725. return;
  726. }
  727. /* check if found sequence is completely within the sequence block
  728. * just being paranoid */
  729. if (seq_size > block_size) {
  730. DRM_ERROR("Corrupted sequence/size, bailing out\n");
  731. return;
  732. }
  733. /* skip the panel id(1 byte) and seq size(2 bytes) */
  734. dev_priv->vbt.dsi.data = kmemdup(seq_data + 3, seq_size, GFP_KERNEL);
  735. if (!dev_priv->vbt.dsi.data)
  736. return;
  737. /*
  738. * loop into the sequence data and split into multiple sequneces
  739. * There are only 5 types of sequences as of now
  740. */
  741. data = dev_priv->vbt.dsi.data;
  742. dev_priv->vbt.dsi.size = seq_size;
  743. /* two consecutive 0x00 indicate end of all sequences */
  744. while (1) {
  745. int seq_id = *data;
  746. if (MIPI_SEQ_MAX > seq_id && seq_id > MIPI_SEQ_UNDEFINED) {
  747. dev_priv->vbt.dsi.sequence[seq_id] = data;
  748. DRM_DEBUG_DRIVER("Found mipi sequence - %d\n", seq_id);
  749. } else {
  750. DRM_ERROR("undefined sequence\n");
  751. goto err;
  752. }
  753. /* partial parsing to skip elements */
  754. data = goto_next_sequence(data, &seq_size);
  755. if (data == NULL) {
  756. DRM_ERROR("Sequence elements going beyond block itself. Sequence block parsing failed\n");
  757. goto err;
  758. }
  759. if (*data == 0)
  760. break; /* end of sequence reached */
  761. }
  762. DRM_DEBUG_DRIVER("MIPI related vbt parsing complete\n");
  763. return;
  764. err:
  765. kfree(dev_priv->vbt.dsi.data);
  766. dev_priv->vbt.dsi.data = NULL;
  767. /* error during parsing so set all pointers to null
  768. * because of partial parsing */
  769. memset(dev_priv->vbt.dsi.sequence, 0, sizeof(dev_priv->vbt.dsi.sequence));
  770. }
  771. static u8 translate_iboost(u8 val)
  772. {
  773. static const u8 mapping[] = { 1, 3, 7 }; /* See VBT spec */
  774. if (val >= ARRAY_SIZE(mapping)) {
  775. DRM_DEBUG_KMS("Unsupported I_boost value found in VBT (%d), display may not work properly\n", val);
  776. return 0;
  777. }
  778. return mapping[val];
  779. }
  780. static void parse_ddi_port(struct drm_i915_private *dev_priv, enum port port,
  781. const struct bdb_header *bdb)
  782. {
  783. union child_device_config *it, *child = NULL;
  784. struct ddi_vbt_port_info *info = &dev_priv->vbt.ddi_port_info[port];
  785. uint8_t hdmi_level_shift;
  786. int i, j;
  787. bool is_dvi, is_hdmi, is_dp, is_edp, is_crt;
  788. uint8_t aux_channel, ddc_pin;
  789. /* Each DDI port can have more than one value on the "DVO Port" field,
  790. * so look for all the possible values for each port and abort if more
  791. * than one is found. */
  792. int dvo_ports[][3] = {
  793. {DVO_PORT_HDMIA, DVO_PORT_DPA, -1},
  794. {DVO_PORT_HDMIB, DVO_PORT_DPB, -1},
  795. {DVO_PORT_HDMIC, DVO_PORT_DPC, -1},
  796. {DVO_PORT_HDMID, DVO_PORT_DPD, -1},
  797. {DVO_PORT_CRT, DVO_PORT_HDMIE, DVO_PORT_DPE},
  798. };
  799. /* Find the child device to use, abort if more than one found. */
  800. for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
  801. it = dev_priv->vbt.child_dev + i;
  802. for (j = 0; j < 3; j++) {
  803. if (dvo_ports[port][j] == -1)
  804. break;
  805. if (it->common.dvo_port == dvo_ports[port][j]) {
  806. if (child) {
  807. DRM_DEBUG_KMS("More than one child device for port %c in VBT.\n",
  808. port_name(port));
  809. return;
  810. }
  811. child = it;
  812. }
  813. }
  814. }
  815. if (!child)
  816. return;
  817. aux_channel = child->raw[25];
  818. ddc_pin = child->common.ddc_pin;
  819. is_dvi = child->common.device_type & DEVICE_TYPE_TMDS_DVI_SIGNALING;
  820. is_dp = child->common.device_type & DEVICE_TYPE_DISPLAYPORT_OUTPUT;
  821. is_crt = child->common.device_type & DEVICE_TYPE_ANALOG_OUTPUT;
  822. is_hdmi = is_dvi && (child->common.device_type & DEVICE_TYPE_NOT_HDMI_OUTPUT) == 0;
  823. is_edp = is_dp && (child->common.device_type & DEVICE_TYPE_INTERNAL_CONNECTOR);
  824. if (port == PORT_A && is_dvi) {
  825. DRM_DEBUG_KMS("VBT claims port A supports DVI%s, ignoring\n",
  826. is_hdmi ? "/HDMI" : "");
  827. is_dvi = false;
  828. is_hdmi = false;
  829. }
  830. info->supports_dvi = is_dvi;
  831. info->supports_hdmi = is_hdmi;
  832. info->supports_dp = is_dp;
  833. DRM_DEBUG_KMS("Port %c VBT info: DP:%d HDMI:%d DVI:%d EDP:%d CRT:%d\n",
  834. port_name(port), is_dp, is_hdmi, is_dvi, is_edp, is_crt);
  835. if (is_edp && is_dvi)
  836. DRM_DEBUG_KMS("Internal DP port %c is TMDS compatible\n",
  837. port_name(port));
  838. if (is_crt && port != PORT_E)
  839. DRM_DEBUG_KMS("Port %c is analog\n", port_name(port));
  840. if (is_crt && (is_dvi || is_dp))
  841. DRM_DEBUG_KMS("Analog port %c is also DP or TMDS compatible\n",
  842. port_name(port));
  843. if (is_dvi && (port == PORT_A || port == PORT_E))
  844. DRM_DEBUG_KMS("Port %c is TMDS compatible\n", port_name(port));
  845. if (!is_dvi && !is_dp && !is_crt)
  846. DRM_DEBUG_KMS("Port %c is not DP/TMDS/CRT compatible\n",
  847. port_name(port));
  848. if (is_edp && (port == PORT_B || port == PORT_C || port == PORT_E))
  849. DRM_DEBUG_KMS("Port %c is internal DP\n", port_name(port));
  850. if (is_dvi) {
  851. if (port == PORT_E) {
  852. info->alternate_ddc_pin = ddc_pin;
  853. /* if DDIE share ddc pin with other port, then
  854. * dvi/hdmi couldn't exist on the shared port.
  855. * Otherwise they share the same ddc bin and system
  856. * couldn't communicate with them seperately. */
  857. if (ddc_pin == DDC_PIN_B) {
  858. dev_priv->vbt.ddi_port_info[PORT_B].supports_dvi = 0;
  859. dev_priv->vbt.ddi_port_info[PORT_B].supports_hdmi = 0;
  860. } else if (ddc_pin == DDC_PIN_C) {
  861. dev_priv->vbt.ddi_port_info[PORT_C].supports_dvi = 0;
  862. dev_priv->vbt.ddi_port_info[PORT_C].supports_hdmi = 0;
  863. } else if (ddc_pin == DDC_PIN_D) {
  864. dev_priv->vbt.ddi_port_info[PORT_D].supports_dvi = 0;
  865. dev_priv->vbt.ddi_port_info[PORT_D].supports_hdmi = 0;
  866. }
  867. } else if (ddc_pin == DDC_PIN_B && port != PORT_B)
  868. DRM_DEBUG_KMS("Unexpected DDC pin for port B\n");
  869. else if (ddc_pin == DDC_PIN_C && port != PORT_C)
  870. DRM_DEBUG_KMS("Unexpected DDC pin for port C\n");
  871. else if (ddc_pin == DDC_PIN_D && port != PORT_D)
  872. DRM_DEBUG_KMS("Unexpected DDC pin for port D\n");
  873. }
  874. if (is_dp) {
  875. if (port == PORT_E) {
  876. info->alternate_aux_channel = aux_channel;
  877. /* if DDIE share aux channel with other port, then
  878. * DP couldn't exist on the shared port. Otherwise
  879. * they share the same aux channel and system
  880. * couldn't communicate with them seperately. */
  881. if (aux_channel == DP_AUX_A)
  882. dev_priv->vbt.ddi_port_info[PORT_A].supports_dp = 0;
  883. else if (aux_channel == DP_AUX_B)
  884. dev_priv->vbt.ddi_port_info[PORT_B].supports_dp = 0;
  885. else if (aux_channel == DP_AUX_C)
  886. dev_priv->vbt.ddi_port_info[PORT_C].supports_dp = 0;
  887. else if (aux_channel == DP_AUX_D)
  888. dev_priv->vbt.ddi_port_info[PORT_D].supports_dp = 0;
  889. }
  890. else if (aux_channel == DP_AUX_A && port != PORT_A)
  891. DRM_DEBUG_KMS("Unexpected AUX channel for port A\n");
  892. else if (aux_channel == DP_AUX_B && port != PORT_B)
  893. DRM_DEBUG_KMS("Unexpected AUX channel for port B\n");
  894. else if (aux_channel == DP_AUX_C && port != PORT_C)
  895. DRM_DEBUG_KMS("Unexpected AUX channel for port C\n");
  896. else if (aux_channel == DP_AUX_D && port != PORT_D)
  897. DRM_DEBUG_KMS("Unexpected AUX channel for port D\n");
  898. }
  899. if (bdb->version >= 158) {
  900. /* The VBT HDMI level shift values match the table we have. */
  901. hdmi_level_shift = child->raw[7] & 0xF;
  902. DRM_DEBUG_KMS("VBT HDMI level shift for port %c: %d\n",
  903. port_name(port),
  904. hdmi_level_shift);
  905. info->hdmi_level_shift = hdmi_level_shift;
  906. }
  907. /* Parse the I_boost config for SKL and above */
  908. if (bdb->version >= 196 && (child->common.flags_1 & IBOOST_ENABLE)) {
  909. info->dp_boost_level = translate_iboost(child->common.iboost_level & 0xF);
  910. DRM_DEBUG_KMS("VBT (e)DP boost level for port %c: %d\n",
  911. port_name(port), info->dp_boost_level);
  912. info->hdmi_boost_level = translate_iboost(child->common.iboost_level >> 4);
  913. DRM_DEBUG_KMS("VBT HDMI boost level for port %c: %d\n",
  914. port_name(port), info->hdmi_boost_level);
  915. }
  916. }
  917. static void parse_ddi_ports(struct drm_i915_private *dev_priv,
  918. const struct bdb_header *bdb)
  919. {
  920. struct drm_device *dev = dev_priv->dev;
  921. enum port port;
  922. if (!HAS_DDI(dev))
  923. return;
  924. if (!dev_priv->vbt.child_dev_num)
  925. return;
  926. if (bdb->version < 155)
  927. return;
  928. for (port = PORT_A; port < I915_MAX_PORTS; port++)
  929. parse_ddi_port(dev_priv, port, bdb);
  930. }
  931. static void
  932. parse_device_mapping(struct drm_i915_private *dev_priv,
  933. const struct bdb_header *bdb)
  934. {
  935. const struct bdb_general_definitions *p_defs;
  936. const union child_device_config *p_child;
  937. union child_device_config *child_dev_ptr;
  938. int i, child_device_num, count;
  939. u8 expected_size;
  940. u16 block_size;
  941. p_defs = find_section(bdb, BDB_GENERAL_DEFINITIONS);
  942. if (!p_defs) {
  943. DRM_DEBUG_KMS("No general definition block is found, no devices defined.\n");
  944. return;
  945. }
  946. if (bdb->version < 195) {
  947. expected_size = sizeof(struct old_child_dev_config);
  948. } else if (bdb->version == 195) {
  949. expected_size = 37;
  950. } else if (bdb->version <= 197) {
  951. expected_size = 38;
  952. } else {
  953. expected_size = 38;
  954. BUILD_BUG_ON(sizeof(*p_child) < 38);
  955. DRM_DEBUG_DRIVER("Expected child device config size for VBT version %u not known; assuming %u\n",
  956. bdb->version, expected_size);
  957. }
  958. /* The legacy sized child device config is the minimum we need. */
  959. if (p_defs->child_dev_size < sizeof(struct old_child_dev_config)) {
  960. DRM_ERROR("Child device config size %u is too small.\n",
  961. p_defs->child_dev_size);
  962. return;
  963. }
  964. /* Flag an error for unexpected size, but continue anyway. */
  965. if (p_defs->child_dev_size != expected_size)
  966. DRM_ERROR("Unexpected child device config size %u (expected %u for VBT version %u)\n",
  967. p_defs->child_dev_size, expected_size, bdb->version);
  968. /* get the block size of general definitions */
  969. block_size = get_blocksize(p_defs);
  970. /* get the number of child device */
  971. child_device_num = (block_size - sizeof(*p_defs)) /
  972. p_defs->child_dev_size;
  973. count = 0;
  974. /* get the number of child device that is present */
  975. for (i = 0; i < child_device_num; i++) {
  976. p_child = child_device_ptr(p_defs, i);
  977. if (!p_child->common.device_type) {
  978. /* skip the device block if device type is invalid */
  979. continue;
  980. }
  981. count++;
  982. }
  983. if (!count) {
  984. DRM_DEBUG_KMS("no child dev is parsed from VBT\n");
  985. return;
  986. }
  987. dev_priv->vbt.child_dev = kcalloc(count, sizeof(*p_child), GFP_KERNEL);
  988. if (!dev_priv->vbt.child_dev) {
  989. DRM_DEBUG_KMS("No memory space for child device\n");
  990. return;
  991. }
  992. dev_priv->vbt.child_dev_num = count;
  993. count = 0;
  994. for (i = 0; i < child_device_num; i++) {
  995. p_child = child_device_ptr(p_defs, i);
  996. if (!p_child->common.device_type) {
  997. /* skip the device block if device type is invalid */
  998. continue;
  999. }
  1000. if (p_child->common.dvo_port >= DVO_PORT_MIPIA
  1001. && p_child->common.dvo_port <= DVO_PORT_MIPID
  1002. &&p_child->common.device_type & DEVICE_TYPE_MIPI_OUTPUT) {
  1003. DRM_DEBUG_KMS("Found MIPI as LFP\n");
  1004. dev_priv->vbt.has_mipi = 1;
  1005. dev_priv->vbt.dsi.port = p_child->common.dvo_port;
  1006. }
  1007. child_dev_ptr = dev_priv->vbt.child_dev + count;
  1008. count++;
  1009. /*
  1010. * Copy as much as we know (sizeof) and is available
  1011. * (child_dev_size) of the child device. Accessing the data must
  1012. * depend on VBT version.
  1013. */
  1014. memcpy(child_dev_ptr, p_child,
  1015. min_t(size_t, p_defs->child_dev_size, sizeof(*p_child)));
  1016. }
  1017. return;
  1018. }
  1019. static void
  1020. init_vbt_defaults(struct drm_i915_private *dev_priv)
  1021. {
  1022. struct drm_device *dev = dev_priv->dev;
  1023. enum port port;
  1024. dev_priv->vbt.crt_ddc_pin = GMBUS_PIN_VGADDC;
  1025. /* Default to having backlight */
  1026. dev_priv->vbt.backlight.present = true;
  1027. /* LFP panel data */
  1028. dev_priv->vbt.lvds_dither = 1;
  1029. dev_priv->vbt.lvds_vbt = 0;
  1030. /* SDVO panel data */
  1031. dev_priv->vbt.sdvo_lvds_vbt_mode = NULL;
  1032. /* general features */
  1033. dev_priv->vbt.int_tv_support = 1;
  1034. dev_priv->vbt.int_crt_support = 1;
  1035. /* Default to using SSC */
  1036. dev_priv->vbt.lvds_use_ssc = 1;
  1037. /*
  1038. * Core/SandyBridge/IvyBridge use alternative (120MHz) reference
  1039. * clock for LVDS.
  1040. */
  1041. dev_priv->vbt.lvds_ssc_freq = intel_bios_ssc_frequency(dev,
  1042. !HAS_PCH_SPLIT(dev));
  1043. DRM_DEBUG_KMS("Set default to SSC at %d kHz\n", dev_priv->vbt.lvds_ssc_freq);
  1044. for (port = PORT_A; port < I915_MAX_PORTS; port++) {
  1045. struct ddi_vbt_port_info *info =
  1046. &dev_priv->vbt.ddi_port_info[port];
  1047. info->hdmi_level_shift = HDMI_LEVEL_SHIFT_UNKNOWN;
  1048. info->supports_dvi = (port != PORT_A && port != PORT_E);
  1049. info->supports_hdmi = info->supports_dvi;
  1050. info->supports_dp = (port != PORT_E);
  1051. }
  1052. }
  1053. static int intel_no_opregion_vbt_callback(const struct dmi_system_id *id)
  1054. {
  1055. DRM_DEBUG_KMS("Falling back to manually reading VBT from "
  1056. "VBIOS ROM for %s\n",
  1057. id->ident);
  1058. return 1;
  1059. }
  1060. static const struct dmi_system_id intel_no_opregion_vbt[] = {
  1061. {
  1062. .callback = intel_no_opregion_vbt_callback,
  1063. .ident = "ThinkCentre A57",
  1064. .matches = {
  1065. DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
  1066. DMI_MATCH(DMI_PRODUCT_NAME, "97027RG"),
  1067. },
  1068. },
  1069. { }
  1070. };
  1071. static const struct bdb_header *validate_vbt(const void *base,
  1072. size_t size,
  1073. const void *_vbt,
  1074. const char *source)
  1075. {
  1076. size_t offset = _vbt - base;
  1077. const struct vbt_header *vbt = _vbt;
  1078. const struct bdb_header *bdb;
  1079. if (offset + sizeof(struct vbt_header) > size) {
  1080. DRM_DEBUG_DRIVER("VBT header incomplete\n");
  1081. return NULL;
  1082. }
  1083. if (memcmp(vbt->signature, "$VBT", 4)) {
  1084. DRM_DEBUG_DRIVER("VBT invalid signature\n");
  1085. return NULL;
  1086. }
  1087. offset += vbt->bdb_offset;
  1088. if (offset + sizeof(struct bdb_header) > size) {
  1089. DRM_DEBUG_DRIVER("BDB header incomplete\n");
  1090. return NULL;
  1091. }
  1092. bdb = base + offset;
  1093. if (offset + bdb->bdb_size > size) {
  1094. DRM_DEBUG_DRIVER("BDB incomplete\n");
  1095. return NULL;
  1096. }
  1097. DRM_DEBUG_KMS("Using VBT from %s: %20s\n",
  1098. source, vbt->signature);
  1099. return bdb;
  1100. }
  1101. static const struct bdb_header *find_vbt(void __iomem *bios, size_t size)
  1102. {
  1103. const struct bdb_header *bdb = NULL;
  1104. size_t i;
  1105. /* Scour memory looking for the VBT signature. */
  1106. for (i = 0; i + 4 < size; i++) {
  1107. if (ioread32(bios + i) == *((const u32 *) "$VBT")) {
  1108. /*
  1109. * This is the one place where we explicitly discard the
  1110. * address space (__iomem) of the BIOS/VBT. From now on
  1111. * everything is based on 'base', and treated as regular
  1112. * memory.
  1113. */
  1114. void *_bios = (void __force *) bios;
  1115. bdb = validate_vbt(_bios, size, _bios + i, "PCI ROM");
  1116. break;
  1117. }
  1118. }
  1119. return bdb;
  1120. }
  1121. /**
  1122. * intel_parse_bios - find VBT and initialize settings from the BIOS
  1123. * @dev: DRM device
  1124. *
  1125. * Loads the Video BIOS and checks that the VBT exists. Sets scratch registers
  1126. * to appropriate values.
  1127. *
  1128. * Returns 0 on success, nonzero on failure.
  1129. */
  1130. int
  1131. intel_parse_bios(struct drm_device *dev)
  1132. {
  1133. struct drm_i915_private *dev_priv = dev->dev_private;
  1134. struct pci_dev *pdev = dev->pdev;
  1135. const struct bdb_header *bdb = NULL;
  1136. u8 __iomem *bios = NULL;
  1137. if (HAS_PCH_NOP(dev))
  1138. return -ENODEV;
  1139. init_vbt_defaults(dev_priv);
  1140. /* XXX Should this validation be moved to intel_opregion.c? */
  1141. if (!dmi_check_system(intel_no_opregion_vbt) && dev_priv->opregion.vbt)
  1142. bdb = validate_vbt(dev_priv->opregion.header, OPREGION_SIZE,
  1143. dev_priv->opregion.vbt, "OpRegion");
  1144. if (bdb == NULL) {
  1145. size_t size;
  1146. bios = pci_map_rom(pdev, &size);
  1147. if (!bios)
  1148. return -1;
  1149. bdb = find_vbt(bios, size);
  1150. if (!bdb) {
  1151. pci_unmap_rom(pdev, bios);
  1152. return -1;
  1153. }
  1154. }
  1155. /* Grab useful general definitions */
  1156. parse_general_features(dev_priv, bdb);
  1157. parse_general_definitions(dev_priv, bdb);
  1158. parse_lfp_panel_data(dev_priv, bdb);
  1159. parse_lfp_backlight(dev_priv, bdb);
  1160. parse_sdvo_panel_data(dev_priv, bdb);
  1161. parse_sdvo_device_mapping(dev_priv, bdb);
  1162. parse_device_mapping(dev_priv, bdb);
  1163. parse_driver_features(dev_priv, bdb);
  1164. parse_edp(dev_priv, bdb);
  1165. parse_psr(dev_priv, bdb);
  1166. parse_mipi(dev_priv, bdb);
  1167. parse_ddi_ports(dev_priv, bdb);
  1168. if (bios)
  1169. pci_unmap_rom(pdev, bios);
  1170. return 0;
  1171. }
  1172. /**
  1173. * intel_bios_is_port_present - is the specified digital port present
  1174. * @dev_priv: i915 device instance
  1175. * @port: port to check
  1176. *
  1177. * Return true if the device in %port is present.
  1178. */
  1179. bool intel_bios_is_port_present(struct drm_i915_private *dev_priv, enum port port)
  1180. {
  1181. static const struct {
  1182. u16 dp, hdmi;
  1183. } port_mapping[] = {
  1184. [PORT_B] = { DVO_PORT_DPB, DVO_PORT_HDMIB, },
  1185. [PORT_C] = { DVO_PORT_DPC, DVO_PORT_HDMIC, },
  1186. [PORT_D] = { DVO_PORT_DPD, DVO_PORT_HDMID, },
  1187. [PORT_E] = { DVO_PORT_DPE, DVO_PORT_HDMIE, },
  1188. };
  1189. int i;
  1190. /* FIXME maybe deal with port A as well? */
  1191. if (WARN_ON(port == PORT_A) || port >= ARRAY_SIZE(port_mapping))
  1192. return false;
  1193. if (!dev_priv->vbt.child_dev_num)
  1194. return false;
  1195. for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
  1196. const union child_device_config *p_child =
  1197. &dev_priv->vbt.child_dev[i];
  1198. if ((p_child->common.dvo_port == port_mapping[port].dp ||
  1199. p_child->common.dvo_port == port_mapping[port].hdmi) &&
  1200. (p_child->common.device_type & (DEVICE_TYPE_TMDS_DVI_SIGNALING |
  1201. DEVICE_TYPE_DISPLAYPORT_OUTPUT)))
  1202. return true;
  1203. }
  1204. return false;
  1205. }