hw/arm: Let devices own the MemoryRegion they create

Avoid orphan memory regions being added in the /unattached QOM
container.

This commit was produced with the Coccinelle script
scripts/coccinelle/memory-region-housekeeping.cocci.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
This commit is contained in:
Philippe Mathieu-Daudé 2020-02-24 18:32:23 +01:00 committed by Paolo Bonzini
parent 5b871c1b62
commit 32b9523ad5
10 changed files with 40 additions and 39 deletions

View File

@ -305,20 +305,20 @@ static void exynos4210_realize(DeviceState *socdev, Error **errp)
/*** Memory ***/ /*** Memory ***/
/* Chip-ID and OMR */ /* Chip-ID and OMR */
memory_region_init_io(&s->chipid_mem, NULL, &exynos4210_chipid_and_omr_ops, memory_region_init_io(&s->chipid_mem, OBJECT(socdev),
NULL, "exynos4210.chipid", sizeof(chipid_and_omr)); &exynos4210_chipid_and_omr_ops, NULL,
"exynos4210.chipid", sizeof(chipid_and_omr));
memory_region_add_subregion(system_mem, EXYNOS4210_CHIPID_ADDR, memory_region_add_subregion(system_mem, EXYNOS4210_CHIPID_ADDR,
&s->chipid_mem); &s->chipid_mem);
/* Internal ROM */ /* Internal ROM */
memory_region_init_rom(&s->irom_mem, NULL, "exynos4210.irom", memory_region_init_rom(&s->irom_mem, OBJECT(socdev), "exynos4210.irom",
EXYNOS4210_IROM_SIZE, &error_fatal); EXYNOS4210_IROM_SIZE, &error_fatal);
memory_region_add_subregion(system_mem, EXYNOS4210_IROM_BASE_ADDR, memory_region_add_subregion(system_mem, EXYNOS4210_IROM_BASE_ADDR,
&s->irom_mem); &s->irom_mem);
/* mirror of iROM */ /* mirror of iROM */
memory_region_init_alias(&s->irom_alias_mem, NULL, "exynos4210.irom_alias", memory_region_init_alias(&s->irom_alias_mem, OBJECT(socdev),
&s->irom_mem, "exynos4210.irom_alias", &s->irom_mem, 0,
0,
EXYNOS4210_IROM_SIZE); EXYNOS4210_IROM_SIZE);
memory_region_add_subregion(system_mem, EXYNOS4210_IROM_MIRROR_BASE_ADDR, memory_region_add_subregion(system_mem, EXYNOS4210_IROM_MIRROR_BASE_ADDR,
&s->irom_alias_mem); &s->irom_alias_mem);

View File

@ -303,16 +303,16 @@ static void fsl_imx25_realize(DeviceState *dev, Error **errp)
} }
/* initialize 2 x 16 KB ROM */ /* initialize 2 x 16 KB ROM */
memory_region_init_rom(&s->rom[0], NULL, memory_region_init_rom(&s->rom[0], OBJECT(dev), "imx25.rom0",
"imx25.rom0", FSL_IMX25_ROM0_SIZE, &err); FSL_IMX25_ROM0_SIZE, &err);
if (err) { if (err) {
error_propagate(errp, err); error_propagate(errp, err);
return; return;
} }
memory_region_add_subregion(get_system_memory(), FSL_IMX25_ROM0_ADDR, memory_region_add_subregion(get_system_memory(), FSL_IMX25_ROM0_ADDR,
&s->rom[0]); &s->rom[0]);
memory_region_init_rom(&s->rom[1], NULL, memory_region_init_rom(&s->rom[1], OBJECT(dev), "imx25.rom1",
"imx25.rom1", FSL_IMX25_ROM1_SIZE, &err); FSL_IMX25_ROM1_SIZE, &err);
if (err) { if (err) {
error_propagate(errp, err); error_propagate(errp, err);
return; return;
@ -331,7 +331,7 @@ static void fsl_imx25_realize(DeviceState *dev, Error **errp)
&s->iram); &s->iram);
/* internal RAM (128 KB) is aliased over 128 MB - 128 KB */ /* internal RAM (128 KB) is aliased over 128 MB - 128 KB */
memory_region_init_alias(&s->iram_alias, NULL, "imx25.iram_alias", memory_region_init_alias(&s->iram_alias, OBJECT(dev), "imx25.iram_alias",
&s->iram, 0, FSL_IMX25_IRAM_ALIAS_SIZE); &s->iram, 0, FSL_IMX25_IRAM_ALIAS_SIZE);
memory_region_add_subregion(get_system_memory(), FSL_IMX25_IRAM_ALIAS_ADDR, memory_region_add_subregion(get_system_memory(), FSL_IMX25_IRAM_ALIAS_ADDR,
&s->iram_alias); &s->iram_alias);

