cia.c revision 1.21.4.1 1 1.21.4.1 thorpej /* $NetBSD: cia.c,v 1.21.4.1 1997/08/23 07:06:58 thorpej Exp $ */
2 1.21.4.1 thorpej
3 1.21.4.1 thorpej /*
4 1.21.4.1 thorpej * Copyright Notice:
5 1.21.4.1 thorpej *
6 1.21.4.1 thorpej * Copyright (c) 1997 Christopher G. Demetriou. All rights reserved.
7 1.21.4.1 thorpej *
8 1.21.4.1 thorpej * License:
9 1.21.4.1 thorpej *
10 1.21.4.1 thorpej * This License applies to this software ("Software"), created
11 1.21.4.1 thorpej * by Christopher G. Demetriou ("Author").
12 1.21.4.1 thorpej *
13 1.21.4.1 thorpej * You may use, copy, modify and redistribute this Software without
14 1.21.4.1 thorpej * charge, in either source code form, binary form, or both, on the
15 1.21.4.1 thorpej * following conditions:
16 1.21.4.1 thorpej *
17 1.21.4.1 thorpej * 1. (a) Binary code: (i) a complete copy of the above copyright notice
18 1.21.4.1 thorpej * must be included within each copy of the Software in binary code form,
19 1.21.4.1 thorpej * and (ii) a complete copy of the above copyright notice and all terms
20 1.21.4.1 thorpej * of this License as presented here must be included within each copy of
21 1.21.4.1 thorpej * all documentation accompanying or associated with binary code, in any
22 1.21.4.1 thorpej * medium, along with a list of the software modules to which the license
23 1.21.4.1 thorpej * applies.
24 1.21.4.1 thorpej *
25 1.21.4.1 thorpej * (b) Source Code: A complete copy of the above copyright notice and all
26 1.21.4.1 thorpej * terms of this License as presented here must be included within: (i)
27 1.21.4.1 thorpej * each copy of the Software in source code form, and (ii) each copy of
28 1.21.4.1 thorpej * all accompanying or associated documentation, in any medium.
29 1.21.4.1 thorpej *
30 1.21.4.1 thorpej * 2. The following Acknowledgment must be used in communications
31 1.21.4.1 thorpej * involving the Software as described below:
32 1.21.4.1 thorpej *
33 1.21.4.1 thorpej * This product includes software developed by
34 1.21.4.1 thorpej * Christopher G. Demetriou for the NetBSD Project.
35 1.21.4.1 thorpej *
36 1.21.4.1 thorpej * The Acknowledgment must be conspicuously and completely displayed
37 1.21.4.1 thorpej * whenever the Software, or any software, products or systems containing
38 1.21.4.1 thorpej * the Software, are mentioned in advertising, marketing, informational
39 1.21.4.1 thorpej * or publicity materials of any kind, whether in print, electronic or
40 1.21.4.1 thorpej * other media (except for information provided to support use of
41 1.21.4.1 thorpej * products containing the Software by existing users or customers).
42 1.21.4.1 thorpej *
43 1.21.4.1 thorpej * 3. The name of the Author may not be used to endorse or promote
44 1.21.4.1 thorpej * products derived from this Software without specific prior written
45 1.21.4.1 thorpej * permission (conditions (1) and (2) above are not considered
46 1.21.4.1 thorpej * endorsement or promotion).
47 1.21.4.1 thorpej *
48 1.21.4.1 thorpej * 4. This license applies to: (a) all copies of the Software, whether
49 1.21.4.1 thorpej * partial or whole, original or modified, and (b) your actions, and the
50 1.21.4.1 thorpej * actions of all those who may act on your behalf. All uses not
51 1.21.4.1 thorpej * expressly permitted are reserved to the Author.
52 1.21.4.1 thorpej *
53 1.21.4.1 thorpej * 5. Disclaimer. THIS SOFTWARE IS MADE AVAILABLE BY THE AUTHOR TO THE
54 1.21.4.1 thorpej * PUBLIC FOR FREE AND "AS IS.'' ALL USERS OF THIS FREE SOFTWARE ARE
55 1.21.4.1 thorpej * SOLELY AND ENTIRELY RESPONSIBLE FOR THEIR OWN CHOICE AND USE OF THIS
56 1.21.4.1 thorpej * SOFTWARE FOR THEIR OWN PURPOSES. BY USING THIS SOFTWARE, EACH USER
57 1.21.4.1 thorpej * AGREES THAT THE AUTHOR SHALL NOT BE LIABLE FOR DAMAGES OF ANY KIND IN
58 1.21.4.1 thorpej * RELATION TO ITS USE OR PERFORMANCE.
59 1.21.4.1 thorpej *
60 1.21.4.1 thorpej * 6. If you have a special need for a change in one or more of these
61 1.21.4.1 thorpej * license conditions, please contact the Author via electronic mail to
62 1.21.4.1 thorpej *
63 1.21.4.1 thorpej * cgd (at) NetBSD.ORG
64 1.21.4.1 thorpej *
65 1.21.4.1 thorpej * or via the contact information on
66 1.21.4.1 thorpej *
67 1.21.4.1 thorpej * http://www.NetBSD.ORG/People/Pages/cgd.html
68 1.21.4.1 thorpej */
69 1.1 cgd
70 1.1 cgd /*
71 1.4 cgd * Copyright (c) 1995, 1996 Carnegie-Mellon University.
72 1.1 cgd * All rights reserved.
73 1.1 cgd *
74 1.1 cgd * Author: Chris G. Demetriou
75 1.1 cgd *
76 1.1 cgd * Permission to use, copy, modify and distribute this software and
77 1.1 cgd * its documentation is hereby granted, provided that both the copyright
78 1.1 cgd * notice and this permission notice appear in all copies of the
79 1.1 cgd * software, derivative works or modified versions, and any portions
80 1.1 cgd * thereof, and that both notices appear in supporting documentation.
81 1.1 cgd *
82 1.1 cgd * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
83 1.1 cgd * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
84 1.1 cgd * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
85 1.1 cgd *
86 1.1 cgd * Carnegie Mellon requests users of this software to return to
87 1.1 cgd *
88 1.1 cgd * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
89 1.1 cgd * School of Computer Science
90 1.1 cgd * Carnegie Mellon University
91 1.1 cgd * Pittsburgh PA 15213-3890
92 1.1 cgd *
93 1.1 cgd * any improvements or extensions that they make and grant Carnegie the
94 1.1 cgd * rights to redistribute these changes.
95 1.1 cgd */
96 1.18 cgd
97 1.19 cgd #include <machine/options.h> /* Config options headers */
98 1.19 cgd #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
99 1.19 cgd
100 1.21.4.1 thorpej __KERNEL_RCSID(0, "$NetBSD: cia.c,v 1.21.4.1 1997/08/23 07:06:58 thorpej Exp $");
101 1.21.4.1 thorpej __KERNEL_COPYRIGHT(0,
102 1.21.4.1 thorpej "Copyright (c) 1997 Christopher G. Demetriou. All rights reserved.");
103 1.1 cgd
104 1.1 cgd #include <sys/param.h>
105 1.1 cgd #include <sys/systm.h>
106 1.1 cgd #include <sys/kernel.h>
107 1.1 cgd #include <sys/malloc.h>
108 1.1 cgd #include <sys/device.h>
109 1.1 cgd #include <vm/vm.h>
110 1.1 cgd
111 1.1 cgd #include <machine/autoconf.h>
112 1.1 cgd #include <machine/rpb.h>
113 1.1 cgd
114 1.1 cgd #include <dev/isa/isareg.h>
115 1.1 cgd #include <dev/isa/isavar.h>
116 1.1 cgd
117 1.1 cgd #include <dev/pci/pcireg.h>
118 1.1 cgd #include <dev/pci/pcivar.h>
119 1.1 cgd #include <alpha/pci/ciareg.h>
120 1.1 cgd #include <alpha/pci/ciavar.h>
121 1.17 cgd #ifdef DEC_KN20AA
122 1.1 cgd #include <alpha/pci/pci_kn20aa.h>
123 1.1 cgd #endif
124 1.17 cgd #ifdef DEC_EB164
125 1.13 cgd #include <alpha/pci/pci_eb164.h>
126 1.13 cgd #endif
127 1.1 cgd
128 1.15 cgd int ciamatch __P((struct device *, struct cfdata *, void *));
129 1.1 cgd void ciaattach __P((struct device *, struct device *, void *));
130 1.1 cgd
131 1.5 cgd struct cfattach cia_ca = {
132 1.5 cgd sizeof(struct cia_softc), ciamatch, ciaattach,
133 1.5 cgd };
134 1.5 cgd
135 1.5 cgd struct cfdriver cia_cd = {
136 1.5 cgd NULL, "cia", DV_DULL,
137 1.1 cgd };
138 1.1 cgd
139 1.9 cgd static int ciaprint __P((void *, const char *pnp));
140 1.1 cgd
141 1.1 cgd /* There can be only one. */
142 1.1 cgd int ciafound;
143 1.1 cgd struct cia_config cia_configuration;
144 1.1 cgd
145 1.1 cgd int
146 1.1 cgd ciamatch(parent, match, aux)
147 1.1 cgd struct device *parent;
148 1.15 cgd struct cfdata *match;
149 1.15 cgd void *aux;
150 1.1 cgd {
151 1.1 cgd struct confargs *ca = aux;
152 1.1 cgd
153 1.1 cgd /* Make sure that we're looking for a CIA. */
154 1.5 cgd if (strcmp(ca->ca_name, cia_cd.cd_name) != 0)
155 1.1 cgd return (0);
156 1.1 cgd
157 1.1 cgd if (ciafound)
158 1.1 cgd return (0);
159 1.1 cgd
160 1.1 cgd return (1);
161 1.1 cgd }
162 1.1 cgd
163 1.1 cgd /*
164 1.1 cgd * Set up the chipset's function pointers.
165 1.1 cgd */
166 1.1 cgd void
167 1.14 cgd cia_init(ccp, mallocsafe)
168 1.1 cgd struct cia_config *ccp;
169 1.14 cgd int mallocsafe;
170 1.1 cgd {
171 1.1 cgd
172 1.21.4.1 thorpej ccp->cc_pass =
173 1.21.4.1 thorpej (REGVAL(CIA_CSR_CIA_REV) & CIA_REV_REV_MASK) >> CIA_REV_REV_SHIFT;
174 1.21.4.1 thorpej ccp->cc_is21172 = (ccp->cc_pass >= 3);
175 1.21.4.1 thorpej ccp->cc_bwx_enabled = ccp->cc_is21172 &&
176 1.21.4.1 thorpej (REGVAL(CIA_CSR_CIA_CNFG) & CIA_CNFG_IOA_BWEN);
177 1.21.4.1 thorpej
178 1.6 cgd ccp->cc_hae_mem = REGVAL(CIA_CSR_HAE_MEM);
179 1.6 cgd ccp->cc_hae_io = REGVAL(CIA_CSR_HAE_IO);
180 1.12 cgd
181 1.14 cgd if (!ccp->cc_initted) {
182 1.14 cgd /* don't do these twice since they set up extents */
183 1.21.4.1 thorpej ccp->cc_iot = cia_swiz_bus_io_init(ccp);
184 1.21.4.1 thorpej ccp->cc_memt = cia_swiz_bus_mem_init(ccp);
185 1.21.4.1 thorpej cia_swiz_pci_init(&ccp->cc_pc, ccp); /* no ext. yet */
186 1.14 cgd }
187 1.14 cgd ccp->cc_mallocsafe = mallocsafe;
188 1.14 cgd
189 1.21 thorpej cia_dma_init(ccp);
190 1.14 cgd
191 1.14 cgd ccp->cc_initted = 1;
192 1.1 cgd }
193 1.1 cgd
194 1.1 cgd void
195 1.1 cgd ciaattach(parent, self, aux)
196 1.1 cgd struct device *parent, *self;
197 1.1 cgd void *aux;
198 1.1 cgd {
199 1.1 cgd struct cia_softc *sc = (struct cia_softc *)self;
200 1.1 cgd struct cia_config *ccp;
201 1.5 cgd struct pcibus_attach_args pba;
202 1.1 cgd
203 1.1 cgd /* note that we've attached the chipset; can't have 2 CIAs. */
204 1.1 cgd ciafound = 1;
205 1.1 cgd
206 1.1 cgd /*
207 1.1 cgd * set up the chipset's info; done once at console init time
208 1.21 thorpej * (maybe), but we must do it here as well to take care of things
209 1.21 thorpej * that need to use memory allocation.
210 1.1 cgd */
211 1.1 cgd ccp = sc->sc_ccp = &cia_configuration;
212 1.14 cgd cia_init(ccp, 1);
213 1.1 cgd
214 1.21.4.1 thorpej printf(": CIA pass %d (%s)", ccp->cc_pass,
215 1.21.4.1 thorpej ccp->cc_is21172 ? "21172" : "21171");
216 1.21.4.1 thorpej if (ccp->cc_is21172)
217 1.21.4.1 thorpej printf(", BWX %sabled", ccp->cc_bwx_enabled ? "en" : "dis");
218 1.21.4.1 thorpej printf("\n");
219 1.1 cgd
220 1.1 cgd switch (hwrpb->rpb_type) {
221 1.17 cgd #ifdef DEC_KN20AA
222 1.1 cgd case ST_DEC_KN20AA:
223 1.5 cgd pci_kn20aa_pickintr(ccp);
224 1.1 cgd #ifdef EVCNT_COUNTERS
225 1.1 cgd evcnt_attach(self, "intr", &kn20aa_intr_evcnt);
226 1.1 cgd #endif
227 1.1 cgd break;
228 1.1 cgd #endif
229 1.13 cgd
230 1.17 cgd #ifdef DEC_EB164
231 1.13 cgd case ST_EB164:
232 1.13 cgd pci_eb164_pickintr(ccp);
233 1.13 cgd #ifdef EVCNT_COUNTERS
234 1.13 cgd evcnt_attach(self, "intr", &eb164_intr_evcnt);
235 1.13 cgd #endif
236 1.13 cgd break;
237 1.13 cgd #endif
238 1.13 cgd
239 1.1 cgd default:
240 1.1 cgd panic("ciaattach: shouldn't be here, really...");
241 1.1 cgd }
242 1.1 cgd
243 1.5 cgd pba.pba_busname = "pci";
244 1.12 cgd pba.pba_iot = ccp->cc_iot;
245 1.12 cgd pba.pba_memt = ccp->cc_memt;
246 1.21 thorpej pba.pba_dmat = &ccp->cc_dmat_direct;
247 1.5 cgd pba.pba_pc = &ccp->cc_pc;
248 1.5 cgd pba.pba_bus = 0;
249 1.20 cgd pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED;
250 1.5 cgd config_found(self, &pba, ciaprint);
251 1.1 cgd }
252 1.1 cgd
253 1.1 cgd static int
254 1.1 cgd ciaprint(aux, pnp)
255 1.1 cgd void *aux;
256 1.9 cgd const char *pnp;
257 1.1 cgd {
258 1.5 cgd register struct pcibus_attach_args *pba = aux;
259 1.1 cgd
260 1.1 cgd /* only PCIs can attach to CIAs; easy. */
261 1.1 cgd if (pnp)
262 1.11 christos printf("%s at %s", pba->pba_busname, pnp);
263 1.11 christos printf(" bus %d", pba->pba_bus);
264 1.1 cgd return (UNCONF);
265 1.1 cgd }
266