VirtualBox

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

Last change on this file since 95551 was 95551, checked in by vboxsync, 2 years ago

DrvKeyboardQueue: Added PS/2 to USB HID translation for consumer control and desktop control keys (see bugref:10256).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 21.2 KB
Line 
1/* $Id: DrvKeyboardQueue.cpp 95551 2022-07-07 13:18:09Z 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/* Keyboard usage page (07h). */
116#define KB(key) (RT_MAKE_U32(0, USB_HID_KB_PAGE) | (uint16_t)key)
117/* Consumer Control usage page (0Ch). */
118#define CC(key) (RT_MAKE_U32(0, USB_HID_CC_PAGE) | (uint16_t)key)
119/* Generic Desktop Control usage page (01h). */
120#define DC(key) (RT_MAKE_U32(0, USB_HID_DC_PAGE) | (uint16_t)key)
121
122/** Lookup table for extended scancodes (arrow keys etc.).
123 * Some of these keys use HID usage pages other than the
124 * standard (07). */
125static const uint32_t aExtScan2Hid[] =
126{
127 KB(0x000), KB(0x000), KB(0x000), KB(0x000), KB(0x000), KB(0x000), KB(0x000), KB(0x000), /* 00-07 */
128 KB(0x000), KB(0x000), KB(0x000), KB(0x000), KB(0x000), KB(0x000), KB(0x000), KB(0x000), /* 08-1F */
129 CC(0x0B6), KB(0x000), KB(0x000), KB(0x000), KB(0x000), KB(0x000), KB(0x000), KB(0x000), /* 10-17 */
130 KB(0x000), CC(0x0B5), KB(0x000), KB(0x000), KB(0x058), KB(0x0e4), KB(0x000), KB(0x000), /* 18-1F */
131 CC(0x0E2), CC(0x192), CC(0x0CD), KB(0x000), CC(0x0B7), KB(0x000), KB(0x000), KB(0x000), /* 20-27 */
132 KB(0x000), KB(0x000), KB(0x000), KB(0x000), KB(0x000), KB(0x000), CC(0x0EA), KB(0x000), /* 28-2F */
133 CC(0x0E9), KB(0x000), CC(0x223), KB(0x000), KB(0x000), KB(0x054), KB(0x000), KB(0x046), /* 30-37 */
134 /* Sun-specific keys. Most of the XT codes are made up */
135 KB(0x0e6), KB(0x000), KB(0x000), KB(0x075), KB(0x076), KB(0x077), KB(0x0A3), KB(0x078), /* 38-3F */
136 KB(0x080), KB(0x081), KB(0x082), KB(0x079), KB(0x000), KB(0x000), KB(0x048), KB(0x04a), /* 40-47 */
137 KB(0x052), KB(0x04b), KB(0x000), KB(0x050), KB(0x000), KB(0x04f), KB(0x000), KB(0x04d), /* 48-4F */
138 KB(0x051), KB(0x04e), KB(0x049), KB(0x04c), KB(0x000), KB(0x000), KB(0x000), KB(0x000), /* 50-57 */
139 KB(0x000), KB(0x000), KB(0x000), KB(0x0e3), KB(0x0e7), KB(0x065), KB(0x066), DC(0x082), /* 58-5F */
140 KB(0x000), KB(0x000), KB(0x000), DC(0x083), KB(0x000), CC(0x221), CC(0x22A), CC(0x227), /* 60-67 */
141 CC(0x226), CC(0x225), CC(0x224), CC(0x194), CC(0x18A), CC(0x183), KB(0x000), KB(0x000), /* 68-6F */
142 KB(0x000), KB(0x000), KB(0x000), KB(0x000), KB(0x000), KB(0x000), KB(0x000), KB(0x000), /* 70-77 */
143 KB(0x000), KB(0x000), KB(0x000), KB(0x000), KB(0x000), KB(0x000), KB(0x000), KB(0x000) /* 78-7F */
144};
145
146/**
147 * Convert a PC scan code to a USB HID usage byte.
148 *
149 * @param state Current state of the translator (scan_state_t).
150 * @param scanCode Incoming scan code.
151 * @param pUsage Pointer to usage; high bit set for key up events. The
152 * contents are only valid if returned state is SS_IDLE.
153 *
154 * @return scan_state_t New state of the translator.
155 */
156static scan_state_t ScancodeToHidUsage(scan_state_t state, uint8_t scanCode, uint32_t *pUsage)
157{
158 uint32_t keyUp;
159 uint32_t usagePg;
160 uint8_t usage;
161
162 Assert(pUsage);
163
164 /* Isolate the scan code and key break flag. */
165 keyUp = (scanCode & 0x80) ? PDMIKBDPORT_KEY_UP : 0;
166
167 switch (state) {
168 case SS_IDLE:
169 if (scanCode == 0xE0) {
170 state = SS_EXT;
171 } else if (scanCode == 0xE1) {
172 state = SS_EXT1;
173 } else {
174 usage = aScancode2Hid[scanCode & 0x7F];
175 AssertMsg(usage, ("SS_IDLE: scanCode=%02X\n", scanCode));
176 *pUsage = usage | keyUp | HID_PG_KB_BITS;
177 /* Remain in SS_IDLE state. */
178 }
179 break;
180 case SS_EXT:
181 usagePg = aExtScan2Hid[scanCode & 0x7F];
182 AssertMsg(usagePg, ("SS_EXT: scanCode=%02X\n", scanCode));
183 *pUsage = usagePg | keyUp;
184 state = SS_IDLE;
185 break;
186 case SS_EXT1:
187 /* The sequence is E1 1D 45 E1 9D C5. We take the easy way out and remain
188 * in the SS_EXT1 state until 45 or C5 is received.
189 */
190 if ((scanCode & 0x7F) == 0x45) {
191 *pUsage = 0x48 | HID_PG_KB_BITS;
192 if (scanCode == 0xC5)
193 *pUsage |= keyUp;
194 state = SS_IDLE;
195 }
196 /* Else remain in SS_EXT1 state. */
197 break;
198 }
199 return state;
200}
201
202
203/* -=-=-=-=- IBase -=-=-=-=- */
204
205/**
206 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
207 */
208static DECLCALLBACK(void *) drvKbdQueueQueryInterface(PPDMIBASE pInterface, const char *pszIID)
209{
210 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
211 PDRVKBDQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVKBDQUEUE);
212
213 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
214 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIKEYBOARDCONNECTOR, &pThis->IConnector);
215 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIKEYBOARDPORT, &pThis->IPort);
216 return NULL;
217}
218
219
220/* -=-=-=-=- IKeyboardPort -=-=-=-=- */
221
222/** Converts a pointer to DRVKBDQUEUE::IPort to a DRVKBDQUEUE pointer. */
223#define IKEYBOARDPORT_2_DRVKBDQUEUE(pInterface) ( (PDRVKBDQUEUE)((char *)(pInterface) - RT_UOFFSETOF(DRVKBDQUEUE, IPort)) )
224
225
226/**
227 * @interface_method_impl{PDMIKEYBOARDPORT,pfnPutEventScan}
228 *
229 * Because of the event queueing the EMT context requirement is lifted.
230 * @thread Any thread.
231 */
232static DECLCALLBACK(int) drvKbdQueuePutEventScan(PPDMIKEYBOARDPORT pInterface, uint8_t u8ScanCode)
233{
234 PDRVKBDQUEUE pDrv = IKEYBOARDPORT_2_DRVKBDQUEUE(pInterface);
235 /* Ignore any attempt to send events if queue is inactive. */
236 if (pDrv->fInactive)
237 return VINF_SUCCESS;
238
239 uint32_t idUsage = 0;
240 pDrv->XlatState = ScancodeToHidUsage(pDrv->XlatState, u8ScanCode, &idUsage);
241
242 if (pDrv->XlatState == SS_IDLE)
243 {
244 PDRVKBDQUEUEITEM pItem = (PDRVKBDQUEUEITEM)PDMDrvHlpQueueAlloc(pDrv->pDrvIns, pDrv->hQueue);
245 if (pItem)
246 {
247 /*
248 * Work around incredibly poorly desgined Korean keyboards which
249 * only send break events for Hangul/Hanja keys -- convert a lone
250 * key up into a key up/key down sequence.
251 */
252 if ( (idUsage == (PDMIKBDPORT_KEY_UP | HID_PG_KB_BITS | 0x90))
253 || (idUsage == (PDMIKBDPORT_KEY_UP | HID_PG_KB_BITS | 0x91)))
254 {
255 PDRVKBDQUEUEITEM pItem2 = (PDRVKBDQUEUEITEM)PDMDrvHlpQueueAlloc(pDrv->pDrvIns, pDrv->hQueue);
256 /*
257 * NB: If there's no room in the queue, we will drop the faked
258 * key down event. Probably less bad than the alternatives.
259 */
260 if (pItem2)
261 {
262 /* Manufacture a key down event. */
263 pItem2->idUsage = idUsage & ~PDMIKBDPORT_KEY_UP;
264 PDMDrvHlpQueueInsert(pDrv->pDrvIns, pDrv->hQueue, &pItem2->Core);
265 }
266 }
267
268 pItem->idUsage = idUsage;
269 PDMDrvHlpQueueInsert(pDrv->pDrvIns, pDrv->hQueue, &pItem->Core);
270
271 return VINF_SUCCESS;
272 }
273 if (!pDrv->fSuspended)
274 AssertMsgFailed(("drvKbdQueuePutEventScan: Queue is full!!!!\n"));
275 return VERR_PDM_NO_QUEUE_ITEMS;
276 }
277 return VINF_SUCCESS;
278}
279
280
281/**
282 * @interface_method_impl{PDMIKEYBOARDPORT,pfnPutEventHid}
283 *
284 * Because of the event queueing the EMT context requirement is lifted.
285 * @thread Any thread.
286 */
287static DECLCALLBACK(int) drvKbdQueuePutEventHid(PPDMIKEYBOARDPORT pInterface, uint32_t idUsage)
288{
289 PDRVKBDQUEUE pDrv = IKEYBOARDPORT_2_DRVKBDQUEUE(pInterface);
290 /* Ignore any attempt to send events if queue is inactive. */
291 if (pDrv->fInactive)
292 return VINF_SUCCESS;
293
294 PDRVKBDQUEUEITEM pItem = (PDRVKBDQUEUEITEM)PDMDrvHlpQueueAlloc(pDrv->pDrvIns, pDrv->hQueue);
295 if (pItem)
296 {
297 pItem->idUsage = idUsage;
298 PDMDrvHlpQueueInsert(pDrv->pDrvIns, pDrv->hQueue, &pItem->Core);
299
300 return VINF_SUCCESS;
301 }
302 AssertMsg(pDrv->fSuspended, ("drvKbdQueuePutEventHid: Queue is full!!!!\n"));
303 return VERR_PDM_NO_QUEUE_ITEMS;
304}
305
306
307/**
308 * @interface_method_impl{PDMIKEYBOARDPORT,pfnReleaseKeys}
309 *
310 * Because of the event queueing the EMT context requirement is lifted.
311 * @thread Any thread.
312 */
313static DECLCALLBACK(int) drvKbdQueueReleaseKeys(PPDMIKEYBOARDPORT pInterface)
314{
315 PDRVKBDQUEUE pDrv = IKEYBOARDPORT_2_DRVKBDQUEUE(pInterface);
316
317 /* Ignore any attempt to send events if queue is inactive. */
318 if (pDrv->fInactive)
319 return VINF_SUCCESS;
320
321 PDRVKBDQUEUEITEM pItem = (PDRVKBDQUEUEITEM)PDMDrvHlpQueueAlloc(pDrv->pDrvIns, pDrv->hQueue);
322 if (pItem)
323 {
324 /* Send a special key event that forces all keys to be released.
325 * Goes through the queue so that it would take effect only after
326 * any key events that might already be queued up.
327 */
328 pItem->idUsage = PDMIKBDPORT_RELEASE_KEYS | HID_PG_KB_BITS;
329 PDMDrvHlpQueueInsert(pDrv->pDrvIns, pDrv->hQueue, &pItem->Core);
330
331 return VINF_SUCCESS;
332 }
333 AssertMsg(pDrv->fSuspended, ("drvKbdQueueReleaseKeys: Queue is full!!!!\n"));
334 return VERR_PDM_NO_QUEUE_ITEMS;
335}
336
337
338/* -=-=-=-=- IConnector -=-=-=-=- */
339
340#define PPDMIKEYBOARDCONNECTOR_2_DRVKBDQUEUE(pInterface) ( (PDRVKBDQUEUE)((char *)(pInterface) - RT_UOFFSETOF(DRVKBDQUEUE, IConnector)) )
341
342
343/**
344 * Pass LED status changes from the guest thru to the frontend driver.
345 *
346 * @param pInterface Pointer to the keyboard connector interface structure.
347 * @param enmLeds The new LED mask.
348 */
349static DECLCALLBACK(void) drvKbdPassThruLedsChange(PPDMIKEYBOARDCONNECTOR pInterface, PDMKEYBLEDS enmLeds)
350{
351 PDRVKBDQUEUE pDrv = PPDMIKEYBOARDCONNECTOR_2_DRVKBDQUEUE(pInterface);
352 pDrv->pDownConnector->pfnLedStatusChange(pDrv->pDownConnector, enmLeds);
353}
354
355/**
356 * Pass keyboard state changes from the guest thru to the frontend driver.
357 *
358 * @param pInterface Pointer to the keyboard connector interface structure.
359 * @param fActive The new active/inactive state.
360 */
361static DECLCALLBACK(void) drvKbdPassThruSetActive(PPDMIKEYBOARDCONNECTOR pInterface, bool fActive)
362{
363 PDRVKBDQUEUE pDrv = PPDMIKEYBOARDCONNECTOR_2_DRVKBDQUEUE(pInterface);
364
365 AssertPtr(pDrv->pDownConnector->pfnSetActive);
366 pDrv->pDownConnector->pfnSetActive(pDrv->pDownConnector, fActive);
367}
368
369/**
370 * Flush the keyboard queue if there are pending events.
371 *
372 * @param pInterface Pointer to the keyboard connector interface structure.
373 */
374static DECLCALLBACK(void) drvKbdFlushQueue(PPDMIKEYBOARDCONNECTOR pInterface)
375{
376 PDRVKBDQUEUE pDrv = PPDMIKEYBOARDCONNECTOR_2_DRVKBDQUEUE(pInterface);
377
378 PDMDrvHlpQueueFlushIfNecessary(pDrv->pDrvIns, pDrv->hQueue);
379}
380
381
382/* -=-=-=-=- queue -=-=-=-=- */
383
384/**
385 * Queue callback for processing a queued item.
386 *
387 * @returns Success indicator.
388 * If false the item will not be removed and the flushing will stop.
389 * @param pDrvIns The driver instance.
390 * @param pItemCore Pointer to the queue item to process.
391 */
392static DECLCALLBACK(bool) drvKbdQueueConsumer(PPDMDRVINS pDrvIns, PPDMQUEUEITEMCORE pItemCore)
393{
394 PDRVKBDQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVKBDQUEUE);
395 PDRVKBDQUEUEITEM pItem = (PDRVKBDQUEUEITEM)pItemCore;
396 int rc = pThis->pUpPort->pfnPutEventHid(pThis->pUpPort, pItem->idUsage);
397 return rc != VERR_TRY_AGAIN;
398}
399
400
401/* -=-=-=-=- driver interface -=-=-=-=- */
402
403/**
404 * Power On notification.
405 *
406 * @returns VBox status code.
407 * @param pDrvIns The drive instance data.
408 */
409static DECLCALLBACK(void) drvKbdQueuePowerOn(PPDMDRVINS pDrvIns)
410{
411 PDRVKBDQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVKBDQUEUE);
412 pThis->fInactive = false;
413}
414
415
416/**
417 * Reset notification.
418 *
419 * @returns VBox status code.
420 * @param pDrvIns The drive instance data.
421 */
422static DECLCALLBACK(void) drvKbdQueueReset(PPDMDRVINS pDrvIns)
423{
424 //PDRVKBDQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVKBDQUEUE);
425 /** @todo purge the queue on reset. */
426 RT_NOREF(pDrvIns);
427}
428
429
430/**
431 * Suspend notification.
432 *
433 * @returns VBox status code.
434 * @param pDrvIns The drive instance data.
435 */
436static DECLCALLBACK(void) drvKbdQueueSuspend(PPDMDRVINS pDrvIns)
437{
438 PDRVKBDQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVKBDQUEUE);
439 pThis->fSuspended = true;
440}
441
442
443/**
444 * Resume notification.
445 *
446 * @returns VBox status code.
447 * @param pDrvIns The drive instance data.
448 */
449static DECLCALLBACK(void) drvKbdQueueResume(PPDMDRVINS pDrvIns)
450{
451 PDRVKBDQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVKBDQUEUE);
452 pThis->fInactive = false;
453 pThis->fSuspended = false;
454}
455
456
457/**
458 * Power Off notification.
459 *
460 * @param pDrvIns The drive instance data.
461 */
462static DECLCALLBACK(void) drvKbdQueuePowerOff(PPDMDRVINS pDrvIns)
463{
464 PDRVKBDQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVKBDQUEUE);
465 pThis->fInactive = true;
466}
467
468
469/**
470 * Construct a keyboard driver instance.
471 *
472 * @copydoc FNPDMDRVCONSTRUCT
473 */
474static DECLCALLBACK(int) drvKbdQueueConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
475{
476 PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
477 PDRVKBDQUEUE pDrv = PDMINS_2_DATA(pDrvIns, PDRVKBDQUEUE);
478 PCPDMDRVHLPR3 pHlp = pDrvIns->pHlpR3;
479
480 LogFlow(("drvKbdQueueConstruct: iInstance=%d\n", pDrvIns->iInstance));
481
482
483 /*
484 * Validate configuration.
485 */
486 PDMDRV_VALIDATE_CONFIG_RETURN(pDrvIns, "QueueSize|Interval", "");
487
488 /*
489 * Init basic data members and interfaces.
490 */
491 pDrv->pDrvIns = pDrvIns;
492 pDrv->fInactive = true;
493 pDrv->fSuspended = false;
494 pDrv->XlatState = SS_IDLE;
495 /* IBase. */
496 pDrvIns->IBase.pfnQueryInterface = drvKbdQueueQueryInterface;
497 /* IKeyboardConnector. */
498 pDrv->IConnector.pfnLedStatusChange = drvKbdPassThruLedsChange;
499 pDrv->IConnector.pfnSetActive = drvKbdPassThruSetActive;
500 pDrv->IConnector.pfnFlushQueue = drvKbdFlushQueue;
501 /* IKeyboardPort. */
502 pDrv->IPort.pfnPutEventScan = drvKbdQueuePutEventScan;
503 pDrv->IPort.pfnPutEventHid = drvKbdQueuePutEventHid;
504 pDrv->IPort.pfnReleaseKeys = drvKbdQueueReleaseKeys;
505
506 /*
507 * Get the IKeyboardPort interface of the above driver/device.
508 */
509 pDrv->pUpPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIKEYBOARDPORT);
510 AssertMsgReturn(pDrv->pUpPort, ("Configuration error: No keyboard port interface above!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE);
511
512 /*
513 * Attach driver below and query it's connector interface.
514 */
515 PPDMIBASE pDownBase;
516 int rc = PDMDrvHlpAttach(pDrvIns, fFlags, &pDownBase);
517 AssertMsgRCReturn(rc, ("Failed to attach driver below us! rc=%Rra\n", rc), rc);
518
519 pDrv->pDownConnector = PDMIBASE_QUERY_INTERFACE(pDownBase, PDMIKEYBOARDCONNECTOR);
520 AssertMsgReturn(pDrv->pDownConnector, ("Configuration error: No keyboard connector interface below!\n"),
521 VERR_PDM_MISSING_INTERFACE_BELOW);
522
523 /*
524 * Create the queue.
525 */
526 uint32_t cMilliesInterval = 0;
527 rc = pHlp->pfnCFGMQueryU32(pCfg, "Interval", &cMilliesInterval);
528 if (rc == VERR_CFGM_VALUE_NOT_FOUND)
529 cMilliesInterval = 0;
530 else
531 AssertMsgRCReturn(rc, ("Configuration error: 32-bit \"Interval\" -> rc=%Rrc\n", rc), rc);
532
533 uint32_t cItems = 0;
534 rc = pHlp->pfnCFGMQueryU32(pCfg, "QueueSize", &cItems);
535 if (rc == VERR_CFGM_VALUE_NOT_FOUND)
536 cItems = 128;
537 else
538 AssertMsgRCReturn(rc, ("Configuration error: 32-bit \"QueueSize\" -> rc=%Rrc\n", rc), rc);
539
540 rc = PDMDrvHlpQueueCreate(pDrvIns, sizeof(DRVKBDQUEUEITEM), cItems, cMilliesInterval,
541 drvKbdQueueConsumer, "Keyboard", &pDrv->hQueue);
542 AssertMsgRCReturn(rc, ("Failed to create driver: cItems=%d cMilliesInterval=%d rc=%Rrc\n", cItems, cMilliesInterval, rc), rc);
543
544 return VINF_SUCCESS;
545}
546
547
548/**
549 * Keyboard queue driver registration record.
550 */
551const PDMDRVREG g_DrvKeyboardQueue =
552{
553 /* u32Version */
554 PDM_DRVREG_VERSION,
555 /* szName */
556 "KeyboardQueue",
557 /* szRCMod */
558 "",
559 /* szR0Mod */
560 "",
561 /* pszDescription */
562 "Keyboard queue driver to plug in between the key source and the device to do queueing and inter-thread transport.",
563 /* fFlags */
564 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
565 /* fClass. */
566 PDM_DRVREG_CLASS_KEYBOARD,
567 /* cMaxInstances */
568 ~0U,
569 /* cbInstance */
570 sizeof(DRVKBDQUEUE),
571 /* pfnConstruct */
572 drvKbdQueueConstruct,
573 /* pfnRelocate */
574 NULL,
575 /* pfnDestruct */
576 NULL,
577 /* pfnIOCtl */
578 NULL,
579 /* pfnPowerOn */
580 drvKbdQueuePowerOn,
581 /* pfnReset */
582 drvKbdQueueReset,
583 /* pfnSuspend */
584 drvKbdQueueSuspend,
585 /* pfnResume */
586 drvKbdQueueResume,
587 /* pfnAttach */
588 NULL,
589 /* pfnDetach */
590 NULL,
591 /* pfnPowerOff */
592 drvKbdQueuePowerOff,
593 /* pfnSoftReset */
594 NULL,
595 /* u32EndVersion */
596 PDM_DRVREG_VERSION
597};
598
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