ia64/xen-unstable

changeset 12022:2041122e0c4a

[HVM] Fix qemu's test for whether physcal addresses are RAM.
HVM guests have a memory hole below 4GB, so can't just check whether
addresses are < the amount of RAM allocated.
Signed-off-by: Tim Deegan <Tim.Deegan@xensource.com>
author Tim Deegan <Tim.Deegan@xensource.com>
date Thu Oct 26 15:08:20 2006 +0100 (2006-10-26)
parents 66cdabe97205
children 4a320d26fc24
files tools/ioemu/target-i386-dm/exec-dm.c
line diff
     1.1 --- a/tools/ioemu/target-i386-dm/exec-dm.c	Thu Oct 26 11:50:17 2006 +0100
     1.2 +++ b/tools/ioemu/target-i386-dm/exec-dm.c	Thu Oct 26 15:08:20 2006 +0100
     1.3 @@ -32,6 +32,8 @@
     1.4  #include <unistd.h>
     1.5  #include <inttypes.h>
     1.6  
     1.7 +#include <xen/hvm/e820.h>
     1.8 +
     1.9  #include "cpu.h"
    1.10  #include "exec-all.h"
    1.11  
    1.12 @@ -407,22 +409,36 @@ int iomem_index(target_phys_addr_t addr)
    1.13          return 0;
    1.14  }
    1.15  
    1.16 +static inline int paddr_is_ram(target_phys_addr_t addr)
    1.17 +{
    1.18 +    /* Is this guest physical address RAM-backed? */
    1.19 +#if defined(CONFIG_DM) && (defined(__i386__) || defined(__x86_64__))
    1.20 +    if (ram_size <= HVM_BELOW_4G_RAM_END)
    1.21 +        /* RAM is contiguous */
    1.22 +        return (addr < ram_size);
    1.23 +    else
    1.24 +        /* There is RAM below and above the MMIO hole */
    1.25 +        return ((addr < HVM_BELOW_4G_MMIO_START) ||
    1.26 +                ((addr >= HVM_BELOW_4G_MMIO_START + HVM_BELOW_4G_MMIO_LENGTH)
    1.27 +                 && (addr < ram_size + HVM_BELOW_4G_MMIO_LENGTH)));
    1.28 +#else
    1.29 +    return (addr < ram_size);
    1.30 +#endif
    1.31 +}
    1.32 +
    1.33  void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf, 
    1.34                              int len, int is_write)
    1.35  {
    1.36      int l, io_index;
    1.37      uint8_t *ptr;
    1.38      uint32_t val;
    1.39 -    target_phys_addr_t page;
    1.40 -    unsigned long pd;
    1.41      
    1.42      while (len > 0) {
    1.43 -        page = addr & TARGET_PAGE_MASK;
    1.44 -        l = (page + TARGET_PAGE_SIZE) - addr;
    1.45 +        /* How much can we copy before the next page boundary? */
    1.46 +        l = TARGET_PAGE_SIZE - (addr & ~TARGET_PAGE_MASK); 
    1.47          if (l > len)
    1.48              l = len;
    1.49  	
    1.50 -        pd = page;
    1.51          io_index = iomem_index(addr);
    1.52          if (is_write) {
    1.53              if (io_index) {
    1.54 @@ -442,15 +458,11 @@ void cpu_physical_memory_rw(target_phys_
    1.55                      io_mem_write[io_index][0](io_mem_opaque[io_index], addr, val);
    1.56                      l = 1;
    1.57                  }
    1.58 -            } else {
    1.59 -                unsigned long addr1;
    1.60 -
    1.61 -                addr1 = (pd & TARGET_PAGE_MASK) + (addr & ~TARGET_PAGE_MASK);
    1.62 -                /* RAM case */
    1.63 -                ptr = phys_ram_base + addr1;
    1.64 -                memcpy(ptr, buf, l);
    1.65 +            } else if (paddr_is_ram(addr)) {
    1.66 +                /* Reading from RAM */
    1.67 +                memcpy(phys_ram_base + addr, buf, l);
    1.68  #ifdef __ia64__
    1.69 -                sync_icache((unsigned long)ptr, l);
    1.70 +                sync_icache((unsigned long)(phys_ram_base + addr), l);
    1.71  #endif 
    1.72              }
    1.73          } else {
    1.74 @@ -471,14 +483,12 @@ void cpu_physical_memory_rw(target_phys_
    1.75                      stb_raw(buf, val);
    1.76                      l = 1;
    1.77                  }
    1.78 -            } else if (addr < ram_size) {
    1.79 -                /* RAM case */
    1.80 -                ptr = phys_ram_base + (pd & TARGET_PAGE_MASK) + 
    1.81 -                    (addr & ~TARGET_PAGE_MASK);
    1.82 -                memcpy(buf, ptr, l);
    1.83 +            } else if (paddr_is_ram(addr)) {
    1.84 +                /* Reading from RAM */
    1.85 +                memcpy(buf, phys_ram_base + addr, l);
    1.86              } else {
    1.87 -                /* unreported MMIO space */
    1.88 -                memset(buf, 0xff, len);
    1.89 +                /* Neither RAM nor known MMIO space */
    1.90 +                memset(buf, 0xff, len); 
    1.91              }
    1.92          }
    1.93          len -= l;