From patchwork Wed May 5 19:21:31 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: 1474539 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 4Fb6JY1bzpz9sPf for ; Thu, 6 May 2021 05:31:09 +1000 (AEST) Received: from localhost ([::1]:37678 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1leNEg-0008Ao-Ny for incoming@patchwork.ozlabs.org; Wed, 05 May 2021 15:31:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43628) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1leN6j-000219-58 for qemu-devel@nongnu.org; Wed, 05 May 2021 15:22:54 -0400 Received: from mailout10.t-online.de ([194.25.134.21]:50418) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1leN6g-0007fc-RD for qemu-devel@nongnu.org; Wed, 05 May 2021 15:22:52 -0400 Received: from fwd09.aul.t-online.de (fwd09.aul.t-online.de [172.20.27.151]) by mailout10.t-online.de (Postfix) with SMTP id 812C9BBEA2; Wed, 5 May 2021 21:21:56 +0200 (CEST) Received: from linpower.localnet (TF+4R2ZQYhA8Wn5GS4um50xJNIPgDve6hZG5psMsSwfzt5IjAXCwdD03ddzN-Oeg6e@[46.86.52.8]) by fwd09.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1leN5l-4XWmRc0; Wed, 5 May 2021 21:21:53 +0200 Received: by linpower.localnet (Postfix, from userid 1000) id 0286F2006F8; Wed, 5 May 2021 21:21:34 +0200 (CEST) From: =?utf-8?q?Volker_R=C3=BCmelin?= To: "Michael S. Tsirkin" , Paolo Bonzini Subject: [PATCH 08/10] pckbd: add controller response queue Date: Wed, 5 May 2021 21:21:31 +0200 Message-Id: <20210505192133.7480-8-vr_qemu@t-online.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 X-ID: TF+4R2ZQYhA8Wn5GS4um50xJNIPgDve6hZG5psMsSwfzt5IjAXCwdD03ddzN-Oeg6e X-TOI-EXPURGATEID: 150726::1620242513-00002D5B-739ED396/0/0 CLEAN NORMAL X-TOI-MSGID: a310330d-494f-4a76-97fc-6aa29130b6d3 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_H4=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 patch, where the guest can disable the PS/2 communication with the 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*[]) {