[PATCH] add virtio vendor caps

From: Gerd Hoffmann
Date: Mon Jan 19 2015 - 05:46:37 EST


---
Makefile | 2 +-
ls-caps-vendor.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ls-caps.c | 9 ++++++++-
lspci.h | 4 ++++
4 files changed, 70 insertions(+), 2 deletions(-)
create mode 100644 ls-caps-vendor.c

diff --git a/Makefile b/Makefile
index 8d49afa..39a07d1 100644
--- a/Makefile
+++ b/Makefile
@@ -69,7 +69,7 @@ force:
lib/config.h lib/config.mk:
cd lib && ./configure

-lspci: lspci.o ls-vpd.o ls-caps.o ls-ecaps.o ls-kernel.o ls-tree.o ls-map.o common.o lib/$(PCILIB)
+lspci: lspci.o ls-vpd.o ls-caps.o ls-caps-vendor.o ls-ecaps.o ls-kernel.o ls-tree.o ls-map.o common.o lib/$(PCILIB)
setpci: setpci.o common.o lib/$(PCILIB)

LSPCIINC=lspci.h pciutils.h $(PCIINC)
diff --git a/ls-caps-vendor.c b/ls-caps-vendor.c
new file mode 100644
index 0000000..5f8b3e1
--- /dev/null
+++ b/ls-caps-vendor.c
@@ -0,0 +1,57 @@
+/*
+ * The PCI Utilities -- Show Vendor-specific Capabilities
+ *
+ * Copyright (c) 2014 Gerd Hoffmann <kraxel@xxxxxxxxxx>
+ *
+ * Can be freely distributed and used under the terms of the GNU GPL.
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#include "lspci.h"
+
+void
+show_vendor_caps_virtio(struct device *d, int where, int cap)
+{
+ int length = BITS(cap, 0, 8);
+ int type = BITS(cap, 8, 5);
+ int bar = BITS(cap, 13, 3);
+ char *tname;
+
+ if (length < 12)
+ return;
+ if (!config_fetch(d, where, length))
+ return;
+
+ switch (type) {
+ case 1:
+ tname = "CommonCfg";
+ break;
+ case 2:
+ tname = "Notify";
+ break;
+ case 3:
+ tname = "ISR";
+ break;
+ case 4:
+ tname = "DeviceCfg";
+ break;
+ default:
+ tname = "<unknown>";
+ break;
+ }
+
+ printf("VirtIO: %s\n", tname);
+
+ if (verbose < 2)
+ return;
+
+ printf("\t\tBAR=%d offset=%08x size=%08x\n", bar,
+ get_conf_long(d, where+4),
+ get_conf_long(d, where+8));
+ if (type != 2 || length < 16)
+ return;
+ printf("\t\tmultiplier=%08x\n",
+ get_conf_long(d, where+12));
+}
diff --git a/ls-caps.c b/ls-caps.c
index 7de55ef..438b580 100644
--- a/ls-caps.c
+++ b/ls-caps.c
@@ -1315,7 +1315,14 @@ show_caps(struct device *d, int where)
cap_ht(d, where, cap);
break;
case PCI_CAP_ID_VNDR:
- printf("Vendor Specific Information: Len=%02x <?>\n", BITS(cap, 0, 8));
+ switch (get_conf_word(d, PCI_VENDOR_ID)) {
+ case 0x1af4: /* Red Hat, devices 0x1000 -> 0x107f are virtio */
+ show_vendor_caps_virtio(d, where, cap);
+ break;
+ default:
+ printf("Vendor Specific Information: Len=%02x <?>\n", BITS(cap, 0, 8));
+ break;
+ }
break;
case PCI_CAP_ID_DBG:
cap_debug_port(cap);
diff --git a/lspci.h b/lspci.h
index 86429b2..5ca9899 100644
--- a/lspci.h
+++ b/lspci.h
@@ -70,6 +70,10 @@ void show_caps(struct device *d, int where);

void show_ext_caps(struct device *d);

+/* ls-caps-vendor.c */
+
+void show_vendor_caps_virtio(struct device *d, int where, int cap);
+
/* ls-kernel.c */

void show_kernel_machine(struct device *d UNUSED);
--
1.8.3.1


--=-0zWL1zFiJykP2TPP5hvE--

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/