]> mj.ucw.cz Git - pciutils.git/commitdiff
Add virtio vendor capability support
authorGerd Hoffmann <kraxel@redhat.com>
Wed, 21 Jan 2015 15:35:04 +0000 (16:35 +0100)
committerMartin Mares <mj@ucw.cz>
Thu, 22 Jan 2015 09:08:09 +0000 (10:08 +0100)
virtio uses vendor-specific capabilities to specify the location of
the virtio register ranges.  The specification can be found here:

http://docs.oasis-open.org/virtio/virtio/v1.0/cs01/virtio-v1.0-cs01.html#x1-690004

This patch adds support for decoding these capabilities to lspci.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Makefile
ls-caps-vendor.c [new file with mode: 0644]
ls-caps.c
lspci.h

index 8d49afa457264a49d3d5e8fc9a51ee3f1df9078a..39a07d1a445e9ecd4b91c543c14bdea2bb004cbd 100644 (file)
--- 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 (file)
index 0000000..4cdfe22
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ *     The PCI Utilities -- Show Vendor-specific Capabilities
+ *
+ *     Copyright (c) 2014 Gerd Hoffmann <kraxel@redhat.com>
+ *
+ *     Can be freely distributed and used under the terms of the GNU GPL.
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#include "lspci.h"
+
+static void
+show_vendor_caps_virtio(struct device *d, int where, int cap)
+{
+  int length = BITS(cap, 0, 8);
+  int type = BITS(cap, 8, 8);
+  char *tname;
+
+  if (length < 16)
+    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",
+        get_conf_byte(d, where +  4),
+        get_conf_long(d, where +  8),
+        get_conf_long(d, where + 12));
+
+  if (type != 2 || length < 20)
+    return;
+
+  printf("\t\tmultiplier=%08x\n",
+        get_conf_long(d, where+16));
+}
+
+void
+show_vendor_caps(struct device *d, int where, int cap)
+{
+  switch (get_conf_word(d, PCI_VENDOR_ID))
+    {
+    case 0x1af4: /* Red Hat */
+      if (get_conf_word(d, PCI_DEVICE_ID) >= 0x1000 &&
+         get_conf_word(d, PCI_DEVICE_ID) <= 0x107f)
+       show_vendor_caps_virtio(d, where, cap);
+      break;
+    default:
+      printf("Vendor Specific Information: Len=%02x <?>\n", BITS(cap, 0, 8));
+      break;
+    }
+}
index 7de55ef5b6bdb2485b14a6450eebef7fa1c9267e..c145ed66bb7048574d6f728f8c7d5d8f7bfb49f6 100644 (file)
--- a/ls-caps.c
+++ b/ls-caps.c
@@ -1315,7 +1315,7 @@ 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));
+             show_vendor_caps(d, where, cap);
              break;
            case PCI_CAP_ID_DBG:
              cap_debug_port(cap);
diff --git a/lspci.h b/lspci.h
index 86429b2c73b43c8291729376ae693e9c8862d295..a3fc9d0e3a81ef72f36eb5a64b0b94303bf9d5d8 100644 (file)
--- 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(struct device *d, int where, int cap);
+
 /* ls-kernel.c */
 
 void show_kernel_machine(struct device *d UNUSED);