vsbus.c revision 1.15 1 /* $NetBSD: vsbus.c,v 1.15 1999/03/09 12:57:58 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 /* XXX - Detecting smg on 4000 VLC crashes, SCSI is 53c94 */
152 if (vax_boardtype == VAX_BTYP_48)
153 return;
154
155 /* If sm_addr is set, a monochrome graphics adapter is found */
156 /* XXX - fixa! */
157 va.va_type = inr_vf;
158 config_found(self, &va, vsbus_print);
159
160 /* XXX - Avoid searching for SCSI on 4000/60 */
161 if (vax_boardtype == VAX_BTYP_46)
162 return;
163
164 /*
165 * Check for mass storage devices. This is tricky :-/
166 * VS2K always has both MFM and SCSI.
167 * VS3100 has either MFM/SCSI, SCSI/SCSI or neither of them.
168 * The device registers are at different places for them all.
169 */
170 if (vax_boardtype == VAX_BTYP_410) {
171 #ifdef notyet
172 va.va_type = inr_dc;
173 config_found(self, &va, vsbus_print);
174 #endif
175 va.va_type = 0x200C0080;
176 config_found(self, &va, vsbus_print);
177 return;
178 }
179
180 if ((vax_confdata & KA420_CFG_STCMSK) == KA420_CFG_NONE)
181 return; /* No ctlrs */
182
183 /* Ok, we have at least one scsi ctlr */
184 va.va_type = 0x200C0080;
185 config_found(self, &va, vsbus_print);
186
187 #ifdef notyet
188 /* The last one is MFM or SCSI */
189 if ((vax_confdata & KA420_CFG_STCMSK) == KA420_CFG_RB) {
190 va.va_type = inr_dc;
191 config_found(self, &va, vsbus_print);
192 } else {
193 va.va_type = 0x200C0180;
194 config_found(self, &va, vsbus_print);
195 }
196 #endif
197 }
198
199 static void stray __P((int));
200
201 static void
202 stray(arg)
203 int arg;
204 {
205 printf("stray interrupt nr %d.\n", arg);
206 }
207
208 static int inrs[] = {IVEC_DC, IVEC_SC, IVEC_VS, IVEC_VF,
209 IVEC_NS, IVEC_NP, IVEC_ST, IVEC_SR};
210
211 void
212 vsbus_intr_setup(sc)
213 struct vsbus_softc *sc;
214 {
215 extern struct ivec_dsp idsptch; /* subr.s */
216 void **scbP = (void*)scb;
217 int i;
218
219 vs_cpu->vc_intmsk = 0; /* disable all interrupts */
220 vs_cpu->vc_intclr = 0xFF; /* clear all old interrupts */
221
222 for (i = 0; i < VSBUS_MAXINTR; i++) {
223 bcopy(&idsptch, &sc->sc_dsp[i], sizeof(struct ivec_dsp));
224 sc->sc_dsp[i].hoppaddr = stray;
225 sc->sc_dsp[i].pushlarg = i;
226 scbP[inrs[i]/4] = &sc->sc_dsp[i];
227 }
228 }
229
230 void
231 vsbus_intr_attach(nr, func, arg)
232 int nr;
233 void (*func)(int);
234 int arg;
235 {
236 struct vsbus_softc *sc = vsbus_cd.cd_devs[0];
237
238 sc->sc_dsp[nr].hoppaddr = func;
239 sc->sc_dsp[nr].pushlarg = arg;
240 }
241
242 void
243 vsbus_intr_enable(nr)
244 int nr;
245 {
246 vs_cpu->vc_intclr = (1<<nr);
247 vs_cpu->vc_intmsk |= (1<<nr);
248 }
249
250 void
251 vsbus_intr_disable(nr)
252 int nr;
253 {
254 vs_cpu->vc_intmsk = vs_cpu->vc_intmsk & ~(1<<nr);
255 }
256
257 #ifdef notyet
258 /*
259 * Allocate/free DMA pages and other bus resources.
260 * VS2000: All DMA and register access must be exclusive.
261 * VS3100: DMA area may be accessed by anyone anytime.
262 * MFM/SCSI: Don't touch reg's while DMA is active.
263 * SCSI/SCSI: Legal to touch any register anytime.
264 */
265
266
267 #endif
268