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