Skip to content

Commit

Permalink
qemu_ram_alloc: Add DeviceState and name parameters
Browse files Browse the repository at this point in the history
These will be used to generate unique id strings for ramblocks.  The name
field is required, the device pointer is optional as most callers don't
have a device.  When there's no device or the device isn't a child of
a bus implementing BusInfo.get_dev_path, the name should be unique for
the platform.

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
  • Loading branch information
awilliam authored and Anthony Liguori committed Jul 6, 2010
1 parent 01657c8 commit 1724f04
Show file tree
Hide file tree
Showing 49 changed files with 133 additions and 100 deletions.
2 changes: 1 addition & 1 deletion cpu-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static inline void cpu_register_physical_memory(target_phys_addr_t start_addr,
}

ram_addr_t cpu_get_physical_page_desc(target_phys_addr_t addr);
ram_addr_t qemu_ram_alloc(ram_addr_t);
ram_addr_t qemu_ram_alloc(DeviceState *dev, const char *name, ram_addr_t size);
void qemu_ram_free(ram_addr_t addr);
/* This should only be used for ram local to a device. */
void *qemu_get_ram_ptr(ram_addr_t addr);
Expand Down
2 changes: 1 addition & 1 deletion exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -2778,7 +2778,7 @@ static ram_addr_t find_ram_offset(ram_addr_t size)
return last;
}

ram_addr_t qemu_ram_alloc(ram_addr_t size)
ram_addr_t qemu_ram_alloc(DeviceState *dev, const char *name, ram_addr_t size)
{
RAMBlock *new_block;

Expand Down
4 changes: 2 additions & 2 deletions hw/an5206.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ static void an5206_init(ram_addr_t ram_size,

/* DRAM at address zero */
cpu_register_physical_memory(0, ram_size,
qemu_ram_alloc(ram_size) | IO_MEM_RAM);
qemu_ram_alloc(NULL, "an5206.ram", ram_size) | IO_MEM_RAM);

/* Internal SRAM. */
cpu_register_physical_memory(AN5206_RAMBAR_ADDR, 512,
qemu_ram_alloc(512) | IO_MEM_RAM);
qemu_ram_alloc(NULL, "an5206.sram", 512) | IO_MEM_RAM);

mcf5206_init(AN5206_MBAR_ADDR, env);

Expand Down
9 changes: 6 additions & 3 deletions hw/armv7m.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,11 @@ qemu_irq *armv7m_init(int flash_size, int sram_size,

/* Flash programming is done via the SCU, so pretend it is ROM. */
cpu_register_physical_memory(0, flash_size,
qemu_ram_alloc(flash_size) | IO_MEM_ROM);
qemu_ram_alloc(NULL, "armv7m.flash",
flash_size) | IO_MEM_ROM);
cpu_register_physical_memory(0x20000000, sram_size,
qemu_ram_alloc(sram_size) | IO_MEM_RAM);
qemu_ram_alloc(NULL, "armv7m.sram",
sram_size) | IO_MEM_RAM);
armv7m_bitband_init();

nvic = qdev_create(NULL, "armv7m_nvic");
Expand Down Expand Up @@ -236,7 +238,8 @@ qemu_irq *armv7m_init(int flash_size, int sram_size,
space. This stops qemu complaining about executing code outside RAM
when returning from an exception. */
cpu_register_physical_memory(0xfffff000, 0x1000,
qemu_ram_alloc(0x1000) | IO_MEM_RAM);
qemu_ram_alloc(NULL, "armv7m.hack",
0x1000) | IO_MEM_RAM);

