Commit 34fc643fd3ff76dac6990cd2fa4a136111eb383a

Authored by aliguori
1 parent af12906f

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
Showing 1 changed file with 37 additions and 17 deletions
kvm-all.c
... ... @@ -32,7 +32,14 @@
32 32 do { } while (0)
33 33 #endif
34 34  
35   -typedef struct kvm_userspace_memory_region KVMSlot;
  35 +typedef struct KVMSlot
  36 +{
  37 + target_phys_addr_t start_addr;
  38 + ram_addr_t memory_size;
  39 + ram_addr_t phys_offset;
  40 + int slot;
  41 + int flags;
  42 +} KVMSlot;
36 43  
37 44 int kvm_allowed = 0;
38 45  
... ... @@ -67,8 +74,8 @@ static KVMSlot *kvm_lookup_slot(KVMState *s, target_phys_addr_t start_addr)
67 74 for (i = 0; i < ARRAY_SIZE(s->slots); i++) {
68 75 KVMSlot *mem = &s->slots[i];
69 76  
70   - if (start_addr >= mem->guest_phys_addr &&
71   - start_addr < (mem->guest_phys_addr + mem->memory_size))
  77 + if (start_addr >= mem->start_addr &&
  78 + start_addr < (mem->start_addr + mem->memory_size))
72 79 return mem;
73 80 }
74 81  
... ... @@ -309,6 +316,19 @@ int kvm_cpu_exec(CPUState *env)
309 316 return ret;
310 317 }
311 318  
  319 +static int kvm_set_user_memory_region(KVMState *s, KVMSlot *slot)
  320 +{
  321 + struct kvm_userspace_memory_region mem;
  322 +
  323 + mem.slot = slot->slot;
  324 + mem.guest_phys_addr = slot->start_addr;
  325 + mem.memory_size = slot->memory_size;
  326 + mem.userspace_addr = (unsigned long)phys_ram_base + slot->phys_offset;
  327 + mem.flags = slot->flags;
  328 +
  329 + return kvm_vm_ioctl(s, KVM_SET_USER_MEMORY_REGION, &mem);
  330 +}
  331 +
312 332 void kvm_set_phys_mem(target_phys_addr_t start_addr,
313 333 ram_addr_t size,
314 334 ram_addr_t phys_offset)
... ... @@ -324,32 +344,32 @@ void kvm_set_phys_mem(target_phys_addr_t start_addr,
324 344 if (mem) {
325 345 if ((flags == IO_MEM_UNASSIGNED) || (flags >= TLB_MMIO)) {
326 346 mem->memory_size = 0;
327   - mem->guest_phys_addr = start_addr;
328   - mem->userspace_addr = 0;
  347 + mem->start_addr = start_addr;
  348 + mem->phys_offset = 0;
329 349 mem->flags = 0;
330 350  
331   - kvm_vm_ioctl(s, KVM_SET_USER_MEMORY_REGION, mem);
332   - } else if (start_addr >= mem->guest_phys_addr &&
333   - (start_addr + size) <= (mem->guest_phys_addr +
  351 + kvm_set_user_memory_region(s, mem);
  352 + } else if (start_addr >= mem->start_addr &&
  353 + (start_addr + size) <= (mem->start_addr +
334 354 mem->memory_size)) {
335 355 KVMSlot slot;
336 356 target_phys_addr_t mem_start;
337 357 ram_addr_t mem_size, mem_offset;
338 358  
339 359 /* Not splitting */
340   - if ((phys_offset - (start_addr - mem->guest_phys_addr)) ==
341   - ((uint8_t *)mem->userspace_addr - phys_ram_base))
  360 + if ((phys_offset - (start_addr - mem->start_addr)) ==
  361 + mem->phys_offset)
342 362 return;
343 363  
344 364 /* unregister whole slot */
345 365 memcpy(&slot, mem, sizeof(slot));
346 366 mem->memory_size = 0;
347   - kvm_vm_ioctl(s, KVM_SET_USER_MEMORY_REGION, mem);
  367 + kvm_set_user_memory_region(s, mem);
348 368  
349 369 /* register prefix slot */
350   - mem_start = slot.guest_phys_addr;
351   - mem_size = start_addr - slot.guest_phys_addr;
352   - mem_offset = (uint8_t *)slot.userspace_addr - phys_ram_base;
  370 + mem_start = slot.start_addr;
  371 + mem_size = start_addr - slot.start_addr;
  372 + mem_offset = slot.phys_offset;
353 373 if (mem_size)
354 374 kvm_set_phys_mem(mem_start, mem_size, mem_offset);
355 375  
... ... @@ -375,11 +395,11 @@ void kvm_set_phys_mem(target_phys_addr_t start_addr,
375 395  
376 396 mem = kvm_alloc_slot(s);
377 397 mem->memory_size = size;
378   - mem->guest_phys_addr = start_addr;
379   - mem->userspace_addr = (unsigned long)(phys_ram_base + phys_offset);
  398 + mem->start_addr = start_addr;
  399 + mem->phys_offset = phys_offset;
380 400 mem->flags = 0;
381 401  
382   - kvm_vm_ioctl(s, KVM_SET_USER_MEMORY_REGION, mem);
  402 + kvm_set_user_memory_region(s, mem);
383 403 /* FIXME deal with errors */
384 404 }
385 405  
... ...