Skip to content

Commit

Permalink
drm/vc4: kms: Convert to atomic helpers
Browse files Browse the repository at this point in the history
Now that the semaphore is gone, our atomic_commit implementation is
basically drm_atomic_helper_commit with a somewhat custom commit_tail,
the main difference being that we're using wait_for_flip_done instead of
wait_for_vblanks used in the drm_atomic_helper_commit_tail helper.

Let's switch to using drm_atomic_helper_commit.

Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
  • Loading branch information
mripard authored and popcornmix committed Jul 8, 2021
1 parent 065e7bf commit 2f3e2d8
Showing 1 changed file with 13 additions and 109 deletions.
122 changes: 13 additions & 109 deletions drivers/gpu/drm/vc4/vc4_kms.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,7 @@ static void vc5_hvs_pv_muxing_commit(struct vc4_dev *vc4,
}
}

static void
vc4_atomic_complete_commit(struct drm_atomic_state *state)
static void vc4_atomic_commit_tail(struct drm_atomic_state *state)
{
struct drm_device *dev = state->dev;
struct vc4_dev *vc4 = to_vc4_dev(dev);
Expand All @@ -361,10 +360,6 @@ vc4_atomic_complete_commit(struct drm_atomic_state *state)
if (vc4->hvs && vc4->hvs->hvs5)
core_req = clk_request_start(hvs->core_clk, 500000000);

drm_atomic_helper_wait_for_fences(dev, state, false);

drm_atomic_helper_wait_for_dependencies(state);

old_hvs_state = vc4_hvs_get_old_global_state(state);
if (!old_hvs_state)
return;
Expand Down Expand Up @@ -418,29 +413,27 @@ vc4_atomic_complete_commit(struct drm_atomic_state *state)

drm_atomic_helper_cleanup_planes(dev, state);

drm_atomic_helper_commit_cleanup_done(state);

if (vc4->hvs && vc4->hvs->hvs5)
clk_request_done(core_req);

drm_atomic_state_put(state);
}

static void commit_work(struct work_struct *work)
{
struct drm_atomic_state *state = container_of(work,
struct drm_atomic_state,
commit_work);
vc4_atomic_complete_commit(state);
}

static int vc4_atomic_commit_setup(struct drm_atomic_state *state)
{
struct drm_device *dev = state->dev;
struct vc4_dev *vc4 = to_vc4_dev(dev);
struct drm_crtc_state *crtc_state;
struct vc4_hvs_state *hvs_state;
struct drm_crtc *crtc;
unsigned int i;

/* We know for sure we don't want an async update here. Set
* state->legacy_cursor_update to false to prevent
* drm_atomic_helper_setup_commit() from auto-completing
* commit->flip_done.
*/
if (!vc4->firmware_kms)
state->legacy_cursor_update = false;

hvs_state = vc4_hvs_get_new_global_state(state);
if (!hvs_state)
return -EINVAL;
Expand All @@ -464,95 +457,6 @@ static int vc4_atomic_commit_setup(struct drm_atomic_state *state)
return 0;
}

/**
* vc4_atomic_commit - commit validated state object
* @dev: DRM device
* @state: the driver state object
* @nonblock: nonblocking commit
*
* This function commits a with drm_atomic_helper_check() pre-validated state
* object. This can still fail when e.g. the framebuffer reservation fails. For
* now this doesn't implement asynchronous commits.
*
* RETURNS
* Zero for success or -errno.
*/
static int vc4_atomic_commit(struct drm_device *dev,
struct drm_atomic_state *state,
bool nonblock)
{
int ret;

if (state->async_update) {
ret = drm_atomic_helper_prepare_planes(dev, state);
if (ret)
return ret;

drm_atomic_helper_async_commit(dev, state);

drm_atomic_helper_cleanup_planes(dev, state);

return 0;
}

/* We know for sure we don't want an async update here. Set
* state->legacy_cursor_update to false to prevent
* drm_atomic_helper_setup_commit() from auto-completing
* commit->flip_done.
*/
if (!vc4->firmware_kms)
state->legacy_cursor_update = false;
ret = drm_atomic_helper_setup_commit(state, nonblock);
if (ret)
return ret;

INIT_WORK(&state->commit_work, commit_work);

ret = drm_atomic_helper_prepare_planes(dev, state);
if (ret)
return ret;

if (!nonblock) {
ret = drm_atomic_helper_wait_for_fences(dev, state, true);
if (ret) {
drm_atomic_helper_cleanup_planes(dev, state);
return ret;
}
}

/*
* This is the point of no return - everything below never fails except
* when the hw goes bonghits. Which means we can commit the new state on
* the software side now.
*/

BUG_ON(drm_atomic_helper_swap_state(state, false) < 0);

/*
* Everything below can be run asynchronously without the need to grab
* any modeset locks at all under one condition: It must be guaranteed
* that the asynchronous work has either been cancelled (if the driver
* supports it, which at least requires that the framebuffers get
* cleaned up with drm_atomic_helper_cleanup_planes()) or completed
* before the new state gets committed on the software side with
* drm_atomic_helper_swap_state().
*
* This scheme allows new atomic state updates to be prepared and
* checked in parallel to the asynchronous completion of the previous
* update. Which is important since compositors need to figure out the
* composition of the next frame right after having submitted the
* current layout.
*/

drm_atomic_state_get(state);
if (nonblock)
queue_work(system_unbound_wq, &state->commit_work);
else
vc4_atomic_complete_commit(state);

return 0;
}

static struct drm_framebuffer *vc4_fb_create(struct drm_device *dev,
struct drm_file *file_priv,
const struct drm_mode_fb_cmd2 *mode_cmd)
Expand Down Expand Up @@ -777,7 +681,6 @@ vc4_hvs_channels_duplicate_state(struct drm_private_obj *obj)

__drm_atomic_helper_private_obj_duplicate_state(obj, &state->base);


for (i = 0; i < HVS_NUM_CHANNELS; i++) {
state->fifo_state[i].in_use = old_state->fifo_state[i].in_use;

Expand Down Expand Up @@ -968,11 +871,12 @@ vc4_atomic_check(struct drm_device *dev, struct drm_atomic_state *state)

static struct drm_mode_config_helper_funcs vc4_mode_config_helpers = {
.atomic_commit_setup = vc4_atomic_commit_setup,
.atomic_commit_tail = vc4_atomic_commit_tail,
};

static const struct drm_mode_config_funcs vc4_mode_funcs = {
.atomic_check = vc4_atomic_check,
.atomic_commit = vc4_atomic_commit,
.atomic_commit = drm_atomic_helper_commit,
.fb_create = vc4_fb_create,
};

Expand Down

0 comments on commit 2f3e2d8

Please sign in to comment.