From patchwork Fri Nov 3 18:27:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 740703 Delivered-To: patch@linaro.org Received: by 2002:a5d:538f:0:b0:32d:baff:b0ca with SMTP id d15csp1543968wrv; Fri, 3 Nov 2023 11:29:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFDnd2MerycZ9p39QHCohTMEngVi6ozMosf2PU/6k20AjbWFy+SPsyhhKIpbcc4VMjysbi2 X-Received: by 2002:a05:620a:3954:b0:779:dc90:ba1d with SMTP id qs20-20020a05620a395400b00779dc90ba1dmr27760439qkn.14.1699036172721; Fri, 03 Nov 2023 11:29:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699036172; cv=none; d=google.com; s=arc-20160816; b=BFDb0MgUs24WM5vmxskyWSo0neOSErjET3kuaG3NIcgYHDUgV7JxSYbpWYY6oHYlgE gYCqfneTY9L3lbg9pBsyYw4syf8dATVHuoZwTMXEjnbRxAe3lhpjN5Wpwjh7vW1yJIZT PdRQy9Bx8HY1xiU6AjoezVZcb7AAFj6Mu3CyXB2kZYAsoiun3wmfV7BwBbYnlT66EGhs E6D8kOLk6od7SVriN2gY5xfhrsqU8eB4gkaDKC+XJEKXF39e+gYfm+5TCigYa+Qljmlb +OLa7eGnXdTsrplenO4phSrI5dKqPC7pHob34U7waxQ61Ju5Pgyi0UwONCgekQTE4VwA ssrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=+EVTungCfjDjTacji5Eqs9/sv58Ra/hS/gF67unlV+M=; fh=v045sp/n/mLZv49zCKO2LE5RLzVm9wU5iQpoO1Uergo=; b=zPYwRfL4eimwOCLGpXAonEb1VWFQHuMJAy9OYBZQdNcfoAfG5h0oo80svhRA/zvhil GBugYlfwZexM0ABKBrAQMGpQQ0AlfRrAPFYkdabgsLs/A/WLROgF9Jwcs5a0wHm5cQoB EI1iZd2QcGCPSXCYHb2yXnyooodC9D+V8+aISYh7DQe1jmr5Nas1vcADmIwLPJNFXrp3 g5zospLQBKwOKIE64z90oLufgmP1/m8FwUd7Ljf5akitA9Qlz4gck1CWbuHtI7VWNekX Zraw/HvY8E0pp8Vks0ULHU2gWsw2XpI6H3eNgE+a2SrN7tN2BLJ4uhnpQ3I/x5KDTshj RyAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=J7blYejo; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id de26-20020a05620a371a00b0077579bb29easi2059358qkb.707.2023.11.03.11.29.32 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 03 Nov 2023 11:29:32 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=J7blYejo; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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) 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-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) 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) 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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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ée Reviewed-by: Alex Bennée --- 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 = { }; /* 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 >*/ - uint32_t kbd_extended; uint32_t pressed_keys; qemu_irq out[8]; }; -static void musicpal_key_event(void *opaque, int keycode) +static void musicpal_key_event(DeviceState *dev, QemuConsole *src, + InputEvent *evt) { - musicpal_key_state *s = opaque; + musicpal_key_state *s = MUSICPAL_KEY(dev); + InputKeyEvent *key = evt->u.key.data; + int qcode = qemu_input_key_value_to_qcode(key->key); uint32_t event = 0; int i; - if (keycode == KEYCODE_EXTENDED) { - s->kbd_extended = 1; - return; + switch (qcode) { + case Q_KEY_CODE_UP: + event = MP_KEY_WHEEL_NAV | MP_KEY_WHEEL_NAV_INV; + break; + + case Q_KEY_CODE_DOWN: + event = MP_KEY_WHEEL_NAV; + break; + + case Q_KEY_CODE_LEFT: + event = MP_KEY_WHEEL_VOL | MP_KEY_WHEEL_VOL_INV; + break; + + case Q_KEY_CODE_RIGHT: + event = MP_KEY_WHEEL_VOL; + break; + + case Q_KEY_CODE_F: + event = MP_KEY_BTN_FAVORITS; + break; + + case Q_KEY_CODE_TAB: + event = MP_KEY_BTN_VOLUME; + break; + + case Q_KEY_CODE_RET: + event = MP_KEY_BTN_NAVIGATION; + break; + + case Q_KEY_CODE_M: + event = MP_KEY_BTN_MENU; + break; } - if (s->kbd_extended) { - switch (keycode & KEY_CODE) { - case KEYCODE_UP: - event = MP_KEY_WHEEL_NAV | MP_KEY_WHEEL_NAV_INV; - break; - - case KEYCODE_DOWN: - event = MP_KEY_WHEEL_NAV; - break; - - case KEYCODE_LEFT: - event = MP_KEY_WHEEL_VOL | MP_KEY_WHEEL_VOL_INV; - break; - - case KEYCODE_RIGHT: - event = MP_KEY_WHEEL_VOL; - break; - } - } else { - switch (keycode & KEY_CODE) { - case KEYCODE_F: - event = MP_KEY_BTN_FAVORITS; - break; - - case KEYCODE_TAB: - event = MP_KEY_BTN_VOLUME; - break; - - case KEYCODE_ENTER: - event = MP_KEY_BTN_NAVIGATION; - break; - - case KEYCODE_M: - event = 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 = 0; } } 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 = 0; i <= 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 keycode) } for (i = 0; i <= 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 &= ~event; - } else { + if (key->down) { s->pressed_keys |= event; + } else { + s->pressed_keys &= ~event; } } - - s->kbd_extended = 0; } static void musicpal_key_init(Object *obj) @@ -1162,20 +1145,27 @@ static void musicpal_key_init(Object *obj) DeviceState *dev = DEVICE(sbd); musicpal_key_state *s = MUSICPAL_KEY(dev); - s->kbd_extended = 0; s->pressed_keys = 0; qdev_init_gpio_out(dev, s->out, ARRAY_SIZE(s->out)); +} - qemu_add_kbd_event_handler(musicpal_key_event, s); +static const QemuInputHandler musicpal_key_handler = { + .name = "musicpal_key", + .mask = INPUT_EVENT_MASK_KEY, + .event = musicpal_key_event, +}; + +static void musicpal_key_realize(DeviceState *dev, Error **errp) +{ + qemu_input_handler_register(dev, &musicpal_key_handler); } static const VMStateDescription musicpal_key_vmsd = { .name = "musicpal_key", - .version_id = 1, - .minimum_version_id = 1, + .version_id = 2, + .minimum_version_id = 2, .fields = (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 *klass, void *data) DeviceClass *dc = DEVICE_CLASS(klass); dc->vmsd = &musicpal_key_vmsd; + dc->realize = musicpal_key_realize; } static const TypeInfo musicpal_key_info = {