ia64/xen-unstable

changeset 8872:40d7eef7d3f5

Re-enable VGA acceleration under the new phys_to_machine_mapping.

Signed-off-by: Yunhong Jiang <yunhong.jiang@intel.com>
Signed-off-by: Xin B Li <xin.b.li@intel.com>
Signed-off-by: Jun Nakajima <jun.nakajima@intel.com>
author kaf24@firebug.cl.cam.ac.uk
date Thu Feb 16 19:04:33 2006 +0100 (2006-02-16)
parents 0d10fac28427
children 50b1fe78e2e8
files tools/ioemu/hw/cirrus_vga.c tools/ioemu/hw/vga.c tools/ioemu/hw/vga_int.h tools/ioemu/vl.c
line diff
     1.1 --- a/tools/ioemu/hw/cirrus_vga.c	Thu Feb 16 18:52:06 2006 +0100
     1.2 +++ b/tools/ioemu/hw/cirrus_vga.c	Thu Feb 16 19:04:33 2006 +0100
     1.3 @@ -269,6 +269,7 @@ typedef struct CirrusVGAState {
     1.4      int last_hw_cursor_y_end;
     1.5      int real_vram_size; /* XXX: suppress that */
     1.6      CPUWriteMemoryFunc **cirrus_linear_write;
     1.7 +    int set_mapping;
     1.8  } CirrusVGAState;
     1.9  
    1.10  typedef struct PCICirrusVGAState {
    1.11 @@ -2431,7 +2432,6 @@ static void cirrus_linear_bitblt_writel(
    1.12  #endif
    1.13  }
    1.14  
    1.15 -
    1.16  static CPUReadMemoryFunc *cirrus_linear_bitblt_read[3] = {
    1.17      cirrus_linear_bitblt_readb,
    1.18      cirrus_linear_bitblt_readw,
    1.19 @@ -2448,9 +2448,9 @@ static CPUWriteMemoryFunc *cirrus_linear
    1.20  static void cirrus_update_memory_access(CirrusVGAState *s)
    1.21  {
    1.22      unsigned mode;
    1.23 +    extern void * set_vram_mapping(unsigned long addr, unsigned long end);
    1.24  
    1.25 -    extern void unset_vram_mapping(unsigned long addr, unsigned long end);
    1.26 -    extern void set_vram_mapping(unsigned long addr, unsigned long end);
    1.27 +    extern int unset_vram_mapping(unsigned long addr, unsigned long end);
    1.28      extern int vga_accelerate;
    1.29  
    1.30      if ((s->sr[0x17] & 0x44) == 0x44) {
    1.31 @@ -2466,15 +2466,36 @@ static void cirrus_update_memory_access(
    1.32  
    1.33      mode = s->gr[0x05] & 0x7;
    1.34      if (mode < 4 || mode > 5 || ((s->gr[0x0B] & 0x4) == 0)) {
    1.35 -            if (vga_accelerate && s->cirrus_lfb_addr && s->cirrus_lfb_end)
    1.36 -                set_vram_mapping(s->cirrus_lfb_addr, s->cirrus_lfb_end);
    1.37 +            if (vga_accelerate && s->cirrus_lfb_addr && s->cirrus_lfb_end) {
    1.38 +                if (!s->set_mapping) {
    1.39 +                    void * vram_pointer;
    1.40 +                    s->set_mapping = 1;
    1.41 +                    vram_pointer = set_vram_mapping(s->cirrus_lfb_addr ,s->cirrus_lfb_end);
    1.42 +                    if (!vram_pointer){
    1.43 +                        fprintf(stderr, "NULL vram_pointer\n");
    1.44 +                    } else
    1.45 +                    {
    1.46 +                        vga_update_vram((VGAState *)s, vram_pointer,
    1.47 +                                        VGA_RAM_SIZE);
    1.48 +                    }
    1.49 +                }
    1.50 +            }
    1.51              s->cirrus_linear_write[0] = cirrus_linear_mem_writeb;
    1.52              s->cirrus_linear_write[1] = cirrus_linear_mem_writew;
    1.53              s->cirrus_linear_write[2] = cirrus_linear_mem_writel;
    1.54          } else {
    1.55          generic_io:
    1.56 -            if (vga_accelerate && s->cirrus_lfb_addr && s->cirrus_lfb_end)
    1.57 -                 unset_vram_mapping(s->cirrus_lfb_addr, s->cirrus_lfb_end);
    1.58 +            if (vga_accelerate && s->cirrus_lfb_addr && s->cirrus_lfb_end) {
    1.59 +                if(s->set_mapping) {
    1.60 +                    int error;
    1.61 +                    s->set_mapping = 0;
    1.62 +                    error = unset_vram_mapping(s->cirrus_lfb_addr,
    1.63 +                                           s->cirrus_lfb_end);
    1.64 +                    if (!error)
    1.65 +                        vga_update_vram((VGAState *)s, NULL, VGA_RAM_SIZE);
    1.66 +                }
    1.67 +            }
    1.68 +
    1.69              s->cirrus_linear_write[0] = cirrus_linear_writeb;
    1.70              s->cirrus_linear_write[1] = cirrus_linear_writew;
    1.71              s->cirrus_linear_write[2] = cirrus_linear_writel;
     2.1 --- a/tools/ioemu/hw/vga.c	Thu Feb 16 18:52:06 2006 +0100
     2.2 +++ b/tools/ioemu/hw/vga.c	Thu Feb 16 19:04:33 2006 +0100
     2.3 @@ -1974,6 +1974,31 @@ int vga_initialize(PCIBus *bus, DisplayS
     2.4      return 0;
     2.5  }
     2.6  
     2.7 +int vga_update_vram(VGAState *s, void *vga_ram_base, int vga_ram_size)
     2.8 +{
     2.9 +    if (s->vram_size != vga_ram_size)
    2.10 +    {
    2.11 +        fprintf(stderr, "No support to change vga_ram_size\n");
    2.12 +        return -1;
    2.13 +    }
    2.14 +
    2.15 +    if ( !vga_ram_base )
    2.16 +    {
    2.17 +        vga_ram_base = qemu_malloc(vga_ram_size);
    2.18 +        if (!vga_ram_base)
    2.19 +        {
    2.20 +            fprintf(stderr, "reallocate error\n");
    2.21 +            return -1;
    2.22 +        }
    2.23 +    }
    2.24 +
    2.25 +    /* XXX lock needed? */
    2.26 +    memcpy(vga_ram_base, s->vram_ptr, vga_ram_size);
    2.27 +    s->vram_ptr = vga_ram_base;
    2.28 +
    2.29 +    return 0;
    2.30 +}
    2.31 +
    2.32  /********************************************************/
    2.33  /* vga screen dump */
    2.34  
     3.1 --- a/tools/ioemu/hw/vga_int.h	Thu Feb 16 18:52:06 2006 +0100
     3.2 +++ b/tools/ioemu/hw/vga_int.h	Thu Feb 16 19:04:33 2006 +0100
     3.3 @@ -164,5 +164,6 @@ void vga_draw_cursor_line_32(uint8_t *d1
     3.4                               unsigned int color0, unsigned int color1,
     3.5                               unsigned int color_xor);
     3.6  
     3.7 +int vga_update_vram(VGAState *s, void *vga_ram_base, int vga_ram_size);
     3.8  extern const uint8_t sr_mask[8];
     3.9  extern const uint8_t gr_mask[16];
     4.1 --- a/tools/ioemu/vl.c	Thu Feb 16 18:52:06 2006 +0100
     4.2 +++ b/tools/ioemu/vl.c	Thu Feb 16 19:04:33 2006 +0100
     4.3 @@ -2485,158 +2485,165 @@ get_vl2_table(unsigned long count, unsig
     4.4  #endif
     4.5  }
     4.6  
     4.7 -int
     4.8 -setup_mapping(int xc_handle, uint32_t dom, unsigned long toptab,
     4.9 -              unsigned long  *mem_page_array, unsigned long *page_table_array,
    4.10 -              unsigned long v_start, unsigned long v_end)
    4.11 +/* FIXME Flush the shadow page */
    4.12 +static int unset_mm_mapping(int xc_handle,
    4.13 +                     uint32_t domid,
    4.14 +                     unsigned long nr_pages,
    4.15 +                     unsigned int address_bits,
    4.16 +                     unsigned long *extent_start)
    4.17  {
    4.18 -    l1_pgentry_t *vl1tab=NULL, *vl1e=NULL;
    4.19 -    l2_pgentry_t *vl2tab[4] = {NULL, NULL, NULL, NULL};
    4.20 -    l2_pgentry_t *vl2e=NULL, *vl2_table = NULL;
    4.21 -    unsigned long l1tab;
    4.22 -    unsigned long ppt_alloc = 0;
    4.23 -    unsigned long count;
    4.24 -    int i = 0;
    4.25 -#if _LEVEL_3_
    4.26 -    l3_pgentry_t *vl3tab = NULL;
    4.27 -    unsigned long l2tab;
    4.28 -
    4.29 -    if ( (vl3tab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
    4.30 -                                        PROT_READ|PROT_WRITE,
    4.31 -                                        toptab >> PAGE_SHIFT)) == NULL )
    4.32 -        goto error_out;
    4.33 -    for (i = 0; i < 4 ; i++) {
    4.34 -        l2tab = vl3tab[i] & PAGE_MASK;
    4.35 -        vl2tab[i] = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
    4.36 -                                         PROT_READ|PROT_WRITE,
    4.37 -                                         l2tab >> PAGE_SHIFT);
    4.38 -        if(vl2tab[i] == NULL)
    4.39 -            goto error_out;
    4.40 +    int err = 0;
    4.41 +    xc_dominfo_t info;
    4.42 +
    4.43 +    err = xc_domain_memory_decrease_reservation(xc_handle, domid,
    4.44 +      nr_pages, 0, extent_start);
    4.45 +
    4.46 +    if ( err )
    4.47 +        fprintf(stderr, "Failed to decrease physmap\n");
    4.48 +
    4.49 +    xc_domain_getinfo(xc_handle, domid, 1, &info);
    4.50 +
    4.51 +    if ( (info.nr_pages - nr_pages) <= 0 )
    4.52 +    {
    4.53 +        fprintf(stderr, "unset_mm_mapping: error nr_pages\n");
    4.54 +        err = -1;
    4.55      }
    4.56 -    munmap(vl3tab, PAGE_SIZE);
    4.57 -    vl3tab = NULL;
    4.58 -#else
    4.59 -    if ( (vl2tab[0] = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
    4.60 -                                           PROT_READ|PROT_WRITE,
    4.61 -                                           toptab >> PAGE_SHIFT)) == NULL )
    4.62 -        goto error_out;
    4.63 -#endif
    4.64 -
    4.65 -    for ( count = 0; count < ((v_end-v_start)>>PAGE_SHIFT); count++ )
    4.66 +
    4.67 +    if ( xc_domain_setmaxmem(xc_handle, domid,
    4.68 +                             (info.nr_pages - nr_pages) * PAGE_SIZE/1024) != 0)
    4.69      {
    4.70 -        if ( ((unsigned long)vl1e & (PAGE_SIZE-1)) == 0 )
    4.71 -        {
    4.72 -            vl2_table = vl2tab[get_vl2_table(count, v_start)];
    4.73 -            vl2e = &vl2_table[l2_table_offset(v_start +
    4.74 -                                              (count << PAGE_SHIFT))];
    4.75 -
    4.76 -            l1tab = page_table_array[ppt_alloc++] << PAGE_SHIFT;
    4.77 -            if ( vl1tab != NULL )
    4.78 -                munmap(vl1tab, PAGE_SIZE);
    4.79 -
    4.80 -            if ( (vl1tab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
    4.81 -                                                PROT_READ|PROT_WRITE,
    4.82 -                                                l1tab >> PAGE_SHIFT)) == NULL )
    4.83 -            {
    4.84 -                goto error_out;
    4.85 -            }
    4.86 -            memset(vl1tab, 0, PAGE_SIZE);
    4.87 -            vl1e = &vl1tab[l1_table_offset(v_start + (count<<PAGE_SHIFT))];
    4.88 -            *vl2e = l1tab | L2_PROT;
    4.89 -        }
    4.90 -
    4.91 -        *vl1e = (mem_page_array[count] << PAGE_SHIFT) | L1_PROT;
    4.92 -        vl1e++;
    4.93 +        fprintf(logfile, "set maxmem returned error %d\n", errno);
    4.94 +        err = -1;
    4.95      }
    4.96 -error_out:
    4.97 -    if (vl1tab)
    4.98 -        munmap(vl1tab, PAGE_SIZE);
    4.99 -    for(i = 0; i < 4; i++)
   4.100 -        if(vl2tab[i]) munmap(vl2tab[i], PAGE_SIZE);
   4.101 -    return ppt_alloc;
   4.102 +
   4.103 +    return err;
   4.104  }
   4.105  
   4.106 -void
   4.107 -unsetup_mapping(int xc_handle, uint32_t dom, unsigned long toptab,
   4.108 -                unsigned long v_start, unsigned long v_end)
   4.109 +static int set_mm_mapping(int xc_handle,
   4.110 +                    uint32_t domid,
   4.111 +                    unsigned long nr_pages,
   4.112 +                    unsigned int address_bits,
   4.113 +                    unsigned long *extent_start)
   4.114  {
   4.115 -    l1_pgentry_t *vl1tab=NULL, *vl1e=NULL;
   4.116 -    l2_pgentry_t *vl2tab[4], *vl2e=NULL, *vl2_table = NULL;
   4.117 -    unsigned long l1tab;
   4.118 -    unsigned long count;
   4.119 -    int i = 0;
   4.120 -#if _LEVEL_3_
   4.121 -    l3_pgentry_t *vl3tab = NULL;
   4.122 -    unsigned long l2tab;
   4.123 -
   4.124 -    if ( (vl3tab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
   4.125 -                                        PROT_READ|PROT_WRITE,
   4.126 -                                        toptab >> PAGE_SHIFT)) == NULL )
   4.127 -        goto error_out;
   4.128 -    for (i = 0; i < 4 ; i ++) {
   4.129 -        l2tab = vl3tab[i] & PAGE_MASK;
   4.130 -        vl2tab[i] = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
   4.131 -                                         PROT_READ|PROT_WRITE,
   4.132 -                                         l2tab >> PAGE_SHIFT);
   4.133 -        if (vl2tab[i] == NULL)
   4.134 -            goto error_out;
   4.135 +    int i;
   4.136 +    xc_dominfo_t info;
   4.137 +    int err = 0;
   4.138 +
   4.139 +    xc_domain_getinfo(xc_handle, domid, 1, &info);
   4.140 +
   4.141 +    if ( xc_domain_setmaxmem(xc_handle, domid,
   4.142 +                             (info.nr_pages + nr_pages) * PAGE_SIZE/1024) != 0)
   4.143 +    {
   4.144 +        fprintf(logfile, "set maxmem returned error %d\n", errno);
   4.145 +        return -1;
   4.146 +    }
   4.147 +
   4.148 +    err = xc_domain_memory_populate_physmap(xc_handle, domid,
   4.149 +                                            nr_pages, 0,
   4.150 +                                            address_bits, extent_start);
   4.151 +
   4.152 +    if ( err )
   4.153 +    {
   4.154 +        fprintf(stderr, "Failed to populate physmap\n");
   4.155 +        return -1;
   4.156 +    }
   4.157 +
   4.158 +    err = xc_domain_translate_gpfn_list(xc_handle, domid,
   4.159 +                                        nr_pages,
   4.160 +                                        extent_start, extent_start);
   4.161 +
   4.162 +    if ( err )
   4.163 +    {
   4.164 +        fprintf(stderr, "Failed to translate gpfn list\n");
   4.165 +        return -1;
   4.166 +    }
   4.167 +
   4.168 +    for (i = 0; i < nr_pages; i++)
   4.169 +        fprintf(stderr, "set_map result i %x result %lx\n", i, extent_start[i]);
   4.170 +
   4.171 +    return 0;
   4.172 +}
   4.173 +
   4.174 +
   4.175 +void * set_vram_mapping(unsigned long begin, unsigned long end)
   4.176 +{
   4.177 +    unsigned long * extent_start = NULL;
   4.178 +    unsigned long nr_extents;
   4.179 +    void *vram_pointer = NULL;
   4.180 +    int i;
   4.181 +
   4.182 +    /* align begin and end address */
   4.183 +    begin = begin & PAGE_MASK;
   4.184 +    end = begin + VGA_RAM_SIZE;
   4.185 +    end = (end + PAGE_SIZE -1 )& PAGE_MASK;
   4.186 +    nr_extents = (end - begin) >> PAGE_SHIFT;
   4.187 +
   4.188 +    extent_start = malloc(sizeof(unsigned long) * nr_extents );
   4.189 +    if (extent_start == NULL)
   4.190 +    {
   4.191 +        fprintf(stderr, "Failed malloc on set_vram_mapping\n");
   4.192 +        return NULL;
   4.193      }
   4.194 -    munmap(vl3tab, PAGE_SIZE);
   4.195 -    vl3tab = NULL;
   4.196 -#else
   4.197 -    if ( (vl2tab[0] = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
   4.198 -                                           PROT_READ|PROT_WRITE,
   4.199 -                                           toptab >> PAGE_SHIFT)) == NULL )
   4.200 -        goto error_out;
   4.201 -#endif
   4.202 -
   4.203 -    for ( count = 0; count < ((v_end-v_start)>>PAGE_SHIFT); count++ ) {
   4.204 -        if ( ((unsigned long)vl1e & (PAGE_SIZE-1)) == 0 )
   4.205 -        {
   4.206 -            vl2_table = vl2tab[get_vl2_table(count, v_start)];
   4.207 -            vl2e = &vl2_table[l2_table_offset(v_start + (count << PAGE_SHIFT))];
   4.208 -            l1tab = *vl2e & PAGE_MASK;
   4.209 -
   4.210 -            if(l1tab == 0)
   4.211 -                continue;
   4.212 -            if ( vl1tab != NULL )
   4.213 -                munmap(vl1tab, PAGE_SIZE);
   4.214 -
   4.215 -            if ( (vl1tab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
   4.216 -                                                PROT_READ|PROT_WRITE,
   4.217 -                                                l1tab >> PAGE_SHIFT)) == NULL )
   4.218 -            {
   4.219 -                goto error_out;
   4.220 -            }
   4.221 -            vl1e = &vl1tab[l1_table_offset(v_start + (count<<PAGE_SHIFT))];
   4.222 -            *vl2e = 0;
   4.223 -        }
   4.224 -
   4.225 -        *vl1e = 0;
   4.226 -        vl1e++;
   4.227 +
   4.228 +    memset(extent_start, 0, sizeof(unsigned long) * nr_extents);
   4.229 +
   4.230 +    for (i = 0; i < nr_extents; i++)
   4.231 +    {
   4.232 +        extent_start[i] = (begin + i * PAGE_SIZE) >> PAGE_SHIFT;
   4.233 +    }
   4.234 +
   4.235 +    set_mm_mapping(xc_handle, domid, nr_extents, 0, extent_start);
   4.236 +
   4.237 +    if ( (vram_pointer =  xc_map_foreign_batch(xc_handle, domid,
   4.238 +                                               PROT_READ|PROT_WRITE,
   4.239 +                                               extent_start,
   4.240 +                                               nr_extents)) == NULL)
   4.241 +    {
   4.242 +        fprintf(logfile,
   4.243 +          "xc_map_foreign_batch vgaram returned error %d\n", errno);
   4.244 +        return NULL;
   4.245      }
   4.246  
   4.247 -error_out:
   4.248 -    if (vl1tab)
   4.249 -        munmap(vl1tab, PAGE_SIZE);
   4.250 -    for(i = 0; i < 4; i++)
   4.251 -        if (vl2tab[i])
   4.252 -            munmap(vl2tab[i], PAGE_SIZE);
   4.253 +    memset(vram_pointer, 0, nr_extents * PAGE_SIZE);
   4.254 +
   4.255 +    free(extent_start);
   4.256 +
   4.257 +    return vram_pointer;
   4.258  }
   4.259  
   4.260 -void set_vram_mapping(unsigned long addr, unsigned long end)
   4.261 +int unset_vram_mapping(unsigned long begin, unsigned long end)
   4.262  {
   4.263 -    end = addr + VGA_RAM_SIZE;
   4.264 -    setup_mapping(xc_handle, domid, toptab,
   4.265 -                  vgapage_array, freepage_array, addr, end);
   4.266 +    unsigned long * extent_start = NULL;
   4.267 +    unsigned long nr_extents;
   4.268 +    int i;
   4.269 +
   4.270 +    /* align begin and end address */
   4.271 +
   4.272 +    end = begin + VGA_RAM_SIZE;
   4.273 +    begin = begin & PAGE_MASK;
   4.274 +    end = (end + PAGE_SIZE -1 ) & PAGE_MASK;
   4.275 +    nr_extents = (end - begin) >> PAGE_SHIFT;
   4.276 +
   4.277 +    extent_start = malloc(sizeof(unsigned long) * nr_extents );
   4.278 +
   4.279 +    if (extent_start == NULL)
   4.280 +    {
   4.281 +        fprintf(stderr, "Failed malloc on set_mm_mapping\n");
   4.282 +        return -1;
   4.283 +    }
   4.284 +
   4.285 +    memset(extent_start, 0, sizeof(unsigned long) * nr_extents);
   4.286 +
   4.287 +    for (i = 0; i < nr_extents; i++)
   4.288 +        extent_start[i] = (begin + (i * PAGE_SIZE)) >> PAGE_SHIFT;
   4.289 +
   4.290 +    unset_mm_mapping(xc_handle, domid, nr_extents, 0, extent_start);
   4.291 +
   4.292 +    free(extent_start);
   4.293 +
   4.294 +    return 0;
   4.295  }
   4.296  
   4.297 -void unset_vram_mapping(unsigned long addr, unsigned long end)
   4.298 -{
   4.299 -    end = addr + VGA_RAM_SIZE;
   4.300 -    /* FIXME Flush the shadow page */
   4.301 -    unsetup_mapping(xc_handle, domid, toptab, addr, end);
   4.302 -}
   4.303  #elif defined(__ia64__)
   4.304  void set_vram_mapping(unsigned long addr, unsigned long end) {}
   4.305  void unset_vram_mapping(unsigned long addr, unsigned long end) {}