From nobody Tue Nov 26 17:22:58 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=1706279896; cv=none; d=zohomail.com; s=zohoarc; b=in7sgI+jYDAkItIt5NS1PFIzyunoCgpxqvztEhtO75vEP8Eekp9RRaC9pJht64Tch+5JlwTnTfoj8tINFYjazAujsglmdKZy9hvVevxaVgsZWoFZTdDQkYwM+6m5Soq7X2gcMnhUdBRo3Uv7XFnmsqa51KvkmxduhFuyoeoMGoI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706279896; h=Content-Type:Content-Transfer-Encoding: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:Cc; bh=FgvQRpsiH5zpwPcK6Oo54VoqD9iaIo5i9dZssiG51CE=; b=V3lF0ESpx4LCbU2lRIzlPc5DIeziKlN+w0lFzYrE6DXLAztjnxl4tEdYLSm9/9v5MQRBEnJddGDXEu/ALje3Nyyrbn4eSADviO5cNwzjvZE6lGLBAR23d+JeUmU27FUgS5m8Rhi19waA0vkiysEAzTZL9z+eKGG4bAxiKxkGj+Q= 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 170627989663893.91613949574901; Fri, 26 Jan 2024 06:38:16 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rTNHG-0002IP-4O; Fri, 26 Jan 2024 09:33:54 -0500 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 1rTNHB-0002EB-5z for qemu-devel@nongnu.org; Fri, 26 Jan 2024 09:33:49 -0500 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rTNH7-0007rd-Tq for qemu-devel@nongnu.org; Fri, 26 Jan 2024 09:33:48 -0500 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-337d58942c9so555691f8f.0 for ; Fri, 26 Jan 2024 06:33:45 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id n5-20020a5d4845000000b00337f722e5ccsm1396207wrs.65.2024.01.26.06.33.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 06:33:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1706279624; x=1706884424; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=FgvQRpsiH5zpwPcK6Oo54VoqD9iaIo5i9dZssiG51CE=; b=SBT0neLZXMm6RIAHCneBrK+3iSFKpED/GNJ6I53FKKgvcVSNmQjbmfFzdW9YfDn1ig vVo/UYYBJrTmcl6QOO7vmYmaXipN2mKOPWnl3Sbt8Qh3yf7JxrjL+Fe1Iv9TeRiUXOZt Kw00J2HTJ/BllhdTz9DfswhEKPWQnYefSD7Yy7hRXNPBq1lEZQoYatSsMULHVYVeTzjR C3+XhNeeOSnKjd9508SAzNLXkeCK+lHVLBeM43/aZBsdb2muIv3BfZLoJHIalpxbUGQM pIfeUeUQgY8vCtYNUGAV18Ia0xxvBwHtgUZpRtyzng3Zc8OvDSjOAIbJgPa9xdE7+VDt eE0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706279624; x=1706884424; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FgvQRpsiH5zpwPcK6Oo54VoqD9iaIo5i9dZssiG51CE=; b=F1muW7fU+fgXWbG1SN+yKIfJGWNbNKoYOXEnb1d/yiwvEE7Lho+U8Td1t1ecLf/5w1 RUlCQceMciPolKUPfFQ/EZ4slm+efzgOt1UgpNlOB1DTjsxF8Hlthl3Ylk3wDGuqSPVl EYgthv5z1hCd0tUTT6KD3XbRP522embUKSK50roJuvtAn9oYYvlb41zPpGrwo0kF7Clc 2BruudnlERm1O+DtV0NQRYE7RJesXTceTlR+AnJNkI9o4jOdN9/UEPsXUhayMMdQotnb Tq1r00eUry1YiRds5HcytnO39J223ROWZKMvHjUVg7Qhga6mv1dNW4x+TLMUuXRUJWro u0Ww== X-Gm-Message-State: AOJu0YzpDu64b6yszwfC/JnRtAsyfcXrd6qzPKWdMctX5ie5AqjM0ChH loIFfZXbG+lJnVTwHVVvi4D8Mqf5H7FUWwKnbGer4oCYOsmsiQ9EwiHrLk2OXKiR1Zn+2PL7sP2 5 X-Google-Smtp-Source: AGHT+IFuCtCIzduHGzT+leX+t2nOW3aINUptU1puokYYACpjBbX/lgvHiQpLqBo0DkjT9iVgWo+bwA== X-Received: by 2002:a5d:6687:0:b0:332:eaa7:56b0 with SMTP id l7-20020a5d6687000000b00332eaa756b0mr1031839wru.14.1706279624343; Fri, 26 Jan 2024 06:33:44 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 04/36] hw/arm/musicpal: Convert to qemu_add_kbd_event_handler() Date: Fri, 26 Jan 2024 14:33:09 +0000 Message-Id: <20240126143341.2101237-5-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240126143341.2101237-1-peter.maydell@linaro.org> References: <20240126143341.2101237-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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::432; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x432.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: 1706279897055100001 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 Tested-by: Alex Benn=C3=A9e Reviewed-by: Alex Benn=C3=A9e Message-id: 20231103182750.855577-1-peter.maydell@linaro.org --- 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 3200c9f68ac..6987472871e 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 (const 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