blob: 19b9cb961b5a19ef401434bda5dd1b548ee53deb [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
117 intel_update_sprite_watermarks(dev, pipe, crtc_w, pixel_size);
118
119 I915_WRITE(SPSTRIDE(pipe, plane), fb->pitches[0]);
120 I915_WRITE(SPPOS(pipe, plane), (crtc_y << 16) | crtc_x);
121
122 linear_offset = y * fb->pitches[0] + x * pixel_size;
123 sprsurf_offset = intel_gen4_compute_page_offset(&x, &y,
124 obj->tiling_mode,
125 pixel_size,
126 fb->pitches[0]);
127 linear_offset -= sprsurf_offset;
128
129 if (obj->tiling_mode != I915_TILING_NONE)
130 I915_WRITE(SPTILEOFF(pipe, plane), (y << 16) | x);
131 else
132 I915_WRITE(SPLINOFF(pipe, plane), linear_offset);
133
134 I915_WRITE(SPSIZE(pipe, plane), (crtc_h << 16) | crtc_w);
135 I915_WRITE(SPCNTR(pipe, plane), sprctl);
136 I915_MODIFY_DISPBASE(SPSURF(pipe, plane), obj->gtt_offset +
137 sprsurf_offset);
138 POSTING_READ(SPSURF(pipe, plane));
139}
140
141static void
142vlv_disable_plane(struct drm_plane *dplane)
143{
144 struct drm_device *dev = dplane->dev;
145 struct drm_i915_private *dev_priv = dev->dev_private;
146 struct intel_plane *intel_plane = to_intel_plane(dplane);
147 int pipe = intel_plane->pipe;
148 int plane = intel_plane->plane;
149
150 I915_WRITE(SPCNTR(pipe, plane), I915_READ(SPCNTR(pipe, plane)) &
151 ~SP_ENABLE);
152 /* Activate double buffered register update */
153 I915_MODIFY_DISPBASE(SPSURF(pipe, plane), 0);
154 POSTING_READ(SPSURF(pipe, plane));
155}
156
157static int
158vlv_update_colorkey(struct drm_plane *dplane,
159 struct drm_intel_sprite_colorkey *key)
160{
161 struct drm_device *dev = dplane->dev;
162 struct drm_i915_private *dev_priv = dev->dev_private;
163 struct intel_plane *intel_plane = to_intel_plane(dplane);
164 int pipe = intel_plane->pipe;
165 int plane = intel_plane->plane;
166 u32 sprctl;
167
168 if (key->flags & I915_SET_COLORKEY_DESTINATION)
169 return -EINVAL;
170
171 I915_WRITE(SPKEYMINVAL(pipe, plane), key->min_value);
172 I915_WRITE(SPKEYMAXVAL(pipe, plane), key->max_value);
173 I915_WRITE(SPKEYMSK(pipe, plane), key->channel_mask);
174
175 sprctl = I915_READ(SPCNTR(pipe, plane));
176 sprctl &= ~SP_SOURCE_KEY;
177 if (key->flags & I915_SET_COLORKEY_SOURCE)
178 sprctl |= SP_SOURCE_KEY;
179 I915_WRITE(SPCNTR(pipe, plane), sprctl);
180
181 POSTING_READ(SPKEYMSK(pipe, plane));
182
183 return 0;
184}
185
186static void
187vlv_get_colorkey(struct drm_plane *dplane,
188 struct drm_intel_sprite_colorkey *key)
189{
190 struct drm_device *dev = dplane->dev;
191 struct drm_i915_private *dev_priv = dev->dev_private;
192 struct intel_plane *intel_plane = to_intel_plane(dplane);
193 int pipe = intel_plane->pipe;
194 int plane = intel_plane->plane;
195 u32 sprctl;
196
197 key->min_value = I915_READ(SPKEYMINVAL(pipe, plane));
198 key->max_value = I915_READ(SPKEYMAXVAL(pipe, plane));
199 key->channel_mask = I915_READ(SPKEYMSK(pipe, plane));
200
201 sprctl = I915_READ(SPCNTR(pipe, plane));
202 if (sprctl & SP_SOURCE_KEY)
203 key->flags = I915_SET_COLORKEY_SOURCE;
204 else
205 key->flags = I915_SET_COLORKEY_NONE;
206}
207
208static void
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800209ivb_update_plane(struct drm_plane *plane, struct drm_framebuffer *fb,
210 struct drm_i915_gem_object *obj, int crtc_x, int crtc_y,
211 unsigned int crtc_w, unsigned int crtc_h,
212 uint32_t x, uint32_t y,
213 uint32_t src_w, uint32_t src_h)
214{
215 struct drm_device *dev = plane->dev;
216 struct drm_i915_private *dev_priv = dev->dev_private;
217 struct intel_plane *intel_plane = to_intel_plane(plane);
218 int pipe = intel_plane->pipe;
219 u32 sprctl, sprscale = 0;
Damien Lespiau5a35e992012-10-26 18:20:12 +0100220 unsigned long sprsurf_offset, linear_offset;
Ville Syrjälä2bd3c3c2012-10-31 17:50:20 +0200221 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
Ville Syrjälä2c6602d2013-02-08 23:13:35 +0200222 bool scaling_was_enabled = dev_priv->sprite_scaling_enabled;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800223
224 sprctl = I915_READ(SPRCTL(pipe));
225
226 /* Mask out pixel format bits in case we change it */
227 sprctl &= ~SPRITE_PIXFORMAT_MASK;
228 sprctl &= ~SPRITE_RGB_ORDER_RGBX;
229 sprctl &= ~SPRITE_YUV_BYTE_ORDER_MASK;
Jesse Barnese86fe0d2012-06-26 13:10:11 -0700230 sprctl &= ~SPRITE_TILED;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800231
232 switch (fb->pixel_format) {
233 case DRM_FORMAT_XBGR8888:
Vijay Purushothaman5ee36912012-08-23 12:08:57 +0530234 sprctl |= SPRITE_FORMAT_RGBX888 | SPRITE_RGB_ORDER_RGBX;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800235 break;
236 case DRM_FORMAT_XRGB8888:
Vijay Purushothaman5ee36912012-08-23 12:08:57 +0530237 sprctl |= SPRITE_FORMAT_RGBX888;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800238 break;
239 case DRM_FORMAT_YUYV:
240 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YUYV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800241 break;
242 case DRM_FORMAT_YVYU:
243 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YVYU;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800244 break;
245 case DRM_FORMAT_UYVY:
246 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_UYVY;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800247 break;
248 case DRM_FORMAT_VYUY:
249 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_VYUY;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800250 break;
251 default:
Ville Syrjälä28d491d2012-10-31 17:50:21 +0200252 BUG();
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800253 }
254
255 if (obj->tiling_mode != I915_TILING_NONE)
256 sprctl |= SPRITE_TILED;
257
258 /* must disable */
259 sprctl |= SPRITE_TRICKLE_FEED_DISABLE;
260 sprctl |= SPRITE_ENABLE;
261
Ville Syrjälä86d3efc2013-01-18 19:11:38 +0200262 if (IS_HASWELL(dev))
263 sprctl |= SPRITE_PIPE_CSC_ENABLE;
264
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800265 /* Sizes are 0 based */
266 src_w--;
267 src_h--;
268 crtc_w--;
269 crtc_h--;
270
271 intel_update_sprite_watermarks(dev, pipe, crtc_w, pixel_size);
272
273 /*
274 * IVB workaround: must disable low power watermarks for at least
275 * one frame before enabling scaling. LP watermarks can be re-enabled
276 * when scaling is disabled.
277 */
278 if (crtc_w != src_w || crtc_h != src_h) {
Ville Syrjälä2c6602d2013-02-08 23:13:35 +0200279 dev_priv->sprite_scaling_enabled |= 1 << pipe;
280
281 if (!scaling_was_enabled) {
Chris Wilson828ed3e2012-04-18 17:12:26 +0100282 intel_update_watermarks(dev);
283 intel_wait_for_vblank(dev, pipe);
284 }
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800285 sprscale = SPRITE_SCALE_ENABLE | (src_w << 16) | src_h;
Ville Syrjälä2c6602d2013-02-08 23:13:35 +0200286 } else
287 dev_priv->sprite_scaling_enabled &= ~(1 << pipe);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800288
289 I915_WRITE(SPRSTRIDE(pipe), fb->pitches[0]);
290 I915_WRITE(SPRPOS(pipe), (crtc_y << 16) | crtc_x);
Damien Lespiauc54173a2012-10-26 18:20:11 +0100291
Chris Wilsonca320ac2012-12-19 12:14:22 +0000292 linear_offset = y * fb->pitches[0] + x * pixel_size;
Damien Lespiau5a35e992012-10-26 18:20:12 +0100293 sprsurf_offset =
Chris Wilsonbc752862013-02-21 20:04:31 +0000294 intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
295 pixel_size, fb->pitches[0]);
Damien Lespiau5a35e992012-10-26 18:20:12 +0100296 linear_offset -= sprsurf_offset;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800297
Damien Lespiau5a35e992012-10-26 18:20:12 +0100298 /* HSW consolidates SPRTILEOFF and SPRLINOFF into a single SPROFFSET
299 * register */
300 if (IS_HASWELL(dev))
301 I915_WRITE(SPROFFSET(pipe), (y << 16) | x);
302 else if (obj->tiling_mode != I915_TILING_NONE)
303 I915_WRITE(SPRTILEOFF(pipe), (y << 16) | x);
304 else
305 I915_WRITE(SPRLINOFF(pipe), linear_offset);
Damien Lespiauc54173a2012-10-26 18:20:11 +0100306
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800307 I915_WRITE(SPRSIZE(pipe), (crtc_h << 16) | crtc_w);
Damien Lespiau2d354c32012-10-22 18:19:27 +0100308 if (intel_plane->can_scale)
309 I915_WRITE(SPRSCALE(pipe), sprscale);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800310 I915_WRITE(SPRCTL(pipe), sprctl);
Damien Lespiau5a35e992012-10-26 18:20:12 +0100311 I915_MODIFY_DISPBASE(SPRSURF(pipe), obj->gtt_offset + sprsurf_offset);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800312 POSTING_READ(SPRSURF(pipe));
Ville Syrjälä2c6602d2013-02-08 23:13:35 +0200313
314 /* potentially re-enable LP watermarks */
315 if (scaling_was_enabled && !dev_priv->sprite_scaling_enabled)
316 intel_update_watermarks(dev);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800317}
318
319static void
320ivb_disable_plane(struct drm_plane *plane)
321{
322 struct drm_device *dev = plane->dev;
323 struct drm_i915_private *dev_priv = dev->dev_private;
324 struct intel_plane *intel_plane = to_intel_plane(plane);
325 int pipe = intel_plane->pipe;
Ville Syrjälä2c6602d2013-02-08 23:13:35 +0200326 bool scaling_was_enabled = dev_priv->sprite_scaling_enabled;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800327
328 I915_WRITE(SPRCTL(pipe), I915_READ(SPRCTL(pipe)) & ~SPRITE_ENABLE);
329 /* Can't leave the scaler enabled... */
Damien Lespiau2d354c32012-10-22 18:19:27 +0100330 if (intel_plane->can_scale)
331 I915_WRITE(SPRSCALE(pipe), 0);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800332 /* Activate double buffered register update */
Armin Reese446f2542012-03-30 16:20:16 -0700333 I915_MODIFY_DISPBASE(SPRSURF(pipe), 0);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800334 POSTING_READ(SPRSURF(pipe));
Chris Wilson828ed3e2012-04-18 17:12:26 +0100335
Ville Syrjälä2c6602d2013-02-08 23:13:35 +0200336 dev_priv->sprite_scaling_enabled &= ~(1 << pipe);
337
338 /* potentially re-enable LP watermarks */
339 if (scaling_was_enabled && !dev_priv->sprite_scaling_enabled)
340 intel_update_watermarks(dev);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800341}
342
Jesse Barnes8ea30862012-01-03 08:05:39 -0800343static int
344ivb_update_colorkey(struct drm_plane *plane,
345 struct drm_intel_sprite_colorkey *key)
346{
347 struct drm_device *dev = plane->dev;
348 struct drm_i915_private *dev_priv = dev->dev_private;
349 struct intel_plane *intel_plane;
350 u32 sprctl;
351 int ret = 0;
352
353 intel_plane = to_intel_plane(plane);
354
355 I915_WRITE(SPRKEYVAL(intel_plane->pipe), key->min_value);
356 I915_WRITE(SPRKEYMAX(intel_plane->pipe), key->max_value);
357 I915_WRITE(SPRKEYMSK(intel_plane->pipe), key->channel_mask);
358
359 sprctl = I915_READ(SPRCTL(intel_plane->pipe));
360 sprctl &= ~(SPRITE_SOURCE_KEY | SPRITE_DEST_KEY);
361 if (key->flags & I915_SET_COLORKEY_DESTINATION)
362 sprctl |= SPRITE_DEST_KEY;
363 else if (key->flags & I915_SET_COLORKEY_SOURCE)
364 sprctl |= SPRITE_SOURCE_KEY;
365 I915_WRITE(SPRCTL(intel_plane->pipe), sprctl);
366
367 POSTING_READ(SPRKEYMSK(intel_plane->pipe));
368
369 return ret;
370}
371
372static void
373ivb_get_colorkey(struct drm_plane *plane, struct drm_intel_sprite_colorkey *key)
374{
375 struct drm_device *dev = plane->dev;
376 struct drm_i915_private *dev_priv = dev->dev_private;
377 struct intel_plane *intel_plane;
378 u32 sprctl;
379
380 intel_plane = to_intel_plane(plane);
381
382 key->min_value = I915_READ(SPRKEYVAL(intel_plane->pipe));
383 key->max_value = I915_READ(SPRKEYMAX(intel_plane->pipe));
384 key->channel_mask = I915_READ(SPRKEYMSK(intel_plane->pipe));
385 key->flags = 0;
386
387 sprctl = I915_READ(SPRCTL(intel_plane->pipe));
388
389 if (sprctl & SPRITE_DEST_KEY)
390 key->flags = I915_SET_COLORKEY_DESTINATION;
391 else if (sprctl & SPRITE_SOURCE_KEY)
392 key->flags = I915_SET_COLORKEY_SOURCE;
393 else
394 key->flags = I915_SET_COLORKEY_NONE;
395}
396
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800397static void
Chris Wilsond1686ae2012-04-10 11:41:49 +0100398ilk_update_plane(struct drm_plane *plane, struct drm_framebuffer *fb,
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800399 struct drm_i915_gem_object *obj, int crtc_x, int crtc_y,
400 unsigned int crtc_w, unsigned int crtc_h,
401 uint32_t x, uint32_t y,
402 uint32_t src_w, uint32_t src_h)
403{
404 struct drm_device *dev = plane->dev;
405 struct drm_i915_private *dev_priv = dev->dev_private;
406 struct intel_plane *intel_plane = to_intel_plane(plane);
Ville Syrjälä2bd3c3c2012-10-31 17:50:20 +0200407 int pipe = intel_plane->pipe;
Damien Lespiau5a35e992012-10-26 18:20:12 +0100408 unsigned long dvssurf_offset, linear_offset;
Chris Wilson8aaa81a2012-04-14 22:14:26 +0100409 u32 dvscntr, dvsscale;
Ville Syrjälä2bd3c3c2012-10-31 17:50:20 +0200410 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800411
412 dvscntr = I915_READ(DVSCNTR(pipe));
413
414 /* Mask out pixel format bits in case we change it */
415 dvscntr &= ~DVS_PIXFORMAT_MASK;
Jesse Barnesab2f9df2012-02-27 12:40:10 -0800416 dvscntr &= ~DVS_RGB_ORDER_XBGR;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800417 dvscntr &= ~DVS_YUV_BYTE_ORDER_MASK;
Ander Conselvan de Oliveira79626522012-07-13 15:50:33 +0300418 dvscntr &= ~DVS_TILED;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800419
420 switch (fb->pixel_format) {
421 case DRM_FORMAT_XBGR8888:
Jesse Barnesab2f9df2012-02-27 12:40:10 -0800422 dvscntr |= DVS_FORMAT_RGBX888 | DVS_RGB_ORDER_XBGR;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800423 break;
424 case DRM_FORMAT_XRGB8888:
Jesse Barnesab2f9df2012-02-27 12:40:10 -0800425 dvscntr |= DVS_FORMAT_RGBX888;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800426 break;
427 case DRM_FORMAT_YUYV:
428 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YUYV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800429 break;
430 case DRM_FORMAT_YVYU:
431 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YVYU;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800432 break;
433 case DRM_FORMAT_UYVY:
434 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_UYVY;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800435 break;
436 case DRM_FORMAT_VYUY:
437 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_VYUY;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800438 break;
439 default:
Ville Syrjälä28d491d2012-10-31 17:50:21 +0200440 BUG();
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800441 }
442
443 if (obj->tiling_mode != I915_TILING_NONE)
444 dvscntr |= DVS_TILED;
445
Chris Wilsond1686ae2012-04-10 11:41:49 +0100446 if (IS_GEN6(dev))
447 dvscntr |= DVS_TRICKLE_FEED_DISABLE; /* must disable */
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800448 dvscntr |= DVS_ENABLE;
449
450 /* Sizes are 0 based */
451 src_w--;
452 src_h--;
453 crtc_w--;
454 crtc_h--;
455
456 intel_update_sprite_watermarks(dev, pipe, crtc_w, pixel_size);
457
Chris Wilson8aaa81a2012-04-14 22:14:26 +0100458 dvsscale = 0;
459 if (IS_GEN5(dev) || crtc_w != src_w || crtc_h != src_h)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800460 dvsscale = DVS_SCALE_ENABLE | (src_w << 16) | src_h;
461
462 I915_WRITE(DVSSTRIDE(pipe), fb->pitches[0]);
463 I915_WRITE(DVSPOS(pipe), (crtc_y << 16) | crtc_x);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800464
Chris Wilsonca320ac2012-12-19 12:14:22 +0000465 linear_offset = y * fb->pitches[0] + x * pixel_size;
Damien Lespiau5a35e992012-10-26 18:20:12 +0100466 dvssurf_offset =
Chris Wilsonbc752862013-02-21 20:04:31 +0000467 intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
468 pixel_size, fb->pitches[0]);
Damien Lespiau5a35e992012-10-26 18:20:12 +0100469 linear_offset -= dvssurf_offset;
470
471 if (obj->tiling_mode != I915_TILING_NONE)
472 I915_WRITE(DVSTILEOFF(pipe), (y << 16) | x);
473 else
474 I915_WRITE(DVSLINOFF(pipe), linear_offset);
475
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800476 I915_WRITE(DVSSIZE(pipe), (crtc_h << 16) | crtc_w);
477 I915_WRITE(DVSSCALE(pipe), dvsscale);
478 I915_WRITE(DVSCNTR(pipe), dvscntr);
Damien Lespiau5a35e992012-10-26 18:20:12 +0100479 I915_MODIFY_DISPBASE(DVSSURF(pipe), obj->gtt_offset + dvssurf_offset);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800480 POSTING_READ(DVSSURF(pipe));
481}
482
483static void
Chris Wilsond1686ae2012-04-10 11:41:49 +0100484ilk_disable_plane(struct drm_plane *plane)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800485{
486 struct drm_device *dev = plane->dev;
487 struct drm_i915_private *dev_priv = dev->dev_private;
488 struct intel_plane *intel_plane = to_intel_plane(plane);
489 int pipe = intel_plane->pipe;
490
491 I915_WRITE(DVSCNTR(pipe), I915_READ(DVSCNTR(pipe)) & ~DVS_ENABLE);
492 /* Disable the scaler */
493 I915_WRITE(DVSSCALE(pipe), 0);
494 /* Flush double buffered register updates */
Armin Reese446f2542012-03-30 16:20:16 -0700495 I915_MODIFY_DISPBASE(DVSSURF(pipe), 0);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800496 POSTING_READ(DVSSURF(pipe));
497}
498
Jesse Barnes175bd422011-12-13 13:19:39 -0800499static void
500intel_enable_primary(struct drm_crtc *crtc)
501{
502 struct drm_device *dev = crtc->dev;
503 struct drm_i915_private *dev_priv = dev->dev_private;
504 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
505 int reg = DSPCNTR(intel_crtc->plane);
506
Chris Wilson93314b52012-06-13 17:36:55 +0100507 if (!intel_crtc->primary_disabled)
508 return;
509
510 intel_crtc->primary_disabled = false;
511 intel_update_fbc(dev);
512
Jesse Barnes175bd422011-12-13 13:19:39 -0800513 I915_WRITE(reg, I915_READ(reg) | DISPLAY_PLANE_ENABLE);
514}
515
516static void
517intel_disable_primary(struct drm_crtc *crtc)
518{
519 struct drm_device *dev = crtc->dev;
520 struct drm_i915_private *dev_priv = dev->dev_private;
521 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
522 int reg = DSPCNTR(intel_crtc->plane);
523
Chris Wilson93314b52012-06-13 17:36:55 +0100524 if (intel_crtc->primary_disabled)
525 return;
526
Jesse Barnes175bd422011-12-13 13:19:39 -0800527 I915_WRITE(reg, I915_READ(reg) & ~DISPLAY_PLANE_ENABLE);
Chris Wilson93314b52012-06-13 17:36:55 +0100528
529 intel_crtc->primary_disabled = true;
530 intel_update_fbc(dev);
Jesse Barnes175bd422011-12-13 13:19:39 -0800531}
532
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800533static int
Chris Wilsond1686ae2012-04-10 11:41:49 +0100534ilk_update_colorkey(struct drm_plane *plane,
Jesse Barnes8ea30862012-01-03 08:05:39 -0800535 struct drm_intel_sprite_colorkey *key)
536{
537 struct drm_device *dev = plane->dev;
538 struct drm_i915_private *dev_priv = dev->dev_private;
539 struct intel_plane *intel_plane;
540 u32 dvscntr;
541 int ret = 0;
542
543 intel_plane = to_intel_plane(plane);
544
545 I915_WRITE(DVSKEYVAL(intel_plane->pipe), key->min_value);
546 I915_WRITE(DVSKEYMAX(intel_plane->pipe), key->max_value);
547 I915_WRITE(DVSKEYMSK(intel_plane->pipe), key->channel_mask);
548
549 dvscntr = I915_READ(DVSCNTR(intel_plane->pipe));
550 dvscntr &= ~(DVS_SOURCE_KEY | DVS_DEST_KEY);
551 if (key->flags & I915_SET_COLORKEY_DESTINATION)
552 dvscntr |= DVS_DEST_KEY;
553 else if (key->flags & I915_SET_COLORKEY_SOURCE)
554 dvscntr |= DVS_SOURCE_KEY;
555 I915_WRITE(DVSCNTR(intel_plane->pipe), dvscntr);
556
557 POSTING_READ(DVSKEYMSK(intel_plane->pipe));
558
559 return ret;
560}
561
562static void
Chris Wilsond1686ae2012-04-10 11:41:49 +0100563ilk_get_colorkey(struct drm_plane *plane, struct drm_intel_sprite_colorkey *key)
Jesse Barnes8ea30862012-01-03 08:05:39 -0800564{
565 struct drm_device *dev = plane->dev;
566 struct drm_i915_private *dev_priv = dev->dev_private;
567 struct intel_plane *intel_plane;
568 u32 dvscntr;
569
570 intel_plane = to_intel_plane(plane);
571
572 key->min_value = I915_READ(DVSKEYVAL(intel_plane->pipe));
573 key->max_value = I915_READ(DVSKEYMAX(intel_plane->pipe));
574 key->channel_mask = I915_READ(DVSKEYMSK(intel_plane->pipe));
575 key->flags = 0;
576
577 dvscntr = I915_READ(DVSCNTR(intel_plane->pipe));
578
579 if (dvscntr & DVS_DEST_KEY)
580 key->flags = I915_SET_COLORKEY_DESTINATION;
581 else if (dvscntr & DVS_SOURCE_KEY)
582 key->flags = I915_SET_COLORKEY_SOURCE;
583 else
584 key->flags = I915_SET_COLORKEY_NONE;
585}
586
Ville Syrjälä17316932013-04-24 18:52:38 +0300587static bool
588format_is_yuv(uint32_t format)
589{
590 switch (format) {
591 case DRM_FORMAT_YUYV:
592 case DRM_FORMAT_UYVY:
593 case DRM_FORMAT_VYUY:
594 case DRM_FORMAT_YVYU:
595 return true;
596 default:
597 return false;
598 }
599}
600
Jesse Barnes8ea30862012-01-03 08:05:39 -0800601static int
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800602intel_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
603 struct drm_framebuffer *fb, int crtc_x, int crtc_y,
604 unsigned int crtc_w, unsigned int crtc_h,
605 uint32_t src_x, uint32_t src_y,
606 uint32_t src_w, uint32_t src_h)
607{
608 struct drm_device *dev = plane->dev;
609 struct drm_i915_private *dev_priv = dev->dev_private;
610 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
611 struct intel_plane *intel_plane = to_intel_plane(plane);
612 struct intel_framebuffer *intel_fb;
613 struct drm_i915_gem_object *obj, *old_obj;
614 int pipe = intel_plane->pipe;
Paulo Zanoni702e7a52012-10-23 18:29:59 -0200615 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
616 pipe);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800617 int ret = 0;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800618 bool disable_primary = false;
Ville Syrjälä17316932013-04-24 18:52:38 +0300619 bool visible;
620 int hscale, vscale;
621 int max_scale, min_scale;
622 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
623 struct drm_rect src = {
624 /* sample coordinates in 16.16 fixed point */
625 .x1 = src_x,
626 .x2 = src_x + src_w,
627 .y1 = src_y,
628 .y2 = src_y + src_h,
629 };
630 struct drm_rect dst = {
631 /* integer pixels */
632 .x1 = crtc_x,
633 .x2 = crtc_x + crtc_w,
634 .y1 = crtc_y,
635 .y2 = crtc_y + crtc_h,
636 };
637 const struct drm_rect clip = {
638 .x2 = crtc->mode.hdisplay,
639 .y2 = crtc->mode.vdisplay,
640 };
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800641
642 intel_fb = to_intel_framebuffer(fb);
643 obj = intel_fb->obj;
644
645 old_obj = intel_plane->obj;
646
Jesse Barnes5e1bac22013-03-26 09:25:43 -0700647 intel_plane->crtc_x = crtc_x;
648 intel_plane->crtc_y = crtc_y;
649 intel_plane->crtc_w = crtc_w;
650 intel_plane->crtc_h = crtc_h;
651 intel_plane->src_x = src_x;
652 intel_plane->src_y = src_y;
653 intel_plane->src_w = src_w;
654 intel_plane->src_h = src_h;
655
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800656 /* Pipe must be running... */
Ville Syrjälä17316932013-04-24 18:52:38 +0300657 if (!(I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_ENABLE)) {
658 DRM_DEBUG_KMS("Pipe disabled\n");
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800659 return -EINVAL;
Ville Syrjälä17316932013-04-24 18:52:38 +0300660 }
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800661
662 /* Don't modify another pipe's plane */
Ville Syrjälä17316932013-04-24 18:52:38 +0300663 if (intel_plane->pipe != intel_crtc->pipe) {
664 DRM_DEBUG_KMS("Wrong plane <-> crtc mapping\n");
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800665 return -EINVAL;
Ville Syrjälä17316932013-04-24 18:52:38 +0300666 }
667
668 /* FIXME check all gen limits */
669 if (fb->width < 3 || fb->height < 3 || fb->pitches[0] > 16384) {
670 DRM_DEBUG_KMS("Unsuitable framebuffer for plane\n");
671 return -EINVAL;
672 }
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800673
Damien Lespiau94c64192012-10-29 15:14:51 +0000674 /* Sprite planes can be linear or x-tiled surfaces */
675 switch (obj->tiling_mode) {
676 case I915_TILING_NONE:
677 case I915_TILING_X:
678 break;
679 default:
Ville Syrjälä17316932013-04-24 18:52:38 +0300680 DRM_DEBUG_KMS("Unsupported tiling mode\n");
Damien Lespiau94c64192012-10-29 15:14:51 +0000681 return -EINVAL;
682 }
683
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300684 /*
685 * FIXME the following code does a bunch of fuzzy adjustments to the
686 * coordinates and sizes. We probably need some way to decide whether
687 * more strict checking should be done instead.
688 */
Ville Syrjälä17316932013-04-24 18:52:38 +0300689 max_scale = intel_plane->max_downscale << 16;
690 min_scale = intel_plane->can_scale ? 1 : (1 << 16);
691
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300692 hscale = drm_rect_calc_hscale_relaxed(&src, &dst, min_scale, max_scale);
693 BUG_ON(hscale < 0);
Ville Syrjälä17316932013-04-24 18:52:38 +0300694
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300695 vscale = drm_rect_calc_vscale_relaxed(&src, &dst, min_scale, max_scale);
696 BUG_ON(vscale < 0);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800697
Ville Syrjälä17316932013-04-24 18:52:38 +0300698 visible = drm_rect_clip_scaled(&src, &dst, &clip, hscale, vscale);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800699
Ville Syrjälä17316932013-04-24 18:52:38 +0300700 crtc_x = dst.x1;
701 crtc_y = dst.y1;
702 crtc_w = drm_rect_width(&dst);
703 crtc_h = drm_rect_height(&dst);
Damien Lespiau2d354c32012-10-22 18:19:27 +0100704
Ville Syrjälä17316932013-04-24 18:52:38 +0300705 if (visible) {
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300706 /* check again in case clipping clamped the results */
707 hscale = drm_rect_calc_hscale(&src, &dst, min_scale, max_scale);
708 if (hscale < 0) {
709 DRM_DEBUG_KMS("Horizontal scaling factor out of limits\n");
710 drm_rect_debug_print(&src, true);
711 drm_rect_debug_print(&dst, false);
712
713 return hscale;
714 }
715
716 vscale = drm_rect_calc_vscale(&src, &dst, min_scale, max_scale);
717 if (vscale < 0) {
718 DRM_DEBUG_KMS("Vertical scaling factor out of limits\n");
719 drm_rect_debug_print(&src, true);
720 drm_rect_debug_print(&dst, false);
721
722 return vscale;
723 }
724
Ville Syrjälä17316932013-04-24 18:52:38 +0300725 /* Make the source viewport size an exact multiple of the scaling factors. */
726 drm_rect_adjust_size(&src,
727 drm_rect_width(&dst) * hscale - drm_rect_width(&src),
728 drm_rect_height(&dst) * vscale - drm_rect_height(&src));
729
730 /* sanity check to make sure the src viewport wasn't enlarged */
731 WARN_ON(src.x1 < (int) src_x ||
732 src.y1 < (int) src_y ||
733 src.x2 > (int) (src_x + src_w) ||
734 src.y2 > (int) (src_y + src_h));
735
736 /*
737 * Hardware doesn't handle subpixel coordinates.
738 * Adjust to (macro)pixel boundary, but be careful not to
739 * increase the source viewport size, because that could
740 * push the downscaling factor out of bounds.
Ville Syrjälä17316932013-04-24 18:52:38 +0300741 */
742 src_x = src.x1 >> 16;
743 src_w = drm_rect_width(&src) >> 16;
744 src_y = src.y1 >> 16;
745 src_h = drm_rect_height(&src) >> 16;
746
747 if (format_is_yuv(fb->pixel_format)) {
748 src_x &= ~1;
749 src_w &= ~1;
750
751 /*
752 * Must keep src and dst the
753 * same if we can't scale.
754 */
755 if (!intel_plane->can_scale)
756 crtc_w &= ~1;
757
758 if (crtc_w == 0)
759 visible = false;
760 }
761 }
762
763 /* Check size restrictions when scaling */
764 if (visible && (src_w != crtc_w || src_h != crtc_h)) {
765 unsigned int width_bytes;
766
767 WARN_ON(!intel_plane->can_scale);
768
769 /* FIXME interlacing min height is 6 */
770
771 if (crtc_w < 3 || crtc_h < 3)
772 visible = false;
773
774 if (src_w < 3 || src_h < 3)
775 visible = false;
776
777 width_bytes = ((src_x * pixel_size) & 63) + src_w * pixel_size;
778
779 if (src_w > 2048 || src_h > 2048 ||
780 width_bytes > 4096 || fb->pitches[0] > 4096) {
781 DRM_DEBUG_KMS("Source dimensions exceed hardware limits\n");
782 return -EINVAL;
783 }
784 }
785
786 dst.x1 = crtc_x;
787 dst.x2 = crtc_x + crtc_w;
788 dst.y1 = crtc_y;
789 dst.y2 = crtc_y + crtc_h;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800790
791 /*
792 * If the sprite is completely covering the primary plane,
793 * we can disable the primary and save power.
794 */
Ville Syrjälä17316932013-04-24 18:52:38 +0300795 disable_primary = drm_rect_equals(&dst, &clip);
796 WARN_ON(disable_primary && !visible);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800797
798 mutex_lock(&dev->struct_mutex);
799
Chris Wilson693db182013-03-05 14:52:39 +0000800 /* Note that this will apply the VT-d workaround for scanouts,
801 * which is more restrictive than required for sprites. (The
802 * primary plane requires 256KiB alignment with 64 PTE padding,
803 * the sprite planes only require 128KiB alignment and 32 PTE padding.
804 */
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800805 ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
Jesse Barnes00c2064b2012-01-13 15:48:39 -0800806 if (ret)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800807 goto out_unlock;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800808
809 intel_plane->obj = obj;
810
Jesse Barnes175bd422011-12-13 13:19:39 -0800811 /*
812 * Be sure to re-enable the primary before the sprite is no longer
813 * covering it fully.
814 */
Chris Wilson93314b52012-06-13 17:36:55 +0100815 if (!disable_primary)
Jesse Barnes175bd422011-12-13 13:19:39 -0800816 intel_enable_primary(crtc);
Jesse Barnes175bd422011-12-13 13:19:39 -0800817
Ville Syrjälä17316932013-04-24 18:52:38 +0300818 if (visible)
819 intel_plane->update_plane(plane, fb, obj,
820 crtc_x, crtc_y, crtc_w, crtc_h,
821 src_x, src_y, src_w, src_h);
822 else
823 intel_plane->disable_plane(plane);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800824
Chris Wilson93314b52012-06-13 17:36:55 +0100825 if (disable_primary)
Jesse Barnes175bd422011-12-13 13:19:39 -0800826 intel_disable_primary(crtc);
Jesse Barnes175bd422011-12-13 13:19:39 -0800827
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800828 /* Unpin old obj after new one is active to avoid ugliness */
829 if (old_obj) {
830 /*
831 * It's fairly common to simply update the position of
832 * an existing object. In that case, we don't need to
833 * wait for vblank to avoid ugliness, we only need to
834 * do the pin & ref bookkeeping.
835 */
836 if (old_obj != obj) {
837 mutex_unlock(&dev->struct_mutex);
838 intel_wait_for_vblank(dev, to_intel_crtc(crtc)->pipe);
839 mutex_lock(&dev->struct_mutex);
840 }
Chris Wilson1690e1e2011-12-14 13:57:08 +0100841 intel_unpin_fb_obj(old_obj);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800842 }
843
844out_unlock:
845 mutex_unlock(&dev->struct_mutex);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800846 return ret;
847}
848
849static int
850intel_disable_plane(struct drm_plane *plane)
851{
852 struct drm_device *dev = plane->dev;
853 struct intel_plane *intel_plane = to_intel_plane(plane);
854 int ret = 0;
855
Chris Wilson93314b52012-06-13 17:36:55 +0100856 if (plane->crtc)
Jesse Barnes175bd422011-12-13 13:19:39 -0800857 intel_enable_primary(plane->crtc);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800858 intel_plane->disable_plane(plane);
859
860 if (!intel_plane->obj)
861 goto out;
862
Ville Syrjäläc626d312013-03-27 17:49:13 +0200863 intel_wait_for_vblank(dev, intel_plane->pipe);
864
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800865 mutex_lock(&dev->struct_mutex);
Chris Wilson1690e1e2011-12-14 13:57:08 +0100866 intel_unpin_fb_obj(intel_plane->obj);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800867 intel_plane->obj = NULL;
868 mutex_unlock(&dev->struct_mutex);
869out:
870
871 return ret;
872}
873
874static void intel_destroy_plane(struct drm_plane *plane)
875{
876 struct intel_plane *intel_plane = to_intel_plane(plane);
877 intel_disable_plane(plane);
878 drm_plane_cleanup(plane);
879 kfree(intel_plane);
880}
881
Jesse Barnes8ea30862012-01-03 08:05:39 -0800882int intel_sprite_set_colorkey(struct drm_device *dev, void *data,
883 struct drm_file *file_priv)
884{
885 struct drm_intel_sprite_colorkey *set = data;
Jesse Barnes8ea30862012-01-03 08:05:39 -0800886 struct drm_mode_object *obj;
887 struct drm_plane *plane;
888 struct intel_plane *intel_plane;
889 int ret = 0;
890
Daniel Vetter1cff8f62012-04-24 09:55:08 +0200891 if (!drm_core_check_feature(dev, DRIVER_MODESET))
892 return -ENODEV;
Jesse Barnes8ea30862012-01-03 08:05:39 -0800893
894 /* Make sure we don't try to enable both src & dest simultaneously */
895 if ((set->flags & (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE)) == (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE))
896 return -EINVAL;
897
Daniel Vettera0e99e62012-12-02 01:05:46 +0100898 drm_modeset_lock_all(dev);
Jesse Barnes8ea30862012-01-03 08:05:39 -0800899
900 obj = drm_mode_object_find(dev, set->plane_id, DRM_MODE_OBJECT_PLANE);
901 if (!obj) {
902 ret = -EINVAL;
903 goto out_unlock;
904 }
905
906 plane = obj_to_plane(obj);
907 intel_plane = to_intel_plane(plane);
908 ret = intel_plane->update_colorkey(plane, set);
909
910out_unlock:
Daniel Vettera0e99e62012-12-02 01:05:46 +0100911 drm_modeset_unlock_all(dev);
Jesse Barnes8ea30862012-01-03 08:05:39 -0800912 return ret;
913}
914
915int intel_sprite_get_colorkey(struct drm_device *dev, void *data,
916 struct drm_file *file_priv)
917{
918 struct drm_intel_sprite_colorkey *get = data;
Jesse Barnes8ea30862012-01-03 08:05:39 -0800919 struct drm_mode_object *obj;
920 struct drm_plane *plane;
921 struct intel_plane *intel_plane;
922 int ret = 0;
923
Daniel Vetter1cff8f62012-04-24 09:55:08 +0200924 if (!drm_core_check_feature(dev, DRIVER_MODESET))
925 return -ENODEV;
Jesse Barnes8ea30862012-01-03 08:05:39 -0800926
Daniel Vettera0e99e62012-12-02 01:05:46 +0100927 drm_modeset_lock_all(dev);
Jesse Barnes8ea30862012-01-03 08:05:39 -0800928
929 obj = drm_mode_object_find(dev, get->plane_id, DRM_MODE_OBJECT_PLANE);
930 if (!obj) {
931 ret = -EINVAL;
932 goto out_unlock;
933 }
934
935 plane = obj_to_plane(obj);
936 intel_plane = to_intel_plane(plane);
937 intel_plane->get_colorkey(plane, get);
938
939out_unlock:
Daniel Vettera0e99e62012-12-02 01:05:46 +0100940 drm_modeset_unlock_all(dev);
Jesse Barnes8ea30862012-01-03 08:05:39 -0800941 return ret;
942}
943
Jesse Barnes5e1bac22013-03-26 09:25:43 -0700944void intel_plane_restore(struct drm_plane *plane)
945{
946 struct intel_plane *intel_plane = to_intel_plane(plane);
947
948 if (!plane->crtc || !plane->fb)
949 return;
950
951 intel_update_plane(plane, plane->crtc, plane->fb,
952 intel_plane->crtc_x, intel_plane->crtc_y,
953 intel_plane->crtc_w, intel_plane->crtc_h,
954 intel_plane->src_x, intel_plane->src_y,
955 intel_plane->src_w, intel_plane->src_h);
956}
957
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800958static const struct drm_plane_funcs intel_plane_funcs = {
959 .update_plane = intel_update_plane,
960 .disable_plane = intel_disable_plane,
961 .destroy = intel_destroy_plane,
962};
963
Chris Wilsond1686ae2012-04-10 11:41:49 +0100964static uint32_t ilk_plane_formats[] = {
965 DRM_FORMAT_XRGB8888,
966 DRM_FORMAT_YUYV,
967 DRM_FORMAT_YVYU,
968 DRM_FORMAT_UYVY,
969 DRM_FORMAT_VYUY,
970};
971
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800972static uint32_t snb_plane_formats[] = {
973 DRM_FORMAT_XBGR8888,
974 DRM_FORMAT_XRGB8888,
975 DRM_FORMAT_YUYV,
976 DRM_FORMAT_YVYU,
977 DRM_FORMAT_UYVY,
978 DRM_FORMAT_VYUY,
979};
980
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700981static uint32_t vlv_plane_formats[] = {
982 DRM_FORMAT_RGB565,
983 DRM_FORMAT_ABGR8888,
984 DRM_FORMAT_ARGB8888,
985 DRM_FORMAT_XBGR8888,
986 DRM_FORMAT_XRGB8888,
987 DRM_FORMAT_XBGR2101010,
988 DRM_FORMAT_ABGR2101010,
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 -0800995int
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700996intel_plane_init(struct drm_device *dev, enum pipe pipe, int plane)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800997{
998 struct intel_plane *intel_plane;
999 unsigned long possible_crtcs;
Chris Wilsond1686ae2012-04-10 11:41:49 +01001000 const uint32_t *plane_formats;
1001 int num_plane_formats;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001002 int ret;
1003
Chris Wilsond1686ae2012-04-10 11:41:49 +01001004 if (INTEL_INFO(dev)->gen < 5)
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001005 return -ENODEV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001006
1007 intel_plane = kzalloc(sizeof(struct intel_plane), GFP_KERNEL);
1008 if (!intel_plane)
1009 return -ENOMEM;
1010
Chris Wilsond1686ae2012-04-10 11:41:49 +01001011 switch (INTEL_INFO(dev)->gen) {
1012 case 5:
1013 case 6:
Damien Lespiau2d354c32012-10-22 18:19:27 +01001014 intel_plane->can_scale = true;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001015 intel_plane->max_downscale = 16;
Chris Wilsond1686ae2012-04-10 11:41:49 +01001016 intel_plane->update_plane = ilk_update_plane;
1017 intel_plane->disable_plane = ilk_disable_plane;
1018 intel_plane->update_colorkey = ilk_update_colorkey;
1019 intel_plane->get_colorkey = ilk_get_colorkey;
1020
1021 if (IS_GEN6(dev)) {
1022 plane_formats = snb_plane_formats;
1023 num_plane_formats = ARRAY_SIZE(snb_plane_formats);
1024 } else {
1025 plane_formats = ilk_plane_formats;
1026 num_plane_formats = ARRAY_SIZE(ilk_plane_formats);
1027 }
1028 break;
1029
1030 case 7:
Damien Lespiaud49f7092013-04-25 15:15:00 +01001031 if (IS_IVYBRIDGE(dev)) {
Damien Lespiau2d354c32012-10-22 18:19:27 +01001032 intel_plane->can_scale = true;
Damien Lespiaud49f7092013-04-25 15:15:00 +01001033 intel_plane->max_downscale = 2;
1034 } else {
1035 intel_plane->can_scale = false;
1036 intel_plane->max_downscale = 1;
1037 }
Chris Wilsond1686ae2012-04-10 11:41:49 +01001038
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001039 if (IS_VALLEYVIEW(dev)) {
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001040 intel_plane->update_plane = vlv_update_plane;
1041 intel_plane->disable_plane = vlv_disable_plane;
1042 intel_plane->update_colorkey = vlv_update_colorkey;
1043 intel_plane->get_colorkey = vlv_get_colorkey;
1044
1045 plane_formats = vlv_plane_formats;
1046 num_plane_formats = ARRAY_SIZE(vlv_plane_formats);
1047 } else {
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001048 intel_plane->update_plane = ivb_update_plane;
1049 intel_plane->disable_plane = ivb_disable_plane;
1050 intel_plane->update_colorkey = ivb_update_colorkey;
1051 intel_plane->get_colorkey = ivb_get_colorkey;
1052
1053 plane_formats = snb_plane_formats;
1054 num_plane_formats = ARRAY_SIZE(snb_plane_formats);
1055 }
Chris Wilsond1686ae2012-04-10 11:41:49 +01001056 break;
1057
1058 default:
Jesper Juhla8b0bba2012-06-27 00:55:37 +02001059 kfree(intel_plane);
Chris Wilsond1686ae2012-04-10 11:41:49 +01001060 return -ENODEV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001061 }
1062
1063 intel_plane->pipe = pipe;
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001064 intel_plane->plane = plane;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001065 possible_crtcs = (1 << pipe);
1066 ret = drm_plane_init(dev, &intel_plane->base, possible_crtcs,
Chris Wilsond1686ae2012-04-10 11:41:49 +01001067 &intel_plane_funcs,
1068 plane_formats, num_plane_formats,
1069 false);
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001070 if (ret)
1071 kfree(intel_plane);
1072
1073 return ret;
1074}