VirtualBox

source: vbox/trunk/src/VBox/Devices/Input/PS2M.cpp@ 51898

Last change on this file since 51898 was 50998, checked in by vboxsync, 10 years ago

PS2M: Clear any buffered command response if command reissued.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 39.4 KB
Line 
1/** @file
2 * PS2M - PS/2 auxiliary device (mouse) emulation.
3 */
4
5/*
6 * Copyright (C) 2007-2013 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 */
16
17/*
18 * References:
19 *
20 * The Undocumented PC (2nd Ed.), Frank van Gilluwe, Addison-Wesley, 1996.
21 * IBM TrackPoint System Version 4.0 Engineering Specification, 1999.
22 * ELAN Microelectronics eKM8025 USB & PS/2 Mouse Controller, 2006.
23 *
24 *
25 * Notes:
26 *
27 * - The auxiliary device commands are very similar to keyboard commands.
28 * Most keyboard commands which do not specifically deal with the keyboard
29 * (enable, disable, reset) have identical counterparts.
30 * - The code refers to 'auxiliary device' and 'mouse'; these terms are not
31 * quite interchangeable. 'Auxiliary device' is used when referring to the
32 * generic PS/2 auxiliary device interface and 'mouse' when referring to
33 * a mouse attached to the auxiliary port.
34 * - The basic modes of operation are reset, stream, and remote. Those are
35 * mutually exclusive. Stream and remote modes can additionally have wrap
36 * mode enabled.
37 * - The auxiliary device sends unsolicited data to the host only when it is
38 * both in stream mode and enabled. Otherwise it only responds to commands.
39 *
40 *
41 * There are three report packet formats supported by the emulated device. The
42 * standard three-byte PS/2 format (with middle button support), IntelliMouse
43 * four-byte format with added scroll wheel, and IntelliMouse Explorer four-byte
44 * format with reduced scroll wheel range but two additional buttons. Note that
45 * the first three bytes of the report are always the same.
46 *
47 * Upon reset, the mouse is always in the standard PS/2 mode. A special 'knock'
48 * sequence can be used to switch to ImPS/2 or ImEx mode. Three consecutive
49 * Set Sampling Rate (0F3h) commands with arguments 200, 100, 80 switch to ImPS/2
50 * mode. While in ImPS/2 or PS/2 mode, three consecutive Set Sampling Rate
51 * commands with arguments 200, 200, 80 switch to ImEx mode. The Read ID (0F2h)
52 * command will report the currently selected protocol.
53 *
54 *
55 * Standard PS/2 pointing device three-byte report packet format:
56 *
57 * +--------+--------+--------+--------+--------+--------+--------+--------+--------+
58 * |Bit/byte| bit 7 | bit 6 | bit 5 | bit 4 | bit 3 | bit 2 | bit 1 | bit 0 |
59 * +--------+--------+--------+--------+--------+--------+--------+--------+--------+
60 * | Byte 1 | Y ovfl | X ovfl | Y sign | X sign | Sync | M btn | R btn | L btn |
61 * +--------+--------+--------+--------+--------+--------+--------+--------+--------+
62 * | Byte 2 | X movement delta (two's complement) |
63 * +--------+--------+--------+--------+--------+--------+--------+--------+--------+
64 * | Byte 3 | Y movement delta (two's complement) |
65 * +--------+--------+--------+--------+--------+--------+--------+--------+--------+
66 *
67 * - The sync bit is always set. It allows software to synchronize data packets
68 * as the X/Y position data typically does not have bit 4 set.
69 * - The overflow bits are set if motion exceeds accumulator range. We use the
70 * maximum range (effectively 9 bits) and do not set the overflow bits.
71 * - Movement in the up/right direction is defined as having positive sign.
72 *
73 *
74 * IntelliMouse PS/2 (ImPS/2) fourth report packet byte:
75 *
76 * +--------+--------+--------+--------+--------+--------+--------+--------+--------+
77 * |Bit/byte| bit 7 | bit 6 | bit 5 | bit 4 | bit 3 | bit 2 | bit 1 | bit 0 |
78 * +--------+--------+--------+--------+--------+--------+--------+--------+--------+
79 * | Byte 4 | Z movement delta (two's complement) |
80 * +--------+--------+--------+--------+--------+--------+--------+--------+--------+
81 *
82 * - The valid range for Z delta values is only -8/+7, i.e. 4 bits.
83 *
84 * IntelliMouse Explorer (ImEx) fourth report packet byte:
85 *
86 * +--------+--------+--------+--------+--------+--------+--------+--------+--------+
87 * |Bit/byte| bit 7 | bit 6 | bit 5 | bit 4 | bit 3 | bit 2 | bit 1 | bit 0 |
88 * +--------+--------+--------+--------+--------+--------+--------+--------+--------+
89 * | Byte 4 | 0 | 0 | Btn 5 | Btn 4 | Z mov't delta (two's complement) |
90 * +--------+--------+--------+--------+--------+--------+--------+--------+--------+
91 *
92 */
93
94
95/*******************************************************************************
96* Header Files *
97*******************************************************************************/
98#define LOG_GROUP LOG_GROUP_DEV_KBD
99#include <VBox/vmm/pdmdev.h>
100#include <VBox/err.h>
101#include <iprt/assert.h>
102#include <iprt/uuid.h>
103#include "VBoxDD.h"
104#define IN_PS2M
105#include "PS2Dev.h"
106
107/*******************************************************************************
108* Defined Constants And Macros *
109*******************************************************************************/
110/** @name Auxiliary device commands sent by the system.
111 * @{ */
112#define ACMD_SET_SCALE_11 0xE6 /* Set 1:1 scaling. */
113#define ACMD_SET_SCALE_21 0xE7 /* Set 2:1 scaling. */
114#define ACMD_SET_RES 0xE8 /* Set resolution. */
115#define ACMD_REQ_STATUS 0xE9 /* Get device status. */
116#define ACMD_SET_STREAM 0xEA /* Set stream mode. */
117#define ACMD_READ_REMOTE 0xEB /* Read remote data. */
118#define ACMD_RESET_WRAP 0xEC /* Exit wrap mode. */
119#define ACMD_INVALID_1 0xED
120#define ACMD_SET_WRAP 0xEE /* Set wrap (echo) mode. */
121#define ACMD_INVALID_2 0xEF
122#define ACMD_SET_REMOTE 0xF0 /* Set remote mode. */
123#define ACMD_INVALID_3 0xF1
124#define ACMD_READ_ID 0xF2 /* Read device ID. */
125#define ACMD_SET_SAMP_RATE 0xF3 /* Set sampling rate. */
126#define ACMD_ENABLE 0xF4 /* Enable (streaming mode). */
127#define ACMD_DFLT_DISABLE 0xF5 /* Disable and set defaults. */
128#define ACMD_SET_DEFAULT 0xF6 /* Set defaults. */
129#define ACMD_INVALID_4 0xF7
130#define ACMD_INVALID_5 0xF8
131#define ACMD_INVALID_6 0xF9
132#define ACMD_INVALID_7 0xFA
133#define ACMD_INVALID_8 0xFB
134#define ACMD_INVALID_9 0xFC
135#define ACMD_INVALID_10 0xFD
136#define ACMD_RESEND 0xFE /* Resend response. */
137#define ACMD_RESET 0xFF /* Reset device. */
138/** @} */
139
140/** @name Auxiliary device responses sent to the system.
141 * @{ */
142#define ARSP_ID 0x00
143#define ARSP_BAT_OK 0xAA /* Self-test passed. */
144#define ARSP_ACK 0xFA /* Command acknowledged. */
145#define ARSP_ERROR 0xFC /* Bad command. */
146#define ARSP_RESEND 0xFE /* Requesting resend. */
147/** @} */
148
149/** Define a simple PS/2 input device queue. */
150#define DEF_PS2Q_TYPE(name, size) \
151 typedef struct { \
152 uint32_t rpos; \
153 uint32_t wpos; \
154 uint32_t cUsed; \
155 uint32_t cSize; \
156 uint8_t abQueue[size]; \
157 } name
158
159/* Internal mouse queue sizes. The input queue is relatively large,
160 * but the command queue only needs to handle a few bytes.
161 */
162#define AUX_EVT_QUEUE_SIZE 256
163#define AUX_CMD_QUEUE_SIZE 8
164
165/*******************************************************************************
166* Structures and Typedefs *
167*******************************************************************************/
168
169DEF_PS2Q_TYPE(AuxEvtQ, AUX_EVT_QUEUE_SIZE);
170DEF_PS2Q_TYPE(AuxCmdQ, AUX_CMD_QUEUE_SIZE);
171#ifndef VBOX_DEVICE_STRUCT_TESTCASE //@todo: hack
172DEF_PS2Q_TYPE(GeneriQ, 1);
173#endif
174
175/* Auxiliary device special modes of operation. */
176typedef enum {
177 AUX_MODE_STD, /* Standard operation. */
178 AUX_MODE_RESET, /* Currently in reset. */
179 AUX_MODE_WRAP /* Wrap mode (echoing input). */
180} PS2M_MODE;
181
182/* Auxiliary device operational state. */
183typedef enum {
184 AUX_STATE_SCALING = RT_BIT(4), /* 2:1 scaling in effect. */
185 AUX_STATE_ENABLED = RT_BIT(5), /* Reporting enabled in stream mode. */
186 AUX_STATE_REMOTE = RT_BIT(6) /* Remote mode (reports on request). */
187} PS2M_STATE;
188
189/* Protocols supported by the PS/2 mouse. */
190typedef enum {
191 PS2M_PROTO_PS2STD = 0, /* Standard PS/2 mouse protocol. */
192 PS2M_PROTO_IMPS2 = 3, /* IntelliMouse PS/2 protocol. */
193 PS2M_PROTO_IMEX = 4 /* IntelliMouse Explorer protocol. */
194} PS2M_PROTO;
195
196/* Protocol selection 'knock' states. */
197typedef enum {
198 PS2M_KNOCK_INITIAL,
199 PS2M_KNOCK_1ST,
200 PS2M_KNOCK_IMPS2_2ND,
201 PS2M_KNOCK_IMEX_2ND
202} PS2M_KNOCK_STATE;
203
204/**
205 * The PS/2 auxiliary device instance data.
206 */
207typedef struct PS2M
208{
209 /** Pointer to parent device (keyboard controller). */
210 R3PTRTYPE(void *) pParent;
211 /** Operational state. */
212 uint8_t u8State;
213 /** Configured sampling rate. */
214 uint8_t u8SampleRate;
215 /** Configured resolution. */
216 uint8_t u8Resolution;
217 /** Currently processed command (if any). */
218 uint8_t u8CurrCmd;
219 /** Set if the throttle delay is active. */
220 bool fThrottleActive;
221 /** Operational mode. */
222 PS2M_MODE enmMode;
223 /** Currently used protocol. */
224 PS2M_PROTO enmProtocol;
225 /** Currently used protocol. */
226 PS2M_KNOCK_STATE enmKnockState;
227 /** Buffer holding mouse events to be sent to the host. */
228 AuxEvtQ evtQ;
229 /** Command response queue (priority). */
230 AuxCmdQ cmdQ;
231 /** Accumulated horizontal movement. */
232 int32_t iAccumX;
233 /** Accumulated vertical movement. */
234 int32_t iAccumY;
235 /** Accumulated Z axis movement. */
236 int32_t iAccumZ;
237 /** Accumulated button presses. */
238 uint32_t fAccumB;
239 /** Throttling delay in milliseconds. */
240 unsigned uThrottleDelay;
241#if HC_ARCH_BITS == 32
242 uint32_t Alignment0;
243#endif
244
245 /** The device critical section protecting everything - R3 Ptr */
246 R3PTRTYPE(PPDMCRITSECT) pCritSectR3;
247 /** Command delay timer - R3 Ptr. */
248 PTMTIMERR3 pDelayTimerR3;
249 /** Interrupt throttling timer - R3 Ptr. */
250 PTMTIMERR3 pThrottleTimerR3;
251 RTR3PTR Alignment1;
252
253 /** Command delay timer - RC Ptr. */
254 PTMTIMERRC pDelayTimerRC;
255 /** Interrupt throttling timer - RC Ptr. */
256 PTMTIMERRC pThrottleTimerRC;
257
258 /** Command delay timer - R0 Ptr. */
259 PTMTIMERR0 pDelayTimerR0;
260 /** Interrupt throttling timer - R0 Ptr. */
261 PTMTIMERR0 pThrottleTimerR0;
262
263 /**
264 * Mouse port - LUN#1.
265 *
266 * @implements PDMIBASE
267 * @implements PDMIMOUSEPORT
268 */
269 struct
270 {
271 /** The base interface for the mouse port. */
272 PDMIBASE IBase;
273 /** The keyboard port base interface. */
274 PDMIMOUSEPORT IPort;
275
276 /** The base interface of the attached mouse driver. */
277 R3PTRTYPE(PPDMIBASE) pDrvBase;
278 /** The keyboard interface of the attached mouse driver. */
279 R3PTRTYPE(PPDMIMOUSECONNECTOR) pDrv;
280 } Mouse;
281} PS2M, *PPS2M;
282
283AssertCompile(PS2M_STRUCT_FILLER >= sizeof(PS2M));
284
285#ifndef VBOX_DEVICE_STRUCT_TESTCASE
286
287/* Key type flags. */
288#define KF_E0 0x01 /* E0 prefix. */
289#define KF_NB 0x02 /* No break code. */
290#define KF_GK 0x04 /* Gray navigation key. */
291#define KF_PS 0x08 /* Print Screen key. */
292#define KF_PB 0x10 /* Pause/Break key. */
293#define KF_NL 0x20 /* Num Lock key. */
294#define KF_NS 0x40 /* NumPad '/' key. */
295
296/*******************************************************************************
297* Global Variables *
298*******************************************************************************/
299
300
301/*******************************************************************************
302* Internal Functions *
303*******************************************************************************/
304
305
306/**
307 * Clear a queue.
308 *
309 * @param pQ Pointer to the queue.
310 */
311static void ps2kClearQueue(GeneriQ *pQ)
312{
313 LogFlowFunc(("Clearing queue %p\n", pQ));
314 pQ->wpos = pQ->rpos;
315 pQ->cUsed = 0;
316}
317
318
319/**
320 * Add a byte to a queue.
321 *
322 * @param pQ Pointer to the queue.
323 * @param val The byte to store.
324 */
325static void ps2kInsertQueue(GeneriQ *pQ, uint8_t val)
326{
327 /* Check if queue is full. */
328 if (pQ->cUsed >= pQ->cSize)
329 {
330 LogFlowFunc(("queue %p full (%d entries)\n", pQ, pQ->cUsed));
331 return;
332 }
333 /* Insert data and update circular buffer write position. */
334 pQ->abQueue[pQ->wpos] = val;
335 if (++pQ->wpos == pQ->cSize)
336 pQ->wpos = 0; /* Roll over. */
337 ++pQ->cUsed;
338 LogFlowFunc(("inserted 0x%02X into queue %p\n", val, pQ));
339}
340
341#ifdef IN_RING3
342
343/**
344 * Save a queue state.
345 *
346 * @param pSSM SSM handle to write the state to.
347 * @param pQ Pointer to the queue.
348 */
349static void ps2kSaveQueue(PSSMHANDLE pSSM, GeneriQ *pQ)
350{
351 uint32_t cItems = pQ->cUsed;
352 int i;
353
354 /* Only save the number of items. Note that the read/write
355 * positions aren't saved as they will be rebuilt on load.
356 */
357 SSMR3PutU32(pSSM, cItems);
358
359 LogFlow(("Storing %d items from queue %p\n", cItems, pQ));
360
361 /* Save queue data - only the bytes actually used (typically zero). */
362 for (i = pQ->rpos; cItems-- > 0; i = (i + 1) % pQ->cSize)
363 SSMR3PutU8(pSSM, pQ->abQueue[i]);
364}
365
366/**
367 * Load a queue state.
368 *
369 * @param pSSM SSM handle to read the state from.
370 * @param pQ Pointer to the queue.
371 *
372 * @return int VBox status/error code.
373 */
374static int ps2kLoadQueue(PSSMHANDLE pSSM, GeneriQ *pQ)
375{
376 int rc;
377
378 /* On load, always put the read pointer at zero. */
379 SSMR3GetU32(pSSM, &pQ->cUsed);
380
381 LogFlow(("Loading %d items to queue %p\n", pQ->cUsed, pQ));
382
383 if (pQ->cUsed > pQ->cSize)
384 {
385 AssertMsgFailed(("Saved size=%u, actual=%u\n", pQ->cUsed, pQ->cSize));
386 return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
387 }
388
389 /* Recalculate queue positions and load data in one go. */
390 pQ->rpos = 0;
391 pQ->wpos = pQ->cUsed;
392 rc = SSMR3GetMem(pSSM, pQ->abQueue, pQ->cUsed);
393
394 return rc;
395}
396
397/* Report a change in status down (or is it up?) the driver chain. */
398static void ps2mSetDriverState(PPS2M pThis, bool fEnabled)
399{
400 PPDMIMOUSECONNECTOR pDrv = pThis->Mouse.pDrv;
401 if (pDrv)
402 pDrv->pfnReportModes(pDrv, fEnabled, false, false);
403}
404
405#endif /* IN_RING3 */
406
407/**
408 * Retrieve a byte from a queue.
409 *
410 * @param pQ Pointer to the queue.
411 * @param pVal Pointer to storage for the byte.
412 *
413 * @return int VINF_TRY_AGAIN if queue is empty,
414 * VINF_SUCCESS if a byte was read.
415 */
416static int ps2kRemoveQueue(GeneriQ *pQ, uint8_t *pVal)
417{
418 int rc = VINF_TRY_AGAIN;
419
420 Assert(pVal);
421 if (pQ->cUsed)
422 {
423 *pVal = pQ->abQueue[pQ->rpos];
424 if (++pQ->rpos == pQ->cSize)
425 pQ->rpos = 0; /* Roll over. */
426 --pQ->cUsed;
427 rc = VINF_SUCCESS;
428 LogFlowFunc(("removed 0x%02X from queue %p\n", *pVal, pQ));
429 } else
430 LogFlowFunc(("queue %p empty\n", pQ));
431 return rc;
432}
433
434static void ps2mSetRate(PPS2M pThis, uint8_t rate)
435{
436 pThis->uThrottleDelay = 1000 / rate;
437 pThis->u8SampleRate = rate;
438 LogFlowFunc(("Sampling rate %u, throttle delay %u ms\n", pThis->u8SampleRate, pThis->uThrottleDelay));
439}
440
441static void ps2mSetDefaults(PPS2M pThis)
442{
443 LogFlowFunc(("Set mouse defaults\n"));
444 /* Standard protocol, reporting disabled, resolution 2, 1:1 scaling. */
445 pThis->enmProtocol = PS2M_PROTO_PS2STD;
446 pThis->u8State = 0;
447 pThis->u8Resolution = 2;
448
449 /* Sample rate 100 reports per second. */
450 ps2mSetRate(pThis, 100);
451
452 /* Event queue, eccumulators, and button status bits are cleared. */
453 ps2kClearQueue((GeneriQ *)&pThis->evtQ);
454 pThis->iAccumX = pThis->iAccumY = pThis->iAccumZ = pThis->fAccumB = 0;
455}
456
457/* Handle the sampling rate 'knock' sequence which selects protocol. */
458static void ps2mRateProtocolKnock(PPS2M pThis, uint8_t rate)
459{
460 switch (pThis->enmKnockState)
461 {
462 case PS2M_KNOCK_INITIAL:
463 if (rate == 200)
464 pThis->enmKnockState = PS2M_KNOCK_1ST;
465 break;
466 case PS2M_KNOCK_1ST:
467 if (rate == 100)
468 pThis->enmKnockState = PS2M_KNOCK_IMPS2_2ND;
469 else if (rate == 200)
470 pThis->enmKnockState = PS2M_KNOCK_IMEX_2ND;
471 else
472 pThis->enmKnockState = PS2M_KNOCK_INITIAL;
473 break;
474 case PS2M_KNOCK_IMPS2_2ND:
475 if (rate == 80)
476 {
477 pThis->enmProtocol = PS2M_PROTO_IMPS2;
478 LogRelFlow(("PS2M: Switching mouse to ImPS/2 protocol.\n"));
479 }
480 pThis->enmKnockState = PS2M_KNOCK_INITIAL;
481 break;
482 case PS2M_KNOCK_IMEX_2ND:
483 if (rate == 80)
484 {
485 pThis->enmProtocol = PS2M_PROTO_IMEX;
486 LogRelFlow(("PS2M: Switching mouse to ImEx protocol.\n"));
487 }
488 /* Fall through! */
489 default:
490 pThis->enmKnockState = PS2M_KNOCK_INITIAL;
491 }
492}
493
494/**
495 * Receive and process a byte sent by the keyboard controller.
496 *
497 * @param pThis The PS/2 auxiliary device instance data.
498 * @param cmd The command (or data) byte.
499 */
500int PS2MByteToAux(PPS2M pThis, uint8_t cmd)
501{
502 uint8_t u8Val;
503 bool fHandled = true;
504
505 LogFlowFunc(("cmd=0x%02X, active cmd=0x%02X\n", cmd, pThis->u8CurrCmd));
506//LogRel(("aux: cmd=0x%02X, active cmd=0x%02X\n", cmd, pThis->u8CurrCmd));
507
508 if (pThis->enmMode == AUX_MODE_RESET)
509 /* In reset mode, do not respond at all. */
510 return VINF_SUCCESS;
511
512 /* If there's anything left in the command response queue, trash it. */
513 ps2kClearQueue((GeneriQ *)&pThis->cmdQ);
514
515 if (pThis->enmMode == AUX_MODE_WRAP)
516 {
517 /* In wrap mode, bounce most data right back.*/
518 if (cmd == ACMD_RESET || cmd == ACMD_RESET_WRAP)
519 ; /* Handle as regular commands. */
520 else
521 {
522 ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, cmd);
523 return VINF_SUCCESS;
524 }
525 }
526
527 switch (cmd)
528 {
529 case ACMD_SET_SCALE_11:
530 pThis->u8State &= ~AUX_STATE_SCALING;
531 ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
532 pThis->u8CurrCmd = 0;
533 break;
534 case ACMD_SET_SCALE_21:
535 pThis->u8State |= AUX_STATE_SCALING;
536 ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
537 pThis->u8CurrCmd = 0;
538 break;
539 case ACMD_REQ_STATUS:
540 /* Report current status, sample rate, and resolution. */
541 //@todo: buttons
542 u8Val = pThis->u8State;
543 ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
544 ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, u8Val);
545 ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, pThis->u8Resolution);
546 ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, pThis->u8SampleRate);
547 pThis->u8CurrCmd = 0;
548 break;
549 case ACMD_SET_STREAM:
550 pThis->u8State &= ~AUX_STATE_REMOTE;
551 ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
552 pThis->u8CurrCmd = 0;
553 break;
554 case ACMD_RESET_WRAP:
555 pThis->enmMode = AUX_MODE_STD;
556 /* NB: Stream mode reporting remains disabled! */
557 ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
558 pThis->u8CurrCmd = 0;
559 break;
560 case ACMD_SET_WRAP:
561 pThis->enmMode = AUX_MODE_WRAP;
562 pThis->u8State &= ~AUX_STATE_ENABLED;
563 ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
564 pThis->u8CurrCmd = 0;
565 break;
566 case ACMD_SET_REMOTE:
567 pThis->u8State |= AUX_STATE_REMOTE;
568 ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
569 pThis->u8CurrCmd = 0;
570 break;
571 case ACMD_READ_ID:
572 ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
573 ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, pThis->enmProtocol);
574 pThis->u8CurrCmd = 0;
575 break;
576 case ACMD_ENABLE:
577 pThis->u8State |= AUX_STATE_ENABLED;
578 //@todo: R3 only!
579#ifdef IN_RING3
580 ps2mSetDriverState(pThis, true);
581#endif
582 ps2kClearQueue((GeneriQ *)&pThis->evtQ);
583 ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
584 pThis->u8CurrCmd = 0;
585 break;
586 case ACMD_DFLT_DISABLE:
587 ps2mSetDefaults(pThis);
588 ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
589 pThis->u8CurrCmd = 0;
590 break;
591 case ACMD_SET_DEFAULT:
592 ps2mSetDefaults(pThis);
593 ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
594 pThis->u8CurrCmd = 0;
595 break;
596 case ACMD_RESEND:
597 pThis->u8CurrCmd = 0;
598 break;
599 case ACMD_RESET:
600 ps2mSetDefaults(pThis);
601 ///@todo reset more?
602 pThis->u8CurrCmd = cmd;
603 pThis->enmMode = AUX_MODE_RESET;
604 ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
605 /* Slightly delay reset completion; it might take hundreds of ms. */
606 TMTimerSetMillies(pThis->CTX_SUFF(pDelayTimer), 1);
607 break;
608 /* The following commands need a parameter. */
609 case ACMD_SET_RES:
610 case ACMD_SET_SAMP_RATE:
611 ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
612 pThis->u8CurrCmd = cmd;
613 break;
614 default:
615 /* Sending a command instead of a parameter starts the new command. */
616 switch (pThis->u8CurrCmd)
617 {
618 case ACMD_SET_RES:
619 //@todo reject unsupported resolutions
620 pThis->u8Resolution = cmd;
621 ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
622 pThis->u8CurrCmd = 0;
623 break;
624 case ACMD_SET_SAMP_RATE:
625 //@todo reject unsupported rates
626 ps2mSetRate(pThis, cmd);
627 ps2mRateProtocolKnock(pThis, cmd);
628 ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
629 pThis->u8CurrCmd = 0;
630 break;
631 default:
632 fHandled = false;
633 }
634 /* Fall through only to handle unrecognized commands. */
635 if (fHandled)
636 break;
637
638 case ACMD_INVALID_1:
639 case ACMD_INVALID_2:
640 case ACMD_INVALID_3:
641 case ACMD_INVALID_4:
642 case ACMD_INVALID_5:
643 case ACMD_INVALID_6:
644 case ACMD_INVALID_7:
645 case ACMD_INVALID_8:
646 case ACMD_INVALID_9:
647 case ACMD_INVALID_10:
648 Log(("Unsupported command 0x%02X!\n", cmd));
649 ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_RESEND);
650 pThis->u8CurrCmd = 0;
651 break;
652 }
653 LogFlowFunc(("Active cmd now 0x%02X; updating interrupts\n", pThis->u8CurrCmd));
654// KBCUpdateInterrupts(pThis->pParent);
655 return VINF_SUCCESS;
656}
657
658/**
659 * Send a byte (keystroke or command response) to the keyboard controller.
660 *
661 * @returns VINF_SUCCESS or VINF_TRY_AGAIN.
662 * @param pThis The PS/2 auxiliary device instance data.
663 * @param pb Where to return the byte we've read.
664 * @remarks Caller must have entered the device critical section.
665 */
666int PS2MByteFromAux(PPS2M pThis, uint8_t *pb)
667{
668 int rc;
669
670 AssertPtr(pb);
671
672 /* Anything in the command queue has priority over data
673 * in the event queue. Additionally, keystrokes are //@todo: true?
674 * blocked if a command is currently in progress, even if
675 * the command queue is empty.
676 */
677 //@todo: Probably should flush/not fill queue if stream mode reporting disabled?!
678 rc = ps2kRemoveQueue((GeneriQ *)&pThis->cmdQ, pb);
679 if (rc != VINF_SUCCESS && !pThis->u8CurrCmd && (pThis->u8State & AUX_STATE_ENABLED))
680 rc = ps2kRemoveQueue((GeneriQ *)&pThis->evtQ, pb);
681
682 LogFlowFunc(("mouse sends 0x%02x (%svalid data)\n", *pb, rc == VINF_SUCCESS ? "" : "not "));
683//if (rc == VINF_SUCCESS) LogRel(("aux: sends 0x%02X\n", *pb));
684
685 return rc;
686}
687
688#ifdef IN_RING3
689
690/* Three-button event mask. */
691#define PS2M_STD_BTN_MASK (RT_BIT(0) | RT_BIT(1) | RT_BIT(2))
692
693/* Report accumulated movement and button presses, then clear the accumulators. */
694static void ps2mReportAccumulatedEvents(PPS2M pThis)
695{
696 uint8_t val;
697 int8_t dX, dY, dZ;
698
699 /* Clamp the accumulated delta values to the allowed range. */
700 dX = RT_MIN(RT_MAX(pThis->iAccumX, -256), 255);
701 dY = RT_MIN(RT_MAX(pThis->iAccumY, -256), 255);
702 dZ = RT_MIN(RT_MAX(pThis->iAccumZ, -8), 7);
703
704 /* Start with the sync bit and buttons 1-3. */
705 val = RT_BIT(3) | (pThis->fAccumB & PS2M_STD_BTN_MASK);
706 /* Set the X/Y sign bits. */
707 if (dX < 0)
708 val |= RT_BIT(4);
709 if (dY < 0)
710 val |= RT_BIT(5);
711
712 /* Send the standard 3-byte packet (always the same). */
713 ps2kInsertQueue((GeneriQ *)&pThis->evtQ, val);
714 ps2kInsertQueue((GeneriQ *)&pThis->evtQ, dX);
715 ps2kInsertQueue((GeneriQ *)&pThis->evtQ, dY);
716
717 /* Add fourth byte if extended protocol is in use. */
718 if (pThis->enmProtocol > PS2M_PROTO_PS2STD)
719 {
720 if (pThis->enmProtocol == PS2M_PROTO_IMPS2)
721 ps2kInsertQueue((GeneriQ *)&pThis->evtQ, dZ);
722 else
723 {
724 Assert(pThis->enmProtocol == PS2M_PROTO_IMEX);
725 /* Z value uses 4 bits; buttons 4/5 in bits 4 and 5. */
726 val = dZ & 0x0f;
727 val |= (pThis->fAccumB << 1) & (RT_BIT(4) | RT_BIT(5));
728 ps2kInsertQueue((GeneriQ *)&pThis->evtQ, dZ);
729 }
730 }
731
732 /* Clear the accumulators. */
733 pThis->iAccumX = pThis->iAccumY = pThis->iAccumZ = pThis->fAccumB = 0;
734
735 /* Poke the KBC to update its state. */
736 KBCUpdateInterrupts(pThis->pParent);
737}
738
739/* Event rate throttling timer to emulate the auxiliary device sampling rate.
740 */
741static DECLCALLBACK(void) ps2mThrottleTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser)
742{
743 PPS2M pThis = (PS2M *)pvUser; NOREF(pDevIns);
744 uint32_t uHaveEvents;
745
746 /* Grab the lock to avoid races with PutEvent(). */
747 int rc = PDMCritSectEnter(pThis->pCritSectR3, VERR_SEM_BUSY);
748 AssertReleaseRC(rc);
749
750#if 0
751 /* If the input queue is not empty, restart the timer. */
752#else
753 /* If more movement is accumulated, report it and restart the timer. */
754 uHaveEvents = pThis->iAccumX | pThis->iAccumY | pThis->iAccumZ | pThis->fAccumB;
755 LogFlowFunc(("Have%s events\n", uHaveEvents ? "" : " no"));
756
757 if (uHaveEvents)
758#endif
759 {
760 ps2mReportAccumulatedEvents(pThis);
761 TMTimerSetMillies(pThis->CTX_SUFF(pThrottleTimer), pThis->uThrottleDelay);
762 }
763 else
764 pThis->fThrottleActive = false;
765
766 PDMCritSectLeave(pThis->pCritSectR3);
767}
768
769/* The auxiliary device is specified to take up to about 500 milliseconds. We need
770 * to delay sending the result to the host for at least a tiny little while.
771 */
772static DECLCALLBACK(void) ps2mDelayTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser)
773{
774 PPS2M pThis = (PS2M *)pvUser; NOREF(pDevIns);
775
776 LogFlowFunc(("Delay timer: cmd %02X\n", pThis->u8CurrCmd));
777
778 Assert(pThis->u8CurrCmd == ACMD_RESET);
779 ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_BAT_OK);
780 ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, 0);
781 pThis->enmMode = AUX_MODE_STD;
782 pThis->u8CurrCmd = 0;
783
784 ///@todo Might want a PS2MCompleteCommand() to push last response, clear command, and kick the KBC...
785 /* Give the KBC a kick. */
786 KBCUpdateInterrupts(pThis->pParent);
787
788 //@todo: move to its proper home!
789 ps2mSetDriverState(pThis, true);
790}
791
792
793/**
794 * Debug device info handler. Prints basic auxiliary device state.
795 *
796 * @param pDevIns Device instance which registered the info.
797 * @param pHlp Callback functions for doing output.
798 * @param pszArgs Argument string. Optional and specific to the handler.
799 */
800static DECLCALLBACK(void) ps2mInfoState(PPDMDEVINS pDevIns, PCDBGFINFOHLP pHlp, const char *pszArgs)
801{
802 static const char *pcszModes[] = { "normal", "reset", "wrap" };
803 static const char *pcszProtocols[] = { "PS/2", NULL, NULL, "ImPS/2", "ImEx" };
804 PPS2M pThis = KBDGetPS2MFromDevIns(pDevIns);
805 NOREF(pszArgs);
806
807 Assert(pThis->enmMode <= RT_ELEMENTS(pcszModes));
808 Assert(pThis->enmProtocol <= RT_ELEMENTS(pcszProtocols));
809 pHlp->pfnPrintf(pHlp, "PS/2 mouse state: %s, %s mode, reporting %s\n",
810 pcszModes[pThis->enmMode],
811 pThis->u8State & AUX_STATE_REMOTE ? "remote" : "stream",
812 pThis->u8State & AUX_STATE_ENABLED ? "enabled" : "disabled");
813 pHlp->pfnPrintf(pHlp, "Protocol: %s, scaling %u:1\n",
814 pcszProtocols[pThis->enmProtocol], pThis->u8State & AUX_STATE_SCALING ? 2 : 1);
815 pHlp->pfnPrintf(pHlp, "Active command %02X\n", pThis->u8CurrCmd);
816 pHlp->pfnPrintf(pHlp, "Sampling rate %u reports/sec, resolution %u counts/mm\n",
817 pThis->u8SampleRate, 1 << pThis->u8Resolution);
818 pHlp->pfnPrintf(pHlp, "Command queue: %d items (%d max)\n",
819 pThis->cmdQ.cUsed, pThis->cmdQ.cSize);
820 pHlp->pfnPrintf(pHlp, "Event queue : %d items (%d max)\n",
821 pThis->evtQ.cUsed, pThis->evtQ.cSize);
822}
823
824/* -=-=-=-=-=- Mouse: IBase -=-=-=-=-=- */
825
826/**
827 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
828 */
829static DECLCALLBACK(void *) ps2mQueryInterface(PPDMIBASE pInterface, const char *pszIID)
830{
831 PPS2M pThis = RT_FROM_MEMBER(pInterface, PS2M, Mouse.IBase);
832 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pThis->Mouse.IBase);
833 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMOUSEPORT, &pThis->Mouse.IPort);
834 return NULL;
835}
836
837
838/* -=-=-=-=-=- Mouse: IMousePort -=-=-=-=-=- */
839
840/**
841 * Mouse event handler.
842 *
843 * @returns VBox status code.
844 * @param pThis The PS/2 auxiliary device instance data.
845 * @param dx X direction movement delta.
846 * @param dy Y direction movement delta.
847 * @param dz Z (vertical scroll) movement delta.
848 * @param dw W (horizontal scroll) movement delta.
849 * @param fButtons Depressed button mask.
850 */
851static int ps2mPutEventWorker(PPS2M pThis, int32_t dx, int32_t dy,
852 int32_t dz, int32_t dw, uint32_t fButtons)
853{
854 int rc = VINF_SUCCESS;
855
856 /* Update internal accumulators and button state. */
857 pThis->iAccumX += dx;
858 pThis->iAccumY += dy;
859 pThis->iAccumZ += dz;
860 pThis->fAccumB |= fButtons & PS2M_STD_BTN_MASK; //@todo: accumulate based on current protocol?
861
862#if 1
863 /* Report the event and start the throttle timer unless it's already running. */
864 if (!pThis->fThrottleActive)
865 {
866 ps2mReportAccumulatedEvents(pThis);
867 pThis->fThrottleActive = true;
868 TMTimerSetMillies(pThis->CTX_SUFF(pThrottleTimer), pThis->uThrottleDelay);
869 }
870#else
871 /* Clamp the delta values to the allowed range. */
872 dx = RT_MIN(RT_MAX(dx, -256), 255);
873 dy = RT_MIN(RT_MAX(dy, -256), 255);
874
875 /* Start with the sync bit. */
876 val = RT_BIT(3);
877 /* Add buttons 1-3. */
878 val |= fButtons & PS2M_STD_BTN_MASK;
879 /* Set the X/Y sign bits. */
880 if (dx < 0)
881 val |= RT_BIT(4);
882 if (dy < 0)
883 val |= RT_BIT(5);
884
885 ps2kInsertQueue((GeneriQ *)&pThis->evtQ, val);
886 ps2kInsertQueue((GeneriQ *)&pThis->evtQ, (uint8_t)dx);
887 ps2kInsertQueue((GeneriQ *)&pThis->evtQ, (uint8_t)dy);
888 if (pThis->enmProtocol > PS2M_PROTO_PS2STD)
889 {
890 ps2kInsertQueue((GeneriQ *)&pThis->evtQ, (uint8_t)dz);
891 }
892#endif
893
894 return rc;
895}
896
897/* -=-=-=-=-=- Mouse: IMousePort -=-=-=-=-=- */
898
899/**
900 * @interface_method_impl{PDMIMOUSEPORT, pfnPutEvent}
901 */
902static DECLCALLBACK(int) ps2mPutEvent(PPDMIMOUSEPORT pInterface, int32_t dx, int32_t dy,
903 int32_t dz, int32_t dw, uint32_t fButtons)
904{
905 PPS2M pThis = RT_FROM_MEMBER(pInterface, PS2M, Mouse.IPort);
906 int rc = PDMCritSectEnter(pThis->pCritSectR3, VERR_SEM_BUSY);
907 AssertReleaseRC(rc);
908
909 LogFlowFunc(("dX=%d dY=%d dZ=%d dW=%d buttons=%02X\n", dx, dy, dz, dw, fButtons));
910 /* NB: The PS/2 Y axis direction is inverted relative to ours. */
911 ps2mPutEventWorker(pThis, dx, -dy, dz, dw, fButtons);
912
913 PDMCritSectLeave(pThis->pCritSectR3);
914 return VINF_SUCCESS;
915}
916
917/**
918 * @interface_method_impl{PDMIMOUSEPORT, pfnPutEventAbs}
919 */
920static DECLCALLBACK(int) ps2mPutEventAbs(PPDMIMOUSEPORT pInterface, uint32_t x, uint32_t y,
921 int32_t dz, int32_t dw, uint32_t fButtons)
922{
923 AssertFailedReturn(VERR_NOT_SUPPORTED);
924 NOREF(pInterface); NOREF(x); NOREF(y); NOREF(dz); NOREF(dw); NOREF(fButtons);
925}
926
927/**
928 * @interface_method_impl{PDMIMOUSEPORT, pfnPutEventMultiTouch}
929 */
930static DECLCALLBACK(int) ps2mPutEventMT(PPDMIMOUSEPORT pInterface, uint8_t cContacts,
931 const uint64_t *pau64Contacts, uint32_t u32ScanTime)
932{
933 AssertFailedReturn(VERR_NOT_SUPPORTED);
934 NOREF(pInterface); NOREF(cContacts); NOREF(pau64Contacts); NOREF(u32ScanTime);
935}
936
937
938
939/**
940 * Attach command.
941 *
942 * This is called to let the device attach to a driver for a
943 * specified LUN.
944 *
945 * This is like plugging in the mouse after turning on the
946 * system.
947 *
948 * @returns VBox status code.
949 * @param pThis The PS/2 auxiliary device instance data.
950 * @param pDevIns The device instance.
951 * @param iLUN The logical unit which is being detached.
952 * @param fFlags Flags, combination of the PDMDEVATT_FLAGS_* \#defines.
953 */
954int PS2MAttach(PPS2M pThis, PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags)
955{
956 int rc;
957
958 /* The LUN must be 1, i.e. mouse. */
959 Assert(iLUN == 1);
960 AssertMsgReturn(fFlags & PDM_TACH_FLAGS_NOT_HOT_PLUG,
961 ("PS/2 mouse does not support hotplugging\n"),
962 VERR_INVALID_PARAMETER);
963
964 LogFlowFunc(("iLUN=%d\n", iLUN));
965
966 rc = PDMDevHlpDriverAttach(pDevIns, iLUN, &pThis->Mouse.IBase, &pThis->Mouse.pDrvBase, "Mouse Port");
967 if (RT_SUCCESS(rc))
968 {
969 pThis->Mouse.pDrv = PDMIBASE_QUERY_INTERFACE(pThis->Mouse.pDrvBase, PDMIMOUSECONNECTOR);
970 if (!pThis->Mouse.pDrv)
971 {
972 AssertLogRelMsgFailed(("LUN #1 doesn't have a mouse interface! rc=%Rrc\n", rc));
973 rc = VERR_PDM_MISSING_INTERFACE;
974 }
975 }
976 else if (rc == VERR_PDM_NO_ATTACHED_DRIVER)
977 {
978 Log(("%s/%d: warning: no driver attached to LUN #1!\n", pDevIns->pReg->szName, pDevIns->iInstance));
979 rc = VINF_SUCCESS;
980 }
981 else
982 AssertLogRelMsgFailed(("Failed to attach LUN #1! rc=%Rrc\n", rc));
983
984 return rc;
985}
986
987void PS2MSaveState(PPS2M pThis, PSSMHANDLE pSSM)
988{
989 uint32_t cPressed = 0;
990
991 LogFlowFunc(("Saving PS2M state\n"));
992
993 /* Save the core auxiliary device state. */
994 SSMR3PutU8(pSSM, pThis->u8State);
995 SSMR3PutU8(pSSM, pThis->u8SampleRate);
996 SSMR3PutU8(pSSM, pThis->u8Resolution);
997 SSMR3PutU8(pSSM, pThis->u8CurrCmd);
998 SSMR3PutU8(pSSM, pThis->enmMode);
999 SSMR3PutU8(pSSM, pThis->enmProtocol);
1000 SSMR3PutU8(pSSM, pThis->enmKnockState);
1001
1002 /* Save the command and event queues. */
1003 ps2kSaveQueue(pSSM, (GeneriQ *)&pThis->cmdQ);
1004 ps2kSaveQueue(pSSM, (GeneriQ *)&pThis->evtQ);
1005
1006 /* Save the command delay timer. Note that the rate throttling
1007 * timer is *not* saved.
1008 */
1009 TMR3TimerSave(pThis->CTX_SUFF(pDelayTimer), pSSM);
1010}
1011
1012int PS2MLoadState(PPS2M pThis, PSSMHANDLE pSSM, uint32_t uVersion)
1013{
1014 uint8_t u8;
1015 int rc;
1016
1017 NOREF(uVersion);
1018 LogFlowFunc(("Loading PS2M state version %u\n", uVersion));
1019
1020 /* Load the basic auxiliary device state. */
1021 SSMR3GetU8(pSSM, &pThis->u8State);
1022 SSMR3GetU8(pSSM, &pThis->u8SampleRate);
1023 SSMR3GetU8(pSSM, &pThis->u8Resolution);
1024 SSMR3GetU8(pSSM, &pThis->u8CurrCmd);
1025 SSMR3GetU8(pSSM, &u8);
1026 pThis->enmMode = (PS2M_MODE)u8;
1027 SSMR3GetU8(pSSM, &u8);
1028 pThis->enmProtocol = (PS2M_PROTO)u8;
1029 SSMR3GetU8(pSSM, &u8);
1030 pThis->enmKnockState = (PS2M_KNOCK_STATE)u8;
1031
1032 /* Load the command and event queues. */
1033 rc = ps2kLoadQueue(pSSM, (GeneriQ *)&pThis->cmdQ);
1034 AssertRCReturn(rc, rc);
1035 rc = ps2kLoadQueue(pSSM, (GeneriQ *)&pThis->evtQ);
1036 AssertRCReturn(rc, rc);
1037
1038 /* Load the command delay timer, just in case. */
1039 rc = TMR3TimerLoad(pThis->CTX_SUFF(pDelayTimer), pSSM);
1040 AssertRCReturn(rc, rc);
1041
1042 /* Recalculate the throttling delay. */
1043 ps2mSetRate(pThis, pThis->u8SampleRate);
1044
1045 //@todo: Is this the right place/logic?
1046 ps2mSetDriverState(pThis, !!(pThis->u8State & AUX_STATE_ENABLED));
1047
1048 return rc;
1049}
1050
1051void PS2MReset(PPS2M pThis)
1052{
1053 LogFlowFunc(("Resetting PS2M\n"));
1054
1055 pThis->u8CurrCmd = 0;
1056
1057 /* Clear the queues. */
1058 ps2kClearQueue((GeneriQ *)&pThis->cmdQ);
1059 ps2mSetDefaults(pThis); /* Also clears event queue. */
1060
1061 /* Activate the PS/2 mouse by default. */
1062// if (pThis->Mouse.pDrv)
1063// pThis->Mouse.pDrv->pfnSetActive(pThis->Mouse.pDrv, true);
1064}
1065
1066void PS2MRelocate(PPS2M pThis, RTGCINTPTR offDelta, PPDMDEVINS pDevIns)
1067{
1068 LogFlowFunc(("Relocating PS2M\n"));
1069 pThis->pDelayTimerRC = TMTimerRCPtr(pThis->pDelayTimerR3);
1070 pThis->pThrottleTimerRC = TMTimerRCPtr(pThis->pThrottleTimerR3);
1071 NOREF(offDelta);
1072}
1073
1074int PS2MConstruct(PPS2M pThis, PPDMDEVINS pDevIns, void *pParent, int iInstance)
1075{
1076 int rc;
1077
1078 LogFlowFunc(("iInstance=%d\n", iInstance));
1079
1080 pThis->pParent = pParent;
1081
1082 /* Initialize the queues. */
1083 pThis->evtQ.cSize = AUX_EVT_QUEUE_SIZE;
1084 pThis->cmdQ.cSize = AUX_CMD_QUEUE_SIZE;
1085
1086 pThis->Mouse.IBase.pfnQueryInterface = ps2mQueryInterface;
1087 pThis->Mouse.IPort.pfnPutEvent = ps2mPutEvent;
1088 pThis->Mouse.IPort.pfnPutEventAbs = ps2mPutEventAbs;
1089 pThis->Mouse.IPort.pfnPutEventMultiTouch = ps2mPutEventMT;
1090
1091 /*
1092 * Initialize the critical section pointer(s).
1093 */
1094 pThis->pCritSectR3 = pDevIns->pCritSectRoR3;
1095
1096 /*
1097 * Create the input rate throttling timer. Does not use virtual time!
1098 */
1099 PTMTIMER pTimer;
1100 rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_REAL, ps2mThrottleTimer, pThis,
1101 TMTIMER_FLAGS_DEFAULT_CRIT_SECT, "PS2M Throttle Timer", &pTimer);
1102 if (RT_FAILURE(rc))
1103 return rc;
1104
1105 pThis->pThrottleTimerR3 = pTimer;
1106 pThis->pThrottleTimerR0 = TMTimerR0Ptr(pTimer);
1107 pThis->pThrottleTimerRC = TMTimerRCPtr(pTimer);
1108
1109 /*
1110 * Create the command delay timer.
1111 */
1112 rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL, ps2mDelayTimer, pThis,
1113 TMTIMER_FLAGS_DEFAULT_CRIT_SECT, "PS2M Delay Timer", &pTimer);
1114 if (RT_FAILURE(rc))
1115 return rc;
1116
1117 pThis->pDelayTimerR3 = pTimer;
1118 pThis->pDelayTimerR0 = TMTimerR0Ptr(pTimer);
1119 pThis->pDelayTimerRC = TMTimerRCPtr(pTimer);
1120
1121 /*
1122 * Register debugger info callbacks.
1123 */
1124 PDMDevHlpDBGFInfoRegister(pDevIns, "ps2m", "Display PS/2 mouse state.", ps2mInfoState);
1125
1126 //@todo: Where should we do this?
1127 ps2mSetDriverState(pThis, true);
1128 pThis->u8State = 0;
1129 pThis->enmMode = AUX_MODE_STD;
1130
1131 return rc;
1132}
1133
1134#endif
1135
1136#endif /* !VBOX_DEVICE_STRUCT_TESTCASE */
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