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
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.h>
34 #include <drm/drm_atomic_helper.h>
35 #include <drm/drm_color_mgmt.h>
36 #include <drm/drm_crtc.h>
37 #include <drm/drm_fourcc.h>
38 #include <drm/drm_plane_helper.h>
39 #include <drm/drm_rect.h>
40 #include <drm/i915_drm.h>
43 #include "i915_trace.h"
44 #include "intel_atomic_plane.h"
45 #include "intel_display_types.h"
46 #include "intel_frontbuffer.h"
48 #include "intel_psr.h"
49 #include "intel_sprite.h"
51 int intel_usecs_to_scanlines(const struct drm_display_mode *adjusted_mode,
55 if (!adjusted_mode->crtc_htotal)
58 return DIV_ROUND_UP(usecs * adjusted_mode->crtc_clock,
59 1000 * adjusted_mode->crtc_htotal);
62 /* FIXME: We should instead only take spinlocks once for the entire update
63 * instead of once per mmio. */
64 #if IS_ENABLED(CONFIG_PROVE_LOCKING)
65 #define VBLANK_EVASION_TIME_US 250
67 #define VBLANK_EVASION_TIME_US 100
71 * intel_pipe_update_start() - start update of a set of display registers
72 * @new_crtc_state: the new crtc state
74 * Mark the start of an update to pipe registers that should be updated
75 * atomically regarding vblank. If the next vblank will happens within
76 * the next 100 us, this function waits until the vblank passes.
78 * After a successful call to this function, interrupts will be disabled
79 * until a subsequent call to intel_pipe_update_end(). That is done to
80 * avoid random delays.
82 void intel_pipe_update_start(const struct intel_crtc_state *new_crtc_state)
84 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
85 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
86 const struct drm_display_mode *adjusted_mode = &new_crtc_state->base.adjusted_mode;
87 long timeout = msecs_to_jiffies_timeout(1);
88 int scanline, min, max, vblank_start;
89 wait_queue_head_t *wq = drm_crtc_vblank_waitqueue(&crtc->base);
90 bool need_vlv_dsi_wa = (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
91 intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI);
95 vblank_start = adjusted_mode->crtc_vblank_start;
96 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
97 vblank_start = DIV_ROUND_UP(vblank_start, 2);
99 /* FIXME needs to be calibrated sensibly */
100 min = vblank_start - intel_usecs_to_scanlines(adjusted_mode,
101 VBLANK_EVASION_TIME_US);
102 max = vblank_start - 1;
104 if (min <= 0 || max <= 0)
107 if (WARN_ON(drm_crtc_vblank_get(&crtc->base)))
111 * Wait for psr to idle out after enabling the VBL interrupts
112 * VBL interrupts will start the PSR exit and prevent a PSR
115 if (intel_psr_wait_for_idle(new_crtc_state, &psr_status))
116 DRM_ERROR("PSR idle timed out 0x%x, atomic update may fail\n",
121 crtc->debug.min_vbl = min;
122 crtc->debug.max_vbl = max;
123 trace_i915_pipe_update_start(crtc);
127 * prepare_to_wait() has a memory barrier, which guarantees
128 * other CPUs can see the task state update by the time we
131 prepare_to_wait(wq, &wait, TASK_UNINTERRUPTIBLE);
133 scanline = intel_get_crtc_scanline(crtc);
134 if (scanline < min || scanline > max)
138 DRM_ERROR("Potential atomic update failure on pipe %c\n",
139 pipe_name(crtc->pipe));
145 timeout = schedule_timeout(timeout);
150 finish_wait(wq, &wait);
152 drm_crtc_vblank_put(&crtc->base);
155 * On VLV/CHV DSI the scanline counter would appear to
156 * increment approx. 1/3 of a scanline before start of vblank.
157 * The registers still get latched at start of vblank however.
158 * This means we must not write any registers on the first
159 * line of vblank (since not the whole line is actually in
160 * vblank). And unfortunately we can't use the interrupt to
161 * wait here since it will fire too soon. We could use the
162 * frame start interrupt instead since it will fire after the
163 * critical scanline, but that would require more changes
164 * in the interrupt code. So for now we'll just do the nasty
165 * thing and poll for the bad scanline to pass us by.
167 * FIXME figure out if BXT+ DSI suffers from this as well
169 while (need_vlv_dsi_wa && scanline == vblank_start)
170 scanline = intel_get_crtc_scanline(crtc);
172 crtc->debug.scanline_start = scanline;
173 crtc->debug.start_vbl_time = ktime_get();
174 crtc->debug.start_vbl_count = intel_crtc_get_vblank_counter(crtc);
176 trace_i915_pipe_update_vblank_evaded(crtc);
184 * intel_pipe_update_end() - end update of a set of display registers
185 * @new_crtc_state: the new crtc state
187 * Mark the end of an update started with intel_pipe_update_start(). This
188 * re-enables interrupts and verifies the update was actually completed
191 void intel_pipe_update_end(struct intel_crtc_state *new_crtc_state)
193 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
194 enum pipe pipe = crtc->pipe;
195 int scanline_end = intel_get_crtc_scanline(crtc);
196 u32 end_vbl_count = intel_crtc_get_vblank_counter(crtc);
197 ktime_t end_vbl_time = ktime_get();
198 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
200 trace_i915_pipe_update_end(crtc, end_vbl_count, scanline_end);
202 /* We're still in the vblank-evade critical section, this can't race.
203 * Would be slightly nice to just grab the vblank count and arm the
204 * event outside of the critical section - the spinlock might spin for a
206 if (new_crtc_state->base.event) {
207 WARN_ON(drm_crtc_vblank_get(&crtc->base) != 0);
209 spin_lock(&crtc->base.dev->event_lock);
210 drm_crtc_arm_vblank_event(&crtc->base, new_crtc_state->base.event);
211 spin_unlock(&crtc->base.dev->event_lock);
213 new_crtc_state->base.event = NULL;
218 if (intel_vgpu_active(dev_priv))
221 if (crtc->debug.start_vbl_count &&
222 crtc->debug.start_vbl_count != end_vbl_count) {
223 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",
224 pipe_name(pipe), crtc->debug.start_vbl_count,
226 ktime_us_delta(end_vbl_time, crtc->debug.start_vbl_time),
227 crtc->debug.min_vbl, crtc->debug.max_vbl,
228 crtc->debug.scanline_start, scanline_end);
230 #ifdef CONFIG_DRM_I915_DEBUG_VBLANK_EVADE
231 else if (ktime_us_delta(end_vbl_time, crtc->debug.start_vbl_time) >
232 VBLANK_EVASION_TIME_US)
233 DRM_WARN("Atomic update on pipe (%c) took %lld us, max time under evasion is %u us\n",
235 ktime_us_delta(end_vbl_time, crtc->debug.start_vbl_time),
236 VBLANK_EVASION_TIME_US);
240 int intel_plane_check_stride(const struct intel_plane_state *plane_state)
242 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
243 const struct drm_framebuffer *fb = plane_state->base.fb;
244 unsigned int rotation = plane_state->base.rotation;
245 u32 stride, max_stride;
248 * We ignore stride for all invisible planes that
249 * can be remapped. Otherwise we could end up
250 * with a false positive when the remapping didn't
251 * kick in due the plane being invisible.
253 if (intel_plane_can_remap(plane_state) &&
254 !plane_state->base.visible)
257 /* FIXME other color planes? */
258 stride = plane_state->color_plane[0].stride;
259 max_stride = plane->max_stride(plane, fb->format->format,
260 fb->modifier, rotation);
262 if (stride > max_stride) {
263 DRM_DEBUG_KMS("[FB:%d] stride (%d) exceeds [PLANE:%d:%s] max stride (%d)\n",
265 plane->base.base.id, plane->base.name, max_stride);
272 int intel_plane_check_src_coordinates(struct intel_plane_state *plane_state)
274 const struct drm_framebuffer *fb = plane_state->base.fb;
275 struct drm_rect *src = &plane_state->base.src;
276 u32 src_x, src_y, src_w, src_h, hsub, vsub;
277 bool rotated = drm_rotation_90_or_270(plane_state->base.rotation);
280 * Hardware doesn't handle subpixel coordinates.
281 * Adjust to (macro)pixel boundary, but be careful not to
282 * increase the source viewport size, because that could
283 * push the downscaling factor out of bounds.
285 src_x = src->x1 >> 16;
286 src_w = drm_rect_width(src) >> 16;
287 src_y = src->y1 >> 16;
288 src_h = drm_rect_height(src) >> 16;
290 drm_rect_init(src, src_x << 16, src_y << 16,
291 src_w << 16, src_h << 16);
293 if (!fb->format->is_yuv)
296 /* YUV specific checks */
298 hsub = fb->format->hsub;
299 vsub = fb->format->vsub;
301 hsub = vsub = max(fb->format->hsub, fb->format->vsub);
304 if (src_x % hsub || src_w % hsub) {
305 DRM_DEBUG_KMS("src x/w (%u, %u) must be a multiple of %u for %sYUV planes\n",
306 src_x, src_w, hsub, rotated ? "rotated " : "");
310 if (src_y % vsub || src_h % vsub) {
311 DRM_DEBUG_KMS("src y/h (%u, %u) must be a multiple of %u for %sYUV planes\n",
312 src_y, src_h, vsub, rotated ? "rotated " : "");
319 bool icl_is_hdr_plane(struct drm_i915_private *dev_priv, enum plane_id plane_id)
321 return INTEL_GEN(dev_priv) >= 11 &&
322 icl_hdr_plane_mask() & BIT(plane_id);
326 skl_plane_ratio(const struct intel_crtc_state *crtc_state,
327 const struct intel_plane_state *plane_state,
328 unsigned int *num, unsigned int *den)
330 struct drm_i915_private *dev_priv = to_i915(plane_state->base.plane->dev);
331 const struct drm_framebuffer *fb = plane_state->base.fb;
333 if (fb->format->cpp[0] == 8) {
334 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) {
347 static int skl_plane_min_cdclk(const struct intel_crtc_state *crtc_state,
348 const struct intel_plane_state *plane_state)
350 struct drm_i915_private *dev_priv = to_i915(plane_state->base.plane->dev);
351 unsigned int pixel_rate = crtc_state->pixel_rate;
352 unsigned int src_w, src_h, dst_w, dst_h;
353 unsigned int num, den;
355 skl_plane_ratio(crtc_state, plane_state, &num, &den);
357 /* two pixels per clock on glk+ */
358 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
361 src_w = drm_rect_width(&plane_state->base.src) >> 16;
362 src_h = drm_rect_height(&plane_state->base.src) >> 16;
363 dst_w = drm_rect_width(&plane_state->base.dst);
364 dst_h = drm_rect_height(&plane_state->base.dst);
366 /* Downscaling limits the maximum pixel rate */
367 dst_w = min(src_w, dst_w);
368 dst_h = min(src_h, dst_h);
370 return DIV64_U64_ROUND_UP(mul_u32_u32(pixel_rate * num, src_w * src_h),
371 mul_u32_u32(den, dst_w * dst_h));
375 skl_plane_max_stride(struct intel_plane *plane,
376 u32 pixel_format, u64 modifier,
377 unsigned int rotation)
379 const struct drm_format_info *info = drm_format_info(pixel_format);
380 int cpp = info->cpp[0];
383 * "The stride in bytes must not exceed the
384 * of the size of 8K pixels and 32K bytes."
386 if (drm_rotation_90_or_270(rotation))
387 return min(8192, 32768 / cpp);
389 return min(8192 * cpp, 32768);
393 skl_program_scaler(struct intel_plane *plane,
394 const struct intel_crtc_state *crtc_state,
395 const struct intel_plane_state *plane_state)
397 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
398 const struct drm_framebuffer *fb = plane_state->base.fb;
399 enum pipe pipe = plane->pipe;
400 int scaler_id = plane_state->scaler_id;
401 const struct intel_scaler *scaler =
402 &crtc_state->scaler_state.scalers[scaler_id];
403 int crtc_x = plane_state->base.dst.x1;
404 int crtc_y = plane_state->base.dst.y1;
405 u32 crtc_w = drm_rect_width(&plane_state->base.dst);
406 u32 crtc_h = drm_rect_height(&plane_state->base.dst);
407 u16 y_hphase, uv_rgb_hphase;
408 u16 y_vphase, uv_rgb_vphase;
411 hscale = drm_rect_calc_hscale(&plane_state->base.src,
412 &plane_state->base.dst,
414 vscale = drm_rect_calc_vscale(&plane_state->base.src,
415 &plane_state->base.dst,
418 /* TODO: handle sub-pixel coordinates */
419 if (drm_format_info_is_yuv_semiplanar(fb->format) &&
420 !icl_is_hdr_plane(dev_priv, plane->id)) {
421 y_hphase = skl_scaler_calc_phase(1, hscale, false);
422 y_vphase = skl_scaler_calc_phase(1, vscale, false);
424 /* MPEG2 chroma siting convention */
425 uv_rgb_hphase = skl_scaler_calc_phase(2, hscale, true);
426 uv_rgb_vphase = skl_scaler_calc_phase(2, vscale, false);
432 uv_rgb_hphase = skl_scaler_calc_phase(1, hscale, false);
433 uv_rgb_vphase = skl_scaler_calc_phase(1, vscale, false);
436 I915_WRITE_FW(SKL_PS_CTRL(pipe, scaler_id),
437 PS_SCALER_EN | PS_PLANE_SEL(plane->id) | scaler->mode);
438 I915_WRITE_FW(SKL_PS_VPHASE(pipe, scaler_id),
439 PS_Y_PHASE(y_vphase) | PS_UV_RGB_PHASE(uv_rgb_vphase));
440 I915_WRITE_FW(SKL_PS_HPHASE(pipe, scaler_id),
441 PS_Y_PHASE(y_hphase) | PS_UV_RGB_PHASE(uv_rgb_hphase));
442 I915_WRITE_FW(SKL_PS_WIN_POS(pipe, scaler_id), (crtc_x << 16) | crtc_y);
443 I915_WRITE_FW(SKL_PS_WIN_SZ(pipe, scaler_id), (crtc_w << 16) | crtc_h);
446 /* Preoffset values for YUV to RGB Conversion */
447 #define PREOFF_YUV_TO_RGB_HI 0x1800
448 #define PREOFF_YUV_TO_RGB_ME 0x1F00
449 #define PREOFF_YUV_TO_RGB_LO 0x1800
451 #define ROFF(x) (((x) & 0xffff) << 16)
452 #define GOFF(x) (((x) & 0xffff) << 0)
453 #define BOFF(x) (((x) & 0xffff) << 16)
456 icl_program_input_csc(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 enum pipe pipe = plane->pipe;
462 enum plane_id plane_id = plane->id;
464 static const u16 input_csc_matrix[][9] = {
466 * BT.601 full range YCbCr -> full range RGB
467 * The matrix required is :
468 * [1.000, 0.000, 1.371,
469 * 1.000, -0.336, -0.698,
470 * 1.000, 1.732, 0.0000]
472 [DRM_COLOR_YCBCR_BT601] = {
474 0x8B28, 0x7800, 0x9AC0,
478 * BT.709 full range YCbCr -> full range RGB
479 * The matrix required is :
480 * [1.000, 0.000, 1.574,
481 * 1.000, -0.187, -0.468,
482 * 1.000, 1.855, 0.0000]
484 [DRM_COLOR_YCBCR_BT709] = {
486 0x9EF8, 0x7800, 0xAC00,
490 * BT.2020 full range YCbCr -> full range RGB
491 * The matrix required is :
492 * [1.000, 0.000, 1.474,
493 * 1.000, -0.1645, -0.5713,
494 * 1.000, 1.8814, 0.0000]
496 [DRM_COLOR_YCBCR_BT2020] = {
498 0x8928, 0x7800, 0xAA88,
503 /* Matrix for Limited Range to Full Range Conversion */
504 static const u16 input_csc_matrix_lr[][9] = {
506 * BT.601 Limted range YCbCr -> full range RGB
507 * The matrix required is :
508 * [1.164384, 0.000, 1.596027,
509 * 1.164384, -0.39175, -0.812813,
510 * 1.164384, 2.017232, 0.0000]
512 [DRM_COLOR_YCBCR_BT601] = {
514 0x8D00, 0x7950, 0x9C88,
518 * BT.709 Limited range YCbCr -> full range RGB
519 * The matrix required is :
520 * [1.164384, 0.000, 1.792741,
521 * 1.164384, -0.213249, -0.532909,
522 * 1.164384, 2.112402, 0.0000]
524 [DRM_COLOR_YCBCR_BT709] = {
526 0x8888, 0x7950, 0xADA8,
530 * BT.2020 Limited range YCbCr -> full range RGB
531 * The matrix required is :
532 * [1.164, 0.000, 1.678,
533 * 1.164, -0.1873, -0.6504,
534 * 1.164, 2.1417, 0.0000]
536 [DRM_COLOR_YCBCR_BT2020] = {
538 0x8A68, 0x7950, 0xAC00,
544 if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
545 csc = input_csc_matrix[plane_state->base.color_encoding];
547 csc = input_csc_matrix_lr[plane_state->base.color_encoding];
549 I915_WRITE_FW(PLANE_INPUT_CSC_COEFF(pipe, plane_id, 0), ROFF(csc[0]) |
551 I915_WRITE_FW(PLANE_INPUT_CSC_COEFF(pipe, plane_id, 1), BOFF(csc[2]));
552 I915_WRITE_FW(PLANE_INPUT_CSC_COEFF(pipe, plane_id, 2), ROFF(csc[3]) |
554 I915_WRITE_FW(PLANE_INPUT_CSC_COEFF(pipe, plane_id, 3), BOFF(csc[5]));
555 I915_WRITE_FW(PLANE_INPUT_CSC_COEFF(pipe, plane_id, 4), ROFF(csc[6]) |
557 I915_WRITE_FW(PLANE_INPUT_CSC_COEFF(pipe, plane_id, 5), BOFF(csc[8]));
559 I915_WRITE_FW(PLANE_INPUT_CSC_PREOFF(pipe, plane_id, 0),
560 PREOFF_YUV_TO_RGB_HI);
561 if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
562 I915_WRITE_FW(PLANE_INPUT_CSC_PREOFF(pipe, plane_id, 1), 0);
564 I915_WRITE_FW(PLANE_INPUT_CSC_PREOFF(pipe, plane_id, 1),
565 PREOFF_YUV_TO_RGB_ME);
566 I915_WRITE_FW(PLANE_INPUT_CSC_PREOFF(pipe, plane_id, 2),
567 PREOFF_YUV_TO_RGB_LO);
568 I915_WRITE_FW(PLANE_INPUT_CSC_POSTOFF(pipe, plane_id, 0), 0x0);
569 I915_WRITE_FW(PLANE_INPUT_CSC_POSTOFF(pipe, plane_id, 1), 0x0);
570 I915_WRITE_FW(PLANE_INPUT_CSC_POSTOFF(pipe, plane_id, 2), 0x0);
574 skl_program_plane(struct intel_plane *plane,
575 const struct intel_crtc_state *crtc_state,
576 const struct intel_plane_state *plane_state,
577 int color_plane, bool slave, u32 plane_ctl)
579 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
580 enum plane_id plane_id = plane->id;
581 enum pipe pipe = plane->pipe;
582 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
583 u32 surf_addr = plane_state->color_plane[color_plane].offset;
584 u32 stride = skl_plane_stride(plane_state, color_plane);
585 u32 aux_stride = skl_plane_stride(plane_state, 1);
586 int crtc_x = plane_state->base.dst.x1;
587 int crtc_y = plane_state->base.dst.y1;
588 u32 x = plane_state->color_plane[color_plane].x;
589 u32 y = plane_state->color_plane[color_plane].y;
590 u32 src_w = drm_rect_width(&plane_state->base.src) >> 16;
591 u32 src_h = drm_rect_height(&plane_state->base.src) >> 16;
592 struct intel_plane *linked = plane_state->planar_linked_plane;
593 const struct drm_framebuffer *fb = plane_state->base.fb;
594 u8 alpha = plane_state->base.alpha >> 8;
595 u32 plane_color_ctl = 0;
596 unsigned long irqflags;
599 plane_ctl |= skl_plane_ctl_crtc(crtc_state);
601 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
602 plane_color_ctl = plane_state->color_ctl |
603 glk_plane_color_ctl_crtc(crtc_state);
605 /* Sizes are 0 based */
609 keymax = (key->max_value & 0xffffff) | PLANE_KEYMAX_ALPHA(alpha);
611 keymsk = key->channel_mask & 0x7ffffff;
613 keymsk |= PLANE_KEYMSK_ALPHA_ENABLE;
615 /* The scaler will handle the output position */
616 if (plane_state->scaler_id >= 0) {
621 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
623 I915_WRITE_FW(PLANE_STRIDE(pipe, plane_id), stride);
624 I915_WRITE_FW(PLANE_POS(pipe, plane_id), (crtc_y << 16) | crtc_x);
625 I915_WRITE_FW(PLANE_SIZE(pipe, plane_id), (src_h << 16) | src_w);
626 I915_WRITE_FW(PLANE_AUX_DIST(pipe, plane_id),
627 (plane_state->color_plane[1].offset - surf_addr) | aux_stride);
629 if (icl_is_hdr_plane(dev_priv, plane_id)) {
633 /* Enable and use MPEG-2 chroma siting */
634 cus_ctl = PLANE_CUS_ENABLE |
636 PLANE_CUS_VPHASE_SIGN_NEGATIVE |
637 PLANE_CUS_VPHASE_0_25;
639 if (linked->id == PLANE_SPRITE5)
640 cus_ctl |= PLANE_CUS_PLANE_7;
641 else if (linked->id == PLANE_SPRITE4)
642 cus_ctl |= PLANE_CUS_PLANE_6;
644 MISSING_CASE(linked->id);
647 I915_WRITE_FW(PLANE_CUS_CTL(pipe, plane_id), cus_ctl);
650 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
651 I915_WRITE_FW(PLANE_COLOR_CTL(pipe, plane_id), plane_color_ctl);
653 if (fb->format->is_yuv && icl_is_hdr_plane(dev_priv, plane_id))
654 icl_program_input_csc(plane, crtc_state, plane_state);
656 skl_write_plane_wm(plane, crtc_state);
658 I915_WRITE_FW(PLANE_KEYVAL(pipe, plane_id), key->min_value);
659 I915_WRITE_FW(PLANE_KEYMSK(pipe, plane_id), keymsk);
660 I915_WRITE_FW(PLANE_KEYMAX(pipe, plane_id), keymax);
662 I915_WRITE_FW(PLANE_OFFSET(pipe, plane_id), (y << 16) | x);
664 if (INTEL_GEN(dev_priv) < 11)
665 I915_WRITE_FW(PLANE_AUX_OFFSET(pipe, plane_id),
666 (plane_state->color_plane[1].y << 16) |
667 plane_state->color_plane[1].x);
670 * The control register self-arms if the plane was previously
671 * disabled. Try to make the plane enable atomic by writing
672 * the control register just before the surface register.
674 I915_WRITE_FW(PLANE_CTL(pipe, plane_id), plane_ctl);
675 I915_WRITE_FW(PLANE_SURF(pipe, plane_id),
676 intel_plane_ggtt_offset(plane_state) + surf_addr);
678 if (!slave && plane_state->scaler_id >= 0)
679 skl_program_scaler(plane, crtc_state, plane_state);
681 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
685 skl_update_plane(struct intel_plane *plane,
686 const struct intel_crtc_state *crtc_state,
687 const struct intel_plane_state *plane_state)
691 if (plane_state->planar_linked_plane) {
692 /* Program the UV plane */
696 skl_program_plane(plane, crtc_state, plane_state,
697 color_plane, false, plane_state->ctl);
701 icl_update_slave(struct intel_plane *plane,
702 const struct intel_crtc_state *crtc_state,
703 const struct intel_plane_state *plane_state)
705 skl_program_plane(plane, crtc_state, plane_state, 0, true,
706 plane_state->ctl | PLANE_CTL_YUV420_Y_PLANE);
710 skl_disable_plane(struct intel_plane *plane,
711 const struct intel_crtc_state *crtc_state)
713 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
714 enum plane_id plane_id = plane->id;
715 enum pipe pipe = plane->pipe;
716 unsigned long irqflags;
718 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
720 if (icl_is_hdr_plane(dev_priv, plane_id))
721 I915_WRITE_FW(PLANE_CUS_CTL(pipe, plane_id), 0);
723 skl_write_plane_wm(plane, crtc_state);
725 I915_WRITE_FW(PLANE_CTL(pipe, plane_id), 0);
726 I915_WRITE_FW(PLANE_SURF(pipe, plane_id), 0);
728 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
732 skl_plane_get_hw_state(struct intel_plane *plane,
735 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
736 enum intel_display_power_domain power_domain;
737 enum plane_id plane_id = plane->id;
738 intel_wakeref_t wakeref;
741 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
742 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
746 ret = I915_READ(PLANE_CTL(plane->pipe, plane_id)) & PLANE_CTL_ENABLE;
750 intel_display_power_put(dev_priv, power_domain, wakeref);
755 static void i9xx_plane_linear_gamma(u16 gamma[8])
757 /* The points are not evenly spaced. */
758 static const u8 in[8] = { 0, 1, 2, 4, 8, 16, 24, 32 };
761 for (i = 0; i < 8; i++)
762 gamma[i] = (in[i] << 8) / 32;
766 chv_update_csc(const struct intel_plane_state *plane_state)
768 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
769 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
770 const struct drm_framebuffer *fb = plane_state->base.fb;
771 enum plane_id plane_id = plane->id;
773 * |r| | c0 c1 c2 | |cr|
774 * |g| = | c3 c4 c5 | x |y |
775 * |b| | c6 c7 c8 | |cb|
777 * Coefficients are s3.12.
779 * Cb and Cr apparently come in as signed already, and
780 * we always get full range data in on account of CLRC0/1.
782 static const s16 csc_matrix[][9] = {
783 /* BT.601 full range YCbCr -> full range RGB */
784 [DRM_COLOR_YCBCR_BT601] = {
789 /* BT.709 full range YCbCr -> full range RGB */
790 [DRM_COLOR_YCBCR_BT709] = {
796 const s16 *csc = csc_matrix[plane_state->base.color_encoding];
798 /* Seems RGB data bypasses the CSC always */
799 if (!fb->format->is_yuv)
802 I915_WRITE_FW(SPCSCYGOFF(plane_id), SPCSC_OOFF(0) | SPCSC_IOFF(0));
803 I915_WRITE_FW(SPCSCCBOFF(plane_id), SPCSC_OOFF(0) | SPCSC_IOFF(0));
804 I915_WRITE_FW(SPCSCCROFF(plane_id), SPCSC_OOFF(0) | SPCSC_IOFF(0));
806 I915_WRITE_FW(SPCSCC01(plane_id), SPCSC_C1(csc[1]) | SPCSC_C0(csc[0]));
807 I915_WRITE_FW(SPCSCC23(plane_id), SPCSC_C1(csc[3]) | SPCSC_C0(csc[2]));
808 I915_WRITE_FW(SPCSCC45(plane_id), SPCSC_C1(csc[5]) | SPCSC_C0(csc[4]));
809 I915_WRITE_FW(SPCSCC67(plane_id), SPCSC_C1(csc[7]) | SPCSC_C0(csc[6]));
810 I915_WRITE_FW(SPCSCC8(plane_id), SPCSC_C0(csc[8]));
812 I915_WRITE_FW(SPCSCYGICLAMP(plane_id), SPCSC_IMAX(1023) | SPCSC_IMIN(0));
813 I915_WRITE_FW(SPCSCCBICLAMP(plane_id), SPCSC_IMAX(512) | SPCSC_IMIN(-512));
814 I915_WRITE_FW(SPCSCCRICLAMP(plane_id), SPCSC_IMAX(512) | SPCSC_IMIN(-512));
816 I915_WRITE_FW(SPCSCYGOCLAMP(plane_id), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
817 I915_WRITE_FW(SPCSCCBOCLAMP(plane_id), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
818 I915_WRITE_FW(SPCSCCROCLAMP(plane_id), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
825 vlv_update_clrc(const struct intel_plane_state *plane_state)
827 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
828 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
829 const struct drm_framebuffer *fb = plane_state->base.fb;
830 enum pipe pipe = plane->pipe;
831 enum plane_id plane_id = plane->id;
832 int contrast, brightness, sh_scale, sh_sin, sh_cos;
834 if (fb->format->is_yuv &&
835 plane_state->base.color_range == DRM_COLOR_YCBCR_LIMITED_RANGE) {
837 * Expand limited range to full range:
838 * Contrast is applied first and is used to expand Y range.
839 * Brightness is applied second and is used to remove the
840 * offset from Y. Saturation/hue is used to expand CbCr range.
842 contrast = DIV_ROUND_CLOSEST(255 << 6, 235 - 16);
843 brightness = -DIV_ROUND_CLOSEST(16 * 255, 235 - 16);
844 sh_scale = DIV_ROUND_CLOSEST(128 << 7, 240 - 128);
845 sh_sin = SIN_0 * sh_scale;
846 sh_cos = COS_0 * sh_scale;
848 /* Pass-through everything. */
852 sh_sin = SIN_0 * sh_scale;
853 sh_cos = COS_0 * sh_scale;
856 /* FIXME these register are single buffered :( */
857 I915_WRITE_FW(SPCLRC0(pipe, plane_id),
858 SP_CONTRAST(contrast) | SP_BRIGHTNESS(brightness));
859 I915_WRITE_FW(SPCLRC1(pipe, plane_id),
860 SP_SH_SIN(sh_sin) | SP_SH_COS(sh_cos));
864 vlv_plane_ratio(const struct intel_crtc_state *crtc_state,
865 const struct intel_plane_state *plane_state,
866 unsigned int *num, unsigned int *den)
868 u8 active_planes = crtc_state->active_planes & ~BIT(PLANE_CURSOR);
869 const struct drm_framebuffer *fb = plane_state->base.fb;
870 unsigned int cpp = fb->format->cpp[0];
873 * VLV bspec only considers cases where all three planes are
874 * enabled, and cases where the primary and one sprite is enabled.
875 * Let's assume the case with just two sprites enabled also
876 * maps to the latter case.
878 if (hweight8(active_planes) == 3) {
893 } else if (hweight8(active_planes) == 2) {
922 int vlv_plane_min_cdclk(const struct intel_crtc_state *crtc_state,
923 const struct intel_plane_state *plane_state)
925 unsigned int pixel_rate;
926 unsigned int num, den;
929 * Note that crtc_state->pixel_rate accounts for both
930 * horizontal and vertical panel fitter downscaling factors.
931 * Pre-HSW bspec tells us to only consider the horizontal
932 * downscaling factor here. We ignore that and just consider
933 * both for simplicity.
935 pixel_rate = crtc_state->pixel_rate;
937 vlv_plane_ratio(crtc_state, plane_state, &num, &den);
939 return DIV_ROUND_UP(pixel_rate * num, den);
942 static u32 vlv_sprite_ctl_crtc(const struct intel_crtc_state *crtc_state)
946 if (crtc_state->gamma_enable)
947 sprctl |= SP_GAMMA_ENABLE;
952 static u32 vlv_sprite_ctl(const struct intel_crtc_state *crtc_state,
953 const struct intel_plane_state *plane_state)
955 const struct drm_framebuffer *fb = plane_state->base.fb;
956 unsigned int rotation = plane_state->base.rotation;
957 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
962 switch (fb->format->format) {
963 case DRM_FORMAT_YUYV:
964 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YUYV;
966 case DRM_FORMAT_YVYU:
967 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YVYU;
969 case DRM_FORMAT_UYVY:
970 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_UYVY;
972 case DRM_FORMAT_VYUY:
973 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_VYUY;
975 case DRM_FORMAT_RGB565:
976 sprctl |= SP_FORMAT_BGR565;
978 case DRM_FORMAT_XRGB8888:
979 sprctl |= SP_FORMAT_BGRX8888;
981 case DRM_FORMAT_ARGB8888:
982 sprctl |= SP_FORMAT_BGRA8888;
984 case DRM_FORMAT_XBGR2101010:
985 sprctl |= SP_FORMAT_RGBX1010102;
987 case DRM_FORMAT_ABGR2101010:
988 sprctl |= SP_FORMAT_RGBA1010102;
990 case DRM_FORMAT_XBGR8888:
991 sprctl |= SP_FORMAT_RGBX8888;
993 case DRM_FORMAT_ABGR8888:
994 sprctl |= SP_FORMAT_RGBA8888;
997 MISSING_CASE(fb->format->format);
1001 if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
1002 sprctl |= SP_YUV_FORMAT_BT709;
1004 if (fb->modifier == I915_FORMAT_MOD_X_TILED)
1007 if (rotation & DRM_MODE_ROTATE_180)
1008 sprctl |= SP_ROTATE_180;
1010 if (rotation & DRM_MODE_REFLECT_X)
1011 sprctl |= SP_MIRROR;
1013 if (key->flags & I915_SET_COLORKEY_SOURCE)
1014 sprctl |= SP_SOURCE_KEY;
1019 static void vlv_update_gamma(const struct intel_plane_state *plane_state)
1021 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
1022 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1023 const struct drm_framebuffer *fb = plane_state->base.fb;
1024 enum pipe pipe = plane->pipe;
1025 enum plane_id plane_id = plane->id;
1029 /* Seems RGB data bypasses the gamma always */
1030 if (!fb->format->is_yuv)
1033 i9xx_plane_linear_gamma(gamma);
1035 /* FIXME these register are single buffered :( */
1036 /* The two end points are implicit (0.0 and 1.0) */
1037 for (i = 1; i < 8 - 1; i++)
1038 I915_WRITE_FW(SPGAMC(pipe, plane_id, i - 1),
1045 vlv_update_plane(struct intel_plane *plane,
1046 const struct intel_crtc_state *crtc_state,
1047 const struct intel_plane_state *plane_state)
1049 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1050 enum pipe pipe = plane->pipe;
1051 enum plane_id plane_id = plane->id;
1052 u32 sprsurf_offset = plane_state->color_plane[0].offset;
1054 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
1055 int crtc_x = plane_state->base.dst.x1;
1056 int crtc_y = plane_state->base.dst.y1;
1057 u32 crtc_w = drm_rect_width(&plane_state->base.dst);
1058 u32 crtc_h = drm_rect_height(&plane_state->base.dst);
1059 u32 x = plane_state->color_plane[0].x;
1060 u32 y = plane_state->color_plane[0].y;
1061 unsigned long irqflags;
1064 sprctl = plane_state->ctl | vlv_sprite_ctl_crtc(crtc_state);
1066 /* Sizes are 0 based */
1070 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
1072 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
1074 I915_WRITE_FW(SPSTRIDE(pipe, plane_id),
1075 plane_state->color_plane[0].stride);
1076 I915_WRITE_FW(SPPOS(pipe, plane_id), (crtc_y << 16) | crtc_x);
1077 I915_WRITE_FW(SPSIZE(pipe, plane_id), (crtc_h << 16) | crtc_w);
1078 I915_WRITE_FW(SPCONSTALPHA(pipe, plane_id), 0);
1080 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B)
1081 chv_update_csc(plane_state);
1084 I915_WRITE_FW(SPKEYMINVAL(pipe, plane_id), key->min_value);
1085 I915_WRITE_FW(SPKEYMSK(pipe, plane_id), key->channel_mask);
1086 I915_WRITE_FW(SPKEYMAXVAL(pipe, plane_id), key->max_value);
1089 I915_WRITE_FW(SPLINOFF(pipe, plane_id), linear_offset);
1090 I915_WRITE_FW(SPTILEOFF(pipe, plane_id), (y << 16) | x);
1093 * The control register self-arms if the plane was previously
1094 * disabled. Try to make the plane enable atomic by writing
1095 * the control register just before the surface register.
1097 I915_WRITE_FW(SPCNTR(pipe, plane_id), sprctl);
1098 I915_WRITE_FW(SPSURF(pipe, plane_id),
1099 intel_plane_ggtt_offset(plane_state) + sprsurf_offset);
1101 vlv_update_clrc(plane_state);
1102 vlv_update_gamma(plane_state);
1104 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1108 vlv_disable_plane(struct intel_plane *plane,
1109 const struct intel_crtc_state *crtc_state)
1111 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1112 enum pipe pipe = plane->pipe;
1113 enum plane_id plane_id = plane->id;
1114 unsigned long irqflags;
1116 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
1118 I915_WRITE_FW(SPCNTR(pipe, plane_id), 0);
1119 I915_WRITE_FW(SPSURF(pipe, plane_id), 0);
1121 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1125 vlv_plane_get_hw_state(struct intel_plane *plane,
1128 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1129 enum intel_display_power_domain power_domain;
1130 enum plane_id plane_id = plane->id;
1131 intel_wakeref_t wakeref;
1134 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
1135 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
1139 ret = I915_READ(SPCNTR(plane->pipe, plane_id)) & SP_ENABLE;
1141 *pipe = plane->pipe;
1143 intel_display_power_put(dev_priv, power_domain, wakeref);
1148 static void ivb_plane_ratio(const struct intel_crtc_state *crtc_state,
1149 const struct intel_plane_state *plane_state,
1150 unsigned int *num, unsigned int *den)
1152 u8 active_planes = crtc_state->active_planes & ~BIT(PLANE_CURSOR);
1153 const struct drm_framebuffer *fb = plane_state->base.fb;
1154 unsigned int cpp = fb->format->cpp[0];
1156 if (hweight8(active_planes) == 2) {
1185 static void ivb_plane_ratio_scaling(const struct intel_crtc_state *crtc_state,
1186 const struct intel_plane_state *plane_state,
1187 unsigned int *num, unsigned int *den)
1189 const struct drm_framebuffer *fb = plane_state->base.fb;
1190 unsigned int cpp = fb->format->cpp[0];
1212 int ivb_plane_min_cdclk(const struct intel_crtc_state *crtc_state,
1213 const struct intel_plane_state *plane_state)
1215 unsigned int pixel_rate;
1216 unsigned int num, den;
1219 * Note that crtc_state->pixel_rate accounts for both
1220 * horizontal and vertical panel fitter downscaling factors.
1221 * Pre-HSW bspec tells us to only consider the horizontal
1222 * downscaling factor here. We ignore that and just consider
1223 * both for simplicity.
1225 pixel_rate = crtc_state->pixel_rate;
1227 ivb_plane_ratio(crtc_state, plane_state, &num, &den);
1229 return DIV_ROUND_UP(pixel_rate * num, den);
1232 static int ivb_sprite_min_cdclk(const struct intel_crtc_state *crtc_state,
1233 const struct intel_plane_state *plane_state)
1235 unsigned int src_w, dst_w, pixel_rate;
1236 unsigned int num, den;
1239 * Note that crtc_state->pixel_rate accounts for both
1240 * horizontal and vertical panel fitter downscaling factors.
1241 * Pre-HSW bspec tells us to only consider the horizontal
1242 * downscaling factor here. We ignore that and just consider
1243 * both for simplicity.
1245 pixel_rate = crtc_state->pixel_rate;
1247 src_w = drm_rect_width(&plane_state->base.src) >> 16;
1248 dst_w = drm_rect_width(&plane_state->base.dst);
1251 ivb_plane_ratio_scaling(crtc_state, plane_state, &num, &den);
1253 ivb_plane_ratio(crtc_state, plane_state, &num, &den);
1255 /* Horizontal downscaling limits the maximum pixel rate */
1256 dst_w = min(src_w, dst_w);
1258 return DIV_ROUND_UP_ULL(mul_u32_u32(pixel_rate, num * src_w),
1262 static void hsw_plane_ratio(const struct intel_crtc_state *crtc_state,
1263 const struct intel_plane_state *plane_state,
1264 unsigned int *num, unsigned int *den)
1266 u8 active_planes = crtc_state->active_planes & ~BIT(PLANE_CURSOR);
1267 const struct drm_framebuffer *fb = plane_state->base.fb;
1268 unsigned int cpp = fb->format->cpp[0];
1270 if (hweight8(active_planes) == 2) {
1295 int hsw_plane_min_cdclk(const struct intel_crtc_state *crtc_state,
1296 const struct intel_plane_state *plane_state)
1298 unsigned int pixel_rate = crtc_state->pixel_rate;
1299 unsigned int num, den;
1301 hsw_plane_ratio(crtc_state, plane_state, &num, &den);
1303 return DIV_ROUND_UP(pixel_rate * num, den);
1306 static u32 ivb_sprite_ctl_crtc(const struct intel_crtc_state *crtc_state)
1310 if (crtc_state->gamma_enable)
1311 sprctl |= SPRITE_GAMMA_ENABLE;
1313 if (crtc_state->csc_enable)
1314 sprctl |= SPRITE_PIPE_CSC_ENABLE;
1319 static bool ivb_need_sprite_gamma(const struct intel_plane_state *plane_state)
1321 struct drm_i915_private *dev_priv =
1322 to_i915(plane_state->base.plane->dev);
1323 const struct drm_framebuffer *fb = plane_state->base.fb;
1325 return fb->format->cpp[0] == 8 &&
1326 (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv));
1329 static u32 ivb_sprite_ctl(const struct intel_crtc_state *crtc_state,
1330 const struct intel_plane_state *plane_state)
1332 struct drm_i915_private *dev_priv =
1333 to_i915(plane_state->base.plane->dev);
1334 const struct drm_framebuffer *fb = plane_state->base.fb;
1335 unsigned int rotation = plane_state->base.rotation;
1336 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
1339 sprctl = SPRITE_ENABLE;
1341 if (IS_IVYBRIDGE(dev_priv))
1342 sprctl |= SPRITE_TRICKLE_FEED_DISABLE;
1344 switch (fb->format->format) {
1345 case DRM_FORMAT_XBGR8888:
1346 sprctl |= SPRITE_FORMAT_RGBX888 | SPRITE_RGB_ORDER_RGBX;
1348 case DRM_FORMAT_XRGB8888:
1349 sprctl |= SPRITE_FORMAT_RGBX888;
1351 case DRM_FORMAT_XBGR16161616F:
1352 sprctl |= SPRITE_FORMAT_RGBX161616 | SPRITE_RGB_ORDER_RGBX;
1354 case DRM_FORMAT_XRGB16161616F:
1355 sprctl |= SPRITE_FORMAT_RGBX161616;
1357 case DRM_FORMAT_YUYV:
1358 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YUYV;
1360 case DRM_FORMAT_YVYU:
1361 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YVYU;
1363 case DRM_FORMAT_UYVY:
1364 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_UYVY;
1366 case DRM_FORMAT_VYUY:
1367 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_VYUY;
1370 MISSING_CASE(fb->format->format);
1374 if (!ivb_need_sprite_gamma(plane_state))
1375 sprctl |= SPRITE_INT_GAMMA_DISABLE;
1377 if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
1378 sprctl |= SPRITE_YUV_TO_RGB_CSC_FORMAT_BT709;
1380 if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
1381 sprctl |= SPRITE_YUV_RANGE_CORRECTION_DISABLE;
1383 if (fb->modifier == I915_FORMAT_MOD_X_TILED)
1384 sprctl |= SPRITE_TILED;
1386 if (rotation & DRM_MODE_ROTATE_180)
1387 sprctl |= SPRITE_ROTATE_180;
1389 if (key->flags & I915_SET_COLORKEY_DESTINATION)
1390 sprctl |= SPRITE_DEST_KEY;
1391 else if (key->flags & I915_SET_COLORKEY_SOURCE)
1392 sprctl |= SPRITE_SOURCE_KEY;
1397 static void ivb_sprite_linear_gamma(const struct intel_plane_state *plane_state,
1403 * WaFP16GammaEnabling:ivb,hsw
1404 * "Workaround : When using the 64-bit format, the sprite output
1405 * on each color channel has one quarter amplitude. It can be
1406 * brought up to full amplitude by using sprite internal gamma
1407 * correction, pipe gamma correction, or pipe color space
1408 * conversion to multiply the sprite output by four."
1412 for (i = 0; i < 16; i++)
1413 gamma[i] = min((scale * i << 10) / 16, (1 << 10) - 1);
1415 gamma[i] = min((scale * i << 10) / 16, 1 << 10);
1422 static void ivb_update_gamma(const struct intel_plane_state *plane_state)
1424 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
1425 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1426 enum pipe pipe = plane->pipe;
1430 if (!ivb_need_sprite_gamma(plane_state))
1433 ivb_sprite_linear_gamma(plane_state, gamma);
1435 /* FIXME these register are single buffered :( */
1436 for (i = 0; i < 16; i++)
1437 I915_WRITE_FW(SPRGAMC(pipe, i),
1442 I915_WRITE_FW(SPRGAMC16(pipe, 0), gamma[i]);
1443 I915_WRITE_FW(SPRGAMC16(pipe, 1), gamma[i]);
1444 I915_WRITE_FW(SPRGAMC16(pipe, 2), gamma[i]);
1447 I915_WRITE_FW(SPRGAMC17(pipe, 0), gamma[i]);
1448 I915_WRITE_FW(SPRGAMC17(pipe, 1), gamma[i]);
1449 I915_WRITE_FW(SPRGAMC17(pipe, 2), gamma[i]);
1454 ivb_update_plane(struct intel_plane *plane,
1455 const struct intel_crtc_state *crtc_state,
1456 const struct intel_plane_state *plane_state)
1458 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1459 enum pipe pipe = plane->pipe;
1460 u32 sprsurf_offset = plane_state->color_plane[0].offset;
1462 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
1463 int crtc_x = plane_state->base.dst.x1;
1464 int crtc_y = plane_state->base.dst.y1;
1465 u32 crtc_w = drm_rect_width(&plane_state->base.dst);
1466 u32 crtc_h = drm_rect_height(&plane_state->base.dst);
1467 u32 x = plane_state->color_plane[0].x;
1468 u32 y = plane_state->color_plane[0].y;
1469 u32 src_w = drm_rect_width(&plane_state->base.src) >> 16;
1470 u32 src_h = drm_rect_height(&plane_state->base.src) >> 16;
1471 u32 sprctl, sprscale = 0;
1472 unsigned long irqflags;
1474 sprctl = plane_state->ctl | ivb_sprite_ctl_crtc(crtc_state);
1476 /* Sizes are 0 based */
1482 if (crtc_w != src_w || crtc_h != src_h)
1483 sprscale = SPRITE_SCALE_ENABLE | (src_w << 16) | src_h;
1485 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
1487 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
1489 I915_WRITE_FW(SPRSTRIDE(pipe), plane_state->color_plane[0].stride);
1490 I915_WRITE_FW(SPRPOS(pipe), (crtc_y << 16) | crtc_x);
1491 I915_WRITE_FW(SPRSIZE(pipe), (crtc_h << 16) | crtc_w);
1492 if (IS_IVYBRIDGE(dev_priv))
1493 I915_WRITE_FW(SPRSCALE(pipe), sprscale);
1496 I915_WRITE_FW(SPRKEYVAL(pipe), key->min_value);
1497 I915_WRITE_FW(SPRKEYMSK(pipe), key->channel_mask);
1498 I915_WRITE_FW(SPRKEYMAX(pipe), key->max_value);
1501 /* HSW consolidates SPRTILEOFF and SPRLINOFF into a single SPROFFSET
1503 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
1504 I915_WRITE_FW(SPROFFSET(pipe), (y << 16) | x);
1506 I915_WRITE_FW(SPRLINOFF(pipe), linear_offset);
1507 I915_WRITE_FW(SPRTILEOFF(pipe), (y << 16) | x);
1511 * The control register self-arms if the plane was previously
1512 * disabled. Try to make the plane enable atomic by writing
1513 * the control register just before the surface register.
1515 I915_WRITE_FW(SPRCTL(pipe), sprctl);
1516 I915_WRITE_FW(SPRSURF(pipe),
1517 intel_plane_ggtt_offset(plane_state) + sprsurf_offset);
1519 ivb_update_gamma(plane_state);
1521 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1525 ivb_disable_plane(struct intel_plane *plane,
1526 const struct intel_crtc_state *crtc_state)
1528 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1529 enum pipe pipe = plane->pipe;
1530 unsigned long irqflags;
1532 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
1534 I915_WRITE_FW(SPRCTL(pipe), 0);
1535 /* Disable the scaler */
1536 if (IS_IVYBRIDGE(dev_priv))
1537 I915_WRITE_FW(SPRSCALE(pipe), 0);
1538 I915_WRITE_FW(SPRSURF(pipe), 0);
1540 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1544 ivb_plane_get_hw_state(struct intel_plane *plane,
1547 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1548 enum intel_display_power_domain power_domain;
1549 intel_wakeref_t wakeref;
1552 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
1553 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
1557 ret = I915_READ(SPRCTL(plane->pipe)) & SPRITE_ENABLE;
1559 *pipe = plane->pipe;
1561 intel_display_power_put(dev_priv, power_domain, wakeref);
1566 static int g4x_sprite_min_cdclk(const struct intel_crtc_state *crtc_state,
1567 const struct intel_plane_state *plane_state)
1569 const struct drm_framebuffer *fb = plane_state->base.fb;
1570 unsigned int hscale, pixel_rate;
1571 unsigned int limit, decimate;
1574 * Note that crtc_state->pixel_rate accounts for both
1575 * horizontal and vertical panel fitter downscaling factors.
1576 * Pre-HSW bspec tells us to only consider the horizontal
1577 * downscaling factor here. We ignore that and just consider
1578 * both for simplicity.
1580 pixel_rate = crtc_state->pixel_rate;
1582 /* Horizontal downscaling limits the maximum pixel rate */
1583 hscale = drm_rect_calc_hscale(&plane_state->base.src,
1584 &plane_state->base.dst,
1586 if (hscale < 0x10000)
1589 /* Decimation steps at 2x,4x,8x,16x */
1590 decimate = ilog2(hscale >> 16);
1591 hscale >>= decimate;
1593 /* Starting limit is 90% of cdclk */
1596 /* -10% per decimation step */
1600 if (fb->format->cpp[0] >= 4)
1601 limit--; /* -10% for RGB */
1604 * We should also do -10% if sprite scaling is enabled
1605 * on the other pipe, but we can't really check for that,
1609 return DIV_ROUND_UP_ULL(mul_u32_u32(pixel_rate, 10 * hscale),
1614 g4x_sprite_max_stride(struct intel_plane *plane,
1615 u32 pixel_format, u64 modifier,
1616 unsigned int rotation)
1621 static u32 g4x_sprite_ctl_crtc(const struct intel_crtc_state *crtc_state)
1625 if (crtc_state->gamma_enable)
1626 dvscntr |= DVS_GAMMA_ENABLE;
1628 if (crtc_state->csc_enable)
1629 dvscntr |= DVS_PIPE_CSC_ENABLE;
1634 static u32 g4x_sprite_ctl(const struct intel_crtc_state *crtc_state,
1635 const struct intel_plane_state *plane_state)
1637 struct drm_i915_private *dev_priv =
1638 to_i915(plane_state->base.plane->dev);
1639 const struct drm_framebuffer *fb = plane_state->base.fb;
1640 unsigned int rotation = plane_state->base.rotation;
1641 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
1644 dvscntr = DVS_ENABLE;
1646 if (IS_GEN(dev_priv, 6))
1647 dvscntr |= DVS_TRICKLE_FEED_DISABLE;
1649 switch (fb->format->format) {
1650 case DRM_FORMAT_XBGR8888:
1651 dvscntr |= DVS_FORMAT_RGBX888 | DVS_RGB_ORDER_XBGR;
1653 case DRM_FORMAT_XRGB8888:
1654 dvscntr |= DVS_FORMAT_RGBX888;
1656 case DRM_FORMAT_XBGR16161616F:
1657 dvscntr |= DVS_FORMAT_RGBX161616 | DVS_RGB_ORDER_XBGR;
1659 case DRM_FORMAT_XRGB16161616F:
1660 dvscntr |= DVS_FORMAT_RGBX161616;
1662 case DRM_FORMAT_YUYV:
1663 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YUYV;
1665 case DRM_FORMAT_YVYU:
1666 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YVYU;
1668 case DRM_FORMAT_UYVY:
1669 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_UYVY;
1671 case DRM_FORMAT_VYUY:
1672 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_VYUY;
1675 MISSING_CASE(fb->format->format);
1679 if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
1680 dvscntr |= DVS_YUV_FORMAT_BT709;
1682 if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
1683 dvscntr |= DVS_YUV_RANGE_CORRECTION_DISABLE;
1685 if (fb->modifier == I915_FORMAT_MOD_X_TILED)
1686 dvscntr |= DVS_TILED;
1688 if (rotation & DRM_MODE_ROTATE_180)
1689 dvscntr |= DVS_ROTATE_180;
1691 if (key->flags & I915_SET_COLORKEY_DESTINATION)
1692 dvscntr |= DVS_DEST_KEY;
1693 else if (key->flags & I915_SET_COLORKEY_SOURCE)
1694 dvscntr |= DVS_SOURCE_KEY;
1699 static void g4x_update_gamma(const struct intel_plane_state *plane_state)
1701 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
1702 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1703 const struct drm_framebuffer *fb = plane_state->base.fb;
1704 enum pipe pipe = plane->pipe;
1708 /* Seems RGB data bypasses the gamma always */
1709 if (!fb->format->is_yuv)
1712 i9xx_plane_linear_gamma(gamma);
1714 /* FIXME these register are single buffered :( */
1715 /* The two end points are implicit (0.0 and 1.0) */
1716 for (i = 1; i < 8 - 1; i++)
1717 I915_WRITE_FW(DVSGAMC_G4X(pipe, i - 1),
1723 static void ilk_sprite_linear_gamma(u16 gamma[17])
1727 for (i = 0; i < 17; i++)
1728 gamma[i] = (i << 10) / 16;
1731 static void ilk_update_gamma(const struct intel_plane_state *plane_state)
1733 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
1734 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1735 const struct drm_framebuffer *fb = plane_state->base.fb;
1736 enum pipe pipe = plane->pipe;
1740 /* Seems RGB data bypasses the gamma always */
1741 if (!fb->format->is_yuv)
1744 ilk_sprite_linear_gamma(gamma);
1746 /* FIXME these register are single buffered :( */
1747 for (i = 0; i < 16; i++)
1748 I915_WRITE_FW(DVSGAMC_ILK(pipe, i),
1753 I915_WRITE_FW(DVSGAMCMAX_ILK(pipe, 0), gamma[i]);
1754 I915_WRITE_FW(DVSGAMCMAX_ILK(pipe, 1), gamma[i]);
1755 I915_WRITE_FW(DVSGAMCMAX_ILK(pipe, 2), gamma[i]);
1760 g4x_update_plane(struct intel_plane *plane,
1761 const struct intel_crtc_state *crtc_state,
1762 const struct intel_plane_state *plane_state)
1764 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1765 enum pipe pipe = plane->pipe;
1766 u32 dvssurf_offset = plane_state->color_plane[0].offset;
1768 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
1769 int crtc_x = plane_state->base.dst.x1;
1770 int crtc_y = plane_state->base.dst.y1;
1771 u32 crtc_w = drm_rect_width(&plane_state->base.dst);
1772 u32 crtc_h = drm_rect_height(&plane_state->base.dst);
1773 u32 x = plane_state->color_plane[0].x;
1774 u32 y = plane_state->color_plane[0].y;
1775 u32 src_w = drm_rect_width(&plane_state->base.src) >> 16;
1776 u32 src_h = drm_rect_height(&plane_state->base.src) >> 16;
1777 u32 dvscntr, dvsscale = 0;
1778 unsigned long irqflags;
1780 dvscntr = plane_state->ctl | g4x_sprite_ctl_crtc(crtc_state);
1782 /* Sizes are 0 based */
1788 if (crtc_w != src_w || crtc_h != src_h)
1789 dvsscale = DVS_SCALE_ENABLE | (src_w << 16) | src_h;
1791 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
1793 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
1795 I915_WRITE_FW(DVSSTRIDE(pipe), plane_state->color_plane[0].stride);
1796 I915_WRITE_FW(DVSPOS(pipe), (crtc_y << 16) | crtc_x);
1797 I915_WRITE_FW(DVSSIZE(pipe), (crtc_h << 16) | crtc_w);
1798 I915_WRITE_FW(DVSSCALE(pipe), dvsscale);
1801 I915_WRITE_FW(DVSKEYVAL(pipe), key->min_value);
1802 I915_WRITE_FW(DVSKEYMSK(pipe), key->channel_mask);
1803 I915_WRITE_FW(DVSKEYMAX(pipe), key->max_value);
1806 I915_WRITE_FW(DVSLINOFF(pipe), linear_offset);
1807 I915_WRITE_FW(DVSTILEOFF(pipe), (y << 16) | x);
1810 * The control register self-arms if the plane was previously
1811 * disabled. Try to make the plane enable atomic by writing
1812 * the control register just before the surface register.
1814 I915_WRITE_FW(DVSCNTR(pipe), dvscntr);
1815 I915_WRITE_FW(DVSSURF(pipe),
1816 intel_plane_ggtt_offset(plane_state) + dvssurf_offset);
1818 if (IS_G4X(dev_priv))
1819 g4x_update_gamma(plane_state);
1821 ilk_update_gamma(plane_state);
1823 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1827 g4x_disable_plane(struct intel_plane *plane,
1828 const struct intel_crtc_state *crtc_state)
1830 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1831 enum pipe pipe = plane->pipe;
1832 unsigned long irqflags;
1834 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
1836 I915_WRITE_FW(DVSCNTR(pipe), 0);
1837 /* Disable the scaler */
1838 I915_WRITE_FW(DVSSCALE(pipe), 0);
1839 I915_WRITE_FW(DVSSURF(pipe), 0);
1841 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1845 g4x_plane_get_hw_state(struct intel_plane *plane,
1848 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1849 enum intel_display_power_domain power_domain;
1850 intel_wakeref_t wakeref;
1853 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
1854 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
1858 ret = I915_READ(DVSCNTR(plane->pipe)) & DVS_ENABLE;
1860 *pipe = plane->pipe;
1862 intel_display_power_put(dev_priv, power_domain, wakeref);
1867 static bool intel_fb_scalable(const struct drm_framebuffer *fb)
1872 switch (fb->format->format) {
1875 case DRM_FORMAT_XRGB16161616F:
1876 case DRM_FORMAT_ARGB16161616F:
1877 case DRM_FORMAT_XBGR16161616F:
1878 case DRM_FORMAT_ABGR16161616F:
1879 return INTEL_GEN(to_i915(fb->dev)) >= 11;
1886 g4x_sprite_check_scaling(struct intel_crtc_state *crtc_state,
1887 struct intel_plane_state *plane_state)
1889 const struct drm_framebuffer *fb = plane_state->base.fb;
1890 const struct drm_rect *src = &plane_state->base.src;
1891 const struct drm_rect *dst = &plane_state->base.dst;
1892 int src_x, src_w, src_h, crtc_w, crtc_h;
1893 const struct drm_display_mode *adjusted_mode =
1894 &crtc_state->base.adjusted_mode;
1895 unsigned int stride = plane_state->color_plane[0].stride;
1896 unsigned int cpp = fb->format->cpp[0];
1897 unsigned int width_bytes;
1898 int min_width, min_height;
1900 crtc_w = drm_rect_width(dst);
1901 crtc_h = drm_rect_height(dst);
1903 src_x = src->x1 >> 16;
1904 src_w = drm_rect_width(src) >> 16;
1905 src_h = drm_rect_height(src) >> 16;
1907 if (src_w == crtc_w && src_h == crtc_h)
1912 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
1914 DRM_DEBUG_KMS("Source height must be even with interlaced modes\n");
1922 width_bytes = ((src_x * cpp) & 63) + src_w * cpp;
1924 if (src_w < min_width || src_h < min_height ||
1925 src_w > 2048 || src_h > 2048) {
1926 DRM_DEBUG_KMS("Source dimensions (%dx%d) exceed hardware limits (%dx%d - %dx%d)\n",
1927 src_w, src_h, min_width, min_height, 2048, 2048);
1931 if (width_bytes > 4096) {
1932 DRM_DEBUG_KMS("Fetch width (%d) exceeds hardware max with scaling (%u)\n",
1937 if (stride > 4096) {
1938 DRM_DEBUG_KMS("Stride (%u) exceeds hardware max with scaling (%u)\n",
1947 g4x_sprite_check(struct intel_crtc_state *crtc_state,
1948 struct intel_plane_state *plane_state)
1950 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
1951 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1952 int min_scale = DRM_PLANE_HELPER_NO_SCALING;
1953 int max_scale = DRM_PLANE_HELPER_NO_SCALING;
1956 if (intel_fb_scalable(plane_state->base.fb)) {
1957 if (INTEL_GEN(dev_priv) < 7) {
1959 max_scale = 16 << 16;
1960 } else if (IS_IVYBRIDGE(dev_priv)) {
1962 max_scale = 2 << 16;
1966 ret = drm_atomic_helper_check_plane_state(&plane_state->base,
1968 min_scale, max_scale,
1973 ret = i9xx_check_plane_surface(plane_state);
1977 if (!plane_state->base.visible)
1980 ret = intel_plane_check_src_coordinates(plane_state);
1984 ret = g4x_sprite_check_scaling(crtc_state, plane_state);
1988 if (INTEL_GEN(dev_priv) >= 7)
1989 plane_state->ctl = ivb_sprite_ctl(crtc_state, plane_state);
1991 plane_state->ctl = g4x_sprite_ctl(crtc_state, plane_state);
1996 int chv_plane_check_rotation(const struct intel_plane_state *plane_state)
1998 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
1999 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
2000 unsigned int rotation = plane_state->base.rotation;
2002 /* CHV ignores the mirror bit when the rotate bit is set :( */
2003 if (IS_CHERRYVIEW(dev_priv) &&
2004 rotation & DRM_MODE_ROTATE_180 &&
2005 rotation & DRM_MODE_REFLECT_X) {
2006 DRM_DEBUG_KMS("Cannot rotate and reflect at the same time\n");
2014 vlv_sprite_check(struct intel_crtc_state *crtc_state,
2015 struct intel_plane_state *plane_state)
2019 ret = chv_plane_check_rotation(plane_state);
2023 ret = drm_atomic_helper_check_plane_state(&plane_state->base,
2025 DRM_PLANE_HELPER_NO_SCALING,
2026 DRM_PLANE_HELPER_NO_SCALING,
2031 ret = i9xx_check_plane_surface(plane_state);
2035 if (!plane_state->base.visible)
2038 ret = intel_plane_check_src_coordinates(plane_state);
2042 plane_state->ctl = vlv_sprite_ctl(crtc_state, plane_state);
2047 static int skl_plane_check_fb(const struct intel_crtc_state *crtc_state,
2048 const struct intel_plane_state *plane_state)
2050 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
2051 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
2052 const struct drm_framebuffer *fb = plane_state->base.fb;
2053 unsigned int rotation = plane_state->base.rotation;
2054 struct drm_format_name_buf format_name;
2059 if (rotation & ~(DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180) &&
2060 is_ccs_modifier(fb->modifier)) {
2061 DRM_DEBUG_KMS("RC support only with 0/180 degree rotation (%x)\n",
2066 if (rotation & DRM_MODE_REFLECT_X &&
2067 fb->modifier == DRM_FORMAT_MOD_LINEAR) {
2068 DRM_DEBUG_KMS("horizontal flip is not supported with linear surface formats\n");
2072 if (drm_rotation_90_or_270(rotation)) {
2073 if (fb->modifier != I915_FORMAT_MOD_Y_TILED &&
2074 fb->modifier != I915_FORMAT_MOD_Yf_TILED) {
2075 DRM_DEBUG_KMS("Y/Yf tiling required for 90/270!\n");
2080 * 90/270 is not allowed with RGB64 16:16:16:16 and
2081 * Indexed 8-bit. RGB 16-bit 5:6:5 is allowed gen11 onwards.
2083 switch (fb->format->format) {
2084 case DRM_FORMAT_RGB565:
2085 if (INTEL_GEN(dev_priv) >= 11)
2089 case DRM_FORMAT_XRGB16161616F:
2090 case DRM_FORMAT_XBGR16161616F:
2091 case DRM_FORMAT_ARGB16161616F:
2092 case DRM_FORMAT_ABGR16161616F:
2093 case DRM_FORMAT_Y210:
2094 case DRM_FORMAT_Y212:
2095 case DRM_FORMAT_Y216:
2096 case DRM_FORMAT_XVYU12_16161616:
2097 case DRM_FORMAT_XVYU16161616:
2098 DRM_DEBUG_KMS("Unsupported pixel format %s for 90/270!\n",
2099 drm_get_format_name(fb->format->format,
2107 /* Y-tiling is not supported in IF-ID Interlace mode */
2108 if (crtc_state->base.enable &&
2109 crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE &&
2110 (fb->modifier == I915_FORMAT_MOD_Y_TILED ||
2111 fb->modifier == I915_FORMAT_MOD_Yf_TILED ||
2112 fb->modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
2113 fb->modifier == I915_FORMAT_MOD_Yf_TILED_CCS)) {
2114 DRM_DEBUG_KMS("Y/Yf tiling not supported in IF-ID mode\n");
2121 static int skl_plane_check_dst_coordinates(const struct intel_crtc_state *crtc_state,
2122 const struct intel_plane_state *plane_state)
2124 struct drm_i915_private *dev_priv =
2125 to_i915(plane_state->base.plane->dev);
2126 int crtc_x = plane_state->base.dst.x1;
2127 int crtc_w = drm_rect_width(&plane_state->base.dst);
2128 int pipe_src_w = crtc_state->pipe_src_w;
2131 * Display WA #1175: cnl,glk
2132 * Planes other than the cursor may cause FIFO underflow and display
2133 * corruption if starting less than 4 pixels from the right edge of
2135 * Besides the above WA fix the similar problem, where planes other
2136 * than the cursor ending less than 4 pixels from the left edge of the
2137 * screen may cause FIFO underflow and display corruption.
2139 if ((IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) &&
2140 (crtc_x + crtc_w < 4 || crtc_x > pipe_src_w - 4)) {
2141 DRM_DEBUG_KMS("requested plane X %s position %d invalid (valid range %d-%d)\n",
2142 crtc_x + crtc_w < 4 ? "end" : "start",
2143 crtc_x + crtc_w < 4 ? crtc_x + crtc_w : crtc_x,
2151 static int skl_plane_check_nv12_rotation(const struct intel_plane_state *plane_state)
2153 const struct drm_framebuffer *fb = plane_state->base.fb;
2154 unsigned int rotation = plane_state->base.rotation;
2155 int src_w = drm_rect_width(&plane_state->base.src) >> 16;
2157 /* Display WA #1106 */
2158 if (drm_format_info_is_yuv_semiplanar(fb->format) && src_w & 3 &&
2159 (rotation == DRM_MODE_ROTATE_270 ||
2160 rotation == (DRM_MODE_REFLECT_X | DRM_MODE_ROTATE_90))) {
2161 DRM_DEBUG_KMS("src width must be multiple of 4 for rotated planar YUV\n");
2168 static int skl_plane_max_scale(struct drm_i915_private *dev_priv,
2169 const struct drm_framebuffer *fb)
2172 * We don't yet know the final source width nor
2173 * whether we can use the HQ scaler mode. Assume
2175 * FIXME need to properly check this later.
2177 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv) ||
2178 !drm_format_info_is_yuv_semiplanar(fb->format))
2184 static int skl_plane_check(struct intel_crtc_state *crtc_state,
2185 struct intel_plane_state *plane_state)
2187 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
2188 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
2189 const struct drm_framebuffer *fb = plane_state->base.fb;
2190 int min_scale = DRM_PLANE_HELPER_NO_SCALING;
2191 int max_scale = DRM_PLANE_HELPER_NO_SCALING;
2194 ret = skl_plane_check_fb(crtc_state, plane_state);
2198 /* use scaler when colorkey is not required */
2199 if (!plane_state->ckey.flags && intel_fb_scalable(fb)) {
2201 max_scale = skl_plane_max_scale(dev_priv, fb);
2204 ret = drm_atomic_helper_check_plane_state(&plane_state->base,
2206 min_scale, max_scale,
2211 ret = skl_check_plane_surface(plane_state);
2215 if (!plane_state->base.visible)
2218 ret = skl_plane_check_dst_coordinates(crtc_state, plane_state);
2222 ret = intel_plane_check_src_coordinates(plane_state);
2226 ret = skl_plane_check_nv12_rotation(plane_state);
2230 /* HW only has 8 bits pixel precision, disable plane if invisible */
2231 if (!(plane_state->base.alpha >> 8))
2232 plane_state->base.visible = false;
2234 plane_state->ctl = skl_plane_ctl(crtc_state, plane_state);
2236 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
2237 plane_state->color_ctl = glk_plane_color_ctl(crtc_state,
2243 static bool has_dst_key_in_primary_plane(struct drm_i915_private *dev_priv)
2245 return INTEL_GEN(dev_priv) >= 9;
2248 static void intel_plane_set_ckey(struct intel_plane_state *plane_state,
2249 const struct drm_intel_sprite_colorkey *set)
2251 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
2252 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
2253 struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
2258 * We want src key enabled on the
2259 * sprite and not on the primary.
2261 if (plane->id == PLANE_PRIMARY &&
2262 set->flags & I915_SET_COLORKEY_SOURCE)
2266 * On SKL+ we want dst key enabled on
2267 * the primary and not on the sprite.
2269 if (INTEL_GEN(dev_priv) >= 9 && plane->id != PLANE_PRIMARY &&
2270 set->flags & I915_SET_COLORKEY_DESTINATION)
2274 int intel_sprite_set_colorkey_ioctl(struct drm_device *dev, void *data,
2275 struct drm_file *file_priv)
2277 struct drm_i915_private *dev_priv = to_i915(dev);
2278 struct drm_intel_sprite_colorkey *set = data;
2279 struct drm_plane *plane;
2280 struct drm_plane_state *plane_state;
2281 struct drm_atomic_state *state;
2282 struct drm_modeset_acquire_ctx ctx;
2285 /* ignore the pointless "none" flag */
2286 set->flags &= ~I915_SET_COLORKEY_NONE;
2288 if (set->flags & ~(I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE))
2291 /* Make sure we don't try to enable both src & dest simultaneously */
2292 if ((set->flags & (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE)) == (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE))
2295 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
2296 set->flags & I915_SET_COLORKEY_DESTINATION)
2299 plane = drm_plane_find(dev, file_priv, set->plane_id);
2300 if (!plane || plane->type != DRM_PLANE_TYPE_OVERLAY)
2304 * SKL+ only plane 2 can do destination keying against plane 1.
2305 * Also multiple planes can't do destination keying on the same
2306 * pipe simultaneously.
2308 if (INTEL_GEN(dev_priv) >= 9 &&
2309 to_intel_plane(plane)->id >= PLANE_SPRITE1 &&
2310 set->flags & I915_SET_COLORKEY_DESTINATION)
2313 drm_modeset_acquire_init(&ctx, 0);
2315 state = drm_atomic_state_alloc(plane->dev);
2320 state->acquire_ctx = &ctx;
2323 plane_state = drm_atomic_get_plane_state(state, plane);
2324 ret = PTR_ERR_OR_ZERO(plane_state);
2326 intel_plane_set_ckey(to_intel_plane_state(plane_state), set);
2329 * On some platforms we have to configure
2330 * the dst colorkey on the primary plane.
2332 if (!ret && has_dst_key_in_primary_plane(dev_priv)) {
2333 struct intel_crtc *crtc =
2334 intel_get_crtc_for_pipe(dev_priv,
2335 to_intel_plane(plane)->pipe);
2337 plane_state = drm_atomic_get_plane_state(state,
2338 crtc->base.primary);
2339 ret = PTR_ERR_OR_ZERO(plane_state);
2341 intel_plane_set_ckey(to_intel_plane_state(plane_state), set);
2345 ret = drm_atomic_commit(state);
2347 if (ret != -EDEADLK)
2350 drm_atomic_state_clear(state);
2351 drm_modeset_backoff(&ctx);
2354 drm_atomic_state_put(state);
2356 drm_modeset_drop_locks(&ctx);
2357 drm_modeset_acquire_fini(&ctx);
2361 static const u32 g4x_plane_formats[] = {
2362 DRM_FORMAT_XRGB8888,
2369 static const u64 i9xx_plane_format_modifiers[] = {
2370 I915_FORMAT_MOD_X_TILED,
2371 DRM_FORMAT_MOD_LINEAR,
2372 DRM_FORMAT_MOD_INVALID
2375 static const u32 snb_plane_formats[] = {
2376 DRM_FORMAT_XRGB8888,
2377 DRM_FORMAT_XBGR8888,
2378 DRM_FORMAT_XRGB16161616F,
2379 DRM_FORMAT_XBGR16161616F,
2386 static const u32 vlv_plane_formats[] = {
2388 DRM_FORMAT_ABGR8888,
2389 DRM_FORMAT_ARGB8888,
2390 DRM_FORMAT_XBGR8888,
2391 DRM_FORMAT_XRGB8888,
2392 DRM_FORMAT_XBGR2101010,
2393 DRM_FORMAT_ABGR2101010,
2400 static const u32 skl_plane_formats[] = {
2403 DRM_FORMAT_XRGB8888,
2404 DRM_FORMAT_XBGR8888,
2405 DRM_FORMAT_ARGB8888,
2406 DRM_FORMAT_ABGR8888,
2407 DRM_FORMAT_XRGB2101010,
2408 DRM_FORMAT_XBGR2101010,
2409 DRM_FORMAT_XRGB16161616F,
2410 DRM_FORMAT_XBGR16161616F,
2417 static const u32 skl_planar_formats[] = {
2420 DRM_FORMAT_XRGB8888,
2421 DRM_FORMAT_XBGR8888,
2422 DRM_FORMAT_ARGB8888,
2423 DRM_FORMAT_ABGR8888,
2424 DRM_FORMAT_XRGB2101010,
2425 DRM_FORMAT_XBGR2101010,
2426 DRM_FORMAT_XRGB16161616F,
2427 DRM_FORMAT_XBGR16161616F,
2435 static const u32 glk_planar_formats[] = {
2438 DRM_FORMAT_XRGB8888,
2439 DRM_FORMAT_XBGR8888,
2440 DRM_FORMAT_ARGB8888,
2441 DRM_FORMAT_ABGR8888,
2442 DRM_FORMAT_XRGB2101010,
2443 DRM_FORMAT_XBGR2101010,
2444 DRM_FORMAT_XRGB16161616F,
2445 DRM_FORMAT_XBGR16161616F,
2456 static const u32 icl_sdr_y_plane_formats[] = {
2459 DRM_FORMAT_XRGB8888,
2460 DRM_FORMAT_XBGR8888,
2461 DRM_FORMAT_ARGB8888,
2462 DRM_FORMAT_ABGR8888,
2463 DRM_FORMAT_XRGB2101010,
2464 DRM_FORMAT_XBGR2101010,
2472 DRM_FORMAT_XVYU2101010,
2473 DRM_FORMAT_XVYU12_16161616,
2474 DRM_FORMAT_XVYU16161616,
2477 static const u32 icl_sdr_uv_plane_formats[] = {
2480 DRM_FORMAT_XRGB8888,
2481 DRM_FORMAT_XBGR8888,
2482 DRM_FORMAT_ARGB8888,
2483 DRM_FORMAT_ABGR8888,
2484 DRM_FORMAT_XRGB2101010,
2485 DRM_FORMAT_XBGR2101010,
2497 DRM_FORMAT_XVYU2101010,
2498 DRM_FORMAT_XVYU12_16161616,
2499 DRM_FORMAT_XVYU16161616,
2502 static const u32 icl_hdr_plane_formats[] = {
2505 DRM_FORMAT_XRGB8888,
2506 DRM_FORMAT_XBGR8888,
2507 DRM_FORMAT_ARGB8888,
2508 DRM_FORMAT_ABGR8888,
2509 DRM_FORMAT_XRGB2101010,
2510 DRM_FORMAT_XBGR2101010,
2511 DRM_FORMAT_XRGB16161616F,
2512 DRM_FORMAT_XBGR16161616F,
2513 DRM_FORMAT_ARGB16161616F,
2514 DRM_FORMAT_ABGR16161616F,
2526 DRM_FORMAT_XVYU2101010,
2527 DRM_FORMAT_XVYU12_16161616,
2528 DRM_FORMAT_XVYU16161616,
2531 static const u64 skl_plane_format_modifiers_noccs[] = {
2532 I915_FORMAT_MOD_Yf_TILED,
2533 I915_FORMAT_MOD_Y_TILED,
2534 I915_FORMAT_MOD_X_TILED,
2535 DRM_FORMAT_MOD_LINEAR,
2536 DRM_FORMAT_MOD_INVALID
2539 static const u64 skl_plane_format_modifiers_ccs[] = {
2540 I915_FORMAT_MOD_Yf_TILED_CCS,
2541 I915_FORMAT_MOD_Y_TILED_CCS,
2542 I915_FORMAT_MOD_Yf_TILED,
2543 I915_FORMAT_MOD_Y_TILED,
2544 I915_FORMAT_MOD_X_TILED,
2545 DRM_FORMAT_MOD_LINEAR,
2546 DRM_FORMAT_MOD_INVALID
2549 static const u64 gen12_plane_format_modifiers_noccs[] = {
2550 I915_FORMAT_MOD_Y_TILED,
2551 I915_FORMAT_MOD_X_TILED,
2552 DRM_FORMAT_MOD_LINEAR,
2553 DRM_FORMAT_MOD_INVALID
2556 static bool g4x_sprite_format_mod_supported(struct drm_plane *_plane,
2557 u32 format, u64 modifier)
2560 case DRM_FORMAT_MOD_LINEAR:
2561 case I915_FORMAT_MOD_X_TILED:
2568 case DRM_FORMAT_XRGB8888:
2569 case DRM_FORMAT_YUYV:
2570 case DRM_FORMAT_YVYU:
2571 case DRM_FORMAT_UYVY:
2572 case DRM_FORMAT_VYUY:
2573 if (modifier == DRM_FORMAT_MOD_LINEAR ||
2574 modifier == I915_FORMAT_MOD_X_TILED)
2582 static bool snb_sprite_format_mod_supported(struct drm_plane *_plane,
2583 u32 format, u64 modifier)
2586 case DRM_FORMAT_MOD_LINEAR:
2587 case I915_FORMAT_MOD_X_TILED:
2594 case DRM_FORMAT_XRGB8888:
2595 case DRM_FORMAT_XBGR8888:
2596 case DRM_FORMAT_XRGB16161616F:
2597 case DRM_FORMAT_XBGR16161616F:
2598 case DRM_FORMAT_YUYV:
2599 case DRM_FORMAT_YVYU:
2600 case DRM_FORMAT_UYVY:
2601 case DRM_FORMAT_VYUY:
2602 if (modifier == DRM_FORMAT_MOD_LINEAR ||
2603 modifier == I915_FORMAT_MOD_X_TILED)
2611 static bool vlv_sprite_format_mod_supported(struct drm_plane *_plane,
2612 u32 format, u64 modifier)
2615 case DRM_FORMAT_MOD_LINEAR:
2616 case I915_FORMAT_MOD_X_TILED:
2623 case DRM_FORMAT_RGB565:
2624 case DRM_FORMAT_ABGR8888:
2625 case DRM_FORMAT_ARGB8888:
2626 case DRM_FORMAT_XBGR8888:
2627 case DRM_FORMAT_XRGB8888:
2628 case DRM_FORMAT_XBGR2101010:
2629 case DRM_FORMAT_ABGR2101010:
2630 case DRM_FORMAT_YUYV:
2631 case DRM_FORMAT_YVYU:
2632 case DRM_FORMAT_UYVY:
2633 case DRM_FORMAT_VYUY:
2634 if (modifier == DRM_FORMAT_MOD_LINEAR ||
2635 modifier == I915_FORMAT_MOD_X_TILED)
2643 static bool skl_plane_format_mod_supported(struct drm_plane *_plane,
2644 u32 format, u64 modifier)
2646 struct intel_plane *plane = to_intel_plane(_plane);
2649 case DRM_FORMAT_MOD_LINEAR:
2650 case I915_FORMAT_MOD_X_TILED:
2651 case I915_FORMAT_MOD_Y_TILED:
2652 case I915_FORMAT_MOD_Yf_TILED:
2654 case I915_FORMAT_MOD_Y_TILED_CCS:
2655 case I915_FORMAT_MOD_Yf_TILED_CCS:
2656 if (!plane->has_ccs)
2664 case DRM_FORMAT_XRGB8888:
2665 case DRM_FORMAT_XBGR8888:
2666 case DRM_FORMAT_ARGB8888:
2667 case DRM_FORMAT_ABGR8888:
2668 if (is_ccs_modifier(modifier))
2671 case DRM_FORMAT_RGB565:
2672 case DRM_FORMAT_XRGB2101010:
2673 case DRM_FORMAT_XBGR2101010:
2674 case DRM_FORMAT_YUYV:
2675 case DRM_FORMAT_YVYU:
2676 case DRM_FORMAT_UYVY:
2677 case DRM_FORMAT_VYUY:
2678 case DRM_FORMAT_NV12:
2679 case DRM_FORMAT_P010:
2680 case DRM_FORMAT_P012:
2681 case DRM_FORMAT_P016:
2682 case DRM_FORMAT_XVYU2101010:
2683 if (modifier == I915_FORMAT_MOD_Yf_TILED)
2687 case DRM_FORMAT_XBGR16161616F:
2688 case DRM_FORMAT_ABGR16161616F:
2689 case DRM_FORMAT_XRGB16161616F:
2690 case DRM_FORMAT_ARGB16161616F:
2691 case DRM_FORMAT_Y210:
2692 case DRM_FORMAT_Y212:
2693 case DRM_FORMAT_Y216:
2694 case DRM_FORMAT_XVYU12_16161616:
2695 case DRM_FORMAT_XVYU16161616:
2696 if (modifier == DRM_FORMAT_MOD_LINEAR ||
2697 modifier == I915_FORMAT_MOD_X_TILED ||
2698 modifier == I915_FORMAT_MOD_Y_TILED)
2706 static bool gen12_plane_format_mod_supported(struct drm_plane *_plane,
2707 u32 format, u64 modifier)
2710 case DRM_FORMAT_MOD_LINEAR:
2711 case I915_FORMAT_MOD_X_TILED:
2712 case I915_FORMAT_MOD_Y_TILED:
2719 case DRM_FORMAT_XRGB8888:
2720 case DRM_FORMAT_XBGR8888:
2721 case DRM_FORMAT_ARGB8888:
2722 case DRM_FORMAT_ABGR8888:
2723 case DRM_FORMAT_RGB565:
2724 case DRM_FORMAT_XRGB2101010:
2725 case DRM_FORMAT_XBGR2101010:
2726 case DRM_FORMAT_YUYV:
2727 case DRM_FORMAT_YVYU:
2728 case DRM_FORMAT_UYVY:
2729 case DRM_FORMAT_VYUY:
2730 case DRM_FORMAT_NV12:
2731 case DRM_FORMAT_P010:
2732 case DRM_FORMAT_P012:
2733 case DRM_FORMAT_P016:
2734 case DRM_FORMAT_XVYU2101010:
2736 case DRM_FORMAT_XBGR16161616F:
2737 case DRM_FORMAT_ABGR16161616F:
2738 case DRM_FORMAT_XRGB16161616F:
2739 case DRM_FORMAT_ARGB16161616F:
2740 case DRM_FORMAT_Y210:
2741 case DRM_FORMAT_Y212:
2742 case DRM_FORMAT_Y216:
2743 case DRM_FORMAT_XVYU12_16161616:
2744 case DRM_FORMAT_XVYU16161616:
2745 if (modifier == DRM_FORMAT_MOD_LINEAR ||
2746 modifier == I915_FORMAT_MOD_X_TILED ||
2747 modifier == I915_FORMAT_MOD_Y_TILED)
2755 static const struct drm_plane_funcs g4x_sprite_funcs = {
2756 .update_plane = drm_atomic_helper_update_plane,
2757 .disable_plane = drm_atomic_helper_disable_plane,
2758 .destroy = intel_plane_destroy,
2759 .atomic_duplicate_state = intel_plane_duplicate_state,
2760 .atomic_destroy_state = intel_plane_destroy_state,
2761 .format_mod_supported = g4x_sprite_format_mod_supported,
2764 static const struct drm_plane_funcs snb_sprite_funcs = {
2765 .update_plane = drm_atomic_helper_update_plane,
2766 .disable_plane = drm_atomic_helper_disable_plane,
2767 .destroy = intel_plane_destroy,
2768 .atomic_duplicate_state = intel_plane_duplicate_state,
2769 .atomic_destroy_state = intel_plane_destroy_state,
2770 .format_mod_supported = snb_sprite_format_mod_supported,
2773 static const struct drm_plane_funcs vlv_sprite_funcs = {
2774 .update_plane = drm_atomic_helper_update_plane,
2775 .disable_plane = drm_atomic_helper_disable_plane,
2776 .destroy = intel_plane_destroy,
2777 .atomic_duplicate_state = intel_plane_duplicate_state,
2778 .atomic_destroy_state = intel_plane_destroy_state,
2779 .format_mod_supported = vlv_sprite_format_mod_supported,
2782 static const struct drm_plane_funcs skl_plane_funcs = {
2783 .update_plane = drm_atomic_helper_update_plane,
2784 .disable_plane = drm_atomic_helper_disable_plane,
2785 .destroy = intel_plane_destroy,
2786 .atomic_duplicate_state = intel_plane_duplicate_state,
2787 .atomic_destroy_state = intel_plane_destroy_state,
2788 .format_mod_supported = skl_plane_format_mod_supported,
2791 static const struct drm_plane_funcs gen12_plane_funcs = {
2792 .update_plane = drm_atomic_helper_update_plane,
2793 .disable_plane = drm_atomic_helper_disable_plane,
2794 .destroy = intel_plane_destroy,
2795 .atomic_duplicate_state = intel_plane_duplicate_state,
2796 .atomic_destroy_state = intel_plane_destroy_state,
2797 .format_mod_supported = gen12_plane_format_mod_supported,
2800 static bool skl_plane_has_fbc(struct drm_i915_private *dev_priv,
2801 enum pipe pipe, enum plane_id plane_id)
2803 if (!HAS_FBC(dev_priv))
2806 return pipe == PIPE_A && plane_id == PLANE_PRIMARY;
2809 static bool skl_plane_has_planar(struct drm_i915_private *dev_priv,
2810 enum pipe pipe, enum plane_id plane_id)
2812 /* Display WA #0870: skl, bxt */
2813 if (IS_SKYLAKE(dev_priv) || IS_BROXTON(dev_priv))
2816 if (IS_GEN(dev_priv, 9) && !IS_GEMINILAKE(dev_priv) && pipe == PIPE_C)
2819 if (plane_id != PLANE_PRIMARY && plane_id != PLANE_SPRITE0)
2825 static const u32 *skl_get_plane_formats(struct drm_i915_private *dev_priv,
2826 enum pipe pipe, enum plane_id plane_id,
2829 if (skl_plane_has_planar(dev_priv, pipe, plane_id)) {
2830 *num_formats = ARRAY_SIZE(skl_planar_formats);
2831 return skl_planar_formats;
2833 *num_formats = ARRAY_SIZE(skl_plane_formats);
2834 return skl_plane_formats;
2838 static const u32 *glk_get_plane_formats(struct drm_i915_private *dev_priv,
2839 enum pipe pipe, enum plane_id plane_id,
2842 if (skl_plane_has_planar(dev_priv, pipe, plane_id)) {
2843 *num_formats = ARRAY_SIZE(glk_planar_formats);
2844 return glk_planar_formats;
2846 *num_formats = ARRAY_SIZE(skl_plane_formats);
2847 return skl_plane_formats;
2851 static const u32 *icl_get_plane_formats(struct drm_i915_private *dev_priv,
2852 enum pipe pipe, enum plane_id plane_id,
2855 if (icl_is_hdr_plane(dev_priv, plane_id)) {
2856 *num_formats = ARRAY_SIZE(icl_hdr_plane_formats);
2857 return icl_hdr_plane_formats;
2858 } else if (icl_is_nv12_y_plane(plane_id)) {
2859 *num_formats = ARRAY_SIZE(icl_sdr_y_plane_formats);
2860 return icl_sdr_y_plane_formats;
2862 *num_formats = ARRAY_SIZE(icl_sdr_uv_plane_formats);
2863 return icl_sdr_uv_plane_formats;
2867 static bool skl_plane_has_ccs(struct drm_i915_private *dev_priv,
2868 enum pipe pipe, enum plane_id plane_id)
2870 if (plane_id == PLANE_CURSOR)
2873 if (INTEL_GEN(dev_priv) >= 10)
2876 if (IS_GEMINILAKE(dev_priv))
2877 return pipe != PIPE_C;
2879 return pipe != PIPE_C &&
2880 (plane_id == PLANE_PRIMARY ||
2881 plane_id == PLANE_SPRITE0);
2884 struct intel_plane *
2885 skl_universal_plane_create(struct drm_i915_private *dev_priv,
2886 enum pipe pipe, enum plane_id plane_id)
2888 const struct drm_plane_funcs *plane_funcs;
2889 struct intel_plane *plane;
2890 enum drm_plane_type plane_type;
2891 unsigned int supported_rotations;
2892 unsigned int possible_crtcs;
2893 const u64 *modifiers;
2898 plane = intel_plane_alloc();
2903 plane->id = plane_id;
2904 plane->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, plane_id);
2906 plane->has_fbc = skl_plane_has_fbc(dev_priv, pipe, plane_id);
2907 if (plane->has_fbc) {
2908 struct intel_fbc *fbc = &dev_priv->fbc;
2910 fbc->possible_framebuffer_bits |= plane->frontbuffer_bit;
2913 plane->max_stride = skl_plane_max_stride;
2914 plane->update_plane = skl_update_plane;
2915 plane->disable_plane = skl_disable_plane;
2916 plane->get_hw_state = skl_plane_get_hw_state;
2917 plane->check_plane = skl_plane_check;
2918 plane->min_cdclk = skl_plane_min_cdclk;
2919 if (icl_is_nv12_y_plane(plane_id))
2920 plane->update_slave = icl_update_slave;
2922 if (INTEL_GEN(dev_priv) >= 11)
2923 formats = icl_get_plane_formats(dev_priv, pipe,
2924 plane_id, &num_formats);
2925 else if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
2926 formats = glk_get_plane_formats(dev_priv, pipe,
2927 plane_id, &num_formats);
2929 formats = skl_get_plane_formats(dev_priv, pipe,
2930 plane_id, &num_formats);
2932 if (INTEL_GEN(dev_priv) >= 12) {
2933 /* TODO: Implement support for gen-12 CCS modifiers */
2934 plane->has_ccs = false;
2935 modifiers = gen12_plane_format_modifiers_noccs;
2936 plane_funcs = &gen12_plane_funcs;
2938 plane->has_ccs = skl_plane_has_ccs(dev_priv, pipe, plane_id);
2940 modifiers = skl_plane_format_modifiers_ccs;
2942 modifiers = skl_plane_format_modifiers_noccs;
2943 plane_funcs = &skl_plane_funcs;
2946 if (plane_id == PLANE_PRIMARY)
2947 plane_type = DRM_PLANE_TYPE_PRIMARY;
2949 plane_type = DRM_PLANE_TYPE_OVERLAY;
2951 possible_crtcs = BIT(pipe);
2953 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
2954 possible_crtcs, plane_funcs,
2955 formats, num_formats, modifiers,
2957 "plane %d%c", plane_id + 1,
2962 supported_rotations =
2963 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_90 |
2964 DRM_MODE_ROTATE_180 | DRM_MODE_ROTATE_270;
2966 if (INTEL_GEN(dev_priv) >= 10)
2967 supported_rotations |= DRM_MODE_REFLECT_X;
2969 drm_plane_create_rotation_property(&plane->base,
2971 supported_rotations);
2973 drm_plane_create_color_properties(&plane->base,
2974 BIT(DRM_COLOR_YCBCR_BT601) |
2975 BIT(DRM_COLOR_YCBCR_BT709),
2976 BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) |
2977 BIT(DRM_COLOR_YCBCR_FULL_RANGE),
2978 DRM_COLOR_YCBCR_BT709,
2979 DRM_COLOR_YCBCR_LIMITED_RANGE);
2981 drm_plane_create_alpha_property(&plane->base);
2982 drm_plane_create_blend_mode_property(&plane->base,
2983 BIT(DRM_MODE_BLEND_PIXEL_NONE) |
2984 BIT(DRM_MODE_BLEND_PREMULTI) |
2985 BIT(DRM_MODE_BLEND_COVERAGE));
2987 drm_plane_create_zpos_immutable_property(&plane->base, plane_id);
2989 drm_plane_helper_add(&plane->base, &intel_plane_helper_funcs);
2994 intel_plane_free(plane);
2996 return ERR_PTR(ret);
2999 struct intel_plane *
3000 intel_sprite_plane_create(struct drm_i915_private *dev_priv,
3001 enum pipe pipe, int sprite)
3003 struct intel_plane *plane;
3004 const struct drm_plane_funcs *plane_funcs;
3005 unsigned long possible_crtcs;
3006 unsigned int supported_rotations;
3007 const u64 *modifiers;
3012 if (INTEL_GEN(dev_priv) >= 9)
3013 return skl_universal_plane_create(dev_priv, pipe,
3014 PLANE_SPRITE0 + sprite);
3016 plane = intel_plane_alloc();
3020 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
3021 plane->max_stride = i9xx_plane_max_stride;
3022 plane->update_plane = vlv_update_plane;
3023 plane->disable_plane = vlv_disable_plane;
3024 plane->get_hw_state = vlv_plane_get_hw_state;
3025 plane->check_plane = vlv_sprite_check;
3026 plane->min_cdclk = vlv_plane_min_cdclk;
3028 formats = vlv_plane_formats;
3029 num_formats = ARRAY_SIZE(vlv_plane_formats);
3030 modifiers = i9xx_plane_format_modifiers;
3032 plane_funcs = &vlv_sprite_funcs;
3033 } else if (INTEL_GEN(dev_priv) >= 7) {
3034 plane->max_stride = g4x_sprite_max_stride;
3035 plane->update_plane = ivb_update_plane;
3036 plane->disable_plane = ivb_disable_plane;
3037 plane->get_hw_state = ivb_plane_get_hw_state;
3038 plane->check_plane = g4x_sprite_check;
3040 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
3041 plane->min_cdclk = hsw_plane_min_cdclk;
3043 plane->min_cdclk = ivb_sprite_min_cdclk;
3045 formats = snb_plane_formats;
3046 num_formats = ARRAY_SIZE(snb_plane_formats);
3047 modifiers = i9xx_plane_format_modifiers;
3049 plane_funcs = &snb_sprite_funcs;
3051 plane->max_stride = g4x_sprite_max_stride;
3052 plane->update_plane = g4x_update_plane;
3053 plane->disable_plane = g4x_disable_plane;
3054 plane->get_hw_state = g4x_plane_get_hw_state;
3055 plane->check_plane = g4x_sprite_check;
3056 plane->min_cdclk = g4x_sprite_min_cdclk;
3058 modifiers = i9xx_plane_format_modifiers;
3059 if (IS_GEN(dev_priv, 6)) {
3060 formats = snb_plane_formats;
3061 num_formats = ARRAY_SIZE(snb_plane_formats);
3063 plane_funcs = &snb_sprite_funcs;
3065 formats = g4x_plane_formats;
3066 num_formats = ARRAY_SIZE(g4x_plane_formats);
3068 plane_funcs = &g4x_sprite_funcs;
3072 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
3073 supported_rotations =
3074 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 |
3077 supported_rotations =
3078 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180;
3082 plane->id = PLANE_SPRITE0 + sprite;
3083 plane->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, plane->id);
3085 possible_crtcs = BIT(pipe);
3087 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
3088 possible_crtcs, plane_funcs,
3089 formats, num_formats, modifiers,
3090 DRM_PLANE_TYPE_OVERLAY,
3091 "sprite %c", sprite_name(pipe, sprite));
3095 drm_plane_create_rotation_property(&plane->base,
3097 supported_rotations);
3099 drm_plane_create_color_properties(&plane->base,
3100 BIT(DRM_COLOR_YCBCR_BT601) |
3101 BIT(DRM_COLOR_YCBCR_BT709),
3102 BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) |
3103 BIT(DRM_COLOR_YCBCR_FULL_RANGE),
3104 DRM_COLOR_YCBCR_BT709,
3105 DRM_COLOR_YCBCR_LIMITED_RANGE);
3108 drm_plane_create_zpos_immutable_property(&plane->base, zpos);
3110 drm_plane_helper_add(&plane->base, &intel_plane_helper_funcs);
3115 intel_plane_free(plane);
3117 return ERR_PTR(ret);