blob: ca02855435d92fe9ad8e867941d58c851a51feb2 [file] [log] [blame]
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001/*
2 * Copyright © 2011 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 *
23 * Authors:
24 * Jesse Barnes <jbarnes@virtuousgeek.org>
25 *
26 * New plane/sprite handling.
27 *
28 * The older chips had a separate interface for programming plane related
29 * registers; newer ones are much simpler and we can use the new DRM plane
30 * support.
31 */
David Howells760285e2012-10-02 18:01:07 +010032#include <drm/drmP.h>
33#include <drm/drm_crtc.h>
34#include <drm/drm_fourcc.h>
Ville Syrjälä17316932013-04-24 18:52:38 +030035#include <drm/drm_rect.h>
Chandra Konduruc3318792015-04-15 15:15:02 -070036#include <drm/drm_atomic.h>
Matt Roperea2c67b2014-12-23 10:41:52 -080037#include <drm/drm_plane_helper.h>
Jesse Barnesb840d907f2011-12-13 13:19:38 -080038#include "intel_drv.h"
Chris Wilson5d723d72016-08-04 16:32:35 +010039#include "intel_frontbuffer.h"
David Howells760285e2012-10-02 18:01:07 +010040#include <drm/i915_drm.h>
Jesse Barnesb840d907f2011-12-13 13:19:38 -080041#include "i915_drv.h"
42
Ville Syrjälä6ca2aeb2014-10-20 19:47:53 +030043static bool
44format_is_yuv(uint32_t format)
45{
46 switch (format) {
47 case DRM_FORMAT_YUYV:
48 case DRM_FORMAT_UYVY:
49 case DRM_FORMAT_VYUY:
50 case DRM_FORMAT_YVYU:
51 return true;
52 default:
53 return false;
54 }
55}
56
Ville Syrjälädfd2e9a2016-05-18 11:34:38 +030057int intel_usecs_to_scanlines(const struct drm_display_mode *adjusted_mode,
58 int usecs)
Ville Syrjälä8d7849d2014-04-29 13:35:46 +030059{
60 /* paranoia */
Ville Syrjälä5e7234c2015-09-25 16:37:43 +030061 if (!adjusted_mode->crtc_htotal)
Ville Syrjälä8d7849d2014-04-29 13:35:46 +030062 return 1;
63
Ville Syrjälä5e7234c2015-09-25 16:37:43 +030064 return DIV_ROUND_UP(usecs * adjusted_mode->crtc_clock,
65 1000 * adjusted_mode->crtc_htotal);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +030066}
67
Ander Conselvan de Oliveira26ff2762014-10-28 15:10:12 +020068/**
69 * intel_pipe_update_start() - start update of a set of display registers
70 * @crtc: the crtc of which the registers are going to be updated
71 * @start_vbl_count: vblank counter return pointer used for error checking
72 *
73 * Mark the start of an update to pipe registers that should be updated
74 * atomically regarding vblank. If the next vblank will happens within
75 * the next 100 us, this function waits until the vblank passes.
76 *
77 * After a successful call to this function, interrupts will be disabled
78 * until a subsequent call to intel_pipe_update_end(). That is done to
79 * avoid random delays. The value written to @start_vbl_count should be
80 * supplied to intel_pipe_update_end() for error checking.
Ander Conselvan de Oliveira26ff2762014-10-28 15:10:12 +020081 */
Maarten Lankhorst34e0adb2015-08-31 13:04:25 +020082void intel_pipe_update_start(struct intel_crtc *crtc)
Ville Syrjälä8d7849d2014-04-29 13:35:46 +030083{
Ville Syrjälä124abe02015-09-08 13:40:45 +030084 const struct drm_display_mode *adjusted_mode = &crtc->config->base.adjusted_mode;
Ville Syrjälä8d7849d2014-04-29 13:35:46 +030085 long timeout = msecs_to_jiffies_timeout(1);
86 int scanline, min, max, vblank_start;
Ville Syrjälä210871b62014-05-22 19:00:50 +030087 wait_queue_head_t *wq = drm_crtc_vblank_waitqueue(&crtc->base);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +030088 DEFINE_WAIT(wait);
89
Ville Syrjälä124abe02015-09-08 13:40:45 +030090 vblank_start = adjusted_mode->crtc_vblank_start;
91 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
Ville Syrjälä8d7849d2014-04-29 13:35:46 +030092 vblank_start = DIV_ROUND_UP(vblank_start, 2);
93
94 /* FIXME needs to be calibrated sensibly */
Ville Syrjälädfd2e9a2016-05-18 11:34:38 +030095 min = vblank_start - intel_usecs_to_scanlines(adjusted_mode, 100);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +030096 max = vblank_start - 1;
97
Maarten Lankhorst8f539a832015-07-13 16:30:32 +020098 local_irq_disable();
Maarten Lankhorst8f539a832015-07-13 16:30:32 +020099
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300100 if (min <= 0 || max <= 0)
Maarten Lankhorst8f539a832015-07-13 16:30:32 +0200101 return;
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300102
Daniel Vetter1e3feef2015-02-13 21:03:45 +0100103 if (WARN_ON(drm_crtc_vblank_get(&crtc->base)))
Maarten Lankhorst8f539a832015-07-13 16:30:32 +0200104 return;
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300105
Jesse Barnesd637ce32015-09-17 08:08:32 -0700106 crtc->debug.min_vbl = min;
107 crtc->debug.max_vbl = max;
108 trace_i915_pipe_update_start(crtc);
Ville Syrjälä25ef2842014-04-29 13:35:48 +0300109
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300110 for (;;) {
111 /*
112 * prepare_to_wait() has a memory barrier, which guarantees
113 * other CPUs can see the task state update by the time we
114 * read the scanline.
115 */
Ville Syrjälä210871b62014-05-22 19:00:50 +0300116 prepare_to_wait(wq, &wait, TASK_UNINTERRUPTIBLE);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300117
118 scanline = intel_get_crtc_scanline(crtc);
119 if (scanline < min || scanline > max)
120 break;
121
122 if (timeout <= 0) {
123 DRM_ERROR("Potential atomic update failure on pipe %c\n",
124 pipe_name(crtc->pipe));
125 break;
126 }
127
128 local_irq_enable();
129
130 timeout = schedule_timeout(timeout);
131
132 local_irq_disable();
133 }
134
Ville Syrjälä210871b62014-05-22 19:00:50 +0300135 finish_wait(wq, &wait);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300136
Daniel Vetter1e3feef2015-02-13 21:03:45 +0100137 drm_crtc_vblank_put(&crtc->base);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300138
Jesse Barneseb120ef2015-09-15 14:19:32 -0700139 crtc->debug.scanline_start = scanline;
140 crtc->debug.start_vbl_time = ktime_get();
Maarten Lankhorsta2991412016-05-17 15:07:48 +0200141 crtc->debug.start_vbl_count = intel_crtc_get_vblank_counter(crtc);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300142
Jesse Barnesd637ce32015-09-17 08:08:32 -0700143 trace_i915_pipe_update_vblank_evaded(crtc);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300144}
145
Ander Conselvan de Oliveira26ff2762014-10-28 15:10:12 +0200146/**
147 * intel_pipe_update_end() - end update of a set of display registers
148 * @crtc: the crtc of which the registers were updated
149 * @start_vbl_count: start vblank counter (used for error checking)
150 *
151 * Mark the end of an update started with intel_pipe_update_start(). This
152 * re-enables interrupts and verifies the update was actually completed
153 * before a vblank using the value of @start_vbl_count.
154 */
Maarten Lankhorst51cbaf02016-05-17 15:07:49 +0200155void intel_pipe_update_end(struct intel_crtc *crtc, struct intel_flip_work *work)
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300156{
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300157 enum pipe pipe = crtc->pipe;
Jesse Barneseb120ef2015-09-15 14:19:32 -0700158 int scanline_end = intel_get_crtc_scanline(crtc);
Maarten Lankhorsta2991412016-05-17 15:07:48 +0200159 u32 end_vbl_count = intel_crtc_get_vblank_counter(crtc);
Maarten Lankhorst85a62bf2015-09-01 12:15:33 +0200160 ktime_t end_vbl_time = ktime_get();
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300161
Maarten Lankhorst51cbaf02016-05-17 15:07:49 +0200162 if (work) {
163 work->flip_queued_vblank = end_vbl_count;
164 smp_mb__before_atomic();
165 atomic_set(&work->pending, 1);
166 }
167
Jesse Barnesd637ce32015-09-17 08:08:32 -0700168 trace_i915_pipe_update_end(crtc, end_vbl_count, scanline_end);
Ville Syrjälä25ef2842014-04-29 13:35:48 +0300169
Daniel Vetter1f7528c2016-06-13 16:13:45 +0200170 /* We're still in the vblank-evade critical section, this can't race.
171 * Would be slightly nice to just grab the vblank count and arm the
172 * event outside of the critical section - the spinlock might spin for a
173 * while ... */
174 if (crtc->base.state->event) {
175 WARN_ON(drm_crtc_vblank_get(&crtc->base) != 0);
176
177 spin_lock(&crtc->base.dev->event_lock);
178 drm_crtc_arm_vblank_event(&crtc->base, crtc->base.state->event);
179 spin_unlock(&crtc->base.dev->event_lock);
180
181 crtc->base.state->event = NULL;
182 }
183
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300184 local_irq_enable();
185
Jesse Barneseb120ef2015-09-15 14:19:32 -0700186 if (crtc->debug.start_vbl_count &&
187 crtc->debug.start_vbl_count != end_vbl_count) {
188 DRM_ERROR("Atomic update failure on pipe %c (start=%u end=%u) time %lld us, min %d, max %d, scanline start %d, end %d\n",
189 pipe_name(pipe), crtc->debug.start_vbl_count,
190 end_vbl_count,
191 ktime_us_delta(end_vbl_time, crtc->debug.start_vbl_time),
192 crtc->debug.min_vbl, crtc->debug.max_vbl,
193 crtc->debug.scanline_start, scanline_end);
194 }
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300195}
196
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800197static void
Maarten Lankhorst2fde1392016-01-07 11:54:06 +0100198skl_update_plane(struct drm_plane *drm_plane,
199 const struct intel_crtc_state *crtc_state,
200 const struct intel_plane_state *plane_state)
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000201{
202 struct drm_device *dev = drm_plane->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100203 struct drm_i915_private *dev_priv = to_i915(dev);
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000204 struct intel_plane *intel_plane = to_intel_plane(drm_plane);
Maarten Lankhorst2fde1392016-01-07 11:54:06 +0100205 struct drm_framebuffer *fb = plane_state->base.fb;
Lyude62e0fb82016-08-22 12:50:08 -0400206 const struct skl_wm_values *wm = &dev_priv->wm.skl_results;
207 struct drm_crtc *crtc = crtc_state->base.crtc;
208 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000209 const int pipe = intel_plane->pipe;
210 const int plane = intel_plane->plane + 1;
cpaul@redhat.comd8c0faf2016-10-18 16:09:49 -0200211 const struct skl_plane_wm *p_wm =
212 &crtc_state->wm.skl.optimal.planes[plane];
Ville Syrjäläd2196772016-01-28 18:33:11 +0200213 u32 plane_ctl;
Maarten Lankhorst2fde1392016-01-07 11:54:06 +0100214 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
Ville Syrjäläb63a16f2016-01-28 16:53:54 +0200215 u32 surf_addr = plane_state->main.offset;
Ville Syrjälä8d0deca2016-02-15 22:54:41 +0200216 unsigned int rotation = plane_state->base.rotation;
Ville Syrjäläd2196772016-01-28 18:33:11 +0200217 u32 stride = skl_plane_stride(fb, 0, rotation);
Ville Syrjälä936e71e2016-07-26 19:06:59 +0300218 int crtc_x = plane_state->base.dst.x1;
219 int crtc_y = plane_state->base.dst.y1;
220 uint32_t crtc_w = drm_rect_width(&plane_state->base.dst);
221 uint32_t crtc_h = drm_rect_height(&plane_state->base.dst);
Ville Syrjäläb63a16f2016-01-28 16:53:54 +0200222 uint32_t x = plane_state->main.x;
223 uint32_t y = plane_state->main.y;
Ville Syrjälä936e71e2016-07-26 19:06:59 +0300224 uint32_t src_w = drm_rect_width(&plane_state->base.src) >> 16;
225 uint32_t src_h = drm_rect_height(&plane_state->base.src) >> 16;
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000226
Ville Syrjälä48fe4692015-03-19 17:57:13 +0200227 plane_ctl = PLANE_CTL_ENABLE |
Bob Paauwee12c8ce2015-08-27 13:46:30 -0700228 PLANE_CTL_PIPE_GAMMA_ENABLE |
Ville Syrjälä48fe4692015-03-19 17:57:13 +0200229 PLANE_CTL_PIPE_CSC_ENABLE;
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000230
Chandra Konduruc3318792015-04-15 15:15:02 -0700231 plane_ctl |= skl_plane_ctl_format(fb->pixel_format);
Ville Syrjäläbae781b2016-11-16 13:33:16 +0200232 plane_ctl |= skl_plane_ctl_tiling(fb->modifier);
Damien Lespiaub3218032015-02-27 11:15:18 +0000233
Chandra Konduruc3318792015-04-15 15:15:02 -0700234 plane_ctl |= skl_plane_ctl_rotation(rotation);
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000235
Lyude62e0fb82016-08-22 12:50:08 -0400236 if (wm->dirty_pipes & drm_crtc_mask(crtc))
cpaul@redhat.comd8c0faf2016-10-18 16:09:49 -0200237 skl_write_plane_wm(intel_crtc, p_wm, &wm->ddb, plane);
Lyude62e0fb82016-08-22 12:50:08 -0400238
Ville Syrjälä47ecbb22015-03-19 21:18:57 +0200239 if (key->flags) {
240 I915_WRITE(PLANE_KEYVAL(pipe, plane), key->min_value);
241 I915_WRITE(PLANE_KEYMAX(pipe, plane), key->max_value);
242 I915_WRITE(PLANE_KEYMSK(pipe, plane), key->channel_mask);
243 }
244
245 if (key->flags & I915_SET_COLORKEY_DESTINATION)
246 plane_ctl |= PLANE_CTL_KEY_ENABLE_DESTINATION;
247 else if (key->flags & I915_SET_COLORKEY_SOURCE)
248 plane_ctl |= PLANE_CTL_KEY_ENABLE_SOURCE;
249
Ville Syrjälä6687c902015-09-15 13:16:41 +0300250 /* Sizes are 0 based */
251 src_w--;
252 src_h--;
253 crtc_w--;
254 crtc_h--;
255
256 I915_WRITE(PLANE_OFFSET(pipe, plane), (y << 16) | x);
Ville Syrjäläef78ec92015-10-13 22:48:39 +0300257 I915_WRITE(PLANE_STRIDE(pipe, plane), stride);
Ville Syrjälä6687c902015-09-15 13:16:41 +0300258 I915_WRITE(PLANE_SIZE(pipe, plane), (src_h << 16) | src_w);
Chandra Konduruc3318792015-04-15 15:15:02 -0700259
260 /* program plane scaler */
Maarten Lankhorst2fde1392016-01-07 11:54:06 +0100261 if (plane_state->scaler_id >= 0) {
Maarten Lankhorst2fde1392016-01-07 11:54:06 +0100262 int scaler_id = plane_state->scaler_id;
Imre Deak7494bcd2016-05-12 16:18:49 +0300263 const struct intel_scaler *scaler;
Chandra Konduruc3318792015-04-15 15:15:02 -0700264
265 DRM_DEBUG_KMS("plane = %d PS_PLANE_SEL(plane) = 0x%x\n", plane,
266 PS_PLANE_SEL(plane));
Imre Deak7494bcd2016-05-12 16:18:49 +0300267
268 scaler = &crtc_state->scaler_state.scalers[scaler_id];
269
270 I915_WRITE(SKL_PS_CTRL(pipe, scaler_id),
271 PS_SCALER_EN | PS_PLANE_SEL(plane) | scaler->mode);
Chandra Konduruc3318792015-04-15 15:15:02 -0700272 I915_WRITE(SKL_PS_PWR_GATE(pipe, scaler_id), 0);
273 I915_WRITE(SKL_PS_WIN_POS(pipe, scaler_id), (crtc_x << 16) | crtc_y);
274 I915_WRITE(SKL_PS_WIN_SZ(pipe, scaler_id),
275 ((crtc_w + 1) << 16)|(crtc_h + 1));
276
277 I915_WRITE(PLANE_POS(pipe, plane), 0);
278 } else {
279 I915_WRITE(PLANE_POS(pipe, plane), (crtc_y << 16) | crtc_x);
280 }
281
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000282 I915_WRITE(PLANE_CTL(pipe, plane), plane_ctl);
Ville Syrjälä6687c902015-09-15 13:16:41 +0300283 I915_WRITE(PLANE_SURF(pipe, plane),
284 intel_fb_gtt_offset(fb, rotation) + surf_addr);
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000285 POSTING_READ(PLANE_SURF(pipe, plane));
286}
287
288static void
Maarten Lankhorst7fabf5e2015-06-15 12:33:47 +0200289skl_disable_plane(struct drm_plane *dplane, struct drm_crtc *crtc)
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000290{
Maarten Lankhorsta8ad0d82015-04-21 17:12:51 +0300291 struct drm_device *dev = dplane->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100292 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorsta8ad0d82015-04-21 17:12:51 +0300293 struct intel_plane *intel_plane = to_intel_plane(dplane);
cpaul@redhat.comd8c0faf2016-10-18 16:09:49 -0200294 struct intel_crtc_state *cstate = to_intel_crtc_state(crtc->state);
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000295 const int pipe = intel_plane->pipe;
296 const int plane = intel_plane->plane + 1;
297
Lyudeccebc232016-08-29 12:31:27 -0400298 /*
299 * We only populate skl_results on watermark updates, and if the
300 * plane's visiblity isn't actually changing neither is its watermarks.
301 */
302 if (!dplane->state->visible)
303 skl_write_plane_wm(to_intel_crtc(crtc),
cpaul@redhat.comd8c0faf2016-10-18 16:09:49 -0200304 &cstate->wm.skl.optimal.planes[plane],
305 &dev_priv->wm.skl_results.ddb, plane);
Lyude62e0fb82016-08-22 12:50:08 -0400306
Ville Syrjälä48fe4692015-03-19 17:57:13 +0200307 I915_WRITE(PLANE_CTL(pipe, plane), 0);
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000308
Ville Syrjälä2ddc1da2015-03-19 17:57:14 +0200309 I915_WRITE(PLANE_SURF(pipe, plane), 0);
310 POSTING_READ(PLANE_SURF(pipe, plane));
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000311}
312
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000313static void
Ville Syrjälä6ca2aeb2014-10-20 19:47:53 +0300314chv_update_csc(struct intel_plane *intel_plane, uint32_t format)
315{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100316 struct drm_i915_private *dev_priv = to_i915(intel_plane->base.dev);
Ville Syrjälä6ca2aeb2014-10-20 19:47:53 +0300317 int plane = intel_plane->plane;
318
319 /* Seems RGB data bypasses the CSC always */
320 if (!format_is_yuv(format))
321 return;
322
323 /*
324 * BT.601 limited range YCbCr -> full range RGB
325 *
326 * |r| | 6537 4769 0| |cr |
327 * |g| = |-3330 4769 -1605| x |y-64|
328 * |b| | 0 4769 8263| |cb |
329 *
330 * Cb and Cr apparently come in as signed already, so no
331 * need for any offset. For Y we need to remove the offset.
332 */
333 I915_WRITE(SPCSCYGOFF(plane), SPCSC_OOFF(0) | SPCSC_IOFF(-64));
334 I915_WRITE(SPCSCCBOFF(plane), SPCSC_OOFF(0) | SPCSC_IOFF(0));
335 I915_WRITE(SPCSCCROFF(plane), SPCSC_OOFF(0) | SPCSC_IOFF(0));
336
337 I915_WRITE(SPCSCC01(plane), SPCSC_C1(4769) | SPCSC_C0(6537));
338 I915_WRITE(SPCSCC23(plane), SPCSC_C1(-3330) | SPCSC_C0(0));
339 I915_WRITE(SPCSCC45(plane), SPCSC_C1(-1605) | SPCSC_C0(4769));
340 I915_WRITE(SPCSCC67(plane), SPCSC_C1(4769) | SPCSC_C0(0));
341 I915_WRITE(SPCSCC8(plane), SPCSC_C0(8263));
342
343 I915_WRITE(SPCSCYGICLAMP(plane), SPCSC_IMAX(940) | SPCSC_IMIN(64));
344 I915_WRITE(SPCSCCBICLAMP(plane), SPCSC_IMAX(448) | SPCSC_IMIN(-448));
345 I915_WRITE(SPCSCCRICLAMP(plane), SPCSC_IMAX(448) | SPCSC_IMIN(-448));
346
347 I915_WRITE(SPCSCYGOCLAMP(plane), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
348 I915_WRITE(SPCSCCBOCLAMP(plane), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
349 I915_WRITE(SPCSCCROCLAMP(plane), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
350}
351
352static void
Maarten Lankhorst2fde1392016-01-07 11:54:06 +0100353vlv_update_plane(struct drm_plane *dplane,
354 const struct intel_crtc_state *crtc_state,
355 const struct intel_plane_state *plane_state)
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700356{
357 struct drm_device *dev = dplane->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100358 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700359 struct intel_plane *intel_plane = to_intel_plane(dplane);
Maarten Lankhorst2fde1392016-01-07 11:54:06 +0100360 struct drm_framebuffer *fb = plane_state->base.fb;
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700361 int pipe = intel_plane->pipe;
362 int plane = intel_plane->plane;
363 u32 sprctl;
Ville Syrjälä54ea9da2016-01-20 21:05:25 +0200364 u32 sprsurf_offset, linear_offset;
Ville Syrjälä8d0deca2016-02-15 22:54:41 +0200365 unsigned int rotation = dplane->state->rotation;
Maarten Lankhorst2fde1392016-01-07 11:54:06 +0100366 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
Ville Syrjälä936e71e2016-07-26 19:06:59 +0300367 int crtc_x = plane_state->base.dst.x1;
368 int crtc_y = plane_state->base.dst.y1;
369 uint32_t crtc_w = drm_rect_width(&plane_state->base.dst);
370 uint32_t crtc_h = drm_rect_height(&plane_state->base.dst);
371 uint32_t x = plane_state->base.src.x1 >> 16;
372 uint32_t y = plane_state->base.src.y1 >> 16;
373 uint32_t src_w = drm_rect_width(&plane_state->base.src) >> 16;
374 uint32_t src_h = drm_rect_height(&plane_state->base.src) >> 16;
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700375
Ville Syrjälä48fe4692015-03-19 17:57:13 +0200376 sprctl = SP_ENABLE;
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700377
378 switch (fb->pixel_format) {
379 case DRM_FORMAT_YUYV:
380 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YUYV;
381 break;
382 case DRM_FORMAT_YVYU:
383 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YVYU;
384 break;
385 case DRM_FORMAT_UYVY:
386 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_UYVY;
387 break;
388 case DRM_FORMAT_VYUY:
389 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_VYUY;
390 break;
391 case DRM_FORMAT_RGB565:
392 sprctl |= SP_FORMAT_BGR565;
393 break;
394 case DRM_FORMAT_XRGB8888:
395 sprctl |= SP_FORMAT_BGRX8888;
396 break;
397 case DRM_FORMAT_ARGB8888:
398 sprctl |= SP_FORMAT_BGRA8888;
399 break;
400 case DRM_FORMAT_XBGR2101010:
401 sprctl |= SP_FORMAT_RGBX1010102;
402 break;
403 case DRM_FORMAT_ABGR2101010:
404 sprctl |= SP_FORMAT_RGBA1010102;
405 break;
406 case DRM_FORMAT_XBGR8888:
407 sprctl |= SP_FORMAT_RGBX8888;
408 break;
409 case DRM_FORMAT_ABGR8888:
410 sprctl |= SP_FORMAT_RGBA8888;
411 break;
412 default:
413 /*
414 * If we get here one of the upper layers failed to filter
415 * out the unsupported plane formats
416 */
417 BUG();
418 break;
419 }
420
Ville Syrjälä4ea67bc2013-11-18 18:32:38 -0800421 /*
422 * Enable gamma to match primary/cursor plane behaviour.
423 * FIXME should be user controllable via propertiesa.
424 */
425 sprctl |= SP_GAMMA_ENABLE;
426
Ville Syrjäläbae781b2016-11-16 13:33:16 +0200427 if (fb->modifier == I915_FORMAT_MOD_X_TILED)
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700428 sprctl |= SP_TILED;
429
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700430 /* Sizes are 0 based */
431 src_w--;
432 src_h--;
433 crtc_w--;
434 crtc_h--;
435
Ville Syrjälä29490562016-01-20 18:02:50 +0200436 intel_add_fb_offsets(&x, &y, plane_state, 0);
437 sprsurf_offset = intel_compute_tile_offset(&x, &y, plane_state, 0);
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700438
Joonas Lahtinen31ad61e2016-07-29 08:50:05 +0300439 if (rotation == DRM_ROTATE_180) {
Ville Syrjälä76eebda2014-08-05 11:26:52 +0530440 sprctl |= SP_ROTATE_180;
441
442 x += src_w;
443 y += src_h;
Ville Syrjälä76eebda2014-08-05 11:26:52 +0530444 }
445
Ville Syrjälä29490562016-01-20 18:02:50 +0200446 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
Ville Syrjälä6687c902015-09-15 13:16:41 +0300447
Ville Syrjälä47ecbb22015-03-19 21:18:57 +0200448 if (key->flags) {
449 I915_WRITE(SPKEYMINVAL(pipe, plane), key->min_value);
450 I915_WRITE(SPKEYMAXVAL(pipe, plane), key->max_value);
451 I915_WRITE(SPKEYMSK(pipe, plane), key->channel_mask);
452 }
453
454 if (key->flags & I915_SET_COLORKEY_SOURCE)
455 sprctl |= SP_SOURCE_KEY;
456
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100457 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B)
Ville Syrjälä6ca2aeb2014-10-20 19:47:53 +0300458 chv_update_csc(intel_plane, fb->pixel_format);
459
Ville Syrjäläca6ad022014-01-17 20:09:03 +0200460 I915_WRITE(SPSTRIDE(pipe, plane), fb->pitches[0]);
461 I915_WRITE(SPPOS(pipe, plane), (crtc_y << 16) | crtc_x);
462
Ville Syrjäläbae781b2016-11-16 13:33:16 +0200463 if (fb->modifier == I915_FORMAT_MOD_X_TILED)
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700464 I915_WRITE(SPTILEOFF(pipe, plane), (y << 16) | x);
465 else
466 I915_WRITE(SPLINOFF(pipe, plane), linear_offset);
467
Ville Syrjäläc14b0482014-10-16 20:52:34 +0300468 I915_WRITE(SPCONSTALPHA(pipe, plane), 0);
469
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700470 I915_WRITE(SPSIZE(pipe, plane), (crtc_h << 16) | crtc_w);
471 I915_WRITE(SPCNTR(pipe, plane), sprctl);
Ville Syrjälä6687c902015-09-15 13:16:41 +0300472 I915_WRITE(SPSURF(pipe, plane),
473 intel_fb_gtt_offset(fb, rotation) + sprsurf_offset);
Ville Syrjäläb12ce1d2015-05-26 20:27:23 +0300474 POSTING_READ(SPSURF(pipe, plane));
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700475}
476
477static void
Maarten Lankhorst7fabf5e2015-06-15 12:33:47 +0200478vlv_disable_plane(struct drm_plane *dplane, struct drm_crtc *crtc)
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700479{
480 struct drm_device *dev = dplane->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100481 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700482 struct intel_plane *intel_plane = to_intel_plane(dplane);
483 int pipe = intel_plane->pipe;
484 int plane = intel_plane->plane;
485
Ville Syrjälä48fe4692015-03-19 17:57:13 +0200486 I915_WRITE(SPCNTR(pipe, plane), 0);
487
Daniel Vetter85ba7b72014-01-24 10:31:44 +0100488 I915_WRITE(SPSURF(pipe, plane), 0);
Ville Syrjäläb12ce1d2015-05-26 20:27:23 +0300489 POSTING_READ(SPSURF(pipe, plane));
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700490}
491
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700492static void
Maarten Lankhorst2fde1392016-01-07 11:54:06 +0100493ivb_update_plane(struct drm_plane *plane,
494 const struct intel_crtc_state *crtc_state,
495 const struct intel_plane_state *plane_state)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800496{
497 struct drm_device *dev = plane->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100498 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800499 struct intel_plane *intel_plane = to_intel_plane(plane);
Maarten Lankhorst2fde1392016-01-07 11:54:06 +0100500 struct drm_framebuffer *fb = plane_state->base.fb;
Ville Syrjälä47ecbb22015-03-19 21:18:57 +0200501 enum pipe pipe = intel_plane->pipe;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800502 u32 sprctl, sprscale = 0;
Ville Syrjälä54ea9da2016-01-20 21:05:25 +0200503 u32 sprsurf_offset, linear_offset;
Ville Syrjälä8d0deca2016-02-15 22:54:41 +0200504 unsigned int rotation = plane_state->base.rotation;
Maarten Lankhorst2fde1392016-01-07 11:54:06 +0100505 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
Ville Syrjälä936e71e2016-07-26 19:06:59 +0300506 int crtc_x = plane_state->base.dst.x1;
507 int crtc_y = plane_state->base.dst.y1;
508 uint32_t crtc_w = drm_rect_width(&plane_state->base.dst);
509 uint32_t crtc_h = drm_rect_height(&plane_state->base.dst);
510 uint32_t x = plane_state->base.src.x1 >> 16;
511 uint32_t y = plane_state->base.src.y1 >> 16;
512 uint32_t src_w = drm_rect_width(&plane_state->base.src) >> 16;
513 uint32_t src_h = drm_rect_height(&plane_state->base.src) >> 16;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800514
Ville Syrjälä48fe4692015-03-19 17:57:13 +0200515 sprctl = SPRITE_ENABLE;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800516
517 switch (fb->pixel_format) {
518 case DRM_FORMAT_XBGR8888:
Vijay Purushothaman5ee36912012-08-23 12:08:57 +0530519 sprctl |= SPRITE_FORMAT_RGBX888 | SPRITE_RGB_ORDER_RGBX;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800520 break;
521 case DRM_FORMAT_XRGB8888:
Vijay Purushothaman5ee36912012-08-23 12:08:57 +0530522 sprctl |= SPRITE_FORMAT_RGBX888;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800523 break;
524 case DRM_FORMAT_YUYV:
525 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YUYV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800526 break;
527 case DRM_FORMAT_YVYU:
528 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YVYU;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800529 break;
530 case DRM_FORMAT_UYVY:
531 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_UYVY;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800532 break;
533 case DRM_FORMAT_VYUY:
534 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_VYUY;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800535 break;
536 default:
Ville Syrjälä28d491d2012-10-31 17:50:21 +0200537 BUG();
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800538 }
539
Ville Syrjälä4ea67bc2013-11-18 18:32:38 -0800540 /*
541 * Enable gamma to match primary/cursor plane behaviour.
542 * FIXME should be user controllable via propertiesa.
543 */
544 sprctl |= SPRITE_GAMMA_ENABLE;
545
Ville Syrjäläbae781b2016-11-16 13:33:16 +0200546 if (fb->modifier == I915_FORMAT_MOD_X_TILED)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800547 sprctl |= SPRITE_TILED;
548
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100549 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Paulo Zanoni1f5d76d2013-08-23 19:51:28 -0300550 sprctl &= ~SPRITE_TRICKLE_FEED_DISABLE;
551 else
552 sprctl |= SPRITE_TRICKLE_FEED_DISABLE;
553
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100554 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Ville Syrjälä86d3efc2013-01-18 19:11:38 +0200555 sprctl |= SPRITE_PIPE_CSC_ENABLE;
556
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800557 /* Sizes are 0 based */
558 src_w--;
559 src_h--;
560 crtc_w--;
561 crtc_h--;
562
Ville Syrjälä8553c182013-12-05 15:51:39 +0200563 if (crtc_w != src_w || crtc_h != src_h)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800564 sprscale = SPRITE_SCALE_ENABLE | (src_w << 16) | src_h;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800565
Ville Syrjälä29490562016-01-20 18:02:50 +0200566 intel_add_fb_offsets(&x, &y, plane_state, 0);
567 sprsurf_offset = intel_compute_tile_offset(&x, &y, plane_state, 0);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800568
Joonas Lahtinen31ad61e2016-07-29 08:50:05 +0300569 if (rotation == DRM_ROTATE_180) {
Ville Syrjälä76eebda2014-08-05 11:26:52 +0530570 sprctl |= SPRITE_ROTATE_180;
571
572 /* HSW and BDW does this automagically in hardware */
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100573 if (!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv)) {
Ville Syrjälä76eebda2014-08-05 11:26:52 +0530574 x += src_w;
575 y += src_h;
Ville Syrjälä76eebda2014-08-05 11:26:52 +0530576 }
577 }
578
Ville Syrjälä29490562016-01-20 18:02:50 +0200579 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
Ville Syrjälä6687c902015-09-15 13:16:41 +0300580
Ville Syrjälä47ecbb22015-03-19 21:18:57 +0200581 if (key->flags) {
582 I915_WRITE(SPRKEYVAL(pipe), key->min_value);
583 I915_WRITE(SPRKEYMAX(pipe), key->max_value);
584 I915_WRITE(SPRKEYMSK(pipe), key->channel_mask);
585 }
586
587 if (key->flags & I915_SET_COLORKEY_DESTINATION)
588 sprctl |= SPRITE_DEST_KEY;
589 else if (key->flags & I915_SET_COLORKEY_SOURCE)
590 sprctl |= SPRITE_SOURCE_KEY;
591
Ville Syrjäläca6ad022014-01-17 20:09:03 +0200592 I915_WRITE(SPRSTRIDE(pipe), fb->pitches[0]);
593 I915_WRITE(SPRPOS(pipe), (crtc_y << 16) | crtc_x);
594
Damien Lespiau5a35e992012-10-26 18:20:12 +0100595 /* HSW consolidates SPRTILEOFF and SPRLINOFF into a single SPROFFSET
596 * register */
Tvrtko Ursulin86527442016-10-13 11:03:00 +0100597 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Damien Lespiau5a35e992012-10-26 18:20:12 +0100598 I915_WRITE(SPROFFSET(pipe), (y << 16) | x);
Ville Syrjäläbae781b2016-11-16 13:33:16 +0200599 else if (fb->modifier == I915_FORMAT_MOD_X_TILED)
Damien Lespiau5a35e992012-10-26 18:20:12 +0100600 I915_WRITE(SPRTILEOFF(pipe), (y << 16) | x);
601 else
602 I915_WRITE(SPRLINOFF(pipe), linear_offset);
Damien Lespiauc54173a2012-10-26 18:20:11 +0100603
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800604 I915_WRITE(SPRSIZE(pipe), (crtc_h << 16) | crtc_w);
Damien Lespiau2d354c32012-10-22 18:19:27 +0100605 if (intel_plane->can_scale)
606 I915_WRITE(SPRSCALE(pipe), sprscale);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800607 I915_WRITE(SPRCTL(pipe), sprctl);
Daniel Vetter85ba7b72014-01-24 10:31:44 +0100608 I915_WRITE(SPRSURF(pipe),
Ville Syrjälä6687c902015-09-15 13:16:41 +0300609 intel_fb_gtt_offset(fb, rotation) + sprsurf_offset);
Ville Syrjäläb12ce1d2015-05-26 20:27:23 +0300610 POSTING_READ(SPRSURF(pipe));
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800611}
612
613static void
Maarten Lankhorst7fabf5e2015-06-15 12:33:47 +0200614ivb_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800615{
616 struct drm_device *dev = plane->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100617 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800618 struct intel_plane *intel_plane = to_intel_plane(plane);
619 int pipe = intel_plane->pipe;
620
Ville Syrjäläc5626572015-10-15 17:04:04 +0300621 I915_WRITE(SPRCTL(pipe), 0);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800622 /* Can't leave the scaler enabled... */
Damien Lespiau2d354c32012-10-22 18:19:27 +0100623 if (intel_plane->can_scale)
624 I915_WRITE(SPRSCALE(pipe), 0);
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300625
Ville Syrjäläb12ce1d2015-05-26 20:27:23 +0300626 I915_WRITE(SPRSURF(pipe), 0);
627 POSTING_READ(SPRSURF(pipe));
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800628}
629
630static void
Maarten Lankhorst2fde1392016-01-07 11:54:06 +0100631ilk_update_plane(struct drm_plane *plane,
632 const struct intel_crtc_state *crtc_state,
633 const struct intel_plane_state *plane_state)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800634{
635 struct drm_device *dev = plane->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100636 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800637 struct intel_plane *intel_plane = to_intel_plane(plane);
Maarten Lankhorst2fde1392016-01-07 11:54:06 +0100638 struct drm_framebuffer *fb = plane_state->base.fb;
Ville Syrjälä2bd3c3c2012-10-31 17:50:20 +0200639 int pipe = intel_plane->pipe;
Chris Wilson8aaa81a2012-04-14 22:14:26 +0100640 u32 dvscntr, dvsscale;
Ville Syrjälä54ea9da2016-01-20 21:05:25 +0200641 u32 dvssurf_offset, linear_offset;
Ville Syrjälä8d0deca2016-02-15 22:54:41 +0200642 unsigned int rotation = plane_state->base.rotation;
Maarten Lankhorst2fde1392016-01-07 11:54:06 +0100643 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
Ville Syrjälä936e71e2016-07-26 19:06:59 +0300644 int crtc_x = plane_state->base.dst.x1;
645 int crtc_y = plane_state->base.dst.y1;
646 uint32_t crtc_w = drm_rect_width(&plane_state->base.dst);
647 uint32_t crtc_h = drm_rect_height(&plane_state->base.dst);
648 uint32_t x = plane_state->base.src.x1 >> 16;
649 uint32_t y = plane_state->base.src.y1 >> 16;
650 uint32_t src_w = drm_rect_width(&plane_state->base.src) >> 16;
651 uint32_t src_h = drm_rect_height(&plane_state->base.src) >> 16;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800652
Ville Syrjälä48fe4692015-03-19 17:57:13 +0200653 dvscntr = DVS_ENABLE;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800654
655 switch (fb->pixel_format) {
656 case DRM_FORMAT_XBGR8888:
Jesse Barnesab2f9df2012-02-27 12:40:10 -0800657 dvscntr |= DVS_FORMAT_RGBX888 | DVS_RGB_ORDER_XBGR;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800658 break;
659 case DRM_FORMAT_XRGB8888:
Jesse Barnesab2f9df2012-02-27 12:40:10 -0800660 dvscntr |= DVS_FORMAT_RGBX888;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800661 break;
662 case DRM_FORMAT_YUYV:
663 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YUYV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800664 break;
665 case DRM_FORMAT_YVYU:
666 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YVYU;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800667 break;
668 case DRM_FORMAT_UYVY:
669 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_UYVY;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800670 break;
671 case DRM_FORMAT_VYUY:
672 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_VYUY;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800673 break;
674 default:
Ville Syrjälä28d491d2012-10-31 17:50:21 +0200675 BUG();
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800676 }
677
Ville Syrjälä4ea67bc2013-11-18 18:32:38 -0800678 /*
679 * Enable gamma to match primary/cursor plane behaviour.
680 * FIXME should be user controllable via propertiesa.
681 */
682 dvscntr |= DVS_GAMMA_ENABLE;
683
Ville Syrjäläbae781b2016-11-16 13:33:16 +0200684 if (fb->modifier == I915_FORMAT_MOD_X_TILED)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800685 dvscntr |= DVS_TILED;
686
Tvrtko Ursulin5db94012016-10-13 11:03:10 +0100687 if (IS_GEN6(dev_priv))
Chris Wilsond1686ae2012-04-10 11:41:49 +0100688 dvscntr |= DVS_TRICKLE_FEED_DISABLE; /* must disable */
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800689
690 /* Sizes are 0 based */
691 src_w--;
692 src_h--;
693 crtc_w--;
694 crtc_h--;
695
Chris Wilson8aaa81a2012-04-14 22:14:26 +0100696 dvsscale = 0;
Ville Syrjälä8368f012013-12-05 15:51:31 +0200697 if (crtc_w != src_w || crtc_h != src_h)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800698 dvsscale = DVS_SCALE_ENABLE | (src_w << 16) | src_h;
699
Ville Syrjälä29490562016-01-20 18:02:50 +0200700 intel_add_fb_offsets(&x, &y, plane_state, 0);
701 dvssurf_offset = intel_compute_tile_offset(&x, &y, plane_state, 0);
Damien Lespiau5a35e992012-10-26 18:20:12 +0100702
Joonas Lahtinen31ad61e2016-07-29 08:50:05 +0300703 if (rotation == DRM_ROTATE_180) {
Ville Syrjälä76eebda2014-08-05 11:26:52 +0530704 dvscntr |= DVS_ROTATE_180;
705
706 x += src_w;
707 y += src_h;
Ville Syrjälä76eebda2014-08-05 11:26:52 +0530708 }
709
Ville Syrjälä29490562016-01-20 18:02:50 +0200710 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
Ville Syrjälä6687c902015-09-15 13:16:41 +0300711
Ville Syrjälä47ecbb22015-03-19 21:18:57 +0200712 if (key->flags) {
713 I915_WRITE(DVSKEYVAL(pipe), key->min_value);
714 I915_WRITE(DVSKEYMAX(pipe), key->max_value);
715 I915_WRITE(DVSKEYMSK(pipe), key->channel_mask);
716 }
717
718 if (key->flags & I915_SET_COLORKEY_DESTINATION)
719 dvscntr |= DVS_DEST_KEY;
720 else if (key->flags & I915_SET_COLORKEY_SOURCE)
721 dvscntr |= DVS_SOURCE_KEY;
722
Ville Syrjäläca6ad022014-01-17 20:09:03 +0200723 I915_WRITE(DVSSTRIDE(pipe), fb->pitches[0]);
724 I915_WRITE(DVSPOS(pipe), (crtc_y << 16) | crtc_x);
725
Ville Syrjäläbae781b2016-11-16 13:33:16 +0200726 if (fb->modifier == I915_FORMAT_MOD_X_TILED)
Damien Lespiau5a35e992012-10-26 18:20:12 +0100727 I915_WRITE(DVSTILEOFF(pipe), (y << 16) | x);
728 else
729 I915_WRITE(DVSLINOFF(pipe), linear_offset);
730
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800731 I915_WRITE(DVSSIZE(pipe), (crtc_h << 16) | crtc_w);
732 I915_WRITE(DVSSCALE(pipe), dvsscale);
733 I915_WRITE(DVSCNTR(pipe), dvscntr);
Daniel Vetter85ba7b72014-01-24 10:31:44 +0100734 I915_WRITE(DVSSURF(pipe),
Ville Syrjälä6687c902015-09-15 13:16:41 +0300735 intel_fb_gtt_offset(fb, rotation) + dvssurf_offset);
Ville Syrjäläb12ce1d2015-05-26 20:27:23 +0300736 POSTING_READ(DVSSURF(pipe));
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800737}
738
739static void
Maarten Lankhorst7fabf5e2015-06-15 12:33:47 +0200740ilk_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800741{
742 struct drm_device *dev = plane->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100743 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800744 struct intel_plane *intel_plane = to_intel_plane(plane);
745 int pipe = intel_plane->pipe;
746
Ville Syrjälä48fe4692015-03-19 17:57:13 +0200747 I915_WRITE(DVSCNTR(pipe), 0);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800748 /* Disable the scaler */
749 I915_WRITE(DVSSCALE(pipe), 0);
Ville Syrjälä48fe4692015-03-19 17:57:13 +0200750
Daniel Vetter85ba7b72014-01-24 10:31:44 +0100751 I915_WRITE(DVSSURF(pipe), 0);
Ville Syrjäläb12ce1d2015-05-26 20:27:23 +0300752 POSTING_READ(DVSSURF(pipe));
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800753}
754
Jesse Barnes8ea30862012-01-03 08:05:39 -0800755static int
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300756intel_check_sprite_plane(struct drm_plane *plane,
Maarten Lankhorst061e4b82015-06-15 12:33:46 +0200757 struct intel_crtc_state *crtc_state,
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300758 struct intel_plane_state *state)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800759{
Tvrtko Ursulin55b8f2a2016-10-14 09:17:22 +0100760 struct drm_i915_private *dev_priv = to_i915(plane->dev);
Maarten Lankhorst061e4b82015-06-15 12:33:46 +0200761 struct drm_crtc *crtc = state->base.crtc;
762 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800763 struct intel_plane *intel_plane = to_intel_plane(plane);
Matt Roper2b875c22014-12-01 15:40:13 -0800764 struct drm_framebuffer *fb = state->base.fb;
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300765 int crtc_x, crtc_y;
766 unsigned int crtc_w, crtc_h;
767 uint32_t src_x, src_y, src_w, src_h;
Ville Syrjälä936e71e2016-07-26 19:06:59 +0300768 struct drm_rect *src = &state->base.src;
769 struct drm_rect *dst = &state->base.dst;
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300770 const struct drm_rect *clip = &state->clip;
Ville Syrjälä17316932013-04-24 18:52:38 +0300771 int hscale, vscale;
772 int max_scale, min_scale;
Chandra Konduru225c2282015-05-18 16:18:44 -0700773 bool can_scale;
Ville Syrjäläb63a16f2016-01-28 16:53:54 +0200774 int ret;
Matt Ropercf4c7c12014-12-04 10:27:42 -0800775
Rob Clark1638d302016-11-05 11:08:08 -0400776 *src = drm_plane_state_src(&state->base);
777 *dst = drm_plane_state_dest(&state->base);
Ville Syrjäläf8856a42016-07-26 19:07:00 +0300778
Matt Ropercf4c7c12014-12-04 10:27:42 -0800779 if (!fb) {
Ville Syrjälä936e71e2016-07-26 19:06:59 +0300780 state->base.visible = false;
Maarten Lankhorstda20eab2015-06-15 12:33:44 +0200781 return 0;
Matt Ropercf4c7c12014-12-04 10:27:42 -0800782 }
Jesse Barnes5e1bac22013-03-26 09:25:43 -0700783
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800784 /* Don't modify another pipe's plane */
Ville Syrjälä17316932013-04-24 18:52:38 +0300785 if (intel_plane->pipe != intel_crtc->pipe) {
786 DRM_DEBUG_KMS("Wrong plane <-> crtc mapping\n");
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800787 return -EINVAL;
Ville Syrjälä17316932013-04-24 18:52:38 +0300788 }
789
790 /* FIXME check all gen limits */
791 if (fb->width < 3 || fb->height < 3 || fb->pitches[0] > 16384) {
792 DRM_DEBUG_KMS("Unsuitable framebuffer for plane\n");
793 return -EINVAL;
794 }
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800795
Chandra Konduru225c2282015-05-18 16:18:44 -0700796 /* setup can_scale, min_scale, max_scale */
Tvrtko Ursulin55b8f2a2016-10-14 09:17:22 +0100797 if (INTEL_GEN(dev_priv) >= 9) {
Chandra Konduru225c2282015-05-18 16:18:44 -0700798 /* use scaler when colorkey is not required */
Maarten Lankhorst818ed962015-06-15 12:33:54 +0200799 if (state->ckey.flags == I915_SET_COLORKEY_NONE) {
Chandra Konduru225c2282015-05-18 16:18:44 -0700800 can_scale = 1;
801 min_scale = 1;
802 max_scale = skl_max_scale(intel_crtc, crtc_state);
803 } else {
804 can_scale = 0;
805 min_scale = DRM_PLANE_HELPER_NO_SCALING;
806 max_scale = DRM_PLANE_HELPER_NO_SCALING;
807 }
808 } else {
809 can_scale = intel_plane->can_scale;
810 max_scale = intel_plane->max_downscale << 16;
811 min_scale = intel_plane->can_scale ? 1 : (1 << 16);
812 }
813
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300814 /*
815 * FIXME the following code does a bunch of fuzzy adjustments to the
816 * coordinates and sizes. We probably need some way to decide whether
817 * more strict checking should be done instead.
818 */
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300819 drm_rect_rotate(src, fb->width << 16, fb->height << 16,
Matt Roper8e7d6882015-01-21 16:35:41 -0800820 state->base.rotation);
Ville Syrjälä76eebda2014-08-05 11:26:52 +0530821
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300822 hscale = drm_rect_calc_hscale_relaxed(src, dst, min_scale, max_scale);
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300823 BUG_ON(hscale < 0);
Ville Syrjälä17316932013-04-24 18:52:38 +0300824
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300825 vscale = drm_rect_calc_vscale_relaxed(src, dst, min_scale, max_scale);
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300826 BUG_ON(vscale < 0);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800827
Ville Syrjälä936e71e2016-07-26 19:06:59 +0300828 state->base.visible = drm_rect_clip_scaled(src, dst, clip, hscale, vscale);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800829
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300830 crtc_x = dst->x1;
831 crtc_y = dst->y1;
832 crtc_w = drm_rect_width(dst);
833 crtc_h = drm_rect_height(dst);
Damien Lespiau2d354c32012-10-22 18:19:27 +0100834
Ville Syrjälä936e71e2016-07-26 19:06:59 +0300835 if (state->base.visible) {
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300836 /* check again in case clipping clamped the results */
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300837 hscale = drm_rect_calc_hscale(src, dst, min_scale, max_scale);
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300838 if (hscale < 0) {
839 DRM_DEBUG_KMS("Horizontal scaling factor out of limits\n");
Ville Syrjäläc70f5772015-11-16 17:02:36 +0200840 drm_rect_debug_print("src: ", src, true);
841 drm_rect_debug_print("dst: ", dst, false);
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300842
843 return hscale;
844 }
845
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300846 vscale = drm_rect_calc_vscale(src, dst, min_scale, max_scale);
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300847 if (vscale < 0) {
848 DRM_DEBUG_KMS("Vertical scaling factor out of limits\n");
Ville Syrjäläc70f5772015-11-16 17:02:36 +0200849 drm_rect_debug_print("src: ", src, true);
850 drm_rect_debug_print("dst: ", dst, false);
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300851
852 return vscale;
853 }
854
Ville Syrjälä17316932013-04-24 18:52:38 +0300855 /* Make the source viewport size an exact multiple of the scaling factors. */
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300856 drm_rect_adjust_size(src,
857 drm_rect_width(dst) * hscale - drm_rect_width(src),
858 drm_rect_height(dst) * vscale - drm_rect_height(src));
Ville Syrjälä17316932013-04-24 18:52:38 +0300859
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300860 drm_rect_rotate_inv(src, fb->width << 16, fb->height << 16,
Matt Roper8e7d6882015-01-21 16:35:41 -0800861 state->base.rotation);
Ville Syrjälä76eebda2014-08-05 11:26:52 +0530862
Ville Syrjälä17316932013-04-24 18:52:38 +0300863 /* sanity check to make sure the src viewport wasn't enlarged */
Matt Roperea2c67b2014-12-23 10:41:52 -0800864 WARN_ON(src->x1 < (int) state->base.src_x ||
865 src->y1 < (int) state->base.src_y ||
866 src->x2 > (int) state->base.src_x + state->base.src_w ||
867 src->y2 > (int) state->base.src_y + state->base.src_h);
Ville Syrjälä17316932013-04-24 18:52:38 +0300868
869 /*
870 * Hardware doesn't handle subpixel coordinates.
871 * Adjust to (macro)pixel boundary, but be careful not to
872 * increase the source viewport size, because that could
873 * push the downscaling factor out of bounds.
Ville Syrjälä17316932013-04-24 18:52:38 +0300874 */
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300875 src_x = src->x1 >> 16;
876 src_w = drm_rect_width(src) >> 16;
877 src_y = src->y1 >> 16;
878 src_h = drm_rect_height(src) >> 16;
Ville Syrjälä17316932013-04-24 18:52:38 +0300879
880 if (format_is_yuv(fb->pixel_format)) {
881 src_x &= ~1;
882 src_w &= ~1;
883
884 /*
885 * Must keep src and dst the
886 * same if we can't scale.
887 */
Chandra Konduru225c2282015-05-18 16:18:44 -0700888 if (!can_scale)
Ville Syrjälä17316932013-04-24 18:52:38 +0300889 crtc_w &= ~1;
890
891 if (crtc_w == 0)
Ville Syrjälä936e71e2016-07-26 19:06:59 +0300892 state->base.visible = false;
Ville Syrjälä17316932013-04-24 18:52:38 +0300893 }
894 }
895
896 /* Check size restrictions when scaling */
Ville Syrjälä936e71e2016-07-26 19:06:59 +0300897 if (state->base.visible && (src_w != crtc_w || src_h != crtc_h)) {
Ville Syrjälä17316932013-04-24 18:52:38 +0300898 unsigned int width_bytes;
Ville Syrjäläac484962016-01-20 21:05:26 +0200899 int cpp = drm_format_plane_cpp(fb->pixel_format, 0);
Ville Syrjälä17316932013-04-24 18:52:38 +0300900
Chandra Konduru225c2282015-05-18 16:18:44 -0700901 WARN_ON(!can_scale);
Ville Syrjälä17316932013-04-24 18:52:38 +0300902
903 /* FIXME interlacing min height is 6 */
904
905 if (crtc_w < 3 || crtc_h < 3)
Ville Syrjälä936e71e2016-07-26 19:06:59 +0300906 state->base.visible = false;
Ville Syrjälä17316932013-04-24 18:52:38 +0300907
908 if (src_w < 3 || src_h < 3)
Ville Syrjälä936e71e2016-07-26 19:06:59 +0300909 state->base.visible = false;
Ville Syrjälä17316932013-04-24 18:52:38 +0300910
Ville Syrjäläac484962016-01-20 21:05:26 +0200911 width_bytes = ((src_x * cpp) & 63) + src_w * cpp;
Ville Syrjälä17316932013-04-24 18:52:38 +0300912
Tvrtko Ursulin55b8f2a2016-10-14 09:17:22 +0100913 if (INTEL_GEN(dev_priv) < 9 && (src_w > 2048 || src_h > 2048 ||
Chandra Konduruc3318792015-04-15 15:15:02 -0700914 width_bytes > 4096 || fb->pitches[0] > 4096)) {
Ville Syrjälä17316932013-04-24 18:52:38 +0300915 DRM_DEBUG_KMS("Source dimensions exceed hardware limits\n");
916 return -EINVAL;
917 }
918 }
919
Ville Syrjälä936e71e2016-07-26 19:06:59 +0300920 if (state->base.visible) {
Chandra Konduru0a5ae1b2015-04-09 16:41:54 -0700921 src->x1 = src_x << 16;
922 src->x2 = (src_x + src_w) << 16;
923 src->y1 = src_y << 16;
924 src->y2 = (src_y + src_h) << 16;
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300925 }
926
927 dst->x1 = crtc_x;
928 dst->x2 = crtc_x + crtc_w;
929 dst->y1 = crtc_y;
930 dst->y2 = crtc_y + crtc_h;
931
Tvrtko Ursulin55b8f2a2016-10-14 09:17:22 +0100932 if (INTEL_GEN(dev_priv) >= 9) {
Ville Syrjäläb63a16f2016-01-28 16:53:54 +0200933 ret = skl_check_plane_surface(state);
934 if (ret)
935 return ret;
936 }
937
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300938 return 0;
939}
940
Jesse Barnes8ea30862012-01-03 08:05:39 -0800941int intel_sprite_set_colorkey(struct drm_device *dev, void *data,
942 struct drm_file *file_priv)
943{
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100944 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes8ea30862012-01-03 08:05:39 -0800945 struct drm_intel_sprite_colorkey *set = data;
Jesse Barnes8ea30862012-01-03 08:05:39 -0800946 struct drm_plane *plane;
Maarten Lankhorst818ed962015-06-15 12:33:54 +0200947 struct drm_plane_state *plane_state;
948 struct drm_atomic_state *state;
949 struct drm_modeset_acquire_ctx ctx;
Jesse Barnes8ea30862012-01-03 08:05:39 -0800950 int ret = 0;
951
Jesse Barnes8ea30862012-01-03 08:05:39 -0800952 /* Make sure we don't try to enable both src & dest simultaneously */
953 if ((set->flags & (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE)) == (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE))
954 return -EINVAL;
955
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100956 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Ville Syrjälä47ecbb22015-03-19 21:18:57 +0200957 set->flags & I915_SET_COLORKEY_DESTINATION)
958 return -EINVAL;
959
Rob Clark7707e652014-07-17 23:30:04 -0400960 plane = drm_plane_find(dev, set->plane_id);
Maarten Lankhorst818ed962015-06-15 12:33:54 +0200961 if (!plane || plane->type != DRM_PLANE_TYPE_OVERLAY)
962 return -ENOENT;
963
964 drm_modeset_acquire_init(&ctx, 0);
965
966 state = drm_atomic_state_alloc(plane->dev);
967 if (!state) {
968 ret = -ENOMEM;
969 goto out;
Jesse Barnes8ea30862012-01-03 08:05:39 -0800970 }
Maarten Lankhorst818ed962015-06-15 12:33:54 +0200971 state->acquire_ctx = &ctx;
Jesse Barnes8ea30862012-01-03 08:05:39 -0800972
Maarten Lankhorst818ed962015-06-15 12:33:54 +0200973 while (1) {
974 plane_state = drm_atomic_get_plane_state(state, plane);
975 ret = PTR_ERR_OR_ZERO(plane_state);
976 if (!ret) {
977 to_intel_plane_state(plane_state)->ckey = *set;
978 ret = drm_atomic_commit(state);
Chandra Konduru6156a452015-04-27 13:48:39 -0700979 }
Maarten Lankhorst818ed962015-06-15 12:33:54 +0200980
981 if (ret != -EDEADLK)
982 break;
983
984 drm_atomic_state_clear(state);
985 drm_modeset_backoff(&ctx);
Chandra Konduru6156a452015-04-27 13:48:39 -0700986 }
987
Chris Wilson08536952016-10-14 13:18:18 +0100988 drm_atomic_state_put(state);
Maarten Lankhorst818ed962015-06-15 12:33:54 +0200989out:
990 drm_modeset_drop_locks(&ctx);
991 drm_modeset_acquire_fini(&ctx);
Jesse Barnes8ea30862012-01-03 08:05:39 -0800992 return ret;
993}
994
Damien Lespiaudada2d52015-05-12 16:13:22 +0100995static const uint32_t ilk_plane_formats[] = {
Chris Wilsond1686ae2012-04-10 11:41:49 +0100996 DRM_FORMAT_XRGB8888,
997 DRM_FORMAT_YUYV,
998 DRM_FORMAT_YVYU,
999 DRM_FORMAT_UYVY,
1000 DRM_FORMAT_VYUY,
1001};
1002
Damien Lespiaudada2d52015-05-12 16:13:22 +01001003static const uint32_t snb_plane_formats[] = {
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001004 DRM_FORMAT_XBGR8888,
1005 DRM_FORMAT_XRGB8888,
1006 DRM_FORMAT_YUYV,
1007 DRM_FORMAT_YVYU,
1008 DRM_FORMAT_UYVY,
1009 DRM_FORMAT_VYUY,
1010};
1011
Damien Lespiaudada2d52015-05-12 16:13:22 +01001012static const uint32_t vlv_plane_formats[] = {
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001013 DRM_FORMAT_RGB565,
1014 DRM_FORMAT_ABGR8888,
1015 DRM_FORMAT_ARGB8888,
1016 DRM_FORMAT_XBGR8888,
1017 DRM_FORMAT_XRGB8888,
1018 DRM_FORMAT_XBGR2101010,
1019 DRM_FORMAT_ABGR2101010,
1020 DRM_FORMAT_YUYV,
1021 DRM_FORMAT_YVYU,
1022 DRM_FORMAT_UYVY,
1023 DRM_FORMAT_VYUY,
1024};
1025
Damien Lespiaudc2a41b2013-12-04 00:49:41 +00001026static uint32_t skl_plane_formats[] = {
1027 DRM_FORMAT_RGB565,
1028 DRM_FORMAT_ABGR8888,
1029 DRM_FORMAT_ARGB8888,
1030 DRM_FORMAT_XBGR8888,
1031 DRM_FORMAT_XRGB8888,
1032 DRM_FORMAT_YUYV,
1033 DRM_FORMAT_YVYU,
1034 DRM_FORMAT_UYVY,
1035 DRM_FORMAT_VYUY,
1036};
1037
Ville Syrjäläb079bd172016-10-25 18:58:02 +03001038struct intel_plane *
Ville Syrjälä580503c2016-10-31 22:37:00 +02001039intel_sprite_plane_create(struct drm_i915_private *dev_priv,
1040 enum pipe pipe, int plane)
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001041{
Ville Syrjäläfca0ce22016-03-21 14:43:22 +00001042 struct intel_plane *intel_plane = NULL;
1043 struct intel_plane_state *state = NULL;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001044 unsigned long possible_crtcs;
Chris Wilsond1686ae2012-04-10 11:41:49 +01001045 const uint32_t *plane_formats;
Ville Syrjälä93ca7e02016-09-26 19:30:56 +03001046 unsigned int supported_rotations;
Chris Wilsond1686ae2012-04-10 11:41:49 +01001047 int num_plane_formats;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001048 int ret;
1049
Daniel Vetterb14c5672013-09-19 12:18:32 +02001050 intel_plane = kzalloc(sizeof(*intel_plane), GFP_KERNEL);
Ville Syrjäläfca0ce22016-03-21 14:43:22 +00001051 if (!intel_plane) {
1052 ret = -ENOMEM;
1053 goto fail;
1054 }
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001055
Matt Roper8e7d6882015-01-21 16:35:41 -08001056 state = intel_create_plane_state(&intel_plane->base);
1057 if (!state) {
Ville Syrjäläfca0ce22016-03-21 14:43:22 +00001058 ret = -ENOMEM;
1059 goto fail;
Matt Roperea2c67b2014-12-23 10:41:52 -08001060 }
Matt Roper8e7d6882015-01-21 16:35:41 -08001061 intel_plane->base.state = &state->base;
Matt Roperea2c67b2014-12-23 10:41:52 -08001062
Ville Syrjälä1890ae62016-10-25 18:58:03 +03001063 if (INTEL_GEN(dev_priv) >= 9) {
1064 intel_plane->can_scale = true;
1065 state->scaler_id = -1;
1066
1067 intel_plane->update_plane = skl_update_plane;
1068 intel_plane->disable_plane = skl_disable_plane;
1069
1070 plane_formats = skl_plane_formats;
1071 num_plane_formats = ARRAY_SIZE(skl_plane_formats);
1072 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
1073 intel_plane->can_scale = false;
1074 intel_plane->max_downscale = 1;
1075
1076 intel_plane->update_plane = vlv_update_plane;
1077 intel_plane->disable_plane = vlv_disable_plane;
1078
1079 plane_formats = vlv_plane_formats;
1080 num_plane_formats = ARRAY_SIZE(vlv_plane_formats);
1081 } else if (INTEL_GEN(dev_priv) >= 7) {
1082 if (IS_IVYBRIDGE(dev_priv)) {
1083 intel_plane->can_scale = true;
1084 intel_plane->max_downscale = 2;
1085 } else {
1086 intel_plane->can_scale = false;
1087 intel_plane->max_downscale = 1;
1088 }
1089
1090 intel_plane->update_plane = ivb_update_plane;
1091 intel_plane->disable_plane = ivb_disable_plane;
1092
1093 plane_formats = snb_plane_formats;
1094 num_plane_formats = ARRAY_SIZE(snb_plane_formats);
1095 } else {
Damien Lespiau2d354c32012-10-22 18:19:27 +01001096 intel_plane->can_scale = true;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001097 intel_plane->max_downscale = 16;
Ville Syrjälä1890ae62016-10-25 18:58:03 +03001098
Chris Wilsond1686ae2012-04-10 11:41:49 +01001099 intel_plane->update_plane = ilk_update_plane;
1100 intel_plane->disable_plane = ilk_disable_plane;
Chris Wilsond1686ae2012-04-10 11:41:49 +01001101
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01001102 if (IS_GEN6(dev_priv)) {
Chris Wilsond1686ae2012-04-10 11:41:49 +01001103 plane_formats = snb_plane_formats;
1104 num_plane_formats = ARRAY_SIZE(snb_plane_formats);
1105 } else {
1106 plane_formats = ilk_plane_formats;
1107 num_plane_formats = ARRAY_SIZE(ilk_plane_formats);
1108 }
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001109 }
1110
Dave Airlie5481e272016-10-25 16:36:13 +10001111 if (INTEL_GEN(dev_priv) >= 9) {
Ville Syrjälä93ca7e02016-09-26 19:30:56 +03001112 supported_rotations =
1113 DRM_ROTATE_0 | DRM_ROTATE_90 |
1114 DRM_ROTATE_180 | DRM_ROTATE_270;
1115 } else {
1116 supported_rotations =
1117 DRM_ROTATE_0 | DRM_ROTATE_180;
1118 }
1119
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001120 intel_plane->pipe = pipe;
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001121 intel_plane->plane = plane;
Sagar Arun Kambled1b9d032015-09-14 21:35:42 +05301122 intel_plane->frontbuffer_bit = INTEL_FRONTBUFFER_SPRITE(pipe, plane);
Matt Roperc59cb172014-12-01 15:40:16 -08001123 intel_plane->check_plane = intel_check_sprite_plane;
Ville Syrjäläfca0ce22016-03-21 14:43:22 +00001124
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001125 possible_crtcs = (1 << pipe);
Ville Syrjäläfca0ce22016-03-21 14:43:22 +00001126
Ville Syrjälä1890ae62016-10-25 18:58:03 +03001127 if (INTEL_GEN(dev_priv) >= 9)
Ville Syrjälä580503c2016-10-31 22:37:00 +02001128 ret = drm_universal_plane_init(&dev_priv->drm, &intel_plane->base,
1129 possible_crtcs, &intel_plane_funcs,
Ville Syrjälä38573dc2016-05-27 20:59:23 +03001130 plane_formats, num_plane_formats,
1131 DRM_PLANE_TYPE_OVERLAY,
1132 "plane %d%c", plane + 2, pipe_name(pipe));
1133 else
Ville Syrjälä580503c2016-10-31 22:37:00 +02001134 ret = drm_universal_plane_init(&dev_priv->drm, &intel_plane->base,
1135 possible_crtcs, &intel_plane_funcs,
Ville Syrjälä38573dc2016-05-27 20:59:23 +03001136 plane_formats, num_plane_formats,
1137 DRM_PLANE_TYPE_OVERLAY,
1138 "sprite %c", sprite_name(pipe, plane));
Ville Syrjäläfca0ce22016-03-21 14:43:22 +00001139 if (ret)
1140 goto fail;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001141
Ville Syrjälä93ca7e02016-09-26 19:30:56 +03001142 drm_plane_create_rotation_property(&intel_plane->base,
1143 DRM_ROTATE_0,
1144 supported_rotations);
Ville Syrjälä7ed6eee2014-08-05 11:26:55 +05301145
Matt Roperea2c67b2014-12-23 10:41:52 -08001146 drm_plane_helper_add(&intel_plane->base, &intel_plane_helper_funcs);
1147
Ville Syrjäläb079bd172016-10-25 18:58:02 +03001148 return intel_plane;
Ville Syrjäläfca0ce22016-03-21 14:43:22 +00001149
1150fail:
1151 kfree(state);
1152 kfree(intel_plane);
1153
Ville Syrjäläb079bd172016-10-25 18:58:02 +03001154 return ERR_PTR(ret);
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001155}