[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 19/40] lasips2: move keyboard port initialisation to new lasips2_
From: |
Mark Cave-Ayland |
Subject: |
[PATCH 19/40] lasips2: move keyboard port initialisation to new lasips2_kbd_port_init() function |
Date: |
Wed, 29 Jun 2022 13:40:05 +0100 |
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>
---
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;
};
--
2.30.2
- [PATCH 07/40] pl050: introduce PL050DeviceClass for the PL050 device, (continued)
- [PATCH 07/40] pl050: introduce PL050DeviceClass for the PL050 device, Mark Cave-Ayland, 2022/06/29
- [PATCH 02/40] pl050: rename pl050_keyboard_init() to pl050_kbd_init(), Mark Cave-Ayland, 2022/06/29
- [PATCH 09/40] pl050: introduce pl050_mouse_class_init() and pl050_mouse_realize(), Mark Cave-Ayland, 2022/06/29
- [PATCH 12/40] lasips2: don't use vmstate_register() in lasips2_realize(), Mark Cave-Ayland, 2022/06/29
- [PATCH 13/40] lasips2: remove the qdev base property and the lasips2_properties array, Mark Cave-Ayland, 2022/06/29
- [PATCH 14/40] lasips2: remove legacy lasips2_initfn() function, Mark Cave-Ayland, 2022/06/29
- [PATCH 15/40] lasips2: change LASIPS2State dev pointer from void to PS2State, Mark Cave-Ayland, 2022/06/29
- [PATCH 10/40] pl050: don't use legacy ps2_kbd_init() function, Mark Cave-Ayland, 2022/06/29
- [PATCH 16/40] lasips2: QOMify LASIPS2Port, Mark Cave-Ayland, 2022/06/29
- [PATCH 17/40] lasips2: introduce new LASIPS2_KBD_PORT QOM type, Mark Cave-Ayland, 2022/06/29
- [PATCH 19/40] lasips2: move keyboard port initialisation to new lasips2_kbd_port_init() function,
Mark Cave-Ayland <=
- [PATCH 18/40] lasips2: introduce new LASIPS2_MOUSE_PORT QOM type, Mark Cave-Ayland, 2022/06/29
- [PATCH 20/40] lasips2: move mouse port initialisation to new lasips2_mouse_port_init() function, Mark Cave-Ayland, 2022/06/29
- [PATCH 21/40] lasips2: introduce lasips2_kbd_port_class_init() and lasips2_kbd_port_realize(), Mark Cave-Ayland, 2022/06/29
- [PATCH 23/40] lasips2: rename LASIPS2Port irq field to birq, Mark Cave-Ayland, 2022/06/29
- [PATCH 22/40] lasips2: introduce lasips2_mouse_port_class_init() and lasips2_mouse_port_realize(), Mark Cave-Ayland, 2022/06/29
- [PATCH 25/40] lasips2: introduce LASIPS2PortDeviceClass for the LASIPS2_PORT device, Mark Cave-Ayland, 2022/06/29
- [PATCH 24/40] lasips2: introduce port IRQ and new lasips2_port_init() function, Mark Cave-Ayland, 2022/06/29
- [PATCH 26/40] lasips2: add named input gpio to port for downstream PS2 device IRQ, Mark Cave-Ayland, 2022/06/29
- [PATCH 28/40] lasips2: switch to using port-based IRQs, Mark Cave-Ayland, 2022/06/29
- [PATCH 27/40] lasips2: add named input gpio to handle incoming port IRQs, Mark Cave-Ayland, 2022/06/29