if_ie_vme.c revision 1.19 1 1.19 perry /* $NetBSD: if_ie_vme.c,v 1.19 2005/02/04 02:10:49 perry Exp $ */
2 1.1 pk
3 1.1 pk /*-
4 1.1 pk * Copyright (c) 1995 Charles D. Cranor
5 1.1 pk * All rights reserved.
6 1.1 pk *
7 1.1 pk * Redistribution and use in source and binary forms, with or without
8 1.1 pk * modification, are permitted provided that the following conditions
9 1.1 pk * are met:
10 1.1 pk * 1. Redistributions of source code must retain the above copyright
11 1.1 pk * notice, this list of conditions and the following disclaimer.
12 1.1 pk * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 pk * notice, this list of conditions and the following disclaimer in the
14 1.1 pk * documentation and/or other materials provided with the distribution.
15 1.1 pk * 3. All advertising materials mentioning features or use of this software
16 1.1 pk * must display the following acknowledgement:
17 1.1 pk * This product includes software developed by Charles D. Cranor.
18 1.1 pk * 4. The name of the author may not be used to endorse or promote products
19 1.1 pk * derived from this software without specific prior written permission.
20 1.1 pk *
21 1.1 pk * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 1.1 pk * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.1 pk * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.1 pk * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 1.1 pk * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 1.1 pk * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 1.1 pk * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.1 pk * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.1 pk * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 1.1 pk * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.1 pk */
32 1.1 pk
33 1.1 pk /*
34 1.1 pk * Converted to SUN ie driver by Charles D. Cranor,
35 1.1 pk * October 1994, January 1995.
36 1.1 pk */
37 1.1 pk
38 1.1 pk /*
39 1.1 pk * The i82586 is a very painful chip, found in sun3's, sun-4/100's
40 1.1 pk * sun-4/200's, and VME based suns. The byte order is all wrong for a
41 1.1 pk * SUN, making life difficult. Programming this chip is mostly the same,
42 1.1 pk * but certain details differ from system to system. This driver is
43 1.1 pk * written so that different "ie" interfaces can be controled by the same
44 1.1 pk * driver.
45 1.1 pk */
46 1.1 pk
47 1.1 pk /*
48 1.1 pk * programming notes:
49 1.1 pk *
50 1.1 pk * the ie chip operates in a 24 bit address space.
51 1.1 pk *
52 1.1 pk * most ie interfaces appear to be divided into two parts:
53 1.1 pk * - generic 586 stuff
54 1.1 pk * - board specific
55 1.1 pk *
56 1.1 pk * generic:
57 1.1 pk * the generic stuff of the ie chip is all done with data structures
58 1.1 pk * that live in the chip's memory address space. the chip expects
59 1.1 pk * its main data structure (the sys conf ptr -- SCP) to be at a fixed
60 1.1 pk * address in its 24 bit space: 0xfffff4
61 1.1 pk *
62 1.1 pk * the SCP points to another structure called the ISCP.
63 1.1 pk * the ISCP points to another structure called the SCB.
64 1.1 pk * the SCB has a status field, a linked list of "commands", and
65 1.1 pk * a linked list of "receive buffers". these are data structures that
66 1.1 pk * live in memory, not registers.
67 1.1 pk *
68 1.1 pk * board:
69 1.1 pk * to get the chip to do anything, you first put a command in the
70 1.1 pk * command data structure list. then you have to signal "attention"
71 1.1 pk * to the chip to get it to look at the command. how you
72 1.1 pk * signal attention depends on what board you have... on PC's
73 1.1 pk * there is an i/o port number to do this, on sun's there is a
74 1.1 pk * register bit you toggle.
75 1.1 pk *
76 1.1 pk * to get data from the chip you program it to interrupt...
77 1.1 pk *
78 1.1 pk *
79 1.1 pk * sun issues:
80 1.1 pk *
81 1.1 pk * there are 3 kinds of sun "ie" interfaces:
82 1.1 pk * 1 - a VME/multibus card
83 1.1 pk * 2 - an on-board interface (sun3's, sun-4/100's, and sun-4/200's)
84 1.1 pk * 3 - another VME board called the 3E
85 1.1 pk *
86 1.1 pk * the VME boards lives in vme16 space. only 16 and 8 bit accesses
87 1.1 pk * are allowed, so functions that copy data must be aware of this.
88 1.1 pk *
89 1.1 pk * the chip is an intel chip. this means that the byte order
90 1.1 pk * on all the "short"s in the chip's data structures is wrong.
91 1.1 pk * so, constants described in the intel docs are swapped for the sun.
92 1.1 pk * that means that any buffer pointers you give the chip must be
93 1.1 pk * swapped to intel format. yuck.
94 1.1 pk *
95 1.1 pk * VME/multibus interface:
96 1.1 pk * for the multibus interface the board ignores the top 4 bits
97 1.2 pk * of the chip address. the multibus interface has its own
98 1.2 pk * MMU like page map (without protections or valid bits, etc).
99 1.1 pk * there are 256 pages of physical memory on the board (each page
100 1.2 pk * is 1024 bytes). There are 1024 slots in the page map. so,
101 1.1 pk * a 1024 byte page takes up 10 bits of address for the offset,
102 1.1 pk * and if there are 1024 slots in the page that is another 10 bits
103 1.2 pk * of the address. That makes a 20 bit address, and as stated
104 1.1 pk * earlier the board ignores the top 4 bits, so that accounts
105 1.1 pk * for all 24 bits of address.
106 1.1 pk *
107 1.2 pk * Note that the last entry of the page map maps the top of the
108 1.1 pk * 24 bit address space and that the SCP is supposed to be at
109 1.1 pk * 0xfffff4 (taking into account allignment). so,
110 1.1 pk * for multibus, that entry in the page map has to be used for the SCP.
111 1.1 pk *
112 1.2 pk * The page map effects BOTH how the ie chip sees the
113 1.1 pk * memory, and how the host sees it.
114 1.1 pk *
115 1.2 pk * The page map is part of the "register" area of the board
116 1.2 pk *
117 1.2 pk * The page map to control where ram appears in the address space.
118 1.2 pk * We choose to have RAM start at 0 in the 24 bit address space.
119 1.2 pk *
120 1.2 pk * to get the phyiscal address of the board's RAM you must take the
121 1.2 pk * top 12 bits of the physical address of the register address and
122 1.2 pk * or in the 4 bits from the status word as bits 17-20 (remember that
123 1.2 pk * the board ignores the chip's top 4 address lines). For example:
124 1.2 pk * if the register is @ 0xffe88000, then the top 12 bits are 0xffe00000.
125 1.8 soren * to get the 4 bits from the status word just do status & IEVME_HADDR.
126 1.2 pk * suppose the value is "4". Then just shift it left 16 bits to get
127 1.2 pk * it into bits 17-20 (e.g. 0x40000). Then or it to get the
128 1.2 pk * address of RAM (in our example: 0xffe40000). see the attach routine!
129 1.2 pk *
130 1.1 pk *
131 1.1 pk * on-board interface:
132 1.1 pk *
133 1.2 pk * on the onboard ie interface the 24 bit address space is hardwired
134 1.2 pk * to be 0xff000000 -> 0xffffffff of KVA. this means that sc_iobase
135 1.2 pk * will be 0xff000000. sc_maddr will be where ever we allocate RAM
136 1.2 pk * in KVA. note that since the SCP is at a fixed address it means
137 1.2 pk * that we have to allocate a fixed KVA for the SCP.
138 1.1 pk * <fill in useful info later>
139 1.1 pk *
140 1.1 pk *
141 1.1 pk * VME3E interface:
142 1.1 pk *
143 1.1 pk * <fill in useful info later>
144 1.1 pk *
145 1.1 pk */
146 1.14 lukem
147 1.14 lukem #include <sys/cdefs.h>
148 1.19 perry __KERNEL_RCSID(0, "$NetBSD: if_ie_vme.c,v 1.19 2005/02/04 02:10:49 perry Exp $");
149 1.1 pk
150 1.1 pk #include <sys/param.h>
151 1.1 pk #include <sys/systm.h>
152 1.1 pk #include <sys/errno.h>
153 1.1 pk #include <sys/device.h>
154 1.1 pk #include <sys/protosw.h>
155 1.1 pk #include <sys/socket.h>
156 1.1 pk
157 1.1 pk #include <net/if.h>
158 1.1 pk #include <net/if_types.h>
159 1.1 pk #include <net/if_dl.h>
160 1.2 pk #include <net/if_media.h>
161 1.1 pk #include <net/if_ether.h>
162 1.1 pk
163 1.1 pk #include <machine/bus.h>
164 1.7 drochner #include <machine/intr.h>
165 1.18 pk #ifdef __sparc__
166 1.18 pk #include <machine/autoconf.h>
167 1.18 pk #endif
168 1.1 pk #include <dev/vme/vmevar.h>
169 1.1 pk
170 1.1 pk #include <dev/ic/i82586reg.h>
171 1.1 pk #include <dev/ic/i82586var.h>
172 1.1 pk
173 1.7 drochner #include "locators.h"
174 1.1 pk
175 1.1 pk /*
176 1.1 pk * VME/multibus definitions
177 1.1 pk */
178 1.1 pk #define IEVME_PAGESIZE 1024 /* bytes */
179 1.1 pk #define IEVME_PAGSHIFT 10 /* bits */
180 1.1 pk #define IEVME_NPAGES 256 /* number of pages on chip */
181 1.1 pk #define IEVME_MAPSZ 1024 /* number of entries in the map */
182 1.1 pk
183 1.1 pk /*
184 1.1 pk * PTE for the page map
185 1.1 pk */
186 1.1 pk #define IEVME_SBORDR 0x8000 /* sun byte order */
187 1.1 pk #define IEVME_IBORDR 0x0000 /* intel byte ordr */
188 1.1 pk
189 1.1 pk #define IEVME_P2MEM 0x2000 /* memory is on P2 */
190 1.1 pk #define IEVME_OBMEM 0x0000 /* memory is on board */
191 1.1 pk
192 1.1 pk #define IEVME_PGMASK 0x0fff /* gives the physical page frame number */
193 1.1 pk
194 1.1 pk struct ievme {
195 1.1 pk u_int16_t pgmap[IEVME_MAPSZ];
196 1.1 pk u_int16_t xxx[32]; /* prom */
197 1.1 pk u_int16_t status; /* see below for bits */
198 1.1 pk u_int16_t xxx2; /* filler */
199 1.1 pk u_int16_t pectrl; /* parity control (see below) */
200 1.1 pk u_int16_t peaddr; /* low 16 bits of address */
201 1.1 pk };
202 1.1 pk
203 1.1 pk /*
204 1.1 pk * status bits
205 1.1 pk */
206 1.1 pk #define IEVME_RESET 0x8000 /* reset board */
207 1.1 pk #define IEVME_ONAIR 0x4000 /* go out of loopback 'on-air' */
208 1.1 pk #define IEVME_ATTEN 0x2000 /* attention */
209 1.1 pk #define IEVME_IENAB 0x1000 /* interrupt enable */
210 1.1 pk #define IEVME_PEINT 0x0800 /* parity error interrupt enable */
211 1.1 pk #define IEVME_PERR 0x0200 /* parity error flag */
212 1.1 pk #define IEVME_INT 0x0100 /* interrupt flag */
213 1.1 pk #define IEVME_P2EN 0x0020 /* enable p2 bus */
214 1.1 pk #define IEVME_256K 0x0010 /* 256kb rams */
215 1.1 pk #define IEVME_HADDR 0x000f /* mask for bits 17-20 of address */
216 1.1 pk
217 1.1 pk /*
218 1.1 pk * parity control
219 1.1 pk */
220 1.1 pk #define IEVME_PARACK 0x0100 /* parity error ack */
221 1.1 pk #define IEVME_PARSRC 0x0080 /* parity error source */
222 1.1 pk #define IEVME_PAREND 0x0040 /* which end of the data got the error */
223 1.1 pk #define IEVME_PARADR 0x000f /* mask to get bits 17-20 of parity address */
224 1.1 pk
225 1.2 pk /* Supported media */
226 1.2 pk static int media[] = {
227 1.2 pk IFM_ETHER | IFM_10_2,
228 1.2 pk };
229 1.2 pk #define NMEDIA (sizeof(media) / sizeof(media[0]))
230 1.1 pk
231 1.1 pk /*
232 1.1 pk * the 3E board not supported (yet?)
233 1.1 pk */
234 1.1 pk
235 1.1 pk
236 1.19 perry static void ie_vmereset(struct ie_softc *, int);
237 1.19 perry static void ie_vmeattend(struct ie_softc *, int);
238 1.19 perry static void ie_vmerun(struct ie_softc *);
239 1.19 perry static int ie_vmeintr(struct ie_softc *, int);
240 1.1 pk
241 1.19 perry int ie_vme_match(struct device *, struct cfdata *, void *);
242 1.19 perry void ie_vme_attach(struct device *, struct device *, void *);
243 1.1 pk
244 1.7 drochner struct ie_vme_softc {
245 1.7 drochner struct ie_softc ie;
246 1.7 drochner bus_space_tag_t ievt;
247 1.7 drochner bus_space_handle_t ievh;
248 1.7 drochner };
249 1.7 drochner
250 1.16 thorpej CFATTACH_DECL(ie_vme, sizeof(struct ie_vme_softc),
251 1.17 thorpej ie_vme_match, ie_vme_attach, NULL, NULL);
252 1.1 pk
253 1.7 drochner #define read_iev(sc, reg) \
254 1.7 drochner bus_space_read_2(sc->ievt, sc->ievh, offsetof(struct ievme, reg))
255 1.7 drochner #define write_iev(sc, reg, val) \
256 1.7 drochner bus_space_write_2(sc->ievt, sc->ievh, offsetof(struct ievme, reg), val)
257 1.2 pk
258 1.1 pk /*
259 1.1 pk * MULTIBUS/VME support routines
260 1.1 pk */
261 1.1 pk void
262 1.2 pk ie_vmereset(sc, what)
263 1.1 pk struct ie_softc *sc;
264 1.2 pk int what;
265 1.1 pk {
266 1.7 drochner struct ie_vme_softc *vsc = (struct ie_vme_softc *)sc;
267 1.7 drochner write_iev(vsc, status, IEVME_RESET);
268 1.1 pk delay(100); /* XXX could be shorter? */
269 1.7 drochner write_iev(vsc, status, 0);
270 1.1 pk }
271 1.1 pk
272 1.1 pk void
273 1.13 tsutsui ie_vmeattend(sc, why)
274 1.1 pk struct ie_softc *sc;
275 1.13 tsutsui int why;
276 1.1 pk {
277 1.7 drochner struct ie_vme_softc *vsc = (struct ie_vme_softc *)sc;
278 1.1 pk
279 1.7 drochner /* flag! */
280 1.7 drochner write_iev(vsc, status, read_iev(vsc, status) | IEVME_ATTEN);
281 1.7 drochner /* down. */
282 1.7 drochner write_iev(vsc, status, read_iev(vsc, status) & ~IEVME_ATTEN);
283 1.1 pk }
284 1.1 pk
285 1.1 pk void
286 1.1 pk ie_vmerun(sc)
287 1.1 pk struct ie_softc *sc;
288 1.1 pk {
289 1.7 drochner struct ie_vme_softc *vsc = (struct ie_vme_softc *)sc;
290 1.1 pk
291 1.7 drochner write_iev(vsc, status, read_iev(vsc, status)
292 1.7 drochner | IEVME_ONAIR | IEVME_IENAB | IEVME_PEINT);
293 1.1 pk }
294 1.1 pk
295 1.1 pk int
296 1.2 pk ie_vmeintr(sc, where)
297 1.1 pk struct ie_softc *sc;
298 1.2 pk int where;
299 1.1 pk {
300 1.7 drochner struct ie_vme_softc *vsc = (struct ie_vme_softc *)sc;
301 1.1 pk
302 1.2 pk if (where != INTR_ENTER)
303 1.2 pk return (0);
304 1.2 pk
305 1.1 pk /*
306 1.1 pk * check for parity error
307 1.1 pk */
308 1.7 drochner if (read_iev(vsc, status) & IEVME_PERR) {
309 1.1 pk printf("%s: parity error (ctrl 0x%x @ 0x%02x%04x)\n",
310 1.7 drochner sc->sc_dev.dv_xname, read_iev(vsc, pectrl),
311 1.7 drochner read_iev(vsc, pectrl) & IEVME_HADDR,
312 1.7 drochner read_iev(vsc, peaddr));
313 1.7 drochner write_iev(vsc, pectrl, read_iev(vsc, pectrl) | IEVME_PARACK);
314 1.1 pk }
315 1.1 pk return (0);
316 1.1 pk }
317 1.1 pk
318 1.19 perry void ie_memcopyin(struct ie_softc *, void *, int, size_t);
319 1.19 perry void ie_memcopyout(struct ie_softc *, const void *, int, size_t);
320 1.2 pk
321 1.2 pk /*
322 1.2 pk * Copy board memory to kernel.
323 1.2 pk */
324 1.2 pk void
325 1.2 pk ie_memcopyin(sc, p, offset, size)
326 1.2 pk struct ie_softc *sc;
327 1.2 pk void *p;
328 1.2 pk int offset;
329 1.2 pk size_t size;
330 1.2 pk {
331 1.7 drochner size_t help;
332 1.7 drochner
333 1.7 drochner if ((offset & 1) && ((u_long)p & 1) && size > 0) {
334 1.7 drochner *(u_int8_t *)p = bus_space_read_1(sc->bt, sc->bh, offset);
335 1.7 drochner offset++;
336 1.7 drochner p = (u_int8_t *)p + 1;
337 1.7 drochner size--;
338 1.7 drochner }
339 1.7 drochner
340 1.7 drochner if ((offset & 1) || ((u_long)p & 1)) {
341 1.7 drochner bus_space_read_region_1(sc->bt, sc->bh, offset, p, size);
342 1.7 drochner return;
343 1.7 drochner }
344 1.7 drochner
345 1.7 drochner help = size / 2;
346 1.7 drochner bus_space_read_region_2(sc->bt, sc->bh, offset, p, help);
347 1.7 drochner if (2 * help == size)
348 1.7 drochner return;
349 1.7 drochner
350 1.7 drochner offset += 2 * help;
351 1.7 drochner p = (u_int16_t *)p + help;
352 1.7 drochner *(u_int8_t *)p = bus_space_read_1(sc->bt, sc->bh, offset);
353 1.2 pk }
354 1.2 pk
355 1.2 pk /*
356 1.7 drochner * Copy from kernel space to board memory.
357 1.2 pk */
358 1.2 pk void
359 1.2 pk ie_memcopyout(sc, p, offset, size)
360 1.2 pk struct ie_softc *sc;
361 1.2 pk const void *p;
362 1.2 pk int offset;
363 1.2 pk size_t size;
364 1.2 pk {
365 1.7 drochner size_t help;
366 1.7 drochner
367 1.7 drochner if ((offset & 1) && ((u_long)p & 1) && size > 0) {
368 1.7 drochner bus_space_write_1(sc->bt, sc->bh, offset, *(u_int8_t *)p);
369 1.7 drochner offset++;
370 1.7 drochner p = (u_int8_t *)p + 1;
371 1.7 drochner size--;
372 1.7 drochner }
373 1.7 drochner
374 1.7 drochner if ((offset & 1) || ((u_long)p & 1)) {
375 1.7 drochner bus_space_write_region_1(sc->bt, sc->bh, offset, p, size);
376 1.7 drochner return;
377 1.7 drochner }
378 1.7 drochner
379 1.7 drochner help = size / 2;
380 1.7 drochner bus_space_write_region_2(sc->bt, sc->bh, offset, p, help);
381 1.7 drochner if (2 * help == size)
382 1.7 drochner return;
383 1.7 drochner
384 1.7 drochner offset += 2 * help;
385 1.7 drochner p = (u_int16_t *)p + help;
386 1.7 drochner bus_space_write_1(sc->bt, sc->bh, offset, *(u_int8_t *)p);
387 1.2 pk }
388 1.2 pk
389 1.2 pk /* read a 16-bit value at BH offset */
390 1.19 perry u_int16_t ie_vme_read16(struct ie_softc *, int offset);
391 1.2 pk /* write a 16-bit value at BH offset */
392 1.19 perry void ie_vme_write16(struct ie_softc *, int offset, u_int16_t value);
393 1.19 perry void ie_vme_write24(struct ie_softc *, int offset, int addr);
394 1.2 pk
395 1.2 pk u_int16_t
396 1.2 pk ie_vme_read16(sc, offset)
397 1.2 pk struct ie_softc *sc;
398 1.2 pk int offset;
399 1.2 pk {
400 1.2 pk u_int16_t v;
401 1.2 pk
402 1.2 pk bus_space_barrier(sc->bt, sc->bh, offset, 2, BUS_SPACE_BARRIER_READ);
403 1.2 pk v = bus_space_read_2(sc->bt, sc->bh, offset);
404 1.2 pk return (((v&0xff)<<8) | ((v>>8)&0xff));
405 1.2 pk }
406 1.2 pk
407 1.2 pk void
408 1.2 pk ie_vme_write16(sc, offset, v)
409 1.2 pk struct ie_softc *sc;
410 1.2 pk int offset;
411 1.2 pk u_int16_t v;
412 1.2 pk {
413 1.2 pk int v0 = ((((v)&0xff)<<8) | (((v)>>8)&0xff));
414 1.2 pk bus_space_write_2(sc->bt, sc->bh, offset, v0);
415 1.2 pk bus_space_barrier(sc->bt, sc->bh, offset, 2, BUS_SPACE_BARRIER_WRITE);
416 1.2 pk }
417 1.2 pk
418 1.2 pk void
419 1.2 pk ie_vme_write24(sc, offset, addr)
420 1.2 pk struct ie_softc *sc;
421 1.2 pk int offset;
422 1.2 pk int addr;
423 1.1 pk {
424 1.2 pk u_char *f = (u_char *)&addr;
425 1.3 pk u_int16_t v0, v1;
426 1.3 pk u_char *t;
427 1.3 pk
428 1.3 pk t = (u_char *)&v0;
429 1.3 pk t[0] = f[3]; t[1] = f[2];
430 1.3 pk bus_space_write_2(sc->bt, sc->bh, offset, v0);
431 1.3 pk
432 1.3 pk t = (u_char *)&v1;
433 1.3 pk t[0] = f[1]; t[1] = 0;
434 1.3 pk bus_space_write_2(sc->bt, sc->bh, offset+2, v1);
435 1.1 pk
436 1.2 pk bus_space_barrier(sc->bt, sc->bh, offset, 4, BUS_SPACE_BARRIER_WRITE);
437 1.1 pk }
438 1.1 pk
439 1.1 pk int
440 1.1 pk ie_vme_match(parent, cf, aux)
441 1.1 pk struct device *parent;
442 1.1 pk struct cfdata *cf;
443 1.1 pk void *aux;
444 1.1 pk {
445 1.1 pk struct vme_attach_args *va = aux;
446 1.7 drochner vme_chipset_tag_t ct = va->va_vct;
447 1.7 drochner vme_am_t mod;
448 1.7 drochner int error;
449 1.7 drochner
450 1.7 drochner if (va->numcfranges < 2) {
451 1.7 drochner printf("ie_vme_match: need 2 ranges\n");
452 1.7 drochner return (0);
453 1.7 drochner }
454 1.7 drochner if ((va->r[1].offset & 0xff0fffff) ||
455 1.7 drochner ((va->r[0].offset & 0xfff00000)
456 1.7 drochner != (va->r[1].offset & 0xfff00000))) {
457 1.7 drochner printf("ie_vme_match: base address mismatch\n");
458 1.7 drochner return (0);
459 1.7 drochner }
460 1.7 drochner if (va->r[0].size != VMECF_LEN_DEFAULT &&
461 1.7 drochner va->r[0].size != sizeof(sizeof(struct ievme))) {
462 1.7 drochner printf("ie_vme_match: bad csr size\n");
463 1.7 drochner return (0);
464 1.7 drochner }
465 1.7 drochner if (va->r[1].size == VMECF_LEN_DEFAULT) {
466 1.7 drochner printf("ie_vme_match: must specify memory size\n");
467 1.7 drochner return (0);
468 1.7 drochner }
469 1.7 drochner
470 1.7 drochner mod = 0x3d; /* VME_AM_A24|VME_AM_MBO|VME_AM_SUPER|VME_AM_DATA */
471 1.7 drochner
472 1.7 drochner if (va->r[0].am != VMECF_AM_DEFAULT &&
473 1.7 drochner va->r[0].am != mod)
474 1.7 drochner return (0);
475 1.1 pk
476 1.7 drochner if (vme_space_alloc(va->va_vct, va->r[0].offset,
477 1.7 drochner sizeof(struct ievme), mod))
478 1.7 drochner return (0);
479 1.7 drochner if (vme_space_alloc(va->va_vct, va->r[1].offset,
480 1.7 drochner va->r[1].size, mod)) {
481 1.7 drochner vme_space_free(va->va_vct, va->r[0].offset,
482 1.7 drochner sizeof(struct ievme), mod);
483 1.7 drochner return (0);
484 1.7 drochner }
485 1.7 drochner error = vme_probe(ct, va->r[0].offset, 2, mod, VME_D16, 0, 0);
486 1.7 drochner vme_space_free(va->va_vct, va->r[0].offset, sizeof(struct ievme), mod);
487 1.7 drochner vme_space_free(va->va_vct, va->r[1].offset, va->r[1].size, mod);
488 1.7 drochner
489 1.7 drochner return (error == 0);
490 1.1 pk }
491 1.1 pk
492 1.1 pk void
493 1.1 pk ie_vme_attach(parent, self, aux)
494 1.1 pk struct device *parent;
495 1.1 pk struct device *self;
496 1.1 pk void *aux;
497 1.1 pk {
498 1.1 pk u_int8_t myaddr[ETHER_ADDR_LEN];
499 1.7 drochner struct ie_vme_softc *vsc = (void *) self;
500 1.1 pk struct vme_attach_args *va = aux;
501 1.7 drochner vme_chipset_tag_t ct = va->va_vct;
502 1.7 drochner struct ie_softc *sc;
503 1.1 pk vme_intr_handle_t ih;
504 1.7 drochner vme_addr_t rampaddr;
505 1.7 drochner vme_size_t memsize;
506 1.7 drochner vme_mapresc_t resc;
507 1.7 drochner int lcv;
508 1.1 pk
509 1.7 drochner vme_am_t mod;
510 1.1 pk
511 1.1 pk /*
512 1.1 pk * *note*: we don't detect the difference between a VME3E and
513 1.1 pk * a multibus/vme card. if you want to use a 3E you'll have
514 1.1 pk * to fix this.
515 1.1 pk */
516 1.7 drochner mod = 0x3d; /* VME_AM_A24|VME_AM_MBO|VME_AM_SUPER|VME_AM_DATA */
517 1.7 drochner if (vme_space_alloc(va->va_vct, va->r[0].offset,
518 1.7 drochner sizeof(struct ievme), mod) ||
519 1.7 drochner vme_space_alloc(va->va_vct, va->r[1].offset,
520 1.7 drochner va->r[1].size, mod))
521 1.7 drochner panic("if_ie: vme alloc");
522 1.1 pk
523 1.7 drochner sc = &vsc->ie;
524 1.1 pk
525 1.1 pk sc->hwreset = ie_vmereset;
526 1.1 pk sc->hwinit = ie_vmerun;
527 1.1 pk sc->chan_attn = ie_vmeattend;
528 1.1 pk sc->intrhook = ie_vmeintr;
529 1.2 pk sc->memcopyout = ie_memcopyout;
530 1.2 pk sc->memcopyin = ie_memcopyin;
531 1.12 bjh21
532 1.12 bjh21 sc->ie_bus_barrier = NULL;
533 1.2 pk sc->ie_bus_read16 = ie_vme_read16;
534 1.2 pk sc->ie_bus_write16 = ie_vme_write16;
535 1.2 pk sc->ie_bus_write24 = ie_vme_write24;
536 1.1 pk
537 1.7 drochner memsize = va->r[1].size;
538 1.7 drochner
539 1.7 drochner if (vme_space_map(ct, va->r[0].offset, sizeof(struct ievme), mod,
540 1.7 drochner VME_D16 | VME_D8, 0,
541 1.7 drochner &vsc->ievt, &vsc->ievh, &resc) != 0)
542 1.7 drochner panic("if_ie: vme map csr");
543 1.7 drochner
544 1.7 drochner rampaddr = va->r[1].offset;
545 1.1 pk
546 1.1 pk /* 4 more */
547 1.7 drochner rampaddr = rampaddr | ((read_iev(vsc, status) & IEVME_HADDR) << 16);
548 1.7 drochner if (vme_space_map(ct, rampaddr, memsize, mod, VME_D16 | VME_D8, 0,
549 1.7 drochner &sc->bt, &sc->bh, &resc) != 0)
550 1.7 drochner panic("if_ie: vme map mem");
551 1.1 pk
552 1.7 drochner write_iev(vsc, pectrl, read_iev(vsc, pectrl) | IEVME_PARACK);
553 1.1 pk
554 1.1 pk /*
555 1.1 pk * Set up mappings, direct map except for last page
556 1.1 pk * which is mapped at zero and at high address (for scp)
557 1.1 pk */
558 1.1 pk for (lcv = 0; lcv < IEVME_MAPSZ - 1; lcv++)
559 1.7 drochner write_iev(vsc, pgmap[lcv], IEVME_SBORDR | IEVME_OBMEM | lcv);
560 1.7 drochner write_iev(vsc, pgmap[IEVME_MAPSZ - 1], IEVME_SBORDR | IEVME_OBMEM | 0);
561 1.1 pk
562 1.1 pk /* Clear all ram */
563 1.7 drochner bus_space_set_region_2(sc->bt, sc->bh, 0, 0, memsize/2);
564 1.1 pk
565 1.1 pk /*
566 1.2 pk * We use the first page to set up SCP, ICSP and SCB data
567 1.2 pk * structures. The remaining pages become the buffer area
568 1.2 pk * (managed in i82586.c).
569 1.2 pk * SCP is in double-mapped page, so the 586 can see it at
570 1.2 pk * the mandatory magic address (IE_SCP_ADDR).
571 1.1 pk */
572 1.2 pk sc->scp = (IE_SCP_ADDR & (IEVME_PAGESIZE - 1));
573 1.1 pk
574 1.1 pk /* iscp at location zero */
575 1.2 pk sc->iscp = 0;
576 1.1 pk
577 1.1 pk /* scb follows iscp */
578 1.2 pk sc->scb = IE_ISCP_SZ;
579 1.2 pk
580 1.2 pk ie_vme_write16(sc, IE_ISCP_SCB((long)sc->iscp), sc->scb);
581 1.2 pk ie_vme_write16(sc, IE_ISCP_BASE((u_long)sc->iscp), 0);
582 1.2 pk ie_vme_write24(sc, IE_SCP_ISCP((u_long)sc->scp), 0);
583 1.2 pk
584 1.2 pk if (i82586_proberam(sc) == 0) {
585 1.2 pk printf(": memory probe failed\n");
586 1.2 pk return;
587 1.2 pk }
588 1.1 pk
589 1.1 pk /*
590 1.1 pk * Rest of first page is unused; rest of ram for buffers.
591 1.1 pk */
592 1.2 pk sc->buf_area = IEVME_PAGESIZE;
593 1.7 drochner sc->buf_area_sz = memsize - IEVME_PAGESIZE;
594 1.1 pk
595 1.2 pk sc->do_xmitnopchain = 0;
596 1.2 pk
597 1.7 drochner printf("\n%s:", self->dv_xname);
598 1.7 drochner
599 1.9 chs #ifdef __sparc__
600 1.18 pk prom_getether(0, myaddr);
601 1.7 drochner #endif
602 1.2 pk i82586_attach(sc, "multibus/vme", myaddr, media, NMEDIA, media[0]);
603 1.1 pk
604 1.7 drochner vme_intr_map(ct, va->ilevel, va->ivector, &ih);
605 1.7 drochner vme_intr_establish(ct, ih, IPL_NET, i82586_intr, sc);
606 1.1 pk }
607