blob: 1a1483b924d08a695a6ae4d8ed6345b626d0b085 [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 */
32#include "drmP.h"
33#include "drm_crtc.h"
34#include "drm_fourcc.h"
35#include "intel_drv.h"
36#include "i915_drm.h"
37#include "i915_drv.h"
38
39static void
40ivb_update_plane(struct drm_plane *plane, struct drm_framebuffer *fb,
41 struct drm_i915_gem_object *obj, int crtc_x, int crtc_y,
42 unsigned int crtc_w, unsigned int crtc_h,
43 uint32_t x, uint32_t y,
44 uint32_t src_w, uint32_t src_h)
45{
46 struct drm_device *dev = plane->dev;
47 struct drm_i915_private *dev_priv = dev->dev_private;
48 struct intel_plane *intel_plane = to_intel_plane(plane);
49 int pipe = intel_plane->pipe;
50 u32 sprctl, sprscale = 0;
51 int pixel_size;
52
53 sprctl = I915_READ(SPRCTL(pipe));
54
55 /* Mask out pixel format bits in case we change it */
56 sprctl &= ~SPRITE_PIXFORMAT_MASK;
57 sprctl &= ~SPRITE_RGB_ORDER_RGBX;
58 sprctl &= ~SPRITE_YUV_BYTE_ORDER_MASK;
Jesse Barnese86fe0d2012-06-26 13:10:11 -070059 sprctl &= ~SPRITE_TILED;
Jesse Barnesb840d907f2011-12-13 13:19:38 -080060
61 switch (fb->pixel_format) {
62 case DRM_FORMAT_XBGR8888:
63 sprctl |= SPRITE_FORMAT_RGBX888;
64 pixel_size = 4;
65 break;
66 case DRM_FORMAT_XRGB8888:
67 sprctl |= SPRITE_FORMAT_RGBX888 | SPRITE_RGB_ORDER_RGBX;
68 pixel_size = 4;
69 break;
70 case DRM_FORMAT_YUYV:
71 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YUYV;
72 pixel_size = 2;
73 break;
74 case DRM_FORMAT_YVYU:
75 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YVYU;
76 pixel_size = 2;
77 break;
78 case DRM_FORMAT_UYVY:
79 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_UYVY;
80 pixel_size = 2;
81 break;
82 case DRM_FORMAT_VYUY:
83 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_VYUY;
84 pixel_size = 2;
85 break;
86 default:
87 DRM_DEBUG_DRIVER("bad pixel format, assuming RGBX888\n");
Jesse Barnesf4d71052012-06-26 13:10:12 -070088 sprctl |= SPRITE_FORMAT_RGBX888;
Jesse Barnesb840d907f2011-12-13 13:19:38 -080089 pixel_size = 4;
90 break;
91 }
92
93 if (obj->tiling_mode != I915_TILING_NONE)
94 sprctl |= SPRITE_TILED;
95
96 /* must disable */
97 sprctl |= SPRITE_TRICKLE_FEED_DISABLE;
98 sprctl |= SPRITE_ENABLE;
99
100 /* Sizes are 0 based */
101 src_w--;
102 src_h--;
103 crtc_w--;
104 crtc_h--;
105
106 intel_update_sprite_watermarks(dev, pipe, crtc_w, pixel_size);
107
108 /*
109 * IVB workaround: must disable low power watermarks for at least
110 * one frame before enabling scaling. LP watermarks can be re-enabled
111 * when scaling is disabled.
112 */
113 if (crtc_w != src_w || crtc_h != src_h) {
Chris Wilson828ed3e2012-04-18 17:12:26 +0100114 if (!dev_priv->sprite_scaling_enabled) {
115 dev_priv->sprite_scaling_enabled = true;
116 intel_update_watermarks(dev);
117 intel_wait_for_vblank(dev, pipe);
118 }
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800119 sprscale = SPRITE_SCALE_ENABLE | (src_w << 16) | src_h;
120 } else {
Chris Wilson828ed3e2012-04-18 17:12:26 +0100121 if (dev_priv->sprite_scaling_enabled) {
122 dev_priv->sprite_scaling_enabled = false;
123 /* potentially re-enable LP watermarks */
124 intel_update_watermarks(dev);
125 }
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800126 }
127
128 I915_WRITE(SPRSTRIDE(pipe), fb->pitches[0]);
129 I915_WRITE(SPRPOS(pipe), (crtc_y << 16) | crtc_x);
130 if (obj->tiling_mode != I915_TILING_NONE) {
131 I915_WRITE(SPRTILEOFF(pipe), (y << 16) | x);
132 } else {
133 unsigned long offset;
134
135 offset = y * fb->pitches[0] + x * (fb->bits_per_pixel / 8);
136 I915_WRITE(SPRLINOFF(pipe), offset);
137 }
138 I915_WRITE(SPRSIZE(pipe), (crtc_h << 16) | crtc_w);
139 I915_WRITE(SPRSCALE(pipe), sprscale);
140 I915_WRITE(SPRCTL(pipe), sprctl);
Armin Reese446f2542012-03-30 16:20:16 -0700141 I915_MODIFY_DISPBASE(SPRSURF(pipe), obj->gtt_offset);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800142 POSTING_READ(SPRSURF(pipe));
143}
144
145static void
146ivb_disable_plane(struct drm_plane *plane)
147{
148 struct drm_device *dev = plane->dev;
149 struct drm_i915_private *dev_priv = dev->dev_private;
150 struct intel_plane *intel_plane = to_intel_plane(plane);
151 int pipe = intel_plane->pipe;
152
153 I915_WRITE(SPRCTL(pipe), I915_READ(SPRCTL(pipe)) & ~SPRITE_ENABLE);
154 /* Can't leave the scaler enabled... */
155 I915_WRITE(SPRSCALE(pipe), 0);
156 /* Activate double buffered register update */
Armin Reese446f2542012-03-30 16:20:16 -0700157 I915_MODIFY_DISPBASE(SPRSURF(pipe), 0);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800158 POSTING_READ(SPRSURF(pipe));
Chris Wilson828ed3e2012-04-18 17:12:26 +0100159
160 dev_priv->sprite_scaling_enabled = false;
161 intel_update_watermarks(dev);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800162}
163
Jesse Barnes8ea30862012-01-03 08:05:39 -0800164static int
165ivb_update_colorkey(struct drm_plane *plane,
166 struct drm_intel_sprite_colorkey *key)
167{
168 struct drm_device *dev = plane->dev;
169 struct drm_i915_private *dev_priv = dev->dev_private;
170 struct intel_plane *intel_plane;
171 u32 sprctl;
172 int ret = 0;
173
174 intel_plane = to_intel_plane(plane);
175
176 I915_WRITE(SPRKEYVAL(intel_plane->pipe), key->min_value);
177 I915_WRITE(SPRKEYMAX(intel_plane->pipe), key->max_value);
178 I915_WRITE(SPRKEYMSK(intel_plane->pipe), key->channel_mask);
179
180 sprctl = I915_READ(SPRCTL(intel_plane->pipe));
181 sprctl &= ~(SPRITE_SOURCE_KEY | SPRITE_DEST_KEY);
182 if (key->flags & I915_SET_COLORKEY_DESTINATION)
183 sprctl |= SPRITE_DEST_KEY;
184 else if (key->flags & I915_SET_COLORKEY_SOURCE)
185 sprctl |= SPRITE_SOURCE_KEY;
186 I915_WRITE(SPRCTL(intel_plane->pipe), sprctl);
187
188 POSTING_READ(SPRKEYMSK(intel_plane->pipe));
189
190 return ret;
191}
192
193static void
194ivb_get_colorkey(struct drm_plane *plane, struct drm_intel_sprite_colorkey *key)
195{
196 struct drm_device *dev = plane->dev;
197 struct drm_i915_private *dev_priv = dev->dev_private;
198 struct intel_plane *intel_plane;
199 u32 sprctl;
200
201 intel_plane = to_intel_plane(plane);
202
203 key->min_value = I915_READ(SPRKEYVAL(intel_plane->pipe));
204 key->max_value = I915_READ(SPRKEYMAX(intel_plane->pipe));
205 key->channel_mask = I915_READ(SPRKEYMSK(intel_plane->pipe));
206 key->flags = 0;
207
208 sprctl = I915_READ(SPRCTL(intel_plane->pipe));
209
210 if (sprctl & SPRITE_DEST_KEY)
211 key->flags = I915_SET_COLORKEY_DESTINATION;
212 else if (sprctl & SPRITE_SOURCE_KEY)
213 key->flags = I915_SET_COLORKEY_SOURCE;
214 else
215 key->flags = I915_SET_COLORKEY_NONE;
216}
217
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800218static void
Chris Wilsond1686ae2012-04-10 11:41:49 +0100219ilk_update_plane(struct drm_plane *plane, struct drm_framebuffer *fb,
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800220 struct drm_i915_gem_object *obj, int crtc_x, int crtc_y,
221 unsigned int crtc_w, unsigned int crtc_h,
222 uint32_t x, uint32_t y,
223 uint32_t src_w, uint32_t src_h)
224{
225 struct drm_device *dev = plane->dev;
226 struct drm_i915_private *dev_priv = dev->dev_private;
227 struct intel_plane *intel_plane = to_intel_plane(plane);
228 int pipe = intel_plane->pipe, pixel_size;
Chris Wilson8aaa81a2012-04-14 22:14:26 +0100229 u32 dvscntr, dvsscale;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800230
231 dvscntr = I915_READ(DVSCNTR(pipe));
232
233 /* Mask out pixel format bits in case we change it */
234 dvscntr &= ~DVS_PIXFORMAT_MASK;
Jesse Barnesab2f9df2012-02-27 12:40:10 -0800235 dvscntr &= ~DVS_RGB_ORDER_XBGR;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800236 dvscntr &= ~DVS_YUV_BYTE_ORDER_MASK;
237
238 switch (fb->pixel_format) {
239 case DRM_FORMAT_XBGR8888:
Jesse Barnesab2f9df2012-02-27 12:40:10 -0800240 dvscntr |= DVS_FORMAT_RGBX888 | DVS_RGB_ORDER_XBGR;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800241 pixel_size = 4;
242 break;
243 case DRM_FORMAT_XRGB8888:
Jesse Barnesab2f9df2012-02-27 12:40:10 -0800244 dvscntr |= DVS_FORMAT_RGBX888;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800245 pixel_size = 4;
246 break;
247 case DRM_FORMAT_YUYV:
248 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YUYV;
249 pixel_size = 2;
250 break;
251 case DRM_FORMAT_YVYU:
252 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YVYU;
253 pixel_size = 2;
254 break;
255 case DRM_FORMAT_UYVY:
256 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_UYVY;
257 pixel_size = 2;
258 break;
259 case DRM_FORMAT_VYUY:
260 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_VYUY;
261 pixel_size = 2;
262 break;
263 default:
264 DRM_DEBUG_DRIVER("bad pixel format, assuming RGBX888\n");
265 dvscntr |= DVS_FORMAT_RGBX888;
266 pixel_size = 4;
267 break;
268 }
269
270 if (obj->tiling_mode != I915_TILING_NONE)
271 dvscntr |= DVS_TILED;
272
Chris Wilsond1686ae2012-04-10 11:41:49 +0100273 if (IS_GEN6(dev))
274 dvscntr |= DVS_TRICKLE_FEED_DISABLE; /* must disable */
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800275 dvscntr |= DVS_ENABLE;
276
277 /* Sizes are 0 based */
278 src_w--;
279 src_h--;
280 crtc_w--;
281 crtc_h--;
282
283 intel_update_sprite_watermarks(dev, pipe, crtc_w, pixel_size);
284
Chris Wilson8aaa81a2012-04-14 22:14:26 +0100285 dvsscale = 0;
286 if (IS_GEN5(dev) || crtc_w != src_w || crtc_h != src_h)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800287 dvsscale = DVS_SCALE_ENABLE | (src_w << 16) | src_h;
288
289 I915_WRITE(DVSSTRIDE(pipe), fb->pitches[0]);
290 I915_WRITE(DVSPOS(pipe), (crtc_y << 16) | crtc_x);
291 if (obj->tiling_mode != I915_TILING_NONE) {
292 I915_WRITE(DVSTILEOFF(pipe), (y << 16) | x);
293 } else {
294 unsigned long offset;
295
296 offset = y * fb->pitches[0] + x * (fb->bits_per_pixel / 8);
297 I915_WRITE(DVSLINOFF(pipe), offset);
298 }
299 I915_WRITE(DVSSIZE(pipe), (crtc_h << 16) | crtc_w);
300 I915_WRITE(DVSSCALE(pipe), dvsscale);
301 I915_WRITE(DVSCNTR(pipe), dvscntr);
Armin Reese446f2542012-03-30 16:20:16 -0700302 I915_MODIFY_DISPBASE(DVSSURF(pipe), obj->gtt_offset);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800303 POSTING_READ(DVSSURF(pipe));
304}
305
306static void
Chris Wilsond1686ae2012-04-10 11:41:49 +0100307ilk_disable_plane(struct drm_plane *plane)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800308{
309 struct drm_device *dev = plane->dev;
310 struct drm_i915_private *dev_priv = dev->dev_private;
311 struct intel_plane *intel_plane = to_intel_plane(plane);
312 int pipe = intel_plane->pipe;
313
314 I915_WRITE(DVSCNTR(pipe), I915_READ(DVSCNTR(pipe)) & ~DVS_ENABLE);
315 /* Disable the scaler */
316 I915_WRITE(DVSSCALE(pipe), 0);
317 /* Flush double buffered register updates */
Armin Reese446f2542012-03-30 16:20:16 -0700318 I915_MODIFY_DISPBASE(DVSSURF(pipe), 0);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800319 POSTING_READ(DVSSURF(pipe));
320}
321
Jesse Barnes175bd422011-12-13 13:19:39 -0800322static void
323intel_enable_primary(struct drm_crtc *crtc)
324{
325 struct drm_device *dev = crtc->dev;
326 struct drm_i915_private *dev_priv = dev->dev_private;
327 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
328 int reg = DSPCNTR(intel_crtc->plane);
329
Chris Wilson93314b52012-06-13 17:36:55 +0100330 if (!intel_crtc->primary_disabled)
331 return;
332
333 intel_crtc->primary_disabled = false;
334 intel_update_fbc(dev);
335
Jesse Barnes175bd422011-12-13 13:19:39 -0800336 I915_WRITE(reg, I915_READ(reg) | DISPLAY_PLANE_ENABLE);
337}
338
339static void
340intel_disable_primary(struct drm_crtc *crtc)
341{
342 struct drm_device *dev = crtc->dev;
343 struct drm_i915_private *dev_priv = dev->dev_private;
344 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
345 int reg = DSPCNTR(intel_crtc->plane);
346
Chris Wilson93314b52012-06-13 17:36:55 +0100347 if (intel_crtc->primary_disabled)
348 return;
349
Jesse Barnes175bd422011-12-13 13:19:39 -0800350 I915_WRITE(reg, I915_READ(reg) & ~DISPLAY_PLANE_ENABLE);
Chris Wilson93314b52012-06-13 17:36:55 +0100351
352 intel_crtc->primary_disabled = true;
353 intel_update_fbc(dev);
Jesse Barnes175bd422011-12-13 13:19:39 -0800354}
355
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800356static int
Chris Wilsond1686ae2012-04-10 11:41:49 +0100357ilk_update_colorkey(struct drm_plane *plane,
Jesse Barnes8ea30862012-01-03 08:05:39 -0800358 struct drm_intel_sprite_colorkey *key)
359{
360 struct drm_device *dev = plane->dev;
361 struct drm_i915_private *dev_priv = dev->dev_private;
362 struct intel_plane *intel_plane;
363 u32 dvscntr;
364 int ret = 0;
365
366 intel_plane = to_intel_plane(plane);
367
368 I915_WRITE(DVSKEYVAL(intel_plane->pipe), key->min_value);
369 I915_WRITE(DVSKEYMAX(intel_plane->pipe), key->max_value);
370 I915_WRITE(DVSKEYMSK(intel_plane->pipe), key->channel_mask);
371
372 dvscntr = I915_READ(DVSCNTR(intel_plane->pipe));
373 dvscntr &= ~(DVS_SOURCE_KEY | DVS_DEST_KEY);
374 if (key->flags & I915_SET_COLORKEY_DESTINATION)
375 dvscntr |= DVS_DEST_KEY;
376 else if (key->flags & I915_SET_COLORKEY_SOURCE)
377 dvscntr |= DVS_SOURCE_KEY;
378 I915_WRITE(DVSCNTR(intel_plane->pipe), dvscntr);
379
380 POSTING_READ(DVSKEYMSK(intel_plane->pipe));
381
382 return ret;
383}
384
385static void
Chris Wilsond1686ae2012-04-10 11:41:49 +0100386ilk_get_colorkey(struct drm_plane *plane, struct drm_intel_sprite_colorkey *key)
Jesse Barnes8ea30862012-01-03 08:05:39 -0800387{
388 struct drm_device *dev = plane->dev;
389 struct drm_i915_private *dev_priv = dev->dev_private;
390 struct intel_plane *intel_plane;
391 u32 dvscntr;
392
393 intel_plane = to_intel_plane(plane);
394
395 key->min_value = I915_READ(DVSKEYVAL(intel_plane->pipe));
396 key->max_value = I915_READ(DVSKEYMAX(intel_plane->pipe));
397 key->channel_mask = I915_READ(DVSKEYMSK(intel_plane->pipe));
398 key->flags = 0;
399
400 dvscntr = I915_READ(DVSCNTR(intel_plane->pipe));
401
402 if (dvscntr & DVS_DEST_KEY)
403 key->flags = I915_SET_COLORKEY_DESTINATION;
404 else if (dvscntr & DVS_SOURCE_KEY)
405 key->flags = I915_SET_COLORKEY_SOURCE;
406 else
407 key->flags = I915_SET_COLORKEY_NONE;
408}
409
410static int
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800411intel_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
412 struct drm_framebuffer *fb, int crtc_x, int crtc_y,
413 unsigned int crtc_w, unsigned int crtc_h,
414 uint32_t src_x, uint32_t src_y,
415 uint32_t src_w, uint32_t src_h)
416{
417 struct drm_device *dev = plane->dev;
418 struct drm_i915_private *dev_priv = dev->dev_private;
419 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
420 struct intel_plane *intel_plane = to_intel_plane(plane);
421 struct intel_framebuffer *intel_fb;
422 struct drm_i915_gem_object *obj, *old_obj;
423 int pipe = intel_plane->pipe;
424 int ret = 0;
425 int x = src_x >> 16, y = src_y >> 16;
426 int primary_w = crtc->mode.hdisplay, primary_h = crtc->mode.vdisplay;
427 bool disable_primary = false;
428
429 intel_fb = to_intel_framebuffer(fb);
430 obj = intel_fb->obj;
431
432 old_obj = intel_plane->obj;
433
Jesse Barnesb4db1e32012-03-20 10:59:09 -0700434 src_w = src_w >> 16;
435 src_h = src_h >> 16;
436
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800437 /* Pipe must be running... */
438 if (!(I915_READ(PIPECONF(pipe)) & PIPECONF_ENABLE))
439 return -EINVAL;
440
441 if (crtc_x >= primary_w || crtc_y >= primary_h)
442 return -EINVAL;
443
444 /* Don't modify another pipe's plane */
445 if (intel_plane->pipe != intel_crtc->pipe)
446 return -EINVAL;
447
448 /*
449 * Clamp the width & height into the visible area. Note we don't
450 * try to scale the source if part of the visible region is offscreen.
451 * The caller must handle that by adjusting source offset and size.
452 */
453 if ((crtc_x < 0) && ((crtc_x + crtc_w) > 0)) {
454 crtc_w += crtc_x;
455 crtc_x = 0;
456 }
457 if ((crtc_x + crtc_w) <= 0) /* Nothing to display */
458 goto out;
459 if ((crtc_x + crtc_w) > primary_w)
460 crtc_w = primary_w - crtc_x;
461
462 if ((crtc_y < 0) && ((crtc_y + crtc_h) > 0)) {
463 crtc_h += crtc_y;
464 crtc_y = 0;
465 }
466 if ((crtc_y + crtc_h) <= 0) /* Nothing to display */
467 goto out;
468 if (crtc_y + crtc_h > primary_h)
469 crtc_h = primary_h - crtc_y;
470
471 if (!crtc_w || !crtc_h) /* Again, nothing to display */
472 goto out;
473
474 /*
475 * We can take a larger source and scale it down, but
476 * only so much... 16x is the max on SNB.
477 */
478 if (((src_w * src_h) / (crtc_w * crtc_h)) > intel_plane->max_downscale)
479 return -EINVAL;
480
481 /*
482 * If the sprite is completely covering the primary plane,
483 * we can disable the primary and save power.
484 */
485 if ((crtc_x == 0) && (crtc_y == 0) &&
486 (crtc_w == primary_w) && (crtc_h == primary_h))
487 disable_primary = true;
488
489 mutex_lock(&dev->struct_mutex);
490
491 ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
Jesse Barnes00c2064b2012-01-13 15:48:39 -0800492 if (ret)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800493 goto out_unlock;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800494
495 intel_plane->obj = obj;
496
Jesse Barnes175bd422011-12-13 13:19:39 -0800497 /*
498 * Be sure to re-enable the primary before the sprite is no longer
499 * covering it fully.
500 */
Chris Wilson93314b52012-06-13 17:36:55 +0100501 if (!disable_primary)
Jesse Barnes175bd422011-12-13 13:19:39 -0800502 intel_enable_primary(crtc);
Jesse Barnes175bd422011-12-13 13:19:39 -0800503
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800504 intel_plane->update_plane(plane, fb, obj, crtc_x, crtc_y,
505 crtc_w, crtc_h, x, y, src_w, src_h);
506
Chris Wilson93314b52012-06-13 17:36:55 +0100507 if (disable_primary)
Jesse Barnes175bd422011-12-13 13:19:39 -0800508 intel_disable_primary(crtc);
Jesse Barnes175bd422011-12-13 13:19:39 -0800509
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800510 /* Unpin old obj after new one is active to avoid ugliness */
511 if (old_obj) {
512 /*
513 * It's fairly common to simply update the position of
514 * an existing object. In that case, we don't need to
515 * wait for vblank to avoid ugliness, we only need to
516 * do the pin & ref bookkeeping.
517 */
518 if (old_obj != obj) {
519 mutex_unlock(&dev->struct_mutex);
520 intel_wait_for_vblank(dev, to_intel_crtc(crtc)->pipe);
521 mutex_lock(&dev->struct_mutex);
522 }
Chris Wilson1690e1e2011-12-14 13:57:08 +0100523 intel_unpin_fb_obj(old_obj);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800524 }
525
526out_unlock:
527 mutex_unlock(&dev->struct_mutex);
528out:
529 return ret;
530}
531
532static int
533intel_disable_plane(struct drm_plane *plane)
534{
535 struct drm_device *dev = plane->dev;
536 struct intel_plane *intel_plane = to_intel_plane(plane);
537 int ret = 0;
538
Chris Wilson93314b52012-06-13 17:36:55 +0100539 if (plane->crtc)
Jesse Barnes175bd422011-12-13 13:19:39 -0800540 intel_enable_primary(plane->crtc);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800541 intel_plane->disable_plane(plane);
542
543 if (!intel_plane->obj)
544 goto out;
545
546 mutex_lock(&dev->struct_mutex);
Chris Wilson1690e1e2011-12-14 13:57:08 +0100547 intel_unpin_fb_obj(intel_plane->obj);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800548 intel_plane->obj = NULL;
549 mutex_unlock(&dev->struct_mutex);
550out:
551
552 return ret;
553}
554
555static void intel_destroy_plane(struct drm_plane *plane)
556{
557 struct intel_plane *intel_plane = to_intel_plane(plane);
558 intel_disable_plane(plane);
559 drm_plane_cleanup(plane);
560 kfree(intel_plane);
561}
562
Jesse Barnes8ea30862012-01-03 08:05:39 -0800563int intel_sprite_set_colorkey(struct drm_device *dev, void *data,
564 struct drm_file *file_priv)
565{
566 struct drm_intel_sprite_colorkey *set = data;
Jesse Barnes8ea30862012-01-03 08:05:39 -0800567 struct drm_mode_object *obj;
568 struct drm_plane *plane;
569 struct intel_plane *intel_plane;
570 int ret = 0;
571
Daniel Vetter1cff8f62012-04-24 09:55:08 +0200572 if (!drm_core_check_feature(dev, DRIVER_MODESET))
573 return -ENODEV;
Jesse Barnes8ea30862012-01-03 08:05:39 -0800574
575 /* Make sure we don't try to enable both src & dest simultaneously */
576 if ((set->flags & (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE)) == (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE))
577 return -EINVAL;
578
579 mutex_lock(&dev->mode_config.mutex);
580
581 obj = drm_mode_object_find(dev, set->plane_id, DRM_MODE_OBJECT_PLANE);
582 if (!obj) {
583 ret = -EINVAL;
584 goto out_unlock;
585 }
586
587 plane = obj_to_plane(obj);
588 intel_plane = to_intel_plane(plane);
589 ret = intel_plane->update_colorkey(plane, set);
590
591out_unlock:
592 mutex_unlock(&dev->mode_config.mutex);
593 return ret;
594}
595
596int intel_sprite_get_colorkey(struct drm_device *dev, void *data,
597 struct drm_file *file_priv)
598{
599 struct drm_intel_sprite_colorkey *get = data;
Jesse Barnes8ea30862012-01-03 08:05:39 -0800600 struct drm_mode_object *obj;
601 struct drm_plane *plane;
602 struct intel_plane *intel_plane;
603 int ret = 0;
604
Daniel Vetter1cff8f62012-04-24 09:55:08 +0200605 if (!drm_core_check_feature(dev, DRIVER_MODESET))
606 return -ENODEV;
Jesse Barnes8ea30862012-01-03 08:05:39 -0800607
608 mutex_lock(&dev->mode_config.mutex);
609
610 obj = drm_mode_object_find(dev, get->plane_id, DRM_MODE_OBJECT_PLANE);
611 if (!obj) {
612 ret = -EINVAL;
613 goto out_unlock;
614 }
615
616 plane = obj_to_plane(obj);
617 intel_plane = to_intel_plane(plane);
618 intel_plane->get_colorkey(plane, get);
619
620out_unlock:
621 mutex_unlock(&dev->mode_config.mutex);
622 return ret;
623}
624
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800625static const struct drm_plane_funcs intel_plane_funcs = {
626 .update_plane = intel_update_plane,
627 .disable_plane = intel_disable_plane,
628 .destroy = intel_destroy_plane,
629};
630
Chris Wilsond1686ae2012-04-10 11:41:49 +0100631static uint32_t ilk_plane_formats[] = {
632 DRM_FORMAT_XRGB8888,
633 DRM_FORMAT_YUYV,
634 DRM_FORMAT_YVYU,
635 DRM_FORMAT_UYVY,
636 DRM_FORMAT_VYUY,
637};
638
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800639static uint32_t snb_plane_formats[] = {
640 DRM_FORMAT_XBGR8888,
641 DRM_FORMAT_XRGB8888,
642 DRM_FORMAT_YUYV,
643 DRM_FORMAT_YVYU,
644 DRM_FORMAT_UYVY,
645 DRM_FORMAT_VYUY,
646};
647
648int
649intel_plane_init(struct drm_device *dev, enum pipe pipe)
650{
651 struct intel_plane *intel_plane;
652 unsigned long possible_crtcs;
Chris Wilsond1686ae2012-04-10 11:41:49 +0100653 const uint32_t *plane_formats;
654 int num_plane_formats;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800655 int ret;
656
Chris Wilsond1686ae2012-04-10 11:41:49 +0100657 if (INTEL_INFO(dev)->gen < 5)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800658 return -ENODEV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800659
660 intel_plane = kzalloc(sizeof(struct intel_plane), GFP_KERNEL);
661 if (!intel_plane)
662 return -ENOMEM;
663
Chris Wilsond1686ae2012-04-10 11:41:49 +0100664 switch (INTEL_INFO(dev)->gen) {
665 case 5:
666 case 6:
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800667 intel_plane->max_downscale = 16;
Chris Wilsond1686ae2012-04-10 11:41:49 +0100668 intel_plane->update_plane = ilk_update_plane;
669 intel_plane->disable_plane = ilk_disable_plane;
670 intel_plane->update_colorkey = ilk_update_colorkey;
671 intel_plane->get_colorkey = ilk_get_colorkey;
672
673 if (IS_GEN6(dev)) {
674 plane_formats = snb_plane_formats;
675 num_plane_formats = ARRAY_SIZE(snb_plane_formats);
676 } else {
677 plane_formats = ilk_plane_formats;
678 num_plane_formats = ARRAY_SIZE(ilk_plane_formats);
679 }
680 break;
681
682 case 7:
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800683 intel_plane->max_downscale = 2;
684 intel_plane->update_plane = ivb_update_plane;
685 intel_plane->disable_plane = ivb_disable_plane;
Jesse Barnes8ea30862012-01-03 08:05:39 -0800686 intel_plane->update_colorkey = ivb_update_colorkey;
687 intel_plane->get_colorkey = ivb_get_colorkey;
Chris Wilsond1686ae2012-04-10 11:41:49 +0100688
689 plane_formats = snb_plane_formats;
690 num_plane_formats = ARRAY_SIZE(snb_plane_formats);
691 break;
692
693 default:
Jesper Juhla8b0bba2012-06-27 00:55:37 +0200694 kfree(intel_plane);
Chris Wilsond1686ae2012-04-10 11:41:49 +0100695 return -ENODEV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800696 }
697
698 intel_plane->pipe = pipe;
699 possible_crtcs = (1 << pipe);
700 ret = drm_plane_init(dev, &intel_plane->base, possible_crtcs,
Chris Wilsond1686ae2012-04-10 11:41:49 +0100701 &intel_plane_funcs,
702 plane_formats, num_plane_formats,
703 false);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800704 if (ret)
705 kfree(intel_plane);
706
707 return ret;
708}