ttwoga.c revision 1.1.2.2 1 1.1.2.2 bouyer /* $NetBSD: ttwoga.c,v 1.1.2.2 2001/01/05 17:33:49 bouyer Exp $ */
2 1.1.2.2 bouyer
3 1.1.2.2 bouyer /*-
4 1.1.2.2 bouyer * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 1.1.2.2 bouyer * All rights reserved.
6 1.1.2.2 bouyer *
7 1.1.2.2 bouyer * This code is derived from software contributed to The NetBSD Foundation
8 1.1.2.2 bouyer * by Jason R. Thorpe.
9 1.1.2.2 bouyer *
10 1.1.2.2 bouyer * Redistribution and use in source and binary forms, with or without
11 1.1.2.2 bouyer * modification, are permitted provided that the following conditions
12 1.1.2.2 bouyer * are met:
13 1.1.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
14 1.1.2.2 bouyer * notice, this list of conditions and the following disclaimer.
15 1.1.2.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.2.2 bouyer * notice, this list of conditions and the following disclaimer in the
17 1.1.2.2 bouyer * documentation and/or other materials provided with the distribution.
18 1.1.2.2 bouyer * 3. All advertising materials mentioning features or use of this software
19 1.1.2.2 bouyer * must display the following acknowledgement:
20 1.1.2.2 bouyer * This product includes software developed by the NetBSD
21 1.1.2.2 bouyer * Foundation, Inc. and its contributors.
22 1.1.2.2 bouyer * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1.2.2 bouyer * contributors may be used to endorse or promote products derived
24 1.1.2.2 bouyer * from this software without specific prior written permission.
25 1.1.2.2 bouyer *
26 1.1.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1.2.2 bouyer * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1.2.2 bouyer * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1.2.2 bouyer * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1.2.2 bouyer * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1.2.2 bouyer * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1.2.2 bouyer * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1.2.2 bouyer * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1.2.2 bouyer * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1.2.2 bouyer * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1.2.2 bouyer * POSSIBILITY OF SUCH DAMAGE.
37 1.1.2.2 bouyer */
38 1.1.2.2 bouyer
39 1.1.2.2 bouyer #include "opt_dec_2100_a500.h"
40 1.1.2.2 bouyer #include "opt_dec_2100a_a500.h"
41 1.1.2.2 bouyer
42 1.1.2.2 bouyer #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
43 1.1.2.2 bouyer
44 1.1.2.2 bouyer __KERNEL_RCSID(0, "$NetBSD: ttwoga.c,v 1.1.2.2 2001/01/05 17:33:49 bouyer Exp $");
45 1.1.2.2 bouyer
46 1.1.2.2 bouyer #include <sys/param.h>
47 1.1.2.2 bouyer #include <sys/systm.h>
48 1.1.2.2 bouyer #include <sys/kernel.h>
49 1.1.2.2 bouyer #include <sys/malloc.h>
50 1.1.2.2 bouyer #include <sys/device.h>
51 1.1.2.2 bouyer
52 1.1.2.2 bouyer #include <machine/autoconf.h>
53 1.1.2.2 bouyer #include <machine/rpb.h>
54 1.1.2.2 bouyer
55 1.1.2.2 bouyer #include <dev/isa/isareg.h>
56 1.1.2.2 bouyer #include <dev/isa/isavar.h>
57 1.1.2.2 bouyer
58 1.1.2.2 bouyer #include <dev/eisa/eisavar.h>
59 1.1.2.2 bouyer
60 1.1.2.2 bouyer #include <dev/pci/pcireg.h>
61 1.1.2.2 bouyer #include <dev/pci/pcivar.h>
62 1.1.2.2 bouyer
63 1.1.2.2 bouyer #include <alpha/pci/ttwogareg.h>
64 1.1.2.2 bouyer #include <alpha/pci/ttwogavar.h>
65 1.1.2.2 bouyer
66 1.1.2.2 bouyer #if defined(DEC_2100_A500) || defined(DEC_2100A_A500)
67 1.1.2.2 bouyer #include <alpha/pci/pci_2100_a500.h>
68 1.1.2.2 bouyer #endif
69 1.1.2.2 bouyer
70 1.1.2.2 bouyer int ttwogamatch(struct device *, struct cfdata *, void *);
71 1.1.2.2 bouyer void ttwogaattach(struct device *, struct device *, void *);
72 1.1.2.2 bouyer
73 1.1.2.2 bouyer struct cfattach ttwoga_ca = {
74 1.1.2.2 bouyer sizeof(struct device), ttwogamatch, ttwogaattach
75 1.1.2.2 bouyer };
76 1.1.2.2 bouyer
77 1.1.2.2 bouyer int ttwogaprint(void *, const char *);
78 1.1.2.2 bouyer
79 1.1.2.2 bouyer int ttwopcimatch(struct device *, struct cfdata *, void *);
80 1.1.2.2 bouyer void ttwopciattach(struct device *, struct device *, void *);
81 1.1.2.2 bouyer
82 1.1.2.2 bouyer struct cfattach ttwopci_ca = {
83 1.1.2.2 bouyer sizeof(struct device), ttwopcimatch, ttwopciattach
84 1.1.2.2 bouyer };
85 1.1.2.2 bouyer
86 1.1.2.2 bouyer int ttwopciprint(void *, const char *);
87 1.1.2.2 bouyer
88 1.1.2.2 bouyer /*
89 1.1.2.2 bouyer * There can be only one, but it might have 2 primary PCI busses.
90 1.1.2.2 bouyer */
91 1.1.2.2 bouyer int ttwogafound;
92 1.1.2.2 bouyer struct ttwoga_config ttwoga_configuration[2];
93 1.1.2.2 bouyer
94 1.1.2.2 bouyer /* CBUS address bias for Gamma systems. */
95 1.1.2.2 bouyer bus_addr_t ttwoga_gamma_cbus_bias;
96 1.1.2.2 bouyer
97 1.1.2.2 bouyer #define GIGABYTE (1024UL * 1024UL * 1024UL)
98 1.1.2.2 bouyer #define MEGABYTE (1024UL * 1024UL)
99 1.1.2.2 bouyer
100 1.1.2.2 bouyer const struct ttwoga_sysmap ttwoga_sysmap[2] = {
101 1.1.2.2 bouyer /* Base System size Bus size */
102 1.1.2.2 bouyer { T2_PCI0_SIO_BASE, 256UL * MEGABYTE, 8UL * MEGABYTE,
103 1.1.2.2 bouyer T2_PCI0_SMEM_BASE, 4UL * GIGABYTE, 128UL * MEGABYTE,
104 1.1.2.2 bouyer T2_PCI0_DMEM_BASE, 1UL * GIGABYTE, 1UL * GIGABYTE,
105 1.1.2.2 bouyer T2_PCI0_CONF_BASE,
106 1.1.2.2 bouyer },
107 1.1.2.2 bouyer { T2_PCI1_SIO_BASE, 256UL * MEGABYTE, 8UL * MEGABYTE,
108 1.1.2.2 bouyer T2_PCI1_SMEM_BASE, 2UL * GIGABYTE, 64UL * MEGABYTE,
109 1.1.2.2 bouyer T2_PCI1_DMEM_BASE, 2UL * GIGABYTE, 2UL * GIGABYTE,
110 1.1.2.2 bouyer T2_PCI1_CONF_BASE,
111 1.1.2.2 bouyer },
112 1.1.2.2 bouyer };
113 1.1.2.2 bouyer
114 1.1.2.2 bouyer #undef GIGABYTE
115 1.1.2.2 bouyer #undef MEGABYTE
116 1.1.2.2 bouyer
117 1.1.2.2 bouyer int
118 1.1.2.2 bouyer ttwogamatch(struct device *parent, struct cfdata *match, void *aux)
119 1.1.2.2 bouyer {
120 1.1.2.2 bouyer struct mainbus_attach_args *ma = aux;
121 1.1.2.2 bouyer
122 1.1.2.2 bouyer /* Make sure that we're looking for a T2 Gate Array. */
123 1.1.2.2 bouyer if (strcmp(ma->ma_name, match->cf_driver->cd_name) != 0)
124 1.1.2.2 bouyer return (0);
125 1.1.2.2 bouyer
126 1.1.2.2 bouyer if (ttwogafound)
127 1.1.2.2 bouyer return (0);
128 1.1.2.2 bouyer
129 1.1.2.2 bouyer return (1);
130 1.1.2.2 bouyer }
131 1.1.2.2 bouyer
132 1.1.2.2 bouyer void
133 1.1.2.2 bouyer ttwogaattach(struct device *parent, struct device *self, void *aux)
134 1.1.2.2 bouyer {
135 1.1.2.2 bouyer struct pcibus_attach_args pba;
136 1.1.2.2 bouyer int hose;
137 1.1.2.2 bouyer
138 1.1.2.2 bouyer printf("\n");
139 1.1.2.2 bouyer
140 1.1.2.2 bouyer /* note that we've attached the chipset; can't have 2 T2s */
141 1.1.2.2 bouyer ttwogafound = 1;
142 1.1.2.2 bouyer
143 1.1.2.2 bouyer /*
144 1.1.2.2 bouyer * Don't do much here; real work is deferred to the ttwopci
145 1.1.2.2 bouyer * layer.
146 1.1.2.2 bouyer */
147 1.1.2.2 bouyer for (hose = 0; hose < 1 /* XXX */; hose++) {
148 1.1.2.2 bouyer #if 0 /* XXX */
149 1.1.2.2 bouyer if (badaddr(_T2GA(hose, T2_IOCSR), sizeof(u_int64_t)))
150 1.1.2.2 bouyer continue;
151 1.1.2.2 bouyer #endif
152 1.1.2.2 bouyer memset(&pba, 0, sizeof(pba));
153 1.1.2.2 bouyer pba.pba_busname = "ttwopci";
154 1.1.2.2 bouyer pba.pba_bus = hose;
155 1.1.2.2 bouyer
156 1.1.2.2 bouyer (void) config_found(self, &pba, ttwogaprint);
157 1.1.2.2 bouyer }
158 1.1.2.2 bouyer }
159 1.1.2.2 bouyer
160 1.1.2.2 bouyer int
161 1.1.2.2 bouyer ttwogaprint(void *aux, const char *pnp)
162 1.1.2.2 bouyer {
163 1.1.2.2 bouyer struct pcibus_attach_args *pba = aux;
164 1.1.2.2 bouyer
165 1.1.2.2 bouyer if (pnp)
166 1.1.2.2 bouyer printf("%s at %s", pba->pba_busname, pnp);
167 1.1.2.2 bouyer printf(" hose %d", pba->pba_bus);
168 1.1.2.2 bouyer return (UNCONF);
169 1.1.2.2 bouyer }
170 1.1.2.2 bouyer
171 1.1.2.2 bouyer /*
172 1.1.2.2 bouyer * Set up the chipset's function pointers.
173 1.1.2.2 bouyer */
174 1.1.2.2 bouyer struct ttwoga_config *
175 1.1.2.2 bouyer ttwoga_init(int hose, int mallocsafe)
176 1.1.2.2 bouyer {
177 1.1.2.2 bouyer struct ttwoga_config *tcp;
178 1.1.2.2 bouyer
179 1.1.2.2 bouyer if (hose < 0 || hose > 1)
180 1.1.2.2 bouyer panic("ttwoga_init: bad hose # %d", hose);
181 1.1.2.2 bouyer
182 1.1.2.2 bouyer tcp = &ttwoga_configuration[hose];
183 1.1.2.2 bouyer tcp->tc_hose = hose;
184 1.1.2.2 bouyer
185 1.1.2.2 bouyer tcp->tc_sysmap = &ttwoga_sysmap[hose];
186 1.1.2.2 bouyer
187 1.1.2.2 bouyer /*
188 1.1.2.2 bouyer * Sable-Gamma has a CBUS address bias.
189 1.1.2.2 bouyer */
190 1.1.2.2 bouyer ttwoga_gamma_cbus_bias = (alpha_implver() == ALPHA_IMPLVER_EV5) ?
191 1.1.2.2 bouyer T2_GAMMA_CBUS_BIAS : 0;
192 1.1.2.2 bouyer
193 1.1.2.2 bouyer alpha_mb();
194 1.1.2.2 bouyer
195 1.1.2.2 bouyer tcp->tc_io_bus_start = (T2GA(tcp, T2_HAE0_2) & HAE0_2_PUA2) << 23;
196 1.1.2.2 bouyer tcp->tc_d_mem_bus_start = (T2GA(tcp, T2_HAE0_4) & HAE0_4_PUA1) << 30;
197 1.1.2.2 bouyer tcp->tc_s_mem_bus_start = (T2GA(tcp, T2_HAE0_1) & HAE0_1_PUA1) << 27;
198 1.1.2.2 bouyer
199 1.1.2.2 bouyer tcp->tc_rev = (T2GA(tcp, T2_IOCSR) & IOCSR_TRN) >> IOCSR_TRN_SHIFT;
200 1.1.2.2 bouyer
201 1.1.2.2 bouyer if (tcp->tc_initted == 0) {
202 1.1.2.2 bouyer /* don't do these twice since they set up extents */
203 1.1.2.2 bouyer ttwoga_bus_io_init(&tcp->tc_iot, tcp);
204 1.1.2.2 bouyer ttwoga_bus_mem_init(&tcp->tc_memt, tcp);
205 1.1.2.2 bouyer }
206 1.1.2.2 bouyer tcp->tc_mallocsafe = mallocsafe;
207 1.1.2.2 bouyer
208 1.1.2.2 bouyer ttwoga_pci_init(&tcp->tc_pc, tcp);
209 1.1.2.2 bouyer
210 1.1.2.2 bouyer tcp->tc_initted = 1;
211 1.1.2.2 bouyer
212 1.1.2.2 bouyer return (tcp);
213 1.1.2.2 bouyer }
214 1.1.2.2 bouyer
215 1.1.2.2 bouyer int
216 1.1.2.2 bouyer ttwopcimatch(struct device *parent, struct cfdata *match, void *aux)
217 1.1.2.2 bouyer {
218 1.1.2.2 bouyer struct pcibus_attach_args *pba = aux;
219 1.1.2.2 bouyer
220 1.1.2.2 bouyer if (strcmp(pba->pba_busname, match->cf_driver->cd_name) != 0)
221 1.1.2.2 bouyer return (0);
222 1.1.2.2 bouyer
223 1.1.2.2 bouyer if (match->cf_loc[PCIBUSCF_BUS] != PCIBUSCF_BUS_DEFAULT &&
224 1.1.2.2 bouyer match->cf_loc[PCIBUSCF_BUS] != pba->pba_bus)
225 1.1.2.2 bouyer return (0);
226 1.1.2.2 bouyer
227 1.1.2.2 bouyer return (1);
228 1.1.2.2 bouyer }
229 1.1.2.2 bouyer
230 1.1.2.2 bouyer void
231 1.1.2.2 bouyer ttwopciattach(struct device *parent, struct device *self, void *aux)
232 1.1.2.2 bouyer {
233 1.1.2.2 bouyer struct pcibus_attach_args *pba = aux, npba;
234 1.1.2.2 bouyer struct ttwoga_config *tcp;
235 1.1.2.2 bouyer
236 1.1.2.2 bouyer /*
237 1.1.2.2 bouyer * set up the chipset's info; done one at console init time
238 1.1.2.2 bouyer * (maybe), but doesn't hurt to do it twice.
239 1.1.2.2 bouyer */
240 1.1.2.2 bouyer tcp = ttwoga_init(pba->pba_bus, 1);
241 1.1.2.2 bouyer
242 1.1.2.2 bouyer ttwoga_dma_init(tcp);
243 1.1.2.2 bouyer
244 1.1.2.2 bouyer if (tcp->tc_rev < TRN_T3)
245 1.1.2.2 bouyer printf(": T2 Gate Array rev. %d\n", tcp->tc_rev);
246 1.1.2.2 bouyer else
247 1.1.2.2 bouyer printf(": T3 or T4 Gate Array rev. %d\n", tcp->tc_rev);
248 1.1.2.2 bouyer
249 1.1.2.2 bouyer if (tcp->tc_rev < 1)
250 1.1.2.2 bouyer printf("%s: WARNING: T2 NOT PASS2... NO BETS...\n",
251 1.1.2.2 bouyer self->dv_xname);
252 1.1.2.2 bouyer
253 1.1.2.2 bouyer switch (cputype) {
254 1.1.2.2 bouyer #if defined(DEC_2100_A500) || defined(DEC_2100A_A500)
255 1.1.2.2 bouyer case ST_DEC_2100_A500:
256 1.1.2.2 bouyer case ST_DEC_2100A_A500:
257 1.1.2.2 bouyer pci_2100_a500_pickintr(tcp);
258 1.1.2.2 bouyer break;
259 1.1.2.2 bouyer #endif
260 1.1.2.2 bouyer
261 1.1.2.2 bouyer default:
262 1.1.2.2 bouyer panic("ttwogaattach: shouldn't be here, really...");
263 1.1.2.2 bouyer }
264 1.1.2.2 bouyer
265 1.1.2.2 bouyer npba.pba_iot = &tcp->tc_iot;
266 1.1.2.2 bouyer npba.pba_memt = &tcp->tc_memt;
267 1.1.2.2 bouyer npba.pba_dmat =
268 1.1.2.2 bouyer alphabus_dma_get_tag(&tcp->tc_dmat_direct, ALPHA_BUS_PCI);
269 1.1.2.2 bouyer npba.pba_pc = &tcp->tc_pc;
270 1.1.2.2 bouyer npba.pba_bus = 0;
271 1.1.2.2 bouyer npba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED;
272 1.1.2.2 bouyer
273 1.1.2.2 bouyer /*
274 1.1.2.2 bouyer * Hose 0 has the STDIO module.
275 1.1.2.2 bouyer */
276 1.1.2.2 bouyer if (pba->pba_bus == 0) {
277 1.1.2.2 bouyer npba.pba_busname = "sableio";
278 1.1.2.2 bouyer (void) config_found(self, &npba, ttwopciprint);
279 1.1.2.2 bouyer }
280 1.1.2.2 bouyer
281 1.1.2.2 bouyer npba.pba_busname = "pci";
282 1.1.2.2 bouyer (void) config_found(self, &npba, ttwopciprint);
283 1.1.2.2 bouyer }
284 1.1.2.2 bouyer
285 1.1.2.2 bouyer int
286 1.1.2.2 bouyer ttwopciprint(void *aux, const char *pnp)
287 1.1.2.2 bouyer {
288 1.1.2.2 bouyer struct pcibus_attach_args *pba = aux;
289 1.1.2.2 bouyer
290 1.1.2.2 bouyer if (pnp)
291 1.1.2.2 bouyer printf("%s at %s", pba->pba_busname, pnp);
292 1.1.2.2 bouyer printf(" bus %d", pba->pba_bus);
293 1.1.2.2 bouyer return (UNCONF);
294 1.1.2.2 bouyer }
295