Skip to content

Commit

Permalink
drm/fb-helper: Push locking into restore_fbdev_mode_atomic|legacy
Browse files Browse the repository at this point in the history
Same game as with the panning function, use drm_modeset_lock_all for
legacy paths, and a proper acquire ctx w/w mutex dance for atomic.

Cc: John Stultz <john.stultz@linaro.org>
Cc: Thierry Reding <treding@nvidia.com>
Reviewed-by: Maarten Lankhorst <maarten.lankhorst@intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20170704151833.17304-8-daniel.vetter@ffwll.ch
  • Loading branch information
Daniel Vetter committed Jul 6, 2017
1 parent 5c2e344 commit 1d0c641
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions drivers/gpu/drm/drm_fb_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,12 +382,17 @@ static int restore_fbdev_mode_atomic(struct drm_fb_helper *fb_helper)
struct drm_atomic_state *state;
int i, ret;
unsigned int plane_mask;
struct drm_modeset_acquire_ctx ctx;

drm_modeset_acquire_init(&ctx, 0);

state = drm_atomic_state_alloc(dev);
if (!state)
return -ENOMEM;
if (!state) {
ret = -ENOMEM;
goto out_ctx;
}

state->acquire_ctx = dev->mode_config.acquire_ctx;
state->acquire_ctx = &ctx;
retry:
plane_mask = 0;
drm_for_each_plane(plane, dev) {
Expand All @@ -396,7 +401,7 @@ static int restore_fbdev_mode_atomic(struct drm_fb_helper *fb_helper)
plane_state = drm_atomic_get_plane_state(state, plane);
if (IS_ERR(plane_state)) {
ret = PTR_ERR(plane_state);
goto fail;
goto out_state;
}

plane_state->rotation = DRM_MODE_ROTATE_0;
Expand All @@ -410,31 +415,35 @@ static int restore_fbdev_mode_atomic(struct drm_fb_helper *fb_helper)

ret = __drm_atomic_helper_disable_plane(plane, plane_state);
if (ret != 0)
goto fail;
goto out_state;
}

for (i = 0; i < fb_helper->crtc_count; i++) {
struct drm_mode_set *mode_set = &fb_helper->crtc_info[i].mode_set;

ret = __drm_atomic_helper_set_config(mode_set, state);
if (ret != 0)
goto fail;
goto out_state;
}

ret = drm_atomic_commit(state);

fail:
out_state:
drm_atomic_clean_old_fb(dev, plane_mask, ret);

if (ret == -EDEADLK)
goto backoff;

drm_atomic_state_put(state);
out_ctx:
drm_modeset_drop_locks(&ctx);
drm_modeset_acquire_fini(&ctx);

return ret;

backoff:
drm_atomic_state_clear(state);
drm_atomic_legacy_backoff(state);
drm_modeset_backoff(&ctx);

goto retry;
}
Expand All @@ -443,8 +452,9 @@ static int restore_fbdev_mode_legacy(struct drm_fb_helper *fb_helper)
{
struct drm_device *dev = fb_helper->dev;
struct drm_plane *plane;
int i;
int i, ret = 0;

drm_modeset_lock_all(fb_helper->dev);
drm_for_each_plane(plane, dev) {
if (plane->type != DRM_PLANE_TYPE_PRIMARY)
drm_plane_force_disable(plane);
Expand All @@ -458,32 +468,31 @@ static int restore_fbdev_mode_legacy(struct drm_fb_helper *fb_helper)
for (i = 0; i < fb_helper->crtc_count; i++) {
struct drm_mode_set *mode_set = &fb_helper->crtc_info[i].mode_set;
struct drm_crtc *crtc = mode_set->crtc;
int ret;

if (crtc->funcs->cursor_set2) {
ret = crtc->funcs->cursor_set2(crtc, NULL, 0, 0, 0, 0, 0);
if (ret)
return ret;
goto out;
} else if (crtc->funcs->cursor_set) {
ret = crtc->funcs->cursor_set(crtc, NULL, 0, 0, 0);
if (ret)
return ret;
goto out;
}

ret = drm_mode_set_config_internal(mode_set);
if (ret)
return ret;
goto out;
}
out:
drm_modeset_unlock_all(fb_helper->dev);

return 0;
return ret;
}

static int restore_fbdev_mode(struct drm_fb_helper *fb_helper)
{
struct drm_device *dev = fb_helper->dev;

drm_warn_on_modeset_not_all_locked(dev);

if (drm_drv_uses_atomic_modeset(dev))
return restore_fbdev_mode_atomic(fb_helper);
else
Expand All @@ -503,23 +512,18 @@ static int restore_fbdev_mode(struct drm_fb_helper *fb_helper)
*/
int drm_fb_helper_restore_fbdev_mode_unlocked(struct drm_fb_helper *fb_helper)
{
struct drm_device *dev = fb_helper->dev;
bool do_delayed;
int ret;

if (!drm_fbdev_emulation)
return -ENODEV;

mutex_lock(&fb_helper->lock);
drm_modeset_lock_all(dev);

ret = restore_fbdev_mode(fb_helper);

do_delayed = fb_helper->delayed_hotplug;
if (do_delayed)
fb_helper->delayed_hotplug = false;

drm_modeset_unlock_all(dev);
mutex_unlock(&fb_helper->lock);

if (do_delayed)
Expand Down Expand Up @@ -577,11 +581,9 @@ static bool drm_fb_helper_force_kernel_mode(void)
continue;

mutex_lock(&helper->lock);
drm_modeset_lock_all(dev);
ret = restore_fbdev_mode(helper);
if (ret)
error = true;
drm_modeset_unlock_all(dev);
mutex_unlock(&helper->lock);
}
return error;
Expand Down

0 comments on commit 1d0c641

Please sign in to comment.