提交 4a1cc680 编写于 作者: A Anthony Liguori

Merge remote-tracking branch 'qemu-kvm/memory/xen' into staging

...@@ -61,9 +61,12 @@ static inline void cpu_register_physical_memory(target_phys_addr_t start_addr, ...@@ -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); 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 qemu_ram_alloc_from_ptr(DeviceState *dev, const char *name,
ram_addr_t size, void *host); ram_addr_t size, void *host,
ram_addr_t qemu_ram_alloc(DeviceState *dev, const char *name, ram_addr_t size); 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(ram_addr_t addr);
void qemu_ram_free_from_ptr(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); void qemu_ram_remap(ram_addr_t addr, ram_addr_t length);
......
...@@ -2916,7 +2916,8 @@ static ram_addr_t last_ram_offset(void) ...@@ -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 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; RAMBlock *new_block, *block;
...@@ -2972,7 +2973,7 @@ ram_addr_t qemu_ram_alloc_from_ptr(DeviceState *dev, const char *name, ...@@ -2972,7 +2973,7 @@ ram_addr_t qemu_ram_alloc_from_ptr(DeviceState *dev, const char *name,
} }
#else #else
if (xen_enabled()) { if (xen_enabled()) {
xen_ram_alloc(new_block->offset, size); xen_ram_alloc(new_block->offset, size, mr);
} else { } else {
new_block->host = qemu_vmalloc(size); new_block->host = qemu_vmalloc(size);
} }
...@@ -2995,9 +2996,10 @@ ram_addr_t qemu_ram_alloc_from_ptr(DeviceState *dev, const char *name, ...@@ -2995,9 +2996,10 @@ ram_addr_t qemu_ram_alloc_from_ptr(DeviceState *dev, const char *name,
return new_block->offset; 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) void qemu_ram_free_from_ptr(ram_addr_t addr)
......
...@@ -44,7 +44,9 @@ void xen_vcpu_init(void); ...@@ -44,7 +44,9 @@ void xen_vcpu_init(void);
void xenstore_store_pv_console_info(int i, struct CharDriverState *chr); void xenstore_store_pv_console_info(int i, struct CharDriverState *chr);
#if defined(NEED_CPU_H) && !defined(CONFIG_USER_ONLY) #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 #endif
#if defined(CONFIG_XEN) && CONFIG_XEN_CTRL_INTERFACE_VERSION < 400 #if defined(CONFIG_XEN) && CONFIG_XEN_CTRL_INTERFACE_VERSION < 400
......
...@@ -997,7 +997,7 @@ void memory_region_init_ram(MemoryRegion *mr, ...@@ -997,7 +997,7 @@ void memory_region_init_ram(MemoryRegion *mr,
memory_region_init(mr, name, size); memory_region_init(mr, name, size);
mr->terminates = true; mr->terminates = true;
mr->destructor = memory_region_destructor_ram; 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; mr->backend_registered = true;
} }
...@@ -1010,7 +1010,7 @@ void memory_region_init_ram_ptr(MemoryRegion *mr, ...@@ -1010,7 +1010,7 @@ void memory_region_init_ram_ptr(MemoryRegion *mr,
memory_region_init(mr, name, size); memory_region_init(mr, name, size);
mr->terminates = true; mr->terminates = true;
mr->destructor = memory_region_destructor_ram_from_ptr; 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; mr->backend_registered = true;
} }
...@@ -1037,7 +1037,7 @@ void memory_region_init_rom_device(MemoryRegion *mr, ...@@ -1037,7 +1037,7 @@ void memory_region_init_rom_device(MemoryRegion *mr,
mr->opaque = opaque; mr->opaque = opaque;
mr->terminates = true; mr->terminates = true;
mr->destructor = memory_region_destructor_rom_device; 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, mr->ram_addr |= cpu_register_io_memory(memory_region_read_thunk,
memory_region_write_thunk, memory_region_write_thunk,
mr, mr,
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "range.h" #include "range.h"
#include "xen-mapcache.h" #include "xen-mapcache.h"
#include "trace.h" #include "trace.h"
#include "exec-memory.h"
#include <xen/hvm/ioreq.h> #include <xen/hvm/ioreq.h>
#include <xen/hvm/params.h> #include <xen/hvm/params.h>
...@@ -31,6 +32,8 @@ ...@@ -31,6 +32,8 @@
do { } while (0) do { } while (0)
#endif #endif
static MemoryRegion ram_memory, ram_640k, ram_lo, ram_hi;
/* Compatibility with older version */ /* Compatibility with older version */
#if __XEN_LATEST_INTERFACE_VERSION__ < 0x0003020a #if __XEN_LATEST_INTERFACE_VERSION__ < 0x0003020a
static inline uint32_t xen_vcpu_eport(shared_iopage_t *shared_page, int i) static inline uint32_t xen_vcpu_eport(shared_iopage_t *shared_page, int i)
...@@ -137,27 +140,18 @@ qemu_irq *xen_interrupt_controller_init(void) ...@@ -137,27 +140,18 @@ qemu_irq *xen_interrupt_controller_init(void)
static void xen_ram_init(ram_addr_t ram_size) static void xen_ram_init(ram_addr_t ram_size)
{ {
RAMBlock *new_block; MemoryRegion *sysmem = get_system_memory();
ram_addr_t below_4g_mem_size, above_4g_mem_size = 0; ram_addr_t below_4g_mem_size, above_4g_mem_size = 0;
ram_addr_t block_len;
new_block = g_malloc0(sizeof (*new_block)); block_len = ram_size;
pstrcpy(new_block->idstr, sizeof (new_block->idstr), "xen.ram");
new_block->host = NULL;
new_block->offset = 0;
new_block->length = ram_size;
if (ram_size >= HVM_BELOW_4G_RAM_END) { if (ram_size >= HVM_BELOW_4G_RAM_END) {
/* Xen does not allocate the memory continuously, and keep a hole at /* Xen does not allocate the memory continuously, and keep a hole at
* HVM_BELOW_4G_MMIO_START of HVM_BELOW_4G_MMIO_LENGTH * HVM_BELOW_4G_MMIO_START of HVM_BELOW_4G_MMIO_LENGTH
*/ */
new_block->length += HVM_BELOW_4G_MMIO_LENGTH; block_len += HVM_BELOW_4G_MMIO_LENGTH;
} }
memory_region_init_ram(&ram_memory, NULL, "xen.ram", block_len);
QLIST_INSERT_HEAD(&ram_list.blocks, new_block, next);
ram_list.phys_dirty = g_realloc(ram_list.phys_dirty,
new_block->length >> TARGET_PAGE_BITS);
memset(ram_list.phys_dirty + (new_block->offset >> TARGET_PAGE_BITS),
0xff, new_block->length >> TARGET_PAGE_BITS);
if (ram_size >= HVM_BELOW_4G_RAM_END) { if (ram_size >= HVM_BELOW_4G_RAM_END) {
above_4g_mem_size = ram_size - HVM_BELOW_4G_RAM_END; above_4g_mem_size = ram_size - HVM_BELOW_4G_RAM_END;
...@@ -166,27 +160,36 @@ static void xen_ram_init(ram_addr_t ram_size) ...@@ -166,27 +160,36 @@ static void xen_ram_init(ram_addr_t ram_size)
below_4g_mem_size = ram_size; below_4g_mem_size = ram_size;
} }
cpu_register_physical_memory(0, 0xa0000, 0); memory_region_init_alias(&ram_640k, "xen.ram.640k",
&ram_memory, 0, 0xa0000);
memory_region_add_subregion(sysmem, 0, &ram_640k);
/* Skip of the VGA IO memory space, it will be registered later by the VGA /* Skip of the VGA IO memory space, it will be registered later by the VGA
* emulated device. * emulated device.
* *
* The area between 0xc0000 and 0x100000 will be used by SeaBIOS to load * The area between 0xc0000 and 0x100000 will be used by SeaBIOS to load
* the Options ROM, so it is registered here as RAM. * the Options ROM, so it is registered here as RAM.
*/ */
cpu_register_physical_memory(0xc0000, below_4g_mem_size - 0xc0000, memory_region_init_alias(&ram_lo, "xen.ram.lo",
0xc0000); &ram_memory, 0xc0000, below_4g_mem_size - 0xc0000);
memory_region_add_subregion(sysmem, 0xc0000, &ram_lo);
if (above_4g_mem_size > 0) { if (above_4g_mem_size > 0) {
cpu_register_physical_memory(0x100000000ULL, above_4g_mem_size, memory_region_init_alias(&ram_hi, "xen.ram.hi",
0x100000000ULL); &ram_memory, 0x100000000ULL,
above_4g_mem_size);
memory_region_add_subregion(sysmem, 0x100000000ULL, &ram_hi);
} }
} }
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; unsigned long nr_pfn;
xen_pfn_t *pfn_list; xen_pfn_t *pfn_list;
int i; int i;
if (mr == &ram_memory) {
return;
}
trace_xen_ram_alloc(ram_addr, size); trace_xen_ram_alloc(ram_addr, size);
nr_pfn = size >> TARGET_PAGE_BITS; nr_pfn = size >> TARGET_PAGE_BITS;
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "qemu-common.h" #include "qemu-common.h"
#include "hw/xen.h" #include "hw/xen.h"
#include "memory.h"
void xenstore_store_pv_console_info(int i, CharDriverState *chr) 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) ...@@ -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)
{ {
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册