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