From nobody Sat Apr 27 17:30:26 2024 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 4VRc781nrWz5JWdG for ; Sat, 27 Apr 2024 17:30:28 +0000 (UTC) (envelope-from 0100018f209bb34f-53541ffc-9f44-4e3f-be9a-27d57c8e0ffd-000000@amazonses.com) Received: from a8-60.smtp-out.amazonses.com (a8-60.smtp-out.amazonses.com [54.240.8.60]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4VRc773wJTz4Z4G for ; Sat, 27 Apr 2024 17:30:27 +0000 (UTC) (envelope-from 0100018f209bb34f-53541ffc-9f44-4e3f-be9a-27d57c8e0ffd-000000@amazonses.com) Authentication-Results: mx1.freebsd.org; dkim=pass header.d=tarsnap.com header.s=dqtolf56kk3wpt62c3jnwboqvr7iedax header.b=beX7WB7A; dkim=pass header.d=amazonses.com header.s=ug7nbtf4gccmlpwj322ax3p6ow6yfsug header.b=di+zXeB9; dmarc=pass (policy=none) header.from=tarsnap.com; spf=pass (mx1.freebsd.org: domain of 0100018f209bb34f-53541ffc-9f44-4e3f-be9a-27d57c8e0ffd-000000@amazonses.com designates 54.240.8.60 as permitted sender) smtp.mailfrom=0100018f209bb34f-53541ffc-9f44-4e3f-be9a-27d57c8e0ffd-000000@amazonses.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=dqtolf56kk3wpt62c3jnwboqvr7iedax; d=tarsnap.com; t=1714239026; h=Message-ID:Date:MIME-Version:Subject:To:References:Cc:From:In-Reply-To:Content-Type:Content-Transfer-Encoding; bh=Dkr68mq1vgLIE8VRfoy5aUGus+HiWuoWQ1rdVOlO0iA=; b=beX7WB7AZ0CNIHh31PQCr/Lwhkk7nyfHCodFWRKDz2bGuruxJAejQjBGRUwaHyVY aCstiQ/xxip/e79G5tZ13832CLR1vT03EQnWXIV8Sr9v0XRfSIbTElN8Vh4lyj+vI6/ zlZx/EIx+c4O5VH17vfG+Tq1je8LKF0q6g1jeIf8= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=ug7nbtf4gccmlpwj322ax3p6ow6yfsug; d=amazonses.com; t=1714239026; h=Message-ID:Date:MIME-Version:Subject:To:References:Cc:From:In-Reply-To:Content-Type:Content-Transfer-Encoding:Feedback-ID; bh=Dkr68mq1vgLIE8VRfoy5aUGus+HiWuoWQ1rdVOlO0iA=; b=di+zXeB9elExRxH+aqvDjvw6ZsS7iKTSclIA8X53EF+R5wclc2dqOtKCc/W/eCwP opLaBB2VUjOWP5lLIO0WNhPvLGPDj39cIeqnKXc6jLspukaBY1PRuTCgJaA4MM8OtaK j9GITVLSGzilozXAOjbKPw6tOJMCRzuqp7VihWDc= Message-ID: <0100018f209bb34f-53541ffc-9f44-4e3f-be9a-27d57c8e0ffd-000000@email.amazonses.com> Date: Sat, 27 Apr 2024 17:30:26 +0000 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 User-Agent: Mozilla Thunderbird Subject: Re: git: a87dd74125d2 - main - scmi: Add an SCMI VirtIO transport driver To: Andrew Turner , src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org References: <202404110959.43B9xVBJ090851@gitrepo.freebsd.org> Content-Language: en-US Cc: Isaac Cilia Attard From: Colin Percival Autocrypt: addr=cperciva@tarsnap.com; keydata= xsFNBGWMSrYBEACdWRqDn3B3SKO7IG0/fGHYtfs26f3Q5QeAcasy1fQLniwGQWn5rlILhbCD K/jdNoDm5Zxq20eqyffoDNObCjnHgg4tGANdi+RmDy+7C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GAEIACAWIQSCVjuE0GIO3A37hkE4l/LiLmWtPwUCZYxK tgIbDAAKCRA4l/LiLmWtP3jmEACQrh9gWe8F1Tkw3m6VoHKwLc5he4tX3WpQa//soPO6iGG3 S3WPruQ46NrAaAojoOcKI9UONDO5rxG0ZTX53S+lu2EO47jbcLwOCjaEpjKpDRt9ZXBQE8Xl mtBE9Bp3W9gpjB1nE3KNM1mJYgsK0QdRpwwfh4pVgGpOj8j23I6MCK+v99zEBnpgCn2GX8W/ kctRXHqWwndHysOJtRP/zrl7dDaABF1f9efUl0LL3TD3GJ9VDz+DNOin/uK2a1hiJo8QzTRk PpfUQ2ebzDsrd1i/pOWkMSkdH+rEu4AGrXWtaBwrMyrGkL6Icb6yO+P9/z0W2wlgBf3P1YRt JPgQt/Dj3yvA/UnaV/QmuVQPjl13o24UnJGsZM8XGnNdfWBKkC1Q6VXC4QT+dyBHYH9MuE9d 6oGl8pFM1+cTfEfbM62/rRoPkF1yHMsI/903VxEvuUIKfhEZAVLFyHldooNxuchntHQP9y8J 8Ou9bWYQP7MnEn+kwSwrZkjurfPkan+xQvp6dDYnj3V0GwA5pprBMaB928VIDVOv+1PNQI3t Cvk5VPv/skq+TJRMHW7bFSt8PRa91cUf1FOLIz9APDiJOzXkwxUEHGV3zPSaUhs1JYjyBeGT wDAvtLUdjOnRhEUOwlnIrztmvyciutjJoVzKEEjj5WXnHk9L9kQ1bpAjkjTONw== In-Reply-To: <202404110959.43B9xVBJ090851@gitrepo.freebsd.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Feedback-ID: 1.us-east-1.Lv9FVjaNvvR5llaqfLoOVbo2VxOELl7cjN0AOyXnPlk=:AmazonSES X-SES-Outgoing: 2024.04.27-54.240.8.60 X-Spamd-Bar: - X-Spamd-Result: default: False [-1.38 / 15.00]; FORGED_MUA_THUNDERBIRD_MSGID_UNKNOWN(2.50)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.99)[-0.994]; DMARC_POLICY_ALLOW(-0.50)[tarsnap.com,none]; FORGED_SENDER(0.30)[cperciva@tarsnap.com,0100018f209bb34f-53541ffc-9f44-4e3f-be9a-27d57c8e0ffd-000000@amazonses.com]; R_DKIM_ALLOW(-0.20)[tarsnap.com:s=dqtolf56kk3wpt62c3jnwboqvr7iedax,amazonses.com:s=ug7nbtf4gccmlpwj322ax3p6ow6yfsug]; RWL_MAILSPIKE_VERYGOOD(-0.20)[54.240.8.60:from]; R_SPF_ALLOW(-0.20)[+ip4:54.240.0.0/18:c]; MIME_GOOD(-0.10)[text/plain]; XM_UA_NO_VERSION(0.01)[]; TO_DN_SOME(0.00)[]; ASN(0.00)[asn:14618, ipnet:54.240.8.0/21, country:US]; RCVD_IN_DNSWL_NONE(0.00)[54.240.8.60:from]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; DKIM_TRACE(0.00)[tarsnap.com:+,amazonses.com:+]; MLMMJ_DEST(0.00)[dev-commits-src-main@FreeBSD.org]; FROM_HAS_DN(0.00)[]; FREEMAIL_CC(0.00)[gmail.com]; RCVD_COUNT_ZERO(0.00)[0]; FROM_NEQ_ENVFROM(0.00)[cperciva@tarsnap.com,0100018f209bb34f-53541ffc-9f44-4e3f-be9a-27d57c8e0ffd-000000@amazonses.com]; DWL_DNSWL_NONE(0.00)[amazonses.com:dkim]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCPT_COUNT_FIVE(0.00)[5] X-Rspamd-Queue-Id: 4VRc773wJTz4Z4G Hi Andrew, It looks like this breaks arm64 kernel configs without 'device virtio_scmi' since sys/dev/firmware/arm/scmi_virtio.c (which is 'optional fdt scmi') uses functions from sys/dev/virtio/scmi/virtio_scmi.c (which is 'optional virtio_scmi'). In particular, the "ARM" kernel configuration (whcih has std.dev and std.arm but not std.virt) breaks. Reported by Isaac Cilia Attard (CCed). Colin Percival On 4/11/24 02:59, Andrew Turner wrote: > The branch main has been updated by andrew: > > URL: https://cgit.FreeBSD.org/src/commit/?id=a87dd74125d290791d7259ceeab9507bada9987e > > commit a87dd74125d290791d7259ceeab9507bada9987e > Author: Cristian Marussi > AuthorDate: 2023-10-23 18:07:06 +0000 > Commit: Andrew Turner > CommitDate: 2024-04-11 09:58:57 +0000 > > scmi: Add an SCMI VirtIO transport driver > > Add an SCMI transport driver based on the virtio-scmi backend. > > Reviewed by: andrew, bryanv > Sponsored by: Arm Ltd > Differential Revision: https://reviews.freebsd.org/D43048 > --- > sys/conf/files.arm64 | 1 + > sys/dev/firmware/arm/scmi.c | 15 +- > sys/dev/firmware/arm/scmi.h | 2 + > sys/dev/firmware/arm/scmi_virtio.c | 298 +++++++++++++++++++++++++++++++++++++ > 4 files changed, 313 insertions(+), 3 deletions(-) > > diff --git a/sys/conf/files.arm64 b/sys/conf/files.arm64 > index a22ffa2b7f0c..632fbab5070d 100644 > --- a/sys/conf/files.arm64 > +++ b/sys/conf/files.arm64 > @@ -275,6 +275,7 @@ dev/firmware/arm/scmi_clk.c optional fdt scmi > dev/firmware/arm/scmi_if.m optional fdt scmi > dev/firmware/arm/scmi_mailbox.c optional fdt scmi > dev/firmware/arm/scmi_smc.c optional fdt scmi > +dev/firmware/arm/scmi_virtio.c optional fdt scmi > dev/firmware/arm/scmi_shmem.c optional fdt scmi > > dev/gpio/pl061.c optional pl061 gpio > diff --git a/sys/dev/firmware/arm/scmi.c b/sys/dev/firmware/arm/scmi.c > index 945c2b2e9f6e..ef4bcbf13996 100644 > --- a/sys/dev/firmware/arm/scmi.c > +++ b/sys/dev/firmware/arm/scmi.c > @@ -484,10 +484,19 @@ scmi_process_response(struct scmi_softc *sc, uint32_t hdr) > > mtx_lock_spin(&req->mtx); > req->done = true; > - if (!req->timed_out) > - wakeup(req); > - else > + if (!req->timed_out) { > + /* > + * Consider the case in which a polled message is picked > + * by chance on the IRQ path on another CPU: setting poll_done > + * will terminate the other poll loop. > + */ > + if (!req->msg.polling) > + wakeup(req); > + else > + atomic_store_rel_int(&req->msg.poll_done, 1); > + } else { > timed_out = true; > + } > mtx_unlock_spin(&req->mtx); > > if (timed_out) > diff --git a/sys/dev/firmware/arm/scmi.h b/sys/dev/firmware/arm/scmi.h > index 572422594292..345ae6eeb03a 100644 > --- a/sys/dev/firmware/arm/scmi.h > +++ b/sys/dev/firmware/arm/scmi.h > @@ -62,12 +62,14 @@ struct scmi_softc { > > struct scmi_msg { > bool polling; > + int poll_done; > uint32_t tx_len; > uint32_t rx_len; > #define SCMI_MSG_HDR_SIZE (sizeof(uint32_t)) > uint32_t hdr; > uint8_t payld[]; > }; > +#define hdr_to_msg(h) __containerof((h), struct scmi_msg, hdr) > > void *scmi_buf_get(device_t dev, uint8_t protocol_id, uint8_t message_id, > int tx_payd_sz, int rx_payld_sz); > diff --git a/sys/dev/firmware/arm/scmi_virtio.c b/sys/dev/firmware/arm/scmi_virtio.c > new file mode 100644 > index 000000000000..12cbb9ecefd5 > --- /dev/null > +++ b/sys/dev/firmware/arm/scmi_virtio.c > @@ -0,0 +1,298 @@ > +/*- > + * SPDX-License-Identifier: BSD-2-Clause > + * > + * Copyright (c) 2023 Arm Ltd > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions > + * are met: > + * 1. Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * 2. Redistributions in binary form must reproduce the above copyright > + * notice, this list of conditions and the following disclaimer in the > + * documentation and/or other materials provided with the distribution. > + * > + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND > + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE > + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE > + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE > + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL > + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS > + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) > + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT > + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY > + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF > + * SUCH DAMAGE. > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include > +#include > +#include > + > +#include > + > +#include "scmi.h" > +#include "scmi_protocols.h" > + > +#define SCMI_VIRTIO_POLLING_INTERVAL_MS 2 > + > +struct scmi_virtio_softc { > + struct scmi_softc base; > + device_t virtio_dev; > + int cmdq_sz; > + int evtq_sz; > + void *p2a_pool; > +}; > + > +static void scmi_virtio_callback(void *, unsigned int, void *); > +static void *scmi_virtio_p2a_pool_init(device_t, unsigned int); > +static int scmi_virtio_transport_init(device_t); > +static void scmi_virtio_transport_cleanup(device_t); > +static int scmi_virtio_xfer_msg(device_t, struct scmi_msg *); > +static int scmi_virtio_poll_msg(device_t, struct scmi_msg *, unsigned int); > +static void scmi_virtio_clear_channel(device_t, void *); > +static int scmi_virtio_probe(device_t); > +static int scmi_virtio_attach(device_t); > + > +static void > +scmi_virtio_callback(void *msg, unsigned int len, void *priv) > +{ > + struct scmi_virtio_softc *sc; > + uint32_t hdr; > + > + sc = priv; > + > + if (msg == NULL || len < sizeof(hdr)) { > + device_printf(sc->virtio_dev, "Ignoring malformed message.\n"); > + return; > + } > + > + hdr = le32toh(*((uint32_t *)msg)); > + scmi_rx_irq_callback(sc->base.dev, msg, hdr); > +} > + > +static void * > +scmi_virtio_p2a_pool_init(device_t dev, unsigned int max_msg) > +{ > + struct scmi_virtio_softc *sc; > + void *pool; > + uint8_t *buf; > + int i; > + > + sc = device_get_softc(dev); > + > + pool = mallocarray(max_msg, SCMI_MAX_MSG_SIZE, M_DEVBUF, > + M_ZERO | M_WAITOK); > + > + for (i = 0, buf = pool; i < max_msg; i++, buf += SCMI_MAX_MSG_SIZE) { > + /* Feed platform with pre-allocated P2A buffers */ > + virtio_scmi_message_enqueue(sc->virtio_dev, > + VIRTIO_SCMI_CHAN_P2A, buf, 0, SCMI_MAX_MSG_SIZE); > + } > + > + device_printf(dev, > + "Fed %d initial P2A buffers to platform.\n", max_msg); > + > + return (pool); > +} > + > +static void > +scmi_virtio_clear_channel(device_t dev, void *msg) > +{ > + struct scmi_virtio_softc *sc; > + > + sc = device_get_softc(dev); > + virtio_scmi_message_enqueue(sc->virtio_dev, VIRTIO_SCMI_CHAN_P2A, > + msg, 0, SCMI_MAX_MSG_SIZE); > +} > + > +static int > +scmi_virtio_transport_init(device_t dev) > +{ > + struct scmi_virtio_softc *sc; > + int ret; > + > + sc = device_get_softc(dev); > + > + sc->cmdq_sz = virtio_scmi_channel_size_get(sc->virtio_dev, > + VIRTIO_SCMI_CHAN_A2P); > + sc->evtq_sz = virtio_scmi_channel_size_get(sc->virtio_dev, > + VIRTIO_SCMI_CHAN_P2A); > + > + if (!sc->cmdq_sz) { > + device_printf(dev, > + "VirtIO cmdq virtqueue not found. Aborting.\n"); > + return (ENXIO); > + } > + > + /* > + * P2A buffers are owned by the platform initially; allocate a feed an > + * appropriate number of buffers. > + */ > + if (sc->evtq_sz != 0) { > + sc->p2a_pool = scmi_virtio_p2a_pool_init(dev, sc->evtq_sz); > + if (sc->p2a_pool == NULL) > + return (ENOMEM); > + } > + > + /* Note that setting a callback also enables that VQ interrupts */ > + ret = virtio_scmi_channel_callback_set(sc->virtio_dev, > + VIRTIO_SCMI_CHAN_A2P, scmi_virtio_callback, sc); > + if (ret) { > + device_printf(dev, "Failed to set VirtIO cmdq callback.\n"); > + return (ENXIO); > + } > + > + device_printf(dev, > + "VirtIO cmdq virtqueue configured - cmdq_sz:%d\n", sc->cmdq_sz); > + > + /* P2A channel is optional */ > + if (sc->evtq_sz) { > + ret = virtio_scmi_channel_callback_set(sc->virtio_dev, > + VIRTIO_SCMI_CHAN_P2A, scmi_virtio_callback, sc); > + if (ret == 0) { > + device_printf(dev, > + "VirtIO evtq virtqueue configured - evtq_sz:%d\n", > + sc->evtq_sz); > + } else { > + device_printf(dev, > + "Failed to set VirtIO evtq callback.Skip.\n"); > + sc->evtq_sz = 0; > + } > + } > + > + sc->base.trs_desc.reply_timo_ms = 100; > + > + return (0); > +} > + > +static void > +scmi_virtio_transport_cleanup(device_t dev) > +{ > + struct scmi_virtio_softc *sc; > + > + sc = device_get_softc(dev); > + > + if (sc->evtq_sz != 0) { > + virtio_scmi_channel_callback_set(sc->virtio_dev, > + VIRTIO_SCMI_CHAN_P2A, NULL, NULL); > + free(sc->p2a_pool, M_DEVBUF); > + } > + > + virtio_scmi_channel_callback_set(sc->virtio_dev, > + VIRTIO_SCMI_CHAN_A2P, NULL, NULL); > +} > + > +static int > +scmi_virtio_xfer_msg(device_t dev, struct scmi_msg *msg) > +{ > + struct scmi_virtio_softc *sc; > + > + sc = device_get_softc(dev); > + > + return (virtio_scmi_message_enqueue(sc->virtio_dev, > + VIRTIO_SCMI_CHAN_A2P, &msg->hdr, msg->tx_len, msg->rx_len)); > +} > + > +static int > +scmi_virtio_poll_msg(device_t dev, struct scmi_msg *msg, unsigned int tmo_ms) > +{ > + struct scmi_virtio_softc *sc; > + device_t vdev; > + int tmo_loops; > + > + sc = device_get_softc(dev); > + vdev = sc->virtio_dev; > + > + tmo_loops = tmo_ms / SCMI_VIRTIO_POLLING_INTERVAL_MS; > + while (tmo_loops-- && atomic_load_acq_int(&msg->poll_done) == 0) { > + struct scmi_msg *rx_msg; > + void *rx_buf; > + uint32_t rx_len; > + > + rx_buf = virtio_scmi_message_poll(vdev, &rx_len); > + if (rx_buf == NULL) { > + DELAY(SCMI_VIRTIO_POLLING_INTERVAL_MS * 1000); > + continue; > + } > + > + rx_msg = hdr_to_msg(rx_buf); > + rx_msg->rx_len = rx_len; > + /* Complete the polling on any poll path */ > + if (rx_msg->polling) > + atomic_store_rel_int(&rx_msg->poll_done, 1); > + > + if (__predict_true(rx_msg == msg)) > + break; > + > + /* > + * Polling returned an unexpected message: either a message > + * polled by some other thread of execution or a message not > + * supposed to be polled. > + */ > + device_printf(dev, "POLLED OoO HDR:|%08X| - polling:%d\n", > + rx_msg->hdr, rx_msg->polling); > + > + if (!rx_msg->polling) > + scmi_rx_irq_callback(sc->base.dev, rx_msg, rx_msg->hdr); > + } > + > + return (tmo_loops > 0 ? 0 : ETIMEDOUT); > +} > + > +static int > +scmi_virtio_probe(device_t dev) > +{ > + if (!ofw_bus_is_compatible(dev, "arm,scmi-virtio")) > + return (ENXIO); > + > + if (!ofw_bus_status_okay(dev)) > + return (ENXIO); > + > + device_set_desc(dev, "ARM SCMI VirtIO Transport driver"); > + > + return (BUS_PROBE_DEFAULT); > +} > + > +static int > +scmi_virtio_attach(device_t dev) > +{ > + struct scmi_virtio_softc *sc; > + > + sc = device_get_softc(dev); > + sc->virtio_dev = virtio_scmi_transport_get(); > + if (sc->virtio_dev == NULL) > + return (1); > + > + /* When attach fails there is nothing to cleanup*/ > + return (scmi_attach(dev)); > +} > + > +static device_method_t scmi_virtio_methods[] = { > + DEVMETHOD(device_probe, scmi_virtio_probe), > + DEVMETHOD(device_attach, scmi_virtio_attach), > + > + /* SCMI interface */ > + DEVMETHOD(scmi_transport_init, scmi_virtio_transport_init), > + DEVMETHOD(scmi_transport_cleanup, scmi_virtio_transport_cleanup), > + DEVMETHOD(scmi_xfer_msg, scmi_virtio_xfer_msg), > + DEVMETHOD(scmi_poll_msg, scmi_virtio_poll_msg), > + DEVMETHOD(scmi_clear_channel, scmi_virtio_clear_channel), > + > + DEVMETHOD_END > +}; > + > +DEFINE_CLASS_1(scmi_virtio, scmi_virtio_driver, scmi_virtio_methods, > + sizeof(struct scmi_virtio_softc), scmi_driver); > + > +/* Needs to be after the mmio_sram driver */ > +DRIVER_MODULE(scmi_virtio, simplebus, scmi_virtio_driver, 0, 0); > +MODULE_VERSION(scmi_virtio, 1); > -- Colin Percival FreeBSD Release Engineering Lead & EC2 platform maintainer Founder, Tarsnap | www.tarsnap.com | Online backups for the truly paranoid