diff mbox series

[v3,08/33] serial: add "chardev" property

Message ID 20191023173154.30051-9-marcandre.lureau@redhat.com
State New
Headers show
Series Clean-ups: qom-ify serial and remove QDEV_PROP_PTR | expand

Commit Message

Marc-André Lureau Oct. 23, 2019, 5:31 p.m. UTC
This is more QOM-friendly, callers may set/get the property themself.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 hw/char/serial.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

Comments

Philippe Mathieu-Daudé Oct. 23, 2019, 10:39 p.m. UTC | #1
On 10/23/19 7:31 PM, Marc-André Lureau wrote:
> This is more QOM-friendly, callers may set/get the property themself.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>   hw/char/serial.c | 11 +++++++++--
>   1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/char/serial.c b/hw/char/serial.c
> index 4af8b0ce4c..09e89727a6 100644
> --- a/hw/char/serial.c
> +++ b/hw/char/serial.c
> @@ -34,6 +34,7 @@
>   #include "sysemu/runstate.h"
>   #include "qemu/error-report.h"
>   #include "trace.h"
> +#include "hw/qdev-properties.h"
>   
>   //#define DEBUG_SERIAL
>   
> @@ -988,7 +989,7 @@ SerialState *serial_init(int base, qemu_irq irq, int baudbase,
>   
>       s->irq = irq;
>       s->baudbase = baudbase;
> -    qemu_chr_fe_init(&s->chr, chr, &error_abort);
> +    qdev_prop_set_chr(dev, "chardev", chr);
>       serial_realize_core(s, &error_fatal);
>       qdev_set_legacy_instance_id(dev, base, 2);
>       qdev_init_nofail(dev);
> @@ -999,11 +1000,17 @@ SerialState *serial_init(int base, qemu_irq irq, int baudbase,
>       return s;
>   }
>   
> +static Property serial_properties[] = {
> +    DEFINE_PROP_CHR("chardev", SerialState, chr),
> +    DEFINE_PROP_END_OF_LIST(),
> +};
> +
>   static void serial_class_init(ObjectClass *klass, void* data)
>   {
>       DeviceClass *dc = DEVICE_CLASS(klass);
>   
>       dc->vmsd = &vmstate_serial;
> +    dc->props = serial_properties;
>   }
>   
>   static const TypeInfo serial_info = {
> @@ -1064,7 +1071,7 @@ SerialState *serial_mm_init(MemoryRegion *address_space,
>       s->it_shift = it_shift;
>       s->irq = irq;
>       s->baudbase = baudbase;
> -    qemu_chr_fe_init(&s->chr, chr, &error_abort);
> +    qdev_prop_set_chr(dev, "chardev", chr);
>   
>       serial_realize_core(s, &error_fatal);
>       qdev_set_legacy_instance_id(dev, base, 2);
> 

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Peter Maydell Nov. 18, 2019, 2:23 p.m. UTC | #2
On Wed, 23 Oct 2019 at 18:33, Marc-André Lureau
<marcandre.lureau@redhat.com> wrote:
>
> This is more QOM-friendly, callers may set/get the property themself.
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  hw/char/serial.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM
diff mbox series

Patch

diff --git a/hw/char/serial.c b/hw/char/serial.c
index 4af8b0ce4c..09e89727a6 100644
--- a/hw/char/serial.c
+++ b/hw/char/serial.c
@@ -34,6 +34,7 @@ 
 #include "sysemu/runstate.h"
 #include "qemu/error-report.h"
 #include "trace.h"
+#include "hw/qdev-properties.h"
 
 //#define DEBUG_SERIAL
 
@@ -988,7 +989,7 @@  SerialState *serial_init(int base, qemu_irq irq, int baudbase,
 
     s->irq = irq;
     s->baudbase = baudbase;
-    qemu_chr_fe_init(&s->chr, chr, &error_abort);
+    qdev_prop_set_chr(dev, "chardev", chr);
     serial_realize_core(s, &error_fatal);
     qdev_set_legacy_instance_id(dev, base, 2);
     qdev_init_nofail(dev);
@@ -999,11 +1000,17 @@  SerialState *serial_init(int base, qemu_irq irq, int baudbase,
     return s;
 }
 
+static Property serial_properties[] = {
+    DEFINE_PROP_CHR("chardev", SerialState, chr),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
 static void serial_class_init(ObjectClass *klass, void* data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
 
     dc->vmsd = &vmstate_serial;
+    dc->props = serial_properties;
 }
 
 static const TypeInfo serial_info = {
@@ -1064,7 +1071,7 @@  SerialState *serial_mm_init(MemoryRegion *address_space,
     s->it_shift = it_shift;
     s->irq = irq;
     s->baudbase = baudbase;
-    qemu_chr_fe_init(&s->chr, chr, &error_abort);
+    qdev_prop_set_chr(dev, "chardev", chr);
 
     serial_realize_core(s, &error_fatal);
     qdev_set_legacy_instance_id(dev, base, 2);