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