|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH 1/2] 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().
Busy-wait on the time CSR instead, 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, so the
tick count is 0 and udelay() returns without waiting. This is also why
the loop doesn't use get_s_time(): it divides by cpu_khz, which is a
division by zero before then.
Assisted-by: Claude
Signed-off-by: Anandu Padinhare <Anandu.Padinhare@xxxxxxxxxxxxxx>
---
xen/arch/riscv/Makefile | 1 +
xen/arch/riscv/delay.c | 17 +++++++++++++++++
xen/arch/riscv/stubs.c | 7 -------
3 files changed, 18 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..232fe02fbf
--- /dev/null
+++ b/xen/arch/riscv/delay.c
@@ -0,0 +1,17 @@
+/* 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)
+{
+ /* cpu_khz is 0 until preinit_xen_time(), so this doesn't wait then. */
+ cycles_t ticks = DIV_ROUND_UP((cycles_t)usecs * cpu_khz, 1000);
+ cycles_t 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 |