From 39b96fa477a6a0950b6e72949e818de4ab183d65 Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Mon, 14 Apr 2008 15:27:59 +0000 Subject: [PATCH] Add support for virtual hwmon devices. This closes Red Hat bug #437637 and ticket #2305. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@5176 7894878c-1315-0410-8ee3-d5d059ff63e0 --- CHANGES | 1 + doc/libsensors-API.txt | 14 ++++++++++++++ lib/access.c | 2 ++ lib/data.c | 5 +++++ lib/sensors.h | 3 ++- lib/sysfs.c | 32 +++++++++++++++++++++++--------- 6 files changed, 47 insertions(+), 10 deletions(-) create mode 100644 doc/libsensors-API.txt diff --git a/CHANGES b/CHANGES index bcd9fcef..f3ff016b 100644 --- a/CHANGES +++ b/CHANGES @@ -5,6 +5,7 @@ SVN-HEAD libsensors: Use __func__ instead of __FUNCTION__ Parse the configuration file in C locale Late compute statements override early ones + Support virtual hwmon devices (#2309) sensors-detect: Add SMSC SCH5027D detection Do not access I/O ports on PPC Move south bridge sensor detection to the right section diff --git a/doc/libsensors-API.txt b/doc/libsensors-API.txt new file mode 100644 index 00000000..49da35e5 --- /dev/null +++ b/doc/libsensors-API.txt @@ -0,0 +1,14 @@ +libsensors API history +====================== + +SENSORS_API_VERSION tracks the evolutions made to the libsensors API +over time. This document summarizes these evolutions so that application +authors can quickly figure out how to test for the availability of a +given new feature. + +0x401 lm-sensors SVN +* Added bus type "virtual": + #define SENSORS_BUS_TYPE_VIRTUAL 4 + +0x400 lm-sensors 3.0.0 to 3.0.1 +* Initial API. diff --git a/lib/access.c b/lib/access.c index ef1e6a55..6fc24472 100644 --- a/lib/access.c +++ b/lib/access.c @@ -347,6 +347,8 @@ const char *sensors_get_adapter_name(const sensors_bus_id *bus) so we don't have any custom string to return. */ case SENSORS_BUS_TYPE_SPI: return "SPI adapter"; + case SENSORS_BUS_TYPE_VIRTUAL: + return "Virtual device"; } /* bus types with several instances */ diff --git a/lib/data.c b/lib/data.c index 4556f3a1..bd69daf6 100644 --- a/lib/data.c +++ b/lib/data.c @@ -109,6 +109,8 @@ int sensors_parse_chip_name(const char *name, sensors_chip_name *res) res->bus.type = SENSORS_BUS_TYPE_PCI; else if (!strncmp(name, "spi", dash - name)) res->bus.type = SENSORS_BUS_TYPE_SPI; + else if (!strncmp(name, "virtual", dash - name)) + res->bus.type = SENSORS_BUS_TYPE_VIRTUAL; else goto ERROR; name = dash + 1; @@ -169,6 +171,9 @@ int sensors_snprintf_chip_name(char *str, size_t size, case SENSORS_BUS_TYPE_SPI: return snprintf(str, size, "%s-spi-%hd-%x", chip->prefix, chip->bus.nr, chip->addr); + case SENSORS_BUS_TYPE_VIRTUAL: + return snprintf(str, size, "%s-virtual-%x", chip->prefix, + chip->addr); } return -SENSORS_ERR_CHIP_NAME; diff --git a/lib/sensors.h b/lib/sensors.h index 50f51cc8..4dd246e0 100644 --- a/lib/sensors.h +++ b/lib/sensors.h @@ -31,7 +31,7 @@ when the API + ABI breaks), the third digit is incremented to track small API additions like new flags / enum values. The second digit is for tracking larger additions like new methods. */ -#define SENSORS_API_VERSION 0x400 +#define SENSORS_API_VERSION 0x401 #define SENSORS_CHIP_NAME_PREFIX_ANY NULL #define SENSORS_CHIP_NAME_ADDR_ANY -1 @@ -41,6 +41,7 @@ #define SENSORS_BUS_TYPE_ISA 1 #define SENSORS_BUS_TYPE_PCI 2 #define SENSORS_BUS_TYPE_SPI 3 +#define SENSORS_BUS_TYPE_VIRTUAL 4 #define SENSORS_BUS_NR_ANY (-1) #define SENSORS_BUS_NR_IGNORE (-2) diff --git a/lib/sysfs.c b/lib/sysfs.c index 96f55dc7..949d32e0 100644 --- a/lib/sysfs.c +++ b/lib/sysfs.c @@ -476,6 +476,15 @@ static int sensors_read_one_sysfs_chip(const char *dev_path, if (!entry.chip.path) sensors_fatal_error(__func__, "Out of memory"); + if (dev_path == NULL) { + /* Virtual device */ + entry.chip.bus.type = SENSORS_BUS_TYPE_VIRTUAL; + entry.chip.bus.nr = 0; + /* For now we assume that virtual devices are unique */ + entry.chip.addr = 0; + goto done; + } + /* Find bus type */ snprintf(linkpath, NAME_MAX, "%s/subsystem", dev_path); sub_len = readlink(linkpath, subsys_path, NAME_MAX - 1); @@ -545,6 +554,7 @@ static int sensors_read_one_sysfs_chip(const char *dev_path, goto exit_free; } +done: if (sensors_read_dynamic_chip(&entry, hwmon_path) < 0) goto exit_free; if (!entry.subfeature) { /* No subfeature, discard chip */ @@ -593,16 +603,20 @@ static int sensors_add_hwmon_device(const char *path, const char *classdev) snprintf(linkpath, NAME_MAX, "%s/device", path); dev_len = readlink(linkpath, device, NAME_MAX - 1); - if (dev_len < 0) - return -SENSORS_ERR_KERNEL; - device[dev_len] = '\0'; - device_p = strrchr(device, '/') + 1; + if (dev_len < 0) { + /* No device link? Treat as virtual */ + err = sensors_read_one_sysfs_chip(NULL, NULL, path); + } else { + device[dev_len] = '\0'; + device_p = strrchr(device, '/') + 1; - /* The attributes we want might be those of the hwmon class device, - or those of the device itself. */ - err = sensors_read_one_sysfs_chip(linkpath, device_p, path); - if (err == 0) - err = sensors_read_one_sysfs_chip(linkpath, device_p, linkpath); + /* The attributes we want might be those of the hwmon class + device, or those of the device itself. */ + err = sensors_read_one_sysfs_chip(linkpath, device_p, path); + if (err == 0) + err = sensors_read_one_sysfs_chip(linkpath, device_p, + linkpath); + } if (err < 0) return err; return 0;