From: Laurent Vivier <laurent@vivier.eu>
To: qemu-devel@nongnu.org
Cc: qemu-trivial@nongnu.org,
"Damien Hedde" <damien.hedde@greensocs.com>,
"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
"Laurent Vivier" <laurent@vivier.eu>
Subject: [PULL 6/6] hw/input/lasips2: QOM'ify the Lasi PS/2
Date: Mon, 1 Nov 2021 09:27:47 +0100 [thread overview]
Message-ID: <20211101082747.2524909-7-laurent@vivier.eu> (raw)
In-Reply-To: <20211101082747.2524909-1-laurent@vivier.eu>
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Damien Hedde <damien.hedde@greensocs.com>
Message-Id: <20210920064048.2729397-4-f4bug@amsat.org>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
hw/hppa/lasi.c | 10 +++++++++-
hw/input/lasips2.c | 38 ++++++++++++++++++++++++++++----------
include/hw/input/lasips2.h | 17 +++++++++++++----
3 files changed, 50 insertions(+), 15 deletions(-)
diff --git a/hw/hppa/lasi.c b/hw/hppa/lasi.c
index 88c3791eb683..91414748b70d 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 0f8362f17bc1..46cd32316dac 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)
diff --git a/include/hw/input/lasips2.h b/include/hw/input/lasips2.h
index c88f1700162a..834b6d867d9d 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 */
--
2.31.1
next prev parent reply other threads:[~2021-11-01 8:32 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-01 8:27 [PULL 0/6] Trivial branch for 6.2 patches Laurent Vivier
2021-11-01 8:27 ` [PULL 1/6] monitor: Trim some trailing space from human-readable output Laurent Vivier
2021-11-01 8:27 ` [PULL 2/6] hw/core/machine: Add the missing delimiter in cpu_slot_to_string() Laurent Vivier
2021-11-01 8:27 ` [PULL 3/6] MAINTAINERS: Split HPPA TCG vs HPPA machines/hardware Laurent Vivier
2021-11-01 8:27 ` [PULL 4/6] hw/input/lasips2: Fix typos in function names Laurent Vivier
2021-11-01 8:27 ` [PULL 5/6] hw/input/lasips2: Move LASIPS2State declaration to 'hw/input/lasips2.h' Laurent Vivier
2021-11-01 8:27 ` Laurent Vivier [this message]
2021-11-01 15:31 ` [PULL 6/6] hw/input/lasips2: QOM'ify the Lasi PS/2 Richard Henderson
2021-11-01 15:43 ` Philippe Mathieu-Daudé
2021-11-02 16:48 ` Philippe Mathieu-Daudé
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=20211101082747.2524909-7-laurent@vivier.eu \
--to=laurent@vivier.eu \
--cc=damien.hedde@greensocs.com \
--cc=f4bug@amsat.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).