From nobody Tue Feb 10 20:49:34 2026 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 1656078577434865.3464801571924; Fri, 24 Jun 2022 06:49:37 -0700 (PDT) Received: from localhost ([::1]:55124 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o4jgm-00083r-7e for importer@patchew.org; Fri, 24 Jun 2022 09:49:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37858) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4jZ4-0007A0-SY; Fri, 24 Jun 2022 09:41:38 -0400 Received: from mail.ilande.co.uk ([2001:41c9:1:41f::167]:41604) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4jZ0-00054B-98; Fri, 24 Jun 2022 09:41:37 -0400 Received: from [2a00:23c4:8ba4:e500:b82f:56f9:46d7:80ab] (helo=kentang.home) by mail.ilande.co.uk with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o4jXg-00037t-OI; Fri, 24 Jun 2022 14:40:16 +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:Content-Type: MIME-Version:References:In-Reply-To:Message-Id:Date:To:From:Sender:Reply-To: Cc:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=mvAJZ4P5Q1iTQxoa3SmGf3mWyoKSkskxl1Q/JBJZB9I=; b=hOGBR4QzebBIemSFl4nKcIyouB 0MKrveDmekyIHhe8+paYJVkgGyqVBWmooPFFMcALszRNn0evk+aZe2K3Oh81M7N0y91PoCK8JdK8T AUqUHfkFIFNNFsOG3X+aKfYJzkTaOzY7eWVyGs0UwVmdegXza3/OfNNQMb6+5+V+YvRXOIdbRTfDm VxOKhMOEuHuy089gozV1zPY2s8g0lAaEpj1Pd/DeIkRxh1KPiiEaUk7NUpte+suqJ4Uf/eiJmwEkc Zt92OXc6eJyYps4LFYseVmfDbqB8QG5vdfKFZetzLlgst97I3rLAulqd/r9EGKNIp46UO2ONObdZB +wZ0dR5rSp3faMz/vn186ae8fyZObyBBT5hXRCOJzhuv6n2RzT8z2BoDKA1c7zMqoVC4hXDmhrMNj g5+07IvpxjdY0JMa5nNeVyFAKXSFr7foD6L+5McY+Bl6p+gvqFeSVRlvxYGZIXj89GH8Xf97XfT13 k11MR2BP5ZGXO+TS5Lmibu7D61kE7XjQNakfH/vSVPE6qaZshwjwD6z/SZNeQCZ4L+oN3YHPepFPu Gw+O2IJ80plxb0xQIjNToB3W9fWI99CVo69mHXyG9Pj8MT8bwKeiB5DEPP3EMiL4+5VeYtli6VA7S 8LbvjoefoHuA7QYIzzJHf5NWkzOws4ToYkx2tuIXc=; From: Mark Cave-Ayland To: richard.henderson@linaro.org, deller@gmx.de, mst@redhat.com, pbonzini@redhat.com, peter.maydell@linaro.org, hpoussin@reactos.org, aleksandar.rikalo@syrmia.com, f4bug@amsat.org, jiaxun.yang@flygoat.com, qemu-arm@nongnu.org, qemu-devel@nongnu.org Date: Fri, 24 Jun 2022 14:40:18 +0100 Message-Id: <20220624134109.881989-4-mark.cave-ayland@ilande.co.uk> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220624134109.881989-1-mark.cave-ayland@ilande.co.uk> References: <20220624134109.881989-1-mark.cave-ayland@ilande.co.uk> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a00:23c4:8ba4:e500:b82f:56f9:46d7:80ab X-SA-Exim-Mail-From: mark.cave-ayland@ilande.co.uk Subject: [PATCH v2 03/54] ps2: QOMify PS2KbdState 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" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1656078579221100001 Make PS2KbdState into a new PS2_KBD_DEVICE QOM type which inherits from the abstract PS2_DEVICE type. Signed-off-by: Mark Cave-Ayland Reviewed-by: Philippe Mathieu-Daud=C3=A9 Acked-by: Helge Deller --- hw/input/ps2.c | 104 ++++++++++++++++++++++++++++++------------------- 1 file changed, 65 insertions(+), 39 deletions(-) diff --git a/hw/input/ps2.c b/hw/input/ps2.c index 514e55cbb6..14eb777c3f 100644 --- a/hw/input/ps2.c +++ b/hw/input/ps2.c @@ -31,6 +31,7 @@ #include "ui/input.h" #include "sysemu/reset.h" #include "sysemu/runstate.h" +#include "qapi/error.h" =20 #include "trace.h" =20 @@ -108,15 +109,19 @@ struct PS2State { #define TYPE_PS2_DEVICE "ps2-device" OBJECT_DECLARE_SIMPLE_TYPE(PS2State, PS2_DEVICE) =20 -typedef struct { - PS2State common; +struct PS2KbdState { + PS2State parent_obj; + int scan_enabled; int translate; int scancode_set; /* 1=3DXT, 2=3DAT, 3=3DPS/2 */ int ledstate; bool need_high_bit; unsigned int modifiers; /* bitmask of MOD_* constants above */ -} PS2KbdState; +}; + +#define TYPE_PS2_KBD_DEVICE "ps2-kbd" +OBJECT_DECLARE_SIMPLE_TYPE(PS2KbdState, PS2_KBD_DEVICE) =20 typedef struct { PS2State common; @@ -330,6 +335,7 @@ static void ps2_cqueue_reset(PS2State *s) static void ps2_put_keycode(void *opaque, int keycode) { PS2KbdState *s =3D opaque; + PS2State *ps =3D PS2_DEVICE(s); =20 trace_ps2_put_keycode(opaque, keycode); qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER, NULL); @@ -338,13 +344,13 @@ static void ps2_put_keycode(void *opaque, int keycode) if (keycode =3D=3D 0xf0) { s->need_high_bit =3D true; } else if (s->need_high_bit) { - ps2_queue(&s->common, translate_table[keycode] | 0x80); + ps2_queue(ps, translate_table[keycode] | 0x80); s->need_high_bit =3D false; } else { - ps2_queue(&s->common, translate_table[keycode]); + ps2_queue(ps, translate_table[keycode]); } } else { - ps2_queue(&s->common, keycode); + ps2_queue(ps, keycode); } } =20 @@ -617,96 +623,99 @@ static void ps2_set_ledstate(PS2KbdState *s, int leds= tate) =20 static void ps2_reset_keyboard(PS2KbdState *s) { + PS2State *ps2 =3D PS2_DEVICE(s); + trace_ps2_reset_keyboard(s); s->scan_enabled =3D 1; s->scancode_set =3D 2; - ps2_reset_queue(&s->common); + ps2_reset_queue(ps2); ps2_set_ledstate(s, 0); } =20 void ps2_write_keyboard(void *opaque, int val) { PS2KbdState *s =3D (PS2KbdState *)opaque; + PS2State *ps2 =3D PS2_DEVICE(s); =20 trace_ps2_write_keyboard(opaque, val); - ps2_cqueue_reset(&s->common); - switch (s->common.write_cmd) { + ps2_cqueue_reset(ps2); + switch (ps2->write_cmd) { default: case -1: switch (val) { case 0x00: - ps2_cqueue_1(&s->common, KBD_REPLY_ACK); + ps2_cqueue_1(ps2, KBD_REPLY_ACK); break; case 0x05: - ps2_cqueue_1(&s->common, KBD_REPLY_RESEND); + ps2_cqueue_1(ps2, KBD_REPLY_RESEND); break; case KBD_CMD_GET_ID: /* We emulate a MF2 AT keyboard here */ - ps2_cqueue_3(&s->common, KBD_REPLY_ACK, KBD_REPLY_ID, + ps2_cqueue_3(ps2, KBD_REPLY_ACK, KBD_REPLY_ID, s->translate ? 0x41 : 0x83); break; case KBD_CMD_ECHO: - ps2_cqueue_1(&s->common, KBD_CMD_ECHO); + ps2_cqueue_1(ps2, KBD_CMD_ECHO); break; case KBD_CMD_ENABLE: s->scan_enabled =3D 1; - ps2_cqueue_1(&s->common, KBD_REPLY_ACK); + ps2_cqueue_1(ps2, KBD_REPLY_ACK); break; case KBD_CMD_SCANCODE: case KBD_CMD_SET_LEDS: case KBD_CMD_SET_RATE: case KBD_CMD_SET_MAKE_BREAK: - s->common.write_cmd =3D val; - ps2_cqueue_1(&s->common, KBD_REPLY_ACK); + ps2->write_cmd =3D val; + ps2_cqueue_1(ps2, KBD_REPLY_ACK); break; case KBD_CMD_RESET_DISABLE: ps2_reset_keyboard(s); s->scan_enabled =3D 0; - ps2_cqueue_1(&s->common, KBD_REPLY_ACK); + ps2_cqueue_1(ps2, KBD_REPLY_ACK); break; case KBD_CMD_RESET_ENABLE: ps2_reset_keyboard(s); s->scan_enabled =3D 1; - ps2_cqueue_1(&s->common, KBD_REPLY_ACK); + ps2_cqueue_1(ps2, KBD_REPLY_ACK); break; case KBD_CMD_RESET: ps2_reset_keyboard(s); - ps2_cqueue_2(&s->common, + ps2_cqueue_2(ps2, KBD_REPLY_ACK, KBD_REPLY_POR); break; case KBD_CMD_SET_TYPEMATIC: - ps2_cqueue_1(&s->common, KBD_REPLY_ACK); + ps2_cqueue_1(ps2, KBD_REPLY_ACK); break; default: - ps2_cqueue_1(&s->common, KBD_REPLY_RESEND); + ps2_cqueue_1(ps2, KBD_REPLY_RESEND); break; } break; case KBD_CMD_SET_MAKE_BREAK: - ps2_cqueue_1(&s->common, KBD_REPLY_ACK); - s->common.write_cmd =3D -1; + ps2_cqueue_1(ps2, KBD_REPLY_ACK); + ps2->write_cmd =3D -1; break; case KBD_CMD_SCANCODE: if (val =3D=3D 0) { - ps2_cqueue_2(&s->common, KBD_REPLY_ACK, s->translate ? + ps2_cqueue_2(ps2, KBD_REPLY_ACK, s->translate ? translate_table[s->scancode_set] : s->scancode_set); } else if (val >=3D 1 && val <=3D 3) { s->scancode_set =3D val; - ps2_cqueue_1(&s->common, KBD_REPLY_ACK); + ps2_cqueue_1(ps2, KBD_REPLY_ACK); } else { - ps2_cqueue_1(&s->common, KBD_REPLY_RESEND); + ps2_cqueue_1(ps2, KBD_REPLY_RESEND); } - s->common.write_cmd =3D -1; + ps2->write_cmd =3D -1; break; case KBD_CMD_SET_LEDS: ps2_set_ledstate(s, val); - ps2_cqueue_1(&s->common, KBD_REPLY_ACK); - s->common.write_cmd =3D -1; + ps2_cqueue_1(ps2, KBD_REPLY_ACK); + ps2->write_cmd =3D -1; break; case KBD_CMD_SET_RATE: - ps2_cqueue_1(&s->common, KBD_REPLY_ACK); - s->common.write_cmd =3D -1; + ps2_cqueue_1(ps2, KBD_REPLY_ACK); + ps2->write_cmd =3D -1; break; } } @@ -1075,9 +1084,10 @@ static void ps2_common_post_load(PS2State *s) static void ps2_kbd_reset(void *opaque) { PS2KbdState *s =3D (PS2KbdState *) opaque; + PS2State *ps2 =3D PS2_DEVICE(s); =20 trace_ps2_kbd_reset(opaque); - ps2_common_reset(&s->common); + ps2_common_reset(ps2); s->scan_enabled =3D 1; s->translate =3D 0; s->scancode_set =3D 2; @@ -1164,15 +1174,16 @@ static const VMStateDescription vmstate_ps2_keyboar= d_need_high_bit =3D { static bool ps2_keyboard_cqueue_needed(void *opaque) { PS2KbdState *s =3D opaque; + PS2State *ps2 =3D PS2_DEVICE(s); =20 - return s->common.queue.cwptr !=3D -1; /* the queue is mostly empty */ + return ps2->queue.cwptr !=3D -1; /* the queue is mostly empty */ } =20 static const VMStateDescription vmstate_ps2_keyboard_cqueue =3D { .name =3D "ps2kbd/command_reply_queue", .needed =3D ps2_keyboard_cqueue_needed, .fields =3D (VMStateField[]) { - VMSTATE_INT32(common.queue.cwptr, PS2KbdState), + VMSTATE_INT32(parent_obj.queue.cwptr, PS2KbdState), VMSTATE_END_OF_LIST() } }; @@ -1180,7 +1191,7 @@ static const VMStateDescription vmstate_ps2_keyboard_= cqueue =3D { static int ps2_kbd_post_load(void *opaque, int version_id) { PS2KbdState *s =3D (PS2KbdState *)opaque; - PS2State *ps2 =3D &s->common; + PS2State *ps2 =3D PS2_DEVICE(s); =20 if (version_id =3D=3D 2) { s->scancode_set =3D 2; @@ -1197,7 +1208,8 @@ static const VMStateDescription vmstate_ps2_keyboard = =3D { .minimum_version_id =3D 2, .post_load =3D ps2_kbd_post_load, .fields =3D (VMStateField[]) { - VMSTATE_STRUCT(common, PS2KbdState, 0, vmstate_ps2_common, PS2Stat= e), + VMSTATE_STRUCT(parent_obj, PS2KbdState, 0, vmstate_ps2_common, + PS2State), VMSTATE_INT32(scan_enabled, PS2KbdState), VMSTATE_INT32(translate, PS2KbdState), VMSTATE_INT32_V(scancode_set, PS2KbdState, 3), @@ -1250,11 +1262,18 @@ static QemuInputHandler ps2_keyboard_handler =3D { =20 void *ps2_kbd_init(void (*update_irq)(void *, int), void *update_arg) { - PS2KbdState *s =3D g_new0(PS2KbdState, 1); + DeviceState *dev; + PS2KbdState *s; + PS2State *ps2; + + dev =3D qdev_new(TYPE_PS2_KBD_DEVICE); + sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); + s =3D PS2_KBD_DEVICE(dev); + ps2 =3D PS2_DEVICE(s); =20 trace_ps2_kbd_init(s); - s->common.update_irq =3D update_irq; - s->common.update_arg =3D update_arg; + ps2->update_irq =3D update_irq; + ps2->update_arg =3D update_arg; s->scancode_set =3D 2; vmstate_register(NULL, 0, &vmstate_ps2_keyboard, s); qemu_input_handler_register((DeviceState *)s, @@ -1284,6 +1303,12 @@ void *ps2_mouse_init(void (*update_irq)(void *, int)= , void *update_arg) return s; } =20 +static const TypeInfo ps2_kbd_info =3D { + .name =3D TYPE_PS2_KBD_DEVICE, + .parent =3D TYPE_PS2_DEVICE, + .instance_size =3D sizeof(PS2KbdState), +}; + static void ps2_class_init(ObjectClass *klass, void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); @@ -1302,6 +1327,7 @@ static const TypeInfo ps2_info =3D { static void ps2_register_types(void) { type_register_static(&ps2_info); + type_register_static(&ps2_kbd_info); } =20 type_init(ps2_register_types) --=20 2.30.2