#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: vme_two_isr.c,v 1.18 2024/01/19 03:59:47 thorpej Exp $");
#include "vmetwo.h"
#include "opt_mvmeconf.h"
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/malloc.h>
#include <sys/cpu.h>
#include <sys/bus.h>
#include <dev/vme/vmereg.h>
#include <dev/vme/vmevar.h>
#include <dev/mvme/mvmebus.h>
#include <dev/mvme/vme_tworeg.h>
#include <dev/mvme/vme_twovar.h>
int vmetwo_not_present;
static struct vme_two_handler {
int (*isr_hand)(void *);
void *isr_arg;
} vme_two_handlers[(VME2_VECTOR_LOCAL_MAX - VME2_VECTOR_LOCAL_MIN) + 1];
#define VMETWO_HANDLERS_SZ (sizeof(vme_two_handlers) / \
sizeof(struct vme_two_handler))
static int vmetwo_local_isr_trampoline(void *);
#ifdef notyet
static void vmetwo_softintr_assert(void);
#endif
static struct vmetwo_softc *vmetwo_sc;
int
vmetwo_probe(bus_space_tag_t bt, bus_addr_t offset)
{
bus_space_handle_t bh;
bus_space_map(bt, offset + VME2REG_LCSR_OFFSET, VME2LCSR_SIZE, 0, &bh);
if (bus_space_peek_4(bt, bh, VME2LCSR_MISC_STATUS, NULL) != 0) {
#if defined(MVME162) || defined(MVME172)
#if defined(MVME167) || defined(MVME177)
if (machineid == MVME_162 || machineid == MVME_172)
#endif
{
extern void pcctwosoftintrinit(void);
bus_space_unmap(bt, bh, VME2LCSR_SIZE);
vmetwo_not_present = 1;
pcctwosoftintrinit();
return (0);
}
#endif
#if defined(MVME167) || defined(MVME177) || defined(MVME88K)
panic("VMEChip2 not responding! Faulty board?");
#endif
#if defined(MVMEPPC)
bus_space_unmap(bt, bh, VME2LCSR_SIZE);
vmetwo_not_present = 1;
return (0);
#endif
}
#if NVMETWO == 0
else {
struct vmetwo_softc *sc;
sc = malloc(sizeof(*sc), M_DEVBUF, M_WAITOK);
sc->sc_mvmebus.sc_bust = bt;
sc->sc_lcrh = bh;
vmetwo_intr_init(sc);
return 0;
}
#else
bus_space_unmap(bt, bh, VME2LCSR_SIZE);
return (1);
#endif
}
void
vmetwo_intr_init(struct vmetwo_softc *sc)
{
u_int32_t reg;
int i;
vmetwo_sc = sc;
for (i = 0; i < VMETWO_HANDLERS_SZ; i++)
vme_two_handlers[i].isr_hand = NULL;
reg = vme2_lcsr_read(sc, VME2LCSR_MISC_STATUS) & ~VME2_MISC_STATUS_MIEN;
vme2_lcsr_write(sc, VME2LCSR_MISC_STATUS, reg);
vme2_lcsr_write(sc, VME2LCSR_LOCAL_INTERRUPT_ENABLE, 0);
vme2_lcsr_write(sc, VME2LCSR_LOCAL_INTERRUPT_CLEAR,
VME2_LOCAL_INTERRUPT_CLEAR_ALL);
for (i = 0; i < VME2_NUM_IL_REGS; i++)
vme2_lcsr_write(sc, VME2LCSR_INTERRUPT_LEVEL_BASE + (i * 4), 0);
reg = vme2_lcsr_read(sc, VME2LCSR_TIMER_CONTROL);
reg &= ~VME2_TIMER_CONTROL_EN(0);
reg &= ~VME2_TIMER_CONTROL_EN(1);
vme2_lcsr_write(sc, VME2LCSR_TIMER_CONTROL, reg);
reg = vme2_lcsr_read(sc, VME2LCSR_VECTOR_BASE);
reg &= ~VME2_VECTOR_BASE_MASK;
reg |= VME2_VECTOR_BASE_REG_VALUE;
vme2_lcsr_write(sc, VME2LCSR_VECTOR_BASE, reg);
reg = vme2_lcsr_read(sc, VME2LCSR_MISC_STATUS) | VME2_MISC_STATUS_MIEN;
vme2_lcsr_write(sc, VME2LCSR_MISC_STATUS, reg);
vmetwo_md_intr_init(sc);
#if defined(MVME167) || defined(MVME177)
#if defined(MVME162) || defined(MVME172)
if (machineid != MVME_162 && machineid != MVME_172)
#endif
{
vmetwo_intr_establish(sc, 7, 7, VME2_VEC_ABORT, 1,
nmihand, NULL, NULL);
}
#endif
#ifdef notyet
vmetwo_intr_establish(sc, 1, 1, VME2_VEC_SOFT0, 1,
(int (*)(void *))softintr_dispatch, NULL, NULL);
_softintr_chipset_assert = vmetwo_softintr_assert;
#endif
}
static int
vmetwo_local_isr_trampoline(void *arg)
{
struct vme_two_handler *isr;
int vec;
vec = (int) arg;
vme2_lcsr_write(vmetwo_sc, VME2LCSR_LOCAL_INTERRUPT_CLEAR,
VME2_LOCAL_INTERRUPT(vec));
isr = &vme_two_handlers[vec - VME2_VECTOR_LOCAL_OFFSET];
if (isr->isr_hand)
(void) (*isr->isr_hand) (isr->isr_arg);
else
printf("vmetwo: Spurious local interrupt, vector 0x%x\n", vec);
return (1);
}
void
vmetwo_local_intr_establish(int pri, int vec, int (*hand)(void *), void *arg, struct evcnt *evcnt)
{
vmetwo_intr_establish(vmetwo_sc, pri, pri, vec, 1, hand, arg, evcnt);
}
void
vmetwo_intr_establish(void *csc, int prior, int lvl, int vec, int first, int (*hand)(void *), void *arg, struct evcnt *evcnt)
{
struct vmetwo_softc *sc = csc;
u_int32_t reg;
int bitoff;
int iloffset, ilshift;
int s;
s = splhigh();
#if NVMETWO > 0
if (vec >= VME2_VECTOR_LOCAL_MIN && vec <= VME2_VECTOR_LOCAL_MAX) {
#endif
vme_two_handlers[vec - VME2_VECTOR_LOCAL_MIN].isr_hand = hand;
vme_two_handlers[vec - VME2_VECTOR_LOCAL_MIN].isr_arg = arg;
hand = vmetwo_local_isr_trampoline;
arg = (void *) (vec - VME2_VECTOR_BASE);
bitoff = vec - VME2_VECTOR_BASE;
#if NVMETWO > 0
first = 1;
} else {
bitoff = lvl - 1;
}
#endif
(*sc->sc_isrlink)(sc->sc_isrcookie, hand, arg, prior, vec, evcnt);
#if NVMETWO > 0
if (first) {
if (evcnt)
evcnt_attach_dynamic(evcnt, EVCNT_TYPE_INTR,
(*sc->sc_isrevcnt)(sc->sc_isrcookie, prior),
device_xname(sc->sc_mvmebus.sc_dev),
mvmebus_irq_name[lvl]);
#endif
iloffset = VME2_ILOFFSET_FROM_VECTOR(bitoff) +
VME2LCSR_INTERRUPT_LEVEL_BASE;
ilshift = VME2_ILSHIFT_FROM_VECTOR(bitoff);
reg = vme2_lcsr_read(sc, iloffset);
reg &= ~(VME2_INTERRUPT_LEVEL_MASK << ilshift);
reg |= (prior << ilshift);
vme2_lcsr_write(sc, iloffset, reg);
vme2_lcsr_write(sc, VME2LCSR_LOCAL_INTERRUPT_CLEAR,
VME2_LOCAL_INTERRUPT(bitoff));
reg = vme2_lcsr_read(sc, VME2LCSR_LOCAL_INTERRUPT_ENABLE);
reg |= VME2_LOCAL_INTERRUPT(bitoff);
vme2_lcsr_write(sc, VME2LCSR_LOCAL_INTERRUPT_ENABLE, reg);
#if NVMETWO > 0
}
#ifdef DIAGNOSTIC
else {
iloffset = VME2_ILOFFSET_FROM_VECTOR(bitoff) +
VME2LCSR_INTERRUPT_LEVEL_BASE;
ilshift = VME2_ILSHIFT_FROM_VECTOR(bitoff);
reg = vme2_lcsr_read(sc, iloffset);
reg &= (VME2_INTERRUPT_LEVEL_MASK << ilshift);
if ((prior << ilshift) != reg)
panic("vmetwo_intr_establish: priority mismatch!");
}
#endif
#endif
splx(s);
}
void
vmetwo_intr_disestablish(void *csc, int lvl, int vec, int last, struct evcnt *evcnt)
{
struct vmetwo_softc *sc = csc;
u_int32_t reg;
int iloffset, ilshift;
int bitoff;
int s;
s = splhigh();
#if NVMETWO > 0
if (vec >= VME2_VECTOR_LOCAL_MIN && vec <= VME2_VECTOR_LOCAL_MAX) {
#endif
bitoff = vec - VME2_VECTOR_BASE;
vme_two_handlers[vec - VME2_VECTOR_LOCAL_MIN].isr_hand = NULL;
last = 1;
#if NVMETWO > 0
} else {
bitoff = lvl - 1;
}
#endif
if (last) {
iloffset = VME2_ILOFFSET_FROM_VECTOR(bitoff) +
VME2LCSR_INTERRUPT_LEVEL_BASE;
ilshift = VME2_ILSHIFT_FROM_VECTOR(bitoff);
reg = vme2_lcsr_read(sc, VME2LCSR_LOCAL_INTERRUPT_ENABLE);
reg &= ~VME2_LOCAL_INTERRUPT(bitoff);
vme2_lcsr_write(sc, VME2LCSR_LOCAL_INTERRUPT_ENABLE, reg);
reg = vme2_lcsr_read(sc, iloffset);
reg &= ~(VME2_INTERRUPT_LEVEL_MASK << ilshift);
vme2_lcsr_write(sc, iloffset, reg);
vme2_lcsr_write(sc, VME2LCSR_LOCAL_INTERRUPT_CLEAR,
VME2_LOCAL_INTERRUPT(vec));
if (evcnt)
evcnt_detach(evcnt);
}
(*sc->sc_isrunlink)(sc->sc_isrcookie, vec);
splx(s);
}
#ifdef notyet
static void
vmetwo_softintr_assert(void)
{
vme2_lcsr_write(vmetwo_sc, VME2LCSR_SOFTINT_SET, VME2_SOFTINT_SET(0));
}
#endif