cia_pci.c revision 1.13 1 /* $NetBSD: cia_pci.c,v 1.13 1997/09/02 20:05:28 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 1995, 1996 Carnegie-Mellon University.
5 * All rights reserved.
6 *
7 * Author: Chris G. Demetriou
8 *
9 * Permission to use, copy, modify and distribute this software and
10 * its documentation is hereby granted, provided that both the copyright
11 * notice and this permission notice appear in all copies of the
12 * software, derivative works or modified versions, and any portions
13 * thereof, and that both notices appear in supporting documentation.
14 *
15 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
17 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 *
19 * Carnegie Mellon requests users of this software to return to
20 *
21 * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
22 * School of Computer Science
23 * Carnegie Mellon University
24 * Pittsburgh PA 15213-3890
25 *
26 * any improvements or extensions that they make and grant Carnegie the
27 * rights to redistribute these changes.
28 */
29
30 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
31
32 __KERNEL_RCSID(0, "$NetBSD: cia_pci.c,v 1.13 1997/09/02 20:05:28 thorpej Exp $");
33
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/kernel.h>
37 #include <sys/device.h>
38 #include <vm/vm.h>
39
40 #include <dev/pci/pcireg.h>
41 #include <dev/pci/pcivar.h>
42 #include <alpha/pci/ciareg.h>
43 #include <alpha/pci/ciavar.h>
44
45 #include <machine/rpb.h> /* XXX for eb164 CIA firmware workarounds. */
46
47 void cia_attach_hook __P((struct device *, struct device *,
48 struct pcibus_attach_args *));
49 int cia_bus_maxdevs __P((void *, int));
50 pcitag_t cia_make_tag __P((void *, int, int, int));
51 void cia_decompose_tag __P((void *, pcitag_t, int *, int *,
52 int *));
53 pcireg_t cia_conf_read __P((void *, pcitag_t, int));
54 void cia_conf_write __P((void *, pcitag_t, int, pcireg_t));
55
56 void
57 cia_pci_init(pc, v)
58 pci_chipset_tag_t pc;
59 void *v;
60 {
61
62 pc->pc_conf_v = v;
63 pc->pc_attach_hook = cia_attach_hook;
64 pc->pc_bus_maxdevs = cia_bus_maxdevs;
65 pc->pc_make_tag = cia_make_tag;
66 pc->pc_decompose_tag = cia_decompose_tag;
67 pc->pc_conf_read = cia_conf_read;
68 pc->pc_conf_write = cia_conf_write;
69 }
70
71 void
72 cia_attach_hook(parent, self, pba)
73 struct device *parent, *self;
74 struct pcibus_attach_args *pba;
75 {
76 }
77
78 int
79 cia_bus_maxdevs(cpv, busno)
80 void *cpv;
81 int busno;
82 {
83
84 return 32;
85 }
86
87 pcitag_t
88 cia_make_tag(cpv, b, d, f)
89 void *cpv;
90 int b, d, f;
91 {
92
93 return (b << 16) | (d << 11) | (f << 8);
94 }
95
96 void
97 cia_decompose_tag(cpv, tag, bp, dp, fp)
98 void *cpv;
99 pcitag_t tag;
100 int *bp, *dp, *fp;
101 {
102
103 if (bp != NULL)
104 *bp = (tag >> 16) & 0xff;
105 if (dp != NULL)
106 *dp = (tag >> 11) & 0x1f;
107 if (fp != NULL)
108 *fp = (tag >> 8) & 0x7;
109 }
110
111 pcireg_t
112 cia_conf_read(cpv, tag, offset)
113 void *cpv;
114 pcitag_t tag;
115 int offset;
116 {
117 struct cia_config *ccp = cpv;
118 pcireg_t *datap, data;
119 int s, secondary, ba;
120 int32_t old_haxr2; /* XXX */
121 #ifdef DEC_EB164
122 extern int cputype; /* XXX */
123 #endif
124
125 #ifdef DIAGNOSTIC
126 s = 0; /* XXX gcc -Wuninitialized */
127 old_haxr2 = 0; /* XXX gcc -Wuninitialized */
128 #endif
129
130 #ifdef DEC_EB164
131 /*
132 * Some (apparently-common) revisions of EB164 firmware do the
133 * Wrong thing with PCI master aborts, which are caused by
134 * accesing the configuration space of devices that don't
135 * exist (for example).
136 *
137 * On EB164's we clear the CIA error register's PCI master
138 * abort bit before touching PCI configuration space and
139 * check it afterwards. If it indicates a master abort,
140 * the device wasn't there so we return 0xffffffff.
141 */
142 if (cputype == ST_EB164) {
143 /* clear the PCI master abort bit in CIA error register */
144 REGVAL(CIA_CSR_CIA_ERR) = 0x00000080; /* XXX */
145 alpha_mb();
146 alpha_pal_draina();
147 }
148 #endif
149
150 /* secondary if bus # != 0 */
151 alpha_pci_decompose_tag(&ccp->cc_pc, tag, &secondary, 0, 0);
152 if (secondary) {
153 s = splhigh();
154 old_haxr2 = REGVAL(CIA_CSRS + 0x480); /* XXX */
155 alpha_mb();
156 REGVAL(CIA_CSRS + 0x480) = old_haxr2 | 0x1; /* XXX */
157 alpha_mb();
158 }
159
160 datap = (pcireg_t *)ALPHA_PHYS_TO_K0SEG(CIA_PCI_CONF |
161 tag << 5UL | /* XXX */
162 (offset & ~0x03) << 5 | /* XXX */
163 0 << 5 | /* XXX */
164 0x3 << 3); /* XXX */
165 data = (pcireg_t)-1;
166 if (!(ba = badaddr(datap, sizeof *datap)))
167 data = *datap;
168
169 if (secondary) {
170 alpha_mb();
171 REGVAL(CIA_CSRS + 0x480) = old_haxr2; /* XXX */
172 alpha_mb();
173 splx(s);
174 }
175
176 #ifdef DEC_EB164
177 if (cputype == ST_EB164) {
178 alpha_pal_draina();
179 /* check CIA error register for PCI master abort */
180 if (REGVAL(CIA_CSR_CIA_ERR) & 0x00000080) { /* XXX */
181 ba = 1;
182 data = 0xffffffff;
183 }
184 }
185 #endif
186
187 #if 0
188 printf("cia_conf_read: tag 0x%lx, reg 0x%lx -> %x @ %p%s\n", tag, reg,
189 data, datap, ba ? " (badaddr)" : "");
190 #endif
191
192 return data;
193 }
194
195 void
196 cia_conf_write(cpv, tag, offset, data)
197 void *cpv;
198 pcitag_t tag;
199 int offset;
200 pcireg_t data;
201 {
202 struct cia_config *ccp = cpv;
203 pcireg_t *datap;
204 int s, secondary;
205 int32_t old_haxr2; /* XXX */
206
207 #ifdef DIAGNOSTIC
208 s = 0; /* XXX gcc -Wuninitialized */
209 old_haxr2 = 0; /* XXX gcc -Wuninitialized */
210 #endif
211
212 /* secondary if bus # != 0 */
213 alpha_pci_decompose_tag(&ccp->cc_pc, tag, &secondary, 0, 0);
214 if (secondary) {
215 s = splhigh();
216 old_haxr2 = REGVAL(CIA_CSRS + 0x480); /* XXX */
217 alpha_mb();
218 REGVAL(CIA_CSRS + 0x480) = old_haxr2 | 0x1; /* XXX */
219 alpha_mb();
220 }
221
222 datap = (pcireg_t *)ALPHA_PHYS_TO_K0SEG(CIA_PCI_CONF |
223 tag << 5UL | /* XXX */
224 (offset & ~0x03) << 5 | /* XXX */
225 0 << 5 | /* XXX */
226 0x3 << 3); /* XXX */
227 *datap = data;
228
229 if (secondary) {
230 alpha_mb();
231 REGVAL(CIA_CSRS + 0x480) = old_haxr2; /* XXX */
232 alpha_mb();
233 splx(s);
234 }
235
236 #if 0
237 printf("cia_conf_write: tag 0x%lx, reg 0x%lx -> 0x%x @ %p\n", tag,
238 reg, data, datap);
239 #endif
240 }
241