tsc.c revision 1.27 1 1.27 thorpej /* $NetBSD: tsc.c,v 1.27 2021/06/19 16:59:07 thorpej Exp $ */
2 1.1 ross
3 1.1 ross /*-
4 1.1 ross * Copyright (c) 1999 by Ross Harvey. All rights reserved.
5 1.1 ross *
6 1.1 ross * Redistribution and use in source and binary forms, with or without
7 1.1 ross * modification, are permitted provided that the following conditions
8 1.1 ross * are met:
9 1.1 ross * 1. Redistributions of source code must retain the above copyright
10 1.1 ross * notice, this list of conditions and the following disclaimer.
11 1.1 ross * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 ross * notice, this list of conditions and the following disclaimer in the
13 1.1 ross * documentation and/or other materials provided with the distribution.
14 1.1 ross * 3. All advertising materials mentioning features or use of this software
15 1.1 ross * must display the following acknowledgement:
16 1.1 ross * This product includes software developed by Ross Harvey.
17 1.1 ross * 4. The name of Ross Harvey may not be used to endorse or promote products
18 1.1 ross * derived from this software without specific prior written permission.
19 1.1 ross *
20 1.1 ross * THIS SOFTWARE IS PROVIDED BY ROSS HARVEY ``AS IS'' AND ANY EXPRESS
21 1.1 ross * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 1.1 ross * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURP0SE
23 1.1 ross * ARE DISCLAIMED. IN NO EVENT SHALL ROSS HARVEY BE LIABLE FOR ANY
24 1.1 ross * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 1.1 ross * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 1.1 ross * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 1.1 ross * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 1.1 ross * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 1.1 ross * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 1.1 ross * SUCH DAMAGE.
31 1.1 ross *
32 1.1 ross */
33 1.1 ross
34 1.1 ross #include <sys/cdefs.h>
35 1.1 ross
36 1.27 thorpej __KERNEL_RCSID(0, "$NetBSD: tsc.c,v 1.27 2021/06/19 16:59:07 thorpej Exp $");
37 1.1 ross
38 1.1 ross #include <sys/param.h>
39 1.1 ross #include <sys/systm.h>
40 1.1 ross #include <sys/device.h>
41 1.1 ross #include <sys/malloc.h>
42 1.1 ross
43 1.1 ross #include <machine/autoconf.h>
44 1.1 ross #include <machine/rpb.h>
45 1.3 thorpej #include <machine/sysarch.h>
46 1.1 ross
47 1.1 ross #include <dev/isa/isareg.h>
48 1.1 ross #include <dev/isa/isavar.h>
49 1.1 ross #include <dev/pci/pcireg.h>
50 1.1 ross #include <dev/pci/pcivar.h>
51 1.1 ross #include <alpha/pci/tsreg.h>
52 1.1 ross #include <alpha/pci/tsvar.h>
53 1.1 ross
54 1.24 martin #include "tsciic.h"
55 1.24 martin
56 1.1 ross #define tsc() { Generate ctags(1) key. }
57 1.1 ross
58 1.17 jakllsch static int tscmatch(device_t, cfdata_t, void *);
59 1.17 jakllsch static void tscattach(device_t, device_t, void *);
60 1.1 ross
61 1.17 jakllsch CFATTACH_DECL_NEW(tsc, 0, tscmatch, tscattach, NULL, NULL);
62 1.1 ross
63 1.1 ross extern struct cfdriver tsc_cd;
64 1.1 ross
65 1.20 tsutsui struct tsp_config tsp_configuration[4];
66 1.1 ross
67 1.14 dsl static int tscprint(void *, const char *pnp);
68 1.1 ross
69 1.17 jakllsch static int tspmatch(device_t, cfdata_t, void *);
70 1.17 jakllsch static void tspattach(device_t, device_t, void *);
71 1.1 ross
72 1.17 jakllsch CFATTACH_DECL_NEW(tsp, 0, tspmatch, tspattach, NULL, NULL);
73 1.1 ross
74 1.1 ross extern struct cfdriver tsp_cd;
75 1.1 ross
76 1.14 dsl static int tsp_bus_get_window(int, int,
77 1.14 dsl struct alpha_bus_space_translation *);
78 1.3 thorpej
79 1.23 jdc static int tsciicprint(void *, const char *pnp);
80 1.23 jdc
81 1.23 jdc static int tsciicmatch(device_t, cfdata_t, void *);
82 1.23 jdc static void tsciicattach(device_t, device_t, void *);
83 1.23 jdc
84 1.23 jdc CFATTACH_DECL_NEW(tsciic, sizeof(struct tsciic_softc), tsciicmatch,
85 1.23 jdc tsciicattach, NULL, NULL);
86 1.23 jdc
87 1.24 martin #if NTSCIIC
88 1.23 jdc extern struct cfdriver tsciic_cd;
89 1.24 martin #endif
90 1.23 jdc
91 1.1 ross /* There can be only one */
92 1.3 thorpej static int tscfound;
93 1.1 ross
94 1.3 thorpej /* Which hose is the display console connected to? */
95 1.3 thorpej int tsp_console_hose;
96 1.1 ross
97 1.17 jakllsch static int
98 1.17 jakllsch tscmatch(device_t parent, cfdata_t match, void *aux)
99 1.1 ross {
100 1.1 ross struct mainbus_attach_args *ma = aux;
101 1.1 ross
102 1.20 tsutsui switch (cputype) {
103 1.20 tsutsui case ST_DEC_6600:
104 1.20 tsutsui case ST_DEC_TITAN:
105 1.20 tsutsui return strcmp(ma->ma_name, tsc_cd.cd_name) == 0 && !tscfound;
106 1.20 tsutsui default:
107 1.20 tsutsui return 0;
108 1.20 tsutsui }
109 1.1 ross }
110 1.1 ross
111 1.17 jakllsch static void
112 1.17 jakllsch tscattach(device_t parent, device_t self, void * aux)
113 1.1 ross {
114 1.1 ross int i;
115 1.1 ross int nbus;
116 1.17 jakllsch uint64_t csc, aar;
117 1.1 ross struct tsp_attach_args tsp;
118 1.23 jdc struct tsciic_attach_args tsciic;
119 1.1 ross struct mainbus_attach_args *ma = aux;
120 1.20 tsutsui int titan = cputype == ST_DEC_TITAN;
121 1.1 ross
122 1.1 ross tscfound = 1;
123 1.1 ross
124 1.1 ross csc = LDQP(TS_C_CSC);
125 1.1 ross
126 1.1 ross nbus = 1 + (CSC_BC(csc) >= 2);
127 1.20 tsutsui printf(": 2127%c Core Logic Chipset, Cchip rev %d\n"
128 1.1 ross "%s%d: %c Dchips, %d memory bus%s of %d bytes\n",
129 1.20 tsutsui titan ? '4' : '2', (int)MISC_REV(LDQP(TS_C_MISC)),
130 1.1 ross ma->ma_name, ma->ma_slot, "2448"[CSC_BC(csc)],
131 1.1 ross nbus, nbus > 1 ? "es" : "", 16 + 16 * ((csc & CSC_AW) != 0));
132 1.1 ross printf("%s%d: arrays present: ", ma->ma_name, ma->ma_slot);
133 1.22 tsutsui for (i = 0; i < 4; ++i) {
134 1.1 ross aar = LDQP(TS_C_AAR0 + i * TS_STEP);
135 1.1 ross printf("%s%dMB%s", i ? ", " : "", (8 << AAR_ASIZ(aar)) & ~0xf,
136 1.1 ross aar & AAR_SPLIT ? " (split)" : "");
137 1.1 ross }
138 1.1 ross printf(", Dchip 0 rev %d\n", (int)LDQP(TS_D_DREV) & 0xf);
139 1.1 ross
140 1.6 thorpej memset(&tsp, 0, sizeof tsp);
141 1.1 ross tsp.tsp_name = "tsp";
142 1.22 tsutsui tsp.tsp_slot = 0;
143 1.22 tsutsui
144 1.25 thorpej config_found(self, &tsp, tscprint, CFARG_EOL);
145 1.20 tsutsui if (titan) {
146 1.20 tsutsui tsp.tsp_slot += 2;
147 1.25 thorpej config_found(self, &tsp, tscprint, CFARG_EOL);
148 1.20 tsutsui }
149 1.1 ross
150 1.20 tsutsui if (csc & CSC_P1P) {
151 1.20 tsutsui tsp.tsp_slot = 1;
152 1.25 thorpej config_found(self, &tsp, tscprint, CFARG_EOL);
153 1.20 tsutsui if (titan) {
154 1.20 tsutsui tsp.tsp_slot += 2;
155 1.25 thorpej config_found(self, &tsp, tscprint, CFARG_EOL);
156 1.20 tsutsui }
157 1.1 ross }
158 1.23 jdc
159 1.23 jdc memset(&tsciic, 0, sizeof tsciic);
160 1.23 jdc tsciic.tsciic_name = "tsciic";
161 1.23 jdc
162 1.25 thorpej config_found(self, &tsciic, tsciicprint, CFARG_EOL);
163 1.1 ross }
164 1.1 ross
165 1.1 ross static int
166 1.15 dsl tscprint(void *aux, const char *p)
167 1.1 ross {
168 1.21 tsutsui struct tsp_attach_args *tsp = aux;
169 1.1 ross
170 1.22 tsutsui if (p)
171 1.10 thorpej aprint_normal("%s%d at %s", tsp->tsp_name, tsp->tsp_slot, p);
172 1.1 ross return UNCONF;
173 1.1 ross }
174 1.1 ross
175 1.23 jdc static int
176 1.23 jdc tsciicprint(void *aux, const char *p)
177 1.23 jdc {
178 1.23 jdc struct tsciic_attach_args *tsciic = aux;
179 1.23 jdc
180 1.23 jdc if (p)
181 1.23 jdc aprint_normal("%s at %s\n", tsciic->tsciic_name, p);
182 1.23 jdc else
183 1.23 jdc aprint_normal("\n");
184 1.23 jdc return UNCONF;
185 1.23 jdc }
186 1.23 jdc
187 1.1 ross #define tsp() { Generate ctags(1) key. }
188 1.1 ross
189 1.17 jakllsch static int
190 1.17 jakllsch tspmatch(device_t parent, cfdata_t match, void *aux)
191 1.1 ross {
192 1.1 ross struct tsp_attach_args *t = aux;
193 1.1 ross
194 1.20 tsutsui switch (cputype) {
195 1.20 tsutsui case ST_DEC_6600:
196 1.20 tsutsui case ST_DEC_TITAN:
197 1.20 tsutsui return strcmp(t->tsp_name, tsp_cd.cd_name) == 0;
198 1.20 tsutsui default:
199 1.20 tsutsui return 0;
200 1.20 tsutsui }
201 1.1 ross }
202 1.1 ross
203 1.17 jakllsch static void
204 1.17 jakllsch tspattach(device_t parent, device_t self, void *aux)
205 1.1 ross {
206 1.1 ross struct pcibus_attach_args pba;
207 1.1 ross struct tsp_attach_args *t = aux;
208 1.1 ross struct tsp_config *pcp;
209 1.1 ross
210 1.1 ross printf("\n");
211 1.1 ross pcp = tsp_init(1, t->tsp_slot);
212 1.5 thorpej
213 1.1 ross tsp_dma_init(pcp);
214 1.22 tsutsui
215 1.5 thorpej /*
216 1.5 thorpej * Do PCI memory initialization that needs to be deferred until
217 1.5 thorpej * malloc is safe. On the Tsunami, we need to do this after
218 1.5 thorpej * DMA is initialized, as well.
219 1.5 thorpej */
220 1.5 thorpej tsp_bus_mem_init2(&pcp->pc_memt, pcp);
221 1.5 thorpej
222 1.27 thorpej alpha_pci_intr_init(pcp, &pcp->pc_iot, &pcp->pc_memt, &pcp->pc_pc);
223 1.5 thorpej
224 1.1 ross pba.pba_iot = &pcp->pc_iot;
225 1.1 ross pba.pba_memt = &pcp->pc_memt;
226 1.1 ross pba.pba_dmat =
227 1.1 ross alphabus_dma_get_tag(&pcp->pc_dmat_direct, ALPHA_BUS_PCI);
228 1.26 thorpej pba.pba_dmat64 = &pcp->pc_dmat64_direct;
229 1.1 ross pba.pba_pc = &pcp->pc_pc;
230 1.1 ross pba.pba_bus = 0;
231 1.7 thorpej pba.pba_bridgetag = NULL;
232 1.19 dyoung pba.pba_flags = PCI_FLAGS_IO_OKAY | PCI_FLAGS_MEM_OKAY |
233 1.2 thorpej PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY;
234 1.25 thorpej config_found(self, &pba, pcibusprint, CFARG_EOL);
235 1.1 ross }
236 1.1 ross
237 1.1 ross struct tsp_config *
238 1.16 dsl tsp_init(int mallocsafe, int n)
239 1.16 dsl /* n: Pchip number */
240 1.1 ross {
241 1.1 ross struct tsp_config *pcp;
242 1.20 tsutsui int titan = cputype == ST_DEC_TITAN;
243 1.1 ross
244 1.20 tsutsui KASSERT(n >= 0 && n < __arraycount(tsp_configuration));
245 1.1 ross pcp = &tsp_configuration[n];
246 1.1 ross pcp->pc_pslot = n;
247 1.1 ross pcp->pc_iobase = TS_Pn(n, 0);
248 1.20 tsutsui pcp->pc_csr = S_PAGE(TS_Pn(n & 1, P_CSRBASE));
249 1.20 tsutsui if (n & 2) {
250 1.20 tsutsui /* `A' port of PA Chip */
251 1.20 tsutsui pcp->pc_csr++;
252 1.20 tsutsui }
253 1.20 tsutsui if (titan) {
254 1.20 tsutsui /* same address on G and A ports */
255 1.20 tsutsui pcp->pc_tlbia = &pcp->pc_csr->port.g.tsp_tlbia.tsg_r;
256 1.20 tsutsui } else {
257 1.20 tsutsui pcp->pc_tlbia = &pcp->pc_csr->port.p.tsp_tlbia.tsg_r;
258 1.20 tsutsui }
259 1.20 tsutsui
260 1.1 ross if (!pcp->pc_initted) {
261 1.1 ross tsp_bus_io_init(&pcp->pc_iot, pcp);
262 1.1 ross tsp_bus_mem_init(&pcp->pc_memt, pcp);
263 1.3 thorpej
264 1.3 thorpej alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_IO] = 1;
265 1.3 thorpej alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_MEM] = 1;
266 1.3 thorpej
267 1.3 thorpej alpha_bus_get_window = tsp_bus_get_window;
268 1.1 ross }
269 1.1 ross pcp->pc_mallocsafe = mallocsafe;
270 1.1 ross tsp_pci_init(&pcp->pc_pc, pcp);
271 1.1 ross pcp->pc_initted = 1;
272 1.1 ross return pcp;
273 1.1 ross }
274 1.1 ross
275 1.1 ross static int
276 1.17 jakllsch tsp_bus_get_window(int type, int window,
277 1.17 jakllsch struct alpha_bus_space_translation *abst)
278 1.3 thorpej {
279 1.3 thorpej struct tsp_config *tsp = &tsp_configuration[tsp_console_hose];
280 1.3 thorpej bus_space_tag_t st;
281 1.4 thorpej int error;
282 1.3 thorpej
283 1.3 thorpej switch (type) {
284 1.3 thorpej case ALPHA_BUS_TYPE_PCI_IO:
285 1.3 thorpej st = &tsp->pc_iot;
286 1.3 thorpej break;
287 1.3 thorpej
288 1.3 thorpej case ALPHA_BUS_TYPE_PCI_MEM:
289 1.3 thorpej st = &tsp->pc_memt;
290 1.3 thorpej break;
291 1.3 thorpej
292 1.3 thorpej default:
293 1.3 thorpej panic("tsp_bus_get_window");
294 1.3 thorpej }
295 1.3 thorpej
296 1.4 thorpej error = alpha_bus_space_get_window(st, window, abst);
297 1.4 thorpej if (error)
298 1.22 tsutsui return error;
299 1.4 thorpej
300 1.4 thorpej abst->abst_sys_start = TS_PHYSADDR(abst->abst_sys_start);
301 1.4 thorpej abst->abst_sys_end = TS_PHYSADDR(abst->abst_sys_end);
302 1.4 thorpej
303 1.22 tsutsui return 0;
304 1.1 ross }
305 1.18 hans
306 1.23 jdc #define tsciic() { Generate ctags(1) key. }
307 1.23 jdc
308 1.23 jdc static int
309 1.23 jdc tsciicmatch(device_t parent, cfdata_t match, void *aux)
310 1.23 jdc {
311 1.24 martin #if NTSCIIC
312 1.23 jdc struct tsciic_attach_args *t = aux;
313 1.24 martin #endif
314 1.23 jdc
315 1.23 jdc switch (cputype) {
316 1.23 jdc case ST_DEC_6600:
317 1.23 jdc case ST_DEC_TITAN:
318 1.24 martin #if NTSCIIC
319 1.23 jdc return strcmp(t->tsciic_name, tsciic_cd.cd_name) == 0;
320 1.24 martin #endif
321 1.23 jdc default:
322 1.23 jdc return 0;
323 1.23 jdc }
324 1.23 jdc }
325 1.23 jdc
326 1.23 jdc static void
327 1.23 jdc tsciicattach(device_t parent, device_t self, void *aux)
328 1.23 jdc {
329 1.24 martin #if NTSCIIC
330 1.23 jdc tsciic_init(self);
331 1.24 martin #endif
332 1.23 jdc }
333 1.23 jdc
334 1.18 hans void
335 1.18 hans tsc_print_dir(unsigned int indent, unsigned long dir)
336 1.18 hans {
337 1.18 hans char buf[60];
338 1.18 hans
339 1.18 hans snprintb(buf, 60,
340 1.18 hans "\177\20"
341 1.18 hans "b\77Internal Cchip asynchronous error\0"
342 1.18 hans "b\76Pchip 0 error\0"
343 1.18 hans "b\75Pchip 1 error\0"
344 1.18 hans "b\74Pchip 2 error\0"
345 1.18 hans "b\73Pchip 3 error\0",
346 1.18 hans dir);
347 1.18 hans IPRINTF(indent, "DIR = %s\n", buf);
348 1.18 hans }
349 1.18 hans
350 1.18 hans void
351 1.18 hans tsc_print_misc(unsigned int indent, unsigned long misc)
352 1.18 hans {
353 1.18 hans unsigned long tmp = MISC_NXM_SRC(misc);
354 1.18 hans
355 1.18 hans if (!MISC_NXM(misc))
356 1.18 hans return;
357 1.18 hans
358 1.18 hans IPRINTF(indent, "NXM address detected\n");
359 1.18 hans IPRINTF(indent, "NXM source = %s %lu\n",
360 1.18 hans tmp <= 3 ? "CPU" : "Pchip", tmp <= 3 ? tmp : tmp - 4);
361 1.18 hans }
362