From owner-dev-commits-src-main@freebsd.org Tue Jan 19 05:08:10 2021 Return-Path: Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 2410E4E52A3; Tue, 19 Jan 2021 05:08:10 +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 4DKc9h0wdYz4XJn; Tue, 19 Jan 2021 05:08:07 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 8777920D8E; Tue, 19 Jan 2021 05:08:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 10J5860s085662; Tue, 19 Jan 2021 05:08:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 10J586mX085661; Tue, 19 Jan 2021 05:08:06 GMT (envelope-from git) Date: Tue, 19 Jan 2021 05:08:06 GMT Message-Id: <202101190508.10J586mX085661@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Bryan Venteicher Subject: git: edf7c8ddceca - main - virtio_console: Add modern (V1) support MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bryanv X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: edf7c8ddcecae93ced005144b6eeac14e08ade8e Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Jan 2021 05:08:10 -0000 The branch main has been updated by bryanv: URL: https://cgit.FreeBSD.org/src/commit/?id=edf7c8ddcecae93ced005144b6eeac14e08ade8e commit edf7c8ddcecae93ced005144b6eeac14e08ade8e Author: Bryan Venteicher AuthorDate: 2021-01-19 04:55:24 +0000 Commit: Bryan Venteicher CommitDate: 2021-01-19 04:55:24 +0000 virtio_console: Add modern (V1) support Reviewed by: grehan (mentor) Differential Revision: https://reviews.freebsd.org/D27901 --- sys/dev/virtio/console/virtio_console.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/sys/dev/virtio/console/virtio_console.c b/sys/dev/virtio/console/virtio_console.c index f3c5db17e764..0bd7c982e3f5 100644 --- a/sys/dev/virtio/console/virtio_console.c +++ b/sys/dev/virtio/console/virtio_console.c @@ -226,6 +226,14 @@ static void vtcon_get_console_size(struct vtcon_softc *, uint16_t *, static void vtcon_enable_interrupts(struct vtcon_softc *); static void vtcon_disable_interrupts(struct vtcon_softc *); +#define vtcon_modern(_sc) (((_sc)->vtcon_features & VIRTIO_F_VERSION_1) != 0) +#define vtcon_htog16(_sc, _val) virtio_htog16(vtcon_modern(_sc), _val) +#define vtcon_htog32(_sc, _val) virtio_htog32(vtcon_modern(_sc), _val) +#define vtcon_htog64(_sc, _val) virtio_htog64(vtcon_modern(_sc), _val) +#define vtcon_gtoh16(_sc, _val) virtio_gtoh16(vtcon_modern(_sc), _val) +#define vtcon_gtoh32(_sc, _val) virtio_gtoh32(vtcon_modern(_sc), _val) +#define vtcon_gtoh64(_sc, _val) virtio_gtoh64(vtcon_modern(_sc), _val) + static int vtcon_pending_free; static struct ttydevsw vtcon_tty_class = { @@ -430,6 +438,7 @@ vtcon_negotiate_features(struct vtcon_softc *sc) features = VTCON_FEATURES; sc->vtcon_features = virtio_negotiate_features(dev, features); + virtio_finalize_features(dev); } static void @@ -846,17 +855,20 @@ vtcon_ctrl_process_event(struct vtcon_softc *sc, struct virtio_console_control *control, void *data, size_t data_len) { device_t dev; - int id; + uint32_t id; + uint16_t event; dev = sc->vtcon_dev; - id = control->id; + id = vtcon_htog32(sc, control->id); + event = vtcon_htog16(sc, control->event); - if (id < 0 || id >= sc->vtcon_max_ports) { - device_printf(dev, "%s: invalid port ID %d\n", __func__, id); + if (id >= sc->vtcon_max_ports) { + device_printf(dev, "%s: event %d invalid port ID %d\n", + __func__, event, id); return; } - switch (control->event) { + switch (event) { case VIRTIO_CONSOLE_PORT_ADD: vtcon_ctrl_port_add_event(sc, id); break; @@ -984,9 +996,9 @@ vtcon_ctrl_send_control(struct vtcon_softc *sc, uint32_t portid, if ((sc->vtcon_flags & VTCON_FLAG_MULTIPORT) == 0) return; - control.id = portid; - control.event = event; - control.value = value; + control.id = vtcon_gtoh32(sc, portid); + control.event = vtcon_gtoh16(sc, event); + control.value = vtcon_gtoh16(sc, value); vtcon_ctrl_poll(sc, &control); }