View File

@ -206,7 +206,7 @@ static void fsl_imx31_realize(DeviceState *dev, Error **errp)
} }
/* On a real system, the first 16k is a `secure boot rom' */ /* On a real system, the first 16k is a `secure boot rom' */
memory_region_init_rom(&s->secure_rom, NULL, "imx31.secure_rom", memory_region_init_rom(&s->secure_rom, OBJECT(dev), "imx31.secure_rom",
FSL_IMX31_SECURE_ROM_SIZE, &err); FSL_IMX31_SECURE_ROM_SIZE, &err);
if (err) { if (err) {
error_propagate(errp, err); error_propagate(errp, err);
@ -216,7 +216,7 @@ static void fsl_imx31_realize(DeviceState *dev, Error **errp)
&s->secure_rom); &s->secure_rom);
/* There is also a 16k ROM */ /* There is also a 16k ROM */
memory_region_init_rom(&s->rom, NULL, "imx31.rom", memory_region_init_rom(&s->rom, OBJECT(dev), "imx31.rom",
FSL_IMX31_ROM_SIZE, &err); FSL_IMX31_ROM_SIZE, &err);
if (err) { if (err) {
error_propagate(errp, err); error_propagate(errp, err);
@ -236,7 +236,7 @@ static void fsl_imx31_realize(DeviceState *dev, Error **errp)
&s->iram); &s->iram);
/* internal RAM (16 KB) is aliased over 256 MB - 16 KB */ /* internal RAM (16 KB) is aliased over 256 MB - 16 KB */
memory_region_init_alias(&s->iram_alias, NULL, "imx31.iram_alias", memory_region_init_alias(&s->iram_alias, OBJECT(dev), "imx31.iram_alias",
&s->iram, 0, FSL_IMX31_IRAM_ALIAS_SIZE); &s->iram, 0, FSL_IMX31_IRAM_ALIAS_SIZE);
memory_region_add_subregion(get_system_memory(), FSL_IMX31_IRAM_ALIAS_ADDR, memory_region_add_subregion(get_system_memory(), FSL_IMX31_IRAM_ALIAS_ADDR,
&s->iram_alias); &s->iram_alias);

View File

@ -405,7 +405,7 @@ static void fsl_imx6_realize(DeviceState *dev, Error **errp)
} }
/* ROM memory */ /* ROM memory */
memory_region_init_rom(&s->rom, NULL, "imx6.rom", memory_region_init_rom(&s->rom, OBJECT(dev), "imx6.rom",
FSL_IMX6_ROM_SIZE, &err); FSL_IMX6_ROM_SIZE, &err);
if (err) { if (err) {
error_propagate(errp, err); error_propagate(errp, err);
@ -415,7 +415,7 @@ static void fsl_imx6_realize(DeviceState *dev, Error **errp)
&s->rom); &s->rom);
/* CAAM memory */ /* CAAM memory */
memory_region_init_rom(&s->caam, NULL, "imx6.caam", memory_region_init_rom(&s->caam, OBJECT(dev), "imx6.caam",
FSL_IMX6_CAAM_MEM_SIZE, &err); FSL_IMX6_CAAM_MEM_SIZE, &err);
if (err) { if (err) {
error_propagate(errp, err); error_propagate(errp, err);
@ -435,7 +435,7 @@ static void fsl_imx6_realize(DeviceState *dev, Error **errp)
&s->ocram); &s->ocram);
/* internal OCRAM (256 KB) is aliased over 1 MB */ /* internal OCRAM (256 KB) is aliased over 1 MB */
memory_region_init_alias(&s->ocram_alias, NULL, "imx6.ocram_alias", memory_region_init_alias(&s->ocram_alias, OBJECT(dev), "imx6.ocram_alias",
&s->ocram, 0, FSL_IMX6_OCRAM_ALIAS_SIZE); &s->ocram, 0, FSL_IMX6_OCRAM_ALIAS_SIZE);
memory_region_add_subregion(get_system_memory(), FSL_IMX6_OCRAM_ALIAS_ADDR, memory_region_add_subregion(get_system_memory(), FSL_IMX6_OCRAM_ALIAS_ADDR,
&s->ocram_alias); &s->ocram_alias);

View File

