Blame SOURCES/0011-scan-PnP-devices-in-sysfs-691.patch

99c779
From 73707308d0c17fffdad2086686135c9cfd179a60 Mon Sep 17 00:00:00 2001
99c779
From: Dan Callaghan <dcallagh@redhat.com>
99c779
Date: Tue, 30 Jun 2015 16:08:22 +1000
99c779
Subject: [PATCH 11/26] scan PnP devices in sysfs (#691)
99c779
99c779
---
99c779
 src/core/Makefile |  4 ++--
99c779
 src/core/main.cc  |  4 ++++
99c779
 src/core/pnp.cc   | 41 +++++++++++++++++++++++++++++++++++++++++
99c779
 src/core/pnp.h    |  2 ++
99c779
 src/core/sysfs.cc | 14 ++++++++++++++
99c779
 src/core/sysfs.h  |  2 ++
99c779
 6 files changed, 65 insertions(+), 2 deletions(-)
99c779
99c779
diff --git a/src/core/Makefile b/src/core/Makefile
99c779
index 5bf5a69..92c34d4 100644
99c779
--- a/src/core/Makefile
99c779
+++ b/src/core/Makefile
99c779
@@ -37,7 +37,7 @@ hw.o: hw.h osutils.h version.h config.h options.h heuristics.h
99c779
 main.o: hw.h print.h version.h options.h mem.h dmi.h cpuinfo.h cpuid.h
99c779
 main.o: device-tree.h pci.h pcmcia.h pcmcia-legacy.h ide.h scsi.h spd.h
99c779
 main.o: network.h isapnp.h fb.h usb.h sysfs.h display.h parisc.h cpufreq.h
99c779
-main.o: ideraid.h mounts.h smp.h abi.h dasd.h virtio.h
99c779
+main.o: ideraid.h mounts.h smp.h abi.h dasd.h virtio.h pnp.h
99c779
 print.o: print.h hw.h options.h version.h osutils.h config.h
99c779
 mem.o: version.h config.h mem.h hw.h
99c779
 dmi.o: version.h config.h dmi.h hw.h osutils.h
99c779
@@ -56,7 +56,7 @@ spd.o: version.h spd.h hw.h osutils.h
99c779
 network.o: version.h config.h network.h hw.h osutils.h sysfs.h options.h
99c779
 network.o: heuristics.h
99c779
 isapnp.o: version.h isapnp.h hw.h pnp.h
99c779
-pnp.o: version.h pnp.h hw.h
99c779
+pnp.o: version.h pnp.h hw.h sysfs.h
99c779
 fb.o: version.h fb.h hw.h
99c779
 options.o: version.h options.h osutils.h
99c779
 usb.o: version.h usb.h hw.h osutils.h heuristics.h options.h
99c779
diff --git a/src/core/main.cc b/src/core/main.cc
99c779
index 03848da..7008933 100644
99c779
--- a/src/core/main.cc
99c779
+++ b/src/core/main.cc
99c779
@@ -32,6 +32,7 @@
99c779
 #include "spd.h"
99c779
 #include "network.h"
99c779
 #include "isapnp.h"
99c779
+#include "pnp.h"
99c779
 #include "fb.h"
99c779
 #include "usb.h"
99c779
 #include "sysfs.h"
99c779
@@ -101,6 +102,9 @@ bool scan_system(hwNode & system)
99c779
     status("ISA PnP");
99c779
     if (enabled("isapnp"))
99c779
       scan_isapnp(computer);
99c779
+    status("PnP (sysfs)");
99c779
+    if (enabled("pnp"))
99c779
+      scan_pnp(computer);
99c779
     status("PCMCIA");
99c779
     if (enabled("pcmcia"))
99c779
       scan_pcmcia(computer);
99c779
diff --git a/src/core/pnp.cc b/src/core/pnp.cc
99c779
index 6f60a76..0e01f7a 100644
99c779
--- a/src/core/pnp.cc
99c779
+++ b/src/core/pnp.cc
99c779
@@ -8,6 +8,7 @@
99c779
  */
99c779
 #include "version.h"
99c779
 #include "pnp.h"
99c779
+#include "sysfs.h"
99c779
 
99c779
 #include <stdlib.h>
99c779
 #include <string.h>
99c779
@@ -149,3 +150,43 @@ hw::hwClass pnp_class(const string & pnpid)
99c779
 
99c779
   return hw::generic;
99c779
 }
