This source file includes following definitions.
- addcomprobe
- addcomprint
- addcomattach
- addcomintr
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 #include <sys/param.h>
63 #include <sys/systm.h>
64 #include <sys/device.h>
65 #include <sys/termios.h>
66
67 #include <machine/bus.h>
68 #include <machine/intr.h>
69
70 #include <dev/ic/comreg.h>
71 #include <dev/ic/comvar.h>
72
73 #include <dev/isa/isavar.h>
74
75 #define NSLAVES 8
76
77
78
79
80
81 #define STATUS_IOADDR 0x420
82 #define STATUS_SIZE 8
83
84 struct addcom_softc {
85 struct device sc_dev;
86 void *sc_ih;
87
88 bus_space_tag_t sc_iot;
89 bus_addr_t sc_iobase;
90
91 int sc_alive[NSLAVES];
92 void *sc_slaves[NSLAVES];
93 bus_space_handle_t sc_slaveioh[NSLAVES];
94 bus_space_handle_t sc_statusioh;
95 };
96
97 #define SLAVE_IOBASE_OFFSET 0x108
98 static int slave_iobases[8] = {
99 0x108,
100 0x110,
101 0x118,
102 0x120,
103 0x128,
104 0x130,
105 0x200,
106 0x208
107 };
108
109 int addcomprobe(struct device *, void *, void *);
110 void addcomattach(struct device *, struct device *, void *);
111 int addcomintr(void *);
112 int addcomprint(void *, const char *);
113
114 struct cfattach addcom_isa_ca = {
115 sizeof(struct addcom_softc), addcomprobe, addcomattach,
116 };
117
118 struct cfdriver addcom_cd = {
119 NULL, "addcom", DV_TTY
120 };
121
122 int
123 addcomprobe(parent, self, aux)
124 struct device *parent;
125 void *self, *aux;
126 {
127 struct isa_attach_args *ia = aux;
128 int iobase = ia->ia_iobase;
129 bus_space_tag_t iot = ia->ia_iot;
130 bus_space_handle_t ioh;
131 int i, rv = 1;
132
133
134
135
136
137
138
139
140
141 if (ia->ia_iobase == -1 )
142 return (0);
143
144
145 if (iobase == comconsaddr && !comconsattached)
146 goto checkmappings;
147
148 if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) {
149 rv = 0;
150 goto out;
151 }
152 rv = comprobe1(iot, ioh);
153 bus_space_unmap(iot, ioh, COM_NPORTS);
154 if (rv == 0)
155 goto out;
156
157 checkmappings:
158 for (i = 1; i < NSLAVES; i++) {
159 iobase += slave_iobases[i] - slave_iobases[i - 1];
160
161 if (iobase == comconsaddr && !comconsattached)
162 continue;
163
164 if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) {
165 rv = 0;
166 goto out;
167 }
168 bus_space_unmap(iot, ioh, COM_NPORTS);
169 }
170
171 out:
172 if (rv)
173 ia->ia_iosize = NSLAVES * COM_NPORTS;
174 return (rv);
175 }
176
177 int
178 addcomprint(aux, pnp)
179 void *aux;
180 const char *pnp;
181 {
182 struct commulti_attach_args *ca = aux;
183
184 if (pnp)
185 printf("com at %s", pnp);
186 printf(" slave %d", ca->ca_slave);
187 return (UNCONF);
188 }
189
190 void
191 addcomattach(parent, self, aux)
192 struct device *parent, *self;
193 void *aux;
194 {
195 struct addcom_softc *sc = (void *)self;
196 struct isa_attach_args *ia = aux;
197 struct commulti_attach_args ca;
198 bus_space_tag_t iot = ia->ia_iot;
199 bus_addr_t iobase;
200 int i;
201
202 sc->sc_iot = ia->ia_iot;
203 sc->sc_iobase = ia->ia_iobase;
204
205
206 if (ia->ia_irq == IRQUNK) {
207 printf(": wildcard interrupt not supported\n");
208 return;
209 }
210
211 sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
212 IPL_TTY, addcomintr, sc, sc->sc_dev.dv_xname);
213 if (sc->sc_ih == NULL) {
214 printf(": can't establish interrupt\n");
215 return;
216 }
217
218 if (bus_space_map(iot, STATUS_IOADDR, STATUS_SIZE,
219 0, &sc->sc_statusioh)) {
220 printf(": can't map status space\n");
221 return;
222 }
223
224 for (i = 0; i < NSLAVES; i++) {
225 iobase = sc->sc_iobase
226 + slave_iobases[i]
227 - SLAVE_IOBASE_OFFSET;
228
229 if ((!(iobase == comconsaddr && !comconsattached)) &&
230 bus_space_map(iot, iobase, COM_NPORTS, 0,
231 &sc->sc_slaveioh[i])) {
232 printf(": can't map i/o space for slave %d\n", i);
233 return;
234 }
235 }
236
237 printf("\n");
238
239 for (i = 0; i < NSLAVES; i++) {
240 ca.ca_slave = i;
241 ca.ca_iot = sc->sc_iot;
242 ca.ca_ioh = sc->sc_slaveioh[i];
243 ca.ca_iobase = sc->sc_iobase
244 + slave_iobases[i]
245 - SLAVE_IOBASE_OFFSET;
246 ca.ca_noien = 0;
247
248 sc->sc_slaves[i] = config_found(self, &ca, addcomprint);
249 if (sc->sc_slaves[i] != NULL)
250 sc->sc_alive[i] = 1;
251 }
252
253 }
254
255 int
256 addcomintr(arg)
257 void *arg;
258 {
259 struct addcom_softc *sc = arg;
260 int intrd, r = 0, i;
261
262 do {
263 intrd = 0;
264 for (i = 0; i < NSLAVES; i++)
265 if (sc->sc_alive[i] && comintr(sc->sc_slaves[i])) {
266 r = 1;
267 intrd = 1;
268 }
269 } while (intrd);
270
271 return (r);
272 }