rmixl_obio.c revision 1.3 1 /* $NetBSD: rmixl_obio.c,v 1.3 2011/02/20 07:48:37 matt Exp $ */
2
3 /*
4 * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc.
5 * All rights reserved.
6 *
7 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed for the NetBSD Project by
20 * Wasabi Systems, Inc.
21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 * or promote products derived from this software without specific prior
23 * written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 */
37
38 /*
39 * On-board device autoconfiguration support for RMI {XLP, XLR, XLS} chips
40 */
41
42 #include <sys/cdefs.h>
43 __KERNEL_RCSID(0, "$NetBSD: rmixl_obio.c,v 1.3 2011/02/20 07:48:37 matt Exp $");
44
45 #include "locators.h"
46 #include "pci.h"
47
48 #include <sys/param.h>
49 #include <sys/systm.h>
50 #include <sys/device.h>
51 #include <sys/extent.h>
52 #include <sys/malloc.h>
53
54 #define _MIPS_BUS_DMA_PRIVATE
55 #include <machine/bus.h>
56
57 #include <machine/int_fmtio.h>
58
59 #include <mips/rmi/rmixlreg.h>
60 #include <mips/rmi/rmixlvar.h>
61 #include <mips/rmi/rmixl_intr.h>
62 #include <mips/rmi/rmixl_obiovar.h>
63 #include <mips/rmi/rmixl_pcievar.h>
64
65 #include <evbmips/rmixl/autoconf.h>
66
67 #ifdef OBIO_DEBUG
68 int obio_rmixl_debug = OBIO_DEBUG;
69 # define DPRINTF(x) do { if (obio_rmixl_debug) printf x ; } while (0)
70 #else
71 # define DPRINTF(x)
72 #endif
73
74 static int obio_match(device_t, cfdata_t, void *);
75 static void obio_attach(device_t, device_t, void *);
76 static int obio_print(void *, const char *);
77 static int obio_search(device_t, cfdata_t, const int *, void *);
78 static void obio_bus_init(struct obio_softc *);
79 static void obio_dma_init_64(bus_dma_tag_t);
80 static int rmixl_addr_error_intr(void *);
81
82
83 CFATTACH_DECL_NEW(obio_rmixl, sizeof(struct obio_softc),
84 obio_match, obio_attach, NULL, NULL);
85
86 int obio_found;
87
88 static int
89 obio_match(device_t parent, cfdata_t cf, void *aux)
90 {
91 struct mainbus_attach_args *aa = aux;
92
93 if (obio_found == 0)
94 if (strncmp(aa->ma_name, cf->cf_name, strlen(cf->cf_name)) == 0)
95 return 1;
96
97 return 0;
98 }
99
100 static void
101 obio_attach(device_t parent, device_t self, void *aux)
102 {
103 struct obio_softc *sc = device_private(self);
104 bus_addr_t ba;
105
106 obio_found = 1;
107 sc->sc_dev = self;
108
109 ba = (bus_addr_t)rmixl_configuration.rc_io_pbase;
110 KASSERT(ba != 0);
111
112 obio_bus_init(sc);
113
114 aprint_normal(" addr %#"PRIxBUSADDR" size %#"PRIxBUSSIZE"\n",
115 ba, (bus_size_t)RMIXL_IO_DEV_SIZE);
116 aprint_naive("\n");
117
118 /*
119 * Attach on-board devices as specified in the kernel config file.
120 */
121 config_search_ia(obio_search, self, "obio", NULL);
122
123 }
124
125 static int
126 obio_print(void *aux, const char *pnp)
127 {
128 struct obio_attach_args *obio = aux;
129
130 if (obio->obio_addr != OBIOCF_ADDR_DEFAULT) {
131 aprint_normal(" addr %#"PRIxBUSADDR, obio->obio_addr);
132 if (obio->obio_size != OBIOCF_SIZE_DEFAULT)
133 aprint_normal("-%#"PRIxBUSADDR,
134 obio->obio_addr + (obio->obio_size - 1));
135 }
136 if (obio->obio_mult != OBIOCF_MULT_DEFAULT)
137 aprint_normal(" mult %d", obio->obio_mult);
138 if (obio->obio_intr != OBIOCF_INTR_DEFAULT)
139 aprint_normal(" intr %d", obio->obio_intr);
140 if (obio->obio_tmsk != OBIOCF_TMSK_DEFAULT)
141 aprint_normal(" tmsk %d", obio->obio_tmsk);
142
143 return (UNCONF);
144 }
145
146 static int
147 obio_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
148 {
149 struct obio_softc *sc = device_private(parent);
150 struct obio_attach_args obio;
151
152 obio.obio_eb_bst = sc->sc_eb_bst;
153 obio.obio_el_bst = sc->sc_el_bst;
154 obio.obio_addr = cf->cf_loc[OBIOCF_ADDR];
155 obio.obio_size = cf->cf_loc[OBIOCF_SIZE];
156 obio.obio_mult = cf->cf_loc[OBIOCF_MULT];
157 obio.obio_intr = cf->cf_loc[OBIOCF_INTR];
158 obio.obio_tmsk = cf->cf_loc[OBIOCF_TMSK];
159 obio.obio_29bit_dmat = sc->sc_29bit_dmat;
160 obio.obio_32bit_dmat = sc->sc_32bit_dmat;
161 obio.obio_64bit_dmat = sc->sc_64bit_dmat;
162
163 if (config_match(parent, cf, &obio) > 0)
164 config_attach(parent, cf, &obio, obio_print);
165
166 return 0;
167 }
168
169 static void
170 obio_bus_init(struct obio_softc *sc)
171 {
172 struct rmixl_config *rcp = &rmixl_configuration;
173 static int done = 0;
174 int error;
175
176 if (done)
177 return;
178 done = 1;
179
180 /* obio (devio) space, Big Endian */
181 if (rcp->rc_obio_eb_memt.bs_cookie == 0)
182 rmixl_obio_eb_bus_mem_init(&rcp->rc_obio_eb_memt, rcp);
183
184 /* obio (devio) space, Little Endian */
185 if (rcp->rc_obio_el_memt.bs_cookie == 0)
186 rmixl_obio_el_bus_mem_init(&rcp->rc_obio_el_memt, rcp);
187
188 /* dma space for all memory, including >= 4GB */
189 if (rcp->rc_dma_tag._cookie == 0)
190 obio_dma_init_64(&rcp->rc_dma_tag);
191 rcp->rc_64bit_dmat = &rcp->rc_dma_tag;
192
193 /* dma space for addr < 4GB */
194 if (rcp->rc_32bit_dmat == NULL) {
195 error = bus_dmatag_subregion(rcp->rc_64bit_dmat,
196 0, (bus_addr_t)1 << 32, &rcp->rc_32bit_dmat, 0);
197 if (error)
198 panic("%s: failed to create 32bit dma tag: %d",
199 __func__, error);
200 }
201
202 /* dma space for addr < 512MB */
203 if (rcp->rc_29bit_dmat == NULL) {
204 error = bus_dmatag_subregion(rcp->rc_32bit_dmat,
205 0, (bus_addr_t)1 << 29, &rcp->rc_29bit_dmat, 0);
206 if (error)
207 panic("%s: failed to create 29bit dma tag: %d",
208 __func__, error);
209 }
210
211 sc->sc_base = (bus_addr_t)rcp->rc_io_pbase;
212 sc->sc_size = (bus_size_t)RMIXL_IO_DEV_SIZE;
213 sc->sc_eb_bst = (bus_space_tag_t)&rcp->rc_obio_eb_memt;
214 sc->sc_el_bst = (bus_space_tag_t)&rcp->rc_obio_el_memt;
215 sc->sc_29bit_dmat = rcp->rc_29bit_dmat;
216 sc->sc_32bit_dmat = rcp->rc_32bit_dmat;
217 sc->sc_64bit_dmat = rcp->rc_64bit_dmat;
218 }
219
220 static void
221 obio_dma_init_64(bus_dma_tag_t t)
222 {
223 t->_cookie = t;
224 t->_wbase = 0;
225 t->_bounce_alloc_lo = 0;
226 t->_bounce_alloc_hi = 0;
227 t->_dmamap_ops = mips_bus_dmamap_ops;
228 t->_dmamem_ops = mips_bus_dmamem_ops;
229 t->_dmatag_ops = mips_bus_dmatag_ops;
230 }
231
232 void
233 rmixl_addr_error_init(void)
234 {
235 uint32_t r;
236
237 /*
238 * activate error addr detection on all (configurable) devices
239 * preserve reserved bit fields
240 * note some of these bits are read-only (writes are ignored)
241 */
242 r = RMIXL_IOREG_READ(RMIXL_ADDR_ERR_DEVICE_MASK);
243 r |= ~(__BITS(19,16) | __BITS(10,9) | __BITS(7,5));
244 RMIXL_IOREG_WRITE(RMIXL_ADDR_ERR_DEVICE_MASK, r);
245
246 /*
247 * enable the address error interrupts
248 * "upgrade" cache and CPU errors to A1
249 */
250 #define _ADDR_ERR_DEVSTAT_A1 (__BIT(8) | __BIT(1) | __BIT(0))
251 #define _ADDR_ERR_RESV \
252 (__BITS(31,21) | __BITS(15,14) | __BITS(10,9) | __BITS(7,2))
253 #define _BITERR_INT_EN_RESV (__BITS(31,8) | __BIT(4))
254
255 r = RMIXL_IOREG_READ(RMIXL_ADDR_ERR_AERR0_EN);
256 r &= _ADDR_ERR_RESV;
257 r |= ~_ADDR_ERR_RESV;
258 RMIXL_IOREG_WRITE(RMIXL_ADDR_ERR_AERR0_EN, r);
259
260 r = RMIXL_IOREG_READ(RMIXL_ADDR_ERR_AERR0_UPG);
261 r &= _ADDR_ERR_RESV;
262 r |= _ADDR_ERR_DEVSTAT_A1;
263 RMIXL_IOREG_WRITE(RMIXL_ADDR_ERR_AERR0_UPG, r);
264
265 /*
266 * clear the log regs and the dev stat (interrupt status) regs
267 * "Write any value to bit[0] to clear"
268 */
269 r = RMIXL_IOREG_READ(RMIXL_ADDR_ERR_AERR1_CLEAR);
270 RMIXL_IOREG_WRITE(RMIXL_ADDR_ERR_AERR1_CLEAR, r);
271
272 /*
273 * enable the double bit error interrupts
274 * (assume reserved bits, which are read-only, are ignored)
275 */
276 r = RMIXL_IOREG_READ(RMIXL_ADDR_ERR_BITERR_INT_EN);
277 r &= _BITERR_INT_EN_RESV;
278 r |= __BITS(7,5);
279 RMIXL_IOREG_WRITE(RMIXL_ADDR_ERR_BITERR_INT_EN, r);
280
281 /*
282 * establish address error ISR
283 * XXX assuming "int 16 (bridge_tb)" is our irq
284 * XXX is true for XLS family only
285 */
286 if (cpu_rmixls(mips_options.mips_cpu))
287 rmixl_intr_establish(16, 1, IPL_HIGH,
288 RMIXL_TRIG_LEVEL, RMIXL_POLR_HIGH,
289 rmixl_addr_error_intr, NULL, false);
290 }
291
292 int
293 rmixl_addr_error_check(void)
294 {
295 uint32_t aerr0_devstat;
296 uint32_t aerr0_log1;
297 uint32_t aerr0_log2;
298 uint32_t aerr0_log3;
299 uint32_t aerr1_devstat;
300 uint32_t aerr1_log1;
301 uint32_t aerr1_log2;
302 uint32_t aerr1_log3;
303 uint32_t sbe_counts;
304 uint32_t dbe_counts;
305
306 aerr0_devstat = RMIXL_IOREG_READ(RMIXL_ADDR_ERR_AERR0_DEVSTAT);
307 aerr0_log1 = RMIXL_IOREG_READ(RMIXL_ADDR_ERR_AERR0_LOG1);
308 aerr0_log2 = RMIXL_IOREG_READ(RMIXL_ADDR_ERR_AERR0_LOG2);
309 aerr0_log3 = RMIXL_IOREG_READ(RMIXL_ADDR_ERR_AERR0_LOG3);
310
311 aerr1_devstat = RMIXL_IOREG_READ(RMIXL_ADDR_ERR_AERR1_DEVSTAT);
312 aerr1_log1 = RMIXL_IOREG_READ(RMIXL_ADDR_ERR_AERR1_LOG1);
313 aerr1_log2 = RMIXL_IOREG_READ(RMIXL_ADDR_ERR_AERR1_LOG2);
314 aerr1_log3 = RMIXL_IOREG_READ(RMIXL_ADDR_ERR_AERR1_LOG3);
315
316 sbe_counts = RMIXL_IOREG_READ(RMIXL_ADDR_ERR_SBE_COUNTS);
317 dbe_counts = RMIXL_IOREG_READ(RMIXL_ADDR_ERR_DBE_COUNTS);
318
319 if (aerr0_log1|aerr0_log2|aerr0_log3
320 |aerr1_log1|aerr1_log2|aerr1_log3
321 |dbe_counts) {
322 printf("aerr0: stat %#x, logs: %#x, %#x, %#x\n",
323 aerr0_devstat, aerr0_log1, aerr0_log2, aerr0_log2);
324 printf("aerr1: stat %#x, logs: %#x, %#x, %#x\n",
325 aerr1_devstat, aerr1_log1, aerr1_log2, aerr1_log2);
326 printf("1-bit errors: %#x, 2-bit errors: %#x\n",
327 sbe_counts, dbe_counts);
328 return 1;
329 }
330 return 0;
331 }
332
333 static int
334 rmixl_addr_error_intr(void *arg)
335 {
336 int err;
337
338 err = rmixl_addr_error_check();
339 if (err != 0) {
340 #if DDB
341 printf("%s\n", __func__);
342 Debugger();
343 #endif
344 panic("Address Error");
345 }
346 return 1;
347 }
348