tcbus.c revision 1.28
1/*	$NetBSD: tcbus.c,v 1.28 2011/07/09 17:32:31 matt Exp $	*/
2
3/*-
4 * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Tohru Nishimura.
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#include <sys/cdefs.h>
33__KERNEL_RCSID(0, "$NetBSD: tcbus.c,v 1.28 2011/07/09 17:32:31 matt Exp $");
34
35#define	_PMAX_BUS_DMA_PRIVATE
36/*
37 * Which system models were configured?
38 */
39#include "opt_dec_3max.h"
40#include "opt_dec_3min.h"
41#include "opt_dec_maxine.h"
42#include "opt_dec_3maxplus.h"
43
44#include <sys/param.h>
45#include <sys/bus.h>
46#include <sys/device.h>
47#include <sys/systm.h>
48
49#include <pmax/autoconf.h>
50#include <pmax/sysconf.h>
51
52#include <dev/tc/tcvar.h>
53#include <pmax/pmax/pmaxtype.h>
54
55static const struct evcnt *tc_ds_intr_evcnt(struct device *, void *);
56static void	tc_ds_intr_establish(struct device *, void *,
57				int, int (*)(void *), void *);
58static void	tc_ds_intr_disestablish(struct device *, void *);
59static bus_dma_tag_t tc_ds_get_dma_tag(int);
60
61extern struct tcbus_attach_args kn02_tc_desc[];	/* XXX */
62extern struct tcbus_attach_args kmin_tc_desc[];	/* XXX */
63extern struct tcbus_attach_args xine_tc_desc[];	/* XXX */
64extern struct tcbus_attach_args kn03_tc_desc[];	/* XXX */
65
66static int	tcbus_match(device_t, cfdata_t, void *);
67static void	tcbus_attach(device_t, device_t, void *);
68
69CFATTACH_DECL_NEW(tcbus, sizeof(struct tc_softc),
70    tcbus_match, tcbus_attach, NULL, NULL);
71
72static int tcbus_found;
73
74static int
75tcbus_match(device_t parent, cfdata_t cf, void *aux)
76{
77	struct mainbus_attach_args *ma = aux;
78
79	if (tcbus_found || strcmp(ma->ma_name, "tcbus"))
80		return 0;
81
82	return 1;
83}
84
85static void
86tcbus_attach(device_t parent, device_t self, void *aux)
87{
88	struct tcbus_attach_args *tba;
89
90	tcbus_found = 1;
91
92	switch (systype) {
93#ifdef DEC_3MAX
94	case DS_3MAX:
95		tba = &kn02_tc_desc[0]; break;
96#endif
97#ifdef DEC_3MIN
98	case DS_3MIN:
99		tba = &kmin_tc_desc[0]; break;
100#endif
101#ifdef DEC_MAXINE
102	case DS_MAXINE:
103		tba = &xine_tc_desc[0]; break;
104#endif
105#ifdef DEC_3MAXPLUS
106	case DS_3MAXPLUS:
107		tba = &kn03_tc_desc[0]; break;
108#endif
109	default:
110		panic("tcbus_attach: no TURBOchannel configured for systype = %d", systype);
111	}
112
113	tba->tba_busname = "tc";
114	tba->tba_memt = 0;
115	tba->tba_intr_evcnt = tc_ds_intr_evcnt;
116	tba->tba_intr_establish = tc_ds_intr_establish;
117	tba->tba_intr_disestablish = tc_ds_intr_disestablish;
118	tba->tba_get_dma_tag = tc_ds_get_dma_tag;
119
120	/* XXX why not config_found(9)? */
121	tcattach(parent, self, tba);
122}
123
124/*
125 * Dispatch to model specific interrupt line evcnt fetch rontine
126 */
127static const struct evcnt *
128tc_ds_intr_evcnt(device_t dev, void *cookie)
129{
130
131	/* XXX for now, no evcnt parent reported */
132	return NULL;
133}
134
135/*
136 * Dispatch to model specific interrupt establishing routine
137 */
138static void
139tc_ds_intr_establish(device_t dev, void *cookie, int level,
140    int (*handler)(void *), void *val)
141{
142
143	(*platform.intr_establish)(dev, cookie, level, handler, val);
144}
145
146static void
147tc_ds_intr_disestablish(device_t dev, void *arg)
148{
149
150	printf("cannot disestablish TC interrupts\n");
151}
152
153/*
154 * Return the DMA tag for use by the specified TURBOchannel slot.
155 */
156static bus_dma_tag_t
157tc_ds_get_dma_tag(int slot)
158{
159	/*
160	 * All DECstations use the default DMA tag.
161	 */
162	return (&pmax_default_bus_dma_tag);
163}
164
165#include "wsdisplay.h"
166
167#if NWSDISPLAY > 0
168
169#include "sfb.h"
170/* #include "sfbp.h" */
171#include "cfb.h"
172#include "mfb.h"
173#include "tfb.h"
174#include "xcfb.h"
175#include "px.h"
176#include "pxg.h"
177
178#include <pmax/pmax/cons.h>
179#include <pmax/dec_prom.h>
180
181int	tc_checkslot(tc_addr_t, char *);
182
183struct cnboards {
184	const char	*cb_tcname;
185	void	(*cb_cnattach)(tc_addr_t);
186} static const cnboards[] = {
187#if NXCFB > 0
188	{ "PMAG-DV ", xcfb_cnattach },
189#endif
190#if NSFB > 0
191	{ "PMAGB-BA", sfb_cnattach },
192#endif
193#if NSFBP > 0
194	{ "PMAGD   ", sfbp_cnattach },
195#endif
196#if NCFB > 0
197	{ "PMAG-BA ", cfb_cnattach },
198#endif
199#if NMFB > 0
200	{ "PMAG-AA ", mfb_cnattach },
201#endif
202#if NTFB > 0
203	{ "PMAG-JA ", tfb_cnattach },
204#endif
205#if NPX > 0
206	{ "PMAG-CA ", px_cnattach },
207#endif
208#if NPXG > 0
209	{ "PMAG-DA ", pxg_cnattach },
210	{ "PMAG-FA ", pxg_cnattach },
211	{ "PMAG-FB ", pxg_cnattach },
212	{ "PMAGB-FA", pxg_cnattach },
213	{ "PMAGB-FB", pxg_cnattach },
214#endif
215};
216
217int
218tcfb_cnattach(int slotno)
219{
220	paddr_t tcaddr;
221	char tcname[TC_ROM_LLEN];
222	int i;
223
224	tcaddr = promcall(callv->_slot_address, slotno);
225	if (tc_badaddr(tcaddr) || tc_checkslot(tcaddr, tcname) == 0)
226		panic("TC console designated by PROM does not exist!?");
227
228	for (i = 0; i < __arraycount(cnboards); i++) {
229		if (strncmp(tcname, cnboards[i].cb_tcname, TC_ROM_LLEN) == 0)
230			break;
231	}
232
233	if (i == __arraycount(cnboards))
234		return (0);
235
236	(cnboards[i].cb_cnattach)((tc_addr_t)TC_PHYS_TO_UNCACHED(tcaddr));
237	return (1);
238}
239
240#endif	/* NWSDISPLAY */
241