cia.c revision 1.58 1 /* $NetBSD: cia.c,v 1.58 2002/05/16 01:01:31 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.58 2002/05/16 01:01:31 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
83 #include <uvm/uvm_extern.h>
84
85 #include <machine/autoconf.h>
86 #include <machine/rpb.h>
87 #include <machine/sysarch.h>
88 #include <machine/alpha.h>
89
90 #include <dev/isa/isareg.h>
91 #include <dev/isa/isavar.h>
92
93 #include <dev/pci/pcireg.h>
94 #include <dev/pci/pcivar.h>
95 #include <alpha/pci/ciareg.h>
96 #include <alpha/pci/ciavar.h>
97
98 #ifdef DEC_KN20AA
99 #include <alpha/pci/pci_kn20aa.h>
100 #endif
101 #ifdef DEC_EB164
102 #include <alpha/pci/pci_eb164.h>
103 #endif
104 #ifdef DEC_550
105 #include <alpha/pci/pci_550.h>
106 #endif
107 #ifdef DEC_1000A
108 #include <alpha/pci/pci_1000a.h>
109 #endif
110 #ifdef DEC_1000
111 #include <alpha/pci/pci_1000.h>
112 #endif
113
114 int ciamatch __P((struct device *, struct cfdata *, void *));
115 void ciaattach __P((struct device *, struct device *, void *));
116
117 struct cfattach cia_ca = {
118 sizeof(struct cia_softc), ciamatch, ciaattach,
119 };
120
121 extern struct cfdriver cia_cd;
122
123 static int ciaprint __P((void *, const char *pnp));
124
125 int cia_bus_get_window __P((int, int,
126 struct alpha_bus_space_translation *));
127
128 /* There can be only one. */
129 int ciafound;
130 struct cia_config cia_configuration;
131
132 /*
133 * This determines if we attempt to use BWX for PCI bus and config space
134 * access. Some systems, notably with Pyxis, don't fare so well unless
135 * BWX is used.
136 *
137 * EXCEPT! Some devices have a really hard time if BWX is used (WHY?!).
138 * So, we decouple the uses for PCI config space and PCI bus space.
139 *
140 * FURTHERMORE! The Pyxis, most notably earlier revs, really don't
141 * do so well if you don't use BWX for bus access. So we default to
142 * forcing BWX on those chips.
143 *
144 * Geez.
145 */
146
147 #ifndef CIA_PCI_USE_BWX
148 #define CIA_PCI_USE_BWX 1
149 #endif
150
151 #ifndef CIA_BUS_USE_BWX
152 #define CIA_BUS_USE_BWX 0
153 #endif
154
155 #ifndef CIA_PYXIS_FORCE_BWX
156 #define CIA_PYXIS_FORCE_BWX 0
157 #endif
158
159 int cia_pci_use_bwx = CIA_PCI_USE_BWX;
160 int cia_bus_use_bwx = CIA_BUS_USE_BWX;
161 int cia_pyxis_force_bwx = CIA_PYXIS_FORCE_BWX;
162
163 int
164 ciamatch(parent, match, aux)
165 struct device *parent;
166 struct cfdata *match;
167 void *aux;
168 {
169 struct mainbus_attach_args *ma = aux;
170
171 /* Make sure that we're looking for a CIA. */
172 if (strcmp(ma->ma_name, cia_cd.cd_name) != 0)
173 return (0);
174
175 if (ciafound)
176 return (0);
177
178 return (1);
179 }
180
181 /*
182 * Set up the chipset's function pointers.
183 */
184 void
185 cia_init(ccp, mallocsafe)
186 struct cia_config *ccp;
187 int mallocsafe;
188 {
189 int pci_use_bwx = cia_pci_use_bwx;
190 int bus_use_bwx = cia_bus_use_bwx;
191
192 ccp->cc_hae_mem = REGVAL(CIA_CSR_HAE_MEM);
193 ccp->cc_hae_io = REGVAL(CIA_CSR_HAE_IO);
194 ccp->cc_rev = REGVAL(CIA_CSR_REV) & REV_MASK;
195
196 /*
197 * Determine if we have a Pyxis. Only two systypes can
198 * have this: the EB164 systype (AlphaPC164LX and AlphaPC164SX)
199 * and the DEC_550 systype (Miata).
200 */
201 if ((cputype == ST_EB164 &&
202 (hwrpb->rpb_variation & SV_ST_MASK) >= SV_ST_ALPHAPC164LX_400) ||
203 cputype == ST_DEC_550) {
204 ccp->cc_flags |= CCF_ISPYXIS;
205 if (cia_pyxis_force_bwx)
206 pci_use_bwx = bus_use_bwx = 1;
207 }
208
209 /*
210 * ALCOR/ALCOR2 Revisions >= 2 and Pyxis have the CNFG register.
211 */
212 if (ccp->cc_rev >= 2 || (ccp->cc_flags & CCF_ISPYXIS) != 0)
213 ccp->cc_cnfg = REGVAL(CIA_CSR_CNFG);
214 else
215 ccp->cc_cnfg = 0;
216
217 /*
218 * Use BWX iff:
219 *
220 * - It hasn't been disbled by the user,
221 * - it's enabled in CNFG,
222 * - we're implementation version ev5,
223 * - BWX is enabled in the CPU's capabilities mask
224 */
225 if ((pci_use_bwx || bus_use_bwx) &&
226 (ccp->cc_cnfg & CNFG_BWEN) != 0 &&
227 (cpu_amask & ALPHA_AMASK_BWX) != 0) {
228 u_int32_t ctrl;
229
230 if (pci_use_bwx)
231 ccp->cc_flags |= CCF_PCI_USE_BWX;
232 if (bus_use_bwx)
233 ccp->cc_flags |= CCF_BUS_USE_BWX;
234
235 /*
236 * For whatever reason, the firmware seems to enable PCI
237 * loopback mode if it also enables BWX. Make sure it's
238 * enabled if we have an old, buggy firmware rev.
239 */
240 alpha_mb();
241 ctrl = REGVAL(CIA_CSR_CTRL);
242 if ((ctrl & CTRL_PCI_LOOP_EN) == 0) {
243 REGVAL(CIA_CSR_CTRL) = ctrl | CTRL_PCI_LOOP_EN;
244 alpha_mb();
245 }
246 }
247
248 if (!ccp->cc_initted) {
249 /* don't do these twice since they set up extents */
250 if (ccp->cc_flags & CCF_BUS_USE_BWX) {
251 cia_bwx_bus_io_init(&ccp->cc_iot, ccp);
252 cia_bwx_bus_mem_init(&ccp->cc_memt, ccp);
253
254 /*
255 * We have one window for both PCI I/O and MEM
256 * in BWX mode.
257 */
258 alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_IO] = 1;
259 alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_MEM] = 1;
260 } else {
261 cia_swiz_bus_io_init(&ccp->cc_iot, ccp);
262 cia_swiz_bus_mem_init(&ccp->cc_memt, ccp);
263
264 /*
265 * We have two I/O windows and 4 MEM windows in
266 * SWIZ mode.
267 */
268 alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_IO] = 2;
269 alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_MEM] = 4;
270 }
271 alpha_bus_get_window = cia_bus_get_window;
272 }
273 ccp->cc_mallocsafe = mallocsafe;
274
275 cia_pci_init(&ccp->cc_pc, ccp);
276 alpha_pci_chipset = &ccp->cc_pc;
277
278 ccp->cc_initted = 1;
279 }
280
281 void
282 ciaattach(parent, self, aux)
283 struct device *parent, *self;
284 void *aux;
285 {
286 struct cia_softc *sc = (struct cia_softc *)self;
287 struct cia_config *ccp;
288 struct pcibus_attach_args pba;
289 char bits[64];
290 const char *name;
291 int pass;
292
293 /* note that we've attached the chipset; can't have 2 CIAs. */
294 ciafound = 1;
295
296 /*
297 * set up the chipset's info; done once at console init time
298 * (maybe), but we must do it here as well to take care of things
299 * that need to use memory allocation.
300 */
301 ccp = sc->sc_ccp = &cia_configuration;
302 cia_init(ccp, 1);
303
304 if (ccp->cc_flags & CCF_ISPYXIS) {
305 name = "Pyxis";
306 pass = ccp->cc_rev;
307 } else {
308 name = "ALCOR/ALCOR2";
309 pass = ccp->cc_rev + 1;
310 }
311
312 printf(": DECchip 2117x Core Logic Chipset (%s), pass %d\n",
313 name, pass);
314 if (ccp->cc_cnfg)
315 printf("%s: extended capabilities: %s\n", self->dv_xname,
316 bitmask_snprintf(ccp->cc_cnfg, CIA_CSR_CNFG_BITS,
317 bits, sizeof(bits)));
318
319 switch (ccp->cc_flags & (CCF_PCI_USE_BWX|CCF_BUS_USE_BWX)) {
320 case CCF_PCI_USE_BWX|CCF_BUS_USE_BWX:
321 name = "PCI config and bus";
322 break;
323 case CCF_PCI_USE_BWX:
324 name = "PCI config";
325 break;
326 case CCF_BUS_USE_BWX:
327 name = "bus";
328 break;
329 default:
330 name = NULL;
331 break;
332 }
333 if (name != NULL)
334 printf("%s: using BWX for %s access\n", self->dv_xname, name);
335
336 #ifdef DEC_550
337 if (cputype == ST_DEC_550 &&
338 (hwrpb->rpb_variation & SV_ST_MASK) < SV_ST_MIATA_1_5) {
339 /*
340 * Miata 1 systems have a bug: DMA cannot cross
341 * an 8k boundary! Make sure PCI read prefetching
342 * is disabled on these chips. Note that secondary
343 * PCI busses don't have this problem, because of
344 * the way PPBs handle PCI read requests.
345 *
346 * In the 21174 Technical Reference Manual, this is
347 * actually documented as "Pyxis Pass 1", but apparently
348 * there are chips that report themselves as "Pass 1"
349 * which do not have the bug! Miatas with the Cypress
350 * PCI-ISA bridge (i.e. Miata 1.5 and Miata 2) do not
351 * have the bug, so we use this check.
352 *
353 * NOTE: This bug is actually worked around in cia_dma.c,
354 * when direct-mapped DMA maps are created.
355 *
356 * XXX WE NEED TO THINK ABOUT HOW TO HANDLE THIS FOR
357 * XXX SGMAP DMA MAPPINGS!
358 */
359 u_int32_t ctrl;
360
361 /* XXX no bets... */
362 printf("%s: WARNING: Pyxis pass 1 DMA bug; no bets...\n",
363 self->dv_xname);
364
365 ccp->cc_flags |= CCF_PYXISBUG;
366
367 alpha_mb();
368 ctrl = REGVAL(CIA_CSR_CTRL);
369 ctrl &= ~(CTRL_RD_TYPE|CTRL_RL_TYPE|CTRL_RM_TYPE);
370 REGVAL(CIA_CSR_CTRL) = ctrl;
371 alpha_mb();
372 }
373 #endif /* DEC_550 */
374
375 cia_dma_init(ccp);
376
377 switch (cputype) {
378 #ifdef DEC_KN20AA
379 case ST_DEC_KN20AA:
380 pci_kn20aa_pickintr(ccp);
381 break;
382 #endif
383
384 #ifdef DEC_EB164
385 case ST_EB164:
386 pci_eb164_pickintr(ccp);
387 break;
388 #endif
389
390 #ifdef DEC_550
391 case ST_DEC_550:
392 pci_550_pickintr(ccp);
393 break;
394 #endif
395
396 #ifdef DEC_1000A
397 case ST_DEC_1000A:
398 pci_1000a_pickintr(ccp, &ccp->cc_iot, &ccp->cc_memt,
399 &ccp->cc_pc);
400 break;
401 #endif
402
403 #ifdef DEC_1000
404 case ST_DEC_1000:
405 pci_1000_pickintr(ccp, &ccp->cc_iot, &ccp->cc_memt,
406 &ccp->cc_pc);
407 break;
408 #endif
409
410 default:
411 panic("ciaattach: shouldn't be here, really...");
412 }
413
414 pba.pba_busname = "pci";
415 pba.pba_iot = &ccp->cc_iot;
416 pba.pba_memt = &ccp->cc_memt;
417 pba.pba_dmat =
418 alphabus_dma_get_tag(&ccp->cc_dmat_direct, ALPHA_BUS_PCI);
419 pba.pba_pc = &ccp->cc_pc;
420 pba.pba_bus = 0;
421 pba.pba_bridgetag = NULL;
422 pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED;
423 if ((ccp->cc_flags & CCF_PYXISBUG) == 0)
424 pba.pba_flags |= PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY |
425 PCI_FLAGS_MWI_OKAY;
426 config_found(self, &pba, ciaprint);
427 }
428
429 static int
430 ciaprint(aux, pnp)
431 void *aux;
432 const char *pnp;
433 {
434 register struct pcibus_attach_args *pba = aux;
435
436 /* only PCIs can attach to CIAs; easy. */
437 if (pnp)
438 printf("%s at %s", pba->pba_busname, pnp);
439 printf(" bus %d", pba->pba_bus);
440 return (UNCONF);
441 }
442
443 int
444 cia_bus_get_window(type, window, abst)
445 int type, window;
446 struct alpha_bus_space_translation *abst;
447 {
448 struct cia_config *ccp = &cia_configuration;
449 bus_space_tag_t st;
450
451 switch (type) {
452 case ALPHA_BUS_TYPE_PCI_IO:
453 st = &ccp->cc_iot;
454 break;
455
456 case ALPHA_BUS_TYPE_PCI_MEM:
457 st = &ccp->cc_memt;
458 break;
459
460 default:
461 panic("cia_bus_get_window");
462 }
463
464 return (alpha_bus_space_get_window(st, window, abst));
465 }
466
467 void
468 cia_pyxis_intr_enable(irq, onoff)
469 int irq, onoff;
470 {
471 u_int64_t imask;
472 int s;
473
474 #if 0
475 printf("cia_pyxis_intr_enable: %s %d\n",
476 onoff ? "enabling" : "disabling", irq);
477 #endif
478
479 s = splhigh();
480 alpha_mb();
481 imask = REGVAL64(PYXIS_INT_MASK);
482 if (onoff)
483 imask |= (1UL << irq);
484 else
485 imask &= ~(1UL << irq);
486 REGVAL64(PYXIS_INT_MASK) = imask;
487 alpha_mb();
488 splx(s);
489 }
490