xref: /netbsd-src/sys/dev/wscons/wsevent_50.c (revision 8a031a1d1e0aac23d43015c71ae6350b917c8347)
1*8a031a1dSpgoyette /* $NetBSD: wsevent_50.c,v 1.5 2019/12/12 02:15:43 pgoyette Exp $ */
2d91f98a8Spgoyette 
3d91f98a8Spgoyette /*-
4d91f98a8Spgoyette  * Copyright (c) 2006, 2008 The NetBSD Foundation, Inc.
5d91f98a8Spgoyette  * All rights reserved.
6d91f98a8Spgoyette  *
7d91f98a8Spgoyette  * This code is derived from software contributed to The NetBSD Foundation
8d91f98a8Spgoyette  * by Julio M. Merino Vidal.
9d91f98a8Spgoyette  *
10d91f98a8Spgoyette  * Redistribution and use in source and binary forms, with or without
11d91f98a8Spgoyette  * modification, are permitted provided that the following conditions
12d91f98a8Spgoyette  * are met:
13d91f98a8Spgoyette  * 1. Redistributions of source code must retain the above copyright
14d91f98a8Spgoyette  *    notice, this list of conditions and the following disclaimer.
15d91f98a8Spgoyette  * 2. Redistributions in binary form must reproduce the above copyright
16d91f98a8Spgoyette  *    notice, this list of conditions and the following disclaimer in the
17d91f98a8Spgoyette  *    documentation and/or other materials provided with the distribution.
18d91f98a8Spgoyette  *
19d91f98a8Spgoyette  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20d91f98a8Spgoyette  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21d91f98a8Spgoyette  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22d91f98a8Spgoyette  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23d91f98a8Spgoyette  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24d91f98a8Spgoyette  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25d91f98a8Spgoyette  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26d91f98a8Spgoyette  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27d91f98a8Spgoyette  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28d91f98a8Spgoyette  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29d91f98a8Spgoyette  * POSSIBILITY OF SUCH DAMAGE.
30d91f98a8Spgoyette  */
31d91f98a8Spgoyette 
32d91f98a8Spgoyette /*
33d91f98a8Spgoyette  * Copyright (c) 1996, 1997 Christopher G. Demetriou.  All rights reserved.
34d91f98a8Spgoyette  *
35d91f98a8Spgoyette  * Redistribution and use in source and binary forms, with or without
36d91f98a8Spgoyette  * modification, are permitted provided that the following conditions
37d91f98a8Spgoyette  * are met:
38d91f98a8Spgoyette  * 1. Redistributions of source code must retain the above copyright
39d91f98a8Spgoyette  *    notice, this list of conditions and the following disclaimer.
40d91f98a8Spgoyette  * 2. Redistributions in binary form must reproduce the above copyright
41d91f98a8Spgoyette  *    notice, this list of conditions and the following disclaimer in the
42d91f98a8Spgoyette  *    documentation and/or other materials provided with the distribution.
43d91f98a8Spgoyette  * 3. All advertising materials mentioning features or use of this software
44d91f98a8Spgoyette  *    must display the following acknowledgement:
45d91f98a8Spgoyette  *      This product includes software developed by Christopher G. Demetriou
46d91f98a8Spgoyette  *	for the NetBSD Project.
47d91f98a8Spgoyette  * 4. The name of the author may not be used to endorse or promote products
48d91f98a8Spgoyette  *    derived from this software without specific prior written permission
49d91f98a8Spgoyette  *
50d91f98a8Spgoyette  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
51d91f98a8Spgoyette  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
52d91f98a8Spgoyette  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
53d91f98a8Spgoyette  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
54d91f98a8Spgoyette  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
55d91f98a8Spgoyette  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
56d91f98a8Spgoyette  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
57d91f98a8Spgoyette  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
58d91f98a8Spgoyette  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
59d91f98a8Spgoyette  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
60d91f98a8Spgoyette  */
61d91f98a8Spgoyette 
62d91f98a8Spgoyette /*
63d91f98a8Spgoyette  * Copyright (c) 1992, 1993
64d91f98a8Spgoyette  *	The Regents of the University of California.  All rights reserved.
65d91f98a8Spgoyette  *
66d91f98a8Spgoyette  * This software was developed by the Computer Systems Engineering group
67d91f98a8Spgoyette  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
68d91f98a8Spgoyette  * contributed to Berkeley.
69d91f98a8Spgoyette  *
70d91f98a8Spgoyette  * All advertising materials mentioning features or use of this software
71d91f98a8Spgoyette  * must display the following acknowledgement:
72d91f98a8Spgoyette  *	This product includes software developed by the University of
73d91f98a8Spgoyette  *	California, Lawrence Berkeley Laboratory.
74d91f98a8Spgoyette  *
75d91f98a8Spgoyette  * Redistribution and use in source and binary forms, with or without
76d91f98a8Spgoyette  * modification, are permitted provided that the following conditions
77d91f98a8Spgoyette  * are met:
78d91f98a8Spgoyette  * 1. Redistributions of source code must retain the above copyright
79d91f98a8Spgoyette  *    notice, this list of conditions and the following disclaimer.
80d91f98a8Spgoyette  * 2. Redistributions in binary form must reproduce the above copyright
81d91f98a8Spgoyette  *    notice, this list of conditions and the following disclaimer in the
82d91f98a8Spgoyette  *    documentation and/or other materials provided with the distribution.
83d91f98a8Spgoyette  * 3. Neither the name of the University nor the names of its contributors
84d91f98a8Spgoyette  *    may be used to endorse or promote products derived from this software
85d91f98a8Spgoyette  *    without specific prior written permission.
86d91f98a8Spgoyette  *
87d91f98a8Spgoyette  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
88d91f98a8Spgoyette  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
89d91f98a8Spgoyette  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
90d91f98a8Spgoyette  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
91d91f98a8Spgoyette  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
92d91f98a8Spgoyette  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
93d91f98a8Spgoyette  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
94d91f98a8Spgoyette  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
95d91f98a8Spgoyette  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
96d91f98a8Spgoyette  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
97d91f98a8Spgoyette  * SUCH DAMAGE.
98d91f98a8Spgoyette  *
99d91f98a8Spgoyette  *	@(#)event.c	8.1 (Berkeley) 6/11/93
100d91f98a8Spgoyette  */
101d91f98a8Spgoyette 
102d91f98a8Spgoyette /*
103d91f98a8Spgoyette  * Internal "wscons_event" queue interface for the keyboard and mouse drivers.
104d91f98a8Spgoyette  */
105d91f98a8Spgoyette 
106d91f98a8Spgoyette #include <sys/cdefs.h>
107*8a031a1dSpgoyette __KERNEL_RCSID(0, "$NetBSD: wsevent_50.c,v 1.5 2019/12/12 02:15:43 pgoyette Exp $");
108d91f98a8Spgoyette 
109d91f98a8Spgoyette #include <sys/param.h>
110d91f98a8Spgoyette #include <sys/kernel.h>
111d91f98a8Spgoyette #include <sys/fcntl.h>
112d91f98a8Spgoyette #include <sys/kmem.h>
113d91f98a8Spgoyette #include <sys/proc.h>
114d91f98a8Spgoyette #include <sys/systm.h>
115d91f98a8Spgoyette #include <sys/vnode.h>
116d91f98a8Spgoyette #include <sys/select.h>
117d91f98a8Spgoyette #include <sys/poll.h>
118d91f98a8Spgoyette #include <sys/compat_stub.h>
119d91f98a8Spgoyette 
120d91f98a8Spgoyette #include <dev/wscons/wsconsio.h>
121d91f98a8Spgoyette #include <dev/wscons/wseventvar.h>
122d91f98a8Spgoyette #include <dev/wscons/wsevent_50.h>
123d91f98a8Spgoyette 
124d91f98a8Spgoyette static int
wsevent_copyout_events50(const struct wscons_event * events,int cnt,struct uio * uio)125d91f98a8Spgoyette wsevent_copyout_events50(const struct wscons_event *events, int cnt,
126d91f98a8Spgoyette     struct uio *uio)
127d91f98a8Spgoyette {
128d91f98a8Spgoyette 	int i;
129d91f98a8Spgoyette 
130d91f98a8Spgoyette 	for (i = 0; i < cnt; i++) {
131d91f98a8Spgoyette 		const struct wscons_event *ev = &events[i];
132d91f98a8Spgoyette 		struct owscons_event ev50;
133d91f98a8Spgoyette 		int error;
134d91f98a8Spgoyette 
135d91f98a8Spgoyette 		ev50.type = ev->type;
136d91f98a8Spgoyette 		ev50.value = ev->value;
137d91f98a8Spgoyette 		timespec_to_timespec50(&ev->time, &ev50.time);
138d91f98a8Spgoyette 
139d91f98a8Spgoyette 		error = uiomove(&ev50, sizeof(ev50), uio);
140d91f98a8Spgoyette 		if (error) {
141d91f98a8Spgoyette 			return error;
142d91f98a8Spgoyette 		}
143d91f98a8Spgoyette 	}
144d91f98a8Spgoyette 	return 0;
145d91f98a8Spgoyette }
146d91f98a8Spgoyette 
147d91f98a8Spgoyette void
wsevent_50_init(void)148d91f98a8Spgoyette wsevent_50_init(void)
149d91f98a8Spgoyette {
150d91f98a8Spgoyette 
151*8a031a1dSpgoyette 	MODULE_HOOK_SET(wscons_copyout_events_50_hook,
152d91f98a8Spgoyette 	    wsevent_copyout_events50);
153d91f98a8Spgoyette }
154d91f98a8Spgoyette 
155d91f98a8Spgoyette void
wsevent_50_fini(void)156d91f98a8Spgoyette wsevent_50_fini(void)
157d91f98a8Spgoyette {
158d91f98a8Spgoyette 
1598c2f80f1Spgoyette 	MODULE_HOOK_UNSET(wscons_copyout_events_50_hook);
160d91f98a8Spgoyette }
161