Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm: Move drm_plane_helper_check_state() into drm_atomic_helper.c

drm_plane_helper_check_update() isn't a transitional helper, so let's
rename it to drm_atomic_helper_check_plane_state() and move it into
drm_atomic_helper.c.

v2: Fix the WARNs about plane_state->crtc matching crtc_state->crtc

Cc: Daniel Vetter <daniel@ffwll.ch>
Suggested-by: Daniel Vetter <daniel@ffwll.ch>
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20171101201619.6175-1-ville.syrjala@linux.intel.com
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>

+169 -165
+4 -4
drivers/gpu/drm/arm/hdlcd_crtc.c
··· 252 252 clip.x2 = crtc_state->adjusted_mode.hdisplay; 253 253 clip.y2 = crtc_state->adjusted_mode.vdisplay; 254 254 255 - return drm_plane_helper_check_state(state, crtc_state, &clip, 256 - DRM_PLANE_HELPER_NO_SCALING, 257 - DRM_PLANE_HELPER_NO_SCALING, 258 - false, true); 255 + return drm_atomic_helper_check_plane_state(state, crtc_state, &clip, 256 + DRM_PLANE_HELPER_NO_SCALING, 257 + DRM_PLANE_HELPER_NO_SCALING, 258 + false, true); 259 259 } 260 260 261 261 static void hdlcd_plane_atomic_update(struct drm_plane *plane,
+2 -2
drivers/gpu/drm/arm/malidp_planes.c
··· 150 150 151 151 clip.x2 = crtc_state->adjusted_mode.hdisplay; 152 152 clip.y2 = crtc_state->adjusted_mode.vdisplay; 153 - ret = drm_plane_helper_check_state(state, crtc_state, &clip, 154 - 0, INT_MAX, true, true); 153 + ret = drm_atomic_helper_check_plane_state(state, crtc_state, &clip, 154 + 0, INT_MAX, true, true); 155 155 if (ret) 156 156 return ret; 157 157
+94
drivers/gpu/drm/drm_atomic_helper.c
··· 696 696 EXPORT_SYMBOL(drm_atomic_helper_check_modeset); 697 697 698 698 /** 699 + * drm_atomic_helper_check_plane_state() - Check plane state for validity 700 + * @plane_state: plane state to check 701 + * @crtc_state: crtc state to check 702 + * @clip: integer clipping coordinates 703 + * @min_scale: minimum @src:@dest scaling factor in 16.16 fixed point 704 + * @max_scale: maximum @src:@dest scaling factor in 16.16 fixed point 705 + * @can_position: is it legal to position the plane such that it 706 + * doesn't cover the entire crtc? This will generally 707 + * only be false for primary planes. 708 + * @can_update_disabled: can the plane be updated while the crtc 709 + * is disabled? 710 + * 711 + * Checks that a desired plane update is valid, and updates various 712 + * bits of derived state (clipped coordinates etc.). Drivers that provide 713 + * their own plane handling rather than helper-provided implementations may 714 + * still wish to call this function to avoid duplication of error checking 715 + * code. 716 + * 717 + * RETURNS: 718 + * Zero if update appears valid, error code on failure 719 + */ 720 + int drm_atomic_helper_check_plane_state(struct drm_plane_state *plane_state, 721 + const struct drm_crtc_state *crtc_state, 722 + const struct drm_rect *clip, 723 + int min_scale, 724 + int max_scale, 725 + bool can_position, 726 + bool can_update_disabled) 727 + { 728 + struct drm_framebuffer *fb = plane_state->fb; 729 + struct drm_rect *src = &plane_state->src; 730 + struct drm_rect *dst = &plane_state->dst; 731 + unsigned int rotation = plane_state->rotation; 732 + int hscale, vscale; 733 + 734 + WARN_ON(plane_state->crtc && plane_state->crtc != crtc_state->crtc); 735 + 736 + *src = drm_plane_state_src(plane_state); 737 + *dst = drm_plane_state_dest(plane_state); 738 + 739 + if (!fb) { 740 + plane_state->visible = false; 741 + return 0; 742 + } 743 + 744 + /* crtc should only be NULL when disabling (i.e., !fb) */ 745 + if (WARN_ON(!plane_state->crtc)) { 746 + plane_state->visible = false; 747 + return 0; 748 + } 749 + 750 + if (!crtc_state->enable && !can_update_disabled) { 751 + DRM_DEBUG_KMS("Cannot update plane of a disabled CRTC.\n"); 752 + return -EINVAL; 753 + } 754 + 755 + drm_rect_rotate(src, fb->width << 16, fb->height << 16, rotation); 756 + 757 + /* Check scaling */ 758 + hscale = drm_rect_calc_hscale(src, dst, min_scale, max_scale); 759 + vscale = drm_rect_calc_vscale(src, dst, min_scale, max_scale); 760 + if (hscale < 0 || vscale < 0) { 761 + DRM_DEBUG_KMS("Invalid scaling of plane\n"); 762 + drm_rect_debug_print("src: ", &plane_state->src, true); 763 + drm_rect_debug_print("dst: ", &plane_state->dst, false); 764 + return -ERANGE; 765 + } 766 + 767 + plane_state->visible = drm_rect_clip_scaled(src, dst, clip, hscale, vscale); 768 + 769 + drm_rect_rotate_inv(src, fb->width << 16, fb->height << 16, rotation); 770 + 771 + if (!plane_state->visible) 772 + /* 773 + * Plane isn't visible; some drivers can handle this 774 + * so we just return success here. Drivers that can't 775 + * (including those that use the primary plane helper's 776 + * update function) will return an error from their 777 + * update_plane handler. 778 + */ 779 + return 0; 780 + 781 + if (!can_position && !drm_rect_equals(dst, clip)) { 782 + DRM_DEBUG_KMS("Plane must cover entire CRTC\n"); 783 + drm_rect_debug_print("dst: ", dst, false); 784 + drm_rect_debug_print("clip: ", clip, false); 785 + return -EINVAL; 786 + } 787 + 788 + return 0; 789 + } 790 + EXPORT_SYMBOL(drm_atomic_helper_check_plane_state); 791 + 792 + /** 699 793 * drm_atomic_helper_check_planes - validate state object for planes changes 700 794 * @dev: DRM device 701 795 * @state: the driver state object
+4 -98
drivers/gpu/drm/drm_plane_helper.c
··· 100 100 } 101 101 102 102 /** 103 - * drm_plane_helper_check_state() - Check plane state for validity 104 - * @plane_state: plane state to check 105 - * @crtc_state: crtc state to check 106 - * @clip: integer clipping coordinates 107 - * @min_scale: minimum @src:@dest scaling factor in 16.16 fixed point 108 - * @max_scale: maximum @src:@dest scaling factor in 16.16 fixed point 109 - * @can_position: is it legal to position the plane such that it 110 - * doesn't cover the entire crtc? This will generally 111 - * only be false for primary planes. 112 - * @can_update_disabled: can the plane be updated while the crtc 113 - * is disabled? 114 - * 115 - * Checks that a desired plane update is valid, and updates various 116 - * bits of derived state (clipped coordinates etc.). Drivers that provide 117 - * their own plane handling rather than helper-provided implementations may 118 - * still wish to call this function to avoid duplication of error checking 119 - * code. 120 - * 121 - * RETURNS: 122 - * Zero if update appears valid, error code on failure 123 - */ 124 - int drm_plane_helper_check_state(struct drm_plane_state *plane_state, 125 - const struct drm_crtc_state *crtc_state, 126 - const struct drm_rect *clip, 127 - int min_scale, 128 - int max_scale, 129 - bool can_position, 130 - bool can_update_disabled) 131 - { 132 - struct drm_framebuffer *fb = plane_state->fb; 133 - struct drm_rect *src = &plane_state->src; 134 - struct drm_rect *dst = &plane_state->dst; 135 - unsigned int rotation = plane_state->rotation; 136 - int hscale, vscale; 137 - 138 - WARN_ON(plane_state->crtc && plane_state->crtc != crtc_state->crtc); 139 - 140 - *src = drm_plane_state_src(plane_state); 141 - *dst = drm_plane_state_dest(plane_state); 142 - 143 - if (!fb) { 144 - plane_state->visible = false; 145 - return 0; 146 - } 147 - 148 - /* crtc should only be NULL when disabling (i.e., !fb) */ 149 - if (WARN_ON(!plane_state->crtc)) { 150 - plane_state->visible = false; 151 - return 0; 152 - } 153 - 154 - if (!crtc_state->enable && !can_update_disabled) { 155 - DRM_DEBUG_KMS("Cannot update plane of a disabled CRTC.\n"); 156 - return -EINVAL; 157 - } 158 - 159 - drm_rect_rotate(src, fb->width << 16, fb->height << 16, rotation); 160 - 161 - /* Check scaling */ 162 - hscale = drm_rect_calc_hscale(src, dst, min_scale, max_scale); 163 - vscale = drm_rect_calc_vscale(src, dst, min_scale, max_scale); 164 - if (hscale < 0 || vscale < 0) { 165 - DRM_DEBUG_KMS("Invalid scaling of plane\n"); 166 - drm_rect_debug_print("src: ", &plane_state->src, true); 167 - drm_rect_debug_print("dst: ", &plane_state->dst, false); 168 - return -ERANGE; 169 - } 170 - 171 - plane_state->visible = drm_rect_clip_scaled(src, dst, clip, hscale, vscale); 172 - 173 - drm_rect_rotate_inv(src, fb->width << 16, fb->height << 16, rotation); 174 - 175 - if (!plane_state->visible) 176 - /* 177 - * Plane isn't visible; some drivers can handle this 178 - * so we just return success here. Drivers that can't 179 - * (including those that use the primary plane helper's 180 - * update function) will return an error from their 181 - * update_plane handler. 182 - */ 183 - return 0; 184 - 185 - if (!can_position && !drm_rect_equals(dst, clip)) { 186 - DRM_DEBUG_KMS("Plane must cover entire CRTC\n"); 187 - drm_rect_debug_print("dst: ", dst, false); 188 - drm_rect_debug_print("clip: ", clip, false); 189 - return -EINVAL; 190 - } 191 - 192 - return 0; 193 - } 194 - EXPORT_SYMBOL(drm_plane_helper_check_state); 195 - 196 - /** 197 103 * drm_plane_helper_check_update() - Check plane update for validity 198 104 * @plane: plane object to update 199 105 * @crtc: owning CRTC of owning plane ··· 160 254 }; 161 255 int ret; 162 256 163 - ret = drm_plane_helper_check_state(&plane_state, &crtc_state, clip, 164 - min_scale, max_scale, 165 - can_position, 166 - can_update_disabled); 257 + ret = drm_atomic_helper_check_plane_state(&plane_state, &crtc_state, 258 + clip, min_scale, max_scale, 259 + can_position, 260 + can_update_disabled); 167 261 if (ret) 168 262 return ret; 169 263
+5 -4
drivers/gpu/drm/drm_simple_kms_helper.c
··· 103 103 clip.x2 = crtc_state->adjusted_mode.hdisplay; 104 104 clip.y2 = crtc_state->adjusted_mode.vdisplay; 105 105 106 - ret = drm_plane_helper_check_state(plane_state, crtc_state, &clip, 107 - DRM_PLANE_HELPER_NO_SCALING, 108 - DRM_PLANE_HELPER_NO_SCALING, 109 - false, true); 106 + ret = drm_atomic_helper_check_plane_state(plane_state, crtc_state, 107 + &clip, 108 + DRM_PLANE_HELPER_NO_SCALING, 109 + DRM_PLANE_HELPER_NO_SCALING, 110 + false, true); 110 111 if (ret) 111 112 return ret; 112 113
+11 -11
drivers/gpu/drm/i915/intel_display.c
··· 9418 9418 u32 offset; 9419 9419 int ret; 9420 9420 9421 - ret = drm_plane_helper_check_state(&plane_state->base, 9422 - &crtc_state->base, 9423 - &plane_state->clip, 9424 - DRM_PLANE_HELPER_NO_SCALING, 9425 - DRM_PLANE_HELPER_NO_SCALING, 9426 - true, true); 9421 + ret = drm_atomic_helper_check_plane_state(&plane_state->base, 9422 + &crtc_state->base, 9423 + &plane_state->clip, 9424 + DRM_PLANE_HELPER_NO_SCALING, 9425 + DRM_PLANE_HELPER_NO_SCALING, 9426 + true, true); 9427 9427 if (ret) 9428 9428 return ret; 9429 9429 ··· 12842 12842 can_position = true; 12843 12843 } 12844 12844 12845 - ret = drm_plane_helper_check_state(&state->base, 12846 - &crtc_state->base, 12847 - &state->clip, 12848 - min_scale, max_scale, 12849 - can_position, true); 12845 + ret = drm_atomic_helper_check_plane_state(&state->base, 12846 + &crtc_state->base, 12847 + &state->clip, 12848 + min_scale, max_scale, 12849 + can_position, true); 12850 12850 if (ret) 12851 12851 return ret; 12852 12852
+4 -4
drivers/gpu/drm/imx/ipuv3-plane.c
··· 342 342 clip.y1 = 0; 343 343 clip.x2 = crtc_state->adjusted_mode.hdisplay; 344 344 clip.y2 = crtc_state->adjusted_mode.vdisplay; 345 - ret = drm_plane_helper_check_state(state, crtc_state, &clip, 346 - DRM_PLANE_HELPER_NO_SCALING, 347 - DRM_PLANE_HELPER_NO_SCALING, 348 - can_position, true); 345 + ret = drm_atomic_helper_check_plane_state(state, crtc_state, &clip, 346 + DRM_PLANE_HELPER_NO_SCALING, 347 + DRM_PLANE_HELPER_NO_SCALING, 348 + can_position, true); 349 349 if (ret) 350 350 return ret; 351 351
+4 -4
drivers/gpu/drm/mediatek/mtk_drm_plane.c
··· 111 111 clip.x2 = crtc_state->mode.hdisplay; 112 112 clip.y2 = crtc_state->mode.vdisplay; 113 113 114 - return drm_plane_helper_check_state(state, crtc_state, &clip, 115 - DRM_PLANE_HELPER_NO_SCALING, 116 - DRM_PLANE_HELPER_NO_SCALING, 117 - true, true); 114 + return drm_atomic_helper_check_plane_state(state, crtc_state, &clip, 115 + DRM_PLANE_HELPER_NO_SCALING, 116 + DRM_PLANE_HELPER_NO_SCALING, 117 + true, true); 118 118 } 119 119 120 120 static void mtk_plane_atomic_update(struct drm_plane *plane,
+4 -4
drivers/gpu/drm/meson/meson_plane.c
··· 61 61 clip.x2 = crtc_state->mode.hdisplay; 62 62 clip.y2 = crtc_state->mode.vdisplay; 63 63 64 - return drm_plane_helper_check_state(state, crtc_state, &clip, 65 - DRM_PLANE_HELPER_NO_SCALING, 66 - DRM_PLANE_HELPER_NO_SCALING, 67 - true, true); 64 + return drm_atomic_helper_check_plane_state(state, crtc_state, &clip, 65 + DRM_PLANE_HELPER_NO_SCALING, 66 + DRM_PLANE_HELPER_NO_SCALING, 67 + true, true); 68 68 } 69 69 70 70 /* Takes a fixed 16.16 number and converts it to integer. */
+3 -2
drivers/gpu/drm/msm/mdp/mdp5/mdp5_plane.c
··· 348 348 min_scale = FRAC_16_16(1, 8); 349 349 max_scale = FRAC_16_16(8, 1); 350 350 351 - ret = drm_plane_helper_check_state(state, crtc_state, &clip, 352 - min_scale, max_scale, true, true); 351 + ret = drm_atomic_helper_check_plane_state(state, crtc_state, &clip, 352 + min_scale, max_scale, 353 + true, true); 353 354 if (ret) 354 355 return ret; 355 356
+10 -10
drivers/gpu/drm/nouveau/nv50_display.c
··· 1143 1143 { 1144 1144 int ret; 1145 1145 1146 - ret = drm_plane_helper_check_state(&asyw->state, &asyh->state, 1147 - &asyw->clip, 1148 - DRM_PLANE_HELPER_NO_SCALING, 1149 - DRM_PLANE_HELPER_NO_SCALING, 1150 - true, true); 1146 + ret = drm_atomic_helper_check_plane_state(&asyw->state, &asyh->state, 1147 + &asyw->clip, 1148 + DRM_PLANE_HELPER_NO_SCALING, 1149 + DRM_PLANE_HELPER_NO_SCALING, 1150 + true, true); 1151 1151 asyh->curs.visible = asyw->state.visible; 1152 1152 if (ret || !asyh->curs.visible) 1153 1153 return ret; ··· 1433 1433 if (!fb->format->depth) 1434 1434 return -EINVAL; 1435 1435 1436 - ret = drm_plane_helper_check_state(&asyw->state, &asyh->state, 1437 - &asyw->clip, 1438 - DRM_PLANE_HELPER_NO_SCALING, 1439 - DRM_PLANE_HELPER_NO_SCALING, 1440 - false, true); 1436 + ret = drm_atomic_helper_check_plane_state(&asyw->state, &asyh->state, 1437 + &asyw->clip, 1438 + DRM_PLANE_HELPER_NO_SCALING, 1439 + DRM_PLANE_HELPER_NO_SCALING, 1440 + false, true); 1441 1441 if (ret) 1442 1442 return ret; 1443 1443
+3 -3
drivers/gpu/drm/rockchip/rockchip_drm_vop.c
··· 659 659 clip.x2 = crtc_state->adjusted_mode.hdisplay; 660 660 clip.y2 = crtc_state->adjusted_mode.vdisplay; 661 661 662 - ret = drm_plane_helper_check_state(state, crtc_state, &clip, 663 - min_scale, max_scale, 664 - true, true); 662 + ret = drm_atomic_helper_check_plane_state(state, crtc_state, &clip, 663 + min_scale, max_scale, 664 + true, true); 665 665 if (ret) 666 666 return ret; 667 667
+2 -2
drivers/gpu/drm/tegra/dc.c
··· 500 500 clip.y2 = crtc_state->mode.vdisplay; 501 501 502 502 /* Check plane state for visibility and calculate clipping bounds */ 503 - err = drm_plane_helper_check_state(state, crtc_state, &clip, 504 - 0, INT_MAX, true, true); 503 + err = drm_atomic_helper_check_plane_state(state, crtc_state, &clip, 504 + 0, INT_MAX, true, true); 505 505 if (err < 0) 506 506 return err; 507 507
+4 -4
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
··· 454 454 clip.y2 = crtc_state->adjusted_mode.vdisplay; 455 455 } 456 456 457 - ret = drm_plane_helper_check_state(state, crtc_state, &clip, 458 - DRM_PLANE_HELPER_NO_SCALING, 459 - DRM_PLANE_HELPER_NO_SCALING, 460 - false, true); 457 + ret = drm_atomic_helper_check_plane_state(state, crtc_state, &clip, 458 + DRM_PLANE_HELPER_NO_SCALING, 459 + DRM_PLANE_HELPER_NO_SCALING, 460 + false, true); 461 461 462 462 if (!ret && new_fb) { 463 463 struct drm_crtc *crtc = state->crtc;
+8 -7
drivers/gpu/drm/zte/zx_plane.c
··· 80 80 clip.x2 = crtc_state->adjusted_mode.hdisplay; 81 81 clip.y2 = crtc_state->adjusted_mode.vdisplay; 82 82 83 - return drm_plane_helper_check_state(plane_state, crtc_state, &clip, 84 - min_scale, max_scale, 85 - true, true); 83 + return drm_atomic_helper_check_plane_state(plane_state, crtc_state, 84 + &clip, min_scale, max_scale, 85 + true, true); 86 86 } 87 87 88 88 static int zx_vl_get_fmt(uint32_t format) ··· 315 315 clip.x2 = crtc_state->adjusted_mode.hdisplay; 316 316 clip.y2 = crtc_state->adjusted_mode.vdisplay; 317 317 318 - return drm_plane_helper_check_state(plane_state, crtc_state, &clip, 319 - DRM_PLANE_HELPER_NO_SCALING, 320 - DRM_PLANE_HELPER_NO_SCALING, 321 - false, true); 318 + return drm_atomic_helper_check_plane_state(plane_state, crtc_state, 319 + &clip, 320 + DRM_PLANE_HELPER_NO_SCALING, 321 + DRM_PLANE_HELPER_NO_SCALING, 322 + false, true); 322 323 } 323 324 324 325 static int zx_gl_get_fmt(uint32_t format)
+7
include/drm/drm_atomic_helper.h
··· 38 38 39 39 int drm_atomic_helper_check_modeset(struct drm_device *dev, 40 40 struct drm_atomic_state *state); 41 + int drm_atomic_helper_check_plane_state(struct drm_plane_state *plane_state, 42 + const struct drm_crtc_state *crtc_state, 43 + const struct drm_rect *clip, 44 + int min_scale, 45 + int max_scale, 46 + bool can_position, 47 + bool can_update_disabled); 41 48 int drm_atomic_helper_check_planes(struct drm_device *dev, 42 49 struct drm_atomic_state *state); 43 50 int drm_atomic_helper_check(struct drm_device *dev,
-6
include/drm/drm_plane_helper.h
··· 38 38 */ 39 39 #define DRM_PLANE_HELPER_NO_SCALING (1<<16) 40 40 41 - int drm_plane_helper_check_state(struct drm_plane_state *plane_state, 42 - const struct drm_crtc_state *crtc_state, 43 - const struct drm_rect *clip, 44 - int min_scale, int max_scale, 45 - bool can_position, 46 - bool can_update_disabled); 47 41 int drm_plane_helper_check_update(struct drm_plane *plane, 48 42 struct drm_crtc *crtc, 49 43 struct drm_framebuffer *fb,