Skip to contentSkip to conversation

riscv: timer: Add support for an early timer

PATCH New Pragnesh Patel 3 participants 11 messages Nov 17, 2020 – Dec 21, 2020 1 message not in the archive

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

PATCH 1/1 riscv: timer: Add support for an early timer

Added support for timer_early_get_count() and timer_early_get_rate() This is mostly useful in tracing.

---
 drivers/timer/andes_plmt_timer.c   | 21 ++++++++++++++++++++-
 drivers/timer/riscv_timer.c        | 21 ++++++++++++++++++++-
 drivers/timer/sifive_clint_timer.c | 21 ++++++++++++++++++++-
 include/configs/ax25-ae350.h       |  5 +++++
 include/configs/sifive-fu540.h     |  5 +++++
 5 files changed, 70 insertions(+), 3 deletions(-)
drivers/timer/andes_plmt_timer.c +20 -1
index cec86718c7..74b795c97a 100644
@@ -17,11 +17,30 @@
 /* mtime register */
 #define MTIME_REG(base)			((ulong)(base))
 
-static u64 andes_plmt_get_count(struct udevice *dev)
+static u64 notrace andes_plmt_get_count(struct udevice *dev)
 {
 	return readq((void __iomem *)MTIME_REG(dev->priv));
 }
 
+#if CONFIG_IS_ENABLED(RISCV_MMODE)
+/**
+ * timer_early_get_rate() - Get the timer rate before driver model
+ */
+unsigned long notrace timer_early_get_rate(void)
+{
+	return RISCV_MMODE_TIMER_FREQ;
+}
+
+/**
+ * timer_early_get_count() - Get the timer count before driver model
+ *
+ */
+u64 notrace timer_early_get_count(void)
+{
+	return readq((void __iomem *)MTIME_REG(RISCV_MMODE_TIMERBASE));
+}
+#endif
+
 static const struct timer_ops andes_plmt_ops = {
 	.get_count = andes_plmt_get_count,
 };
drivers/timer/riscv_timer.c +20 -1
index 21ae184057..a0f71ca897 100644
@@ -16,7 +16,7 @@
 #include <timer.h>
 #include <asm/csr.h>
 
-static u64 riscv_timer_get_count(struct udevice *dev)
+static u64 notrace riscv_timer_get_count(struct udevice *dev)
 {
 	__maybe_unused u32 hi, lo;
 
@@ -31,6 +31,25 @@ static u64 riscv_timer_get_count(struct udevice *dev)
 	return ((u64)hi << 32) | lo;
 }
 
