VirtualBox

source: vbox/trunk/src/VBox/Devices/Input/DrvKeyboardQueue.cpp@ 91687

Last change on this file since 91687 was 90241, checked in by vboxsync, 3 years ago

DrvKeyboardQueue: Fixed Korean key detection (I think), added assertion for keys that have no translation and produce zero usage code.

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette