Skip to contentSkip to conversation

hw/input/lasips2: QOM'ify the Lasi PS/2

PATCH Applied Philippe Mathieu-Daudé 3 participants 10 messages Sep 20, 2021 – Oct 27, 2021

lore
Share & tools
lore
#0 lore raw

cover hw/input/lasips2: QOM'ify the Lasi PS/2

Slowly nuking non-QOM devices: Lasi PS/2's turn.

Philippe Mathieu-Daudé (3):
hw/input/lasips2: Fix typos in function names hw/input/lasips2: Move LASIPS2State declaration to

    'hw/input/lasips2.h'

hw/input/lasips2: QOM'ify the Lasi PS/2

 include/hw/input/lasips2.h | 31 ++++++++++++++++--
 hw/hppa/lasi.c             | 10 +++++-
 hw/input/lasips2.c         | 64 +++++++++++++++++++-------------------
 3 files changed, 70 insertions(+), 35 deletions(-)
Signature · 1 line
2.31.1
#1 lore raw

PATCH 1/3 hw/input/lasips2: Fix typos in function names

Artist is another device, this one is the Lasi PS/2. Rename the functions accordingly.

---
 hw/input/lasips2.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
hw/input/lasips2.c +4 -4
index e7faf24058b..68d741d3421 100644
@@ -96,7 +96,7 @@ typedef enum {
     LASIPS2_STATUS_CLKSHD = 0x80,
 } lasips2_status_reg_t;
 
-static const char *artist_read_reg_name(uint64_t addr)
+static const char *lasips2_read_reg_name(uint64_t addr)
 {
     switch (addr & 0xc) {
     case REG_PS2_ID:
@@ -116,7 +116,7 @@ static const char *artist_read_reg_name(uint64_t addr)
     }
 }
 
-static const char *artist_write_reg_name(uint64_t addr)
+static const char *lasips2_write_reg_name(uint64_t addr)
 {
     switch (addr & 0x0c) {
     case REG_PS2_RESET:
@@ -145,7 +145,7 @@ static void lasips2_reg_write(void *opaque, hwaddr addr, uint64_t val,
     LASIPS2Port *port = opaque;
 
     trace_lasips2_reg_write(size, port->id, addr,
-                            artist_write_reg_name(addr), val);
+                            lasips2_write_reg_name(addr), val);
 
     switch (addr & 0xc) {
     case REG_PS2_CONTROL:
@@ -239,7 +239,7 @@ static uint64_t lasips2_reg_read(void *opaque, hwaddr addr, unsigned size)
         break;
     }
     trace_lasips2_reg_read(size, port->id, addr,
-                           artist_read_reg_name(addr), ret);
+                           lasips2_read_reg_name(addr), ret);
 
     return ret;
 }
Signature · 1 line
2.31.1
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] hw/input/lasips2: Fix typos in function names

Quoted 4 lines · Philippe Mathieu-Daudé

Artist is another device, this one is the Lasi PS/2. Rename the functions accordingly.

Quoted 45 lines
---
  hw/input/lasips2.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
hw/input/lasips2.c +4 -4
index e7faf24058b..68d741d3421 100644
@@ -96,7 +96,7 @@ typedef enum {
      LASIPS2_STATUS_CLKSHD = 0x80,
  } lasips2_status_reg_t;
 
-static const char *artist_read_reg_name(uint64_t addr)
+static const char *lasips2_read_reg_name(uint64_t addr)
  {
      switch (addr & 0xc) {
      case REG_PS2_ID:
@@ -116,7 +116,7 @@ static const char *artist_read_reg_name(uint64_t addr)
      }
  }
 
-static const char *artist_write_reg_name(uint64_t addr)
+static const char *lasips2_write_reg_name(uint64_t addr)
  {
      switch (addr & 0x0c) {
      case REG_PS2_RESET:
@@ -145,7 +145,7 @@ static void lasips2_reg_write(void *opaque, hwaddr addr, uint64_t val,
      LASIPS2Port *port = opaque;
 
      trace_lasips2_reg_write(size, port->id, addr,
-                            artist_write_reg_name(addr), val);
+                            lasips2_write_reg_name(addr), val);
 
      switch (addr & 0xc) {
      case REG_PS2_CONTROL:
@@ -239,7 +239,7 @@ static uint64_t lasips2_reg_read(void *opaque, hwaddr addr, unsigned size)
          break;
      }
      trace_lasips2_reg_read(size, port->id, addr,
-                           artist_read_reg_name(addr), ret);
+                           lasips2_read_reg_name(addr), ret);
 
      return ret;
  }
