1 /* $NetBSD: mainbus.c,v 1.15 2002/10/02 05:28:14 thorpej Exp $ */ 2 3 /*- 4 * Copyright (c) 2000 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Steve C. Woodford 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 /* 40 * Derived from the mainbus code in mvme68k/autoconf.c by Chuck Cranor. 41 */ 42 43 #include "vmetwo.h" 44 45 #include <sys/param.h> 46 #include <sys/kernel.h> 47 #include <sys/systm.h> 48 #include <sys/device.h> 49 50 #define _MVME68K_BUS_DMA_PRIVATE 51 #define _MVME68K_BUS_SPACE_PRIVATE 52 #include <machine/bus.h> 53 #undef _MVME68K_BUS_DMA_PRIVATE 54 #undef _MVME68K_BUS_SPACE_PRIVATE 55 #include <machine/cpu.h> 56 57 #include <mvme68k/dev/mainbus.h> 58 59 #if defined(MVME162) || defined(MVME172) || defined(MVME167) || defined(MVME177) 60 #if NVMETWO == 0 61 #include <dev/vme/vmevar.h> 62 #include <dev/mvme/mvmebus.h> 63 #include <dev/mvme/vme_twovar.h> 64 #endif 65 #endif 66 67 void mainbus_attach __P((struct device *, struct device *, void *)); 68 int mainbus_match __P((struct device *, struct cfdata *, void *)); 69 int mainbus_print __P((void *, const char *)); 70 71 CFATTACH_DECL(mainbus, sizeof(struct device), 72 mainbus_match, mainbus_attach, NULL, NULL); 73 74 75 struct mainbus_devices { 76 const char *md_name; 77 bus_addr_t md_offset; 78 }; 79 80 #ifdef MVME147 81 static struct mainbus_devices mainbusdevs_147[] = { 82 {"pcc", MAINBUS_PCC_OFFSET}, 83 {"timekeeper", MAINBUS_TK147_OFFSET}, 84 {NULL, 0} 85 }; 86 #endif 87 88 #if defined(MVME162) || defined(MVME167) || defined(MVME172) || defined(MVME177) 89 static struct mainbus_devices mainbusdevs_1x7[] = { 90 {"pcctwo", MAINBUS_PCCTWO_OFFSET}, 91 {"vmetwo", MAINBUS_VMETWO_OFFSET}, 92 {"timekeeper", MAINBUS_TIMEKEEPER_OFFSET}, 93 {NULL, 0} 94 }; 95 #endif 96 97 struct mvme68k_bus_dma_tag _mainbus_dma_tag = { 98 NULL, 99 _bus_dmamap_create, 100 _bus_dmamap_destroy, 101 _bus_dmamap_load_direct, 102 _bus_dmamap_load_mbuf_direct, 103 _bus_dmamap_load_uio_direct, 104 _bus_dmamap_load_raw_direct, 105 _bus_dmamap_unload, 106 NULL, /* Set up at run-time */ 107 _bus_dmamem_alloc, 108 _bus_dmamem_free, 109 _bus_dmamem_map, 110 _bus_dmamem_unmap, 111 _bus_dmamem_mmap 112 }; 113 114 struct mvme68k_bus_space_tag _mainbus_space_tag = { 115 NULL, 116 _bus_space_map, 117 _bus_space_unmap, 118 _bus_space_peek_1, 119 _bus_space_peek_2, 120 _bus_space_peek_4, 121 _bus_space_poke_1, 122 _bus_space_poke_2, 123 _bus_space_poke_4 124 }; 125 126 127 /* ARGSUSED */ 128 int 129 mainbus_match(parent, cf, args) 130 struct device *parent; 131 struct cfdata *cf; 132 void *args; 133 { 134 static int mainbus_matched; 135 136 if (mainbus_matched) 137 return (0); 138 139 return ((mainbus_matched = 1)); 140 } 141 142 /* ARGSUSED */ 143 void 144 mainbus_attach(parent, self, args) 145 struct device *parent; 146 struct device *self; 147 void *args; 148 { 149 struct mainbus_attach_args ma; 150 struct mainbus_devices *devices; 151 int i; 152 153 printf("\n"); 154 155 /* 156 * Attach children appropriate for this CPU. 157 */ 158 switch (machineid) { 159 #ifdef MVME147 160 case MVME_147: 161 devices = mainbusdevs_147; 162 _mainbus_dma_tag._dmamap_sync = _bus_dmamap_sync_030; 163 break; 164 #endif 165 166 #if defined(MVME162) || defined(MVME167) || defined(MVME172) || defined(MVME177) 167 case MVME_162: 168 case MVME_167: 169 case MVME_172: 170 case MVME_177: 171 devices = mainbusdevs_1x7; 172 _mainbus_dma_tag._dmamap_sync = _bus_dmamap_sync_0460; 173 break; 174 #endif 175 176 default: 177 panic("mainbus_attach: impossible CPU type"); 178 } 179 180 for (i = 0; devices[i].md_name != NULL; ++i) { 181 /* 182 * On mvme162 and up, if the kernel config file had no vmetwo0 183 * device, we have to do some manual initialisation on the 184 * VMEChip2 to get local interrupts working (ABORT switch, 185 * hardware assisted soft interrupts). 186 */ 187 #if defined(MVME162) || defined(MVME172) || defined(MVME167) || defined(MVME177) 188 #if NVMETWO == 0 189 if (devices[i].md_offset == MAINBUS_VMETWO_OFFSET 190 #if defined(MVME147) 191 && machineid != MVME_147 192 #endif 193 ) { 194 (void) vmetwo_probe(&_mainbus_space_tag, 195 intiobase_phys + MAINBUS_VMETWO_OFFSET); 196 continue; 197 } 198 #endif 199 #endif 200 ma.ma_name = devices[i].md_name; 201 ma.ma_dmat = &_mainbus_dma_tag; 202 ma.ma_bust = &_mainbus_space_tag; 203 ma.ma_offset = devices[i].md_offset + intiobase_phys; 204 205 (void) config_found(self, &ma, mainbus_print); 206 } 207 208 209 /* 210 * Attach the memory controllers on mvme162->mvme177. 211 * Note: These *must* be attached after the PCCChip2/MCChip. 212 * They must also be attached *after* the VMEchip2 has been 213 * initialised (either by the driver, or the vmetwo_probe() 214 * call above). 215 */ 216 #if defined(MVME162) || defined(MVME172) || defined(MVME167) || defined(MVME177) 217 #if defined(MVME147) 218 if (machineid != MVME_147) 219 #endif 220 { 221 ma.ma_name = "memc"; 222 ma.ma_dmat = &_mainbus_dma_tag; 223 ma.ma_bust = &_mainbus_space_tag; 224 ma.ma_offset = MAINBUS_MEMC1_OFFSET + intiobase_phys; 225 (void) config_found(self, &ma, mainbus_print); 226 ma.ma_offset = MAINBUS_MEMC2_OFFSET + intiobase_phys; 227 (void) config_found(self, &ma, mainbus_print); 228 } 229 #endif 230 231 /* 232 * Attach Industry Pack modules on mvme162 and mvme172 233 */ 234 #if defined(MVME162) || defined(MVME172) 235 #if defined(MVME147) || defined(MVME167) || defined(MVME177) 236 if (machineid == MVME_162 || machineid == MVME_172) 237 #endif 238 { 239 ma.ma_name = "ipack"; 240 ma.ma_dmat = &_mainbus_dma_tag; 241 ma.ma_bust = &_mainbus_space_tag; 242 ma.ma_offset = MAINBUS_IPACK_OFFSET + intiobase_phys; 243 (void) config_found(self, &ma, mainbus_print); 244 } 245 #endif 246 } 247 248 int 249 mainbus_print(aux, cp) 250 void *aux; 251 const char *cp; 252 { 253 struct mainbus_attach_args *ma; 254 255 ma = aux; 256 257 if (cp) 258 printf("%s at %s", ma->ma_name, cp); 259 260 printf(" address 0x%lx", ma->ma_offset); 261 262 return (UNCONF); 263 } 264