VirtualBox

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

Last change on this file since 95271 was 93115, checked in by vboxsync, 3 years ago

scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 20.2 KB
Line 
1/* $Id: DrvKeyboardQueue.cpp 93115 2022-01-01 11:31:46Z vboxsync $ */
2/** @file
3 * VBox input devices: Keyboard queue driver
4 */
5
6/*
7 * Copyright (C) 2006-2022 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 PDMQUEUEHANDLE hQueue;
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)PDMDrvHlpQueueAlloc(pDrv->pDrvIns, pDrv->hQueue);
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)PDMDrvHlpQueueAlloc(pDrv->pDrvIns, pDrv->hQueue);
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 PDMDrvHlpQueueInsert(pDrv->pDrvIns, pDrv->hQueue, &pItem2->Core);
255 }
256 }
257
258 pItem->idUsage = idUsage;
259 PDMDrvHlpQueueInsert(pDrv->pDrvIns, pDrv->hQueue, &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 return VINF_SUCCESS;
268}
269
270
271/**
272 * @interface_method_impl{PDMIKEYBOARDPORT,pfnPutEventHid}
273 *
274 * Because of the event queueing the EMT context requirement is lifted.
275 * @thread Any thread.
276 */
277static DECLCALLBACK(int) drvKbdQueuePutEventHid(PPDMIKEYBOARDPORT pInterface, uint32_t idUsage)
278{
279 PDRVKBDQUEUE pDrv = IKEYBOARDPORT_2_DRVKBDQUEUE(pInterface);
280 /* Ignore any attempt to send events if queue is inactive. */
281 if (pDrv->fInactive)
282 return VINF_SUCCESS;
283
284 PDRVKBDQUEUEITEM pItem = (PDRVKBDQUEUEITEM)PDMDrvHlpQueueAlloc(pDrv->pDrvIns, pDrv->hQueue);
285 if (pItem)
286 {
287 pItem->idUsage = idUsage;
288 PDMDrvHlpQueueInsert(pDrv->pDrvIns, pDrv->hQueue, &pItem->Core);
289
290 return VINF_SUCCESS;
291 }
292 AssertMsg(pDrv->fSuspended, ("drvKbdQueuePutEventHid: Queue is full!!!!\n"));
293 return VERR_PDM_NO_QUEUE_ITEMS;
294}
295
296
297/**
298 * @interface_method_impl{PDMIKEYBOARDPORT,pfnReleaseKeys}
299 *
300 * Because of the event queueing the EMT context requirement is lifted.
301 * @thread Any thread.
302 */
303static DECLCALLBACK(int) drvKbdQueueReleaseKeys(PPDMIKEYBOARDPORT pInterface)
304{
305 PDRVKBDQUEUE pDrv = IKEYBOARDPORT_2_DRVKBDQUEUE(pInterface);
306
307 /* Ignore any attempt to send events if queue is inactive. */
308 if (pDrv->fInactive)
309 return VINF_SUCCESS;
310
311 PDRVKBDQUEUEITEM pItem = (PDRVKBDQUEUEITEM)PDMDrvHlpQueueAlloc(pDrv->pDrvIns, pDrv->hQueue);
312 if (pItem)
313 {
314 /* Send a special key event that forces all keys to be released.
315 * Goes through the queue so that it would take effect only after
316 * any key events that might already be queued up.
317 */
318 pItem->idUsage = PDMIKBDPORT_RELEASE_KEYS | HID_PG_KB_BITS;
319 PDMDrvHlpQueueInsert(pDrv->pDrvIns, pDrv->hQueue, &pItem->Core);
320
321 return VINF_SUCCESS;
322 }
323 AssertMsg(pDrv->fSuspended, ("drvKbdQueueReleaseKeys: Queue is full!!!!\n"));
324 return VERR_PDM_NO_QUEUE_ITEMS;
325}
326
327
328/* -=-=-=-=- IConnector -=-=-=-=- */
329
330#define PPDMIKEYBOARDCONNECTOR_2_DRVKBDQUEUE(pInterface) ( (PDRVKBDQUEUE)((char *)(pInterface) - RT_UOFFSETOF(DRVKBDQUEUE, IConnector)) )
331
332
333/**
334 * Pass LED status changes from the guest thru to the frontend driver.
335 *
336 * @param pInterface Pointer to the keyboard connector interface structure.
337 * @param enmLeds The new LED mask.
338 */
339static DECLCALLBACK(void) drvKbdPassThruLedsChange(PPDMIKEYBOARDCONNECTOR pInterface, PDMKEYBLEDS enmLeds)
340{
341 PDRVKBDQUEUE pDrv = PPDMIKEYBOARDCONNECTOR_2_DRVKBDQUEUE(pInterface);
342 pDrv->pDownConnector->pfnLedStatusChange(pDrv->pDownConnector, enmLeds);
343}
344
345/**
346 * Pass keyboard state changes from the guest thru to the frontend driver.
347 *
348 * @param pInterface Pointer to the keyboard connector interface structure.
349 * @param fActive The new active/inactive state.
350 */
351static DECLCALLBACK(void) drvKbdPassThruSetActive(PPDMIKEYBOARDCONNECTOR pInterface, bool fActive)
352{
353 PDRVKBDQUEUE pDrv = PPDMIKEYBOARDCONNECTOR_2_DRVKBDQUEUE(pInterface);
354
355 AssertPtr(pDrv->pDownConnector->pfnSetActive);
356 pDrv->pDownConnector->pfnSetActive(pDrv->pDownConnector, fActive);
357}
358
359/**
360 * Flush the keyboard queue if there are pending events.
361 *
362 * @param pInterface Pointer to the keyboard connector interface structure.
363 */
364static DECLCALLBACK(void) drvKbdFlushQueue(PPDMIKEYBOARDCONNECTOR pInterface)
365{
366 PDRVKBDQUEUE pDrv = PPDMIKEYBOARDCONNECTOR_2_DRVKBDQUEUE(pInterface);
367
368 PDMDrvHlpQueueFlushIfNecessary(pDrv->pDrvIns, pDrv->hQueue);
369}
370
371
372/* -=-=-=-=- queue -=-=-=-=- */
373
374/**
375 * Queue callback for processing a queued item.
376 *
377 * @returns Success indicator.
378 * If false the item will not be removed and the flushing will stop.
379 * @param pDrvIns The driver instance.
380 * @param pItemCore Pointer to the queue item to process.
381 */
382static DECLCALLBACK(bool) drvKbdQueueConsumer(PPDMDRVINS pDrvIns, PPDMQUEUEITEMCORE pItemCore)
383{
384 PDRVKBDQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVKBDQUEUE);
385 PDRVKBDQUEUEITEM pItem = (PDRVKBDQUEUEITEM)pItemCore;
386 int rc = pThis->pUpPort->pfnPutEventHid(pThis->pUpPort, pItem->idUsage);
387 return rc != VERR_TRY_AGAIN;
388}
389
390
391/* -=-=-=-=- driver interface -=-=-=-=- */
392
393/**
394 * Power On notification.
395 *
396 * @returns VBox status code.
397 * @param pDrvIns The drive instance data.
398 */
399static DECLCALLBACK(void) drvKbdQueuePowerOn(PPDMDRVINS pDrvIns)
400{
401 PDRVKBDQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVKBDQUEUE);
402 pThis->fInactive = false;
403}
404
405
406/**
407 * Reset notification.
408 *
409 * @returns VBox status code.
410 * @param pDrvIns The drive instance data.
411 */
412static DECLCALLBACK(void) drvKbdQueueReset(PPDMDRVINS pDrvIns)
413{
414 //PDRVKBDQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVKBDQUEUE);
415 /** @todo purge the queue on reset. */
416 RT_NOREF(pDrvIns);
417}
418
419
420/**
421 * Suspend notification.
422 *
423 * @returns VBox status code.
424 * @param pDrvIns The drive instance data.
425 */
426static DECLCALLBACK(void) drvKbdQueueSuspend(PPDMDRVINS pDrvIns)
427{
428 PDRVKBDQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVKBDQUEUE);
429 pThis->fSuspended = true;
430}
431
432
433/**
434 * Resume notification.
435 *
436 * @returns VBox status code.
437 * @param pDrvIns The drive instance data.
438 */
439static DECLCALLBACK(void) drvKbdQueueResume(PPDMDRVINS pDrvIns)
440{
441 PDRVKBDQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVKBDQUEUE);
442 pThis->fInactive = false;
443 pThis->fSuspended = false;
444}
445
446
447/**
448 * Power Off notification.
449 *
450 * @param pDrvIns The drive instance data.
451 */
452static DECLCALLBACK(void) drvKbdQueuePowerOff(PPDMDRVINS pDrvIns)
453{
454 PDRVKBDQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVKBDQUEUE);
455 pThis->fInactive = true;
456}
457
458
459/**
460 * Construct a keyboard driver instance.
461 *
462 * @copydoc FNPDMDRVCONSTRUCT
463 */
464static DECLCALLBACK(int) drvKbdQueueConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
465{
466 PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
467 PDRVKBDQUEUE pDrv = PDMINS_2_DATA(pDrvIns, PDRVKBDQUEUE);
468 PCPDMDRVHLPR3 pHlp = pDrvIns->pHlpR3;
469
470 LogFlow(("drvKbdQueueConstruct: iInstance=%d\n", pDrvIns->iInstance));
471
472
473 /*
474 * Validate configuration.
475 */
476 PDMDRV_VALIDATE_CONFIG_RETURN(pDrvIns, "QueueSize|Interval", "");
477
478 /*
479 * Init basic data members and interfaces.
480 */
481 pDrv->pDrvIns = pDrvIns;
482 pDrv->fInactive = true;
483 pDrv->fSuspended = false;
484 pDrv->XlatState = SS_IDLE;
485 /* IBase. */
486 pDrvIns->IBase.pfnQueryInterface = drvKbdQueueQueryInterface;
487 /* IKeyboardConnector. */
488 pDrv->IConnector.pfnLedStatusChange = drvKbdPassThruLedsChange;
489 pDrv->IConnector.pfnSetActive = drvKbdPassThruSetActive;
490 pDrv->IConnector.pfnFlushQueue = drvKbdFlushQueue;
491 /* IKeyboardPort. */
492 pDrv->IPort.pfnPutEventScan = drvKbdQueuePutEventScan;
493 pDrv->IPort.pfnPutEventHid = drvKbdQueuePutEventHid;
494 pDrv->IPort.pfnReleaseKeys = drvKbdQueueReleaseKeys;
495
496 /*
497 * Get the IKeyboardPort interface of the above driver/device.
498 */
499 pDrv->pUpPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIKEYBOARDPORT);
500 AssertMsgReturn(pDrv->pUpPort, ("Configuration error: No keyboard port interface above!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE);
501
502 /*
503 * Attach driver below and query it's connector interface.
504 */
505 PPDMIBASE pDownBase;
506 int rc = PDMDrvHlpAttach(pDrvIns, fFlags, &pDownBase);
507 AssertMsgRCReturn(rc, ("Failed to attach driver below us! rc=%Rra\n", rc), rc);
508
509 pDrv->pDownConnector = PDMIBASE_QUERY_INTERFACE(pDownBase, PDMIKEYBOARDCONNECTOR);
510 AssertMsgReturn(pDrv->pDownConnector, ("Configuration error: No keyboard connector interface below!\n"),
511 VERR_PDM_MISSING_INTERFACE_BELOW);
512
513 /*
514 * Create the queue.
515 */
516 uint32_t cMilliesInterval = 0;
517 rc = pHlp->pfnCFGMQueryU32(pCfg, "Interval", &cMilliesInterval);
518 if (rc == VERR_CFGM_VALUE_NOT_FOUND)
519 cMilliesInterval = 0;
520 else
521 AssertMsgRCReturn(rc, ("Configuration error: 32-bit \"Interval\" -> rc=%Rrc\n", rc), rc);
522
523 uint32_t cItems = 0;
524 rc = pHlp->pfnCFGMQueryU32(pCfg, "QueueSize", &cItems);
525 if (rc == VERR_CFGM_VALUE_NOT_FOUND)
526 cItems = 128;
527 else
528 AssertMsgRCReturn(rc, ("Configuration error: 32-bit \"QueueSize\" -> rc=%Rrc\n", rc), rc);
529
530 rc = PDMDrvHlpQueueCreate(pDrvIns, sizeof(DRVKBDQUEUEITEM), cItems, cMilliesInterval,
531 drvKbdQueueConsumer, "Keyboard", &pDrv->hQueue);
532 AssertMsgRCReturn(rc, ("Failed to create driver: cItems=%d cMilliesInterval=%d rc=%Rrc\n", cItems, cMilliesInterval, rc), rc);
533
534 return VINF_SUCCESS;
535}
536
537
538/**
539 * Keyboard queue driver registration record.
540 */
541const PDMDRVREG g_DrvKeyboardQueue =
542{
543 /* u32Version */
544 PDM_DRVREG_VERSION,
545 /* szName */
546 "KeyboardQueue",
547 /* szRCMod */
548 "",
549 /* szR0Mod */
550 "",
551 /* pszDescription */
552 "Keyboard queue driver to plug in between the key source and the device to do queueing and inter-thread transport.",
553 /* fFlags */
554 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
555 /* fClass. */
556 PDM_DRVREG_CLASS_KEYBOARD,
557 /* cMaxInstances */
558 ~0U,
559 /* cbInstance */
560 sizeof(DRVKBDQUEUE),
561 /* pfnConstruct */
562 drvKbdQueueConstruct,
563 /* pfnRelocate */
564 NULL,
565 /* pfnDestruct */
566 NULL,
567 /* pfnIOCtl */
568 NULL,
569 /* pfnPowerOn */
570 drvKbdQueuePowerOn,
571 /* pfnReset */
572 drvKbdQueueReset,
573 /* pfnSuspend */
574 drvKbdQueueSuspend,
575 /* pfnResume */
576 drvKbdQueueResume,
577 /* pfnAttach */
578 NULL,
579 /* pfnDetach */
580 NULL,
581 /* pfnPowerOff */
582 drvKbdQueuePowerOff,
583 /* pfnSoftReset */
584 NULL,
585 /* u32EndVersion */
586 PDM_DRVREG_VERSION
587};
588
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