1994-10-01 02:56:21 +00:00
|
|
|
/*
|
1995-02-17 02:22:57 +00:00
|
|
|
* APM (Advanced Power Management) BIOS Device Driver
|
|
|
|
*
|
|
|
|
* Copyright (c) 1994 UKAI, Fumitoshi.
|
1997-01-06 06:02:03 +00:00
|
|
|
* Copyright (c) 1994-1995 by HOSOKAWA, Tatsumi <hosokawa@jp.FreeBSD.org>
|
1996-04-18 19:21:47 +00:00
|
|
|
* Copyright (c) 1996 Nate Williams <nate@FreeBSD.org>
|
1997-03-29 11:07:12 +00:00
|
|
|
* Copyright (c) 1997 Poul-Henning Kamp <phk@FreeBSD.org>
|
1994-10-01 02:56:21 +00:00
|
|
|
*
|
|
|
|
* This software may be used, modified, copied, and distributed, in
|
|
|
|
* both source and binary form provided that the above copyright and
|
1995-05-30 08:16:23 +00:00
|
|
|
* these terms are retained. Under no circumstances is the author
|
|
|
|
* responsible for the proper functioning of this software, nor does
|
|
|
|
* the author assume any responsibility for damages incurred with its
|
1994-10-01 02:56:21 +00:00
|
|
|
* use.
|
|
|
|
*
|
|
|
|
* Sep, 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD)
|
1994-10-01 05:13:37 +00:00
|
|
|
*
|
1999-06-01 18:17:50 +00:00
|
|
|
* $Id: apm.c,v 1.87 1999/05/30 16:52:01 phk Exp $
|
1994-10-01 02:56:21 +00:00
|
|
|
*/
|
|
|
|
|
1998-01-24 02:54:56 +00:00
|
|
|
#include "opt_devfs.h"
|
1999-05-06 01:07:03 +00:00
|
|
|
#include "opt_smp.h"
|
1998-01-24 02:54:56 +00:00
|
|
|
|
1994-10-01 02:56:21 +00:00
|
|
|
#include <sys/param.h>
|
Divorce "dev_t" from the "major|minor" bitmap, which is now called
udev_t in the kernel but still called dev_t in userland.
Provide functions to manipulate both types:
major() umajor()
minor() uminor()
makedev() umakedev()
dev2udev() udev2dev()
For now they're functions, they will become in-line functions
after one of the next two steps in this process.
Return major/minor/makedev to macro-hood for userland.
Register a name in cdevsw[] for the "filedescriptor" driver.
In the kernel the udev_t appears in places where we have the
major/minor number combination, (ie: a potential device: we
may not have the driver nor the device), like in inodes, vattr,
cdevsw registration and so on, whereas the dev_t appears where
we carry around a reference to a actual device.
In the future the cdevsw and the aliased-from vnode will be hung
directly from the dev_t, along with up to two softc pointers for
the device driver and a few houskeeping bits. This will essentially
replace the current "alias" check code (same buck, bigger bang).
A little stunt has been provided to try to catch places where the
wrong type is being used (dev_t vs udev_t), if you see something
not working, #undef DEVT_FASCIST in kern/kern_conf.c and see if
it makes a difference. If it does, please try to track it down
(many hands make light work) or at least try to reproduce it
as simply as possible, and describe how to do that.
Without DEVT_FASCIST I belive this patch is a no-op.
Stylistic/posixoid comments about the userland view of the <sys/*.h>
files welcome now, from userland they now contain the end result.
Next planned step: make all dev_t's refer to the same devsw[] which
means convert BLK's to CHR's at the perimeter of the vnodes and
other places where they enter the game (bootdev, mknod, sysctl).
1999-05-11 19:55:07 +00:00
|
|
|
#include <sys/systm.h>
|
1995-11-28 09:44:42 +00:00
|
|
|
#include <sys/conf.h>
|
1995-11-29 10:49:16 +00:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#ifdef DEVFS
|
|
|
|
#include <sys/devfsext.h>
|
|
|
|
#endif /*DEVFS*/
|
1997-01-07 15:36:34 +00:00
|
|
|
#include <sys/time.h>
|
1998-10-30 05:41:15 +00:00
|
|
|
#include <sys/reboot.h>
|
1999-04-16 21:22:55 +00:00
|
|
|
#include <sys/bus.h>
|
1994-10-01 02:56:21 +00:00
|
|
|
#include <machine/apm_bios.h>
|
|
|
|
#include <machine/segments.h>
|
1994-10-02 17:40:38 +00:00
|
|
|
#include <machine/clock.h>
|
1994-10-01 02:56:21 +00:00
|
|
|
#include <vm/vm.h>
|
1995-12-07 12:48:31 +00:00
|
|
|
#include <vm/vm_param.h>
|
|
|
|
#include <vm/pmap.h>
|
1994-10-01 02:56:21 +00:00
|
|
|
#include <sys/syslog.h>
|
1996-08-28 17:54:17 +00:00
|
|
|
#include <i386/apm/apm_setup.h>
|
1994-10-01 02:56:21 +00:00
|
|
|
|
1998-06-03 01:59:42 +00:00
|
|
|
#include <machine/psl.h>
|
|
|
|
#include <machine/vm86.h>
|
|
|
|
|
1999-05-06 01:07:03 +00:00
|
|
|
#ifdef SMP
|
|
|
|
#include <machine/smp.h>
|
|
|
|
#endif
|
|
|
|
|
1997-01-06 06:02:03 +00:00
|
|
|
static int apm_display __P((int newstate));
|
1997-11-12 04:12:51 +00:00
|
|
|
static int apm_int __P((u_long *eax, u_long *ebx, u_long *ecx, u_long *edx));
|
1995-12-22 13:08:27 +00:00
|
|
|
static void apm_resume __P((void));
|
1995-11-18 04:37:23 +00:00
|
|
|
|
1994-10-01 02:56:21 +00:00
|
|
|
/* static data */
|
1995-02-17 02:22:57 +00:00
|
|
|
struct apm_softc {
|
1996-03-19 16:56:56 +00:00
|
|
|
int initialized, active;
|
|
|
|
int always_halt_cpu, slow_idle_cpu;
|
|
|
|
int disabled, disengaged;
|
1995-02-17 02:22:57 +00:00
|
|
|
u_int minorversion, majorversion;
|
|
|
|
u_int cs32_base, cs16_base, ds_base;
|
1998-06-03 01:59:42 +00:00
|
|
|
u_int cs16_limit, cs32_limit, ds_limit;
|
1995-02-17 02:22:57 +00:00
|
|
|
u_int cs_entry;
|
|
|
|
u_int intversion;
|
|
|
|
struct apmhook sc_suspend;
|
|
|
|
struct apmhook sc_resume;
|
1996-03-28 14:29:52 +00:00
|
|
|
#ifdef DEVFS
|
1995-12-08 11:19:42 +00:00
|
|
|
void *sc_devfs_token;
|
1996-03-28 14:29:52 +00:00
|
|
|
#endif
|
1995-05-30 08:16:23 +00:00
|
|
|
};
|
1995-02-17 02:22:57 +00:00
|
|
|
|
1996-03-18 21:58:22 +00:00
|
|
|
static struct apm_softc apm_softc;
|
1995-12-22 13:08:27 +00:00
|
|
|
static struct apmhook *hook[NAPM_HOOK]; /* XXX */
|
1995-02-17 02:22:57 +00:00
|
|
|
|
1994-10-02 17:40:38 +00:00
|
|
|
#define is_enabled(foo) ((foo) ? "enabled" : "disabled")
|
|
|
|
|
1994-10-01 02:56:21 +00:00
|
|
|
/* Map version number to integer (keeps ordering of version numbers) */
|
|
|
|
#define INTVERSION(major, minor) ((major)*100 + (minor))
|
|
|
|
|
1997-09-21 21:33:10 +00:00
|
|
|
static struct callout_handle apm_timeout_ch =
|
|
|
|
CALLOUT_HANDLE_INITIALIZER(&apm_timeout_ch);
|
|
|
|
|
1994-10-01 02:56:21 +00:00
|
|
|
static timeout_t apm_timeout;
|
1995-12-08 11:19:42 +00:00
|
|
|
static d_open_t apmopen;
|
|
|
|
static d_close_t apmclose;
|
|
|
|
static d_ioctl_t apmioctl;
|
|
|
|
|
1995-11-28 09:44:42 +00:00
|
|
|
#define CDEV_MAJOR 39
|
1999-05-30 16:53:49 +00:00
|
|
|
static struct cdevsw apm_cdevsw = {
|
|
|
|
/* open */ apmopen,
|
|
|
|
/* close */ apmclose,
|
|
|
|
/* read */ noread,
|
|
|
|
/* write */ nowrite,
|
|
|
|
/* ioctl */ apmioctl,
|
|
|
|
/* stop */ nostop,
|
|
|
|
/* reset */ noreset,
|
|
|
|
/* devtotty */ nodevtotty,
|
|
|
|
/* poll */ nopoll,
|
|
|
|
/* mmap */ nommap,
|
|
|
|
/* strategy */ nostrategy,
|
|
|
|
/* name */ "apm",
|
|
|
|
/* parms */ noparms,
|
|
|
|
/* maj */ CDEV_MAJOR,
|
|
|
|
/* dump */ nodump,
|
|
|
|
/* psize */ nopsize,
|
|
|
|
/* flags */ 0,
|
|
|
|
/* maxio */ 0,
|
|
|
|
/* bmaj */ -1
|
|
|
|
};
|
1995-12-08 11:19:42 +00:00
|
|
|
|
1994-10-01 02:56:21 +00:00
|
|
|
/* setup APM GDT discriptors */
|
1995-05-30 08:16:23 +00:00
|
|
|
static void
|
1998-06-03 01:59:42 +00:00
|
|
|
setup_apm_gdt(u_int code32_base, u_int code16_base, u_int data_base, u_int code32_limit, u_int code16_limit, u_int data_limit)
|
1994-10-01 02:56:21 +00:00
|
|
|
{
|
1999-05-06 01:07:03 +00:00
|
|
|
#ifdef SMP
|
|
|
|
int x;
|
|
|
|
#endif
|
|
|
|
|
1994-10-01 02:56:21 +00:00
|
|
|
/* setup 32bit code segment */
|
|
|
|
gdt_segs[GAPMCODE32_SEL].ssd_base = code32_base;
|
1998-06-03 01:59:42 +00:00
|
|
|
gdt_segs[GAPMCODE32_SEL].ssd_limit = code32_limit;
|
1994-10-01 02:56:21 +00:00
|
|
|
|
|
|
|
/* setup 16bit code segment */
|
|
|
|
gdt_segs[GAPMCODE16_SEL].ssd_base = code16_base;
|
1998-06-03 01:59:42 +00:00
|
|
|
gdt_segs[GAPMCODE16_SEL].ssd_limit = code16_limit;
|
1994-10-01 02:56:21 +00:00
|
|
|
|
|
|
|
/* setup data segment */
|
|
|
|
gdt_segs[GAPMDATA_SEL ].ssd_base = data_base;
|
|
|
|
gdt_segs[GAPMDATA_SEL ].ssd_limit = data_limit;
|
|
|
|
|
|
|
|
/* reflect these changes on physical GDT */
|
1994-11-15 14:09:18 +00:00
|
|
|
ssdtosd(gdt_segs + GAPMCODE32_SEL, &gdt[GAPMCODE32_SEL].sd);
|
|
|
|
ssdtosd(gdt_segs + GAPMCODE16_SEL, &gdt[GAPMCODE16_SEL].sd);
|
|
|
|
ssdtosd(gdt_segs + GAPMDATA_SEL , &gdt[GAPMDATA_SEL ].sd);
|
1999-05-06 01:07:03 +00:00
|
|
|
|
|
|
|
#ifdef SMP
|
|
|
|
for (x = 1; x < NCPU; x++) {
|
|
|
|
gdt[x * NGDT + GAPMCODE32_SEL].sd = gdt[GAPMCODE32_SEL].sd;
|
|
|
|
gdt[x * NGDT + GAPMCODE16_SEL].sd = gdt[GAPMCODE16_SEL].sd;
|
|
|
|
gdt[x * NGDT + GAPMDATA_SEL ].sd = gdt[GAPMDATA_SEL ].sd;
|
|
|
|
}
|
|
|
|
#endif
|
1994-10-01 02:56:21 +00:00
|
|
|
}
|
|
|
|
|
1998-02-09 06:11:36 +00:00
|
|
|
/* 48bit far pointer. Do not staticize - used from apm_setup.s */
|
1997-03-29 11:07:12 +00:00
|
|
|
struct addr48 {
|
1994-10-01 02:56:21 +00:00
|
|
|
u_long offset;
|
|
|
|
u_short segment;
|
|
|
|
} apm_addr;
|
|
|
|
|
1995-12-22 13:08:27 +00:00
|
|
|
static int apm_errno;
|
1994-10-02 01:45:42 +00:00
|
|
|
|
1997-11-12 04:12:51 +00:00
|
|
|
static int
|
|
|
|
apm_int(u_long *eax, u_long *ebx, u_long *ecx, u_long *edx)
|
1994-10-02 01:45:42 +00:00
|
|
|
{
|
1997-03-29 11:07:12 +00:00
|
|
|
struct apm_bios_arg apa;
|
|
|
|
int cf;
|
|
|
|
|
|
|
|
apa.eax = *eax;
|
|
|
|
apa.ebx = *ebx;
|
|
|
|
apa.ecx = *ecx;
|
1997-11-12 04:12:51 +00:00
|
|
|
apa.edx = *edx;
|
1997-03-29 11:07:12 +00:00
|
|
|
cf = apm_bios_call(&apa);
|
|
|
|
*eax = apa.eax;
|
|
|
|
*ebx = apa.ebx;
|
|
|
|
*ecx = apa.ecx;
|
1997-11-12 04:12:51 +00:00
|
|
|
*edx = apa.edx;
|
1994-10-02 01:45:42 +00:00
|
|
|
apm_errno = ((*eax) >> 8) & 0xff;
|
|
|
|
return cf;
|
|
|
|
}
|
1994-10-01 02:56:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* enable/disable power management */
|
1995-05-30 08:16:23 +00:00
|
|
|
static int
|
1997-01-06 06:02:03 +00:00
|
|
|
apm_enable_disable_pm(int enable)
|
1994-10-01 02:56:21 +00:00
|
|
|
{
|
1997-01-06 06:02:03 +00:00
|
|
|
struct apm_softc *sc = &apm_softc;
|
|
|
|
|
1997-11-12 04:12:51 +00:00
|
|
|
u_long eax, ebx, ecx, edx;
|
1994-10-02 01:45:42 +00:00
|
|
|
|
1995-02-17 02:22:57 +00:00
|
|
|
eax = (APM_BIOS << 8) | APM_ENABLEDISABLEPM;
|
1994-10-01 02:56:21 +00:00
|
|
|
|
1997-01-06 06:02:03 +00:00
|
|
|
if (sc->intversion >= INTVERSION(1, 1))
|
1994-10-02 01:45:42 +00:00
|
|
|
ebx = PMDV_ALLDEV;
|
1997-01-06 06:02:03 +00:00
|
|
|
else
|
1994-10-02 01:45:42 +00:00
|
|
|
ebx = 0xffff; /* APM version 1.0 only */
|
|
|
|
ecx = enable;
|
1997-12-04 02:40:00 +00:00
|
|
|
edx = 0;
|
1997-11-12 04:12:51 +00:00
|
|
|
return apm_int(&eax, &ebx, &ecx, &edx);
|
1994-10-01 02:56:21 +00:00
|
|
|
}
|
|
|
|
|
1994-10-02 17:40:38 +00:00
|
|
|
static void
|
1997-03-29 11:07:12 +00:00
|
|
|
apm_driver_version(int version)
|
1994-10-02 17:40:38 +00:00
|
|
|
{
|
1997-11-12 04:12:51 +00:00
|
|
|
u_long eax, ebx, ecx, edx;
|
1994-10-02 17:40:38 +00:00
|
|
|
|
1997-03-29 11:07:12 +00:00
|
|
|
/* First try APM 1.2 */
|
1995-02-17 02:22:57 +00:00
|
|
|
eax = (APM_BIOS << 8) | APM_DRVVERSION;
|
1994-10-02 17:40:38 +00:00
|
|
|
ebx = 0x0;
|
1997-03-29 11:07:12 +00:00
|
|
|
ecx = version;
|
1997-12-04 02:40:00 +00:00
|
|
|
edx = 0;
|
1997-11-12 04:12:51 +00:00
|
|
|
if(!apm_int(&eax, &ebx, &ecx, &edx))
|
1994-10-02 17:40:38 +00:00
|
|
|
apm_version = eax & 0xffff;
|
|
|
|
}
|
|
|
|
|
1994-10-01 02:56:21 +00:00
|
|
|
/* engage/disengage power management (APM 1.1 or later) */
|
1995-05-30 08:16:23 +00:00
|
|
|
static int
|
1997-01-06 06:02:03 +00:00
|
|
|
apm_engage_disengage_pm(int engage)
|
1994-10-01 02:56:21 +00:00
|
|
|
{
|
1997-11-12 04:12:51 +00:00
|
|
|
u_long eax, ebx, ecx, edx;
|
1994-10-01 02:56:21 +00:00
|
|
|
|
1995-02-17 02:22:57 +00:00
|
|
|
eax = (APM_BIOS << 8) | APM_ENGAGEDISENGAGEPM;
|
1994-10-02 01:45:42 +00:00
|
|
|
ebx = PMDV_ALLDEV;
|
|
|
|
ecx = engage;
|
1997-12-04 02:40:00 +00:00
|
|
|
edx = 0;
|
1997-11-12 04:12:51 +00:00
|
|
|
return(apm_int(&eax, &ebx, &ecx, &edx));
|
1994-10-01 02:56:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* get PM event */
|
1995-05-30 08:16:23 +00:00
|
|
|
static u_int
|
1997-01-06 06:02:03 +00:00
|
|
|
apm_getevent(void)
|
1994-10-01 02:56:21 +00:00
|
|
|
{
|
1997-11-12 04:12:51 +00:00
|
|
|
u_long eax, ebx, ecx, edx;
|
1994-10-01 02:56:21 +00:00
|
|
|
|
1995-02-17 02:22:57 +00:00
|
|
|
eax = (APM_BIOS << 8) | APM_GETPMEVENT;
|
1995-05-30 08:16:23 +00:00
|
|
|
|
1994-12-16 06:16:30 +00:00
|
|
|
ebx = 0;
|
|
|
|
ecx = 0;
|
1997-12-04 02:40:00 +00:00
|
|
|
edx = 0;
|
1997-11-12 04:12:51 +00:00
|
|
|
if (apm_int(&eax, &ebx, &ecx, &edx))
|
1994-10-01 02:56:21 +00:00
|
|
|
return PMEV_NOEVENT;
|
1994-10-02 17:40:38 +00:00
|
|
|
|
1994-10-02 01:45:42 +00:00
|
|
|
return ebx & 0xffff;
|
1994-10-01 02:56:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* suspend entire system */
|
1995-05-30 08:16:23 +00:00
|
|
|
static int
|
1998-07-06 06:29:07 +00:00
|
|
|
apm_suspend_system(int state)
|
1994-10-01 02:56:21 +00:00
|
|
|
{
|
1997-11-12 04:12:51 +00:00
|
|
|
u_long eax, ebx, ecx, edx;
|
1995-05-30 08:16:23 +00:00
|
|
|
|
1995-02-17 02:22:57 +00:00
|
|
|
eax = (APM_BIOS << 8) | APM_SETPWSTATE;
|
1994-10-02 01:45:42 +00:00
|
|
|
ebx = PMDV_ALLDEV;
|
1998-07-06 06:29:07 +00:00
|
|
|
ecx = state;
|
1997-12-04 02:40:00 +00:00
|
|
|
edx = 0;
|
1994-10-01 02:56:21 +00:00
|
|
|
|
1997-11-12 04:12:51 +00:00
|
|
|
if (apm_int(&eax, &ebx, &ecx, &edx)) {
|
1995-05-30 08:16:23 +00:00
|
|
|
printf("Entire system suspend failure: errcode = %ld\n",
|
1994-10-02 01:45:42 +00:00
|
|
|
0xff & (eax >> 8));
|
1994-10-01 02:56:21 +00:00
|
|
|
return 1;
|
|
|
|
}
|
1995-02-17 02:22:57 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Display control */
|
|
|
|
/*
|
|
|
|
* Experimental implementation: My laptop machine can't handle this function
|
|
|
|
* If your laptop can control the display via APM, please inform me.
|
1997-01-06 06:02:03 +00:00
|
|
|
* HOSOKAWA, Tatsumi <hosokawa@jp.FreeBSD.org>
|
1995-02-17 02:22:57 +00:00
|
|
|
*/
|
1995-12-22 13:08:27 +00:00
|
|
|
static int
|
1997-01-06 06:02:03 +00:00
|
|
|
apm_display(int newstate)
|
1995-02-17 02:22:57 +00:00
|
|
|
{
|
1997-11-12 04:12:51 +00:00
|
|
|
u_long eax, ebx, ecx, edx;
|
1995-05-30 08:16:23 +00:00
|
|
|
|
1995-02-17 02:22:57 +00:00
|
|
|
eax = (APM_BIOS << 8) | APM_SETPWSTATE;
|
1997-01-06 06:02:03 +00:00
|
|
|
ebx = PMDV_DISP0;
|
|
|
|
ecx = newstate ? PMST_APMENABLED:PMST_SUSPEND;
|
1997-12-04 02:40:00 +00:00
|
|
|
edx = 0;
|
1997-11-12 04:12:51 +00:00
|
|
|
if (apm_int(&eax, &ebx, &ecx, &edx)) {
|
1995-05-30 08:16:23 +00:00
|
|
|
printf("Display off failure: errcode = %ld\n",
|
1995-02-17 02:22:57 +00:00
|
|
|
0xff & (eax >> 8));
|
|
|
|
return 1;
|
|
|
|
}
|
1994-10-01 02:56:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1997-06-15 02:03:03 +00:00
|
|
|
/*
|
|
|
|
* Turn off the entire system.
|
|
|
|
*/
|
1998-10-30 05:41:15 +00:00
|
|
|
static void
|
|
|
|
apm_power_off(int howto, void *junk)
|
1997-06-15 02:03:03 +00:00
|
|
|
{
|
1997-11-12 04:12:51 +00:00
|
|
|
u_long eax, ebx, ecx, edx;
|
1997-06-15 02:03:03 +00:00
|
|
|
|
1998-12-10 23:36:14 +00:00
|
|
|
/* Not halting powering off, or not active */
|
|
|
|
if (!(howto & RB_POWEROFF) || !apm_softc.active)
|
1997-06-19 00:25:03 +00:00
|
|
|
return;
|
1997-06-15 02:03:03 +00:00
|
|
|
eax = (APM_BIOS << 8) | APM_SETPWSTATE;
|
|
|
|
ebx = PMDV_ALLDEV;
|
|
|
|
ecx = PMST_OFF;
|
1997-12-04 02:40:00 +00:00
|
|
|
edx = 0;
|
1997-11-12 04:12:51 +00:00
|
|
|
apm_int(&eax, &ebx, &ecx, &edx);
|
1997-06-15 02:03:03 +00:00
|
|
|
}
|
1997-01-06 06:02:03 +00:00
|
|
|
|
1994-10-01 02:56:21 +00:00
|
|
|
/* APM Battery low handler */
|
1995-05-30 08:16:23 +00:00
|
|
|
static void
|
1997-01-06 06:02:03 +00:00
|
|
|
apm_battery_low(void)
|
1994-10-01 02:56:21 +00:00
|
|
|
{
|
1994-10-02 17:40:38 +00:00
|
|
|
printf("\007\007 * * * BATTERY IS LOW * * * \007\007");
|
1994-10-01 02:56:21 +00:00
|
|
|
}
|
|
|
|
|
1995-02-17 02:22:57 +00:00
|
|
|
/* APM hook manager */
|
|
|
|
static struct apmhook *
|
|
|
|
apm_add_hook(struct apmhook **list, struct apmhook *ah)
|
|
|
|
{
|
|
|
|
int s;
|
|
|
|
struct apmhook *p, *prev;
|
|
|
|
|
1996-04-18 19:21:47 +00:00
|
|
|
#ifdef APM_DEBUG
|
1995-02-17 02:22:57 +00:00
|
|
|
printf("Add hook \"%s\"\n", ah->ah_name);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
s = splhigh();
|
1997-01-06 06:02:03 +00:00
|
|
|
if (ah == NULL)
|
1995-02-17 02:22:57 +00:00
|
|
|
panic("illegal apm_hook!");
|
|
|
|
prev = NULL;
|
1997-01-06 06:02:03 +00:00
|
|
|
for (p = *list; p != NULL; prev = p, p = p->ah_next)
|
|
|
|
if (p->ah_order > ah->ah_order)
|
1995-02-17 02:22:57 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
if (prev == NULL) {
|
|
|
|
ah->ah_next = *list;
|
|
|
|
*list = ah;
|
|
|
|
} else {
|
|
|
|
ah->ah_next = prev->ah_next;
|
|
|
|
prev->ah_next = ah;
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
return ah;
|
|
|
|
}
|
|
|
|
|
1995-05-30 08:16:23 +00:00
|
|
|
static void
|
1995-02-17 02:22:57 +00:00
|
|
|
apm_del_hook(struct apmhook **list, struct apmhook *ah)
|
|
|
|
{
|
|
|
|
int s;
|
|
|
|
struct apmhook *p, *prev;
|
|
|
|
|
|
|
|
s = splhigh();
|
|
|
|
prev = NULL;
|
1997-01-06 06:02:03 +00:00
|
|
|
for (p = *list; p != NULL; prev = p, p = p->ah_next)
|
|
|
|
if (p == ah)
|
1995-02-17 02:22:57 +00:00
|
|
|
goto deleteit;
|
|
|
|
panic("Tried to delete unregistered apm_hook.");
|
|
|
|
goto nosuchnode;
|
|
|
|
deleteit:
|
1997-01-06 06:02:03 +00:00
|
|
|
if (prev != NULL)
|
1995-02-17 02:22:57 +00:00
|
|
|
prev->ah_next = p->ah_next;
|
1997-01-06 06:02:03 +00:00
|
|
|
else
|
1995-02-17 02:22:57 +00:00
|
|
|
*list = p->ah_next;
|
|
|
|
nosuchnode:
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* APM driver calls some functions automatically */
|
1995-05-30 08:16:23 +00:00
|
|
|
static void
|
1995-02-17 02:22:57 +00:00
|
|
|
apm_execute_hook(struct apmhook *list)
|
|
|
|
{
|
|
|
|
struct apmhook *p;
|
|
|
|
|
|
|
|
for (p = list; p != NULL; p = p->ah_next) {
|
1996-04-18 19:21:47 +00:00
|
|
|
#ifdef APM_DEBUG
|
1995-02-17 02:22:57 +00:00
|
|
|
printf("Execute APM hook \"%s.\"\n", p->ah_name);
|
|
|
|
#endif
|
1997-01-06 06:02:03 +00:00
|
|
|
if ((*(p->ah_fun))(p->ah_arg))
|
1995-02-17 02:22:57 +00:00
|
|
|
printf("Warning: APM hook \"%s\" failed", p->ah_name);
|
1995-05-30 08:16:23 +00:00
|
|
|
}
|
1995-02-17 02:22:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* establish an apm hook */
|
|
|
|
struct apmhook *
|
|
|
|
apm_hook_establish(int apmh, struct apmhook *ah)
|
|
|
|
{
|
|
|
|
if (apmh < 0 || apmh >= NAPM_HOOK)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return apm_add_hook(&hook[apmh], ah);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* disestablish an apm hook */
|
1995-12-25 07:38:47 +00:00
|
|
|
void
|
1995-02-17 02:22:57 +00:00
|
|
|
apm_hook_disestablish(int apmh, struct apmhook *ah)
|
|
|
|
{
|
|
|
|
if (apmh < 0 || apmh >= NAPM_HOOK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
apm_del_hook(&hook[apmh], ah);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1994-10-01 02:56:21 +00:00
|
|
|
static struct timeval suspend_time;
|
1995-02-17 02:22:57 +00:00
|
|
|
static struct timeval diff_time;
|
1994-10-01 02:56:21 +00:00
|
|
|
|
1995-05-30 08:16:23 +00:00
|
|
|
static int
|
1995-11-18 04:37:23 +00:00
|
|
|
apm_default_resume(void *arg)
|
1994-10-01 02:56:21 +00:00
|
|
|
{
|
1995-02-17 02:22:57 +00:00
|
|
|
int pl;
|
1994-10-01 02:56:21 +00:00
|
|
|
u_int second, minute, hour;
|
1995-02-17 02:22:57 +00:00
|
|
|
struct timeval resume_time, tmp_time;
|
1994-10-01 02:56:21 +00:00
|
|
|
|
1995-02-17 02:22:57 +00:00
|
|
|
/* modified for adjkerntz */
|
|
|
|
pl = splsoftclock();
|
|
|
|
inittodr(0); /* adjust time to RTC */
|
1994-10-01 02:56:21 +00:00
|
|
|
microtime(&resume_time);
|
1998-03-30 09:56:58 +00:00
|
|
|
getmicrotime(&tmp_time);
|
1995-02-17 02:22:57 +00:00
|
|
|
timevaladd(&tmp_time, &diff_time);
|
1998-03-30 09:56:58 +00:00
|
|
|
|
|
|
|
#ifdef FIXME
|
|
|
|
/* XXX THIS DOESN'T WORK!!! */
|
1995-02-17 02:22:57 +00:00
|
|
|
time = tmp_time;
|
1998-03-30 09:56:58 +00:00
|
|
|
#endif
|
|
|
|
|
1997-12-23 16:32:35 +00:00
|
|
|
#ifdef APM_FIXUP_CALLTODO
|
|
|
|
/* Calculate the delta time suspended */
|
|
|
|
timevalsub(&resume_time, &suspend_time);
|
|
|
|
/* Fixup the calltodo list with the delta time. */
|
|
|
|
adjust_timeout_calltodo(&resume_time);
|
|
|
|
#endif /* APM_FIXUP_CALLTODOK */
|
1995-02-17 02:22:57 +00:00
|
|
|
splx(pl);
|
1997-12-23 16:32:35 +00:00
|
|
|
#ifndef APM_FIXUP_CALLTODO
|
|
|
|
second = resume_time.tv_sec - suspend_time.tv_sec;
|
|
|
|
#else /* APM_FIXUP_CALLTODO */
|
|
|
|
/*
|
|
|
|
* We've already calculated resume_time to be the delta between
|
|
|
|
* the suspend and the resume.
|
|
|
|
*/
|
|
|
|
second = resume_time.tv_sec;
|
|
|
|
#endif /* APM_FIXUP_CALLTODO */
|
1994-10-01 02:56:21 +00:00
|
|
|
hour = second / 3600;
|
|
|
|
second %= 3600;
|
|
|
|
minute = second / 60;
|
|
|
|
second %= 60;
|
1994-10-02 17:40:38 +00:00
|
|
|
log(LOG_NOTICE, "resumed from suspended mode (slept %02d:%02d:%02d)\n",
|
|
|
|
hour, minute, second);
|
1994-10-01 02:56:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1995-05-30 08:16:23 +00:00
|
|
|
static int
|
1995-11-18 04:37:23 +00:00
|
|
|
apm_default_suspend(void *arg)
|
1994-10-01 02:56:21 +00:00
|
|
|
{
|
1994-10-02 01:45:42 +00:00
|
|
|
int pl;
|
1995-02-17 02:22:57 +00:00
|
|
|
|
|
|
|
pl = splsoftclock();
|
|
|
|
microtime(&diff_time);
|
|
|
|
inittodr(0);
|
1994-10-01 02:56:21 +00:00
|
|
|
microtime(&suspend_time);
|
1995-02-17 02:22:57 +00:00
|
|
|
timevalsub(&diff_time, &suspend_time);
|
|
|
|
splx(pl);
|
1994-10-01 02:56:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1997-01-06 06:02:03 +00:00
|
|
|
static void apm_processevent(void);
|
1995-02-17 02:22:57 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Public interface to the suspend/resume:
|
|
|
|
*
|
|
|
|
* Execute suspend and resume hook before and after sleep, respectively.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
1995-05-30 08:16:23 +00:00
|
|
|
void
|
1998-07-06 06:29:07 +00:00
|
|
|
apm_suspend(int state)
|
1995-02-17 02:22:57 +00:00
|
|
|
{
|
1996-03-18 21:58:22 +00:00
|
|
|
struct apm_softc *sc = &apm_softc;
|
1999-04-16 21:22:55 +00:00
|
|
|
int error;
|
1995-02-17 02:22:57 +00:00
|
|
|
|
|
|
|
if (!sc)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (sc->initialized) {
|
1999-04-16 21:22:55 +00:00
|
|
|
error = DEVICE_SUSPEND(root_bus);
|
1999-04-21 07:57:55 +00:00
|
|
|
/*
|
|
|
|
* XXX Shouldn't ignore the error like this, but should
|
|
|
|
* instead fix the newbus code. Until that happens,
|
|
|
|
* I'm doing this to get suspend working again.
|
|
|
|
*/
|
1999-04-16 21:22:55 +00:00
|
|
|
if (error)
|
1999-04-21 07:57:55 +00:00
|
|
|
printf("DEVICE_SUSPEND error %d, ignored\n", error);
|
1995-02-17 02:22:57 +00:00
|
|
|
apm_execute_hook(hook[APM_HOOK_SUSPEND]);
|
1998-07-06 06:29:07 +00:00
|
|
|
if (apm_suspend_system(state) == 0)
|
1997-11-04 17:37:52 +00:00
|
|
|
apm_processevent();
|
|
|
|
else
|
1997-11-10 14:38:08 +00:00
|
|
|
/* Failure, 'resume' the system again */
|
1997-11-04 17:37:52 +00:00
|
|
|
apm_execute_hook(hook[APM_HOOK_RESUME]);
|
1995-02-17 02:22:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
apm_resume(void)
|
|
|
|
{
|
1996-03-18 21:58:22 +00:00
|
|
|
struct apm_softc *sc = &apm_softc;
|
1995-02-17 02:22:57 +00:00
|
|
|
|
|
|
|
if (!sc)
|
|
|
|
return;
|
|
|
|
|
1999-04-16 21:22:55 +00:00
|
|
|
if (sc->initialized) {
|
|
|
|
DEVICE_RESUME(root_bus);
|
1995-02-17 02:22:57 +00:00
|
|
|
apm_execute_hook(hook[APM_HOOK_RESUME]);
|
1999-04-16 21:22:55 +00:00
|
|
|
}
|
1995-02-17 02:22:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1994-10-01 02:56:21 +00:00
|
|
|
/* get APM information */
|
|
|
|
static int
|
1997-01-06 06:02:03 +00:00
|
|
|
apm_get_info(apm_info_t aip)
|
1994-10-01 02:56:21 +00:00
|
|
|
{
|
1997-01-06 06:02:03 +00:00
|
|
|
struct apm_softc *sc = &apm_softc;
|
1997-11-12 04:12:51 +00:00
|
|
|
u_long eax, ebx, ecx, edx;
|
1994-10-01 02:56:21 +00:00
|
|
|
|
1995-02-17 02:22:57 +00:00
|
|
|
eax = (APM_BIOS << 8) | APM_GETPWSTATUS;
|
1994-10-02 01:45:42 +00:00
|
|
|
ebx = PMDV_ALLDEV;
|
1994-12-16 06:16:30 +00:00
|
|
|
ecx = 0;
|
1997-12-04 02:40:00 +00:00
|
|
|
edx = 0xffff; /* default to unknown battery time */
|
1994-10-02 01:45:42 +00:00
|
|
|
|
1997-11-12 04:12:51 +00:00
|
|
|
if (apm_int(&eax, &ebx, &ecx, &edx))
|
1994-10-01 02:56:21 +00:00
|
|
|
return 1;
|
1994-10-02 01:45:42 +00:00
|
|
|
|
1998-07-06 06:29:07 +00:00
|
|
|
aip->ai_infoversion = 1;
|
1997-11-12 04:12:51 +00:00
|
|
|
aip->ai_acline = (ebx >> 8) & 0xff;
|
|
|
|
aip->ai_batt_stat = ebx & 0xff;
|
|
|
|
aip->ai_batt_life = ecx & 0xff;
|
|
|
|
aip->ai_major = (u_int)sc->majorversion;
|
|
|
|
aip->ai_minor = (u_int)sc->minorversion;
|
|
|
|
aip->ai_status = (u_int)sc->active;
|
|
|
|
edx &= 0xffff;
|
|
|
|
if (edx == 0xffff) /* Time is unknown */
|
|
|
|
aip->ai_batt_time = -1;
|
|
|
|
else if (edx & 0x8000) /* Time is in minutes */
|
|
|
|
aip->ai_batt_time = (edx & 0x7fff) * 60;
|
|
|
|
else /* Time is in seconds */
|
|
|
|
aip->ai_batt_time = edx;
|
1998-07-06 06:29:07 +00:00
|
|
|
|
|
|
|
eax = (APM_BIOS << 8) | APM_GETCAPABILITIES;
|
|
|
|
ebx = 0;
|
|
|
|
ecx = 0;
|
|
|
|
edx = 0;
|
|
|
|
if (apm_int(&eax, &ebx, &ecx, &edx)) {
|
|
|
|
aip->ai_batteries = -1; /* Unknown */
|
|
|
|
aip->ai_capabilities = 0xff00; /* Unknown, with no bits set */
|
|
|
|
} else {
|
|
|
|
aip->ai_batteries = ebx & 0xff;
|
|
|
|
aip->ai_capabilities = ecx & 0xf;
|
|
|
|
}
|
|
|
|
|
1997-11-12 04:12:51 +00:00
|
|
|
bzero(aip->ai_spare, sizeof aip->ai_spare);
|
1996-03-13 00:42:56 +00:00
|
|
|
|
1994-10-01 02:56:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* inform APM BIOS that CPU is idle */
|
1995-12-25 07:38:47 +00:00
|
|
|
void
|
1994-10-01 02:56:21 +00:00
|
|
|
apm_cpu_idle(void)
|
|
|
|
{
|
1996-03-18 21:58:22 +00:00
|
|
|
struct apm_softc *sc = &apm_softc;
|
1995-02-17 02:22:57 +00:00
|
|
|
|
1996-03-19 16:56:56 +00:00
|
|
|
if (sc->active) {
|
1997-11-12 04:12:51 +00:00
|
|
|
u_long eax, ebx, ecx, edx;
|
1996-03-19 16:48:38 +00:00
|
|
|
|
1996-03-19 16:56:56 +00:00
|
|
|
eax = (APM_BIOS <<8) | APM_CPUIDLE;
|
1997-12-04 02:40:00 +00:00
|
|
|
edx = ecx = ebx = 0;
|
1997-11-12 04:12:51 +00:00
|
|
|
apm_int(&eax, &ebx, &ecx, &edx);
|
1994-10-01 02:56:21 +00:00
|
|
|
}
|
|
|
|
/*
|
1995-05-30 08:16:23 +00:00
|
|
|
* Some APM implementation halts CPU in BIOS, whenever
|
1994-10-01 02:56:21 +00:00
|
|
|
* "CPU-idle" function are invoked, but swtch() of
|
|
|
|
* FreeBSD halts CPU, therefore, CPU is halted twice
|
|
|
|
* in the sched loop. It makes the interrupt latency
|
|
|
|
* terribly long and be able to cause a serious problem
|
|
|
|
* in interrupt processing. We prevent it by removing
|
|
|
|
* "hlt" operation from swtch() and managed it under
|
|
|
|
* APM driver.
|
|
|
|
*/
|
1997-01-06 06:02:03 +00:00
|
|
|
if (!sc->active || sc->always_halt_cpu)
|
1996-03-19 04:40:03 +00:00
|
|
|
__asm("hlt"); /* wait for interrupt */
|
1994-10-01 02:56:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* inform APM BIOS that CPU is busy */
|
1995-12-25 07:38:47 +00:00
|
|
|
void
|
1994-10-01 02:56:21 +00:00
|
|
|
apm_cpu_busy(void)
|
|
|
|
{
|
1996-03-18 21:58:22 +00:00
|
|
|
struct apm_softc *sc = &apm_softc;
|
1995-02-17 02:22:57 +00:00
|
|
|
|
1996-03-19 16:56:56 +00:00
|
|
|
/*
|
|
|
|
* The APM specification says this is only necessary if your BIOS
|
|
|
|
* slows down the processor in the idle task, otherwise it's not
|
|
|
|
* necessary.
|
|
|
|
*/
|
|
|
|
if (sc->slow_idle_cpu && sc->active) {
|
1997-11-12 04:12:51 +00:00
|
|
|
u_long eax, ebx, ecx, edx;
|
1996-03-19 16:48:38 +00:00
|
|
|
|
1996-03-19 16:56:56 +00:00
|
|
|
eax = (APM_BIOS <<8) | APM_CPUBUSY;
|
1997-12-04 02:40:00 +00:00
|
|
|
edx = ecx = ebx = 0;
|
1997-11-12 04:12:51 +00:00
|
|
|
apm_int(&eax, &ebx, &ecx, &edx);
|
1994-10-01 02:56:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* APM timeout routine:
|
|
|
|
*
|
1994-10-02 17:40:38 +00:00
|
|
|
* This routine is automatically called by timer once per second.
|
1994-10-01 02:56:21 +00:00
|
|
|
*/
|
|
|
|
|
1995-05-30 08:16:23 +00:00
|
|
|
static void
|
1997-01-06 06:02:03 +00:00
|
|
|
apm_timeout(void *dummy)
|
1994-10-01 02:56:21 +00:00
|
|
|
{
|
1997-01-06 06:02:03 +00:00
|
|
|
struct apm_softc *sc = &apm_softc;
|
1995-02-17 02:22:57 +00:00
|
|
|
|
1997-01-06 06:02:03 +00:00
|
|
|
apm_processevent();
|
|
|
|
if (sc->active == 1)
|
1997-09-21 21:33:10 +00:00
|
|
|
/* Run slightly more oftan than 1 Hz */
|
|
|
|
apm_timeout_ch = timeout(apm_timeout, NULL, hz - 1 );
|
1994-10-01 02:56:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* enable APM BIOS */
|
1995-05-30 08:16:23 +00:00
|
|
|
static void
|
1997-01-06 06:02:03 +00:00
|
|
|
apm_event_enable(void)
|
1994-10-01 02:56:21 +00:00
|
|
|
{
|
1997-01-06 06:02:03 +00:00
|
|
|
struct apm_softc *sc = &apm_softc;
|
|
|
|
|
1994-10-02 01:45:42 +00:00
|
|
|
#ifdef APM_DEBUG
|
1994-10-01 02:56:21 +00:00
|
|
|
printf("called apm_event_enable()\n");
|
|
|
|
#endif
|
1995-02-17 02:22:57 +00:00
|
|
|
if (sc->initialized) {
|
|
|
|
sc->active = 1;
|
|
|
|
apm_timeout(sc);
|
1994-10-01 02:56:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* disable APM BIOS */
|
1995-05-30 08:16:23 +00:00
|
|
|
static void
|
1997-01-06 06:02:03 +00:00
|
|
|
apm_event_disable(void)
|
1994-10-01 02:56:21 +00:00
|
|
|
{
|
1997-01-06 06:02:03 +00:00
|
|
|
struct apm_softc *sc = &apm_softc;
|
|
|
|
|
1994-10-02 01:45:42 +00:00
|
|
|
#ifdef APM_DEBUG
|
1994-10-01 02:56:21 +00:00
|
|
|
printf("called apm_event_disable()\n");
|
|
|
|
#endif
|
1995-02-17 02:22:57 +00:00
|
|
|
if (sc->initialized) {
|
1997-09-21 21:33:10 +00:00
|
|
|
untimeout(apm_timeout, NULL, apm_timeout_ch);
|
1995-02-17 02:22:57 +00:00
|
|
|
sc->active = 0;
|
1994-10-01 02:56:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* halt CPU in scheduling loop */
|
1995-05-30 08:16:23 +00:00
|
|
|
static void
|
1997-01-06 06:02:03 +00:00
|
|
|
apm_halt_cpu(void)
|
1994-10-01 02:56:21 +00:00
|
|
|
{
|
1997-01-06 06:02:03 +00:00
|
|
|
struct apm_softc *sc = &apm_softc;
|
|
|
|
|
|
|
|
if (sc->initialized)
|
1996-03-19 16:56:56 +00:00
|
|
|
sc->always_halt_cpu = 1;
|
1994-10-01 02:56:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* don't halt CPU in scheduling loop */
|
1995-05-30 08:16:23 +00:00
|
|
|
static void
|
1997-01-06 06:02:03 +00:00
|
|
|
apm_not_halt_cpu(void)
|
1994-10-01 02:56:21 +00:00
|
|
|
{
|
1997-01-06 06:02:03 +00:00
|
|
|
struct apm_softc *sc = &apm_softc;
|
|
|
|
|
|
|
|
if (sc->initialized)
|
1996-03-19 16:56:56 +00:00
|
|
|
sc->always_halt_cpu = 0;
|
1994-10-01 02:56:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* device driver definitions */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* probe APM (dummy):
|
|
|
|
*
|
|
|
|
* APM probing routine is placed on locore.s and apm_init.S because
|
|
|
|
* this process forces the CPU to turn to real mode or V86 mode.
|
1997-01-06 06:02:03 +00:00
|
|
|
* Current version uses real mode, but in a future version, we want
|
1994-10-01 02:56:21 +00:00
|
|
|
* to use V86 mode in APM initialization.
|
1998-06-03 01:59:42 +00:00
|
|
|
*
|
|
|
|
* XXX If VM86 is defined, we do.
|
1994-10-01 02:56:21 +00:00
|
|
|
*/
|
1994-10-02 17:40:38 +00:00
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
static int
|
1999-04-16 21:22:55 +00:00
|
|
|
apm_probe(device_t dev)
|
1994-10-01 02:56:21 +00:00
|
|
|
{
|
1998-06-03 01:59:42 +00:00
|
|
|
struct vm86frame vmf;
|
|
|
|
int i;
|
1999-04-18 15:10:58 +00:00
|
|
|
int disabled, flags;
|
|
|
|
|
|
|
|
if (resource_int_value("apm", 0, "disabled", &disabled) == 0
|
|
|
|
&& disabled != 0)
|
|
|
|
return ENXIO;
|
1999-04-16 21:22:55 +00:00
|
|
|
|
|
|
|
device_set_desc(dev, "APM BIOS");
|
1997-01-06 06:02:03 +00:00
|
|
|
|
1999-04-16 21:22:55 +00:00
|
|
|
if ( device_get_unit(dev) > 0 ) {
|
1996-03-18 21:58:22 +00:00
|
|
|
printf("apm: Only one APM driver supported.\n");
|
1999-04-16 21:22:55 +00:00
|
|
|
return ENXIO;
|
1996-03-18 21:58:22 +00:00
|
|
|
}
|
1998-06-03 01:59:42 +00:00
|
|
|
|
1999-04-16 21:22:55 +00:00
|
|
|
if (resource_int_value("apm", 0, "flags", &flags) != 0)
|
|
|
|
flags = 0;
|
|
|
|
|
1998-06-03 01:59:42 +00:00
|
|
|
bzero(&vmf, sizeof(struct vm86frame)); /* safety */
|
1998-09-28 03:41:12 +00:00
|
|
|
vmf.vmf_ax = (APM_BIOS << 8) | APM_INSTCHECK;
|
1998-06-03 01:59:42 +00:00
|
|
|
vmf.vmf_bx = 0;
|
1998-09-28 03:41:12 +00:00
|
|
|
if (((i = vm86_intcall(SYSTEM_BIOS, &vmf)) == 0) &&
|
1998-06-03 01:59:42 +00:00
|
|
|
!(vmf.vmf_eflags & PSL_C) &&
|
|
|
|
(vmf.vmf_bx == 0x504d)) {
|
|
|
|
|
|
|
|
apm_version = vmf.vmf_ax;
|
|
|
|
apm_flags = vmf.vmf_cx;
|
|
|
|
|
1998-09-28 03:41:12 +00:00
|
|
|
vmf.vmf_ax = (APM_BIOS << 8) | APM_PROT32CONNECT;
|
1998-06-03 01:59:42 +00:00
|
|
|
vmf.vmf_bx = 0;
|
1998-09-28 03:41:12 +00:00
|
|
|
if (((i = vm86_intcall(SYSTEM_BIOS, &vmf)) == 0) &&
|
1998-06-03 01:59:42 +00:00
|
|
|
!(vmf.vmf_eflags & PSL_C)) {
|
|
|
|
|
|
|
|
apm_cs32_base = vmf.vmf_ax;
|
|
|
|
apm_cs_entry = vmf.vmf_ebx;
|
|
|
|
apm_cs16_base = vmf.vmf_cx;
|
|
|
|
apm_ds_base = vmf.vmf_dx;
|
|
|
|
apm_cs32_limit = vmf.vmf_si;
|
|
|
|
if (apm_version >= 0x0102)
|
|
|
|
apm_cs16_limit = (vmf.esi.r_ex >> 16);
|
|
|
|
apm_ds_limit = vmf.vmf_di;
|
|
|
|
#ifdef APM_DEBUG
|
|
|
|
printf("apm: BIOS probe/32-bit connect successful\n");
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
/* XXX constant typo! */
|
|
|
|
if (vmf.vmf_ah == APME_PROT32NOTDUPPORTED) {
|
|
|
|
apm_version = APMINI_NOT32BIT;
|
|
|
|
} else {
|
|
|
|
apm_version = APMINI_CONNECTERR;
|
|
|
|
}
|
|
|
|
#ifdef APM_DEBUG
|
|
|
|
printf("apm: BIOS 32-bit connect failed: error 0x%x carry %d ah 0x%x\n",
|
|
|
|
i, (vmf.vmf_eflags & PSL_C) ? 1 : 0, vmf.vmf_ah);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
apm_version = APMINI_CANTFIND;
|
|
|
|
#ifdef APM_DEBUG
|
|
|
|
printf("apm: BIOS probe failed: error 0x%x carry %d bx 0x%x\n",
|
|
|
|
i, (vmf.vmf_eflags & PSL_C) ? 1 : 0, vmf.vmf_bx);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bzero(&apm_softc, sizeof(apm_softc));
|
|
|
|
|
1994-10-01 02:56:21 +00:00
|
|
|
switch (apm_version) {
|
|
|
|
case APMINI_CANTFIND:
|
|
|
|
/* silent */
|
1999-05-09 04:58:13 +00:00
|
|
|
return ENXIO;
|
1994-10-01 02:56:21 +00:00
|
|
|
case APMINI_NOT32BIT:
|
1996-03-18 21:58:22 +00:00
|
|
|
printf("apm: 32bit connection is not supported.\n");
|
1999-05-09 04:58:13 +00:00
|
|
|
return ENXIO;
|
1994-10-01 02:56:21 +00:00
|
|
|
case APMINI_CONNECTERR:
|
1996-03-18 21:58:22 +00:00
|
|
|
printf("apm: 32-bit connection error.\n");
|
1999-05-09 04:58:13 +00:00
|
|
|
return ENXIO;
|
1994-10-01 02:56:21 +00:00
|
|
|
}
|
1999-04-16 21:22:55 +00:00
|
|
|
if (flags & 0x20)
|
1997-03-29 11:07:12 +00:00
|
|
|
statclock_disable = 1;
|
1999-04-16 21:22:55 +00:00
|
|
|
return 0;
|
1994-10-01 02:56:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Process APM event */
|
|
|
|
static void
|
1997-01-06 06:02:03 +00:00
|
|
|
apm_processevent(void)
|
1994-10-01 02:56:21 +00:00
|
|
|
{
|
1994-10-02 17:40:38 +00:00
|
|
|
int apm_event;
|
1994-10-01 02:56:21 +00:00
|
|
|
|
1994-10-02 01:45:42 +00:00
|
|
|
#ifdef APM_DEBUG
|
|
|
|
# define OPMEV_DEBUGMESSAGE(symbol) case symbol: \
|
1996-04-18 19:21:47 +00:00
|
|
|
printf("Received APM Event: " #symbol "\n");
|
1994-10-01 02:56:21 +00:00
|
|
|
#else
|
1994-10-02 17:40:38 +00:00
|
|
|
# define OPMEV_DEBUGMESSAGE(symbol) case symbol:
|
1994-10-01 02:56:21 +00:00
|
|
|
#endif
|
1996-04-18 19:21:47 +00:00
|
|
|
do {
|
1997-01-06 06:02:03 +00:00
|
|
|
apm_event = apm_getevent();
|
1994-10-01 02:56:21 +00:00
|
|
|
switch (apm_event) {
|
1994-10-02 17:40:38 +00:00
|
|
|
OPMEV_DEBUGMESSAGE(PMEV_STANDBYREQ);
|
1998-07-06 06:29:07 +00:00
|
|
|
apm_suspend(PMST_STANDBY);
|
1994-10-02 17:40:38 +00:00
|
|
|
break;
|
|
|
|
OPMEV_DEBUGMESSAGE(PMEV_SUSPENDREQ);
|
1998-07-06 06:29:07 +00:00
|
|
|
apm_suspend(PMST_SUSPEND);
|
1994-10-02 17:40:38 +00:00
|
|
|
break;
|
|
|
|
OPMEV_DEBUGMESSAGE(PMEV_USERSUSPENDREQ);
|
1998-07-06 06:29:07 +00:00
|
|
|
apm_suspend(PMST_SUSPEND);
|
1994-10-02 17:40:38 +00:00
|
|
|
break;
|
|
|
|
OPMEV_DEBUGMESSAGE(PMEV_CRITSUSPEND);
|
1998-07-06 06:29:07 +00:00
|
|
|
apm_suspend(PMST_SUSPEND);
|
1994-10-01 02:56:21 +00:00
|
|
|
break;
|
1994-10-02 17:40:38 +00:00
|
|
|
OPMEV_DEBUGMESSAGE(PMEV_NORMRESUME);
|
1995-02-17 02:22:57 +00:00
|
|
|
apm_resume();
|
1994-10-02 17:40:38 +00:00
|
|
|
break;
|
|
|
|
OPMEV_DEBUGMESSAGE(PMEV_CRITRESUME);
|
1995-02-17 02:22:57 +00:00
|
|
|
apm_resume();
|
1994-10-02 17:40:38 +00:00
|
|
|
break;
|
|
|
|
OPMEV_DEBUGMESSAGE(PMEV_STANDBYRESUME);
|
1995-02-17 02:22:57 +00:00
|
|
|
apm_resume();
|
1994-10-02 17:40:38 +00:00
|
|
|
break;
|
|
|
|
OPMEV_DEBUGMESSAGE(PMEV_BATTERYLOW);
|
1997-01-06 06:02:03 +00:00
|
|
|
apm_battery_low();
|
1998-07-06 06:29:07 +00:00
|
|
|
apm_suspend(PMST_SUSPEND);
|
1994-10-01 02:56:21 +00:00
|
|
|
break;
|
1994-10-02 17:40:38 +00:00
|
|
|
OPMEV_DEBUGMESSAGE(PMEV_POWERSTATECHANGE);
|
1994-10-01 02:56:21 +00:00
|
|
|
break;
|
1994-10-02 17:40:38 +00:00
|
|
|
OPMEV_DEBUGMESSAGE(PMEV_UPDATETIME);
|
1994-10-01 02:56:21 +00:00
|
|
|
inittodr(0); /* adjust time to RTC */
|
|
|
|
break;
|
1997-03-29 11:07:12 +00:00
|
|
|
case PMEV_NOEVENT:
|
1996-04-18 19:21:47 +00:00
|
|
|
break;
|
1994-10-02 17:40:38 +00:00
|
|
|
default:
|
|
|
|
printf("Unknown Original APM Event 0x%x\n", apm_event);
|
|
|
|
break;
|
1994-10-01 02:56:21 +00:00
|
|
|
}
|
1996-04-18 19:21:47 +00:00
|
|
|
} while (apm_event != PMEV_NOEVENT);
|
1994-10-01 02:56:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attach APM:
|
|
|
|
*
|
|
|
|
* Initialize APM driver (APM BIOS itself has been initialized in locore.s)
|
|
|
|
*/
|
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
static int
|
1999-04-16 21:22:55 +00:00
|
|
|
apm_attach(device_t dev)
|
1994-10-01 02:56:21 +00:00
|
|
|
{
|
1995-02-17 02:22:57 +00:00
|
|
|
#define APM_KERNBASE KERNBASE
|
1996-03-18 21:58:22 +00:00
|
|
|
struct apm_softc *sc = &apm_softc;
|
1999-04-16 21:22:55 +00:00
|
|
|
int flags;
|
|
|
|
|
|
|
|
if (resource_int_value("apm", 0, "flags", &flags) != 0)
|
|
|
|
flags = 0;
|
1995-02-17 02:22:57 +00:00
|
|
|
|
|
|
|
sc->initialized = 0;
|
1996-03-18 22:29:48 +00:00
|
|
|
|
|
|
|
/* Must be externally enabled */
|
1995-02-17 02:22:57 +00:00
|
|
|
sc->active = 0;
|
1994-10-01 02:56:21 +00:00
|
|
|
|
|
|
|
/* setup APM parameters */
|
1996-07-10 15:09:48 +00:00
|
|
|
sc->cs16_base = (apm_cs16_base << 4) + APM_KERNBASE;
|
|
|
|
sc->cs32_base = (apm_cs32_base << 4) + APM_KERNBASE;
|
1995-02-17 02:22:57 +00:00
|
|
|
sc->ds_base = (apm_ds_base << 4) + APM_KERNBASE;
|
1998-06-03 01:59:42 +00:00
|
|
|
sc->cs32_limit = apm_cs32_limit - 1;
|
|
|
|
if (apm_cs16_limit == 0)
|
1998-12-04 21:28:39 +00:00
|
|
|
apm_cs16_limit = apm_cs32_limit;
|
1998-06-03 01:59:42 +00:00
|
|
|
sc->cs16_limit = apm_cs16_limit - 1;
|
|
|
|
sc->ds_limit = apm_ds_limit - 1;
|
1995-02-17 02:22:57 +00:00
|
|
|
sc->cs_entry = apm_cs_entry;
|
|
|
|
|
1996-03-19 16:56:56 +00:00
|
|
|
/* Always call HLT in idle loop */
|
|
|
|
sc->always_halt_cpu = 1;
|
|
|
|
|
|
|
|
sc->slow_idle_cpu = ((apm_flags & APM_CPUIDLE_SLOW) != 0);
|
1995-02-17 02:22:57 +00:00
|
|
|
sc->disabled = ((apm_flags & APM_DISABLED) != 0);
|
|
|
|
sc->disengaged = ((apm_flags & APM_DISENGAGED) != 0);
|
|
|
|
|
1994-10-01 02:56:21 +00:00
|
|
|
/* print bootstrap messages */
|
1994-10-02 01:45:42 +00:00
|
|
|
#ifdef APM_DEBUG
|
1996-04-18 19:21:47 +00:00
|
|
|
printf("apm: APM BIOS version %04x\n", apm_version);
|
1996-03-18 21:58:22 +00:00
|
|
|
printf("apm: Code32 0x%08x, Code16 0x%08x, Data 0x%08x\n",
|
|
|
|
sc->cs32_base, sc->cs16_base, sc->ds_base);
|
|
|
|
printf("apm: Code entry 0x%08x, Idling CPU %s, Management %s\n",
|
1996-03-19 16:56:56 +00:00
|
|
|
sc->cs_entry, is_enabled(sc->slow_idle_cpu),
|
1995-02-17 02:22:57 +00:00
|
|
|
is_enabled(!sc->disabled));
|
1998-06-03 01:59:42 +00:00
|
|
|
printf("apm: CS32_limit=0x%x, CS16_limit=0x%x, DS_limit=0x%x\n",
|
|
|
|
(u_short)sc->cs32_limit, (u_short)sc->cs16_limit, (u_short)sc->ds_limit);
|
1994-10-02 01:45:42 +00:00
|
|
|
#endif /* APM_DEBUG */
|
1994-10-01 02:56:21 +00:00
|
|
|
|
1997-01-06 06:02:03 +00:00
|
|
|
#if 0
|
1996-03-18 22:40:57 +00:00
|
|
|
/* Workaround for some buggy APM BIOS implementations */
|
1995-02-17 02:22:57 +00:00
|
|
|
sc->cs_limit = 0xffff;
|
|
|
|
sc->ds_limit = 0xffff;
|
1996-04-23 19:59:14 +00:00
|
|
|
#endif
|
1994-10-01 02:56:21 +00:00
|
|
|
|
|
|
|
/* setup GDT */
|
1995-05-30 08:16:23 +00:00
|
|
|
setup_apm_gdt(sc->cs32_base, sc->cs16_base, sc->ds_base,
|
1998-06-03 01:59:42 +00:00
|
|
|
sc->cs32_limit, sc->cs16_limit, sc->ds_limit);
|
1994-10-01 02:56:21 +00:00
|
|
|
|
|
|
|
/* setup entry point 48bit pointer */
|
|
|
|
apm_addr.segment = GSEL(GAPMCODE32_SEL, SEL_KPL);
|
1995-02-17 02:22:57 +00:00
|
|
|
apm_addr.offset = sc->cs_entry;
|
1994-10-01 02:56:21 +00:00
|
|
|
|
1999-04-16 21:22:55 +00:00
|
|
|
if ((flags & 0x10)) {
|
|
|
|
if ((flags & 0xf) >= 0x2) {
|
1997-03-29 11:07:12 +00:00
|
|
|
apm_driver_version(0x102);
|
|
|
|
}
|
1999-04-16 21:22:55 +00:00
|
|
|
if (!apm_version && (flags & 0xf) >= 0x1) {
|
1997-03-29 11:07:12 +00:00
|
|
|
apm_driver_version(0x101);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
apm_driver_version(0x102);
|
|
|
|
if (!apm_version)
|
|
|
|
apm_driver_version(0x101);
|
|
|
|
}
|
|
|
|
if (!apm_version)
|
|
|
|
apm_version = 0x100;
|
|
|
|
|
1995-02-17 02:22:57 +00:00
|
|
|
sc->minorversion = ((apm_version & 0x00f0) >> 4) * 10 +
|
1994-10-02 17:40:38 +00:00
|
|
|
((apm_version & 0x000f) >> 0);
|
1995-05-30 08:16:23 +00:00
|
|
|
sc->majorversion = ((apm_version & 0xf000) >> 12) * 10 +
|
1994-10-02 17:40:38 +00:00
|
|
|
((apm_version & 0x0f00) >> 8);
|
|
|
|
|
1995-02-17 02:22:57 +00:00
|
|
|
sc->intversion = INTVERSION(sc->majorversion, sc->minorversion);
|
1994-10-02 17:40:38 +00:00
|
|
|
|
1996-04-18 19:21:47 +00:00
|
|
|
#ifdef APM_DEBUG
|
1997-01-06 06:02:03 +00:00
|
|
|
if (sc->intversion >= INTVERSION(1, 1))
|
1996-03-18 21:58:22 +00:00
|
|
|
printf("apm: Engaged control %s\n", is_enabled(!sc->disengaged));
|
1996-04-18 19:21:47 +00:00
|
|
|
#endif
|
1994-10-02 17:40:38 +00:00
|
|
|
|
1996-04-18 19:21:47 +00:00
|
|
|
printf("apm: found APM BIOS version %d.%d\n",
|
1995-02-17 02:22:57 +00:00
|
|
|
sc->majorversion, sc->minorversion);
|
1996-04-23 19:59:14 +00:00
|
|
|
|
1996-04-18 19:21:47 +00:00
|
|
|
#ifdef APM_DEBUG
|
1996-03-19 16:56:56 +00:00
|
|
|
printf("apm: Slow Idling CPU %s\n", is_enabled(sc->slow_idle_cpu));
|
1996-04-18 19:21:47 +00:00
|
|
|
#endif
|
1994-10-02 17:40:38 +00:00
|
|
|
|
1994-10-01 02:56:21 +00:00
|
|
|
/* enable power management */
|
1995-02-17 02:22:57 +00:00
|
|
|
if (sc->disabled) {
|
1997-01-06 06:02:03 +00:00
|
|
|
if (apm_enable_disable_pm(1)) {
|
1996-04-18 19:21:47 +00:00
|
|
|
#ifdef APM_DEBUG
|
|
|
|
printf("apm: *Warning* enable function failed! [%x]\n",
|
1994-10-02 01:45:42 +00:00
|
|
|
apm_errno);
|
1996-04-18 19:21:47 +00:00
|
|
|
#endif
|
1994-10-01 02:56:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* engage power managment (APM 1.1 or later) */
|
1995-02-17 02:22:57 +00:00
|
|
|
if (sc->intversion >= INTVERSION(1, 1) && sc->disengaged) {
|
1997-01-06 06:02:03 +00:00
|
|
|
if (apm_engage_disengage_pm(1)) {
|
1996-04-18 19:21:47 +00:00
|
|
|
#ifdef APM_DEBUG
|
|
|
|
printf("apm: *Warning* engage function failed err=[%x]",
|
1994-10-02 01:45:42 +00:00
|
|
|
apm_errno);
|
1996-04-18 19:21:47 +00:00
|
|
|
printf(" (Docked or using external power?).\n");
|
|
|
|
#endif
|
1994-10-01 02:56:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-02-17 02:22:57 +00:00
|
|
|
/* default suspend hook */
|
|
|
|
sc->sc_suspend.ah_fun = apm_default_suspend;
|
|
|
|
sc->sc_suspend.ah_arg = sc;
|
|
|
|
sc->sc_suspend.ah_name = "default suspend";
|
|
|
|
sc->sc_suspend.ah_order = APM_MAX_ORDER;
|
|
|
|
|
|
|
|
/* default resume hook */
|
|
|
|
sc->sc_resume.ah_fun = apm_default_resume;
|
|
|
|
sc->sc_resume.ah_arg = sc;
|
|
|
|
sc->sc_resume.ah_name = "default resume";
|
|
|
|
sc->sc_resume.ah_order = APM_MIN_ORDER;
|
1994-10-01 02:56:21 +00:00
|
|
|
|
1995-02-17 02:22:57 +00:00
|
|
|
apm_hook_establish(APM_HOOK_SUSPEND, &sc->sc_suspend);
|
|
|
|
apm_hook_establish(APM_HOOK_RESUME , &sc->sc_resume);
|
1994-10-02 17:40:38 +00:00
|
|
|
|
1997-01-06 06:02:03 +00:00
|
|
|
apm_event_enable();
|
1995-02-17 02:22:57 +00:00
|
|
|
|
1998-10-30 05:41:15 +00:00
|
|
|
/* Power the system off using APM */
|
|
|
|
at_shutdown_pri(apm_power_off, NULL, SHUTDOWN_FINAL, SHUTDOWN_PRI_LAST);
|
|
|
|
|
1995-02-17 02:22:57 +00:00
|
|
|
sc->initialized = 1;
|
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
#ifdef DEVFS
|
1996-03-28 14:29:52 +00:00
|
|
|
sc->sc_devfs_token =
|
|
|
|
devfs_add_devswf(&apm_cdevsw, 0, DV_CHR, 0, 0, 0600, "apm");
|
1995-12-08 11:19:42 +00:00
|
|
|
#endif
|
1994-10-01 02:56:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
static int
|
1995-05-30 08:16:23 +00:00
|
|
|
apmopen(dev_t dev, int flag, int fmt, struct proc *p)
|
1994-10-01 02:56:21 +00:00
|
|
|
{
|
1996-03-18 21:58:22 +00:00
|
|
|
struct apm_softc *sc = &apm_softc;
|
1995-02-17 02:22:57 +00:00
|
|
|
|
1996-03-18 22:29:48 +00:00
|
|
|
if (minor(dev) != 0 || !sc->initialized)
|
1996-03-18 21:58:22 +00:00
|
|
|
return (ENXIO);
|
|
|
|
|
1994-10-01 02:56:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
static int
|
1994-10-01 02:56:21 +00:00
|
|
|
apmclose(dev_t dev, int flag, int fmt, struct proc *p)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
static int
|
1998-06-07 17:13:14 +00:00
|
|
|
apmioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
|
1994-10-01 02:56:21 +00:00
|
|
|
{
|
1996-03-18 21:58:22 +00:00
|
|
|
struct apm_softc *sc = &apm_softc;
|
1994-10-01 02:56:21 +00:00
|
|
|
int error = 0;
|
1997-01-06 06:02:03 +00:00
|
|
|
int newstate;
|
1994-10-01 02:56:21 +00:00
|
|
|
|
1996-03-18 22:29:48 +00:00
|
|
|
if (minor(dev) != 0 || !sc->initialized)
|
|
|
|
return (ENXIO);
|
1994-10-02 01:45:42 +00:00
|
|
|
#ifdef APM_DEBUG
|
1996-03-18 21:58:22 +00:00
|
|
|
printf("APM ioctl: cmd = 0x%x\n", cmd);
|
1994-10-01 02:56:21 +00:00
|
|
|
#endif
|
|
|
|
switch (cmd) {
|
|
|
|
case APMIO_SUSPEND:
|
1998-07-06 06:29:07 +00:00
|
|
|
if (sc->active)
|
|
|
|
apm_suspend(PMST_SUSPEND);
|
|
|
|
else
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case APMIO_STANDBY:
|
|
|
|
if (sc->active)
|
|
|
|
apm_suspend(PMST_STANDBY);
|
1997-01-06 06:02:03 +00:00
|
|
|
else
|
1996-03-18 23:30:14 +00:00
|
|
|
error = EINVAL;
|
1994-10-01 02:56:21 +00:00
|
|
|
break;
|
1998-07-06 06:29:07 +00:00
|
|
|
|
1997-11-12 04:12:51 +00:00
|
|
|
case APMIO_GETINFO_OLD:
|
|
|
|
{
|
|
|
|
struct apm_info info;
|
|
|
|
apm_info_old_t aiop;
|
|
|
|
|
|
|
|
if (apm_get_info(&info))
|
|
|
|
error = ENXIO;
|
|
|
|
aiop = (apm_info_old_t)addr;
|
|
|
|
aiop->ai_major = info.ai_major;
|
|
|
|
aiop->ai_minor = info.ai_minor;
|
|
|
|
aiop->ai_acline = info.ai_acline;
|
|
|
|
aiop->ai_batt_stat = info.ai_batt_stat;
|
|
|
|
aiop->ai_batt_life = info.ai_batt_life;
|
|
|
|
aiop->ai_status = info.ai_status;
|
|
|
|
}
|
|
|
|
break;
|
1994-10-01 02:56:21 +00:00
|
|
|
case APMIO_GETINFO:
|
1997-01-06 06:02:03 +00:00
|
|
|
if (apm_get_info((apm_info_t)addr))
|
1994-10-01 02:56:21 +00:00
|
|
|
error = ENXIO;
|
|
|
|
break;
|
|
|
|
case APMIO_ENABLE:
|
1997-01-06 06:02:03 +00:00
|
|
|
apm_event_enable();
|
1994-10-01 02:56:21 +00:00
|
|
|
break;
|
|
|
|
case APMIO_DISABLE:
|
1997-01-06 06:02:03 +00:00
|
|
|
apm_event_disable();
|
1994-10-01 02:56:21 +00:00
|
|
|
break;
|
|
|
|
case APMIO_HALTCPU:
|
1997-01-06 06:02:03 +00:00
|
|
|
apm_halt_cpu();
|
1994-10-01 02:56:21 +00:00
|
|
|
break;
|
|
|
|
case APMIO_NOTHALTCPU:
|
1997-01-06 06:02:03 +00:00
|
|
|
apm_not_halt_cpu();
|
1995-02-17 02:22:57 +00:00
|
|
|
break;
|
1997-01-06 06:02:03 +00:00
|
|
|
case APMIO_DISPLAY:
|
|
|
|
newstate = *(int *)addr;
|
|
|
|
if (apm_display(newstate))
|
1995-02-17 02:22:57 +00:00
|
|
|
error = ENXIO;
|
1994-10-01 02:56:21 +00:00
|
|
|
break;
|
1997-03-29 11:07:12 +00:00
|
|
|
case APMIO_BIOS:
|
1998-07-06 06:29:07 +00:00
|
|
|
if (apm_bios_call((struct apm_bios_arg*)addr) == 0)
|
|
|
|
((struct apm_bios_arg*)addr)->eax &= 0xff;
|
1997-03-29 11:07:12 +00:00
|
|
|
break;
|
1994-10-01 02:56:21 +00:00
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
1995-11-29 10:49:16 +00:00
|
|
|
|
1999-04-16 21:22:55 +00:00
|
|
|
static device_method_t apm_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_probe, apm_probe),
|
|
|
|
DEVMETHOD(device_attach, apm_attach),
|
1995-11-29 10:49:16 +00:00
|
|
|
|
1999-04-16 21:22:55 +00:00
|
|
|
{ 0, 0 }
|
|
|
|
};
|
1995-11-28 09:44:42 +00:00
|
|
|
|
1999-04-16 21:22:55 +00:00
|
|
|
static driver_t apm_driver = {
|
|
|
|
"apm",
|
|
|
|
apm_methods,
|
|
|
|
1, /* no softc (XXX) */
|
|
|
|
};
|
1995-11-29 10:49:16 +00:00
|
|
|
|
1999-04-16 21:22:55 +00:00
|
|
|
static devclass_t apm_devclass;
|
1995-11-29 10:49:16 +00:00
|
|
|
|
1999-05-07 10:11:40 +00:00
|
|
|
DEV_DRIVER_MODULE(apm, nexus, apm_driver, apm_devclass,
|
1999-05-09 13:00:50 +00:00
|
|
|
CDEV_MAJOR, NOMAJ, apm_cdevsw, 0, 0);
|