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