Skip to contentSkip to conversation

arch: arm: socfpga: timer_s10: Override udelay for secure section

PATCH In review [email protected] 2 participants 2 messages Jun 1, 2022 – Jun 16, 2022

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

PATCH 1/1 arch: arm: socfpga: timer_s10: Override udelay for secure section

From: Dinesh Maniyam <[email protected]>

Override __udelay() as 'always inlined' function so that PSCI code run in '__secure' section can call this delay function as well.

---
 arch/arm/mach-socfpga/timer_s10.c | 35 ++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)
arch/arm/mach-socfpga/timer_s10.c +34 -1
index 7d5598e1a3..33afc87749 100644
@@ -1,11 +1,12 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- * Copyright (C) 2017-2018 Intel Corporation <www.intel.com>
+ * Copyright (C) 2017-2022 Intel Corporation <www.intel.com>
  *
  */
 
 #include <common.h>
 #include <init.h>
+#include <div64.h>
 #include <asm/io.h>
 #include <asm/arch/timer.h>
 
@@ -26,3 +27,35 @@ int timer_init(void)
 #endif
 	return 0;
 }
+
+__always_inline u64 __get_time_stamp(void)
+{
+	u64 cntpct;
+
+	isb();
+	asm volatile("mrs %0, cntpct_el0" : "=r" (cntpct));
+
+	return cntpct;
+}
+
+__always_inline uint64_t __usec_to_tick(unsigned long usec)
+{
+	u64 tick = usec;
+	u64 cntfrq;
+
+	asm volatile("mrs %0, cntfrq_el0" : "=r" (cntfrq));
+	tick *= cntfrq;
+	do_div(tick, 1000000);
+
+	return tick;
+}
+
+__always_inline void __udelay(unsigned long usec)
+{
+	/* get current timestamp */
+	u64 tmp = __get_time_stamp() + __usec_to_tick(usec);
+
+	while (__get_time_stamp() < tmp + 1)	/* loop till event */
+		;
+}
+
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 81 lines

-----Original Message-----
From: Maniyam, Dinesh <[email protected]>
Sent: Wednesday, 1 June, 2022 3:55 PM
To: [email protected]
Cc: Vasut, Marek <[email protected]>; Simon Goldschmidt <[email protected]>; Chee, Tien Fong <[email protected]>; Hea, Kok Kiang <[email protected]>; Gan, Yau Wai <[email protected]>; Kho, Sin Hui <[email protected]>; Lokanathan, Raaj <[email protected]>; Maniyam, Dinesh <[email protected]>; Chee Hong Ang <[email protected]>
Subject: [PATCH] arch: arm: socfpga: timer_s10: Override udelay for secure section

From: Dinesh Maniyam <[email protected]>

Override __udelay() as 'always inlined' function so that PSCI code run in '__secure' section can call this delay function as well.

---
 arch/arm/mach-socfpga/timer_s10.c | 35
++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)
arch/arm/mach- renamed from arch/arm/mach-socfpga/timer_s10.c +0 -0

socfpga/timer_s10.c
index 7d5598e1a3..33afc87749 100644

arch/arm/mach-socfpga/timer_s10.c +31 -2
@@ -1,11 +1,12 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- * Copyright (C) 2017-2018 Intel Corporation <www.intel.com>
+ * Copyright (C) 2017-2022 Intel Corporation <www.intel.com>
  *
  */
 
 #include <common.h>
 #include <init.h>
+#include <div64.h>
 #include <asm/io.h>
 #include <asm/arch/timer.h>
 
@@ -26,3 +27,35 @@ int timer_init(void)
 #endif
 	return 0;
 }
+
+__always_inline u64 __get_time_stamp(void) {
+	u64 cntpct;
+
+	isb();
+	asm volatile("mrs %0, cntpct_el0" : "=r" (cntpct));
+
+	return cntpct;
+}
+
+__always_inline uint64_t __usec_to_tick(unsigned long usec) {
+	u64 tick = usec;
+	u64 cntfrq;
+
+	asm volatile("mrs %0, cntfrq_el0" : "=r" (cntfrq));
+	tick *= cntfrq;
+	do_div(tick, 1000000);
+
+	return tick;
+}
+
+__always_inline void __udelay(unsigned long usec) {
+	/* get current timestamp */
+	u64 tmp = __get_time_stamp() + __usec_to_tick(usec);
+
+	while (__get_time_stamp() < tmp + 1)	/* loop till event */
+		;
+}
+
--
Quoted 1 line

2.25.1

Regards
Tien Fong