@@ -991,8 +991,10 @@ BlockBackend *pflash_cfi01_get_blk(DeviceState *dev)
return fl->blk;
}
-MemoryRegion *pflash_cfi01_get_memory(PFlashCFI01 *fl)
+MemoryRegion *pflash_cfi01_get_memory(DeviceState *dev)
{
+ PFlashCFI01 *fl = PFLASH_CFI01(dev);
+
return &fl->mem;
}
@@ -187,7 +187,7 @@ static void pc_system_flash_map(PCMachineState *pcms,
0x100000000ULL - total_size);
if (i == 0) {
- flash_mem = pflash_cfi01_get_memory(system_flash);
+ flash_mem = pflash_cfi01_get_memory(DEVICE(system_flash));
pc_isa_bios_init(rom_memory, flash_mem, size);
/* Encrypt the pflash boot ROM */
@@ -1291,7 +1291,8 @@ void mips_malta_init(MachineState *machine)
dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
65536,
4, 0x0000, 0x0000, 0x0000, 0x0000, be);
- bios = pflash_cfi01_get_memory(fl);
+ dev = DEVICE(fl);
+ bios = pflash_cfi01_get_memory(dev);
fl_idx++;
if (kernel_filename) {
ram_low_size = MIN(ram_size, 256 * MiB);
@@ -1144,7 +1144,7 @@ void ppce500_init(MachineState *machine)
sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
memory_region_add_subregion(&pms->pbus_dev->mmio, 0,
- pflash_cfi01_get_memory(PFLASH_CFI01(dev)));
+ pflash_cfi01_get_memory(dev));
}
/*
@@ -459,7 +459,7 @@ static void xtfpga_init(const XtfpgaBoardDesc *board, MachineState *machine)
}
} else {
if (flash) {
- MemoryRegion *flash_mr = pflash_cfi01_get_memory(flash);
+ MemoryRegion *flash_mr = pflash_cfi01_get_memory(DEVICE(flash));
MemoryRegion *flash_io = g_malloc(sizeof(*flash_io));
uint32_t size = env->config->sysrom.location[0].size;
@@ -22,7 +22,7 @@ PFlashCFI01 *pflash_cfi01_register(hwaddr base,
uint16_t id2, uint16_t id3,
int be);
BlockBackend *pflash_cfi01_get_blk(DeviceState *dev);
-MemoryRegion *pflash_cfi01_get_memory(PFlashCFI01 *fl);
+MemoryRegion *pflash_cfi01_get_memory(DeviceState *dev);
void pflash_cfi01_legacy_drive(DeviceState *dev, DriveInfo *dinfo);
/* pflash_cfi02.c */
The point of a getter() function is to not expose the structure internal fields. Otherwise callers could simply access the PFlashCFI01::mem field. Have the callers pass a DeviceState* argument. The QOM type check is done in the callee. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> --- hw/block/pflash_cfi01.c | 4 +++- hw/i386/pc_sysfw.c | 2 +- hw/mips/malta.c | 3 ++- hw/ppc/e500.c | 2 +- hw/xtensa/xtfpga.c | 2 +- include/hw/block/flash.h | 2 +- 6 files changed, 9 insertions(+), 6 deletions(-)