intel_bios.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 "drmP.h"
  28. #include "drm.h"
  29. #include "i915_drm.h"
  30. #include "i915_drv.h"
  31. #include "intel_bios.h"
  32. static void *
  33. find_section(struct bdb_header *bdb, int section_id)
  34. {
  35. u8 *base = (u8 *)bdb;
  36. int index = 0;
  37. u16 total, current_size;
  38. u8 current_id;
  39. /* skip to first section */
  40. index += bdb->header_size;
  41. total = bdb->bdb_size;
  42. /* walk the sections looking for section_id */
  43. while (index < total) {
  44. current_id = *(base + index);
  45. index++;
  46. current_size = *((u16 *)(base + index));
  47. index += 2;
  48. if (current_id == section_id)
  49. return base + index;
  50. index += current_size;
  51. }
  52. return NULL;
  53. }
  54. /* Try to find panel data */
  55. static void
  56. parse_panel_data(struct drm_i915_private *dev_priv, struct bdb_header *bdb)
  57. {
  58. struct bdb_lvds_options *lvds_options;
  59. struct bdb_lvds_lfp_data *lvds_lfp_data;
  60. struct bdb_lvds_lfp_data_entry *entry;
  61. struct lvds_dvo_timing *dvo_timing;
  62. struct drm_display_mode *panel_fixed_mode;
  63. /* Defaults if we can't find VBT info */
  64. dev_priv->lvds_dither = 0;
  65. dev_priv->lvds_vbt = 0;
  66. lvds_options = find_section(bdb, BDB_LVDS_OPTIONS);
  67. if (!lvds_options)
  68. return;
  69. dev_priv->lvds_dither = lvds_options->pixel_dither;
  70. if (lvds_options->panel_type == 0xff)
  71. return;
  72. lvds_lfp_data = find_section(bdb, BDB_LVDS_LFP_DATA);
  73. if (!lvds_lfp_data)
  74. return;
  75. dev_priv->lvds_vbt = 1;
  76. entry = &lvds_lfp_data->data[lvds_options->panel_type];
  77. dvo_timing = &entry->dvo_timing;
  78. panel_fixed_mode = drm_calloc(1, sizeof(*panel_fixed_mode),
  79. DRM_MEM_DRIVER);
  80. panel_fixed_mode->hdisplay = (dvo_timing->hactive_hi << 8) |
  81. dvo_timing->hactive_lo;
  82. panel_fixed_mode->hsync_start = panel_fixed_mode->hdisplay +
  83. ((dvo_timing->hsync_off_hi << 8) | dvo_timing->hsync_off_lo);
  84. panel_fixed_mode->hsync_end = panel_fixed_mode->hsync_start +
  85. dvo_timing->hsync_pulse_width;
  86. panel_fixed_mode->htotal = panel_fixed_mode->hdisplay +
  87. ((dvo_timing->hblank_hi << 8) | dvo_timing->hblank_lo);
  88. panel_fixed_mode->vdisplay = (dvo_timing->vactive_hi << 8) |
  89. dvo_timing->vactive_lo;
  90. panel_fixed_mode->vsync_start = panel_fixed_mode->vdisplay +
  91. dvo_timing->vsync_off;
  92. panel_fixed_mode->vsync_end = panel_fixed_mode->vsync_start +
  93. dvo_timing->vsync_pulse_width;
  94. panel_fixed_mode->vtotal = panel_fixed_mode->vdisplay +
  95. ((dvo_timing->vblank_hi << 8) | dvo_timing->vblank_lo);
  96. panel_fixed_mode->clock = dvo_timing->clock * 10;
  97. panel_fixed_mode->type = DRM_MODE_TYPE_PREFERRED;
  98. drm_mode_set_name(panel_fixed_mode);
  99. dev_priv->vbt_mode = panel_fixed_mode;
  100. DRM_DEBUG("Found panel mode in BIOS VBT tables:\n");
  101. drm_mode_debug_printmodeline(panel_fixed_mode);
  102. return;
  103. }
  104. static void
  105. parse_general_features(struct drm_i915_private *dev_priv,
  106. struct bdb_header *bdb)
  107. {
  108. struct bdb_general_features *general;
  109. /* Set sensible defaults in case we can't find the general block */
  110. dev_priv->int_tv_support = 1;
  111. dev_priv->int_crt_support = 1;
  112. general = find_section(bdb, BDB_GENERAL_FEATURES);
  113. if (general) {
  114. dev_priv->int_tv_support = general->int_tv_support;
  115. dev_priv->int_crt_support = general->int_crt_support;
  116. }
  117. }
  118. /**
  119. * intel_init_bios - initialize VBIOS settings & find VBT
  120. * @dev: DRM device
  121. *
  122. * Loads the Video BIOS and checks that the VBT exists. Sets scratch registers
  123. * to appropriate values.
  124. *
  125. * VBT existence is a sanity check that is relied on by other i830_bios.c code.
  126. * Note that it would be better to use a BIOS call to get the VBT, as BIOSes may
  127. * feed an updated VBT back through that, compared to what we'll fetch using
  128. * this method of groping around in the BIOS data.
  129. *
  130. * Returns 0 on success, nonzero on failure.
  131. */
  132. bool
  133. intel_init_bios(struct drm_device *dev)
  134. {
  135. struct drm_i915_private *dev_priv = dev->dev_private;
  136. struct pci_dev *pdev = dev->pdev;
  137. struct vbt_header *vbt = NULL;
  138. struct bdb_header *bdb;
  139. u8 __iomem *bios;
  140. size_t size;
  141. int i;
  142. bios = pci_map_rom(pdev, &size);
  143. if (!bios)
  144. return -1;
  145. /* Scour memory looking for the VBT signature */
  146. for (i = 0; i + 4 < size; i++) {
  147. if (!memcmp(bios + i, "$VBT", 4)) {
  148. vbt = (struct vbt_header *)(bios + i);
  149. break;
  150. }
  151. }
  152. if (!vbt) {
  153. DRM_ERROR("VBT signature missing\n");
  154. pci_unmap_rom(pdev, bios);
  155. return -1;
  156. }
  157. bdb = (struct bdb_header *)(bios + i + vbt->bdb_offset);
  158. /* Grab useful general definitions */
  159. parse_general_features(dev_priv, bdb);
  160. parse_panel_data(dev_priv, bdb);
  161. pci_unmap_rom(pdev, bios);
  162. return 0;
  163. }