summaryrefslogtreecommitdiffstats
path: root/sys/i386
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>1995-02-17 02:22:57 +0000
committerphk <phk@FreeBSD.org>1995-02-17 02:22:57 +0000
commit07489c563c706b6c4a660268e30e2242c5294049 (patch)
treed32f9f8cc24d9d0cee4bcb4e4423df81b41475f6 /sys/i386
parenta40b30676abee4b79054303f04b9293014518de0 (diff)
downloadFreeBSD-src-07489c563c706b6c4a660268e30e2242c5294049.zip
FreeBSD-src-07489c563c706b6c4a660268e30e2242c5294049.tar.gz
This is the latest version of the APM stuff from HOSOKAWA, I have looked
briefly over it, and see some serious architectural issues in this stuff. On the other hand, I doubt that we will have any solution to these issues before 2.1, so we might as well leave this in. Most of the stuff is bracketed by #ifdef's so it shouldn't matter too much in the normal case. Reviewed by: phk Submitted by: HOSOKAWA, Tatsumi <hosokawa@mt.cs.keio.ac.jp>
Diffstat (limited to 'sys/i386')
-rw-r--r--sys/i386/apm/apm.c655
-rw-r--r--sys/i386/apm/apm_init/Makefile8
-rw-r--r--sys/i386/apm/apm_init/apm_init.S14
-rw-r--r--sys/i386/apm/apm_init/apm_init.inc70
-rw-r--r--sys/i386/apm/apm_init/bin2asm.c20
-rw-r--r--sys/i386/apm/apm_init/real_prot.h4
-rw-r--r--sys/i386/apm/apm_init/table.c6
-rw-r--r--sys/i386/apm/apm_setup.h3
-rw-r--r--sys/i386/apm/apm_setup.s134
-rw-r--r--sys/i386/bios/apm.c655
-rw-r--r--sys/i386/bios/apm_init/Makefile8
-rw-r--r--sys/i386/bios/apm_init/apm_init.S14
-rw-r--r--sys/i386/bios/apm_init/apm_init.inc70
-rw-r--r--sys/i386/bios/apm_init/bin2asm.c20
-rw-r--r--sys/i386/bios/apm_init/real_prot.h4
-rw-r--r--sys/i386/bios/apm_init/table.c6
-rw-r--r--sys/i386/bios/apm_setup.h3
-rw-r--r--sys/i386/bios/apm_setup.s134
-rw-r--r--sys/i386/conf/LINT12
-rw-r--r--sys/i386/conf/NOTES12
-rw-r--r--sys/i386/conf/files.i3865
-rw-r--r--sys/i386/i386/locore.s99
-rw-r--r--sys/i386/i386/swtch.s40
-rw-r--r--sys/i386/include/apm_bios.h47
-rw-r--r--sys/i386/include/apm_segments.h4
-rw-r--r--sys/i386/isa/icu.s9
-rw-r--r--sys/i386/isa/if_ze.c404
-rw-r--r--sys/i386/isa/if_zp.c2266
-rw-r--r--sys/i386/isa/if_zpreg.h295
-rw-r--r--sys/i386/isa/isa.c4
-rw-r--r--sys/i386/isa/pcic.c249
-rw-r--r--sys/i386/isa/pcic.h181
-rw-r--r--sys/i386/isa/syscons.c33
33 files changed, 4634 insertions, 854 deletions
diff --git a/sys/i386/apm/apm.c b/sys/i386/apm/apm.c
index b9f500b..38f5d8f 100644
--- a/sys/i386/apm/apm.c
+++ b/sys/i386/apm/apm.c
@@ -1,8 +1,8 @@
-#define APM_DEBUG 1
/*
- * LP (Laptop Package)
- *
- * Copyright (c) 1994 by HOSOKAWA, Tatsumi <hosokawa@mt.cs.keio.ac.jp>
+ * 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>
*
* This software may be used, modified, copied, and distributed, in
* both source and binary form provided that the above copyright and
@@ -13,13 +13,14 @@
*
* Sep, 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD)
*
- * $Id: apm.c,v 1.9 1994/12/16 07:09:22 phk Exp $
+ * $Id: apm.c,v 1.10 1994/12/16 07:31:47 phk Exp $
*/
#include "apm.h"
#if NAPM > 0
+#ifdef __FreeBSD__
#include <sys/param.h>
#include "conf.h"
#include <sys/kernel.h>
@@ -38,27 +39,73 @@
#include <vm/vm.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 */
/* static data */
-static int apm_initialized = 0, active = 0, halt_cpu = 1;
-static u_int minorversion, majorversion;
-static u_int cs32_base, cs16_base, ds_base;
-static u_int cs_limit, ds_limit;
-static u_int cs_entry;
-static u_int intversion;
-static int idle_cpu, disabled, disengaged;
+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;
+};
+
+static struct apm_softc apm_softc[NAPM];
+static struct apm_softc *master_softc = NULL; /* XXX */
+struct apmhook *hook[NAPM_HOOK]; /* XXX */
+#ifdef APM_SLOWSTART
+int apm_slowstart = 0;
+int apm_ss_cnt = 0;
+static int apm_slowstart_p = 0;
+int apm_slowstart_stat = 0;
+#endif /* APM_SLOWSTART */
+
+#ifdef MACH_KERNEL
+extern struct fake_descriptor gdt[GDTSZ];
+extern void fix_desc(struct fake_descriptor *, int);
+#endif /* MACH_KERNEL */
#define is_enabled(foo) ((foo) ? "enabled" : "disabled")
/* Map version number to integer (keeps ordering of version numbers) */
#define INTVERSION(major, minor) ((major)*100 + (minor))
+#ifdef __FreeBSD__
static timeout_t apm_timeout;
+#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;
@@ -75,6 +122,31 @@ 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 */
@@ -87,7 +159,7 @@ int apm_errno;
inline
int
-apm_int(u_long *eax,u_long *ebx,u_long *ecx)
+apm_int(u_long *eax, u_long *ebx, u_long *ecx)
{
u_long cf;
__asm ("pushl %%ebp
@@ -112,76 +184,76 @@ apm_int(u_long *eax,u_long *ebx,u_long *ecx)
/* enable/disable power management */
static int
-apm_enable_disable_pm(int enable)
+apm_enable_disable_pm(struct apm_softc *sc, int enable)
{
- u_long eax,ebx,ecx;
+ u_long eax, ebx, ecx;
- eax = (APM_BIOS<<8) | APM_ENABLEDISABLEPM;
+ eax = (APM_BIOS << 8) | APM_ENABLEDISABLEPM;
- if (intversion >= INTVERSION(1, 1)) {
+ if (sc->intversion >= INTVERSION(1, 1)) {
ebx = PMDV_ALLDEV;
} else {
ebx = 0xffff; /* APM version 1.0 only */
}
ecx = enable;
- return apm_int(&eax,&ebx,&ecx);
+ return apm_int(&eax, &ebx, &ecx);
}
/* Tell APM-BIOS that WE will do 1.1 and see what they say... */
static void
-apm_driver_version()
+apm_driver_version(void)
{
- u_long eax,ebx,ecx,i;
+ u_long eax, ebx, ecx, i;
#ifdef APM_DEBUG
eax = (APM_BIOS<<8) | APM_INSTCHECK;
ebx = 0x0;
ecx = 0x0101;
- i = apm_int(&eax,&ebx,&ecx);
+ i = apm_int(&eax, &ebx, &ecx);
printf("[%04lx %04lx %04lx %ld %02x]\n",
- eax,ebx,ecx,i,apm_errno);
+ eax, ebx, ecx, i, apm_errno);
#endif
- eax = (APM_BIOS<<8) | APM_DRVVERSION;
+ eax = (APM_BIOS << 8) | APM_DRVVERSION;
ebx = 0x0;
ecx = 0x0101;
- if(!apm_int(&eax,&ebx,&ecx))
+ if(!apm_int(&eax, &ebx, &ecx))
apm_version = eax & 0xffff;
#ifdef APM_DEBUG
- eax = (APM_BIOS<<8) | APM_INSTCHECK;
+ eax = (APM_BIOS << 8) | APM_INSTCHECK;
ebx = 0x0;
ecx = 0x0101;
- i = apm_int(&eax,&ebx,&ecx);
+ i = apm_int(&eax, &ebx, &ecx);
printf("[%04lx %04lx %04lx %ld %02x]\n",
- eax,ebx,ecx,i,apm_errno);
+ eax, ebx, ecx, i, apm_errno);
#endif
}
/* engage/disengage power management (APM 1.1 or later) */
static int
-apm_engage_disengage_pm(int engage)
+apm_engage_disengage_pm(struct apm_softc *sc, int engage)
{
- u_long eax,ebx,ecx,i;
+ u_long eax, ebx, ecx, i;
- eax = (APM_BIOS<<8) | APM_ENGAGEDISENGAGEPM;
+ eax = (APM_BIOS << 8) | APM_ENGAGEDISENGAGEPM;
ebx = PMDV_ALLDEV;
ecx = engage;
- i = apm_int(&eax,&ebx,&ecx);
+ i = apm_int(&eax, &ebx, &ecx);
return i;
}
/* get PM event */
static u_int
-apm_getevent(void)
+apm_getevent(struct apm_softc *sc)
{
- u_long eax,ebx,ecx;
+ u_long eax, ebx, ecx;
- eax = (APM_BIOS<<8) | APM_GETPMEVENT;
+ eax = (APM_BIOS << 8) | APM_GETPMEVENT;
ebx = 0;
ecx = 0;
- if (apm_int(&eax,&ebx,&ecx))
+ if (apm_int(&eax, &ebx, &ecx))
return PMEV_NOEVENT;
return ebx & 0xffff;
@@ -189,39 +261,171 @@ apm_getevent(void)
/* suspend entire system */
static int
-apm_suspend_system(void)
+apm_suspend_system(struct apm_softc *sc)
{
- u_long eax,ebx,ecx;
-
- eax = (APM_BIOS<<8) | APM_SETPWSTATE;
+ u_long eax, ebx, ecx;
+
+ eax = (APM_BIOS << 8) | APM_SETPWSTATE;
ebx = PMDV_ALLDEV;
ecx = PMST_SUSPEND;
- if (apm_int(&eax,&ebx,&ecx)) {
+ __asm("cli");
+ if (apm_int(&eax, &ebx, &ecx)) {
+ __asm("sti");
printf("Entire system suspend failure: errcode = %ld\n",
0xff & (eax >> 8));
return 1;
}
+ __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>
+ */
+int
+apm_display_off(void)
+{
+ u_long eax, ebx, ecx;
+
+ eax = (APM_BIOS << 8) | APM_SETPWSTATE;
+ ebx = PMDV_2NDSTORAGE0;
+ ecx = PMST_STANDBY;
+ if (apm_int(&eax, &ebx, &ecx)) {
+ printf("Display off failure: errcode = %ld\n",
+ 0xff & (eax >> 8));
+ return 1;
+ }
+
return 0;
}
/* APM Battery low handler */
static void
-apm_battery_low(void)
+apm_battery_low(struct apm_softc *sc)
{
printf("\007\007 * * * BATTERY IS LOW * * * \007\007");
}
+/* 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;
+}
+
+static void
+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 */
+static void
+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);
+ }
+ }
+}
+
+
+/* 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 */
+void
+apm_hook_disestablish(int apmh, struct apmhook *ah)
+{
+ if (apmh < 0 || apmh >= NAPM_HOOK)
+ return;
+
+ apm_del_hook(&hook[apmh], ah);
+}
+
+
static struct timeval suspend_time;
+static struct timeval diff_time;
static int
-apm_default_resume(void)
+apm_default_resume(struct apm_softc *sc)
{
+#ifdef __FreeBSD__
+ int pl;
u_int second, minute, hour;
- struct timeval resume_time;
+ struct timeval resume_time, tmp_time;
- inittodr(0); /* adjust time to RTC */
+ /* modified for adjkerntz */
+ pl = splsoftclock();
+ inittodr(0); /* adjust time to RTC */
microtime(&resume_time);
+ tmp_time = time; /* because 'time' is volatile */
+ timevaladd(&tmp_time, &diff_time);
+ time = tmp_time;
+ splx(pl);
second = resume_time.tv_sec - suspend_time.tv_sec;
hour = second / 3600;
second %= 3600;
@@ -229,48 +433,99 @@ apm_default_resume(void)
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)
{
+#ifdef __FreeBSD__
int pl;
+
+ pl = splsoftclock();
+ microtime(&diff_time);
+ inittodr(0);
microtime(&suspend_time);
- apm_suspend_system();
+ 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;
}
+static void apm_processevent(struct apm_softc *);
+
+/*
+ * Public interface to the suspend/resume:
+ *
+ * Execute suspend and resume hook before and after sleep, respectively.
+ *
+ */
+
+void
+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]);
+ }
+}
+
+
/* get APM information */
static int
-apm_get_info(apm_info_t aip)
+apm_get_info(struct apm_softc *sc, apm_info_t aip)
{
- u_long eax,ebx,ecx;
+ u_long eax, ebx, ecx;
- eax = (APM_BIOS<<8)|APM_GETPWSTATUS;
+ eax = (APM_BIOS << 8) | APM_GETPWSTATUS;
ebx = PMDV_ALLDEV;
ecx = 0;
- if (apm_int(&eax,&ebx,&ecx))
+ if (apm_int(&eax, &ebx, &ecx))
return 1;
aip->ai_acline = (ebx >> 8) & 0xff;
aip->ai_batt_stat = ebx & 0xff;
aip->ai_batt_life = ecx & 0xff;
- aip->ai_major = (u_int)majorversion;
- aip->ai_minor = (u_int)minorversion;
+ aip->ai_major = (u_int)sc->majorversion;
+ aip->ai_minor = (u_int)sc->minorversion;
return 0;
}
-static void apm_processevent(void);
-
/* inform APM BIOS that CPU is idle */
void
apm_cpu_idle(void)
{
- if (idle_cpu) {
- if (active) {
+ struct apm_softc *sc = master_softc; /* XXX */
+
+ if (sc->idle_cpu) {
+ if (sc->active) {
__asm ("movw $0x5305, %ax; lcall _apm_addr");
}
}
@@ -284,7 +539,13 @@ apm_cpu_idle(void)
* "hlt" operation from swtch() and managed it under
* APM driver.
*/
- if (!active || halt_cpu) {
+ /*
+ * UKAI Note: on NetBSD, idle() called from cpu_switch()
+ * doesn't halt CPU, so halt_cpu may not need on NetBSD/i386
+ * or only "sti" operation would be needed.
+ */
+
+ if (!sc->active || sc->halt_cpu) {
__asm("sti ; hlt"); /* wait for interrupt */
}
}
@@ -293,7 +554,9 @@ apm_cpu_idle(void)
void
apm_cpu_busy(void)
{
- if (idle_cpu && active) {
+ struct apm_softc *sc = master_softc; /* XXX */
+
+ if (sc->idle_cpu && sc->active) {
__asm("movw $0x5306, %ax; lcall _apm_addr");
}
}
@@ -306,59 +569,81 @@ apm_cpu_busy(void)
*/
static void
-apm_timeout(void *arg1)
+apm_timeout(void *arg)
{
- apm_processevent();
- timeout(apm_timeout, NULL, hz - 1 ); /* More than 1 Hz */
+ struct apm_softc *sc = arg;
+
+ apm_processevent(sc);
+ timeout(apm_timeout, (void *)sc, hz - 1 ); /* More than 1 Hz */
}
/* enable APM BIOS */
static void
-apm_event_enable(void)
+apm_event_enable(struct apm_softc *sc)
{
#ifdef APM_DEBUG
printf("called apm_event_enable()\n");
#endif
- if (apm_initialized) {
- active = 1;
- apm_timeout(0);
+ if (sc->initialized) {
+ sc->active = 1;
+ apm_timeout(sc);
}
}
/* disable APM BIOS */
static void
-apm_event_disable(void)
+apm_event_disable(struct apm_softc *sc)
{
#ifdef APM_DEBUG
printf("called apm_event_disable()\n");
#endif
- if (apm_initialized) {
+ if (sc->initialized) {
untimeout(apm_timeout, NULL);
- active = 0;
+ sc->active = 0;
}
}
/* halt CPU in scheduling loop */
-static void apm_halt_cpu(void)
+static void
+apm_halt_cpu(struct apm_softc *sc)
{
- if (apm_initialized) {
- halt_cpu = 1;
+ if (sc->initialized) {
+ sc->halt_cpu = 1;
}
+#ifdef APM_SLOWSTART
+ apm_slowstart = 0;
+#endif /* APM_SLOWSTART */
}
/* don't halt CPU in scheduling loop */
-static void apm_not_halt_cpu(void)
+static void
+apm_not_halt_cpu(struct apm_softc *sc)
{
- if (apm_initialized) {
- halt_cpu = 0;
+ if (sc->initialized) {
+ sc->halt_cpu = 0;
}
+#ifdef APM_SLOWSTART
+ apm_slowstart = apm_slowstart_p;
+#endif /* APM_SLOWSTART */
}
/* device driver definitions */
+#ifdef __FreeBSD__
int apmprobe (struct isa_device *);
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 */
-struct isa_driver apmdriver = { apmprobe, apmattach, "apm" };
/*
* probe APM (dummy):
@@ -370,31 +655,40 @@ struct isa_driver apmdriver = { apmprobe, apmattach, "apm" };
*/
int
-apmprobe(struct isa_device *dvp)
+#ifdef __FreeBSD__
+ apmprobe(struct isa_device *dvp)
+#endif /* __FreeBSD__ */
+#ifdef MACH_KERNEL
+ 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 */
+ struct apm_softc *sc = &apm_softc[unit];
+
switch (apm_version) {
case APMINI_CANTFIND:
/* silent */
return 0;
case APMINI_NOT32BIT:
- printf("apm%d: 32bit connection is not supported.\n",
- dvp->id_unit);
+ printf("apm%d: 32bit connection is not supported.\n", unit);
return 0;
case APMINI_CONNECTERR:
- printf("apm%d: 32-bit connection error.\n", dvp->id_unit);
+ printf("apm%d: 32-bit connection error.\n", unit);
return 0;
}
- if ((apm_version & 0xff00) != 0x0100) return 0;
- if ((apm_version & 0x00f0) >= 0x00a0) return 0;
- if ((apm_version & 0x000f) >= 0x000a) return 0;
return -1;
}
/* Process APM event */
static void
-apm_processevent(void)
+apm_processevent(struct apm_softc *sc)
{
int apm_event;
@@ -404,39 +698,35 @@ apm_processevent(void)
#else
# define OPMEV_DEBUGMESSAGE(symbol) case symbol:
#endif
-
while (1) {
- apm_event = apm_getevent();
+ apm_event = apm_getevent(sc);
if (apm_event == PMEV_NOEVENT)
break;
switch (apm_event) {
OPMEV_DEBUGMESSAGE(PMEV_STANDBYREQ);
- apm_default_suspend();
+ apm_suspend();
break;
OPMEV_DEBUGMESSAGE(PMEV_SUSPENDREQ);
- apm_default_suspend();
+ apm_suspend();
break;
OPMEV_DEBUGMESSAGE(PMEV_USERSUSPENDREQ);
- apm_default_suspend();
+ apm_suspend();
break;
-
OPMEV_DEBUGMESSAGE(PMEV_CRITSUSPEND);
- apm_default_suspend();
+ apm_suspend();
break;
-
OPMEV_DEBUGMESSAGE(PMEV_NORMRESUME);
- apm_default_resume();
+ apm_resume();
break;
OPMEV_DEBUGMESSAGE(PMEV_CRITRESUME);
- apm_default_resume();
+ apm_resume();
break;
OPMEV_DEBUGMESSAGE(PMEV_STANDBYRESUME);
- apm_default_resume();
+ apm_resume();
break;
-
OPMEV_DEBUGMESSAGE(PMEV_BATTERYLOW);
- apm_battery_low();
- apm_default_suspend();
+ apm_battery_low(sc);
+ apm_suspend();
break;
OPMEV_DEBUGMESSAGE(PMEV_POWERSTATECHANGE);
@@ -480,94 +770,147 @@ apm_processevent(void)
* /phk
*/
+#ifdef __FreeBSD__
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;
+#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];
+ int i;
+
+ master_softc = sc; /* XXX */
+ sc->initialized = 0;
+ sc->active = 0;
+ sc->halt_cpu = 1;
/* setup APM parameters */
- cs32_base = (apm_cs32_base << 4) + KERNBASE;
- cs16_base = (apm_cs16_base << 4) + KERNBASE;
- ds_base = (apm_ds_base << 4) + KERNBASE;
- cs_limit = apm_cs_limit;
- ds_limit = apm_ds_limit;
- cs_entry = apm_cs_entry;
-
- idle_cpu = ((apm_flags & APM_CPUIDLE_SLOW) != 0);
- disabled = ((apm_flags & APM_DISABLED) != 0);
- disengaged = ((apm_flags & APM_DISENGAGED) != 0);
+ 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);
+
+#ifdef APM_SLOWSTART
+ if (sc->idle_cpu) {
+ apm_slowstart = apm_slowstart_p = 1;
+ }
+#endif
/* print bootstrap messages */
#ifdef APM_DEBUG
printf(" found APM BIOS version %04x\n", apm_version);
printf("apm%d: Code32 0x%08x, Code16 0x%08x, Data 0x%08x\n",
- dvp->id_unit, cs32_base, cs16_base, ds_base);
+ unit, sc->cs32_base, sc->cs16_base, sc->ds_base);
printf("apm%d: Code entry 0x%08x, Idling CPU %s, Management %s\n",
- dvp->id_unit, cs_entry, is_enabled(idle_cpu),
- is_enabled(!disabled));
+ unit, sc->cs_entry, is_enabled(sc->idle_cpu),
+ is_enabled(!sc->disabled));
printf("apm%d: CS_limit=%x, DS_limit=%x\n",
- dvp->id_unit, cs_limit,ds_limit);
-
+ unit, sc->cs_limit, sc->ds_limit);
#endif /* APM_DEBUG */
- cs_limit = 0xffff;
- ds_limit = 0xffff;
+ sc->cs_limit = 0xffff;
+ sc->ds_limit = 0xffff;
/* setup GDT */
- setup_apm_gdt(cs32_base, cs16_base, ds_base, cs_limit, ds_limit);
+ setup_apm_gdt(sc->cs32_base, sc->cs16_base, sc->ds_base,
+ sc->cs_limit, sc->ds_limit);
/* setup entry point 48bit pointer */
+#ifdef __FreeBSD__
apm_addr.segment = GSEL(GAPMCODE32_SEL, SEL_KPL);
- apm_addr.offset = cs_entry;
+#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 */
apm_driver_version();
-
- minorversion = ((apm_version & 0x00f0) >> 4) * 10 +
+ sc->minorversion = ((apm_version & 0x00f0) >> 4) * 10 +
((apm_version & 0x000f) >> 0);
- majorversion = ((apm_version & 0xf000) >> 12) * 10 +
+ sc->majorversion = ((apm_version & 0xf000) >> 12) * 10 +
((apm_version & 0x0f00) >> 8);
- intversion = INTVERSION(majorversion, minorversion);
+ sc->intversion = INTVERSION(sc->majorversion, sc->minorversion);
- if (intversion >= INTVERSION(1, 1)) {
+ if (sc->intversion >= INTVERSION(1, 1)) {
printf("apm%d: Engaged control %s\n",
- dvp->id_unit, is_enabled(!disengaged));
+ unit, is_enabled(!sc->disengaged));
}
- printf(" found APM BIOS version %d.%d\n", majorversion, minorversion);
- printf("apm%d: Idling CPU %s\n", dvp->id_unit, is_enabled(idle_cpu));
+ printf(" found APM BIOS version %d.%d\n",
+ sc->majorversion, sc->minorversion);
+ printf("apm%d: Idling CPU %s\n", unit, is_enabled(sc->idle_cpu));
/* enable power management */
- if (disabled) {
- if (apm_enable_disable_pm(1)) {
+ if (sc->disabled) {
+ if (apm_enable_disable_pm(sc, 1)) {
printf("Warning: APM enable function failed! [%x]\n",
apm_errno);
}
}
/* engage power managment (APM 1.1 or later) */
- if (intversion >= INTVERSION(1, 1) && disengaged) {
- if (apm_engage_disengage_pm(1)) {
+ if (sc->intversion >= INTVERSION(1, 1) && sc->disengaged) {
+ if (apm_engage_disengage_pm(sc, 1)) {
printf("Warning: APM engage function failed [%x]\n",
apm_errno);
}
}
- apm_initialized = 1;
+ /* 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;
- apm_event_enable();
+ apm_hook_establish(APM_HOOK_SUSPEND, &sc->sc_suspend);
+ apm_hook_establish(APM_HOOK_RESUME , &sc->sc_resume);
+ apm_event_enable(sc);
+
+ sc->initialized = 1;
+
+#ifdef __FreeBSD__
return 0;
+#endif /* __FreeBSD__ */
}
+#ifdef __FreeBSD__
int
apmopen(dev_t dev, int flag, int fmt, struct proc *p)
{
- if (!apm_initialized) {
+ struct apm_softc *sc = &apm_softc[minor(dev)];
+
+ if (minor(dev) >= NAPM) {
+ return (ENXIO);
+ }
+ if (!sc->initialized) {
return ENXIO;
}
- if (minor(dev))
- return (ENXIO);
return 0;
}
@@ -580,6 +923,7 @@ apmclose(dev_t dev, int flag, int fmt, struct proc *p)
int
apmioctl(dev_t dev, int cmd, caddr_t addr, int flag, struct proc *p)
{
+ struct apm_softc *sc = &apm_softc[minor(dev)];
int error = 0;
int pl;
@@ -587,40 +931,67 @@ apmioctl(dev_t dev, int cmd, caddr_t addr, int flag, struct proc *p)
printf("APM ioctl: minor = %d, cmd = 0x%x\n", minor(dev), cmd);
#endif
- pl = splhigh();
- if (minor(dev) != 0) {
+ if (minor(dev) >= NAPM) {
return ENXIO;
}
- if (!apm_initialized) {
+ if (!sc->initialized) {
return ENXIO;
}
switch (cmd) {
case APMIO_SUSPEND:
- apm_default_suspend();
+ apm_suspend();
break;
case APMIO_GETINFO:
- if (apm_get_info((apm_info_t)addr)) {
+ if (apm_get_info(sc, (apm_info_t)addr)) {
error = ENXIO;
}
break;
case APMIO_ENABLE:
- apm_event_enable();
+ apm_event_enable(sc);
break;
case APMIO_DISABLE:
- apm_event_disable();
+ apm_event_disable(sc);
break;
case APMIO_HALTCPU:
- apm_halt_cpu();
+ apm_halt_cpu(sc);
break;
case APMIO_NOTHALTCPU:
- apm_not_halt_cpu();
+ apm_not_halt_cpu(sc);
+ break;
+ case APMIO_DISPLAYOFF:
+ if (apm_display_off()) {
+ error = ENXIO;
+ }
break;
default:
error = EINVAL;
break;
}
- splx(pl);
return error;
}
+#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 */
diff --git a/sys/i386/apm/apm_init/Makefile b/sys/i386/apm/apm_init/Makefile
index fc6464e..1d9c5c3 100644
--- a/sys/i386/apm/apm_init/Makefile
+++ b/sys/i386/apm/apm_init/Makefile
@@ -1,9 +1,9 @@
#
-# LP (Laptop Package)
+# APM (Advanced Power Management) BIOS Device Driver
#
-# (C) 1994 by HOSOKAWA, Tatsumi <hosokawa@mt.cs.keio.ac.jp>
+# Copyright (c) 1994-1995 by HOSOKAWA, Tatsumi <hosokawa@mt.cs.keio.ac.jp>
#
-# This software may be used, modified, copied, and distributed in
+# This software may be used, modified, copied, and distributed, in
# both source and binary form provided that the above copyright and
# these terms are retained. Under no circumstances is the author
# responsible for the proper functioning of this software, nor does
@@ -12,7 +12,7 @@
#
# Sep., 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD)
#
-# $Id$
+# $Id: Makefile,v 1.2 1994/10/01 05:12:29 davidg Exp $
#
OBJS = apm_init.o real_prot.o table.o
diff --git a/sys/i386/apm/apm_init/apm_init.S b/sys/i386/apm/apm_init/apm_init.S
index 5276947..76becc4 100644
--- a/sys/i386/apm/apm_init/apm_init.S
+++ b/sys/i386/apm/apm_init/apm_init.S
@@ -1,7 +1,7 @@
/*
- * LP (Laptop Package)
+ * APM (Advanced Power Management) BIOS Device Driver
*
- * Copyright (C) 1994 by HOSOKAWA, Tatsumi <hosokawa@mt.cs.keio.ac.jp>
+ * Copyright (c) 1994-1995 by HOSOKAWA, Tatsumi <hosokawa@mt.cs.keio.ac.jp>
*
* This software may be used, modified, copied, and distributed, in
* both source and binary form provided that the above copyright and
@@ -12,7 +12,7 @@
*
* Sep., 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD)
*
- * $Id: apm_init.S,v 1.2 1994/10/01 05:12:29 davidg Exp $
+ * $Id: apm_init.S,v 1.3 1994/10/01 21:29:49 phk Exp $
*/
/*
@@ -128,6 +128,7 @@ ENTRY(apm_init)
/* don't support 32bit connection */
jmp finish
1:
+ andl $0x0000ffff, %edx
movl %edx, apm_version
andl $0x0000ffff, %ecx
movl %ecx, apm_flags
@@ -174,15 +175,12 @@ finish:
movl old_esp, %esp /* restore old stack pointer */
movl apm_version, %ebp /* stored to %eax later */
movl apm_flags, %edi
-#if 0
- movw $(BOOTSTRAP_DS_SEL), %ax
- /* restore old data segments */
-#else
movw %fs, %ax
-#endif
movw %ax, %ss
movw %ax, %es
movw %ax, %ds
+ xorl %eax, %eax
+ movw %ax, %fs
movl %ebp, %eax
popl %ebp /* restore old base pointer */
lret /* restore old code segment */
diff --git a/sys/i386/apm/apm_init/apm_init.inc b/sys/i386/apm/apm_init/apm_init.inc
index d88a888..44fc01e 100644
--- a/sys/i386/apm/apm_init/apm_init.inc
+++ b/sys/i386/apm/apm_init/apm_init.inc
@@ -3,51 +3,53 @@
.byte 0xfa, 0x55, 0x66, 0x8c, 0xd8, 0x66, 0x8e, 0xe0
.byte 0x66, 0xb8, 0xf0, 0x00, 0x66, 0x8e, 0xd8, 0x66
- .byte 0x8e, 0xc0, 0x66, 0x8e, 0xd0, 0x89, 0x25, 0x84
+ .byte 0x8e, 0xc0, 0x66, 0x8e, 0xd0, 0x89, 0x25, 0x94
.byte 0x01, 0x00, 0x00, 0xbc, 0x00, 0x00, 0x01, 0x00
- .byte 0x0f, 0x01, 0x0d, 0xa0, 0x01, 0x00, 0x00, 0xe8
- .byte 0x14, 0x01, 0x00, 0x00, 0xb4, 0x53, 0xb0, 0x00
+ .byte 0x0f, 0x01, 0x0d, 0xb0, 0x01, 0x00, 0x00, 0xe8
+ .byte 0x24, 0x01, 0x00, 0x00, 0xb4, 0x53, 0xb0, 0x00
.byte 0x66, 0xbb, 0x00, 0x00, 0x00, 0x00, 0xfb, 0xcd
- .byte 0x15, 0xfa, 0x73, 0x15, 0x66, 0xe8, 0xce, 0x00
- .byte 0x00, 0x00, 0xc7, 0x05, 0x88, 0x01, 0x00, 0x00
- .byte 0xff, 0xff, 0xff, 0xff, 0xe9, 0x8c, 0x00, 0x00
- .byte 0x00, 0x89, 0xc2, 0x66, 0xe8, 0xb7, 0x00, 0x00
+ .byte 0x15, 0xfa, 0x73, 0x15, 0x66, 0xe8, 0xde, 0x00
+ .byte 0x00, 0x00, 0xc7, 0x05, 0x98, 0x01, 0x00, 0x00
+ .byte 0xff, 0xff, 0xff, 0xff, 0xe9, 0x92, 0x00, 0x00
+ .byte 0x00, 0x89, 0xc2, 0x66, 0xe8, 0xc7, 0x00, 0x00
.byte 0x00, 0x80, 0xff, 0x50, 0x75, 0x05, 0x80, 0xfb
- .byte 0x4d, 0x74, 0x0c, 0xc7, 0x05, 0x88, 0x01, 0x00
- .byte 0x00, 0xff, 0xff, 0xff, 0xff, 0xeb, 0x6e, 0xf7
+ .byte 0x4d, 0x74, 0x0c, 0xc7, 0x05, 0x98, 0x01, 0x00
+ .byte 0x00, 0xff, 0xff, 0xff, 0xff, 0xeb, 0x74, 0xf7
.byte 0xc1, 0x02, 0x00, 0x00, 0x00, 0x75, 0x0c, 0xc7
- .byte 0x05, 0x88, 0x01, 0x00, 0x00, 0xfe, 0xff, 0xff
- .byte 0xff, 0xeb, 0x5a, 0x89, 0x15, 0x88, 0x01, 0x00
- .byte 0x00, 0x81, 0xe1, 0xff, 0xff, 0x00, 0x00, 0x89
- .byte 0x0d, 0x8c, 0x01, 0x00, 0x00, 0xe8, 0xa6, 0x00
- .byte 0x00, 0x00, 0xb4, 0x53, 0xb0, 0x03, 0x66, 0xbb
- .byte 0x00, 0x00, 0x00, 0x00, 0xfb, 0xcd, 0x15, 0xfa
- .byte 0x73, 0x12, 0x66, 0xe8, 0x60, 0x00, 0x00, 0x00
- .byte 0xc7, 0x05, 0x88, 0x01, 0x00, 0x00, 0xfd, 0xff
- .byte 0xff, 0xff, 0xeb, 0x21, 0x89, 0xc5, 0x66, 0xe8
- .byte 0x4c, 0x00, 0x00, 0x00, 0xb8, 0xff, 0xff, 0x00
- .byte 0x00, 0x21, 0xc5, 0x21, 0xc1, 0x21, 0xc2, 0x21
- .byte 0xc6, 0x21, 0xc7, 0xc1, 0xe5, 0x10, 0x09, 0xe9
- .byte 0xc1, 0xe7, 0x10, 0x09, 0xfe, 0xfa, 0x0f, 0x01
- .byte 0x1d, 0xa0, 0x01, 0x00, 0x00, 0x8b, 0x25, 0x84
- .byte 0x01, 0x00, 0x00, 0x8b, 0x2d, 0x88, 0x01, 0x00
- .byte 0x00, 0x8b, 0x3d, 0x8c, 0x01, 0x00, 0x00, 0x66
- .byte 0x8c, 0xe0, 0x66, 0x8e, 0xd0, 0x66, 0x8e, 0xc0
- .byte 0x66, 0x8e, 0xd8, 0x89, 0xe8, 0x5d, 0xcb, 0x00
+ .byte 0x05, 0x98, 0x01, 0x00, 0x00, 0xfe, 0xff, 0xff
+ .byte 0xff, 0xeb, 0x60, 0x81, 0xe2, 0xff, 0xff, 0x00
+ .byte 0x00, 0x89, 0x15, 0x98, 0x01, 0x00, 0x00, 0x81
+ .byte 0xe1, 0xff, 0xff, 0x00, 0x00, 0x89, 0x0d, 0x9c
+ .byte 0x01, 0x00, 0x00, 0xe8, 0xb0, 0x00, 0x00, 0x00
+ .byte 0xb4, 0x53, 0xb0, 0x03, 0x66, 0xbb, 0x00, 0x00
+ .byte 0x00, 0x00, 0xfb, 0xcd, 0x15, 0xfa, 0x73, 0x12
+ .byte 0x66, 0xe8, 0x6a, 0x00, 0x00, 0x00, 0xc7, 0x05
+ .byte 0x98, 0x01, 0x00, 0x00, 0xfd, 0xff, 0xff, 0xff
+ .byte 0xeb, 0x21, 0x89, 0xc5, 0x66, 0xe8, 0x56, 0x00
+ .byte 0x00, 0x00, 0xb8, 0xff, 0xff, 0x00, 0x00, 0x21
+ .byte 0xc5, 0x21, 0xc1, 0x21, 0xc2, 0x21, 0xc6, 0x21
+ .byte 0xc7, 0xc1, 0xe5, 0x10, 0x09, 0xe9, 0xc1, 0xe7
+ .byte 0x10, 0x09, 0xfe, 0xfa, 0x0f, 0x01, 0x1d, 0xb0
+ .byte 0x01, 0x00, 0x00, 0x8b, 0x25, 0x94, 0x01, 0x00
+ .byte 0x00, 0x8b, 0x2d, 0x98, 0x01, 0x00, 0x00, 0x8b
+ .byte 0x3d, 0x9c, 0x01, 0x00, 0x00, 0x66, 0x8c, 0xe0
+ .byte 0x66, 0x8e, 0xd0, 0x66, 0x8e, 0xc0, 0x66, 0x8e
+ .byte 0xd8, 0x31, 0xc0, 0x66, 0x8e, 0xe0, 0x89, 0xe8
+ .byte 0x5d, 0xcb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
.byte 0xfa, 0x0f, 0x20, 0xc0, 0x66, 0x83, 0xc8, 0x01
- .byte 0x0f, 0x22, 0xc0, 0x66, 0xea, 0x23, 0x01, 0x00
+ .byte 0x0f, 0x22, 0xc0, 0x66, 0xea, 0x33, 0x01, 0x00
.byte 0x00, 0xe8, 0x00, 0xb8, 0xf0, 0x00, 0x00, 0x00
.byte 0x66, 0x8e, 0xd8, 0x66, 0x8e, 0xd0, 0x66, 0x8e
- .byte 0xc0, 0x0f, 0x01, 0x1d, 0xa0, 0x01, 0x00, 0x00
+ .byte 0xc0, 0x0f, 0x01, 0x1d, 0xb0, 0x01, 0x00, 0x00
.byte 0xc3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
- .byte 0xa1, 0x80, 0x01, 0x00, 0x00, 0xc1, 0xf8, 0x04
- .byte 0x66, 0x50, 0x66, 0xb8, 0x62, 0x01, 0x66, 0x50
- .byte 0xea, 0x57, 0x01, 0x00, 0x00, 0xf8, 0x00, 0x0f
+ .byte 0xa1, 0x90, 0x01, 0x00, 0x00, 0xc1, 0xf8, 0x04
+ .byte 0x66, 0x50, 0x66, 0xb8, 0x72, 0x01, 0x66, 0x50
+ .byte 0xea, 0x67, 0x01, 0x00, 0x00, 0xf8, 0x00, 0x0f
.byte 0x20, 0xc0, 0x66, 0x83, 0xe0, 0xfe, 0x0f, 0x22
.byte 0xc0, 0xcb, 0x66, 0x8c, 0xc8, 0x66, 0x8e, 0xd8
.byte 0x66, 0x8e, 0xd0, 0x66, 0x8e, 0xc0, 0x67, 0x66
- .byte 0x0f, 0x01, 0x1d, 0xa6, 0x01, 0x00, 0x00, 0x66
+ .byte 0x0f, 0x01, 0x1d, 0xb6, 0x01, 0x00, 0x00, 0x66
.byte 0xc3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
.byte 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00
.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
@@ -56,4 +58,4 @@
.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x03
.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
-/* Total size = 0x01b0 */
+/* Total size = 0x01c0 */
diff --git a/sys/i386/apm/apm_init/bin2asm.c b/sys/i386/apm/apm_init/bin2asm.c
index 5577247..791798a 100644
--- a/sys/i386/apm/apm_init/bin2asm.c
+++ b/sys/i386/apm/apm_init/bin2asm.c
@@ -1,9 +1,9 @@
/*
- * LP (Laptop Package)
+ * APM (Advanced Power Management) BIOS Device Driver
*
- * Copyright (C) 1994 by HOSOKAWA, Tatsumi <hosokawa@mt.cs.keio.ac.jp>
+ * Copyright (c) 1994-1995 by HOSOKAWA, Tatsumi <hosokawa@mt.cs.keio.ac.jp>
*
- * This software may be used, modified, copied, and distributed, in
+ * This software may be used, modified, copied, and distributed, in
* both source and binary form provided that the above copyright and
* these terms are retained. Under no circumstances is the author
* responsible for the proper functioning of this software, nor does
@@ -12,7 +12,7 @@
*
* Sep., 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD)
*
- * $Id$
+ * $Id: bin2asm.c,v 1.2 1994/10/01 05:12:30 davidg Exp $
*/
#include <stdio.h>
@@ -21,7 +21,7 @@
int main(int argc, char *argv[])
{
- int c, col;
+ int c, col, lastline;
FILE *infile, *outfile;
if (argc != 3) {
@@ -44,6 +44,8 @@ int main(int argc, char *argv[])
fprintf(outfile, "/* This file is automatically generated by bin2asm */\n");
fprintf(outfile, "/* Original file is '%s' */\n\n", argv[1]);
+ lastline = 0;
+
while ((c = fgetc(infile)) != EOF) {
if (col % NCOLS == 0) {
fprintf(outfile, "\t.byte\t");
@@ -51,12 +53,20 @@ int main(int argc, char *argv[])
fprintf(outfile, "0x%02x", c);
if (col % NCOLS == NCOLS - 1) {
fprintf(outfile, "\n");
+ lastline = 1;
}
else {
fprintf(outfile, ", ");
+ lastline = 0;
}
col++;
}
+ if (!lastline) {
+ do {
+ fprintf(outfile, "0x00, ");
+ } while ((col++) % NCOLS < NCOLS - 2);
+ fprintf(outfile, "0x00\n");
+ }
fprintf(outfile, "\n/* Total size = 0x%04x */\n", col);
diff --git a/sys/i386/apm/apm_init/real_prot.h b/sys/i386/apm/apm_init/real_prot.h
index bc02200..692ebfe 100644
--- a/sys/i386/apm/apm_init/real_prot.h
+++ b/sys/i386/apm/apm_init/real_prot.h
@@ -24,7 +24,7 @@
* the rights to redistribute these changes.
*
* from: Mach, Revision 2.7 92/02/29 15:33:41 rpd
- * $Id: asm.h,v 1.3 1993/10/16 19:11:29 rgrimes Exp $
+ * $Id: real_prot.h,v 1.1 1994/10/01 02:55:52 davidg Exp $
*/
/*
@@ -40,6 +40,8 @@
* use.
*
* Sep., 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD)
+ * Nov., 1994 Commited to FreeBSD 2.0-current
+ * Jan., 1995 Ported to RT-Mach 3.0 MK83g
*/
/*
diff --git a/sys/i386/apm/apm_init/table.c b/sys/i386/apm/apm_init/table.c
index f859bff..607fcc6 100644
--- a/sys/i386/apm/apm_init/table.c
+++ b/sys/i386/apm/apm_init/table.c
@@ -1,7 +1,7 @@
/*
- * LP (Laptop Package)
+ * APM (Advanced Power Management) BIOS Device Driver
*
- * Copyright (C) 1994 by HOSOKAWA, Tatsumi <hosokawa@mt.cs.keio.ac.jp>
+ * Copyright (c) 1994-1995 by HOSOKAWA, Tatsumi <hosokawa@mt.cs.keio.ac.jp>
*
* This software may be used, modified, copied, and distributed, in
* both source and binary form provided that the above copyright and
@@ -12,7 +12,7 @@
*
* Sep., 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD)
*
- * $Id$
+ * $Id: table.c,v 1.2 1994/10/01 05:12:31 davidg Exp $
*/
#include <apm_bios.h>
diff --git a/sys/i386/apm/apm_setup.h b/sys/i386/apm/apm_setup.h
index 6f564c9..55f126d 100644
--- a/sys/i386/apm/apm_setup.h
+++ b/sys/i386/apm/apm_setup.h
@@ -12,7 +12,7 @@
*
* Sep., 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD)
*
- * $Id$
+ * $Id: apm_setup.h,v 1.2 1994/10/01 05:12:23 davidg Exp $
*/
extern u_long apm_version;
@@ -23,3 +23,4 @@ extern u_short apm_ds_base;
extern u_short apm_cs_limit;
extern u_short apm_ds_limit;
extern u_short apm_flags;
+extern u_short kernelbase;
diff --git a/sys/i386/apm/apm_setup.s b/sys/i386/apm/apm_setup.s
index d354679..b3ae77d 100644
--- a/sys/i386/apm/apm_setup.s
+++ b/sys/i386/apm/apm_setup.s
@@ -12,14 +12,29 @@
*
* Sep., 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD)
*
- * $Id: apm_setup.s,v 1.3 1994/10/02 01:45:42 phk Exp $
+ * $Id: apm_setup.s,v 1.4 1994/10/10 01:14:03 phk Exp $
*/
-#define ASM
+#include "apm.h"
+
+#if NAPM > 0
-#include <machine/asmacros.h>
-#include "assym.s"
+#ifdef __FreeBSD__
+#define ASSEMBLER
+#include "assym.s" /* system definitions */
+#include <machine/asmacros.h> /* miscellaneous asm macros */
#include <machine/apm_bios.h>
+#include <machine/apm_segments.h>
+#define PADDR(addr) addr-KERNBASE
+#endif /* __FreeBSD__ */
+
+#ifdef MACH_KERNEL
+#define ASSEMBLER
+#include "assym.s"
+#include "i386at/apm_bios.h"
+#include "i386at/apm_segments.h"
+#define PADDR(addr) addr-KERNELBASE
+#endif /* MACH_KERNEL */
.file "apm_setup.s"
@@ -28,7 +43,12 @@ _apm_init_image:
.globl _apm_init_image
1:
-#include "apm_init/apm_init.inc"
+#ifdef __FreeBSD__
+#include "i386/apm/apm_init/apm_init.inc"
+#endif /* __FreeBSD__ */
+#ifdef MACH_KERNEL
+#include "i386at/apm_init/apm_init.inc"
+#endif /* MACH_KERNEL */
2:
_apm_init_image_size:
@@ -66,4 +86,108 @@ _apm_ds_limit:
_apm_flags:
.globl _apm_flags
.word 0
+ .globl _apm_current_gdt_pdesc /* current GDT pseudo desc. */
+_apm_current_gdt_pdesc:
+ .word 0, 0, 0
+
+ .globl _bootstrap_gdt
+_bootstrap_gdt:
+ .space SIZEOF_GDT*BOOTSTRAP_GDT_NUM
+
+ .text
+_apm_setup:
+ .globl _apm_setup
+
+ /*
+ * Setup APM BIOS:
+ *
+ * APM BIOS initialization should be done from real mode or V86 mode.
+ *
+ * (by HOSOKAWA, Tatsumi <hosokawa@mt.cs.keio.ac.jp>)
+ */
+
+ /*
+ * Don't trust the value of %fs and %gs (some AT-compatible BIOS
+ * implementations leave junk values in these segment registers
+ * on bootstrap)
+ */
+ xorl %eax, %eax /* null selector */
+ movw %ax, %fs
+ movw %ax, %gs
+
+ /*
+ * Copy APM initializer under 1MB boundary:
+ *
+ * APM initializer program must switch the CPU to real mode.
+ * But FreeBSD kernel runs above 1MB boundary. So we must
+ * copy the initializer code to conventional memory.
+ */
+ movl PADDR(_apm_init_image_size), %ecx /* size */
+ lea PADDR(_apm_init_image), %esi /* source */
+ movl $ APM_OURADDR, %edi /* destination */
+ cld
+ rep
+ movsb
+
+ /* get GDT base */
+ sgdt PADDR(_apm_current_gdt_pdesc)
+
+ /* copy GDT to _bootstrap_gdt */
+ xorl %ecx, %ecx
+ movw PADDR(_apm_current_gdt_pdesc), %cx
+ movl PADDR(_apm_current_gdt_pdesc + 2), %esi
+ lea PADDR(_bootstrap_gdt), %edi
+ cld
+ rep
+ movsb
+
+ /* setup GDT pseudo descriptor */
+ movw $(SIZEOF_GDT*BOOTSTRAP_GDT_NUM), %ax
+ movw %ax, PADDR(_apm_current_gdt_pdesc)
+ leal PADDR(_bootstrap_gdt), %eax
+ movl %eax, PADDR(_apm_current_gdt_pdesc + 2)
+
+ /* load new GDTR */
+ lgdt PADDR(_apm_current_gdt_pdesc)
+
+ /* setup GDT for APM initializer */
+ lea PADDR(_bootstrap_gdt), %ecx
+ movl $(APM_OURADDR), %eax /* use %ax for 15..0 */
+ movl %eax, %ebx
+ shrl $16, %ebx /* use %bl for 23..16 */
+ /* use %bh for 31..24 */
+#define APM_SETUP_GDT(index, attrib) \
+ movl $(index), %si ; \
+ lea 0(%ecx,%esi,8), %edx ; \
+ movw $0xffff, (%edx) ; \
+ movw %ax, 2(%edx) ; \
+ movb %bl, 4(%edx) ; \
+ movw $(attrib), 5(%edx) ; \
+ movb %bh, 7(%edx)
+
+ APM_SETUP_GDT(APM_INIT_CS_INDEX , CS32_ATTRIB)
+ APM_SETUP_GDT(APM_INIT_DS_INDEX , DS32_ATTRIB)
+ APM_SETUP_GDT(APM_INIT_CS16_INDEX, CS16_ATTRIB)
+
+ /*
+ * Call the initializer:
+ *
+ * direct intersegment call to conventional memory code
+ */
+ .byte 0x9a /* actually, lcall $APM_INIT_CS_SEL, $0 */
+ .long 0
+ .word APM_INIT_CS_SEL
+
+ movl %eax, PADDR(_apm_version)
+ movl %ebx, PADDR(_apm_cs_entry)
+ movw %cx, PADDR(_apm_cs32_base)
+ shrl $16, %ecx
+ movw %cx, PADDR(_apm_cs16_base)
+ movw %dx, PADDR(_apm_ds_base)
+ movw %si, PADDR(_apm_cs_limit)
+ shrl $16, %esi
+ movw %si, PADDR(_apm_ds_limit)
+ movw %di, PADDR(_apm_flags)
+ ret
+#endif NAPM > 0
diff --git a/sys/i386/bios/apm.c b/sys/i386/bios/apm.c
index b9f500b..38f5d8f 100644
--- a/sys/i386/bios/apm.c
+++ b/sys/i386/bios/apm.c
@@ -1,8 +1,8 @@
-#define APM_DEBUG 1
/*
- * LP (Laptop Package)
- *
- * Copyright (c) 1994 by HOSOKAWA, Tatsumi <hosokawa@mt.cs.keio.ac.jp>
+ * 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>
*
* This software may be used, modified, copied, and distributed, in
* both source and binary form provided that the above copyright and
@@ -13,13 +13,14 @@
*
* Sep, 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD)
*
- * $Id: apm.c,v 1.9 1994/12/16 07:09:22 phk Exp $
+ * $Id: apm.c,v 1.10 1994/12/16 07:31:47 phk Exp $
*/
#include "apm.h"
#if NAPM > 0
+#ifdef __FreeBSD__
#include <sys/param.h>
#include "conf.h"
#include <sys/kernel.h>
@@ -38,27 +39,73 @@
#include <vm/vm.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 */
/* static data */
-static int apm_initialized = 0, active = 0, halt_cpu = 1;
-static u_int minorversion, majorversion;
-static u_int cs32_base, cs16_base, ds_base;
-static u_int cs_limit, ds_limit;
-static u_int cs_entry;
-static u_int intversion;
-static int idle_cpu, disabled, disengaged;
+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;
+};
+
+static struct apm_softc apm_softc[NAPM];
+static struct apm_softc *master_softc = NULL; /* XXX */
+struct apmhook *hook[NAPM_HOOK]; /* XXX */
+#ifdef APM_SLOWSTART
+int apm_slowstart = 0;
+int apm_ss_cnt = 0;
+static int apm_slowstart_p = 0;
+int apm_slowstart_stat = 0;
+#endif /* APM_SLOWSTART */
+
+#ifdef MACH_KERNEL
+extern struct fake_descriptor gdt[GDTSZ];
+extern void fix_desc(struct fake_descriptor *, int);
+#endif /* MACH_KERNEL */
#define is_enabled(foo) ((foo) ? "enabled" : "disabled")
/* Map version number to integer (keeps ordering of version numbers) */
#define INTVERSION(major, minor) ((major)*100 + (minor))
+#ifdef __FreeBSD__
static timeout_t apm_timeout;
+#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;
@@ -75,6 +122,31 @@ 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 */
@@ -87,7 +159,7 @@ int apm_errno;
inline
int
-apm_int(u_long *eax,u_long *ebx,u_long *ecx)
+apm_int(u_long *eax, u_long *ebx, u_long *ecx)
{
u_long cf;
__asm ("pushl %%ebp
@@ -112,76 +184,76 @@ apm_int(u_long *eax,u_long *ebx,u_long *ecx)
/* enable/disable power management */
static int
-apm_enable_disable_pm(int enable)
+apm_enable_disable_pm(struct apm_softc *sc, int enable)
{
- u_long eax,ebx,ecx;
+ u_long eax, ebx, ecx;
- eax = (APM_BIOS<<8) | APM_ENABLEDISABLEPM;
+ eax = (APM_BIOS << 8) | APM_ENABLEDISABLEPM;
- if (intversion >= INTVERSION(1, 1)) {
+ if (sc->intversion >= INTVERSION(1, 1)) {
ebx = PMDV_ALLDEV;
} else {
ebx = 0xffff; /* APM version 1.0 only */
}
ecx = enable;
- return apm_int(&eax,&ebx,&ecx);
+ return apm_int(&eax, &ebx, &ecx);
}
/* Tell APM-BIOS that WE will do 1.1 and see what they say... */
static void
-apm_driver_version()
+apm_driver_version(void)
{
- u_long eax,ebx,ecx,i;
+ u_long eax, ebx, ecx, i;
#ifdef APM_DEBUG
eax = (APM_BIOS<<8) | APM_INSTCHECK;
ebx = 0x0;
ecx = 0x0101;
- i = apm_int(&eax,&ebx,&ecx);
+ i = apm_int(&eax, &ebx, &ecx);
printf("[%04lx %04lx %04lx %ld %02x]\n",
- eax,ebx,ecx,i,apm_errno);
+ eax, ebx, ecx, i, apm_errno);
#endif
- eax = (APM_BIOS<<8) | APM_DRVVERSION;
+ eax = (APM_BIOS << 8) | APM_DRVVERSION;
ebx = 0x0;
ecx = 0x0101;
- if(!apm_int(&eax,&ebx,&ecx))
+ if(!apm_int(&eax, &ebx, &ecx))
apm_version = eax & 0xffff;
#ifdef APM_DEBUG
- eax = (APM_BIOS<<8) | APM_INSTCHECK;
+ eax = (APM_BIOS << 8) | APM_INSTCHECK;
ebx = 0x0;
ecx = 0x0101;
- i = apm_int(&eax,&ebx,&ecx);
+ i = apm_int(&eax, &ebx, &ecx);
printf("[%04lx %04lx %04lx %ld %02x]\n",
- eax,ebx,ecx,i,apm_errno);
+ eax, ebx, ecx, i, apm_errno);
#endif
}
/* engage/disengage power management (APM 1.1 or later) */
static int
-apm_engage_disengage_pm(int engage)
+apm_engage_disengage_pm(struct apm_softc *sc, int engage)
{
- u_long eax,ebx,ecx,i;
+ u_long eax, ebx, ecx, i;
- eax = (APM_BIOS<<8) | APM_ENGAGEDISENGAGEPM;
+ eax = (APM_BIOS << 8) | APM_ENGAGEDISENGAGEPM;
ebx = PMDV_ALLDEV;
ecx = engage;
- i = apm_int(&eax,&ebx,&ecx);
+ i = apm_int(&eax, &ebx, &ecx);
return i;
}
/* get PM event */
static u_int
-apm_getevent(void)
+apm_getevent(struct apm_softc *sc)
{
- u_long eax,ebx,ecx;
+ u_long eax, ebx, ecx;
- eax = (APM_BIOS<<8) | APM_GETPMEVENT;
+ eax = (APM_BIOS << 8) | APM_GETPMEVENT;
ebx = 0;
ecx = 0;
- if (apm_int(&eax,&ebx,&ecx))
+ if (apm_int(&eax, &ebx, &ecx))
return PMEV_NOEVENT;
return ebx & 0xffff;
@@ -189,39 +261,171 @@ apm_getevent(void)
/* suspend entire system */
static int
-apm_suspend_system(void)
+apm_suspend_system(struct apm_softc *sc)
{
- u_long eax,ebx,ecx;
-
- eax = (APM_BIOS<<8) | APM_SETPWSTATE;
+ u_long eax, ebx, ecx;
+
+ eax = (APM_BIOS << 8) | APM_SETPWSTATE;
ebx = PMDV_ALLDEV;
ecx = PMST_SUSPEND;
- if (apm_int(&eax,&ebx,&ecx)) {
+ __asm("cli");
+ if (apm_int(&eax, &ebx, &ecx)) {
+ __asm("sti");
printf("Entire system suspend failure: errcode = %ld\n",
0xff & (eax >> 8));
return 1;
}
+ __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>
+ */
+int
+apm_display_off(void)
+{
+ u_long eax, ebx, ecx;
+
+ eax = (APM_BIOS << 8) | APM_SETPWSTATE;
+ ebx = PMDV_2NDSTORAGE0;
+ ecx = PMST_STANDBY;
+ if (apm_int(&eax, &ebx, &ecx)) {
+ printf("Display off failure: errcode = %ld\n",
+ 0xff & (eax >> 8));
+ return 1;
+ }
+
return 0;
}
/* APM Battery low handler */
static void
-apm_battery_low(void)
+apm_battery_low(struct apm_softc *sc)
{
printf("\007\007 * * * BATTERY IS LOW * * * \007\007");
}
+/* 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;
+}
+
+static void
+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 */
+static void
+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);
+ }
+ }
+}
+
+
+/* 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 */
+void
+apm_hook_disestablish(int apmh, struct apmhook *ah)
+{
+ if (apmh < 0 || apmh >= NAPM_HOOK)
+ return;
+
+ apm_del_hook(&hook[apmh], ah);
+}
+
+
static struct timeval suspend_time;
+static struct timeval diff_time;
static int
-apm_default_resume(void)
+apm_default_resume(struct apm_softc *sc)
{
+#ifdef __FreeBSD__
+ int pl;
u_int second, minute, hour;
- struct timeval resume_time;
+ struct timeval resume_time, tmp_time;
- inittodr(0); /* adjust time to RTC */
+ /* modified for adjkerntz */
+ pl = splsoftclock();
+ inittodr(0); /* adjust time to RTC */
microtime(&resume_time);
+ tmp_time = time; /* because 'time' is volatile */
+ timevaladd(&tmp_time, &diff_time);
+ time = tmp_time;
+ splx(pl);
second = resume_time.tv_sec - suspend_time.tv_sec;
hour = second / 3600;
second %= 3600;
@@ -229,48 +433,99 @@ apm_default_resume(void)
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)
{
+#ifdef __FreeBSD__
int pl;
+
+ pl = splsoftclock();
+ microtime(&diff_time);
+ inittodr(0);
microtime(&suspend_time);
- apm_suspend_system();
+ 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;
}
+static void apm_processevent(struct apm_softc *);
+
+/*
+ * Public interface to the suspend/resume:
+ *
+ * Execute suspend and resume hook before and after sleep, respectively.
+ *
+ */
+
+void
+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]);
+ }
+}
+
+
/* get APM information */
static int
-apm_get_info(apm_info_t aip)
+apm_get_info(struct apm_softc *sc, apm_info_t aip)
{
- u_long eax,ebx,ecx;
+ u_long eax, ebx, ecx;
- eax = (APM_BIOS<<8)|APM_GETPWSTATUS;
+ eax = (APM_BIOS << 8) | APM_GETPWSTATUS;
ebx = PMDV_ALLDEV;
ecx = 0;
- if (apm_int(&eax,&ebx,&ecx))
+ if (apm_int(&eax, &ebx, &ecx))
return 1;
aip->ai_acline = (ebx >> 8) & 0xff;
aip->ai_batt_stat = ebx & 0xff;
aip->ai_batt_life = ecx & 0xff;
- aip->ai_major = (u_int)majorversion;
- aip->ai_minor = (u_int)minorversion;
+ aip->ai_major = (u_int)sc->majorversion;
+ aip->ai_minor = (u_int)sc->minorversion;
return 0;
}
-static void apm_processevent(void);
-
/* inform APM BIOS that CPU is idle */
void
apm_cpu_idle(void)
{
- if (idle_cpu) {
- if (active) {
+ struct apm_softc *sc = master_softc; /* XXX */
+
+ if (sc->idle_cpu) {
+ if (sc->active) {
__asm ("movw $0x5305, %ax; lcall _apm_addr");
}
}
@@ -284,7 +539,13 @@ apm_cpu_idle(void)
* "hlt" operation from swtch() and managed it under
* APM driver.
*/
- if (!active || halt_cpu) {
+ /*
+ * UKAI Note: on NetBSD, idle() called from cpu_switch()
+ * doesn't halt CPU, so halt_cpu may not need on NetBSD/i386
+ * or only "sti" operation would be needed.
+ */
+
+ if (!sc->active || sc->halt_cpu) {
__asm("sti ; hlt"); /* wait for interrupt */
}
}
@@ -293,7 +554,9 @@ apm_cpu_idle(void)
void
apm_cpu_busy(void)
{
- if (idle_cpu && active) {
+ struct apm_softc *sc = master_softc; /* XXX */
+
+ if (sc->idle_cpu && sc->active) {
__asm("movw $0x5306, %ax; lcall _apm_addr");
}
}
@@ -306,59 +569,81 @@ apm_cpu_busy(void)
*/
static void
-apm_timeout(void *arg1)
+apm_timeout(void *arg)
{
- apm_processevent();
- timeout(apm_timeout, NULL, hz - 1 ); /* More than 1 Hz */
+ struct apm_softc *sc = arg;
+
+ apm_processevent(sc);
+ timeout(apm_timeout, (void *)sc, hz - 1 ); /* More than 1 Hz */
}
/* enable APM BIOS */
static void
-apm_event_enable(void)
+apm_event_enable(struct apm_softc *sc)
{
#ifdef APM_DEBUG
printf("called apm_event_enable()\n");
#endif
- if (apm_initialized) {
- active = 1;
- apm_timeout(0);
+ if (sc->initialized) {
+ sc->active = 1;
+ apm_timeout(sc);
}
}
/* disable APM BIOS */
static void
-apm_event_disable(void)
+apm_event_disable(struct apm_softc *sc)
{
#ifdef APM_DEBUG
printf("called apm_event_disable()\n");
#endif
- if (apm_initialized) {
+ if (sc->initialized) {
untimeout(apm_timeout, NULL);
- active = 0;
+ sc->active = 0;
}
}
/* halt CPU in scheduling loop */
-static void apm_halt_cpu(void)
+static void
+apm_halt_cpu(struct apm_softc *sc)
{
- if (apm_initialized) {
- halt_cpu = 1;
+ if (sc->initialized) {
+ sc->halt_cpu = 1;
}
+#ifdef APM_SLOWSTART
+ apm_slowstart = 0;
+#endif /* APM_SLOWSTART */
}
/* don't halt CPU in scheduling loop */
-static void apm_not_halt_cpu(void)
+static void
+apm_not_halt_cpu(struct apm_softc *sc)
{
- if (apm_initialized) {
- halt_cpu = 0;
+ if (sc->initialized) {
+ sc->halt_cpu = 0;
}
+#ifdef APM_SLOWSTART
+ apm_slowstart = apm_slowstart_p;
+#endif /* APM_SLOWSTART */
}
/* device driver definitions */
+#ifdef __FreeBSD__
int apmprobe (struct isa_device *);
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 */
-struct isa_driver apmdriver = { apmprobe, apmattach, "apm" };
/*
* probe APM (dummy):
@@ -370,31 +655,40 @@ struct isa_driver apmdriver = { apmprobe, apmattach, "apm" };
*/
int
-apmprobe(struct isa_device *dvp)
+#ifdef __FreeBSD__
+ apmprobe(struct isa_device *dvp)
+#endif /* __FreeBSD__ */
+#ifdef MACH_KERNEL
+ 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 */
+ struct apm_softc *sc = &apm_softc[unit];
+
switch (apm_version) {
case APMINI_CANTFIND:
/* silent */
return 0;
case APMINI_NOT32BIT:
- printf("apm%d: 32bit connection is not supported.\n",
- dvp->id_unit);
+ printf("apm%d: 32bit connection is not supported.\n", unit);
return 0;
case APMINI_CONNECTERR:
- printf("apm%d: 32-bit connection error.\n", dvp->id_unit);
+ printf("apm%d: 32-bit connection error.\n", unit);
return 0;
}
- if ((apm_version & 0xff00) != 0x0100) return 0;
- if ((apm_version & 0x00f0) >= 0x00a0) return 0;
- if ((apm_version & 0x000f) >= 0x000a) return 0;
return -1;
}
/* Process APM event */
static void
-apm_processevent(void)
+apm_processevent(struct apm_softc *sc)
{
int apm_event;
@@ -404,39 +698,35 @@ apm_processevent(void)
#else
# define OPMEV_DEBUGMESSAGE(symbol) case symbol:
#endif
-
while (1) {
- apm_event = apm_getevent();
+ apm_event = apm_getevent(sc);
if (apm_event == PMEV_NOEVENT)
break;
switch (apm_event) {
OPMEV_DEBUGMESSAGE(PMEV_STANDBYREQ);
- apm_default_suspend();
+ apm_suspend();
break;
OPMEV_DEBUGMESSAGE(PMEV_SUSPENDREQ);
- apm_default_suspend();
+ apm_suspend();
break;
OPMEV_DEBUGMESSAGE(PMEV_USERSUSPENDREQ);
- apm_default_suspend();
+ apm_suspend();
break;
-
OPMEV_DEBUGMESSAGE(PMEV_CRITSUSPEND);
- apm_default_suspend();
+ apm_suspend();
break;
-
OPMEV_DEBUGMESSAGE(PMEV_NORMRESUME);
- apm_default_resume();
+ apm_resume();
break;
OPMEV_DEBUGMESSAGE(PMEV_CRITRESUME);
- apm_default_resume();
+ apm_resume();
break;
OPMEV_DEBUGMESSAGE(PMEV_STANDBYRESUME);
- apm_default_resume();
+ apm_resume();
break;
-
OPMEV_DEBUGMESSAGE(PMEV_BATTERYLOW);
- apm_battery_low();
- apm_default_suspend();
+ apm_battery_low(sc);
+ apm_suspend();
break;
OPMEV_DEBUGMESSAGE(PMEV_POWERSTATECHANGE);
@@ -480,94 +770,147 @@ apm_processevent(void)
* /phk
*/
+#ifdef __FreeBSD__
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;
+#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];
+ int i;
+
+ master_softc = sc; /* XXX */
+ sc->initialized = 0;
+ sc->active = 0;
+ sc->halt_cpu = 1;
/* setup APM parameters */
- cs32_base = (apm_cs32_base << 4) + KERNBASE;
- cs16_base = (apm_cs16_base << 4) + KERNBASE;
- ds_base = (apm_ds_base << 4) + KERNBASE;
- cs_limit = apm_cs_limit;
- ds_limit = apm_ds_limit;
- cs_entry = apm_cs_entry;
-
- idle_cpu = ((apm_flags & APM_CPUIDLE_SLOW) != 0);
- disabled = ((apm_flags & APM_DISABLED) != 0);
- disengaged = ((apm_flags & APM_DISENGAGED) != 0);
+ 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);
+
+#ifdef APM_SLOWSTART
+ if (sc->idle_cpu) {
+ apm_slowstart = apm_slowstart_p = 1;
+ }
+#endif
/* print bootstrap messages */
#ifdef APM_DEBUG
printf(" found APM BIOS version %04x\n", apm_version);
printf("apm%d: Code32 0x%08x, Code16 0x%08x, Data 0x%08x\n",
- dvp->id_unit, cs32_base, cs16_base, ds_base);
+ unit, sc->cs32_base, sc->cs16_base, sc->ds_base);
printf("apm%d: Code entry 0x%08x, Idling CPU %s, Management %s\n",
- dvp->id_unit, cs_entry, is_enabled(idle_cpu),
- is_enabled(!disabled));
+ unit, sc->cs_entry, is_enabled(sc->idle_cpu),
+ is_enabled(!sc->disabled));
printf("apm%d: CS_limit=%x, DS_limit=%x\n",
- dvp->id_unit, cs_limit,ds_limit);
-
+ unit, sc->cs_limit, sc->ds_limit);
#endif /* APM_DEBUG */
- cs_limit = 0xffff;
- ds_limit = 0xffff;
+ sc->cs_limit = 0xffff;
+ sc->ds_limit = 0xffff;
/* setup GDT */
- setup_apm_gdt(cs32_base, cs16_base, ds_base, cs_limit, ds_limit);
+ setup_apm_gdt(sc->cs32_base, sc->cs16_base, sc->ds_base,
+ sc->cs_limit, sc->ds_limit);
/* setup entry point 48bit pointer */
+#ifdef __FreeBSD__
apm_addr.segment = GSEL(GAPMCODE32_SEL, SEL_KPL);
- apm_addr.offset = cs_entry;
+#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 */
apm_driver_version();
-
- minorversion = ((apm_version & 0x00f0) >> 4) * 10 +
+ sc->minorversion = ((apm_version & 0x00f0) >> 4) * 10 +
((apm_version & 0x000f) >> 0);
- majorversion = ((apm_version & 0xf000) >> 12) * 10 +
+ sc->majorversion = ((apm_version & 0xf000) >> 12) * 10 +
((apm_version & 0x0f00) >> 8);
- intversion = INTVERSION(majorversion, minorversion);
+ sc->intversion = INTVERSION(sc->majorversion, sc->minorversion);
- if (intversion >= INTVERSION(1, 1)) {
+ if (sc->intversion >= INTVERSION(1, 1)) {
printf("apm%d: Engaged control %s\n",
- dvp->id_unit, is_enabled(!disengaged));
+ unit, is_enabled(!sc->disengaged));
}
- printf(" found APM BIOS version %d.%d\n", majorversion, minorversion);
- printf("apm%d: Idling CPU %s\n", dvp->id_unit, is_enabled(idle_cpu));
+ printf(" found APM BIOS version %d.%d\n",
+ sc->majorversion, sc->minorversion);
+ printf("apm%d: Idling CPU %s\n", unit, is_enabled(sc->idle_cpu));
/* enable power management */
- if (disabled) {
- if (apm_enable_disable_pm(1)) {
+ if (sc->disabled) {
+ if (apm_enable_disable_pm(sc, 1)) {
printf("Warning: APM enable function failed! [%x]\n",
apm_errno);
}
}
/* engage power managment (APM 1.1 or later) */
- if (intversion >= INTVERSION(1, 1) && disengaged) {
- if (apm_engage_disengage_pm(1)) {
+ if (sc->intversion >= INTVERSION(1, 1) && sc->disengaged) {
+ if (apm_engage_disengage_pm(sc, 1)) {
printf("Warning: APM engage function failed [%x]\n",
apm_errno);
}
}
- apm_initialized = 1;
+ /* 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;
- apm_event_enable();
+ apm_hook_establish(APM_HOOK_SUSPEND, &sc->sc_suspend);
+ apm_hook_establish(APM_HOOK_RESUME , &sc->sc_resume);
+ apm_event_enable(sc);
+
+ sc->initialized = 1;
+
+#ifdef __FreeBSD__
return 0;
+#endif /* __FreeBSD__ */
}
+#ifdef __FreeBSD__
int
apmopen(dev_t dev, int flag, int fmt, struct proc *p)
{
- if (!apm_initialized) {
+ struct apm_softc *sc = &apm_softc[minor(dev)];
+
+ if (minor(dev) >= NAPM) {
+ return (ENXIO);
+ }
+ if (!sc->initialized) {
return ENXIO;
}
- if (minor(dev))
- return (ENXIO);
return 0;
}
@@ -580,6 +923,7 @@ apmclose(dev_t dev, int flag, int fmt, struct proc *p)
int
apmioctl(dev_t dev, int cmd, caddr_t addr, int flag, struct proc *p)
{
+ struct apm_softc *sc = &apm_softc[minor(dev)];
int error = 0;
int pl;
@@ -587,40 +931,67 @@ apmioctl(dev_t dev, int cmd, caddr_t addr, int flag, struct proc *p)
printf("APM ioctl: minor = %d, cmd = 0x%x\n", minor(dev), cmd);
#endif
- pl = splhigh();
- if (minor(dev) != 0) {
+ if (minor(dev) >= NAPM) {
return ENXIO;
}
- if (!apm_initialized) {
+ if (!sc->initialized) {
return ENXIO;
}
switch (cmd) {
case APMIO_SUSPEND:
- apm_default_suspend();
+ apm_suspend();
break;
case APMIO_GETINFO:
- if (apm_get_info((apm_info_t)addr)) {
+ if (apm_get_info(sc, (apm_info_t)addr)) {
error = ENXIO;
}
break;
case APMIO_ENABLE:
- apm_event_enable();
+ apm_event_enable(sc);
break;
case APMIO_DISABLE:
- apm_event_disable();
+ apm_event_disable(sc);
break;
case APMIO_HALTCPU:
- apm_halt_cpu();
+ apm_halt_cpu(sc);
break;
case APMIO_NOTHALTCPU:
- apm_not_halt_cpu();
+ apm_not_halt_cpu(sc);
+ break;
+ case APMIO_DISPLAYOFF:
+ if (apm_display_off()) {
+ error = ENXIO;
+ }
break;
default:
error = EINVAL;
break;
}
- splx(pl);
return error;
}
+#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 */
diff --git a/sys/i386/bios/apm_init/Makefile b/sys/i386/bios/apm_init/Makefile
index fc6464e..1d9c5c3 100644
--- a/sys/i386/bios/apm_init/Makefile
+++ b/sys/i386/bios/apm_init/Makefile
@@ -1,9 +1,9 @@
#
-# LP (Laptop Package)
+# APM (Advanced Power Management) BIOS Device Driver
#
-# (C) 1994 by HOSOKAWA, Tatsumi <hosokawa@mt.cs.keio.ac.jp>
+# Copyright (c) 1994-1995 by HOSOKAWA, Tatsumi <hosokawa@mt.cs.keio.ac.jp>
#
-# This software may be used, modified, copied, and distributed in
+# This software may be used, modified, copied, and distributed, in
# both source and binary form provided that the above copyright and
# these terms are retained. Under no circumstances is the author
# responsible for the proper functioning of this software, nor does
@@ -12,7 +12,7 @@
#
# Sep., 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD)
#
-# $Id$
+# $Id: Makefile,v 1.2 1994/10/01 05:12:29 davidg Exp $
#
OBJS = apm_init.o real_prot.o table.o
diff --git a/sys/i386/bios/apm_init/apm_init.S b/sys/i386/bios/apm_init/apm_init.S
index 5276947..76becc4 100644
--- a/sys/i386/bios/apm_init/apm_init.S
+++ b/sys/i386/bios/apm_init/apm_init.S
@@ -1,7 +1,7 @@
/*
- * LP (Laptop Package)
+ * APM (Advanced Power Management) BIOS Device Driver
*
- * Copyright (C) 1994 by HOSOKAWA, Tatsumi <hosokawa@mt.cs.keio.ac.jp>
+ * Copyright (c) 1994-1995 by HOSOKAWA, Tatsumi <hosokawa@mt.cs.keio.ac.jp>
*
* This software may be used, modified, copied, and distributed, in
* both source and binary form provided that the above copyright and
@@ -12,7 +12,7 @@
*
* Sep., 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD)
*
- * $Id: apm_init.S,v 1.2 1994/10/01 05:12:29 davidg Exp $
+ * $Id: apm_init.S,v 1.3 1994/10/01 21:29:49 phk Exp $
*/
/*
@@ -128,6 +128,7 @@ ENTRY(apm_init)
/* don't support 32bit connection */
jmp finish
1:
+ andl $0x0000ffff, %edx
movl %edx, apm_version
andl $0x0000ffff, %ecx
movl %ecx, apm_flags
@@ -174,15 +175,12 @@ finish:
movl old_esp, %esp /* restore old stack pointer */
movl apm_version, %ebp /* stored to %eax later */
movl apm_flags, %edi
-#if 0
- movw $(BOOTSTRAP_DS_SEL), %ax
- /* restore old data segments */
-#else
movw %fs, %ax
-#endif
movw %ax, %ss
movw %ax, %es
movw %ax, %ds
+ xorl %eax, %eax
+ movw %ax, %fs
movl %ebp, %eax
popl %ebp /* restore old base pointer */
lret /* restore old code segment */
diff --git a/sys/i386/bios/apm_init/apm_init.inc b/sys/i386/bios/apm_init/apm_init.inc
index d88a888..44fc01e 100644
--- a/sys/i386/bios/apm_init/apm_init.inc
+++ b/sys/i386/bios/apm_init/apm_init.inc
@@ -3,51 +3,53 @@
.byte 0xfa, 0x55, 0x66, 0x8c, 0xd8, 0x66, 0x8e, 0xe0
.byte 0x66, 0xb8, 0xf0, 0x00, 0x66, 0x8e, 0xd8, 0x66
- .byte 0x8e, 0xc0, 0x66, 0x8e, 0xd0, 0x89, 0x25, 0x84
+ .byte 0x8e, 0xc0, 0x66, 0x8e, 0xd0, 0x89, 0x25, 0x94
.byte 0x01, 0x00, 0x00, 0xbc, 0x00, 0x00, 0x01, 0x00
- .byte 0x0f, 0x01, 0x0d, 0xa0, 0x01, 0x00, 0x00, 0xe8
- .byte 0x14, 0x01, 0x00, 0x00, 0xb4, 0x53, 0xb0, 0x00
+ .byte 0x0f, 0x01, 0x0d, 0xb0, 0x01, 0x00, 0x00, 0xe8
+ .byte 0x24, 0x01, 0x00, 0x00, 0xb4, 0x53, 0xb0, 0x00
.byte 0x66, 0xbb, 0x00, 0x00, 0x00, 0x00, 0xfb, 0xcd
- .byte 0x15, 0xfa, 0x73, 0x15, 0x66, 0xe8, 0xce, 0x00
- .byte 0x00, 0x00, 0xc7, 0x05, 0x88, 0x01, 0x00, 0x00
- .byte 0xff, 0xff, 0xff, 0xff, 0xe9, 0x8c, 0x00, 0x00
- .byte 0x00, 0x89, 0xc2, 0x66, 0xe8, 0xb7, 0x00, 0x00
+ .byte 0x15, 0xfa, 0x73, 0x15, 0x66, 0xe8, 0xde, 0x00
+ .byte 0x00, 0x00, 0xc7, 0x05, 0x98, 0x01, 0x00, 0x00
+ .byte 0xff, 0xff, 0xff, 0xff, 0xe9, 0x92, 0x00, 0x00
+ .byte 0x00, 0x89, 0xc2, 0x66, 0xe8, 0xc7, 0x00, 0x00
.byte 0x00, 0x80, 0xff, 0x50, 0x75, 0x05, 0x80, 0xfb
- .byte 0x4d, 0x74, 0x0c, 0xc7, 0x05, 0x88, 0x01, 0x00
- .byte 0x00, 0xff, 0xff, 0xff, 0xff, 0xeb, 0x6e, 0xf7
+ .byte 0x4d, 0x74, 0x0c, 0xc7, 0x05, 0x98, 0x01, 0x00
+ .byte 0x00, 0xff, 0xff, 0xff, 0xff, 0xeb, 0x74, 0xf7
.byte 0xc1, 0x02, 0x00, 0x00, 0x00, 0x75, 0x0c, 0xc7
- .byte 0x05, 0x88, 0x01, 0x00, 0x00, 0xfe, 0xff, 0xff
- .byte 0xff, 0xeb, 0x5a, 0x89, 0x15, 0x88, 0x01, 0x00
- .byte 0x00, 0x81, 0xe1, 0xff, 0xff, 0x00, 0x00, 0x89
- .byte 0x0d, 0x8c, 0x01, 0x00, 0x00, 0xe8, 0xa6, 0x00
- .byte 0x00, 0x00, 0xb4, 0x53, 0xb0, 0x03, 0x66, 0xbb
- .byte 0x00, 0x00, 0x00, 0x00, 0xfb, 0xcd, 0x15, 0xfa
- .byte 0x73, 0x12, 0x66, 0xe8, 0x60, 0x00, 0x00, 0x00
- .byte 0xc7, 0x05, 0x88, 0x01, 0x00, 0x00, 0xfd, 0xff
- .byte 0xff, 0xff, 0xeb, 0x21, 0x89, 0xc5, 0x66, 0xe8
- .byte 0x4c, 0x00, 0x00, 0x00, 0xb8, 0xff, 0xff, 0x00
- .byte 0x00, 0x21, 0xc5, 0x21, 0xc1, 0x21, 0xc2, 0x21
- .byte 0xc6, 0x21, 0xc7, 0xc1, 0xe5, 0x10, 0x09, 0xe9
- .byte 0xc1, 0xe7, 0x10, 0x09, 0xfe, 0xfa, 0x0f, 0x01
- .byte 0x1d, 0xa0, 0x01, 0x00, 0x00, 0x8b, 0x25, 0x84
- .byte 0x01, 0x00, 0x00, 0x8b, 0x2d, 0x88, 0x01, 0x00
- .byte 0x00, 0x8b, 0x3d, 0x8c, 0x01, 0x00, 0x00, 0x66
- .byte 0x8c, 0xe0, 0x66, 0x8e, 0xd0, 0x66, 0x8e, 0xc0
- .byte 0x66, 0x8e, 0xd8, 0x89, 0xe8, 0x5d, 0xcb, 0x00
+ .byte 0x05, 0x98, 0x01, 0x00, 0x00, 0xfe, 0xff, 0xff
+ .byte 0xff, 0xeb, 0x60, 0x81, 0xe2, 0xff, 0xff, 0x00
+ .byte 0x00, 0x89, 0x15, 0x98, 0x01, 0x00, 0x00, 0x81
+ .byte 0xe1, 0xff, 0xff, 0x00, 0x00, 0x89, 0x0d, 0x9c
+ .byte 0x01, 0x00, 0x00, 0xe8, 0xb0, 0x00, 0x00, 0x00
+ .byte 0xb4, 0x53, 0xb0, 0x03, 0x66, 0xbb, 0x00, 0x00
+ .byte 0x00, 0x00, 0xfb, 0xcd, 0x15, 0xfa, 0x73, 0x12
+ .byte 0x66, 0xe8, 0x6a, 0x00, 0x00, 0x00, 0xc7, 0x05
+ .byte 0x98, 0x01, 0x00, 0x00, 0xfd, 0xff, 0xff, 0xff
+ .byte 0xeb, 0x21, 0x89, 0xc5, 0x66, 0xe8, 0x56, 0x00
+ .byte 0x00, 0x00, 0xb8, 0xff, 0xff, 0x00, 0x00, 0x21
+ .byte 0xc5, 0x21, 0xc1, 0x21, 0xc2, 0x21, 0xc6, 0x21
+ .byte 0xc7, 0xc1, 0xe5, 0x10, 0x09, 0xe9, 0xc1, 0xe7
+ .byte 0x10, 0x09, 0xfe, 0xfa, 0x0f, 0x01, 0x1d, 0xb0
+ .byte 0x01, 0x00, 0x00, 0x8b, 0x25, 0x94, 0x01, 0x00
+ .byte 0x00, 0x8b, 0x2d, 0x98, 0x01, 0x00, 0x00, 0x8b
+ .byte 0x3d, 0x9c, 0x01, 0x00, 0x00, 0x66, 0x8c, 0xe0
+ .byte 0x66, 0x8e, 0xd0, 0x66, 0x8e, 0xc0, 0x66, 0x8e
+ .byte 0xd8, 0x31, 0xc0, 0x66, 0x8e, 0xe0, 0x89, 0xe8
+ .byte 0x5d, 0xcb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
.byte 0xfa, 0x0f, 0x20, 0xc0, 0x66, 0x83, 0xc8, 0x01
- .byte 0x0f, 0x22, 0xc0, 0x66, 0xea, 0x23, 0x01, 0x00
+ .byte 0x0f, 0x22, 0xc0, 0x66, 0xea, 0x33, 0x01, 0x00
.byte 0x00, 0xe8, 0x00, 0xb8, 0xf0, 0x00, 0x00, 0x00
.byte 0x66, 0x8e, 0xd8, 0x66, 0x8e, 0xd0, 0x66, 0x8e
- .byte 0xc0, 0x0f, 0x01, 0x1d, 0xa0, 0x01, 0x00, 0x00
+ .byte 0xc0, 0x0f, 0x01, 0x1d, 0xb0, 0x01, 0x00, 0x00
.byte 0xc3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
- .byte 0xa1, 0x80, 0x01, 0x00, 0x00, 0xc1, 0xf8, 0x04
- .byte 0x66, 0x50, 0x66, 0xb8, 0x62, 0x01, 0x66, 0x50
- .byte 0xea, 0x57, 0x01, 0x00, 0x00, 0xf8, 0x00, 0x0f
+ .byte 0xa1, 0x90, 0x01, 0x00, 0x00, 0xc1, 0xf8, 0x04
+ .byte 0x66, 0x50, 0x66, 0xb8, 0x72, 0x01, 0x66, 0x50
+ .byte 0xea, 0x67, 0x01, 0x00, 0x00, 0xf8, 0x00, 0x0f
.byte 0x20, 0xc0, 0x66, 0x83, 0xe0, 0xfe, 0x0f, 0x22
.byte 0xc0, 0xcb, 0x66, 0x8c, 0xc8, 0x66, 0x8e, 0xd8
.byte 0x66, 0x8e, 0xd0, 0x66, 0x8e, 0xc0, 0x67, 0x66
- .byte 0x0f, 0x01, 0x1d, 0xa6, 0x01, 0x00, 0x00, 0x66
+ .byte 0x0f, 0x01, 0x1d, 0xb6, 0x01, 0x00, 0x00, 0x66
.byte 0xc3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
.byte 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00
.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
@@ -56,4 +58,4 @@
.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x03
.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
-/* Total size = 0x01b0 */
+/* Total size = 0x01c0 */
diff --git a/sys/i386/bios/apm_init/bin2asm.c b/sys/i386/bios/apm_init/bin2asm.c
index 5577247..791798a 100644
--- a/sys/i386/bios/apm_init/bin2asm.c
+++ b/sys/i386/bios/apm_init/bin2asm.c
@@ -1,9 +1,9 @@
/*
- * LP (Laptop Package)
+ * APM (Advanced Power Management) BIOS Device Driver
*
- * Copyright (C) 1994 by HOSOKAWA, Tatsumi <hosokawa@mt.cs.keio.ac.jp>
+ * Copyright (c) 1994-1995 by HOSOKAWA, Tatsumi <hosokawa@mt.cs.keio.ac.jp>
*
- * This software may be used, modified, copied, and distributed, in
+ * This software may be used, modified, copied, and distributed, in
* both source and binary form provided that the above copyright and
* these terms are retained. Under no circumstances is the author
* responsible for the proper functioning of this software, nor does
@@ -12,7 +12,7 @@
*
* Sep., 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD)
*
- * $Id$
+ * $Id: bin2asm.c,v 1.2 1994/10/01 05:12:30 davidg Exp $
*/
#include <stdio.h>
@@ -21,7 +21,7 @@
int main(int argc, char *argv[])
{
- int c, col;
+ int c, col, lastline;
FILE *infile, *outfile;
if (argc != 3) {
@@ -44,6 +44,8 @@ int main(int argc, char *argv[])
fprintf(outfile, "/* This file is automatically generated by bin2asm */\n");
fprintf(outfile, "/* Original file is '%s' */\n\n", argv[1]);
+ lastline = 0;
+
while ((c = fgetc(infile)) != EOF) {
if (col % NCOLS == 0) {
fprintf(outfile, "\t.byte\t");
@@ -51,12 +53,20 @@ int main(int argc, char *argv[])
fprintf(outfile, "0x%02x", c);
if (col % NCOLS == NCOLS - 1) {
fprintf(outfile, "\n");
+ lastline = 1;
}
else {
fprintf(outfile, ", ");
+ lastline = 0;
}
col++;
}
+ if (!lastline) {
+ do {
+ fprintf(outfile, "0x00, ");
+ } while ((col++) % NCOLS < NCOLS - 2);
+ fprintf(outfile, "0x00\n");
+ }
fprintf(outfile, "\n/* Total size = 0x%04x */\n", col);
diff --git a/sys/i386/bios/apm_init/real_prot.h b/sys/i386/bios/apm_init/real_prot.h
index bc02200..692ebfe 100644
--- a/sys/i386/bios/apm_init/real_prot.h
+++ b/sys/i386/bios/apm_init/real_prot.h
@@ -24,7 +24,7 @@
* the rights to redistribute these changes.
*
* from: Mach, Revision 2.7 92/02/29 15:33:41 rpd
- * $Id: asm.h,v 1.3 1993/10/16 19:11:29 rgrimes Exp $
+ * $Id: real_prot.h,v 1.1 1994/10/01 02:55:52 davidg Exp $
*/
/*
@@ -40,6 +40,8 @@
* use.
*
* Sep., 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD)
+ * Nov., 1994 Commited to FreeBSD 2.0-current
+ * Jan., 1995 Ported to RT-Mach 3.0 MK83g
*/
/*
diff --git a/sys/i386/bios/apm_init/table.c b/sys/i386/bios/apm_init/table.c
index f859bff..607fcc6 100644
--- a/sys/i386/bios/apm_init/table.c
+++ b/sys/i386/bios/apm_init/table.c
@@ -1,7 +1,7 @@
/*
- * LP (Laptop Package)
+ * APM (Advanced Power Management) BIOS Device Driver
*
- * Copyright (C) 1994 by HOSOKAWA, Tatsumi <hosokawa@mt.cs.keio.ac.jp>
+ * Copyright (c) 1994-1995 by HOSOKAWA, Tatsumi <hosokawa@mt.cs.keio.ac.jp>
*
* This software may be used, modified, copied, and distributed, in
* both source and binary form provided that the above copyright and
@@ -12,7 +12,7 @@
*
* Sep., 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD)
*
- * $Id$
+ * $Id: table.c,v 1.2 1994/10/01 05:12:31 davidg Exp $
*/
#include <apm_bios.h>
diff --git a/sys/i386/bios/apm_setup.h b/sys/i386/bios/apm_setup.h
index 6f564c9..55f126d 100644
--- a/sys/i386/bios/apm_setup.h
+++ b/sys/i386/bios/apm_setup.h
@@ -12,7 +12,7 @@
*
* Sep., 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD)
*
- * $Id$
+ * $Id: apm_setup.h,v 1.2 1994/10/01 05:12:23 davidg Exp $
*/
extern u_long apm_version;
@@ -23,3 +23,4 @@ extern u_short apm_ds_base;
extern u_short apm_cs_limit;
extern u_short apm_ds_limit;
extern u_short apm_flags;
+extern u_short kernelbase;
diff --git a/sys/i386/bios/apm_setup.s b/sys/i386/bios/apm_setup.s
index d354679..b3ae77d 100644
--- a/sys/i386/bios/apm_setup.s
+++ b/sys/i386/bios/apm_setup.s
@@ -12,14 +12,29 @@
*
* Sep., 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD)
*
- * $Id: apm_setup.s,v 1.3 1994/10/02 01:45:42 phk Exp $
+ * $Id: apm_setup.s,v 1.4 1994/10/10 01:14:03 phk Exp $
*/
-#define ASM
+#include "apm.h"
+
+#if NAPM > 0
-#include <machine/asmacros.h>
-#include "assym.s"
+#ifdef __FreeBSD__
+#define ASSEMBLER
+#include "assym.s" /* system definitions */
+#include <machine/asmacros.h> /* miscellaneous asm macros */
#include <machine/apm_bios.h>
+#include <machine/apm_segments.h>
+#define PADDR(addr) addr-KERNBASE
+#endif /* __FreeBSD__ */
+
+#ifdef MACH_KERNEL
+#define ASSEMBLER
+#include "assym.s"
+#include "i386at/apm_bios.h"
+#include "i386at/apm_segments.h"
+#define PADDR(addr) addr-KERNELBASE
+#endif /* MACH_KERNEL */
.file "apm_setup.s"
@@ -28,7 +43,12 @@ _apm_init_image:
.globl _apm_init_image
1:
-#include "apm_init/apm_init.inc"
+#ifdef __FreeBSD__
+#include "i386/apm/apm_init/apm_init.inc"
+#endif /* __FreeBSD__ */
+#ifdef MACH_KERNEL
+#include "i386at/apm_init/apm_init.inc"
+#endif /* MACH_KERNEL */
2:
_apm_init_image_size:
@@ -66,4 +86,108 @@ _apm_ds_limit:
_apm_flags:
.globl _apm_flags
.word 0
+ .globl _apm_current_gdt_pdesc /* current GDT pseudo desc. */
+_apm_current_gdt_pdesc:
+ .word 0, 0, 0
+
+ .globl _bootstrap_gdt
+_bootstrap_gdt:
+ .space SIZEOF_GDT*BOOTSTRAP_GDT_NUM
+
+ .text
+_apm_setup:
+ .globl _apm_setup
+
+ /*
+ * Setup APM BIOS:
+ *
+ * APM BIOS initialization should be done from real mode or V86 mode.
+ *
+ * (by HOSOKAWA, Tatsumi <hosokawa@mt.cs.keio.ac.jp>)
+ */
+
+ /*
+ * Don't trust the value of %fs and %gs (some AT-compatible BIOS
+ * implementations leave junk values in these segment registers
+ * on bootstrap)
+ */
+ xorl %eax, %eax /* null selector */
+ movw %ax, %fs
+ movw %ax, %gs
+
+ /*
+ * Copy APM initializer under 1MB boundary:
+ *
+ * APM initializer program must switch the CPU to real mode.
+ * But FreeBSD kernel runs above 1MB boundary. So we must
+ * copy the initializer code to conventional memory.
+ */
+ movl PADDR(_apm_init_image_size), %ecx /* size */
+ lea PADDR(_apm_init_image), %esi /* source */
+ movl $ APM_OURADDR, %edi /* destination */
+ cld
+ rep
+ movsb
+
+ /* get GDT base */
+ sgdt PADDR(_apm_current_gdt_pdesc)
+
+ /* copy GDT to _bootstrap_gdt */
+ xorl %ecx, %ecx
+ movw PADDR(_apm_current_gdt_pdesc), %cx
+ movl PADDR(_apm_current_gdt_pdesc + 2), %esi
+ lea PADDR(_bootstrap_gdt), %edi
+ cld
+ rep
+ movsb
+
+ /* setup GDT pseudo descriptor */
+ movw $(SIZEOF_GDT*BOOTSTRAP_GDT_NUM), %ax
+ movw %ax, PADDR(_apm_current_gdt_pdesc)
+ leal PADDR(_bootstrap_gdt), %eax
+ movl %eax, PADDR(_apm_current_gdt_pdesc + 2)
+
+ /* load new GDTR */
+ lgdt PADDR(_apm_current_gdt_pdesc)
+
+ /* setup GDT for APM initializer */
+ lea PADDR(_bootstrap_gdt), %ecx
+ movl $(APM_OURADDR), %eax /* use %ax for 15..0 */
+ movl %eax, %ebx
+ shrl $16, %ebx /* use %bl for 23..16 */
+ /* use %bh for 31..24 */
+#define APM_SETUP_GDT(index, attrib) \
+ movl $(index), %si ; \
+ lea 0(%ecx,%esi,8), %edx ; \
+ movw $0xffff, (%edx) ; \
+ movw %ax, 2(%edx) ; \
+ movb %bl, 4(%edx) ; \
+ movw $(attrib), 5(%edx) ; \
+ movb %bh, 7(%edx)
+
+ APM_SETUP_GDT(APM_INIT_CS_INDEX , CS32_ATTRIB)
+ APM_SETUP_GDT(APM_INIT_DS_INDEX , DS32_ATTRIB)
+ APM_SETUP_GDT(APM_INIT_CS16_INDEX, CS16_ATTRIB)
+
+ /*
+ * Call the initializer:
+ *
+ * direct intersegment call to conventional memory code
+ */
+ .byte 0x9a /* actually, lcall $APM_INIT_CS_SEL, $0 */
+ .long 0
+ .word APM_INIT_CS_SEL
+
+ movl %eax, PADDR(_apm_version)
+ movl %ebx, PADDR(_apm_cs_entry)
+ movw %cx, PADDR(_apm_cs32_base)
+ shrl $16, %ecx
+ movw %cx, PADDR(_apm_cs16_base)
+ movw %dx, PADDR(_apm_ds_base)
+ movw %si, PADDR(_apm_cs_limit)
+ shrl $16, %esi
+ movw %si, PADDR(_apm_ds_limit)
+ movw %di, PADDR(_apm_flags)
+ ret
+#endif NAPM > 0
diff --git a/sys/i386/conf/LINT b/sys/i386/conf/LINT
index 8cb1fc9..81bf365 100644
--- a/sys/i386/conf/LINT
+++ b/sys/i386/conf/LINT
@@ -2,7 +2,7 @@
# LINT -- config file for checking all the sources, tries to pull in
# as much of the source tree as it can.
#
-# $Id: LINT,v 1.142 1995/02/15 04:49:18 jkh Exp $
+# $Id: LINT,v 1.143 1995/02/15 06:18:15 jkh Exp $
#
# NB: You probably don't want to try running a kernel built from this
# file. Instead, you should start from GENERIC, and add options from
@@ -479,7 +479,10 @@ options DSI_SOFT_MODEM #code for DSI Softmodems
# le: Digital Equipment EtherWorks 2 and EtherWorks 3 (DEPCA, DE100,
# DE101, DE200, DE201, DE202, DE203, DE204, DE205, DE422)
# lnc: Lance/PCnet cards (Isolan, Novell NE2100, NE32-VL)
-# ze: PCMCIA ethernet controller.
+# ze: IBM/National Semiconductor PCMCIA ethernet controller.
+# zp: 3Com PCMCIA Etherlink III (It does not require shared memory for
+# send/receive operation, but it needs 'iomem' to read/write the
+# attribute memory)
#
device cx0 at isa? port 0x240 net irq 15 drq 7 vector cxintr
@@ -490,6 +493,8 @@ device ep0 at isa? port 0x300 net irq 10 vector epintr
device el0 at isa? port 0x300 net irq 9 vector elintr
device le0 at isa? port 0x300 net irq 5 iomem 0xd0000 vector le_intr
device ze0 at isa? port 0x300 net irq 5 iomem 0xd8000 vector zeintr
+device zp0 at isa? port 0x300 net irq 10 iomem 0xd8000 vector zpintr
+
# ISDN drivers - `isdn'.
#
@@ -558,10 +563,7 @@ device scd0 at isa? port 0x230 bio
device wt0 at isa? port 0x300 bio irq 5 drq 1 vector wtintr
device ctx0 at isa? port 0x230 iomem 0xd0000
device spigot0 at isa? port 0xad6 irq 15 iomem 0xee000 vector spigintr
-
-# NB: both lines are required
device apm0 at isa?
-options APM
#
# PCI devices:
diff --git a/sys/i386/conf/NOTES b/sys/i386/conf/NOTES
index 8cb1fc9..81bf365 100644
--- a/sys/i386/conf/NOTES
+++ b/sys/i386/conf/NOTES
@@ -2,7 +2,7 @@
# LINT -- config file for checking all the sources, tries to pull in
# as much of the source tree as it can.
#
-# $Id: LINT,v 1.142 1995/02/15 04:49:18 jkh Exp $
+# $Id: LINT,v 1.143 1995/02/15 06:18:15 jkh Exp $
#
# NB: You probably don't want to try running a kernel built from this
# file. Instead, you should start from GENERIC, and add options from
@@ -479,7 +479,10 @@ options DSI_SOFT_MODEM #code for DSI Softmodems
# le: Digital Equipment EtherWorks 2 and EtherWorks 3 (DEPCA, DE100,
# DE101, DE200, DE201, DE202, DE203, DE204, DE205, DE422)
# lnc: Lance/PCnet cards (Isolan, Novell NE2100, NE32-VL)
-# ze: PCMCIA ethernet controller.
+# ze: IBM/National Semiconductor PCMCIA ethernet controller.
+# zp: 3Com PCMCIA Etherlink III (It does not require shared memory for
+# send/receive operation, but it needs 'iomem' to read/write the
+# attribute memory)
#
device cx0 at isa? port 0x240 net irq 15 drq 7 vector cxintr
@@ -490,6 +493,8 @@ device ep0 at isa? port 0x300 net irq 10 vector epintr
device el0 at isa? port 0x300 net irq 9 vector elintr
device le0 at isa? port 0x300 net irq 5 iomem 0xd0000 vector le_intr
device ze0 at isa? port 0x300 net irq 5 iomem 0xd8000 vector zeintr
+device zp0 at isa? port 0x300 net irq 10 iomem 0xd8000 vector zpintr
+
# ISDN drivers - `isdn'.
#
@@ -558,10 +563,7 @@ device scd0 at isa? port 0x230 bio
device wt0 at isa? port 0x300 bio irq 5 drq 1 vector wtintr
device ctx0 at isa? port 0x230 iomem 0xd0000
device spigot0 at isa? port 0xad6 irq 15 iomem 0xee000 vector spigintr
-
-# NB: both lines are required
device apm0 at isa?
-options APM
#
# PCI devices:
diff --git a/sys/i386/conf/files.i386 b/sys/i386/conf/files.i386
index cf20538..0e1c3f5 100644
--- a/sys/i386/conf/files.i386
+++ b/sys/i386/conf/files.i386
@@ -1,7 +1,7 @@
# This file tells config what files go into building a kernel,
# files marked standard are always included.
#
-# $Id: files.i386,v 1.81 1995/02/14 07:19:10 phk Exp $
+# $Id: files.i386,v 1.82 1995/02/14 22:34:41 jkh Exp $
#
i386/apm/apm.c optional apm device-driver
i386/apm/apm_setup.s optional apm
@@ -81,7 +81,10 @@ i386/isa/if_is.c optional is device-driver
i386/isa/if_ix.c optional ix device-driver
i386/isa/if_le.c optional le device-driver
i386/isa/if_lnc.c optional lnc device-driver
+i386/isa/pcic.c optional ze device-driver
+i386/isa/pcic.c optional zp device-driver
i386/isa/if_ze.c optional ze device-driver
+i386/isa/if_zp.c optional zp device-driver
i386/isa/isa.c optional isa device-driver
i386/isa/joy.c optional joy device-driver
i386/isa/lpt.c optional lpt device-driver
diff --git a/sys/i386/i386/locore.s b/sys/i386/i386/locore.s
index 167d9c5..657debd 100644
--- a/sys/i386/i386/locore.s
+++ b/sys/i386/i386/locore.s
@@ -34,7 +34,7 @@
* SUCH DAMAGE.
*
* from: @(#)locore.s 7.3 (Berkeley) 5/13/91
- * $Id: locore.s,v 1.47 1995/01/25 21:40:15 bde Exp $
+ * $Id: locore.s,v 1.48 1995/02/11 04:21:22 phk Exp $
*/
/*
@@ -55,11 +55,6 @@
#include <machine/asmacros.h> /* miscellaneous asm macros */
#include <sys/reboot.h>
#include "apm.h"
-#if NAPM > 0
-#define ASM
-#include <machine/apm_bios.h>
-#include <machine/apm_segments.h>
-#endif /* NAPM */
/*
* XXX
@@ -147,15 +142,6 @@ _proc0paddr: .long 0 /* address of proc 0 address space */
.globl _bdb_exists /* flag to indicate BDE debugger is available */
_bdb_exists: .long 0
#endif
-#if NAPM > 0
- .globl _apm_current_gdt_pdesc /* current GDT pseudo desc. */
-_apm_current_gdt_pdesc:
- .word 0, 0, 0
-
- .globl _bootstrap_gdt
-_bootstrap_gdt:
- .space SIZEOF_GDT * BOOTSTRAP_GDT_NUM
-#endif /* NAPM */
/*
* System Initialization
@@ -322,87 +308,8 @@ got_common_bi_size:
movl %eax,_bootdev-KERNBASE
#if NAPM > 0
- /*
- * Setup APM BIOS:
- *
- * APM BIOS initialization should be done from real mode or V86 mode.
- *
- * (by HOSOKAWA, Tatsumi <hosokawa@mt.cs.keio.ac.jp>)
- */
-
- /*
- * Copy APM initializer under 1MB boundary:
- *
- * APM initializer program must switch the CPU to real mode.
- * But FreeBSD kernel runs above 1MB boundary. So we must
- * copy the initializer code to conventional memory.
- */
- movl _apm_init_image_size-KERNBASE, %ecx /* size */
- lea _apm_init_image-KERNBASE, %esi /* source */
- movl $ APM_OURADDR, %edi /* destination */
- cld
- rep
- movsb
-
- /* get GDT base */
- sgdt _apm_current_gdt_pdesc-KERNBASE
-
- /* copy GDT to _bootstrap_gdt */
- xorl %ecx, %ecx
- movw _apm_current_gdt_pdesc-KERNBASE, %cx
- movl _apm_current_gdt_pdesc-KERNBASE+2, %esi
- lea _bootstrap_gdt-KERNBASE, %edi
- cld
- rep
- movsb
-
- /* setup GDT pseudo descriptor */
- movw $(SIZEOF_GDT*BOOTSTRAP_GDT_NUM), %ax
- movw %ax, _apm_current_gdt_pdesc-KERNBASE
- leal _bootstrap_gdt-KERNBASE, %eax
- movl %eax, _apm_current_gdt_pdesc-KERNBASE+2
-
- /* load new GDTR */
- lgdt _apm_current_gdt_pdesc-KERNBASE
-
- /* setup GDT for APM initializer */
- lea _bootstrap_gdt-KERNBASE, %ecx
- movl $(APM_OURADDR), %eax /* use %ax for 15..0 */
- movl %eax, %ebx
- shrl $16, %ebx /* use %bl for 23..16 */
- /* use %bh for 31..24 */
-#define APM_SETUP_GDT(index, attrib) \
- movl $(index), %si ; \
- lea 0(%ecx,%esi,8), %edx ; \
- movw $0xffff, (%edx) ; \
- movw %ax, 2(%edx) ; \
- movb %bl, 4(%edx) ; \
- movw $(attrib), 5(%edx) ; \
- movb %bh, 7(%edx)
-
- APM_SETUP_GDT(APM_INIT_CS_INDEX , CS32_ATTRIB)
- APM_SETUP_GDT(APM_INIT_DS_INDEX , DS32_ATTRIB)
- APM_SETUP_GDT(APM_INIT_CS16_INDEX, CS16_ATTRIB)
-
- /*
- * Call the initializer:
- *
- * direct intersegment call to conventional memory code
- */
- .byte 0x9a /* actually, lcall $APM_INIT_CS_SEL, $0 */
- .long 0
- .word APM_INIT_CS_SEL
-
- movw %ax, _apm_version-KERNBASE
- movl %ebx, _apm_cs_entry-KERNBASE
- movw %cx, _apm_cs32_base-KERNBASE
- shrl $16, %ecx
- movw %cx, _apm_cs16_base-KERNBASE
- movw %dx, _apm_ds_base-KERNBASE
- movw %si, _apm_cs_limit-KERNBASE
- shrl $16, %esi
- movw %si, _apm_ds_limit-KERNBASE
- movw %di, _apm_flags-KERNBASE
+ /* call APM BIOS driver setup (i386/apm/apm_setup.s) */
+ call _apm_setup
#endif /* NAPM */
/* Find out our CPU type. */
diff --git a/sys/i386/i386/swtch.s b/sys/i386/i386/swtch.s
index e9e476a..e15298d 100644
--- a/sys/i386/i386/swtch.s
+++ b/sys/i386/i386/swtch.s
@@ -33,7 +33,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: swtch.s,v 1.18 1994/12/03 10:02:22 bde Exp $
+ * $Id: swtch.s,v 1.19 1995/01/21 15:20:23 bde Exp $
*/
#include "npx.h" /* for NNPX */
@@ -249,6 +249,26 @@ _idle:
ALIGN_TEXT
idle_loop:
+#if NAPM > 0
+#if APM_SLOWSTART <=0 || !defined(APM_SLOWSTART)
+ movl _apm_slowstart, %eax
+ orl %eax, %eax
+ jz 1f
+ xorl %eax, %eax
+ incl %eax
+ movl %eax, _apm_slowstart_stat
+ movl _apm_ss_cnt, %eax
+ cmpl $ APM_SLOWSTART, %eax
+ jae 2f
+ incl %eax
+ movl %eax, _apm_ss_cnt
+ call _apm_cpu_idle
+ jmp 1f
+2:
+ call _apm_cpu_busy
+1:
+#endif
+#endif
cli
movb $1,_intr_nesting_level /* charge Intr if we leave */
cmpl $0,_whichrtqs /* real-time queue */
@@ -258,11 +278,27 @@ idle_loop:
cmpl $0,_whichidqs /* 'idle' queue */
jne idqr
movb $0,_intr_nesting_level /* charge Idle for this loop */
-#ifdef APM
+#if NAPM > 0
+#if APM_SLOWSTART <= 0 || !defined(APM_SLOWSTART)
/*
* XXX it breaks the rules to call a function while interrupts are
* disabled. How long before apm enables them?
*/
+ call _apm_cpu_idle
+ call _apm_cpu_busy
+#else
+ movl _apm_slowstart, %eax
+ orl %eax, %eax
+ jz 1f
+ xorl %eax, %eax
+ movl %eax, _apm_ss_cnt
+ movl %eax, _apm_slowstart_stat
+1:
+ call _apm_cpu_idle
+ call _apm_cpu_busy
+#endif
+
+
call _apm_cpu_idle
call _apm_cpu_busy
#else
diff --git a/sys/i386/include/apm_bios.h b/sys/i386/include/apm_bios.h
index e3afdc1..67cdc38 100644
--- a/sys/i386/include/apm_bios.h
+++ b/sys/i386/include/apm_bios.h
@@ -1,7 +1,7 @@
/*
- * Advanced Power Management (APM) BIOS driver for laptop PCs.
- *
- * Copyright (c) 1994 by HOSOKAWA Tatsumi <hosokawa@mt.cs.keio.ac.jp>
+ * APM (Advanced Power Management) BIOS Device Driver
+ *
+ * Copyright (c) 1994-1995 by HOSOKAWA, Tatsumi <hosokawa@mt.cs.keio.ac.jp>
*
* This software may be used, modified, copied, and distributed, in
* both source and binary form provided that the above copyright and
@@ -12,7 +12,7 @@
*
* Aug, 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD)
*
- * $Id: apm_bios.h,v 1.2 1994/10/01 05:13:36 davidg Exp $
+ * $Id: apm_bios.h,v 1.3 1994/10/02 17:31:27 phk Exp $
*/
#ifndef _MACHINE_APM_BIOS_H_
@@ -118,25 +118,28 @@
/* 0x0040 - 0x007f OEM-defined device states */
/* 0x0080 - 0xffff Reserved device states */
-#if !defined(ASM) && !defined(INITIALIZER)
+#if !defined(ASSEMBLER) && !defined(INITIALIZER)
/* C definitions */
-typedef struct apm_hook_func {
- struct apm_hook_func *next; /* Linked list */
- int (*func)(void);
- const char *name;
- int order;
-} *apm_hook_func_t;
-
-apm_hook_func_t apm_resume_hook_init(int (*func)(void), char *name, int order);
-void apm_resume_hook_delete(apm_hook_func_t delete_func);
-apm_hook_func_t apm_suspend_hook_init(int (*func)(void), char *name, int order);
-void apm_suspend_hook_delete(apm_hook_func_t delete_func);
-void apm_suspend_resume(void);
+struct apmhook {
+ struct apmhook *ah_next;
+ int (*ah_fun)();
+ void *ah_arg;
+ const char *ah_name;
+ int ah_order;
+};
+#define APM_HOOK_NONE (-1)
+#define APM_HOOK_SUSPEND 0
+#define APM_HOOK_RESUME 1
+#define NAPM_HOOK 2
+
+void apm_suspend(void);
+struct apmhook *apm_hook_establish (int apmh, struct apmhook *);
+void apm_hook_disestablish (int apmh, struct apmhook *);
void apm_cpu_idle(void);
void apm_cpu_busy(void);
-#endif /* !ASM && !INITIALIZER */
+#endif /* !ASSEMBLER && !INITIALIZER */
#define APM_MIN_ORDER 0x00
#define APM_MID_ORDER 0x80
@@ -163,7 +166,7 @@ void apm_cpu_busy(void);
/* 0x0300 - 0xffff Reserved */
#define PMEV_DEFAULT 0xffffffff /* used for customization */
-#if !defined(ASM) && !defined(INITIALIZER)
+#if !defined(ASSEMBLER) && !defined(INITIALIZER)
typedef struct apm_info {
u_int ai_major; /* APM major version */
@@ -173,14 +176,16 @@ typedef struct apm_info {
u_int ai_batt_life; /* Remaining battery life */
} *apm_info_t;
-
+#ifdef __FreeBSD__
#define APMIO_SUSPEND _IO('P', 1)
#define APMIO_GETINFO _IOR('P', 2, struct apm_info)
#define APMIO_ENABLE _IO('P', 5)
#define APMIO_DISABLE _IO('P', 6)
#define APMIO_HALTCPU _IO('P', 7)
#define APMIO_NOTHALTCPU _IO('P', 8)
+#define APMIO_DISPLAYOFF _IO('P', 9)
+#endif /* __FreeBSD__ */
-#endif /* !ASM && !INITIALIZER */
+#endif /* !ASSEMBLER && !INITIALIZER */
#endif /* _MACHINE_APM_BIOS_H_ */
diff --git a/sys/i386/include/apm_segments.h b/sys/i386/include/apm_segments.h
index f23a6c2..8bee29e 100644
--- a/sys/i386/include/apm_segments.h
+++ b/sys/i386/include/apm_segments.h
@@ -12,7 +12,7 @@
*
* Sep., 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD)
*
- * $Id$
+ * $Id: apm_segments.h,v 1.2 1994/10/01 05:13:37 davidg Exp $
*/
#ifndef _MACHINE_APM_SEGMENTS_H
@@ -32,6 +32,4 @@
#define CS16_ATTRIB 0x009e
#define DS32_ATTRIB 0x4092
-#define BOOTSTRAP_DS_SEL 0x10
-
#endif
diff --git a/sys/i386/isa/icu.s b/sys/i386/isa/icu.s
index e4e031d..ddab5de 100644
--- a/sys/i386/isa/icu.s
+++ b/sys/i386/isa/icu.s
@@ -36,7 +36,7 @@
*
* @(#)icu.s 7.2 (Berkeley) 5/21/91
*
- * $Id: icu.s,v 1.18 1995/01/14 11:00:27 bde Exp $
+ * $Id: icu.s,v 1.19 1995/02/08 21:46:44 bde Exp $
*/
/*
@@ -154,6 +154,13 @@ doreti_unpend:
jae doreti_swi
cli
movl %eax,_cpl
+#if NAPM > 0 && defined(APM_SLOWSTART)
+ movl _apm_slowstart_stat, %eax
+ orl %eax, %eax
+ jz 1:
+ call _apm_idle_cpu
+1:
+#endif
MEXITCOUNT
jmp %edx
diff --git a/sys/i386/isa/if_ze.c b/sys/i386/isa/if_ze.c
index bd52940..f447cc0 100644
--- a/sys/i386/isa/if_ze.c
+++ b/sys/i386/isa/if_ze.c
@@ -47,7 +47,7 @@
*/
/*
- * $Id: if_ze.c,v 1.9 1994/11/24 14:29:26 davidg Exp $
+ * $Id: if_ze.c,v 1.10 1995/01/23 18:02:32 phk Exp $
*/
#include "ze.h"
@@ -89,316 +89,15 @@
#include "i386/isa/isa_device.h"
#include "i386/isa/icu.h"
#include "i386/isa/if_zereg.h"
+#include "i386/isa/pcic.h"
+#include "apm.h"
+#if NAPM > 0
+#include "i386/include/apm_bios.h"
+#endif /* NAPM > 0 */
/*****************************************************************************
- * pcmcia controller chip (PCIC) support *
- * (eventually, move this to a separate file) *
- *****************************************************************************/
-#include "ic/i82365.h"
-
-/*
- * Each PCIC chip (82365SL or clone) can handle two card slots, and there
- * can be up to four PCICs in a system. (On some machines, not all of the
- * address lines are decoded, so a card may appear to be in more than one
- * slot.)
- */
-#define MAXSLOT 8
-
-/*
- * To access a register on the PCIC for a particular slot, you
- * first write the correct OFFSET value for that slot in the
- * INDEX register for the PCIC controller. You then read or write
- * the value from or to the DATA register for that controller.
- *
- * The first pair of chips shares I/O addresss for DATA and INDEX,
- * as does the second pair. (To the programmer, it looks like each
- * pair is a single chip.) The i/o port addresses are hard-wired
- * into the PCIC; so the following addresses should be valid for
- * any machine that uses this chip.
- */
-
-#define PCIC_INDEX_0 0x3E0 /* index reg, chips 0 and 1 */
-#define PCIC_DATA_0 0x3E1 /* data register, chips 0 and 1 */
-#define PCIC_INDEX_1 0x3E2 /* index reg, chips 1 and 2 */
-#define PCIC_DATA_1 0x3E3 /* data register, chips 1 and 2 */
-
-/*
- * Given a slot number, calculate the INDEX and DATA registers
- * to talk to that slot. OFFSET is added to the register number
- * to address the registers for a particular slot.
- */
-#define INDEX(slot) ((slot) < 4 ? PCIC_INDEX_0 : PCIC_INDEX_1)
-#define DATA(slot) ((slot) < 4 ? PCIC_DATA_0 : PCIC_DATA_1)
-#define OFFSET(slot) ((slot) % 4 * 0x40)
-
-/*
- * There are 5 sets (windows) of memory mapping registers on the PCIC chip
- * for each slot, numbered 0..4.
- *
- * They start at 10/50 hex within the chip's register space (not system
- * I/O space), and are eight addresses apart. These are actually pairs of
- * 8-bit-wide registers (low byte first, then high byte) since the
- * address fields are actually 12 bits long. The upper bits are used
- * for other things like 8/16-bit select and wait states.
- *
- * Memory mapping registers include start/stop addresses to define the
- * region to be mapped (in terms of system memory addresses), and
- * an offset register to allow for translation from system space
- * to card space. The lower 12 bits aren't included in these, so memory is
- * mapped in 4K chunks.
- */
-#define MEM_START_ADDR(window) (((window) * 0x08) + 0x10)
-#define MEM_STOP_ADDR(window) (((window) * 0x08) + 0x12)
-#define MEM_OFFSET(window) (((window) * 0x08) + 0x14)
-/*
- * this bit gets set in the address window enable register (PCIC_ADDRWINE)
- * to enable a particular address window.
- */
-#define MEM_ENABLE_BIT(window) ((1) << (window))
-
-/*
- * There are two i/o port addressing windows. I/O ports cannot be
- * relocated within system i/o space (unless the card doesn't decode
- * all of the address bits); unlike card memory, there is no address
- * translation offset.
- */
-#define IO_START_ADDR(window) ((window) ? PCIC_IO1_STL : PCIC_IO0_STL)
-#define IO_STOP_ADDR(window) ((window) ? PCIC_IO1_SPL : PCIC_IO0_SPL)
-#define IO_ENABLE_BIT(window) ((window) ? PCIC_IO1_EN : PCIC_IO0_EN)
-#define IO_CS16_BIT(window) ((window) ? PCIC_IO1_CS16 : PCIC_IO0_CS16)
-
-/*
- * read a byte from a pcic register for a particular slot
- */
-static inline unsigned char
-pcic_getb (int slot, int reg)
-{
- outb (INDEX(slot), OFFSET (slot) + reg);
- return inb (DATA (slot));
-}
-
-/*
- * write a byte to a pcic register for a particular slot
- */
-static inline void
-pcic_putb (int slot, int reg, unsigned char val)
-{
- outb (INDEX(slot), OFFSET (slot) + reg);
- outb (DATA (slot), val);
-}
-
-/*
- * read a word from a pcic register for a particular slot
- */
-static inline unsigned short
-pcic_getw (int slot, int reg)
-{
- return pcic_getb (slot, reg) | (pcic_getb (slot, reg+1) << 8);
-}
-
-/*
- * write a word to a pcic register at a particular slot
- */
-static inline void
-pcic_putw (int slot, int reg, unsigned short val)
-{
- pcic_putb (slot, reg, val & 0xff);
- pcic_putb (slot, reg + 1, (val >> 8) & 0xff);
-}
-
-static void
-pcic_print_regs (int slot)
-{
- int i, j;
-
- for (i = 0; i < 0x40; i += 16) {
- for (j = 0; j < 16; ++j)
- printf ("%02x ", pcic_getb (slot, i + j));
- printf ("\n");
- }
-}
-
-/*
- * map a portion of the card's memory space into system memory
- * space.
- *
- * slot = # of the slot the card is plugged into
- * window = which pcic memory map registers to use (0..4)
- * sys_addr = base system PHYSICAL memory address where we want it. must
- * be on an appropriate boundary (lower 12 bits are zero).
- * card_addr = the base address of the card's memory to correspond
- * to sys_addr
- * length = length of the segment to map (may be rounded up as necessary)
- * type = which card memory space to map (attribute or shared)
- * width = 1 for byte-wide mapping; 2 for word (16-bit) mapping.
- */
-
-enum memtype { COMMON, ATTRIBUTE };
-
-static void
-pcic_map_memory (int slot, int window, unsigned long sys_addr,
- unsigned long card_addr, unsigned long length,
- enum memtype type, int width)
-{
- unsigned short offset;
- unsigned short mem_start_addr;
- unsigned short mem_stop_addr;
-
- sys_addr >>= 12;
- card_addr >>= 12;
- length >>= 12;
- /*
- * compute an offset for the chip such that
- * (sys_addr + offset) = card_addr
- * but the arithmetic is done modulo 2^14
- */
- offset = (card_addr - sys_addr) & 0x3FFF;
- /*
- * now OR in the bit for "attribute memory" if necessary
- */
- if (type == ATTRIBUTE) {
- offset |= (PCIC_REG << 8);
- /* REG == "region active" pin on card */
- }
- /*
- * okay, set up the chip memory mapping registers, and turn
- * on the enable bit for this window.
- * if we are doing 16-bit wide accesses (width == 2),
- * turn on the appropriate bit.
- *
- * XXX for now, we set all of the wait state bits to zero.
- * Not really sure how they should be set.
- */
- mem_start_addr = sys_addr & 0xFFF;
- if (width == 2)
- mem_start_addr |= (PCIC_DATA16 << 8);
- mem_stop_addr = (sys_addr + length) & 0xFFF;
-
- pcic_putw (slot, MEM_START_ADDR(window), mem_start_addr);
- pcic_putw (slot, MEM_STOP_ADDR(window), mem_stop_addr);
- pcic_putw (slot, MEM_OFFSET(window), offset);
- /*
- * Assert the bit (PCIC_MEMCS16) that says to decode all of
- * the address lines.
- */
- pcic_putb (slot, PCIC_ADDRWINE,
- pcic_getb (slot, PCIC_ADDRWINE) |
- MEM_ENABLE_BIT(window) | PCIC_MEMCS16);
-}
-
-static void
-pcic_unmap_memory (int slot, int window)
-{
- /*
- * seems like we need to turn off the enable bit first, after which
- * we can clear the registers out just to be sure.
- */
- pcic_putb (slot, PCIC_ADDRWINE,
- pcic_getb (slot, PCIC_ADDRWINE) & ~MEM_ENABLE_BIT(window));
- pcic_putw (slot, MEM_START_ADDR(window), 0);
- pcic_putw (slot, MEM_STOP_ADDR(window), 0);
- pcic_putw (slot, MEM_OFFSET(window), 0);
-}
-
-/*
- * map a range of addresses into system i/o space
- * (no translation of i/o addresses is possible)
- *
- * 'width' is:
- * + 0 to tell the PCIC to generate the ISA IOCS16* signal from
- * the PCMCIA IOIS16* signal.
- * + 1 to select 8-bit width
- * + 2 to select 16-bit width
- */
-
-static void
-pcic_map_io (int slot, int window, unsigned short base, unsigned short length,
- unsigned short width)
-{
- unsigned char x;
-
- pcic_putw (slot, IO_START_ADDR(window), base);
- pcic_putw (slot, IO_STOP_ADDR(window), base+length-1);
- /*
- * select the bits that determine whether
- * an i/o operation is 8 or 16 bits wide
- */
- x = pcic_getb (slot, PCIC_IOCTL);
- switch (width) {
- case 0: /* PCMCIA card decides */
- if (window)
- x = (x & 0xf0) | PCIC_IO1_CS16;
- else
- x = (x & 0x0f) | PCIC_IO0_CS16;
- break;
- case 1: /* 8 bits wide */
- break;
- case 2: /* 16 bits wide */
- if (window)
- x = (x & 0xf0) | PCIC_IO1_16BIT;
- else
- x = (x & 0x0f) | PCIC_IO0_16BIT;
- break;
- }
- pcic_putb (slot, PCIC_IOCTL, x);
- pcic_putb (slot, PCIC_ADDRWINE,
- pcic_getb (slot, PCIC_ADDRWINE) | IO_ENABLE_BIT(window));
-}
-
-#ifdef TEST
-static void
-pcic_unmap_io (int slot, int window)
-{
- pcic_putb (slot, PCIC_ADDRWINE,
- pcic_getb (slot, PCIC_ADDRWINE) & ~IO_ENABLE_BIT(window));
- pcic_putw (slot, IO_START_ADDR(window), 0);
- pcic_putw (slot, IO_STOP_ADDR(window), 0);
-}
-#endif /* TEST */
-
-/*
- * tell the PCIC which irq we want to use. only the following are legal:
- * 3, 4, 5, 7, 9, 10, 11, 12, 14, 15
- *
- * NB: 'irq' is an interrupt NUMBER, not a MASK as in struct isa_device.
- */
-
-static void
-pcic_map_irq (int slot, int irq)
-{
- if (irq < 3 || irq == 6 || irq == 8 || irq == 13 || irq > 15) {
- printf ("ze: pcic_map_irq (slot %d): illegal irq %d\n", slot, irq);
- return;
- }
- pcic_putb (slot, PCIC_INT_GEN,
- pcic_getb (slot, PCIC_INT_GEN) | (irq & 0x0F));
-}
-
-static void
-pcic_power_on (int slot)
-{
- pcic_putb (slot, PCIC_POWER,
- pcic_getb (slot, PCIC_POWER) | PCIC_DISRST | PCIC_PCPWRE);
- DELAY (100000);
- pcic_putb (slot, PCIC_POWER,
- pcic_getb (slot, PCIC_POWER) | PCIC_OUTENA);
-}
-
-static void
-pcic_reset (int slot)
-{
- /* assert RESET (by clearing a bit!), wait a bit, and de-assert it */
- pcic_putb (slot, PCIC_INT_GEN,
- pcic_getb (slot, PCIC_INT_GEN) & ~PCIC_CARDRESET);
- DELAY (100000);
- pcic_putb (slot, PCIC_INT_GEN,
- pcic_getb (slot, PCIC_INT_GEN) | PCIC_CARDRESET);
-}
-
-
-/*****************************************************************************
* Driver for Ethernet Adapter *
*****************************************************************************/
/*
@@ -437,8 +136,13 @@ struct ze_softc {
u_char rec_page_start; /* first page of RX ring-buffer */
u_char rec_page_stop; /* last page of RX ring-buffer */
u_char next_packet; /* pointer to next unread RX packet */
+ int slot; /* information for reconfiguration */
u_char last_alive; /* information for reconfiguration */
u_char last_up; /* information for reconfiguration */
+#if NAPM > 0
+ struct apmhook s_hook; /* reconfiguration support */
+ struct apmhook r_hook; /* reconfiguration support */
+#endif /* NAPM > 0 */
} ze_softc[NZE];
int ze_attach(), ze_ioctl(), ze_probe();
@@ -529,12 +233,14 @@ ze_check_cis (unsigned char *scratch)
* + Leaves product/vendor id of last card probed in 'card_info'
*/
+static int prev_slot = 0;
+
static int
ze_find_adapter (unsigned char *scratch, int reconfig)
{
int slot;
- for (slot = 0; slot < MAXSLOT; ++slot) {
+ for (slot = prev_slot; slot < MAXSLOT; ++slot) {
/*
* see if there's a PCMCIA controller here
* Intel PCMCIA controllers use 0x82 and 0x83
@@ -558,6 +264,9 @@ ze_find_adapter (unsigned char *scratch, int reconfig)
if (!reconfig) {
printf ("ze: slot %d: no card in slot\n", slot);
}
+ else {
+ log (LOG_NOTICE, "ze: slot %d: no card in slot\n", slot);
+ }
/* no card in slot */
continue;
}
@@ -576,15 +285,24 @@ ze_find_adapter (unsigned char *scratch, int reconfig)
if (!reconfig) {
printf ("ze: found card in slot %d\n", slot);
}
+ else {
+ log (LOG_NOTICE, "ze: found card in slot %d\n", slot);
+ }
+ prev_slot = (prev_slot == MAXSLOT - 1) ? 0 : prev_slot+1;
+
return slot;
}
else {
if (!reconfig) {
printf ("ze: pcmcia slot %d: %s\n", slot, card_info);
}
+ else {
+ log (LOG_NOTICE, "ze: pcmcia slot %d: %s\n", slot, card_info);
+ }
}
pcic_unmap_memory (slot, 0);
}
+ prev_slot = 0;
return -1;
}
@@ -611,7 +329,7 @@ ze_probe(isa_dev)
struct isa_device *isa_dev;
{
struct ze_softc *sc = &ze_softc[isa_dev->id_unit];
- int i, x;
+ int i, x, re_init_flag;
u_int memsize;
u_char iptr, memwidth, sum, tmp;
int slot;
@@ -652,6 +370,8 @@ ze_probe(isa_dev)
enet_addr[5] = PEEK(isa_dev->id_maddr+0xffa);
pcic_unmap_memory (slot, 0);
+ re_init_flag = 0;
+re_init:
/*
* (2) map card configuration registers. these are offset
* in card memory space by 0x20000. normally we could get
@@ -749,10 +469,26 @@ ze_probe(isa_dev)
outb (isa_dev->id_iobase + ZE_RESET, tmp);
DELAY(20000);
+#if 0
+ tmp = inb(isa_dev->id_iobase);
+ printf("CR = 0x%x\n", tmp);
+#endif
/*
* query MAM bit in misc register for 10base2
*/
tmp = inb (isa_dev->id_iobase + ZE_MISC);
+
+ /*
+ * Some Intel-compatible PCICs of Cirrus Logic fails in
+ * initializing them. This is a quick hack to fix this
+ * problem.
+ * HOSOKAWA, Tatsumi <hosokawa@mt.cs.keio.ac.jp>
+ */
+ if (!tmp && !re_init_flag) {
+ re_init_flag++;
+ goto re_init;
+ }
+
sc->mau = tmp & 0x09 ? "10base2" : "10baseT";
/* set width/size */
@@ -779,8 +515,34 @@ ze_probe(isa_dev)
/* information for reconfiguration */
sc->last_alive = 0;
sc->last_up = 0;
+ sc->slot = slot;
+
return 32;
}
+
+#if NAPM > 0
+static int
+ze_suspend(isa_dev)
+ struct isa_device *isa_dev;
+{
+ struct ze_softc *sc = &ze_softc[isa_dev->id_unit];
+
+ pcic_power_off(sc->slot);
+ return 0;
+}
+
+static int
+ze_resume(isa_dev)
+ struct isa_device *isa_dev;
+{
+#if 0
+ printf("Resume ze:\n");
+#endif
+ prev_slot = 0;
+ reconfig_isadev(isa_dev, &net_imask);
+ return 0;
+}
+#endif /* NAPM > 0 */
/*
* Install interface into kernel networking data structures
@@ -794,21 +556,26 @@ ze_attach(isa_dev)
struct ifnet *ifp = &sc->arpcom.ac_if;
struct ifaddr *ifa;
struct sockaddr_dl *sdl;
+ int pl;
/* PCMCIA card can be offlined. Reconfiguration is required */
if (isa_dev->id_reconfig) {
+ ze_reset(isa_dev->id_unit);
if (!isa_dev->id_alive && sc->last_alive) {
+ pl = splimp();
sc->last_up = (ifp->if_flags & IFF_UP);
- ifp->if_flags &= ~(IFF_UP);
+ if_down(ifp);
+ splx(pl);
sc->last_alive = 0;
}
if (isa_dev->id_alive && !sc->last_alive) {
if (sc->last_up) {
- ifp->if_flags |= IFF_UP;
+ pl = splimp();
+ if_up(ifp);
+ splx(pl);
}
sc->last_alive = 1;
}
- ze_reset(isa_dev->id_unit);
return 1;
}
else {
@@ -888,6 +655,19 @@ ze_attach(isa_dev)
bpfattach(&sc->bpf, ifp, DLT_EN10MB, sizeof(struct ether_header));
#endif
+#if NAPM > 0
+ sc->s_hook.ah_fun = ze_suspend;
+ sc->s_hook.ah_arg = (void *)isa_dev;
+ sc->s_hook.ah_name = "IBM PCMCIA Ethernet I/II";
+ sc->s_hook.ah_order = APM_MID_ORDER;
+ apm_hook_establish(APM_HOOK_SUSPEND , &sc->s_hook);
+ sc->r_hook.ah_fun = ze_resume;
+ sc->r_hook.ah_arg = (void *)isa_dev;
+ sc->r_hook.ah_name = "IBM PCMCIA Ethernet I/II";
+ sc->r_hook.ah_order = APM_MID_ORDER;
+ apm_hook_establish(APM_HOOK_RESUME , &sc->r_hook);
+#endif /* NAPM > 0 */
+
return 1;
}
diff --git a/sys/i386/isa/if_zp.c b/sys/i386/isa/if_zp.c
new file mode 100644
index 0000000..27c7f3d
--- /dev/null
+++ b/sys/i386/isa/if_zp.c
@@ -0,0 +1,2266 @@
+#define ZP_DEBUG 1
+/*
+ * This code is based on
+ * (1) FreeBSD implementation on ISA/EISA Ethelink III by Herb Peyerl
+ * (2) Linux implementation on PCMCIA Etherlink III by Devid Hinds
+ * (3) FreeBSD implementation on PCMCIA IBM Ethernet Card I/II
+ * by David Greenman
+ * (4) RT-Mach implementation on PCMCIA/ISA/EISA Etherlink III
+ * by Seiji Murata
+ *
+ * Copyright (c) by HOSOKAWA, Tatsumi <hosokawa@mt.cs.keio.ac.jp>
+ * Copyright (c) by Seiji Murata <seiji@mt.cs.keio.ac.jp>
+ */
+/*
+ * Copyright (c) 1993 Herb Peyerl <hpeyerl@novatel.ca>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * From: if_ep.c,v 1.9 1994/01/25 10:46:29 deraadt Exp $
+ * $Id: if_ep.c,v 1.9 1994/05/02 22:27:33 ats Exp $
+ */
+/*-
+ * TODO:
+ * [1] integrate into current if_ed.c
+ * [2] parse tuples to find out where to map the shared memory buffer,
+ * and what to write into the configuration register
+ * [3] move pcic-specific code into a separate module.
+ *
+ * Device driver for IBM PCMCIA Credit Card Adapter for Ethernet,
+ * if_ze.c
+ *
+ * Based on the Device driver for National Semiconductor DS8390 ethernet
+ * adapters by David Greenman. Modifications for PCMCIA by Keith Moore.
+ * Adapted for FreeBSD 1.1.5 by Jordan Hubbard.
+ *
+ * Currently supports only the IBM Credit Card Adapter for Ethernet, but
+ * could probably work with other PCMCIA cards also, if it were modified
+ * to get the locations of the PCMCIA configuration option register (COR)
+ * by parsing the configuration tuples, rather than by hard-coding in
+ * the value expected by IBM's card.
+ *
+ * Sources for data on the PCMCIA/IBM CCAE specific portions of the driver:
+ *
+ * [1] _Local Area Network Credit Card Adapters Technical Reference_,
+ * IBM Corp., SC30-3585-00, part # 33G9243.
+ * [2] "pre-alpha" PCMCIA support code for Linux by Barry Jaspan.
+ * [3] Intel 82536SL PC Card Interface Controller Data Sheet, Intel
+ * Order Number 290423-002
+ * [4] National Semiconductor DP83902A ST-NIC (tm) Serial Network
+ * Interface Controller for Twisted Pair data sheet.
+ *
+ *
+ * Copyright (C) 1993, David Greenman. This software may be used, modified,
+ * copied, distributed, and sold, in both source and binary form provided
+ * that the above copyright and 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 use.
+ */
+/*======================================================================
+
+ A PCMCIA ethernet driver for the 3com 3c589 card.
+
+ Written by David Hinds, dhinds@allegro.stanford.edu
+
+ The network driver code is based on Donald Becker's 3c589 code:
+
+ Written 1994 by Donald Becker.
+ Copyright 1993 United States Government as represented by the
+ Director, National Security Agency. This software may be used and
+ distributed according to the terms of the GNU Public License,
+ incorporated herein by reference.
+ Donald Becker may be reached at becker@cesdis1.gsfc.nasa.gov
+
+======================================================================*/
+/*
+ * I doubled delay loops in this file because it is not enough for some
+ * laptop machines' PCIC (especially, on my Chaplet ILFA 350 ^^;).
+ * HOSOKAWA, Tatsumi <hosokawa@mt.cs.keio.ac.jp>
+ */
+/*
+ * Very small patch for IBM Ethernet PCMCIA Card II and IBM ThinkPad230Cs.
+ * ETO, Toshihisa <eto@osl.fujitsu.co.jp>
+ */
+
+#include "zp.h"
+#if NZP > 0
+#ifdef MACH_KERNEL
+
+#define IF_CNTRS MACH
+
+#include <mach_ttd.h>
+#include <kern/time_out.h>
+#include <device/device_types.h>
+#include <device/errno.h>
+#include <device/io_req.h>
+#include <device/if_hdr.h>
+#include <device/if_ether.h>
+#include <device/net_status.h>
+#include <device/net_io.h>
+
+#include <i386/ipl.h>
+#include <chips/busses.h>
+
+#include <i386at/if_zpreg.h>
+
+#define SPLNET spl6
+
+#if MACH_TTD
+#include <ttd/ttd_stub.h>
+#endif /* MACH_TTD */
+
+#include "i82365.h"
+
+#define MAXSLOT 8
+#define SHARED_MEMORY
+
+enum memtype { COMMON, ATTRIBUTE };
+
+#else /* MACH_KERNEL */
+
+#include "bpfilter.h"
+
+#include <sys/param.h>
+#if defined(__FreeBSD__)
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#endif
+#include <sys/mbuf.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <sys/errno.h>
+#include <sys/syslog.h>
+#if defined(__NetBSD__)
+#include <sys/select.h>
+#endif
+
+#include <net/if.h>
+#include <net/if_dl.h>
+#include <net/if_types.h>
+
+#ifdef INET
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/in_var.h>
+#include <netinet/ip.h>
+#include <netinet/if_ether.h>
+#endif
+
+#ifdef NS
+#include <netns/ns.h>
+#include <netns/ns_if.h>
+#endif
+
+#if NBPFILTER > 0
+#include <net/bpf.h>
+#include <net/bpfdesc.h>
+#endif
+
+#include <i386/isa/isa.h>
+#include <i386/isa/isa_device.h>
+#include <i386/isa/icu.h>
+#include <i386/isa/if_zpreg.h>
+#include <i386/isa/pcic.h>
+
+#include "apm.h"
+#if NAPM > 0
+#include "i386/include/apm_bios.h"
+#endif /* NAPM > 0 */
+
+#endif /* MACH_KERNEL */
+
+#define ETHER_MIN_LEN 64
+#define ETHER_MAX_LEN 1518
+#define ETHER_ADDR_LEN 6
+
+
+/*****************************************************************************
+ * Driver for Ethernet Adapter *
+ *****************************************************************************/
+/*
+ * zp_softc: per line info and status
+ */
+struct zp_softc {
+#ifdef MACH_KERNEL
+ struct ifnet ds_if; /* generic interface header */
+ u_char ds_addr[6]; /* Ethernet hardware address */
+#else /* MACH_KERNEL */
+ struct arpcom arpcom; /* Ethernet common part */
+#define MAX_MBS 8 /* # of mbufs we keep around */
+ struct mbuf *mb[MAX_MBS]; /* spare mbuf storage. */
+ int next_mb; /* Which mbuf to use next. */
+ int last_mb; /* Last mbuf. */
+ caddr_t bpf; /* BPF "magic cookie" */
+#endif /* MACH_KERNEL */
+ short ep_io_addr; /* i/o bus address */
+ char ep_connectors; /* Connectors on this card. */
+ int tx_start_thresh; /* Current TX_start_thresh. */
+ char bus32bit; /* 32bit access possible */
+#ifdef MACH_KERNEL
+ u_char attached;
+#endif
+#ifndef ORIGINAL
+ u_short if_port;
+#endif /* ORIGINAL */
+ u_char last_alive; /* information for reconfiguration */
+ u_char last_up; /* information for reconfiguration */
+ int slot; /* PCMCIA slot */
+#if NAPM > 0
+ struct apmhook s_hook; /* reconfiguration support */
+ struct apmhook r_hook; /* reconfiguration support */
+#endif /* NAPM > 0 */
+} zp_softc[NZP];
+
+#ifdef MACH_KERNEL
+
+static int send_ID_sequence(),f_is_eeprom_busy();
+static u_short get_eeprom_data();
+int zpprobe(),zpopen(),zpoutput(),zpsetinput(),zpgetstat(),
+ zpsetstat(),zpintr();
+void zpattach(),zpinit(),zpstart(),zpread(),zpreset(),
+ zpwatchdog(),zpstop();
+
+static vm_offset_t zp_std[NZP] = {0};
+static struct bus_device *zp_info[NZP];
+
+struct bus_driver zpdriver =
+ {zpprobe, 0, zpattach, 0, zp_std, "zp", zp_info, 0, 0, 0};
+
+typedef struct zp_softc zp_softc_t;
+
+char *zp_name = "zp";
+
+static unsigned char card_info[256];
+
+#define splnet spl7
+#define splimp spl7
+
+#else /* MACH_KERNEL */
+
+int zpprobe __P((struct isa_device *));
+int zpattach __P((struct isa_device *));
+int zpioctl __P((struct ifnet * ifp, int, caddr_t));
+static u_short read_eeprom_data __P((int, int));
+
+void zpinit __P((int));
+void zpintr __P((int));
+void zpmbuffill __P((caddr_t));
+void zpmbufempty __P((struct zp_softc *));
+void zpread __P((struct zp_softc *));
+void zpreset __P((int));
+void zpstart __P((struct ifnet *));
+void zpstop __P((int));
+void zpwatchdog __P((int));
+
+struct isa_driver zpdriver = {
+ zpprobe,
+ zpattach,
+ "zp"
+};
+
+static int send_ID_sequence __P((u_short));
+static u_short get_eeprom_data __P((int, int));
+static int f_is_eeprom_busy __P((struct isa_device *));
+
+#endif /* MACH_KERNEL */
+
+#define CARD_INFO "3Com Corporation~3C589"
+
+static unsigned char card_info[256];
+
+/*
+ * scan the card information structure looking for the version/product info
+ * tuple. when we find it, compare it to the string we are looking for.
+ * return 1 if we find it, 0 otherwise.
+ */
+
+static int
+zp_check_cis (unsigned char *scratch)
+{
+ int i,j,k;
+
+ card_info[0] = '\0';
+ i = 0;
+ while (scratch[i] != 0xff && i < 1024) {
+ unsigned char link = scratch[i+2];
+
+#if 0
+ printf ("[%02x] %02x ", i, link);
+ for (j = 4; j < 2 * link + 4 && j < 32; j += 2)
+ printf ("%02x ", scratch[j + i]);
+ printf ("\n");
+#endif
+ if (scratch[i] == 0x15) {
+ /*
+ * level 1 version/product info
+ * copy to card_info, translating '\0' to '~'
+ */
+ k = 0;
+ for (j = i+8; scratch[j] != 0xff; j += 2)
+ card_info[k++] = scratch[j] == '\0' ? '~' : scratch[j];
+ card_info[k++] = '\0';
+#ifdef ZP_DEBUG
+ printf("card info = %s\n", card_info);
+ printf("result = %d\n", memcmp (card_info, CARD_INFO, sizeof(CARD_INFO)-1) == 0);
+#endif
+ return (memcmp (card_info, CARD_INFO, sizeof(CARD_INFO)-1) == 0);
+ }
+ i += 4 + 2 * link;
+ }
+ return 0;
+}
+
+/*
+ * Probe each slot looking for an IBM Credit Card Adapter for Ethernet
+ * For each card that we find, map its card information structure
+ * into system memory at 'scratch' and see whether it's one of ours.
+ * Return the slot number if we find a card, or -1 otherwise.
+ *
+ * Side effects:
+ * + On success, leaves CIS mapped into memory at 'scratch';
+ * caller must free it.
+ * + On success, leaves ethernet address in enet_addr.
+ * + Leaves product/vendor id of last card probed in 'card_info'
+ */
+
+int prev_slot = 0;
+
+static int
+zp_find_adapter (unsigned char *scratch, int reconfig)
+{
+ int slot;
+
+ for (slot = prev_slot; slot < MAXSLOT; ++slot) {
+ /*
+ * see if there's a PCMCIA controller here
+ * Intel PCMCIA controllers use 0x82 and 0x83
+ * IBM clone chips use 0x88 and 0x89, apparently
+ */
+ /*
+ * IBM ThinkPad230Cs use 0x84.
+ */
+ unsigned char idbyte = pcic_getb (slot, PCIC_ID_REV);
+
+ if (idbyte != 0x82 && idbyte != 0x83 &&
+ idbyte != 0x84 && /* for IBM ThinkPad 230Cs */
+ idbyte != 0x88 && idbyte != 0x89) {
+#if 0
+ printf ("ibmccae: pcic slot %d: wierd id/rev code 0x%02x\n",
+ slot, idbyte);
+#endif
+ continue;
+ }
+ if ((pcic_getb (slot, PCIC_STATUS) & PCIC_CD) != PCIC_CD) {
+ if (!reconfig) {
+ printf ("zp: slot %d: no card in slot\n", slot);
+ }
+ else {
+ log (LOG_NOTICE, "zp: slot %d: no card in slot\n", slot);
+ }
+ /* no card in slot */
+ continue;
+ }
+ pcic_power_on (slot);
+ pcic_reset (slot);
+ /*
+ * map the card's attribute memory and examine its
+ * card information structure tuples for something
+ * we recognize.
+ */
+#ifdef MACH_KERNEL
+ pcic_map_memory (slot, 0, scratch, 0L,
+ 0xFFFL, ATTRIBUTE, 1);
+#else /* MACH_KERNEL */
+ pcic_map_memory (slot, 0, kvtop (scratch), 0L,
+ 0xFFFL, ATTRIBUTE, 1);
+#endif /* MACH_KERNEL */
+
+ if ((zp_check_cis (scratch)) > 0) {
+ /* found it */
+ if (!reconfig) {
+ printf ("zp: found card in slot %d\n", slot);
+ }
+ else {
+ log (LOG_NOTICE, "zp: found card in slot %d\n", slot);
+ }
+ prev_slot = (prev_slot == MAXSLOT - 1) ? 0 : prev_slot+1;
+
+ return slot;
+ }
+ else {
+ if (!reconfig) {
+ printf ("zp: pcmcia slot %d: %s\n", slot, card_info);
+ }
+ else {
+ log (LOG_NOTICE, "zp: pcmcia slot %d: %s\n", slot, card_info);
+ }
+ }
+ pcic_unmap_memory (slot, 0);
+ }
+ prev_slot = 0;
+ return -1;
+}
+
+
+/*
+ * macros to handle casting unsigned long to (char *) so we can
+ * read/write into physical memory space.
+ */
+
+#define PEEK(addr) (*((unsigned char *)(addr)))
+#define POKE(addr,val) do { PEEK(addr) = (val); } while (0)
+
+/*
+ * Determine if the device is present
+ *
+ * on entry:
+ * a pointer to an isa_device struct
+ * on exit:
+ * NULL if device not found
+ * or # of i/o addresses used (if found)
+ */
+#ifdef MACH_KERNEL
+int zpprobe(port,dev)
+ struct bus_device *dev;
+#else /* MACH_KERNEL */
+int
+zpprobe(struct isa_device *isa_dev)
+#endif /* MACH_KERNEL */
+{
+#ifdef MACH_KERNEL
+ zp_softc_t *sc = &zp_softc[dev->unit];
+#else /* MACH_KERNEL */
+ struct zp_softc *sc = &zp_softc[isa_dev->id_unit];
+#endif /* MACH_KERNEL */
+ int i, x;
+ u_int memsize;
+ u_char iptr, memwidth, sum, tmp;
+ int slot;
+ u_short k;
+ int id_port = 0x100; /* XXX */
+ int re_init_flag;
+
+#ifdef ZP_DEBUG
+ printf("### zpprobe ####\n");
+#ifdef MACH_KERNEL
+ cngetc();
+#endif /* MACH_KERNEL */
+#endif /* ZP_DEBUG */
+
+
+#ifdef MACH_KERNEL
+#define DELAY(x) delay(x * 10)
+ sc->attached = 0;
+ BASE = dev->address;
+#endif /* MACH_KERNEL */
+
+ if ((slot = zp_find_adapter (isa_dev->id_maddr, isa_dev->id_reconfig)) < 0)
+ return NULL;
+
+ /*
+ * okay, we found a card, so set it up
+ */
+ /*
+ * Inhibit 16 bit memory delay.
+ * POINTETH.SYS apparently does this, for what reason I don't know.
+ */
+ pcic_putb (slot, PCIC_CDGC,
+ pcic_getb (slot, PCIC_CDGC) | PCIC_16_DL_INH);
+ /*
+ * things to map
+ * (1) card's EEPROM is already mapped by the find_adapter routine
+ * but we still need to get the card's ethernet address.
+ * after that we unmap that part of attribute memory.
+ * (2) card configuration registers need to be mapped in so we
+ * can set the configuration and socket # registers.
+ * (3) shared memory packet buffer
+ * (4) i/o ports
+ * (5) IRQ
+ */
+#ifdef notdef
+ /*
+ * Sigh. Location of the ethernet address isn't documented in [1].
+ * It was derived by doing a hex dump of all of attribute memory
+ * and looking for the IBM vendor prefix.
+ */
+ enet_addr[0] = PEEK(isa_dev->id_maddr+0xff0);
+ enet_addr[1] = PEEK(isa_dev->id_maddr+0xff2);
+ enet_addr[2] = PEEK(isa_dev->id_maddr+0xff4);
+ enet_addr[3] = PEEK(isa_dev->id_maddr+0xff6);
+ enet_addr[4] = PEEK(isa_dev->id_maddr+0xff8);
+ enet_addr[5] = PEEK(isa_dev->id_maddr+0xffa);
+#endif
+#if 0
+ pcic_unmap_memory (slot, 0);
+#endif
+ re_init_flag = 0;
+re_init:
+ /*
+ * (2) map card configuration registers. these are offset
+ * in card memory space by 0x20000. normally we could get
+ * this offset from the card information structure, but I'm
+ * too lazy and am not quite sure if I understand the CIS anyway.
+ *
+ * XXX IF YOU'RE TRYING TO PORT THIS DRIVER FOR A DIFFERENT
+ * PCMCIA CARD, the most likely thing to change is the constant
+ * 0x20000 in the next statement. Oh yes, also change the
+ * card id string that we probe for.
+ */
+#ifdef MACH_KERNEL
+ pcic_map_memory (slot, 0, dev->phys_address, 0x10000, 8L,
+ ATTRIBUTE, 1);
+ POKE(phystokv(dev->phys_address), 0x80); /* reset the card (how long?) */
+ DELAY (10000);
+#else
+ pcic_map_memory (slot, 0, kvtop (isa_dev->id_maddr), 0x10000, 8L,
+ ATTRIBUTE, 1);
+ POKE(isa_dev->id_maddr, 0x80); /* reset the card (how long?) */
+ DELAY (40000);
+#endif
+ /*
+ * Set the configuration index. According to [1], the adapter won't
+ * respond to any i/o signals until we do this; it uses the
+ * Memory Only interface (whatever that is; it's not documented).
+ * Also turn on "level" (not pulse) interrupts.
+ *
+ * XXX probably should init the socket and copy register also,
+ * so that we can deal with multiple instances of the same card.
+ */
+#ifdef MACH_KERNEL
+ POKE(phystokv(dev->phys_address), 0x41);
+ pcic_unmap_memory (slot, 0);
+#else /* MACH_KERNEL */
+ POKE(isa_dev->id_maddr, 0x41);
+ pcic_unmap_memory (slot, 0);
+#endif /* MACH_KERNEL*/
+
+#ifdef notdef
+ /*
+ * (3) now map in the shared memory buffer. This has to be mapped
+ * as words, not bytes, and on a 16k boundary. The offset value
+ * was derived by installing IBM's POINTETH.SYS under DOS and
+ * looking at the PCIC registers; it's not documented in IBM's
+ * tech ref manual ([1]).
+ */
+ pcic_map_memory (slot, 0, kvtop (isa_dev->id_maddr), 0x4000L, 0x4000L,
+ COMMON, 2);
+#endif
+
+ /*
+ * (4) map i/o ports.
+ *
+ * XXX is it possible that the config file leaves this unspecified,
+ * in which case we have to pick one?
+ *
+ * At least one PCMCIA device driver I'v seen maps a block
+ * of 32 consecutive i/o ports as two windows of 16 ports each.
+ * Maybe some other pcic chips are restricted to 16-port windows;
+ * the 82365SL doesn't seem to have that problem. But since
+ * we have an extra window anyway...
+ */
+#ifdef MACH_KERNEL
+ pcic_map_io (slot, 0, dev->address, 16, 2);
+#else
+#if 1
+ pcic_map_io (slot, 0, isa_dev->id_iobase, 16, 2);
+#else
+ pcic_map_io (slot, 0, isa_dev->id_iobase, 16, 1);
+ pcic_map_io (slot, 1, isa_dev->id_iobase + 16, 16, 1);
+#endif
+#endif
+
+ /*
+ * (5) configure the card for the desired interrupt
+ *
+ * XXX is it possible that the config file leaves this unspecified?
+ */
+ pcic_map_irq (slot, ffs (isa_dev->id_irq) - 1);
+
+ /* tell the PCIC that this is an I/O card (not memory) */
+ pcic_putb (slot, PCIC_INT_GEN,
+ pcic_getb (slot, PCIC_INT_GEN) | PCIC_CARDTYPE);
+
+#if 0
+ /* tell the PCIC to use level-mode interrupts */
+ /* XXX this register may not be present on all controllers */
+ pcic_putb (slot, PCIC_GLO_CTRL,
+ pcic_getb (slot, PCIC_GLO_CTRL) | PCIC_LVL_MODE);
+#endif
+
+#ifdef ZP_DEBUG
+ pcic_print_regs (slot);
+#endif
+#ifdef notdef
+ /* I couldn't find the following part in linux. seiji */
+
+ /*
+ * Setup i/o addresses
+ */
+ sc->nic_addr = isa_dev->id_iobase;
+#if 0
+ sc->vector = isa_dev->id_irq;
+#endif
+ sc->smem_start = (caddr_t)isa_dev->id_maddr;
+
+#if 0
+ sc->vendor = ZE_VENDOR_IBM;
+ sc->type = xxx;
+#endif
+
+ /* reset card to force it into a known state */
+ tmp = inb (isa_dev->id_iobase + ZE_RESET);
+ DELAY(20000);
+ outb (isa_dev->id_iobase + ZE_RESET, tmp);
+ DELAY(20000);
+
+ /*
+ * query MAM bit in misc register for 10base2
+ */
+ tmp = inb (isa_dev->id_iobase + ZE_MISC);
+ if (!tmp && !re_init_flag) {
+ re_init_flag++;
+ goto re_init;
+ }
+ sc->mau = tmp & 0x09 ? "10base2" : "10baseT";
+#endif
+
+#ifdef MACH_KERNEL
+ sc->ep_io_addr = dev->address;
+#else /* MACH_KERNEL */
+ sc->ep_io_addr = isa_dev->id_iobase;
+#endif /* MACH_KERNEL */
+ GO_WINDOW(0);
+#if 0
+ k = get_eeprom_data(BASE, EEPROM_ADDR_CFG); /* get addr cfg */
+#endif
+ k = read_eeprom_data(BASE, EEPROM_ADDR_CFG); /* get addr cfg */
+#ifndef ORIGINAL
+ sc->if_port = k >> 14;
+#endif /* ORIGINAL */
+#ifdef ZP_DEBUG
+ printf("EEPROM data = 0x%x\n", k);
+#endif
+ k = (k & 0x1f) * 0x10 + 0x200; /* decode base addr. */
+#ifdef MACH_KERNEL
+ if (k != (u_short)dev->address)
+#else /* MACH_KERNEL */
+ if (k != (u_short)isa_dev->id_iobase)
+#endif /* MACH_KERNEL */
+ {
+ if (!re_init_flag) {
+ re_init_flag++;
+ goto re_init;
+ }
+ return(0);
+ }
+
+ k = read_eeprom_data(BASE, EEPROM_RESOURCE_CFG);
+
+ k >>= 12;
+
+#ifdef MACH_KERNEL
+#ifdef ZP_DEBUG
+ printf("!!!IRQ Mach config: %d, board config: %d!!!\n",
+ dev->sysdep1, (k == 2) ? 9 : k);
+#ifdef MACH_KERNEL
+ cngetc();
+#endif /* MACH_KERNEL */
+#endif /* ZP_DEBUG */
+ if (dev->sysdep1 != ((k == 2) ? 9 : k))
+#else /* MACH_KERNEL */
+ if (isa_dev->id_irq != (1 << ((k == 2) ? 9 : k)))
+#endif /* MACH_KERNEL */
+#ifdef ZP_DEBUG
+ {
+ printf("Unmatched !!!!!!\n");
+ return(0);
+ }
+#else /* ZP_DEBUG */
+ return (0);
+#endif /* ZP_DEBUG */
+
+#if 0
+ outb(id_port, ACTIVATE_ADAPTER_TO_CONFIG);
+#else
+ outb(BASE, ACTIVATE_ADAPTER_TO_CONFIG);
+#endif
+
+#ifdef MACH_KERNEL
+ dev->name = zp_name;
+ return (1);
+#else /* MACH_KERNEL */
+
+ /* information for reconfiguration */
+ sc->last_alive = 0;
+ sc->last_up = 0;
+ sc->slot = slot;
+
+ return (0x10); /* 16 bytes of I/O space used. */
+#endif /* MACH_KERNEL */
+}
+
+#if NAPM > 0
+static int
+zp_suspend(isa_dev)
+ struct isa_device *isa_dev;
+{
+ struct zp_softc *sc = &zp_softc[isa_dev->id_unit];
+
+ pcic_power_off(sc->slot);
+ return 0;
+}
+
+static int
+zp_resume(isa_dev)
+ struct isa_device *isa_dev;
+{
+ prev_slot = 0;
+ reconfig_isadev(isa_dev, &net_imask);
+ return 0;
+}
+#endif /* NAPM > 0 */
+
+
+/*
+ * Install interface into kernel networking data structures
+ */
+
+#ifdef MACH_KERNEL
+void zpattach(dev)
+ struct bus_device *dev;
+#else /* MACH_KERNEL */
+int
+zpattach(isa_dev)
+ struct isa_device *isa_dev;
+#endif /* MACH_KERNEL */
+{
+#ifdef MACH_KERNEL
+ zp_softc_t *sc = &zp_softc[dev->unit];
+ struct ifnet *ifp = &(sc->ds_if);
+#else /* MACH_KERNEL */
+ struct zp_softc *sc = &zp_softc[isa_dev->id_unit];
+ struct ifnet *ifp = &sc->arpcom.ac_if;
+#endif /* MACH_KERNEL */
+ u_short i;
+ struct ifaddr *ifa;
+ struct sockaddr_dl *sdl;
+ int pl;
+
+#ifdef ZP_DEBUG
+ printf("### zpattach ####\n");
+ cngetc();
+#endif /* ZP_DEBUG */
+
+ /* PCMCIA card can be offlined. Reconfiguration is required */
+ if (isa_dev->id_reconfig) {
+ zpreset(isa_dev->id_unit);
+ if (!isa_dev->id_alive && sc->last_alive) {
+ pl = splimp();
+ sc->last_up = (ifp->if_flags & IFF_UP);
+ if_down(ifp);
+ splx(pl);
+ sc->last_alive = 0;
+ }
+ if (isa_dev->id_alive && !sc->last_alive) {
+ if (sc->last_up) {
+ pl = splimp();
+ if_up(ifp);
+ splx(pl);
+ }
+ sc->last_alive = 1;
+ }
+ return 1;
+ }
+ else {
+ sc->last_alive = 1;
+ }
+
+
+#ifdef MACH_KERNEL
+ printf(", port = %x, spl = %d, pic = %d. ",
+ dev->address, dev->sysdep, dev->sysdep1);
+
+ take_dev_irq(dev);
+ sc->ep_io_addr = dev->address;
+#else /* MACH_KERNEL */
+ sc->ep_io_addr = isa_dev->id_iobase;
+ printf("zp%d: ", isa_dev->id_unit);
+#endif /* MACH_KERNEL */
+
+ sc->ep_connectors = 0;
+
+#ifdef MACH_KERNEL
+ i = inw(sc->ep_io_addr + EP_W0_CONFIG_CTRL);
+#else /* MACH_KERNEL */
+ i = inw(isa_dev->id_iobase + EP_W0_CONFIG_CTRL);
+#endif /* MACH_KERNEL */
+
+#ifdef ZP_DEBUG
+ {
+ short if_port;
+ if_port = read_eeprom_data(BASE, 8) >> 14;
+ sc->if_port = if_port;
+ printf("Linux select:%x\n",if_port);
+ cngetc();
+ }
+
+ printf("SELECT connectors:%x\n",i);
+#endif /* ZP_DEBUG */
+
+ if (i & IS_AUI) {
+ printf("aui");
+ sc->ep_connectors |= AUI;
+ }
+ if (i & IS_BNC) {
+ if (sc->ep_connectors)
+ printf("/");
+ printf("bnc");
+ sc->ep_connectors |= BNC;
+ }
+ if (i & IS_UTP) {
+ if (sc->ep_connectors)
+ printf("/");
+ printf("utp");
+ sc->ep_connectors |= UTP;
+ }
+ if (!sc->ep_connectors)
+ printf("no connectors!");
+
+#ifdef MACH_KERNEL
+#ifndef ORIGINAL
+ printf(":%s was selected.\n",if_names[sc->if_port]);
+#ifdef ZP_DEBUG
+ cngetc();
+#endif /* EP_DEBUG */
+#endif /* ORIGINAL */
+#endif /* MACH_KERNEL */
+
+ GO_WINDOW(0);
+ {
+ short tmp_addr[3];
+ int i;
+ for (i = 0;i < 3;i++) {
+ tmp_addr[i] = htons(read_eeprom_data(BASE, i));
+ }
+#ifdef MACH_KERNEL
+ bcopy(tmp_addr, sc->ds_addr, 6);
+#else /* MACH_KERNEL */
+ bcopy(tmp_addr, sc->arpcom.ac_enaddr, 6);
+#endif /* MACH_KERNEL */
+ }
+
+#ifdef MACH_KERNEL
+ printf("id [%x:%x:%x:%x:%x:%x]",
+ sc->ds_addr[0],sc->ds_addr[1],sc->ds_addr[2],
+ sc->ds_addr[3],sc->ds_addr[4],sc->ds_addr[5]);
+ printf(" address %s\n", ether_sprintf(sc->ds_addr));
+#ifdef ZP_DEBUG
+ cngetc();
+#endif /* ZP_DEBUG */
+#else /* MACH_KERNEL */
+ printf(" address %s\n", ether_sprintf(sc->arpcom.ac_enaddr));
+#endif /* MACH_KERNEL */
+
+ ifp->if_mtu = ETHERMTU;
+#ifdef MACH_KERNEL
+ ifp->if_flags = IFF_BROADCAST;
+ ifp->if_unit = dev->unit;
+ ifp->if_header_size = sizeof(struct ether_header);
+ ifp->if_header_format = HDR_ETHERNET;
+ ifp->if_address_size = 6;
+ ifp->if_address = (char *)&sc->ds_addr[0];
+
+#define IFF_ALTPHYS 0x8000
+
+#ifdef ORIGINAL
+ /*
+ * This is a temporary.
+ * Mach can not select link with ifconfig,
+ * so I select AUI statically.
+ */
+ ifp->if_flags |= IFF_ALTPHYS;
+#else ORIGINAL
+ /*
+ * Select connector according to board setting.
+ */
+ if (sc->if_port != 3) {
+ ifp->if_flags |= IFF_ALTPHYS;
+ }
+#endif ORIGINAL
+
+ if_init_queues(ifp);
+ sc->attached = 1;
+
+#else /* MACH_KERNEL */
+ ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS;
+ ifp->if_unit = isa_dev->id_unit;
+ ifp->if_name = "zp";
+ ifp->if_init = zpinit;
+ ifp->if_output = ether_output;
+ ifp->if_start = zpstart;
+ ifp->if_ioctl = zpioctl;
+ ifp->if_watchdog = zpwatchdog;
+ /*
+ * Select connector according to board setting.
+ */
+#if defined(__NetBSD__) || defined(__FreeBSD__)
+#if 0
+ if (sc->if_port != 3) {
+ ifp->if_flags |= IFF_LINK0;
+ }
+#else
+ ifp->if_flags |= IFF_LINK0;
+#endif
+#endif /* __NetBSD__ || __FreeBSD__ */
+
+ if_attach(ifp);
+#endif /* MACH_KERNEL */
+
+#ifndef MACH_KERNEL
+ /*
+ * Fill the hardware address into ifa_addr if we find an
+ * AF_LINK entry. We need to do this so bpf's can get the hardware
+ * addr of this card. netstat likes this too!
+ */
+ ifa = ifp->if_addrlist;
+ while ((ifa != 0) && (ifa->ifa_addr != 0) &&
+ (ifa->ifa_addr->sa_family != AF_LINK))
+ ifa = ifa->ifa_next;
+
+ if ((ifa != 0) && (ifa->ifa_addr != 0)) {
+ sdl = (struct sockaddr_dl *) ifa->ifa_addr;
+ sdl->sdl_type = IFT_ETHER;
+ sdl->sdl_alen = ETHER_ADDR_LEN;
+ sdl->sdl_slen = 0;
+ bcopy(sc->arpcom.ac_enaddr, LLADDR(sdl), ETHER_ADDR_LEN);
+ }
+#if NBPFILTER > 0
+ bpfattach(&sc->bpf, ifp, DLT_EN10MB, sizeof(struct ether_header));
+#endif
+#if NAPM > 0
+ sc->s_hook.ah_fun = zp_suspend;
+ sc->s_hook.ah_arg = (void *)isa_dev;
+ sc->s_hook.ah_name = "3Com PCMCIA Etherlink III 3C589";
+ sc->s_hook.ah_order = APM_MID_ORDER;
+ apm_hook_establish(APM_HOOK_SUSPEND , &sc->s_hook);
+ sc->r_hook.ah_fun = zp_resume;
+ sc->r_hook.ah_arg = (void *)isa_dev;
+ sc->r_hook.ah_name = "3Com PCMCIA Etherlink III 3C589";
+ sc->r_hook.ah_order = APM_MID_ORDER;
+ apm_hook_establish(APM_HOOK_RESUME , &sc->r_hook);
+#endif /* NAPM > 0 */
+ return 1;
+#endif /* MACH_KERNEL */
+}
+
+/*
+ * The order in here seems important. Otherwise we may not receive
+ * interrupts. ?!
+ */
+void
+zpinit(unit)
+ int unit;
+{
+ register struct zp_softc *sc = &zp_softc[unit];
+#ifdef MACH_KERNEL
+ register struct ifnet *ifp = &sc->ds_if;
+#else /* MACH_KERNEL */
+ register struct ifnet *ifp = &sc->arpcom.ac_if;
+#endif /* MACH_KERNEL */
+ int s, i;
+
+#ifdef ZP_DEBUG
+ printf("### zpinit ####\n");
+#endif /* ZP_DEBUG */
+
+#ifndef MACH_KERNEL
+ if (ifp->if_addrlist == (struct ifaddr *) 0)
+ return;
+#endif /* MACH_KERNEL */
+
+ s = splimp();
+ while (inw(BASE + EP_STATUS) & S_COMMAND_IN_PROGRESS)
+ ;
+
+ GO_WINDOW(0);
+
+ /* Disable the card */
+ outw(BASE + EP_W0_CONFIG_CTRL, 0);
+
+ /* Enable the card */
+ outw(BASE + EP_W0_CONFIG_CTRL, ENABLE_DRQ_IRQ);
+
+ GO_WINDOW(2);
+
+ /* Reload the ether_addr. */
+ for (i = 0; i < 6; i++)
+#ifdef MACH_KERNEL
+ outb(BASE + EP_W2_ADDR_0 + i, sc->ds_addr[i]);
+#else /* MACH_KERNEL */
+ outb(BASE + EP_W2_ADDR_0 + i, sc->arpcom.ac_enaddr[i]);
+#endif /* MACH_KERNEL */
+
+ outw(BASE + EP_COMMAND, RX_RESET);
+ outw(BASE + EP_COMMAND, TX_RESET);
+
+ /* Window 1 is operating window */
+ GO_WINDOW(1);
+ for (i = 0; i < 31; i++)
+ inb(BASE + EP_W1_TX_STATUS);
+
+ /* get rid of stray intr's */
+ outw(BASE + EP_COMMAND, ACK_INTR | 0xff);
+
+ outw(BASE + EP_COMMAND, SET_RD_0_MASK | S_CARD_FAILURE | S_RX_COMPLETE |
+ S_TX_COMPLETE | S_TX_AVAIL);
+ outw(BASE + EP_COMMAND, SET_INTR_MASK | S_CARD_FAILURE | S_RX_COMPLETE |
+ S_TX_COMPLETE | S_TX_AVAIL);
+
+#ifndef ORIGINAL
+#ifndef IFF_MULTICAST
+#define IFF_MULTICAST 0x10000
+#endif
+
+#ifdef MACH_KERNEL
+ outw(BASE + EP_COMMAND, SET_RX_FILTER | FIL_INDIVIDUAL |
+ ((sc->ds_if.if_flags & IFF_MULTICAST) ? FIL_GROUP : 0) |
+ FIL_BRDCST |
+ ((sc->ds_if.if_flags & IFF_PROMISC) ? FIL_ALL : 0));
+#else
+ outw(BASE + EP_COMMAND, SET_RX_FILTER | FIL_INDIVIDUAL |
+ ((sc->arpcom.ac_if.if_flags & IFF_MULTICAST) ? FIL_GROUP : 0) |
+ FIL_BRDCST |
+ ((sc->arpcom.ac_if.if_flags & IFF_PROMISC) ? FIL_ALL : 0));
+#endif MACH_KERNEL
+#else /* ORIGINAL */
+ outw(BASE + EP_COMMAND, SET_RX_FILTER | FIL_INDIVIDUAL |
+ FIL_GROUP | FIL_BRDCST);
+#endif /* ORIGINAL */
+ /*
+ * you can `ifconfig (link0|-link0) ep0' to get the following
+ * behaviour:
+ * -link0 disable AUI/UTP. enable BNC.
+ * link0 disable BNC. enable AUI. if the card has a UTP
+ * connector, that is enabled too. not sure, but it
+ * seems you have to be careful to not plug things
+ * into both AUI & UTP.
+ */
+
+#if defined(__NetBSD__) || defined(__FreeBSD__)
+ if (!(ifp->if_flags & IFF_LINK0) && (sc->ep_connectors & BNC)) {
+#else
+ if (!(ifp->if_flags & IFF_ALTPHYS) && (sc->ep_connectors & BNC)) {
+#endif
+#ifdef ZP_DEBUG
+ printf("START TRANCEIVER");
+#endif /* ZP_DEBUG */
+ outw(BASE + EP_COMMAND, START_TRANSCEIVER);
+ DELAY(1000);
+ }
+
+#if defined(__NetBSD__) || defined(__FreeBSD__)
+ if ((ifp->if_flags & IFF_LINK0) && (sc->ep_connectors & UTP)) {
+#else
+ if ((ifp->if_flags & IFF_ALTPHYS) && (sc->ep_connectors & UTP)) {
+#endif
+#ifdef ZP_DEBUG
+ printf("ENABLE UTP");
+#endif /* ZP_DEBUG */
+ GO_WINDOW(4);
+ outw(BASE + EP_W4_MEDIA_TYPE, ENABLE_UTP);
+ GO_WINDOW(1);
+ }
+
+ outw(BASE + EP_COMMAND, RX_ENABLE);
+ outw(BASE + EP_COMMAND, TX_ENABLE);
+
+ ifp->if_flags |= IFF_RUNNING;
+#ifndef MACH_KERNEL
+ ifp->if_flags &= ~IFF_OACTIVE; /* just in case */
+#endif /* MACH_KERNEL */
+ sc->tx_start_thresh = 20; /* probably a good starting point. */
+#ifndef MACH_KERNEL
+ /*
+ * Store up a bunch of mbuf's for use later. (MAX_MBS). First we
+ * free up any that we had in case we're being called from intr or
+ * somewhere else.
+ */
+ sc->last_mb = 0;
+ sc->next_mb = 0;
+ zpmbuffill((caddr_t)sc);
+#endif /* MACH_KERNEL */
+#ifdef MACH_KERNEL
+#if 0 /* seiji */
+ sc->tbusy = 0;
+#endif
+ zpstart(unit);
+#else /* MACH_KERNEL */
+ zpstart(ifp);
+#endif /* MACH_KERNEL */
+ splx(s);
+#ifdef ZP_DEBUG
+ printf("### zpinit done ####\n");
+#endif /* ZP_DEBUG */
+}
+
+static const char padmap[] = {0, 3, 2, 1};
+
+#ifdef MACH_KERNEL
+void
+zpstart(unit)
+ int unit;
+#else /* MACH_KERNEL */
+void
+zpstart(ifp)
+ struct ifnet *ifp;
+#endif /* MACH_KERNEL */
+{
+#ifdef MACH_KERNEL
+ register struct zp_softc *sc = &zp_softc[unit];
+ struct ifnet *ifp = &sc->ds_if;
+ io_req_t m;
+#else /* MACH_KERNEL */
+ register struct zp_softc *sc = &zp_softc[ifp->if_unit];
+ struct mbuf *m, *top;
+#endif /* MACH_KERNEL */
+
+ int s, len, pad;
+
+#ifdef ZP_DEBUG
+ printf("### zpstart ####\n");
+#endif /* ZP_DEBUG */
+#ifdef ZP_DEBUG
+ printf("head1 = 0x%x\n", sc->arpcom.ac_if.if_snd.ifq_head);
+ printf("BASE = 0x%x\n", BASE);
+#endif
+
+ s = splimp();
+
+#ifndef MACH_KERNEL
+ if (sc->arpcom.ac_if.if_flags & IFF_OACTIVE) {
+ splx(s);
+#ifdef ZP_DEBUG
+ printf("### zpstart oactive ####\n");
+#endif /* ZP_DEBUG */
+ return;
+ }
+#endif /* MACH_KERNEL */
+
+startagain:
+
+#ifdef MACH_KERNEL
+
+#if 0 /* seiji */
+ if (sc->tbusy) {
+ return;
+ }
+#endif
+ /* Sneak a peek at the next packet */
+ m = (io_req_t)
+ ((ifp->if_snd.ifq_head.next == (queue_t)&(ifp->if_snd.ifq_head)) ?
+ 0 : ifp->if_snd.ifq_head.next);
+ if (m == 0) {
+ splx(s);
+#ifdef ZP_DEBUG
+ printf("### zpstart none data 1 ####\n");
+#endif /* ZP_DEBUG */
+ return;
+ }
+#if 0
+ IF_DEQUEUE(&ifp->if_snd, m);
+ if (NULL == m) {
+ return;
+ }
+#endif
+
+#if 0 /* seiji */
+ sc->tbusy++;
+ zp_cntrs[unit].xmt++;
+#endif
+ len = m->io_count;
+#else /* MACH_KERNEL */
+
+ /* Sneak a peek at the next packet */
+ m = sc->arpcom.ac_if.if_snd.ifq_head;
+#ifdef ZP_DEBUG
+ printf("head2 = 0x%x\n", sc->arpcom.ac_if.if_snd.ifq_head);
+#endif
+ if (m == 0) {
+ splx(s);
+#ifdef ZP_DEBUG
+ printf("### zpstart none data 2 ####\n");
+#endif /* EP_DEBUG */
+ return;
+ }
+#if 0
+ len = m->m_pkthdr.len;
+#else
+ for (len = 0, top = m; m; m = m->m_next)
+ len += m->m_len;
+#endif
+#endif /* MACH_KERNEL */
+
+ pad = padmap[len & 3];
+
+ /*
+ * The 3c509 automatically pads short packets to minimum ethernet
+ * length, but we drop packets that are too large. Perhaps we should
+ * truncate them instead?
+ */
+ if (len + pad > ETHER_MAX_LEN) {
+ /* packet is obviously too large: toss it */
+#ifdef MACH_KERNEL
+ ++(ifp->if_oerrors);
+ IF_DEQUEUE(&(ifp->if_snd), m);
+ iodone(m);
+
+#else /* MACH_KERNEL */
+ ++sc->arpcom.ac_if.if_oerrors;
+ IF_DEQUEUE(&sc->arpcom.ac_if.if_snd, m);
+ m_freem(m);
+#endif /* MACH_KERNEL */
+ goto readcheck;
+ }
+#if 1
+ if (inw(BASE + EP_W1_FREE_TX) < len + pad + 4) {
+ /* no room in FIFO */
+ outw(BASE + EP_COMMAND, SET_TX_AVAIL_THRESH | (len + pad + 4));
+#ifndef MACH_KERNEL
+ sc->arpcom.ac_if.if_flags |= IFF_OACTIVE;
+#endif /* MACH_KERNEL */
+ splx(s);
+
+#ifdef ZP_DEBUG
+ printf("### zpstart no room ####\n");
+#endif /* EP_DEBUG */
+ return;
+ }
+#else
+ {int i;
+ if ((i = inw(BASE + EP_W1_FREE_TX)) < len + pad + 4) {
+ printf("BASE + EP_W1_FREE_TX = 0x%x\n", i);
+ /* no room in FIFO */
+ outw(BASE + EP_COMMAND, SET_TX_AVAIL_THRESH | (len + pad + 4));
+#ifndef MACH_KERNEL
+ sc->arpcom.ac_if.if_flags |= IFF_OACTIVE;
+#endif /* MACH_KERNEL */
+ splx(s);
+
+ printf("### zpstart no room ####\n");
+ return;
+ }
+ printf("BASE + EP_W1_FREE_TX = 0x%x\n", i);
+ }
+#endif
+#ifdef MACH_KERNEL
+ IF_DEQUEUE(&(ifp->if_snd), m);
+#else /* MACH_KERNEL */
+ IF_DEQUEUE(&sc->arpcom.ac_if.if_snd, m);
+#endif /* MACH_KERNEL */
+
+ if (m == 0) { /* not really needed */
+ splx(s);
+#ifdef ZP_DEBUG
+ printf("### zpstart ??? ####\n");
+#endif /* ZP_DEBUG */
+ return;
+ }
+ outw(BASE + EP_COMMAND, SET_TX_START_THRESH |
+ (len / 4 + sc->tx_start_thresh));
+
+ outw(BASE + EP_W1_TX_PIO_WR_1, len);
+ outw(BASE + EP_W1_TX_PIO_WR_1, 0xffff); /* Second dword meaningless */
+
+#ifdef MACH_KERNEL
+ if (sc->bus32bit) {
+ loutl(BASE + EP_W1_TX_PIO_WR_1, m->io_data,len/4);
+ if (len & 3)
+ loutb(BASE + EP_W1_TX_PIO_WR_1,
+ m->io_data + (len & ~3), len & 3);
+ } else {
+ loutw(BASE + EP_W1_TX_PIO_WR_1, m->io_data, len/2);
+ if (len & 1)
+ outb(BASE + EP_W1_TX_PIO_WR_1, *(m->io_data + len - 1));
+ }
+#else /* MACH_KERNEL */
+ for (top = m; m != 0; m = m->m_next) {
+ if (sc->bus32bit) {
+ outsl(BASE + EP_W1_TX_PIO_WR_1, mtod(m, caddr_t),
+ m->m_len/4);
+ if (m->m_len & 3)
+ outsb(BASE + EP_W1_TX_PIO_WR_1,
+ mtod(m, caddr_t) + m->m_len/4,
+ m->m_len & 3);
+ } else {
+#ifdef ZP_DEBUG
+ printf("Output len = %d\n", m->m_len);
+#endif /* ZP_DEBUG */
+ outsw(BASE + EP_W1_TX_PIO_WR_1, mtod(m, caddr_t), m->m_len/2);
+ if (m->m_len & 1)
+ outb(BASE + EP_W1_TX_PIO_WR_1,
+ *(mtod(m, caddr_t) + m->m_len - 1));
+ }
+ }
+#endif /* MACH_KERNEL */
+ while (pad--)
+ outb(BASE + EP_W1_TX_PIO_WR_1, 0); /* Padding */
+
+#ifndef MACH_KERNEL
+#if NBPFILTER > 0
+ if (sc->bpf) {
+#if 0
+ u_short etype;
+ int off, datasize, resid;
+ struct ether_header *eh;
+ struct trailer_header {
+ u_short ether_type;
+ u_short ether_residual;
+ } trailer_header;
+ char ether_packet[ETHER_MAX_LEN];
+ char *ep;
+
+ ep = ether_packet;
+
+ /*
+ * We handle trailers below:
+ * Copy ether header first, then residual data,
+ * then data. Put all this in a temporary buffer
+ * 'ether_packet' and send off to bpf. Since the
+ * system has generated this packet, we assume
+ * that all of the offsets in the packet are
+ * correct; if they're not, the system will almost
+ * certainly crash in m_copydata.
+ * We make no assumptions about how the data is
+ * arranged in the mbuf chain (i.e. how much
+ * data is in each mbuf, if mbuf clusters are
+ * used, etc.), which is why we use m_copydata
+ * to get the ether header rather than assume
+ * that this is located in the first mbuf.
+ */
+ /* copy ether header */
+ m_copydata(top, 0, sizeof(struct ether_header), ep);
+ eh = (struct ether_header *) ep;
+ ep += sizeof(struct ether_header);
+ eh->ether_type = etype = ntohs(eh->ether_type);
+ if (etype >= ETHERTYPE_TRAIL &&
+ etype < ETHERTYPE_TRAIL + ETHERTYPE_NTRAILER) {
+ datasize = ((etype - ETHERTYPE_TRAIL) << 9);
+ off = datasize + sizeof(struct ether_header);
+
+ /* copy trailer_header into a data structure */
+ m_copydata(top, off, sizeof(struct trailer_header),
+ (caddr_t)&trailer_header.ether_type);
+
+ /* copy residual data */
+ resid = trailer_header.ether_residual -
+ sizeof(struct trailer_header);
+ resid = ntohs(resid);
+ m_copydata(top, off + sizeof(struct trailer_header),
+ resid, ep);
+ ep += resid;
+
+ /* copy data */
+ m_copydata(top, sizeof(struct ether_header),
+ datasize, ep);
+ ep += datasize;
+
+ /* restore original ether packet type */
+ eh->ether_type = trailer_header.ether_type;
+
+ bpf_tap(sc->bpf, ether_packet, ep - ether_packet);
+ } else
+ bpf_mtap(sc->bpf, top);
+#endif
+
+ bpf_mtap(sc->bpf, top);
+ }
+#endif
+#endif /* MACH_KERNEL */
+
+#ifdef MACH_KERNEL
+ ++(ifp->if_opackets);
+ iodone(m);
+#else /* MACH_KERNEL */
+ m_freem(top);
+ ++sc->arpcom.ac_if.if_opackets;
+#endif /* MACH_KERNEL */
+ /*
+ * Is another packet coming in? We don't want to overflow the
+ * tiny RX fifo.
+ */
+readcheck:
+ if (inw(BASE + EP_W1_RX_STATUS) & RX_BYTES_MASK) {
+ splx(s);
+#ifdef ZP_DEBUG
+ printf("### zpstart done ####\n");
+#endif /* ZP_DEBUG */
+ return;
+ }
+#ifdef ZP_DEBUG2
+ printf("### zpstart startagain ####\n");
+#endif /* ZP_DEBUG */
+ goto startagain;
+}
+
+#ifdef MACH_KERNEL
+int zpopen(dev, flag)
+ dev_t dev;
+ int flag;
+{
+ register int unit = minor(dev);
+
+#ifdef ZP_DEBUG
+ printf("### zpopen ####\n");
+#endif /* ZP_DEBUG */
+
+ if (unit < 0 || unit >= NZP || zp_softc[unit].attached == 0) {
+ return (ENXIO);
+ }
+
+ zp_softc[unit].ds_if.if_flags |= IFF_UP;
+ zpinit(unit);
+ return (0);
+}
+
+int zpoutput(dev, ior)
+ dev_t dev;
+ io_req_t ior;
+{
+ register int unit = minor(dev);
+ io_return_t result;
+
+#ifdef ZP_DEBUG
+ printf("### zpoutput ####\n");
+#endif /* ZP_DEBUG */
+
+ if (unit < 0 || unit >= NZP || zp_softc[unit].attached == 0) {
+ return (ENXIO);
+ }
+ result = net_write(&zp_softc[unit].ds_if, zpstart, ior);
+#ifdef ZP_DEBUG
+ printf("### zpoutput done ####\n");
+#endif /* ZP_DEBUG */
+ return (result);
+}
+
+int zpsetinput(dev, receive_port, priority, filter, filter_count)
+ dev_t dev;
+ mach_port_t receive_port;
+ int priority;
+ filter_t filter[];
+ unsigned int filter_count;
+{
+ register int unit = minor(dev);
+
+#ifdef ZP_DEBUG
+ printf("### zpsetinput ####\n");
+#endif /* ZP_DEBUG */
+
+ if (unit < 0 || unit >= NZP || zp_softc[unit].attached == 0) {
+ return (ENXIO);
+ }
+ return (net_set_filter(&zp_softc[unit].ds_if,
+ receive_port, priority, filter,
+ filter_count));
+}
+
+#endif /* MACH_KERNEL */
+
+#ifdef MACH_KERNEL
+int
+#else /* MACH_KERNEL */
+void
+#endif /* MACH_KERNEL */
+zpintr(unit)
+ int unit;
+{
+ int status, i;
+ register struct zp_softc *sc = &zp_softc[unit];
+
+#ifdef MACH_KERNEL
+ struct ifnet *ifp = &sc->ds_if;
+#else /* MACH_KERNEL */
+ struct ifnet *ifp = &sc->arpcom.ac_if;
+ struct mbuf *m;
+#endif /* MACH_KERNEL */
+
+#ifdef ZP_DEBUG
+ printf("### zpintr ####\n");
+#endif /* ZP_DEBUG */
+
+ status = 0;
+checkintr:
+ status = inw(BASE + EP_STATUS) &
+ (S_TX_COMPLETE | S_TX_AVAIL | S_RX_COMPLETE | S_CARD_FAILURE);
+#ifndef ORIGINAL
+checkintr2:
+#endif /* ORIGINAL */
+ if (status == 0) {
+ /* No interrupts. */
+ outw(BASE + EP_COMMAND, C_INTR_LATCH);
+#ifdef ZP_DEBUG
+ printf("### zpintr done ####\n");
+#endif /* ZP_DEBUG */
+
+#ifndef ORIGINAL
+ if (status = inw(BASE + EP_STATUS) &
+ (S_TX_COMPLETE | S_TX_AVAIL | S_RX_COMPLETE |
+ S_CARD_FAILURE)) {
+ goto checkintr2;
+ }
+#endif /* ORIGINAL */
+
+#ifdef MACH_KERNEL
+ return (0);
+#else /* MACH_KERNEL */
+ return;
+#endif /* MACH_KERNEL */
+ }
+ /* important that we do this first. */
+ outw(BASE + EP_COMMAND, ACK_INTR | status);
+
+ if (status & S_TX_AVAIL) {
+ status &= ~S_TX_AVAIL;
+ inw(BASE + EP_W1_FREE_TX);
+#ifdef MACH_KERNEL
+ zpstart(unit);
+#else /* MACH_KERNEL */
+ sc->arpcom.ac_if.if_flags &= ~IFF_OACTIVE;
+ zpstart(&sc->arpcom.ac_if);
+#endif /* MACH_KERNEL */
+
+ }
+ if (status & S_RX_COMPLETE) {
+ status &= ~S_RX_COMPLETE;
+ zpread(sc);
+ }
+ if (status & S_CARD_FAILURE) {
+ printf("zp%d: reset (status: %x)\n", unit, status);
+ outw(BASE + EP_COMMAND, C_INTR_LATCH);
+ zpinit(unit);
+#ifdef ZP_DEBUG
+ printf("### zpintr error ####\n");
+#endif /* ZP_DEBUG */
+#ifdef MACH_KERNEL
+ return (0);
+#else /* MACH_KERNEL */
+ return;
+#endif /* MACH_KERNEL */
+ }
+ if (status & S_TX_COMPLETE) {
+ status &= ~S_TX_COMPLETE;
+ /*
+ * We need to read TX_STATUS until we get a 0 status in
+ * order to turn off the interrupt flag.
+ */
+ while ((i = inb(BASE + EP_W1_TX_STATUS)) & TXS_COMPLETE) {
+ outw(BASE + EP_W1_TX_STATUS, 0x0);
+#if ZE_DEBUG
+ printf("EP_W1_TX_STATUS = 0x%x\n", i);
+#endif
+ if (i & (TXS_MAX_COLLISION | TXS_JABBER | TXS_UNDERRUN)) {
+ if (i & TXS_MAX_COLLISION)
+#ifdef MACH_KERNEL
+ ++(ifp->if_collisions);
+#else /* MACH_KERNEL */
+ ++sc->arpcom.ac_if.if_collisions;
+#endif /* MACH_KERNEL */
+ if (i & (TXS_JABBER | TXS_UNDERRUN)) {
+ outw(BASE + EP_COMMAND, TX_RESET);
+ if (i & TXS_UNDERRUN) {
+ if (sc->tx_start_thresh < ETHER_MAX_LEN) {
+ sc->tx_start_thresh += 20;
+ outw(BASE + EP_COMMAND,
+ SET_TX_START_THRESH |
+ sc->tx_start_thresh);
+ }
+ }
+ }
+ outw(BASE + EP_COMMAND, TX_ENABLE);
+#ifdef MACH_KERNEL
+ ++(ifp->if_oerrors);
+#else /* MACH_KERNEL */
+ ++sc->arpcom.ac_if.if_oerrors;
+#endif /* MACH_KERNEL */
+ }
+ }
+#ifdef MACH_KERNEL
+ zpstart(unit);
+#else /* MACH_KERNEL */
+ zpstart(ifp);
+#endif /* MACH_KERNEL */
+ }
+ goto checkintr;
+}
+
+void
+zpread(sc)
+ register struct zp_softc *sc;
+{
+ struct ether_header *eh;
+#ifdef MACH_KERNEL
+ struct ether_header eth;
+ ipc_kmsg_t new_kmsg;
+ struct packet_header *pkt;
+ int totlen;
+#else /* MACH_KERNEL */
+ struct mbuf *mcur, *m, *m0, *top;
+ int totlen, lenthisone;
+ int save_totlen;
+ u_short etype;
+ int off, resid;
+ int count, spinwait;
+#endif /* MACH_KERNEL */
+ int i;
+
+#ifdef ZP_DEBUG
+ printf("### zpread ####\n");
+#endif /* ZP_DEBUG */
+
+ totlen = inw(BASE + EP_W1_RX_STATUS);
+#ifndef MACH_KERNEL
+ off = 0;
+ top = 0;
+#endif /* MACH_KERNEL */
+
+ if (totlen & ERR_RX) {
+#ifdef MACH_KERNEL
+ ++(sc->ds_if.if_ierrors);
+#else /* MACH_KERNEL */
+ ++sc->arpcom.ac_if.if_ierrors;
+#endif /* MACH_KERNEL */
+ goto out;
+ }
+#ifdef MACH_KERNEL
+ totlen &= RX_BYTES_MASK; /* Lower 11 bits = RX bytes. */
+#else /* MACH_KERNEL */
+ save_totlen = totlen &= RX_BYTES_MASK; /* Lower 11 bits = RX bytes. */
+#endif /* MACH_KERNEL */
+
+#ifdef MACH_KERNEL
+ /* Get Etherheader */
+
+ linw(BASE + EP_W1_RX_PIO_RD_1,
+ (char *)&eth, sizeof(struct ether_header) / 2);
+ totlen -= sizeof(struct ether_header);
+
+ new_kmsg = net_kmsg_get();
+ if (new_kmsg == IKM_NULL) {
+ /* Drop the packet */
+ ++(sc->ds_if.if_rcvdrops);
+ /*
+ * Is this true ?
+ * Do I have to remove the packet ?
+ * Maybe out discard incoming packet.
+ */
+ goto out;
+ }
+ eh = (struct ether_header *)(&net_kmsg(new_kmsg)->header[0]);
+ pkt = (struct packet_header *)(&net_kmsg(new_kmsg)->packet[0]);
+
+ *eh = eth; /* Is this true ? */
+
+ if (sc->bus32bit) {
+ linl(BASE + EP_W1_RX_PIO_RD_1, (char *)(pkt + 1), totlen/4);
+ if (totlen & 3)
+ linb(BASE + EP_W1_RX_PIO_RD_1,
+ (char *)(pkt + 1) + (totlen & ~3), totlen & 3);
+ } else {
+ linw(BASE + EP_W1_RX_PIO_RD_1,
+ (char *)(pkt + 1),totlen/2);
+ if (totlen & 1)
+ *((char *)(pkt + 1) + totlen - 1) =
+ inb(BASE + EP_W1_RX_PIO_RD_1);
+ }
+
+ outw(BASE + EP_COMMAND, RX_DISCARD_TOP_PACK);
+ while (inw(BASE + EP_STATUS) & S_COMMAND_IN_PROGRESS)
+ ;
+ ++(sc->ds_if.if_ipackets);
+
+ pkt->type = eh->ether_type;
+ pkt->length = totlen + sizeof(struct packet_header);
+
+ net_packet(&(sc->ds_if), new_kmsg, pkt->length,
+ ethernet_priority(new_kmsg, pkt->type));
+
+#ifdef ZP_DEBUG
+ printf("### zpread done ####\n");
+#endif /* ZP_DEBUG */
+
+ return;
+
+#else /* MACH_KERNEL */
+ m = sc->mb[sc->next_mb];
+ sc->mb[sc->next_mb] = 0;
+
+ if (m == 0) {
+ MGETHDR(m, M_DONTWAIT, MT_DATA);
+ if (m == 0)
+ goto out;
+ } else {
+ /* Convert one of our saved mbuf's */
+ sc->next_mb = (sc->next_mb + 1) % MAX_MBS;
+ m->m_data = m->m_pktdat;
+ m->m_flags = M_PKTHDR;
+ }
+
+ top = m0 = m; /* We assign top so we can "goto out" */
+#define EROUND ((sizeof(struct ether_header) + 3) & ~3)
+#define EOFF (EROUND - sizeof(struct ether_header))
+ m0->m_data += EOFF;
+ /* Read what should be the header. */
+ insw(BASE + EP_W1_RX_PIO_RD_1,
+ mtod(m0, caddr_t), sizeof(struct ether_header) / 2);
+ m->m_len = sizeof(struct ether_header);
+ totlen -= sizeof(struct ether_header);
+ /*
+ * mostly deal with trailer here. (untested)
+ * We do this in a couple of parts. First we check for a trailer, if
+ * we have one we convert the mbuf back to a regular mbuf and set the offset and
+ * subtract sizeof(struct ether_header) from the pktlen.
+ * After we've read the packet off the interface (all except for the trailer
+ * header, we then get a header mbuf, read the trailer into it, and fix up
+ * the mbuf pointer chain.
+ */
+ eh = mtod(m, struct ether_header *);
+ eh->ether_type = etype = ntohs((u_short) eh->ether_type);
+ if (etype >= ETHERTYPE_TRAIL &&
+ etype < ETHERTYPE_TRAIL + ETHERTYPE_NTRAILER) {
+ m->m_data = m->m_dat; /* Convert back to regular mbuf. */
+ m->m_flags = 0; /* This sucks but non-trailers are the norm */
+ off = (etype - ETHERTYPE_TRAIL) * 512;
+ if (off >= ETHERMTU) {
+ m_freem(m);
+ return; /* sanity */
+ }
+ totlen -= sizeof(struct ether_header); /* We don't read the trailer */
+ m->m_data += 2 * sizeof(u_short); /* Get rid of type & len */
+ }
+ while (totlen > 0) {
+ lenthisone = min(totlen, M_TRAILINGSPACE(m));
+ if (lenthisone == 0) { /* no room in this one */
+ mcur = m;
+ m = sc->mb[sc->next_mb];
+ sc->mb[sc->next_mb] = 0;
+ if (!m) {
+ MGET(m, M_DONTWAIT, MT_DATA);
+ if (m == 0)
+ goto out;
+ } else {
+ timeout(zpmbuffill, (caddr_t)sc, 0);
+ sc->next_mb = (sc->next_mb + 1) % MAX_MBS;
+ }
+ if (totlen >= MINCLSIZE)
+ MCLGET(m, M_DONTWAIT);
+ m->m_len = 0;
+ mcur->m_next = m;
+ lenthisone = min(totlen, M_TRAILINGSPACE(m));
+ }
+ if (sc->bus32bit) {
+ insl(BASE + EP_W1_RX_PIO_RD_1, mtod(m, caddr_t) + m->m_len,
+ lenthisone / 4);
+ m->m_len += (lenthisone & ~3);
+ if (lenthisone & 3)
+ insb(BASE + EP_W1_RX_PIO_RD_1,
+ mtod(m, caddr_t) + m->m_len,
+ lenthisone & 3);
+ m->m_len += (lenthisone & 3);
+ } else {
+ insw(BASE + EP_W1_RX_PIO_RD_1, mtod(m, caddr_t) + m->m_len,
+ lenthisone / 2);
+ m->m_len += lenthisone;
+ if (lenthisone & 1)
+ *(mtod(m, caddr_t) + m->m_len - 1) = inb(BASE + EP_W1_RX_PIO_RD_1);
+ }
+ totlen -= lenthisone;
+ }
+ if (off) {
+ top = sc->mb[sc->next_mb];
+ sc->mb[sc->next_mb] = 0;
+ if (top == 0) {
+ MGETHDR(m, M_DONTWAIT, MT_DATA);
+ if (top == 0) {
+ top = m0;
+ goto out;
+ }
+ } else {
+ /* Convert one of our saved mbuf's */
+ sc->next_mb = (sc->next_mb + 1) % MAX_MBS;
+ top->m_data = top->m_pktdat;
+ top->m_flags = M_PKTHDR;
+ }
+ insw(BASE + EP_W1_RX_PIO_RD_1, mtod(top, caddr_t),
+ sizeof(struct ether_header));
+ top->m_next = m0;
+ top->m_len = sizeof(struct ether_header);
+ /* XXX Accomodate for type and len from beginning of trailer */
+ top->m_pkthdr.len = save_totlen - (2 * sizeof(u_short));
+ } else {
+ top = m0;
+ top->m_pkthdr.len = save_totlen;
+ }
+
+ top->m_pkthdr.rcvif = &sc->arpcom.ac_if;
+ outw(BASE + EP_COMMAND, RX_DISCARD_TOP_PACK);
+ while (inw(BASE + EP_STATUS) & S_COMMAND_IN_PROGRESS)
+ ;
+ ++sc->arpcom.ac_if.if_ipackets;
+#if NBPFILTER > 0
+ if (sc->bpf) {
+ bpf_mtap(sc->bpf, top);
+
+ /*
+ * Note that the interface cannot be in promiscuous mode if
+ * there are no BPF listeners. And if we are in promiscuous
+ * mode, we have to check if this packet is really ours.
+ */
+ if ((sc->arpcom.ac_if.if_flags & IFF_PROMISC) &&
+ (eh->ether_dhost[0] & 1) == 0 &&
+ bcmp(eh->ether_dhost, sc->arpcom.ac_enaddr,
+ sizeof(eh->ether_dhost)) != 0 &&
+ bcmp(eh->ether_dhost, etherbroadcastaddr,
+ sizeof(eh->ether_dhost)) != 0) {
+ m_freem(top);
+ return;
+ }
+ }
+#endif
+ m_adj(top, sizeof(struct ether_header));
+ ether_input(&sc->arpcom.ac_if, eh, top);
+ return;
+#endif /* MACH_KERNEL */
+
+out: outw(BASE + EP_COMMAND, RX_DISCARD_TOP_PACK);
+ while (inw(BASE + EP_STATUS) & S_COMMAND_IN_PROGRESS)
+ ;
+#ifndef MACH_KERNEL
+ if (top)
+ m_freem(top);
+#endif /* MACH_KERNEL */
+
+#ifdef ZP_DEBUG
+ printf("### zpread Error ####\n");
+#endif /* ZP_DEBUG */
+}
+
+
+#ifdef MACH_KERNEL
+
+int zpgetstat(dev, flavor, status, count)
+ dev_t dev;
+ int flavor;
+ dev_status_t status;
+ unsigned int *count;
+{
+ register int unit = minor(dev);
+
+#ifdef ZP_DEBUG
+ printf("### zpgetstat ####\n");
+#endif /* ZP_DEBUG */
+
+ if (unit < 0 || unit >= NZP || zp_softc[unit].attached == 0) {
+ return (ENXIO);
+ }
+ return (net_getstat(&zp_softc[unit].ds_if,flavor,status,count));
+}
+
+int zpsetstat(dev, flavor, status, count)
+ dev_t dev;
+ int flavor;
+ dev_status_t status;
+ unsigned int count;
+{
+ register int unit = minor(dev);
+ register zp_softc_t *sc;
+
+#ifdef ZP_DEBUG
+ printf("### zpsetstat ####\n");
+#endif /* ZP_DEBUG */
+
+ if (unit < 0 || unit >= NZP || zp_softc[unit].attached == 0) {
+ return (ENXIO);
+ }
+
+ sc = &zp_softc[unit];
+
+ switch (flavor) {
+ case NET_STATUS:
+ {
+ register struct net_status *ns =
+ (struct net_status *)status;
+
+ if (count < NET_STATUS_COUNT) {
+ return (D_INVALID_SIZE);
+ }
+ if (sc->ds_if.if_flags != ns->flags) {
+ sc->ds_if.if_flags = ns->flags;
+ if (sc->ds_if.if_flags & IFF_RUNNING) {
+ zpinit(sc->ds_if.if_unit);
+ }
+ }
+ }
+ break;
+ default:
+ return (D_INVALID_OPERATION);
+ }
+ return (D_SUCCESS);
+}
+
+#else /* MACH_KERNEL */
+
+/*
+ * Look familiar?
+ */
+static int
+zpioctl(ifp, cmd, data)
+ register struct ifnet *ifp;
+ int cmd;
+ caddr_t data;
+{
+ register struct ifaddr *ifa = (struct ifaddr *) data;
+ struct zp_softc *sc = &zp_softc[ifp->if_unit];
+ struct ifreq *ifr = (struct ifreq *) data;
+ int s, error = 0;
+
+#ifdef ZP_DEBUG
+ printf("### zpioctl ####\n");
+#endif /* ZP_DEBUG */
+
+ switch (cmd) {
+ case SIOCSIFADDR:
+ ifp->if_flags |= IFF_UP;
+ switch (ifa->ifa_addr->sa_family) {
+#ifdef INET
+ case AF_INET:
+ zpinit(ifp->if_unit); /* before arpwhohas */
+#if 1
+ arp_ifinit((struct arpcom *)ifp, ifa);
+#else
+ ((struct arpcom *) ifp)->ac_ipaddr = IA_SIN(ifa)->sin_addr;
+ arpwhohas((struct arpcom *) ifp, &IA_SIN(ifa)->sin_addr);
+#endif
+ break;
+#endif
+#ifdef NS
+ case AF_NS:
+ {
+ register struct ns_addr *ina = &(IA_SNS(ifa)->sns_addr);
+
+ if (ns_nullhost(*ina))
+ ina->x_host =
+ *(union ns_host *)(sc->arpcom.ac_enaddr);
+ else {
+ ifp->if_flags &= ~IFF_RUNNING;
+ bcopy((caddr_t) ina->x_host.c_host,
+ (caddr_t)sc->arpcom.ac_enaddr,
+ sizeof(sc->arpcom.ac_enaddr));
+ }
+ zpinit(ifp->if_unit);
+ break;
+ }
+#endif
+ default:
+ zpinit(ifp->if_unit);
+ break;
+ }
+ break;
+ case SIOCSIFFLAGS:
+ if ((ifp->if_flags & IFF_UP) == 0 && ifp->if_flags & IFF_RUNNING) {
+ ifp->if_flags &= ~IFF_RUNNING;
+ zpstop(ifp->if_unit);
+ zpmbufempty(sc);
+ break;
+ }
+ if (ifp->if_flags & IFF_UP && (ifp->if_flags & IFF_RUNNING) == 0)
+ zpinit(ifp->if_unit);
+ break;
+#ifdef notdef
+ case SIOCGHWADDR:
+ bcopy((caddr_t) sc->sc_addr, (caddr_t) &ifr->ifr_data,
+ sizeof(sc->sc_addr));
+ break;
+#endif
+ default:
+ error = EINVAL;
+ }
+ return (error);
+}
+
+#endif /* MACH_KERNEL */
+
+void
+zpreset(unit)
+ int unit;
+{
+ int s = splimp();
+
+#ifdef ZP_DEBUG
+ printf("### zpreset ####\n");
+#endif /* ZP_DEBUG */
+
+ zpstop(unit);
+ zpinit(unit);
+ splx(s);
+}
+
+void
+zpwatchdog(unit)
+ int unit;
+{
+ struct zp_softc *sc = &zp_softc[unit];
+
+#ifdef ZP_DEBUG
+ printf("### zpwatchdog ####\n");
+#endif /* ZP_DEBUG */
+
+#ifdef MACH_KERNEL
+ ++sc->ds_if.if_oerrors;
+#else /* MACH_KERNEL */
+ log(LOG_ERR, "zp%d: watchdog\n", unit);
+ ++sc->arpcom.ac_if.if_oerrors;
+#endif /* MACH_KERNEL */
+ zpreset(unit);
+}
+
+void
+zpstop(unit)
+ int unit;
+{
+ struct zp_softc *sc = &zp_softc[unit];
+
+#ifdef ZP_DEBUG
+ printf("### zpstop ####\n");
+#endif /* ZP_DEBUG */
+
+ outw(BASE + EP_COMMAND, RX_DISABLE);
+ outw(BASE + EP_COMMAND, RX_DISCARD_TOP_PACK);
+ while (inw(BASE + EP_STATUS) & S_COMMAND_IN_PROGRESS)
+ ;
+ outw(BASE + EP_COMMAND, TX_DISABLE);
+ outw(BASE + EP_COMMAND, STOP_TRANSCEIVER);
+ outw(BASE + EP_COMMAND, RX_RESET);
+ outw(BASE + EP_COMMAND, TX_RESET);
+ outw(BASE + EP_COMMAND, C_INTR_LATCH);
+ outw(BASE + EP_COMMAND, SET_RD_0_MASK);
+ outw(BASE + EP_COMMAND, SET_INTR_MASK);
+ outw(BASE + EP_COMMAND, SET_RX_FILTER);
+}
+
+
+/*
+ * This is adapted straight from the book. There's probably a better way.
+ */
+static int
+send_ID_sequence(port)
+ u_short port;
+{
+ char cx, al;
+
+#ifdef ZP_DEBUG2
+ printf("### send_ID_sequence ####\n");
+#ifdef MACH_KERNEL
+ cngetc();
+#endif /* MACH_KERNEL */
+#endif /* ZP_DEBUG */
+
+ cx = 0x0ff;
+ al = 0x0ff;
+
+ outb(port, 0x0);
+ DELAY(1000);
+ outb(port, 0x0);
+ DELAY(1000);
+
+loop1: cx--;
+ outb(port, al);
+ if (!(al & 0x80)) {
+ al = al << 1;
+ goto loop1;
+ }
+ al = al << 1;
+ al ^= 0xcf;
+ if (cx)
+ goto loop1;
+
+ return(1);
+}
+
+
+/*
+ * We get eeprom data from the id_port given an offset into the
+ * eeprom. Basically; after the ID_sequence is sent to all of
+ * the cards; they enter the ID_CMD state where they will accept
+ * command requests. 0x80-0xbf loads the eeprom data. We then
+ * read the port 16 times and with every read; the cards check
+ * for contention (ie: if one card writes a 0 bit and another
+ * writes a 1 bit then the host sees a 0. At the end of the cycle;
+ * each card compares the data on the bus; if there is a difference
+ * then that card goes into ID_WAIT state again). In the meantime;
+ * one bit of data is returned in the AX register which is conveniently
+ * returned to us by inb(). Hence; we read 16 times getting one
+ * bit of data with each read.
+ */
+static u_short
+get_eeprom_data(id_port, offset)
+ int id_port;
+ int offset;
+{
+ int i, data = 0;
+
+#ifdef ZP_DEBUG2
+ printf("### get_eeprom_data ####\n");
+#ifdef MACH_KERNEL
+ cngetc();
+#endif /* MACH_KERNEL */
+#endif /* ZP_DEBUG */
+
+ outb(id_port, 0x80 + offset);
+ DELAY(1000);
+ for (i = 0; i < 16; i++)
+ data = (data << 1) | (inw(id_port) & 1);
+ return (data);
+}
+
+
+static u_short
+read_eeprom_data(id_port, offset)
+ int id_port;
+ int offset;
+{
+ int i, data = 0;
+
+#ifdef ZP_DEBUG
+ printf("### read_eeprom_data ####\n");
+#ifdef MACH_KERNEL
+ cngetc();
+#endif /* MACH_KERNEL */
+#endif /* ZP_DEBUG */
+
+ outb(id_port + 10, 0x80 + offset);
+ DELAY(1000);
+ return inw(id_port + 12);
+}
+
+
+
+static int
+#ifdef MACH_KERNEL
+f_is_eeprom_busy(dev)
+ struct bus_device *dev;
+#else /* MACH_KERNEL */
+f_is_eeprom_busy(is)
+ struct isa_device *is;
+#endif /* MACH_KERNEL */
+{
+ int i = 0, j;
+#ifdef MACH_KERNEL
+ register struct zp_softc *sc = &zp_softc[dev->unit];
+#else /* MACH_KERNEL */
+ register struct zp_softc *sc = &zp_softc[is->id_unit];
+#endif /* MACH_KERNEL */
+
+#ifdef ZP_DEBUG
+ printf("### f_is_eeprom_busy ####\n");
+ printf("BASE: %x\n", BASE);
+#ifdef MACH_KERNEL
+ cngetc();
+#endif /* MACH_KERNEL */
+#endif /* ZP_DEBUG */
+
+ while (i++ < 100) {
+ j = inw(BASE + EP_W0_EEPROM_COMMAND);
+ if (j & EEPROM_BUSY)
+ DELAY(100);
+ else
+ break;
+ }
+ if (i >= 100) {
+#ifdef MACH_KERNEL
+ printf("\nzp%d: eeprom failed to come ready.\n", dev->unit);
+#else /* MACH_KERNEL */
+ printf("\nzp%d: eeprom failed to come ready.\n", is->id_unit);
+#endif /* MACH_KERNEL */
+ return (1);
+ }
+ if (j & EEPROM_TST_MODE) {
+#ifdef MACH_KERNEL
+ printf("\nzp%d: 3c589 in test mode. Erase pencil mark!\n", dev->unit);
+#else /* MACH_KERNEL */
+ printf("\nzp%d: 3c589 in test mode. Erase pencil mark!\n", is->id_unit);
+#endif /* MACH_KERNEL */
+
+ return (1);
+ }
+ return (0);
+}
+
+#ifndef MACH_KERNEL
+void
+zpmbuffill(sp)
+ caddr_t sp;
+{
+ struct zp_softc *sc = (struct zp_softc *)sp;
+ int s, i;
+
+#ifdef ZP_DEBUG
+ printf("### zpmbuffill ####\n");
+#endif /* ZP_DEBUG */
+
+ s = splimp();
+ i = sc->last_mb;
+ do {
+ if(sc->mb[i] == NULL)
+ MGET(sc->mb[i], M_DONTWAIT, MT_DATA);
+ if(sc->mb[i] == NULL)
+ break;
+ i = (i + 1) % MAX_MBS;
+ } while (i != sc->next_mb);
+ sc->last_mb = i;
+ splx(s);
+}
+
+static void
+zpmbufempty(sc)
+ struct zp_softc *sc;
+{
+ int s, i;
+
+#ifdef ZP_DEBUG
+ printf("### zpmbufempty ####\n");
+#endif /* ZP_DEBUG */
+
+ s = splimp();
+ for (i = 0; i<MAX_MBS; i++) {
+ if (sc->mb[i]) {
+ m_freem(sc->mb[i]);
+ sc->mb[i] = NULL;
+ }
+ }
+ sc->last_mb = sc->next_mb = 0;
+ untimeout(zpmbuffill, sc);
+ splx(s);
+}
+
+#endif /* MACH_KERNEL */
+
+#endif /* NZP > 0 */
diff --git a/sys/i386/isa/if_zpreg.h b/sys/i386/isa/if_zpreg.h
new file mode 100644
index 0000000..f8f184a
--- /dev/null
+++ b/sys/i386/isa/if_zpreg.h
@@ -0,0 +1,295 @@
+/*
+ * Copyright (c) 1993 Herb Peyerl (hpeyerl@novatel.ca)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. The name of the author may not be used to endorse or promote products
+ * derived from this software withough specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $Id: if_epreg.h,v 1.2 1994/01/10 19:13:50 ats Exp $
+ */
+/**************************************************************************
+ * *
+ * These define the EEPROM data structure. They are used in the probe
+ * function to verify the existance of the adapter after having sent
+ * the ID_Sequence.
+ *
+ * There are others but only the ones we use are defined here.
+ *
+ **************************************************************************/
+
+#define EEPROM_NODE_ADDR_0 0x0 /* Word */
+#define EEPROM_NODE_ADDR_1 0x1 /* Word */
+#define EEPROM_NODE_ADDR_2 0x2 /* Word */
+#define EEPROM_PROD_ID 0x3 /* 0x9[0-f]50 */
+#define EEPROM_MFG_ID 0x7 /* 0x6d50 */
+#define EEPROM_ADDR_CFG 0x8 /* Base addr */
+#define EEPROM_RESOURCE_CFG 0x9 /* IRQ. Bits 12-15 */
+
+/**************************************************************************
+ * *
+ * These are the registers for the 3Com 3c509 and their bit patterns when *
+ * applicable. They have been taken out the the "EtherLink III Parallel *
+ * Tasking EISA and ISA Technical Reference" "Beta Draft 10/30/92" manual *
+ * from 3com. *
+ * *
+ **************************************************************************/
+
+#define EP_COMMAND 0x0e /* Write. BASE+0x0e is always a command reg. */
+#define EP_STATUS 0x0e /* Read. BASE+0x0e is always status reg. */
+#define EP_WINDOW 0x0f /* Read. BASE+0x0f is always window reg. */
+/*
+ * Window 0 registers. Setup.
+ */
+ /* Write */
+#define EP_W0_EEPROM_DATA 0x0c
+#define EP_W0_EEPROM_COMMAND 0x0a
+#define EP_W0_RESOURCE_CFG 0x08
+#define EP_W0_ADDRESS_CFG 0x06
+#define EP_W0_CONFIG_CTRL 0x04
+ /* Read */
+#define EP_W0_PRODUCT_ID 0x02
+#define EP_W0_MFG_ID 0x00
+
+/*
+ * Window 1 registers. Operating Set.
+ */
+ /* Write */
+#define EP_W1_TX_PIO_WR_2 0x02
+#define EP_W1_TX_PIO_WR_1 0x00
+ /* Read */
+#define EP_W1_FREE_TX 0x0c
+#define EP_W1_TX_STATUS 0x0b /* byte */
+#define EP_W1_TIMER 0x0a /* byte */
+#define EP_W1_RX_STATUS 0x08
+#define EP_W1_RX_PIO_RD_2 0x02
+#define EP_W1_RX_PIO_RD_1 0x00
+
+/*
+ * Window 2 registers. Station Address Setup/Read
+ */
+ /* Read/Write */
+#define EP_W2_ADDR_5 0x05
+#define EP_W2_ADDR_4 0x04
+#define EP_W2_ADDR_3 0x03
+#define EP_W2_ADDR_2 0x02
+#define EP_W2_ADDR_1 0x01
+#define EP_W2_ADDR_0 0x00
+
+/*
+ * Window 3 registers. FIFO Management.
+ */
+ /* Read */
+#define EP_W3_FREE_TX 0x0c
+#define EP_W3_FREE_RX 0x0a
+
+/*
+ * Window 4 registers. Diagnostics.
+ */
+ /* Read/Write */
+#define EP_W4_MEDIA_TYPE 0x0a
+#define EP_W4_CTRLR_STATUS 0x08
+#define EP_W4_NET_DIAG 0x06
+#define EP_W4_FIFO_DIAG 0x04
+#define EP_W4_HOST_DIAG 0x02
+#define EP_W4_TX_DIAG 0x00
+
+/*
+ * Window 5 Registers. Results and Internal status.
+ */
+ /* Read */
+#define EP_W5_READ_0_MASK 0x0c
+#define EP_W5_INTR_MASK 0x0a
+#define EP_W5_RX_FILTER 0x08
+#define EP_W5_RX_EARLY_THRESH 0x06
+#define EP_W5_TX_AVAIL_THRESH 0x02
+#define EP_W5_TX_START_THRESH 0x00
+
+/*
+ * Window 6 registers. Statistics.
+ */
+ /* Read/Write */
+#define TX_TOTAL_OK 0x0c
+#define RX_TOTAL_OK 0x0a
+#define TX_DEFERRALS 0x08
+#define RX_FRAMES_OK 0x07
+#define TX_FRAMES_OK 0x06
+#define RX_OVERRUNS 0x05
+#define TX_COLLISIONS 0x04
+#define TX_AFTER_1_COLLISION 0x03
+#define TX_AFTER_X_COLLISIONS 0x02
+#define TX_NO_SQE 0x01
+#define TX_CD_LOST 0x00
+
+/****************************************
+ *
+ * Register definitions.
+ *
+ ****************************************/
+
+/*
+ * Command register. All windows.
+ *
+ * 16 bit register.
+ * 15-11: 5-bit code for command to be executed.
+ * 10-0: 11-bit arg if any. For commands with no args;
+ * this can be set to anything.
+ */
+#define GLOBAL_RESET (u_short) 0x0000 /* Wait at least 1ms after issuing */
+#define WINDOW_SELECT (u_short) (0x1<<11)
+#define START_TRANSCEIVER (u_short) (0x2<<11) /* Read ADDR_CFG reg to determine
+ whether this is needed. If so;
+ wait 800 uSec before using trans-
+ ceiver. */
+#define RX_DISABLE (u_short) (0x3<<11) /* state disabled on power-up */
+#define RX_ENABLE (u_short) (0x4<<11)
+#define RX_RESET (u_short) (0x5<<11)
+#define RX_DISCARD_TOP_PACK (u_short) (0x8<<11)
+#define TX_ENABLE (u_short) (0x9<<11)
+#define TX_DISABLE (u_short) (0xa<<11)
+#define TX_RESET (u_short) (0xb<<11)
+#define REQ_INTR (u_short) (0xc<<11)
+ /*
+ * The following C_* acknowledge the various interrupts.
+ * Some of them don't do anything. See the manual.
+ */
+#define ACK_INTR (u_short) (0x6800)
+# define C_INTR_LATCH (u_short) (ACK_INTR|0x1)
+# define C_CARD_FAILURE (u_short) (ACK_INTR|0x2)
+# define C_TX_COMPLETE (u_short) (ACK_INTR|0x4)
+# define C_TX_AVAIL (u_short) (ACK_INTR|0x8)
+# define C_RX_COMPLETE (u_short) (ACK_INTR|0x10)
+# define C_RX_EARLY (u_short) (ACK_INTR|0x20)
+# define C_INT_RQD (u_short) (ACK_INTR|0x40)
+# define C_UPD_STATS (u_short) (ACK_INTR|0x80)
+#define SET_INTR_MASK (u_short) (0xe<<11)
+#define SET_RD_0_MASK (u_short) (0xf<<11)
+#define SET_RX_FILTER (u_short) (0x10<<11)
+# define FIL_INDIVIDUAL (u_short) (0x1)
+# define FIL_GROUP (u_short) (0x2)
+# define FIL_BRDCST (u_short) (0x4)
+# define FIL_ALL (u_short) (0x8)
+#define SET_RX_EARLY_THRESH (u_short) (0x11<<11)
+#define SET_TX_AVAIL_THRESH (u_short) (0x12<<11)
+#define SET_TX_START_THRESH (u_short) (0x13<<11)
+#define STATS_ENABLE (u_short) (0x15<<11)
+#define STATS_DISABLE (u_short) (0x16<<11)
+#define STOP_TRANSCEIVER (u_short) (0x17<<11)
+
+/*
+ * Status register. All windows.
+ *
+ * 15-13: Window number(0-7).
+ * 12: Command_in_progress.
+ * 11: reserved.
+ * 10: reserved.
+ * 9: reserved.
+ * 8: reserved.
+ * 7: Update Statistics.
+ * 6: Interrupt Requested.
+ * 5: RX Early.
+ * 4: RX Complete.
+ * 3: TX Available.
+ * 2: TX Complete.
+ * 1: Adapter Failure.
+ * 0: Interrupt Latch.
+ */
+#define S_INTR_LATCH (u_short) (0x1)
+#define S_CARD_FAILURE (u_short) (0x2)
+#define S_TX_COMPLETE (u_short) (0x4)
+#define S_TX_AVAIL (u_short) (0x8)
+#define S_RX_COMPLETE (u_short) (0x10)
+#define S_RX_EARLY (u_short) (0x20)
+#define S_INT_RQD (u_short) (0x40)
+#define S_UPD_STATS (u_short) (0x80)
+#define S_COMMAND_IN_PROGRESS (u_short) (0x1000)
+
+/*
+ * FIFO Registers. RX Status.
+ *
+ * 15: Incomplete or FIFO empty.
+ * 14: 1: Error in RX Packet 0: Incomplete or no error.
+ * 13-11: Type of error.
+ * 1000 = Overrun.
+ * 1011 = Run Packet Error.
+ * 1100 = Alignment Error.
+ * 1101 = CRC Error.
+ * 1001 = Oversize Packet Error (>1514 bytes)
+ * 0010 = Dribble Bits.
+ * (all other error codes, no errors.)
+ *
+ * 10-0: RX Bytes (0-1514)
+ */
+#define ERR_INCOMPLETE (u_short) (0x8000)
+#define ERR_RX (u_short) (0x4000)
+#define ERR_RX_PACKET (u_short) (0x2000)
+#define ERR_OVERRUN (u_short) (0x1000)
+#define ERR_RUNT (u_short) (0x1300)
+#define ERR_ALIGNMENT (u_short) (0x1400)
+#define ERR_CRC (u_short) (0x1500)
+#define ERR_OVERSIZE (u_short) (0x1100)
+#define ERR_DRIBBLE (u_short) (0x200)
+
+/*
+ * TX Status
+ *
+ * Reports the transmit status of a completed transmission. Writing this
+ * register pops the transmit completion stack.
+ *
+ * Window 1/Port 0x0b.
+ *
+ * 7: Complete
+ * 6: Interrupt on successful transmission requested.
+ * 5: Jabber Error (TP Only, TX Reset required. )
+ * 4: Underrun (TX Reset required. )
+ * 3: Maximum Collisions.
+ * 2: TX Status Overflow.
+ * 1-0: Undefined.
+ *
+ */
+#define TXS_COMPLETE 0x80
+#define TXS_INTR_REQ 0x40
+#define TXS_JABBER 0x20
+#define TXS_UNDERRUN 0x10
+#define TXS_MAX_COLLISION 0x8
+#define TXS_STATUS_OVERFLOW 0x4
+
+/*
+ * Misc defines for various things.
+ */
+#define TAG_ADAPTER_0 0xd0
+#define ACTIVATE_ADAPTER_TO_CONFIG 0xff
+#define ENABLE_DRQ_IRQ 0x0001
+#define MFG_ID 0x6d50
+#define PROD_ID 0x9150
+#define BASE sc->ep_io_addr
+#define GO_WINDOW(x) outw(BASE+EP_COMMAND, WINDOW_SELECT|x)
+#define AUI 0x1
+#define BNC 0x2
+#define UTP 0x4
+#define IS_AUI (1<<13)
+#define IS_BNC (1<<12)
+#define IS_UTP (1<<9)
+#define EEPROM_BUSY (1<<15)
+#define EEPROM_TST_MODE (1<<14)
+#define READ_EEPROM (1<<7)
+#define ETHER_ADDR_LEN 6
+#define ETHER_MAX 1536
+#define ENABLE_UTP 0xc0
+#define DISABLE_UTP 0x0
+#define RX_BYTES_MASK (u_short) (0x07ff)
diff --git a/sys/i386/isa/isa.c b/sys/i386/isa/isa.c
index 2246826..3b4aa1f 100644
--- a/sys/i386/isa/isa.c
+++ b/sys/i386/isa/isa.c
@@ -34,7 +34,7 @@
* SUCH DAMAGE.
*
* from: @(#)isa.c 7.2 (Berkeley) 5/13/91
- * $Id: isa.c,v 1.35 1994/11/01 17:26:29 ache Exp $
+ * $Id: isa.c,v 1.36 1994/11/03 04:15:03 jkh Exp $
*/
/*
@@ -417,9 +417,11 @@ config_isadev_c(isdp, mp, reconfig)
}
if (reconfig) {
last_alive = isdp->id_alive;
+ isdp->id_reconfig = 1;
}
else {
last_alive = 0;
+ isdp->id_reconfig = 0;
}
id_alive = (*dp->probe)(isdp);
if (id_alive) {
diff --git a/sys/i386/isa/pcic.c b/sys/i386/isa/pcic.c
new file mode 100644
index 0000000..4c5977a
--- /dev/null
+++ b/sys/i386/isa/pcic.c
@@ -0,0 +1,249 @@
+/*-
+ * TODO:
+ * [1] integrate into current if_ed.c
+ * [2] parse tuples to find out where to map the shared memory buffer,
+ * and what to write into the configuration register
+ * [3] move pcic-specific code into a separate module.
+ *
+ * Device driver for IBM PCMCIA Credit Card Adapter for Ethernet,
+ * if_ze.c
+ *
+ * Based on the Device driver for National Semiconductor DS8390 ethernet
+ * adapters by David Greenman. Modifications for PCMCIA by Keith Moore.
+ * Adapted for FreeBSD 1.1.5 by Jordan Hubbard.
+ *
+ * Currently supports only the IBM Credit Card Adapter for Ethernet, but
+ * could probably work with other PCMCIA cards also, if it were modified
+ * to get the locations of the PCMCIA configuration option register (COR)
+ * by parsing the configuration tuples, rather than by hard-coding in
+ * the value expected by IBM's card.
+ *
+ * Sources for data on the PCMCIA/IBM CCAE specific portions of the driver:
+ *
+ * [1] _Local Area Network Credit Card Adapters Technical Reference_,
+ * IBM Corp., SC30-3585-00, part # 33G9243.
+ * [2] "pre-alpha" PCMCIA support code for Linux by Barry Jaspan.
+ * [3] Intel 82536SL PC Card Interface Controller Data Sheet, Intel
+ * Order Number 290423-002
+ * [4] National Semiconductor DP83902A ST-NIC (tm) Serial Network
+ * Interface Controller for Twisted Pair data sheet.
+ *
+ *
+ * Copyright (C) 1993, David Greenman. This software may be used, modified,
+ * copied, distributed, and sold, in both source and binary form provided
+ * that the above copyright and 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 use.
+ */
+#include <sys/param.h>
+#if defined(__FreeBSD__)
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#endif
+#include <i386/isa/isa.h>
+#include <i386/isa/isa_device.h>
+#include <i386/isa/icu.h>
+#include <i386/isa/pcic.h>
+
+void
+pcic_print_regs (int slot)
+{
+ int i, j;
+
+ for (i = 0; i < 0x40; i += 16) {
+ for (j = 0; j < 16; ++j)
+ printf ("%02x ", pcic_getb (slot, i + j));
+ printf ("\n");
+ }
+}
+
+/*
+ * map a portion of the card's memory space into system memory
+ * space.
+ *
+ * slot = # of the slot the card is plugged into
+ * window = which pcic memory map registers to use (0..4)
+ * sys_addr = base system PHYSICAL memory address where we want it. must
+ * be on an appropriate boundary (lower 12 bits are zero).
+ * card_addr = the base address of the card's memory to correspond
+ * to sys_addr
+ * length = length of the segment to map (may be rounded up as necessary)
+ * type = which card memory space to map (attribute or shared)
+ * width = 1 for byte-wide mapping; 2 for word (16-bit) mapping.
+ */
+
+void
+pcic_map_memory (int slot, int window, unsigned long sys_addr,
+ unsigned long card_addr, unsigned long length,
+ enum memtype type, int width)
+{
+ unsigned short offset;
+ unsigned short mem_start_addr;
+ unsigned short mem_stop_addr;
+
+ sys_addr >>= 12;
+ card_addr >>= 12;
+ length >>= 12;
+ /*
+ * compute an offset for the chip such that
+ * (sys_addr + offset) = card_addr
+ * but the arithmetic is done modulo 2^14
+ */
+ offset = (card_addr - sys_addr) & 0x3FFF;
+ /*
+ * now OR in the bit for "attribute memory" if necessary
+ */
+ if (type == ATTRIBUTE) {
+ offset |= (PCIC_REG << 8);
+ /* REG == "region active" pin on card */
+ }
+ /*
+ * okay, set up the chip memory mapping registers, and turn
+ * on the enable bit for this window.
+ * if we are doing 16-bit wide accesses (width == 2),
+ * turn on the appropriate bit.
+ *
+ * XXX for now, we set all of the wait state bits to zero.
+ * Not really sure how they should be set.
+ */
+ mem_start_addr = sys_addr & 0xFFF;
+ if (width == 2)
+ mem_start_addr |= (PCIC_DATA16 << 8);
+ mem_stop_addr = (sys_addr + length) & 0xFFF;
+
+ pcic_putw (slot, MEM_START_ADDR(window), mem_start_addr);
+ pcic_putw (slot, MEM_STOP_ADDR(window), mem_stop_addr);
+ pcic_putw (slot, MEM_OFFSET(window), offset);
+ /*
+ * Assert the bit (PCIC_MEMCS16) that says to decode all of
+ * the address lines.
+ */
+ pcic_putb (slot, PCIC_ADDRWINE,
+ pcic_getb (slot, PCIC_ADDRWINE) |
+ MEM_ENABLE_BIT(window) | PCIC_MEMCS16);
+}
+
+void
+pcic_unmap_memory (int slot, int window)
+{
+ /*
+ * seems like we need to turn off the enable bit first, after which
+ * we can clear the registers out just to be sure.
+ */
+ pcic_putb (slot, PCIC_ADDRWINE,
+ pcic_getb (slot, PCIC_ADDRWINE) & ~MEM_ENABLE_BIT(window));
+ pcic_putw (slot, MEM_START_ADDR(window), 0);
+ pcic_putw (slot, MEM_STOP_ADDR(window), 0);
+ pcic_putw (slot, MEM_OFFSET(window), 0);
+}
+
+/*
+ * map a range of addresses into system i/o space
+ * (no translation of i/o addresses is possible)
+ *
+ * 'width' is:
+ * + 0 to tell the PCIC to generate the ISA IOCS16* signal from
+ * the PCMCIA IOIS16* signal.
+ * + 1 to select 8-bit width
+ * + 2 to select 16-bit width
+ */
+
+void
+pcic_map_io (int slot, int window, unsigned short base, unsigned short length,
+ unsigned short width)
+{
+ unsigned char x;
+
+ pcic_putw (slot, IO_START_ADDR(window), base);
+ pcic_putw (slot, IO_STOP_ADDR(window), base+length-1);
+ /*
+ * select the bits that determine whether
+ * an i/o operation is 8 or 16 bits wide
+ */
+ x = pcic_getb (slot, PCIC_IOCTL);
+ switch (width) {
+ case 0: /* PCMCIA card decides */
+ if (window)
+ x = (x & 0xf0) | PCIC_IO1_CS16;
+ else
+ x = (x & 0x0f) | PCIC_IO0_CS16;
+ break;
+ case 1: /* 8 bits wide */
+ break;
+ case 2: /* 16 bits wide */
+ if (window)
+ x = (x & 0xf0) | PCIC_IO1_16BIT;
+ else
+ x = (x & 0x0f) | PCIC_IO0_16BIT;
+ break;
+ }
+ pcic_putb (slot, PCIC_IOCTL, x);
+ pcic_putb (slot, PCIC_ADDRWINE,
+ pcic_getb (slot, PCIC_ADDRWINE) | IO_ENABLE_BIT(window));
+}
+
+#ifdef TEST
+void
+pcic_unmap_io (int slot, int window)
+{
+ pcic_putb (slot, PCIC_ADDRWINE,
+ pcic_getb (slot, PCIC_ADDRWINE) & ~IO_ENABLE_BIT(window));
+ pcic_putw (slot, IO_START_ADDR(window), 0);
+ pcic_putw (slot, IO_STOP_ADDR(window), 0);
+}
+#endif /* TEST */
+
+/*
+ * tell the PCIC which irq we want to use. only the following are legal:
+ * 3, 4, 5, 7, 9, 10, 11, 12, 14, 15
+ *
+ * NB: 'irq' is an interrupt NUMBER, not a MASK as in struct isa_device.
+ */
+
+void
+pcic_map_irq (int slot, int irq)
+{
+ if (irq < 3 || irq == 6 || irq == 8 || irq == 13 || irq > 15) {
+ printf ("zp: pcic_map_irq (slot %d): illegal irq %d\n", slot, irq);
+ return;
+ }
+ pcic_putb (slot, PCIC_INT_GEN,
+ pcic_getb (slot, PCIC_INT_GEN) | (irq & 0x0F));
+}
+
+void
+pcic_power_on (int slot)
+{
+ pcic_putb (slot, PCIC_STATUS,
+ pcic_getb (slot, PCIC_STATUS) | PCIC_POW);
+ DELAY (100000);
+ pcic_putb (slot, PCIC_POWER,
+ pcic_getb (slot, PCIC_POWER) | PCIC_DISRST | PCIC_PCPWRE);
+ DELAY (100000);
+ pcic_putb (slot, PCIC_POWER,
+ pcic_getb (slot, PCIC_POWER) | PCIC_OUTENA);
+}
+
+void
+pcic_power_off (int slot)
+{
+ /*
+ * If you success to power-off the PCMCIA slots and
+ * resume safely, please tell me your way to implement it.
+ *
+ * HOSOKAWA, Tatsumi <hosokawa@mt.cs.keio.ac.jp>
+ */
+}
+
+void
+pcic_reset (int slot)
+{
+ /* assert RESET (by clearing a bit!), wait a bit, and de-assert it */
+ pcic_putb (slot, PCIC_INT_GEN,
+ pcic_getb (slot, PCIC_INT_GEN) & ~PCIC_CARDRESET);
+ DELAY (100000);
+ pcic_putb (slot, PCIC_INT_GEN,
+ pcic_getb (slot, PCIC_INT_GEN) | PCIC_CARDRESET);
+}
+
diff --git a/sys/i386/isa/pcic.h b/sys/i386/isa/pcic.h
new file mode 100644
index 0000000..852f332
--- /dev/null
+++ b/sys/i386/isa/pcic.h
@@ -0,0 +1,181 @@
+/*-
+ * TODO:
+ * [1] integrate into current if_ed.c
+ * [2] parse tuples to find out where to map the shared memory buffer,
+ * and what to write into the configuration register
+ * [3] move pcic-specific code into a separate module.
+ *
+ * Device driver for IBM PCMCIA Credit Card Adapter for Ethernet,
+ * if_ze.c
+ *
+ * Based on the Device driver for National Semiconductor DS8390 ethernet
+ * adapters by David Greenman. Modifications for PCMCIA by Keith Moore.
+ * Adapted for FreeBSD 1.1.5 by Jordan Hubbard.
+ *
+ * Currently supports only the IBM Credit Card Adapter for Ethernet, but
+ * could probably work with other PCMCIA cards also, if it were modified
+ * to get the locations of the PCMCIA configuration option register (COR)
+ * by parsing the configuration tuples, rather than by hard-coding in
+ * the value expected by IBM's card.
+ *
+ * Sources for data on the PCMCIA/IBM CCAE specific portions of the driver:
+ *
+ * [1] _Local Area Network Credit Card Adapters Technical Reference_,
+ * IBM Corp., SC30-3585-00, part # 33G9243.
+ * [2] "pre-alpha" PCMCIA support code for Linux by Barry Jaspan.
+ * [3] Intel 82536SL PC Card Interface Controller Data Sheet, Intel
+ * Order Number 290423-002
+ * [4] National Semiconductor DP83902A ST-NIC (tm) Serial Network
+ * Interface Controller for Twisted Pair data sheet.
+ *
+ *
+ * Copyright (C) 1993, David Greenman. This software may be used, modified,
+ * copied, distributed, and sold, in both source and binary form provided
+ * that the above copyright and 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 use.
+ */
+
+#ifndef __PCIC_H__
+#define __PCIC_H__
+
+/*****************************************************************************
+ * pcmcia controller chip (PCIC) support *
+ * (eventually, move this to a separate file) *
+ *****************************************************************************/
+#include "ic/i82365.h"
+
+/*
+ * Each PCIC chip (82365SL or clone) can handle two card slots, and there
+ * can be up to four PCICs in a system. (On some machines, not all of the
+ * address lines are decoded, so a card may appear to be in more than one
+ * slot.)
+ */
+#define MAXSLOT 8
+
+/*
+ * To access a register on the PCIC for a particular slot, you
+ * first write the correct OFFSET value for that slot in the
+ * INDEX register for the PCIC controller. You then read or write
+ * the value from or to the DATA register for that controller.
+ *
+ * The first pair of chips shares I/O addresss for DATA and INDEX,
+ * as does the second pair. (To the programmer, it looks like each
+ * pair is a single chip.) The i/o port addresses are hard-wired
+ * into the PCIC; so the following addresses should be valid for
+ * any machine that uses this chip.
+ */
+
+#define PCIC_INDEX_0 0x3E0 /* index reg, chips 0 and 1 */
+#define PCIC_DATA_0 0x3E1 /* data register, chips 0 and 1 */
+#define PCIC_INDEX_1 0x3E2 /* index reg, chips 1 and 2 */
+#define PCIC_DATA_1 0x3E3 /* data register, chips 1 and 2 */
+
+/*
+ * Given a slot number, calculate the INDEX and DATA registers
+ * to talk to that slot. OFFSET is added to the register number
+ * to address the registers for a particular slot.
+ */
+#define INDEX(slot) ((slot) < 4 ? PCIC_INDEX_0 : PCIC_INDEX_1)
+#define DATA(slot) ((slot) < 4 ? PCIC_DATA_0 : PCIC_DATA_1)
+#define OFFSET(slot) ((slot) % 4 * 0x40)
+
+/*
+ * There are 5 sets (windows) of memory mapping registers on the PCIC chip
+ * for each slot, numbered 0..4.
+ *
+ * They start at 10/50 hex within the chip's register space (not system
+ * I/O space), and are eight addresses apart. These are actually pairs of
+ * 8-bit-wide registers (low byte first, then high byte) since the
+ * address fields are actually 12 bits long. The upper bits are used
+ * for other things like 8/16-bit select and wait states.
+ *
+ * Memory mapping registers include start/stop addresses to define the
+ * region to be mapped (in terms of system memory addresses), and
+ * an offset register to allow for translation from system space
+ * to card space. The lower 12 bits aren't included in these, so memory is
+ * mapped in 4K chunks.
+ */
+#define MEM_START_ADDR(window) (((window) * 0x08) + 0x10)
+#define MEM_STOP_ADDR(window) (((window) * 0x08) + 0x12)
+#define MEM_OFFSET(window) (((window) * 0x08) + 0x14)
+/*
+ * this bit gets set in the address window enable register (PCIC_ADDRWINE)
+ * to enable a particular address window.
+ */
+#define MEM_ENABLE_BIT(window) ((1) << (window))
+
+/*
+ * There are two i/o port addressing windows. I/O ports cannot be
+ * relocated within system i/o space (unless the card doesn't decode
+ * all of the address bits); unlike card memory, there is no address
+ * translation offset.
+ */
+#define IO_START_ADDR(window) ((window) ? PCIC_IO1_STL : PCIC_IO0_STL)
+#define IO_STOP_ADDR(window) ((window) ? PCIC_IO1_SPL : PCIC_IO0_SPL)
+#define IO_ENABLE_BIT(window) ((window) ? PCIC_IO1_EN : PCIC_IO0_EN)
+#define IO_CS16_BIT(window) ((window) ? PCIC_IO1_CS16 : PCIC_IO0_CS16)
+
+/*
+ * types of mapped memory
+ */
+enum memtype { COMMON, ATTRIBUTE };
+
+/*
+ * read a byte from a pcic register for a particular slot
+ */
+static inline unsigned char
+pcic_getb (int slot, int reg)
+{
+ outb (INDEX(slot), OFFSET (slot) + reg);
+ return inb (DATA (slot));
+}
+
+/*
+ * write a byte to a pcic register for a particular slot
+ */
+static inline void
+pcic_putb (int slot, int reg, unsigned char val)
+{
+ outb (INDEX(slot), OFFSET (slot) + reg);
+ outb (DATA (slot), val);
+}
+
+/*
+ * read a word from a pcic register for a particular slot
+ */
+static inline unsigned short
+pcic_getw (int slot, int reg)
+{
+ return pcic_getb (slot, reg) | (pcic_getb (slot, reg+1) << 8);
+}
+
+/*
+ * write a word to a pcic register at a particular slot
+ */
+static inline void
+pcic_putw (int slot, int reg, unsigned short val)
+{
+ pcic_putb (slot, reg, val & 0xff);
+ pcic_putb (slot, reg + 1, (val >> 8) & 0xff);
+}
+
+
+void pcic_print_regs (int slot);
+void pcic_map_memory (int slot, int window, unsigned long sys_addr,
+ unsigned long card_addr, unsigned long length,
+ enum memtype type, int width);
+void pcic_unmap_memory (int slot, int window);
+void pcic_map_io (int slot, int window, unsigned short base,
+ unsigned short length, unsigned short width);
+#ifdef TEST
+void pcic_unmap_io (int slot, int window);
+#endif /* TEST */
+void pcic_map_irq (int slot, int irq);
+void pcic_power_on (int slot);
+void pcic_power_off (int slot);
+void pcic_reset (int slot);
+
+
+#endif /* __PCIC_H__ */
diff --git a/sys/i386/isa/syscons.c b/sys/i386/isa/syscons.c
index 24a952c..102cc0e 100644
--- a/sys/i386/isa/syscons.c
+++ b/sys/i386/isa/syscons.c
@@ -35,7 +35,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: syscons.c,v 1.101 1995/02/07 11:53:27 sos Exp $
+ * $Id: syscons.c,v 1.102 1995/02/14 14:37:53 sos Exp $
*/
#include "sc.h"
@@ -72,6 +72,10 @@
#if !defined(MAXCONS)
#define MAXCONS 16
#endif
+#include "apm.h"
+#if NAPM > 0
+#include "machine/apm_bios.h"
+#endif
/* this may break on older VGA's but is usefull on real 32 bit systems */
#define bcopyw bcopy
@@ -188,6 +192,9 @@ typedef struct scr_stat {
u_short *history_pos; /* position shown on screen */
u_short *history_save; /* save area index */
int history_size; /* size of history buffer */
+#if NAPM > 0
+ struct apmhook r_hook; /* reconfiguration support */
+#endif /* NAPM > 0 */
} scr_stat;
typedef struct default_attr {
@@ -414,6 +421,20 @@ sc_registerdev(struct isa_device *id)
dev_attach(&kdc_sc[id->id_unit]);
}
+#if NAPM > 0
+/* ARGSUSED */
+static int
+pcresume(void *dummy)
+{
+ shfts = 0;
+ ctls = 0;
+ alts = 0;
+ agrs = 0;
+ metas = 0;
+ return 0;
+}
+#endif /* NAPM > 0 */
+
int
scattach(struct isa_device *dev)
@@ -464,6 +485,13 @@ scattach(struct isa_device *dev)
update_leds(scp->status);
sc_registerdev(dev);
+#if NAPM > 0
+ scp->r_hook.ah_fun = pcresume;
+ scp->r_hook.ah_arg = NULL;
+ scp->r_hook.ah_name = "pccons keyboard";
+ scp->r_hook.ah_order = APM_MID_ORDER;
+ apm_hook_establish(APM_HOOK_RESUME , &scp->r_hook);
+#endif /* NAPM > 0*/
return 0;
}
@@ -2827,6 +2855,9 @@ next_code:
shutdown_nice();
break;
case SUSP:
+#if NAPM > 0
+ apm_suspend();
+#endif
break;
case DBG:
OpenPOWER on IntegriCloud