1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-18 10:35:55 +00:00
This commit is contained in:
Poul-Henning Kamp 1995-12-22 13:08:27 +00:00
parent b0aa8fc32f
commit 0fccf9dcec
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=12959
2 changed files with 22 additions and 292 deletions

View File

@ -13,14 +13,11 @@
*
* Sep, 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD)
*
* $Id: apm.c,v 1.19 1995/12/07 12:45:21 davidg Exp $
* $Id: apm.c,v 1.20 1995/12/08 11:13:09 julian Exp $
*/
#include "apm.h"
#if NAPM > 0
#ifdef __FreeBSD__
#include <sys/param.h>
#include <conf.h>
#include <sys/conf.h>
@ -45,31 +42,10 @@
#include <vm/pmap.h>
#include <sys/syslog.h>
#include "apm_setup.h"
#endif /* __FreeBSD__ */
#ifdef MACH_KERNEL
#include <mach/std_types.h>
#include <sys/types.h>
#include <sys/time.h>
#include <device/conf.h>
#include <device/errno.h>
#include <device/tty.h>
#include <device/io_req.h>
#include <kern/time_out.h>
#include <i386/ipl.h>
#include <i386/pio.h>
#include <i386/seg.h>
#include <i386/machspl.h>
#include <chips/busses.h>
#include <i386at/apm_bios.h>
#include <i386at/apm_setup.h>
#include <i386at/apm_segments.h>
#endif /* MACH_KERNEL */
extern int apm_display_off __P((void));
extern int apm_int __P((u_long *eax, u_long *ebx, u_long *ecx));
extern void apm_resume __P((void));
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));
/* static data */
struct apm_softc {
@ -87,7 +63,7 @@ struct apm_softc {
static struct apm_softc apm_softc[NAPM];
static struct apm_softc *master_softc = NULL; /* XXX */
struct apmhook *hook[NAPM_HOOK]; /* XXX */
static struct apmhook *hook[NAPM_HOOK]; /* XXX */
#ifdef APM_SLOWSTART
int apm_slowstart = 0;
int apm_ss_cnt = 0;
@ -105,7 +81,6 @@ extern void fix_desc(struct fake_descriptor *, int);
/* Map version number to integer (keeps ordering of version numbers) */
#define INTVERSION(major, minor) ((major)*100 + (minor))
#ifdef __FreeBSD__
static timeout_t apm_timeout;
static d_open_t apmopen;
static d_close_t apmclose;
@ -117,16 +92,10 @@ static struct cdevsw apm_cdevsw =
apmioctl, nostop, nullreset, nodevtotty,/* APM */
seltrue, nommap, NULL , "apm" ,NULL, -1};
#endif /* __FreeBSD__ */
#ifdef MACH_KERNEL
static void apm_timeout(void *);
#endif /* MACH_KERNEL */
/* setup APM GDT discriptors */
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)
{
#ifdef __FreeBSD__
/* setup 32bit code segment */
gdt_segs[GAPMCODE32_SEL].ssd_base = code32_base;
gdt_segs[GAPMCODE32_SEL].ssd_limit = code_limit;
@ -143,40 +112,15 @@ setup_apm_gdt(u_int code32_base, u_int code16_base, u_int data_base, u_int code_
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);
#endif /* __FreeBSD__ */
#ifdef MACH_KERNEL
/* setup 32bit code segment */
gdt[sel_idx(GAPMCODE32_SEL)].offset = code32_base;
gdt[sel_idx(GAPMCODE32_SEL)].lim_or_seg = code_limit;
gdt[sel_idx(GAPMCODE32_SEL)].size_or_wdct = SZ_32;
gdt[sel_idx(GAPMCODE32_SEL)].access = ACC_P | ACC_PL_K | ACC_CODE_R;
/* setup 16bit code segment */
gdt[sel_idx(GAPMCODE16_SEL)].offset = code16_base;
gdt[sel_idx(GAPMCODE16_SEL)].lim_or_seg = code_limit;
gdt[sel_idx(GAPMCODE16_SEL)].size_or_wdct = 0;
gdt[sel_idx(GAPMCODE16_SEL)].access = ACC_P | ACC_PL_K | ACC_CODE_R;
/* setup data segment */
gdt[sel_idx(GAPMDATA_SEL )].offset = data_base;
gdt[sel_idx(GAPMDATA_SEL )].lim_or_seg = data_limit;
gdt[sel_idx(GAPMDATA_SEL )].size_or_wdct = 0;
gdt[sel_idx(GAPMDATA_SEL )].access = ACC_P | ACC_PL_K | ACC_DATA_W;
/* reflect these changes on physical GDT */
fix_desc(gdt + sel_idx(GAPMCODE32_SEL), 1);
fix_desc(gdt + sel_idx(GAPMCODE16_SEL), 1);
fix_desc(gdt + sel_idx(GAPMDATA_SEL) , 1);
#endif /* MACH_KERNEL */
}
/* 48bit far pointer */
struct addr48 {
static struct addr48 {
u_long offset;
u_short segment;
} apm_addr;
int apm_errno;
static int apm_errno;
inline
int
@ -307,7 +251,7 @@ apm_suspend_system(struct apm_softc *sc)
* If your laptop can control the display via APM, please inform me.
* HOSOKAWA, Tatsumi <hosokawa@mt.cs.keio.ac.jp>
*/
int
static int
apm_display_off(void)
{
u_long eax, ebx, ecx;
@ -418,7 +362,7 @@ apm_hook_establish(int apmh, struct apmhook *ah)
}
/* disestablish an apm hook */
void
static void
apm_hook_disestablish(int apmh, struct apmhook *ah)
{
if (apmh < 0 || apmh >= NAPM_HOOK)
@ -434,7 +378,6 @@ static struct timeval diff_time;
static int
apm_default_resume(void *arg)
{
#ifdef __FreeBSD__
int pl;
u_int second, minute, hour;
struct timeval resume_time, tmp_time;
@ -454,14 +397,12 @@ apm_default_resume(void *arg)
second %= 60;
log(LOG_NOTICE, "resumed from suspended mode (slept %02d:%02d:%02d)\n",
hour, minute, second);
#endif /* __FreeBSD__ */
return 0;
}
static int
apm_default_suspend(void *arg)
{
#ifdef __FreeBSD__
int pl;
pl = splsoftclock();
@ -470,10 +411,6 @@ apm_default_suspend(void *arg)
microtime(&suspend_time);
timevalsub(&diff_time, &suspend_time);
splx(pl);
#if 0
printf("diff_time = %d:%d\n", diff_time.tv_sec, diff_time.tv_usec);
#endif
#endif /* __FreeBSD__ */
return 0;
}
@ -540,7 +477,7 @@ apm_get_info(struct apm_softc *sc, apm_info_t aip)
/* inform APM BIOS that CPU is idle */
void
static void
apm_cpu_idle(void)
{
struct apm_softc *sc = master_softc; /* XXX */
@ -572,7 +509,7 @@ apm_cpu_idle(void)
}
/* inform APM BIOS that CPU is busy */
void
static void
apm_cpu_busy(void)
{
struct apm_softc *sc = master_softc; /* XXX */
@ -649,22 +586,10 @@ apm_not_halt_cpu(struct apm_softc *sc)
}
/* device driver definitions */
#ifdef __FreeBSD__
static int apmprobe (struct isa_device *);
static int apmattach(struct isa_device *);
struct isa_driver apmdriver = {
apmprobe, apmattach, "apm" };
#endif /* __FreeBSD__ */
#ifdef MACH_KERNEL
int apmprobe(vm_offset_t, struct bus_ctlr *);
void apmattach(struct bus_device *);
static struct bus_device *apminfo[NAPM];
static vm_offset_t apmstd[NAPM] = { 0 };
struct bus_driver apmdriver = {
apmprobe, 0, apmattach, 0, apmstd, "apm", apminfo, 0, 0, 0};
#endif /* MACH_KERNEL */
/*
* probe APM (dummy):
@ -675,21 +600,10 @@ struct bus_driver apmdriver = {
* to use V86 mode in APM initialization.
*/
#ifdef __FreeBSD__
static int
apmprobe(struct isa_device *dvp)
#endif /* __FreeBSD__ */
#ifdef MACH_KERNEL
int
apmprobe(vm_offset_t port, struct bus_ctlr *devc)
#endif /* MACH_KERNEL */
{
#ifdef __FreeBSD__
int unit = dvp->id_unit;
#endif /* __FreeBSD__ */
#ifdef MACH_KERNEL
int unit = devc->unit;
#endif /* MACH_KERNEL */
switch (apm_version) {
case APMINI_CANTFIND:
@ -791,24 +705,12 @@ apm_processevent(struct apm_softc *sc)
* /phk
*/
#ifdef __FreeBSD__
static int
apmattach(struct isa_device *dvp)
#endif /* __FreeBSD__ */
#ifdef MACH_KERNEL
void
apmattach(struct bus_device *dvp)
#endif /* MACH_KERNEL */
{
#ifdef __FreeBSD__
int unit = dvp->id_unit;
char name[32];
#define APM_KERNBASE KERNBASE
#endif /* __FreeBSD__ */
#ifdef MACH_KERNEL
int unit = dvp->unit;
#define APM_KERNBASE VM_MIN_KERNEL_ADDRESS
#endif /* MACH_KERNEL */
struct apm_softc *sc = &apm_softc[unit];
master_softc = sc; /* XXX */
@ -854,12 +756,7 @@ apmattach(struct bus_device *dvp)
sc->cs_limit, sc->ds_limit);
/* setup entry point 48bit pointer */
#ifdef __FreeBSD__
apm_addr.segment = GSEL(GAPMCODE32_SEL, SEL_KPL);
#endif /* __FreeBSD__ */
#ifdef MACH_KERNEL
apm_addr.segment = GAPMCODE32_SEL;
#endif /* MACH_KERNEL */
apm_addr.offset = sc->cs_entry;
/* Try to kick bios into 1.1 mode */
@ -915,17 +812,14 @@ apmattach(struct bus_device *dvp)
sc->initialized = 1;
#ifdef __FreeBSD__
#ifdef DEVFS
sprintf(name,"apm%d",unit);
sc->sc_devfs_token = devfs_add_devsw(
"/", name, &apm_cdevsw, unit, DV_CHR, 0, 0, 0600);
#endif
return 0;
#endif /* __FreeBSD__ */
}
#ifdef __FreeBSD__
static int
apmopen(dev_t dev, int flag, int fmt, struct proc *p)
{
@ -1011,32 +905,3 @@ apm_drvinit(void *unused)
}
SYSINIT(apmdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,apm_drvinit,NULL)
#endif /* __FreeBSD__ */
#ifdef MACH_KERNEL
io_return_t apmopen(dev_t dev, int flag, io_req_t ior)
{
int result;
result = ENXIO;
return result;
}
io_return_t apmclose(dev_t dev, int flag)
{
return 0;
}
io_return_t apmgetstat(dev_t dev, int flavor, int *data, u_int *count)
{
}
io_return_t apmsetstat(dev_t dev, int flavor, int *data, u_int count)
{
}
#endif /* MACH_KERNEL */
#endif /* NAPM > 0 */

View File

@ -13,14 +13,11 @@
*
* Sep, 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD)
*
* $Id: apm.c,v 1.19 1995/12/07 12:45:21 davidg Exp $
* $Id: apm.c,v 1.20 1995/12/08 11:13:09 julian Exp $
*/
#include "apm.h"
#if NAPM > 0
#ifdef __FreeBSD__
#include <sys/param.h>
#include <conf.h>
#include <sys/conf.h>
@ -45,31 +42,10 @@
#include <vm/pmap.h>
#include <sys/syslog.h>
#include "apm_setup.h"
#endif /* __FreeBSD__ */
#ifdef MACH_KERNEL
#include <mach/std_types.h>
#include <sys/types.h>
#include <sys/time.h>
#include <device/conf.h>
#include <device/errno.h>
#include <device/tty.h>
#include <device/io_req.h>
#include <kern/time_out.h>
#include <i386/ipl.h>
#include <i386/pio.h>
#include <i386/seg.h>
#include <i386/machspl.h>
#include <chips/busses.h>
#include <i386at/apm_bios.h>
#include <i386at/apm_setup.h>
#include <i386at/apm_segments.h>
#endif /* MACH_KERNEL */
extern int apm_display_off __P((void));
extern int apm_int __P((u_long *eax, u_long *ebx, u_long *ecx));
extern void apm_resume __P((void));
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));
/* static data */
struct apm_softc {
@ -87,7 +63,7 @@ struct apm_softc {
static struct apm_softc apm_softc[NAPM];
static struct apm_softc *master_softc = NULL; /* XXX */
struct apmhook *hook[NAPM_HOOK]; /* XXX */
static struct apmhook *hook[NAPM_HOOK]; /* XXX */
#ifdef APM_SLOWSTART
int apm_slowstart = 0;
int apm_ss_cnt = 0;
@ -105,7 +81,6 @@ extern void fix_desc(struct fake_descriptor *, int);
/* Map version number to integer (keeps ordering of version numbers) */
#define INTVERSION(major, minor) ((major)*100 + (minor))
#ifdef __FreeBSD__
static timeout_t apm_timeout;
static d_open_t apmopen;
static d_close_t apmclose;
@ -117,16 +92,10 @@ static struct cdevsw apm_cdevsw =
apmioctl, nostop, nullreset, nodevtotty,/* APM */
seltrue, nommap, NULL , "apm" ,NULL, -1};
#endif /* __FreeBSD__ */
#ifdef MACH_KERNEL
static void apm_timeout(void *);
#endif /* MACH_KERNEL */
/* setup APM GDT discriptors */
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)
{
#ifdef __FreeBSD__
/* setup 32bit code segment */
gdt_segs[GAPMCODE32_SEL].ssd_base = code32_base;
gdt_segs[GAPMCODE32_SEL].ssd_limit = code_limit;
@ -143,40 +112,15 @@ setup_apm_gdt(u_int code32_base, u_int code16_base, u_int data_base, u_int code_
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);
#endif /* __FreeBSD__ */
#ifdef MACH_KERNEL
/* setup 32bit code segment */
gdt[sel_idx(GAPMCODE32_SEL)].offset = code32_base;
gdt[sel_idx(GAPMCODE32_SEL)].lim_or_seg = code_limit;
gdt[sel_idx(GAPMCODE32_SEL)].size_or_wdct = SZ_32;
gdt[sel_idx(GAPMCODE32_SEL)].access = ACC_P | ACC_PL_K | ACC_CODE_R;
/* setup 16bit code segment */
gdt[sel_idx(GAPMCODE16_SEL)].offset = code16_base;
gdt[sel_idx(GAPMCODE16_SEL)].lim_or_seg = code_limit;
gdt[sel_idx(GAPMCODE16_SEL)].size_or_wdct = 0;
gdt[sel_idx(GAPMCODE16_SEL)].access = ACC_P | ACC_PL_K | ACC_CODE_R;
/* setup data segment */
gdt[sel_idx(GAPMDATA_SEL )].offset = data_base;
gdt[sel_idx(GAPMDATA_SEL )].lim_or_seg = data_limit;
gdt[sel_idx(GAPMDATA_SEL )].size_or_wdct = 0;
gdt[sel_idx(GAPMDATA_SEL )].access = ACC_P | ACC_PL_K | ACC_DATA_W;
/* reflect these changes on physical GDT */
fix_desc(gdt + sel_idx(GAPMCODE32_SEL), 1);
fix_desc(gdt + sel_idx(GAPMCODE16_SEL), 1);
fix_desc(gdt + sel_idx(GAPMDATA_SEL) , 1);
#endif /* MACH_KERNEL */
}
/* 48bit far pointer */
struct addr48 {
static struct addr48 {
u_long offset;
u_short segment;
} apm_addr;
int apm_errno;
static int apm_errno;
inline
int
@ -307,7 +251,7 @@ apm_suspend_system(struct apm_softc *sc)
* If your laptop can control the display via APM, please inform me.
* HOSOKAWA, Tatsumi <hosokawa@mt.cs.keio.ac.jp>
*/
int
static int
apm_display_off(void)
{
u_long eax, ebx, ecx;
@ -418,7 +362,7 @@ apm_hook_establish(int apmh, struct apmhook *ah)
}
/* disestablish an apm hook */
void
static void
apm_hook_disestablish(int apmh, struct apmhook *ah)
{
if (apmh < 0 || apmh >= NAPM_HOOK)
@ -434,7 +378,6 @@ static struct timeval diff_time;
static int
apm_default_resume(void *arg)
{
#ifdef __FreeBSD__
int pl;
u_int second, minute, hour;
struct timeval resume_time, tmp_time;
@ -454,14 +397,12 @@ apm_default_resume(void *arg)
second %= 60;
log(LOG_NOTICE, "resumed from suspended mode (slept %02d:%02d:%02d)\n",
hour, minute, second);
#endif /* __FreeBSD__ */
return 0;
}
static int
apm_default_suspend(void *arg)
{
#ifdef __FreeBSD__
int pl;
pl = splsoftclock();
@ -470,10 +411,6 @@ apm_default_suspend(void *arg)
microtime(&suspend_time);
timevalsub(&diff_time, &suspend_time);
splx(pl);
#if 0
printf("diff_time = %d:%d\n", diff_time.tv_sec, diff_time.tv_usec);
#endif
#endif /* __FreeBSD__ */
return 0;
}
@ -540,7 +477,7 @@ apm_get_info(struct apm_softc *sc, apm_info_t aip)
/* inform APM BIOS that CPU is idle */
void
static void
apm_cpu_idle(void)
{
struct apm_softc *sc = master_softc; /* XXX */
@ -572,7 +509,7 @@ apm_cpu_idle(void)
}
/* inform APM BIOS that CPU is busy */
void
static void
apm_cpu_busy(void)
{
struct apm_softc *sc = master_softc; /* XXX */
@ -649,22 +586,10 @@ apm_not_halt_cpu(struct apm_softc *sc)
}
/* device driver definitions */
#ifdef __FreeBSD__
static int apmprobe (struct isa_device *);
static int apmattach(struct isa_device *);
struct isa_driver apmdriver = {
apmprobe, apmattach, "apm" };
#endif /* __FreeBSD__ */
#ifdef MACH_KERNEL
int apmprobe(vm_offset_t, struct bus_ctlr *);
void apmattach(struct bus_device *);
static struct bus_device *apminfo[NAPM];
static vm_offset_t apmstd[NAPM] = { 0 };
struct bus_driver apmdriver = {
apmprobe, 0, apmattach, 0, apmstd, "apm", apminfo, 0, 0, 0};
#endif /* MACH_KERNEL */
/*
* probe APM (dummy):
@ -675,21 +600,10 @@ struct bus_driver apmdriver = {
* to use V86 mode in APM initialization.
*/
#ifdef __FreeBSD__
static int
apmprobe(struct isa_device *dvp)
#endif /* __FreeBSD__ */
#ifdef MACH_KERNEL
int
apmprobe(vm_offset_t port, struct bus_ctlr *devc)
#endif /* MACH_KERNEL */
{
#ifdef __FreeBSD__
int unit = dvp->id_unit;
#endif /* __FreeBSD__ */
#ifdef MACH_KERNEL
int unit = devc->unit;
#endif /* MACH_KERNEL */
switch (apm_version) {
case APMINI_CANTFIND:
@ -791,24 +705,12 @@ apm_processevent(struct apm_softc *sc)
* /phk
*/
#ifdef __FreeBSD__
static int
apmattach(struct isa_device *dvp)
#endif /* __FreeBSD__ */
#ifdef MACH_KERNEL
void
apmattach(struct bus_device *dvp)
#endif /* MACH_KERNEL */
{
#ifdef __FreeBSD__
int unit = dvp->id_unit;
char name[32];
#define APM_KERNBASE KERNBASE
#endif /* __FreeBSD__ */
#ifdef MACH_KERNEL
int unit = dvp->unit;
#define APM_KERNBASE VM_MIN_KERNEL_ADDRESS
#endif /* MACH_KERNEL */
struct apm_softc *sc = &apm_softc[unit];
master_softc = sc; /* XXX */
@ -854,12 +756,7 @@ apmattach(struct bus_device *dvp)
sc->cs_limit, sc->ds_limit);
/* setup entry point 48bit pointer */
#ifdef __FreeBSD__
apm_addr.segment = GSEL(GAPMCODE32_SEL, SEL_KPL);
#endif /* __FreeBSD__ */
#ifdef MACH_KERNEL
apm_addr.segment = GAPMCODE32_SEL;
#endif /* MACH_KERNEL */
apm_addr.offset = sc->cs_entry;
/* Try to kick bios into 1.1 mode */
@ -915,17 +812,14 @@ apmattach(struct bus_device *dvp)
sc->initialized = 1;
#ifdef __FreeBSD__
#ifdef DEVFS
sprintf(name,"apm%d",unit);
sc->sc_devfs_token = devfs_add_devsw(
"/", name, &apm_cdevsw, unit, DV_CHR, 0, 0, 0600);
#endif
return 0;
#endif /* __FreeBSD__ */
}
#ifdef __FreeBSD__
static int
apmopen(dev_t dev, int flag, int fmt, struct proc *p)
{
@ -1011,32 +905,3 @@ apm_drvinit(void *unused)
}
SYSINIT(apmdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,apm_drvinit,NULL)
#endif /* __FreeBSD__ */
#ifdef MACH_KERNEL
io_return_t apmopen(dev_t dev, int flag, io_req_t ior)
{
int result;
result = ENXIO;
return result;
}
io_return_t apmclose(dev_t dev, int flag)
{
return 0;
}
io_return_t apmgetstat(dev_t dev, int flavor, int *data, u_int *count)
{
}
io_return_t apmsetstat(dev_t dev, int flavor, int *data, u_int count)
{
}
#endif /* MACH_KERNEL */
#endif /* NAPM > 0 */