Module Name: src Committed By: thorpej Date: Sun Nov 19 19:49:44 UTC 2023
Modified Files: src/sys/dev/pci: virtio_pci.c Log Message: On alpha and sparc64, use VirtIO 1.0 and VIRTIO_F_ACCESS_PLATFORM so that DMA to PCI-attached VirtIO devices works properly. This is needed for Qemu to select the appropriate address space for PCI DMA. To generate a diff of this commit: cvs rdiff -u -r1.43 -r1.44 src/sys/dev/pci/virtio_pci.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/pci/virtio_pci.c diff -u src/sys/dev/pci/virtio_pci.c:1.43 src/sys/dev/pci/virtio_pci.c:1.44 --- src/sys/dev/pci/virtio_pci.c:1.43 Fri Jul 7 07:19:36 2023 +++ src/sys/dev/pci/virtio_pci.c Sun Nov 19 19:49:44 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: virtio_pci.c,v 1.43 2023/07/07 07:19:36 rin Exp $ */ +/* $NetBSD: virtio_pci.c,v 1.44 2023/11/19 19:49:44 thorpej Exp $ */ /* * Copyright (c) 2020 The NetBSD Foundation, Inc. @@ -28,7 +28,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: virtio_pci.c,v 1.43 2023/07/07 07:19:36 rin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: virtio_pci.c,v 1.44 2023/11/19 19:49:44 thorpej Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -50,6 +50,15 @@ __KERNEL_RCSID(0, "$NetBSD: virtio_pci.c #define VIRTIO_PRIVATE #include <dev/pci/virtiovar.h> /* XXX: move to non-pci */ +#if defined(__alpha__) || defined(__sparc64__) +/* + * XXX VIRTIO_F_ACCESS_PLATFORM is required for standard PCI DMA + * XXX to work on these platforms, at least by Qemu. + * XXX + * XXX Generalize this later. + */ +#define __NEED_VIRTIO_F_ACCESS_PLATFORM +#endif /* __alpha__ || __sparc64__ */ #define VIRTIO_PCI_LOG(_sc, _use_log, _fmt, _args...) \ do { \ @@ -275,8 +284,28 @@ virtio_pci_attach(device_t parent, devic ret = virtio_pci_attach_10(self, aux); } if (ret == 0 && revision == 0) { - /* revision 0 means 0.9 only or both 0.9 and 1.0 */ + /* + * revision 0 means 0.9 only or both 0.9 and 1.0. The + * latter are so-called "Transitional Devices". For + * those devices, we want to use the 1.0 interface if + * possible. + * + * XXX Currently only on platforms that require 1.0 + * XXX features, such as VIRTIO_F_ACCESS_PLATFORM. + */ +#ifdef __NEED_VIRTIO_F_ACCESS_PLATFORM + /* First, try to attach 1.0 */ + ret = virtio_pci_attach_10(self, aux); + if (ret != 0) { + aprint_error_dev(self, + "VirtIO 1.0 error = %d, falling back to 0.9\n", + ret); + /* Fall back to 0.9. */ + ret = virtio_pci_attach_09(self, aux); + } +#else ret = virtio_pci_attach_09(self, aux); +#endif /* __NEED_VIRTIO_F_ACCESS_PLATFORM */ } if (ret) { aprint_error_dev(self, "cannot attach (%d)\n", ret); @@ -781,6 +810,10 @@ virtio_pci_negotiate_features_10(struct uint64_t host, negotiated, device_status; guest_features |= VIRTIO_F_VERSION_1; +#ifdef __NEED_VIRTIO_F_ACCESS_PLATFORM + /* XXX This could use some work. */ + guest_features |= VIRTIO_F_ACCESS_PLATFORM; +#endif /* __NEED_VIRTIO_F_ACCESS_PLATFORM */ /* notify on empty is 0.9 only */ guest_features &= ~VIRTIO_F_NOTIFY_ON_EMPTY; sc->sc_active_features = 0;