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