From patchwork Tue Aug 11 14:15:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 52315 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by patches.linaro.org (Postfix) with ESMTPS id 3C57B22DD6 for ; Tue, 11 Aug 2015 14:15:39 +0000 (UTC) Received: by lbsm2 with SMTP id m2sf36766142lbs.1 for ; Tue, 11 Aug 2015 07:15:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=MVsv4chuQxrOXZSDpVlpJZ5MGdjTdxFG/Fvl/hHcN5A=; b=HpbjzWIvLtUjdSoAOLWqc/Vdp2EHV7fCFa4wd6R5apr01S/F9zxFIlDTpp4ZQmjzxi IxElAssD5CGfhgwl2DCgnLoHGYp4icBu9ENDvViD25KnG0Yybx6tTVfAaSrMJIrcraAg o0Ytjg7iUmpp3XWwa5bTiEmyN/hW5qGHVmp4FNPHxPnbe/dbrbWvuvpPFzEKTJV6IQAU RaVH/ZSvwtOZgVINUZVzsDzWfTCV+q05E2xscCggn1yMUTgOof/fgaBetdlNQucy2oru IouAuV9sqIuni7Mi8UFwSrWjlw8GXg3Gx5aG2jALNO2SQRNdZkjEvw67R8rrgzRE4K3j PArg== X-Gm-Message-State: ALoCoQkej/XPUfYaFWak8yvQWEFNhlUM7rCBQ/bCAl3AguPQ1WMMlnFt3xm9zxLjgmJVQuqEx2NS X-Received: by 10.112.138.2 with SMTP id qm2mr8153531lbb.19.1439302538260; Tue, 11 Aug 2015 07:15:38 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.36.201 with SMTP id s9ls466334laj.40.gmail; Tue, 11 Aug 2015 07:15:38 -0700 (PDT) X-Received: by 10.112.202.234 with SMTP id kl10mr26723560lbc.51.1439302538114; Tue, 11 Aug 2015 07:15:38 -0700 (PDT) Received: from mail-lb0-f170.google.com (mail-lb0-f170.google.com. [209.85.217.170]) by mx.google.com with ESMTPS id l7si1462827lbo.54.2015.08.11.07.15.38 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Aug 2015 07:15:38 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) client-ip=209.85.217.170; Received: by lbbtg9 with SMTP id tg9so7123849lbb.1 for ; Tue, 11 Aug 2015 07:15:38 -0700 (PDT) X-Received: by 10.152.36.102 with SMTP id p6mr26503192laj.19.1439302537968; Tue, 11 Aug 2015 07:15:37 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.7.198 with SMTP id l6csp2558006lba; Tue, 11 Aug 2015 07:15:36 -0700 (PDT) X-Received: by 10.70.38.10 with SMTP id c10mr56917960pdk.72.1439302532777; Tue, 11 Aug 2015 07:15:32 -0700 (PDT) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id cn9si3800365pdb.68.2015.08.11.07.15.30 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 11 Aug 2015 07:15:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::1 as permitted sender) client-ip=2001:8b0:1d0::1; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1ZPAKq-0004zG-QO; Tue, 11 Aug 2015 15:15:24 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Markus Armbruster Subject: [PATCH 1/3] hw/sd/pxa2xx_mmci: convert to SysBusDevice object Date: Tue, 11 Aug 2015 15:15:22 +0100 Message-Id: <1439302524-19142-2-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1439302524-19142-1-git-send-email-peter.maydell@linaro.org> References: <1439302524-19142-1-git-send-email-peter.maydell@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Convert the pxa2xx_mmci device to be a sysbus device. Signed-off-by: Peter Maydell --- hw/sd/pxa2xx_mmci.c | 96 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 79 insertions(+), 17 deletions(-) diff --git a/hw/sd/pxa2xx_mmci.c b/hw/sd/pxa2xx_mmci.c index d1fe6d5..5b676c7 100644 --- a/hw/sd/pxa2xx_mmci.c +++ b/hw/sd/pxa2xx_mmci.c @@ -11,16 +11,23 @@ */ #include "hw/hw.h" +#include "hw/sysbus.h" #include "hw/arm/pxa.h" #include "hw/sd.h" #include "hw/qdev.h" -struct PXA2xxMMCIState { +#define TYPE_PXA2XX_MMCI "pxa2xx-mmci" +#define PXA2XX_MMCI(obj) OBJECT_CHECK(PXA2xxMMCIState, (obj), TYPE_PXA2XX_MMCI) + +typedef struct PXA2xxMMCIState { + SysBusDevice parent_obj; + MemoryRegion iomem; qemu_irq irq; qemu_irq rx_dma; qemu_irq tx_dma; + void *blk; /* Should be a BlockBackend* */ SDState *card; uint32_t status; @@ -48,7 +55,7 @@ struct PXA2xxMMCIState { int resp_len; int cmdreq; -}; +} PXA2xxMMCIState; #define MMC_STRPCL 0x00 /* MMC Clock Start/Stop register */ #define MMC_STAT 0x04 /* MMC Status register */ @@ -474,31 +481,86 @@ PXA2xxMMCIState *pxa2xx_mmci_init(MemoryRegion *sysmem, BlockBackend *blk, qemu_irq irq, qemu_irq rx_dma, qemu_irq tx_dma) { - PXA2xxMMCIState *s; + DeviceState *dev; + SysBusDevice *sbd; + + dev = qdev_create(NULL, TYPE_PXA2XX_MMCI); + qdev_prop_set_ptr(dev, "drive", blk); + qdev_init_nofail(dev); + sbd = SYS_BUS_DEVICE(dev); + sysbus_mmio_map(sbd, 0, base); + sysbus_connect_irq(sbd, 0, irq); + sysbus_connect_irq(sbd, 1, rx_dma); + sysbus_connect_irq(sbd, 2, tx_dma); + return PXA2XX_MMCI(dev); +} - s = (PXA2xxMMCIState *) g_malloc0(sizeof(PXA2xxMMCIState)); - s->irq = irq; - s->rx_dma = rx_dma; - s->tx_dma = tx_dma; +void pxa2xx_mmci_handlers(PXA2xxMMCIState *s, qemu_irq readonly, + qemu_irq coverswitch) +{ + sd_set_cb(s->card, readonly, coverswitch); +} + +static void pxa2xx_mmci_instance_init(Object *obj) +{ + PXA2xxMMCIState *s = PXA2XX_MMCI(obj); + SysBusDevice *sbd = SYS_BUS_DEVICE(obj); - memory_region_init_io(&s->iomem, NULL, &pxa2xx_mmci_ops, s, + memory_region_init_io(&s->iomem, obj, &pxa2xx_mmci_ops, s, "pxa2xx-mmci", 0x00100000); - memory_region_add_subregion(sysmem, base, &s->iomem); + sysbus_init_mmio(sbd, &s->iomem); + sysbus_init_irq(sbd, &s->irq); + sysbus_init_irq(sbd, &s->rx_dma); + sysbus_init_irq(sbd, &s->tx_dma); + + register_savevm(NULL, "pxa2xx_mmci", 0, 0, + pxa2xx_mmci_save, pxa2xx_mmci_load, s); +} + +static void pxa2xx_mmci_realize(DeviceState *dev, Error **errp) +{ + PXA2xxMMCIState *s = PXA2XX_MMCI(dev); /* Instantiate the actual storage */ - s->card = sd_init(blk, false); + s->card = sd_init(s->blk, false); if (s->card == NULL) { - exit(1); + error_setg(errp, "Could not initialize SD card with specified drive"); + return; } +} - register_savevm(NULL, "pxa2xx_mmci", 0, 0, - pxa2xx_mmci_save, pxa2xx_mmci_load, s); +static Property pxa2xx_mmci_properties[] = { + /* Note: pointer property 'drive' may remain NULL, thus no need + * for dc->cannot_instantiate_with_device_add_yet = true; + * Unfortunately this can't be a DEFINE_PROP_DRIVE, because + * setting a 'drive' property results in a call to blk_attach_dev() + * attaching the BlockBackend to this device; that then means that + * the call in sd_init() to blk_attach_dev_nofail() which tries to + * attach the BlockBackend to the SD card object aborts. + */ + DEFINE_PROP_PTR("drive", PXA2xxMMCIState, blk), + DEFINE_PROP_END_OF_LIST(), +}; - return s; +static void pxa2xx_mmci_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + + dc->realize = pxa2xx_mmci_realize; + dc->props = pxa2xx_mmci_properties; } -void pxa2xx_mmci_handlers(PXA2xxMMCIState *s, qemu_irq readonly, - qemu_irq coverswitch) +static const TypeInfo pxa2xx_mmci_info = { + .name = TYPE_PXA2XX_MMCI, + .parent = TYPE_SYS_BUS_DEVICE, + .instance_size = sizeof(PXA2xxMMCIState), + .class_init = pxa2xx_mmci_class_init, + .instance_init = pxa2xx_mmci_instance_init, +}; + +static void pxa2xx_mmci_register_types(void) { - sd_set_cb(s->card, readonly, coverswitch); + type_register_static(&pxa2xx_mmci_info); } + +type_init(pxa2xx_mmci_register_types)