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

drm/crtc-helper: Transitional functions using atomic plane helpers

These two functions allow drivers to reuse their atomic plane helpers
functions for the primary plane to implement the interfaces required
by the crtc helpers for the legacy ->set_config callback.

This is purely transitional and won't be used once the driver is fully
converted. But it allows partial conversions to the atomic plane
helpers which are functional.

v2:
- Use ->atomic_duplicate_state if available.
- Don't forget to run crtc_funcs->atomic_check.

v3: Shift source coordinates correctly for 16.16 fixed point.

v4: Don't forget to call ->atomic_destroy_state if available.

v5: Fixup kerneldoc.

v6: Reuse the plane_commit function from the transitional plane
helpers to avoid too much duplication.

v7:
- Remove some stale comment.
- Correctly handle the lack of plane->state object, necessary for
transitional use.

v8: Fixup an embarrassing h/vdisplay mixup.

Reviewed-by: Sean Paul <seanpaul@chromium.org>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>

+130 -5
+110
drivers/gpu/drm/drm_crtc_helper.c
··· 38 38 #include <drm/drm_fourcc.h> 39 39 #include <drm/drm_crtc_helper.h> 40 40 #include <drm/drm_fb_helper.h> 41 + #include <drm/drm_plane_helper.h> 41 42 #include <drm/drm_edid.h> 42 43 43 44 MODULE_AUTHOR("David Airlie, Jesse Barnes"); ··· 889 888 drm_modeset_unlock_all(dev); 890 889 } 891 890 EXPORT_SYMBOL(drm_helper_resume_force_mode); 891 + 892 + /** 893 + * drm_helper_crtc_mode_set - mode_set implementation for atomic plane helpers 894 + * @crtc: DRM CRTC 895 + * @mode: DRM display mode which userspace requested 896 + * @adjusted_mode: DRM display mode adjusted by ->mode_fixup callbacks 897 + * @x: x offset of the CRTC scanout area on the underlying framebuffer 898 + * @y: y offset of the CRTC scanout area on the underlying framebuffer 899 + * @old_fb: previous framebuffer 900 + * 901 + * This function implements a callback useable as the ->mode_set callback 902 + * required by the crtc helpers. Besides the atomic plane helper functions for 903 + * the primary plane the driver must also provide the ->mode_set_nofb callback 904 + * to set up the crtc. 905 + * 906 + * This is a transitional helper useful for converting drivers to the atomic 907 + * interfaces. 908 + */ 909 + int drm_helper_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *mode, 910 + struct drm_display_mode *adjusted_mode, int x, int y, 911 + struct drm_framebuffer *old_fb) 912 + { 913 + struct drm_crtc_state *crtc_state; 914 + struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private; 915 + int ret; 916 + 917 + if (crtc->funcs->atomic_duplicate_state) 918 + crtc_state = crtc->funcs->atomic_duplicate_state(crtc); 919 + else if (crtc->state) 920 + crtc_state = kmemdup(crtc->state, sizeof(*crtc_state), 921 + GFP_KERNEL); 922 + else 923 + crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL); 924 + if (!crtc_state) 925 + return -ENOMEM; 926 + 927 + crtc_state->enable = true; 928 + crtc_state->planes_changed = true; 929 + drm_mode_copy(&crtc_state->mode, mode); 930 + drm_mode_copy(&crtc_state->adjusted_mode, adjusted_mode); 931 + 932 + if (crtc_funcs->atomic_check) { 933 + ret = crtc_funcs->atomic_check(crtc, crtc_state); 934 + if (ret) { 935 + kfree(crtc_state); 936 + 937 + return ret; 938 + } 939 + } 940 + 941 + swap(crtc->state, crtc_state); 942 + 943 + crtc_funcs->mode_set_nofb(crtc); 944 + 945 + if (crtc_state) { 946 + if (crtc->funcs->atomic_destroy_state) 947 + crtc->funcs->atomic_destroy_state(crtc, crtc_state); 948 + else 949 + kfree(crtc_state); 950 + } 951 + 952 + return drm_helper_crtc_mode_set_base(crtc, x, y, old_fb); 953 + } 954 + EXPORT_SYMBOL(drm_helper_crtc_mode_set); 955 + 956 + /** 957 + * drm_helper_crtc_mode_set_base - mode_set_base implementation for atomic plane helpers 958 + * @crtc: DRM CRTC 959 + * @x: x offset of the CRTC scanout area on the underlying framebuffer 960 + * @y: y offset of the CRTC scanout area on the underlying framebuffer 961 + * @old_fb: previous framebuffer 962 + * 963 + * This function implements a callback useable as the ->mode_set_base used 964 + * required by the crtc helpers. The driver must provide the atomic plane helper 965 + * functions for the primary plane. 966 + * 967 + * This is a transitional helper useful for converting drivers to the atomic 968 + * interfaces. 969 + */ 970 + int drm_helper_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y, 971 + struct drm_framebuffer *old_fb) 972 + { 973 + struct drm_plane_state *plane_state; 974 + struct drm_plane *plane = crtc->primary; 975 + 976 + if (plane->funcs->atomic_duplicate_state) 977 + plane_state = plane->funcs->atomic_duplicate_state(plane); 978 + else if (plane->state) 979 + plane_state = kmemdup(plane->state, sizeof(*plane_state), 980 + GFP_KERNEL); 981 + else 982 + plane_state = kzalloc(sizeof(*plane_state), GFP_KERNEL); 983 + if (!plane_state) 984 + return -ENOMEM; 985 + 986 + plane_state->crtc = crtc; 987 + plane_state->fb = crtc->primary->fb; 988 + plane_state->crtc_x = 0; 989 + plane_state->crtc_y = 0; 990 + plane_state->crtc_h = crtc->mode.vdisplay; 991 + plane_state->crtc_w = crtc->mode.hdisplay; 992 + plane_state->src_x = x << 16; 993 + plane_state->src_y = y << 16; 994 + plane_state->src_h = crtc->mode.vdisplay << 16; 995 + plane_state->src_w = crtc->mode.hdisplay << 16; 996 + 997 + return drm_plane_helper_commit(plane, plane_state, old_fb); 998 + } 999 + EXPORT_SYMBOL(drm_helper_crtc_mode_set_base);
+5 -5
drivers/gpu/drm/drm_plane_helper.c
··· 370 370 } 371 371 EXPORT_SYMBOL(drm_crtc_init); 372 372 373 - static int 374 - plane_commit(struct drm_plane *plane, struct drm_plane_state *plane_state, 375 - struct drm_framebuffer *old_fb) 373 + int drm_plane_helper_commit(struct drm_plane *plane, 374 + struct drm_plane_state *plane_state, 375 + struct drm_framebuffer *old_fb) 376 376 { 377 377 struct drm_plane_helper_funcs *plane_funcs; 378 378 struct drm_crtc *crtc[2]; ··· 497 497 plane_state->src_h = src_h; 498 498 plane_state->src_w = src_w; 499 499 500 - return plane_commit(plane, plane_state, plane->fb); 500 + return drm_plane_helper_commit(plane, plane_state, plane->fb); 501 501 } 502 502 EXPORT_SYMBOL(drm_plane_helper_update); 503 503 ··· 536 536 plane_state->crtc = NULL; 537 537 plane_state->fb = NULL; 538 538 539 - return plane_commit(plane, plane_state, plane->fb); 539 + return drm_plane_helper_commit(plane, plane_state, plane->fb); 540 540 } 541 541 EXPORT_SYMBOL(drm_plane_helper_disable);
+4
include/drm/drm_crtc.h
··· 230 230 * struct drm_crtc_state - mutable CRTC state 231 231 * @enable: whether the CRTC should be enabled, gates all other state 232 232 * @planes_changed: for use by helpers and drivers when computing state updates 233 + * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings 233 234 * @mode: current mode timings 234 235 * @event: optional pointer to a DRM event to signal upon completion of the 235 236 * state update ··· 241 240 242 241 /* computed state bits used by helpers and drivers */ 243 242 bool planes_changed : 1; 243 + 244 + /* adjusted_mode: for use by helpers and drivers */ 245 + struct drm_display_mode adjusted_mode; 244 246 245 247 struct drm_display_mode mode; 246 248
+7
include/drm/drm_crtc_helper.h
··· 68 68 int (*mode_set)(struct drm_crtc *crtc, struct drm_display_mode *mode, 69 69 struct drm_display_mode *adjusted_mode, int x, int y, 70 70 struct drm_framebuffer *old_fb); 71 + void (*mode_set_nofb)(struct drm_crtc *crtc); 71 72 72 73 /* Move the crtc on the current fb to the given position *optional* */ 73 74 int (*mode_set_base)(struct drm_crtc *crtc, int x, int y, ··· 167 166 } 168 167 169 168 extern void drm_helper_resume_force_mode(struct drm_device *dev); 169 + 170 + int drm_helper_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *mode, 171 + struct drm_display_mode *adjusted_mode, int x, int y, 172 + struct drm_framebuffer *old_fb); 173 + int drm_helper_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y, 174 + struct drm_framebuffer *old_fb); 170 175 171 176 /* drm_probe_helper.c */ 172 177 extern int drm_helper_probe_single_connector_modes(struct drm_connector
+4
include/drm/drm_plane_helper.h
··· 103 103 uint32_t src_w, uint32_t src_h); 104 104 int drm_plane_helper_disable(struct drm_plane *plane); 105 105 106 + /* For use by drm_crtc_helper.c */ 107 + int drm_plane_helper_commit(struct drm_plane *plane, 108 + struct drm_plane_state *plane_state, 109 + struct drm_framebuffer *old_fb); 106 110 #endif