diff options
Diffstat (limited to 'hw/block/pflash_cfi01.c')
-rw-r--r-- | hw/block/pflash_cfi01.c | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c index 6898a257d9..2bcd7318bc 100644 --- a/hw/block/pflash_cfi01.c +++ b/hw/block/pflash_cfi01.c @@ -60,8 +60,14 @@ do { \ #define DPRINTF(fmt, ...) do { } while (0) #endif +#define TYPE_CFI_PFLASH01 "cfi.pflash01" +#define CFI_PFLASH01(obj) OBJECT_CHECK(pflash_t, (obj), TYPE_CFI_PFLASH01) + struct pflash_t { - SysBusDevice busdev; + /*< private >*/ + SysBusDevice parent_obj; + /*< public >*/ + BlockDriverState *bs; uint32_t nb_blocs; uint64_t sector_len; @@ -563,9 +569,9 @@ static const MemoryRegionOps pflash_cfi01_ops_le = { .endianness = DEVICE_NATIVE_ENDIAN, }; -static int pflash_cfi01_init(SysBusDevice *dev) +static void pflash_cfi01_realize(DeviceState *dev, Error **errp) { - pflash_t *pfl = FROM_SYSBUS(typeof(*pfl), dev); + pflash_t *pfl = CFI_PFLASH01(dev); uint64_t total_len; int ret; @@ -584,7 +590,7 @@ static int pflash_cfi01_init(SysBusDevice *dev) pfl->name, total_len); vmstate_register_ram(&pfl->mem, DEVICE(pfl)); pfl->storage = memory_region_get_ram_ptr(&pfl->mem); - sysbus_init_mmio(dev, &pfl->mem); + sysbus_init_mmio(SYS_BUS_DEVICE(dev), &pfl->mem); if (pfl->bs) { /* read the initial flash content */ @@ -593,7 +599,8 @@ static int pflash_cfi01_init(SysBusDevice *dev) if (ret < 0) { vmstate_unregister_ram(&pfl->mem, DEVICE(pfl)); memory_region_destroy(&pfl->mem); - return 1; + error_setg(errp, "failed to read the initial flash content"); + return; } } @@ -690,8 +697,6 @@ static int pflash_cfi01_init(SysBusDevice *dev) pfl->cfi_table[0x3c] = 0x00; pfl->cfi_table[0x3f] = 0x01; /* Number of protection fields */ - - return 0; } static Property pflash_cfi01_properties[] = { @@ -711,16 +716,15 @@ static Property pflash_cfi01_properties[] = { static void pflash_cfi01_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); - k->init = pflash_cfi01_init; + dc->realize = pflash_cfi01_realize; dc->props = pflash_cfi01_properties; dc->vmsd = &vmstate_pflash; } static const TypeInfo pflash_cfi01_info = { - .name = "cfi.pflash01", + .name = TYPE_CFI_PFLASH01, .parent = TYPE_SYS_BUS_DEVICE, .instance_size = sizeof(struct pflash_t), .class_init = pflash_cfi01_class_init, @@ -741,10 +745,7 @@ pflash_t *pflash_cfi01_register(hwaddr base, uint16_t id0, uint16_t id1, uint16_t id2, uint16_t id3, int be) { - DeviceState *dev = qdev_create(NULL, "cfi.pflash01"); - SysBusDevice *busdev = SYS_BUS_DEVICE(dev); - pflash_t *pfl = (pflash_t *)object_dynamic_cast(OBJECT(dev), - "cfi.pflash01"); + DeviceState *dev = qdev_create(NULL, TYPE_CFI_PFLASH01); if (bs && qdev_prop_set_drive(dev, "drive", bs)) { abort(); @@ -760,8 +761,8 @@ pflash_t *pflash_cfi01_register(hwaddr base, qdev_prop_set_string(dev, "name", name); qdev_init_nofail(dev); - sysbus_mmio_map(busdev, 0, base); - return pfl; + sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base); + return CFI_PFLASH01(dev); } MemoryRegion *pflash_cfi01_get_memory(pflash_t *fl) |