xref: /netbsd-src/sys/arch/alpha/pci/ttwoga.c (revision 27527e67bbdf8d9ec84fd58803048ed6d181ece2)
1 /* $NetBSD: ttwoga.c,v 1.10 2005/12/11 12:16:17 christos 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.10 2005/12/11 12:16:17 christos 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 #include "locators.h"
71 
72 int	ttwogamatch(struct device *, struct cfdata *, void *);
73 void	ttwogaattach(struct device *, struct device *, void *);
74 
75 CFATTACH_DECL(ttwoga, sizeof(struct device),
76     ttwogamatch, ttwogaattach, NULL, NULL);
77 
78 int	ttwogaprint(void *, const char *);
79 
80 int	ttwopcimatch(struct device *, struct cfdata *, void *);
81 void	ttwopciattach(struct device *, struct device *, void *);
82 
83 CFATTACH_DECL(ttwopci, sizeof(struct device),
84     ttwopcimatch, ttwopciattach, NULL, NULL);
85 
86 int	ttwosableioprint(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_bus = hose;
154 
155 		(void) config_found_ia(self, "ttwoga", &pba, ttwogaprint);
156 	}
157 }
158 
159 int
160 ttwogaprint(void *aux, const char *pnp)
161 {
162 	struct pcibus_attach_args *pba = aux;
163 
164 	if (pnp)
165 		aprint_normal("ttwopci at %s", pnp);
166 	aprint_normal(" hose %d", pba->pba_bus);
167 	return (UNCONF);
168 }
169 
170 /*
171  * Set up the chipset's function pointers.
172  */
173 struct ttwoga_config *
174 ttwoga_init(int hose, int mallocsafe)
175 {
176 	struct ttwoga_config *tcp;
177 
178 	if (hose < 0 || hose > 1)
179 		panic("ttwoga_init: bad hose # %d", hose);
180 
181 	tcp = &ttwoga_configuration[hose];
182 	tcp->tc_hose = hose;
183 
184 	tcp->tc_sysmap = &ttwoga_sysmap[hose];
185 
186 	/*
187 	 * Sable-Gamma has a CBUS address bias.
188 	 */
189 	ttwoga_gamma_cbus_bias = (alpha_implver() == ALPHA_IMPLVER_EV5) ?
190 	    T2_GAMMA_CBUS_BIAS : 0;
191 
192 	alpha_mb();
193 
194 	tcp->tc_io_bus_start = (T2GA(tcp, T2_HAE0_2) & HAE0_2_PUA2) << 23;
195 	tcp->tc_d_mem_bus_start = (T2GA(tcp, T2_HAE0_4) & HAE0_4_PUA1) << 30;
196 	tcp->tc_s_mem_bus_start = (T2GA(tcp, T2_HAE0_1) & HAE0_1_PUA1) << 27;
197 
198 	tcp->tc_rev  = (T2GA(tcp, T2_IOCSR) & IOCSR_TRN) >> IOCSR_TRN_SHIFT;
199 
200 	if (tcp->tc_initted == 0) {
201 		/* don't do these twice since they set up extents */
202 		ttwoga_bus_io_init(&tcp->tc_iot, tcp);
203 		ttwoga_bus_mem_init(&tcp->tc_memt, tcp);
204 	}
205 	tcp->tc_mallocsafe = mallocsafe;
206 
207 	ttwoga_pci_init(&tcp->tc_pc, tcp);
208 
209 	tcp->tc_initted = 1;
210 
211 	return (tcp);
212 }
213 
214 int
215 ttwopcimatch(struct device *parent, struct cfdata *match, void *aux)
216 {
217 	struct pcibus_attach_args *pba = aux;
218 
219 	if (match->cf_loc[PCIBUSCF_BUS] != PCIBUSCF_BUS_DEFAULT &&
220 	    match->cf_loc[PCIBUSCF_BUS] != pba->pba_bus)
221 		return (0);
222 
223 	return (1);
224 }
225 
226 void
227 ttwopciattach(struct device *parent, struct device *self, void *aux)
228 {
229 	struct pcibus_attach_args *pba = aux, npba;
230 	struct ttwoga_config *tcp;
231 
232 	/*
233 	 * set up the chipset's info; done one at console init time
234 	 * (maybe), but doesn't hurt to do it twice.
235 	 */
236 	tcp = ttwoga_init(pba->pba_bus, 1);
237 
238 	ttwoga_dma_init(tcp);
239 
240 	if (tcp->tc_rev < TRN_T3)
241 		printf(": T2 Gate Array rev. %d\n", tcp->tc_rev);
242 	else
243 		printf(": T3 or T4 Gate Array rev. %d\n", tcp->tc_rev);
244 
245 	if (tcp->tc_rev < 1)
246 		printf("%s: WARNING: T2 NOT PASS2... NO BETS...\n",
247 		    self->dv_xname);
248 
249 	switch (cputype) {
250 #if defined(DEC_2100_A500) || defined(DEC_2100A_A500)
251 	case ST_DEC_2100_A500:
252 	case ST_DEC_2100A_A500:
253 		pci_2100_a500_pickintr(tcp);
254 		break;
255 #endif
256 
257 	default:
258 		panic("ttwogaattach: shouldn't be here, really...");
259 	}
260 
261 	npba.pba_iot = &tcp->tc_iot;
262 	npba.pba_memt = &tcp->tc_memt;
263 	npba.pba_dmat =
264 	    alphabus_dma_get_tag(&tcp->tc_dmat_direct, ALPHA_BUS_PCI);
265 	npba.pba_dmat64 = NULL;
266 	npba.pba_pc = &tcp->tc_pc;
267 	npba.pba_bus = 0;
268 	npba.pba_bridgetag = NULL;
269 	npba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED;
270 
271 	/*
272 	 * Hose 0 has the STDIO module.
273 	 */
274 	if (pba->pba_bus == 0) {
275 		(void) config_found_ia(self, "sableiobus", &npba,
276 				       ttwosableioprint);
277 	}
278 
279 	(void) config_found_ia(self, "pcibus", &npba, pcibusprint);
280 }
281 
282 int
283 ttwosableioprint(void *aux, const char *pnp)
284 {
285 	struct pcibus_attach_args *pba = aux;
286 
287 	if (pnp)
288 		aprint_normal("sableio at %s", pnp);
289 	aprint_normal(" bus %d", pba->pba_bus);
290 	return (UNCONF);
291 }
292