Skip to contentSkip to conversation

drm/komeda: Fix off-by-1 when with readback conn due to rounding

PATCH In review [email protected] 2 participants 3 messages Mar 5, 2021 – Mar 11, 2021

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/komeda: Fix off-by-1 when with readback conn due to rounding

From: Carsten Haitzler <[email protected]>

When setting up a readback conenctor that writes data back to memory rather than to an actual output device (HDMI etc.), rounding was ses to round-down. As the DPU uses a higher internal number of bits when generating a color value, this round-down back to 8bit ended up with everything being off-by one. e.g. #ffffff became #fefefe. This sets rounding to "round" so things end up correct by turning on the round flag (LW_TRC).

---
 drivers/gpu/drm/arm/display/komeda/d71/d71_component.c | 6 +++++-
 drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h      | 1 +
 2 files changed, 6 insertions(+), 1 deletion(-)
drivers/gpu/drm/arm/display/komeda/d71/d71_component.c +5 -1
index 8a02ade369db..d551e79fa0f1 100644
@@ -468,7 +468,11 @@ static void d71_wb_layer_update(struct komeda_component *c,
 	struct komeda_layer_state *st = to_layer_st(state);
 	struct drm_connector_state *conn_st = state->wb_conn->state;
 	struct komeda_fb *kfb = to_kfb(conn_st->writeback_job->fb);
-	u32 ctrl = L_EN | LW_OFM, mask = L_EN | LW_OFM | LW_TBU_EN;
+	/* LW_TRC sets rounding to round not truncate which is needed for
+         * the output of writeback to match the input in the most common
+         * use cases like RGB888 -> RGB888, so set this bit by default */
+	u32 ctrl = L_EN | LW_OFM | LW_TRC;
+	u32 mask = L_EN | LW_OFM | LW_TBU_EN | LW_TRC;
 	u32 __iomem *reg = c->reg;
 
 	d71_layer_update_fb(c, kfb, st->addr);
drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h +1 -0
index e80172a0b320..a8036689d721 100644
@@ -321,6 +321,7 @@
 #define LAYER_WR_FORMAT		0x0D8
 
 /* Layer_WR control bits */
+#define LW_TRC			BIT(1)
 #define LW_OFM			BIT(4)
 #define LW_LALPHA(x)		(((x) & 0xFF) << 8)
 #define LW_A_WCACHE(x)		(((x) & 0xF) << 28)
Signature · 6 lines
2.30.0

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

Hi Carsten, (+James for komeda)

Thanks for typing this up.

Quoted 3 lines · On Fri, Mar 05, 2021 at 04:38:53PM +0000, [email protected] wrote:

From: Carsten Haitzler <[email protected]>

When setting up a readback conenctor that writes data back to memory

s/readback conenctor/writeback connector/ (similar in the subject)

Quoted 1 line

rather than to an actual output device (HDMI etc.), rounding was ses

s/ses/set/

Quoted 1 line

to round-down. As the DPU uses a higher internal number of bits when

"round-down" isn't really accurate - the rounding mode "rounds" based on the most-significant discarded bit - so can round-up too.

Come to think of it, I can't explain 0xff becoming 0xfe, but still, truncation is likely fine.

Quoted 4 lines

generating a color value, this round-down back to 8bit ended up with everything being off-by one. e.g. #ffffff became #fefefe. This sets rounding to "round" so things end up correct by turning on the round flag (LW_TRC).

LW_TRC is the truncation flag. 0: Round, 1: Truncate

Quoted 12 lines
---
 drivers/gpu/drm/arm/display/komeda/d71/d71_component.c | 6 +++++-
 drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h      | 1 +
 2 files changed, 6 insertions(+), 1 deletion(-)
drivers/gpu/drm/arm/display/komeda/d71/d71_component.c +0 -0
index 8a02ade369db..d551e79fa0f1 100644

drivers/gpu/drm/arm/display/komeda/d71/d71_component.c static void d71_wb_layer_update(struct komeda_component *c, · line 473

Quoted 7 lines
drivers/gpu/drm/arm/display/komeda/d71/d71_component.c +3 -1
@@ -468,7 +468,11 @@ static void d71_wb_layer_update(struct komeda_component *c,
 	struct komeda_layer_state *st = to_layer_st(state);
 	struct drm_connector_state *conn_st = state->wb_conn->state;
 	struct komeda_fb *kfb = to_kfb(conn_st->writeback_job->fb);
-	u32 ctrl = L_EN | LW_OFM, mask = L_EN | LW_OFM | LW_TBU_EN;
+	/* LW_TRC sets rounding to round not truncate which is needed for
+         * the output of writeback to match the input in the most common
+         * use cases like RGB888 -> RGB888, so set this bit by default */

/*
* Comment style should be like this
*/

Same as above though - your description is inverted. By setting the LW_TRC bit, you're forcing the hardware to truncate instead of round.

drivers/gpu/drm/arm/display/komeda/d71/d71_component.c static void d71_wb_layer_update(struct komeda_component *c, · line 475

Quoted 2 lines
drivers/gpu/drm/arm/display/komeda/d71/d71_component.c +2 -0
+	u32 ctrl = L_EN | LW_OFM | LW_TRC;
+	u32 mask = L_EN | LW_OFM | LW_TBU_EN | LW_TRC;

Really nitpicking, but I think it'd be good to keep these in the same order as the bits in the register: L_EN | LW_TRC | LW_OFM | LW_TBU_EN

Cheers,
-Brian

Quoted 22 lines
drivers/gpu/drm/arm/display/komeda/d71/d71_component.c +0 -0
 	u32 __iomem *reg = c->reg;
 
 	d71_layer_update_fb(c, kfb, st->addr);
drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h +1 -0
index e80172a0b320..a8036689d721 100644
@@ -321,6 +321,7 @@
 #define LAYER_WR_FORMAT		0x0D8
 
 /* Layer_WR control bits */
+#define LW_TRC			BIT(1)
 #define LW_OFM			BIT(4)
 #define LW_LALPHA(x)		(((x) & 0xFF) << 8)
 #define LW_A_WCACHE(x)		(((x) & 0xF) << 28)
Signature · 6 lines
2.30.0

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

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

#2 lore raw
Quoted 7 lines · Brian Starkey

Hi Carsten, (+James for komeda)

Thanks for typing this up.

Quoted 2 lines · On Fri, Mar 05, 2021 at 04:38:53PM +0000, [email protected] wrote:

From: Carsten Haitzler <[email protected]>

Quoted 7 lines
Quoted 1 line

When setting up a readback conenctor that writes data back to memory

s/readback conenctor/writeback connector/ (similar in the subject)

Quoted 1 line

rather than to an actual output device (HDMI etc.), rounding was ses

s/ses/set/

I swear I re-read the log text... I must be auto-correcting in my head as I read. :)

Quoted 7 lines
Quoted 1 line

to round-down. As the DPU uses a higher internal number of bits when

"round-down" isn't really accurate - the rounding mode "rounds" based on the most-significant discarded bit - so can round-up too.

Come to think of it, I can't explain 0xff becoming 0xfe, but still, truncation is likely fine.

Actually it was the other way - I mixed up the src/dest, but TRC does fix it which is the important bit.

Quoted 31 lines
Quoted 4 lines

generating a color value, this round-down back to 8bit ended up with everything being off-by one. e.g. #ffffff became #fefefe. This sets rounding to "round" so things end up correct by turning on the round flag (LW_TRC).

LW_TRC is the truncation flag. 0: Round, 1: Truncate

Quoted 12 lines
---
  drivers/gpu/drm/arm/display/komeda/d71/d71_component.c | 6 +++++-
  drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h      | 1 +
  2 files changed, 6 insertions(+), 1 deletion(-)
drivers/gpu/drm/arm/display/komeda/d71/d71_component.c +0 -0
index 8a02ade369db..d551e79fa0f1 100644

drivers/gpu/drm/arm/display/komeda/d71/d71_component.c static void d71_wb_layer_update(struct komeda_component *c, · line 473

Quoted 7 lines
drivers/gpu/drm/arm/display/komeda/d71/d71_component.c +3 -1
@@ -468,7 +468,11 @@ static void d71_wb_layer_update(struct komeda_component *c,
  	struct komeda_layer_state *st = to_layer_st(state);
  	struct drm_connector_state *conn_st = state->wb_conn->state;
  	struct komeda_fb *kfb = to_kfb(conn_st->writeback_job->fb);
-	u32 ctrl = L_EN | LW_OFM, mask = L_EN | LW_OFM | LW_TBU_EN;
+	/* LW_TRC sets rounding to round not truncate which is needed for
+         * the output of writeback to match the input in the most common
+         * use cases like RGB888 -> RGB888, so set this bit by default */

/*
* Comment style should be like this
*/

Quoted 2 lines

Same as above though - your description is inverted. By setting the LW_TRC bit, you're forcing the hardware to truncate instead of round.

Yeah - inverted. But the source does have mixed comment styles with some /*
* xxxx
*/

and some

/* xxxx */

and some

/* xxxx
*/

with the last 2 most common.

Quoted 5 lines

drivers/gpu/drm/arm/display/komeda/d71/d71_component.c static void d71_wb_layer_update(struct komeda_component *c, · line 475

Quoted 2 lines
drivers/gpu/drm/arm/display/komeda/d71/d71_component.c +2 -0
+	u32 ctrl = L_EN | LW_OFM | LW_TRC;
+	u32 mask = L_EN | LW_OFM | LW_TBU_EN | LW_TRC;

Really nitpicking, but I think it'd be good to keep these in the same order as the bits in the register: L_EN | LW_TRC | LW_OFM | LW_TBU_EN

I can do that. I'll send another with the above.

Quoted 21 lines

Cheers,
-Brian

Quoted 18 lines
drivers/gpu/drm/arm/display/komeda/d71/d71_component.c +0 -0
  	u32 __iomem *reg = c->reg;
 
  	d71_layer_update_fb(c, kfb, st->addr);
drivers/gpu/drm/arm/display/komeda/d71/d71_regs.h +1 -0
index e80172a0b320..a8036689d721 100644
@@ -321,6 +321,7 @@
  #define LAYER_WR_FORMAT		0x0D8
 
  /* Layer_WR control bits */
+#define LW_TRC			BIT(1)
  #define LW_OFM			BIT(4)
  #define LW_LALPHA(x)		(((x) & 0xFF) << 8)
  #define LW_A_WCACHE(x)		(((x) & 0xF) << 28)
Signature · 1 line
2.30.0
Quoted 4 lines
Quoted 4 lines

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

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