From a1ae0e85037b3ea5a4dc9a81d5de1acd509c0d05 Mon Sep 17 00:00:00 2001 From: Andrew Baumann Date: Wed, 25 Nov 2015 15:00:16 -0800 Subject: [PATCH] bcm2835_emmc: convert to header file and init/realize --- hw/arm/bcm2835_peripherals.c | 12 ++--- hw/sd/bcm2835_emmc.c | 96 ++++++++++-------------------------- include/hw/arm/bcm2835_peripherals.h | 4 +- include/hw/sd/bcm2835_emmc.h | 56 +++++++++++++++++++++ 4 files changed, 91 insertions(+), 77 deletions(-) create mode 100644 include/hw/sd/bcm2835_emmc.h diff --git a/hw/arm/bcm2835_peripherals.c b/hw/arm/bcm2835_peripherals.c index 3796c0df17..32955700bb 100644 --- a/hw/arm/bcm2835_peripherals.c +++ b/hw/arm/bcm2835_peripherals.c @@ -106,9 +106,9 @@ static void bcm2835_peripherals_init(Object *obj) qdev_set_parent_bus(DEVICE(&s->vchiq), sysbus_get_default()); /* Extended Mass Media Controller */ - s->emmc = dev = SYS_BUS_DEVICE(object_new("bcm2835_emmc")); - object_property_add_child(obj, "emmc", OBJECT(dev), NULL); - qdev_set_parent_bus(DEVICE(dev), sysbus_get_default()); + object_initialize(&s->emmc, sizeof(s->emmc), TYPE_BCM2835_EMMC); + object_property_add_child(obj, "emmc", OBJECT(&s->emmc), NULL); + qdev_set_parent_bus(DEVICE(&s->emmc), sysbus_get_default()); /* DMA Channels */ object_initialize(&s->dma, sizeof(s->dma), TYPE_BCM2835_DMA); @@ -312,15 +312,15 @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp) qdev_get_gpio_in(DEVICE(&s->sbm), MBOX_CHAN_VCHIQ)); /* Extended Mass Media Controller */ - object_property_set_bool(OBJECT(s->emmc), true, "realized", &err); + object_property_set_bool(OBJECT(&s->emmc), true, "realized", &err); if (err) { error_propagate(errp, err); return; } memory_region_add_subregion(&s->peri_mr, EMMC_OFFSET, - sysbus_mmio_get_region(s->emmc, 0)); - sysbus_connect_irq(s->emmc, 0, + sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->emmc), 0)); + sysbus_connect_irq(SYS_BUS_DEVICE(&s->emmc), 0, qdev_get_gpio_in(DEVICE(&s->ic), INTERRUPT_VC_ARASANSDIO)); diff --git a/hw/sd/bcm2835_emmc.c b/hw/sd/bcm2835_emmc.c index 5c7caba41f..46628b5549 100644 --- a/hw/sd/bcm2835_emmc.c +++ b/hw/sd/bcm2835_emmc.c @@ -3,10 +3,8 @@ * This code is licensed under the GNU GPLv2 and later. */ -#include "qemu/timer.h" -#include "hw/sysbus.h" -#include "hw/sd/sd.h" #include "sysemu/blockdev.h" +#include "hw/sd/bcm2835_emmc.h" /* * Controller registers @@ -294,51 +292,7 @@ #define COMPLETION_DELAY (100000) -#define TYPE_BCM2835_EMMC "bcm2835_emmc" -#define BCM2835_EMMC(obj) \ - OBJECT_CHECK(Bcm2835EmmcState, (obj), TYPE_BCM2835_EMMC) - -typedef struct { - SysBusDevice busdev; - MemoryRegion iomem; - - SDState *card; - - uint32_t arg2; - uint32_t blksizecnt; - uint32_t arg1; - uint32_t cmdtm; - uint32_t resp0; - uint32_t resp1; - uint32_t resp2; - uint32_t resp3; - uint32_t data; - uint32_t status; - uint32_t control0; - uint32_t control1; - uint32_t interrupt; - uint32_t irpt_mask; - uint32_t irpt_en; - uint32_t control2; - uint32_t force_irpt; - uint32_t spi_int_spt; - uint32_t slotisr_ver; - uint32_t caps; - uint32_t caps2; - uint32_t maxcurr; - uint32_t maxcurr2; - - int acmd; - int write_op; - - uint32_t bytecnt; - - QEMUTimer *delay_timer; - qemu_irq irq; - -} Bcm2835EmmcState; - -static void bcm2835_emmc_set_irq(Bcm2835EmmcState *s) +static void bcm2835_emmc_set_irq(BCM2835EmmcState *s) { /* the error bit must be set iff there are any other errors */ assert(((s->interrupt & SDHCI_INT_ERROR) == 0) @@ -351,7 +305,7 @@ static void bcm2835_emmc_set_irq(Bcm2835EmmcState *s) } } -static void autocmd12(Bcm2835EmmcState *s) +static void autocmd12(BCM2835EmmcState *s) { SDRequest request; uint8_t response[16]; @@ -366,7 +320,7 @@ static void autocmd12(Bcm2835EmmcState *s) sd_do_command(s->card, &request, response); } -static void autocmd23(Bcm2835EmmcState *s) +static void autocmd23(BCM2835EmmcState *s) { SDRequest request; uint8_t response[16]; @@ -383,7 +337,7 @@ static void autocmd23(Bcm2835EmmcState *s) static void delayed_completion(void *opaque) { - Bcm2835EmmcState *s = (Bcm2835EmmcState *)opaque; + BCM2835EmmcState *s = (BCM2835EmmcState *)opaque; s->interrupt |= SDHCI_INT_DATA_END; autocmd12(s); @@ -395,7 +349,7 @@ static void delayed_completion(void *opaque) static uint64_t bcm2835_emmc_read(void *opaque, hwaddr offset, unsigned size) { - Bcm2835EmmcState *s = (Bcm2835EmmcState *)opaque; + BCM2835EmmcState *s = (BCM2835EmmcState *)opaque; uint32_t res = 0; uint8_t tmp = 0; int set_irq = 0; @@ -539,7 +493,7 @@ static uint64_t bcm2835_emmc_read(void *opaque, hwaddr offset, static void bcm2835_emmc_write(void *opaque, hwaddr offset, uint64_t value, unsigned size) { - Bcm2835EmmcState *s = (Bcm2835EmmcState *)opaque; + BCM2835EmmcState *s = (BCM2835EmmcState *)opaque; uint8_t cmd; SDRequest request; uint8_t response[16]; @@ -763,16 +717,25 @@ static const VMStateDescription vmstate_bcm2835_emmc = { } }; -static int bcm2835_emmc_init(SysBusDevice *sbd) +static void bcm2835_emmc_init(Object *obj) { + BCM2835EmmcState *s = BCM2835_EMMC(obj); + + memory_region_init_io(&s->iomem, OBJECT(s), &bcm2835_emmc_ops, s, + TYPE_BCM2835_EMMC, 0x100000); + sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->iomem); + sysbus_init_irq(SYS_BUS_DEVICE(s), &s->irq); +} + +static void bcm2835_emmc_realize(DeviceState *dev, Error **errp) +{ + BCM2835EmmcState *s = BCM2835_EMMC(dev); DriveInfo *dinfo; - DeviceState *dev = DEVICE(sbd); - Bcm2835EmmcState *s = BCM2835_EMMC(dev); dinfo = drive_get(IF_SD, 0, 0); if (!dinfo) { - fprintf(stderr, "bcm2835_emmc: missing SD card\n"); - exit(1); + error_setg(errp, "bcm2835_emmc: missing SD card"); + return; } s->card = sd_init(blk_by_legacy_dinfo(dinfo), 0); @@ -811,29 +774,22 @@ static int bcm2835_emmc_init(SysBusDevice *sbd) s->write_op = 0; s->delay_timer = timer_new_us(QEMU_CLOCK_VIRTUAL, delayed_completion, s); - - memory_region_init_io(&s->iomem, OBJECT(s), &bcm2835_emmc_ops, s, - TYPE_BCM2835_EMMC, 0x100000); - sysbus_init_mmio(sbd, &s->iomem); - vmstate_register(dev, -1, &vmstate_bcm2835_emmc, s); - - sysbus_init_irq(sbd, &s->irq); - - return 0; } static void bcm2835_emmc_class_init(ObjectClass *klass, void *data) { - SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass); + DeviceClass *dc = DEVICE_CLASS(klass); - sdc->init = bcm2835_emmc_init; + dc->realize = bcm2835_emmc_realize; + dc->vmsd = &vmstate_bcm2835_emmc; } static TypeInfo bcm2835_emmc_info = { .name = TYPE_BCM2835_EMMC, .parent = TYPE_SYS_BUS_DEVICE, - .instance_size = sizeof(Bcm2835EmmcState), + .instance_size = sizeof(BCM2835EmmcState), .class_init = bcm2835_emmc_class_init, + .instance_init = bcm2835_emmc_init, }; static void bcm2835_emmc_register_types(void) diff --git a/include/hw/arm/bcm2835_peripherals.h b/include/hw/arm/bcm2835_peripherals.h index d0062873c7..e200c37524 100644 --- a/include/hw/arm/bcm2835_peripherals.h +++ b/include/hw/arm/bcm2835_peripherals.h @@ -23,6 +23,7 @@ #include "hw/misc/bcm2835_property.h" #include "hw/misc/bcm2835_sbm.h" #include "hw/misc/bcm2835_vchiq.h" +#include "hw/sd/bcm2835_emmc.h" #define TYPE_BCM2835_PERIPHERALS "bcm2835_peripherals" #define BCM2835_PERIPHERALS(obj) \ @@ -46,7 +47,8 @@ typedef struct BCM2835PeripheralState { BCM2835PropertyState property; BCM2835SbmState sbm; BCM2835VchiqState vchiq; - SysBusDevice *uart0, *systimer, *armtimer, *usb, *emmc; + BCM2835EmmcState emmc; + SysBusDevice *uart0, *systimer, *armtimer, *usb; } BCM2835PeripheralState; #endif /* BCM2835_PERIPHERALS_H */ diff --git a/include/hw/sd/bcm2835_emmc.h b/include/hw/sd/bcm2835_emmc.h new file mode 100644 index 0000000000..b756c67019 --- /dev/null +++ b/include/hw/sd/bcm2835_emmc.h @@ -0,0 +1,56 @@ +/* + * Raspberry Pi emulation (c) 2012 Gregory Estrade + * This code is licensed under the GNU GPLv2 and later. + */ + +#ifndef BCM2835_EMMC_H +#define BCM2835_EMMC_H + +#include "hw/sysbus.h" +#include "hw/sd/sd.h" +#include "qemu/timer.h" + +#define TYPE_BCM2835_EMMC "bcm2835_emmc" +#define BCM2835_EMMC(obj) \ + OBJECT_CHECK(BCM2835EmmcState, (obj), TYPE_BCM2835_EMMC) + +typedef struct { + SysBusDevice busdev; + MemoryRegion iomem; + + SDState *card; + + uint32_t arg2; + uint32_t blksizecnt; + uint32_t arg1; + uint32_t cmdtm; + uint32_t resp0; + uint32_t resp1; + uint32_t resp2; + uint32_t resp3; + uint32_t data; + uint32_t status; + uint32_t control0; + uint32_t control1; + uint32_t interrupt; + uint32_t irpt_mask; + uint32_t irpt_en; + uint32_t control2; + uint32_t force_irpt; + uint32_t spi_int_spt; + uint32_t slotisr_ver; + uint32_t caps; + uint32_t caps2; + uint32_t maxcurr; + uint32_t maxcurr2; + + int acmd; + int write_op; + + uint32_t bytecnt; + + QEMUTimer *delay_timer; + qemu_irq irq; +} BCM2835EmmcState; + +#endif -- 2.11.4.GIT