Commit 4b9674e5 authored by Leo Li's avatar Leo Li Committed by Alex Deucher
Browse files

drm/amd/display: Move iteration out of dm_update_crtcs



[Why]
To reduce indent in dm_update_crtcs, and to make it operate on single
instances.

[How]
Move iteration of plane states into atomic_check.
No functional change is intended.

Signed-off-by: default avatarLeo Li <sunpeng.li@amd.com>
Reviewed-by: default avatarNicholas Kazlauskas <nicholas.kazlauskas@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent 9e869063
Loading
Loading
Loading
Loading
+175 −166
Original line number Diff line number Diff line
@@ -5461,15 +5461,15 @@ static void reset_freesync_config_for_crtc(
	       sizeof(new_crtc_state->vrr_infopacket));
}

static int dm_update_crtcs_state(struct amdgpu_display_manager *dm,
static int dm_update_crtc_state(struct amdgpu_display_manager *dm,
				struct drm_atomic_state *state,
				struct drm_crtc *crtc,
				struct drm_crtc_state *old_crtc_state,
				struct drm_crtc_state *new_crtc_state,
				bool enable,
				bool *lock_and_validation_needed)
{
	struct dm_atomic_state *dm_state = NULL;
	struct drm_crtc *crtc;
	struct drm_crtc_state *old_crtc_state, *new_crtc_state;
	int i;
	struct dm_crtc_state *dm_old_crtc_state, *dm_new_crtc_state;
	struct dc_stream_state *new_stream;
	int ret = 0;
@@ -5478,7 +5478,6 @@ static int dm_update_crtcs_state(struct amdgpu_display_manager *dm,
	 * TODO Move this code into dm_crtc_atomic_check once we get rid of dc_validation_set
	 * update changed items
	 */
	for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
	struct amdgpu_crtc *acrtc = NULL;
	struct amdgpu_dm_connector *aconnector = NULL;
	struct drm_connector_state *drm_new_conn_state = NULL, *drm_old_conn_state = NULL;
@@ -5510,7 +5509,7 @@ static int dm_update_crtcs_state(struct amdgpu_display_manager *dm,

		if (IS_ERR(drm_new_conn_state)) {
			ret = PTR_ERR_OR_ZERO(drm_new_conn_state);
				break;
			goto fail;
		}

		dm_new_conn_state = to_dm_connector_state(drm_new_conn_state);
@@ -5531,7 +5530,8 @@ static int dm_update_crtcs_state(struct amdgpu_display_manager *dm,
		if (!new_stream) {
			DRM_DEBUG_DRIVER("%s: Failed to create new stream for crtc %d\n",
					__func__, acrtc->base.base.id);
				break;
			ret = -ENOMEM;
			goto fail;
		}

		dm_new_crtc_state->abm_level = dm_new_conn_state->abm_level;
@@ -5545,7 +5545,7 @@ static int dm_update_crtcs_state(struct amdgpu_display_manager *dm,
	}

	if (!drm_atomic_crtc_needs_modeset(new_crtc_state))
			goto next_crtc;
		goto skip_modeset;

	DRM_DEBUG_DRIVER(
		"amdgpu_crtc id:%d crtc_state_flags: enable:%d, active:%d, "
@@ -5563,7 +5563,7 @@ static int dm_update_crtcs_state(struct amdgpu_display_manager *dm,
	if (!enable) {

		if (!dm_old_crtc_state->stream)
				goto next_crtc;
			goto skip_modeset;

		ret = dm_atomic_get_state(state, &dm_state);
		if (ret)
@@ -5595,10 +5595,10 @@ static int dm_update_crtcs_state(struct amdgpu_display_manager *dm,
		 * TODO: need to dig out the root cause of that
		 */
		if (!aconnector || (!aconnector->dc_sink && aconnector->mst_port))
				goto next_crtc;
			goto skip_modeset;

		if (modereset_required(new_crtc_state))
				goto next_crtc;
			goto skip_modeset;

		if (modeset_required(new_crtc_state, new_stream,
				     dm_old_crtc_state->stream)) {
@@ -5628,7 +5628,7 @@ static int dm_update_crtcs_state(struct amdgpu_display_manager *dm,
		}
	}

next_crtc:
skip_modeset:
	/* Release extra reference */
	if (new_stream)
		 dc_stream_release(new_stream);
@@ -5639,7 +5639,7 @@ static int dm_update_crtcs_state(struct amdgpu_display_manager *dm,
	 */
	if (!(enable && aconnector && new_crtc_state->enable &&
	      new_crtc_state->active))
			continue;
		return 0;
	/*
	 * Given above conditions, the dc state cannot be NULL because:
	 * 1. We're in the process of enabling CRTCs (just been added
@@ -5670,7 +5670,6 @@ static int dm_update_crtcs_state(struct amdgpu_display_manager *dm,
	/* Update Freesync settings. */
	get_freesync_config_for_crtc(dm_new_crtc_state,
				     dm_new_conn_state);
	}

	return ret;

@@ -6019,14 +6018,24 @@ static int amdgpu_dm_atomic_check(struct drm_device *dev,
	}

	/* Disable all crtcs which require disable */
	ret = dm_update_crtcs_state(&adev->dm, state, false, &lock_and_validation_needed);
	if (ret) {
	for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
		ret = dm_update_crtc_state(&adev->dm, state, crtc,
					   old_crtc_state,
					   new_crtc_state,
					   false,
					   &lock_and_validation_needed);
		if (ret)
			goto fail;
	}

	/* Enable all crtcs which require enable */
	ret = dm_update_crtcs_state(&adev->dm, state, true, &lock_and_validation_needed);
	if (ret) {
	for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
		ret = dm_update_crtc_state(&adev->dm, state, crtc,
					   old_crtc_state,
					   new_crtc_state,
					   true,
					   &lock_and_validation_needed);
		if (ret)
			goto fail;
	}