blob: 0a174d7e5854b7e77320db09edbc6dfe25e13078 [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>
Jesse Barnesb840d907f2011-12-13 13:19:38 -080036#include "intel_drv.h"
David Howells760285e2012-10-02 18:01:07 +010037#include <drm/i915_drm.h>
Jesse Barnesb840d907f2011-12-13 13:19:38 -080038#include "i915_drv.h"
39
40static void
Ville Syrjäläb39d53f2013-08-06 22:24:09 +030041vlv_update_plane(struct drm_plane *dplane, struct drm_crtc *crtc,
42 struct drm_framebuffer *fb,
Jesse Barnes7f1f3852013-04-02 11:22:20 -070043 struct drm_i915_gem_object *obj, int crtc_x, int crtc_y,
44 unsigned int crtc_w, unsigned int crtc_h,
45 uint32_t x, uint32_t y,
46 uint32_t src_w, uint32_t src_h)
47{
48 struct drm_device *dev = dplane->dev;
49 struct drm_i915_private *dev_priv = dev->dev_private;
50 struct intel_plane *intel_plane = to_intel_plane(dplane);
51 int pipe = intel_plane->pipe;
52 int plane = intel_plane->plane;
53 u32 sprctl;
54 unsigned long sprsurf_offset, linear_offset;
55 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
56
57 sprctl = I915_READ(SPCNTR(pipe, plane));
58
59 /* Mask out pixel format bits in case we change it */
60 sprctl &= ~SP_PIXFORMAT_MASK;
61 sprctl &= ~SP_YUV_BYTE_ORDER_MASK;
62 sprctl &= ~SP_TILED;
63
64 switch (fb->pixel_format) {
65 case DRM_FORMAT_YUYV:
66 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YUYV;
67 break;
68 case DRM_FORMAT_YVYU:
69 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YVYU;
70 break;
71 case DRM_FORMAT_UYVY:
72 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_UYVY;
73 break;
74 case DRM_FORMAT_VYUY:
75 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_VYUY;
76 break;
77 case DRM_FORMAT_RGB565:
78 sprctl |= SP_FORMAT_BGR565;
79 break;
80 case DRM_FORMAT_XRGB8888:
81 sprctl |= SP_FORMAT_BGRX8888;
82 break;
83 case DRM_FORMAT_ARGB8888:
84 sprctl |= SP_FORMAT_BGRA8888;
85 break;
86 case DRM_FORMAT_XBGR2101010:
87 sprctl |= SP_FORMAT_RGBX1010102;
88 break;
89 case DRM_FORMAT_ABGR2101010:
90 sprctl |= SP_FORMAT_RGBA1010102;
91 break;
92 case DRM_FORMAT_XBGR8888:
93 sprctl |= SP_FORMAT_RGBX8888;
94 break;
95 case DRM_FORMAT_ABGR8888:
96 sprctl |= SP_FORMAT_RGBA8888;
97 break;
98 default:
99 /*
100 * If we get here one of the upper layers failed to filter
101 * out the unsupported plane formats
102 */
103 BUG();
104 break;
105 }
106
107 if (obj->tiling_mode != I915_TILING_NONE)
108 sprctl |= SP_TILED;
109
110 sprctl |= SP_ENABLE;
111
Ville Syrjäläec4c4aa2013-07-05 11:57:15 +0300112 intel_update_sprite_watermarks(dev, pipe, src_w, pixel_size, true,
Ville Syrjälä67ca28f2013-07-05 11:57:14 +0300113 src_w != crtc_w || src_h != crtc_h);
114
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700115 /* Sizes are 0 based */
116 src_w--;
117 src_h--;
118 crtc_w--;
119 crtc_h--;
120
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700121 I915_WRITE(SPSTRIDE(pipe, plane), fb->pitches[0]);
122 I915_WRITE(SPPOS(pipe, plane), (crtc_y << 16) | crtc_x);
123
124 linear_offset = y * fb->pitches[0] + x * pixel_size;
125 sprsurf_offset = intel_gen4_compute_page_offset(&x, &y,
126 obj->tiling_mode,
127 pixel_size,
128 fb->pitches[0]);
129 linear_offset -= sprsurf_offset;
130
131 if (obj->tiling_mode != I915_TILING_NONE)
132 I915_WRITE(SPTILEOFF(pipe, plane), (y << 16) | x);
133 else
134 I915_WRITE(SPLINOFF(pipe, plane), linear_offset);
135
136 I915_WRITE(SPSIZE(pipe, plane), (crtc_h << 16) | crtc_w);
137 I915_WRITE(SPCNTR(pipe, plane), sprctl);
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700138 I915_MODIFY_DISPBASE(SPSURF(pipe, plane), i915_gem_obj_ggtt_offset(obj) +
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700139 sprsurf_offset);
140 POSTING_READ(SPSURF(pipe, plane));
141}
142
143static void
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300144vlv_disable_plane(struct drm_plane *dplane, struct drm_crtc *crtc)
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700145{
146 struct drm_device *dev = dplane->dev;
147 struct drm_i915_private *dev_priv = dev->dev_private;
148 struct intel_plane *intel_plane = to_intel_plane(dplane);
149 int pipe = intel_plane->pipe;
150 int plane = intel_plane->plane;
151
152 I915_WRITE(SPCNTR(pipe, plane), I915_READ(SPCNTR(pipe, plane)) &
153 ~SP_ENABLE);
154 /* Activate double buffered register update */
155 I915_MODIFY_DISPBASE(SPSURF(pipe, plane), 0);
156 POSTING_READ(SPSURF(pipe, plane));
157}
158
159static int
160vlv_update_colorkey(struct drm_plane *dplane,
161 struct drm_intel_sprite_colorkey *key)
162{
163 struct drm_device *dev = dplane->dev;
164 struct drm_i915_private *dev_priv = dev->dev_private;
165 struct intel_plane *intel_plane = to_intel_plane(dplane);
166 int pipe = intel_plane->pipe;
167 int plane = intel_plane->plane;
168 u32 sprctl;
169
170 if (key->flags & I915_SET_COLORKEY_DESTINATION)
171 return -EINVAL;
172
173 I915_WRITE(SPKEYMINVAL(pipe, plane), key->min_value);
174 I915_WRITE(SPKEYMAXVAL(pipe, plane), key->max_value);
175 I915_WRITE(SPKEYMSK(pipe, plane), key->channel_mask);
176
177 sprctl = I915_READ(SPCNTR(pipe, plane));
178 sprctl &= ~SP_SOURCE_KEY;
179 if (key->flags & I915_SET_COLORKEY_SOURCE)
180 sprctl |= SP_SOURCE_KEY;
181 I915_WRITE(SPCNTR(pipe, plane), sprctl);
182
183 POSTING_READ(SPKEYMSK(pipe, plane));
184
185 return 0;
186}
187
188static void
189vlv_get_colorkey(struct drm_plane *dplane,
190 struct drm_intel_sprite_colorkey *key)
191{
192 struct drm_device *dev = dplane->dev;
193 struct drm_i915_private *dev_priv = dev->dev_private;
194 struct intel_plane *intel_plane = to_intel_plane(dplane);
195 int pipe = intel_plane->pipe;
196 int plane = intel_plane->plane;
197 u32 sprctl;
198
199 key->min_value = I915_READ(SPKEYMINVAL(pipe, plane));
200 key->max_value = I915_READ(SPKEYMAXVAL(pipe, plane));
201 key->channel_mask = I915_READ(SPKEYMSK(pipe, plane));
202
203 sprctl = I915_READ(SPCNTR(pipe, plane));
204 if (sprctl & SP_SOURCE_KEY)
205 key->flags = I915_SET_COLORKEY_SOURCE;
206 else
207 key->flags = I915_SET_COLORKEY_NONE;
208}
209
210static void
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300211ivb_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
212 struct drm_framebuffer *fb,
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800213 struct drm_i915_gem_object *obj, int crtc_x, int crtc_y,
214 unsigned int crtc_w, unsigned int crtc_h,
215 uint32_t x, uint32_t y,
216 uint32_t src_w, uint32_t src_h)
217{
218 struct drm_device *dev = plane->dev;
219 struct drm_i915_private *dev_priv = dev->dev_private;
220 struct intel_plane *intel_plane = to_intel_plane(plane);
221 int pipe = intel_plane->pipe;
222 u32 sprctl, sprscale = 0;
Damien Lespiau5a35e992012-10-26 18:20:12 +0100223 unsigned long sprsurf_offset, linear_offset;
Ville Syrjälä2bd3c3c2012-10-31 17:50:20 +0200224 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
Ville Syrjälä2c6602d2013-02-08 23:13:35 +0200225 bool scaling_was_enabled = dev_priv->sprite_scaling_enabled;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800226
227 sprctl = I915_READ(SPRCTL(pipe));
228
229 /* Mask out pixel format bits in case we change it */
230 sprctl &= ~SPRITE_PIXFORMAT_MASK;
231 sprctl &= ~SPRITE_RGB_ORDER_RGBX;
232 sprctl &= ~SPRITE_YUV_BYTE_ORDER_MASK;
Jesse Barnese86fe0d2012-06-26 13:10:11 -0700233 sprctl &= ~SPRITE_TILED;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800234
235 switch (fb->pixel_format) {
236 case DRM_FORMAT_XBGR8888:
Vijay Purushothaman5ee36912012-08-23 12:08:57 +0530237 sprctl |= SPRITE_FORMAT_RGBX888 | SPRITE_RGB_ORDER_RGBX;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800238 break;
239 case DRM_FORMAT_XRGB8888:
Vijay Purushothaman5ee36912012-08-23 12:08:57 +0530240 sprctl |= SPRITE_FORMAT_RGBX888;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800241 break;
242 case DRM_FORMAT_YUYV:
243 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YUYV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800244 break;
245 case DRM_FORMAT_YVYU:
246 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YVYU;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800247 break;
248 case DRM_FORMAT_UYVY:
249 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_UYVY;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800250 break;
251 case DRM_FORMAT_VYUY:
252 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_VYUY;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800253 break;
254 default:
Ville Syrjälä28d491d2012-10-31 17:50:21 +0200255 BUG();
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800256 }
257
258 if (obj->tiling_mode != I915_TILING_NONE)
259 sprctl |= SPRITE_TILED;
260
261 /* must disable */
262 sprctl |= SPRITE_TRICKLE_FEED_DISABLE;
263 sprctl |= SPRITE_ENABLE;
264
Ville Syrjälä86d3efc2013-01-18 19:11:38 +0200265 if (IS_HASWELL(dev))
266 sprctl |= SPRITE_PIPE_CSC_ENABLE;
267
Ville Syrjäläec4c4aa2013-07-05 11:57:15 +0300268 intel_update_sprite_watermarks(dev, pipe, src_w, pixel_size, true,
Ville Syrjälä67ca28f2013-07-05 11:57:14 +0300269 src_w != crtc_w || src_h != crtc_h);
270
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800271 /* Sizes are 0 based */
272 src_w--;
273 src_h--;
274 crtc_w--;
275 crtc_h--;
276
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800277 /*
278 * IVB workaround: must disable low power watermarks for at least
279 * one frame before enabling scaling. LP watermarks can be re-enabled
280 * when scaling is disabled.
281 */
282 if (crtc_w != src_w || crtc_h != src_h) {
Ville Syrjälä2c6602d2013-02-08 23:13:35 +0200283 dev_priv->sprite_scaling_enabled |= 1 << pipe;
284
285 if (!scaling_was_enabled) {
Chris Wilson828ed3e2012-04-18 17:12:26 +0100286 intel_update_watermarks(dev);
287 intel_wait_for_vblank(dev, pipe);
288 }
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800289 sprscale = SPRITE_SCALE_ENABLE | (src_w << 16) | src_h;
Ville Syrjälä2c6602d2013-02-08 23:13:35 +0200290 } else
291 dev_priv->sprite_scaling_enabled &= ~(1 << pipe);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800292
293 I915_WRITE(SPRSTRIDE(pipe), fb->pitches[0]);
294 I915_WRITE(SPRPOS(pipe), (crtc_y << 16) | crtc_x);
Damien Lespiauc54173a2012-10-26 18:20:11 +0100295
Chris Wilsonca320ac2012-12-19 12:14:22 +0000296 linear_offset = y * fb->pitches[0] + x * pixel_size;
Damien Lespiau5a35e992012-10-26 18:20:12 +0100297 sprsurf_offset =
Chris Wilsonbc752862013-02-21 20:04:31 +0000298 intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
299 pixel_size, fb->pitches[0]);
Damien Lespiau5a35e992012-10-26 18:20:12 +0100300 linear_offset -= sprsurf_offset;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800301
Damien Lespiau5a35e992012-10-26 18:20:12 +0100302 /* HSW consolidates SPRTILEOFF and SPRLINOFF into a single SPROFFSET
303 * register */
304 if (IS_HASWELL(dev))
305 I915_WRITE(SPROFFSET(pipe), (y << 16) | x);
306 else if (obj->tiling_mode != I915_TILING_NONE)
307 I915_WRITE(SPRTILEOFF(pipe), (y << 16) | x);
308 else
309 I915_WRITE(SPRLINOFF(pipe), linear_offset);
Damien Lespiauc54173a2012-10-26 18:20:11 +0100310
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800311 I915_WRITE(SPRSIZE(pipe), (crtc_h << 16) | crtc_w);
Damien Lespiau2d354c32012-10-22 18:19:27 +0100312 if (intel_plane->can_scale)
313 I915_WRITE(SPRSCALE(pipe), sprscale);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800314 I915_WRITE(SPRCTL(pipe), sprctl);
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700315 I915_MODIFY_DISPBASE(SPRSURF(pipe),
316 i915_gem_obj_ggtt_offset(obj) + sprsurf_offset);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800317 POSTING_READ(SPRSURF(pipe));
Ville Syrjälä2c6602d2013-02-08 23:13:35 +0200318
319 /* potentially re-enable LP watermarks */
320 if (scaling_was_enabled && !dev_priv->sprite_scaling_enabled)
321 intel_update_watermarks(dev);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800322}
323
324static void
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300325ivb_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800326{
327 struct drm_device *dev = plane->dev;
328 struct drm_i915_private *dev_priv = dev->dev_private;
329 struct intel_plane *intel_plane = to_intel_plane(plane);
330 int pipe = intel_plane->pipe;
Ville Syrjälä2c6602d2013-02-08 23:13:35 +0200331 bool scaling_was_enabled = dev_priv->sprite_scaling_enabled;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800332
333 I915_WRITE(SPRCTL(pipe), I915_READ(SPRCTL(pipe)) & ~SPRITE_ENABLE);
334 /* Can't leave the scaler enabled... */
Damien Lespiau2d354c32012-10-22 18:19:27 +0100335 if (intel_plane->can_scale)
336 I915_WRITE(SPRSCALE(pipe), 0);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800337 /* Activate double buffered register update */
Armin Reese446f2542012-03-30 16:20:16 -0700338 I915_MODIFY_DISPBASE(SPRSURF(pipe), 0);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800339 POSTING_READ(SPRSURF(pipe));
Chris Wilson828ed3e2012-04-18 17:12:26 +0100340
Ville Syrjälä2c6602d2013-02-08 23:13:35 +0200341 dev_priv->sprite_scaling_enabled &= ~(1 << pipe);
342
Ville Syrjäläbdd57d02013-07-05 11:57:13 +0300343 intel_update_sprite_watermarks(dev, pipe, 0, 0, false, false);
Paulo Zanoni4c4ff432013-05-24 11:59:17 -0300344
Ville Syrjälä2c6602d2013-02-08 23:13:35 +0200345 /* potentially re-enable LP watermarks */
346 if (scaling_was_enabled && !dev_priv->sprite_scaling_enabled)
347 intel_update_watermarks(dev);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800348}
349
Jesse Barnes8ea30862012-01-03 08:05:39 -0800350static int
351ivb_update_colorkey(struct drm_plane *plane,
352 struct drm_intel_sprite_colorkey *key)
353{
354 struct drm_device *dev = plane->dev;
355 struct drm_i915_private *dev_priv = dev->dev_private;
356 struct intel_plane *intel_plane;
357 u32 sprctl;
358 int ret = 0;
359
360 intel_plane = to_intel_plane(plane);
361
362 I915_WRITE(SPRKEYVAL(intel_plane->pipe), key->min_value);
363 I915_WRITE(SPRKEYMAX(intel_plane->pipe), key->max_value);
364 I915_WRITE(SPRKEYMSK(intel_plane->pipe), key->channel_mask);
365
366 sprctl = I915_READ(SPRCTL(intel_plane->pipe));
367 sprctl &= ~(SPRITE_SOURCE_KEY | SPRITE_DEST_KEY);
368 if (key->flags & I915_SET_COLORKEY_DESTINATION)
369 sprctl |= SPRITE_DEST_KEY;
370 else if (key->flags & I915_SET_COLORKEY_SOURCE)
371 sprctl |= SPRITE_SOURCE_KEY;
372 I915_WRITE(SPRCTL(intel_plane->pipe), sprctl);
373
374 POSTING_READ(SPRKEYMSK(intel_plane->pipe));
375
376 return ret;
377}
378
379static void
380ivb_get_colorkey(struct drm_plane *plane, struct drm_intel_sprite_colorkey *key)
381{
382 struct drm_device *dev = plane->dev;
383 struct drm_i915_private *dev_priv = dev->dev_private;
384 struct intel_plane *intel_plane;
385 u32 sprctl;
386
387 intel_plane = to_intel_plane(plane);
388
389 key->min_value = I915_READ(SPRKEYVAL(intel_plane->pipe));
390 key->max_value = I915_READ(SPRKEYMAX(intel_plane->pipe));
391 key->channel_mask = I915_READ(SPRKEYMSK(intel_plane->pipe));
392 key->flags = 0;
393
394 sprctl = I915_READ(SPRCTL(intel_plane->pipe));
395
396 if (sprctl & SPRITE_DEST_KEY)
397 key->flags = I915_SET_COLORKEY_DESTINATION;
398 else if (sprctl & SPRITE_SOURCE_KEY)
399 key->flags = I915_SET_COLORKEY_SOURCE;
400 else
401 key->flags = I915_SET_COLORKEY_NONE;
402}
403
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800404static void
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300405ilk_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
406 struct drm_framebuffer *fb,
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800407 struct drm_i915_gem_object *obj, int crtc_x, int crtc_y,
408 unsigned int crtc_w, unsigned int crtc_h,
409 uint32_t x, uint32_t y,
410 uint32_t src_w, uint32_t src_h)
411{
412 struct drm_device *dev = plane->dev;
413 struct drm_i915_private *dev_priv = dev->dev_private;
414 struct intel_plane *intel_plane = to_intel_plane(plane);
Ville Syrjälä2bd3c3c2012-10-31 17:50:20 +0200415 int pipe = intel_plane->pipe;
Damien Lespiau5a35e992012-10-26 18:20:12 +0100416 unsigned long dvssurf_offset, linear_offset;
Chris Wilson8aaa81a2012-04-14 22:14:26 +0100417 u32 dvscntr, dvsscale;
Ville Syrjälä2bd3c3c2012-10-31 17:50:20 +0200418 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800419
420 dvscntr = I915_READ(DVSCNTR(pipe));
421
422 /* Mask out pixel format bits in case we change it */
423 dvscntr &= ~DVS_PIXFORMAT_MASK;
Jesse Barnesab2f9df2012-02-27 12:40:10 -0800424 dvscntr &= ~DVS_RGB_ORDER_XBGR;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800425 dvscntr &= ~DVS_YUV_BYTE_ORDER_MASK;
Ander Conselvan de Oliveira79626522012-07-13 15:50:33 +0300426 dvscntr &= ~DVS_TILED;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800427
428 switch (fb->pixel_format) {
429 case DRM_FORMAT_XBGR8888:
Jesse Barnesab2f9df2012-02-27 12:40:10 -0800430 dvscntr |= DVS_FORMAT_RGBX888 | DVS_RGB_ORDER_XBGR;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800431 break;
432 case DRM_FORMAT_XRGB8888:
Jesse Barnesab2f9df2012-02-27 12:40:10 -0800433 dvscntr |= DVS_FORMAT_RGBX888;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800434 break;
435 case DRM_FORMAT_YUYV:
436 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YUYV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800437 break;
438 case DRM_FORMAT_YVYU:
439 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YVYU;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800440 break;
441 case DRM_FORMAT_UYVY:
442 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_UYVY;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800443 break;
444 case DRM_FORMAT_VYUY:
445 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_VYUY;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800446 break;
447 default:
Ville Syrjälä28d491d2012-10-31 17:50:21 +0200448 BUG();
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800449 }
450
451 if (obj->tiling_mode != I915_TILING_NONE)
452 dvscntr |= DVS_TILED;
453
Chris Wilsond1686ae2012-04-10 11:41:49 +0100454 if (IS_GEN6(dev))
455 dvscntr |= DVS_TRICKLE_FEED_DISABLE; /* must disable */
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800456 dvscntr |= DVS_ENABLE;
457
Ville Syrjäläec4c4aa2013-07-05 11:57:15 +0300458 intel_update_sprite_watermarks(dev, pipe, src_w, pixel_size, true,
Ville Syrjälä67ca28f2013-07-05 11:57:14 +0300459 src_w != crtc_w || src_h != crtc_h);
460
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800461 /* Sizes are 0 based */
462 src_w--;
463 src_h--;
464 crtc_w--;
465 crtc_h--;
466
Chris Wilson8aaa81a2012-04-14 22:14:26 +0100467 dvsscale = 0;
468 if (IS_GEN5(dev) || crtc_w != src_w || crtc_h != src_h)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800469 dvsscale = DVS_SCALE_ENABLE | (src_w << 16) | src_h;
470
471 I915_WRITE(DVSSTRIDE(pipe), fb->pitches[0]);
472 I915_WRITE(DVSPOS(pipe), (crtc_y << 16) | crtc_x);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800473
Chris Wilsonca320ac2012-12-19 12:14:22 +0000474 linear_offset = y * fb->pitches[0] + x * pixel_size;
Damien Lespiau5a35e992012-10-26 18:20:12 +0100475 dvssurf_offset =
Chris Wilsonbc752862013-02-21 20:04:31 +0000476 intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
477 pixel_size, fb->pitches[0]);
Damien Lespiau5a35e992012-10-26 18:20:12 +0100478 linear_offset -= dvssurf_offset;
479
480 if (obj->tiling_mode != I915_TILING_NONE)
481 I915_WRITE(DVSTILEOFF(pipe), (y << 16) | x);
482 else
483 I915_WRITE(DVSLINOFF(pipe), linear_offset);
484
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800485 I915_WRITE(DVSSIZE(pipe), (crtc_h << 16) | crtc_w);
486 I915_WRITE(DVSSCALE(pipe), dvsscale);
487 I915_WRITE(DVSCNTR(pipe), dvscntr);
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700488 I915_MODIFY_DISPBASE(DVSSURF(pipe),
489 i915_gem_obj_ggtt_offset(obj) + dvssurf_offset);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800490 POSTING_READ(DVSSURF(pipe));
491}
492
493static void
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300494ilk_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800495{
496 struct drm_device *dev = plane->dev;
497 struct drm_i915_private *dev_priv = dev->dev_private;
498 struct intel_plane *intel_plane = to_intel_plane(plane);
499 int pipe = intel_plane->pipe;
500
501 I915_WRITE(DVSCNTR(pipe), I915_READ(DVSCNTR(pipe)) & ~DVS_ENABLE);
502 /* Disable the scaler */
503 I915_WRITE(DVSSCALE(pipe), 0);
504 /* Flush double buffered register updates */
Armin Reese446f2542012-03-30 16:20:16 -0700505 I915_MODIFY_DISPBASE(DVSSURF(pipe), 0);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800506 POSTING_READ(DVSSURF(pipe));
507}
508
Jesse Barnes175bd422011-12-13 13:19:39 -0800509static void
510intel_enable_primary(struct drm_crtc *crtc)
511{
512 struct drm_device *dev = crtc->dev;
513 struct drm_i915_private *dev_priv = dev->dev_private;
514 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
515 int reg = DSPCNTR(intel_crtc->plane);
516
Chris Wilson93314b52012-06-13 17:36:55 +0100517 if (!intel_crtc->primary_disabled)
518 return;
519
520 intel_crtc->primary_disabled = false;
521 intel_update_fbc(dev);
522
Jesse Barnes175bd422011-12-13 13:19:39 -0800523 I915_WRITE(reg, I915_READ(reg) | DISPLAY_PLANE_ENABLE);
524}
525
526static void
527intel_disable_primary(struct drm_crtc *crtc)
528{
529 struct drm_device *dev = crtc->dev;
530 struct drm_i915_private *dev_priv = dev->dev_private;
531 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
532 int reg = DSPCNTR(intel_crtc->plane);
533
Chris Wilson93314b52012-06-13 17:36:55 +0100534 if (intel_crtc->primary_disabled)
535 return;
536
Jesse Barnes175bd422011-12-13 13:19:39 -0800537 I915_WRITE(reg, I915_READ(reg) & ~DISPLAY_PLANE_ENABLE);
Chris Wilson93314b52012-06-13 17:36:55 +0100538
539 intel_crtc->primary_disabled = true;
540 intel_update_fbc(dev);
Jesse Barnes175bd422011-12-13 13:19:39 -0800541}
542
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800543static int
Chris Wilsond1686ae2012-04-10 11:41:49 +0100544ilk_update_colorkey(struct drm_plane *plane,
Jesse Barnes8ea30862012-01-03 08:05:39 -0800545 struct drm_intel_sprite_colorkey *key)
546{
547 struct drm_device *dev = plane->dev;
548 struct drm_i915_private *dev_priv = dev->dev_private;
549 struct intel_plane *intel_plane;
550 u32 dvscntr;
551 int ret = 0;
552
553 intel_plane = to_intel_plane(plane);
554
555 I915_WRITE(DVSKEYVAL(intel_plane->pipe), key->min_value);
556 I915_WRITE(DVSKEYMAX(intel_plane->pipe), key->max_value);
557 I915_WRITE(DVSKEYMSK(intel_plane->pipe), key->channel_mask);
558
559 dvscntr = I915_READ(DVSCNTR(intel_plane->pipe));
560 dvscntr &= ~(DVS_SOURCE_KEY | DVS_DEST_KEY);
561 if (key->flags & I915_SET_COLORKEY_DESTINATION)
562 dvscntr |= DVS_DEST_KEY;
563 else if (key->flags & I915_SET_COLORKEY_SOURCE)
564 dvscntr |= DVS_SOURCE_KEY;
565 I915_WRITE(DVSCNTR(intel_plane->pipe), dvscntr);
566
567 POSTING_READ(DVSKEYMSK(intel_plane->pipe));
568
569 return ret;
570}
571
572static void
Chris Wilsond1686ae2012-04-10 11:41:49 +0100573ilk_get_colorkey(struct drm_plane *plane, struct drm_intel_sprite_colorkey *key)
Jesse Barnes8ea30862012-01-03 08:05:39 -0800574{
575 struct drm_device *dev = plane->dev;
576 struct drm_i915_private *dev_priv = dev->dev_private;
577 struct intel_plane *intel_plane;
578 u32 dvscntr;
579
580 intel_plane = to_intel_plane(plane);
581
582 key->min_value = I915_READ(DVSKEYVAL(intel_plane->pipe));
583 key->max_value = I915_READ(DVSKEYMAX(intel_plane->pipe));
584 key->channel_mask = I915_READ(DVSKEYMSK(intel_plane->pipe));
585 key->flags = 0;
586
587 dvscntr = I915_READ(DVSCNTR(intel_plane->pipe));
588
589 if (dvscntr & DVS_DEST_KEY)
590 key->flags = I915_SET_COLORKEY_DESTINATION;
591 else if (dvscntr & DVS_SOURCE_KEY)
592 key->flags = I915_SET_COLORKEY_SOURCE;
593 else
594 key->flags = I915_SET_COLORKEY_NONE;
595}
596
Ville Syrjälä17316932013-04-24 18:52:38 +0300597static bool
598format_is_yuv(uint32_t format)
599{
600 switch (format) {
601 case DRM_FORMAT_YUYV:
602 case DRM_FORMAT_UYVY:
603 case DRM_FORMAT_VYUY:
604 case DRM_FORMAT_YVYU:
605 return true;
606 default:
607 return false;
608 }
609}
610
Jesse Barnes8ea30862012-01-03 08:05:39 -0800611static int
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800612intel_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
613 struct drm_framebuffer *fb, int crtc_x, int crtc_y,
614 unsigned int crtc_w, unsigned int crtc_h,
615 uint32_t src_x, uint32_t src_y,
616 uint32_t src_w, uint32_t src_h)
617{
618 struct drm_device *dev = plane->dev;
619 struct drm_i915_private *dev_priv = dev->dev_private;
620 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
621 struct intel_plane *intel_plane = to_intel_plane(plane);
622 struct intel_framebuffer *intel_fb;
623 struct drm_i915_gem_object *obj, *old_obj;
624 int pipe = intel_plane->pipe;
Paulo Zanoni702e7a52012-10-23 18:29:59 -0200625 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
626 pipe);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800627 int ret = 0;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800628 bool disable_primary = false;
Ville Syrjälä17316932013-04-24 18:52:38 +0300629 bool visible;
630 int hscale, vscale;
631 int max_scale, min_scale;
632 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
633 struct drm_rect src = {
634 /* sample coordinates in 16.16 fixed point */
635 .x1 = src_x,
636 .x2 = src_x + src_w,
637 .y1 = src_y,
638 .y2 = src_y + src_h,
639 };
640 struct drm_rect dst = {
641 /* integer pixels */
642 .x1 = crtc_x,
643 .x2 = crtc_x + crtc_w,
644 .y1 = crtc_y,
645 .y2 = crtc_y + crtc_h,
646 };
647 const struct drm_rect clip = {
648 .x2 = crtc->mode.hdisplay,
649 .y2 = crtc->mode.vdisplay,
650 };
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800651
652 intel_fb = to_intel_framebuffer(fb);
653 obj = intel_fb->obj;
654
655 old_obj = intel_plane->obj;
656
Jesse Barnes5e1bac22013-03-26 09:25:43 -0700657 intel_plane->crtc_x = crtc_x;
658 intel_plane->crtc_y = crtc_y;
659 intel_plane->crtc_w = crtc_w;
660 intel_plane->crtc_h = crtc_h;
661 intel_plane->src_x = src_x;
662 intel_plane->src_y = src_y;
663 intel_plane->src_w = src_w;
664 intel_plane->src_h = src_h;
665
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800666 /* Pipe must be running... */
Ville Syrjälä17316932013-04-24 18:52:38 +0300667 if (!(I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_ENABLE)) {
668 DRM_DEBUG_KMS("Pipe disabled\n");
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800669 return -EINVAL;
Ville Syrjälä17316932013-04-24 18:52:38 +0300670 }
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800671
672 /* Don't modify another pipe's plane */
Ville Syrjälä17316932013-04-24 18:52:38 +0300673 if (intel_plane->pipe != intel_crtc->pipe) {
674 DRM_DEBUG_KMS("Wrong plane <-> crtc mapping\n");
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800675 return -EINVAL;
Ville Syrjälä17316932013-04-24 18:52:38 +0300676 }
677
678 /* FIXME check all gen limits */
679 if (fb->width < 3 || fb->height < 3 || fb->pitches[0] > 16384) {
680 DRM_DEBUG_KMS("Unsuitable framebuffer for plane\n");
681 return -EINVAL;
682 }
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800683
Damien Lespiau94c64192012-10-29 15:14:51 +0000684 /* Sprite planes can be linear or x-tiled surfaces */
685 switch (obj->tiling_mode) {
686 case I915_TILING_NONE:
687 case I915_TILING_X:
688 break;
689 default:
Ville Syrjälä17316932013-04-24 18:52:38 +0300690 DRM_DEBUG_KMS("Unsupported tiling mode\n");
Damien Lespiau94c64192012-10-29 15:14:51 +0000691 return -EINVAL;
692 }
693
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300694 /*
695 * FIXME the following code does a bunch of fuzzy adjustments to the
696 * coordinates and sizes. We probably need some way to decide whether
697 * more strict checking should be done instead.
698 */
Ville Syrjälä17316932013-04-24 18:52:38 +0300699 max_scale = intel_plane->max_downscale << 16;
700 min_scale = intel_plane->can_scale ? 1 : (1 << 16);
701
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300702 hscale = drm_rect_calc_hscale_relaxed(&src, &dst, min_scale, max_scale);
703 BUG_ON(hscale < 0);
Ville Syrjälä17316932013-04-24 18:52:38 +0300704
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300705 vscale = drm_rect_calc_vscale_relaxed(&src, &dst, min_scale, max_scale);
706 BUG_ON(vscale < 0);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800707
Ville Syrjälä17316932013-04-24 18:52:38 +0300708 visible = drm_rect_clip_scaled(&src, &dst, &clip, hscale, vscale);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800709
Ville Syrjälä17316932013-04-24 18:52:38 +0300710 crtc_x = dst.x1;
711 crtc_y = dst.y1;
712 crtc_w = drm_rect_width(&dst);
713 crtc_h = drm_rect_height(&dst);
Damien Lespiau2d354c32012-10-22 18:19:27 +0100714
Ville Syrjälä17316932013-04-24 18:52:38 +0300715 if (visible) {
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300716 /* check again in case clipping clamped the results */
717 hscale = drm_rect_calc_hscale(&src, &dst, min_scale, max_scale);
718 if (hscale < 0) {
719 DRM_DEBUG_KMS("Horizontal scaling factor out of limits\n");
720 drm_rect_debug_print(&src, true);
721 drm_rect_debug_print(&dst, false);
722
723 return hscale;
724 }
725
726 vscale = drm_rect_calc_vscale(&src, &dst, min_scale, max_scale);
727 if (vscale < 0) {
728 DRM_DEBUG_KMS("Vertical scaling factor out of limits\n");
729 drm_rect_debug_print(&src, true);
730 drm_rect_debug_print(&dst, false);
731
732 return vscale;
733 }
734
Ville Syrjälä17316932013-04-24 18:52:38 +0300735 /* Make the source viewport size an exact multiple of the scaling factors. */
736 drm_rect_adjust_size(&src,
737 drm_rect_width(&dst) * hscale - drm_rect_width(&src),
738 drm_rect_height(&dst) * vscale - drm_rect_height(&src));
739
740 /* sanity check to make sure the src viewport wasn't enlarged */
741 WARN_ON(src.x1 < (int) src_x ||
742 src.y1 < (int) src_y ||
743 src.x2 > (int) (src_x + src_w) ||
744 src.y2 > (int) (src_y + src_h));
745
746 /*
747 * Hardware doesn't handle subpixel coordinates.
748 * Adjust to (macro)pixel boundary, but be careful not to
749 * increase the source viewport size, because that could
750 * push the downscaling factor out of bounds.
Ville Syrjälä17316932013-04-24 18:52:38 +0300751 */
752 src_x = src.x1 >> 16;
753 src_w = drm_rect_width(&src) >> 16;
754 src_y = src.y1 >> 16;
755 src_h = drm_rect_height(&src) >> 16;
756
757 if (format_is_yuv(fb->pixel_format)) {
758 src_x &= ~1;
759 src_w &= ~1;
760
761 /*
762 * Must keep src and dst the
763 * same if we can't scale.
764 */
765 if (!intel_plane->can_scale)
766 crtc_w &= ~1;
767
768 if (crtc_w == 0)
769 visible = false;
770 }
771 }
772
773 /* Check size restrictions when scaling */
774 if (visible && (src_w != crtc_w || src_h != crtc_h)) {
775 unsigned int width_bytes;
776
777 WARN_ON(!intel_plane->can_scale);
778
779 /* FIXME interlacing min height is 6 */
780
781 if (crtc_w < 3 || crtc_h < 3)
782 visible = false;
783
784 if (src_w < 3 || src_h < 3)
785 visible = false;
786
787 width_bytes = ((src_x * pixel_size) & 63) + src_w * pixel_size;
788
789 if (src_w > 2048 || src_h > 2048 ||
790 width_bytes > 4096 || fb->pitches[0] > 4096) {
791 DRM_DEBUG_KMS("Source dimensions exceed hardware limits\n");
792 return -EINVAL;
793 }
794 }
795
796 dst.x1 = crtc_x;
797 dst.x2 = crtc_x + crtc_w;
798 dst.y1 = crtc_y;
799 dst.y2 = crtc_y + crtc_h;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800800
801 /*
802 * If the sprite is completely covering the primary plane,
803 * we can disable the primary and save power.
804 */
Ville Syrjälä17316932013-04-24 18:52:38 +0300805 disable_primary = drm_rect_equals(&dst, &clip);
806 WARN_ON(disable_primary && !visible);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800807
808 mutex_lock(&dev->struct_mutex);
809
Chris Wilson693db182013-03-05 14:52:39 +0000810 /* Note that this will apply the VT-d workaround for scanouts,
811 * which is more restrictive than required for sprites. (The
812 * primary plane requires 256KiB alignment with 64 PTE padding,
813 * the sprite planes only require 128KiB alignment and 32 PTE padding.
814 */
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800815 ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
Jesse Barnes00c2064b2012-01-13 15:48:39 -0800816 if (ret)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800817 goto out_unlock;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800818
819 intel_plane->obj = obj;
820
Jesse Barnes175bd422011-12-13 13:19:39 -0800821 /*
822 * Be sure to re-enable the primary before the sprite is no longer
823 * covering it fully.
824 */
Chris Wilson93314b52012-06-13 17:36:55 +0100825 if (!disable_primary)
Jesse Barnes175bd422011-12-13 13:19:39 -0800826 intel_enable_primary(crtc);
Jesse Barnes175bd422011-12-13 13:19:39 -0800827
Ville Syrjälä17316932013-04-24 18:52:38 +0300828 if (visible)
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300829 intel_plane->update_plane(plane, crtc, fb, obj,
Ville Syrjälä17316932013-04-24 18:52:38 +0300830 crtc_x, crtc_y, crtc_w, crtc_h,
831 src_x, src_y, src_w, src_h);
832 else
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300833 intel_plane->disable_plane(plane, crtc);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800834
Chris Wilson93314b52012-06-13 17:36:55 +0100835 if (disable_primary)
Jesse Barnes175bd422011-12-13 13:19:39 -0800836 intel_disable_primary(crtc);
Jesse Barnes175bd422011-12-13 13:19:39 -0800837
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800838 /* Unpin old obj after new one is active to avoid ugliness */
839 if (old_obj) {
840 /*
841 * It's fairly common to simply update the position of
842 * an existing object. In that case, we don't need to
843 * wait for vblank to avoid ugliness, we only need to
844 * do the pin & ref bookkeeping.
845 */
846 if (old_obj != obj) {
847 mutex_unlock(&dev->struct_mutex);
848 intel_wait_for_vblank(dev, to_intel_crtc(crtc)->pipe);
849 mutex_lock(&dev->struct_mutex);
850 }
Chris Wilson1690e1e2011-12-14 13:57:08 +0100851 intel_unpin_fb_obj(old_obj);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800852 }
853
854out_unlock:
855 mutex_unlock(&dev->struct_mutex);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800856 return ret;
857}
858
859static int
860intel_disable_plane(struct drm_plane *plane)
861{
862 struct drm_device *dev = plane->dev;
863 struct intel_plane *intel_plane = to_intel_plane(plane);
864 int ret = 0;
865
Ville Syrjälä88a94a52013-08-07 13:30:23 +0300866 if (!plane->fb)
867 return 0;
868
869 if (WARN_ON(!plane->crtc))
870 return -EINVAL;
871
872 intel_enable_primary(plane->crtc);
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300873 intel_plane->disable_plane(plane, plane->crtc);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800874
875 if (!intel_plane->obj)
876 goto out;
877
Ville Syrjäläc626d312013-03-27 17:49:13 +0200878 intel_wait_for_vblank(dev, intel_plane->pipe);
879
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800880 mutex_lock(&dev->struct_mutex);
Chris Wilson1690e1e2011-12-14 13:57:08 +0100881 intel_unpin_fb_obj(intel_plane->obj);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800882 intel_plane->obj = NULL;
883 mutex_unlock(&dev->struct_mutex);
884out:
885
886 return ret;
887}
888
889static void intel_destroy_plane(struct drm_plane *plane)
890{
891 struct intel_plane *intel_plane = to_intel_plane(plane);
892 intel_disable_plane(plane);
893 drm_plane_cleanup(plane);
894 kfree(intel_plane);
895}
896
Jesse Barnes8ea30862012-01-03 08:05:39 -0800897int intel_sprite_set_colorkey(struct drm_device *dev, void *data,
898 struct drm_file *file_priv)
899{
900 struct drm_intel_sprite_colorkey *set = data;
Jesse Barnes8ea30862012-01-03 08:05:39 -0800901 struct drm_mode_object *obj;
902 struct drm_plane *plane;
903 struct intel_plane *intel_plane;
904 int ret = 0;
905
Daniel Vetter1cff8f62012-04-24 09:55:08 +0200906 if (!drm_core_check_feature(dev, DRIVER_MODESET))
907 return -ENODEV;
Jesse Barnes8ea30862012-01-03 08:05:39 -0800908
909 /* Make sure we don't try to enable both src & dest simultaneously */
910 if ((set->flags & (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE)) == (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE))
911 return -EINVAL;
912
Daniel Vettera0e99e62012-12-02 01:05:46 +0100913 drm_modeset_lock_all(dev);
Jesse Barnes8ea30862012-01-03 08:05:39 -0800914
915 obj = drm_mode_object_find(dev, set->plane_id, DRM_MODE_OBJECT_PLANE);
916 if (!obj) {
917 ret = -EINVAL;
918 goto out_unlock;
919 }
920
921 plane = obj_to_plane(obj);
922 intel_plane = to_intel_plane(plane);
923 ret = intel_plane->update_colorkey(plane, set);
924
925out_unlock:
Daniel Vettera0e99e62012-12-02 01:05:46 +0100926 drm_modeset_unlock_all(dev);
Jesse Barnes8ea30862012-01-03 08:05:39 -0800927 return ret;
928}
929
930int intel_sprite_get_colorkey(struct drm_device *dev, void *data,
931 struct drm_file *file_priv)
932{
933 struct drm_intel_sprite_colorkey *get = data;
Jesse Barnes8ea30862012-01-03 08:05:39 -0800934 struct drm_mode_object *obj;
935 struct drm_plane *plane;
936 struct intel_plane *intel_plane;
937 int ret = 0;
938
Daniel Vetter1cff8f62012-04-24 09:55:08 +0200939 if (!drm_core_check_feature(dev, DRIVER_MODESET))
940 return -ENODEV;
Jesse Barnes8ea30862012-01-03 08:05:39 -0800941
Daniel Vettera0e99e62012-12-02 01:05:46 +0100942 drm_modeset_lock_all(dev);
Jesse Barnes8ea30862012-01-03 08:05:39 -0800943
944 obj = drm_mode_object_find(dev, get->plane_id, DRM_MODE_OBJECT_PLANE);
945 if (!obj) {
946 ret = -EINVAL;
947 goto out_unlock;
948 }
949
950 plane = obj_to_plane(obj);
951 intel_plane = to_intel_plane(plane);
952 intel_plane->get_colorkey(plane, get);
953
954out_unlock:
Daniel Vettera0e99e62012-12-02 01:05:46 +0100955 drm_modeset_unlock_all(dev);
Jesse Barnes8ea30862012-01-03 08:05:39 -0800956 return ret;
957}
958
Jesse Barnes5e1bac22013-03-26 09:25:43 -0700959void intel_plane_restore(struct drm_plane *plane)
960{
961 struct intel_plane *intel_plane = to_intel_plane(plane);
962
963 if (!plane->crtc || !plane->fb)
964 return;
965
966 intel_update_plane(plane, plane->crtc, plane->fb,
967 intel_plane->crtc_x, intel_plane->crtc_y,
968 intel_plane->crtc_w, intel_plane->crtc_h,
969 intel_plane->src_x, intel_plane->src_y,
970 intel_plane->src_w, intel_plane->src_h);
971}
972
Ville Syrjäläbb53d4a2013-06-04 13:49:04 +0300973void intel_plane_disable(struct drm_plane *plane)
974{
975 if (!plane->crtc || !plane->fb)
976 return;
977
978 intel_disable_plane(plane);
979}
980
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800981static const struct drm_plane_funcs intel_plane_funcs = {
982 .update_plane = intel_update_plane,
983 .disable_plane = intel_disable_plane,
984 .destroy = intel_destroy_plane,
985};
986
Chris Wilsond1686ae2012-04-10 11:41:49 +0100987static uint32_t ilk_plane_formats[] = {
988 DRM_FORMAT_XRGB8888,
989 DRM_FORMAT_YUYV,
990 DRM_FORMAT_YVYU,
991 DRM_FORMAT_UYVY,
992 DRM_FORMAT_VYUY,
993};
994
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800995static uint32_t snb_plane_formats[] = {
996 DRM_FORMAT_XBGR8888,
997 DRM_FORMAT_XRGB8888,
998 DRM_FORMAT_YUYV,
999 DRM_FORMAT_YVYU,
1000 DRM_FORMAT_UYVY,
1001 DRM_FORMAT_VYUY,
1002};
1003
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001004static uint32_t vlv_plane_formats[] = {
1005 DRM_FORMAT_RGB565,
1006 DRM_FORMAT_ABGR8888,
1007 DRM_FORMAT_ARGB8888,
1008 DRM_FORMAT_XBGR8888,
1009 DRM_FORMAT_XRGB8888,
1010 DRM_FORMAT_XBGR2101010,
1011 DRM_FORMAT_ABGR2101010,
1012 DRM_FORMAT_YUYV,
1013 DRM_FORMAT_YVYU,
1014 DRM_FORMAT_UYVY,
1015 DRM_FORMAT_VYUY,
1016};
1017
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001018int
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001019intel_plane_init(struct drm_device *dev, enum pipe pipe, int plane)
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001020{
1021 struct intel_plane *intel_plane;
1022 unsigned long possible_crtcs;
Chris Wilsond1686ae2012-04-10 11:41:49 +01001023 const uint32_t *plane_formats;
1024 int num_plane_formats;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001025 int ret;
1026
Chris Wilsond1686ae2012-04-10 11:41:49 +01001027 if (INTEL_INFO(dev)->gen < 5)
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001028 return -ENODEV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001029
1030 intel_plane = kzalloc(sizeof(struct intel_plane), GFP_KERNEL);
1031 if (!intel_plane)
1032 return -ENOMEM;
1033
Chris Wilsond1686ae2012-04-10 11:41:49 +01001034 switch (INTEL_INFO(dev)->gen) {
1035 case 5:
1036 case 6:
Damien Lespiau2d354c32012-10-22 18:19:27 +01001037 intel_plane->can_scale = true;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001038 intel_plane->max_downscale = 16;
Chris Wilsond1686ae2012-04-10 11:41:49 +01001039 intel_plane->update_plane = ilk_update_plane;
1040 intel_plane->disable_plane = ilk_disable_plane;
1041 intel_plane->update_colorkey = ilk_update_colorkey;
1042 intel_plane->get_colorkey = ilk_get_colorkey;
1043
1044 if (IS_GEN6(dev)) {
1045 plane_formats = snb_plane_formats;
1046 num_plane_formats = ARRAY_SIZE(snb_plane_formats);
1047 } else {
1048 plane_formats = ilk_plane_formats;
1049 num_plane_formats = ARRAY_SIZE(ilk_plane_formats);
1050 }
1051 break;
1052
1053 case 7:
Damien Lespiaud49f7092013-04-25 15:15:00 +01001054 if (IS_IVYBRIDGE(dev)) {
Damien Lespiau2d354c32012-10-22 18:19:27 +01001055 intel_plane->can_scale = true;
Damien Lespiaud49f7092013-04-25 15:15:00 +01001056 intel_plane->max_downscale = 2;
1057 } else {
1058 intel_plane->can_scale = false;
1059 intel_plane->max_downscale = 1;
1060 }
Chris Wilsond1686ae2012-04-10 11:41:49 +01001061
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001062 if (IS_VALLEYVIEW(dev)) {
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001063 intel_plane->update_plane = vlv_update_plane;
1064 intel_plane->disable_plane = vlv_disable_plane;
1065 intel_plane->update_colorkey = vlv_update_colorkey;
1066 intel_plane->get_colorkey = vlv_get_colorkey;
1067
1068 plane_formats = vlv_plane_formats;
1069 num_plane_formats = ARRAY_SIZE(vlv_plane_formats);
1070 } else {
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001071 intel_plane->update_plane = ivb_update_plane;
1072 intel_plane->disable_plane = ivb_disable_plane;
1073 intel_plane->update_colorkey = ivb_update_colorkey;
1074 intel_plane->get_colorkey = ivb_get_colorkey;
1075
1076 plane_formats = snb_plane_formats;
1077 num_plane_formats = ARRAY_SIZE(snb_plane_formats);
1078 }
Chris Wilsond1686ae2012-04-10 11:41:49 +01001079 break;
1080
1081 default:
Jesper Juhla8b0bba2012-06-27 00:55:37 +02001082 kfree(intel_plane);
Chris Wilsond1686ae2012-04-10 11:41:49 +01001083 return -ENODEV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001084 }
1085
1086 intel_plane->pipe = pipe;
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001087 intel_plane->plane = plane;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001088 possible_crtcs = (1 << pipe);
1089 ret = drm_plane_init(dev, &intel_plane->base, possible_crtcs,
Chris Wilsond1686ae2012-04-10 11:41:49 +01001090 &intel_plane_funcs,
1091 plane_formats, num_plane_formats,
1092 false);
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001093 if (ret)
1094 kfree(intel_plane);
1095
1096 return ret;
1097}