ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync/* $Id$ */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/** @file
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * PS2M - PS/2 auxiliary device (mouse) emulation.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/*
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * Copyright (C) 2007-2013 Oracle Corporation
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync *
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 */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/*
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * References:
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync *
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 *
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync *
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * Notes:
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync *
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 *
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync *
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 *
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 *
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync *
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * Standard PS/2 pointing device three-byte report packet format:
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync *
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 *
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 *
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync *
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * IntelliMouse PS/2 (ImPS/2) fourth report packet byte:
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync *
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 *
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * - The valid range for Z delta values is only -8/+7, i.e. 4 bits.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync *
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * IntelliMouse Explorer (ImEx) fourth report packet byte:
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync *
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 */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/*******************************************************************************
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync* Header Files *
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync*******************************************************************************/
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#define LOG_GROUP LOG_GROUP_DEV_KBD
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#include <VBox/vmm/pdmdev.h>
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#include <VBox/err.h>
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#include <iprt/assert.h>
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#include <iprt/uuid.h>
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#include "VBoxDD.h"
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#define IN_PS2M
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#include "PS2Dev.h"
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/*******************************************************************************
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync* Defined Constants And Macros *
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync*******************************************************************************/
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/** @name Auxiliary device commands sent by the system.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @{ */
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_SET_RES 0xE8 /* Set resolution. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#define ACMD_REQ_STATUS 0xE9 /* Get device status. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#define ACMD_SET_STREAM 0xEA /* Set stream mode. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#define ACMD_READ_REMOTE 0xEB /* Read remote data. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#define ACMD_RESET_WRAP 0xEC /* Exit wrap mode. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#define ACMD_INVALID_1 0xED
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#define ACMD_SET_WRAP 0xEE /* Set wrap (echo) mode. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#define ACMD_INVALID_2 0xEF
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#define ACMD_SET_REMOTE 0xF0 /* Set remote mode. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#define ACMD_INVALID_3 0xF1
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#define ACMD_READ_ID 0xF2 /* Read device ID. */
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#define ACMD_SET_DEFAULT 0xF6 /* Set defaults. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#define ACMD_INVALID_4 0xF7
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#define ACMD_INVALID_5 0xF8
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#define ACMD_INVALID_6 0xF9
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#define ACMD_INVALID_7 0xFA
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#define ACMD_INVALID_8 0xFB
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#define ACMD_INVALID_9 0xFC
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#define ACMD_INVALID_10 0xFD
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#define ACMD_RESEND 0xFE /* Resend response. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#define ACMD_RESET 0xFF /* Reset device. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/** @} */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/** @name Auxiliary device responses sent to the system.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @{ */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#define ARSP_ID 0x00
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#define ARSP_BAT_OK 0xAA /* Self-test passed. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#define ARSP_ACK 0xFA /* Command acknowledged. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#define ARSP_ERROR 0xFC /* Bad command. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#define ARSP_RESEND 0xFE /* Requesting resend. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/** @} */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/** Define a simple PS/2 input device queue. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#define DEF_PS2Q_TYPE(name, size) \
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync typedef struct { \
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync uint32_t rpos; \
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync uint32_t wpos; \
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync uint32_t cUsed; \
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync uint32_t cSize; \
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync uint8_t abQueue[size]; \
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync } name
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
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#define AUX_EVT_QUEUE_SIZE 256
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#define AUX_CMD_QUEUE_SIZE 8
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/*******************************************************************************
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync* Structures and Typedefs *
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync*******************************************************************************/
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncDEF_PS2Q_TYPE(AuxEvtQ, AUX_EVT_QUEUE_SIZE);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncDEF_PS2Q_TYPE(AuxCmdQ, AUX_CMD_QUEUE_SIZE);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#ifndef VBOX_DEVICE_STRUCT_TESTCASE //@todo: hack
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncDEF_PS2Q_TYPE(GeneriQ, 1);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#endif
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/* Auxiliary device special modes of operation. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsynctypedef enum {
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync AUX_MODE_STD, /* Standard operation. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync AUX_MODE_RESET, /* Currently in reset. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync AUX_MODE_WRAP /* Wrap mode (echoing input). */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync} PS2M_MODE;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
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). */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync} PS2M_STATE;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync/* Externally visible state bits. */
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync#define AUX_STATE_EXTERNAL (AUX_STATE_SCALING | AUX_STATE_ENABLED | AUX_STATE_REMOTE)
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync
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} PS2M_PROTO;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/* Protocol selection 'knock' states. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsynctypedef enum {
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync PS2M_KNOCK_INITIAL,
e74c6b6b998c532cdfec426de8ad08b6441e7215vboxsync PS2M_KNOCK_1ST,
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync PS2M_KNOCK_IMPS2_2ND,
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync PS2M_KNOCK_IMEX_2ND
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync} PS2M_KNOCK_STATE;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/**
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * The PS/2 auxiliary device instance data.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsynctypedef struct PS2M
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync{
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** Pointer to parent device (keyboard controller). */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync R3PTRTYPE(void *) pParent;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** Operational state. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync uint8_t u8State;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** Configured sampling rate. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync uint8_t u8SampleRate;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** Configured resolution. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync uint8_t u8Resolution;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** Currently processed command (if any). */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync uint8_t u8CurrCmd;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** Set if the throttle delay is active. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync bool fThrottleActive;
d1310b60a66ca7122b1f7b1a0efdd6af5b5d2235vboxsync /** Set if the throttle delay is active. */
d1310b60a66ca7122b1f7b1a0efdd6af5b5d2235vboxsync bool fDelayReset;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** Operational mode. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync PS2M_MODE enmMode;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** Currently used protocol. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync PS2M_PROTO enmProtocol;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** Currently used protocol. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync PS2M_KNOCK_STATE enmKnockState;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** Buffer holding mouse events to be sent to the host. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync AuxEvtQ evtQ;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** Command response queue (priority). */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync AuxCmdQ cmdQ;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** Accumulated horizontal movement. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync int32_t iAccumX;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** Accumulated vertical movement. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync int32_t iAccumY;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** Accumulated Z axis movement. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync int32_t iAccumZ;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** Accumulated button presses. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync uint32_t fAccumB;
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync /** Instantaneous button data. */
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync uint32_t fCurrB;
c0015339febab0b824ff8d8293abc82fa2189982vboxsync /** Button state last sent to the guest. */
c0015339febab0b824ff8d8293abc82fa2189982vboxsync uint32_t fReportedB;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** Throttling delay in milliseconds. */
ee7f55a76bfe96d9ae800e58529ab5b957cd8653vboxsync uint32_t uThrottleDelay;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** The device critical section protecting everything - R3 Ptr */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync R3PTRTYPE(PPDMCRITSECT) pCritSectR3;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** Command delay timer - R3 Ptr. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync PTMTIMERR3 pDelayTimerR3;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** Interrupt throttling timer - R3 Ptr. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync PTMTIMERR3 pThrottleTimerR3;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync RTR3PTR Alignment1;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** Command delay timer - RC Ptr. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync PTMTIMERRC pDelayTimerRC;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** Interrupt throttling timer - RC Ptr. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync PTMTIMERRC pThrottleTimerRC;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** Command delay timer - R0 Ptr. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync PTMTIMERR0 pDelayTimerR0;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** Interrupt throttling timer - R0 Ptr. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync PTMTIMERR0 pThrottleTimerR0;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /**
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * Mouse port - LUN#1.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync *
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @implements PDMIBASE
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @implements PDMIMOUSEPORT
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync struct
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync {
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** The base interface for the mouse port. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync PDMIBASE IBase;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** The keyboard port base interface. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync PDMIMOUSEPORT IPort;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** The base interface of the attached mouse driver. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync R3PTRTYPE(PPDMIBASE) pDrvBase;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /** The keyboard interface of the attached mouse driver. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync R3PTRTYPE(PPDMIMOUSECONNECTOR) pDrv;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync } Mouse;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync} PS2M, *PPS2M;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncAssertCompile(PS2M_STRUCT_FILLER >= sizeof(PS2M));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#ifndef VBOX_DEVICE_STRUCT_TESTCASE
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/*******************************************************************************
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync* Global Variables *
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync*******************************************************************************/
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/*******************************************************************************
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync* Internal Functions *
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync*******************************************************************************/
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/**
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * Clear a queue.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync *
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @param pQ Pointer to the queue.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncstatic void ps2kClearQueue(GeneriQ *pQ)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync{
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync LogFlowFunc(("Clearing queue %p\n", pQ));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pQ->wpos = pQ->rpos;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pQ->cUsed = 0;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync}
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/**
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * Add a byte to a queue.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync *
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @param pQ Pointer to the queue.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @param val The byte to store.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncstatic void ps2kInsertQueue(GeneriQ *pQ, uint8_t val)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync{
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Check if queue is full. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync if (pQ->cUsed >= pQ->cSize)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync {
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync LogFlowFunc(("queue %p full (%d entries)\n", pQ, pQ->cUsed));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync return;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync }
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Insert data and update circular buffer write position. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pQ->abQueue[pQ->wpos] = val;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync if (++pQ->wpos == pQ->cSize)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pQ->wpos = 0; /* Roll over. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ++pQ->cUsed;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync LogFlowFunc(("inserted 0x%02X into queue %p\n", val, pQ));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync}
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#ifdef IN_RING3
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/**
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * Save a queue state.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync *
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @param pSSM SSM handle to write the state to.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @param pQ Pointer to the queue.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncstatic void ps2kSaveQueue(PSSMHANDLE pSSM, GeneriQ *pQ)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync{
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync uint32_t cItems = pQ->cUsed;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync int i;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
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 */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync SSMR3PutU32(pSSM, cItems);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync LogFlow(("Storing %d items from queue %p\n", cItems, pQ));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Save queue data - only the bytes actually used (typically zero). */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync for (i = pQ->rpos; cItems-- > 0; i = (i + 1) % pQ->cSize)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync SSMR3PutU8(pSSM, pQ->abQueue[i]);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync}
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/**
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * Load a queue state.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync *
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @param pSSM SSM handle to read the state from.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @param pQ Pointer to the queue.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync *
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @return int VBox status/error code.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncstatic int ps2kLoadQueue(PSSMHANDLE pSSM, GeneriQ *pQ)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync{
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync int rc;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* On load, always put the read pointer at zero. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync SSMR3GetU32(pSSM, &pQ->cUsed);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync LogFlow(("Loading %d items to queue %p\n", pQ->cUsed, pQ));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync if (pQ->cUsed > pQ->cSize)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync {
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync AssertMsgFailed(("Saved size=%u, actual=%u\n", pQ->cUsed, pQ->cSize));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync }
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Recalculate queue positions and load data in one go. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pQ->rpos = 0;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pQ->wpos = pQ->cUsed;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync rc = SSMR3GetMem(pSSM, pQ->abQueue, pQ->cUsed);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync return rc;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync}
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/* Report a change in status down (or is it up?) the driver chain. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncstatic void ps2mSetDriverState(PPS2M pThis, bool fEnabled)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync{
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync PPDMIMOUSECONNECTOR pDrv = pThis->Mouse.pDrv;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync if (pDrv)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pDrv->pfnReportModes(pDrv, fEnabled, false, false);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync}
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
d1310b60a66ca7122b1f7b1a0efdd6af5b5d2235vboxsync/* Reset the pointing device. */
d1310b60a66ca7122b1f7b1a0efdd6af5b5d2235vboxsyncstatic void ps2mReset(PPS2M pThis)
d1310b60a66ca7122b1f7b1a0efdd6af5b5d2235vboxsync{
d1310b60a66ca7122b1f7b1a0efdd6af5b5d2235vboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_BAT_OK);
d1310b60a66ca7122b1f7b1a0efdd6af5b5d2235vboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, 0);
d1310b60a66ca7122b1f7b1a0efdd6af5b5d2235vboxsync pThis->enmMode = AUX_MODE_STD;
d1310b60a66ca7122b1f7b1a0efdd6af5b5d2235vboxsync pThis->u8CurrCmd = 0;
d1310b60a66ca7122b1f7b1a0efdd6af5b5d2235vboxsync
d1310b60a66ca7122b1f7b1a0efdd6af5b5d2235vboxsync //@todo: move to its proper home!
d1310b60a66ca7122b1f7b1a0efdd6af5b5d2235vboxsync ps2mSetDriverState(pThis, true);
d1310b60a66ca7122b1f7b1a0efdd6af5b5d2235vboxsync}
d1310b60a66ca7122b1f7b1a0efdd6af5b5d2235vboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#endif /* IN_RING3 */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/**
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * Retrieve a byte from a queue.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync *
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @param pQ Pointer to the queue.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @param pVal Pointer to storage for the byte.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync *
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @return int VINF_TRY_AGAIN if queue is empty,
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * VINF_SUCCESS if a byte was read.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncstatic int ps2kRemoveQueue(GeneriQ *pQ, uint8_t *pVal)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync{
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync int rc = VINF_TRY_AGAIN;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync Assert(pVal);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync if (pQ->cUsed)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync {
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync *pVal = pQ->abQueue[pQ->rpos];
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync if (++pQ->rpos == pQ->cSize)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pQ->rpos = 0; /* Roll over. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync --pQ->cUsed;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync rc = VINF_SUCCESS;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync LogFlowFunc(("removed 0x%02X from queue %p\n", *pVal, pQ));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync } else
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync LogFlowFunc(("queue %p empty\n", pQ));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync return rc;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync}
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncstatic void ps2mSetRate(PPS2M pThis, uint8_t rate)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync{
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync Assert(rate);
c1d5e93e911979ec2a78b200ac98da7163896edfvboxsync pThis->uThrottleDelay = rate ? 1000 / rate : 0;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->u8SampleRate = rate;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync LogFlowFunc(("Sampling rate %u, throttle delay %u ms\n", pThis->u8SampleRate, pThis->uThrottleDelay));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync}
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncstatic void ps2mSetDefaults(PPS2M pThis)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync{
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync LogFlowFunc(("Set mouse defaults\n"));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Standard protocol, reporting disabled, resolution 2, 1:1 scaling. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->enmProtocol = PS2M_PROTO_PS2STD;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->u8State = 0;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->u8Resolution = 2;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Sample rate 100 reports per second. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2mSetRate(pThis, 100);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
f6ec7fe3e4607b1c0c06fd650be48072f410c95dvboxsync /* Event queue, eccumulators, and button status bits are cleared. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2kClearQueue((GeneriQ *)&pThis->evtQ);
c0015339febab0b824ff8d8293abc82fa2189982vboxsync pThis->iAccumX = pThis->iAccumY = pThis->iAccumZ = pThis->fAccumB;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync}
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/* Handle the sampling rate 'knock' sequence which selects protocol. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncstatic void ps2mRateProtocolKnock(PPS2M pThis, uint8_t rate)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync{
e74c6b6b998c532cdfec426de8ad08b6441e7215vboxsync switch (pThis->enmKnockState)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync {
e74c6b6b998c532cdfec426de8ad08b6441e7215vboxsync case PS2M_KNOCK_INITIAL:
e74c6b6b998c532cdfec426de8ad08b6441e7215vboxsync if (rate == 200)
e74c6b6b998c532cdfec426de8ad08b6441e7215vboxsync pThis->enmKnockState = PS2M_KNOCK_1ST;
e74c6b6b998c532cdfec426de8ad08b6441e7215vboxsync break;
e74c6b6b998c532cdfec426de8ad08b6441e7215vboxsync case PS2M_KNOCK_1ST:
e74c6b6b998c532cdfec426de8ad08b6441e7215vboxsync if (rate == 100)
e74c6b6b998c532cdfec426de8ad08b6441e7215vboxsync pThis->enmKnockState = PS2M_KNOCK_IMPS2_2ND;
e74c6b6b998c532cdfec426de8ad08b6441e7215vboxsync else if (rate == 200)
e74c6b6b998c532cdfec426de8ad08b6441e7215vboxsync pThis->enmKnockState = PS2M_KNOCK_IMEX_2ND;
e74c6b6b998c532cdfec426de8ad08b6441e7215vboxsync else
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->enmKnockState = PS2M_KNOCK_INITIAL;
e74c6b6b998c532cdfec426de8ad08b6441e7215vboxsync break;
e74c6b6b998c532cdfec426de8ad08b6441e7215vboxsync case PS2M_KNOCK_IMPS2_2ND:
e74c6b6b998c532cdfec426de8ad08b6441e7215vboxsync if (rate == 80)
e74c6b6b998c532cdfec426de8ad08b6441e7215vboxsync {
e74c6b6b998c532cdfec426de8ad08b6441e7215vboxsync pThis->enmProtocol = PS2M_PROTO_IMPS2;
e74c6b6b998c532cdfec426de8ad08b6441e7215vboxsync LogRelFlow(("PS2M: Switching mouse to ImPS/2 protocol.\n"));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync }
e74c6b6b998c532cdfec426de8ad08b6441e7215vboxsync pThis->enmKnockState = PS2M_KNOCK_INITIAL;
e74c6b6b998c532cdfec426de8ad08b6441e7215vboxsync break;
e74c6b6b998c532cdfec426de8ad08b6441e7215vboxsync case PS2M_KNOCK_IMEX_2ND:
e74c6b6b998c532cdfec426de8ad08b6441e7215vboxsync if (rate == 80)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync {
e74c6b6b998c532cdfec426de8ad08b6441e7215vboxsync pThis->enmProtocol = PS2M_PROTO_IMEX;
e74c6b6b998c532cdfec426de8ad08b6441e7215vboxsync LogRelFlow(("PS2M: Switching mouse to ImEx protocol.\n"));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync }
e74c6b6b998c532cdfec426de8ad08b6441e7215vboxsync /* Fall through! */
e74c6b6b998c532cdfec426de8ad08b6441e7215vboxsync default:
e74c6b6b998c532cdfec426de8ad08b6441e7215vboxsync pThis->enmKnockState = PS2M_KNOCK_INITIAL;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync }
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync}
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync/* Three-button event mask. */
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync#define PS2M_STD_BTN_MASK (RT_BIT(0) | RT_BIT(1) | RT_BIT(2))
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync/* Report accumulated movement and button presses, then clear the accumulators. */
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsyncstatic void ps2mReportAccumulatedEvents(PPS2M pThis, GeneriQ *pQueue, bool fAccumBtns)
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync{
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync uint32_t fBtnState = fAccumBtns ? pThis->fAccumB : pThis->fCurrB;
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync uint8_t val;
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync int dX, dY, dZ;
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync /* Clamp the accumulated delta values to the allowed range. */
892ba2c161e62c8e858f2fcf299c38951e330d39vboxsync dX = RT_MIN(RT_MAX(pThis->iAccumX, -255), 255);
892ba2c161e62c8e858f2fcf299c38951e330d39vboxsync dY = RT_MIN(RT_MAX(pThis->iAccumY, -255), 255);
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync dZ = RT_MIN(RT_MAX(pThis->iAccumZ, -8), 7);
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync /* Start with the sync bit and buttons 1-3. */
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync val = RT_BIT(3) | (fBtnState & PS2M_STD_BTN_MASK);
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync /* Set the X/Y sign bits. */
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync if (dX < 0)
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync val |= RT_BIT(4);
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync if (dY < 0)
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync val |= RT_BIT(5);
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync /* Send the standard 3-byte packet (always the same). */
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync ps2kInsertQueue(pQueue, val);
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync ps2kInsertQueue(pQueue, dX);
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync ps2kInsertQueue(pQueue, dY);
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync /* Add fourth byte if extended protocol is in use. */
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync if (pThis->enmProtocol > PS2M_PROTO_PS2STD)
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync {
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync if (pThis->enmProtocol == PS2M_PROTO_IMPS2)
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync ps2kInsertQueue(pQueue, dZ);
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync else
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync {
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync Assert(pThis->enmProtocol == PS2M_PROTO_IMEX);
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync /* Z value uses 4 bits; buttons 4/5 in bits 4 and 5. */
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync val = dZ & 0x0f;
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync val |= (fBtnState << 1) & (RT_BIT(4) | RT_BIT(5));
9c0221b469bab6bb2479b1b9ce7fd5de9ab2d519vboxsync ps2kInsertQueue(pQueue, val);
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync }
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync }
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync
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. */
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync if (fAccumBtns)
c0015339febab0b824ff8d8293abc82fa2189982vboxsync {
c0015339febab0b824ff8d8293abc82fa2189982vboxsync pThis->fReportedB = pThis->fAccumB;
c0015339febab0b824ff8d8293abc82fa2189982vboxsync pThis->fAccumB = 0;
c0015339febab0b824ff8d8293abc82fa2189982vboxsync }
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync}
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync/* Determine whether a reporting rate is one of the valid ones. */
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsyncbool ps2mIsRateSupported(uint8_t rate)
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync{
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync static uint8_t aValidRates[] = { 10, 20, 40, 60, 80, 100, 200 };
b5ac78cae3b763dc564386dc1c307c679215a23bvboxsync size_t i;
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync bool fValid = false;
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync for (i = 0; i < RT_ELEMENTS(aValidRates); ++i)
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync if (aValidRates[i] == rate)
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync {
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync fValid = true;
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync break;
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync }
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync return fValid;
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync}
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/**
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * Receive and process a byte sent by the keyboard controller.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync *
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @param pThis The PS/2 auxiliary device instance data.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @param cmd The command (or data) byte.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncint PS2MByteToAux(PPS2M pThis, uint8_t cmd)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync{
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync uint8_t u8Val;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync bool fHandled = true;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
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));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
67b6e4f9c1d5be5c46a4ab5e9c17513d3b524938vboxsync if (pThis->enmMode == AUX_MODE_RESET)
67b6e4f9c1d5be5c46a4ab5e9c17513d3b524938vboxsync /* In reset mode, do not respond at all. */
67b6e4f9c1d5be5c46a4ab5e9c17513d3b524938vboxsync return VINF_SUCCESS;
f6ec7fe3e4607b1c0c06fd650be48072f410c95dvboxsync
f6ec7fe3e4607b1c0c06fd650be48072f410c95dvboxsync /* If there's anything left in the command response queue, trash it. */
f6ec7fe3e4607b1c0c06fd650be48072f410c95dvboxsync ps2kClearQueue((GeneriQ *)&pThis->cmdQ);
f6ec7fe3e4607b1c0c06fd650be48072f410c95dvboxsync
f6ec7fe3e4607b1c0c06fd650be48072f410c95dvboxsync if (pThis->enmMode == AUX_MODE_WRAP)
67b6e4f9c1d5be5c46a4ab5e9c17513d3b524938vboxsync {
67b6e4f9c1d5be5c46a4ab5e9c17513d3b524938vboxsync /* In wrap mode, bounce most data right back.*/
67b6e4f9c1d5be5c46a4ab5e9c17513d3b524938vboxsync if (cmd == ACMD_RESET || cmd == ACMD_RESET_WRAP)
67b6e4f9c1d5be5c46a4ab5e9c17513d3b524938vboxsync ; /* Handle as regular commands. */
67b6e4f9c1d5be5c46a4ab5e9c17513d3b524938vboxsync else
67b6e4f9c1d5be5c46a4ab5e9c17513d3b524938vboxsync {
67b6e4f9c1d5be5c46a4ab5e9c17513d3b524938vboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, cmd);
67b6e4f9c1d5be5c46a4ab5e9c17513d3b524938vboxsync return VINF_SUCCESS;
67b6e4f9c1d5be5c46a4ab5e9c17513d3b524938vboxsync }
67b6e4f9c1d5be5c46a4ab5e9c17513d3b524938vboxsync }
67b6e4f9c1d5be5c46a4ab5e9c17513d3b524938vboxsync
d1310b60a66ca7122b1f7b1a0efdd6af5b5d2235vboxsync#ifndef IN_RING3
2ce50c7f2d493de97978fc2a75c14c65ee5bf945vboxsync /* Reset, Enable, and Set Default commands must be run in R3. */
2ce50c7f2d493de97978fc2a75c14c65ee5bf945vboxsync if (cmd == ACMD_RESET || cmd == ACMD_ENABLE || cmd == ACMD_SET_DEFAULT)
d1310b60a66ca7122b1f7b1a0efdd6af5b5d2235vboxsync return VINF_IOM_R3_IOPORT_WRITE;
d1310b60a66ca7122b1f7b1a0efdd6af5b5d2235vboxsync#endif
d1310b60a66ca7122b1f7b1a0efdd6af5b5d2235vboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync switch (cmd)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync {
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync case ACMD_SET_SCALE_11:
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->u8State &= ~AUX_STATE_SCALING;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->u8CurrCmd = 0;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync break;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync case ACMD_SET_SCALE_21:
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->u8State |= AUX_STATE_SCALING;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->u8CurrCmd = 0;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync break;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync case ACMD_REQ_STATUS:
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, u8Val);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, pThis->u8Resolution);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, pThis->u8SampleRate);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->u8CurrCmd = 0;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync break;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync case ACMD_SET_STREAM:
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->u8State &= ~AUX_STATE_REMOTE;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->u8CurrCmd = 0;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync break;
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync case ACMD_READ_REMOTE:
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync ps2mReportAccumulatedEvents(pThis, (GeneriQ *)&pThis->cmdQ, false);
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync pThis->u8CurrCmd = 0;
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync break;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync case ACMD_RESET_WRAP:
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->enmMode = AUX_MODE_STD;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* NB: Stream mode reporting remains disabled! */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->u8CurrCmd = 0;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync break;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync case ACMD_SET_WRAP:
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->enmMode = AUX_MODE_WRAP;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->u8State &= ~AUX_STATE_ENABLED;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->u8CurrCmd = 0;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync break;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync case ACMD_SET_REMOTE:
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->u8State |= AUX_STATE_REMOTE;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->u8CurrCmd = 0;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync break;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync case ACMD_READ_ID:
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, pThis->enmProtocol);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->u8CurrCmd = 0;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync break;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync case ACMD_ENABLE:
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->u8State |= AUX_STATE_ENABLED;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#ifdef IN_RING3
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2mSetDriverState(pThis, true);
d1310b60a66ca7122b1f7b1a0efdd6af5b5d2235vboxsync#else
d1310b60a66ca7122b1f7b1a0efdd6af5b5d2235vboxsync AssertLogRelMsgFailed(("Invalid ACMD_ENABLE outside R3!\n"));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#endif
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2kClearQueue((GeneriQ *)&pThis->evtQ);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->u8CurrCmd = 0;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync break;
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync case ACMD_DISABLE:
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync pThis->u8State &= ~AUX_STATE_ENABLED;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->u8CurrCmd = 0;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync break;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync case ACMD_SET_DEFAULT:
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2mSetDefaults(pThis);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->u8CurrCmd = 0;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync break;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync case ACMD_RESEND:
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->u8CurrCmd = 0;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync break;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync case ACMD_RESET:
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2mSetDefaults(pThis);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ///@todo reset more?
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->u8CurrCmd = cmd;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->enmMode = AUX_MODE_RESET;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
d1310b60a66ca7122b1f7b1a0efdd6af5b5d2235vboxsync if (pThis->fDelayReset)
d1310b60a66ca7122b1f7b1a0efdd6af5b5d2235vboxsync /* Slightly delay reset completion; it might take hundreds of ms. */
d1310b60a66ca7122b1f7b1a0efdd6af5b5d2235vboxsync TMTimerSetMillies(pThis->CTX_SUFF(pDelayTimer), 1);
d1310b60a66ca7122b1f7b1a0efdd6af5b5d2235vboxsync else
d1310b60a66ca7122b1f7b1a0efdd6af5b5d2235vboxsync#ifdef IN_RING3
d1310b60a66ca7122b1f7b1a0efdd6af5b5d2235vboxsync ps2mReset(pThis);
d1310b60a66ca7122b1f7b1a0efdd6af5b5d2235vboxsync#else
d1310b60a66ca7122b1f7b1a0efdd6af5b5d2235vboxsync AssertLogRelMsgFailed(("Invalid ACMD_RESET outside R3!\n"));
d1310b60a66ca7122b1f7b1a0efdd6af5b5d2235vboxsync#endif
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync break;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* The following commands need a parameter. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync case ACMD_SET_RES:
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync case ACMD_SET_SAMP_RATE:
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->u8CurrCmd = cmd;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync break;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync default:
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Sending a command instead of a parameter starts the new command. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync switch (pThis->u8CurrCmd)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync {
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync case ACMD_SET_RES:
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync if (cmd < 4) /* Valid resolutions are 0-3. */
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync {
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync pThis->u8Resolution = cmd;
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync pThis->u8State &= ~AUX_STATE_RES_ERR;
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync pThis->u8CurrCmd = 0;
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync }
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync else
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync {
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync /* Bad resolution. Reply with Resend or Error. */
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync if (pThis->u8State & AUX_STATE_RES_ERR)
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync {
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync pThis->u8State &= ~AUX_STATE_RES_ERR;
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ERROR);
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync pThis->u8CurrCmd = 0;
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync }
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync else
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync {
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync pThis->u8State |= AUX_STATE_RES_ERR;
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_RESEND);
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync /* NB: Current command remains unchanged. */
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync }
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync }
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync break;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync case ACMD_SET_SAMP_RATE:
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync if (ps2mIsRateSupported(cmd))
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync {
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync pThis->u8State &= ~AUX_STATE_RATE_ERR;
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync ps2mSetRate(pThis, cmd);
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync ps2mRateProtocolKnock(pThis, cmd);
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync pThis->u8CurrCmd = 0;
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync }
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync else
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync {
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync /* Bad rate. Reply with Resend or Error. */
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync if (pThis->u8State & AUX_STATE_RATE_ERR)
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync {
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync pThis->u8State &= ~AUX_STATE_RATE_ERR;
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ERROR);
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync pThis->u8CurrCmd = 0;
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync }
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync else
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync {
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync pThis->u8State |= AUX_STATE_RATE_ERR;
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_RESEND);
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync /* NB: Current command remains unchanged. */
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync }
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync }
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync break;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync default:
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync fHandled = false;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync }
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Fall through only to handle unrecognized commands. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync if (fHandled)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync break;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync case ACMD_INVALID_1:
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync case ACMD_INVALID_2:
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync case ACMD_INVALID_3:
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync case ACMD_INVALID_4:
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync case ACMD_INVALID_5:
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync case ACMD_INVALID_6:
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync case ACMD_INVALID_7:
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync case ACMD_INVALID_8:
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync case ACMD_INVALID_9:
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync case ACMD_INVALID_10:
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync Log(("Unsupported command 0x%02X!\n", cmd));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_RESEND);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->u8CurrCmd = 0;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync break;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync }
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync LogFlowFunc(("Active cmd now 0x%02X; updating interrupts\n", pThis->u8CurrCmd));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync// KBCUpdateInterrupts(pThis->pParent);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync return VINF_SUCCESS;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync}
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/**
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * Send a byte (keystroke or command response) to the keyboard controller.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync *
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 */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncint PS2MByteFromAux(PPS2M pThis, uint8_t *pb)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync{
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync int rc;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync AssertPtr(pb);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
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 */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync //@todo: Probably should flush/not fill queue if stream mode reporting disabled?!
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync rc = ps2kRemoveQueue((GeneriQ *)&pThis->cmdQ, pb);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync if (rc != VINF_SUCCESS && !pThis->u8CurrCmd && (pThis->u8State & AUX_STATE_ENABLED))
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync rc = ps2kRemoveQueue((GeneriQ *)&pThis->evtQ, pb);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
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
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync return rc;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync}
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#ifdef IN_RING3
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/* Event rate throttling timer to emulate the auxiliary device sampling rate.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncstatic DECLCALLBACK(void) ps2mThrottleTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync{
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync PPS2M pThis = (PS2M *)pvUser; NOREF(pDevIns);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync uint32_t uHaveEvents;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Grab the lock to avoid races with PutEvent(). */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync int rc = PDMCritSectEnter(pThis->pCritSectR3, VERR_SEM_BUSY);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync AssertReleaseRC(rc);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#if 0
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* If the input queue is not empty, restart the timer. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#else
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"));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync if (uHaveEvents)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#endif
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync {
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync /* Report accumulated data, poke the KBC, and start the timer. */
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync ps2mReportAccumulatedEvents(pThis, (GeneriQ *)&pThis->evtQ, true);
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync KBCUpdateInterrupts(pThis->pParent);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync TMTimerSetMillies(pThis->CTX_SUFF(pThrottleTimer), pThis->uThrottleDelay);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync }
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync else
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->fThrottleActive = false;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync PDMCritSectLeave(pThis->pCritSectR3);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync}
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
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.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncstatic DECLCALLBACK(void) ps2mDelayTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync{
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync PPS2M pThis = (PS2M *)pvUser; NOREF(pDevIns);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync LogFlowFunc(("Delay timer: cmd %02X\n", pThis->u8CurrCmd));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync Assert(pThis->u8CurrCmd == ACMD_RESET);
d1310b60a66ca7122b1f7b1a0efdd6af5b5d2235vboxsync ps2mReset(pThis);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ///@todo Might want a PS2MCompleteCommand() to push last response, clear command, and kick the KBC...
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Give the KBC a kick. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync KBCUpdateInterrupts(pThis->pParent);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync}
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/**
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * Debug device info handler. Prints basic auxiliary device state.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync *
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.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncstatic DECLCALLBACK(void) ps2mInfoState(PPDMDEVINS pDevIns, PCDBGFINFOHLP pHlp, const char *pszArgs)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync{
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync static const char *pcszModes[] = { "normal", "reset", "wrap" };
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync static const char *pcszProtocols[] = { "PS/2", NULL, NULL, "ImPS/2", "ImEx" };
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync PPS2M pThis = KBDGetPS2MFromDevIns(pDevIns);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync NOREF(pszArgs);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync Assert(pThis->enmMode <= RT_ELEMENTS(pcszModes));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync Assert(pThis->enmProtocol <= RT_ELEMENTS(pcszProtocols));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pHlp->pfnPrintf(pHlp, "PS/2 mouse state: %s, %s mode, reporting %s\n",
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pcszModes[pThis->enmMode],
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 pThis->u8SampleRate, 1 << pThis->u8Resolution);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pHlp->pfnPrintf(pHlp, "Command queue: %d items (%d max)\n",
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->cmdQ.cUsed, pThis->cmdQ.cSize);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pHlp->pfnPrintf(pHlp, "Event queue : %d items (%d max)\n",
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->evtQ.cUsed, pThis->evtQ.cSize);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync}
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/* -=-=-=-=-=- Mouse: IBase -=-=-=-=-=- */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/**
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @interface_method_impl{PDMIBASE,pfnQueryInterface}
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncstatic DECLCALLBACK(void *) ps2mQueryInterface(PPDMIBASE pInterface, const char *pszIID)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync{
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 return NULL;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync}
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/* -=-=-=-=-=- Mouse: IMousePort -=-=-=-=-=- */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/**
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * Mouse event handler.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync *
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.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncstatic int ps2mPutEventWorker(PPS2M pThis, int32_t dx, int32_t dy,
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync int32_t dz, int32_t dw, uint32_t fButtons)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync{
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync int rc = VINF_SUCCESS;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Update internal accumulators and button state. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->iAccumX += dx;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->iAccumY += dy;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->iAccumZ += dz;
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync pThis->fAccumB |= fButtons; //@todo: accumulate based on current protocol?
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync pThis->fCurrB = fButtons;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#if 1
f6ec7fe3e4607b1c0c06fd650be48072f410c95dvboxsync /* Report the event and start the throttle timer unless it's already running. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync if (!pThis->fThrottleActive)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync {
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync ps2mReportAccumulatedEvents(pThis, (GeneriQ *)&pThis->evtQ, true);
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync KBCUpdateInterrupts(pThis->pParent);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->fThrottleActive = true;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync TMTimerSetMillies(pThis->CTX_SUFF(pThrottleTimer), pThis->uThrottleDelay);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync }
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#else
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Clamp the delta values to the allowed range. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync dx = RT_MIN(RT_MAX(dx, -256), 255);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync dy = RT_MIN(RT_MAX(dy, -256), 255);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Start with the sync bit. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync val = RT_BIT(3);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Add buttons 1-3. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync val |= fButtons & PS2M_STD_BTN_MASK;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Set the X/Y sign bits. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync if (dx < 0)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync val |= RT_BIT(4);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync if (dy < 0)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync val |= RT_BIT(5);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2kInsertQueue((GeneriQ *)&pThis->evtQ, val);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2kInsertQueue((GeneriQ *)&pThis->evtQ, (uint8_t)dx);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2kInsertQueue((GeneriQ *)&pThis->evtQ, (uint8_t)dy);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync if (pThis->enmProtocol > PS2M_PROTO_PS2STD)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync {
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2kInsertQueue((GeneriQ *)&pThis->evtQ, (uint8_t)dz);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync }
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#endif
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync return rc;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync}
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/* -=-=-=-=-=- Mouse: IMousePort -=-=-=-=-=- */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/**
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @interface_method_impl{PDMIMOUSEPORT, pfnPutEvent}
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncstatic DECLCALLBACK(int) ps2mPutEvent(PPDMIMOUSEPORT pInterface, int32_t dx, int32_t dy,
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync int32_t dz, int32_t dw, uint32_t fButtons)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync{
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync PPS2M pThis = RT_FROM_MEMBER(pInterface, PS2M, Mouse.IPort);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync int rc = PDMCritSectEnter(pThis->pCritSectR3, VERR_SEM_BUSY);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync AssertReleaseRC(rc);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
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
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync PDMCritSectLeave(pThis->pCritSectR3);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync return VINF_SUCCESS;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync}
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/**
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @interface_method_impl{PDMIMOUSEPORT, pfnPutEventAbs}
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncstatic DECLCALLBACK(int) ps2mPutEventAbs(PPDMIMOUSEPORT pInterface, uint32_t x, uint32_t y,
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync int32_t dz, int32_t dw, uint32_t fButtons)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync{
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync AssertFailedReturn(VERR_NOT_SUPPORTED);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync NOREF(pInterface); NOREF(x); NOREF(y); NOREF(dz); NOREF(dw); NOREF(fButtons);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync}
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/**
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * @interface_method_impl{PDMIMOUSEPORT, pfnPutEventMultiTouch}
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncstatic DECLCALLBACK(int) ps2mPutEventMT(PPDMIMOUSEPORT pInterface, uint8_t cContacts,
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync const uint64_t *pau64Contacts, uint32_t u32ScanTime)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync{
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync AssertFailedReturn(VERR_NOT_SUPPORTED);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync NOREF(pInterface); NOREF(cContacts); NOREF(pau64Contacts); NOREF(u32ScanTime);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync}
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync/**
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * Attach command.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync *
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * This is called to let the device attach to a driver for a
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * specified LUN.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync *
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * This is like plugging in the mouse after turning on the
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * system.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync *
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.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncint PS2MAttach(PPS2M pThis, PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync{
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync int rc;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* The LUN must be 1, i.e. mouse. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync Assert(iLUN == 1);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync AssertMsgReturn(fFlags & PDM_TACH_FLAGS_NOT_HOT_PLUG,
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ("PS/2 mouse does not support hotplugging\n"),
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync VERR_INVALID_PARAMETER);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync LogFlowFunc(("iLUN=%d\n", iLUN));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync rc = PDMDevHlpDriverAttach(pDevIns, iLUN, &pThis->Mouse.IBase, &pThis->Mouse.pDrvBase, "Mouse Port");
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync if (RT_SUCCESS(rc))
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync {
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->Mouse.pDrv = PDMIBASE_QUERY_INTERFACE(pThis->Mouse.pDrvBase, PDMIMOUSECONNECTOR);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync if (!pThis->Mouse.pDrv)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync {
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync AssertLogRelMsgFailed(("LUN #1 doesn't have a mouse interface! rc=%Rrc\n", rc));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync rc = VERR_PDM_MISSING_INTERFACE;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync }
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync }
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync else if (rc == VERR_PDM_NO_ATTACHED_DRIVER)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync {
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync Log(("%s/%d: warning: no driver attached to LUN #1!\n", pDevIns->pReg->szName, pDevIns->iInstance));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync rc = VINF_SUCCESS;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync }
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync else
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync AssertLogRelMsgFailed(("Failed to attach LUN #1! rc=%Rrc\n", rc));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync return rc;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync}
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncvoid PS2MSaveState(PPS2M pThis, PSSMHANDLE pSSM)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync{
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync uint32_t cPressed = 0;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync LogFlowFunc(("Saving PS2M state\n"));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Save the core auxiliary device state. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync SSMR3PutU8(pSSM, pThis->u8State);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync SSMR3PutU8(pSSM, pThis->u8SampleRate);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync SSMR3PutU8(pSSM, pThis->u8Resolution);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync SSMR3PutU8(pSSM, pThis->u8CurrCmd);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync SSMR3PutU8(pSSM, pThis->enmMode);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync SSMR3PutU8(pSSM, pThis->enmProtocol);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync SSMR3PutU8(pSSM, pThis->enmKnockState);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Save the command and event queues. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2kSaveQueue(pSSM, (GeneriQ *)&pThis->cmdQ);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2kSaveQueue(pSSM, (GeneriQ *)&pThis->evtQ);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Save the command delay timer. Note that the rate throttling
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * timer is *not* saved.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync TMR3TimerSave(pThis->CTX_SUFF(pDelayTimer), pSSM);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync}
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncint PS2MLoadState(PPS2M pThis, PSSMHANDLE pSSM, uint32_t uVersion)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync{
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync uint8_t u8;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync int rc;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync NOREF(uVersion);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync LogFlowFunc(("Loading PS2M state version %u\n", uVersion));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Load the basic auxiliary device state. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync SSMR3GetU8(pSSM, &pThis->u8State);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync SSMR3GetU8(pSSM, &pThis->u8SampleRate);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync SSMR3GetU8(pSSM, &pThis->u8Resolution);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync SSMR3GetU8(pSSM, &pThis->u8CurrCmd);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync SSMR3GetU8(pSSM, &u8);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->enmMode = (PS2M_MODE)u8;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync SSMR3GetU8(pSSM, &u8);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->enmProtocol = (PS2M_PROTO)u8;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync SSMR3GetU8(pSSM, &u8);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->enmKnockState = (PS2M_KNOCK_STATE)u8;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Load the command and event queues. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync rc = ps2kLoadQueue(pSSM, (GeneriQ *)&pThis->cmdQ);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync AssertRCReturn(rc, rc);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync rc = ps2kLoadQueue(pSSM, (GeneriQ *)&pThis->evtQ);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync AssertRCReturn(rc, rc);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Load the command delay timer, just in case. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync rc = TMR3TimerLoad(pThis->CTX_SUFF(pDelayTimer), pSSM);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync AssertRCReturn(rc, rc);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Recalculate the throttling delay. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2mSetRate(pThis, pThis->u8SampleRate);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2mSetDriverState(pThis, !!(pThis->u8State & AUX_STATE_ENABLED));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync return rc;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync}
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsyncvoid PS2MFixupState(PPS2M pThis, uint8_t u8State, uint8_t u8Rate, uint8_t u8Proto)
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync{
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync LogFlowFunc(("Fixing up old PS2M state version\n"));
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync /* Load the basic auxiliary device state. */
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync pThis->u8State = u8State;
07da12a45cbdde033cd52f83e8fa8d70f8b71b17vboxsync pThis->u8SampleRate = u8Rate ? u8Rate : 40; /* In case it wasn't saved right. */
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync pThis->enmProtocol = (PS2M_PROTO)u8Proto;
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync /* Recalculate the throttling delay. */
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync ps2mSetRate(pThis, pThis->u8SampleRate);
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync ps2mSetDriverState(pThis, !!(pThis->u8State & AUX_STATE_ENABLED));
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync}
ed4a2bd5f3f74bb638e09a9ef937e69d130263d6vboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncvoid PS2MReset(PPS2M pThis)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync{
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync LogFlowFunc(("Resetting PS2M\n"));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->u8CurrCmd = 0;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Clear the queues. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2kClearQueue((GeneriQ *)&pThis->cmdQ);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2mSetDefaults(pThis); /* Also clears event queue. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Activate the PS/2 mouse by default. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync// if (pThis->Mouse.pDrv)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync// pThis->Mouse.pDrv->pfnSetActive(pThis->Mouse.pDrv, true);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync}
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncvoid PS2MRelocate(PPS2M pThis, RTGCINTPTR offDelta, PPDMDEVINS pDevIns)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync{
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync LogFlowFunc(("Relocating PS2M\n"));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->pDelayTimerRC = TMTimerRCPtr(pThis->pDelayTimerR3);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->pThrottleTimerRC = TMTimerRCPtr(pThis->pThrottleTimerR3);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync NOREF(offDelta);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync}
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsyncint PS2MConstruct(PPS2M pThis, PPDMDEVINS pDevIns, void *pParent, int iInstance)
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync{
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync int rc;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync LogFlowFunc(("iInstance=%d\n", iInstance));
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->pParent = pParent;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /* Initialize the queues. */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->evtQ.cSize = AUX_EVT_QUEUE_SIZE;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->cmdQ.cSize = AUX_CMD_QUEUE_SIZE;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->Mouse.IBase.pfnQueryInterface = ps2mQueryInterface;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->Mouse.IPort.pfnPutEvent = ps2mPutEvent;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->Mouse.IPort.pfnPutEventAbs = ps2mPutEventAbs;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->Mouse.IPort.pfnPutEventMultiTouch = ps2mPutEventMT;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /*
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * Initialize the critical section pointer(s).
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->pCritSectR3 = pDevIns->pCritSectRoR3;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /*
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * Create the input rate throttling timer. Does not use virtual time!
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync PTMTIMER pTimer;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_REAL, ps2mThrottleTimer, pThis,
5c8b6fedb1ca14990808596a1268b9c99946c73bvboxsync TMTIMER_FLAGS_DEFAULT_CRIT_SECT, "PS2M Throttle Timer", &pTimer);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync if (RT_FAILURE(rc))
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync return rc;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->pThrottleTimerR3 = pTimer;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->pThrottleTimerR0 = TMTimerR0Ptr(pTimer);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->pThrottleTimerRC = TMTimerRCPtr(pTimer);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /*
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * Create the command delay timer.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL, ps2mDelayTimer, pThis,
5c8b6fedb1ca14990808596a1268b9c99946c73bvboxsync TMTIMER_FLAGS_DEFAULT_CRIT_SECT, "PS2M Delay Timer", &pTimer);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync if (RT_FAILURE(rc))
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync return rc;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->pDelayTimerR3 = pTimer;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->pDelayTimerR0 = TMTimerR0Ptr(pTimer);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->pDelayTimerRC = TMTimerRCPtr(pTimer);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync /*
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync * Register debugger info callbacks.
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync */
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync PDMDevHlpDBGFInfoRegister(pDevIns, "ps2m", "Display PS/2 mouse state.", ps2mInfoState);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync //@todo: Where should we do this?
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync ps2mSetDriverState(pThis, true);
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->u8State = 0;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync pThis->enmMode = AUX_MODE_STD;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync return rc;
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync}
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#endif
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync
13b491985af0d1325baad7591dcab4a9b27949cdvboxsync#endif /* !VBOX_DEVICE_STRUCT_TESTCASE */