summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilippe Mathieu-Daudé2018-01-16 14:28:17 +0100
committerPeter Maydell2018-01-16 14:28:17 +0100
commit253674981e2449128ab25b35659a55857c60d5c4 (patch)
tree02e6a417b5f90fdd376da6e7f51026d73d720278
parentsdhci: refactor common sysbus/pci class_init() into sdhci_common_class_init() (diff)
downloadqemu-253674981e2449128ab25b35659a55857c60d5c4.tar.gz
qemu-253674981e2449128ab25b35659a55857c60d5c4.tar.xz
qemu-253674981e2449128ab25b35659a55857c60d5c4.zip
sdhci: refactor common sysbus/pci realize() into sdhci_common_realize()
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Reviewed-by: Alistair Francis <alistair.francis@xilinx.com> Message-id: 20180115182436.2066-6-f4bug@amsat.org Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
-rw-r--r--hw/sd/sdhci.c30
1 files changed, 21 insertions, 9 deletions
diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c
index 15d0961ac7..cf0c079990 100644
--- a/hw/sd/sdhci.c
+++ b/hw/sd/sdhci.c
@@ -1214,6 +1214,15 @@ static void sdhci_uninitfn(SDHCIState *s)
s->fifo_buffer = NULL;
}
+static void sdhci_common_realize(SDHCIState *s, Error **errp)
+{
+ s->buf_maxsz = sdhci_get_fifolen(s);
+ s->fifo_buffer = g_malloc0(s->buf_maxsz);
+
+ memory_region_init_io(&s->iomem, OBJECT(s), &sdhci_mmio_ops, s, "sdhci",
+ SDHC_REGISTERS_MAP_SIZE);
+}
+
static bool sdhci_pending_insert_vmstate_needed(void *opaque)
{
SDHCIState *s = opaque;
@@ -1292,14 +1301,16 @@ static Property sdhci_pci_properties[] = {
static void sdhci_pci_realize(PCIDevice *dev, Error **errp)
{
SDHCIState *s = PCI_SDHCI(dev);
+
+ sdhci_initfn(s);
+ sdhci_common_realize(s, errp);
+ if (errp && *errp) {
+ return;
+ }
+
dev->config[PCI_CLASS_PROG] = 0x01; /* Standard Host supported DMA */
dev->config[PCI_INTERRUPT_PIN] = 0x01; /* interrupt pin A */
- sdhci_initfn(s);
- s->buf_maxsz = sdhci_get_fifolen(s);
- s->fifo_buffer = g_malloc0(s->buf_maxsz);
s->irq = pci_allocate_irq(dev);
- memory_region_init_io(&s->iomem, OBJECT(s), &sdhci_mmio_ops, s, "sdhci",
- SDHC_REGISTERS_MAP_SIZE);
pci_register_bar(dev, 0, 0, &s->iomem);
}
@@ -1362,11 +1373,12 @@ static void sdhci_sysbus_realize(DeviceState *dev, Error ** errp)
SDHCIState *s = SYSBUS_SDHCI(dev);
SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
- s->buf_maxsz = sdhci_get_fifolen(s);
- s->fifo_buffer = g_malloc0(s->buf_maxsz);
+ sdhci_common_realize(s, errp);
+ if (errp && *errp) {
+ return;
+ }
+
sysbus_init_irq(sbd, &s->irq);
- memory_region_init_io(&s->iomem, OBJECT(s), &sdhci_mmio_ops, s, "sdhci",
- SDHC_REGISTERS_MAP_SIZE);
sysbus_init_mmio(sbd, &s->iomem);
}