Module Name:    src
Committed By:   snj
Date:           Tue Dec 31 01:30:24 UTC 2024

Modified Files:
        src/sys/dev/pci [netbsd-10]: virtio_pci.c virtioreg.h

Log Message:
Pull up following revision(s) (requested by martin in ticket #1032):
        sys/dev/pci/virtioreg.h: 1.13
        sys/dev/pci/virtio_pci.c: 1.44
Define the VIRTIO_F_ACCESS_PLATFORM, VIRTIO_F_RING_PACKED,
VIRTIO_F_ORDER_PLATFORM, and VIRTIO_F_SR_IOV feature bits.
--
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.38.4.5 -r1.38.4.6 src/sys/dev/pci/virtio_pci.c
cvs rdiff -u -r1.11.2.1 -r1.11.2.2 src/sys/dev/pci/virtioreg.h

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.38.4.5 src/sys/dev/pci/virtio_pci.c:1.38.4.6
--- src/sys/dev/pci/virtio_pci.c:1.38.4.5	Thu Nov 28 16:33:25 2024
+++ src/sys/dev/pci/virtio_pci.c	Tue Dec 31 01:30:24 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: virtio_pci.c,v 1.38.4.5 2024/11/28 16:33:25 martin Exp $ */
+/* $NetBSD: virtio_pci.c,v 1.38.4.6 2024/12/31 01:30:24 snj 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.38.4.5 2024/11/28 16:33:25 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: virtio_pci.c,v 1.38.4.6 2024/12/31 01:30:24 snj Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -51,6 +51,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 {							\
@@ -277,8 +286,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);
@@ -798,6 +827,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;

Index: src/sys/dev/pci/virtioreg.h
diff -u src/sys/dev/pci/virtioreg.h:1.11.2.1 src/sys/dev/pci/virtioreg.h:1.11.2.2
--- src/sys/dev/pci/virtioreg.h:1.11.2.1	Sat May 13 10:56:10 2023
+++ src/sys/dev/pci/virtioreg.h	Tue Dec 31 01:30:24 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: virtioreg.h,v 1.11.2.1 2023/05/13 10:56:10 martin Exp $	*/
+/*	$NetBSD: virtioreg.h,v 1.11.2.2 2024/12/31 01:30:24 snj Exp $	*/
 
 /*
  * Copyright (c) 2010 Minoura Makoto.
@@ -84,6 +84,10 @@
 #define  VIRTIO_F_RING_EVENT_IDX		__BIT(29)
 #define  VIRTIO_F_BAD_FEATURE			__BIT(30)
 #define  VIRTIO_F_VERSION_1			__BIT(32)
+#define  VIRTIO_F_ACCESS_PLATFORM		__BIT(33)
+#define  VIRTIO_F_RING_PACKED			__BIT(34)
+#define  VIRTIO_F_ORDER_PLATFORM		__BIT(36)
+#define  VIRTIO_F_SR_IOV			__BIT(37)
 
 /* common device status flags */
 #define  VIRTIO_CONFIG_DEVICE_STATUS_RESET		  0
@@ -101,6 +105,10 @@
 /* common device/guest features */
 #define VIRTIO_COMMON_FLAG_BITS			\
         "\177\020"				\
+	"b\x24" "SR_IOV\0"			\
+	"b\x23" "ORDER_PLATFORM\0"		\
+	"b\x22" "RING_PACKED\0"			\
+	"b\x21" "ACCESS_PLATFORM\0"		\
 	"b\x20" "V1\0"				\
 	"b\x1e" "BAD_FEATURE\0"			\
 	"b\x1d" "EVENT_IDX\0"			\

Reply via email to