1 /* $NetBSD: neptune.c,v 1.8 2002/10/02 16:02:42 thorpej 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 CFATTACH_DECL(neptune, sizeof(struct neptune_softc), 79 neptune_match, neptune_attach, NULL, NULL); 80 81 static int 82 neptune_match(parent, cf, aux) 83 struct device *parent; 84 struct cfdata *cf; 85 void *aux; 86 { 87 struct intio_attach_args *ia = aux; 88 89 if (strcmp(ia->ia_name, "neptune") != 0) 90 return 0; 91 92 ia->ia_size = 0x400; 93 if (intio_map_allocate_region (parent, ia, INTIO_MAP_TESTONLY)) 94 return 0; 95 96 /* Neptune is a virtual device. Always there. */ 97 98 return (1); 99 } 100 101 102 static void 103 neptune_attach(parent, self, aux) 104 struct device *parent, *self; 105 void *aux; 106 { 107 struct neptune_softc *sc = (struct neptune_softc *)self; 108 struct intio_attach_args *ia = aux; 109 struct neptune_attach_args na; 110 int r; 111 struct cfdata *cf; 112 113 ia->ia_size = 0x400; 114 r = intio_map_allocate_region (parent, ia, INTIO_MAP_ALLOCATE); 115 #ifdef DIAGNOSTIC 116 if (r) 117 panic ("IO map for Neptune corruption??"); 118 #endif 119 120 sc->sc_bst = malloc(sizeof(struct x68k_bus_space), M_DEVBUF, M_NOWAIT); 121 if (sc->sc_bst == NULL) 122 panic("neptune_attach: can't allocate bus_space structure"); 123 *sc->sc_bst = neptune_bus; 124 sc->sc_bst->x68k_bus_device = self; 125 126 sc->sc_addr = (vaddr_t) (ia->ia_addr - PHYS_INTIODEV + intiobase); 127 128 na.na_bst = sc->sc_bst; 129 na.na_intr = ia->ia_intr; 130 131 cf = config_search (neptune_search, self, &na); 132 if (cf) { 133 printf (": Neptune-X ISA bridge\n"); 134 config_attach(self, cf, &na, neptune_print); 135 } else { 136 printf (": no device found.\n"); 137 intio_map_free_region(parent, ia); 138 } 139 } 140 141 static int 142 neptune_search(parent, cf, aux) 143 struct device *parent; 144 struct cfdata *cf; 145 void *aux; 146 { 147 struct neptune_attach_args *na = aux; 148 149 na->na_addr = cf->neptune_cf_addr; 150 151 return config_match(parent, cf, na); 152 } 153 154 static int 155 neptune_print(aux, name) 156 void *aux; 157 const char *name; 158 { 159 struct neptune_attach_args *na = aux; 160 161 /* if (na->na_addr > 0) */ 162 printf (" addr 0x%06x", na->na_addr); 163 164 return (QUIET); 165 } 166 167 168 /* 169 * neptune bus space stuff. 170 */ 171 static int 172 neptune_bus_space_map(t, bpa, size, flags, bshp) 173 bus_space_tag_t t; 174 bus_addr_t bpa; 175 bus_size_t size; 176 int flags; 177 bus_space_handle_t *bshp; 178 { 179 vaddr_t start = ((struct neptune_softc*) ((struct x68k_bus_space*) t) 180 ->x68k_bus_device)->sc_addr; 181 182 /* 183 * Neptune bus is mapped permanently. 184 */ 185 *bshp = (bus_space_handle_t) ((u_int)start + ((u_int)bpa - 0x200) * 2); 186 187 if (badaddr((caddr_t)*bshp)) { 188 return 1; 189 } 190 191 *bshp |= 0x80000000; /* higher byte (= even address) only */ 192 193 return (0); 194 } 195 196 static void 197 neptune_bus_space_unmap(t, bsh, size) 198 bus_space_tag_t t; 199 bus_space_handle_t bsh; 200 bus_size_t size; 201 { 202 return; 203 } 204 205 static int 206 neptune_bus_space_subregion(t, bsh, offset, size, nbshp) 207 bus_space_tag_t t; 208 bus_space_handle_t bsh; 209 bus_size_t offset, size; 210 bus_space_handle_t *nbshp; 211 { 212 213 *nbshp = bsh + offset*2; 214 return (0); 215 } 216