1 /*
2 * Copyright © 2014 Intel Corporation
3 *
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:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
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
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24 /**
25 * DOC: atomic plane helpers
26 *
27 * The functions here are used by the atomic plane helper functions to
28 * implement legacy plane updates (i.e., drm_plane->update_plane() and
29 * drm_plane->disable_plane()). This allows plane updates to use the
30 * atomic state infrastructure and perform plane updates as separate
31 * prepare/check/commit/cleanup steps.
32 */
33
34 #include <linux/dma-fence-chain.h>
35 #include <linux/dma-resv.h>
36 #include <linux/iosys-map.h>
37
38 #include <drm/drm_atomic_helper.h>
39 #include <drm/drm_blend.h>
40 #include <drm/drm_cache.h>
41 #include <drm/drm_damage_helper.h>
42 #include <drm/drm_fourcc.h>
43 #include <drm/drm_gem.h>
44 #include <drm/drm_gem_atomic_helper.h>
45 #include <drm/drm_panic.h>
46 #include <drm/drm_print.h>
47
48 #include "i9xx_plane_regs.h"
49 #include "intel_cdclk.h"
50 #include "intel_cursor.h"
51 #include "intel_colorop.h"
52 #include "intel_display_rps.h"
53 #include "intel_display_trace.h"
54 #include "intel_display_types.h"
55 #include "intel_fb.h"
56 #include "intel_fb_pin.h"
57 #include "intel_fbdev.h"
58 #include "intel_parent.h"
59 #include "intel_plane.h"
60 #include "intel_psr.h"
61 #include "skl_scaler.h"
62 #include "skl_universal_plane.h"
63 #include "skl_watermark.h"
64
intel_plane_state_reset(struct intel_plane_state * plane_state,struct intel_plane * plane)65 static void intel_plane_state_reset(struct intel_plane_state *plane_state,
66 struct intel_plane *plane)
67 {
68 memset(plane_state, 0, sizeof(*plane_state));
69
70 __drm_atomic_helper_plane_state_reset(&plane_state->uapi, &plane->base);
71
72 plane_state->scaler_id = -1;
73 }
74
intel_plane_alloc(void)75 struct intel_plane *intel_plane_alloc(void)
76 {
77 struct intel_plane_state *plane_state;
78 struct intel_plane *plane;
79
80 plane = kzalloc_obj(*plane);
81 if (!plane)
82 return ERR_PTR(-ENOMEM);
83
84 plane_state = kzalloc_obj(*plane_state);
85 if (!plane_state) {
86 kfree(plane);
87 return ERR_PTR(-ENOMEM);
88 }
89
90 intel_plane_state_reset(plane_state, plane);
91
92 plane->base.state = &plane_state->uapi;
93
94 return plane;
95 }
96
intel_plane_free(struct intel_plane * plane)97 void intel_plane_free(struct intel_plane *plane)
98 {
99 intel_plane_destroy_state(&plane->base, plane->base.state);
100 kfree(plane);
101 }
102
103 /**
104 * intel_plane_destroy - destroy a plane
105 * @plane: plane to destroy
106 *
107 * Common destruction function for all types of planes (primary, cursor,
108 * sprite).
109 */
intel_plane_destroy(struct drm_plane * plane)110 void intel_plane_destroy(struct drm_plane *plane)
111 {
112 drm_plane_cleanup(plane);
113 kfree(to_intel_plane(plane));
114 }
115
116 /**
117 * intel_plane_duplicate_state - duplicate plane state
118 * @plane: drm plane
119 *
120 * Allocates and returns a copy of the plane state (both common and
121 * Intel-specific) for the specified plane.
122 *
123 * Returns: The newly allocated plane state, or NULL on failure.
124 */
125 struct drm_plane_state *
intel_plane_duplicate_state(struct drm_plane * plane)126 intel_plane_duplicate_state(struct drm_plane *plane)
127 {
128 struct intel_plane_state *intel_state;
129
130 intel_state = to_intel_plane_state(plane->state);
131 intel_state = kmemdup(intel_state, sizeof(*intel_state), GFP_KERNEL);
132
133 if (!intel_state)
134 return NULL;
135
136 __drm_atomic_helper_plane_duplicate_state(plane, &intel_state->uapi);
137
138 intel_state->ggtt_vma = NULL;
139 intel_state->dpt_vma = NULL;
140 intel_state->flags = 0;
141 intel_state->damage = DRM_RECT_INIT(0, 0, 0, 0);
142
143 /* add reference to fb */
144 if (intel_state->hw.fb)
145 drm_framebuffer_get(intel_state->hw.fb);
146
147 return &intel_state->uapi;
148 }
149
150 /**
151 * intel_plane_destroy_state - destroy plane state
152 * @plane: drm plane
153 * @state: state object to destroy
154 *
155 * Destroys the plane state (both common and Intel-specific) for the
156 * specified plane.
157 */
158 void
intel_plane_destroy_state(struct drm_plane * plane,struct drm_plane_state * state)159 intel_plane_destroy_state(struct drm_plane *plane,
160 struct drm_plane_state *state)
161 {
162 struct intel_plane_state *plane_state = to_intel_plane_state(state);
163
164 drm_WARN_ON(plane->dev, plane_state->ggtt_vma);
165 drm_WARN_ON(plane->dev, plane_state->dpt_vma);
166
167 __drm_atomic_helper_plane_destroy_state(&plane_state->uapi);
168 if (plane_state->hw.fb)
169 drm_framebuffer_put(plane_state->hw.fb);
170 kfree(plane_state);
171 }
172
intel_plane_needs_physical(struct intel_plane * plane)173 bool intel_plane_needs_physical(struct intel_plane *plane)
174 {
175 struct intel_display *display = to_intel_display(plane);
176
177 return plane->id == PLANE_CURSOR &&
178 DISPLAY_INFO(display)->cursor_needs_physical;
179 }
180
intel_plane_can_async_flip(struct intel_plane * plane,const struct drm_format_info * info,u64 modifier)181 bool intel_plane_can_async_flip(struct intel_plane *plane,
182 const struct drm_format_info *info,
183 u64 modifier)
184 {
185 if (intel_format_info_is_yuv_semiplanar(info, modifier) ||
186 info->format == DRM_FORMAT_C8)
187 return false;
188
189 return plane->can_async_flip && plane->can_async_flip(modifier);
190 }
191
intel_plane_format_mod_supported_async(struct drm_plane * _plane,u32 format,u64 modifier)192 bool intel_plane_format_mod_supported_async(struct drm_plane *_plane,
193 u32 format, u64 modifier)
194 {
195 struct intel_plane *plane = to_intel_plane(_plane);
196 const struct drm_format_info *info;
197
198 if (!plane->base.funcs->format_mod_supported(&plane->base, format, modifier))
199 return false;
200
201 info = drm_get_format_info(plane->base.dev, format, modifier);
202
203 return intel_plane_can_async_flip(plane, info, modifier);
204 }
205
intel_adjusted_rate(const struct drm_rect * src,const struct drm_rect * dst,unsigned int rate)206 unsigned int intel_adjusted_rate(const struct drm_rect *src,
207 const struct drm_rect *dst,
208 unsigned int rate)
209 {
210 unsigned int src_w, src_h, dst_w, dst_h;
211
212 src_w = drm_rect_width(src) >> 16;
213 src_h = drm_rect_height(src) >> 16;
214 dst_w = drm_rect_width(dst);
215 dst_h = drm_rect_height(dst);
216
217 /* Downscaling limits the maximum pixel rate */
218 dst_w = min(src_w, dst_w);
219 dst_h = min(src_h, dst_h);
220
221 return DIV_ROUND_UP_ULL(mul_u32_u32(rate, src_w * src_h),
222 dst_w * dst_h);
223 }
224
intel_plane_pixel_rate(const struct intel_crtc_state * crtc_state,const struct intel_plane_state * plane_state)225 unsigned int intel_plane_pixel_rate(const struct intel_crtc_state *crtc_state,
226 const struct intel_plane_state *plane_state)
227 {
228 /*
229 * Note we don't check for plane visibility here as
230 * we want to use this when calculating the cursor
231 * watermarks even if the cursor is fully offscreen.
232 * That depends on the src/dst rectangles being
233 * correctly populated whenever the watermark code
234 * considers the cursor to be visible, whether or not
235 * it is actually visible.
236 *
237 * See: intel_wm_plane_visible() and intel_check_cursor()
238 */
239
240 return intel_adjusted_rate(&plane_state->uapi.src,
241 &plane_state->uapi.dst,
242 crtc_state->pixel_rate);
243 }
244
intel_plane_data_rate(const struct intel_crtc_state * crtc_state,const struct intel_plane_state * plane_state,int color_plane)245 unsigned int intel_plane_data_rate(const struct intel_crtc_state *crtc_state,
246 const struct intel_plane_state *plane_state,
247 int color_plane)
248 {
249 const struct drm_framebuffer *fb = plane_state->hw.fb;
250
251 if (!plane_state->uapi.visible)
252 return 0;
253
254 return intel_plane_pixel_rate(crtc_state, plane_state) *
255 fb->format->cpp[color_plane];
256 }
257
258 static unsigned int
intel_plane_relative_data_rate(const struct intel_crtc_state * crtc_state,const struct intel_plane_state * plane_state,int color_plane)259 intel_plane_relative_data_rate(const struct intel_crtc_state *crtc_state,
260 const struct intel_plane_state *plane_state,
261 int color_plane)
262 {
263 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
264 const struct drm_framebuffer *fb = plane_state->hw.fb;
265 unsigned int rel_data_rate;
266 int width, height;
267
268 if (plane->id == PLANE_CURSOR)
269 return 0;
270
271 if (!plane_state->uapi.visible)
272 return 0;
273
274 /*
275 * Src coordinates are already rotated by 270 degrees for
276 * the 90/270 degree plane rotation cases (to match the
277 * GTT mapping), hence no need to account for rotation here.
278 */
279 width = drm_rect_width(&plane_state->uapi.src) >> 16;
280 height = drm_rect_height(&plane_state->uapi.src) >> 16;
281
282 /* UV plane does 1/2 pixel sub-sampling */
283 if (color_plane == 1) {
284 width /= 2;
285 height /= 2;
286 }
287
288 rel_data_rate =
289 skl_plane_relative_data_rate(crtc_state, plane, width, height,
290 fb->format->cpp[color_plane]);
291 if (!rel_data_rate)
292 return 0;
293
294 return intel_adjusted_rate(&plane_state->uapi.src,
295 &plane_state->uapi.dst,
296 rel_data_rate);
297 }
298
intel_plane_calc_min_cdclk(struct intel_atomic_state * state,struct intel_plane * plane)299 static void intel_plane_calc_min_cdclk(struct intel_atomic_state *state,
300 struct intel_plane *plane)
301 {
302 const struct intel_plane_state *plane_state =
303 intel_atomic_get_new_plane_state(state, plane);
304 struct intel_crtc *crtc = to_intel_crtc(plane_state->hw.crtc);
305 struct intel_crtc_state *new_crtc_state;
306
307 if (!plane_state->uapi.visible || !plane->min_cdclk)
308 return;
309
310 new_crtc_state = intel_atomic_get_new_crtc_state(state, crtc);
311
312 new_crtc_state->plane_min_cdclk[plane->id] =
313 plane->min_cdclk(new_crtc_state, plane_state);
314 }
315
intel_plane_clear_hw_state(struct intel_plane_state * plane_state)316 static void intel_plane_clear_hw_state(struct intel_plane_state *plane_state)
317 {
318 if (plane_state->hw.fb)
319 drm_framebuffer_put(plane_state->hw.fb);
320
321 memset(&plane_state->hw, 0, sizeof(plane_state->hw));
322 }
323
324 static void
intel_plane_copy_uapi_plane_damage(struct intel_plane_state * new_plane_state,const struct intel_plane_state * old_uapi_plane_state,const struct intel_plane_state * new_uapi_plane_state)325 intel_plane_copy_uapi_plane_damage(struct intel_plane_state *new_plane_state,
326 const struct intel_plane_state *old_uapi_plane_state,
327 const struct intel_plane_state *new_uapi_plane_state)
328 {
329 struct intel_display *display = to_intel_display(new_plane_state);
330 struct drm_rect *damage = &new_plane_state->damage;
331
332 /* damage property tracking enabled from display version 12 onwards */
333 if (DISPLAY_VER(display) < 12)
334 return;
335
336 if (!drm_atomic_helper_damage_merged(&old_uapi_plane_state->uapi,
337 &new_uapi_plane_state->uapi,
338 damage))
339 /* Incase helper fails, mark whole plane region as damage */
340 *damage = drm_plane_state_src(&new_uapi_plane_state->uapi);
341 }
342
343 static bool
intel_plane_colorop_replace_blob(struct intel_plane_state * plane_state,struct intel_colorop * intel_colorop,struct drm_property_blob * blob)344 intel_plane_colorop_replace_blob(struct intel_plane_state *plane_state,
345 struct intel_colorop *intel_colorop,
346 struct drm_property_blob *blob)
347 {
348 if (intel_colorop->id == INTEL_PLANE_CB_CSC)
349 return drm_property_replace_blob(&plane_state->hw.ctm, blob);
350 else if (intel_colorop->id == INTEL_PLANE_CB_PRE_CSC_LUT)
351 return drm_property_replace_blob(&plane_state->hw.degamma_lut, blob);
352 else if (intel_colorop->id == INTEL_PLANE_CB_POST_CSC_LUT)
353 return drm_property_replace_blob(&plane_state->hw.gamma_lut, blob);
354 else if (intel_colorop->id == INTEL_PLANE_CB_3DLUT)
355 return drm_property_replace_blob(&plane_state->hw.lut_3d, blob);
356
357 return false;
358 }
359
360 static void
intel_plane_color_copy_uapi_to_hw_state(struct intel_plane_state * plane_state,const struct intel_plane_state * from_plane_state,struct intel_crtc * crtc)361 intel_plane_color_copy_uapi_to_hw_state(struct intel_plane_state *plane_state,
362 const struct intel_plane_state *from_plane_state,
363 struct intel_crtc *crtc)
364 {
365 struct drm_colorop *iter_colorop, *colorop;
366 struct drm_colorop_state *new_colorop_state;
367 struct drm_atomic_state *state = plane_state->uapi.state;
368 struct intel_colorop *intel_colorop;
369 struct drm_property_blob *blob;
370 struct intel_atomic_state *intel_atomic_state = to_intel_atomic_state(state);
371 struct intel_crtc_state *new_crtc_state = intel_atomic_state ?
372 intel_atomic_get_new_crtc_state(intel_atomic_state, crtc) : NULL;
373 bool changed = false;
374 int i = 0;
375
376 iter_colorop = plane_state->uapi.color_pipeline;
377
378 while (iter_colorop) {
379 for_each_new_colorop_in_state(state, colorop, new_colorop_state, i) {
380 if (new_colorop_state->colorop == iter_colorop) {
381 blob = new_colorop_state->bypass ? NULL : new_colorop_state->data;
382 intel_colorop = to_intel_colorop(colorop);
383 changed |= intel_plane_colorop_replace_blob(plane_state,
384 intel_colorop,
385 blob);
386 }
387 }
388 iter_colorop = iter_colorop->next;
389 }
390
391 if (new_crtc_state && changed)
392 new_crtc_state->plane_color_changed = true;
393 }
394
intel_plane_copy_uapi_to_hw_state(struct intel_plane_state * plane_state,const struct intel_plane_state * from_plane_state,struct intel_crtc * crtc)395 void intel_plane_copy_uapi_to_hw_state(struct intel_plane_state *plane_state,
396 const struct intel_plane_state *from_plane_state,
397 struct intel_crtc *crtc)
398 {
399 intel_plane_clear_hw_state(plane_state);
400
401 /*
402 * For the joiner secondary uapi.crtc will point at
403 * the primary crtc. So we explicitly assign the right
404 * secondary crtc to hw.crtc. uapi.crtc!=NULL simply
405 * indicates the plane is logically enabled on the uapi level.
406 */
407 plane_state->hw.crtc = from_plane_state->uapi.crtc ? &crtc->base : NULL;
408
409 plane_state->hw.fb = from_plane_state->uapi.fb;
410 if (plane_state->hw.fb)
411 drm_framebuffer_get(plane_state->hw.fb);
412
413 plane_state->hw.alpha = from_plane_state->uapi.alpha;
414 plane_state->hw.pixel_blend_mode =
415 from_plane_state->uapi.pixel_blend_mode;
416 plane_state->hw.rotation = from_plane_state->uapi.rotation;
417 plane_state->hw.color_encoding = from_plane_state->uapi.color_encoding;
418 plane_state->hw.color_range = from_plane_state->uapi.color_range;
419 plane_state->hw.scaling_filter = from_plane_state->uapi.scaling_filter;
420
421 plane_state->uapi.src = drm_plane_state_src(&from_plane_state->uapi);
422 plane_state->uapi.dst = drm_plane_state_dest(&from_plane_state->uapi);
423
424 intel_plane_color_copy_uapi_to_hw_state(plane_state, from_plane_state, crtc);
425 }
426
intel_plane_copy_hw_state(struct intel_plane_state * plane_state,const struct intel_plane_state * from_plane_state)427 void intel_plane_copy_hw_state(struct intel_plane_state *plane_state,
428 const struct intel_plane_state *from_plane_state)
429 {
430 intel_plane_clear_hw_state(plane_state);
431
432 memcpy(&plane_state->hw, &from_plane_state->hw,
433 sizeof(plane_state->hw));
434
435 if (plane_state->hw.fb)
436 drm_framebuffer_get(plane_state->hw.fb);
437 }
438
439 static void unlink_nv12_plane(struct intel_crtc_state *crtc_state,
440 struct intel_plane_state *plane_state);
441
intel_plane_set_invisible(struct intel_crtc_state * crtc_state,struct intel_plane_state * plane_state)442 void intel_plane_set_invisible(struct intel_crtc_state *crtc_state,
443 struct intel_plane_state *plane_state)
444 {
445 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
446
447 unlink_nv12_plane(crtc_state, plane_state);
448
449 crtc_state->active_planes &= ~BIT(plane->id);
450 crtc_state->scaled_planes &= ~BIT(plane->id);
451 crtc_state->nv12_planes &= ~BIT(plane->id);
452 crtc_state->c8_planes &= ~BIT(plane->id);
453 crtc_state->async_flip_planes &= ~BIT(plane->id);
454 crtc_state->data_rate[plane->id] = 0;
455 crtc_state->data_rate_y[plane->id] = 0;
456 crtc_state->rel_data_rate[plane->id] = 0;
457 crtc_state->rel_data_rate_y[plane->id] = 0;
458 crtc_state->plane_min_cdclk[plane->id] = 0;
459
460 plane_state->uapi.visible = false;
461 }
462
intel_plane_is_scaled(const struct intel_plane_state * plane_state)463 static bool intel_plane_is_scaled(const struct intel_plane_state *plane_state)
464 {
465 int src_w = drm_rect_width(&plane_state->uapi.src) >> 16;
466 int src_h = drm_rect_height(&plane_state->uapi.src) >> 16;
467 int dst_w = drm_rect_width(&plane_state->uapi.dst);
468 int dst_h = drm_rect_height(&plane_state->uapi.dst);
469
470 return src_w != dst_w || src_h != dst_h;
471 }
472
intel_plane_do_async_flip(struct intel_plane * plane,const struct intel_crtc_state * old_crtc_state,const struct intel_crtc_state * new_crtc_state)473 static bool intel_plane_do_async_flip(struct intel_plane *plane,
474 const struct intel_crtc_state *old_crtc_state,
475 const struct intel_crtc_state *new_crtc_state)
476 {
477 struct intel_display *display = to_intel_display(plane);
478
479 if (!plane->async_flip)
480 return false;
481
482 if (!new_crtc_state->uapi.async_flip)
483 return false;
484
485 /*
486 * In platforms after DISPLAY13, we might need to override
487 * first async flip in order to change watermark levels
488 * as part of optimization.
489 *
490 * And let's do this for all skl+ so that we can eg. change the
491 * modifier as well.
492 *
493 * TODO: For older platforms there is less reason to do this as
494 * only X-tile is supported with async flips, though we could
495 * extend this so other scanout parameters (stride/etc) could
496 * be changed as well...
497 */
498 return DISPLAY_VER(display) < 9 || old_crtc_state->uapi.async_flip;
499 }
500
i9xx_must_disable_cxsr(const struct intel_crtc_state * new_crtc_state,const struct intel_plane_state * old_plane_state,const struct intel_plane_state * new_plane_state)501 static bool i9xx_must_disable_cxsr(const struct intel_crtc_state *new_crtc_state,
502 const struct intel_plane_state *old_plane_state,
503 const struct intel_plane_state *new_plane_state)
504 {
505 struct intel_plane *plane = to_intel_plane(new_plane_state->uapi.plane);
506 bool old_visible = old_plane_state->uapi.visible;
507 bool new_visible = new_plane_state->uapi.visible;
508 u32 old_ctl = old_plane_state->ctl;
509 u32 new_ctl = new_plane_state->ctl;
510 bool modeset, turn_on, turn_off;
511
512 if (plane->id == PLANE_CURSOR)
513 return false;
514
515 modeset = intel_crtc_needs_modeset(new_crtc_state);
516 turn_off = old_visible && (!new_visible || modeset);
517 turn_on = new_visible && (!old_visible || modeset);
518
519 /* Must disable CxSR around plane enable/disable */
520 if (turn_on || turn_off)
521 return true;
522
523 if (!old_visible || !new_visible)
524 return false;
525
526 /*
527 * Most plane control register updates are blocked while in CxSR.
528 *
529 * Tiling mode is one exception where the primary plane can
530 * apparently handle it, whereas the sprites can not (the
531 * sprite issue being only relevant on VLV/CHV where CxSR
532 * is actually possible with a sprite enabled).
533 */
534 if (plane->id == PLANE_PRIMARY) {
535 old_ctl &= ~DISP_TILED;
536 new_ctl &= ~DISP_TILED;
537 }
538
539 return old_ctl != new_ctl;
540 }
541
ilk_must_disable_cxsr(const struct intel_crtc_state * new_crtc_state,const struct intel_plane_state * old_plane_state,const struct intel_plane_state * new_plane_state)542 static bool ilk_must_disable_cxsr(const struct intel_crtc_state *new_crtc_state,
543 const struct intel_plane_state *old_plane_state,
544 const struct intel_plane_state *new_plane_state)
545 {
546 struct intel_plane *plane = to_intel_plane(new_plane_state->uapi.plane);
547 bool old_visible = old_plane_state->uapi.visible;
548 bool new_visible = new_plane_state->uapi.visible;
549 bool modeset, turn_on;
550
551 if (plane->id == PLANE_CURSOR)
552 return false;
553
554 modeset = intel_crtc_needs_modeset(new_crtc_state);
555 turn_on = new_visible && (!old_visible || modeset);
556
557 /*
558 * ILK/SNB DVSACNTR/Sprite Enable
559 * IVB SPR_CTL/Sprite Enable
560 * "When in Self Refresh Big FIFO mode, a write to enable the
561 * plane will be internally buffered and delayed while Big FIFO
562 * mode is exiting."
563 *
564 * Which means that enabling the sprite can take an extra frame
565 * when we start in big FIFO mode (LP1+). Thus we need to drop
566 * down to LP0 and wait for vblank in order to make sure the
567 * sprite gets enabled on the next vblank after the register write.
568 * Doing otherwise would risk enabling the sprite one frame after
569 * we've already signalled flip completion. We can resume LP1+
570 * once the sprite has been enabled.
571 *
572 * With experimental results seems this is needed also for primary
573 * plane, not only sprite plane.
574 */
575 if (turn_on)
576 return true;
577
578 /*
579 * WaCxSRDisabledForSpriteScaling:ivb
580 * IVB SPR_SCALE/Scaling Enable
581 * "Low Power watermarks must be disabled for at least one
582 * frame before enabling sprite scaling, and kept disabled
583 * until sprite scaling is disabled."
584 *
585 * ILK/SNB DVSASCALE/Scaling Enable
586 * "When in Self Refresh Big FIFO mode, scaling enable will be
587 * masked off while Big FIFO mode is exiting."
588 *
589 * Despite the w/a only being listed for IVB we assume that
590 * the ILK/SNB note has similar ramifications, hence we apply
591 * the w/a on all three platforms.
592 */
593 return !intel_plane_is_scaled(old_plane_state) &&
594 intel_plane_is_scaled(new_plane_state);
595 }
596
intel_plane_atomic_calc_changes(const struct intel_crtc_state * old_crtc_state,struct intel_crtc_state * new_crtc_state,const struct intel_plane_state * old_plane_state,struct intel_plane_state * new_plane_state)597 static int intel_plane_atomic_calc_changes(const struct intel_crtc_state *old_crtc_state,
598 struct intel_crtc_state *new_crtc_state,
599 const struct intel_plane_state *old_plane_state,
600 struct intel_plane_state *new_plane_state)
601 {
602 struct intel_display *display = to_intel_display(new_crtc_state);
603 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
604 struct intel_plane *plane = to_intel_plane(new_plane_state->uapi.plane);
605 bool mode_changed = intel_crtc_needs_modeset(new_crtc_state);
606 bool was_crtc_enabled = old_crtc_state->hw.active;
607 bool is_crtc_enabled = new_crtc_state->hw.active;
608 bool turn_off, turn_on, visible, was_visible;
609 int ret;
610
611 if (DISPLAY_VER(display) >= 9 && plane->id != PLANE_CURSOR) {
612 ret = skl_update_scaler_plane(new_crtc_state, new_plane_state);
613 if (ret)
614 return ret;
615 }
616
617 was_visible = old_plane_state->uapi.visible;
618 visible = new_plane_state->uapi.visible;
619
620 if (!was_crtc_enabled && drm_WARN_ON(display->drm, was_visible))
621 was_visible = false;
622
623 /*
624 * Visibility is calculated as if the crtc was on, but
625 * after scaler setup everything depends on it being off
626 * when the crtc isn't active.
627 *
628 * FIXME this is wrong for watermarks. Watermarks should also
629 * be computed as if the pipe would be active. Perhaps move
630 * per-plane wm computation to the .check_plane() hook, and
631 * only combine the results from all planes in the current place?
632 */
633 if (!is_crtc_enabled) {
634 intel_plane_set_invisible(new_crtc_state, new_plane_state);
635 visible = false;
636 }
637
638 if (!was_visible && !visible)
639 return 0;
640
641 turn_off = was_visible && (!visible || mode_changed);
642 turn_on = visible && (!was_visible || mode_changed);
643
644 drm_dbg_atomic(display->drm,
645 "[CRTC:%d:%s] with [PLANE:%d:%s] visible %i -> %i, off %i, on %i, ms %i\n",
646 crtc->base.base.id, crtc->base.name,
647 plane->base.base.id, plane->base.name,
648 was_visible, visible,
649 turn_off, turn_on, mode_changed);
650
651 if (visible || was_visible)
652 new_crtc_state->fb_bits |= plane->frontbuffer_bit;
653
654 if (HAS_GMCH(display) &&
655 i9xx_must_disable_cxsr(new_crtc_state, old_plane_state, new_plane_state))
656 new_crtc_state->disable_cxsr = true;
657
658 if ((display->platform.ironlake || display->platform.sandybridge || display->platform.ivybridge) &&
659 ilk_must_disable_cxsr(new_crtc_state, old_plane_state, new_plane_state))
660 new_crtc_state->disable_cxsr = true;
661
662 if (intel_plane_do_async_flip(plane, old_crtc_state, new_crtc_state))
663 new_crtc_state->do_async_flip = true;
664
665 if (new_crtc_state->uapi.async_flip) {
666 /*
667 * On platforms with double buffered async flip bit we
668 * set the bit already one frame early during the sync
669 * flip (see {i9xx,skl}_plane_update_arm()). The
670 * hardware will therefore be ready to perform a real
671 * async flip during the next commit, without having
672 * to wait yet another frame for the bit to latch.
673 *
674 * async_flip_planes bitmask is also used by selective
675 * fetch calculation to choose full frame update.
676 */
677 new_crtc_state->async_flip_planes |= BIT(plane->id);
678 }
679
680 return 0;
681 }
682
intel_plane_atomic_check_with_state(const struct intel_crtc_state * old_crtc_state,struct intel_crtc_state * new_crtc_state,const struct intel_plane_state * old_plane_state,struct intel_plane_state * new_plane_state)683 int intel_plane_atomic_check_with_state(const struct intel_crtc_state *old_crtc_state,
684 struct intel_crtc_state *new_crtc_state,
685 const struct intel_plane_state *old_plane_state,
686 struct intel_plane_state *new_plane_state)
687 {
688 struct intel_plane *plane = to_intel_plane(new_plane_state->uapi.plane);
689 const struct drm_framebuffer *fb = new_plane_state->hw.fb;
690 int ret;
691
692 intel_plane_set_invisible(new_crtc_state, new_plane_state);
693 new_crtc_state->enabled_planes &= ~BIT(plane->id);
694
695 if (!new_plane_state->hw.crtc && !old_plane_state->hw.crtc)
696 return 0;
697
698 ret = plane->check_plane(new_crtc_state, new_plane_state);
699 if (ret)
700 return ret;
701
702 if (fb)
703 new_crtc_state->enabled_planes |= BIT(plane->id);
704
705 /* FIXME pre-g4x don't work like this */
706 if (new_plane_state->uapi.visible)
707 new_crtc_state->active_planes |= BIT(plane->id);
708
709 if (new_plane_state->uapi.visible &&
710 intel_plane_is_scaled(new_plane_state))
711 new_crtc_state->scaled_planes |= BIT(plane->id);
712
713 if (new_plane_state->uapi.visible &&
714 intel_format_info_is_yuv_semiplanar(fb->format, fb->modifier))
715 new_crtc_state->nv12_planes |= BIT(plane->id);
716
717 if (new_plane_state->uapi.visible &&
718 fb->format->format == DRM_FORMAT_C8)
719 new_crtc_state->c8_planes |= BIT(plane->id);
720
721 if (new_plane_state->uapi.visible || old_plane_state->uapi.visible)
722 new_crtc_state->update_planes |= BIT(plane->id);
723
724 if (new_plane_state->uapi.visible &&
725 intel_format_info_is_yuv_semiplanar(fb->format, fb->modifier)) {
726 new_crtc_state->data_rate_y[plane->id] =
727 intel_plane_data_rate(new_crtc_state, new_plane_state, 0);
728 new_crtc_state->data_rate[plane->id] =
729 intel_plane_data_rate(new_crtc_state, new_plane_state, 1);
730
731 new_crtc_state->rel_data_rate_y[plane->id] =
732 intel_plane_relative_data_rate(new_crtc_state,
733 new_plane_state, 0);
734 new_crtc_state->rel_data_rate[plane->id] =
735 intel_plane_relative_data_rate(new_crtc_state,
736 new_plane_state, 1);
737 } else if (new_plane_state->uapi.visible) {
738 new_crtc_state->data_rate[plane->id] =
739 intel_plane_data_rate(new_crtc_state, new_plane_state, 0);
740
741 new_crtc_state->rel_data_rate[plane->id] =
742 intel_plane_relative_data_rate(new_crtc_state,
743 new_plane_state, 0);
744 }
745
746 return intel_plane_atomic_calc_changes(old_crtc_state, new_crtc_state,
747 old_plane_state, new_plane_state);
748 }
749
750 struct intel_plane *
intel_crtc_get_plane(struct intel_crtc * crtc,enum plane_id plane_id)751 intel_crtc_get_plane(struct intel_crtc *crtc, enum plane_id plane_id)
752 {
753 struct intel_display *display = to_intel_display(crtc);
754 struct intel_plane *plane;
755
756 for_each_intel_plane_on_crtc(display->drm, crtc, plane) {
757 if (plane->id == plane_id)
758 return plane;
759 }
760
761 return NULL;
762 }
763
plane_atomic_check(struct intel_atomic_state * state,struct intel_plane * plane)764 static int plane_atomic_check(struct intel_atomic_state *state,
765 struct intel_plane *plane)
766 {
767 struct intel_display *display = to_intel_display(state);
768 struct intel_plane_state *new_plane_state =
769 intel_atomic_get_new_plane_state(state, plane);
770 const struct intel_plane_state *old_plane_state =
771 intel_atomic_get_old_plane_state(state, plane);
772 const struct intel_plane_state *new_primary_crtc_plane_state;
773 const struct intel_plane_state *old_primary_crtc_plane_state;
774 struct intel_crtc *crtc = intel_crtc_for_pipe(display, plane->pipe);
775 const struct intel_crtc_state *old_crtc_state =
776 intel_atomic_get_old_crtc_state(state, crtc);
777 struct intel_crtc_state *new_crtc_state =
778 intel_atomic_get_new_crtc_state(state, crtc);
779
780 if (new_crtc_state && intel_crtc_is_joiner_secondary(new_crtc_state)) {
781 struct intel_crtc *primary_crtc =
782 intel_primary_crtc(new_crtc_state);
783 struct intel_plane *primary_crtc_plane =
784 intel_crtc_get_plane(primary_crtc, plane->id);
785
786 new_primary_crtc_plane_state =
787 intel_atomic_get_new_plane_state(state, primary_crtc_plane);
788 old_primary_crtc_plane_state =
789 intel_atomic_get_old_plane_state(state, primary_crtc_plane);
790 } else {
791 new_primary_crtc_plane_state = new_plane_state;
792 old_primary_crtc_plane_state = old_plane_state;
793 }
794
795 intel_plane_copy_uapi_plane_damage(new_plane_state,
796 old_primary_crtc_plane_state,
797 new_primary_crtc_plane_state);
798
799 intel_plane_copy_uapi_to_hw_state(new_plane_state,
800 new_primary_crtc_plane_state,
801 crtc);
802
803 new_plane_state->uapi.visible = false;
804 if (!new_crtc_state)
805 return 0;
806
807 return intel_plane_atomic_check_with_state(old_crtc_state,
808 new_crtc_state,
809 old_plane_state,
810 new_plane_state);
811 }
812
813 static struct intel_plane *
skl_next_plane_to_commit(struct intel_atomic_state * state,struct intel_crtc * crtc,struct skl_ddb_entry ddb[I915_MAX_PLANES],struct skl_ddb_entry ddb_y[I915_MAX_PLANES],unsigned int * update_mask)814 skl_next_plane_to_commit(struct intel_atomic_state *state,
815 struct intel_crtc *crtc,
816 struct skl_ddb_entry ddb[I915_MAX_PLANES],
817 struct skl_ddb_entry ddb_y[I915_MAX_PLANES],
818 unsigned int *update_mask)
819 {
820 struct intel_crtc_state *crtc_state =
821 intel_atomic_get_new_crtc_state(state, crtc);
822 struct intel_plane_state __maybe_unused *plane_state;
823 struct intel_plane *plane;
824 int i;
825
826 if (*update_mask == 0)
827 return NULL;
828
829 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
830 enum plane_id plane_id = plane->id;
831
832 if (crtc->pipe != plane->pipe ||
833 !(*update_mask & BIT(plane_id)))
834 continue;
835
836 if (skl_ddb_allocation_overlaps(&crtc_state->wm.skl.plane_ddb[plane_id],
837 ddb, I915_MAX_PLANES, plane_id) ||
838 skl_ddb_allocation_overlaps(&crtc_state->wm.skl.plane_ddb_y[plane_id],
839 ddb_y, I915_MAX_PLANES, plane_id))
840 continue;
841
842 *update_mask &= ~BIT(plane_id);
843 ddb[plane_id] = crtc_state->wm.skl.plane_ddb[plane_id];
844 ddb_y[plane_id] = crtc_state->wm.skl.plane_ddb_y[plane_id];
845
846 return plane;
847 }
848
849 /* should never happen */
850 drm_WARN_ON(state->base.dev, 1);
851
852 return NULL;
853 }
854
intel_plane_update_noarm(struct intel_dsb * dsb,struct intel_plane * plane,const struct intel_crtc_state * crtc_state,const struct intel_plane_state * plane_state)855 void intel_plane_update_noarm(struct intel_dsb *dsb,
856 struct intel_plane *plane,
857 const struct intel_crtc_state *crtc_state,
858 const struct intel_plane_state *plane_state)
859 {
860 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
861
862 trace_intel_plane_update_noarm(plane_state, crtc);
863
864 if (plane->fbc)
865 intel_fbc_dirty_rect_update_noarm(dsb, plane);
866
867 if (plane->update_noarm)
868 plane->update_noarm(dsb, plane, crtc_state, plane_state);
869 }
870
intel_plane_async_flip(struct intel_dsb * dsb,struct intel_plane * plane,const struct intel_crtc_state * crtc_state,const struct intel_plane_state * plane_state,bool async_flip)871 void intel_plane_async_flip(struct intel_dsb *dsb,
872 struct intel_plane *plane,
873 const struct intel_crtc_state *crtc_state,
874 const struct intel_plane_state *plane_state,
875 bool async_flip)
876 {
877 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
878
879 trace_intel_plane_async_flip(plane, crtc, async_flip);
880 plane->async_flip(dsb, plane, crtc_state, plane_state, async_flip);
881 }
882
intel_plane_update_arm(struct intel_dsb * dsb,struct intel_plane * plane,const struct intel_crtc_state * crtc_state,const struct intel_plane_state * plane_state)883 void intel_plane_update_arm(struct intel_dsb *dsb,
884 struct intel_plane *plane,
885 const struct intel_crtc_state *crtc_state,
886 const struct intel_plane_state *plane_state)
887 {
888 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
889
890 if (crtc_state->do_async_flip && plane->async_flip) {
891 intel_plane_async_flip(dsb, plane, crtc_state, plane_state, true);
892 return;
893 }
894
895 trace_intel_plane_update_arm(plane_state, crtc);
896 plane->update_arm(dsb, plane, crtc_state, plane_state);
897 }
898
intel_plane_disable_arm(struct intel_dsb * dsb,struct intel_plane * plane,const struct intel_crtc_state * crtc_state)899 void intel_plane_disable_arm(struct intel_dsb *dsb,
900 struct intel_plane *plane,
901 const struct intel_crtc_state *crtc_state)
902 {
903 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
904
905 trace_intel_plane_disable_arm(plane, crtc);
906 plane->disable_arm(dsb, plane, crtc_state);
907 }
908
intel_crtc_planes_update_noarm(struct intel_dsb * dsb,struct intel_atomic_state * state,struct intel_crtc * crtc)909 void intel_crtc_planes_update_noarm(struct intel_dsb *dsb,
910 struct intel_atomic_state *state,
911 struct intel_crtc *crtc)
912 {
913 struct intel_crtc_state *new_crtc_state =
914 intel_atomic_get_new_crtc_state(state, crtc);
915 u32 update_mask = new_crtc_state->update_planes;
916 struct intel_plane_state *new_plane_state;
917 struct intel_plane *plane;
918 int i;
919
920 if (new_crtc_state->do_async_flip)
921 return;
922
923 /*
924 * Since we only write non-arming registers here,
925 * the order does not matter even for skl+.
926 */
927 for_each_new_intel_plane_in_state(state, plane, new_plane_state, i) {
928 if (crtc->pipe != plane->pipe ||
929 !(update_mask & BIT(plane->id)))
930 continue;
931
932 /* TODO: for mailbox updates this should be skipped */
933 if (new_plane_state->uapi.visible ||
934 new_plane_state->is_y_plane)
935 intel_plane_update_noarm(dsb, plane,
936 new_crtc_state, new_plane_state);
937 }
938 }
939
skl_crtc_planes_update_arm(struct intel_dsb * dsb,struct intel_atomic_state * state,struct intel_crtc * crtc)940 static void skl_crtc_planes_update_arm(struct intel_dsb *dsb,
941 struct intel_atomic_state *state,
942 struct intel_crtc *crtc)
943 {
944 struct intel_crtc_state *old_crtc_state =
945 intel_atomic_get_old_crtc_state(state, crtc);
946 struct intel_crtc_state *new_crtc_state =
947 intel_atomic_get_new_crtc_state(state, crtc);
948 struct skl_ddb_entry ddb[I915_MAX_PLANES];
949 struct skl_ddb_entry ddb_y[I915_MAX_PLANES];
950 u32 update_mask = new_crtc_state->update_planes;
951 struct intel_plane *plane;
952
953 memcpy(ddb, old_crtc_state->wm.skl.plane_ddb,
954 sizeof(old_crtc_state->wm.skl.plane_ddb));
955 memcpy(ddb_y, old_crtc_state->wm.skl.plane_ddb_y,
956 sizeof(old_crtc_state->wm.skl.plane_ddb_y));
957
958 while ((plane = skl_next_plane_to_commit(state, crtc, ddb, ddb_y, &update_mask))) {
959 struct intel_plane_state *new_plane_state =
960 intel_atomic_get_new_plane_state(state, plane);
961
962 /*
963 * TODO: for mailbox updates intel_plane_update_noarm()
964 * would have to be called here as well.
965 */
966 if (new_plane_state->uapi.visible ||
967 new_plane_state->is_y_plane)
968 intel_plane_update_arm(dsb, plane, new_crtc_state, new_plane_state);
969 else
970 intel_plane_disable_arm(dsb, plane, new_crtc_state);
971 }
972 }
973
i9xx_crtc_planes_update_arm(struct intel_dsb * dsb,struct intel_atomic_state * state,struct intel_crtc * crtc)974 static void i9xx_crtc_planes_update_arm(struct intel_dsb *dsb,
975 struct intel_atomic_state *state,
976 struct intel_crtc *crtc)
977 {
978 struct intel_crtc_state *new_crtc_state =
979 intel_atomic_get_new_crtc_state(state, crtc);
980 u32 update_mask = new_crtc_state->update_planes;
981 struct intel_plane_state *new_plane_state;
982 struct intel_plane *plane;
983 int i;
984
985 for_each_new_intel_plane_in_state(state, plane, new_plane_state, i) {
986 if (crtc->pipe != plane->pipe ||
987 !(update_mask & BIT(plane->id)))
988 continue;
989
990 /*
991 * TODO: for mailbox updates intel_plane_update_noarm()
992 * would have to be called here as well.
993 */
994 if (new_plane_state->uapi.visible)
995 intel_plane_update_arm(dsb, plane, new_crtc_state, new_plane_state);
996 else
997 intel_plane_disable_arm(dsb, plane, new_crtc_state);
998 }
999 }
1000
intel_crtc_planes_update_arm(struct intel_dsb * dsb,struct intel_atomic_state * state,struct intel_crtc * crtc)1001 void intel_crtc_planes_update_arm(struct intel_dsb *dsb,
1002 struct intel_atomic_state *state,
1003 struct intel_crtc *crtc)
1004 {
1005 struct intel_display *display = to_intel_display(state);
1006
1007 if (DISPLAY_VER(display) >= 9)
1008 skl_crtc_planes_update_arm(dsb, state, crtc);
1009 else
1010 i9xx_crtc_planes_update_arm(dsb, state, crtc);
1011 }
1012
intel_plane_check_clipping(struct intel_plane_state * plane_state,struct intel_crtc_state * crtc_state,int min_scale,int max_scale,bool can_position)1013 int intel_plane_check_clipping(struct intel_plane_state *plane_state,
1014 struct intel_crtc_state *crtc_state,
1015 int min_scale, int max_scale,
1016 bool can_position)
1017 {
1018 struct intel_display *display = to_intel_display(plane_state);
1019 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
1020 struct drm_framebuffer *fb = plane_state->hw.fb;
1021 struct drm_rect *src = &plane_state->uapi.src;
1022 struct drm_rect *dst = &plane_state->uapi.dst;
1023 const struct drm_rect *clip = &crtc_state->pipe_src;
1024 unsigned int rotation = plane_state->hw.rotation;
1025 int hscale, vscale;
1026
1027 if (!fb) {
1028 plane_state->uapi.visible = false;
1029 return 0;
1030 }
1031
1032 drm_rect_rotate(src, fb->width << 16, fb->height << 16, rotation);
1033
1034 /* Check scaling */
1035 hscale = drm_rect_calc_hscale(src, dst, min_scale, max_scale);
1036 vscale = drm_rect_calc_vscale(src, dst, min_scale, max_scale);
1037 if (hscale < 0 || vscale < 0) {
1038 drm_dbg_kms(display->drm,
1039 "[PLANE:%d:%s] invalid scaling "DRM_RECT_FP_FMT " -> " DRM_RECT_FMT "\n",
1040 plane->base.base.id, plane->base.name,
1041 DRM_RECT_FP_ARG(src), DRM_RECT_ARG(dst));
1042 return -ERANGE;
1043 }
1044
1045 /*
1046 * FIXME: This might need further adjustment for seamless scaling
1047 * with phase information, for the 2p2 and 2p1 scenarios.
1048 */
1049 plane_state->uapi.visible = drm_rect_clip_scaled(src, dst, clip);
1050
1051 drm_rect_rotate_inv(src, fb->width << 16, fb->height << 16, rotation);
1052
1053 if (!can_position && plane_state->uapi.visible &&
1054 !drm_rect_equals(dst, clip)) {
1055 drm_dbg_kms(display->drm,
1056 "[PLANE:%d:%s] plane (" DRM_RECT_FMT ") must cover entire CRTC (" DRM_RECT_FMT ")\n",
1057 plane->base.base.id, plane->base.name,
1058 DRM_RECT_ARG(dst), DRM_RECT_ARG(clip));
1059 return -EINVAL;
1060 }
1061
1062 /* final plane coordinates will be relative to the plane's pipe */
1063 drm_rect_translate(dst, -clip->x1, -clip->y1);
1064
1065 return 0;
1066 }
1067
intel_plane_check_src_coordinates(struct intel_plane_state * plane_state)1068 int intel_plane_check_src_coordinates(struct intel_plane_state *plane_state)
1069 {
1070 struct intel_display *display = to_intel_display(plane_state);
1071 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
1072 const struct drm_framebuffer *fb = plane_state->hw.fb;
1073 struct drm_rect *src = &plane_state->uapi.src;
1074 u32 src_x, src_y, src_w, src_h, hsub, vsub;
1075 bool rotated = drm_rotation_90_or_270(plane_state->hw.rotation);
1076
1077 /*
1078 * FIXME hsub/vsub vs. block size is a mess. Pre-tgl CCS
1079 * abuses hsub/vsub so we can't use them here. But as they
1080 * are limited to 32bpp RGB formats we don't actually need
1081 * to check anything.
1082 */
1083 if (fb->modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
1084 fb->modifier == I915_FORMAT_MOD_Yf_TILED_CCS)
1085 return 0;
1086
1087 /*
1088 * Hardware doesn't handle subpixel coordinates.
1089 * Adjust to (macro)pixel boundary, but be careful not to
1090 * increase the source viewport size, because that could
1091 * push the downscaling factor out of bounds.
1092 */
1093 src_x = src->x1 >> 16;
1094 src_w = drm_rect_width(src) >> 16;
1095 src_y = src->y1 >> 16;
1096 src_h = drm_rect_height(src) >> 16;
1097
1098 drm_rect_init(src, src_x << 16, src_y << 16,
1099 src_w << 16, src_h << 16);
1100
1101 if (fb->format->format == DRM_FORMAT_RGB565 && rotated) {
1102 hsub = 2;
1103 vsub = 2;
1104 } else if (DISPLAY_VER(display) >= 20 &&
1105 intel_format_info_is_yuv_semiplanar(fb->format, fb->modifier)) {
1106 /*
1107 * This allows NV12 and P0xx formats to have odd size and/or odd
1108 * source coordinates on DISPLAY_VER(display) >= 20
1109 */
1110 hsub = 1;
1111 vsub = 1;
1112
1113 /* Wa_16023981245 */
1114 if ((DISPLAY_VERx100(display) == 2000 ||
1115 DISPLAY_VERx100(display) == 3000 ||
1116 DISPLAY_VERx100(display) == 3002) &&
1117 src_x % 2 != 0)
1118 hsub = 2;
1119
1120 if (DISPLAY_VER(display) == 35)
1121 vsub = 2;
1122 } else {
1123 hsub = fb->format->hsub;
1124 vsub = fb->format->vsub;
1125 }
1126
1127 if (rotated)
1128 hsub = vsub = max(hsub, vsub);
1129
1130 if (src_x % hsub || src_w % hsub) {
1131 drm_dbg_kms(display->drm,
1132 "[PLANE:%d:%s] src x/w (%u, %u) must be a multiple of %u (rotated: %s)\n",
1133 plane->base.base.id, plane->base.name,
1134 src_x, src_w, hsub, str_yes_no(rotated));
1135 return -EINVAL;
1136 }
1137
1138 if (src_y % vsub || src_h % vsub) {
1139 drm_dbg_kms(display->drm,
1140 "[PLANE:%d:%s] src y/h (%u, %u) must be a multiple of %u (rotated: %s)\n",
1141 plane->base.base.id, plane->base.name,
1142 src_y, src_h, vsub, str_yes_no(rotated));
1143 return -EINVAL;
1144 }
1145
1146 return 0;
1147 }
1148
add_dma_resv_fences(struct dma_resv * resv,struct drm_plane_state * new_plane_state)1149 static int add_dma_resv_fences(struct dma_resv *resv,
1150 struct drm_plane_state *new_plane_state)
1151 {
1152 struct dma_fence *fence = dma_fence_get(new_plane_state->fence);
1153 struct dma_fence *new;
1154 int ret;
1155
1156 ret = dma_resv_get_singleton(resv, dma_resv_usage_rw(false), &new);
1157 if (ret)
1158 goto error;
1159
1160 if (new && fence) {
1161 struct dma_fence_chain *chain = dma_fence_chain_alloc();
1162
1163 if (!chain) {
1164 ret = -ENOMEM;
1165 goto error;
1166 }
1167
1168 dma_fence_chain_init(chain, fence, new, 1);
1169 fence = &chain->base;
1170
1171 } else if (new) {
1172 fence = new;
1173 }
1174
1175 dma_fence_put(new_plane_state->fence);
1176 new_plane_state->fence = fence;
1177 return 0;
1178
1179 error:
1180 dma_fence_put(fence);
1181 return ret;
1182 }
1183
1184 /**
1185 * intel_prepare_plane_fb - Prepare fb for usage on plane
1186 * @_plane: drm plane to prepare for
1187 * @_new_plane_state: the plane state being prepared
1188 *
1189 * Prepares a framebuffer for usage on a display plane. Generally this
1190 * involves pinning the underlying object and updating the frontbuffer tracking
1191 * bits. Some older platforms need special physical address handling for
1192 * cursor planes.
1193 *
1194 * Returns 0 on success, negative error code on failure.
1195 */
1196 static int
intel_prepare_plane_fb(struct drm_plane * _plane,struct drm_plane_state * _new_plane_state)1197 intel_prepare_plane_fb(struct drm_plane *_plane,
1198 struct drm_plane_state *_new_plane_state)
1199 {
1200 struct intel_plane *plane = to_intel_plane(_plane);
1201 struct intel_display *display = to_intel_display(plane);
1202 struct intel_plane_state *new_plane_state =
1203 to_intel_plane_state(_new_plane_state);
1204 struct intel_atomic_state *state =
1205 to_intel_atomic_state(new_plane_state->uapi.state);
1206 struct intel_plane_state *old_plane_state =
1207 intel_atomic_get_old_plane_state(state, plane);
1208 struct drm_gem_object *obj = intel_fb_bo(new_plane_state->hw.fb);
1209 struct drm_gem_object *old_obj = intel_fb_bo(old_plane_state->hw.fb);
1210 int ret;
1211
1212 if (old_obj) {
1213 const struct intel_crtc_state *new_crtc_state =
1214 intel_atomic_get_new_crtc_state(state,
1215 to_intel_crtc(old_plane_state->hw.crtc));
1216
1217 /* Big Hammer, we also need to ensure that any pending
1218 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
1219 * current scanout is retired before unpinning the old
1220 * framebuffer. Note that we rely on userspace rendering
1221 * into the buffer attached to the pipe they are waiting
1222 * on. If not, userspace generates a GPU hang with IPEHR
1223 * point to the MI_WAIT_FOR_EVENT.
1224 *
1225 * This should only fail upon a hung GPU, in which case we
1226 * can safely continue.
1227 */
1228 if (intel_crtc_needs_modeset(new_crtc_state)) {
1229 ret = add_dma_resv_fences(old_obj->resv,
1230 &new_plane_state->uapi);
1231 if (ret < 0)
1232 return ret;
1233 }
1234 }
1235
1236 if (!obj)
1237 return 0;
1238
1239 ret = intel_plane_pin_fb(new_plane_state, old_plane_state);
1240 if (ret)
1241 return ret;
1242
1243 ret = drm_gem_plane_helper_prepare_fb(&plane->base, &new_plane_state->uapi);
1244 if (ret < 0)
1245 goto unpin_fb;
1246
1247 if (new_plane_state->uapi.fence) {
1248 intel_parent_fence_priority_display(display, new_plane_state->uapi.fence);
1249 intel_display_rps_boost_after_vblank(new_plane_state->hw.crtc,
1250 new_plane_state->uapi.fence);
1251 }
1252
1253 /*
1254 * We declare pageflips to be interactive and so merit a small bias
1255 * towards upclocking to deliver the frame on time. By only changing
1256 * the RPS thresholds to sample more regularly and aim for higher
1257 * clocks we can hopefully deliver low power workloads (like kodi)
1258 * that are not quite steady state without resorting to forcing
1259 * maximum clocks following a vblank miss (see do_rps_boost()).
1260 */
1261 intel_display_rps_mark_interactive(display, state, true);
1262
1263 return 0;
1264
1265 unpin_fb:
1266 intel_plane_unpin_fb(new_plane_state);
1267
1268 return ret;
1269 }
1270
1271 /**
1272 * intel_cleanup_plane_fb - Cleans up an fb after plane use
1273 * @plane: drm plane to clean up for
1274 * @_old_plane_state: the state from the previous modeset
1275 *
1276 * Cleans up a framebuffer that has just been removed from a plane.
1277 */
1278 static void
intel_cleanup_plane_fb(struct drm_plane * plane,struct drm_plane_state * _old_plane_state)1279 intel_cleanup_plane_fb(struct drm_plane *plane,
1280 struct drm_plane_state *_old_plane_state)
1281 {
1282 struct intel_display *display = to_intel_display(plane->dev);
1283 struct intel_plane_state *old_plane_state =
1284 to_intel_plane_state(_old_plane_state);
1285 struct intel_atomic_state *state =
1286 to_intel_atomic_state(old_plane_state->uapi.state);
1287 struct drm_gem_object *obj = intel_fb_bo(old_plane_state->hw.fb);
1288
1289 if (!obj)
1290 return;
1291
1292 intel_display_rps_mark_interactive(display, state, false);
1293
1294 intel_plane_unpin_fb(old_plane_state);
1295 }
1296
1297 /* Handle Y-tiling, only if DPT is enabled (otherwise disabling tiling is easier)
1298 * All DPT hardware have 128-bytes width tiling, so Y-tile dimension is 32x32
1299 * pixels for 32bits pixels.
1300 */
1301 #define YTILE_WIDTH 32
1302 #define YTILE_HEIGHT 32
1303 #define YTILE_SIZE (YTILE_WIDTH * YTILE_HEIGHT * 4)
1304
intel_ytile_get_offset(unsigned int width,unsigned int x,unsigned int y)1305 static unsigned int intel_ytile_get_offset(unsigned int width, unsigned int x, unsigned int y)
1306 {
1307 u32 offset;
1308 unsigned int swizzle;
1309 unsigned int width_in_blocks = DIV_ROUND_UP(width, 32);
1310
1311 /* Block offset */
1312 offset = ((y / YTILE_HEIGHT) * width_in_blocks + (x / YTILE_WIDTH)) * YTILE_SIZE;
1313
1314 x = x % YTILE_WIDTH;
1315 y = y % YTILE_HEIGHT;
1316
1317 /* bit order inside a block is x4 x3 x2 y4 y3 y2 y1 y0 x1 x0 */
1318 swizzle = (x & 3) | ((y & 0x1f) << 2) | ((x & 0x1c) << 5);
1319 offset += swizzle * 4;
1320 return offset;
1321 }
1322
intel_4tile_get_offset(unsigned int width,unsigned int x,unsigned int y)1323 static unsigned int intel_4tile_get_offset(unsigned int width, unsigned int x, unsigned int y)
1324 {
1325 u32 offset;
1326 unsigned int swizzle;
1327 unsigned int width_in_blocks = DIV_ROUND_UP(width, 32);
1328
1329 /* Block offset */
1330 offset = ((y / YTILE_HEIGHT) * width_in_blocks + (x / YTILE_WIDTH)) * YTILE_SIZE;
1331
1332 x = x % YTILE_WIDTH;
1333 y = y % YTILE_HEIGHT;
1334
1335 /* bit order inside a block is y4 y3 x4 y2 x3 x2 y1 y0 x1 x0 */
1336 swizzle = (x & 3) | ((y & 3) << 2) | ((x & 0xc) << 2) | (y & 4) << 4 |
1337 ((x & 0x10) << 3) | ((y & 0x18) << 5);
1338 offset += swizzle * 4;
1339 return offset;
1340 }
1341
intel_panic_flush(struct drm_plane * _plane)1342 static void intel_panic_flush(struct drm_plane *_plane)
1343 {
1344 struct intel_plane *plane = to_intel_plane(_plane);
1345 struct intel_display *display = to_intel_display(plane);
1346 const struct intel_plane_state *plane_state = to_intel_plane_state(plane->base.state);
1347 struct intel_crtc *crtc = to_intel_crtc(plane_state->hw.crtc);
1348 const struct intel_crtc_state *crtc_state = to_intel_crtc_state(crtc->base.state);
1349 const struct intel_framebuffer *fb = to_intel_framebuffer(plane_state->hw.fb);
1350
1351 intel_parent_panic_finish(display, fb->panic);
1352
1353 if (crtc_state->enable_psr2_sel_fetch) {
1354 /* Force a full update for psr2 */
1355 intel_psr2_panic_force_full_update(crtc_state);
1356 }
1357
1358 /* Flush the cache and don't disable tiling if it's the fbdev framebuffer.*/
1359 if (fb == intel_fbdev_framebuffer(display->fbdev.fbdev)) {
1360 struct iosys_map map;
1361
1362 intel_fbdev_get_map(display->fbdev.fbdev, &map);
1363 drm_clflush_virt_range(map.vaddr, fb->base.pitches[0] * fb->base.height);
1364 return;
1365 }
1366
1367 if (fb->base.modifier != DRM_FORMAT_MOD_LINEAR && plane->disable_tiling)
1368 plane->disable_tiling(plane);
1369 }
1370
intel_get_tiling_func(u64 fb_modifier)1371 static unsigned int (*intel_get_tiling_func(u64 fb_modifier))(unsigned int width,
1372 unsigned int x,
1373 unsigned int y)
1374 {
1375 switch (fb_modifier) {
1376 case I915_FORMAT_MOD_Y_TILED:
1377 case I915_FORMAT_MOD_Y_TILED_CCS:
1378 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS_CC:
1379 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
1380 case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS:
1381 return intel_ytile_get_offset;
1382 case I915_FORMAT_MOD_4_TILED:
1383 case I915_FORMAT_MOD_4_TILED_DG2_RC_CCS:
1384 case I915_FORMAT_MOD_4_TILED_DG2_MC_CCS:
1385 case I915_FORMAT_MOD_4_TILED_DG2_RC_CCS_CC:
1386 case I915_FORMAT_MOD_4_TILED_MTL_RC_CCS:
1387 case I915_FORMAT_MOD_4_TILED_MTL_RC_CCS_CC:
1388 case I915_FORMAT_MOD_4_TILED_MTL_MC_CCS:
1389 case I915_FORMAT_MOD_4_TILED_BMG_CCS:
1390 case I915_FORMAT_MOD_4_TILED_LNL_CCS:
1391 return intel_4tile_get_offset;
1392 case I915_FORMAT_MOD_X_TILED:
1393 case I915_FORMAT_MOD_Yf_TILED:
1394 case I915_FORMAT_MOD_Yf_TILED_CCS:
1395 default:
1396 /* Not supported yet */
1397 return NULL;
1398 }
1399 }
1400
intel_get_scanout_buffer(struct drm_plane * plane,struct drm_scanout_buffer * sb)1401 static int intel_get_scanout_buffer(struct drm_plane *plane,
1402 struct drm_scanout_buffer *sb)
1403 {
1404 struct intel_plane_state *plane_state;
1405 struct drm_gem_object *obj;
1406 struct intel_framebuffer *fb;
1407 struct intel_display *display = to_intel_display(plane->dev);
1408
1409 if (!plane->state || !plane->state->fb || !plane->state->visible)
1410 return -ENODEV;
1411
1412 plane_state = to_intel_plane_state(plane->state);
1413 fb = to_intel_framebuffer(plane_state->hw.fb);
1414
1415 obj = intel_fb_bo(&fb->base);
1416 if (!obj)
1417 return -ENODEV;
1418
1419 if (fb == intel_fbdev_framebuffer(display->fbdev.fbdev)) {
1420 intel_fbdev_get_map(display->fbdev.fbdev, &sb->map[0]);
1421 } else {
1422 int ret;
1423 /* Can't disable tiling if DPT is in use */
1424 if (intel_fb_uses_dpt(&fb->base)) {
1425 if (fb->base.format->cpp[0] != 4)
1426 return -EOPNOTSUPP;
1427 fb->panic_tiling = intel_get_tiling_func(fb->base.modifier);
1428 if (!fb->panic_tiling)
1429 return -EOPNOTSUPP;
1430 }
1431 sb->private = fb;
1432 ret = intel_parent_panic_setup(display, fb->panic, sb);
1433 if (ret)
1434 return ret;
1435 }
1436 sb->width = fb->base.width;
1437 sb->height = fb->base.height;
1438 /* Use the generic linear format, because tiling, RC, CCS, CC
1439 * will be disabled in disable_tiling()
1440 */
1441 sb->format = drm_format_info(fb->base.format->format);
1442 sb->pitch[0] = fb->base.pitches[0];
1443
1444 return 0;
1445 }
1446
1447 static const struct drm_plane_helper_funcs intel_plane_helper_funcs = {
1448 .prepare_fb = intel_prepare_plane_fb,
1449 .cleanup_fb = intel_cleanup_plane_fb,
1450 };
1451
1452 static const struct drm_plane_helper_funcs intel_primary_plane_helper_funcs = {
1453 .prepare_fb = intel_prepare_plane_fb,
1454 .cleanup_fb = intel_cleanup_plane_fb,
1455 .get_scanout_buffer = intel_get_scanout_buffer,
1456 .panic_flush = intel_panic_flush,
1457 };
1458
intel_plane_helper_add(struct intel_plane * plane)1459 void intel_plane_helper_add(struct intel_plane *plane)
1460 {
1461 if (plane->base.type == DRM_PLANE_TYPE_PRIMARY)
1462 drm_plane_helper_add(&plane->base, &intel_primary_plane_helper_funcs);
1463 else
1464 drm_plane_helper_add(&plane->base, &intel_plane_helper_funcs);
1465 }
1466
intel_plane_init_cursor_vblank_work(struct intel_plane_state * old_plane_state,struct intel_plane_state * new_plane_state)1467 void intel_plane_init_cursor_vblank_work(struct intel_plane_state *old_plane_state,
1468 struct intel_plane_state *new_plane_state)
1469 {
1470 if (!old_plane_state->ggtt_vma ||
1471 old_plane_state->ggtt_vma == new_plane_state->ggtt_vma)
1472 return;
1473
1474 drm_vblank_work_init(&old_plane_state->unpin_work, old_plane_state->hw.crtc,
1475 intel_cursor_unpin_work);
1476 }
1477
link_nv12_planes(struct intel_crtc_state * crtc_state,struct intel_plane_state * uv_plane_state,struct intel_plane_state * y_plane_state)1478 static void link_nv12_planes(struct intel_crtc_state *crtc_state,
1479 struct intel_plane_state *uv_plane_state,
1480 struct intel_plane_state *y_plane_state)
1481 {
1482 struct intel_display *display = to_intel_display(uv_plane_state);
1483 struct intel_plane *uv_plane = to_intel_plane(uv_plane_state->uapi.plane);
1484 struct intel_plane *y_plane = to_intel_plane(y_plane_state->uapi.plane);
1485
1486 drm_dbg_kms(display->drm, "UV plane [PLANE:%d:%s] using Y plane [PLANE:%d:%s]\n",
1487 uv_plane->base.base.id, uv_plane->base.name,
1488 y_plane->base.base.id, y_plane->base.name);
1489
1490 uv_plane_state->planar_linked_plane = y_plane;
1491
1492 y_plane_state->is_y_plane = true;
1493 y_plane_state->planar_linked_plane = uv_plane;
1494
1495 crtc_state->enabled_planes |= BIT(y_plane->id);
1496 crtc_state->active_planes |= BIT(y_plane->id);
1497 crtc_state->update_planes |= BIT(y_plane->id);
1498
1499 crtc_state->data_rate[y_plane->id] = crtc_state->data_rate_y[uv_plane->id];
1500 crtc_state->rel_data_rate[y_plane->id] = crtc_state->rel_data_rate_y[uv_plane->id];
1501
1502 /* Copy parameters to Y plane */
1503 intel_plane_copy_hw_state(y_plane_state, uv_plane_state);
1504 y_plane_state->uapi.src = uv_plane_state->uapi.src;
1505 y_plane_state->uapi.dst = uv_plane_state->uapi.dst;
1506
1507 y_plane_state->ctl = uv_plane_state->ctl;
1508 y_plane_state->color_ctl = uv_plane_state->color_ctl;
1509 y_plane_state->view = uv_plane_state->view;
1510 y_plane_state->decrypt = uv_plane_state->decrypt;
1511
1512 icl_link_nv12_planes(uv_plane_state, y_plane_state);
1513 }
1514
unlink_nv12_plane(struct intel_crtc_state * crtc_state,struct intel_plane_state * plane_state)1515 static void unlink_nv12_plane(struct intel_crtc_state *crtc_state,
1516 struct intel_plane_state *plane_state)
1517 {
1518 struct intel_display *display = to_intel_display(plane_state);
1519 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
1520
1521 if (!plane_state->planar_linked_plane)
1522 return;
1523
1524 plane_state->planar_linked_plane = NULL;
1525
1526 if (!plane_state->is_y_plane)
1527 return;
1528
1529 drm_WARN_ON(display->drm, plane_state->uapi.visible);
1530
1531 plane_state->is_y_plane = false;
1532
1533 crtc_state->enabled_planes &= ~BIT(plane->id);
1534 crtc_state->active_planes &= ~BIT(plane->id);
1535 crtc_state->update_planes |= BIT(plane->id);
1536 crtc_state->data_rate[plane->id] = 0;
1537 crtc_state->rel_data_rate[plane->id] = 0;
1538 }
1539
icl_check_nv12_planes(struct intel_atomic_state * state,struct intel_crtc * crtc)1540 static int icl_check_nv12_planes(struct intel_atomic_state *state,
1541 struct intel_crtc *crtc)
1542 {
1543 struct intel_display *display = to_intel_display(state);
1544 struct intel_crtc_state *crtc_state =
1545 intel_atomic_get_new_crtc_state(state, crtc);
1546 struct intel_plane_state *plane_state;
1547 struct intel_plane *plane;
1548 int i;
1549
1550 if (DISPLAY_VER(display) < 11)
1551 return 0;
1552
1553 /*
1554 * Destroy all old plane links and make the Y plane invisible
1555 * in the crtc_state->active_planes mask.
1556 */
1557 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
1558 if (plane->pipe != crtc->pipe)
1559 continue;
1560
1561 unlink_nv12_plane(crtc_state, plane_state);
1562 }
1563
1564 if (!crtc_state->nv12_planes)
1565 return 0;
1566
1567 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
1568 struct intel_plane_state *y_plane_state = NULL;
1569 struct intel_plane *y_plane;
1570
1571 if (plane->pipe != crtc->pipe)
1572 continue;
1573
1574 if ((crtc_state->nv12_planes & BIT(plane->id)) == 0)
1575 continue;
1576
1577 for_each_intel_plane_on_crtc(display->drm, crtc, y_plane) {
1578 if (!icl_is_nv12_y_plane(display, y_plane->id))
1579 continue;
1580
1581 if (crtc_state->active_planes & BIT(y_plane->id))
1582 continue;
1583
1584 y_plane_state = intel_atomic_get_plane_state(state, y_plane);
1585 if (IS_ERR(y_plane_state))
1586 return PTR_ERR(y_plane_state);
1587
1588 break;
1589 }
1590
1591 if (!y_plane_state) {
1592 drm_dbg_kms(display->drm,
1593 "[CRTC:%d:%s] need %d free Y planes for planar YUV\n",
1594 crtc->base.base.id, crtc->base.name,
1595 hweight8(crtc_state->nv12_planes));
1596 return -EINVAL;
1597 }
1598
1599 link_nv12_planes(crtc_state, plane_state, y_plane_state);
1600 }
1601
1602 return 0;
1603 }
1604
intel_crtc_add_planes_to_state(struct intel_atomic_state * state,struct intel_crtc * crtc,u8 plane_ids_mask)1605 static int intel_crtc_add_planes_to_state(struct intel_atomic_state *state,
1606 struct intel_crtc *crtc,
1607 u8 plane_ids_mask)
1608 {
1609 struct intel_display *display = to_intel_display(state);
1610 struct intel_plane *plane;
1611
1612 for_each_intel_plane_on_crtc(display->drm, crtc, plane) {
1613 struct intel_plane_state *plane_state;
1614
1615 if ((plane_ids_mask & BIT(plane->id)) == 0)
1616 continue;
1617
1618 plane_state = intel_atomic_get_plane_state(state, plane);
1619 if (IS_ERR(plane_state))
1620 return PTR_ERR(plane_state);
1621 }
1622
1623 return 0;
1624 }
1625
intel_plane_add_affected(struct intel_atomic_state * state,struct intel_crtc * crtc)1626 int intel_plane_add_affected(struct intel_atomic_state *state,
1627 struct intel_crtc *crtc)
1628 {
1629 const struct intel_crtc_state *old_crtc_state =
1630 intel_atomic_get_old_crtc_state(state, crtc);
1631 const struct intel_crtc_state *new_crtc_state =
1632 intel_atomic_get_new_crtc_state(state, crtc);
1633
1634 return intel_crtc_add_planes_to_state(state, crtc,
1635 old_crtc_state->enabled_planes |
1636 new_crtc_state->enabled_planes);
1637 }
1638
active_planes_affects_min_cdclk(struct intel_display * display)1639 static bool active_planes_affects_min_cdclk(struct intel_display *display)
1640 {
1641 /* See {hsw,vlv,ivb}_plane_ratio() */
1642 return display->platform.broadwell || display->platform.haswell ||
1643 display->platform.cherryview || display->platform.valleyview ||
1644 display->platform.ivybridge;
1645 }
1646
intel_joiner_affected_planes(struct intel_atomic_state * state,u8 joined_pipes)1647 static u8 intel_joiner_affected_planes(struct intel_atomic_state *state,
1648 u8 joined_pipes)
1649 {
1650 const struct intel_plane_state *plane_state;
1651 struct intel_plane *plane;
1652 u8 affected_planes = 0;
1653 int i;
1654
1655 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
1656 struct intel_plane *linked = plane_state->planar_linked_plane;
1657
1658 if ((joined_pipes & BIT(plane->pipe)) == 0)
1659 continue;
1660
1661 affected_planes |= BIT(plane->id);
1662 if (linked)
1663 affected_planes |= BIT(linked->id);
1664 }
1665
1666 return affected_planes;
1667 }
1668
intel_joiner_add_affected_planes(struct intel_atomic_state * state,u8 joined_pipes)1669 static int intel_joiner_add_affected_planes(struct intel_atomic_state *state,
1670 u8 joined_pipes)
1671 {
1672 u8 prev_affected_planes, affected_planes = 0;
1673
1674 /*
1675 * We want all the joined pipes to have the same
1676 * set of planes in the atomic state, to make sure
1677 * state copying always works correctly, and the
1678 * UV<->Y plane linkage is always up to date.
1679 * Keep pulling planes in until we've determined
1680 * the full set of affected planes. A bit complicated
1681 * on account of each pipe being capable of selecting
1682 * their own Y planes independently of the other pipes,
1683 * and the selection being done from the set of
1684 * inactive planes.
1685 */
1686 do {
1687 struct intel_crtc *crtc;
1688
1689 for_each_intel_crtc_in_pipe_mask(state->base.dev, crtc, joined_pipes) {
1690 int ret;
1691
1692 ret = intel_crtc_add_planes_to_state(state, crtc, affected_planes);
1693 if (ret)
1694 return ret;
1695 }
1696
1697 prev_affected_planes = affected_planes;
1698 affected_planes = intel_joiner_affected_planes(state, joined_pipes);
1699 } while (affected_planes != prev_affected_planes);
1700
1701 return 0;
1702 }
1703
intel_add_affected_planes(struct intel_atomic_state * state)1704 static int intel_add_affected_planes(struct intel_atomic_state *state)
1705 {
1706 const struct intel_crtc_state *crtc_state;
1707 struct intel_crtc *crtc;
1708 int i;
1709
1710 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
1711 int ret;
1712
1713 ret = intel_joiner_add_affected_planes(state, intel_crtc_joined_pipe_mask(crtc_state));
1714 if (ret)
1715 return ret;
1716 }
1717
1718 return 0;
1719 }
1720
intel_plane_atomic_check(struct intel_atomic_state * state)1721 int intel_plane_atomic_check(struct intel_atomic_state *state)
1722 {
1723 struct intel_display *display = to_intel_display(state);
1724 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
1725 struct intel_plane_state __maybe_unused *plane_state;
1726 struct intel_plane *plane;
1727 struct intel_crtc *crtc;
1728 int i, ret;
1729
1730 ret = intel_add_affected_planes(state);
1731 if (ret)
1732 return ret;
1733
1734 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
1735 ret = plane_atomic_check(state, plane);
1736 if (ret) {
1737 drm_dbg_atomic(display->drm,
1738 "[PLANE:%d:%s] atomic driver check failed\n",
1739 plane->base.base.id, plane->base.name);
1740 return ret;
1741 }
1742 }
1743
1744 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
1745 new_crtc_state, i) {
1746 u8 old_active_planes, new_active_planes;
1747
1748 ret = icl_check_nv12_planes(state, crtc);
1749 if (ret)
1750 return ret;
1751
1752 /*
1753 * On some platforms the number of active planes affects
1754 * the planes' minimum cdclk calculation. Add such planes
1755 * to the state before we compute the minimum cdclk.
1756 */
1757 if (!active_planes_affects_min_cdclk(display))
1758 continue;
1759
1760 old_active_planes = old_crtc_state->active_planes & ~BIT(PLANE_CURSOR);
1761 new_active_planes = new_crtc_state->active_planes & ~BIT(PLANE_CURSOR);
1762
1763 if (hweight8(old_active_planes) == hweight8(new_active_planes))
1764 continue;
1765
1766 ret = intel_crtc_add_planes_to_state(state, crtc, new_active_planes);
1767 if (ret)
1768 return ret;
1769 }
1770
1771 for_each_new_intel_plane_in_state(state, plane, plane_state, i)
1772 intel_plane_calc_min_cdclk(state, plane);
1773
1774 return 0;
1775 }
1776