xref: /netbsd-src/sys/arch/pmax/tc/tcbus.c (revision 8b0f9554ff8762542c4defc4f70e1eb76fb508fa)
1 /*	$NetBSD: tcbus.c,v 1.20 2006/07/31 00:19:05 ad Exp $	*/
2 
3 /*
4  * Copyright (c) 1999, 2000 Tohru Nishimura.  All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. All advertising materials mentioning features or use of this software
15  *    must display the following acknowledgement:
16  *      This product includes software developed by Tohru Nishimura
17  *	for the NetBSD Project.
18  * 4. The name of the author may not be used to endorse or promote products
19  *    derived from this software without specific prior written permission
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
34 __KERNEL_RCSID(0, "$NetBSD: tcbus.c,v 1.20 2006/07/31 00:19:05 ad Exp $");
35 
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/systm.h>
46 #include <sys/device.h>
47 
48 #include <machine/autoconf.h>
49 #include <machine/sysconf.h>
50 
51 #define	_PMAX_BUS_DMA_PRIVATE
52 #include <machine/bus.h>
53 
54 #include <dev/tc/tcvar.h>
55 #include <pmax/pmax/pmaxtype.h>
56 
57 static const struct evcnt *tc_ds_intr_evcnt __P((struct device *, void *));
58 static void	tc_ds_intr_establish __P((struct device *, void *,
59 				int, int (*)(void *), void *));
60 static void	tc_ds_intr_disestablish __P((struct device *, void *));
61 static bus_dma_tag_t tc_ds_get_dma_tag __P((int));
62 
63 extern struct tcbus_attach_args kn02_tc_desc[];	/* XXX */
64 extern struct tcbus_attach_args kmin_tc_desc[];	/* XXX */
65 extern struct tcbus_attach_args xine_tc_desc[];	/* XXX */
66 extern struct tcbus_attach_args kn03_tc_desc[];	/* XXX */
67 
68 static int	tcbus_match __P((struct device *, struct cfdata *, void *));
69 static void	tcbus_attach __P((struct device *, struct device *, void *));
70 
71 CFATTACH_DECL(tcbus, sizeof(struct tc_softc),
72     tcbus_match, tcbus_attach, NULL, NULL);
73 
74 static int tcbus_found;
75 
76 static int
77 tcbus_match(parent, cfdata, aux)
78 	struct device *parent;
79 	struct cfdata *cfdata;
80 	void *aux;
81 {
82 	struct mainbus_attach_args *ma = aux;
83 
84 	if (tcbus_found || strcmp(ma->ma_name, "tcbus"))
85 		return 0;
86 
87 	return 1;
88 }
89 
90 static void
91 tcbus_attach(parent, self, aux)
92 	struct device *parent, *self;
93 	void *aux;
94 {
95 	struct tcbus_attach_args *tba;
96 
97 	tcbus_found = 1;
98 
99 	switch (systype) {
100 #ifdef DEC_3MAX
101 	case DS_3MAX:
102 		tba = &kn02_tc_desc[0]; break;
103 #endif
104 #ifdef DEC_3MIN
105 	case DS_3MIN:
106 		tba = &kmin_tc_desc[0]; break;
107 #endif
108 #ifdef DEC_MAXINE
109 	case DS_MAXINE:
110 		tba = &xine_tc_desc[0]; break;
111 #endif
112 #ifdef DEC_3MAXPLUS
113 	case DS_3MAXPLUS:
114 		tba = &kn03_tc_desc[0]; break;
115 #endif
116 	default:
117 		panic("tcbus_attach: no TURBOchannel configured for systype = %d", systype);
118 	}
119 
120 	tba->tba_busname = "tc";
121 	tba->tba_memt = 0;
122 	tba->tba_intr_evcnt = tc_ds_intr_evcnt;
123 	tba->tba_intr_establish = tc_ds_intr_establish;
124 	tba->tba_intr_disestablish = tc_ds_intr_disestablish;
125 	tba->tba_get_dma_tag = tc_ds_get_dma_tag;
126 
127 	tcattach(parent, self, tba);
128 }
129 
130 /*
131  * Dispatch to model specific interrupt line evcnt fetch rontine
132  */
133 static const struct evcnt *
134 tc_ds_intr_evcnt(dev, cookie)
135 	struct device *dev;
136 	void *cookie;
137 {
138 
139 	/* XXX for now, no evcnt parent reported */
140 	return NULL;
141 }
142 
143 /*
144  * Dispatch to model specific interrupt establishing routine
145  */
146 static void
147 tc_ds_intr_establish(dev, cookie, level, handler, val)
148 	struct device *dev;
149 	void *cookie;
150 	int level;
151 	int (*handler) __P((void *));
152 	void *val;
153 {
154 
155 	(*platform.intr_establish)(dev, cookie, level, handler, val);
156 }
157 
158 static void
159 tc_ds_intr_disestablish(dev, arg)
160 	struct device *dev;
161 	void *arg;
162 {
163 
164 	printf("cannot disestablish TC interrupts\n");
165 }
166 
167 /*
168  * Return the DMA tag for use by the specified TURBOchannel slot.
169  */
170 static bus_dma_tag_t
171 tc_ds_get_dma_tag(slot)
172 	int slot;
173 {
174 	/*
175 	 * All DECstations use the default DMA tag.
176 	 */
177 	return (&pmax_default_bus_dma_tag);
178 }
179 
180 #include "wsdisplay.h"
181 
182 #if NWSDISPLAY > 0
183 
184 #include "sfb.h"
185 /* #include "sfbp.h" */
186 #include "cfb.h"
187 #include "mfb.h"
188 #include "tfb.h"
189 #include "xcfb.h"
190 #include "px.h"
191 #include "pxg.h"
192 
193 #include <pmax/pmax/cons.h>
194 #include <machine/dec_prom.h>
195 
196 int	tc_checkslot __P((tc_addr_t, char *));
197 
198 struct cnboards {
199 	const char	*cb_tcname;
200 	void	(*cb_cnattach)(tc_addr_t);
201 } static const cnboards[] = {
202 #if NXCFB > 0
203 	{ "PMAG-DV ", xcfb_cnattach },
204 #endif
205 #if NSFB > 0
206 	{ "PMAGB-BA", sfb_cnattach },
207 #endif
208 #if NSFBP > 0
209 	{ "PMAGD   ", sfbp_cnattach },
210 #endif
211 #if NCFB > 0
212 	{ "PMAG-BA ", cfb_cnattach },
213 #endif
214 #if NMFB > 0
215 	{ "PMAG-AA ", mfb_cnattach },
216 #endif
217 #if NTFB > 0
218 	{ "PMAG-JA ", tfb_cnattach },
219 #endif
220 #if NPX > 0
221 	{ "PMAG-CA ", px_cnattach },
222 #endif
223 #if NPXG > 0
224 	{ "PMAG-DA ", pxg_cnattach },
225 	{ "PMAG-FA ", pxg_cnattach },
226 	{ "PMAG-FB ", pxg_cnattach },
227 	{ "PMAGB-FA", pxg_cnattach },
228 	{ "PMAGB-FB", pxg_cnattach },
229 #endif
230 };
231 
232 int
233 tcfb_cnattach(slotno)
234 	int slotno;
235 {
236 	paddr_t tcaddr;
237 	char tcname[TC_ROM_LLEN];
238 	int i;
239 
240 	tcaddr = (*callv->_slot_address)(slotno);
241 	if (tc_badaddr(tcaddr) || tc_checkslot(tcaddr, tcname) == 0)
242 		panic("TC console designated by PROM does not exist!?");
243 
244 	for (i = 0; i < sizeof(cnboards) / sizeof(cnboards[0]); i++)
245 		if (strncmp(tcname, cnboards[i].cb_tcname, TC_ROM_LLEN) == 0)
246 			break;
247 
248 	if (i == sizeof(cnboards) / sizeof(cnboards[0]))
249 		return (0);
250 
251 	(cnboards[i].cb_cnattach)((tc_addr_t)TC_PHYS_TO_UNCACHED(tcaddr));
252 	return (1);
253 }
254 
255 #endif	/* NWSDISPLAY */
256