vsbus.c revision 1.16 1 1.16 ragge /* $NetBSD: vsbus.c,v 1.16 1999/03/13 15:16:48 ragge Exp $ */
2 1.1 ragge /*
3 1.1 ragge * Copyright (c) 1996 Ludd, University of Lule}, Sweden.
4 1.1 ragge * All rights reserved.
5 1.1 ragge *
6 1.1 ragge * This code is derived from software contributed to Ludd by Bertram Barth.
7 1.1 ragge *
8 1.1 ragge * Redistribution and use in source and binary forms, with or without
9 1.1 ragge * modification, are permitted provided that the following conditions
10 1.1 ragge * are met:
11 1.1 ragge * 1. Redistributions of source code must retain the above copyright
12 1.1 ragge * notice, this list of conditions and the following disclaimer.
13 1.1 ragge * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 ragge * notice, this list of conditions and the following disclaimer in the
15 1.1 ragge * documentation and/or other materials provided with the distribution.
16 1.1 ragge * 3. All advertising materials mentioning features or use of this software
17 1.1 ragge * must display the following acknowledgement:
18 1.1 ragge * This product includes software developed at Ludd, University of
19 1.1 ragge * Lule}, Sweden and its contributors.
20 1.1 ragge * 4. The name of the author may not be used to endorse or promote products
21 1.1 ragge * derived from this software without specific prior written permission
22 1.1 ragge *
23 1.1 ragge * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 1.1 ragge * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 1.1 ragge * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 1.1 ragge * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 1.1 ragge * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 1.1 ragge * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 1.1 ragge * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 1.1 ragge * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 1.1 ragge * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 1.1 ragge * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 1.1 ragge */
34 1.1 ragge
35 1.1 ragge #include <sys/param.h>
36 1.1 ragge #include <sys/systm.h>
37 1.1 ragge #include <sys/buf.h>
38 1.1 ragge #include <sys/conf.h>
39 1.1 ragge #include <sys/file.h>
40 1.1 ragge #include <sys/ioctl.h>
41 1.1 ragge #include <sys/proc.h>
42 1.1 ragge #include <sys/user.h>
43 1.1 ragge #include <sys/map.h>
44 1.1 ragge #include <sys/device.h>
45 1.1 ragge #include <sys/dkstat.h>
46 1.1 ragge #include <sys/disklabel.h>
47 1.1 ragge #include <sys/syslog.h>
48 1.1 ragge #include <sys/stat.h>
49 1.1 ragge
50 1.1 ragge #include <machine/pte.h>
51 1.1 ragge #include <machine/sid.h>
52 1.1 ragge #include <machine/scb.h>
53 1.1 ragge #include <machine/cpu.h>
54 1.1 ragge #include <machine/trap.h>
55 1.1 ragge #include <machine/nexus.h>
56 1.1 ragge
57 1.1 ragge #include <machine/uvax.h>
58 1.1 ragge #include <machine/ka410.h>
59 1.12 ragge #include <machine/ka420.h>
60 1.1 ragge #include <machine/ka43.h>
61 1.1 ragge
62 1.1 ragge #include <machine/vsbus.h>
63 1.1 ragge
64 1.10 ragge #include "ioconf.h"
65 1.1 ragge
66 1.9 ragge int vsbus_match __P((struct device *, struct cfdata *, void *));
67 1.1 ragge void vsbus_attach __P((struct device *, struct device *, void *));
68 1.2 cgd int vsbus_print __P((void *, const char *));
69 1.16 ragge int vsbus_search __P((struct device *, struct cfdata *, void *));
70 1.1 ragge
71 1.1 ragge void ka410_attach __P((struct device *, struct device *, void *));
72 1.1 ragge void ka43_attach __P((struct device *, struct device *, void *));
73 1.1 ragge
74 1.10 ragge struct vsbus_softc {
75 1.10 ragge struct device sc_dev;
76 1.16 ragge volatile struct vs_cpu *sc_cpu;
77 1.16 ragge u_char sc_mask; /* Interrupts to enable after autoconf */
78 1.10 ragge };
79 1.1 ragge
80 1.10 ragge struct cfattach vsbus_ca = {
81 1.10 ragge sizeof(struct vsbus_softc), vsbus_match, vsbus_attach
82 1.1 ragge };
83 1.6 ragge
84 1.1 ragge int
85 1.1 ragge vsbus_print(aux, name)
86 1.1 ragge void *aux;
87 1.2 cgd const char *name;
88 1.1 ragge {
89 1.10 ragge struct vsbus_attach_args *va = aux;
90 1.1 ragge
91 1.16 ragge printf(" csr 0x%lx vec %o ipl %x maskbit %x", va->va_paddr,
92 1.16 ragge va->va_cvec & 511, va->va_br, va->va_maskno - 1);
93 1.16 ragge return(UNCONF);
94 1.1 ragge }
95 1.1 ragge
96 1.1 ragge int
97 1.1 ragge vsbus_match(parent, cf, aux)
98 1.1 ragge struct device *parent;
99 1.9 ragge struct cfdata *cf;
100 1.1 ragge void *aux;
101 1.1 ragge {
102 1.1 ragge struct bp_conf *bp = aux;
103 1.1 ragge
104 1.1 ragge if (strcmp(bp->type, "vsbus"))
105 1.1 ragge return 0;
106 1.1 ragge /*
107 1.1 ragge * on machines which can have it, the vsbus is always there
108 1.1 ragge */
109 1.1 ragge if ((vax_bustype & VAX_VSBUS) == 0)
110 1.1 ragge return (0);
111 1.1 ragge
112 1.1 ragge return (1);
113 1.1 ragge }
114 1.1 ragge
115 1.1 ragge void
116 1.1 ragge vsbus_attach(parent, self, aux)
117 1.1 ragge struct device *parent, *self;
118 1.1 ragge void *aux;
119 1.1 ragge {
120 1.10 ragge struct vsbus_softc *sc = (void *)self;
121 1.1 ragge
122 1.4 christos printf("\n");
123 1.14 ragge
124 1.16 ragge sc->sc_cpu = (void *)vax_map_physmem(VS_REGS, 1);
125 1.16 ragge
126 1.1 ragge /*
127 1.16 ragge * First: find which interrupts we won't care about.
128 1.16 ragge * There are interrupts that interrupt on a periodic basic
129 1.16 ragge * that we don't want to interfere with the rest of the
130 1.16 ragge * interrupt probing.
131 1.1 ragge */
132 1.16 ragge sc->sc_cpu->vc_intmsk = 0;
133 1.16 ragge sc->sc_cpu->vc_intclr = 0xff;
134 1.16 ragge DELAY(1000000); /* Wait a second */
135 1.16 ragge sc->sc_mask = sc->sc_cpu->vc_intreq;
136 1.16 ragge printf("%s: interrupt mask %x\n", self->dv_xname, sc->sc_mask);
137 1.1 ragge /*
138 1.1 ragge * now check for all possible devices on this "bus"
139 1.1 ragge */
140 1.16 ragge config_search(vsbus_search, self, NULL);
141 1.13 ragge
142 1.16 ragge /* Autoconfig finished, enable interrupts */
143 1.16 ragge sc->sc_cpu->vc_intmsk = ~sc->sc_mask;
144 1.1 ragge }
145 1.1 ragge
146 1.16 ragge int
147 1.16 ragge vsbus_search(parent, cf, aux)
148 1.16 ragge struct device *parent;
149 1.16 ragge struct cfdata *cf;
150 1.16 ragge void *aux;
151 1.1 ragge {
152 1.16 ragge struct vsbus_softc *sc = (void *)parent;
153 1.16 ragge struct vsbus_attach_args va;
154 1.16 ragge int i, vec, br;
155 1.16 ragge u_char c;
156 1.1 ragge
157 1.16 ragge va.va_paddr = cf->cf_loc[0];
158 1.16 ragge va.va_addr = vax_map_physmem(va.va_paddr, 1);
159 1.1 ragge
160 1.16 ragge sc->sc_cpu->vc_intmsk = 0;
161 1.16 ragge sc->sc_cpu->vc_intclr = 0xff;
162 1.16 ragge scb_vecref(0, 0); /* Clear vector ref */
163 1.16 ragge
164 1.16 ragge i = (*cf->cf_attach->ca_match) (parent, cf, &va);
165 1.16 ragge vax_unmap_physmem(va.va_addr, 1);
166 1.16 ragge c = sc->sc_cpu->vc_intreq & ~sc->sc_mask;
167 1.16 ragge if (i > 10)
168 1.16 ragge c = sc->sc_mask; /* Fooling interrupt */
169 1.16 ragge if (c == 0 || i == 0)
170 1.16 ragge goto forgetit;
171 1.16 ragge
172 1.16 ragge sc->sc_cpu->vc_intmsk = c;
173 1.16 ragge DELAY(100);
174 1.16 ragge sc->sc_cpu->vc_intmsk = 0;
175 1.16 ragge va.va_maskno = ffs((u_int)c);
176 1.16 ragge i = scb_vecref(&vec, &br);
177 1.16 ragge if (i == 0)
178 1.16 ragge goto fail;
179 1.16 ragge if (vec == 0)
180 1.16 ragge goto fail;
181 1.16 ragge
182 1.16 ragge scb_vecalloc(vec, va.va_ivec, cf->cf_unit, SCB_ISTACK);
183 1.16 ragge va.va_br = br;
184 1.16 ragge va.va_cvec = vec;
185 1.16 ragge
186 1.16 ragge config_attach(parent, cf, &va, vsbus_print);
187 1.16 ragge return 0;
188 1.16 ragge
189 1.16 ragge fail:
190 1.16 ragge printf("%s%d at %s csr %x %s\n",
191 1.16 ragge cf->cf_driver->cd_name, cf->cf_unit, parent->dv_xname,
192 1.16 ragge cf->cf_loc[0], (i ? "zero vector" : "didn't interrupt"));
193 1.16 ragge forgetit:
194 1.16 ragge return 0;
195 1.1 ragge }
196 1.1 ragge
197 1.16 ragge /*
198 1.16 ragge * Sets a new interrupt mask. Returns the old one.
199 1.16 ragge * Works like spl functions.
200 1.16 ragge */
201 1.16 ragge unsigned char
202 1.16 ragge vsbus_setmask(mask)
203 1.16 ragge unsigned char mask;
204 1.1 ragge {
205 1.10 ragge struct vsbus_softc *sc = vsbus_cd.cd_devs[0];
206 1.16 ragge unsigned char ch;
207 1.1 ragge
208 1.16 ragge ch = sc->sc_cpu->vc_intmsk;
209 1.16 ragge sc->sc_cpu->vc_intmsk = mask;
210 1.16 ragge return ch;
211 1.1 ragge }
212 1.1 ragge
213 1.16 ragge /*
214 1.16 ragge * Clears the interrupts in mask.
215 1.16 ragge */
216 1.10 ragge void
217 1.16 ragge vsbus_clrintr(mask)
218 1.16 ragge unsigned char mask;
219 1.1 ragge {
220 1.16 ragge struct vsbus_softc *sc = vsbus_cd.cd_devs[0];
221 1.1 ragge
222 1.16 ragge sc->sc_cpu->vc_intclr = mask;
223 1.1 ragge }
224 1.1 ragge
225 1.12 ragge #ifdef notyet
226 1.1 ragge /*
227 1.12 ragge * Allocate/free DMA pages and other bus resources.
228 1.12 ragge * VS2000: All DMA and register access must be exclusive.
229 1.12 ragge * VS3100: DMA area may be accessed by anyone anytime.
230 1.12 ragge * MFM/SCSI: Don't touch reg's while DMA is active.
231 1.12 ragge * SCSI/SCSI: Legal to touch any register anytime.
232 1.1 ragge */
233 1.1 ragge
234 1.1 ragge
235 1.1 ragge #endif
236