qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Damien Hedde <damien.hedde@greensocs.com>
To: "Philippe Mathieu-Daudé" <f4bug@amsat.org>, qemu-devel@nongnu.org
Cc: Richard Henderson <richard.henderson@linaro.org>,
	Helge Deller <deller@gmx.de>,
	Sven Schnelle <svens@stackframe.org>
Subject: Re: [PATCH 3/3] hw/input/lasips2: QOM'ify the Lasi PS/2
Date: Wed, 29 Sep 2021 16:33:31 +0200	[thread overview]
Message-ID: <a829a153-dd96-8038-2ced-b2e0b8c5ab12@greensocs.com> (raw)
In-Reply-To: <20210920064048.2729397-4-f4bug@amsat.org>



On 9/20/21 08:40, Philippe Mathieu-Daudé wrote:
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

Reviewed-by: Damien Hedde <damien.hedde@greensocs.com>

> ---
>   include/hw/input/lasips2.h | 17 +++++++++++++----
>   hw/hppa/lasi.c             | 10 +++++++++-
>   hw/input/lasips2.c         | 38 ++++++++++++++++++++++++++++----------
>   3 files changed, 50 insertions(+), 15 deletions(-)
> 
> diff --git a/include/hw/input/lasips2.h b/include/hw/input/lasips2.h
> index c88f1700162..834b6d867d9 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 */
> diff --git a/hw/hppa/lasi.c b/hw/hppa/lasi.c
> index 88c3791eb68..91414748b70 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 0f8362f17bc..46cd32316da 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)
> 


  reply	other threads:[~2021-09-29 14:37 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-20  6:40 [PATCH 0/3] hw/input/lasips2: QOM'ify the Lasi PS/2 Philippe Mathieu-Daudé
2021-09-20  6:40 ` [PATCH 1/3] hw/input/lasips2: Fix typos in function names Philippe Mathieu-Daudé
2021-09-29 14:24   ` Damien Hedde
2021-09-20  6:40 ` [PATCH 2/3] hw/input/lasips2: Move LASIPS2State declaration to 'hw/input/lasips2.h' Philippe Mathieu-Daudé
2021-09-29 14:27   ` Damien Hedde
2021-09-20  6:40 ` [PATCH 3/3] hw/input/lasips2: QOM'ify the Lasi PS/2 Philippe Mathieu-Daudé
2021-09-29 14:33   ` Damien Hedde [this message]
2021-09-29 14:06 ` [PATCH 0/3] " Philippe Mathieu-Daudé
2021-10-27  5:11 ` Philippe Mathieu-Daudé
2021-10-27  8:46   ` Laurent Vivier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a829a153-dd96-8038-2ced-b2e0b8c5ab12@greensocs.com \
    --to=damien.hedde@greensocs.com \
    --cc=deller@gmx.de \
    --cc=f4bug@amsat.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=svens@stackframe.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).