[PATCH v3 6/7] drm/ast: Store VBIOS mode info in struct ast_crtc_state

Thomas Zimmermann tzimmermann at suse.de
Mon Dec 2 11:15:56 UTC 2019


After looking up VBIOS mode information in CRTC's atomic_check(), we
can reuse it in atomic_flush(). No need for a second look-up.

Signed-off-by: Thomas Zimmermann <tzimmermann at suse.de>
---
 drivers/gpu/drm/ast/ast_drv.h  |  2 ++
 drivers/gpu/drm/ast/ast_mode.c | 58 ++++++++++++++++++----------------
 2 files changed, 32 insertions(+), 28 deletions(-)

diff --git a/drivers/gpu/drm/ast/ast_drv.h b/drivers/gpu/drm/ast/ast_drv.h
index e13afb8a706f..72883b5aefa7 100644
--- a/drivers/gpu/drm/ast/ast_drv.h
+++ b/drivers/gpu/drm/ast/ast_drv.h
@@ -283,6 +283,8 @@ struct ast_vbios_mode_info {
 
 struct ast_crtc_state {
 	struct drm_crtc_state base;
+
+	struct ast_vbios_mode_info vbios_mode_info;
 };
 
 #define to_ast_crtc_state(state) container_of(state, struct ast_crtc_state, base)
diff --git a/drivers/gpu/drm/ast/ast_mode.c b/drivers/gpu/drm/ast/ast_mode.c
index 5c226142d493..e9859e9d8f49 100644
--- a/drivers/gpu/drm/ast/ast_mode.c
+++ b/drivers/gpu/drm/ast/ast_mode.c
@@ -784,24 +784,25 @@ static int ast_crtc_helper_atomic_check(struct drm_crtc *crtc,
 {
 	struct ast_private *ast = crtc->dev->dev_private;
 	struct drm_plane_state *plane_state;
+	struct ast_crtc_state *ast_state;
 	bool succ;
-	struct drm_display_mode adjusted_mode;
-	struct ast_vbios_mode_info vbios_mode;
 
 	if (ast->chip == AST1180) {
 		DRM_ERROR("AST 1180 modesetting not supported\n");
 		return -EINVAL;
 	}
 
+	ast_state = to_ast_crtc_state(state);
 	plane_state = crtc->primary->state;
 
-	if (plane_state && plane_state->fb) {
-		succ = ast_get_vbios_mode_info(plane_state->fb->format,
-					       &state->mode, &adjusted_mode,
-					       &vbios_mode);
-		if (!succ)
-			return -EINVAL;
-	}
+	if (!plane_state || !plane_state->fb)
+		return 0;
+
+	succ = ast_get_vbios_mode_info(plane_state->fb->format, &state->mode,
+				       &state->adjusted_mode,
+				       &ast_state->vbios_mode_info);
+	if (!succ)
+		return -EINVAL;
 
 	return 0;
 }
@@ -820,40 +821,36 @@ static void ast_crtc_helper_atomic_flush(struct drm_crtc *crtc,
 	struct drm_device *dev = crtc->dev;
 	struct ast_private *ast = dev->dev_private;
 	const struct drm_framebuffer *fb = crtc->primary->state->fb;
+	struct ast_crtc_state *ast_state;
 	const struct drm_format_info *format;
-	struct drm_display_mode adjusted_mode;
-	struct ast_vbios_mode_info vbios_mode;
-	bool succ;
+	struct ast_vbios_mode_info *vbios_mode_info;
+	struct drm_display_mode *adjusted_mode;
 
 	crtc->state->no_vblank = true;
 
 	if (!fb)
 		return;
 
-	format = fb->format;
+	ast_state = to_ast_crtc_state(crtc->state);
 
-	memset(&adjusted_mode, 0, sizeof(adjusted_mode));
-	drm_mode_copy(&adjusted_mode, &crtc->state->adjusted_mode);
-
-	succ = ast_get_vbios_mode_info(format,
-				       &crtc->state->adjusted_mode,
-				       &adjusted_mode, &vbios_mode);
-	if (WARN_ON_ONCE(!succ))
-		return; /* BUG: didn't validate this in atomic_check() */
+	format = fb->format;
+	vbios_mode_info = &ast_state->vbios_mode_info;
 
 	ast_set_color_reg(ast, format);
-	ast_set_vbios_color_reg(ast, format, &vbios_mode);
+	ast_set_vbios_color_reg(ast, format, vbios_mode_info);
 
 	if (!crtc->state->mode_changed)
 		return;
 
-	ast_set_vbios_mode_reg(ast, &adjusted_mode, &vbios_mode);
+	adjusted_mode = &crtc->state->adjusted_mode;
+
+	ast_set_vbios_mode_reg(ast, adjusted_mode, vbios_mode_info);
 	ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xa1, 0x06);
-	ast_set_std_reg(ast, &adjusted_mode, &vbios_mode);
-	ast_set_crtc_reg(ast, &adjusted_mode, &vbios_mode);
-	ast_set_dclk_reg(ast, &adjusted_mode, &vbios_mode);
+	ast_set_std_reg(ast, adjusted_mode, vbios_mode_info);
+	ast_set_crtc_reg(ast, adjusted_mode, vbios_mode_info);
+	ast_set_dclk_reg(ast, adjusted_mode, vbios_mode_info);
 	ast_set_crtthd_reg(ast);
-	ast_set_sync_reg(ast, &adjusted_mode, &vbios_mode);
+	ast_set_sync_reg(ast, adjusted_mode, vbios_mode_info);
 }
 
 static void
@@ -887,7 +884,7 @@ static void ast_crtc_destroy(struct drm_crtc *crtc)
 static struct drm_crtc_state *
 ast_crtc_atomic_duplicate_state(struct drm_crtc *crtc)
 {
-        struct ast_crtc_state *new_ast_state;
+        struct ast_crtc_state *new_ast_state, *ast_state;
 
         if (WARN_ON(!crtc->state))
                 return NULL;
@@ -897,6 +894,11 @@ ast_crtc_atomic_duplicate_state(struct drm_crtc *crtc)
                 return NULL;
         __drm_atomic_helper_crtc_duplicate_state(crtc, &new_ast_state->base);
 
+	ast_state = to_ast_crtc_state(crtc->state);
+
+	memcpy(&new_ast_state->vbios_mode_info, &ast_state->vbios_mode_info,
+	       sizeof(new_ast_state->vbios_mode_info));
+
         return &new_ast_state->base;
 }
 
-- 
2.23.0



More information about the dri-devel mailing list