mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] mem: add flush callback to sync caches for execution
@ 2026-04-13 10:28 Ahmad Fatoum
  2026-04-13 11:24 ` Sascha Hauer
  2026-04-14  6:31 ` Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2026-04-13 10:28 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

barebox always calls sync_caches_for_execution() on boot, but it can be
useful to trigger it manually when testing:

- memcpy -s /dev/zero -d /dev/mem 0 $TFA_REGION_BASE $TFA_REGION_SIZE
- sync /dev/mem # flush D$ and invalidate I$
- smc -i        # check if PSCI monitor is still usable

Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 drivers/misc/mem.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/misc/mem.c b/drivers/misc/mem.c
index 0cf021cf97ba..b356c6eab389 100644
--- a/drivers/misc/mem.c
+++ b/drivers/misc/mem.c
@@ -6,11 +6,19 @@
 #include <common.h>
 #include <driver.h>
 #include <init.h>
+#include <asm/cache.h>
+
+static int mem_flush(struct cdev *cdev)
+{
+	sync_caches_for_execution();
+	return 0;
+}
 
 static struct cdev_operations memops = {
 	.read  = mem_read,
 	.write = mem_write,
 	.memmap = generic_memmap_rw,
+	.flush = mem_flush,
 };
 
 static int mem_probe(struct device *dev)
-- 
2.47.3




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

* Re: [PATCH] mem: add flush callback to sync caches for execution
  2026-04-13 10:28 [PATCH] mem: add flush callback to sync caches for execution Ahmad Fatoum
@ 2026-04-13 11:24 ` Sascha Hauer
  2026-04-14  6:31 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2026-04-13 11:24 UTC (permalink / raw)
  To: barebox, Ahmad Fatoum


On Mon, 13 Apr 2026 12:28:12 +0200, Ahmad Fatoum wrote:
> barebox always calls sync_caches_for_execution() on boot, but it can be
> useful to trigger it manually when testing:
> 
> - memcpy -s /dev/zero -d /dev/mem 0 $TFA_REGION_BASE $TFA_REGION_SIZE
> - sync /dev/mem # flush D$ and invalidate I$
> - smc -i        # check if PSCI monitor is still usable
> 
> [...]

Applied, thanks!

[1/1] mem: add flush callback to sync caches for execution
      https://git.pengutronix.de/cgit/barebox/commit/?id=4f0cf6a66d84 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




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

* Re: [PATCH] mem: add flush callback to sync caches for execution
  2026-04-13 10:28 [PATCH] mem: add flush callback to sync caches for execution Ahmad Fatoum
  2026-04-13 11:24 ` Sascha Hauer
@ 2026-04-14  6:31 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2026-04-14  6:31 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Mon, Apr 13, 2026 at 12:28:12PM +0200, Ahmad Fatoum wrote:
> barebox always calls sync_caches_for_execution() on boot, but it can be
> useful to trigger it manually when testing:
> 
> - memcpy -s /dev/zero -d /dev/mem 0 $TFA_REGION_BASE $TFA_REGION_SIZE
> - sync /dev/mem # flush D$ and invalidate I$
> - smc -i        # check if PSCI monitor is still usable
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
> ---
>  drivers/misc/mem.c | 8 ++++++++
>  1 file changed, 8 insertions(+)

Reverted this one. It breaks compilation on riscv:

In file included from drivers/misc/mem.c:9:
arch/riscv/include/asm/cache.h: In function 'local_flush_icache_all':
arch/riscv/include/asm/cache.h:25:9: error: implicit declaration of function 'riscv_vendor_id' [-Werror=implicit-function-declaration]
   25 |  switch(riscv_vendor_id()) {

And PowerPC:

powerpc-603e-linux-gnu-ld: drivers/misc/mem.o: in function `mem_flush':
drivers/misc/mem.c:13:(.text.mem_flush+0xc): undefined reference to `sync_caches_for_execution'
make[1]: *** [Makefile:1099: barebox] Error 1

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



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

end of thread, other threads:[~2026-04-14  6:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-04-13 10:28 [PATCH] mem: add flush callback to sync caches for execution Ahmad Fatoum
2026-04-13 11:24 ` Sascha Hauer
2026-04-14  6:31 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox