From nobody Sat Sep 07 01:47:56 2024 X-Original-To: dev-commits-src-all@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 4X0wwD4CgZz5WSR3; Sat, 07 Sep 2024 01:47:56 +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 4X0wwD0vVRz4jw6; Sat, 7 Sep 2024 01:47:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1725673676; 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=d84Xq1UBbXZw3OzgFI9xFWYz/lOfAD1/7/T3lfIv5KQ=; b=ZRcx70qWT2KOoIA5qXedrEJ4uDcGZrrWD02OwCPyGKzhP9oiNTyI9qs7CEPkmPadleK9Uu /P4D4XG7/QrsmFVgWmeaGxIkfsazpL5r/qEXYhYdiGEkZKKwS1omdT6xLxMVTVeCW8U0gN Zmh1RLqOAcgXImeW/cEcOwhqbgsoSjmcIp0ltOI1dtj/MtVM3iLEE8vKo9IQeM6ODe1JeE rqBIz+4b84EHpAlfcKufyYwjb2XEFw9f8yyVz2UnbCPUQN/ZvAMzJ0+3ewEsCg6ZKsw2ty /qegYwD0mtvislHLtaQB3uhD3Z9bexMsMSlEQmB57CyYVLI+mYtqzt8ZtIyfSg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1725673676; a=rsa-sha256; cv=none; b=QYcfqv1j35wQ3vKyGWfgi/OS6kFb9jNba2ZdbcwPgihCKB9GgTTEFxN6IXNvkju8uNPFs6 NBlstgnPp2EvCI+gDdDgUbuj2dpWMghlt9Dm12ZW1KWYbYLuh7ODdSXJJp1Dqxl43TiccT E5Pm5U1dTs74HoqmpG/KlL1NiUX54Wil3HcTouwAiDqISDh8NOS6TQ5rieHFGmxCBjgQUY cGCwnQsVFkwf1HGqrZTB1GZ/znk0YyVIIND3SGik98w+nBtuY0+SDUbf8RVtjxozKup7Aw T+xobLg9j5t5vq4cptibDWC8AIQgEUn+9LpczRpXPVRrqJ5WNGtfIRkGaEJ3Uw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1725673676; 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=d84Xq1UBbXZw3OzgFI9xFWYz/lOfAD1/7/T3lfIv5KQ=; b=iFnROYUfjnnNa4PRfgjX48blE/7XN0yUXthkILDInzDarvtlXOEKAIDl8wDVS5OTQ+0M8X cZI0DHgTSoZxry/vQh+Vyt1JokRuIyFB5a12d41OLAKQSqLDlb9G9coa916RZPvF1yD1do uwlUJgubHm7r0YwXfCJ2evevH4z6CySaMuPeZ0vW1B9ue4C3FVRn1Ggy4HKrjot6ciSwuf wmT9yZSKxtMAFnSV41D0nyngXwKp1X4yWvQCfNcVO5wm1mwb3/ioZDS5q0DKRp+UbcXsCV Mt1sgGSfNEYpV4hQufPXMcj8kNOjw9r7FSh10nzkXYzoVwUgm80up7l2kzHJmQ== 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 4X0wwD0WhhzGJh; Sat, 7 Sep 2024 01:47:56 +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 4871ludW041535; Sat, 7 Sep 2024 01:47:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4871lu2G041532; Sat, 7 Sep 2024 01:47:56 GMT (envelope-from git) Date: Sat, 7 Sep 2024 01:47:56 GMT Message-Id: <202409070147.4871lu2G041532@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Jessica Clarke Subject: git: 601baffb0b54 - stable/14 - riscv: Create a newbus device for the SBI driver List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jrtc27 X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 601baffb0b54b8fe70ad1dd9fd923fe38d08337e Auto-Submitted: auto-generated The branch stable/14 has been updated by jrtc27: URL: https://cgit.FreeBSD.org/src/commit/?id=601baffb0b54b8fe70ad1dd9fd923fe38d08337e commit 601baffb0b54b8fe70ad1dd9fd923fe38d08337e Author: Jessica Clarke AuthorDate: 2024-01-24 23:49:54 +0000 Commit: Jessica Clarke CommitDate: 2024-09-06 23:59:12 +0000 riscv: Create a newbus device for the SBI driver This approach is based on the Arm PSCI driver, though that makes more extensive use of its softc than we do here. This will be used to extract the SBI IPI code as a real PIC. Reviewed by: mhorne, imp MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D35900 (cherry picked from commit c55272fdf8570b4e15112009ad0066ed156f21a7) --- sys/riscv/include/sbi.h | 6 +---- sys/riscv/riscv/sbi.c | 65 +++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 59 insertions(+), 12 deletions(-) diff --git a/sys/riscv/include/sbi.h b/sys/riscv/include/sbi.h index 4fbdd598ec4d..bd3991e0a89f 100644 --- a/sys/riscv/include/sbi.h +++ b/sys/riscv/include/sbi.h @@ -159,11 +159,7 @@ sbi_call(uint64_t arg7, uint64_t arg6, uint64_t arg0, uint64_t arg1, return (ret); } -/* Base extension functions and variables. */ -extern u_long sbi_spec_version; -extern u_long sbi_impl_id; -extern u_long sbi_impl_version; - +/* Base extension functions. */ static __inline long sbi_probe_extension(long id) { diff --git a/sys/riscv/riscv/sbi.c b/sys/riscv/riscv/sbi.c index 36aaa8a6ffed..284b29af77df 100644 --- a/sys/riscv/riscv/sbi.c +++ b/sys/riscv/riscv/sbi.c @@ -2,6 +2,7 @@ * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2019 Mitchell Horne + * Copyright (c) 2021 Jessica Clarke * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,10 +28,11 @@ #include #include -#include #include -#include +#include #include +#include +#include #include #include @@ -40,9 +42,15 @@ #define OPENSBI_VERSION_MAJOR_OFFSET 16 #define OPENSBI_VERSION_MINOR_MASK 0xFFFF -u_long sbi_spec_version; -u_long sbi_impl_id; -u_long sbi_impl_version; +struct sbi_softc { + device_t dev; +}; + +static struct sbi_softc *sbi_softc = NULL; + +static u_long sbi_spec_version; +static u_long sbi_impl_id; +static u_long sbi_impl_version; static bool has_time_extension = false; static bool has_ipi_extension = false; @@ -316,10 +324,53 @@ sbi_init(void) } static void -sbi_late_init(void *dummy __unused) +sbi_identify(driver_t *driver, device_t parent) +{ + device_t dev; + + if (device_find_child(parent, "sbi", -1) != NULL) + return; + + dev = BUS_ADD_CHILD(parent, 0, "sbi", -1); + if (dev == NULL) + device_printf(parent, "Can't add sbi child\n"); +} + +static int +sbi_probe(device_t dev) { + device_set_desc(dev, "RISC-V Supervisor Binary Interface"); + + return (BUS_PROBE_NOWILDCARD); +} + +static int +sbi_attach(device_t dev) +{ + struct sbi_softc *sc; + + if (sbi_softc != NULL) + return (ENXIO); + + sc = device_get_softc(dev); + sc->dev = dev; + sbi_softc = sc; + EVENTHANDLER_REGISTER(shutdown_final, sbi_shutdown_final, NULL, SHUTDOWN_PRI_LAST); + + return (0); } -SYSINIT(sbi, SI_SUB_KLD, SI_ORDER_ANY, sbi_late_init, NULL); +static device_method_t sbi_methods[] = { + /* Device interface */ + DEVMETHOD(device_identify, sbi_identify), + DEVMETHOD(device_probe, sbi_probe), + DEVMETHOD(device_attach, sbi_attach), + + DEVMETHOD_END +}; + +DEFINE_CLASS_0(sbi, sbi_driver, sbi_methods, sizeof(struct sbi_softc)); +EARLY_DRIVER_MODULE(sbi, nexus, sbi_driver, 0, 0, + BUS_PASS_CPU + BUS_PASS_ORDER_FIRST);