This source file includes following definitions.
- piix_init
- piix_getclink
- piix_get_intr
- piix_set_intr
- piix_get_trigger
- piix_set_trigger
- piix_pir_dump
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70 #include <sys/param.h>
71 #include <sys/systm.h>
72 #include <sys/device.h>
73 #include <sys/malloc.h>
74
75 #include <machine/intr.h>
76 #include <machine/bus.h>
77
78 #include <dev/pci/pcivar.h>
79 #include <dev/pci/pcireg.h>
80 #include <dev/pci/pcidevs.h>
81
82 #include <i386/pci/pcibiosvar.h>
83 #include <i386/pci/piixreg.h>
84 #include <i386/pci/piixvar.h>
85
86 #ifdef PIIX_DEBUG
87 #define DPRINTF(arg) printf arg
88 #else
89 #define DPRINTF(arg)
90 #endif
91
92 int piix_getclink(pciintr_icu_handle_t, int, int *);
93 int piix_get_intr(pciintr_icu_handle_t, int, int *);
94 int piix_set_intr(pciintr_icu_handle_t, int, int);
95 #ifdef PIIX_DEBUG
96 void piix_pir_dump(struct piix_handle *);
97 #endif
98
99 const struct pciintr_icu piix_pci_icu = {
100 piix_getclink,
101 piix_get_intr,
102 piix_set_intr,
103 piix_get_trigger,
104 piix_set_trigger,
105 };
106
107 int
108 piix_init(pci_chipset_tag_t pc, bus_space_tag_t iot, pcitag_t tag,
109 pciintr_icu_tag_t *ptagp, pciintr_icu_handle_t *phandp)
110 {
111 struct piix_handle *ph;
112
113 ph = malloc(sizeof(*ph), M_DEVBUF, M_NOWAIT);
114 if (ph == NULL)
115 return (1);
116
117 ph->ph_iot = iot;
118 ph->ph_pc = pc;
119 ph->ph_tag = tag;
120
121 if (bus_space_map(iot, PIIX_REG_ELCR, PIIX_REG_ELCR_SIZE, 0,
122 &ph->ph_elcr_ioh) != 0) {
123 free(ph, M_DEVBUF);
124 return (1);
125 }
126
127 #ifdef PIIX_DEBUG
128 piix_pir_dump(ph);
129 #endif
130 *ptagp = &piix_pci_icu;
131 *phandp = ph;
132 return (0);
133 }
134
135 int
136 piix_getclink(pciintr_icu_handle_t v, int link, int *clinkp)
137 {
138 DPRINTF(("PIIX link value 0x%x: ", link));
139
140
141 if (PIIX_LEGAL_LINK(link - 1)) {
142 *clinkp = link - 1;
143 DPRINTF(("PIRQ %d (simple)\n", *clinkp));
144 return (0);
145 }
146
147
148 if (link >= 0x60 && link <= 0x63) {
149 *clinkp = link - 0x60;
150 DPRINTF(("PIRQ %d (register offset)\n", *clinkp));
151 return (0);
152 }
153
154
155 if (link >= 0x68 && link <= 0x6b) {
156 *clinkp = link - 0x64;
157 DPRINTF(("PIRQ %d (high register offset)\n", *clinkp));
158 return (0);
159 }
160
161 DPRINTF(("bogus IRQ selection source\n"));
162 return (1);
163 }
164
165 int
166 piix_get_intr(pciintr_icu_handle_t v, int clink, int *irqp)
167 {
168 struct piix_handle *ph = v;
169 int shift, off;
170 pcireg_t reg;
171
172 if (PIIX_LEGAL_LINK(clink) == 0)
173 return (1);
174
175 off = PIIX_CFG_PIRQ;
176 if (clink > 3) {
177 off += 8;
178 clink -= 4;
179 }
180
181 reg = pci_conf_read(ph->ph_pc, ph->ph_tag, off);
182 shift = clink << 3;
183 if ((reg >> shift) & PIIX_CFG_PIRQ_NONE)
184 *irqp = I386_PCI_INTERRUPT_LINE_NO_CONNECTION;
185 else
186 *irqp = PIIX_PIRQ(reg, clink);
187
188 return (0);
189 }
190
191 int
192 piix_set_intr(pciintr_icu_handle_t v, int clink, int irq)
193 {
194 struct piix_handle *ph = v;
195 int shift, off;
196 pcireg_t reg;
197
198 if (PIIX_LEGAL_LINK(clink) == 0 || PIIX_LEGAL_IRQ(irq) == 0)
199 return (1);
200
201 off = PIIX_CFG_PIRQ;
202 if (clink > 3) {
203 off += 8;
204 clink -= 4;
205 }
206
207 reg = pci_conf_read(ph->ph_pc, ph->ph_tag, off);
208 shift = clink << 3;
209 reg &= ~((PIIX_CFG_PIRQ_NONE | PIIX_CFG_PIRQ_MASK) << shift);
210 reg |= irq << shift;
211 pci_conf_write(ph->ph_pc, ph->ph_tag, off, reg);
212
213 return (0);
214 }
215
216 int
217 piix_get_trigger(pciintr_icu_handle_t v, int irq, int *triggerp)
218 {
219 struct piix_handle *ph = v;
220 int off, bit;
221 u_int8_t elcr;
222
223 if (PIIX_LEGAL_IRQ(irq) == 0)
224 return (1);
225
226 off = (irq > 7) ? 1 : 0;
227 bit = irq & 7;
228
229 elcr = bus_space_read_1(ph->ph_iot, ph->ph_elcr_ioh, off);
230 if (elcr & (1 << bit))
231 *triggerp = IST_LEVEL;
232 else
233 *triggerp = IST_EDGE;
234
235 return (0);
236 }
237
238 int
239 piix_set_trigger(pciintr_icu_handle_t v, int irq, int trigger)
240 {
241 struct piix_handle *ph = v;
242 int off, bit;
243 u_int8_t elcr;
244
245 if (PIIX_LEGAL_IRQ(irq) == 0)
246 return (1);
247
248 off = (irq > 7) ? 1 : 0;
249 bit = irq & 7;
250
251 elcr = bus_space_read_1(ph->ph_iot, ph->ph_elcr_ioh, off);
252 if (trigger == IST_LEVEL)
253 elcr |= (1 << bit);
254 else
255 elcr &= ~(1 << bit);
256 bus_space_write_1(ph->ph_iot, ph->ph_elcr_ioh, off, elcr);
257
258 return (0);
259 }
260
261 #ifdef PIIX_DEBUG
262 void
263 piix_pir_dump(struct piix_handle *ph)
264 {
265 int i, irq;
266 pcireg_t irqs = pci_conf_read(ph->ph_pc, ph->ph_tag, PIIX_CFG_PIRQ);
267 u_int8_t elcr[2];
268
269 elcr[0] = bus_space_read_1(ph->ph_iot, ph->ph_elcr_ioh, 0);
270 elcr[1] = bus_space_read_1(ph->ph_iot, ph->ph_elcr_ioh, 1);
271
272 for (i = 0; i < 8; i++) {
273 if (i == 4)
274 irqs = pci_conf_read(ph->ph_pc, ph->ph_tag,
275 PIIX_CFG_PIRQH);
276
277 irq = PIIX_PIRQ(irqs, i);
278 if (irq & PIIX_CFG_PIRQ_NONE)
279 printf("PIIX PIRQ %d: irq none (0x%x)\n", i, irq);
280 else
281 printf("PIIX PIRQ %d: irq %d\n", i, irq);
282 }
283
284 printf("PIIX irq:");
285 for (i = 0; i < 16; i++)
286 printf(" %2d", i);
287 printf("\n");
288 printf(" trigger:");
289 for (i = 0; i < 16; i++)
290 printf(" %c", (elcr[(i & 8) ? 1 : 0] & (1 << (i & 7))) ?
291 'L' : 'E');
292 printf("\n");
293 }
294 #endif