summaryrefslogtreecommitdiff
path: root/sys/arch/vax/bi/kdb.c
diff options
context:
space:
mode:
authorHugh Graham <hugh@cvs.openbsd.org>2002-06-11 09:36:25 +0000
committerHugh Graham <hugh@cvs.openbsd.org>2002-06-11 09:36:25 +0000
commit10ca5e5818bb80e596db244327a2663b6703bb18 (patch)
treec7ac330b34d73ea4e0c78d17a9eed0a3b6df63aa /sys/arch/vax/bi/kdb.c
parent180b34af9885b092bee0f67c5b2ac8577d972cfe (diff)
New boot code, mostly from ragge's work in NetBSD.
Some header syncing and a couple network drivers came along for the ride. Assembly files have been renamed from .s to .S to facilitate diffs. Kernel is backwards compat - with manual interaction. OpenBSD features have been preserved.
Diffstat (limited to 'sys/arch/vax/bi/kdb.c')
-rw-r--r--sys/arch/vax/bi/kdb.c298
1 files changed, 168 insertions, 130 deletions
diff --git a/sys/arch/vax/bi/kdb.c b/sys/arch/vax/bi/kdb.c
index 0362e0958ca..f03de356ff1 100644
--- a/sys/arch/vax/bi/kdb.c
+++ b/sys/arch/vax/bi/kdb.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: kdb.c,v 1.6 2002/03/14 01:26:47 millert Exp $ */
-/* $NetBSD: kdb.c,v 1.5 1997/01/11 11:34:39 ragge Exp $ */
+/* $OpenBSD: kdb.c,v 1.7 2002/06/11 09:36:23 hugh Exp $ */
+/* $NetBSD: kdb.c,v 1.26 2001/11/13 12:51:34 lukem Exp $ */
/*
* Copyright (c) 1996 Ludd, University of Lule}, Sweden.
* All rights reserved.
@@ -14,8 +14,8 @@
* 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:
- * This product includes software developed at Ludd, University of
- * Lule}, Sweden and its contributors.
+ * This product includes software developed at Ludd, University of
+ * Lule}, Sweden and its contributors.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission
*
@@ -40,54 +40,64 @@
* Nices hardware error handling.
*/
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: kdb.c,v 1.26 2001/11/13 12:51:34 lukem Exp $");
+
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/buf.h>
#include <sys/device.h>
#include <sys/proc.h>
+#include <sys/user.h>
#include <sys/malloc.h>
+#include <sys/systm.h>
+#include <sys/sched.h>
#include <uvm/uvm_extern.h>
-#include <machine/sid.h>
+#ifdef __vax__
#include <machine/pte.h>
#include <machine/pcb.h>
-#include <machine/trap.h>
-#include <machine/scb.h>
+#endif
+#include <machine/bus.h>
+
+#include <dev/bi/bireg.h>
+#include <dev/bi/bivar.h>
+#include <dev/bi/kdbreg.h>
+
+#include <dev/mscp/mscp.h>
+#include <dev/mscp/mscpreg.h>
+#include <dev/mscp/mscpvar.h>
-#include <vax/bi/bireg.h>
-#include <vax/bi/bivar.h>
-#include <vax/bi/kdbreg.h>
+#include "locators.h"
-#include <vax/mscp/mscp.h>
-#include <vax/mscp/mscpvar.h>
-#include <vax/mscp/mscpreg.h>
+#define KDB_WL(adr, val) bus_space_write_4(sc->sc_iot, sc->sc_ioh, adr, val)
+#define KDB_RL(adr) bus_space_read_4(sc->sc_iot, sc->sc_ioh, adr)
+#define KDB_RS(adr) bus_space_read_2(sc->sc_iot, sc->sc_ioh, adr)
-#define b_forw b_hash.le_next
+#define b_forw b_hash.le_next
/*
* 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 evcnt sc_intrcnt; /* Interrupt counting */
+ caddr_t 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 */
+ bus_dma_tag_t sc_dmat;
+ bus_dmamap_t sc_cmap; /* Control structures */
+ bus_space_tag_t sc_iot;
+ bus_space_handle_t sc_ioh;
};
-int kdbmatch(struct device *, void *, void *);
-void kdbattach(struct device *, struct device *, void *);
-void kdbreset(int);
-void kdbintr(int);
-void kdbctlrdone(struct device *, int);
-int kdbprint(void *, const char *);
-void kdbsaerror(struct device *, int);
-int kdbgo(struct device *, struct buf *);
-
-struct cfdriver kdb_cd = {
- NULL, "kdb", DV_DULL
-};
+int kdbmatch __P((struct device *, struct cfdata *, void *));
+void kdbattach __P((struct device *, struct device *, void *));
+void kdbreset __P((int));
+void kdbintr __P((void *));
+void kdbctlrdone __P((struct device *));
+int kdbprint __P((void *, const char *));
+void kdbsaerror __P((struct device *, int));
+void kdbgo __P((struct device *, struct mscp_xi *));
struct cfattach kdb_ca = {
sizeof(struct kdb_softc), kdbmatch, kdbattach
@@ -116,20 +126,21 @@ kdbprint(aux, name)
* Poke at a supposed KDB to see if it is there.
*/
int
-kdbmatch(parent, match, aux)
+kdbmatch(parent, cf, aux)
struct device *parent;
- void *match, *aux;
+ struct cfdata *cf;
+ void *aux;
{
- struct cfdata *cf = match;
struct bi_attach_args *ba = aux;
- if (ba->ba_node->biic.bi_dtype != BIDT_KDB50)
- return 0;
+ if (bus_space_read_2(ba->ba_iot, ba->ba_ioh, BIREG_DTYPE) != BIDT_KDB50)
+ return 0;
- if (cf->cf_loc[0] != -1 && cf->cf_loc[0] != ba->ba_nodenr)
- return 0;
+ if (cf->cf_loc[BICF_NODE] != BICF_NODE_DEFAULT &&
+ cf->cf_loc[BICF_NODE] != ba->ba_nodenr)
+ return 0;
- return 1;
+ return 1;
}
void
@@ -140,104 +151,135 @@ kdbattach(parent, self, aux)
struct kdb_softc *sc = (void *)self;
struct bi_attach_args *ba = aux;
struct mscp_attach_args ma;
- extern struct ivec_dsp idsptch;
volatile int i = 10000;
+ int error, rseg;
+ bus_dma_segment_t seg;
printf("\n");
- 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;
+ bi_intr_establish(ba->ba_icookie, ba->ba_ivec,
+ kdbintr, sc, &sc->sc_intrcnt);
+ evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
+ sc->sc_dev.dv_xname, "intr");
- bzero(&sc->sc_kdb, sizeof (struct mscp_pack));
+ sc->sc_iot = ba->ba_iot;
+ sc->sc_ioh = ba->ba_ioh;
+ sc->sc_dmat = ba->ba_dmat;
+
+ /*
+ * Map the communication area and command and
+ * response packets into Unibus space.
+ */
+ if ((error = bus_dmamem_alloc(sc->sc_dmat, sizeof(struct mscp_pack),
+ NBPG, 0, &seg, 1, &rseg, BUS_DMA_NOWAIT)) != 0) {
+ printf("Alloc ctrl area %d\n", error);
+ return;
+ }
+ if ((error = bus_dmamem_map(sc->sc_dmat, &seg, rseg,
+ sizeof(struct mscp_pack), &sc->sc_kdb,
+ BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) != 0) {
+ printf("Map ctrl area %d\n", error);
+err: bus_dmamem_free(sc->sc_dmat, &seg, rseg);
+ return;
+ }
+ if ((error = bus_dmamap_create(sc->sc_dmat, sizeof(struct mscp_pack),
+ 1, sizeof(struct mscp_pack), 0, BUS_DMA_NOWAIT, &sc->sc_cmap))) {
+ printf("Create DMA map %d\n", error);
+err2: bus_dmamem_unmap(sc->sc_dmat, sc->sc_kdb,
+ sizeof(struct mscp_pack));
+ goto err;
+ }
+ if ((error = bus_dmamap_load(sc->sc_dmat, sc->sc_cmap,
+ sc->sc_kdb, sizeof(struct mscp_pack), 0, BUS_DMA_NOWAIT))) {
+ printf("Load ctrl map %d\n", error);
+ bus_dmamap_destroy(sc->sc_dmat, sc->sc_cmap);
+ goto err2;
+ }
+ memset(sc->sc_kdb, 0, 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_uda = (struct mscp_pack *)sc->sc_kdb;
ma.ma_softc = &sc->sc_softc;
- ma.ma_ivec = (int)&scb->scb_nexvec[1][ba->ba_nodenr] - (int)scb;
+ ma.ma_iot = sc->sc_iot;
+ ma.ma_iph = sc->sc_ioh + KDB_IP;
+ ma.ma_sah = sc->sc_ioh + KDB_SA;
+ ma.ma_swh = sc->sc_ioh + KDB_SW;
+ ma.ma_dmat = sc->sc_dmat;
+ ma.ma_dmam = sc->sc_cmap;
+ ma.ma_ivec = ba->ba_ivec;
ma.ma_ctlrnr = ba->ba_nodenr;
- sc->sc_kr->kdb_bi.bi_csr |= BICSR_NRST;
+ ma.ma_adapnr = ba->ba_busnr;
+
+ KDB_WL(BIREG_VAXBICSR, KDB_RL(BIREG_VAXBICSR) | 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;
+ KDB_WL(BIREG_INTRDES, ba->ba_intcpu); /* Interrupt on CPU # */
+ KDB_WL(BIREG_BCICSR, KDB_RL(BIREG_BCICSR) |
+ BCI_STOPEN | BCI_IDENTEN | BCI_UINTEN | BCI_INTEN);
+ KDB_WL(BIREG_UINTRCSR, ba->ba_ivec);
config_found(&sc->sc_dev, &ma, kdbprint);
}
-int
-kdbgo(usc, bp)
+void
+kdbgo(usc, mxi)
struct device *usc;
- struct buf *bp;
+ struct mscp_xi *mxi;
{
struct kdb_softc *sc = (void *)usc;
- struct mscp_softc *mi = sc->sc_softc;
- struct mscp *mp = (void *)bp->b_actb;
- struct pcb *pcb;
- pt_entry_t *pte;
- int pfnum, npf, o, i;
- unsigned info = 0;
- caddr_t addr;
-
- o = (int)bp->b_un.b_addr & PGOFSET;
- npf = btoc(bp->b_bcount + o) + 1;
- addr = bp->b_un.b_addr;
-
- /*
- * 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_vmspace->vm_map.pmap->pm_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;
- rv = vm_fault(&bp->b_proc->p_vmspace->vm_map,
- (unsigned)addr + i * NBPG,
- VM_PROT_READ|VM_PROT_WRITE, FALSE);
- if (rv)
- panic("KDB DMA to nonexistent page, %d", rv);
- }
- }
+ struct buf *bp = mxi->mxi_bp;
+ struct mscp *mp = mxi->mxi_mp;
+ u_int32_t addr = (u_int32_t)bp->b_data;
+ u_int32_t mapaddr;
+ int err;
+
+ /*
+ * The KDB50 wants to read VAX Page tables directly, therefore
+ * the result from bus_dmamap_load() is uninteresting. (But it
+ * should never fail!).
+ *
+ * On VAX, point to the corresponding page tables. (user/sys)
+ * On other systems, do something else...
+ */
+ err = bus_dmamap_load(sc->sc_dmat, mxi->mxi_dmam, bp->b_data,
+ bp->b_bcount, (bp->b_flags & B_PHYS ? bp->b_proc : 0),
+ BUS_DMA_NOWAIT);
+
+ if (err) /* Shouldn't happen */
+ panic("kdbgo: bus_dmamap_load: error %d", err);
+
+#ifdef __vax__
/*
- * 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.
+ * 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) {
- int i = kvtophys(pte);
- unsigned k;
-
- if (trunc_page(i) != trunc_page(kvtophys(pte) + npf * 4)) {
- info = (unsigned)malloc(2 * NBPG, M_DEVBUF, M_WAITOK);
- k = (info + PGOFSET) & ~PGOFSET;
- bcopy(pte, (void *)k, NBPG);
- i = kvtophys(k);
+ if ((bp->b_flags & B_PHYS) == 0) {
+ mapaddr = ((u_int32_t)kvtopte(addr)) & ~KERNBASE;
+ } else {
+ struct pcb *pcb;
+ u_int32_t eaddr;
+
+ /*
+ * We check if the PTE's needed crosses a page boundary.
+ * If they do; only transfer the amount of data that is
+ * mapped by the first PTE page and led the system handle
+ * the rest of the data.
+ */
+ pcb = &bp->b_proc->p_addr->u_pcb;
+ mapaddr = (u_int32_t)uvtopte(addr, pcb);
+ eaddr = (u_int32_t)uvtopte(addr + (bp->b_bcount - 1), pcb);
+ if (trunc_page(mapaddr) != trunc_page(eaddr)) {
+ mp->mscp_seq.seq_bytecount =
+ (((round_page(mapaddr) - mapaddr)/4) * 512);
}
- mp->mscp_seq.seq_mapbase = i;
- } else
- mp->mscp_seq.seq_mapbase = (unsigned)pte;
- mscp_dgo(mi, KDB_MAP | o, info, bp);
- return 1;
+ mapaddr = kvtophys(mapaddr);
+ }
+#else
+#error Must write code to handle KDB50 on non-vax.
+#endif
+
+ mp->mscp_seq.seq_mapbase = mapaddr;
+ mxi->mxi_dmam->dm_segs[0].ds_addr = (addr & 511) | KDB_MAP;
+ mscp_dgo(sc->sc_softc, mxi);
}
void
@@ -246,11 +288,11 @@ kdbsaerror(usc, doreset)
int doreset;
{
struct kdb_softc *sc = (void *)usc;
- register int code = sc->sc_kr->kdb_sa;
- if ((code & MP_ERR) == 0)
+ if ((KDB_RS(KDB_SA) & MP_ERR) == 0)
return;
- printf("%s: controller error, sa=0x%x\n", sc->sc_dev.dv_xname, code);
+ printf("%s: controller error, sa=0x%x\n", sc->sc_dev.dv_xname,
+ KDB_RS(KDB_SA));
/* What to do now??? */
}
@@ -260,18 +302,17 @@ kdbsaerror(usc, doreset)
* interrupts, and process responses.
*/
void
-kdbintr(ctlr)
- int ctlr;
+kdbintr(void *arg)
{
- struct kdb_softc *sc = kdb_cd.cd_devs[ctlr];
- struct uba_softc *uh;
- struct mscp_pack *ud;
+ struct kdb_softc *sc = arg;
- if (sc->sc_kr->kdb_sa & MP_ERR) { /* ctlr fatal error */
+ if (KDB_RS(KDB_SA) & MP_ERR) { /* ctlr fatal error */
kdbsaerror(&sc->sc_dev, 1);
return;
}
+ KERNEL_LOCK(LK_CANRECURSE|LK_EXCLUSIVE);
mscp_intr(sc->sc_softc);
+ KERNEL_UNLOCK();
}
#ifdef notyet
@@ -283,7 +324,7 @@ void
kdbreset(ctlr)
int ctlr;
{
- register struct kdb_softc *sc;
+ struct kdb_softc *sc;
sc = kdb_cd.cd_devs[ctlr];
printf(" kdb%d", ctlr);
@@ -304,10 +345,7 @@ kdbreset(ctlr)
#endif
void
-kdbctlrdone(usc, info)
+kdbctlrdone(usc)
struct device *usc;
- int info;
{
- if (info)
- free((void *)info, NBPG * 2);
}