#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/malloc.h>
#include <machine/autoconf.h>
#include <machine/pte.h>
#include <dev/tc/tcvar.h>
#include <dev/tc/ioasicreg.h>
#include <alpha/tc/tc_conf.h>
#include <alpha/tc/tc_3000_300.h>
#include "wsdisplay.h"
int tc_3000_300_intrnull(void *);
#define C(x) ((void *)(u_long)x)
#define KV(x) (ALPHA_PHYS_TO_K0SEG(x))
#define DEC_3000_300_IOASIC_ADDR KV(0x1a0000000)
struct tc_slotdesc tc_3000_300_slots[] = {
{ KV(0x100000000), C(TC_3000_300_DEV_OPT0), },
{ KV(0x120000000), C(TC_3000_300_DEV_OPT1), },
{ KV(0x140000000), C(TC_3000_300_DEV_BOGUS), },
{ KV(0x160000000), C(TC_3000_300_DEV_BOGUS), },
{ KV(0x180000000), C(TC_3000_300_DEV_BOGUS), },
{ KV(0x1a0000000), C(TC_3000_300_DEV_BOGUS), },
{ KV(0x1c0000000), C(TC_3000_300_DEV_BOGUS), },
};
int tc_3000_300_nslots =
sizeof(tc_3000_300_slots) / sizeof(tc_3000_300_slots[0]);
struct tc_builtin tc_3000_300_builtins[] = {
{ "PMAGB-BA", 6, 0x02000000, C(TC_3000_300_DEV_CXTURBO), },
{ "FLAMG-IO", 5, 0x00000000, C(TC_3000_300_DEV_IOASIC), },
{ "PMAZ-DS ", 4, 0x00000000, C(TC_3000_300_DEV_TCDS), },
};
int tc_3000_300_nbuiltins =
sizeof(tc_3000_300_builtins) / sizeof(tc_3000_300_builtins[0]);
struct tcintr {
int (*tci_func)(void *);
void *tci_arg;
int tci_level;
struct evcount tci_count;
} tc_3000_300_intr[TC_3000_300_NCOOKIES];
void
tc_3000_300_intr_setup(void)
{
volatile u_int32_t *imskp;
u_long i;
imskp = (volatile u_int32_t *)(DEC_3000_300_IOASIC_ADDR + IOASIC_IMSK);
*imskp &= ~(IOASIC_INTR_300_OPT0 | IOASIC_INTR_300_OPT1);
for (i = 0; i < TC_3000_300_NCOOKIES; i++) {
tc_3000_300_intr[i].tci_func = tc_3000_300_intrnull;
tc_3000_300_intr[i].tci_arg = (void *)i;
tc_3000_300_intr[i].tci_level = IPL_HIGH;
}
}
void
tc_3000_300_intr_establish(struct device *tcadev, void *cookie, int level,
int (*func)(void *), void *arg, const char *name)
{
volatile u_int32_t *imskp;
u_long dev = (u_long)cookie;
#ifdef DIAGNOSTIC
#endif
if (tc_3000_300_intr[dev].tci_func != tc_3000_300_intrnull)
panic("tc_3000_300_intr_establish: cookie %lu twice", dev);
tc_3000_300_intr[dev].tci_func = func;
tc_3000_300_intr[dev].tci_arg = arg;
tc_3000_300_intr[dev].tci_level = level;
if (name != NULL)
evcount_attach(&tc_3000_300_intr[dev].tci_count, name, NULL);
imskp = (volatile u_int32_t *)(DEC_3000_300_IOASIC_ADDR + IOASIC_IMSK);
switch (dev) {
case TC_3000_300_DEV_OPT0:
*imskp |= IOASIC_INTR_300_OPT0;
break;
case TC_3000_300_DEV_OPT1:
*imskp |= IOASIC_INTR_300_OPT1;
break;
default:
break;
}
}
void
tc_3000_300_intr_disestablish(struct device *tcadev, void *cookie,
const char *name)
{
volatile u_int32_t *imskp;
u_long dev = (u_long)cookie;
#ifdef DIAGNOSTIC
#endif
if (tc_3000_300_intr[dev].tci_func == tc_3000_300_intrnull)
panic("tc_3000_300_intr_disestablish: cookie %lu bad intr",
dev);
imskp = (volatile u_int32_t *)(DEC_3000_300_IOASIC_ADDR + IOASIC_IMSK);
switch (dev) {
case TC_3000_300_DEV_OPT0:
*imskp &= ~IOASIC_INTR_300_OPT0;
break;
case TC_3000_300_DEV_OPT1:
*imskp &= ~IOASIC_INTR_300_OPT1;
break;
default:
break;
}
tc_3000_300_intr[dev].tci_func = tc_3000_300_intrnull;
tc_3000_300_intr[dev].tci_arg = (void *)dev;
tc_3000_300_intr[dev].tci_level = IPL_HIGH;
if (name != NULL)
evcount_detach(&tc_3000_300_intr[dev].tci_count);
}
int
tc_3000_300_intrnull(void *val)
{
panic("tc_3000_300_intrnull: uncaught TC intr for cookie %ld",
(u_long)val);
}
void
tc_3000_300_iointr(void *arg, unsigned long vec)
{
u_int32_t tcir, ioasicir, ioasicimr;
int ifound;
do {
tc_syncbus();
tcir = *(volatile u_int32_t *)TC_3000_300_IR;
ioasicir = *(volatile u_int32_t *)
(DEC_3000_300_IOASIC_ADDR + IOASIC_INTR);
ioasicimr = *(volatile u_int32_t *)
(DEC_3000_300_IOASIC_ADDR + IOASIC_IMSK);
tc_mb();
ioasicir &= ioasicimr;
*(volatile u_int32_t *)TC_3000_300_IR = tcir;
tc_wmb();
ifound = 0;
#ifdef MULTIPROCESSOR
#define INTRLOCK(slot) \
if (tc_3000_300_intr[slot].tci_level < IPL_CLOCK) \
__mp_lock(&kernel_lock)
#define INTRUNLOCK(slot) \
if (tc_3000_300_intr[slot].tci_level < IPL_CLOCK) \
__mp_unlock(&kernel_lock)
#else
#define INTRLOCK(slot) do { } while (0)
#define INTRUNLOCK(slot) do { } while (0)
#endif
#define CHECKINTR(slot, flag) \
if (flag) { \
ifound = 1; \
INTRLOCK(slot); \
(*tc_3000_300_intr[slot].tci_func) \
(tc_3000_300_intr[slot].tci_arg); \
tc_3000_300_intr[slot].tci_count.ec_count++; \
INTRUNLOCK(slot); \
}
CHECKINTR(TC_3000_300_DEV_CXTURBO,
tcir & TC_3000_300_IR_CXTURBO);
CHECKINTR(TC_3000_300_DEV_IOASIC,
(tcir & TC_3000_300_IR_IOASIC) &&
(ioasicir & ~(IOASIC_INTR_300_OPT1|IOASIC_INTR_300_OPT0)));
CHECKINTR(TC_3000_300_DEV_TCDS, tcir & TC_3000_300_IR_TCDS);
CHECKINTR(TC_3000_300_DEV_OPT1,
ioasicir & IOASIC_INTR_300_OPT1);
CHECKINTR(TC_3000_300_DEV_OPT0,
ioasicir & IOASIC_INTR_300_OPT0);
#undef INTRUNLOCK
#undef INTRLOCK
#undef CHECKINTR
#ifdef DIAGNOSTIC
#define PRINTINTR(msg, bits) \
if (tcir & bits) \
printf(msg);
PRINTINTR("BCache tag parity error\n",
TC_3000_300_IR_BCTAGPARITY);
PRINTINTR("TC overrun error\n", TC_3000_300_IR_TCOVERRUN);
PRINTINTR("TC I/O timeout\n", TC_3000_300_IR_TCTIMEOUT);
PRINTINTR("Bcache parity error\n",
TC_3000_300_IR_BCACHEPARITY);
PRINTINTR("Memory parity error\n", TC_3000_300_IR_MEMPARITY);
#undef PRINTINTR
#endif
} while (ifound);
}
#if NWSDISPLAY > 0
int
tc_3000_300_fb_cnattach(u_int64_t turbo_slot)
{
u_int32_t output_slot;
output_slot = turbo_slot & 0xffffffff;
if (output_slot >= tc_3000_300_nslots) {
return EINVAL;
}
if (output_slot == 0) {
return ENXIO;
}
return tc_fb_cnattach(tc_3000_300_slots[output_slot-1].tcs_addr);
}
#endif