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