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
32 #include <drm/drm_atomic_helper.h>
33 #include <drm/drm_crtc.h>
34 #include <drm/drm_fourcc.h>
35 #include <drm/drm_rect.h>
36 #include <drm/drm_atomic.h>
37 #include <drm/drm_plane_helper.h>
38 #include "intel_drv.h"
39 #include "intel_frontbuffer.h"
40 #include <drm/i915_drm.h>
42 #include <drm/drm_color_mgmt.h>
44 int intel_usecs_to_scanlines(const struct drm_display_mode *adjusted_mode,
48 if (!adjusted_mode->crtc_htotal)
51 return DIV_ROUND_UP(usecs * adjusted_mode->crtc_clock,
52 1000 * adjusted_mode->crtc_htotal);
55 /* FIXME: We should instead only take spinlocks once for the entire update
56 * instead of once per mmio. */
57 #if IS_ENABLED(CONFIG_PROVE_LOCKING)
58 #define VBLANK_EVASION_TIME_US 250
60 #define VBLANK_EVASION_TIME_US 100
64 * intel_pipe_update_start() - start update of a set of display registers
65 * @new_crtc_state: the new crtc state
67 * Mark the start of an update to pipe registers that should be updated
68 * atomically regarding vblank. If the next vblank will happens within
69 * the next 100 us, this function waits until the vblank passes.
71 * After a successful call to this function, interrupts will be disabled
72 * until a subsequent call to intel_pipe_update_end(). That is done to
73 * avoid random delays.
75 void intel_pipe_update_start(const struct intel_crtc_state *new_crtc_state)
77 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
78 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
79 const struct drm_display_mode *adjusted_mode = &new_crtc_state->base.adjusted_mode;
80 long timeout = msecs_to_jiffies_timeout(1);
81 int scanline, min, max, vblank_start;
82 wait_queue_head_t *wq = drm_crtc_vblank_waitqueue(&crtc->base);
83 bool need_vlv_dsi_wa = (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
84 intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI);
88 vblank_start = adjusted_mode->crtc_vblank_start;
89 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
90 vblank_start = DIV_ROUND_UP(vblank_start, 2);
92 /* FIXME needs to be calibrated sensibly */
93 min = vblank_start - intel_usecs_to_scanlines(adjusted_mode,
94 VBLANK_EVASION_TIME_US);
95 max = vblank_start - 1;
97 if (min <= 0 || max <= 0)
100 if (WARN_ON(drm_crtc_vblank_get(&crtc->base)))
104 * Wait for psr to idle out after enabling the VBL interrupts
105 * VBL interrupts will start the PSR exit and prevent a PSR
108 if (intel_psr_wait_for_idle(new_crtc_state, &psr_status))
109 DRM_ERROR("PSR idle timed out 0x%x, atomic update may fail\n",
114 crtc->debug.min_vbl = min;
115 crtc->debug.max_vbl = max;
116 trace_i915_pipe_update_start(crtc);
120 * prepare_to_wait() has a memory barrier, which guarantees
121 * other CPUs can see the task state update by the time we
124 prepare_to_wait(wq, &wait, TASK_UNINTERRUPTIBLE);
126 scanline = intel_get_crtc_scanline(crtc);
127 if (scanline < min || scanline > max)
131 DRM_ERROR("Potential atomic update failure on pipe %c\n",
132 pipe_name(crtc->pipe));
138 timeout = schedule_timeout(timeout);
143 finish_wait(wq, &wait);
145 drm_crtc_vblank_put(&crtc->base);
148 * On VLV/CHV DSI the scanline counter would appear to
149 * increment approx. 1/3 of a scanline before start of vblank.
150 * The registers still get latched at start of vblank however.
151 * This means we must not write any registers on the first
152 * line of vblank (since not the whole line is actually in
153 * vblank). And unfortunately we can't use the interrupt to
154 * wait here since it will fire too soon. We could use the
155 * frame start interrupt instead since it will fire after the
156 * critical scanline, but that would require more changes
157 * in the interrupt code. So for now we'll just do the nasty
158 * thing and poll for the bad scanline to pass us by.
160 * FIXME figure out if BXT+ DSI suffers from this as well
162 while (need_vlv_dsi_wa && scanline == vblank_start)
163 scanline = intel_get_crtc_scanline(crtc);
165 crtc->debug.scanline_start = scanline;
166 crtc->debug.start_vbl_time = ktime_get();
167 crtc->debug.start_vbl_count = intel_crtc_get_vblank_counter(crtc);
169 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);
233 int intel_plane_check_stride(const struct intel_plane_state *plane_state)
235 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
236 const struct drm_framebuffer *fb = plane_state->base.fb;
237 unsigned int rotation = plane_state->base.rotation;
238 u32 stride, max_stride;
240 /* FIXME other color planes? */
241 stride = plane_state->color_plane[0].stride;
242 max_stride = plane->max_stride(plane, fb->format->format,
243 fb->modifier, rotation);
245 if (stride > max_stride) {
246 DRM_DEBUG_KMS("[FB:%d] stride (%d) exceeds [PLANE:%d:%s] max stride (%d)\n",
248 plane->base.base.id, plane->base.name, max_stride);
255 int intel_plane_check_src_coordinates(struct intel_plane_state *plane_state)
257 const struct drm_framebuffer *fb = plane_state->base.fb;
258 struct drm_rect *src = &plane_state->base.src;
259 u32 src_x, src_y, src_w, src_h;
262 * Hardware doesn't handle subpixel coordinates.
263 * Adjust to (macro)pixel boundary, but be careful not to
264 * increase the source viewport size, because that could
265 * push the downscaling factor out of bounds.
267 src_x = src->x1 >> 16;
268 src_w = drm_rect_width(src) >> 16;
269 src_y = src->y1 >> 16;
270 src_h = drm_rect_height(src) >> 16;
272 src->x1 = src_x << 16;
273 src->x2 = (src_x + src_w) << 16;
274 src->y1 = src_y << 16;
275 src->y2 = (src_y + src_h) << 16;
277 if (fb->format->is_yuv &&
278 (src_x & 1 || src_w & 1)) {
279 DRM_DEBUG_KMS("src x/w (%u, %u) must be a multiple of 2 for YUV planes\n",
284 if (fb->format->is_yuv &&
285 fb->format->num_planes > 1 &&
286 (src_y & 1 || src_h & 1)) {
287 DRM_DEBUG_KMS("src y/h (%u, %u) must be a multiple of 2 for planar YUV planes\n",
296 skl_plane_max_stride(struct intel_plane *plane,
297 u32 pixel_format, u64 modifier,
298 unsigned int rotation)
300 int cpp = drm_format_plane_cpp(pixel_format, 0);
303 * "The stride in bytes must not exceed the
304 * of the size of 8K pixels and 32K bytes."
306 if (drm_rotation_90_or_270(rotation))
307 return min(8192, 32768 / cpp);
309 return min(8192 * cpp, 32768);
313 skl_program_scaler(struct intel_plane *plane,
314 const struct intel_crtc_state *crtc_state,
315 const struct intel_plane_state *plane_state)
317 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
318 enum pipe pipe = plane->pipe;
319 int scaler_id = plane_state->scaler_id;
320 const struct intel_scaler *scaler =
321 &crtc_state->scaler_state.scalers[scaler_id];
322 int crtc_x = plane_state->base.dst.x1;
323 int crtc_y = plane_state->base.dst.y1;
324 u32 crtc_w = drm_rect_width(&plane_state->base.dst);
325 u32 crtc_h = drm_rect_height(&plane_state->base.dst);
326 u16 y_hphase, uv_rgb_hphase;
327 u16 y_vphase, uv_rgb_vphase;
330 hscale = drm_rect_calc_hscale(&plane_state->base.src,
331 &plane_state->base.dst,
333 vscale = drm_rect_calc_vscale(&plane_state->base.src,
334 &plane_state->base.dst,
337 /* TODO: handle sub-pixel coordinates */
338 if (plane_state->base.fb->format->format == DRM_FORMAT_NV12 &&
339 !icl_is_hdr_plane(plane)) {
340 y_hphase = skl_scaler_calc_phase(1, hscale, false);
341 y_vphase = skl_scaler_calc_phase(1, vscale, false);
343 /* MPEG2 chroma siting convention */
344 uv_rgb_hphase = skl_scaler_calc_phase(2, hscale, true);
345 uv_rgb_vphase = skl_scaler_calc_phase(2, vscale, false);
351 uv_rgb_hphase = skl_scaler_calc_phase(1, hscale, false);
352 uv_rgb_vphase = skl_scaler_calc_phase(1, vscale, false);
355 I915_WRITE_FW(SKL_PS_CTRL(pipe, scaler_id),
356 PS_SCALER_EN | PS_PLANE_SEL(plane->id) | scaler->mode);
357 I915_WRITE_FW(SKL_PS_VPHASE(pipe, scaler_id),
358 PS_Y_PHASE(y_vphase) | PS_UV_RGB_PHASE(uv_rgb_vphase));
359 I915_WRITE_FW(SKL_PS_HPHASE(pipe, scaler_id),
360 PS_Y_PHASE(y_hphase) | PS_UV_RGB_PHASE(uv_rgb_hphase));
361 I915_WRITE_FW(SKL_PS_WIN_POS(pipe, scaler_id), (crtc_x << 16) | crtc_y);
362 I915_WRITE_FW(SKL_PS_WIN_SZ(pipe, scaler_id), (crtc_w << 16) | crtc_h);
365 /* Preoffset values for YUV to RGB Conversion */
366 #define PREOFF_YUV_TO_RGB_HI 0x1800
367 #define PREOFF_YUV_TO_RGB_ME 0x1F00
368 #define PREOFF_YUV_TO_RGB_LO 0x1800
370 #define ROFF(x) (((x) & 0xffff) << 16)
371 #define GOFF(x) (((x) & 0xffff) << 0)
372 #define BOFF(x) (((x) & 0xffff) << 16)
375 icl_program_input_csc(struct intel_plane *plane,
376 const struct intel_crtc_state *crtc_state,
377 const struct intel_plane_state *plane_state)
379 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
380 enum pipe pipe = plane->pipe;
381 enum plane_id plane_id = plane->id;
383 static const u16 input_csc_matrix[][9] = {
385 * BT.601 full range YCbCr -> full range RGB
386 * The matrix required is :
387 * [1.000, 0.000, 1.371,
388 * 1.000, -0.336, -0.698,
389 * 1.000, 1.732, 0.0000]
391 [DRM_COLOR_YCBCR_BT601] = {
393 0x8B28, 0x7800, 0x9AC0,
397 * BT.709 full range YCbCr -> full range RGB
398 * The matrix required is :
399 * [1.000, 0.000, 1.574,
400 * 1.000, -0.187, -0.468,
401 * 1.000, 1.855, 0.0000]
403 [DRM_COLOR_YCBCR_BT709] = {
405 0x9EF8, 0x7800, 0xABF8,
410 /* Matrix for Limited Range to Full Range Conversion */
411 static const u16 input_csc_matrix_lr[][9] = {
413 * BT.601 Limted range YCbCr -> full range RGB
414 * The matrix required is :
415 * [1.164384, 0.000, 1.596370,
416 * 1.138393, -0.382500, -0.794598,
417 * 1.138393, 1.971696, 0.0000]
419 [DRM_COLOR_YCBCR_BT601] = {
421 0x8CB8, 0x7918, 0x9C40,
425 * BT.709 Limited range YCbCr -> full range RGB
426 * The matrix required is :
427 * [1.164, 0.000, 1.833671,
428 * 1.138393, -0.213249, -0.532909,
429 * 1.138393, 2.112402, 0.0000]
431 [DRM_COLOR_YCBCR_BT709] = {
433 0x8888, 0x7918, 0xADA8,
439 if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
440 csc = input_csc_matrix[plane_state->base.color_encoding];
442 csc = input_csc_matrix_lr[plane_state->base.color_encoding];
444 I915_WRITE_FW(PLANE_INPUT_CSC_COEFF(pipe, plane_id, 0), ROFF(csc[0]) |
446 I915_WRITE_FW(PLANE_INPUT_CSC_COEFF(pipe, plane_id, 1), BOFF(csc[2]));
447 I915_WRITE_FW(PLANE_INPUT_CSC_COEFF(pipe, plane_id, 2), ROFF(csc[3]) |
449 I915_WRITE_FW(PLANE_INPUT_CSC_COEFF(pipe, plane_id, 3), BOFF(csc[5]));
450 I915_WRITE_FW(PLANE_INPUT_CSC_COEFF(pipe, plane_id, 4), ROFF(csc[6]) |
452 I915_WRITE_FW(PLANE_INPUT_CSC_COEFF(pipe, plane_id, 5), BOFF(csc[8]));
454 I915_WRITE_FW(PLANE_INPUT_CSC_PREOFF(pipe, plane_id, 0),
455 PREOFF_YUV_TO_RGB_HI);
456 I915_WRITE_FW(PLANE_INPUT_CSC_PREOFF(pipe, plane_id, 1),
457 PREOFF_YUV_TO_RGB_ME);
458 I915_WRITE_FW(PLANE_INPUT_CSC_PREOFF(pipe, plane_id, 2),
459 PREOFF_YUV_TO_RGB_LO);
460 I915_WRITE_FW(PLANE_INPUT_CSC_POSTOFF(pipe, plane_id, 0), 0x0);
461 I915_WRITE_FW(PLANE_INPUT_CSC_POSTOFF(pipe, plane_id, 1), 0x0);
462 I915_WRITE_FW(PLANE_INPUT_CSC_POSTOFF(pipe, plane_id, 2), 0x0);
466 skl_program_plane(struct intel_plane *plane,
467 const struct intel_crtc_state *crtc_state,
468 const struct intel_plane_state *plane_state,
469 int color_plane, bool slave, u32 plane_ctl)
471 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
472 enum plane_id plane_id = plane->id;
473 enum pipe pipe = plane->pipe;
474 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
475 u32 surf_addr = plane_state->color_plane[color_plane].offset;
476 u32 stride = skl_plane_stride(plane_state, color_plane);
477 u32 aux_stride = skl_plane_stride(plane_state, 1);
478 int crtc_x = plane_state->base.dst.x1;
479 int crtc_y = plane_state->base.dst.y1;
480 u32 x = plane_state->color_plane[color_plane].x;
481 u32 y = plane_state->color_plane[color_plane].y;
482 u32 src_w = drm_rect_width(&plane_state->base.src) >> 16;
483 u32 src_h = drm_rect_height(&plane_state->base.src) >> 16;
484 struct intel_plane *linked = plane_state->linked_plane;
485 const struct drm_framebuffer *fb = plane_state->base.fb;
486 u8 alpha = plane_state->base.alpha >> 8;
487 unsigned long irqflags;
490 /* Sizes are 0 based */
494 keymax = (key->max_value & 0xffffff) | PLANE_KEYMAX_ALPHA(alpha);
496 keymsk = key->channel_mask & 0x3ffffff;
498 keymsk |= PLANE_KEYMSK_ALPHA_ENABLE;
500 /* The scaler will handle the output position */
501 if (plane_state->scaler_id >= 0) {
506 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
508 I915_WRITE_FW(PLANE_STRIDE(pipe, plane_id), stride);
509 I915_WRITE_FW(PLANE_POS(pipe, plane_id), (crtc_y << 16) | crtc_x);
510 I915_WRITE_FW(PLANE_SIZE(pipe, plane_id), (src_h << 16) | src_w);
511 I915_WRITE_FW(PLANE_AUX_DIST(pipe, plane_id),
512 (plane_state->color_plane[1].offset - surf_addr) | aux_stride);
514 if (icl_is_hdr_plane(plane)) {
518 /* Enable and use MPEG-2 chroma siting */
519 cus_ctl = PLANE_CUS_ENABLE |
521 PLANE_CUS_VPHASE_SIGN_NEGATIVE |
522 PLANE_CUS_VPHASE_0_25;
524 if (linked->id == PLANE_SPRITE5)
525 cus_ctl |= PLANE_CUS_PLANE_7;
526 else if (linked->id == PLANE_SPRITE4)
527 cus_ctl |= PLANE_CUS_PLANE_6;
529 MISSING_CASE(linked->id);
532 I915_WRITE_FW(PLANE_CUS_CTL(pipe, plane_id), cus_ctl);
535 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
536 I915_WRITE_FW(PLANE_COLOR_CTL(pipe, plane_id),
537 plane_state->color_ctl);
539 if (fb->format->is_yuv && icl_is_hdr_plane(plane))
540 icl_program_input_csc(plane, crtc_state, plane_state);
542 skl_write_plane_wm(plane, crtc_state);
544 I915_WRITE_FW(PLANE_KEYVAL(pipe, plane_id), key->min_value);
545 I915_WRITE_FW(PLANE_KEYMSK(pipe, plane_id), keymsk);
546 I915_WRITE_FW(PLANE_KEYMAX(pipe, plane_id), keymax);
548 I915_WRITE_FW(PLANE_OFFSET(pipe, plane_id), (y << 16) | x);
550 if (INTEL_GEN(dev_priv) < 11)
551 I915_WRITE_FW(PLANE_AUX_OFFSET(pipe, plane_id),
552 (plane_state->color_plane[1].y << 16) |
553 plane_state->color_plane[1].x);
556 * The control register self-arms if the plane was previously
557 * disabled. Try to make the plane enable atomic by writing
558 * the control register just before the surface register.
560 I915_WRITE_FW(PLANE_CTL(pipe, plane_id), plane_ctl);
561 I915_WRITE_FW(PLANE_SURF(pipe, plane_id),
562 intel_plane_ggtt_offset(plane_state) + surf_addr);
564 if (!slave && plane_state->scaler_id >= 0)
565 skl_program_scaler(plane, crtc_state, plane_state);
567 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
571 skl_update_plane(struct intel_plane *plane,
572 const struct intel_crtc_state *crtc_state,
573 const struct intel_plane_state *plane_state)
577 if (plane_state->linked_plane) {
578 /* Program the UV plane */
582 skl_program_plane(plane, crtc_state, plane_state,
583 color_plane, false, plane_state->ctl);
587 icl_update_slave(struct intel_plane *plane,
588 const struct intel_crtc_state *crtc_state,
589 const struct intel_plane_state *plane_state)
591 skl_program_plane(plane, crtc_state, plane_state, 0, true,
592 plane_state->ctl | PLANE_CTL_YUV420_Y_PLANE);
596 skl_disable_plane(struct intel_plane *plane,
597 const struct intel_crtc_state *crtc_state)
599 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
600 enum plane_id plane_id = plane->id;
601 enum pipe pipe = plane->pipe;
602 unsigned long irqflags;
604 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
606 skl_write_plane_wm(plane, crtc_state);
608 I915_WRITE_FW(PLANE_CTL(pipe, plane_id), 0);
609 I915_WRITE_FW(PLANE_SURF(pipe, plane_id), 0);
611 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
615 skl_plane_get_hw_state(struct intel_plane *plane,
618 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
619 enum intel_display_power_domain power_domain;
620 enum plane_id plane_id = plane->id;
621 intel_wakeref_t wakeref;
624 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
625 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
629 ret = I915_READ(PLANE_CTL(plane->pipe, plane_id)) & PLANE_CTL_ENABLE;
633 intel_display_power_put(dev_priv, power_domain, wakeref);
639 chv_update_csc(const struct intel_plane_state *plane_state)
641 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
642 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
643 const struct drm_framebuffer *fb = plane_state->base.fb;
644 enum plane_id plane_id = plane->id;
646 * |r| | c0 c1 c2 | |cr|
647 * |g| = | c3 c4 c5 | x |y |
648 * |b| | c6 c7 c8 | |cb|
650 * Coefficients are s3.12.
652 * Cb and Cr apparently come in as signed already, and
653 * we always get full range data in on account of CLRC0/1.
655 static const s16 csc_matrix[][9] = {
656 /* BT.601 full range YCbCr -> full range RGB */
657 [DRM_COLOR_YCBCR_BT601] = {
662 /* BT.709 full range YCbCr -> full range RGB */
663 [DRM_COLOR_YCBCR_BT709] = {
669 const s16 *csc = csc_matrix[plane_state->base.color_encoding];
671 /* Seems RGB data bypasses the CSC always */
672 if (!fb->format->is_yuv)
675 I915_WRITE_FW(SPCSCYGOFF(plane_id), SPCSC_OOFF(0) | SPCSC_IOFF(0));
676 I915_WRITE_FW(SPCSCCBOFF(plane_id), SPCSC_OOFF(0) | SPCSC_IOFF(0));
677 I915_WRITE_FW(SPCSCCROFF(plane_id), SPCSC_OOFF(0) | SPCSC_IOFF(0));
679 I915_WRITE_FW(SPCSCC01(plane_id), SPCSC_C1(csc[1]) | SPCSC_C0(csc[0]));
680 I915_WRITE_FW(SPCSCC23(plane_id), SPCSC_C1(csc[3]) | SPCSC_C0(csc[2]));
681 I915_WRITE_FW(SPCSCC45(plane_id), SPCSC_C1(csc[5]) | SPCSC_C0(csc[4]));
682 I915_WRITE_FW(SPCSCC67(plane_id), SPCSC_C1(csc[7]) | SPCSC_C0(csc[6]));
683 I915_WRITE_FW(SPCSCC8(plane_id), SPCSC_C0(csc[8]));
685 I915_WRITE_FW(SPCSCYGICLAMP(plane_id), SPCSC_IMAX(1023) | SPCSC_IMIN(0));
686 I915_WRITE_FW(SPCSCCBICLAMP(plane_id), SPCSC_IMAX(512) | SPCSC_IMIN(-512));
687 I915_WRITE_FW(SPCSCCRICLAMP(plane_id), SPCSC_IMAX(512) | SPCSC_IMIN(-512));
689 I915_WRITE_FW(SPCSCYGOCLAMP(plane_id), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
690 I915_WRITE_FW(SPCSCCBOCLAMP(plane_id), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
691 I915_WRITE_FW(SPCSCCROCLAMP(plane_id), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
698 vlv_update_clrc(const struct intel_plane_state *plane_state)
700 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
701 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
702 const struct drm_framebuffer *fb = plane_state->base.fb;
703 enum pipe pipe = plane->pipe;
704 enum plane_id plane_id = plane->id;
705 int contrast, brightness, sh_scale, sh_sin, sh_cos;
707 if (fb->format->is_yuv &&
708 plane_state->base.color_range == DRM_COLOR_YCBCR_LIMITED_RANGE) {
710 * Expand limited range to full range:
711 * Contrast is applied first and is used to expand Y range.
712 * Brightness is applied second and is used to remove the
713 * offset from Y. Saturation/hue is used to expand CbCr range.
715 contrast = DIV_ROUND_CLOSEST(255 << 6, 235 - 16);
716 brightness = -DIV_ROUND_CLOSEST(16 * 255, 235 - 16);
717 sh_scale = DIV_ROUND_CLOSEST(128 << 7, 240 - 128);
718 sh_sin = SIN_0 * sh_scale;
719 sh_cos = COS_0 * sh_scale;
721 /* Pass-through everything. */
725 sh_sin = SIN_0 * sh_scale;
726 sh_cos = COS_0 * sh_scale;
729 /* FIXME these register are single buffered :( */
730 I915_WRITE_FW(SPCLRC0(pipe, plane_id),
731 SP_CONTRAST(contrast) | SP_BRIGHTNESS(brightness));
732 I915_WRITE_FW(SPCLRC1(pipe, plane_id),
733 SP_SH_SIN(sh_sin) | SP_SH_COS(sh_cos));
736 static u32 vlv_sprite_ctl(const struct intel_crtc_state *crtc_state,
737 const struct intel_plane_state *plane_state)
739 const struct drm_framebuffer *fb = plane_state->base.fb;
740 unsigned int rotation = plane_state->base.rotation;
741 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
744 sprctl = SP_ENABLE | SP_GAMMA_ENABLE;
746 switch (fb->format->format) {
747 case DRM_FORMAT_YUYV:
748 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YUYV;
750 case DRM_FORMAT_YVYU:
751 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YVYU;
753 case DRM_FORMAT_UYVY:
754 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_UYVY;
756 case DRM_FORMAT_VYUY:
757 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_VYUY;
759 case DRM_FORMAT_RGB565:
760 sprctl |= SP_FORMAT_BGR565;
762 case DRM_FORMAT_XRGB8888:
763 sprctl |= SP_FORMAT_BGRX8888;
765 case DRM_FORMAT_ARGB8888:
766 sprctl |= SP_FORMAT_BGRA8888;
768 case DRM_FORMAT_XBGR2101010:
769 sprctl |= SP_FORMAT_RGBX1010102;
771 case DRM_FORMAT_ABGR2101010:
772 sprctl |= SP_FORMAT_RGBA1010102;
774 case DRM_FORMAT_XBGR8888:
775 sprctl |= SP_FORMAT_RGBX8888;
777 case DRM_FORMAT_ABGR8888:
778 sprctl |= SP_FORMAT_RGBA8888;
781 MISSING_CASE(fb->format->format);
785 if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
786 sprctl |= SP_YUV_FORMAT_BT709;
788 if (fb->modifier == I915_FORMAT_MOD_X_TILED)
791 if (rotation & DRM_MODE_ROTATE_180)
792 sprctl |= SP_ROTATE_180;
794 if (rotation & DRM_MODE_REFLECT_X)
797 if (key->flags & I915_SET_COLORKEY_SOURCE)
798 sprctl |= SP_SOURCE_KEY;
804 vlv_update_plane(struct intel_plane *plane,
805 const struct intel_crtc_state *crtc_state,
806 const struct intel_plane_state *plane_state)
808 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
809 enum pipe pipe = plane->pipe;
810 enum plane_id plane_id = plane->id;
811 u32 sprctl = plane_state->ctl;
812 u32 sprsurf_offset = plane_state->color_plane[0].offset;
814 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
815 int crtc_x = plane_state->base.dst.x1;
816 int crtc_y = plane_state->base.dst.y1;
817 u32 crtc_w = drm_rect_width(&plane_state->base.dst);
818 u32 crtc_h = drm_rect_height(&plane_state->base.dst);
819 u32 x = plane_state->color_plane[0].x;
820 u32 y = plane_state->color_plane[0].y;
821 unsigned long irqflags;
823 /* Sizes are 0 based */
827 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
829 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
831 I915_WRITE_FW(SPSTRIDE(pipe, plane_id),
832 plane_state->color_plane[0].stride);
833 I915_WRITE_FW(SPPOS(pipe, plane_id), (crtc_y << 16) | crtc_x);
834 I915_WRITE_FW(SPSIZE(pipe, plane_id), (crtc_h << 16) | crtc_w);
835 I915_WRITE_FW(SPCONSTALPHA(pipe, plane_id), 0);
837 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B)
838 chv_update_csc(plane_state);
841 I915_WRITE_FW(SPKEYMINVAL(pipe, plane_id), key->min_value);
842 I915_WRITE_FW(SPKEYMSK(pipe, plane_id), key->channel_mask);
843 I915_WRITE_FW(SPKEYMAXVAL(pipe, plane_id), key->max_value);
846 I915_WRITE_FW(SPLINOFF(pipe, plane_id), linear_offset);
847 I915_WRITE_FW(SPTILEOFF(pipe, plane_id), (y << 16) | x);
850 * The control register self-arms if the plane was previously
851 * disabled. Try to make the plane enable atomic by writing
852 * the control register just before the surface register.
854 I915_WRITE_FW(SPCNTR(pipe, plane_id), sprctl);
855 I915_WRITE_FW(SPSURF(pipe, plane_id),
856 intel_plane_ggtt_offset(plane_state) + sprsurf_offset);
858 vlv_update_clrc(plane_state);
860 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
864 vlv_disable_plane(struct intel_plane *plane,
865 const struct intel_crtc_state *crtc_state)
867 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
868 enum pipe pipe = plane->pipe;
869 enum plane_id plane_id = plane->id;
870 unsigned long irqflags;
872 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
874 I915_WRITE_FW(SPCNTR(pipe, plane_id), 0);
875 I915_WRITE_FW(SPSURF(pipe, plane_id), 0);
877 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
881 vlv_plane_get_hw_state(struct intel_plane *plane,
884 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
885 enum intel_display_power_domain power_domain;
886 enum plane_id plane_id = plane->id;
887 intel_wakeref_t wakeref;
890 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
891 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
895 ret = I915_READ(SPCNTR(plane->pipe, plane_id)) & SP_ENABLE;
899 intel_display_power_put(dev_priv, power_domain, wakeref);
904 static u32 ivb_sprite_ctl(const struct intel_crtc_state *crtc_state,
905 const struct intel_plane_state *plane_state)
907 struct drm_i915_private *dev_priv =
908 to_i915(plane_state->base.plane->dev);
909 const struct drm_framebuffer *fb = plane_state->base.fb;
910 unsigned int rotation = plane_state->base.rotation;
911 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
914 sprctl = SPRITE_ENABLE | SPRITE_GAMMA_ENABLE;
916 if (IS_IVYBRIDGE(dev_priv))
917 sprctl |= SPRITE_TRICKLE_FEED_DISABLE;
919 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
920 sprctl |= SPRITE_PIPE_CSC_ENABLE;
922 switch (fb->format->format) {
923 case DRM_FORMAT_XBGR8888:
924 sprctl |= SPRITE_FORMAT_RGBX888 | SPRITE_RGB_ORDER_RGBX;
926 case DRM_FORMAT_XRGB8888:
927 sprctl |= SPRITE_FORMAT_RGBX888;
929 case DRM_FORMAT_YUYV:
930 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YUYV;
932 case DRM_FORMAT_YVYU:
933 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YVYU;
935 case DRM_FORMAT_UYVY:
936 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_UYVY;
938 case DRM_FORMAT_VYUY:
939 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_VYUY;
942 MISSING_CASE(fb->format->format);
946 if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
947 sprctl |= SPRITE_YUV_TO_RGB_CSC_FORMAT_BT709;
949 if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
950 sprctl |= SPRITE_YUV_RANGE_CORRECTION_DISABLE;
952 if (fb->modifier == I915_FORMAT_MOD_X_TILED)
953 sprctl |= SPRITE_TILED;
955 if (rotation & DRM_MODE_ROTATE_180)
956 sprctl |= SPRITE_ROTATE_180;
958 if (key->flags & I915_SET_COLORKEY_DESTINATION)
959 sprctl |= SPRITE_DEST_KEY;
960 else if (key->flags & I915_SET_COLORKEY_SOURCE)
961 sprctl |= SPRITE_SOURCE_KEY;
967 ivb_update_plane(struct intel_plane *plane,
968 const struct intel_crtc_state *crtc_state,
969 const struct intel_plane_state *plane_state)
971 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
972 enum pipe pipe = plane->pipe;
973 u32 sprctl = plane_state->ctl, sprscale = 0;
974 u32 sprsurf_offset = plane_state->color_plane[0].offset;
976 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
977 int crtc_x = plane_state->base.dst.x1;
978 int crtc_y = plane_state->base.dst.y1;
979 u32 crtc_w = drm_rect_width(&plane_state->base.dst);
980 u32 crtc_h = drm_rect_height(&plane_state->base.dst);
981 u32 x = plane_state->color_plane[0].x;
982 u32 y = plane_state->color_plane[0].y;
983 u32 src_w = drm_rect_width(&plane_state->base.src) >> 16;
984 u32 src_h = drm_rect_height(&plane_state->base.src) >> 16;
985 unsigned long irqflags;
987 /* Sizes are 0 based */
993 if (crtc_w != src_w || crtc_h != src_h)
994 sprscale = SPRITE_SCALE_ENABLE | (src_w << 16) | src_h;
996 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
998 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
1000 I915_WRITE_FW(SPRSTRIDE(pipe), plane_state->color_plane[0].stride);
1001 I915_WRITE_FW(SPRPOS(pipe), (crtc_y << 16) | crtc_x);
1002 I915_WRITE_FW(SPRSIZE(pipe), (crtc_h << 16) | crtc_w);
1003 if (IS_IVYBRIDGE(dev_priv))
1004 I915_WRITE_FW(SPRSCALE(pipe), sprscale);
1007 I915_WRITE_FW(SPRKEYVAL(pipe), key->min_value);
1008 I915_WRITE_FW(SPRKEYMSK(pipe), key->channel_mask);
1009 I915_WRITE_FW(SPRKEYMAX(pipe), key->max_value);
1012 /* HSW consolidates SPRTILEOFF and SPRLINOFF into a single SPROFFSET
1014 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
1015 I915_WRITE_FW(SPROFFSET(pipe), (y << 16) | x);
1017 I915_WRITE_FW(SPRLINOFF(pipe), linear_offset);
1018 I915_WRITE_FW(SPRTILEOFF(pipe), (y << 16) | x);
1022 * The control register self-arms if the plane was previously
1023 * disabled. Try to make the plane enable atomic by writing
1024 * the control register just before the surface register.
1026 I915_WRITE_FW(SPRCTL(pipe), sprctl);
1027 I915_WRITE_FW(SPRSURF(pipe),
1028 intel_plane_ggtt_offset(plane_state) + sprsurf_offset);
1030 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1034 ivb_disable_plane(struct intel_plane *plane,
1035 const struct intel_crtc_state *crtc_state)
1037 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1038 enum pipe pipe = plane->pipe;
1039 unsigned long irqflags;
1041 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
1043 I915_WRITE_FW(SPRCTL(pipe), 0);
1044 /* Disable the scaler */
1045 if (IS_IVYBRIDGE(dev_priv))
1046 I915_WRITE_FW(SPRSCALE(pipe), 0);
1047 I915_WRITE_FW(SPRSURF(pipe), 0);
1049 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1053 ivb_plane_get_hw_state(struct intel_plane *plane,
1056 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1057 enum intel_display_power_domain power_domain;
1058 intel_wakeref_t wakeref;
1061 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
1062 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
1066 ret = I915_READ(SPRCTL(plane->pipe)) & SPRITE_ENABLE;
1068 *pipe = plane->pipe;
1070 intel_display_power_put(dev_priv, power_domain, wakeref);
1076 g4x_sprite_max_stride(struct intel_plane *plane,
1077 u32 pixel_format, u64 modifier,
1078 unsigned int rotation)
1083 static u32 g4x_sprite_ctl(const struct intel_crtc_state *crtc_state,
1084 const struct intel_plane_state *plane_state)
1086 struct drm_i915_private *dev_priv =
1087 to_i915(plane_state->base.plane->dev);
1088 const struct drm_framebuffer *fb = plane_state->base.fb;
1089 unsigned int rotation = plane_state->base.rotation;
1090 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
1093 dvscntr = DVS_ENABLE | DVS_GAMMA_ENABLE;
1095 if (IS_GEN(dev_priv, 6))
1096 dvscntr |= DVS_TRICKLE_FEED_DISABLE;
1098 switch (fb->format->format) {
1099 case DRM_FORMAT_XBGR8888:
1100 dvscntr |= DVS_FORMAT_RGBX888 | DVS_RGB_ORDER_XBGR;
1102 case DRM_FORMAT_XRGB8888:
1103 dvscntr |= DVS_FORMAT_RGBX888;
1105 case DRM_FORMAT_YUYV:
1106 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YUYV;
1108 case DRM_FORMAT_YVYU:
1109 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YVYU;
1111 case DRM_FORMAT_UYVY:
1112 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_UYVY;
1114 case DRM_FORMAT_VYUY:
1115 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_VYUY;
1118 MISSING_CASE(fb->format->format);
1122 if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
1123 dvscntr |= DVS_YUV_FORMAT_BT709;
1125 if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
1126 dvscntr |= DVS_YUV_RANGE_CORRECTION_DISABLE;
1128 if (fb->modifier == I915_FORMAT_MOD_X_TILED)
1129 dvscntr |= DVS_TILED;
1131 if (rotation & DRM_MODE_ROTATE_180)
1132 dvscntr |= DVS_ROTATE_180;
1134 if (key->flags & I915_SET_COLORKEY_DESTINATION)
1135 dvscntr |= DVS_DEST_KEY;
1136 else if (key->flags & I915_SET_COLORKEY_SOURCE)
1137 dvscntr |= DVS_SOURCE_KEY;
1143 g4x_update_plane(struct intel_plane *plane,
1144 const struct intel_crtc_state *crtc_state,
1145 const struct intel_plane_state *plane_state)
1147 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1148 enum pipe pipe = plane->pipe;
1149 u32 dvscntr = plane_state->ctl, dvsscale = 0;
1150 u32 dvssurf_offset = plane_state->color_plane[0].offset;
1152 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
1153 int crtc_x = plane_state->base.dst.x1;
1154 int crtc_y = plane_state->base.dst.y1;
1155 u32 crtc_w = drm_rect_width(&plane_state->base.dst);
1156 u32 crtc_h = drm_rect_height(&plane_state->base.dst);
1157 u32 x = plane_state->color_plane[0].x;
1158 u32 y = plane_state->color_plane[0].y;
1159 u32 src_w = drm_rect_width(&plane_state->base.src) >> 16;
1160 u32 src_h = drm_rect_height(&plane_state->base.src) >> 16;
1161 unsigned long irqflags;
1163 /* Sizes are 0 based */
1169 if (crtc_w != src_w || crtc_h != src_h)
1170 dvsscale = DVS_SCALE_ENABLE | (src_w << 16) | src_h;
1172 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
1174 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
1176 I915_WRITE_FW(DVSSTRIDE(pipe), plane_state->color_plane[0].stride);
1177 I915_WRITE_FW(DVSPOS(pipe), (crtc_y << 16) | crtc_x);
1178 I915_WRITE_FW(DVSSIZE(pipe), (crtc_h << 16) | crtc_w);
1179 I915_WRITE_FW(DVSSCALE(pipe), dvsscale);
1182 I915_WRITE_FW(DVSKEYVAL(pipe), key->min_value);
1183 I915_WRITE_FW(DVSKEYMSK(pipe), key->channel_mask);
1184 I915_WRITE_FW(DVSKEYMAX(pipe), key->max_value);
1187 I915_WRITE_FW(DVSLINOFF(pipe), linear_offset);
1188 I915_WRITE_FW(DVSTILEOFF(pipe), (y << 16) | x);
1191 * The control register self-arms if the plane was previously
1192 * disabled. Try to make the plane enable atomic by writing
1193 * the control register just before the surface register.
1195 I915_WRITE_FW(DVSCNTR(pipe), dvscntr);
1196 I915_WRITE_FW(DVSSURF(pipe),
1197 intel_plane_ggtt_offset(plane_state) + dvssurf_offset);
1199 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1203 g4x_disable_plane(struct intel_plane *plane,
1204 const struct intel_crtc_state *crtc_state)
1206 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1207 enum pipe pipe = plane->pipe;
1208 unsigned long irqflags;
1210 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
1212 I915_WRITE_FW(DVSCNTR(pipe), 0);
1213 /* Disable the scaler */
1214 I915_WRITE_FW(DVSSCALE(pipe), 0);
1215 I915_WRITE_FW(DVSSURF(pipe), 0);
1217 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1221 g4x_plane_get_hw_state(struct intel_plane *plane,
1224 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1225 enum intel_display_power_domain power_domain;
1226 intel_wakeref_t wakeref;
1229 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
1230 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
1234 ret = I915_READ(DVSCNTR(plane->pipe)) & DVS_ENABLE;
1236 *pipe = plane->pipe;
1238 intel_display_power_put(dev_priv, power_domain, wakeref);
1243 static bool intel_fb_scalable(const struct drm_framebuffer *fb)
1248 switch (fb->format->format) {
1257 g4x_sprite_check_scaling(struct intel_crtc_state *crtc_state,
1258 struct intel_plane_state *plane_state)
1260 const struct drm_framebuffer *fb = plane_state->base.fb;
1261 const struct drm_rect *src = &plane_state->base.src;
1262 const struct drm_rect *dst = &plane_state->base.dst;
1263 int src_x, src_y, src_w, src_h, crtc_w, crtc_h;
1264 const struct drm_display_mode *adjusted_mode =
1265 &crtc_state->base.adjusted_mode;
1266 unsigned int cpp = fb->format->cpp[0];
1267 unsigned int width_bytes;
1268 int min_width, min_height;
1270 crtc_w = drm_rect_width(dst);
1271 crtc_h = drm_rect_height(dst);
1273 src_x = src->x1 >> 16;
1274 src_y = src->y1 >> 16;
1275 src_w = drm_rect_width(src) >> 16;
1276 src_h = drm_rect_height(src) >> 16;
1278 if (src_w == crtc_w && src_h == crtc_h)
1283 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
1285 DRM_DEBUG_KMS("Source height must be even with interlaced modes\n");
1293 width_bytes = ((src_x * cpp) & 63) + src_w * cpp;
1295 if (src_w < min_width || src_h < min_height ||
1296 src_w > 2048 || src_h > 2048) {
1297 DRM_DEBUG_KMS("Source dimensions (%dx%d) exceed hardware limits (%dx%d - %dx%d)\n",
1298 src_w, src_h, min_width, min_height, 2048, 2048);
1302 if (width_bytes > 4096) {
1303 DRM_DEBUG_KMS("Fetch width (%d) exceeds hardware max with scaling (%u)\n",
1308 if (width_bytes > 4096 || fb->pitches[0] > 4096) {
1309 DRM_DEBUG_KMS("Stride (%u) exceeds hardware max with scaling (%u)\n",
1310 fb->pitches[0], 4096);
1318 g4x_sprite_check(struct intel_crtc_state *crtc_state,
1319 struct intel_plane_state *plane_state)
1321 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
1322 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1323 int min_scale = DRM_PLANE_HELPER_NO_SCALING;
1324 int max_scale = DRM_PLANE_HELPER_NO_SCALING;
1327 if (intel_fb_scalable(plane_state->base.fb)) {
1328 if (INTEL_GEN(dev_priv) < 7) {
1330 max_scale = 16 << 16;
1331 } else if (IS_IVYBRIDGE(dev_priv)) {
1333 max_scale = 2 << 16;
1337 ret = drm_atomic_helper_check_plane_state(&plane_state->base,
1339 min_scale, max_scale,
1344 if (!plane_state->base.visible)
1347 ret = intel_plane_check_src_coordinates(plane_state);
1351 ret = g4x_sprite_check_scaling(crtc_state, plane_state);
1355 ret = i9xx_check_plane_surface(plane_state);
1359 if (INTEL_GEN(dev_priv) >= 7)
1360 plane_state->ctl = ivb_sprite_ctl(crtc_state, plane_state);
1362 plane_state->ctl = g4x_sprite_ctl(crtc_state, plane_state);
1367 int chv_plane_check_rotation(const struct intel_plane_state *plane_state)
1369 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
1370 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1371 unsigned int rotation = plane_state->base.rotation;
1373 /* CHV ignores the mirror bit when the rotate bit is set :( */
1374 if (IS_CHERRYVIEW(dev_priv) &&
1375 rotation & DRM_MODE_ROTATE_180 &&
1376 rotation & DRM_MODE_REFLECT_X) {
1377 DRM_DEBUG_KMS("Cannot rotate and reflect at the same time\n");
1385 vlv_sprite_check(struct intel_crtc_state *crtc_state,
1386 struct intel_plane_state *plane_state)
1390 ret = chv_plane_check_rotation(plane_state);
1394 ret = drm_atomic_helper_check_plane_state(&plane_state->base,
1396 DRM_PLANE_HELPER_NO_SCALING,
1397 DRM_PLANE_HELPER_NO_SCALING,
1402 if (!plane_state->base.visible)
1405 ret = intel_plane_check_src_coordinates(plane_state);
1409 ret = i9xx_check_plane_surface(plane_state);
1413 plane_state->ctl = vlv_sprite_ctl(crtc_state, plane_state);
1418 static int skl_plane_check_fb(const struct intel_crtc_state *crtc_state,
1419 const struct intel_plane_state *plane_state)
1421 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
1422 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1423 const struct drm_framebuffer *fb = plane_state->base.fb;
1424 unsigned int rotation = plane_state->base.rotation;
1425 struct drm_format_name_buf format_name;
1430 if (rotation & ~(DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180) &&
1431 is_ccs_modifier(fb->modifier)) {
1432 DRM_DEBUG_KMS("RC support only with 0/180 degree rotation (%x)\n",
1437 if (rotation & DRM_MODE_REFLECT_X &&
1438 fb->modifier == DRM_FORMAT_MOD_LINEAR) {
1439 DRM_DEBUG_KMS("horizontal flip is not supported with linear surface formats\n");
1443 if (drm_rotation_90_or_270(rotation)) {
1444 if (fb->modifier != I915_FORMAT_MOD_Y_TILED &&
1445 fb->modifier != I915_FORMAT_MOD_Yf_TILED) {
1446 DRM_DEBUG_KMS("Y/Yf tiling required for 90/270!\n");
1451 * 90/270 is not allowed with RGB64 16:16:16:16 and
1452 * Indexed 8-bit. RGB 16-bit 5:6:5 is allowed gen11 onwards.
1453 * TBD: Add RGB64 case once its added in supported format
1456 switch (fb->format->format) {
1457 case DRM_FORMAT_RGB565:
1458 if (INTEL_GEN(dev_priv) >= 11)
1462 DRM_DEBUG_KMS("Unsupported pixel format %s for 90/270!\n",
1463 drm_get_format_name(fb->format->format,
1471 /* Y-tiling is not supported in IF-ID Interlace mode */
1472 if (crtc_state->base.enable &&
1473 crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE &&
1474 (fb->modifier == I915_FORMAT_MOD_Y_TILED ||
1475 fb->modifier == I915_FORMAT_MOD_Yf_TILED ||
1476 fb->modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
1477 fb->modifier == I915_FORMAT_MOD_Yf_TILED_CCS)) {
1478 DRM_DEBUG_KMS("Y/Yf tiling not supported in IF-ID mode\n");
1485 static int skl_plane_check_dst_coordinates(const struct intel_crtc_state *crtc_state,
1486 const struct intel_plane_state *plane_state)
1488 struct drm_i915_private *dev_priv =
1489 to_i915(plane_state->base.plane->dev);
1490 int crtc_x = plane_state->base.dst.x1;
1491 int crtc_w = drm_rect_width(&plane_state->base.dst);
1492 int pipe_src_w = crtc_state->pipe_src_w;
1495 * Display WA #1175: cnl,glk
1496 * Planes other than the cursor may cause FIFO underflow and display
1497 * corruption if starting less than 4 pixels from the right edge of
1499 * Besides the above WA fix the similar problem, where planes other
1500 * than the cursor ending less than 4 pixels from the left edge of the
1501 * screen may cause FIFO underflow and display corruption.
1503 if ((IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) &&
1504 (crtc_x + crtc_w < 4 || crtc_x > pipe_src_w - 4)) {
1505 DRM_DEBUG_KMS("requested plane X %s position %d invalid (valid range %d-%d)\n",
1506 crtc_x + crtc_w < 4 ? "end" : "start",
1507 crtc_x + crtc_w < 4 ? crtc_x + crtc_w : crtc_x,
1515 static int skl_plane_check_nv12_rotation(const struct intel_plane_state *plane_state)
1517 const struct drm_framebuffer *fb = plane_state->base.fb;
1518 unsigned int rotation = plane_state->base.rotation;
1519 int src_w = drm_rect_width(&plane_state->base.src) >> 16;
1521 /* Display WA #1106 */
1522 if (fb->format->format == DRM_FORMAT_NV12 && src_w & 3 &&
1523 (rotation == DRM_MODE_ROTATE_270 ||
1524 rotation == (DRM_MODE_REFLECT_X | DRM_MODE_ROTATE_90))) {
1525 DRM_DEBUG_KMS("src width must be multiple of 4 for rotated NV12\n");
1532 static int skl_plane_check(struct intel_crtc_state *crtc_state,
1533 struct intel_plane_state *plane_state)
1535 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
1536 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1537 const struct drm_framebuffer *fb = plane_state->base.fb;
1538 int min_scale = DRM_PLANE_HELPER_NO_SCALING;
1539 int max_scale = DRM_PLANE_HELPER_NO_SCALING;
1542 ret = skl_plane_check_fb(crtc_state, plane_state);
1546 /* use scaler when colorkey is not required */
1547 if (!plane_state->ckey.flags && intel_fb_scalable(fb)) {
1549 max_scale = skl_max_scale(crtc_state, fb->format->format);
1552 ret = drm_atomic_helper_check_plane_state(&plane_state->base,
1554 min_scale, max_scale,
1559 if (!plane_state->base.visible)
1562 ret = skl_plane_check_dst_coordinates(crtc_state, plane_state);
1566 ret = intel_plane_check_src_coordinates(plane_state);
1570 ret = skl_plane_check_nv12_rotation(plane_state);
1574 ret = skl_check_plane_surface(plane_state);
1578 /* HW only has 8 bits pixel precision, disable plane if invisible */
1579 if (!(plane_state->base.alpha >> 8))
1580 plane_state->base.visible = false;
1582 plane_state->ctl = skl_plane_ctl(crtc_state, plane_state);
1584 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
1585 plane_state->color_ctl = glk_plane_color_ctl(crtc_state,
1591 static bool has_dst_key_in_primary_plane(struct drm_i915_private *dev_priv)
1593 return INTEL_GEN(dev_priv) >= 9;
1596 static void intel_plane_set_ckey(struct intel_plane_state *plane_state,
1597 const struct drm_intel_sprite_colorkey *set)
1599 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
1600 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1601 struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
1606 * We want src key enabled on the
1607 * sprite and not on the primary.
1609 if (plane->id == PLANE_PRIMARY &&
1610 set->flags & I915_SET_COLORKEY_SOURCE)
1614 * On SKL+ we want dst key enabled on
1615 * the primary and not on the sprite.
1617 if (INTEL_GEN(dev_priv) >= 9 && plane->id != PLANE_PRIMARY &&
1618 set->flags & I915_SET_COLORKEY_DESTINATION)
1622 int intel_sprite_set_colorkey_ioctl(struct drm_device *dev, void *data,
1623 struct drm_file *file_priv)
1625 struct drm_i915_private *dev_priv = to_i915(dev);
1626 struct drm_intel_sprite_colorkey *set = data;
1627 struct drm_plane *plane;
1628 struct drm_plane_state *plane_state;
1629 struct drm_atomic_state *state;
1630 struct drm_modeset_acquire_ctx ctx;
1633 /* ignore the pointless "none" flag */
1634 set->flags &= ~I915_SET_COLORKEY_NONE;
1636 if (set->flags & ~(I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE))
1639 /* Make sure we don't try to enable both src & dest simultaneously */
1640 if ((set->flags & (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE)) == (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE))
1643 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
1644 set->flags & I915_SET_COLORKEY_DESTINATION)
1647 plane = drm_plane_find(dev, file_priv, set->plane_id);
1648 if (!plane || plane->type != DRM_PLANE_TYPE_OVERLAY)
1652 * SKL+ only plane 2 can do destination keying against plane 1.
1653 * Also multiple planes can't do destination keying on the same
1654 * pipe simultaneously.
1656 if (INTEL_GEN(dev_priv) >= 9 &&
1657 to_intel_plane(plane)->id >= PLANE_SPRITE1 &&
1658 set->flags & I915_SET_COLORKEY_DESTINATION)
1661 drm_modeset_acquire_init(&ctx, 0);
1663 state = drm_atomic_state_alloc(plane->dev);
1668 state->acquire_ctx = &ctx;
1671 plane_state = drm_atomic_get_plane_state(state, plane);
1672 ret = PTR_ERR_OR_ZERO(plane_state);
1674 intel_plane_set_ckey(to_intel_plane_state(plane_state), set);
1677 * On some platforms we have to configure
1678 * the dst colorkey on the primary plane.
1680 if (!ret && has_dst_key_in_primary_plane(dev_priv)) {
1681 struct intel_crtc *crtc =
1682 intel_get_crtc_for_pipe(dev_priv,
1683 to_intel_plane(plane)->pipe);
1685 plane_state = drm_atomic_get_plane_state(state,
1686 crtc->base.primary);
1687 ret = PTR_ERR_OR_ZERO(plane_state);
1689 intel_plane_set_ckey(to_intel_plane_state(plane_state), set);
1693 ret = drm_atomic_commit(state);
1695 if (ret != -EDEADLK)
1698 drm_atomic_state_clear(state);
1699 drm_modeset_backoff(&ctx);
1702 drm_atomic_state_put(state);
1704 drm_modeset_drop_locks(&ctx);
1705 drm_modeset_acquire_fini(&ctx);
1709 static const u32 g4x_plane_formats[] = {
1710 DRM_FORMAT_XRGB8888,
1717 static const u64 i9xx_plane_format_modifiers[] = {
1718 I915_FORMAT_MOD_X_TILED,
1719 DRM_FORMAT_MOD_LINEAR,
1720 DRM_FORMAT_MOD_INVALID
1723 static const u32 snb_plane_formats[] = {
1724 DRM_FORMAT_XBGR8888,
1725 DRM_FORMAT_XRGB8888,
1732 static const u32 vlv_plane_formats[] = {
1734 DRM_FORMAT_ABGR8888,
1735 DRM_FORMAT_ARGB8888,
1736 DRM_FORMAT_XBGR8888,
1737 DRM_FORMAT_XRGB8888,
1738 DRM_FORMAT_XBGR2101010,
1739 DRM_FORMAT_ABGR2101010,
1746 static const u32 skl_plane_formats[] = {
1749 DRM_FORMAT_XRGB8888,
1750 DRM_FORMAT_XBGR8888,
1751 DRM_FORMAT_ARGB8888,
1752 DRM_FORMAT_ABGR8888,
1753 DRM_FORMAT_XRGB2101010,
1754 DRM_FORMAT_XBGR2101010,
1761 static const u32 skl_planar_formats[] = {
1764 DRM_FORMAT_XRGB8888,
1765 DRM_FORMAT_XBGR8888,
1766 DRM_FORMAT_ARGB8888,
1767 DRM_FORMAT_ABGR8888,
1768 DRM_FORMAT_XRGB2101010,
1769 DRM_FORMAT_XBGR2101010,
1777 static const u64 skl_plane_format_modifiers_noccs[] = {
1778 I915_FORMAT_MOD_Yf_TILED,
1779 I915_FORMAT_MOD_Y_TILED,
1780 I915_FORMAT_MOD_X_TILED,
1781 DRM_FORMAT_MOD_LINEAR,
1782 DRM_FORMAT_MOD_INVALID
1785 static const u64 skl_plane_format_modifiers_ccs[] = {
1786 I915_FORMAT_MOD_Yf_TILED_CCS,
1787 I915_FORMAT_MOD_Y_TILED_CCS,
1788 I915_FORMAT_MOD_Yf_TILED,
1789 I915_FORMAT_MOD_Y_TILED,
1790 I915_FORMAT_MOD_X_TILED,
1791 DRM_FORMAT_MOD_LINEAR,
1792 DRM_FORMAT_MOD_INVALID
1795 static bool g4x_sprite_format_mod_supported(struct drm_plane *_plane,
1796 u32 format, u64 modifier)
1799 case DRM_FORMAT_MOD_LINEAR:
1800 case I915_FORMAT_MOD_X_TILED:
1807 case DRM_FORMAT_XRGB8888:
1808 case DRM_FORMAT_YUYV:
1809 case DRM_FORMAT_YVYU:
1810 case DRM_FORMAT_UYVY:
1811 case DRM_FORMAT_VYUY:
1812 if (modifier == DRM_FORMAT_MOD_LINEAR ||
1813 modifier == I915_FORMAT_MOD_X_TILED)
1821 static bool snb_sprite_format_mod_supported(struct drm_plane *_plane,
1822 u32 format, u64 modifier)
1825 case DRM_FORMAT_MOD_LINEAR:
1826 case I915_FORMAT_MOD_X_TILED:
1833 case DRM_FORMAT_XRGB8888:
1834 case DRM_FORMAT_XBGR8888:
1835 case DRM_FORMAT_YUYV:
1836 case DRM_FORMAT_YVYU:
1837 case DRM_FORMAT_UYVY:
1838 case DRM_FORMAT_VYUY:
1839 if (modifier == DRM_FORMAT_MOD_LINEAR ||
1840 modifier == I915_FORMAT_MOD_X_TILED)
1848 static bool vlv_sprite_format_mod_supported(struct drm_plane *_plane,
1849 u32 format, u64 modifier)
1852 case DRM_FORMAT_MOD_LINEAR:
1853 case I915_FORMAT_MOD_X_TILED:
1860 case DRM_FORMAT_RGB565:
1861 case DRM_FORMAT_ABGR8888:
1862 case DRM_FORMAT_ARGB8888:
1863 case DRM_FORMAT_XBGR8888:
1864 case DRM_FORMAT_XRGB8888:
1865 case DRM_FORMAT_XBGR2101010:
1866 case DRM_FORMAT_ABGR2101010:
1867 case DRM_FORMAT_YUYV:
1868 case DRM_FORMAT_YVYU:
1869 case DRM_FORMAT_UYVY:
1870 case DRM_FORMAT_VYUY:
1871 if (modifier == DRM_FORMAT_MOD_LINEAR ||
1872 modifier == I915_FORMAT_MOD_X_TILED)
1880 static bool skl_plane_format_mod_supported(struct drm_plane *_plane,
1881 u32 format, u64 modifier)
1883 struct intel_plane *plane = to_intel_plane(_plane);
1886 case DRM_FORMAT_MOD_LINEAR:
1887 case I915_FORMAT_MOD_X_TILED:
1888 case I915_FORMAT_MOD_Y_TILED:
1889 case I915_FORMAT_MOD_Yf_TILED:
1891 case I915_FORMAT_MOD_Y_TILED_CCS:
1892 case I915_FORMAT_MOD_Yf_TILED_CCS:
1893 if (!plane->has_ccs)
1901 case DRM_FORMAT_XRGB8888:
1902 case DRM_FORMAT_XBGR8888:
1903 case DRM_FORMAT_ARGB8888:
1904 case DRM_FORMAT_ABGR8888:
1905 if (is_ccs_modifier(modifier))
1908 case DRM_FORMAT_RGB565:
1909 case DRM_FORMAT_XRGB2101010:
1910 case DRM_FORMAT_XBGR2101010:
1911 case DRM_FORMAT_YUYV:
1912 case DRM_FORMAT_YVYU:
1913 case DRM_FORMAT_UYVY:
1914 case DRM_FORMAT_VYUY:
1915 case DRM_FORMAT_NV12:
1916 if (modifier == I915_FORMAT_MOD_Yf_TILED)
1920 if (modifier == DRM_FORMAT_MOD_LINEAR ||
1921 modifier == I915_FORMAT_MOD_X_TILED ||
1922 modifier == I915_FORMAT_MOD_Y_TILED)
1930 static const struct drm_plane_funcs g4x_sprite_funcs = {
1931 .update_plane = drm_atomic_helper_update_plane,
1932 .disable_plane = drm_atomic_helper_disable_plane,
1933 .destroy = intel_plane_destroy,
1934 .atomic_get_property = intel_plane_atomic_get_property,
1935 .atomic_set_property = intel_plane_atomic_set_property,
1936 .atomic_duplicate_state = intel_plane_duplicate_state,
1937 .atomic_destroy_state = intel_plane_destroy_state,
1938 .format_mod_supported = g4x_sprite_format_mod_supported,
1941 static const struct drm_plane_funcs snb_sprite_funcs = {
1942 .update_plane = drm_atomic_helper_update_plane,
1943 .disable_plane = drm_atomic_helper_disable_plane,
1944 .destroy = intel_plane_destroy,
1945 .atomic_get_property = intel_plane_atomic_get_property,
1946 .atomic_set_property = intel_plane_atomic_set_property,
1947 .atomic_duplicate_state = intel_plane_duplicate_state,
1948 .atomic_destroy_state = intel_plane_destroy_state,
1949 .format_mod_supported = snb_sprite_format_mod_supported,
1952 static const struct drm_plane_funcs vlv_sprite_funcs = {
1953 .update_plane = drm_atomic_helper_update_plane,
1954 .disable_plane = drm_atomic_helper_disable_plane,
1955 .destroy = intel_plane_destroy,
1956 .atomic_get_property = intel_plane_atomic_get_property,
1957 .atomic_set_property = intel_plane_atomic_set_property,
1958 .atomic_duplicate_state = intel_plane_duplicate_state,
1959 .atomic_destroy_state = intel_plane_destroy_state,
1960 .format_mod_supported = vlv_sprite_format_mod_supported,
1963 static const struct drm_plane_funcs skl_plane_funcs = {
1964 .update_plane = drm_atomic_helper_update_plane,
1965 .disable_plane = drm_atomic_helper_disable_plane,
1966 .destroy = intel_plane_destroy,
1967 .atomic_get_property = intel_plane_atomic_get_property,
1968 .atomic_set_property = intel_plane_atomic_set_property,
1969 .atomic_duplicate_state = intel_plane_duplicate_state,
1970 .atomic_destroy_state = intel_plane_destroy_state,
1971 .format_mod_supported = skl_plane_format_mod_supported,
1974 static bool skl_plane_has_fbc(struct drm_i915_private *dev_priv,
1975 enum pipe pipe, enum plane_id plane_id)
1977 if (!HAS_FBC(dev_priv))
1980 return pipe == PIPE_A && plane_id == PLANE_PRIMARY;
1983 static bool skl_plane_has_planar(struct drm_i915_private *dev_priv,
1984 enum pipe pipe, enum plane_id plane_id)
1986 if (INTEL_GEN(dev_priv) >= 11)
1987 return plane_id <= PLANE_SPRITE3;
1989 /* Display WA #0870: skl, bxt */
1990 if (IS_SKYLAKE(dev_priv) || IS_BROXTON(dev_priv))
1993 if (IS_GEN(dev_priv, 9) && !IS_GEMINILAKE(dev_priv) && pipe == PIPE_C)
1996 if (plane_id != PLANE_PRIMARY && plane_id != PLANE_SPRITE0)
2002 static bool skl_plane_has_ccs(struct drm_i915_private *dev_priv,
2003 enum pipe pipe, enum plane_id plane_id)
2005 if (plane_id == PLANE_CURSOR)
2008 if (INTEL_GEN(dev_priv) >= 10)
2011 if (IS_GEMINILAKE(dev_priv))
2012 return pipe != PIPE_C;
2014 return pipe != PIPE_C &&
2015 (plane_id == PLANE_PRIMARY ||
2016 plane_id == PLANE_SPRITE0);
2019 struct intel_plane *
2020 skl_universal_plane_create(struct drm_i915_private *dev_priv,
2021 enum pipe pipe, enum plane_id plane_id)
2023 struct intel_plane *plane;
2024 enum drm_plane_type plane_type;
2025 unsigned int supported_rotations;
2026 unsigned int possible_crtcs;
2027 const u64 *modifiers;
2032 plane = intel_plane_alloc();
2037 plane->id = plane_id;
2038 plane->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, plane_id);
2040 plane->has_fbc = skl_plane_has_fbc(dev_priv, pipe, plane_id);
2041 if (plane->has_fbc) {
2042 struct intel_fbc *fbc = &dev_priv->fbc;
2044 fbc->possible_framebuffer_bits |= plane->frontbuffer_bit;
2047 plane->max_stride = skl_plane_max_stride;
2048 plane->update_plane = skl_update_plane;
2049 plane->disable_plane = skl_disable_plane;
2050 plane->get_hw_state = skl_plane_get_hw_state;
2051 plane->check_plane = skl_plane_check;
2052 if (icl_is_nv12_y_plane(plane_id))
2053 plane->update_slave = icl_update_slave;
2055 if (skl_plane_has_planar(dev_priv, pipe, plane_id)) {
2056 formats = skl_planar_formats;
2057 num_formats = ARRAY_SIZE(skl_planar_formats);
2059 formats = skl_plane_formats;
2060 num_formats = ARRAY_SIZE(skl_plane_formats);
2063 plane->has_ccs = skl_plane_has_ccs(dev_priv, pipe, plane_id);
2065 modifiers = skl_plane_format_modifiers_ccs;
2067 modifiers = skl_plane_format_modifiers_noccs;
2069 if (plane_id == PLANE_PRIMARY)
2070 plane_type = DRM_PLANE_TYPE_PRIMARY;
2072 plane_type = DRM_PLANE_TYPE_OVERLAY;
2074 possible_crtcs = BIT(pipe);
2076 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
2077 possible_crtcs, &skl_plane_funcs,
2078 formats, num_formats, modifiers,
2080 "plane %d%c", plane_id + 1,
2085 supported_rotations =
2086 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_90 |
2087 DRM_MODE_ROTATE_180 | DRM_MODE_ROTATE_270;
2089 if (INTEL_GEN(dev_priv) >= 10)
2090 supported_rotations |= DRM_MODE_REFLECT_X;
2092 drm_plane_create_rotation_property(&plane->base,
2094 supported_rotations);
2096 drm_plane_create_color_properties(&plane->base,
2097 BIT(DRM_COLOR_YCBCR_BT601) |
2098 BIT(DRM_COLOR_YCBCR_BT709),
2099 BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) |
2100 BIT(DRM_COLOR_YCBCR_FULL_RANGE),
2101 DRM_COLOR_YCBCR_BT709,
2102 DRM_COLOR_YCBCR_LIMITED_RANGE);
2104 drm_plane_create_alpha_property(&plane->base);
2105 drm_plane_create_blend_mode_property(&plane->base,
2106 BIT(DRM_MODE_BLEND_PIXEL_NONE) |
2107 BIT(DRM_MODE_BLEND_PREMULTI) |
2108 BIT(DRM_MODE_BLEND_COVERAGE));
2110 drm_plane_helper_add(&plane->base, &intel_plane_helper_funcs);
2115 intel_plane_free(plane);
2117 return ERR_PTR(ret);
2120 struct intel_plane *
2121 intel_sprite_plane_create(struct drm_i915_private *dev_priv,
2122 enum pipe pipe, int sprite)
2124 struct intel_plane *plane;
2125 const struct drm_plane_funcs *plane_funcs;
2126 unsigned long possible_crtcs;
2127 unsigned int supported_rotations;
2128 const u64 *modifiers;
2133 if (INTEL_GEN(dev_priv) >= 9)
2134 return skl_universal_plane_create(dev_priv, pipe,
2135 PLANE_SPRITE0 + sprite);
2137 plane = intel_plane_alloc();
2141 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
2142 plane->max_stride = i9xx_plane_max_stride;
2143 plane->update_plane = vlv_update_plane;
2144 plane->disable_plane = vlv_disable_plane;
2145 plane->get_hw_state = vlv_plane_get_hw_state;
2146 plane->check_plane = vlv_sprite_check;
2148 formats = vlv_plane_formats;
2149 num_formats = ARRAY_SIZE(vlv_plane_formats);
2150 modifiers = i9xx_plane_format_modifiers;
2152 plane_funcs = &vlv_sprite_funcs;
2153 } else if (INTEL_GEN(dev_priv) >= 7) {
2154 plane->max_stride = g4x_sprite_max_stride;
2155 plane->update_plane = ivb_update_plane;
2156 plane->disable_plane = ivb_disable_plane;
2157 plane->get_hw_state = ivb_plane_get_hw_state;
2158 plane->check_plane = g4x_sprite_check;
2160 formats = snb_plane_formats;
2161 num_formats = ARRAY_SIZE(snb_plane_formats);
2162 modifiers = i9xx_plane_format_modifiers;
2164 plane_funcs = &snb_sprite_funcs;
2166 plane->max_stride = g4x_sprite_max_stride;
2167 plane->update_plane = g4x_update_plane;
2168 plane->disable_plane = g4x_disable_plane;
2169 plane->get_hw_state = g4x_plane_get_hw_state;
2170 plane->check_plane = g4x_sprite_check;
2172 modifiers = i9xx_plane_format_modifiers;
2173 if (IS_GEN(dev_priv, 6)) {
2174 formats = snb_plane_formats;
2175 num_formats = ARRAY_SIZE(snb_plane_formats);
2177 plane_funcs = &snb_sprite_funcs;
2179 formats = g4x_plane_formats;
2180 num_formats = ARRAY_SIZE(g4x_plane_formats);
2182 plane_funcs = &g4x_sprite_funcs;
2186 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
2187 supported_rotations =
2188 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 |
2191 supported_rotations =
2192 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180;
2196 plane->id = PLANE_SPRITE0 + sprite;
2197 plane->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, plane->id);
2199 possible_crtcs = BIT(pipe);
2201 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
2202 possible_crtcs, plane_funcs,
2203 formats, num_formats, modifiers,
2204 DRM_PLANE_TYPE_OVERLAY,
2205 "sprite %c", sprite_name(pipe, sprite));
2209 drm_plane_create_rotation_property(&plane->base,
2211 supported_rotations);
2213 drm_plane_create_color_properties(&plane->base,
2214 BIT(DRM_COLOR_YCBCR_BT601) |
2215 BIT(DRM_COLOR_YCBCR_BT709),
2216 BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) |
2217 BIT(DRM_COLOR_YCBCR_FULL_RANGE),
2218 DRM_COLOR_YCBCR_BT709,
2219 DRM_COLOR_YCBCR_LIMITED_RANGE);
2221 drm_plane_helper_add(&plane->base, &intel_plane_helper_funcs);
2226 intel_plane_free(plane);
2228 return ERR_PTR(ret);