ttwoga.c revision 1.3 1 /* $NetBSD: ttwoga.c,v 1.3 2002/09/27 02:24:09 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe.
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 #include "opt_dec_2100_a500.h"
40 #include "opt_dec_2100a_a500.h"
41
42 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
43
44 __KERNEL_RCSID(0, "$NetBSD: ttwoga.c,v 1.3 2002/09/27 02:24:09 thorpej Exp $");
45
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/kernel.h>
49 #include <sys/malloc.h>
50 #include <sys/device.h>
51
52 #include <machine/autoconf.h>
53 #include <machine/rpb.h>
54
55 #include <dev/isa/isareg.h>
56 #include <dev/isa/isavar.h>
57
58 #include <dev/eisa/eisavar.h>
59
60 #include <dev/pci/pcireg.h>
61 #include <dev/pci/pcivar.h>
62
63 #include <alpha/pci/ttwogareg.h>
64 #include <alpha/pci/ttwogavar.h>
65
66 #if defined(DEC_2100_A500) || defined(DEC_2100A_A500)
67 #include <alpha/pci/pci_2100_a500.h>
68 #endif
69
70 int ttwogamatch(struct device *, struct cfdata *, void *);
71 void ttwogaattach(struct device *, struct device *, void *);
72
73 struct cfattach ttwoga_ca = {
74 sizeof(struct device), ttwogamatch, ttwogaattach
75 };
76
77 int ttwogaprint(void *, const char *);
78
79 int ttwopcimatch(struct device *, struct cfdata *, void *);
80 void ttwopciattach(struct device *, struct device *, void *);
81
82 struct cfattach ttwopci_ca = {
83 sizeof(struct device), ttwopcimatch, ttwopciattach
84 };
85
86 int ttwopciprint(void *, const char *);
87
88 /*
89 * There can be only one, but it might have 2 primary PCI busses.
90 */
91 int ttwogafound;
92 struct ttwoga_config ttwoga_configuration[2];
93
94 /* CBUS address bias for Gamma systems. */
95 bus_addr_t ttwoga_gamma_cbus_bias;
96
97 #define GIGABYTE (1024UL * 1024UL * 1024UL)
98 #define MEGABYTE (1024UL * 1024UL)
99
100 const struct ttwoga_sysmap ttwoga_sysmap[2] = {
101 /* Base System size Bus size */
102 { T2_PCI0_SIO_BASE, 256UL * MEGABYTE, 8UL * MEGABYTE,
103 T2_PCI0_SMEM_BASE, 4UL * GIGABYTE, 128UL * MEGABYTE,
104 T2_PCI0_DMEM_BASE, 1UL * GIGABYTE, 1UL * GIGABYTE,
105 T2_PCI0_CONF_BASE,
106 },
107 { T2_PCI1_SIO_BASE, 256UL * MEGABYTE, 8UL * MEGABYTE,
108 T2_PCI1_SMEM_BASE, 2UL * GIGABYTE, 64UL * MEGABYTE,
109 T2_PCI1_DMEM_BASE, 2UL * GIGABYTE, 2UL * GIGABYTE,
110 T2_PCI1_CONF_BASE,
111 },
112 };
113
114 #undef GIGABYTE
115 #undef MEGABYTE
116
117 int
118 ttwogamatch(struct device *parent, struct cfdata *match, void *aux)
119 {
120 struct mainbus_attach_args *ma = aux;
121
122 /* Make sure that we're looking for a T2 Gate Array. */
123 if (strcmp(ma->ma_name, match->cf_name) != 0)
124 return (0);
125
126 if (ttwogafound)
127 return (0);
128
129 return (1);
130 }
131
132 void
133 ttwogaattach(struct device *parent, struct device *self, void *aux)
134 {
135 struct pcibus_attach_args pba;
136 int hose;
137
138 printf("\n");
139
140 /* note that we've attached the chipset; can't have 2 T2s */
141 ttwogafound = 1;
142
143 /*
144 * Don't do much here; real work is deferred to the ttwopci
145 * layer.
146 */
147 for (hose = 0; hose < 1 /* XXX */; hose++) {
148 #if 0 /* XXX */
149 if (badaddr(_T2GA(hose, T2_IOCSR), sizeof(u_int64_t)))
150 continue;
151 #endif
152 memset(&pba, 0, sizeof(pba));
153 pba.pba_busname = "ttwopci";
154 pba.pba_bus = hose;
155
156 (void) config_found(self, &pba, ttwogaprint);
157 }
158 }
159
160 int
161 ttwogaprint(void *aux, const char *pnp)
162 {
163 struct pcibus_attach_args *pba = aux;
164
165 if (pnp)
166 printf("%s at %s", pba->pba_busname, pnp);
167 printf(" hose %d", pba->pba_bus);
168 return (UNCONF);
169 }
170
171 /*
172 * Set up the chipset's function pointers.
173 */
174 struct ttwoga_config *
175 ttwoga_init(int hose, int mallocsafe)
176 {
177 struct ttwoga_config *tcp;
178
179 if (hose < 0 || hose > 1)
180 panic("ttwoga_init: bad hose # %d", hose);
181
182 tcp = &ttwoga_configuration[hose];
183 tcp->tc_hose = hose;
184
185 tcp->tc_sysmap = &ttwoga_sysmap[hose];
186
187 /*
188 * Sable-Gamma has a CBUS address bias.
189 */
190 ttwoga_gamma_cbus_bias = (alpha_implver() == ALPHA_IMPLVER_EV5) ?
191 T2_GAMMA_CBUS_BIAS : 0;
192
193 alpha_mb();
194
195 tcp->tc_io_bus_start = (T2GA(tcp, T2_HAE0_2) & HAE0_2_PUA2) << 23;
196 tcp->tc_d_mem_bus_start = (T2GA(tcp, T2_HAE0_4) & HAE0_4_PUA1) << 30;
197 tcp->tc_s_mem_bus_start = (T2GA(tcp, T2_HAE0_1) & HAE0_1_PUA1) << 27;
198
199 tcp->tc_rev = (T2GA(tcp, T2_IOCSR) & IOCSR_TRN) >> IOCSR_TRN_SHIFT;
200
201 if (tcp->tc_initted == 0) {
202 /* don't do these twice since they set up extents */
203 ttwoga_bus_io_init(&tcp->tc_iot, tcp);
204 ttwoga_bus_mem_init(&tcp->tc_memt, tcp);
205 }
206 tcp->tc_mallocsafe = mallocsafe;
207
208 ttwoga_pci_init(&tcp->tc_pc, tcp);
209
210 tcp->tc_initted = 1;
211
212 return (tcp);
213 }
214
215 int
216 ttwopcimatch(struct device *parent, struct cfdata *match, void *aux)
217 {
218 struct pcibus_attach_args *pba = aux;
219
220 if (strcmp(pba->pba_busname, match->cf_name) != 0)
221 return (0);
222
223 if (match->cf_loc[PCIBUSCF_BUS] != PCIBUSCF_BUS_DEFAULT &&
224 match->cf_loc[PCIBUSCF_BUS] != pba->pba_bus)
225 return (0);
226
227 return (1);
228 }
229
230 void
231 ttwopciattach(struct device *parent, struct device *self, void *aux)
232 {
233 struct pcibus_attach_args *pba = aux, npba;
234 struct ttwoga_config *tcp;
235
236 /*
237 * set up the chipset's info; done one at console init time
238 * (maybe), but doesn't hurt to do it twice.
239 */
240 tcp = ttwoga_init(pba->pba_bus, 1);
241
242 ttwoga_dma_init(tcp);
243
244 if (tcp->tc_rev < TRN_T3)
245 printf(": T2 Gate Array rev. %d\n", tcp->tc_rev);
246 else
247 printf(": T3 or T4 Gate Array rev. %d\n", tcp->tc_rev);
248
249 if (tcp->tc_rev < 1)
250 printf("%s: WARNING: T2 NOT PASS2... NO BETS...\n",
251 self->dv_xname);
252
253 switch (cputype) {
254 #if defined(DEC_2100_A500) || defined(DEC_2100A_A500)
255 case ST_DEC_2100_A500:
256 case ST_DEC_2100A_A500:
257 pci_2100_a500_pickintr(tcp);
258 break;
259 #endif
260
261 default:
262 panic("ttwogaattach: shouldn't be here, really...");
263 }
264
265 npba.pba_iot = &tcp->tc_iot;
266 npba.pba_memt = &tcp->tc_memt;
267 npba.pba_dmat =
268 alphabus_dma_get_tag(&tcp->tc_dmat_direct, ALPHA_BUS_PCI);
269 npba.pba_pc = &tcp->tc_pc;
270 npba.pba_bus = 0;
271 npba.pba_bridgetag = NULL;
272 npba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED;
273
274 /*
275 * Hose 0 has the STDIO module.
276 */
277 if (pba->pba_bus == 0) {
278 npba.pba_busname = "sableio";
279 (void) config_found(self, &npba, ttwopciprint);
280 }
281
282 npba.pba_busname = "pci";
283 (void) config_found(self, &npba, ttwopciprint);
284 }
285
286 int
287 ttwopciprint(void *aux, const char *pnp)
288 {
289 struct pcibus_attach_args *pba = aux;
290
291 if (pnp)
292 printf("%s at %s", pba->pba_busname, pnp);
293 printf(" bus %d", pba->pba_bus);
294 return (UNCONF);
295 }
296