aboutsummaryrefslogtreecommitdiff
path: root/hw/input
diff options
context:
space:
mode:
authorMark Cave-Ayland <mark.cave-ayland@ilande.co.uk>2022-07-12 22:52:30 +0100
committerMark Cave-Ayland <mark.cave-ayland@ilande.co.uk>2022-07-18 19:28:46 +0100
commitb7047733dc5b6c6843d9569e23c74d2ed280b4f2 (patch)
treefc70844f4c9d2dbebe4d50e17dd3f5e76b8e2a50 /hw/input
parentcb5827cee33f3b99daef7005491eae3af4316df6 (diff)
downloadqemu-b7047733dc5b6c6843d9569e23c74d2ed280b4f2.zip
qemu-b7047733dc5b6c6843d9569e23c74d2ed280b4f2.tar.gz
qemu-b7047733dc5b6c6843d9569e23c74d2ed280b4f2.tar.bz2
lasips2: move keyboard port initialisation to new lasips2_kbd_port_init() function
Move the initialisation of the keyboard port from lasips2_init() to a new lasips2_kbd_port_init() function which will be invoked using object_initialize_child() during the LASIPS2 device init. Update LASIPS2State so that it now holds the new LASIPS2KbdPort child object and ensure that it is realised in lasips2_realize(). Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> Tested-by: Helge Deller <deller@gmx.de> Acked-by: Helge Deller <deller@gmx.de> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Message-Id: <20220712215251.7944-20-mark.cave-ayland@ilande.co.uk> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Diffstat (limited to 'hw/input')
-rw-r--r--hw/input/lasips2.c47
1 files changed, 33 insertions, 14 deletions
diff --git a/hw/input/lasips2.c b/hw/input/lasips2.c
index f70cf89..74427c9 100644
--- a/hw/input/lasips2.c
+++ b/hw/input/lasips2.c
@@ -40,9 +40,9 @@ static const VMStateDescription vmstate_lasips2 = {
.version_id = 0,
.minimum_version_id = 0,
.fields = (VMStateField[]) {
- VMSTATE_UINT8(kbd.control, LASIPS2State),
- VMSTATE_UINT8(kbd.id, LASIPS2State),
- VMSTATE_BOOL(kbd.irq, LASIPS2State),
+ VMSTATE_UINT8(kbd_port.parent_obj.control, LASIPS2State),
+ VMSTATE_UINT8(kbd_port.parent_obj.id, LASIPS2State),
+ VMSTATE_BOOL(kbd_port.parent_obj.irq, LASIPS2State),
VMSTATE_UINT8(mouse.control, LASIPS2State),
VMSTATE_UINT8(mouse.id, LASIPS2State),
VMSTATE_BOOL(mouse.irq, LASIPS2State),
@@ -119,8 +119,8 @@ static const char *lasips2_write_reg_name(uint64_t addr)
static void lasips2_update_irq(LASIPS2State *s)
{
- trace_lasips2_intr(s->kbd.irq | s->mouse.irq);
- qemu_set_irq(s->irq, s->kbd.irq | s->mouse.irq);
+ trace_lasips2_intr(s->kbd_port.parent_obj.irq | s->mouse.irq);
+ qemu_set_irq(s->irq, s->kbd_port.parent_obj.irq | s->mouse.irq);
}
static void lasips2_reg_write(void *opaque, hwaddr addr, uint64_t val,
@@ -211,7 +211,7 @@ static uint64_t lasips2_reg_read(void *opaque, hwaddr addr, unsigned size)
}
}
- if (port->parent->kbd.irq || port->parent->mouse.irq) {
+ if (port->parent->kbd_port.parent_obj.irq || port->parent->mouse.irq) {
ret |= LASIPS2_STATUS_CMPINTR;
}
break;
@@ -240,7 +240,7 @@ static const MemoryRegionOps lasips2_reg_ops = {
static void lasips2_set_kbd_irq(void *opaque, int n, int level)
{
LASIPS2State *s = LASIPS2(opaque);
- LASIPS2Port *port = &s->kbd;
+ LASIPS2Port *port = LASIPS2_PORT(&s->kbd_port);
port->irq = level;
lasips2_update_irq(port->parent);
@@ -258,9 +258,15 @@ static void lasips2_set_mouse_irq(void *opaque, int n, int level)
static void lasips2_realize(DeviceState *dev, Error **errp)
{
LASIPS2State *s = LASIPS2(dev);
+ LASIPS2Port *lp;
- s->kbd.ps2dev = ps2_kbd_init();
- qdev_connect_gpio_out(DEVICE(s->kbd.ps2dev), PS2_DEVICE_IRQ,
+ lp = LASIPS2_PORT(&s->kbd_port);
+ if (!(qdev_realize(DEVICE(lp), NULL, errp))) {
+ return;
+ }
+
+ lp->ps2dev = ps2_kbd_init();
+ qdev_connect_gpio_out(DEVICE(lp->ps2dev), PS2_DEVICE_IRQ,
qdev_get_gpio_in_named(dev, "ps2-kbd-input-irq",
0));
s->mouse.ps2dev = ps2_mouse_init();
@@ -272,18 +278,19 @@ static void lasips2_realize(DeviceState *dev, Error **errp)
static void lasips2_init(Object *obj)
{
LASIPS2State *s = LASIPS2(obj);
+ LASIPS2Port *lp;
+
+ object_initialize_child(obj, "lasips2-kbd-port", &s->kbd_port,
+ TYPE_LASIPS2_KBD_PORT);
- s->kbd.id = 0;
s->mouse.id = 1;
- s->kbd.parent = s;
s->mouse.parent = s;
- memory_region_init_io(&s->kbd.reg, obj, &lasips2_reg_ops, &s->kbd,
- "lasips2-kbd", 0x100);
memory_region_init_io(&s->mouse.reg, obj, &lasips2_reg_ops, &s->mouse,
"lasips2-mouse", 0x100);
- sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->kbd.reg);
+ lp = LASIPS2_PORT(&s->kbd_port);
+ sysbus_init_mmio(SYS_BUS_DEVICE(obj), &lp->reg);
sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->mouse.reg);
sysbus_init_irq(SYS_BUS_DEVICE(obj), &s->irq);
@@ -318,10 +325,22 @@ static const TypeInfo lasips2_port_info = {
.abstract = true,
};
+static void lasips2_kbd_port_init(Object *obj)
+{
+ LASIPS2KbdPort *s = LASIPS2_KBD_PORT(obj);
+ LASIPS2Port *lp = LASIPS2_PORT(obj);
+
+ memory_region_init_io(&lp->reg, obj, &lasips2_reg_ops, lp, "lasips2-kbd",
+ 0x100);
+ lp->id = 0;
+ lp->parent = container_of(s, LASIPS2State, kbd_port);
+}
+
static const TypeInfo lasips2_kbd_port_info = {
.name = TYPE_LASIPS2_KBD_PORT,
.parent = TYPE_LASIPS2_PORT,
.instance_size = sizeof(LASIPS2KbdPort),
+ .instance_init = lasips2_kbd_port_init,
};
static const TypeInfo lasips2_mouse_port_info = {