vsbus.c revision 1.14 1 /* $NetBSD: vsbus.c,v 1.14 1999/02/02 18:37:21 ragge Exp $ */
2 /*
3 * Copyright (c) 1996 Ludd, University of Lule}, Sweden.
4 * All rights reserved.
5 *
6 * This code is derived from software contributed to Ludd by Bertram Barth.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed at Ludd, University of
19 * Lule}, Sweden and its contributors.
20 * 4. The name of the author may not be used to endorse or promote products
21 * derived from this software without specific prior written permission
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/buf.h>
38 #include <sys/conf.h>
39 #include <sys/file.h>
40 #include <sys/ioctl.h>
41 #include <sys/proc.h>
42 #include <sys/user.h>
43 #include <sys/map.h>
44 #include <sys/device.h>
45 #include <sys/dkstat.h>
46 #include <sys/disklabel.h>
47 #include <sys/syslog.h>
48 #include <sys/stat.h>
49
50 #include <machine/pte.h>
51 #include <machine/sid.h>
52 #include <machine/scb.h>
53 #include <machine/cpu.h>
54 #include <machine/trap.h>
55 #include <machine/nexus.h>
56
57 #include <machine/uvax.h>
58 #include <machine/ka410.h>
59 #include <machine/ka420.h>
60 #include <machine/ka43.h>
61
62 #include <machine/vsbus.h>
63
64 #include "ioconf.h"
65
66 int vsbus_match __P((struct device *, struct cfdata *, void *));
67 void vsbus_attach __P((struct device *, struct device *, void *));
68 int vsbus_print __P((void *, const char *));
69
70 void ka410_attach __P((struct device *, struct device *, void *));
71 void ka43_attach __P((struct device *, struct device *, void *));
72
73 static struct vs_cpu *vs_cpu;
74
75 #define VSBUS_MAXINTR 8
76
77 struct vsbus_softc {
78 struct device sc_dev;
79 struct ivec_dsp sc_dsp[VSBUS_MAXINTR];
80 };
81
82 struct cfattach vsbus_ca = {
83 sizeof(struct vsbus_softc), vsbus_match, vsbus_attach
84 };
85
86 void vsbus_intr_setup __P((struct vsbus_softc *));
87
88 #define VSBUS_MAXDEVS 8
89
90 int
91 vsbus_print(aux, name)
92 void *aux;
93 const char *name;
94 {
95 struct vsbus_attach_args *va = aux;
96
97 if (name) {
98 printf ("device %d at %s", va->va_type, name);
99 return (UNSUPP);
100 }
101 return (UNCONF);
102 }
103
104 int
105 vsbus_match(parent, cf, aux)
106 struct device *parent;
107 struct cfdata *cf;
108 void *aux;
109 {
110 struct bp_conf *bp = aux;
111
112 if (strcmp(bp->type, "vsbus"))
113 return 0;
114 /*
115 * on machines which can have it, the vsbus is always there
116 */
117 if ((vax_bustype & VAX_VSBUS) == 0)
118 return (0);
119
120 return (1);
121 }
122
123 void
124 vsbus_attach(parent, self, aux)
125 struct device *parent, *self;
126 void *aux;
127 {
128 struct vsbus_softc *sc = (void *)self;
129 struct vsbus_attach_args va;
130
131 printf("\n");
132
133 vs_cpu = (void *)vax_map_physmem(VS_REGS, 1);
134 /*
135 * first setup interrupt-table, so that devices can register
136 * their interrupt-routines...
137 */
138 vsbus_intr_setup(sc);
139
140 /*
141 * now check for all possible devices on this "bus"
142 */
143 /* Always have network */
144 va.va_type = inr_ni;
145 config_found(self, &va, vsbus_print);
146
147 /* Always have serial line */
148 va.va_type = inr_sr;
149 config_found(self, &va, vsbus_print);
150
151 /* If sm_addr is set, a monochrome graphics adapter is found */
152 /* XXX - fixa! */
153 va.va_type = inr_vf;
154 config_found(self, &va, vsbus_print);
155
156 /* XXX - Avoid searching for SCSI on 4000/60 */
157 if (vax_boardtype == VAX_BTYP_46)
158 return;
159
160 /*
161 * Check for mass storage devices. This is tricky :-/
162 * VS2K always has both MFM and SCSI.
163 * VS3100 has either MFM/SCSI, SCSI/SCSI or neither of them.
164 * The device registers are at different places for them all.
165 */
166 if (vax_boardtype == VAX_BTYP_410) {
167 #ifdef notyet
168 va.va_type = inr_dc;
169 config_found(self, &va, vsbus_print);
170 #endif
171 va.va_type = 0x200C0080;
172 config_found(self, &va, vsbus_print);
173 return;
174 }
175
176 if ((vax_confdata & KA420_CFG_STCMSK) == KA420_CFG_NONE)
177 return; /* No ctlrs */
178
179 /* Ok, we have at least one scsi ctlr */
180 va.va_type = 0x200C0080;
181 config_found(self, &va, vsbus_print);
182
183 #ifdef notyet
184 /* The last one is MFM or SCSI */
185 if ((vax_confdata & KA420_CFG_STCMSK) == KA420_CFG_RB) {
186 va.va_type = inr_dc;
187 config_found(self, &va, vsbus_print);
188 } else {
189 va.va_type = 0x200C0180;
190 config_found(self, &va, vsbus_print);
191 }
192 #endif
193 }
194
195 static void stray __P((int));
196
197 static void
198 stray(arg)
199 int arg;
200 {
201 printf("stray interrupt nr %d.\n", arg);
202 }
203
204 static int inrs[] = {IVEC_DC, IVEC_SC, IVEC_VS, IVEC_VF,
205 IVEC_NS, IVEC_NP, IVEC_ST, IVEC_SR};
206
207 void
208 vsbus_intr_setup(sc)
209 struct vsbus_softc *sc;
210 {
211 extern struct ivec_dsp idsptch; /* subr.s */
212 void **scbP = (void*)scb;
213 int i;
214
215 vs_cpu->vc_intmsk = 0; /* disable all interrupts */
216 vs_cpu->vc_intclr = 0xFF; /* clear all old interrupts */
217
218 for (i = 0; i < VSBUS_MAXINTR; i++) {
219 bcopy(&idsptch, &sc->sc_dsp[i], sizeof(struct ivec_dsp));
220 sc->sc_dsp[i].hoppaddr = stray;
221 sc->sc_dsp[i].pushlarg = i;
222 scbP[inrs[i]/4] = &sc->sc_dsp[i];
223 }
224 }
225
226 void
227 vsbus_intr_attach(nr, func, arg)
228 int nr;
229 void (*func)(int);
230 int arg;
231 {
232 struct vsbus_softc *sc = vsbus_cd.cd_devs[0];
233
234 sc->sc_dsp[nr].hoppaddr = func;
235 sc->sc_dsp[nr].pushlarg = arg;
236 }
237
238 void
239 vsbus_intr_enable(nr)
240 int nr;
241 {
242 vs_cpu->vc_intclr = (1<<nr);
243 vs_cpu->vc_intmsk |= (1<<nr);
244 }
245
246 void
247 vsbus_intr_disable(nr)
248 int nr;
249 {
250 vs_cpu->vc_intmsk = vs_cpu->vc_intmsk & ~(1<<nr);
251 }
252
253 #ifdef notyet
254 /*
255 * Allocate/free DMA pages and other bus resources.
256 * VS2000: All DMA and register access must be exclusive.
257 * VS3100: DMA area may be accessed by anyone anytime.
258 * MFM/SCSI: Don't touch reg's while DMA is active.
259 * SCSI/SCSI: Legal to touch any register anytime.
260 */
261
262
263 #endif
264