From fce537d4a741521ac182d54465c568b101b9a71e Mon Sep 17 00:00:00 2001 From: Avi Kivity Date: Sun, 18 Dec 2011 15:48:55 +0200 Subject: memory, xen: pass MemoryRegion to xen_ram_alloc() Currently xen_ram_alloc() relies on ram_addr, which is going away. Give it something else to use as a cookie. Signed-off-by: Avi Kivity --- cpu-common.h | 7 +++++-- exec.c | 10 ++++++---- hw/xen.h | 4 +++- memory.c | 6 +++--- xen-all.c | 2 +- xen-stub.c | 3 ++- 6 files changed, 20 insertions(+), 12 deletions(-) diff --git a/cpu-common.h b/cpu-common.h index 48f4c01a3f..72eb731c3e 100644 --- a/cpu-common.h +++ b/cpu-common.h @@ -61,9 +61,12 @@ 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); +struct MemoryRegion; ram_addr_t qemu_ram_alloc_from_ptr(DeviceState *dev, const char *name, - ram_addr_t size, void *host); -ram_addr_t qemu_ram_alloc(DeviceState *dev, const char *name, ram_addr_t size); + ram_addr_t size, void *host, + struct MemoryRegion *mr); +ram_addr_t qemu_ram_alloc(DeviceState *dev, const char *name, ram_addr_t size, + struct MemoryRegion *mr); void qemu_ram_free(ram_addr_t addr); void qemu_ram_free_from_ptr(ram_addr_t addr); void qemu_ram_remap(ram_addr_t addr, ram_addr_t length); diff --git a/exec.c b/exec.c index 06889bdf18..fbcb1bf028 100644 --- a/exec.c +++ b/exec.c @@ -2916,7 +2916,8 @@ static ram_addr_t last_ram_offset(void) } ram_addr_t qemu_ram_alloc_from_ptr(DeviceState *dev, const char *name, - ram_addr_t size, void *host) + ram_addr_t size, void *host, + MemoryRegion *mr) { RAMBlock *new_block, *block; @@ -2972,7 +2973,7 @@ ram_addr_t qemu_ram_alloc_from_ptr(DeviceState *dev, const char *name, } #else if (xen_enabled()) { - xen_ram_alloc(new_block->offset, size); + xen_ram_alloc(new_block->offset, size, mr); } else { new_block->host = qemu_vmalloc(size); } @@ -2995,9 +2996,10 @@ ram_addr_t qemu_ram_alloc_from_ptr(DeviceState *dev, const char *name, return new_block->offset; } -ram_addr_t qemu_ram_alloc(DeviceState *dev, const char *name, ram_addr_t size) +ram_addr_t qemu_ram_alloc(DeviceState *dev, const char *name, ram_addr_t size, + MemoryRegion *mr) { - return qemu_ram_alloc_from_ptr(dev, name, size, NULL); + return qemu_ram_alloc_from_ptr(dev, name, size, NULL, mr); } void qemu_ram_free_from_ptr(ram_addr_t addr) diff --git a/hw/xen.h b/hw/xen.h index 21621115e4..f9f66e83ef 100644 --- a/hw/xen.h +++ b/hw/xen.h @@ -44,7 +44,9 @@ void xen_vcpu_init(void); void xenstore_store_pv_console_info(int i, struct CharDriverState *chr); #if defined(NEED_CPU_H) && !defined(CONFIG_USER_ONLY) -void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size); +struct MemoryRegion; +void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, + struct MemoryRegion *mr); #endif #if defined(CONFIG_XEN) && CONFIG_XEN_CTRL_INTERFACE_VERSION < 400 diff --git a/memory.c b/memory.c index adfdf1470c..1a42cea088 100644 --- a/memory.c +++ b/memory.c @@ -982,7 +982,7 @@ void memory_region_init_ram(MemoryRegion *mr, memory_region_init(mr, name, size); mr->terminates = true; mr->destructor = memory_region_destructor_ram; - mr->ram_addr = qemu_ram_alloc(dev, name, size); + mr->ram_addr = qemu_ram_alloc(dev, name, size, mr); mr->backend_registered = true; } @@ -995,7 +995,7 @@ void memory_region_init_ram_ptr(MemoryRegion *mr, memory_region_init(mr, name, size); mr->terminates = true; mr->destructor = memory_region_destructor_ram_from_ptr; - mr->ram_addr = qemu_ram_alloc_from_ptr(dev, name, size, ptr); + mr->ram_addr = qemu_ram_alloc_from_ptr(dev, name, size, ptr, mr); mr->backend_registered = true; } @@ -1022,7 +1022,7 @@ void memory_region_init_rom_device(MemoryRegion *mr, mr->opaque = opaque; mr->terminates = true; mr->destructor = memory_region_destructor_rom_device; - mr->ram_addr = qemu_ram_alloc(dev, name, size); + mr->ram_addr = qemu_ram_alloc(dev, name, size, mr); mr->ram_addr |= cpu_register_io_memory(memory_region_read_thunk, memory_region_write_thunk, mr, diff --git a/xen-all.c b/xen-all.c index b5e28abd40..b441fc188a 100644 --- a/xen-all.c +++ b/xen-all.c @@ -181,7 +181,7 @@ static void xen_ram_init(ram_addr_t ram_size) } } -void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size) +void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr) { unsigned long nr_pfn; xen_pfn_t *pfn_list; diff --git a/xen-stub.c b/xen-stub.c index efe2ab55f2..5fa400faae 100644 --- a/xen-stub.c +++ b/xen-stub.c @@ -8,6 +8,7 @@ #include "qemu-common.h" #include "hw/xen.h" +#include "memory.h" void xenstore_store_pv_console_info(int i, CharDriverState *chr) { @@ -30,7 +31,7 @@ void xen_cmos_set_s3_resume(void *opaque, int irq, int level) { } -void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size) +void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr) { } -- cgit v1.2.3