Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 14 Jun 2010 03:34:22 -0400
From:      "Constantine A. Murenin" <cnst@FreeBSD.org>
To:        freebsd-acpi@FreeBSD.org, freebsd-drivers@FreeBSD.org
Cc:        Rui Paulo <rpaulo@FreeBSD.org>, "Constantine A. Murenin" <cnst@FreeBSD.org>
Subject:   Re: aibs(4): ASUSTeK AI Booster (ACPI ATK0110) Hardware Monitor
Message-ID:  <20100614073422.GA1155@hita.home.const.name>
In-Reply-To: <20100411.140047.527849116143353707.imp@bsdimp.com>
References:  <DE573364-A7A7-4805-BCBC-665AE0E13BA6@freebsd.org> <20100406.074313.364718154403381345.imp@bsdimp.com> <20100411192449.GA1367@dale.cnst.cs.uwaterloo.ca> <20100411.140047.527849116143353707.imp@bsdimp.com>

next in thread | previous in thread | raw e-mail | index | archive | help

--SUOF0GtieIMvvwua
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Disposition: inline

Dear freebsd-{acpi,drivers}@,

Per rpaulo@ (Rui Paulo) request, I'm reviving the thread with the 
reposting of a refreshed revision of the patch for further review.

Attached patch provides support for the hardware monitoring capabilities 
that are present in many modern desktop motherboards from ASUS featuring 
the ATK0110 ACPI device.

This driver, aibs(4), is a replacement for FreeBSD's existing acpi_aiboost(4).  
The new aibs(4) driver has the following advantages when compared to the old acpi_aiboost(4):  

* the supposed range specifications are now reported 
for each input that is being sensed 

* the nature of the new tree, with "volt", "temp" and "fan" subtrees, 
allows one to specifically query for the sensors of a certain type 

* the temperature sensors are exported in the temperature 'K' units through 
sysctl(9), such that they are pretty-printed by sysctl(8) automatically 

* more user documentation is provided 


It is expected that aibs(4) should replace any and all functionality 
previously provided by acpi_aiboost(4), provide additional features as 
specified above and decrease the size of both the source and the binary 
code.  Please find the demonstration below. 


