From nobody Fri Jan 10 19:18:33 2025 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4YVBJp0czHz5kNft; Fri, 10 Jan 2025 19:18:34 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YVBJn2MxTz4Mh1; Fri, 10 Jan 2025 19:18:33 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1736536713; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=rucQ0uJlwGOe1X5z+FnJOfn/E62jk1aXGt+7PMkYtE4=; b=dyl9/Vxh3HHrRYLb+pDlvxV4FgsSxWiMj1iKXBEcdHpBL+zFstOv9DTLZblLwyDeOCP6Nr wsQ16Rz0U28R8PoJozt5OYFUBgmH4CpikH6H8l66jIXmcXWvNiiG4glRPafOT833xPFSba RoaVh7cKd9u68vp+k2UHr5pVfQOAvbIJgs9H5lEGOkZWIdO0PqCSBiZmoAml86bawTbS3J tWy8MT+sZoCXaOqhtdA6AwIEb5fsI0IWxVYalg5Adka5Yw6hTYgXdd9ElL9GdcV2PbDpRi 9YEcAqNSskceDbGk1d7byMBfHmyRG5BmiW8ceXI0bEWbTWqe0Es86s3jaN1Eiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1736536713; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=rucQ0uJlwGOe1X5z+FnJOfn/E62jk1aXGt+7PMkYtE4=; b=BmZgMuyeqlXmREyeFMlp8K4fuwYfaAH9lR1UvgaSY1v9PZFl85nSYFwq4kva08d1zAtmwq SIJqF6ySvRGbN9PR2iOW3xuVi/dY7C7mIdp1DMl5QTlUV6h+VrCd1nS1PXx6i+vOhayR5k M8wiNZXpV0qUxGXKErGxRrwacuwFVvewDx6ZC6ESExuk1s3nX7XeaSxPVHymZ80f2DtwgG P/5z+POqiU9o5q4CHL2A79H2iFfLG2lnR8Sl3uyHSG7l3yMhajpZGIqZkK9YDdWTnkz4dg TtozDAv5ym1EoeKZGZQcr5eHuH+9Z0T9UuqR+TSDRHdpOGtLz7GdWLzX+8UO5Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1736536713; a=rsa-sha256; cv=none; b=EgIV+ax9XDpfyuLVEC6TXzGzhh074RepH22OC8R9Xo9TeZW3CQGkOGqfxwYyrukFTKtGyO JHLJjEbOMGnlz8ZlprRS+ecye4hkf/uB3GDG541bp8/QIyfE6HJEYWFnaN8MAo6XOnBHvH AOe1klQqCQv2Jg58e0+9cOJj9QoRAIjiUHY3l2pBaGtWX3x6DZ+h1P7Hp7HMoY7WWHyKWV zTGiv7nEVr552NdIuZ8R+w59JIffw7q7dT6kCJvA4MDsSKLxl88puf60GfhCP+akNx8i/G NT4N5bg2KbVbpmejrfYAFsQZhJmdspoUJRwtZIO79EIRbE8L/21u6wpe7iOPlQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4YVBJn1fKVz8qT; Fri, 10 Jan 2025 19:18:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 50AJIXlK026567; Fri, 10 Jan 2025 19:18:33 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 50AJIXUD026564; Fri, 10 Jan 2025 19:18:33 GMT (envelope-from git) Date: Fri, 10 Jan 2025 19:18:33 GMT Message-Id: <202501101918.50AJIXUD026564@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mitchell Horne Subject: git: def7999c2ccd - main - riscv: enable cpufreq_dt driver List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mhorne X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: def7999c2ccddc9a303a65c0bea22976e79d8613 Auto-Submitted: auto-generated The branch main has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=def7999c2ccddc9a303a65c0bea22976e79d8613 commit def7999c2ccddc9a303a65c0bea22976e79d8613 Author: Mitchell Horne AuthorDate: 2024-10-08 18:49:11 +0000 Commit: Mitchell Horne 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