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