Skip to contentSkip to conversation

drm/exynos: rewrite fimg2d error handling

PATCH In review Tobias Jakobi 2 participants 12 messages Sep 8, 2015 – Sep 21, 2015 Arm Samsung Exynos

lore
Share & tools
lore
#0 lore raw

v2 cover drm/exynos: rewrite fimg2d error handling

Hello,

during the discussion about the last patchset touching the fimg2d code, it became apparent that the error handling for the command submission is currently unsatisfactory.

This series rewrites the handling. All functions that submit command buffers now first check if enough space is available and only then proceed to build the command buffers.

In particular the command buffer is no longer left in a half-finished state, since parameters passed to the functions are now validated before command submission. For this some validation functions are introduced.

This should also increase performance if the bottleneck is the submission part, since adding commands to the buffer is now more lightweight.

Last but not least some prefix was added to messages printed by fprintf and printf, and the G2D context struct was moved out of the public header.

Please review and let me know if I can improve anything!

With best wishes,
Tobias

Changes since v1:
- squashed some of the patches together (suggested by Inki)
- changed return value of validate functions (suggested by Inki)
- added some more explanatory comments (suggested by Emil)

Tobias Jakobi (9):
exynos/fimg2d: fix empty buffer handling in g2d_flush() exynos/fimg2d: simplify base address submission in

    g2d_scale_and_blend()

exynos/fimg2d: add g2d_check_space()
exynos/fimg2d: add g2d_validate_xyz() functions exynos/fimg2d: remove default case from g2d_get_blend_op() exynos/fimg2d: remove superfluous initialization of g2d_point_val exynos/fimg2d: make g2d_add_cmd() less heavy exynos/fimg2d: add message prefix
exynos/fimg2d: remove g2d_context from public header

 exynos/exynos_fimg2d.c | 376 ++++++++++++++++++++++++++++++-------------------
 exynos/exynos_fimg2d.h |  14 +-
 2 files changed, 231 insertions(+), 159 deletions(-)
Signature · 1 line
2.0.5
#1 lore raw

PATCH v2 1/9 exynos/fimg2d: fix empty buffer handling in g2d_flush()

Empty command buffers are no error, we just don't have anything to do for flushing then.

---
 exynos/exynos_fimg2d.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
exynos/exynos_fimg2d.c +1 -1
index 24a06d0..4a88e0c 100644
@@ -191,7 +191,7 @@ static int g2d_flush(struct g2d_context *ctx)
 	struct drm_exynos_g2d_set_cmdlist cmdlist = {0};
 
 	if (ctx->cmd_nr == 0 && ctx->cmd_buf_nr == 0)
-		return -1;
+		return 0;
 
 	if (ctx->cmdlist_nr >= G2D_MAX_CMD_LIST_NR) {
 		fprintf(stderr, "Overflow cmdlist.\n");
Signature · 1 line
2.0.5
#2 lore raw

PATCH v2 2/9 exynos/fimg2d: simplify base address submission in g2d_scale_and_blend()

In reply to Tobias Jakobi

Use g2d_add_base_addr() for source and destination base address just like all other calls.

---
 exynos/exynos_fimg2d.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)
