All of lore.kernel.org
 help / color / mirror / Atom feed
* [pciutils patch] add virtio vendor capability support
@ 2015-01-21 11:21 Gerd Hoffmann
  2015-01-21 14:57 ` Martin Mares
  0 siblings, 1 reply; 4+ messages in thread
From: Gerd Hoffmann @ 2015-01-21 11:21 UTC (permalink / raw)
  To: mj; +Cc: virtio-dev, virtualization

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         |  2 +-
 ls-caps-vendor.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 ls-caps.c        |  9 ++++++++-
 lspci.h          |  4 ++++
 4 files changed, 72 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..edcc44a
--- /dev/null
+++ b/ls-caps-vendor.c
@@ -0,0 +1,59 @@
+/*
+ *	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"
+
+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));
+}
diff --git a/ls-caps.c b/ls-caps.c
index 7de55ef..54a64a7 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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [pciutils patch] add virtio vendor capability support
  2015-01-21 11:21 [pciutils patch] add virtio vendor capability support Gerd Hoffmann
@ 2015-01-21 14:57 ` Martin Mares
  2015-01-21 15:16   ` Gerd Hoffmann
       [not found]   ` <1421853400.10966.4.camel@nilsson.home.kraxel.org>
  0 siblings, 2 replies; 4+ messages in thread
From: Martin Mares @ 2015-01-21 14:57 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: virtio-dev, virtualization

Hello!

> 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.

I like the patch, except for a couple of details:

(1) Please follow the coding style of the rest of pciutils.

(2) You assume that PCI_CAP_ID_VNDR of all Redhat devices contains virtio,
    but the comment nearby refers to a range of device IDs only.

(3) Moving code related to vendor-defined caps to a separate file sounds
    good, but I think we should push the boundary a bit further: let the
    main switch in ls-caps.c call a function from ls-caps-vendor.c as soon
    as it finds PCI_CAP_ID_VENDOR, leaving all decisions based on
    vendor/device ID to this function.

Could you please fix these and resubmit?

				Have a nice fortnight
-- 
Martin `MJ' Mares                          <mj@ucw.cz>   http://mj.ucw.cz/
Faculty of Math and Physics, Charles University, Prague, Czech Rep., Earth
VI has two modes: the one in which it beeps and the one in which it doesn't.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [pciutils patch] add virtio vendor capability support
  2015-01-21 14:57 ` Martin Mares
@ 2015-01-21 15:16   ` Gerd Hoffmann
       [not found]   ` <1421853400.10966.4.camel@nilsson.home.kraxel.org>
  1 sibling, 0 replies; 4+ messages in thread
From: Gerd Hoffmann @ 2015-01-21 15:16 UTC (permalink / raw)
  To: Martin Mares; +Cc: virtio-dev, virtualization

On Mi, 2015-01-21 at 15:57 +0100, Martin Mares wrote:
> Hello!
> 
> > 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.
> 
> I like the patch, except for a couple of details:
> 
> (1) Please follow the coding style of the rest of pciutils.

I've tried.  What specifically doesn't match?

> (2) You assume that PCI_CAP_ID_VNDR of all Redhat devices contains virtio,
>     but the comment nearby refers to a range of device IDs only.

I'll add a check.  Doesn't matter today, there are no other redhat
devices with vendor caps, so I was a bit lazy.  But who knows what
happens in the future ...

> (3) Moving code related to vendor-defined caps to a separate file sounds
>     good, but I think we should push the boundary a bit further: let the
>     main switch in ls-caps.c call a function from ls-caps-vendor.c as soon
>     as it finds PCI_CAP_ID_VENDOR, leaving all decisions based on
>     vendor/device ID to this function.

Makes sense indeed, will do.

cheers,
  Gerd

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [pciutils patch] add virtio vendor capability support
       [not found]   ` <1421853400.10966.4.camel@nilsson.home.kraxel.org>
@ 2015-01-21 15:18     ` Martin Mares
  0 siblings, 0 replies; 4+ messages in thread
From: Martin Mares @ 2015-01-21 15:18 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: virtio-dev, virtualization

Hi!

> > (1) Please follow the coding style of the rest of pciutils.
> 
> I've tried.  What specifically doesn't match?

Positions of braces (e.g., after switch). But if you fix the other things,
I can re-indent the source myself.

				Martin

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-01-21 15:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-21 11:21 [pciutils patch] add virtio vendor capability support Gerd Hoffmann
2015-01-21 14:57 ` Martin Mares
2015-01-21 15:16   ` Gerd Hoffmann
     [not found]   ` <1421853400.10966.4.camel@nilsson.home.kraxel.org>
2015-01-21 15:18     ` Martin Mares

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.