blob: 4d27243656e3128305ff41e17c46b403b13e05c8 [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"
David Howells760285e2012-10-02 18:01:07 +010039#include <drm/i915_drm.h>
Jesse Barnesb840d907f2011-12-13 13:19:38 -080040#include "i915_drv.h"
41
Ville Syrjälä6ca2aeb2014-10-20 19:47:53 +030042static bool
43format_is_yuv(uint32_t format)
44{
45 switch (format) {
46 case DRM_FORMAT_YUYV:
47 case DRM_FORMAT_UYVY:
48 case DRM_FORMAT_VYUY:
49 case DRM_FORMAT_YVYU:
50 return true;
51 default:
52 return false;
53 }
54}
55
Ville Syrjälä8d7849d2014-04-29 13:35:46 +030056static int usecs_to_scanlines(const struct drm_display_mode *mode, int usecs)
57{
58 /* paranoia */
59 if (!mode->crtc_htotal)
60 return 1;
61
62 return DIV_ROUND_UP(usecs * mode->crtc_clock, 1000 * mode->crtc_htotal);
63}
64
Ander Conselvan de Oliveira26ff2762014-10-28 15:10:12 +020065/**
66 * intel_pipe_update_start() - start update of a set of display registers
67 * @crtc: the crtc of which the registers are going to be updated
68 * @start_vbl_count: vblank counter return pointer used for error checking
69 *
70 * Mark the start of an update to pipe registers that should be updated
71 * atomically regarding vblank. If the next vblank will happens within
72 * the next 100 us, this function waits until the vblank passes.
73 *
74 * After a successful call to this function, interrupts will be disabled
75 * until a subsequent call to intel_pipe_update_end(). That is done to
76 * avoid random delays. The value written to @start_vbl_count should be
77 * supplied to intel_pipe_update_end() for error checking.
Ander Conselvan de Oliveira26ff2762014-10-28 15:10:12 +020078 */
Maarten Lankhorst34e0adb2015-08-31 13:04:25 +020079void intel_pipe_update_start(struct intel_crtc *crtc)
Ville Syrjälä8d7849d2014-04-29 13:35:46 +030080{
81 struct drm_device *dev = crtc->base.dev;
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +020082 const struct drm_display_mode *mode = &crtc->config->base.adjusted_mode;
Ville Syrjälä8d7849d2014-04-29 13:35:46 +030083 enum pipe pipe = crtc->pipe;
84 long timeout = msecs_to_jiffies_timeout(1);
85 int scanline, min, max, vblank_start;
Ville Syrjälä210871b62014-05-22 19:00:50 +030086 wait_queue_head_t *wq = drm_crtc_vblank_waitqueue(&crtc->base);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +030087 DEFINE_WAIT(wait);
88
Ville Syrjälä8d7849d2014-04-29 13:35:46 +030089 vblank_start = mode->crtc_vblank_start;
90 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
91 vblank_start = DIV_ROUND_UP(vblank_start, 2);
92
93 /* FIXME needs to be calibrated sensibly */
94 min = vblank_start - usecs_to_scanlines(mode, 100);
95 max = vblank_start - 1;
96
Maarten Lankhorst8f539a832015-07-13 16:30:32 +020097 local_irq_disable();
Maarten Lankhorst34e0adb2015-08-31 13:04:25 +020098 crtc->start_vbl_count = 0;
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
Ville Syrjälä25ef2842014-04-29 13:35:48 +0300106 trace_i915_pipe_update_start(crtc, min, max);
107
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300108 for (;;) {
109 /*
110 * prepare_to_wait() has a memory barrier, which guarantees
111 * other CPUs can see the task state update by the time we
112 * read the scanline.
113 */
Ville Syrjälä210871b62014-05-22 19:00:50 +0300114 prepare_to_wait(wq, &wait, TASK_UNINTERRUPTIBLE);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300115
116 scanline = intel_get_crtc_scanline(crtc);
117 if (scanline < min || scanline > max)
118 break;
119
120 if (timeout <= 0) {
121 DRM_ERROR("Potential atomic update failure on pipe %c\n",
122 pipe_name(crtc->pipe));
123 break;
124 }
125
126 local_irq_enable();
127
128 timeout = schedule_timeout(timeout);
129
130 local_irq_disable();
131 }
132
Ville Syrjälä210871b62014-05-22 19:00:50 +0300133 finish_wait(wq, &wait);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300134
Daniel Vetter1e3feef2015-02-13 21:03:45 +0100135 drm_crtc_vblank_put(&crtc->base);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300136
Maarten Lankhorst85a62bf2015-09-01 12:15:33 +0200137 crtc->start_vbl_time = ktime_get();
Maarten Lankhorst34e0adb2015-08-31 13:04:25 +0200138 crtc->start_vbl_count = dev->driver->get_vblank_counter(dev, pipe);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300139
Maarten Lankhorst34e0adb2015-08-31 13:04:25 +0200140 trace_i915_pipe_update_vblank_evaded(crtc, min, max,
141 crtc->start_vbl_count);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300142}
143
Ander Conselvan de Oliveira26ff2762014-10-28 15:10:12 +0200144/**
145 * intel_pipe_update_end() - end update of a set of display registers
146 * @crtc: the crtc of which the registers were updated
147 * @start_vbl_count: start vblank counter (used for error checking)
148 *
149 * Mark the end of an update started with intel_pipe_update_start(). This
150 * re-enables interrupts and verifies the update was actually completed
151 * before a vblank using the value of @start_vbl_count.
152 */
Maarten Lankhorst34e0adb2015-08-31 13:04:25 +0200153void intel_pipe_update_end(struct intel_crtc *crtc)
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300154{
155 struct drm_device *dev = crtc->base.dev;
156 enum pipe pipe = crtc->pipe;
157 u32 end_vbl_count = dev->driver->get_vblank_counter(dev, pipe);
Maarten Lankhorst85a62bf2015-09-01 12:15:33 +0200158 ktime_t end_vbl_time = ktime_get();
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300159
Ville Syrjälä25ef2842014-04-29 13:35:48 +0300160 trace_i915_pipe_update_end(crtc, end_vbl_count);
161
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300162 local_irq_enable();
163
Maarten Lankhorst34e0adb2015-08-31 13:04:25 +0200164 if (crtc->start_vbl_count && crtc->start_vbl_count != end_vbl_count)
Maarten Lankhorst85a62bf2015-09-01 12:15:33 +0200165 DRM_ERROR("Atomic update failure on pipe %c (start=%u end=%u) time %lld us\n",
166 pipe_name(pipe), crtc->start_vbl_count, end_vbl_count,
167 ktime_us_delta(end_vbl_time, crtc->start_vbl_time));
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300168}
169
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800170static void
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000171skl_update_plane(struct drm_plane *drm_plane, struct drm_crtc *crtc,
172 struct drm_framebuffer *fb,
Ville Syrjäläbdd75542015-03-19 17:57:11 +0200173 int crtc_x, int crtc_y,
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000174 unsigned int crtc_w, unsigned int crtc_h,
175 uint32_t x, uint32_t y,
176 uint32_t src_w, uint32_t src_h)
177{
178 struct drm_device *dev = drm_plane->dev;
179 struct drm_i915_private *dev_priv = dev->dev_private;
180 struct intel_plane *intel_plane = to_intel_plane(drm_plane);
Ville Syrjäläbdd75542015-03-19 17:57:11 +0200181 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000182 const int pipe = intel_plane->pipe;
183 const int plane = intel_plane->plane + 1;
Sonika Jindal3b7a5112015-04-10 14:37:29 +0530184 u32 plane_ctl, stride_div, stride;
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000185 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
Maarten Lankhorst818ed962015-06-15 12:33:54 +0200186 const struct drm_intel_sprite_colorkey *key =
187 &to_intel_plane_state(drm_plane->state)->ckey;
Tvrtko Ursulin121920f2015-03-23 11:10:37 +0000188 unsigned long surf_addr;
Sonika Jindal3b7a5112015-04-10 14:37:29 +0530189 u32 tile_height, plane_offset, plane_size;
190 unsigned int rotation;
191 int x_offset, y_offset;
Chandra Konduruc3318792015-04-15 15:15:02 -0700192 struct intel_crtc_state *crtc_state = to_intel_crtc(crtc)->config;
193 int scaler_id;
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000194
Ville Syrjälä48fe4692015-03-19 17:57:13 +0200195 plane_ctl = PLANE_CTL_ENABLE |
196 PLANE_CTL_PIPE_CSC_ENABLE;
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000197
Chandra Konduruc3318792015-04-15 15:15:02 -0700198 plane_ctl |= skl_plane_ctl_format(fb->pixel_format);
199 plane_ctl |= skl_plane_ctl_tiling(fb->modifier[0]);
Damien Lespiaub3218032015-02-27 11:15:18 +0000200
Sonika Jindal3b7a5112015-04-10 14:37:29 +0530201 rotation = drm_plane->state->rotation;
Chandra Konduruc3318792015-04-15 15:15:02 -0700202 plane_ctl |= skl_plane_ctl_rotation(rotation);
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000203
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000204 intel_update_sprite_watermarks(drm_plane, crtc, src_w, src_h,
205 pixel_size, true,
206 src_w != crtc_w || src_h != crtc_h);
207
Damien Lespiaub3218032015-02-27 11:15:18 +0000208 stride_div = intel_fb_stride_alignment(dev, fb->modifier[0],
209 fb->pixel_format);
210
Chandra Konduruc3318792015-04-15 15:15:02 -0700211 scaler_id = to_intel_plane_state(drm_plane->state)->scaler_id;
212
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000213 /* Sizes are 0 based */
214 src_w--;
215 src_h--;
216 crtc_w--;
217 crtc_h--;
218
Ville Syrjälä47ecbb22015-03-19 21:18:57 +0200219 if (key->flags) {
220 I915_WRITE(PLANE_KEYVAL(pipe, plane), key->min_value);
221 I915_WRITE(PLANE_KEYMAX(pipe, plane), key->max_value);
222 I915_WRITE(PLANE_KEYMSK(pipe, plane), key->channel_mask);
223 }
224
225 if (key->flags & I915_SET_COLORKEY_DESTINATION)
226 plane_ctl |= PLANE_CTL_KEY_ENABLE_DESTINATION;
227 else if (key->flags & I915_SET_COLORKEY_SOURCE)
228 plane_ctl |= PLANE_CTL_KEY_ENABLE_SOURCE;
229
Tvrtko Ursulin121920f2015-03-23 11:10:37 +0000230 surf_addr = intel_plane_obj_offset(intel_plane, obj);
231
Sonika Jindal3b7a5112015-04-10 14:37:29 +0530232 if (intel_rotation_90_or_270(rotation)) {
233 /* stride: Surface height in tiles */
Chandra Konduru2614f172015-05-08 20:22:46 -0700234 tile_height = intel_tile_height(dev, fb->pixel_format,
235 fb->modifier[0]);
Sonika Jindal3b7a5112015-04-10 14:37:29 +0530236 stride = DIV_ROUND_UP(fb->height, tile_height);
237 plane_size = (src_w << 16) | src_h;
238 x_offset = stride * tile_height - y - (src_h + 1);
239 y_offset = x;
240 } else {
241 stride = fb->pitches[0] / stride_div;
242 plane_size = (src_h << 16) | src_w;
243 x_offset = x;
244 y_offset = y;
245 }
246 plane_offset = y_offset << 16 | x_offset;
247
248 I915_WRITE(PLANE_OFFSET(pipe, plane), plane_offset);
249 I915_WRITE(PLANE_STRIDE(pipe, plane), stride);
Sonika Jindal3b7a5112015-04-10 14:37:29 +0530250 I915_WRITE(PLANE_SIZE(pipe, plane), plane_size);
Chandra Konduruc3318792015-04-15 15:15:02 -0700251
252 /* program plane scaler */
253 if (scaler_id >= 0) {
254 uint32_t ps_ctrl = 0;
255
256 DRM_DEBUG_KMS("plane = %d PS_PLANE_SEL(plane) = 0x%x\n", plane,
257 PS_PLANE_SEL(plane));
258 ps_ctrl = PS_SCALER_EN | PS_PLANE_SEL(plane) |
259 crtc_state->scaler_state.scalers[scaler_id].mode;
260 I915_WRITE(SKL_PS_CTRL(pipe, scaler_id), ps_ctrl);
261 I915_WRITE(SKL_PS_PWR_GATE(pipe, scaler_id), 0);
262 I915_WRITE(SKL_PS_WIN_POS(pipe, scaler_id), (crtc_x << 16) | crtc_y);
263 I915_WRITE(SKL_PS_WIN_SZ(pipe, scaler_id),
264 ((crtc_w + 1) << 16)|(crtc_h + 1));
265
266 I915_WRITE(PLANE_POS(pipe, plane), 0);
267 } else {
268 I915_WRITE(PLANE_POS(pipe, plane), (crtc_y << 16) | crtc_x);
269 }
270
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000271 I915_WRITE(PLANE_CTL(pipe, plane), plane_ctl);
Tvrtko Ursulin121920f2015-03-23 11:10:37 +0000272 I915_WRITE(PLANE_SURF(pipe, plane), surf_addr);
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000273 POSTING_READ(PLANE_SURF(pipe, plane));
274}
275
276static void
Maarten Lankhorst7fabf5e2015-06-15 12:33:47 +0200277skl_disable_plane(struct drm_plane *dplane, struct drm_crtc *crtc)
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000278{
Maarten Lankhorsta8ad0d82015-04-21 17:12:51 +0300279 struct drm_device *dev = dplane->dev;
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000280 struct drm_i915_private *dev_priv = dev->dev_private;
Maarten Lankhorsta8ad0d82015-04-21 17:12:51 +0300281 struct intel_plane *intel_plane = to_intel_plane(dplane);
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000282 const int pipe = intel_plane->pipe;
283 const int plane = intel_plane->plane + 1;
284
Ville Syrjälä48fe4692015-03-19 17:57:13 +0200285 I915_WRITE(PLANE_CTL(pipe, plane), 0);
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000286
Ville Syrjälä2ddc1da2015-03-19 17:57:14 +0200287 I915_WRITE(PLANE_SURF(pipe, plane), 0);
288 POSTING_READ(PLANE_SURF(pipe, plane));
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000289
Maarten Lankhorsta8ad0d82015-04-21 17:12:51 +0300290 intel_update_sprite_watermarks(dplane, crtc, 0, 0, 0, false, false);
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000291}
292
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000293static void
Ville Syrjälä6ca2aeb2014-10-20 19:47:53 +0300294chv_update_csc(struct intel_plane *intel_plane, uint32_t format)
295{
296 struct drm_i915_private *dev_priv = intel_plane->base.dev->dev_private;
297 int plane = intel_plane->plane;
298
299 /* Seems RGB data bypasses the CSC always */
300 if (!format_is_yuv(format))
301 return;
302
303 /*
304 * BT.601 limited range YCbCr -> full range RGB
305 *
306 * |r| | 6537 4769 0| |cr |
307 * |g| = |-3330 4769 -1605| x |y-64|
308 * |b| | 0 4769 8263| |cb |
309 *
310 * Cb and Cr apparently come in as signed already, so no
311 * need for any offset. For Y we need to remove the offset.
312 */
313 I915_WRITE(SPCSCYGOFF(plane), SPCSC_OOFF(0) | SPCSC_IOFF(-64));
314 I915_WRITE(SPCSCCBOFF(plane), SPCSC_OOFF(0) | SPCSC_IOFF(0));
315 I915_WRITE(SPCSCCROFF(plane), SPCSC_OOFF(0) | SPCSC_IOFF(0));
316
317 I915_WRITE(SPCSCC01(plane), SPCSC_C1(4769) | SPCSC_C0(6537));
318 I915_WRITE(SPCSCC23(plane), SPCSC_C1(-3330) | SPCSC_C0(0));
319 I915_WRITE(SPCSCC45(plane), SPCSC_C1(-1605) | SPCSC_C0(4769));
320 I915_WRITE(SPCSCC67(plane), SPCSC_C1(4769) | SPCSC_C0(0));
321 I915_WRITE(SPCSCC8(plane), SPCSC_C0(8263));
322
323 I915_WRITE(SPCSCYGICLAMP(plane), SPCSC_IMAX(940) | SPCSC_IMIN(64));
324 I915_WRITE(SPCSCCBICLAMP(plane), SPCSC_IMAX(448) | SPCSC_IMIN(-448));
325 I915_WRITE(SPCSCCRICLAMP(plane), SPCSC_IMAX(448) | SPCSC_IMIN(-448));
326
327 I915_WRITE(SPCSCYGOCLAMP(plane), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
328 I915_WRITE(SPCSCCBOCLAMP(plane), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
329 I915_WRITE(SPCSCCROCLAMP(plane), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
330}
331
332static void
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300333vlv_update_plane(struct drm_plane *dplane, struct drm_crtc *crtc,
334 struct drm_framebuffer *fb,
Ville Syrjäläbdd75542015-03-19 17:57:11 +0200335 int crtc_x, int crtc_y,
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700336 unsigned int crtc_w, unsigned int crtc_h,
337 uint32_t x, uint32_t y,
338 uint32_t src_w, uint32_t src_h)
339{
340 struct drm_device *dev = dplane->dev;
341 struct drm_i915_private *dev_priv = dev->dev_private;
342 struct intel_plane *intel_plane = to_intel_plane(dplane);
Ville Syrjäläbdd75542015-03-19 17:57:11 +0200343 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700344 int pipe = intel_plane->pipe;
345 int plane = intel_plane->plane;
346 u32 sprctl;
347 unsigned long sprsurf_offset, linear_offset;
348 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
Maarten Lankhorst818ed962015-06-15 12:33:54 +0200349 const struct drm_intel_sprite_colorkey *key =
350 &to_intel_plane_state(dplane->state)->ckey;
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700351
Ville Syrjälä48fe4692015-03-19 17:57:13 +0200352 sprctl = SP_ENABLE;
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700353
354 switch (fb->pixel_format) {
355 case DRM_FORMAT_YUYV:
356 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YUYV;
357 break;
358 case DRM_FORMAT_YVYU:
359 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YVYU;
360 break;
361 case DRM_FORMAT_UYVY:
362 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_UYVY;
363 break;
364 case DRM_FORMAT_VYUY:
365 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_VYUY;
366 break;
367 case DRM_FORMAT_RGB565:
368 sprctl |= SP_FORMAT_BGR565;
369 break;
370 case DRM_FORMAT_XRGB8888:
371 sprctl |= SP_FORMAT_BGRX8888;
372 break;
373 case DRM_FORMAT_ARGB8888:
374 sprctl |= SP_FORMAT_BGRA8888;
375 break;
376 case DRM_FORMAT_XBGR2101010:
377 sprctl |= SP_FORMAT_RGBX1010102;
378 break;
379 case DRM_FORMAT_ABGR2101010:
380 sprctl |= SP_FORMAT_RGBA1010102;
381 break;
382 case DRM_FORMAT_XBGR8888:
383 sprctl |= SP_FORMAT_RGBX8888;
384 break;
385 case DRM_FORMAT_ABGR8888:
386 sprctl |= SP_FORMAT_RGBA8888;
387 break;
388 default:
389 /*
390 * If we get here one of the upper layers failed to filter
391 * out the unsupported plane formats
392 */
393 BUG();
394 break;
395 }
396
Ville Syrjälä4ea67bc2013-11-18 18:32:38 -0800397 /*
398 * Enable gamma to match primary/cursor plane behaviour.
399 * FIXME should be user controllable via propertiesa.
400 */
401 sprctl |= SP_GAMMA_ENABLE;
402
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700403 if (obj->tiling_mode != I915_TILING_NONE)
404 sprctl |= SP_TILED;
405
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700406 /* Sizes are 0 based */
407 src_w--;
408 src_h--;
409 crtc_w--;
410 crtc_h--;
411
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700412 linear_offset = y * fb->pitches[0] + x * pixel_size;
Ville Syrjälä4e9a86b2015-06-11 16:31:14 +0300413 sprsurf_offset = intel_gen4_compute_page_offset(dev_priv,
414 &x, &y,
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700415 obj->tiling_mode,
416 pixel_size,
417 fb->pitches[0]);
418 linear_offset -= sprsurf_offset;
419
Matt Roper8e7d6882015-01-21 16:35:41 -0800420 if (dplane->state->rotation == BIT(DRM_ROTATE_180)) {
Ville Syrjälä76eebda2014-08-05 11:26:52 +0530421 sprctl |= SP_ROTATE_180;
422
423 x += src_w;
424 y += src_h;
425 linear_offset += src_h * fb->pitches[0] + src_w * pixel_size;
426 }
427
Ville Syrjälä47ecbb22015-03-19 21:18:57 +0200428 if (key->flags) {
429 I915_WRITE(SPKEYMINVAL(pipe, plane), key->min_value);
430 I915_WRITE(SPKEYMAXVAL(pipe, plane), key->max_value);
431 I915_WRITE(SPKEYMSK(pipe, plane), key->channel_mask);
432 }
433
434 if (key->flags & I915_SET_COLORKEY_SOURCE)
435 sprctl |= SP_SOURCE_KEY;
436
Ville Syrjälä6ca2aeb2014-10-20 19:47:53 +0300437 if (IS_CHERRYVIEW(dev) && pipe == PIPE_B)
438 chv_update_csc(intel_plane, fb->pixel_format);
439
Ville Syrjäläca6ad022014-01-17 20:09:03 +0200440 I915_WRITE(SPSTRIDE(pipe, plane), fb->pitches[0]);
441 I915_WRITE(SPPOS(pipe, plane), (crtc_y << 16) | crtc_x);
442
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700443 if (obj->tiling_mode != I915_TILING_NONE)
444 I915_WRITE(SPTILEOFF(pipe, plane), (y << 16) | x);
445 else
446 I915_WRITE(SPLINOFF(pipe, plane), linear_offset);
447
Ville Syrjäläc14b0482014-10-16 20:52:34 +0300448 I915_WRITE(SPCONSTALPHA(pipe, plane), 0);
449
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700450 I915_WRITE(SPSIZE(pipe, plane), (crtc_h << 16) | crtc_w);
451 I915_WRITE(SPCNTR(pipe, plane), sprctl);
Daniel Vetter85ba7b72014-01-24 10:31:44 +0100452 I915_WRITE(SPSURF(pipe, plane), i915_gem_obj_ggtt_offset(obj) +
453 sprsurf_offset);
Ville Syrjäläb12ce1d2015-05-26 20:27:23 +0300454 POSTING_READ(SPSURF(pipe, plane));
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700455}
456
457static void
Maarten Lankhorst7fabf5e2015-06-15 12:33:47 +0200458vlv_disable_plane(struct drm_plane *dplane, struct drm_crtc *crtc)
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700459{
460 struct drm_device *dev = dplane->dev;
461 struct drm_i915_private *dev_priv = dev->dev_private;
462 struct intel_plane *intel_plane = to_intel_plane(dplane);
463 int pipe = intel_plane->pipe;
464 int plane = intel_plane->plane;
465
Ville Syrjälä48fe4692015-03-19 17:57:13 +0200466 I915_WRITE(SPCNTR(pipe, plane), 0);
467
Daniel Vetter85ba7b72014-01-24 10:31:44 +0100468 I915_WRITE(SPSURF(pipe, plane), 0);
Ville Syrjäläb12ce1d2015-05-26 20:27:23 +0300469 POSTING_READ(SPSURF(pipe, plane));
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700470}
471
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700472static void
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300473ivb_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
474 struct drm_framebuffer *fb,
Ville Syrjäläbdd75542015-03-19 17:57:11 +0200475 int crtc_x, int crtc_y,
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800476 unsigned int crtc_w, unsigned int crtc_h,
477 uint32_t x, uint32_t y,
478 uint32_t src_w, uint32_t src_h)
479{
480 struct drm_device *dev = plane->dev;
481 struct drm_i915_private *dev_priv = dev->dev_private;
482 struct intel_plane *intel_plane = to_intel_plane(plane);
Ville Syrjäläbdd75542015-03-19 17:57:11 +0200483 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Ville Syrjälä47ecbb22015-03-19 21:18:57 +0200484 enum pipe pipe = intel_plane->pipe;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800485 u32 sprctl, sprscale = 0;
Damien Lespiau5a35e992012-10-26 18:20:12 +0100486 unsigned long sprsurf_offset, linear_offset;
Ville Syrjälä2bd3c3c2012-10-31 17:50:20 +0200487 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
Maarten Lankhorst818ed962015-06-15 12:33:54 +0200488 const struct drm_intel_sprite_colorkey *key =
489 &to_intel_plane_state(plane->state)->ckey;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800490
Ville Syrjälä48fe4692015-03-19 17:57:13 +0200491 sprctl = SPRITE_ENABLE;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800492
493 switch (fb->pixel_format) {
494 case DRM_FORMAT_XBGR8888:
Vijay Purushothaman5ee36912012-08-23 12:08:57 +0530495 sprctl |= SPRITE_FORMAT_RGBX888 | SPRITE_RGB_ORDER_RGBX;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800496 break;
497 case DRM_FORMAT_XRGB8888:
Vijay Purushothaman5ee36912012-08-23 12:08:57 +0530498 sprctl |= SPRITE_FORMAT_RGBX888;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800499 break;
500 case DRM_FORMAT_YUYV:
501 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YUYV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800502 break;
503 case DRM_FORMAT_YVYU:
504 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YVYU;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800505 break;
506 case DRM_FORMAT_UYVY:
507 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_UYVY;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800508 break;
509 case DRM_FORMAT_VYUY:
510 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_VYUY;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800511 break;
512 default:
Ville Syrjälä28d491d2012-10-31 17:50:21 +0200513 BUG();
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800514 }
515
Ville Syrjälä4ea67bc2013-11-18 18:32:38 -0800516 /*
517 * Enable gamma to match primary/cursor plane behaviour.
518 * FIXME should be user controllable via propertiesa.
519 */
520 sprctl |= SPRITE_GAMMA_ENABLE;
521
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800522 if (obj->tiling_mode != I915_TILING_NONE)
523 sprctl |= SPRITE_TILED;
524
Ville Syrjäläb42c6002013-11-03 13:47:27 +0200525 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Paulo Zanoni1f5d76d2013-08-23 19:51:28 -0300526 sprctl &= ~SPRITE_TRICKLE_FEED_DISABLE;
527 else
528 sprctl |= SPRITE_TRICKLE_FEED_DISABLE;
529
Ville Syrjälä6bbfa1c2013-11-02 21:07:39 -0700530 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Ville Syrjälä86d3efc2013-01-18 19:11:38 +0200531 sprctl |= SPRITE_PIPE_CSC_ENABLE;
532
Damien Lespiaued57cb82014-07-15 09:21:24 +0200533 intel_update_sprite_watermarks(plane, crtc, src_w, src_h, pixel_size,
534 true,
Ville Syrjälä67ca28f2013-07-05 11:57:14 +0300535 src_w != crtc_w || src_h != crtc_h);
536
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800537 /* Sizes are 0 based */
538 src_w--;
539 src_h--;
540 crtc_w--;
541 crtc_h--;
542
Ville Syrjälä8553c182013-12-05 15:51:39 +0200543 if (crtc_w != src_w || crtc_h != src_h)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800544 sprscale = SPRITE_SCALE_ENABLE | (src_w << 16) | src_h;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800545
Chris Wilsonca320ac2012-12-19 12:14:22 +0000546 linear_offset = y * fb->pitches[0] + x * pixel_size;
Damien Lespiau5a35e992012-10-26 18:20:12 +0100547 sprsurf_offset =
Ville Syrjälä4e9a86b2015-06-11 16:31:14 +0300548 intel_gen4_compute_page_offset(dev_priv,
549 &x, &y, obj->tiling_mode,
Chris Wilsonbc752862013-02-21 20:04:31 +0000550 pixel_size, fb->pitches[0]);
Damien Lespiau5a35e992012-10-26 18:20:12 +0100551 linear_offset -= sprsurf_offset;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800552
Matt Roper8e7d6882015-01-21 16:35:41 -0800553 if (plane->state->rotation == BIT(DRM_ROTATE_180)) {
Ville Syrjälä76eebda2014-08-05 11:26:52 +0530554 sprctl |= SPRITE_ROTATE_180;
555
556 /* HSW and BDW does this automagically in hardware */
557 if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) {
558 x += src_w;
559 y += src_h;
560 linear_offset += src_h * fb->pitches[0] +
561 src_w * pixel_size;
562 }
563 }
564
Ville Syrjälä47ecbb22015-03-19 21:18:57 +0200565 if (key->flags) {
566 I915_WRITE(SPRKEYVAL(pipe), key->min_value);
567 I915_WRITE(SPRKEYMAX(pipe), key->max_value);
568 I915_WRITE(SPRKEYMSK(pipe), key->channel_mask);
569 }
570
571 if (key->flags & I915_SET_COLORKEY_DESTINATION)
572 sprctl |= SPRITE_DEST_KEY;
573 else if (key->flags & I915_SET_COLORKEY_SOURCE)
574 sprctl |= SPRITE_SOURCE_KEY;
575
Ville Syrjäläca6ad022014-01-17 20:09:03 +0200576 I915_WRITE(SPRSTRIDE(pipe), fb->pitches[0]);
577 I915_WRITE(SPRPOS(pipe), (crtc_y << 16) | crtc_x);
578
Damien Lespiau5a35e992012-10-26 18:20:12 +0100579 /* HSW consolidates SPRTILEOFF and SPRLINOFF into a single SPROFFSET
580 * register */
Paulo Zanonib3dc6852013-11-02 21:07:33 -0700581 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Damien Lespiau5a35e992012-10-26 18:20:12 +0100582 I915_WRITE(SPROFFSET(pipe), (y << 16) | x);
583 else if (obj->tiling_mode != I915_TILING_NONE)
584 I915_WRITE(SPRTILEOFF(pipe), (y << 16) | x);
585 else
586 I915_WRITE(SPRLINOFF(pipe), linear_offset);
Damien Lespiauc54173a2012-10-26 18:20:11 +0100587
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800588 I915_WRITE(SPRSIZE(pipe), (crtc_h << 16) | crtc_w);
Damien Lespiau2d354c32012-10-22 18:19:27 +0100589 if (intel_plane->can_scale)
590 I915_WRITE(SPRSCALE(pipe), sprscale);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800591 I915_WRITE(SPRCTL(pipe), sprctl);
Daniel Vetter85ba7b72014-01-24 10:31:44 +0100592 I915_WRITE(SPRSURF(pipe),
593 i915_gem_obj_ggtt_offset(obj) + sprsurf_offset);
Ville Syrjäläb12ce1d2015-05-26 20:27:23 +0300594 POSTING_READ(SPRSURF(pipe));
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800595}
596
597static void
Maarten Lankhorst7fabf5e2015-06-15 12:33:47 +0200598ivb_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800599{
600 struct drm_device *dev = plane->dev;
601 struct drm_i915_private *dev_priv = dev->dev_private;
602 struct intel_plane *intel_plane = to_intel_plane(plane);
603 int pipe = intel_plane->pipe;
604
605 I915_WRITE(SPRCTL(pipe), I915_READ(SPRCTL(pipe)) & ~SPRITE_ENABLE);
606 /* Can't leave the scaler enabled... */
Damien Lespiau2d354c32012-10-22 18:19:27 +0100607 if (intel_plane->can_scale)
608 I915_WRITE(SPRSCALE(pipe), 0);
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300609
Ville Syrjäläb12ce1d2015-05-26 20:27:23 +0300610 I915_WRITE(SPRSURF(pipe), 0);
611 POSTING_READ(SPRSURF(pipe));
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800612}
613
614static void
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300615ilk_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
616 struct drm_framebuffer *fb,
Ville Syrjäläbdd75542015-03-19 17:57:11 +0200617 int crtc_x, int crtc_y,
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800618 unsigned int crtc_w, unsigned int crtc_h,
619 uint32_t x, uint32_t y,
620 uint32_t src_w, uint32_t src_h)
621{
622 struct drm_device *dev = plane->dev;
623 struct drm_i915_private *dev_priv = dev->dev_private;
624 struct intel_plane *intel_plane = to_intel_plane(plane);
Ville Syrjäläbdd75542015-03-19 17:57:11 +0200625 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Ville Syrjälä2bd3c3c2012-10-31 17:50:20 +0200626 int pipe = intel_plane->pipe;
Damien Lespiau5a35e992012-10-26 18:20:12 +0100627 unsigned long dvssurf_offset, linear_offset;
Chris Wilson8aaa81a2012-04-14 22:14:26 +0100628 u32 dvscntr, dvsscale;
Ville Syrjälä2bd3c3c2012-10-31 17:50:20 +0200629 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
Maarten Lankhorst818ed962015-06-15 12:33:54 +0200630 const struct drm_intel_sprite_colorkey *key =
631 &to_intel_plane_state(plane->state)->ckey;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800632
Ville Syrjälä48fe4692015-03-19 17:57:13 +0200633 dvscntr = DVS_ENABLE;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800634
635 switch (fb->pixel_format) {
636 case DRM_FORMAT_XBGR8888:
Jesse Barnesab2f9df2012-02-27 12:40:10 -0800637 dvscntr |= DVS_FORMAT_RGBX888 | DVS_RGB_ORDER_XBGR;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800638 break;
639 case DRM_FORMAT_XRGB8888:
Jesse Barnesab2f9df2012-02-27 12:40:10 -0800640 dvscntr |= DVS_FORMAT_RGBX888;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800641 break;
642 case DRM_FORMAT_YUYV:
643 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YUYV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800644 break;
645 case DRM_FORMAT_YVYU:
646 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YVYU;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800647 break;
648 case DRM_FORMAT_UYVY:
649 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_UYVY;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800650 break;
651 case DRM_FORMAT_VYUY:
652 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_VYUY;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800653 break;
654 default:
Ville Syrjälä28d491d2012-10-31 17:50:21 +0200655 BUG();
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800656 }
657
Ville Syrjälä4ea67bc2013-11-18 18:32:38 -0800658 /*
659 * Enable gamma to match primary/cursor plane behaviour.
660 * FIXME should be user controllable via propertiesa.
661 */
662 dvscntr |= DVS_GAMMA_ENABLE;
663
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800664 if (obj->tiling_mode != I915_TILING_NONE)
665 dvscntr |= DVS_TILED;
666
Chris Wilsond1686ae2012-04-10 11:41:49 +0100667 if (IS_GEN6(dev))
668 dvscntr |= DVS_TRICKLE_FEED_DISABLE; /* must disable */
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800669
Damien Lespiaued57cb82014-07-15 09:21:24 +0200670 intel_update_sprite_watermarks(plane, crtc, src_w, src_h,
671 pixel_size, true,
Ville Syrjälä67ca28f2013-07-05 11:57:14 +0300672 src_w != crtc_w || src_h != crtc_h);
673
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800674 /* Sizes are 0 based */
675 src_w--;
676 src_h--;
677 crtc_w--;
678 crtc_h--;
679
Chris Wilson8aaa81a2012-04-14 22:14:26 +0100680 dvsscale = 0;
Ville Syrjälä8368f012013-12-05 15:51:31 +0200681 if (crtc_w != src_w || crtc_h != src_h)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800682 dvsscale = DVS_SCALE_ENABLE | (src_w << 16) | src_h;
683
Chris Wilsonca320ac2012-12-19 12:14:22 +0000684 linear_offset = y * fb->pitches[0] + x * pixel_size;
Damien Lespiau5a35e992012-10-26 18:20:12 +0100685 dvssurf_offset =
Ville Syrjälä4e9a86b2015-06-11 16:31:14 +0300686 intel_gen4_compute_page_offset(dev_priv,
687 &x, &y, obj->tiling_mode,
Chris Wilsonbc752862013-02-21 20:04:31 +0000688 pixel_size, fb->pitches[0]);
Damien Lespiau5a35e992012-10-26 18:20:12 +0100689 linear_offset -= dvssurf_offset;
690
Matt Roper8e7d6882015-01-21 16:35:41 -0800691 if (plane->state->rotation == BIT(DRM_ROTATE_180)) {
Ville Syrjälä76eebda2014-08-05 11:26:52 +0530692 dvscntr |= DVS_ROTATE_180;
693
694 x += src_w;
695 y += src_h;
696 linear_offset += src_h * fb->pitches[0] + src_w * pixel_size;
697 }
698
Ville Syrjälä47ecbb22015-03-19 21:18:57 +0200699 if (key->flags) {
700 I915_WRITE(DVSKEYVAL(pipe), key->min_value);
701 I915_WRITE(DVSKEYMAX(pipe), key->max_value);
702 I915_WRITE(DVSKEYMSK(pipe), key->channel_mask);
703 }
704
705 if (key->flags & I915_SET_COLORKEY_DESTINATION)
706 dvscntr |= DVS_DEST_KEY;
707 else if (key->flags & I915_SET_COLORKEY_SOURCE)
708 dvscntr |= DVS_SOURCE_KEY;
709
Ville Syrjäläca6ad022014-01-17 20:09:03 +0200710 I915_WRITE(DVSSTRIDE(pipe), fb->pitches[0]);
711 I915_WRITE(DVSPOS(pipe), (crtc_y << 16) | crtc_x);
712
Damien Lespiau5a35e992012-10-26 18:20:12 +0100713 if (obj->tiling_mode != I915_TILING_NONE)
714 I915_WRITE(DVSTILEOFF(pipe), (y << 16) | x);
715 else
716 I915_WRITE(DVSLINOFF(pipe), linear_offset);
717
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800718 I915_WRITE(DVSSIZE(pipe), (crtc_h << 16) | crtc_w);
719 I915_WRITE(DVSSCALE(pipe), dvsscale);
720 I915_WRITE(DVSCNTR(pipe), dvscntr);
Daniel Vetter85ba7b72014-01-24 10:31:44 +0100721 I915_WRITE(DVSSURF(pipe),
722 i915_gem_obj_ggtt_offset(obj) + dvssurf_offset);
Ville Syrjäläb12ce1d2015-05-26 20:27:23 +0300723 POSTING_READ(DVSSURF(pipe));
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800724}
725
726static void
Maarten Lankhorst7fabf5e2015-06-15 12:33:47 +0200727ilk_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800728{
729 struct drm_device *dev = plane->dev;
730 struct drm_i915_private *dev_priv = dev->dev_private;
731 struct intel_plane *intel_plane = to_intel_plane(plane);
732 int pipe = intel_plane->pipe;
733
Ville Syrjälä48fe4692015-03-19 17:57:13 +0200734 I915_WRITE(DVSCNTR(pipe), 0);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800735 /* Disable the scaler */
736 I915_WRITE(DVSSCALE(pipe), 0);
Ville Syrjälä48fe4692015-03-19 17:57:13 +0200737
Daniel Vetter85ba7b72014-01-24 10:31:44 +0100738 I915_WRITE(DVSSURF(pipe), 0);
Ville Syrjäläb12ce1d2015-05-26 20:27:23 +0300739 POSTING_READ(DVSSURF(pipe));
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800740}
741
Jesse Barnes8ea30862012-01-03 08:05:39 -0800742static int
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300743intel_check_sprite_plane(struct drm_plane *plane,
Maarten Lankhorst061e4b82015-06-15 12:33:46 +0200744 struct intel_crtc_state *crtc_state,
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300745 struct intel_plane_state *state)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800746{
Chandra Konduruc3318792015-04-15 15:15:02 -0700747 struct drm_device *dev = plane->dev;
Maarten Lankhorst061e4b82015-06-15 12:33:46 +0200748 struct drm_crtc *crtc = state->base.crtc;
749 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800750 struct intel_plane *intel_plane = to_intel_plane(plane);
Matt Roper2b875c22014-12-01 15:40:13 -0800751 struct drm_framebuffer *fb = state->base.fb;
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300752 int crtc_x, crtc_y;
753 unsigned int crtc_w, crtc_h;
754 uint32_t src_x, src_y, src_w, src_h;
755 struct drm_rect *src = &state->src;
756 struct drm_rect *dst = &state->dst;
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300757 const struct drm_rect *clip = &state->clip;
Ville Syrjälä17316932013-04-24 18:52:38 +0300758 int hscale, vscale;
759 int max_scale, min_scale;
Chandra Konduru225c2282015-05-18 16:18:44 -0700760 bool can_scale;
Matt Ropercf4c7c12014-12-04 10:27:42 -0800761 int pixel_size;
762
763 if (!fb) {
764 state->visible = false;
Maarten Lankhorstda20eab2015-06-15 12:33:44 +0200765 return 0;
Matt Ropercf4c7c12014-12-04 10:27:42 -0800766 }
Jesse Barnes5e1bac22013-03-26 09:25:43 -0700767
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800768 /* Don't modify another pipe's plane */
Ville Syrjälä17316932013-04-24 18:52:38 +0300769 if (intel_plane->pipe != intel_crtc->pipe) {
770 DRM_DEBUG_KMS("Wrong plane <-> crtc mapping\n");
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800771 return -EINVAL;
Ville Syrjälä17316932013-04-24 18:52:38 +0300772 }
773
774 /* FIXME check all gen limits */
775 if (fb->width < 3 || fb->height < 3 || fb->pitches[0] > 16384) {
776 DRM_DEBUG_KMS("Unsuitable framebuffer for plane\n");
777 return -EINVAL;
778 }
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800779
Chandra Konduru225c2282015-05-18 16:18:44 -0700780 /* setup can_scale, min_scale, max_scale */
781 if (INTEL_INFO(dev)->gen >= 9) {
782 /* use scaler when colorkey is not required */
Maarten Lankhorst818ed962015-06-15 12:33:54 +0200783 if (state->ckey.flags == I915_SET_COLORKEY_NONE) {
Chandra Konduru225c2282015-05-18 16:18:44 -0700784 can_scale = 1;
785 min_scale = 1;
786 max_scale = skl_max_scale(intel_crtc, crtc_state);
787 } else {
788 can_scale = 0;
789 min_scale = DRM_PLANE_HELPER_NO_SCALING;
790 max_scale = DRM_PLANE_HELPER_NO_SCALING;
791 }
792 } else {
793 can_scale = intel_plane->can_scale;
794 max_scale = intel_plane->max_downscale << 16;
795 min_scale = intel_plane->can_scale ? 1 : (1 << 16);
796 }
797
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300798 /*
799 * FIXME the following code does a bunch of fuzzy adjustments to the
800 * coordinates and sizes. We probably need some way to decide whether
801 * more strict checking should be done instead.
802 */
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300803 drm_rect_rotate(src, fb->width << 16, fb->height << 16,
Matt Roper8e7d6882015-01-21 16:35:41 -0800804 state->base.rotation);
Ville Syrjälä76eebda2014-08-05 11:26:52 +0530805
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300806 hscale = drm_rect_calc_hscale_relaxed(src, dst, min_scale, max_scale);
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300807 BUG_ON(hscale < 0);
Ville Syrjälä17316932013-04-24 18:52:38 +0300808
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300809 vscale = drm_rect_calc_vscale_relaxed(src, dst, min_scale, max_scale);
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300810 BUG_ON(vscale < 0);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800811
Maarten Lankhorst818ed962015-06-15 12:33:54 +0200812 state->visible = drm_rect_clip_scaled(src, dst, clip, hscale, vscale);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800813
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300814 crtc_x = dst->x1;
815 crtc_y = dst->y1;
816 crtc_w = drm_rect_width(dst);
817 crtc_h = drm_rect_height(dst);
Damien Lespiau2d354c32012-10-22 18:19:27 +0100818
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300819 if (state->visible) {
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300820 /* check again in case clipping clamped the results */
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300821 hscale = drm_rect_calc_hscale(src, dst, min_scale, max_scale);
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300822 if (hscale < 0) {
823 DRM_DEBUG_KMS("Horizontal scaling factor out of limits\n");
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300824 drm_rect_debug_print(src, true);
825 drm_rect_debug_print(dst, false);
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300826
827 return hscale;
828 }
829
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300830 vscale = drm_rect_calc_vscale(src, dst, min_scale, max_scale);
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300831 if (vscale < 0) {
832 DRM_DEBUG_KMS("Vertical scaling factor out of limits\n");
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300833 drm_rect_debug_print(src, true);
834 drm_rect_debug_print(dst, false);
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300835
836 return vscale;
837 }
838
Ville Syrjälä17316932013-04-24 18:52:38 +0300839 /* Make the source viewport size an exact multiple of the scaling factors. */
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300840 drm_rect_adjust_size(src,
841 drm_rect_width(dst) * hscale - drm_rect_width(src),
842 drm_rect_height(dst) * vscale - drm_rect_height(src));
Ville Syrjälä17316932013-04-24 18:52:38 +0300843
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300844 drm_rect_rotate_inv(src, fb->width << 16, fb->height << 16,
Matt Roper8e7d6882015-01-21 16:35:41 -0800845 state->base.rotation);
Ville Syrjälä76eebda2014-08-05 11:26:52 +0530846
Ville Syrjälä17316932013-04-24 18:52:38 +0300847 /* sanity check to make sure the src viewport wasn't enlarged */
Matt Roperea2c67b2014-12-23 10:41:52 -0800848 WARN_ON(src->x1 < (int) state->base.src_x ||
849 src->y1 < (int) state->base.src_y ||
850 src->x2 > (int) state->base.src_x + state->base.src_w ||
851 src->y2 > (int) state->base.src_y + state->base.src_h);
Ville Syrjälä17316932013-04-24 18:52:38 +0300852
853 /*
854 * Hardware doesn't handle subpixel coordinates.
855 * Adjust to (macro)pixel boundary, but be careful not to
856 * increase the source viewport size, because that could
857 * push the downscaling factor out of bounds.
Ville Syrjälä17316932013-04-24 18:52:38 +0300858 */
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300859 src_x = src->x1 >> 16;
860 src_w = drm_rect_width(src) >> 16;
861 src_y = src->y1 >> 16;
862 src_h = drm_rect_height(src) >> 16;
Ville Syrjälä17316932013-04-24 18:52:38 +0300863
864 if (format_is_yuv(fb->pixel_format)) {
865 src_x &= ~1;
866 src_w &= ~1;
867
868 /*
869 * Must keep src and dst the
870 * same if we can't scale.
871 */
Chandra Konduru225c2282015-05-18 16:18:44 -0700872 if (!can_scale)
Ville Syrjälä17316932013-04-24 18:52:38 +0300873 crtc_w &= ~1;
874
875 if (crtc_w == 0)
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300876 state->visible = false;
Ville Syrjälä17316932013-04-24 18:52:38 +0300877 }
878 }
879
880 /* Check size restrictions when scaling */
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300881 if (state->visible && (src_w != crtc_w || src_h != crtc_h)) {
Ville Syrjälä17316932013-04-24 18:52:38 +0300882 unsigned int width_bytes;
883
Chandra Konduru225c2282015-05-18 16:18:44 -0700884 WARN_ON(!can_scale);
Ville Syrjälä17316932013-04-24 18:52:38 +0300885
886 /* FIXME interlacing min height is 6 */
887
888 if (crtc_w < 3 || crtc_h < 3)
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300889 state->visible = false;
Ville Syrjälä17316932013-04-24 18:52:38 +0300890
891 if (src_w < 3 || src_h < 3)
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300892 state->visible = false;
Ville Syrjälä17316932013-04-24 18:52:38 +0300893
Matt Ropercf4c7c12014-12-04 10:27:42 -0800894 pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300895 width_bytes = ((src_x * pixel_size) & 63) +
896 src_w * pixel_size;
Ville Syrjälä17316932013-04-24 18:52:38 +0300897
Chandra Konduruc3318792015-04-15 15:15:02 -0700898 if (INTEL_INFO(dev)->gen < 9 && (src_w > 2048 || src_h > 2048 ||
899 width_bytes > 4096 || fb->pitches[0] > 4096)) {
Ville Syrjälä17316932013-04-24 18:52:38 +0300900 DRM_DEBUG_KMS("Source dimensions exceed hardware limits\n");
901 return -EINVAL;
902 }
903 }
904
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300905 if (state->visible) {
Chandra Konduru0a5ae1b2015-04-09 16:41:54 -0700906 src->x1 = src_x << 16;
907 src->x2 = (src_x + src_w) << 16;
908 src->y1 = src_y << 16;
909 src->y2 = (src_y + src_h) << 16;
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300910 }
911
912 dst->x1 = crtc_x;
913 dst->x2 = crtc_x + crtc_w;
914 dst->y1 = crtc_y;
915 dst->y2 = crtc_y + crtc_h;
916
917 return 0;
918}
919
Gustavo Padovan34aa50a2014-10-24 14:51:32 +0100920static void
921intel_commit_sprite_plane(struct drm_plane *plane,
922 struct intel_plane_state *state)
923{
Matt Roper2b875c22014-12-01 15:40:13 -0800924 struct drm_crtc *crtc = state->base.crtc;
Gustavo Padovan34aa50a2014-10-24 14:51:32 +0100925 struct intel_plane *intel_plane = to_intel_plane(plane);
Matt Roper2b875c22014-12-01 15:40:13 -0800926 struct drm_framebuffer *fb = state->base.fb;
Gustavo Padovan34aa50a2014-10-24 14:51:32 +0100927
Matt Roperea2c67b2014-12-23 10:41:52 -0800928 crtc = crtc ? crtc : plane->crtc;
Matt Roperea2c67b2014-12-23 10:41:52 -0800929
Maarten Lankhorsta5392052015-06-15 12:33:52 +0200930 if (!crtc->state->active)
Maarten Lankhorst302d19a2015-06-15 12:33:45 +0200931 return;
932
933 if (state->visible) {
934 intel_plane->update_plane(plane, crtc, fb,
935 state->dst.x1, state->dst.y1,
936 drm_rect_width(&state->dst),
937 drm_rect_height(&state->dst),
938 state->src.x1 >> 16,
939 state->src.y1 >> 16,
940 drm_rect_width(&state->src) >> 16,
941 drm_rect_height(&state->src) >> 16);
942 } else {
Maarten Lankhorst7fabf5e2015-06-15 12:33:47 +0200943 intel_plane->disable_plane(plane, crtc);
Ville Syrjälä03c5b252013-10-01 18:02:11 +0300944 }
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800945}
946
Jesse Barnes8ea30862012-01-03 08:05:39 -0800947int intel_sprite_set_colorkey(struct drm_device *dev, void *data,
948 struct drm_file *file_priv)
949{
950 struct drm_intel_sprite_colorkey *set = data;
Jesse Barnes8ea30862012-01-03 08:05:39 -0800951 struct drm_plane *plane;
Maarten Lankhorst818ed962015-06-15 12:33:54 +0200952 struct drm_plane_state *plane_state;
953 struct drm_atomic_state *state;
954 struct drm_modeset_acquire_ctx ctx;
Jesse Barnes8ea30862012-01-03 08:05:39 -0800955 int ret = 0;
956
Jesse Barnes8ea30862012-01-03 08:05:39 -0800957 /* Make sure we don't try to enable both src & dest simultaneously */
958 if ((set->flags & (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE)) == (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE))
959 return -EINVAL;
960
Ville Syrjälä47ecbb22015-03-19 21:18:57 +0200961 if (IS_VALLEYVIEW(dev) &&
962 set->flags & I915_SET_COLORKEY_DESTINATION)
963 return -EINVAL;
964
Rob Clark7707e652014-07-17 23:30:04 -0400965 plane = drm_plane_find(dev, set->plane_id);
Maarten Lankhorst818ed962015-06-15 12:33:54 +0200966 if (!plane || plane->type != DRM_PLANE_TYPE_OVERLAY)
967 return -ENOENT;
968
969 drm_modeset_acquire_init(&ctx, 0);
970
971 state = drm_atomic_state_alloc(plane->dev);
972 if (!state) {
973 ret = -ENOMEM;
974 goto out;
Jesse Barnes8ea30862012-01-03 08:05:39 -0800975 }
Maarten Lankhorst818ed962015-06-15 12:33:54 +0200976 state->acquire_ctx = &ctx;
Jesse Barnes8ea30862012-01-03 08:05:39 -0800977
Maarten Lankhorst818ed962015-06-15 12:33:54 +0200978 while (1) {
979 plane_state = drm_atomic_get_plane_state(state, plane);
980 ret = PTR_ERR_OR_ZERO(plane_state);
981 if (!ret) {
982 to_intel_plane_state(plane_state)->ckey = *set;
983 ret = drm_atomic_commit(state);
Chandra Konduru6156a452015-04-27 13:48:39 -0700984 }
Maarten Lankhorst818ed962015-06-15 12:33:54 +0200985
986 if (ret != -EDEADLK)
987 break;
988
989 drm_atomic_state_clear(state);
990 drm_modeset_backoff(&ctx);
Chandra Konduru6156a452015-04-27 13:48:39 -0700991 }
992
Maarten Lankhorst818ed962015-06-15 12:33:54 +0200993 if (ret)
994 drm_atomic_state_free(state);
Ville Syrjälä47ecbb22015-03-19 21:18:57 +0200995
Maarten Lankhorst818ed962015-06-15 12:33:54 +0200996out:
997 drm_modeset_drop_locks(&ctx);
998 drm_modeset_acquire_fini(&ctx);
Jesse Barnes8ea30862012-01-03 08:05:39 -0800999 return ret;
1000}
1001
Damien Lespiaudada2d52015-05-12 16:13:22 +01001002static const uint32_t ilk_plane_formats[] = {
Chris Wilsond1686ae2012-04-10 11:41:49 +01001003 DRM_FORMAT_XRGB8888,
1004 DRM_FORMAT_YUYV,
1005 DRM_FORMAT_YVYU,
1006 DRM_FORMAT_UYVY,
1007 DRM_FORMAT_VYUY,
1008};
1009
Damien Lespiaudada2d52015-05-12 16:13:22 +01001010static const uint32_t snb_plane_formats[] = {
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001011 DRM_FORMAT_XBGR8888,
1012 DRM_FORMAT_XRGB8888,
1013 DRM_FORMAT_YUYV,
1014 DRM_FORMAT_YVYU,
1015 DRM_FORMAT_UYVY,
1016 DRM_FORMAT_VYUY,
1017};
1018
Damien Lespiaudada2d52015-05-12 16:13:22 +01001019static const uint32_t vlv_plane_formats[] = {
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001020 DRM_FORMAT_RGB565,
1021 DRM_FORMAT_ABGR8888,
1022 DRM_FORMAT_ARGB8888,
1023 DRM_FORMAT_XBGR8888,
1024 DRM_FORMAT_XRGB8888,
1025 DRM_FORMAT_XBGR2101010,
1026 DRM_FORMAT_ABGR2101010,
1027 DRM_FORMAT_YUYV,
1028 DRM_FORMAT_YVYU,
1029 DRM_FORMAT_UYVY,
1030 DRM_FORMAT_VYUY,
1031};
1032
Damien Lespiaudc2a41b2013-12-04 00:49:41 +00001033static uint32_t skl_plane_formats[] = {
1034 DRM_FORMAT_RGB565,
1035 DRM_FORMAT_ABGR8888,
1036 DRM_FORMAT_ARGB8888,
1037 DRM_FORMAT_XBGR8888,
1038 DRM_FORMAT_XRGB8888,
1039 DRM_FORMAT_YUYV,
1040 DRM_FORMAT_YVYU,
1041 DRM_FORMAT_UYVY,
1042 DRM_FORMAT_VYUY,
1043};
1044
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001045int
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001046intel_plane_init(struct drm_device *dev, enum pipe pipe, int plane)
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001047{
1048 struct intel_plane *intel_plane;
Matt Roper8e7d6882015-01-21 16:35:41 -08001049 struct intel_plane_state *state;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001050 unsigned long possible_crtcs;
Chris Wilsond1686ae2012-04-10 11:41:49 +01001051 const uint32_t *plane_formats;
1052 int num_plane_formats;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001053 int ret;
1054
Chris Wilsond1686ae2012-04-10 11:41:49 +01001055 if (INTEL_INFO(dev)->gen < 5)
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001056 return -ENODEV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001057
Daniel Vetterb14c5672013-09-19 12:18:32 +02001058 intel_plane = kzalloc(sizeof(*intel_plane), GFP_KERNEL);
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001059 if (!intel_plane)
1060 return -ENOMEM;
1061
Matt Roper8e7d6882015-01-21 16:35:41 -08001062 state = intel_create_plane_state(&intel_plane->base);
1063 if (!state) {
Matt Roperea2c67b2014-12-23 10:41:52 -08001064 kfree(intel_plane);
1065 return -ENOMEM;
1066 }
Matt Roper8e7d6882015-01-21 16:35:41 -08001067 intel_plane->base.state = &state->base;
Matt Roperea2c67b2014-12-23 10:41:52 -08001068
Chris Wilsond1686ae2012-04-10 11:41:49 +01001069 switch (INTEL_INFO(dev)->gen) {
1070 case 5:
1071 case 6:
Damien Lespiau2d354c32012-10-22 18:19:27 +01001072 intel_plane->can_scale = true;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001073 intel_plane->max_downscale = 16;
Chris Wilsond1686ae2012-04-10 11:41:49 +01001074 intel_plane->update_plane = ilk_update_plane;
1075 intel_plane->disable_plane = ilk_disable_plane;
Chris Wilsond1686ae2012-04-10 11:41:49 +01001076
1077 if (IS_GEN6(dev)) {
1078 plane_formats = snb_plane_formats;
1079 num_plane_formats = ARRAY_SIZE(snb_plane_formats);
1080 } else {
1081 plane_formats = ilk_plane_formats;
1082 num_plane_formats = ARRAY_SIZE(ilk_plane_formats);
1083 }
1084 break;
1085
1086 case 7:
Ben Widawsky4e0bbc32013-11-02 21:07:07 -07001087 case 8:
Damien Lespiaud49f7092013-04-25 15:15:00 +01001088 if (IS_IVYBRIDGE(dev)) {
Damien Lespiau2d354c32012-10-22 18:19:27 +01001089 intel_plane->can_scale = true;
Damien Lespiaud49f7092013-04-25 15:15:00 +01001090 intel_plane->max_downscale = 2;
1091 } else {
1092 intel_plane->can_scale = false;
1093 intel_plane->max_downscale = 1;
1094 }
Chris Wilsond1686ae2012-04-10 11:41:49 +01001095
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001096 if (IS_VALLEYVIEW(dev)) {
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001097 intel_plane->update_plane = vlv_update_plane;
1098 intel_plane->disable_plane = vlv_disable_plane;
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001099
1100 plane_formats = vlv_plane_formats;
1101 num_plane_formats = ARRAY_SIZE(vlv_plane_formats);
1102 } else {
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001103 intel_plane->update_plane = ivb_update_plane;
1104 intel_plane->disable_plane = ivb_disable_plane;
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001105
1106 plane_formats = snb_plane_formats;
1107 num_plane_formats = ARRAY_SIZE(snb_plane_formats);
1108 }
Chris Wilsond1686ae2012-04-10 11:41:49 +01001109 break;
Damien Lespiaudc2a41b2013-12-04 00:49:41 +00001110 case 9:
Chandra Konduruc3318792015-04-15 15:15:02 -07001111 intel_plane->can_scale = true;
Damien Lespiaudc2a41b2013-12-04 00:49:41 +00001112 intel_plane->update_plane = skl_update_plane;
1113 intel_plane->disable_plane = skl_disable_plane;
Chandra Konduru549e2bf2015-04-07 15:28:38 -07001114 state->scaler_id = -1;
Chris Wilsond1686ae2012-04-10 11:41:49 +01001115
Damien Lespiaudc2a41b2013-12-04 00:49:41 +00001116 plane_formats = skl_plane_formats;
1117 num_plane_formats = ARRAY_SIZE(skl_plane_formats);
1118 break;
Chris Wilsond1686ae2012-04-10 11:41:49 +01001119 default:
Jesper Juhla8b0bba2012-06-27 00:55:37 +02001120 kfree(intel_plane);
Chris Wilsond1686ae2012-04-10 11:41:49 +01001121 return -ENODEV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001122 }
1123
1124 intel_plane->pipe = pipe;
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001125 intel_plane->plane = plane;
Sagar Arun Kambled1b9d032015-09-14 21:35:42 +05301126 intel_plane->frontbuffer_bit = INTEL_FRONTBUFFER_SPRITE(pipe, plane);
Matt Roperc59cb172014-12-01 15:40:16 -08001127 intel_plane->check_plane = intel_check_sprite_plane;
1128 intel_plane->commit_plane = intel_commit_sprite_plane;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001129 possible_crtcs = (1 << pipe);
Derek Foreman8fe8a3f2014-09-03 10:38:20 -03001130 ret = drm_universal_plane_init(dev, &intel_plane->base, possible_crtcs,
Matt Roper65a3fea2015-01-21 16:35:42 -08001131 &intel_plane_funcs,
Derek Foreman8fe8a3f2014-09-03 10:38:20 -03001132 plane_formats, num_plane_formats,
1133 DRM_PLANE_TYPE_OVERLAY);
Ville Syrjälä7ed6eee2014-08-05 11:26:55 +05301134 if (ret) {
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001135 kfree(intel_plane);
Ville Syrjälä7ed6eee2014-08-05 11:26:55 +05301136 goto out;
1137 }
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001138
Sonika Jindal3b7a5112015-04-10 14:37:29 +05301139 intel_create_rotation_property(dev, intel_plane);
Ville Syrjälä7ed6eee2014-08-05 11:26:55 +05301140
Matt Roperea2c67b2014-12-23 10:41:52 -08001141 drm_plane_helper_add(&intel_plane->base, &intel_plane_helper_funcs);
1142
Damien Lespiaucaf4e252015-06-04 16:56:18 +01001143out:
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001144 return ret;
1145}