From b7047733dc5b6c6843d9569e23c74d2ed280b4f2 Mon Sep 17 00:00:00 2001 From: Mark Cave-Ayland Date: Tue, 12 Jul 2022 22:52:30 +0100 Subject: [PATCH] lasips2: move keyboard port initialisation to new lasips2_kbd_port_init() function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Tested-by: Helge Deller Acked-by: Helge Deller Reviewed-by: Peter Maydell Message-Id: <20220712215251.7944-20-mark.cave-ayland@ilande.co.uk> Reviewed-by: Philippe Mathieu-Daudé --- hw/input/lasips2.c | 47 ++++++++++++++++++++++++++------------ include/hw/input/lasips2.h | 2 +- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/hw/input/lasips2.c b/hw/input/lasips2.c index f70cf893f6..74427c9990 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 = { diff --git a/include/hw/input/lasips2.h b/include/hw/input/lasips2.h index aab6a3500c..f728f54c78 100644 --- a/include/hw/input/lasips2.h +++ b/include/hw/input/lasips2.h @@ -60,7 +60,7 @@ struct LASIPS2MousePort { struct LASIPS2State { SysBusDevice parent_obj; - LASIPS2Port kbd; + LASIPS2KbdPort kbd_port; LASIPS2Port mouse; qemu_irq irq; };