From nobody Tue Aug 25 17:51:27 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1779364938; cv=none; d=zohomail.com; s=zohoarc; b=AxdJ4sVswsfWxEaHWp6b1WwzQ3tFrA6LVZqSj5Op6FrAMMiKMWQN8qjppZc7z9DADYJUyGoQU1KZ2Opu7Llc0eIVYGJaEXhUCATKW7carFA7S/krCfjONawlB3mGL7spxPOoCkJEw6GPPy3dnoI8qB2XnL8CKlf1xuLtpf9PnUY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779364938; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=YQ54XMaiAgfFL8G0tzhmo5Nowz0ljDTt98jhBbihl7Q=; b=Q4puT/Z0/oSDx+RwbRmuMYGYNR08EJiTy55qd0W2KcUXbK0PQWbXAAVJqvp17yB7g9gAW+DNPHUrFWNCNCVhHZ7FEKuuebia6AMQfEkV6K/roBul6e36DqNScFZY67T5Q4OD9BD8iSEYP2lbJHq43VcLClzVx8lOsyMFTkIfJQM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779364938099397.4868268083495; Thu, 21 May 2026 05:02:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wQ25J-00019T-M7; Thu, 21 May 2026 08:01:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wQ23v-00088T-4x for qemu-devel@nongnu.org; Thu, 21 May 2026 07:59:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wQ23o-0004X4-GG for qemu-devel@nongnu.org; Thu, 21 May 2026 07:59:37 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-642-LLJEPJ45OWaXQ_kTmtInjg-1; Thu, 21 May 2026 07:59:28 -0400 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4A43419560B4; Thu, 21 May 2026 11:59:27 +0000 (UTC) Received: from localhost (unknown [10.44.24.26]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 446E11684; Thu, 21 May 2026 11:59:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1779364771; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YQ54XMaiAgfFL8G0tzhmo5Nowz0ljDTt98jhBbihl7Q=; b=K+acDEXAdC3BzIiSqa5/+o58shUFsK4xh30itnDYnaAcWXURaFeLcpuYwZ73rzS5bGk1M7 dyAISUZ5x7gva055uym2YB5lTwj2xmtOJgfRBQ4tLRbrWrujHREP5hMkY1IcVhB5HimpVt 6usEAwCNWt5z2nZMUrulBmM/xfCbET0= X-MC-Unique: LLJEPJ45OWaXQ_kTmtInjg-1 X-Mimecast-MFC-AGG-ID: LLJEPJ45OWaXQ_kTmtInjg_1779364767 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: stefanha@gmail.com, Akihiko Odaki Subject: [PULL 21/38] hw/input/ps2: Use Linux key codes Date: Thu, 21 May 2026 15:56:58 +0400 Message-ID: <20260521115717.1701482-22-marcandre.lureau@redhat.com> In-Reply-To: <20260521115717.1701482-1-marcandre.lureau@redhat.com> References: <20260521115717.1701482-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 8 X-Spam_score: 0.8 X-Spam_bar: / X-Spam_report: (0.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1779364941812154100 From: Akihiko Odaki QemuInputEvent now stores Linux key codes for key events. Use those codes directly instead of translating between internal key code representations. Signed-off-by: Akihiko Odaki Reviewed-by: Marc-Andr=C3=A9 Lureau Message-ID: <20260520-input-v3-13-7c9e4c7abe34@rsg.ci.i.u-tokyo.ac.jp> --- hw/input/ps2.c | 51 +++++++++++++++++++++---------------------- hw/input/trace-events | 2 +- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/hw/input/ps2.c b/hw/input/ps2.c index 93c3c737205..f2523ff4bc7 100644 --- a/hw/input/ps2.c +++ b/hw/input/ps2.c @@ -28,6 +28,7 @@ #include "hw/core/sysbus.h" #include "hw/input/ps2.h" #include "migration/vmstate.h" +#include "standard-headers/linux/input-event-codes.h" #include "ui/console.h" #include "ui/input.h" #include "system/reset.h" @@ -123,20 +124,20 @@ static uint8_t translate_table[256] =3D { 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, }; =20 -static unsigned int ps2_modifier_bit(QKeyCode key) +static unsigned int ps2_modifier_bit(unsigned int key) { switch (key) { - case Q_KEY_CODE_CTRL: + case KEY_LEFTCTRL: return MOD_CTRL_L; - case Q_KEY_CODE_CTRL_R: + case KEY_RIGHTCTRL: return MOD_CTRL_R; - case Q_KEY_CODE_SHIFT: + case KEY_LEFTSHIFT: return MOD_SHIFT_L; - case Q_KEY_CODE_SHIFT_R: + case KEY_RIGHTSHIFT: return MOD_SHIFT_R; - case Q_KEY_CODE_ALT: + case KEY_LEFTALT: return MOD_ALT_L; - case Q_KEY_CODE_ALT_R: + case KEY_RIGHTALT: return MOD_ALT_R; default: return 0; @@ -313,7 +314,6 @@ static void ps2_keyboard_event(DeviceState *dev, QemuCo= nsole *src, QemuInputEvent *evt) { PS2KbdState *s =3D (PS2KbdState *)dev; - int qcode; uint16_t keycode =3D 0; int mod; =20 @@ -324,10 +324,9 @@ static void ps2_keyboard_event(DeviceState *dev, QemuC= onsole *src, =20 qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER, NULL); assert(evt->type =3D=3D INPUT_EVENT_KIND_KEY); - qcode =3D qemu_input_linux_to_qcode(evt->key.key); =20 - mod =3D ps2_modifier_bit(qcode); - trace_ps2_keyboard_event(s, qcode, evt->key.down, mod, + mod =3D ps2_modifier_bit(evt->key.key); + trace_ps2_keyboard_event(s, evt->key.key, evt->key.down, mod, s->modifiers, s->scancode_set, s->translate); if (evt->key.down) { s->modifiers |=3D mod; @@ -336,7 +335,7 @@ static void ps2_keyboard_event(DeviceState *dev, QemuCo= nsole *src, } =20 if (s->scancode_set =3D=3D 1) { - if (qcode =3D=3D Q_KEY_CODE_PAUSE) { + if (evt->key.key =3D=3D KEY_PAUSE) { if (s->modifiers & (MOD_CTRL_L | MOD_CTRL_R)) { if (evt->key.down) { ps2_put_keycode(s, 0xe0); @@ -354,7 +353,7 @@ static void ps2_keyboard_event(DeviceState *dev, QemuCo= nsole *src, ps2_put_keycode(s, 0xc5); } } - } else if (qcode =3D=3D Q_KEY_CODE_PRINT) { + } else if (evt->key.key =3D=3D KEY_SYSRQ) { if (s->modifiers & MOD_ALT_L) { if (evt->key.down) { ps2_put_keycode(s, 0xb8); @@ -401,12 +400,12 @@ static void ps2_keyboard_event(DeviceState *dev, Qemu= Console *src, ps2_put_keycode(s, 0xaa); } } - } else if ((qcode =3D=3D Q_KEY_CODE_LANG1 || qcode =3D=3D Q_KEY_CO= DE_LANG2) + } else if ((evt->key.key =3D=3D KEY_HANGEUL || evt->key.key =3D=3D= KEY_HANJA) && !evt->key.down) { /* Ignore release for these keys */ } else { - if (qcode < qemu_input_map_qcode_to_atset1_len) { - keycode =3D qemu_input_map_qcode_to_atset1[qcode]; + if (evt->key.key < qemu_input_map_linux_to_atset1_len) { + keycode =3D qemu_input_map_linux_to_atset1[evt->key.key]; } if (keycode) { if (keycode & 0xff00) { @@ -418,11 +417,11 @@ static void ps2_keyboard_event(DeviceState *dev, Qemu= Console *src, ps2_put_keycode(s, keycode & 0xff); } else { qemu_log_mask(LOG_UNIMP, - "ps2: ignoring key with qcode %d\n", qcode); + "ps2: ignoring key %u\n", evt->key.key); } } } else if (s->scancode_set =3D=3D 2) { - if (qcode =3D=3D Q_KEY_CODE_PAUSE) { + if (evt->key.key =3D=3D KEY_PAUSE) { if (s->modifiers & (MOD_CTRL_L | MOD_CTRL_R)) { if (evt->key.down) { ps2_put_keycode(s, 0xe0); @@ -443,7 +442,7 @@ static void ps2_keyboard_event(DeviceState *dev, QemuCo= nsole *src, ps2_put_keycode(s, 0x77); } } - } else if (qcode =3D=3D Q_KEY_CODE_PRINT) { + } else if (evt->key.key =3D=3D KEY_SYSRQ) { if (s->modifiers & MOD_ALT_L) { if (evt->key.down) { ps2_put_keycode(s, 0xf0); @@ -499,12 +498,12 @@ static void ps2_keyboard_event(DeviceState *dev, Qemu= Console *src, ps2_put_keycode(s, 0x12); } } - } else if ((qcode =3D=3D Q_KEY_CODE_LANG1 || qcode =3D=3D Q_KEY_CO= DE_LANG2) && + } else if ((evt->key.key =3D=3D KEY_HANGEUL || evt->key.key =3D=3D= KEY_HANJA) && !evt->key.down) { /* Ignore release for these keys */ } else { - if (qcode < qemu_input_map_qcode_to_atset2_len) { - keycode =3D qemu_input_map_qcode_to_atset2[qcode]; + if (evt->key.key < qemu_input_map_linux_to_atset2_len) { + keycode =3D qemu_input_map_linux_to_atset2[evt->key.key]; } if (keycode) { if (keycode & 0xff00) { @@ -516,12 +515,12 @@ static void ps2_keyboard_event(DeviceState *dev, Qemu= Console *src, ps2_put_keycode(s, keycode & 0xff); } else { qemu_log_mask(LOG_UNIMP, - "ps2: ignoring key with qcode %d\n", qcode); + "ps2: ignoring key %u\n", evt->key.key); } } } else if (s->scancode_set =3D=3D 3) { - if (qcode < qemu_input_map_qcode_to_atset3_len) { - keycode =3D qemu_input_map_qcode_to_atset3[qcode]; + if (evt->key.key < qemu_input_map_linux_to_atset3_len) { + keycode =3D qemu_input_map_linux_to_atset3[evt->key.key]; } if (keycode) { /* FIXME: break code should be configured on a key by key basi= s */ @@ -531,7 +530,7 @@ static void ps2_keyboard_event(DeviceState *dev, QemuCo= nsole *src, ps2_put_keycode(s, keycode); } else { qemu_log_mask(LOG_UNIMP, - "ps2: ignoring key with qcode %d\n", qcode); + "ps2: ignoring key %u\n", evt->key.key); } } } diff --git a/hw/input/trace-events b/hw/input/trace-events index 1484625565b..43900914be2 100644 --- a/hw/input/trace-events +++ b/hw/input/trace-events @@ -30,7 +30,7 @@ pckbd_kbd_write_data(uint64_t val) "0x%02"PRIx64 =20 # ps2.c ps2_put_keycode(void *opaque, int keycode) "%p keycode 0x%02x" -ps2_keyboard_event(void *opaque, int qcode, int down, unsigned int modifie= r, unsigned int modifiers, int set, int xlate) "%p qcode %d down %d modifie= r 0x%x modifiers 0x%x set %d xlate %d" +ps2_keyboard_event(void *opaque, unsigned int lnx, int down, unsigned int = modifier, unsigned int modifiers, int set, int xlate) "%p lnx %u down %d mo= difier 0x%x modifiers 0x%x set %d xlate %d" ps2_read_data(void *opaque) "%p" ps2_set_ledstate(void *s, int ledstate) "%p ledstate %d" ps2_reset_keyboard(void *s) "%p" --=20 2.54.0