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.
|
|
|
|
* Copyright (c) 1994-1995 by HOSOKAWA, Tatsumi <hosokawa@mt.cs.keio.ac.jp>
|
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
|
|
|
*
|
1996-03-12 21:51:58 +00:00
|
|
|
* $Id: apm.c,v 1.25 1996/03/12 06:09:34 nate Exp $
|
1994-10-01 02:56:21 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "apm.h"
|
|
|
|
|
|
|
|
#include <sys/param.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*/
|
1994-10-01 02:56:21 +00:00
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include "i386/isa/isa.h"
|
|
|
|
#include "i386/isa/isa_device.h"
|
|
|
|
#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>
|
|
|
|
#include "apm_setup.h"
|
|
|
|
|
1995-12-22 13:08:27 +00:00
|
|
|
static int apm_display_off __P((void));
|
|
|
|
static int apm_int __P((u_long *eax, u_long *ebx, u_long *ecx));
|
|
|
|
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 {
|
|
|
|
int initialized, active, halt_cpu;
|
|
|
|
u_int minorversion, majorversion;
|
|
|
|
u_int cs32_base, cs16_base, ds_base;
|
|
|
|
u_int cs_limit, ds_limit;
|
|
|
|
u_int cs_entry;
|
|
|
|
u_int intversion;
|
|
|
|
int idle_cpu, disabled, disengaged;
|
|
|
|
struct apmhook sc_suspend;
|
|
|
|
struct apmhook sc_resume;
|
1995-12-08 11:19:42 +00:00
|
|
|
void *sc_devfs_token;
|
1995-05-30 08:16:23 +00:00
|
|
|
};
|
1995-02-17 02:22:57 +00:00
|
|
|
|
|
|
|
static struct apm_softc apm_softc[NAPM];
|
|
|
|
static struct apm_softc *master_softc = NULL; /* XXX */
|
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))
|
|
|
|
|
|
|
|
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
|
1995-12-08 11:19:42 +00:00
|
|
|
static struct cdevsw apm_cdevsw =
|
|
|
|
{ apmopen, apmclose, noread, nowrite, /*39*/
|
|
|
|
apmioctl, nostop, nullreset, nodevtotty,/* APM */
|
|
|
|
seltrue, nommap, NULL , "apm" ,NULL, -1};
|
|
|
|
|
1994-10-01 02:56:21 +00:00
|
|
|
/* setup APM GDT discriptors */
|
1995-05-30 08:16:23 +00:00
|
|
|
static void
|
|
|
|
setup_apm_gdt(u_int code32_base, u_int code16_base, u_int data_base, u_int code_limit, u_int data_limit)
|
1994-10-01 02:56:21 +00:00
|
|
|
{
|
|
|
|
/* setup 32bit code segment */
|
|
|
|
gdt_segs[GAPMCODE32_SEL].ssd_base = code32_base;
|
|
|
|
gdt_segs[GAPMCODE32_SEL].ssd_limit = code_limit;
|
|
|
|
|
|
|
|
/* setup 16bit code segment */
|
|
|
|
gdt_segs[GAPMCODE16_SEL].ssd_base = code16_base;
|
|
|
|
gdt_segs[GAPMCODE16_SEL].ssd_limit = code_limit;
|
|
|
|
|
|
|
|
/* 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);
|
1994-10-01 02:56:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 48bit far pointer */
|
1995-12-22 13:08:27 +00:00
|
|
|
static 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
|
|
|
|
|
|
|
inline
|
|
|
|
int
|
1995-02-17 02:22:57 +00:00
|
|
|
apm_int(u_long *eax, u_long *ebx, u_long *ecx)
|
1994-10-02 01:45:42 +00:00
|
|
|
{
|
|
|
|
u_long cf;
|
|
|
|
__asm ("pushl %%ebp
|
|
|
|
pushl %%edx
|
1994-12-16 06:16:30 +00:00
|
|
|
pushl %%esi
|
1994-10-02 01:45:42 +00:00
|
|
|
xorl %3,%3
|
1994-12-16 07:09:22 +00:00
|
|
|
movl %3,%%esi
|
1994-10-02 01:45:42 +00:00
|
|
|
lcall _apm_addr
|
|
|
|
jnc 1f
|
|
|
|
incl %3
|
1995-05-30 08:16:23 +00:00
|
|
|
1:
|
1994-12-16 06:16:30 +00:00
|
|
|
popl %%esi
|
|
|
|
popl %%edx
|
1994-10-02 01:45:42 +00:00
|
|
|
popl %%ebp"
|
|
|
|
: "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=D" (cf)
|
|
|
|
: "0" (*eax), "1" (*ebx), "2" (*ecx)
|
1995-05-30 08:16:23 +00:00
|
|
|
);
|
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
|
1995-02-17 02:22:57 +00:00
|
|
|
apm_enable_disable_pm(struct apm_softc *sc, int enable)
|
1994-10-01 02:56:21 +00:00
|
|
|
{
|
1995-02-17 02:22:57 +00:00
|
|
|
u_long eax, ebx, ecx;
|
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
|
|
|
|
1995-02-17 02:22:57 +00:00
|
|
|
if (sc->intversion >= INTVERSION(1, 1)) {
|
1994-10-02 01:45:42 +00:00
|
|
|
ebx = PMDV_ALLDEV;
|
|
|
|
} else {
|
|
|
|
ebx = 0xffff; /* APM version 1.0 only */
|
1994-10-01 02:56:21 +00:00
|
|
|
}
|
1994-10-02 01:45:42 +00:00
|
|
|
ecx = enable;
|
1995-02-17 02:22:57 +00:00
|
|
|
return apm_int(&eax, &ebx, &ecx);
|
1994-10-01 02:56:21 +00:00
|
|
|
}
|
|
|
|
|
1994-10-02 17:40:38 +00:00
|
|
|
/* Tell APM-BIOS that WE will do 1.1 and see what they say... */
|
|
|
|
static void
|
1995-02-17 02:22:57 +00:00
|
|
|
apm_driver_version(void)
|
1994-10-02 17:40:38 +00:00
|
|
|
{
|
1995-10-28 15:39:31 +00:00
|
|
|
u_long eax, ebx, ecx;
|
1994-10-02 17:40:38 +00:00
|
|
|
|
|
|
|
#ifdef APM_DEBUG
|
|
|
|
eax = (APM_BIOS<<8) | APM_INSTCHECK;
|
|
|
|
ebx = 0x0;
|
|
|
|
ecx = 0x0101;
|
1995-02-17 02:22:57 +00:00
|
|
|
i = apm_int(&eax, &ebx, &ecx);
|
1994-10-02 17:40:38 +00:00
|
|
|
printf("[%04lx %04lx %04lx %ld %02x]\n",
|
1995-02-17 02:22:57 +00:00
|
|
|
eax, ebx, ecx, i, apm_errno);
|
1994-10-02 17:40:38 +00:00
|
|
|
#endif
|
|
|
|
|
1995-02-17 02:22:57 +00:00
|
|
|
eax = (APM_BIOS << 8) | APM_DRVVERSION;
|
1994-10-02 17:40:38 +00:00
|
|
|
ebx = 0x0;
|
|
|
|
ecx = 0x0101;
|
1995-05-30 08:16:23 +00:00
|
|
|
if(!apm_int(&eax, &ebx, &ecx))
|
1994-10-02 17:40:38 +00:00
|
|
|
apm_version = eax & 0xffff;
|
|
|
|
|
|
|
|
#ifdef APM_DEBUG
|
1995-02-17 02:22:57 +00:00
|
|
|
eax = (APM_BIOS << 8) | APM_INSTCHECK;
|
1994-10-02 17:40:38 +00:00
|
|
|
ebx = 0x0;
|
|
|
|
ecx = 0x0101;
|
1995-02-17 02:22:57 +00:00
|
|
|
i = apm_int(&eax, &ebx, &ecx);
|
1994-10-02 17:40:38 +00:00
|
|
|
printf("[%04lx %04lx %04lx %ld %02x]\n",
|
1995-02-17 02:22:57 +00:00
|
|
|
eax, ebx, ecx, i, apm_errno);
|
1994-10-02 17:40:38 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
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
|
1995-02-17 02:22:57 +00:00
|
|
|
apm_engage_disengage_pm(struct apm_softc *sc, int engage)
|
1994-10-01 02:56:21 +00:00
|
|
|
{
|
1995-02-17 02:22:57 +00:00
|
|
|
u_long eax, ebx, ecx, i;
|
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;
|
1995-02-17 02:22:57 +00:00
|
|
|
i = apm_int(&eax, &ebx, &ecx);
|
1994-10-02 01:45:42 +00:00
|
|
|
return i;
|
1994-10-01 02:56:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* get PM event */
|
1995-05-30 08:16:23 +00:00
|
|
|
static u_int
|
1995-02-17 02:22:57 +00:00
|
|
|
apm_getevent(struct apm_softc *sc)
|
1994-10-01 02:56:21 +00:00
|
|
|
{
|
1995-02-17 02:22:57 +00:00
|
|
|
u_long eax, ebx, ecx;
|
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;
|
1995-02-17 02:22:57 +00:00
|
|
|
if (apm_int(&eax, &ebx, &ecx))
|
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
|
1995-02-17 02:22:57 +00:00
|
|
|
apm_suspend_system(struct apm_softc *sc)
|
1994-10-01 02:56:21 +00:00
|
|
|
{
|
1995-02-17 02:22:57 +00:00
|
|
|
u_long eax, ebx, ecx;
|
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;
|
|
|
|
ecx = PMST_SUSPEND;
|
1994-10-01 02:56:21 +00:00
|
|
|
|
1995-02-17 02:22:57 +00:00
|
|
|
__asm("cli");
|
|
|
|
if (apm_int(&eax, &ebx, &ecx)) {
|
|
|
|
__asm("sti");
|
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
|
|
|
__asm("sti");
|
|
|
|
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.
|
|
|
|
* HOSOKAWA, Tatsumi <hosokawa@mt.cs.keio.ac.jp>
|
|
|
|
*/
|
1995-12-22 13:08:27 +00:00
|
|
|
static int
|
1995-02-17 02:22:57 +00:00
|
|
|
apm_display_off(void)
|
|
|
|
{
|
|
|
|
u_long eax, ebx, ecx;
|
1995-05-30 08:16:23 +00:00
|
|
|
|
1995-02-17 02:22:57 +00:00
|
|
|
eax = (APM_BIOS << 8) | APM_SETPWSTATE;
|
|
|
|
ebx = PMDV_2NDSTORAGE0;
|
|
|
|
ecx = PMST_STANDBY;
|
|
|
|
if (apm_int(&eax, &ebx, &ecx)) {
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* APM Battery low handler */
|
1995-05-30 08:16:23 +00:00
|
|
|
static void
|
1995-02-17 02:22:57 +00:00
|
|
|
apm_battery_low(struct apm_softc *sc)
|
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;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
printf("Add hook \"%s\"\n", ah->ah_name);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
s = splhigh();
|
|
|
|
if (ah == NULL) {
|
|
|
|
panic("illegal apm_hook!");
|
|
|
|
}
|
|
|
|
prev = NULL;
|
|
|
|
for (p = *list; p != NULL; prev = p, p = p->ah_next) {
|
|
|
|
if (p->ah_order > ah->ah_order) {
|
|
|
|
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;
|
|
|
|
for (p = *list; p != NULL; prev = p, p = p->ah_next) {
|
|
|
|
if (p == ah) {
|
|
|
|
goto deleteit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
panic("Tried to delete unregistered apm_hook.");
|
|
|
|
goto nosuchnode;
|
|
|
|
deleteit:
|
|
|
|
if (prev != NULL) {
|
|
|
|
prev->ah_next = p->ah_next;
|
|
|
|
} else {
|
|
|
|
*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) {
|
|
|
|
#if 0
|
|
|
|
printf("Execute APM hook \"%s.\"\n", p->ah_name);
|
|
|
|
#endif
|
|
|
|
if ((*(p->ah_fun))(p->ah_arg)) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
1995-12-25 07:38:47 +00:00
|
|
|
#ifdef notused
|
1995-02-17 02:22:57 +00:00
|
|
|
/* 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);
|
|
|
|
}
|
1995-12-25 07:38:47 +00:00
|
|
|
#endif /* notused */
|
1995-02-17 02:22:57 +00:00
|
|
|
|
|
|
|
|
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);
|
1995-02-17 02:22:57 +00:00
|
|
|
tmp_time = time; /* because 'time' is volatile */
|
|
|
|
timevaladd(&tmp_time, &diff_time);
|
|
|
|
time = tmp_time;
|
|
|
|
splx(pl);
|
1994-10-01 02:56:21 +00:00
|
|
|
second = resume_time.tv_sec - suspend_time.tv_sec;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
1995-02-17 02:22:57 +00:00
|
|
|
static void apm_processevent(struct apm_softc *);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
1995-02-17 02:22:57 +00:00
|
|
|
apm_suspend(void)
|
|
|
|
{
|
|
|
|
struct apm_softc *sc;
|
|
|
|
|
|
|
|
sc = master_softc; /* XXX */
|
|
|
|
if (!sc)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (sc->initialized) {
|
|
|
|
apm_execute_hook(hook[APM_HOOK_SUSPEND]);
|
|
|
|
apm_suspend_system(sc);
|
|
|
|
apm_processevent(sc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
apm_resume(void)
|
|
|
|
{
|
|
|
|
struct apm_softc *sc;
|
|
|
|
|
|
|
|
sc = master_softc; /* XXX */
|
|
|
|
if (!sc)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (sc->initialized) {
|
|
|
|
apm_execute_hook(hook[APM_HOOK_RESUME]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1994-10-01 02:56:21 +00:00
|
|
|
/* get APM information */
|
|
|
|
static int
|
1995-02-17 02:22:57 +00:00
|
|
|
apm_get_info(struct apm_softc *sc, apm_info_t aip)
|
1994-10-01 02:56:21 +00:00
|
|
|
{
|
1995-02-17 02:22:57 +00:00
|
|
|
u_long eax, ebx, ecx;
|
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;
|
1994-10-02 01:45:42 +00:00
|
|
|
|
1995-02-17 02:22:57 +00:00
|
|
|
if (apm_int(&eax, &ebx, &ecx))
|
1994-10-01 02:56:21 +00:00
|
|
|
return 1;
|
1994-10-02 01:45:42 +00:00
|
|
|
|
|
|
|
aip->ai_acline = (ebx >> 8) & 0xff;
|
|
|
|
aip->ai_batt_stat = ebx & 0xff;
|
|
|
|
aip->ai_batt_life = ecx & 0xff;
|
1995-02-17 02:22:57 +00:00
|
|
|
aip->ai_major = (u_int)sc->majorversion;
|
|
|
|
aip->ai_minor = (u_int)sc->minorversion;
|
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)
|
|
|
|
{
|
1995-02-17 02:22:57 +00:00
|
|
|
struct apm_softc *sc = master_softc; /* XXX */
|
|
|
|
|
|
|
|
if (sc->idle_cpu) {
|
|
|
|
if (sc->active) {
|
1994-10-02 01:45:42 +00:00
|
|
|
__asm ("movw $0x5305, %ax; lcall _apm_addr");
|
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.
|
|
|
|
*/
|
1995-02-17 02:22:57 +00:00
|
|
|
if (!sc->active || sc->halt_cpu) {
|
1994-10-02 01:45:42 +00:00
|
|
|
__asm("sti ; 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)
|
|
|
|
{
|
1995-02-17 02:22:57 +00:00
|
|
|
struct apm_softc *sc = master_softc; /* XXX */
|
|
|
|
|
|
|
|
if (sc->idle_cpu && sc->active) {
|
1994-10-02 01:45:42 +00:00
|
|
|
__asm("movw $0x5306, %ax; lcall _apm_addr");
|
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
|
1995-02-17 02:22:57 +00:00
|
|
|
apm_timeout(void *arg)
|
1994-10-01 02:56:21 +00:00
|
|
|
{
|
1995-02-17 02:22:57 +00:00
|
|
|
struct apm_softc *sc = arg;
|
|
|
|
|
|
|
|
apm_processevent(sc);
|
|
|
|
timeout(apm_timeout, (void *)sc, hz - 1 ); /* More than 1 Hz */
|
1994-10-01 02:56:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* enable APM BIOS */
|
1995-05-30 08:16:23 +00:00
|
|
|
static void
|
1995-02-17 02:22:57 +00:00
|
|
|
apm_event_enable(struct apm_softc *sc)
|
1994-10-01 02:56:21 +00:00
|
|
|
{
|
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
|
1995-02-17 02:22:57 +00:00
|
|
|
apm_event_disable(struct apm_softc *sc)
|
1994-10-01 02:56:21 +00:00
|
|
|
{
|
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) {
|
1994-10-01 02:56:21 +00:00
|
|
|
untimeout(apm_timeout, NULL);
|
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
|
1995-02-17 02:22:57 +00:00
|
|
|
apm_halt_cpu(struct apm_softc *sc)
|
1994-10-01 02:56:21 +00:00
|
|
|
{
|
1995-02-17 02:22:57 +00:00
|
|
|
if (sc->initialized) {
|
|
|
|
sc->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
|
1995-02-17 02:22:57 +00:00
|
|
|
apm_not_halt_cpu(struct apm_softc *sc)
|
1994-10-01 02:56:21 +00:00
|
|
|
{
|
1995-02-17 02:22:57 +00:00
|
|
|
if (sc->initialized) {
|
|
|
|
sc->halt_cpu = 0;
|
1994-10-01 02:56:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* device driver definitions */
|
1995-12-08 11:19:42 +00:00
|
|
|
static int apmprobe (struct isa_device *);
|
|
|
|
static int apmattach(struct isa_device *);
|
1995-02-17 02:22:57 +00:00
|
|
|
struct isa_driver apmdriver = {
|
|
|
|
apmprobe, apmattach, "apm" };
|
1994-10-01 02:56:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
* Current version uses real mode, but on future version, we want
|
|
|
|
* to use V86 mode in APM initialization.
|
|
|
|
*/
|
1994-10-02 17:40:38 +00:00
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
static int
|
|
|
|
apmprobe(struct isa_device *dvp)
|
1994-10-01 02:56:21 +00:00
|
|
|
{
|
1995-02-17 02:22:57 +00:00
|
|
|
int unit = dvp->id_unit;
|
|
|
|
|
1996-03-12 06:09:34 +00:00
|
|
|
/*
|
|
|
|
* XXX - This is necessary here so that we don't panic in the idle
|
|
|
|
* loop because master_softc is unitialized.
|
|
|
|
*/
|
|
|
|
master_softc = &apm_softc[unit];
|
|
|
|
|
1994-10-01 02:56:21 +00:00
|
|
|
switch (apm_version) {
|
|
|
|
case APMINI_CANTFIND:
|
|
|
|
/* silent */
|
|
|
|
return 0;
|
|
|
|
case APMINI_NOT32BIT:
|
1995-02-17 02:22:57 +00:00
|
|
|
printf("apm%d: 32bit connection is not supported.\n", unit);
|
1994-10-01 02:56:21 +00:00
|
|
|
return 0;
|
|
|
|
case APMINI_CONNECTERR:
|
1995-02-17 02:22:57 +00:00
|
|
|
printf("apm%d: 32-bit connection error.\n", unit);
|
1994-10-01 02:56:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1994-10-02 17:40:38 +00:00
|
|
|
|
1994-10-01 02:56:21 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Process APM event */
|
|
|
|
static void
|
1995-02-17 02:22:57 +00:00
|
|
|
apm_processevent(struct apm_softc *sc)
|
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: \
|
1994-10-02 17:40:38 +00:00
|
|
|
printf("Original 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
|
1994-10-02 17:40:38 +00:00
|
|
|
while (1) {
|
1995-02-17 02:22:57 +00:00
|
|
|
apm_event = apm_getevent(sc);
|
1995-05-30 08:16:23 +00:00
|
|
|
if (apm_event == PMEV_NOEVENT)
|
1994-10-02 17:40:38 +00:00
|
|
|
break;
|
1994-10-01 02:56:21 +00:00
|
|
|
switch (apm_event) {
|
1994-10-02 17:40:38 +00:00
|
|
|
OPMEV_DEBUGMESSAGE(PMEV_STANDBYREQ);
|
1995-02-17 02:22:57 +00:00
|
|
|
apm_suspend();
|
1994-10-02 17:40:38 +00:00
|
|
|
break;
|
|
|
|
OPMEV_DEBUGMESSAGE(PMEV_SUSPENDREQ);
|
1995-02-17 02:22:57 +00:00
|
|
|
apm_suspend();
|
1994-10-02 17:40:38 +00:00
|
|
|
break;
|
|
|
|
OPMEV_DEBUGMESSAGE(PMEV_USERSUSPENDREQ);
|
1995-02-17 02:22:57 +00:00
|
|
|
apm_suspend();
|
1994-10-02 17:40:38 +00:00
|
|
|
break;
|
|
|
|
OPMEV_DEBUGMESSAGE(PMEV_CRITSUSPEND);
|
1995-02-17 02:22:57 +00:00
|
|
|
apm_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);
|
1995-02-17 02:22:57 +00:00
|
|
|
apm_battery_low(sc);
|
|
|
|
apm_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;
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attach APM:
|
|
|
|
*
|
|
|
|
* Initialize APM driver (APM BIOS itself has been initialized in locore.s)
|
1994-10-02 17:40:38 +00:00
|
|
|
*
|
|
|
|
* Now, unless I'm mad, (not quite ruled out yet), the APM-1.1 spec is bogus:
|
1995-05-30 08:16:23 +00:00
|
|
|
*
|
1994-10-02 17:40:38 +00:00
|
|
|
* Appendix C says under the header "APM 1.0/APM 1.1 Modal BIOS Behavior"
|
|
|
|
* that "When an APM Driver connects with an APM 1.1 BIOS, the APM 1.1 BIOS
|
|
|
|
* will default to an APM 1.0 connection. After an APM Driver calls the APM
|
|
|
|
* Driver Version function, specifying that it supports APM 1.1, and [sic!]
|
|
|
|
* APM BIOS will change its behavior to an APM 1.1 connection. If the APM
|
|
|
|
* BIOS is an APM 1.0 BIOS, the APM Driver Version function call will fail,
|
|
|
|
* and the connection will remain an APM 1.0 connection."
|
|
|
|
*
|
|
|
|
* OK so I can establish a 1.0 connection, and then tell that I'm a 1.1
|
|
|
|
* and maybe then the BIOS will tell that it too is a 1.1.
|
|
|
|
* Fine.
|
1995-05-30 08:16:23 +00:00
|
|
|
* Now how will I ever get the segment-limits for instance ? There is no
|
|
|
|
* way I can see that I can get a 1.1 response back from an "APM Protected
|
1994-10-02 17:40:38 +00:00
|
|
|
* Mode 32-bit Interface Connect" function ???
|
1995-05-30 08:16:23 +00:00
|
|
|
*
|
1994-10-02 17:40:38 +00:00
|
|
|
* Who made this, Intel and Microsoft ? -- How did you guess !
|
|
|
|
*
|
|
|
|
* /phk
|
1994-10-01 02:56:21 +00:00
|
|
|
*/
|
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
static int
|
1994-10-01 02:56:21 +00:00
|
|
|
apmattach(struct isa_device *dvp)
|
|
|
|
{
|
1995-02-17 02:22:57 +00:00
|
|
|
int unit = dvp->id_unit;
|
1995-12-08 11:19:42 +00:00
|
|
|
char name[32];
|
1995-02-17 02:22:57 +00:00
|
|
|
#define APM_KERNBASE KERNBASE
|
|
|
|
struct apm_softc *sc = &apm_softc[unit];
|
|
|
|
|
|
|
|
sc->initialized = 0;
|
|
|
|
sc->active = 0;
|
|
|
|
sc->halt_cpu = 1;
|
1994-10-01 02:56:21 +00:00
|
|
|
|
|
|
|
/* setup APM parameters */
|
1995-02-17 02:22:57 +00:00
|
|
|
sc->cs16_base = (apm_cs32_base << 4) + APM_KERNBASE;
|
|
|
|
sc->cs32_base = (apm_cs16_base << 4) + APM_KERNBASE;
|
|
|
|
sc->ds_base = (apm_ds_base << 4) + APM_KERNBASE;
|
|
|
|
sc->cs_limit = apm_cs_limit;
|
|
|
|
sc->ds_limit = apm_ds_limit;
|
|
|
|
sc->cs_entry = apm_cs_entry;
|
|
|
|
|
|
|
|
sc->idle_cpu = ((apm_flags & APM_CPUIDLE_SLOW) != 0);
|
|
|
|
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
|
1994-10-02 17:40:38 +00:00
|
|
|
printf(" found APM BIOS version %04x\n", apm_version);
|
1994-10-02 01:45:42 +00:00
|
|
|
printf("apm%d: Code32 0x%08x, Code16 0x%08x, Data 0x%08x\n",
|
1995-02-17 02:22:57 +00:00
|
|
|
unit, sc->cs32_base, sc->cs16_base, sc->ds_base);
|
1994-10-02 01:45:42 +00:00
|
|
|
printf("apm%d: Code entry 0x%08x, Idling CPU %s, Management %s\n",
|
1995-05-30 08:16:23 +00:00
|
|
|
unit, sc->cs_entry, is_enabled(sc->idle_cpu),
|
1995-02-17 02:22:57 +00:00
|
|
|
is_enabled(!sc->disabled));
|
1994-10-02 17:40:38 +00:00
|
|
|
printf("apm%d: CS_limit=%x, DS_limit=%x\n",
|
1995-02-17 02:22:57 +00:00
|
|
|
unit, sc->cs_limit, sc->ds_limit);
|
1994-10-02 01:45:42 +00:00
|
|
|
#endif /* APM_DEBUG */
|
1994-10-01 02:56:21 +00:00
|
|
|
|
1995-02-17 02:22:57 +00:00
|
|
|
sc->cs_limit = 0xffff;
|
|
|
|
sc->ds_limit = 0xffff;
|
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,
|
1995-02-17 02:22:57 +00:00
|
|
|
sc->cs_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
|
|
|
|
1994-10-02 17:40:38 +00:00
|
|
|
/* Try to kick bios into 1.1 mode */
|
|
|
|
apm_driver_version();
|
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
|
|
|
|
1995-02-17 02:22:57 +00:00
|
|
|
if (sc->intversion >= INTVERSION(1, 1)) {
|
1994-10-02 17:40:38 +00:00
|
|
|
printf("apm%d: Engaged control %s\n",
|
1995-02-17 02:22:57 +00:00
|
|
|
unit, is_enabled(!sc->disengaged));
|
1994-10-02 17:40:38 +00:00
|
|
|
}
|
|
|
|
|
1995-05-30 08:16:23 +00:00
|
|
|
printf(" found APM BIOS version %d.%d\n",
|
1995-02-17 02:22:57 +00:00
|
|
|
sc->majorversion, sc->minorversion);
|
|
|
|
printf("apm%d: Idling CPU %s\n", unit, is_enabled(sc->idle_cpu));
|
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) {
|
|
|
|
if (apm_enable_disable_pm(sc, 1)) {
|
1995-05-30 08:16:23 +00:00
|
|
|
printf("Warning: APM enable function failed! [%x]\n",
|
1994-10-02 01:45:42 +00:00
|
|
|
apm_errno);
|
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) {
|
|
|
|
if (apm_engage_disengage_pm(sc, 1)) {
|
1995-05-30 08:16:23 +00:00
|
|
|
printf("Warning: APM engage function failed [%x]\n",
|
1994-10-02 01:45:42 +00:00
|
|
|
apm_errno);
|
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
|
|
|
|
1995-02-17 02:22:57 +00:00
|
|
|
apm_event_enable(sc);
|
|
|
|
|
|
|
|
sc->initialized = 1;
|
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
#ifdef DEVFS
|
|
|
|
sprintf(name,"apm%d",unit);
|
|
|
|
sc->sc_devfs_token = devfs_add_devsw(
|
|
|
|
"/", name, &apm_cdevsw, unit, DV_CHR, 0, 0, 0600);
|
|
|
|
#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
|
|
|
{
|
1995-02-17 02:22:57 +00:00
|
|
|
struct apm_softc *sc = &apm_softc[minor(dev)];
|
|
|
|
|
|
|
|
if (minor(dev) >= NAPM) {
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
if (!sc->initialized) {
|
1994-10-01 02:56:21 +00:00
|
|
|
return ENXIO;
|
|
|
|
}
|
|
|
|
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
|
1994-10-01 02:56:21 +00:00
|
|
|
apmioctl(dev_t dev, int cmd, caddr_t addr, int flag, struct proc *p)
|
|
|
|
{
|
1995-02-17 02:22:57 +00:00
|
|
|
struct apm_softc *sc = &apm_softc[minor(dev)];
|
1994-10-01 02:56:21 +00:00
|
|
|
int error = 0;
|
|
|
|
|
1994-10-02 01:45:42 +00:00
|
|
|
#ifdef APM_DEBUG
|
1994-10-01 02:56:21 +00:00
|
|
|
printf("APM ioctl: minor = %d, cmd = 0x%x\n", minor(dev), cmd);
|
|
|
|
#endif
|
|
|
|
|
1995-02-17 02:22:57 +00:00
|
|
|
if (minor(dev) >= NAPM) {
|
1994-10-01 02:56:21 +00:00
|
|
|
return ENXIO;
|
|
|
|
}
|
1995-02-17 02:22:57 +00:00
|
|
|
if (!sc->initialized) {
|
1994-10-01 02:56:21 +00:00
|
|
|
return ENXIO;
|
|
|
|
}
|
|
|
|
switch (cmd) {
|
|
|
|
case APMIO_SUSPEND:
|
1995-02-17 02:22:57 +00:00
|
|
|
apm_suspend();
|
1994-10-01 02:56:21 +00:00
|
|
|
break;
|
|
|
|
case APMIO_GETINFO:
|
1995-02-17 02:22:57 +00:00
|
|
|
if (apm_get_info(sc, (apm_info_t)addr)) {
|
1994-10-01 02:56:21 +00:00
|
|
|
error = ENXIO;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case APMIO_ENABLE:
|
1995-02-17 02:22:57 +00:00
|
|
|
apm_event_enable(sc);
|
1994-10-01 02:56:21 +00:00
|
|
|
break;
|
|
|
|
case APMIO_DISABLE:
|
1995-02-17 02:22:57 +00:00
|
|
|
apm_event_disable(sc);
|
1994-10-01 02:56:21 +00:00
|
|
|
break;
|
|
|
|
case APMIO_HALTCPU:
|
1995-02-17 02:22:57 +00:00
|
|
|
apm_halt_cpu(sc);
|
1994-10-01 02:56:21 +00:00
|
|
|
break;
|
|
|
|
case APMIO_NOTHALTCPU:
|
1995-02-17 02:22:57 +00:00
|
|
|
apm_not_halt_cpu(sc);
|
|
|
|
break;
|
|
|
|
case APMIO_DISPLAYOFF:
|
|
|
|
if (apm_display_off()) {
|
|
|
|
error = ENXIO;
|
|
|
|
}
|
1994-10-01 02:56:21 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
1995-11-29 10:49:16 +00:00
|
|
|
|
|
|
|
|
1995-11-28 09:44:42 +00:00
|
|
|
static apm_devsw_installed = 0;
|
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
static void
|
|
|
|
apm_drvinit(void *unused)
|
1995-11-28 09:44:42 +00:00
|
|
|
{
|
1995-11-29 10:49:16 +00:00
|
|
|
dev_t dev;
|
|
|
|
|
1995-11-28 09:44:42 +00:00
|
|
|
if( ! apm_devsw_installed ) {
|
1995-11-29 10:49:16 +00:00
|
|
|
dev = makedev(CDEV_MAJOR,0);
|
|
|
|
cdevsw_add(&dev,&apm_cdevsw,NULL);
|
1995-11-28 09:44:42 +00:00
|
|
|
apm_devsw_installed = 1;
|
1995-11-29 14:41:20 +00:00
|
|
|
}
|
1995-11-28 09:44:42 +00:00
|
|
|
}
|
1995-11-29 10:49:16 +00:00
|
|
|
|
|
|
|
SYSINIT(apmdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,apm_drvinit,NULL)
|