All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 0/9] Add video damage tracking
@ 2023-01-03 21:49 Alexander Graf
  2023-01-03 21:49 ` [PATCH v4 1/9] dm: video: Add damage tracking API Alexander Graf
                   ` (10 more replies)
  0 siblings, 11 replies; 25+ messages in thread
From: Alexander Graf @ 2023-01-03 21:49 UTC (permalink / raw)
  To: u-boot
  Cc: Matthias Brugger, Heinrich Schuchardt, Anatolij Gustschin,
	Simon Glass, Da Xue, Ilias Apalodimas, Jagan Teki,
	Andre Przywara, Neil Armstrong, Philipp Tomsich, Kever Yang,
	Patrick Delaunay, Patrice Chotard, uboot-stm32, u-boot-amlogic

This patch set speeds up graphics output on ARM by a factor of 60x.

On most ARM SBCs, we keep the frame buffer in DRAM and map it as cached,
but need it accessible by the display controller which reads directly
from a later point of consistency. Hence, we flush the frame buffer to
DRAM on every change. The full frame buffer.

Unfortunately, with the advent of 4k displays, we are seeing frame buffers
that can take a while to flush out. This was reported by Da Xue with grub,
which happily print 1000s of spaces on the screen to draw a menu. Every
printed space triggers a cache flush.

This patch set implements the easiest mitigation against this problem:
Damage tracking. We remember the lowest common denominator region that was
touched since the last video_sync() call and only flush that. The most
typical writer to the frame buffer is the video console, which always
writes rectangles of characters on the screen and syncs afterwards.

With this patch set applied, we reduce drawing a large grub menu (with
serial console attached for size information) on an RK3399-ROC system
at 1440p from 55 seconds to less than 1 second.

Version 2 also implements VIDEO_COPY using this mechanism, reducing its
overhead compared to before as well. So even x86 systems should be faster
with this now :).


Alternatives considered:

  1) Lazy sync - Sandbox does this. It only calls video_sync(true) ever
     so often. We are missing timers to do this generically.

  2) Double buffering - We could try to identify whether anything changed
     at all and only draw to the FB if it did. That would require
     maintaining a second buffer that we need to scan.

  3) Text buffer - Maintain a buffer of all text printed on the screen with
     respective location. Don't write if the old and new character are
     identical. This would limit applicability to text only and is an
     optimization on top of this patch set.

  4) Hash screen lines - Create a hash (sha256?) over every line when it
     changes. Only flush when it does. I'm not sure if this would waste
     more time, memory and cache than the current approach. It would make
     full screen updates much more expensive.

v1 -> v2:

  - new patch: video: Use VIDEO_DAMAGE for VIDEO_COPY
  - Remove ifdefs
  - Fix dcache range; we were flushing too much before
  - Fix ranges in truetype target
  - Limit rotate to necessary damange

v2 -> v3:

  - Rebase
  - Adapt to DM_VIDEO always
  - Make CONFIG_COPY always select VIDEO_DAMAGE

v3 -> v4:

  - New patch: video: Always compile cache flushing code
  - New patch: video: Enable VIDEO_DAMAGE for drivers that need it
  - Simplify first damage logic
  - Skip damage on EfiBltVideoToBltBuffer
  - Move damage clear from patch 6 to patch 1
  - Remove VIDEO_DAMAGE default for ARM

Alexander Graf (9):
  dm: video: Add damage tracking API
  dm: video: Add damage notification on display clear
  vidconsole: Add damage notifications to all vidconsole drivers
  video: Add damage notification on bmp display
  efi_loader: GOP: Add damage notification on BLT
  video: Only dcache flush damaged lines
  video: Use VIDEO_DAMAGE for VIDEO_COPY
  video: Always compile cache flushing code
  video: Enable VIDEO_DAMAGE for drivers that need it

 arch/arm/mach-omap2/omap3/Kconfig |   1 +
 arch/arm/mach-sunxi/Kconfig       |   1 +
 drivers/video/Kconfig             |  27 +++++
 drivers/video/console_normal.c    |  22 ++--
 drivers/video/console_rotate.c    |  87 +++++++++-----
 drivers/video/console_truetype.c  |  30 ++---
 drivers/video/exynos/Kconfig      |   1 +
 drivers/video/imx/Kconfig         |   1 +
 drivers/video/meson/Kconfig       |   1 +
 drivers/video/rockchip/Kconfig    |   1 +
 drivers/video/stm32/Kconfig       |   1 +
 drivers/video/vidconsole-uclass.c |  16 ---
 drivers/video/video-uclass.c      | 187 +++++++++++++++++-------------
 drivers/video/video_bmp.c         |   7 +-
 include/video.h                   |  54 ++++-----
 include/video_console.h           |  49 --------
 lib/efi_loader/efi_gop.c          |   6 +
 17 files changed, 251 insertions(+), 241 deletions(-)

-- 
2.37.1 (Apple Git-137.1)


^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH v4 1/9] dm: video: Add damage tracking API
  2023-01-03 21:49 [PATCH v4 0/9] Add video damage tracking Alexander Graf
@ 2023-01-03 21:49 ` Alexander Graf
  2023-01-07  0:13   ` Simon Glass
  2023-01-03 21:49 ` [PATCH v4 2/9] dm: video: Add damage notification on display clear Alexander Graf
                   ` (9 subsequent siblings)
  10 siblings, 1 reply; 25+ messages in thread
From: Alexander Graf @ 2023-01-03 21:49 UTC (permalink / raw)
  To: u-boot
  Cc: Matthias Brugger, Heinrich Schuchardt, Anatolij Gustschin,
	Simon Glass, Da Xue, Ilias Apalodimas, Jagan Teki,
	Andre Przywara, Neil Armstrong, Philipp Tomsich, Kever Yang,
	Patrick Delaunay, Patrice Chotard, uboot-stm32, u-boot-amlogic

We are going to introduce image damage tracking to fasten up screen
refresh on large displays. This patch adds damage tracking for up to
one rectangle of the screen which is typically enough to hold blt or
text print updates. Callers into this API and a reduced dcache flush
code path will follow in later patches.

Signed-off-by: Alexander Graf <agraf@csgraf.de>
Reported-by: Da Xue <da@libre.computer>

---

v1 -> v2:

  - Remove ifdefs

v2 -> v3:

  - Adapt Kconfig to DM always

v3 -> v4:

  - Move damage clear from patch 6 to this one
  - Simplify first damage logic
  - Remove VIDEO_DAMAGE default for ARM
---
 drivers/video/Kconfig        | 13 ++++++++++++
 drivers/video/video-uclass.c | 41 ++++++++++++++++++++++++++++++++++++
 include/video.h              | 29 +++++++++++++++++++++++--
 3 files changed, 81 insertions(+), 2 deletions(-)

diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index f539977d9b..826a1a6587 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -62,6 +62,19 @@ config VIDEO_COPY
 	  To use this, your video driver must set @copy_base in
 	  struct video_uc_plat.
 
+config VIDEO_DAMAGE
+	bool "Enable damage tracking of frame buffer regions"
+	help
+	  On some machines (most ARM), the display frame buffer resides in
+	  RAM. To make the display controller pick up screen updates, we
+	  have to flush frame buffer contents from CPU caches into RAM which
+	  can be a slow operation.
+
+	  This feature adds damage tracking to collect information about regions
+	  that received updates. When we want to sync, we then only flush
+	  regions of the frame buffer that were modified before, speeding up
+	  screen refreshes significantly.
+
 config BACKLIGHT_PWM
 	bool "Generic PWM based Backlight Driver"
 	depends on BACKLIGHT && DM_PWM
diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c
index 0ce376ca3f..d18c8cd2b1 100644
--- a/drivers/video/video-uclass.c
+++ b/drivers/video/video-uclass.c
@@ -21,6 +21,8 @@
 #include <dm/device_compat.h>
 #include <dm/device-internal.h>
 #include <dm/uclass-internal.h>
+#include <linux/types.h>
+#include <linux/bitmap.h>
 #ifdef CONFIG_SANDBOX
 #include <asm/sdl.h>
 #endif
@@ -254,6 +256,37 @@ void video_set_default_colors(struct udevice *dev, bool invert)
 	priv->colour_bg = video_index_to_colour(priv, back);
 }
 
+/* Notify about changes in the frame buffer */
+int video_damage(struct udevice *vid, int x, int y, int width, int height)
+{
+	struct video_priv *priv = dev_get_uclass_priv(vid);
+	int endx = x + width;
+	int endy = y + height;
+
+	if (!CONFIG_IS_ENABLED(VIDEO_DAMAGE))
+		return 0;
+
+	if (x > priv->xsize)
+		return 0;
+
+	if (y > priv->ysize)
+		return 0;
+
+	if (endx > priv->xsize)
+		endx = priv->xsize;
+
+	if (endy > priv->ysize)
+		endy = priv->ysize;
+
+	/* Span a rectangle across all old and new damage */
+	priv->damage.x = min(x, priv->damage.x);
+	priv->damage.y = min(y, priv->damage.y);
+	priv->damage.endx = max(endx, priv->damage.endx);
+	priv->damage.endy = max(endy, priv->damage.endy);
+
+	return 0;
+}
+
 /* Flush video activity to the caches */
 int video_sync(struct udevice *vid, bool force)
 {
@@ -288,6 +321,14 @@ int video_sync(struct udevice *vid, bool force)
 		last_sync = get_timer(0);
 	}
 #endif
+
+	if (CONFIG_IS_ENABLED(VIDEO_DAMAGE)) {
+		priv->damage.x = priv->xsize;
+		priv->damage.y = priv->ysize;
+		priv->damage.endx = 0;
+		priv->damage.endy = 0;
+	}
+
 	return 0;
 }
 
