ia64/xen-unstable

changeset 10946:7ff6020e4758

[HVM] Tidy up e820 parsing in Xen.
Signed-off-by: Steven Smith <ssmith@xensource.com>
author kfraser@localhost.localdomain
date Thu Aug 03 15:02:34 2006 +0100 (2006-08-03)
parents 164ad1411255
children cec400df7462
files xen/arch/x86/hvm/hvm.c
line diff
     1.1 --- a/xen/arch/x86/hvm/hvm.c	Thu Aug 03 13:44:05 2006 +0000
     1.2 +++ b/xen/arch/x86/hvm/hvm.c	Thu Aug 03 15:02:34 2006 +0100
     1.3 @@ -60,6 +60,8 @@ static void hvm_zap_mmio_range(
     1.4  {
     1.5      unsigned long i, val = INVALID_MFN;
     1.6  
     1.7 +    ASSERT(d == current->domain);
     1.8 +
     1.9      for ( i = 0; i < nr_pfn; i++ )
    1.10      {
    1.11          if ( pfn + i >= 0xfffff )
    1.12 @@ -69,25 +71,36 @@ static void hvm_zap_mmio_range(
    1.13      }
    1.14  }
    1.15  
    1.16 -static void hvm_map_io_shared_page(struct domain *d)
    1.17 +static void e820_zap_iommu_callback(struct domain *d,
    1.18 +                                    struct e820entry *e,
    1.19 +                                    void *ign)
    1.20 +{
    1.21 +    if ( e->type == E820_IO )
    1.22 +        hvm_zap_mmio_range(d, e->addr >> PAGE_SHIFT, e->size >> PAGE_SHIFT);
    1.23 +}
    1.24 +
    1.25 +static void e820_foreach(struct domain *d,
    1.26 +                         void (*cb)(struct domain *d,
    1.27 +                                    struct e820entry *e,
    1.28 +                                    void *data),
    1.29 +                         void *data)
    1.30  {
    1.31      int i;
    1.32      unsigned char e820_map_nr;
    1.33      struct e820entry *e820entry;
    1.34      unsigned char *p;
    1.35      unsigned long mfn;
    1.36 -    unsigned long gpfn = 0;
    1.37  
    1.38 -    local_flush_tlb_pge();
    1.39 -
    1.40 -    mfn = get_mfn_from_gpfn(E820_MAP_PAGE >> PAGE_SHIFT);
    1.41 -    if (mfn == INVALID_MFN) {
    1.42 +    mfn = gmfn_to_mfn(d, E820_MAP_PAGE >> PAGE_SHIFT);
    1.43 +    if ( mfn == INVALID_MFN )
    1.44 +    {
    1.45          printk("Can not find E820 memory map page for HVM domain.\n");
    1.46          domain_crash_synchronous();
    1.47      }
    1.48  
    1.49      p = map_domain_page(mfn);
    1.50 -    if (p == NULL) {
    1.51 +    if ( p == NULL )
    1.52 +    {
    1.53          printk("Can not map E820 memory map page for HVM domain.\n");
    1.54          domain_crash_synchronous();
    1.55      }
    1.56 @@ -96,36 +109,52 @@ static void hvm_map_io_shared_page(struc
    1.57      e820entry = (struct e820entry *)(p + E820_MAP_OFFSET);
    1.58  
    1.59      for ( i = 0; i < e820_map_nr; i++ )
    1.60 -    {
    1.61 -        if ( e820entry[i].type == E820_SHARED_PAGE )
    1.62 -            gpfn = (e820entry[i].addr >> PAGE_SHIFT);
    1.63 -        if ( e820entry[i].type == E820_IO )
    1.64 -            hvm_zap_mmio_range(
    1.65 -                d, 
    1.66 -                e820entry[i].addr >> PAGE_SHIFT,
    1.67 -                e820entry[i].size >> PAGE_SHIFT);
    1.68 -    }
    1.69 +        cb(d, e820entry + i, data);
    1.70  
    1.71 -    if ( gpfn == 0 ) {
    1.72 -        printk("Can not get io request shared page"
    1.73 -               " from E820 memory map for HVM domain.\n");
    1.74 -        unmap_domain_page(p);
    1.75 -        domain_crash_synchronous();
    1.76 +    unmap_domain_page(p);
    1.77 +}
    1.78 +
    1.79 +static void hvm_zap_iommu_pages(struct domain *d)
    1.80 +{
    1.81 +    e820_foreach(d, e820_zap_iommu_callback, NULL);
    1.82 +}
    1.83 +
    1.84 +static void e820_map_io_shared_callback(struct domain *d,
    1.85 +                                        struct e820entry *e,
    1.86 +                                        void *data)
    1.87 +{
    1.88 +    unsigned long *mfn = data;
    1.89 +    if ( e->type == E820_SHARED_PAGE )
    1.90 +    {
    1.91 +        ASSERT(*mfn == INVALID_MFN);
    1.92 +        *mfn = gmfn_to_mfn(d, e->addr >> PAGE_SHIFT);
    1.93      }
    1.94 -    unmap_domain_page(p);
    1.95 +}
    1.96  
    1.97 -    /* Initialise shared page */
    1.98 -    mfn = get_mfn_from_gpfn(gpfn);
    1.99 -    if (mfn == INVALID_MFN) {
   1.100 +void hvm_map_io_shared_page(struct vcpu *v)
   1.101 +{
   1.102 +    unsigned long mfn = INVALID_MFN;
   1.103 +    void *p;
   1.104 +    struct domain *d = v->domain;
   1.105 +
   1.106 +    if ( d->arch.hvm_domain.shared_page_va )
   1.107 +        return;
   1.108 +
   1.109 +    e820_foreach(d, e820_map_io_shared_callback, &mfn);
   1.110 +
   1.111 +    if ( mfn == INVALID_MFN )
   1.112 +    {
   1.113          printk("Can not find io request shared page for HVM domain.\n");
   1.114          domain_crash_synchronous();
   1.115      }
   1.116  
   1.117      p = map_domain_page_global(mfn);
   1.118 -    if (p == NULL) {
   1.119 +    if ( p == NULL )
   1.120 +    {
   1.121          printk("Can not map io request shared page for HVM domain.\n");
   1.122          domain_crash_synchronous();
   1.123      }
   1.124 +
   1.125      d->arch.hvm_domain.shared_page_va = (unsigned long)p;
   1.126  }
   1.127  
   1.128 @@ -143,7 +172,8 @@ void hvm_setup_platform(struct domain* d
   1.129          domain_crash_synchronous();
   1.130      }
   1.131  
   1.132 -    hvm_map_io_shared_page(d);
   1.133 +    hvm_zap_iommu_pages(d);
   1.134 +    hvm_map_io_shared_page(v);
   1.135  
   1.136      platform = &d->arch.hvm_domain;
   1.137      pic_init(&platform->vpic, pic_irq_request, &platform->interrupt_request);
   1.138 @@ -155,7 +185,8 @@ void hvm_setup_platform(struct domain* d
   1.139          hvm_vioapic_init(d);
   1.140      }
   1.141  
   1.142 -    init_timer(&platform->pl_time.periodic_tm.timer, pt_timer_fn, v, v->processor);
   1.143 +    init_timer(&platform->pl_time.periodic_tm.timer,
   1.144 +               pt_timer_fn, v, v->processor);
   1.145      pit_init(v, cpu_khz);
   1.146  }
   1.147