1 /* $NetBSD: cia_pci.c,v 1.28 2009/03/14 15:35:59 dsl Exp $ */
4 * Copyright (c) 1995, 1996 Carnegie-Mellon University.
7 * Author: Chris G. Demetriou
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 *,
52 pcireg_t
cia_conf_read(void *, pcitag_t
, int);
53 void cia_conf_write(void *, pcitag_t
, int, pcireg_t
);
56 cia_pci_init(pci_chipset_tag_t pc
, void *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
;
69 cia_attach_hook(struct device
*parent
, struct device
*self
, struct pcibus_attach_args
*pba
)
74 cia_bus_maxdevs(void *cpv
, int busno
)
81 cia_make_tag(void *cpv
, int b
, int d
, int f
)
84 return (b
<< 16) | (d
<< 11) | (f
<< 8);
88 cia_decompose_tag(void *cpv
, pcitag_t tag
, int *bp
, int *dp
, int *fp
)
92 *bp
= (tag
>> 16) & 0xff;
94 *dp
= (tag
>> 11) & 0x1f;
96 *fp
= (tag
>> 8) & 0x7;
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
;
108 s
= 0; /* XXX gcc -Wuninitialized */
109 old_cfg
= 0; /* XXX gcc -Wuninitialized */
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
;
127 /* secondary if bus # != 0 */
128 pci_decompose_tag(&ccp
->cc_pc
, tag
, &secondary
, 0, 0);
131 old_cfg
= REGVAL(CIA_CSR_CFG
);
133 REGVAL(CIA_CSR_CFG
) = old_cfg
| 0x1;
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
) {
144 (pcireg_t
*)ALPHA_PHYS_TO_K0SEG(CIA_EV56_BWCONF1
|
145 tag
| (offset
& ~0x03));
148 (pcireg_t
*)ALPHA_PHYS_TO_K0SEG(CIA_EV56_BWCONF0
|
149 tag
| (offset
& ~0x03));
152 datap
= (pcireg_t
*)ALPHA_PHYS_TO_K0SEG(CIA_PCI_CONF
|
153 tag
<< 5UL | /* XXX */
154 (offset
& ~0x03) << 5 | /* XXX */
160 if (!(ba
= badaddr(datap
, sizeof *datap
)))
167 REGVAL(CIA_CSR_CFG
) = old_cfg
;
174 errbits
= REGVAL(CIA_CSR_CIA_ERR
);
175 if (errbits
& (CIA_ERR_RCVD_MAS_ABT
|CIA_ERR_RCVD_TAR_ABT
)) {
181 REGVAL(CIA_CSR_CIA_ERR
) = errbits
;
187 printf("cia_conf_read: tag 0x%lx, reg 0x%lx -> %x @ %p%s\n", tag
, reg
,
188 data
, datap
, ba
? " (badaddr)" : "");
195 cia_conf_write(void *cpv
, pcitag_t tag
, int offset
, pcireg_t data
)
197 struct cia_config
*ccp
= cpv
;
203 s
= 0; /* XXX gcc -Wuninitialized */
204 old_cfg
= 0; /* XXX gcc -Wuninitialized */
207 /* secondary if bus # != 0 */
208 pci_decompose_tag(&ccp
->cc_pc
, tag
, &secondary
, 0, 0);
211 old_cfg
= REGVAL(CIA_CSR_CFG
);
213 REGVAL(CIA_CSR_CFG
) = old_cfg
| 0x1;
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
) {
224 (pcireg_t
*)ALPHA_PHYS_TO_K0SEG(CIA_EV56_BWCONF1
|
225 tag
| (offset
& ~0x03));
228 (pcireg_t
*)ALPHA_PHYS_TO_K0SEG(CIA_EV56_BWCONF0
|
229 tag
| (offset
& ~0x03));
232 datap
= (pcireg_t
*)ALPHA_PHYS_TO_K0SEG(CIA_PCI_CONF
|
233 tag
<< 5UL | /* XXX */
234 (offset
& ~0x03) << 5 | /* XXX */
245 REGVAL(CIA_CSR_CFG
) = old_cfg
;
251 printf("cia_conf_write: tag 0x%lx, reg 0x%lx -> 0x%x @ %p\n", tag
,