xref: /netbsd-src/sys/arch/sun3/dev/if_ie_obio.c (revision 03daa790ebb1227f96803546c28ec9033628154d)
1 /*	$NetBSD: if_ie_obio.c,v 1.26 2024/12/20 23:52:00 tsutsui 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  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 /*
33  * Machine-dependent glue for the Intel Ethernet (ie) driver.
34  */
35 
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: if_ie_obio.c,v 1.26 2024/12/20 23:52:00 tsutsui Exp $");
38 
39 #include "opt_inet.h"
40 
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/device.h>
44 #include <sys/protosw.h>
45 #include <sys/socket.h>
46 #include <net/if.h>
47 #include <net/if_ether.h>
48 
49 #ifdef INET
50 #include <netinet/in.h>
51 #include <netinet/in_systm.h>
52 #include <netinet/in_var.h>
53 #include <netinet/ip.h>
54 #include <netinet/if_inarp.h>
55 #endif
56 
57 #include <machine/autoconf.h>
58 #include <machine/cpu.h>
59 #include <machine/dvma.h>
60 #include <machine/idprom.h>
61 #include <machine/vmparam.h>
62 
63 #include "i82586.h"
64 #include "if_iereg.h"
65 #include "if_ievar.h"
66 
67 static void ie_obreset(struct ie_softc *);
68 static void ie_obattend(struct ie_softc *);
69 static void ie_obrun(struct ie_softc *);
70 
71 /*
72  * New-style autoconfig attachment
73  */
74 
75 static int  ie_obio_match(device_t, cfdata_t, void *);
76 static void ie_obio_attach(device_t, device_t, void *);
77 
78 CFATTACH_DECL_NEW(ie_obio, sizeof(struct ie_softc),
79     ie_obio_match, ie_obio_attach, NULL, NULL);
80 
81 static int
82 ie_obio_match(device_t parent, cfdata_t cf, void *args)
83 {
84 	struct confargs *ca = args;
85 
86 	/* Make sure there is something there... */
87 	if (bus_peek(ca->ca_bustype, ca->ca_paddr, 1) == -1)
88 		return 0;
89 
90 	/* Default interrupt priority. */
91 	if (ca->ca_intpri == -1)
92 		ca->ca_intpri = 3;
93 
94 	return 1;
95 }
96 
97 void
98 ie_obio_attach(device_t parent, device_t self, void *args)
99 {
100 	struct ie_softc *sc = device_private(self);
101 	struct confargs *ca = args;
102 
103 	sc->sc_dev = self;
104 	sc->hard_type = IE_OBIO;
105 	sc->reset_586 = ie_obreset;
106 	sc->chan_attn = ie_obattend;
107 	sc->run_586 = ie_obrun;
108 	sc->sc_memcpy = memcpy;
109 	sc->sc_memset = memset;
110 
111 	/* Map in the control registers. */
112 	sc->sc_reg = bus_mapin(ca->ca_bustype,
113 	    ca->ca_paddr, sizeof(struct ieob));
114 
115 	/*
116 	 * The on-board "ie" is wired-up such that its
117 	 * memory access goes to the high 16 megabytes
118 	 * of the on-board memory space (on-board DVMA).
119 	 */
120 	sc->sc_iobase = (void *)DVMA_OBIO_SLAVE_BASE;
121 
122 	/*
123 	 * The on-board "ie" just uses main memory, so
124 	 * we can choose how much memory to give it.
125 	 * XXX: Would like to use less than 64K...
126 	 */
127 	sc->sc_msize = 0x8000; /* MEMSIZE 32K */
128 
129 	/* Allocate "shared" memory (in DVMA space). */
130 	sc->sc_maddr = dvma_malloc(sc->sc_msize);
131 	if (sc->sc_maddr == NULL)
132 		panic(": not enough dvma space");
133 
134 	/*
135 	 * Set the System Configuration Pointer (SCP).
136 	 * Its location is system-dependent because the
137 	 * i82586 reads it from a fixed physical address.
138 	 * On this hardware, the i82586 address maps to
139 	 * a 24-bit offset in on-board DVMA space. The
140 	 * SCP happens to fall in a page used by the
141 	 * PROM monitor, which the PROM knows about.
142 	 */
143 	sc->scp = (volatile void *)((char *)sc->sc_iobase + IE_SCP_ADDR);
144 
145 	/*
146 	 * The rest of ram is used for buffers.
147 	 */
148 	sc->buf_area    = sc->sc_maddr;
149 	sc->buf_area_sz = sc->sc_msize;
150 
151 	/* Install interrupt handler. */
152 	isr_add_autovect(ie_intr, sc, ca->ca_intpri);
153 
154 	/* Set the ethernet address. */
155 	idprom_etheraddr(sc->sc_addr);
156 
157 	/* Do machine-independent parts of attach. */
158 	ie_attach(sc);
159 }
160 
161 
162 /*
163  * onboard ie support
164  */
165 
166 /* Whack the "channel attetion" line. */
167 void
168 ie_obattend(struct ie_softc *sc)
169 {
170 	volatile struct ieob *ieo = (struct ieob *)sc->sc_reg;
171 
172 	ieo->obctrl |= IEOB_ATTEN;	/* flag! */
173 	ieo->obctrl &= ~IEOB_ATTEN;	/* down. */
174 }
175 
176 /*
177  * This is called during driver attach.
178  * Reset and initialize.
179  */
180 void
181 ie_obreset(struct ie_softc *sc)
182 {
183 	volatile struct ieob *ieo = (struct ieob *)sc->sc_reg;
184 	ieo->obctrl = 0;
185 	delay(20);
186 	ieo->obctrl = (IEOB_NORSET | IEOB_ONAIR | IEOB_IENAB);
187 }
188 
189 /*
190  * This is called at the end of ieinit().
191  * optional.
192  */
193 void
194 ie_obrun(struct ie_softc *sc)
195 {
196 
197 	/* do it all in reset */
198 }
199