ms.c revision 1.25.2.1 1 1.25.2.1 skrll /* $NetBSD: ms.c,v 1.25.2.1 2004/08/03 10:31:54 skrll Exp $ */
2 1.5 cgd
3 1.1 mw /*
4 1.1 mw * based on:
5 1.1 mw *
6 1.1 mw * Copyright (c) 1992, 1993
7 1.1 mw * The Regents of the University of California. All rights reserved.
8 1.1 mw *
9 1.1 mw * This software was developed by the Computer Systems Engineering group
10 1.1 mw * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
11 1.1 mw * contributed to Berkeley.
12 1.1 mw *
13 1.1 mw * All advertising materials mentioning features or use of this software
14 1.1 mw * must display the following acknowledgement:
15 1.1 mw * This product includes software developed by the University of
16 1.1 mw * California, Lawrence Berkeley Laboratory.
17 1.1 mw *
18 1.1 mw * Redistribution and use in source and binary forms, with or without
19 1.1 mw * modification, are permitted provided that the following conditions
20 1.1 mw * are met:
21 1.1 mw * 1. Redistributions of source code must retain the above copyright
22 1.1 mw * notice, this list of conditions and the following disclaimer.
23 1.1 mw * 2. Redistributions in binary form must reproduce the above copyright
24 1.1 mw * notice, this list of conditions and the following disclaimer in the
25 1.1 mw * documentation and/or other materials provided with the distribution.
26 1.25.2.1 skrll * 3. Neither the name of the University nor the names of its contributors
27 1.1 mw * may be used to endorse or promote products derived from this software
28 1.1 mw * without specific prior written permission.
29 1.1 mw *
30 1.1 mw * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
31 1.1 mw * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32 1.1 mw * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 1.1 mw * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
34 1.1 mw * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35 1.1 mw * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36 1.1 mw * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37 1.1 mw * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38 1.1 mw * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
39 1.1 mw * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 1.1 mw * SUCH DAMAGE.
41 1.1 mw *
42 1.1 mw * @(#)ms.c 8.1 (Berkeley) 6/11/93
43 1.1 mw *
44 1.5 cgd * Header: ms.c,v 1.5 92/11/26 01:28:47 torek Exp (LBL)
45 1.1 mw */
46 1.20 aymeric
47 1.20 aymeric #include <sys/cdefs.h>
48 1.25.2.1 skrll __KERNEL_RCSID(0, "$NetBSD: ms.c,v 1.25.2.1 2004/08/03 10:31:54 skrll Exp $");
49 1.1 mw
50 1.1 mw /*
51 1.1 mw * Mouse driver.
52 1.25.2.1 skrll *
53 1.25.2.1 skrll * wscons aware. Attaches two wsmouse devices, one for each port.
54 1.25.2.1 skrll * Also still exports its own device entry points so it is possible
55 1.25.2.1 skrll * to open this and read firm_events.
56 1.25.2.1 skrll * The events go only to one place at a time:
57 1.25.2.1 skrll * - When somebody has opened a ms device directly wsmouse cannot be activated.
58 1.25.2.1 skrll * (when wsmouse is opened it calls ms_enable to activate)
59 1.25.2.1 skrll * - When feeding events to wsmouse open of ms device will fail.
60 1.1 mw */
61 1.1 mw
62 1.25.2.1 skrll #include "wsmouse.h"
63 1.25.2.1 skrll
64 1.2 chopps #include <sys/param.h>
65 1.9 is #include <sys/device.h>
66 1.2 chopps #include <sys/ioctl.h>
67 1.2 chopps #include <sys/kernel.h>
68 1.2 chopps #include <sys/proc.h>
69 1.2 chopps #include <sys/syslog.h>
70 1.2 chopps #include <sys/systm.h>
71 1.16 thorpej #include <sys/callout.h>
72 1.2 chopps #include <sys/tty.h>
73 1.8 veego #include <sys/signalvar.h>
74 1.21 gehenna #include <sys/conf.h>
75 1.1 mw
76 1.2 chopps #include <amiga/dev/event_var.h>
77 1.2 chopps #include <amiga/dev/vuid_event.h>
78 1.1 mw
79 1.2 chopps #include <amiga/amiga/custom.h>
80 1.2 chopps #include <amiga/amiga/cia.h>
81 1.9 is #include <amiga/amiga/device.h>
82 1.1 mw
83 1.25.2.1 skrll #if NWSMOUSE > 0
84 1.25.2.1 skrll #include <dev/wscons/wsmousevar.h>
85 1.25.2.1 skrll #include <dev/wscons/wsconsio.h>
86 1.25.2.1 skrll #endif
87 1.25.2.1 skrll
88 1.19 aymeric void msattach(struct device *, struct device *, void *);
89 1.19 aymeric int msmatch(struct device *, struct cfdata *, void *);
90 1.1 mw
91 1.17 kleink /* per-port state */
92 1.17 kleink struct ms_port {
93 1.17 kleink int ms_portno; /* which hardware port, for msintr() */
94 1.9 is
95 1.17 kleink struct callout ms_intr_ch;
96 1.16 thorpej
97 1.9 is u_char ms_horc; /* horizontal counter on last scan */
98 1.9 is u_char ms_verc; /* vertical counter on last scan */
99 1.9 is char ms_mb; /* mouse button state */
100 1.9 is char ms_ub; /* user button state */
101 1.9 is int ms_dx; /* delta-x */
102 1.9 is int ms_dy; /* delta-y */
103 1.9 is volatile int ms_ready; /* event queue is ready */
104 1.9 is struct evvar ms_events; /* event queue state */
105 1.25.2.1 skrll #if NWSMOUSE > 0
106 1.25.2.1 skrll struct device *ms_wsmousedev; /* wsmouse device */
107 1.25.2.1 skrll int ms_wsenabled; /* feeding events to wscons */
108 1.25.2.1 skrll #endif
109 1.9 is };
110 1.9 is
111 1.17 kleink #define MS_NPORTS 2
112 1.17 kleink
113 1.17 kleink struct ms_softc {
114 1.17 kleink struct device sc_dev; /* base device */
115 1.17 kleink struct ms_port sc_ports[MS_NPORTS];
116 1.17 kleink };
117 1.17 kleink
118 1.23 thorpej CFATTACH_DECL(ms, sizeof(struct ms_softc),
119 1.23 thorpej msmatch, msattach, NULL, NULL);
120 1.9 is
121 1.19 aymeric void msintr(void *);
122 1.19 aymeric void ms_enable(struct ms_port *);
123 1.19 aymeric void ms_disable(struct ms_port *);
124 1.17 kleink
125 1.15 thorpej extern struct cfdriver ms_cd;
126 1.21 gehenna
127 1.21 gehenna dev_type_open(msopen);
128 1.21 gehenna dev_type_close(msclose);
129 1.21 gehenna dev_type_read(msread);
130 1.21 gehenna dev_type_ioctl(msioctl);
131 1.21 gehenna dev_type_poll(mspoll);
132 1.24 jdolecek dev_type_kqfilter(mskqfilter);
133 1.21 gehenna
134 1.21 gehenna const struct cdevsw ms_cdevsw = {
135 1.21 gehenna msopen, msclose, msread, nowrite, msioctl,
136 1.24 jdolecek nostop, notty, mspoll, nommap, mskqfilter,
137 1.21 gehenna };
138 1.1 mw
139 1.17 kleink #define MS_UNIT(d) ((minor(d) & ~0x1) >> 1)
140 1.17 kleink #define MS_PORT(d) (minor(d) & 0x1)
141 1.17 kleink
142 1.17 kleink /*
143 1.17 kleink * Given a dev_t, return a pointer to the port's hardware state.
144 1.25 perry * Assumes the unit to be valid, so do *not* use this in msopen().
145 1.17 kleink */
146 1.17 kleink #define MS_DEV2MSPORT(d) \
147 1.17 kleink (&(((struct ms_softc *)getsoftc(ms_cd, MS_UNIT(d)))->sc_ports[MS_PORT(d)]))
148 1.17 kleink
149 1.25.2.1 skrll #if NWSMOUSE > 0
150 1.25.2.1 skrll /*
151 1.25.2.1 skrll * Callbacks for wscons.
152 1.25.2.1 skrll */
153 1.25.2.1 skrll static int ms_wscons_enable(void *);
154 1.25.2.1 skrll static int ms_wscons_ioctl(void *, u_long, caddr_t, int, struct proc *);
155 1.25.2.1 skrll static void ms_wscons_disable(void *);
156 1.25.2.1 skrll
157 1.25.2.1 skrll static struct wsmouse_accessops ms_wscons_accessops = {
158 1.25.2.1 skrll ms_wscons_enable,
159 1.25.2.1 skrll ms_wscons_ioctl,
160 1.25.2.1 skrll ms_wscons_disable
161 1.25.2.1 skrll };
162 1.25.2.1 skrll #endif
163 1.25.2.1 skrll
164 1.3 chopps int
165 1.19 aymeric msmatch(struct device *pdp, struct cfdata *cfp, void *auxp)
166 1.3 chopps {
167 1.17 kleink static int ms_matched = 0;
168 1.9 is
169 1.17 kleink /* Allow only one instance. */
170 1.17 kleink if (!matchname((char *)auxp, "ms") || ms_matched)
171 1.17 kleink return 0;
172 1.9 is
173 1.17 kleink ms_matched = 1;
174 1.17 kleink return 1;
175 1.3 chopps }
176 1.1 mw
177 1.9 is void
178 1.19 aymeric msattach(struct device *pdp, struct device *dp, void *auxp)
179 1.9 is {
180 1.25.2.1 skrll #if NWSMOUSE > 0
181 1.25.2.1 skrll struct wsmousedev_attach_args waa;
182 1.25.2.1 skrll #endif
183 1.16 thorpej struct ms_softc *sc = (void *) dp;
184 1.17 kleink int i;
185 1.16 thorpej
186 1.13 christos printf("\n");
187 1.17 kleink for (i = 0; i < MS_NPORTS; i++) {
188 1.17 kleink sc->sc_ports[i].ms_portno = i;
189 1.17 kleink callout_init(&sc->sc_ports[i].ms_intr_ch);
190 1.25.2.1 skrll #if NWSMOUSE > 0
191 1.25.2.1 skrll waa.accessops = &ms_wscons_accessops;
192 1.25.2.1 skrll waa.accesscookie = &sc->sc_ports[i];
193 1.25.2.1 skrll
194 1.25.2.1 skrll sc->sc_ports[i].ms_wsenabled = 0;
195 1.25.2.1 skrll sc->sc_ports[i].ms_wsmousedev =
196 1.25.2.1 skrll config_found(dp, &waa, wsmousedevprint);
197 1.25.2.1 skrll #endif
198 1.17 kleink }
199 1.9 is }
200 1.9 is
201 1.3 chopps /*
202 1.3 chopps * Amiga mice are hooked up to one of the two "game" ports, where
203 1.3 chopps * the main mouse is usually on the first port, and port 2 can
204 1.3 chopps * be used by a joystick. Nevertheless, we support two mouse
205 1.3 chopps * devices, /dev/mouse0 and /dev/mouse1 (with a link of /dev/mouse to
206 1.3 chopps * the device that represents the port of the mouse in use).
207 1.3 chopps */
208 1.1 mw
209 1.3 chopps /*
210 1.17 kleink * enable scanner, called when someone opens the port.
211 1.3 chopps */
212 1.1 mw void
213 1.19 aymeric ms_enable(struct ms_port *ms)
214 1.1 mw {
215 1.10 is
216 1.19 aymeric /*
217 1.3 chopps * use this as flag to the "interrupt" to tell it when to
218 1.3 chopps * shut off (when it's reset to 0).
219 1.3 chopps */
220 1.3 chopps ms->ms_ready = 1;
221 1.1 mw
222 1.17 kleink callout_reset(&ms->ms_intr_ch, 2, msintr, ms);
223 1.1 mw }
224 1.1 mw
225 1.3 chopps /*
226 1.3 chopps * disable scanner. Just set ms_ready to 0, and after the next
227 1.3 chopps * timeout taken, no further timeouts will be initiated.
228 1.3 chopps */
229 1.1 mw void
230 1.19 aymeric ms_disable(struct ms_port *ms)
231 1.1 mw {
232 1.3 chopps int s;
233 1.1 mw
234 1.3 chopps s = splhigh ();
235 1.3 chopps ms->ms_ready = 0;
236 1.3 chopps /*
237 1.3 chopps * sync with the interrupt
238 1.3 chopps */
239 1.3 chopps tsleep(ms, PZERO - 1, "mouse-disable", 0);
240 1.3 chopps splx(s);
241 1.1 mw }
242 1.1 mw
243 1.1 mw
244 1.19 aymeric /*
245 1.3 chopps * we're emulating a mousesystems serial mouse here..
246 1.3 chopps */
247 1.1 mw void
248 1.19 aymeric msintr(void *arg)
249 1.1 mw {
250 1.3 chopps static const char to_one[] = { 1, 2, 2, 4, 4, 4, 4 };
251 1.3 chopps static const int to_id[] = { MS_RIGHT, MS_MIDDLE, 0, MS_LEFT };
252 1.17 kleink struct ms_port *ms = arg;
253 1.3 chopps struct firm_event *fe;
254 1.17 kleink int mb, ub, d, get, put, any, port;
255 1.3 chopps u_char pra, *horc, *verc;
256 1.3 chopps u_short pot, count;
257 1.3 chopps short dx, dy;
258 1.19 aymeric
259 1.17 kleink port = ms->ms_portno;
260 1.10 is
261 1.3 chopps horc = ((u_char *) &count) + 1;
262 1.3 chopps verc = (u_char *) &count;
263 1.3 chopps
264 1.3 chopps /*
265 1.3 chopps * first read the three buttons.
266 1.3 chopps */
267 1.3 chopps pot = custom.potgor;
268 1.3 chopps pra = ciaa.pra;
269 1.17 kleink pot >>= port == 0 ? 8 : 12; /* contains right and middle button */
270 1.17 kleink pra >>= port == 0 ? 6 : 7; /* contains left button */
271 1.3 chopps mb = (pot & 4) / 4 + (pot & 1) * 2 + (pra & 1) * 4;
272 1.3 chopps mb ^= 0x07;
273 1.3 chopps
274 1.3 chopps /*
275 1.3 chopps * read current values of counter registers
276 1.3 chopps */
277 1.17 kleink if (port == 0)
278 1.3 chopps count = custom.joy0dat;
279 1.3 chopps else
280 1.3 chopps count = custom.joy1dat;
281 1.19 aymeric
282 1.3 chopps /*
283 1.3 chopps * take care of wraparound
284 1.3 chopps */
285 1.3 chopps dx = *horc - ms->ms_horc;
286 1.3 chopps if (dx < -127)
287 1.3 chopps dx += 255;
288 1.3 chopps else if (dx > 127)
289 1.3 chopps dx -= 255;
290 1.3 chopps dy = *verc - ms->ms_verc;
291 1.3 chopps if (dy < -127)
292 1.3 chopps dy += 255;
293 1.3 chopps else if (dy > 127)
294 1.3 chopps dy -= 255;
295 1.3 chopps
296 1.3 chopps /*
297 1.3 chopps * remember current values for next scan
298 1.3 chopps */
299 1.3 chopps ms->ms_horc = *horc;
300 1.3 chopps ms->ms_verc = *verc;
301 1.3 chopps
302 1.3 chopps ms->ms_dx = dx;
303 1.3 chopps ms->ms_dy = dy;
304 1.3 chopps ms->ms_mb = mb;
305 1.19 aymeric
306 1.25.2.1 skrll #if NWSMOUSE > 0
307 1.25.2.1 skrll /*
308 1.25.2.1 skrll * If we have attached wsmouse and we are not opened
309 1.25.2.1 skrll * directly then pass events to wscons.
310 1.25.2.1 skrll */
311 1.25.2.1 skrll if (ms->ms_wsmousedev && ms->ms_wsenabled)
312 1.25.2.1 skrll {
313 1.25.2.1 skrll int buttons = 0;
314 1.25.2.1 skrll
315 1.25.2.1 skrll if (mb & 4)
316 1.25.2.1 skrll buttons |= 1;
317 1.25.2.1 skrll if (mb & 2)
318 1.25.2.1 skrll buttons |= 2;
319 1.25.2.1 skrll if (mb & 1)
320 1.25.2.1 skrll buttons |= 4;
321 1.25.2.1 skrll
322 1.25.2.1 skrll wsmouse_input(ms->ms_wsmousedev,
323 1.25.2.1 skrll buttons,
324 1.25.2.1 skrll dx,
325 1.25.2.1 skrll -dy,
326 1.25.2.1 skrll 0,
327 1.25.2.1 skrll WSMOUSE_INPUT_DELTA);
328 1.25.2.1 skrll
329 1.25.2.1 skrll } else
330 1.25.2.1 skrll #endif
331 1.3 chopps if (dx || dy || ms->ms_ub != ms->ms_mb) {
332 1.3 chopps /*
333 1.3 chopps * We have at least one event (mouse button, delta-X, or
334 1.3 chopps * delta-Y; possibly all three, and possibly three separate
335 1.3 chopps * button events). Deliver these events until we are out of
336 1.19 aymeric * changes or out of room. As events get delivered, mark them
337 1.3 chopps * `unchanged'.
338 1.3 chopps */
339 1.3 chopps any = 0;
340 1.3 chopps get = ms->ms_events.ev_get;
341 1.3 chopps put = ms->ms_events.ev_put;
342 1.3 chopps fe = &ms->ms_events.ev_q[put];
343 1.3 chopps
344 1.3 chopps mb = ms->ms_mb;
345 1.3 chopps ub = ms->ms_ub;
346 1.3 chopps while ((d = mb ^ ub) != 0) {
347 1.3 chopps /*
348 1.3 chopps * Mouse button change. Convert up to three changes
349 1.3 chopps * to the `first' change, and drop it into the event
350 1.3 chopps * queue.
351 1.3 chopps */
352 1.3 chopps if ((++put) % EV_QSIZE == get) {
353 1.3 chopps put--;
354 1.3 chopps goto out;
355 1.3 chopps }
356 1.3 chopps
357 1.3 chopps d = to_one[d - 1]; /* from 1..7 to {1,2,4} */
358 1.3 chopps fe->id = to_id[d - 1]; /* from {1,2,4} to ID */
359 1.3 chopps fe->value = mb & d ? VKEY_DOWN : VKEY_UP;
360 1.3 chopps fe->time = time;
361 1.3 chopps fe++;
362 1.3 chopps
363 1.3 chopps if (put >= EV_QSIZE) {
364 1.3 chopps put = 0;
365 1.3 chopps fe = &ms->ms_events.ev_q[0];
366 1.3 chopps }
367 1.3 chopps any = 1;
368 1.3 chopps
369 1.3 chopps ub ^= d;
370 1.3 chopps }
371 1.3 chopps if (ms->ms_dx) {
372 1.3 chopps if ((++put) % EV_QSIZE == get) {
373 1.3 chopps put--;
374 1.3 chopps goto out;
375 1.3 chopps }
376 1.3 chopps
377 1.3 chopps fe->id = LOC_X_DELTA;
378 1.3 chopps fe->value = ms->ms_dx;
379 1.3 chopps fe->time = time;
380 1.4 chopps fe++;
381 1.3 chopps
382 1.3 chopps if (put >= EV_QSIZE) {
383 1.3 chopps put = 0;
384 1.3 chopps fe = &ms->ms_events.ev_q[0];
385 1.3 chopps }
386 1.3 chopps any = 1;
387 1.3 chopps
388 1.3 chopps ms->ms_dx = 0;
389 1.3 chopps }
390 1.3 chopps if (ms->ms_dy) {
391 1.3 chopps if ((++put) % EV_QSIZE == get) {
392 1.3 chopps put--;
393 1.3 chopps goto out;
394 1.3 chopps }
395 1.3 chopps
396 1.3 chopps fe->id = LOC_Y_DELTA;
397 1.3 chopps fe->value = ms->ms_dy;
398 1.3 chopps fe->time = time;
399 1.4 chopps fe++;
400 1.3 chopps
401 1.3 chopps if (put >= EV_QSIZE) {
402 1.3 chopps put = 0;
403 1.3 chopps fe = &ms->ms_events.ev_q[0];
404 1.3 chopps }
405 1.3 chopps any = 1;
406 1.1 mw
407 1.3 chopps ms->ms_dy = 0;
408 1.3 chopps }
409 1.1 mw out:
410 1.3 chopps if (any) {
411 1.3 chopps ms->ms_ub = ub;
412 1.3 chopps ms->ms_events.ev_put = put;
413 1.3 chopps EV_WAKEUP(&ms->ms_events);
414 1.3 chopps }
415 1.1 mw }
416 1.1 mw
417 1.3 chopps /*
418 1.3 chopps * reschedule handler, or if terminating,
419 1.3 chopps * handshake with ms_disable
420 1.3 chopps */
421 1.3 chopps if (ms->ms_ready)
422 1.17 kleink callout_reset(&ms->ms_intr_ch, 2, msintr, ms);
423 1.3 chopps else
424 1.3 chopps wakeup(ms);
425 1.1 mw }
426 1.1 mw
427 1.1 mw int
428 1.19 aymeric msopen(dev_t dev, int flags, int mode, struct proc *p)
429 1.1 mw {
430 1.17 kleink struct ms_softc *sc;
431 1.17 kleink struct ms_port *ms;
432 1.17 kleink int unit, port;
433 1.3 chopps
434 1.17 kleink unit = MS_UNIT(dev);
435 1.17 kleink sc = (struct ms_softc *)getsoftc(ms_cd, unit);
436 1.3 chopps
437 1.17 kleink if (sc == NULL)
438 1.3 chopps return(EXDEV);
439 1.3 chopps
440 1.17 kleink port = MS_PORT(dev);
441 1.17 kleink ms = &sc->sc_ports[port];
442 1.17 kleink
443 1.3 chopps if (ms->ms_events.ev_io)
444 1.3 chopps return(EBUSY);
445 1.18 is
446 1.25.2.1 skrll #if NWSMOUSE > 0
447 1.25.2.1 skrll /* don't allow opening when sending events to wsmouse */
448 1.25.2.1 skrll if (ms->ms_wsenabled)
449 1.25.2.1 skrll return EBUSY;
450 1.25.2.1 skrll #endif
451 1.18 is /* initialize potgo bits for mouse mode */
452 1.18 is custom.potgo = custom.potgor | (0xf00 << (port * 4));
453 1.3 chopps
454 1.3 chopps ms->ms_events.ev_io = p;
455 1.3 chopps ev_init(&ms->ms_events); /* may cause sleep */
456 1.17 kleink ms_enable(ms);
457 1.3 chopps return(0);
458 1.1 mw }
459 1.1 mw
460 1.1 mw int
461 1.19 aymeric msclose(dev_t dev, int flags, int mode, struct proc *p)
462 1.1 mw {
463 1.17 kleink struct ms_port *ms;
464 1.1 mw
465 1.17 kleink ms = MS_DEV2MSPORT(dev);
466 1.3 chopps
467 1.17 kleink ms_disable(ms);
468 1.3 chopps ev_fini(&ms->ms_events);
469 1.3 chopps ms->ms_events.ev_io = NULL;
470 1.3 chopps return(0);
471 1.1 mw }
472 1.1 mw
473 1.1 mw int
474 1.19 aymeric msread(dev_t dev, struct uio *uio, int flags)
475 1.1 mw {
476 1.17 kleink struct ms_port *ms;
477 1.1 mw
478 1.17 kleink ms = MS_DEV2MSPORT(dev);
479 1.10 is
480 1.3 chopps return(ev_read(&ms->ms_events, uio, flags));
481 1.1 mw }
482 1.1 mw
483 1.1 mw int
484 1.19 aymeric msioctl(dev_t dev, u_long cmd, register caddr_t data, int flag,
485 1.19 aymeric struct proc *p)
486 1.1 mw {
487 1.17 kleink struct ms_port *ms;
488 1.1 mw
489 1.17 kleink ms = MS_DEV2MSPORT(dev);
490 1.1 mw
491 1.3 chopps switch (cmd) {
492 1.3 chopps case FIONBIO: /* we will remove this someday (soon???) */
493 1.3 chopps return(0);
494 1.3 chopps case FIOASYNC:
495 1.3 chopps ms->ms_events.ev_async = *(int *)data != 0;
496 1.3 chopps return(0);
497 1.25.2.1 skrll case FIOSETOWN:
498 1.25.2.1 skrll if (-*(int *)data != ms->ms_events.ev_io->p_pgid
499 1.25.2.1 skrll && *(int *)data != ms->ms_events.ev_io->p_pid)
500 1.25.2.1 skrll return(EPERM);
501 1.25.2.1 skrll return(0);
502 1.3 chopps case TIOCSPGRP:
503 1.3 chopps if (*(int *)data != ms->ms_events.ev_io->p_pgid)
504 1.3 chopps return(EPERM);
505 1.3 chopps return(0);
506 1.3 chopps case VUIDGFORMAT: /* we only do firm_events */
507 1.3 chopps *(int *)data = VUID_FIRM_EVENT;
508 1.3 chopps return(0);
509 1.3 chopps case VUIDSFORMAT:
510 1.3 chopps if (*(int *)data != VUID_FIRM_EVENT)
511 1.3 chopps return(EINVAL);
512 1.3 chopps return(0);
513 1.3 chopps }
514 1.3 chopps return(ENOTTY);
515 1.1 mw }
516 1.1 mw
517 1.1 mw int
518 1.19 aymeric mspoll(dev_t dev, int events, struct proc *p)
519 1.1 mw {
520 1.17 kleink struct ms_port *ms;
521 1.1 mw
522 1.17 kleink ms = MS_DEV2MSPORT(dev);
523 1.10 is
524 1.12 mhitch return(ev_poll(&ms->ms_events, events, p));
525 1.24 jdolecek }
526 1.24 jdolecek
527 1.24 jdolecek int
528 1.24 jdolecek mskqfilter(dev, kn)
529 1.24 jdolecek dev_t dev;
530 1.24 jdolecek struct knote *kn;
531 1.24 jdolecek {
532 1.24 jdolecek struct ms_port *ms;
533 1.24 jdolecek
534 1.24 jdolecek ms = MS_DEV2MSPORT(dev);
535 1.24 jdolecek
536 1.24 jdolecek return (ev_kqfilter(&ms->ms_events, kn));
537 1.1 mw }
538 1.25.2.1 skrll
539 1.25.2.1 skrll #if NWSMOUSE > 0
540 1.25.2.1 skrll
541 1.25.2.1 skrll static int
542 1.25.2.1 skrll ms_wscons_ioctl(void *cookie, u_long cmd, caddr_t data, int flag,
543 1.25.2.1 skrll struct proc *p)
544 1.25.2.1 skrll {
545 1.25.2.1 skrll switch(cmd) {
546 1.25.2.1 skrll case WSMOUSEIO_GTYPE:
547 1.25.2.1 skrll *(u_int*)data = WSMOUSE_TYPE_AMIGA;
548 1.25.2.1 skrll return (0);
549 1.25.2.1 skrll }
550 1.25.2.1 skrll
551 1.25.2.1 skrll return -1;
552 1.25.2.1 skrll }
553 1.25.2.1 skrll
554 1.25.2.1 skrll static int
555 1.25.2.1 skrll ms_wscons_enable(void *cookie)
556 1.25.2.1 skrll {
557 1.25.2.1 skrll struct ms_port *port = cookie;
558 1.25.2.1 skrll
559 1.25.2.1 skrll /* somebody reading events from us directly? */
560 1.25.2.1 skrll if (port->ms_events.ev_io)
561 1.25.2.1 skrll return EBUSY;
562 1.25.2.1 skrll
563 1.25.2.1 skrll port->ms_wsenabled = 1;
564 1.25.2.1 skrll ms_enable(port);
565 1.25.2.1 skrll
566 1.25.2.1 skrll return 0;
567 1.25.2.1 skrll }
568 1.25.2.1 skrll
569 1.25.2.1 skrll static void
570 1.25.2.1 skrll ms_wscons_disable(void *cookie)
571 1.25.2.1 skrll {
572 1.25.2.1 skrll struct ms_port *port = cookie;
573 1.25.2.1 skrll
574 1.25.2.1 skrll if (port->ms_wsenabled)
575 1.25.2.1 skrll ms_disable(port);
576 1.25.2.1 skrll port->ms_wsenabled = 0;
577 1.25.2.1 skrll }
578 1.25.2.1 skrll
579 1.25.2.1 skrll #endif
580 1.25.2.1 skrll
581