exynos/exynos_fimg2d.c +2 -12
index 4a88e0c..85b2317 100644
@@ -672,12 +672,7 @@ g2d_scale_and_blend(struct g2d_context *ctx, struct g2d_image *src,
 		g2d_add_cmd(ctx, DST_SELECT_REG, G2D_SELECT_MODE_NORMAL);
 
 	g2d_add_cmd(ctx, DST_COLOR_MODE_REG, dst->color_mode);
-	if (dst->buf_type == G2D_IMGBUF_USERPTR)
-		g2d_add_cmd(ctx, DST_BASE_ADDR_REG | G2D_BUF_USERPTR,
-				(unsigned long)&dst->user_ptr[0]);
-	else
-		g2d_add_cmd(ctx, DST_BASE_ADDR_REG, dst->bo[0]);
-
+	g2d_add_base_addr(ctx, dst, g2d_dst);
 	g2d_add_cmd(ctx, DST_STRIDE_REG, dst->stride);
 
 	g2d_add_cmd(ctx, SRC_SELECT_REG, src->select_mode);
@@ -685,12 +680,7 @@ g2d_scale_and_blend(struct g2d_context *ctx, struct g2d_image *src,
 
 	switch (src->select_mode) {
 	case G2D_SELECT_MODE_NORMAL:
-		if (src->buf_type == G2D_IMGBUF_USERPTR)
-			g2d_add_cmd(ctx, SRC_BASE_ADDR_REG | G2D_BUF_USERPTR,
-					(unsigned long)&src->user_ptr[0]);
-		else
-			g2d_add_cmd(ctx, SRC_BASE_ADDR_REG, src->bo[0]);
-
+		g2d_add_base_addr(ctx, src, g2d_src);
 		g2d_add_cmd(ctx, SRC_STRIDE_REG, src->stride);
 		break;
 	case G2D_SELECT_MODE_FGCOLOR:
Signature · 6 lines
2.0.5

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#3 lore raw

PATCH v2 3/9 exynos/fimg2d: add g2d_check_space()

In reply to Tobias Jakobi

This is going to be used to check if the command buffers have enough space left prior to actual submission of the commands.

Use this in g2d_{solid_fill,copy,copy_with_scale}().

For this the parameter validation before buffer space checking so that we can exit early if it fails. Also don't reset the G2D context in this situation since the buffers are not partially submitted anymore.

The repeat mode in g2d_copy_with_scale() is checked first to make computation of space easier.

---
 exynos/exynos_fimg2d.c | 99 ++++++++++++++++++++++++++++++++------------------
 1 file changed, 64 insertions(+), 35 deletions(-)
exynos/exynos_fimg2d.c +64 -35
index 85b2317..2e04f4a 100644
@@ -102,6 +102,23 @@ static unsigned int g2d_get_blend_op(enum e_g2d_op op)
 }
 
 /*
+ * g2d_check_space - check if command buffers have enough space left.
+ *
+ * @ctx: a pointer to g2d_context structure.
+ * @num_cmds: number of (regular) commands.
+ * @num_gem_cmds: number of GEM commands.
+ */
+static unsigned int g2d_check_space(const struct g2d_context *ctx,
+	unsigned int num_cmds, unsigned int num_gem_cmds)
+{
+	if (ctx->cmd_nr + num_cmds >= G2D_MAX_CMD_NR ||
+	    ctx->cmd_buf_nr + num_gem_cmds >= G2D_MAX_GEM_CMD_NR)
+		return 1;
+	else
+		return 0;
+}
+
+/*
  * g2d_add_cmd - set given command and value to user side command buffer.
  *
  * @ctx: a pointer to g2d_context structure.
@@ -302,6 +319,9 @@ g2d_solid_fill(struct g2d_context *ctx, struct g2d_image *img,
 	union g2d_bitblt_cmd_val bitblt;
 	union g2d_point_val pt;
 
+	if (g2d_check_space(ctx, 7, 1))
+		return -ENOSPC;
+
 	g2d_add_cmd(ctx, DST_SELECT_REG, G2D_SELECT_MODE_NORMAL);
 	g2d_add_cmd(ctx, DST_COLOR_MODE_REG, img->color_mode);
 	g2d_add_base_addr(ctx, img, g2d_dst);
@@ -355,17 +375,7 @@ g2d_copy(struct g2d_context *ctx, struct g2d_image *src,
 {
 	union g2d_rop4_val rop4;
 	union g2d_point_val pt;
-	unsigned int src_w = 0, src_h = 0, dst_w = 0, dst_h = 0;
-
-	g2d_add_cmd(ctx, DST_SELECT_REG, G2D_SELECT_MODE_BGCOLOR);
-	g2d_add_cmd(ctx, DST_COLOR_MODE_REG, dst->color_mode);
-	g2d_add_base_addr(ctx, dst, g2d_dst);
-	g2d_add_cmd(ctx, DST_STRIDE_REG, dst->stride);
-
-	g2d_add_cmd(ctx, SRC_SELECT_REG, G2D_SELECT_MODE_NORMAL);
-	g2d_add_cmd(ctx, SRC_COLOR_MODE_REG, src->color_mode);
-	g2d_add_base_addr(ctx, src, g2d_src);
-	g2d_add_cmd(ctx, SRC_STRIDE_REG, src->stride);
+	unsigned int src_w, src_h, dst_w, dst_h;
 
 	src_w = w;
 	src_h = h;
@@ -386,10 +396,22 @@ g2d_copy(struct g2d_context *ctx, struct g2d_image *src,
 
 	if (w <= 0 || h <= 0) {
 		fprintf(stderr, "invalid width or height.\n");
-		g2d_reset(ctx);
 		return -EINVAL;
 	}
 
+	if (g2d_check_space(ctx, 11, 2))
+		return -ENOSPC;
+
+	g2d_add_cmd(ctx, DST_SELECT_REG, G2D_SELECT_MODE_BGCOLOR);
+	g2d_add_cmd(ctx, DST_COLOR_MODE_REG, dst->color_mode);
+	g2d_add_base_addr(ctx, dst, g2d_dst);
+	g2d_add_cmd(ctx, DST_STRIDE_REG, dst->stride);
+
+	g2d_add_cmd(ctx, SRC_SELECT_REG, G2D_SELECT_MODE_NORMAL);
+	g2d_add_cmd(ctx, SRC_COLOR_MODE_REG, src->color_mode);
+	g2d_add_base_addr(ctx, src, g2d_src);
+	g2d_add_cmd(ctx, SRC_STRIDE_REG, src->stride);
+
 	pt.val = 0;
 	pt.data.x = src_x;
 	pt.data.y = src_y;
@@ -445,23 +467,12 @@ g2d_copy_with_scale(struct g2d_context *ctx, struct g2d_image *src,
 {
 	union g2d_rop4_val rop4;
 	union g2d_point_val pt;
-	unsigned int scale;
+	unsigned int scale, repeat_pad;
 	unsigned int scale_x, scale_y;
 
-	g2d_add_cmd(ctx, DST_SELECT_REG, G2D_SELECT_MODE_BGCOLOR);
-	g2d_add_cmd(ctx, DST_COLOR_MODE_REG, dst->color_mode);
-	g2d_add_base_addr(ctx, dst, g2d_dst);
-	g2d_add_cmd(ctx, DST_STRIDE_REG, dst->stride);
-
-	g2d_add_cmd(ctx, SRC_SELECT_REG, G2D_SELECT_MODE_NORMAL);
-	g2d_add_cmd(ctx, SRC_COLOR_MODE_REG, src->color_mode);
-
-	g2d_add_cmd(ctx, SRC_REPEAT_MODE_REG, src->repeat_mode);
-	if (src->repeat_mode == G2D_REPEAT_MODE_PAD)
-		g2d_add_cmd(ctx, SRC_PAD_VALUE_REG, dst->color);
-
-	g2d_add_base_addr(ctx, src, g2d_src);
-	g2d_add_cmd(ctx, SRC_STRIDE_REG, src->stride);
+	/* Sanitize this parameter to facilitate space computation below. */
+	if (negative)
+		negative = 1;
 
 	if (src_w == dst_w && src_h == dst_h)
 		scale = 0;
@@ -471,6 +482,8 @@ g2d_copy_with_scale(struct g2d_context *ctx, struct g2d_image *src,
 		scale_y = g2d_get_scaling(src_h, dst_h);
 	}
 
+	repeat_pad = src->repeat_mode == G2D_REPEAT_MODE_PAD ? 1 : 0;
+
 	if (src_x + src_w > src->width)
 		src_w = src->width - src_x;
 	if (src_y + src_h > src->height)
@@ -483,21 +496,37 @@ g2d_copy_with_scale(struct g2d_context *ctx, struct g2d_image *src,
 
 	if (src_w <= 0 || src_h <= 0 || dst_w <= 0 || dst_h <= 0) {
 		fprintf(stderr, "invalid width or height.\n");
-		g2d_reset(ctx);
 		return -EINVAL;
 	}
 
+	if (g2d_check_space(ctx, 12 + scale * 3 + negative + repeat_pad, 2))
+		return -ENOSPC;
+
+	g2d_add_cmd(ctx, DST_SELECT_REG, G2D_SELECT_MODE_BGCOLOR);
+	g2d_add_cmd(ctx, DST_COLOR_MODE_REG, dst->color_mode);
+	g2d_add_base_addr(ctx, dst, g2d_dst);
+	g2d_add_cmd(ctx, DST_STRIDE_REG, dst->stride);
+
+	g2d_add_cmd(ctx, SRC_SELECT_REG, G2D_SELECT_MODE_NORMAL);
+	g2d_add_cmd(ctx, SRC_COLOR_MODE_REG, src->color_mode);
+
+	g2d_add_cmd(ctx, SRC_REPEAT_MODE_REG, src->repeat_mode);
+	if (repeat_pad)
+		g2d_add_cmd(ctx, SRC_PAD_VALUE_REG, dst->color);
+
+	g2d_add_base_addr(ctx, src, g2d_src);
+	g2d_add_cmd(ctx, SRC_STRIDE_REG, src->stride);
+
+	rop4.val = 0;
+	rop4.data.unmasked_rop3 = G2D_ROP3_SRC;
+
 	if (negative) {
 		g2d_add_cmd(ctx, BG_COLOR_REG, 0x00FFFFFF);
-		rop4.val = 0;
-		rop4.data.unmasked_rop3 = G2D_ROP3_SRC^G2D_ROP3_DST;
-		g2d_add_cmd(ctx, ROP4_REG, rop4.val);
-	} else {
-		rop4.val = 0;
-		rop4.data.unmasked_rop3 = G2D_ROP3_SRC;
-		g2d_add_cmd(ctx, ROP4_REG, rop4.val);
+		rop4.data.unmasked_rop3 ^= G2D_ROP3_DST;
 	}
 
+	g2d_add_cmd(ctx, ROP4_REG, rop4.val);
+
 	if (scale) {
 		g2d_add_cmd(ctx, SRC_SCALE_CTRL_REG, G2D_SCALE_MODE_BILINEAR);
 		g2d_add_cmd(ctx, SRC_XSCALE_REG, scale_x);
Signature · 1 line
2.0.5
#4 lore raw

PATCH v2 4/9 exynos/fimg2d: add g2d_validate_xyz() functions

In reply to Tobias Jakobi

The G2D headers define a number of modes through enums (like e.g. color, select, repeat, etc.).

This introduces g2d_validate_select_mode() and g2d_validate_blending_op() which validate a select mode or blending operation respectively.

Use this together with g2d_check_space() in g2d_{blend,scale_and_blend}().

For this we move parameter validation to the top and also validate the select mode of the source image and the requested blending operation before starting command submission.

---
 exynos/exynos_fimg2d.c | 181 ++++++++++++++++++++++++++++++++++---------------
 1 file changed, 126 insertions(+), 55 deletions(-)
exynos/exynos_fimg2d.c +126 -55
index 2e04f4a..9d9359a 100644
@@ -119,6 +119,54 @@ static unsigned int g2d_check_space(const struct g2d_context *ctx,
 }
 
 /*
+ * g2d_validate_select_mode - validate select mode.
+ *
+ * @mode: the mode to validate
+ *
+ * Returns zero for an invalid mode and one otherwise.
+ */
+static int g2d_validate_select_mode(
+	enum e_g2d_select_mode mode)
+{
+	switch (mode) {
+	case G2D_SELECT_MODE_NORMAL:
+	case G2D_SELECT_MODE_FGCOLOR:
+	case G2D_SELECT_MODE_BGCOLOR:
+		return 1;
+	}
+
+	return 0;
+}
+
+/*
+ * g2d_validate_blending_op - validate blending operation.
+ *
+ * @operation: the operation to validate
+ *
+ * Returns zero for an invalid mode and one otherwise.
+ */
+static int g2d_validate_blending_op(
+	enum e_g2d_op operation)
+{
+	switch (operation) {
+	case G2D_OP_CLEAR:
+	case G2D_OP_SRC:
+	case G2D_OP_DST:
+	case G2D_OP_OVER:
+	case G2D_OP_INTERPOLATE:
+	case G2D_OP_DISJOINT_CLEAR:
+	case G2D_OP_DISJOINT_SRC:
+	case G2D_OP_DISJOINT_DST:
+	case G2D_OP_CONJOINT_CLEAR:
+	case G2D_OP_CONJOINT_SRC:
+	case G2D_OP_CONJOINT_DST:
+		return 1;
+	}
+
+	return 0;
+}
+
+/*
  * g2d_add_cmd - set given command and value to user side command buffer.
  *
  * @ctx: a pointer to g2d_context structure.
@@ -579,7 +627,45 @@ g2d_blend(struct g2d_context *ctx, struct g2d_image *src,
 	union g2d_point_val pt;
 	union g2d_bitblt_cmd_val bitblt;
 	union g2d_blend_func_val blend;
-	unsigned int src_w = 0, src_h = 0, dst_w = 0, dst_h = 0;
+	unsigned int gem_space;
+	unsigned int src_w, src_h, dst_w, dst_h;
+
+	src_w = w;
+	src_h = h;
+	if (src_x + w > src->width)
+		src_w = src->width - src_x;
+	if (src_y + h > src->height)
+		src_h = src->height - src_y;
+
+	dst_w = w;
+	dst_h = h;
+	if (dst_x + w > dst->width)
+		dst_w = dst->width - dst_x;
+	if (dst_y + h > dst->height)
+		dst_h = dst->height - dst_y;
+
+	w = MIN(src_w, dst_w);
+	h = MIN(src_h, dst_h);
+
+	if (w <= 0 || h <= 0) {
+		fprintf(stderr, "invalid width or height.\n");
+		return -EINVAL;
+	}
+
+	if (!g2d_validate_select_mode(src->select_mode)) {
+		fprintf(stderr , "invalid select mode for source.\n");
+		return -EINVAL;
+	}
+
+	if (!g2d_validate_blending_op(op)) {
+		fprintf(stderr , "unsupported blending operation.\n");
+		return -EINVAL;
+	}
+
+	gem_space = src->select_mode == G2D_SELECT_MODE_NORMAL ? 2 : 1;
+
+	if (g2d_check_space(ctx, 12, gem_space))
+		return -ENOSPC;
 
 	bitblt.val = 0;
 	blend.val = 0;
@@ -607,32 +693,6 @@ g2d_blend(struct g2d_context *ctx, struct g2d_image *src,
 	case G2D_SELECT_MODE_BGCOLOR:
 		g2d_add_cmd(ctx, BG_COLOR_REG, src->color);
 		break;
-	default:
-		fprintf(stderr , "failed to set src.\n");
-		return -EINVAL;
-	}
-
-	src_w = w;
-	src_h = h;
-	if (src_x + w > src->width)
-		src_w = src->width - src_x;
-	if (src_y + h > src->height)
-		src_h = src->height - src_y;
-
-	dst_w = w;
-	dst_h = h;
-	if (dst_x + w > dst->width)
-		dst_w = dst->width - dst_x;
-	if (dst_y + h > dst->height)
-		dst_h = dst->height - dst_y;
-
-	w = MIN(src_w, dst_w);
-	h = MIN(src_h, dst_h);
-
-	if (w <= 0 || h <= 0) {
-		fprintf(stderr, "invalid width or height.\n");
-		g2d_reset(ctx);
-		return -EINVAL;
 	}
 
 	bitblt.data.alpha_blend_mode = G2D_ALPHA_BLEND_MODE_ENABLE;
@@ -689,9 +749,47 @@ g2d_scale_and_blend(struct g2d_context *ctx, struct g2d_image *src,
 	union g2d_point_val pt;
 	union g2d_bitblt_cmd_val bitblt;
 	union g2d_blend_func_val blend;
-	unsigned int scale;
+	unsigned int scale, gem_space;
 	unsigned int scale_x, scale_y;
 
+	if (src_w == dst_w && src_h == dst_h)
+		scale = 0;
+	else {
+		scale = 1;
+		scale_x = g2d_get_scaling(src_w, dst_w);
+		scale_y = g2d_get_scaling(src_h, dst_h);
+	}
+
+	if (src_x + src_w > src->width)
+		src_w = src->width - src_x;
+	if (src_y + src_h > src->height)
+		src_h = src->height - src_y;
+
+	if (dst_x + dst_w > dst->width)
+		dst_w = dst->width - dst_x;
+	if (dst_y + dst_h > dst->height)
+		dst_h = dst->height - dst_y;
+
+	if (src_w <= 0 || src_h <= 0 || dst_w <= 0 || dst_h <= 0) {
+		fprintf(stderr, "invalid width or height.\n");
+		return -EINVAL;
+	}
+
+	if (!g2d_validate_select_mode(src->select_mode)) {
+		fprintf(stderr , "invalid select mode for source.\n");
+		return -EINVAL;
+	}
+
+	if (!g2d_validate_blending_op(op)) {
+		fprintf(stderr , "unsupported blending operation.\n");
+		return -EINVAL;
+	}
+
+	gem_space = src->select_mode == G2D_SELECT_MODE_NORMAL ? 2 : 1;
+
+	if (g2d_check_space(ctx, 12 + scale * 3, gem_space))
+		return -ENOSPC;
+
 	bitblt.val = 0;
 	blend.val = 0;
 
@@ -718,33 +816,6 @@ g2d_scale_and_blend(struct g2d_context *ctx, struct g2d_image *src,
 	case G2D_SELECT_MODE_BGCOLOR:
 		g2d_add_cmd(ctx, BG_COLOR_REG, src->color);
 		break;
-	default:
-		fprintf(stderr , "failed to set src.\n");
-		return -EINVAL;
-	}
-
-	if (src_w == dst_w && src_h == dst_h)
-		scale = 0;
-	else {
-		scale = 1;
-		scale_x = g2d_get_scaling(src_w, dst_w);
-		scale_y = g2d_get_scaling(src_h, dst_h);
-	}
-
-	if (src_x + src_w > src->width)
-		src_w = src->width - src_x;
-	if (src_y + src_h > src->height)
-		src_h = src->height - src_y;
-
-	if (dst_x + dst_w > dst->width)
-		dst_w = dst->width - dst_x;
-	if (dst_y + dst_h > dst->height)
-		dst_h = dst->height - dst_y;
-
-	if (src_w <= 0 || src_h <= 0 || dst_w <= 0 || dst_h <= 0) {
-		fprintf(stderr, "invalid width or height.\n");
-		g2d_reset(ctx);
-		return -EINVAL;
 	}
 
 	if (scale) {
Signature · 6 lines
2.0.5

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#5 lore raw

PATCH v2 5/9 exynos/fimg2d: remove default case from g2d_get_blend_op()

In reply to Tobias Jakobi

We now validate the blending mode via g2d_validate_mode() prior to feeding it to g2d_get_blend_op().

---
 exynos/exynos_fimg2d.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
exynos/exynos_fimg2d.c +5 -5
index 9d9359a..d7cbb24 100644
@@ -64,6 +64,11 @@ static unsigned int g2d_get_blend_op(enum e_g2d_op op)
 
 	val.val = 0;
 
+	/*
+	 * The switch statement is missing the default branch since
+	 * we assume that the caller checks the blending operation
+	 * via g2d_validate_blending_op() first.
+	 */
 	switch (op) {
 	case G2D_OP_CLEAR:
 	case G2D_OP_DISJOINT_CLEAR:
@@ -91,11 +96,6 @@ static unsigned int g2d_get_blend_op(enum e_g2d_op op)
 		SET_BF(val, G2D_COEFF_MODE_SRC_ALPHA, 0, 0, 0,
 				G2D_COEFF_MODE_SRC_ALPHA, 1, 0, 0);
 		break;
-	default:
-		fprintf(stderr, "Not support operation(%d).\n", op);
-		SET_BF(val, G2D_COEFF_MODE_ONE, 0, 0, 0, G2D_COEFF_MODE_ZERO,
-				0, 0, 0);
-		break;
 	}
 
 	return val.val;
Signature · 1 line
2.0.5
#6 lore raw

PATCH v2 6/9 exynos/fimg2d: remove superfluous initialization of g2d_point_val

In reply to Tobias Jakobi

The g2d_point_val union consists of two coordinates of 16 bits. Whenever this union is used though, both coordinates are explicitly set. Hence prior initialization is unnecessary.

---
 exynos/exynos_fimg2d.c | 19 -------------------
 1 file changed, 19 deletions(-)
exynos/exynos_fimg2d.c +0 -19
index d7cbb24..fbc77a3 100644
@@ -380,15 +380,12 @@ g2d_solid_fill(struct g2d_context *ctx, struct g2d_image *img,
 	if (y + h > img->height)
 		h = img->height - y;
 
-	pt.val = 0;
 	pt.data.x = x;
 	pt.data.y = y;
 	g2d_add_cmd(ctx, DST_LEFT_TOP_REG, pt.val);
 
-	pt.val = 0;
 	pt.data.x = x + w;
 	pt.data.y = y + h;
-
 	g2d_add_cmd(ctx, DST_RIGHT_BOTTOM_REG, pt.val);
 
 	g2d_add_cmd(ctx, SF_COLOR_REG, img->color);
@@ -460,20 +457,16 @@ g2d_copy(struct g2d_context *ctx, struct g2d_image *src,
 	g2d_add_base_addr(ctx, src, g2d_src);
 	g2d_add_cmd(ctx, SRC_STRIDE_REG, src->stride);
 
-	pt.val = 0;
 	pt.data.x = src_x;
 	pt.data.y = src_y;
 	g2d_add_cmd(ctx, SRC_LEFT_TOP_REG, pt.val);
-	pt.val = 0;
 	pt.data.x = src_x + w;
 	pt.data.y = src_y + h;
 	g2d_add_cmd(ctx, SRC_RIGHT_BOTTOM_REG, pt.val);
 
-	pt.val = 0;
 	pt.data.x = dst_x;
 	pt.data.y = dst_y;
 	g2d_add_cmd(ctx, DST_LEFT_TOP_REG, pt.val);
-	pt.val = 0;
 	pt.data.x = dst_x + w;
 	pt.data.y = dst_y + h;
 	g2d_add_cmd(ctx, DST_RIGHT_BOTTOM_REG, pt.val);
@@ -581,20 +574,16 @@ g2d_copy_with_scale(struct g2d_context *ctx, struct g2d_image *src,
 		g2d_add_cmd(ctx, SRC_YSCALE_REG, scale_y);
 	}
 
-	pt.val = 0;
 	pt.data.x = src_x;
 	pt.data.y = src_y;
 	g2d_add_cmd(ctx, SRC_LEFT_TOP_REG, pt.val);
-	pt.val = 0;
 	pt.data.x = src_x + src_w;
 	pt.data.y = src_y + src_h;
 	g2d_add_cmd(ctx, SRC_RIGHT_BOTTOM_REG, pt.val);
 
-	pt.val = 0;
 	pt.data.x = dst_x;
 	pt.data.y = dst_y;
 	g2d_add_cmd(ctx, DST_LEFT_TOP_REG, pt.val);
-	pt.val = 0;
 	pt.data.x = dst_x + dst_w;
 	pt.data.y = dst_y + dst_h;
 	g2d_add_cmd(ctx, DST_RIGHT_BOTTOM_REG, pt.val);
@@ -700,20 +689,16 @@ g2d_blend(struct g2d_context *ctx, struct g2d_image *src,
 	g2d_add_cmd(ctx, BITBLT_COMMAND_REG, bitblt.val);
 	g2d_add_cmd(ctx, BLEND_FUNCTION_REG, blend.val);
 
-	pt.val = 0;
 	pt.data.x = src_x;
 	pt.data.y = src_y;
 	g2d_add_cmd(ctx, SRC_LEFT_TOP_REG, pt.val);
-	pt.val = 0;
 	pt.data.x = src_x + w;
 	pt.data.y = src_y + h;
 	g2d_add_cmd(ctx, SRC_RIGHT_BOTTOM_REG, pt.val);
 
-	pt.val = 0;
 	pt.data.x = dst_x;
 	pt.data.y = dst_y;
 	g2d_add_cmd(ctx, DST_LEFT_TOP_REG, pt.val);
-	pt.val = 0;
 	pt.data.x = dst_x + w;
 	pt.data.y = dst_y + h;
 	g2d_add_cmd(ctx, DST_RIGHT_BOTTOM_REG, pt.val);
@@ -829,20 +814,16 @@ g2d_scale_and_blend(struct g2d_context *ctx, struct g2d_image *src,
 	g2d_add_cmd(ctx, BITBLT_COMMAND_REG, bitblt.val);
 	g2d_add_cmd(ctx, BLEND_FUNCTION_REG, blend.val);
 
-	pt.val = 0;
 	pt.data.x = src_x;
 	pt.data.y = src_y;
 	g2d_add_cmd(ctx, SRC_LEFT_TOP_REG, pt.val);
-	pt.val = 0;
 	pt.data.x = src_x + src_w;
 	pt.data.y = src_y + src_h;
 	g2d_add_cmd(ctx, SRC_RIGHT_BOTTOM_REG, pt.val);
 
-	pt.val = 0;
 	pt.data.x = dst_x;
 	pt.data.y = dst_y;
 	g2d_add_cmd(ctx, DST_LEFT_TOP_REG, pt.val);
-	pt.val = 0;
 	pt.data.x = dst_x + dst_w;
 	pt.data.y = dst_y + dst_h;
 	g2d_add_cmd(ctx, DST_RIGHT_BOTTOM_REG, pt.val);
Signature · 6 lines
2.0.5

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#7 lore raw

PATCH v2 7/9 exynos/fimg2d: make g2d_add_cmd() less heavy

In reply to Tobias Jakobi

The function currently checks for each added command if an overflow of the corresponding command buffers occurs, but none of the callers ever checks the return value.

Since all callers are now converted to use g2d_check_space() simplify the function.

(1) The overflow checks become asserts, so they're only active for debug builds. This is fine since g2d_add_cmd() is not part of the public API.

(2) Switch the return value to void.

(3) Explicitly state that the caller has to check buffer space before calling g2d_add_cmd().

---
 exynos/exynos_fimg2d.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)
exynos/exynos_fimg2d.c +7 -11
index fbc77a3..5873fe7 100644
@@ -18,6 +18,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
+#include <assert.h>
 
 #include <sys/mman.h>
 #include <linux/stddef.h>
@@ -172,8 +173,11 @@ static int g2d_validate_blending_op(
  * @ctx: a pointer to g2d_context structure.
  * @cmd: command data.
  * @value: value data.
+ *
+ * The caller has to make sure that the commands buffers have enough space
+ * left to hold the command. Use g2d_check_space() to ensure this.
  */
-static int g2d_add_cmd(struct g2d_context *ctx, unsigned long cmd,
+static void g2d_add_cmd(struct g2d_context *ctx, unsigned long cmd,
 			unsigned long value)
 {
 	switch (cmd & ~(G2D_BUF_USERPTR)) {
@@ -183,28 +187,20 @@ static int g2d_add_cmd(struct g2d_context *ctx, unsigned long cmd,
 	case DST_PLANE2_BASE_ADDR_REG:
 	case PAT_BASE_ADDR_REG:
 	case MASK_BASE_ADDR_REG:
-		if (ctx->cmd_buf_nr >= G2D_MAX_GEM_CMD_NR) {
-			fprintf(stderr, "Overflow cmd_gem size.\n");
-			return -EINVAL;
-		}
+		assert(ctx->cmd_buf_nr < G2D_MAX_GEM_CMD_NR);
 
 		ctx->cmd_buf[ctx->cmd_buf_nr].offset = cmd;
 		ctx->cmd_buf[ctx->cmd_buf_nr].data = value;
 		ctx->cmd_buf_nr++;
 		break;
 	default:
-		if (ctx->cmd_nr >= G2D_MAX_CMD_NR) {
-			fprintf(stderr, "Overflow cmd size.\n");
-			return -EINVAL;
-		}
+		assert(ctx->cmd_nr < G2D_MAX_CMD_NR);
 
 		ctx->cmd[ctx->cmd_nr].offset = cmd;
 		ctx->cmd[ctx->cmd_nr].data = value;
 		ctx->cmd_nr++;
 		break;
 	}
-
-	return 0;
 }
 
 /*
Signature · 1 line
2.0.5
#8 lore raw

PATCH v2 8/9 exynos/fimg2d: add message prefix

In reply to Tobias Jakobi

Add a prefix to the messages printed to the console via printf() and fprintf() so that one can easily see where the message comes from.

---
 exynos/exynos_fimg2d.c | 30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)
exynos/exynos_fimg2d.c +16 -14
index 5873fe7..9746c21 100644
@@ -42,6 +42,8 @@
 
 #define MIN(a, b)	((a) < (b) ? (a) : (b))
 
+#define MSG_PREFIX "exynos/fimg2d: "
+
 enum g2d_base_addr_reg {
 	g2d_dst = 0,
 	g2d_src
@@ -255,7 +257,7 @@ static int g2d_flush(struct g2d_context *ctx)
 		return 0;
 
 	if (ctx->cmdlist_nr >= G2D_MAX_CMD_LIST_NR) {
-		fprintf(stderr, "Overflow cmdlist.\n");
+		fprintf(stderr, MSG_PREFIX "command list overflow.\n");
 		return -EINVAL;
 	}
 
@@ -271,7 +273,7 @@ static int g2d_flush(struct g2d_context *ctx)
 
 	ret = drmIoctl(ctx->fd, DRM_IOCTL_EXYNOS_G2D_SET_CMDLIST, &cmdlist);
 	if (ret < 0) {
-		fprintf(stderr, "failed to set cmdlist.\n");
+		fprintf(stderr, MSG_PREFIX "failed to set cmdlist.\n");
 		return ret;
 	}
 
@@ -293,7 +295,7 @@ struct g2d_context *g2d_init(int fd)
 
 	ctx = calloc(1, sizeof(*ctx));
 	if (!ctx) {
-		fprintf(stderr, "failed to allocate context.\n");
+		fprintf(stderr, MSG_PREFIX "failed to allocate context.\n");
 		return NULL;
 	}
 
@@ -301,7 +303,7 @@ struct g2d_context *g2d_init(int fd)
 
 	ret = drmIoctl(fd, DRM_IOCTL_EXYNOS_G2D_GET_VER, &ver);
 	if (ret < 0) {
-		fprintf(stderr, "failed to get version.\n");
+		fprintf(stderr, MSG_PREFIX "failed to get version.\n");
 		free(ctx);
 		return NULL;
 	}
@@ -309,7 +311,7 @@ struct g2d_context *g2d_init(int fd)
 	ctx->major = ver.major;
 	ctx->minor = ver.minor;
 
-	printf("g2d version(%d.%d).\n", ctx->major, ctx->minor);
+	printf(MSG_PREFIX "G2D version (%d.%d).\n", ctx->major, ctx->minor);
 	return ctx;
 }
 
@@ -335,7 +337,7 @@ int g2d_exec(struct g2d_context *ctx)
 
 	ret = drmIoctl(ctx->fd, DRM_IOCTL_EXYNOS_G2D_EXEC, &exec);
 	if (ret < 0) {
-		fprintf(stderr, "failed to execute.\n");
+		fprintf(stderr, MSG_PREFIX "failed to execute.\n");
 		return ret;
 	}
 
@@ -436,7 +438,7 @@ g2d_copy(struct g2d_context *ctx, struct g2d_image *src,
 	h = MIN(src_h, dst_h);
 
 	if (w <= 0 || h <= 0) {
-		fprintf(stderr, "invalid width or height.\n");
+		fprintf(stderr, MSG_PREFIX "invalid width or height.\n");
 		return -EINVAL;
 	}
 
@@ -532,7 +534,7 @@ g2d_copy_with_scale(struct g2d_context *ctx, struct g2d_image *src,
 		dst_h = dst->height - dst_y;
 
 	if (src_w <= 0 || src_h <= 0 || dst_w <= 0 || dst_h <= 0) {
-		fprintf(stderr, "invalid width or height.\n");
+		fprintf(stderr, MSG_PREFIX "invalid width or height.\n");
 		return -EINVAL;
 	}
 
@@ -633,17 +635,17 @@ g2d_blend(struct g2d_context *ctx, struct g2d_image *src,
 	h = MIN(src_h, dst_h);
 
 	if (w <= 0 || h <= 0) {
-		fprintf(stderr, "invalid width or height.\n");
+		fprintf(stderr, MSG_PREFIX "invalid width or height.\n");
 		return -EINVAL;
 	}
 
 	if (!g2d_validate_select_mode(src->select_mode)) {
-		fprintf(stderr , "invalid select mode for source.\n");
+		fprintf(stderr , MSG_PREFIX "invalid select mode for source.\n");
 		return -EINVAL;
 	}
 
 	if (!g2d_validate_blending_op(op)) {
-		fprintf(stderr , "unsupported blending operation.\n");
+		fprintf(stderr , MSG_PREFIX "unsupported blending operation.\n");
 		return -EINVAL;
 	}
 
@@ -752,17 +754,17 @@ g2d_scale_and_blend(struct g2d_context *ctx, struct g2d_image *src,
 		dst_h = dst->height - dst_y;
 
 	if (src_w <= 0 || src_h <= 0 || dst_w <= 0 || dst_h <= 0) {
-		fprintf(stderr, "invalid width or height.\n");
+		fprintf(stderr, MSG_PREFIX "invalid width or height.\n");
 		return -EINVAL;
 	}
 
 	if (!g2d_validate_select_mode(src->select_mode)) {
-		fprintf(stderr , "invalid select mode for source.\n");
+		fprintf(stderr , MSG_PREFIX "invalid select mode for source.\n");
 		return -EINVAL;
 	}
 
 	if (!g2d_validate_blending_op(op)) {
-		fprintf(stderr , "unsupported blending operation.\n");
+		fprintf(stderr , MSG_PREFIX "unsupported blending operation.\n");
 		return -EINVAL;
 	}
 
Signature · 1 line
2.0.5
#9 lore raw

PATCH v2 9/9 exynos/fimg2d: remove g2d_context from public header

In reply to Tobias Jakobi

All functions from the public API only operation on struct g2d_context*, so this shouldn't break too much.

Make the context private since we don't want the user to modify its content directly. Also remove the defines that were only used for fields of g2d_context.

---
 exynos/exynos_fimg2d.c | 15 +++++++++++++++
 exynos/exynos_fimg2d.h | 14 +-------------
 2 files changed, 16 insertions(+), 13 deletions(-)
exynos/exynos_fimg2d.c +15 -0
index 9746c21..e734144 100644
@@ -44,6 +44,21 @@
 
 #define MSG_PREFIX "exynos/fimg2d: "
 
+#define G2D_MAX_CMD_NR		64
+#define G2D_MAX_GEM_CMD_NR	64
+#define G2D_MAX_CMD_LIST_NR	64
+
+struct g2d_context {
+	int				fd;
+	unsigned int			major;
+	unsigned int			minor;
+	struct drm_exynos_g2d_cmd	cmd[G2D_MAX_CMD_NR];
+	struct drm_exynos_g2d_cmd	cmd_buf[G2D_MAX_GEM_CMD_NR];
+	unsigned int			cmd_nr;
+	unsigned int			cmd_buf_nr;
+	unsigned int			cmdlist_nr;
+};
+
 enum g2d_base_addr_reg {
 	g2d_dst = 0,
 	g2d_src
exynos/exynos_fimg2d.h +1 -13
index 9db0c88..4aa1568 100644
@@ -13,9 +13,6 @@
 #ifndef _FIMG2D_H_
 #define _FIMG2D_H_
 
-#define G2D_MAX_CMD_NR		64
-#define G2D_MAX_GEM_CMD_NR	64
-#define G2D_MAX_CMD_LIST_NR	64
 #define G2D_PLANE_MAX_NR	2
 
 enum e_g2d_color_mode {
@@ -289,16 +286,7 @@ struct g2d_image {
 	void				*mapped_ptr[G2D_PLANE_MAX_NR];
 };
 
-struct g2d_context {
-	int				fd;
-	unsigned int			major;
-	unsigned int			minor;
-	struct drm_exynos_g2d_cmd	cmd[G2D_MAX_CMD_NR];
-	struct drm_exynos_g2d_cmd	cmd_buf[G2D_MAX_GEM_CMD_NR];
-	unsigned int			cmd_nr;
-	unsigned int			cmd_buf_nr;
-	unsigned int			cmdlist_nr;
-};
+struct g2d_context;
 
 struct g2d_context *g2d_init(int fd);
 void g2d_fini(struct g2d_context *ctx);
Signature · 6 lines
2.0.5

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#10 lore raw
In reply to Tobias Jakobi

Hi Tobias,

Quoted 19 lines · Tobias Jakobi

Hello,

during the discussion about the last patchset touching the fimg2d code, it became apparent that the error handling for the command submission is currently unsatisfactory.

This series rewrites the handling. All functions that submit command buffers now first check if enough space is available and only then proceed to build the command buffers.

In particular the command buffer is no longer left in a half-finished state, since parameters passed to the functions are now validated before command submission. For this some validation functions are introduced.

This should also increase performance if the bottleneck is the submission part, since adding commands to the buffer is now more lightweight.

Quoted 7 lines

Last but not least some prefix was added to messages printed by fprintf and printf, and the G2D context struct was moved out of the public header.

Please review and let me know if I can improve anything!

Considering that there were no more objections with the series I've scooped them up.

Thanks for clearing this and sticking around !
Emil
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#11 lore raw

Hey Emil,

Quoted 28 lines · Emil Velikov

Hi Tobias,

Quoted 24 lines · Tobias Jakobi

Hello,

during the discussion about the last patchset touching the fimg2d code, it became apparent that the error handling for the command submission is currently unsatisfactory.

This series rewrites the handling. All functions that submit command buffers now first check if enough space is available and only then proceed to build the command buffers.

In particular the command buffer is no longer left in a half-finished state, since parameters passed to the functions are now validated before command submission. For this some validation functions are introduced.

This should also increase performance if the bottleneck is the submission part, since adding commands to the buffer is now more lightweight.

Last but not least some prefix was added to messages printed by fprintf and printf, and the G2D context struct was moved out of the public header.

Quoted 4 lines
Quoted 2 lines

Please review and let me know if I can improve anything!

Considering that there were no more objections with the series I've scooped them up.

thanks a lot! Going to prepare the next batch then :)

With best wishes,
Tobias

Quoted 4 lines

Thanks for clearing this and sticking around !
Emil

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel