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