tsc.c revision 1.6.2.3 1 1.6.2.3 nathanw /* $NetBSD: tsc.c,v 1.6.2.3 2002/10/18 02:34:25 nathanw Exp $ */
2 1.6.2.2 nathanw
3 1.6.2.2 nathanw /*-
4 1.6.2.2 nathanw * Copyright (c) 1999 by Ross Harvey. All rights reserved.
5 1.6.2.2 nathanw *
6 1.6.2.2 nathanw * Redistribution and use in source and binary forms, with or without
7 1.6.2.2 nathanw * modification, are permitted provided that the following conditions
8 1.6.2.2 nathanw * are met:
9 1.6.2.2 nathanw * 1. Redistributions of source code must retain the above copyright
10 1.6.2.2 nathanw * notice, this list of conditions and the following disclaimer.
11 1.6.2.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
12 1.6.2.2 nathanw * notice, this list of conditions and the following disclaimer in the
13 1.6.2.2 nathanw * documentation and/or other materials provided with the distribution.
14 1.6.2.2 nathanw * 3. All advertising materials mentioning features or use of this software
15 1.6.2.2 nathanw * must display the following acknowledgement:
16 1.6.2.2 nathanw * This product includes software developed by Ross Harvey.
17 1.6.2.2 nathanw * 4. The name of Ross Harvey may not be used to endorse or promote products
18 1.6.2.2 nathanw * derived from this software without specific prior written permission.
19 1.6.2.2 nathanw *
20 1.6.2.2 nathanw * THIS SOFTWARE IS PROVIDED BY ROSS HARVEY ``AS IS'' AND ANY EXPRESS
21 1.6.2.2 nathanw * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 1.6.2.2 nathanw * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURP0SE
23 1.6.2.2 nathanw * ARE DISCLAIMED. IN NO EVENT SHALL ROSS HARVEY BE LIABLE FOR ANY
24 1.6.2.2 nathanw * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 1.6.2.2 nathanw * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 1.6.2.2 nathanw * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 1.6.2.2 nathanw * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 1.6.2.2 nathanw * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 1.6.2.2 nathanw * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 1.6.2.2 nathanw * SUCH DAMAGE.
31 1.6.2.2 nathanw *
32 1.6.2.2 nathanw */
33 1.6.2.2 nathanw
34 1.6.2.2 nathanw #include "opt_dec_6600.h"
35 1.6.2.2 nathanw
36 1.6.2.2 nathanw #include <sys/cdefs.h>
37 1.6.2.2 nathanw
38 1.6.2.3 nathanw __KERNEL_RCSID(0, "$NetBSD: tsc.c,v 1.6.2.3 2002/10/18 02:34:25 nathanw Exp $");
39 1.6.2.2 nathanw
40 1.6.2.2 nathanw #include <sys/param.h>
41 1.6.2.2 nathanw #include <sys/systm.h>
42 1.6.2.2 nathanw #include <sys/device.h>
43 1.6.2.2 nathanw #include <sys/malloc.h>
44 1.6.2.2 nathanw
45 1.6.2.2 nathanw #include <machine/autoconf.h>
46 1.6.2.2 nathanw #include <machine/rpb.h>
47 1.6.2.2 nathanw #include <machine/sysarch.h>
48 1.6.2.2 nathanw
49 1.6.2.2 nathanw #include <dev/isa/isareg.h>
50 1.6.2.2 nathanw #include <dev/isa/isavar.h>
51 1.6.2.2 nathanw #include <dev/pci/pcireg.h>
52 1.6.2.2 nathanw #include <dev/pci/pcivar.h>
53 1.6.2.2 nathanw #include <alpha/pci/tsreg.h>
54 1.6.2.2 nathanw #include <alpha/pci/tsvar.h>
55 1.6.2.2 nathanw
56 1.6.2.2 nathanw #ifdef DEC_6600
57 1.6.2.2 nathanw #include <alpha/pci/pci_6600.h>
58 1.6.2.2 nathanw #endif
59 1.6.2.2 nathanw
60 1.6.2.2 nathanw #define tsc() { Generate ctags(1) key. }
61 1.6.2.2 nathanw
62 1.6.2.2 nathanw int tscmatch __P((struct device *, struct cfdata *, void *));
63 1.6.2.2 nathanw void tscattach __P((struct device *, struct device *, void *));
64 1.6.2.2 nathanw
65 1.6.2.3 nathanw CFATTACH_DECL(tsc, sizeof(struct tsc_softc),
66 1.6.2.3 nathanw tscmatch, tscattach, NULL, NULL);
67 1.6.2.2 nathanw
68 1.6.2.2 nathanw extern struct cfdriver tsc_cd;
69 1.6.2.2 nathanw
70 1.6.2.2 nathanw struct tsp_config tsp_configuration[2];
71 1.6.2.2 nathanw
72 1.6.2.2 nathanw static int tscprint __P((void *, const char *pnp));
73 1.6.2.2 nathanw
74 1.6.2.2 nathanw int tspmatch __P((struct device *, struct cfdata *, void *));
75 1.6.2.2 nathanw void tspattach __P((struct device *, struct device *, void *));
76 1.6.2.2 nathanw
77 1.6.2.3 nathanw CFATTACH_DECL(tsp, sizeof(struct tsp_softc),
78 1.6.2.3 nathanw tspmatch, tspattach, NULL, NULL);
79 1.6.2.2 nathanw
80 1.6.2.2 nathanw extern struct cfdriver tsp_cd;
81 1.6.2.2 nathanw
82 1.6.2.2 nathanw static int tspprint __P((void *, const char *pnp));
83 1.6.2.2 nathanw
84 1.6.2.2 nathanw static int tsp_bus_get_window __P((int, int,
85 1.6.2.2 nathanw struct alpha_bus_space_translation *));
86 1.6.2.2 nathanw
87 1.6.2.2 nathanw /* There can be only one */
88 1.6.2.2 nathanw static int tscfound;
89 1.6.2.2 nathanw
90 1.6.2.2 nathanw /* Which hose is the display console connected to? */
91 1.6.2.2 nathanw int tsp_console_hose;
92 1.6.2.2 nathanw
93 1.6.2.2 nathanw int
94 1.6.2.2 nathanw tscmatch(parent, match, aux)
95 1.6.2.2 nathanw struct device *parent;
96 1.6.2.2 nathanw struct cfdata *match;
97 1.6.2.2 nathanw void *aux;
98 1.6.2.2 nathanw {
99 1.6.2.2 nathanw struct mainbus_attach_args *ma = aux;
100 1.6.2.2 nathanw
101 1.6.2.2 nathanw return cputype == ST_DEC_6600
102 1.6.2.2 nathanw && strcmp(ma->ma_name, tsc_cd.cd_name) == 0
103 1.6.2.2 nathanw && !tscfound;
104 1.6.2.2 nathanw }
105 1.6.2.2 nathanw
106 1.6.2.2 nathanw void tscattach(parent, self, aux)
107 1.6.2.2 nathanw struct device *parent, *self;
108 1.6.2.2 nathanw void *aux;
109 1.6.2.2 nathanw {
110 1.6.2.2 nathanw int i;
111 1.6.2.2 nathanw int nbus;
112 1.6.2.2 nathanw u_int64_t csc, aar;
113 1.6.2.2 nathanw struct tsp_attach_args tsp;
114 1.6.2.2 nathanw struct mainbus_attach_args *ma = aux;
115 1.6.2.2 nathanw
116 1.6.2.2 nathanw tscfound = 1;
117 1.6.2.2 nathanw
118 1.6.2.2 nathanw csc = LDQP(TS_C_CSC);
119 1.6.2.2 nathanw
120 1.6.2.2 nathanw nbus = 1 + (CSC_BC(csc) >= 2);
121 1.6.2.2 nathanw printf(": 21272 Core Logic Chipset, Cchip rev %d\n"
122 1.6.2.2 nathanw "%s%d: %c Dchips, %d memory bus%s of %d bytes\n",
123 1.6.2.2 nathanw (int)MISC_REV(LDQP(TS_C_MISC)),
124 1.6.2.2 nathanw ma->ma_name, ma->ma_slot, "2448"[CSC_BC(csc)],
125 1.6.2.2 nathanw nbus, nbus > 1 ? "es" : "", 16 + 16 * ((csc & CSC_AW) != 0));
126 1.6.2.2 nathanw printf("%s%d: arrays present: ", ma->ma_name, ma->ma_slot);
127 1.6.2.2 nathanw for(i = 0; i < 4; ++i) {
128 1.6.2.2 nathanw aar = LDQP(TS_C_AAR0 + i * TS_STEP);
129 1.6.2.2 nathanw printf("%s%dMB%s", i ? ", " : "", (8 << AAR_ASIZ(aar)) & ~0xf,
130 1.6.2.2 nathanw aar & AAR_SPLIT ? " (split)" : "");
131 1.6.2.2 nathanw }
132 1.6.2.2 nathanw printf(", Dchip 0 rev %d\n", (int)LDQP(TS_D_DREV) & 0xf);
133 1.6.2.2 nathanw
134 1.6.2.2 nathanw memset(&tsp, 0, sizeof tsp);
135 1.6.2.2 nathanw tsp.tsp_name = "tsp";
136 1.6.2.2 nathanw config_found(self, &tsp, NULL);
137 1.6.2.2 nathanw
138 1.6.2.2 nathanw if(LDQP(TS_C_CSC) & CSC_P1P) {
139 1.6.2.2 nathanw ++tsp.tsp_slot;
140 1.6.2.2 nathanw config_found(self, &tsp, tscprint);
141 1.6.2.2 nathanw }
142 1.6.2.2 nathanw }
143 1.6.2.2 nathanw
144 1.6.2.2 nathanw static int
145 1.6.2.2 nathanw tscprint(aux, p)
146 1.6.2.2 nathanw void *aux;
147 1.6.2.2 nathanw const char *p;
148 1.6.2.2 nathanw {
149 1.6.2.2 nathanw register struct tsp_attach_args *tsp = aux;
150 1.6.2.2 nathanw
151 1.6.2.2 nathanw if(p)
152 1.6.2.2 nathanw printf("%s%d at %s", tsp->tsp_name, tsp->tsp_slot, p);
153 1.6.2.2 nathanw return UNCONF;
154 1.6.2.2 nathanw }
155 1.6.2.2 nathanw
156 1.6.2.2 nathanw #define tsp() { Generate ctags(1) key. }
157 1.6.2.2 nathanw
158 1.6.2.2 nathanw int
159 1.6.2.2 nathanw tspmatch(parent, match, aux)
160 1.6.2.2 nathanw struct device *parent;
161 1.6.2.2 nathanw struct cfdata *match;
162 1.6.2.2 nathanw void *aux;
163 1.6.2.2 nathanw {
164 1.6.2.2 nathanw struct tsp_attach_args *t = aux;
165 1.6.2.2 nathanw
166 1.6.2.2 nathanw return cputype == ST_DEC_6600
167 1.6.2.2 nathanw && strcmp(t->tsp_name, tsp_cd.cd_name) == 0;
168 1.6.2.2 nathanw }
169 1.6.2.2 nathanw
170 1.6.2.2 nathanw void
171 1.6.2.2 nathanw tspattach(parent, self, aux)
172 1.6.2.2 nathanw struct device *parent, *self;
173 1.6.2.2 nathanw void *aux;
174 1.6.2.2 nathanw {
175 1.6.2.2 nathanw struct pcibus_attach_args pba;
176 1.6.2.2 nathanw struct tsp_attach_args *t = aux;
177 1.6.2.2 nathanw struct tsp_config *pcp;
178 1.6.2.2 nathanw
179 1.6.2.2 nathanw printf("\n");
180 1.6.2.2 nathanw pcp = tsp_init(1, t->tsp_slot);
181 1.6.2.2 nathanw
182 1.6.2.2 nathanw tsp_dma_init(pcp);
183 1.6.2.2 nathanw
184 1.6.2.2 nathanw /*
185 1.6.2.2 nathanw * Do PCI memory initialization that needs to be deferred until
186 1.6.2.2 nathanw * malloc is safe. On the Tsunami, we need to do this after
187 1.6.2.2 nathanw * DMA is initialized, as well.
188 1.6.2.2 nathanw */
189 1.6.2.2 nathanw tsp_bus_mem_init2(&pcp->pc_memt, pcp);
190 1.6.2.2 nathanw
191 1.6.2.2 nathanw pci_6600_pickintr(pcp);
192 1.6.2.2 nathanw
193 1.6.2.2 nathanw pba.pba_busname = "pci";
194 1.6.2.2 nathanw pba.pba_iot = &pcp->pc_iot;
195 1.6.2.2 nathanw pba.pba_memt = &pcp->pc_memt;
196 1.6.2.2 nathanw pba.pba_dmat =
197 1.6.2.2 nathanw alphabus_dma_get_tag(&pcp->pc_dmat_direct, ALPHA_BUS_PCI);
198 1.6.2.2 nathanw pba.pba_pc = &pcp->pc_pc;
199 1.6.2.2 nathanw pba.pba_bus = 0;
200 1.6.2.2 nathanw pba.pba_bridgetag = NULL;
201 1.6.2.2 nathanw pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED |
202 1.6.2.2 nathanw PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY;
203 1.6.2.2 nathanw config_found(self, &pba, tspprint);
204 1.6.2.2 nathanw }
205 1.6.2.2 nathanw
206 1.6.2.2 nathanw struct tsp_config *
207 1.6.2.2 nathanw tsp_init(mallocsafe, n)
208 1.6.2.2 nathanw int mallocsafe;
209 1.6.2.2 nathanw int n; /* Pchip number */
210 1.6.2.2 nathanw {
211 1.6.2.2 nathanw struct tsp_config *pcp;
212 1.6.2.2 nathanw
213 1.6.2.2 nathanw KASSERT((n | 1) == 1);
214 1.6.2.2 nathanw pcp = &tsp_configuration[n];
215 1.6.2.2 nathanw pcp->pc_pslot = n;
216 1.6.2.2 nathanw pcp->pc_iobase = TS_Pn(n, 0);
217 1.6.2.2 nathanw pcp->pc_csr = S_PAGE(TS_Pn(n, P_CSRBASE));
218 1.6.2.2 nathanw if (!pcp->pc_initted) {
219 1.6.2.2 nathanw tsp_bus_io_init(&pcp->pc_iot, pcp);
220 1.6.2.2 nathanw tsp_bus_mem_init(&pcp->pc_memt, pcp);
221 1.6.2.2 nathanw
222 1.6.2.2 nathanw alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_IO] = 1;
223 1.6.2.2 nathanw alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_MEM] = 1;
224 1.6.2.2 nathanw
225 1.6.2.2 nathanw alpha_bus_get_window = tsp_bus_get_window;
226 1.6.2.2 nathanw }
227 1.6.2.2 nathanw pcp->pc_mallocsafe = mallocsafe;
228 1.6.2.2 nathanw tsp_pci_init(&pcp->pc_pc, pcp);
229 1.6.2.2 nathanw pcp->pc_initted = 1;
230 1.6.2.2 nathanw return pcp;
231 1.6.2.2 nathanw }
232 1.6.2.2 nathanw
233 1.6.2.2 nathanw static int
234 1.6.2.2 nathanw tspprint(aux, p)
235 1.6.2.2 nathanw void *aux;
236 1.6.2.2 nathanw const char *p;
237 1.6.2.2 nathanw {
238 1.6.2.2 nathanw register struct pcibus_attach_args *pci = aux;
239 1.6.2.2 nathanw
240 1.6.2.2 nathanw if(p)
241 1.6.2.2 nathanw printf("%s at %s", pci->pba_busname, p);
242 1.6.2.2 nathanw printf(" bus %d", pci->pba_bus);
243 1.6.2.2 nathanw return UNCONF;
244 1.6.2.2 nathanw }
245 1.6.2.2 nathanw
246 1.6.2.2 nathanw static int
247 1.6.2.2 nathanw tsp_bus_get_window(type, window, abst)
248 1.6.2.2 nathanw int type, window;
249 1.6.2.2 nathanw struct alpha_bus_space_translation *abst;
250 1.6.2.2 nathanw {
251 1.6.2.2 nathanw struct tsp_config *tsp = &tsp_configuration[tsp_console_hose];
252 1.6.2.2 nathanw bus_space_tag_t st;
253 1.6.2.2 nathanw int error;
254 1.6.2.2 nathanw
255 1.6.2.2 nathanw switch (type) {
256 1.6.2.2 nathanw case ALPHA_BUS_TYPE_PCI_IO:
257 1.6.2.2 nathanw st = &tsp->pc_iot;
258 1.6.2.2 nathanw break;
259 1.6.2.2 nathanw
260 1.6.2.2 nathanw case ALPHA_BUS_TYPE_PCI_MEM:
261 1.6.2.2 nathanw st = &tsp->pc_memt;
262 1.6.2.2 nathanw break;
263 1.6.2.2 nathanw
264 1.6.2.2 nathanw default:
265 1.6.2.2 nathanw panic("tsp_bus_get_window");
266 1.6.2.2 nathanw }
267 1.6.2.2 nathanw
268 1.6.2.2 nathanw error = alpha_bus_space_get_window(st, window, abst);
269 1.6.2.2 nathanw if (error)
270 1.6.2.2 nathanw return (error);
271 1.6.2.2 nathanw
272 1.6.2.2 nathanw abst->abst_sys_start = TS_PHYSADDR(abst->abst_sys_start);
273 1.6.2.2 nathanw abst->abst_sys_end = TS_PHYSADDR(abst->abst_sys_end);
274 1.6.2.2 nathanw
275 1.6.2.2 nathanw return (0);
276 1.6.2.2 nathanw }
277