diff --git a/include/video.h b/include/video.h
index 43f2e2c02f..4b35e97f79 100644
--- a/include/video.h
+++ b/include/video.h
@@ -109,6 +109,12 @@ struct video_priv {
 	void *fb;
 	int fb_size;
 	void *copy_fb;
+	struct {
+		int x;
+		int y;
+		int endx;
+		int endy;
+	} damage;
 	int line_length;
 	u32 colour_fg;
 	u32 colour_bg;
@@ -211,8 +217,9 @@ int video_fill(struct udevice *dev, u32 colour);
  * @return: 0 on success, error code otherwise
  *
  * Some frame buffers are cached or have a secondary frame buffer. This
- * function syncs these up so that the current contents of the U-Boot frame
- * buffer are displayed to the user.
+ * function syncs the damaged parts of them up so that the current contents
+ * of the U-Boot frame buffer are displayed to the user. It clears the damage
+ * buffer.
  */
 int video_sync(struct udevice *vid, bool force);
 
@@ -332,6 +339,24 @@ static inline int video_sync_copy_all(struct udevice *dev)
 
 #endif
 
+/**
+ * video_damage() - Notify the video subsystem about screen updates.
+ *
+ * @vid:	Device to sync
+ * @x:	        Upper left X coordinate of the damaged rectangle
+ * @y:	        Upper left Y coordinate of the damaged rectangle
+ * @width:	Width of the damaged rectangle
+ * @height:	Height of the damaged rectangle
+ *
+ * @return: 0
+ *
+ * Some frame buffers are cached or have a secondary frame buffer. This
+ * function notifies the video subsystem about rectangles that were updated
+ * within the frame buffer. They may only get written to the screen on the
+ * next call to video_sync().
+ */
+int video_damage(struct udevice *vid, int x, int y, int width, int height);
+
 /**
  * video_is_active() - Test if one video device it active
  *
-- 
2.37.1 (Apple Git-137.1)


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH v4 2/9] dm: video: Add damage notification on display clear
  2023-01-03 21:49 [PATCH v4 0/9] Add video damage tracking Alexander Graf
  2023-01-03 21:49 ` [PATCH v4 1/9] dm: video: Add damage tracking API Alexander Graf
@ 2023-01-03 21:49 ` Alexander Graf
  2023-01-07  0:13   ` Simon Glass
  2023-01-03 21:49 ` [PATCH v4 3/9] vidconsole: Add damage notifications to all vidconsole drivers Alexander Graf
                   ` (8 subsequent siblings)
  10 siblings, 1 reply; 25+ messages in thread
From: Alexander Graf @ 2023-01-03 21:49 UTC (permalink / raw)
  To: u-boot
  Cc: Matthias Brugger, Heinrich Schuchardt, Anatolij Gustschin,
	Simon Glass, Da Xue, Ilias Apalodimas, Jagan Teki,
	Andre Przywara, Neil Armstrong, Philipp Tomsich, Kever Yang,
	Patrick Delaunay, Patrice Chotard, uboot-stm32, u-boot-amlogic

Let's report the video damage when we clear the screen. This
way we can later lazily flush only relevant regions to hardware.

Signed-off-by: Alexander Graf <agraf@csgraf.de>
Reported-by: Da Xue <da@libre.computer>
---
 drivers/video/video-uclass.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c
index d18c8cd2b1..48fc29aeb0 100644
--- a/drivers/video/video-uclass.c
+++ b/drivers/video/video-uclass.c
@@ -160,6 +160,8 @@ int video_fill(struct udevice *dev, u32 colour)
 	if (ret)
 		return ret;
 
+	video_damage(dev, 0, 0, priv->xsize, priv->ysize);
+
 	return video_sync(dev, false);
 }
 
-- 
2.37.1 (Apple Git-137.1)


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH v4 3/9] vidconsole: Add damage notifications to all vidconsole drivers
  2023-01-03 21:49 [PATCH v4 0/9] Add video damage tracking Alexander Graf
  2023-01-03 21:49 ` [PATCH v4 1/9] dm: video: Add damage tracking API Alexander Graf
  2023-01-03 21:49 ` [PATCH v4 2/9] dm: video: Add damage notification on display clear Alexander Graf
@ 2023-01-03 21:49 ` Alexander Graf
  2023-01-07  0:13   ` Simon Glass
  2023-01-03 21:49 ` [PATCH v4 4/9] video: Add damage notification on bmp display Alexander Graf
                   ` (7 subsequent siblings)
  10 siblings, 1 reply; 25+ messages in thread
From: Alexander Graf @ 2023-01-03 21:49 UTC (permalink / raw)
  To: u-boot
  Cc: Matthias Brugger, Heinrich Schuchardt, Anatolij Gustschin,
	Simon Glass, Da Xue, Ilias Apalodimas, Jagan Teki,
	Andre Przywara, Neil Armstrong, Philipp Tomsich, Kever Yang,
	Patrick Delaunay, Patrice Chotard, uboot-stm32, u-boot-amlogic

Now that we have a damage tracking API, let's populate damage done by
vidconsole drivers. We try to declare as little memory as damaged as
possible, with the exception of rotated screens that I couldn't get my
head wrapped around. On those, we revert to the old behavior and mark
the full screen as damaged on every update.

Signed-off-by: Alexander Graf <agraf@csgraf.de>
Reported-by: Da Xue <da@libre.computer>

---

v1 -> v2:

  - Fix ranges in truetype target
  - Limit rotate to necessary damange
---
 drivers/video/console_normal.c   | 10 ++++++
 drivers/video/console_rotate.c   | 54 ++++++++++++++++++++++++++++++++
 drivers/video/console_truetype.c | 15 +++++++++
 3 files changed, 79 insertions(+)

diff --git a/drivers/video/console_normal.c b/drivers/video/console_normal.c
index 04f022491e..5b5586fd3e 100644
--- a/drivers/video/console_normal.c
+++ b/drivers/video/console_normal.c
@@ -57,6 +57,9 @@ static int console_normal_set_row(struct udevice *dev, uint row, int clr)
 	if (ret)
 		return ret;
 
+	video_damage(dev->parent, 0, VIDEO_FONT_HEIGHT * row, vid_priv->xsize,
+		     VIDEO_FONT_HEIGHT);
+
 	return 0;
 }
 
@@ -76,6 +79,9 @@ static int console_normal_move_rows(struct udevice *dev, uint rowdst,
 	if (ret)
 		return ret;
 
+	video_damage(dev->parent, 0, VIDEO_FONT_HEIGHT * rowdst, vid_priv->xsize,
+		     VIDEO_FONT_HEIGHT * count);
+
 	return 0;
 }
 
@@ -143,6 +149,10 @@ static int console_normal_putc_xy(struct udevice *dev, uint x_frac, uint y,
 		}
 		line += vid_priv->line_length;
 	}
+
+	video_damage(dev->parent, VID_TO_PIXEL(x_frac), y, VIDEO_FONT_WIDTH,
+		     VIDEO_FONT_HEIGHT);
+
 	ret = vidconsole_sync_copy(dev, start, line);
 	if (ret)
 		return ret;
diff --git a/drivers/video/console_rotate.c b/drivers/video/console_rotate.c
index 36c8d0609d..56e20bb4f3 100644
--- a/drivers/video/console_rotate.c
+++ b/drivers/video/console_rotate.c
@@ -57,6 +57,12 @@ static int console_set_row_1(struct udevice *dev, uint row, int clr)
 	if (ret)
 		return ret;
 
+	video_damage(dev->parent,
+		     vid_priv->xsize - ((row + 1) * VIDEO_FONT_HEIGHT),
+		     0,
+		     VIDEO_FONT_HEIGHT,
+		     vid_priv->ysize);
+
 	return 0;
 }
 
@@ -83,6 +89,12 @@ static int console_move_rows_1(struct udevice *dev, uint rowdst, uint rowsrc,
 		dst += vid_priv->line_length;
 	}
 
+	video_damage(dev->parent,
+		     vid_priv->xsize - ((rowdst + count) * VIDEO_FONT_HEIGHT),
+		     0,
+		     count * VIDEO_FONT_HEIGHT,
+		     vid_priv->ysize);
+
 	return 0;
 }
 
@@ -150,6 +162,12 @@ static int console_putc_xy_1(struct udevice *dev, uint x_frac, uint y, char ch)
 	if (ret)
 		return ret;
 
+	video_damage(dev->parent,
+		     vid_priv->xsize - y - VIDEO_FONT_HEIGHT - 1,
+		     linenum - 1,
+		     VIDEO_FONT_HEIGHT,
+		     VIDEO_FONT_WIDTH);
+
 	return VID_TO_POS(VIDEO_FONT_WIDTH);
 }
 
@@ -199,6 +217,12 @@ static int console_set_row_2(struct udevice *dev, uint row, int clr)
 	if (ret)
 		return ret;
 
+	video_damage(dev->parent,
+		     0,
+		     vid_priv->ysize - (row + 1) * VIDEO_FONT_HEIGHT,
+		     vid_priv->xsize,
+		     VIDEO_FONT_HEIGHT);
+
 	return 0;
 }
 
@@ -218,6 +242,12 @@ static int console_move_rows_2(struct udevice *dev, uint rowdst, uint rowsrc,
 	vidconsole_memmove(dev, dst, src,
 			   VIDEO_FONT_HEIGHT * vid_priv->line_length * count);
 
+	video_damage(dev->parent,
+		     0,
+		     vid_priv->ysize - (rowdst + count) * VIDEO_FONT_HEIGHT,
+		     vid_priv->xsize,
+		     count * VIDEO_FONT_HEIGHT);
+
 	return 0;
 }
 
@@ -288,6 +318,12 @@ static int console_putc_xy_2(struct udevice *dev, uint x_frac, uint y, char ch)
 	if (ret)
 		return ret;
 
+	video_damage(dev->parent,
+		     x - VIDEO_FONT_WIDTH,
+		     linenum - VIDEO_FONT_HEIGHT + 1,
+		     VIDEO_FONT_WIDTH,
+		     VIDEO_FONT_HEIGHT);
+
 	return VID_TO_POS(VIDEO_FONT_WIDTH);
 }
 
@@ -335,6 +371,12 @@ static int console_set_row_3(struct udevice *dev, uint row, int clr)
 	if (ret)
 		return ret;
 
+	video_damage(dev->parent,
+		     row * VIDEO_FONT_HEIGHT,
+		     0,
+		     VIDEO_FONT_HEIGHT,
+		     vid_priv->ysize);
+
 	return 0;
 }
 
@@ -359,6 +401,12 @@ static int console_move_rows_3(struct udevice *dev, uint rowdst, uint rowsrc,
 		dst += vid_priv->line_length;
 	}
 
+	video_damage(dev->parent,
+		     rowdst * VIDEO_FONT_HEIGHT,
+		     0,
+		     count * VIDEO_FONT_HEIGHT,
+		     vid_priv->ysize);
+
 	return 0;
 }
 
@@ -424,6 +472,12 @@ static int console_putc_xy_3(struct udevice *dev, uint x_frac, uint y, char ch)
 	if (ret)
 		return ret;
 
+	video_damage(dev->parent,
+		     y,
+		     x - VIDEO_FONT_WIDTH + 1,
+		     VIDEO_FONT_HEIGHT,
+		     VIDEO_FONT_WIDTH);
+
 	return VID_TO_POS(VIDEO_FONT_WIDTH);
 }
 
diff --git a/drivers/video/console_truetype.c b/drivers/video/console_truetype.c
index 6859c9fa11..3fc6e24485 100644
--- a/drivers/video/console_truetype.c
+++ b/drivers/video/console_truetype.c
@@ -145,6 +145,7 @@ struct console_tt_priv {
 static int console_truetype_set_row(struct udevice *dev, uint row, int clr)
 {
 	struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
+	struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
 	struct console_tt_priv *priv = dev_get_priv(dev);
 	struct console_tt_metrics *met = priv->cur_met;
 	void *end, *line;
@@ -188,6 +189,9 @@ static int console_truetype_set_row(struct udevice *dev, uint row, int clr)
 	if (ret)
 		return ret;
 
+	video_damage(dev->parent, 0, vc_priv->y_charsize * row, vid_priv->xsize,
+		     vc_priv->y_charsize);
+
 	return 0;
 }
 
@@ -195,6 +199,7 @@ static int console_truetype_move_rows(struct udevice *dev, uint rowdst,
 				     uint rowsrc, uint count)
 {
 	struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
+	struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
 	struct console_tt_priv *priv = dev_get_priv(dev);
 	struct console_tt_metrics *met = priv->cur_met;
 	void *dst;
@@ -213,6 +218,9 @@ static int console_truetype_move_rows(struct udevice *dev, uint rowdst,
 	for (i = 0; i < priv->pos_ptr; i++)
 		priv->pos[i].ypos -= diff;
 
+	video_damage(dev->parent, 0, vc_priv->y_charsize * rowdst, vid_priv->xsize,
+		     vc_priv->y_charsize * count);
+
 	return 0;
 }
 
@@ -370,6 +378,10 @@ static int console_truetype_putc_xy(struct udevice *dev, uint x, uint y,
 
 		line += vid_priv->line_length;
 	}
+
+	video_damage(dev->parent, VID_TO_PIXEL(x) + xoff,
+		     y + priv->baseline + yoff, width, height);
+
 	ret = vidconsole_sync_copy(dev, start, line);
 	if (ret)
 		return ret;
@@ -437,6 +449,9 @@ static int console_truetype_erase(struct udevice *dev, int xstart, int ystart,
 		}
 		line += vid_priv->line_length;
 	}
+
+	video_damage(dev->parent, xstart, ystart, xend - xstart, yend - ystart);
+
 	ret = vidconsole_sync_copy(dev, start, line);
 	if (ret)
 		return ret;
-- 
2.37.1 (Apple Git-137.1)


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH v4 4/9] video: Add damage notification on bmp display
  2023-01-03 21:49 [PATCH v4 0/9] Add video damage tracking Alexander Graf
                   ` (2 preceding siblings ...)
  2023-01-03 21:49 ` [PATCH v4 3/9] vidconsole: Add damage notifications to all vidconsole drivers Alexander Graf
@ 2023-01-03 21:49 ` Alexander Graf
  2023-01-07  0:13   ` Simon Glass
  2023-01-03 21:50 ` [PATCH v4 5/9] efi_loader: GOP: Add damage notification on BLT Alexander Graf
                   ` (6 subsequent siblings)
  10 siblings, 1 reply; 25+ messages in thread
From: Alexander Graf @ 2023-01-03 21:49 UTC (permalink / raw)
  To: u-boot
  Cc: Matthias Brugger, Heinrich Schuchardt, Anatolij Gustschin,
	Simon Glass, Da Xue, Ilias Apalodimas, Jagan Teki,
	Andre Przywara, Neil Armstrong, Philipp Tomsich, Kever Yang,
	Patrick Delaunay, Patrice Chotard, uboot-stm32, u-boot-amlogic

Let's report the video damage when we draw a bitmap on the screen. This
way we can later lazily flush only relevant regions to hardware.

Signed-off-by: Alexander Graf <agraf@csgraf.de>
Reported-by: Da Xue <da@libre.computer>
---
 drivers/video/video_bmp.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/video/video_bmp.c b/drivers/video/video_bmp.c
index 6188a13e44..7dc5b011a8 100644
--- a/drivers/video/video_bmp.c
+++ b/drivers/video/video_bmp.c
@@ -424,6 +424,8 @@ int video_bmp_display(struct udevice *dev, ulong bmp_image, int x, int y,
 		break;
 	};
 
+	video_damage(dev, x, y, width, height);
+
 	/* Find the position of the top left of the image in the framebuffer */
 	fb = (uchar *)(priv->fb + y * priv->line_length + x * bpix / 8);
 	ret = video_sync_copy(dev, start, fb);
-- 
2.37.1 (Apple Git-137.1)


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH v4 5/9] efi_loader: GOP: Add damage notification on BLT
  2023-01-03 21:49 [PATCH v4 0/9] Add video damage tracking Alexander Graf
                   ` (3 preceding siblings ...)
  2023-01-03 21:49 ` [PATCH v4 4/9] video: Add damage notification on bmp display Alexander Graf
@ 2023-01-03 21:50 ` Alexander Graf
  2023-01-04 12:50   ` Heinrich Schuchardt
  2023-01-03 21:50 ` [PATCH v4 6/9] video: Only dcache flush damaged lines Alexander Graf
                   ` (5 subsequent siblings)
  10 siblings, 1 reply; 25+ messages in thread
From: Alexander Graf @ 2023-01-03 21:50 UTC (permalink / raw)
  To: u-boot
  Cc: Matthias Brugger, Heinrich Schuchardt, Anatolij Gustschin,
	Simon Glass, Da Xue, Ilias Apalodimas, Jagan Teki,
	Andre Przywara, Neil Armstrong, Philipp Tomsich, Kever Yang,
	Patrick Delaunay, Patrice Chotard, uboot-stm32, u-boot-amlogic

Now that we have a damage tracking API, let's populate damage done by
UEFI payloads when they BLT data onto the screen.

Signed-off-by: Alexander Graf <agraf@csgraf.de>
Reported-by: Da Xue <da@libre.computer>

---

v1 -> v2:

  - Remove ifdefs from gop

v2 -> v3:

  - Adapt to always assume DM is used

v3 -> v4:

  - Skip damage on EfiBltVideoToBltBuffer
