From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55864) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b2eTR-0005fr-Uc for qemu-devel@nongnu.org; Tue, 17 May 2016 08:51:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b2eTN-0004FO-L7 for qemu-devel@nongnu.org; Tue, 17 May 2016 08:51:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47505) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b2eTN-0004FB-CQ for qemu-devel@nongnu.org; Tue, 17 May 2016 08:51:41 -0400 References: <1463108878-15956-1-git-send-email-zxq_yx_007@163.com> <1463108878-15956-3-git-send-email-zxq_yx_007@163.com> From: Paolo Bonzini Message-ID: <573B13D1.2070805@redhat.com> Date: Tue, 17 May 2016 14:51:29 +0200 MIME-Version: 1.0 In-Reply-To: <1463108878-15956-3-git-send-email-zxq_yx_007@163.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v3 2/4] hw/char: QOM'ify etraxfs_ser.c List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: xiaoqiang zhao , qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, agraf@suse.de, michael@walle.cc, edgar.iglesias@gmail.com, cornelia.huck@de.ibm.com On 13/05/2016 05:07, xiaoqiang zhao wrote: > * Drop the old SysBus init function and use instance_init > * Call qemu_chr_add_handlers in the realize callback > * Use qdev chardev prop instead of qemu_char_get_next_serial >=20 > Signed-off-by: xiaoqiang zhao > --- > hw/char/etraxfs_ser.c | 27 +++++++++++++++++---------- > 1 file changed, 17 insertions(+), 10 deletions(-) >=20 > diff --git a/hw/char/etraxfs_ser.c b/hw/char/etraxfs_ser.c > index 146b387..6957c68 100644 > --- a/hw/char/etraxfs_ser.c > +++ b/hw/char/etraxfs_ser.c > @@ -159,6 +159,11 @@ static const MemoryRegionOps ser_ops =3D { > } > }; > =20 > +static Property etraxfs_ser_properties[] =3D { > + DEFINE_PROP_CHR("etraxfs-serial", ETRAXSerial, chr), The usual name for this property is "chardev". > + DEFINE_PROP_END_OF_LIST(), > +}; > + > static void serial_receive(void *opaque, const uint8_t *buf, int size) > { > ETRAXSerial *s =3D opaque; > @@ -209,40 +214,42 @@ static void etraxfs_ser_reset(DeviceState *d) > =20 > } > =20 > -static int etraxfs_ser_init(SysBusDevice *dev) > +static void etraxfs_ser_init(Object *obj) > { > - ETRAXSerial *s =3D ETRAX_SERIAL(dev); > + ETRAXSerial *s =3D ETRAX_SERIAL(obj); > + SysBusDevice *dev =3D SYS_BUS_DEVICE(obj); > =20 > sysbus_init_irq(dev, &s->irq); > - memory_region_init_io(&s->mmio, OBJECT(s), &ser_ops, s, > + memory_region_init_io(&s->mmio, obj, &ser_ops, s, > "etraxfs-serial", R_MAX * 4); > sysbus_init_mmio(dev, &s->mmio); > +} > + > +static void etraxfs_ser_realize(DeviceState *dev, Error **errp) > +{ > + ETRAXSerial *s =3D ETRAX_SERIAL(dev); > =20 > - /* FIXME use a qdev chardev prop instead of qemu_char_get_next_ser= ial() */ > - s->chr =3D qemu_char_get_next_serial(); > if (s->chr) { > qemu_chr_add_handlers(s->chr, > serial_can_receive, serial_receive, > serial_event, s); > } > - return 0; > } > =20 > static void etraxfs_ser_class_init(ObjectClass *klass, void *data) > { > DeviceClass *dc =3D DEVICE_CLASS(klass); > - SysBusDeviceClass *k =3D SYS_BUS_DEVICE_CLASS(klass); > =20 > - k->init =3D etraxfs_ser_init; > dc->reset =3D etraxfs_ser_reset; > - /* Reason: init() method uses qemu_char_get_next_serial() */ > - dc->cannot_instantiate_with_device_add_yet =3D true; > + dc->props =3D etraxfs_ser_properties; > + dc->realize =3D etraxfs_ser_realize; > } > =20 > static const TypeInfo etraxfs_ser_info =3D { > .name =3D TYPE_ETRAX_FS_SERIAL, > .parent =3D TYPE_SYS_BUS_DEVICE, > .instance_size =3D sizeof(ETRAXSerial), > + .instance_init =3D etraxfs_ser_init, > .class_init =3D etraxfs_ser_class_init, > }; > =20 >=20 I'm sorry, this is not enough. You need to learn how to test this device. CRIS images are available at http://wiki.qemu.org/Testing. You have not added a replacement for the call to qemu_char_get_next_serial(). The board code in hw/cris/axis_dev88.c needs to use qemu_char_get_next_serial(). I suggest creating a function like void etraxfs_ser_create(hwaddr addr, qemu_irq irq, CharDriverState *chr) { DeviceState *dev; SysBusDevice *s; qemu_irq irq; dev =3D qdev_create(NULL, "extrafs,serial"); s =3D SYS_BUS_DEVICE(dev); qdev_prop_set_chr(s, "chardev", chr); qdev_init_nofail(dev); sysbus_mmio_map(s, 0, addr); sysbus_connect_irq(s, 0, irq); } and using it with qemu_char_get_next_serial() as the "chr" parameter. Note that this code is untested. Thanks, Paolo