thunderbolt: Use kcalloc
[deliverable/linux.git] / drivers / gpu / drm / i915 / intel_sprite.c
1 /*
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 <drm/drmP.h>
33 #include <drm/drm_crtc.h>
34 #include <drm/drm_fourcc.h>
35 #include <drm/drm_rect.h>
36 #include "intel_drv.h"
37 #include <drm/i915_drm.h>
38 #include "i915_drv.h"
39
40 static int usecs_to_scanlines(const struct drm_display_mode *mode, int usecs)
41 {
42 /* paranoia */
43 if (!mode->crtc_htotal)
44 return 1;
45
46 return DIV_ROUND_UP(usecs * mode->crtc_clock, 1000 * mode->crtc_htotal);
47 }
48
49 static bool intel_pipe_update_start(struct intel_crtc *crtc, uint32_t *start_vbl_count)
50 {
51 struct drm_device *dev = crtc->base.dev;
52 const struct drm_display_mode *mode = &crtc->config.adjusted_mode;
53 enum pipe pipe = crtc->pipe;
54 long timeout = msecs_to_jiffies_timeout(1);
55 int scanline, min, max, vblank_start;
56 DEFINE_WAIT(wait);
57
58 WARN_ON(!drm_modeset_is_locked(&crtc->base.mutex));
59
60 vblank_start = mode->crtc_vblank_start;
61 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
62 vblank_start = DIV_ROUND_UP(vblank_start, 2);
63
64 /* FIXME needs to be calibrated sensibly */
65 min = vblank_start - usecs_to_scanlines(mode, 100);
66 max = vblank_start - 1;
67
68 if (min <= 0 || max <= 0)
69 return false;
70
71 if (WARN_ON(drm_vblank_get(dev, pipe)))
72 return false;
73
74 local_irq_disable();
75
76 trace_i915_pipe_update_start(crtc, min, max);
77
78 for (;;) {
79 /*
80 * prepare_to_wait() has a memory barrier, which guarantees
81 * other CPUs can see the task state update by the time we
82 * read the scanline.
83 */
84 prepare_to_wait(&crtc->vbl_wait, &wait, TASK_UNINTERRUPTIBLE);
85
86 scanline = intel_get_crtc_scanline(crtc);
87 if (scanline < min || scanline > max)
88 break;
89
90 if (timeout <= 0) {
91 DRM_ERROR("Potential atomic update failure on pipe %c\n",
92 pipe_name(crtc->pipe));
93 break;
94 }
95
96 local_irq_enable();
97
98 timeout = schedule_timeout(timeout);
99
100 local_irq_disable();
101 }
102
103 finish_wait(&crtc->vbl_wait, &wait);
104
105 drm_vblank_put(dev, pipe);
106
107 *start_vbl_count = dev->driver->get_vblank_counter(dev, pipe);
108
109 trace_i915_pipe_update_vblank_evaded(crtc, min, max, *start_vbl_count);
110
111 return true;
112 }
113
114 static void intel_pipe_update_end(struct intel_crtc *crtc, u32 start_vbl_count)
115 {
116 struct drm_device *dev = crtc->base.dev;
117 enum pipe pipe = crtc->pipe;
118 u32 end_vbl_count = dev->driver->get_vblank_counter(dev, pipe);
119
120 trace_i915_pipe_update_end(crtc, end_vbl_count);
121
122 local_irq_enable();
123
124 if (start_vbl_count != end_vbl_count)
125 DRM_ERROR("Atomic update failure on pipe %c (start=%u end=%u)\n",
126 pipe_name(pipe), start_vbl_count, end_vbl_count);
127 }
128
129 static void intel_update_primary_plane(struct intel_crtc *crtc)
130 {
131 struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
132 int reg = DSPCNTR(crtc->plane);
133
134 if (crtc->primary_enabled)
135 I915_WRITE(reg, I915_READ(reg) | DISPLAY_PLANE_ENABLE);
136 else
137 I915_WRITE(reg, I915_READ(reg) & ~DISPLAY_PLANE_ENABLE);
138 }
139
140 static void
141 vlv_update_plane(struct drm_plane *dplane, struct drm_crtc *crtc,
142 struct drm_framebuffer *fb,
143 struct drm_i915_gem_object *obj, int crtc_x, int crtc_y,
144 unsigned int crtc_w, unsigned int crtc_h,
145 uint32_t x, uint32_t y,
146 uint32_t src_w, uint32_t src_h)
147 {
148 struct drm_device *dev = dplane->dev;
149 struct drm_i915_private *dev_priv = dev->dev_private;
150 struct intel_plane *intel_plane = to_intel_plane(dplane);
151 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
152 int pipe = intel_plane->pipe;
153 int plane = intel_plane->plane;
154 u32 sprctl;
155 unsigned long sprsurf_offset, linear_offset;
156 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
157 u32 start_vbl_count;
158 bool atomic_update;
159
160 sprctl = I915_READ(SPCNTR(pipe, plane));
161
162 /* Mask out pixel format bits in case we change it */
163 sprctl &= ~SP_PIXFORMAT_MASK;
164 sprctl &= ~SP_YUV_BYTE_ORDER_MASK;
165 sprctl &= ~SP_TILED;
166
167 switch (fb->pixel_format) {
168 case DRM_FORMAT_YUYV:
169 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YUYV;
170 break;
171 case DRM_FORMAT_YVYU:
172 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YVYU;
173 break;
174 case DRM_FORMAT_UYVY:
175 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_UYVY;
176 break;
177 case DRM_FORMAT_VYUY:
178 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_VYUY;
179 break;
180 case DRM_FORMAT_RGB565:
181 sprctl |= SP_FORMAT_BGR565;
182 break;
183 case DRM_FORMAT_XRGB8888:
184 sprctl |= SP_FORMAT_BGRX8888;
185 break;
186 case DRM_FORMAT_ARGB8888:
187 sprctl |= SP_FORMAT_BGRA8888;
188 break;
189 case DRM_FORMAT_XBGR2101010:
190 sprctl |= SP_FORMAT_RGBX1010102;
191 break;
192 case DRM_FORMAT_ABGR2101010:
193 sprctl |= SP_FORMAT_RGBA1010102;
194 break;
195 case DRM_FORMAT_XBGR8888:
196 sprctl |= SP_FORMAT_RGBX8888;
197 break;
198 case DRM_FORMAT_ABGR8888:
199 sprctl |= SP_FORMAT_RGBA8888;
200 break;
201 default:
202 /*
203 * If we get here one of the upper layers failed to filter
204 * out the unsupported plane formats
205 */
206 BUG();
207 break;
208 }
209
210 /*
211 * Enable gamma to match primary/cursor plane behaviour.
212 * FIXME should be user controllable via propertiesa.
213 */
214 sprctl |= SP_GAMMA_ENABLE;
215
216 if (obj->tiling_mode != I915_TILING_NONE)
217 sprctl |= SP_TILED;
218
219 sprctl |= SP_ENABLE;
220
221 intel_update_sprite_watermarks(dplane, crtc, src_w, pixel_size, true,
222 src_w != crtc_w || src_h != crtc_h);
223
224 /* Sizes are 0 based */
225 src_w--;
226 src_h--;
227 crtc_w--;
228 crtc_h--;
229
230 linear_offset = y * fb->pitches[0] + x * pixel_size;
231 sprsurf_offset = intel_gen4_compute_page_offset(&x, &y,
232 obj->tiling_mode,
233 pixel_size,
234 fb->pitches[0]);
235 linear_offset -= sprsurf_offset;
236
237 atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count);
238
239 intel_update_primary_plane(intel_crtc);
240
241 I915_WRITE(SPSTRIDE(pipe, plane), fb->pitches[0]);
242 I915_WRITE(SPPOS(pipe, plane), (crtc_y << 16) | crtc_x);
243
244 if (obj->tiling_mode != I915_TILING_NONE)
245 I915_WRITE(SPTILEOFF(pipe, plane), (y << 16) | x);
246 else
247 I915_WRITE(SPLINOFF(pipe, plane), linear_offset);
248
249 I915_WRITE(SPSIZE(pipe, plane), (crtc_h << 16) | crtc_w);
250 I915_WRITE(SPCNTR(pipe, plane), sprctl);
251 I915_WRITE(SPSURF(pipe, plane), i915_gem_obj_ggtt_offset(obj) +
252 sprsurf_offset);
253
254 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
255
256 if (atomic_update)
257 intel_pipe_update_end(intel_crtc, start_vbl_count);
258 }
259
260 static void
261 vlv_disable_plane(struct drm_plane *dplane, struct drm_crtc *crtc)
262 {
263 struct drm_device *dev = dplane->dev;
264 struct drm_i915_private *dev_priv = dev->dev_private;
265 struct intel_plane *intel_plane = to_intel_plane(dplane);
266 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
267 int pipe = intel_plane->pipe;
268 int plane = intel_plane->plane;
269 u32 start_vbl_count;
270 bool atomic_update;
271
272 atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count);
273
274 intel_update_primary_plane(intel_crtc);
275
276 I915_WRITE(SPCNTR(pipe, plane), I915_READ(SPCNTR(pipe, plane)) &
277 ~SP_ENABLE);
278 /* Activate double buffered register update */
279 I915_WRITE(SPSURF(pipe, plane), 0);
280
281 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
282
283 if (atomic_update)
284 intel_pipe_update_end(intel_crtc, start_vbl_count);
285
286 intel_update_sprite_watermarks(dplane, crtc, 0, 0, false, false);
287 }
288
289 static int
290 vlv_update_colorkey(struct drm_plane *dplane,
291 struct drm_intel_sprite_colorkey *key)
292 {
293 struct drm_device *dev = dplane->dev;
294 struct drm_i915_private *dev_priv = dev->dev_private;
295 struct intel_plane *intel_plane = to_intel_plane(dplane);
296 int pipe = intel_plane->pipe;
297 int plane = intel_plane->plane;
298 u32 sprctl;
299
300 if (key->flags & I915_SET_COLORKEY_DESTINATION)
301 return -EINVAL;
302
303 I915_WRITE(SPKEYMINVAL(pipe, plane), key->min_value);
304 I915_WRITE(SPKEYMAXVAL(pipe, plane), key->max_value);
305 I915_WRITE(SPKEYMSK(pipe, plane), key->channel_mask);
306
307 sprctl = I915_READ(SPCNTR(pipe, plane));
308 sprctl &= ~SP_SOURCE_KEY;
309 if (key->flags & I915_SET_COLORKEY_SOURCE)
310 sprctl |= SP_SOURCE_KEY;
311 I915_WRITE(SPCNTR(pipe, plane), sprctl);
312
313 POSTING_READ(SPKEYMSK(pipe, plane));
314
315 return 0;
316 }
317
318 static void
319 vlv_get_colorkey(struct drm_plane *dplane,
320 struct drm_intel_sprite_colorkey *key)
321 {
322 struct drm_device *dev = dplane->dev;
323 struct drm_i915_private *dev_priv = dev->dev_private;
324 struct intel_plane *intel_plane = to_intel_plane(dplane);
325 int pipe = intel_plane->pipe;
326 int plane = intel_plane->plane;
327 u32 sprctl;
328
329 key->min_value = I915_READ(SPKEYMINVAL(pipe, plane));
330 key->max_value = I915_READ(SPKEYMAXVAL(pipe, plane));
331 key->channel_mask = I915_READ(SPKEYMSK(pipe, plane));
332
333 sprctl = I915_READ(SPCNTR(pipe, plane));
334 if (sprctl & SP_SOURCE_KEY)
335 key->flags = I915_SET_COLORKEY_SOURCE;
336 else
337 key->flags = I915_SET_COLORKEY_NONE;
338 }
339
340 static void
341 ivb_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
342 struct drm_framebuffer *fb,
343 struct drm_i915_gem_object *obj, int crtc_x, int crtc_y,
344 unsigned int crtc_w, unsigned int crtc_h,
345 uint32_t x, uint32_t y,
346 uint32_t src_w, uint32_t src_h)
347 {
348 struct drm_device *dev = plane->dev;
349 struct drm_i915_private *dev_priv = dev->dev_private;
350 struct intel_plane *intel_plane = to_intel_plane(plane);
351 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
352 int pipe = intel_plane->pipe;
353 u32 sprctl, sprscale = 0;
354 unsigned long sprsurf_offset, linear_offset;
355 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
356 u32 start_vbl_count;
357 bool atomic_update;
358
359 sprctl = I915_READ(SPRCTL(pipe));
360
361 /* Mask out pixel format bits in case we change it */
362 sprctl &= ~SPRITE_PIXFORMAT_MASK;
363 sprctl &= ~SPRITE_RGB_ORDER_RGBX;
364 sprctl &= ~SPRITE_YUV_BYTE_ORDER_MASK;
365 sprctl &= ~SPRITE_TILED;
366
367 switch (fb->pixel_format) {
368 case DRM_FORMAT_XBGR8888:
369 sprctl |= SPRITE_FORMAT_RGBX888 | SPRITE_RGB_ORDER_RGBX;
370 break;
371 case DRM_FORMAT_XRGB8888:
372 sprctl |= SPRITE_FORMAT_RGBX888;
373 break;
374 case DRM_FORMAT_YUYV:
375 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YUYV;
376 break;
377 case DRM_FORMAT_YVYU:
378 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YVYU;
379 break;
380 case DRM_FORMAT_UYVY:
381 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_UYVY;
382 break;
383 case DRM_FORMAT_VYUY:
384 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_VYUY;
385 break;
386 default:
387 BUG();
388 }
389
390 /*
391 * Enable gamma to match primary/cursor plane behaviour.
392 * FIXME should be user controllable via propertiesa.
393 */
394 sprctl |= SPRITE_GAMMA_ENABLE;
395
396 if (obj->tiling_mode != I915_TILING_NONE)
397 sprctl |= SPRITE_TILED;
398
399 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
400 sprctl &= ~SPRITE_TRICKLE_FEED_DISABLE;
401 else
402 sprctl |= SPRITE_TRICKLE_FEED_DISABLE;
403
404 sprctl |= SPRITE_ENABLE;
405
406 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
407 sprctl |= SPRITE_PIPE_CSC_ENABLE;
408
409 intel_update_sprite_watermarks(plane, crtc, src_w, pixel_size, true,
410 src_w != crtc_w || src_h != crtc_h);
411
412 /* Sizes are 0 based */
413 src_w--;
414 src_h--;
415 crtc_w--;
416 crtc_h--;
417
418 if (crtc_w != src_w || crtc_h != src_h)
419 sprscale = SPRITE_SCALE_ENABLE | (src_w << 16) | src_h;
420
421 linear_offset = y * fb->pitches[0] + x * pixel_size;
422 sprsurf_offset =
423 intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
424 pixel_size, fb->pitches[0]);
425 linear_offset -= sprsurf_offset;
426
427 atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count);
428
429 intel_update_primary_plane(intel_crtc);
430
431 I915_WRITE(SPRSTRIDE(pipe), fb->pitches[0]);
432 I915_WRITE(SPRPOS(pipe), (crtc_y << 16) | crtc_x);
433
434 /* HSW consolidates SPRTILEOFF and SPRLINOFF into a single SPROFFSET
435 * register */
436 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
437 I915_WRITE(SPROFFSET(pipe), (y << 16) | x);
438 else if (obj->tiling_mode != I915_TILING_NONE)
439 I915_WRITE(SPRTILEOFF(pipe), (y << 16) | x);
440 else
441 I915_WRITE(SPRLINOFF(pipe), linear_offset);
442
443 I915_WRITE(SPRSIZE(pipe), (crtc_h << 16) | crtc_w);
444 if (intel_plane->can_scale)
445 I915_WRITE(SPRSCALE(pipe), sprscale);
446 I915_WRITE(SPRCTL(pipe), sprctl);
447 I915_WRITE(SPRSURF(pipe),
448 i915_gem_obj_ggtt_offset(obj) + sprsurf_offset);
449
450 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
451
452 if (atomic_update)
453 intel_pipe_update_end(intel_crtc, start_vbl_count);
454 }
455
456 static void
457 ivb_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc)
458 {
459 struct drm_device *dev = plane->dev;
460 struct drm_i915_private *dev_priv = dev->dev_private;
461 struct intel_plane *intel_plane = to_intel_plane(plane);
462 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
463 int pipe = intel_plane->pipe;
464 u32 start_vbl_count;
465 bool atomic_update;
466
467 atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count);
468
469 intel_update_primary_plane(intel_crtc);
470
471 I915_WRITE(SPRCTL(pipe), I915_READ(SPRCTL(pipe)) & ~SPRITE_ENABLE);
472 /* Can't leave the scaler enabled... */
473 if (intel_plane->can_scale)
474 I915_WRITE(SPRSCALE(pipe), 0);
475 /* Activate double buffered register update */
476 I915_WRITE(SPRSURF(pipe), 0);
477
478 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
479
480 if (atomic_update)
481 intel_pipe_update_end(intel_crtc, start_vbl_count);
482
483 /*
484 * Avoid underruns when disabling the sprite.
485 * FIXME remove once watermark updates are done properly.
486 */
487 intel_wait_for_vblank(dev, pipe);
488
489 intel_update_sprite_watermarks(plane, crtc, 0, 0, false, false);
490 }
491
492 static int
493 ivb_update_colorkey(struct drm_plane *plane,
494 struct drm_intel_sprite_colorkey *key)
495 {
496 struct drm_device *dev = plane->dev;
497 struct drm_i915_private *dev_priv = dev->dev_private;
498 struct intel_plane *intel_plane;
499 u32 sprctl;
500 int ret = 0;
501
502 intel_plane = to_intel_plane(plane);
503
504 I915_WRITE(SPRKEYVAL(intel_plane->pipe), key->min_value);
505 I915_WRITE(SPRKEYMAX(intel_plane->pipe), key->max_value);
506 I915_WRITE(SPRKEYMSK(intel_plane->pipe), key->channel_mask);
507
508 sprctl = I915_READ(SPRCTL(intel_plane->pipe));
509 sprctl &= ~(SPRITE_SOURCE_KEY | SPRITE_DEST_KEY);
510 if (key->flags & I915_SET_COLORKEY_DESTINATION)
511 sprctl |= SPRITE_DEST_KEY;
512 else if (key->flags & I915_SET_COLORKEY_SOURCE)
513 sprctl |= SPRITE_SOURCE_KEY;
514 I915_WRITE(SPRCTL(intel_plane->pipe), sprctl);
515
516 POSTING_READ(SPRKEYMSK(intel_plane->pipe));
517
518 return ret;
519 }
520
521 static void
522 ivb_get_colorkey(struct drm_plane *plane, struct drm_intel_sprite_colorkey *key)
523 {
524 struct drm_device *dev = plane->dev;
525 struct drm_i915_private *dev_priv = dev->dev_private;
526 struct intel_plane *intel_plane;
527 u32 sprctl;
528
529 intel_plane = to_intel_plane(plane);
530
531 key->min_value = I915_READ(SPRKEYVAL(intel_plane->pipe));
532 key->max_value = I915_READ(SPRKEYMAX(intel_plane->pipe));
533 key->channel_mask = I915_READ(SPRKEYMSK(intel_plane->pipe));
534 key->flags = 0;
535
536 sprctl = I915_READ(SPRCTL(intel_plane->pipe));
537
538 if (sprctl & SPRITE_DEST_KEY)
539 key->flags = I915_SET_COLORKEY_DESTINATION;
540 else if (sprctl & SPRITE_SOURCE_KEY)
541 key->flags = I915_SET_COLORKEY_SOURCE;
542 else
543 key->flags = I915_SET_COLORKEY_NONE;
544 }
545
546 static void
547 ilk_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
548 struct drm_framebuffer *fb,
549 struct drm_i915_gem_object *obj, int crtc_x, int crtc_y,
550 unsigned int crtc_w, unsigned int crtc_h,
551 uint32_t x, uint32_t y,
552 uint32_t src_w, uint32_t src_h)
553 {
554 struct drm_device *dev = plane->dev;
555 struct drm_i915_private *dev_priv = dev->dev_private;
556 struct intel_plane *intel_plane = to_intel_plane(plane);
557 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
558 int pipe = intel_plane->pipe;
559 unsigned long dvssurf_offset, linear_offset;
560 u32 dvscntr, dvsscale;
561 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
562 u32 start_vbl_count;
563 bool atomic_update;
564
565 dvscntr = I915_READ(DVSCNTR(pipe));
566
567 /* Mask out pixel format bits in case we change it */
568 dvscntr &= ~DVS_PIXFORMAT_MASK;
569 dvscntr &= ~DVS_RGB_ORDER_XBGR;
570 dvscntr &= ~DVS_YUV_BYTE_ORDER_MASK;
571 dvscntr &= ~DVS_TILED;
572
573 switch (fb->pixel_format) {
574 case DRM_FORMAT_XBGR8888:
575 dvscntr |= DVS_FORMAT_RGBX888 | DVS_RGB_ORDER_XBGR;
576 break;
577 case DRM_FORMAT_XRGB8888:
578 dvscntr |= DVS_FORMAT_RGBX888;
579 break;
580 case DRM_FORMAT_YUYV:
581 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YUYV;
582 break;
583 case DRM_FORMAT_YVYU:
584 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YVYU;
585 break;
586 case DRM_FORMAT_UYVY:
587 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_UYVY;
588 break;
589 case DRM_FORMAT_VYUY:
590 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_VYUY;
591 break;
592 default:
593 BUG();
594 }
595
596 /*
597 * Enable gamma to match primary/cursor plane behaviour.
598 * FIXME should be user controllable via propertiesa.
599 */
600 dvscntr |= DVS_GAMMA_ENABLE;
601
602 if (obj->tiling_mode != I915_TILING_NONE)
603 dvscntr |= DVS_TILED;
604
605 if (IS_GEN6(dev))
606 dvscntr |= DVS_TRICKLE_FEED_DISABLE; /* must disable */
607 dvscntr |= DVS_ENABLE;
608
609 intel_update_sprite_watermarks(plane, crtc, src_w, pixel_size, true,
610 src_w != crtc_w || src_h != crtc_h);
611
612 /* Sizes are 0 based */
613 src_w--;
614 src_h--;
615 crtc_w--;
616 crtc_h--;
617
618 dvsscale = 0;
619 if (crtc_w != src_w || crtc_h != src_h)
620 dvsscale = DVS_SCALE_ENABLE | (src_w << 16) | src_h;
621
622 linear_offset = y * fb->pitches[0] + x * pixel_size;
623 dvssurf_offset =
624 intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
625 pixel_size, fb->pitches[0]);
626 linear_offset -= dvssurf_offset;
627
628 atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count);
629
630 intel_update_primary_plane(intel_crtc);
631
632 I915_WRITE(DVSSTRIDE(pipe), fb->pitches[0]);
633 I915_WRITE(DVSPOS(pipe), (crtc_y << 16) | crtc_x);
634
635 if (obj->tiling_mode != I915_TILING_NONE)
636 I915_WRITE(DVSTILEOFF(pipe), (y << 16) | x);
637 else
638 I915_WRITE(DVSLINOFF(pipe), linear_offset);
639
640 I915_WRITE(DVSSIZE(pipe), (crtc_h << 16) | crtc_w);
641 I915_WRITE(DVSSCALE(pipe), dvsscale);
642 I915_WRITE(DVSCNTR(pipe), dvscntr);
643 I915_WRITE(DVSSURF(pipe),
644 i915_gem_obj_ggtt_offset(obj) + dvssurf_offset);
645
646 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
647
648 if (atomic_update)
649 intel_pipe_update_end(intel_crtc, start_vbl_count);
650 }
651
652 static void
653 ilk_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc)
654 {
655 struct drm_device *dev = plane->dev;
656 struct drm_i915_private *dev_priv = dev->dev_private;
657 struct intel_plane *intel_plane = to_intel_plane(plane);
658 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
659 int pipe = intel_plane->pipe;
660 u32 start_vbl_count;
661 bool atomic_update;
662
663 atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count);
664
665 intel_update_primary_plane(intel_crtc);
666
667 I915_WRITE(DVSCNTR(pipe), I915_READ(DVSCNTR(pipe)) & ~DVS_ENABLE);
668 /* Disable the scaler */
669 I915_WRITE(DVSSCALE(pipe), 0);
670 /* Flush double buffered register updates */
671 I915_WRITE(DVSSURF(pipe), 0);
672
673 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
674
675 if (atomic_update)
676 intel_pipe_update_end(intel_crtc, start_vbl_count);
677
678 /*
679 * Avoid underruns when disabling the sprite.
680 * FIXME remove once watermark updates are done properly.
681 */
682 intel_wait_for_vblank(dev, pipe);
683
684 intel_update_sprite_watermarks(plane, crtc, 0, 0, false, false);
685 }
686
687 static void
688 intel_post_enable_primary(struct drm_crtc *crtc)
689 {
690 struct drm_device *dev = crtc->dev;
691 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
692
693 /*
694 * FIXME IPS should be fine as long as one plane is
695 * enabled, but in practice it seems to have problems
696 * when going from primary only to sprite only and vice
697 * versa.
698 */
699 hsw_enable_ips(intel_crtc);
700
701 mutex_lock(&dev->struct_mutex);
702 intel_update_fbc(dev);
703 mutex_unlock(&dev->struct_mutex);
704 }
705
706 static void
707 intel_pre_disable_primary(struct drm_crtc *crtc)
708 {
709 struct drm_device *dev = crtc->dev;
710 struct drm_i915_private *dev_priv = dev->dev_private;
711 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
712
713 mutex_lock(&dev->struct_mutex);
714 if (dev_priv->fbc.plane == intel_crtc->plane)
715 intel_disable_fbc(dev);
716 mutex_unlock(&dev->struct_mutex);
717
718 /*
719 * FIXME IPS should be fine as long as one plane is
720 * enabled, but in practice it seems to have problems
721 * when going from primary only to sprite only and vice
722 * versa.
723 */
724 hsw_disable_ips(intel_crtc);
725 }
726
727 static int
728 ilk_update_colorkey(struct drm_plane *plane,
729 struct drm_intel_sprite_colorkey *key)
730 {
731 struct drm_device *dev = plane->dev;
732 struct drm_i915_private *dev_priv = dev->dev_private;
733 struct intel_plane *intel_plane;
734 u32 dvscntr;
735 int ret = 0;
736
737 intel_plane = to_intel_plane(plane);
738
739 I915_WRITE(DVSKEYVAL(intel_plane->pipe), key->min_value);
740 I915_WRITE(DVSKEYMAX(intel_plane->pipe), key->max_value);
741 I915_WRITE(DVSKEYMSK(intel_plane->pipe), key->channel_mask);
742
743 dvscntr = I915_READ(DVSCNTR(intel_plane->pipe));
744 dvscntr &= ~(DVS_SOURCE_KEY | DVS_DEST_KEY);
745 if (key->flags & I915_SET_COLORKEY_DESTINATION)
746 dvscntr |= DVS_DEST_KEY;
747 else if (key->flags & I915_SET_COLORKEY_SOURCE)
748 dvscntr |= DVS_SOURCE_KEY;
749 I915_WRITE(DVSCNTR(intel_plane->pipe), dvscntr);
750
751 POSTING_READ(DVSKEYMSK(intel_plane->pipe));
752
753 return ret;
754 }
755
756 static void
757 ilk_get_colorkey(struct drm_plane *plane, struct drm_intel_sprite_colorkey *key)
758 {
759 struct drm_device *dev = plane->dev;
760 struct drm_i915_private *dev_priv = dev->dev_private;
761 struct intel_plane *intel_plane;
762 u32 dvscntr;
763
764 intel_plane = to_intel_plane(plane);
765
766 key->min_value = I915_READ(DVSKEYVAL(intel_plane->pipe));
767 key->max_value = I915_READ(DVSKEYMAX(intel_plane->pipe));
768 key->channel_mask = I915_READ(DVSKEYMSK(intel_plane->pipe));
769 key->flags = 0;
770
771 dvscntr = I915_READ(DVSCNTR(intel_plane->pipe));
772
773 if (dvscntr & DVS_DEST_KEY)
774 key->flags = I915_SET_COLORKEY_DESTINATION;
775 else if (dvscntr & DVS_SOURCE_KEY)
776 key->flags = I915_SET_COLORKEY_SOURCE;
777 else
778 key->flags = I915_SET_COLORKEY_NONE;
779 }
780
781 static bool
782 format_is_yuv(uint32_t format)
783 {
784 switch (format) {
785 case DRM_FORMAT_YUYV:
786 case DRM_FORMAT_UYVY:
787 case DRM_FORMAT_VYUY:
788 case DRM_FORMAT_YVYU:
789 return true;
790 default:
791 return false;
792 }
793 }
794
795 static bool colorkey_enabled(struct intel_plane *intel_plane)
796 {
797 struct drm_intel_sprite_colorkey key;
798
799 intel_plane->get_colorkey(&intel_plane->base, &key);
800
801 return key.flags != I915_SET_COLORKEY_NONE;
802 }
803
804 static int
805 intel_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
806 struct drm_framebuffer *fb, int crtc_x, int crtc_y,
807 unsigned int crtc_w, unsigned int crtc_h,
808 uint32_t src_x, uint32_t src_y,
809 uint32_t src_w, uint32_t src_h)
810 {
811 struct drm_device *dev = plane->dev;
812 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
813 struct intel_plane *intel_plane = to_intel_plane(plane);
814 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
815 struct drm_i915_gem_object *obj = intel_fb->obj;
816 struct drm_i915_gem_object *old_obj = intel_plane->obj;
817 int ret;
818 bool primary_enabled;
819 bool visible;
820 int hscale, vscale;
821 int max_scale, min_scale;
822 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
823 struct drm_rect src = {
824 /* sample coordinates in 16.16 fixed point */
825 .x1 = src_x,
826 .x2 = src_x + src_w,
827 .y1 = src_y,
828 .y2 = src_y + src_h,
829 };
830 struct drm_rect dst = {
831 /* integer pixels */
832 .x1 = crtc_x,
833 .x2 = crtc_x + crtc_w,
834 .y1 = crtc_y,
835 .y2 = crtc_y + crtc_h,
836 };
837 const struct drm_rect clip = {
838 .x2 = intel_crtc->active ? intel_crtc->config.pipe_src_w : 0,
839 .y2 = intel_crtc->active ? intel_crtc->config.pipe_src_h : 0,
840 };
841 const struct {
842 int crtc_x, crtc_y;
843 unsigned int crtc_w, crtc_h;
844 uint32_t src_x, src_y, src_w, src_h;
845 } orig = {
846 .crtc_x = crtc_x,
847 .crtc_y = crtc_y,
848 .crtc_w = crtc_w,
849 .crtc_h = crtc_h,
850 .src_x = src_x,
851 .src_y = src_y,
852 .src_w = src_w,
853 .src_h = src_h,
854 };
855
856 /* Don't modify another pipe's plane */
857 if (intel_plane->pipe != intel_crtc->pipe) {
858 DRM_DEBUG_KMS("Wrong plane <-> crtc mapping\n");
859 return -EINVAL;
860 }
861
862 /* FIXME check all gen limits */
863 if (fb->width < 3 || fb->height < 3 || fb->pitches[0] > 16384) {
864 DRM_DEBUG_KMS("Unsuitable framebuffer for plane\n");
865 return -EINVAL;
866 }
867
868 /* Sprite planes can be linear or x-tiled surfaces */
869 switch (obj->tiling_mode) {
870 case I915_TILING_NONE:
871 case I915_TILING_X:
872 break;
873 default:
874 DRM_DEBUG_KMS("Unsupported tiling mode\n");
875 return -EINVAL;
876 }
877
878 /*
879 * FIXME the following code does a bunch of fuzzy adjustments to the
880 * coordinates and sizes. We probably need some way to decide whether
881 * more strict checking should be done instead.
882 */
883 max_scale = intel_plane->max_downscale << 16;
884 min_scale = intel_plane->can_scale ? 1 : (1 << 16);
885
886 hscale = drm_rect_calc_hscale_relaxed(&src, &dst, min_scale, max_scale);
887 BUG_ON(hscale < 0);
888
889 vscale = drm_rect_calc_vscale_relaxed(&src, &dst, min_scale, max_scale);
890 BUG_ON(vscale < 0);
891
892 visible = drm_rect_clip_scaled(&src, &dst, &clip, hscale, vscale);
893
894 crtc_x = dst.x1;
895 crtc_y = dst.y1;
896 crtc_w = drm_rect_width(&dst);
897 crtc_h = drm_rect_height(&dst);
898
899 if (visible) {
900 /* check again in case clipping clamped the results */
901 hscale = drm_rect_calc_hscale(&src, &dst, min_scale, max_scale);
902 if (hscale < 0) {
903 DRM_DEBUG_KMS("Horizontal scaling factor out of limits\n");
904 drm_rect_debug_print(&src, true);
905 drm_rect_debug_print(&dst, false);
906
907 return hscale;
908 }
909
910 vscale = drm_rect_calc_vscale(&src, &dst, min_scale, max_scale);
911 if (vscale < 0) {
912 DRM_DEBUG_KMS("Vertical scaling factor out of limits\n");
913 drm_rect_debug_print(&src, true);
914 drm_rect_debug_print(&dst, false);
915
916 return vscale;
917 }
918
919 /* Make the source viewport size an exact multiple of the scaling factors. */
920 drm_rect_adjust_size(&src,
921 drm_rect_width(&dst) * hscale - drm_rect_width(&src),
922 drm_rect_height(&dst) * vscale - drm_rect_height(&src));
923
924 /* sanity check to make sure the src viewport wasn't enlarged */
925 WARN_ON(src.x1 < (int) src_x ||
926 src.y1 < (int) src_y ||
927 src.x2 > (int) (src_x + src_w) ||
928 src.y2 > (int) (src_y + src_h));
929
930 /*
931 * Hardware doesn't handle subpixel coordinates.
932 * Adjust to (macro)pixel boundary, but be careful not to
933 * increase the source viewport size, because that could
934 * push the downscaling factor out of bounds.
935 */
936 src_x = src.x1 >> 16;
937 src_w = drm_rect_width(&src) >> 16;
938 src_y = src.y1 >> 16;
939 src_h = drm_rect_height(&src) >> 16;
940
941 if (format_is_yuv(fb->pixel_format)) {
942 src_x &= ~1;
943 src_w &= ~1;
944
945 /*
946 * Must keep src and dst the
947 * same if we can't scale.
948 */
949 if (!intel_plane->can_scale)
950 crtc_w &= ~1;
951
952 if (crtc_w == 0)
953 visible = false;
954 }
955 }
956
957 /* Check size restrictions when scaling */
958 if (visible && (src_w != crtc_w || src_h != crtc_h)) {
959 unsigned int width_bytes;
960
961 WARN_ON(!intel_plane->can_scale);
962
963 /* FIXME interlacing min height is 6 */
964
965 if (crtc_w < 3 || crtc_h < 3)
966 visible = false;
967
968 if (src_w < 3 || src_h < 3)
969 visible = false;
970
971 width_bytes = ((src_x * pixel_size) & 63) + src_w * pixel_size;
972
973 if (src_w > 2048 || src_h > 2048 ||
974 width_bytes > 4096 || fb->pitches[0] > 4096) {
975 DRM_DEBUG_KMS("Source dimensions exceed hardware limits\n");
976 return -EINVAL;
977 }
978 }
979
980 dst.x1 = crtc_x;
981 dst.x2 = crtc_x + crtc_w;
982 dst.y1 = crtc_y;
983 dst.y2 = crtc_y + crtc_h;
984
985 /*
986 * If the sprite is completely covering the primary plane,
987 * we can disable the primary and save power.
988 */
989 primary_enabled = !drm_rect_equals(&dst, &clip) || colorkey_enabled(intel_plane);
990 WARN_ON(!primary_enabled && !visible && intel_crtc->active);
991
992 mutex_lock(&dev->struct_mutex);
993
994 /* Note that this will apply the VT-d workaround for scanouts,
995 * which is more restrictive than required for sprites. (The
996 * primary plane requires 256KiB alignment with 64 PTE padding,
997 * the sprite planes only require 128KiB alignment and 32 PTE padding.
998 */
999 ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
1000
1001 mutex_unlock(&dev->struct_mutex);
1002
1003 if (ret)
1004 return ret;
1005
1006 intel_plane->crtc_x = orig.crtc_x;
1007 intel_plane->crtc_y = orig.crtc_y;
1008 intel_plane->crtc_w = orig.crtc_w;
1009 intel_plane->crtc_h = orig.crtc_h;
1010 intel_plane->src_x = orig.src_x;
1011 intel_plane->src_y = orig.src_y;
1012 intel_plane->src_w = orig.src_w;
1013 intel_plane->src_h = orig.src_h;
1014 intel_plane->obj = obj;
1015
1016 if (intel_crtc->active) {
1017 bool primary_was_enabled = intel_crtc->primary_enabled;
1018
1019 intel_crtc->primary_enabled = primary_enabled;
1020
1021 if (primary_was_enabled != primary_enabled)
1022 intel_crtc_wait_for_pending_flips(crtc);
1023
1024 if (primary_was_enabled && !primary_enabled)
1025 intel_pre_disable_primary(crtc);
1026
1027 if (visible)
1028 intel_plane->update_plane(plane, crtc, fb, obj,
1029 crtc_x, crtc_y, crtc_w, crtc_h,
1030 src_x, src_y, src_w, src_h);
1031 else
1032 intel_plane->disable_plane(plane, crtc);
1033
1034 if (!primary_was_enabled && primary_enabled)
1035 intel_post_enable_primary(crtc);
1036 }
1037
1038 /* Unpin old obj after new one is active to avoid ugliness */
1039 if (old_obj) {
1040 /*
1041 * It's fairly common to simply update the position of
1042 * an existing object. In that case, we don't need to
1043 * wait for vblank to avoid ugliness, we only need to
1044 * do the pin & ref bookkeeping.
1045 */
1046 if (old_obj != obj && intel_crtc->active)
1047 intel_wait_for_vblank(dev, intel_crtc->pipe);
1048
1049 mutex_lock(&dev->struct_mutex);
1050 intel_unpin_fb_obj(old_obj);
1051 mutex_unlock(&dev->struct_mutex);
1052 }
1053
1054 return 0;
1055 }
1056
1057 static int
1058 intel_disable_plane(struct drm_plane *plane)
1059 {
1060 struct drm_device *dev = plane->dev;
1061 struct intel_plane *intel_plane = to_intel_plane(plane);
1062 struct intel_crtc *intel_crtc;
1063
1064 if (!plane->fb)
1065 return 0;
1066
1067 if (WARN_ON(!plane->crtc))
1068 return -EINVAL;
1069
1070 intel_crtc = to_intel_crtc(plane->crtc);
1071
1072 if (intel_crtc->active) {
1073 bool primary_was_enabled = intel_crtc->primary_enabled;
1074
1075 intel_crtc->primary_enabled = true;
1076
1077 intel_plane->disable_plane(plane, plane->crtc);
1078
1079 if (!primary_was_enabled && intel_crtc->primary_enabled)
1080 intel_post_enable_primary(plane->crtc);
1081 }
1082
1083 if (intel_plane->obj) {
1084 if (intel_crtc->active)
1085 intel_wait_for_vblank(dev, intel_plane->pipe);
1086
1087 mutex_lock(&dev->struct_mutex);
1088 intel_unpin_fb_obj(intel_plane->obj);
1089 mutex_unlock(&dev->struct_mutex);
1090
1091 intel_plane->obj = NULL;
1092 }
1093
1094 return 0;
1095 }
1096
1097 static void intel_destroy_plane(struct drm_plane *plane)
1098 {
1099 struct intel_plane *intel_plane = to_intel_plane(plane);
1100 intel_disable_plane(plane);
1101 drm_plane_cleanup(plane);
1102 kfree(intel_plane);
1103 }
1104
1105 int intel_sprite_set_colorkey(struct drm_device *dev, void *data,
1106 struct drm_file *file_priv)
1107 {
1108 struct drm_intel_sprite_colorkey *set = data;
1109 struct drm_mode_object *obj;
1110 struct drm_plane *plane;
1111 struct intel_plane *intel_plane;
1112 int ret = 0;
1113
1114 if (!drm_core_check_feature(dev, DRIVER_MODESET))
1115 return -ENODEV;
1116
1117 /* Make sure we don't try to enable both src & dest simultaneously */
1118 if ((set->flags & (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE)) == (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE))
1119 return -EINVAL;
1120
1121 drm_modeset_lock_all(dev);
1122
1123 obj = drm_mode_object_find(dev, set->plane_id, DRM_MODE_OBJECT_PLANE);
1124 if (!obj) {
1125 ret = -ENOENT;
1126 goto out_unlock;
1127 }
1128
1129 plane = obj_to_plane(obj);
1130 intel_plane = to_intel_plane(plane);
1131 ret = intel_plane->update_colorkey(plane, set);
1132
1133 out_unlock:
1134 drm_modeset_unlock_all(dev);
1135 return ret;
1136 }
1137
1138 int intel_sprite_get_colorkey(struct drm_device *dev, void *data,
1139 struct drm_file *file_priv)
1140 {
1141 struct drm_intel_sprite_colorkey *get = data;
1142 struct drm_mode_object *obj;
1143 struct drm_plane *plane;
1144 struct intel_plane *intel_plane;
1145 int ret = 0;
1146
1147 if (!drm_core_check_feature(dev, DRIVER_MODESET))
1148 return -ENODEV;
1149
1150 drm_modeset_lock_all(dev);
1151
1152 obj = drm_mode_object_find(dev, get->plane_id, DRM_MODE_OBJECT_PLANE);
1153 if (!obj) {
1154 ret = -ENOENT;
1155 goto out_unlock;
1156 }
1157
1158 plane = obj_to_plane(obj);
1159 intel_plane = to_intel_plane(plane);
1160 intel_plane->get_colorkey(plane, get);
1161
1162 out_unlock:
1163 drm_modeset_unlock_all(dev);
1164 return ret;
1165 }
1166
1167 void intel_plane_restore(struct drm_plane *plane)
1168 {
1169 struct intel_plane *intel_plane = to_intel_plane(plane);
1170
1171 if (!plane->crtc || !plane->fb)
1172 return;
1173
1174 intel_update_plane(plane, plane->crtc, plane->fb,
1175 intel_plane->crtc_x, intel_plane->crtc_y,
1176 intel_plane->crtc_w, intel_plane->crtc_h,
1177 intel_plane->src_x, intel_plane->src_y,
1178 intel_plane->src_w, intel_plane->src_h);
1179 }
1180
1181 void intel_plane_disable(struct drm_plane *plane)
1182 {
1183 if (!plane->crtc || !plane->fb)
1184 return;
1185
1186 intel_disable_plane(plane);
1187 }
1188
1189 static const struct drm_plane_funcs intel_plane_funcs = {
1190 .update_plane = intel_update_plane,
1191 .disable_plane = intel_disable_plane,
1192 .destroy = intel_destroy_plane,
1193 };
1194
1195 static uint32_t ilk_plane_formats[] = {
1196 DRM_FORMAT_XRGB8888,
1197 DRM_FORMAT_YUYV,
1198 DRM_FORMAT_YVYU,
1199 DRM_FORMAT_UYVY,
1200 DRM_FORMAT_VYUY,
1201 };
1202
1203 static uint32_t snb_plane_formats[] = {
1204 DRM_FORMAT_XBGR8888,
1205 DRM_FORMAT_XRGB8888,
1206 DRM_FORMAT_YUYV,
1207 DRM_FORMAT_YVYU,
1208 DRM_FORMAT_UYVY,
1209 DRM_FORMAT_VYUY,
1210 };
1211
1212 static uint32_t vlv_plane_formats[] = {
1213 DRM_FORMAT_RGB565,
1214 DRM_FORMAT_ABGR8888,
1215 DRM_FORMAT_ARGB8888,
1216 DRM_FORMAT_XBGR8888,
1217 DRM_FORMAT_XRGB8888,
1218 DRM_FORMAT_XBGR2101010,
1219 DRM_FORMAT_ABGR2101010,
1220 DRM_FORMAT_YUYV,
1221 DRM_FORMAT_YVYU,
1222 DRM_FORMAT_UYVY,
1223 DRM_FORMAT_VYUY,
1224 };
1225
1226 int
1227 intel_plane_init(struct drm_device *dev, enum pipe pipe, int plane)
1228 {
1229 struct intel_plane *intel_plane;
1230 unsigned long possible_crtcs;
1231 const uint32_t *plane_formats;
1232 int num_plane_formats;
1233 int ret;
1234
1235 if (INTEL_INFO(dev)->gen < 5)
1236 return -ENODEV;
1237
1238 intel_plane = kzalloc(sizeof(*intel_plane), GFP_KERNEL);
1239 if (!intel_plane)
1240 return -ENOMEM;
1241
1242 switch (INTEL_INFO(dev)->gen) {
1243 case 5:
1244 case 6:
1245 intel_plane->can_scale = true;
1246 intel_plane->max_downscale = 16;
1247 intel_plane->update_plane = ilk_update_plane;
1248 intel_plane->disable_plane = ilk_disable_plane;
1249 intel_plane->update_colorkey = ilk_update_colorkey;
1250 intel_plane->get_colorkey = ilk_get_colorkey;
1251
1252 if (IS_GEN6(dev)) {
1253 plane_formats = snb_plane_formats;
1254 num_plane_formats = ARRAY_SIZE(snb_plane_formats);
1255 } else {
1256 plane_formats = ilk_plane_formats;
1257 num_plane_formats = ARRAY_SIZE(ilk_plane_formats);
1258 }
1259 break;
1260
1261 case 7:
1262 case 8:
1263 if (IS_IVYBRIDGE(dev)) {
1264 intel_plane->can_scale = true;
1265 intel_plane->max_downscale = 2;
1266 } else {
1267 intel_plane->can_scale = false;
1268 intel_plane->max_downscale = 1;
1269 }
1270
1271 if (IS_VALLEYVIEW(dev)) {
1272 intel_plane->update_plane = vlv_update_plane;
1273 intel_plane->disable_plane = vlv_disable_plane;
1274 intel_plane->update_colorkey = vlv_update_colorkey;
1275 intel_plane->get_colorkey = vlv_get_colorkey;
1276
1277 plane_formats = vlv_plane_formats;
1278 num_plane_formats = ARRAY_SIZE(vlv_plane_formats);
1279 } else {
1280 intel_plane->update_plane = ivb_update_plane;
1281 intel_plane->disable_plane = ivb_disable_plane;
1282 intel_plane->update_colorkey = ivb_update_colorkey;
1283 intel_plane->get_colorkey = ivb_get_colorkey;
1284
1285 plane_formats = snb_plane_formats;
1286 num_plane_formats = ARRAY_SIZE(snb_plane_formats);
1287 }
1288 break;
1289
1290 default:
1291 kfree(intel_plane);
1292 return -ENODEV;
1293 }
1294
1295 intel_plane->pipe = pipe;
1296 intel_plane->plane = plane;
1297 possible_crtcs = (1 << pipe);
1298 ret = drm_plane_init(dev, &intel_plane->base, possible_crtcs,
1299 &intel_plane_funcs,
1300 plane_formats, num_plane_formats,
1301 false);
1302 if (ret)
1303 kfree(intel_plane);
1304
1305 return ret;
1306 }
This page took 0.058322 seconds and 5 git commands to generate.