diff mbox series

[pciutils,4/5] libpci: sysfs: Implement PROGIF, REVID and SUBSYS support

Message ID 20220121135718.27172-5-pali@kernel.org
State New
Headers show
Series Support for PROGIF, REVID and SUBSYS | expand

Commit Message

Pali Rohár Jan. 21, 2022, 1:57 p.m. UTC
In sysfs there are optional nodes with this information.
---
 lib/sysfs.c | 39 ++++++++++++++++++++++++++++++++++++---
 1 file changed, 36 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/lib/sysfs.c b/lib/sysfs.c
index 7c157a2688ad..7714607f66a0 100644
--- a/lib/sysfs.c
+++ b/lib/sysfs.c
@@ -329,6 +329,7 @@  static unsigned int
 sysfs_fill_info(struct pci_dev *d, unsigned int flags)
 {
   unsigned int done = 0;
+  int value;
 
   if (!d->access->buscentric)
     {
@@ -343,10 +344,42 @@  sysfs_fill_info(struct pci_dev *d, unsigned int flags)
 	  d->device_id = sysfs_get_value(d, "device", 1);
 	  done |= PCI_FILL_IDENT;
 	}
-      if (flags & PCI_FILL_CLASS)
+      if (flags & (PCI_FILL_CLASS | PCI_FILL_PROGIF))
 	{
-	  d->device_class = sysfs_get_value(d, "class", 1) >> 8;
-	  done |= PCI_FILL_CLASS;
+	  value = sysfs_get_value(d, "class", 1);
+	  if (flags & PCI_FILL_CLASS)
+	    {
+	      d->device_class = value >> 8;
+	      done |= PCI_FILL_CLASS;
+	    }
+	  if (flags & PCI_FILL_PROGIF)
+	    {
+	      d->prog_if = value & 0xff;
+	      done |= PCI_FILL_PROGIF;
+	    }
+	}
+      if (flags & PCI_FILL_REVID)
+	{
+	  value = sysfs_get_value(d, "revision", 0);
+	  if (value >= 0)
+	    {
+	      d->rev_id = value;
+	      done |= PCI_FILL_REVID;
+	    }
+        }
+      if (flags & PCI_FILL_SUBSYS)
+	{
+	  value = sysfs_get_value(d, "subsystem_vendor", 0);
+	  if (value >= 0)
+	    {
+	      d->subsys_vendor_id = value;
+	      value = sysfs_get_value(d, "subsystem_device", 0);
+	      if (value >= 0)
+	        {
+	          d->subsys_id = value;
+	          done |= PCI_FILL_SUBSYS;
+	        }
+	    }
 	}
       if (flags & PCI_FILL_IRQ)
 	{