All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
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
Subject: [PATCH v2 04/54] ps2: QOMify PS2MouseState
Date: Fri, 24 Jun 2022 14:40:19 +0100	[thread overview]
Message-ID: <20220624134109.881989-5-mark.cave-ayland@ilande.co.uk> (raw)
In-Reply-To: <20220624134109.881989-1-mark.cave-ayland@ilande.co.uk>

Make PS2MouseState into a new PS2_MOUSE_DEVICE QOM type which inherits from the
abstract PS2_DEVICE type.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Acked-by: Helge Deller <deller@gmx.de>
---
 hw/input/ps2.c | 98 ++++++++++++++++++++++++++++++--------------------
 1 file changed, 60 insertions(+), 38 deletions(-)

diff --git a/hw/input/ps2.c b/hw/input/ps2.c
index 14eb777c3f..ee7c36d4f2 100644
--- a/hw/input/ps2.c
+++ b/hw/input/ps2.c
@@ -123,8 +123,9 @@ struct PS2KbdState {
 #define TYPE_PS2_KBD_DEVICE "ps2-kbd"
 OBJECT_DECLARE_SIMPLE_TYPE(PS2KbdState, PS2_KBD_DEVICE)
 
-typedef struct {
-    PS2State common;
+struct PS2MouseState {
+    PS2State parent_obj;
+
     uint8_t mouse_status;
     uint8_t mouse_resolution;
     uint8_t mouse_sample_rate;
@@ -136,7 +137,10 @@ typedef struct {
     int mouse_dz;
     int mouse_dw;
     uint8_t mouse_buttons;
-} PS2MouseState;
+};
+
+#define TYPE_PS2_MOUSE_DEVICE "ps2-mouse"
+OBJECT_DECLARE_SIMPLE_TYPE(PS2MouseState, PS2_MOUSE_DEVICE)
 
 static uint8_t translate_table[256] = {
     0xff, 0x43, 0x41, 0x3f, 0x3d, 0x3b, 0x3c, 0x58,
@@ -735,12 +739,13 @@ void ps2_keyboard_set_translation(void *opaque, int mode)
 
 static int ps2_mouse_send_packet(PS2MouseState *s)
 {
+    PS2State *ps2 = PS2_DEVICE(s);
     /* IMPS/2 and IMEX send 4 bytes, PS2 sends 3 bytes */
     const int needed = s->mouse_type ? 4 : 3;
     unsigned int b;
     int dx1, dy1, dz1, dw1;
 
-    if (PS2_QUEUE_SIZE - s->common.queue.count < needed) {
+    if (PS2_QUEUE_SIZE - ps2->queue.count < needed) {
         return 0;
     }
 
@@ -760,9 +765,9 @@ static int ps2_mouse_send_packet(PS2MouseState *s)
         dy1 = -127;
     }
     b = 0x08 | ((dx1 < 0) << 4) | ((dy1 < 0) << 5) | (s->mouse_buttons & 0x07);
-    ps2_queue_noirq(&s->common, b);
-    ps2_queue_noirq(&s->common, dx1 & 0xff);
-    ps2_queue_noirq(&s->common, dy1 & 0xff);
+    ps2_queue_noirq(ps2, b);
+    ps2_queue_noirq(ps2, dx1 & 0xff);
+    ps2_queue_noirq(ps2, dy1 & 0xff);
     /* extra byte for IMPS/2 or IMEX */
     switch (s->mouse_type) {
     default:
@@ -776,7 +781,7 @@ static int ps2_mouse_send_packet(PS2MouseState *s)
         } else if (dz1 < -127) {
             dz1 = -127;
         }
-        ps2_queue_noirq(&s->common, dz1 & 0xff);
+        ps2_queue_noirq(ps2, dz1 & 0xff);
         s->mouse_dz -= dz1;
         s->mouse_dw = 0;
         break;
@@ -812,11 +817,11 @@ static int ps2_mouse_send_packet(PS2MouseState *s)
             b = (dz1 & 0x0f) | ((s->mouse_buttons & 0x18) << 1);
             s->mouse_dz -= dz1;
         }
-        ps2_queue_noirq(&s->common, b);
+        ps2_queue_noirq(ps2, b);
         break;
     }
 
-    ps2_raise_irq(&s->common);
+    ps2_raise_irq(ps2);
 
     trace_ps2_mouse_send_packet(s, dx1, dy1, dz1, b);
     /* update deltas */
@@ -918,85 +923,86 @@ void ps2_mouse_fake_event(void *opaque)
 void ps2_write_mouse(void *opaque, int val)
 {
     PS2MouseState *s = (PS2MouseState *)opaque;
+    PS2State *ps2 = PS2_DEVICE(s);
 
     trace_ps2_write_mouse(opaque, val);
-    switch (s->common.write_cmd) {
+    switch (ps2->write_cmd) {
     default:
     case -1:
         /* mouse command */
         if (s->mouse_wrap) {
             if (val == AUX_RESET_WRAP) {
                 s->mouse_wrap = 0;
-                ps2_queue(&s->common, AUX_ACK);
+                ps2_queue(ps2, AUX_ACK);
                 return;
             } else if (val != AUX_RESET) {
-                ps2_queue(&s->common, val);
+                ps2_queue(ps2, val);
                 return;
             }
         }
         switch (val) {
         case AUX_SET_SCALE11:
             s->mouse_status &= ~MOUSE_STATUS_SCALE21;
-            ps2_queue(&s->common, AUX_ACK);
+            ps2_queue(ps2, AUX_ACK);
             break;
         case AUX_SET_SCALE21:
             s->mouse_status |= MOUSE_STATUS_SCALE21;
-            ps2_queue(&s->common, AUX_ACK);
+            ps2_queue(ps2, AUX_ACK);
             break;
         case AUX_SET_STREAM:
             s->mouse_status &= ~MOUSE_STATUS_REMOTE;
-            ps2_queue(&s->common, AUX_ACK);
+            ps2_queue(ps2, AUX_ACK);
             break;
         case AUX_SET_WRAP:
             s->mouse_wrap = 1;
-            ps2_queue(&s->common, AUX_ACK);
+            ps2_queue(ps2, AUX_ACK);
             break;
         case AUX_SET_REMOTE:
             s->mouse_status |= MOUSE_STATUS_REMOTE;
-            ps2_queue(&s->common, AUX_ACK);
+            ps2_queue(ps2, AUX_ACK);
             break;
         case AUX_GET_TYPE:
-            ps2_queue_2(&s->common,
+            ps2_queue_2(ps2,
                 AUX_ACK,
                 s->mouse_type);
             break;
         case AUX_SET_RES:
         case AUX_SET_SAMPLE:
-            s->common.write_cmd = val;
-            ps2_queue(&s->common, AUX_ACK);
+            ps2->write_cmd = val;
+            ps2_queue(ps2, AUX_ACK);
             break;
         case AUX_GET_SCALE:
-            ps2_queue_4(&s->common,
+            ps2_queue_4(ps2,
                 AUX_ACK,
                 s->mouse_status,
                 s->mouse_resolution,
                 s->mouse_sample_rate);
             break;
         case AUX_POLL:
-            ps2_queue(&s->common, AUX_ACK);
+            ps2_queue(ps2, AUX_ACK);
             ps2_mouse_send_packet(s);
             break;
         case AUX_ENABLE_DEV:
             s->mouse_status |= MOUSE_STATUS_ENABLED;
-            ps2_queue(&s->common, AUX_ACK);
+            ps2_queue(ps2, AUX_ACK);
             break;
         case AUX_DISABLE_DEV:
             s->mouse_status &= ~MOUSE_STATUS_ENABLED;
-            ps2_queue(&s->common, AUX_ACK);
+            ps2_queue(ps2, AUX_ACK);
             break;
         case AUX_SET_DEFAULT:
             s->mouse_sample_rate = 100;
             s->mouse_resolution = 2;
             s->mouse_status = 0;
-            ps2_queue(&s->common, AUX_ACK);
+            ps2_queue(ps2, AUX_ACK);
             break;
         case AUX_RESET:
             s->mouse_sample_rate = 100;
             s->mouse_resolution = 2;
             s->mouse_status = 0;
             s->mouse_type = 0;
-            ps2_reset_queue(&s->common);
-            ps2_queue_3(&s->common,
+            ps2_reset_queue(ps2);
+            ps2_queue_3(ps2,
                 AUX_ACK,
                 0xaa,
                 s->mouse_type);
@@ -1037,13 +1043,13 @@ void ps2_write_mouse(void *opaque, int val)
             s->mouse_detect_state = 0;
             break;
         }
-        ps2_queue(&s->common, AUX_ACK);
-        s->common.write_cmd = -1;
+        ps2_queue(ps2, AUX_ACK);
+        ps2->write_cmd = -1;
         break;
     case AUX_SET_RES:
         s->mouse_resolution = val;
-        ps2_queue(&s->common, AUX_ACK);
-        s->common.write_cmd = -1;
+        ps2_queue(ps2, AUX_ACK);
+        ps2->write_cmd = -1;
         break;
     }
 }
@@ -1097,9 +1103,10 @@ static void ps2_kbd_reset(void *opaque)
 static void ps2_mouse_reset(void *opaque)
 {
     PS2MouseState *s = (PS2MouseState *) opaque;
+    PS2State *ps2 = PS2_DEVICE(s);
 
     trace_ps2_mouse_reset(opaque);
-    ps2_common_reset(&s->common);
+    ps2_common_reset(ps2);
     s->mouse_status = 0;
     s->mouse_resolution = 0;
     s->mouse_sample_rate = 0;
@@ -1226,7 +1233,7 @@ static const VMStateDescription vmstate_ps2_keyboard = {
 static int ps2_mouse_post_load(void *opaque, int version_id)
 {
     PS2MouseState *s = (PS2MouseState *)opaque;
-    PS2State *ps2 = &s->common;
+    PS2State *ps2 = PS2_DEVICE(s);
 
     ps2_common_post_load(ps2);
 
@@ -1239,7 +1246,8 @@ static const VMStateDescription vmstate_ps2_mouse = {
     .minimum_version_id = 2,
     .post_load = ps2_mouse_post_load,
     .fields = (VMStateField[]) {
-        VMSTATE_STRUCT(common, PS2MouseState, 0, vmstate_ps2_common, PS2State),
+        VMSTATE_STRUCT(parent_obj, PS2MouseState, 0, vmstate_ps2_common,
+                       PS2State),
         VMSTATE_UINT8(mouse_status, PS2MouseState),
         VMSTATE_UINT8(mouse_resolution, PS2MouseState),
         VMSTATE_UINT8(mouse_sample_rate, PS2MouseState),
@@ -1291,11 +1299,18 @@ static QemuInputHandler ps2_mouse_handler = {
 
 void *ps2_mouse_init(void (*update_irq)(void *, int), void *update_arg)
 {
-    PS2MouseState *s = g_new0(PS2MouseState, 1);
+    DeviceState *dev;
+    PS2MouseState *s;
+    PS2State *ps2;
+
+    dev = qdev_new(TYPE_PS2_MOUSE_DEVICE);
+    sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
+    s = PS2_MOUSE_DEVICE(dev);
+    ps2 = PS2_DEVICE(s);
 
     trace_ps2_mouse_init(s);
-    s->common.update_irq = update_irq;
-    s->common.update_arg = update_arg;
+    ps2->update_irq = update_irq;
+    ps2->update_arg = update_arg;
     vmstate_register(NULL, 0, &vmstate_ps2_mouse, s);
     qemu_input_handler_register((DeviceState *)s,
                                 &ps2_mouse_handler);
@@ -1309,6 +1324,12 @@ static const TypeInfo ps2_kbd_info = {
     .instance_size = sizeof(PS2KbdState),
 };
 
+static const TypeInfo ps2_mouse_info = {
+    .name          = TYPE_PS2_MOUSE_DEVICE,
+    .parent        = TYPE_PS2_DEVICE,
+    .instance_size = sizeof(PS2MouseState),
+};
+
 static void ps2_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
@@ -1328,6 +1349,7 @@ static void ps2_register_types(void)
 {
     type_register_static(&ps2_info);
     type_register_static(&ps2_kbd_info);
+    type_register_static(&ps2_mouse_info);
 }
 
 type_init(ps2_register_types)
-- 
2.30.2



  parent reply	other threads:[~2022-06-24 13:50 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-24 13:40 [PATCH v2 00/54] PS2 device QOMification - part 1 Mark Cave-Ayland
2022-06-24 13:40 ` [PATCH v2 01/54] ps2: checkpatch fixes Mark Cave-Ayland
2022-06-24 13:40 ` [PATCH v2 02/54] ps2: QOMify PS2State Mark Cave-Ayland
2022-06-24 13:40 ` [PATCH v2 03/54] ps2: QOMify PS2KbdState Mark Cave-Ayland
2022-06-24 13:40 ` Mark Cave-Ayland [this message]
2022-06-24 13:40 ` [PATCH v2 05/54] ps2: move QOM type definitions from ps2.c to ps2.h Mark Cave-Ayland
2022-06-24 13:40 ` [PATCH v2 06/54] ps2: improve function prototypes in ps2.c and ps2.h Mark Cave-Ayland
2022-06-24 13:40 ` [PATCH v2 07/54] ps2: introduce PS2DeviceClass Mark Cave-Ayland
2022-06-24 13:40 ` [PATCH v2 08/54] ps2: implement ps2_reset() for the PS2_DEVICE QOM type based upon ps2_common_reset() Mark Cave-Ayland
2022-06-24 13:40 ` [PATCH v2 09/54] ps2: remove duplicate setting of scancode_set in ps2_kbd_init() Mark Cave-Ayland
2022-06-24 13:40 ` [PATCH v2 10/54] ps2: implement ps2_kbd_realize() and use it to register ps2_keyboard_handler Mark Cave-Ayland
2022-06-24 13:40 ` [PATCH v2 11/54] ps2: implement ps2_mouse_realize() and use it to register ps2_mouse_handler Mark Cave-Ayland
2022-06-24 13:40 ` [PATCH v2 12/54] ps2: don't use vmstate_register() in ps2_kbd_init() Mark Cave-Ayland
2022-06-24 13:40 ` [PATCH v2 13/54] ps2: don't use vmstate_register() in ps2_mouse_init() Mark Cave-Ayland
2022-06-24 13:40 ` [PATCH v2 14/54] pl050: checkpatch fixes Mark Cave-Ayland
2022-06-24 13:40 ` [PATCH v2 15/54] pl050: split pl050_update_irq() into separate pl050_set_irq() and pl050_update_irq() functions Mark Cave-Ayland
2022-06-24 13:40 ` [PATCH v2 16/54] lasips2: spacing fixes Mark Cave-Ayland
2022-06-24 13:40 ` [PATCH v2 17/54] lasips2: rename ps2dev_update_irq() to lasips2_port_set_irq() Mark Cave-Ayland
2022-06-24 13:40 ` [PATCH v2 18/54] pckbd: checkpatch fixes Mark Cave-Ayland
2022-06-24 13:40 ` [PATCH v2 19/54] pckbd: move KBDState from pckbd.c to i8042.h Mark Cave-Ayland
2022-06-24 13:40 ` [PATCH v2 20/54] pckbd: move ISAKBDState " Mark Cave-Ayland
2022-06-24 13:40 ` [PATCH v2 21/54] pckbd: introduce new I8042_MMIO QOM type Mark Cave-Ayland
2022-06-24 13:40 ` [PATCH v2 22/54] pckbd: implement i8042_mmio_reset() for I8042_MMIO device Mark Cave-Ayland
2022-06-24 15:07   ` Peter Maydell
2022-06-24 13:40 ` [PATCH v2 23/54] pckbd: add mask qdev property to " Mark Cave-Ayland
2022-06-24 13:40 ` [PATCH v2 24/54] pckbd: add size " Mark Cave-Ayland
2022-06-24 13:40 ` [PATCH v2 25/54] pckbd: implement i8042_mmio_realize() function Mark Cave-Ayland
2022-06-24 13:40 ` [PATCH v2 26/54] pckbd: implement i8042_mmio_init() function Mark Cave-Ayland
2022-06-24 15:07   ` Peter Maydell
2022-06-24 13:40 ` [PATCH v2 27/54] pckbd: alter i8042_mm_init() to return a I8042_MMIO device Mark Cave-Ayland
2022-06-24 13:40 ` [PATCH v2 28/54] pckbd: move mapping of I8042_MMIO registers to MIPS magnum machine Mark Cave-Ayland
2022-06-24 13:40 ` [PATCH v2 29/54] pckbd: more vmstate_register() from i8042_mm_init() to i8042_mmio_realize() Mark Cave-Ayland
2022-06-24 15:07   ` Peter Maydell
2022-06-24 13:40 ` [PATCH v2 30/54] pckbd: move ps2_kbd_init() and ps2_mouse_init() " Mark Cave-Ayland
2022-06-24 13:40 ` [PATCH v2 31/54] ps2: make ps2_raise_irq() function static Mark Cave-Ayland
2022-06-24 13:40 ` [PATCH v2 32/54] ps2: use ps2_raise_irq() instead of calling update_irq() directly Mark Cave-Ayland
2022-06-24 13:40 ` [PATCH v2 33/54] ps2: introduce ps2_lower_irq() " Mark Cave-Ayland
2022-06-24 13:40 ` [PATCH v2 34/54] ps2: add gpio for output IRQ and optionally use it in ps2_raise_irq() and ps2_lower_irq() Mark Cave-Ayland
2022-06-24 13:40 ` [PATCH v2 35/54] pckbd: replace irq_kbd and irq_mouse with qemu_irq array in KBDState Mark Cave-Ayland
2022-06-24 13:40 ` [PATCH v2 36/54] pl050: switch over from update_irq() function to PS2 device gpio Mark Cave-Ayland
2022-06-24 15:08   ` Peter Maydell
2022-06-24 13:40 ` [PATCH v2 37/54] pl050: add QEMU interface comment Mark Cave-Ayland
2022-06-24 15:08   ` Peter Maydell
2022-06-24 13:40 ` [PATCH v2 38/54] lasips2: QOMify LASIPS2State Mark Cave-Ayland
2022-06-24 13:40 ` [PATCH v2 39/54] lasips2: move lasips2 QOM types from lasips2.c to lasips2.h Mark Cave-Ayland
2022-06-24 13:40 ` [PATCH v2 40/54] lasips2: rename lasips2_init() to lasips2_initfn() and update it to return the LASIPS2 device Mark Cave-Ayland
2022-06-24 13:40 ` [PATCH v2 41/54] lasips2: implement lasips2_init() function Mark Cave-Ayland
2022-06-24 13:40 ` [PATCH v2 42/54] lasips2: move mapping of LASIPS2 registers to HPPA machine Mark Cave-Ayland
2022-06-24 13:40 ` [PATCH v2 43/54] lasips2: move initialisation of PS2 ports from lasi_initfn() to lasi_init() Mark Cave-Ayland
2022-06-24 13:40 ` [PATCH v2 44/54] lasips2: add base property Mark Cave-Ayland
2022-06-24 15:09   ` Peter Maydell
2022-06-24 13:41 ` [PATCH v2 45/54] lasips2: implement lasips2_realize() Mark Cave-Ayland
2022-06-24 13:41 ` [PATCH v2 46/54] lasips2: use sysbus IRQ for output IRQ Mark Cave-Ayland
2022-06-24 15:10   ` Peter Maydell
2022-06-24 13:41 ` [PATCH v2 47/54] lasips2: switch over from update_irq() function to PS2 device gpio Mark Cave-Ayland
2022-06-24 15:10   ` Peter Maydell
2022-06-26 10:14   ` Mark Cave-Ayland
2022-06-24 13:41 ` [PATCH v2 48/54] lasips2: add QEMU interface comment Mark Cave-Ayland
2022-06-24 15:11   ` Peter Maydell
2022-06-24 13:41 ` [PATCH v2 49/54] pckbd: switch I8042_MMIO device from update_irq() function to PS2 device gpio Mark Cave-Ayland
2022-06-24 13:41 ` [PATCH v2 50/54] pckbd: add QEMU interface comment for I8042_MMIO device Mark Cave-Ayland
2022-06-24 15:11   ` Peter Maydell
2022-06-24 13:41 ` [PATCH v2 51/54] pckbd: add i8042_reset() function to I8042 device Mark Cave-Ayland
2022-06-24 13:41 ` [PATCH v2 52/54] pckbd: switch I8042 device from update_irq() function to PS2 device gpio Mark Cave-Ayland
2022-06-24 13:41 ` [PATCH v2 53/54] pckbd: add QEMU interface comment for I8042 device Mark Cave-Ayland
2022-06-24 15:12   ` Peter Maydell
2022-06-24 13:41 ` [PATCH v2 54/54] ps2: remove update_irq() function and update_arg parameter Mark Cave-Ayland

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220624134109.881989-5-mark.cave-ayland@ilande.co.uk \
    --to=mark.cave-ayland@ilande.co.uk \
    --cc=aleksandar.rikalo@syrmia.com \
    --cc=deller@gmx.de \
    --cc=f4bug@amsat.org \
    --cc=hpoussin@reactos.org \
    --cc=jiaxun.yang@flygoat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.