Received: from eggs.gnu.org ([2001:4830:134:3::10]:42338) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZC1Lt-00032A-Uc for qemu-devel@nongnu.org; Mon, 06 Jul 2015 04:02:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZC1Lm-0004v9-Md for qemu-devel@nongnu.org; Mon, 06 Jul 2015 04:02:09 -0400 Received: from zose-mta02.web4all.fr ([185.49.20.43]:58834) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZC1Lm-0004uu-AM for qemu-devel@nongnu.org; Mon, 06 Jul 2015 04:02:02 -0400 Date: Mon, 6 Jul 2015 10:01:58 +0200 (CEST) From: jcd@tribudubois.net Message-ID: <355004074.3296402.1436169718399.JavaMail.zimbra@tribudubois.net> In-Reply-To: References: <1f2d203ab99d07d673b966f3596d38f0387de1f5.1436138841.git.jcd@tribudubois.net> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_3296401_723363540.1436169718398" Subject: Re: [Qemu-devel] [PATCH v10 02/21] i.MX: Move serial initialization to init/realize of DeviceClass. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Crosthwaite Cc: qemu-devel ------=_Part_3296401_723363540.1436169718398 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable ----- Le 6 Juil 15, =C3=A0 8:40, Peter Crosthwaite a =C3=A9crit :=20 > On Sun, Jul 5, 2015 at 5:04 PM, Jean-Christophe Dubois > wrote: > > Move constructor to DeviceClass methods > > * imx_serial_init > > * imx_serial_realize > > imx32_serial_properties is renamed to imx_serial_properties. > > The Qdev construction helper is moved to an include file as an > > inline function. This function is going to be removed soon. > > Signed-off-by: Jean-Christophe Dubois > > --- > > Changes since v1: > > * not present on v1 > > Changes since v2: > > * not present on v2 > > Changes since v3: > > * not present on v3 > > Changes since v4: > > * not present on v4 > > Changes since v5: > > * not present on v5 > > Changes since v6: > > * not present on v6 > > Changes since v7: > > * not present on v7 > > Changes since v8: > > * Remove Qdev construction helper > > Changes since v9: > > * Qdev construction helper is reintegrated and moved to a header file > > as an inline function. > > hw/char/imx_serial.c | 70 +++++++++++++++------------------------------= ------- > > include/hw/arm/imx.h | 30 +++++++++++++++++++++- > > 2 files changed, 49 insertions(+), 51 deletions(-) > > diff --git a/hw/char/imx_serial.c b/hw/char/imx_serial.c > > index 1dcb325..ef5af05 100644 > > --- a/hw/char/imx_serial.c > > +++ b/hw/char/imx_serial.c > > @@ -21,7 +21,6 @@ > > #include "hw/char/imx_serial.h" > > #include "sysemu/sysemu.h" > > #include "sysemu/char.h" > > -#include "hw/arm/imx.h" > > //#define DEBUG_SERIAL 1 > > #ifdef DEBUG_SERIAL > > @@ -38,13 +37,13 @@ do { printf("imx_serial: " fmt , ##args); } while (= 0) > > //#define DEBUG_IMPLEMENTATION 1 > > #ifdef DEBUG_IMPLEMENTATION > > # define IPRINTF(fmt, args...) \ > > - do { fprintf(stderr, "imx_serial: " fmt, ##args); } while (0) > > + do { fprintf(stderr, "%s: " fmt, TYPE_IMX_SERIAL, ##args); } while (0= ) > > #else > > # define IPRINTF(fmt, args...) do {} while (0) > > #endif > > static const VMStateDescription vmstate_imx_serial =3D { > > - .name =3D "imx-serial", > > + .name =3D TYPE_IMX_SERIAL, > > .version_id =3D 1, > > .minimum_version_id =3D 1, > > .fields =3D (VMStateField[]) { > > @@ -299,22 +298,18 @@ static void imx_event(void *opaque, int event) > > } > > } > > - > > static const struct MemoryRegionOps imx_serial_ops =3D { > > .read =3D imx_serial_read, > > .write =3D imx_serial_write, > > .endianness =3D DEVICE_NATIVE_ENDIAN, > > }; > > -static int imx_serial_init(SysBusDevice *dev) > > +static void imx_serial_realize(DeviceState *dev, Error **errp) > > { > > IMXSerialState *s =3D IMX_SERIAL(dev); > > - > > - memory_region_init_io(&s->iomem, OBJECT(s), &imx_serial_ops, s, > > - "imx-serial", 0x1000); > > - sysbus_init_mmio(dev, &s->iomem); > > - sysbus_init_irq(dev, &s->irq); > > + /* FIXME use a qdev chardev prop instead of qemu_char_get_next_serial= () */ > > + s->chr =3D qemu_char_get_next_serial(); > > if (s->chr) { > > qemu_chr_add_handlers(s->chr, imx_can_receive, imx_receive, > > @@ -323,45 +318,20 @@ static int imx_serial_init(SysBusDevice *dev) > > DPRINTF("No char dev for uart at 0x%lx\n", > > (unsigned long)s->iomem.ram_addr); > > } > > - > > - return 0; > > } > > -void imx_serial_create(int uart, const hwaddr addr, qemu_irq irq) > > +static void imx_serial_init(Object *obj) > > { > > - DeviceState *dev; > > - SysBusDevice *bus; > > - CharDriverState *chr; > > - const char chr_name[] =3D "serial"; > > - char label[ARRAY_SIZE(chr_name) + 1]; > > - > > - dev =3D qdev_create(NULL, TYPE_IMX_SERIAL); > > - > > - if (uart >=3D MAX_SERIAL_PORTS) { > > - hw_error("Cannot assign uart %d: QEMU supports only %d ports\n", > > - uart, MAX_SERIAL_PORTS); > > - } > > - chr =3D serial_hds[uart]; > > - if (!chr) { > > - snprintf(label, ARRAY_SIZE(label), "%s%d", chr_name, uart); > > - chr =3D qemu_chr_new(label, "null", NULL); > > - if (!(chr)) { > > - hw_error("Can't assign serial port to imx-uart%d.\n", uart); > > - } > > - } > > - > > - qdev_prop_set_chr(dev, "chardev", chr); > I'm confused as to why you needed to replace the qdev_prop_set_chr > logic with qemu_get_char_get_next_serial(). Can you give some details > on why we want to do this? I am just following the general ARM template of other serial drivers. I am = not proficient enough in Qemu wizardry to proprose my own thing in this reg= ard.=20 So far no other ARM plateform (except strongarm?) seems to be using "charde= v" and all seems to be using qemu_get_char_get_next_serial() even if it is = supposed to be deprecated some day (even the cadence serial driver).=20 > > - bus =3D SYS_BUS_DEVICE(dev); > > - qdev_init_nofail(dev); > > - if (addr !=3D (hwaddr)-1) { > > - sysbus_mmio_map(bus, 0, addr); > > - } > > - sysbus_connect_irq(bus, 0, irq); > > + SysBusDevice *sbd =3D SYS_BUS_DEVICE(obj); > > + IMXSerialState *s =3D IMX_SERIAL(obj); > > + memory_region_init_io(&s->iomem, obj, &imx_serial_ops, s, > > + TYPE_IMX_SERIAL, 0x1000); > > + sysbus_init_mmio(sbd, &s->iomem); > > + sysbus_init_irq(sbd, &s->irq); > > } > > - > > -static Property imx32_serial_properties[] =3D { > > +static Property imx_serial_properties[] =3D { > > DEFINE_PROP_CHR("chardev", IMXSerialState, chr), > > DEFINE_PROP_END_OF_LIST(), > > }; > > @@ -369,21 +339,21 @@ static Property imx32_serial_properties[] =3D { > > static void imx_serial_class_init(ObjectClass *klass, void *data) > > { > > DeviceClass *dc =3D DEVICE_CLASS(klass); > > - SysBusDeviceClass *k =3D SYS_BUS_DEVICE_CLASS(klass); > > - k->init =3D imx_serial_init; > > + dc->realize =3D imx_serial_realize; > > dc->vmsd =3D &vmstate_imx_serial; > > dc->reset =3D imx_serial_reset_at_boot; > > set_bit(DEVICE_CATEGORY_INPUT, dc->categories); > > dc->desc =3D "i.MX series UART"; > > - dc->props =3D imx32_serial_properties; > > + dc->props =3D imx_serial_properties; > > } > > static const TypeInfo imx_serial_info =3D { > > - .name =3D TYPE_IMX_SERIAL, > > - .parent =3D TYPE_SYS_BUS_DEVICE, > > - .instance_size =3D sizeof(IMXSerialState), > > - .class_init =3D imx_serial_class_init, > > + .name =3D TYPE_IMX_SERIAL, > > + .parent =3D TYPE_SYS_BUS_DEVICE, > > + .instance_size =3D sizeof(IMXSerialState), > > + .instance_init =3D imx_serial_init, > > + .class_init =3D imx_serial_class_init, > > }; > > static void imx_serial_register_types(void) > > diff --git a/include/hw/arm/imx.h b/include/hw/arm/imx.h > > index ea9e093..b861e80 100644 > > --- a/include/hw/arm/imx.h > > +++ b/include/hw/arm/imx.h > > @@ -11,7 +11,34 @@ > > #ifndef IMX_H > > #define IMX_H > > -void imx_serial_create(int uart, const hwaddr addr, qemu_irq irq); > > +#include "hw/qdev-core.h" > > +#include "hw/sysbus.h" > > +#include "hw/char/imx_serial.h" > > + > > +/*** > > + * This Qdev construction helper is going to be removed soon > > + */ > > +static inline void imx_serial_create(int uart, const hwaddr addr, qemu= _irq irq) > > +{ > > + /* uart parameter is not used anymore */ > > + DeviceState *dev; > > + > > + dev =3D qdev_create(NULL, TYPE_IMX_SERIAL); > > + > > + if (dev) { > > + SysBusDevice *bus; > > + > > + bus =3D SYS_BUS_DEVICE(dev); > > + > > + qdev_init_nofail(dev); > > + > > + if (addr !=3D (hwaddr)-1) { > > + sysbus_mmio_map(bus, 0, addr); > > + } > > + > > + sysbus_connect_irq(bus, 0, irq); > > + } > > +} > Can you leave the implementation in imx_serial.c? I don't see the need > for moving it out. There is no reason the c file cannot have all of > _init _realize and _create. I sure could, but I wanted to move these Qdev functions to a single place w= here I could nuke them together (removing a single file) when I don't need = them anymore (when porting KZM to SOC logic).=20 > Regards, > Peter > > typedef enum { > > NOCLK, > > @@ -31,4 +58,5 @@ void imx_timerg_create(const hwaddr addr, > > DeviceState *ccm); > > + > > #endif /* IMX_H */ > > -- > > 2.1.4 ------=_Part_3296401_723363540.1436169718398 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable


----- Le 6 Juil 15, =C3=A0 8:40, Peter Cr= osthwaite <peter.crosthwaite@xilinx.com> a =C3=A9crit :
On Sun, Jul 5, 2015 at 5:04 PM, Jean= -Christophe Dubois
<jcd@tribudubois.net> wrote:
> Move const= ructor to DeviceClass methods
>  * imx_serial_init
>  = ;* imx_serial_realize
>
> imx32_serial_properties is renamed to= imx_serial_properties.
>
> The Qdev construction helper is mov= ed to an include file as an
> inline function. This function is going= to be removed soon.
>
> Signed-off-by: Jean-Christophe Dubois = <jcd@tribudubois.net>
> ---
>
> Changes since v1:>     * not present on v1
>
> Changes since v2:<= br>>     * not present on v2
>
> Changes since v3:=
>     * not present on v3
>
> Changes since v4= :
>     * not present on v4
>
> Changes since v= 5:
>     * not present on v5
>
> Changes since = v6:
>     * not present on v6
>
> Changes since= v7:
>     * not present on v7
>
> Changes sinc= e v8:
>     * Remove Qdev construction helper
>
&g= t; Changes since v9:
>     * Qdev construction helper is re= integrated and moved to a header file
>       as an in= line function.
>
>  hw/char/imx_serial.c | 70 ++++++++++++= +++-------------------------------------
>  include/hw/arm/imx.h= | 30 +++++++++++++++++++++-
>  2 files changed, 49 insertions(+= ), 51 deletions(-)
>
> diff --git a/hw/char/imx_serial.c b/hw/c= har/imx_serial.c
> index 1dcb325..ef5af05 100644
> --- a/hw/cha= r/imx_serial.c
> +++ b/hw/char/imx_serial.c
> @@ -21,7 +21,6 @@=
>  #include "hw/char/imx_serial.h"
>  #include "syse= mu/sysemu.h"
>  #include "sysemu/char.h"
> -#include "hw/a= rm/imx.h"
>
>  //#define DEBUG_SERIAL 1
>  #ifd= ef DEBUG_SERIAL
> @@ -38,13 +37,13 @@ do { printf("imx_serial: " fmt = , ##args); } while (0)
>  //#define DEBUG_IMPLEMENTATION 1
&g= t;  #ifdef DEBUG_IMPLEMENTATION
>  #  define IPRINTF(f= mt, args...) \
> -    do  { fprintf(stderr, "imx_seria= l: " fmt, ##args); } while (0)
> +    do  { fprintf(st= derr, "%s: " fmt, TYPE_IMX_SERIAL, ##args); } while (0)
>  #else=
>  #  define IPRINTF(fmt, args...) do {} while (0)
>=  #endif
>
>  static const VMStateDescription vmstate= _imx_serial =3D {
> -    .name =3D "imx-serial",
> + =    .name =3D TYPE_IMX_SERIAL,
>      .versio= n_id =3D 1,
>      .minimum_version_id =3D 1,
> =      .fields =3D (VMStateField[]) {
> @@ -299,22 +298,= 18 @@ static void imx_event(void *opaque, int event)
>     =  }
>  }
>
> -
>  static const struct= MemoryRegionOps imx_serial_ops =3D {
>      .read =3D= imx_serial_read,
>      .write =3D imx_serial_write,<= br>>      .endianness =3D DEVICE_NATIVE_ENDIAN,
> &= nbsp;};
>
> -static int imx_serial_init(SysBusDevice *dev)
&= gt; +static void imx_serial_realize(DeviceState *dev, Error **errp)
>=  {
>      IMXSerialState *s =3D IMX_SERIAL(dev);=
>
> -
> -    memory_region_init_io(&s->= iomem, OBJECT(s), &imx_serial_ops, s,
> -       &n= bsp;                  "imx-ser= ial", 0x1000);
> -    sysbus_init_mmio(dev, &s->iome= m);
> -    sysbus_init_irq(dev, &s->irq);
> + =    /* FIXME use a qdev chardev prop instead of qemu_char_get_next= _serial() */
> +    s->chr =3D qemu_char_get_next_serial= ();
>
>      if (s->chr) {
>   &nb= sp;      qemu_chr_add_handlers(s->chr, imx_can_receive, i= mx_receive,
> @@ -323,45 +318,20 @@ static int imx_serial_init(SysBus= Device *dev)
>          DPRINTF("No char dev= for uart at 0x%lx\n",
>             &n= bsp;    (unsigned long)s->iomem.ram_addr);
>   &nbs= p;  }
> -
> -    return 0;
>  }
&g= t;
> -void imx_serial_create(int uart, const hwaddr addr, qemu_irq ir= q)
> +static void imx_serial_init(Object *obj)
>  {
>= ; -    DeviceState *dev;
> -    SysBusDevice *bus= ;
> -    CharDriverState *chr;
> -    const= char chr_name[] =3D "serial";
> -    char label[ARRAY_SIZE= (chr_name) + 1];
> -
> -    dev =3D qdev_create(NULL,= TYPE_IMX_SERIAL);
> -
> -    if (uart >=3D MAX_SE= RIAL_PORTS) {
> -        hw_error("Cannot assign = uart %d: QEMU supports only %d ports\n",
> -       &nb= sp;         uart, MAX_SERIAL_PORTS);
> -   &= nbsp;}
> -    chr =3D serial_hds[uart];
> -   &n= bsp;if (!chr) {
> -        snprintf(label, ARRAY_= SIZE(label), "%s%d", chr_name, uart);
> -        = chr =3D qemu_chr_new(label, "null", NULL);
> -       &= nbsp;if (!(chr)) {
> -            hw_er= ror("Can't assign serial port to imx-uart%d.\n", uart);
> -   &n= bsp;    }
> -    }
> -
> -   &nb= sp;qdev_prop_set_chr(dev, "chardev", chr);

I'm confused as to why yo= u needed to replace the qdev_prop_set_chr
logic with qemu_get_char_get_n= ext_serial(). Can you give some details
on why we want to do this?

I am just following the general ARM template of = other serial drivers. I am not proficient enough in Qemu wizardry to propro= se my own thing in this regard.
So far n= o other ARM plateform (except strongarm?) seems to be using "chardev" and a= ll seems to be using qemu_get_char_get_next_serial() even if it is supposed= to be deprecated some day (even the cadence serial driver).

> -    bus =3D SYS_BUS_DEVICE(dev);
>= -    qdev_init_nofail(dev);
> -    if (addr !=3D= (hwaddr)-1) {
> -        sysbus_mmio_map(bus, 0,= addr);
> -    }
> -    sysbus_connect_irq(= bus, 0, irq);
> +    SysBusDevice *sbd =3D SYS_BUS_DEVICE(o= bj);
> +    IMXSerialState *s =3D IMX_SERIAL(obj);
><= br>> +    memory_region_init_io(&s->iomem, obj, &im= x_serial_ops, s,
> +              =            TYPE_IMX_SERIAL, 0x1000);
>= +    sysbus_init_mmio(sbd, &s->iomem);
> +   &= nbsp;sysbus_init_irq(sbd, &s->irq);
>  }
>
> = -
> -static Property imx32_serial_properties[] =3D {
> +static = Property imx_serial_properties[] =3D {
>      DEFINE_P= ROP_CHR("chardev", IMXSerialState, chr),
>      DEFINE= _PROP_END_OF_LIST(),
>  };
> @@ -369,21 +339,21 @@ static = Property imx32_serial_properties[] =3D {
>  static void imx_seri= al_class_init(ObjectClass *klass, void *data)
>  {
>  = ;    DeviceClass *dc =3D DEVICE_CLASS(klass);
> -   &n= bsp;SysBusDeviceClass *k =3D SYS_BUS_DEVICE_CLASS(klass);
>
> -=    k->init =3D imx_serial_init;
> +    dc->= ;realize =3D imx_serial_realize;
>      dc->vmsd = =3D &vmstate_imx_serial;
>      dc->reset =3D i= mx_serial_reset_at_boot;
>      set_bit(DEVICE_CATEGOR= Y_INPUT, dc->categories);
>      dc->desc =3D "i= .MX series UART";
> -    dc->props =3D imx32_serial_prop= erties;
> +    dc->props =3D imx_serial_properties;
&= gt;  }
>
>  static const TypeInfo imx_serial_info =3D= {
> -    .name =3D TYPE_IMX_SERIAL,
> -    = ;.parent =3D TYPE_SYS_BUS_DEVICE,
> -    .instance_size =3D= sizeof(IMXSerialState),
> -    .class_init =3D imx_serial_= class_init,
> +    .name          = =3D TYPE_IMX_SERIAL,
> +    .parent       &= nbsp; =3D TYPE_SYS_BUS_DEVICE,
> +    .instance_size  = =3D sizeof(IMXSerialState),
> +    .instance_init  =3D= imx_serial_init,
> +    .class_init     =3D imx_= serial_class_init,
>  };
>
>  static void imx_s= erial_register_types(void)
> diff --git a/include/hw/arm/imx.h b/incl= ude/hw/arm/imx.h
> index ea9e093..b861e80 100644
> --- a/includ= e/hw/arm/imx.h
> +++ b/include/hw/arm/imx.h
> @@ -11,7 +11,34 @= @
>  #ifndef IMX_H
>  #define IMX_H
>
> -= void imx_serial_create(int uart, const hwaddr addr, qemu_irq irq);
> = +#include "hw/qdev-core.h"
> +#include "hw/sysbus.h"
> +#includ= e "hw/char/imx_serial.h"
> +
> +/***
> + * This Qdev cons= truction helper is going to be removed soon
> + */
> +static in= line void imx_serial_create(int uart, const hwaddr addr, qemu_irq irq)
&= gt; +{
> +   /* uart parameter is not used anymore */
> + =   DeviceState *dev;
> +
> +   dev =3D qdev_create(NUL= L, TYPE_IMX_SERIAL);
> +
> +   if (dev) {
> +  =     SysBusDevice *bus;
> +
> +       = bus =3D SYS_BUS_DEVICE(dev);
> +
> +       qdev_= init_nofail(dev);
> +
> +       if (addr !=3D (h= waddr)-1) {
> +           sysbus_mmio_map(bu= s, 0, addr);
> +       }
> +
> +   &n= bsp;   sysbus_connect_irq(bus, 0, irq);
> +   }
> +}<= br>
Can you leave the implementation in imx_serial.c? I don't see the ne= ed
for moving it out. There is no reason the c file cannot have all of_init _realize and _create.

I sure could,= but I wanted to move these Qdev functions to a single place where I could = nuke them together (removing a single file) when I don't need them anymore = (when porting KZM to SOC logic).


Regards,
Peter

>
>  type= def enum  {
>      NOCLK,
> @@ -31,4 +58,5 = @@ void imx_timerg_create(const hwaddr addr,
>       &= nbsp;                DeviceState *c= cm);
>
>
> +
>  #endif /* IMX_H */
> --<= br>> 2.1.4
>
>
------=_Part_3296401_723363540.1436169718398--