apecs_pci.c revision 1.21 1 /* $NetBSD: apecs_pci.c,v 1.21 2009/03/14 15:35:59 dsl 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: apecs_pci.c,v 1.21 2009/03/14 15:35:59 dsl Exp $");
33
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/kernel.h>
37 #include <sys/device.h>
38
39 #include <uvm/uvm_extern.h>
40
41 #include <dev/pci/pcireg.h>
42 #include <dev/pci/pcivar.h>
43 #include <alpha/pci/apecsreg.h>
44 #include <alpha/pci/apecsvar.h>
45
46 void apecs_attach_hook(struct device *, struct device *,
47 struct pcibus_attach_args *);
48 int apecs_bus_maxdevs(void *, int);
49 pcitag_t apecs_make_tag(void *, int, int, int);
50 void apecs_decompose_tag(void *, pcitag_t, int *, int *,
51 int *);
52 pcireg_t apecs_conf_read(void *, pcitag_t, int);
53 void apecs_conf_write(void *, pcitag_t, int, pcireg_t);
54
55 void
56 apecs_pci_init(pci_chipset_tag_t pc, void *v)
57 {
58
59 pc->pc_conf_v = v;
60 pc->pc_attach_hook = apecs_attach_hook;
61 pc->pc_bus_maxdevs = apecs_bus_maxdevs;
62 pc->pc_make_tag = apecs_make_tag;
63 pc->pc_decompose_tag = apecs_decompose_tag;
64 pc->pc_conf_read = apecs_conf_read;
65 pc->pc_conf_write = apecs_conf_write;
66 }
67
68 void
69 apecs_attach_hook(parent, self, pba)
70 struct device *parent, *self;
71 struct pcibus_attach_args *pba;
72 {
73 }
74
75 int
76 apecs_bus_maxdevs(void *cpv, int busno)
77 {
78
79 return 32;
80 }
81
82 pcitag_t
83 apecs_make_tag(cpv, b, d, f)
84 void *cpv;
85 int b, d, f;
86 {
87
88 return (b << 16) | (d << 11) | (f << 8);
89 }
90
91 void
92 apecs_decompose_tag(cpv, tag, bp, dp, fp)
93 void *cpv;
94 pcitag_t tag;
95 int *bp, *dp, *fp;
96 {
97
98 if (bp != NULL)
99 *bp = (tag >> 16) & 0xff;
100 if (dp != NULL)
101 *dp = (tag >> 11) & 0x1f;
102 if (fp != NULL)
103 *fp = (tag >> 8) & 0x7;
104 }
105
106 pcireg_t
107 apecs_conf_read(void *cpv, pcitag_t tag, int offset)
108 {
109 struct apecs_config *acp = cpv;
110 pcireg_t *datap, data;
111 int s, secondary, ba;
112 int32_t old_haxr2; /* XXX */
113
114 s = 0; /* XXX gcc -Wuninitialized */
115 old_haxr2 = 0; /* XXX gcc -Wuninitialized */
116
117 /* secondary if bus # != 0 */
118 pci_decompose_tag(&acp->ac_pc, tag, &secondary, 0, 0);
119 if (secondary) {
120 s = splhigh();
121 old_haxr2 = REGVAL(EPIC_HAXR2);
122 alpha_mb();
123 REGVAL(EPIC_HAXR2) = old_haxr2 | 0x1;
124 alpha_mb();
125 }
126
127 datap = (pcireg_t *)ALPHA_PHYS_TO_K0SEG(APECS_PCI_CONF |
128 tag << 5UL | /* XXX */
129 (offset & ~0x03) << 5 | /* XXX */
130 0 << 5 | /* XXX */
131 0x3 << 3); /* XXX */
132 data = (pcireg_t)-1;
133 if (!(ba = badaddr(datap, sizeof *datap)))
134 data = *datap;
135
136 if (secondary) {
137 alpha_mb();
138 REGVAL(EPIC_HAXR2) = old_haxr2;
139 alpha_mb();
140 splx(s);
141 }
142
143 #if 0
144 printf("apecs_conf_read: tag 0x%lx, reg 0x%lx -> %x @ %p%s\n", tag, reg,
145 data, datap, ba ? " (badaddr)" : "");
146 #endif
147
148 return data;
149 }
150
151 void
152 apecs_conf_write(void *cpv, pcitag_t tag, int offset, pcireg_t data)
153 {
154 struct apecs_config *acp = cpv;
155 pcireg_t *datap;
156 int s, secondary;
157 int32_t old_haxr2; /* XXX */
158
159 s = 0; /* XXX gcc -Wuninitialized */
160 old_haxr2 = 0; /* XXX gcc -Wuninitialized */
161
162 /* secondary if bus # != 0 */
163 pci_decompose_tag(&acp->ac_pc, tag, &secondary, 0, 0);
164 if (secondary) {
165 s = splhigh();
166 old_haxr2 = REGVAL(EPIC_HAXR2);
167 alpha_mb();
168 REGVAL(EPIC_HAXR2) = old_haxr2 | 0x1;
169 alpha_mb();
170 }
171
172 datap = (pcireg_t *)ALPHA_PHYS_TO_K0SEG(APECS_PCI_CONF |
173 tag << 5UL | /* XXX */
174 (offset & ~0x03) << 5 | /* XXX */
175 0 << 5 | /* XXX */
176 0x3 << 3); /* XXX */
177
178 alpha_mb();
179 *datap = data;
180 alpha_mb();
181 alpha_mb();
182
183 if (secondary) {
184 alpha_mb();
185 REGVAL(EPIC_HAXR2) = old_haxr2;
186 alpha_mb();
187 splx(s);
188 }
189
190 #if 0
191 printf("apecs_conf_write: tag 0x%lx, reg 0x%lx -> 0x%x @ %p\n", tag,
192 reg, data, datap);
193 #endif
194 }
195