---
 lib/efi_loader/efi_gop.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/lib/efi_loader/efi_gop.c b/lib/efi_loader/efi_gop.c
index d1dc2f22d0..425dcbf6b1 100644
--- a/lib/efi_loader/efi_gop.c
+++ b/lib/efi_loader/efi_gop.c
@@ -32,6 +32,7 @@ struct efi_gop_obj {
 	struct efi_gop ops;
 	struct efi_gop_mode_info info;
 	struct efi_gop_mode mode;
+	struct udevice *vdev;
 	/* Fields we only have access to during init */
 	u32 bpix;
 	void *fb;
@@ -120,6 +121,7 @@ static __always_inline efi_status_t gop_blt_int(struct efi_gop *this,
 	u32 *fb32 = gopobj->fb;
 	u16 *fb16 = gopobj->fb;
 	struct efi_gop_pixel *buffer = __builtin_assume_aligned(bufferp, 4);
+	bool blt_to_video = (operation != EFI_BLT_VIDEO_TO_BLT_BUFFER);
 
 	if (delta) {
 		/* Check for 4 byte alignment */
@@ -243,6 +245,9 @@ static __always_inline efi_status_t gop_blt_int(struct efi_gop *this,
 		dlineoff += dwidth;
 	}
 
+	if (blt_to_video)
+		video_damage(gopobj->vdev, dx, dy, width, height);
+
 	return EFI_SUCCESS;
 }
 
@@ -547,6 +552,7 @@ efi_status_t efi_gop_register(void)
 	gopobj->info.pixels_per_scanline = col;
 	gopobj->bpix = bpix;
 	gopobj->fb = fb;
+	gopobj->vdev = vdev;
 
 	return EFI_SUCCESS;
 }
-- 
2.37.1 (Apple Git-137.1)


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH v4 6/9] video: Only dcache flush damaged lines
  2023-01-03 21:49 [PATCH v4 0/9] Add video damage tracking Alexander Graf
                   ` (4 preceding siblings ...)
  2023-01-03 21:50 ` [PATCH v4 5/9] efi_loader: GOP: Add damage notification on BLT Alexander Graf
@ 2023-01-03 21:50 ` Alexander Graf
  2023-01-07  0:13   ` Simon Glass
  2023-01-03 21:50 ` [PATCH v4 7/9] video: Use VIDEO_DAMAGE for VIDEO_COPY Alexander Graf
                   ` (4 subsequent siblings)
  10 siblings, 1 reply; 25+ messages in thread
From: Alexander Graf @ 2023-01-03 21:50 UTC (permalink / raw)
  To: u-boot
  Cc: Matthias Brugger, Heinrich Schuchardt, Anatolij Gustschin,
	Simon Glass, Da Xue, Ilias Apalodimas, Jagan Teki,
	Andre Przywara, Neil Armstrong, Philipp Tomsich, Kever Yang,
	Patrick Delaunay, Patrice Chotard, uboot-stm32, u-boot-amlogic

Now that we have a damage area tells us which parts of the frame buffer
actually need updating, let's only dcache flush those on video_sync()
calls. With this optimization in place, frame buffer updates - especially
on large screen such as 4k displays - speed up significantly.

Signed-off-by: Alexander Graf <agraf@csgraf.de>
Reported-by: Da Xue <da@libre.computer>

---

v1 -> v2:

  - Fix dcache range; we were flushing too much before
  - Remove ifdefs

v3 -> v4:

  - Simplify first damage logic
---
 drivers/video/video-uclass.c | 45 +++++++++++++++++++++++++++++-------
 1 file changed, 37 insertions(+), 8 deletions(-)

diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c
index 48fc29aeb0..37ab9f7ca4 100644
--- a/drivers/video/video-uclass.c
+++ b/drivers/video/video-uclass.c
@@ -289,9 +289,45 @@ int video_damage(struct udevice *vid, int x, int y, int width, int height)
 	return 0;
 }
 
+#if defined(CONFIG_ARM) && !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
+static void video_flush_dcache(struct udevice *vid)
+{
+	struct video_priv *priv = dev_get_uclass_priv(vid);
+
+	if (!priv->flush_dcache)
+		return;
+
+	if (!CONFIG_IS_ENABLED(VIDEO_DAMAGE)) {
+		flush_dcache_range((ulong)priv->fb,
+				   ALIGN((ulong)priv->fb + priv->fb_size,
+					 CONFIG_SYS_CACHELINE_SIZE));
+
+		return;
+	}
+
+	if (priv->damage.endx > priv->damage.x) {
+		int lstart = priv->damage.x * VNBYTES(priv->bpix);
+		int lend = priv->damage.endx * VNBYTES(priv->bpix);
+		int y;
+
+		for (y = priv->damage.y; y < priv->damage.endy; y++) {
+			ulong fb = (ulong)priv->fb;
+			ulong start = fb + (y * priv->line_length) + lstart;
+			ulong end = start + lend - lstart;
+
+			start = ALIGN_DOWN(start, CONFIG_SYS_CACHELINE_SIZE);
+			end = ALIGN(end, CONFIG_SYS_CACHELINE_SIZE);
+
+			flush_dcache_range(start, end);
+		}
+	}
+}
+#endif
+
 /* Flush video activity to the caches */
 int video_sync(struct udevice *vid, bool force)
 {
+	struct video_priv *priv = dev_get_uclass_priv(vid);
 	struct video_ops *ops = video_get_ops(vid);
 	int ret;
 
@@ -307,15 +343,8 @@ int video_sync(struct udevice *vid, bool force)
 	 * out whether it exists? For now, ARM is safe.
 	 */
 #if defined(CONFIG_ARM) && !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
-	struct video_priv *priv = dev_get_uclass_priv(vid);
-
-	if (priv->flush_dcache) {
-		flush_dcache_range((ulong)priv->fb,
-				   ALIGN((ulong)priv->fb + priv->fb_size,
-					 CONFIG_SYS_CACHELINE_SIZE));
-	}
+	video_flush_dcache(vid);
 #elif defined(CONFIG_VIDEO_SANDBOX_SDL)
-	struct video_priv *priv = dev_get_uclass_priv(vid);
 	static ulong last_sync;
 
 	if (force || get_timer(last_sync) > 100) {
-- 
2.37.1 (Apple Git-137.1)


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH v4 7/9] video: Use VIDEO_DAMAGE for VIDEO_COPY
  2023-01-03 21:49 [PATCH v4 0/9] Add video damage tracking Alexander Graf
                   ` (5 preceding siblings ...)
  2023-01-03 21:50 ` [PATCH v4 6/9] video: Only dcache flush damaged lines Alexander Graf
@ 2023-01-03 21:50 ` Alexander Graf
  2023-01-07  0:13   ` Simon Glass
  2023-01-03 21:50 ` [PATCH v4 8/9] video: Always compile cache flushing code Alexander Graf
                   ` (3 subsequent siblings)
  10 siblings, 1 reply; 25+ messages in thread
From: Alexander Graf @ 2023-01-03 21:50 UTC (permalink / raw)
  To: u-boot
  Cc: Matthias Brugger, Heinrich Schuchardt, Anatolij Gustschin,
	Simon Glass, Da Xue, Ilias Apalodimas, Jagan Teki,
	Andre Przywara, Neil Armstrong, Philipp Tomsich, Kever Yang,
	Patrick Delaunay, Patrice Chotard, uboot-stm32, u-boot-amlogic

CONFIG_VIDEO_COPY implemented a range based copying mechanism: If we
print a single character, it will always copy the full range of bytes
from the top left corner of the character to the lower right onto the
uncached frame buffer. This includes pretty much the full line contents
of the printed character.

Since we now have proper damage tracking, let's make use of that to reduce
the amount of data we need to copy. With this patch applied, we will only
copy the tiny rectangle surrounding characters when we print them,
speeding up the video console.

As a bonus, we remove a lot of code.

Signed-off-by: Alexander Graf <agraf@csgraf.de>

---

v2 -> v3:

  - Rebase
  - Make CONFIG_COPY always select VIDEO_DAMAGE
---
 drivers/video/Kconfig             |  5 ++
 drivers/video/console_normal.c    | 14 +----
 drivers/video/console_rotate.c    | 37 ++-----------
 drivers/video/console_truetype.c  | 17 +-----
 drivers/video/vidconsole-uclass.c | 16 ------
 drivers/video/video-uclass.c      | 91 ++++++++-----------------------
 drivers/video/video_bmp.c         |  7 ---
 include/video.h                   | 37 -------------
 include/video_console.h           | 49 -----------------
 9 files changed, 37 insertions(+), 236 deletions(-)

diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 826a1a6587..472e9c7c61 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -53,11 +53,14 @@ config VIDEO_PCI_DEFAULT_FB_SIZE
 
 config VIDEO_COPY
 	bool "Enable copying the frame buffer to a hardware copy"
+	select VIDEO_DAMAGE
 	help
 	  On some machines (e.g. x86), reading from the frame buffer is very
 	  slow because it is uncached. To improve performance, this feature
 	  allows the frame buffer to be kept in cached memory (allocated by
 	  U-Boot) and then copied to the hardware frame-buffer as needed.
+	  It uses the VIDEO_DAMAGE feature to keep track of regions to copy
+	  and will only copy actually touched regions.
 
 	  To use this, your video driver must set @copy_base in
 	  struct video_uc_plat.
@@ -75,6 +78,8 @@ config VIDEO_DAMAGE
 	  regions of the frame buffer that were modified before, speeding up
 	  screen refreshes significantly.
 
+	  It is also used by VIDEO_COPY to identify which regions changed.
+
 config BACKLIGHT_PWM
 	bool "Generic PWM based Backlight Driver"
 	depends on BACKLIGHT && DM_PWM
diff --git a/drivers/video/console_normal.c b/drivers/video/console_normal.c
index 5b5586fd3e..625d14516f 100644
--- a/drivers/video/console_normal.c
+++ b/drivers/video/console_normal.c
@@ -18,7 +18,6 @@ static int console_normal_set_row(struct udevice *dev, uint row, int clr)
 	struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
 	void *line, *end;
 	int pixels = VIDEO_FONT_HEIGHT * vid_priv->xsize;
-	int ret;
 	int i;
 
 	line = vid_priv->fb + row * VIDEO_FONT_HEIGHT * vid_priv->line_length;
@@ -53,9 +52,6 @@ static int console_normal_set_row(struct udevice *dev, uint row, int clr)
 	default:
 		return -ENOSYS;
 	}
-	ret = vidconsole_sync_copy(dev, line, end);
-	if (ret)
-		return ret;
 
 	video_damage(dev->parent, 0, VIDEO_FONT_HEIGHT * row, vid_priv->xsize,
 		     VIDEO_FONT_HEIGHT);
@@ -70,14 +66,11 @@ static int console_normal_move_rows(struct udevice *dev, uint rowdst,
 	void *dst;
 	void *src;
 	int size;
-	int ret;
 
 	dst = vid_priv->fb + rowdst * VIDEO_FONT_HEIGHT * vid_priv->line_length;
 	src = vid_priv->fb + rowsrc * VIDEO_FONT_HEIGHT * vid_priv->line_length;
 	size = VIDEO_FONT_HEIGHT * vid_priv->line_length * count;
-	ret = vidconsole_memmove(dev, dst, src, size);
-	if (ret)
-		return ret;
+	memmove(dst, src, size);
 
 	video_damage(dev->parent, 0, VIDEO_FONT_HEIGHT * rowdst, vid_priv->xsize,
 		     VIDEO_FONT_HEIGHT * count);
@@ -94,7 +87,6 @@ static int console_normal_putc_xy(struct udevice *dev, uint x_frac, uint y,
 	int i, row;
 	void *start;
 	void *line;
-	int ret;
 
 	start = vid_priv->fb + y * vid_priv->line_length +
 		VID_TO_PIXEL(x_frac) * VNBYTES(vid_priv->bpix);
@@ -153,10 +145,6 @@ static int console_normal_putc_xy(struct udevice *dev, uint x_frac, uint y,
 	video_damage(dev->parent, VID_TO_PIXEL(x_frac), y, VIDEO_FONT_WIDTH,
 		     VIDEO_FONT_HEIGHT);
 
-	ret = vidconsole_sync_copy(dev, start, line);
-	if (ret)
-		return ret;
-
 	return VID_TO_POS(VIDEO_FONT_WIDTH);
 }
 
diff --git a/drivers/video/console_rotate.c b/drivers/video/console_rotate.c
index 56e20bb4f3..9b179a45b6 100644
--- a/drivers/video/console_rotate.c
+++ b/drivers/video/console_rotate.c
@@ -53,9 +53,6 @@ static int console_set_row_1(struct udevice *dev, uint row, int clr)
 		}
 		line += vid_priv->line_length;
 	}
