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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
/* This file contains the device independent input driver interface. */
/*
* Changes:
* Sep 22, 2013 created (D.C. van Moolenbroek)
*/
#include <minix/drivers.h>
#include <minix/inputdriver.h>
#include <minix/ds.h>
static endpoint_t input_endpt = NONE;
static int kbd_id = INVALID_INPUT_ID;
static int mouse_id = INVALID_INPUT_ID;
static int running;
/*
* Announce that we are up after a fresh start or restart.
*/
void
inputdriver_announce(unsigned int type)
{
const char *driver_prefix = "drv.inp.";
char key[DS_MAX_KEYLEN];
char label[DS_MAX_KEYLEN];
int r;
/* Publish a driver up event. */
if ((r = ds_retrieve_label_name(label, sef_self())) != OK)
panic("libinputdriver: unable to retrieve own label: %d", r);
snprintf(key, sizeof(key), "%s%s", driver_prefix, label);
if ((r = ds_publish_u32(key, type, DSF_OVERWRITE)) != OK)
panic("libinputdriver: unable to publish up event: %d", r);
/* Now we wait for the input server to contact us. */
}
/*
* Send an event to the input server.
*/
void
inputdriver_send_event(int mouse, unsigned short page, unsigned short code,
int value, int flags)
{
message m;
int id;
if (input_endpt == NONE)
return;
id = mouse ? mouse_id : kbd_id;
if (id == INVALID_INPUT_ID)
return;
memset(&m, 0, sizeof(m));
m.m_type = INPUT_EVENT;
m.m_linputdriver_input_event.id = id;
m.m_linputdriver_input_event.page = page;
m.m_linputdriver_input_event.code = code;
m.m_linputdriver_input_event.value = value;
m.m_linputdriver_input_event.flags = flags;
/*
* Use a blocking send call, for two reasons. First, this avoids the
* situation that we ever end up queuing too many asynchronous messages
* to the input server. Second, it allows us to detect trivially if
* the input server has crashed, in which case we should stop sending
* more messages to it.
*/
if (ipc_send(input_endpt, &m) != OK)
input_endpt = NONE;
}
/*
* The input server requests that we configure the driver. This request should
* be sent to us once, although it may be sent multiple times if the input
* server crashes and recovers. The configuration consists of device IDs for
* use in keyboard and/or mouse events, one per each device type.
*/
static void
do_conf(message *m_ptr)
{
endpoint_t ep;
int r;
/* Make sure that the sender is actually the input server. */
if ((r = ds_retrieve_label_endpt("input", &ep)) != OK) {
printf("libinputdriver: unable to get input endpoint (%d)\n",
r);
return; /* ignore message */
}
if (ep != m_ptr->m_source) {
printf("libinputdriver: ignoring CONF request from %u\n",
m_ptr->m_source);
return;
}
/* Save the new state. */
input_endpt = m_ptr->m_source;
kbd_id = m_ptr->m_input_linputdriver_input_conf.kbd_id;
mouse_id = m_ptr->m_input_linputdriver_input_conf.mouse_id;
/* If the input server is "full" there's nothing for us to do. */
if (kbd_id == INVALID_INPUT_ID && mouse_id == INVALID_INPUT_ID)
printf("libinputdriver: no IDs given, driver disabled\n");
}
/*
* The input server is telling us to change the LEDs to a particular mask.
* For now this is for keyboards only, so no device type is provided.
* This approach was chosen over sending toggle events for the individual LEDs
* for convenience reasons only.
*/
static void
do_setleds(struct inputdriver *idp, message *m_ptr)
{
unsigned int mask;
if (m_ptr->m_source != input_endpt) {
printf("libinputdriver: ignoring SETLEDS request from %u\n",
m_ptr->m_source);
return;
}
mask = m_ptr->m_input_linputdriver_setleds.led_mask;
if (idp->idr_leds)
idp->idr_leds(mask);
}
/*
* Call the appropriate driver function, based on the type of message.
* All messages in the input protocol are one-way, so we never send a reply.
*/
void
inputdriver_process(struct inputdriver *idp, message *m_ptr, int ipc_status)
{
/* Check for notifications first. */
if (is_ipc_notify(ipc_status)) {
switch (_ENDPOINT_P(m_ptr->m_source)) {
case HARDWARE:
if (idp->idr_intr)
idp->idr_intr(m_ptr->m_notify.interrupts);
break;
case CLOCK:
if (idp->idr_alarm)
idp->idr_alarm(m_ptr->m_notify.timestamp);
break;
default:
if (idp->idr_other)
idp->idr_other(m_ptr, ipc_status);
}
return;
}
switch (m_ptr->m_type) {
case INPUT_CONF: do_conf(m_ptr); break;
case INPUT_SETLEDS: do_setleds(idp, m_ptr); break;
default:
if (idp->idr_other)
idp->idr_other(m_ptr, ipc_status);
}
}
/*
* Break out of the main loop after finishing the current request.
*/
void
inputdriver_terminate(void)
{
running = FALSE;
sef_cancel();
}
/*
* Main program of any input driver task.
*/
void
inputdriver_task(struct inputdriver *idp)
{
message m;
int r, ipc_status;
running = TRUE;
while (running) {
if ((r = sef_receive_status(ANY, &m, &ipc_status)) != OK) {
if (r == EINTR && !running)
break;
panic("libinputdriver: receive failed: %d", r);
}
inputdriver_process(idp, &m, ipc_status);
}
}
|