1 /* $NetBSD: mbio.c,v 1.7 2001/12/15 22:13:11 fredette 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 Adam Glass, Gordon W. Ross, and Matthew Fredette. 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 #include <sys/param.h> 40 #include <sys/systm.h> 41 #include <sys/device.h> 42 43 #include <uvm/uvm_extern.h> 44 45 #include <machine/autoconf.h> 46 #include <machine/pmap.h> 47 48 #include <sun2/sun2/control.h> 49 #include <sun2/sun2/machdep.h> 50 #include <sun2/sun2/mbio.h> 51 52 /* Does this machine have a Multibus? */ 53 extern int cpu_has_multibus; 54 55 static int mbio_match __P((struct device *, struct cfdata *, void *)); 56 static void mbio_attach __P((struct device *, struct device *, void *)); 57 58 struct mbio_softc { 59 struct device sc_dev; /* base device */ 60 bus_space_tag_t sc_bustag; /* parent bus tag */ 61 bus_dma_tag_t sc_dmatag; /* parent bus dma tag */ 62 }; 63 64 struct cfattach mbio_ca = { 65 sizeof(struct mbio_softc), mbio_match, mbio_attach 66 }; 67 68 static paddr_t mbio_bus_mmap __P((bus_space_tag_t, bus_type_t, bus_addr_t, 69 off_t, int, int)); 70 static int _mbio_bus_map __P((bus_space_tag_t, bus_type_t, bus_addr_t, 71 bus_size_t, int, 72 vaddr_t, bus_space_handle_t *)); 73 74 static struct sun68k_bus_space_tag mbio_space_tag = { 75 NULL, /* cookie */ 76 NULL, /* parent bus tag */ 77 _mbio_bus_map, /* bus_space_map */ 78 NULL, /* bus_space_unmap */ 79 NULL, /* bus_space_subregion */ 80 NULL, /* bus_space_barrier */ 81 mbio_bus_mmap, /* bus_space_mmap */ 82 NULL, /* bus_intr_establish */ 83 NULL, /* bus_space_peek_N */ 84 NULL /* bus_space_poke_N */ 85 }; 86 87 static int 88 mbio_match(parent, cf, aux) 89 struct device *parent; 90 struct cfdata *cf; 91 void *aux; 92 { 93 struct mainbus_attach_args *ma = aux; 94 95 return (cpu_has_multibus && (ma->ma_name == NULL || strcmp(cf->cf_driver->cd_name, ma->ma_name) == 0)); 96 } 97 98 static void 99 mbio_attach(parent, self, aux) 100 struct device *parent; 101 struct device *self; 102 void *aux; 103 { 104 struct mainbus_attach_args *ma = aux; 105 struct mbio_softc *sc = (struct mbio_softc *)self; 106 struct mbio_attach_args mba; 107 const char *const *cpp; 108 static const char *const special[] = { 109 /* find these first */ 110 NULL 111 }; 112 113 /* 114 * There is only one mbio bus 115 */ 116 if (self->dv_unit > 0) { 117 printf(" unsupported\n"); 118 return; 119 } 120 printf("\n"); 121 122 sc->sc_bustag = ma->ma_bustag; 123 sc->sc_dmatag = ma->ma_dmatag; 124 125 mbio_space_tag.cookie = sc; 126 mbio_space_tag.parent = sc->sc_bustag; 127 128 /* 129 * Prepare the skeleton attach arguments for our devices. 130 * The values we give in the locators are indications to 131 * sun68k_bus_search about which locators must and must not 132 * be defined. 133 */ 134 mba = *ma; 135 mba.mba_bustag = &mbio_space_tag; 136 mba.mba_paddr = LOCATOR_REQUIRED; 137 mba.mba_pri = LOCATOR_OPTIONAL; 138 139 /* Find all `early' mbio devices */ 140 for (cpp = special; *cpp != NULL; cpp++) { 141 mba.mba_name = *cpp; 142 (void)config_search(sun68k_bus_search, self, &mba); 143 } 144 145 /* Find all other mbio devices */ 146 mba.mba_name = NULL; 147 (void)config_search(sun68k_bus_search, self, &mba); 148 } 149 150 int 151 _mbio_bus_map(t, btype, paddr, size, flags, vaddr, hp) 152 bus_space_tag_t t; 153 bus_type_t btype; 154 bus_addr_t paddr; 155 bus_size_t size; 156 int flags; 157 vaddr_t vaddr; 158 bus_space_handle_t *hp; 159 { 160 struct mbio_softc *sc = t->cookie; 161 162 if ((paddr + size) > MBIO_SIZE) 163 panic("_mbio_bus_map: out of range"); 164 165 return (bus_space_map2(sc->sc_bustag, PMAP_MBIO, paddr, 166 size, flags | _SUN68K_BUS_MAP_USE_PROM, vaddr, hp)); 167 } 168 169 paddr_t 170 mbio_bus_mmap(t, btype, paddr, off, prot, flags) 171 bus_space_tag_t t; 172 bus_type_t btype; 173 bus_addr_t paddr; 174 off_t off; 175 int prot; 176 int flags; 177 { 178 struct mbio_softc *sc = t->cookie; 179 180 return (bus_space_mmap2(sc->sc_bustag, PMAP_MBIO, paddr, off, 181 prot, flags)); 182 } 183