git: def7999c2ccd - main - riscv: enable cpufreq_dt driver
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 10 Jan 2025 19:18:33 UTC
The branch main has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=def7999c2ccddc9a303a65c0bea22976e79d8613 commit def7999c2ccddc9a303a65c0bea22976e79d8613 Author: Mitchell Horne <mhorne@FreeBSD.org> AuthorDate: 2024-10-08 18:49:11 +0000 Commit: Mitchell Horne <mhorne@FreeBSD.org> CommitDate: 2025-01-10 19:16:06 +0000 riscv: enable cpufreq_dt driver Implement the small amount of MD code required; copied from arm/arm64. One tweak is made to cpufreq_dt itself: if the opp-shared property is missing, but there is only one CPU, then we can still attach. This is relevant for the single-core Allwinner D1. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D48124 --- sys/conf/files.riscv | 1 + sys/dev/cpufreq/cpufreq_dt.c | 2 +- sys/riscv/conf/GENERIC | 3 +++ sys/riscv/include/pcpu.h | 3 ++- sys/riscv/riscv/machdep.c | 12 +++++++++++- 5 files changed, 18 insertions(+), 3 deletions(-) diff --git a/sys/conf/files.riscv b/sys/conf/files.riscv index 514c955181c3..36eea03f29a1 100644 --- a/sys/conf/files.riscv +++ b/sys/conf/files.riscv @@ -4,6 +4,7 @@ cddl/dev/dtrace/riscv/dtrace_subr.c optional dtrace compile-with "${DTRACE_C}" cddl/dev/dtrace/riscv/instr_size.c optional dtrace compile-with "${DTRACE_C}" cddl/dev/fbt/riscv/fbt_isa.c optional dtrace_fbt | dtraceall compile-with "${FBT_C}" crypto/des/des_enc.c optional netsmb +dev/cpufreq/cpufreq_dt.c optional cpufreq fdt dev/ofw/ofw_cpu.c optional fdt dev/ofw/ofw_pcib.c optional pci fdt dev/pci/pci_dw.c optional pci fdt diff --git a/sys/dev/cpufreq/cpufreq_dt.c b/sys/dev/cpufreq/cpufreq_dt.c index 929eebfe7dc5..e35a8ec73ef4 100644 --- a/sys/dev/cpufreq/cpufreq_dt.c +++ b/sys/dev/cpufreq/cpufreq_dt.c @@ -401,7 +401,7 @@ cpufreq_dt_oppv2_parse(struct cpufreq_dt_softc *sc, phandle_t node) if (opp_table == opp_xref) return (ENXIO); - if (!OF_hasprop(opp_table, "opp-shared")) { + if (!OF_hasprop(opp_table, "opp-shared") && mp_ncpus > 1) { device_printf(sc->dev, "Only opp-shared is supported\n"); return (ENXIO); } diff --git a/sys/riscv/conf/GENERIC b/sys/riscv/conf/GENERIC index 23d8a4e47eee..34426f167963 100644 --- a/sys/riscv/conf/GENERIC +++ b/sys/riscv/conf/GENERIC @@ -90,6 +90,9 @@ device syscon device syscon_power device riscv_syscon +# CPU frequency control +device cpufreq + # Bus drivers device pci diff --git a/sys/riscv/include/pcpu.h b/sys/riscv/include/pcpu.h index d00226defc2f..f11060496963 100644 --- a/sys/riscv/include/pcpu.h +++ b/sys/riscv/include/pcpu.h @@ -46,7 +46,8 @@ struct pmap *pc_curpmap; /* Currently active pmap */ \ uint32_t pc_pending_ipis; /* IPIs pending to this CPU */ \ uint32_t pc_hart; /* Hart ID */ \ - char __pad[56] /* Pad to factor of PAGE_SIZE */ + uint64_t pc_clock; \ + char __pad[48] /* Pad to factor of PAGE_SIZE */ #ifdef _KERNEL diff --git a/sys/riscv/riscv/machdep.c b/sys/riscv/riscv/machdep.c index c5da4832dd36..c0d4b7cc2726 100644 --- a/sys/riscv/riscv/machdep.c +++ b/sys/riscv/riscv/machdep.c @@ -219,8 +219,18 @@ cpu_flush_dcache(void *ptr, size_t len) int cpu_est_clockrate(int cpu_id, uint64_t *rate) { + struct pcpu *pc; - panic("cpu_est_clockrate"); + pc = pcpu_find(cpu_id); + if (pc == NULL || rate == NULL) + return (EINVAL); + + if (pc->pc_clock == 0) + return (EOPNOTSUPP); + + *rate = pc->pc_clock; + + return (0); } void