From nobody Wed Jan 24 23:50:23 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 4TL10v502sz58xqC; Wed, 24 Jan 2024 23:50:23 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4TL10v3B44z4qyH; Wed, 24 Jan 2024 23:50:23 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706140223; 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=77m49LqiE6WfweHtyxFO8gLHyriEYjGZ3aDGpI+5ug0=; b=x6vqE8G57CE1otCu6proPk4ejUia+cKvJuyQ2ryvAs6N1aF5uw1Y4Ch2JdaE5guO4iGBoJ 4jSoLTY0uWJ4ZPQ7MfX6VI6B0gVnQXgwDDy7Ax5KNOEq3Bp867rEYTnBL0YZFwxfmc2WFk 2FZTvEZk7bhm7i3u94a6Yj3t0PTtusjuOTzBEZBZbhvDgRJ0GHtoR7iUPsS8WedaG4unLX GYtsET9fSKUpjPHgFUogbGRA0afQQJBNv6Vc7+eaJZmjAWPxxLENXa0KwkhvVIw7v5/jTF 0ouBaQ4tqXMU+KWpZ9yWE8cfY6VGJCWPyTaDjDyriLg4lPBR+q+0ykwZepkysQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706140223; 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=77m49LqiE6WfweHtyxFO8gLHyriEYjGZ3aDGpI+5ug0=; b=RzIyM4gfLe5Lp71LgvpMQt0RuqK3et6+Zs6ViHG1g7WRuGLBVOd/q7tG9rbnu9WW56ebFd yOQWdZItbIg9qSqUj2mun50GNT9a3NMiqh47EKPu2FJTMasyQICJ6pBwmaoZabRcQz8k7z LENzWp14JEk1Iars9/NLcuNCu15RsH3pc02sEj4rCrQ+5mT6NLQvlIO14j1YZAY5snsjBZ vgKrb4XHbhxtJwLH36Kwfh2jauzY94jgZkRjIhfIjeFtj86CZDeywPRm2jY4aAv8WDagwK OL0tQSLMHXUOSJw+A9SH+PDMvWSKQwPza8sioJ7F6XzKMpJfpjdED+hETCRO8Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1706140223; a=rsa-sha256; cv=none; b=XwyV8FsUGOhEFqUrNInQeVNASbD4cdgFt0XGScaMHs04SpDnAN9eVOCQC/p4TdzxxOpi0l hX/IxlVCu8+7A7w1Z9OBE9+ETHH3WI99Ud2e1kDRxC+6B+8hvltJGUwTiTISgeZlaBP6ZE iUdb6YtTQX2gmT8N3kuEDl/3tBfX3KVuasZzpEMYXRfpwv06/VtzAP7irlHP8MxEg6/4/y GjrvsM+aYDziocBnesFjfu7rzVBAl0poT1jJ8TBBqM2rg2+zW1AfZZHE9gMEl/fovXyHhj yOnzGe35wtDRZaPJWLmo62iCtR+l2PzgqSKYU0zzvE4p82RNXgrUe7HJ1LjWkg== 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 4TL10v2HD3zbJ1; Wed, 24 Jan 2024 23:50:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 40ONoNXn018636; Wed, 24 Jan 2024 23:50:23 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40ONoN1J018633; Wed, 24 Jan 2024 23:50:23 GMT (envelope-from git) Date: Wed, 24 Jan 2024 23:50:23 GMT Message-Id: <202401242350.40ONoN1J018633@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Jessica Clarke Subject: git: c55272fdf857 - main - 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: 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/main X-Git-Reftype: branch X-Git-Commit: c55272fdf8570b4e15112009ad0066ed156f21a7 Auto-Submitted: auto-generated The branch main has been updated by jrtc27: URL: https://cgit.FreeBSD.org/src/commit/?id=c55272fdf8570b4e15112009ad0066ed156f21a7 commit c55272fdf8570b4e15112009ad0066ed156f21a7 Author: Jessica Clarke AuthorDate: 2024-01-24 23:49:54 +0000 Commit: Jessica Clarke CommitDate: 2024-01-24 23:49:54 +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 --- 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 630b9bbd9727..7c6d19064456 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 @@ -26,10 +27,11 @@ */ #include -#include #include -#include +#include #include +#include +#include #include #include @@ -39,9 +41,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; @@ -315,10 +323,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);