@ -543,7 +543,7 @@ static void fsl_imx6ul_realize(DeviceState *dev, Error **errp)
/* /*
* ROM memory * ROM memory
*/ */
memory_region_init_rom(&s->rom, NULL, "imx6ul.rom", memory_region_init_rom(&s->rom, OBJECT(dev), "imx6ul.rom",
FSL_IMX6UL_ROM_SIZE, &error_abort); FSL_IMX6UL_ROM_SIZE, &error_abort);
memory_region_add_subregion(get_system_memory(), FSL_IMX6UL_ROM_ADDR, memory_region_add_subregion(get_system_memory(), FSL_IMX6UL_ROM_ADDR,
&s->rom); &s->rom);
@ -551,7 +551,7 @@ static void fsl_imx6ul_realize(DeviceState *dev, Error **errp)
/* /*
* CAAM memory * CAAM memory
*/ */
memory_region_init_rom(&s->caam, NULL, "imx6ul.caam", memory_region_init_rom(&s->caam, OBJECT(dev), "imx6ul.caam",
FSL_IMX6UL_CAAM_MEM_SIZE, &error_abort); FSL_IMX6UL_CAAM_MEM_SIZE, &error_abort);
memory_region_add_subregion(get_system_memory(), FSL_IMX6UL_CAAM_MEM_ADDR, memory_region_add_subregion(get_system_memory(), FSL_IMX6UL_CAAM_MEM_ADDR,
&s->caam); &s->caam);
@ -568,8 +568,9 @@ static void fsl_imx6ul_realize(DeviceState *dev, Error **errp)
/* /*
* internal OCRAM (128 KB) is aliased over 512 KB * internal OCRAM (128 KB) is aliased over 512 KB
*/ */
memory_region_init_alias(&s->ocram_alias, NULL, "imx6ul.ocram_alias", memory_region_init_alias(&s->ocram_alias, OBJECT(dev),
&s->ocram, 0, FSL_IMX6UL_OCRAM_ALIAS_SIZE); "imx6ul.ocram_alias", &s->ocram, 0,
FSL_IMX6UL_OCRAM_ALIAS_SIZE);
memory_region_add_subregion(get_system_memory(), memory_region_add_subregion(get_system_memory(),
FSL_IMX6UL_OCRAM_ALIAS_ADDR, &s->ocram_alias); FSL_IMX6UL_OCRAM_ALIAS_ADDR, &s->ocram_alias);
} }

View File

@ -96,7 +96,7 @@ static void m2sxxx_soc_realize(DeviceState *dev_soc, Error **errp)
MemoryRegion *nvm_alias = g_new(MemoryRegion, 1); MemoryRegion *nvm_alias = g_new(MemoryRegion, 1);
MemoryRegion *sram = g_new(MemoryRegion, 1); MemoryRegion *sram = g_new(MemoryRegion, 1);
memory_region_init_rom(nvm, NULL, "MSF2.eNVM", s->envm_size, memory_region_init_rom(nvm, OBJECT(dev_soc), "MSF2.eNVM", s->envm_size,
&error_fatal); &error_fatal);
/* /*
* On power-on, the eNVM region 0x60000000 is automatically * On power-on, the eNVM region 0x60000000 is automatically
@ -104,8 +104,8 @@ static void m2sxxx_soc_realize(DeviceState *dev_soc, Error **errp)
* start address (0x0). We do not support remapping other eNVM, * start address (0x0). We do not support remapping other eNVM,
* eSRAM and DDR regions by guest(via Sysreg) currently. * eSRAM and DDR regions by guest(via Sysreg) currently.
*/ */
memory_region_init_alias(nvm_alias, NULL, "MSF2.eNVM", memory_region_init_alias(nvm_alias, OBJECT(dev_soc), "MSF2.eNVM", nvm, 0,
nvm, 0, s->envm_size); s->envm_size);
memory_region_add_subregion(system_memory, ENVM_BASE_ADDRESS, nvm); memory_region_add_subregion(system_memory, ENVM_BASE_ADDRESS, nvm);
memory_region_add_subregion(system_memory, 0, nvm_alias); memory_region_add_subregion(system_memory, 0, nvm_alias);

View File

