ia64/xen-unstable

changeset 7037:8a757f283fb8

Add VGA acceleration support for cirrus logic device model

Signed-off-by: Xiaofeng Ling <xiaofeng.ling@intel.com>
Signed-off-by: Yunhong Jiang <yunhong.jiang@intel.com>
Signed-off-by: Asit Mallick <asit.k.mallick@intel.com>
author kaf24@firebug.cl.cam.ac.uk
date Fri Sep 23 13:30:54 2005 +0100 (2005-09-23)
parents 94c6fc048d8e
children 6aef7d1062bb
files tools/ioemu/hw/cirrus_vga.c tools/ioemu/hw/pc.c tools/ioemu/hw/vga.c tools/ioemu/target-i386-dm/helper2.c tools/ioemu/vl.c tools/libxc/xc_vmx_build.c
line diff
     1.1 --- a/tools/ioemu/hw/cirrus_vga.c	Fri Sep 23 12:52:43 2005 +0100
     1.2 +++ b/tools/ioemu/hw/cirrus_vga.c	Fri Sep 23 13:30:54 2005 +0100
     1.3 @@ -231,6 +231,8 @@ typedef struct CirrusVGAState {
     1.4      int cirrus_linear_io_addr;
     1.5      int cirrus_linear_bitblt_io_addr;
     1.6      int cirrus_mmio_io_addr;
     1.7 +    unsigned long cirrus_lfb_addr;
     1.8 +    unsigned long cirrus_lfb_end;
     1.9      uint32_t cirrus_addr_mask;
    1.10      uint32_t linear_mmio_mask;
    1.11      uint8_t cirrus_shadow_gr0;
    1.12 @@ -2447,6 +2449,10 @@ static void cirrus_update_memory_access(
    1.13  {
    1.14      unsigned mode;
    1.15  
    1.16 +    extern void unset_vram_mapping(unsigned long addr, unsigned long end);
    1.17 +    extern void set_vram_mapping(unsigned long addr, unsigned long end);
    1.18 +    extern int vga_accelerate;
    1.19 +
    1.20      if ((s->sr[0x17] & 0x44) == 0x44) {
    1.21          goto generic_io;
    1.22      } else if (s->cirrus_srcptr != s->cirrus_srcptr_end) {
    1.23 @@ -2454,17 +2460,21 @@ static void cirrus_update_memory_access(
    1.24      } else {
    1.25  	if ((s->gr[0x0B] & 0x14) == 0x14) {
    1.26              goto generic_io;
    1.27 -	} else if (s->gr[0x0B] & 0x02) {
    1.28 -            goto generic_io;
    1.29 -        }
    1.30 -        
    1.31 -	mode = s->gr[0x05] & 0x7;
    1.32 -	if (mode < 4 || mode > 5 || ((s->gr[0x0B] & 0x4) == 0)) {
    1.33 +    } else if (s->gr[0x0B] & 0x02) {
    1.34 +        goto generic_io;
    1.35 +    }
    1.36 +
    1.37 +    mode = s->gr[0x05] & 0x7;
    1.38 +    if (mode < 4 || mode > 5 || ((s->gr[0x0B] & 0x4) == 0)) {
    1.39 +            if (vga_accelerate && s->cirrus_lfb_addr && s->cirrus_lfb_end)
    1.40 +                set_vram_mapping(s->cirrus_lfb_addr, s->cirrus_lfb_end);
    1.41              s->cirrus_linear_write[0] = cirrus_linear_mem_writeb;
    1.42              s->cirrus_linear_write[1] = cirrus_linear_mem_writew;
    1.43              s->cirrus_linear_write[2] = cirrus_linear_mem_writel;
    1.44          } else {
    1.45          generic_io:
    1.46 +            if (vga_accelerate && s->cirrus_lfb_addr && s->cirrus_lfb_end)
    1.47 +                 unset_vram_mapping(s->cirrus_lfb_addr, s->cirrus_lfb_end);
    1.48              s->cirrus_linear_write[0] = cirrus_linear_writeb;
    1.49              s->cirrus_linear_write[1] = cirrus_linear_writew;
    1.50              s->cirrus_linear_write[2] = cirrus_linear_writel;
    1.51 @@ -3058,6 +3068,8 @@ static void cirrus_pci_lfb_map(PCIDevice
    1.52      /* XXX: add byte swapping apertures */
    1.53      cpu_register_physical_memory(addr, s->vram_size,
    1.54  				 s->cirrus_linear_io_addr);
    1.55 +    s->cirrus_lfb_addr = addr;
    1.56 +    s->cirrus_lfb_end = addr + VGA_RAM_SIZE;
    1.57      cpu_register_physical_memory(addr + 0x1000000, 0x400000,
    1.58  				 s->cirrus_linear_bitblt_io_addr);
    1.59  }
     2.1 --- a/tools/ioemu/hw/pc.c	Fri Sep 23 12:52:43 2005 +0100
     2.2 +++ b/tools/ioemu/hw/pc.c	Fri Sep 23 13:30:54 2005 +0100
     2.3 @@ -385,6 +385,7 @@ void pc_init(int ram_size, int vga_ram_s
     2.4      unsigned long bios_offset, vga_bios_offset;
     2.5      int bios_size, isa_bios_size;
     2.6      PCIBus *pci_bus;
     2.7 +    extern void * shared_vram;
     2.8      
     2.9      linux_boot = (kernel_filename != NULL);
    2.10  
    2.11 @@ -511,14 +512,14 @@ void pc_init(int ram_size, int vga_ram_s
    2.12      if (cirrus_vga_enabled) {
    2.13          if (pci_enabled) {
    2.14              pci_cirrus_vga_init(pci_bus, 
    2.15 -                                ds, phys_ram_base + ram_size, ram_size, 
    2.16 +                                ds, shared_vram, ram_size, 
    2.17                                  vga_ram_size);
    2.18          } else {
    2.19 -            isa_cirrus_vga_init(ds, phys_ram_base + ram_size, ram_size, 
    2.20 +            isa_cirrus_vga_init(ds, shared_vram, ram_size, 
    2.21                                  vga_ram_size);
    2.22          }
    2.23      } else {
    2.24 -        vga_initialize(pci_bus, ds, phys_ram_base + ram_size, ram_size, 
    2.25 +        vga_initialize(pci_bus, ds, shared_vram, ram_size, 
    2.26                         vga_ram_size);
    2.27      }
    2.28  
     3.1 --- a/tools/ioemu/hw/vga.c	Fri Sep 23 12:52:43 2005 +0100
     3.2 +++ b/tools/ioemu/hw/vga.c	Fri Sep 23 13:30:54 2005 +0100
     3.3 @@ -1568,6 +1568,8 @@ void vga_update_display(void)
     3.4              s->graphic_mode = graphic_mode;
     3.5              full_update = 1;
     3.6          }
     3.7 +
     3.8 +        full_update = 1;
     3.9          switch(graphic_mode) {
    3.10          case GMODE_TEXT:
    3.11              vga_draw_text(s, full_update);
    3.12 @@ -1848,6 +1850,7 @@ void vga_common_init(VGAState *s, Displa
    3.13                       unsigned long vga_ram_offset, int vga_ram_size)
    3.14  {
    3.15      int i, j, v, b;
    3.16 +    extern void* shared_vram;
    3.17  
    3.18      for(i = 0;i < 256; i++) {
    3.19          v = 0;
    3.20 @@ -1876,7 +1879,7 @@ void vga_common_init(VGAState *s, Displa
    3.21  
    3.22      /* qemu's vga mem is not detached from phys_ram_base and can cause DM abort
    3.23       * when guest write vga mem, so allocate a new one */
    3.24 -    s->vram_ptr = qemu_mallocz(vga_ram_size);
    3.25 +    s->vram_ptr = shared_vram;
    3.26  
    3.27      s->vram_offset = vga_ram_offset;
    3.28      s->vram_size = vga_ram_size;
     4.1 --- a/tools/ioemu/target-i386-dm/helper2.c	Fri Sep 23 12:52:43 2005 +0100
     4.2 +++ b/tools/ioemu/target-i386-dm/helper2.c	Fri Sep 23 13:30:54 2005 +0100
     4.3 @@ -54,6 +54,8 @@
     4.4  #include "exec-all.h"
     4.5  #include "vl.h"
     4.6  
     4.7 +void *shared_vram;
     4.8 +
     4.9  shared_iopage_t *shared_page = NULL;
    4.10  extern int reset_requested;
    4.11  
     5.1 --- a/tools/ioemu/vl.c	Fri Sep 23 12:52:43 2005 +0100
     5.2 +++ b/tools/ioemu/vl.c	Fri Sep 23 13:30:54 2005 +0100
     5.3 @@ -134,6 +134,7 @@ int pci_enabled = 1;
     5.4  int prep_enabled = 0;
     5.5  int rtc_utc = 1;
     5.6  int cirrus_vga_enabled = 1;
     5.7 +int vga_accelerate = 1;
     5.8  int graphic_width = 800;
     5.9  int graphic_height = 600;
    5.10  int graphic_depth = 15;
    5.11 @@ -141,6 +142,12 @@ int full_screen = 0;
    5.12  TextConsole *vga_console;
    5.13  CharDriverState *serial_hds[MAX_SERIAL_PORTS];
    5.14  int xc_handle;
    5.15 +unsigned long *vgapage_array;
    5.16 +unsigned long *freepage_array;
    5.17 +unsigned long free_pages;
    5.18 +void *vtop_table;
    5.19 +unsigned long toptab;
    5.20 +unsigned long vgaram_pages;
    5.21  
    5.22  /***********************************************************/
    5.23  /* x86 ISA bus support */
    5.24 @@ -2162,6 +2169,7 @@ void help(void)
    5.25             "-isa            simulate an ISA-only system (default is PCI system)\n"
    5.26             "-std-vga        simulate a standard VGA card with VESA Bochs Extensions\n"
    5.27             "                (default is CL-GD5446 PCI VGA)\n"
    5.28 +           "-vgaacc [0|1]   1 to accelerate CL-GD5446 speed, default is 1\n"
    5.29  #endif
    5.30             "-loadvm file    start right away with a saved state (loadvm in monitor)\n"
    5.31             "\n"
    5.32 @@ -2251,6 +2259,7 @@ enum {
    5.33      QEMU_OPTION_serial,
    5.34      QEMU_OPTION_loadvm,
    5.35      QEMU_OPTION_full_screen,
    5.36 +    QEMU_OPTION_vgaacc,
    5.37  };
    5.38  
    5.39  typedef struct QEMUOption {
    5.40 @@ -2327,6 +2336,7 @@ const QEMUOption qemu_options[] = {
    5.41      { "pci", 0, QEMU_OPTION_pci },
    5.42      { "nic-pcnet", 0, QEMU_OPTION_nic_pcnet },
    5.43      { "cirrusvga", 0, QEMU_OPTION_cirrusvga },
    5.44 +    { "vgaacc", HAS_ARG, QEMU_OPTION_vgaacc },
    5.45      { NULL },
    5.46  };
    5.47  
    5.48 @@ -2343,6 +2353,177 @@ static uint8_t *signal_stack;
    5.49  #define NET_IF_USER  1
    5.50  #define NET_IF_DUMMY 2
    5.51  
    5.52 +#include <xg_private.h>
    5.53 +
    5.54 +#define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_USER)
    5.55 +#define L2_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER)
    5.56 +
    5.57 +#ifdef __i386__
    5.58 +#define _LEVEL_3_ 0
    5.59 +#else
    5.60 +#define _LEVEL_3_ 1
    5.61 +#endif
    5.62 +
    5.63 +#if _LEVEL_3_
    5.64 +#define L3_PROT (_PAGE_PRESENT)
    5.65 +#define L1_PAGETABLE_ENTRIES    512
    5.66 +#else
    5.67 +#define L1_PAGETABLE_ENTRIES    1024
    5.68 +#endif
    5.69 +
    5.70 +inline int
    5.71 +get_vl2_table(unsigned long count, unsigned long start)
    5.72 +{
    5.73 +#if _LEVEL_3_
    5.74 +    return ((start + (count << PAGE_SHIFT)) >> L3_PAGETABLE_SHIFT) & 0x3;
    5.75 +#else
    5.76 +    return 0;
    5.77 +#endif
    5.78 +}
    5.79 +
    5.80 +int
    5.81 +setup_mapping(int xc_handle, u32 dom, unsigned long toptab, unsigned long  *mem_page_array, unsigned long *page_table_array, unsigned long v_start, unsigned long v_end)
    5.82 +{
    5.83 +    l1_pgentry_t *vl1tab=NULL, *vl1e=NULL;
    5.84 +    l2_pgentry_t *vl2tab[4], *vl2e=NULL, *vl2_table = NULL;
    5.85 +    unsigned long l1tab;
    5.86 +    unsigned long ppt_alloc = 0;
    5.87 +    unsigned long count;
    5.88 +    int i = 0;
    5.89 +#if _LEVEL_3_
    5.90 +    l3_pgentry_t *vl3tab = NULL;
    5.91 +    unsigned long l2tab;
    5.92 +    if ( (vl3tab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE, 
    5.93 +                                        PROT_READ|PROT_WRITE, 
    5.94 +                                        toptab >> PAGE_SHIFT)) == NULL )
    5.95 +        goto error_out;
    5.96 +    for (i = 0; i < 4 ; i++) {
    5.97 +        l2tab = vl3tab[i] & PAGE_MASK;
    5.98 +        vl2tab[i] = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
    5.99 +          PROT_READ|PROT_WRITE,
   5.100 +          l2tab >> PAGE_SHIFT);
   5.101 +        if(vl2tab[i] == NULL)
   5.102 +            goto error_out;
   5.103 +    }
   5.104 +    munmap(vl3tab, PAGE_SIZE);
   5.105 +    vl3tab = NULL;
   5.106 +#else
   5.107 +    if ( (vl2tab[0] = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE, 
   5.108 +                                           PROT_READ|PROT_WRITE, 
   5.109 +                                           toptab >> PAGE_SHIFT)) == NULL )
   5.110 +        goto error_out;
   5.111 +#endif
   5.112 +
   5.113 +    for ( count = 0; count < ((v_end-v_start)>>PAGE_SHIFT); count++ )
   5.114 +    {
   5.115 +        if ( ((unsigned long)vl1e & (PAGE_SIZE-1)) == 0 )
   5.116 +        {
   5.117 +            vl2_table = vl2tab[get_vl2_table(count, v_start)];
   5.118 +            vl2e = &vl2_table[l2_table_offset(
   5.119 +                v_start + (count << PAGE_SHIFT))];
   5.120 +
   5.121 +            l1tab = page_table_array[ppt_alloc++] << PAGE_SHIFT;
   5.122 +            if ( vl1tab != NULL )
   5.123 +                munmap(vl1tab, PAGE_SIZE);
   5.124 +
   5.125 +            if ( (vl1tab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
   5.126 +                                                PROT_READ|PROT_WRITE,
   5.127 +                                                l1tab >> PAGE_SHIFT)) == NULL )
   5.128 +            {
   5.129 +                goto error_out;
   5.130 +            }
   5.131 +            memset(vl1tab, 0, PAGE_SIZE);
   5.132 +            vl1e = &vl1tab[l1_table_offset(v_start + (count<<PAGE_SHIFT))];
   5.133 +            *vl2e = l1tab | L2_PROT;
   5.134 +        }
   5.135 +
   5.136 +        *vl1e = (mem_page_array[count] << PAGE_SHIFT) | L1_PROT;
   5.137 +        vl1e++;
   5.138 +    }
   5.139 +error_out:
   5.140 +    if(vl1tab)  munmap(vl1tab, PAGE_SIZE);
   5.141 +    for(i = 0; i < 4; i++)
   5.142 +        if(vl2tab[i]) munmap(vl2tab[i], PAGE_SIZE);
   5.143 +    return ppt_alloc;
   5.144 +}
   5.145 +
   5.146 +void
   5.147 +unsetup_mapping(int xc_handle, u32 dom, unsigned long toptab, unsigned long v_start, unsigned long v_end)
   5.148 +{
   5.149 +    l1_pgentry_t *vl1tab=NULL, *vl1e=NULL;
   5.150 +    l2_pgentry_t *vl2tab[4], *vl2e=NULL, *vl2_table = NULL;
   5.151 +    unsigned long l1tab;
   5.152 +    unsigned long count;
   5.153 +    int i = 0;
   5.154 +#if _LEVEL_3_
   5.155 +    l3_pgentry_t *vl3tab = NULL;
   5.156 +    unsigned long l2tab;
   5.157 +    if ( (vl3tab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE, 
   5.158 +                                        PROT_READ|PROT_WRITE, 
   5.159 +                                        toptab >> PAGE_SHIFT)) == NULL )
   5.160 +        goto error_out;
   5.161 +    for (i = 0; i < 4 ; i ++){
   5.162 +        l2tab = vl3tab[i] & PAGE_MASK;
   5.163 +        vl2tab[i] = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
   5.164 +          PROT_READ|PROT_WRITE,
   5.165 +          l2tab >> PAGE_SHIFT);
   5.166 +        if(vl2tab[i] == NULL)
   5.167 +            goto error_out;
   5.168 +    }
   5.169 +    munmap(vl3tab, PAGE_SIZE);
   5.170 +    vl3tab = NULL;
   5.171 +#else
   5.172 +    if ( (vl2tab[0] = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE, 
   5.173 +                                        PROT_READ|PROT_WRITE, 
   5.174 +                                        toptab >> PAGE_SHIFT)) == NULL )
   5.175 +        goto error_out;
   5.176 +#endif
   5.177 +
   5.178 +    for ( count = 0; count < ((v_end-v_start)>>PAGE_SHIFT); count++ ){
   5.179 +        if ( ((unsigned long)vl1e & (PAGE_SIZE-1)) == 0 )
   5.180 +        {
   5.181 +            vl2_table = vl2tab[get_vl2_table(count, v_start)];
   5.182 +            vl2e = &vl2_table[l2_table_offset(v_start + (count << PAGE_SHIFT))];
   5.183 +            l1tab = *vl2e & PAGE_MASK;
   5.184 +
   5.185 +            if(l1tab == 0)
   5.186 +                continue;
   5.187 +            if ( vl1tab != NULL )
   5.188 +                munmap(vl1tab, PAGE_SIZE);
   5.189 +
   5.190 +            if ( (vl1tab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
   5.191 +                      PROT_READ|PROT_WRITE,
   5.192 +                      l1tab >> PAGE_SHIFT)) == NULL )
   5.193 +            {
   5.194 +                goto error_out;
   5.195 +            }
   5.196 +            vl1e = &vl1tab[l1_table_offset(v_start + (count<<PAGE_SHIFT))];
   5.197 +            *vl2e = 0;
   5.198 +        }
   5.199 +
   5.200 +        *vl1e = 0;
   5.201 +        vl1e++;
   5.202 +    }
   5.203 +error_out:
   5.204 +    if(vl1tab)  munmap(vl1tab, PAGE_SIZE);
   5.205 +    for(i = 0; i < 4; i++)
   5.206 +        if(vl2tab[i]) munmap(vl2tab[i], PAGE_SIZE);
   5.207 +}
   5.208 +
   5.209 +void set_vram_mapping(unsigned long addr, unsigned long end)
   5.210 +{
   5.211 +    end = addr + VGA_RAM_SIZE;
   5.212 +    setup_mapping(xc_handle, domid, toptab,
   5.213 +      vgapage_array, freepage_array, addr, end);
   5.214 +}
   5.215 +
   5.216 +void unset_vram_mapping(unsigned long addr, unsigned long end)
   5.217 +{
   5.218 +    end = addr + VGA_RAM_SIZE;
   5.219 +    /* FIXME Flush the shadow page */
   5.220 +    unsetup_mapping(xc_handle, domid, toptab, addr, end);
   5.221 +}
   5.222 +
   5.223  int main(int argc, char **argv)
   5.224  {
   5.225  #ifdef CONFIG_GDBSTUB
   5.226 @@ -2366,8 +2547,9 @@ int main(int argc, char **argv)
   5.227      char serial_devices[MAX_SERIAL_PORTS][128];
   5.228      int serial_device_index;
   5.229      const char *loadvm = NULL;
   5.230 -    unsigned long nr_pages, *page_array;
   5.231 +    unsigned long nr_pages, extra_pages, ram_pages, *page_array;
   5.232      extern void *shared_page;
   5.233 +    extern void *shared_vram;
   5.234      /* change the qemu-dm to daemon, just like bochs dm */
   5.235  //    daemon(0, 0);
   5.236      
   5.237 @@ -2674,6 +2856,17 @@ int main(int argc, char **argv)
   5.238              case QEMU_OPTION_cirrusvga:
   5.239                  cirrus_vga_enabled = 1;
   5.240                  break;
   5.241 +            case QEMU_OPTION_vgaacc:
   5.242 +                {
   5.243 +                    const char *p;
   5.244 +                    p = optarg;
   5.245 +                    vga_accelerate = strtol(p, (char **)&p, 0);
   5.246 +                    if (*p != '\0') {
   5.247 +                        fprintf(stderr, "qemu: invalid vgaacc option\n");
   5.248 +                        exit(1);
   5.249 +                    }
   5.250 +                    break;
   5.251 +                }
   5.252              case QEMU_OPTION_std_vga:
   5.253                  cirrus_vga_enabled = 0;
   5.254                  break;
   5.255 @@ -2803,12 +2996,25 @@ int main(int argc, char **argv)
   5.256      /* init the memory */
   5.257      phys_ram_size = ram_size + vga_ram_size + bios_size;
   5.258  
   5.259 -    #define PAGE_SHIFT 12
   5.260 -    #define PAGE_SIZE  (1 << PAGE_SHIFT)
   5.261 -
   5.262 -    nr_pages = ram_size/PAGE_SIZE;
   5.263 +    ram_pages = ram_size/PAGE_SIZE;
   5.264 +    vgaram_pages =  (vga_ram_size -1)/PAGE_SIZE + 1;
   5.265 +    free_pages = vgaram_pages / L1_PAGETABLE_ENTRIES;
   5.266 +    extra_pages = vgaram_pages + free_pages;
   5.267 +
   5.268      xc_handle = xc_interface_open();
   5.269 -    
   5.270 +
   5.271 +    xc_dominfo_t info;
   5.272 +    xc_domain_getinfo(xc_handle, domid, 1, &info);
   5.273 +
   5.274 +    nr_pages = info.nr_pages + extra_pages;
   5.275 +
   5.276 +    if ( xc_domain_setmaxmem(xc_handle, domid,
   5.277 +            (nr_pages) * PAGE_SIZE/1024 ) != 0)
   5.278 +    {
   5.279 +        perror("set maxmem");
   5.280 +        exit(-1);
   5.281 +    }
   5.282 +   
   5.283      if ( (page_array = (unsigned long *)
   5.284  	  malloc(nr_pages * sizeof(unsigned long))) == NULL)
   5.285      {
   5.286 @@ -2816,6 +3022,12 @@ int main(int argc, char **argv)
   5.287  	    exit(-1);
   5.288      }
   5.289  
   5.290 +    if (xc_domain_memory_increase_reservation(xc_handle, domid, 
   5.291 +          extra_pages , 0, 0, NULL) != 0) {
   5.292 +        perror("increase reservation");
   5.293 +        exit(-1);
   5.294 +    }
   5.295 +
   5.296      if ( xc_get_pfn_list(xc_handle, domid, page_array, nr_pages) != nr_pages )
   5.297      {
   5.298  	    perror("xc_get_pfn_list");
   5.299 @@ -2825,15 +3037,36 @@ int main(int argc, char **argv)
   5.300      if ((phys_ram_base =  xc_map_foreign_batch(xc_handle, domid,
   5.301  						 PROT_READ|PROT_WRITE,
   5.302  						 page_array,
   5.303 -						 nr_pages - 1)) == 0) {
   5.304 +						 ram_pages - 1)) == 0) {
   5.305  	    perror("xc_map_foreign_batch");
   5.306  	    exit(-1);
   5.307      }
   5.308  
   5.309      shared_page = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
   5.310  				       PROT_READ|PROT_WRITE,
   5.311 -				       page_array[nr_pages - 1]);
   5.312 -
   5.313 + 				       page_array[ram_pages - 1]);
   5.314 +
   5.315 +    vgapage_array = &page_array[nr_pages - vgaram_pages];
   5.316 +
   5.317 +    if ((shared_vram =  xc_map_foreign_batch(xc_handle, domid,
   5.318 + 						 PROT_READ|PROT_WRITE,
   5.319 + 						 vgapage_array,
   5.320 + 						 vgaram_pages)) == 0) {
   5.321 + 	    perror("xc_map_foreign_batch vgaram ");
   5.322 + 	    exit(-1);
   5.323 +     }
   5.324 +
   5.325 +
   5.326 +
   5.327 +    memset(shared_vram, 0, vgaram_pages * PAGE_SIZE);
   5.328 +    toptab = page_array[ram_pages] << PAGE_SHIFT;
   5.329 +
   5.330 +    vtop_table = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
   5.331 +				       PROT_READ|PROT_WRITE,
   5.332 + 				       page_array[ram_pages]);
   5.333 +
   5.334 +    freepage_array = &page_array[nr_pages - extra_pages];
   5.335 + 
   5.336  
   5.337      fprintf(logfile, "shared page at pfn:%lx, mfn: %lx\n", (nr_pages-1), 
   5.338             (page_array[nr_pages - 1]));
     6.1 --- a/tools/libxc/xc_vmx_build.c	Fri Sep 23 12:52:43 2005 +0100
     6.2 +++ b/tools/libxc/xc_vmx_build.c	Fri Sep 23 13:30:54 2005 +0100
     6.3 @@ -383,7 +383,6 @@ static int setup_guest(int xc_handle,
     6.4      l2tab = page_array[ppt_alloc++] << PAGE_SHIFT;
     6.5      ctxt->ctrlreg[3] = l2tab;
     6.6  
     6.7 -    /* Initialise the page tables. */
     6.8      if ( (vl2tab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
     6.9                                          PROT_READ|PROT_WRITE,
    6.10                                          l2tab >> PAGE_SHIFT)) == NULL )
    6.11 @@ -415,23 +414,35 @@ static int setup_guest(int xc_handle,
    6.12      munmap(vl1tab, PAGE_SIZE);
    6.13      munmap(vl2tab, PAGE_SIZE);
    6.14  #else
    6.15 -    /* here l3tab means pdpt, only 4 entry is used */
    6.16      l3tab = page_array[ppt_alloc++] << PAGE_SHIFT;
    6.17      ctxt->ctrlreg[3] = l3tab;
    6.18  
    6.19 -    /* Initialise the page tables. */
    6.20      if ( (vl3tab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
    6.21                                          PROT_READ|PROT_WRITE,
    6.22                                          l3tab >> PAGE_SHIFT)) == NULL )
    6.23          goto error_out;
    6.24      memset(vl3tab, 0, PAGE_SIZE);
    6.25  
    6.26 +    /* Fill in every PDPT entry. */
    6.27 +    for ( i = 0; i < L3_PAGETABLE_ENTRIES_PAE; i++ )
    6.28 +    {
    6.29 +        l2tab = page_array[ppt_alloc++] << PAGE_SHIFT;
    6.30 +        if ( (vl2tab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
    6.31 +                                            PROT_READ|PROT_WRITE,
    6.32 +                                            l2tab >> PAGE_SHIFT)) == NULL )
    6.33 +            goto error_out;
    6.34 +        memset(vl2tab, 0, PAGE_SIZE);
    6.35 +        munmap(vl2tab, PAGE_SIZE);
    6.36 +        vl3tab[i] = l2tab | L3_PROT;
    6.37 +    }
    6.38 +
    6.39      vl3e = &vl3tab[l3_table_offset(dsi.v_start)];
    6.40  
    6.41      for ( count = 0; count < ((v_end-dsi.v_start)>>PAGE_SHIFT); count++ )
    6.42      {
    6.43 -        if (!(count % (1 << (L3_PAGETABLE_SHIFT - L1_PAGETABLE_SHIFT)))){
    6.44 -            l2tab = page_array[ppt_alloc++] << PAGE_SHIFT;
    6.45 +        if (!(count & (1 << (L3_PAGETABLE_SHIFT - L1_PAGETABLE_SHIFT)))){
    6.46 +            l2tab = vl3tab[count >> (L3_PAGETABLE_SHIFT - L1_PAGETABLE_SHIFT)]
    6.47 +                & PAGE_MASK;
    6.48  
    6.49              if (vl2tab != NULL)
    6.50                  munmap(vl2tab, PAGE_SIZE);
    6.51 @@ -441,8 +452,6 @@ static int setup_guest(int xc_handle,
    6.52                                                  l2tab >> PAGE_SHIFT)) == NULL )
    6.53                  goto error_out;
    6.54  
    6.55 -            memset(vl2tab, 0, PAGE_SIZE);
    6.56 -            *vl3e++ = l2tab | L3_PROT;
    6.57              vl2e = &vl2tab[l2_table_offset(dsi.v_start + (count << PAGE_SHIFT))];
    6.58          }
    6.59          if ( ((unsigned long)vl1e & (PAGE_SIZE-1)) == 0 )