99c779
+
99c779
+bool scan_pnp(hwNode & n)
99c779
+{
99c779
+  vector < sysfs::entry > entries = sysfs::entries_by_bus("pnp");
99c779
+
99c779
+  if (entries.empty())
99c779
+    return false;
99c779
+
99c779
+  hwNode *core = n.getChild("core");
99c779
+  if (!core)
99c779
+  {
99c779
+    n.addChild(hwNode("core", hw::bus));
99c779
+    core = n.getChild("core");
99c779
+  }
99c779
+
99c779
+  for (vector < sysfs::entry >::iterator it = entries.begin();
99c779
+      it != entries.end(); ++it)
99c779
+  {
99c779
+    const sysfs::entry & e = *it;
99c779
+
99c779
+    vector < string > pnpids = e.multiline_attr("id");
99c779
+    if (pnpids.empty())
99c779
+      continue;
99c779
+    // devices can report multiple PnP IDs, just pick the first
99c779
+    string pnpid = pnpids[0];
99c779
+
99c779
+    hwNode device("pnp" + e.name(), pnp_class(pnpid));
99c779
+    device.addCapability("pnp");
99c779
+    string driver = e.driver();
99c779
+    if (!driver.empty())
99c779
+      device.setConfig("driver", driver);
99c779
+    string vendor = vendorname(pnpid.c_str());
99c779
+    if (!vendor.empty())
99c779
+      device.setVendor(vendor);
99c779
+    device.claim();
99c779
+
99c779
+    core->addChild(device);
99c779
+  }
99c779
+  return true;
99c779
+}
99c779
diff --git a/src/core/pnp.h b/src/core/pnp.h
99c779
index 6406583..dfc5159 100644
99c779
--- a/src/core/pnp.h
99c779
+++ b/src/core/pnp.h
99c779
@@ -7,4 +7,6 @@
99c779
 const char * vendorname(const char * id);
99c779
 
99c779
 hw::hwClass pnp_class(const string & pnpid);
99c779
+
99c779
+bool scan_pnp(hwNode &);
99c779
 #endif
99c779
diff --git a/src/core/sysfs.cc b/src/core/sysfs.cc
99c779
index acc9d00..ed2c600 100644
99c779
--- a/src/core/sysfs.cc
99c779
+++ b/src/core/sysfs.cc
99c779
@@ -298,6 +298,20 @@ entry entry::parent() const
99c779
   return e;
99c779
 }
99c779
 
99c779
+string entry::string_attr(const string & name, const string & def) const
99c779
+{
99c779
+  return hw::strip(get_string(This->devpath + "/" + name, def));
99c779
+}
99c779
+
99c779
+
99c779
+vector < string > entry::multiline_attr(const string & name) const
99c779
+{
99c779
+  vector < string > lines;
99c779
+  loadfile(This->devpath + "/" + name, lines);
99c779
+  return lines;
99c779
+}
99c779
+
99c779
+
99c779
 string entry::modalias() const
99c779
 {
99c779
   return get_string(This->devpath+"/modalias");
99c779
diff --git a/src/core/sysfs.h b/src/core/sysfs.h
99c779
index a9dc573..7ceb395 100644
99c779
--- a/src/core/sysfs.h
99c779
+++ b/src/core/sysfs.h
99c779
@@ -27,6 +27,8 @@ namespace sysfs
99c779
       string modalias() const;
99c779
       entry parent() const;
99c779
       string name_in_class(const string &) const;
99c779
+      string string_attr(const string & name, const string & def = "") const;
99c779
+      vector < string > multiline_attr(const string & name) const;
99c779
 
99c779
       struct entry_i * This;
99c779
 
99c779
-- 
99c779
2.10.2
99c779