1 | /* $Id: DrvKeyboardQueue.cpp 82968 2020-02-04 10:35:17Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox input devices: Keyboard queue driver
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2020 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 |
|
---|
19 | /*********************************************************************************************************************************
|
---|
20 | * Header Files *
|
---|
21 | *********************************************************************************************************************************/
|
---|
22 | #define LOG_GROUP LOG_GROUP_DRV_KBD_QUEUE
|
---|
23 | #include <VBox/vmm/pdmdrv.h>
|
---|
24 | #include <iprt/assert.h>
|
---|
25 | #include <iprt/uuid.h>
|
---|
26 |
|
---|
27 | #include "VBoxDD.h"
|
---|
28 |
|
---|
29 |
|
---|
30 | /*********************************************************************************************************************************
|
---|
31 | * Defined Constants And Macros *
|
---|
32 | *********************************************************************************************************************************/
|
---|
33 | /** Keyboard usage page bits to be OR-ed into the code. */
|
---|
34 | #define HID_PG_KB_BITS 0x070000
|
---|
35 |
|
---|
36 |
|
---|
37 | /*********************************************************************************************************************************
|
---|
38 | * Structures and Typedefs *
|
---|
39 | *********************************************************************************************************************************/
|
---|
40 |
|
---|
41 | /** Scancode translator state. */
|
---|
42 | typedef enum {
|
---|
43 | SS_IDLE, /**< Starting state. */
|
---|
44 | SS_EXT, /**< E0 byte was received. */
|
---|
45 | SS_EXT1 /**< E1 byte was received. */
|
---|
46 | } scan_state_t;
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * Keyboard queue driver instance data.
|
---|
50 | *
|
---|
51 | * @implements PDMIKEYBOARDCONNECTOR
|
---|
52 | * @implements PDMIKEYBOARDPORT
|
---|
53 | */
|
---|
54 | typedef struct DRVKBDQUEUE
|
---|
55 | {
|
---|
56 | /** Pointer to the driver instance structure. */
|
---|
57 | PPDMDRVINS pDrvIns;
|
---|
58 | /** Pointer to the keyboard port interface of the driver/device above us. */
|
---|
59 | PPDMIKEYBOARDPORT pUpPort;
|
---|
60 | /** Pointer to the keyboard port interface of the driver/device below us. */
|
---|
61 | PPDMIKEYBOARDCONNECTOR pDownConnector;
|
---|
62 | /** Our keyboard connector interface. */
|
---|
63 | PDMIKEYBOARDCONNECTOR IConnector;
|
---|
64 | /** Our keyboard port interface. */
|
---|
65 | PDMIKEYBOARDPORT IPort;
|
---|
66 | /** The queue handle. */
|
---|
67 | PPDMQUEUE pQueue;
|
---|
68 | /** State of the scancode translation. */
|
---|
69 | scan_state_t XlatState;
|
---|
70 | /** Discard input when this flag is set. */
|
---|
71 | bool fInactive;
|
---|
72 | /** When VM is suspended, queue full errors are not fatal. */
|
---|
73 | bool fSuspended;
|
---|
74 | } DRVKBDQUEUE, *PDRVKBDQUEUE;
|
---|
75 |
|
---|
76 |
|
---|
77 | /**
|
---|
78 | * Keyboard queue item.
|
---|
79 | */
|
---|
80 | typedef struct DRVKBDQUEUEITEM
|
---|
81 | {
|
---|
82 | /** The core part owned by the queue manager. */
|
---|
83 | PDMQUEUEITEMCORE Core;
|
---|
84 | /** The keycode. */
|
---|
85 | uint32_t idUsage;
|
---|
86 | } DRVKBDQUEUEITEM, *PDRVKBDQUEUEITEM;
|
---|
87 |
|
---|
88 |
|
---|
89 | /*********************************************************************************************************************************
|
---|
90 | * Global Variables *
|
---|
91 | *********************************************************************************************************************************/
|
---|
92 |
|
---|
93 | /** Lookup table for converting PC/XT scan codes to USB HID usage codes. */
|
---|
94 | static const uint8_t aScancode2Hid[] =
|
---|
95 | {
|
---|
96 | 0x00, 0x29, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, /* 00-07 */
|
---|
97 | 0x24, 0x25, 0x26, 0x27, 0x2d, 0x2e, 0x2a, 0x2b, /* 08-1F */
|
---|
98 | 0x14, 0x1a, 0x08, 0x15, 0x17, 0x1c, 0x18, 0x0c, /* 10-17 */
|
---|
99 | 0x12, 0x13, 0x2f, 0x30, 0x28, 0xe0, 0x04, 0x16, /* 18-1F */
|
---|
100 | 0x07, 0x09, 0x0a, 0x0b, 0x0d, 0x0e, 0x0f, 0x33, /* 20-27 */
|
---|
101 | 0x34, 0x35, 0xe1, 0x31, 0x1d, 0x1b, 0x06, 0x19, /* 28-2F */
|
---|
102 | 0x05, 0x11, 0x10, 0x36, 0x37, 0x38, 0xe5, 0x55, /* 30-37 */
|
---|
103 | 0xe2, 0x2c, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, /* 38-3F */
|
---|
104 | 0x3f, 0x40, 0x41, 0x42, 0x43, 0x53, 0x47, 0x5f, /* 40-47 */
|
---|
105 | 0x60, 0x61, 0x56, 0x5c, 0x5d, 0x5e, 0x57, 0x59, /* 48-4F */
|
---|
106 | 0x5a, 0x5b, 0x62, 0x63, 0x46, 0x00, 0x64, 0x44, /* 50-57 */
|
---|
107 | 0x45, 0x67, 0x00, 0x00, 0x8c, 0x00, 0x00, 0x00, /* 58-5F */
|
---|
108 | 0x00, 0x00, 0x00, 0x00, 0x68, 0x69, 0x6a, 0x6b, /* 60-67 */
|
---|
109 | 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x00, /* 68-6F */
|
---|
110 | 0x88, 0x91, 0x90, 0x87, 0x00, 0x00, 0x00, 0x00, /* 70-77 */
|
---|
111 | 0x00, 0x8a, 0x00, 0x8b, 0x00, 0x89, 0x85, 0x00 /* 78-7F */
|
---|
112 | };
|
---|
113 |
|
---|
114 | /** Lookup table for extended scancodes (arrow keys etc.). */
|
---|
115 | static const uint8_t aExtScan2Hid[] =
|
---|
116 | {
|
---|
117 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 00-07 */
|
---|
118 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 08-1F */
|
---|
119 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 10-17 */
|
---|
120 | 0x00, 0x00, 0x00, 0x00, 0x58, 0xe4, 0x00, 0x00, /* 18-1F */
|
---|
121 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 20-27 */
|
---|
122 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 28-2F */
|
---|
123 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x00, 0x46, /* 30-37 */
|
---|
124 | /* Sun-specific keys. Most of the XT codes are made up */
|
---|
125 | 0xe6, 0x00, 0x00, 0x75, 0x76, 0x77, 0xA3, 0x78, /* 38-3F */
|
---|
126 | 0x80, 0x81, 0x82, 0x79, 0x00, 0x00, 0x48, 0x4a, /* 40-47 */
|
---|
127 | 0x52, 0x4b, 0x00, 0x50, 0x00, 0x4f, 0x00, 0x4d, /* 48-4F */
|
---|
128 | 0x51, 0x4e, 0x49, 0x4c, 0x00, 0x00, 0x00, 0x00, /* 50-57 */
|
---|
129 | 0x00, 0x00, 0x00, 0xe3, 0xe7, 0x65, 0x66, 0x00, /* 58-5F */
|
---|
130 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 60-67 */
|
---|
131 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 68-6F */
|
---|
132 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 70-77 */
|
---|
133 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* 78-7F */
|
---|
134 | };
|
---|
135 |
|
---|
136 | /**
|
---|
137 | * Convert a PC scan code to a USB HID usage byte.
|
---|
138 | *
|
---|
139 | * @param state Current state of the translator (scan_state_t).
|
---|
140 | * @param scanCode Incoming scan code.
|
---|
141 | * @param pUsage Pointer to usage; high bit set for key up events. The
|
---|
142 | * contents are only valid if returned state is SS_IDLE.
|
---|
143 | *
|
---|
144 | * @return scan_state_t New state of the translator.
|
---|
145 | */
|
---|
146 | static scan_state_t ScancodeToHidUsage(scan_state_t state, uint8_t scanCode, uint32_t *pUsage)
|
---|
147 | {
|
---|
148 | uint32_t keyUp;
|
---|
149 | uint8_t usage;
|
---|
150 |
|
---|
151 | Assert(pUsage);
|
---|
152 |
|
---|
153 | /* Isolate the scan code and key break flag. */
|
---|
154 | keyUp = (scanCode & 0x80) << 24;
|
---|
155 |
|
---|
156 | switch (state) {
|
---|
157 | case SS_IDLE:
|
---|
158 | if (scanCode == 0xE0) {
|
---|
159 | state = SS_EXT;
|
---|
160 | } else if (scanCode == 0xE1) {
|
---|
161 | state = SS_EXT1;
|
---|
162 | } else {
|
---|
163 | usage = aScancode2Hid[scanCode & 0x7F];
|
---|
164 | *pUsage = usage | keyUp | HID_PG_KB_BITS;
|
---|
165 | /* Remain in SS_IDLE state. */
|
---|
166 | }
|
---|
167 | break;
|
---|
168 | case SS_EXT:
|
---|
169 | usage = aExtScan2Hid[scanCode & 0x7F];
|
---|
170 | *pUsage = usage | keyUp | HID_PG_KB_BITS;
|
---|
171 | state = SS_IDLE;
|
---|
172 | break;
|
---|
173 | case SS_EXT1:
|
---|
174 | /* The sequence is E1 1D 45 E1 9D C5. We take the easy way out and remain
|
---|
175 | * in the SS_EXT1 state until 45 or C5 is received.
|
---|
176 | */
|
---|
177 | if ((scanCode & 0x7F) == 0x45) {
|
---|
178 | *pUsage = 0x48 | HID_PG_KB_BITS;
|
---|
179 | if (scanCode == 0xC5)
|
---|
180 | *pUsage |= keyUp;
|
---|
181 | state = SS_IDLE;
|
---|
182 | }
|
---|
183 | /* Else remain in SS_EXT1 state. */
|
---|
184 | break;
|
---|
185 | }
|
---|
186 | return state;
|
---|
187 | }
|
---|
188 |
|
---|
189 |
|
---|
190 | /* -=-=-=-=- IBase -=-=-=-=- */
|
---|
191 |
|
---|
192 | /**
|
---|
193 | * @interface_method_impl{PDMIBASE,pfnQueryInterface}
|
---|
194 | */
|
---|
195 | static DECLCALLBACK(void *) drvKbdQueueQueryInterface(PPDMIBASE pInterface, const char *pszIID)
|
---|
196 | {
|
---|
197 | PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
|
---|
198 | PDRVKBDQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVKBDQUEUE);
|
---|
199 |
|
---|
200 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
|
---|
201 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMIKEYBOARDCONNECTOR, &pThis->IConnector);
|
---|
202 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMIKEYBOARDPORT, &pThis->IPort);
|
---|
203 | return NULL;
|
---|
204 | }
|
---|
205 |
|
---|
206 |
|
---|
207 | /* -=-=-=-=- IKeyboardPort -=-=-=-=- */
|
---|
208 |
|
---|
209 | /** Converts a pointer to DRVKBDQUEUE::IPort to a DRVKBDQUEUE pointer. */
|
---|
210 | #define IKEYBOARDPORT_2_DRVKBDQUEUE(pInterface) ( (PDRVKBDQUEUE)((char *)(pInterface) - RT_UOFFSETOF(DRVKBDQUEUE, IPort)) )
|
---|
211 |
|
---|
212 |
|
---|
213 | /**
|
---|
214 | * @interface_method_impl{PDMIKEYBOARDPORT,pfnPutEventScan}
|
---|
215 | *
|
---|
216 | * Because of the event queueing the EMT context requirement is lifted.
|
---|
217 | * @thread Any thread.
|
---|
218 | */
|
---|
219 | static DECLCALLBACK(int) drvKbdQueuePutEventScan(PPDMIKEYBOARDPORT pInterface, uint8_t u8ScanCode)
|
---|
220 | {
|
---|
221 | PDRVKBDQUEUE pDrv = IKEYBOARDPORT_2_DRVKBDQUEUE(pInterface);
|
---|
222 | /* Ignore any attempt to send events if queue is inactive. */
|
---|
223 | if (pDrv->fInactive)
|
---|
224 | return VINF_SUCCESS;
|
---|
225 |
|
---|
226 | uint32_t idUsage = 0;
|
---|
227 | pDrv->XlatState = ScancodeToHidUsage(pDrv->XlatState, u8ScanCode, &idUsage);
|
---|
228 |
|
---|
229 | if (pDrv->XlatState == SS_IDLE)
|
---|
230 | {
|
---|
231 | PDRVKBDQUEUEITEM pItem = (PDRVKBDQUEUEITEM)PDMQueueAlloc(pDrv->pQueue);
|
---|
232 | if (pItem)
|
---|
233 | {
|
---|
234 | /*
|
---|
235 | * Work around incredibly poorly desgined Korean keyboards which
|
---|
236 | * only send break events for Hangul/Hanja keys -- convert a lone
|
---|
237 | * key up into a key up/key down sequence.
|
---|
238 | */
|
---|
239 | if (idUsage == UINT32_C(0x80000090) || idUsage == UINT32_C(0x80000091))
|
---|
240 | {
|
---|
241 | PDRVKBDQUEUEITEM pItem2 = (PDRVKBDQUEUEITEM)PDMQueueAlloc(pDrv->pQueue);
|
---|
242 | /*
|
---|
243 | * NB: If there's no room in the queue, we will drop the faked
|
---|
244 | * key down event. Probably less bad than the alternatives.
|
---|
245 | */
|
---|
246 | if (pItem2)
|
---|
247 | {
|
---|
248 | /* Manufacture a key down event. */
|
---|
249 | pItem2->idUsage = idUsage & ~UINT32_C(0x80000000);
|
---|
250 | PDMQueueInsert(pDrv->pQueue, &pItem2->Core);
|
---|
251 | }
|
---|
252 | }
|
---|
253 |
|
---|
254 | pItem->idUsage = idUsage;
|
---|
255 | PDMQueueInsert(pDrv->pQueue, &pItem->Core);
|
---|
256 |
|
---|
257 | return VINF_SUCCESS;
|
---|
258 | }
|
---|
259 | if (!pDrv->fSuspended)
|
---|
260 | AssertMsgFailed(("drvKbdQueuePutEventScan: Queue is full!!!!\n"));
|
---|
261 | return VERR_PDM_NO_QUEUE_ITEMS;
|
---|
262 | }
|
---|
263 | else
|
---|
264 | return VINF_SUCCESS;
|
---|
265 | }
|
---|
266 |
|
---|
267 |
|
---|
268 | /**
|
---|
269 | * @interface_method_impl{PDMIKEYBOARDPORT,pfnPutEventHid}
|
---|
270 | *
|
---|
271 | * Because of the event queueing the EMT context requirement is lifted.
|
---|
272 | * @thread Any thread.
|
---|
273 | */
|
---|
274 | static DECLCALLBACK(int) drvKbdQueuePutEventHid(PPDMIKEYBOARDPORT pInterface, uint32_t idUsage)
|
---|
275 | {
|
---|
276 | PDRVKBDQUEUE pDrv = IKEYBOARDPORT_2_DRVKBDQUEUE(pInterface);
|
---|
277 | /* Ignore any attempt to send events if queue is inactive. */
|
---|
278 | if (pDrv->fInactive)
|
---|
279 | return VINF_SUCCESS;
|
---|
280 |
|
---|
281 | PDRVKBDQUEUEITEM pItem = (PDRVKBDQUEUEITEM)PDMQueueAlloc(pDrv->pQueue);
|
---|
282 | if (pItem)
|
---|
283 | {
|
---|
284 | pItem->idUsage = idUsage;
|
---|
285 | PDMQueueInsert(pDrv->pQueue, &pItem->Core);
|
---|
286 |
|
---|
287 | return VINF_SUCCESS;
|
---|
288 | }
|
---|
289 | if (!pDrv->fSuspended)
|
---|
290 | AssertMsgFailed(("drvKbdQueuePutEventHid: Queue is full!!!!\n"));
|
---|
291 | return VERR_PDM_NO_QUEUE_ITEMS;
|
---|
292 | }
|
---|
293 |
|
---|
294 |
|
---|
295 | /* -=-=-=-=- IConnector -=-=-=-=- */
|
---|
296 |
|
---|
297 | #define PPDMIKEYBOARDCONNECTOR_2_DRVKBDQUEUE(pInterface) ( (PDRVKBDQUEUE)((char *)(pInterface) - RT_UOFFSETOF(DRVKBDQUEUE, IConnector)) )
|
---|
298 |
|
---|
299 |
|
---|
300 | /**
|
---|
301 | * Pass LED status changes from the guest thru to the frontend driver.
|
---|
302 | *
|
---|
303 | * @param pInterface Pointer to the keyboard connector interface structure.
|
---|
304 | * @param enmLeds The new LED mask.
|
---|
305 | */
|
---|
306 | static DECLCALLBACK(void) drvKbdPassThruLedsChange(PPDMIKEYBOARDCONNECTOR pInterface, PDMKEYBLEDS enmLeds)
|
---|
307 | {
|
---|
308 | PDRVKBDQUEUE pDrv = PPDMIKEYBOARDCONNECTOR_2_DRVKBDQUEUE(pInterface);
|
---|
309 | pDrv->pDownConnector->pfnLedStatusChange(pDrv->pDownConnector, enmLeds);
|
---|
310 | }
|
---|
311 |
|
---|
312 | /**
|
---|
313 | * Pass keyboard state changes from the guest thru to the frontend driver.
|
---|
314 | *
|
---|
315 | * @param pInterface Pointer to the keyboard connector interface structure.
|
---|
316 | * @param fActive The new active/inactive state.
|
---|
317 | */
|
---|
318 | static DECLCALLBACK(void) drvKbdPassThruSetActive(PPDMIKEYBOARDCONNECTOR pInterface, bool fActive)
|
---|
319 | {
|
---|
320 | PDRVKBDQUEUE pDrv = PPDMIKEYBOARDCONNECTOR_2_DRVKBDQUEUE(pInterface);
|
---|
321 |
|
---|
322 | AssertPtr(pDrv->pDownConnector->pfnSetActive);
|
---|
323 | pDrv->pDownConnector->pfnSetActive(pDrv->pDownConnector, fActive);
|
---|
324 | }
|
---|
325 |
|
---|
326 | /**
|
---|
327 | * Flush the keyboard queue if there are pending events.
|
---|
328 | *
|
---|
329 | * @param pInterface Pointer to the keyboard connector interface structure.
|
---|
330 | */
|
---|
331 | static DECLCALLBACK(void) drvKbdFlushQueue(PPDMIKEYBOARDCONNECTOR pInterface)
|
---|
332 | {
|
---|
333 | PDRVKBDQUEUE pDrv = PPDMIKEYBOARDCONNECTOR_2_DRVKBDQUEUE(pInterface);
|
---|
334 |
|
---|
335 | AssertPtr(pDrv->pQueue);
|
---|
336 | PDMQueueFlushIfNecessary(pDrv->pQueue);
|
---|
337 | }
|
---|
338 |
|
---|
339 |
|
---|
340 | /* -=-=-=-=- queue -=-=-=-=- */
|
---|
341 |
|
---|
342 | /**
|
---|
343 | * Queue callback for processing a queued item.
|
---|
344 | *
|
---|
345 | * @returns Success indicator.
|
---|
346 | * If false the item will not be removed and the flushing will stop.
|
---|
347 | * @param pDrvIns The driver instance.
|
---|
348 | * @param pItemCore Pointer to the queue item to process.
|
---|
349 | */
|
---|
350 | static DECLCALLBACK(bool) drvKbdQueueConsumer(PPDMDRVINS pDrvIns, PPDMQUEUEITEMCORE pItemCore)
|
---|
351 | {
|
---|
352 | PDRVKBDQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVKBDQUEUE);
|
---|
353 | PDRVKBDQUEUEITEM pItem = (PDRVKBDQUEUEITEM)pItemCore;
|
---|
354 | int rc = pThis->pUpPort->pfnPutEventHid(pThis->pUpPort, pItem->idUsage);
|
---|
355 | return RT_SUCCESS(rc);
|
---|
356 | }
|
---|
357 |
|
---|
358 |
|
---|
359 | /* -=-=-=-=- driver interface -=-=-=-=- */
|
---|
360 |
|
---|
361 | /**
|
---|
362 | * Power On notification.
|
---|
363 | *
|
---|
364 | * @returns VBox status code.
|
---|
365 | * @param pDrvIns The drive instance data.
|
---|
366 | */
|
---|
367 | static DECLCALLBACK(void) drvKbdQueuePowerOn(PPDMDRVINS pDrvIns)
|
---|
368 | {
|
---|
369 | PDRVKBDQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVKBDQUEUE);
|
---|
370 | pThis->fInactive = false;
|
---|
371 | }
|
---|
372 |
|
---|
373 |
|
---|
374 | /**
|
---|
375 | * Reset notification.
|
---|
376 | *
|
---|
377 | * @returns VBox status code.
|
---|
378 | * @param pDrvIns The drive instance data.
|
---|
379 | */
|
---|
380 | static DECLCALLBACK(void) drvKbdQueueReset(PPDMDRVINS pDrvIns)
|
---|
381 | {
|
---|
382 | //PDRVKBDQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVKBDQUEUE);
|
---|
383 | /** @todo purge the queue on reset. */
|
---|
384 | RT_NOREF(pDrvIns);
|
---|
385 | }
|
---|
386 |
|
---|
387 |
|
---|
388 | /**
|
---|
389 | * Suspend notification.
|
---|
390 | *
|
---|
391 | * @returns VBox status code.
|
---|
392 | * @param pDrvIns The drive instance data.
|
---|
393 | */
|
---|
394 | static DECLCALLBACK(void) drvKbdQueueSuspend(PPDMDRVINS pDrvIns)
|
---|
395 | {
|
---|
396 | PDRVKBDQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVKBDQUEUE);
|
---|
397 | pThis->fSuspended = true;
|
---|
398 | }
|
---|
399 |
|
---|
400 |
|
---|
401 | /**
|
---|
402 | * Resume notification.
|
---|
403 | *
|
---|
404 | * @returns VBox status code.
|
---|
405 | * @param pDrvIns The drive instance data.
|
---|
406 | */
|
---|
407 | static DECLCALLBACK(void) drvKbdQueueResume(PPDMDRVINS pDrvIns)
|
---|
408 | {
|
---|
409 | PDRVKBDQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVKBDQUEUE);
|
---|
410 | pThis->fInactive = false;
|
---|
411 | pThis->fSuspended = false;
|
---|
412 | }
|
---|
413 |
|
---|
414 |
|
---|
415 | /**
|
---|
416 | * Power Off notification.
|
---|
417 | *
|
---|
418 | * @param pDrvIns The drive instance data.
|
---|
419 | */
|
---|
420 | static DECLCALLBACK(void) drvKbdQueuePowerOff(PPDMDRVINS pDrvIns)
|
---|
421 | {
|
---|
422 | PDRVKBDQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVKBDQUEUE);
|
---|
423 | pThis->fInactive = true;
|
---|
424 | }
|
---|
425 |
|
---|
426 |
|
---|
427 | /**
|
---|
428 | * Construct a keyboard driver instance.
|
---|
429 | *
|
---|
430 | * @copydoc FNPDMDRVCONSTRUCT
|
---|
431 | */
|
---|
432 | static DECLCALLBACK(int) drvKbdQueueConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
|
---|
433 | {
|
---|
434 | PDRVKBDQUEUE pDrv = PDMINS_2_DATA(pDrvIns, PDRVKBDQUEUE);
|
---|
435 | LogFlow(("drvKbdQueueConstruct: iInstance=%d\n", pDrvIns->iInstance));
|
---|
436 | PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
|
---|
437 |
|
---|
438 | /*
|
---|
439 | * Validate configuration.
|
---|
440 | */
|
---|
441 | if (!CFGMR3AreValuesValid(pCfg, "QueueSize\0Interval\0"))
|
---|
442 | return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
|
---|
443 |
|
---|
444 | /*
|
---|
445 | * Init basic data members and interfaces.
|
---|
446 | */
|
---|
447 | pDrv->fInactive = true;
|
---|
448 | pDrv->fSuspended = false;
|
---|
449 | pDrv->XlatState = SS_IDLE;
|
---|
450 | /* IBase. */
|
---|
451 | pDrvIns->IBase.pfnQueryInterface = drvKbdQueueQueryInterface;
|
---|
452 | /* IKeyboardConnector. */
|
---|
453 | pDrv->IConnector.pfnLedStatusChange = drvKbdPassThruLedsChange;
|
---|
454 | pDrv->IConnector.pfnSetActive = drvKbdPassThruSetActive;
|
---|
455 | pDrv->IConnector.pfnFlushQueue = drvKbdFlushQueue;
|
---|
456 | /* IKeyboardPort. */
|
---|
457 | pDrv->IPort.pfnPutEventScan = drvKbdQueuePutEventScan;
|
---|
458 | pDrv->IPort.pfnPutEventHid = drvKbdQueuePutEventHid;
|
---|
459 |
|
---|
460 | /*
|
---|
461 | * Get the IKeyboardPort interface of the above driver/device.
|
---|
462 | */
|
---|
463 | pDrv->pUpPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIKEYBOARDPORT);
|
---|
464 | if (!pDrv->pUpPort)
|
---|
465 | {
|
---|
466 | AssertMsgFailed(("Configuration error: No keyboard port interface above!\n"));
|
---|
467 | return VERR_PDM_MISSING_INTERFACE_ABOVE;
|
---|
468 | }
|
---|
469 |
|
---|
470 | /*
|
---|
471 | * Attach driver below and query it's connector interface.
|
---|
472 | */
|
---|
473 | PPDMIBASE pDownBase;
|
---|
474 | int rc = PDMDrvHlpAttach(pDrvIns, fFlags, &pDownBase);
|
---|
475 | if (RT_FAILURE(rc))
|
---|
476 | {
|
---|
477 | AssertMsgFailed(("Failed to attach driver below us! rc=%Rra\n", rc));
|
---|
478 | return rc;
|
---|
479 | }
|
---|
480 | pDrv->pDownConnector = PDMIBASE_QUERY_INTERFACE(pDownBase, PDMIKEYBOARDCONNECTOR);
|
---|
481 | if (!pDrv->pDownConnector)
|
---|
482 | {
|
---|
483 | AssertMsgFailed(("Configuration error: No keyboard connector interface below!\n"));
|
---|
484 | return VERR_PDM_MISSING_INTERFACE_BELOW;
|
---|
485 | }
|
---|
486 |
|
---|
487 | /*
|
---|
488 | * Create the queue.
|
---|
489 | */
|
---|
490 | uint32_t cMilliesInterval = 0;
|
---|
491 | rc = CFGMR3QueryU32(pCfg, "Interval", &cMilliesInterval);
|
---|
492 | if (rc == VERR_CFGM_VALUE_NOT_FOUND)
|
---|
493 | cMilliesInterval = 0;
|
---|
494 | else if (RT_FAILURE(rc))
|
---|
495 | {
|
---|
496 | AssertMsgFailed(("Configuration error: 32-bit \"Interval\" -> rc=%Rrc\n", rc));
|
---|
497 | return rc;
|
---|
498 | }
|
---|
499 |
|
---|
500 | uint32_t cItems = 0;
|
---|
501 | rc = CFGMR3QueryU32(pCfg, "QueueSize", &cItems);
|
---|
502 | if (rc == VERR_CFGM_VALUE_NOT_FOUND)
|
---|
503 | cItems = 128;
|
---|
504 | else if (RT_FAILURE(rc))
|
---|
505 | {
|
---|
506 | AssertMsgFailed(("Configuration error: 32-bit \"QueueSize\" -> rc=%Rrc\n", rc));
|
---|
507 | return rc;
|
---|
508 | }
|
---|
509 |
|
---|
510 | rc = PDMDrvHlpQueueCreate(pDrvIns, sizeof(DRVKBDQUEUEITEM), cItems, cMilliesInterval, drvKbdQueueConsumer, "Keyboard", &pDrv->pQueue);
|
---|
511 | if (RT_FAILURE(rc))
|
---|
512 | {
|
---|
513 | AssertMsgFailed(("Failed to create driver: cItems=%d cMilliesInterval=%d rc=%Rrc\n", cItems, cMilliesInterval, rc));
|
---|
514 | return rc;
|
---|
515 | }
|
---|
516 |
|
---|
517 | return VINF_SUCCESS;
|
---|
518 | }
|
---|
519 |
|
---|
520 |
|
---|
521 | /**
|
---|
522 | * Keyboard queue driver registration record.
|
---|
523 | */
|
---|
524 | const PDMDRVREG g_DrvKeyboardQueue =
|
---|
525 | {
|
---|
526 | /* u32Version */
|
---|
527 | PDM_DRVREG_VERSION,
|
---|
528 | /* szName */
|
---|
529 | "KeyboardQueue",
|
---|
530 | /* szRCMod */
|
---|
531 | "",
|
---|
532 | /* szR0Mod */
|
---|
533 | "",
|
---|
534 | /* pszDescription */
|
---|
535 | "Keyboard queue driver to plug in between the key source and the device to do queueing and inter-thread transport.",
|
---|
536 | /* fFlags */
|
---|
537 | PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
|
---|
538 | /* fClass. */
|
---|
539 | PDM_DRVREG_CLASS_KEYBOARD,
|
---|
540 | /* cMaxInstances */
|
---|
541 | ~0U,
|
---|
542 | /* cbInstance */
|
---|
543 | sizeof(DRVKBDQUEUE),
|
---|
544 | /* pfnConstruct */
|
---|
545 | drvKbdQueueConstruct,
|
---|
546 | /* pfnRelocate */
|
---|
547 | NULL,
|
---|
548 | /* pfnDestruct */
|
---|
549 | NULL,
|
---|
550 | /* pfnIOCtl */
|
---|
551 | NULL,
|
---|
552 | /* pfnPowerOn */
|
---|
553 | drvKbdQueuePowerOn,
|
---|
554 | /* pfnReset */
|
---|
555 | drvKbdQueueReset,
|
---|
556 | /* pfnSuspend */
|
---|
557 | drvKbdQueueSuspend,
|
---|
558 | /* pfnResume */
|
---|
559 | drvKbdQueueResume,
|
---|
560 | /* pfnAttach */
|
---|
561 | NULL,
|
---|
562 | /* pfnDetach */
|
---|
563 | NULL,
|
---|
564 | /* pfnPowerOff */
|
---|
565 | drvKbdQueuePowerOff,
|
---|
566 | /* pfnSoftReset */
|
---|
567 | NULL,
|
---|
568 | /* u32EndVersion */
|
---|
569 | PDM_DRVREG_VERSION
|
---|
570 | };
|
---|
571 |
|
---|