1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32#include <drm/drmP.h>
33#include <drm/drm_atomic_helper.h>
34#include <drm/drm_crtc.h>
35#include <drm/drm_fourcc.h>
36#include <drm/drm_rect.h>
37#include <drm/drm_atomic.h>
38#include <drm/drm_plane_helper.h>
39#include "intel_drv.h"
40#include "intel_frontbuffer.h"
41#include <drm/i915_drm.h>
42#include "i915_drv.h"
43
44static bool
45format_is_yuv(uint32_t format)
46{
47 switch (format) {
48 case DRM_FORMAT_YUYV:
49 case DRM_FORMAT_UYVY:
50 case DRM_FORMAT_VYUY:
51 case DRM_FORMAT_YVYU:
52 return true;
53 default:
54 return false;
55 }
56}
57
58int intel_usecs_to_scanlines(const struct drm_display_mode *adjusted_mode,
59 int usecs)
60{
61
62 if (!adjusted_mode->crtc_htotal)
63 return 1;
64
65 return DIV_ROUND_UP(usecs * adjusted_mode->crtc_clock,
66 1000 * adjusted_mode->crtc_htotal);
67}
68
69
70
71#if IS_ENABLED(CONFIG_PROVE_LOCKING)
72#define VBLANK_EVASION_TIME_US 250
73#else
74#define VBLANK_EVASION_TIME_US 100
75#endif
76
77
78
79
80
81
82
83
84
85
86
87
88
89void intel_pipe_update_start(const struct intel_crtc_state *new_crtc_state)
90{
91 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
92 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
93 const struct drm_display_mode *adjusted_mode = &new_crtc_state->base.adjusted_mode;
94 long timeout = msecs_to_jiffies_timeout(1);
95 int scanline, min, max, vblank_start;
96 wait_queue_head_t *wq = drm_crtc_vblank_waitqueue(&crtc->base);
97 bool need_vlv_dsi_wa = (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
98 intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI);
99 DEFINE_WAIT(wait);
100
101 vblank_start = adjusted_mode->crtc_vblank_start;
102 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
103 vblank_start = DIV_ROUND_UP(vblank_start, 2);
104
105
106 min = vblank_start - intel_usecs_to_scanlines(adjusted_mode,
107 VBLANK_EVASION_TIME_US);
108 max = vblank_start - 1;
109
110 local_irq_disable();
111
112 if (min <= 0 || max <= 0)
113 return;
114
115 if (WARN_ON(drm_crtc_vblank_get(&crtc->base)))
116 return;
117
118 crtc->debug.min_vbl = min;
119 crtc->debug.max_vbl = max;
120 trace_i915_pipe_update_start(crtc);
121
122 for (;;) {
123
124
125
126
127
128 prepare_to_wait(wq, &wait, TASK_UNINTERRUPTIBLE);
129
130 scanline = intel_get_crtc_scanline(crtc);
131 if (scanline < min || scanline > max)
132 break;
133
134 if (timeout <= 0) {
135 DRM_ERROR("Potential atomic update failure on pipe %c\n",
136 pipe_name(crtc->pipe));
137 break;
138 }
139
140 local_irq_enable();
141
142 timeout = schedule_timeout(timeout);
143
144 local_irq_disable();
145 }
146
147 finish_wait(wq, &wait);
148
149 drm_crtc_vblank_put(&crtc->base);
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166 while (need_vlv_dsi_wa && scanline == vblank_start)
167 scanline = intel_get_crtc_scanline(crtc);
168
169 crtc->debug.scanline_start = scanline;
170 crtc->debug.start_vbl_time = ktime_get();
171 crtc->debug.start_vbl_count = intel_crtc_get_vblank_counter(crtc);
172
173 trace_i915_pipe_update_vblank_evaded(crtc);
174}
175
176
177
178
179
180
181
182
183
184void intel_pipe_update_end(struct intel_crtc_state *new_crtc_state)
185{
186 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
187 enum pipe pipe = crtc->pipe;
188 int scanline_end = intel_get_crtc_scanline(crtc);
189 u32 end_vbl_count = intel_crtc_get_vblank_counter(crtc);
190 ktime_t end_vbl_time = ktime_get();
191 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
192
193 trace_i915_pipe_update_end(crtc, end_vbl_count, scanline_end);
194
195
196
197
198
199 if (new_crtc_state->base.event) {
200 WARN_ON(drm_crtc_vblank_get(&crtc->base) != 0);
201
202 spin_lock(&crtc->base.dev->event_lock);
203 drm_crtc_arm_vblank_event(&crtc->base, new_crtc_state->base.event);
204 spin_unlock(&crtc->base.dev->event_lock);
205
206 new_crtc_state->base.event = NULL;
207 }
208
209 local_irq_enable();
210
211 if (intel_vgpu_active(dev_priv))
212 return;
213
214 if (crtc->debug.start_vbl_count &&
215 crtc->debug.start_vbl_count != end_vbl_count) {
216 DRM_ERROR("Atomic update failure on pipe %c (start=%u end=%u) time %lld us, min %d, max %d, scanline start %d, end %d\n",
217 pipe_name(pipe), crtc->debug.start_vbl_count,
218 end_vbl_count,
219 ktime_us_delta(end_vbl_time, crtc->debug.start_vbl_time),
220 crtc->debug.min_vbl, crtc->debug.max_vbl,
221 crtc->debug.scanline_start, scanline_end);
222 }
223#ifdef CONFIG_DRM_I915_DEBUG_VBLANK_EVADE
224 else if (ktime_us_delta(end_vbl_time, crtc->debug.start_vbl_time) >
225 VBLANK_EVASION_TIME_US)
226 DRM_WARN("Atomic update on pipe (%c) took %lld us, max time under evasion is %u us\n",
227 pipe_name(pipe),
228 ktime_us_delta(end_vbl_time, crtc->debug.start_vbl_time),
229 VBLANK_EVASION_TIME_US);
230#endif
231}
232
233void
234skl_update_plane(struct intel_plane *plane,
235 const struct intel_crtc_state *crtc_state,
236 const struct intel_plane_state *plane_state)
237{
238 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
239 const struct drm_framebuffer *fb = plane_state->base.fb;
240 enum plane_id plane_id = plane->id;
241 enum pipe pipe = plane->pipe;
242 u32 plane_ctl = plane_state->ctl;
243 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
244 u32 surf_addr = plane_state->main.offset;
245 unsigned int rotation = plane_state->base.rotation;
246 u32 stride = skl_plane_stride(fb, 0, rotation);
247 u32 aux_stride = skl_plane_stride(fb, 1, rotation);
248 int crtc_x = plane_state->base.dst.x1;
249 int crtc_y = plane_state->base.dst.y1;
250 uint32_t crtc_w = drm_rect_width(&plane_state->base.dst);
251 uint32_t crtc_h = drm_rect_height(&plane_state->base.dst);
252 uint32_t x = plane_state->main.x;
253 uint32_t y = plane_state->main.y;
254 uint32_t src_w = drm_rect_width(&plane_state->base.src) >> 16;
255 uint32_t src_h = drm_rect_height(&plane_state->base.src) >> 16;
256 unsigned long irqflags;
257
258
259 src_w--;
260 src_h--;
261 crtc_w--;
262 crtc_h--;
263
264 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
265
266 if (IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) {
267 I915_WRITE_FW(PLANE_COLOR_CTL(pipe, plane_id),
268 PLANE_COLOR_PIPE_GAMMA_ENABLE |
269 PLANE_COLOR_PIPE_CSC_ENABLE |
270 PLANE_COLOR_PLANE_GAMMA_DISABLE);
271 }
272
273 if (key->flags) {
274 I915_WRITE_FW(PLANE_KEYVAL(pipe, plane_id), key->min_value);
275 I915_WRITE_FW(PLANE_KEYMAX(pipe, plane_id), key->max_value);
276 I915_WRITE_FW(PLANE_KEYMSK(pipe, plane_id), key->channel_mask);
277 }
278
279 I915_WRITE_FW(PLANE_OFFSET(pipe, plane_id), (y << 16) | x);
280 I915_WRITE_FW(PLANE_STRIDE(pipe, plane_id), stride);
281 I915_WRITE_FW(PLANE_SIZE(pipe, plane_id), (src_h << 16) | src_w);
282 I915_WRITE_FW(PLANE_AUX_DIST(pipe, plane_id),
283 (plane_state->aux.offset - surf_addr) | aux_stride);
284 I915_WRITE_FW(PLANE_AUX_OFFSET(pipe, plane_id),
285 (plane_state->aux.y << 16) | plane_state->aux.x);
286
287
288 if (plane_state->scaler_id >= 0) {
289 int scaler_id = plane_state->scaler_id;
290 const struct intel_scaler *scaler;
291
292 scaler = &crtc_state->scaler_state.scalers[scaler_id];
293
294 I915_WRITE_FW(SKL_PS_CTRL(pipe, scaler_id),
295 PS_SCALER_EN | PS_PLANE_SEL(plane_id) | scaler->mode);
296 I915_WRITE_FW(SKL_PS_PWR_GATE(pipe, scaler_id), 0);
297 I915_WRITE_FW(SKL_PS_WIN_POS(pipe, scaler_id), (crtc_x << 16) | crtc_y);
298 I915_WRITE_FW(SKL_PS_WIN_SZ(pipe, scaler_id),
299 ((crtc_w + 1) << 16)|(crtc_h + 1));
300
301 I915_WRITE_FW(PLANE_POS(pipe, plane_id), 0);
302 } else {
303 I915_WRITE_FW(PLANE_POS(pipe, plane_id), (crtc_y << 16) | crtc_x);
304 }
305
306 I915_WRITE_FW(PLANE_CTL(pipe, plane_id), plane_ctl);
307 I915_WRITE_FW(PLANE_SURF(pipe, plane_id),
308 intel_plane_ggtt_offset(plane_state) + surf_addr);
309 POSTING_READ_FW(PLANE_SURF(pipe, plane_id));
310
311 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
312}
313
314void
315skl_disable_plane(struct intel_plane *plane, struct intel_crtc *crtc)
316{
317 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
318 enum plane_id plane_id = plane->id;
319 enum pipe pipe = plane->pipe;
320 unsigned long irqflags;
321
322 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
323
324 I915_WRITE_FW(PLANE_CTL(pipe, plane_id), 0);
325
326 I915_WRITE_FW(PLANE_SURF(pipe, plane_id), 0);
327 POSTING_READ_FW(PLANE_SURF(pipe, plane_id));
328
329 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
330}
331
332bool
333skl_plane_get_hw_state(struct intel_plane *plane)
334{
335 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
336 enum intel_display_power_domain power_domain;
337 enum plane_id plane_id = plane->id;
338 enum pipe pipe = plane->pipe;
339 bool ret;
340
341 power_domain = POWER_DOMAIN_PIPE(pipe);
342 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
343 return false;
344
345 ret = I915_READ(PLANE_CTL(pipe, plane_id)) & PLANE_CTL_ENABLE;
346
347 intel_display_power_put(dev_priv, power_domain);
348
349 return ret;
350}
351
352static void
353chv_update_csc(struct intel_plane *plane, uint32_t format)
354{
355 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
356 enum plane_id plane_id = plane->id;
357
358
359 if (!format_is_yuv(format))
360 return;
361
362
363
364
365
366
367
368
369
370
371
372 I915_WRITE_FW(SPCSCYGOFF(plane_id), SPCSC_OOFF(0) | SPCSC_IOFF(-64));
373 I915_WRITE_FW(SPCSCCBOFF(plane_id), SPCSC_OOFF(0) | SPCSC_IOFF(0));
374 I915_WRITE_FW(SPCSCCROFF(plane_id), SPCSC_OOFF(0) | SPCSC_IOFF(0));
375
376 I915_WRITE_FW(SPCSCC01(plane_id), SPCSC_C1(4769) | SPCSC_C0(6537));
377 I915_WRITE_FW(SPCSCC23(plane_id), SPCSC_C1(-3330) | SPCSC_C0(0));
378 I915_WRITE_FW(SPCSCC45(plane_id), SPCSC_C1(-1605) | SPCSC_C0(4769));
379 I915_WRITE_FW(SPCSCC67(plane_id), SPCSC_C1(4769) | SPCSC_C0(0));
380 I915_WRITE_FW(SPCSCC8(plane_id), SPCSC_C0(8263));
381
382 I915_WRITE_FW(SPCSCYGICLAMP(plane_id), SPCSC_IMAX(940) | SPCSC_IMIN(64));
383 I915_WRITE_FW(SPCSCCBICLAMP(plane_id), SPCSC_IMAX(448) | SPCSC_IMIN(-448));
384 I915_WRITE_FW(SPCSCCRICLAMP(plane_id), SPCSC_IMAX(448) | SPCSC_IMIN(-448));
385
386 I915_WRITE_FW(SPCSCYGOCLAMP(plane_id), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
387 I915_WRITE_FW(SPCSCCBOCLAMP(plane_id), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
388 I915_WRITE_FW(SPCSCCROCLAMP(plane_id), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
389}
390
391static u32 vlv_sprite_ctl(const struct intel_crtc_state *crtc_state,
392 const struct intel_plane_state *plane_state)
393{
394 const struct drm_framebuffer *fb = plane_state->base.fb;
395 unsigned int rotation = plane_state->base.rotation;
396 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
397 u32 sprctl;
398
399 sprctl = SP_ENABLE | SP_GAMMA_ENABLE;
400
401 switch (fb->format->format) {
402 case DRM_FORMAT_YUYV:
403 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YUYV;
404 break;
405 case DRM_FORMAT_YVYU:
406 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YVYU;
407 break;
408 case DRM_FORMAT_UYVY:
409 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_UYVY;
410 break;
411 case DRM_FORMAT_VYUY:
412 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_VYUY;
413 break;
414 case DRM_FORMAT_RGB565:
415 sprctl |= SP_FORMAT_BGR565;
416 break;
417 case DRM_FORMAT_XRGB8888:
418 sprctl |= SP_FORMAT_BGRX8888;
419 break;
420 case DRM_FORMAT_ARGB8888:
421 sprctl |= SP_FORMAT_BGRA8888;
422 break;
423 case DRM_FORMAT_XBGR2101010:
424 sprctl |= SP_FORMAT_RGBX1010102;
425 break;
426 case DRM_FORMAT_ABGR2101010:
427 sprctl |= SP_FORMAT_RGBA1010102;
428 break;
429 case DRM_FORMAT_XBGR8888:
430 sprctl |= SP_FORMAT_RGBX8888;
431 break;
432 case DRM_FORMAT_ABGR8888:
433 sprctl |= SP_FORMAT_RGBA8888;
434 break;
435 default:
436 MISSING_CASE(fb->format->format);
437 return 0;
438 }
439
440 if (fb->modifier == I915_FORMAT_MOD_X_TILED)
441 sprctl |= SP_TILED;
442
443 if (rotation & DRM_MODE_ROTATE_180)
444 sprctl |= SP_ROTATE_180;
445
446 if (rotation & DRM_MODE_REFLECT_X)
447 sprctl |= SP_MIRROR;
448
449 if (key->flags & I915_SET_COLORKEY_SOURCE)
450 sprctl |= SP_SOURCE_KEY;
451
452 return sprctl;
453}
454
455static void
456vlv_update_plane(struct intel_plane *plane,
457 const struct intel_crtc_state *crtc_state,
458 const struct intel_plane_state *plane_state)
459{
460 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
461 const struct drm_framebuffer *fb = plane_state->base.fb;
462 enum pipe pipe = plane->pipe;
463 enum plane_id plane_id = plane->id;
464 u32 sprctl = plane_state->ctl;
465 u32 sprsurf_offset = plane_state->main.offset;
466 u32 linear_offset;
467 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
468 int crtc_x = plane_state->base.dst.x1;
469 int crtc_y = plane_state->base.dst.y1;
470 uint32_t crtc_w = drm_rect_width(&plane_state->base.dst);
471 uint32_t crtc_h = drm_rect_height(&plane_state->base.dst);
472 uint32_t x = plane_state->main.x;
473 uint32_t y = plane_state->main.y;
474 unsigned long irqflags;
475
476
477 crtc_w--;
478 crtc_h--;
479
480 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
481
482 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
483
484 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B)
485 chv_update_csc(plane, fb->format->format);
486
487 if (key->flags) {
488 I915_WRITE_FW(SPKEYMINVAL(pipe, plane_id), key->min_value);
489 I915_WRITE_FW(SPKEYMAXVAL(pipe, plane_id), key->max_value);
490 I915_WRITE_FW(SPKEYMSK(pipe, plane_id), key->channel_mask);
491 }
492 I915_WRITE_FW(SPSTRIDE(pipe, plane_id), fb->pitches[0]);
493 I915_WRITE_FW(SPPOS(pipe, plane_id), (crtc_y << 16) | crtc_x);
494
495 if (fb->modifier == I915_FORMAT_MOD_X_TILED)
496 I915_WRITE_FW(SPTILEOFF(pipe, plane_id), (y << 16) | x);
497 else
498 I915_WRITE_FW(SPLINOFF(pipe, plane_id), linear_offset);
499
500 I915_WRITE_FW(SPCONSTALPHA(pipe, plane_id), 0);
501
502 I915_WRITE_FW(SPSIZE(pipe, plane_id), (crtc_h << 16) | crtc_w);
503 I915_WRITE_FW(SPCNTR(pipe, plane_id), sprctl);
504 I915_WRITE_FW(SPSURF(pipe, plane_id),
505 intel_plane_ggtt_offset(plane_state) + sprsurf_offset);
506 POSTING_READ_FW(SPSURF(pipe, plane_id));
507
508 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
509}
510
511static void
512vlv_disable_plane(struct intel_plane *plane, struct intel_crtc *crtc)
513{
514 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
515 enum pipe pipe = plane->pipe;
516 enum plane_id plane_id = plane->id;
517 unsigned long irqflags;
518
519 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
520
521 I915_WRITE_FW(SPCNTR(pipe, plane_id), 0);
522
523 I915_WRITE_FW(SPSURF(pipe, plane_id), 0);
524 POSTING_READ_FW(SPSURF(pipe, plane_id));
525
526 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
527}
528
529static bool
530vlv_plane_get_hw_state(struct intel_plane *plane)
531{
532 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
533 enum intel_display_power_domain power_domain;
534 enum plane_id plane_id = plane->id;
535 enum pipe pipe = plane->pipe;
536 bool ret;
537
538 power_domain = POWER_DOMAIN_PIPE(pipe);
539 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
540 return false;
541
542 ret = I915_READ(SPCNTR(pipe, plane_id)) & SP_ENABLE;
543
544 intel_display_power_put(dev_priv, power_domain);
545
546 return ret;
547}
548
549static u32 ivb_sprite_ctl(const struct intel_crtc_state *crtc_state,
550 const struct intel_plane_state *plane_state)
551{
552 struct drm_i915_private *dev_priv =
553 to_i915(plane_state->base.plane->dev);
554 const struct drm_framebuffer *fb = plane_state->base.fb;
555 unsigned int rotation = plane_state->base.rotation;
556 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
557 u32 sprctl;
558
559 sprctl = SPRITE_ENABLE | SPRITE_GAMMA_ENABLE;
560
561 if (IS_IVYBRIDGE(dev_priv))
562 sprctl |= SPRITE_TRICKLE_FEED_DISABLE;
563
564 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
565 sprctl |= SPRITE_PIPE_CSC_ENABLE;
566
567 switch (fb->format->format) {
568 case DRM_FORMAT_XBGR8888:
569 sprctl |= SPRITE_FORMAT_RGBX888 | SPRITE_RGB_ORDER_RGBX;
570 break;
571 case DRM_FORMAT_XRGB8888:
572 sprctl |= SPRITE_FORMAT_RGBX888;
573 break;
574 case DRM_FORMAT_YUYV:
575 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YUYV;
576 break;
577 case DRM_FORMAT_YVYU:
578 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YVYU;
579 break;
580 case DRM_FORMAT_UYVY:
581 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_UYVY;
582 break;
583 case DRM_FORMAT_VYUY:
584 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_VYUY;
585 break;
586 default:
587 MISSING_CASE(fb->format->format);
588 return 0;
589 }
590
591 if (fb->modifier == I915_FORMAT_MOD_X_TILED)
592 sprctl |= SPRITE_TILED;
593
594 if (rotation & DRM_MODE_ROTATE_180)
595 sprctl |= SPRITE_ROTATE_180;
596
597 if (key->flags & I915_SET_COLORKEY_DESTINATION)
598 sprctl |= SPRITE_DEST_KEY;
599 else if (key->flags & I915_SET_COLORKEY_SOURCE)
600 sprctl |= SPRITE_SOURCE_KEY;
601
602 return sprctl;
603}
604
605static void
606ivb_update_plane(struct intel_plane *plane,
607 const struct intel_crtc_state *crtc_state,
608 const struct intel_plane_state *plane_state)
609{
610 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
611 const struct drm_framebuffer *fb = plane_state->base.fb;
612 enum pipe pipe = plane->pipe;
613 u32 sprctl = plane_state->ctl, sprscale = 0;
614 u32 sprsurf_offset = plane_state->main.offset;
615 u32 linear_offset;
616 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
617 int crtc_x = plane_state->base.dst.x1;
618 int crtc_y = plane_state->base.dst.y1;
619 uint32_t crtc_w = drm_rect_width(&plane_state->base.dst);
620 uint32_t crtc_h = drm_rect_height(&plane_state->base.dst);
621 uint32_t x = plane_state->main.x;
622 uint32_t y = plane_state->main.y;
623 uint32_t src_w = drm_rect_width(&plane_state->base.src) >> 16;
624 uint32_t src_h = drm_rect_height(&plane_state->base.src) >> 16;
625 unsigned long irqflags;
626
627
628 src_w--;
629 src_h--;
630 crtc_w--;
631 crtc_h--;
632
633 if (crtc_w != src_w || crtc_h != src_h)
634 sprscale = SPRITE_SCALE_ENABLE | (src_w << 16) | src_h;
635
636 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
637
638 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
639
640 if (key->flags) {
641 I915_WRITE_FW(SPRKEYVAL(pipe), key->min_value);
642 I915_WRITE_FW(SPRKEYMAX(pipe), key->max_value);
643 I915_WRITE_FW(SPRKEYMSK(pipe), key->channel_mask);
644 }
645
646 I915_WRITE_FW(SPRSTRIDE(pipe), fb->pitches[0]);
647 I915_WRITE_FW(SPRPOS(pipe), (crtc_y << 16) | crtc_x);
648
649
650
651 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
652 I915_WRITE_FW(SPROFFSET(pipe), (y << 16) | x);
653 else if (fb->modifier == I915_FORMAT_MOD_X_TILED)
654 I915_WRITE_FW(SPRTILEOFF(pipe), (y << 16) | x);
655 else
656 I915_WRITE_FW(SPRLINOFF(pipe), linear_offset);
657
658 I915_WRITE_FW(SPRSIZE(pipe), (crtc_h << 16) | crtc_w);
659 if (plane->can_scale)
660 I915_WRITE_FW(SPRSCALE(pipe), sprscale);
661 I915_WRITE_FW(SPRCTL(pipe), sprctl);
662 I915_WRITE_FW(SPRSURF(pipe),
663 intel_plane_ggtt_offset(plane_state) + sprsurf_offset);
664 POSTING_READ_FW(SPRSURF(pipe));
665
666 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
667}
668
669static void
670ivb_disable_plane(struct intel_plane *plane, struct intel_crtc *crtc)
671{
672 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
673 enum pipe pipe = plane->pipe;
674 unsigned long irqflags;
675
676 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
677
678 I915_WRITE_FW(SPRCTL(pipe), 0);
679
680 if (plane->can_scale)
681 I915_WRITE_FW(SPRSCALE(pipe), 0);
682
683 I915_WRITE_FW(SPRSURF(pipe), 0);
684 POSTING_READ_FW(SPRSURF(pipe));
685
686 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
687}
688
689static bool
690ivb_plane_get_hw_state(struct intel_plane *plane)
691{
692 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
693 enum intel_display_power_domain power_domain;
694 enum pipe pipe = plane->pipe;
695 bool ret;
696
697 power_domain = POWER_DOMAIN_PIPE(pipe);
698 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
699 return false;
700
701 ret = I915_READ(SPRCTL(pipe)) & SPRITE_ENABLE;
702
703 intel_display_power_put(dev_priv, power_domain);
704
705 return ret;
706}
707
708static u32 g4x_sprite_ctl(const struct intel_crtc_state *crtc_state,
709 const struct intel_plane_state *plane_state)
710{
711 struct drm_i915_private *dev_priv =
712 to_i915(plane_state->base.plane->dev);
713 const struct drm_framebuffer *fb = plane_state->base.fb;
714 unsigned int rotation = plane_state->base.rotation;
715 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
716 u32 dvscntr;
717
718 dvscntr = DVS_ENABLE | DVS_GAMMA_ENABLE;
719
720 if (IS_GEN6(dev_priv))
721 dvscntr |= DVS_TRICKLE_FEED_DISABLE;
722
723 switch (fb->format->format) {
724 case DRM_FORMAT_XBGR8888:
725 dvscntr |= DVS_FORMAT_RGBX888 | DVS_RGB_ORDER_XBGR;
726 break;
727 case DRM_FORMAT_XRGB8888:
728 dvscntr |= DVS_FORMAT_RGBX888;
729 break;
730 case DRM_FORMAT_YUYV:
731 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YUYV;
732 break;
733 case DRM_FORMAT_YVYU:
734 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YVYU;
735 break;
736 case DRM_FORMAT_UYVY:
737 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_UYVY;
738 break;
739 case DRM_FORMAT_VYUY:
740 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_VYUY;
741 break;
742 default:
743 MISSING_CASE(fb->format->format);
744 return 0;
745 }
746
747 if (fb->modifier == I915_FORMAT_MOD_X_TILED)
748 dvscntr |= DVS_TILED;
749
750 if (rotation & DRM_MODE_ROTATE_180)
751 dvscntr |= DVS_ROTATE_180;
752
753 if (key->flags & I915_SET_COLORKEY_DESTINATION)
754 dvscntr |= DVS_DEST_KEY;
755 else if (key->flags & I915_SET_COLORKEY_SOURCE)
756 dvscntr |= DVS_SOURCE_KEY;
757
758 return dvscntr;
759}
760
761static void
762g4x_update_plane(struct intel_plane *plane,
763 const struct intel_crtc_state *crtc_state,
764 const struct intel_plane_state *plane_state)
765{
766 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
767 const struct drm_framebuffer *fb = plane_state->base.fb;
768 enum pipe pipe = plane->pipe;
769 u32 dvscntr = plane_state->ctl, dvsscale = 0;
770 u32 dvssurf_offset = plane_state->main.offset;
771 u32 linear_offset;
772 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
773 int crtc_x = plane_state->base.dst.x1;
774 int crtc_y = plane_state->base.dst.y1;
775 uint32_t crtc_w = drm_rect_width(&plane_state->base.dst);
776 uint32_t crtc_h = drm_rect_height(&plane_state->base.dst);
777 uint32_t x = plane_state->main.x;
778 uint32_t y = plane_state->main.y;
779 uint32_t src_w = drm_rect_width(&plane_state->base.src) >> 16;
780 uint32_t src_h = drm_rect_height(&plane_state->base.src) >> 16;
781 unsigned long irqflags;
782
783
784 src_w--;
785 src_h--;
786 crtc_w--;
787 crtc_h--;
788
789 if (crtc_w != src_w || crtc_h != src_h)
790 dvsscale = DVS_SCALE_ENABLE | (src_w << 16) | src_h;
791
792 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
793
794 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
795
796 if (key->flags) {
797 I915_WRITE_FW(DVSKEYVAL(pipe), key->min_value);
798 I915_WRITE_FW(DVSKEYMAX(pipe), key->max_value);
799 I915_WRITE_FW(DVSKEYMSK(pipe), key->channel_mask);
800 }
801
802 I915_WRITE_FW(DVSSTRIDE(pipe), fb->pitches[0]);
803 I915_WRITE_FW(DVSPOS(pipe), (crtc_y << 16) | crtc_x);
804
805 if (fb->modifier == I915_FORMAT_MOD_X_TILED)
806 I915_WRITE_FW(DVSTILEOFF(pipe), (y << 16) | x);
807 else
808 I915_WRITE_FW(DVSLINOFF(pipe), linear_offset);
809
810 I915_WRITE_FW(DVSSIZE(pipe), (crtc_h << 16) | crtc_w);
811 I915_WRITE_FW(DVSSCALE(pipe), dvsscale);
812 I915_WRITE_FW(DVSCNTR(pipe), dvscntr);
813 I915_WRITE_FW(DVSSURF(pipe),
814 intel_plane_ggtt_offset(plane_state) + dvssurf_offset);
815 POSTING_READ_FW(DVSSURF(pipe));
816
817 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
818}
819
820static void
821g4x_disable_plane(struct intel_plane *plane, struct intel_crtc *crtc)
822{
823 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
824 enum pipe pipe = plane->pipe;
825 unsigned long irqflags;
826
827 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
828
829 I915_WRITE_FW(DVSCNTR(pipe), 0);
830
831 I915_WRITE_FW(DVSSCALE(pipe), 0);
832
833 I915_WRITE_FW(DVSSURF(pipe), 0);
834 POSTING_READ_FW(DVSSURF(pipe));
835
836 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
837}
838
839static bool
840g4x_plane_get_hw_state(struct intel_plane *plane)
841{
842 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
843 enum intel_display_power_domain power_domain;
844 enum pipe pipe = plane->pipe;
845 bool ret;
846
847 power_domain = POWER_DOMAIN_PIPE(pipe);
848 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
849 return false;
850
851 ret = I915_READ(DVSCNTR(pipe)) & DVS_ENABLE;
852
853 intel_display_power_put(dev_priv, power_domain);
854
855 return ret;
856}
857
858static int
859intel_check_sprite_plane(struct intel_plane *plane,
860 struct intel_crtc_state *crtc_state,
861 struct intel_plane_state *state)
862{
863 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
864 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
865 struct drm_framebuffer *fb = state->base.fb;
866 int crtc_x, crtc_y;
867 unsigned int crtc_w, crtc_h;
868 uint32_t src_x, src_y, src_w, src_h;
869 struct drm_rect *src = &state->base.src;
870 struct drm_rect *dst = &state->base.dst;
871 const struct drm_rect *clip = &state->clip;
872 int hscale, vscale;
873 int max_scale, min_scale;
874 bool can_scale;
875 int ret;
876
877 *src = drm_plane_state_src(&state->base);
878 *dst = drm_plane_state_dest(&state->base);
879
880 if (!fb) {
881 state->base.visible = false;
882 return 0;
883 }
884
885
886 if (plane->pipe != crtc->pipe) {
887 DRM_DEBUG_KMS("Wrong plane <-> crtc mapping\n");
888 return -EINVAL;
889 }
890
891
892 if (fb->width < 3 || fb->height < 3 || fb->pitches[0] > 16384) {
893 DRM_DEBUG_KMS("Unsuitable framebuffer for plane\n");
894 return -EINVAL;
895 }
896
897
898 if (INTEL_GEN(dev_priv) >= 9) {
899
900 if (state->ckey.flags == I915_SET_COLORKEY_NONE) {
901 can_scale = 1;
902 min_scale = 1;
903 max_scale = skl_max_scale(crtc, crtc_state);
904 } else {
905 can_scale = 0;
906 min_scale = DRM_PLANE_HELPER_NO_SCALING;
907 max_scale = DRM_PLANE_HELPER_NO_SCALING;
908 }
909 } else {
910 can_scale = plane->can_scale;
911 max_scale = plane->max_downscale << 16;
912 min_scale = plane->can_scale ? 1 : (1 << 16);
913 }
914
915
916
917
918
919
920 drm_rect_rotate(src, fb->width << 16, fb->height << 16,
921 state->base.rotation);
922
923 hscale = drm_rect_calc_hscale_relaxed(src, dst, min_scale, max_scale);
924 BUG_ON(hscale < 0);
925
926 vscale = drm_rect_calc_vscale_relaxed(src, dst, min_scale, max_scale);
927 BUG_ON(vscale < 0);
928
929 state->base.visible = drm_rect_clip_scaled(src, dst, clip, hscale, vscale);
930
931 crtc_x = dst->x1;
932 crtc_y = dst->y1;
933 crtc_w = drm_rect_width(dst);
934 crtc_h = drm_rect_height(dst);
935
936 if (state->base.visible) {
937
938 hscale = drm_rect_calc_hscale(src, dst, min_scale, max_scale);
939 if (hscale < 0) {
940 DRM_DEBUG_KMS("Horizontal scaling factor out of limits\n");
941 drm_rect_debug_print("src: ", src, true);
942 drm_rect_debug_print("dst: ", dst, false);
943
944 return hscale;
945 }
946
947 vscale = drm_rect_calc_vscale(src, dst, min_scale, max_scale);
948 if (vscale < 0) {
949 DRM_DEBUG_KMS("Vertical scaling factor out of limits\n");
950 drm_rect_debug_print("src: ", src, true);
951 drm_rect_debug_print("dst: ", dst, false);
952
953 return vscale;
954 }
955
956
957 drm_rect_adjust_size(src,
958 drm_rect_width(dst) * hscale - drm_rect_width(src),
959 drm_rect_height(dst) * vscale - drm_rect_height(src));
960
961 drm_rect_rotate_inv(src, fb->width << 16, fb->height << 16,
962 state->base.rotation);
963
964
965 WARN_ON(src->x1 < (int) state->base.src_x ||
966 src->y1 < (int) state->base.src_y ||
967 src->x2 > (int) state->base.src_x + state->base.src_w ||
968 src->y2 > (int) state->base.src_y + state->base.src_h);
969
970
971
972
973
974
975
976 src_x = src->x1 >> 16;
977 src_w = drm_rect_width(src) >> 16;
978 src_y = src->y1 >> 16;
979 src_h = drm_rect_height(src) >> 16;
980
981 if (format_is_yuv(fb->format->format)) {
982 src_x &= ~1;
983 src_w &= ~1;
984
985
986
987
988
989 if (!can_scale)
990 crtc_w &= ~1;
991
992 if (crtc_w == 0)
993 state->base.visible = false;
994 }
995 }
996
997
998 if (state->base.visible && (src_w != crtc_w || src_h != crtc_h)) {
999 unsigned int width_bytes;
1000 int cpp = fb->format->cpp[0];
1001
1002 WARN_ON(!can_scale);
1003
1004
1005
1006 if (crtc_w < 3 || crtc_h < 3)
1007 state->base.visible = false;
1008
1009 if (src_w < 3 || src_h < 3)
1010 state->base.visible = false;
1011
1012 width_bytes = ((src_x * cpp) & 63) + src_w * cpp;
1013
1014 if (INTEL_GEN(dev_priv) < 9 && (src_w > 2048 || src_h > 2048 ||
1015 width_bytes > 4096 || fb->pitches[0] > 4096)) {
1016 DRM_DEBUG_KMS("Source dimensions exceed hardware limits\n");
1017 return -EINVAL;
1018 }
1019 }
1020
1021 if (state->base.visible) {
1022 src->x1 = src_x << 16;
1023 src->x2 = (src_x + src_w) << 16;
1024 src->y1 = src_y << 16;
1025 src->y2 = (src_y + src_h) << 16;
1026 }
1027
1028 dst->x1 = crtc_x;
1029 dst->x2 = crtc_x + crtc_w;
1030 dst->y1 = crtc_y;
1031 dst->y2 = crtc_y + crtc_h;
1032
1033 if (INTEL_GEN(dev_priv) >= 9) {
1034 ret = skl_check_plane_surface(state);
1035 if (ret)
1036 return ret;
1037
1038 state->ctl = skl_plane_ctl(crtc_state, state);
1039 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
1040 ret = i9xx_check_plane_surface(state);
1041 if (ret)
1042 return ret;
1043
1044 state->ctl = vlv_sprite_ctl(crtc_state, state);
1045 } else if (INTEL_GEN(dev_priv) >= 7) {
1046 ret = i9xx_check_plane_surface(state);
1047 if (ret)
1048 return ret;
1049
1050 state->ctl = ivb_sprite_ctl(crtc_state, state);
1051 } else {
1052 ret = i9xx_check_plane_surface(state);
1053 if (ret)
1054 return ret;
1055
1056 state->ctl = g4x_sprite_ctl(crtc_state, state);
1057 }
1058
1059 return 0;
1060}
1061
1062int intel_sprite_set_colorkey(struct drm_device *dev, void *data,
1063 struct drm_file *file_priv)
1064{
1065 struct drm_i915_private *dev_priv = to_i915(dev);
1066 struct drm_intel_sprite_colorkey *set = data;
1067 struct drm_plane *plane;
1068 struct drm_plane_state *plane_state;
1069 struct drm_atomic_state *state;
1070 struct drm_modeset_acquire_ctx ctx;
1071 int ret = 0;
1072
1073
1074 if ((set->flags & (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE)) == (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE))
1075 return -EINVAL;
1076
1077 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
1078 set->flags & I915_SET_COLORKEY_DESTINATION)
1079 return -EINVAL;
1080
1081 plane = drm_plane_find(dev, file_priv, set->plane_id);
1082 if (!plane || plane->type != DRM_PLANE_TYPE_OVERLAY)
1083 return -ENOENT;
1084
1085 drm_modeset_acquire_init(&ctx, 0);
1086
1087 state = drm_atomic_state_alloc(plane->dev);
1088 if (!state) {
1089 ret = -ENOMEM;
1090 goto out;
1091 }
1092 state->acquire_ctx = &ctx;
1093
1094 while (1) {
1095 plane_state = drm_atomic_get_plane_state(state, plane);
1096 ret = PTR_ERR_OR_ZERO(plane_state);
1097 if (!ret) {
1098 to_intel_plane_state(plane_state)->ckey = *set;
1099 ret = drm_atomic_commit(state);
1100 }
1101
1102 if (ret != -EDEADLK)
1103 break;
1104
1105 drm_atomic_state_clear(state);
1106 drm_modeset_backoff(&ctx);
1107 }
1108
1109 drm_atomic_state_put(state);
1110out:
1111 drm_modeset_drop_locks(&ctx);
1112 drm_modeset_acquire_fini(&ctx);
1113 return ret;
1114}
1115
1116static const uint32_t g4x_plane_formats[] = {
1117 DRM_FORMAT_XRGB8888,
1118 DRM_FORMAT_YUYV,
1119 DRM_FORMAT_YVYU,
1120 DRM_FORMAT_UYVY,
1121 DRM_FORMAT_VYUY,
1122};
1123
1124static const uint64_t i9xx_plane_format_modifiers[] = {
1125 I915_FORMAT_MOD_X_TILED,
1126 DRM_FORMAT_MOD_LINEAR,
1127 DRM_FORMAT_MOD_INVALID
1128};
1129
1130static const uint32_t snb_plane_formats[] = {
1131 DRM_FORMAT_XBGR8888,
1132 DRM_FORMAT_XRGB8888,
1133 DRM_FORMAT_YUYV,
1134 DRM_FORMAT_YVYU,
1135 DRM_FORMAT_UYVY,
1136 DRM_FORMAT_VYUY,
1137};
1138
1139static const uint32_t vlv_plane_formats[] = {
1140 DRM_FORMAT_RGB565,
1141 DRM_FORMAT_ABGR8888,
1142 DRM_FORMAT_ARGB8888,
1143 DRM_FORMAT_XBGR8888,
1144 DRM_FORMAT_XRGB8888,
1145 DRM_FORMAT_XBGR2101010,
1146 DRM_FORMAT_ABGR2101010,
1147 DRM_FORMAT_YUYV,
1148 DRM_FORMAT_YVYU,
1149 DRM_FORMAT_UYVY,
1150 DRM_FORMAT_VYUY,
1151};
1152
1153static uint32_t skl_plane_formats[] = {
1154 DRM_FORMAT_RGB565,
1155 DRM_FORMAT_ABGR8888,
1156 DRM_FORMAT_ARGB8888,
1157 DRM_FORMAT_XBGR8888,
1158 DRM_FORMAT_XRGB8888,
1159 DRM_FORMAT_YUYV,
1160 DRM_FORMAT_YVYU,
1161 DRM_FORMAT_UYVY,
1162 DRM_FORMAT_VYUY,
1163};
1164
1165static const uint64_t skl_plane_format_modifiers[] = {
1166 I915_FORMAT_MOD_X_TILED,
1167 DRM_FORMAT_MOD_LINEAR,
1168 DRM_FORMAT_MOD_INVALID
1169};
1170
1171static bool g4x_sprite_plane_format_mod_supported(struct drm_plane *plane,
1172 uint32_t format,
1173 uint64_t modifier)
1174{
1175 switch (format) {
1176 case DRM_FORMAT_XBGR8888:
1177 case DRM_FORMAT_XRGB8888:
1178 case DRM_FORMAT_YUYV:
1179 case DRM_FORMAT_YVYU:
1180 case DRM_FORMAT_UYVY:
1181 case DRM_FORMAT_VYUY:
1182 if (modifier == DRM_FORMAT_MOD_LINEAR ||
1183 modifier == I915_FORMAT_MOD_X_TILED)
1184 return true;
1185
1186 default:
1187 return false;
1188 }
1189}
1190
1191static bool vlv_sprite_plane_format_mod_supported(struct drm_plane *plane,
1192 uint32_t format,
1193 uint64_t modifier)
1194{
1195 switch (format) {
1196 case DRM_FORMAT_YUYV:
1197 case DRM_FORMAT_YVYU:
1198 case DRM_FORMAT_UYVY:
1199 case DRM_FORMAT_VYUY:
1200 case DRM_FORMAT_RGB565:
1201 case DRM_FORMAT_XRGB8888:
1202 case DRM_FORMAT_ARGB8888:
1203 case DRM_FORMAT_XBGR2101010:
1204 case DRM_FORMAT_ABGR2101010:
1205 case DRM_FORMAT_XBGR8888:
1206 case DRM_FORMAT_ABGR8888:
1207 if (modifier == DRM_FORMAT_MOD_LINEAR ||
1208 modifier == I915_FORMAT_MOD_X_TILED)
1209 return true;
1210
1211 default:
1212 return false;
1213 }
1214}
1215
1216static bool skl_sprite_plane_format_mod_supported(struct drm_plane *plane,
1217 uint32_t format,
1218 uint64_t modifier)
1219{
1220
1221 switch (format) {
1222 case DRM_FORMAT_XRGB8888:
1223 case DRM_FORMAT_XBGR8888:
1224 case DRM_FORMAT_ARGB8888:
1225 case DRM_FORMAT_ABGR8888:
1226 case DRM_FORMAT_RGB565:
1227 case DRM_FORMAT_XRGB2101010:
1228 case DRM_FORMAT_XBGR2101010:
1229 case DRM_FORMAT_YUYV:
1230 case DRM_FORMAT_YVYU:
1231 case DRM_FORMAT_UYVY:
1232 case DRM_FORMAT_VYUY:
1233 if (modifier == I915_FORMAT_MOD_Yf_TILED)
1234 return true;
1235
1236 case DRM_FORMAT_C8:
1237 if (modifier == DRM_FORMAT_MOD_LINEAR ||
1238 modifier == I915_FORMAT_MOD_X_TILED ||
1239 modifier == I915_FORMAT_MOD_Y_TILED)
1240 return true;
1241
1242 default:
1243 return false;
1244 }
1245}
1246
1247static bool intel_sprite_plane_format_mod_supported(struct drm_plane *plane,
1248 uint32_t format,
1249 uint64_t modifier)
1250{
1251 struct drm_i915_private *dev_priv = to_i915(plane->dev);
1252
1253 if (WARN_ON(modifier == DRM_FORMAT_MOD_INVALID))
1254 return false;
1255
1256 if ((modifier >> 56) != DRM_FORMAT_MOD_VENDOR_INTEL &&
1257 modifier != DRM_FORMAT_MOD_LINEAR)
1258 return false;
1259
1260 if (INTEL_GEN(dev_priv) >= 9)
1261 return skl_sprite_plane_format_mod_supported(plane, format, modifier);
1262 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
1263 return vlv_sprite_plane_format_mod_supported(plane, format, modifier);
1264 else
1265 return g4x_sprite_plane_format_mod_supported(plane, format, modifier);
1266
1267 unreachable();
1268}
1269
1270static const struct drm_plane_funcs intel_sprite_plane_funcs = {
1271 .update_plane = drm_atomic_helper_update_plane,
1272 .disable_plane = drm_atomic_helper_disable_plane,
1273 .destroy = intel_plane_destroy,
1274 .atomic_get_property = intel_plane_atomic_get_property,
1275 .atomic_set_property = intel_plane_atomic_set_property,
1276 .atomic_duplicate_state = intel_plane_duplicate_state,
1277 .atomic_destroy_state = intel_plane_destroy_state,
1278 .format_mod_supported = intel_sprite_plane_format_mod_supported,
1279};
1280
1281struct intel_plane *
1282intel_sprite_plane_create(struct drm_i915_private *dev_priv,
1283 enum pipe pipe, int plane)
1284{
1285 struct intel_plane *intel_plane = NULL;
1286 struct intel_plane_state *state = NULL;
1287 unsigned long possible_crtcs;
1288 const uint32_t *plane_formats;
1289 const uint64_t *modifiers;
1290 unsigned int supported_rotations;
1291 int num_plane_formats;
1292 int ret;
1293
1294 intel_plane = kzalloc(sizeof(*intel_plane), GFP_KERNEL);
1295 if (!intel_plane) {
1296 ret = -ENOMEM;
1297 goto fail;
1298 }
1299
1300 state = intel_create_plane_state(&intel_plane->base);
1301 if (!state) {
1302 ret = -ENOMEM;
1303 goto fail;
1304 }
1305 intel_plane->base.state = &state->base;
1306
1307 if (INTEL_GEN(dev_priv) >= 10) {
1308 intel_plane->can_scale = true;
1309 state->scaler_id = -1;
1310
1311 intel_plane->update_plane = skl_update_plane;
1312 intel_plane->disable_plane = skl_disable_plane;
1313 intel_plane->get_hw_state = skl_plane_get_hw_state;
1314
1315 plane_formats = skl_plane_formats;
1316 num_plane_formats = ARRAY_SIZE(skl_plane_formats);
1317 modifiers = skl_plane_format_modifiers;
1318 } else if (INTEL_GEN(dev_priv) >= 9) {
1319 intel_plane->can_scale = true;
1320 state->scaler_id = -1;
1321
1322 intel_plane->update_plane = skl_update_plane;
1323 intel_plane->disable_plane = skl_disable_plane;
1324 intel_plane->get_hw_state = skl_plane_get_hw_state;
1325
1326 plane_formats = skl_plane_formats;
1327 num_plane_formats = ARRAY_SIZE(skl_plane_formats);
1328 modifiers = skl_plane_format_modifiers;
1329 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
1330 intel_plane->can_scale = false;
1331 intel_plane->max_downscale = 1;
1332
1333 intel_plane->update_plane = vlv_update_plane;
1334 intel_plane->disable_plane = vlv_disable_plane;
1335 intel_plane->get_hw_state = vlv_plane_get_hw_state;
1336
1337 plane_formats = vlv_plane_formats;
1338 num_plane_formats = ARRAY_SIZE(vlv_plane_formats);
1339 modifiers = i9xx_plane_format_modifiers;
1340 } else if (INTEL_GEN(dev_priv) >= 7) {
1341 if (IS_IVYBRIDGE(dev_priv)) {
1342 intel_plane->can_scale = true;
1343 intel_plane->max_downscale = 2;
1344 } else {
1345 intel_plane->can_scale = false;
1346 intel_plane->max_downscale = 1;
1347 }
1348
1349 intel_plane->update_plane = ivb_update_plane;
1350 intel_plane->disable_plane = ivb_disable_plane;
1351 intel_plane->get_hw_state = ivb_plane_get_hw_state;
1352
1353 plane_formats = snb_plane_formats;
1354 num_plane_formats = ARRAY_SIZE(snb_plane_formats);
1355 modifiers = i9xx_plane_format_modifiers;
1356 } else {
1357 intel_plane->can_scale = true;
1358 intel_plane->max_downscale = 16;
1359
1360 intel_plane->update_plane = g4x_update_plane;
1361 intel_plane->disable_plane = g4x_disable_plane;
1362 intel_plane->get_hw_state = g4x_plane_get_hw_state;
1363
1364 modifiers = i9xx_plane_format_modifiers;
1365 if (IS_GEN6(dev_priv)) {
1366 plane_formats = snb_plane_formats;
1367 num_plane_formats = ARRAY_SIZE(snb_plane_formats);
1368 } else {
1369 plane_formats = g4x_plane_formats;
1370 num_plane_formats = ARRAY_SIZE(g4x_plane_formats);
1371 }
1372 }
1373
1374 if (INTEL_GEN(dev_priv) >= 9) {
1375 supported_rotations =
1376 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_90 |
1377 DRM_MODE_ROTATE_180 | DRM_MODE_ROTATE_270;
1378 } else if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
1379 supported_rotations =
1380 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 |
1381 DRM_MODE_REFLECT_X;
1382 } else {
1383 supported_rotations =
1384 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180;
1385 }
1386
1387 intel_plane->pipe = pipe;
1388 intel_plane->plane = plane;
1389 intel_plane->id = PLANE_SPRITE0 + plane;
1390 intel_plane->frontbuffer_bit = INTEL_FRONTBUFFER_SPRITE(pipe, plane);
1391 intel_plane->check_plane = intel_check_sprite_plane;
1392
1393 possible_crtcs = (1 << pipe);
1394
1395 if (INTEL_GEN(dev_priv) >= 9)
1396 ret = drm_universal_plane_init(&dev_priv->drm, &intel_plane->base,
1397 possible_crtcs, &intel_sprite_plane_funcs,
1398 plane_formats, num_plane_formats,
1399 modifiers,
1400 DRM_PLANE_TYPE_OVERLAY,
1401 "plane %d%c", plane + 2, pipe_name(pipe));
1402 else
1403 ret = drm_universal_plane_init(&dev_priv->drm, &intel_plane->base,
1404 possible_crtcs, &intel_sprite_plane_funcs,
1405 plane_formats, num_plane_formats,
1406 modifiers,
1407 DRM_PLANE_TYPE_OVERLAY,
1408 "sprite %c", sprite_name(pipe, plane));
1409 if (ret)
1410 goto fail;
1411
1412 drm_plane_create_rotation_property(&intel_plane->base,
1413 DRM_MODE_ROTATE_0,
1414 supported_rotations);
1415
1416 drm_plane_helper_add(&intel_plane->base, &intel_plane_helper_funcs);
1417
1418 return intel_plane;
1419
1420fail:
1421 kfree(state);
1422 kfree(intel_plane);
1423
1424 return ERR_PTR(ret);
1425}
1426