> ll /usr/c/src/sys/dev/acpi_support/{acpi_aiboost,atk0110}.c
-rw-r--r--  1 constant  wheel  8919 Apr  3 20:31 /usr/c/src/sys/dev/acpi_support/acpi_aiboost.c
-rw-r--r--  1 constant  wheel  8304 Jun 14 02:19 /usr/c/src/sys/dev/acpi_support/atk0110.c
> ll /boot/kernel/*aib*s*
-r-xr-xr-x  1 root  wheel  11581 Jun 14 02:51 /boot/kernel/acpi_aiboost.ko
-r-xr-xr-x  1 root  wheel  24504 Jun 14 02:51 /boot/kernel/acpi_aiboost.ko.symbols
-r-xr-xr-x  1 root  wheel   9801 Jun 14 02:51 /boot/kernel/aibs.ko
-r-xr-xr-x  1 root  wheel  21203 Jun 14 02:51 /boot/kernel/aibs.ko.symbols

> sudo kldload acpi_aiboost.ko
> sysctl dev.acpi_aiboost.0
dev.acpi_aiboost.0.%desc: ASUStek AIBOOSTER
dev.acpi_aiboost.0.%driver: acpi_aiboost
dev.acpi_aiboost.0.%location: handle=\_SB_.PCI0.SBRG.ASOC
dev.acpi_aiboost.0.%pnpinfo: _HID=ATK0110 _UID=16843024
dev.acpi_aiboost.0.%parent: acpi0
dev.acpi_aiboost.0.temp0: 370
dev.acpi_aiboost.0.temp1: 580
dev.acpi_aiboost.0.volt0: 1232
dev.acpi_aiboost.0.volt1: 3312
dev.acpi_aiboost.0.volt2: 5017
dev.acpi_aiboost.0.volt3: 12302
dev.acpi_aiboost.0.fan0: 907
dev.acpi_aiboost.0.fan1: 0
> sysctl -d dev.acpi_aiboost.0
dev.acpi_aiboost.0:
dev.acpi_aiboost.0.%desc: device description
dev.acpi_aiboost.0.%driver: device driver name
dev.acpi_aiboost.0.%location: device location relative to parent
dev.acpi_aiboost.0.%pnpinfo: device identification
dev.acpi_aiboost.0.%parent: parent device
dev.acpi_aiboost.0.temp0: CPU Temperature
dev.acpi_aiboost.0.temp1: MB Temperature
dev.acpi_aiboost.0.volt0: Vcore Voltage
dev.acpi_aiboost.0.volt1:  +3.3 Voltage
dev.acpi_aiboost.0.volt2:  +5 Voltage
dev.acpi_aiboost.0.volt3:  +12 Voltage
dev.acpi_aiboost.0.fan0: CPU FAN Speed
dev.acpi_aiboost.0.fan1: CHASSIS FAN Speed
> sudo kldunload acpi_aiboost.ko

> sudo kldload aibs.ko
0.021u 1.012s 0:01.06 97.1%     2+68k 1+0io 0pf+0w
> sysctl dev.aibs.0.{volt,temp,fan}
dev.aibs.0.volt.0: 1232 850 1600
dev.aibs.0.volt.1: 3312 2970 3630
dev.aibs.0.volt.2: 5017 4500 5500
dev.aibs.0.volt.3: 12302 10200 13800
dev.aibs.0.temp.0: 38.0C 80.0C 95.0C
dev.aibs.0.temp.1: 58.0C 60.0C 95.0C
dev.aibs.0.fan.0: 902 600 7200
dev.aibs.0.fan.1: 0 700 7200
> sysctl -d dev.aibs.0.{volt,temp,fan}
dev.aibs.0.volt:
dev.aibs.0.volt.0: Vcore Voltage
dev.aibs.0.volt.1:  +3.3 Voltage
dev.aibs.0.volt.2:  +5 Voltage
dev.aibs.0.volt.3:  +12 Voltage
dev.aibs.0.temp:
dev.aibs.0.temp.0: CPU Temperature
dev.aibs.0.temp.1: MB Temperature
dev.aibs.0.fan:
dev.aibs.0.fan.0: CPU FAN Speed
dev.aibs.0.fan.1: CHASSIS FAN Speed
> sudo kldunload aibs.ko
 

Best regards,
Constantine.SU.

--SUOF0GtieIMvvwua
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline;
	filename="svn_diff.aibs.r0.2010-06-14T021919-0400.dev.patch"

Index: share/man/man4/aibs.4
===================================================================
--- share/man/man4/aibs.4	(revision 0)
+++ share/man/man4/aibs.4	(revision 0)
@@ -0,0 +1,209 @@
+.\"	$FreeBSD$
+.\"	$NetBSD: aibs.4,v 1.2 2010/02/09 05:37:25 cnst Exp $
+.\"	$OpenBSD: aibs.4,v 1.4 2009/07/30 06:30:45 jmc Exp $
+.\"
+.\" Copyright (c) 2009/2010 Constantine A. Murenin <cnst++@FreeBSD.org>
+.\"
+.\" Permission to use, copy, modify, and distribute this software for any
+.\" purpose with or without fee is hereby granted, provided that the above
+.\" copyright notice and this permission notice appear in all copies.
+.\"
+.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+.\"
+.Dd April 4, 2010
+.Dt AIBS 4
+.Os
+.Sh NAME
+.Nm aibs
+.Nd "ASUSTeK AI Booster ACPI ATK0110 voltage, temperature and fan sensor"
+.Sh SYNOPSIS
+To compile this driver into the kernel,
+place the following lines in your
+kernel configuration file:
+.Bd -ragged -offset indent
+.Cd "device acpi"
+.Cd "device aibs"
+.Ed
+.Pp
+Alternatively, to load the driver as a
+module at boot time, place the following lines in
+.Xr loader.conf 5 :
+.Bd -literal -offset indent
+acpi_load="YES"
+aibs_load="YES"
+.Ed
+.Sh DESCRIPTION
+The
+.Nm
+driver provides support for the voltage, temperature and fan sensors
+available through the
+.Tn ATK0110
+.Tn ASOC
+.Tn ACPI
+device
+on
+.Tn ASUSTeK
+motherboards.
+The number of sensors of each type,
+as well as the description of each sensor,
+varies according to the motherboard.
+.Pp
+The driver supports an arbitrary set of sensors,
+provides descriptions regarding what each sensor is used for,
+and reports the current values as well as
+the supposed range specifications of each sensor's input
+as defined by the motherboard manufacturer through
+.Tn ACPI .
+.Pp
+The range specifications are as follows:
+.Bl -bullet
+.It
+Voltage sensors have a lower and an upper range specification.
+.It
+Temperature sensors have two upper specifications.
+.It
+Fan sensors may either have only the lower specification,
+or, depending on the
+.Tn DSDT ,
+one lower and one upper specification.
+.El
+.Pp
+Sensor readings and the range specifications are made available through the
+.Xr sysctl 3
+interface,
+and can be monitored with
+.Xr sysctl 8 .
+For example, on an ASUS V3-P5G965 barebone:
+.Bd -literal -offset indent
+> sysctl dev.aibs.0.{volt,temp,fan}
+dev.aibs.0.volt.0: 1192 850 1600
+dev.aibs.0.volt.1: 3312 2970 3630
+dev.aibs.0.volt.2: 5017 4500 5500
+dev.aibs.0.volt.3: 12302 10200 13800
+dev.aibs.0.temp.0: 28.0C 80.0C 95.0C
+dev.aibs.0.temp.1: 55.0C 60.0C 95.0C
+dev.aibs.0.fan.0: 878 600 7200
+dev.aibs.0.fan.1: 0 700 7200
+.Pp
+> sysctl -d dev.aibs.0.{volt,temp,fan}
+dev.aibs.0.volt: 
+dev.aibs.0.volt.0: Vcore Voltage
+dev.aibs.0.volt.1:  +3.3 Voltage
+dev.aibs.0.volt.2:  +5 Voltage
+dev.aibs.0.volt.3:  +12 Voltage
+dev.aibs.0.temp: 
+dev.aibs.0.temp.0: CPU Temperature
+dev.aibs.0.temp.1: MB Temperature
+dev.aibs.0.fan: 
+dev.aibs.0.fan.0: CPU FAN Speed
+dev.aibs.0.fan.1: CHASSIS FAN Speed
+.Ed
+.Pp
+Generally, sensors provided by the
+.Nm
+driver may also be supported by certain other drivers or utilities
+that access the
+.Tn ISA /
+.Tn LPC
+or
+.Tn I2C /
+.Tn SMBus
+devices directly.
+The precise collection of
+.Nm
+sensors is comprised of the sensors
+specifically utilised in the motherboard
+design, which may be supported through
+a combination of one or more physical hardware monitoring chips.
+.Pp
+The
+.Nm
+driver, however, provides the following advantages
+when compared to the native hardware monitoring drivers or other utilities:
+.Bl -bullet
+.It
+Sensor values from
+.Nm
+are expected to be more reliable.
+For example, voltage sensors in many hardware monitoring chips
+can only sense voltage from 0 to 2 or 4 volts, and the excessive
+voltage is removed by the resistors, which may vary with the motherboard
+and with the voltage that is being sensed.
+In
+.Nm ,
+the required resistor factors are provided by
+the motherboard manufacturer through
+.Tn ACPI ;
+in the native drivers, the resistor factors
+are encoded into the driver based on the chip manufacturer's recommendations.
+In essence, sensor values from
+.Nm
+are very likely to be identical to the readings from the
+Hardware Monitor screen in the BIOS.
+.It
+Sensor descriptions from
+.Nm
+are more likely to match the markings on the motherboard.
+.It
+Sensor range specifications are supported by
+.Nm .
+The range specification is reported
+for each individual sensor as suggested by the motherboard manufacturer.
+For example, the threshold for the CPU temperature sensor is likely
+to be significantly higher than that for the chassis temperature sensor.
+.It
+Support for newer chips in
+.Nm .
+Newer chips may miss a native driver,
+but should be supported through
+.Nm
+regardless.
+.El
+.Sh SEE ALSO
+.Xr sysctl 3 ,
+.Xr acpi 4 ,
+.Xr sysctl 8
+.Sh HISTORY
+The
+.Nm
+driver first appeared in
+.Ox 4.7 ,
+.Dx 2.5 ,
+.Nx 6.0
+and
+.Fx 9.0 .
+.Pp
+An earlier version of the driver,
+.Nm acpi_aiboost ,
+first appeared in
+.Fx 7.0
+and
+.Nx 5.0 .
+.Sh AUTHORS
+.An -nosplit
+The
+.Nm
+driver was written for
+.Ox ,
+.Dx ,
+.Nx
+and
+.Fx
+by
+.An Constantine A. Murenin Aq cnst@FreeBSD.org ,
+Raouf Boutaba Research Group,
+David R. Cheriton School of Computer Science,
+University of Waterloo.
+.Pp
+An earlier version of the driver, named
+.Nm acpi_aiboost ,
+was written for
+.Fx
+by
+.An Takanori Watanabe .
Index: share/man/man4/Makefile
===================================================================
--- share/man/man4/Makefile	(revision 209152)
+++ share/man/man4/Makefile	(working copy)
@@ -26,6 +26,7 @@
 	ahc.4 \
 	ahci.4 \
 	ahd.4 \
+	${_aibs.4} \
 	aio.4 \
 	alc.4 \
 	ale.4 \
@@ -633,6 +634,7 @@
 _acpi_sony.4=	acpi_sony.4
 _acpi_toshiba.4=acpi_toshiba.4
 _acpi_wmi.4=	acpi_wmi.4
+_aibs.4=	aibs.4
 _amdsbwd.4=	amdsbwd.4
 _amdsmb.4=	amdsmb.4
 _amdtemp.4=	amdtemp.4
Index: sys/conf/files
===================================================================
--- sys/conf/files	(revision 209152)
+++ sys/conf/files	(working copy)
@@ -436,6 +436,7 @@
 dev/acpi_support/acpi_panasonic.c optional acpi_panasonic acpi
 dev/acpi_support/acpi_sony.c	optional acpi_sony acpi
 dev/acpi_support/acpi_toshiba.c	optional acpi_toshiba acpi
+dev/acpi_support/atk0110.c	optional aibs acpi
 dev/acpica/Osd/OsdDebug.c	optional acpi
 dev/acpica/Osd/OsdHardware.c	optional acpi
 dev/acpica/Osd/OsdInterrupt.c	optional acpi
Index: sys/modules/acpi/Makefile
===================================================================
--- sys/modules/acpi/Makefile	(revision 209152)
+++ sys/modules/acpi/Makefile	(working copy)
@@ -6,6 +6,6 @@
 
 SUBDIR+=	acpi_aiboost acpi_asus acpi_fujitsu acpi_hp acpi_ibm	\
 		acpi_panasonic acpi_sony acpi_toshiba acpi_video	\
-		acpi_dock acpi_wmi 
+		acpi_dock acpi_wmi aibs
 
 .include <bsd.subdir.mk>
Index: sys/modules/acpi/aibs/Makefile
===================================================================
--- sys/modules/acpi/aibs/Makefile	(revision 0)
+++ sys/modules/acpi/aibs/Makefile	(revision 0)
@@ -0,0 +1,10 @@
+# $FreeBSD$
+
+.PATH:		${.CURDIR}/../../../dev/acpi_support
+
+KMOD=		aibs
+SRCS=		atk0110.c
+SRCS+=		opt_acpi.h acpi_if.h bus_if.h device_if.h
+SRCS+=		opt_ddb.h
+
+.include <bsd.kmod.mk>
Index: sys/dev/acpi_support/atk0110.c
===================================================================
--- sys/dev/acpi_support/atk0110.c	(revision 0)
+++ sys/dev/acpi_support/atk0110.c	(revision 0)
@@ -0,0 +1,359 @@
+/*	$FreeBSD$	*/
+/*	$NetBSD: atk0110.c,v 1.4 2010/02/11 06:54:57 cnst Exp $	*/
+/*	$OpenBSD: atk0110.c,v 1.1 2009/07/23 01:38:16 cnst Exp $	*/
+
+/*
+ * Copyright (c) 2009/2010 Constantine A. Murenin <cnst++@FreeBSD.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <machine/_inttypes.h>
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/bus.h>
+#include <sys/module.h>
+#include <sys/malloc.h>
+#include <sys/sysctl.h>
+
+#include <contrib/dev/acpica/include/acpi.h>
+#include <dev/acpica/acpivar.h>
+
+/*
+ * ASUSTeK AI Booster (ACPI ASOC ATK0110).
+ *
+ * This code was originally written for OpenBSD after the techniques
+ * described in the Linux's asus_atk0110.c and FreeBSD's Takanori Watanabe's
+ * acpi_aiboost.c were verified to be accurate on the actual hardware kindly
+ * provided by Sam Fourman Jr.  It was subsequently ported from OpenBSD to
+ * DragonFly BSD, to NetBSD's sysmon_envsys(9) and to FreeBSD's sysctl(9).
+ *
+ *				  -- Constantine A. Murenin <http://cnst.su/>;
+ */
+
+#define _COMPONENT	ACPI_OEM
+ACPI_MODULE_NAME("aibs");
+ACPI_SERIAL_DECL(aibs, "aibs");
+
+#define AIBS_MORE_SENSORS
+#define AIBS_VERBOSE
+
+enum aibs_type {
+	AIBS_VOLT,
+	AIBS_TEMP,
+	AIBS_FAN
+};
+
+struct aibs_sensor {
+	ACPI_INTEGER	v;
+	ACPI_INTEGER	i;
+	ACPI_INTEGER	l;
+	ACPI_INTEGER	h;
+	enum aibs_type	t;
+};
+
+struct aibs_softc {
+	struct device		*sc_dev;
+	ACPI_HANDLE		sc_ah;
+
+	struct aibs_sensor	*sc_asens_volt;
+	struct aibs_sensor	*sc_asens_temp;
+	struct aibs_sensor	*sc_asens_fan;
+};
+
+static int aibs_probe(device_t);
+static int aibs_attach(device_t);
+static int aibs_detach(device_t);
+static int aibs_sysctl(SYSCTL_HANDLER_ARGS);
+
+static void aibs_attach_sif(struct aibs_softc *, enum aibs_type);
+
+static device_method_t aibs_methods[] = {
+	DEVMETHOD(device_probe,		aibs_probe),
+	DEVMETHOD(device_attach,	aibs_attach),
+	DEVMETHOD(device_detach,	aibs_detach),
+	{ NULL, NULL }
+};
+
+static driver_t aibs_driver = {
+	"aibs",
+	aibs_methods,
+	sizeof(struct aibs_softc)
+};
+
+static devclass_t aibs_devclass;
+
+DRIVER_MODULE(aibs, acpi, aibs_driver, aibs_devclass, NULL, NULL);
+
+
+static char* aibs_hids[] = {
+	"ATK0110",
+	NULL
+};
+
+static int
+aibs_probe(device_t dev)
+{
+	if (acpi_disabled("aibs") ||
+	    ACPI_ID_PROBE(device_get_parent(dev), dev, aibs_hids) == NULL)
+		return ENXIO;
+
+	device_set_desc(dev, "ASUSTeK AI Booster (ACPI ASOC ATK0110)");
+	return 0;
+}
+
+static int
+aibs_attach(device_t dev)
+{
+	struct aibs_softc *sc = device_get_softc(dev);
+
+	sc->sc_dev = dev;
+	sc->sc_ah = acpi_get_handle(dev);
+
+	aibs_attach_sif(sc, AIBS_VOLT);
+	aibs_attach_sif(sc, AIBS_TEMP);
+	aibs_attach_sif(sc, AIBS_FAN);
+
+	return 0;
+}
+
+static void
+aibs_attach_sif(struct aibs_softc *sc, enum aibs_type st)
+{
+	ACPI_STATUS		s;
+	ACPI_BUFFER		b;
+	ACPI_OBJECT		*bp, *o;
+	int			i, n;
+	const char		*node;
+	char			name[] = "?SIF";
+	struct aibs_sensor	*as;
+	struct sysctl_oid	*so;
+
+	switch (st) {
+	case AIBS_VOLT:
+		node = "volt";
+		name[0] = 'V';
+		break;
+	case AIBS_TEMP:
+		node = "temp";
+		name[0] = 'T';
+		break;
+	case AIBS_FAN:
+		node = "fan";
+		name[0] = 'F';
+		break;
+	default:
+		return;
+	}
+
+	b.Length = ACPI_ALLOCATE_BUFFER;
+	s = AcpiEvaluateObjectTyped(sc->sc_ah, name, NULL, &b,
+	    ACPI_TYPE_PACKAGE);
+	if (ACPI_FAILURE(s)) {
+		device_printf(sc->sc_dev, "%s not found\n", name);
+		return;
+	}
+
+	bp = b.Pointer;
+	o = bp->Package.Elements;
+	if (o[0].Type != ACPI_TYPE_INTEGER) {
+		device_printf(sc->sc_dev, "%s[0]: invalid type\n", name);
+		AcpiOsFree(b.Pointer);
+		return;
+	}
+
+	n = o[0].Integer.Value;
+	if (bp->Package.Count - 1 < n) {
+		device_printf(sc->sc_dev, "%s: invalid package\n", name);
+		AcpiOsFree(b.Pointer);
+		return;
+	} else if (bp->Package.Count - 1 > n) {
+		int on = n;
+
+#ifdef AIBS_MORE_SENSORS
+		n = bp->Package.Count - 1;
+#endif
+		device_printf(sc->sc_dev, "%s: malformed package: %i/%i"
+		    ", assume %i\n", name, on, bp->Package.Count - 1, n);
+	}
+	if (n < 1) {
+		device_printf(sc->sc_dev, "%s: no members in the package\n",
+		    name);
+		AcpiOsFree(b.Pointer);
+		return;
+	}
+
+	as = malloc(sizeof(*as) * n, M_DEVBUF, M_NOWAIT | M_ZERO);
+	if (as == NULL) {
+		device_printf(sc->sc_dev, "%s: malloc fail\n", name);
+		AcpiOsFree(b.Pointer);
+		return;
+	}
+	switch (st) {
+	case AIBS_VOLT:
+		sc->sc_asens_volt = as;
+		break;
+	case AIBS_TEMP:
+		sc->sc_asens_temp = as;
+		break;
+	case AIBS_FAN:
+		sc->sc_asens_fan = as;
+		break;
+	}
+
+	/* sysctl subtree for sensors of this type */
+	so = SYSCTL_ADD_NODE(device_get_sysctl_ctx(sc->sc_dev),
+	    SYSCTL_CHILDREN(device_get_sysctl_tree(sc->sc_dev)), st,
+	    node, CTLFLAG_RD, NULL, NULL);
+
+	for (i = 0, o++; i < n; i++, o++) {
+		ACPI_OBJECT	*oi;
+		char		si[3];
+		const char	*desc;
+
+		/* acpica5 automatically evaluates the referenced package */
+		if (o[0].Type != ACPI_TYPE_PACKAGE) {
+			device_printf(sc->sc_dev,
+			    "%s: %i: not a package: %i type\n",
+			    name, i, o[0].Type);
+			continue;
+		}
+		oi = o[0].Package.Elements;
+		if (o[0].Package.Count != 5 ||
+		    oi[0].Type != ACPI_TYPE_INTEGER ||
+		    oi[1].Type != ACPI_TYPE_STRING ||
+		    oi[2].Type != ACPI_TYPE_INTEGER ||
+		    oi[3].Type != ACPI_TYPE_INTEGER ||
+		    oi[4].Type != ACPI_TYPE_INTEGER) {
+			device_printf(sc->sc_dev,
+			    "%s: %i: invalid package\n",
+			    name, i);
+			continue;
+		}
+		as[i].i = oi[0].Integer.Value;
+		desc = oi[1].String.Pointer;
+		as[i].l = oi[2].Integer.Value;
+		as[i].h = oi[3].Integer.Value;
+		as[i].t = st;
+#ifdef AIBS_VERBOSE
+		device_printf(sc->sc_dev, "%c%i: "
+		    "0x%08"PRIx64" %20s %5"PRIi64" / %5"PRIi64"  "
+		    "0x%"PRIx64"\n",
+		    name[0], i,
+		    as[i].i, desc, (int64_t)as[i].l, (int64_t)as[i].h,
+		    oi[4].Integer.Value);
+#endif
+		snprintf(si, sizeof(si), "%i", i);
+		SYSCTL_ADD_PROC(device_get_sysctl_ctx(sc->sc_dev),
+		    SYSCTL_CHILDREN(so), i, si, CTLTYPE_OPAQUE | CTLFLAG_RD,
+		    sc, st, aibs_sysctl, st == AIBS_TEMP ? "IK" : "I", desc);
+	}
+
+	AcpiOsFree(b.Pointer);
+}
+
+static int
+aibs_detach(device_t dev)
+{
+	struct aibs_softc	*sc = device_get_softc(dev);
+
+	if (sc->sc_asens_volt != NULL)
+		free(sc->sc_asens_volt, M_DEVBUF);
+	if (sc->sc_asens_temp != NULL)
+		free(sc->sc_asens_temp, M_DEVBUF);
+	if (sc->sc_asens_fan != NULL)
+		free(sc->sc_asens_fan, M_DEVBUF);
+	return 0;
+}
+
+#ifdef AIBS_VERBOSE
+#define ddevice_printf(x...) device_printf(x)
+#else
+#define ddevice_printf(x...)
+#endif
+
+static int
+aibs_sysctl(SYSCTL_HANDLER_ARGS)
+{
+	struct aibs_softc	*sc = arg1;
+	enum aibs_type		st = arg2;
+	int			i = oidp->oid_number;
+	ACPI_STATUS		rs;
+	ACPI_OBJECT		p, *bp;
+	ACPI_OBJECT_LIST	mp;
+	ACPI_BUFFER		b;
+	char			*name;
+	struct aibs_sensor	*as;
+	ACPI_INTEGER		v, l, h;
+	int			so[3];
+
+	switch (st) {
+	case AIBS_VOLT:
+		name = "RVLT";
+		as = sc->sc_asens_volt;
+		break;
+	case AIBS_TEMP:
+		name = "RTMP";
+		as = sc->sc_asens_temp;
+		break;
+	case AIBS_FAN:
+		name = "RFAN";
+		as = sc->sc_asens_fan;
+		break;
+	default:
+		return ENOENT;
+	}
+	if (as == NULL)
+		return ENOENT;
+	l = as[i].l;
+	h = as[i].h;
+	p.Type = ACPI_TYPE_INTEGER;
+	p.Integer.Value = as[i].i;
+	mp.Count = 1;
+	mp.Pointer = &p;
+	b.Length = ACPI_ALLOCATE_BUFFER;
+	ACPI_SERIAL_BEGIN(aibs);
+	rs = AcpiEvaluateObjectTyped(sc->sc_ah, name, &mp, &b,
+	    ACPI_TYPE_INTEGER);
+	if (ACPI_FAILURE(rs)) {
+		ddevice_printf(sc->sc_dev,
+		    "%s: %i: evaluation failed\n",
+		    name, i);
+		ACPI_SERIAL_END(aibs);
+		return EIO;
+	}
+	bp = b.Pointer;
+	v = bp->Integer.Value;
+	AcpiOsFree(b.Pointer);
+	ACPI_SERIAL_END(aibs);
+
+	switch (st) {
+	case AIBS_VOLT:
+		break;
+	case AIBS_TEMP:
+		v += 2732;
+		l += 2732;
+		h += 2732;
+		break;
+	case AIBS_FAN:
+		break;
+	}
+	so[0] = v;
+	so[1] = l;
+	so[2] = h;
+	return sysctl_handle_opaque(oidp, &so, sizeof(so), req);
+}
Index: sys/i386/conf/NOTES
===================================================================
--- sys/i386/conf/NOTES	(revision 209152)
+++ sys/i386/conf/NOTES	(working copy)
@@ -506,6 +506,9 @@
 # ACPI Docking Station
 device		acpi_dock
 
+# ACPI ASOC ATK0110 ASUSTeK AI Booster (voltage, temperature and fan sensors)
+device		aibs
+
 # The cpufreq(4) driver provides support for non-ACPI CPU frequency control
 device		cpufreq
 

--SUOF0GtieIMvvwua--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100614073422.GA1155>