1/*	$NetBSD: vme_two_68k.c,v 1.9 2008/04/28 20:23:29 martin 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 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32/*
33 * Front-end for the VMEchip2 found on the MVME-1[67][27] boards.
34 */
35
36#include <sys/cdefs.h>
37__KERNEL_RCSID(0, "$NetBSD: vme_two_68k.c,v 1.9 2008/04/28 20:23:29 martin Exp $");
38
39#include "vmetwo.h"
40
41#include <sys/param.h>
42#include <sys/kernel.h>
43#include <sys/systm.h>
44#include <sys/device.h>
45
46#include <machine/cpu.h>
47#include <machine/bus.h>
48
49#include <dev/vme/vmereg.h>
50#include <dev/vme/vmevar.h>
51
52#include <mvme68k/mvme68k/isr.h>
53#include <mvme68k/dev/mainbus.h>
54
55#include <dev/mvme/mvmebus.h>
56#include <dev/mvme/vme_tworeg.h>
57#include <dev/mvme/vme_twovar.h>
58
59#include "ioconf.h"
60
61static void vmetwoisrlink(void *, int (*)(void *), void *,
62	int, int, struct evcnt *);
63static void vmetwoisrunlink(void *, int);
64static struct evcnt *vmetwoisrevcnt(void *, int);
65
66#if NVMETWO > 0
67
68int vmetwo_match(device_t, cfdata_t, void *);
69void vmetwo_attach(device_t, device_t, void *);
70
71CFATTACH_DECL_NEW(vmetwo, sizeof(struct vmetwo_softc),
72    vmetwo_match, vmetwo_attach, NULL, NULL);
73
74
75/* ARGSUSED */
76int
77vmetwo_match(device_t parent, cfdata_t cf, void *aux)
78{
79	struct mainbus_attach_args *ma;
80	static int matched = 0;
81
82	ma = aux;
83
84	if (strcmp(ma->ma_name, vmetwo_cd.cd_name))
85		return 0;
86
87	/* Only one VMEchip2, please. */
88	if (matched++)
89		return 0;
90
91	/*
92	 * Some mvme1[67]2 boards have a `no VMEchip2' build option...
93	 */
94	return vmetwo_probe(ma->ma_bust, ma->ma_offset) ? 1 : 0;
95}
96
97/* ARGSUSED */
98void
99vmetwo_attach(device_t parent, device_t self, void *aux)
100{
101	struct mainbus_attach_args *ma;
102	struct vmetwo_softc *sc;
103
104	sc = device_private(self);
105	sc->sc_mvmebus.sc_dev = self;
106	ma = aux;
107
108	/*
109	 * Map the local control registers
110	 */
111	bus_space_map(ma->ma_bust, ma->ma_offset + VME2REG_LCSR_OFFSET,
112	    VME2LCSR_SIZE, 0, &sc->sc_lcrh);
113
114#ifdef notyet
115	/*
116	 * Map the global control registers
117	 */
118	bus_space_map(ma->ma_bust, ma->ma_offset + VME2REG_GCSR_OFFSET,
119	    VME2GCSR_SIZE, 0, &sc->sc_gcrh);
120#endif
121
122	/* Initialise stuff for the common vme_two back-end */
123	sc->sc_mvmebus.sc_bust = ma->ma_bust;
124	sc->sc_mvmebus.sc_dmat = ma->ma_dmat;
125
126	vmetwo_init(sc);
127}
128
129#endif	/* NVMETWO > 0 */
130
131void
132vmetwo_md_intr_init(struct vmetwo_softc *sc)
133{
134
135	sc->sc_isrlink = vmetwoisrlink;
136	sc->sc_isrunlink = vmetwoisrunlink;
137	sc->sc_isrevcnt = vmetwoisrevcnt;
138}
139
140/* ARGSUSED */
141static void
142vmetwoisrlink(void *cookie, int (*fn)(void *), void *arg, int ipl, int vec,
143    struct evcnt *evcnt)
144{
145
146	isrlink_vectored(fn, arg, ipl, vec, evcnt);
147}
148
149/* ARGSUSED */
150static void
151vmetwoisrunlink(void *cookie, int vec)
152{
153
154	isrunlink_vectored(vec);
155}
156
157/* ARGSUSED */
158static struct evcnt *
159vmetwoisrevcnt(void *cookie, int ipl)
160{
161
162	return isrlink_evcnt(ipl);
163}
164