cia.c revision 1.55 1 /* $NetBSD: cia.c,v 1.55 2000/04/03 01:48:07 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 1998, 2000 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 of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40 /*
41 * Copyright (c) 1995, 1996 Carnegie-Mellon University.
42 * All rights reserved.
43 *
44 * Author: Chris G. Demetriou
45 *
46 * Permission to use, copy, modify and distribute this software and
47 * its documentation is hereby granted, provided that both the copyright
48 * notice and this permission notice appear in all copies of the
49 * software, derivative works or modified versions, and any portions
50 * thereof, and that both notices appear in supporting documentation.
51 *
52 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
53 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
54 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
55 *
56 * Carnegie Mellon requests users of this software to return to
57 *
58 * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
59 * School of Computer Science
60 * Carnegie Mellon University
61 * Pittsburgh PA 15213-3890
62 *
63 * any improvements or extensions that they make and grant Carnegie the
64 * rights to redistribute these changes.
65 */
66
67 #include "opt_dec_eb164.h"
68 #include "opt_dec_kn20aa.h"
69 #include "opt_dec_550.h"
70 #include "opt_dec_1000a.h"
71 #include "opt_dec_1000.h"
72
73 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
74
75 __KERNEL_RCSID(0, "$NetBSD: cia.c,v 1.55 2000/04/03 01:48:07 thorpej Exp $");
76
77 #include <sys/param.h>
78 #include <sys/systm.h>
79 #include <sys/kernel.h>
80 #include <sys/malloc.h>
81 #include <sys/device.h>
82 #include <vm/vm.h>
83
84 #include <machine/autoconf.h>
85 #include <machine/rpb.h>
86 #include <machine/sysarch.h>
87
88 #include <dev/isa/isareg.h>
89 #include <dev/isa/isavar.h>
90
91 #include <dev/pci/pcireg.h>
92 #include <dev/pci/pcivar.h>
93 #include <alpha/pci/ciareg.h>
94 #include <alpha/pci/ciavar.h>
95
96 #ifdef DEC_KN20AA
97 #include <alpha/pci/pci_kn20aa.h>
98 #endif
99 #ifdef DEC_EB164
100 #include <alpha/pci/pci_eb164.h>
101 #endif
102 #ifdef DEC_550
103 #include <alpha/pci/pci_550.h>
104 #endif
105 #ifdef DEC_1000A
106 #include <alpha/pci/pci_1000a.h>
107 #endif
108 #ifdef DEC_1000
109 #include <alpha/pci/pci_1000.h>
110 #endif
111
112 int ciamatch __P((struct device *, struct cfdata *, void *));
113 void ciaattach __P((struct device *, struct device *, void *));
114
115 struct cfattach cia_ca = {
116 sizeof(struct cia_softc), ciamatch, ciaattach,
117 };
118
119 extern struct cfdriver cia_cd;
120
121 static int ciaprint __P((void *, const char *pnp));
122
123 int cia_bus_get_window __P((int, int,
124 struct alpha_bus_space_translation *));
125
126 /* There can be only one. */
127 int ciafound;
128 struct cia_config cia_configuration;
129
130 /*
131 * This determines if we attempt to use BWX for PCI bus and config space
132 * access. Some systems, notably with Pyxis, don't fare so well unless
133 * BWX is used.
134 *
135 * EXCEPT! Some devices have a really hard time if BWX is used (WHY?!).
136 * So, we decouple the uses for PCI config space and PCI bus space.
137 *
138 * FURTHERMORE! The Pyxis, most notably earlier revs, really don't
139 * do so well if you don't use BWX for bus access. So we default to
140 * forcing BWX on those chips.
141 *
142 * Geez.
143 */
144
145 #ifndef CIA_PCI_USE_BWX
146 #define CIA_PCI_USE_BWX 1
147 #endif
148
149 #ifndef CIA_BUS_USE_BWX
150 #define CIA_BUS_USE_BWX 0
151 #endif
152
153 #ifndef CIA_PYXIS_FORCE_BWX
154 #define CIA_PYXIS_FORCE_BWX 0
155 #endif
156
157 int cia_pci_use_bwx = CIA_PCI_USE_BWX;
158 int cia_bus_use_bwx = CIA_BUS_USE_BWX;
159 int cia_pyxis_force_bwx = CIA_PYXIS_FORCE_BWX;
160
161 int
162 ciamatch(parent, match, aux)
163 struct device *parent;
164 struct cfdata *match;
165 void *aux;
166 {
167 struct mainbus_attach_args *ma = aux;
168
169 /* Make sure that we're looking for a CIA. */
170 if (strcmp(ma->ma_name, cia_cd.cd_name) != 0)
171 return (0);
172
173 if (ciafound)
174 return (0);
175
176 return (1);
177 }
178
179 /*
180 * Set up the chipset's function pointers.
181 */
182 void
183 cia_init(ccp, mallocsafe)
184 struct cia_config *ccp;
185 int mallocsafe;
186 {
187 int pci_use_bwx = cia_pci_use_bwx;
188 int bus_use_bwx = cia_bus_use_bwx;
189
190 ccp->cc_hae_mem = REGVAL(CIA_CSR_HAE_MEM);
191 ccp->cc_hae_io = REGVAL(CIA_CSR_HAE_IO);
192 ccp->cc_rev = REGVAL(CIA_CSR_REV) & REV_MASK;
193
194 /*
195 * Determine if we have a Pyxis. Only two systypes can
196 * have this: the EB164 systype (AlphaPC164LX and AlphaPC164SX)
197 * and the DEC_550 systype (Miata).
198 */
199 if ((cputype == ST_EB164 &&
200 (hwrpb->rpb_variation & SV_ST_MASK) >= SV_ST_ALPHAPC164LX_400) ||
201 cputype == ST_DEC_550) {
202 ccp->cc_flags |= CCF_ISPYXIS;
203 if (cia_pyxis_force_bwx)
204 pci_use_bwx = bus_use_bwx = 1;
205 }
206
207 /*
208 * ALCOR/ALCOR2 Revisions >= 2 and Pyxis have the CNFG register.
209 */
210 if (ccp->cc_rev >= 2 || (ccp->cc_flags & CCF_ISPYXIS) != 0)
211 ccp->cc_cnfg = REGVAL(CIA_CSR_CNFG);
212 else
213 ccp->cc_cnfg = 0;
214
215 /*
216 * Use BWX iff:
217 *
218 * - It hasn't been disbled by the user,
219 * - it's enabled in CNFG,
220 * - we're implementation version ev5,
221 * - BWX is enabled in the CPU's capabilities mask (yes,
222 * the bit is really cleared if the capability exists...)
223 */
224 if ((pci_use_bwx || bus_use_bwx) &&
225 (ccp->cc_cnfg & CNFG_BWEN) != 0 &&
226 (cpu_amask & ALPHA_AMASK_BWX) != 0) {
227 u_int32_t ctrl;
228
229 if (pci_use_bwx)
230 ccp->cc_flags |= CCF_PCI_USE_BWX;
231 if (bus_use_bwx)
232 ccp->cc_flags |= CCF_BUS_USE_BWX;
233
234 /*
235 * For whatever reason, the firmware seems to enable PCI
236 * loopback mode if it also enables BWX. Make sure it's
237 * enabled if we have an old, buggy firmware rev.
238 */
239 alpha_mb();
240 ctrl = REGVAL(CIA_CSR_CTRL);
241 if ((ctrl & CTRL_PCI_LOOP_EN) == 0) {
242 REGVAL(CIA_CSR_CTRL) = ctrl | CTRL_PCI_LOOP_EN;
243 alpha_mb();
244 }
245 }
246
247 if (!ccp->cc_initted) {
248 /* don't do these twice since they set up extents */
249 if (ccp->cc_flags & CCF_BUS_USE_BWX) {
250 cia_bwx_bus_io_init(&ccp->cc_iot, ccp);
251 cia_bwx_bus_mem_init(&ccp->cc_memt, ccp);
252
253 /*
254 * We have one window for both PCI I/O and MEM
255 * in BWX mode.
256 */
257 alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_IO] = 1;
258 alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_MEM] = 1;
259 } else {
260 cia_swiz_bus_io_init(&ccp->cc_iot, ccp);
261 cia_swiz_bus_mem_init(&ccp->cc_memt, ccp);
262
263 /*
264 * We have two I/O windows and 4 MEM windows in
265 * SWIZ mode.
266 */
267 alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_IO] = 2;
268 alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_MEM] = 4;
269 }
270 alpha_bus_get_window = cia_bus_get_window;
271 }
272 ccp->cc_mallocsafe = mallocsafe;
273
274 cia_pci_init(&ccp->cc_pc, ccp);
275 alpha_pci_chipset = &ccp->cc_pc;
276
277 ccp->cc_initted = 1;
278 }
279
280 void
281 ciaattach(parent, self, aux)
282 struct device *parent, *self;
283 void *aux;
284 {
285 struct cia_softc *sc = (struct cia_softc *)self;
286 struct cia_config *ccp;
287 struct pcibus_attach_args pba;
288 char bits[64];
289 const char *name;
290 int pass;
291
292 /* note that we've attached the chipset; can't have 2 CIAs. */
293 ciafound = 1;
294
295 /*
296 * set up the chipset's info; done once at console init time
297 * (maybe), but we must do it here as well to take care of things
298 * that need to use memory allocation.
299 */
300 ccp = sc->sc_ccp = &cia_configuration;
301 cia_init(ccp, 1);
302
303 if (ccp->cc_flags & CCF_ISPYXIS) {
304 name = "Pyxis";
305 pass = ccp->cc_rev;
306 } else {
307 name = "ALCOR/ALCOR2";
308 pass = ccp->cc_rev + 1;
309 }
310
311 printf(": DECchip 2117x Core Logic Chipset (%s), pass %d\n",
312 name, pass);
313 if (ccp->cc_cnfg)
314 printf("%s: extended capabilities: %s\n", self->dv_xname,
315 bitmask_snprintf(ccp->cc_cnfg, CIA_CSR_CNFG_BITS,
316 bits, sizeof(bits)));
317
318 switch (ccp->cc_flags & (CCF_PCI_USE_BWX|CCF_BUS_USE_BWX)) {
319 case CCF_PCI_USE_BWX|CCF_BUS_USE_BWX:
320 name = "PCI config and bus";
321 break;
322 case CCF_PCI_USE_BWX:
323 name = "PCI config";
324 break;
325 case CCF_BUS_USE_BWX:
326 name = "bus";
327 break;
328 default:
329 name = NULL;
330 break;
331 }
332 if (name != NULL)
333 printf("%s: using BWX for %s access\n", self->dv_xname, name);
334
335 #ifdef DEC_550
336 if (cputype == ST_DEC_550 &&
337 (hwrpb->rpb_variation & SV_ST_MASK) < SV_ST_MIATA_1_5) {
338 /*
339 * Miata 1 systems have a bug: DMA cannot cross
340 * an 8k boundary! Make sure PCI read prefetching
341 * is disabled on these chips. Note that secondary
342 * PCI busses don't have this problem, because of
343 * the way PPBs handle PCI read requests.
344 *
345 * In the 21174 Technical Reference Manual, this is
346 * actually documented as "Pyxis Pass 1", but apparently
347 * there are chips that report themselves as "Pass 1"
348 * which do not have the bug! Miatas with the Cypress
349 * PCI-ISA bridge (i.e. Miata 1.5 and Miata 2) do not
350 * have the bug, so we use this check.
351 *
352 * NOTE: This bug is actually worked around in cia_dma.c,
353 * when direct-mapped DMA maps are created.
354 *
355 * XXX WE NEED TO THINK ABOUT HOW TO HANDLE THIS FOR
356 * XXX SGMAP DMA MAPPINGS!
357 */
358 u_int32_t ctrl;
359
360 /* XXX no bets... */
361 printf("%s: WARNING: Pyxis pass 1 DMA bug; no bets...\n",
362 self->dv_xname);
363
364 ccp->cc_flags |= CCF_PYXISBUG;
365
366 alpha_mb();
367 ctrl = REGVAL(CIA_CSR_CTRL);
368 ctrl &= ~(CTRL_RD_TYPE|CTRL_RL_TYPE|CTRL_RM_TYPE);
369 REGVAL(CIA_CSR_CTRL) = ctrl;
370 alpha_mb();
371 }
372 #endif /* DEC_550 */
373
374 cia_dma_init(ccp);
375
376 switch (cputype) {
377 #ifdef DEC_KN20AA
378 case ST_DEC_KN20AA:
379 pci_kn20aa_pickintr(ccp);
380 break;
381 #endif
382
383 #ifdef DEC_EB164
384 case ST_EB164:
385 pci_eb164_pickintr(ccp);
386 break;
387 #endif
388
389 #ifdef DEC_550
390 case ST_DEC_550:
391 pci_550_pickintr(ccp);
392 break;
393 #endif
394
395 #ifdef DEC_1000A
396 case ST_DEC_1000A:
397 pci_1000a_pickintr(ccp, &ccp->cc_iot, &ccp->cc_memt,
398 &ccp->cc_pc);
399 break;
400 #endif
401
402 #ifdef DEC_1000
403 case ST_DEC_1000:
404 pci_1000_pickintr(ccp, &ccp->cc_iot, &ccp->cc_memt,
405 &ccp->cc_pc);
406 break;
407 #endif
408
409 default:
410 panic("ciaattach: shouldn't be here, really...");
411 }
412
413 pba.pba_busname = "pci";
414 pba.pba_iot = &ccp->cc_iot;
415 pba.pba_memt = &ccp->cc_memt;
416 pba.pba_dmat =
417 alphabus_dma_get_tag(&ccp->cc_dmat_direct, ALPHA_BUS_PCI);
418 pba.pba_pc = &ccp->cc_pc;
419 pba.pba_bus = 0;
420 pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED;
421 if ((ccp->cc_flags & CCF_PYXISBUG) == 0)
422 pba.pba_flags |= PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY |
423 PCI_FLAGS_MWI_OKAY;
424 config_found(self, &pba, ciaprint);
425 }
426
427 static int
428 ciaprint(aux, pnp)
429 void *aux;
430 const char *pnp;
431 {
432 register struct pcibus_attach_args *pba = aux;
433
434 /* only PCIs can attach to CIAs; easy. */
435 if (pnp)
436 printf("%s at %s", pba->pba_busname, pnp);
437 printf(" bus %d", pba->pba_bus);
438 return (UNCONF);
439 }
440
441 int
442 cia_bus_get_window(type, window, abst)
443 int type, window;
444 struct alpha_bus_space_translation *abst;
445 {
446 struct cia_config *ccp = &cia_configuration;
447 bus_space_tag_t st;
448
449 switch (type) {
450 case ALPHA_BUS_TYPE_PCI_IO:
451 st = &ccp->cc_iot;
452 break;
453
454 case ALPHA_BUS_TYPE_PCI_MEM:
455 st = &ccp->cc_memt;
456 break;
457
458 default:
459 panic("cia_bus_get_window");
460 }
461
462 return (alpha_bus_space_get_window(st, window, abst));
463 }
464
465 void
466 cia_pyxis_intr_enable(irq, onoff)
467 int irq, onoff;
468 {
469 u_int64_t imask;
470 int s;
471
472 #if 0
473 printf("cia_pyxis_intr_enable: %s %d\n",
474 onoff ? "enabling" : "disabling", irq);
475 #endif
476
477 s = splhigh();
478 alpha_mb();
479 imask = REGVAL64(PYXIS_INT_MASK);
480 if (onoff)
481 imask |= (1UL << irq);
482 else
483 imask &= ~(1UL << irq);
484 REGVAL64(PYXIS_INT_MASK) = imask;
485 alpha_mb();
486 splx(s);
487 }
488