source: mainline/uspace/srv/hid/input/ctl/kbdev.c@ 86ffa27f

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 86ffa27f was 1875a0c, checked in by Martin Decky <martin@…>, 14 years ago

input server improvements

  • integrate legacy port mouse drivers (PS/2, ADB) into the input server (to be on par with the legacy keyboard drivers)
  • create generic port/protocol layers for the mouse in the input server
  • rename the "hid_in" namespace to "hid" namespace (hid_in/input was rather redundant)
  • rename the mouse event IPC messages to be more consistent with the keyboard event messages
  • rename input server ops structure members to be more generic (parse_scancode → parse)
  • cstyle changes (newlines, comments, printouts)
  • Property mode set to 100644
File size: 4.7 KB
Line 
1/*
2 * Copyright (c) 2011 Jiri Svoboda
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup kbd_ctl
30 * @ingroup input
31 * @{
32 */
33/**
34 * @file
35 * @brief Keyboard device connector controller driver.
36 */
37
38#include <async.h>
39#include <bool.h>
40#include <errno.h>
41#include <fcntl.h>
42#include <gsp.h>
43#include <io/console.h>
44#include <io/keycode.h>
45#include <ipc/kbdev.h>
46#include <input.h>
47#include <kbd.h>
48#include <kbd_ctl.h>
49#include <kbd_port.h>
50#include <stdlib.h>
51#include <vfs/vfs_sess.h>
52
53
54static int kbdev_ctl_init(kbd_dev_t *);
55static void kbdev_ctl_set_ind(kbd_dev_t *, unsigned int);
56
57static void kbdev_callback_conn(ipc_callid_t, ipc_call_t *, void *arg);
58
59kbd_ctl_ops_t kbdev_ctl = {
60 .parse = NULL,
61 .init = kbdev_ctl_init,
62 .set_ind = kbdev_ctl_set_ind
63};
64
65/** Kbdev softstate */
66typedef struct {
67 /** Link to generic keyboard device */
68 kbd_dev_t *kbd_dev;
69
70 /** Session with kbdev device */
71 async_sess_t *sess;
72
73 /** File descriptor of open kbdev device */
74 int fd;
75} kbdev_t;
76
77static kbdev_t *kbdev_new(kbd_dev_t *kdev)
78{
79 kbdev_t *kbdev;
80
81 kbdev = calloc(1, sizeof(kbdev_t));
82 if (kbdev == NULL)
83 return NULL;
84
85 kbdev->kbd_dev = kdev;
86 kbdev->fd = -1;
87
88 return kbdev;
89}
90
91static void kbdev_destroy(kbdev_t *kbdev)
92{
93 if (kbdev->sess != NULL)
94 async_hangup(kbdev->sess);
95 if (kbdev->fd >= 0)
96 close(kbdev->fd);
97 free(kbdev);
98}
99
100static int kbdev_ctl_init(kbd_dev_t *kdev)
101{
102 const char *pathname;
103 async_sess_t *sess;
104 async_exch_t *exch;
105 kbdev_t *kbdev;
106 int fd;
107 int rc;
108
109 pathname = kdev->dev_path;
110
111 fd = open(pathname, O_RDWR);
112 if (fd < 0) {
113 return -1;
114 }
115
116 sess = fd_session(EXCHANGE_SERIALIZE, fd);
117 if (sess == NULL) {
118 printf("%s: Failed starting session with '%s'\n", NAME, pathname);
119 close(fd);
120 return -1;
121 }
122
123 kbdev = kbdev_new(kdev);
124 if (kbdev == NULL) {
125 printf("%s: Failed allocating device structure for '%s'.\n",
126 NAME, pathname);
127 return -1;
128 }
129
130 kbdev->fd = fd;
131 kbdev->sess = sess;
132
133 exch = async_exchange_begin(sess);
134 if (exch == NULL) {
135 printf("%s: Failed starting exchange with '%s'.\n", NAME, pathname);
136 kbdev_destroy(kbdev);
137 return -1;
138 }
139
140 rc = async_connect_to_me(exch, 0, 0, 0, kbdev_callback_conn, kbdev);
141 if (rc != EOK) {
142 printf("%s: Failed creating callback connection from '%s'.\n",
143 NAME, pathname);
144 async_exchange_end(exch);
145 kbdev_destroy(kbdev);
146 return -1;
147 }
148
149 async_exchange_end(exch);
150
151 kdev->ctl_private = (void *) kbdev;
152 return 0;
153}
154
155static void kbdev_ctl_set_ind(kbd_dev_t *kdev, unsigned mods)
156{
157 async_sess_t *sess;
158 async_exch_t *exch;
159
160 sess = ((kbdev_t *) kdev->ctl_private)->sess;
161
162 exch = async_exchange_begin(sess);
163 if (!exch)
164 return;
165
166 async_msg_1(exch, KBDEV_SET_IND, mods);
167 async_exchange_end(exch);
168}
169
170static void kbdev_callback_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
171{
172 kbdev_t *kbdev;
173 int retval;
174 int type, key;
175
176 /* Kbdev device structure */
177 kbdev = arg;
178
179 while (true) {
180 ipc_call_t call;
181 ipc_callid_t callid;
182
183 callid = async_get_call(&call);
184 if (!IPC_GET_IMETHOD(call)) {
185 /* XXX Handle hangup */
186 return;
187 }
188
189 switch (IPC_GET_IMETHOD(call)) {
190 case KBDEV_EVENT:
191 /* Got event from keyboard device */
192 retval = 0;
193 type = IPC_GET_ARG1(call);
194 key = IPC_GET_ARG2(call);
195 kbd_push_event(kbdev->kbd_dev, type, key);
196 break;
197 default:
198 retval = ENOTSUP;
199 break;
200 }
201
202 async_answer_0(callid, retval);
203 }
204}
205
206/**
207 * @}
208 */
Note: See TracBrowser for help on using the repository browser.