xref: /netbsd-src/sys/arch/sun3/dev/if_ie_obio.c (revision 7c7c171d130af9949261bc7dce2150a03c3d239c)
1 /*	$NetBSD: if_ie_obio.c,v 1.13 1998/02/05 04:56:41 gwr Exp $	*/
2 
3 /*-
4  * Copyright (c) 1996 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Gordon W. Ross.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *        This product includes software developed by the NetBSD
21  *        Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 /*
40  * Machine-dependent glue for the Intel Ethernet (ie) driver.
41  */
42 
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/device.h>
46 #include <sys/protosw.h>
47 #include <sys/socket.h>
48 #include <net/if.h>
49 #include <net/if_ether.h>
50 
51 #ifdef INET
52 #include <netinet/in.h>
53 #include <netinet/in_systm.h>
54 #include <netinet/in_var.h>
55 #include <netinet/ip.h>
56 #include <netinet/if_inarp.h>
57 #endif
58 
59 #include <machine/autoconf.h>
60 #include <machine/cpu.h>
61 #include <machine/dvma.h>
62 #include <machine/idprom.h>
63 #include <machine/vmparam.h>
64 
65 #include "i82586.h"
66 #include "if_iereg.h"
67 #include "if_ievar.h"
68 
69 static void ie_obreset __P((struct ie_softc *));
70 static void ie_obattend __P((struct ie_softc *));
71 static void ie_obrun __P((struct ie_softc *));
72 
73 /*
74  * New-style autoconfig attachment
75  */
76 
77 static int  ie_obio_match __P((struct device *, struct cfdata *, void *));
78 static void ie_obio_attach __P((struct device *, struct device *, void *));
79 
80 struct cfattach ie_obio_ca = {
81 	sizeof(struct ie_softc), ie_obio_match, ie_obio_attach
82 };
83 
84 
85 static int
86 ie_obio_match(parent, cf, args)
87 	struct device *parent;
88 	struct cfdata *cf;
89 	void *args;
90 {
91 	struct confargs *ca = args;
92 
93 	/* Make sure there is something there... */
94 	if (bus_peek(ca->ca_bustype, ca->ca_paddr, 1) == -1)
95 		return (0);
96 
97 	/* Default interrupt priority. */
98 	if (ca->ca_intpri == -1)
99 		ca->ca_intpri = 3;
100 
101 	return (1);
102 }
103 
104 void
105 ie_obio_attach(parent, self, args)
106 	struct device *parent;
107 	struct device *self;
108 	void *args;
109 {
110 	struct ie_softc *sc = (void *) self;
111 	struct confargs *ca = args;
112 
113 	sc->hard_type = IE_OBIO;
114 	sc->reset_586 = ie_obreset;
115 	sc->chan_attn = ie_obattend;
116 	sc->run_586 = ie_obrun;
117 	sc->sc_bcopy = bcopy;
118 	sc->sc_bzero = bzero;
119 
120 	/* Map in the control registers. */
121 	sc->sc_reg = bus_mapin(ca->ca_bustype,
122 		ca->ca_paddr, sizeof(struct ieob));
123 
124 	/*
125 	 * The on-board "ie" is wired-up such that its
126 	 * memory access goes to the high 16 megabytes
127 	 * of the on-board memory space (on-board DVMA).
128 	 */
129 	sc->sc_iobase = (caddr_t)DVMA_OBIO_SLAVE_BASE;
130 
131 	/*
132 	 * The on-board "ie" just uses main memory, so
133 	 * we can choose how much memory to give it.
134 	 * XXX: Would like to use less than 64K...
135 	 */
136 	sc->sc_msize = 0x8000; /* MEMSIZE 32K */
137 
138 	/* Allocate "shared" memory (in DVMA space). */
139 	sc->sc_maddr = dvma_malloc(sc->sc_msize);
140 	if (sc->sc_maddr == NULL)
141 		panic(": not enough dvma space");
142 
143 	/*
144 	 * Set the System Configuration Pointer (SCP).
145 	 * Its location is system-dependent because the
146 	 * i82586 reads it from a fixed physical address.
147 	 * On this hardware, the i82586 address maps to
148 	 * a 24-bit offset in on-board DVMA space. The
149 	 * SCP happens to fall in a page used by the
150 	 * PROM monitor, which the PROM knows about.
151 	 */
152 	sc->scp = (volatile void *) (sc->sc_iobase + IE_SCP_ADDR);
153 
154 	/*
155 	 * The rest of ram is used for buffers.
156 	 */
157 	sc->buf_area    = sc->sc_maddr;
158 	sc->buf_area_sz = sc->sc_msize;
159 
160 	/* Install interrupt handler. */
161 	isr_add_autovect(ie_intr, (void *)sc, ca->ca_intpri);
162 
163 	/* Set the ethernet address. */
164 	idprom_etheraddr(sc->sc_addr);
165 
166 	/* Do machine-independent parts of attach. */
167 	ie_attach(sc);
168 }
169 
170 
171 /*
172  * onboard ie support
173  */
174 
175 /* Whack the "channel attetion" line. */
176 void
177 ie_obattend(sc)
178 	struct ie_softc *sc;
179 {
180 	volatile struct ieob *ieo = (struct ieob *) sc->sc_reg;
181 
182 	ieo->obctrl |= IEOB_ATTEN;	/* flag! */
183 	ieo->obctrl &= ~IEOB_ATTEN;	/* down. */
184 }
185 
186 /*
187  * This is called during driver attach.
188  * Reset and initialize.
189  */
190 void
191 ie_obreset(sc)
192 	struct ie_softc *sc;
193 {
194 	volatile struct ieob *ieo = (struct ieob *) sc->sc_reg;
195 	ieo->obctrl = 0;
196 	delay(20);
197 	ieo->obctrl = (IEOB_NORSET | IEOB_ONAIR | IEOB_IENAB);
198 }
199 
200 /*
201  * This is called at the end of ieinit().
202  * optional.
203  */
204 void
205 ie_obrun(sc)
206 	struct ie_softc *sc;
207 {
208 	/* do it all in reset */
209 }
210 
211