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
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
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
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>
45 format_is_yuv(uint32_t format)
58 int intel_usecs_to_scanlines(const struct drm_display_mode *adjusted_mode,
62 if (!adjusted_mode->crtc_htotal)
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
74 #define VBLANK_EVASION_TIME_US 100
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);
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;
112 if (min <= 0 || max <= 0)
115 if (WARN_ON(drm_crtc_vblank_get(&crtc->base)))
118 crtc->debug.min_vbl = min;
119 crtc->debug.max_vbl = max;
120 trace_i915_pipe_update_start(crtc);
124 * prepare_to_wait() has a memory barrier, which guarantees
125 * other CPUs can see the task state update by the time we
128 prepare_to_wait(wq, &wait, TASK_UNINTERRUPTIBLE);
130 scanline = intel_get_crtc_scanline(crtc);
131 if (scanline < min || scanline > max)
135 DRM_ERROR("Potential atomic update failure on pipe %c\n",
136 pipe_name(crtc->pipe));
142 timeout = schedule_timeout(timeout);
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
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
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;
211 if (intel_vgpu_active(dev_priv))
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,
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",
228 ktime_us_delta(end_vbl_time, crtc->debug.start_vbl_time),
229 VBLANK_EVASION_TIME_US);
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 */
264 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
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);
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);
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);
287 /* program plane scaler */
288 if (plane_state->scaler_id >= 0) {
289 int scaler_id = plane_state->scaler_id;
290 const struct intel_scaler *scaler;
292 scaler = &crtc_state->scaler_state.scalers[scaler_id];
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));
301 I915_WRITE_FW(PLANE_POS(pipe, plane_id), 0);
303 I915_WRITE_FW(PLANE_POS(pipe, plane_id), (crtc_y << 16) | crtc_x);
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));
311 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
315 skl_disable_plane(struct intel_plane *plane, struct intel_crtc *crtc)
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;
322 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
324 I915_WRITE_FW(PLANE_CTL(pipe, plane_id), 0);
326 I915_WRITE_FW(PLANE_SURF(pipe, plane_id), 0);
327 POSTING_READ_FW(PLANE_SURF(pipe, plane_id));
329 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
333 skl_plane_get_hw_state(struct intel_plane *plane)
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;
341 power_domain = POWER_DOMAIN_PIPE(pipe);
342 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
345 ret = I915_READ(PLANE_CTL(pipe, plane_id)) & PLANE_CTL_ENABLE;
347 intel_display_power_put(dev_priv, power_domain);
353 chv_update_csc(struct intel_plane *plane, uint32_t format)
355 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
356 enum plane_id plane_id = plane->id;
358 /* Seems RGB data bypasses the CSC always */
359 if (!format_is_yuv(format))
363 * BT.601 limited range YCbCr -> full range RGB
365 * |r| | 6537 4769 0| |cr |
366 * |g| = |-3330 4769 -1605| x |y-64|
367 * |b| | 0 4769 8263| |cb |
369 * Cb and Cr apparently come in as signed already, so no
370 * need for any offset. For Y we need to remove the offset.
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));
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));
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));
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));
391 static u32 vlv_sprite_ctl(const struct intel_crtc_state *crtc_state,
392 const struct intel_plane_state *plane_state)
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;
399 sprctl = SP_ENABLE | SP_GAMMA_ENABLE;
401 switch (fb->format->format) {
402 case DRM_FORMAT_YUYV:
403 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YUYV;
405 case DRM_FORMAT_YVYU:
406 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YVYU;
408 case DRM_FORMAT_UYVY:
409 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_UYVY;
411 case DRM_FORMAT_VYUY:
412 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_VYUY;
414 case DRM_FORMAT_RGB565:
415 sprctl |= SP_FORMAT_BGR565;
417 case DRM_FORMAT_XRGB8888:
418 sprctl |= SP_FORMAT_BGRX8888;
420 case DRM_FORMAT_ARGB8888:
421 sprctl |= SP_FORMAT_BGRA8888;
423 case DRM_FORMAT_XBGR2101010:
424 sprctl |= SP_FORMAT_RGBX1010102;
426 case DRM_FORMAT_ABGR2101010:
427 sprctl |= SP_FORMAT_RGBA1010102;
429 case DRM_FORMAT_XBGR8888:
430 sprctl |= SP_FORMAT_RGBX8888;
432 case DRM_FORMAT_ABGR8888:
433 sprctl |= SP_FORMAT_RGBA8888;
436 MISSING_CASE(fb->format->format);
440 if (fb->modifier == I915_FORMAT_MOD_X_TILED)
443 if (rotation & DRM_MODE_ROTATE_180)
444 sprctl |= SP_ROTATE_180;
446 if (rotation & DRM_MODE_REFLECT_X)
449 if (key->flags & I915_SET_COLORKEY_SOURCE)
450 sprctl |= SP_SOURCE_KEY;
456 vlv_update_plane(struct intel_plane *plane,
457 const struct intel_crtc_state *crtc_state,
458 const struct intel_plane_state *plane_state)
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;
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;
476 /* Sizes are 0 based */
480 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
482 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
484 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B)
485 chv_update_csc(plane, fb->format->format);
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);
492 I915_WRITE_FW(SPSTRIDE(pipe, plane_id), fb->pitches[0]);
493 I915_WRITE_FW(SPPOS(pipe, plane_id), (crtc_y << 16) | crtc_x);
495 if (fb->modifier == I915_FORMAT_MOD_X_TILED)
496 I915_WRITE_FW(SPTILEOFF(pipe, plane_id), (y << 16) | x);
498 I915_WRITE_FW(SPLINOFF(pipe, plane_id), linear_offset);
500 I915_WRITE_FW(SPCONSTALPHA(pipe, plane_id), 0);
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));
508 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
512 vlv_disable_plane(struct intel_plane *plane, struct intel_crtc *crtc)
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;
519 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
521 I915_WRITE_FW(SPCNTR(pipe, plane_id), 0);
523 I915_WRITE_FW(SPSURF(pipe, plane_id), 0);
524 POSTING_READ_FW(SPSURF(pipe, plane_id));
526 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
530 vlv_plane_get_hw_state(struct intel_plane *plane)
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;
538 power_domain = POWER_DOMAIN_PIPE(pipe);
539 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
542 ret = I915_READ(SPCNTR(pipe, plane_id)) & SP_ENABLE;
544 intel_display_power_put(dev_priv, power_domain);
549 static u32 ivb_sprite_ctl(const struct intel_crtc_state *crtc_state,
550 const struct intel_plane_state *plane_state)
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;
559 sprctl = SPRITE_ENABLE | SPRITE_GAMMA_ENABLE;
561 if (IS_IVYBRIDGE(dev_priv))
562 sprctl |= SPRITE_TRICKLE_FEED_DISABLE;
564 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
565 sprctl |= SPRITE_PIPE_CSC_ENABLE;
567 switch (fb->format->format) {
568 case DRM_FORMAT_XBGR8888:
569 sprctl |= SPRITE_FORMAT_RGBX888 | SPRITE_RGB_ORDER_RGBX;
571 case DRM_FORMAT_XRGB8888:
572 sprctl |= SPRITE_FORMAT_RGBX888;
574 case DRM_FORMAT_YUYV:
575 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YUYV;
577 case DRM_FORMAT_YVYU:
578 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YVYU;
580 case DRM_FORMAT_UYVY:
581 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_UYVY;
583 case DRM_FORMAT_VYUY:
584 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_VYUY;
587 MISSING_CASE(fb->format->format);
591 if (fb->modifier == I915_FORMAT_MOD_X_TILED)
592 sprctl |= SPRITE_TILED;
594 if (rotation & DRM_MODE_ROTATE_180)
595 sprctl |= SPRITE_ROTATE_180;
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;
606 ivb_update_plane(struct intel_plane *plane,
607 const struct intel_crtc_state *crtc_state,
608 const struct intel_plane_state *plane_state)
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;
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;
627 /* Sizes are 0 based */
633 if (crtc_w != src_w || crtc_h != src_h)
634 sprscale = SPRITE_SCALE_ENABLE | (src_w << 16) | src_h;
636 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
638 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
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);
646 I915_WRITE_FW(SPRSTRIDE(pipe), fb->pitches[0]);
647 I915_WRITE_FW(SPRPOS(pipe), (crtc_y << 16) | crtc_x);
649 /* HSW consolidates SPRTILEOFF and SPRLINOFF into a single SPROFFSET
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);
656 I915_WRITE_FW(SPRLINOFF(pipe), linear_offset);
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));
666 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
670 ivb_disable_plane(struct intel_plane *plane, struct intel_crtc *crtc)
672 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
673 enum pipe pipe = plane->pipe;
674 unsigned long irqflags;
676 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
678 I915_WRITE_FW(SPRCTL(pipe), 0);
679 /* Can't leave the scaler enabled... */
680 if (plane->can_scale)
681 I915_WRITE_FW(SPRSCALE(pipe), 0);
683 I915_WRITE_FW(SPRSURF(pipe), 0);
684 POSTING_READ_FW(SPRSURF(pipe));
686 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
690 ivb_plane_get_hw_state(struct intel_plane *plane)
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;
697 power_domain = POWER_DOMAIN_PIPE(pipe);
698 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
701 ret = I915_READ(SPRCTL(pipe)) & SPRITE_ENABLE;
703 intel_display_power_put(dev_priv, power_domain);
708 static u32 g4x_sprite_ctl(const struct intel_crtc_state *crtc_state,
709 const struct intel_plane_state *plane_state)
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;
718 dvscntr = DVS_ENABLE | DVS_GAMMA_ENABLE;
720 if (IS_GEN6(dev_priv))
721 dvscntr |= DVS_TRICKLE_FEED_DISABLE;
723 switch (fb->format->format) {
724 case DRM_FORMAT_XBGR8888:
725 dvscntr |= DVS_FORMAT_RGBX888 | DVS_RGB_ORDER_XBGR;
727 case DRM_FORMAT_XRGB8888:
728 dvscntr |= DVS_FORMAT_RGBX888;
730 case DRM_FORMAT_YUYV:
731 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YUYV;
733 case DRM_FORMAT_YVYU:
734 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YVYU;
736 case DRM_FORMAT_UYVY:
737 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_UYVY;
739 case DRM_FORMAT_VYUY:
740 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_VYUY;
743 MISSING_CASE(fb->format->format);
747 if (fb->modifier == I915_FORMAT_MOD_X_TILED)
748 dvscntr |= DVS_TILED;
750 if (rotation & DRM_MODE_ROTATE_180)
751 dvscntr |= DVS_ROTATE_180;
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;
762 g4x_update_plane(struct intel_plane *plane,
763 const struct intel_crtc_state *crtc_state,
764 const struct intel_plane_state *plane_state)
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;
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;
783 /* Sizes are 0 based */
789 if (crtc_w != src_w || crtc_h != src_h)
790 dvsscale = DVS_SCALE_ENABLE | (src_w << 16) | src_h;
792 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
794 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
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);
802 I915_WRITE_FW(DVSSTRIDE(pipe), fb->pitches[0]);
803 I915_WRITE_FW(DVSPOS(pipe), (crtc_y << 16) | crtc_x);
805 if (fb->modifier == I915_FORMAT_MOD_X_TILED)
806 I915_WRITE_FW(DVSTILEOFF(pipe), (y << 16) | x);
808 I915_WRITE_FW(DVSLINOFF(pipe), linear_offset);
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));
817 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
821 g4x_disable_plane(struct intel_plane *plane, struct intel_crtc *crtc)
823 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
824 enum pipe pipe = plane->pipe;
825 unsigned long irqflags;
827 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
829 I915_WRITE_FW(DVSCNTR(pipe), 0);
830 /* Disable the scaler */
831 I915_WRITE_FW(DVSSCALE(pipe), 0);
833 I915_WRITE_FW(DVSSURF(pipe), 0);
834 POSTING_READ_FW(DVSSURF(pipe));
836 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
840 g4x_plane_get_hw_state(struct intel_plane *plane)
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;
847 power_domain = POWER_DOMAIN_PIPE(pipe);
848 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
851 ret = I915_READ(DVSCNTR(pipe)) & DVS_ENABLE;
853 intel_display_power_put(dev_priv, power_domain);
859 intel_check_sprite_plane(struct intel_plane *plane,
860 struct intel_crtc_state *crtc_state,
861 struct intel_plane_state *state)
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;
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;
873 int max_scale, min_scale;
877 *src = drm_plane_state_src(&state->base);
878 *dst = drm_plane_state_dest(&state->base);
881 state->base.visible = false;
885 /* Don't modify another pipe's plane */
886 if (plane->pipe != crtc->pipe) {
887 DRM_DEBUG_KMS("Wrong plane <-> crtc mapping\n");
891 /* FIXME check all gen limits */
892 if (fb->width < 3 || fb->height < 3 || fb->pitches[0] > 16384) {
893 DRM_DEBUG_KMS("Unsuitable framebuffer for plane\n");
897 /* setup can_scale, min_scale, max_scale */
898 if (INTEL_GEN(dev_priv) >= 9) {
899 /* use scaler when colorkey is not required */
900 if (state->ckey.flags == I915_SET_COLORKEY_NONE) {
903 max_scale = skl_max_scale(crtc, crtc_state);
906 min_scale = DRM_PLANE_HELPER_NO_SCALING;
907 max_scale = DRM_PLANE_HELPER_NO_SCALING;
910 can_scale = plane->can_scale;
911 max_scale = plane->max_downscale << 16;
912 min_scale = plane->can_scale ? 1 : (1 << 16);
916 * FIXME the following code does a bunch of fuzzy adjustments to the
917 * coordinates and sizes. We probably need some way to decide whether
918 * more strict checking should be done instead.
920 drm_rect_rotate(src, fb->width << 16, fb->height << 16,
921 state->base.rotation);
923 hscale = drm_rect_calc_hscale_relaxed(src, dst, min_scale, max_scale);
926 vscale = drm_rect_calc_vscale_relaxed(src, dst, min_scale, max_scale);
929 state->base.visible = drm_rect_clip_scaled(src, dst, clip, hscale, vscale);
933 crtc_w = drm_rect_width(dst);
934 crtc_h = drm_rect_height(dst);
936 if (state->base.visible) {
937 /* check again in case clipping clamped the results */
938 hscale = drm_rect_calc_hscale(src, dst, min_scale, max_scale);
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);
947 vscale = drm_rect_calc_vscale(src, dst, min_scale, max_scale);
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);
956 /* Make the source viewport size an exact multiple of the scaling factors. */
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));
961 drm_rect_rotate_inv(src, fb->width << 16, fb->height << 16,
962 state->base.rotation);
964 /* sanity check to make sure the src viewport wasn't enlarged */
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);
971 * Hardware doesn't handle subpixel coordinates.
972 * Adjust to (macro)pixel boundary, but be careful not to
973 * increase the source viewport size, because that could
974 * push the downscaling factor out of bounds.
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;
981 if (format_is_yuv(fb->format->format)) {
986 * Must keep src and dst the
987 * same if we can't scale.
993 state->base.visible = false;
997 /* Check size restrictions when scaling */
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];
1002 WARN_ON(!can_scale);
1004 /* FIXME interlacing min height is 6 */
1006 if (crtc_w < 3 || crtc_h < 3)
1007 state->base.visible = false;
1009 if (src_w < 3 || src_h < 3)
1010 state->base.visible = false;
1012 width_bytes = ((src_x * cpp) & 63) + src_w * cpp;
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");
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;
1029 dst->x2 = crtc_x + crtc_w;
1031 dst->y2 = crtc_y + crtc_h;
1033 if (INTEL_GEN(dev_priv) >= 9) {
1034 ret = skl_check_plane_surface(state);
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);
1044 state->ctl = vlv_sprite_ctl(crtc_state, state);
1045 } else if (INTEL_GEN(dev_priv) >= 7) {
1046 ret = i9xx_check_plane_surface(state);
1050 state->ctl = ivb_sprite_ctl(crtc_state, state);
1052 ret = i9xx_check_plane_surface(state);
1056 state->ctl = g4x_sprite_ctl(crtc_state, state);
1062 int intel_sprite_set_colorkey(struct drm_device *dev, void *data,
1063 struct drm_file *file_priv)
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;
1073 /* Make sure we don't try to enable both src & dest simultaneously */
1074 if ((set->flags & (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE)) == (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE))
1077 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
1078 set->flags & I915_SET_COLORKEY_DESTINATION)
1081 plane = drm_plane_find(dev, file_priv, set->plane_id);
1082 if (!plane || plane->type != DRM_PLANE_TYPE_OVERLAY)
1085 drm_modeset_acquire_init(&ctx, 0);
1087 state = drm_atomic_state_alloc(plane->dev);
1092 state->acquire_ctx = &ctx;
1095 plane_state = drm_atomic_get_plane_state(state, plane);
1096 ret = PTR_ERR_OR_ZERO(plane_state);
1098 to_intel_plane_state(plane_state)->ckey = *set;
1099 ret = drm_atomic_commit(state);
1102 if (ret != -EDEADLK)
1105 drm_atomic_state_clear(state);
1106 drm_modeset_backoff(&ctx);
1109 drm_atomic_state_put(state);
1111 drm_modeset_drop_locks(&ctx);
1112 drm_modeset_acquire_fini(&ctx);
1116 static const uint32_t g4x_plane_formats[] = {
1117 DRM_FORMAT_XRGB8888,
1124 static const uint64_t i9xx_plane_format_modifiers[] = {
1125 I915_FORMAT_MOD_X_TILED,
1126 DRM_FORMAT_MOD_LINEAR,
1127 DRM_FORMAT_MOD_INVALID
1130 static const uint32_t snb_plane_formats[] = {
1131 DRM_FORMAT_XBGR8888,
1132 DRM_FORMAT_XRGB8888,
1139 static const uint32_t vlv_plane_formats[] = {
1141 DRM_FORMAT_ABGR8888,
1142 DRM_FORMAT_ARGB8888,
1143 DRM_FORMAT_XBGR8888,
1144 DRM_FORMAT_XRGB8888,
1145 DRM_FORMAT_XBGR2101010,
1146 DRM_FORMAT_ABGR2101010,
1153 static uint32_t skl_plane_formats[] = {
1155 DRM_FORMAT_ABGR8888,
1156 DRM_FORMAT_ARGB8888,
1157 DRM_FORMAT_XBGR8888,
1158 DRM_FORMAT_XRGB8888,
1165 static const uint64_t skl_plane_format_modifiers[] = {
1166 I915_FORMAT_MOD_X_TILED,
1167 DRM_FORMAT_MOD_LINEAR,
1168 DRM_FORMAT_MOD_INVALID
1171 static bool g4x_sprite_plane_format_mod_supported(struct drm_plane *plane,
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)
1191 static bool vlv_sprite_plane_format_mod_supported(struct drm_plane *plane,
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)
1216 static bool skl_sprite_plane_format_mod_supported(struct drm_plane *plane,
1220 /* This is the same as primary plane since SKL has universal planes */
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)
1237 if (modifier == DRM_FORMAT_MOD_LINEAR ||
1238 modifier == I915_FORMAT_MOD_X_TILED ||
1239 modifier == I915_FORMAT_MOD_Y_TILED)
1247 static bool intel_sprite_plane_format_mod_supported(struct drm_plane *plane,
1251 struct drm_i915_private *dev_priv = to_i915(plane->dev);
1253 if (WARN_ON(modifier == DRM_FORMAT_MOD_INVALID))
1256 if ((modifier >> 56) != DRM_FORMAT_MOD_VENDOR_INTEL &&
1257 modifier != DRM_FORMAT_MOD_LINEAR)
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);
1265 return g4x_sprite_plane_format_mod_supported(plane, format, modifier);
1270 static 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,
1281 struct intel_plane *
1282 intel_sprite_plane_create(struct drm_i915_private *dev_priv,
1283 enum pipe pipe, int plane)
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;
1294 intel_plane = kzalloc(sizeof(*intel_plane), GFP_KERNEL);
1300 state = intel_create_plane_state(&intel_plane->base);
1305 intel_plane->base.state = &state->base;
1307 if (INTEL_GEN(dev_priv) >= 10) {
1308 intel_plane->can_scale = true;
1309 state->scaler_id = -1;
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;
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;
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;
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;
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;
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;
1345 intel_plane->can_scale = false;
1346 intel_plane->max_downscale = 1;
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;
1353 plane_formats = snb_plane_formats;
1354 num_plane_formats = ARRAY_SIZE(snb_plane_formats);
1355 modifiers = i9xx_plane_format_modifiers;
1357 intel_plane->can_scale = true;
1358 intel_plane->max_downscale = 16;
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;
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);
1369 plane_formats = g4x_plane_formats;
1370 num_plane_formats = ARRAY_SIZE(g4x_plane_formats);
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 |
1383 supported_rotations =
1384 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180;
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;
1393 possible_crtcs = (1 << pipe);
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,
1400 DRM_PLANE_TYPE_OVERLAY,
1401 "plane %d%c", plane + 2, pipe_name(pipe));
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,
1407 DRM_PLANE_TYPE_OVERLAY,
1408 "sprite %c", sprite_name(pipe, plane));
1412 drm_plane_create_rotation_property(&intel_plane->base,
1414 supported_rotations);
1416 drm_plane_helper_add(&intel_plane->base, &intel_plane_helper_funcs);
1424 return ERR_PTR(ret);