1 /* $NetBSD: neptune.c,v 1.4 2000/01/16 14:20:56 minoura Exp $ */ 2 3 /*- 4 * Copyright (c) 1998 NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Minoura Makoto. 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. The name of the author may not be used to endorse or promote products 23 * derived from this software without specific prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 26 * ``AS IS'' AND 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 THE FOUNDATION OR CONTRIBUTORS 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 * Neptune-X -- X68k-ISA Bus Bridge 40 */ 41 42 #include <sys/param.h> 43 #include <sys/systm.h> 44 #include <sys/device.h> 45 #include <sys/malloc.h> 46 47 #include <machine/bus.h> 48 #include <machine/cpu.h> 49 #include <machine/frame.h> 50 51 #include <arch/x68k/dev/intiovar.h> 52 #include <arch/x68k/dev/neptunevar.h> 53 54 /* bus_space stuff */ 55 static int neptune_bus_space_map __P((bus_space_tag_t, bus_addr_t, bus_size_t, 56 int, bus_space_handle_t*)); 57 static void neptune_bus_space_unmap __P((bus_space_tag_t, 58 bus_space_handle_t, bus_size_t)); 59 static int neptune_bus_space_subregion __P((bus_space_tag_t, bus_space_handle_t, 60 bus_size_t, bus_size_t, 61 bus_space_handle_t*)); 62 63 static struct x68k_bus_space neptune_bus = { 64 #if 0 65 X68K_NEPUTUNE_BUS, 66 #endif 67 neptune_bus_space_map, neptune_bus_space_unmap, 68 neptune_bus_space_subregion, 69 x68k_bus_space_alloc, x68k_bus_space_free, 70 }; 71 72 73 static int neptune_match __P((struct device *, struct cfdata *, void *)); 74 static void neptune_attach __P((struct device *, struct device *, void *)); 75 static int neptune_search __P((struct device *, struct cfdata *cf, void *)); 76 static int neptune_print __P((void *, const char *)); 77 78 struct cfattach neptune_ca = { 79 sizeof(struct neptune_softc), neptune_match, neptune_attach 80 }; 81 82 static int 83 neptune_match(parent, cf, aux) 84 struct device *parent; 85 struct cfdata *cf; 86 void *aux; 87 { 88 struct intio_attach_args *ia = aux; 89 90 if (strcmp(ia->ia_name, "neptune") != 0) 91 return 0; 92 93 ia->ia_size = 0x400; 94 if (intio_map_allocate_region (parent, ia, INTIO_MAP_TESTONLY)) 95 return 0; 96 97 /* Neptune is a virtual device. Always there. */ 98 99 return (1); 100 } 101 102 103 static void 104 neptune_attach(parent, self, aux) 105 struct device *parent, *self; 106 void *aux; 107 { 108 struct neptune_softc *sc = (struct neptune_softc *)self; 109 struct intio_attach_args *ia = aux; 110 struct neptune_attach_args na; 111 int r; 112 struct cfdata *cf; 113 114 ia->ia_size = 0x400; 115 r = intio_map_allocate_region (parent, ia, INTIO_MAP_ALLOCATE); 116 #ifdef DIAGNOSTIC 117 if (r) 118 panic ("IO map for Neptune corruption??"); 119 #endif 120 121 sc->sc_bst = malloc(sizeof(struct x68k_bus_space), M_DEVBUF, M_NOWAIT); 122 if (sc->sc_bst == NULL) 123 panic("neptune_attach: can't allocate bus_space structure"); 124 *sc->sc_bst = neptune_bus; 125 sc->sc_bst->x68k_bus_device = self; 126 127 sc->sc_addr = (vaddr_t) (ia->ia_addr - PHYS_INTIODEV + intiobase); 128 129 na.na_bst = sc->sc_bst; 130 na.na_intr = ia->ia_intr; 131 132 cf = config_search (neptune_search, self, &na); 133 if (cf) { 134 printf (": Neptune-X ISA bridge\n"); 135 config_attach(self, cf, &na, neptune_print); 136 } else { 137 printf (": no device found.\n"); 138 intio_map_free_region(parent, ia); 139 } 140 } 141 142 static int 143 neptune_search(parent, cf, aux) 144 struct device *parent; 145 struct cfdata *cf; 146 void *aux; 147 { 148 struct neptune_attach_args *na = aux; 149 150 na->na_addr = cf->neptune_cf_addr; 151 152 return (*cf->cf_attach->ca_match)(parent, cf, na); 153 } 154 155 static int 156 neptune_print(aux, name) 157 void *aux; 158 const char *name; 159 { 160 struct neptune_attach_args *na = aux; 161 162 /* if (na->na_addr > 0) */ 163 printf (" addr 0x%06x", na->na_addr); 164 165 return (QUIET); 166 } 167 168 169 /* 170 * neptune bus space stuff. 171 */ 172 static int 173 neptune_bus_space_map(t, bpa, size, flags, bshp) 174 bus_space_tag_t t; 175 bus_addr_t bpa; 176 bus_size_t size; 177 int flags; 178 bus_space_handle_t *bshp; 179 { 180 vaddr_t start = ((struct neptune_softc*) ((struct x68k_bus_space*) t) 181 ->x68k_bus_device)->sc_addr; 182 183 /* 184 * Neptune bus is mapped permanently. 185 */ 186 *bshp = (bus_space_handle_t) ((u_int)start + ((u_int)bpa - 0x200) * 2); 187 188 if (badaddr((caddr_t)*bshp)) { 189 return 1; 190 } 191 192 *bshp |= 0x80000000; /* higher byte (= even address) only */ 193 194 return (0); 195 } 196 197 static void 198 neptune_bus_space_unmap(t, bsh, size) 199 bus_space_tag_t t; 200 bus_space_handle_t bsh; 201 bus_size_t size; 202 { 203 return; 204 } 205 206 static int 207 neptune_bus_space_subregion(t, bsh, offset, size, nbshp) 208 bus_space_tag_t t; 209 bus_space_handle_t bsh; 210 bus_size_t offset, size; 211 bus_space_handle_t *nbshp; 212 { 213 214 *nbshp = bsh + offset*2; 215 return (0); 216 } 217