blob: 87fe3b625c4b143d3b8a6fead9da15214c812bcf [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ä17316932013-04-24 18:52:38 +0300684 max_scale = intel_plane->max_downscale << 16;
685 min_scale = intel_plane->can_scale ? 1 : (1 << 16);
686
687 hscale = drm_rect_calc_hscale(&src, &dst, min_scale, max_scale);
688 if (hscale < 0) {
689 DRM_DEBUG_KMS("Horizontal scaling factor out of limits\n");
690 drm_rect_debug_print(&src, true);
691 drm_rect_debug_print(&dst, false);
692
693 return hscale;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800694 }
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800695
Ville Syrjälä17316932013-04-24 18:52:38 +0300696 vscale = drm_rect_calc_vscale(&src, &dst, min_scale, max_scale);
697 if (vscale < 0) {
698 DRM_DEBUG_KMS("Vertical scaling factor out of limits\n");
699 drm_rect_debug_print(&src, true);
700 drm_rect_debug_print(&dst, false);
701
702 return vscale;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800703 }
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) {
713 /* Make the source viewport size an exact multiple of the scaling factors. */
714 drm_rect_adjust_size(&src,
715 drm_rect_width(&dst) * hscale - drm_rect_width(&src),
716 drm_rect_height(&dst) * vscale - drm_rect_height(&src));
717
718 /* sanity check to make sure the src viewport wasn't enlarged */
719 WARN_ON(src.x1 < (int) src_x ||
720 src.y1 < (int) src_y ||
721 src.x2 > (int) (src_x + src_w) ||
722 src.y2 > (int) (src_y + src_h));
723
724 /*
725 * Hardware doesn't handle subpixel coordinates.
726 * Adjust to (macro)pixel boundary, but be careful not to
727 * increase the source viewport size, because that could
728 * push the downscaling factor out of bounds.
729 *
730 * FIXME Should we be really strict and reject the
731 * config if it results in non (macro)pixel aligned
732 * coords?
733 */
734 src_x = src.x1 >> 16;
735 src_w = drm_rect_width(&src) >> 16;
736 src_y = src.y1 >> 16;
737 src_h = drm_rect_height(&src) >> 16;
738
739 if (format_is_yuv(fb->pixel_format)) {
740 src_x &= ~1;
741 src_w &= ~1;
742
743 /*
744 * Must keep src and dst the
745 * same if we can't scale.
746 */
747 if (!intel_plane->can_scale)
748 crtc_w &= ~1;
749
750 if (crtc_w == 0)
751 visible = false;
752 }
753 }
754
755 /* Check size restrictions when scaling */
756 if (visible && (src_w != crtc_w || src_h != crtc_h)) {
757 unsigned int width_bytes;
758
759 WARN_ON(!intel_plane->can_scale);
760
761 /* FIXME interlacing min height is 6 */
762
763 if (crtc_w < 3 || crtc_h < 3)
764 visible = false;
765
766 if (src_w < 3 || src_h < 3)
767 visible = false;
768
769 width_bytes = ((src_x * pixel_size) & 63) + src_w * pixel_size;
770
771 if (src_w > 2048 || src_h > 2048 ||
772 width_bytes > 4096 || fb->pitches[0] > 4096) {
773 DRM_DEBUG_KMS("Source dimensions exceed hardware limits\n");
774 return -EINVAL;
775 }
776 }
777
778 dst.x1 = crtc_x;
779 dst.x2 = crtc_x + crtc_w;
780 dst.y1 = crtc_y;
781 dst.y2 = crtc_y + crtc_h;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800782
783 /*
784 * If the sprite is completely covering the primary plane,
785 * we can disable the primary and save power.
786 */
Ville Syrjälä17316932013-04-24 18:52:38 +0300787 disable_primary = drm_rect_equals(&dst, &clip);
788 WARN_ON(disable_primary && !visible);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800789
790 mutex_lock(&dev->struct_mutex);
791
Chris Wilson693db182013-03-05 14:52:39 +0000792 /* Note that this will apply the VT-d workaround for scanouts,
793 * which is more restrictive than required for sprites. (The
794 * primary plane requires 256KiB alignment with 64 PTE padding,
795 * the sprite planes only require 128KiB alignment and 32 PTE padding.
796 */
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800797 ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
Jesse Barnes00c2064b2012-01-13 15:48:39 -0800798 if (ret)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800799 goto out_unlock;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800800
801 intel_plane->obj = obj;
802
Jesse Barnes175bd422011-12-13 13:19:39 -0800803 /*
804 * Be sure to re-enable the primary before the sprite is no longer
805 * covering it fully.
806 */
Chris Wilson93314b52012-06-13 17:36:55 +0100807 if (!disable_primary)
Jesse Barnes175bd422011-12-13 13:19:39 -0800808 intel_enable_primary(crtc);
Jesse Barnes175bd422011-12-13 13:19:39 -0800809
Ville Syrjälä17316932013-04-24 18:52:38 +0300810 if (visible)
811 intel_plane->update_plane(plane, fb, obj,
812 crtc_x, crtc_y, crtc_w, crtc_h,
813 src_x, src_y, src_w, src_h);
814 else
815 intel_plane->disable_plane(plane);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800816
Chris Wilson93314b52012-06-13 17:36:55 +0100817 if (disable_primary)
Jesse Barnes175bd422011-12-13 13:19:39 -0800818 intel_disable_primary(crtc);
Jesse Barnes175bd422011-12-13 13:19:39 -0800819
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800820 /* Unpin old obj after new one is active to avoid ugliness */
821 if (old_obj) {
822 /*
823 * It's fairly common to simply update the position of
824 * an existing object. In that case, we don't need to
825 * wait for vblank to avoid ugliness, we only need to
826 * do the pin & ref bookkeeping.
827 */
828 if (old_obj != obj) {
829 mutex_unlock(&dev->struct_mutex);
830 intel_wait_for_vblank(dev, to_intel_crtc(crtc)->pipe);
831 mutex_lock(&dev->struct_mutex);
832 }
Chris Wilson1690e1e2011-12-14 13:57:08 +0100833 intel_unpin_fb_obj(old_obj);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800834 }
835
836out_unlock:
837 mutex_unlock(&dev->struct_mutex);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800838 return ret;
839}
840
841static int
842intel_disable_plane(struct drm_plane *plane)
843{
844 struct drm_device *dev = plane->dev;
845 struct intel_plane *intel_plane = to_intel_plane(plane);
846 int ret = 0;
847
Chris Wilson93314b52012-06-13 17:36:55 +0100848 if (plane->crtc)
Jesse Barnes175bd422011-12-13 13:19:39 -0800849 intel_enable_primary(plane->crtc);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800850 intel_plane->disable_plane(plane);
851
852 if (!intel_plane->obj)
853 goto out;
854
Ville Syrjäläc626d312013-03-27 17:49:13 +0200855 intel_wait_for_vblank(dev, intel_plane->pipe);
856
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800857 mutex_lock(&dev->struct_mutex);
Chris Wilson1690e1e2011-12-14 13:57:08 +0100858 intel_unpin_fb_obj(intel_plane->obj);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800859 intel_plane->obj = NULL;
860 mutex_unlock(&dev->struct_mutex);
861out:
862
863 return ret;
864}
865
866static void intel_destroy_plane(struct drm_plane *plane)
867{
868 struct intel_plane *intel_plane = to_intel_plane(plane);
869 intel_disable_plane(plane);
870 drm_plane_cleanup(plane);
871 kfree(intel_plane);
872}
873
Jesse Barnes8ea30862012-01-03 08:05:39 -0800874int intel_sprite_set_colorkey(struct drm_device *dev, void *data,
875 struct drm_file *file_priv)
876{
877 struct drm_intel_sprite_colorkey *set = data;
Jesse Barnes8ea30862012-01-03 08:05:39 -0800878 struct drm_mode_object *obj;
879 struct drm_plane *plane;
880 struct intel_plane *intel_plane;
881 int ret = 0;
882
Daniel Vetter1cff8f62012-04-24 09:55:08 +0200883 if (!drm_core_check_feature(dev, DRIVER_MODESET))
884 return -ENODEV;
Jesse Barnes8ea30862012-01-03 08:05:39 -0800885
886 /* Make sure we don't try to enable both src & dest simultaneously */
887 if ((set->flags & (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE)) == (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE))
888 return -EINVAL;
889
Daniel Vettera0e99e62012-12-02 01:05:46 +0100890 drm_modeset_lock_all(dev);
Jesse Barnes8ea30862012-01-03 08:05:39 -0800891
892 obj = drm_mode_object_find(dev, set->plane_id, DRM_MODE_OBJECT_PLANE);
893 if (!obj) {
894 ret = -EINVAL;
895 goto out_unlock;
896 }
897
898 plane = obj_to_plane(obj);
899 intel_plane = to_intel_plane(plane);
900 ret = intel_plane->update_colorkey(plane, set);
901
902out_unlock:
Daniel Vettera0e99e62012-12-02 01:05:46 +0100903 drm_modeset_unlock_all(dev);
Jesse Barnes8ea30862012-01-03 08:05:39 -0800904 return ret;
905}
906
907int intel_sprite_get_colorkey(struct drm_device *dev, void *data,
908 struct drm_file *file_priv)
909{
910 struct drm_intel_sprite_colorkey *get = data;
Jesse Barnes8ea30862012-01-03 08:05:39 -0800911 struct drm_mode_object *obj;
912 struct drm_plane *plane;
913 struct intel_plane *intel_plane;
914 int ret = 0;
915
Daniel Vetter1cff8f62012-04-24 09:55:08 +0200916 if (!drm_core_check_feature(dev, DRIVER_MODESET))
917 return -ENODEV;
Jesse Barnes8ea30862012-01-03 08:05:39 -0800918
Daniel Vettera0e99e62012-12-02 01:05:46 +0100919 drm_modeset_lock_all(dev);
Jesse Barnes8ea30862012-01-03 08:05:39 -0800920
921 obj = drm_mode_object_find(dev, get->plane_id, DRM_MODE_OBJECT_PLANE);
922 if (!obj) {
923 ret = -EINVAL;
924 goto out_unlock;
925 }
926
927 plane = obj_to_plane(obj);
928 intel_plane = to_intel_plane(plane);
929 intel_plane->get_colorkey(plane, get);
930
931out_unlock:
Daniel Vettera0e99e62012-12-02 01:05:46 +0100932 drm_modeset_unlock_all(dev);
Jesse Barnes8ea30862012-01-03 08:05:39 -0800933 return ret;
934}
935
Jesse Barnes5e1bac22013-03-26 09:25:43 -0700936void intel_plane_restore(struct drm_plane *plane)
937{
938 struct intel_plane *intel_plane = to_intel_plane(plane);
939
940 if (!plane->crtc || !plane->fb)
941 return;
942
943 intel_update_plane(plane, plane->crtc, plane->fb,
944 intel_plane->crtc_x, intel_plane->crtc_y,
945 intel_plane->crtc_w, intel_plane->crtc_h,
946 intel_plane->src_x, intel_plane->src_y,
947 intel_plane->src_w, intel_plane->src_h);
948}
949
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800950static const struct drm_plane_funcs intel_plane_funcs = {
951 .update_plane = intel_update_plane,
952 .disable_plane = intel_disable_plane,
953 .destroy = intel_destroy_plane,
954};
955
Chris Wilsond1686ae2012-04-10 11:41:49 +0100956static uint32_t ilk_plane_formats[] = {
957 DRM_FORMAT_XRGB8888,
958 DRM_FORMAT_YUYV,
959 DRM_FORMAT_YVYU,
960 DRM_FORMAT_UYVY,
961 DRM_FORMAT_VYUY,
962};
963
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800964static uint32_t snb_plane_formats[] = {
965 DRM_FORMAT_XBGR8888,
966 DRM_FORMAT_XRGB8888,
967 DRM_FORMAT_YUYV,
968 DRM_FORMAT_YVYU,
969 DRM_FORMAT_UYVY,
970 DRM_FORMAT_VYUY,
971};
972
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700973static uint32_t vlv_plane_formats[] = {
974 DRM_FORMAT_RGB565,
975 DRM_FORMAT_ABGR8888,
976 DRM_FORMAT_ARGB8888,
977 DRM_FORMAT_XBGR8888,
978 DRM_FORMAT_XRGB8888,
979 DRM_FORMAT_XBGR2101010,
980 DRM_FORMAT_ABGR2101010,
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 -0800987int
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700988intel_plane_init(struct drm_device *dev, enum pipe pipe, int plane)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800989{
990 struct intel_plane *intel_plane;
991 unsigned long possible_crtcs;
Chris Wilsond1686ae2012-04-10 11:41:49 +0100992 const uint32_t *plane_formats;
993 int num_plane_formats;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800994 int ret;
995
Chris Wilsond1686ae2012-04-10 11:41:49 +0100996 if (INTEL_INFO(dev)->gen < 5)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800997 return -ENODEV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800998
999 intel_plane = kzalloc(sizeof(struct intel_plane), GFP_KERNEL);
1000 if (!intel_plane)
1001 return -ENOMEM;
1002
Chris Wilsond1686ae2012-04-10 11:41:49 +01001003 switch (INTEL_INFO(dev)->gen) {
1004 case 5:
1005 case 6:
Damien Lespiau2d354c32012-10-22 18:19:27 +01001006 intel_plane->can_scale = true;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001007 intel_plane->max_downscale = 16;
Chris Wilsond1686ae2012-04-10 11:41:49 +01001008 intel_plane->update_plane = ilk_update_plane;
1009 intel_plane->disable_plane = ilk_disable_plane;
1010 intel_plane->update_colorkey = ilk_update_colorkey;
1011 intel_plane->get_colorkey = ilk_get_colorkey;
1012
1013 if (IS_GEN6(dev)) {
1014 plane_formats = snb_plane_formats;
1015 num_plane_formats = ARRAY_SIZE(snb_plane_formats);
1016 } else {
1017 plane_formats = ilk_plane_formats;
1018 num_plane_formats = ARRAY_SIZE(ilk_plane_formats);
1019 }
1020 break;
1021
1022 case 7:
Damien Lespiaud49f7092013-04-25 15:15:00 +01001023 if (IS_IVYBRIDGE(dev)) {
Damien Lespiau2d354c32012-10-22 18:19:27 +01001024 intel_plane->can_scale = true;
Damien Lespiaud49f7092013-04-25 15:15:00 +01001025 intel_plane->max_downscale = 2;
1026 } else {
1027 intel_plane->can_scale = false;
1028 intel_plane->max_downscale = 1;
1029 }
Chris Wilsond1686ae2012-04-10 11:41:49 +01001030
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001031 if (IS_VALLEYVIEW(dev)) {
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001032 intel_plane->update_plane = vlv_update_plane;
1033 intel_plane->disable_plane = vlv_disable_plane;
1034 intel_plane->update_colorkey = vlv_update_colorkey;
1035 intel_plane->get_colorkey = vlv_get_colorkey;
1036
1037 plane_formats = vlv_plane_formats;
1038 num_plane_formats = ARRAY_SIZE(vlv_plane_formats);
1039 } else {
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001040 intel_plane->update_plane = ivb_update_plane;
1041 intel_plane->disable_plane = ivb_disable_plane;
1042 intel_plane->update_colorkey = ivb_update_colorkey;
1043 intel_plane->get_colorkey = ivb_get_colorkey;
1044
1045 plane_formats = snb_plane_formats;
1046 num_plane_formats = ARRAY_SIZE(snb_plane_formats);
1047 }
Chris Wilsond1686ae2012-04-10 11:41:49 +01001048 break;
1049
1050 default:
Jesper Juhla8b0bba2012-06-27 00:55:37 +02001051 kfree(intel_plane);
Chris Wilsond1686ae2012-04-10 11:41:49 +01001052 return -ENODEV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001053 }
1054
1055 intel_plane->pipe = pipe;
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001056 intel_plane->plane = plane;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001057 possible_crtcs = (1 << pipe);
1058 ret = drm_plane_init(dev, &intel_plane->base, possible_crtcs,
Chris Wilsond1686ae2012-04-10 11:41:49 +01001059 &intel_plane_funcs,
1060 plane_formats, num_plane_formats,
1061 false);
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001062 if (ret)
1063 kfree(intel_plane);
1064
1065 return ret;
1066}