-	ret = vidconsole_sync_copy(dev, start, line);
-	if (ret)
-		return ret;
 
 	video_damage(dev->parent,
 		     vid_priv->xsize - ((row + 1) * VIDEO_FONT_HEIGHT),
@@ -81,10 +78,7 @@ static int console_move_rows_1(struct udevice *dev, uint rowdst, uint rowsrc,
 		(rowsrc + count) * VIDEO_FONT_HEIGHT * pbytes;
 
 	for (j = 0; j < vid_priv->ysize; j++) {
-		ret = vidconsole_memmove(dev, dst, src,
-					 VIDEO_FONT_HEIGHT * pbytes * count);
-		if (ret)
-			return ret;
+		memmove(dst, src, VIDEO_FONT_HEIGHT * pbytes * count);
 		src += vid_priv->line_length;
 		dst += vid_priv->line_length;
 	}
@@ -158,10 +152,6 @@ static int console_putc_xy_1(struct udevice *dev, uint x_frac, uint y, char ch)
 		mask >>= 1;
 	}
 	/* We draw backwards from 'start, so account for the first line */
-	ret = vidconsole_sync_copy(dev, start - vid_priv->line_length, line);
-	if (ret)
-		return ret;
-
 	video_damage(dev->parent,
 		     vid_priv->xsize - y - VIDEO_FONT_HEIGHT - 1,
 		     linenum - 1,
@@ -213,9 +203,6 @@ static int console_set_row_2(struct udevice *dev, uint row, int clr)
 	default:
 		return -ENOSYS;
 	}
-	ret = vidconsole_sync_copy(dev, start, end);
-	if (ret)
-		return ret;
 
 	video_damage(dev->parent,
 		     0,
@@ -239,8 +226,8 @@ static int console_move_rows_2(struct udevice *dev, uint rowdst, uint rowsrc,
 		vid_priv->line_length;
 	src = end - (rowsrc + count) * VIDEO_FONT_HEIGHT *
 		vid_priv->line_length;
-	vidconsole_memmove(dev, dst, src,
-			   VIDEO_FONT_HEIGHT * vid_priv->line_length * count);
+	memmove(dev, dst, src, VIDEO_FONT_HEIGHT *
+		vid_priv->line_length * count);
 
 	video_damage(dev->parent,
 		     0,
@@ -313,10 +300,6 @@ static int console_putc_xy_2(struct udevice *dev, uint x_frac, uint y, char ch)
 		}
 		line -= vid_priv->line_length;
 	}
-	/* Add 4 bytes to allow for the first pixel writen */
-	ret = vidconsole_sync_copy(dev, start + 4, line);
-	if (ret)
-		return ret;
 
 	video_damage(dev->parent,
 		     x - VIDEO_FONT_WIDTH,
@@ -367,9 +350,6 @@ static int console_set_row_3(struct udevice *dev, uint row, int clr)
 		}
 		line += vid_priv->line_length;
 	}
-	ret = vidconsole_sync_copy(dev, start, line);
-	if (ret)
-		return ret;
 
 	video_damage(dev->parent,
 		     row * VIDEO_FONT_HEIGHT,
@@ -387,16 +367,13 @@ static int console_move_rows_3(struct udevice *dev, uint rowdst, uint rowsrc,
 	int pbytes = VNBYTES(vid_priv->bpix);
 	void *dst;
 	void *src;
-	int j, ret;
+	int j;
 
 	dst = vid_priv->fb + rowdst * VIDEO_FONT_HEIGHT * pbytes;
 	src = vid_priv->fb + rowsrc * VIDEO_FONT_HEIGHT * pbytes;
 
 	for (j = 0; j < vid_priv->ysize; j++) {
-		ret = vidconsole_memmove(dev, dst, src,
-					 VIDEO_FONT_HEIGHT * pbytes * count);
-		if (ret)
-			return ret;
+		memmove(dev, dst, src, VIDEO_FONT_HEIGHT * pbytes * count);
 		src += vid_priv->line_length;
 		dst += vid_priv->line_length;
 	}
@@ -468,10 +445,6 @@ static int console_putc_xy_3(struct udevice *dev, uint x_frac, uint y, char ch)
 		mask >>= 1;
 	}
 	/* Add a line to allow for the first pixels writen */
-	ret = vidconsole_sync_copy(dev, start + vid_priv->line_length, line);
-	if (ret)
-		return ret;
-
 	video_damage(dev->parent,
 		     y,
 		     x - VIDEO_FONT_WIDTH + 1,
diff --git a/drivers/video/console_truetype.c b/drivers/video/console_truetype.c
index 3fc6e24485..a545189cbd 100644
--- a/drivers/video/console_truetype.c
+++ b/drivers/video/console_truetype.c
@@ -185,9 +185,6 @@ static int console_truetype_set_row(struct udevice *dev, uint row, int clr)
 	default:
 		return -ENOSYS;
 	}
-	ret = vidconsole_sync_copy(dev, line, end);
-	if (ret)
-		return ret;
 
 	video_damage(dev->parent, 0, vc_priv->y_charsize * row, vid_priv->xsize,
 		     vc_priv->y_charsize);
@@ -204,14 +201,11 @@ static int console_truetype_move_rows(struct udevice *dev, uint rowdst,
 	struct console_tt_metrics *met = priv->cur_met;
 	void *dst;
 	void *src;
-	int i, diff, ret;
+	int i, diff;
 
 	dst = vid_priv->fb + rowdst * met->font_size * vid_priv->line_length;
 	src = vid_priv->fb + rowsrc * met->font_size * vid_priv->line_length;
-	ret = vidconsole_memmove(dev, dst, src, met->font_size *
-				 vid_priv->line_length * count);
-	if (ret)
-		return ret;
+	memmove(dev, dst, src, met->font_size * vid_priv->line_length * count);
 
 	/* Scroll up our position history */
 	diff = (rowsrc - rowdst) * met->font_size;
@@ -382,9 +376,6 @@ static int console_truetype_putc_xy(struct udevice *dev, uint x, uint y,
 	video_damage(dev->parent, VID_TO_PIXEL(x) + xoff,
 		     y + priv->baseline + yoff, width, height);
 
-	ret = vidconsole_sync_copy(dev, start, line);
-	if (ret)
-		return ret;
 	free(data);
 
 	return width_frac;
@@ -452,10 +443,6 @@ static int console_truetype_erase(struct udevice *dev, int xstart, int ystart,
 
 	video_damage(dev->parent, xstart, ystart, xend - xstart, yend - ystart);
 
-	ret = vidconsole_sync_copy(dev, start, line);
-	if (ret)
-		return ret;
-
 	return 0;
 }
 
diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c
index 6bdfb6e37d..c6447baf36 100644
--- a/drivers/video/vidconsole-uclass.c
+++ b/drivers/video/vidconsole-uclass.c
@@ -601,22 +601,6 @@ UCLASS_DRIVER(vidconsole) = {
 	.per_device_auto	= sizeof(struct vidconsole_priv),
 };
 
-#ifdef CONFIG_VIDEO_COPY
-int vidconsole_sync_copy(struct udevice *dev, void *from, void *to)
-{
-	struct udevice *vid = dev_get_parent(dev);
-
-	return video_sync_copy(vid, from, to);
-}
-
-int vidconsole_memmove(struct udevice *dev, void *dst, const void *src,
-		       int size)
-{
-	memmove(dst, src, size);
-	return vidconsole_sync_copy(dev, dst, dst + size);
-}
-#endif
-
 void vidconsole_position_cursor(struct udevice *dev, unsigned col, unsigned row)
 {
 	struct vidconsole_priv *priv = dev_get_uclass_priv(dev);
diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c
index 37ab9f7ca4..956863f98a 100644
--- a/drivers/video/video-uclass.c
+++ b/drivers/video/video-uclass.c
@@ -131,7 +131,6 @@ int video_reserve(ulong *addrp)
 int video_fill(struct udevice *dev, u32 colour)
 {
 	struct video_priv *priv = dev_get_uclass_priv(dev);
-	int ret;
 
 	switch (priv->bpix) {
 	case VIDEO_BPP16:
@@ -156,9 +155,6 @@ int video_fill(struct udevice *dev, u32 colour)
 		memset(priv->fb, colour, priv->fb_size);
 		break;
 	}
-	ret = video_sync_copy(dev, priv->fb, priv->fb + priv->fb_size);
-	if (ret)
-		return ret;
 
 	video_damage(dev, 0, 0, priv->xsize, priv->ysize);
 
@@ -324,6 +320,27 @@ static void video_flush_dcache(struct udevice *vid)
 }
 #endif
 
+static void video_flush_copy(struct udevice *vid)
+{
+	struct video_priv *priv = dev_get_uclass_priv(vid);
+
+	if (!priv->copy_fb)
+		return;
+
+	if (priv->damage.endx && priv->damage.endy) {
+		int lstart = priv->damage.x * VNBYTES(priv->bpix);
+		int lend = priv->damage.endx * VNBYTES(priv->bpix);
+		int y;
+
+		for (y = priv->damage.y; y < priv->damage.endy; y++) {
+			ulong offset = (y * priv->line_length) + lstart;
+			ulong len = lend - lstart;
+
+			memcpy(priv->copy_fb + offset, priv->fb + offset, len);
+		}
+	}
+}
+
 /* Flush video activity to the caches */
 int video_sync(struct udevice *vid, bool force)
 {
@@ -331,6 +348,9 @@ int video_sync(struct udevice *vid, bool force)
 	struct video_ops *ops = video_get_ops(vid);
 	int ret;
 
+	if (CONFIG_IS_ENABLED(VIDEO_COPY))
+		video_flush_copy(vid);
+
 	if (ops && ops->video_sync) {
 		ret = ops->video_sync(vid);
 		if (ret)
@@ -407,69 +427,6 @@ int video_get_ysize(struct udevice *dev)
 	return priv->ysize;
 }
 
-#ifdef CONFIG_VIDEO_COPY
-int video_sync_copy(struct udevice *dev, void *from, void *to)
-{
-	struct video_priv *priv = dev_get_uclass_priv(dev);
-
-	if (priv->copy_fb) {
-		long offset, size;
-
-		/* Find the offset of the first byte to copy */
-		if ((ulong)to > (ulong)from) {
-			size = to - from;
-			offset = from - priv->fb;
-		} else {
-			size = from - to;
-			offset = to - priv->fb;
-		}
-
-		/*
-		 * Allow a bit of leeway for valid requests somewhere near the
-		 * frame buffer
-		 */
-		if (offset < -priv->fb_size || offset > 2 * priv->fb_size) {
-#ifdef DEBUG
-			char str[120];
-
-			snprintf(str, sizeof(str),
-				 "[** FAULT sync_copy fb=%p, from=%p, to=%p, offset=%lx]",
-				 priv->fb, from, to, offset);
-			console_puts_select_stderr(true, str);
-#endif
-			return -EFAULT;
-		}
-
-		/*
-		 * Silently crop the memcpy. This allows callers to avoid doing
-		 * this themselves. It is common for the end pointer to go a
-		 * few lines after the end of the frame buffer, since most of
-		 * the update algorithms terminate a line after their last write
-		 */
-		if (offset + size > priv->fb_size) {
-			size = priv->fb_size - offset;
-		} else if (offset < 0) {
-			size += offset;
-			offset = 0;
-		}
-
-		memcpy(priv->copy_fb + offset, priv->fb + offset, size);
-	}
-
-	return 0;
-}
-
-int video_sync_copy_all(struct udevice *dev)
-{
-	struct video_priv *priv = dev_get_uclass_priv(dev);
-
-	video_sync_copy(dev, priv->fb, priv->fb + priv->fb_size);
-
-	return 0;
-}
-
-#endif
-
 #define SPLASH_DECL(_name) \
 	extern u8 __splash_ ## _name ## _begin[]; \
 	extern u8 __splash_ ## _name ## _end[]
diff --git a/drivers/video/video_bmp.c b/drivers/video/video_bmp.c
index 7dc5b011a8..609dc9fef6 100644
--- a/drivers/video/video_bmp.c
+++ b/drivers/video/video_bmp.c
@@ -254,7 +254,6 @@ int video_bmp_display(struct udevice *dev, ulong bmp_image, int x, int y,
 	enum video_format eformat;
 	struct bmp_color_table_entry *palette;
 	int hdr_size;
-	int ret;
 
 	if (!bmp || !(bmp->header.signature[0] == 'B' &&
 	    bmp->header.signature[1] == 'M')) {
@@ -426,11 +425,5 @@ int video_bmp_display(struct udevice *dev, ulong bmp_image, int x, int y,
 
 	video_damage(dev, x, y, width, height);
 
-	/* Find the position of the top left of the image in the framebuffer */
-	fb = (uchar *)(priv->fb + y * priv->line_length + x * bpix / 8);
-	ret = video_sync_copy(dev, start, fb);
-	if (ret)
-		return log_ret(ret);
-
 	return video_sync(dev, false);
 }
diff --git a/include/video.h b/include/video.h
index 4b35e97f79..e1162fc533 100644
--- a/include/video.h
+++ b/include/video.h
@@ -302,43 +302,6 @@ void video_set_default_colors(struct udevice *dev, bool invert);
  */
 int video_default_font_height(struct udevice *dev);
 
-#ifdef CONFIG_VIDEO_COPY
-/**
- * vidconsole_sync_copy() - Sync back to the copy framebuffer
- *
- * This ensures that the copy framebuffer has the same data as the framebuffer
- * for a particular region. It should be called after the framebuffer is updated
- *
- * @from and @to can be in either order. The region between them is synced.
- *
- * @dev: Vidconsole device being updated
- * @from: Start/end address within the framebuffer (->fb)
- * @to: Other address within the frame buffer
- * Return: 0 if OK, -EFAULT if the start address is before the start of the
- *	frame buffer start
- */
-int video_sync_copy(struct udevice *dev, void *from, void *to);
-
-/**
- * video_sync_copy_all() - Sync the entire framebuffer to the copy
- *
- * @dev: Vidconsole device being updated
- * Return: 0 (always)
- */
-int video_sync_copy_all(struct udevice *dev);
-#else
-static inline int video_sync_copy(struct udevice *dev, void *from, void *to)
-{
-	return 0;
-}
-
-static inline int video_sync_copy_all(struct udevice *dev)
-{
-	return 0;
-}
-
-#endif
-
 /**
  * video_damage() - Notify the video subsystem about screen updates.
  *
diff --git a/include/video_console.h b/include/video_console.h
index d755eb73cf..10d2d111c2 100644
--- a/include/video_console.h
+++ b/include/video_console.h
@@ -256,53 +256,4 @@ int vidconsole_select_font(struct udevice *dev, const char *name, uint size);
  */
 const char *vidconsole_get_font(struct udevice *dev, uint *sizep);
 
-#ifdef CONFIG_VIDEO_COPY
-/**
- * vidconsole_sync_copy() - Sync back to the copy framebuffer
- *
- * This ensures that the copy framebuffer has the same data as the framebuffer
- * for a particular region. It should be called after the framebuffer is updated
- *
- * @from and @to can be in either order. The region between them is synced.
- *
- * @dev: Vidconsole device being updated
- * @from: Start/end address within the framebuffer (->fb)
- * @to: Other address within the frame buffer
- * Return: 0 if OK, -EFAULT if the start address is before the start of the
- *	frame buffer start
- */
-int vidconsole_sync_copy(struct udevice *dev, void *from, void *to);
-
-/**
- * vidconsole_memmove() - Perform a memmove() within the frame buffer
- *
- * This handles a memmove(), e.g. for scrolling. It also updates the copy
- * framebuffer.
- *
- * @dev: Vidconsole device being updated
- * @dst: Destination address within the framebuffer (->fb)
- * @src: Source address within the framebuffer (->fb)
- * @size: Number of bytes to transfer
- * Return: 0 if OK, -EFAULT if the start address is before the start of the
- *	frame buffer start
- */
-int vidconsole_memmove(struct udevice *dev, void *dst, const void *src,
-		       int size);
-#else
-static inline int vidconsole_sync_copy(struct udevice *dev, void *from,
-				       void *to)
-{
-	return 0;
-}
-
-static inline int vidconsole_memmove(struct udevice *dev, void *dst,
-				     const void *src, int size)
-{
-	memmove(dst, src, size);
-
-	return 0;
-}
-
-#endif
-
 #endif
-- 
2.37.1 (Apple Git-137.1)


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH v4 8/9] video: Always compile cache flushing code
  2023-01-03 21:49 [PATCH v4 0/9] Add video damage tracking Alexander Graf
                   ` (6 preceding siblings ...)
  2023-01-03 21:50 ` [PATCH v4 7/9] video: Use VIDEO_DAMAGE for VIDEO_COPY Alexander Graf
@ 2023-01-03 21:50 ` Alexander Graf
  2023-01-07  0:13   ` Simon Glass
  2023-01-03 21:50 ` [PATCH v4 9/9] video: Enable VIDEO_DAMAGE for drivers that need it Alexander Graf
                   ` (2 subsequent siblings)
  10 siblings, 1 reply; 25+ messages in thread
From: Alexander Graf @ 2023-01-03 21:50 UTC (permalink / raw)
  To: u-boot
  Cc: Matthias Brugger, Heinrich Schuchardt, Anatolij Gustschin,
	Simon Glass, Da Xue, Ilias Apalodimas, Jagan Teki,
	Andre Przywara, Neil Armstrong, Philipp Tomsich, Kever Yang,
	Patrick Delaunay, Patrice Chotard, uboot-stm32, u-boot-amlogic

The dcache flushing code path was conditional on ARM && !DCACHE config
options. However, dcaches exist on other platforms as well and may need
clearing if their driver requires it.

Simplify the compile logic and always enable the dcache flush logic in
the video core. That way, drivers can always rely on it to call the arch
specific callbacks.

This will increase code size for non-ARM platforms with CONFIG_VIDEO=y
slightly.

Reported-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@csgraf.de>
---
 drivers/video/video-uclass.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c
index 956863f98a..bad5eedc96 100644
--- a/drivers/video/video-uclass.c
+++ b/drivers/video/video-uclass.c
@@ -285,11 +285,13 @@ int video_damage(struct udevice *vid, int x, int y, int width, int height)
 	return 0;
 }
 
-#if defined(CONFIG_ARM) && !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
 static void video_flush_dcache(struct udevice *vid)
 {
 	struct video_priv *priv = dev_get_uclass_priv(vid);
 
+	if (CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
+		return;
+
 	if (!priv->flush_dcache)
 		return;
 
@@ -318,7 +320,6 @@ static void video_flush_dcache(struct udevice *vid)
 		}
 	}
 }
-#endif
 
 static void video_flush_copy(struct udevice *vid)
 {
@@ -357,14 +358,9 @@ int video_sync(struct udevice *vid, bool force)
 			return ret;
 	}
 
-	/*
-	 * flush_dcache_range() is declared in common.h but it seems that some
-	 * architectures do not actually implement it. Is there a way to find
-	 * out whether it exists? For now, ARM is safe.
-	 */
-#if defined(CONFIG_ARM) && !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
 	video_flush_dcache(vid);
-#elif defined(CONFIG_VIDEO_SANDBOX_SDL)
+
+#if defined(CONFIG_VIDEO_SANDBOX_SDL)
 	static ulong last_sync;
 
 	if (force || get_timer(last_sync) > 100) {
-- 
2.37.1 (Apple Git-137.1)


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH v4 9/9] video: Enable VIDEO_DAMAGE for drivers that need it
  2023-01-03 21:49 [PATCH v4 0/9] Add video damage tracking Alexander Graf
                   ` (7 preceding siblings ...)
  2023-01-03 21:50 ` [PATCH v4 8/9] video: Always compile cache flushing code Alexander Graf
@ 2023-01-03 21:50 ` Alexander Graf
  2023-01-04 12:32   ` Neil Armstrong
  2023-01-07  0:13   ` Simon Glass
  2023-01-07  0:13 ` [PATCH v4 0/9] Add video damage tracking Simon Glass
  2023-04-14  7:35 ` Antonio Murdaca
  10 siblings, 2 replies; 25+ messages in thread
From: Alexander Graf @ 2023-01-03 21:50 UTC (permalink / raw)
  To: u-boot
  Cc: Matthias Brugger, Heinrich Schuchardt, Anatolij Gustschin,
	Simon Glass, Da Xue, Ilias Apalodimas, Jagan Teki,
	Andre Przywara, Neil Armstrong, Philipp Tomsich, Kever Yang,
	Patrick Delaunay, Patrice Chotard, uboot-stm32, u-boot-amlogic

Some drivers call video_set_flush_dcache() to indicate that they want to
have the dcache flushed for the frame buffer. These drivers benefit from
our new video damage control, because we can reduce the amount of memory
that gets flushed significantly.

This patch enables video damage control for all device drivers that call
video_set_flush_dcache() to make sure they benefit from it.

Signed-off-by: Alexander Graf <agraf@csgraf.de>
---
 arch/arm/mach-omap2/omap3/Kconfig | 1 +
 arch/arm/mach-sunxi/Kconfig       | 1 +
 drivers/video/Kconfig             | 9 +++++++++
 drivers/video/exynos/Kconfig      | 1 +
 drivers/video/imx/Kconfig         | 1 +
 drivers/video/meson/Kconfig       | 1 +
 drivers/video/rockchip/Kconfig    | 1 +
 drivers/video/stm32/Kconfig       | 1 +
 8 files changed, 16 insertions(+)

diff --git a/arch/arm/mach-omap2/omap3/Kconfig b/arch/arm/mach-omap2/omap3/Kconfig
index 3e97ec2629..ea231f16a2 100644
--- a/arch/arm/mach-omap2/omap3/Kconfig
+++ b/arch/arm/mach-omap2/omap3/Kconfig
@@ -113,6 +113,7 @@ config TARGET_NOKIA_RX51
 	select CMDLINE_TAG
 	select INITRD_TAG
 	select REVISION_TAG
+	select VIDEO_DAMAGE
 
 config TARGET_TAO3530
 	bool "TAO3530"
diff --git a/arch/arm/mach-sunxi/Kconfig b/arch/arm/mach-sunxi/Kconfig
index dbe6005daa..373bf58731 100644
--- a/arch/arm/mach-sunxi/Kconfig
+++ b/arch/arm/mach-sunxi/Kconfig
@@ -790,6 +790,7 @@ config VIDEO_SUNXI
 	depends on !SUN50I_GEN_H6
 	select VIDEO
 	select DISPLAY
+	select VIDEO_DAMAGE
 	imply VIDEO_DT_SIMPLEFB
 	default y
 	---help---
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 472e9c7c61..a186bd8525 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -436,6 +436,7 @@ config VIDEO_LCD_ANX9804
 
 config ATMEL_LCD
 	bool "Atmel LCD panel support"
+	select VIDEO_DAMAGE
 	depends on ARCH_AT91
 
 config ATMEL_LCD_BGR555
@@ -445,6 +446,7 @@ config ATMEL_LCD_BGR555
 
 config VIDEO_BCM2835
 	bool "Display support for BCM2835"
+	select VIDEO_DAMAGE
 	help
 	  The graphics processor already sets up the display so this driver
 	  simply checks the resolution and then sets up the frame buffer with
@@ -554,6 +556,7 @@ source "drivers/video/meson/Kconfig"
 
 config VIDEO_MVEBU
 	bool "Armada XP LCD controller"
+	select VIDEO_DAMAGE
 	---help---
 	Support for the LCD controller integrated in the Marvell
 	Armada XP SoC.
@@ -588,6 +591,7 @@ config NXP_TDA19988
 
 config ATMEL_HLCD
 	bool "Enable ATMEL video support using HLCDC"
+	select VIDEO_DAMAGE
 	help
 	   HLCDC supports video output to an attached LCD panel.
 
@@ -652,6 +656,7 @@ source "drivers/video/stm32/Kconfig"
 config VIDEO_TEGRA20
 	bool "Enable LCD support on Tegra20"
 	depends on OF_CONTROL
+	select VIDEO_DAMAGE
 	help
 	   Tegra20 supports video output to an attached LCD panel as well as
 	   other options such as HDMI. Only the LCD is supported in U-Boot.
@@ -660,6 +665,7 @@ config VIDEO_TEGRA20
 
 config VIDEO_TEGRA124
 	bool "Enable video support on Tegra124"
+	select VIDEO_DAMAGE
 	help
 	   Tegra124 supports many video output options including eDP and
 	   HDMI. At present only eDP is supported by U-Boot. This option
@@ -672,6 +678,7 @@ source "drivers/video/imx/Kconfig"
 
 config VIDEO_MXS
 	bool "Enable video support on i.MX28/i.MX6UL/i.MX7 SoCs"
+	select VIDEO_DAMAGE
 	help
 	  Enable framebuffer driver for i.MX28/i.MX6UL/i.MX7 processors
 
@@ -741,6 +748,7 @@ config VIDEO_DW_MIPI_DSI
 
 config VIDEO_SIMPLE
 	bool "Simple display driver for preconfigured display"
+	select VIDEO_DAMAGE
 	help
 	  Enables a simple generic display driver which utilizes the
 	  simple-framebuffer devicetree bindings.
@@ -759,6 +767,7 @@ config VIDEO_DT_SIMPLEFB
 
 config VIDEO_MCDE_SIMPLE
 	bool "Simple driver for ST-Ericsson MCDE with preconfigured display"
+	select VIDEO_DAMAGE
 	help
 	  Enables a simple display driver for ST-Ericsson MCDE
 	  (Multichannel Display Engine), which reads the configuration from
diff --git a/drivers/video/exynos/Kconfig b/drivers/video/exynos/Kconfig
index 599d19d5ec..66aa11661c 100644
--- a/drivers/video/exynos/Kconfig
+++ b/drivers/video/exynos/Kconfig
@@ -12,6 +12,7 @@ config EXYNOS_DP
 
 config EXYNOS_FB
 	bool "Exynos FIMD support"
+	select VIDEO_DAMAGE
 
 config EXYNOS_MIPI_DSIM
 	bool "Exynos MIPI DSI support"
diff --git a/drivers/video/imx/Kconfig b/drivers/video/imx/Kconfig
index 34e8b64059..50d8b05365 100644
--- a/drivers/video/imx/Kconfig
+++ b/drivers/video/imx/Kconfig
@@ -2,6 +2,7 @@
 config VIDEO_IPUV3
 	bool "i.MX IPUv3 Core video support"
 	depends on VIDEO && (MX5 || MX6)
+	select VIDEO_DAMAGE
 	help
 	  This enables framebuffer driver for i.MX processors working
 	  on the IPUv3(Image Processing Unit) internal graphic processor.
diff --git a/drivers/video/meson/Kconfig b/drivers/video/meson/Kconfig
index 3c2d72d019..70fb75607b 100644
--- a/drivers/video/meson/Kconfig
+++ b/drivers/video/meson/Kconfig
@@ -8,5 +8,6 @@ config VIDEO_MESON
 	bool "Enable Amlogic Meson video support"
 	depends on VIDEO
 	select DISPLAY
+	select VIDEO_DAMAGE
 	help
 	  Enable Amlogic Meson Video Processing Unit video support.
diff --git a/drivers/video/rockchip/Kconfig b/drivers/video/rockchip/Kconfig
index b03866347b..1a3b02cee0 100644
--- a/drivers/video/rockchip/Kconfig
+++ b/drivers/video/rockchip/Kconfig
@@ -11,6 +11,7 @@
 menuconfig VIDEO_ROCKCHIP
 	bool "Enable Rockchip Video Support"
 	depends on VIDEO
+	select VIDEO_DAMAGE
 	help
 	  Rockchip SoCs provide video output capabilities for High-Definition
 	  Multimedia Interface (HDMI), Low-voltage Differential Signalling
diff --git a/drivers/video/stm32/Kconfig b/drivers/video/stm32/Kconfig
index 48066063e4..cce2255706 100644
--- a/drivers/video/stm32/Kconfig
+++ b/drivers/video/stm32/Kconfig
@@ -8,6 +8,7 @@
 menuconfig VIDEO_STM32
 	bool "Enable STM32 video support"
 	depends on VIDEO
+	select VIDEO_DAMAGE
 	help
 	  STM32 supports many video output options including RGB and
 	  DSI. This option enables these supports which can be used on
-- 
2.37.1 (Apple Git-137.1)


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* Re: [PATCH v4 9/9] video: Enable VIDEO_DAMAGE for drivers that need it
  2023-01-03 21:50 ` [PATCH v4 9/9] video: Enable VIDEO_DAMAGE for drivers that need it Alexander Graf
@ 2023-01-04 12:32   ` Neil Armstrong
  2023-01-07  0:13   ` Simon Glass
  1 sibling, 0 replies; 25+ messages in thread
From: Neil Armstrong @ 2023-01-04 12:32 UTC (permalink / raw)
  To: Alexander Graf, u-boot
  Cc: Matthias Brugger, Heinrich Schuchardt, Anatolij Gustschin,
	Simon Glass, Da Xue, Ilias Apalodimas, Jagan Teki,
	Andre Przywara, Philipp Tomsich, Kever Yang, Patrick Delaunay,
	Patrice Chotard, uboot-stm32, u-boot-amlogic

Le 03/01/2023 à 22:50, Alexander Graf a écrit :
> Some drivers call video_set_flush_dcache() to indicate that they want to
> have the dcache flushed for the frame buffer. These drivers benefit from
> our new video damage control, because we can reduce the amount of memory
> that gets flushed significantly.
> 
> This patch enables video damage control for all device drivers that call
> video_set_flush_dcache() to make sure they benefit from it.
> 
> Signed-off-by: Alexander Graf <agraf@csgraf.de>
> ---
>   arch/arm/mach-omap2/omap3/Kconfig | 1 +
>   arch/arm/mach-sunxi/Kconfig       | 1 +
>   drivers/video/Kconfig             | 9 +++++++++
>   drivers/video/exynos/Kconfig      | 1 +
>   drivers/video/imx/Kconfig         | 1 +
>   drivers/video/meson/Kconfig       | 1 +
>   drivers/video/rockchip/Kconfig    | 1 +
>   drivers/video/stm32/Kconfig       | 1 +
>   8 files changed, 16 insertions(+)
> 

<snip>

> --- a/drivers/video/meson/Kconfig
> +++ b/drivers/video/meson/Kconfig
> @@ -8,5 +8,6 @@ config VIDEO_MESON
>   	bool "Enable Amlogic Meson video support"
>   	depends on VIDEO
>   	select DISPLAY
> +	select VIDEO_DAMAGE
>   	help
>   	  Enable Amlogic Meson Video Processing Unit video support.

For Amlogic:
Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>

<snip>

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v4 5/9] efi_loader: GOP: Add damage notification on BLT
  2023-01-03 21:50 ` [PATCH v4 5/9] efi_loader: GOP: Add damage notification on BLT Alexander Graf
@ 2023-01-04 12:50   ` Heinrich Schuchardt
  0 siblings, 0 replies; 25+ messages in thread
From: Heinrich Schuchardt @ 2023-01-04 12:50 UTC (permalink / raw)
  To: Alexander Graf
  Cc: Matthias Brugger, Anatolij Gustschin, Simon Glass, Da Xue,
	Ilias Apalodimas, Jagan Teki, Andre Przywara, Neil Armstrong,
	Philipp Tomsich, Patrick Delaunay, Patrice Chotard, uboot-stm32,
	u-boot-amlogic, u-boot, Kever Yang

On 1/3/23 22:50, Alexander Graf wrote:
> Now that we have a damage tracking API, let's populate damage done by
> UEFI payloads when they BLT data onto the screen.
>
> Signed-off-by: Alexander Graf <agraf@csgraf.de>
> Reported-by: Da Xue <da@libre.computer>
>
> ---
>
> v1 -> v2:
>
>    - Remove ifdefs from gop
>
> v2 -> v3:
>
>    - Adapt to always assume DM is used
>
> v3 -> v4:
>
>    - Skip damage on EfiBltVideoToBltBuffer
> ---
>   lib/efi_loader/efi_gop.c | 6 ++++++
>   1 file changed, 6 insertions(+)
>
> diff --git a/lib/efi_loader/efi_gop.c b/lib/efi_loader/efi_gop.c
> index d1dc2f22d0..425dcbf6b1 100644
> --- a/lib/efi_loader/efi_gop.c
> +++ b/lib/efi_loader/efi_gop.c
> @@ -32,6 +32,7 @@ struct efi_gop_obj {
>   	struct efi_gop ops;
>   	struct efi_gop_mode_info info;
>   	struct efi_gop_mode mode;
> +	struct udevice *vdev;
>   	/* Fields we only have access to during init */
>   	u32 bpix;
>   	void *fb;
> @@ -120,6 +121,7 @@ static __always_inline efi_status_t gop_blt_int(struct efi_gop *this,
>   	u32 *fb32 = gopobj->fb;
>   	u16 *fb16 = gopobj->fb;
>   	struct efi_gop_pixel *buffer = __builtin_assume_aligned(bufferp, 4);
> +	bool blt_to_video = (operation != EFI_BLT_VIDEO_TO_BLT_BUFFER);

Using a variable is not really necessary but it could make the code more
accessible to readers.

Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

>
>   	if (delta) {
>   		/* Check for 4 byte alignment */
> @@ -243,6 +245,9 @@ static __always_inline efi_status_t gop_blt_int(struct efi_gop *this,
>   		dlineoff += dwidth;
>   	}
>
> +	if (blt_to_video)
> +		video_damage(gopobj->vdev, dx, dy, width, height);
> +
>   	return EFI_SUCCESS;
>   }
>
> @@ -547,6 +552,7 @@ efi_status_t efi_gop_register(void)
>   	gopobj->info.pixels_per_scanline = col;
>   	gopobj->bpix = bpix;
>   	gopobj->fb = fb;
> +	gopobj->vdev = vdev;
>
>   	return EFI_SUCCESS;
>   }


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v4 1/9] dm: video: Add damage tracking API
  2023-01-03 21:49 ` [PATCH v4 1/9] dm: video: Add damage tracking API Alexander Graf
@ 2023-01-07  0:13   ` Simon Glass
  0 siblings, 0 replies; 25+ messages in thread
From: Simon Glass @ 2023-01-07  0:13 UTC (permalink / raw)
  To: Alexander Graf
  Cc: u-boot, Matthias Brugger, Heinrich Schuchardt,
	Anatolij Gustschin, Da Xue, Ilias Apalodimas, Jagan Teki,
	Andre Przywara, Neil Armstrong, Philipp Tomsich, Kever Yang,
	Patrick Delaunay, Patrice Chotard, uboot-stm32, u-boot-amlogic

Hi Alex,

On Tue, 3 Jan 2023 at 14:50, Alexander Graf <agraf@csgraf.de> wrote:
>
> We are going to introduce image damage tracking to fasten up screen
> refresh on large displays. This patch adds damage tracking for up to
> one rectangle of the screen which is typically enough to hold blt or
> text print updates. Callers into this API and a reduced dcache flush
> code path will follow in later patches.
>
> Signed-off-by: Alexander Graf <agraf@csgraf.de>
> Reported-by: Da Xue <da@libre.computer>
>
> ---
>
> v1 -> v2:
>
>   - Remove ifdefs
>
> v2 -> v3:
>
>   - Adapt Kconfig to DM always
>
> v3 -> v4:
>
>   - Move damage clear from patch 6 to this one
>   - Simplify first damage logic
>   - Remove VIDEO_DAMAGE default for ARM
> ---
>  drivers/video/Kconfig        | 13 ++++++++++++
>  drivers/video/video-uclass.c | 41 ++++++++++++++++++++++++++++++++++++
>  include/video.h              | 29 +++++++++++++++++++++++--
>  3 files changed, 81 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
> index f539977d9b..826a1a6587 100644
> --- a/drivers/video/Kconfig
> +++ b/drivers/video/Kconfig
> @@ -62,6 +62,19 @@ config VIDEO_COPY
>           To use this, your video driver must set @copy_base in
>           struct video_uc_plat.
>
> +config VIDEO_DAMAGE
> +       bool "Enable damage tracking of frame buffer regions"
> +       help
> +         On some machines (most ARM), the display frame buffer resides in
> +         RAM. To make the display controller pick up screen updates, we
> +         have to flush frame buffer contents from CPU caches into RAM which
> +         can be a slow operation.
> +
> +         This feature adds damage tracking to collect information about regions
> +         that received updates. When we want to sync, we then only flush
> +         regions of the frame buffer that were modified before, speeding up
> +         screen refreshes significantly.
> +
>  config BACKLIGHT_PWM
>         bool "Generic PWM based Backlight Driver"
>         depends on BACKLIGHT && DM_PWM
> diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c
> index 0ce376ca3f..d18c8cd2b1 100644
> --- a/drivers/video/video-uclass.c
> +++ b/drivers/video/video-uclass.c
> @@ -21,6 +21,8 @@
>  #include <dm/device_compat.h>
>  #include <dm/device-internal.h>
>  #include <dm/uclass-internal.h>
> +#include <linux/types.h>
> +#include <linux/bitmap.h>
>  #ifdef CONFIG_SANDBOX
>  #include <asm/sdl.h>
>  #endif
> @@ -254,6 +256,37 @@ void video_set_default_colors(struct udevice *dev, bool invert)
>         priv->colour_bg = video_index_to_colour(priv, back);
>  }
>
> +/* Notify about changes in the frame buffer */
> +int video_damage(struct udevice *vid, int x, int y, int width, int height)
> +{
> +       struct video_priv *priv = dev_get_uclass_priv(vid);
> +       int endx = x + width;
> +       int endy = y + height;
> +
> +       if (!CONFIG_IS_ENABLED(VIDEO_DAMAGE))
> +               return 0;
> +
> +       if (x > priv->xsize)
> +               return 0;
> +
> +       if (y > priv->ysize)
> +               return 0;
> +
> +       if (endx > priv->xsize)
> +               endx = priv->xsize;
> +
> +       if (endy > priv->ysize)
> +               endy = priv->ysize;
> +
> +       /* Span a rectangle across all old and new damage */
> +       priv->damage.x = min(x, priv->damage.x);
> +       priv->damage.y = min(y, priv->damage.y);
> +       priv->damage.endx = max(endx, priv->damage.endx);
> +       priv->damage.endy = max(endy, priv->damage.endy);
> +
> +       return 0;

Should we make this void, then?

> +}
> +
>  /* Flush video activity to the caches */
>  int video_sync(struct udevice *vid, bool force)
>  {
> @@ -288,6 +321,14 @@ int video_sync(struct udevice *vid, bool force)
>                 last_sync = get_timer(0);
>         }
>  #endif
> +
> +       if (CONFIG_IS_ENABLED(VIDEO_DAMAGE)) {
> +               priv->damage.x = priv->xsize;
> +               priv->damage.y = priv->ysize;
> +               priv->damage.endx = 0;
> +               priv->damage.endy = 0;
> +       }
> +
>         return 0;
>  }
>
> diff --git a/include/video.h b/include/video.h
> index 43f2e2c02f..4b35e97f79 100644
> --- a/include/video.h
> +++ b/include/video.h
> @@ -109,6 +109,12 @@ struct video_priv {

Please update the comment when you add struct members.

>         void *fb;
>         int fb_size;
>         void *copy_fb;
> +       struct {
> +               int x;
> +               int y;
> +               int endx;
> +               int endy;
> +       } damage;
>         int line_length;
>         u32 colour_fg;
>         u32 colour_bg;
> @@ -211,8 +217,9 @@ int video_fill(struct udevice *dev, u32 colour);
>   * @return: 0 on success, error code otherwise
>   *
>   * Some frame buffers are cached or have a secondary frame buffer. This
> - * function syncs these up so that the current contents of the U-Boot frame
> - * buffer are displayed to the user.
> + * function syncs the damaged parts of them up so that the current contents
> + * of the U-Boot frame buffer are displayed to the user. It clears the damage
> + * buffer.
>   */
>  int video_sync(struct udevice *vid, bool force);
>
> @@ -332,6 +339,24 @@ static inline int video_sync_copy_all(struct udevice *dev)
>
>  #endif
>
> +/**
> + * video_damage() - Notify the video subsystem about screen updates.
> + *
> + * @vid:       Device to sync
> + * @x:         Upper left X coordinate of the damaged rectangle
> + * @y:         Upper left Y coordinate of the damaged rectangle
> + * @width:     Width of the damaged rectangle
> + * @height:    Height of the damaged rectangle
> + *
> + * @return: 0

Returns: 0

(that is the style now, sadly meaning that much of U-Boot needs to be updated)

> + *
> + * Some frame buffers are cached or have a secondary frame buffer. This
> + * function notifies the video subsystem about rectangles that were updated
> + * within the frame buffer. They may only get written to the screen on the
> + * next call to video_sync().
> + */
> +int video_damage(struct udevice *vid, int x, int y, int width, int height);
> +
>  /**
>   * video_is_active() - Test if one video device it active
>   *
> --
> 2.37.1 (Apple Git-137.1)
>

Regards,
Simon

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v4 2/9] dm: video: Add damage notification on display clear
  2023-01-03 21:49 ` [PATCH v4 2/9] dm: video: Add damage notification on display clear Alexander Graf
@ 2023-01-07  0:13   ` Simon Glass
  0 siblings, 0 replies; 25+ messages in thread
From: Simon Glass @ 2023-01-07  0:13 UTC (permalink / raw)
  To: Alexander Graf
  Cc: u-boot, Matthias Brugger, Heinrich Schuchardt,
	Anatolij Gustschin, Da Xue, Ilias Apalodimas, Jagan Teki,
	Andre Przywara, Neil Armstrong, Philipp Tomsich, Kever Yang,
	Patrick Delaunay, Patrice Chotard, uboot-stm32, u-boot-amlogic

On Tue, 3 Jan 2023 at 14:50, Alexander Graf <agraf@csgraf.de> wrote:
>
> Let's report the video damage when we clear the screen. This
> way we can later lazily flush only relevant regions to hardware.
>
> Signed-off-by: Alexander Graf <agraf@csgraf.de>
> Reported-by: Da Xue <da@libre.computer>
> ---
>  drivers/video/video-uclass.c | 2 ++
>  1 file changed, 2 insertions(+)

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v4 3/9] vidconsole: Add damage notifications to all vidconsole drivers
  2023-01-03 21:49 ` [PATCH v4 3/9] vidconsole: Add damage notifications to all vidconsole drivers Alexander Graf
@ 2023-01-07  0:13   ` Simon Glass
  0 siblings, 0 replies; 25+ messages in thread
From: Simon Glass @ 2023-01-07  0:13 UTC (permalink / raw)
  To: Alexander Graf
  Cc: u-boot, Matthias Brugger, Heinrich Schuchardt,
	Anatolij Gustschin, Da Xue, Ilias Apalodimas, Jagan Teki,
	Andre Przywara, Neil Armstrong, Philipp Tomsich, Kever Yang,
	Patrick Delaunay, Patrice Chotard, uboot-stm32, u-boot-amlogic

On Tue, 3 Jan 2023 at 14:50, Alexander Graf <agraf@csgraf.de> wrote:
>
> Now that we have a damage tracking API, let's populate damage done by
> vidconsole drivers. We try to declare as little memory as damaged as
> possible, with the exception of rotated screens that I couldn't get my
> head wrapped around. On those, we revert to the old behavior and mark
> the full screen as damaged on every update.
>
> Signed-off-by: Alexander Graf <agraf@csgraf.de>
> Reported-by: Da Xue <da@libre.computer>
>
> ---
>
> v1 -> v2:
>
>   - Fix ranges in truetype target
>   - Limit rotate to necessary damange
> ---
>  drivers/video/console_normal.c   | 10 ++++++
>  drivers/video/console_rotate.c   | 54 ++++++++++++++++++++++++++++++++
>  drivers/video/console_truetype.c | 15 +++++++++
>  3 files changed, 79 insertions(+)
>

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v4 4/9] video: Add damage notification on bmp display
  2023-01-03 21:49 ` [PATCH v4 4/9] video: Add damage notification on bmp display Alexander Graf
@ 2023-01-07  0:13   ` Simon Glass
  0 siblings, 0 replies; 25+ messages in thread
From: Simon Glass @ 2023-01-07  0:13 UTC (permalink / raw)
  To: Alexander Graf
  Cc: u-boot, Matthias Brugger, Heinrich Schuchardt,
	Anatolij Gustschin, Da Xue, Ilias Apalodimas, Jagan Teki,
	Andre Przywara, Neil Armstrong, Philipp Tomsich, Kever Yang,
	Patrick Delaunay, Patrice Chotard, uboot-stm32, u-boot-amlogic

On Tue, 3 Jan 2023 at 14:50, Alexander Graf <agraf@csgraf.de> wrote:
>
> Let's report the video damage when we draw a bitmap on the screen. This
> way we can later lazily flush only relevant regions to hardware.
>
> Signed-off-by: Alexander Graf <agraf@csgraf.de>
> Reported-by: Da Xue <da@libre.computer>
> ---
>  drivers/video/video_bmp.c | 2 ++
>  1 file changed, 2 insertions(+)
>

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v4 6/9] video: Only dcache flush damaged lines
  2023-01-03 21:50 ` [PATCH v4 6/9] video: Only dcache flush damaged lines Alexander Graf
@ 2023-01-07  0:13   ` Simon Glass
  0 siblings, 0 replies; 25+ messages in thread
From: Simon Glass @ 2023-01-07  0:13 UTC (permalink / raw)
  To: Alexander Graf
  Cc: u-boot, Matthias Brugger, Heinrich Schuchardt,
	Anatolij Gustschin, Da Xue, Ilias Apalodimas, Jagan Teki,
	Andre Przywara, Neil Armstrong, Philipp Tomsich, Kever Yang,
	Patrick Delaunay, Patrice Chotard, uboot-stm32, u-boot-amlogic

On Tue, 3 Jan 2023 at 14:50, Alexander Graf <agraf@csgraf.de> wrote:
>
> Now that we have a damage area tells us which parts of the frame buffer
> actually need updating, let's only dcache flush those on video_sync()
> calls. With this optimization in place, frame buffer updates - especially
> on large screen such as 4k displays - speed up significantly.
>
> Signed-off-by: Alexander Graf <agraf@csgraf.de>
> Reported-by: Da Xue <da@libre.computer>
>
> ---
>
> v1 -> v2:
>
>   - Fix dcache range; we were flushing too much before
>   - Remove ifdefs
>
> v3 -> v4:
>
>   - Simplify first damage logic
> ---
>  drivers/video/video-uclass.c | 45 +++++++++++++++++++++++++++++-------
>  1 file changed, 37 insertions(+), 8 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v4 7/9] video: Use VIDEO_DAMAGE for VIDEO_COPY
  2023-01-03 21:50 ` [PATCH v4 7/9] video: Use VIDEO_DAMAGE for VIDEO_COPY Alexander Graf
@ 2023-01-07  0:13   ` Simon Glass
  2023-01-07 22:40     ` Heinrich Schuchardt
  0 siblings, 1 reply; 25+ messages in thread
From: Simon Glass @ 2023-01-07  0:13 UTC (permalink / raw)
  To: Alexander Graf
  Cc: u-boot, Matthias Brugger, Heinrich Schuchardt,
	Anatolij Gustschin, Da Xue, Ilias Apalodimas, Jagan Teki,
	Andre Przywara, Neil Armstrong, Philipp Tomsich, Kever Yang,
	Patrick Delaunay, Patrice Chotard, uboot-stm32, u-boot-amlogic

Hi Alexander,

On Tue, 3 Jan 2023 at 14:50, Alexander Graf <agraf@csgraf.de> wrote:
>
> CONFIG_VIDEO_COPY implemented a range based copying mechanism: If we

range-based

> print a single character, it will always copy the full range of bytes
> from the top left corner of the character to the lower right onto the
> uncached frame buffer. This includes pretty much the full line contents
> of the printed character.
>
> Since we now have proper damage tracking, let's make use of that to reduce
> the amount of data we need to copy. With this patch applied, we will only
> copy the tiny rectangle surrounding characters when we print them,
> speeding up the video console.
>
> As a bonus, we remove a lot of code.
>
> Signed-off-by: Alexander Graf <agraf@csgraf.de>
>
> ---
>
> v2 -> v3:
>
>   - Rebase
>   - Make CONFIG_COPY always select VIDEO_DAMAGE
> ---
>  drivers/video/Kconfig             |  5 ++
>  drivers/video/console_normal.c    | 14 +----
>  drivers/video/console_rotate.c    | 37 ++-----------
>  drivers/video/console_truetype.c  | 17 +-----
>  drivers/video/vidconsole-uclass.c | 16 ------
>  drivers/video/video-uclass.c      | 91 ++++++++-----------------------
>  drivers/video/video_bmp.c         |  7 ---
>  include/video.h                   | 37 -------------
>  include/video_console.h           | 49 -----------------
>  9 files changed, 37 insertions(+), 236 deletions(-)
>

This feature needs some tests in test/dm/video.c

For sandbox, I think you will need to allow it to be enabled /
disabled at runtime, so the some tests can use it and some not?

Regards,
Simon

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v4 0/9] Add video damage tracking
  2023-01-03 21:49 [PATCH v4 0/9] Add video damage tracking Alexander Graf
                   ` (8 preceding siblings ...)
  2023-01-03 21:50 ` [PATCH v4 9/9] video: Enable VIDEO_DAMAGE for drivers that need it Alexander Graf
@ 2023-01-07  0:13 ` Simon Glass
  2023-04-14  7:35 ` Antonio Murdaca
  10 siblings, 0 replies; 25+ messages in thread
From: Simon Glass @ 2023-01-07  0:13 UTC (permalink / raw)
  To: Alexander Graf
  Cc: u-boot, Matthias Brugger, Heinrich Schuchardt,
	Anatolij Gustschin, Da Xue, Ilias Apalodimas, Jagan Teki,
	Andre Przywara, Neil Armstrong, Philipp Tomsich, Kever Yang,
	Patrick Delaunay, Patrice Chotard, uboot-stm32, u-boot-amlogic

Hi Alex,

On Tue, 3 Jan 2023 at 14:50, Alexander Graf <agraf@csgraf.de> wrote:
>
> This patch set speeds up graphics output on ARM by a factor of 60x.
>
> On most ARM SBCs, we keep the frame buffer in DRAM and map it as cached,
> but need it accessible by the display controller which reads directly
> from a later point of consistency. Hence, we flush the frame buffer to
> DRAM on every change. The full frame buffer.
>
> Unfortunately, with the advent of 4k displays, we are seeing frame buffers
> that can take a while to flush out. This was reported by Da Xue with grub,
> which happily print 1000s of spaces on the screen to draw a menu. Every
> printed space triggers a cache flush.
>
> This patch set implements the easiest mitigation against this problem:
> Damage tracking. We remember the lowest common denominator region that was
> touched since the last video_sync() call and only flush that. The most
> typical writer to the frame buffer is the video console, which always
> writes rectangles of characters on the screen and syncs afterwards.
>
> With this patch set applied, we reduce drawing a large grub menu (with
> serial console attached for size information) on an RK3399-ROC system
> at 1440p from 55 seconds to less than 1 second.
>
> Version 2 also implements VIDEO_COPY using this mechanism, reducing its
> overhead compared to before as well. So even x86 systems should be faster
> with this now :).
>
>
> Alternatives considered:
>
>   1) Lazy sync - Sandbox does this. It only calls video_sync(true) ever
>      so often. We are missing timers to do this generically.
>
>   2) Double buffering - We could try to identify whether anything changed
>      at all and only draw to the FB if it did. That would require
>      maintaining a second buffer that we need to scan.
>
>   3) Text buffer - Maintain a buffer of all text printed on the screen with
>      respective location. Don't write if the old and new character are
>      identical. This would limit applicability to text only and is an
>      optimization on top of this patch set.
>
>   4) Hash screen lines - Create a hash (sha256?) over every line when it
>      changes. Only flush when it does. I'm not sure if this would waste
>      more time, memory and cache than the current approach. It would make
>      full screen updates much more expensive.
>
> v1 -> v2:
>
>   - new patch: video: Use VIDEO_DAMAGE for VIDEO_COPY
>   - Remove ifdefs
>   - Fix dcache range; we were flushing too much before
>   - Fix ranges in truetype target
>   - Limit rotate to necessary damange

damage

>
> v2 -> v3:
>
>   - Rebase
>   - Adapt to DM_VIDEO always
>   - Make CONFIG_COPY always select VIDEO_DAMAGE
>
> v3 -> v4:
>
>   - New patch: video: Always compile cache flushing code
>   - New patch: video: Enable VIDEO_DAMAGE for drivers that need it
>   - Simplify first damage logic
>   - Skip damage on EfiBltVideoToBltBuffer
>   - Move damage clear from patch 6 to patch 1
>   - Remove VIDEO_DAMAGE default for ARM
>
> Alexander Graf (9):
>   dm: video: Add damage tracking API
>   dm: video: Add damage notification on display clear
>   vidconsole: Add damage notifications to all vidconsole drivers
>   video: Add damage notification on bmp display
>   efi_loader: GOP: Add damage notification on BLT
>   video: Only dcache flush damaged lines
>   video: Use VIDEO_DAMAGE for VIDEO_COPY
>   video: Always compile cache flushing code
>   video: Enable VIDEO_DAMAGE for drivers that need it
>
>  arch/arm/mach-omap2/omap3/Kconfig |   1 +
>  arch/arm/mach-sunxi/Kconfig       |   1 +
>  drivers/video/Kconfig             |  27 +++++
>  drivers/video/console_normal.c    |  22 ++--
>  drivers/video/console_rotate.c    |  87 +++++++++-----
>  drivers/video/console_truetype.c  |  30 ++---
>  drivers/video/exynos/Kconfig      |   1 +
>  drivers/video/imx/Kconfig         |   1 +
>  drivers/video/meson/Kconfig       |   1 +
>  drivers/video/rockchip/Kconfig    |   1 +
>  drivers/video/stm32/Kconfig       |   1 +
>  drivers/video/vidconsole-uclass.c |  16 ---
>  drivers/video/video-uclass.c      | 187 +++++++++++++++++-------------
>  drivers/video/video_bmp.c         |   7 +-
>  include/video.h                   |  54 ++++-----
>  include/video_console.h           |  49 --------
>  lib/efi_loader/efi_gop.c          |   6 +
>  17 files changed, 251 insertions(+), 241 deletions(-)
>
> --
> 2.37.1 (Apple Git-137.1)
>

This looks good but needs tests and a rebase to -next

Regards,
Simon

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v4 8/9] video: Always compile cache flushing code
  2023-01-03 21:50 ` [PATCH v4 8/9] video: Always compile cache flushing code Alexander Graf
@ 2023-01-07  0:13   ` Simon Glass
  0 siblings, 0 replies; 25+ messages in thread
From: Simon Glass @ 2023-01-07  0:13 UTC (permalink / raw)
  To: Alexander Graf
  Cc: u-boot, Matthias Brugger, Heinrich Schuchardt,
	Anatolij Gustschin, Da Xue, Ilias Apalodimas, Jagan Teki,
	Andre Przywara, Neil Armstrong, Philipp Tomsich, Kever Yang,
	Patrick Delaunay, Patrice Chotard, uboot-stm32, u-boot-amlogic

On Tue, 3 Jan 2023 at 14:50, Alexander Graf <agraf@csgraf.de> wrote:
>
> The dcache flushing code path was conditional on ARM && !DCACHE config
> options. However, dcaches exist on other platforms as well and may need
> clearing if their driver requires it.
>
> Simplify the compile logic and always enable the dcache flush logic in
> the video core. That way, drivers can always rely on it to call the arch
> specific callbacks.
>
> This will increase code size for non-ARM platforms with CONFIG_VIDEO=y
> slightly.
>
> Reported-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> Signed-off-by: Alexander Graf <agraf@csgraf.de>
> ---
>  drivers/video/video-uclass.c | 14 +++++---------
>  1 file changed, 5 insertions(+), 9 deletions(-)
>

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v4 9/9] video: Enable VIDEO_DAMAGE for drivers that need it
  2023-01-03 21:50 ` [PATCH v4 9/9] video: Enable VIDEO_DAMAGE for drivers that need it Alexander Graf
  2023-01-04 12:32   ` Neil Armstrong
@ 2023-01-07  0:13   ` Simon Glass
  1 sibling, 0 replies; 25+ messages in thread
From: Simon Glass @ 2023-01-07  0:13 UTC (permalink / raw)
  To: Alexander Graf
  Cc: u-boot, Matthias Brugger, Heinrich Schuchardt,
	Anatolij Gustschin, Da Xue, Ilias Apalodimas, Jagan Teki,
	Andre Przywara, Neil Armstrong, Philipp Tomsich, Kever Yang,
	Patrick Delaunay, Patrice Chotard, uboot-stm32, u-boot-amlogic

Hi Alex,

On Tue, 3 Jan 2023 at 14:50, Alexander Graf <agraf@csgraf.de> wrote:
>
> Some drivers call video_set_flush_dcache() to indicate that they want to
> have the dcache flushed for the frame buffer. These drivers benefit from
> our new video damage control, because we can reduce the amount of memory
> that gets flushed significantly.
>
> This patch enables video damage control for all device drivers that call
> video_set_flush_dcache() to make sure they benefit from it.
>
> Signed-off-by: Alexander Graf <agraf@csgraf.de>
> ---
>  arch/arm/mach-omap2/omap3/Kconfig | 1 +
>  arch/arm/mach-sunxi/Kconfig       | 1 +
>  drivers/video/Kconfig             | 9 +++++++++
>  drivers/video/exynos/Kconfig      | 1 +
>  drivers/video/imx/Kconfig         | 1 +
>  drivers/video/meson/Kconfig       | 1 +
>  drivers/video/rockchip/Kconfig    | 1 +
>  drivers/video/stm32/Kconfig       | 1 +
>  8 files changed, 16 insertions(+)
>
> diff --git a/arch/arm/mach-omap2/omap3/Kconfig b/arch/arm/mach-omap2/omap3/Kconfig
> index 3e97ec2629..ea231f16a2 100644
> --- a/arch/arm/mach-omap2/omap3/Kconfig
> +++ b/arch/arm/mach-omap2/omap3/Kconfig
> @@ -113,6 +113,7 @@ config TARGET_NOKIA_RX51
>         select CMDLINE_TAG
>         select INITRD_TAG
>         select REVISION_TAG
> +       select VIDEO_DAMAGE

Please avoid using select since it means that boards cannot disable it.

You can use 'imply' instead.

Or you can use 'default y' for the damage Kconfig.

Regards,
Simon

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v4 7/9] video: Use VIDEO_DAMAGE for VIDEO_COPY
  2023-01-07  0:13   ` Simon Glass
@ 2023-01-07 22:40     ` Heinrich Schuchardt
  2023-01-08 15:48       ` Simon Glass
  0 siblings, 1 reply; 25+ messages in thread
From: Heinrich Schuchardt @ 2023-01-07 22:40 UTC (permalink / raw)
  To: Simon Glass
  Cc: u-boot, Matthias Brugger, Anatolij Gustschin, Da Xue,
	Ilias Apalodimas, Jagan Teki, Andre Przywara, Neil Armstrong,
	Philipp Tomsich, Kever Yang, Patrick Delaunay, Patrice Chotard,
	uboot-stm32, u-boot-amlogic, Alexander Graf

On 1/7/23 01:13, Simon Glass wrote:
> Hi Alexander,
>
> On Tue, 3 Jan 2023 at 14:50, Alexander Graf <agraf@csgraf.de> wrote:
>>
>> CONFIG_VIDEO_COPY implemented a range based copying mechanism: If we
>
> range-based
>
>> print a single character, it will always copy the full range of bytes
>> from the top left corner of the character to the lower right onto the
>> uncached frame buffer. This includes pretty much the full line contents
>> of the printed character.
>>
>> Since we now have proper damage tracking, let's make use of that to reduce
>> the amount of data we need to copy. With this patch applied, we will only
>> copy the tiny rectangle surrounding characters when we print them,
>> speeding up the video console.
>>
>> As a bonus, we remove a lot of code.
>>
>> Signed-off-by: Alexander Graf <agraf@csgraf.de>
>>
>> ---
>>
>> v2 -> v3:
>>
>>    - Rebase
>>    - Make CONFIG_COPY always select VIDEO_DAMAGE
>> ---
>>   drivers/video/Kconfig             |  5 ++
>>   drivers/video/console_normal.c    | 14 +----
>>   drivers/video/console_rotate.c    | 37 ++-----------
>>   drivers/video/console_truetype.c  | 17 +-----
>>   drivers/video/vidconsole-uclass.c | 16 ------
>>   drivers/video/video-uclass.c      | 91 ++++++++-----------------------
>>   drivers/video/video_bmp.c         |  7 ---
>>   include/video.h                   | 37 -------------
>>   include/video_console.h           | 49 -----------------
>>   9 files changed, 37 insertions(+), 236 deletions(-)
>>
>
> This feature needs some tests in test/dm/video.c
>
> For sandbox, I think you will need to allow it to be enabled /
> disabled at runtime, so the some tests can use it and some not?

It should be good enough to enable the feature in one of the sandbox
defconfigs and disable it in another.

Best regards

Heinrich

>
> Regards,
> Simon


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v4 7/9] video: Use VIDEO_DAMAGE for VIDEO_COPY
  2023-01-07 22:40     ` Heinrich Schuchardt
@ 2023-01-08 15:48       ` Simon Glass
  0 siblings, 0 replies; 25+ messages in thread
From: Simon Glass @ 2023-01-08 15:48 UTC (permalink / raw)
  To: Heinrich Schuchardt
  Cc: u-boot, Matthias Brugger, Anatolij Gustschin, Da Xue,
	Ilias Apalodimas, Jagan Teki, Andre Przywara, Neil Armstrong,
	Philipp Tomsich, Kever Yang, Patrick Delaunay, Patrice Chotard,
	uboot-stm32, u-boot-amlogic, Alexander Graf

Hi Heinrich,

On Sat, 7 Jan 2023 at 16:22, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>
> On 1/7/23 01:13, Simon Glass wrote:
> > Hi Alexander,
> >
> > On Tue, 3 Jan 2023 at 14:50, Alexander Graf <agraf@csgraf.de> wrote:
> >>
> >> CONFIG_VIDEO_COPY implemented a range based copying mechanism: If we
> >
> > range-based
> >
> >> print a single character, it will always copy the full range of bytes
> >> from the top left corner of the character to the lower right onto the
> >> uncached frame buffer. This includes pretty much the full line contents
> >> of the printed character.
> >>
> >> Since we now have proper damage tracking, let's make use of that to reduce
> >> the amount of data we need to copy. With this patch applied, we will only
> >> copy the tiny rectangle surrounding characters when we print them,
> >> speeding up the video console.
> >>
> >> As a bonus, we remove a lot of code.
> >>
> >> Signed-off-by: Alexander Graf <agraf@csgraf.de>
> >>
> >> ---
> >>
> >> v2 -> v3:
> >>
> >>    - Rebase
> >>    - Make CONFIG_COPY always select VIDEO_DAMAGE
> >> ---
> >>   drivers/video/Kconfig             |  5 ++
> >>   drivers/video/console_normal.c    | 14 +----
> >>   drivers/video/console_rotate.c    | 37 ++-----------
> >>   drivers/video/console_truetype.c  | 17 +-----
> >>   drivers/video/vidconsole-uclass.c | 16 ------
> >>   drivers/video/video-uclass.c      | 91 ++++++++-----------------------
> >>   drivers/video/video_bmp.c         |  7 ---
> >>   include/video.h                   | 37 -------------
> >>   include/video_console.h           | 49 -----------------
> >>   9 files changed, 37 insertions(+), 236 deletions(-)
> >>
> >
> > This feature needs some tests in test/dm/video.c
> >
> > For sandbox, I think you will need to allow it to be enabled /
> > disabled at runtime, so the some tests can use it and some not?
>
> It should be good enough to enable the feature in one of the sandbox
> defconfigs and disable it in another.

Yes that would work, e.g. enable in sandbox but not sandbox_flattree

Regards,
Simon

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v4 0/9] Add video damage tracking
  2023-01-03 21:49 [PATCH v4 0/9] Add video damage tracking Alexander Graf
                   ` (9 preceding siblings ...)
  2023-01-07  0:13 ` [PATCH v4 0/9] Add video damage tracking Simon Glass
@ 2023-04-14  7:35 ` Antonio Murdaca
  2023-04-19  1:45   ` Simon Glass
  10 siblings, 1 reply; 25+ messages in thread
From: Antonio Murdaca @ 2023-04-14  7:35 UTC (permalink / raw)
  To: u-boot

Hi, this patch set applies cleanly on 2023.01 and solves the issue on the 
rockpro64 where the grub would take forever to draw on the screen.
Thanks



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v4 0/9] Add video damage tracking
  2023-04-14  7:35 ` Antonio Murdaca
@ 2023-04-19  1:45   ` Simon Glass
  0 siblings, 0 replies; 25+ messages in thread
From: Simon Glass @ 2023-04-19  1:45 UTC (permalink / raw)
  To: Antonio Murdaca, Alex Graf, Heinrich Schuchardt; +Cc: u-boot

Hi Antonio,

+Alex Graf
+Heinrich Schuchardt

On Fri, 14 Apr 2023 at 08:55, Antonio Murdaca <antoniomurdaca@gmail.com> wrote:
>
> Hi, this patch set applies cleanly on 2023.01 and solves the issue on the
> rockpro64 where the grub would take forever to draw on the screen.

Could we get some tests added for this so we can get it into the tree.

Alternatively, is there a way to avoid flushing after every space? I
notice that even sandbox has started doing this, so something is wrong
somewhere.

Heinrich do you know anything about that?

Regards,
Simon

^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2023-04-19  1:48 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-03 21:49 [PATCH v4 0/9] Add video damage tracking Alexander Graf
2023-01-03 21:49 ` [PATCH v4 1/9] dm: video: Add damage tracking API Alexander Graf
2023-01-07  0:13   ` Simon Glass
2023-01-03 21:49 ` [PATCH v4 2/9] dm: video: Add damage notification on display clear Alexander Graf
2023-01-07  0:13   ` Simon Glass
2023-01-03 21:49 ` [PATCH v4 3/9] vidconsole: Add damage notifications to all vidconsole drivers Alexander Graf
2023-01-07  0:13   ` Simon Glass
2023-01-03 21:49 ` [PATCH v4 4/9] video: Add damage notification on bmp display Alexander Graf
2023-01-07  0:13   ` Simon Glass
2023-01-03 21:50 ` [PATCH v4 5/9] efi_loader: GOP: Add damage notification on BLT Alexander Graf
2023-01-04 12:50   ` Heinrich Schuchardt
2023-01-03 21:50 ` [PATCH v4 6/9] video: Only dcache flush damaged lines Alexander Graf
2023-01-07  0:13   ` Simon Glass
2023-01-03 21:50 ` [PATCH v4 7/9] video: Use VIDEO_DAMAGE for VIDEO_COPY Alexander Graf
2023-01-07  0:13   ` Simon Glass
2023-01-07 22:40     ` Heinrich Schuchardt
2023-01-08 15:48       ` Simon Glass
2023-01-03 21:50 ` [PATCH v4 8/9] video: Always compile cache flushing code Alexander Graf
2023-01-07  0:13   ` Simon Glass
2023-01-03 21:50 ` [PATCH v4 9/9] video: Enable VIDEO_DAMAGE for drivers that need it Alexander Graf
2023-01-04 12:32   ` Neil Armstrong
2023-01-07  0:13   ` Simon Glass
2023-01-07  0:13 ` [PATCH v4 0/9] Add video damage tracking Simon Glass
2023-04-14  7:35 ` Antonio Murdaca
2023-04-19  1:45   ` Simon Glass

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.