cia.c revision 1.40 1 1.40 thorpej /* $NetBSD: cia.c,v 1.40 1998/06/05 02:15:38 thorpej Exp $ */
2 1.1 cgd
3 1.1 cgd /*
4 1.4 cgd * Copyright (c) 1995, 1996 Carnegie-Mellon University.
5 1.1 cgd * All rights reserved.
6 1.1 cgd *
7 1.1 cgd * Author: Chris G. Demetriou
8 1.1 cgd *
9 1.1 cgd * Permission to use, copy, modify and distribute this software and
10 1.1 cgd * its documentation is hereby granted, provided that both the copyright
11 1.1 cgd * notice and this permission notice appear in all copies of the
12 1.1 cgd * software, derivative works or modified versions, and any portions
13 1.1 cgd * thereof, and that both notices appear in supporting documentation.
14 1.1 cgd *
15 1.1 cgd * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 1.1 cgd * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
17 1.1 cgd * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 1.1 cgd *
19 1.1 cgd * Carnegie Mellon requests users of this software to return to
20 1.1 cgd *
21 1.1 cgd * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
22 1.1 cgd * School of Computer Science
23 1.1 cgd * Carnegie Mellon University
24 1.1 cgd * Pittsburgh PA 15213-3890
25 1.1 cgd *
26 1.1 cgd * any improvements or extensions that they make and grant Carnegie the
27 1.1 cgd * rights to redistribute these changes.
28 1.1 cgd */
29 1.18 cgd
30 1.25 thorpej #include "opt_dec_eb164.h"
31 1.25 thorpej #include "opt_dec_kn20aa.h"
32 1.39 thorpej #include "opt_dec_550.h"
33 1.25 thorpej
34 1.19 cgd #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
35 1.19 cgd
36 1.40 thorpej __KERNEL_RCSID(0, "$NetBSD: cia.c,v 1.40 1998/06/05 02:15:38 thorpej Exp $");
37 1.1 cgd
38 1.1 cgd #include <sys/param.h>
39 1.1 cgd #include <sys/systm.h>
40 1.1 cgd #include <sys/kernel.h>
41 1.1 cgd #include <sys/malloc.h>
42 1.1 cgd #include <sys/device.h>
43 1.1 cgd #include <vm/vm.h>
44 1.1 cgd
45 1.1 cgd #include <machine/autoconf.h>
46 1.1 cgd #include <machine/rpb.h>
47 1.1 cgd
48 1.1 cgd #include <dev/isa/isareg.h>
49 1.1 cgd #include <dev/isa/isavar.h>
50 1.1 cgd
51 1.1 cgd #include <dev/pci/pcireg.h>
52 1.1 cgd #include <dev/pci/pcivar.h>
53 1.1 cgd #include <alpha/pci/ciareg.h>
54 1.1 cgd #include <alpha/pci/ciavar.h>
55 1.17 cgd #ifdef DEC_KN20AA
56 1.1 cgd #include <alpha/pci/pci_kn20aa.h>
57 1.1 cgd #endif
58 1.17 cgd #ifdef DEC_EB164
59 1.13 cgd #include <alpha/pci/pci_eb164.h>
60 1.13 cgd #endif
61 1.39 thorpej #ifdef DEC_550
62 1.39 thorpej #include <alpha/pci/pci_550.h>
63 1.39 thorpej #endif
64 1.1 cgd
65 1.15 cgd int ciamatch __P((struct device *, struct cfdata *, void *));
66 1.1 cgd void ciaattach __P((struct device *, struct device *, void *));
67 1.1 cgd
68 1.5 cgd struct cfattach cia_ca = {
69 1.5 cgd sizeof(struct cia_softc), ciamatch, ciaattach,
70 1.5 cgd };
71 1.5 cgd
72 1.29 thorpej extern struct cfdriver cia_cd;
73 1.1 cgd
74 1.9 cgd static int ciaprint __P((void *, const char *pnp));
75 1.1 cgd
76 1.1 cgd /* There can be only one. */
77 1.1 cgd int ciafound;
78 1.1 cgd struct cia_config cia_configuration;
79 1.1 cgd
80 1.37 thorpej /*
81 1.37 thorpej * This determines if we attempt to use BWX for PCI bus and config space
82 1.37 thorpej * access. Some systems, notably with Pyxis, don't fare so well unless
83 1.37 thorpej * BWX is used.
84 1.37 thorpej */
85 1.37 thorpej #ifndef CIA_USE_BWX
86 1.37 thorpej #define CIA_USE_BWX 1
87 1.37 thorpej #endif
88 1.37 thorpej
89 1.37 thorpej int cia_use_bwx = CIA_USE_BWX;
90 1.37 thorpej
91 1.1 cgd int
92 1.1 cgd ciamatch(parent, match, aux)
93 1.1 cgd struct device *parent;
94 1.15 cgd struct cfdata *match;
95 1.15 cgd void *aux;
96 1.1 cgd {
97 1.35 thorpej struct mainbus_attach_args *ma = aux;
98 1.1 cgd
99 1.1 cgd /* Make sure that we're looking for a CIA. */
100 1.35 thorpej if (strcmp(ma->ma_name, cia_cd.cd_name) != 0)
101 1.1 cgd return (0);
102 1.1 cgd
103 1.1 cgd if (ciafound)
104 1.1 cgd return (0);
105 1.1 cgd
106 1.1 cgd return (1);
107 1.1 cgd }
108 1.1 cgd
109 1.1 cgd /*
110 1.1 cgd * Set up the chipset's function pointers.
111 1.1 cgd */
112 1.1 cgd void
113 1.14 cgd cia_init(ccp, mallocsafe)
114 1.1 cgd struct cia_config *ccp;
115 1.14 cgd int mallocsafe;
116 1.1 cgd {
117 1.1 cgd
118 1.6 cgd ccp->cc_hae_mem = REGVAL(CIA_CSR_HAE_MEM);
119 1.6 cgd ccp->cc_hae_io = REGVAL(CIA_CSR_HAE_IO);
120 1.36 thorpej ccp->cc_rev = REGVAL(CIA_CSR_REV) & REV_MASK;
121 1.36 thorpej
122 1.36 thorpej /*
123 1.36 thorpej * Determine if we have a Pyxis. Only two systypes can
124 1.36 thorpej * have this: the EB164 systype (AlphaPC164LX and AlphaPC164SX)
125 1.36 thorpej * and the DEC_550 systype (Miata).
126 1.36 thorpej */
127 1.36 thorpej if ((hwrpb->rpb_type == ST_EB164 &&
128 1.36 thorpej (hwrpb->rpb_variation & SV_ST_MASK) >= SV_ST_ALPHAPC164LX_400) ||
129 1.36 thorpej hwrpb->rpb_type == ST_DEC_550)
130 1.36 thorpej ccp->cc_flags |= CCF_ISPYXIS;
131 1.27 thorpej
132 1.27 thorpej /*
133 1.40 thorpej * ALCOR/ALCOR2 Revisions >= 2 and Pyxis have the CNFG register.
134 1.27 thorpej */
135 1.40 thorpej if (ccp->cc_rev >= 2 || (ccp->cc_flags & CCF_ISPYXIS) != 0)
136 1.27 thorpej ccp->cc_cnfg = REGVAL(CIA_CSR_CNFG);
137 1.27 thorpej else
138 1.27 thorpej ccp->cc_cnfg = 0;
139 1.12 cgd
140 1.37 thorpej /*
141 1.37 thorpej * Use BWX iff:
142 1.37 thorpej *
143 1.37 thorpej * - It hasn't been disbled by the user,
144 1.37 thorpej * - it's enabled in CNFG,
145 1.37 thorpej * - we're implementation version ev5,
146 1.37 thorpej * - BWX is enabled in the CPU's capabilities mask (yes,
147 1.37 thorpej * the bit is really cleared if the capability exists...)
148 1.37 thorpej */
149 1.37 thorpej if (cia_use_bwx != 0 &&
150 1.37 thorpej (ccp->cc_cnfg & CNFG_BWEN) != 0 &&
151 1.37 thorpej alpha_implver() == ALPHA_IMPLVER_EV5 &&
152 1.38 thorpej alpha_amask(ALPHA_AMASK_BWX) == 0) {
153 1.38 thorpej u_int32_t ctrl;
154 1.38 thorpej
155 1.37 thorpej ccp->cc_flags |= CCF_USEBWX;
156 1.38 thorpej
157 1.38 thorpej /*
158 1.38 thorpej * For whatever reason, the firmware seems to enable PCI
159 1.38 thorpej * loopback mode if it also enables BWX. Make sure it's
160 1.38 thorpej * enabled if we have an old, buggy firmware rev.
161 1.38 thorpej */
162 1.38 thorpej alpha_mb();
163 1.38 thorpej ctrl = REGVAL(CIA_CSR_CTRL);
164 1.38 thorpej if ((ctrl & CTRL_PCI_LOOP_EN) == 0) {
165 1.38 thorpej REGVAL(CIA_CSR_CTRL) = ctrl | CTRL_PCI_LOOP_EN;
166 1.38 thorpej alpha_mb();
167 1.38 thorpej }
168 1.38 thorpej }
169 1.37 thorpej
170 1.14 cgd if (!ccp->cc_initted) {
171 1.14 cgd /* don't do these twice since they set up extents */
172 1.37 thorpej if (ccp->cc_flags & CCF_USEBWX) {
173 1.37 thorpej cia_bwx_bus_io_init(&ccp->cc_iot, ccp);
174 1.37 thorpej cia_bwx_bus_mem_init(&ccp->cc_memt, ccp);
175 1.37 thorpej } else {
176 1.37 thorpej cia_swiz_bus_io_init(&ccp->cc_iot, ccp);
177 1.37 thorpej cia_swiz_bus_mem_init(&ccp->cc_memt, ccp);
178 1.37 thorpej }
179 1.14 cgd }
180 1.14 cgd ccp->cc_mallocsafe = mallocsafe;
181 1.14 cgd
182 1.14 cgd cia_pci_init(&ccp->cc_pc, ccp);
183 1.14 cgd
184 1.21 thorpej cia_dma_init(ccp);
185 1.14 cgd
186 1.14 cgd ccp->cc_initted = 1;
187 1.1 cgd }
188 1.1 cgd
189 1.1 cgd void
190 1.1 cgd ciaattach(parent, self, aux)
191 1.1 cgd struct device *parent, *self;
192 1.1 cgd void *aux;
193 1.1 cgd {
194 1.1 cgd struct cia_softc *sc = (struct cia_softc *)self;
195 1.1 cgd struct cia_config *ccp;
196 1.5 cgd struct pcibus_attach_args pba;
197 1.28 thorpej char bits[64];
198 1.1 cgd
199 1.1 cgd /* note that we've attached the chipset; can't have 2 CIAs. */
200 1.1 cgd ciafound = 1;
201 1.1 cgd
202 1.1 cgd /*
203 1.1 cgd * set up the chipset's info; done once at console init time
204 1.21 thorpej * (maybe), but we must do it here as well to take care of things
205 1.21 thorpej * that need to use memory allocation.
206 1.1 cgd */
207 1.1 cgd ccp = sc->sc_ccp = &cia_configuration;
208 1.14 cgd cia_init(ccp, 1);
209 1.1 cgd
210 1.36 thorpej printf(": DECchip 2117x Core Logic Chipset (%s), pass %d\n",
211 1.36 thorpej (ccp->cc_flags & CCF_ISPYXIS) ? "Pyxis" : "ALCOR/ALCOR2",
212 1.36 thorpej ccp->cc_rev + 1);
213 1.28 thorpej if (ccp->cc_cnfg)
214 1.28 thorpej printf("%s: extended capabilities: %s\n", self->dv_xname,
215 1.28 thorpej bitmask_snprintf(ccp->cc_cnfg, CIA_CSR_CNFG_BITS,
216 1.28 thorpej bits, sizeof(bits)));
217 1.37 thorpej #if 1
218 1.37 thorpej if (ccp->cc_flags & CCF_USEBWX)
219 1.37 thorpej printf("%s: using BWX for PCI config and device access\n",
220 1.37 thorpej self->dv_xname);
221 1.37 thorpej #endif
222 1.1 cgd
223 1.1 cgd switch (hwrpb->rpb_type) {
224 1.17 cgd #ifdef DEC_KN20AA
225 1.1 cgd case ST_DEC_KN20AA:
226 1.5 cgd pci_kn20aa_pickintr(ccp);
227 1.1 cgd #ifdef EVCNT_COUNTERS
228 1.1 cgd evcnt_attach(self, "intr", &kn20aa_intr_evcnt);
229 1.1 cgd #endif
230 1.1 cgd break;
231 1.1 cgd #endif
232 1.13 cgd
233 1.17 cgd #ifdef DEC_EB164
234 1.13 cgd case ST_EB164:
235 1.13 cgd pci_eb164_pickintr(ccp);
236 1.13 cgd #ifdef EVCNT_COUNTERS
237 1.13 cgd evcnt_attach(self, "intr", &eb164_intr_evcnt);
238 1.39 thorpej #endif
239 1.39 thorpej break;
240 1.39 thorpej #endif
241 1.39 thorpej
242 1.39 thorpej #ifdef DEC_550
243 1.39 thorpej case ST_DEC_550:
244 1.39 thorpej pci_550_pickintr(ccp);
245 1.39 thorpej #ifdef EVCNT_COUNTERS
246 1.39 thorpej evcnt_attach(self, "intr", &dec_550_intr_evcnt);
247 1.13 cgd #endif
248 1.13 cgd break;
249 1.13 cgd #endif
250 1.13 cgd
251 1.1 cgd default:
252 1.1 cgd panic("ciaattach: shouldn't be here, really...");
253 1.1 cgd }
254 1.1 cgd
255 1.5 cgd pba.pba_busname = "pci";
256 1.23 thorpej pba.pba_iot = &ccp->cc_iot;
257 1.23 thorpej pba.pba_memt = &ccp->cc_memt;
258 1.30 thorpej pba.pba_dmat =
259 1.30 thorpej alphabus_dma_get_tag(&ccp->cc_dmat_direct, ALPHA_BUS_PCI);
260 1.5 cgd pba.pba_pc = &ccp->cc_pc;
261 1.5 cgd pba.pba_bus = 0;
262 1.20 cgd pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED;
263 1.5 cgd config_found(self, &pba, ciaprint);
264 1.1 cgd }
265 1.1 cgd
266 1.1 cgd static int
267 1.1 cgd ciaprint(aux, pnp)
268 1.1 cgd void *aux;
269 1.9 cgd const char *pnp;
270 1.1 cgd {
271 1.5 cgd register struct pcibus_attach_args *pba = aux;
272 1.1 cgd
273 1.1 cgd /* only PCIs can attach to CIAs; easy. */
274 1.1 cgd if (pnp)
275 1.11 christos printf("%s at %s", pba->pba_busname, pnp);
276 1.11 christos printf(" bus %d", pba->pba_bus);
277 1.1 cgd return (UNCONF);
278 1.1 cgd }
279