1 1.29 nat /* $NetBSD: sbc_obio.c,v 1.29 2025/05/24 10:08:35 nat Exp $ */ 2 1.1 scottr 3 1.1 scottr /* 4 1.1 scottr * Copyright (C) 1996,1997 Scott Reynolds. All rights reserved. 5 1.1 scottr * 6 1.1 scottr * Redistribution and use in source and binary forms, with or without 7 1.1 scottr * modification, are permitted provided that the following conditions 8 1.1 scottr * are met: 9 1.1 scottr * 1. Redistributions of source code must retain the above copyright 10 1.1 scottr * notice, this list of conditions and the following disclaimer. 11 1.1 scottr * 2. Redistributions in binary form must reproduce the above copyright 12 1.1 scottr * notice, this list of conditions and the following disclaimer in the 13 1.1 scottr * documentation and/or other materials provided with the distribution. 14 1.6 scottr * 3. The name of the author may not be used to endorse or promote products 15 1.1 scottr * derived from this software without specific prior written permission 16 1.1 scottr * 17 1.1 scottr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 1.1 scottr * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 1.1 scottr * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 1.1 scottr * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 1.1 scottr * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 1.1 scottr * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 1.1 scottr * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 1.1 scottr * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 1.1 scottr * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 1.1 scottr * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 1.1 scottr */ 28 1.17 lukem 29 1.17 lukem #include <sys/cdefs.h> 30 1.29 nat __KERNEL_RCSID(0, "$NetBSD: sbc_obio.c,v 1.29 2025/05/24 10:08:35 nat Exp $"); 31 1.1 scottr 32 1.1 scottr #include <sys/types.h> 33 1.1 scottr #include <sys/param.h> 34 1.1 scottr #include <sys/systm.h> 35 1.1 scottr #include <sys/kernel.h> 36 1.1 scottr #include <sys/errno.h> 37 1.1 scottr #include <sys/device.h> 38 1.1 scottr #include <sys/buf.h> 39 1.1 scottr #include <sys/proc.h> 40 1.1 scottr 41 1.5 bouyer #include <dev/scsipi/scsi_all.h> 42 1.5 bouyer #include <dev/scsipi/scsipi_all.h> 43 1.5 bouyer #include <dev/scsipi/scsipi_debug.h> 44 1.5 bouyer #include <dev/scsipi/scsiconf.h> 45 1.1 scottr 46 1.1 scottr #include <dev/ic/ncr5380reg.h> 47 1.1 scottr #include <dev/ic/ncr5380var.h> 48 1.1 scottr 49 1.1 scottr #include <machine/cpu.h> 50 1.19 chs #include <machine/bus.h> 51 1.1 scottr #include <machine/viareg.h> 52 1.1 scottr 53 1.4 scottr #include <mac68k/dev/sbcreg.h> 54 1.4 scottr #include <mac68k/dev/sbcvar.h> 55 1.1 scottr 56 1.19 chs #include <mac68k/obio/obiovar.h> 57 1.19 chs 58 1.1 scottr /* 59 1.1 scottr * From Guide to the Macintosh Family Hardware, pp. 137-143 60 1.1 scottr * These are offsets from SCSIBase (see pmap_bootstrap.c) 61 1.1 scottr */ 62 1.1 scottr #define SBC_REG_OFS 0x10000 63 1.1 scottr #define SBC_DMA_OFS 0x12000 64 1.1 scottr #define SBC_HSK_OFS 0x06000 65 1.1 scottr 66 1.1 scottr #define SBC_DMA_OFS_PB500 0x06000 67 1.1 scottr 68 1.1 scottr #define SBC_REG_OFS_IIFX 0x08000 /* Just guessing... */ 69 1.1 scottr #define SBC_DMA_OFS_IIFX 0x0c000 70 1.1 scottr #define SBC_HSK_OFS_IIFX 0x0e000 71 1.1 scottr 72 1.1 scottr #define SBC_REG_OFS_DUO2 0x00000 73 1.1 scottr #define SBC_DMA_OFS_DUO2 0x02000 74 1.1 scottr #define SBC_HSK_OFS_DUO2 0x04000 75 1.1 scottr 76 1.23 tsutsui static int sbc_obio_match(device_t, cfdata_t, void *); 77 1.23 tsutsui static void sbc_obio_attach(device_t, device_t, void *); 78 1.1 scottr 79 1.18 chs void sbc_intr_enable(struct ncr5380_softc *); 80 1.18 chs void sbc_intr_disable(struct ncr5380_softc *); 81 1.18 chs void sbc_obio_clrintr(struct ncr5380_softc *); 82 1.1 scottr 83 1.23 tsutsui CFATTACH_DECL_NEW(sbc_obio, sizeof(struct sbc_softc), 84 1.16 thorpej sbc_obio_match, sbc_obio_attach, NULL, NULL); 85 1.1 scottr 86 1.1 scottr static int 87 1.23 tsutsui sbc_obio_match(device_t parent, cfdata_t cf, void *aux) 88 1.1 scottr { 89 1.23 tsutsui struct obio_attach_args *oa = aux; 90 1.19 chs 91 1.1 scottr switch (current_mac_model->machineid) { 92 1.1 scottr case MACH_MACIIFX: /* Note: the IIfx isn't (yet) supported. */ 93 1.19 chs if (oa->oa_addr == 0) 94 1.8 scottr return 1; 95 1.1 scottr break; 96 1.19 chs 97 1.1 scottr case MACH_MACPB210: 98 1.1 scottr case MACH_MACPB230: 99 1.1 scottr case MACH_MACPB250: 100 1.1 scottr case MACH_MACPB270: 101 1.1 scottr case MACH_MACPB280: 102 1.1 scottr case MACH_MACPB280C: 103 1.19 chs if (oa->oa_addr == 1) 104 1.1 scottr return 1; 105 1.1 scottr /*FALLTHROUGH*/ 106 1.1 scottr default: 107 1.19 chs if (oa->oa_addr == 0 && mac68k_machine.scsi80) 108 1.1 scottr return 1; 109 1.1 scottr } 110 1.1 scottr return 0; 111 1.1 scottr } 112 1.1 scottr 113 1.1 scottr static void 114 1.23 tsutsui sbc_obio_attach(device_t parent, device_t self, void *aux) 115 1.1 scottr { 116 1.23 tsutsui struct sbc_softc *sc = device_private(self); 117 1.23 tsutsui struct ncr5380_softc *ncr_sc = &sc->ncr_sc; 118 1.23 tsutsui struct obio_attach_args *oa = aux; 119 1.1 scottr char bits[64]; 120 1.10 scottr extern vaddr_t SCSIBase; 121 1.1 scottr 122 1.23 tsutsui ncr_sc->sc_dev = self; 123 1.1 scottr /* Pull in the options flags. */ 124 1.23 tsutsui sc->sc_options = ((device_cfdata(self)->cf_flags | 125 1.22 thorpej sbc_options) & SBC_OPTIONS_MASK); 126 1.1 scottr 127 1.1 scottr /* 128 1.1 scottr * Set up offsets to 5380 registers and GLUE I/O space, and turn 129 1.1 scottr * off options we know we can't support on certain models. 130 1.1 scottr */ 131 1.1 scottr switch (current_mac_model->machineid) { 132 1.1 scottr case MACH_MACIIFX: /* Note: the IIfx isn't (yet) supported. */ 133 1.1 scottr sc->sc_regs = (struct sbc_regs *)(SCSIBase + SBC_REG_OFS_IIFX); 134 1.10 scottr sc->sc_drq_addr = (vaddr_t)(SCSIBase + SBC_HSK_OFS_IIFX); 135 1.10 scottr sc->sc_nodrq_addr = (vaddr_t)(SCSIBase + SBC_DMA_OFS_IIFX); 136 1.1 scottr sc->sc_options &= ~(SBC_INTR | SBC_RESELECT); 137 1.1 scottr break; 138 1.1 scottr case MACH_MACPB500: 139 1.1 scottr sc->sc_regs = (struct sbc_regs *)(SCSIBase + SBC_REG_OFS); 140 1.10 scottr sc->sc_drq_addr = (vaddr_t)(SCSIBase + SBC_HSK_OFS); /*??*/ 141 1.10 scottr sc->sc_nodrq_addr = (vaddr_t)(SCSIBase + SBC_DMA_OFS_PB500); 142 1.28 nat if (sc->sc_options & SBC_INTR) 143 1.28 nat sc->sc_options |= SBC_PDMA; 144 1.1 scottr sc->sc_options &= ~(SBC_INTR | SBC_RESELECT); 145 1.1 scottr break; 146 1.29 nat case MACH_MACPB140: 147 1.29 nat case MACH_MACPB145: 148 1.29 nat case MACH_MACPB160: 149 1.29 nat case MACH_MACPB165: 150 1.29 nat case MACH_MACPB165C: 151 1.29 nat case MACH_MACPB170: 152 1.29 nat case MACH_MACPB180: 153 1.29 nat case MACH_MACPB180C: 154 1.29 nat if (sc->sc_options & SBC_PDMA) 155 1.29 nat sc->sc_options |= SBC_INTR; 156 1.29 nat sc->sc_options &= ~(SBC_PDMA); 157 1.29 nat sc->sc_regs = (struct sbc_regs *)(SCSIBase + SBC_REG_OFS); 158 1.29 nat sc->sc_drq_addr = (vaddr_t)(SCSIBase + SBC_HSK_OFS); 159 1.29 nat sc->sc_nodrq_addr = (vaddr_t)(SCSIBase + SBC_DMA_OFS); 160 1.29 nat break; 161 1.1 scottr case MACH_MACPB210: 162 1.1 scottr case MACH_MACPB230: 163 1.1 scottr case MACH_MACPB250: 164 1.1 scottr case MACH_MACPB270: 165 1.1 scottr case MACH_MACPB280: 166 1.1 scottr case MACH_MACPB280C: 167 1.20 chs if (oa->oa_addr == 1) { 168 1.1 scottr sc->sc_regs = (struct sbc_regs *)(0xfee00000 + SBC_REG_OFS_DUO2); 169 1.10 scottr sc->sc_drq_addr = (vaddr_t)(0xfee00000 + SBC_HSK_OFS_DUO2); 170 1.10 scottr sc->sc_nodrq_addr = (vaddr_t)(0xfee00000 + SBC_DMA_OFS_DUO2); 171 1.1 scottr break; 172 1.1 scottr } 173 1.1 scottr /*FALLTHROUGH*/ 174 1.1 scottr default: 175 1.1 scottr sc->sc_regs = (struct sbc_regs *)(SCSIBase + SBC_REG_OFS); 176 1.10 scottr sc->sc_drq_addr = (vaddr_t)(SCSIBase + SBC_HSK_OFS); 177 1.10 scottr sc->sc_nodrq_addr = (vaddr_t)(SCSIBase + SBC_DMA_OFS); 178 1.1 scottr break; 179 1.1 scottr } 180 1.1 scottr 181 1.1 scottr /* 182 1.1 scottr * Initialize fields used by the MI code 183 1.1 scottr */ 184 1.1 scottr ncr_sc->sci_r0 = &sc->sc_regs->sci_pr0.sci_reg; 185 1.1 scottr ncr_sc->sci_r1 = &sc->sc_regs->sci_pr1.sci_reg; 186 1.1 scottr ncr_sc->sci_r2 = &sc->sc_regs->sci_pr2.sci_reg; 187 1.1 scottr ncr_sc->sci_r3 = &sc->sc_regs->sci_pr3.sci_reg; 188 1.1 scottr ncr_sc->sci_r4 = &sc->sc_regs->sci_pr4.sci_reg; 189 1.1 scottr ncr_sc->sci_r5 = &sc->sc_regs->sci_pr5.sci_reg; 190 1.1 scottr ncr_sc->sci_r6 = &sc->sc_regs->sci_pr6.sci_reg; 191 1.1 scottr ncr_sc->sci_r7 = &sc->sc_regs->sci_pr7.sci_reg; 192 1.13 tsutsui 193 1.13 tsutsui ncr_sc->sc_rev = NCR_VARIANT_NCR5380; 194 1.1 scottr 195 1.1 scottr /* 196 1.1 scottr * MD function pointers used by the MI code. 197 1.1 scottr */ 198 1.1 scottr if (sc->sc_options & SBC_PDMA) { 199 1.1 scottr ncr_sc->sc_pio_out = sbc_pdma_out; 200 1.1 scottr ncr_sc->sc_pio_in = sbc_pdma_in; 201 1.1 scottr } else { 202 1.1 scottr ncr_sc->sc_pio_out = ncr5380_pio_out; 203 1.1 scottr ncr_sc->sc_pio_in = ncr5380_pio_in; 204 1.1 scottr } 205 1.1 scottr ncr_sc->sc_dma_alloc = NULL; 206 1.1 scottr ncr_sc->sc_dma_free = NULL; 207 1.1 scottr ncr_sc->sc_dma_poll = NULL; 208 1.1 scottr ncr_sc->sc_intr_on = NULL; 209 1.1 scottr ncr_sc->sc_intr_off = NULL; 210 1.1 scottr ncr_sc->sc_dma_setup = NULL; 211 1.1 scottr ncr_sc->sc_dma_start = NULL; 212 1.1 scottr ncr_sc->sc_dma_eop = NULL; 213 1.1 scottr ncr_sc->sc_dma_stop = NULL; 214 1.1 scottr ncr_sc->sc_flags = 0; 215 1.1 scottr ncr_sc->sc_min_dma_len = MIN_DMA_LEN; 216 1.1 scottr 217 1.1 scottr if (sc->sc_options & SBC_INTR) { 218 1.1 scottr ncr_sc->sc_dma_alloc = sbc_dma_alloc; 219 1.1 scottr ncr_sc->sc_dma_free = sbc_dma_free; 220 1.1 scottr ncr_sc->sc_dma_poll = sbc_dma_poll; 221 1.1 scottr ncr_sc->sc_dma_setup = sbc_dma_setup; 222 1.1 scottr ncr_sc->sc_dma_start = sbc_dma_start; 223 1.1 scottr ncr_sc->sc_dma_eop = sbc_dma_eop; 224 1.1 scottr ncr_sc->sc_dma_stop = sbc_dma_stop; 225 1.1 scottr via2_register_irq(VIA2_SCSIDRQ, sbc_drq_intr, ncr_sc); 226 1.3 scottr } 227 1.3 scottr 228 1.27 nat mutex_init(&sc->sc_drq_lock, MUTEX_DEFAULT, IPL_BIO); 229 1.26 nat 230 1.3 scottr via2_register_irq(VIA2_SCSIIRQ, sbc_irq_intr, ncr_sc); 231 1.3 scottr sc->sc_clrintr = sbc_obio_clrintr; 232 1.1 scottr 233 1.1 scottr if ((sc->sc_options & SBC_RESELECT) == 0) 234 1.1 scottr ncr_sc->sc_no_disconnect = 0xff; 235 1.1 scottr 236 1.24 christos if (sc->sc_options) { 237 1.24 christos snprintb(bits, sizeof(bits), SBC_OPTIONS_BITS, sc->sc_options); 238 1.24 christos aprint_normal(": options=%s", bits); 239 1.24 christos } 240 1.23 tsutsui aprint_normal("\n"); 241 1.1 scottr 242 1.7 scottr if (sc->sc_options & (SBC_INTR|SBC_RESELECT)) { 243 1.7 scottr /* Enable SCSI interrupts through VIA2 */ 244 1.7 scottr sbc_intr_enable(ncr_sc); 245 1.7 scottr } 246 1.1 scottr 247 1.1 scottr #ifdef SBC_DEBUG 248 1.1 scottr if (sbc_debug) 249 1.23 tsutsui aprint_debug_dev(self, "softc=%p regs=%p\n", sc, sc->sc_regs); 250 1.1 scottr #endif 251 1.1 scottr 252 1.14 bouyer ncr_sc->sc_channel.chan_id = 7; 253 1.14 bouyer ncr_sc->sc_adapter.adapt_minphys = minphys; 254 1.11 mycroft 255 1.1 scottr /* 256 1.1 scottr * Initialize the SCSI controller itself. 257 1.1 scottr */ 258 1.11 mycroft ncr5380_attach(ncr_sc); 259 1.1 scottr } 260 1.1 scottr 261 1.1 scottr /* 262 1.1 scottr * Interrupt support routines. 263 1.1 scottr */ 264 1.1 scottr void 265 1.18 chs sbc_intr_enable(struct ncr5380_softc *ncr_sc) 266 1.1 scottr { 267 1.3 scottr struct sbc_softc *sc = (struct sbc_softc *)ncr_sc; 268 1.3 scottr int s, flags; 269 1.3 scottr 270 1.3 scottr flags = V2IF_SCSIIRQ; 271 1.3 scottr if (sc->sc_options & SBC_INTR) 272 1.3 scottr flags |= V2IF_SCSIDRQ; 273 1.1 scottr 274 1.1 scottr s = splhigh(); 275 1.1 scottr if (VIA2 == VIA2OFF) 276 1.3 scottr via2_reg(vIER) = 0x80 | flags; 277 1.1 scottr else 278 1.3 scottr via2_reg(rIER) = 0x80 | flags; 279 1.1 scottr splx(s); 280 1.1 scottr } 281 1.1 scottr 282 1.1 scottr void 283 1.18 chs sbc_intr_disable(struct ncr5380_softc *ncr_sc) 284 1.1 scottr { 285 1.3 scottr struct sbc_softc *sc = (struct sbc_softc *)ncr_sc; 286 1.3 scottr int s, flags; 287 1.3 scottr 288 1.3 scottr flags = V2IF_SCSIIRQ; 289 1.3 scottr if (sc->sc_options & SBC_INTR) 290 1.3 scottr flags |= V2IF_SCSIDRQ; 291 1.1 scottr 292 1.1 scottr s = splhigh(); 293 1.1 scottr if (VIA2 == VIA2OFF) 294 1.3 scottr via2_reg(vIER) = flags; 295 1.1 scottr else 296 1.3 scottr via2_reg(rIER) = flags; 297 1.1 scottr splx(s); 298 1.1 scottr } 299 1.1 scottr 300 1.1 scottr void 301 1.18 chs sbc_obio_clrintr(struct ncr5380_softc *ncr_sc) 302 1.1 scottr { 303 1.3 scottr struct sbc_softc *sc = (struct sbc_softc *)ncr_sc; 304 1.3 scottr int flags; 305 1.3 scottr 306 1.3 scottr flags = V2IF_SCSIIRQ; 307 1.3 scottr if (sc->sc_options & SBC_INTR) 308 1.3 scottr flags |= V2IF_SCSIDRQ; 309 1.3 scottr 310 1.1 scottr if (VIA2 == VIA2OFF) 311 1.3 scottr via2_reg(vIFR) = 0x80 | flags; 312 1.1 scottr else 313 1.3 scottr via2_reg(rIFR) = 0x80 | flags; 314 1.1 scottr } 315