diff mbox series

[PULL,6/6] hw/input/lasips2: QOM'ify the Lasi PS/2

Message ID 20211101082747.2524909-7-laurent@vivier.eu
State New
Headers show
Series [PULL,1/6] monitor: Trim some trailing space from human-readable output | expand

Commit Message

Laurent Vivier Nov. 1, 2021, 8:27 a.m. UTC
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(-)

Comments

Richard Henderson Nov. 1, 2021, 3:31 p.m. UTC | #1
On 11/1/21 4:27 AM, Laurent Vivier wrote:
> 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(-)

This has broken the qtest-hppa device-introspection test:

ERROR:../src/qom/object.c:2011:object_get_canonical_path_component: code should not be reached
Broken pipe
Aborted (core dumped)

Also, the previous patch 5 does not compile on its own:

In file included from ../src/hw/input/lasips2.c:28:0:
/home/richard.henderson/qemu/src/include/hw/input/lasips2.h:17:18: error: field ‘reg’ has 
incomplete type
      MemoryRegion reg;
                   ^~~
ninja: build stopped: subcommand failed.

Reverting to patch 4 builds, and passes the introspection test.


r~
Philippe Mathieu-Daudé Nov. 1, 2021, 3:43 p.m. UTC | #2
On 11/1/21 16:31, Richard Henderson wrote:
> On 11/1/21 4:27 AM, Laurent Vivier wrote:
>> 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(-)
> 
> This has broken the qtest-hppa device-introspection test:
> 
> ERROR:../src/qom/object.c:2011:object_get_canonical_path_component: code
> should not be reached
> Broken pipe
> Aborted (core dumped)
> 
> Also, the previous patch 5 does not compile on its own:
> 
> In file included from ../src/hw/input/lasips2.c:28:0:
> /home/richard.henderson/qemu/src/include/hw/input/lasips2.h:17:18:
> error: field ‘reg’ has incomplete type
>      MemoryRegion reg;
>                   ^~~
> ninja: build stopped: subcommand failed.
> 
> Reverting to patch 4 builds, and passes the introspection test.

Thank you for the update, I'll have a look.
Philippe Mathieu-Daudé Nov. 2, 2021, 4:48 p.m. UTC | #3
Hi Laurent,

On 11/1/21 16:43, Philippe Mathieu-Daudé wrote:
> On 11/1/21 16:31, Richard Henderson wrote:
>> On 11/1/21 4:27 AM, Laurent Vivier wrote:
>>> 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(-)
>>
>> This has broken the qtest-hppa device-introspection test:
>>
>> ERROR:../src/qom/object.c:2011:object_get_canonical_path_component: code
>> should not be reached
>> Broken pipe
>> Aborted (core dumped)
>>
>> Also, the previous patch 5 does not compile on its own:
>>
>> In file included from ../src/hw/input/lasips2.c:28:0:
>> /home/richard.henderson/qemu/src/include/hw/input/lasips2.h:17:18:
>> error: field ‘reg’ has incomplete type
>>      MemoryRegion reg;
>>                   ^~~
>> ninja: build stopped: subcommand failed.
>>
>> Reverting to patch 4 builds, and passes the introspection test.
> 
> Thank you for the update, I'll have a look.

The last 2 patches are broken, do you mind resending your pullreq
without them?

Thanks,

Phil.
diff mbox series

Patch

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 */