diff mbox

[U-Boot,1/4] cmd_mem.c: add a memory wait (mwait) command

Message ID 1447157597-3645-1-git-send-email-jacquiot.aurelien@gmail.com
State Changes Requested
Delegated to: Tom Rini
Headers show

Commit Message

Aurelien Jacquiot Nov. 10, 2015, 12:13 p.m. UTC
From: Aurelien Jacquiot <a-jacquiot@ti.com>

This new memory command allows to wait a given value in memory.
It can be useful when U-Boot is used in a slave mode (another device
is pushing images to the local memory) such as RapidIO or any
RDMA kind of transport. We can then be notified that images have been
loaded to our memory before booting.

Usage is: mwait[.b, .w, .l, .q] address value

Signed-off-by: Aurelien Jacquiot <a-jacquiot@ti.com>
---
 common/cmd_mem.c |   69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 69 insertions(+), 0 deletions(-)

Comments

Tom Rini Jan. 4, 2016, 3:50 p.m. UTC | #1
On Tue, Nov 10, 2015 at 01:13:17PM +0100, jacquiot.aurelien@gmail.com wrote:

> From: Aurelien Jacquiot <a-jacquiot@ti.com>
> 
> This new memory command allows to wait a given value in memory.
> It can be useful when U-Boot is used in a slave mode (another device
> is pushing images to the local memory) such as RapidIO or any
> RDMA kind of transport. We can then be notified that images have been
> loaded to our memory before booting.
> 
> Usage is: mwait[.b, .w, .l, .q] address value

First, we need to add a new CONFIG_CMD_MWAIT (and Kconfig entry) for
this.  Second:

> +		WATCHDOG_RESET();
> +		udelay(1000);

Lets use 100 here not 1000, after looking at how long we wait during
'sleep' which is this an equivalent of.  Thanks!
diff mbox

Patch

diff --git a/common/cmd_mem.c b/common/cmd_mem.c
index 43c3fb6..af6e39d 100644
--- a/common/cmd_mem.c
+++ b/common/cmd_mem.c
@@ -1238,6 +1238,65 @@  static int do_mem_crc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
 #endif
 
+static int
+do_mem_mwait(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+	ulong addr;
+#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+	u64   val, readval;
+#else
+	ulong val, readval;
+#endif
+	int   size;
+
+	if (argc != 3)
+		return CMD_RET_USAGE;
+
+	/* check for size specification */
+	size = cmd_get_data_size(argv[0], 4);
+	if (size < 1)
+		return 1;
+
+	/* first arg: address */
+	addr = simple_strtoul(argv[1], NULL, 16);
+
+	/* second arg: expected value */
+#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+	val = simple_strtoull(argv[2], NULL, 16);
+	printf("waiting 0x%llx at 0x%lx...\n", val, addr);
+#else
+	val = simple_strtoul(argv[2], NULL, 16);
+	printf("waiting 0x%lx at 0x%lx...\n", val, addr);
+#endif
+
+	for (;;) {
+		if (size == 4)
+			readval = *((u32 *)addr);
+#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+		else if (size == 8)
+			readval = *((u64 *)addr);
+#endif
+		else if (size == 2)
+			readval = *((u16 *)addr);
+		else
+			readval = *((u8 *)addr);
+
+		if (readval == val)
+			return 0;
+
+		/* check for ctrl-c to abort... */
+		if (ctrlc()) {
+			puts("Abort\n");
+			return 0;
+		}
+
+		WATCHDOG_RESET();
+		udelay(1000);
+	}
+
+	return 0;
+}
+
 /**************************************************/
 U_BOOT_CMD(
 	md,	3,	1,	do_mem_md,
@@ -1399,6 +1458,16 @@  U_BOOT_CMD(
 );
 #endif /* CONFIG_MX_CYCLIC */
 
+U_BOOT_CMD(
+	mwait,	3,	1,	do_mem_mwait,
+	"memory wait for value",
+#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+	"[.b, .w, .l, .q] address value\n"
+#else
+	"[.b, .w, .l] address value\n"
+#endif
+);
+
 #ifdef CONFIG_CMD_MEMINFO
 U_BOOT_CMD(
 	meminfo,	3,	1,	do_mem_info,