All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
To: qemu-devel@nongnu.org
Cc: "Sven Schnelle" <svens@stackframe.org>,
	"Helge Deller" <deller@gmx.de>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>
Subject: [PATCH 3/3] hw/input/lasips2: QOM'ify the Lasi PS/2
Date: Mon, 20 Sep 2021 08:40:48 +0200	[thread overview]
Message-ID: <20210920064048.2729397-4-f4bug@amsat.org> (raw)
In-Reply-To: <20210920064048.2729397-1-f4bug@amsat.org>

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 include/hw/input/lasips2.h | 17 +++++++++++++----
 hw/hppa/lasi.c             | 10 +++++++++-
 hw/input/lasips2.c         | 38 ++++++++++++++++++++++++++++----------
 3 files changed, 50 insertions(+), 15 deletions(-)

diff --git a/include/hw/input/lasips2.h b/include/hw/input/lasips2.h
index c88f1700162..834b6d867d9 100644
--- a/include/hw/input/lasips2.h
+++ b/include/hw/input/lasips2.h
@@ -7,11 +7,11 @@
 #ifndef HW_INPUT_LASIPS2_H
 #define HW_INPUT_LASIPS2_H
 
-#include "exec/hwaddr.h"
+#include "hw/sysbus.h"
 
 #define TYPE_LASIPS2 "lasips2"
+OBJECT_DECLARE_SIMPLE_TYPE(LASIPS2State, LASIPS2)
 
-struct LASIPS2State;
 typedef struct LASIPS2Port {
     struct LASIPS2State *parent;
     MemoryRegion reg;
@@ -23,12 +23,21 @@ typedef struct LASIPS2Port {
     bool irq;
 } LASIPS2Port;
 
+/*
+ * QEMU interface:
+ *  + sysbus MMIO region 0 is the keyboard port interface
+ *  + sysbus MMIO region 1 is the mouse port interface
+ *  + sysbus IRQ 0 is the interrupt line shared between
+ *    keyboard and mouse ports
+ */
 typedef struct LASIPS2State {
+    /*< private >*/
+    SysBusDevice parent_obj;
+
+    /*< public >*/
     LASIPS2Port kbd;
     LASIPS2Port mouse;
     qemu_irq irq;
 } LASIPS2State;
 
-void lasips2_init(MemoryRegion *address_space, hwaddr base, qemu_irq irq);
-
 #endif /* HW_INPUT_LASIPS2_H */
diff --git a/hw/hppa/lasi.c b/hw/hppa/lasi.c
index 88c3791eb68..91414748b70 100644
--- a/hw/hppa/lasi.c
+++ b/hw/hppa/lasi.c
@@ -297,6 +297,7 @@ static int lasi_get_irq(unsigned long hpa)
 DeviceState *lasi_init(MemoryRegion *address_space)
 {
     DeviceState *dev;
+    SysBusDevice *sbd;
     LasiState *s;
 
     dev = qdev_new(TYPE_LASI_CHIP);
@@ -340,7 +341,14 @@ DeviceState *lasi_init(MemoryRegion *address_space)
     /* PS/2 Keyboard/Mouse */
     qemu_irq ps2kbd_irq = qemu_allocate_irq(lasi_set_irq, s,
             lasi_get_irq(LASI_PS2KBD_HPA));
-    lasips2_init(address_space, LASI_PS2KBD_HPA,  ps2kbd_irq);
+
+    sbd = SYS_BUS_DEVICE(qdev_new(TYPE_LASIPS2));
+    sysbus_realize_and_unref(sbd, &error_fatal);
+    memory_region_add_subregion(address_space, LASI_PS2KBD_HPA,
+                                sysbus_mmio_get_region(sbd, 0));
+    memory_region_add_subregion(address_space, LASI_PS2MOU_HPA,
+                                sysbus_mmio_get_region(sbd, 1));
+    sysbus_connect_irq(sbd, 0, ps2kbd_irq);
 
     return dev;
 }
diff --git a/hw/input/lasips2.c b/hw/input/lasips2.c
index 0f8362f17bc..46cd32316da 100644
--- a/hw/input/lasips2.c
+++ b/hw/input/lasips2.c
@@ -243,28 +243,46 @@ static void ps2dev_update_irq(void *opaque, int level)
     lasips2_update_irq(port->parent);
 }
 
-void lasips2_init(MemoryRegion *address_space,
-                  hwaddr base, qemu_irq irq)
+static void lasips2_init(Object *obj)
 {
-    LASIPS2State *s;
+    LASIPS2State *s = LASIPS2(obj);
+    SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
 
-    s = g_malloc0(sizeof(LASIPS2State));
-
-    s->irq = irq;
+    sysbus_init_irq(sbd, &s->irq);
     s->mouse.id = 1;
     s->kbd.parent = s;
     s->mouse.parent = s;
 
-    vmstate_register(NULL, base, &vmstate_lasips2, s);
-
     s->kbd.dev = ps2_kbd_init(ps2dev_update_irq, &s->kbd);
     s->mouse.dev = ps2_mouse_init(ps2dev_update_irq, &s->mouse);
 
     memory_region_init_io(&s->kbd.reg, NULL, &lasips2_reg_ops, &s->kbd,
                           "lasips2-kbd", 0x100);
-    memory_region_add_subregion(address_space, base, &s->kbd.reg);
+    sysbus_init_mmio(sbd, &s->kbd.reg);
 
     memory_region_init_io(&s->mouse.reg, NULL, &lasips2_reg_ops, &s->mouse,
                           "lasips2-mouse", 0x100);
-    memory_region_add_subregion(address_space, base + 0x100, &s->mouse.reg);
+    sysbus_init_mmio(sbd, &s->mouse.reg);
 }
+
+static void lasips2_class_init(ObjectClass *oc, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(oc);
+
+    dc->vmsd = &vmstate_lasips2;
+}
+
+static const TypeInfo lasips2_info = {
+    .name          = TYPE_LASIPS2,
+    .parent        = TYPE_SYS_BUS_DEVICE,
+    .instance_size = sizeof(LASIPS2State),
+    .instance_init = lasips2_init,
+    .class_init    = lasips2_class_init,
+};
+
+static void lasips2_register_types(void)
+{
+    type_register_static(&lasips2_info);
+}
+
+type_init(lasips2_register_types)
-- 
2.31.1



  parent reply	other threads:[~2021-09-20  6:42 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-20  6:40 [PATCH 0/3] hw/input/lasips2: QOM'ify the Lasi PS/2 Philippe Mathieu-Daudé
2021-09-20  6:40 ` [PATCH 1/3] hw/input/lasips2: Fix typos in function names Philippe Mathieu-Daudé
2021-09-29 14:24   ` Damien Hedde
2021-09-20  6:40 ` [PATCH 2/3] hw/input/lasips2: Move LASIPS2State declaration to 'hw/input/lasips2.h' Philippe Mathieu-Daudé
2021-09-29 14:27   ` Damien Hedde
2021-09-20  6:40 ` Philippe Mathieu-Daudé [this message]
2021-09-29 14:33   ` [PATCH 3/3] hw/input/lasips2: QOM'ify the Lasi PS/2 Damien Hedde
2021-09-29 14:06 ` [PATCH 0/3] " Philippe Mathieu-Daudé
2021-10-27  5:11 ` Philippe Mathieu-Daudé
2021-10-27  8:46   ` Laurent Vivier

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=20210920064048.2729397-4-f4bug@amsat.org \
    --to=f4bug@amsat.org \
    --cc=deller@gmx.de \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=svens@stackframe.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.