@ -165,7 +165,7 @@ static void nrf51_soc_realize(DeviceState *dev_soc, Error **errp)
} }
/* STUB Peripherals */ /* STUB Peripherals */
memory_region_init_io(&s->clock, NULL, &clock_ops, NULL, memory_region_init_io(&s->clock, OBJECT(dev_soc), &clock_ops, NULL,
"nrf51_soc.clock", 0x1000); "nrf51_soc.clock", 0x1000);
memory_region_add_subregion_overlap(&s->container, memory_region_add_subregion_overlap(&s->container,
NRF51_IOMEM_BASE, &s->clock, -1); NRF51_IOMEM_BASE, &s->clock, -1);

View File

@ -93,10 +93,10 @@ static void stm32f205_soc_realize(DeviceState *dev_soc, Error **errp)
MemoryRegion *flash = g_new(MemoryRegion, 1); MemoryRegion *flash = g_new(MemoryRegion, 1);
MemoryRegion *flash_alias = g_new(MemoryRegion, 1); MemoryRegion *flash_alias = g_new(MemoryRegion, 1);
memory_region_init_rom(flash, NULL, "STM32F205.flash", FLASH_SIZE, memory_region_init_rom(flash, OBJECT(dev_soc), "STM32F205.flash",
&error_fatal); FLASH_SIZE, &error_fatal);
memory_region_init_alias(flash_alias, NULL, "STM32F205.flash.alias", memory_region_init_alias(flash_alias, OBJECT(dev_soc),
flash, 0, FLASH_SIZE); "STM32F205.flash.alias", flash, 0, FLASH_SIZE);
memory_region_add_subregion(system_memory, FLASH_BASE_ADDRESS, flash); memory_region_add_subregion(system_memory, FLASH_BASE_ADDRESS, flash);
memory_region_add_subregion(system_memory, 0, flash_alias); memory_region_add_subregion(system_memory, 0, flash_alias);

View File

@ -95,14 +95,15 @@ static void stm32f405_soc_realize(DeviceState *dev_soc, Error **errp)
Error *err = NULL; Error *err = NULL;
int i; int i;
memory_region_init_rom(&s->flash, NULL, "STM32F405.flash", FLASH_SIZE, memory_region_init_rom(&s->flash, OBJECT(dev_soc), "STM32F405.flash",
&err); FLASH_SIZE, &err);
if (err != NULL) { if (err != NULL) {
error_propagate(errp, err); error_propagate(errp, err);
return; return;
} }
memory_region_init_alias(&s->flash_alias, NULL, "STM32F405.flash.alias", memory_region_init_alias(&s->flash_alias, OBJECT(dev_soc),
&s->flash, 0, FLASH_SIZE); "STM32F405.flash.alias", &s->flash, 0,
FLASH_SIZE);
memory_region_add_subregion(system_memory, FLASH_BASE_ADDRESS, &s->flash); memory_region_add_subregion(system_memory, FLASH_BASE_ADDRESS, &s->flash);
memory_region_add_subregion(system_memory, 0, &s->flash_alias); memory_region_add_subregion(system_memory, 0, &s->flash_alias);

View File

@ -318,9 +318,9 @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp)
ddr_low_size = XLNX_ZYNQMP_MAX_LOW_RAM_SIZE; ddr_low_size = XLNX_ZYNQMP_MAX_LOW_RAM_SIZE;
ddr_high_size = ram_size - XLNX_ZYNQMP_MAX_LOW_RAM_SIZE; ddr_high_size = ram_size - XLNX_ZYNQMP_MAX_LOW_RAM_SIZE;
memory_region_init_alias(&s->ddr_ram_high, NULL, memory_region_init_alias(&s->ddr_ram_high, OBJECT(dev),
"ddr-ram-high", s->ddr_ram, "ddr-ram-high", s->ddr_ram, ddr_low_size,
ddr_low_size, ddr_high_size); ddr_high_size);
memory_region_add_subregion(get_system_memory(), memory_region_add_subregion(get_system_memory(),
XLNX_ZYNQMP_HIGH_RAM_START, XLNX_ZYNQMP_HIGH_RAM_START,
&s->ddr_ram_high); &s->ddr_ram_high);
@ -330,9 +330,8 @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp)
ddr_low_size = ram_size; ddr_low_size = ram_size;
} }
memory_region_init_alias(&s->ddr_ram_low, NULL, memory_region_init_alias(&s->ddr_ram_low, OBJECT(dev), "ddr-ram-low",
"ddr-ram-low", s->ddr_ram, s->ddr_ram, 0, ddr_low_size);
0, ddr_low_size);
memory_region_add_subregion(get_system_memory(), 0, &s->ddr_ram_low); memory_region_add_subregion(get_system_memory(), 0, &s->ddr_ram_low);
/* Create the four OCM banks */ /* Create the four OCM banks */