qemu_register_reset(armv7m_reset, env);
return pic;
Expand Down
4 changes: 2 additions & 2 deletions hw/axis_dev88.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,12 @@ void axisdev88_init (ram_addr_t ram_size,
env = cpu_init(cpu_model);

/* allocate RAM */
phys_ram = qemu_ram_alloc(ram_size);
phys_ram = qemu_ram_alloc(NULL, "axisdev88.ram", ram_size);
cpu_register_physical_memory(0x40000000, ram_size, phys_ram | IO_MEM_RAM);

/* The ETRAX-FS has 128Kb on chip ram, the docs refer to it as the
internal memory. */
phys_intmem = qemu_ram_alloc(INTMEM_SIZE);
phys_intmem = qemu_ram_alloc(NULL, "axisdev88.chipram", INTMEM_SIZE);
cpu_register_physical_memory(0x38000000, INTMEM_SIZE,
phys_intmem | IO_MEM_RAM);

Expand Down
2 changes: 1 addition & 1 deletion hw/dummy_m68k.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static void dummy_m68k_init(ram_addr_t ram_size,

/* RAM at address zero */
cpu_register_physical_memory(0, ram_size,
qemu_ram_alloc(ram_size) | IO_MEM_RAM);
qemu_ram_alloc(NULL, "dummy_m68k.ram", ram_size) | IO_MEM_RAM);

/* Load kernel. */
if (kernel_filename) {
Expand Down
6 changes: 3 additions & 3 deletions hw/etraxfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,17 @@ void bareetraxfs_init (ram_addr_t ram_size,
env = cpu_init(cpu_model);

/* allocate RAM */
phys_ram = qemu_ram_alloc(ram_size);
phys_ram = qemu_ram_alloc(NULL, "etraxfs.ram", ram_size);
cpu_register_physical_memory(0x40000000, ram_size, phys_ram | IO_MEM_RAM);

/* The ETRAX-FS has 128Kb on chip ram, the docs refer to it as the
internal memory. */
phys_intmem = qemu_ram_alloc(INTMEM_SIZE);
phys_intmem = qemu_ram_alloc(NULL, "etraxfs.chipram", INTMEM_SIZE);
cpu_register_physical_memory(0x38000000, INTMEM_SIZE,
phys_intmem | IO_MEM_RAM);


phys_flash = qemu_ram_alloc(FLASH_SIZE);
phys_flash = qemu_ram_alloc(NULL, "etraxfs.flash", FLASH_SIZE);
dinfo = drive_get(IF_PFLASH, 0, 0);
pflash_cfi02_register(0x0, phys_flash,
dinfo ? dinfo->bdrv : NULL, (64 * 1024),
Expand Down
2 changes: 1 addition & 1 deletion hw/g364fb.c
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ int g364fb_mm_init(target_phys_addr_t vram_base,
s = qemu_mallocz(sizeof(G364State));

s->vram_size = 8 * 1024 * 1024;
s->vram_offset = qemu_ram_alloc(s->vram_size);
s->vram_offset = qemu_ram_alloc(NULL, "g364fb.vram", s->vram_size);
s->vram = qemu_get_ram_ptr(s->vram_offset);
s->irq = irq;

Expand Down
6 changes: 4 additions & 2 deletions hw/gumstix.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ static void connex_init(ram_addr_t ram_size,
#else
be = 0;
#endif
if (!pflash_cfi01_register(0x00000000, qemu_ram_alloc(connex_rom),
if (!pflash_cfi01_register(0x00000000, qemu_ram_alloc(NULL, "connext.rom",
connex_rom),
dinfo->bdrv, sector_len, connex_rom / sector_len,
2, 0, 0, 0, 0, be)) {
fprintf(stderr, "qemu: Error registering flash memory.\n");
Expand Down Expand Up @@ -105,7 +106,8 @@ static void verdex_init(ram_addr_t ram_size,
#else
be = 0;
#endif
if (!pflash_cfi01_register(0x00000000, qemu_ram_alloc(verdex_rom),
if (!pflash_cfi01_register(0x00000000, qemu_ram_alloc(NULL, "verdex.rom",
verdex_rom),
dinfo->bdrv, sector_len, verdex_rom / sector_len,
2, 0, 0, 0, 0, be)) {
fprintf(stderr, "qemu: Error registering flash memory.\n");
Expand Down
2 changes: 1 addition & 1 deletion hw/ide/via.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ static int vt82c686b_ide_initfn(PCIDevice *dev)
pci_register_bar((PCIDevice *)d, 4, 0x10,
PCI_BASE_ADDRESS_SPACE_IO, bmdma_map);

vmstate_register(0, &vmstate_ide_pci, d);
vmstate_register(&dev->qdev, 0, &vmstate_ide_pci, d);

ide_bus_new(&d->bus[0], &d->dev.qdev);
ide_bus_new(&d->bus[1], &d->dev.qdev);
Expand Down
4 changes: 2 additions & 2 deletions hw/integratorcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ static int integratorcm_init(SysBusDevice *dev)
}
memcpy(integrator_spd + 73, "QEMU-MEMORY", 11);
s->cm_init = 0x00000112;
s->flash_offset = qemu_ram_alloc(0x100000);
s->flash_offset = qemu_ram_alloc(NULL, "integrator.flash", 0x100000);

iomemtype = cpu_register_io_memory(integratorcm_readfn,
integratorcm_writefn, s);
Expand Down Expand Up @@ -467,7 +467,7 @@ static void integratorcp_init(ram_addr_t ram_size,
fprintf(stderr, "Unable to find CPU definition\n");
exit(1);
}
ram_offset = qemu_ram_alloc(ram_size);
ram_offset = qemu_ram_alloc(NULL, "integrator.ram", ram_size);
/* ??? On a real system the first 1Mb is mapped as SSRAM or boot flash. */
/* ??? RAM should repeat to fill physical memory space. */
/* SDRAM at address zero*/
Expand Down
6 changes: 4 additions & 2 deletions hw/mainstone.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ static void mainstone_common_init(ram_addr_t ram_size,
/* Setup CPU & memory */
cpu = pxa270_init(mainstone_binfo.ram_size, cpu_model);
cpu_register_physical_memory(0, MAINSTONE_ROM,
qemu_ram_alloc(MAINSTONE_ROM) | IO_MEM_ROM);
qemu_ram_alloc(NULL, "mainstone.rom",
MAINSTONE_ROM) | IO_MEM_ROM);

#ifdef TARGET_WORDS_BIGENDIAN
be = 1;
Expand All @@ -104,7 +105,8 @@ static void mainstone_common_init(ram_addr_t ram_size,
}

if (!pflash_cfi01_register(mainstone_flash_base[i],
qemu_ram_alloc(MAINSTONE_FLASH),
qemu_ram_alloc(NULL, "mainstone.flash",
MAINSTONE_FLASH),
dinfo->bdrv, sector_len,
MAINSTONE_FLASH / sector_len, 4, 0, 0, 0, 0,
be)) {
Expand Down
4 changes: 2 additions & 2 deletions hw/mcf5208.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,11 @@ static void mcf5208evb_init(ram_addr_t ram_size,

/* DRAM at 0x40000000 */
cpu_register_physical_memory(0x40000000, ram_size,
qemu_ram_alloc(ram_size) | IO_MEM_RAM);
qemu_ram_alloc(NULL, "mcf5208.ram", ram_size) | IO_MEM_RAM);

/* Internal SRAM. */
cpu_register_physical_memory(0x80000000, 16384,
qemu_ram_alloc(16384) | IO_MEM_RAM);
qemu_ram_alloc(NULL, "mcf5208.sram", 16384) | IO_MEM_RAM);

/* Internal peripherals. */
pic = mcf_intc_init(0xfc048000, env);
Expand Down
4 changes: 2 additions & 2 deletions hw/mips_fulong2e.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ static void mips_fulong2e_init(ram_addr_t ram_size, const char *boot_device,
bios_size = 1024 * 1024;

/* allocate RAM */
ram_offset = qemu_ram_alloc(ram_size);
bios_offset = qemu_ram_alloc(bios_size);
ram_offset = qemu_ram_alloc(NULL, "fulong2e.ram", ram_size);
bios_offset = qemu_ram_alloc(NULL, "fulong2e.bios", bios_size);

cpu_register_physical_memory(0, ram_size, IO_MEM_RAM);
cpu_register_physical_memory(0x1fc00000LL,
Expand Down
4 changes: 2 additions & 2 deletions hw/mips_jazz.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ void mips_jazz_init (ram_addr_t ram_size,
qemu_register_reset(main_cpu_reset, env);

/* allocate RAM */
ram_offset = qemu_ram_alloc(ram_size);
ram_offset = qemu_ram_alloc(NULL, "mips_jazz.ram", ram_size);
cpu_register_physical_memory(0, ram_size, ram_offset | IO_MEM_RAM);

bios_offset = qemu_ram_alloc(MAGNUM_BIOS_SIZE);
bios_offset = qemu_ram_alloc(NULL, "mips_jazz.bios", MAGNUM_BIOS_SIZE);
cpu_register_physical_memory(0x1fc00000LL,
MAGNUM_BIOS_SIZE, bios_offset | IO_MEM_ROM);
cpu_register_physical_memory(0xfff00000LL,
Expand Down
4 changes: 2 additions & 2 deletions hw/mips_malta.c
Original file line number Diff line number Diff line change
Expand Up @@ -831,8 +831,8 @@ void mips_malta_init (ram_addr_t ram_size,
((unsigned int)ram_size / (1 << 20)));
exit(1);
}
ram_offset = qemu_ram_alloc(ram_size);
bios_offset = qemu_ram_alloc(BIOS_SIZE);
ram_offset = qemu_ram_alloc(NULL, "mips_malta.ram", ram_size);
bios_offset = qemu_ram_alloc(NULL, "mips_malta.bios", BIOS_SIZE);


cpu_register_physical_memory(0, ram_size, ram_offset | IO_MEM_RAM);
Expand Down
4 changes: 2 additions & 2 deletions hw/mips_mipssim.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ mips_mipssim_init (ram_addr_t ram_size,
qemu_register_reset(main_cpu_reset, reset_info);

/* Allocate RAM. */
ram_offset = qemu_ram_alloc(ram_size);
bios_offset = qemu_ram_alloc(BIOS_SIZE);
ram_offset = qemu_ram_alloc(NULL, "mips_mipssim.ram", ram_size);
bios_offset = qemu_ram_alloc(NULL, "mips_mipssim.bios", BIOS_SIZE);

cpu_register_physical_memory(0, ram_size, ram_offset | IO_MEM_RAM);

Expand Down
6 changes: 3 additions & 3 deletions hw/mips_r4k.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ void mips_r4k_init (ram_addr_t ram_size,
((unsigned int)ram_size / (1 << 20)));
exit(1);
}
ram_offset = qemu_ram_alloc(ram_size);
ram_offset = qemu_ram_alloc(NULL, "mips_r4k.ram", ram_size);

cpu_register_physical_memory(0, ram_size, ram_offset | IO_MEM_RAM);

Expand Down Expand Up @@ -226,14 +226,14 @@ void mips_r4k_init (ram_addr_t ram_size,
be = 0;
#endif
if ((bios_size > 0) && (bios_size <= BIOS_SIZE)) {
bios_offset = qemu_ram_alloc(BIOS_SIZE);
bios_offset = qemu_ram_alloc(NULL, "mips_r4k.bios", BIOS_SIZE);
cpu_register_physical_memory(0x1fc00000, BIOS_SIZE,
bios_offset | IO_MEM_ROM);

load_image_targphys(filename, 0x1fc00000, BIOS_SIZE);
} else if ((dinfo = drive_get(IF_PFLASH, 0, 0)) != NULL) {
uint32_t mips_rom = 0x00400000;
bios_offset = qemu_ram_alloc(mips_rom);
bios_offset = qemu_ram_alloc(NULL, "mips_r4k.bios", mips_rom);
if (!pflash_cfi01_register(0x1fc00000, bios_offset,
dinfo->bdrv, sector_len,
mips_rom / sector_len,
Expand Down
11 changes: 7 additions & 4 deletions hw/musicpal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1506,9 +1506,10 @@ static void musicpal_init(ram_addr_t ram_size,

/* For now we use a fixed - the original - RAM size */
cpu_register_physical_memory(0, MP_RAM_DEFAULT_SIZE,
qemu_ram_alloc(MP_RAM_DEFAULT_SIZE));
qemu_ram_alloc(NULL, "musicpal.ram",
MP_RAM_DEFAULT_SIZE));

sram_off = qemu_ram_alloc(MP_SRAM_SIZE);
sram_off = qemu_ram_alloc(NULL, "musicpal.sram", MP_SRAM_SIZE);
cpu_register_physical_memory(MP_SRAM_BASE, MP_SRAM_SIZE, sram_off);

dev = sysbus_create_simple("mv88w8618_pic", MP_PIC_BASE,
Expand Down Expand Up @@ -1555,14 +1556,16 @@ static void musicpal_init(ram_addr_t ram_size,
* image is smaller than 32 MB.
*/
#ifdef TARGET_WORDS_BIGENDIAN
pflash_cfi02_register(0-MP_FLASH_SIZE_MAX, qemu_ram_alloc(flash_size),
pflash_cfi02_register(0-MP_FLASH_SIZE_MAX, qemu_ram_alloc(NULL,
"musicpal.flash", flash_size),
dinfo->bdrv, 0x10000,
(flash_size + 0xffff) >> 16,
MP_FLASH_SIZE_MAX / flash_size,
2, 0x00BF, 0x236D, 0x0000, 0x0000,
0x5555, 0x2AAA, 1);
#else
pflash_cfi02_register(0-MP_FLASH_SIZE_MAX, qemu_ram_alloc(flash_size),
pflash_cfi02_register(0-MP_FLASH_SIZE_MAX, qemu_ram_alloc(NULL,
"musicpal.flash", flash_size),
dinfo->bdrv, 0x10000,
(flash_size + 0xffff) >> 16,
MP_FLASH_SIZE_MAX / flash_size,
Expand Down
6 changes: 4 additions & 2 deletions hw/omap1.c
Original file line number Diff line number Diff line change
Expand Up @@ -3732,9 +3732,11 @@ struct omap_mpu_state_s *omap310_mpu_init(unsigned long sdram_size,

/* Memory-mapped stuff */
cpu_register_physical_memory(OMAP_EMIFF_BASE, s->sdram_size,
(emiff_base = qemu_ram_alloc(s->sdram_size)) | IO_MEM_RAM);
(emiff_base = qemu_ram_alloc(NULL, "omap1.dram",
s->sdram_size)) | IO_MEM_RAM);
cpu_register_physical_memory(OMAP_IMIF_BASE, s->sram_size,
(imif_base = qemu_ram_alloc(s->sram_size)) | IO_MEM_RAM);
(imif_base = qemu_ram_alloc(NULL, "omap1.sram",
s->sram_size)) | IO_MEM_RAM);

omap_clkm_init(0xfffece00, 0xe1008000, s);

Expand Down
6 changes: 4 additions & 2 deletions hw/omap2.c
Original file line number Diff line number Diff line change
Expand Up @@ -2253,9 +2253,11 @@ struct omap_mpu_state_s *omap2420_mpu_init(unsigned long sdram_size,

/* Memory-mapped stuff */
cpu_register_physical_memory(OMAP2_Q2_BASE, s->sdram_size,
(q2_base = qemu_ram_alloc(s->sdram_size)) | IO_MEM_RAM);
(q2_base = qemu_ram_alloc(NULL, "omap2.dram",
s->sdram_size)) | IO_MEM_RAM);
cpu_register_physical_memory(OMAP2_SRAM_BASE, s->sram_size,
(sram_base = qemu_ram_alloc(s->sram_size)) | IO_MEM_RAM);
(sram_base = qemu_ram_alloc(NULL, "omap2.sram",
s->sram_size)) | IO_MEM_RAM);

s->l4 = omap_l4_init(OMAP2_L4_BASE, 54);

Expand Down
12 changes: 8 additions & 4 deletions hw/omap_sx1.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ static void sx1_init(ram_addr_t ram_size,

/* External Flash (EMIFS) */
cpu_register_physical_memory(OMAP_CS0_BASE, flash_size,
qemu_ram_alloc(flash_size) | IO_MEM_ROM);
qemu_ram_alloc(NULL, "omap_sx1.flash0-0",
flash_size) | IO_MEM_ROM);

io = cpu_register_io_memory(static_readfn, static_writefn, &cs0val);
cpu_register_physical_memory(OMAP_CS0_BASE + flash_size,
Expand All @@ -157,7 +158,8 @@ static void sx1_init(ram_addr_t ram_size,
#endif

if ((dinfo = drive_get(IF_PFLASH, 0, fl_idx)) != NULL) {
if (!pflash_cfi01_register(OMAP_CS0_BASE, qemu_ram_alloc(flash_size),
if (!pflash_cfi01_register(OMAP_CS0_BASE, qemu_ram_alloc(NULL,
"omap_sx1.flash0-1", flash_size),
dinfo->bdrv, sector_size,
flash_size / sector_size,
4, 0, 0, 0, 0, be)) {
Expand All @@ -170,12 +172,14 @@ static void sx1_init(ram_addr_t ram_size,
if ((version == 1) &&
(dinfo = drive_get(IF_PFLASH, 0, fl_idx)) != NULL) {
cpu_register_physical_memory(OMAP_CS1_BASE, flash1_size,
qemu_ram_alloc(flash1_size) | IO_MEM_ROM);
qemu_ram_alloc(NULL, "omap_sx1.flash1-0",
flash1_size) | IO_MEM_ROM);
io = cpu_register_io_memory(static_readfn, static_writefn, &cs1val);
cpu_register_physical_memory(OMAP_CS1_BASE + flash1_size,
OMAP_CS1_SIZE - flash1_size, io);

if (!pflash_cfi01_register(OMAP_CS1_BASE, qemu_ram_alloc(flash1_size),
if (!pflash_cfi01_register(OMAP_CS1_BASE, qemu_ram_alloc(NULL,
"omap_sx1.flash1-1", flash1_size),
dinfo->bdrv, sector_size,
flash1_size / sector_size,
4, 0, 0, 0, 0, be)) {
Expand Down
2 changes: 1 addition & 1 deletion hw/onenand.c
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ void *onenand_init(uint32_t id, int regshift, qemu_irq irq)
s->bdrv = dinfo->bdrv;
s->otp = memset(qemu_malloc((64 + 2) << PAGE_SHIFT),
0xff, (64 + 2) << PAGE_SHIFT);
s->ram = qemu_ram_alloc(0xc000 << s->shift);
s->ram = qemu_ram_alloc(NULL, "onenand.ram", 0xc000 << s->shift);
ram = qemu_get_ram_ptr(s->ram);
s->boot[0] = ram + (0x0000 << s->shift);
s->boot[1] = ram + (0x8000 << s->shift);
Expand Down
3 changes: 2 additions & 1 deletion hw/palm.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ static void palmte_init(ram_addr_t ram_size,

/* External Flash (EMIFS) */
cpu_register_physical_memory(OMAP_CS0_BASE, flash_size,
qemu_ram_alloc(flash_size) | IO_MEM_ROM);
qemu_ram_alloc(NULL, "palmte.flash",
flash_size) | IO_MEM_ROM);

io = cpu_register_io_memory(static_readfn, static_writefn, &cs0val);
cpu_register_physical_memory(OMAP_CS0_BASE + flash_size,
Expand Down
Loading

0 comments on commit 1724f04

Please sign in to comment.