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