git: b6e6c534a893 - stable/13 - riscv timer: cleanup

From: Mitchell Horne <mhorne_at_FreeBSD.org>
Date: Mon, 04 Jul 2022 16:40:10 UTC
The branch stable/13 has been updated by mhorne:

URL: https://cgit.FreeBSD.org/src/commit/?id=b6e6c534a8932387e2cc597fe1f481edb0da3dbb

commit b6e6c534a8932387e2cc597fe1f481edb0da3dbb
Author:     Mitchell Horne <mhorne@FreeBSD.org>
AuthorDate: 2022-06-21 16:22:40 +0000
Commit:     Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2022-07-04 16:37:05 +0000

    riscv timer: cleanup
    
    - Prune unused definitions and includes
    - Slight renaming of callback functions to indicate their usage
    - Place vdso_fill_timehands callback logically in the file
    - Small style nits
    
    MFC after:      1 week
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D35460
    
    (cherry picked from commit 715276a08b08c1f30ee3313758a936a417939ef4)
---
 sys/riscv/riscv/timer.c | 58 +++++++++++++++++--------------------------------
 1 file changed, 20 insertions(+), 38 deletions(-)

diff --git a/sys/riscv/riscv/timer.c b/sys/riscv/riscv/timer.c
index 34bc7590e397..c852d3dbe0f1 100644
--- a/sys/riscv/riscv/timer.c
+++ b/sys/riscv/riscv/timer.c
@@ -46,52 +46,35 @@ __FBSDID("$FreeBSD$");
 #include <sys/bus.h>
 #include <sys/kernel.h>
 #include <sys/module.h>
-#include <sys/malloc.h>
-#include <sys/rman.h>
 #include <sys/timeet.h>
 #include <sys/timetc.h>
 #include <sys/vdso.h>
 #include <sys/watchdog.h>
 
-#include <sys/proc.h>
-
-#include <machine/bus.h>
-#include <machine/cpu.h>
 #include <machine/cpufunc.h>
 #include <machine/intr.h>
-#include <machine/asm.h>
-#include <machine/trap.h>
 #include <machine/sbi.h>
 
-#include <dev/fdt/fdt_common.h>
-#include <dev/ofw/ofw_bus.h>
-#include <dev/ofw/ofw_bus_subr.h>
 #include <dev/ofw/openfirm.h>
 
-#define	TIMER_COUNTS		0x00
-#define	TIMER_MTIMECMP(cpu)	(cpu * 8)
-
 struct riscv_timer_softc {
 	void			*ih;
 	uint32_t		clkfreq;
 	struct eventtimer	et;
 };
-
 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_tc_get_timecount;
+static timecounter_fill_vdso_timehands_t riscv_timer_tc_fill_vdso_timehands;
 
 static struct timecounter riscv_timer_timecount = {
 	.tc_name           = "RISC-V Timecounter",
-	.tc_get_timecount  = riscv_timer_get_timecount,
+	.tc_get_timecount  = riscv_timer_tc_get_timecount,
 	.tc_poll_pps       = NULL,
 	.tc_counter_mask   = ~0u,
 	.tc_frequency      = 0,
 	.tc_quality        = 1000,
-	.tc_fill_vdso_timehands = riscv_timer_fill_vdso_timehands,
+	.tc_fill_vdso_timehands = riscv_timer_tc_fill_vdso_timehands,
 };
 
 static inline uint64_t
@@ -111,8 +94,8 @@ get_counts(struct riscv_timer_softc *sc)
 	return (counts);
 }
 
-static unsigned
-riscv_timer_get_timecount(struct timecounter *tc)
+static u_int
+riscv_timer_tc_get_timecount(struct timecounter *tc)
 {
 	struct riscv_timer_softc *sc;
 
@@ -121,8 +104,17 @@ riscv_timer_get_timecount(struct timecounter *tc)
 	return (get_counts(sc));
 }
 
+static uint32_t
+riscv_timer_tc_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);
+}
+
 static int
-riscv_timer_start(struct eventtimer *et, sbintime_t first, sbintime_t period)
+riscv_timer_et_start(struct eventtimer *et, sbintime_t first, sbintime_t period)
 {
 	uint64_t counts;
 
@@ -135,11 +127,10 @@ riscv_timer_start(struct eventtimer *et, sbintime_t first, sbintime_t period)
 	}
 
 	return (EINVAL);
-
 }
 
 static int
-riscv_timer_stop(struct eventtimer *et)
+riscv_timer_et_stop(struct eventtimer *et)
 {
 
 	/* Disable timer interrupts. */
@@ -205,7 +196,7 @@ riscv_timer_attach(device_t dev)
 	int error;
 
 	sc = device_get_softc(dev);
-	if (riscv_timer_sc)
+	if (riscv_timer_sc != NULL)
 		return (ENXIO);
 
 	if (device_get_unit(dev) != 0)
@@ -237,8 +228,8 @@ riscv_timer_attach(device_t dev)
 	sc->et.et_frequency = sc->clkfreq;
 	sc->et.et_min_period = (0x00000002LLU << 32) / sc->et.et_frequency;
 	sc->et.et_max_period = (0xfffffffeLLU << 32) / sc->et.et_frequency;
-	sc->et.et_start = riscv_timer_start;
-	sc->et.et_stop = riscv_timer_stop;
+	sc->et.et_start = riscv_timer_et_start;
+	sc->et.et_stop = riscv_timer_et_stop;
 	sc->et.et_priv = sc;
 	et_register(&sc->et);
 
@@ -309,12 +300,3 @@ DELAY(int usec)
 	}
 	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);
-}