Received: from eggs.gnu.org ([2001:4830:134:3::10]:60991) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YzjzV-0007wE-KE for qemu-devel@nongnu.org; Tue, 02 Jun 2015 07:04:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YzjzS-0005Ge-R4 for qemu-devel@nongnu.org; Tue, 02 Jun 2015 07:04:17 -0400 Received: from hall.aurel32.net ([2001:bc8:30d7:101::1]:59812) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YzjzS-0005GZ-IU for qemu-devel@nongnu.org; Tue, 02 Jun 2015 07:04:14 -0400 Date: Tue, 2 Jun 2015 13:04:13 +0200 From: Aurelien Jarno Message-ID: <20150602110413.GK26298@aurel32.net> References: <1432729200-5322-1-git-send-email-hpoussin@reactos.org> <1432729200-5322-12-git-send-email-hpoussin@reactos.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: <1432729200-5322-12-git-send-email-hpoussin@reactos.org> Sender: Aurelien Jarno Subject: Re: [Qemu-devel] [PATCH v2 11/17] net/dp8393x: QOM'ify List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?iso-8859-15?Q?Herv=E9?= Poussineau Cc: Leon Alrae , qemu-devel@nongnu.org, Laurent Vivier On 2015-05-27 14:19, Herv=E9 Poussineau wrote: > Signed-off-by: Laurent Vivier > Signed-off-by: Herv=E9 Poussineau > --- > hw/mips/mips_jazz.c | 12 ++++++-- > hw/net/dp8393x.c | 83 ++++++++++++++++++++++++++++++++++----------= ------ > include/hw/mips/mips.h | 5 --- > 3 files changed, 67 insertions(+), 33 deletions(-) >=20 > diff --git a/hw/mips/mips_jazz.c b/hw/mips/mips_jazz.c > index 29a13c0..648654e 100644 > --- a/hw/mips/mips_jazz.c > +++ b/hw/mips/mips_jazz.c > @@ -273,8 +273,16 @@ static void mips_jazz_init(MachineState *machine, > if (!nd->model) > nd->model =3D g_strdup("dp83932"); > if (strcmp(nd->model, "dp83932") =3D=3D 0) { > - dp83932_init(nd, 0x80001000, 2, get_system_memory(), > - qdev_get_gpio_in(rc4030, 4), rc4030_dma_mr); > + qemu_check_nic_model(nd, "dp83932"); > + > + dev =3D qdev_create(NULL, "dp8393x"); > + qdev_set_nic_properties(dev, nd); > + qdev_prop_set_uint8(dev, "it_shift", 2); > + qdev_prop_set_ptr(dev, "dma_mr", rc4030_dma_mr); > + qdev_init_nofail(dev); > + sysbus =3D SYS_BUS_DEVICE(dev); > + sysbus_mmio_map(sysbus, 0, 0x80001000); > + sysbus_connect_irq(sysbus, 0, qdev_get_gpio_in(rc4030, 4)); > break; > } else if (is_help_option(nd->model)) { > fprintf(stderr, "qemu: Supported NICs: dp83932\n"); > diff --git a/hw/net/dp8393x.c b/hw/net/dp8393x.c > index 0aff04f..51e728b 100644 > --- a/hw/net/dp8393x.c > +++ b/hw/net/dp8393x.c > @@ -17,10 +17,10 @@ > * with this program; if not, see . > */ > =20 > -#include "hw/hw.h" > -#include "qemu/timer.h" > +#include "hw/sysbus.h" > +#include "hw/devices.h" > #include "net/net.h" > -#include "hw/mips/mips.h" > +#include "qemu/timer.h" > #include > =20 > //#define DEBUG_SONIC > @@ -139,9 +139,14 @@ do { printf("sonic ERROR: %s: " fmt, __func__ , ## _= _VA_ARGS__); } while (0) > #define SONIC_ISR_PINT 0x0800 > #define SONIC_ISR_LCD 0x1000 > =20 > +#define TYPE_DP8393X "dp8393x" > +#define DP8393X(obj) OBJECT_CHECK(dp8393xState, (obj), TYPE_DP8393X) > + > typedef struct dp8393xState { > + SysBusDevice parent_obj; > + > /* Hardware */ > - int it_shift; > + uint8_t it_shift; > qemu_irq irq; > #ifdef DEBUG_SONIC > int irq_level; > @@ -150,7 +155,6 @@ typedef struct dp8393xState { > int64_t wt_last_update; > NICConf conf; > NICState *nic; > - MemoryRegion *address_space; > MemoryRegion mmio; > =20 > /* Registers */ > @@ -162,6 +166,7 @@ typedef struct dp8393xState { > int loopback_packet; > =20 > /* Memory access */ > + void *dma_mr; > AddressSpace as; > } dp8393xState; > =20 > @@ -774,9 +779,9 @@ static ssize_t dp8393x_receive(NetClientState *nc, co= nst uint8_t * buf, > return size; > } > =20 > -static void dp8393x_reset(void *opaque) > +static void dp8393x_reset(DeviceState *dev) > { > - dp8393xState *s =3D opaque; > + dp8393xState *s =3D DP8393X(dev); > timer_del(s->watchdog); > =20 > s->regs[SONIC_CR] =3D SONIC_CR_RST | SONIC_CR_STP | SONIC_CR_RXDIS; > @@ -805,33 +810,59 @@ static NetClientInfo net_dp83932_info =3D { > .receive =3D dp8393x_receive, > }; > =20 > -void dp83932_init(NICInfo *nd, hwaddr base, int it_shift, > - MemoryRegion *address_space, > - qemu_irq irq, MemoryRegion *dma_mr) > +static void dp8393x_instance_init(Object *obj) > { > - dp8393xState *s; > + SysBusDevice *sbd =3D SYS_BUS_DEVICE(obj); > + dp8393xState *s =3D DP8393X(obj); > =20 > - qemu_check_nic_model(nd, "dp83932"); > + sysbus_init_mmio(sbd, &s->mmio); > + sysbus_init_irq(sbd, &s->irq); > +} > + > +static void dp8393x_realize(DeviceState *dev, Error **errp) > +{ > + dp8393xState *s =3D DP8393X(dev); > =20 > - s =3D g_malloc0(sizeof(dp8393xState)); > + address_space_init(&s->as, s->dma_mr, "dp8393x"); > + memory_region_init_io(&s->mmio, OBJECT(dev), &dp8393x_ops, s, > + "dp8393x-regs", 0x40 << s->it_shift); > + > + s->nic =3D qemu_new_nic(&net_dp83932_info, &s->conf, > + object_get_typename(OBJECT(dev)), dev->id, s); > + qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); > =20 > - s->address_space =3D address_space; > - address_space_init(&s->as, dma_mr, "dp8393x-dma"); > - s->it_shift =3D it_shift; > - s->irq =3D irq; > s->watchdog =3D timer_new_ns(QEMU_CLOCK_VIRTUAL, dp8393x_watchdog, s= ); > s->regs[SONIC_SR] =3D 0x0004; /* only revision recognized by Linux */ > +} > =20 > - s->conf.macaddr =3D nd->macaddr; > - s->conf.peers.ncs[0] =3D nd->netdev; > +static Property dp8393x_properties[] =3D { > + DEFINE_NIC_PROPERTIES(dp8393xState, conf), > + DEFINE_PROP_PTR("dma_mr", dp8393xState, dma_mr), > + DEFINE_PROP_UINT8("it_shift", dp8393xState, it_shift, 0), > + DEFINE_PROP_END_OF_LIST(), > +}; > =20 > - s->nic =3D qemu_new_nic(&net_dp83932_info, &s->conf, nd->model, nd->= name, s); > +static void dp8393x_class_init(ObjectClass *klass, void *data) > +{ > + DeviceClass *dc =3D DEVICE_CLASS(klass); > =20 > - qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); > - qemu_register_reset(dp8393x_reset, s); > - dp8393x_reset(s); > + set_bit(DEVICE_CATEGORY_NETWORK, dc->categories); > + dc->realize =3D dp8393x_realize; > + dc->reset =3D dp8393x_reset; > + dc->props =3D dp8393x_properties; > +} > =20 > - memory_region_init_io(&s->mmio, NULL, &dp8393x_ops, s, > - "dp8393x", 0x40 << it_shift); > - memory_region_add_subregion(address_space, base, &s->mmio); > +static const TypeInfo dp8393x_info =3D { > + .name =3D TYPE_DP8393X, > + .parent =3D TYPE_SYS_BUS_DEVICE, > + .instance_size =3D sizeof(dp8393xState), > + .instance_init =3D dp8393x_instance_init, > + .class_init =3D dp8393x_class_init, > +}; > + > +static void dp8393x_register_types(void) > +{ > + type_register_static(&dp8393x_info); > } > + > +type_init(dp8393x_register_types) > diff --git a/include/hw/mips/mips.h b/include/hw/mips/mips.h > index 31b4729..e0065ce 100644 > --- a/include/hw/mips/mips.h > +++ b/include/hw/mips/mips.h > @@ -20,9 +20,4 @@ void rc4030_dma_write(void *dma, uint8_t *buf, int len); > =20 > DeviceState *rc4030_init(rc4030_dma **dmas, MemoryRegion **dma_mr); > =20 > -/* dp8393x.c */ > -void dp83932_init(NICInfo *nd, hwaddr base, int it_shift, > - MemoryRegion *address_space, > - qemu_irq irq, MemoryRegion *dma_mr); > - > #endif I am not very comfortable with the QOM API, but it looks fine to me. Reviewed-by: Aurelien Jarno --=20 Aurelien Jarno GPG: 4096R/1DDD8C9B aurelien@aurel32.net http://www.aurel32.net