Implement a loader tunable/sysctl to allow the user to request that

the APM driver byte-swap battery time values.  (For broken laptops.)

PR:		i386/42439
Submitted by:	Bruce M Simpson <bms@spc.org>
This commit is contained in:
Matthew N. Dodd 2003-06-22 05:08:10 +00:00
parent adef9265ef
commit c27e9c5100
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=116665

View File

@ -38,6 +38,7 @@ __FBSDID("$FreeBSD$");
#include <machine/apm_bios.h>
#include <machine/clock.h>
#include <machine/endian.h>
#include <machine/pc/bios.h>
#include <machine/cpufunc.h>
#include <machine/segments.h>
@ -119,6 +120,7 @@ static struct cdevsw apm_cdevsw = {
static int apm_suspend_delay = 1;
static int apm_standby_delay = 1;
static int apm_swab_batt_minutes = 0;
static int apm_debug = 0;
#define APM_DPRINT(args...) do { \
@ -131,6 +133,10 @@ SYSCTL_INT(_machdep, OID_AUTO, apm_suspend_delay, CTLFLAG_RW, &apm_suspend_delay
SYSCTL_INT(_machdep, OID_AUTO, apm_standby_delay, CTLFLAG_RW, &apm_standby_delay, 1, "");
SYSCTL_INT(_debug, OID_AUTO, apm_debug, CTLFLAG_RW, &apm_debug, 0, "");
TUNABLE_INT("machdep.apm_swab_batt_minutes", &apm_swab_batt_minutes);
SYSCTL_INT(_machdep, OID_AUTO, apm_swab_batt_minutes, CTLFLAG_RW,
&apm_swab_batt_minutes, 0, "Byte swap battery time value.");
#ifdef PC98
static __inline void
apm_enable_smm(sc)
@ -629,6 +635,8 @@ apm_get_pwstatus(apm_pwstatus_t app)
app->ap_batt_flag = (sc->bios.r.ecx >> 8) & 0xff;
app->ap_batt_life = sc->bios.r.ecx & 0xff;
sc->bios.r.edx &= 0xffff;
if (apm_swab_batt_minutes)
sc->bios.r.edx = __bswap16(sc->bios.r.edx) | 0x8000;
if (sc->bios.r.edx == 0xffff) /* Time is unknown */
app->ap_batt_time = -1;
else if (sc->bios.r.edx & 0x8000) /* Time is in minutes */