1 1.16 rin /* $NetBSD: sc_mbmem.c,v 1.16 2023/08/04 11:18:18 rin Exp $ */ 2 1.1 fredette 3 1.1 fredette /*- 4 1.1 fredette * Copyright (c) 1996 The NetBSD Foundation, Inc. 5 1.1 fredette * All rights reserved. 6 1.1 fredette * 7 1.1 fredette * This code is derived from software contributed to The NetBSD Foundation 8 1.1 fredette * by Adam Glass, David Jones, Gordon W. Ross, and Matthew Fredette. 9 1.1 fredette * 10 1.1 fredette * Redistribution and use in source and binary forms, with or without 11 1.1 fredette * modification, are permitted provided that the following conditions 12 1.1 fredette * are met: 13 1.1 fredette * 1. Redistributions of source code must retain the above copyright 14 1.1 fredette * notice, this list of conditions and the following disclaimer. 15 1.1 fredette * 2. Redistributions in binary form must reproduce the above copyright 16 1.1 fredette * notice, this list of conditions and the following disclaimer in the 17 1.1 fredette * documentation and/or other materials provided with the distribution. 18 1.1 fredette * 19 1.1 fredette * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 1.1 fredette * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 1.1 fredette * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 1.1 fredette * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 1.1 fredette * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 1.1 fredette * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 1.1 fredette * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 1.1 fredette * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 1.1 fredette * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 1.1 fredette * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 1.1 fredette * POSSIBILITY OF SUCH DAMAGE. 30 1.1 fredette */ 31 1.1 fredette 32 1.1 fredette /* 33 1.1 fredette * This file contains only the machine-dependent parts of the 34 1.1 fredette * Sun-2 SCSI driver. (Autoconfig stuff and DMA functions.) 35 1.1 fredette * The machine-independent parts are in sunscpal.c 36 1.1 fredette * 37 1.1 fredette * Supported hardware includes: 38 1.1 fredette * Sun SCSI-2 on Multibus (Sun2/120,Sun2/170) 39 1.1 fredette * Sun SCSI-2 on VME (Sun2/50,Sun3/160,Sun3/260,others?) 40 1.1 fredette * 41 1.1 fredette * Credits, history: 42 1.1 fredette * 43 1.1 fredette * Matthew Fredette took revision 1.15 of si_vme.c, and then heavily 44 1.1 fredette * modified it to support the Sun sc. The remaining credits 45 1.1 fredette * are from si_vme.c: 46 1.1 fredette * 47 1.1 fredette * David Jones wrote the initial version of this module, which 48 1.1 fredette * included support for the VME adapter only. (no reselection). 49 1.1 fredette * 50 1.1 fredette * Gordon Ross added support for the OBIO adapter, and re-worked 51 1.1 fredette * both the VME and OBIO code to support disconnect/reselect. 52 1.1 fredette * (Required figuring out the hardware "features" noted above.) 53 1.1 fredette * 54 1.1 fredette * The autoconfiguration boilerplate came from Adam Glass. 55 1.1 fredette */ 56 1.1 fredette 57 1.1 fredette /***************************************************************** 58 1.1 fredette * Multibus functions for sc 59 1.1 fredette ****************************************************************/ 60 1.8 lukem 61 1.8 lukem #include <sys/cdefs.h> 62 1.16 rin __KERNEL_RCSID(0, "$NetBSD: sc_mbmem.c,v 1.16 2023/08/04 11:18:18 rin Exp $"); 63 1.1 fredette 64 1.1 fredette #include <sys/param.h> 65 1.1 fredette #include <sys/systm.h> 66 1.1 fredette #include <sys/errno.h> 67 1.1 fredette #include <sys/kernel.h> 68 1.15 thorpej #include <sys/kmem.h> 69 1.1 fredette #include <sys/device.h> 70 1.1 fredette #include <sys/buf.h> 71 1.1 fredette #include <sys/proc.h> 72 1.1 fredette 73 1.1 fredette #include <dev/scsipi/scsi_all.h> 74 1.1 fredette #include <dev/scsipi/scsipi_all.h> 75 1.1 fredette #include <dev/scsipi/scsipi_debug.h> 76 1.1 fredette #include <dev/scsipi/scsiconf.h> 77 1.1 fredette 78 1.1 fredette #include <machine/autoconf.h> 79 1.1 fredette #include <machine/bus.h> 80 1.1 fredette 81 1.1 fredette /* #define DEBUG XXX */ 82 1.1 fredette 83 1.1 fredette #include <dev/ic/sunscpalreg.h> 84 1.1 fredette #include <dev/ic/sunscpalvar.h> 85 1.1 fredette 86 1.2 fredette /* Yes, we use a VME header file. */ 87 1.2 fredette #include <dev/vme/screg.h> 88 1.1 fredette 89 1.1 fredette /* 90 1.1 fredette * Transfers smaller than this are done using PIO 91 1.1 fredette * (on assumption they're not worth DMA overhead) 92 1.1 fredette */ 93 1.1 fredette #define MIN_DMA_LEN 128 94 1.1 fredette 95 1.1 fredette /* 96 1.1 fredette * New-style autoconfig attachment 97 1.1 fredette */ 98 1.1 fredette 99 1.13 tsutsui static int sunsc_mbmem_match(device_t, cfdata_t, void *); 100 1.13 tsutsui static void sunsc_mbmem_attach(device_t, device_t, void *); 101 1.9 chs static int sunsc_mbmem_intr(void *); 102 1.1 fredette 103 1.13 tsutsui CFATTACH_DECL_NEW(sc_mbmem, sizeof(struct sunscpal_softc), 104 1.6 thorpej sunsc_mbmem_match, sunsc_mbmem_attach, NULL, NULL); 105 1.1 fredette 106 1.1 fredette /* 107 1.1 fredette * Options for parity, DMA, and interrupts. 108 1.1 fredette */ 109 1.1 fredette int sunsc_mbmem_options = 0x00; 110 1.1 fredette 111 1.9 chs static int 112 1.13 tsutsui sunsc_mbmem_match(device_t parent, cfdata_t cf, void *aux) 113 1.1 fredette { 114 1.2 fredette struct mbmem_attach_args *mbma = aux; 115 1.2 fredette bus_space_handle_t bh; 116 1.13 tsutsui bool matched; 117 1.1 fredette 118 1.1 fredette /* No default Multibus address. */ 119 1.2 fredette if (mbma->mbma_paddr == -1) 120 1.13 tsutsui return 0; 121 1.1 fredette 122 1.2 fredette /* Make sure there is something there... */ 123 1.2 fredette if (bus_space_map(mbma->mbma_bustag, mbma->mbma_paddr, SCREG_BANK_SZ, 124 1.13 tsutsui 0, &bh)) 125 1.13 tsutsui return 0; 126 1.13 tsutsui matched = 127 1.13 tsutsui (bus_space_peek_2(mbma->mbma_bustag, bh, SCREG_ICR, NULL) == 0); 128 1.2 fredette bus_space_unmap(mbma->mbma_bustag, bh, SCREG_BANK_SZ); 129 1.2 fredette if (!matched) 130 1.13 tsutsui return 0; 131 1.1 fredette 132 1.1 fredette /* Default interrupt priority. */ 133 1.2 fredette if (mbma->mbma_pri == -1) 134 1.2 fredette mbma->mbma_pri = 2; 135 1.1 fredette 136 1.13 tsutsui return 1; 137 1.1 fredette } 138 1.1 fredette 139 1.9 chs static void 140 1.13 tsutsui sunsc_mbmem_attach(device_t parent, device_t self, void *args) 141 1.1 fredette { 142 1.13 tsutsui struct sunscpal_softc *sc = device_private(self); 143 1.11 thorpej struct cfdata *cf = device_cfdata(self); 144 1.2 fredette struct mbmem_attach_args *mbma = args; 145 1.2 fredette int i; 146 1.1 fredette 147 1.13 tsutsui sc->sc_dev = self; 148 1.13 tsutsui 149 1.1 fredette /* Map in the device. */ 150 1.2 fredette sc->sunscpal_regt = mbma->mbma_bustag; 151 1.2 fredette sc->sunscpal_dmat = mbma->mbma_dmatag; 152 1.2 fredette if (bus_space_map(mbma->mbma_bustag, mbma->mbma_paddr, SCREG_BANK_SZ, 153 1.13 tsutsui 0, &sc->sunscpal_regh)) 154 1.13 tsutsui panic("%s: can't map", __func__); 155 1.1 fredette 156 1.1 fredette /* Device register offsets. */ 157 1.2 fredette sc->sunscpal_data = SCREG_DATA; 158 1.2 fredette sc->sunscpal_cmd_stat = SCREG_CMD_STAT; 159 1.2 fredette sc->sunscpal_icr = SCREG_ICR; 160 1.2 fredette sc->sunscpal_dma_addr_h = SCREG_DMA_ADDR_H; 161 1.2 fredette sc->sunscpal_dma_addr_l = SCREG_DMA_ADDR_L; 162 1.2 fredette sc->sunscpal_dma_count = SCREG_DMA_COUNT; 163 1.2 fredette sc->sunscpal_intvec = SCREG_INTVEC; 164 1.1 fredette 165 1.2 fredette /* Allocate DMA handles. */ 166 1.2 fredette i = SUNSCPAL_OPENINGS * sizeof(struct sunscpal_dma_handle); 167 1.16 rin sc->sc_dma_handles = kmem_zalloc(i, KM_SLEEP); 168 1.2 fredette for (i = 0; i < SUNSCPAL_OPENINGS; i++) 169 1.2 fredette if (bus_dmamap_create(sc->sunscpal_dmat, SUNSCPAL_MAX_DMA_LEN, 170 1.13 tsutsui 1, SUNSCPAL_MAX_DMA_LEN, 171 1.13 tsutsui 0, BUS_DMA_WAITOK, &sc->sc_dma_handles[i].dh_dmamap) != 0) 172 1.7 wiz panic("sc: DMA map create failed"); 173 1.2 fredette 174 1.1 fredette /* Miscellaneous. */ 175 1.1 fredette sc->sc_min_dma_len = MIN_DMA_LEN; 176 1.1 fredette sc->sc_rev = SUNSCPAL_VARIANT_501_1006; 177 1.1 fredette 178 1.1 fredette /* Attach interrupt handler. */ 179 1.2 fredette bus_intr_establish(mbma->mbma_bustag, mbma->mbma_pri, IPL_BIO, 0, 180 1.13 tsutsui sunsc_mbmem_intr, sc); 181 1.1 fredette 182 1.1 fredette /* Do the common attach stuff. */ 183 1.13 tsutsui sunscpal_attach(sc, cf->cf_flags ? cf->cf_flags : sunsc_mbmem_options); 184 1.1 fredette } 185 1.1 fredette 186 1.1 fredette static int 187 1.1 fredette sunsc_mbmem_intr(void *arg) 188 1.1 fredette { 189 1.1 fredette struct sunscpal_softc *sc = arg; 190 1.1 fredette int claimed; 191 1.1 fredette 192 1.1 fredette claimed = sunscpal_intr(sc); 193 1.1 fredette #ifdef DEBUG 194 1.13 tsutsui if (claimed == 0) { 195 1.13 tsutsui printf("%s: spurious from SBC\n", __func__); 196 1.1 fredette } 197 1.1 fredette #endif 198 1.1 fredette /* Yes, we DID cause this interrupt. */ 199 1.1 fredette claimed = 1; 200 1.1 fredette 201 1.13 tsutsui return claimed; 202 1.1 fredette } 203