Home | History | Annotate | Line # | Download | only in mvme
osiop_pcctwo.c revision 1.10
      1  1.10  thorpej /*	$NetBSD: osiop_pcctwo.c,v 1.10 2006/03/29 07:07:41 thorpej Exp $	*/
      2   1.1      scw 
      3   1.1      scw /*-
      4   1.1      scw  * Copyright (c) 1999, 2002 The NetBSD Foundation, Inc.
      5   1.1      scw  * All rights reserved.
      6   1.1      scw  *
      7   1.1      scw  * This code is derived from software contributed to The NetBSD Foundation
      8   1.1      scw  * by Steve C. Woodford.
      9   1.1      scw  *
     10   1.1      scw  * Redistribution and use in source and binary forms, with or without
     11   1.1      scw  * modification, are permitted provided that the following conditions
     12   1.1      scw  * are met:
     13   1.1      scw  * 1. Redistributions of source code must retain the above copyright
     14   1.1      scw  *    notice, this list of conditions and the following disclaimer.
     15   1.1      scw  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1      scw  *    notice, this list of conditions and the following disclaimer in the
     17   1.1      scw  *    documentation and/or other materials provided with the distribution.
     18   1.1      scw  * 3. All advertising materials mentioning features or use of this software
     19   1.1      scw  *    must display the following acknowledgement:
     20   1.1      scw  *	This product includes software developed by the NetBSD
     21   1.1      scw  *	Foundation, Inc. and its contributors.
     22   1.1      scw  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23   1.1      scw  *    contributors may be used to endorse or promote products derived
     24   1.1      scw  *    from this software without specific prior written permission.
     25   1.1      scw  *
     26   1.1      scw  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27   1.1      scw  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28   1.1      scw  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29   1.1      scw  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30   1.1      scw  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31   1.1      scw  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32   1.1      scw  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33   1.1      scw  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34   1.1      scw  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35   1.1      scw  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36   1.1      scw  * POSSIBILITY OF SUCH DAMAGE.
     37   1.1      scw  */
     38   1.1      scw 
     39   1.1      scw /*
     40   1.1      scw  * Front-end attachment code for the ncr53c710 SCSI controller
     41   1.1      scw  * on mvme68k/mvme88k boards.
     42   1.1      scw  */
     43   1.5    lukem 
     44   1.5    lukem #include <sys/cdefs.h>
     45  1.10  thorpej __KERNEL_RCSID(0, "$NetBSD: osiop_pcctwo.c,v 1.10 2006/03/29 07:07:41 thorpej Exp $");
     46   1.1      scw 
     47   1.1      scw #include <sys/param.h>
     48   1.1      scw #include <sys/systm.h>
     49   1.1      scw #include <sys/kernel.h>
     50   1.1      scw #include <sys/device.h>
     51   1.1      scw 
     52   1.1      scw #include <dev/scsipi/scsi_all.h>
     53   1.1      scw #include <dev/scsipi/scsipi_all.h>
     54   1.1      scw #include <dev/scsipi/scsiconf.h>
     55   1.1      scw 
     56   1.1      scw #include <machine/cpu.h>
     57   1.1      scw #include <machine/bus.h>
     58   1.1      scw #include <machine/autoconf.h>
     59   1.1      scw 
     60   1.1      scw #include <dev/ic/osiopreg.h>
     61   1.1      scw #include <dev/ic/osiopvar.h>
     62   1.1      scw 
     63   1.1      scw #include <dev/mvme/pcctworeg.h>
     64   1.1      scw #include <dev/mvme/pcctwovar.h>
     65   1.1      scw 
     66   1.1      scw 
     67   1.8    perry int osiop_pcctwo_match(struct device *, struct cfdata *, void *);
     68   1.8    perry void osiop_pcctwo_attach(struct device *, struct device *, void *);
     69   1.1      scw 
     70   1.1      scw struct osiop_pcctwo_softc {
     71   1.1      scw 	struct osiop_softc	sc_osiop;
     72   1.1      scw 	struct evcnt		sc_evcnt;
     73   1.1      scw };
     74   1.1      scw 
     75   1.3  thorpej CFATTACH_DECL(osiop_pcctwo, sizeof(struct osiop_pcctwo_softc),
     76   1.4  thorpej     osiop_pcctwo_match, osiop_pcctwo_attach, NULL, NULL);
     77   1.1      scw 
     78   1.8    perry static int osiop_pcctwo_intr(void *);
     79   1.1      scw 
     80   1.1      scw extern struct cfdriver osiop_cd;
     81   1.1      scw 
     82   1.1      scw /* ARGSUSED */
     83   1.1      scw int
     84   1.1      scw osiop_pcctwo_match(parent, cf, args)
     85   1.1      scw 	struct device *parent;
     86   1.1      scw 	struct cfdata *cf;
     87   1.1      scw 	void *args;
     88   1.1      scw {
     89   1.1      scw 	struct pcctwo_attach_args *pa;
     90   1.6      scw 	bus_space_handle_t bsh;
     91   1.6      scw 	int rv;
     92   1.1      scw 
     93   1.1      scw 	pa = args;
     94   1.1      scw 
     95   1.1      scw 	if (strcmp(pa->pa_name, osiop_cd.cd_name))
     96   1.6      scw 		return (0);
     97   1.6      scw 
     98   1.6      scw 	/*
     99   1.6      scw 	 * See if the SCSI controller is responding.
    100   1.6      scw 	 */
    101   1.6      scw 	if (bus_space_map(pa->pa_bust, pa->pa_offset, OSIOP_NREGS, 0, &bsh))
    102   1.6      scw 		return (0);
    103   1.6      scw 	rv = bus_space_peek_1(pa->pa_bust, bsh, OSIOP_CTEST8, NULL);
    104   1.6      scw 	bus_space_unmap(pa->pa_bust, bsh, OSIOP_NREGS);
    105   1.6      scw 	if (rv)
    106   1.1      scw 		return (0);
    107   1.1      scw 
    108   1.1      scw 	pa->pa_ipl = cf->pcctwocf_ipl;
    109   1.1      scw 
    110   1.1      scw 	return (1);
    111   1.1      scw }
    112   1.1      scw 
    113   1.1      scw /* ARGSUSED */
    114   1.1      scw void
    115   1.1      scw osiop_pcctwo_attach(parent, self, args)
    116   1.1      scw 	struct device *parent;
    117   1.1      scw 	struct device *self;
    118   1.1      scw 	void *args;
    119   1.1      scw {
    120   1.1      scw 	struct pcctwo_attach_args *pa;
    121   1.1      scw 	struct osiop_pcctwo_softc *sc;
    122   1.1      scw 	int clk, ctest7;
    123   1.1      scw 
    124   1.1      scw 	pa = (struct pcctwo_attach_args *) args;
    125  1.10  thorpej 	sc = device_private(self);
    126   1.1      scw 
    127   1.1      scw 	/*
    128   1.7      wiz 	 * On the '17x the siop's clock is the same as the CPU clock.
    129   1.7      wiz 	 * On the other boards, the siop runs at twice the CPU clock.
    130   1.1      scw 	 * Also, the 17x cannot do proper bus-snooping (the 68060 is
    131   1.1      scw 	 * lame in this repspect) so don't enable it on that board.
    132   1.1      scw 	 */
    133   1.1      scw #ifdef MVME68K
    134   1.1      scw 	if (machineid == MVME_172 || machineid == MVME_177) {
    135   1.1      scw 		clk = cpuspeed;
    136   1.1      scw 		ctest7 = 0;
    137   1.1      scw 	} else {
    138   1.1      scw 		clk = cpuspeed * 2;
    139   1.1      scw 		ctest7 = OSIOP_CTEST7_SC0;
    140   1.1      scw 	}
    141   1.1      scw #else
    142   1.1      scw #error Set up siop clock speed for mvme187
    143   1.1      scw #endif
    144   1.1      scw 
    145   1.1      scw 	sc->sc_osiop.sc_bst = pa->pa_bust;
    146   1.1      scw 	sc->sc_osiop.sc_dmat = pa->pa_dmat;
    147   1.1      scw 	(void) bus_space_map(sc->sc_osiop.sc_bst, pa->pa_offset, OSIOP_NREGS,
    148   1.1      scw 	    0, &sc->sc_osiop.sc_reg);
    149   1.1      scw 
    150   1.1      scw 	sc->sc_osiop.sc_clock_freq = clk;
    151   1.1      scw 	sc->sc_osiop.sc_ctest7 = ctest7 | OSIOP_CTEST7_TT1;
    152   1.1      scw 	sc->sc_osiop.sc_dcntl = OSIOP_DCNTL_EA;
    153   1.1      scw 	sc->sc_osiop.sc_id = 7;	/* XXX: Could use NVRAM setting */
    154   1.1      scw 
    155   1.1      scw 	/* Attach main MI driver */
    156   1.1      scw 	osiop_attach(&sc->sc_osiop);
    157   1.1      scw 
    158   1.1      scw 	/* Register the event counter */
    159   1.1      scw 	evcnt_attach_dynamic(&sc->sc_evcnt, EVCNT_TYPE_INTR,
    160   1.1      scw 	    pcctwointr_evcnt(pa->pa_ipl), "disk", sc->sc_osiop.sc_dev.dv_xname);
    161   1.1      scw 
    162   1.1      scw 	/* Hook the chip's interrupt */
    163   1.1      scw 	pcctwointr_establish(PCCTWOV_SCSI, osiop_pcctwo_intr, pa->pa_ipl, sc,
    164   1.1      scw 	    &sc->sc_evcnt);
    165   1.1      scw }
    166   1.1      scw 
    167   1.1      scw static int
    168   1.1      scw osiop_pcctwo_intr(arg)
    169   1.1      scw 	void *arg;
    170   1.1      scw {
    171   1.1      scw 	struct osiop_pcctwo_softc *sc = (struct osiop_pcctwo_softc *) arg;
    172   1.1      scw 	u_char istat;
    173   1.1      scw 
    174   1.1      scw 	/*
    175   1.1      scw 	 * Catch any errors which can happen when the SIOP is
    176   1.1      scw 	 * local bus master...
    177   1.1      scw 	 */
    178   1.1      scw 	istat = pcc2_reg_read(sys_pcctwo, PCC2REG_SCSI_ERR_STATUS);
    179   1.1      scw 	if ((istat & PCCTWO_ERR_SR_MASK) != 0) {
    180   1.1      scw 		printf("%s: Local bus error: 0x%02x\n",
    181   1.1      scw 		    sc->sc_osiop.sc_dev.dv_xname, istat);
    182   1.1      scw 		istat |= PCCTWO_ERR_SR_SCLR;
    183   1.1      scw 		pcc2_reg_write(sys_pcctwo, PCC2REG_SCSI_ERR_STATUS, istat);
    184   1.1      scw 	}
    185   1.1      scw 
    186   1.1      scw 	/* This is potentially nasty, since the IRQ is level triggered... */
    187   1.1      scw 	if (sc->sc_osiop.sc_flags & OSIOP_INTSOFF)
    188   1.1      scw 		return (0);
    189   1.1      scw 
    190   1.1      scw 	istat = osiop_read_1(&sc->sc_osiop, OSIOP_ISTAT);
    191   1.1      scw 
    192   1.1      scw 	if ((istat & (OSIOP_ISTAT_SIP | OSIOP_ISTAT_DIP)) == 0)
    193   1.1      scw 		return (0);
    194   1.1      scw 
    195   1.1      scw 	/* Save interrupt details for the back-end interrupt handler */
    196   1.1      scw 	sc->sc_osiop.sc_sstat0 = osiop_read_1(&sc->sc_osiop, OSIOP_SSTAT0);
    197   1.1      scw 	sc->sc_osiop.sc_istat = istat;
    198   1.1      scw 	sc->sc_osiop.sc_dstat = osiop_read_1(&sc->sc_osiop, OSIOP_DSTAT);
    199   1.1      scw 
    200   1.1      scw 	/* Deal with the interrupt */
    201   1.1      scw 	osiop_intr(&sc->sc_osiop);
    202   1.1      scw 
    203   1.1      scw 	return (1);
    204   1.1      scw }
    205