1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
|
/* $OpenBSD: kdb.c,v 1.4 2001/09/11 20:05:25 miod Exp $ */
/* $NetBSD: kdb.c,v 1.5 1997/01/11 11:34:39 ragge Exp $ */
/*
* 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:
* 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
*
* 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>
#include <sys/malloc.h>
#include <vm/vm.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>
#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 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 */
};
int kdbmatch __P((struct device *, void *, void *));
void kdbattach __P((struct device *, struct device *, void *));
void kdbreset __P((int));
void kdbintr __P((int));
void kdbctlrdone __P((struct device *, int));
int kdbprint __P((void *, const char *));
void kdbsaerror __P((struct device *, int));
int kdbgo __P((struct device *, struct buf *));
struct cfdriver kdb_cd = {
NULL, "kdb", DV_DULL
};
struct cfattach kdb_ca = {
sizeof(struct kdb_softc), kdbmatch, kdbattach
};
/*
* More driver definitions, for generic MSCP code.
*/
struct mscp_ctlr kdb_mscp_ctlr = {
kdbctlrdone,
kdbgo,
kdbsaerror,
};
int
kdbprint(aux, name)
void *aux;
const char *name;
{
if (name)
printf("%s: mscpbus", name);
return UNCONF;
}
/*
* Poke at a supposed KDB to see if it is there.
*/
int
kdbmatch(parent, match, aux)
struct device *parent;
void *match, *aux;
{
struct cfdata *cf = match;
struct bi_attach_args *ba = aux;
if (ba->ba_node->biic.bi_dtype != BIDT_KDB50)
return 0;
if (cf->cf_loc[0] != -1 && cf->cf_loc[0] != ba->ba_nodenr)
return 0;
return 1;
}
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;
extern struct ivec_dsp idsptch;
volatile int i = 10000;
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;
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
kdbgo(usc, bp)
struct device *usc;
struct buf *bp;
{
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);
}
}
/*
* 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)) {
info = (unsigned)malloc(2 * NBPG, M_DEVBUF, M_WAITOK);
k = (info + PGOFSET) & ~PGOFSET;
bcopy(pte, (void *)k, NBPG);
i = kvtophys(k);
}
mp->mscp_seq.seq_mapbase = i;
} else
mp->mscp_seq.seq_mapbase = (unsigned)pte;
mscp_dgo(mi, KDB_MAP | o, info, bp);
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;
printf("%s: controller error, sa=0x%x\n", sc->sc_dev.dv_xname, code);
/* 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];
struct uba_softc *uh;
struct mscp_pack *ud;
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];
printf(" kdb%d", ctlr);
/* 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))
printf(" (hung)");
}
#endif
void
kdbctlrdone(usc, info)
struct device *usc;
int info;
{
if (info)
free((void *)info, NBPG * 2);
}
|