blob: 78b621cdd108f13ae061c27a1499df71c84da5bd [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äadf3d352013-08-06 22:24:11 +0300112 intel_update_sprite_watermarks(dplane, crtc, 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));
Ville Syrjäläa95fd8c2013-08-06 22:24:12 +0300157
158 intel_update_sprite_watermarks(dplane, crtc, 0, 0, false, false);
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700159}
160
161static int
162vlv_update_colorkey(struct drm_plane *dplane,
163 struct drm_intel_sprite_colorkey *key)
164{
165 struct drm_device *dev = dplane->dev;
166 struct drm_i915_private *dev_priv = dev->dev_private;
167 struct intel_plane *intel_plane = to_intel_plane(dplane);
168 int pipe = intel_plane->pipe;
169 int plane = intel_plane->plane;
170 u32 sprctl;
171
172 if (key->flags & I915_SET_COLORKEY_DESTINATION)
173 return -EINVAL;
174
175 I915_WRITE(SPKEYMINVAL(pipe, plane), key->min_value);
176 I915_WRITE(SPKEYMAXVAL(pipe, plane), key->max_value);
177 I915_WRITE(SPKEYMSK(pipe, plane), key->channel_mask);
178
179 sprctl = I915_READ(SPCNTR(pipe, plane));
180 sprctl &= ~SP_SOURCE_KEY;
181 if (key->flags & I915_SET_COLORKEY_SOURCE)
182 sprctl |= SP_SOURCE_KEY;
183 I915_WRITE(SPCNTR(pipe, plane), sprctl);
184
185 POSTING_READ(SPKEYMSK(pipe, plane));
186
187 return 0;
188}
189
190static void
191vlv_get_colorkey(struct drm_plane *dplane,
192 struct drm_intel_sprite_colorkey *key)
193{
194 struct drm_device *dev = dplane->dev;
195 struct drm_i915_private *dev_priv = dev->dev_private;
196 struct intel_plane *intel_plane = to_intel_plane(dplane);
197 int pipe = intel_plane->pipe;
198 int plane = intel_plane->plane;
199 u32 sprctl;
200
201 key->min_value = I915_READ(SPKEYMINVAL(pipe, plane));
202 key->max_value = I915_READ(SPKEYMAXVAL(pipe, plane));
203 key->channel_mask = I915_READ(SPKEYMSK(pipe, plane));
204
205 sprctl = I915_READ(SPCNTR(pipe, plane));
206 if (sprctl & SP_SOURCE_KEY)
207 key->flags = I915_SET_COLORKEY_SOURCE;
208 else
209 key->flags = I915_SET_COLORKEY_NONE;
210}
211
212static void
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300213ivb_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
214 struct drm_framebuffer *fb,
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800215 struct drm_i915_gem_object *obj, int crtc_x, int crtc_y,
216 unsigned int crtc_w, unsigned int crtc_h,
217 uint32_t x, uint32_t y,
218 uint32_t src_w, uint32_t src_h)
219{
220 struct drm_device *dev = plane->dev;
221 struct drm_i915_private *dev_priv = dev->dev_private;
222 struct intel_plane *intel_plane = to_intel_plane(plane);
223 int pipe = intel_plane->pipe;
224 u32 sprctl, sprscale = 0;
Damien Lespiau5a35e992012-10-26 18:20:12 +0100225 unsigned long sprsurf_offset, linear_offset;
Ville Syrjälä2bd3c3c2012-10-31 17:50:20 +0200226 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
Ville Syrjälä2c6602d2013-02-08 23:13:35 +0200227 bool scaling_was_enabled = dev_priv->sprite_scaling_enabled;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800228
229 sprctl = I915_READ(SPRCTL(pipe));
230
231 /* Mask out pixel format bits in case we change it */
232 sprctl &= ~SPRITE_PIXFORMAT_MASK;
233 sprctl &= ~SPRITE_RGB_ORDER_RGBX;
234 sprctl &= ~SPRITE_YUV_BYTE_ORDER_MASK;
Jesse Barnese86fe0d2012-06-26 13:10:11 -0700235 sprctl &= ~SPRITE_TILED;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800236
237 switch (fb->pixel_format) {
238 case DRM_FORMAT_XBGR8888:
Vijay Purushothaman5ee36912012-08-23 12:08:57 +0530239 sprctl |= SPRITE_FORMAT_RGBX888 | SPRITE_RGB_ORDER_RGBX;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800240 break;
241 case DRM_FORMAT_XRGB8888:
Vijay Purushothaman5ee36912012-08-23 12:08:57 +0530242 sprctl |= SPRITE_FORMAT_RGBX888;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800243 break;
244 case DRM_FORMAT_YUYV:
245 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YUYV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800246 break;
247 case DRM_FORMAT_YVYU:
248 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YVYU;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800249 break;
250 case DRM_FORMAT_UYVY:
251 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_UYVY;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800252 break;
253 case DRM_FORMAT_VYUY:
254 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_VYUY;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800255 break;
256 default:
Ville Syrjälä28d491d2012-10-31 17:50:21 +0200257 BUG();
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800258 }
259
260 if (obj->tiling_mode != I915_TILING_NONE)
261 sprctl |= SPRITE_TILED;
262
263 /* must disable */
264 sprctl |= SPRITE_TRICKLE_FEED_DISABLE;
265 sprctl |= SPRITE_ENABLE;
266
Ville Syrjälä86d3efc2013-01-18 19:11:38 +0200267 if (IS_HASWELL(dev))
268 sprctl |= SPRITE_PIPE_CSC_ENABLE;
269
Ville Syrjäläadf3d352013-08-06 22:24:11 +0300270 intel_update_sprite_watermarks(plane, crtc, src_w, pixel_size, true,
Ville Syrjälä67ca28f2013-07-05 11:57:14 +0300271 src_w != crtc_w || src_h != crtc_h);
272
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800273 /* Sizes are 0 based */
274 src_w--;
275 src_h--;
276 crtc_w--;
277 crtc_h--;
278
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800279 /*
280 * IVB workaround: must disable low power watermarks for at least
281 * one frame before enabling scaling. LP watermarks can be re-enabled
282 * when scaling is disabled.
283 */
284 if (crtc_w != src_w || crtc_h != src_h) {
Ville Syrjälä2c6602d2013-02-08 23:13:35 +0200285 dev_priv->sprite_scaling_enabled |= 1 << pipe;
286
287 if (!scaling_was_enabled) {
Chris Wilson828ed3e2012-04-18 17:12:26 +0100288 intel_update_watermarks(dev);
289 intel_wait_for_vblank(dev, pipe);
290 }
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800291 sprscale = SPRITE_SCALE_ENABLE | (src_w << 16) | src_h;
Ville Syrjälä2c6602d2013-02-08 23:13:35 +0200292 } else
293 dev_priv->sprite_scaling_enabled &= ~(1 << pipe);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800294
295 I915_WRITE(SPRSTRIDE(pipe), fb->pitches[0]);
296 I915_WRITE(SPRPOS(pipe), (crtc_y << 16) | crtc_x);
Damien Lespiauc54173a2012-10-26 18:20:11 +0100297
Chris Wilsonca320ac2012-12-19 12:14:22 +0000298 linear_offset = y * fb->pitches[0] + x * pixel_size;
Damien Lespiau5a35e992012-10-26 18:20:12 +0100299 sprsurf_offset =
Chris Wilsonbc752862013-02-21 20:04:31 +0000300 intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
301 pixel_size, fb->pitches[0]);
Damien Lespiau5a35e992012-10-26 18:20:12 +0100302 linear_offset -= sprsurf_offset;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800303
Damien Lespiau5a35e992012-10-26 18:20:12 +0100304 /* HSW consolidates SPRTILEOFF and SPRLINOFF into a single SPROFFSET
305 * register */
306 if (IS_HASWELL(dev))
307 I915_WRITE(SPROFFSET(pipe), (y << 16) | x);
308 else if (obj->tiling_mode != I915_TILING_NONE)
309 I915_WRITE(SPRTILEOFF(pipe), (y << 16) | x);
310 else
311 I915_WRITE(SPRLINOFF(pipe), linear_offset);
Damien Lespiauc54173a2012-10-26 18:20:11 +0100312
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800313 I915_WRITE(SPRSIZE(pipe), (crtc_h << 16) | crtc_w);
Damien Lespiau2d354c32012-10-22 18:19:27 +0100314 if (intel_plane->can_scale)
315 I915_WRITE(SPRSCALE(pipe), sprscale);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800316 I915_WRITE(SPRCTL(pipe), sprctl);
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700317 I915_MODIFY_DISPBASE(SPRSURF(pipe),
318 i915_gem_obj_ggtt_offset(obj) + sprsurf_offset);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800319 POSTING_READ(SPRSURF(pipe));
Ville Syrjälä2c6602d2013-02-08 23:13:35 +0200320
321 /* potentially re-enable LP watermarks */
322 if (scaling_was_enabled && !dev_priv->sprite_scaling_enabled)
323 intel_update_watermarks(dev);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800324}
325
326static void
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300327ivb_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800328{
329 struct drm_device *dev = plane->dev;
330 struct drm_i915_private *dev_priv = dev->dev_private;
331 struct intel_plane *intel_plane = to_intel_plane(plane);
332 int pipe = intel_plane->pipe;
Ville Syrjälä2c6602d2013-02-08 23:13:35 +0200333 bool scaling_was_enabled = dev_priv->sprite_scaling_enabled;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800334
335 I915_WRITE(SPRCTL(pipe), I915_READ(SPRCTL(pipe)) & ~SPRITE_ENABLE);
336 /* Can't leave the scaler enabled... */
Damien Lespiau2d354c32012-10-22 18:19:27 +0100337 if (intel_plane->can_scale)
338 I915_WRITE(SPRSCALE(pipe), 0);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800339 /* Activate double buffered register update */
Armin Reese446f2542012-03-30 16:20:16 -0700340 I915_MODIFY_DISPBASE(SPRSURF(pipe), 0);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800341 POSTING_READ(SPRSURF(pipe));
Chris Wilson828ed3e2012-04-18 17:12:26 +0100342
Ville Syrjälä2c6602d2013-02-08 23:13:35 +0200343 dev_priv->sprite_scaling_enabled &= ~(1 << pipe);
344
Ville Syrjäläadf3d352013-08-06 22:24:11 +0300345 intel_update_sprite_watermarks(plane, crtc, 0, 0, false, false);
Paulo Zanoni4c4ff432013-05-24 11:59:17 -0300346
Ville Syrjälä2c6602d2013-02-08 23:13:35 +0200347 /* potentially re-enable LP watermarks */
348 if (scaling_was_enabled && !dev_priv->sprite_scaling_enabled)
349 intel_update_watermarks(dev);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800350}
351
Jesse Barnes8ea30862012-01-03 08:05:39 -0800352static int
353ivb_update_colorkey(struct drm_plane *plane,
354 struct drm_intel_sprite_colorkey *key)
355{
356 struct drm_device *dev = plane->dev;
357 struct drm_i915_private *dev_priv = dev->dev_private;
358 struct intel_plane *intel_plane;
359 u32 sprctl;
360 int ret = 0;
361
362 intel_plane = to_intel_plane(plane);
363
364 I915_WRITE(SPRKEYVAL(intel_plane->pipe), key->min_value);
365 I915_WRITE(SPRKEYMAX(intel_plane->pipe), key->max_value);
366 I915_WRITE(SPRKEYMSK(intel_plane->pipe), key->channel_mask);
367
368 sprctl = I915_READ(SPRCTL(intel_plane->pipe));
369 sprctl &= ~(SPRITE_SOURCE_KEY | SPRITE_DEST_KEY);
370 if (key->flags & I915_SET_COLORKEY_DESTINATION)
371 sprctl |= SPRITE_DEST_KEY;
372 else if (key->flags & I915_SET_COLORKEY_SOURCE)
373 sprctl |= SPRITE_SOURCE_KEY;
374 I915_WRITE(SPRCTL(intel_plane->pipe), sprctl);
375
376 POSTING_READ(SPRKEYMSK(intel_plane->pipe));
377
378 return ret;
379}
380
381static void
382ivb_get_colorkey(struct drm_plane *plane, struct drm_intel_sprite_colorkey *key)
383{
384 struct drm_device *dev = plane->dev;
385 struct drm_i915_private *dev_priv = dev->dev_private;
386 struct intel_plane *intel_plane;
387 u32 sprctl;
388
389 intel_plane = to_intel_plane(plane);
390
391 key->min_value = I915_READ(SPRKEYVAL(intel_plane->pipe));
392 key->max_value = I915_READ(SPRKEYMAX(intel_plane->pipe));
393 key->channel_mask = I915_READ(SPRKEYMSK(intel_plane->pipe));
394 key->flags = 0;
395
396 sprctl = I915_READ(SPRCTL(intel_plane->pipe));
397
398 if (sprctl & SPRITE_DEST_KEY)
399 key->flags = I915_SET_COLORKEY_DESTINATION;
400 else if (sprctl & SPRITE_SOURCE_KEY)
401 key->flags = I915_SET_COLORKEY_SOURCE;
402 else
403 key->flags = I915_SET_COLORKEY_NONE;
404}
405
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800406static void
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300407ilk_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
408 struct drm_framebuffer *fb,
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800409 struct drm_i915_gem_object *obj, int crtc_x, int crtc_y,
410 unsigned int crtc_w, unsigned int crtc_h,
411 uint32_t x, uint32_t y,
412 uint32_t src_w, uint32_t src_h)
413{
414 struct drm_device *dev = plane->dev;
415 struct drm_i915_private *dev_priv = dev->dev_private;
416 struct intel_plane *intel_plane = to_intel_plane(plane);
Ville Syrjälä2bd3c3c2012-10-31 17:50:20 +0200417 int pipe = intel_plane->pipe;
Damien Lespiau5a35e992012-10-26 18:20:12 +0100418 unsigned long dvssurf_offset, linear_offset;
Chris Wilson8aaa81a2012-04-14 22:14:26 +0100419 u32 dvscntr, dvsscale;
Ville Syrjälä2bd3c3c2012-10-31 17:50:20 +0200420 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800421
422 dvscntr = I915_READ(DVSCNTR(pipe));
423
424 /* Mask out pixel format bits in case we change it */
425 dvscntr &= ~DVS_PIXFORMAT_MASK;
Jesse Barnesab2f9df2012-02-27 12:40:10 -0800426 dvscntr &= ~DVS_RGB_ORDER_XBGR;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800427 dvscntr &= ~DVS_YUV_BYTE_ORDER_MASK;
Ander Conselvan de Oliveira79626522012-07-13 15:50:33 +0300428 dvscntr &= ~DVS_TILED;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800429
430 switch (fb->pixel_format) {
431 case DRM_FORMAT_XBGR8888:
Jesse Barnesab2f9df2012-02-27 12:40:10 -0800432 dvscntr |= DVS_FORMAT_RGBX888 | DVS_RGB_ORDER_XBGR;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800433 break;
434 case DRM_FORMAT_XRGB8888:
Jesse Barnesab2f9df2012-02-27 12:40:10 -0800435 dvscntr |= DVS_FORMAT_RGBX888;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800436 break;
437 case DRM_FORMAT_YUYV:
438 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YUYV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800439 break;
440 case DRM_FORMAT_YVYU:
441 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YVYU;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800442 break;
443 case DRM_FORMAT_UYVY:
444 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_UYVY;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800445 break;
446 case DRM_FORMAT_VYUY:
447 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_VYUY;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800448 break;
449 default:
Ville Syrjälä28d491d2012-10-31 17:50:21 +0200450 BUG();
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800451 }
452
453 if (obj->tiling_mode != I915_TILING_NONE)
454 dvscntr |= DVS_TILED;
455
Chris Wilsond1686ae2012-04-10 11:41:49 +0100456 if (IS_GEN6(dev))
457 dvscntr |= DVS_TRICKLE_FEED_DISABLE; /* must disable */
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800458 dvscntr |= DVS_ENABLE;
459
Ville Syrjäläadf3d352013-08-06 22:24:11 +0300460 intel_update_sprite_watermarks(plane, crtc, src_w, pixel_size, true,
Ville Syrjälä67ca28f2013-07-05 11:57:14 +0300461 src_w != crtc_w || src_h != crtc_h);
462
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800463 /* Sizes are 0 based */
464 src_w--;
465 src_h--;
466 crtc_w--;
467 crtc_h--;
468
Chris Wilson8aaa81a2012-04-14 22:14:26 +0100469 dvsscale = 0;
470 if (IS_GEN5(dev) || crtc_w != src_w || crtc_h != src_h)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800471 dvsscale = DVS_SCALE_ENABLE | (src_w << 16) | src_h;
472
473 I915_WRITE(DVSSTRIDE(pipe), fb->pitches[0]);
474 I915_WRITE(DVSPOS(pipe), (crtc_y << 16) | crtc_x);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800475
Chris Wilsonca320ac2012-12-19 12:14:22 +0000476 linear_offset = y * fb->pitches[0] + x * pixel_size;
Damien Lespiau5a35e992012-10-26 18:20:12 +0100477 dvssurf_offset =
Chris Wilsonbc752862013-02-21 20:04:31 +0000478 intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
479 pixel_size, fb->pitches[0]);
Damien Lespiau5a35e992012-10-26 18:20:12 +0100480 linear_offset -= dvssurf_offset;
481
482 if (obj->tiling_mode != I915_TILING_NONE)
483 I915_WRITE(DVSTILEOFF(pipe), (y << 16) | x);
484 else
485 I915_WRITE(DVSLINOFF(pipe), linear_offset);
486
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800487 I915_WRITE(DVSSIZE(pipe), (crtc_h << 16) | crtc_w);
488 I915_WRITE(DVSSCALE(pipe), dvsscale);
489 I915_WRITE(DVSCNTR(pipe), dvscntr);
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700490 I915_MODIFY_DISPBASE(DVSSURF(pipe),
491 i915_gem_obj_ggtt_offset(obj) + dvssurf_offset);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800492 POSTING_READ(DVSSURF(pipe));
493}
494
495static void
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300496ilk_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800497{
498 struct drm_device *dev = plane->dev;
499 struct drm_i915_private *dev_priv = dev->dev_private;
500 struct intel_plane *intel_plane = to_intel_plane(plane);
501 int pipe = intel_plane->pipe;
502
503 I915_WRITE(DVSCNTR(pipe), I915_READ(DVSCNTR(pipe)) & ~DVS_ENABLE);
504 /* Disable the scaler */
505 I915_WRITE(DVSSCALE(pipe), 0);
506 /* Flush double buffered register updates */
Armin Reese446f2542012-03-30 16:20:16 -0700507 I915_MODIFY_DISPBASE(DVSSURF(pipe), 0);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800508 POSTING_READ(DVSSURF(pipe));
Ville Syrjäläa95fd8c2013-08-06 22:24:12 +0300509
510 intel_update_sprite_watermarks(plane, crtc, 0, 0, false, false);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800511}
512
Jesse Barnes175bd422011-12-13 13:19:39 -0800513static void
514intel_enable_primary(struct drm_crtc *crtc)
515{
516 struct drm_device *dev = crtc->dev;
517 struct drm_i915_private *dev_priv = dev->dev_private;
518 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
519 int reg = DSPCNTR(intel_crtc->plane);
520
Chris Wilson93314b52012-06-13 17:36:55 +0100521 if (!intel_crtc->primary_disabled)
522 return;
523
524 intel_crtc->primary_disabled = false;
525 intel_update_fbc(dev);
526
Jesse Barnes175bd422011-12-13 13:19:39 -0800527 I915_WRITE(reg, I915_READ(reg) | DISPLAY_PLANE_ENABLE);
528}
529
530static void
531intel_disable_primary(struct drm_crtc *crtc)
532{
533 struct drm_device *dev = crtc->dev;
534 struct drm_i915_private *dev_priv = dev->dev_private;
535 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
536 int reg = DSPCNTR(intel_crtc->plane);
537
Chris Wilson93314b52012-06-13 17:36:55 +0100538 if (intel_crtc->primary_disabled)
539 return;
540
Jesse Barnes175bd422011-12-13 13:19:39 -0800541 I915_WRITE(reg, I915_READ(reg) & ~DISPLAY_PLANE_ENABLE);
Chris Wilson93314b52012-06-13 17:36:55 +0100542
543 intel_crtc->primary_disabled = true;
544 intel_update_fbc(dev);
Jesse Barnes175bd422011-12-13 13:19:39 -0800545}
546
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800547static int
Chris Wilsond1686ae2012-04-10 11:41:49 +0100548ilk_update_colorkey(struct drm_plane *plane,
Jesse Barnes8ea30862012-01-03 08:05:39 -0800549 struct drm_intel_sprite_colorkey *key)
550{
551 struct drm_device *dev = plane->dev;
552 struct drm_i915_private *dev_priv = dev->dev_private;
553 struct intel_plane *intel_plane;
554 u32 dvscntr;
555 int ret = 0;
556
557 intel_plane = to_intel_plane(plane);
558
559 I915_WRITE(DVSKEYVAL(intel_plane->pipe), key->min_value);
560 I915_WRITE(DVSKEYMAX(intel_plane->pipe), key->max_value);
561 I915_WRITE(DVSKEYMSK(intel_plane->pipe), key->channel_mask);
562
563 dvscntr = I915_READ(DVSCNTR(intel_plane->pipe));
564 dvscntr &= ~(DVS_SOURCE_KEY | DVS_DEST_KEY);
565 if (key->flags & I915_SET_COLORKEY_DESTINATION)
566 dvscntr |= DVS_DEST_KEY;
567 else if (key->flags & I915_SET_COLORKEY_SOURCE)
568 dvscntr |= DVS_SOURCE_KEY;
569 I915_WRITE(DVSCNTR(intel_plane->pipe), dvscntr);
570
571 POSTING_READ(DVSKEYMSK(intel_plane->pipe));
572
573 return ret;
574}
575
576static void
Chris Wilsond1686ae2012-04-10 11:41:49 +0100577ilk_get_colorkey(struct drm_plane *plane, struct drm_intel_sprite_colorkey *key)
Jesse Barnes8ea30862012-01-03 08:05:39 -0800578{
579 struct drm_device *dev = plane->dev;
580 struct drm_i915_private *dev_priv = dev->dev_private;
581 struct intel_plane *intel_plane;
582 u32 dvscntr;
583
584 intel_plane = to_intel_plane(plane);
585
586 key->min_value = I915_READ(DVSKEYVAL(intel_plane->pipe));
587 key->max_value = I915_READ(DVSKEYMAX(intel_plane->pipe));
588 key->channel_mask = I915_READ(DVSKEYMSK(intel_plane->pipe));
589 key->flags = 0;
590
591 dvscntr = I915_READ(DVSCNTR(intel_plane->pipe));
592
593 if (dvscntr & DVS_DEST_KEY)
594 key->flags = I915_SET_COLORKEY_DESTINATION;
595 else if (dvscntr & DVS_SOURCE_KEY)
596 key->flags = I915_SET_COLORKEY_SOURCE;
597 else
598 key->flags = I915_SET_COLORKEY_NONE;
599}
600
Ville Syrjälä17316932013-04-24 18:52:38 +0300601static bool
602format_is_yuv(uint32_t format)
603{
604 switch (format) {
605 case DRM_FORMAT_YUYV:
606 case DRM_FORMAT_UYVY:
607 case DRM_FORMAT_VYUY:
608 case DRM_FORMAT_YVYU:
609 return true;
610 default:
611 return false;
612 }
613}
614
Jesse Barnes8ea30862012-01-03 08:05:39 -0800615static int
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800616intel_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
617 struct drm_framebuffer *fb, int crtc_x, int crtc_y,
618 unsigned int crtc_w, unsigned int crtc_h,
619 uint32_t src_x, uint32_t src_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_crtc *intel_crtc = to_intel_crtc(crtc);
625 struct intel_plane *intel_plane = to_intel_plane(plane);
626 struct intel_framebuffer *intel_fb;
627 struct drm_i915_gem_object *obj, *old_obj;
628 int pipe = intel_plane->pipe;
Paulo Zanoni702e7a52012-10-23 18:29:59 -0200629 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
630 pipe);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800631 int ret = 0;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800632 bool disable_primary = false;
Ville Syrjälä17316932013-04-24 18:52:38 +0300633 bool visible;
634 int hscale, vscale;
635 int max_scale, min_scale;
636 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
637 struct drm_rect src = {
638 /* sample coordinates in 16.16 fixed point */
639 .x1 = src_x,
640 .x2 = src_x + src_w,
641 .y1 = src_y,
642 .y2 = src_y + src_h,
643 };
644 struct drm_rect dst = {
645 /* integer pixels */
646 .x1 = crtc_x,
647 .x2 = crtc_x + crtc_w,
648 .y1 = crtc_y,
649 .y2 = crtc_y + crtc_h,
650 };
651 const struct drm_rect clip = {
652 .x2 = crtc->mode.hdisplay,
653 .y2 = crtc->mode.vdisplay,
654 };
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800655
656 intel_fb = to_intel_framebuffer(fb);
657 obj = intel_fb->obj;
658
659 old_obj = intel_plane->obj;
660
Jesse Barnes5e1bac22013-03-26 09:25:43 -0700661 intel_plane->crtc_x = crtc_x;
662 intel_plane->crtc_y = crtc_y;
663 intel_plane->crtc_w = crtc_w;
664 intel_plane->crtc_h = crtc_h;
665 intel_plane->src_x = src_x;
666 intel_plane->src_y = src_y;
667 intel_plane->src_w = src_w;
668 intel_plane->src_h = src_h;
669
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800670 /* Pipe must be running... */
Ville Syrjälä17316932013-04-24 18:52:38 +0300671 if (!(I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_ENABLE)) {
672 DRM_DEBUG_KMS("Pipe disabled\n");
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800673 return -EINVAL;
Ville Syrjälä17316932013-04-24 18:52:38 +0300674 }
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800675
676 /* Don't modify another pipe's plane */
Ville Syrjälä17316932013-04-24 18:52:38 +0300677 if (intel_plane->pipe != intel_crtc->pipe) {
678 DRM_DEBUG_KMS("Wrong plane <-> crtc mapping\n");
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800679 return -EINVAL;
Ville Syrjälä17316932013-04-24 18:52:38 +0300680 }
681
682 /* FIXME check all gen limits */
683 if (fb->width < 3 || fb->height < 3 || fb->pitches[0] > 16384) {
684 DRM_DEBUG_KMS("Unsuitable framebuffer for plane\n");
685 return -EINVAL;
686 }
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800687
Damien Lespiau94c64192012-10-29 15:14:51 +0000688 /* Sprite planes can be linear or x-tiled surfaces */
689 switch (obj->tiling_mode) {
690 case I915_TILING_NONE:
691 case I915_TILING_X:
692 break;
693 default:
Ville Syrjälä17316932013-04-24 18:52:38 +0300694 DRM_DEBUG_KMS("Unsupported tiling mode\n");
Damien Lespiau94c64192012-10-29 15:14:51 +0000695 return -EINVAL;
696 }
697
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300698 /*
699 * FIXME the following code does a bunch of fuzzy adjustments to the
700 * coordinates and sizes. We probably need some way to decide whether
701 * more strict checking should be done instead.
702 */
Ville Syrjälä17316932013-04-24 18:52:38 +0300703 max_scale = intel_plane->max_downscale << 16;
704 min_scale = intel_plane->can_scale ? 1 : (1 << 16);
705
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300706 hscale = drm_rect_calc_hscale_relaxed(&src, &dst, min_scale, max_scale);
707 BUG_ON(hscale < 0);
Ville Syrjälä17316932013-04-24 18:52:38 +0300708
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300709 vscale = drm_rect_calc_vscale_relaxed(&src, &dst, min_scale, max_scale);
710 BUG_ON(vscale < 0);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800711
Ville Syrjälä17316932013-04-24 18:52:38 +0300712 visible = drm_rect_clip_scaled(&src, &dst, &clip, hscale, vscale);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800713
Ville Syrjälä17316932013-04-24 18:52:38 +0300714 crtc_x = dst.x1;
715 crtc_y = dst.y1;
716 crtc_w = drm_rect_width(&dst);
717 crtc_h = drm_rect_height(&dst);
Damien Lespiau2d354c32012-10-22 18:19:27 +0100718
Ville Syrjälä17316932013-04-24 18:52:38 +0300719 if (visible) {
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300720 /* check again in case clipping clamped the results */
721 hscale = drm_rect_calc_hscale(&src, &dst, min_scale, max_scale);
722 if (hscale < 0) {
723 DRM_DEBUG_KMS("Horizontal scaling factor out of limits\n");
724 drm_rect_debug_print(&src, true);
725 drm_rect_debug_print(&dst, false);
726
727 return hscale;
728 }
729
730 vscale = drm_rect_calc_vscale(&src, &dst, min_scale, max_scale);
731 if (vscale < 0) {
732 DRM_DEBUG_KMS("Vertical scaling factor out of limits\n");
733 drm_rect_debug_print(&src, true);
734 drm_rect_debug_print(&dst, false);
735
736 return vscale;
737 }
738
Ville Syrjälä17316932013-04-24 18:52:38 +0300739 /* Make the source viewport size an exact multiple of the scaling factors. */
740 drm_rect_adjust_size(&src,
741 drm_rect_width(&dst) * hscale - drm_rect_width(&src),
742 drm_rect_height(&dst) * vscale - drm_rect_height(&src));
743
744 /* sanity check to make sure the src viewport wasn't enlarged */
745 WARN_ON(src.x1 < (int) src_x ||
746 src.y1 < (int) src_y ||
747 src.x2 > (int) (src_x + src_w) ||
748 src.y2 > (int) (src_y + src_h));
749
750 /*
751 * Hardware doesn't handle subpixel coordinates.
752 * Adjust to (macro)pixel boundary, but be careful not to
753 * increase the source viewport size, because that could
754 * push the downscaling factor out of bounds.
Ville Syrjälä17316932013-04-24 18:52:38 +0300755 */
756 src_x = src.x1 >> 16;
757 src_w = drm_rect_width(&src) >> 16;
758 src_y = src.y1 >> 16;
759 src_h = drm_rect_height(&src) >> 16;
760
761 if (format_is_yuv(fb->pixel_format)) {
762 src_x &= ~1;
763 src_w &= ~1;
764
765 /*
766 * Must keep src and dst the
767 * same if we can't scale.
768 */
769 if (!intel_plane->can_scale)
770 crtc_w &= ~1;
771
772 if (crtc_w == 0)
773 visible = false;
774 }
775 }
776
777 /* Check size restrictions when scaling */
778 if (visible && (src_w != crtc_w || src_h != crtc_h)) {
779 unsigned int width_bytes;
780
781 WARN_ON(!intel_plane->can_scale);
782
783 /* FIXME interlacing min height is 6 */
784
785 if (crtc_w < 3 || crtc_h < 3)
786 visible = false;
787
788 if (src_w < 3 || src_h < 3)
789 visible = false;
790
791 width_bytes = ((src_x * pixel_size) & 63) + src_w * pixel_size;
792
793 if (src_w > 2048 || src_h > 2048 ||
794 width_bytes > 4096 || fb->pitches[0] > 4096) {
795 DRM_DEBUG_KMS("Source dimensions exceed hardware limits\n");
796 return -EINVAL;
797 }
798 }
799
800 dst.x1 = crtc_x;
801 dst.x2 = crtc_x + crtc_w;
802 dst.y1 = crtc_y;
803 dst.y2 = crtc_y + crtc_h;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800804
805 /*
806 * If the sprite is completely covering the primary plane,
807 * we can disable the primary and save power.
808 */
Ville Syrjälä17316932013-04-24 18:52:38 +0300809 disable_primary = drm_rect_equals(&dst, &clip);
810 WARN_ON(disable_primary && !visible);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800811
812 mutex_lock(&dev->struct_mutex);
813
Chris Wilson693db182013-03-05 14:52:39 +0000814 /* Note that this will apply the VT-d workaround for scanouts,
815 * which is more restrictive than required for sprites. (The
816 * primary plane requires 256KiB alignment with 64 PTE padding,
817 * the sprite planes only require 128KiB alignment and 32 PTE padding.
818 */
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800819 ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
Jesse Barnes00c2064b2012-01-13 15:48:39 -0800820 if (ret)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800821 goto out_unlock;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800822
823 intel_plane->obj = obj;
824
Jesse Barnes175bd422011-12-13 13:19:39 -0800825 /*
826 * Be sure to re-enable the primary before the sprite is no longer
827 * covering it fully.
828 */
Chris Wilson93314b52012-06-13 17:36:55 +0100829 if (!disable_primary)
Jesse Barnes175bd422011-12-13 13:19:39 -0800830 intel_enable_primary(crtc);
Jesse Barnes175bd422011-12-13 13:19:39 -0800831
Ville Syrjälä17316932013-04-24 18:52:38 +0300832 if (visible)
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300833 intel_plane->update_plane(plane, crtc, fb, obj,
Ville Syrjälä17316932013-04-24 18:52:38 +0300834 crtc_x, crtc_y, crtc_w, crtc_h,
835 src_x, src_y, src_w, src_h);
836 else
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300837 intel_plane->disable_plane(plane, crtc);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800838
Chris Wilson93314b52012-06-13 17:36:55 +0100839 if (disable_primary)
Jesse Barnes175bd422011-12-13 13:19:39 -0800840 intel_disable_primary(crtc);
Jesse Barnes175bd422011-12-13 13:19:39 -0800841
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800842 /* Unpin old obj after new one is active to avoid ugliness */
843 if (old_obj) {
844 /*
845 * It's fairly common to simply update the position of
846 * an existing object. In that case, we don't need to
847 * wait for vblank to avoid ugliness, we only need to
848 * do the pin & ref bookkeeping.
849 */
850 if (old_obj != obj) {
851 mutex_unlock(&dev->struct_mutex);
852 intel_wait_for_vblank(dev, to_intel_crtc(crtc)->pipe);
853 mutex_lock(&dev->struct_mutex);
854 }
Chris Wilson1690e1e2011-12-14 13:57:08 +0100855 intel_unpin_fb_obj(old_obj);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800856 }
857
858out_unlock:
859 mutex_unlock(&dev->struct_mutex);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800860 return ret;
861}
862
863static int
864intel_disable_plane(struct drm_plane *plane)
865{
866 struct drm_device *dev = plane->dev;
867 struct intel_plane *intel_plane = to_intel_plane(plane);
868 int ret = 0;
869
Ville Syrjälä88a94a52013-08-07 13:30:23 +0300870 if (!plane->fb)
871 return 0;
872
873 if (WARN_ON(!plane->crtc))
874 return -EINVAL;
875
876 intel_enable_primary(plane->crtc);
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300877 intel_plane->disable_plane(plane, plane->crtc);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800878
879 if (!intel_plane->obj)
880 goto out;
881
Ville Syrjäläc626d312013-03-27 17:49:13 +0200882 intel_wait_for_vblank(dev, intel_plane->pipe);
883
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800884 mutex_lock(&dev->struct_mutex);
Chris Wilson1690e1e2011-12-14 13:57:08 +0100885 intel_unpin_fb_obj(intel_plane->obj);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800886 intel_plane->obj = NULL;
887 mutex_unlock(&dev->struct_mutex);
888out:
889
890 return ret;
891}
892
893static void intel_destroy_plane(struct drm_plane *plane)
894{
895 struct intel_plane *intel_plane = to_intel_plane(plane);
896 intel_disable_plane(plane);
897 drm_plane_cleanup(plane);
898 kfree(intel_plane);
899}
900
Jesse Barnes8ea30862012-01-03 08:05:39 -0800901int intel_sprite_set_colorkey(struct drm_device *dev, void *data,
902 struct drm_file *file_priv)
903{
904 struct drm_intel_sprite_colorkey *set = data;
Jesse Barnes8ea30862012-01-03 08:05:39 -0800905 struct drm_mode_object *obj;
906 struct drm_plane *plane;
907 struct intel_plane *intel_plane;
908 int ret = 0;
909
Daniel Vetter1cff8f62012-04-24 09:55:08 +0200910 if (!drm_core_check_feature(dev, DRIVER_MODESET))
911 return -ENODEV;
Jesse Barnes8ea30862012-01-03 08:05:39 -0800912
913 /* Make sure we don't try to enable both src & dest simultaneously */
914 if ((set->flags & (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE)) == (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE))
915 return -EINVAL;
916
Daniel Vettera0e99e62012-12-02 01:05:46 +0100917 drm_modeset_lock_all(dev);
Jesse Barnes8ea30862012-01-03 08:05:39 -0800918
919 obj = drm_mode_object_find(dev, set->plane_id, DRM_MODE_OBJECT_PLANE);
920 if (!obj) {
921 ret = -EINVAL;
922 goto out_unlock;
923 }
924
925 plane = obj_to_plane(obj);
926 intel_plane = to_intel_plane(plane);
927 ret = intel_plane->update_colorkey(plane, set);
928
929out_unlock:
Daniel Vettera0e99e62012-12-02 01:05:46 +0100930 drm_modeset_unlock_all(dev);
Jesse Barnes8ea30862012-01-03 08:05:39 -0800931 return ret;
932}
933
934int intel_sprite_get_colorkey(struct drm_device *dev, void *data,
935 struct drm_file *file_priv)
936{
937 struct drm_intel_sprite_colorkey *get = data;
Jesse Barnes8ea30862012-01-03 08:05:39 -0800938 struct drm_mode_object *obj;
939 struct drm_plane *plane;
940 struct intel_plane *intel_plane;
941 int ret = 0;
942
Daniel Vetter1cff8f62012-04-24 09:55:08 +0200943 if (!drm_core_check_feature(dev, DRIVER_MODESET))
944 return -ENODEV;
Jesse Barnes8ea30862012-01-03 08:05:39 -0800945
Daniel Vettera0e99e62012-12-02 01:05:46 +0100946 drm_modeset_lock_all(dev);
Jesse Barnes8ea30862012-01-03 08:05:39 -0800947
948 obj = drm_mode_object_find(dev, get->plane_id, DRM_MODE_OBJECT_PLANE);
949 if (!obj) {
950 ret = -EINVAL;
951 goto out_unlock;
952 }
953
954 plane = obj_to_plane(obj);
955 intel_plane = to_intel_plane(plane);
956 intel_plane->get_colorkey(plane, get);
957
958out_unlock:
Daniel Vettera0e99e62012-12-02 01:05:46 +0100959 drm_modeset_unlock_all(dev);
Jesse Barnes8ea30862012-01-03 08:05:39 -0800960 return ret;
961}
962
Jesse Barnes5e1bac22013-03-26 09:25:43 -0700963void intel_plane_restore(struct drm_plane *plane)
964{
965 struct intel_plane *intel_plane = to_intel_plane(plane);
966
967 if (!plane->crtc || !plane->fb)
968 return;
969
970 intel_update_plane(plane, plane->crtc, plane->fb,
971 intel_plane->crtc_x, intel_plane->crtc_y,
972 intel_plane->crtc_w, intel_plane->crtc_h,
973 intel_plane->src_x, intel_plane->src_y,
974 intel_plane->src_w, intel_plane->src_h);
975}
976
Ville Syrjäläbb53d4a2013-06-04 13:49:04 +0300977void intel_plane_disable(struct drm_plane *plane)
978{
979 if (!plane->crtc || !plane->fb)
980 return;
981
982 intel_disable_plane(plane);
983}
984
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800985static const struct drm_plane_funcs intel_plane_funcs = {
986 .update_plane = intel_update_plane,
987 .disable_plane = intel_disable_plane,
988 .destroy = intel_destroy_plane,
989};
990
Chris Wilsond1686ae2012-04-10 11:41:49 +0100991static uint32_t ilk_plane_formats[] = {
992 DRM_FORMAT_XRGB8888,
993 DRM_FORMAT_YUYV,
994 DRM_FORMAT_YVYU,
995 DRM_FORMAT_UYVY,
996 DRM_FORMAT_VYUY,
997};
998
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800999static uint32_t snb_plane_formats[] = {
1000 DRM_FORMAT_XBGR8888,
1001 DRM_FORMAT_XRGB8888,
1002 DRM_FORMAT_YUYV,
1003 DRM_FORMAT_YVYU,
1004 DRM_FORMAT_UYVY,
1005 DRM_FORMAT_VYUY,
1006};
1007
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001008static uint32_t vlv_plane_formats[] = {
1009 DRM_FORMAT_RGB565,
1010 DRM_FORMAT_ABGR8888,
1011 DRM_FORMAT_ARGB8888,
1012 DRM_FORMAT_XBGR8888,
1013 DRM_FORMAT_XRGB8888,
1014 DRM_FORMAT_XBGR2101010,
1015 DRM_FORMAT_ABGR2101010,
1016 DRM_FORMAT_YUYV,
1017 DRM_FORMAT_YVYU,
1018 DRM_FORMAT_UYVY,
1019 DRM_FORMAT_VYUY,
1020};
1021
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001022int
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001023intel_plane_init(struct drm_device *dev, enum pipe pipe, int plane)
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001024{
1025 struct intel_plane *intel_plane;
1026 unsigned long possible_crtcs;
Chris Wilsond1686ae2012-04-10 11:41:49 +01001027 const uint32_t *plane_formats;
1028 int num_plane_formats;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001029 int ret;
1030
Chris Wilsond1686ae2012-04-10 11:41:49 +01001031 if (INTEL_INFO(dev)->gen < 5)
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001032 return -ENODEV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001033
1034 intel_plane = kzalloc(sizeof(struct intel_plane), GFP_KERNEL);
1035 if (!intel_plane)
1036 return -ENOMEM;
1037
Chris Wilsond1686ae2012-04-10 11:41:49 +01001038 switch (INTEL_INFO(dev)->gen) {
1039 case 5:
1040 case 6:
Damien Lespiau2d354c32012-10-22 18:19:27 +01001041 intel_plane->can_scale = true;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001042 intel_plane->max_downscale = 16;
Chris Wilsond1686ae2012-04-10 11:41:49 +01001043 intel_plane->update_plane = ilk_update_plane;
1044 intel_plane->disable_plane = ilk_disable_plane;
1045 intel_plane->update_colorkey = ilk_update_colorkey;
1046 intel_plane->get_colorkey = ilk_get_colorkey;
1047
1048 if (IS_GEN6(dev)) {
1049 plane_formats = snb_plane_formats;
1050 num_plane_formats = ARRAY_SIZE(snb_plane_formats);
1051 } else {
1052 plane_formats = ilk_plane_formats;
1053 num_plane_formats = ARRAY_SIZE(ilk_plane_formats);
1054 }
1055 break;
1056
1057 case 7:
Damien Lespiaud49f7092013-04-25 15:15:00 +01001058 if (IS_IVYBRIDGE(dev)) {
Damien Lespiau2d354c32012-10-22 18:19:27 +01001059 intel_plane->can_scale = true;
Damien Lespiaud49f7092013-04-25 15:15:00 +01001060 intel_plane->max_downscale = 2;
1061 } else {
1062 intel_plane->can_scale = false;
1063 intel_plane->max_downscale = 1;
1064 }
Chris Wilsond1686ae2012-04-10 11:41:49 +01001065
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001066 if (IS_VALLEYVIEW(dev)) {
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001067 intel_plane->update_plane = vlv_update_plane;
1068 intel_plane->disable_plane = vlv_disable_plane;
1069 intel_plane->update_colorkey = vlv_update_colorkey;
1070 intel_plane->get_colorkey = vlv_get_colorkey;
1071
1072 plane_formats = vlv_plane_formats;
1073 num_plane_formats = ARRAY_SIZE(vlv_plane_formats);
1074 } else {
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001075 intel_plane->update_plane = ivb_update_plane;
1076 intel_plane->disable_plane = ivb_disable_plane;
1077 intel_plane->update_colorkey = ivb_update_colorkey;
1078 intel_plane->get_colorkey = ivb_get_colorkey;
1079
1080 plane_formats = snb_plane_formats;
1081 num_plane_formats = ARRAY_SIZE(snb_plane_formats);
1082 }
Chris Wilsond1686ae2012-04-10 11:41:49 +01001083 break;
1084
1085 default:
Jesper Juhla8b0bba2012-06-27 00:55:37 +02001086 kfree(intel_plane);
Chris Wilsond1686ae2012-04-10 11:41:49 +01001087 return -ENODEV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001088 }
1089
1090 intel_plane->pipe = pipe;
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001091 intel_plane->plane = plane;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001092 possible_crtcs = (1 << pipe);
1093 ret = drm_plane_init(dev, &intel_plane->base, possible_crtcs,
Chris Wilsond1686ae2012-04-10 11:41:49 +01001094 &intel_plane_funcs,
1095 plane_formats, num_plane_formats,
1096 false);
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001097 if (ret)
1098 kfree(intel_plane);
1099
1100 return ret;
1101}