From nobody Fri Jan 10 19:18:30 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 4YVBJl2LXzz5kNsj; Fri, 10 Jan 2025 19:18:31 +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 4YVBJl00mkz4Mpy; Fri, 10 Jan 2025 19:18:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1736536711; 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=kEUXlwABnOGUVwn/5gUu9AsHtLZ69QPHrvHbF50AkxQ=; b=YDzju5eaBr9GX56ZgAEtb6perql/ImCP8jF+/xHOOIN3P9ZO1vPkF/nU5ql3PpQfhbAEDg Cf0+gCiBlIaiEnsKcqxsGifjMmdIEgFpexNlY6ym7LVJV89TtH74OFWtu+CCvi+Sahg5jN /ln4v6HaOghU3Igy9+6ZeWOTSvDqxGZ/6MP5m2Diox0HTRwSCpzAt27QXmKfPLJqndags9 vmByOpxRQWk/Oto+ddtbj/Ws7mBYMN0CWH0tYksKplzHV619L+jlBDP6WaCn8UrI1HqU0b TgAPOGW2p3Q8en5llp9/zeIiv86on7arF9rhRotmw4Hj8kjHq32NuUEgsQAFww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1736536711; 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=kEUXlwABnOGUVwn/5gUu9AsHtLZ69QPHrvHbF50AkxQ=; b=ajEwwYBE9ujwspjmO2DZPQ7Tpji+L997UHWO5KZ63Au02ioxGHM26ScVQVOdd+c1dtQFc+ 25LR0iOH3pdPZOd7b5QBaKVrZFufu1WCEmHR3cj/64GjalIf7PtgxMIF8hcJdUSKKQIEeA bcK+k0kLcJZ7/uOtZx9cIKAoq/lqJjum3Y0aDGP4ksVtUFqKOGNxGmmeTH3YxES9gMDR1c DAm7IRORJSzEmKXz+KOa8p9FIOzbROj5ddpVb1aEW+xTWFyYzc9mytlptIK45vDC+/ZzIo Z+wYAGqG695YKle19I4rMEiCrhj/Fy7KGfThx8EwbrlFT6jgOEKcyerVJOct/A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1736536711; a=rsa-sha256; cv=none; b=FoD+oMvS72MvfgLzF7jKGSMPmNJ1qZ/1RB5xf2hevJdoC4aKbjWgEDfX+h4ZJwtTwKrwBa mwdMRrKPHsKeyFfemoWGGOwRPZYBBR6DzrVkPpaJ8a4cLMKZaw21L2SEf8iliJxfdFZzAt jjUrzH4KG8pFgNhzIsp4lYHvgcJU5lmMUUvWfuuFqfGjQ7s03SBFhIPQlDBZwTVN9EAB5/ +TE3j1lH85MUzcmK4GeR/mw+0m7+3qA99RUXyhVEwsgHaHpPHEkNl6hggbYBSUdA/n4Cq6 m9Pb4zPQ9RjLhKY/4BirdjrbfBkgNVYkQSo64/m+p56AiVarmzECW+sG8hlTbA== 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 4YVBJk6TMDz8mx; Fri, 10 Jan 2025 19:18:30 +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 50AJIUi0026475; Fri, 10 Jan 2025 19:18:30 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 50AJIU6Y026472; Fri, 10 Jan 2025 19:18:30 GMT (envelope-from git) Date: Fri, 10 Jan 2025 19:18:30 GMT Message-Id: <202501101918.50AJIU6Y026472@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: 4ea0c3f04f42 - main - ofw_cpu: collapse some #ifdef code 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: 4ea0c3f04f42119dff92317c0e4cef52350ed9db Auto-Submitted: auto-generated The branch main has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=4ea0c3f04f42119dff92317c0e4cef52350ed9db commit 4ea0c3f04f42119dff92317c0e4cef52350ed9db Author: Mitchell Horne AuthorDate: 2025-01-10 18:46:43 +0000 Commit: Mitchell Horne CommitDate: 2025-01-10 18:55:03 +0000 ofw_cpu: collapse some #ifdef code Mainly, to avoid repeating the list of architectures, #define HAS_CLK. Further, split the clk code into a helper function, which is a stub in the !HAS_CLK case. This aids in overall legibility. While here, add one separating whitespace, again for legibility. Reviewed by: jhb Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D48149 --- sys/dev/ofw/ofw_cpu.c | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/sys/dev/ofw/ofw_cpu.c b/sys/dev/ofw/ofw_cpu.c index cbca8caee186..339716a946ff 100644 --- a/sys/dev/ofw/ofw_cpu.c +++ b/sys/dev/ofw/ofw_cpu.c @@ -44,6 +44,7 @@ #if defined(__arm__) || defined(__arm64__) || defined(__riscv) #include +#define HAS_CLK #endif static int ofw_cpulist_probe(device_t); @@ -198,6 +199,30 @@ ofw_cpu_probe(device_t dev) return (0); } +static int +get_freq_from_clk(device_t dev, struct ofw_cpu_softc *sc) +{ +#ifdef HAS_CLK + clk_t cpuclk; + uint64_t freq; + int rv; + + rv = clk_get_by_ofw_index(dev, 0, 0, &cpuclk); + if (rv == 0) { + rv = clk_get_freq(cpuclk, &freq); + if (rv != 0 && bootverbose) + device_printf(dev, + "Cannot get freq of property clocks\n"); + else + sc->sc_nominal_mhz = freq / 1000000; + } + + return (rv); +#else + return (ENODEV); +#endif +} + static int ofw_cpu_attach(device_t dev) { @@ -206,10 +231,6 @@ ofw_cpu_attach(device_t dev) phandle_t node; pcell_t cell; int rv; -#if defined(__arm__) || defined(__arm64__) || defined(__riscv) - clk_t cpuclk; - uint64_t freq; -#endif sc = device_get_softc(dev); psc = device_get_softc(device_get_parent(dev)); @@ -276,18 +297,7 @@ ofw_cpu_attach(device_t dev) sc->sc_cpu_pcpu = pcpu_find(device_get_unit(dev)); if (OF_getencprop(node, "clock-frequency", &cell, sizeof(cell)) < 0) { -#if defined(__arm__) || defined(__arm64__) || defined(__riscv) - rv = clk_get_by_ofw_index(dev, 0, 0, &cpuclk); - if (rv == 0) { - rv = clk_get_freq(cpuclk, &freq); - if (rv != 0 && bootverbose) - device_printf(dev, - "Cannot get freq of property clocks\n"); - else - sc->sc_nominal_mhz = freq / 1000000; - } else -#endif - { + if (get_freq_from_clk(dev, sc) != 0) { if (bootverbose) device_printf(dev, "missing 'clock-frequency' property\n"); @@ -298,6 +308,7 @@ ofw_cpu_attach(device_t dev) if (sc->sc_nominal_mhz != 0 && bootverbose) device_printf(dev, "Nominal frequency %dMhz\n", sc->sc_nominal_mhz); + bus_identify_children(dev); bus_attach_children(dev); return (0);