1 /* $NetBSD: obio.c,v 1.31 2008/04/28 20:23:38 martin Exp $ */
4 * Copyright (c) 1996 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Adam Glass and Gordon W. Ross.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: obio.c,v 1.31 2008/04/28 20:23:38 martin Exp $");
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/device.h>
39 #include <uvm/uvm_extern.h>
41 #define _SUN68K_BUS_DMA_PRIVATE
42 #include <machine/autoconf.h>
43 #include <machine/bus.h>
44 #include <machine/dvma.h>
45 #include <machine/mon.h>
46 #include <machine/pte.h>
48 #include <sun3/sun3/machdep.h>
49 #include <sun3/sun3x/obio.h>
51 static int obio_match(device_t
, cfdata_t
, void *);
52 static void obio_attach(device_t
, device_t
, void *);
53 static int obio_print(void *, const char *);
54 static int obio_submatch(device_t
, cfdata_t
, const int *, void *);
58 bus_space_tag_t sc_bustag
;
59 bus_dma_tag_t sc_dmatag
;
61 CFATTACH_DECL_NEW(obio
, sizeof(struct obio_softc
),
62 obio_match
, obio_attach
, NULL
, NULL
);
64 static int obio_attached
;
66 static int obio_bus_map(bus_space_tag_t
, bus_type_t
, bus_addr_t
, bus_size_t
,
67 int, vaddr_t
, bus_space_handle_t
*);
68 static paddr_t
obio_bus_mmap(bus_space_tag_t
, bus_type_t
, bus_addr_t
,
70 static int obio_dmamap_load(bus_dma_tag_t
, bus_dmamap_t
, void *, bus_size_t
,
73 static struct sun68k_bus_space_tag obio_space_tag
= {
75 NULL
, /* parent bus space tag */
76 obio_bus_map
, /* bus_space_map */
77 NULL
, /* bus_space_unmap */
78 NULL
, /* bus_space_subregion */
79 NULL
, /* bus_space_barrier */
80 obio_bus_mmap
, /* bus_space_mmap */
81 NULL
, /* bus_intr_establish */
82 NULL
, /* bus_space_peek_N */
83 NULL
/* bus_space_poke_N */
86 static struct sun68k_bus_dma_tag obio_dma_tag
;
89 obio_match(device_t parent
, cfdata_t cf
, void *aux
)
91 struct confargs
*ca
= aux
;
96 if (ca
->ca_bustype
!= BUS_OBIO
)
99 if (ca
->ca_name
!= NULL
&& strcmp(cf
->cf_name
, ca
->ca_name
) != 0)
106 * We need control over the order of attachment on OBIO,
107 * so do "direct" style autoconfiguration with addresses
108 * from the list below. OBIO addresses are fixed forever.
110 * Warning: This whole list is very carefully ordered!
111 * In general, anything not already shown here should
112 * be added at or near the end.
114 static paddr_t obio_alist
[] = {
116 /* This is used by the Ethernet and SCSI drivers. */
119 /* Misc. registers - needed by many things */
122 OBIO_DIAGREG
, /* leds.c */
123 OBIO_IDPROM1
, /* idprom.c (3/470) */
124 OBIO_MEMREG
, /* memerr.c */
125 OBIO_INTERREG
, /* intreg.c */
134 /* Note: This must come after OBIO_IDPROM1. */
135 OBIO_IDPROM2
, /* idprom.c (3/80) */
137 /* Note: Must probe for the Intersil first! */
138 OBIO_CLOCK1
, /* clock.c (3/470) */
139 OBIO_CLOCK2
, /* clock.c (3/80) */
144 /* Need esp DMA before SCSI. */
145 OBIO_EMULEX_DMA
, /* 3/80 only */
146 OBIO_EMULEX_SCSI
, /* 3/80 only */
148 /* Memory subsystem */
154 OBIO_FDC
, /* floppy disk (3/80) */
155 OBIO_PRINTER_PORT
, /* printer port (3/80) */
157 #define OBIO_ALIST_LEN __arraycount(obio_alist)
160 obio_attach(struct device
*parent
, struct device
*self
, void *aux
)
162 struct confargs
*ca
= aux
;
163 struct obio_softc
*sc
= device_private(self
);
172 sc
->sc_bustag
= ca
->ca_bustag
;
173 sc
->sc_dmatag
= ca
->ca_dmatag
;
175 obio_space_tag
.cookie
= sc
;
176 obio_space_tag
.parent
= sc
->sc_bustag
;
178 obio_dma_tag
= *sc
->sc_dmatag
;
179 obio_dma_tag
._cookie
= sc
;
180 obio_dma_tag
._dmamap_load
= obio_dmamap_load
;
183 oba
.ca_bustag
= &obio_space_tag
;
184 oba
.ca_dmatag
= &obio_dma_tag
;
186 /* Configure these in the order listed above. */
187 for (i
= 0; i
< OBIO_ALIST_LEN
; i
++) {
188 /* Our parent set ca->ca_bustype already. */
189 oba
.ca_paddr
= obio_alist
[i
];
190 /* These are filled-in by obio_submatch. */
193 (void)config_found_sm_loc(self
, "obio", NULL
, &oba
, obio_print
,
199 * Print out the confargs. The (parent) name is non-NULL
200 * when there was no match found by config_found().
203 obio_print(void *args
, const char *name
)
206 /* Be quiet about empty OBIO locations. */
210 /* Otherwise do the usual. */
211 return bus_print(args
, name
);
215 obio_submatch(device_t parent
, cfdata_t cf
, const int *ldesc
, void *aux
)
217 struct confargs
*ca
= aux
;
220 * Note that a defaulted address locator can never match
221 * the value of ca->ca_paddr set by the obio_attach loop.
222 * Without this diagnostic, any device with a defaulted
223 * address locator would always be silently unmatched.
224 * Therefore, just disallow default addresses on OBIO.
227 if (cf
->cf_paddr
== -1)
228 panic("%s: invalid address for: %s%d",
229 __func__
, cf
->cf_name
, cf
->cf_unit
);
233 * Note that obio_attach calls config_found_sm() with
234 * this function as the "submatch" and ca->ca_paddr
235 * set to each of the possible OBIO locations, so we
236 * want to reject any unmatched address here.
238 if (cf
->cf_paddr
!= ca
->ca_paddr
)
242 * Copy the locators into our confargs for the child.
243 * Note: ca->ca_bustype was set by our parent driver
244 * (mainbus) and ca->ca_paddr was set by obio_attach.
246 ca
->ca_intpri
= cf
->cf_intpri
;
247 ca
->ca_intvec
= cf
->cf_intvec
;
249 /* Now call the match function of the potential child. */
250 return config_match(parent
, cf
, aux
);
254 /*****************************************************************/
257 * This is our record of "interesting" OBIO mappings that
258 * the PROM has left in the virtual space reserved for it.
259 * Each row of the array holds a virtual address and the
260 * physical address it maps to (if found).
262 static struct prom_map
{
265 } prom_mappings
[] = {
266 { OBIO_ENABLEREG
, 0 }, /* regs: Sys ENA, Bus ERR, etc. */
267 { OBIO_ZS_KBD_MS
, 0 }, /* Keyboard and Mouse */
268 { OBIO_ZS_TTY_AB
, 0 }, /* Serial Ports */
269 { OBIO_EEPROM
, 0 }, /* EEPROM/IDPROM/clock */
271 #define PROM_MAP_CNT __arraycount(prom_mappings)
274 * Find a virtual address for a device at physical address 'pa'.
275 * If one is found among the mappings already made by the PROM
276 * at power-up time, use it and return 0. Otherwise return errno
277 * as a sign that a mapping will have to be created.
280 find_prom_map(paddr_t pa
, bus_type_t iospace
, int sz
, vaddr_t
*vap
)
289 /* The saved mappings are all one page long. */
293 /* Linear search for it. The list is short. */
294 for (i
= 0; i
< PROM_MAP_CNT
; i
++) {
295 if (pa
== prom_mappings
[i
].pa
) {
296 *vap
= prom_mappings
[i
].va
+ off
;
304 * Search the PROM page tables for OBIO mappings that
305 * we would like to borrow.
308 save_prom_mappings(void)
315 /* Note: mon_ctbl[0] maps SUN3X_MON_KDB_BASE */
316 mon_pte
= *romVectorPtr
->monptaddr
;
318 for (va
= SUN3X_MON_KDB_BASE
; va
< SUN3X_MONEND
;
319 va
+= PAGE_SIZE
, mon_pte
++) {
320 /* Is this a valid mapping to OBIO? */
321 /* XXX - Some macros would be nice... */
322 if ((*mon_pte
& 0xF0000003) != 0x60000001)
325 /* Yes it is. Is this a mapping we want? */
326 pa
= *mon_pte
& MMU_SHORT_PTE_BASEADDR
;
327 for (i
= 0; i
< PROM_MAP_CNT
; i
++) {
328 if (pa
!= prom_mappings
[i
].pa
)
330 /* Yes, we want it. Save the va? */
331 if (prom_mappings
[i
].va
== 0) {
332 prom_mappings
[i
].va
= va
;
339 * These are all the OBIO address that are required early in
340 * the life of the kernel. All are less than one page long.
341 * This function should make any required mappings that we
342 * were not able to find among the PROM monitor's mappings.
345 make_required_mappings(void)
349 for (i
= 0; i
< PROM_MAP_CNT
; i
++) {
350 if (prom_mappings
[i
].va
== 0) {
352 * Actually, the PROM always has all the
353 * "required" mappings we need, (smile)
354 * but this makes sure that is true.
356 mon_printf("obio: no mapping for pa=0x%x\n",
357 prom_mappings
[i
].pa
);
358 sunmon_abort(); /* Ancient PROM? */
365 * Find mappings for devices that are needed before autoconfiguration.
366 * We first look for and record any useful PROM mappings, then call
367 * the "init" functions for drivers that we need to use before the
368 * normal autoconfiguration calls configure(). Warning: this is
369 * called before pmap_bootstrap, so no allocation allowed!
375 save_prom_mappings();
376 make_required_mappings();
381 * Find the interrupt reg mapping and turn off the
382 * interrupts, otherwise the PROM clock interrupt
383 * would poll the zs and toggle some LEDs...
389 obio_bus_map(bus_space_tag_t t
, bus_type_t btype
, bus_addr_t paddr
,
390 bus_size_t size
, int flags
, vaddr_t vaddr
, bus_space_handle_t
*hp
)
392 struct obio_softc
*sc
= t
->cookie
;
394 return bus_space_map2(sc
->sc_bustag
, PMAP_OBIO
, paddr
, size
,
395 flags
| _SUN68K_BUS_MAP_USE_PROM
, vaddr
, hp
);
399 obio_bus_mmap(bus_space_tag_t t
, bus_type_t btype
, bus_addr_t paddr
, off_t off
,
402 struct obio_softc
*sc
= t
->cookie
;
404 return bus_space_mmap2(sc
->sc_bustag
, PMAP_OBIO
, paddr
, off
, prot
,
409 obio_dmamap_load(bus_dma_tag_t t
, bus_dmamap_t map
, void *buf
,
410 bus_size_t buflen
, struct proc
*p
, int flags
)
414 error
= _bus_dmamap_load(t
, map
, buf
, buflen
, p
, flags
);
416 map
->dm_segs
[0].ds_addr
&= DVMA_OBIO_SLAVE_MASK
;