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