+#if CONFIG_IS_ENABLED(RISCV_SMODE)
+/**
+ * timer_early_get_rate() - Get the timer rate before driver model
+ */
+unsigned long notrace timer_early_get_rate(void)
+{
+	return RISCV_SMODE_TIMER_FREQ;
+}
+
+/**
+ * timer_early_get_count() - Get the timer count before driver model
+ *
+ */
+u64 notrace timer_early_get_count(void)
+{
+	return riscv_timer_get_count(NULL);
+}
+#endif
+
 static int riscv_timer_probe(struct udevice *dev)
 {
 	struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
drivers/timer/sifive_clint_timer.c +20 -1
index 00ce0f08d6..9ae05a0e7e 100644
@@ -14,11 +14,30 @@
 /* mtime register */
 #define MTIME_REG(base)			((ulong)(base) + 0xbff8)
 
-static u64 sifive_clint_get_count(struct udevice *dev)
+static u64 notrace sifive_clint_get_count(struct udevice *dev)
 {
 	return readq((void __iomem *)MTIME_REG(dev->priv));
 }
 
+#if CONFIG_IS_ENABLED(RISCV_MMODE)
+/**
+ * timer_early_get_rate() - Get the timer rate before driver model
+ */
+unsigned long notrace timer_early_get_rate(void)
+{
+	return RISCV_MMODE_TIMER_FREQ;
+}
+
+/**
+ * timer_early_get_count() - Get the timer count before driver model
+ *
+ */
+u64 notrace timer_early_get_count(void)
+{
+	return readq((void __iomem *)MTIME_REG(RISCV_MMODE_TIMERBASE));
+}
+#endif
+
 static const struct timer_ops sifive_clint_ops = {
 	.get_count = sifive_clint_get_count,
 };
include/configs/ax25-ae350.h +5 -0
index b2606e794d..bd9c371f83 100644
@@ -17,6 +17,11 @@
 #endif
 #endif
 
+#define RISCV_MMODE_TIMERBASE           0xe6000000
+#define RISCV_MMODE_TIMER_FREQ          60000000
+
+#define RISCV_SMODE_TIMER_FREQ          60000000
+
 /*
  * CPU and Board Configuration Options
  */
include/configs/sifive-fu540.h +5 -0
index c1c79db147..0d69d1c548 100644
@@ -36,6 +36,11 @@
 
 #define CONFIG_STANDALONE_LOAD_ADDR	0x80200000
 
+#define RISCV_MMODE_TIMERBASE		0x2000000
+#define RISCV_MMODE_TIMER_FREQ		1000000
+
+#define RISCV_SMODE_TIMER_FREQ		1000000
+
 /* Environment options */
 
 #ifndef CONFIG_SPL_BUILD
Signature · 1 line
2.17.1

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw

PATCH 1/1 riscv: timer: Add support for an early timer

Hi Pragnesh,

Quoted 9 lines

From: Pragnesh Patel [mailto:pragnesh.patel at sifive.com]
Sent: Tuesday, November 17, 2020 7:05 PM
To: u-boot at lists.denx.de
Cc: atish.patra at wdc.com; palmerdabbelt at google.com; bmeng.cn at gmail.com; paul.walmsley at sifive.com; anup.patel at wdc.com; sagar.kadam at sifive.com; Rick Jian-Zhi Chen(???); Pragnesh Patel; Palmer Dabbelt; Sean Anderson; Simon Glass; Bin Meng
Subject: [PATCH] riscv: timer: Add support for an early timer

Added support for timer_early_get_count() and timer_early_get_rate() This is mostly useful in tracing.

Quoted 9 lines
---
 drivers/timer/andes_plmt_timer.c   | 21 ++++++++++++++++++++-
 drivers/timer/riscv_timer.c        | 21 ++++++++++++++++++++-
 drivers/timer/sifive_clint_timer.c | 21 ++++++++++++++++++++-
 include/configs/ax25-ae350.h       |  5 +++++
 include/configs/sifive-fu540.h     |  5 +++++
 5 files changed, 70 insertions(+), 3 deletions(-)

I verify with ae350_rv64_defconfig

make FTRACE=1 ae350_rv64_defconfig
make FTRACE=1

and it boot fail as below:

U-Boot 2021.01-rc2-00140-geb42715 (Nov 24 2020 - 15:02:18 +0800)

DRAM:  1 GiB
trace: enabled

DO you have any suggestions ?

Thanks,
Rick

Quoted 145 lines
drivers/timer/andes_plmt_timer.c +20 -1
index cec86718c7..74b795c97a 100644
@@ -17,11 +17,30 @@
 /* mtime register */
 #define MTIME_REG(base)                        ((ulong)(base))
 
-static u64 andes_plmt_get_count(struct udevice *dev)
+static u64 notrace andes_plmt_get_count(struct udevice *dev)
 {
        return readq((void __iomem *)MTIME_REG(dev->priv));
 }
 
+#if CONFIG_IS_ENABLED(RISCV_MMODE)
+/**
+ * timer_early_get_rate() - Get the timer rate before driver model
+ */
+unsigned long notrace timer_early_get_rate(void)
+{
+       return RISCV_MMODE_TIMER_FREQ;
+}
+
+/**
+ * timer_early_get_count() - Get the timer count before driver model
+ *
+ */
+u64 notrace timer_early_get_count(void)
+{
+       return readq((void __iomem *)MTIME_REG(RISCV_MMODE_TIMERBASE));
+}
+#endif
+
 static const struct timer_ops andes_plmt_ops = {
        .get_count = andes_plmt_get_count,
 };
drivers/timer/riscv_timer.c +20 -1
index 21ae184057..a0f71ca897 100644
@@ -16,7 +16,7 @@
 #include <timer.h>
 #include <asm/csr.h>
 
-static u64 riscv_timer_get_count(struct udevice *dev)
+static u64 notrace riscv_timer_get_count(struct udevice *dev)
 {
        __maybe_unused u32 hi, lo;
 
@@ -31,6 +31,25 @@ static u64 riscv_timer_get_count(struct udevice *dev)
        return ((u64)hi << 32) | lo;
 }
 
+#if CONFIG_IS_ENABLED(RISCV_SMODE)
+/**
+ * timer_early_get_rate() - Get the timer rate before driver model
+ */
+unsigned long notrace timer_early_get_rate(void)
+{
+       return RISCV_SMODE_TIMER_FREQ;
+}
+
+/**
+ * timer_early_get_count() - Get the timer count before driver model
+ *
+ */
+u64 notrace timer_early_get_count(void)
+{
+       return riscv_timer_get_count(NULL);
+}
+#endif
+
 static int riscv_timer_probe(struct udevice *dev)
 {
        struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
drivers/timer/sifive_clint_timer.c +20 -1
index 00ce0f08d6..9ae05a0e7e 100644
@@ -14,11 +14,30 @@
 /* mtime register */
 #define MTIME_REG(base)                        ((ulong)(base) + 0xbff8)
 
-static u64 sifive_clint_get_count(struct udevice *dev)
+static u64 notrace sifive_clint_get_count(struct udevice *dev)
 {
        return readq((void __iomem *)MTIME_REG(dev->priv));
 }
 
+#if CONFIG_IS_ENABLED(RISCV_MMODE)
+/**
+ * timer_early_get_rate() - Get the timer rate before driver model
+ */
+unsigned long notrace timer_early_get_rate(void)
+{
+       return RISCV_MMODE_TIMER_FREQ;
+}
+
+/**
+ * timer_early_get_count() - Get the timer count before driver model
+ *
+ */
+u64 notrace timer_early_get_count(void)
+{
+       return readq((void __iomem *)MTIME_REG(RISCV_MMODE_TIMERBASE));
+}
+#endif
+
 static const struct timer_ops sifive_clint_ops = {
        .get_count = sifive_clint_get_count,
 };
include/configs/ax25-ae350.h +5 -0
index b2606e794d..bd9c371f83 100644
@@ -17,6 +17,11 @@
 #endif
 #endif
 
+#define RISCV_MMODE_TIMERBASE           0xe6000000
+#define RISCV_MMODE_TIMER_FREQ          60000000
+
+#define RISCV_SMODE_TIMER_FREQ          60000000
+
 /*
  * CPU and Board Configuration Options
  */
include/configs/sifive-fu540.h +5 -1
index c1c79db147..0d69d1c548 100644
@@ -36,6 +36,11 @@
 
 #define CONFIG_STANDALONE_LOAD_ADDR    0x80200000
 
+#define RISCV_MMODE_TIMERBASE          0x2000000
+#define RISCV_MMODE_TIMER_FREQ         1000000
+
+#define RISCV_SMODE_TIMER_FREQ         1000000
+
 /* Environment options */
 
 #ifndef CONFIG_SPL_BUILD
--

2.17.1

#3 lore raw

PATCH 1/1 riscv: timer: Add support for an early timer

Hi Rick,

Quoted 45 lines

-----Original Message-----
From: Rick Chen <[email protected]>
Sent: 24 November 2020 13:08
To: Pragnesh Patel <[email protected]>
Cc: U-Boot Mailing List <[email protected]>; Atish Patra <[email protected]>; Bin Meng <[email protected]>; Paul Walmsley ( Sifive) <[email protected]>; Anup Patel <[email protected]>; Sagar Kadam <[email protected]>; Palmer Dabbelt <[email protected]>; Simon Glass <[email protected]>; rick <[email protected]>; Alan Kao <[email protected]>; Leo Liang <[email protected]>
Subject: Re: [PATCH] riscv: timer: Add support for an early timer

[External Email] Do not click links or attachments unless you recognize the sender and know the content is safe

Hi Pragnesh,

Quoted 4 lines

From: Pragnesh Patel [mailto:pragnesh.patel at sifive.com]
Sent: Tuesday, November 17, 2020 7:05 PM
To: u-boot at lists.denx.de
Cc: atish.patra at wdc.com; palmerdabbelt at google.com;

bmeng.cn at gmail.com;

Quoted 8 lines

paul.walmsley at sifive.com; anup.patel at wdc.com; sagar.kadam at sifive.com; Rick Jian-Zhi Chen(???); Pragnesh Patel; Palmer Dabbelt; Sean Anderson; Simon Glass; Bin Meng
Subject: [PATCH] riscv: timer: Add support for an early timer

Added support for timer_early_get_count() and timer_early_get_rate() This is mostly useful in tracing.

Quoted 9 lines
---
 drivers/timer/andes_plmt_timer.c   | 21 ++++++++++++++++++++-
 drivers/timer/riscv_timer.c        | 21 ++++++++++++++++++++-
 drivers/timer/sifive_clint_timer.c | 21 ++++++++++++++++++++-
 include/configs/ax25-ae350.h       |  5 +++++
 include/configs/sifive-fu540.h     |  5 +++++
 5 files changed, 70 insertions(+), 3 deletions(-)

I verify with ae350_rv64_defconfig

make FTRACE=1 ae350_rv64_defconfig
make FTRACE=1

Quoted 8 lines

and it boot fail as below:

U-Boot 2021.01-rc2-00140-geb42715 (Nov 24 2020 - 15:02:18 +0800)

DRAM:  1 GiB
trace: enabled

DO you have any suggestions ?

Please enable CONFIG_TIMER_EARLY=y in ae350_rv64_defconfig

Actually in v2, I will make TRACE to select TIMER_EARLY like below,

lib/Kconfig +1 -0
@@ -210,6 +210,7 @@ config BITREVERSE
 config TRACE
        bool "Support for tracing of function calls and timing"
        imply CMD_TRACE
+       select TIMER_EARLY
 

Let me know if you have any suggestion.

Quoted 134 lines

Thanks,
Rick

Quoted 130 lines
drivers/timer/andes_plmt_timer.c +17 -1
index cec86718c7..74b795c97a 100644
@@ -17,11 +17,30 @@
 /* mtime register */
 #define MTIME_REG(base)                        ((ulong)(base))
 
-static u64 andes_plmt_get_count(struct udevice *dev)
+static u64 notrace andes_plmt_get_count(struct udevice *dev)
 {
        return readq((void __iomem *)MTIME_REG(dev->priv));  }
 
+#if CONFIG_IS_ENABLED(RISCV_MMODE)
+/**
+ * timer_early_get_rate() - Get the timer rate before driver model
+*/ unsigned long notrace timer_early_get_rate(void) {
+       return RISCV_MMODE_TIMER_FREQ; }
+
+/**
+ * timer_early_get_count() - Get the timer count before driver model
+ *
+ */
+u64 notrace timer_early_get_count(void) {
+       return readq((void __iomem
+*)MTIME_REG(RISCV_MMODE_TIMERBASE));
+}
+#endif
+
 static const struct timer_ops andes_plmt_ops = {
        .get_count = andes_plmt_get_count,  }; diff --git

a/drivers/timer/riscv_timer.c b/drivers/timer/riscv_timer.c index 21ae184057..a0f71ca897 100644

drivers/timer/riscv_timer.c +14 -1
@@ -16,7 +16,7 @@
 #include <timer.h>
 #include <asm/csr.h>
 
-static u64 riscv_timer_get_count(struct udevice *dev)
+static u64 notrace riscv_timer_get_count(struct udevice *dev)
 {
        __maybe_unused u32 hi, lo;
 
@@ -31,6 +31,25 @@ static u64 riscv_timer_get_count(struct udevice *dev)
        return ((u64)hi << 32) | lo;
 }
 
+#if CONFIG_IS_ENABLED(RISCV_SMODE)
+/**
+ * timer_early_get_rate() - Get the timer rate before driver model
+*/ unsigned long notrace timer_early_get_rate(void) {
+       return RISCV_SMODE_TIMER_FREQ; }
+
+/**
+ * timer_early_get_count() - Get the timer count before driver model
+ *
+ */
+u64 notrace timer_early_get_count(void) {
+       return riscv_timer_get_count(NULL); } #endif
+
 static int riscv_timer_probe(struct udevice *dev)  {
        struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
drivers/timer/sifive_clint_timer.c +17 -1
index 00ce0f08d6..9ae05a0e7e 100644
@@ -14,11 +14,30 @@
 /* mtime register */
 #define MTIME_REG(base)                        ((ulong)(base) + 0xbff8)
 
-static u64 sifive_clint_get_count(struct udevice *dev)
+static u64 notrace sifive_clint_get_count(struct udevice *dev)
 {
        return readq((void __iomem *)MTIME_REG(dev->priv));  }
 
+#if CONFIG_IS_ENABLED(RISCV_MMODE)
+/**
+ * timer_early_get_rate() - Get the timer rate before driver model
+*/ unsigned long notrace timer_early_get_rate(void) {
+       return RISCV_MMODE_TIMER_FREQ; }
+
+/**
+ * timer_early_get_count() - Get the timer count before driver model
+ *
+ */
+u64 notrace timer_early_get_count(void) {
+       return readq((void __iomem
+*)MTIME_REG(RISCV_MMODE_TIMERBASE));
+}
+#endif
+
 static const struct timer_ops sifive_clint_ops = {
        .get_count = sifive_clint_get_count,  }; diff --git

a/include/configs/ax25-ae350.h b/include/configs/ax25-ae350.h index b2606e794d..bd9c371f83 100644

include/configs/ax25-ae350.h +5 -0
@@ -17,6 +17,11 @@
 #endif
 #endif
 
+#define RISCV_MMODE_TIMERBASE           0xe6000000
+#define RISCV_MMODE_TIMER_FREQ          60000000
+
+#define RISCV_SMODE_TIMER_FREQ          60000000
+
 /*
  * CPU and Board Configuration Options
  */
(quoted diff) +0 -0

b/include/configs/sifive-fu540.h index c1c79db147..0d69d1c548 100644

include/configs/sifive-fu540.h +5 -1
@@ -36,6 +36,11 @@
 
 #define CONFIG_STANDALONE_LOAD_ADDR    0x80200000
 
+#define RISCV_MMODE_TIMERBASE          0x2000000
+#define RISCV_MMODE_TIMER_FREQ         1000000
+
+#define RISCV_SMODE_TIMER_FREQ         1000000
+
 /* Environment options */
 
 #ifndef CONFIG_SPL_BUILD
--

2.17.1

#4 lore raw

PATCH 1/1 riscv: timer: Add support for an early timer

Hi Pragnesh

Quoted 68 lines

Hi Rick,

Quoted 45 lines

-----Original Message-----
From: Rick Chen <[email protected]>
Sent: 24 November 2020 13:08
To: Pragnesh Patel <[email protected]>
Cc: U-Boot Mailing List <[email protected]>; Atish Patra <[email protected]>; Bin Meng <[email protected]>; Paul Walmsley ( Sifive) <[email protected]>; Anup Patel <[email protected]>; Sagar Kadam <[email protected]>; Palmer Dabbelt <[email protected]>; Simon Glass <[email protected]>; rick <[email protected]>; Alan Kao <[email protected]>; Leo Liang <[email protected]>
Subject: Re: [PATCH] riscv: timer: Add support for an early timer

[External Email] Do not click links or attachments unless you recognize the sender and know the content is safe

Hi Pragnesh,

Quoted 4 lines

From: Pragnesh Patel [mailto:pragnesh.patel at sifive.com]
Sent: Tuesday, November 17, 2020 7:05 PM
To: u-boot at lists.denx.de
Cc: atish.patra at wdc.com; palmerdabbelt at google.com;

bmeng.cn at gmail.com;

Quoted 8 lines

paul.walmsley at sifive.com; anup.patel at wdc.com; sagar.kadam at sifive.com; Rick Jian-Zhi Chen(???); Pragnesh Patel; Palmer Dabbelt; Sean Anderson; Simon Glass; Bin Meng
Subject: [PATCH] riscv: timer: Add support for an early timer

Added support for timer_early_get_count() and timer_early_get_rate() This is mostly useful in tracing.

Quoted 9 lines
---
 drivers/timer/andes_plmt_timer.c   | 21 ++++++++++++++++++++-
 drivers/timer/riscv_timer.c        | 21 ++++++++++++++++++++-
 drivers/timer/sifive_clint_timer.c | 21 ++++++++++++++++++++-
 include/configs/ax25-ae350.h       |  5 +++++
 include/configs/sifive-fu540.h     |  5 +++++
 5 files changed, 70 insertions(+), 3 deletions(-)

I verify with ae350_rv64_defconfig

make FTRACE=1 ae350_rv64_defconfig
make FTRACE=1

Quoted 8 lines

and it boot fail as below:

U-Boot 2021.01-rc2-00140-geb42715 (Nov 24 2020 - 15:02:18 +0800)

DRAM:  1 GiB
trace: enabled

DO you have any suggestions ?

Please enable CONFIG_TIMER_EARLY=y in ae350_rv64_defconfig

Actually in v2, I will make TRACE to select TIMER_EARLY like below,

lib/Kconfig +1 -0
@@ -210,6 +210,7 @@ config BITREVERSE
 config TRACE
        bool "Support for tracing of function calls and timing"
        imply CMD_TRACE
+       select TIMER_EARLY
 
Quoted 1 line

Let me know if you have any suggestion.

OK.

After add CONFIG_TIMER_EARLY, U-Boot boots ok.
But When I try to booting kernel with FTRACE=1, following are the test stats:

ae350_rv64_spl_defconfig without FTRACE=1, kernel booting is ok. ae350_rv64_spl_defconfig with FTRACE=1, kernel booting fail. ae350_rv64_defconfig with FTRACE=1, kernel booting is ok

The failure case seems not reasonable.
Any suggestions ?

Thanks,
Rick

Quoted 135 lines
Quoted 135 lines

Thanks,
Rick

Quoted 130 lines
drivers/timer/andes_plmt_timer.c +17 -1
index cec86718c7..74b795c97a 100644
@@ -17,11 +17,30 @@
 /* mtime register */
 #define MTIME_REG(base)                        ((ulong)(base))
 
-static u64 andes_plmt_get_count(struct udevice *dev)
+static u64 notrace andes_plmt_get_count(struct udevice *dev)
 {
        return readq((void __iomem *)MTIME_REG(dev->priv));  }
 
+#if CONFIG_IS_ENABLED(RISCV_MMODE)
+/**
+ * timer_early_get_rate() - Get the timer rate before driver model
+*/ unsigned long notrace timer_early_get_rate(void) {
+       return RISCV_MMODE_TIMER_FREQ; }
+
+/**
+ * timer_early_get_count() - Get the timer count before driver model
+ *
+ */
+u64 notrace timer_early_get_count(void) {
+       return readq((void __iomem
+*)MTIME_REG(RISCV_MMODE_TIMERBASE));
+}
+#endif
+
 static const struct timer_ops andes_plmt_ops = {
        .get_count = andes_plmt_get_count,  }; diff --git

a/drivers/timer/riscv_timer.c b/drivers/timer/riscv_timer.c index 21ae184057..a0f71ca897 100644

drivers/timer/riscv_timer.c +14 -1
@@ -16,7 +16,7 @@
 #include <timer.h>
 #include <asm/csr.h>
 
-static u64 riscv_timer_get_count(struct udevice *dev)
+static u64 notrace riscv_timer_get_count(struct udevice *dev)
 {
        __maybe_unused u32 hi, lo;
 
@@ -31,6 +31,25 @@ static u64 riscv_timer_get_count(struct udevice *dev)
        return ((u64)hi << 32) | lo;
 }
 
+#if CONFIG_IS_ENABLED(RISCV_SMODE)
+/**
+ * timer_early_get_rate() - Get the timer rate before driver model
+*/ unsigned long notrace timer_early_get_rate(void) {
+       return RISCV_SMODE_TIMER_FREQ; }
+
+/**
+ * timer_early_get_count() - Get the timer count before driver model
+ *
+ */
+u64 notrace timer_early_get_count(void) {
+       return riscv_timer_get_count(NULL); } #endif
+
 static int riscv_timer_probe(struct udevice *dev)  {
        struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
drivers/timer/sifive_clint_timer.c +17 -1
index 00ce0f08d6..9ae05a0e7e 100644
@@ -14,11 +14,30 @@
 /* mtime register */
 #define MTIME_REG(base)                        ((ulong)(base) + 0xbff8)
 
-static u64 sifive_clint_get_count(struct udevice *dev)
+static u64 notrace sifive_clint_get_count(struct udevice *dev)
 {
        return readq((void __iomem *)MTIME_REG(dev->priv));  }
 
+#if CONFIG_IS_ENABLED(RISCV_MMODE)
+/**
+ * timer_early_get_rate() - Get the timer rate before driver model
+*/ unsigned long notrace timer_early_get_rate(void) {
+       return RISCV_MMODE_TIMER_FREQ; }
+
+/**
+ * timer_early_get_count() - Get the timer count before driver model
+ *
+ */
+u64 notrace timer_early_get_count(void) {
+       return readq((void __iomem
+*)MTIME_REG(RISCV_MMODE_TIMERBASE));
+}
+#endif
+
 static const struct timer_ops sifive_clint_ops = {
        .get_count = sifive_clint_get_count,  }; diff --git

a/include/configs/ax25-ae350.h b/include/configs/ax25-ae350.h index b2606e794d..bd9c371f83 100644

include/configs/ax25-ae350.h +5 -0
@@ -17,6 +17,11 @@
 #endif
 #endif
 
+#define RISCV_MMODE_TIMERBASE           0xe6000000
+#define RISCV_MMODE_TIMER_FREQ          60000000
+
+#define RISCV_SMODE_TIMER_FREQ          60000000
+
 /*
  * CPU and Board Configuration Options
  */
(quoted diff) +0 -0

b/include/configs/sifive-fu540.h index c1c79db147..0d69d1c548 100644

include/configs/sifive-fu540.h +5 -1
@@ -36,6 +36,11 @@
 
 #define CONFIG_STANDALONE_LOAD_ADDR    0x80200000
 
+#define RISCV_MMODE_TIMERBASE          0x2000000
+#define RISCV_MMODE_TIMER_FREQ         1000000
+
+#define RISCV_SMODE_TIMER_FREQ         1000000
+
 /* Environment options */
 
 #ifndef CONFIG_SPL_BUILD
--

2.17.1

#5 lore raw

PATCH 1/1 riscv: timer: Add support for an early timer

Hi Rick,

Quoted 94 lines

-----Original Message-----
From: Rick Chen <[email protected]>
Sent: 26 November 2020 14:44
To: Pragnesh Patel <[email protected]>
Cc: Simon Glass <[email protected]>; U-Boot Mailing List <u- boot at lists.denx.de>; Atish Patra <[email protected]>; Bin Meng <[email protected]>; Paul Walmsley ( Sifive) <[email protected]>; Anup Patel <[email protected]>; Sagar Kadam <[email protected]>; Palmer Dabbelt <[email protected]>; rick <[email protected]>; Alan Kao <[email protected]>; Leo Liang <[email protected]>
Subject: Re: [PATCH] riscv: timer: Add support for an early timer

[External Email] Do not click links or attachments unless you recognize the sender and know the content is safe

Hi Pragnesh

Quoted 69 lines

Hi Rick,

Quoted 46 lines

-----Original Message-----
From: Rick Chen <[email protected]>
Sent: 24 November 2020 13:08
To: Pragnesh Patel <[email protected]>
Cc: U-Boot Mailing List <[email protected]>; Atish Patra <[email protected]>; Bin Meng <[email protected]>; Paul Walmsley ( Sifive) <[email protected]>; Anup Patel <[email protected]>; Sagar Kadam <[email protected]>; Palmer Dabbelt <[email protected]>; Simon Glass <[email protected]>; rick <[email protected]>; Alan Kao <[email protected]>; Leo Liang <[email protected]>
Subject: Re: [PATCH] riscv: timer: Add support for an early timer

[External Email] Do not click links or attachments unless you recognize the sender and know the content is safe

Hi Pragnesh,

Quoted 4 lines

From: Pragnesh Patel [mailto:pragnesh.patel at sifive.com]
Sent: Tuesday, November 17, 2020 7:05 PM
To: u-boot at lists.denx.de
Cc: atish.patra at wdc.com; palmerdabbelt at google.com;

bmeng.cn at gmail.com;

Quoted 8 lines

paul.walmsley at sifive.com; anup.patel at wdc.com; sagar.kadam at sifive.com; Rick Jian-Zhi Chen(???); Pragnesh Patel; Palmer Dabbelt; Sean Anderson; Simon Glass; Bin Meng
Subject: [PATCH] riscv: timer: Add support for an early timer

Added support for timer_early_get_count() and timer_early_get_rate() This is mostly useful in tracing.

Quoted 9 lines
---
 drivers/timer/andes_plmt_timer.c   | 21 ++++++++++++++++++++-
 drivers/timer/riscv_timer.c        | 21 ++++++++++++++++++++-
 drivers/timer/sifive_clint_timer.c | 21 ++++++++++++++++++++-
 include/configs/ax25-ae350.h       |  5 +++++
 include/configs/sifive-fu540.h     |  5 +++++
 5 files changed, 70 insertions(+), 3 deletions(-)

I verify with ae350_rv64_defconfig

make FTRACE=1 ae350_rv64_defconfig
make FTRACE=1

Quoted 8 lines

and it boot fail as below:

U-Boot 2021.01-rc2-00140-geb42715 (Nov 24 2020 - 15:02:18 +0800)

DRAM:  1 GiB
trace: enabled

DO you have any suggestions ?

Please enable CONFIG_TIMER_EARLY=y in ae350_rv64_defconfig

Actually in v2, I will make TRACE to select TIMER_EARLY like below,

lib/Kconfig +1 -0
@@ -210,6 +210,7 @@ config BITREVERSE
 config TRACE
        bool "Support for tracing of function calls and timing"
        imply CMD_TRACE
+       select TIMER_EARLY
 
Quoted 1 line

Let me know if you have any suggestion.

OK.

After add CONFIG_TIMER_EARLY, U-Boot boots ok.
But When I try to booting kernel with FTRACE=1, following are the test stats:

Quoted 6 lines

ae350_rv64_spl_defconfig without FTRACE=1, kernel booting is ok. ae350_rv64_spl_defconfig with FTRACE=1, kernel booting fail. ae350_rv64_defconfig with FTRACE=1, kernel booting is ok

The failure case seems not reasonable.
Any suggestions ?

Strange, Can you please tell me which steps you follow and also send some debug logs if possible.

Quoted 143 lines

Thanks,
Rick

Quoted 46 lines
Quoted 46 lines

Thanks,
Rick

Quoted 41 lines
drivers/timer/andes_plmt_timer.c +18 -1
index cec86718c7..74b795c97a 100644
@@ -17,11 +17,30 @@
 /* mtime register */
 #define MTIME_REG(base)                        ((ulong)(base))
 
-static u64 andes_plmt_get_count(struct udevice *dev)
+static u64 notrace andes_plmt_get_count(struct udevice *dev)
 {
        return readq((void __iomem *)MTIME_REG(dev->priv));  }
 
+#if CONFIG_IS_ENABLED(RISCV_MMODE)
+/**
+ * timer_early_get_rate() - Get the timer rate before driver model
+*/ unsigned long notrace timer_early_get_rate(void) {
+       return RISCV_MMODE_TIMER_FREQ; }
+
+/**
+ * timer_early_get_count() - Get the timer count before driver
+model
+ *
+ */
+u64 notrace timer_early_get_count(void) {
+       return readq((void __iomem
+*)MTIME_REG(RISCV_MMODE_TIMERBASE));
+}
+#endif
+
 static const struct timer_ops andes_plmt_ops = {
        .get_count = andes_plmt_get_count,  }; diff --git

a/drivers/timer/riscv_timer.c b/drivers/timer/riscv_timer.c index 21ae184057..a0f71ca897 100644

drivers/timer/riscv_timer.c +0 -0
@@ -16,7 +16,7 @@
 #include <timer.h>
 #include <asm/csr.h>
 
Quoted 6 lines
Quoted 6 lines

drivers/timer/riscv_timer.c static u64 riscv_timer_get_count(struct udevice

Quoted 6 lines
drivers/timer/riscv_timer.c +1 -1
-static u64 riscv_timer_get_count(struct udevice *dev)
+static u64 notrace riscv_timer_get_count(struct udevice *dev)
 {
        __maybe_unused u32 hi, lo;
 
@@ -31,6 +31,25 @@ static u64 riscv_timer_get_count(struct udevice

*dev)

Quoted 86 lines
Quoted 86 lines
Quoted 86 lines
drivers/timer/riscv_timer.c +14 -0
        return ((u64)hi << 32) | lo;  }
 
+#if CONFIG_IS_ENABLED(RISCV_SMODE)
+/**
+ * timer_early_get_rate() - Get the timer rate before driver model
+*/ unsigned long notrace timer_early_get_rate(void) {
+       return RISCV_SMODE_TIMER_FREQ; }
+
+/**
+ * timer_early_get_count() - Get the timer count before driver
+model
+ *
+ */
+u64 notrace timer_early_get_count(void) {
+       return riscv_timer_get_count(NULL); } #endif
+
 static int riscv_timer_probe(struct udevice *dev)  {
        struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
drivers/timer/sifive_clint_timer.c +18 -1
index 00ce0f08d6..9ae05a0e7e 100644
@@ -14,11 +14,30 @@
 /* mtime register */
 #define MTIME_REG(base)                        ((ulong)(base) + 0xbff8)
 
-static u64 sifive_clint_get_count(struct udevice *dev)
+static u64 notrace sifive_clint_get_count(struct udevice *dev)
 {
        return readq((void __iomem *)MTIME_REG(dev->priv));  }
 
+#if CONFIG_IS_ENABLED(RISCV_MMODE)
+/**
+ * timer_early_get_rate() - Get the timer rate before driver model
+*/ unsigned long notrace timer_early_get_rate(void) {
+       return RISCV_MMODE_TIMER_FREQ; }
+
+/**
+ * timer_early_get_count() - Get the timer count before driver
+model
+ *
+ */
+u64 notrace timer_early_get_count(void) {
+       return readq((void __iomem
+*)MTIME_REG(RISCV_MMODE_TIMERBASE));
+}
+#endif
+
 static const struct timer_ops sifive_clint_ops = {
        .get_count = sifive_clint_get_count,  }; diff --git

a/include/configs/ax25-ae350.h b/include/configs/ax25-ae350.h index b2606e794d..bd9c371f83 100644

include/configs/ax25-ae350.h +5 -0
@@ -17,6 +17,11 @@
 #endif
 #endif
 
+#define RISCV_MMODE_TIMERBASE           0xe6000000
+#define RISCV_MMODE_TIMER_FREQ          60000000
+
+#define RISCV_SMODE_TIMER_FREQ          60000000
+
 /*
  * CPU and Board Configuration Options
  */
(quoted diff) +0 -0

b/include/configs/sifive-fu540.h index c1c79db147..0d69d1c548 100644

include/configs/sifive-fu540.h +5 -1
@@ -36,6 +36,11 @@
 
 #define CONFIG_STANDALONE_LOAD_ADDR    0x80200000
 
+#define RISCV_MMODE_TIMERBASE          0x2000000
+#define RISCV_MMODE_TIMER_FREQ         1000000
+
+#define RISCV_SMODE_TIMER_FREQ         1000000
+
 /* Environment options */
 
 #ifndef CONFIG_SPL_BUILD
--

2.17.1

#6 lore raw

PATCH 1/1 riscv: timer: Add support for an early timer

Hi, Pragnesh

Quoted 96 lines

Hi Rick,

Quoted 94 lines

-----Original Message-----
From: Rick Chen <[email protected]>
Sent: 26 November 2020 14:44
To: Pragnesh Patel <[email protected]>
Cc: Simon Glass <[email protected]>; U-Boot Mailing List <u- boot at lists.denx.de>; Atish Patra <[email protected]>; Bin Meng <[email protected]>; Paul Walmsley ( Sifive) <[email protected]>; Anup Patel <[email protected]>; Sagar Kadam <[email protected]>; Palmer Dabbelt <[email protected]>; rick <[email protected]>; Alan Kao <[email protected]>; Leo Liang <[email protected]>
Subject: Re: [PATCH] riscv: timer: Add support for an early timer

[External Email] Do not click links or attachments unless you recognize the sender and know the content is safe

Hi Pragnesh

Quoted 69 lines

Hi Rick,

Quoted 46 lines

-----Original Message-----
From: Rick Chen <[email protected]>
Sent: 24 November 2020 13:08
To: Pragnesh Patel <[email protected]>
Cc: U-Boot Mailing List <[email protected]>; Atish Patra <[email protected]>; Bin Meng <[email protected]>; Paul Walmsley ( Sifive) <[email protected]>; Anup Patel <[email protected]>; Sagar Kadam <[email protected]>; Palmer Dabbelt <[email protected]>; Simon Glass <[email protected]>; rick <[email protected]>; Alan Kao <[email protected]>; Leo Liang <[email protected]>
Subject: Re: [PATCH] riscv: timer: Add support for an early timer

[External Email] Do not click links or attachments unless you recognize the sender and know the content is safe

Hi Pragnesh,

Quoted 4 lines

From: Pragnesh Patel [mailto:pragnesh.patel at sifive.com]
Sent: Tuesday, November 17, 2020 7:05 PM
To: u-boot at lists.denx.de
Cc: atish.patra at wdc.com; palmerdabbelt at google.com;

bmeng.cn at gmail.com;

Quoted 8 lines

paul.walmsley at sifive.com; anup.patel at wdc.com; sagar.kadam at sifive.com; Rick Jian-Zhi Chen(???); Pragnesh Patel; Palmer Dabbelt; Sean Anderson; Simon Glass; Bin Meng
Subject: [PATCH] riscv: timer: Add support for an early timer

Added support for timer_early_get_count() and timer_early_get_rate() This is mostly useful in tracing.

Quoted 9 lines
---
 drivers/timer/andes_plmt_timer.c   | 21 ++++++++++++++++++++-
 drivers/timer/riscv_timer.c        | 21 ++++++++++++++++++++-
 drivers/timer/sifive_clint_timer.c | 21 ++++++++++++++++++++-
 include/configs/ax25-ae350.h       |  5 +++++
 include/configs/sifive-fu540.h     |  5 +++++
 5 files changed, 70 insertions(+), 3 deletions(-)

I verify with ae350_rv64_defconfig

make FTRACE=1 ae350_rv64_defconfig
make FTRACE=1

Quoted 8 lines

and it boot fail as below:

U-Boot 2021.01-rc2-00140-geb42715 (Nov 24 2020 - 15:02:18 +0800)

DRAM:  1 GiB
trace: enabled

DO you have any suggestions ?

Please enable CONFIG_TIMER_EARLY=y in ae350_rv64_defconfig

Actually in v2, I will make TRACE to select TIMER_EARLY like below,

lib/Kconfig +1 -0
@@ -210,6 +210,7 @@ config BITREVERSE
 config TRACE
        bool "Support for tracing of function calls and timing"
        imply CMD_TRACE
+       select TIMER_EARLY
 
Quoted 1 line

Let me know if you have any suggestion.

OK.

After add CONFIG_TIMER_EARLY, U-Boot boots ok.
But When I try to booting kernel with FTRACE=1, following are the test stats:

Quoted 9 lines
Quoted 6 lines

ae350_rv64_spl_defconfig without FTRACE=1, kernel booting is ok. ae350_rv64_spl_defconfig with FTRACE=1, kernel booting fail. ae350_rv64_defconfig with FTRACE=1, kernel booting is ok

The failure case seems not reasonable.
Any suggestions ?

Strange, Can you please tell me which steps you follow and also send some debug logs if possible.

Following are the configurations, steps and debug logs:

+++ b/configs/ae350_rv64_defconfig
q+CONFIG_TRACE=y
+CONFIG_TRACE_BUFFER_SIZE=0x01000000
+CONFIG_TRACE_CALL_DEPTH_LIMIT=15
+CONFIG_CMD_TRACE=y
+CONFIG_TIMER_EARLY=y

+++ b/configs/ae350_rv64_spl_defconfig
+CONFIG_TRACE=y
+CONFIG_TRACE_BUFFER_SIZE=0x01000000
+CONFIG_TRACE_CALL_DEPTH_LIMIT=15
+CONFIG_CMD_TRACE=y
+CONFIG_TIMER_EARLY=y

//////////////////////////////////////////////// case 1 ///////////////////////////////////////////////////
ae350_rv64_defconfig with FTRACE=1, kernel booting is ok //////////////////////////////////////////////// case 1 ///////////////////////////////////////////////////
make FTRACE=1 ae350_rv64_defconfig
make FTRACE=1 /////////////////////////////////////////////////////////////////////////////////////////////////////////////// U-Boot 2021.01-rc2-00139-gb3d3d69-dirty (Nov 25 2020 - 11:14:28 +0800)

DRAM:  1 GiB
trace: enabled
Flash: 64 MiB
MMC:   mmc at f0e00000: 0
Loading Environment from SPIFlash... SF: Detected mx25u1635e with page
size 256 Bytes, erase size 4 KiB, total 2 MiB
OK
In:    serial at f0300000
Out:   serial at f0300000
Err:   serial at f0300000
Net:   no alias for ethernet0
Warning: mac at e0100000 (eth0) using random MAC address - de:fa:3e:1b:11:42
eth0: mac at e0100000
Hit any key to stop autoboot:  0

RISC-V # fatload mmc 0:1 0x20000000 ae350_rv64_smp_4_no_fd_coherent.dtb 6455 bytes read in 67 ms (93.8 KiB/s)
RISC-V # fatload mmc 0:1 0x00600000 bootm_ae350_rv64_smp_bbl.bin 22518836 bytes read in 11915 ms (1.8 MiB/s)
RISC-V # bootm 0x00600000 - 0x20000000
## Booting kernel from Legacy Image at 00600000 ...
Image Name:
Image Type: RISC-V Linux Kernel Image (uncompressed)
Data Size: 22518772 Bytes = 21.5 MiB
Load Address: 00000000
Entry Point: 00000000
Verifying Checksum ... OK
## Flattened Device Tree blob at 20000000
Booting using the fdt blob at 0x20000000
Loading Kernel Image
Loading Device Tree to 000000001effb000, end 000000001efff936 ... OK

Starting kernel ...(fake run for tracing)

Starting kernel ...

OF: fdt: Ignoring memory range 0x0 - 0x200000
Linux version 4.17.0-00253-g49136e10bcb2 (sqa at atcsqa07) (gcc version 7.3.0 (2019-04-06_nds64le-linux-glibc-v5_experimental)) #1 SMP PREEMPT Sat Apr 6 23:41:49 CST 2019
bootconsole [early0] enabled
Initial ramdisk at: 0x (ptrval) (13665712 bytes)
Zone ranges:
DMA32 [mem 0x0000000000200000-0x000000003fffffff]
Normal empty
Movable zone start for each node
Early memory node ranges
...
...

//////////////////////////////////////////////// case 2 ///////////////////////////////////////////////////
ae350_rv64_spl_defconfig with FTRACE=1, kernel booting fail //////////////////////////////////////////////// case 2 ///////////////////////////////////////////////////
make FTRACE=1 ae350_rv64_spl_defconfig
make FTRACE=1 /////////////////////////////////////////////////////////////////////////////////////////////////////////////// U-Boot SPL 2020.10-rc2-00175-gfa50824 (Sep 15 2020 - 19:26:29 +0800)
Trying to boot from MMC1
U-Boot SPL 2021.01-rc2-00139-gb3d3d69-dirty (Nov 25 2020 - 13:48:05 +0800)
Trying to boot from RAM
U-Boot 2021.01-rc2-00139-gb3d3d69-dirty (Nov 25 2020 - 13:48:05 +0800)

DRAM:  1 GiB
trace: enabled
Flash: 64 MiB
MMC:   mmc at f0e00000: 0
Loading Environment from SPIFlash... SF: Detected mx25u1635e with page
size 256 Bytes, erase size 4 KiB, total 2 MiB
OK
In:    serial at f0300000
Out:   serial at f0300000
Err:   serial at f0300000
Net:   no alias for ethernet0
Warning: mac at e0100000 (eth0) using random MAC address - 36:86:da:0f:8e:8d
eth0: mac at e0100000
Hit any key to stop autoboot:  0

27689996 bytes read in 15024 ms (1.8 MiB/s)
6435 bytes read in 25 ms (251 KiB/s)
## Booting kernel from Legacy Image at 00600000 ...
Image Name:
Image Type: RISC-V Linux Kernel Image (uncompressed)
Data Size: 27689932 Bytes = 26.4 MiB
Load Address: 00200000
Entry Point: 00200000
Verifying Checksum ... OK
## Flattened Device Tree blob at 20000000
Booting using the fdt blob at 0x20000000
Loading Kernel Image
Loading Device Tree to 000000001effb000, end 000000001efff922 ... OK

Starting kernel ...(fake run for tracing)

Starting kernel ...

(hang here)

//////////////////////////////////////////////// case 3 ///////////////////////////////////////////////////
ae350_rv64_spl_defconfig without FTRACE=1, kernel booting ok //////////////////////////////////////////////// case 2 ///////////////////////////////////////////////////
make ae350_rv64_spl_defconfig
make ///////////////////////////////////////////////////////////////////////////////////////////////////////////////

U-Boot SPL 2021.01-rc2-00139-gb3d3d69-dirty (Nov 25 2020 - 11:25:30 +0800) Trying to boot from RAM
U-Boot 2021.01-rc2-00139-gb3d3d69-dirty (Nov 25 2020 - 11:25:30 +0800)

DRAM:  1 GiB
trace: enabled
Flash: 64 MiB
MMC:   mmc at f0e00000: 0
Loading Environment from SPIFlash... SF: Detected mx25u1635e with page
size 256 Bytes, erase size 4 KiB, total 2 MiB
OK
In:    serial at f0300000
Out:   serial at f0300000
Err:   serial at f0300000
Net:   no alias for ethernet0
Warning: mac at e0100000 (eth0) using random MAC address - 6a:1a:a0:e2:cc:d8
eth0: mac at e0100000
Hit any key to stop autoboot:  0

27689996 bytes read in 9333 ms (2.8 MiB/s)
6435 bytes read in 15 ms (418.9 KiB/s)
## Booting kernel from Legacy Image at 00600000 ...
Image Name:
Image Type: RISC-V Linux Kernel Image (uncompressed)
Data Size: 27689932 Bytes = 26.4 MiB
Load Address: 00200000
Entry Point: 00200000
Verifying Checksum ... OK
## Flattened Device Tree blob at 20000000
Booting using the fdt blob at 0x20000000
Loading Kernel Image
Loading Device Tree to 000000001effb000, end 000000001efff922 ... OK

Starting kernel ...(fake run for tracing)

Starting kernel ...

[    0.000000] OF: fdt: Ignoring memory range 0x0 - 0x200000
[    0.000000] Linux version 5.4.0-00137-g5601822 (rick at atcsqa06) (gcc
version 7.4.0 (2020-07-29_nds64le-linux-glibc-v5d-532904c2315e)) #56
SMP PREEMPT Thu Nov 19 18:06:46 CST 2020
[    0.000000] initrd not found or empty - disabling initrd
[    0.000000] Zone ranges:
[    0.000000]   DMA32    [mem 0x0000000000200000-0x000000003fffffff]
[    0.000000]   Normal   empty
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges

...
////////////////////////////////////////////////// end //////////////////////////////////////////////////////////

Thanks,
Rick

Quoted 143 lines
Quoted 143 lines

Thanks,
Rick

Quoted 46 lines
Quoted 46 lines

Thanks,
Rick

Quoted 41 lines
drivers/timer/andes_plmt_timer.c +18 -1
index cec86718c7..74b795c97a 100644
@@ -17,11 +17,30 @@
 /* mtime register */
 #define MTIME_REG(base)                        ((ulong)(base))
 
-static u64 andes_plmt_get_count(struct udevice *dev)
+static u64 notrace andes_plmt_get_count(struct udevice *dev)
 {
        return readq((void __iomem *)MTIME_REG(dev->priv));  }
 
+#if CONFIG_IS_ENABLED(RISCV_MMODE)
+/**
+ * timer_early_get_rate() - Get the timer rate before driver model
+*/ unsigned long notrace timer_early_get_rate(void) {
+       return RISCV_MMODE_TIMER_FREQ; }
+
+/**
+ * timer_early_get_count() - Get the timer count before driver
+model
+ *
+ */
+u64 notrace timer_early_get_count(void) {
+       return readq((void __iomem
+*)MTIME_REG(RISCV_MMODE_TIMERBASE));
+}
+#endif
+
 static const struct timer_ops andes_plmt_ops = {
        .get_count = andes_plmt_get_count,  }; diff --git

a/drivers/timer/riscv_timer.c b/drivers/timer/riscv_timer.c index 21ae184057..a0f71ca897 100644

drivers/timer/riscv_timer.c +0 -0
@@ -16,7 +16,7 @@
 #include <timer.h>
 #include <asm/csr.h>
 
Quoted 6 lines
Quoted 6 lines

drivers/timer/riscv_timer.c static u64 riscv_timer_get_count(struct udevice

Quoted 6 lines
drivers/timer/riscv_timer.c +1 -1
-static u64 riscv_timer_get_count(struct udevice *dev)
+static u64 notrace riscv_timer_get_count(struct udevice *dev)
 {
        __maybe_unused u32 hi, lo;
 
@@ -31,6 +31,25 @@ static u64 riscv_timer_get_count(struct udevice

*dev)

Quoted 86 lines
Quoted 86 lines
Quoted 86 lines
drivers/timer/riscv_timer.c +14 -0
        return ((u64)hi << 32) | lo;  }
 
+#if CONFIG_IS_ENABLED(RISCV_SMODE)
+/**
+ * timer_early_get_rate() - Get the timer rate before driver model
+*/ unsigned long notrace timer_early_get_rate(void) {
+       return RISCV_SMODE_TIMER_FREQ; }
+
+/**
+ * timer_early_get_count() - Get the timer count before driver
+model
+ *
+ */
+u64 notrace timer_early_get_count(void) {
+       return riscv_timer_get_count(NULL); } #endif
+
 static int riscv_timer_probe(struct udevice *dev)  {
        struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
drivers/timer/sifive_clint_timer.c +18 -1
index 00ce0f08d6..9ae05a0e7e 100644
@@ -14,11 +14,30 @@
 /* mtime register */
 #define MTIME_REG(base)                        ((ulong)(base) + 0xbff8)
 
-static u64 sifive_clint_get_count(struct udevice *dev)
+static u64 notrace sifive_clint_get_count(struct udevice *dev)
 {
        return readq((void __iomem *)MTIME_REG(dev->priv));  }
 
+#if CONFIG_IS_ENABLED(RISCV_MMODE)
+/**
+ * timer_early_get_rate() - Get the timer rate before driver model
+*/ unsigned long notrace timer_early_get_rate(void) {
+       return RISCV_MMODE_TIMER_FREQ; }
+
+/**
+ * timer_early_get_count() - Get the timer count before driver
+model
+ *
+ */
+u64 notrace timer_early_get_count(void) {
+       return readq((void __iomem
+*)MTIME_REG(RISCV_MMODE_TIMERBASE));
+}
+#endif
+
 static const struct timer_ops sifive_clint_ops = {
        .get_count = sifive_clint_get_count,  }; diff --git

a/include/configs/ax25-ae350.h b/include/configs/ax25-ae350.h index b2606e794d..bd9c371f83 100644

include/configs/ax25-ae350.h +5 -0
@@ -17,6 +17,11 @@
 #endif
 #endif
 
+#define RISCV_MMODE_TIMERBASE           0xe6000000
+#define RISCV_MMODE_TIMER_FREQ          60000000
+
+#define RISCV_SMODE_TIMER_FREQ          60000000
+
 /*
  * CPU and Board Configuration Options
  */
(quoted diff) +0 -0

b/include/configs/sifive-fu540.h index c1c79db147..0d69d1c548 100644

include/configs/sifive-fu540.h +5 -1
@@ -36,6 +36,11 @@
 
 #define CONFIG_STANDALONE_LOAD_ADDR    0x80200000
 
+#define RISCV_MMODE_TIMERBASE          0x2000000
+#define RISCV_MMODE_TIMER_FREQ         1000000
+
+#define RISCV_SMODE_TIMER_FREQ         1000000
+
 /* Environment options */
 
 #ifndef CONFIG_SPL_BUILD
--

2.17.1

#7 lore raw

PATCH 1/1 riscv: timer: Add support for an early timer

Hi Rick,

Quoted 1 line

-----Original Message-----

[...]

Quoted 132 lines
Quoted 11 lines
Quoted 9 lines

After add CONFIG_TIMER_EARLY, U-Boot boots ok.
But When I try to booting kernel with FTRACE=1, following are the test stats:

ae350_rv64_spl_defconfig without FTRACE=1, kernel booting is ok. ae350_rv64_spl_defconfig with FTRACE=1, kernel booting fail. ae350_rv64_defconfig with FTRACE=1, kernel booting is ok

The failure case seems not reasonable.
Any suggestions ?

Strange, Can you please tell me which steps you follow and also send some

debug logs if possible.

Quoted 1 line

Following are the configurations, steps and debug logs:

+++ b/configs/ae350_rv64_defconfig
q+CONFIG_TRACE=y

(quoted diff) +10 -0
+CONFIG_TRACE_BUFFER_SIZE=0x01000000
+CONFIG_TRACE_CALL_DEPTH_LIMIT=15
+CONFIG_CMD_TRACE=y
+CONFIG_TIMER_EARLY=y
 
+++ b/configs/ae350_rv64_spl_defconfig
+CONFIG_TRACE=y
+CONFIG_TRACE_BUFFER_SIZE=0x01000000
+CONFIG_TRACE_CALL_DEPTH_LIMIT=15
+CONFIG_CMD_TRACE=y
+CONFIG_TIMER_EARLY=y

//////////////////////////////////////////////// case 1 ///////////////////////////////////////////////////
ae350_rv64_defconfig with FTRACE=1, kernel booting is ok //////////////////////////////////////////////// case 1 ///////////////////////////////////////////////////
make FTRACE=1 ae350_rv64_defconfig
make FTRACE=1 ////////////////////////////////////////////////////////////////////////////////////// /////////////////////////
U-Boot 2021.01-rc2-00139-gb3d3d69-dirty (Nov 25 2020 - 11:14:28 +0800)

DRAM:  1 GiB
trace: enabled
Flash: 64 MiB
MMC:   mmc at f0e00000: 0
Loading Environment from SPIFlash... SF: Detected mx25u1635e with page
size 256 Bytes, erase size 4 KiB, total 2 MiB
OK
In:    serial at f0300000
Out:   serial at f0300000
Err:   serial at f0300000
Net:   no alias for ethernet0
Warning: mac at e0100000 (eth0) using random MAC address - de:fa:3e:1b:11:42
eth0: mac at e0100000
Hit any key to stop autoboot:  0

RISC-V # fatload mmc 0:1 0x20000000 ae350_rv64_smp_4_no_fd_coherent.dtb 6455 bytes read in 67 ms (93.8 KiB/s)
RISC-V # fatload mmc 0:1 0x00600000 bootm_ae350_rv64_smp_bbl.bin 22518836 bytes read in 11915 ms (1.8 MiB/s)
RISC-V # bootm 0x00600000 - 0x20000000
## Booting kernel from Legacy Image at 00600000 ...
Image Name:
Image Type: RISC-V Linux Kernel Image (uncompressed)
Data Size: 22518772 Bytes = 21.5 MiB
Load Address: 00000000
Entry Point: 00000000
Verifying Checksum ... OK
## Flattened Device Tree blob at 20000000
Booting using the fdt blob at 0x20000000
Loading Kernel Image
Loading Device Tree to 000000001effb000, end 000000001efff936 ... OK

Starting kernel ...(fake run for tracing)

Starting kernel ...

OF: fdt: Ignoring memory range 0x0 - 0x200000
Linux version 4.17.0-00253-g49136e10bcb2 (sqa at atcsqa07) (gcc version 7.3.0 (2019-04-06_nds64le-linux-glibc-v5_experimental)) #1 SMP PREEMPT Sat Apr 6 23:41:49 CST 2019
bootconsole [early0] enabled
Initial ramdisk at: 0x (ptrval) (13665712 bytes)
Zone ranges:
DMA32 [mem 0x0000000000200000-0x000000003fffffff]
Normal empty
Movable zone start for each node
Early memory node ranges
...
...

//////////////////////////////////////////////// case 2 /////////////////////////////////////////////////// ae350_rv64_spl_defconfig with FTRACE=1, kernel booting fail //////////////////////////////////////////////// case 2 ///////////////////////////////////////////////////
make FTRACE=1 ae350_rv64_spl_defconfig
make FTRACE=1 ////////////////////////////////////////////////////////////////////////////////////// /////////////////////////
U-Boot SPL 2020.10-rc2-00175-gfa50824 (Sep 15 2020 - 19:26:29 +0800) Trying to boot from MMC1
U-Boot SPL 2021.01-rc2-00139-gb3d3d69-dirty (Nov 25 2020 - 13:48:05 +0800) Trying to boot from RAM
U-Boot 2021.01-rc2-00139-gb3d3d69-dirty (Nov 25 2020 - 13:48:05 +0800)

DRAM:  1 GiB
trace: enabled
Flash: 64 MiB
MMC:   mmc at f0e00000: 0
Loading Environment from SPIFlash... SF: Detected mx25u1635e with page
size 256 Bytes, erase size 4 KiB, total 2 MiB
OK
In:    serial at f0300000
Out:   serial at f0300000
Err:   serial at f0300000
Net:   no alias for ethernet0
Warning: mac at e0100000 (eth0) using random MAC address - 36:86:da:0f:8e:8d
eth0: mac at e0100000
Hit any key to stop autoboot:  0

27689996 bytes read in 15024 ms (1.8 MiB/s)
6435 bytes read in 25 ms (251 KiB/s)
## Booting kernel from Legacy Image at 00600000 ...
Image Name:
Image Type: RISC-V Linux Kernel Image (uncompressed)
Data Size: 27689932 Bytes = 26.4 MiB
Load Address: 00200000
Entry Point: 00200000
Verifying Checksum ... OK
## Flattened Device Tree blob at 20000000
Booting using the fdt blob at 0x20000000
Loading Kernel Image
Loading Device Tree to 000000001effb000, end 000000001efff922 ... OK

Quoted 5 lines

Starting kernel ...(fake run for tracing)

Starting kernel ...

(hang here)

Thanks for the logs.

From logs, I can't find where it got stuck. Can you please use gdb to see where it got stuck ?

Meanwhile I will give it a try on HiFive Unleashed board.

Quoted 206 lines

//////////////////////////////////////////////// case 3 /////////////////////////////////////////////////// ae350_rv64_spl_defconfig without FTRACE=1, kernel booting ok //////////////////////////////////////////////// case 2 ///////////////////////////////////////////////////
make ae350_rv64_spl_defconfig
make ////////////////////////////////////////////////////////////////////////////////////// /////////////////////////

U-Boot SPL 2021.01-rc2-00139-gb3d3d69-dirty (Nov 25 2020 - 11:25:30 +0800) Trying to boot from RAM
U-Boot 2021.01-rc2-00139-gb3d3d69-dirty (Nov 25 2020 - 11:25:30 +0800)

DRAM:  1 GiB
trace: enabled
Flash: 64 MiB
MMC:   mmc at f0e00000: 0
Loading Environment from SPIFlash... SF: Detected mx25u1635e with page
size 256 Bytes, erase size 4 KiB, total 2 MiB
OK
In:    serial at f0300000
Out:   serial at f0300000
Err:   serial at f0300000
Net:   no alias for ethernet0
Warning: mac at e0100000 (eth0) using random MAC address - 6a:1a:a0:e2:cc:d8
eth0: mac at e0100000
Hit any key to stop autoboot:  0

27689996 bytes read in 9333 ms (2.8 MiB/s)
6435 bytes read in 15 ms (418.9 KiB/s)
## Booting kernel from Legacy Image at 00600000 ...
Image Name:
Image Type: RISC-V Linux Kernel Image (uncompressed)
Data Size: 27689932 Bytes = 26.4 MiB
Load Address: 00200000
Entry Point: 00200000
Verifying Checksum ... OK
## Flattened Device Tree blob at 20000000
Booting using the fdt blob at 0x20000000
Loading Kernel Image
Loading Device Tree to 000000001effb000, end 000000001efff922 ... OK

Starting kernel ...(fake run for tracing)

Starting kernel ...

[    0.000000] OF: fdt: Ignoring memory range 0x0 - 0x200000
[    0.000000] Linux version 5.4.0-00137-g5601822 (rick at atcsqa06) (gcc
version 7.4.0 (2020-07-29_nds64le-linux-glibc-v5d-532904c2315e)) #56
SMP PREEMPT Thu Nov 19 18:06:46 CST 2020
[    0.000000] initrd not found or empty - disabling initrd
[    0.000000] Zone ranges:
[    0.000000]   DMA32    [mem 0x0000000000200000-0x000000003fffffff]
[    0.000000]   Normal   empty
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges

...
////////////////////////////////////////////////// end //////////////////////////////////////////////////////////

Thanks,
Rick

Quoted 143 lines
Quoted 143 lines

Thanks,
Rick

Quoted 46 lines
Quoted 46 lines

Thanks,
Rick

Quoted 41 lines
drivers/timer/andes_plmt_timer.c +18 -1
index cec86718c7..74b795c97a 100644
@@ -17,11 +17,30 @@
 /* mtime register */
 #define MTIME_REG(base)                        ((ulong)(base))
 
-static u64 andes_plmt_get_count(struct udevice *dev)
+static u64 notrace andes_plmt_get_count(struct udevice *dev)
 {
        return readq((void __iomem *)MTIME_REG(dev->priv));  }
 
+#if CONFIG_IS_ENABLED(RISCV_MMODE)
+/**
+ * timer_early_get_rate() - Get the timer rate before driver model
+*/ unsigned long notrace timer_early_get_rate(void) {
+       return RISCV_MMODE_TIMER_FREQ; }
+
+/**
+ * timer_early_get_count() - Get the timer count before driver
+model
+ *
+ */
+u64 notrace timer_early_get_count(void) {
+       return readq((void __iomem
+*)MTIME_REG(RISCV_MMODE_TIMERBASE));
+}
+#endif
+
 static const struct timer_ops andes_plmt_ops = {
        .get_count = andes_plmt_get_count,  }; diff --git

a/drivers/timer/riscv_timer.c b/drivers/timer/riscv_timer.c index 21ae184057..a0f71ca897 100644

drivers/timer/riscv_timer.c +0 -0
@@ -16,7 +16,7 @@
 #include <timer.h>
 #include <asm/csr.h>
 
Quoted 6 lines
Quoted 6 lines

drivers/timer/riscv_timer.c static u64 riscv_timer_get_count(struct udevice

Quoted 6 lines
drivers/timer/riscv_timer.c +1 -1
-static u64 riscv_timer_get_count(struct udevice *dev)
+static u64 notrace riscv_timer_get_count(struct udevice *dev)
 {
        __maybe_unused u32 hi, lo;
 
@@ -31,6 +31,25 @@ static u64 riscv_timer_get_count(struct udevice

*dev)

Quoted 86 lines
Quoted 86 lines
Quoted 86 lines
drivers/timer/riscv_timer.c +14 -0
        return ((u64)hi << 32) | lo;  }
 
+#if CONFIG_IS_ENABLED(RISCV_SMODE)
+/**
+ * timer_early_get_rate() - Get the timer rate before driver model
+*/ unsigned long notrace timer_early_get_rate(void) {
+       return RISCV_SMODE_TIMER_FREQ; }
+
+/**
+ * timer_early_get_count() - Get the timer count before driver
+model
+ *
+ */
+u64 notrace timer_early_get_count(void) {
+       return riscv_timer_get_count(NULL); } #endif
+
 static int riscv_timer_probe(struct udevice *dev)  {
        struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
drivers/timer/sifive_clint_timer.c +18 -1
index 00ce0f08d6..9ae05a0e7e 100644
@@ -14,11 +14,30 @@
 /* mtime register */
 #define MTIME_REG(base)                        ((ulong)(base) + 0xbff8)
 
-static u64 sifive_clint_get_count(struct udevice *dev)
+static u64 notrace sifive_clint_get_count(struct udevice *dev)
 {
        return readq((void __iomem *)MTIME_REG(dev->priv));  }
 
+#if CONFIG_IS_ENABLED(RISCV_MMODE)
+/**
+ * timer_early_get_rate() - Get the timer rate before driver model
+*/ unsigned long notrace timer_early_get_rate(void) {
+       return RISCV_MMODE_TIMER_FREQ; }
+
+/**
+ * timer_early_get_count() - Get the timer count before driver
+model
+ *
+ */
+u64 notrace timer_early_get_count(void) {
+       return readq((void __iomem
+*)MTIME_REG(RISCV_MMODE_TIMERBASE));
+}
+#endif
+
 static const struct timer_ops sifive_clint_ops = {
        .get_count = sifive_clint_get_count,  }; diff --git

a/include/configs/ax25-ae350.h b/include/configs/ax25-ae350.h index b2606e794d..bd9c371f83 100644

include/configs/ax25-ae350.h +5 -0
@@ -17,6 +17,11 @@
 #endif
 #endif
 
+#define RISCV_MMODE_TIMERBASE           0xe6000000
+#define RISCV_MMODE_TIMER_FREQ          60000000
+
+#define RISCV_SMODE_TIMER_FREQ          60000000
+
 /*
  * CPU and Board Configuration Options
  */
(quoted diff) +0 -0

b/include/configs/sifive-fu540.h index c1c79db147..0d69d1c548 100644

include/configs/sifive-fu540.h +5 -1
@@ -36,6 +36,11 @@
 
 #define CONFIG_STANDALONE_LOAD_ADDR    0x80200000
 
+#define RISCV_MMODE_TIMERBASE          0x2000000
+#define RISCV_MMODE_TIMER_FREQ         1000000
+
+#define RISCV_SMODE_TIMER_FREQ         1000000
+
 /* Environment options */
 
 #ifndef CONFIG_SPL_BUILD
--

2.17.1

#8 lore raw

PATCH 1/1 riscv: timer: Add support for an early timer

Hi Rick,

[...]

Quoted 25 lines
Quoted 25 lines

Following are the configurations, steps and debug logs:

+++ b/configs/ae350_rv64_defconfig
q+CONFIG_TRACE=y

(quoted diff) +10 -0
+CONFIG_TRACE_BUFFER_SIZE=0x01000000
+CONFIG_TRACE_CALL_DEPTH_LIMIT=15
+CONFIG_CMD_TRACE=y
+CONFIG_TIMER_EARLY=y
 
+++ b/configs/ae350_rv64_spl_defconfig
+CONFIG_TRACE=y
+CONFIG_TRACE_BUFFER_SIZE=0x01000000
+CONFIG_TRACE_CALL_DEPTH_LIMIT=15
+CONFIG_CMD_TRACE=y
+CONFIG_TIMER_EARLY=y

//////////////////////////////////////////////// case 1 /////////////////////////////////////////////////// ae350_rv64_defconfig with FTRACE=1, kernel booting is ok //////////////////////////////////////////////// case 1 ///////////////////////////////////////////////////
make FTRACE=1 ae350_rv64_defconfig
make FTRACE=1 ///////////////////////////////////////////////////////////////////////

[...]

Quoted 10 lines
Quoted 10 lines

//////////////////////////////////////////////// case 2 /////////////////////////////////////////////////// ae350_rv64_spl_defconfig with FTRACE=1, kernel booting fail //////////////////////////////////////////////// case 2 ///////////////////////////////////////////////////
make FTRACE=1 ae350_rv64_spl_defconfig
make FTRACE=1 /////////////////////////////////////////////////////////////////////// ///////////////
/////////////////////////

[...]

Quoted 4 lines
Quoted 1 line

(hang here)

Thanks for the logs.

From logs, I can't find where it got stuck. Can you please use gdb to see where it

Quoted 3 lines

got stuck ?

Meanwhile I will give it a try on HiFive Unleashed board.

On HiFive Unleashed it works fine with tracing.

U-Boot 2021.01-rc2-00049-gb2a38d1d0f (Dec 01 2020 - 15:04:41 +0530)

CPU:   rv64imafdc
Model: SiFive HiFive Unleashed A00
DRAM:  8 GiB
trace: enabled
MMC:   spi at 10050000:mmc at 0: 0
Loading Environment from SPIFlash... SF: Detected is25wp256 with page size 256 Bytes, erase size 4 KiB, total 32 MiB
*** Warning - bad CRC, using default environment
In:    serial at 10010000
Out:   serial at 10010000
Err:   serial at 10010000
Net:   eth0: ethernet at 10090000
Hit any key to stop autoboot:  0

=>
=> trace stats
178,750 function sites
25,359,991 function calls
1 untracked function calls
1,278,927 traced function calls (24358307 dropped due to overflow)
19 maximum observed call depth
15 call depth limit
25,238,922 calls not traced due to depth
=> fatload mmc 0:3 0x86000000 hifive-unleashed-a00.dtb
7199 bytes read in 27 ms (259.8 KiB/s)
=> fatload mmc 0:3 0x84000000 uImage
21421212 bytes read in 19496 ms (1 MiB/s)
=> bootm 0x84000000 - 0x86000000
## Booting kernel from Legacy Image at 84000000 ...

   Image Name:   Linux
   Image Type:   RISC-V Linux Kernel Image (uncompressed)
   Data Size:    21421148 Bytes = 20.4 MiB

Load Address: 80200000
Entry Point: 80200000
Verifying Checksum ... OK
## Flattened Device Tree blob at 86000000
Booting using the fdt blob at 0x86000000
Loading Kernel Image
Using Device Tree in place at 0000000086000000, end 0000000086004c1e
Starting kernel ...(fake run for tracing)
Starting kernel ...

[    0.000000] OF: fdt: Ignoring memory range 0x80000000 - 0x80200000
[    0.000000] Linux version 5.8.0-rc3-16077-g9ebcfadb0610-dirty (pragneshp at sachinj2-OptiPlex-7010) (riscv64-unknown-linux-gnu-gcc (crosstool-NG 1.24.0.37-3f461da) 9.2.0, GNU ld (crosstool-NG 1.24.0.37-3f461da) 2.32) #34 SMP Tue Jul 21 15:56:29 IST 2020
[    0.000000] initrd not found or empty - disabling initrd
[    0.000000] Zone ranges:
[    0.000000]   DMA32    [mem 0x0000000080200000-0x00000000ffffffff]
[    0.000000]   Normal   [mem 0x0000000100000000-0x000000027fffffff]
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x0000000080200000-0x000000027fffffff]
[    0.000000] Initmem setup node 0 [mem 0x0000000080200000-0x000000027fffffff]

....
Welcome to Buildroot
buildroot login: root
Password:

Quoted 10 lines
Quoted 10 lines

//////////////////////////////////////////////// case 3 /////////////////////////////////////////////////// ae350_rv64_spl_defconfig without FTRACE=1, kernel booting ok //////////////////////////////////////////////// case 2 ///////////////////////////////////////////////////
make ae350_rv64_spl_defconfig
make ///////////////////////////////////////////////////////////////////////

#9 lore raw

PATCH 1/1 riscv: timer: Add support for an early timer

Hi Pragnesh

Quoted 101 lines

Hi Rick,

[...]

Quoted 25 lines
Quoted 25 lines

Following are the configurations, steps and debug logs:

+++ b/configs/ae350_rv64_defconfig
q+CONFIG_TRACE=y

(quoted diff) +10 -0
+CONFIG_TRACE_BUFFER_SIZE=0x01000000
+CONFIG_TRACE_CALL_DEPTH_LIMIT=15
+CONFIG_CMD_TRACE=y
+CONFIG_TIMER_EARLY=y
 
+++ b/configs/ae350_rv64_spl_defconfig
+CONFIG_TRACE=y
+CONFIG_TRACE_BUFFER_SIZE=0x01000000
+CONFIG_TRACE_CALL_DEPTH_LIMIT=15
+CONFIG_CMD_TRACE=y
+CONFIG_TIMER_EARLY=y

//////////////////////////////////////////////// case 1 /////////////////////////////////////////////////// ae350_rv64_defconfig with FTRACE=1, kernel booting is ok //////////////////////////////////////////////// case 1 ///////////////////////////////////////////////////
make FTRACE=1 ae350_rv64_defconfig
make FTRACE=1 ///////////////////////////////////////////////////////////////////////

[...]

Quoted 10 lines
Quoted 10 lines

//////////////////////////////////////////////// case 2 /////////////////////////////////////////////////// ae350_rv64_spl_defconfig with FTRACE=1, kernel booting fail //////////////////////////////////////////////// case 2 ///////////////////////////////////////////////////
make FTRACE=1 ae350_rv64_spl_defconfig
make FTRACE=1 /////////////////////////////////////////////////////////////////////// ///////////////
/////////////////////////

[...]

Quoted 8 lines
Quoted 1 line

(hang here)

Thanks for the logs.

From logs, I can't find where it got stuck. Can you please use gdb to see where it got stuck ?

Meanwhile I will give it a try on HiFive Unleashed board.

On HiFive Unleashed it works fine with tracing.

U-Boot 2021.01-rc2-00049-gb2a38d1d0f (Dec 01 2020 - 15:04:41 +0530)

CPU:   rv64imafdc
Model: SiFive HiFive Unleashed A00
DRAM:  8 GiB
trace: enabled
MMC:   spi at 10050000:mmc at 0: 0
Loading Environment from SPIFlash... SF: Detected is25wp256 with page size 256 Bytes, erase size 4 KiB, total 32 MiB
*** Warning - bad CRC, using default environment
In:    serial at 10010000
Out:   serial at 10010000
Err:   serial at 10010000
Net:   eth0: ethernet at 10090000
Hit any key to stop autoboot:  0

=>
=> trace stats
178,750 function sites
25,359,991 function calls
1 untracked function calls
1,278,927 traced function calls (24358307 dropped due to overflow)
19 maximum observed call depth
15 call depth limit
25,238,922 calls not traced due to depth
=> fatload mmc 0:3 0x86000000 hifive-unleashed-a00.dtb
7199 bytes read in 27 ms (259.8 KiB/s)
=> fatload mmc 0:3 0x84000000 uImage
21421212 bytes read in 19496 ms (1 MiB/s)
=> bootm 0x84000000 - 0x86000000
## Booting kernel from Legacy Image at 84000000 ...

   Image Name:   Linux
   Image Type:   RISC-V Linux Kernel Image (uncompressed)
   Data Size:    21421148 Bytes = 20.4 MiB

Load Address: 80200000
Entry Point: 80200000
Verifying Checksum ... OK
## Flattened Device Tree blob at 86000000
Booting using the fdt blob at 0x86000000
Loading Kernel Image
Using Device Tree in place at 0000000086000000, end 0000000086004c1e
Starting kernel ...(fake run for tracing)
Starting kernel ...

[    0.000000] OF: fdt: Ignoring memory range 0x80000000 - 0x80200000
[    0.000000] Linux version 5.8.0-rc3-16077-g9ebcfadb0610-dirty (pragneshp at sachinj2-OptiPlex-7010) (riscv64-unknown-linux-gnu-gcc (crosstool-NG 1.24.0.37-3f461da) 9.2.0, GNU ld (crosstool-NG 1.24.0.37-3f461da) 2.32) #34 SMP Tue Jul 21 15:56:29 IST 2020
[    0.000000] initrd not found or empty - disabling initrd
[    0.000000] Zone ranges:
[    0.000000]   DMA32    [mem 0x0000000080200000-0x00000000ffffffff]
[    0.000000]   Normal   [mem 0x0000000100000000-0x000000027fffffff]
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x0000000080200000-0x000000027fffffff]
[    0.000000] Initmem setup node 0 [mem 0x0000000080200000-0x000000027fffffff]
Quoted 5 lines

....
Welcome to Buildroot
buildroot login: root
Password:

Please check about the CI failure item Job #95.56
https://travis-ci.org/github/rickchen36/u-boot-riscv/jobs/748298543

Thanks,
Rick

#10 lore raw

PATCH 1/1 riscv: timer: Add support for an early timer

Hi Rick,

Quoted 125 lines

-----Original Message-----
From: Rick Chen <[email protected]>
Sent: 10 December 2020 08:36
To: Pragnesh Patel <[email protected]>
Cc: Simon Glass <[email protected]>; U-Boot Mailing List <u- boot at lists.denx.de>; Atish Patra <[email protected]>; Bin Meng <[email protected]>; Paul Walmsley ( Sifive) <[email protected]>; Anup Patel <[email protected]>; Sagar Kadam <[email protected]>; Palmer Dabbelt <[email protected]>; rick <[email protected]>; Alan Kao <[email protected]>; Leo Liang <[email protected]>
Subject: Re: [PATCH] riscv: timer: Add support for an early timer

[External Email] Do not click links or attachments unless you recognize the sender and know the content is safe

Hi Pragnesh

Quoted 92 lines

Hi Rick,

[...]

Quoted 26 lines
Quoted 26 lines

Following are the configurations, steps and debug logs:

+++ b/configs/ae350_rv64_defconfig
q+CONFIG_TRACE=y

(quoted diff) +10 -0
+CONFIG_TRACE_BUFFER_SIZE=0x01000000
+CONFIG_TRACE_CALL_DEPTH_LIMIT=15
+CONFIG_CMD_TRACE=y
+CONFIG_TIMER_EARLY=y
 
+++ b/configs/ae350_rv64_spl_defconfig
+CONFIG_TRACE=y
+CONFIG_TRACE_BUFFER_SIZE=0x01000000
+CONFIG_TRACE_CALL_DEPTH_LIMIT=15
+CONFIG_CMD_TRACE=y
+CONFIG_TIMER_EARLY=y

//////////////////////////////////////////////// case 1 /////////////////////////////////////////////////// ae350_rv64_defconfig with FTRACE=1, kernel booting is ok //////////////////////////////////////////////// case 1 ///////////////////////////////////////////////////
make FTRACE=1 ae350_rv64_defconfig
make FTRACE=1 //////////////////////////////////////////////////////////////////// ///

[...]

Quoted 10 lines
Quoted 10 lines

//////////////////////////////////////////////// case 2 /////////////////////////////////////////////////// ae350_rv64_spl_defconfig with FTRACE=1, kernel booting fail //////////////////////////////////////////////// case 2 ///////////////////////////////////////////////////
make FTRACE=1 ae350_rv64_spl_defconfig make FTRACE=1 //////////////////////////////////////////////////////////////////// ///
///////////////
/////////////////////////

[...]

Quoted 8 lines
Quoted 1 line

(hang here)

Thanks for the logs.

From logs, I can't find where it got stuck. Can you please use gdb to see where it got stuck ?

Meanwhile I will give it a try on HiFive Unleashed board.

On HiFive Unleashed it works fine with tracing.

U-Boot 2021.01-rc2-00049-gb2a38d1d0f (Dec 01 2020 - 15:04:41 +0530)

CPU:   rv64imafdc
Model: SiFive HiFive Unleashed A00
DRAM:  8 GiB
trace: enabled
MMC:   spi at 10050000:mmc at 0: 0
Loading Environment from SPIFlash... SF: Detected is25wp256 with page
size 256 Bytes, erase size 4 KiB, total 32 MiB
*** Warning - bad CRC, using default environment
In:    serial at 10010000
Out:   serial at 10010000
Err:   serial at 10010000
Net:   eth0: ethernet at 10090000
Hit any key to stop autoboot:  0
=>
=> trace stats
        178,750 function sites
     25,359,991 function calls
              1 untracked function calls
      1,278,927 traced function calls (24358307 dropped due to overflow)
             19 maximum observed call depth
             15 call depth limit
     25,238,922 calls not traced due to depth => fatload mmc 0:3

0x86000000 hifive-unleashed-a00.dtb
7199 bytes read in 27 ms (259.8 KiB/s) => fatload mmc 0:3 0x84000000 uImage
21421212 bytes read in 19496 ms (1 MiB/s) => bootm 0x84000000 - 0x86000000 ## Booting kernel from Legacy Image at 84000000 ...

   Image Name:   Linux
   Image Type:   RISC-V Linux Kernel Image (uncompressed)
   Data Size:    21421148 Bytes = 20.4 MiB

Load Address: 80200000
Entry Point: 80200000
Verifying Checksum ... OK
## Flattened Device Tree blob at 86000000
Booting using the fdt blob at 0x86000000
Loading Kernel Image
Using Device Tree in place at 0000000086000000, end
0000000086004c1e Starting kernel ...(fake run for tracing) Starting kernel ...

Quoted 2 lines
[    0.000000] OF: fdt: Ignoring memory range 0x80000000 - 0x80200000
[    0.000000] Linux version 5.8.0-rc3-16077-g9ebcfadb0610-dirty

(pragneshp at sachinj2-OptiPlex-7010) (riscv64-unknown-linux-gnu-gcc (crosstool- NG 1.24.0.37-3f461da) 9.2.0, GNU ld (crosstool-NG 1.24.0.37-3f461da) 2.32) #34 SMP Tue Jul 21 15:56:29 IST 2020

Quoted 8 lines
[    0.000000] initrd not found or empty - disabling initrd
[    0.000000] Zone ranges:
[    0.000000]   DMA32    [mem 0x0000000080200000-0x00000000ffffffff]
[    0.000000]   Normal   [mem 0x0000000100000000-0x000000027fffffff]
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x0000000080200000-0x000000027fffffff]
[    0.000000] Initmem setup node 0 [mem 0x0000000080200000-

0x000000027fffffff]

Quoted 8 lines
Quoted 5 lines

....
Welcome to Buildroot
buildroot login: root
Password:

Please check about the CI failure item Job #95.56
https://travis-ci.org/github/rickchen36/u-boot-riscv/jobs/748298543

This is due to 'RISCV_MMODE_TIMER_FREQ' undeclared

I will update "include/configs/qemu-riscv.h" in v2 as below,

include/configs/qemu-riscv.h +5 -0
@@ -29,6 +29,11 @@
 
 #define CONFIG_STANDALONE_LOAD_ADDR    0x80200000
 
+#define RISCV_MMODE_TIMERBASE          0x2000000
+#define RISCV_MMODE_TIMER_FREQ         1000000
+
+#define RISCV_SMODE_TIMER_FREQ         1000000
+
 
 
Quoted 3 lines

Thanks,
Rick

#11 lore raw

PATCH 1/1 riscv: timer: Add support for an early timer

In reply to Rick Chen

Hi Rick,
[....]

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

After add CONFIG_TIMER_EARLY, U-Boot boots ok.
But When I try to booting kernel with FTRACE=1, following are the test stats:

ae350_rv64_spl_defconfig without FTRACE=1, kernel booting is ok. ae350_rv64_spl_defconfig with FTRACE=1, kernel booting fail. ae350_rv64_defconfig with FTRACE=1, kernel booting is ok

The failure case seems not reasonable.
Any suggestions ?

Can you please enable debug logs by adding below in ae350_rv64_spl_defconfig ?

CONFIG_LOG=y
CONFIG_LOG_MAX_LEVEL=9
CONFIG_LOG_DEFAULT_LEVEL=9
CONFIG_LOG_CONSOLE=y
CONFIG_SPL_LOG=y
CONFIG_SPL_LOG_MAX_LEVEL=9
CONFIG_SPL_LOG_CONSOLE=y

Quoted 334 lines
Quoted 2 lines

Strange, Can you please tell me which steps you follow and also send some

debug logs if possible.

Quoted 1 line

Following are the configurations, steps and debug logs:

+++ b/configs/ae350_rv64_defconfig
q+CONFIG_TRACE=y

(quoted diff) +10 -0
+CONFIG_TRACE_BUFFER_SIZE=0x01000000
+CONFIG_TRACE_CALL_DEPTH_LIMIT=15
+CONFIG_CMD_TRACE=y
+CONFIG_TIMER_EARLY=y
 
+++ b/configs/ae350_rv64_spl_defconfig
+CONFIG_TRACE=y
+CONFIG_TRACE_BUFFER_SIZE=0x01000000
+CONFIG_TRACE_CALL_DEPTH_LIMIT=15
+CONFIG_CMD_TRACE=y
+CONFIG_TIMER_EARLY=y

//////////////////////////////////////////////// case 1 ///////////////////////////////////////////////////
ae350_rv64_defconfig with FTRACE=1, kernel booting is ok //////////////////////////////////////////////// case 1 ///////////////////////////////////////////////////
make FTRACE=1 ae350_rv64_defconfig
make FTRACE=1 ////////////////////////////////////////////////////////////////////////////////////// /////////////////////////
U-Boot 2021.01-rc2-00139-gb3d3d69-dirty (Nov 25 2020 - 11:14:28 +0800)

DRAM:  1 GiB
trace: enabled
Flash: 64 MiB
MMC:   mmc at f0e00000: 0
Loading Environment from SPIFlash... SF: Detected mx25u1635e with page
size 256 Bytes, erase size 4 KiB, total 2 MiB
OK
In:    serial at f0300000
Out:   serial at f0300000
Err:   serial at f0300000
Net:   no alias for ethernet0
Warning: mac at e0100000 (eth0) using random MAC address - de:fa:3e:1b:11:42
eth0: mac at e0100000
Hit any key to stop autoboot:  0

RISC-V # fatload mmc 0:1 0x20000000 ae350_rv64_smp_4_no_fd_coherent.dtb 6455 bytes read in 67 ms (93.8 KiB/s)
RISC-V # fatload mmc 0:1 0x00600000 bootm_ae350_rv64_smp_bbl.bin 22518836 bytes read in 11915 ms (1.8 MiB/s)
RISC-V # bootm 0x00600000 - 0x20000000
## Booting kernel from Legacy Image at 00600000 ...
Image Name:
Image Type: RISC-V Linux Kernel Image (uncompressed)
Data Size: 22518772 Bytes = 21.5 MiB
Load Address: 00000000
Entry Point: 00000000
Verifying Checksum ... OK
## Flattened Device Tree blob at 20000000
Booting using the fdt blob at 0x20000000
Loading Kernel Image
Loading Device Tree to 000000001effb000, end 000000001efff936 ... OK

Starting kernel ...(fake run for tracing)

Starting kernel ...

OF: fdt: Ignoring memory range 0x0 - 0x200000
Linux version 4.17.0-00253-g49136e10bcb2 (sqa at atcsqa07) (gcc version 7.3.0 (2019-04-06_nds64le-linux-glibc-v5_experimental)) #1 SMP PREEMPT Sat Apr 6 23:41:49 CST 2019
bootconsole [early0] enabled
Initial ramdisk at: 0x (ptrval) (13665712 bytes)
Zone ranges:
DMA32 [mem 0x0000000000200000-0x000000003fffffff]
Normal empty
Movable zone start for each node
Early memory node ranges
...
...

//////////////////////////////////////////////// case 2 /////////////////////////////////////////////////// ae350_rv64_spl_defconfig with FTRACE=1, kernel booting fail //////////////////////////////////////////////// case 2 ///////////////////////////////////////////////////
make FTRACE=1 ae350_rv64_spl_defconfig
make FTRACE=1 ////////////////////////////////////////////////////////////////////////////////////// /////////////////////////
U-Boot SPL 2020.10-rc2-00175-gfa50824 (Sep 15 2020 - 19:26:29 +0800) Trying to boot from MMC1
U-Boot SPL 2021.01-rc2-00139-gb3d3d69-dirty (Nov 25 2020 - 13:48:05 +0800) Trying to boot from RAM
U-Boot 2021.01-rc2-00139-gb3d3d69-dirty (Nov 25 2020 - 13:48:05 +0800)

DRAM:  1 GiB
trace: enabled
Flash: 64 MiB
MMC:   mmc at f0e00000: 0
Loading Environment from SPIFlash... SF: Detected mx25u1635e with page
size 256 Bytes, erase size 4 KiB, total 2 MiB
OK
In:    serial at f0300000
Out:   serial at f0300000
Err:   serial at f0300000
Net:   no alias for ethernet0
Warning: mac at e0100000 (eth0) using random MAC address - 36:86:da:0f:8e:8d
eth0: mac at e0100000
Hit any key to stop autoboot:  0

27689996 bytes read in 15024 ms (1.8 MiB/s)
6435 bytes read in 25 ms (251 KiB/s)
## Booting kernel from Legacy Image at 00600000 ...
Image Name:
Image Type: RISC-V Linux Kernel Image (uncompressed)
Data Size: 27689932 Bytes = 26.4 MiB
Load Address: 00200000
Entry Point: 00200000
Verifying Checksum ... OK
## Flattened Device Tree blob at 20000000
Booting using the fdt blob at 0x20000000
Loading Kernel Image
Loading Device Tree to 000000001effb000, end 000000001efff922 ... OK

Starting kernel ...(fake run for tracing)

Starting kernel ...

(hang here)

//////////////////////////////////////////////// case 3 /////////////////////////////////////////////////// ae350_rv64_spl_defconfig without FTRACE=1, kernel booting ok //////////////////////////////////////////////// case 2 ///////////////////////////////////////////////////
make ae350_rv64_spl_defconfig
make ////////////////////////////////////////////////////////////////////////////////////// /////////////////////////

U-Boot SPL 2021.01-rc2-00139-gb3d3d69-dirty (Nov 25 2020 - 11:25:30 +0800) Trying to boot from RAM
U-Boot 2021.01-rc2-00139-gb3d3d69-dirty (Nov 25 2020 - 11:25:30 +0800)

DRAM:  1 GiB
trace: enabled
Flash: 64 MiB
MMC:   mmc at f0e00000: 0
Loading Environment from SPIFlash... SF: Detected mx25u1635e with page
size 256 Bytes, erase size 4 KiB, total 2 MiB
OK
In:    serial at f0300000
Out:   serial at f0300000
Err:   serial at f0300000
Net:   no alias for ethernet0
Warning: mac at e0100000 (eth0) using random MAC address - 6a:1a:a0:e2:cc:d8
eth0: mac at e0100000
Hit any key to stop autoboot:  0

27689996 bytes read in 9333 ms (2.8 MiB/s)
6435 bytes read in 15 ms (418.9 KiB/s)
## Booting kernel from Legacy Image at 00600000 ...
Image Name:
Image Type: RISC-V Linux Kernel Image (uncompressed)
Data Size: 27689932 Bytes = 26.4 MiB
Load Address: 00200000
Entry Point: 00200000
Verifying Checksum ... OK
## Flattened Device Tree blob at 20000000
Booting using the fdt blob at 0x20000000
Loading Kernel Image
Loading Device Tree to 000000001effb000, end 000000001efff922 ... OK

Starting kernel ...(fake run for tracing)

Starting kernel ...

[    0.000000] OF: fdt: Ignoring memory range 0x0 - 0x200000
[    0.000000] Linux version 5.4.0-00137-g5601822 (rick at atcsqa06) (gcc
version 7.4.0 (2020-07-29_nds64le-linux-glibc-v5d-532904c2315e)) #56
SMP PREEMPT Thu Nov 19 18:06:46 CST 2020
[    0.000000] initrd not found or empty - disabling initrd
[    0.000000] Zone ranges:
[    0.000000]   DMA32    [mem 0x0000000000200000-0x000000003fffffff]
[    0.000000]   Normal   empty
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges

...
////////////////////////////////////////////////// end //////////////////////////////////////////////////////////

Thanks,
Rick

Quoted 143 lines
Quoted 143 lines

Thanks,
Rick

Quoted 46 lines
Quoted 46 lines

Thanks,
Rick

Quoted 41 lines
drivers/timer/andes_plmt_timer.c +18 -1
index cec86718c7..74b795c97a 100644
@@ -17,11 +17,30 @@
 /* mtime register */
 #define MTIME_REG(base)                        ((ulong)(base))
 
-static u64 andes_plmt_get_count(struct udevice *dev)
+static u64 notrace andes_plmt_get_count(struct udevice *dev)
 {
        return readq((void __iomem *)MTIME_REG(dev->priv));  }
 
+#if CONFIG_IS_ENABLED(RISCV_MMODE)
+/**
+ * timer_early_get_rate() - Get the timer rate before driver model
+*/ unsigned long notrace timer_early_get_rate(void) {
+       return RISCV_MMODE_TIMER_FREQ; }
+
+/**
+ * timer_early_get_count() - Get the timer count before driver
+model
+ *
+ */
+u64 notrace timer_early_get_count(void) {
+       return readq((void __iomem
+*)MTIME_REG(RISCV_MMODE_TIMERBASE));
+}
+#endif
+
 static const struct timer_ops andes_plmt_ops = {
        .get_count = andes_plmt_get_count,  }; diff --git

a/drivers/timer/riscv_timer.c b/drivers/timer/riscv_timer.c index 21ae184057..a0f71ca897 100644

drivers/timer/riscv_timer.c +0 -0
@@ -16,7 +16,7 @@
 #include <timer.h>
 #include <asm/csr.h>
 
Quoted 6 lines
Quoted 6 lines

drivers/timer/riscv_timer.c static u64 riscv_timer_get_count(struct udevice

Quoted 6 lines
drivers/timer/riscv_timer.c +1 -1
-static u64 riscv_timer_get_count(struct udevice *dev)
+static u64 notrace riscv_timer_get_count(struct udevice *dev)
 {
        __maybe_unused u32 hi, lo;
 
@@ -31,6 +31,25 @@ static u64 riscv_timer_get_count(struct udevice

*dev)

Quoted 86 lines
Quoted 86 lines
Quoted 86 lines
drivers/timer/riscv_timer.c +14 -0
        return ((u64)hi << 32) | lo;  }
 
+#if CONFIG_IS_ENABLED(RISCV_SMODE)
+/**
+ * timer_early_get_rate() - Get the timer rate before driver model
+*/ unsigned long notrace timer_early_get_rate(void) {
+       return RISCV_SMODE_TIMER_FREQ; }
+
+/**
+ * timer_early_get_count() - Get the timer count before driver
+model
+ *
+ */
+u64 notrace timer_early_get_count(void) {
+       return riscv_timer_get_count(NULL); } #endif
+
 static int riscv_timer_probe(struct udevice *dev)  {
        struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
drivers/timer/sifive_clint_timer.c +18 -1
index 00ce0f08d6..9ae05a0e7e 100644
@@ -14,11 +14,30 @@
 /* mtime register */
 #define MTIME_REG(base)                        ((ulong)(base) + 0xbff8)
 
-static u64 sifive_clint_get_count(struct udevice *dev)
+static u64 notrace sifive_clint_get_count(struct udevice *dev)
 {
        return readq((void __iomem *)MTIME_REG(dev->priv));  }
 
+#if CONFIG_IS_ENABLED(RISCV_MMODE)
+/**
+ * timer_early_get_rate() - Get the timer rate before driver model
+*/ unsigned long notrace timer_early_get_rate(void) {
+       return RISCV_MMODE_TIMER_FREQ; }
+
+/**
+ * timer_early_get_count() - Get the timer count before driver
+model
+ *
+ */
+u64 notrace timer_early_get_count(void) {
+       return readq((void __iomem
+*)MTIME_REG(RISCV_MMODE_TIMERBASE));
+}
+#endif
+
 static const struct timer_ops sifive_clint_ops = {
        .get_count = sifive_clint_get_count,  }; diff --git

a/include/configs/ax25-ae350.h b/include/configs/ax25-ae350.h index b2606e794d..bd9c371f83 100644

include/configs/ax25-ae350.h +5 -0
@@ -17,6 +17,11 @@
 #endif
 #endif
 
+#define RISCV_MMODE_TIMERBASE           0xe6000000
+#define RISCV_MMODE_TIMER_FREQ          60000000
+
+#define RISCV_SMODE_TIMER_FREQ          60000000
+
 /*
  * CPU and Board Configuration Options
  */
(quoted diff) +0 -0

b/include/configs/sifive-fu540.h index c1c79db147..0d69d1c548 100644

include/configs/sifive-fu540.h +5 -1
@@ -36,6 +36,11 @@
 
 #define CONFIG_STANDALONE_LOAD_ADDR    0x80200000
 
+#define RISCV_MMODE_TIMERBASE          0x2000000
+#define RISCV_MMODE_TIMER_FREQ         1000000
+
+#define RISCV_SMODE_TIMER_FREQ         1000000
+
 /* Environment options */
 
 #ifndef CONFIG_SPL_BUILD
--

2.17.1