From nobody Sun Nov 24 07:23:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=ilande.co.uk Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1725313153820223.8061590310939; Mon, 2 Sep 2024 14:39:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1slEkw-0003gP-4G; Mon, 02 Sep 2024 17:38:39 -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 1slEkr-0003fp-J5 for qemu-devel@nongnu.org; Mon, 02 Sep 2024 17:38:33 -0400 Received: from mail.ilande.co.uk ([2001:41c9:1:41f::167]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1slEkp-0007r0-UC for qemu-devel@nongnu.org; Mon, 02 Sep 2024 17:38:33 -0400 Received: from [2a00:23c4:8bb4:4000:fb99:dbc7:e0ba:aaf] (helo=localhost.localdomain) by mail.ilande.co.uk with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1slEkQ-000CDb-Ih; Mon, 02 Sep 2024 22:38:10 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=ilande.co.uk; s=20220518; h=Subject:Content-Transfer-Encoding:MIME-Version: Message-Id:Date:To:From:Sender:Reply-To:Cc:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References; bh=IHF8QA3Jkd4+btstC28ShQHVtDlsS4RsqKVOSDbRhMc=; b=zb5/WcBaShJktANAh6ogQGb+QU KMmY/UarGi/lKB/oL68vMsqbR5thQsQY51KqSDjBBsG71uh332RjgSyxAXSf8tokJtsFfM3Z1nL6b gMXWGn6JEBguQs7Ac94qoRXbX8wxrzAaz5Jr/f8+YxIgQUxY6fqkvFUzH1zCKpJZOOuIvy9coIni1 ltzMCHnwlItOelqr9D1hj7oMB/ColX6xELVS4nf36ReQeS5N8HR0u70TVbc4/BNmqDOHuwNBK5TQk c2aDsFYzovMd5SssUO074mjKhKwzbHHWuMRagB5/pfbyyGoa1P28vtgqqMQ1ykagJILx44IHc1Qru FM42Q56rRcXCtElUU98BHnMrslBIcCBf+UZHoM+YMMkACzoNc5Mmi9KM9IR/1pvarJBcH+TU+w2yp Z6vdbT9zgjj+hP8LCymyFH/lPMZ8wvcnhCmpsUmpPIQ+52Cyw/+hOwyFIEYrXf8PSEkLvTrw3Mj/T P64ccgk/Hv7iZBMc8YlxuvDaRWG3Br9UQkOySSoJAzbG2Mrg4mml7x9QrmOKeVhPfTKrWHPlsU+13 IoCFRUaVng4ZBHZk0h2eDNSLo9KxtO2O/+Y5YR3LNHM1rHDkYMboK29wAG6aUsqVn79ZeUR7aJlhG 30jUAdbR9Gi35xLXTMujWvdHvY2wq/qbVYh5MWW9g=; From: Mark Cave-Ayland To: chauser@pullman.com, marcandre.lureau@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org Date: Mon, 2 Sep 2024 22:38:16 +0100 Message-Id: <20240902213816.89071-1-mark.cave-ayland@ilande.co.uk> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a00:23c4:8bb4:4000:fb99:dbc7:e0ba:aaf X-SA-Exim-Mail-From: mark.cave-ayland@ilande.co.uk Subject: [PATCH] escc: convert Sun mouse to use QemuInputHandler X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on mail.ilande.co.uk) 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=2001:41c9:1:41f::167; envelope-from=mark.cave-ayland@ilande.co.uk; helo=mail.ilande.co.uk 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, 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: fail (Header signature does not verify) X-ZM-MESSAGEID: 1725313156603116600 Content-Type: text/plain; charset="utf-8" Update the Sun mouse implementation to use QemuInputHandler instead of the legacy qemu_add_mouse_event_handler() function. Note that this conversion adds extra sunmouse_* members to ESCCChannelState but they are not added to the migration stream (similar to the Sun keyboard members). If this were desired in future, the Sun devices should be split into separate devices and added to the migration stream there instead. Signed-off-by: Mark Cave-Ayland Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2518 --- hw/char/escc.c | 79 ++++++++++++++++++++++++++++++------------ include/hw/char/escc.h | 3 ++ roms/seabios | 2 +- 3 files changed, 60 insertions(+), 24 deletions(-) diff --git a/hw/char/escc.c b/hw/char/escc.c index d450d70eda..6d4e3e3350 100644 --- a/hw/char/escc.c +++ b/hw/char/escc.c @@ -287,6 +287,7 @@ static void escc_reset_chn(ESCCChannelState *s) s->rxint =3D s->txint =3D 0; s->rxint_under_svc =3D s->txint_under_svc =3D 0; s->e0_mode =3D s->led_mode =3D s->caps_lock_mode =3D s->num_lock_mode = =3D 0; + s->sunmouse_dx =3D s->sunmouse_dy =3D s->sunmouse_buttons =3D 0; clear_queue(s); } =20 @@ -952,53 +953,85 @@ static void handle_kbd_command(ESCCChannelState *s, i= nt val) } } =20 -static void sunmouse_event(void *opaque, - int dx, int dy, int dz, int buttons_state) +static void sunmouse_handle_event(DeviceState *dev, QemuConsole *src, + InputEvent *evt) { - ESCCChannelState *s =3D opaque; - int ch; + ESCCChannelState *s =3D (ESCCChannelState *)dev; + InputMoveEvent *move; + InputBtnEvent *btn; + static const int bmap[INPUT_BUTTON__MAX] =3D { + [INPUT_BUTTON_LEFT] =3D 0x4, + [INPUT_BUTTON_MIDDLE] =3D 0x2, + [INPUT_BUTTON_RIGHT] =3D 0x1, + [INPUT_BUTTON_SIDE] =3D 0x0, + [INPUT_BUTTON_EXTRA] =3D 0x0, + }; + + switch (evt->type) { + case INPUT_EVENT_KIND_REL: + move =3D evt->u.rel.data; + if (move->axis =3D=3D INPUT_AXIS_X) { + s->sunmouse_dx +=3D move->value; + } else if (move->axis =3D=3D INPUT_AXIS_Y) { + s->sunmouse_dy -=3D move->value; + } + break; =20 - trace_escc_sunmouse_event(dx, dy, buttons_state); - ch =3D 0x80 | 0x7; /* protocol start byte, no buttons pressed */ + case INPUT_EVENT_KIND_BTN: + btn =3D evt->u.btn.data; + if (btn->down) { + s->sunmouse_buttons |=3D bmap[btn->button]; + } else { + s->sunmouse_buttons &=3D ~bmap[btn->button]; + } + break; =20 - if (buttons_state & MOUSE_EVENT_LBUTTON) { - ch ^=3D 0x4; - } - if (buttons_state & MOUSE_EVENT_MBUTTON) { - ch ^=3D 0x2; - } - if (buttons_state & MOUSE_EVENT_RBUTTON) { - ch ^=3D 0x1; + default: + /* keep gcc happy */ + break; } +} =20 - put_queue(s, ch); +static void sunmouse_sync(DeviceState *dev) +{ + ESCCChannelState *s =3D (ESCCChannelState *)dev; + int ch; =20 - ch =3D dx; + trace_escc_sunmouse_event(s->sunmouse_dx, s->sunmouse_dy, 0); + ch =3D 0x80 | 0x7; /* protocol start byte, no buttons pressed */ + ch ^=3D s->sunmouse_buttons; + put_queue(s, ch); =20 + ch =3D s->sunmouse_dx; if (ch > 127) { ch =3D 127; } else if (ch < -127) { ch =3D -127; } - put_queue(s, ch & 0xff); + s->sunmouse_dx =3D 0; =20 - ch =3D -dy; - + ch =3D s->sunmouse_dy; if (ch > 127) { ch =3D 127; } else if (ch < -127) { ch =3D -127; } - put_queue(s, ch & 0xff); + s->sunmouse_dy =3D 0; =20 /* MSC protocol specifies two extra motion bytes */ - put_queue(s, 0); put_queue(s, 0); } =20 +static const QemuInputHandler sunmouse_handler =3D { + .name =3D "QEMU Sun Mouse", + .mask =3D INPUT_EVENT_MASK_BTN | INPUT_EVENT_MASK_REL, + .event =3D sunmouse_handle_event, + .sync =3D sunmouse_sync, +}; + static void escc_init1(Object *obj) { ESCCState *s =3D ESCC(obj); @@ -1036,8 +1069,8 @@ static void escc_realize(DeviceState *dev, Error **er= rp) } =20 if (s->chn[0].type =3D=3D escc_mouse) { - qemu_add_mouse_event_handler(sunmouse_event, &s->chn[0], 0, - "QEMU Sun Mouse"); + s->chn[0].hs =3D qemu_input_handler_register((DeviceState *)(&s->c= hn[0]), + &sunmouse_handler); } if (s->chn[1].type =3D=3D escc_kbd) { s->chn[1].hs =3D qemu_input_handler_register((DeviceState *)(&s->c= hn[1]), diff --git a/include/hw/char/escc.h b/include/hw/char/escc.h index 5669a5b811..8c4c6a7730 100644 --- a/include/hw/char/escc.h +++ b/include/hw/char/escc.h @@ -46,6 +46,9 @@ typedef struct ESCCChannelState { uint8_t rx, tx; QemuInputHandlerState *hs; char *sunkbd_layout; + int sunmouse_dx; + int sunmouse_dy; + int sunmouse_buttons; } ESCCChannelState; =20 struct ESCCState { diff --git a/roms/seabios b/roms/seabios index a6ed6b701f..7d0c606870 160000 --- a/roms/seabios +++ b/roms/seabios @@ -1 +1 @@ -Subproject commit a6ed6b701f0a57db0569ab98b0661c12a6ec3ff8 +Subproject commit 7d0c6068703eae9f2498be0c900ab95b25b4f07a --=20 2.39.2