-
Notifications
You must be signed in to change notification settings - Fork 2
/
seabios-Support-USB-keyboard-auto-repeat.patch
253 lines (235 loc) · 6.8 KB
/
seabios-Support-USB-keyboard-auto-repeat.patch
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
From 86df0d751de91cfd8d802f42e39f62ac99fcdf7b Mon Sep 17 00:00:00 2001
From: Gerd Hoffmann <[email protected]>
Date: Fri, 18 Jun 2010 09:52:10 -0300
Subject: [PATCH 1/2] Support USB keyboard auto-repeat.
RH-Author: Gerd Hoffmann <[email protected]>
Message-id: <[email protected]>
Patchwork-id: 9973
O-Subject: [RHEL-6 seabios PATCH 1/2] Support USB keyboard auto-repeat.
Bugzilla: 561324
RH-Acked-by: Alex Williamson <[email protected]>
RH-Acked-by: Jes Sorensen <[email protected]>
RH-Acked-by: Gleb Natapov <[email protected]>
Support handling of multiple keys pressed simultanously.
Support auto-repeat via USB HID Set_Idle command.
Also, add "noinline" directives to reduce stack usage of timer irq.
(cherry picked from commit 84a4d4b0b10c8a4e04c4e7bfd806c6c50693d945)
bugzilla: #561324
Signed-off-by: Gerd Hoffmann <[email protected]>
---
src/biosvar.h | 12 +++++++
src/mouse.c | 2 +-
src/usb-hid.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++---------
src/usb.c | 2 +-
4 files changed, 98 insertions(+), 18 deletions(-)
Signed-off-by: Eduardo Habkost <[email protected]>
---
src/biosvar.h | 12 +++++++
src/mouse.c | 2 +-
src/usb-hid.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++---------
src/usb.c | 2 +-
4 files changed, 98 insertions(+), 18 deletions(-)
diff --git a/src/biosvar.h b/src/biosvar.h
index b6e061b..a683b7a 100644
--- a/src/biosvar.h
+++ b/src/biosvar.h
@@ -188,6 +188,17 @@ struct fdpt_s {
u8 checksum;
} PACKED;
+struct usbkeyinfo {
+ union {
+ struct {
+ u8 modifiers;
+ u8 repeatcount;
+ u8 keys[6];
+ };
+ u64 data;
+ };
+};
+
struct extended_bios_data_area_s {
u8 size;
u8 reserved1[0x21];
@@ -206,6 +217,7 @@ struct extended_bios_data_area_s {
// 0x121 - Begin custom storage.
u8 ps2ctr;
+ struct usbkeyinfo usbkey_last;
int RTCusers;
// El Torito Emulation data
diff --git a/src/mouse.c b/src/mouse.c
index 52e225c..8389d2a 100644
--- a/src/mouse.c
+++ b/src/mouse.c
@@ -281,7 +281,7 @@ handle_15c2(struct bregs *regs)
}
}
-void
+void noinline
process_mouse(u8 data)
{
if (!CONFIG_MOUSE)
diff --git a/src/usb-hid.c b/src/usb-hid.c
index 7756c62..b714685 100644
--- a/src/usb-hid.c
+++ b/src/usb-hid.c
@@ -30,17 +30,20 @@ set_protocol(u32 endp, u16 val)
}
static int
-set_idle(u32 endp, u8 val)
+set_idle(u32 endp, int ms)
{
struct usb_ctrlrequest req;
req.bRequestType = USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE;
req.bRequest = HID_REQ_SET_IDLE;
- req.wValue = val<<8;
+ req.wValue = (ms/4)<<8;
req.wIndex = 0;
req.wLength = 0;
return send_default_control(endp, &req, NULL);
}
+#define KEYREPEATWAITMS 500
+#define KEYREPEATMS 33
+
int
usb_keyboard_init(u32 endp, struct usb_interface_descriptor *iface, int imax)
{
@@ -75,7 +78,7 @@ usb_keyboard_init(u32 endp, struct usb_interface_descriptor *iface, int imax)
if (ret)
return -1;
// Only send reports on a new key event.
- ret = set_idle(endp, 0);
+ ret = set_idle(endp, KEYREPEATMS);
if (ret)
return -1;
@@ -121,6 +124,8 @@ static u16 ModifierToScanCode[] VAR16 = {
0x001d, 0x002a, 0x0038, 0xe05b, 0xe01d, 0x0036, 0xe038, 0xe05c
};
+#define RELEASEBIT 0x80
+
struct keyevent {
u8 modifiers;
u8 reserved;
@@ -135,8 +140,8 @@ prockeys(u16 keys)
if (key == 0xe1) {
// Pause key
process_key(0xe1);
- process_key(0x1d | (keys & 0x80));
- process_key(0x45 | (keys & 0x80));
+ process_key(0x1d | (keys & RELEASEBIT));
+ process_key(0x45 | (keys & RELEASEBIT));
return;
}
process_key(key);
@@ -145,26 +150,89 @@ prockeys(u16 keys)
}
static void
+procscankey(u8 key, u8 flags)
+{
+ if (key >= ARRAY_SIZE(KeyToScanCode))
+ return;
+ u16 keys = GET_GLOBAL(KeyToScanCode[key]);
+ if (keys)
+ prockeys(keys | flags);
+}
+
+static void
+procmodkey(u8 mods, u8 flags)
+{
+ int i;
+ for (i=0; mods; i++)
+ if (mods & (1<<i)) {
+ // Modifier key change.
+ prockeys(GET_GLOBAL(ModifierToScanCode[i]) | flags);
+ mods &= ~(1<<i);
+ }
+}
+
+static void noinline
handle_key(struct keyevent *data)
{
dprintf(5, "Got key %x %x\n", data->modifiers, data->keys[0]);
- // XXX
+
+ // Load old keys.
+ u16 ebda_seg = get_ebda_seg();
+ struct usbkeyinfo old;
+ old.data = GET_EBDA2(ebda_seg, usbkey_last.data);
+
+ // Check for keys no longer pressed.
+ int addpos = 0;
int i;
- for (i=0; i<8; i++)
- if (data->modifiers & (1<<i))
- prockeys(GET_GLOBAL(ModifierToScanCode[i]));
+ for (i=0; i<ARRAY_SIZE(old.keys); i++) {
+ u8 key = old.keys[i];
+ if (!key)
+ break;
+ int j;
+ for (j=0;; j++) {
+ if (j>=ARRAY_SIZE(data->keys)) {
+ // Key released.
+ procscankey(key, RELEASEBIT);
+ if (i+1 >= ARRAY_SIZE(old.keys) || !old.keys[i+1])
+ // Last pressed key released - disable repeat.
+ old.repeatcount = 0xff;
+ break;
+ }
+ if (data->keys[j] == key) {
+ // Key still pressed.
+ data->keys[j] = 0;
+ old.keys[addpos++] = key;
+ break;
+ }
+ }
+ }
+ procmodkey(old.modifiers & ~data->modifiers, RELEASEBIT);
+
+ // Process new keys
+ procmodkey(data->modifiers & ~old.modifiers, 0);
+ old.modifiers = data->modifiers;
for (i=0; i<ARRAY_SIZE(data->keys); i++) {
u8 key = data->keys[i];
- if (key >= ARRAY_SIZE(KeyToScanCode))
- continue;
- key = GET_GLOBAL(KeyToScanCode[key]);
if (!key)
continue;
- prockeys(key);
+ // New key pressed.
+ procscankey(key, 0);
+ old.keys[addpos++] = key;
+ old.repeatcount = KEYREPEATWAITMS / KEYREPEATMS + 1;
}
- for (i=0; i<8; i++)
- if (data->modifiers & (1<<i))
- prockeys(GET_GLOBAL(ModifierToScanCode[i]) | 0x80);
+ if (addpos < ARRAY_SIZE(old.keys))
+ old.keys[addpos] = 0;
+
+ // Check for key repeat event.
+ if (addpos) {
+ if (!old.repeatcount)
+ procscankey(old.keys[addpos-1], 0);
+ else if (old.repeatcount != 0xff)
+ old.repeatcount--;
+ }
+
+ // Update old keys
+ SET_EBDA2(ebda_seg, usbkey_last.data, old.data);
}
void
diff --git a/src/usb.c b/src/usb.c
index 2bd5832..12747db 100644
--- a/src/usb.c
+++ b/src/usb.c
@@ -44,7 +44,7 @@ alloc_intr_pipe(u32 endp, int period)
}
}
-int
+int noinline
usb_poll_intr(struct usb_pipe *pipe, void *data)
{
u32 endp = GET_FLATPTR(pipe->endp);
--
1.7.0.3