#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: uba_bi.c,v 1.16 2024/02/04 18:52:35 andvar Exp $");
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/buf.h>
#include <sys/device.h>
#include <sys/proc.h>
#include <sys/malloc.h>
#include <sys/systm.h>
#include <machine/sid.h>
#include <machine/pte.h>
#include <machine/pcb.h>
#include <machine/trap.h>
#include <machine/scb.h>
#include <vax/bi/bireg.h>
#include <vax/bi/bivar.h>
#include <vax/uba/ubareg.h>
#include <vax/uba/ubavar.h>
#include "locators.h"
#define BUA(uba) ((struct dwbua_regs *)(uba))
static int uba_bi_match(device_t, cfdata_t, void *);
static void uba_bi_attach(device_t, device_t, void *);
static void bua_init(struct uba_softc *);
static void bua_purge(struct uba_softc *, int);
#define BUACSR_ERR 0x80000000
#define BUACSR_BIF 0x10000000
#define BUACSR_SSYNTO 0x08000000
#define BUACSR_UIE 0x04000000
#define BUACSR_IVMR 0x02000000
#define BUACSR_BADBDP 0x01000000
#define BUACSR_BUAEIE 0x00100000
#define BUACSR_UPI 0x00020000
#define BUACSR_UREGDUMP 0x00010000
#define BUACSR_IERRNO 0x000000ff
#define BUAOFFSET_MASK 0x00003e00
#define BUADPR_DPSEL 0x00e00000
#define BUADPR_PURGE 0x00000001
#define BUAMR_IOADR 0x40000000
#define BUAMR_LAE 0x04000000
static int allocvec;
CFATTACH_DECL_NEW(uba_bi, sizeof(struct uba_softc),
uba_bi_match, uba_bi_attach, NULL, NULL);
struct dwbua_regs {
struct biiregs bn_biic;
int pad1[396];
int bn_csr;
int bn_vor;
int bn_fubar;
int bn_bifar;
int bn_mdiag[5];
int pad2[3];
int bn_dpcsr[6];
int pad3[38];
struct pte bn_map[UBAPAGES];
int pad4[UBAIOPAGES];
};
static int
uba_bi_match(device_t parent, cfdata_t cf, void *aux)
{
struct bi_attach_args *ba = aux;
if ((ba->ba_node->biic.bi_dtype != BIDT_DWBUA) &&
(ba->ba_node->biic.bi_dtype != BIDT_KLESI))
return 0;
if (cf->cf_loc[BICF_NODE] != BICF_NODE_DEFAULT &&
cf->cf_loc[BICF_NODE] != ba->ba_nodenr)
return 0;
return 1;
}
void
uba_bi_attach(device_t parent, device_t self, void *aux)
{
struct uba_softc *sc = device_private(self);
struct bi_attach_args *ba = aux;
volatile int timo;
if (ba->ba_node->biic.bi_dtype == BIDT_DWBUA)
printf(": DWBUA\n");
else
printf(": KLESI-B\n");
sc->uh_dev = self;
sc->uh_uba = (void *)ba->ba_node;
sc->uh_nbdp = NBDPBUA;
sc->uh_ubapurge = bua_purge;
sc->uh_ubainit = bua_init;
sc->uh_memsize = UBAPAGES;
sc->uh_mr = BUA(sc->uh_uba)->bn_map;
#ifdef notdef
scb->scb_nexvec[1][ba->ba_nodenr] = &sc->sc_ivec;
#endif
BUA(sc->uh_uba)->bn_biic.bi_csr |= BICSR_ARB_NONE;
BUA(sc->uh_uba)->bn_biic.bi_csr |= BICSR_STS | BICSR_INIT;
DELAY(1000);
timo = 1000;
while (BUA(sc->uh_uba)->bn_biic.bi_csr & BICSR_BROKE)
if (timo == 0) {
aprint_error_dev(self, "BROKE bit set\n");
return;
}
BUA(sc->uh_uba)->bn_biic.bi_intrdes = ba->ba_intcpu;
BUA(sc->uh_uba)->bn_biic.bi_csr =
(BUA(sc->uh_uba)->bn_biic.bi_csr&~BICSR_ARB_MASK) | BICSR_ARB_HIGH;
BUA(sc->uh_uba)->bn_vor = VAX_NBPG + (VAX_NBPG * allocvec++);
uba_attach(sc, BUA(sc->uh_uba)->bn_biic.bi_sadr + UBAPAGES * VAX_NBPG);
}
void
bua_init(struct uba_softc *sc)
{
BUA(sc->uh_uba)->bn_csr |= BUACSR_UPI;
DELAY(500000);
};
void
bua_purge(struct uba_softc *sc, int bdp)
{
BUA(sc->uh_uba)->bn_dpcsr[bdp] |= BUADPR_PURGE;
}