VirtualBox

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

Last change on this file since 106061 was 106061, checked in by vboxsync, 2 months ago

Copyright year updates by scm.

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