diff options
author | aliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162> | 2008-11-19 17:41:58 +0000 |
---|---|---|
committer | aliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162> | 2008-11-19 17:41:58 +0000 |
commit | 34fc643fd3ff76dac6990cd2fa4a136111eb383a (patch) | |
tree | 9c44b39bc7c80fc7d850f0bfc90572c132c36ae5 /kvm-all.c | |
parent | af12906f77f37a3dd7da158d5b42d90a59d6fc7a (diff) |
Make KVMSlot a real structure
struct kvm_userspace_memory_region does not use QEMU friendly types to
define memory slots. This results in lots of ugly casting with warnings
on 32-bit platforms.
This patch introduces a proper KVMSlot structure that uses QEMU types to
describe memory slots. This eliminates many of the casts and isolates
the type conversions to one spot.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5755 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'kvm-all.c')
-rw-r--r-- | kvm-all.c | 54 |
1 files changed, 37 insertions, 17 deletions
@@ -32,7 +32,14 @@ do { } while (0) #endif -typedef struct kvm_userspace_memory_region KVMSlot; +typedef struct KVMSlot +{ + target_phys_addr_t start_addr; + ram_addr_t memory_size; + ram_addr_t phys_offset; + int slot; + int flags; +} KVMSlot; int kvm_allowed = 0; @@ -67,8 +74,8 @@ static KVMSlot *kvm_lookup_slot(KVMState *s, target_phys_addr_t start_addr) for (i = 0; i < ARRAY_SIZE(s->slots); i++) { KVMSlot *mem = &s->slots[i]; - if (start_addr >= mem->guest_phys_addr && - start_addr < (mem->guest_phys_addr + mem->memory_size)) + if (start_addr >= mem->start_addr && + start_addr < (mem->start_addr + mem->memory_size)) return mem; } @@ -309,6 +316,19 @@ int kvm_cpu_exec(CPUState *env) return ret; } +static int kvm_set_user_memory_region(KVMState *s, KVMSlot *slot) +{ + struct kvm_userspace_memory_region mem; + + mem.slot = slot->slot; + mem.guest_phys_addr = slot->start_addr; + mem.memory_size = slot->memory_size; + mem.userspace_addr = (unsigned long)phys_ram_base + slot->phys_offset; + mem.flags = slot->flags; + + return kvm_vm_ioctl(s, KVM_SET_USER_MEMORY_REGION, &mem); +} + void kvm_set_phys_mem(target_phys_addr_t start_addr, ram_addr_t size, ram_addr_t phys_offset) @@ -324,32 +344,32 @@ void kvm_set_phys_mem(target_phys_addr_t start_addr, if (mem) { if ((flags == IO_MEM_UNASSIGNED) || (flags >= TLB_MMIO)) { mem->memory_size = 0; - mem->guest_phys_addr = start_addr; - mem->userspace_addr = 0; + mem->start_addr = start_addr; + mem->phys_offset = 0; mem->flags = 0; - kvm_vm_ioctl(s, KVM_SET_USER_MEMORY_REGION, mem); - } else if (start_addr >= mem->guest_phys_addr && - (start_addr + size) <= (mem->guest_phys_addr + + kvm_set_user_memory_region(s, mem); + } else if (start_addr >= mem->start_addr && + (start_addr + size) <= (mem->start_addr + mem->memory_size)) { KVMSlot slot; target_phys_addr_t mem_start; ram_addr_t mem_size, mem_offset; /* Not splitting */ - if ((phys_offset - (start_addr - mem->guest_phys_addr)) == - ((uint8_t *)mem->userspace_addr - phys_ram_base)) + if ((phys_offset - (start_addr - mem->start_addr)) == + mem->phys_offset) return; /* unregister whole slot */ memcpy(&slot, mem, sizeof(slot)); mem->memory_size = 0; - kvm_vm_ioctl(s, KVM_SET_USER_MEMORY_REGION, mem); + kvm_set_user_memory_region(s, mem); /* register prefix slot */ - mem_start = slot.guest_phys_addr; - mem_size = start_addr - slot.guest_phys_addr; - mem_offset = (uint8_t *)slot.userspace_addr - phys_ram_base; + mem_start = slot.start_addr; + mem_size = start_addr - slot.start_addr; + mem_offset = slot.phys_offset; if (mem_size) kvm_set_phys_mem(mem_start, mem_size, mem_offset); @@ -375,11 +395,11 @@ void kvm_set_phys_mem(target_phys_addr_t start_addr, mem = kvm_alloc_slot(s); mem->memory_size = size; - mem->guest_phys_addr = start_addr; - mem->userspace_addr = (unsigned long)(phys_ram_base + phys_offset); + mem->start_addr = start_addr; + mem->phys_offset = phys_offset; mem->flags = 0; - kvm_vm_ioctl(s, KVM_SET_USER_MEMORY_REGION, mem); + kvm_set_user_memory_region(s, mem); /* FIXME deal with errors */ } |