Date: Wed, 27 Mar 2019 16:26:03 +0000 (UTC) From: Ruslan Bukin <br@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r345581 - head/sys/riscv/riscv Message-ID: <201903271626.x2RGQ3e7076110@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: br Date: Wed Mar 27 16:26:03 2019 New Revision: 345581 URL: https://svnweb.freebsd.org/changeset/base/345581 Log: Grab timer frequency from FDT. RISC-V timer has no dedicated DTS node and we have to get timer frequency from cpus node. Tested on Government Furnished Equipment (GFE) cores synthesized on Xilinx VCU118. Reviewed by: markj Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D19727 Modified: head/sys/riscv/riscv/timer.c Modified: head/sys/riscv/riscv/timer.c ============================================================================== --- head/sys/riscv/riscv/timer.c Wed Mar 27 16:19:02 2019 (r345580) +++ head/sys/riscv/riscv/timer.c Wed Mar 27 16:26:03 2019 (r345581) @@ -61,7 +61,10 @@ __FBSDID("$FreeBSD$"); #include <machine/trap.h> #include <machine/sbi.h> -#define DEFAULT_FREQ 10000000 +#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) @@ -157,6 +160,32 @@ riscv_timer_intr(void *arg) } static int +riscv_timer_get_timebase(device_t dev, uint32_t *freq) +{ + phandle_t node; + int len; + + node = OF_finddevice("/cpus"); + if (node == -1) { + if (bootverbose) + device_printf(dev, "Can't find cpus node.\n"); + return (ENXIO); + } + + len = OF_getproplen(node, "timebase-frequency"); + if (len != 4) { + if (bootverbose) + device_printf(dev, + "Can't find timebase-frequency property.\n"); + return (ENXIO); + } + + OF_getencprop(node, "timebase-frequency", freq, len); + + return (0); +} + +static int riscv_timer_probe(device_t dev) { @@ -176,10 +205,9 @@ riscv_timer_attach(device_t dev) return (ENXIO); if (device_get_unit(dev) != 0) - return ENXIO; + return (ENXIO); - sc->clkfreq = DEFAULT_FREQ; - if (sc->clkfreq == 0) { + if (riscv_timer_get_timebase(dev, &sc->clkfreq) != 0) { device_printf(dev, "No clock frequency specified\n"); return (ENXIO); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201903271626.x2RGQ3e7076110>