cia_pci.c revision 1.7 1 1.7 cgd /* $NetBSD: cia_pci.c,v 1.7 1996/11/23 06:46:50 cgd Exp $ */
2 1.1 cgd
3 1.1 cgd /*
4 1.2 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.1 cgd
30 1.1 cgd #include <sys/param.h>
31 1.1 cgd #include <sys/systm.h>
32 1.1 cgd #include <sys/kernel.h>
33 1.1 cgd #include <sys/device.h>
34 1.1 cgd #include <vm/vm.h>
35 1.1 cgd
36 1.1 cgd #include <dev/pci/pcireg.h>
37 1.1 cgd #include <dev/pci/pcivar.h>
38 1.1 cgd #include <alpha/pci/ciareg.h>
39 1.1 cgd #include <alpha/pci/ciavar.h>
40 1.1 cgd
41 1.7 cgd #include <machine/rpb.h> /* XXX for eb164 CIA firmware workarounds. */
42 1.7 cgd #include "dec_eb164.h" /* XXX for eb164 CIA firmware workarounds. */
43 1.7 cgd
44 1.2 cgd void cia_attach_hook __P((struct device *, struct device *,
45 1.2 cgd struct pcibus_attach_args *));
46 1.2 cgd int cia_bus_maxdevs __P((void *, int));
47 1.2 cgd pcitag_t cia_make_tag __P((void *, int, int, int));
48 1.2 cgd void cia_decompose_tag __P((void *, pcitag_t, int *, int *,
49 1.2 cgd int *));
50 1.2 cgd pcireg_t cia_conf_read __P((void *, pcitag_t, int));
51 1.2 cgd void cia_conf_write __P((void *, pcitag_t, int, pcireg_t));
52 1.1 cgd
53 1.2 cgd void
54 1.2 cgd cia_pci_init(pc, v)
55 1.2 cgd pci_chipset_tag_t pc;
56 1.2 cgd void *v;
57 1.2 cgd {
58 1.2 cgd
59 1.2 cgd pc->pc_conf_v = v;
60 1.2 cgd pc->pc_attach_hook = cia_attach_hook;
61 1.2 cgd pc->pc_bus_maxdevs = cia_bus_maxdevs;
62 1.2 cgd pc->pc_make_tag = cia_make_tag;
63 1.2 cgd pc->pc_decompose_tag = cia_decompose_tag;
64 1.2 cgd pc->pc_conf_read = cia_conf_read;
65 1.2 cgd pc->pc_conf_write = cia_conf_write;
66 1.2 cgd }
67 1.2 cgd
68 1.2 cgd void
69 1.2 cgd cia_attach_hook(parent, self, pba)
70 1.2 cgd struct device *parent, *self;
71 1.2 cgd struct pcibus_attach_args *pba;
72 1.2 cgd {
73 1.2 cgd }
74 1.2 cgd
75 1.2 cgd int
76 1.2 cgd cia_bus_maxdevs(cpv, busno)
77 1.2 cgd void *cpv;
78 1.2 cgd int busno;
79 1.2 cgd {
80 1.2 cgd
81 1.2 cgd return 32;
82 1.2 cgd }
83 1.2 cgd
84 1.2 cgd pcitag_t
85 1.2 cgd cia_make_tag(cpv, b, d, f)
86 1.2 cgd void *cpv;
87 1.2 cgd int b, d, f;
88 1.2 cgd {
89 1.2 cgd
90 1.2 cgd return (b << 16) | (d << 11) | (f << 8);
91 1.2 cgd }
92 1.2 cgd
93 1.2 cgd void
94 1.2 cgd cia_decompose_tag(cpv, tag, bp, dp, fp)
95 1.2 cgd void *cpv;
96 1.2 cgd pcitag_t tag;
97 1.2 cgd int *bp, *dp, *fp;
98 1.2 cgd {
99 1.2 cgd
100 1.2 cgd if (bp != NULL)
101 1.2 cgd *bp = (tag >> 16) & 0xff;
102 1.2 cgd if (dp != NULL)
103 1.2 cgd *dp = (tag >> 11) & 0x1f;
104 1.2 cgd if (fp != NULL)
105 1.2 cgd *fp = (tag >> 8) & 0x7;
106 1.2 cgd }
107 1.2 cgd
108 1.2 cgd pcireg_t
109 1.1 cgd cia_conf_read(cpv, tag, offset)
110 1.1 cgd void *cpv;
111 1.2 cgd pcitag_t tag;
112 1.2 cgd int offset;
113 1.1 cgd {
114 1.2 cgd struct cia_config *ccp = cpv;
115 1.2 cgd pcireg_t *datap, data;
116 1.1 cgd int s, secondary, ba;
117 1.1 cgd int32_t old_haxr2; /* XXX */
118 1.7 cgd #if NDEC_EB164
119 1.7 cgd extern int cputype; /* XXX */
120 1.7 cgd #endif
121 1.1 cgd
122 1.6 cgd #ifdef DIAGNOSTIC
123 1.6 cgd s = 0; /* XXX gcc -Wuninitialized */
124 1.6 cgd old_haxr2 = 0; /* XXX gcc -Wuninitialized */
125 1.6 cgd #endif
126 1.6 cgd
127 1.7 cgd #if NDEC_EB164
128 1.7 cgd /*
129 1.7 cgd * Some (apparently-common) revisions of EB164 firmware do the
130 1.7 cgd * Wrong thing with PCI master aborts, which are caused by
131 1.7 cgd * accesing the configuration space of devices that don't
132 1.7 cgd * exist (for example).
133 1.7 cgd *
134 1.7 cgd * On EB164's we clear the CIA error register's PCI master
135 1.7 cgd * abort bit before touching PCI configuration space and
136 1.7 cgd * check it afterwards. If it indicates a master abort,
137 1.7 cgd * the device wasn't there so we return 0xffffffff.
138 1.7 cgd */
139 1.7 cgd if (cputype == ST_EB164) {
140 1.7 cgd /* clear the PCI master abort bit in CIA error register */
141 1.7 cgd REGVAL(CIA_CSR_CIA_ERR) = 0x00000080; /* XXX */
142 1.7 cgd alpha_mb();
143 1.7 cgd alpha_pal_draina();
144 1.7 cgd }
145 1.7 cgd #endif
146 1.7 cgd
147 1.2 cgd /* secondary if bus # != 0 */
148 1.2 cgd pci_decompose_tag(&ccp->cc_pc, tag, &secondary, 0, 0);
149 1.1 cgd if (secondary) {
150 1.1 cgd s = splhigh();
151 1.1 cgd old_haxr2 = REGVAL(CIA_CSRS + 0x480); /* XXX */
152 1.3 cgd alpha_mb();
153 1.1 cgd REGVAL(CIA_CSRS + 0x480) = old_haxr2 | 0x1; /* XXX */
154 1.3 cgd alpha_mb();
155 1.1 cgd }
156 1.1 cgd
157 1.3 cgd datap = (pcireg_t *)ALPHA_PHYS_TO_K0SEG(CIA_PCI_CONF |
158 1.1 cgd tag << 5UL | /* XXX */
159 1.1 cgd (offset & ~0x03) << 5 | /* XXX */
160 1.1 cgd 0 << 5 | /* XXX */
161 1.1 cgd 0x3 << 3); /* XXX */
162 1.2 cgd data = (pcireg_t)-1;
163 1.1 cgd if (!(ba = badaddr(datap, sizeof *datap)))
164 1.1 cgd data = *datap;
165 1.1 cgd
166 1.1 cgd if (secondary) {
167 1.3 cgd alpha_mb();
168 1.1 cgd REGVAL(CIA_CSRS + 0x480) = old_haxr2; /* XXX */
169 1.3 cgd alpha_mb();
170 1.1 cgd splx(s);
171 1.1 cgd }
172 1.7 cgd
173 1.7 cgd #if NDEC_EB164
174 1.7 cgd if (cputype == ST_EB164) {
175 1.7 cgd alpha_pal_draina();
176 1.7 cgd /* check CIA error register for PCI master abort */
177 1.7 cgd if (REGVAL(CIA_CSR_CIA_ERR) & 0x00000080) { /* XXX */
178 1.7 cgd ba = 1;
179 1.7 cgd data = 0xffffffff;
180 1.7 cgd }
181 1.7 cgd }
182 1.7 cgd #endif
183 1.1 cgd
184 1.1 cgd #if 0
185 1.5 christos printf("cia_conf_read: tag 0x%lx, reg 0x%lx -> %x @ %p%s\n", tag, reg,
186 1.1 cgd data, datap, ba ? " (badaddr)" : "");
187 1.1 cgd #endif
188 1.1 cgd
189 1.1 cgd return data;
190 1.1 cgd }
191 1.1 cgd
192 1.1 cgd void
193 1.1 cgd cia_conf_write(cpv, tag, offset, data)
194 1.1 cgd void *cpv;
195 1.2 cgd pcitag_t tag;
196 1.2 cgd int offset;
197 1.2 cgd pcireg_t data;
198 1.1 cgd {
199 1.2 cgd struct cia_config *ccp = cpv;
200 1.2 cgd pcireg_t *datap;
201 1.1 cgd int s, secondary;
202 1.1 cgd int32_t old_haxr2; /* XXX */
203 1.6 cgd
204 1.6 cgd #ifdef DIAGNOSTIC
205 1.6 cgd s = 0; /* XXX gcc -Wuninitialized */
206 1.6 cgd old_haxr2 = 0; /* XXX gcc -Wuninitialized */
207 1.6 cgd #endif
208 1.1 cgd
209 1.2 cgd /* secondary if bus # != 0 */
210 1.2 cgd pci_decompose_tag(&ccp->cc_pc, tag, &secondary, 0, 0);
211 1.1 cgd if (secondary) {
212 1.1 cgd s = splhigh();
213 1.1 cgd old_haxr2 = REGVAL(CIA_CSRS + 0x480); /* XXX */
214 1.3 cgd alpha_mb();
215 1.1 cgd REGVAL(CIA_CSRS + 0x480) = old_haxr2 | 0x1; /* XXX */
216 1.3 cgd alpha_mb();
217 1.1 cgd }
218 1.1 cgd
219 1.3 cgd datap = (pcireg_t *)ALPHA_PHYS_TO_K0SEG(CIA_PCI_CONF |
220 1.1 cgd tag << 5UL | /* XXX */
221 1.1 cgd (offset & ~0x03) << 5 | /* XXX */
222 1.1 cgd 0 << 5 | /* XXX */
223 1.1 cgd 0x3 << 3); /* XXX */
224 1.1 cgd *datap = data;
225 1.1 cgd
226 1.1 cgd if (secondary) {
227 1.3 cgd alpha_mb();
228 1.1 cgd REGVAL(CIA_CSRS + 0x480) = old_haxr2; /* XXX */
229 1.3 cgd alpha_mb();
230 1.1 cgd splx(s);
231 1.1 cgd }
232 1.1 cgd
233 1.1 cgd #if 0
234 1.5 christos printf("cia_conf_write: tag 0x%lx, reg 0x%lx -> 0x%x @ %p\n", tag,
235 1.1 cgd reg, data, datap);
236 1.1 cgd #endif
237 1.1 cgd }
238