From patchwork Fri May 7 18:09:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Volker_R=C3=BCmelin?= X-Patchwork-Id: 1475641 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FcJpH6d6yz9sCD for ; Sat, 8 May 2021 04:27:35 +1000 (AEST) Received: from localhost ([::1]:37702 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lf5CH-0003tV-Rz for incoming@patchwork.ozlabs.org; Fri, 07 May 2021 14:27:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60650) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf51C-0000b2-3X for qemu-devel@nongnu.org; Fri, 07 May 2021 14:16:06 -0400 Received: from mailout03.t-online.de ([194.25.134.81]:40976) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf4vJ-0001Se-81 for qemu-devel@nongnu.org; Fri, 07 May 2021 14:10:02 -0400 Received: from fwd35.aul.t-online.de (fwd35.aul.t-online.de [172.20.27.145]) by mailout03.t-online.de (Postfix) with SMTP id 8AC0F45C28; Fri, 7 May 2021 20:09:57 +0200 (CEST) Received: from linpower.localnet (ZqtQHUZOYhDgo1SN7lyAkFmJ1m33jdZdpYGpxm8pmCNM12RwdKcwMb6KQllRk91Zp0@[46.86.52.8]) by fwd35.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1lf4vB-2WNKNM0; Fri, 7 May 2021 20:09:53 +0200 Received: by linpower.localnet (Postfix, from userid 1000) id 5E00B20061B; Fri, 7 May 2021 20:09:53 +0200 (CEST) From: =?utf-8?q?Volker_R=C3=BCmelin?= To: "Michael S. Tsirkin" , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v2 01/11] ps2: fix mouse stream corruption Date: Fri, 7 May 2021 20:09:43 +0200 Message-Id: <20210507180953.8530-1-vr_qemu@t-online.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 X-ID: ZqtQHUZOYhDgo1SN7lyAkFmJ1m33jdZdpYGpxm8pmCNM12RwdKcwMb6KQllRk91Zp0 X-TOI-EXPURGATEID: 150726::1620410994-0000C8B5-6F5A20C4/0/0 CLEAN NORMAL X-TOI-MSGID: 4ad93643-547d-4b5f-85fd-22d3f1e1d7df Received-SPF: none client-ip=194.25.134.81; envelope-from=volker.ruemelin@t-online.de; helo=mailout03.t-online.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Commit 7abe7eb294 "ps2: Fix mouse stream corruption due to lost data" added code to avoid mouse stream corruptions but the calculation of the needed free queue size was wrong. Fix this. To reproduce, open a text file with the vim 7.3 32 bit for DOS exe- cutable in a FreeDOS client started with -display sdl and move the mouse around for a few seconds. You will quickly see erratic mouse movements and unexpected mouse clicks. CuteMouse (ctmouse.exe) in FreeDOS doesn't try to re-sync the mouse stream. Fixes: 7abe7eb294 ("ps2: Fix mouse stream corruption due to lost data") Signed-off-by: Volker Rümelin --- hw/input/ps2.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/input/ps2.c b/hw/input/ps2.c index 72cdb80ae1..d9f79e8260 100644 --- a/hw/input/ps2.c +++ b/hw/input/ps2.c @@ -645,7 +645,8 @@ void ps2_keyboard_set_translation(void *opaque, int mode) static int ps2_mouse_send_packet(PS2MouseState *s) { - const int needed = 3 + (s->mouse_type - 2); + /* IMPS/2 and IMEX send 4 bytes, PS2 sends 3 bytes */ + const int needed = s->mouse_type ? 4 : 3; unsigned int b; int dx1, dy1, dz1; From patchwork Fri May 7 18:09:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Volker_R=C3=BCmelin?= X-Patchwork-Id: 1475639 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FcJnq2sMgz9sCD for ; Sat, 8 May 2021 04:27:10 +1000 (AEST) Received: from localhost ([::1]:36622 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lf5Bs-00039R-5e for incoming@patchwork.ozlabs.org; Fri, 07 May 2021 14:27:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60650) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf51B-0000b2-PC for qemu-devel@nongnu.org; Fri, 07 May 2021 14:16:05 -0400 Received: from mailout07.t-online.de ([194.25.134.83]:59592) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf4vJ-0001Tp-K2 for qemu-devel@nongnu.org; Fri, 07 May 2021 14:10:03 -0400 Received: from fwd31.aul.t-online.de (fwd31.aul.t-online.de [172.20.26.136]) by mailout07.t-online.de (Postfix) with SMTP id 091D55E43D; Fri, 7 May 2021 20:10:00 +0200 (CEST) Received: from linpower.localnet (r96bMOZdYh-IEO0vmUANlP1hbLhibwiRumDzALFwqHabGnBB+aKb+GkvQtFT8JNZYX@[46.86.52.8]) by fwd31.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1lf4vE-0Ii9L60; Fri, 7 May 2021 20:09:56 +0200 Received: by linpower.localnet (Postfix, from userid 1000) id 604092006E6; Fri, 7 May 2021 20:09:53 +0200 (CEST) From: =?utf-8?q?Volker_R=C3=BCmelin?= To: "Michael S. Tsirkin" , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v2 02/11] ps2: don't raise an interrupt if queue is full Date: Fri, 7 May 2021 20:09:44 +0200 Message-Id: <20210507180953.8530-2-vr_qemu@t-online.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 X-ID: r96bMOZdYh-IEO0vmUANlP1hbLhibwiRumDzALFwqHabGnBB+aKb+GkvQtFT8JNZYX X-TOI-EXPURGATEID: 150726::1620410996-000102A7-7669BDC4/0/0 CLEAN NORMAL X-TOI-MSGID: 4b1f7d64-fcd8-44c0-895a-e351692ced7a Received-SPF: none client-ip=194.25.134.83; envelope-from=volker.ruemelin@t-online.de; helo=mailout07.t-online.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" ps2_queue() behaves differently than the very similar functions ps2_queue_2() to ps2_queue_4(). The first one calls update_irq() even if the queue is full, the others don't. Change ps2_queue() to be consistent with the others. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Volker Rümelin --- hw/input/ps2.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/input/ps2.c b/hw/input/ps2.c index d9f79e8260..55a81a0c51 100644 --- a/hw/input/ps2.c +++ b/hw/input/ps2.c @@ -212,6 +212,10 @@ void ps2_raise_irq(PS2State *s) void ps2_queue(PS2State *s, int b) { + if (PS2_QUEUE_SIZE - s->queue.count < 1) { + return; + } + ps2_queue_noirq(s, b); s->update_irq(s->update_arg, 1); } From patchwork Fri May 7 18:09:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Volker_R=C3=BCmelin?= X-Patchwork-Id: 1475633 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FcJZH4wBmz9sTD for ; Sat, 8 May 2021 04:17:11 +1000 (AEST) Received: from localhost ([::1]:49196 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lf52D-0000ps-Iz for incoming@patchwork.ozlabs.org; Fri, 07 May 2021 14:17:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60650) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf51A-0000b2-1t for qemu-devel@nongnu.org; Fri, 07 May 2021 14:16:04 -0400 Received: from mailout01.t-online.de ([194.25.134.80]:60664) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf4wR-0001vg-AB for qemu-devel@nongnu.org; Fri, 07 May 2021 14:11:21 -0400 Received: from fwd02.aul.t-online.de (fwd02.aul.t-online.de [172.20.26.148]) by mailout01.t-online.de (Postfix) with SMTP id 58A9886A61; Fri, 7 May 2021 20:09:59 +0200 (CEST) Received: from linpower.localnet (JbJhWZZJwheFiZJzGrIIH89sNbkih9MPuvetny+daQIWUDxdpT24Gqy265OB++XgUT@[46.86.52.8]) by fwd02.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1lf4vH-03Mi7U0; Fri, 7 May 2021 20:09:59 +0200 Received: by linpower.localnet (Postfix, from userid 1000) id 60F562006E8; Fri, 7 May 2021 20:09:53 +0200 (CEST) From: =?utf-8?q?Volker_R=C3=BCmelin?= To: "Michael S. Tsirkin" , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v2 03/11] ps2: don't deassert irq twice if queue is empty Date: Fri, 7 May 2021 20:09:45 +0200 Message-Id: <20210507180953.8530-3-vr_qemu@t-online.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 X-ID: JbJhWZZJwheFiZJzGrIIH89sNbkih9MPuvetny+daQIWUDxdpT24Gqy265OB++XgUT X-TOI-EXPURGATEID: 150726::1620410999-0000AFC8-8AEDC4F1/0/0 CLEAN NORMAL X-TOI-MSGID: fd714e4f-92d6-41f3-bcb5-31c9b3a467e0 Received-SPF: none client-ip=194.25.134.80; envelope-from=volker.ruemelin@t-online.de; helo=mailout01.t-online.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Don't deassert the irq twice if the queue is empty. While the second deassertion doesn't do any harm, it's unnecessary. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Volker Rümelin --- hw/input/ps2.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hw/input/ps2.c b/hw/input/ps2.c index 55a81a0c51..4aee46a595 100644 --- a/hw/input/ps2.c +++ b/hw/input/ps2.c @@ -519,7 +519,9 @@ uint32_t ps2_read_data(PS2State *s) /* reading deasserts IRQ */ s->update_irq(s->update_arg, 0); /* reassert IRQs if data left */ - s->update_irq(s->update_arg, q->count != 0); + if (q->count) { + s->update_irq(s->update_arg, 1); + } } return val; } From patchwork Fri May 7 18:09:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Volker_R=C3=BCmelin?= X-Patchwork-Id: 1475634 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FcJZJ4Gf7z9sV5 for ; Sat, 8 May 2021 04:17:12 +1000 (AEST) Received: from localhost ([::1]:49244 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lf52E-0000rk-Hj for incoming@patchwork.ozlabs.org; Fri, 07 May 2021 14:17:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60652) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf519-0000b3-RC for qemu-devel@nongnu.org; Fri, 07 May 2021 14:16:03 -0400 Received: from mailout01.t-online.de ([194.25.134.80]:60680) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf4wR-0001vh-A5 for qemu-devel@nongnu.org; Fri, 07 May 2021 14:11:24 -0400 Received: from fwd38.aul.t-online.de (fwd38.aul.t-online.de [172.20.26.138]) by mailout01.t-online.de (Postfix) with SMTP id 8C40F49547; Fri, 7 May 2021 20:10:03 +0200 (CEST) Received: from linpower.localnet (TtNPuYZrohak7m9nBY2oDi+Mm17wnH2P9S+jn2vZ-SqZPZWaeWZ3+ZqmDDOpB6hw2j@[46.86.52.8]) by fwd38.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1lf4vJ-1OZvii0; Fri, 7 May 2021 20:10:01 +0200 Received: by linpower.localnet (Postfix, from userid 1000) id 635842006E9; Fri, 7 May 2021 20:09:53 +0200 (CEST) From: =?utf-8?q?Volker_R=C3=BCmelin?= To: "Michael S. Tsirkin" , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v2 04/11] pckbd: split out interrupt line changing code Date: Fri, 7 May 2021 20:09:46 +0200 Message-Id: <20210507180953.8530-4-vr_qemu@t-online.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 X-ID: TtNPuYZrohak7m9nBY2oDi+Mm17wnH2P9S+jn2vZ-SqZPZWaeWZ3+ZqmDDOpB6hw2j X-TOI-EXPURGATEID: 150726::1620411001-00010279-9409736A/0/0 CLEAN NORMAL X-TOI-MSGID: b6599d56-4174-4832-94e2-c18a56cb791c Received-SPF: none client-ip=194.25.134.80; envelope-from=volker.ruemelin@t-online.de; helo=mailout01.t-online.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Split out the interrupt line changing code from kbd_update_irq(). This is a preparation for the next patch. There is no functional change. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Volker Rümelin --- hw/input/pckbd.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/hw/input/pckbd.c b/hw/input/pckbd.c index dde85ba6c6..90b33954a8 100644 --- a/hw/input/pckbd.c +++ b/hw/input/pckbd.c @@ -148,15 +148,34 @@ typedef struct KBDState { hwaddr mask; } KBDState; -/* update irq and KBD_STAT_[MOUSE_]OBF */ /* XXX: not generating the irqs if KBD_MODE_DISABLE_KBD is set may be incorrect, but it avoids having to simulate exact delays */ -static void kbd_update_irq(KBDState *s) +static void kbd_update_irq_lines(KBDState *s) { int irq_kbd_level, irq_mouse_level; irq_kbd_level = 0; irq_mouse_level = 0; + + if (s->status & KBD_STAT_OBF) { + if (s->status & KBD_STAT_MOUSE_OBF) { + if (s->mode & KBD_MODE_MOUSE_INT) { + irq_mouse_level = 1; + } + } else { + if ((s->mode & KBD_MODE_KBD_INT) && + !(s->mode & KBD_MODE_DISABLE_KBD)) { + irq_kbd_level = 1; + } + } + } + qemu_set_irq(s->irq_kbd, irq_kbd_level); + qemu_set_irq(s->irq_mouse, irq_mouse_level); +} + +/* update irq and KBD_STAT_[MOUSE_]OBF */ +static void kbd_update_irq(KBDState *s) +{ s->status &= ~(KBD_STAT_OBF | KBD_STAT_MOUSE_OBF); s->outport &= ~(KBD_OUT_OBF | KBD_OUT_MOUSE_OBF); if (s->pending) { @@ -166,16 +185,9 @@ static void kbd_update_irq(KBDState *s) if (s->pending == KBD_PENDING_AUX) { s->status |= KBD_STAT_MOUSE_OBF; s->outport |= KBD_OUT_MOUSE_OBF; - if (s->mode & KBD_MODE_MOUSE_INT) - irq_mouse_level = 1; - } else { - if ((s->mode & KBD_MODE_KBD_INT) && - !(s->mode & KBD_MODE_DISABLE_KBD)) - irq_kbd_level = 1; } } - qemu_set_irq(s->irq_kbd, irq_kbd_level); - qemu_set_irq(s->irq_mouse, irq_mouse_level); + kbd_update_irq_lines(s); } static void kbd_update_kbd_irq(void *opaque, int level) From patchwork Fri May 7 18:09:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Volker_R=C3=BCmelin?= X-Patchwork-Id: 1475644 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FcJy71RFrz9sW4 for ; Sat, 8 May 2021 04:34:21 +1000 (AEST) Received: from localhost ([::1]:49594 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lf5Io-0003i6-4O for incoming@patchwork.ozlabs.org; Fri, 07 May 2021 14:34:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60650) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf51B-0000b2-Ed for qemu-devel@nongnu.org; Fri, 07 May 2021 14:16:05 -0400 Received: from mailout12.t-online.de ([194.25.134.22]:53506) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf4vT-0001YP-SP for qemu-devel@nongnu.org; Fri, 07 May 2021 14:10:25 -0400 Received: from fwd01.aul.t-online.de (fwd01.aul.t-online.de [172.20.27.147]) by mailout12.t-online.de (Postfix) with SMTP id 75EAC484F1; Fri, 7 May 2021 20:10:09 +0200 (CEST) Received: from linpower.localnet (VT2FCZZvZhHilWwjTFIpKUxq4ft7s5nCgc06t6cP9Cj5eO2QnObgQyiSHNixlKmgqo@[46.86.52.8]) by fwd01.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1lf4vM-0G55Ky0; Fri, 7 May 2021 20:10:04 +0200 Received: by linpower.localnet (Postfix, from userid 1000) id 65AC72006EB; Fri, 7 May 2021 20:09:53 +0200 (CEST) From: =?utf-8?q?Volker_R=C3=BCmelin?= To: "Michael S. Tsirkin" , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v2 05/11] pckbd: don't update OBF flags if KBD_STAT_OBF is set Date: Fri, 7 May 2021 20:09:47 +0200 Message-Id: <20210507180953.8530-5-vr_qemu@t-online.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 X-ID: VT2FCZZvZhHilWwjTFIpKUxq4ft7s5nCgc06t6cP9Cj5eO2QnObgQyiSHNixlKmgqo X-TOI-EXPURGATEID: 150726::1620411004-0000B607-EEE96906/0/0 CLEAN NORMAL X-TOI-MSGID: 0796e5a0-2886-46d6-97d2-9b990960546c Received-SPF: none client-ip=194.25.134.22; envelope-from=volker.ruemelin@t-online.de; helo=mailout12.t-online.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Don't update the OBF flags in the status register and the cor- responding IRQ lines if KBD_STAT_OBF is set. Otherwise this may change the PS/2 event type. If the guest ISR was already scheduled, the changed event type will be rather surprising for the guest. This fixes a mouse event stream corruption. To reproduce the problem start a FreeDOS 1.2 guest with -machine pc,accel=kvm and -display gtk. The KVM in-kernel irqchip has to be enabled. Now open a text file with edit.exe in the guest and hold down the cursor right key and at the same time move the mouse around. You will quickly notice erratic mouse movements and unexpected mouse clicks. A trace file shows the mouse event stream corruption. Guest rip 0xce93 (f000:ce93) is the in al,0x60 instruction in the seabios mouse ISR, guest rip 0xceca (f000:ceca) is the in al,0x60 instruction in the seabios keyboard ISR. qemu-system-x86-5659 [007] .... 280.971116: tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1 # gtk queues a mouse event qemu-system-x86-5665 [000] .... 280.971121: kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd qemu-system-x86-5665 [000] d..1 280.971122: kvm_entry: vcpu 0, rip 0x22da qemu-system-x86-5665 [000] .... 280.971123: kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd qemu-system-x86-5665 [000] d..1 280.971124: kvm_entry: vcpu 0, rip 0x22da qemu-system-x86-5665 [000] .... 280.971126: kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0 qemu-system-x86-5665 [000] .... 280.971176: tracing_mark_write: pckbd_kbd_read_status 0x3d # KBD_STAT_OBF and KBD_STAT_MOUSE_OBF set, the mouse ISR will # read data from the PS/2 controller. qemu-system-x86-5665 [000] d..1 280.971180: kvm_entry: vcpu 0, rip 0x110c8d qemu-system-x86-5665 [000] .... 280.971191: kvm_exit: reason EXTERNAL_INTERRUPT rip 0x110c8d info 0 800000f6 qemu-system-x86-5665 [000] d..1 280.971191: kvm_entry: vcpu 0, rip 0x110c8d qemu-system-x86-5665 [000] .... 280.971193: kvm_exit: reason IO_INSTRUCTION rip 0xce93 info 600048 0 # the mouse ISR wants to read data from the PS/2 controller qemu-system-x86-5659 [007] .... 280.971231: tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0 qemu-system-x86-5659 [007] .... 280.971238: tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0 # gtk queues a keyboard event 0xe0 0x4d (key right) qemu-system-x86-5665 [000] .... 280.971257: tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1 qemu-system-x86-5665 [000] .... 280.971262: tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0 # ps2_read_data() deasserts and reasserts the keyboard IRQ qemu-system-x86-5665 [000] .... 280.971266: tracing_mark_write: pckbd_kbd_read_data 0xe0 kbd # -> the mouse ISR receives keyboard data qemu-system-x86-5665 [000] d..1 280.971268: kvm_entry: vcpu 0, rip 0xce95 qemu-system-x86-5665 [000] .... 280.971269: kvm_exit: reason IO_INSTRUCTION rip 0xe828 info a00040 0 qemu-system-x86-5665 [000] .... 280.971270: kvm_ack_irq: irqchip PIC slave pin 12 qemu-system-x86-5665 [000] d..1 280.971270: kvm_entry: vcpu 0, rip 0xe82a qemu-system-x86-5665 [000] .... 280.971271: kvm_exit: reason IO_INSTRUCTION rip 0xe82a info 200040 0 qemu-system-x86-5665 [000] .... 280.971271: kvm_ack_irq: irqchip PIC master pin 2 qemu-system-x86-5665 [000] d..1 280.971271: kvm_entry: vcpu 0, rip 0xe82c qemu-system-x86-5665 [000] .... 280.971272: kvm_exit: reason PENDING_INTERRUPT rip 0x22da info 0 0 qemu-system-x86-5665 [000] d..1 280.971273: kvm_entry: vcpu 0, rip 0x22da qemu-system-x86-5665 [000] .... 280.971274: kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0 qemu-system-x86-5665 [000] .... 280.971275: tracing_mark_write: pckbd_kbd_read_status 0x1d qemu-system-x86-5665 [000] d..1 280.971276: kvm_entry: vcpu 0, rip 0x110c8d qemu-system-x86-5665 [000] .... 280.971277: kvm_exit: reason IO_INSTRUCTION rip 0xceca info 600048 0 # the keyboard ISR wants to read data from the PS/2 controller qemu-system-x86-5665 [000] .... 280.971279: tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1 qemu-system-x86-5665 [000] .... 280.971282: tracing_mark_write: pckbd_kbd_read_data 0x4d kbd # the keyboard ISR receives the second byte of the keyboard event Signed-off-by: Volker Rümelin --- hw/input/pckbd.c | 91 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 68 insertions(+), 23 deletions(-) diff --git a/hw/input/pckbd.c b/hw/input/pckbd.c index 90b33954a8..8336f4e4b3 100644 --- a/hw/input/pckbd.c +++ b/hw/input/pckbd.c @@ -139,6 +139,7 @@ typedef struct KBDState { bool outport_present; /* Bitmask of devices with data available. */ uint8_t pending; + uint8_t obdata; void *kbd; void *mouse; @@ -173,6 +174,13 @@ static void kbd_update_irq_lines(KBDState *s) qemu_set_irq(s->irq_mouse, irq_mouse_level); } +static void kbd_deassert_irq(KBDState *s) +{ + s->status &= ~(KBD_STAT_OBF | KBD_STAT_MOUSE_OBF); + s->outport &= ~(KBD_OUT_OBF | KBD_OUT_MOUSE_OBF); + kbd_update_irq_lines(s); +} + /* update irq and KBD_STAT_[MOUSE_]OBF */ static void kbd_update_irq(KBDState *s) { @@ -181,7 +189,6 @@ static void kbd_update_irq(KBDState *s) if (s->pending) { s->status |= KBD_STAT_OBF; s->outport |= KBD_OUT_OBF; - /* kbd data takes priority over aux data. */ if (s->pending == KBD_PENDING_AUX) { s->status |= KBD_STAT_MOUSE_OBF; s->outport |= KBD_OUT_MOUSE_OBF; @@ -190,26 +197,42 @@ static void kbd_update_irq(KBDState *s) kbd_update_irq_lines(s); } +static void kbd_safe_update_irq(KBDState *s) +{ + /* + * with KBD_STAT_OBF set, a call to kbd_read_data() will eventually call + * kbd_update_irq() + */ + if (s->status & KBD_STAT_OBF) { + return; + } + if (s->pending) { + kbd_update_irq(s); + } +} + static void kbd_update_kbd_irq(void *opaque, int level) { - KBDState *s = (KBDState *)opaque; + KBDState *s = opaque; - if (level) + if (level) { s->pending |= KBD_PENDING_KBD; - else + } else { s->pending &= ~KBD_PENDING_KBD; - kbd_update_irq(s); + } + kbd_safe_update_irq(s); } static void kbd_update_aux_irq(void *opaque, int level) { - KBDState *s = (KBDState *)opaque; + KBDState *s = opaque; - if (level) + if (level) { s->pending |= KBD_PENDING_AUX; - else + } else { s->pending &= ~KBD_PENDING_AUX; - kbd_update_irq(s); + } + kbd_safe_update_irq(s); } static uint64_t kbd_read_status(void *opaque, hwaddr addr, @@ -290,11 +313,10 @@ static void kbd_write_command(void *opaque, hwaddr addr, break; case KBD_CCMD_KBD_DISABLE: s->mode |= KBD_MODE_DISABLE_KBD; - kbd_update_irq(s); break; case KBD_CCMD_KBD_ENABLE: s->mode &= ~KBD_MODE_DISABLE_KBD; - kbd_update_irq(s); + kbd_safe_update_irq(s); break; case KBD_CCMD_READ_INPORT: kbd_queue(s, 0x80, 0); @@ -327,15 +349,19 @@ static uint64_t kbd_read_data(void *opaque, hwaddr addr, unsigned size) { KBDState *s = opaque; - uint32_t val; + uint8_t status = s->status; - if (s->pending == KBD_PENDING_AUX) - val = ps2_read_data(s->mouse); - else - val = ps2_read_data(s->kbd); + if (status & KBD_STAT_OBF) { + kbd_deassert_irq(s); + if (status & KBD_STAT_MOUSE_OBF) { + s->obdata = ps2_read_data(s->mouse); + } else { + s->obdata = ps2_read_data(s->kbd); + } + } - trace_pckbd_kbd_read_data(val); - return val; + trace_pckbd_kbd_read_data(s->obdata); + return s->obdata; } static void kbd_write_data(void *opaque, hwaddr addr, @@ -352,8 +378,16 @@ static void kbd_write_data(void *opaque, hwaddr addr, case KBD_CCMD_WRITE_MODE: s->mode = val; ps2_keyboard_set_translation(s->kbd, (s->mode & KBD_MODE_KCC) != 0); - /* ??? */ - kbd_update_irq(s); + /* + * a write to the mode byte interrupt enable flags directly updates + * the irq lines + */ + kbd_update_irq_lines(s); + /* + * a write to the mode byte disable interface flags may raise + * an irq if there is pending data in the PS/2 queues. + */ + kbd_safe_update_irq(s); break; case KBD_CCMD_WRITE_OBUF: kbd_queue(s, val, 0); @@ -381,6 +415,8 @@ static void kbd_reset(void *opaque) s->status = KBD_STAT_CMD | KBD_STAT_UNLOCKED; s->outport = KBD_OUT_RESET | KBD_OUT_A20 | KBD_OUT_ONES; s->outport_present = false; + s->pending = 0; + kbd_deassert_irq(s); } static uint8_t kbd_outport_default(KBDState *s) @@ -427,7 +463,7 @@ static int kbd_post_load(void *opaque, int version_id) static const VMStateDescription vmstate_kbd = { .name = "pckbd", - .version_id = 3, + .version_id = 4, .minimum_version_id = 3, .post_load = kbd_post_load, .fields = (VMStateField[]) { @@ -435,6 +471,7 @@ static const VMStateDescription vmstate_kbd = { VMSTATE_UINT8(status, KBDState), VMSTATE_UINT8(mode, KBDState), VMSTATE_UINT8(pending, KBDState), + VMSTATE_UINT8_V(obdata, KBDState, 4), VMSTATE_END_OF_LIST() }, .subsections = (const VMStateDescription*[]) { @@ -512,12 +549,20 @@ void i8042_setup_a20_line(ISADevice *dev, qemu_irq a20_out) qdev_connect_gpio_out_named(DEVICE(dev), I8042_A20_LINE, 0, a20_out); } +static bool vmstate_version_id_3(void *opaque, int version_id) +{ + return version_id == 3; +} + static const VMStateDescription vmstate_kbd_isa = { .name = "pckbd", - .version_id = 3, + .version_id = 4, .minimum_version_id = 3, .fields = (VMStateField[]) { - VMSTATE_STRUCT(kbd, ISAKBDState, 0, vmstate_kbd, KBDState), + VMSTATE_VSTRUCT_TEST(kbd, ISAKBDState, vmstate_version_id_3, + 3, vmstate_kbd, KBDState, 3), + VMSTATE_VSTRUCT_TEST(kbd, ISAKBDState, NULL, + 4, vmstate_kbd, KBDState, 4), VMSTATE_END_OF_LIST() } }; From patchwork Fri May 7 18:09:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Volker_R=C3=BCmelin?= X-Patchwork-Id: 1475645 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FcJzy1dfWz9sW4 for ; Sat, 8 May 2021 04:35:58 +1000 (AEST) Received: from localhost ([::1]:53446 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lf5KN-0006G3-7x for incoming@patchwork.ozlabs.org; Fri, 07 May 2021 14:35:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60652) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf51B-0000b3-Jx for qemu-devel@nongnu.org; Fri, 07 May 2021 14:16:05 -0400 Received: from mailout12.t-online.de ([194.25.134.22]:53494) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf4vS-0001Y0-8m for qemu-devel@nongnu.org; Fri, 07 May 2021 14:10:13 -0400 Received: from fwd27.aul.t-online.de (fwd27.aul.t-online.de [172.20.26.132]) by mailout12.t-online.de (Postfix) with SMTP id 4EF33484EC; Fri, 7 May 2021 20:10:08 +0200 (CEST) Received: from linpower.localnet (TtNPusZYZhYsOulvooqdOC1u32tlJeoQ3bk0qi4ffZGRc-th7P1ptjm+jFaPiWJQMk@[46.86.52.8]) by fwd27.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1lf4vP-0NH6fI0; Fri, 7 May 2021 20:10:07 +0200 Received: by linpower.localnet (Postfix, from userid 1000) id 67E582006ED; Fri, 7 May 2021 20:09:53 +0200 (CEST) From: =?utf-8?q?Volker_R=C3=BCmelin?= To: "Michael S. Tsirkin" , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v2 06/11] pckbd: PS/2 keyboard throttle Date: Fri, 7 May 2021 20:09:48 +0200 Message-Id: <20210507180953.8530-6-vr_qemu@t-online.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 X-ID: TtNPusZYZhYsOulvooqdOC1u32tlJeoQ3bk0qi4ffZGRc-th7P1ptjm+jFaPiWJQMk X-TOI-EXPURGATEID: 150726::1620411007-000107BB-6030C77B/0/0 CLEAN NORMAL X-TOI-MSGID: 6b46a844-7445-41d7-a8ed-1cf5c9021ba4 Received-SPF: none client-ip=194.25.134.22; envelope-from=volker.ruemelin@t-online.de; helo=mailout12.t-online.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Limit the keyboard data rate to the serial link speed. Some old DOS software relies on being able to read an incoming scan-code more than once. After reading keyboard data from the i8042 controller, the guest software has 1ms to read the same data again. Use -global i8042.kbd-throttle=on to enable this feature. To see how this patch works, start a FreeDOS 1.2 guest with the qemu option -global i8042.kbd-throttle=on and open a text file with the vim 7.3 32 bit for DOS executable. Then use the cursor keys (not the cursor keys on the numeric keypad) to move through the text. Without the kbd-throttle option enabled each keystroke will move the cursor two positions. Buglink: https://bugs.launchpad.net/bugs/1895363 Buglink: https://bugs.launchpad.net/bugs/1897568 Signed-off-by: Volker Rümelin --- hw/input/pckbd.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/hw/input/pckbd.c b/hw/input/pckbd.c index 8336f4e4b3..f45aebb6b8 100644 --- a/hw/input/pckbd.c +++ b/hw/input/pckbd.c @@ -24,12 +24,14 @@ #include "qemu/osdep.h" #include "qemu/log.h" +#include "qemu/timer.h" #include "hw/isa/isa.h" #include "migration/vmstate.h" #include "hw/acpi/aml-build.h" #include "hw/input/ps2.h" #include "hw/irq.h" #include "hw/input/i8042.h" +#include "hw/qdev-properties.h" #include "sysemu/reset.h" #include "sysemu/runstate.h" @@ -131,17 +133,21 @@ #define KBD_PENDING_KBD 1 #define KBD_PENDING_AUX 2 +#define KBD_MIGR_TIMER_PENDING 0x1 + typedef struct KBDState { uint8_t write_cmd; /* if non zero, write data to port 60 is expected */ uint8_t status; uint8_t mode; uint8_t outport; + uint32_t migration_flags; bool outport_present; /* Bitmask of devices with data available. */ uint8_t pending; uint8_t obdata; void *kbd; void *mouse; + QEMUTimer *throttle_timer; qemu_irq irq_kbd; qemu_irq irq_mouse; @@ -206,6 +212,10 @@ static void kbd_safe_update_irq(KBDState *s) if (s->status & KBD_STAT_OBF) { return; } + /* the throttle timer is pending and will call kbd_update_irq() */ + if (s->throttle_timer && timer_pending(s->throttle_timer)) { + return; + } if (s->pending) { kbd_update_irq(s); } @@ -235,6 +245,18 @@ static void kbd_update_aux_irq(void *opaque, int level) kbd_safe_update_irq(s); } +static void kbd_throttle_timeout(void *opaque) +{ + KBDState *s = opaque; + + if (s->status & KBD_STAT_OBF) { + return; + } + if (s->pending) { + kbd_update_irq(s); + } +} + static uint64_t kbd_read_status(void *opaque, hwaddr addr, unsigned size) { @@ -356,6 +378,10 @@ static uint64_t kbd_read_data(void *opaque, hwaddr addr, if (status & KBD_STAT_MOUSE_OBF) { s->obdata = ps2_read_data(s->mouse); } else { + if (s->throttle_timer) { + timer_mod(s->throttle_timer, + qemu_clock_get_us(QEMU_CLOCK_VIRTUAL) + 1000); + } s->obdata = ps2_read_data(s->kbd); } } @@ -417,6 +443,9 @@ static void kbd_reset(void *opaque) s->outport_present = false; s->pending = 0; kbd_deassert_irq(s); + if (s->throttle_timer) { + timer_del(s->throttle_timer); + } } static uint8_t kbd_outport_default(KBDState *s) @@ -451,6 +480,18 @@ static const VMStateDescription vmstate_kbd_outport = { } }; +static int kbd_pre_save(void *opaque) +{ + KBDState *s = opaque; + + s->migration_flags = 0; + if (s->throttle_timer && timer_pending(s->throttle_timer)) { + s->migration_flags |= KBD_MIGR_TIMER_PENDING; + } + + return 0; +} + static int kbd_post_load(void *opaque, int version_id) { KBDState *s = opaque; @@ -458,6 +499,9 @@ static int kbd_post_load(void *opaque, int version_id) s->outport = kbd_outport_default(s); } s->outport_present = false; + if (s->migration_flags & KBD_MIGR_TIMER_PENDING) { + kbd_throttle_timeout(s); + } return 0; } @@ -465,12 +509,14 @@ static const VMStateDescription vmstate_kbd = { .name = "pckbd", .version_id = 4, .minimum_version_id = 3, + .pre_save = kbd_pre_save, .post_load = kbd_post_load, .fields = (VMStateField[]) { VMSTATE_UINT8(write_cmd, KBDState), VMSTATE_UINT8(status, KBDState), VMSTATE_UINT8(mode, KBDState), VMSTATE_UINT8(pending, KBDState), + VMSTATE_UINT32_V(migration_flags, KBDState, 4), VMSTATE_UINT8_V(obdata, KBDState, 4), VMSTATE_END_OF_LIST() }, @@ -534,6 +580,7 @@ struct ISAKBDState { ISADevice parent_obj; KBDState kbd; + bool kbd_throttle; MemoryRegion io[2]; }; @@ -614,6 +661,10 @@ static void i8042_realizefn(DeviceState *dev, Error **errp) s->kbd = ps2_kbd_init(kbd_update_kbd_irq, s); s->mouse = ps2_mouse_init(kbd_update_aux_irq, s); + if (isa_s->kbd_throttle) { + s->throttle_timer = timer_new_us(QEMU_CLOCK_VIRTUAL, + kbd_throttle_timeout, s); + } qemu_register_reset(kbd_reset, s); } @@ -645,11 +696,17 @@ static void i8042_build_aml(ISADevice *isadev, Aml *scope) aml_append(scope, mou); } +static Property i8042_properties[] = { + DEFINE_PROP_BOOL("kbd-throttle", ISAKBDState, kbd_throttle, false), + DEFINE_PROP_END_OF_LIST(), +}; + static void i8042_class_initfn(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); ISADeviceClass *isa = ISA_DEVICE_CLASS(klass); + device_class_set_props(dc, i8042_properties); dc->realize = i8042_realizefn; dc->vmsd = &vmstate_kbd_isa; isa->build_aml = i8042_build_aml; From patchwork Fri May 7 18:09:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Volker_R=C3=BCmelin?= X-Patchwork-Id: 1475637 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FcJjl5hDDz9sXV for ; Sat, 8 May 2021 04:23:39 +1000 (AEST) Received: from localhost ([::1]:57842 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lf58N-0006mq-6E for incoming@patchwork.ozlabs.org; Fri, 07 May 2021 14:23:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60650) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf51A-0000b2-Sa for qemu-devel@nongnu.org; Fri, 07 May 2021 14:16:04 -0400 Received: from mailout08.t-online.de ([194.25.134.20]:43172) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf4ve-0001bG-FP for qemu-devel@nongnu.org; Fri, 07 May 2021 14:10:34 -0400 Received: from fwd35.aul.t-online.de (fwd35.aul.t-online.de [172.20.27.145]) by mailout08.t-online.de (Postfix) with SMTP id A2BEFE598; Fri, 7 May 2021 20:10:17 +0200 (CEST) Received: from linpower.localnet (rxpXzZZCgh4Cr6x+9KxGLRocEsDq6QEojo0JcfefFzVeo3xf8WiiNKId4DSzj1mQEb@[46.86.52.8]) by fwd35.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1lf4vR-332qcy0; Fri, 7 May 2021 20:10:09 +0200 Received: by linpower.localnet (Postfix, from userid 1000) id 6A1062006F0; Fri, 7 May 2021 20:09:53 +0200 (CEST) From: =?utf-8?q?Volker_R=C3=BCmelin?= To: "Michael S. Tsirkin" , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v2 07/11] pckbd: add state variable for interrupt source Date: Fri, 7 May 2021 20:09:49 +0200 Message-Id: <20210507180953.8530-7-vr_qemu@t-online.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 X-ID: rxpXzZZCgh4Cr6x+9KxGLRocEsDq6QEojo0JcfefFzVeo3xf8WiiNKId4DSzj1mQEb X-TOI-EXPURGATEID: 150726::1620411009-0000C8B5-77E6D4F6/0/0 CLEAN NORMAL X-TOI-MSGID: 61138439-5705-4c5e-b1b6-63b536afa437 Received-SPF: none client-ip=194.25.134.20; envelope-from=volker.ruemelin@t-online.de; helo=mailout08.t-online.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Currently there is only one flag to distinguish between two interrupt sources and there are no available flags for more sources. Add an internal state variable to store the interrupt source. The next patch will introduce an additional interrupt source. There is no functional change. Signed-off-by: Volker Rümelin --- hw/input/pckbd.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/hw/input/pckbd.c b/hw/input/pckbd.c index f45aebb6b8..f8f3859b17 100644 --- a/hw/input/pckbd.c +++ b/hw/input/pckbd.c @@ -135,12 +135,16 @@ #define KBD_MIGR_TIMER_PENDING 0x1 +#define KBD_OBSRC_KBD 0x01 +#define KBD_OBSRC_MOUSE 0x02 + typedef struct KBDState { uint8_t write_cmd; /* if non zero, write data to port 60 is expected */ uint8_t status; uint8_t mode; uint8_t outport; uint32_t migration_flags; + uint32_t obsrc; bool outport_present; /* Bitmask of devices with data available. */ uint8_t pending; @@ -198,6 +202,9 @@ static void kbd_update_irq(KBDState *s) if (s->pending == KBD_PENDING_AUX) { s->status |= KBD_STAT_MOUSE_OBF; s->outport |= KBD_OUT_MOUSE_OBF; + s->obsrc = KBD_OBSRC_MOUSE; + } else { + s->obsrc = KBD_OBSRC_KBD; } } kbd_update_irq_lines(s); @@ -371,18 +378,17 @@ static uint64_t kbd_read_data(void *opaque, hwaddr addr, unsigned size) { KBDState *s = opaque; - uint8_t status = s->status; - if (status & KBD_STAT_OBF) { + if (s->status & KBD_STAT_OBF) { kbd_deassert_irq(s); - if (status & KBD_STAT_MOUSE_OBF) { - s->obdata = ps2_read_data(s->mouse); - } else { + if (s->obsrc & KBD_OBSRC_KBD) { if (s->throttle_timer) { timer_mod(s->throttle_timer, qemu_clock_get_us(QEMU_CLOCK_VIRTUAL) + 1000); } s->obdata = ps2_read_data(s->kbd); + } else if (s->obsrc & KBD_OBSRC_MOUSE) { + s->obdata = ps2_read_data(s->mouse); } } @@ -499,6 +505,11 @@ static int kbd_post_load(void *opaque, int version_id) s->outport = kbd_outport_default(s); } s->outport_present = false; + if (version_id < 4) { + s->obsrc = s->status & KBD_STAT_OBF ? + (s->status & KBD_STAT_MOUSE_OBF ? KBD_OBSRC_MOUSE : KBD_OBSRC_KBD) : + 0; + } if (s->migration_flags & KBD_MIGR_TIMER_PENDING) { kbd_throttle_timeout(s); } @@ -517,6 +528,7 @@ static const VMStateDescription vmstate_kbd = { VMSTATE_UINT8(mode, KBDState), VMSTATE_UINT8(pending, KBDState), VMSTATE_UINT32_V(migration_flags, KBDState, 4), + VMSTATE_UINT32_V(obsrc, KBDState, 4), VMSTATE_UINT8_V(obdata, KBDState, 4), VMSTATE_END_OF_LIST() }, From patchwork Fri May 7 18:09:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Volker_R=C3=BCmelin?= X-Patchwork-Id: 1475638 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FcJkH6ybPz9sXL for ; Sat, 8 May 2021 04:24:07 +1000 (AEST) Received: from localhost ([::1]:59058 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lf58v-0007bc-VI for incoming@patchwork.ozlabs.org; Fri, 07 May 2021 14:24:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60650) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf51B-0000b2-56 for qemu-devel@nongnu.org; Fri, 07 May 2021 14:16:05 -0400 Received: from mailout10.t-online.de ([194.25.134.21]:37692) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf4va-0001b9-T1 for qemu-devel@nongnu.org; Fri, 07 May 2021 14:10:32 -0400 Received: from fwd17.aul.t-online.de (fwd17.aul.t-online.de [172.20.27.64]) by mailout10.t-online.de (Postfix) with SMTP id C10CF6FBBF; Fri, 7 May 2021 20:10:15 +0200 (CEST) Received: from linpower.localnet (ZZ+97UZFrhEvqQlKJWCFPOF+Wq-Os9dIBVPyAg8YDVf9klOvkDJWoUwXBjujIZLQuS@[46.86.52.8]) by fwd17.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1lf4vU-0cPtdQ0; Fri, 7 May 2021 20:10:12 +0200 Received: by linpower.localnet (Postfix, from userid 1000) id 6C3A12006F8; Fri, 7 May 2021 20:09:53 +0200 (CEST) From: =?utf-8?q?Volker_R=C3=BCmelin?= To: "Michael S. Tsirkin" , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v2 08/11] pckbd: add controller response queue Date: Fri, 7 May 2021 20:09:50 +0200 Message-Id: <20210507180953.8530-8-vr_qemu@t-online.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 X-ID: ZZ+97UZFrhEvqQlKJWCFPOF+Wq-Os9dIBVPyAg8YDVf9klOvkDJWoUwXBjujIZLQuS X-TOI-EXPURGATEID: 150726::1620411012-0000EBC3-3EADA505/0/0 CLEAN NORMAL X-TOI-MSGID: 1c654dd2-88c9-407a-8e0d-f2e4e9c4a600 Received-SPF: none client-ip=194.25.134.21; envelope-from=volker.ruemelin@t-online.de; helo=mailout10.t-online.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Add a separate queue for PS/2 controller responses. The responses no longer get queued in the keyboard or mouse queues. The advantage of this can be seen after the next two patches, where the guest can disable the PS/2 communication with keyboard and mouse and still talk to the PS/2 controller. Signed-off-by: Volker Rümelin --- hw/input/pckbd.c | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/hw/input/pckbd.c b/hw/input/pckbd.c index f8f3859b17..3c41c11841 100644 --- a/hw/input/pckbd.c +++ b/hw/input/pckbd.c @@ -132,11 +132,14 @@ #define KBD_PENDING_KBD 1 #define KBD_PENDING_AUX 2 +#define KBD_PENDING_CTRL_KBD 0x04 +#define KBD_PENDING_CTRL_AUX 0x08 #define KBD_MIGR_TIMER_PENDING 0x1 #define KBD_OBSRC_KBD 0x01 #define KBD_OBSRC_MOUSE 0x02 +#define KBD_OBSRC_CTRL 0x04 typedef struct KBDState { uint8_t write_cmd; /* if non zero, write data to port 60 is expected */ @@ -149,6 +152,7 @@ typedef struct KBDState { /* Bitmask of devices with data available. */ uint8_t pending; uint8_t obdata; + uint8_t cbdata; void *kbd; void *mouse; QEMUTimer *throttle_timer; @@ -199,12 +203,18 @@ static void kbd_update_irq(KBDState *s) if (s->pending) { s->status |= KBD_STAT_OBF; s->outport |= KBD_OUT_OBF; - if (s->pending == KBD_PENDING_AUX) { + if (s->pending & KBD_PENDING_CTRL_KBD) { + s->obsrc = KBD_OBSRC_CTRL; + } else if (s->pending & KBD_PENDING_CTRL_AUX) { s->status |= KBD_STAT_MOUSE_OBF; s->outport |= KBD_OUT_MOUSE_OBF; - s->obsrc = KBD_OBSRC_MOUSE; - } else { + s->obsrc = KBD_OBSRC_CTRL; + } else if (s->pending & KBD_PENDING_KBD) { s->obsrc = KBD_OBSRC_KBD; + } else { + s->status |= KBD_STAT_MOUSE_OBF; + s->outport |= KBD_OUT_MOUSE_OBF; + s->obsrc = KBD_OBSRC_MOUSE; } } kbd_update_irq_lines(s); @@ -276,10 +286,21 @@ static uint64_t kbd_read_status(void *opaque, hwaddr addr, static void kbd_queue(KBDState *s, int b, int aux) { - if (aux) - ps2_queue(s->mouse, b); - else - ps2_queue(s->kbd, b); + s->cbdata = b; + s->pending &= ~KBD_PENDING_CTRL_KBD & ~KBD_PENDING_CTRL_AUX; + s->pending |= aux ? KBD_PENDING_CTRL_AUX : KBD_PENDING_CTRL_KBD; + kbd_safe_update_irq(s); +} + +static uint8_t kbd_dequeue(KBDState *s) +{ + uint8_t b = s->cbdata; + + s->pending &= ~KBD_PENDING_CTRL_KBD & ~KBD_PENDING_CTRL_AUX; + if (s->pending) { + kbd_update_irq(s); + } + return b; } static void outport_write(KBDState *s, uint32_t val) @@ -389,6 +410,8 @@ static uint64_t kbd_read_data(void *opaque, hwaddr addr, s->obdata = ps2_read_data(s->kbd); } else if (s->obsrc & KBD_OBSRC_MOUSE) { s->obdata = ps2_read_data(s->mouse); + } else if (s->obsrc & KBD_OBSRC_CTRL) { + s->obdata = kbd_dequeue(s); } } @@ -530,6 +553,7 @@ static const VMStateDescription vmstate_kbd = { VMSTATE_UINT32_V(migration_flags, KBDState, 4), VMSTATE_UINT32_V(obsrc, KBDState, 4), VMSTATE_UINT8_V(obdata, KBDState, 4), + VMSTATE_UINT8_V(cbdata, KBDState, 4), VMSTATE_END_OF_LIST() }, .subsections = (const VMStateDescription*[]) { From patchwork Fri May 7 18:09:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Volker_R=C3=BCmelin?= X-Patchwork-Id: 1475642 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FcJsZ3pL6z9sXV for ; Sat, 8 May 2021 04:30:26 +1000 (AEST) Received: from localhost ([::1]:43154 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lf5F2-0007bv-HU for incoming@patchwork.ozlabs.org; Fri, 07 May 2021 14:30:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60652) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf51B-0000b3-AJ for qemu-devel@nongnu.org; Fri, 07 May 2021 14:16:05 -0400 Received: from mailout10.t-online.de ([194.25.134.21]:37702) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf4va-0001bC-T5 for qemu-devel@nongnu.org; Fri, 07 May 2021 14:10:27 -0400 Received: from fwd05.aul.t-online.de (fwd05.aul.t-online.de [172.20.27.149]) by mailout10.t-online.de (Postfix) with SMTP id 79DE56FBBE; Fri, 7 May 2021 20:10:17 +0200 (CEST) Received: from linpower.localnet (TvEx-EZAZh61BG8i-ic8AOlEPGq3zrZM6keVvH9fhLdU3W+Z7yF75d0ioYhOJeCQex@[46.86.52.8]) by fwd05.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1lf4vX-11PhHE0; Fri, 7 May 2021 20:10:15 +0200 Received: by linpower.localnet (Postfix, from userid 1000) id 6E5772006FD; Fri, 7 May 2021 20:09:53 +0200 (CEST) From: =?utf-8?q?Volker_R=C3=BCmelin?= To: "Michael S. Tsirkin" , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v2 09/11] pckbd: add function kbd_pending() Date: Fri, 7 May 2021 20:09:51 +0200 Message-Id: <20210507180953.8530-9-vr_qemu@t-online.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 X-ID: TvEx-EZAZh61BG8i-ic8AOlEPGq3zrZM6keVvH9fhLdU3W+Z7yF75d0ioYhOJeCQex X-TOI-EXPURGATEID: 150726::1620411015-00016BF9-09703825/0/0 CLEAN NORMAL X-TOI-MSGID: 2fa47cfa-c056-48cb-bd4f-e304887a86ce Received-SPF: none client-ip=194.25.134.21; envelope-from=volker.ruemelin@t-online.de; helo=mailout10.t-online.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Replace reads of the variable s->pending with a call to a new function kbd_pending() to ease the review of the next patch. There is no functional change. Signed-off-by: Volker Rümelin Reviewed-by: Philippe Mathieu-Daudé --- hw/input/pckbd.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/hw/input/pckbd.c b/hw/input/pckbd.c index 3c41c11841..3ecc9c74ab 100644 --- a/hw/input/pckbd.c +++ b/hw/input/pckbd.c @@ -195,21 +195,28 @@ static void kbd_deassert_irq(KBDState *s) kbd_update_irq_lines(s); } +static uint8_t kbd_pending(KBDState *s) +{ + return s->pending; +} + /* update irq and KBD_STAT_[MOUSE_]OBF */ static void kbd_update_irq(KBDState *s) { + uint8_t pending = kbd_pending(s); + s->status &= ~(KBD_STAT_OBF | KBD_STAT_MOUSE_OBF); s->outport &= ~(KBD_OUT_OBF | KBD_OUT_MOUSE_OBF); - if (s->pending) { + if (pending) { s->status |= KBD_STAT_OBF; s->outport |= KBD_OUT_OBF; - if (s->pending & KBD_PENDING_CTRL_KBD) { + if (pending & KBD_PENDING_CTRL_KBD) { s->obsrc = KBD_OBSRC_CTRL; - } else if (s->pending & KBD_PENDING_CTRL_AUX) { + } else if (pending & KBD_PENDING_CTRL_AUX) { s->status |= KBD_STAT_MOUSE_OBF; s->outport |= KBD_OUT_MOUSE_OBF; s->obsrc = KBD_OBSRC_CTRL; - } else if (s->pending & KBD_PENDING_KBD) { + } else if (pending & KBD_PENDING_KBD) { s->obsrc = KBD_OBSRC_KBD; } else { s->status |= KBD_STAT_MOUSE_OBF; @@ -233,7 +240,7 @@ static void kbd_safe_update_irq(KBDState *s) if (s->throttle_timer && timer_pending(s->throttle_timer)) { return; } - if (s->pending) { + if (kbd_pending(s)) { kbd_update_irq(s); } } @@ -269,7 +276,7 @@ static void kbd_throttle_timeout(void *opaque) if (s->status & KBD_STAT_OBF) { return; } - if (s->pending) { + if (kbd_pending(s)) { kbd_update_irq(s); } } @@ -297,7 +304,7 @@ static uint8_t kbd_dequeue(KBDState *s) uint8_t b = s->cbdata; s->pending &= ~KBD_PENDING_CTRL_KBD & ~KBD_PENDING_CTRL_AUX; - if (s->pending) { + if (kbd_pending(s)) { kbd_update_irq(s); } return b; From patchwork Fri May 7 18:09:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Volker_R=C3=BCmelin?= X-Patchwork-Id: 1475636 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FcJjB2bxGz9sj5 for ; Sat, 8 May 2021 04:23:09 +1000 (AEST) Received: from localhost ([::1]:57434 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lf57x-0006WZ-SD for incoming@patchwork.ozlabs.org; Fri, 07 May 2021 14:23:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60650) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf51A-0000b2-JW for qemu-devel@nongnu.org; Fri, 07 May 2021 14:16:04 -0400 Received: from mailout09.t-online.de ([194.25.134.84]:40914) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf4vm-0001bl-TR for qemu-devel@nongnu.org; Fri, 07 May 2021 14:10:36 -0400 Received: from fwd27.aul.t-online.de (fwd27.aul.t-online.de [172.20.26.132]) by mailout09.t-online.de (Postfix) with SMTP id 806775A70D; Fri, 7 May 2021 20:10:24 +0200 (CEST) Received: from linpower.localnet (SrgmIvZaohpbcsB5MBcdcFV7-au+YJR2eCs-raEEwxPVgAvXtzD-OBg2hbw14Z-gE0@[46.86.52.8]) by fwd27.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1lf4vZ-0fF3my0; Fri, 7 May 2021 20:10:17 +0200 Received: by linpower.localnet (Postfix, from userid 1000) id 7095A2006FE; Fri, 7 May 2021 20:09:53 +0200 (CEST) From: =?utf-8?q?Volker_R=C3=BCmelin?= To: "Michael S. Tsirkin" , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v2 10/11] pckbd: correctly disable PS/2 communication Date: Fri, 7 May 2021 20:09:52 +0200 Message-Id: <20210507180953.8530-10-vr_qemu@t-online.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 X-ID: SrgmIvZaohpbcsB5MBcdcFV7-au+YJR2eCs-raEEwxPVgAvXtzD-OBg2hbw14Z-gE0 X-TOI-EXPURGATEID: 150726::1620411017-000107BB-2671AA0E/0/0 CLEAN NORMAL X-TOI-MSGID: c1d42b8b-43bf-458f-88ef-828046e0e5c7 Received-SPF: none client-ip=194.25.134.84; envelope-from=volker.ruemelin@t-online.de; helo=mailout09.t-online.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Currently the PS/2 controller command KBD_CCMD_MOUSE_DISABLE doesn't disable the PS/2 mouse communication at all, and the PS/2 controller commands KBD_CCMD_KBD_DISABLE and KBD_CCMD_KBD_ENABLE disable and enable the keyboard interrupt, which is very different from what a real PS/2 controller does. A guest may notice the difference. Mask out pending data on disabled queues to correctly disable the PS/2 controller communication. Signed-off-by: Volker Rümelin --- hw/input/pckbd.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/hw/input/pckbd.c b/hw/input/pckbd.c index 3ecc9c74ab..7c476f7a3e 100644 --- a/hw/input/pckbd.c +++ b/hw/input/pckbd.c @@ -130,10 +130,12 @@ #define MOUSE_STATUS_ENABLED 0x20 #define MOUSE_STATUS_SCALE21 0x10 -#define KBD_PENDING_KBD 1 -#define KBD_PENDING_AUX 2 +#define KBD_PENDING_KBD_V3 0x01 +#define KBD_PENDING_AUX_V3 0x02 #define KBD_PENDING_CTRL_KBD 0x04 #define KBD_PENDING_CTRL_AUX 0x08 +#define KBD_PENDING_KBD KBD_MODE_DISABLE_KBD /* 0x10 */ +#define KBD_PENDING_AUX KBD_MODE_DISABLE_MOUSE /* 0x20 */ #define KBD_MIGR_TIMER_PENDING 0x1 @@ -163,8 +165,6 @@ typedef struct KBDState { hwaddr mask; } KBDState; -/* XXX: not generating the irqs if KBD_MODE_DISABLE_KBD is set may be - incorrect, but it avoids having to simulate exact delays */ static void kbd_update_irq_lines(KBDState *s) { int irq_kbd_level, irq_mouse_level; @@ -178,8 +178,7 @@ static void kbd_update_irq_lines(KBDState *s) irq_mouse_level = 1; } } else { - if ((s->mode & KBD_MODE_KBD_INT) && - !(s->mode & KBD_MODE_DISABLE_KBD)) { + if (s->mode & KBD_MODE_KBD_INT) { irq_kbd_level = 1; } } @@ -197,7 +196,7 @@ static void kbd_deassert_irq(KBDState *s) static uint8_t kbd_pending(KBDState *s) { - return s->pending; + return s->pending & (~s->mode | ~(KBD_PENDING_KBD | KBD_PENDING_AUX)); } /* update irq and KBD_STAT_[MOUSE_]OBF */ @@ -357,6 +356,7 @@ static void kbd_write_command(void *opaque, hwaddr addr, break; case KBD_CCMD_MOUSE_ENABLE: s->mode &= ~KBD_MODE_DISABLE_MOUSE; + kbd_safe_update_irq(s); break; case KBD_CCMD_TEST_MOUSE: kbd_queue(s, 0x00, 0); @@ -436,6 +436,9 @@ static void kbd_write_data(void *opaque, hwaddr addr, switch(s->write_cmd) { case 0: ps2_write_keyboard(s->kbd, val); + /* sending data to the keyboard reenables PS/2 communication */ + s->mode &= ~KBD_MODE_DISABLE_KBD; + kbd_safe_update_irq(s); break; case KBD_CCMD_WRITE_MODE: s->mode = val; @@ -462,6 +465,9 @@ static void kbd_write_data(void *opaque, hwaddr addr, break; case KBD_CCMD_WRITE_MOUSE: ps2_write_mouse(s->mouse, val); + /* sending data to the mouse reenables PS/2 communication */ + s->mode &= ~KBD_MODE_DISABLE_MOUSE; + kbd_safe_update_irq(s); break; default: break; @@ -539,7 +545,16 @@ static int kbd_post_load(void *opaque, int version_id) s->obsrc = s->status & KBD_STAT_OBF ? (s->status & KBD_STAT_MOUSE_OBF ? KBD_OBSRC_MOUSE : KBD_OBSRC_KBD) : 0; + if (s->pending & KBD_PENDING_KBD_V3) { + s->pending |= KBD_PENDING_KBD; + } + if (s->pending & KBD_PENDING_AUX_V3) { + s->pending |= KBD_PENDING_AUX; + } } + /* clear all unused flags */ + s->pending &= KBD_PENDING_CTRL_KBD | KBD_PENDING_CTRL_AUX | + KBD_PENDING_KBD | KBD_PENDING_AUX; if (s->migration_flags & KBD_MIGR_TIMER_PENDING) { kbd_throttle_timeout(s); } From patchwork Fri May 7 18:09:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Volker_R=C3=BCmelin?= X-Patchwork-Id: 1475640 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FcJnq6K5mz9sXL for ; Sat, 8 May 2021 04:27:11 +1000 (AEST) Received: from localhost ([::1]:36760 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lf5Bt-0003F8-IW for incoming@patchwork.ozlabs.org; Fri, 07 May 2021 14:27:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60652) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf51B-0000b3-0q for qemu-devel@nongnu.org; Fri, 07 May 2021 14:16:05 -0400 Received: from mailout07.t-online.de ([194.25.134.83]:59788) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf4vg-0001bV-JJ for qemu-devel@nongnu.org; Fri, 07 May 2021 14:10:34 -0400 Received: from fwd11.aul.t-online.de (fwd11.aul.t-online.de [172.20.27.152]) by mailout07.t-online.de (Postfix) with SMTP id 95F6663890; Fri, 7 May 2021 20:10:20 +0200 (CEST) Received: from linpower.localnet (TtNPusZbohA2DJJOgHOS6x8oJvUFF-KaQrKHXXwJuAbYG26aH9YjrTzuExmPY9zgff@[46.86.52.8]) by fwd11.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1lf4vc-1dtie80; Fri, 7 May 2021 20:10:20 +0200 Received: by linpower.localnet (Postfix, from userid 1000) id 72C992006FF; Fri, 7 May 2021 20:09:53 +0200 (CEST) From: =?utf-8?q?Volker_R=C3=BCmelin?= To: "Michael S. Tsirkin" , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v2 11/11] pckbd: remove duplicated keyboard and mouse defines Date: Fri, 7 May 2021 20:09:53 +0200 Message-Id: <20210507180953.8530-11-vr_qemu@t-online.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 X-ID: TtNPusZbohA2DJJOgHOS6x8oJvUFF-KaQrKHXXwJuAbYG26aH9YjrTzuExmPY9zgff X-TOI-EXPURGATEID: 150726::1620411020-00007FA5-58FBA92D/0/0 CLEAN NORMAL X-TOI-MSGID: ba811b08-f0e6-416d-a80f-385eb0ba8dbf Received-SPF: none client-ip=194.25.134.83; envelope-from=volker.ruemelin@t-online.de; helo=mailout07.t-online.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" In 2005 the author of commit daa579632d "PS2 mouse and keyboard separation (Paul Brook)" and 0e43e99c04 "PS2 mouse and keyboard separation (Paul Brook)" separated the PS/2 controller code and the PS/2 keyboard and mouse code. It seems he forgot to remove a few defines. Remove them now. Signed-off-by: Volker Rümelin --- hw/input/pckbd.c | 37 ------------------------------------- 1 file changed, 37 deletions(-) diff --git a/hw/input/pckbd.c b/hw/input/pckbd.c index 7c476f7a3e..a386457187 100644 --- a/hw/input/pckbd.c +++ b/hw/input/pckbd.c @@ -61,21 +61,6 @@ #define KBD_CCMD_RESET 0xFE /* Pulse bit 0 of the output port P2 = CPU reset. */ #define KBD_CCMD_NO_OP 0xFF /* Pulse no bits of the output port P2. */ -/* Keyboard Commands */ -#define KBD_CMD_SET_LEDS 0xED /* Set keyboard leds */ -#define KBD_CMD_ECHO 0xEE -#define KBD_CMD_GET_ID 0xF2 /* get keyboard ID */ -#define KBD_CMD_SET_RATE 0xF3 /* Set typematic rate */ -#define KBD_CMD_ENABLE 0xF4 /* Enable scanning */ -#define KBD_CMD_RESET_DISABLE 0xF5 /* reset and disable scanning */ -#define KBD_CMD_RESET_ENABLE 0xF6 /* reset and enable scanning */ -#define KBD_CMD_RESET 0xFF /* Reset */ - -/* Keyboard Replies */ -#define KBD_REPLY_POR 0xAA /* Power on reset */ -#define KBD_REPLY_ACK 0xFA /* Command ACK */ -#define KBD_REPLY_RESEND 0xFE /* Command NACK, send the cmd again */ - /* Status Register Bits */ #define KBD_STAT_OBF 0x01 /* Keyboard output buffer full */ #define KBD_STAT_IBF 0x02 /* Keyboard input buffer full */ @@ -108,28 +93,6 @@ */ #define KBD_OUT_ONES 0xcc -/* Mouse Commands */ -#define AUX_SET_SCALE11 0xE6 /* Set 1:1 scaling */ -#define AUX_SET_SCALE21 0xE7 /* Set 2:1 scaling */ -#define AUX_SET_RES 0xE8 /* Set resolution */ -#define AUX_GET_SCALE 0xE9 /* Get scaling factor */ -#define AUX_SET_STREAM 0xEA /* Set stream mode */ -#define AUX_POLL 0xEB /* Poll */ -#define AUX_RESET_WRAP 0xEC /* Reset wrap mode */ -#define AUX_SET_WRAP 0xEE /* Set wrap mode */ -#define AUX_SET_REMOTE 0xF0 /* Set remote mode */ -#define AUX_GET_TYPE 0xF2 /* Get type */ -#define AUX_SET_SAMPLE 0xF3 /* Set sample rate */ -#define AUX_ENABLE_DEV 0xF4 /* Enable aux device */ -#define AUX_DISABLE_DEV 0xF5 /* Disable aux device */ -#define AUX_SET_DEFAULT 0xF6 -#define AUX_RESET 0xFF /* Reset aux device */ -#define AUX_ACK 0xFA /* Command byte ACK. */ - -#define MOUSE_STATUS_REMOTE 0x40 -#define MOUSE_STATUS_ENABLED 0x20 -#define MOUSE_STATUS_SCALE21 0x10 - #define KBD_PENDING_KBD_V3 0x01 #define KBD_PENDING_AUX_V3 0x02 #define KBD_PENDING_CTRL_KBD 0x04