|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH v2 1/3] xen/riscv: implement udelay()
udelay() is still a stub that hits BUG_ON(), so mdelay() can't be used
on RISC-V, for example to honour the delay in machine_restart().
Implement udelay() by busy-waiting on the time CSR, as Linux's RISC-V
__delay() does. Convert the delay to timer ticks once, multiplying
before dividing and rounding up so that short delays aren't cut to zero
ticks, then spin until that many ticks have passed.
cpu_khz is only set by preinit_xen_time(). Before that it is 0, and
udelay() returns without waiting.
Assisted-by: Claude
Signed-off-by: Anandu Padinhare <Anandu.Padinhare@xxxxxxxxxxxxxx>
---
Changes in v2:
- Reword the commit message and return early when cpu_khz is
0 (Baptiste).
xen/arch/riscv/Makefile | 1 +
xen/arch/riscv/delay.c | 21 +++++++++++++++++++++
xen/arch/riscv/stubs.c | 7 -------
3 files changed, 22 insertions(+), 7 deletions(-)
create mode 100644 xen/arch/riscv/delay.c
diff --git a/xen/arch/riscv/Makefile b/xen/arch/riscv/Makefile
index 665ec26933..a9aa7d1b2f 100644
--- a/xen/arch/riscv/Makefile
+++ b/xen/arch/riscv/Makefile
@@ -1,6 +1,7 @@
obj-y += aia.o
obj-y += aplic.o
obj-y += cpufeature.o
+obj-y += delay.o
obj-y += device.init.o
obj-y += domain.o
obj-y += domain-build.init.o
diff --git a/xen/arch/riscv/delay.c b/xen/arch/riscv/delay.c
new file mode 100644
index 0000000000..e6ba9b3a5a
--- /dev/null
+++ b/xen/arch/riscv/delay.c
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <xen/delay.h>
+#include <xen/macros.h>
+#include <xen/time.h>
+
+#include <asm/processor.h>
+
+void udelay(unsigned long usecs)
+{
+ cycles_t ticks, start;
+
+ if ( !cpu_khz )
+ return;
+
+ ticks = DIV_ROUND_UP((cycles_t)usecs * cpu_khz, 1000);
+ start = get_cycles();
+
+ while ( get_cycles() - start < ticks )
+ cpu_relax();
+}
diff --git a/xen/arch/riscv/stubs.c b/xen/arch/riscv/stubs.c
index 3a7953593d..98231e39cc 100644
--- a/xen/arch/riscv/stubs.c
+++ b/xen/arch/riscv/stubs.c
@@ -240,13 +240,6 @@ int guest_physmap_remove_page(struct domain *d, gfn_t gfn,
mfn_t mfn,
BUG_ON("unimplemented");
}
-/* delay.c */
-
-void udelay(unsigned long usecs)
-{
- BUG_ON("unimplemented");
-}
-
/* guest_access.h */
static inline unsigned long raw_clear_guest(void *to, unsigned int len)
--
2.53.0
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |