amd756.c revision 1.1.4.2 1 1.1.4.2 bouyer /* $NetBSD: amd756.c,v 1.1.4.2 2001/04/23 09:41:50 bouyer Exp $ */
2 1.1.4.2 bouyer
3 1.1.4.2 bouyer /*-
4 1.1.4.2 bouyer * Copyright (c) 1999, 2001 The NetBSD Foundation, Inc.
5 1.1.4.2 bouyer * All rights reserved.
6 1.1.4.2 bouyer *
7 1.1.4.2 bouyer * This code is derived from software contributed to The NetBSD Foundation
8 1.1.4.2 bouyer * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 1.1.4.2 bouyer * NASA Ames Research Center.
10 1.1.4.2 bouyer *
11 1.1.4.2 bouyer * Redistribution and use in source and binary forms, with or without
12 1.1.4.2 bouyer * modification, are permitted provided that the following conditions
13 1.1.4.2 bouyer * are met:
14 1.1.4.2 bouyer * 1. Redistributions of source code must retain the above copyright
15 1.1.4.2 bouyer * notice, this list of conditions and the following disclaimer.
16 1.1.4.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
17 1.1.4.2 bouyer * notice, this list of conditions and the following disclaimer in the
18 1.1.4.2 bouyer * documentation and/or other materials provided with the distribution.
19 1.1.4.2 bouyer * 3. All advertising materials mentioning features or use of this software
20 1.1.4.2 bouyer * must display the following acknowledgement:
21 1.1.4.2 bouyer * This product includes software developed by the NetBSD
22 1.1.4.2 bouyer * Foundation, Inc. and its contributors.
23 1.1.4.2 bouyer * 4. Neither the name of The NetBSD Foundation nor the names of its
24 1.1.4.2 bouyer * contributors may be used to endorse or promote products derived
25 1.1.4.2 bouyer * from this software without specific prior written permission.
26 1.1.4.2 bouyer *
27 1.1.4.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 1.1.4.2 bouyer * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 1.1.4.2 bouyer * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 1.1.4.2 bouyer * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 1.1.4.2 bouyer * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 1.1.4.2 bouyer * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 1.1.4.2 bouyer * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 1.1.4.2 bouyer * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 1.1.4.2 bouyer * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 1.1.4.2 bouyer * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 1.1.4.2 bouyer * POSSIBILITY OF SUCH DAMAGE.
38 1.1.4.2 bouyer */
39 1.1.4.2 bouyer
40 1.1.4.2 bouyer /*
41 1.1.4.2 bouyer * Copyright (c) 1999, by UCHIYAMA Yasushi
42 1.1.4.2 bouyer * All rights reserved.
43 1.1.4.2 bouyer *
44 1.1.4.2 bouyer * Redistribution and use in source and binary forms, with or without
45 1.1.4.2 bouyer * modification, are permitted provided that the following conditions
46 1.1.4.2 bouyer * are met:
47 1.1.4.2 bouyer * 1. Redistributions of source code must retain the above copyright
48 1.1.4.2 bouyer * notice, this list of conditions and the following disclaimer.
49 1.1.4.2 bouyer * 2. The name of the developer may NOT be used to endorse or promote products
50 1.1.4.2 bouyer * derived from this software without specific prior written permission.
51 1.1.4.2 bouyer *
52 1.1.4.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
53 1.1.4.2 bouyer * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 1.1.4.2 bouyer * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55 1.1.4.2 bouyer * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
56 1.1.4.2 bouyer * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57 1.1.4.2 bouyer * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58 1.1.4.2 bouyer * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59 1.1.4.2 bouyer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60 1.1.4.2 bouyer * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61 1.1.4.2 bouyer * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62 1.1.4.2 bouyer * SUCH DAMAGE.
63 1.1.4.2 bouyer */
64 1.1.4.2 bouyer
65 1.1.4.2 bouyer /*
66 1.1.4.2 bouyer * Support for the Advanced Micro Devices AMD756 Peripheral Bus Controller.
67 1.1.4.2 bouyer */
68 1.1.4.2 bouyer
69 1.1.4.2 bouyer #include <sys/param.h>
70 1.1.4.2 bouyer #include <sys/systm.h>
71 1.1.4.2 bouyer #include <sys/device.h>
72 1.1.4.2 bouyer #include <sys/malloc.h>
73 1.1.4.2 bouyer
74 1.1.4.2 bouyer #include <machine/intr.h>
75 1.1.4.2 bouyer #include <machine/bus.h>
76 1.1.4.2 bouyer
77 1.1.4.2 bouyer #include <dev/pci/pcivar.h>
78 1.1.4.2 bouyer #include <dev/pci/pcireg.h>
79 1.1.4.2 bouyer #include <dev/pci/pcidevs.h>
80 1.1.4.2 bouyer
81 1.1.4.2 bouyer #include <i386/pci/pci_intr_fixup.h>
82 1.1.4.2 bouyer #include <i386/pci/amd756reg.h>
83 1.1.4.2 bouyer
84 1.1.4.2 bouyer struct amd756_handle {
85 1.1.4.2 bouyer bus_space_tag_t ph_iot;
86 1.1.4.2 bouyer bus_space_handle_t ph_regs_ioh;
87 1.1.4.2 bouyer pci_chipset_tag_t ph_pc;
88 1.1.4.2 bouyer pcitag_t ph_tag;
89 1.1.4.2 bouyer };
90 1.1.4.2 bouyer
91 1.1.4.2 bouyer int amd756_getclink __P((pciintr_icu_handle_t, int, int *));
92 1.1.4.2 bouyer int amd756_get_intr __P((pciintr_icu_handle_t, int, int *));
93 1.1.4.2 bouyer int amd756_set_intr __P((pciintr_icu_handle_t, int, int));
94 1.1.4.2 bouyer int amd756_get_trigger __P((pciintr_icu_handle_t, int, int *));
95 1.1.4.2 bouyer int amd756_set_trigger __P((pciintr_icu_handle_t, int, int));
96 1.1.4.2 bouyer #ifdef AMD756_DEBUG
97 1.1.4.2 bouyer static void amd756_pir_dump __P((struct amd756_handle *));
98 1.1.4.2 bouyer #endif
99 1.1.4.2 bouyer
100 1.1.4.2 bouyer const struct pciintr_icu amd756_pci_icu = {
101 1.1.4.2 bouyer amd756_getclink,
102 1.1.4.2 bouyer amd756_get_intr,
103 1.1.4.2 bouyer amd756_set_intr,
104 1.1.4.2 bouyer amd756_get_trigger,
105 1.1.4.2 bouyer amd756_set_trigger,
106 1.1.4.2 bouyer };
107 1.1.4.2 bouyer
108 1.1.4.2 bouyer
109 1.1.4.2 bouyer int
110 1.1.4.2 bouyer amd756_init(pc, iot, tag, ptagp, phandp)
111 1.1.4.2 bouyer pci_chipset_tag_t pc;
112 1.1.4.2 bouyer bus_space_tag_t iot;
113 1.1.4.2 bouyer pcitag_t tag;
114 1.1.4.2 bouyer pciintr_icu_tag_t *ptagp;
115 1.1.4.2 bouyer pciintr_icu_handle_t *phandp;
116 1.1.4.2 bouyer {
117 1.1.4.2 bouyer struct amd756_handle *ph;
118 1.1.4.2 bouyer
119 1.1.4.2 bouyer ph = malloc(sizeof(*ph), M_DEVBUF, M_NOWAIT);
120 1.1.4.2 bouyer if (ph == NULL)
121 1.1.4.2 bouyer return (1);
122 1.1.4.2 bouyer
123 1.1.4.2 bouyer ph->ph_iot = iot;
124 1.1.4.2 bouyer ph->ph_pc = pc;
125 1.1.4.2 bouyer ph->ph_tag = tag;
126 1.1.4.2 bouyer
127 1.1.4.2 bouyer *ptagp = &amd756_pci_icu;
128 1.1.4.2 bouyer *phandp = ph;
129 1.1.4.2 bouyer
130 1.1.4.2 bouyer #ifdef AMD756_DEBUG
131 1.1.4.2 bouyer amd756_pir_dump(ph);
132 1.1.4.2 bouyer #endif
133 1.1.4.2 bouyer
134 1.1.4.2 bouyer return (0);
135 1.1.4.2 bouyer }
136 1.1.4.2 bouyer
137 1.1.4.2 bouyer int
138 1.1.4.2 bouyer amd756_getclink(v, link, clinkp)
139 1.1.4.2 bouyer pciintr_icu_handle_t v;
140 1.1.4.2 bouyer int link, *clinkp;
141 1.1.4.2 bouyer {
142 1.1.4.2 bouyer if (AMD756_LEGAL_LINK(link - 1) == 0)
143 1.1.4.2 bouyer return (1);
144 1.1.4.2 bouyer
145 1.1.4.2 bouyer *clinkp = link - 1;
146 1.1.4.2 bouyer
147 1.1.4.2 bouyer return (0);
148 1.1.4.2 bouyer }
149 1.1.4.2 bouyer
150 1.1.4.2 bouyer int
151 1.1.4.2 bouyer amd756_get_intr(v, clink, irqp)
152 1.1.4.2 bouyer pciintr_icu_handle_t v;
153 1.1.4.2 bouyer int clink, *irqp;
154 1.1.4.2 bouyer {
155 1.1.4.2 bouyer struct amd756_handle *ph = v;
156 1.1.4.2 bouyer pcireg_t reg;
157 1.1.4.2 bouyer int val;
158 1.1.4.2 bouyer
159 1.1.4.2 bouyer if (AMD756_LEGAL_LINK(clink) == 0)
160 1.1.4.2 bouyer return (1);
161 1.1.4.2 bouyer
162 1.1.4.2 bouyer reg = AMD756_GET_PIIRQSEL(ph);
163 1.1.4.2 bouyer val = (reg >> (4 * clink)) & 0x0f;
164 1.1.4.2 bouyer *irqp = (val == 0) ?
165 1.1.4.2 bouyer I386_PCI_INTERRUPT_LINE_NO_CONNECTION : val;
166 1.1.4.2 bouyer
167 1.1.4.2 bouyer return (0);
168 1.1.4.2 bouyer }
169 1.1.4.2 bouyer
170 1.1.4.2 bouyer int
171 1.1.4.2 bouyer amd756_set_intr(v, clink, irq)
172 1.1.4.2 bouyer pciintr_icu_handle_t v;
173 1.1.4.2 bouyer int clink, irq;
174 1.1.4.2 bouyer {
175 1.1.4.2 bouyer struct amd756_handle *ph = v;
176 1.1.4.2 bouyer int val;
177 1.1.4.2 bouyer pcireg_t reg;
178 1.1.4.2 bouyer
179 1.1.4.2 bouyer if (AMD756_LEGAL_LINK(clink) == 0 || AMD756_LEGAL_IRQ(irq) == 0)
180 1.1.4.2 bouyer return (1);
181 1.1.4.2 bouyer
182 1.1.4.2 bouyer reg = AMD756_GET_PIIRQSEL(ph);
183 1.1.4.2 bouyer amd756_get_intr(v, clink, &val);
184 1.1.4.2 bouyer reg &= ~(0x000f << (4 * clink));
185 1.1.4.2 bouyer reg |= irq << (4 * clink);
186 1.1.4.2 bouyer AMD756_SET_PIIRQSEL(ph, reg);
187 1.1.4.2 bouyer
188 1.1.4.2 bouyer return (0);
189 1.1.4.2 bouyer }
190 1.1.4.2 bouyer
191 1.1.4.2 bouyer int
192 1.1.4.2 bouyer amd756_get_trigger(v, irq, triggerp)
193 1.1.4.2 bouyer pciintr_icu_handle_t v;
194 1.1.4.2 bouyer int irq, *triggerp;
195 1.1.4.2 bouyer {
196 1.1.4.2 bouyer struct amd756_handle *ph = v;
197 1.1.4.2 bouyer int i, pciirq;
198 1.1.4.2 bouyer pcireg_t reg;
199 1.1.4.2 bouyer
200 1.1.4.2 bouyer if (AMD756_LEGAL_IRQ(irq) == 0)
201 1.1.4.2 bouyer return (1);
202 1.1.4.2 bouyer
203 1.1.4.2 bouyer for (i = 0; i <= 3; i++) {
204 1.1.4.2 bouyer amd756_get_intr(v, i, &pciirq);
205 1.1.4.2 bouyer if (pciirq == irq) {
206 1.1.4.2 bouyer reg = AMD756_GET_EDGESEL(ph);
207 1.1.4.2 bouyer if (reg & (1 << i))
208 1.1.4.2 bouyer *triggerp = IST_EDGE;
209 1.1.4.2 bouyer else
210 1.1.4.2 bouyer *triggerp = IST_LEVEL;
211 1.1.4.2 bouyer break;
212 1.1.4.2 bouyer }
213 1.1.4.2 bouyer }
214 1.1.4.2 bouyer
215 1.1.4.2 bouyer return (0);
216 1.1.4.2 bouyer }
217 1.1.4.2 bouyer
218 1.1.4.2 bouyer int
219 1.1.4.2 bouyer amd756_set_trigger(v, irq, trigger)
220 1.1.4.2 bouyer pciintr_icu_handle_t v;
221 1.1.4.2 bouyer int irq, trigger;
222 1.1.4.2 bouyer {
223 1.1.4.2 bouyer struct amd756_handle *ph = v;
224 1.1.4.2 bouyer int i, pciirq;
225 1.1.4.2 bouyer pcireg_t reg;
226 1.1.4.2 bouyer
227 1.1.4.2 bouyer if (AMD756_LEGAL_IRQ(irq) == 0)
228 1.1.4.2 bouyer return (1);
229 1.1.4.2 bouyer
230 1.1.4.2 bouyer for (i = 0; i <= 3; i++) {
231 1.1.4.2 bouyer amd756_get_intr(v, i, &pciirq);
232 1.1.4.2 bouyer if (pciirq == irq) {
233 1.1.4.2 bouyer reg = AMD756_GET_PIIRQSEL(ph);
234 1.1.4.2 bouyer if (trigger == IST_LEVEL)
235 1.1.4.2 bouyer reg &= ~(1 << (4 * i));
236 1.1.4.2 bouyer else
237 1.1.4.2 bouyer reg |= 1 << (4 * i);
238 1.1.4.2 bouyer AMD756_SET_PIIRQSEL(ph, reg);
239 1.1.4.2 bouyer break;
240 1.1.4.2 bouyer }
241 1.1.4.2 bouyer }
242 1.1.4.2 bouyer
243 1.1.4.2 bouyer return (0);
244 1.1.4.2 bouyer }
245 1.1.4.2 bouyer
246 1.1.4.2 bouyer #ifdef AMD756_DEBUG
247 1.1.4.2 bouyer static void
248 1.1.4.2 bouyer amd756_pir_dump(ph)
249 1.1.4.2 bouyer struct amd756_handle *ph;
250 1.1.4.2 bouyer {
251 1.1.4.2 bouyer int a, b;
252 1.1.4.2 bouyer
253 1.1.4.2 bouyer printf ("AMD756 PCI INTERRUPT ROUTING REGISTERS:\n");
254 1.1.4.2 bouyer
255 1.1.4.2 bouyer a = AMD756_GET_EDGESEL(ph);
256 1.1.4.2 bouyer b = AMD756_GET_PIIRQSEL(ph);
257 1.1.4.2 bouyer
258 1.1.4.2 bouyer printf ("TRIGGER: %02x, ROUTING: %04x\n", a, b);
259 1.1.4.2 bouyer }
260 1.1.4.2 bouyer #endif
261