From nobody Wed Nov 27 12:58:19 2024 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=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1699036173; cv=none; d=zohomail.com; s=zohoarc; b=kbWZyfbO2eagZcFc3g9o2YBI/RID/PV9LUaGqbl+dkJXAw4NamCJzwQb4Q8dkhVL4H0wt+TENzG7/GabwfVx6u4CQv8NtjyLvSgWLq2/paeWsZw/WKjOKpdMda+bnoH6lWzCmfB12QkHIRZ1lNVCqFd37yOmY3G7jw4ilCvVgd8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699036173; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=+EVTungCfjDjTacji5Eqs9/sv58Ra/hS/gF67unlV+M=; b=G4Zv8M9GdntfNOIOYdUlhmMHjPTxA4YGMowFk4yDdltsIXj4A9Bor+QvzYKnRmTPy2gu5WzzadWw9raWeI/5N8W+Fmk0X8vIhItfmVfa6/TEI5I2KQhR92cTQe3nuvJR3tMMTW8JwGOd1cS5Hky6GuuIz2kNJ/mevGILzsHOuoQ= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1699036173150673.8390000073666; Fri, 3 Nov 2023 11:29:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qyytn-0001kC-II; Fri, 03 Nov 2023 14:28:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qyytm-0001jd-AR for qemu-devel@nongnu.org; Fri, 03 Nov 2023 14:28:02 -0400 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qyyte-0007AU-Kq for qemu-devel@nongnu.org; Fri, 03 Nov 2023 14:28:02 -0400 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-32ded3eb835so1594336f8f.0 for ; Fri, 03 Nov 2023 11:27:53 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id i7-20020adfe487000000b0032de6f95fb3sm2423224wrm.40.2023.11.03.11.27.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 11:27:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699036073; x=1699640873; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=+EVTungCfjDjTacji5Eqs9/sv58Ra/hS/gF67unlV+M=; b=J7blYejozMCugUYX3MSVHHG2j926sHxqcOVq/N1Zuyp0BXwqou7qNo9JIzNXG7JQ8r 9c2Ok/1ePEhCOS75JBO6uBmVm92FRn8vOySPBgj3X6zn++pj0F07b4AHjhdkbqK5Ele2 3mz/T0ZrRA/BTlC580TjfXhZC6Ps10krTpyDEL10Lz6Hi6VT/mY0sHX5GLRMSmXvlAxf EqGTw6LPFzc022sVgMhl1mFyIqNgJ3bPUvRiWK1F6XWLrFdfhMq9bmnNP6PaCqSNQTd/ f4QLbc1ctWmIu5td3wB+oKAtk/eGbT3F+T5J0D5i8AgDIhIYYR7QDU/S9Zy4Z3pzm6Kz g1iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699036073; x=1699640873; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+EVTungCfjDjTacji5Eqs9/sv58Ra/hS/gF67unlV+M=; b=CL8iNkP4pmqBtnVkJVi8Erq0IaX3wmgpAZBn5gqw6b2pKMO7T9sdQ61Mro2nlnjMRZ 5WdJzHVCWVEVFGqyZz/Nddv3VLIjabvVyGK4HYA46me1bA12WV6eYq7VxhL9JRM0gew3 Yiv14PvaR17xhl3zEjI6ale6HB7zYaFewk4tnva45ZKKHdOMAiJzm1krf4dvudJ7aMFD DxuVndkgBNKSW8urhuC7ywvClFBPVHjPd52IuYYgOp0tXv4c7nfxTrzRthT4Fp1iuIf5 +bnp7Pfjg2Nb8u9bkU2coPZbdJKLXN1wutB6BBB2nX/Au5y8FUoUkgfUfQnzhtg9DLfN p5sA== X-Gm-Message-State: AOJu0YxR4nnCDrp+a7kErkvm6N2Ec/PrxuO6T1h8bvD8i5KQtxgCGhD+ lqWKxy4+lPdy9WME0i7FYsQ58w== X-Google-Smtp-Source: AGHT+IF7EveEAMs6BsQht2VPo5CV3E0cgZk8MYNwSK188zEc21SGjDtTXPIRhMPSm2S+bqAPVtOToQ== X-Received: by 2002:a5d:4e06:0:b0:32d:7efc:7e1f with SMTP id p6-20020a5d4e06000000b0032d7efc7e1fmr14761777wrt.71.1699036072728; Fri, 03 Nov 2023 11:27:52 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Cc: Jan Kiszka Subject: [PATCH] hw/arm/musicpal: Convert to qemu_add_kbd_event_handler() Date: Fri, 3 Nov 2023 18:27:50 +0000 Message-Id: <20231103182750.855577-1-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::433; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x433.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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 @linaro.org) X-ZM-MESSAGEID: 1699036174681100001 Content-Type: text/plain; charset="utf-8" Convert the musicpal key input device to use qemu_add_kbd_event_handler(). This lets us simplify it because we no longer need to track whether we're in the middle of a PS/2 multibyte key sequence. In the conversion we move the keyboard handler registration from init to realize, because devices shouldn't disturb the state of the simulation by doing things like registering input handlers until they're realized, so that device objects can be introspected safely. The behaviour where key-repeat is permitted for the arrow-keys only is intentional (added in commit 7c6ce4baedfcd0c), so we retain it, and add a comment to that effect. This is a migration compatibility break for musicpal. Signed-off-by: Peter Maydell Reviewed-by: Alex Benn=C3=A9e Tested-by: Alex Benn=C3=A9e --- hw/arm/musicpal.c | 131 +++++++++++++++++++++------------------------- 1 file changed, 61 insertions(+), 70 deletions(-) diff --git a/hw/arm/musicpal.c b/hw/arm/musicpal.c index 9703bfb97fb..e8c1250ab04 100644 --- a/hw/arm/musicpal.c +++ b/hw/arm/musicpal.c @@ -1043,20 +1043,6 @@ static const TypeInfo musicpal_gpio_info =3D { }; =20 /* Keyboard codes & masks */ -#define KEY_RELEASED 0x80 -#define KEY_CODE 0x7f - -#define KEYCODE_TAB 0x0f -#define KEYCODE_ENTER 0x1c -#define KEYCODE_F 0x21 -#define KEYCODE_M 0x32 - -#define KEYCODE_EXTENDED 0xe0 -#define KEYCODE_UP 0x48 -#define KEYCODE_DOWN 0x50 -#define KEYCODE_LEFT 0x4b -#define KEYCODE_RIGHT 0x4d - #define MP_KEY_WHEEL_VOL (1 << 0) #define MP_KEY_WHEEL_VOL_INV (1 << 1) #define MP_KEY_WHEEL_NAV (1 << 2) @@ -1074,67 +1060,66 @@ struct musicpal_key_state { SysBusDevice parent_obj; /*< public >*/ =20 - uint32_t kbd_extended; uint32_t pressed_keys; qemu_irq out[8]; }; =20 -static void musicpal_key_event(void *opaque, int keycode) +static void musicpal_key_event(DeviceState *dev, QemuConsole *src, + InputEvent *evt) { - musicpal_key_state *s =3D opaque; + musicpal_key_state *s =3D MUSICPAL_KEY(dev); + InputKeyEvent *key =3D evt->u.key.data; + int qcode =3D qemu_input_key_value_to_qcode(key->key); uint32_t event =3D 0; int i; =20 - if (keycode =3D=3D KEYCODE_EXTENDED) { - s->kbd_extended =3D 1; - return; + switch (qcode) { + case Q_KEY_CODE_UP: + event =3D MP_KEY_WHEEL_NAV | MP_KEY_WHEEL_NAV_INV; + break; + + case Q_KEY_CODE_DOWN: + event =3D MP_KEY_WHEEL_NAV; + break; + + case Q_KEY_CODE_LEFT: + event =3D MP_KEY_WHEEL_VOL | MP_KEY_WHEEL_VOL_INV; + break; + + case Q_KEY_CODE_RIGHT: + event =3D MP_KEY_WHEEL_VOL; + break; + + case Q_KEY_CODE_F: + event =3D MP_KEY_BTN_FAVORITS; + break; + + case Q_KEY_CODE_TAB: + event =3D MP_KEY_BTN_VOLUME; + break; + + case Q_KEY_CODE_RET: + event =3D MP_KEY_BTN_NAVIGATION; + break; + + case Q_KEY_CODE_M: + event =3D MP_KEY_BTN_MENU; + break; } =20 - if (s->kbd_extended) { - switch (keycode & KEY_CODE) { - case KEYCODE_UP: - event =3D MP_KEY_WHEEL_NAV | MP_KEY_WHEEL_NAV_INV; - break; - - case KEYCODE_DOWN: - event =3D MP_KEY_WHEEL_NAV; - break; - - case KEYCODE_LEFT: - event =3D MP_KEY_WHEEL_VOL | MP_KEY_WHEEL_VOL_INV; - break; - - case KEYCODE_RIGHT: - event =3D MP_KEY_WHEEL_VOL; - break; - } - } else { - switch (keycode & KEY_CODE) { - case KEYCODE_F: - event =3D MP_KEY_BTN_FAVORITS; - break; - - case KEYCODE_TAB: - event =3D MP_KEY_BTN_VOLUME; - break; - - case KEYCODE_ENTER: - event =3D MP_KEY_BTN_NAVIGATION; - break; - - case KEYCODE_M: - event =3D MP_KEY_BTN_MENU; - break; - } - /* Do not repeat already pressed buttons */ - if (!(keycode & KEY_RELEASED) && (s->pressed_keys & event)) { + /* + * We allow repeated wheel-events when the arrow keys are held down, + * but do not repeat already-pressed buttons for the other key inputs. + */ + if (!(event & (MP_KEY_WHEEL_NAV | MP_KEY_WHEEL_VOL))) { + if (key->down && (s->pressed_keys & event)) { event =3D 0; } } =20 if (event) { /* Raise GPIO pin first if repeating a key */ - if (!(keycode & KEY_RELEASED) && (s->pressed_keys & event)) { + if (key->down && (s->pressed_keys & event)) { for (i =3D 0; i <=3D 7; i++) { if (event & (1 << i)) { qemu_set_irq(s->out[i], 1); @@ -1143,17 +1128,15 @@ static void musicpal_key_event(void *opaque, int ke= ycode) } for (i =3D 0; i <=3D 7; i++) { if (event & (1 << i)) { - qemu_set_irq(s->out[i], !!(keycode & KEY_RELEASED)); + qemu_set_irq(s->out[i], !key->down); } } - if (keycode & KEY_RELEASED) { - s->pressed_keys &=3D ~event; - } else { + if (key->down) { s->pressed_keys |=3D event; + } else { + s->pressed_keys &=3D ~event; } } - - s->kbd_extended =3D 0; } =20 static void musicpal_key_init(Object *obj) @@ -1162,20 +1145,27 @@ static void musicpal_key_init(Object *obj) DeviceState *dev =3D DEVICE(sbd); musicpal_key_state *s =3D MUSICPAL_KEY(dev); =20 - s->kbd_extended =3D 0; s->pressed_keys =3D 0; =20 qdev_init_gpio_out(dev, s->out, ARRAY_SIZE(s->out)); +} =20 - qemu_add_kbd_event_handler(musicpal_key_event, s); +static const QemuInputHandler musicpal_key_handler =3D { + .name =3D "musicpal_key", + .mask =3D INPUT_EVENT_MASK_KEY, + .event =3D musicpal_key_event, +}; + +static void musicpal_key_realize(DeviceState *dev, Error **errp) +{ + qemu_input_handler_register(dev, &musicpal_key_handler); } =20 static const VMStateDescription musicpal_key_vmsd =3D { .name =3D "musicpal_key", - .version_id =3D 1, - .minimum_version_id =3D 1, + .version_id =3D 2, + .minimum_version_id =3D 2, .fields =3D (VMStateField[]) { - VMSTATE_UINT32(kbd_extended, musicpal_key_state), VMSTATE_UINT32(pressed_keys, musicpal_key_state), VMSTATE_END_OF_LIST() } @@ -1186,6 +1176,7 @@ static void musicpal_key_class_init(ObjectClass *klas= s, void *data) DeviceClass *dc =3D DEVICE_CLASS(klass); =20 dc->vmsd =3D &musicpal_key_vmsd; + dc->realize =3D musicpal_key_realize; } =20 static const TypeInfo musicpal_key_info =3D { --=20 2.34.1