#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 <machine/rpb.h>
#include <dev/tc/tcvar.h>
#include <alpha/tc/tc_conf.h>
#include <alpha/tc/tc_3000_500.h>
#include "wsdisplay.h"
int tc_3000_500_intrnull(void *);
int tc_3000_500_fb_cnattach(u_int64_t);
#define C(x) ((void *)(u_long)x)
#define KV(x) (ALPHA_PHYS_TO_K0SEG(x))
struct tc_slotdesc tc_3000_500_slots[] = {
{ KV(0x100000000), C(TC_3000_500_DEV_OPT0), },
{ KV(0x120000000), C(TC_3000_500_DEV_OPT1), },
{ KV(0x140000000), C(TC_3000_500_DEV_OPT2), },
{ KV(0x160000000), C(TC_3000_500_DEV_OPT3), },
{ KV(0x180000000), C(TC_3000_500_DEV_OPT4), },
{ KV(0x1a0000000), C(TC_3000_500_DEV_OPT5), },
{ KV(0x1c0000000), C(TC_3000_500_DEV_BOGUS), },
{ KV(0x1e0000000), C(TC_3000_500_DEV_BOGUS), },
};
int tc_3000_500_nslots =
sizeof(tc_3000_500_slots) / sizeof(tc_3000_500_slots[0]);
struct tc_builtin tc_3000_500_graphics_builtins[] = {
{ "FLAMG-IO", 7, 0x00000000, C(TC_3000_500_DEV_IOASIC), },
{ "PMAGB-BA", 7, 0x02000000, C(TC_3000_500_DEV_CXTURBO), },
{ "PMAZ-DS ", 6, 0x00000000, C(TC_3000_500_DEV_TCDS), },
};
int tc_3000_500_graphics_nbuiltins = sizeof(tc_3000_500_graphics_builtins) /
sizeof(tc_3000_500_graphics_builtins[0]);
struct tc_builtin tc_3000_500_nographics_builtins[] = {
{ "FLAMG-IO", 7, 0x00000000, C(TC_3000_500_DEV_IOASIC), },
{ "PMAZ-DS ", 6, 0x00000000, C(TC_3000_500_DEV_TCDS), },
};
int tc_3000_500_nographics_nbuiltins = sizeof(tc_3000_500_nographics_builtins) /
sizeof(tc_3000_500_nographics_builtins[0]);
u_int32_t tc_3000_500_intrbits[TC_3000_500_NCOOKIES] = {
TC_3000_500_IR_OPT0,
TC_3000_500_IR_OPT1,
TC_3000_500_IR_OPT2,
TC_3000_500_IR_OPT3,
TC_3000_500_IR_OPT4,
TC_3000_500_IR_OPT5,
TC_3000_500_IR_TCDS,
TC_3000_500_IR_IOASIC,
TC_3000_500_IR_CXTURBO,
};
struct tcintr {
int (*tci_func)(void *);
void *tci_arg;
int tci_level;
struct evcount tci_count;
} tc_3000_500_intr[TC_3000_500_NCOOKIES];
u_int32_t tc_3000_500_imask;
void
tc_3000_500_intr_setup(void)
{
u_long i;
tc_3000_500_imask = *(volatile u_int32_t *)TC_3000_500_IMR_READ;
for (i = 0; i < TC_3000_500_NCOOKIES; i++)
tc_3000_500_imask |= tc_3000_500_intrbits[i];
*(volatile u_int32_t *)TC_3000_500_IMR_WRITE = tc_3000_500_imask;
tc_mb();
for (i = 0; i < TC_3000_500_NCOOKIES; i++) {
tc_3000_500_intr[i].tci_func = tc_3000_500_intrnull;
tc_3000_500_intr[i].tci_arg = (void *)i;
tc_3000_500_intr[i].tci_level = IPL_HIGH;
}
}
void
tc_3000_500_intr_establish(struct device *tcadev, void *cookie, int level,
int (*func)(void *), void *arg, const char *name)
{
u_long dev = (u_long)cookie;
#ifdef DIAGNOSTIC
#endif
if (tc_3000_500_intr[dev].tci_func != tc_3000_500_intrnull)
panic("tc_3000_500_intr_establish: cookie %lu twice", dev);
tc_3000_500_intr[dev].tci_func = func;
tc_3000_500_intr[dev].tci_arg = arg;
tc_3000_500_intr[dev].tci_level = level;
if (name != NULL)
evcount_attach(&tc_3000_500_intr[dev].tci_count, name, NULL);
tc_3000_500_imask &= ~tc_3000_500_intrbits[dev];
*(volatile u_int32_t *)TC_3000_500_IMR_WRITE = tc_3000_500_imask;
tc_mb();
}
void
tc_3000_500_intr_disestablish(struct device *tcadev, void *cookie,
const char *name)
{
u_long dev = (u_long)cookie;
#ifdef DIAGNOSTIC
#endif
if (tc_3000_500_intr[dev].tci_func == tc_3000_500_intrnull)
panic("tc_3000_500_intr_disestablish: cookie %lu bad intr",
dev);
tc_3000_500_imask |= tc_3000_500_intrbits[dev];
*(volatile u_int32_t *)TC_3000_500_IMR_WRITE = tc_3000_500_imask;
tc_mb();
tc_3000_500_intr[dev].tci_func = tc_3000_500_intrnull;
tc_3000_500_intr[dev].tci_arg = (void *)dev;
tc_3000_500_intr[dev].tci_level = IPL_HIGH;
if (name != NULL)
evcount_detach(&tc_3000_500_intr[dev].tci_count);
}
int
tc_3000_500_intrnull(void *val)
{
panic("tc_3000_500_intrnull: uncaught TC intr for cookie %ld",
(u_long)val);
}
void
tc_3000_500_iointr(void *arg, unsigned long vec)
{
u_int32_t ir;
int ifound;
do {
tc_syncbus();
ir = *(volatile u_int32_t *)TC_3000_500_IR_CLEAR;
ir &= ~(tc_3000_500_imask & 0x1ff);
ifound = 0;
#ifdef MULTIPROCESSOR
#define INTRLOCK(slot) \
if (tc_3000_500_intr[slot].tci_level < IPL_CLOCK) \
__mp_lock(&kernel_lock)
#define INTRUNLOCK(slot) \
if (tc_3000_500_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) \
if (ir & tc_3000_500_intrbits[slot]) { \
ifound = 1; \
INTRLOCK(slot); \
(*tc_3000_500_intr[slot].tci_func) \
(tc_3000_500_intr[slot].tci_arg); \
tc_3000_500_intr[slot].tci_count.ec_count++; \
INTRUNLOCK(slot); \
}
CHECKINTR(TC_3000_500_DEV_CXTURBO);
CHECKINTR(TC_3000_500_DEV_IOASIC);
CHECKINTR(TC_3000_500_DEV_TCDS);
CHECKINTR(TC_3000_500_DEV_OPT5);
CHECKINTR(TC_3000_500_DEV_OPT4);
CHECKINTR(TC_3000_500_DEV_OPT3);
CHECKINTR(TC_3000_500_DEV_OPT2);
CHECKINTR(TC_3000_500_DEV_OPT1);
CHECKINTR(TC_3000_500_DEV_OPT0);
#undef INTRUNLOCK
#undef INTRLOCK
#undef CHECKINTR
#ifdef DIAGNOSTIC
#define PRINTINTR(msg, bits) \
if (ir & bits) \
printf(msg);
PRINTINTR("Second error occurred\n", TC_3000_500_IR_ERR2);
PRINTINTR("DMA buffer error\n", TC_3000_500_IR_DMABE);
PRINTINTR("DMA cross 2K boundary\n", TC_3000_500_IR_DMA2K);
PRINTINTR("TC reset in progress\n", TC_3000_500_IR_TCRESET);
PRINTINTR("TC parity error\n", TC_3000_500_IR_TCPAR);
PRINTINTR("DMA tag error\n", TC_3000_500_IR_DMATAG);
PRINTINTR("Single-bit error\n", TC_3000_500_IR_DMASBE);
PRINTINTR("Double-bit error\n", TC_3000_500_IR_DMADBE);
PRINTINTR("TC I/O timeout\n", TC_3000_500_IR_TCTIMEOUT);
PRINTINTR("DMA block too long\n", TC_3000_500_IR_DMABLOCK);
PRINTINTR("Invalid I/O address\n", TC_3000_500_IR_IOADDR);
PRINTINTR("DMA scatter/gather invalid\n", TC_3000_500_IR_DMASG);
PRINTINTR("Scatter/gather parity error\n",
TC_3000_500_IR_SGPAR);
#undef PRINTINTR
#endif
} while (ifound);
}
#if NWSDISPLAY > 0
int
tc_3000_500_fb_cnattach(u_int64_t turbo_slot)
{
u_int32_t output_slot;
output_slot = turbo_slot & 0xffffffff;
if (output_slot >= tc_3000_500_nslots) {
return EINVAL;
}
if (hwrpb->rpb_variation & SV_GRAPHICS) {
if (output_slot == 0) {
return ENXIO;
}
} else {
output_slot += 3;
}
return tc_fb_cnattach(tc_3000_500_slots[output_slot-1].tcs_addr);
}
#endif
void
tc_3000_500_ioslot(u_int32_t slot, u_int32_t flags, int set)
{
volatile u_int32_t *iosp;
u_int32_t ios;
int s;
iosp = (volatile u_int32_t *)TC_3000_500_IOSLOT;
ios = *iosp;
flags <<= (slot * 3);
if (set)
ios |= flags;
else
ios &= ~flags;
s = splhigh();
*iosp = ios;
tc_mb();
splx(s);
}
int
tc_3000_500_activate(struct device *self, int act)
{
int slot;
int rv;
switch (act) {
case DVACT_POWERDOWN:
rv = config_activate_children(self, act);
for (slot = 0; slot < tc_3000_500_nslots; slot++)
tc_3000_500_ioslot(slot, IOSLOT_S, 0);
break;
default:
rv = config_activate_children(self, act);
break;
}
return rv;
}