qms.c revision 1.5 1 1.5 lukem /* $NetBSD: qms.c,v 1.5 2003/07/15 00:24:45 lukem Exp $ */
2 1.1 reinoud
3 1.1 reinoud /*
4 1.1 reinoud * Copyright (c) Scott Stevens 1995 All rights reserved
5 1.1 reinoud * Copyright (c) Melvin Tang-Richardson 1995 All rights reserved
6 1.1 reinoud * Copyright (c) Mark Brinicombe 1995 All rights reserved
7 1.1 reinoud *
8 1.1 reinoud * Redistribution and use in source and binary forms, with or without
9 1.1 reinoud * modification, are permitted provided that the following conditions
10 1.1 reinoud * are met:
11 1.1 reinoud * 1. Redistributions of source code must retain the above copyright
12 1.1 reinoud * notice, this list of conditions and the following disclaimer.
13 1.1 reinoud * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 reinoud * notice, this list of conditions and the following disclaimer in the
15 1.1 reinoud * documentation and/or other materials provided with the distribution.
16 1.1 reinoud * 3. All advertising materials mentioning features or use of this software
17 1.1 reinoud * must display the following acknowledgement:
18 1.1 reinoud * This product includes software developed for the NetBSD Project.
19 1.1 reinoud * 4. The name of the author may not be used to endorse or promote products
20 1.1 reinoud * derived from this software without specific prior written permission.
21 1.1 reinoud *
22 1.1 reinoud * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 1.1 reinoud * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 1.1 reinoud * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 1.1 reinoud * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 1.1 reinoud * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 1.1 reinoud * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 1.1 reinoud * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 1.1 reinoud * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 1.1 reinoud * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 1.1 reinoud * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 1.1 reinoud */
33 1.1 reinoud
34 1.1 reinoud /*
35 1.1 reinoud * Quadrature mouse driver
36 1.1 reinoud */
37 1.5 lukem
38 1.5 lukem #include <sys/cdefs.h>
39 1.5 lukem __KERNEL_RCSID(0, "$NetBSD: qms.c,v 1.5 2003/07/15 00:24:45 lukem Exp $");
40 1.1 reinoud
41 1.1 reinoud #include <sys/param.h>
42 1.1 reinoud #include <sys/systm.h>
43 1.1 reinoud #include <sys/conf.h>
44 1.1 reinoud #include <sys/ioctl.h>
45 1.1 reinoud #include <sys/tty.h>
46 1.1 reinoud #include <sys/kernel.h>
47 1.1 reinoud #include <sys/types.h>
48 1.1 reinoud #include <sys/device.h>
49 1.1 reinoud #include <sys/proc.h>
50 1.1 reinoud #include <sys/time.h>
51 1.1 reinoud #include <sys/errno.h>
52 1.1 reinoud #include <dev/cons.h>
53 1.1 reinoud #include <sys/fcntl.h>
54 1.1 reinoud #include <sys/signalvar.h>
55 1.1 reinoud #include <sys/vnode.h>
56 1.1 reinoud #include <sys/time.h>
57 1.1 reinoud #include <sys/poll.h>
58 1.1 reinoud
59 1.1 reinoud #include <machine/bus.h>
60 1.1 reinoud #include <machine/mouse.h>
61 1.1 reinoud #include <arm/iomd/qmsvar.h>
62 1.1 reinoud
63 1.1 reinoud #define MOUSE_IOC_ACK
64 1.1 reinoud
65 1.1 reinoud #define QMOUSE_BSIZE 12*64
66 1.1 reinoud
67 1.1 reinoud #ifdef MOUSE_IOC_ACK
68 1.1 reinoud static void qmsputbuffer __P((struct qms_softc *sc, struct mousebufrec *buf));
69 1.1 reinoud #endif
70 1.1 reinoud
71 1.1 reinoud extern struct cfdriver qms_cd;
72 1.2 gehenna
73 1.2 gehenna dev_type_open(qmsopen);
74 1.2 gehenna dev_type_close(qmsclose);
75 1.2 gehenna dev_type_read(qmsread);
76 1.2 gehenna dev_type_ioctl(qmsioctl);
77 1.2 gehenna dev_type_poll(qmspoll);
78 1.3 jdolecek dev_type_kqfilter(qmskqfilter);
79 1.2 gehenna
80 1.2 gehenna const struct cdevsw qms_cdevsw = {
81 1.2 gehenna qmsopen, qmsclose, qmsread, nowrite, qmsioctl,
82 1.3 jdolecek nostop, notty, qmspoll, nommap, qmskqfilter,
83 1.2 gehenna };
84 1.1 reinoud
85 1.1 reinoud /* qms device structure */
86 1.1 reinoud
87 1.1 reinoud /* Offsets of hardware registers */
88 1.1 reinoud #define QMS_MOUSEX 0 /* 16 bit X register */
89 1.1 reinoud #define QMS_MOUSEY 1 /* 16 bit Y register */
90 1.1 reinoud
91 1.1 reinoud #define QMS_BUTTONS 0 /* mouse buttons register */
92 1.1 reinoud
93 1.1 reinoud /*
94 1.1 reinoud * generic attach routine. This does the generic part of the driver
95 1.1 reinoud * attachment and is called from the bus specific attach routine.
96 1.1 reinoud */
97 1.1 reinoud
98 1.1 reinoud void
99 1.1 reinoud qmsattach(sc)
100 1.1 reinoud struct qms_softc *sc;
101 1.1 reinoud {
102 1.1 reinoud /* Set up origin and multipliers */
103 1.1 reinoud sc->origx = 0;
104 1.1 reinoud sc->origy = 0;
105 1.1 reinoud sc->xmult = 2;
106 1.1 reinoud sc->ymult = 2;
107 1.1 reinoud
108 1.1 reinoud /* Set up bounding box */
109 1.1 reinoud sc->boundx = -4095;
110 1.1 reinoud sc->boundy = -4095;
111 1.1 reinoud sc->bounda = 4096;
112 1.1 reinoud sc->boundb = 4096;
113 1.1 reinoud
114 1.1 reinoud sc->sc_state = 0;
115 1.1 reinoud
116 1.1 reinoud /* Set the mouse X & Y registers to a known state */
117 1.1 reinoud bus_space_write_4(sc->sc_iot, sc->sc_ioh, QMS_MOUSEX, sc->origx);
118 1.1 reinoud bus_space_write_4(sc->sc_iot, sc->sc_ioh, QMS_MOUSEX, sc->origx);
119 1.1 reinoud }
120 1.1 reinoud
121 1.1 reinoud int
122 1.1 reinoud qmsopen(dev, flag, mode, p)
123 1.1 reinoud dev_t dev;
124 1.1 reinoud int flag;
125 1.1 reinoud int mode;
126 1.1 reinoud struct proc *p;
127 1.1 reinoud {
128 1.1 reinoud struct qms_softc *sc;
129 1.1 reinoud int unit = minor(dev);
130 1.1 reinoud
131 1.1 reinoud /* validate the unit and softc */
132 1.1 reinoud if (unit >= qms_cd.cd_ndevs)
133 1.1 reinoud return(ENXIO);
134 1.1 reinoud
135 1.1 reinoud sc = qms_cd.cd_devs[unit];
136 1.1 reinoud
137 1.1 reinoud if (!sc) return(ENXIO);
138 1.1 reinoud
139 1.1 reinoud /* check if we are already open */
140 1.1 reinoud if (sc->sc_state & QMOUSE_OPEN) return(EBUSY);
141 1.1 reinoud
142 1.1 reinoud /* update softc */
143 1.1 reinoud sc->sc_proc = p;
144 1.1 reinoud
145 1.1 reinoud sc->lastx = -1;
146 1.1 reinoud sc->lasty = -1;
147 1.1 reinoud sc->lastb = -1;
148 1.1 reinoud
149 1.1 reinoud /* initialise buffer */
150 1.1 reinoud if (clalloc(&sc->sc_buffer, QMOUSE_BSIZE, 0) == -1)
151 1.1 reinoud return(ENOMEM);
152 1.1 reinoud
153 1.1 reinoud /* set mode and state */
154 1.1 reinoud sc->sc_mode = MOUSEMODE_ABS;
155 1.1 reinoud sc->sc_state |= QMOUSE_OPEN;
156 1.1 reinoud
157 1.1 reinoud /* enable interrupts */
158 1.1 reinoud sc->sc_intenable(sc, 1);
159 1.1 reinoud
160 1.1 reinoud return(0);
161 1.1 reinoud }
162 1.1 reinoud
163 1.1 reinoud
164 1.1 reinoud int
165 1.1 reinoud qmsclose(dev, flag, mode, p)
166 1.1 reinoud dev_t dev;
167 1.1 reinoud int flag;
168 1.1 reinoud int mode;
169 1.1 reinoud struct proc *p;
170 1.1 reinoud {
171 1.1 reinoud int unit = minor(dev);
172 1.1 reinoud struct qms_softc *sc = qms_cd.cd_devs[unit];
173 1.1 reinoud
174 1.1 reinoud /* disable interrupts */
175 1.1 reinoud sc->sc_intenable(sc, 0);
176 1.1 reinoud
177 1.1 reinoud /* clean up */
178 1.1 reinoud sc->sc_proc = NULL;
179 1.1 reinoud sc->sc_state = 0;
180 1.1 reinoud
181 1.1 reinoud clfree(&sc->sc_buffer);
182 1.1 reinoud
183 1.1 reinoud return(0);
184 1.1 reinoud }
185 1.1 reinoud
186 1.1 reinoud int
187 1.1 reinoud qmsread(dev, uio, flag)
188 1.1 reinoud dev_t dev;
189 1.1 reinoud struct uio *uio;
190 1.1 reinoud int flag;
191 1.1 reinoud {
192 1.1 reinoud int unit = minor(dev);
193 1.1 reinoud struct qms_softc *sc = qms_cd.cd_devs[unit];
194 1.1 reinoud int error;
195 1.1 reinoud int s;
196 1.1 reinoud int length;
197 1.1 reinoud u_char buffer[128];
198 1.1 reinoud
199 1.1 reinoud error = 0;
200 1.1 reinoud s = spltty();
201 1.1 reinoud while (sc->sc_buffer.c_cc == 0) {
202 1.1 reinoud if (flag & IO_NDELAY) {
203 1.1 reinoud (void)splx(s);
204 1.1 reinoud return(EWOULDBLOCK);
205 1.1 reinoud }
206 1.1 reinoud sc->sc_state |= QMOUSE_ASLEEP;
207 1.1 reinoud if ((error = tsleep((caddr_t)sc, PZERO | PCATCH, "qmsread", 0))) {
208 1.1 reinoud sc->sc_state &= ~QMOUSE_ASLEEP;
209 1.1 reinoud (void)splx(s);
210 1.1 reinoud return(error);
211 1.1 reinoud }
212 1.1 reinoud }
213 1.1 reinoud
214 1.1 reinoud while (sc->sc_buffer.c_cc > 0 && uio->uio_resid > 0) {
215 1.1 reinoud length = min(sc->sc_buffer.c_cc, uio->uio_resid);
216 1.1 reinoud if(length>sizeof(buffer))
217 1.1 reinoud length=sizeof(buffer);
218 1.1 reinoud
219 1.1 reinoud (void)q_to_b(&sc->sc_buffer, buffer, length);
220 1.1 reinoud
221 1.1 reinoud if ((error = (uiomove(buffer, length, uio))))
222 1.1 reinoud break;
223 1.1 reinoud }
224 1.1 reinoud (void)splx(s);
225 1.1 reinoud return(error);
226 1.1 reinoud }
227 1.1 reinoud
228 1.1 reinoud
229 1.1 reinoud #define FMT_START \
230 1.1 reinoud int x = bus_space_read_4(sc->sc_iot, sc->sc_ioh, QMS_MOUSEX) & 0xffff; \
231 1.1 reinoud int y = bus_space_read_4(sc->sc_iot, sc->sc_ioh, QMS_MOUSEY) & 0xffff; \
232 1.1 reinoud int b = bus_space_read_1(sc->sc_iot, sc->sc_butioh, QMS_BUTTONS) & 0x70;\
233 1.1 reinoud if (x & 0x8000) x |= 0xffff0000; \
234 1.1 reinoud if (y & 0x8000) y |= 0xffff0000; \
235 1.1 reinoud x = (x - sc->origx); \
236 1.1 reinoud y = (y - sc->origy); \
237 1.1 reinoud if (x < (sc->boundx)) x = sc->boundx; \
238 1.1 reinoud if (x > (sc->bounda)) x = sc->bounda; \
239 1.1 reinoud bus_space_write_4(sc->sc_iot, sc->sc_ioh, QMS_MOUSEX, x + sc->origx); \
240 1.1 reinoud if (y < (sc->boundy)) y = sc->boundy; \
241 1.1 reinoud if (y > (sc->boundb)) y = sc->boundb; \
242 1.1 reinoud bus_space_write_4(sc->sc_iot, sc->sc_ioh, QMS_MOUSEY, y + sc->origy); \
243 1.1 reinoud x = x * sc->xmult; \
244 1.1 reinoud y = y * sc->ymult;
245 1.1 reinoud
246 1.1 reinoud #define FMT_END
247 1.1 reinoud
248 1.1 reinoud
249 1.1 reinoud int
250 1.1 reinoud qmsioctl(dev, cmd, data, flag, p)
251 1.1 reinoud dev_t dev;
252 1.1 reinoud u_long cmd;
253 1.1 reinoud caddr_t data;
254 1.1 reinoud int flag;
255 1.1 reinoud struct proc *p;
256 1.1 reinoud {
257 1.1 reinoud struct qms_softc *sc = qms_cd.cd_devs[minor(dev)];
258 1.1 reinoud
259 1.1 reinoud switch (cmd) {
260 1.1 reinoud case MOUSEIOC_WRITEX:
261 1.1 reinoud bus_space_write_4(sc->sc_iot, sc->sc_ioh, QMS_MOUSEX,
262 1.1 reinoud *(int *)data + sc->origx);
263 1.1 reinoud return 0;
264 1.1 reinoud case MOUSEIOC_WRITEY:
265 1.1 reinoud bus_space_write_4(sc->sc_iot, sc->sc_ioh, QMS_MOUSEY,
266 1.1 reinoud *(int *)data + sc->origy);
267 1.1 reinoud return 0;
268 1.1 reinoud case MOUSEIOC_SETSTATE:
269 1.1 reinoud {
270 1.1 reinoud struct mouse_state *co = (void *)data;
271 1.1 reinoud bus_space_write_4(sc->sc_iot, sc->sc_ioh, QMS_MOUSEX, co->x);
272 1.1 reinoud bus_space_write_4(sc->sc_iot, sc->sc_ioh, QMS_MOUSEY, co->y);
273 1.1 reinoud return 0;
274 1.1 reinoud }
275 1.1 reinoud case MOUSEIOC_SETBOUNDS:
276 1.1 reinoud {
277 1.1 reinoud struct mouse_boundingbox *bo = (void *)data;
278 1.1 reinoud struct mousebufrec buffer;
279 1.1 reinoud #ifdef MOUSE_IOC_ACK
280 1.1 reinoud int s;
281 1.1 reinoud
282 1.1 reinoud s = spltty();
283 1.1 reinoud #endif
284 1.1 reinoud
285 1.1 reinoud sc->boundx = bo->x;
286 1.1 reinoud sc->boundy = bo->y;
287 1.1 reinoud sc->bounda = bo->a;
288 1.1 reinoud sc->boundb = bo->b;
289 1.1 reinoud
290 1.1 reinoud buffer.status = IOC_ACK;
291 1.1 reinoud buffer.x = sc->origx;
292 1.1 reinoud buffer.y = sc->origy;
293 1.1 reinoud #ifdef MOUSE_IOC_ACK
294 1.1 reinoud if (sc->sc_buffer.c_cc > 0)
295 1.1 reinoud printf("%s: setting bounding with non empty buffer (%d)\n",
296 1.1 reinoud sc->sc_device.dv_xname, sc->sc_buffer.c_cc);
297 1.1 reinoud qmsputbuffer(sc, &buffer);
298 1.1 reinoud (void)splx(s);
299 1.1 reinoud #endif
300 1.1 reinoud return 0;
301 1.1 reinoud }
302 1.1 reinoud case MOUSEIOC_SETMODE:
303 1.1 reinoud {
304 1.1 reinoud struct mousebufrec buffer;
305 1.1 reinoud #ifdef MOUSE_IOC_ACK
306 1.1 reinoud int s;
307 1.1 reinoud
308 1.1 reinoud s = spltty();
309 1.1 reinoud #endif
310 1.1 reinoud sc->sc_mode = *(int *)data;
311 1.1 reinoud
312 1.1 reinoud buffer.status = IOC_ACK;
313 1.1 reinoud buffer.x = sc->origx;
314 1.1 reinoud buffer.y = sc->origy;
315 1.1 reinoud #ifdef MOUSE_IOC_ACK
316 1.1 reinoud if (sc->sc_buffer.c_cc > 0)
317 1.1 reinoud printf("%s: setting mode with non empty buffer (%d)\n",
318 1.1 reinoud sc->sc_device.dv_xname, sc->sc_buffer.c_cc);
319 1.1 reinoud qmsputbuffer(sc, &buffer);
320 1.1 reinoud (void)splx(s);
321 1.1 reinoud #endif
322 1.1 reinoud return 0;
323 1.1 reinoud }
324 1.1 reinoud case MOUSEIOC_SETORIGIN:
325 1.1 reinoud {
326 1.1 reinoud struct mouse_origin *oo = (void *)data;
327 1.1 reinoud struct mousebufrec buffer;
328 1.1 reinoud #ifdef MOUSE_IOC_ACK
329 1.1 reinoud int s;
330 1.1 reinoud
331 1.1 reinoud s = spltty();
332 1.1 reinoud #endif
333 1.1 reinoud /* Need to fix up! */
334 1.1 reinoud sc->origx = oo->x;
335 1.1 reinoud sc->origy = oo->y;
336 1.1 reinoud
337 1.1 reinoud buffer.status = IOC_ACK;
338 1.1 reinoud buffer.x = sc->origx;
339 1.1 reinoud buffer.y = sc->origy;
340 1.1 reinoud #ifdef MOUSE_IOC_ACK
341 1.1 reinoud if (sc->sc_buffer.c_cc > 0)
342 1.1 reinoud printf("%s: setting origin with non empty buffer (%d)\n",
343 1.1 reinoud sc->sc_device.dv_xname, sc->sc_buffer.c_cc);
344 1.1 reinoud qmsputbuffer(sc, &buffer);
345 1.1 reinoud (void)splx(s);
346 1.1 reinoud #endif
347 1.1 reinoud return 0;
348 1.1 reinoud }
349 1.1 reinoud case MOUSEIOC_GETSTATE:
350 1.1 reinoud {
351 1.1 reinoud struct mouse_state *co = (void *)data;
352 1.1 reinoud FMT_START
353 1.1 reinoud co->x = x;
354 1.1 reinoud co->y = y;
355 1.1 reinoud co->buttons = b ^ 0x70;
356 1.1 reinoud FMT_END
357 1.1 reinoud return 0;
358 1.1 reinoud }
359 1.1 reinoud case MOUSEIOC_GETBOUNDS:
360 1.1 reinoud {
361 1.1 reinoud struct mouse_boundingbox *bo = (void *)data;
362 1.1 reinoud bo->x = sc->boundx;
363 1.1 reinoud bo->y = sc->boundy;
364 1.1 reinoud bo->a = sc->bounda;
365 1.1 reinoud bo->b = sc->boundb;
366 1.1 reinoud return 0;
367 1.1 reinoud }
368 1.1 reinoud case MOUSEIOC_GETORIGIN:
369 1.1 reinoud {
370 1.1 reinoud struct mouse_origin *oo = (void *)data;
371 1.1 reinoud oo->x = sc->origx;
372 1.1 reinoud oo->y = sc->origy;
373 1.1 reinoud return 0;
374 1.1 reinoud }
375 1.1 reinoud }
376 1.1 reinoud
377 1.1 reinoud return (EINVAL);
378 1.1 reinoud }
379 1.1 reinoud
380 1.1 reinoud
381 1.1 reinoud int
382 1.1 reinoud qmsintr(arg)
383 1.1 reinoud void *arg;
384 1.1 reinoud {
385 1.1 reinoud struct qms_softc *sc = arg;
386 1.1 reinoud int s;
387 1.1 reinoud struct mousebufrec buffer;
388 1.1 reinoud int dosignal=0;
389 1.1 reinoud
390 1.1 reinoud FMT_START
391 1.1 reinoud
392 1.1 reinoud b &= 0x70;
393 1.1 reinoud b >>= 4;
394 1.1 reinoud if (x != sc->lastx || y != sc->lasty || b != sc->lastb) {
395 1.1 reinoud /* Mouse state changed */
396 1.1 reinoud buffer.status = b | ( b ^ sc->lastb) << 3 | (((x==sc->lastx) && (y==sc->lasty))?0:MOVEMENT);
397 1.1 reinoud if(sc->sc_mode == MOUSEMODE_REL) {
398 1.1 reinoud sc->origx = sc->origy = 0;
399 1.1 reinoud bus_space_write_4(sc->sc_iot, sc->sc_ioh, QMS_MOUSEX, sc->origx);
400 1.1 reinoud bus_space_write_4(sc->sc_iot, sc->sc_ioh, QMS_MOUSEY, sc->origy);
401 1.1 reinoud }
402 1.1 reinoud buffer.x = x;
403 1.1 reinoud buffer.y = y;
404 1.1 reinoud microtime(&buffer.event_time);
405 1.1 reinoud
406 1.1 reinoud if (sc->sc_buffer.c_cc == 0)
407 1.1 reinoud dosignal = 1;
408 1.1 reinoud
409 1.1 reinoud s = spltty();
410 1.1 reinoud (void)b_to_q((char *)&buffer, sizeof(buffer), &sc->sc_buffer);
411 1.1 reinoud (void)splx(s);
412 1.1 reinoud selwakeup(&sc->sc_rsel);
413 1.1 reinoud
414 1.1 reinoud if (sc->sc_state & QMOUSE_ASLEEP) {
415 1.1 reinoud sc->sc_state &= ~QMOUSE_ASLEEP;
416 1.1 reinoud wakeup((caddr_t)sc);
417 1.1 reinoud }
418 1.1 reinoud
419 1.1 reinoud /* if (dosignal)*/
420 1.1 reinoud psignal(sc->sc_proc, SIGIO);
421 1.1 reinoud
422 1.1 reinoud sc->lastx = x;
423 1.1 reinoud sc->lasty = y;
424 1.1 reinoud sc->lastb = b;
425 1.1 reinoud }
426 1.1 reinoud
427 1.1 reinoud FMT_END
428 1.1 reinoud return(0); /* Pass interrupt on down the chain */
429 1.1 reinoud }
430 1.1 reinoud
431 1.1 reinoud
432 1.1 reinoud int
433 1.1 reinoud qmspoll(dev, events, p)
434 1.1 reinoud dev_t dev;
435 1.1 reinoud int events;
436 1.1 reinoud struct proc *p;
437 1.1 reinoud {
438 1.1 reinoud struct qms_softc *sc = qms_cd.cd_devs[minor(dev)];
439 1.1 reinoud int revents = 0;
440 1.1 reinoud int s = spltty();
441 1.1 reinoud
442 1.1 reinoud if (events & (POLLIN | POLLRDNORM)) {
443 1.1 reinoud if (sc->sc_buffer.c_cc > 0)
444 1.1 reinoud revents |= events & (POLLIN | POLLRDNORM);
445 1.1 reinoud else
446 1.1 reinoud selrecord(p, &sc->sc_rsel);
447 1.1 reinoud }
448 1.1 reinoud
449 1.1 reinoud (void)splx(s);
450 1.1 reinoud return (revents);
451 1.1 reinoud }
452 1.1 reinoud
453 1.1 reinoud
454 1.1 reinoud #ifdef MOUSE_IOC_ACK
455 1.1 reinoud static void
456 1.1 reinoud qmsputbuffer(sc, buffer)
457 1.1 reinoud struct qms_softc *sc;
458 1.1 reinoud struct mousebufrec *buffer;
459 1.1 reinoud {
460 1.1 reinoud int s;
461 1.1 reinoud int dosignal = 0;
462 1.1 reinoud
463 1.1 reinoud /* Time stamp the buffer */
464 1.1 reinoud microtime(&buffer->event_time);
465 1.1 reinoud
466 1.1 reinoud if (sc->sc_buffer.c_cc == 0)
467 1.1 reinoud dosignal=1;
468 1.1 reinoud
469 1.1 reinoud s = spltty();
470 1.1 reinoud (void)b_to_q((char *)buffer, sizeof(*buffer), &sc->sc_buffer);
471 1.1 reinoud (void)splx(s);
472 1.1 reinoud selwakeup(&sc->sc_rsel);
473 1.1 reinoud
474 1.1 reinoud if (sc->sc_state & QMOUSE_ASLEEP) {
475 1.1 reinoud sc->sc_state &= ~QMOUSE_ASLEEP;
476 1.1 reinoud wakeup((caddr_t)sc);
477 1.1 reinoud }
478 1.1 reinoud
479 1.1 reinoud if (dosignal)
480 1.1 reinoud psignal(sc->sc_proc, SIGIO);
481 1.1 reinoud }
482 1.1 reinoud #endif
483 1.3 jdolecek
484 1.3 jdolecek /* XXXLUKEM (jdolecek) kqueue hooks not tested */
485 1.3 jdolecek static void
486 1.3 jdolecek filt_qmsrdetach(struct knote *kn)
487 1.3 jdolecek {
488 1.3 jdolecek struct qms_softc *sc = kn->kn_hook;
489 1.3 jdolecek int s;
490 1.3 jdolecek
491 1.3 jdolecek s = spltty();
492 1.4 christos SLIST_REMOVE(&sc->sc_rsel.sel_klist, kn, knote, kn_selnext);
493 1.3 jdolecek splx(s);
494 1.3 jdolecek }
495 1.3 jdolecek
496 1.3 jdolecek static int
497 1.3 jdolecek filt_qmsread(struct knote *kn, long hint)
498 1.3 jdolecek {
499 1.3 jdolecek struct qms_softc *sc = kn->kn_hook;
500 1.3 jdolecek
501 1.3 jdolecek kn->kn_data = sc->sc_buffer.c_cc;
502 1.3 jdolecek return (kn->kn_data > 0);
503 1.3 jdolecek }
504 1.3 jdolecek
505 1.3 jdolecek static const struct filterops qmsread_filtops =
506 1.3 jdolecek { 1, NULL, filt_qmsrdetach, filt_qmsread };
507 1.3 jdolecek
508 1.3 jdolecek int
509 1.3 jdolecek qmskqfilter(dev_t dev, struct knote *kn)
510 1.3 jdolecek {
511 1.3 jdolecek struct qms_softc *sc = qms_cd.cd_devs[minor(dev)];
512 1.3 jdolecek struct klist *klist;
513 1.3 jdolecek int s;
514 1.3 jdolecek
515 1.3 jdolecek switch (kn->kn_filter) {
516 1.3 jdolecek case EVFILT_READ:
517 1.4 christos klist = &sc->sc_rsel.sel_klist;
518 1.3 jdolecek kn->kn_fop = &qmsread_filtops;
519 1.3 jdolecek break;
520 1.3 jdolecek
521 1.3 jdolecek default:
522 1.3 jdolecek return (1);
523 1.3 jdolecek }
524 1.3 jdolecek
525 1.3 jdolecek kn->kn_hook = sc;
526 1.3 jdolecek
527 1.3 jdolecek s = spltty();
528 1.3 jdolecek SLIST_INSERT_HEAD(klist, kn, kn_selnext);
529 1.3 jdolecek splx(s);
530 1.3 jdolecek
531 1.3 jdolecek return (0);
532 1.3 jdolecek }
533 1.1 reinoud
534 1.1 reinoud /* End of qms.c */
535