xref: /netbsd/sys/arch/mvme68k/dev/vme_two_68k.c (revision c4a72b64)
1 /*	$NetBSD: vme_two_68k.c,v 1.5 2002/10/02 05:28:15 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 for the VMEchip2 found on the MVME-1[67][27] boards.
41  */
42 
43 #include "vmetwo.h"
44 
45 #include <sys/param.h>
46 #include <sys/kernel.h>
47 #include <sys/systm.h>
48 #include <sys/device.h>
49 
50 #include <machine/cpu.h>
51 #include <machine/bus.h>
52 
53 #include <dev/vme/vmereg.h>
54 #include <dev/vme/vmevar.h>
55 
56 #include <mvme68k/mvme68k/isr.h>
57 #include <mvme68k/dev/mainbus.h>
58 
59 #include <dev/mvme/mvmebus.h>
60 #include <dev/mvme/vme_tworeg.h>
61 #include <dev/mvme/vme_twovar.h>
62 
63 
64 static void vmetwoisrlink(void *, int (*)(void *), void *,
65 	int, int, struct evcnt *);
66 static void vmetwoisrunlink(void *, int);
67 static struct evcnt *vmetwoisrevcnt(void *, int);
68 
69 #if NVMETWO > 0
70 
71 int vmetwo_match __P((struct device *, struct cfdata *, void *));
72 void vmetwo_attach __P((struct device *, struct device *, void *));
73 
74 CFATTACH_DECL(vmetwo, sizeof(struct vmetwo_softc),
75     vmetwo_match, vmetwo_attach, NULL, NULL);
76 extern struct cfdriver vmetwo_cd;
77 
78 
79 /* ARGSUSED */
80 int
81 vmetwo_match(parent, cf, aux)
82 	struct device *parent;
83 	struct cfdata *cf;
84 	void *aux;
85 {
86 	struct mainbus_attach_args *ma;
87 	static int matched = 0;
88 
89 	ma = aux;
90 
91 	if (strcmp(ma->ma_name, vmetwo_cd.cd_name))
92 		return (0);
93 
94 	/* Only one VMEchip2, please. */
95 	if (matched++)
96 		return (0);
97 
98 	/*
99 	 * Some mvme1[67]2 boards have a `no VMEchip2' build option...
100 	 */
101 	return (vmetwo_probe(ma->ma_bust, ma->ma_offset) ? 1 : 0);
102 }
103 
104 /* ARGSUSED */
105 void
106 vmetwo_attach(parent, self, aux)
107 	struct device *parent;
108 	struct device *self;
109 	void *aux;
110 {
111 	struct mainbus_attach_args *ma;
112 	struct vmetwo_softc *sc;
113 
114 	sc = (struct vmetwo_softc *) self;
115 	ma = aux;
116 
117 	/*
118 	 * Map the local control registers
119 	 */
120 	bus_space_map(ma->ma_bust, ma->ma_offset + VME2REG_LCSR_OFFSET,
121 	    VME2LCSR_SIZE, 0, &sc->sc_lcrh);
122 
123 #ifdef notyet
124 	/*
125 	 * Map the global control registers
126 	 */
127 	bus_space_map(ma->ma_bust, ma->ma_offset + VME2REG_GCSR_OFFSET,
128 	    VME2GCSR_SIZE, 0, &sc->sc_gcrh);
129 #endif
130 
131 	/* Initialise stuff for the common vme_two back-end */
132 	sc->sc_mvmebus.sc_bust = ma->ma_bust;
133 	sc->sc_mvmebus.sc_dmat = ma->ma_dmat;
134 
135 	vmetwo_init(sc);
136 }
137 
138 #endif	/* NVMETWO > 0 */
139 
140 void
141 vmetwo_md_intr_init(sc)
142 	struct vmetwo_softc *sc;
143 {
144 
145 	sc->sc_isrlink = vmetwoisrlink;
146 	sc->sc_isrunlink = vmetwoisrunlink;
147 	sc->sc_isrevcnt = vmetwoisrevcnt;
148 }
149 
150 /* ARGSUSED */
151 static void
152 vmetwoisrlink(cookie, fn, arg, ipl, vec, evcnt)
153 	void *cookie;
154 	int (*fn)(void *);
155 	void *arg;
156 	int ipl, vec;
157 	struct evcnt *evcnt;
158 {
159 
160 	isrlink_vectored(fn, arg, ipl, vec, evcnt);
161 }
162 
163 /* ARGSUSED */
164 static void
165 vmetwoisrunlink(cookie, vec)
166 	void *cookie;
167 	int vec;
168 {
169 
170 	isrunlink_vectored(vec);
171 }
172 
173 /* ARGSUSED */
174 static struct evcnt *
175 vmetwoisrevcnt(cookie, ipl)
176 	void *cookie;
177 	int ipl;
178 {
179 
180 	return (isrlink_evcnt(ipl));
181 }
182