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