From patchwork Mon May 7 13:01:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gonglei (Arei)\" via" X-Patchwork-Id: 10384287 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3541360159 for ; Mon, 7 May 2018 15:04:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3596128C90 for ; Mon, 7 May 2018 15:04:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2991D28C98; Mon, 7 May 2018 15:04:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CBF8028C90 for ; Mon, 7 May 2018 15:04:32 +0000 (UTC) Received: from localhost ([::1]:46682 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fFhgm-0007bS-3H for patchwork-qemu-devel@patchwork.kernel.org; Mon, 07 May 2018 11:04:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34945) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fFhfX-0006wC-55 for qemu-devel@nongnu.org; Mon, 07 May 2018 11:03:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fFhfN-0008Nj-QE for qemu-devel@nongnu.org; Mon, 07 May 2018 11:03:15 -0400 Received: from mail1.hostfission.com ([139.99.139.48]:51160) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fFhfN-0008M2-Ea for qemu-devel@nongnu.org; Mon, 07 May 2018 11:03:05 -0400 Received: from moya.office.hostfission.com (office.hostfission.com [158.140.217.90]) by mail1.hostfission.com (Postfix) with ESMTP id 8D54741ED8; Tue, 8 May 2018 01:03:03 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=hostfission.com; s=mail; t=1525705383; bh=cjoICs+ynQia+U/rnSky2kP8SjZr6USNRV62Fto7wKA=; h=From:Date:Subject:To:From; b=DNbbWS4jhxYFTu4hVwPzGtjXDiUAwWnLMC1XPWss3O6uf7tepeK0DAzeT0FQyPQrH cQKjpE2Rn+rUKp7VPD5IdP+h4kR4beuQ4TH+RP9hHVDgUkeQlgZLFsZjbOipq7mR7J zTL8suVkGIC8KDkWw9gyJcPRSp2gqjV2SJlNWss8= Received: by moya.office.hostfission.com (Postfix, from userid 0) id 7486B381924; Tue, 8 May 2018 01:03:03 +1000 (AEST) Date: Mon, 7 May 2018 23:01:46 +1000 To: qemu-devel@nongnu.org, Gerd Hoffmann Message-Id: <20180507150303.7486B381924@moya.office.hostfission.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 139.99.139.48 Subject: [Qemu-devel] [PATCHv3 1/2] ps2: Clear the PS/2 queue and obey disable X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Geoffrey McRae via Qemu-devel From: "Gonglei (Arei)\" via" Reply-To: Geoffrey McRae Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This allows guest's to correctly reinitialize and identify the mouse should the guest decide to re-scan or reset during mouse input events. When the guest sends the "Identify" command, due to the PC's hardware architecutre it is impossible to reliably determine the response from the command amongst other streaming data, such as mouse or keyboard events. Standard practice is for the guest to disable the device and then issue the identify command, so this must be obeyed. Signed-off-by: Geoffrey McRae --- hw/input/ps2.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/hw/input/ps2.c b/hw/input/ps2.c index 06f5d2ac4a..4abc8cecdd 100644 --- a/hw/input/ps2.c +++ b/hw/input/ps2.c @@ -232,6 +232,11 @@ static void ps2_keyboard_event(DeviceState *dev, QemuConsole *src, uint16_t keycode = 0; int mod; + /* do not process events while disabled to prevent stream corruption */ + if (!s->scan_enabled) { + return; + } + qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER); assert(evt->type == INPUT_EVENT_KIND_KEY); qcode = qemu_input_key_value_to_qcode(key->key); @@ -673,6 +678,11 @@ static void ps2_mouse_sync(DeviceState *dev) { PS2MouseState *s = (PS2MouseState *)dev; + /* do not sync while disabled to prevent stream corruption */ + if (!(s->mouse_status & MOUSE_STATUS_ENABLED)) { + return; + } + if (s->mouse_buttons) { qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER); } @@ -776,6 +786,7 @@ void ps2_write_mouse(void *opaque, int val) s->mouse_resolution = 2; s->mouse_status = 0; s->mouse_type = 0; + ps2_reset_queue(&s->common); ps2_queue(&s->common, AUX_ACK); ps2_queue(&s->common, 0xaa); ps2_queue(&s->common, s->mouse_type);