1 /* $NetBSD: osiop_pcctwo.c,v 1.1 2002/02/12 20:38:48 scw Exp $ */ 2 3 /*- 4 * Copyright (c) 1999, 2002 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 * Front-end attachment code for the ncr53c710 SCSI controller 41 * on mvme68k/mvme88k boards. 42 */ 43 44 #include <sys/param.h> 45 #include <sys/systm.h> 46 #include <sys/kernel.h> 47 #include <sys/device.h> 48 49 #include <dev/scsipi/scsi_all.h> 50 #include <dev/scsipi/scsipi_all.h> 51 #include <dev/scsipi/scsiconf.h> 52 53 #include <machine/cpu.h> 54 #include <machine/bus.h> 55 #include <machine/autoconf.h> 56 57 #include <dev/ic/osiopreg.h> 58 #include <dev/ic/osiopvar.h> 59 60 #include <dev/mvme/pcctworeg.h> 61 #include <dev/mvme/pcctwovar.h> 62 63 64 int osiop_pcctwo_match __P((struct device *, struct cfdata *, void *)); 65 void osiop_pcctwo_attach __P((struct device *, struct device *, void *)); 66 67 struct osiop_pcctwo_softc { 68 struct osiop_softc sc_osiop; 69 struct evcnt sc_evcnt; 70 }; 71 72 struct cfattach osiop_pcctwo_ca = { 73 sizeof(struct osiop_pcctwo_softc), osiop_pcctwo_match, 74 osiop_pcctwo_attach 75 }; 76 77 static int osiop_pcctwo_intr __P((void *)); 78 79 extern struct cfdriver osiop_cd; 80 81 /* ARGSUSED */ 82 int 83 osiop_pcctwo_match(parent, cf, args) 84 struct device *parent; 85 struct cfdata *cf; 86 void *args; 87 { 88 struct pcctwo_attach_args *pa; 89 90 pa = args; 91 92 if (strcmp(pa->pa_name, osiop_cd.cd_name)) 93 return (0); 94 95 pa->pa_ipl = cf->pcctwocf_ipl; 96 97 return (1); 98 } 99 100 /* ARGSUSED */ 101 void 102 osiop_pcctwo_attach(parent, self, args) 103 struct device *parent; 104 struct device *self; 105 void *args; 106 { 107 struct pcctwo_attach_args *pa; 108 struct osiop_pcctwo_softc *sc; 109 int clk, ctest7; 110 111 pa = (struct pcctwo_attach_args *) args; 112 sc = (struct osiop_pcctwo_softc *) self; 113 114 /* 115 * On the '17x the siop's clock is the same as the cpu clock. 116 * On the other boards, the siop runs at twice the cpu clock. 117 * Also, the 17x cannot do proper bus-snooping (the 68060 is 118 * lame in this repspect) so don't enable it on that board. 119 */ 120 #ifdef MVME68K 121 if (machineid == MVME_172 || machineid == MVME_177) { 122 clk = cpuspeed; 123 ctest7 = 0; 124 } else { 125 clk = cpuspeed * 2; 126 ctest7 = OSIOP_CTEST7_SC0; 127 } 128 #else 129 #error Set up siop clock speed for mvme187 130 #endif 131 132 sc->sc_osiop.sc_bst = pa->pa_bust; 133 sc->sc_osiop.sc_dmat = pa->pa_dmat; 134 (void) bus_space_map(sc->sc_osiop.sc_bst, pa->pa_offset, OSIOP_NREGS, 135 0, &sc->sc_osiop.sc_reg); 136 137 sc->sc_osiop.sc_clock_freq = clk; 138 sc->sc_osiop.sc_ctest7 = ctest7 | OSIOP_CTEST7_TT1; 139 sc->sc_osiop.sc_dcntl = OSIOP_DCNTL_EA; 140 sc->sc_osiop.sc_id = 7; /* XXX: Could use NVRAM setting */ 141 142 /* Attach main MI driver */ 143 osiop_attach(&sc->sc_osiop); 144 145 /* Register the event counter */ 146 evcnt_attach_dynamic(&sc->sc_evcnt, EVCNT_TYPE_INTR, 147 pcctwointr_evcnt(pa->pa_ipl), "disk", sc->sc_osiop.sc_dev.dv_xname); 148 149 /* Hook the chip's interrupt */ 150 pcctwointr_establish(PCCTWOV_SCSI, osiop_pcctwo_intr, pa->pa_ipl, sc, 151 &sc->sc_evcnt); 152 } 153 154 static int 155 osiop_pcctwo_intr(arg) 156 void *arg; 157 { 158 struct osiop_pcctwo_softc *sc = (struct osiop_pcctwo_softc *) arg; 159 u_char istat; 160 161 /* 162 * Catch any errors which can happen when the SIOP is 163 * local bus master... 164 */ 165 istat = pcc2_reg_read(sys_pcctwo, PCC2REG_SCSI_ERR_STATUS); 166 if ((istat & PCCTWO_ERR_SR_MASK) != 0) { 167 printf("%s: Local bus error: 0x%02x\n", 168 sc->sc_osiop.sc_dev.dv_xname, istat); 169 istat |= PCCTWO_ERR_SR_SCLR; 170 pcc2_reg_write(sys_pcctwo, PCC2REG_SCSI_ERR_STATUS, istat); 171 } 172 173 /* This is potentially nasty, since the IRQ is level triggered... */ 174 if (sc->sc_osiop.sc_flags & OSIOP_INTSOFF) 175 return (0); 176 177 istat = osiop_read_1(&sc->sc_osiop, OSIOP_ISTAT); 178 179 if ((istat & (OSIOP_ISTAT_SIP | OSIOP_ISTAT_DIP)) == 0) 180 return (0); 181 182 /* Save interrupt details for the back-end interrupt handler */ 183 sc->sc_osiop.sc_sstat0 = osiop_read_1(&sc->sc_osiop, OSIOP_SSTAT0); 184 sc->sc_osiop.sc_istat = istat; 185 sc->sc_osiop.sc_dstat = osiop_read_1(&sc->sc_osiop, OSIOP_DSTAT); 186 187 /* Deal with the interrupt */ 188 osiop_intr(&sc->sc_osiop); 189 190 return (1); 191 } 192