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