Sync usage with man page.
[netbsd-mini2440.git] / sys / arch / alpha / pci / cia_pci.c
blob9f1b099e22944bc23a0e3929833512f627688d23
1 /* $NetBSD: cia_pci.c,v 1.28 2009/03/14 15:35:59 dsl Exp $ */
3 /*
4 * Copyright (c) 1995, 1996 Carnegie-Mellon University.
5 * All rights reserved.
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.
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.
19 * Carnegie Mellon requests users of this software to return to
21 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
22 * School of Computer Science
23 * Carnegie Mellon University
24 * Pittsburgh PA 15213-3890
26 * any improvements or extensions that they make and grant Carnegie the
27 * rights to redistribute these changes.
30 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
32 __KERNEL_RCSID(0, "$NetBSD: cia_pci.c,v 1.28 2009/03/14 15:35:59 dsl Exp $");
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/kernel.h>
37 #include <sys/device.h>
39 #include <uvm/uvm_extern.h>
41 #include <dev/pci/pcireg.h>
42 #include <dev/pci/pcivar.h>
43 #include <alpha/pci/ciareg.h>
44 #include <alpha/pci/ciavar.h>
46 void cia_attach_hook(struct device *, struct device *,
47 struct pcibus_attach_args *);
48 int cia_bus_maxdevs(void *, int);
49 pcitag_t cia_make_tag(void *, int, int, int);
50 void cia_decompose_tag(void *, pcitag_t, int *, int *,
51 int *);
52 pcireg_t cia_conf_read(void *, pcitag_t, int);
53 void cia_conf_write(void *, pcitag_t, int, pcireg_t);
55 void
56 cia_pci_init(pci_chipset_tag_t pc, void *v)
59 pc->pc_conf_v = v;
60 pc->pc_attach_hook = cia_attach_hook;
61 pc->pc_bus_maxdevs = cia_bus_maxdevs;
62 pc->pc_make_tag = cia_make_tag;
63 pc->pc_decompose_tag = cia_decompose_tag;
64 pc->pc_conf_read = cia_conf_read;
65 pc->pc_conf_write = cia_conf_write;
68 void
69 cia_attach_hook(struct device *parent, struct device *self, struct pcibus_attach_args *pba)
73 int
74 cia_bus_maxdevs(void *cpv, int busno)
77 return 32;
80 pcitag_t
81 cia_make_tag(void *cpv, int b, int d, int f)
84 return (b << 16) | (d << 11) | (f << 8);
87 void
88 cia_decompose_tag(void *cpv, pcitag_t tag, int *bp, int *dp, int *fp)
91 if (bp != NULL)
92 *bp = (tag >> 16) & 0xff;
93 if (dp != NULL)
94 *dp = (tag >> 11) & 0x1f;
95 if (fp != NULL)
96 *fp = (tag >> 8) & 0x7;
99 pcireg_t
100 cia_conf_read(void *cpv, pcitag_t tag, int offset)
102 struct cia_config *ccp = cpv;
103 pcireg_t *datap, data;
104 int s, secondary, ba;
105 u_int32_t old_cfg, errbits;
107 #ifdef __GNUC__
108 s = 0; /* XXX gcc -Wuninitialized */
109 old_cfg = 0; /* XXX gcc -Wuninitialized */
110 #endif
113 * Some (apparently-common) revisions of EB164 and AlphaStation
114 * firmware do the Wrong thing with PCI master and target aborts,
115 * which are caused by accesing the configuration space of devices
116 * that don't exist (for example).
118 * To work around this, we clear the CIA error register's PCI
119 * master and target abort bits before touching PCI configuration
120 * space and check it afterwards. If it indicates a master or target
121 * abort, the device wasn't there so we return 0xffffffff.
123 REGVAL(CIA_CSR_CIA_ERR) = CIA_ERR_RCVD_MAS_ABT|CIA_ERR_RCVD_TAR_ABT;
124 alpha_mb();
125 alpha_pal_draina();
127 /* secondary if bus # != 0 */
128 pci_decompose_tag(&ccp->cc_pc, tag, &secondary, 0, 0);
129 if (secondary) {
130 s = splhigh();
131 old_cfg = REGVAL(CIA_CSR_CFG);
132 alpha_mb();
133 REGVAL(CIA_CSR_CFG) = old_cfg | 0x1;
134 alpha_mb();
138 * We just inline the BWX support, since this is the only
139 * difference between BWX and swiz for config space.
141 if (ccp->cc_flags & CCF_PCI_USE_BWX) {
142 if (secondary) {
143 datap =
144 (pcireg_t *)ALPHA_PHYS_TO_K0SEG(CIA_EV56_BWCONF1 |
145 tag | (offset & ~0x03));
146 } else {
147 datap =
148 (pcireg_t *)ALPHA_PHYS_TO_K0SEG(CIA_EV56_BWCONF0 |
149 tag | (offset & ~0x03));
151 } else {
152 datap = (pcireg_t *)ALPHA_PHYS_TO_K0SEG(CIA_PCI_CONF |
153 tag << 5UL | /* XXX */
154 (offset & ~0x03) << 5 | /* XXX */
155 0 << 5 | /* XXX */
156 0x3 << 3); /* XXX */
158 data = (pcireg_t)-1;
159 alpha_mb();
160 if (!(ba = badaddr(datap, sizeof *datap)))
161 data = *datap;
162 alpha_mb();
163 alpha_mb();
165 if (secondary) {
166 alpha_mb();
167 REGVAL(CIA_CSR_CFG) = old_cfg;
168 alpha_mb();
169 splx(s);
172 alpha_pal_draina();
173 alpha_mb();
174 errbits = REGVAL(CIA_CSR_CIA_ERR);
175 if (errbits & (CIA_ERR_RCVD_MAS_ABT|CIA_ERR_RCVD_TAR_ABT)) {
176 ba = 1;
177 data = 0xffffffff;
180 if (errbits) {
181 REGVAL(CIA_CSR_CIA_ERR) = errbits;
182 alpha_mb();
183 alpha_pal_draina();
186 #if 0
187 printf("cia_conf_read: tag 0x%lx, reg 0x%lx -> %x @ %p%s\n", tag, reg,
188 data, datap, ba ? " (badaddr)" : "");
189 #endif
191 return data;
194 void
195 cia_conf_write(void *cpv, pcitag_t tag, int offset, pcireg_t data)
197 struct cia_config *ccp = cpv;
198 pcireg_t *datap;
199 int s, secondary;
200 u_int32_t old_cfg;
202 #ifdef __GNUC__
203 s = 0; /* XXX gcc -Wuninitialized */
204 old_cfg = 0; /* XXX gcc -Wuninitialized */
205 #endif
207 /* secondary if bus # != 0 */
208 pci_decompose_tag(&ccp->cc_pc, tag, &secondary, 0, 0);
209 if (secondary) {
210 s = splhigh();
211 old_cfg = REGVAL(CIA_CSR_CFG);
212 alpha_mb();
213 REGVAL(CIA_CSR_CFG) = old_cfg | 0x1;
214 alpha_mb();
218 * We just inline the BWX support, since this is the only
219 * difference between BWX and swiz for config space.
221 if (ccp->cc_flags & CCF_PCI_USE_BWX) {
222 if (secondary) {
223 datap =
224 (pcireg_t *)ALPHA_PHYS_TO_K0SEG(CIA_EV56_BWCONF1 |
225 tag | (offset & ~0x03));
226 } else {
227 datap =
228 (pcireg_t *)ALPHA_PHYS_TO_K0SEG(CIA_EV56_BWCONF0 |
229 tag | (offset & ~0x03));
231 } else {
232 datap = (pcireg_t *)ALPHA_PHYS_TO_K0SEG(CIA_PCI_CONF |
233 tag << 5UL | /* XXX */
234 (offset & ~0x03) << 5 | /* XXX */
235 0 << 5 | /* XXX */
236 0x3 << 3); /* XXX */
238 alpha_mb();
239 *datap = data;
240 alpha_mb();
241 alpha_mb();
243 if (secondary) {
244 alpha_mb();
245 REGVAL(CIA_CSR_CFG) = old_cfg;
246 alpha_mb();
247 splx(s);
250 #if 0
251 printf("cia_conf_write: tag 0x%lx, reg 0x%lx -> 0x%x @ %p\n", tag,
252 reg, data, datap);
253 #endif