#3 lore raw

PATCH 2/3 hw/input/lasips2: Move LASIPS2State declaration to 'hw/input/lasips2.h'

In reply to Philippe Mathieu-Daudé

We want to use the OBJECT_DECLARE_SIMPLE_TYPE() macro to QOM'ify this device in the next commit. To make its review simpler, as a first step move the LASIPS2State and LASIPS2Port declarations to 'hw/input/lasips2.h'

---
 include/hw/input/lasips2.h | 18 ++++++++++++++++++
 hw/input/lasips2.c         | 18 ------------------
 2 files changed, 18 insertions(+), 18 deletions(-)
include/hw/input/lasips2.h +18 -0
index 0cd7b59064a..c88f1700162 100644
@@ -11,6 +11,24 @@
 
 #define TYPE_LASIPS2 "lasips2"
 
+struct LASIPS2State;
+typedef struct LASIPS2Port {
+    struct LASIPS2State *parent;
+    MemoryRegion reg;
+    void *dev;
+    uint8_t id;
+    uint8_t control;
+    uint8_t buf;
+    bool loopback_rbne;
+    bool irq;
+} LASIPS2Port;
+
+typedef struct LASIPS2State {
+    LASIPS2Port kbd;
+    LASIPS2Port mouse;
+    qemu_irq irq;
+} LASIPS2State;
+
 void lasips2_init(MemoryRegion *address_space, hwaddr base, qemu_irq irq);
 
 #endif /* HW_INPUT_LASIPS2_H */
hw/input/lasips2.c +0 -18
index 68d741d3421..0f8362f17bc 100644
@@ -33,24 +33,6 @@
 #include "hw/irq.h"
 
 
-struct LASIPS2State;
-typedef struct LASIPS2Port {
-    struct LASIPS2State *parent;
-    MemoryRegion reg;
-    void *dev;
-    uint8_t id;
-    uint8_t control;
-    uint8_t buf;
-    bool loopback_rbne;
-    bool irq;
-} LASIPS2Port;
-
-typedef struct LASIPS2State {
-    LASIPS2Port kbd;
-    LASIPS2Port mouse;
-    qemu_irq irq;
-} LASIPS2State;
-
 static const VMStateDescription vmstate_lasips2 = {
     .name = "lasips2",
     .version_id = 0,
Signature · 1 line
2.31.1
Reviewed-by on v1 2/3
#4 lore raw

Re: [PATCH 2/3] hw/input/lasips2: Move LASIPS2State declaration to 'hw/input/lasips2.h'

Quoted 6 lines · Philippe Mathieu-Daudé

We want to use the OBJECT_DECLARE_SIMPLE_TYPE() macro to QOM'ify this device in the next commit. To make its review simpler, as a first step move the LASIPS2State and LASIPS2Port declarations to 'hw/input/lasips2.h'

Quoted 64 lines
---
  include/hw/input/lasips2.h | 18 ++++++++++++++++++
  hw/input/lasips2.c         | 18 ------------------
  2 files changed, 18 insertions(+), 18 deletions(-)
include/hw/input/lasips2.h +18 -0
index 0cd7b59064a..c88f1700162 100644
@@ -11,6 +11,24 @@
 
  #define TYPE_LASIPS2 "lasips2"
 
+struct LASIPS2State;
+typedef struct LASIPS2Port {
+    struct LASIPS2State *parent;
+    MemoryRegion reg;
+    void *dev;
+    uint8_t id;
+    uint8_t control;
+    uint8_t buf;
+    bool loopback_rbne;
+    bool irq;
+} LASIPS2Port;
+
+typedef struct LASIPS2State {
+    LASIPS2Port kbd;
+    LASIPS2Port mouse;
+    qemu_irq irq;
+} LASIPS2State;
+
  void lasips2_init(MemoryRegion *address_space, hwaddr base, qemu_irq irq);
 
  #endif /* HW_INPUT_LASIPS2_H */
hw/input/lasips2.c +0 -18
index 68d741d3421..0f8362f17bc 100644
@@ -33,24 +33,6 @@
  #include "hw/irq.h"
 
 
-struct LASIPS2State;
-typedef struct LASIPS2Port {
-    struct LASIPS2State *parent;
-    MemoryRegion reg;
-    void *dev;
-    uint8_t id;
-    uint8_t control;
-    uint8_t buf;
-    bool loopback_rbne;
-    bool irq;
-} LASIPS2Port;
-
-typedef struct LASIPS2State {
-    LASIPS2Port kbd;
-    LASIPS2Port mouse;
-    qemu_irq irq;
-} LASIPS2State;
-
  static const VMStateDescription vmstate_lasips2 = {
      .name = "lasips2",
      .version_id = 0,
#5 lore raw

PATCH 3/3 hw/input/lasips2: QOM'ify the Lasi PS/2

In reply to Philippe Mathieu-Daudé
---
 include/hw/input/lasips2.h | 17 +++++++++++++----
 hw/hppa/lasi.c             | 10 +++++++++-
 hw/input/lasips2.c         | 38 ++++++++++++++++++++++++++++----------
 3 files changed, 50 insertions(+), 15 deletions(-)
include/hw/input/lasips2.h +13 -4
index c88f1700162..834b6d867d9 100644
@@ -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 */
hw/hppa/lasi.c +9 -1
index 88c3791eb68..91414748b70 100644
@@ -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;
 }
hw/input/lasips2.c +28 -10
index 0f8362f17bc..46cd32316da 100644
@@ -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)
Signature · 1 line
2.31.1
Reviewed-by on v1 3/3
#6 lore raw
Quoted 1 line · Philippe Mathieu-Daudé
Quoted 138 lines
---
  include/hw/input/lasips2.h | 17 +++++++++++++----
  hw/hppa/lasi.c             | 10 +++++++++-
  hw/input/lasips2.c         | 38 ++++++++++++++++++++++++++++----------
  3 files changed, 50 insertions(+), 15 deletions(-)
