Merge branch 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[cris-mirror.git] / drivers / gpu / drm / i915 / intel_sprite.c
blobdd485f59eb1dcfe795896d718047460405a7dcfd
1 /*
2 * Copyright © 2011 Intel Corporation
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:
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.
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.
23 * Authors:
24 * Jesse Barnes <jbarnes@virtuousgeek.org>
26 * New plane/sprite handling.
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.
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"
44 static bool
45 format_is_yuv(uint32_t format)
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;
58 int intel_usecs_to_scanlines(const struct drm_display_mode *adjusted_mode,
59 int usecs)
61 /* paranoia */
62 if (!adjusted_mode->crtc_htotal)
63 return 1;
65 return DIV_ROUND_UP(usecs * adjusted_mode->crtc_clock,
66 1000 * adjusted_mode->crtc_htotal);
69 /* FIXME: We should instead only take spinlocks once for the entire update
70 * instead of once per mmio. */
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
77 /**
78 * intel_pipe_update_start() - start update of a set of display registers
79 * @new_crtc_state: the new crtc state
81 * Mark the start of an update to pipe registers that should be updated
82 * atomically regarding vblank. If the next vblank will happens within
83 * the next 100 us, this function waits until the vblank passes.
85 * After a successful call to this function, interrupts will be disabled
86 * until a subsequent call to intel_pipe_update_end(). That is done to
87 * avoid random delays.
89 void intel_pipe_update_start(const struct intel_crtc_state *new_crtc_state)
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);
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);
105 /* FIXME needs to be calibrated sensibly */
106 min = vblank_start - intel_usecs_to_scanlines(adjusted_mode,
107 VBLANK_EVASION_TIME_US);
108 max = vblank_start - 1;
110 local_irq_disable();
112 if (min <= 0 || max <= 0)
113 return;
115 if (WARN_ON(drm_crtc_vblank_get(&crtc->base)))
116 return;
118 crtc->debug.min_vbl = min;
119 crtc->debug.max_vbl = max;
120 trace_i915_pipe_update_start(crtc);
122 for (;;) {
124 * prepare_to_wait() has a memory barrier, which guarantees
125 * other CPUs can see the task state update by the time we
126 * read the scanline.
128 prepare_to_wait(wq, &wait, TASK_UNINTERRUPTIBLE);
130 scanline = intel_get_crtc_scanline(crtc);
131 if (scanline < min || scanline > max)
132 break;
134 if (timeout <= 0) {
135 DRM_ERROR("Potential atomic update failure on pipe %c\n",
136 pipe_name(crtc->pipe));
137 break;
140 local_irq_enable();
142 timeout = schedule_timeout(timeout);
144 local_irq_disable();
147 finish_wait(wq, &wait);
149 drm_crtc_vblank_put(&crtc->base);
152 * On VLV/CHV DSI the scanline counter would appear to
153 * increment approx. 1/3 of a scanline before start of vblank.
154 * The registers still get latched at start of vblank however.
155 * This means we must not write any registers on the first
156 * line of vblank (since not the whole line is actually in
157 * vblank). And unfortunately we can't use the interrupt to
158 * wait here since it will fire too soon. We could use the
159 * frame start interrupt instead since it will fire after the
160 * critical scanline, but that would require more changes
161 * in the interrupt code. So for now we'll just do the nasty
162 * thing and poll for the bad scanline to pass us by.
164 * FIXME figure out if BXT+ DSI suffers from this as well
166 while (need_vlv_dsi_wa && scanline == vblank_start)
167 scanline = intel_get_crtc_scanline(crtc);
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);
173 trace_i915_pipe_update_vblank_evaded(crtc);
177 * intel_pipe_update_end() - end update of a set of display registers
178 * @new_crtc_state: the new crtc state
180 * Mark the end of an update started with intel_pipe_update_start(). This
181 * re-enables interrupts and verifies the update was actually completed
182 * before a vblank.
184 void intel_pipe_update_end(struct intel_crtc_state *new_crtc_state)
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);
193 trace_i915_pipe_update_end(crtc, end_vbl_count, scanline_end);
195 /* We're still in the vblank-evade critical section, this can't race.
196 * Would be slightly nice to just grab the vblank count and arm the
197 * event outside of the critical section - the spinlock might spin for a
198 * while ... */
199 if (new_crtc_state->base.event) {
200 WARN_ON(drm_crtc_vblank_get(&crtc->base) != 0);
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);
206 new_crtc_state->base.event = NULL;
209 local_irq_enable();
211 if (intel_vgpu_active(dev_priv))
212 return;
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);
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
233 void
234 skl_update_plane(struct intel_plane *plane,
235 const struct intel_crtc_state *crtc_state,
236 const struct intel_plane_state *plane_state)
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;
258 /* Sizes are 0 based */
259 src_w--;
260 src_h--;
261 crtc_w--;
262 crtc_h--;
264 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
266 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
267 I915_WRITE_FW(PLANE_COLOR_CTL(pipe, plane_id),
268 plane_state->color_ctl);
269 if (key->flags) {
270 I915_WRITE_FW(PLANE_KEYVAL(pipe, plane_id), key->min_value);
271 I915_WRITE_FW(PLANE_KEYMAX(pipe, plane_id), key->max_value);
272 I915_WRITE_FW(PLANE_KEYMSK(pipe, plane_id), key->channel_mask);
275 I915_WRITE_FW(PLANE_OFFSET(pipe, plane_id), (y << 16) | x);
276 I915_WRITE_FW(PLANE_STRIDE(pipe, plane_id), stride);
277 I915_WRITE_FW(PLANE_SIZE(pipe, plane_id), (src_h << 16) | src_w);
278 I915_WRITE_FW(PLANE_AUX_DIST(pipe, plane_id),
279 (plane_state->aux.offset - surf_addr) | aux_stride);
280 I915_WRITE_FW(PLANE_AUX_OFFSET(pipe, plane_id),
281 (plane_state->aux.y << 16) | plane_state->aux.x);
283 /* program plane scaler */
284 if (plane_state->scaler_id >= 0) {
285 int scaler_id = plane_state->scaler_id;
286 const struct intel_scaler *scaler;
288 scaler = &crtc_state->scaler_state.scalers[scaler_id];
290 I915_WRITE_FW(SKL_PS_CTRL(pipe, scaler_id),
291 PS_SCALER_EN | PS_PLANE_SEL(plane_id) | scaler->mode);
292 I915_WRITE_FW(SKL_PS_PWR_GATE(pipe, scaler_id), 0);
293 I915_WRITE_FW(SKL_PS_WIN_POS(pipe, scaler_id), (crtc_x << 16) | crtc_y);
294 I915_WRITE_FW(SKL_PS_WIN_SZ(pipe, scaler_id),
295 ((crtc_w + 1) << 16)|(crtc_h + 1));
297 I915_WRITE_FW(PLANE_POS(pipe, plane_id), 0);
298 } else {
299 I915_WRITE_FW(PLANE_POS(pipe, plane_id), (crtc_y << 16) | crtc_x);
302 I915_WRITE_FW(PLANE_CTL(pipe, plane_id), plane_ctl);
303 I915_WRITE_FW(PLANE_SURF(pipe, plane_id),
304 intel_plane_ggtt_offset(plane_state) + surf_addr);
305 POSTING_READ_FW(PLANE_SURF(pipe, plane_id));
307 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
310 void
311 skl_disable_plane(struct intel_plane *plane, struct intel_crtc *crtc)
313 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
314 enum plane_id plane_id = plane->id;
315 enum pipe pipe = plane->pipe;
316 unsigned long irqflags;
318 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
320 I915_WRITE_FW(PLANE_CTL(pipe, plane_id), 0);
322 I915_WRITE_FW(PLANE_SURF(pipe, plane_id), 0);
323 POSTING_READ_FW(PLANE_SURF(pipe, plane_id));
325 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
328 bool
329 skl_plane_get_hw_state(struct intel_plane *plane)
331 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
332 enum intel_display_power_domain power_domain;
333 enum plane_id plane_id = plane->id;
334 enum pipe pipe = plane->pipe;
335 bool ret;
337 power_domain = POWER_DOMAIN_PIPE(pipe);
338 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
339 return false;
341 ret = I915_READ(PLANE_CTL(pipe, plane_id)) & PLANE_CTL_ENABLE;
343 intel_display_power_put(dev_priv, power_domain);
345 return ret;
348 static void
349 chv_update_csc(struct intel_plane *plane, uint32_t format)
351 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
352 enum plane_id plane_id = plane->id;
354 /* Seems RGB data bypasses the CSC always */
355 if (!format_is_yuv(format))
356 return;
359 * BT.601 limited range YCbCr -> full range RGB
361 * |r| | 6537 4769 0| |cr |
362 * |g| = |-3330 4769 -1605| x |y-64|
363 * |b| | 0 4769 8263| |cb |
365 * Cb and Cr apparently come in as signed already, so no
366 * need for any offset. For Y we need to remove the offset.
368 I915_WRITE_FW(SPCSCYGOFF(plane_id), SPCSC_OOFF(0) | SPCSC_IOFF(-64));
369 I915_WRITE_FW(SPCSCCBOFF(plane_id), SPCSC_OOFF(0) | SPCSC_IOFF(0));
370 I915_WRITE_FW(SPCSCCROFF(plane_id), SPCSC_OOFF(0) | SPCSC_IOFF(0));
372 I915_WRITE_FW(SPCSCC01(plane_id), SPCSC_C1(4769) | SPCSC_C0(6537));
373 I915_WRITE_FW(SPCSCC23(plane_id), SPCSC_C1(-3330) | SPCSC_C0(0));
374 I915_WRITE_FW(SPCSCC45(plane_id), SPCSC_C1(-1605) | SPCSC_C0(4769));
375 I915_WRITE_FW(SPCSCC67(plane_id), SPCSC_C1(4769) | SPCSC_C0(0));
376 I915_WRITE_FW(SPCSCC8(plane_id), SPCSC_C0(8263));
378 I915_WRITE_FW(SPCSCYGICLAMP(plane_id), SPCSC_IMAX(940) | SPCSC_IMIN(64));
379 I915_WRITE_FW(SPCSCCBICLAMP(plane_id), SPCSC_IMAX(448) | SPCSC_IMIN(-448));
380 I915_WRITE_FW(SPCSCCRICLAMP(plane_id), SPCSC_IMAX(448) | SPCSC_IMIN(-448));
382 I915_WRITE_FW(SPCSCYGOCLAMP(plane_id), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
383 I915_WRITE_FW(SPCSCCBOCLAMP(plane_id), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
384 I915_WRITE_FW(SPCSCCROCLAMP(plane_id), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
387 static u32 vlv_sprite_ctl(const struct intel_crtc_state *crtc_state,
388 const struct intel_plane_state *plane_state)
390 const struct drm_framebuffer *fb = plane_state->base.fb;
391 unsigned int rotation = plane_state->base.rotation;
392 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
393 u32 sprctl;
395 sprctl = SP_ENABLE | SP_GAMMA_ENABLE;
397 switch (fb->format->format) {
398 case DRM_FORMAT_YUYV:
399 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YUYV;
400 break;
401 case DRM_FORMAT_YVYU:
402 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YVYU;
403 break;
404 case DRM_FORMAT_UYVY:
405 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_UYVY;
406 break;
407 case DRM_FORMAT_VYUY:
408 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_VYUY;
409 break;
410 case DRM_FORMAT_RGB565:
411 sprctl |= SP_FORMAT_BGR565;
412 break;
413 case DRM_FORMAT_XRGB8888:
414 sprctl |= SP_FORMAT_BGRX8888;
415 break;
416 case DRM_FORMAT_ARGB8888:
417 sprctl |= SP_FORMAT_BGRA8888;
418 break;
419 case DRM_FORMAT_XBGR2101010:
420 sprctl |= SP_FORMAT_RGBX1010102;
421 break;
422 case DRM_FORMAT_ABGR2101010:
423 sprctl |= SP_FORMAT_RGBA1010102;
424 break;
425 case DRM_FORMAT_XBGR8888:
426 sprctl |= SP_FORMAT_RGBX8888;
427 break;
428 case DRM_FORMAT_ABGR8888:
429 sprctl |= SP_FORMAT_RGBA8888;
430 break;
431 default:
432 MISSING_CASE(fb->format->format);
433 return 0;
436 if (fb->modifier == I915_FORMAT_MOD_X_TILED)
437 sprctl |= SP_TILED;
439 if (rotation & DRM_MODE_ROTATE_180)
440 sprctl |= SP_ROTATE_180;
442 if (rotation & DRM_MODE_REFLECT_X)
443 sprctl |= SP_MIRROR;
445 if (key->flags & I915_SET_COLORKEY_SOURCE)
446 sprctl |= SP_SOURCE_KEY;
448 return sprctl;
451 static void
452 vlv_update_plane(struct intel_plane *plane,
453 const struct intel_crtc_state *crtc_state,
454 const struct intel_plane_state *plane_state)
456 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
457 const struct drm_framebuffer *fb = plane_state->base.fb;
458 enum pipe pipe = plane->pipe;
459 enum plane_id plane_id = plane->id;
460 u32 sprctl = plane_state->ctl;
461 u32 sprsurf_offset = plane_state->main.offset;
462 u32 linear_offset;
463 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
464 int crtc_x = plane_state->base.dst.x1;
465 int crtc_y = plane_state->base.dst.y1;
466 uint32_t crtc_w = drm_rect_width(&plane_state->base.dst);
467 uint32_t crtc_h = drm_rect_height(&plane_state->base.dst);
468 uint32_t x = plane_state->main.x;
469 uint32_t y = plane_state->main.y;
470 unsigned long irqflags;
472 /* Sizes are 0 based */
473 crtc_w--;
474 crtc_h--;
476 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
478 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
480 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B)
481 chv_update_csc(plane, fb->format->format);
483 if (key->flags) {
484 I915_WRITE_FW(SPKEYMINVAL(pipe, plane_id), key->min_value);
485 I915_WRITE_FW(SPKEYMAXVAL(pipe, plane_id), key->max_value);
486 I915_WRITE_FW(SPKEYMSK(pipe, plane_id), key->channel_mask);
488 I915_WRITE_FW(SPSTRIDE(pipe, plane_id), fb->pitches[0]);
489 I915_WRITE_FW(SPPOS(pipe, plane_id), (crtc_y << 16) | crtc_x);
491 if (fb->modifier == I915_FORMAT_MOD_X_TILED)
492 I915_WRITE_FW(SPTILEOFF(pipe, plane_id), (y << 16) | x);
493 else
494 I915_WRITE_FW(SPLINOFF(pipe, plane_id), linear_offset);
496 I915_WRITE_FW(SPCONSTALPHA(pipe, plane_id), 0);
498 I915_WRITE_FW(SPSIZE(pipe, plane_id), (crtc_h << 16) | crtc_w);
499 I915_WRITE_FW(SPCNTR(pipe, plane_id), sprctl);
500 I915_WRITE_FW(SPSURF(pipe, plane_id),
501 intel_plane_ggtt_offset(plane_state) + sprsurf_offset);
502 POSTING_READ_FW(SPSURF(pipe, plane_id));
504 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
507 static void
508 vlv_disable_plane(struct intel_plane *plane, struct intel_crtc *crtc)
510 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
511 enum pipe pipe = plane->pipe;
512 enum plane_id plane_id = plane->id;
513 unsigned long irqflags;
515 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
517 I915_WRITE_FW(SPCNTR(pipe, plane_id), 0);
519 I915_WRITE_FW(SPSURF(pipe, plane_id), 0);
520 POSTING_READ_FW(SPSURF(pipe, plane_id));
522 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
525 static bool
526 vlv_plane_get_hw_state(struct intel_plane *plane)
528 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
529 enum intel_display_power_domain power_domain;
530 enum plane_id plane_id = plane->id;
531 enum pipe pipe = plane->pipe;
532 bool ret;
534 power_domain = POWER_DOMAIN_PIPE(pipe);
535 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
536 return false;
538 ret = I915_READ(SPCNTR(pipe, plane_id)) & SP_ENABLE;
540 intel_display_power_put(dev_priv, power_domain);
542 return ret;
545 static u32 ivb_sprite_ctl(const struct intel_crtc_state *crtc_state,
546 const struct intel_plane_state *plane_state)
548 struct drm_i915_private *dev_priv =
549 to_i915(plane_state->base.plane->dev);
550 const struct drm_framebuffer *fb = plane_state->base.fb;
551 unsigned int rotation = plane_state->base.rotation;
552 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
553 u32 sprctl;
555 sprctl = SPRITE_ENABLE | SPRITE_GAMMA_ENABLE;
557 if (IS_IVYBRIDGE(dev_priv))
558 sprctl |= SPRITE_TRICKLE_FEED_DISABLE;
560 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
561 sprctl |= SPRITE_PIPE_CSC_ENABLE;
563 switch (fb->format->format) {
564 case DRM_FORMAT_XBGR8888:
565 sprctl |= SPRITE_FORMAT_RGBX888 | SPRITE_RGB_ORDER_RGBX;
566 break;
567 case DRM_FORMAT_XRGB8888:
568 sprctl |= SPRITE_FORMAT_RGBX888;
569 break;
570 case DRM_FORMAT_YUYV:
571 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YUYV;
572 break;
573 case DRM_FORMAT_YVYU:
574 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YVYU;
575 break;
576 case DRM_FORMAT_UYVY:
577 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_UYVY;
578 break;
579 case DRM_FORMAT_VYUY:
580 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_VYUY;
581 break;
582 default:
583 MISSING_CASE(fb->format->format);
584 return 0;
587 if (fb->modifier == I915_FORMAT_MOD_X_TILED)
588 sprctl |= SPRITE_TILED;
590 if (rotation & DRM_MODE_ROTATE_180)
591 sprctl |= SPRITE_ROTATE_180;
593 if (key->flags & I915_SET_COLORKEY_DESTINATION)
594 sprctl |= SPRITE_DEST_KEY;
595 else if (key->flags & I915_SET_COLORKEY_SOURCE)
596 sprctl |= SPRITE_SOURCE_KEY;
598 return sprctl;
601 static void
602 ivb_update_plane(struct intel_plane *plane,
603 const struct intel_crtc_state *crtc_state,
604 const struct intel_plane_state *plane_state)
606 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
607 const struct drm_framebuffer *fb = plane_state->base.fb;
608 enum pipe pipe = plane->pipe;
609 u32 sprctl = plane_state->ctl, sprscale = 0;
610 u32 sprsurf_offset = plane_state->main.offset;
611 u32 linear_offset;
612 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
613 int crtc_x = plane_state->base.dst.x1;
614 int crtc_y = plane_state->base.dst.y1;
615 uint32_t crtc_w = drm_rect_width(&plane_state->base.dst);
616 uint32_t crtc_h = drm_rect_height(&plane_state->base.dst);
617 uint32_t x = plane_state->main.x;
618 uint32_t y = plane_state->main.y;
619 uint32_t src_w = drm_rect_width(&plane_state->base.src) >> 16;
620 uint32_t src_h = drm_rect_height(&plane_state->base.src) >> 16;
621 unsigned long irqflags;
623 /* Sizes are 0 based */
624 src_w--;
625 src_h--;
626 crtc_w--;
627 crtc_h--;
629 if (crtc_w != src_w || crtc_h != src_h)
630 sprscale = SPRITE_SCALE_ENABLE | (src_w << 16) | src_h;
632 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
634 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
636 if (key->flags) {
637 I915_WRITE_FW(SPRKEYVAL(pipe), key->min_value);
638 I915_WRITE_FW(SPRKEYMAX(pipe), key->max_value);
639 I915_WRITE_FW(SPRKEYMSK(pipe), key->channel_mask);
642 I915_WRITE_FW(SPRSTRIDE(pipe), fb->pitches[0]);
643 I915_WRITE_FW(SPRPOS(pipe), (crtc_y << 16) | crtc_x);
645 /* HSW consolidates SPRTILEOFF and SPRLINOFF into a single SPROFFSET
646 * register */
647 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
648 I915_WRITE_FW(SPROFFSET(pipe), (y << 16) | x);
649 else if (fb->modifier == I915_FORMAT_MOD_X_TILED)
650 I915_WRITE_FW(SPRTILEOFF(pipe), (y << 16) | x);
651 else
652 I915_WRITE_FW(SPRLINOFF(pipe), linear_offset);
654 I915_WRITE_FW(SPRSIZE(pipe), (crtc_h << 16) | crtc_w);
655 if (plane->can_scale)
656 I915_WRITE_FW(SPRSCALE(pipe), sprscale);
657 I915_WRITE_FW(SPRCTL(pipe), sprctl);
658 I915_WRITE_FW(SPRSURF(pipe),
659 intel_plane_ggtt_offset(plane_state) + sprsurf_offset);
660 POSTING_READ_FW(SPRSURF(pipe));
662 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
665 static void
666 ivb_disable_plane(struct intel_plane *plane, struct intel_crtc *crtc)
668 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
669 enum pipe pipe = plane->pipe;
670 unsigned long irqflags;
672 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
674 I915_WRITE_FW(SPRCTL(pipe), 0);
675 /* Can't leave the scaler enabled... */
676 if (plane->can_scale)
677 I915_WRITE_FW(SPRSCALE(pipe), 0);
679 I915_WRITE_FW(SPRSURF(pipe), 0);
680 POSTING_READ_FW(SPRSURF(pipe));
682 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
685 static bool
686 ivb_plane_get_hw_state(struct intel_plane *plane)
688 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
689 enum intel_display_power_domain power_domain;
690 enum pipe pipe = plane->pipe;
691 bool ret;
693 power_domain = POWER_DOMAIN_PIPE(pipe);
694 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
695 return false;
697 ret = I915_READ(SPRCTL(pipe)) & SPRITE_ENABLE;
699 intel_display_power_put(dev_priv, power_domain);
701 return ret;
704 static u32 g4x_sprite_ctl(const struct intel_crtc_state *crtc_state,
705 const struct intel_plane_state *plane_state)
707 struct drm_i915_private *dev_priv =
708 to_i915(plane_state->base.plane->dev);
709 const struct drm_framebuffer *fb = plane_state->base.fb;
710 unsigned int rotation = plane_state->base.rotation;
711 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
712 u32 dvscntr;
714 dvscntr = DVS_ENABLE | DVS_GAMMA_ENABLE;
716 if (IS_GEN6(dev_priv))
717 dvscntr |= DVS_TRICKLE_FEED_DISABLE;
719 switch (fb->format->format) {
720 case DRM_FORMAT_XBGR8888:
721 dvscntr |= DVS_FORMAT_RGBX888 | DVS_RGB_ORDER_XBGR;
722 break;
723 case DRM_FORMAT_XRGB8888:
724 dvscntr |= DVS_FORMAT_RGBX888;
725 break;
726 case DRM_FORMAT_YUYV:
727 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YUYV;
728 break;
729 case DRM_FORMAT_YVYU:
730 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YVYU;
731 break;
732 case DRM_FORMAT_UYVY:
733 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_UYVY;
734 break;
735 case DRM_FORMAT_VYUY:
736 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_VYUY;
737 break;
738 default:
739 MISSING_CASE(fb->format->format);
740 return 0;
743 if (fb->modifier == I915_FORMAT_MOD_X_TILED)
744 dvscntr |= DVS_TILED;
746 if (rotation & DRM_MODE_ROTATE_180)
747 dvscntr |= DVS_ROTATE_180;
749 if (key->flags & I915_SET_COLORKEY_DESTINATION)
750 dvscntr |= DVS_DEST_KEY;
751 else if (key->flags & I915_SET_COLORKEY_SOURCE)
752 dvscntr |= DVS_SOURCE_KEY;
754 return dvscntr;
757 static void
758 g4x_update_plane(struct intel_plane *plane,
759 const struct intel_crtc_state *crtc_state,
760 const struct intel_plane_state *plane_state)
762 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
763 const struct drm_framebuffer *fb = plane_state->base.fb;
764 enum pipe pipe = plane->pipe;
765 u32 dvscntr = plane_state->ctl, dvsscale = 0;
766 u32 dvssurf_offset = plane_state->main.offset;
767 u32 linear_offset;
768 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
769 int crtc_x = plane_state->base.dst.x1;
770 int crtc_y = plane_state->base.dst.y1;
771 uint32_t crtc_w = drm_rect_width(&plane_state->base.dst);
772 uint32_t crtc_h = drm_rect_height(&plane_state->base.dst);
773 uint32_t x = plane_state->main.x;
774 uint32_t y = plane_state->main.y;
775 uint32_t src_w = drm_rect_width(&plane_state->base.src) >> 16;
776 uint32_t src_h = drm_rect_height(&plane_state->base.src) >> 16;
777 unsigned long irqflags;
779 /* Sizes are 0 based */
780 src_w--;
781 src_h--;
782 crtc_w--;
783 crtc_h--;
785 if (crtc_w != src_w || crtc_h != src_h)
786 dvsscale = DVS_SCALE_ENABLE | (src_w << 16) | src_h;
788 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
790 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
792 if (key->flags) {
793 I915_WRITE_FW(DVSKEYVAL(pipe), key->min_value);
794 I915_WRITE_FW(DVSKEYMAX(pipe), key->max_value);
795 I915_WRITE_FW(DVSKEYMSK(pipe), key->channel_mask);
798 I915_WRITE_FW(DVSSTRIDE(pipe), fb->pitches[0]);
799 I915_WRITE_FW(DVSPOS(pipe), (crtc_y << 16) | crtc_x);
801 if (fb->modifier == I915_FORMAT_MOD_X_TILED)
802 I915_WRITE_FW(DVSTILEOFF(pipe), (y << 16) | x);
803 else
804 I915_WRITE_FW(DVSLINOFF(pipe), linear_offset);
806 I915_WRITE_FW(DVSSIZE(pipe), (crtc_h << 16) | crtc_w);
807 I915_WRITE_FW(DVSSCALE(pipe), dvsscale);
808 I915_WRITE_FW(DVSCNTR(pipe), dvscntr);
809 I915_WRITE_FW(DVSSURF(pipe),
810 intel_plane_ggtt_offset(plane_state) + dvssurf_offset);
811 POSTING_READ_FW(DVSSURF(pipe));
813 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
816 static void
817 g4x_disable_plane(struct intel_plane *plane, struct intel_crtc *crtc)
819 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
820 enum pipe pipe = plane->pipe;
821 unsigned long irqflags;
823 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
825 I915_WRITE_FW(DVSCNTR(pipe), 0);
826 /* Disable the scaler */
827 I915_WRITE_FW(DVSSCALE(pipe), 0);
829 I915_WRITE_FW(DVSSURF(pipe), 0);
830 POSTING_READ_FW(DVSSURF(pipe));
832 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
835 static bool
836 g4x_plane_get_hw_state(struct intel_plane *plane)
838 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
839 enum intel_display_power_domain power_domain;
840 enum pipe pipe = plane->pipe;
841 bool ret;
843 power_domain = POWER_DOMAIN_PIPE(pipe);
844 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
845 return false;
847 ret = I915_READ(DVSCNTR(pipe)) & DVS_ENABLE;
849 intel_display_power_put(dev_priv, power_domain);
851 return ret;
854 static int
855 intel_check_sprite_plane(struct intel_plane *plane,
856 struct intel_crtc_state *crtc_state,
857 struct intel_plane_state *state)
859 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
860 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
861 struct drm_framebuffer *fb = state->base.fb;
862 int crtc_x, crtc_y;
863 unsigned int crtc_w, crtc_h;
864 uint32_t src_x, src_y, src_w, src_h;
865 struct drm_rect *src = &state->base.src;
866 struct drm_rect *dst = &state->base.dst;
867 const struct drm_rect *clip = &state->clip;
868 int hscale, vscale;
869 int max_scale, min_scale;
870 bool can_scale;
871 int ret;
873 *src = drm_plane_state_src(&state->base);
874 *dst = drm_plane_state_dest(&state->base);
876 if (!fb) {
877 state->base.visible = false;
878 return 0;
881 /* Don't modify another pipe's plane */
882 if (plane->pipe != crtc->pipe) {
883 DRM_DEBUG_KMS("Wrong plane <-> crtc mapping\n");
884 return -EINVAL;
887 /* FIXME check all gen limits */
888 if (fb->width < 3 || fb->height < 3 || fb->pitches[0] > 16384) {
889 DRM_DEBUG_KMS("Unsuitable framebuffer for plane\n");
890 return -EINVAL;
893 /* setup can_scale, min_scale, max_scale */
894 if (INTEL_GEN(dev_priv) >= 9) {
895 /* use scaler when colorkey is not required */
896 if (state->ckey.flags == I915_SET_COLORKEY_NONE) {
897 can_scale = 1;
898 min_scale = 1;
899 max_scale = skl_max_scale(crtc, crtc_state);
900 } else {
901 can_scale = 0;
902 min_scale = DRM_PLANE_HELPER_NO_SCALING;
903 max_scale = DRM_PLANE_HELPER_NO_SCALING;
905 } else {
906 can_scale = plane->can_scale;
907 max_scale = plane->max_downscale << 16;
908 min_scale = plane->can_scale ? 1 : (1 << 16);
912 * FIXME the following code does a bunch of fuzzy adjustments to the
913 * coordinates and sizes. We probably need some way to decide whether
914 * more strict checking should be done instead.
916 drm_rect_rotate(src, fb->width << 16, fb->height << 16,
917 state->base.rotation);
919 hscale = drm_rect_calc_hscale_relaxed(src, dst, min_scale, max_scale);
920 BUG_ON(hscale < 0);
922 vscale = drm_rect_calc_vscale_relaxed(src, dst, min_scale, max_scale);
923 BUG_ON(vscale < 0);
925 state->base.visible = drm_rect_clip_scaled(src, dst, clip, hscale, vscale);
927 crtc_x = dst->x1;
928 crtc_y = dst->y1;
929 crtc_w = drm_rect_width(dst);
930 crtc_h = drm_rect_height(dst);
932 if (state->base.visible) {
933 /* check again in case clipping clamped the results */
934 hscale = drm_rect_calc_hscale(src, dst, min_scale, max_scale);
935 if (hscale < 0) {
936 DRM_DEBUG_KMS("Horizontal scaling factor out of limits\n");
937 drm_rect_debug_print("src: ", src, true);
938 drm_rect_debug_print("dst: ", dst, false);
940 return hscale;
943 vscale = drm_rect_calc_vscale(src, dst, min_scale, max_scale);
944 if (vscale < 0) {
945 DRM_DEBUG_KMS("Vertical scaling factor out of limits\n");
946 drm_rect_debug_print("src: ", src, true);
947 drm_rect_debug_print("dst: ", dst, false);
949 return vscale;
952 /* Make the source viewport size an exact multiple of the scaling factors. */
953 drm_rect_adjust_size(src,
954 drm_rect_width(dst) * hscale - drm_rect_width(src),
955 drm_rect_height(dst) * vscale - drm_rect_height(src));
957 drm_rect_rotate_inv(src, fb->width << 16, fb->height << 16,
958 state->base.rotation);
960 /* sanity check to make sure the src viewport wasn't enlarged */
961 WARN_ON(src->x1 < (int) state->base.src_x ||
962 src->y1 < (int) state->base.src_y ||
963 src->x2 > (int) state->base.src_x + state->base.src_w ||
964 src->y2 > (int) state->base.src_y + state->base.src_h);
967 * Hardware doesn't handle subpixel coordinates.
968 * Adjust to (macro)pixel boundary, but be careful not to
969 * increase the source viewport size, because that could
970 * push the downscaling factor out of bounds.
972 src_x = src->x1 >> 16;
973 src_w = drm_rect_width(src) >> 16;
974 src_y = src->y1 >> 16;
975 src_h = drm_rect_height(src) >> 16;
977 if (format_is_yuv(fb->format->format)) {
978 src_x &= ~1;
979 src_w &= ~1;
982 * Must keep src and dst the
983 * same if we can't scale.
985 if (!can_scale)
986 crtc_w &= ~1;
988 if (crtc_w == 0)
989 state->base.visible = false;
993 /* Check size restrictions when scaling */
994 if (state->base.visible && (src_w != crtc_w || src_h != crtc_h)) {
995 unsigned int width_bytes;
996 int cpp = fb->format->cpp[0];
998 WARN_ON(!can_scale);
1000 /* FIXME interlacing min height is 6 */
1002 if (crtc_w < 3 || crtc_h < 3)
1003 state->base.visible = false;
1005 if (src_w < 3 || src_h < 3)
1006 state->base.visible = false;
1008 width_bytes = ((src_x * cpp) & 63) + src_w * cpp;
1010 if (INTEL_GEN(dev_priv) < 9 && (src_w > 2048 || src_h > 2048 ||
1011 width_bytes > 4096 || fb->pitches[0] > 4096)) {
1012 DRM_DEBUG_KMS("Source dimensions exceed hardware limits\n");
1013 return -EINVAL;
1017 if (state->base.visible) {
1018 src->x1 = src_x << 16;
1019 src->x2 = (src_x + src_w) << 16;
1020 src->y1 = src_y << 16;
1021 src->y2 = (src_y + src_h) << 16;
1024 dst->x1 = crtc_x;
1025 dst->x2 = crtc_x + crtc_w;
1026 dst->y1 = crtc_y;
1027 dst->y2 = crtc_y + crtc_h;
1029 if (INTEL_GEN(dev_priv) >= 9) {
1030 ret = skl_check_plane_surface(state);
1031 if (ret)
1032 return ret;
1034 state->ctl = skl_plane_ctl(crtc_state, state);
1035 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
1036 ret = i9xx_check_plane_surface(state);
1037 if (ret)
1038 return ret;
1040 state->ctl = vlv_sprite_ctl(crtc_state, state);
1041 } else if (INTEL_GEN(dev_priv) >= 7) {
1042 ret = i9xx_check_plane_surface(state);
1043 if (ret)
1044 return ret;
1046 state->ctl = ivb_sprite_ctl(crtc_state, state);
1047 } else {
1048 ret = i9xx_check_plane_surface(state);
1049 if (ret)
1050 return ret;
1052 state->ctl = g4x_sprite_ctl(crtc_state, state);
1055 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
1056 state->color_ctl = glk_plane_color_ctl(crtc_state, state);
1058 return 0;
1061 int intel_sprite_set_colorkey(struct drm_device *dev, void *data,
1062 struct drm_file *file_priv)
1064 struct drm_i915_private *dev_priv = to_i915(dev);
1065 struct drm_intel_sprite_colorkey *set = data;
1066 struct drm_plane *plane;
1067 struct drm_plane_state *plane_state;
1068 struct drm_atomic_state *state;
1069 struct drm_modeset_acquire_ctx ctx;
1070 int ret = 0;
1072 /* Make sure we don't try to enable both src & dest simultaneously */
1073 if ((set->flags & (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE)) == (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE))
1074 return -EINVAL;
1076 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
1077 set->flags & I915_SET_COLORKEY_DESTINATION)
1078 return -EINVAL;
1080 plane = drm_plane_find(dev, file_priv, set->plane_id);
1081 if (!plane || plane->type != DRM_PLANE_TYPE_OVERLAY)
1082 return -ENOENT;
1084 drm_modeset_acquire_init(&ctx, 0);
1086 state = drm_atomic_state_alloc(plane->dev);
1087 if (!state) {
1088 ret = -ENOMEM;
1089 goto out;
1091 state->acquire_ctx = &ctx;
1093 while (1) {
1094 plane_state = drm_atomic_get_plane_state(state, plane);
1095 ret = PTR_ERR_OR_ZERO(plane_state);
1096 if (!ret) {
1097 to_intel_plane_state(plane_state)->ckey = *set;
1098 ret = drm_atomic_commit(state);
1101 if (ret != -EDEADLK)
1102 break;
1104 drm_atomic_state_clear(state);
1105 drm_modeset_backoff(&ctx);
1108 drm_atomic_state_put(state);
1109 out:
1110 drm_modeset_drop_locks(&ctx);
1111 drm_modeset_acquire_fini(&ctx);
1112 return ret;
1115 static const uint32_t g4x_plane_formats[] = {
1116 DRM_FORMAT_XRGB8888,
1117 DRM_FORMAT_YUYV,
1118 DRM_FORMAT_YVYU,
1119 DRM_FORMAT_UYVY,
1120 DRM_FORMAT_VYUY,
1123 static const uint64_t i9xx_plane_format_modifiers[] = {
1124 I915_FORMAT_MOD_X_TILED,
1125 DRM_FORMAT_MOD_LINEAR,
1126 DRM_FORMAT_MOD_INVALID
1129 static const uint32_t snb_plane_formats[] = {
1130 DRM_FORMAT_XBGR8888,
1131 DRM_FORMAT_XRGB8888,
1132 DRM_FORMAT_YUYV,
1133 DRM_FORMAT_YVYU,
1134 DRM_FORMAT_UYVY,
1135 DRM_FORMAT_VYUY,
1138 static const uint32_t vlv_plane_formats[] = {
1139 DRM_FORMAT_RGB565,
1140 DRM_FORMAT_ABGR8888,
1141 DRM_FORMAT_ARGB8888,
1142 DRM_FORMAT_XBGR8888,
1143 DRM_FORMAT_XRGB8888,
1144 DRM_FORMAT_XBGR2101010,
1145 DRM_FORMAT_ABGR2101010,
1146 DRM_FORMAT_YUYV,
1147 DRM_FORMAT_YVYU,
1148 DRM_FORMAT_UYVY,
1149 DRM_FORMAT_VYUY,
1152 static uint32_t skl_plane_formats[] = {
1153 DRM_FORMAT_RGB565,
1154 DRM_FORMAT_ABGR8888,
1155 DRM_FORMAT_ARGB8888,
1156 DRM_FORMAT_XBGR8888,
1157 DRM_FORMAT_XRGB8888,
1158 DRM_FORMAT_YUYV,
1159 DRM_FORMAT_YVYU,
1160 DRM_FORMAT_UYVY,
1161 DRM_FORMAT_VYUY,
1164 static const uint64_t skl_plane_format_modifiers[] = {
1165 I915_FORMAT_MOD_X_TILED,
1166 DRM_FORMAT_MOD_LINEAR,
1167 DRM_FORMAT_MOD_INVALID
1170 static bool g4x_sprite_plane_format_mod_supported(struct drm_plane *plane,
1171 uint32_t format,
1172 uint64_t modifier)
1174 switch (format) {
1175 case DRM_FORMAT_XBGR8888:
1176 case DRM_FORMAT_XRGB8888:
1177 case DRM_FORMAT_YUYV:
1178 case DRM_FORMAT_YVYU:
1179 case DRM_FORMAT_UYVY:
1180 case DRM_FORMAT_VYUY:
1181 if (modifier == DRM_FORMAT_MOD_LINEAR ||
1182 modifier == I915_FORMAT_MOD_X_TILED)
1183 return true;
1184 /* fall through */
1185 default:
1186 return false;
1190 static bool vlv_sprite_plane_format_mod_supported(struct drm_plane *plane,
1191 uint32_t format,
1192 uint64_t modifier)
1194 switch (format) {
1195 case DRM_FORMAT_YUYV:
1196 case DRM_FORMAT_YVYU:
1197 case DRM_FORMAT_UYVY:
1198 case DRM_FORMAT_VYUY:
1199 case DRM_FORMAT_RGB565:
1200 case DRM_FORMAT_XRGB8888:
1201 case DRM_FORMAT_ARGB8888:
1202 case DRM_FORMAT_XBGR2101010:
1203 case DRM_FORMAT_ABGR2101010:
1204 case DRM_FORMAT_XBGR8888:
1205 case DRM_FORMAT_ABGR8888:
1206 if (modifier == DRM_FORMAT_MOD_LINEAR ||
1207 modifier == I915_FORMAT_MOD_X_TILED)
1208 return true;
1209 /* fall through */
1210 default:
1211 return false;
1215 static bool skl_sprite_plane_format_mod_supported(struct drm_plane *plane,
1216 uint32_t format,
1217 uint64_t modifier)
1219 /* This is the same as primary plane since SKL has universal planes */
1220 switch (format) {
1221 case DRM_FORMAT_XRGB8888:
1222 case DRM_FORMAT_XBGR8888:
1223 case DRM_FORMAT_ARGB8888:
1224 case DRM_FORMAT_ABGR8888:
1225 case DRM_FORMAT_RGB565:
1226 case DRM_FORMAT_XRGB2101010:
1227 case DRM_FORMAT_XBGR2101010:
1228 case DRM_FORMAT_YUYV:
1229 case DRM_FORMAT_YVYU:
1230 case DRM_FORMAT_UYVY:
1231 case DRM_FORMAT_VYUY:
1232 if (modifier == I915_FORMAT_MOD_Yf_TILED)
1233 return true;
1234 /* fall through */
1235 case DRM_FORMAT_C8:
1236 if (modifier == DRM_FORMAT_MOD_LINEAR ||
1237 modifier == I915_FORMAT_MOD_X_TILED ||
1238 modifier == I915_FORMAT_MOD_Y_TILED)
1239 return true;
1240 /* fall through */
1241 default:
1242 return false;
1246 static bool intel_sprite_plane_format_mod_supported(struct drm_plane *plane,
1247 uint32_t format,
1248 uint64_t modifier)
1250 struct drm_i915_private *dev_priv = to_i915(plane->dev);
1252 if (WARN_ON(modifier == DRM_FORMAT_MOD_INVALID))
1253 return false;
1255 if ((modifier >> 56) != DRM_FORMAT_MOD_VENDOR_INTEL &&
1256 modifier != DRM_FORMAT_MOD_LINEAR)
1257 return false;
1259 if (INTEL_GEN(dev_priv) >= 9)
1260 return skl_sprite_plane_format_mod_supported(plane, format, modifier);
1261 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
1262 return vlv_sprite_plane_format_mod_supported(plane, format, modifier);
1263 else
1264 return g4x_sprite_plane_format_mod_supported(plane, format, modifier);
1266 unreachable();
1269 static const struct drm_plane_funcs intel_sprite_plane_funcs = {
1270 .update_plane = drm_atomic_helper_update_plane,
1271 .disable_plane = drm_atomic_helper_disable_plane,
1272 .destroy = intel_plane_destroy,
1273 .atomic_get_property = intel_plane_atomic_get_property,
1274 .atomic_set_property = intel_plane_atomic_set_property,
1275 .atomic_duplicate_state = intel_plane_duplicate_state,
1276 .atomic_destroy_state = intel_plane_destroy_state,
1277 .format_mod_supported = intel_sprite_plane_format_mod_supported,
1280 struct intel_plane *
1281 intel_sprite_plane_create(struct drm_i915_private *dev_priv,
1282 enum pipe pipe, int plane)
1284 struct intel_plane *intel_plane = NULL;
1285 struct intel_plane_state *state = NULL;
1286 unsigned long possible_crtcs;
1287 const uint32_t *plane_formats;
1288 const uint64_t *modifiers;
1289 unsigned int supported_rotations;
1290 int num_plane_formats;
1291 int ret;
1293 intel_plane = kzalloc(sizeof(*intel_plane), GFP_KERNEL);
1294 if (!intel_plane) {
1295 ret = -ENOMEM;
1296 goto fail;
1299 state = intel_create_plane_state(&intel_plane->base);
1300 if (!state) {
1301 ret = -ENOMEM;
1302 goto fail;
1304 intel_plane->base.state = &state->base;
1306 if (INTEL_GEN(dev_priv) >= 10) {
1307 intel_plane->can_scale = true;
1308 state->scaler_id = -1;
1310 intel_plane->update_plane = skl_update_plane;
1311 intel_plane->disable_plane = skl_disable_plane;
1312 intel_plane->get_hw_state = skl_plane_get_hw_state;
1314 plane_formats = skl_plane_formats;
1315 num_plane_formats = ARRAY_SIZE(skl_plane_formats);
1316 modifiers = skl_plane_format_modifiers;
1317 } else if (INTEL_GEN(dev_priv) >= 9) {
1318 intel_plane->can_scale = true;
1319 state->scaler_id = -1;
1321 intel_plane->update_plane = skl_update_plane;
1322 intel_plane->disable_plane = skl_disable_plane;
1323 intel_plane->get_hw_state = skl_plane_get_hw_state;
1325 plane_formats = skl_plane_formats;
1326 num_plane_formats = ARRAY_SIZE(skl_plane_formats);
1327 modifiers = skl_plane_format_modifiers;
1328 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
1329 intel_plane->can_scale = false;
1330 intel_plane->max_downscale = 1;
1332 intel_plane->update_plane = vlv_update_plane;
1333 intel_plane->disable_plane = vlv_disable_plane;
1334 intel_plane->get_hw_state = vlv_plane_get_hw_state;
1336 plane_formats = vlv_plane_formats;
1337 num_plane_formats = ARRAY_SIZE(vlv_plane_formats);
1338 modifiers = i9xx_plane_format_modifiers;
1339 } else if (INTEL_GEN(dev_priv) >= 7) {
1340 if (IS_IVYBRIDGE(dev_priv)) {
1341 intel_plane->can_scale = true;
1342 intel_plane->max_downscale = 2;
1343 } else {
1344 intel_plane->can_scale = false;
1345 intel_plane->max_downscale = 1;
1348 intel_plane->update_plane = ivb_update_plane;
1349 intel_plane->disable_plane = ivb_disable_plane;
1350 intel_plane->get_hw_state = ivb_plane_get_hw_state;
1352 plane_formats = snb_plane_formats;
1353 num_plane_formats = ARRAY_SIZE(snb_plane_formats);
1354 modifiers = i9xx_plane_format_modifiers;
1355 } else {
1356 intel_plane->can_scale = true;
1357 intel_plane->max_downscale = 16;
1359 intel_plane->update_plane = g4x_update_plane;
1360 intel_plane->disable_plane = g4x_disable_plane;
1361 intel_plane->get_hw_state = g4x_plane_get_hw_state;
1363 modifiers = i9xx_plane_format_modifiers;
1364 if (IS_GEN6(dev_priv)) {
1365 plane_formats = snb_plane_formats;
1366 num_plane_formats = ARRAY_SIZE(snb_plane_formats);
1367 } else {
1368 plane_formats = g4x_plane_formats;
1369 num_plane_formats = ARRAY_SIZE(g4x_plane_formats);
1373 if (INTEL_GEN(dev_priv) >= 9) {
1374 supported_rotations =
1375 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_90 |
1376 DRM_MODE_ROTATE_180 | DRM_MODE_ROTATE_270;
1377 } else if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
1378 supported_rotations =
1379 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 |
1380 DRM_MODE_REFLECT_X;
1381 } else {
1382 supported_rotations =
1383 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180;
1386 intel_plane->pipe = pipe;
1387 intel_plane->i9xx_plane = plane;
1388 intel_plane->id = PLANE_SPRITE0 + plane;
1389 intel_plane->frontbuffer_bit = INTEL_FRONTBUFFER_SPRITE(pipe, plane);
1390 intel_plane->check_plane = intel_check_sprite_plane;
1392 possible_crtcs = (1 << pipe);
1394 if (INTEL_GEN(dev_priv) >= 9)
1395 ret = drm_universal_plane_init(&dev_priv->drm, &intel_plane->base,
1396 possible_crtcs, &intel_sprite_plane_funcs,
1397 plane_formats, num_plane_formats,
1398 modifiers,
1399 DRM_PLANE_TYPE_OVERLAY,
1400 "plane %d%c", plane + 2, pipe_name(pipe));
1401 else
1402 ret = drm_universal_plane_init(&dev_priv->drm, &intel_plane->base,
1403 possible_crtcs, &intel_sprite_plane_funcs,
1404 plane_formats, num_plane_formats,
1405 modifiers,
1406 DRM_PLANE_TYPE_OVERLAY,
1407 "sprite %c", sprite_name(pipe, plane));
1408 if (ret)
1409 goto fail;
1411 drm_plane_create_rotation_property(&intel_plane->base,
1412 DRM_MODE_ROTATE_0,
1413 supported_rotations);
1415 drm_plane_helper_add(&intel_plane->base, &intel_plane_helper_funcs);
1417 return intel_plane;
1419 fail:
1420 kfree(state);
1421 kfree(intel_plane);
1423 return ERR_PTR(ret);