#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: dec_5100.c,v 1.48 2014/03/24 19:31:40 christos Exp $");
#define __INTR_PRIVATE
#include <sys/param.h>
#include <sys/cpu.h>
#include <sys/device.h>
#include <sys/intr.h>
#include <sys/lwp.h>
#include <sys/kernel.h>
#include <sys/systm.h>
#include <mips/locore.h>
#include <mips/mips/mips_mcclock.h>
#include <pmax/locore.h>
#include <pmax/sysconf.h>
#include <dev/tc/tcvar.h>
#include <pmax/pmax/machdep.h>
#include <pmax/pmax/kn01.h>
#include <pmax/pmax/kn230.h>
#include <pmax/ibus/ibusvar.h>
#include <pmax/pmax/cons.h>
void dec_5100_init(void);
static void dec_5100_bus_reset(void);
static void dec_5100_cons_init(void);
static void dec_5100_intr(uint32_t, vaddr_t, uint32_t);
static void dec_5100_intr_establish(device_t, void *,
int, int (*)(void *), void *);
static void dec_5100_memintr(void);
static const struct ipl_sr_map dec_5100_ipl_sr_map = {
.sr_bits = {
[IPL_NONE] = 0,
[IPL_SOFTCLOCK] = MIPS_SOFT_INT_MASK_0,
[IPL_SOFTNET] = MIPS_SOFT_INT_MASK,
[IPL_VM] = MIPS_SPL_0_1,
[IPL_SCHED] = MIPS_SPLHIGH,
[IPL_DDB] = MIPS_SPLHIGH,
[IPL_HIGH] = MIPS_SPLHIGH,
},
};
void
dec_5100_init(void)
{
platform.iobus = "baseboard";
platform.bus_reset = dec_5100_bus_reset;
platform.cons_init = dec_5100_cons_init;
platform.iointr = dec_5100_intr;
platform.intr_establish = dec_5100_intr_establish;
platform.memsize = memsize_scan;
mips_set_wbflush(kn230_wbflush);
ipl_sr_map = dec_5100_ipl_sr_map;
mc_cpuspeed(MIPS_PHYS_TO_KSEG1(KN01_SYS_CLOCK), MIPS_INT_MASK_2);
cpu_setmodel("DECsystem 5100 (MIPSMATE)");
}
static void
dec_5100_bus_reset(void)
{
uint32_t icsr;
icsr = *(volatile uint32_t *)MIPS_PHYS_TO_KSEG1(KN230_SYS_ICSR);
icsr |= KN230_CSR_INTR_WMERR;
*(volatile uint32_t *)MIPS_PHYS_TO_KSEG1(KN230_SYS_ICSR) = icsr;
kn230_wbflush();
}
static void
dec_5100_cons_init(void)
{
DELAY(160000000 / 9600);
dz_ibus_cnsetup(KN230_SYS_DZ0);
dz_ibus_cnattach(0);
}
static void
dec_5100_intr_establish(device_t dev, void *cookie, int level,
int (*handler)(void *), void *arg)
{
intrtab[(intptr_t)cookie].ih_func = handler;
intrtab[(intptr_t)cookie].ih_arg = arg;
}
#define CALLINTR(vvv, ibit) \
do { \
if ((icsr & (ibit)) && intrtab[vvv].ih_func) { \
(*intrtab[vvv].ih_func)(intrtab[vvv].ih_arg); \
intrtab[vvv].ih_count.ev_count++; \
} \
} while (0)
static void
dec_5100_intr(uint32_t status, vaddr_t pc, uint32_t ipending)
{
uint32_t icsr;
if (ipending & MIPS_INT_MASK_4) {
#ifdef DDB
Debugger();
#else
prom_haltbutton();
#endif
}
icsr = *(volatile uint32_t *)MIPS_PHYS_TO_KSEG1(KN230_SYS_ICSR);
if (ipending & MIPS_INT_MASK_2) {
struct clockframe cf;
__asm volatile("lbu $0,48(%0)" ::
"r"(MIPS_PHYS_TO_KSEG1(KN01_SYS_CLOCK)));
cf.pc = pc;
cf.sr = status;
cf.intr = (curcpu()->ci_idepth > 1);
hardclock(&cf);
pmax_clock_evcnt.ev_count++;
}
if (ipending & MIPS_INT_MASK_0) {
CALLINTR(SYS_DEV_SCC0, KN230_CSR_INTR_DZ0);
CALLINTR(SYS_DEV_OPT0, KN230_CSR_INTR_OPT0);
CALLINTR(SYS_DEV_OPT1, KN230_CSR_INTR_OPT1);
}
if (ipending & MIPS_INT_MASK_1) {
CALLINTR(SYS_DEV_LANCE, KN230_CSR_INTR_LANCE);
CALLINTR(SYS_DEV_SCSI, KN230_CSR_INTR_SII);
}
if (ipending & MIPS_INT_MASK_3) {
dec_5100_memintr();
pmax_memerr_evcnt.ev_count++;
}
}
static void
dec_5100_memintr(void)
{
uint32_t icsr;
icsr = *(volatile uint32_t *)MIPS_PHYS_TO_KSEG1(KN230_SYS_ICSR);
icsr |= KN230_CSR_INTR_WMERR;
*(volatile uint32_t *)MIPS_PHYS_TO_KSEG1(KN230_SYS_ICSR) = icsr;
kn230_wbflush();
#ifdef DIAGNOSTIC
printf("\nMemory interrupt\n");
#endif
if (cold)
return;
if (icsr & KN230_CSR_INTR_WMERR) {
panic("write to non-existent memory");
} else {
panic("stray memory error interrupt");
}
}