From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38049) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VTbeC-000548-Uh for qemu-devel@nongnu.org; Tue, 08 Oct 2013 14:05:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VTbdu-0007aC-E1 for qemu-devel@nongnu.org; Tue, 08 Oct 2013 14:04:40 -0400 Received: from cantor2.suse.de ([195.135.220.15]:43038 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VTbdu-0007Xq-0P for qemu-devel@nongnu.org; Tue, 08 Oct 2013 14:04:22 -0400 Received: from relay1.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id C6C97A57B7 for ; Tue, 8 Oct 2013 19:45:08 +0200 (CEST) From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Tue, 8 Oct 2013 19:44:56 +0200 Message-Id: <1381254296-3203-59-git-send-email-afaerber@suse.de> In-Reply-To: <1381254296-3203-1-git-send-email-afaerber@suse.de> References: <1381254296-3203-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 58/58] pcmcia/pxa2xx: QOM'ify PXA2xxPCMCIAState List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Andreas=20F=C3=A4rber?= Turn it into a SysBusDevice and use a container MemoryRegion. Add a link property to the PCMCIACardState. Signed-off-by: Andreas F=C3=A4rber --- hw/pcmcia/pxa2xx.c | 78 +++++++++++++++++++++++++++++++++++++++++++++---= ------ 1 file changed, 66 insertions(+), 12 deletions(-) diff --git a/hw/pcmcia/pxa2xx.c b/hw/pcmcia/pxa2xx.c index 2c515be..8f17596 100644 --- a/hw/pcmcia/pxa2xx.c +++ b/hw/pcmcia/pxa2xx.c @@ -11,19 +11,27 @@ */ =20 #include "hw/hw.h" +#include "hw/sysbus.h" #include "hw/pcmcia.h" #include "hw/arm/pxa.h" =20 +#define TYPE_PXA2XX_PCMCIA "pxa2xx-pcmcia" +#define PXA2XX_PCMCIA(obj) \ + OBJECT_CHECK(PXA2xxPCMCIAState, obj, TYPE_PXA2XX_PCMCIA) =20 struct PXA2xxPCMCIAState { + SysBusDevice parent_obj; + PCMCIASocket slot; - PCMCIACardState *card; + MemoryRegion container_mem; MemoryRegion common_iomem; MemoryRegion attr_iomem; MemoryRegion iomem; =20 qemu_irq irq; qemu_irq cd_irq; + + PCMCIACardState *card; }; =20 static uint64_t pxa2xx_pcmcia_common_read(void *opaque, @@ -134,15 +142,43 @@ static void pxa2xx_pcmcia_set_irq(void *opaque, int= line, int level) PXA2xxPCMCIAState *pxa2xx_pcmcia_init(MemoryRegion *sysmem, hwaddr base) { + DeviceState *dev; PXA2xxPCMCIAState *s; =20 - s =3D (PXA2xxPCMCIAState *) - g_malloc0(sizeof(PXA2xxPCMCIAState)); + dev =3D qdev_create(NULL, TYPE_PXA2XX_PCMCIA); + sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base); + s =3D PXA2XX_PCMCIA(dev); + + if (base =3D=3D 0x30000000) { + s->slot.slot_string =3D "PXA PC Card Socket 1"; + } else { + s->slot.slot_string =3D "PXA PC Card Socket 0"; + } + + qdev_init_nofail(dev); + + return s; +} + +static void pxa2xx_pcmcia_realize(DeviceState *dev, Error **errp) +{ + PXA2xxPCMCIAState *s =3D PXA2XX_PCMCIA(dev); + + pcmcia_socket_register(&s->slot); +} + +static void pxa2xx_pcmcia_initfn(Object *obj) +{ + SysBusDevice *sbd =3D SYS_BUS_DEVICE(obj); + PXA2xxPCMCIAState *s =3D PXA2XX_PCMCIA(obj); + + memory_region_init(&s->container_mem, obj, "container", 0x10000000); + sysbus_init_mmio(sbd, &s->container_mem); =20 /* Socket I/O Memory Space */ memory_region_init_io(&s->iomem, NULL, &pxa2xx_pcmcia_io_ops, s, "pxa2xx-pcmcia-io", 0x04000000); - memory_region_add_subregion(sysmem, base | 0x00000000, + memory_region_add_subregion(&s->container_mem, 0x00000000, &s->iomem); =20 /* Then next 64 MB is reserved */ @@ -150,23 +186,19 @@ PXA2xxPCMCIAState *pxa2xx_pcmcia_init(MemoryRegion = *sysmem, /* Socket Attribute Memory Space */ memory_region_init_io(&s->attr_iomem, NULL, &pxa2xx_pcmcia_attr_ops,= s, "pxa2xx-pcmcia-attribute", 0x04000000); - memory_region_add_subregion(sysmem, base | 0x08000000, + memory_region_add_subregion(&s->container_mem, 0x08000000, &s->attr_iomem); =20 /* Socket Common Memory Space */ memory_region_init_io(&s->common_iomem, NULL, &pxa2xx_pcmcia_common_= ops, s, "pxa2xx-pcmcia-common", 0x04000000); - memory_region_add_subregion(sysmem, base | 0x0c000000, + memory_region_add_subregion(&s->container_mem, 0x0c000000, &s->common_iomem); =20 - if (base =3D=3D 0x30000000) - s->slot.slot_string =3D "PXA PC Card Socket 1"; - else - s->slot.slot_string =3D "PXA PC Card Socket 0"; s->slot.irq =3D qemu_allocate_irqs(pxa2xx_pcmcia_set_irq, s, 1)[0]; - pcmcia_socket_register(&s->slot); =20 - return s; + object_property_add_link(obj, "card", TYPE_PCMCIA_CARD, + (Object **)&s->card, NULL); } =20 /* Insert a new card into a slot */ @@ -227,3 +259,25 @@ void pxa2xx_pcmcia_set_irq_cb(void *opaque, qemu_irq= irq, qemu_irq cd_irq) s->irq =3D irq; s->cd_irq =3D cd_irq; } + +static void pxa2xx_pcmcia_class_init(ObjectClass *oc, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(oc); + + dc->realize =3D pxa2xx_pcmcia_realize; +} + +static const TypeInfo pxa2xx_pcmcia_type_info =3D { + .name =3D TYPE_PXA2XX_PCMCIA, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(PXA2xxPCMCIAState), + .instance_init =3D pxa2xx_pcmcia_initfn, + .class_init =3D pxa2xx_pcmcia_class_init, +}; + +static void pxa2xx_pcmcia_register_types(void) +{ + type_register_static(&pxa2xx_pcmcia_type_info); +} + +type_init(pxa2xx_pcmcia_register_types) --=20 1.8.1.4