summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Yurchenko <grange@cvs.openbsd.org>2003-04-25 20:06:42 +0000
committerAlexander Yurchenko <grange@cvs.openbsd.org>2003-04-25 20:06:42 +0000
commit14f6abdffc727eeddbcea128909598e7ffd9dfaa (patch)
treef64f5fcf67a0dc9104dc5acaf1a39e9aa7262941
parent07cebfad56982a350f09156ba7ff86d3ed970c30 (diff)
sysctl front-end for the hardware monitoring sensors. This adds
new node hw.sensors; information from the sensors can be obtained via hw.sensors.n, where n is a sensor number. All values are read only for now. Documentation and back-end drivers are comming. Tested by henning@ and millert@. Four oks from henning@ and one from millert@.
-rw-r--r--sys/kern/kern_sysctl.c35
-rw-r--r--sys/sys/sensors.h51
-rw-r--r--sys/sys/sysctl.h6
3 files changed, 87 insertions, 5 deletions
diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c
index 977d730a384..338027df657 100644
--- a/sys/kern/kern_sysctl.c
+++ b/sys/kern/kern_sysctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_sysctl.c,v 1.79 2003/01/21 16:59:23 markus Exp $ */
+/* $OpenBSD: kern_sysctl.c,v 1.80 2003/04/25 20:06:41 grange Exp $ */
/* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */
/*-
@@ -65,6 +65,7 @@
#include <sys/namei.h>
#include <sys/exec.h>
#include <sys/mbuf.h>
+#include <sys/sensors.h>
#include <sys/mount.h>
#include <sys/syscallargs.h>
@@ -94,6 +95,7 @@ extern long numvnodes;
int sysctl_diskinit(int, struct proc *);
int sysctl_proc_args(int *, u_int, void *, size_t *, struct proc *);
int sysctl_intrcnt(int *, u_int, void *, size_t *);
+int sysctl_sensors(int *, u_int, void *, size_t *, void *, size_t);
/*
* Lock to avoid too many processes vslocking a large amount of memory
@@ -506,8 +508,8 @@ hw_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
extern char machine[], cpu_model[];
int err;
- /* all sysctl names at this level are terminal */
- if (namelen != 1)
+ /* all sysctl names at this level except sensors are terminal */
+ if (name[0] != HW_SENSORS && namelen != 1)
return (ENOTDIR); /* overloaded */
switch (name[0]) {
@@ -543,6 +545,9 @@ hw_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
disk_count * sizeof(struct diskstats)));
case HW_DISKCOUNT:
return (sysctl_rdint(oldp, oldlenp, newp, disk_count));
+ case HW_SENSORS:
+ return (sysctl_sensors(name + 1, namelen - 1, oldp, oldlenp,
+ newp, newlen));
default:
return (EOPNOTSUPP);
}
@@ -1489,3 +1494,27 @@ sysctl_intrcnt(int *name, u_int namelen, void *oldp, size_t *oldlenp)
return (EOPNOTSUPP);
}
}
+
+int nsensors = 0;
+struct sensors_head sensors = SLIST_HEAD_INITIALIZER(&sensors);
+
+int
+sysctl_sensors(int *name, u_int namelen, void *oldp, size_t *oldlenp,
+ void *newp, size_t newlen)
+{
+ struct sensor *s = NULL;
+ int num;
+
+ if (namelen != 1)
+ return (ENOTDIR);
+
+ num = name[0];
+ if (num >= nsensors)
+ return (ENXIO);
+
+ SLIST_FOREACH(s, &sensors, list)
+ if (s->num == num)
+ break;
+
+ return (sysctl_rdstruct(oldp, oldlenp, newp, s, sizeof(struct sensor)));
+}
diff --git a/sys/sys/sensors.h b/sys/sys/sensors.h
new file mode 100644
index 00000000000..8befdc92178
--- /dev/null
+++ b/sys/sys/sensors.h
@@ -0,0 +1,51 @@
+/* $OpenBSD: sensors.h,v 1.1 2003/04/25 20:06:41 grange Exp $ */
+
+/*
+ * Copyright (c) 2003 Alexander Yurchenko <grange@openbsd.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _SYS_SENSORS_H_
+#define _SYS_SENSORS_H_
+
+/* Sensor types */
+enum sensor_type {
+ SENSOR_TEMP, /* temperature */
+ SENSOR_FANRPM, /* fan revolution speed */
+ SENSOR_VOLTS_DC /* voltage */
+};
+
+/* Sensor data */
+struct sensor {
+ SLIST_ENTRY(sensor) list;
+ int num; /* sensor number */
+ char device[16]; /* device name */
+ enum sensor_type type; /* sensor type */
+ char desc[32]; /* sensor description */
+ int64_t value; /* current value */
+ u_int rfact; /* resistor factor */
+};
+
+SLIST_HEAD(sensors_head, sensor);
+
+#endif /* !_SYS_SENSORS_H_ */
diff --git a/sys/sys/sysctl.h b/sys/sys/sysctl.h
index 502d3b71b5d..7169a645390 100644
--- a/sys/sys/sysctl.h
+++ b/sys/sys/sysctl.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: sysctl.h,v 1.62 2003/01/21 16:59:23 markus Exp $ */
+/* $OpenBSD: sysctl.h,v 1.63 2003/04/25 20:06:41 grange Exp $ */
/* $NetBSD: sysctl.h,v 1.16 1996/04/09 20:55:36 cgd Exp $ */
/*
@@ -376,7 +376,8 @@ struct kinfo_proc {
#define HW_DISKNAMES 8 /* strings: disk drive names */
#define HW_DISKSTATS 9 /* struct: diskstats[] */
#define HW_DISKCOUNT 10 /* int: number of disks */
-#define HW_MAXID 11 /* number of valid hw ids */
+#define HW_SENSORS 11 /* node: hardware monitors */
+#define HW_MAXID 12 /* number of valid hw ids */
#define CTL_HW_NAMES { \
{ 0, 0 }, \
@@ -390,6 +391,7 @@ struct kinfo_proc {
{ "disknames", CTLTYPE_STRING }, \
{ "diskstats", CTLTYPE_STRUCT }, \
{ "diskcount", CTLTYPE_INT }, \
+ { "sensors", CTLTYPE_NODE}, \
}
/*