Module Name: src
Committed By: skrll
Date: Thu Jan 18 07:41:50 UTC 2024
Modified Files:
src/sys/arch/riscv/riscv: clock_machdep.c riscv_machdep.c
Log Message:
Provide a working delay(9)
To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/riscv/riscv/clock_machdep.c
cvs rdiff -u -r1.35 -r1.36 src/sys/arch/riscv/riscv/riscv_machdep.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/riscv/riscv/clock_machdep.c
diff -u src/sys/arch/riscv/riscv/clock_machdep.c:1.6 src/sys/arch/riscv/riscv/clock_machdep.c:1.7
--- src/sys/arch/riscv/riscv/clock_machdep.c:1.6 Wed Jul 26 06:13:44 2023
+++ src/sys/arch/riscv/riscv/clock_machdep.c Thu Jan 18 07:41:50 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: clock_machdep.c,v 1.6 2023/07/26 06:13:44 skrll Exp $ */
+/* $NetBSD: clock_machdep.c,v 1.7 2024/01/18 07:41:50 skrll Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
#include <sys/cdefs.h>
-__RCSID("$NetBSD: clock_machdep.c,v 1.6 2023/07/26 06:13:44 skrll Exp $");
+__RCSID("$NetBSD: clock_machdep.c,v 1.7 2024/01/18 07:41:50 skrll Exp $");
#include <sys/param.h>
#include <sys/cpu.h>
@@ -47,6 +47,7 @@ static void (*_riscv_timer_init)(void) =
static uint32_t timer_frequency;
static uint32_t timer_ticks_per_hz;
+static uint32_t timer_ticks_per_usec;
static u_int
timer_get_timecount(struct timecounter *tc)
@@ -67,6 +68,7 @@ riscv_timer_frequency_set(uint32_t freq)
{
timer_frequency = freq;
timer_ticks_per_hz = freq / hz;
+ timer_ticks_per_usec = freq / 1000000;
}
uint32_t
@@ -143,3 +145,14 @@ void
setstatclockrate(int newhz)
{
}
+
+void
+delay(unsigned long us)
+{
+ const uint64_t ticks = (uint64_t)us * timer_ticks_per_usec;
+ const uint64_t finish = csr_time_read() + ticks;
+
+ while (csr_time_read() < finish) {
+ /* spin, baby spin */
+ }
+}
Index: src/sys/arch/riscv/riscv/riscv_machdep.c
diff -u src/sys/arch/riscv/riscv/riscv_machdep.c:1.35 src/sys/arch/riscv/riscv/riscv_machdep.c:1.36
--- src/sys/arch/riscv/riscv/riscv_machdep.c:1.35 Fri Dec 22 08:41:59 2023
+++ src/sys/arch/riscv/riscv/riscv_machdep.c Thu Jan 18 07:41:50 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: riscv_machdep.c,v 1.35 2023/12/22 08:41:59 skrll Exp $ */
+/* $NetBSD: riscv_machdep.c,v 1.36 2024/01/18 07:41:50 skrll Exp $ */
/*-
* Copyright (c) 2014, 2019, 2022 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
#include "opt_riscv_debug.h"
#include <sys/cdefs.h>
-__RCSID("$NetBSD: riscv_machdep.c,v 1.35 2023/12/22 08:41:59 skrll Exp $");
+__RCSID("$NetBSD: riscv_machdep.c,v 1.36 2024/01/18 07:41:50 skrll Exp $");
#include <sys/param.h>
@@ -136,18 +136,6 @@ SYSCTL_SETUP(sysctl_machdep_setup, "sysc
CTL_MACHDEP, CTL_EOL);
}
-void
-delay(unsigned long us)
-{
- const uint32_t cycles_per_us = curcpu()->ci_data.cpu_cc_freq / 1000000;
- const uint64_t cycles = (uint64_t)us * cycles_per_us;
- const uint64_t finish = csr_cycle_read() + cycles;
-
- while (csr_cycle_read() < finish) {
- /* spin, baby spin */
- }
-}
-
#ifdef MODULAR
/*
* Push any modules loaded by the boot loader.