aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/DocBook/drm.tmpl16
-rw-r--r--drivers/gpu/drm/i915/Makefile1
-rw-r--r--drivers/gpu/drm/i915/i915_debugfs.c3
-rw-r--r--drivers/gpu/drm/i915/i915_dma.c9
-rw-r--r--drivers/gpu/drm/i915/i915_drv.c9
-rw-r--r--drivers/gpu/drm/i915/i915_drv.h25
-rw-r--r--drivers/gpu/drm/i915/i915_gem.c65
-rw-r--r--drivers/gpu/drm/i915/i915_gem_context.c71
-rw-r--r--drivers/gpu/drm/i915/i915_gem_evict.c11
-rw-r--r--drivers/gpu/drm/i915/i915_gem_execbuffer.c2
-rw-r--r--drivers/gpu/drm/i915/i915_irq.c54
-rw-r--r--drivers/gpu/drm/i915/i915_reg.h4
-rw-r--r--drivers/gpu/drm/i915/intel_atomic_plane.c152
-rw-r--r--drivers/gpu/drm/i915/intel_audio.c110
-rw-r--r--drivers/gpu/drm/i915/intel_bios.c20
-rw-r--r--drivers/gpu/drm/i915/intel_bios.h11
-rw-r--r--drivers/gpu/drm/i915/intel_display.c425
-rw-r--r--drivers/gpu/drm/i915/intel_dp.c4
-rw-r--r--drivers/gpu/drm/i915/intel_drv.h52
-rw-r--r--drivers/gpu/drm/i915/intel_lrc.c2
-rw-r--r--drivers/gpu/drm/i915/intel_pm.c9
-rw-r--r--drivers/gpu/drm/i915/intel_psr.c42
-rw-r--r--drivers/gpu/drm/i915/intel_ringbuffer.c18
-rw-r--r--drivers/gpu/drm/i915/intel_runtime_pm.c56
-rw-r--r--drivers/gpu/drm/i915/intel_sdvo.c3
-rw-r--r--drivers/gpu/drm/i915/intel_sprite.c203
-rw-r--r--include/drm/i915_component.h38
-rw-r--r--include/drm/i915_powerwell.h37
-rw-r--r--include/uapi/drm/i915_drm.h21
-rw-r--r--sound/pci/hda/hda_i915.c154
-rw-r--r--sound/pci/hda/hda_i915.h37
-rw-r--r--sound/pci/hda/hda_intel.c60
-rw-r--r--sound/pci/hda/hda_intel.h71
33 files changed, 1111 insertions, 684 deletions
diff --git a/Documentation/DocBook/drm.tmpl b/Documentation/DocBook/drm.tmpl
index 3b2571e84819..77d045557daf 100644
--- a/Documentation/DocBook/drm.tmpl
+++ b/Documentation/DocBook/drm.tmpl
@@ -4018,6 +4018,11 @@ int num_ioctls;</synopsis>
4018 </para> 4018 </para>
4019 </sect2> 4019 </sect2>
4020 <sect2> 4020 <sect2>
4021 <title>Atomic Plane Helpers</title>
4022!Pdrivers/gpu/drm/i915/intel_atomic_plane.c atomic plane helpers
4023!Idrivers/gpu/drm/i915/intel_atomic_plane.c
4024 </sect2>
4025 <sect2>
4021 <title>Output Probing</title> 4026 <title>Output Probing</title>
4022 <para> 4027 <para>
4023 This section covers output probing and related infrastructure like the 4028 This section covers output probing and related infrastructure like the
@@ -4159,6 +4164,17 @@ int num_ioctls;</synopsis>
4159!Pdrivers/gpu/drm/i915/i915_gem_gtt.c Global GTT views 4164!Pdrivers/gpu/drm/i915/i915_gem_gtt.c Global GTT views
4160!Idrivers/gpu/drm/i915/i915_gem_gtt.c 4165!Idrivers/gpu/drm/i915/i915_gem_gtt.c
4161 </sect2> 4166 </sect2>
4167 <sect2>
4168 <title>Buffer Object Eviction</title>
4169 <para>
4170 This section documents the interface function for evicting buffer
4171 objects to make space available in the virtual gpu address spaces.
4172 Note that this is mostly orthogonal to shrinking buffer objects
4173 caches, which has the goal to make main memory (shared with the gpu
4174 through the unified memory architecture) available.
4175 </para>
4176!Idrivers/gpu/drm/i915/i915_gem_evict.c
4177 </sect2>
4162 </sect1> 4178 </sect1>
4163 4179
4164 <sect1> 4180 <sect1>
diff --git a/drivers/gpu/drm/i915/Makefile b/drivers/gpu/drm/i915/Makefile
index 1849ffae61ae..16e3dc350274 100644
--- a/drivers/gpu/drm/i915/Makefile
+++ b/drivers/gpu/drm/i915/Makefile
@@ -66,6 +66,7 @@ i915-y += dvo_ch7017.o \
66 dvo_ns2501.o \ 66 dvo_ns2501.o \
67 dvo_sil164.o \ 67 dvo_sil164.o \
68 dvo_tfp410.o \ 68 dvo_tfp410.o \
69 intel_atomic_plane.o \
69 intel_crt.o \ 70 intel_crt.o \
70 intel_ddi.o \ 71 intel_ddi.o \
71 intel_dp.o \ 72 intel_dp.o \
diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
index e515aad47858..0d11cbe9f80c 100644
--- a/drivers/gpu/drm/i915/i915_debugfs.c
+++ b/drivers/gpu/drm/i915/i915_debugfs.c
@@ -2248,6 +2248,9 @@ static int i915_edp_psr_status(struct seq_file *m, void *data)
2248 } 2248 }
2249 seq_puts(m, "\n"); 2249 seq_puts(m, "\n");
2250 2250
2251 seq_printf(m, "Link standby: %s\n",
2252 yesno((bool)dev_priv->psr.link_standby));
2253
2251 /* CHV PSR has no kind of performance counter */ 2254 /* CHV PSR has no kind of performance counter */
2252 if (HAS_PSR(dev) && HAS_DDI(dev)) { 2255 if (HAS_PSR(dev) && HAS_DDI(dev)) {
2253 psrperf = I915_READ(EDP_PSR_PERF_CNT(dev)) & 2256 psrperf = I915_READ(EDP_PSR_PERF_CNT(dev)) &
diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
index 52730ed86385..2447de36de44 100644
--- a/drivers/gpu/drm/i915/i915_dma.c
+++ b/drivers/gpu/drm/i915/i915_dma.c
@@ -143,6 +143,9 @@ static int i915_getparam(struct drm_device *dev, void *data,
143 case I915_PARAM_HAS_COHERENT_PHYS_GTT: 143 case I915_PARAM_HAS_COHERENT_PHYS_GTT:
144 value = 1; 144 value = 1;
145 break; 145 break;
146 case I915_PARAM_MMAP_VERSION:
147 value = 1;
148 break;
146 default: 149 default:
147 DRM_DEBUG("Unknown parameter %d\n", param->param); 150 DRM_DEBUG("Unknown parameter %d\n", param->param);
148 return -EINVAL; 151 return -EINVAL;
@@ -830,6 +833,8 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags)
830 833
831 intel_runtime_pm_enable(dev_priv); 834 intel_runtime_pm_enable(dev_priv);
832 835
836 i915_audio_component_init(dev_priv);
837
833 return 0; 838 return 0;
834 839
835out_power_well: 840out_power_well:
@@ -870,6 +875,8 @@ int i915_driver_unload(struct drm_device *dev)
870 struct drm_i915_private *dev_priv = dev->dev_private; 875 struct drm_i915_private *dev_priv = dev->dev_private;
871 int ret; 876 int ret;
872 877
878 i915_audio_component_cleanup(dev_priv);
879
873 ret = i915_gem_suspend(dev); 880 ret = i915_gem_suspend(dev);
874 if (ret) { 881 if (ret) {
875 DRM_ERROR("failed to idle hardware: %d\n", ret); 882 DRM_ERROR("failed to idle hardware: %d\n", ret);
@@ -1063,6 +1070,8 @@ const struct drm_ioctl_desc i915_ioctls[] = {
1063 DRM_IOCTL_DEF_DRV(I915_REG_READ, i915_reg_read_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW), 1070 DRM_IOCTL_DEF_DRV(I915_REG_READ, i915_reg_read_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
1064 DRM_IOCTL_DEF_DRV(I915_GET_RESET_STATS, i915_get_reset_stats_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW), 1071 DRM_IOCTL_DEF_DRV(I915_GET_RESET_STATS, i915_get_reset_stats_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
1065 DRM_IOCTL_DEF_DRV(I915_GEM_USERPTR, i915_gem_userptr_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW), 1072 DRM_IOCTL_DEF_DRV(I915_GEM_USERPTR, i915_gem_userptr_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
1073 DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_GETPARAM, i915_gem_context_getparam_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
1074 DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_SETPARAM, i915_gem_context_setparam_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
1066}; 1075};
1067 1076
1068int i915_max_ioctl = ARRAY_SIZE(i915_ioctls); 1077int i915_max_ioctl = ARRAY_SIZE(i915_ioctls);
diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index 0763fa0791e3..308774f42079 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -942,8 +942,7 @@ static int i915_pm_suspend(struct device *dev)
942 942
943static int i915_pm_suspend_late(struct device *dev) 943static int i915_pm_suspend_late(struct device *dev)
944{ 944{
945 struct pci_dev *pdev = to_pci_dev(dev); 945 struct drm_device *drm_dev = dev_to_i915(dev)->dev;
946 struct drm_device *drm_dev = pci_get_drvdata(pdev);
947 946
948 /* 947 /*
949 * We have a suspedn ordering issue with the snd-hda driver also 948 * We have a suspedn ordering issue with the snd-hda driver also
@@ -962,8 +961,7 @@ static int i915_pm_suspend_late(struct device *dev)
962 961
963static int i915_pm_resume_early(struct device *dev) 962static int i915_pm_resume_early(struct device *dev)
964{ 963{
965 struct pci_dev *pdev = to_pci_dev(dev); 964 struct drm_device *drm_dev = dev_to_i915(dev)->dev;
966 struct drm_device *drm_dev = pci_get_drvdata(pdev);
967 965
968 if (drm_dev->switch_power_state == DRM_SWITCH_POWER_OFF) 966 if (drm_dev->switch_power_state == DRM_SWITCH_POWER_OFF)
969 return 0; 967 return 0;
@@ -973,8 +971,7 @@ static int i915_pm_resume_early(struct device *dev)
973 971
974static int i915_pm_resume(struct device *dev) 972static int i915_pm_resume(struct device *dev)
975{ 973{
976 struct pci_dev *pdev = to_pci_dev(dev); 974 struct drm_device *drm_dev = dev_to_i915(dev)->dev;
977 struct drm_device *drm_dev = pci_get_drvdata(pdev);
978 975
979 if (drm_dev->switch_power_state == DRM_SWITCH_POWER_OFF) 976 if (drm_dev->switch_power_state == DRM_SWITCH_POWER_OFF)
980 return 0; 977 return 0;
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 54f2a275dba6..ede48628bf85 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -55,7 +55,7 @@
55 55
56#define DRIVER_NAME "i915" 56#define DRIVER_NAME "i915"
57#define DRIVER_DESC "Intel Graphics" 57#define DRIVER_DESC "Intel Graphics"
58#define DRIVER_DATE "20141219" 58#define DRIVER_DATE "20150117"
59 59
60#undef WARN_ON 60#undef WARN_ON
61/* Many gcc seem to no see through this and fall over :( */ 61/* Many gcc seem to no see through this and fall over :( */
@@ -83,7 +83,7 @@
83 int __ret_warn_on = !!(condition); \ 83 int __ret_warn_on = !!(condition); \
84 if (unlikely(__ret_warn_on)) { \ 84 if (unlikely(__ret_warn_on)) { \
85 if (i915.verbose_state_checks) \ 85 if (i915.verbose_state_checks) \
86 __WARN_printf(format); \ 86 WARN(1, format); \
87 else \ 87 else \
88 DRM_ERROR(format); \ 88 DRM_ERROR(format); \
89 } \ 89 } \
@@ -94,7 +94,7 @@
94 int __ret_warn_on = !!(condition); \ 94 int __ret_warn_on = !!(condition); \
95 if (unlikely(__ret_warn_on)) { \ 95 if (unlikely(__ret_warn_on)) { \
96 if (i915.verbose_state_checks) \ 96 if (i915.verbose_state_checks) \
97 __WARN_printf("WARN_ON(" #condition ")\n"); \ 97 WARN(1, "WARN_ON(" #condition ")\n"); \
98 else \ 98 else \
99 DRM_ERROR("WARN_ON(" #condition ")\n"); \ 99 DRM_ERROR("WARN_ON(" #condition ")\n"); \
100 } \ 100 } \
@@ -678,6 +678,11 @@ struct i915_ctx_hang_stats {
678 /* Time when this context was last blamed for a GPU reset */ 678 /* Time when this context was last blamed for a GPU reset */
679 unsigned long guilty_ts; 679 unsigned long guilty_ts;
680 680
681 /* If the contexts causes a second GPU hang within this time,
682 * it is permanently banned from submitting any more work.
683 */
684 unsigned long ban_period_seconds;
685
681 /* This context is banned to submit more work */ 686 /* This context is banned to submit more work */
682 bool banned; 687 bool banned;
683}; 688};
@@ -784,6 +789,7 @@ struct i915_psr {
784 bool active; 789 bool active;
785 struct delayed_work work; 790 struct delayed_work work;
786 unsigned busy_frontbuffer_bits; 791 unsigned busy_frontbuffer_bits;
792 bool link_standby;
787}; 793};
788 794
789enum intel_pch { 795enum intel_pch {
@@ -1409,7 +1415,6 @@ struct intel_vbt_data {
1409 bool present; 1415 bool present;
1410 bool active_low_pwm; 1416 bool active_low_pwm;
1411 u8 min_brightness; /* min_brightness/255 of max */ 1417 u8 min_brightness; /* min_brightness/255 of max */
1412 u8 controller; /* brightness controller number */
1413 } backlight; 1418 } backlight;
1414 1419
1415 /* MIPI DSI */ 1420 /* MIPI DSI */
@@ -1768,6 +1773,9 @@ struct drm_i915_private {
1768 struct drm_property *broadcast_rgb_property; 1773 struct drm_property *broadcast_rgb_property;
1769 struct drm_property *force_audio_property; 1774 struct drm_property *force_audio_property;
1770 1775
1776 /* hda/i915 audio component */
1777 bool audio_component_registered;
1778
1771 uint32_t hw_context_size; 1779 uint32_t hw_context_size;
1772 struct list_head context_list; 1780 struct list_head context_list;
1773 1781
@@ -1853,6 +1861,11 @@ static inline struct drm_i915_private *to_i915(const struct drm_device *dev)
1853 return dev->dev_private; 1861 return dev->dev_private;
1854} 1862}
1855 1863
1864static inline struct drm_i915_private *dev_to_i915(struct device *dev)
1865{
1866 return to_i915(dev_get_drvdata(dev));
1867}
1868
1856/* Iterate over initialised rings */ 1869/* Iterate over initialised rings */
1857#define for_each_ring(ring__, dev_priv__, i__) \ 1870#define for_each_ring(ring__, dev_priv__, i__) \
1858 for ((i__) = 0; (i__) < I915_NUM_RINGS; (i__)++) \ 1871 for ((i__) = 0; (i__) < I915_NUM_RINGS; (i__)++) \
@@ -2892,6 +2905,10 @@ int i915_gem_context_create_ioctl(struct drm_device *dev, void *data,
2892 struct drm_file *file); 2905 struct drm_file *file);
2893int i915_gem_context_destroy_ioctl(struct drm_device *dev, void *data, 2906int i915_gem_context_destroy_ioctl(struct drm_device *dev, void *data,
2894 struct drm_file *file); 2907 struct drm_file *file);
2908int i915_gem_context_getparam_ioctl(struct drm_device *dev, void *data,
2909 struct drm_file *file_priv);
2910int i915_gem_context_setparam_ioctl(struct drm_device *dev, void *data,
2911 struct drm_file *file_priv);
2895 2912
2896/* i915_gem_evict.c */ 2913/* i915_gem_evict.c */
2897int __must_check i915_gem_evict_something(struct drm_device *dev, 2914int __must_check i915_gem_evict_something(struct drm_device *dev,
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 4e4d969d3b28..6c403654e33a 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -153,12 +153,6 @@ int i915_mutex_lock_interruptible(struct drm_device *dev)
153 return 0; 153 return 0;
154} 154}
155 155
156static inline bool
157i915_gem_object_is_inactive(struct drm_i915_gem_object *obj)
158{
159 return i915_gem_obj_bound_any(obj) && !obj->active;
160}
161
162int 156int
163i915_gem_get_aperture_ioctl(struct drm_device *dev, void *data, 157i915_gem_get_aperture_ioctl(struct drm_device *dev, void *data,
164 struct drm_file *file) 158 struct drm_file *file)
@@ -1487,18 +1481,10 @@ i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,
1487 if (ret) 1481 if (ret)
1488 goto unref; 1482 goto unref;
1489 1483
1490 if (read_domains & I915_GEM_DOMAIN_GTT) { 1484 if (read_domains & I915_GEM_DOMAIN_GTT)
1491 ret = i915_gem_object_set_to_gtt_domain(obj, write_domain != 0); 1485 ret = i915_gem_object_set_to_gtt_domain(obj, write_domain != 0);
1492 1486 else
1493 /* Silently promote "you're not bound, there was nothing to do"
1494 * to success, since the client was just asking us to
1495 * make sure everything was done.
1496 */
1497 if (ret == -EINVAL)
1498 ret = 0;
1499 } else {
1500 ret = i915_gem_object_set_to_cpu_domain(obj, write_domain != 0); 1487 ret = i915_gem_object_set_to_cpu_domain(obj, write_domain != 0);
1501 }
1502 1488
1503unref: 1489unref:
1504 drm_gem_object_unreference(&obj->base); 1490 drm_gem_object_unreference(&obj->base);
@@ -1563,6 +1549,12 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data,
1563 struct drm_gem_object *obj; 1549 struct drm_gem_object *obj;
1564 unsigned long addr; 1550 unsigned long addr;
1565 1551
1552 if (args->flags & ~(I915_MMAP_WC))
1553 return -EINVAL;
1554
1555 if (args->flags & I915_MMAP_WC && !cpu_has_pat)
1556 return -ENODEV;
1557
1566 obj = drm_gem_object_lookup(dev, file, args->handle); 1558 obj = drm_gem_object_lookup(dev, file, args->handle);
1567 if (obj == NULL) 1559 if (obj == NULL)
1568 return -ENOENT; 1560 return -ENOENT;
@@ -1578,6 +1570,19 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data,
1578 addr = vm_mmap(obj->filp, 0, args->size, 1570 addr = vm_mmap(obj->filp, 0, args->size,
1579 PROT_READ | PROT_WRITE, MAP_SHARED, 1571 PROT_READ | PROT_WRITE, MAP_SHARED,
1580 args->offset); 1572 args->offset);
1573 if (args->flags & I915_MMAP_WC) {
1574 struct mm_struct *mm = current->mm;
1575 struct vm_area_struct *vma;
1576
1577 down_write(&mm->mmap_sem);
1578 vma = find_vma(mm, addr);
1579 if (vma)
1580 vma->vm_page_prot =
1581 pgprot_writecombine(vm_get_page_prot(vma->vm_flags));
1582 else
1583 addr = -ENOMEM;
1584 up_write(&mm->mmap_sem);
1585 }
1581 drm_gem_object_unreference_unlocked(obj); 1586 drm_gem_object_unreference_unlocked(obj);
1582 if (IS_ERR((void *)addr)) 1587 if (IS_ERR((void *)addr))
1583 return addr; 1588 return addr;
@@ -2529,7 +2534,8 @@ static bool i915_context_is_banned(struct drm_i915_private *dev_priv,
2529 if (ctx->hang_stats.banned) 2534 if (ctx->hang_stats.banned)
2530 return true; 2535 return true;
2531 2536
2532 if (elapsed <= DRM_I915_CTX_BAN_PERIOD) { 2537 if (ctx->hang_stats.ban_period_seconds &&
2538 elapsed <= ctx->hang_stats.ban_period_seconds) {
2533 if (!i915_gem_context_is_default(ctx)) { 2539 if (!i915_gem_context_is_default(ctx)) {
2534 DRM_DEBUG("context hanging too fast, banning!\n"); 2540 DRM_DEBUG("context hanging too fast, banning!\n");
2535 return true; 2541 return true;
@@ -3698,15 +3704,10 @@ i915_gem_object_flush_cpu_write_domain(struct drm_i915_gem_object *obj,
3698int 3704int
3699i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj, bool write) 3705i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj, bool write)
3700{ 3706{
3701 struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
3702 struct i915_vma *vma = i915_gem_obj_to_ggtt(obj);
3703 uint32_t old_write_domain, old_read_domains; 3707 uint32_t old_write_domain, old_read_domains;
3708 struct i915_vma *vma;
3704 int ret; 3709 int ret;
3705 3710
3706 /* Not valid to be called on unbound objects. */
3707 if (vma == NULL)
3708 return -EINVAL;
3709
3710 if (obj->base.write_domain == I915_GEM_DOMAIN_GTT) 3711 if (obj->base.write_domain == I915_GEM_DOMAIN_GTT)
3711 return 0; 3712 return 0;
3712 3713
@@ -3715,6 +3716,19 @@ i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj, bool write)
3715 return ret; 3716 return ret;
3716 3717
3717 i915_gem_object_retire(obj); 3718 i915_gem_object_retire(obj);
3719
3720 /* Flush and acquire obj->pages so that we are coherent through
3721 * direct access in memory with previous cached writes through
3722 * shmemfs and that our cache domain tracking remains valid.
3723 * For example, if the obj->filp was moved to swap without us
3724 * being notified and releasing the pages, we would mistakenly
3725 * continue to assume that the obj remained out of the CPU cached
3726 * domain.
3727 */
3728 ret = i915_gem_object_get_pages(obj);
3729 if (ret)
3730 return ret;
3731
3718 i915_gem_object_flush_cpu_write_domain(obj, false); 3732 i915_gem_object_flush_cpu_write_domain(obj, false);
3719 3733
3720 /* Serialise direct access to this object with the barriers for 3734 /* Serialise direct access to this object with the barriers for
@@ -3746,9 +3760,10 @@ i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj, bool write)
3746 old_write_domain); 3760 old_write_domain);
3747 3761
3748 /* And bump the LRU for this access */ 3762 /* And bump the LRU for this access */
3749 if (i915_gem_object_is_inactive(obj)) 3763 vma = i915_gem_obj_to_ggtt(obj);
3764 if (vma && drm_mm_node_allocated(&vma->node) && !obj->active)
3750 list_move_tail(&vma->mm_list, 3765 list_move_tail(&vma->mm_list,
3751 &dev_priv->gtt.base.inactive_list); 3766 &to_i915(obj->base.dev)->gtt.base.inactive_list);
3752 3767
3753 return 0; 3768 return 0;
3754} 3769}
diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c
index 9b23fb1f5bf6..8603bf48d3ee 100644
--- a/drivers/gpu/drm/i915/i915_gem_context.c
+++ b/drivers/gpu/drm/i915/i915_gem_context.c
@@ -222,6 +222,8 @@ __create_hw_context(struct drm_device *dev,
222 * is no remap info, it will be a NOP. */ 222 * is no remap info, it will be a NOP. */
223 ctx->remap_slice = (1 << NUM_L3_SLICES(dev)) - 1; 223 ctx->remap_slice = (1 << NUM_L3_SLICES(dev)) - 1;
224 224
225 ctx->hang_stats.ban_period_seconds = DRM_I915_CTX_BAN_PERIOD;
226
225 return ctx; 227 return ctx;
226 228
227err_out: 229err_out:
@@ -792,3 +794,72 @@ int i915_gem_context_destroy_ioctl(struct drm_device *dev, void *data,
792 DRM_DEBUG_DRIVER("HW context %d destroyed\n", args->ctx_id); 794 DRM_DEBUG_DRIVER("HW context %d destroyed\n", args->ctx_id);
793 return 0; 795 return 0;
794} 796}
797
798int i915_gem_context_getparam_ioctl(struct drm_device *dev, void *data,
799 struct drm_file *file)
800{
801 struct drm_i915_file_private *file_priv = file->driver_priv;
802 struct drm_i915_gem_context_param *args = data;
803 struct intel_context *ctx;
804 int ret;
805
806 ret = i915_mutex_lock_interruptible(dev);
807 if (ret)
808 return ret;
809
810 ctx = i915_gem_context_get(file_priv, args->ctx_id);
811 if (IS_ERR(ctx)) {
812 mutex_unlock(&dev->struct_mutex);
813 return PTR_ERR(ctx);
814 }
815
816 args->size = 0;
817 switch (args->param) {
818 case I915_CONTEXT_PARAM_BAN_PERIOD:
819 args->value = ctx->hang_stats.ban_period_seconds;
820 break;
821 default:
822 ret = -EINVAL;
823 break;
824 }
825 mutex_unlock(&dev->struct_mutex);
826
827 return ret;
828}
829
830int i915_gem_context_setparam_ioctl(struct drm_device *dev, void *data,
831 struct drm_file *file)
832{
833 struct drm_i915_file_private *file_priv = file->driver_priv;
834 struct drm_i915_gem_context_param *args = data;
835 struct intel_context *ctx;
836 int ret;
837
838 ret = i915_mutex_lock_interruptible(dev);
839 if (ret)
840 return ret;
841
842 ctx = i915_gem_context_get(file_priv, args->ctx_id);
843 if (IS_ERR(ctx)) {
844 mutex_unlock(&dev->struct_mutex);
845 return PTR_ERR(ctx);
846 }
847
848 switch (args->param) {
849 case I915_CONTEXT_PARAM_BAN_PERIOD:
850 if (args->size)
851 ret = -EINVAL;
852 else if (args->value < ctx->hang_stats.ban_period_seconds &&
853 !capable(CAP_SYS_ADMIN))
854 ret = -EPERM;
855 else
856 ctx->hang_stats.ban_period_seconds = args->value;
857 break;
858 default:
859 ret = -EINVAL;
860 break;
861 }
862 mutex_unlock(&dev->struct_mutex);
863
864 return ret;
865}
diff --git a/drivers/gpu/drm/i915/i915_gem_evict.c b/drivers/gpu/drm/i915/i915_gem_evict.c
index 886ff2ee7a28..e3a49d94da3a 100644
--- a/drivers/gpu/drm/i915/i915_gem_evict.c
+++ b/drivers/gpu/drm/i915/i915_gem_evict.c
@@ -50,11 +50,12 @@ mark_free(struct i915_vma *vma, struct list_head *unwind)
50 * i915_gem_evict_something - Evict vmas to make room for binding a new one 50 * i915_gem_evict_something - Evict vmas to make room for binding a new one
51 * @dev: drm_device 51 * @dev: drm_device
52 * @vm: address space to evict from 52 * @vm: address space to evict from
53 * @size: size of the desired free space 53 * @min_size: size of the desired free space
54 * @alignment: alignment constraint of the desired free space 54 * @alignment: alignment constraint of the desired free space
55 * @cache_level: cache_level for the desired space 55 * @cache_level: cache_level for the desired space
56 * @mappable: whether the free space must be mappable 56 * @start: start (inclusive) of the range from which to evict objects
57 * @nonblocking: whether evicting active objects is allowed or not 57 * @end: end (exclusive) of the range from which to evict objects
58 * @flags: additional flags to control the eviction algorithm
58 * 59 *
59 * This function will try to evict vmas until a free space satisfying the 60 * This function will try to evict vmas until a free space satisfying the
60 * requirements is found. Callers must check first whether any such hole exists 61 * requirements is found. Callers must check first whether any such hole exists
@@ -196,7 +197,6 @@ found:
196 197
197/** 198/**
198 * i915_gem_evict_vm - Evict all idle vmas from a vm 199 * i915_gem_evict_vm - Evict all idle vmas from a vm
199 *
200 * @vm: Address space to cleanse 200 * @vm: Address space to cleanse
201 * @do_idle: Boolean directing whether to idle first. 201 * @do_idle: Boolean directing whether to idle first.
202 * 202 *
@@ -214,6 +214,7 @@ int i915_gem_evict_vm(struct i915_address_space *vm, bool do_idle)
214 struct i915_vma *vma, *next; 214 struct i915_vma *vma, *next;
215 int ret; 215 int ret;
216 216
217 WARN_ON(!mutex_is_locked(&vm->dev->struct_mutex));
217 trace_i915_gem_evict_vm(vm); 218 trace_i915_gem_evict_vm(vm);
218 219
219 if (do_idle) { 220 if (do_idle) {
@@ -222,6 +223,8 @@ int i915_gem_evict_vm(struct i915_address_space *vm, bool do_idle)
222 return ret; 223 return ret;
223 224
224 i915_gem_retire_requests(vm->dev); 225 i915_gem_retire_requests(vm->dev);
226
227 WARN_ON(!list_empty(&vm->active_list));
225 } 228 }
226 229
227 list_for_each_entry_safe(vma, next, &vm->inactive_list, mm_list) 230 list_for_each_entry_safe(vma, next, &vm->inactive_list, mm_list)
diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
index 1d6e0929ab83..e3ef17783765 100644
--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
@@ -1081,6 +1081,7 @@ i915_gem_execbuffer_parse(struct intel_engine_cs *ring,
1081{ 1081{
1082 struct drm_i915_private *dev_priv = to_i915(batch_obj->base.dev); 1082 struct drm_i915_private *dev_priv = to_i915(batch_obj->base.dev);
1083 struct drm_i915_gem_object *shadow_batch_obj; 1083 struct drm_i915_gem_object *shadow_batch_obj;
1084 bool need_reloc = false;
1084 int ret; 1085 int ret;
1085 1086
1086 shadow_batch_obj = i915_gem_batch_pool_get(&dev_priv->mm.batch_pool, 1087 shadow_batch_obj = i915_gem_batch_pool_get(&dev_priv->mm.batch_pool,
@@ -1106,6 +1107,7 @@ i915_gem_execbuffer_parse(struct intel_engine_cs *ring,
1106 vma->exec_entry = shadow_exec_entry; 1107 vma->exec_entry = shadow_exec_entry;
1107 vma->exec_entry->flags = __EXEC_OBJECT_PURGEABLE; 1108 vma->exec_entry->flags = __EXEC_OBJECT_PURGEABLE;
1108 drm_gem_object_reference(&shadow_batch_obj->base); 1109 drm_gem_object_reference(&shadow_batch_obj->base);
1110 i915_gem_execbuffer_reserve_vma(vma, ring, &need_reloc);
1109 list_add_tail(&vma->exec_list, &eb->vmas); 1111 list_add_tail(&vma->exec_list, &eb->vmas);
1110 1112
1111 shadow_batch_obj->base.pending_read_domains = 1113 shadow_batch_obj->base.pending_read_domains =
diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
index 818ab4e9dabc..8fe5a87705f7 100644
--- a/drivers/gpu/drm/i915/i915_irq.c
+++ b/drivers/gpu/drm/i915/i915_irq.c
@@ -45,7 +45,7 @@
45 * and related files, but that will be described in separate chapters. 45 * and related files, but that will be described in separate chapters.
46 */ 46 */
47 47
48static const u32 hpd_ibx[] = { 48static const u32 hpd_ibx[HPD_NUM_PINS] = {
49 [HPD_CRT] = SDE_CRT_HOTPLUG, 49 [HPD_CRT] = SDE_CRT_HOTPLUG,
50 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG, 50 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG,
51 [HPD_PORT_B] = SDE_PORTB_HOTPLUG, 51 [HPD_PORT_B] = SDE_PORTB_HOTPLUG,
@@ -53,7 +53,7 @@ static const u32 hpd_ibx[] = {
53 [HPD_PORT_D] = SDE_PORTD_HOTPLUG 53 [HPD_PORT_D] = SDE_PORTD_HOTPLUG
54}; 54};
55 55
56static const u32 hpd_cpt[] = { 56static const u32 hpd_cpt[HPD_NUM_PINS] = {
57 [HPD_CRT] = SDE_CRT_HOTPLUG_CPT, 57 [HPD_CRT] = SDE_CRT_HOTPLUG_CPT,
58 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG_CPT, 58 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG_CPT,
59 [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT, 59 [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT,
@@ -61,7 +61,7 @@ static const u32 hpd_cpt[] = {
61 [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT 61 [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT
62}; 62};
63 63
64static const u32 hpd_mask_i915[] = { 64static const u32 hpd_mask_i915[HPD_NUM_PINS] = {
65 [HPD_CRT] = CRT_HOTPLUG_INT_EN, 65 [HPD_CRT] = CRT_HOTPLUG_INT_EN,
66 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_EN, 66 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_EN,
67 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_EN, 67 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_EN,
@@ -70,7 +70,7 @@ static const u32 hpd_mask_i915[] = {
70 [HPD_PORT_D] = PORTD_HOTPLUG_INT_EN 70 [HPD_PORT_D] = PORTD_HOTPLUG_INT_EN
71}; 71};
72 72
73static const u32 hpd_status_g4x[] = { 73static const u32 hpd_status_g4x[HPD_NUM_PINS] = {
74 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS, 74 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
75 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_G4X, 75 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_G4X,
76 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_G4X, 76 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_G4X,
@@ -79,7 +79,7 @@ static const u32 hpd_status_g4x[] = {
79 [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS 79 [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS
80}; 80};
81 81
82static const u32 hpd_status_i915[] = { /* i915 and valleyview are the same */ 82static const u32 hpd_status_i915[HPD_NUM_PINS] = { /* i915 and valleyview are the same */
83 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS, 83 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
84 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_I915, 84 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_I915,
85 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_I915, 85 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_I915,
@@ -1522,7 +1522,7 @@ static inline enum port get_port_from_pin(enum hpd_pin pin)
1522static inline void intel_hpd_irq_handler(struct drm_device *dev, 1522static inline void intel_hpd_irq_handler(struct drm_device *dev,
1523 u32 hotplug_trigger, 1523 u32 hotplug_trigger,
1524 u32 dig_hotplug_reg, 1524 u32 dig_hotplug_reg,
1525 const u32 *hpd) 1525 const u32 hpd[HPD_NUM_PINS])
1526{ 1526{
1527 struct drm_i915_private *dev_priv = dev->dev_private; 1527 struct drm_i915_private *dev_priv = dev->dev_private;
1528 int i; 1528 int i;
@@ -4145,26 +4145,24 @@ static void i915_hpd_irq_setup(struct drm_device *dev)
4145 4145
4146 assert_spin_locked(&dev_priv->irq_lock); 4146 assert_spin_locked(&dev_priv->irq_lock);
4147 4147
4148 if (I915_HAS_HOTPLUG(dev)) { 4148 hotplug_en = I915_READ(PORT_HOTPLUG_EN);
4149 hotplug_en = I915_READ(PORT_HOTPLUG_EN); 4149 hotplug_en &= ~HOTPLUG_INT_EN_MASK;
4150 hotplug_en &= ~HOTPLUG_INT_EN_MASK; 4150 /* Note HDMI and DP share hotplug bits */
4151 /* Note HDMI and DP share hotplug bits */ 4151 /* enable bits are the same for all generations */
4152 /* enable bits are the same for all generations */ 4152 for_each_intel_encoder(dev, intel_encoder)
4153 for_each_intel_encoder(dev, intel_encoder) 4153 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
4154 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED) 4154 hotplug_en |= hpd_mask_i915[intel_encoder->hpd_pin];
4155 hotplug_en |= hpd_mask_i915[intel_encoder->hpd_pin]; 4155 /* Programming the CRT detection parameters tends
4156 /* Programming the CRT detection parameters tends 4156 to generate a spurious hotplug event about three
4157 to generate a spurious hotplug event about three 4157 seconds later. So just do it once.
4158 seconds later. So just do it once. 4158 */
4159 */ 4159 if (IS_G4X(dev))
4160 if (IS_G4X(dev)) 4160 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
4161 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64; 4161 hotplug_en &= ~CRT_HOTPLUG_VOLTAGE_COMPARE_MASK;
4162 hotplug_en &= ~CRT_HOTPLUG_VOLTAGE_COMPARE_MASK; 4162 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
4163 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50; 4163
4164 4164 /* Ignore TV since it's buggy */
4165 /* Ignore TV since it's buggy */ 4165 I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
4166 I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
4167 }
4168} 4166}
4169 4167
4170static irqreturn_t i965_irq_handler(int irq, void *arg) 4168static irqreturn_t i965_irq_handler(int irq, void *arg)
@@ -4428,14 +4426,14 @@ void intel_irq_init(struct drm_i915_private *dev_priv)
4428 dev->driver->irq_postinstall = i915_irq_postinstall; 4426 dev->driver->irq_postinstall = i915_irq_postinstall;
4429 dev->driver->irq_uninstall = i915_irq_uninstall; 4427 dev->driver->irq_uninstall = i915_irq_uninstall;
4430 dev->driver->irq_handler = i915_irq_handler; 4428 dev->driver->irq_handler = i915_irq_handler;
4431 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
4432 } else { 4429 } else {
4433 dev->driver->irq_preinstall = i965_irq_preinstall; 4430 dev->driver->irq_preinstall = i965_irq_preinstall;
4434 dev->driver->irq_postinstall = i965_irq_postinstall; 4431 dev->driver->irq_postinstall = i965_irq_postinstall;
4435 dev->driver->irq_uninstall = i965_irq_uninstall; 4432 dev->driver->irq_uninstall = i965_irq_uninstall;
4436 dev->driver->irq_handler = i965_irq_handler; 4433 dev->driver->irq_handler = i965_irq_handler;
4437 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
4438 } 4434 }
4435 if (I915_HAS_HOTPLUG(dev_priv))
4436 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
4439 dev->driver->enable_vblank = i915_enable_vblank; 4437 dev->driver->enable_vblank = i915_enable_vblank;
4440 dev->driver->disable_vblank = i915_disable_vblank; 4438 dev->driver->disable_vblank = i915_disable_vblank;
4441 } 4439 }
diff --git a/drivers/gpu/drm/i915/i915_reg.h b/drivers/gpu/drm/i915/i915_reg.h
index 40ca873a05ad..a39bb0385bcb 100644
--- a/drivers/gpu/drm/i915/i915_reg.h
+++ b/drivers/gpu/drm/i915/i915_reg.h
@@ -5202,6 +5202,9 @@ enum punit_power_well {
5202#define COMMON_SLICE_CHICKEN2 0x7014 5202#define COMMON_SLICE_CHICKEN2 0x7014
5203# define GEN8_CSC2_SBE_VUE_CACHE_CONSERVATIVE (1<<0) 5203# define GEN8_CSC2_SBE_VUE_CACHE_CONSERVATIVE (1<<0)
5204 5204
5205#define HIZ_CHICKEN 0x7018
5206# define CHV_HZ_8X8_MODE_IN_1X (1<<15)
5207
5205#define GEN7_L3SQCREG1 0xB010 5208#define GEN7_L3SQCREG1 0xB010
5206#define VLV_B0_WA_L3SQCREG1_VALUE 0x00D30000 5209#define VLV_B0_WA_L3SQCREG1_VALUE 0x00D30000
5207 5210
@@ -6167,6 +6170,7 @@ enum punit_power_well {
6167#define HSW_ROW_CHICKEN3_L3_GLOBAL_ATOMICS_DISABLE (1 << 6) 6170#define HSW_ROW_CHICKEN3_L3_GLOBAL_ATOMICS_DISABLE (1 << 6)
6168 6171
6169#define HALF_SLICE_CHICKEN3 0xe184 6172#define HALF_SLICE_CHICKEN3 0xe184
6173#define HSW_SAMPLE_C_PERFORMANCE (1<<9)
6170#define GEN8_CENTROID_PIXEL_OPT_DIS (1<<8) 6174#define GEN8_CENTROID_PIXEL_OPT_DIS (1<<8)
6171#define GEN8_SAMPLER_POWER_BYPASS_DIS (1<<1) 6175#define GEN8_SAMPLER_POWER_BYPASS_DIS (1<<1)
6172 6176
diff --git a/drivers/gpu/drm/i915/intel_atomic_plane.c b/drivers/gpu/drm/i915/intel_atomic_plane.c
new file mode 100644
index 000000000000..5488efef1837
--- /dev/null
+++ b/drivers/gpu/drm/i915/intel_atomic_plane.c
@@ -0,0 +1,152 @@
1/*
2 * Copyright © 2014 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
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24/**
25 * DOC: atomic plane helpers
26 *
27 * The functions here are used by the atomic plane helper functions to
28 * implement legacy plane updates (i.e., drm_plane->update_plane() and
29 * drm_plane->disable_plane()). This allows plane updates to use the
30 * atomic state infrastructure and perform plane updates as separate
31 * prepare/check/commit/cleanup steps.
32 */
33
34#include <drm/drmP.h>
35#include <drm/drm_atomic_helper.h>
36#include <drm/drm_plane_helper.h>
37#include "intel_drv.h"
38
39/**
40 * intel_plane_duplicate_state - duplicate plane state
41 * @plane: drm plane
42 *
43 * Allocates and returns a copy of the plane state (both common and
44 * Intel-specific) for the specified plane.
45 *
46 * Returns: The newly allocated plane state, or NULL or failure.
47 */
48struct drm_plane_state *
49intel_plane_duplicate_state(struct drm_plane *plane)
50{
51 struct intel_plane_state *state;
52
53 if (plane->state)
54 state = kmemdup(plane->state, sizeof(*state), GFP_KERNEL);
55 else
56 state = kzalloc(sizeof(*state), GFP_KERNEL);
57
58 if (!state)
59 return NULL;
60
61 if (state->base.fb)
62 drm_framebuffer_reference(state->base.fb);
63
64 return &state->base;
65}
66
67/**
68 * intel_plane_destroy_state - destroy plane state
69 * @plane: drm plane
70 * @state: state object to destroy
71 *
72 * Destroys the plane state (both common and Intel-specific) for the
73 * specified plane.
74 */
75void
76intel_plane_destroy_state(struct drm_plane *plane,
77 struct drm_plane_state *state)
78{
79 drm_atomic_helper_plane_destroy_state(plane, state);
80}
81
82static int intel_plane_atomic_check(struct drm_plane *plane,
83 struct drm_plane_state *state)
84{
85 struct drm_crtc *crtc = state->crtc;
86 struct intel_crtc *intel_crtc;
87 struct intel_plane *intel_plane = to_intel_plane(plane);
88 struct intel_plane_state *intel_state = to_intel_plane_state(state);
89
90 crtc = crtc ? crtc : plane->crtc;
91 intel_crtc = to_intel_crtc(crtc);
92
93 /*
94 * The original src/dest coordinates are stored in state->base, but
95 * we want to keep another copy internal to our driver that we can
96 * clip/modify ourselves.
97 */
98 intel_state->src.x1 = state->src_x;
99 intel_state->src.y1 = state->src_y;
100 intel_state->src.x2 = state->src_x + state->src_w;
101 intel_state->src.y2 = state->src_y + state->src_h;
102 intel_state->dst.x1 = state->crtc_x;
103 intel_state->dst.y1 = state->crtc_y;
104 intel_state->dst.x2 = state->crtc_x + state->crtc_w;
105 intel_state->dst.y2 = state->crtc_y + state->crtc_h;
106
107 /* Clip all planes to CRTC size, or 0x0 if CRTC is disabled */
108 intel_state->clip.x1 = 0;
109 intel_state->clip.y1 = 0;
110 intel_state->clip.x2 =
111 intel_crtc->active ? intel_crtc->config.pipe_src_w : 0;
112 intel_state->clip.y2 =
113 intel_crtc->active ? intel_crtc->config.pipe_src_h : 0;
114
115 /*
116 * Disabling a plane is always okay; we just need to update
117 * fb tracking in a special way since cleanup_fb() won't
118 * get called by the plane helpers.
119 */
120 if (state->fb == NULL && plane->state->fb != NULL) {
121 /*
122 * 'prepare' is never called when plane is being disabled, so
123 * we need to handle frontbuffer tracking as a special case
124 */
125 intel_crtc->atomic.disabled_planes |=
126 (1 << drm_plane_index(plane));
127 }
128
129 return intel_plane->check_plane(plane, intel_state);
130}
131
132static void intel_plane_atomic_update(struct drm_plane *plane,
133 struct drm_plane_state *old_state)
134{
135 struct intel_plane *intel_plane = to_intel_plane(plane);
136 struct intel_plane_state *intel_state =
137 to_intel_plane_state(plane->state);
138
139 /* Don't disable an already disabled plane */
140 if (!plane->state->fb && !old_state->fb)
141 return;
142
143 intel_plane->commit_plane(plane, intel_state);
144}
145
146const struct drm_plane_helper_funcs intel_plane_helper_funcs = {
147 .prepare_fb = intel_prepare_plane_fb,
148 .cleanup_fb = intel_cleanup_plane_fb,
149 .atomic_check = intel_plane_atomic_check,
150 .atomic_update = intel_plane_atomic_update,
151};
152
diff --git a/drivers/gpu/drm/i915/intel_audio.c b/drivers/gpu/drm/i915/intel_audio.c
index 2c7ed5cb29c0..ee41b882e71a 100644
--- a/drivers/gpu/drm/i915/intel_audio.c
+++ b/drivers/gpu/drm/i915/intel_audio.c
@@ -22,6 +22,9 @@
22 */ 22 */
23 23
24#include <linux/kernel.h> 24#include <linux/kernel.h>
25#include <linux/component.h>
26#include <drm/i915_component.h>
27#include "intel_drv.h"
25 28
26#include <drm/drmP.h> 29#include <drm/drmP.h>
27#include <drm/drm_edid.h> 30#include <drm/drm_edid.h>
@@ -461,3 +464,110 @@ void intel_init_audio(struct drm_device *dev)
461 dev_priv->display.audio_codec_disable = ilk_audio_codec_disable; 464 dev_priv->display.audio_codec_disable = ilk_audio_codec_disable;
462 } 465 }
463} 466}
467
468static void i915_audio_component_get_power(struct device *dev)
469{
470 intel_display_power_get(dev_to_i915(dev), POWER_DOMAIN_AUDIO);
471}
472
473static void i915_audio_component_put_power(struct device *dev)
474{
475 intel_display_power_put(dev_to_i915(dev), POWER_DOMAIN_AUDIO);
476}
477
478/* Get CDCLK in kHz */
479static int i915_audio_component_get_cdclk_freq(struct device *dev)
480{
481 struct drm_i915_private *dev_priv = dev_to_i915(dev);
482 int ret;
483
484 if (WARN_ON_ONCE(!HAS_DDI(dev_priv)))
485 return -ENODEV;
486
487 intel_display_power_get(dev_priv, POWER_DOMAIN_AUDIO);
488 ret = intel_ddi_get_cdclk_freq(dev_priv);
489 intel_display_power_put(dev_priv, POWER_DOMAIN_AUDIO);
490
491 return ret;
492}
493
494static const struct i915_audio_component_ops i915_audio_component_ops = {
495 .owner = THIS_MODULE,
496 .get_power = i915_audio_component_get_power,
497 .put_power = i915_audio_component_put_power,
498 .get_cdclk_freq = i915_audio_component_get_cdclk_freq,
499};
500
501static int i915_audio_component_bind(struct device *i915_dev,
502 struct device *hda_dev, void *data)
503{
504 struct i915_audio_component *acomp = data;
505
506 if (WARN_ON(acomp->ops || acomp->dev))
507 return -EEXIST;
508
509 acomp->ops = &i915_audio_component_ops;
510 acomp->dev = i915_dev;
511
512 return 0;
513}
514
515static void i915_audio_component_unbind(struct device *i915_dev,
516 struct device *hda_dev, void *data)
517{
518 struct i915_audio_component *acomp = data;
519
520 acomp->ops = NULL;
521 acomp->dev = NULL;
522}
523
524static const struct component_ops i915_audio_component_bind_ops = {
525 .bind = i915_audio_component_bind,
526 .unbind = i915_audio_component_unbind,
527};
528
529/**
530 * i915_audio_component_init - initialize and register the audio component
531 * @dev_priv: i915 device instance
532 *
533 * This will register with the component framework a child component which
534 * will bind dynamically to the snd_hda_intel driver's corresponding master
535 * component when the latter is registered. During binding the child
536 * initializes an instance of struct i915_audio_component which it receives
537 * from the master. The master can then start to use the interface defined by
538 * this struct. Each side can break the binding at any point by deregistering
539 * its own component after which each side's component unbind callback is
540 * called.
541 *
542 * We ignore any error during registration and continue with reduced
543 * functionality (i.e. without HDMI audio).
544 */
545void i915_audio_component_init(struct drm_i915_private *dev_priv)
546{
547 int ret;
548
549 ret = component_add(dev_priv->dev->dev, &i915_audio_component_bind_ops);
550 if (ret < 0) {
551 DRM_ERROR("failed to add audio component (%d)\n", ret);
552 /* continue with reduced functionality */
553 return;
554 }
555
556 dev_priv->audio_component_registered = true;
557}
558
559/**
560 * i915_audio_component_cleanup - deregister the audio component
561 * @dev_priv: i915 device instance
562 *
563 * Deregisters the audio component, breaking any existing binding to the
564 * corresponding snd_hda_intel driver's master component.
565 */
566void i915_audio_component_cleanup(struct drm_i915_private *dev_priv)
567{
568 if (!dev_priv->audio_component_registered)
569 return;
570
571 component_del(dev_priv->dev->dev, &i915_audio_component_bind_ops);
572 dev_priv->audio_component_registered = false;
573}
diff --git a/drivers/gpu/drm/i915/intel_bios.c b/drivers/gpu/drm/i915/intel_bios.c
index 65b1fbc5eb57..3f178258d9f9 100644
--- a/drivers/gpu/drm/i915/intel_bios.c
+++ b/drivers/gpu/drm/i915/intel_bios.c
@@ -314,7 +314,6 @@ parse_lfp_backlight(struct drm_i915_private *dev_priv, struct bdb_header *bdb)
314{ 314{
315 const struct bdb_lfp_backlight_data *backlight_data; 315 const struct bdb_lfp_backlight_data *backlight_data;
316 const struct bdb_lfp_backlight_data_entry *entry; 316 const struct bdb_lfp_backlight_data_entry *entry;
317 const struct bdb_lfp_backlight_control_data *bl_ctrl_data;
318 317
319 backlight_data = find_section(bdb, BDB_LVDS_BACKLIGHT); 318 backlight_data = find_section(bdb, BDB_LVDS_BACKLIGHT);
320 if (!backlight_data) 319 if (!backlight_data)
@@ -327,7 +326,6 @@ parse_lfp_backlight(struct drm_i915_private *dev_priv, struct bdb_header *bdb)
327 } 326 }
328 327
329 entry = &backlight_data->data[panel_type]; 328 entry = &backlight_data->data[panel_type];
330 bl_ctrl_data = &backlight_data->blc_ctl[panel_type];
331 329
332 dev_priv->vbt.backlight.present = entry->type == BDB_BACKLIGHT_TYPE_PWM; 330 dev_priv->vbt.backlight.present = entry->type == BDB_BACKLIGHT_TYPE_PWM;
333 if (!dev_priv->vbt.backlight.present) { 331 if (!dev_priv->vbt.backlight.present) {
@@ -339,30 +337,12 @@ parse_lfp_backlight(struct drm_i915_private *dev_priv, struct bdb_header *bdb)
339 dev_priv->vbt.backlight.pwm_freq_hz = entry->pwm_freq_hz; 337 dev_priv->vbt.backlight.pwm_freq_hz = entry->pwm_freq_hz;
340 dev_priv->vbt.backlight.active_low_pwm = entry->active_low_pwm; 338 dev_priv->vbt.backlight.active_low_pwm = entry->active_low_pwm;
341 dev_priv->vbt.backlight.min_brightness = entry->min_brightness; 339 dev_priv->vbt.backlight.min_brightness = entry->min_brightness;
342
343 dev_priv->vbt.backlight.controller = 0;
344 if (bdb->version >= 191) {
345 dev_priv->vbt.backlight.present =
346 bl_ctrl_data->pin == BLC_CONTROL_PIN_DDI;
347 if (!dev_priv->vbt.backlight.present) {
348 DRM_DEBUG_KMS("BL control pin is not DDI (pin %u)\n",
349 bl_ctrl_data->pin);
350 return;
351 }
352 if (bl_ctrl_data->controller == 1)
353 dev_priv->vbt.backlight.controller =
354 bl_ctrl_data->controller;
355 }
356
357 DRM_DEBUG_KMS("VBT backlight PWM modulation frequency %u Hz, " 340 DRM_DEBUG_KMS("VBT backlight PWM modulation frequency %u Hz, "
358 "active %s, min brightness %u, level %u\n", 341 "active %s, min brightness %u, level %u\n",
359 dev_priv->vbt.backlight.pwm_freq_hz, 342 dev_priv->vbt.backlight.pwm_freq_hz,
360 dev_priv->vbt.backlight.active_low_pwm ? "low" : "high", 343 dev_priv->vbt.backlight.active_low_pwm ? "low" : "high",
361 dev_priv->vbt.backlight.min_brightness, 344 dev_priv->vbt.backlight.min_brightness,
362 backlight_data->level[panel_type]); 345 backlight_data->level[panel_type]);
363
364 DRM_DEBUG_KMS("VBT BL controller %u\n",
365 dev_priv->vbt.backlight.controller);
366} 346}
367 347
368/* Try to find sdvo panel data */ 348/* Try to find sdvo panel data */
diff --git a/drivers/gpu/drm/i915/intel_bios.h b/drivers/gpu/drm/i915/intel_bios.h
index 9a7202e5caf4..a6a8710f665f 100644
--- a/drivers/gpu/drm/i915/intel_bios.h
+++ b/drivers/gpu/drm/i915/intel_bios.h
@@ -402,21 +402,10 @@ struct bdb_lfp_backlight_data_entry {
402 u8 obsolete3; 402 u8 obsolete3;
403} __packed; 403} __packed;
404 404
405#define BLC_CONTROL_PIN_PMIC 0
406#define BLC_CONTROL_PIN_LPSS_PWM 1
407#define BLC_CONTROL_PIN_DDI 2
408#define BLC_CONTROL_PIN_CABC 3
409
410struct bdb_lfp_backlight_control_data {
411 u8 controller:4;
412 u8 pin:4;
413} __packed;
414
415struct bdb_lfp_backlight_data { 405struct bdb_lfp_backlight_data {
416 u8 entry_size; 406 u8 entry_size;
417 struct bdb_lfp_backlight_data_entry data[16]; 407 struct bdb_lfp_backlight_data_entry data[16];
418 u8 level[16]; 408 u8 level[16];
419 struct bdb_lfp_backlight_control_data blc_ctl[16];
420} __packed; 409} __packed;
421 410
422struct aimdb_header { 411struct aimdb_header {
diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
index dc266e772340..91d8ada8fe6d 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -98,6 +98,8 @@ static void vlv_prepare_pll(struct intel_crtc *crtc,
98 const struct intel_crtc_config *pipe_config); 98 const struct intel_crtc_config *pipe_config);
99static void chv_prepare_pll(struct intel_crtc *crtc, 99static void chv_prepare_pll(struct intel_crtc *crtc,
100 const struct intel_crtc_config *pipe_config); 100 const struct intel_crtc_config *pipe_config);
101static void intel_begin_crtc_commit(struct drm_crtc *crtc);
102static void intel_finish_crtc_commit(struct drm_crtc *crtc);
101 103
102static struct intel_encoder *intel_find_encoder(struct intel_connector *connector, int pipe) 104static struct intel_encoder *intel_find_encoder(struct intel_connector *connector, int pipe)
103{ 105{
@@ -2165,7 +2167,8 @@ static void intel_disable_primary_hw_plane(struct drm_plane *plane,
2165 struct drm_i915_private *dev_priv = dev->dev_private; 2167 struct drm_i915_private *dev_priv = dev->dev_private;
2166 struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 2168 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
2167 2169
2168 assert_pipe_enabled(dev_priv, intel_crtc->pipe); 2170 if (WARN_ON(!intel_crtc->active))
2171 return;
2169 2172
2170 if (!intel_crtc->primary_enabled) 2173 if (!intel_crtc->primary_enabled)
2171 return; 2174 return;
@@ -4036,7 +4039,7 @@ static void ironlake_pfit_enable(struct intel_crtc *crtc)
4036 } 4039 }
4037} 4040}
4038 4041
4039static void intel_enable_planes(struct drm_crtc *crtc) 4042static void intel_enable_sprite_planes(struct drm_crtc *crtc)
4040{ 4043{
4041 struct drm_device *dev = crtc->dev; 4044 struct drm_device *dev = crtc->dev;
4042 enum pipe pipe = to_intel_crtc(crtc)->pipe; 4045 enum pipe pipe = to_intel_crtc(crtc)->pipe;
@@ -4050,7 +4053,7 @@ static void intel_enable_planes(struct drm_crtc *crtc)
4050 } 4053 }
4051} 4054}
4052 4055
4053static void intel_disable_planes(struct drm_crtc *crtc) 4056static void intel_disable_sprite_planes(struct drm_crtc *crtc)
4054{ 4057{
4055 struct drm_device *dev = crtc->dev; 4058 struct drm_device *dev = crtc->dev;
4056 enum pipe pipe = to_intel_crtc(crtc)->pipe; 4059 enum pipe pipe = to_intel_crtc(crtc)->pipe;
@@ -4194,7 +4197,7 @@ static void intel_crtc_enable_planes(struct drm_crtc *crtc)
4194 int pipe = intel_crtc->pipe; 4197 int pipe = intel_crtc->pipe;
4195 4198
4196 intel_enable_primary_hw_plane(crtc->primary, crtc); 4199 intel_enable_primary_hw_plane(crtc->primary, crtc);
4197 intel_enable_planes(crtc); 4200 intel_enable_sprite_planes(crtc);
4198 intel_crtc_update_cursor(crtc, true); 4201 intel_crtc_update_cursor(crtc, true);
4199 intel_crtc_dpms_overlay(intel_crtc, true); 4202 intel_crtc_dpms_overlay(intel_crtc, true);
4200 4203
@@ -4229,7 +4232,7 @@ static void intel_crtc_disable_planes(struct drm_crtc *crtc)
4229 4232
4230 intel_crtc_dpms_overlay(intel_crtc, false); 4233 intel_crtc_dpms_overlay(intel_crtc, false);
4231 intel_crtc_update_cursor(crtc, false); 4234 intel_crtc_update_cursor(crtc, false);
4232 intel_disable_planes(crtc); 4235 intel_disable_sprite_planes(crtc);
4233 intel_disable_primary_hw_plane(crtc->primary, crtc); 4236 intel_disable_primary_hw_plane(crtc->primary, crtc);
4234 4237
4235 /* 4238 /*
@@ -4301,15 +4304,15 @@ static void ironlake_crtc_enable(struct drm_crtc *crtc)
4301 if (intel_crtc->config.has_pch_encoder) 4304 if (intel_crtc->config.has_pch_encoder)
4302 ironlake_pch_enable(crtc); 4305 ironlake_pch_enable(crtc);
4303 4306
4307 assert_vblank_disabled(crtc);
4308 drm_crtc_vblank_on(crtc);
4309
4304 for_each_encoder_on_crtc(dev, crtc, encoder) 4310 for_each_encoder_on_crtc(dev, crtc, encoder)
4305 encoder->enable(encoder); 4311 encoder->enable(encoder);
4306 4312
4307 if (HAS_PCH_CPT(dev)) 4313 if (HAS_PCH_CPT(dev))
4308 cpt_verify_modeset(dev, intel_crtc->pipe); 4314 cpt_verify_modeset(dev, intel_crtc->pipe);
4309 4315
4310 assert_vblank_disabled(crtc);
4311 drm_crtc_vblank_on(crtc);
4312
4313 intel_crtc_enable_planes(crtc); 4316 intel_crtc_enable_planes(crtc);
4314} 4317}
4315 4318
@@ -4421,14 +4424,14 @@ static void haswell_crtc_enable(struct drm_crtc *crtc)
4421 if (intel_crtc->config.dp_encoder_is_mst) 4424 if (intel_crtc->config.dp_encoder_is_mst)
4422 intel_ddi_set_vc_payload_alloc(crtc, true); 4425 intel_ddi_set_vc_payload_alloc(crtc, true);
4423 4426
4427 assert_vblank_disabled(crtc);
4428 drm_crtc_vblank_on(crtc);
4429
4424 for_each_encoder_on_crtc(dev, crtc, encoder) { 4430 for_each_encoder_on_crtc(dev, crtc, encoder) {
4425 encoder->enable(encoder); 4431 encoder->enable(encoder);
4426 intel_opregion_notify_encoder(encoder, true); 4432 intel_opregion_notify_encoder(encoder, true);
4427 } 4433 }
4428 4434
4429 assert_vblank_disabled(crtc);
4430 drm_crtc_vblank_on(crtc);
4431
4432 /* If we change the relative order between pipe/planes enabling, we need 4435 /* If we change the relative order between pipe/planes enabling, we need
4433 * to change the workaround. */ 4436 * to change the workaround. */
4434 haswell_mode_set_planes_workaround(intel_crtc); 4437 haswell_mode_set_planes_workaround(intel_crtc);
@@ -4479,12 +4482,12 @@ static void ironlake_crtc_disable(struct drm_crtc *crtc)
4479 4482
4480 intel_crtc_disable_planes(crtc); 4483 intel_crtc_disable_planes(crtc);
4481 4484
4482 drm_crtc_vblank_off(crtc);
4483 assert_vblank_disabled(crtc);
4484
4485 for_each_encoder_on_crtc(dev, crtc, encoder) 4485 for_each_encoder_on_crtc(dev, crtc, encoder)
4486 encoder->disable(encoder); 4486 encoder->disable(encoder);
4487 4487
4488 drm_crtc_vblank_off(crtc);
4489 assert_vblank_disabled(crtc);
4490
4488 if (intel_crtc->config.has_pch_encoder) 4491 if (intel_crtc->config.has_pch_encoder)
4489 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); 4492 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
4490 4493
@@ -4543,14 +4546,14 @@ static void haswell_crtc_disable(struct drm_crtc *crtc)
4543 4546
4544 intel_crtc_disable_planes(crtc); 4547 intel_crtc_disable_planes(crtc);
4545 4548
4546 drm_crtc_vblank_off(crtc);
4547 assert_vblank_disabled(crtc);
4548
4549 for_each_encoder_on_crtc(dev, crtc, encoder) { 4549 for_each_encoder_on_crtc(dev, crtc, encoder) {
4550 intel_opregion_notify_encoder(encoder, false); 4550 intel_opregion_notify_encoder(encoder, false);
4551 encoder->disable(encoder); 4551 encoder->disable(encoder);
4552 } 4552 }
4553 4553
4554 drm_crtc_vblank_off(crtc);
4555 assert_vblank_disabled(crtc);
4556
4554 if (intel_crtc->config.has_pch_encoder) 4557 if (intel_crtc->config.has_pch_encoder)
4555 intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, 4558 intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A,
4556 false); 4559 false);
@@ -5018,12 +5021,12 @@ static void valleyview_crtc_enable(struct drm_crtc *crtc)
5018 intel_update_watermarks(crtc); 5021 intel_update_watermarks(crtc);
5019 intel_enable_pipe(intel_crtc); 5022 intel_enable_pipe(intel_crtc);
5020 5023
5021 for_each_encoder_on_crtc(dev, crtc, encoder)
5022 encoder->enable(encoder);
5023
5024 assert_vblank_disabled(crtc); 5024 assert_vblank_disabled(crtc);
5025 drm_crtc_vblank_on(crtc); 5025 drm_crtc_vblank_on(crtc);
5026 5026
5027 for_each_encoder_on_crtc(dev, crtc, encoder)
5028 encoder->enable(encoder);
5029
5027 intel_crtc_enable_planes(crtc); 5030 intel_crtc_enable_planes(crtc);
5028 5031
5029 /* Underruns don't raise interrupts, so check manually. */ 5032 /* Underruns don't raise interrupts, so check manually. */
@@ -5079,12 +5082,12 @@ static void i9xx_crtc_enable(struct drm_crtc *crtc)
5079 intel_update_watermarks(crtc); 5082 intel_update_watermarks(crtc);
5080 intel_enable_pipe(intel_crtc); 5083 intel_enable_pipe(intel_crtc);
5081 5084
5082 for_each_encoder_on_crtc(dev, crtc, encoder)
5083 encoder->enable(encoder);
5084
5085 assert_vblank_disabled(crtc); 5085 assert_vblank_disabled(crtc);
5086 drm_crtc_vblank_on(crtc); 5086 drm_crtc_vblank_on(crtc);
5087 5087
5088 for_each_encoder_on_crtc(dev, crtc, encoder)
5089 encoder->enable(encoder);
5090
5088 intel_crtc_enable_planes(crtc); 5091 intel_crtc_enable_planes(crtc);
5089 5092
5090 /* 5093 /*
@@ -5156,12 +5159,12 @@ static void i9xx_crtc_disable(struct drm_crtc *crtc)
5156 */ 5159 */
5157 intel_wait_for_vblank(dev, pipe); 5160 intel_wait_for_vblank(dev, pipe);
5158 5161
5159 drm_crtc_vblank_off(crtc);
5160 assert_vblank_disabled(crtc);
5161
5162 for_each_encoder_on_crtc(dev, crtc, encoder) 5162 for_each_encoder_on_crtc(dev, crtc, encoder)
5163 encoder->disable(encoder); 5163 encoder->disable(encoder);
5164 5164
5165 drm_crtc_vblank_off(crtc);
5166 assert_vblank_disabled(crtc);
5167
5165 intel_disable_pipe(intel_crtc); 5168 intel_disable_pipe(intel_crtc);
5166 5169
5167 i9xx_pfit_disable(intel_crtc); 5170 i9xx_pfit_disable(intel_crtc);
@@ -9613,7 +9616,6 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
9613 struct drm_i915_gem_object *obj = intel_fb_obj(fb); 9616 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
9614 struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 9617 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
9615 struct drm_plane *primary = crtc->primary; 9618 struct drm_plane *primary = crtc->primary;
9616 struct intel_plane *intel_plane = to_intel_plane(primary);
9617 enum pipe pipe = intel_crtc->pipe; 9619 enum pipe pipe = intel_crtc->pipe;
9618 struct intel_unpin_work *work; 9620 struct intel_unpin_work *work;
9619 struct intel_engine_cs *ring; 9621 struct intel_engine_cs *ring;
@@ -9772,15 +9774,7 @@ free_work:
9772 9774
9773 if (ret == -EIO) { 9775 if (ret == -EIO) {
9774out_hang: 9776out_hang:
9775 ret = primary->funcs->update_plane(primary, crtc, fb, 9777 ret = intel_plane_restore(primary);
9776 intel_plane->crtc_x,
9777 intel_plane->crtc_y,
9778 intel_plane->crtc_h,
9779 intel_plane->crtc_w,
9780 intel_plane->src_x,
9781 intel_plane->src_y,
9782 intel_plane->src_h,
9783 intel_plane->src_w);
9784 if (ret == 0 && event) { 9778 if (ret == 0 && event) {
9785 spin_lock_irq(&dev->event_lock); 9779 spin_lock_irq(&dev->event_lock);
9786 drm_send_vblank_event(dev, pipe, event); 9780 drm_send_vblank_event(dev, pipe, event);
@@ -9793,6 +9787,8 @@ out_hang:
9793static struct drm_crtc_helper_funcs intel_helper_funcs = { 9787static struct drm_crtc_helper_funcs intel_helper_funcs = {
9794 .mode_set_base_atomic = intel_pipe_set_base_atomic, 9788 .mode_set_base_atomic = intel_pipe_set_base_atomic,
9795 .load_lut = intel_crtc_load_lut, 9789 .load_lut = intel_crtc_load_lut,
9790 .atomic_begin = intel_begin_crtc_commit,
9791 .atomic_flush = intel_finish_crtc_commit,
9796}; 9792};
9797 9793
9798/** 9794/**
@@ -11673,7 +11669,7 @@ intel_prepare_plane_fb(struct drm_plane *plane,
11673 unsigned frontbuffer_bits = 0; 11669 unsigned frontbuffer_bits = 0;
11674 int ret = 0; 11670 int ret = 0;
11675 11671
11676 if (WARN_ON(fb == plane->fb || !obj)) 11672 if (!obj)
11677 return 0; 11673 return 0;
11678 11674
11679 switch (plane->type) { 11675 switch (plane->type) {
@@ -11737,13 +11733,20 @@ static int
11737intel_check_primary_plane(struct drm_plane *plane, 11733intel_check_primary_plane(struct drm_plane *plane,
11738 struct intel_plane_state *state) 11734 struct intel_plane_state *state)
11739{ 11735{
11736 struct drm_device *dev = plane->dev;
11737 struct drm_i915_private *dev_priv = dev->dev_private;
11740 struct drm_crtc *crtc = state->base.crtc; 11738 struct drm_crtc *crtc = state->base.crtc;
11739 struct intel_crtc *intel_crtc;
11740 struct intel_plane *intel_plane = to_intel_plane(plane);
11741 struct drm_framebuffer *fb = state->base.fb; 11741 struct drm_framebuffer *fb = state->base.fb;
11742 struct drm_rect *dest = &state->dst; 11742 struct drm_rect *dest = &state->dst;
11743 struct drm_rect *src = &state->src; 11743 struct drm_rect *src = &state->src;
11744 const struct drm_rect *clip = &state->clip; 11744 const struct drm_rect *clip = &state->clip;
11745 int ret; 11745 int ret;
11746 11746
11747 crtc = crtc ? crtc : plane->crtc;
11748 intel_crtc = to_intel_crtc(crtc);
11749
11747 ret = drm_plane_helper_check_update(plane, crtc, fb, 11750 ret = drm_plane_helper_check_update(plane, crtc, fb,
11748 src, dest, clip, 11751 src, dest, clip,
11749 DRM_PLANE_HELPER_NO_SCALING, 11752 DRM_PLANE_HELPER_NO_SCALING,
@@ -11752,10 +11755,40 @@ intel_check_primary_plane(struct drm_plane *plane,
11752 if (ret) 11755 if (ret)
11753 return ret; 11756 return ret;
11754 11757
11755 intel_crtc_wait_for_pending_flips(crtc); 11758 if (intel_crtc->active) {
11756 if (intel_crtc_has_pending_flip(crtc)) { 11759 intel_crtc->atomic.wait_for_flips = true;
11757 DRM_ERROR("pipe is still busy with an old pageflip\n"); 11760
11758 return -EBUSY; 11761 /*
11762 * FBC does not work on some platforms for rotated
11763 * planes, so disable it when rotation is not 0 and
11764 * update it when rotation is set back to 0.
11765 *
11766 * FIXME: This is redundant with the fbc update done in
11767 * the primary plane enable function except that that
11768 * one is done too late. We eventually need to unify
11769 * this.
11770 */
11771 if (intel_crtc->primary_enabled &&
11772 INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev) &&
11773 dev_priv->fbc.plane == intel_crtc->plane &&
11774 intel_plane->rotation != BIT(DRM_ROTATE_0)) {
11775 intel_crtc->atomic.disable_fbc = true;
11776 }
11777
11778 if (state->visible) {
11779 /*
11780 * BDW signals flip done immediately if the plane
11781 * is disabled, even if the plane enable is already
11782 * armed to occur at the next vblank :(
11783 */
11784 if (IS_BROADWELL(dev) && !intel_crtc->primary_enabled)
11785 intel_crtc->atomic.wait_vblank = true;
11786 }
11787
11788 intel_crtc->atomic.fb_bits |=
11789 INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe);
11790
11791 intel_crtc->atomic.update_fbc = true;
11759 } 11792 }
11760 11793
11761 return 0; 11794 return 0;
@@ -11769,58 +11802,22 @@ intel_commit_primary_plane(struct drm_plane *plane,
11769 struct drm_framebuffer *fb = state->base.fb; 11802 struct drm_framebuffer *fb = state->base.fb;
11770 struct drm_device *dev = plane->dev; 11803 struct drm_device *dev = plane->dev;
11771 struct drm_i915_private *dev_priv = dev->dev_private; 11804 struct drm_i915_private *dev_priv = dev->dev_private;
11772 struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 11805 struct intel_crtc *intel_crtc;
11773 struct drm_i915_gem_object *obj = intel_fb_obj(fb); 11806 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
11774 struct intel_plane *intel_plane = to_intel_plane(plane); 11807 struct intel_plane *intel_plane = to_intel_plane(plane);
11775 struct drm_rect *src = &state->src; 11808 struct drm_rect *src = &state->src;
11776 enum pipe pipe = intel_plane->pipe;
11777 11809
11778 if (!fb) { 11810 crtc = crtc ? crtc : plane->crtc;
11779 /* 11811 intel_crtc = to_intel_crtc(crtc);
11780 * 'prepare' is never called when plane is being disabled, so
11781 * we need to handle frontbuffer tracking here
11782 */
11783 mutex_lock(&dev->struct_mutex);
11784 i915_gem_track_fb(intel_fb_obj(plane->fb), NULL,
11785 INTEL_FRONTBUFFER_PRIMARY(pipe));
11786 mutex_unlock(&dev->struct_mutex);
11787 }
11788 11812
11789 plane->fb = fb; 11813 plane->fb = fb;
11790 crtc->x = src->x1 >> 16; 11814 crtc->x = src->x1 >> 16;
11791 crtc->y = src->y1 >> 16; 11815 crtc->y = src->y1 >> 16;
11792 11816
11793 intel_plane->crtc_x = state->orig_dst.x1;
11794 intel_plane->crtc_y = state->orig_dst.y1;
11795 intel_plane->crtc_w = drm_rect_width(&state->orig_dst);
11796 intel_plane->crtc_h = drm_rect_height(&state->orig_dst);
11797 intel_plane->src_x = state->orig_src.x1;
11798 intel_plane->src_y = state->orig_src.y1;
11799 intel_plane->src_w = drm_rect_width(&state->orig_src);
11800 intel_plane->src_h = drm_rect_height(&state->orig_src);
11801 intel_plane->obj = obj; 11817 intel_plane->obj = obj;
11802 11818
11803 if (intel_crtc->active) { 11819 if (intel_crtc->active) {
11804 /*
11805 * FBC does not work on some platforms for rotated
11806 * planes, so disable it when rotation is not 0 and
11807 * update it when rotation is set back to 0.
11808 *
11809 * FIXME: This is redundant with the fbc update done in
11810 * the primary plane enable function except that that
11811 * one is done too late. We eventually need to unify
11812 * this.
11813 */
11814 if (intel_crtc->primary_enabled &&
11815 INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev) &&
11816 dev_priv->fbc.plane == intel_crtc->plane &&
11817 intel_plane->rotation != BIT(DRM_ROTATE_0)) {
11818 intel_fbc_disable(dev);
11819 }
11820
11821 if (state->visible) { 11820 if (state->visible) {
11822 bool was_enabled = intel_crtc->primary_enabled;
11823
11824 /* FIXME: kill this fastboot hack */ 11821 /* FIXME: kill this fastboot hack */
11825 intel_update_pipe_size(intel_crtc); 11822 intel_update_pipe_size(intel_crtc);
11826 11823
@@ -11828,14 +11825,6 @@ intel_commit_primary_plane(struct drm_plane *plane,
11828 11825
11829 dev_priv->display.update_primary_plane(crtc, plane->fb, 11826 dev_priv->display.update_primary_plane(crtc, plane->fb,
11830 crtc->x, crtc->y); 11827 crtc->x, crtc->y);
11831
11832 /*
11833 * BDW signals flip done immediately if the plane
11834 * is disabled, even if the plane enable is already
11835 * armed to occur at the next vblank :(
11836 */
11837 if (IS_BROADWELL(dev) && !was_enabled)
11838 intel_wait_for_vblank(dev, intel_crtc->pipe);
11839 } else { 11828 } else {
11840 /* 11829 /*
11841 * If clipping results in a non-visible primary plane, 11830 * If clipping results in a non-visible primary plane,
@@ -11846,110 +11835,121 @@ intel_commit_primary_plane(struct drm_plane *plane,
11846 */ 11835 */
11847 intel_disable_primary_hw_plane(plane, crtc); 11836 intel_disable_primary_hw_plane(plane, crtc);
11848 } 11837 }
11849
11850 intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_PRIMARY(pipe));
11851
11852 mutex_lock(&dev->struct_mutex);
11853 intel_fbc_update(dev);
11854 mutex_unlock(&dev->struct_mutex);
11855 } 11838 }
11856} 11839}
11857 11840
11858int 11841static void intel_begin_crtc_commit(struct drm_crtc *crtc)
11859intel_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
11860 struct drm_framebuffer *fb, int crtc_x, int crtc_y,
11861 unsigned int crtc_w, unsigned int crtc_h,
11862 uint32_t src_x, uint32_t src_y,
11863 uint32_t src_w, uint32_t src_h)
11864{ 11842{
11865 struct drm_device *dev = plane->dev; 11843 struct drm_device *dev = crtc->dev;
11866 struct drm_i915_private *dev_priv = dev->dev_private; 11844 struct drm_i915_private *dev_priv = dev->dev_private;
11867 struct drm_framebuffer *old_fb = plane->fb;
11868 struct intel_plane_state state;
11869 struct intel_plane *intel_plane = to_intel_plane(plane);
11870 struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 11845 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11871 int ret; 11846 struct intel_plane *intel_plane;
11847 struct drm_plane *p;
11848 unsigned fb_bits = 0;
11849
11850 /* Track fb's for any planes being disabled */
11851 list_for_each_entry(p, &dev->mode_config.plane_list, head) {
11852 intel_plane = to_intel_plane(p);
11853
11854 if (intel_crtc->atomic.disabled_planes &
11855 (1 << drm_plane_index(p))) {
11856 switch (p->type) {
11857 case DRM_PLANE_TYPE_PRIMARY:
11858 fb_bits = INTEL_FRONTBUFFER_PRIMARY(intel_plane->pipe);
11859 break;
11860 case DRM_PLANE_TYPE_CURSOR:
11861 fb_bits = INTEL_FRONTBUFFER_CURSOR(intel_plane->pipe);
11862 break;
11863 case DRM_PLANE_TYPE_OVERLAY:
11864 fb_bits = INTEL_FRONTBUFFER_SPRITE(intel_plane->pipe);
11865 break;
11866 }
11872 11867
11873 state.base.crtc = crtc ? crtc : plane->crtc; 11868 mutex_lock(&dev->struct_mutex);
11874 state.base.fb = fb; 11869 i915_gem_track_fb(intel_fb_obj(p->fb), NULL, fb_bits);
11870 mutex_unlock(&dev->struct_mutex);
11871 }
11872 }
11875 11873
11876 /* sample coordinates in 16.16 fixed point */ 11874 if (intel_crtc->atomic.wait_for_flips)
11877 state.src.x1 = src_x; 11875 intel_crtc_wait_for_pending_flips(crtc);
11878 state.src.x2 = src_x + src_w;
11879 state.src.y1 = src_y;
11880 state.src.y2 = src_y + src_h;
11881 11876
11882 /* integer pixels */ 11877 if (intel_crtc->atomic.disable_fbc)
11883 state.dst.x1 = crtc_x; 11878 intel_fbc_disable(dev);
11884 state.dst.x2 = crtc_x + crtc_w;
11885 state.dst.y1 = crtc_y;
11886 state.dst.y2 = crtc_y + crtc_h;
11887 11879
11888 state.clip.x1 = 0; 11880 if (intel_crtc->atomic.pre_disable_primary)
11889 state.clip.y1 = 0; 11881 intel_pre_disable_primary(crtc);
11890 state.clip.x2 = intel_crtc->active ? intel_crtc->config.pipe_src_w : 0;
11891 state.clip.y2 = intel_crtc->active ? intel_crtc->config.pipe_src_h : 0;
11892 11882
11893 state.orig_src = state.src; 11883 if (intel_crtc->atomic.update_wm)
11894 state.orig_dst = state.dst; 11884 intel_update_watermarks(crtc);
11895 11885
11896 ret = intel_plane->check_plane(plane, &state); 11886 intel_runtime_pm_get(dev_priv);
11897 if (ret)
11898 return ret;
11899 11887
11900 if (fb != old_fb && fb) { 11888 /* Perform vblank evasion around commit operation */
11901 ret = intel_prepare_plane_fb(plane, fb); 11889 if (intel_crtc->active)
11902 if (ret) 11890 intel_crtc->atomic.evade =
11903 return ret; 11891 intel_pipe_update_start(intel_crtc,
11904 } 11892 &intel_crtc->atomic.start_vbl_count);
11893}
11894
11895static void intel_finish_crtc_commit(struct drm_crtc *crtc)
11896{
11897 struct drm_device *dev = crtc->dev;
11898 struct drm_i915_private *dev_priv = dev->dev_private;
11899 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11900 struct drm_plane *p;
11901
11902 if (intel_crtc->atomic.evade)
11903 intel_pipe_update_end(intel_crtc,
11904 intel_crtc->atomic.start_vbl_count);
11905 11905
11906 intel_runtime_pm_get(dev_priv);
11907 intel_plane->commit_plane(plane, &state);
11908 intel_runtime_pm_put(dev_priv); 11906 intel_runtime_pm_put(dev_priv);
11909 11907
11910 if (fb != old_fb && old_fb) { 11908 if (intel_crtc->atomic.wait_vblank)
11911 if (intel_crtc->active) 11909 intel_wait_for_vblank(dev, intel_crtc->pipe);
11912 intel_wait_for_vblank(dev, intel_crtc->pipe); 11910
11913 intel_cleanup_plane_fb(plane, old_fb); 11911 intel_frontbuffer_flip(dev, intel_crtc->atomic.fb_bits);
11912
11913 if (intel_crtc->atomic.update_fbc) {
11914 mutex_lock(&dev->struct_mutex);
11915 intel_fbc_update(dev);
11916 mutex_unlock(&dev->struct_mutex);
11914 } 11917 }
11915 11918
11916 plane->fb = fb; 11919 if (intel_crtc->atomic.post_enable_primary)
11920 intel_post_enable_primary(crtc);
11917 11921
11918 return 0; 11922 drm_for_each_legacy_plane(p, &dev->mode_config.plane_list)
11923 if (intel_crtc->atomic.update_sprite_watermarks & drm_plane_index(p))
11924 intel_update_sprite_watermarks(p, crtc, 0, 0, 0,
11925 false, false);
11926
11927 memset(&intel_crtc->atomic, 0, sizeof(intel_crtc->atomic));
11919} 11928}
11920 11929
11921/** 11930/**
11922 * intel_disable_plane - disable a plane 11931 * intel_plane_destroy - destroy a plane
11923 * @plane: plane to disable 11932 * @plane: plane to destroy
11924 * 11933 *
11925 * General disable handler for all plane types. 11934 * Common destruction function for all types of planes (primary, cursor,
11935 * sprite).
11926 */ 11936 */
11927int 11937void intel_plane_destroy(struct drm_plane *plane)
11928intel_disable_plane(struct drm_plane *plane)
11929{
11930 if (!plane->fb)
11931 return 0;
11932
11933 if (WARN_ON(!plane->crtc))
11934 return -EINVAL;
11935
11936 return plane->funcs->update_plane(plane, plane->crtc, NULL,
11937 0, 0, 0, 0, 0, 0, 0, 0);
11938}
11939
11940/* Common destruction function for both primary and cursor planes */
11941static void intel_plane_destroy(struct drm_plane *plane)
11942{ 11938{
11943 struct intel_plane *intel_plane = to_intel_plane(plane); 11939 struct intel_plane *intel_plane = to_intel_plane(plane);
11940 intel_plane_destroy_state(plane, plane->state);
11944 drm_plane_cleanup(plane); 11941 drm_plane_cleanup(plane);
11945 kfree(intel_plane); 11942 kfree(intel_plane);
11946} 11943}
11947 11944
11948static const struct drm_plane_funcs intel_primary_plane_funcs = { 11945static const struct drm_plane_funcs intel_primary_plane_funcs = {
11949 .update_plane = intel_update_plane, 11946 .update_plane = drm_plane_helper_update,
11950 .disable_plane = intel_disable_plane, 11947 .disable_plane = drm_plane_helper_disable,
11951 .destroy = intel_plane_destroy, 11948 .destroy = intel_plane_destroy,
11952 .set_property = intel_plane_set_property 11949 .set_property = intel_plane_set_property,
11950 .atomic_duplicate_state = intel_plane_duplicate_state,
11951 .atomic_destroy_state = intel_plane_destroy_state,
11952
11953}; 11953};
11954 11954
11955static struct drm_plane *intel_primary_plane_create(struct drm_device *dev, 11955static struct drm_plane *intel_primary_plane_create(struct drm_device *dev,
@@ -11963,6 +11963,12 @@ static struct drm_plane *intel_primary_plane_create(struct drm_device *dev,
11963 if (primary == NULL) 11963 if (primary == NULL)
11964 return NULL; 11964 return NULL;
11965 11965
11966 primary->base.state = intel_plane_duplicate_state(&primary->base);
11967 if (primary->base.state == NULL) {
11968 kfree(primary);
11969 return NULL;
11970 }
11971
11966 primary->can_scale = false; 11972 primary->can_scale = false;
11967 primary->max_downscale = 1; 11973 primary->max_downscale = 1;
11968 primary->pipe = pipe; 11974 primary->pipe = pipe;
@@ -11998,6 +12004,8 @@ static struct drm_plane *intel_primary_plane_create(struct drm_device *dev,
11998 primary->rotation); 12004 primary->rotation);
11999 } 12005 }
12000 12006
12007 drm_plane_helper_add(&primary->base, &intel_plane_helper_funcs);
12008
12001 return &primary->base; 12009 return &primary->base;
12002} 12010}
12003 12011
@@ -12006,16 +12014,19 @@ intel_check_cursor_plane(struct drm_plane *plane,
12006 struct intel_plane_state *state) 12014 struct intel_plane_state *state)
12007{ 12015{
12008 struct drm_crtc *crtc = state->base.crtc; 12016 struct drm_crtc *crtc = state->base.crtc;
12009 struct drm_device *dev = crtc->dev; 12017 struct drm_device *dev = plane->dev;
12010 struct drm_framebuffer *fb = state->base.fb; 12018 struct drm_framebuffer *fb = state->base.fb;
12011 struct drm_rect *dest = &state->dst; 12019 struct drm_rect *dest = &state->dst;
12012 struct drm_rect *src = &state->src; 12020 struct drm_rect *src = &state->src;
12013 const struct drm_rect *clip = &state->clip; 12021 const struct drm_rect *clip = &state->clip;
12014 struct drm_i915_gem_object *obj = intel_fb_obj(fb); 12022 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
12015 int crtc_w, crtc_h; 12023 struct intel_crtc *intel_crtc;
12016 unsigned stride; 12024 unsigned stride;
12017 int ret; 12025 int ret;
12018 12026
12027 crtc = crtc ? crtc : plane->crtc;
12028 intel_crtc = to_intel_crtc(crtc);
12029
12019 ret = drm_plane_helper_check_update(plane, crtc, fb, 12030 ret = drm_plane_helper_check_update(plane, crtc, fb,
12020 src, dest, clip, 12031 src, dest, clip,
12021 DRM_PLANE_HELPER_NO_SCALING, 12032 DRM_PLANE_HELPER_NO_SCALING,
@@ -12027,18 +12038,17 @@ intel_check_cursor_plane(struct drm_plane *plane,
12027 12038
12028 /* if we want to turn off the cursor ignore width and height */ 12039 /* if we want to turn off the cursor ignore width and height */
12029 if (!obj) 12040 if (!obj)
12030 return 0; 12041 goto finish;
12031 12042
12032 /* Check for which cursor types we support */ 12043 /* Check for which cursor types we support */
12033 crtc_w = drm_rect_width(&state->orig_dst); 12044 if (!cursor_size_ok(dev, state->base.crtc_w, state->base.crtc_h)) {
12034 crtc_h = drm_rect_height(&state->orig_dst); 12045 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
12035 if (!cursor_size_ok(dev, crtc_w, crtc_h)) { 12046 state->base.crtc_w, state->base.crtc_h);
12036 DRM_DEBUG("Cursor dimension not supported\n");
12037 return -EINVAL; 12047 return -EINVAL;
12038 } 12048 }
12039 12049
12040 stride = roundup_pow_of_two(crtc_w) * 4; 12050 stride = roundup_pow_of_two(state->base.crtc_w) * 4;
12041 if (obj->base.size < stride * crtc_h) { 12051 if (obj->base.size < stride * state->base.crtc_h) {
12042 DRM_DEBUG_KMS("buffer is too small\n"); 12052 DRM_DEBUG_KMS("buffer is too small\n");
12043 return -ENOMEM; 12053 return -ENOMEM;
12044 } 12054 }
@@ -12054,6 +12064,15 @@ intel_check_cursor_plane(struct drm_plane *plane,
12054 } 12064 }
12055 mutex_unlock(&dev->struct_mutex); 12065 mutex_unlock(&dev->struct_mutex);
12056 12066
12067finish:
12068 if (intel_crtc->active) {
12069 if (intel_crtc->cursor_width != state->base.crtc_w)
12070 intel_crtc->atomic.update_wm = true;
12071
12072 intel_crtc->atomic.fb_bits |=
12073 INTEL_FRONTBUFFER_CURSOR(intel_crtc->pipe);
12074 }
12075
12057 return ret; 12076 return ret;
12058} 12077}
12059 12078
@@ -12062,43 +12081,24 @@ intel_commit_cursor_plane(struct drm_plane *plane,
12062 struct intel_plane_state *state) 12081 struct intel_plane_state *state)
12063{ 12082{
12064 struct drm_crtc *crtc = state->base.crtc; 12083 struct drm_crtc *crtc = state->base.crtc;
12065 struct drm_device *dev = crtc->dev; 12084 struct drm_device *dev = plane->dev;
12066 struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 12085 struct intel_crtc *intel_crtc;
12067 struct intel_plane *intel_plane = to_intel_plane(plane); 12086 struct intel_plane *intel_plane = to_intel_plane(plane);
12068 struct drm_i915_gem_object *obj = intel_fb_obj(state->base.fb); 12087 struct drm_i915_gem_object *obj = intel_fb_obj(state->base.fb);
12069 struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->fb);
12070 enum pipe pipe = intel_crtc->pipe;
12071 unsigned old_width;
12072 uint32_t addr; 12088 uint32_t addr;
12073 12089
12090 crtc = crtc ? crtc : plane->crtc;
12091 intel_crtc = to_intel_crtc(crtc);
12092
12074 plane->fb = state->base.fb; 12093 plane->fb = state->base.fb;
12075 crtc->cursor_x = state->orig_dst.x1; 12094 crtc->cursor_x = state->base.crtc_x;
12076 crtc->cursor_y = state->orig_dst.y1; 12095 crtc->cursor_y = state->base.crtc_y;
12077 12096
12078 intel_plane->crtc_x = state->orig_dst.x1;
12079 intel_plane->crtc_y = state->orig_dst.y1;
12080 intel_plane->crtc_w = drm_rect_width(&state->orig_dst);
12081 intel_plane->crtc_h = drm_rect_height(&state->orig_dst);
12082 intel_plane->src_x = state->orig_src.x1;
12083 intel_plane->src_y = state->orig_src.y1;
12084 intel_plane->src_w = drm_rect_width(&state->orig_src);
12085 intel_plane->src_h = drm_rect_height(&state->orig_src);
12086 intel_plane->obj = obj; 12097 intel_plane->obj = obj;
12087 12098
12088 if (intel_crtc->cursor_bo == obj) 12099 if (intel_crtc->cursor_bo == obj)
12089 goto update; 12100 goto update;
12090 12101
12091 /*
12092 * 'prepare' is only called when fb != NULL; we still need to update
12093 * frontbuffer tracking for the 'disable' case here.
12094 */
12095 if (!obj) {
12096 mutex_lock(&dev->struct_mutex);
12097 i915_gem_track_fb(old_obj, NULL,
12098 INTEL_FRONTBUFFER_CURSOR(pipe));
12099 mutex_unlock(&dev->struct_mutex);
12100 }
12101
12102 if (!obj) 12102 if (!obj)
12103 addr = 0; 12103 addr = 0;
12104 else if (!INTEL_INFO(dev)->cursor_needs_physical) 12104 else if (!INTEL_INFO(dev)->cursor_needs_physical)
@@ -12109,25 +12109,20 @@ intel_commit_cursor_plane(struct drm_plane *plane,
12109 intel_crtc->cursor_addr = addr; 12109 intel_crtc->cursor_addr = addr;
12110 intel_crtc->cursor_bo = obj; 12110 intel_crtc->cursor_bo = obj;
12111update: 12111update:
12112 old_width = intel_crtc->cursor_width; 12112 intel_crtc->cursor_width = state->base.crtc_w;
12113 intel_crtc->cursor_height = state->base.crtc_h;
12113 12114
12114 intel_crtc->cursor_width = drm_rect_width(&state->orig_dst); 12115 if (intel_crtc->active)
12115 intel_crtc->cursor_height = drm_rect_height(&state->orig_dst);
12116
12117 if (intel_crtc->active) {
12118 if (old_width != intel_crtc->cursor_width)
12119 intel_update_watermarks(crtc);
12120 intel_crtc_update_cursor(crtc, state->visible); 12116 intel_crtc_update_cursor(crtc, state->visible);
12121
12122 intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_CURSOR(pipe));
12123 }
12124} 12117}
12125 12118
12126static const struct drm_plane_funcs intel_cursor_plane_funcs = { 12119static const struct drm_plane_funcs intel_cursor_plane_funcs = {
12127 .update_plane = intel_update_plane, 12120 .update_plane = drm_plane_helper_update,
12128 .disable_plane = intel_disable_plane, 12121 .disable_plane = drm_plane_helper_disable,
12129 .destroy = intel_plane_destroy, 12122 .destroy = intel_plane_destroy,
12130 .set_property = intel_plane_set_property, 12123 .set_property = intel_plane_set_property,
12124 .atomic_duplicate_state = intel_plane_duplicate_state,
12125 .atomic_destroy_state = intel_plane_destroy_state,
12131}; 12126};
12132 12127
12133static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev, 12128static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev,
@@ -12139,6 +12134,12 @@ static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev,
12139 if (cursor == NULL) 12134 if (cursor == NULL)
12140 return NULL; 12135 return NULL;
12141 12136
12137 cursor->base.state = intel_plane_duplicate_state(&cursor->base);
12138 if (cursor->base.state == NULL) {
12139 kfree(cursor);
12140 return NULL;
12141 }
12142
12142 cursor->can_scale = false; 12143 cursor->can_scale = false;
12143 cursor->max_downscale = 1; 12144 cursor->max_downscale = 1;
12144 cursor->pipe = pipe; 12145 cursor->pipe = pipe;
@@ -12165,6 +12166,8 @@ static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev,
12165 cursor->rotation); 12166 cursor->rotation);
12166 } 12167 }
12167 12168
12169 drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs);
12170
12168 return &cursor->base; 12171 return &cursor->base;
12169} 12172}
12170 12173
@@ -12390,14 +12393,16 @@ static void intel_setup_outputs(struct drm_device *dev)
12390 * eDP ports. Consult the VBT as well as DP_DETECTED to 12393 * eDP ports. Consult the VBT as well as DP_DETECTED to
12391 * detect eDP ports. 12394 * detect eDP ports.
12392 */ 12395 */
12393 if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIB) & SDVO_DETECTED) 12396 if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIB) & SDVO_DETECTED &&
12397 !intel_dp_is_edp(dev, PORT_B))
12394 intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIB, 12398 intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIB,
12395 PORT_B); 12399 PORT_B);
12396 if (I915_READ(VLV_DISPLAY_BASE + DP_B) & DP_DETECTED || 12400 if (I915_READ(VLV_DISPLAY_BASE + DP_B) & DP_DETECTED ||
12397 intel_dp_is_edp(dev, PORT_B)) 12401 intel_dp_is_edp(dev, PORT_B))
12398 intel_dp_init(dev, VLV_DISPLAY_BASE + DP_B, PORT_B); 12402 intel_dp_init(dev, VLV_DISPLAY_BASE + DP_B, PORT_B);
12399 12403
12400 if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIC) & SDVO_DETECTED) 12404 if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIC) & SDVO_DETECTED &&
12405 !intel_dp_is_edp(dev, PORT_C))
12401 intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIC, 12406 intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIC,
12402 PORT_C); 12407 PORT_C);
12403 if (I915_READ(VLV_DISPLAY_BASE + DP_C) & DP_DETECTED || 12408 if (I915_READ(VLV_DISPLAY_BASE + DP_C) & DP_DETECTED ||
diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
index 88d81a8b0d35..df7b558f3222 100644
--- a/drivers/gpu/drm/i915/intel_dp.c
+++ b/drivers/gpu/drm/i915/intel_dp.c
@@ -3773,7 +3773,7 @@ go_again:
3773 intel_dp_stop_link_train(intel_dp); 3773 intel_dp_stop_link_train(intel_dp);
3774 } 3774 }
3775 3775
3776 DRM_DEBUG_KMS("got esi %02x %02x %02x\n", esi[0], esi[1], esi[2]); 3776 DRM_DEBUG_KMS("got esi %3ph\n", esi);
3777 ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled); 3777 ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled);
3778 3778
3779 if (handled) { 3779 if (handled) {
@@ -3789,7 +3789,7 @@ go_again:
3789 3789
3790 bret = intel_dp_get_sink_irq_esi(intel_dp, esi); 3790 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
3791 if (bret == true) { 3791 if (bret == true) {
3792 DRM_DEBUG_KMS("got esi2 %02x %02x %02x\n", esi[0], esi[1], esi[2]); 3792 DRM_DEBUG_KMS("got esi2 %3ph\n", esi);
3793 goto go_again; 3793 goto go_again;
3794 } 3794 }
3795 } else 3795 } else
diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
index bb871f3cfe2e..30e968f8c55e 100644
--- a/drivers/gpu/drm/i915/intel_drv.h
+++ b/drivers/gpu/drm/i915/intel_drv.h
@@ -248,9 +248,13 @@ struct intel_plane_state {
248 struct drm_rect src; 248 struct drm_rect src;
249 struct drm_rect dst; 249 struct drm_rect dst;
250 struct drm_rect clip; 250 struct drm_rect clip;
251 struct drm_rect orig_src;
252 struct drm_rect orig_dst;
253 bool visible; 251 bool visible;
252
253 /*
254 * used only for sprite planes to determine when to implicitly
255 * enable/disable the primary plane
256 */
257 bool hides_primary;
254}; 258};
255 259
256struct intel_plane_config { 260struct intel_plane_config {
@@ -415,6 +419,32 @@ struct skl_pipe_wm {
415 uint32_t linetime; 419 uint32_t linetime;
416}; 420};
417 421
422/*
423 * Tracking of operations that need to be performed at the beginning/end of an
424 * atomic commit, outside the atomic section where interrupts are disabled.
425 * These are generally operations that grab mutexes or might otherwise sleep
426 * and thus can't be run with interrupts disabled.
427 */
428struct intel_crtc_atomic_commit {
429 /* vblank evasion */
430 bool evade;
431 unsigned start_vbl_count;
432
433 /* Sleepable operations to perform before commit */
434 bool wait_for_flips;
435 bool disable_fbc;
436 bool pre_disable_primary;
437 bool update_wm;
438 unsigned disabled_planes;
439
440 /* Sleepable operations to perform after commit */
441 unsigned fb_bits;
442 bool wait_vblank;
443 bool update_fbc;
444 bool post_enable_primary;
445 unsigned update_sprite_watermarks;
446};
447
418struct intel_crtc { 448struct intel_crtc {
419 struct drm_crtc base; 449 struct drm_crtc base;
420 enum pipe pipe; 450 enum pipe pipe;
@@ -468,6 +498,8 @@ struct intel_crtc {
468 498
469 int scanline_offset; 499 int scanline_offset;
470 struct intel_mmio_flip mmio_flip; 500 struct intel_mmio_flip mmio_flip;
501
502 struct intel_crtc_atomic_commit atomic;
471}; 503};
472 504
473struct intel_plane_wm_parameters { 505struct intel_plane_wm_parameters {
@@ -485,10 +517,6 @@ struct intel_plane {
485 struct drm_i915_gem_object *obj; 517 struct drm_i915_gem_object *obj;
486 bool can_scale; 518 bool can_scale;
487 int max_downscale; 519 int max_downscale;
488 int crtc_x, crtc_y;
489 unsigned int crtc_w, crtc_h;
490 uint32_t src_x, src_y;
491 uint32_t src_w, src_h;
492 unsigned int rotation; 520 unsigned int rotation;
493 521
494 /* Since we need to change the watermarks before/after 522 /* Since we need to change the watermarks before/after
@@ -542,6 +570,7 @@ struct cxsr_latency {
542#define to_intel_encoder(x) container_of(x, struct intel_encoder, base) 570#define to_intel_encoder(x) container_of(x, struct intel_encoder, base)
543#define to_intel_framebuffer(x) container_of(x, struct intel_framebuffer, base) 571#define to_intel_framebuffer(x) container_of(x, struct intel_framebuffer, base)
544#define to_intel_plane(x) container_of(x, struct intel_plane, base) 572#define to_intel_plane(x) container_of(x, struct intel_plane, base)
573#define to_intel_plane_state(x) container_of(x, struct intel_plane_state, base)
545#define intel_fb_obj(x) (x ? to_intel_framebuffer(x)->obj : NULL) 574#define intel_fb_obj(x) (x ? to_intel_framebuffer(x)->obj : NULL)
546 575
547struct intel_hdmi { 576struct intel_hdmi {
@@ -874,6 +903,8 @@ void intel_fb_obj_flush(struct drm_i915_gem_object *obj, bool retire);
874void intel_init_audio(struct drm_device *dev); 903void intel_init_audio(struct drm_device *dev);
875void intel_audio_codec_enable(struct intel_encoder *encoder); 904void intel_audio_codec_enable(struct intel_encoder *encoder);
876void intel_audio_codec_disable(struct intel_encoder *encoder); 905void intel_audio_codec_disable(struct intel_encoder *encoder);
906void i915_audio_component_init(struct drm_i915_private *dev_priv);
907void i915_audio_component_cleanup(struct drm_i915_private *dev_priv);
877 908
878/* intel_display.c */ 909/* intel_display.c */
879bool intel_has_pending_fb_unpin(struct drm_device *dev); 910bool intel_has_pending_fb_unpin(struct drm_device *dev);
@@ -1021,6 +1052,7 @@ int intel_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
1021 uint32_t src_x, uint32_t src_y, 1052 uint32_t src_x, uint32_t src_y,
1022 uint32_t src_w, uint32_t src_h); 1053 uint32_t src_w, uint32_t src_h);
1023int intel_disable_plane(struct drm_plane *plane); 1054int intel_disable_plane(struct drm_plane *plane);
1055void intel_plane_destroy(struct drm_plane *plane);
1024 1056
1025/* intel_dp_mst.c */ 1057/* intel_dp_mst.c */
1026int intel_dp_mst_encoder_init(struct intel_digital_port *intel_dig_port, int conn_id); 1058int intel_dp_mst_encoder_init(struct intel_digital_port *intel_dig_port, int conn_id);
@@ -1214,8 +1246,16 @@ int intel_sprite_get_colorkey(struct drm_device *dev, void *data,
1214bool intel_pipe_update_start(struct intel_crtc *crtc, 1246bool intel_pipe_update_start(struct intel_crtc *crtc,
1215 uint32_t *start_vbl_count); 1247 uint32_t *start_vbl_count);
1216void intel_pipe_update_end(struct intel_crtc *crtc, u32 start_vbl_count); 1248void intel_pipe_update_end(struct intel_crtc *crtc, u32 start_vbl_count);
1249void intel_post_enable_primary(struct drm_crtc *crtc);
1250void intel_pre_disable_primary(struct drm_crtc *crtc);
1217 1251
1218/* intel_tv.c */ 1252/* intel_tv.c */
1219void intel_tv_init(struct drm_device *dev); 1253void intel_tv_init(struct drm_device *dev);
1220 1254
1255/* intel_atomic.c */
1256struct drm_plane_state *intel_plane_duplicate_state(struct drm_plane *plane);
1257void intel_plane_destroy_state(struct drm_plane *plane,
1258 struct drm_plane_state *state);
1259extern const struct drm_plane_helper_funcs intel_plane_helper_funcs;
1260
1221#endif /* __INTEL_DRV_H__ */ 1261#endif /* __INTEL_DRV_H__ */
diff --git a/drivers/gpu/drm/i915/intel_lrc.c b/drivers/gpu/drm/i915/intel_lrc.c
index 7670a0f0f620..e405b61cdac5 100644
--- a/drivers/gpu/drm/i915/intel_lrc.c
+++ b/drivers/gpu/drm/i915/intel_lrc.c
@@ -1137,6 +1137,7 @@ static int gen8_init_common_ring(struct intel_engine_cs *ring)
1137 _MASKED_BIT_DISABLE(GFX_REPLAY_MODE) | 1137 _MASKED_BIT_DISABLE(GFX_REPLAY_MODE) |
1138 _MASKED_BIT_ENABLE(GFX_RUN_LIST_ENABLE)); 1138 _MASKED_BIT_ENABLE(GFX_RUN_LIST_ENABLE));
1139 POSTING_READ(RING_MODE_GEN7(ring)); 1139 POSTING_READ(RING_MODE_GEN7(ring));
1140 ring->next_context_status_buffer = 0;
1140 DRM_DEBUG_DRIVER("Execlists enabled for %s\n", ring->name); 1141 DRM_DEBUG_DRIVER("Execlists enabled for %s\n", ring->name);
1141 1142
1142 memset(&ring->hangcheck, 0, sizeof(ring->hangcheck)); 1143 memset(&ring->hangcheck, 0, sizeof(ring->hangcheck));
@@ -1394,7 +1395,6 @@ static int logical_ring_init(struct drm_device *dev, struct intel_engine_cs *rin
1394 INIT_LIST_HEAD(&ring->execlist_queue); 1395 INIT_LIST_HEAD(&ring->execlist_queue);
1395 INIT_LIST_HEAD(&ring->execlist_retired_req_list); 1396 INIT_LIST_HEAD(&ring->execlist_retired_req_list);
1396 spin_lock_init(&ring->execlist_lock); 1397 spin_lock_init(&ring->execlist_lock);
1397 ring->next_context_status_buffer = 0;
1398 1398
1399 ret = i915_cmd_parser_init_ring(ring); 1399 ret = i915_cmd_parser_init_ring(ring);
1400 if (ret) 1400 if (ret)
diff --git a/drivers/gpu/drm/i915/intel_pm.c b/drivers/gpu/drm/i915/intel_pm.c
index 7d99a9c4e49b..03fc7f2ee9d1 100644
--- a/drivers/gpu/drm/i915/intel_pm.c
+++ b/drivers/gpu/drm/i915/intel_pm.c
@@ -4681,8 +4681,7 @@ static void cherryview_enable_rps(struct drm_device *dev)
4681 I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10); 4681 I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10);
4682 I915_WRITE(GEN6_RC_SLEEP, 0); 4682 I915_WRITE(GEN6_RC_SLEEP, 0);
4683 4683
4684 /* TO threshold set to 1750 us ( 0x557 * 1.28 us) */ 4684 I915_WRITE(GEN6_RC6_THRESHOLD, 50000); /* 50/125ms per EI */
4685 I915_WRITE(GEN6_RC6_THRESHOLD, 0x557);
4686 4685
4687 /* allows RC6 residency counter to work */ 4686 /* allows RC6 residency counter to work */
4688 I915_WRITE(VLV_COUNTER_CONTROL, 4687 I915_WRITE(VLV_COUNTER_CONTROL,
@@ -4696,7 +4695,7 @@ static void cherryview_enable_rps(struct drm_device *dev)
4696 /* 3: Enable RC6 */ 4695 /* 3: Enable RC6 */
4697 if ((intel_enable_rc6(dev) & INTEL_RC6_ENABLE) && 4696 if ((intel_enable_rc6(dev) & INTEL_RC6_ENABLE) &&
4698 (pcbr >> VLV_PCBR_ADDR_SHIFT)) 4697 (pcbr >> VLV_PCBR_ADDR_SHIFT))
4699 rc6_mode = GEN7_RC_CTL_TO_MODE; 4698 rc6_mode = GEN6_RC_CTL_EI_MODE(1);
4700 4699
4701 I915_WRITE(GEN6_RC_CONTROL, rc6_mode); 4700 I915_WRITE(GEN6_RC_CONTROL, rc6_mode);
4702 4701
@@ -5974,6 +5973,10 @@ static void haswell_init_clock_gating(struct drm_device *dev)
5974 I915_WRITE(GEN7_GT_MODE, 5973 I915_WRITE(GEN7_GT_MODE,
5975 _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4)); 5974 _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4));
5976 5975
5976 /* WaSampleCChickenBitEnable:hsw */
5977 I915_WRITE(HALF_SLICE_CHICKEN3,
5978 _MASKED_BIT_ENABLE(HSW_SAMPLE_C_PERFORMANCE));
5979
5977 /* WaSwitchSolVfFArbitrationPriority:hsw */ 5980 /* WaSwitchSolVfFArbitrationPriority:hsw */
5978 I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) | HSW_ECOCHK_ARB_PRIO_SOL); 5981 I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) | HSW_ECOCHK_ARB_PRIO_SOL);
5979 5982
diff --git a/drivers/gpu/drm/i915/intel_psr.c b/drivers/gpu/drm/i915/intel_psr.c
index dd0e6e0447d4..5ae193ec464a 100644
--- a/drivers/gpu/drm/i915/intel_psr.c
+++ b/drivers/gpu/drm/i915/intel_psr.c
@@ -143,7 +143,6 @@ static void hsw_psr_enable_sink(struct intel_dp *intel_dp)
143 struct drm_i915_private *dev_priv = dev->dev_private; 143 struct drm_i915_private *dev_priv = dev->dev_private;
144 uint32_t aux_clock_divider; 144 uint32_t aux_clock_divider;
145 int precharge = 0x3; 145 int precharge = 0x3;
146 bool only_standby = dev_priv->vbt.psr.full_link;
147 static const uint8_t aux_msg[] = { 146 static const uint8_t aux_msg[] = {
148 [0] = DP_AUX_NATIVE_WRITE << 4, 147 [0] = DP_AUX_NATIVE_WRITE << 4,
149 [1] = DP_SET_POWER >> 8, 148 [1] = DP_SET_POWER >> 8,
@@ -157,16 +156,13 @@ static void hsw_psr_enable_sink(struct intel_dp *intel_dp)
157 156
158 aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, 0); 157 aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, 0);
159 158
160 if (IS_BROADWELL(dev) && dig_port->port != PORT_A)
161 only_standby = true;
162
163 /* Enable PSR in sink */ 159 /* Enable PSR in sink */
164 if (intel_dp->psr_dpcd[1] & DP_PSR_NO_TRAIN_ON_EXIT || only_standby) 160 if (dev_priv->psr.link_standby)
165 drm_dp_dpcd_writeb(&intel_dp->aux, DP_PSR_EN_CFG, 161 drm_dp_dpcd_writeb(&intel_dp->aux, DP_PSR_EN_CFG,
166 DP_PSR_ENABLE & ~DP_PSR_MAIN_LINK_ACTIVE); 162 DP_PSR_ENABLE | DP_PSR_MAIN_LINK_ACTIVE);
167 else 163 else
168 drm_dp_dpcd_writeb(&intel_dp->aux, DP_PSR_EN_CFG, 164 drm_dp_dpcd_writeb(&intel_dp->aux, DP_PSR_EN_CFG,
169 DP_PSR_ENABLE | DP_PSR_MAIN_LINK_ACTIVE); 165 DP_PSR_ENABLE & ~DP_PSR_MAIN_LINK_ACTIVE);
170 166
171 /* Setup AUX registers */ 167 /* Setup AUX registers */
172 for (i = 0; i < sizeof(aux_msg); i += 4) 168 for (i = 0; i < sizeof(aux_msg); i += 4)
@@ -226,12 +222,8 @@ static void hsw_psr_enable_source(struct intel_dp *intel_dp)
226 dev_priv->vbt.psr.idle_frames + 1 : 2; 222 dev_priv->vbt.psr.idle_frames + 1 : 2;
227 uint32_t val = 0x0; 223 uint32_t val = 0x0;
228 const uint32_t link_entry_time = EDP_PSR_MIN_LINK_ENTRY_TIME_8_LINES; 224 const uint32_t link_entry_time = EDP_PSR_MIN_LINK_ENTRY_TIME_8_LINES;
229 bool only_standby = false;
230 225
231 if (IS_BROADWELL(dev) && dig_port->port != PORT_A) 226 if (dev_priv->psr.link_standby) {
232 only_standby = true;
233
234 if (intel_dp->psr_dpcd[1] & DP_PSR_NO_TRAIN_ON_EXIT || only_standby) {
235 val |= EDP_PSR_LINK_STANDBY; 227 val |= EDP_PSR_LINK_STANDBY;
236 val |= EDP_PSR_TP2_TP3_TIME_0us; 228 val |= EDP_PSR_TP2_TP3_TIME_0us;
237 val |= EDP_PSR_TP1_TIME_0us; 229 val |= EDP_PSR_TP1_TIME_0us;
@@ -270,22 +262,19 @@ static bool intel_psr_match_conditions(struct intel_dp *intel_dp)
270 return false; 262 return false;
271 } 263 }
272 264
273 /* Below limitations aren't valid for Broadwell */ 265 if (IS_HASWELL(dev) &&
274 if (IS_BROADWELL(dev)) 266 I915_READ(HSW_STEREO_3D_CTL(intel_crtc->config.cpu_transcoder)) &
275 goto out; 267 S3D_ENABLE) {
276
277 if (I915_READ(HSW_STEREO_3D_CTL(intel_crtc->config.cpu_transcoder)) &
278 S3D_ENABLE) {
279 DRM_DEBUG_KMS("PSR condition failed: Stereo 3D is Enabled\n"); 268 DRM_DEBUG_KMS("PSR condition failed: Stereo 3D is Enabled\n");
280 return false; 269 return false;
281 } 270 }
282 271
283 if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) { 272 if (IS_HASWELL(dev) &&
273 intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
284 DRM_DEBUG_KMS("PSR condition failed: Interlaced is Enabled\n"); 274 DRM_DEBUG_KMS("PSR condition failed: Interlaced is Enabled\n");
285 return false; 275 return false;
286 } 276 }
287 277
288 out:
289 dev_priv->psr.source_ok = true; 278 dev_priv->psr.source_ok = true;
290 return true; 279 return true;
291} 280}
@@ -344,6 +333,13 @@ void intel_psr_enable(struct intel_dp *intel_dp)
344 if (!intel_psr_match_conditions(intel_dp)) 333 if (!intel_psr_match_conditions(intel_dp))
345 goto unlock; 334 goto unlock;
346 335
336 /* First we check VBT, but we must respect sink and source
337 * known restrictions */
338 dev_priv->psr.link_standby = dev_priv->vbt.psr.full_link;
339 if ((intel_dp->psr_dpcd[1] & DP_PSR_NO_TRAIN_ON_EXIT) ||
340 (IS_BROADWELL(dev) && intel_dig_port->port != PORT_A))
341 dev_priv->psr.link_standby = true;
342
347 dev_priv->psr.busy_frontbuffer_bits = 0; 343 dev_priv->psr.busy_frontbuffer_bits = 0;
348 344
349 if (HAS_DDI(dev)) { 345 if (HAS_DDI(dev)) {
@@ -620,13 +616,11 @@ void intel_psr_flush(struct drm_device *dev,
620 616
621 /* 617 /*
622 * On Valleyview and Cherryview we don't use hardware tracking so 618 * On Valleyview and Cherryview we don't use hardware tracking so
623 * sprite plane updates or cursor moves don't result in a PSR 619 * any plane updates or cursor moves don't result in a PSR
624 * invalidating. Which means we need to manually fake this in 620 * invalidating. Which means we need to manually fake this in
625 * software for all flushes, not just when we've seen a preceding 621 * software for all flushes, not just when we've seen a preceding
626 * invalidation through frontbuffer rendering. */ 622 * invalidation through frontbuffer rendering. */
627 if (!HAS_DDI(dev) && 623 if (!HAS_DDI(dev))
628 ((frontbuffer_bits & INTEL_FRONTBUFFER_SPRITE(pipe)) ||
629 (frontbuffer_bits & INTEL_FRONTBUFFER_CURSOR(pipe))))
630 intel_psr_exit(dev); 624 intel_psr_exit(dev);
631 625
632 if (!dev_priv->psr.active && !dev_priv->psr.busy_frontbuffer_bits) 626 if (!dev_priv->psr.active && !dev_priv->psr.busy_frontbuffer_bits)
diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.c b/drivers/gpu/drm/i915/intel_ringbuffer.c
index 12a36f0ca53d..23020d67329b 100644
--- a/drivers/gpu/drm/i915/intel_ringbuffer.c
+++ b/drivers/gpu/drm/i915/intel_ringbuffer.c
@@ -796,6 +796,16 @@ static int bdw_init_workarounds(struct intel_engine_cs *ring)
796 HDC_DONOT_FETCH_MEM_WHEN_MASKED | 796 HDC_DONOT_FETCH_MEM_WHEN_MASKED |
797 (IS_BDW_GT3(dev) ? HDC_FENCE_DEST_SLM_DISABLE : 0)); 797 (IS_BDW_GT3(dev) ? HDC_FENCE_DEST_SLM_DISABLE : 0));
798 798
799 /* From the Haswell PRM, Command Reference: Registers, CACHE_MODE_0:
800 * "The Hierarchical Z RAW Stall Optimization allows non-overlapping
801 * polygons in the same 8x4 pixel/sample area to be processed without
802 * stalling waiting for the earlier ones to write to Hierarchical Z
803 * buffer."
804 *
805 * This optimization is off by default for Broadwell; turn it on.
806 */
807 WA_CLR_BIT_MASKED(CACHE_MODE_0_GEN7, HIZ_RAW_STALL_OPT_DISABLE);
808
799 /* Wa4x4STCOptimizationDisable:bdw */ 809 /* Wa4x4STCOptimizationDisable:bdw */
800 WA_SET_BIT_MASKED(CACHE_MODE_1, 810 WA_SET_BIT_MASKED(CACHE_MODE_1,
801 GEN8_4x4_STC_OPTIMIZATION_DISABLE); 811 GEN8_4x4_STC_OPTIMIZATION_DISABLE);
@@ -836,6 +846,14 @@ static int chv_init_workarounds(struct intel_engine_cs *ring)
836 HDC_FORCE_NON_COHERENT | 846 HDC_FORCE_NON_COHERENT |
837 HDC_DONOT_FETCH_MEM_WHEN_MASKED); 847 HDC_DONOT_FETCH_MEM_WHEN_MASKED);
838 848
849 /* According to the CACHE_MODE_0 default value documentation, some
850 * CHV platforms disable this optimization by default. Turn it on.
851 */
852 WA_CLR_BIT_MASKED(CACHE_MODE_0_GEN7, HIZ_RAW_STALL_OPT_DISABLE);
853
854 /* Improve HiZ throughput on CHV. */
855 WA_SET_BIT_MASKED(HIZ_CHICKEN, CHV_HZ_8X8_MODE_IN_1X);
856
839 return 0; 857 return 0;
840} 858}
841 859
diff --git a/drivers/gpu/drm/i915/intel_runtime_pm.c b/drivers/gpu/drm/i915/intel_runtime_pm.c
index 39e1b071765d..8bf7bb4a12bc 100644
--- a/drivers/gpu/drm/i915/intel_runtime_pm.c
+++ b/drivers/gpu/drm/i915/intel_runtime_pm.c
@@ -31,7 +31,6 @@
31 31
32#include "i915_drv.h" 32#include "i915_drv.h"
33#include "intel_drv.h" 33#include "intel_drv.h"
34#include <drm/i915_powerwell.h>
35 34
36/** 35/**
37 * DOC: runtime pm 36 * DOC: runtime pm
@@ -50,8 +49,6 @@
50 * present for a given platform. 49 * present for a given platform.
51 */ 50 */
52 51
53static struct i915_power_domains *hsw_pwr;
54
55#define for_each_power_well(i, power_well, domain_mask, power_domains) \ 52#define for_each_power_well(i, power_well, domain_mask, power_domains) \
56 for (i = 0; \ 53 for (i = 0; \
57 i < (power_domains)->power_well_count && \ 54 i < (power_domains)->power_well_count && \
@@ -1071,10 +1068,8 @@ int intel_power_domains_init(struct drm_i915_private *dev_priv)
1071 */ 1068 */
1072 if (IS_HASWELL(dev_priv->dev)) { 1069 if (IS_HASWELL(dev_priv->dev)) {
1073 set_power_wells(power_domains, hsw_power_wells); 1070 set_power_wells(power_domains, hsw_power_wells);
1074 hsw_pwr = power_domains;
1075 } else if (IS_BROADWELL(dev_priv->dev)) { 1071 } else if (IS_BROADWELL(dev_priv->dev)) {
1076 set_power_wells(power_domains, bdw_power_wells); 1072 set_power_wells(power_domains, bdw_power_wells);
1077 hsw_pwr = power_domains;
1078 } else if (IS_CHERRYVIEW(dev_priv->dev)) { 1073 } else if (IS_CHERRYVIEW(dev_priv->dev)) {
1079 set_power_wells(power_domains, chv_power_wells); 1074 set_power_wells(power_domains, chv_power_wells);
1080 } else if (IS_VALLEYVIEW(dev_priv->dev)) { 1075 } else if (IS_VALLEYVIEW(dev_priv->dev)) {
@@ -1118,8 +1113,6 @@ void intel_power_domains_fini(struct drm_i915_private *dev_priv)
1118 * the power well is not enabled, so just enable it in case 1113 * the power well is not enabled, so just enable it in case
1119 * we're going to unload/reload. */ 1114 * we're going to unload/reload. */
1120 intel_display_set_init_power(dev_priv, true); 1115 intel_display_set_init_power(dev_priv, true);
1121
1122 hsw_pwr = NULL;
1123} 1116}
1124 1117
1125static void intel_power_domains_resume(struct drm_i915_private *dev_priv) 1118static void intel_power_domains_resume(struct drm_i915_private *dev_priv)
@@ -1328,52 +1321,3 @@ void intel_runtime_pm_enable(struct drm_i915_private *dev_priv)
1328 pm_runtime_put_autosuspend(device); 1321 pm_runtime_put_autosuspend(device);
1329} 1322}
1330 1323
1331/* Display audio driver power well request */
1332int i915_request_power_well(void)
1333{
1334 struct drm_i915_private *dev_priv;
1335
1336 if (!hsw_pwr)
1337 return -ENODEV;
1338
1339 dev_priv = container_of(hsw_pwr, struct drm_i915_private,
1340 power_domains);
1341 intel_display_power_get(dev_priv, POWER_DOMAIN_AUDIO);
1342 return 0;
1343}
1344EXPORT_SYMBOL_GPL(i915_request_power_well);
1345
1346/* Display audio driver power well release */
1347int i915_release_power_well(void)
1348{
1349 struct drm_i915_private *dev_priv;
1350
1351 if (!hsw_pwr)
1352 return -ENODEV;
1353
1354 dev_priv = container_of(hsw_pwr, struct drm_i915_private,
1355 power_domains);
1356 intel_display_power_put(dev_priv, POWER_DOMAIN_AUDIO);
1357 return 0;
1358}
1359EXPORT_SYMBOL_GPL(i915_release_power_well);
1360
1361/*
1362 * Private interface for the audio driver to get CDCLK in kHz.
1363 *
1364 * Caller must request power well using i915_request_power_well() prior to
1365 * making the call.
1366 */
1367int i915_get_cdclk_freq(void)
1368{
1369 struct drm_i915_private *dev_priv;
1370
1371 if (!hsw_pwr)
1372 return -ENODEV;
1373
1374 dev_priv = container_of(hsw_pwr, struct drm_i915_private,
1375 power_domains);
1376
1377 return intel_ddi_get_cdclk_freq(dev_priv);
1378}
1379EXPORT_SYMBOL_GPL(i915_get_cdclk_freq);
diff --git a/drivers/gpu/drm/i915/intel_sdvo.c b/drivers/gpu/drm/i915/intel_sdvo.c
index 6d7a277458b5..4e3d362931e9 100644
--- a/drivers/gpu/drm/i915/intel_sdvo.c
+++ b/drivers/gpu/drm/i915/intel_sdvo.c
@@ -1617,6 +1617,9 @@ static uint16_t intel_sdvo_get_hotplug_support(struct intel_sdvo *intel_sdvo)
1617 struct drm_device *dev = intel_sdvo->base.base.dev; 1617 struct drm_device *dev = intel_sdvo->base.base.dev;
1618 uint16_t hotplug; 1618 uint16_t hotplug;
1619 1619
1620 if (!I915_HAS_HOTPLUG(dev))
1621 return 0;
1622
1620 /* HW Erratum: SDVO Hotplug is broken on all i945G chips, there's noise 1623 /* HW Erratum: SDVO Hotplug is broken on all i945G chips, there's noise
1621 * on the line. */ 1624 * on the line. */
1622 if (IS_I945G(dev) || IS_I945GM(dev)) 1625 if (IS_I945G(dev) || IS_I945GM(dev))
diff --git a/drivers/gpu/drm/i915/intel_sprite.c b/drivers/gpu/drm/i915/intel_sprite.c
index c18e57d36c2c..dca3f70ef1ba 100644
--- a/drivers/gpu/drm/i915/intel_sprite.c
+++ b/drivers/gpu/drm/i915/intel_sprite.c
@@ -33,6 +33,7 @@
33#include <drm/drm_crtc.h> 33#include <drm/drm_crtc.h>
34#include <drm/drm_fourcc.h> 34#include <drm/drm_fourcc.h>
35#include <drm/drm_rect.h> 35#include <drm/drm_rect.h>
36#include <drm/drm_plane_helper.h>
36#include "intel_drv.h" 37#include "intel_drv.h"
37#include <drm/i915_drm.h> 38#include <drm/i915_drm.h>
38#include "i915_drv.h" 39#include "i915_drv.h"
@@ -412,8 +413,6 @@ vlv_update_plane(struct drm_plane *dplane, struct drm_crtc *crtc,
412 u32 sprctl; 413 u32 sprctl;
413 unsigned long sprsurf_offset, linear_offset; 414 unsigned long sprsurf_offset, linear_offset;
414 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); 415 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
415 u32 start_vbl_count;
416 bool atomic_update;
417 416
418 sprctl = I915_READ(SPCNTR(pipe, plane)); 417 sprctl = I915_READ(SPCNTR(pipe, plane));
419 418
@@ -502,8 +501,6 @@ vlv_update_plane(struct drm_plane *dplane, struct drm_crtc *crtc,
502 linear_offset += src_h * fb->pitches[0] + src_w * pixel_size; 501 linear_offset += src_h * fb->pitches[0] + src_w * pixel_size;
503 } 502 }
504 503
505 atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count);
506
507 intel_update_primary_plane(intel_crtc); 504 intel_update_primary_plane(intel_crtc);
508 505
509 if (IS_CHERRYVIEW(dev) && pipe == PIPE_B) 506 if (IS_CHERRYVIEW(dev) && pipe == PIPE_B)
@@ -525,9 +522,6 @@ vlv_update_plane(struct drm_plane *dplane, struct drm_crtc *crtc,
525 sprsurf_offset); 522 sprsurf_offset);
526 523
527 intel_flush_primary_plane(dev_priv, intel_crtc->plane); 524 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
528
529 if (atomic_update)
530 intel_pipe_update_end(intel_crtc, start_vbl_count);
531} 525}
532 526
533static void 527static void
@@ -539,10 +533,6 @@ vlv_disable_plane(struct drm_plane *dplane, struct drm_crtc *crtc)
539 struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 533 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
540 int pipe = intel_plane->pipe; 534 int pipe = intel_plane->pipe;
541 int plane = intel_plane->plane; 535 int plane = intel_plane->plane;
542 u32 start_vbl_count;
543 bool atomic_update;
544
545 atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count);
546 536
547 intel_update_primary_plane(intel_crtc); 537 intel_update_primary_plane(intel_crtc);
548 538
@@ -553,9 +543,6 @@ vlv_disable_plane(struct drm_plane *dplane, struct drm_crtc *crtc)
553 543
554 intel_flush_primary_plane(dev_priv, intel_crtc->plane); 544 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
555 545
556 if (atomic_update)
557 intel_pipe_update_end(intel_crtc, start_vbl_count);
558
559 intel_update_sprite_watermarks(dplane, crtc, 0, 0, 0, false, false); 546 intel_update_sprite_watermarks(dplane, crtc, 0, 0, 0, false, false);
560} 547}
561 548
@@ -626,8 +613,6 @@ ivb_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
626 u32 sprctl, sprscale = 0; 613 u32 sprctl, sprscale = 0;
627 unsigned long sprsurf_offset, linear_offset; 614 unsigned long sprsurf_offset, linear_offset;
628 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); 615 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
629 u32 start_vbl_count;
630 bool atomic_update;
631 616
632 sprctl = I915_READ(SPRCTL(pipe)); 617 sprctl = I915_READ(SPRCTL(pipe));
633 618
@@ -711,8 +696,6 @@ ivb_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
711 } 696 }
712 } 697 }
713 698
714 atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count);
715
716 intel_update_primary_plane(intel_crtc); 699 intel_update_primary_plane(intel_crtc);
717 700
718 I915_WRITE(SPRSTRIDE(pipe), fb->pitches[0]); 701 I915_WRITE(SPRSTRIDE(pipe), fb->pitches[0]);
@@ -735,9 +718,6 @@ ivb_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
735 i915_gem_obj_ggtt_offset(obj) + sprsurf_offset); 718 i915_gem_obj_ggtt_offset(obj) + sprsurf_offset);
736 719
737 intel_flush_primary_plane(dev_priv, intel_crtc->plane); 720 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
738
739 if (atomic_update)
740 intel_pipe_update_end(intel_crtc, start_vbl_count);
741} 721}
742 722
743static void 723static void
@@ -748,10 +728,6 @@ ivb_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc)
748 struct intel_plane *intel_plane = to_intel_plane(plane); 728 struct intel_plane *intel_plane = to_intel_plane(plane);
749 struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 729 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
750 int pipe = intel_plane->pipe; 730 int pipe = intel_plane->pipe;
751 u32 start_vbl_count;
752 bool atomic_update;
753
754 atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count);
755 731
756 intel_update_primary_plane(intel_crtc); 732 intel_update_primary_plane(intel_crtc);
757 733
@@ -764,16 +740,12 @@ ivb_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc)
764 740
765 intel_flush_primary_plane(dev_priv, intel_crtc->plane); 741 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
766 742
767 if (atomic_update)
768 intel_pipe_update_end(intel_crtc, start_vbl_count);
769
770 /* 743 /*
771 * Avoid underruns when disabling the sprite. 744 * Avoid underruns when disabling the sprite.
772 * FIXME remove once watermark updates are done properly. 745 * FIXME remove once watermark updates are done properly.
773 */ 746 */
774 intel_wait_for_vblank(dev, pipe); 747 intel_crtc->atomic.wait_vblank = true;
775 748 intel_crtc->atomic.update_sprite_watermarks |= (1 << drm_plane_index(plane));
776 intel_update_sprite_watermarks(plane, crtc, 0, 0, 0, false, false);
777} 749}
778 750
779static int 751static int
@@ -846,8 +818,6 @@ ilk_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
846 unsigned long dvssurf_offset, linear_offset; 818 unsigned long dvssurf_offset, linear_offset;
847 u32 dvscntr, dvsscale; 819 u32 dvscntr, dvsscale;
848 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); 820 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
849 u32 start_vbl_count;
850 bool atomic_update;
851 821
852 dvscntr = I915_READ(DVSCNTR(pipe)); 822 dvscntr = I915_READ(DVSCNTR(pipe));
853 823
@@ -922,8 +892,6 @@ ilk_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
922 linear_offset += src_h * fb->pitches[0] + src_w * pixel_size; 892 linear_offset += src_h * fb->pitches[0] + src_w * pixel_size;
923 } 893 }
924 894
925 atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count);
926
927 intel_update_primary_plane(intel_crtc); 895 intel_update_primary_plane(intel_crtc);
928 896
929 I915_WRITE(DVSSTRIDE(pipe), fb->pitches[0]); 897 I915_WRITE(DVSSTRIDE(pipe), fb->pitches[0]);
@@ -941,9 +909,6 @@ ilk_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
941 i915_gem_obj_ggtt_offset(obj) + dvssurf_offset); 909 i915_gem_obj_ggtt_offset(obj) + dvssurf_offset);
942 910
943 intel_flush_primary_plane(dev_priv, intel_crtc->plane); 911 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
944
945 if (atomic_update)
946 intel_pipe_update_end(intel_crtc, start_vbl_count);
947} 912}
948 913
949static void 914static void
@@ -954,10 +919,6 @@ ilk_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc)
954 struct intel_plane *intel_plane = to_intel_plane(plane); 919 struct intel_plane *intel_plane = to_intel_plane(plane);
955 struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 920 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
956 int pipe = intel_plane->pipe; 921 int pipe = intel_plane->pipe;
957 u32 start_vbl_count;
958 bool atomic_update;
959
960 atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count);
961 922
962 intel_update_primary_plane(intel_crtc); 923 intel_update_primary_plane(intel_crtc);
963 924
@@ -969,19 +930,25 @@ ilk_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc)
969 930
970 intel_flush_primary_plane(dev_priv, intel_crtc->plane); 931 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
971 932
972 if (atomic_update)
973 intel_pipe_update_end(intel_crtc, start_vbl_count);
974
975 /* 933 /*
976 * Avoid underruns when disabling the sprite. 934 * Avoid underruns when disabling the sprite.
977 * FIXME remove once watermark updates are done properly. 935 * FIXME remove once watermark updates are done properly.
978 */ 936 */
979 intel_wait_for_vblank(dev, pipe); 937 intel_crtc->atomic.wait_vblank = true;
980 938 intel_crtc->atomic.update_sprite_watermarks |= (1 << drm_plane_index(plane));
981 intel_update_sprite_watermarks(plane, crtc, 0, 0, 0, false, false);
982} 939}
983 940
984static void 941/**
942 * intel_post_enable_primary - Perform operations after enabling primary plane
943 * @crtc: the CRTC whose primary plane was just enabled
944 *
945 * Performs potentially sleeping operations that must be done after the primary
946 * plane is enabled, such as updating FBC and IPS. Note that this may be
947 * called due to an explicit primary plane update, or due to an implicit
948 * re-enable that is caused when a sprite plane is updated to no longer
949 * completely hide the primary plane.
950 */
951void
985intel_post_enable_primary(struct drm_crtc *crtc) 952intel_post_enable_primary(struct drm_crtc *crtc)
986{ 953{
987 struct drm_device *dev = crtc->dev; 954 struct drm_device *dev = crtc->dev;
@@ -1008,7 +975,17 @@ intel_post_enable_primary(struct drm_crtc *crtc)
1008 mutex_unlock(&dev->struct_mutex); 975 mutex_unlock(&dev->struct_mutex);
1009} 976}
1010 977
1011static void 978/**
979 * intel_pre_disable_primary - Perform operations before disabling primary plane
980 * @crtc: the CRTC whose primary plane is to be disabled
981 *
982 * Performs potentially sleeping operations that must be done before the
983 * primary plane is enabled, such as updating FBC and IPS. Note that this may
984 * be called due to an explicit primary plane update, or due to an implicit
985 * disable that is caused when a sprite plane completely hides the primary
986 * plane.
987 */
988void
1012intel_pre_disable_primary(struct drm_crtc *crtc) 989intel_pre_disable_primary(struct drm_crtc *crtc)
1013{ 990{
1014 struct drm_device *dev = crtc->dev; 991 struct drm_device *dev = crtc->dev;
@@ -1105,15 +1082,16 @@ intel_check_sprite_plane(struct drm_plane *plane,
1105 uint32_t src_x, src_y, src_w, src_h; 1082 uint32_t src_x, src_y, src_w, src_h;
1106 struct drm_rect *src = &state->src; 1083 struct drm_rect *src = &state->src;
1107 struct drm_rect *dst = &state->dst; 1084 struct drm_rect *dst = &state->dst;
1108 struct drm_rect *orig_src = &state->orig_src;
1109 const struct drm_rect *clip = &state->clip; 1085 const struct drm_rect *clip = &state->clip;
1110 int hscale, vscale; 1086 int hscale, vscale;
1111 int max_scale, min_scale; 1087 int max_scale, min_scale;
1112 int pixel_size; 1088 int pixel_size;
1113 1089
1090 intel_crtc = intel_crtc ? intel_crtc : to_intel_crtc(plane->crtc);
1091
1114 if (!fb) { 1092 if (!fb) {
1115 state->visible = false; 1093 state->visible = false;
1116 return 0; 1094 goto finish;
1117 } 1095 }
1118 1096
1119 /* Don't modify another pipe's plane */ 1097 /* Don't modify another pipe's plane */
@@ -1191,10 +1169,10 @@ intel_check_sprite_plane(struct drm_plane *plane,
1191 intel_plane->rotation); 1169 intel_plane->rotation);
1192 1170
1193 /* sanity check to make sure the src viewport wasn't enlarged */ 1171 /* sanity check to make sure the src viewport wasn't enlarged */
1194 WARN_ON(src->x1 < (int) orig_src->x1 || 1172 WARN_ON(src->x1 < (int) state->base.src_x ||
1195 src->y1 < (int) orig_src->y1 || 1173 src->y1 < (int) state->base.src_y ||
1196 src->x2 > (int) orig_src->x2 || 1174 src->x2 > (int) state->base.src_x + state->base.src_w ||
1197 src->y2 > (int) orig_src->y2); 1175 src->y2 > (int) state->base.src_y + state->base.src_h);
1198 1176
1199 /* 1177 /*
1200 * Hardware doesn't handle subpixel coordinates. 1178 * Hardware doesn't handle subpixel coordinates.
@@ -1260,6 +1238,29 @@ intel_check_sprite_plane(struct drm_plane *plane,
1260 dst->y1 = crtc_y; 1238 dst->y1 = crtc_y;
1261 dst->y2 = crtc_y + crtc_h; 1239 dst->y2 = crtc_y + crtc_h;
1262 1240
1241finish:
1242 /*
1243 * If the sprite is completely covering the primary plane,
1244 * we can disable the primary and save power.
1245 */
1246 state->hides_primary = fb != NULL && drm_rect_equals(dst, clip) &&
1247 !colorkey_enabled(intel_plane);
1248 WARN_ON(state->hides_primary && !state->visible && intel_crtc->active);
1249
1250 if (intel_crtc->active) {
1251 if (intel_crtc->primary_enabled == state->hides_primary)
1252 intel_crtc->atomic.wait_for_flips = true;
1253
1254 if (intel_crtc->primary_enabled && state->hides_primary)
1255 intel_crtc->atomic.pre_disable_primary = true;
1256
1257 intel_crtc->atomic.fb_bits |=
1258 INTEL_FRONTBUFFER_SPRITE(intel_crtc->pipe);
1259
1260 if (!intel_crtc->primary_enabled && !state->hides_primary)
1261 intel_crtc->atomic.post_enable_primary = true;
1262 }
1263
1263 return 0; 1264 return 0;
1264} 1265}
1265 1266
@@ -1267,58 +1268,23 @@ static void
1267intel_commit_sprite_plane(struct drm_plane *plane, 1268intel_commit_sprite_plane(struct drm_plane *plane,
1268 struct intel_plane_state *state) 1269 struct intel_plane_state *state)
1269{ 1270{
1270 struct drm_device *dev = plane->dev;
1271 struct drm_crtc *crtc = state->base.crtc; 1271 struct drm_crtc *crtc = state->base.crtc;
1272 struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 1272 struct intel_crtc *intel_crtc;
1273 struct intel_plane *intel_plane = to_intel_plane(plane); 1273 struct intel_plane *intel_plane = to_intel_plane(plane);
1274 enum pipe pipe = intel_crtc->pipe;
1275 struct drm_framebuffer *fb = state->base.fb; 1274 struct drm_framebuffer *fb = state->base.fb;
1276 struct drm_i915_gem_object *obj = intel_fb_obj(fb); 1275 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
1277 int crtc_x, crtc_y; 1276 int crtc_x, crtc_y;
1278 unsigned int crtc_w, crtc_h; 1277 unsigned int crtc_w, crtc_h;
1279 uint32_t src_x, src_y, src_w, src_h; 1278 uint32_t src_x, src_y, src_w, src_h;
1280 struct drm_rect *dst = &state->dst;
1281 const struct drm_rect *clip = &state->clip;
1282 bool primary_enabled;
1283 1279
1284 /* 1280 crtc = crtc ? crtc : plane->crtc;
1285 * 'prepare' is never called when plane is being disabled, so we need 1281 intel_crtc = to_intel_crtc(crtc);
1286 * to handle frontbuffer tracking here
1287 */
1288 if (!fb) {
1289 mutex_lock(&dev->struct_mutex);
1290 i915_gem_track_fb(intel_fb_obj(plane->fb), NULL,
1291 INTEL_FRONTBUFFER_SPRITE(pipe));
1292 mutex_unlock(&dev->struct_mutex);
1293 }
1294 1282
1295 /* 1283 plane->fb = state->base.fb;
1296 * If the sprite is completely covering the primary plane,
1297 * we can disable the primary and save power.
1298 */
1299 primary_enabled = !drm_rect_equals(dst, clip) || colorkey_enabled(intel_plane);
1300 WARN_ON(!primary_enabled && !state->visible && intel_crtc->active);
1301
1302 intel_plane->crtc_x = state->orig_dst.x1;
1303 intel_plane->crtc_y = state->orig_dst.y1;
1304 intel_plane->crtc_w = drm_rect_width(&state->orig_dst);
1305 intel_plane->crtc_h = drm_rect_height(&state->orig_dst);
1306 intel_plane->src_x = state->orig_src.x1;
1307 intel_plane->src_y = state->orig_src.y1;
1308 intel_plane->src_w = drm_rect_width(&state->orig_src);
1309 intel_plane->src_h = drm_rect_height(&state->orig_src);
1310 intel_plane->obj = obj; 1284 intel_plane->obj = obj;
1311 1285
1312 if (intel_crtc->active) { 1286 if (intel_crtc->active) {
1313 bool primary_was_enabled = intel_crtc->primary_enabled; 1287 intel_crtc->primary_enabled = !state->hides_primary;
1314
1315 intel_crtc->primary_enabled = primary_enabled;
1316
1317 if (primary_was_enabled != primary_enabled)
1318 intel_crtc_wait_for_pending_flips(crtc);
1319
1320 if (primary_was_enabled && !primary_enabled)
1321 intel_pre_disable_primary(crtc);
1322 1288
1323 if (state->visible) { 1289 if (state->visible) {
1324 crtc_x = state->dst.x1; 1290 crtc_x = state->dst.x1;
@@ -1335,23 +1301,9 @@ intel_commit_sprite_plane(struct drm_plane *plane,
1335 } else { 1301 } else {
1336 intel_plane->disable_plane(plane, crtc); 1302 intel_plane->disable_plane(plane, crtc);
1337 } 1303 }
1338
1339
1340 intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_SPRITE(pipe));
1341
1342 if (!primary_was_enabled && primary_enabled)
1343 intel_post_enable_primary(crtc);
1344 } 1304 }
1345} 1305}
1346 1306
1347static void intel_destroy_plane(struct drm_plane *plane)
1348{
1349 struct intel_plane *intel_plane = to_intel_plane(plane);
1350 intel_disable_plane(plane);
1351 drm_plane_cleanup(plane);
1352 kfree(intel_plane);
1353}
1354
1355int intel_sprite_set_colorkey(struct drm_device *dev, void *data, 1307int intel_sprite_set_colorkey(struct drm_device *dev, void *data,
1356 struct drm_file *file_priv) 1308 struct drm_file *file_priv)
1357{ 1309{
@@ -1439,23 +1391,23 @@ int intel_plane_set_property(struct drm_plane *plane,
1439 1391
1440int intel_plane_restore(struct drm_plane *plane) 1392int intel_plane_restore(struct drm_plane *plane)
1441{ 1393{
1442 struct intel_plane *intel_plane = to_intel_plane(plane);
1443
1444 if (!plane->crtc || !plane->fb) 1394 if (!plane->crtc || !plane->fb)
1445 return 0; 1395 return 0;
1446 1396
1447 return plane->funcs->update_plane(plane, plane->crtc, plane->fb, 1397 return plane->funcs->update_plane(plane, plane->crtc, plane->fb,
1448 intel_plane->crtc_x, intel_plane->crtc_y, 1398 plane->state->crtc_x, plane->state->crtc_y,
1449 intel_plane->crtc_w, intel_plane->crtc_h, 1399 plane->state->crtc_w, plane->state->crtc_h,
1450 intel_plane->src_x, intel_plane->src_y, 1400 plane->state->src_x, plane->state->src_y,
1451 intel_plane->src_w, intel_plane->src_h); 1401 plane->state->src_w, plane->state->src_h);
1452} 1402}
1453 1403
1454static const struct drm_plane_funcs intel_plane_funcs = { 1404static const struct drm_plane_funcs intel_sprite_plane_funcs = {
1455 .update_plane = intel_update_plane, 1405 .update_plane = drm_plane_helper_update,
1456 .disable_plane = intel_disable_plane, 1406 .disable_plane = drm_plane_helper_disable,
1457 .destroy = intel_destroy_plane, 1407 .destroy = intel_plane_destroy,
1458 .set_property = intel_plane_set_property, 1408 .set_property = intel_plane_set_property,
1409 .atomic_duplicate_state = intel_plane_duplicate_state,
1410 .atomic_destroy_state = intel_plane_destroy_state,
1459}; 1411};
1460 1412
1461static uint32_t ilk_plane_formats[] = { 1413static uint32_t ilk_plane_formats[] = {
@@ -1517,6 +1469,13 @@ intel_plane_init(struct drm_device *dev, enum pipe pipe, int plane)
1517 if (!intel_plane) 1469 if (!intel_plane)
1518 return -ENOMEM; 1470 return -ENOMEM;
1519 1471
1472 intel_plane->base.state =
1473 intel_plane_duplicate_state(&intel_plane->base);
1474 if (intel_plane->base.state == NULL) {
1475 kfree(intel_plane);
1476 return -ENOMEM;
1477 }
1478
1520 switch (INTEL_INFO(dev)->gen) { 1479 switch (INTEL_INFO(dev)->gen) {
1521 case 5: 1480 case 5:
1522 case 6: 1481 case 6:
@@ -1591,7 +1550,7 @@ intel_plane_init(struct drm_device *dev, enum pipe pipe, int plane)
1591 intel_plane->commit_plane = intel_commit_sprite_plane; 1550 intel_plane->commit_plane = intel_commit_sprite_plane;
1592 possible_crtcs = (1 << pipe); 1551 possible_crtcs = (1 << pipe);
1593 ret = drm_universal_plane_init(dev, &intel_plane->base, possible_crtcs, 1552 ret = drm_universal_plane_init(dev, &intel_plane->base, possible_crtcs,
1594 &intel_plane_funcs, 1553 &intel_sprite_plane_funcs,
1595 plane_formats, num_plane_formats, 1554 plane_formats, num_plane_formats,
1596 DRM_PLANE_TYPE_OVERLAY); 1555 DRM_PLANE_TYPE_OVERLAY);
1597 if (ret) { 1556 if (ret) {
@@ -1610,6 +1569,8 @@ intel_plane_init(struct drm_device *dev, enum pipe pipe, int plane)
1610 dev->mode_config.rotation_property, 1569 dev->mode_config.rotation_property,
1611 intel_plane->rotation); 1570 intel_plane->rotation);
1612 1571
1572 drm_plane_helper_add(&intel_plane->base, &intel_plane_helper_funcs);
1573
1613 out: 1574 out:
1614 return ret; 1575 return ret;
1615} 1576}
diff --git a/include/drm/i915_component.h b/include/drm/i915_component.h
new file mode 100644
index 000000000000..3e2f22e5bf3c
--- /dev/null
+++ b/include/drm/i915_component.h
@@ -0,0 +1,38 @@
1/*
2 * Copyright © 2014 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
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24#ifndef _I915_COMPONENT_H_
25#define _I915_COMPONENT_H_
26
27struct i915_audio_component {
28 struct device *dev;
29
30 const struct i915_audio_component_ops {
31 struct module *owner;
32 void (*get_power)(struct device *);
33 void (*put_power)(struct device *);
34 int (*get_cdclk_freq)(struct device *);
35 } *ops;
36};
37
38#endif /* _I915_COMPONENT_H_ */
diff --git a/include/drm/i915_powerwell.h b/include/drm/i915_powerwell.h
deleted file mode 100644
index baa6f11b1837..000000000000
--- a/include/drm/i915_powerwell.h
+++ /dev/null
@@ -1,37 +0,0 @@
1/**************************************************************************
2 *
3 * Copyright 2013 Intel Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 * USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 *
27 **************************************************************************/
28
29#ifndef _I915_POWERWELL_H_
30#define _I915_POWERWELL_H_
31
32/* For use by hda_i915 driver */
33extern int i915_request_power_well(void);
34extern int i915_release_power_well(void);
35extern int i915_get_cdclk_freq(void);
36
37#endif /* _I915_POWERWELL_H_ */
diff --git a/include/uapi/drm/i915_drm.h b/include/uapi/drm/i915_drm.h
index 250262265ee3..2e559f6e699e 100644
--- a/include/uapi/drm/i915_drm.h
+++ b/include/uapi/drm/i915_drm.h
@@ -224,6 +224,8 @@ typedef struct _drm_i915_sarea {
224#define DRM_I915_REG_READ 0x31 224#define DRM_I915_REG_READ 0x31
225#define DRM_I915_GET_RESET_STATS 0x32 225#define DRM_I915_GET_RESET_STATS 0x32
226#define DRM_I915_GEM_USERPTR 0x33 226#define DRM_I915_GEM_USERPTR 0x33
227#define DRM_I915_GEM_CONTEXT_GETPARAM 0x34
228#define DRM_I915_GEM_CONTEXT_SETPARAM 0x35
227 229
228#define DRM_IOCTL_I915_INIT DRM_IOW( DRM_COMMAND_BASE + DRM_I915_INIT, drm_i915_init_t) 230#define DRM_IOCTL_I915_INIT DRM_IOW( DRM_COMMAND_BASE + DRM_I915_INIT, drm_i915_init_t)
229#define DRM_IOCTL_I915_FLUSH DRM_IO ( DRM_COMMAND_BASE + DRM_I915_FLUSH) 231#define DRM_IOCTL_I915_FLUSH DRM_IO ( DRM_COMMAND_BASE + DRM_I915_FLUSH)
@@ -275,6 +277,8 @@ typedef struct _drm_i915_sarea {
275#define DRM_IOCTL_I915_REG_READ DRM_IOWR (DRM_COMMAND_BASE + DRM_I915_REG_READ, struct drm_i915_reg_read) 277#define DRM_IOCTL_I915_REG_READ DRM_IOWR (DRM_COMMAND_BASE + DRM_I915_REG_READ, struct drm_i915_reg_read)
276#define DRM_IOCTL_I915_GET_RESET_STATS DRM_IOWR (DRM_COMMAND_BASE + DRM_I915_GET_RESET_STATS, struct drm_i915_reset_stats) 278#define DRM_IOCTL_I915_GET_RESET_STATS DRM_IOWR (DRM_COMMAND_BASE + DRM_I915_GET_RESET_STATS, struct drm_i915_reset_stats)
277#define DRM_IOCTL_I915_GEM_USERPTR DRM_IOWR (DRM_COMMAND_BASE + DRM_I915_GEM_USERPTR, struct drm_i915_gem_userptr) 279#define DRM_IOCTL_I915_GEM_USERPTR DRM_IOWR (DRM_COMMAND_BASE + DRM_I915_GEM_USERPTR, struct drm_i915_gem_userptr)
280#define DRM_IOCTL_I915_GEM_CONTEXT_GETPARAM DRM_IOWR (DRM_COMMAND_BASE + DRM_I915_GEM_CONTEXT_GETPARAM, struct drm_i915_gem_context_param)
281#define DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM DRM_IOWR (DRM_COMMAND_BASE + DRM_I915_GEM_CONTEXT_SETPARAM, struct drm_i915_gem_context_param)
278 282
279/* Allow drivers to submit batchbuffers directly to hardware, relying 283/* Allow drivers to submit batchbuffers directly to hardware, relying
280 * on the security mechanisms provided by hardware. 284 * on the security mechanisms provided by hardware.
@@ -341,6 +345,7 @@ typedef struct drm_i915_irq_wait {
341#define I915_PARAM_HAS_WT 27 345#define I915_PARAM_HAS_WT 27
342#define I915_PARAM_CMD_PARSER_VERSION 28 346#define I915_PARAM_CMD_PARSER_VERSION 28
343#define I915_PARAM_HAS_COHERENT_PHYS_GTT 29 347#define I915_PARAM_HAS_COHERENT_PHYS_GTT 29
348#define I915_PARAM_MMAP_VERSION 30
344 349
345typedef struct drm_i915_getparam { 350typedef struct drm_i915_getparam {
346 int param; 351 int param;
@@ -488,6 +493,14 @@ struct drm_i915_gem_mmap {
488 * This is a fixed-size type for 32/64 compatibility. 493 * This is a fixed-size type for 32/64 compatibility.
489 */ 494 */
490 __u64 addr_ptr; 495 __u64 addr_ptr;
496
497 /**
498 * Flags for extended behaviour.
499 *
500 * Added in version 2.
501 */
502 __u64 flags;
503#define I915_MMAP_WC 0x1
491}; 504};
492 505
493struct drm_i915_gem_mmap_gtt { 506struct drm_i915_gem_mmap_gtt {
@@ -1073,4 +1086,12 @@ struct drm_i915_gem_userptr {
1073 __u32 handle; 1086 __u32 handle;
1074}; 1087};
1075 1088
1089struct drm_i915_gem_context_param {
1090 __u32 ctx_id;
1091 __u32 size;
1092 __u64 param;
1093#define I915_CONTEXT_PARAM_BAN_PERIOD 0x1
1094 __u64 value;
1095};
1096
1076#endif /* _UAPI_I915_DRM_H_ */ 1097#endif /* _UAPI_I915_DRM_H_ */
diff --git a/sound/pci/hda/hda_i915.c b/sound/pci/hda/hda_i915.c
index d4d0375ac181..714894527e06 100644
--- a/sound/pci/hda/hda_i915.c
+++ b/sound/pci/hda/hda_i915.c
@@ -18,10 +18,12 @@
18 18
19#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/pci.h>
22#include <linux/component.h>
23#include <drm/i915_component.h>
21#include <sound/core.h> 24#include <sound/core.h>
22#include <drm/i915_powerwell.h>
23#include "hda_priv.h" 25#include "hda_priv.h"
24#include "hda_i915.h" 26#include "hda_intel.h"
25 27
26/* Intel HSW/BDW display HDA controller Extended Mode registers. 28/* Intel HSW/BDW display HDA controller Extended Mode registers.
27 * EM4 (M value) and EM5 (N Value) are used to convert CDClk (Core Display 29 * EM4 (M value) and EM5 (N Value) are used to convert CDClk (Core Display
@@ -31,32 +33,33 @@
31#define AZX_REG_EM4 0x100c 33#define AZX_REG_EM4 0x100c
32#define AZX_REG_EM5 0x1010 34#define AZX_REG_EM5 0x1010
33 35
34static int (*get_power)(void); 36int hda_display_power(struct hda_intel *hda, bool enable)
35static int (*put_power)(void);
36static int (*get_cdclk)(void);
37
38int hda_display_power(bool enable)
39{ 37{
40 if (!get_power || !put_power) 38 struct i915_audio_component *acomp = &hda->audio_component;
39
40 if (!acomp->ops)
41 return -ENODEV; 41 return -ENODEV;
42 42
43 pr_debug("HDA display power %s \n", 43 dev_dbg(&hda->chip.pci->dev, "display power %s\n",
44 enable ? "Enable" : "Disable"); 44 enable ? "enable" : "disable");
45 if (enable) 45 if (enable)
46 return get_power(); 46 acomp->ops->get_power(acomp->dev);
47 else 47 else
48 return put_power(); 48 acomp->ops->put_power(acomp->dev);
49
50 return 0;
49} 51}
50 52
51void haswell_set_bclk(struct azx *chip) 53void haswell_set_bclk(struct hda_intel *hda)
52{ 54{
53 int cdclk_freq; 55 int cdclk_freq;
54 unsigned int bclk_m, bclk_n; 56 unsigned int bclk_m, bclk_n;
57 struct i915_audio_component *acomp = &hda->audio_component;
55 58
56 if (!get_cdclk) 59 if (!acomp->ops)
57 return; 60 return;
58 61
59 cdclk_freq = get_cdclk(); 62 cdclk_freq = acomp->ops->get_cdclk_freq(acomp->dev);
60 switch (cdclk_freq) { 63 switch (cdclk_freq) {
61 case 337500: 64 case 337500:
62 bclk_m = 16; 65 bclk_m = 16;
@@ -80,51 +83,108 @@ void haswell_set_bclk(struct azx *chip)
80 break; 83 break;
81 } 84 }
82 85
83 azx_writew(chip, EM4, bclk_m); 86 azx_writew(&hda->chip, EM4, bclk_m);
84 azx_writew(chip, EM5, bclk_n); 87 azx_writew(&hda->chip, EM5, bclk_n);
85} 88}
86 89
87 90static int hda_component_master_bind(struct device *dev)
88int hda_i915_init(void)
89{ 91{
90 int err = 0; 92 struct snd_card *card = dev_get_drvdata(dev);
91 93 struct azx *chip = card->private_data;
92 get_power = symbol_request(i915_request_power_well); 94 struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
93 if (!get_power) { 95 struct i915_audio_component *acomp = &hda->audio_component;
94 pr_warn("hda-i915: get_power symbol get fail\n"); 96 int ret;
95 return -ENODEV; 97
98 ret = component_bind_all(dev, acomp);
99 if (ret < 0)
100 return ret;
101
102 if (WARN_ON(!(acomp->dev && acomp->ops && acomp->ops->get_power &&
103 acomp->ops->put_power && acomp->ops->get_cdclk_freq))) {
104 ret = -EINVAL;
105 goto out_unbind;
96 } 106 }
97 107
98 put_power = symbol_request(i915_release_power_well); 108 /*
99 if (!put_power) { 109 * Atm, we don't support dynamic unbinding initiated by the child
100 symbol_put(i915_request_power_well); 110 * component, so pin its containing module until we unbind.
101 get_power = NULL; 111 */
102 return -ENODEV; 112 if (!try_module_get(acomp->ops->owner)) {
113 ret = -ENODEV;
114 goto out_unbind;
103 } 115 }
104 116
105 get_cdclk = symbol_request(i915_get_cdclk_freq); 117 return 0;
106 if (!get_cdclk) /* may have abnormal BCLK and audio playback rate */
107 pr_warn("hda-i915: get_cdclk symbol get fail\n");
108 118
109 pr_debug("HDA driver get symbol successfully from i915 module\n"); 119out_unbind:
120 component_unbind_all(dev, acomp);
110 121
111 return err; 122 return ret;
112} 123}
113 124
114int hda_i915_exit(void) 125static void hda_component_master_unbind(struct device *dev)
115{ 126{
116 if (get_power) { 127 struct snd_card *card = dev_get_drvdata(dev);
117 symbol_put(i915_request_power_well); 128 struct azx *chip = card->private_data;
118 get_power = NULL; 129 struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
119 } 130 struct i915_audio_component *acomp = &hda->audio_component;
120 if (put_power) { 131
121 symbol_put(i915_release_power_well); 132 module_put(acomp->ops->owner);
122 put_power = NULL; 133 component_unbind_all(dev, acomp);
123 } 134 WARN_ON(acomp->ops || acomp->dev);
124 if (get_cdclk) { 135}
125 symbol_put(i915_get_cdclk_freq); 136
126 get_cdclk = NULL; 137static const struct component_master_ops hda_component_master_ops = {
138 .bind = hda_component_master_bind,
139 .unbind = hda_component_master_unbind,
140};
141
142static int hda_component_master_match(struct device *dev, void *data)
143{
144 /* i915 is the only supported component */
145 return !strcmp(dev->driver->name, "i915");
146}
147
148int hda_i915_init(struct hda_intel *hda)
149{
150 struct component_match *match = NULL;
151 struct device *dev = &hda->chip.pci->dev;
152 struct i915_audio_component *acomp = &hda->audio_component;
153 int ret;
154
155 component_match_add(dev, &match, hda_component_master_match, hda);
156 ret = component_master_add_with_match(dev, &hda_component_master_ops,
157 match);
158 if (ret < 0)
159 goto out_err;
160
161 /*
162 * Atm, we don't support deferring the component binding, so make sure
163 * i915 is loaded and that the binding successfully completes.
164 */
165 request_module("i915");
166
167 if (!acomp->ops) {
168 ret = -ENODEV;
169 goto out_master_del;
127 } 170 }
128 171
172 dev_dbg(dev, "bound to i915 component master\n");
173
174 return 0;
175out_master_del:
176 component_master_del(dev, &hda_component_master_ops);
177out_err:
178 dev_err(dev, "failed to add i915 component master (%d)\n", ret);
179
180 return ret;
181}
182
183int hda_i915_exit(struct hda_intel *hda)
184{
185 struct device *dev = &hda->chip.pci->dev;
186
187 component_master_del(dev, &hda_component_master_ops);
188
129 return 0; 189 return 0;
130} 190}
diff --git a/sound/pci/hda/hda_i915.h b/sound/pci/hda/hda_i915.h
deleted file mode 100644
index e6072c627583..000000000000
--- a/sound/pci/hda/hda_i915.h
+++ /dev/null
@@ -1,37 +0,0 @@
1/*
2 * This program is free software; you can redistribute it and/or modify it
3 * under the terms of the GNU General Public License as published by the Free
4 * Software Foundation; either version 2 of the License, or (at your option)
5 * any later version.
6 *
7 * This program is distributed in the hope that it will be useful, but WITHOUT
8 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
10 * more details.
11 *
12 * You should have received a copy of the GNU General Public License along with
13 * this program; if not, write to the Free Software Foundation, Inc., 59
14 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15 */
16#ifndef __SOUND_HDA_I915_H
17#define __SOUND_HDA_I915_H
18
19#ifdef CONFIG_SND_HDA_I915
20int hda_display_power(bool enable);
21void haswell_set_bclk(struct azx *chip);
22int hda_i915_init(void);
23int hda_i915_exit(void);
24#else
25static inline int hda_display_power(bool enable) { return 0; }
26static inline void haswell_set_bclk(struct azx *chip) { return; }
27static inline int hda_i915_init(void)
28{
29 return -ENODEV;
30}
31static inline int hda_i915_exit(void)
32{
33 return 0;
34}
35#endif
36
37#endif
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index d426a0bd6a5f..95a539993990 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -63,7 +63,7 @@
63#include "hda_codec.h" 63#include "hda_codec.h"
64#include "hda_controller.h" 64#include "hda_controller.h"
65#include "hda_priv.h" 65#include "hda_priv.h"
66#include "hda_i915.h" 66#include "hda_intel.h"
67 67
68/* position fix mode */ 68/* position fix mode */
69enum { 69enum {
@@ -354,31 +354,6 @@ static char *driver_short_names[] = {
354 [AZX_DRIVER_GENERIC] = "HD-Audio Generic", 354 [AZX_DRIVER_GENERIC] = "HD-Audio Generic",
355}; 355};
356 356
357struct hda_intel {
358 struct azx chip;
359
360 /* for pending irqs */
361 struct work_struct irq_pending_work;
362
363 /* sync probing */
364 struct completion probe_wait;
365 struct work_struct probe_work;
366
367 /* card list (for power_save trigger) */
368 struct list_head list;
369
370 /* extra flags */
371 unsigned int irq_pending_warned:1;
372
373 /* VGA-switcheroo setup */
374 unsigned int use_vga_switcheroo:1;
375 unsigned int vga_switcheroo_registered:1;
376 unsigned int init_failed:1; /* delayed init failed */
377
378 /* secondary power domain for hdmi audio under vga device */
379 struct dev_pm_domain hdmi_pm_domain;
380};
381
382#ifdef CONFIG_X86 357#ifdef CONFIG_X86
383static void __mark_pages_wc(struct azx *chip, struct snd_dma_buffer *dmab, bool on) 358static void __mark_pages_wc(struct azx *chip, struct snd_dma_buffer *dmab, bool on)
384{ 359{
@@ -828,7 +803,7 @@ static int azx_suspend(struct device *dev)
828 pci_save_state(pci); 803 pci_save_state(pci);
829 pci_set_power_state(pci, PCI_D3hot); 804 pci_set_power_state(pci, PCI_D3hot);
830 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) 805 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL)
831 hda_display_power(false); 806 hda_display_power(hda, false);
832 return 0; 807 return 0;
833} 808}
834 809
@@ -848,8 +823,8 @@ static int azx_resume(struct device *dev)
848 return 0; 823 return 0;
849 824
850 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) { 825 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) {
851 hda_display_power(true); 826 hda_display_power(hda, true);
852 haswell_set_bclk(chip); 827 haswell_set_bclk(hda);
853 } 828 }
854 pci_set_power_state(pci, PCI_D0); 829 pci_set_power_state(pci, PCI_D0);
855 pci_restore_state(pci); 830 pci_restore_state(pci);
@@ -901,7 +876,7 @@ static int azx_runtime_suspend(struct device *dev)
901 azx_enter_link_reset(chip); 876 azx_enter_link_reset(chip);
902 azx_clear_irq_pending(chip); 877 azx_clear_irq_pending(chip);
903 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) 878 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL)
904 hda_display_power(false); 879 hda_display_power(hda, false);
905 880
906 return 0; 881 return 0;
907} 882}
@@ -927,8 +902,8 @@ static int azx_runtime_resume(struct device *dev)
927 return 0; 902 return 0;
928 903
929 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) { 904 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) {
930 hda_display_power(true); 905 hda_display_power(hda, true);
931 haswell_set_bclk(chip); 906 haswell_set_bclk(hda);
932 } 907 }
933 908
934 /* Read STATESTS before controller reset */ 909 /* Read STATESTS before controller reset */
@@ -1150,8 +1125,8 @@ static int azx_free(struct azx *chip)
1150 release_firmware(chip->fw); 1125 release_firmware(chip->fw);
1151#endif 1126#endif
1152 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) { 1127 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) {
1153 hda_display_power(false); 1128 hda_display_power(hda, false);
1154 hda_i915_exit(); 1129 hda_i915_exit(hda);
1155 } 1130 }
1156 kfree(hda); 1131 kfree(hda);
1157 1132
@@ -1629,8 +1604,12 @@ static int azx_first_init(struct azx *chip)
1629 /* initialize chip */ 1604 /* initialize chip */
1630 azx_init_pci(chip); 1605 azx_init_pci(chip);
1631 1606
1632 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) 1607 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) {
1633 haswell_set_bclk(chip); 1608 struct hda_intel *hda;
1609
1610 hda = container_of(chip, struct hda_intel, chip);
1611 haswell_set_bclk(hda);
1612 }
1634 1613
1635 azx_init_chip(chip, (probe_only[dev] & 2) == 0); 1614 azx_init_chip(chip, (probe_only[dev] & 2) == 0);
1636 1615
@@ -1910,13 +1889,10 @@ static int azx_probe_continue(struct azx *chip)
1910 /* Request power well for Haswell HDA controller and codec */ 1889 /* Request power well for Haswell HDA controller and codec */
1911 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) { 1890 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) {
1912#ifdef CONFIG_SND_HDA_I915 1891#ifdef CONFIG_SND_HDA_I915
1913 err = hda_i915_init(); 1892 err = hda_i915_init(hda);
1914 if (err < 0) { 1893 if (err < 0)
1915 dev_err(chip->card->dev,
1916 "Error request power-well from i915\n");
1917 goto out_free; 1894 goto out_free;
1918 } 1895 err = hda_display_power(hda, true);
1919 err = hda_display_power(true);
1920 if (err < 0) { 1896 if (err < 0) {
1921 dev_err(chip->card->dev, 1897 dev_err(chip->card->dev,
1922 "Cannot turn on display power on i915\n"); 1898 "Cannot turn on display power on i915\n");
diff --git a/sound/pci/hda/hda_intel.h b/sound/pci/hda/hda_intel.h
new file mode 100644
index 000000000000..348611835476
--- /dev/null
+++ b/sound/pci/hda/hda_intel.h
@@ -0,0 +1,71 @@
1/*
2 * This program is free software; you can redistribute it and/or modify it
3 * under the terms of the GNU General Public License as published by the Free
4 * Software Foundation; either version 2 of the License, or (at your option)
5 * any later version.
6 *
7 * This program is distributed in the hope that it will be useful, but WITHOUT
8 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
10 * more details.
11 *
12 * You should have received a copy of the GNU General Public License along with
13 * this program; if not, write to the Free Software Foundation, Inc., 59
14 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15 */
16#ifndef __SOUND_HDA_INTEL_H
17#define __SOUND_HDA_INTEL_H
18
19#include <drm/i915_component.h>
20#include "hda_priv.h"
21
22struct hda_intel {
23 struct azx chip;
24
25 /* for pending irqs */
26 struct work_struct irq_pending_work;
27
28 /* sync probing */
29 struct completion probe_wait;
30 struct work_struct probe_work;
31
32 /* card list (for power_save trigger) */
33 struct list_head list;
34
35 /* extra flags */
36 unsigned int irq_pending_warned:1;
37
38 /* VGA-switcheroo setup */
39 unsigned int use_vga_switcheroo:1;
40 unsigned int vga_switcheroo_registered:1;
41 unsigned int init_failed:1; /* delayed init failed */
42
43 /* secondary power domain for hdmi audio under vga device */
44 struct dev_pm_domain hdmi_pm_domain;
45
46 /* i915 component interface */
47 struct i915_audio_component audio_component;
48};
49
50#ifdef CONFIG_SND_HDA_I915
51int hda_display_power(struct hda_intel *hda, bool enable);
52void haswell_set_bclk(struct hda_intel *hda);
53int hda_i915_init(struct hda_intel *hda);
54int hda_i915_exit(struct hda_intel *hda);
55#else
56static inline int hda_display_power(struct hda_intel *hda, bool enable)
57{
58 return 0;
59}
60static inline void haswell_set_bclk(struct hda_intel *hda) { return; }
61static inline int hda_i915_init(struct hda_intel *hda)
62{
63 return -ENODEV;
64}
65static inline int hda_i915_exit(struct hda_intel *hda)
66{
67 return 0;
68}
69#endif
70
71#endif