include/hw/input/lasips2.h +13 -4
index c88f1700162..834b6d867d9 100644
@@ -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 */
hw/hppa/lasi.c +9 -1
index 88c3791eb68..91414748b70 100644
@@ -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;
  }
hw/input/lasips2.c +28 -10
index 0f8362f17bc..46cd32316da 100644
@@ -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)
#7 lore raw
In reply to Philippe Mathieu-Daudé

ping?

Quoted 13 lines · Philippe Mathieu-Daudé

Slowly nuking non-QOM devices: Lasi PS/2's turn.

Philippe Mathieu-Daudé (3):
hw/input/lasips2: Fix typos in function names hw/input/lasips2: Move LASIPS2State declaration to

    'hw/input/lasips2.h'

hw/input/lasips2: QOM'ify the Lasi PS/2

 include/hw/input/lasips2.h | 31 ++++++++++++++++--
 hw/hppa/lasi.c             | 10 +++++-
 hw/input/lasips2.c         | 64 +++++++++++++++++++-------------------
 3 files changed, 70 insertions(+), 35 deletions(-)
#8 lore raw
In reply to Philippe Mathieu-Daudé

Cc'ing qemu-trivial@ (fully reviewed).

Quoted 13 lines · Philippe Mathieu-Daudé

Slowly nuking non-QOM devices: Lasi PS/2's turn.

Philippe Mathieu-Daudé (3):
hw/input/lasips2: Fix typos in function names hw/input/lasips2: Move LASIPS2State declaration to

    'hw/input/lasips2.h'

hw/input/lasips2: QOM'ify the Lasi PS/2

 include/hw/input/lasips2.h | 31 ++++++++++++++++--
 hw/hppa/lasi.c             | 10 +++++-
 hw/input/lasips2.c         | 64 +++++++++++++++++++-------------------
 3 files changed, 70 insertions(+), 35 deletions(-)
#9 lore raw

Le 27/10/2021 à 07:11, Philippe Mathieu-Daudé a écrit :

Quoted 17 lines

Cc'ing qemu-trivial@ (fully reviewed).

Quoted 13 lines · Philippe Mathieu-Daudé

Slowly nuking non-QOM devices: Lasi PS/2's turn.

Philippe Mathieu-Daudé (3):
hw/input/lasips2: Fix typos in function names hw/input/lasips2: Move LASIPS2State declaration to

     'hw/input/lasips2.h'

hw/input/lasips2: QOM'ify the Lasi PS/2

  include/hw/input/lasips2.h | 31 ++++++++++++++++--
  hw/hppa/lasi.c             | 10 +++++-
  hw/input/lasips2.c         | 64 +++++++++++++++++++-------------------
  3 files changed, 70 insertions(+), 35 deletions(-)

Applied to my trivial-patches branch.

Thanks,
Laurent