VirtualBox

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

Last change on this file since 91881 was 91863, checked in by vboxsync, 3 years ago

Devices/Input: Change input drivers to access the CFGM API through the driver helper callback table only, bugref:10074

  • 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 91863 2021-10-20 09:04:02Z 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 PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
471 PDRVKBDQUEUE pDrv = PDMINS_2_DATA(pDrvIns, PDRVKBDQUEUE);
472 PCPDMDRVHLPR3 pHlp = pDrvIns->pHlpR3;
473
474 LogFlow(("drvKbdQueueConstruct: iInstance=%d\n", pDrvIns->iInstance));
475
476
477 /*
478 * Validate configuration.
479 */
480 PDMDRV_VALIDATE_CONFIG_RETURN(pDrvIns, "QueueSize|Interval", "");
481
482 /*
483 * Init basic data members and interfaces.
484 */
485 pDrv->fInactive = true;
486 pDrv->fSuspended = false;
487 pDrv->XlatState = SS_IDLE;
488 /* IBase. */
489 pDrvIns->IBase.pfnQueryInterface = drvKbdQueueQueryInterface;
490 /* IKeyboardConnector. */
491 pDrv->IConnector.pfnLedStatusChange = drvKbdPassThruLedsChange;
492 pDrv->IConnector.pfnSetActive = drvKbdPassThruSetActive;
493 pDrv->IConnector.pfnFlushQueue = drvKbdFlushQueue;
494 /* IKeyboardPort. */
495 pDrv->IPort.pfnPutEventScan = drvKbdQueuePutEventScan;
496 pDrv->IPort.pfnPutEventHid = drvKbdQueuePutEventHid;
497 pDrv->IPort.pfnReleaseKeys = drvKbdQueueReleaseKeys;
498
499 /*
500 * Get the IKeyboardPort interface of the above driver/device.
501 */
502 pDrv->pUpPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIKEYBOARDPORT);
503 if (!pDrv->pUpPort)
504 {
505 AssertMsgFailed(("Configuration error: No keyboard port interface above!\n"));
506 return VERR_PDM_MISSING_INTERFACE_ABOVE;
507 }
508
509 /*
510 * Attach driver below and query it's connector interface.
511 */
512 PPDMIBASE pDownBase;
513 int rc = PDMDrvHlpAttach(pDrvIns, fFlags, &pDownBase);
514 if (RT_FAILURE(rc))
515 {
516 AssertMsgFailed(("Failed to attach driver below us! rc=%Rra\n", rc));
517 return rc;
518 }
519 pDrv->pDownConnector = PDMIBASE_QUERY_INTERFACE(pDownBase, PDMIKEYBOARDCONNECTOR);
520 if (!pDrv->pDownConnector)
521 {
522 AssertMsgFailed(("Configuration error: No keyboard connector interface below!\n"));
523 return VERR_PDM_MISSING_INTERFACE_BELOW;
524 }
525
526 /*
527 * Create the queue.
528 */
529 uint32_t cMilliesInterval = 0;
530 rc = pHlp->pfnCFGMQueryU32(pCfg, "Interval", &cMilliesInterval);
531 if (rc == VERR_CFGM_VALUE_NOT_FOUND)
532 cMilliesInterval = 0;
533 else if (RT_FAILURE(rc))
534 {
535 AssertMsgFailed(("Configuration error: 32-bit \"Interval\" -> rc=%Rrc\n", rc));
536 return rc;
537 }
538
539 uint32_t cItems = 0;
540 rc = pHlp->pfnCFGMQueryU32(pCfg, "QueueSize", &cItems);
541 if (rc == VERR_CFGM_VALUE_NOT_FOUND)
542 cItems = 128;
543 else if (RT_FAILURE(rc))
544 {
545 AssertMsgFailed(("Configuration error: 32-bit \"QueueSize\" -> rc=%Rrc\n", rc));
546 return rc;
547 }
548
549 rc = PDMDrvHlpQueueCreate(pDrvIns, sizeof(DRVKBDQUEUEITEM), cItems, cMilliesInterval,
550 drvKbdQueueConsumer, "Keyboard", &pDrv->pQueue);
551 if (RT_FAILURE(rc))
552 {
553 AssertMsgFailed(("Failed to create driver: cItems=%d cMilliesInterval=%d rc=%Rrc\n", cItems, cMilliesInterval, rc));
554 return rc;
555 }
556
557 return VINF_SUCCESS;
558}
559
560
561/**
562 * Keyboard queue driver registration record.
563 */
564const PDMDRVREG g_DrvKeyboardQueue =
565{
566 /* u32Version */
567 PDM_DRVREG_VERSION,
568 /* szName */
569 "KeyboardQueue",
570 /* szRCMod */
571 "",
572 /* szR0Mod */
573 "",
574 /* pszDescription */
575 "Keyboard queue driver to plug in between the key source and the device to do queueing and inter-thread transport.",
576 /* fFlags */
577 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
578 /* fClass. */
579 PDM_DRVREG_CLASS_KEYBOARD,
580 /* cMaxInstances */
581 ~0U,
582 /* cbInstance */
583 sizeof(DRVKBDQUEUE),
584 /* pfnConstruct */
585 drvKbdQueueConstruct,
586 /* pfnRelocate */
587 NULL,
588 /* pfnDestruct */
589 NULL,
590 /* pfnIOCtl */
591 NULL,
592 /* pfnPowerOn */
593 drvKbdQueuePowerOn,
594 /* pfnReset */
595 drvKbdQueueReset,
596 /* pfnSuspend */
597 drvKbdQueueSuspend,
598 /* pfnResume */
599 drvKbdQueueResume,
600 /* pfnAttach */
601 NULL,
602 /* pfnDetach */
603 NULL,
604 /* pfnPowerOff */
605 drvKbdQueuePowerOff,
606 /* pfnSoftReset */
607 NULL,
608 /* u32EndVersion */
609 PDM_DRVREG_VERSION
610};
611
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