1999-01-02 00:43:17 +03:00
|
|
|
/* $NetBSD: kdb.c,v 1.14 1999/01/01 21:43:17 ragge Exp $ */
|
1996-07-19 18:26:52 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1996 Ludd, University of Lule}, Sweden.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
1998-03-02 20:00:00 +03:00
|
|
|
* This product includes software developed at Ludd, University of
|
|
|
|
* Lule}, Sweden and its contributors.
|
1996-07-19 18:26:52 +04:00
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* KDB50 disk device driver
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* TODO
|
|
|
|
* Implement node reset routine.
|
|
|
|
* Nices hardware error handling.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/proc.h>
|
1998-01-19 01:09:13 +03:00
|
|
|
#include <sys/user.h>
|
1996-07-19 18:26:52 +04:00
|
|
|
#include <sys/malloc.h>
|
1998-03-02 20:00:00 +03:00
|
|
|
#include <sys/systm.h>
|
1996-07-19 18:26:52 +04:00
|
|
|
|
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/vm_kern.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/bi/kdbreg.h>
|
|
|
|
|
|
|
|
#include <vax/mscp/mscp.h>
|
|
|
|
#include <vax/mscp/mscpvar.h>
|
|
|
|
#include <vax/mscp/mscpreg.h>
|
|
|
|
|
1997-07-17 06:12:50 +04:00
|
|
|
#include "locators.h"
|
|
|
|
|
1998-03-02 20:00:00 +03:00
|
|
|
#define b_forw b_hash.le_next
|
1996-07-19 18:26:52 +04:00
|
|
|
/*
|
|
|
|
* Software status, per controller.
|
|
|
|
*/
|
|
|
|
struct kdb_softc {
|
|
|
|
struct device sc_dev; /* Autoconfig info */
|
|
|
|
struct ivec_dsp sc_ivec; /* Interrupt vector handler */
|
|
|
|
struct mscp_pack sc_kdb; /* Struct for kdb communication */
|
|
|
|
struct mscp_softc *sc_softc; /* MSCP info (per mscpvar.h) */
|
|
|
|
struct kdb_regs *sc_kr; /* KDB controller registers */
|
|
|
|
struct mscp *sc_mscp; /* Keep pointer to active mscp */
|
|
|
|
};
|
|
|
|
|
1998-01-24 17:16:11 +03:00
|
|
|
int kdbmatch __P((struct device *, struct cfdata *, void *));
|
1996-07-19 18:26:52 +04:00
|
|
|
void kdbattach __P((struct device *, struct device *, void *));
|
|
|
|
void kdbreset __P((int));
|
|
|
|
void kdbintr __P((int));
|
|
|
|
void kdbctlrdone __P((struct device *, int));
|
1996-08-28 01:53:46 +04:00
|
|
|
int kdbprint __P((void *, const char *));
|
1996-07-19 18:26:52 +04:00
|
|
|
void kdbsaerror __P((struct device *, int));
|
1997-01-11 14:34:39 +03:00
|
|
|
int kdbgo __P((struct device *, struct buf *));
|
1996-07-19 18:26:52 +04:00
|
|
|
|
|
|
|
struct cfattach kdb_ca = {
|
|
|
|
sizeof(struct kdb_softc), kdbmatch, kdbattach
|
|
|
|
};
|
|
|
|
|
1998-01-12 23:52:29 +03:00
|
|
|
extern struct cfdriver kdb_cd;
|
|
|
|
|
1996-07-19 18:26:52 +04:00
|
|
|
/*
|
|
|
|
* More driver definitions, for generic MSCP code.
|
|
|
|
*/
|
|
|
|
struct mscp_ctlr kdb_mscp_ctlr = {
|
|
|
|
kdbctlrdone,
|
|
|
|
kdbgo,
|
|
|
|
kdbsaerror,
|
|
|
|
};
|
|
|
|
|
|
|
|
int
|
|
|
|
kdbprint(aux, name)
|
|
|
|
void *aux;
|
1996-08-28 01:53:46 +04:00
|
|
|
const char *name;
|
1996-07-19 18:26:52 +04:00
|
|
|
{
|
|
|
|
if (name)
|
1996-10-13 07:29:05 +04:00
|
|
|
printf("%s: mscpbus", name);
|
1996-07-19 18:26:52 +04:00
|
|
|
return UNCONF;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Poke at a supposed KDB to see if it is there.
|
|
|
|
*/
|
|
|
|
int
|
1998-01-24 17:16:11 +03:00
|
|
|
kdbmatch(parent, cf, aux)
|
1996-07-19 18:26:52 +04:00
|
|
|
struct device *parent;
|
1998-03-02 20:00:00 +03:00
|
|
|
struct cfdata *cf;
|
1998-01-24 17:16:11 +03:00
|
|
|
void *aux;
|
1996-07-19 18:26:52 +04:00
|
|
|
{
|
|
|
|
struct bi_attach_args *ba = aux;
|
|
|
|
|
1998-03-02 20:00:00 +03:00
|
|
|
if (ba->ba_node->biic.bi_dtype != BIDT_KDB50)
|
|
|
|
return 0;
|
1996-07-19 18:26:52 +04:00
|
|
|
|
1998-03-02 20:00:00 +03:00
|
|
|
if (cf->cf_loc[BICF_NODE] != BICF_NODE_DEFAULT &&
|
1997-07-17 06:12:50 +04:00
|
|
|
cf->cf_loc[BICF_NODE] != ba->ba_nodenr)
|
1998-03-02 20:00:00 +03:00
|
|
|
return 0;
|
1996-07-19 18:26:52 +04:00
|
|
|
|
1998-03-02 20:00:00 +03:00
|
|
|
return 1;
|
1996-07-19 18:26:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
kdbattach(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
struct kdb_softc *sc = (void *)self;
|
|
|
|
struct bi_attach_args *ba = aux;
|
|
|
|
struct mscp_attach_args ma;
|
1998-03-02 20:00:00 +03:00
|
|
|
extern struct ivec_dsp idsptch;
|
1996-07-19 18:26:52 +04:00
|
|
|
volatile int i = 10000;
|
|
|
|
|
1996-10-13 07:29:05 +04:00
|
|
|
printf("\n");
|
1996-07-19 18:26:52 +04:00
|
|
|
bcopy(&idsptch, &sc->sc_ivec, sizeof(struct ivec_dsp));
|
|
|
|
scb->scb_nexvec[1][ba->ba_nodenr] = &sc->sc_ivec;
|
|
|
|
sc->sc_ivec.hoppaddr = kdbintr;
|
|
|
|
sc->sc_ivec.pushlarg = self->dv_unit;
|
|
|
|
sc->sc_kr = (void *)ba->ba_node;
|
|
|
|
|
|
|
|
bzero(&sc->sc_kdb, sizeof (struct mscp_pack));
|
|
|
|
|
|
|
|
ma.ma_mc = &kdb_mscp_ctlr;
|
|
|
|
ma.ma_type = MSCPBUS_DISK|MSCPBUS_KDB;
|
|
|
|
ma.ma_uuda = (struct mscp_pack *)kvtophys(&sc->sc_kdb);
|
|
|
|
ma.ma_uda = &sc->sc_kdb;
|
|
|
|
ma.ma_ip = &sc->sc_kr->kdb_ip;
|
|
|
|
ma.ma_sa = &sc->sc_kr->kdb_sa;
|
|
|
|
ma.ma_sw = &sc->sc_kr->kdb_sw;
|
|
|
|
ma.ma_softc = &sc->sc_softc;
|
|
|
|
ma.ma_ivec = (int)&scb->scb_nexvec[1][ba->ba_nodenr] - (int)scb;
|
|
|
|
ma.ma_ctlrnr = ba->ba_nodenr;
|
|
|
|
sc->sc_kr->kdb_bi.bi_csr |= BICSR_NRST;
|
|
|
|
while (i--) /* Need delay??? */
|
|
|
|
;
|
|
|
|
sc->sc_kr->kdb_bi.bi_intrdes = ba->ba_intcpu;
|
|
|
|
sc->sc_kr->kdb_bi.bi_bcicsr |= BCI_STOPEN | BCI_IDENTEN | BCI_UINTEN |
|
|
|
|
BCI_INTEN;
|
|
|
|
sc->sc_kr->kdb_bi.bi_uintrcsr = ma.ma_ivec;
|
|
|
|
config_found(&sc->sc_dev, &ma, kdbprint);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1997-01-11 14:34:39 +03:00
|
|
|
kdbgo(usc, bp)
|
1996-07-19 18:26:52 +04:00
|
|
|
struct device *usc;
|
1997-01-11 14:34:39 +03:00
|
|
|
struct buf *bp;
|
1996-07-19 18:26:52 +04:00
|
|
|
{
|
|
|
|
struct kdb_softc *sc = (void *)usc;
|
|
|
|
struct mscp_softc *mi = sc->sc_softc;
|
1997-01-11 14:34:39 +03:00
|
|
|
struct mscp *mp = (void *)bp->b_actb;
|
1998-03-02 20:00:00 +03:00
|
|
|
struct pcb *pcb;
|
|
|
|
pt_entry_t *pte;
|
|
|
|
int npf, o, i;
|
1996-07-19 18:26:52 +04:00
|
|
|
unsigned info = 0;
|
1998-03-02 20:00:00 +03:00
|
|
|
caddr_t addr;
|
1996-07-19 18:26:52 +04:00
|
|
|
|
1999-01-02 00:43:17 +03:00
|
|
|
o = (int)bp->b_un.b_addr & VAX_PGOFSET;
|
1998-11-29 17:48:51 +03:00
|
|
|
npf = vax_btoc(bp->b_bcount + o) + 1;
|
1996-07-19 18:26:52 +04:00
|
|
|
addr = bp->b_un.b_addr;
|
|
|
|
|
1998-03-02 20:00:00 +03:00
|
|
|
/*
|
|
|
|
* Get a pointer to the pte pointing out the first virtual address.
|
|
|
|
* Use different ways in kernel and user space.
|
|
|
|
*/
|
|
|
|
if ((bp->b_flags & B_PHYS) == 0) {
|
|
|
|
pte = kvtopte(addr);
|
|
|
|
} else {
|
|
|
|
pcb = &bp->b_proc->p_addr->u_pcb;
|
|
|
|
pte = uvtopte(addr, pcb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When we are doing DMA to user space, be sure that all pages
|
|
|
|
* we want to transfer to is mapped. WHY DO WE NEED THIS???
|
|
|
|
* SHOULDN'T THEY ALWAYS BE MAPPED WHEN DOING THIS???
|
|
|
|
*/
|
|
|
|
for (i = 0; i < (npf - 1); i++) {
|
|
|
|
if ((pte + i)->pg_pfn == 0) {
|
|
|
|
int rv;
|
|
|
|
#if defined(UVM)
|
|
|
|
rv = uvm_fault(&bp->b_proc->p_vmspace->vm_map,
|
1999-01-02 00:43:17 +03:00
|
|
|
(unsigned)addr + i * VAX_NBPG, 0,
|
1998-03-02 20:00:00 +03:00
|
|
|
VM_PROT_READ|VM_PROT_WRITE);
|
|
|
|
#else
|
|
|
|
rv = vm_fault(&bp->b_proc->p_vmspace->vm_map,
|
1999-01-02 00:43:17 +03:00
|
|
|
(unsigned)addr + i * VAX_NBPG,
|
1998-03-02 20:00:00 +03:00
|
|
|
VM_PROT_READ|VM_PROT_WRITE, FALSE);
|
|
|
|
#endif
|
|
|
|
if (rv)
|
|
|
|
panic("KDB DMA to nonexistent page, %d", rv);
|
|
|
|
}
|
|
|
|
}
|
1996-07-19 18:26:52 +04:00
|
|
|
/*
|
|
|
|
* pte's for userspace isn't necessary positioned
|
|
|
|
* in consecutive physical pages. We check if they
|
|
|
|
* are, otherwise we need to copy the pte's to a
|
|
|
|
* physically contigouos page area.
|
|
|
|
* XXX some copying here may be unneccessary. Subject to fix.
|
|
|
|
*/
|
|
|
|
if (bp->b_flags & B_PHYS) {
|
|
|
|
int i = kvtophys(pte);
|
|
|
|
unsigned k;
|
|
|
|
|
|
|
|
if (trunc_page(i) != trunc_page(kvtophys(pte) + npf * 4)) {
|
1999-01-02 00:43:17 +03:00
|
|
|
info = (unsigned)malloc(2 * VAX_NBPG, M_DEVBUF, M_WAITOK);
|
|
|
|
k = (info + VAX_PGOFSET) & ~VAX_PGOFSET;
|
|
|
|
bcopy(pte, (void *)k, VAX_NBPG);
|
1996-07-19 18:26:52 +04:00
|
|
|
i = kvtophys(k);
|
|
|
|
}
|
|
|
|
mp->mscp_seq.seq_mapbase = i;
|
|
|
|
} else
|
|
|
|
mp->mscp_seq.seq_mapbase = (unsigned)pte;
|
1997-01-11 14:34:39 +03:00
|
|
|
mscp_dgo(mi, KDB_MAP | o, info, bp);
|
1996-07-19 18:26:52 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
kdbsaerror(usc, doreset)
|
|
|
|
struct device *usc;
|
|
|
|
int doreset;
|
|
|
|
{
|
|
|
|
struct kdb_softc *sc = (void *)usc;
|
|
|
|
register int code = sc->sc_kr->kdb_sa;
|
|
|
|
|
|
|
|
if ((code & MP_ERR) == 0)
|
|
|
|
return;
|
1996-10-13 07:29:05 +04:00
|
|
|
printf("%s: controller error, sa=0x%x\n", sc->sc_dev.dv_xname, code);
|
1996-07-19 18:26:52 +04:00
|
|
|
/* What to do now??? */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Interrupt routine. Depending on the state of the controller,
|
|
|
|
* continue initialisation, or acknowledge command and response
|
|
|
|
* interrupts, and process responses.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
kdbintr(ctlr)
|
|
|
|
int ctlr;
|
|
|
|
{
|
|
|
|
struct kdb_softc *sc = kdb_cd.cd_devs[ctlr];
|
|
|
|
|
|
|
|
if (sc->sc_kr->kdb_sa & MP_ERR) { /* ctlr fatal error */
|
|
|
|
kdbsaerror(&sc->sc_dev, 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mscp_intr(sc->sc_softc);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef notyet
|
|
|
|
/*
|
|
|
|
* The KDB50 has been reset. Reinitialise the controller
|
|
|
|
* and requeue outstanding I/O.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
kdbreset(ctlr)
|
|
|
|
int ctlr;
|
|
|
|
{
|
|
|
|
register struct kdb_softc *sc;
|
|
|
|
|
|
|
|
sc = kdb_cd.cd_devs[ctlr];
|
1996-10-13 07:29:05 +04:00
|
|
|
printf(" kdb%d", ctlr);
|
1996-07-19 18:26:52 +04:00
|
|
|
|
|
|
|
|
|
|
|
/* reset queues and requeue pending transfers */
|
|
|
|
mscp_requeue(sc->sc_softc);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If it fails to initialise we will notice later and
|
|
|
|
* try again (and again...). Do not call kdbstart()
|
|
|
|
* here; it will be done after the controller finishes
|
|
|
|
* initialisation.
|
|
|
|
*/
|
|
|
|
if (kdbinit(sc))
|
1996-10-13 07:29:05 +04:00
|
|
|
printf(" (hung)");
|
1996-07-19 18:26:52 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void
|
|
|
|
kdbctlrdone(usc, info)
|
|
|
|
struct device *usc;
|
|
|
|
int info;
|
|
|
|
{
|
|
|
|
if (info)
|
1999-01-02 00:43:17 +03:00
|
|
|
free((void *)info, VAX_NBPG * 2);
|
1996-07-19 18:26:52 +04:00
|
|
|
}
|