13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * PS2M - PS/2 auxiliary device (mouse) emulation.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * Copyright (C) 2007-2013 Oracle Corporation
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * available from http://www.virtualbox.org. This file is free software;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * you can redistribute it and/or modify it under the terms of the GNU
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * General Public License (GPL) as published by the Free Software
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * References:
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * The Undocumented PC (2nd Ed.), Frank van Gilluwe, Addison-Wesley, 1996.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * IBM TrackPoint System Version 4.0 Engineering Specification, 1999.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * ELAN Microelectronics eKM8025 USB & PS/2 Mouse Controller, 2006.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * - The auxiliary device commands are very similar to keyboard commands.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * Most keyboard commands which do not specifically deal with the keyboard
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * (enable, disable, reset) have identical counterparts.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * - The code refers to 'auxiliary device' and 'mouse'; these terms are not
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * quite interchangeable. 'Auxiliary device' is used when referring to the
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * generic PS/2 auxiliary device interface and 'mouse' when referring to
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * a mouse attached to the auxiliary port.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * - The basic modes of operation are reset, stream, and remote. Those are
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * mutually exclusive. Stream and remote modes can additionally have wrap
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * mode enabled.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * - The auxiliary device sends unsolicited data to the host only when it is
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * both in stream mode and enabled. Otherwise it only responds to commands.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * There are three report packet formats supported by the emulated device. The
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * standard three-byte PS/2 format (with middle button support), IntelliMouse
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * four-byte format with added scroll wheel, and IntelliMouse Explorer four-byte
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * format with reduced scroll wheel range but two additional buttons. Note that
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * the first three bytes of the report are always the same.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * Upon reset, the mouse is always in the standard PS/2 mode. A special 'knock'
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * sequence can be used to switch to ImPS/2 or ImEx mode. Three consecutive
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * Set Sampling Rate (0F3h) commands with arguments 200, 100, 80 switch to ImPS/2
e74c6b6b998c532cdfec426de8ad08b6441e7215vboxsync * mode. While in ImPS/2 or PS/2 mode, three consecutive Set Sampling Rate
e74c6b6b998c532cdfec426de8ad08b6441e7215vboxsync * commands with arguments 200, 200, 80 switch to ImEx mode. The Read ID (0F2h)
e74c6b6b998c532cdfec426de8ad08b6441e7215vboxsync * command will report the currently selected protocol.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * Standard PS/2 pointing device three-byte report packet format:
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * +--------+--------+--------+--------+--------+--------+--------+--------+--------+
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * |Bit/byte| bit 7 | bit 6 | bit 5 | bit 4 | bit 3 | bit 2 | bit 1 | bit 0 |
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * +--------+--------+--------+--------+--------+--------+--------+--------+--------+
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * | Byte 1 | Y ovfl | X ovfl | Y sign | X sign | Sync | M btn | R btn | L btn |
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * +--------+--------+--------+--------+--------+--------+--------+--------+--------+
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * | Byte 2 | X movement delta (two's complement) |
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * +--------+--------+--------+--------+--------+--------+--------+--------+--------+
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * | Byte 3 | Y movement delta (two's complement) |
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * +--------+--------+--------+--------+--------+--------+--------+--------+--------+
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * - The sync bit is always set. It allows software to synchronize data packets
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * as the X/Y position data typically does not have bit 4 set.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * - The overflow bits are set if motion exceeds accumulator range. We use the
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * maximum range (effectively 9 bits) and do not set the overflow bits.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * - Movement in the up/right direction is defined as having positive sign.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * IntelliMouse PS/2 (ImPS/2) fourth report packet byte:
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * +--------+--------+--------+--------+--------+--------+--------+--------+--------+
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * |Bit/byte| bit 7 | bit 6 | bit 5 | bit 4 | bit 3 | bit 2 | bit 1 | bit 0 |
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * +--------+--------+--------+--------+--------+--------+--------+--------+--------+
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * | Byte 4 | Z movement delta (two's complement) |
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * +--------+--------+--------+--------+--------+--------+--------+--------+--------+
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * - The valid range for Z delta values is only -8/+7, i.e. 4 bits.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * IntelliMouse Explorer (ImEx) fourth report packet byte:
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * +--------+--------+--------+--------+--------+--------+--------+--------+--------+
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * |Bit/byte| bit 7 | bit 6 | bit 5 | bit 4 | bit 3 | bit 2 | bit 1 | bit 0 |
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * +--------+--------+--------+--------+--------+--------+--------+--------+--------+
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * | Byte 4 | 0 | 0 | Btn 5 | Btn 4 | Z mov't delta (two's complement) |
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * +--------+--------+--------+--------+--------+--------+--------+--------+--------+
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/*******************************************************************************
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync* Header Files *
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync*******************************************************************************/
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/*******************************************************************************
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync* Defined Constants And Macros *
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync*******************************************************************************/
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/** @name Auxiliary device commands sent by the system.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#define ACMD_SET_SCALE_11 0xE6 /* Set 1:1 scaling. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#define ACMD_SET_SCALE_21 0xE7 /* Set 2:1 scaling. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#define ACMD_REQ_STATUS 0xE9 /* Get device status. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#define ACMD_READ_REMOTE 0xEB /* Read remote data. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#define ACMD_SET_WRAP 0xEE /* Set wrap (echo) mode. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#define ACMD_SET_SAMP_RATE 0xF3 /* Set sampling rate. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#define ACMD_ENABLE 0xF4 /* Enable (streaming mode). */
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync#define ACMD_DISABLE 0xF5 /* Disable (streaming mode). */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/** @name Auxiliary device responses sent to the system.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/** Define a simple PS/2 input device queue. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync typedef struct { \
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/* Internal mouse queue sizes. The input queue is relatively large,
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * but the command queue only needs to handle a few bytes.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/*******************************************************************************
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync* Structures and Typedefs *
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync*******************************************************************************/
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/* Auxiliary device special modes of operation. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsynctypedef enum {
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/* Auxiliary device operational state. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsynctypedef enum {
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync AUX_STATE_RATE_ERR = RT_BIT(0), /* Invalid rate received. */
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync AUX_STATE_RES_ERR = RT_BIT(1), /* Invalid resolution received. */
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync AUX_STATE_SCALING = RT_BIT(4), /* 2:1 scaling in effect. */
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync AUX_STATE_ENABLED = RT_BIT(5), /* Reporting enabled in stream mode. */
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync AUX_STATE_REMOTE = RT_BIT(6) /* Remote mode (reports on request). */
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync/* Externally visible state bits. */
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync#define AUX_STATE_EXTERNAL (AUX_STATE_SCALING | AUX_STATE_ENABLED | AUX_STATE_REMOTE)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/* Protocols supported by the PS/2 mouse. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsynctypedef enum {
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync PS2M_PROTO_PS2STD = 0, /* Standard PS/2 mouse protocol. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync PS2M_PROTO_IMPS2 = 3, /* IntelliMouse PS/2 protocol. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync PS2M_PROTO_IMEX = 4 /* IntelliMouse Explorer protocol. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/* Protocol selection 'knock' states. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsynctypedef enum {
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * The PS/2 auxiliary device instance data.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** Pointer to parent device (keyboard controller). */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** Operational state. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** Configured sampling rate. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** Configured resolution. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** Currently processed command (if any). */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** Set if the throttle delay is active. */
d1310b60a66ca7122b1f7b1a0efdd6af5b5d2235vboxsync /** Set if the throttle delay is active. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** Operational mode. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** Currently used protocol. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** Currently used protocol. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** Buffer holding mouse events to be sent to the host. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** Command response queue (priority). */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** Accumulated horizontal movement. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** Accumulated vertical movement. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** Accumulated Z axis movement. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** Accumulated button presses. */
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync /** Instantaneous button data. */
c0015339febab0b824ff8d8293abc82fa2189982vboxsync /** Button state last sent to the guest. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** Throttling delay in milliseconds. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** The device critical section protecting everything - R3 Ptr */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** Command delay timer - R3 Ptr. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** Interrupt throttling timer - R3 Ptr. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** Command delay timer - RC Ptr. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** Interrupt throttling timer - RC Ptr. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** Command delay timer - R0 Ptr. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** Interrupt throttling timer - R0 Ptr. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * Mouse port - LUN#1.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @implements PDMIBASE
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @implements PDMIMOUSEPORT
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** The base interface for the mouse port. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** The keyboard port base interface. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** The base interface of the attached mouse driver. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** The keyboard interface of the attached mouse driver. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/*******************************************************************************
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync* Global Variables *
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync*******************************************************************************/
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/*******************************************************************************
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync* Internal Functions *
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync*******************************************************************************/
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * Clear a queue.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @param pQ Pointer to the queue.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * Add a byte to a queue.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @param pQ Pointer to the queue.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @param val The byte to store.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncstatic void ps2kInsertQueue(GeneriQ *pQ, uint8_t val)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Check if queue is full. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync LogFlowFunc(("queue %p full (%d entries)\n", pQ, pQ->cUsed));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Insert data and update circular buffer write position. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync LogFlowFunc(("inserted 0x%02X into queue %p\n", val, pQ));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * Save a queue state.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @param pSSM SSM handle to write the state to.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @param pQ Pointer to the queue.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncstatic void ps2kSaveQueue(PSSMHANDLE pSSM, GeneriQ *pQ)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Only save the number of items. Note that the read/write
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * positions aren't saved as they will be rebuilt on load.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync LogFlow(("Storing %d items from queue %p\n", cItems, pQ));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Save queue data - only the bytes actually used (typically zero). */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync for (i = pQ->rpos; cItems-- > 0; i = (i + 1) % pQ->cSize)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * Load a queue state.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @param pSSM SSM handle to read the state from.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @param pQ Pointer to the queue.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @return int VBox status/error code.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncstatic int ps2kLoadQueue(PSSMHANDLE pSSM, GeneriQ *pQ)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* On load, always put the read pointer at zero. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync LogFlow(("Loading %d items to queue %p\n", pQ->cUsed, pQ));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync AssertMsgFailed(("Saved size=%u, actual=%u\n", pQ->cUsed, pQ->cSize));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Recalculate queue positions and load data in one go. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/* Report a change in status down (or is it up?) the driver chain. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncstatic void ps2mSetDriverState(PPS2M pThis, bool fEnabled)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pDrv->pfnReportModes(pDrv, fEnabled, false, false);
d1310b60a66ca7122b1f7b1a0efdd6af5b5d2235vboxsync/* Reset the pointing device. */
d1310b60a66ca7122b1f7b1a0efdd6af5b5d2235vboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_BAT_OK);
d1310b60a66ca7122b1f7b1a0efdd6af5b5d2235vboxsync //@todo: move to its proper home!
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#endif /* IN_RING3 */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * Retrieve a byte from a queue.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @param pQ Pointer to the queue.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @param pVal Pointer to storage for the byte.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @return int VINF_TRY_AGAIN if queue is empty,
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * VINF_SUCCESS if a byte was read.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncstatic int ps2kRemoveQueue(GeneriQ *pQ, uint8_t *pVal)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync LogFlowFunc(("removed 0x%02X from queue %p\n", *pVal, pQ));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync LogFlowFunc(("Sampling rate %u, throttle delay %u ms\n", pThis->u8SampleRate, pThis->uThrottleDelay));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Standard protocol, reporting disabled, resolution 2, 1:1 scaling. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Sample rate 100 reports per second. */
f6ec7fe3e4607b1c0c06fd650be48072f410c95dvboxsync /* Event queue, eccumulators, and button status bits are cleared. */
c0015339febab0b824ff8d8293abc82fa2189982vboxsync pThis->iAccumX = pThis->iAccumY = pThis->iAccumZ = pThis->fAccumB;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/* Handle the sampling rate 'knock' sequence which selects protocol. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncstatic void ps2mRateProtocolKnock(PPS2M pThis, uint8_t rate)
e74c6b6b998c532cdfec426de8ad08b6441e7215vboxsync LogRelFlow(("PS2M: Switching mouse to ImPS/2 protocol.\n"));
e74c6b6b998c532cdfec426de8ad08b6441e7215vboxsync LogRelFlow(("PS2M: Switching mouse to ImEx protocol.\n"));
e74c6b6b998c532cdfec426de8ad08b6441e7215vboxsync /* Fall through! */
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync/* Three-button event mask. */
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync#define PS2M_STD_BTN_MASK (RT_BIT(0) | RT_BIT(1) | RT_BIT(2))
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync/* Report accumulated movement and button presses, then clear the accumulators. */
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsyncstatic void ps2mReportAccumulatedEvents(PPS2M pThis, GeneriQ *pQueue, bool fAccumBtns)
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync uint32_t fBtnState = fAccumBtns ? pThis->fAccumB : pThis->fCurrB;
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync /* Clamp the accumulated delta values to the allowed range. */
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync /* Start with the sync bit and buttons 1-3. */
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync /* Set the X/Y sign bits. */
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync /* Send the standard 3-byte packet (always the same). */
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync /* Add fourth byte if extended protocol is in use. */
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync /* Z value uses 4 bits; buttons 4/5 in bits 4 and 5. */
c0015339febab0b824ff8d8293abc82fa2189982vboxsync /* Clear the movement accumulators, but not necessarily button state. */
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync pThis->iAccumX = pThis->iAccumY = pThis->iAccumZ = 0;
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync /* Clear accumulated button state only when it's being used. */
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync/* Determine whether a reporting rate is one of the valid ones. */
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync static uint8_t aValidRates[] = { 10, 20, 40, 60, 80, 100, 200 };
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * Receive and process a byte sent by the keyboard controller.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @param pThis The PS/2 auxiliary device instance data.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @param cmd The command (or data) byte.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync LogFlowFunc(("cmd=0x%02X, active cmd=0x%02X\n", cmd, pThis->u8CurrCmd));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync//LogRel(("aux: cmd=0x%02X, active cmd=0x%02X\n", cmd, pThis->u8CurrCmd));
67b6e4f9c1d5be5c46a4ab5e9c17513d3b524938vboxsync /* In reset mode, do not respond at all. */
f6ec7fe3e4607b1c0c06fd650be48072f410c95dvboxsync /* If there's anything left in the command response queue, trash it. */
67b6e4f9c1d5be5c46a4ab5e9c17513d3b524938vboxsync /* In wrap mode, bounce most data right back.*/
67b6e4f9c1d5be5c46a4ab5e9c17513d3b524938vboxsync ; /* Handle as regular commands. */
2ce50c7f2d493de97978fc2a75c14c65ee5bf945vboxsync /* Reset, Enable, and Set Default commands must be run in R3. */
2ce50c7f2d493de97978fc2a75c14c65ee5bf945vboxsync if (cmd == ACMD_RESET || cmd == ACMD_ENABLE || cmd == ACMD_SET_DEFAULT)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Report current status, sample rate, and resolution. */
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync u8Val = (pThis->u8State & AUX_STATE_EXTERNAL) | (pThis->fCurrB & PS2M_STD_BTN_MASK);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, pThis->u8Resolution);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, pThis->u8SampleRate);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync ps2mReportAccumulatedEvents(pThis, (GeneriQ *)&pThis->cmdQ, false);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* NB: Stream mode reporting remains disabled! */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, pThis->enmProtocol);
d1310b60a66ca7122b1f7b1a0efdd6af5b5d2235vboxsync AssertLogRelMsgFailed(("Invalid ACMD_ENABLE outside R3!\n"));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ///@todo reset more?
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
d1310b60a66ca7122b1f7b1a0efdd6af5b5d2235vboxsync /* Slightly delay reset completion; it might take hundreds of ms. */
d1310b60a66ca7122b1f7b1a0efdd6af5b5d2235vboxsync TMTimerSetMillies(pThis->CTX_SUFF(pDelayTimer), 1);
d1310b60a66ca7122b1f7b1a0efdd6af5b5d2235vboxsync AssertLogRelMsgFailed(("Invalid ACMD_RESET outside R3!\n"));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* The following commands need a parameter. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Sending a command instead of a parameter starts the new command. */
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync /* Bad resolution. Reply with Resend or Error. */
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ERROR);
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_RESEND);
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync /* NB: Current command remains unchanged. */
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync /* Bad rate. Reply with Resend or Error. */
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ERROR);
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_RESEND);
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync /* NB: Current command remains unchanged. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Fall through only to handle unrecognized commands. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_RESEND);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync LogFlowFunc(("Active cmd now 0x%02X; updating interrupts\n", pThis->u8CurrCmd));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync// KBCUpdateInterrupts(pThis->pParent);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * Send a byte (keystroke or command response) to the keyboard controller.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @returns VINF_SUCCESS or VINF_TRY_AGAIN.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @param pThis The PS/2 auxiliary device instance data.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @param pb Where to return the byte we've read.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @remarks Caller must have entered the device critical section.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Anything in the command queue has priority over data
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * in the event queue. Additionally, keystrokes are //@todo: true?
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * blocked if a command is currently in progress, even if
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * the command queue is empty.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync //@todo: Probably should flush/not fill queue if stream mode reporting disabled?!
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync if (rc != VINF_SUCCESS && !pThis->u8CurrCmd && (pThis->u8State & AUX_STATE_ENABLED))
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync LogFlowFunc(("mouse sends 0x%02x (%svalid data)\n", *pb, rc == VINF_SUCCESS ? "" : "not "));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync//if (rc == VINF_SUCCESS) LogRel(("aux: sends 0x%02X\n", *pb));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/* Event rate throttling timer to emulate the auxiliary device sampling rate.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncstatic DECLCALLBACK(void) ps2mThrottleTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Grab the lock to avoid races with PutEvent(). */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync int rc = PDMCritSectEnter(pThis->pCritSectR3, VERR_SEM_BUSY);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* If the input queue is not empty, restart the timer. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* If more movement is accumulated, report it and restart the timer. */
c0015339febab0b824ff8d8293abc82fa2189982vboxsync uHaveEvents = pThis->iAccumX | pThis->iAccumY | pThis->iAccumZ | (pThis->fCurrB != pThis->fReportedB);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync LogFlowFunc(("Have%s events\n", uHaveEvents ? "" : " no"));
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync /* Report accumulated data, poke the KBC, and start the timer. */
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync ps2mReportAccumulatedEvents(pThis, (GeneriQ *)&pThis->evtQ, true);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync TMTimerSetMillies(pThis->CTX_SUFF(pThrottleTimer), pThis->uThrottleDelay);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/* The auxiliary device is specified to take up to about 500 milliseconds. We need
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * to delay sending the result to the host for at least a tiny little while.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncstatic DECLCALLBACK(void) ps2mDelayTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync LogFlowFunc(("Delay timer: cmd %02X\n", pThis->u8CurrCmd));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ///@todo Might want a PS2MCompleteCommand() to push last response, clear command, and kick the KBC...
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Give the KBC a kick. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * Debug device info handler. Prints basic auxiliary device state.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @param pDevIns Device instance which registered the info.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @param pHlp Callback functions for doing output.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @param pszArgs Argument string. Optional and specific to the handler.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncstatic DECLCALLBACK(void) ps2mInfoState(PPDMDEVINS pDevIns, PCDBGFINFOHLP pHlp, const char *pszArgs)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync static const char *pcszModes[] = { "normal", "reset", "wrap" };
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync static const char *pcszProtocols[] = { "PS/2", NULL, NULL, "ImPS/2", "ImEx" };
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync Assert(pThis->enmProtocol <= RT_ELEMENTS(pcszProtocols));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pHlp->pfnPrintf(pHlp, "PS/2 mouse state: %s, %s mode, reporting %s\n",
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->u8State & AUX_STATE_REMOTE ? "remote" : "stream",
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->u8State & AUX_STATE_ENABLED ? "enabled" : "disabled");
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pHlp->pfnPrintf(pHlp, "Protocol: %s, scaling %u:1\n",
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pcszProtocols[pThis->enmProtocol], pThis->u8State & AUX_STATE_SCALING ? 2 : 1);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pHlp->pfnPrintf(pHlp, "Active command %02X\n", pThis->u8CurrCmd);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pHlp->pfnPrintf(pHlp, "Sampling rate %u reports/sec, resolution %u counts/mm\n",
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pHlp->pfnPrintf(pHlp, "Command queue: %d items (%d max)\n",
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pHlp->pfnPrintf(pHlp, "Event queue : %d items (%d max)\n",
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/* -=-=-=-=-=- Mouse: IBase -=-=-=-=-=- */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @interface_method_impl{PDMIBASE,pfnQueryInterface}
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncstatic DECLCALLBACK(void *) ps2mQueryInterface(PPDMIBASE pInterface, const char *pszIID)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync PPS2M pThis = RT_FROM_MEMBER(pInterface, PS2M, Mouse.IBase);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pThis->Mouse.IBase);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMOUSEPORT, &pThis->Mouse.IPort);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/* -=-=-=-=-=- Mouse: IMousePort -=-=-=-=-=- */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * Mouse event handler.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @returns VBox status code.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @param pThis The PS/2 auxiliary device instance data.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @param dx X direction movement delta.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @param dy Y direction movement delta.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @param dz Z (vertical scroll) movement delta.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @param dw W (horizontal scroll) movement delta.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @param fButtons Depressed button mask.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncstatic int ps2mPutEventWorker(PPS2M pThis, int32_t dx, int32_t dy,
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Update internal accumulators and button state. */
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync pThis->fAccumB |= fButtons; //@todo: accumulate based on current protocol?
f6ec7fe3e4607b1c0c06fd650be48072f410c95dvboxsync /* Report the event and start the throttle timer unless it's already running. */
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync ps2mReportAccumulatedEvents(pThis, (GeneriQ *)&pThis->evtQ, true);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync TMTimerSetMillies(pThis->CTX_SUFF(pThrottleTimer), pThis->uThrottleDelay);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Clamp the delta values to the allowed range. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Start with the sync bit. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Add buttons 1-3. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Set the X/Y sign bits. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2kInsertQueue((GeneriQ *)&pThis->evtQ, (uint8_t)dx);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2kInsertQueue((GeneriQ *)&pThis->evtQ, (uint8_t)dy);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2kInsertQueue((GeneriQ *)&pThis->evtQ, (uint8_t)dz);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/* -=-=-=-=-=- Mouse: IMousePort -=-=-=-=-=- */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @interface_method_impl{PDMIMOUSEPORT, pfnPutEvent}
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncstatic DECLCALLBACK(int) ps2mPutEvent(PPDMIMOUSEPORT pInterface, int32_t dx, int32_t dy,
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync PPS2M pThis = RT_FROM_MEMBER(pInterface, PS2M, Mouse.IPort);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync int rc = PDMCritSectEnter(pThis->pCritSectR3, VERR_SEM_BUSY);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync LogFlowFunc(("dX=%d dY=%d dZ=%d dW=%d buttons=%02X\n", dx, dy, dz, dw, fButtons));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* NB: The PS/2 Y axis direction is inverted relative to ours. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2mPutEventWorker(pThis, dx, -dy, dz, dw, fButtons);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @interface_method_impl{PDMIMOUSEPORT, pfnPutEventAbs}
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncstatic DECLCALLBACK(int) ps2mPutEventAbs(PPDMIMOUSEPORT pInterface, uint32_t x, uint32_t y,
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync NOREF(pInterface); NOREF(x); NOREF(y); NOREF(dz); NOREF(dw); NOREF(fButtons);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @interface_method_impl{PDMIMOUSEPORT, pfnPutEventMultiTouch}
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncstatic DECLCALLBACK(int) ps2mPutEventMT(PPDMIMOUSEPORT pInterface, uint8_t cContacts,
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync const uint64_t *pau64Contacts, uint32_t u32ScanTime)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync NOREF(pInterface); NOREF(cContacts); NOREF(pau64Contacts); NOREF(u32ScanTime);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * Attach command.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * This is called to let the device attach to a driver for a
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * specified LUN.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * This is like plugging in the mouse after turning on the
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @returns VBox status code.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @param pThis The PS/2 auxiliary device instance data.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @param pDevIns The device instance.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @param iLUN The logical unit which is being detached.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @param fFlags Flags, combination of the PDMDEVATT_FLAGS_* \#defines.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncint PS2MAttach(PPS2M pThis, PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* The LUN must be 1, i.e. mouse. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync AssertMsgReturn(fFlags & PDM_TACH_FLAGS_NOT_HOT_PLUG,
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ("PS/2 mouse does not support hotplugging\n"),
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync rc = PDMDevHlpDriverAttach(pDevIns, iLUN, &pThis->Mouse.IBase, &pThis->Mouse.pDrvBase, "Mouse Port");
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->Mouse.pDrv = PDMIBASE_QUERY_INTERFACE(pThis->Mouse.pDrvBase, PDMIMOUSECONNECTOR);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync AssertLogRelMsgFailed(("LUN #1 doesn't have a mouse interface! rc=%Rrc\n", rc));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync Log(("%s/%d: warning: no driver attached to LUN #1!\n", pDevIns->pReg->szName, pDevIns->iInstance));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync AssertLogRelMsgFailed(("Failed to attach LUN #1! rc=%Rrc\n", rc));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Save the core auxiliary device state. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Save the command and event queues. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Save the command delay timer. Note that the rate throttling
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * timer is *not* saved.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncint PS2MLoadState(PPS2M pThis, PSSMHANDLE pSSM, uint32_t uVersion)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync LogFlowFunc(("Loading PS2M state version %u\n", uVersion));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Load the basic auxiliary device state. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Load the command and event queues. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Load the command delay timer, just in case. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync rc = TMR3TimerLoad(pThis->CTX_SUFF(pDelayTimer), pSSM);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Recalculate the throttling delay. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2mSetDriverState(pThis, !!(pThis->u8State & AUX_STATE_ENABLED));
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsyncvoid PS2MFixupState(PPS2M pThis, uint8_t u8State, uint8_t u8Rate, uint8_t u8Proto)
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync LogFlowFunc(("Fixing up old PS2M state version\n"));
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync /* Load the basic auxiliary device state. */
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync pThis->u8SampleRate = u8Rate ? u8Rate : 40; /* In case it wasn't saved right. */
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync /* Recalculate the throttling delay. */
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync ps2mSetDriverState(pThis, !!(pThis->u8State & AUX_STATE_ENABLED));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Clear the queues. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2mSetDefaults(pThis); /* Also clears event queue. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Activate the PS/2 mouse by default. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync// if (pThis->Mouse.pDrv)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync// pThis->Mouse.pDrv->pfnSetActive(pThis->Mouse.pDrv, true);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncvoid PS2MRelocate(PPS2M pThis, RTGCINTPTR offDelta, PPDMDEVINS pDevIns)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->pDelayTimerRC = TMTimerRCPtr(pThis->pDelayTimerR3);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->pThrottleTimerRC = TMTimerRCPtr(pThis->pThrottleTimerR3);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncint PS2MConstruct(PPS2M pThis, PPDMDEVINS pDevIns, void *pParent, int iInstance)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Initialize the queues. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->Mouse.IBase.pfnQueryInterface = ps2mQueryInterface;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->Mouse.IPort.pfnPutEventAbs = ps2mPutEventAbs;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->Mouse.IPort.pfnPutEventMultiTouch = ps2mPutEventMT;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * Initialize the critical section pointer(s).
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * Create the input rate throttling timer. Does not use virtual time!
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_REAL, ps2mThrottleTimer, pThis,
5c8b6fedb1ca14990808596a1268b9c99946c73bvboxsync TMTIMER_FLAGS_DEFAULT_CRIT_SECT, "PS2M Throttle Timer", &pTimer);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * Create the command delay timer.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL, ps2mDelayTimer, pThis,
5c8b6fedb1ca14990808596a1268b9c99946c73bvboxsync TMTIMER_FLAGS_DEFAULT_CRIT_SECT, "PS2M Delay Timer", &pTimer);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * Register debugger info callbacks.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync PDMDevHlpDBGFInfoRegister(pDevIns, "ps2m", "Display PS/2 mouse state.", ps2mInfoState);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync //@todo: Where should we do this?
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#endif /* !VBOX_DEVICE_STRUCT_TESTCASE */