blob: 069155f17edba3edc2c605cded0b2839738faa22 [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
Jesse Barnes7f1f3852013-04-02 11:22:20 -070041vlv_update_plane(struct drm_plane *dplane, struct drm_framebuffer *fb,
42 struct drm_i915_gem_object *obj, int crtc_x, int crtc_y,
43 unsigned int crtc_w, unsigned int crtc_h,
44 uint32_t x, uint32_t y,
45 uint32_t src_w, uint32_t src_h)
46{
47 struct drm_device *dev = dplane->dev;
48 struct drm_i915_private *dev_priv = dev->dev_private;
49 struct intel_plane *intel_plane = to_intel_plane(dplane);
50 int pipe = intel_plane->pipe;
51 int plane = intel_plane->plane;
52 u32 sprctl;
53 unsigned long sprsurf_offset, linear_offset;
54 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
55
56 sprctl = I915_READ(SPCNTR(pipe, plane));
57
58 /* Mask out pixel format bits in case we change it */
59 sprctl &= ~SP_PIXFORMAT_MASK;
60 sprctl &= ~SP_YUV_BYTE_ORDER_MASK;
61 sprctl &= ~SP_TILED;
62
63 switch (fb->pixel_format) {
64 case DRM_FORMAT_YUYV:
65 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YUYV;
66 break;
67 case DRM_FORMAT_YVYU:
68 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YVYU;
69 break;
70 case DRM_FORMAT_UYVY:
71 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_UYVY;
72 break;
73 case DRM_FORMAT_VYUY:
74 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_VYUY;
75 break;
76 case DRM_FORMAT_RGB565:
77 sprctl |= SP_FORMAT_BGR565;
78 break;
79 case DRM_FORMAT_XRGB8888:
80 sprctl |= SP_FORMAT_BGRX8888;
81 break;
82 case DRM_FORMAT_ARGB8888:
83 sprctl |= SP_FORMAT_BGRA8888;
84 break;
85 case DRM_FORMAT_XBGR2101010:
86 sprctl |= SP_FORMAT_RGBX1010102;
87 break;
88 case DRM_FORMAT_ABGR2101010:
89 sprctl |= SP_FORMAT_RGBA1010102;
90 break;
91 case DRM_FORMAT_XBGR8888:
92 sprctl |= SP_FORMAT_RGBX8888;
93 break;
94 case DRM_FORMAT_ABGR8888:
95 sprctl |= SP_FORMAT_RGBA8888;
96 break;
97 default:
98 /*
99 * If we get here one of the upper layers failed to filter
100 * out the unsupported plane formats
101 */
102 BUG();
103 break;
104 }
105
106 if (obj->tiling_mode != I915_TILING_NONE)
107 sprctl |= SP_TILED;
108
109 sprctl |= SP_ENABLE;
110
111 /* Sizes are 0 based */
112 src_w--;
113 src_h--;
114 crtc_w--;
115 crtc_h--;
116
Ville Syrjäläbdd57d02013-07-05 11:57:13 +0300117 intel_update_sprite_watermarks(dev, pipe, crtc_w, pixel_size, true,
118 src_w != crtc_w || src_h != crtc_h);
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700119
120 I915_WRITE(SPSTRIDE(pipe, plane), fb->pitches[0]);
121 I915_WRITE(SPPOS(pipe, plane), (crtc_y << 16) | crtc_x);
122
123 linear_offset = y * fb->pitches[0] + x * pixel_size;
124 sprsurf_offset = intel_gen4_compute_page_offset(&x, &y,
125 obj->tiling_mode,
126 pixel_size,
127 fb->pitches[0]);
128 linear_offset -= sprsurf_offset;
129
130 if (obj->tiling_mode != I915_TILING_NONE)
131 I915_WRITE(SPTILEOFF(pipe, plane), (y << 16) | x);
132 else
133 I915_WRITE(SPLINOFF(pipe, plane), linear_offset);
134
135 I915_WRITE(SPSIZE(pipe, plane), (crtc_h << 16) | crtc_w);
136 I915_WRITE(SPCNTR(pipe, plane), sprctl);
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700137 I915_MODIFY_DISPBASE(SPSURF(pipe, plane), i915_gem_obj_ggtt_offset(obj) +
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700138 sprsurf_offset);
139 POSTING_READ(SPSURF(pipe, plane));
140}
141
142static void
143vlv_disable_plane(struct drm_plane *dplane)
144{
145 struct drm_device *dev = dplane->dev;
146 struct drm_i915_private *dev_priv = dev->dev_private;
147 struct intel_plane *intel_plane = to_intel_plane(dplane);
148 int pipe = intel_plane->pipe;
149 int plane = intel_plane->plane;
150
151 I915_WRITE(SPCNTR(pipe, plane), I915_READ(SPCNTR(pipe, plane)) &
152 ~SP_ENABLE);
153 /* Activate double buffered register update */
154 I915_MODIFY_DISPBASE(SPSURF(pipe, plane), 0);
155 POSTING_READ(SPSURF(pipe, plane));
156}
157
158static int
159vlv_update_colorkey(struct drm_plane *dplane,
160 struct drm_intel_sprite_colorkey *key)
161{
162 struct drm_device *dev = dplane->dev;
163 struct drm_i915_private *dev_priv = dev->dev_private;
164 struct intel_plane *intel_plane = to_intel_plane(dplane);
165 int pipe = intel_plane->pipe;
166 int plane = intel_plane->plane;
167 u32 sprctl;
168
169 if (key->flags & I915_SET_COLORKEY_DESTINATION)
170 return -EINVAL;
171
172 I915_WRITE(SPKEYMINVAL(pipe, plane), key->min_value);
173 I915_WRITE(SPKEYMAXVAL(pipe, plane), key->max_value);
174 I915_WRITE(SPKEYMSK(pipe, plane), key->channel_mask);
175
176 sprctl = I915_READ(SPCNTR(pipe, plane));
177 sprctl &= ~SP_SOURCE_KEY;
178 if (key->flags & I915_SET_COLORKEY_SOURCE)
179 sprctl |= SP_SOURCE_KEY;
180 I915_WRITE(SPCNTR(pipe, plane), sprctl);
181
182 POSTING_READ(SPKEYMSK(pipe, plane));
183
184 return 0;
185}
186
187static void
188vlv_get_colorkey(struct drm_plane *dplane,
189 struct drm_intel_sprite_colorkey *key)
190{
191 struct drm_device *dev = dplane->dev;
192 struct drm_i915_private *dev_priv = dev->dev_private;
193 struct intel_plane *intel_plane = to_intel_plane(dplane);
194 int pipe = intel_plane->pipe;
195 int plane = intel_plane->plane;
196 u32 sprctl;
197
198 key->min_value = I915_READ(SPKEYMINVAL(pipe, plane));
199 key->max_value = I915_READ(SPKEYMAXVAL(pipe, plane));
200 key->channel_mask = I915_READ(SPKEYMSK(pipe, plane));
201
202 sprctl = I915_READ(SPCNTR(pipe, plane));
203 if (sprctl & SP_SOURCE_KEY)
204 key->flags = I915_SET_COLORKEY_SOURCE;
205 else
206 key->flags = I915_SET_COLORKEY_NONE;
207}
208
209static void
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800210ivb_update_plane(struct drm_plane *plane, struct drm_framebuffer *fb,
211 struct drm_i915_gem_object *obj, int crtc_x, int crtc_y,
212 unsigned int crtc_w, unsigned int crtc_h,
213 uint32_t x, uint32_t y,
214 uint32_t src_w, uint32_t src_h)
215{
216 struct drm_device *dev = plane->dev;
217 struct drm_i915_private *dev_priv = dev->dev_private;
218 struct intel_plane *intel_plane = to_intel_plane(plane);
219 int pipe = intel_plane->pipe;
220 u32 sprctl, sprscale = 0;
Damien Lespiau5a35e992012-10-26 18:20:12 +0100221 unsigned long sprsurf_offset, linear_offset;
Ville Syrjälä2bd3c3c2012-10-31 17:50:20 +0200222 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
Ville Syrjälä2c6602d2013-02-08 23:13:35 +0200223 bool scaling_was_enabled = dev_priv->sprite_scaling_enabled;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800224
225 sprctl = I915_READ(SPRCTL(pipe));
226
227 /* Mask out pixel format bits in case we change it */
228 sprctl &= ~SPRITE_PIXFORMAT_MASK;
229 sprctl &= ~SPRITE_RGB_ORDER_RGBX;
230 sprctl &= ~SPRITE_YUV_BYTE_ORDER_MASK;
Jesse Barnese86fe0d2012-06-26 13:10:11 -0700231 sprctl &= ~SPRITE_TILED;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800232
233 switch (fb->pixel_format) {
234 case DRM_FORMAT_XBGR8888:
Vijay Purushothaman5ee36912012-08-23 12:08:57 +0530235 sprctl |= SPRITE_FORMAT_RGBX888 | SPRITE_RGB_ORDER_RGBX;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800236 break;
237 case DRM_FORMAT_XRGB8888:
Vijay Purushothaman5ee36912012-08-23 12:08:57 +0530238 sprctl |= SPRITE_FORMAT_RGBX888;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800239 break;
240 case DRM_FORMAT_YUYV:
241 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YUYV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800242 break;
243 case DRM_FORMAT_YVYU:
244 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YVYU;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800245 break;
246 case DRM_FORMAT_UYVY:
247 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_UYVY;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800248 break;
249 case DRM_FORMAT_VYUY:
250 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_VYUY;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800251 break;
252 default:
Ville Syrjälä28d491d2012-10-31 17:50:21 +0200253 BUG();
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800254 }
255
256 if (obj->tiling_mode != I915_TILING_NONE)
257 sprctl |= SPRITE_TILED;
258
259 /* must disable */
260 sprctl |= SPRITE_TRICKLE_FEED_DISABLE;
261 sprctl |= SPRITE_ENABLE;
262
Ville Syrjälä86d3efc2013-01-18 19:11:38 +0200263 if (IS_HASWELL(dev))
264 sprctl |= SPRITE_PIPE_CSC_ENABLE;
265
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800266 /* Sizes are 0 based */
267 src_w--;
268 src_h--;
269 crtc_w--;
270 crtc_h--;
271
Ville Syrjäläbdd57d02013-07-05 11:57:13 +0300272 intel_update_sprite_watermarks(dev, pipe, crtc_w, pixel_size, true,
273 src_w != crtc_w || src_h != crtc_h);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800274
275 /*
276 * IVB workaround: must disable low power watermarks for at least
277 * one frame before enabling scaling. LP watermarks can be re-enabled
278 * when scaling is disabled.
279 */
280 if (crtc_w != src_w || crtc_h != src_h) {
Ville Syrjälä2c6602d2013-02-08 23:13:35 +0200281 dev_priv->sprite_scaling_enabled |= 1 << pipe;
282
283 if (!scaling_was_enabled) {
Chris Wilson828ed3e2012-04-18 17:12:26 +0100284 intel_update_watermarks(dev);
285 intel_wait_for_vblank(dev, pipe);
286 }
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800287 sprscale = SPRITE_SCALE_ENABLE | (src_w << 16) | src_h;
Ville Syrjälä2c6602d2013-02-08 23:13:35 +0200288 } else
289 dev_priv->sprite_scaling_enabled &= ~(1 << pipe);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800290
291 I915_WRITE(SPRSTRIDE(pipe), fb->pitches[0]);
292 I915_WRITE(SPRPOS(pipe), (crtc_y << 16) | crtc_x);
Damien Lespiauc54173a2012-10-26 18:20:11 +0100293
Chris Wilsonca320ac2012-12-19 12:14:22 +0000294 linear_offset = y * fb->pitches[0] + x * pixel_size;
Damien Lespiau5a35e992012-10-26 18:20:12 +0100295 sprsurf_offset =
Chris Wilsonbc752862013-02-21 20:04:31 +0000296 intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
297 pixel_size, fb->pitches[0]);
Damien Lespiau5a35e992012-10-26 18:20:12 +0100298 linear_offset -= sprsurf_offset;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800299
Damien Lespiau5a35e992012-10-26 18:20:12 +0100300 /* HSW consolidates SPRTILEOFF and SPRLINOFF into a single SPROFFSET
301 * register */
302 if (IS_HASWELL(dev))
303 I915_WRITE(SPROFFSET(pipe), (y << 16) | x);
304 else if (obj->tiling_mode != I915_TILING_NONE)
305 I915_WRITE(SPRTILEOFF(pipe), (y << 16) | x);
306 else
307 I915_WRITE(SPRLINOFF(pipe), linear_offset);
Damien Lespiauc54173a2012-10-26 18:20:11 +0100308
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800309 I915_WRITE(SPRSIZE(pipe), (crtc_h << 16) | crtc_w);
Damien Lespiau2d354c32012-10-22 18:19:27 +0100310 if (intel_plane->can_scale)
311 I915_WRITE(SPRSCALE(pipe), sprscale);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800312 I915_WRITE(SPRCTL(pipe), sprctl);
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700313 I915_MODIFY_DISPBASE(SPRSURF(pipe),
314 i915_gem_obj_ggtt_offset(obj) + sprsurf_offset);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800315 POSTING_READ(SPRSURF(pipe));
Ville Syrjälä2c6602d2013-02-08 23:13:35 +0200316
317 /* potentially re-enable LP watermarks */
318 if (scaling_was_enabled && !dev_priv->sprite_scaling_enabled)
319 intel_update_watermarks(dev);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800320}
321
322static void
323ivb_disable_plane(struct drm_plane *plane)
324{
325 struct drm_device *dev = plane->dev;
326 struct drm_i915_private *dev_priv = dev->dev_private;
327 struct intel_plane *intel_plane = to_intel_plane(plane);
328 int pipe = intel_plane->pipe;
Ville Syrjälä2c6602d2013-02-08 23:13:35 +0200329 bool scaling_was_enabled = dev_priv->sprite_scaling_enabled;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800330
331 I915_WRITE(SPRCTL(pipe), I915_READ(SPRCTL(pipe)) & ~SPRITE_ENABLE);
332 /* Can't leave the scaler enabled... */
Damien Lespiau2d354c32012-10-22 18:19:27 +0100333 if (intel_plane->can_scale)
334 I915_WRITE(SPRSCALE(pipe), 0);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800335 /* Activate double buffered register update */
Armin Reese446f2542012-03-30 16:20:16 -0700336 I915_MODIFY_DISPBASE(SPRSURF(pipe), 0);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800337 POSTING_READ(SPRSURF(pipe));
Chris Wilson828ed3e2012-04-18 17:12:26 +0100338
Ville Syrjälä2c6602d2013-02-08 23:13:35 +0200339 dev_priv->sprite_scaling_enabled &= ~(1 << pipe);
340
Ville Syrjäläbdd57d02013-07-05 11:57:13 +0300341 intel_update_sprite_watermarks(dev, pipe, 0, 0, false, false);
Paulo Zanoni4c4ff432013-05-24 11:59:17 -0300342
Ville Syrjälä2c6602d2013-02-08 23:13:35 +0200343 /* potentially re-enable LP watermarks */
344 if (scaling_was_enabled && !dev_priv->sprite_scaling_enabled)
345 intel_update_watermarks(dev);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800346}
347
Jesse Barnes8ea30862012-01-03 08:05:39 -0800348static int
349ivb_update_colorkey(struct drm_plane *plane,
350 struct drm_intel_sprite_colorkey *key)
351{
352 struct drm_device *dev = plane->dev;
353 struct drm_i915_private *dev_priv = dev->dev_private;
354 struct intel_plane *intel_plane;
355 u32 sprctl;
356 int ret = 0;
357
358 intel_plane = to_intel_plane(plane);
359
360 I915_WRITE(SPRKEYVAL(intel_plane->pipe), key->min_value);
361 I915_WRITE(SPRKEYMAX(intel_plane->pipe), key->max_value);
362 I915_WRITE(SPRKEYMSK(intel_plane->pipe), key->channel_mask);
363
364 sprctl = I915_READ(SPRCTL(intel_plane->pipe));
365 sprctl &= ~(SPRITE_SOURCE_KEY | SPRITE_DEST_KEY);
366 if (key->flags & I915_SET_COLORKEY_DESTINATION)
367 sprctl |= SPRITE_DEST_KEY;
368 else if (key->flags & I915_SET_COLORKEY_SOURCE)
369 sprctl |= SPRITE_SOURCE_KEY;
370 I915_WRITE(SPRCTL(intel_plane->pipe), sprctl);
371
372 POSTING_READ(SPRKEYMSK(intel_plane->pipe));
373
374 return ret;
375}
376
377static void
378ivb_get_colorkey(struct drm_plane *plane, struct drm_intel_sprite_colorkey *key)
379{
380 struct drm_device *dev = plane->dev;
381 struct drm_i915_private *dev_priv = dev->dev_private;
382 struct intel_plane *intel_plane;
383 u32 sprctl;
384
385 intel_plane = to_intel_plane(plane);
386
387 key->min_value = I915_READ(SPRKEYVAL(intel_plane->pipe));
388 key->max_value = I915_READ(SPRKEYMAX(intel_plane->pipe));
389 key->channel_mask = I915_READ(SPRKEYMSK(intel_plane->pipe));
390 key->flags = 0;
391
392 sprctl = I915_READ(SPRCTL(intel_plane->pipe));
393
394 if (sprctl & SPRITE_DEST_KEY)
395 key->flags = I915_SET_COLORKEY_DESTINATION;
396 else if (sprctl & SPRITE_SOURCE_KEY)
397 key->flags = I915_SET_COLORKEY_SOURCE;
398 else
399 key->flags = I915_SET_COLORKEY_NONE;
400}
401
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800402static void
Chris Wilsond1686ae2012-04-10 11:41:49 +0100403ilk_update_plane(struct drm_plane *plane, struct drm_framebuffer *fb,
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800404 struct drm_i915_gem_object *obj, int crtc_x, int crtc_y,
405 unsigned int crtc_w, unsigned int crtc_h,
406 uint32_t x, uint32_t y,
407 uint32_t src_w, uint32_t src_h)
408{
409 struct drm_device *dev = plane->dev;
410 struct drm_i915_private *dev_priv = dev->dev_private;
411 struct intel_plane *intel_plane = to_intel_plane(plane);
Ville Syrjälä2bd3c3c2012-10-31 17:50:20 +0200412 int pipe = intel_plane->pipe;
Damien Lespiau5a35e992012-10-26 18:20:12 +0100413 unsigned long dvssurf_offset, linear_offset;
Chris Wilson8aaa81a2012-04-14 22:14:26 +0100414 u32 dvscntr, dvsscale;
Ville Syrjälä2bd3c3c2012-10-31 17:50:20 +0200415 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800416
417 dvscntr = I915_READ(DVSCNTR(pipe));
418
419 /* Mask out pixel format bits in case we change it */
420 dvscntr &= ~DVS_PIXFORMAT_MASK;
Jesse Barnesab2f9df2012-02-27 12:40:10 -0800421 dvscntr &= ~DVS_RGB_ORDER_XBGR;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800422 dvscntr &= ~DVS_YUV_BYTE_ORDER_MASK;
Ander Conselvan de Oliveira79626522012-07-13 15:50:33 +0300423 dvscntr &= ~DVS_TILED;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800424
425 switch (fb->pixel_format) {
426 case DRM_FORMAT_XBGR8888:
Jesse Barnesab2f9df2012-02-27 12:40:10 -0800427 dvscntr |= DVS_FORMAT_RGBX888 | DVS_RGB_ORDER_XBGR;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800428 break;
429 case DRM_FORMAT_XRGB8888:
Jesse Barnesab2f9df2012-02-27 12:40:10 -0800430 dvscntr |= DVS_FORMAT_RGBX888;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800431 break;
432 case DRM_FORMAT_YUYV:
433 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YUYV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800434 break;
435 case DRM_FORMAT_YVYU:
436 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YVYU;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800437 break;
438 case DRM_FORMAT_UYVY:
439 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_UYVY;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800440 break;
441 case DRM_FORMAT_VYUY:
442 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_VYUY;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800443 break;
444 default:
Ville Syrjälä28d491d2012-10-31 17:50:21 +0200445 BUG();
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800446 }
447
448 if (obj->tiling_mode != I915_TILING_NONE)
449 dvscntr |= DVS_TILED;
450
Chris Wilsond1686ae2012-04-10 11:41:49 +0100451 if (IS_GEN6(dev))
452 dvscntr |= DVS_TRICKLE_FEED_DISABLE; /* must disable */
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800453 dvscntr |= DVS_ENABLE;
454
455 /* Sizes are 0 based */
456 src_w--;
457 src_h--;
458 crtc_w--;
459 crtc_h--;
460
Ville Syrjäläbdd57d02013-07-05 11:57:13 +0300461 intel_update_sprite_watermarks(dev, pipe, crtc_w, pixel_size, true,
462 src_w != crtc_w || src_h != crtc_h);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800463
Chris Wilson8aaa81a2012-04-14 22:14:26 +0100464 dvsscale = 0;
465 if (IS_GEN5(dev) || crtc_w != src_w || crtc_h != src_h)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800466 dvsscale = DVS_SCALE_ENABLE | (src_w << 16) | src_h;
467
468 I915_WRITE(DVSSTRIDE(pipe), fb->pitches[0]);
469 I915_WRITE(DVSPOS(pipe), (crtc_y << 16) | crtc_x);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800470
Chris Wilsonca320ac2012-12-19 12:14:22 +0000471 linear_offset = y * fb->pitches[0] + x * pixel_size;
Damien Lespiau5a35e992012-10-26 18:20:12 +0100472 dvssurf_offset =
Chris Wilsonbc752862013-02-21 20:04:31 +0000473 intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
474 pixel_size, fb->pitches[0]);
Damien Lespiau5a35e992012-10-26 18:20:12 +0100475 linear_offset -= dvssurf_offset;
476
477 if (obj->tiling_mode != I915_TILING_NONE)
478 I915_WRITE(DVSTILEOFF(pipe), (y << 16) | x);
479 else
480 I915_WRITE(DVSLINOFF(pipe), linear_offset);
481
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800482 I915_WRITE(DVSSIZE(pipe), (crtc_h << 16) | crtc_w);
483 I915_WRITE(DVSSCALE(pipe), dvsscale);
484 I915_WRITE(DVSCNTR(pipe), dvscntr);
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700485 I915_MODIFY_DISPBASE(DVSSURF(pipe),
486 i915_gem_obj_ggtt_offset(obj) + dvssurf_offset);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800487 POSTING_READ(DVSSURF(pipe));
488}
489
490static void
Chris Wilsond1686ae2012-04-10 11:41:49 +0100491ilk_disable_plane(struct drm_plane *plane)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800492{
493 struct drm_device *dev = plane->dev;
494 struct drm_i915_private *dev_priv = dev->dev_private;
495 struct intel_plane *intel_plane = to_intel_plane(plane);
496 int pipe = intel_plane->pipe;
497
498 I915_WRITE(DVSCNTR(pipe), I915_READ(DVSCNTR(pipe)) & ~DVS_ENABLE);
499 /* Disable the scaler */
500 I915_WRITE(DVSSCALE(pipe), 0);
501 /* Flush double buffered register updates */
Armin Reese446f2542012-03-30 16:20:16 -0700502 I915_MODIFY_DISPBASE(DVSSURF(pipe), 0);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800503 POSTING_READ(DVSSURF(pipe));
504}
505
Jesse Barnes175bd422011-12-13 13:19:39 -0800506static void
507intel_enable_primary(struct drm_crtc *crtc)
508{
509 struct drm_device *dev = crtc->dev;
510 struct drm_i915_private *dev_priv = dev->dev_private;
511 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
512 int reg = DSPCNTR(intel_crtc->plane);
513
Chris Wilson93314b52012-06-13 17:36:55 +0100514 if (!intel_crtc->primary_disabled)
515 return;
516
517 intel_crtc->primary_disabled = false;
518 intel_update_fbc(dev);
519
Jesse Barnes175bd422011-12-13 13:19:39 -0800520 I915_WRITE(reg, I915_READ(reg) | DISPLAY_PLANE_ENABLE);
521}
522
523static void
524intel_disable_primary(struct drm_crtc *crtc)
525{
526 struct drm_device *dev = crtc->dev;
527 struct drm_i915_private *dev_priv = dev->dev_private;
528 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
529 int reg = DSPCNTR(intel_crtc->plane);
530
Chris Wilson93314b52012-06-13 17:36:55 +0100531 if (intel_crtc->primary_disabled)
532 return;
533
Jesse Barnes175bd422011-12-13 13:19:39 -0800534 I915_WRITE(reg, I915_READ(reg) & ~DISPLAY_PLANE_ENABLE);
Chris Wilson93314b52012-06-13 17:36:55 +0100535
536 intel_crtc->primary_disabled = true;
537 intel_update_fbc(dev);
Jesse Barnes175bd422011-12-13 13:19:39 -0800538}
539
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800540static int
Chris Wilsond1686ae2012-04-10 11:41:49 +0100541ilk_update_colorkey(struct drm_plane *plane,
Jesse Barnes8ea30862012-01-03 08:05:39 -0800542 struct drm_intel_sprite_colorkey *key)
543{
544 struct drm_device *dev = plane->dev;
545 struct drm_i915_private *dev_priv = dev->dev_private;
546 struct intel_plane *intel_plane;
547 u32 dvscntr;
548 int ret = 0;
549
550 intel_plane = to_intel_plane(plane);
551
552 I915_WRITE(DVSKEYVAL(intel_plane->pipe), key->min_value);
553 I915_WRITE(DVSKEYMAX(intel_plane->pipe), key->max_value);
554 I915_WRITE(DVSKEYMSK(intel_plane->pipe), key->channel_mask);
555
556 dvscntr = I915_READ(DVSCNTR(intel_plane->pipe));
557 dvscntr &= ~(DVS_SOURCE_KEY | DVS_DEST_KEY);
558 if (key->flags & I915_SET_COLORKEY_DESTINATION)
559 dvscntr |= DVS_DEST_KEY;
560 else if (key->flags & I915_SET_COLORKEY_SOURCE)
561 dvscntr |= DVS_SOURCE_KEY;
562 I915_WRITE(DVSCNTR(intel_plane->pipe), dvscntr);
563
564 POSTING_READ(DVSKEYMSK(intel_plane->pipe));
565
566 return ret;
567}
568
569static void
Chris Wilsond1686ae2012-04-10 11:41:49 +0100570ilk_get_colorkey(struct drm_plane *plane, struct drm_intel_sprite_colorkey *key)
Jesse Barnes8ea30862012-01-03 08:05:39 -0800571{
572 struct drm_device *dev = plane->dev;
573 struct drm_i915_private *dev_priv = dev->dev_private;
574 struct intel_plane *intel_plane;
575 u32 dvscntr;
576
577 intel_plane = to_intel_plane(plane);
578
579 key->min_value = I915_READ(DVSKEYVAL(intel_plane->pipe));
580 key->max_value = I915_READ(DVSKEYMAX(intel_plane->pipe));
581 key->channel_mask = I915_READ(DVSKEYMSK(intel_plane->pipe));
582 key->flags = 0;
583
584 dvscntr = I915_READ(DVSCNTR(intel_plane->pipe));
585
586 if (dvscntr & DVS_DEST_KEY)
587 key->flags = I915_SET_COLORKEY_DESTINATION;
588 else if (dvscntr & DVS_SOURCE_KEY)
589 key->flags = I915_SET_COLORKEY_SOURCE;
590 else
591 key->flags = I915_SET_COLORKEY_NONE;
592}
593
Ville Syrjälä17316932013-04-24 18:52:38 +0300594static bool
595format_is_yuv(uint32_t format)
596{
597 switch (format) {
598 case DRM_FORMAT_YUYV:
599 case DRM_FORMAT_UYVY:
600 case DRM_FORMAT_VYUY:
601 case DRM_FORMAT_YVYU:
602 return true;
603 default:
604 return false;
605 }
606}
607
Jesse Barnes8ea30862012-01-03 08:05:39 -0800608static int
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800609intel_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
610 struct drm_framebuffer *fb, int crtc_x, int crtc_y,
611 unsigned int crtc_w, unsigned int crtc_h,
612 uint32_t src_x, uint32_t src_y,
613 uint32_t src_w, uint32_t src_h)
614{
615 struct drm_device *dev = plane->dev;
616 struct drm_i915_private *dev_priv = dev->dev_private;
617 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
618 struct intel_plane *intel_plane = to_intel_plane(plane);
619 struct intel_framebuffer *intel_fb;
620 struct drm_i915_gem_object *obj, *old_obj;
621 int pipe = intel_plane->pipe;
Paulo Zanoni702e7a52012-10-23 18:29:59 -0200622 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
623 pipe);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800624 int ret = 0;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800625 bool disable_primary = false;
Ville Syrjälä17316932013-04-24 18:52:38 +0300626 bool visible;
627 int hscale, vscale;
628 int max_scale, min_scale;
629 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
630 struct drm_rect src = {
631 /* sample coordinates in 16.16 fixed point */
632 .x1 = src_x,
633 .x2 = src_x + src_w,
634 .y1 = src_y,
635 .y2 = src_y + src_h,
636 };
637 struct drm_rect dst = {
638 /* integer pixels */
639 .x1 = crtc_x,
640 .x2 = crtc_x + crtc_w,
641 .y1 = crtc_y,
642 .y2 = crtc_y + crtc_h,
643 };
644 const struct drm_rect clip = {
645 .x2 = crtc->mode.hdisplay,
646 .y2 = crtc->mode.vdisplay,
647 };
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800648
649 intel_fb = to_intel_framebuffer(fb);
650 obj = intel_fb->obj;
651
652 old_obj = intel_plane->obj;
653
Jesse Barnes5e1bac22013-03-26 09:25:43 -0700654 intel_plane->crtc_x = crtc_x;
655 intel_plane->crtc_y = crtc_y;
656 intel_plane->crtc_w = crtc_w;
657 intel_plane->crtc_h = crtc_h;
658 intel_plane->src_x = src_x;
659 intel_plane->src_y = src_y;
660 intel_plane->src_w = src_w;
661 intel_plane->src_h = src_h;
662
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800663 /* Pipe must be running... */
Ville Syrjälä17316932013-04-24 18:52:38 +0300664 if (!(I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_ENABLE)) {
665 DRM_DEBUG_KMS("Pipe disabled\n");
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800666 return -EINVAL;
Ville Syrjälä17316932013-04-24 18:52:38 +0300667 }
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800668
669 /* Don't modify another pipe's plane */
Ville Syrjälä17316932013-04-24 18:52:38 +0300670 if (intel_plane->pipe != intel_crtc->pipe) {
671 DRM_DEBUG_KMS("Wrong plane <-> crtc mapping\n");
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800672 return -EINVAL;
Ville Syrjälä17316932013-04-24 18:52:38 +0300673 }
674
675 /* FIXME check all gen limits */
676 if (fb->width < 3 || fb->height < 3 || fb->pitches[0] > 16384) {
677 DRM_DEBUG_KMS("Unsuitable framebuffer for plane\n");
678 return -EINVAL;
679 }
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800680
Damien Lespiau94c64192012-10-29 15:14:51 +0000681 /* Sprite planes can be linear or x-tiled surfaces */
682 switch (obj->tiling_mode) {
683 case I915_TILING_NONE:
684 case I915_TILING_X:
685 break;
686 default:
Ville Syrjälä17316932013-04-24 18:52:38 +0300687 DRM_DEBUG_KMS("Unsupported tiling mode\n");
Damien Lespiau94c64192012-10-29 15:14:51 +0000688 return -EINVAL;
689 }
690
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300691 /*
692 * FIXME the following code does a bunch of fuzzy adjustments to the
693 * coordinates and sizes. We probably need some way to decide whether
694 * more strict checking should be done instead.
695 */
Ville Syrjälä17316932013-04-24 18:52:38 +0300696 max_scale = intel_plane->max_downscale << 16;
697 min_scale = intel_plane->can_scale ? 1 : (1 << 16);
698
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300699 hscale = drm_rect_calc_hscale_relaxed(&src, &dst, min_scale, max_scale);
700 BUG_ON(hscale < 0);
Ville Syrjälä17316932013-04-24 18:52:38 +0300701
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300702 vscale = drm_rect_calc_vscale_relaxed(&src, &dst, min_scale, max_scale);
703 BUG_ON(vscale < 0);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800704
Ville Syrjälä17316932013-04-24 18:52:38 +0300705 visible = drm_rect_clip_scaled(&src, &dst, &clip, hscale, vscale);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800706
Ville Syrjälä17316932013-04-24 18:52:38 +0300707 crtc_x = dst.x1;
708 crtc_y = dst.y1;
709 crtc_w = drm_rect_width(&dst);
710 crtc_h = drm_rect_height(&dst);
Damien Lespiau2d354c32012-10-22 18:19:27 +0100711
Ville Syrjälä17316932013-04-24 18:52:38 +0300712 if (visible) {
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300713 /* check again in case clipping clamped the results */
714 hscale = drm_rect_calc_hscale(&src, &dst, min_scale, max_scale);
715 if (hscale < 0) {
716 DRM_DEBUG_KMS("Horizontal scaling factor out of limits\n");
717 drm_rect_debug_print(&src, true);
718 drm_rect_debug_print(&dst, false);
719
720 return hscale;
721 }
722
723 vscale = drm_rect_calc_vscale(&src, &dst, min_scale, max_scale);
724 if (vscale < 0) {
725 DRM_DEBUG_KMS("Vertical scaling factor out of limits\n");
726 drm_rect_debug_print(&src, true);
727 drm_rect_debug_print(&dst, false);
728
729 return vscale;
730 }
731
Ville Syrjälä17316932013-04-24 18:52:38 +0300732 /* Make the source viewport size an exact multiple of the scaling factors. */
733 drm_rect_adjust_size(&src,
734 drm_rect_width(&dst) * hscale - drm_rect_width(&src),
735 drm_rect_height(&dst) * vscale - drm_rect_height(&src));
736
737 /* sanity check to make sure the src viewport wasn't enlarged */
738 WARN_ON(src.x1 < (int) src_x ||
739 src.y1 < (int) src_y ||
740 src.x2 > (int) (src_x + src_w) ||
741 src.y2 > (int) (src_y + src_h));
742
743 /*
744 * Hardware doesn't handle subpixel coordinates.
745 * Adjust to (macro)pixel boundary, but be careful not to
746 * increase the source viewport size, because that could
747 * push the downscaling factor out of bounds.
Ville Syrjälä17316932013-04-24 18:52:38 +0300748 */
749 src_x = src.x1 >> 16;
750 src_w = drm_rect_width(&src) >> 16;
751 src_y = src.y1 >> 16;
752 src_h = drm_rect_height(&src) >> 16;
753
754 if (format_is_yuv(fb->pixel_format)) {
755 src_x &= ~1;
756 src_w &= ~1;
757
758 /*
759 * Must keep src and dst the
760 * same if we can't scale.
761 */
762 if (!intel_plane->can_scale)
763 crtc_w &= ~1;
764
765 if (crtc_w == 0)
766 visible = false;
767 }
768 }
769
770 /* Check size restrictions when scaling */
771 if (visible && (src_w != crtc_w || src_h != crtc_h)) {
772 unsigned int width_bytes;
773
774 WARN_ON(!intel_plane->can_scale);
775
776 /* FIXME interlacing min height is 6 */
777
778 if (crtc_w < 3 || crtc_h < 3)
779 visible = false;
780
781 if (src_w < 3 || src_h < 3)
782 visible = false;
783
784 width_bytes = ((src_x * pixel_size) & 63) + src_w * pixel_size;
785
786 if (src_w > 2048 || src_h > 2048 ||
787 width_bytes > 4096 || fb->pitches[0] > 4096) {
788 DRM_DEBUG_KMS("Source dimensions exceed hardware limits\n");
789 return -EINVAL;
790 }
791 }
792
793 dst.x1 = crtc_x;
794 dst.x2 = crtc_x + crtc_w;
795 dst.y1 = crtc_y;
796 dst.y2 = crtc_y + crtc_h;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800797
798 /*
799 * If the sprite is completely covering the primary plane,
800 * we can disable the primary and save power.
801 */
Ville Syrjälä17316932013-04-24 18:52:38 +0300802 disable_primary = drm_rect_equals(&dst, &clip);
803 WARN_ON(disable_primary && !visible);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800804
805 mutex_lock(&dev->struct_mutex);
806
Chris Wilson693db182013-03-05 14:52:39 +0000807 /* Note that this will apply the VT-d workaround for scanouts,
808 * which is more restrictive than required for sprites. (The
809 * primary plane requires 256KiB alignment with 64 PTE padding,
810 * the sprite planes only require 128KiB alignment and 32 PTE padding.
811 */
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800812 ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
Jesse Barnes00c2064b2012-01-13 15:48:39 -0800813 if (ret)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800814 goto out_unlock;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800815
816 intel_plane->obj = obj;
817
Jesse Barnes175bd422011-12-13 13:19:39 -0800818 /*
819 * Be sure to re-enable the primary before the sprite is no longer
820 * covering it fully.
821 */
Chris Wilson93314b52012-06-13 17:36:55 +0100822 if (!disable_primary)
Jesse Barnes175bd422011-12-13 13:19:39 -0800823 intel_enable_primary(crtc);
Jesse Barnes175bd422011-12-13 13:19:39 -0800824
Ville Syrjälä17316932013-04-24 18:52:38 +0300825 if (visible)
826 intel_plane->update_plane(plane, fb, obj,
827 crtc_x, crtc_y, crtc_w, crtc_h,
828 src_x, src_y, src_w, src_h);
829 else
830 intel_plane->disable_plane(plane);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800831
Chris Wilson93314b52012-06-13 17:36:55 +0100832 if (disable_primary)
Jesse Barnes175bd422011-12-13 13:19:39 -0800833 intel_disable_primary(crtc);
Jesse Barnes175bd422011-12-13 13:19:39 -0800834
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800835 /* Unpin old obj after new one is active to avoid ugliness */
836 if (old_obj) {
837 /*
838 * It's fairly common to simply update the position of
839 * an existing object. In that case, we don't need to
840 * wait for vblank to avoid ugliness, we only need to
841 * do the pin & ref bookkeeping.
842 */
843 if (old_obj != obj) {
844 mutex_unlock(&dev->struct_mutex);
845 intel_wait_for_vblank(dev, to_intel_crtc(crtc)->pipe);
846 mutex_lock(&dev->struct_mutex);
847 }
Chris Wilson1690e1e2011-12-14 13:57:08 +0100848 intel_unpin_fb_obj(old_obj);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800849 }
850
851out_unlock:
852 mutex_unlock(&dev->struct_mutex);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800853 return ret;
854}
855
856static int
857intel_disable_plane(struct drm_plane *plane)
858{
859 struct drm_device *dev = plane->dev;
860 struct intel_plane *intel_plane = to_intel_plane(plane);
861 int ret = 0;
862
Chris Wilson93314b52012-06-13 17:36:55 +0100863 if (plane->crtc)
Jesse Barnes175bd422011-12-13 13:19:39 -0800864 intel_enable_primary(plane->crtc);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800865 intel_plane->disable_plane(plane);
866
867 if (!intel_plane->obj)
868 goto out;
869
Ville Syrjäläc626d312013-03-27 17:49:13 +0200870 intel_wait_for_vblank(dev, intel_plane->pipe);
871
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800872 mutex_lock(&dev->struct_mutex);
Chris Wilson1690e1e2011-12-14 13:57:08 +0100873 intel_unpin_fb_obj(intel_plane->obj);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800874 intel_plane->obj = NULL;
875 mutex_unlock(&dev->struct_mutex);
876out:
877
878 return ret;
879}
880
881static void intel_destroy_plane(struct drm_plane *plane)
882{
883 struct intel_plane *intel_plane = to_intel_plane(plane);
884 intel_disable_plane(plane);
885 drm_plane_cleanup(plane);
886 kfree(intel_plane);
887}
888
Jesse Barnes8ea30862012-01-03 08:05:39 -0800889int intel_sprite_set_colorkey(struct drm_device *dev, void *data,
890 struct drm_file *file_priv)
891{
892 struct drm_intel_sprite_colorkey *set = data;
Jesse Barnes8ea30862012-01-03 08:05:39 -0800893 struct drm_mode_object *obj;
894 struct drm_plane *plane;
895 struct intel_plane *intel_plane;
896 int ret = 0;
897
Daniel Vetter1cff8f62012-04-24 09:55:08 +0200898 if (!drm_core_check_feature(dev, DRIVER_MODESET))
899 return -ENODEV;
Jesse Barnes8ea30862012-01-03 08:05:39 -0800900
901 /* Make sure we don't try to enable both src & dest simultaneously */
902 if ((set->flags & (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE)) == (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE))
903 return -EINVAL;
904
Daniel Vettera0e99e62012-12-02 01:05:46 +0100905 drm_modeset_lock_all(dev);
Jesse Barnes8ea30862012-01-03 08:05:39 -0800906
907 obj = drm_mode_object_find(dev, set->plane_id, DRM_MODE_OBJECT_PLANE);
908 if (!obj) {
909 ret = -EINVAL;
910 goto out_unlock;
911 }
912
913 plane = obj_to_plane(obj);
914 intel_plane = to_intel_plane(plane);
915 ret = intel_plane->update_colorkey(plane, set);
916
917out_unlock:
Daniel Vettera0e99e62012-12-02 01:05:46 +0100918 drm_modeset_unlock_all(dev);
Jesse Barnes8ea30862012-01-03 08:05:39 -0800919 return ret;
920}
921
922int intel_sprite_get_colorkey(struct drm_device *dev, void *data,
923 struct drm_file *file_priv)
924{
925 struct drm_intel_sprite_colorkey *get = data;
Jesse Barnes8ea30862012-01-03 08:05:39 -0800926 struct drm_mode_object *obj;
927 struct drm_plane *plane;
928 struct intel_plane *intel_plane;
929 int ret = 0;
930
Daniel Vetter1cff8f62012-04-24 09:55:08 +0200931 if (!drm_core_check_feature(dev, DRIVER_MODESET))
932 return -ENODEV;
Jesse Barnes8ea30862012-01-03 08:05:39 -0800933
Daniel Vettera0e99e62012-12-02 01:05:46 +0100934 drm_modeset_lock_all(dev);
Jesse Barnes8ea30862012-01-03 08:05:39 -0800935
936 obj = drm_mode_object_find(dev, get->plane_id, DRM_MODE_OBJECT_PLANE);
937 if (!obj) {
938 ret = -EINVAL;
939 goto out_unlock;
940 }
941
942 plane = obj_to_plane(obj);
943 intel_plane = to_intel_plane(plane);
944 intel_plane->get_colorkey(plane, get);
945
946out_unlock:
Daniel Vettera0e99e62012-12-02 01:05:46 +0100947 drm_modeset_unlock_all(dev);
Jesse Barnes8ea30862012-01-03 08:05:39 -0800948 return ret;
949}
950
Jesse Barnes5e1bac22013-03-26 09:25:43 -0700951void intel_plane_restore(struct drm_plane *plane)
952{
953 struct intel_plane *intel_plane = to_intel_plane(plane);
954
955 if (!plane->crtc || !plane->fb)
956 return;
957
958 intel_update_plane(plane, plane->crtc, plane->fb,
959 intel_plane->crtc_x, intel_plane->crtc_y,
960 intel_plane->crtc_w, intel_plane->crtc_h,
961 intel_plane->src_x, intel_plane->src_y,
962 intel_plane->src_w, intel_plane->src_h);
963}
964
Ville Syrjäläbb53d4a2013-06-04 13:49:04 +0300965void intel_plane_disable(struct drm_plane *plane)
966{
967 if (!plane->crtc || !plane->fb)
968 return;
969
970 intel_disable_plane(plane);
971}
972
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800973static const struct drm_plane_funcs intel_plane_funcs = {
974 .update_plane = intel_update_plane,
975 .disable_plane = intel_disable_plane,
976 .destroy = intel_destroy_plane,
977};
978
Chris Wilsond1686ae2012-04-10 11:41:49 +0100979static uint32_t ilk_plane_formats[] = {
980 DRM_FORMAT_XRGB8888,
981 DRM_FORMAT_YUYV,
982 DRM_FORMAT_YVYU,
983 DRM_FORMAT_UYVY,
984 DRM_FORMAT_VYUY,
985};
986
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800987static uint32_t snb_plane_formats[] = {
988 DRM_FORMAT_XBGR8888,
989 DRM_FORMAT_XRGB8888,
990 DRM_FORMAT_YUYV,
991 DRM_FORMAT_YVYU,
992 DRM_FORMAT_UYVY,
993 DRM_FORMAT_VYUY,
994};
995
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700996static uint32_t vlv_plane_formats[] = {
997 DRM_FORMAT_RGB565,
998 DRM_FORMAT_ABGR8888,
999 DRM_FORMAT_ARGB8888,
1000 DRM_FORMAT_XBGR8888,
1001 DRM_FORMAT_XRGB8888,
1002 DRM_FORMAT_XBGR2101010,
1003 DRM_FORMAT_ABGR2101010,
1004 DRM_FORMAT_YUYV,
1005 DRM_FORMAT_YVYU,
1006 DRM_FORMAT_UYVY,
1007 DRM_FORMAT_VYUY,
1008};
1009
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001010int
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001011intel_plane_init(struct drm_device *dev, enum pipe pipe, int plane)
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001012{
1013 struct intel_plane *intel_plane;
1014 unsigned long possible_crtcs;
Chris Wilsond1686ae2012-04-10 11:41:49 +01001015 const uint32_t *plane_formats;
1016 int num_plane_formats;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001017 int ret;
1018
Chris Wilsond1686ae2012-04-10 11:41:49 +01001019 if (INTEL_INFO(dev)->gen < 5)
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001020 return -ENODEV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001021
1022 intel_plane = kzalloc(sizeof(struct intel_plane), GFP_KERNEL);
1023 if (!intel_plane)
1024 return -ENOMEM;
1025
Chris Wilsond1686ae2012-04-10 11:41:49 +01001026 switch (INTEL_INFO(dev)->gen) {
1027 case 5:
1028 case 6:
Damien Lespiau2d354c32012-10-22 18:19:27 +01001029 intel_plane->can_scale = true;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001030 intel_plane->max_downscale = 16;
Chris Wilsond1686ae2012-04-10 11:41:49 +01001031 intel_plane->update_plane = ilk_update_plane;
1032 intel_plane->disable_plane = ilk_disable_plane;
1033 intel_plane->update_colorkey = ilk_update_colorkey;
1034 intel_plane->get_colorkey = ilk_get_colorkey;
1035
1036 if (IS_GEN6(dev)) {
1037 plane_formats = snb_plane_formats;
1038 num_plane_formats = ARRAY_SIZE(snb_plane_formats);
1039 } else {
1040 plane_formats = ilk_plane_formats;
1041 num_plane_formats = ARRAY_SIZE(ilk_plane_formats);
1042 }
1043 break;
1044
1045 case 7:
Damien Lespiaud49f7092013-04-25 15:15:00 +01001046 if (IS_IVYBRIDGE(dev)) {
Damien Lespiau2d354c32012-10-22 18:19:27 +01001047 intel_plane->can_scale = true;
Damien Lespiaud49f7092013-04-25 15:15:00 +01001048 intel_plane->max_downscale = 2;
1049 } else {
1050 intel_plane->can_scale = false;
1051 intel_plane->max_downscale = 1;
1052 }
Chris Wilsond1686ae2012-04-10 11:41:49 +01001053
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001054 if (IS_VALLEYVIEW(dev)) {
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001055 intel_plane->update_plane = vlv_update_plane;
1056 intel_plane->disable_plane = vlv_disable_plane;
1057 intel_plane->update_colorkey = vlv_update_colorkey;
1058 intel_plane->get_colorkey = vlv_get_colorkey;
1059
1060 plane_formats = vlv_plane_formats;
1061 num_plane_formats = ARRAY_SIZE(vlv_plane_formats);
1062 } else {
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001063 intel_plane->update_plane = ivb_update_plane;
1064 intel_plane->disable_plane = ivb_disable_plane;
1065 intel_plane->update_colorkey = ivb_update_colorkey;
1066 intel_plane->get_colorkey = ivb_get_colorkey;
1067
1068 plane_formats = snb_plane_formats;
1069 num_plane_formats = ARRAY_SIZE(snb_plane_formats);
1070 }
Chris Wilsond1686ae2012-04-10 11:41:49 +01001071 break;
1072
1073 default:
Jesper Juhla8b0bba2012-06-27 00:55:37 +02001074 kfree(intel_plane);
Chris Wilsond1686ae2012-04-10 11:41:49 +01001075 return -ENODEV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001076 }
1077
1078 intel_plane->pipe = pipe;
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001079 intel_plane->plane = plane;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001080 possible_crtcs = (1 << pipe);
1081 ret = drm_plane_init(dev, &intel_plane->base, possible_crtcs,
Chris Wilsond1686ae2012-04-10 11:41:49 +01001082 &intel_plane_funcs,
1083 plane_formats, num_plane_formats,
1084 false);
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001085 if (ret)
1086 kfree(intel_plane);
1087
1088 return ret;
1089}