Changeset View
Changeset View
Standalone View
Standalone View
sys/riscv/riscv/timer.c
Show First 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | |||||
#include <sys/systm.h> | #include <sys/systm.h> | ||||
#include <sys/bus.h> | #include <sys/bus.h> | ||||
#include <sys/kernel.h> | #include <sys/kernel.h> | ||||
#include <sys/module.h> | #include <sys/module.h> | ||||
#include <sys/malloc.h> | #include <sys/malloc.h> | ||||
#include <sys/rman.h> | #include <sys/rman.h> | ||||
#include <sys/timeet.h> | #include <sys/timeet.h> | ||||
#include <sys/timetc.h> | #include <sys/timetc.h> | ||||
#include <sys/vdso.h> | |||||
#include <sys/watchdog.h> | #include <sys/watchdog.h> | ||||
#include <sys/proc.h> | #include <sys/proc.h> | ||||
#include <machine/bus.h> | #include <machine/bus.h> | ||||
#include <machine/cpu.h> | #include <machine/cpu.h> | ||||
#include <machine/cpufunc.h> | #include <machine/cpufunc.h> | ||||
#include <machine/intr.h> | #include <machine/intr.h> | ||||
Show All 12 Lines | |||||
struct riscv_timer_softc { | struct riscv_timer_softc { | ||||
void *ih; | void *ih; | ||||
uint32_t clkfreq; | uint32_t clkfreq; | ||||
struct eventtimer et; | struct eventtimer et; | ||||
}; | }; | ||||
static struct riscv_timer_softc *riscv_timer_sc = NULL; | static struct riscv_timer_softc *riscv_timer_sc = NULL; | ||||
static uint32_t riscv_timer_fill_vdso_timehands(struct vdso_timehands *vdso_th, | |||||
struct timecounter *tc); | |||||
static timecounter_get_t riscv_timer_get_timecount; | static timecounter_get_t riscv_timer_get_timecount; | ||||
static struct timecounter riscv_timer_timecount = { | static struct timecounter riscv_timer_timecount = { | ||||
.tc_name = "RISC-V Timecounter", | .tc_name = "RISC-V Timecounter", | ||||
.tc_get_timecount = riscv_timer_get_timecount, | .tc_get_timecount = riscv_timer_get_timecount, | ||||
.tc_poll_pps = NULL, | .tc_poll_pps = NULL, | ||||
.tc_counter_mask = ~0u, | .tc_counter_mask = ~0u, | ||||
.tc_frequency = 0, | .tc_frequency = 0, | ||||
.tc_quality = 1000, | .tc_quality = 1000, | ||||
.tc_fill_vdso_timehands = riscv_timer_fill_vdso_timehands, | |||||
}; | }; | ||||
static inline uint64_t | static inline uint64_t | ||||
get_cycles(void) | get_cycles(void) | ||||
{ | { | ||||
return (rdtime()); | return (rdtime()); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 197 Lines • ▼ Show 20 Lines | DELAY(int usec) | ||||
first = get_counts(riscv_timer_sc); | first = get_counts(riscv_timer_sc); | ||||
while (counts > 0) { | while (counts > 0) { | ||||
last = get_counts(riscv_timer_sc); | last = get_counts(riscv_timer_sc); | ||||
counts -= (int64_t)(last - first); | counts -= (int64_t)(last - first); | ||||
first = last; | first = last; | ||||
} | } | ||||
TSEXIT(); | TSEXIT(); | ||||
} | |||||
static uint32_t | |||||
riscv_timer_fill_vdso_timehands(struct vdso_timehands *vdso_th, | |||||
struct timecounter *tc) | |||||
{ | |||||
vdso_th->th_algo = VDSO_TH_ALGO_RISCV_RDTIME; | |||||
bzero(vdso_th->th_res, sizeof(vdso_th->th_res)); | |||||
return (1); | |||||
} | } |