1 /* $NetBSD: mainbus.c,v 1.27 2026/04/26 18:02:57 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 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 /* 33 * Derived from the mainbus code in mvme68k/autoconf.c by Chuck Cranor. 34 */ 35 36 #include <sys/cdefs.h> 37 __KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.27 2026/04/26 18:02:57 thorpej Exp $"); 38 39 #include "opt_mvmeconf.h" 40 #include "vmetwo.h" 41 42 #include <sys/param.h> 43 #include <sys/kernel.h> 44 #include <sys/systm.h> 45 #include <sys/device.h> 46 #include <sys/kcore.h> 47 48 #define _M68K_BUS_DMA_PRIVATE 49 #define _M68K_BUS_SPACE_PRIVATE 50 #include <machine/bus.h> 51 #undef _M68K_BUS_DMA_PRIVATE 52 #undef _M68K_BUS_SPACE_PRIVATE 53 #include <machine/cpu.h> 54 55 #include <m68k/seglist.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(device_t, device_t, void *); 68 int mainbus_match(device_t, cfdata_t, void *); 69 int mainbus_print(void *, const char *); 70 71 CFATTACH_DECL_NEW(mainbus, 0, 72 mainbus_match, mainbus_attach, NULL, NULL); 73 74 struct mainbus_devices { 75 const char *md_name; 76 bus_addr_t md_offset; 77 }; 78 79 #ifdef MVME147 80 static struct mainbus_devices mainbusdevs_147[] = { 81 {"pcc", MAINBUS_PCC_OFFSET}, 82 {"timekeeper", MAINBUS_TK147_OFFSET}, 83 {NULL, 0} 84 }; 85 #endif 86 87 #if defined(MVME162) || defined(MVME167) || defined(MVME172) || defined(MVME177) 88 static struct mainbus_devices mainbusdevs_1x7[] = { 89 {"pcctwo", MAINBUS_PCCTWO_OFFSET}, 90 {"vmetwo", MAINBUS_VMETWO_OFFSET}, 91 {"timekeeper", MAINBUS_TIMEKEEPER_OFFSET}, 92 {NULL, 0} 93 }; 94 #endif 95 96 static int 97 mvme68k_bus_dmamem_alloc(bus_dma_tag_t t, bus_size_t size, bus_size_t alignment, 98 bus_size_t boundary, bus_dma_segment_t *segs, int nsegs, int *rsegs, 99 int flags) 100 { 101 extern paddr_t avail_start, avail_end; 102 bus_addr_t high; 103 104 if (flags & BUS_DMA_ONBOARD_RAM) { 105 high = phys_seg_list[0].ps_avail_end; 106 } else { 107 high = avail_end; 108 } 109 110 return _bus_dmamem_alloc_common(t, avail_start, high, 111 size, alignment, boundary, segs, nsegs, rsegs, flags); 112 } 113 114 struct m68k_bus_dma_tag _mainbus_dma_tag = { 115 NULL, 116 0, 117 _bus_dmamap_create, 118 _bus_dmamap_destroy, 119 _bus_dmamap_load_direct, 120 _bus_dmamap_load_mbuf_direct, 121 _bus_dmamap_load_uio_direct, 122 _bus_dmamap_load_raw_direct, 123 _bus_dmamap_unload, 124 _bus_dmamap_sync, 125 mvme68k_bus_dmamem_alloc, 126 _bus_dmamem_free, 127 _bus_dmamem_map, 128 _bus_dmamem_unmap, 129 _bus_dmamem_mmap 130 }; 131 132 /* ARGSUSED */ 133 int 134 mainbus_match(device_t parent, cfdata_t cf, void *args) 135 { 136 static int mainbus_matched; 137 138 if (mainbus_matched) 139 return 0; 140 141 return (mainbus_matched = 1); 142 } 143 144 /* ARGSUSED */ 145 void 146 mainbus_attach(device_t parent, device_t self, void *args) 147 { 148 struct mainbus_attach_args ma; 149 struct mainbus_devices *devices; 150 int i; 151 152 printf("\n"); 153 154 /* 155 * Attach children appropriate for this CPU. 156 */ 157 switch (machineid) { 158 #ifdef MVME147 159 case MVME_147: 160 devices = mainbusdevs_147; 161 break; 162 #endif 163 164 #if defined(MVME162) || defined(MVME167) || defined(MVME172) || defined(MVME177) 165 case MVME_162: 166 case MVME_167: 167 case MVME_172: 168 case MVME_177: 169 devices = mainbusdevs_1x7; 170 break; 171 #endif 172 173 default: 174 panic("mainbus_attach: impossible CPU type"); 175 } 176 177 for (i = 0; devices[i].md_name != NULL; ++i) { 178 /* 179 * On mvme162 and up, if the kernel config file had no vmetwo0 180 * device, we have to do some manual initialisation on the 181 * VMEChip2 to get local interrupts working (ABORT switch, 182 * hardware assisted soft interrupts). 183 */ 184 #if defined(MVME162) || defined(MVME172) || defined(MVME167) || defined(MVME177) 185 #if NVMETWO == 0 186 if (devices[i].md_offset == MAINBUS_VMETWO_OFFSET 187 #if defined(MVME147) 188 && machineid != MVME_147 189 #endif 190 ) { 191 (void)vmetwo_probe(&m68k_simple_bus_space, 192 intiobase_phys + MAINBUS_VMETWO_OFFSET); 193 continue; 194 } 195 #endif 196 #endif 197 ma.ma_name = devices[i].md_name; 198 ma.ma_dmat = &_mainbus_dma_tag; 199 ma.ma_bust = &m68k_simple_bus_space; 200 ma.ma_offset = devices[i].md_offset + intiobase_phys; 201 202 (void)config_found(self, &ma, mainbus_print, CFARGS_NONE); 203 } 204 205 206 /* 207 * Attach the memory controllers on mvme162->mvme177. 208 * Note: These *must* be attached after the PCCChip2/MCChip. 209 * They must also be attached *after* the VMEchip2 has been 210 * initialised (either by the driver, or the vmetwo_probe() 211 * call above). 212 */ 213 #if defined(MVME162) || defined(MVME172) || defined(MVME167) || defined(MVME177) 214 #if defined(MVME147) 215 if (machineid != MVME_147) 216 #endif 217 { 218 ma.ma_name = "memc"; 219 ma.ma_dmat = &_mainbus_dma_tag; 220 ma.ma_bust = &m68k_simple_bus_space; 221 ma.ma_offset = MAINBUS_MEMC1_OFFSET + intiobase_phys; 222 (void)config_found(self, &ma, mainbus_print, CFARGS_NONE); 223 ma.ma_offset = MAINBUS_MEMC2_OFFSET + intiobase_phys; 224 (void)config_found(self, &ma, mainbus_print, CFARGS_NONE); 225 } 226 #endif 227 228 /* 229 * Attach Industry Pack modules on mvme162 and mvme172 230 */ 231 #if defined(MVME162) || defined(MVME172) 232 #if defined(MVME147) || defined(MVME167) || defined(MVME177) 233 if (machineid == MVME_162 || machineid == MVME_172) 234 #endif 235 { 236 ma.ma_name = "ipack"; 237 ma.ma_dmat = &_mainbus_dma_tag; 238 ma.ma_bust = &m68k_simple_bus_space; 239 ma.ma_offset = MAINBUS_IPACK_OFFSET + intiobase_phys; 240 (void)config_found(self, &ma, mainbus_print, CFARGS_NONE); 241 } 242 #endif 243 } 244 245 int 246 mainbus_print(void *aux, const char *cp) 247 { 248 struct mainbus_attach_args *ma; 249 250 ma = aux; 251 252 if (cp) 253 aprint_normal("%s at %s", ma->ma_name, cp); 254 255 aprint_normal(" address 0x%lx", ma->ma_offset); 256 257 return UNCONF; 258 } 259