This source file includes following definitions.
- opti82c558_init
- opti82c558_getclink
- opti82c558_get_intr
- opti82c558_set_intr
- opti82c558_get_trigger
- opti82c558_set_trigger
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/opti82c558reg.h>
84
85 int opti82c558_getclink(pciintr_icu_handle_t, int, int *);
86 int opti82c558_get_intr(pciintr_icu_handle_t, int, int *);
87 int opti82c558_set_intr(pciintr_icu_handle_t, int, int);
88 int opti82c558_get_trigger(pciintr_icu_handle_t, int, int *);
89 int opti82c558_set_trigger(pciintr_icu_handle_t, int, int);
90
91 const struct pciintr_icu opti82c558_pci_icu = {
92 opti82c558_getclink,
93 opti82c558_get_intr,
94 opti82c558_set_intr,
95 opti82c558_get_trigger,
96 opti82c558_set_trigger,
97 };
98
99 struct opti82c558_handle {
100 pci_chipset_tag_t ph_pc;
101 pcitag_t ph_tag;
102 };
103
104 static const int viper_pirq_decode[] = {
105 -1, 5, 9, 10, 11, 12, 14, 15
106 };
107
108 static const int viper_pirq_encode[] = {
109 -1,
110 -1,
111 -1,
112 -1,
113 -1,
114 VIPER_PIRQ_5,
115 -1,
116 -1,
117 -1,
118 VIPER_PIRQ_9,
119 VIPER_PIRQ_10,
120 VIPER_PIRQ_11,
121 VIPER_PIRQ_12,
122 -1,
123 VIPER_PIRQ_14,
124 VIPER_PIRQ_15,
125 };
126
127 int
128 opti82c558_init(pci_chipset_tag_t pc, bus_space_tag_t iot, pcitag_t tag,
129 pciintr_icu_tag_t *ptagp, pciintr_icu_handle_t *phandp)
130 {
131 struct opti82c558_handle *ph;
132
133 ph = malloc(sizeof(*ph), M_DEVBUF, M_NOWAIT);
134 if (ph == NULL)
135 return (1);
136
137 ph->ph_pc = pc;
138 ph->ph_tag = tag;
139
140 *ptagp = &opti82c558_pci_icu;
141 *phandp = ph;
142 return (0);
143 }
144
145 int
146 opti82c558_getclink(pciintr_icu_handle_t v, int link, int *clinkp)
147 {
148
149 if (VIPER_LEGAL_LINK(link - 1)) {
150 *clinkp = link - 1;
151 return (0);
152 }
153
154 return (1);
155 }
156
157 int
158 opti82c558_get_intr(pciintr_icu_handle_t v, int clink, int *irqp)
159 {
160 struct opti82c558_handle *ph = v;
161 pcireg_t reg;
162 int val;
163
164 if (VIPER_LEGAL_LINK(clink) == 0)
165 return (1);
166
167 reg = pci_conf_read(ph->ph_pc, ph->ph_tag, VIPER_CFG_PIRQ);
168 val = VIPER_PIRQ(reg, clink);
169 *irqp = (val == VIPER_PIRQ_NONE) ? 0xff : viper_pirq_decode[val];
170
171 return (0);
172 }
173
174 int
175 opti82c558_set_intr(pciintr_icu_handle_t v, int clink, int irq)
176 {
177 struct opti82c558_handle *ph = v;
178 int shift;
179 pcireg_t reg;
180
181 if (VIPER_LEGAL_LINK(clink) == 0 || VIPER_LEGAL_IRQ(irq) == 0)
182 return (1);
183
184 reg = pci_conf_read(ph->ph_pc, ph->ph_tag, VIPER_CFG_PIRQ);
185 shift = VIPER_PIRQ_SELECT_SHIFT * clink;
186 reg &= ~(VIPER_PIRQ_SELECT_MASK << shift);
187 reg |= (viper_pirq_encode[irq] << shift);
188 pci_conf_write(ph->ph_pc, ph->ph_tag, VIPER_CFG_PIRQ, reg);
189
190 return (0);
191 }
192
193 int
194 opti82c558_get_trigger(pciintr_icu_handle_t v, int irq, int *triggerp)
195 {
196 struct opti82c558_handle *ph = v;
197 pcireg_t reg;
198
199 if (VIPER_LEGAL_IRQ(irq) == 0) {
200
201 *triggerp = IST_EDGE;
202 return (0);
203 }
204
205 reg = pci_conf_read(ph->ph_pc, ph->ph_tag, VIPER_CFG_PIRQ);
206 if ((reg >> (VIPER_CFG_TRIGGER_SHIFT + viper_pirq_encode[irq])) & 1)
207 *triggerp = IST_LEVEL;
208 else
209 *triggerp = IST_EDGE;
210
211 return (0);
212 }
213
214 int
215 opti82c558_set_trigger(pciintr_icu_handle_t v, int irq, int trigger)
216 {
217 struct opti82c558_handle *ph = v;
218 int shift;
219 pcireg_t reg;
220
221 if (VIPER_LEGAL_IRQ(irq) == 0) {
222
223 return ((trigger != IST_LEVEL) ? 0 : 1);
224 }
225
226 reg = pci_conf_read(ph->ph_pc, ph->ph_tag, VIPER_CFG_PIRQ);
227 shift = (VIPER_CFG_TRIGGER_SHIFT + viper_pirq_encode[irq]);
228 if (trigger == IST_LEVEL)
229 reg |= (1 << shift);
230 else
231 reg &= ~(1 << shift);
232 pci_conf_write(ph->ph_pc, ph->ph_tag, VIPER_CFG_PIRQ, reg);
233
234 return (0);
235 }