30 #include <linux/device.h>
32 #include <drm/i915_drm.h>
38 #include <linux/module.h>
44 "Use kernel modesetting [KMS] (0=DRM_I915_KMS from .config, "
45 "1=on, -1=force vga console preference [default])");
53 "Override lid status (0=autodetect [default], 1=lid open, "
59 "Enable powersavings, fbc, downclocking, etc. (default: true)");
64 "Use semaphores for inter-ring sync (default: -1 (use per-chip defaults))");
69 "Enable power-saving render C-state 6. "
70 "Different stages can be selected via bitmask values "
71 "(0 = disable; 1 = enable rc6; 2 = enable deep rc6; 4 = enable deepest rc6). "
72 "For example, 3 would enable rc6 and deep rc6, and 7 would enable everything. "
73 "default: -1 (use per-chip default)");
78 "Enable frame buffer compression for power savings "
79 "(default: -1 (use per-chip default))");
84 "Use panel (LVDS/eDP) downclocking for power savings "
90 "Specify LVDS channel mode "
91 "(0=probe BIOS [default], 1=single-channel, 2=dual-channel)");
96 "Use Spread Spectrum Clock with panels [LVDS/eDP] "
97 "(default: auto from VBT)");
102 "Override/Ignore selection of SDVO panel mode in the VBT "
103 "(-2=ignore, -1=auto [default], index in VBT BIOS table)");
112 "Periodically check GPU activity for detecting hangs. "
113 "WARNING: Disabling this can cause system wide hangs. "
119 "Enable PPGTT (default: true)");
124 "Enable preliminary hardware support. "
125 "Enable Haswell and ValleyView Support. "
128 static struct drm_driver
driver;
131 #define INTEL_VGA_DEVICE(id, info) { \
132 .class = PCI_BASE_CLASS_DISPLAY << 16, \
133 .class_mask = 0xff0000, \
136 .subvendor = PCI_ANY_ID, \
137 .subdevice = PCI_ANY_ID, \
138 .driver_data = (unsigned long) info }
141 .gen = 2, .is_mobile = 1, .cursor_needs_physical = 1,
142 .has_overlay = 1, .overlay_needs_physical = 1,
147 .has_overlay = 1, .overlay_needs_physical = 1,
151 .gen = 2, .is_i85x = 1, .is_mobile = 1,
152 .cursor_needs_physical = 1,
153 .has_overlay = 1, .overlay_needs_physical = 1,
158 .has_overlay = 1, .overlay_needs_physical = 1,
162 .gen = 3, .is_i915g = 1, .cursor_needs_physical = 1,
163 .has_overlay = 1, .overlay_needs_physical = 1,
166 .gen = 3, .is_mobile = 1,
167 .cursor_needs_physical = 1,
168 .has_overlay = 1, .overlay_needs_physical = 1,
172 .gen = 3, .has_hotplug = 1, .cursor_needs_physical = 1,
173 .has_overlay = 1, .overlay_needs_physical = 1,
176 .gen = 3, .is_i945gm = 1, .is_mobile = 1,
177 .has_hotplug = 1, .cursor_needs_physical = 1,
178 .has_overlay = 1, .overlay_needs_physical = 1,
183 .gen = 4, .is_broadwater = 1,
189 .gen = 4, .is_crestline = 1,
190 .is_mobile = 1, .has_fbc = 1, .has_hotplug = 1,
196 .gen = 3, .is_g33 = 1,
197 .need_gfx_hws = 1, .has_hotplug = 1,
202 .gen = 4, .is_g4x = 1, .need_gfx_hws = 1,
203 .has_pipe_cxsr = 1, .has_hotplug = 1,
208 .gen = 4, .is_g4x = 1,
209 .is_mobile = 1, .need_gfx_hws = 1, .has_fbc = 1,
210 .has_pipe_cxsr = 1, .has_hotplug = 1,
216 .gen = 3, .is_g33 = 1, .is_pineview = 1, .is_mobile = 1,
217 .need_gfx_hws = 1, .has_hotplug = 1,
223 .need_gfx_hws = 1, .has_hotplug = 1,
228 .gen = 5, .is_mobile = 1,
229 .need_gfx_hws = 1, .has_hotplug = 1,
236 .need_gfx_hws = 1, .has_hotplug = 1,
244 .gen = 6, .is_mobile = 1,
245 .need_gfx_hws = 1, .has_hotplug = 1,
254 .is_ivybridge = 1, .gen = 7,
255 .need_gfx_hws = 1, .has_hotplug = 1,
263 .is_ivybridge = 1, .gen = 7, .is_mobile = 1,
264 .need_gfx_hws = 1, .has_hotplug = 1,
273 .gen = 7, .is_mobile = 1,
274 .need_gfx_hws = 1, .has_hotplug = 1,
283 .need_gfx_hws = 1, .has_hotplug = 1,
291 .is_haswell = 1, .gen = 7,
292 .need_gfx_hws = 1, .has_hotplug = 1,
300 .is_haswell = 1, .gen = 7, .is_mobile = 1,
301 .need_gfx_hws = 1, .has_hotplug = 1,
395 #if defined(CONFIG_DRM_I915_KMS)
399 #define INTEL_PCH_DEVICE_ID_MASK 0xff00
400 #define INTEL_PCH_IBX_DEVICE_ID_TYPE 0x3b00
401 #define INTEL_PCH_CPT_DEVICE_ID_TYPE 0x1c00
402 #define INTEL_PCH_PPT_DEVICE_ID_TYPE 0x1e00
403 #define INTEL_PCH_LPT_DEVICE_ID_TYPE 0x8c00
425 DRM_DEBUG_KMS(
"Found Ibex Peak PCH\n");
429 DRM_DEBUG_KMS(
"Found CougarPoint PCH\n");
434 DRM_DEBUG_KMS(
"Found PatherPoint PCH\n");
438 DRM_DEBUG_KMS(
"Found LynxPoint PCH\n");
451 if (i915_semaphores >= 0)
452 return i915_semaphores;
454 #ifdef CONFIG_INTEL_IOMMU
472 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
476 "GEM idle failed, resume might fail\n");
487 intel_opregion_fini(dev);
503 if (!dev || !dev->dev_private) {
504 DRM_ERROR(
"dev: %p\n", dev);
505 DRM_ERROR(
"DRM not initialized, aborting suspend.\n");
513 if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
516 error = i915_drm_freeze(dev);
529 static int i915_drm_thaw(
struct drm_device *dev)
534 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
544 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
549 dev_priv->
mm.suspended = 0;
560 intel_opregion_init(dev);
574 if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
582 ret = i915_drm_thaw(dev);
590 static int i8xx_do_reset(
struct drm_device *dev)
620 static int i965_reset_complete(
struct drm_device *dev)
623 pci_read_config_byte(dev->pdev,
I965_GDRST, &gdrst);
627 static int i965_do_reset(
struct drm_device *dev)
637 pci_read_config_byte(dev->pdev,
I965_GDRST, &gdrst);
641 ret =
wait_for(i965_reset_complete(dev), 500);
646 pci_read_config_byte(dev->pdev,
I965_GDRST, &gdrst);
651 return wait_for(i965_reset_complete(dev), 500);
654 static int ironlake_do_reset(
struct drm_device *dev)
674 static int gen6_do_reset(
struct drm_device *dev)
678 unsigned long irqflags;
698 dev_priv->
gt.force_wake_get(dev_priv);
700 dev_priv->
gt.force_wake_put(dev_priv);
705 spin_unlock_irqrestore(&dev_priv->
gt_lock, irqflags);
717 ret = gen6_do_reset(dev);
720 ret = ironlake_do_reset(dev);
723 ret = i965_do_reset(dev);
726 ret = i8xx_do_reset(dev);
732 DRM_DEBUG(
"Simulated gpu hang, resetting stop_rings\n");
735 DRM_ERROR(
"Reset not implemented, but ignoring "
736 "error for simulated gpu hangs\n");
773 DRM_ERROR(
"GPU hanging too fast, declaring wedged!\n");
779 DRM_ERROR(
"Failed to reset chip.\n");
798 if (drm_core_check_feature(dev, DRIVER_MODESET) ||
799 !dev_priv->
mm.suspended) {
803 dev_priv->
mm.suspended = 0;
837 if(!i915_preliminary_hw_support) {
838 DRM_ERROR(
"Preliminary hardware support disabled\n");
854 if (intel_info->
gen != 3) {
856 ~(DRIVER_USE_AGP | DRIVER_REQUIRE_AGP);
858 DRM_ERROR(
"drm/i915 can't work without intel_agp module!\n");
862 return drm_get_pci_dev(pdev, ent, &
driver);
866 i915_pci_remove(
struct pci_dev *pdev)
868 struct drm_device *dev = pci_get_drvdata(pdev);
873 static int i915_pm_suspend(
struct device *dev)
876 struct drm_device *drm_dev = pci_get_drvdata(pdev);
879 if (!drm_dev || !drm_dev->dev_private) {
880 dev_err(dev,
"DRM not initialized, aborting suspend.\n");
884 if (drm_dev->switch_power_state == DRM_SWITCH_POWER_OFF)
887 error = i915_drm_freeze(drm_dev);
897 static int i915_pm_resume(
struct device *dev)
900 struct drm_device *drm_dev = pci_get_drvdata(pdev);
905 static int i915_pm_freeze(
struct device *dev)
908 struct drm_device *drm_dev = pci_get_drvdata(pdev);
910 if (!drm_dev || !drm_dev->dev_private) {
911 dev_err(dev,
"DRM not initialized, aborting suspend.\n");
915 return i915_drm_freeze(drm_dev);
918 static int i915_pm_thaw(
struct device *dev)
921 struct drm_device *drm_dev = pci_get_drvdata(pdev);
923 return i915_drm_thaw(drm_dev);
926 static int i915_pm_poweroff(
struct device *dev)
929 struct drm_device *drm_dev = pci_get_drvdata(pdev);
931 return i915_drm_freeze(drm_dev);
934 static const struct dev_pm_ops i915_pm_ops = {
935 .suspend = i915_pm_suspend,
936 .resume = i915_pm_resume,
937 .freeze = i915_pm_freeze,
938 .thaw = i915_pm_thaw,
939 .poweroff = i915_pm_poweroff,
940 .restore = i915_pm_resume,
943 static const struct vm_operations_struct i915_gem_vm_ops = {
959 .compat_ioctl = i915_compat_ioctl,
964 static struct drm_driver
driver = {
969 DRIVER_USE_AGP | DRIVER_REQUIRE_AGP |
970 DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_GEM | DRIVER_PRIME,
985 #if defined(CONFIG_DEBUG_FS)
991 .gem_vm_ops = &i915_gem_vm_ops,
1002 .fops = &i915_driver_fops,
1013 .id_table = pciidlist,
1014 .probe = i915_pci_probe,
1015 .remove = i915_pci_remove,
1016 .driver.pm = &i915_pm_ops,
1019 static int __init i915_init(
void)
1032 #if defined(CONFIG_DRM_I915_KMS)
1033 if (i915_modeset != 0)
1034 driver.driver_features |= DRIVER_MODESET;
1036 if (i915_modeset == 1)
1037 driver.driver_features |= DRIVER_MODESET;
1039 #ifdef CONFIG_VGA_CONSOLE
1041 driver.driver_features &= ~DRIVER_MODESET;
1044 if (!(driver.driver_features & DRIVER_MODESET))
1045 driver.get_vblank_timestamp =
NULL;
1050 static void __exit i915_exit(
void)
1063 #define NEEDS_FORCE_WAKE(dev_priv, reg) \
1064 ((HAS_FORCE_WAKE((dev_priv)->dev)) && \
1065 ((reg) < 0x40000) && \
1066 ((reg) != FORCEWAKE))
1068 static bool IS_DISPLAYREG(
u32 reg)
1112 if (reg >= 0x4000c &&
1116 if (reg >= 0x4f000 &&
1120 if (reg >= 0x4f100 &&
1146 #define __i915_read(x, y) \
1147 u##x i915_read##x(struct drm_i915_private *dev_priv, u32 reg) { \
1149 if (NEEDS_FORCE_WAKE((dev_priv), (reg))) { \
1150 unsigned long irqflags; \
1151 spin_lock_irqsave(&dev_priv->gt_lock, irqflags); \
1152 if (dev_priv->forcewake_count == 0) \
1153 dev_priv->gt.force_wake_get(dev_priv); \
1154 val = read##y(dev_priv->regs + reg); \
1155 if (dev_priv->forcewake_count == 0) \
1156 dev_priv->gt.force_wake_put(dev_priv); \
1157 spin_unlock_irqrestore(&dev_priv->gt_lock, irqflags); \
1158 } else if (IS_VALLEYVIEW(dev_priv->dev) && IS_DISPLAYREG(reg)) { \
1159 val = read##y(dev_priv->regs + reg + 0x180000); \
1161 val = read##y(dev_priv->regs + reg); \
1163 trace_i915_reg_rw(false, reg, val, sizeof(val)); \
1173 #define __i915_write(x, y) \
1174 void i915_write##x(struct drm_i915_private *dev_priv, u32 reg, u##x val) { \
1175 u32 __fifo_ret = 0; \
1176 trace_i915_reg_rw(true, reg, val, sizeof(val)); \
1177 if (NEEDS_FORCE_WAKE((dev_priv), (reg))) { \
1178 __fifo_ret = __gen6_gt_wait_for_fifo(dev_priv); \
1180 if (IS_VALLEYVIEW(dev_priv->dev) && IS_DISPLAYREG(reg)) { \
1181 write##y(val, dev_priv->regs + reg + 0x180000); \
1183 write##y(val, dev_priv->regs + reg); \
1185 if (unlikely(__fifo_ret)) { \
1186 gen6_gt_check_fifodbg(dev_priv); \
1188 if (IS_HASWELL(dev_priv->dev) && (I915_READ_NOTRACE(GEN7_ERR_INT) & ERR_INT_MMIO_UNCLAIMED)) { \
1189 DRM_ERROR("Unclaimed write to %x\n", reg); \
1190 writel(ERR_INT_MMIO_UNCLAIMED, dev_priv->regs + GEN7_ERR_INT); \
1199 static const struct register_whitelist {
1216 if (entry->offset == reg->
offset &&
1224 switch (entry->size) {