debuggers.hg

changeset 20866:a56216b3f62d

minios: implement xc_map_foreign_bulk

In order to do so it modifies map_frames_ex and do_map_frames to take
an int *err as parameter and return any error that way.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Jan 18 14:48:18 2010 +0000 (2010-01-18)
parents 618b3597603c
children d7e8b6a66a3d
files extras/mini-os/arch/ia64/mm.c extras/mini-os/arch/x86/ioremap.c extras/mini-os/arch/x86/mm.c extras/mini-os/include/ia64/arch_mm.h extras/mini-os/include/mm.h extras/mini-os/include/x86/arch_mm.h extras/mini-os/lib/sys.c tools/libxc/xc_minios.c
line diff
     1.1 --- a/extras/mini-os/arch/ia64/mm.c	Mon Jan 18 10:37:28 2010 +0000
     1.2 +++ b/extras/mini-os/arch/ia64/mm.c	Mon Jan 18 14:48:18 2010 +0000
     1.3 @@ -137,17 +137,17 @@ unsigned long allocate_ondemand(unsigned
     1.4  
     1.5  /* Helper function used in gnttab.c. */
     1.6  void do_map_frames(unsigned long addr,
     1.7 -        unsigned long *f, unsigned long n, unsigned long stride,
     1.8 -	unsigned long increment, domid_t id, int may_fail, unsigned long prot)
     1.9 +    const unsigned long *f, unsigned long n, unsigned long stride,
    1.10 +	unsigned long increment, domid_t id, int *err, unsigned long prot)
    1.11  {
    1.12  	/* TODO */
    1.13  	ASSERT(0);
    1.14  }
    1.15  
    1.16  void*
    1.17 -map_frames_ex(unsigned long* frames, unsigned long n, unsigned long stride,
    1.18 +map_frames_ex(const unsigned long* frames, unsigned long n, unsigned long stride,
    1.19  	unsigned long increment, unsigned long alignment, domid_t id,
    1.20 -	int may_fail, unsigned long prot)
    1.21 +	int *err, unsigned long prot)
    1.22  {
    1.23          /* TODO: incomplete! */
    1.24          ASSERT(n == 1 || (stride == 0 && increment == 1));
     2.1 --- a/extras/mini-os/arch/x86/ioremap.c	Mon Jan 18 10:37:28 2010 +0000
     2.2 +++ b/extras/mini-os/arch/x86/ioremap.c	Mon Jan 18 14:48:18 2010 +0000
     2.3 @@ -53,7 +53,7 @@ static void *__do_ioremap(unsigned long 
     2.4          }
     2.5      }   
     2.6      va = (unsigned long)map_frames_ex(&mfns, num_pages, 0, 1, 1,
     2.7 -                                      DOMID_IO, 0, prot);
     2.8 +                                      DOMID_IO, NULL, prot);
     2.9      return (void *)(va + offset);
    2.10      
    2.11  mfn_invalid:
     3.1 --- a/extras/mini-os/arch/x86/mm.c	Mon Jan 18 10:37:28 2010 +0000
     3.2 +++ b/extras/mini-os/arch/x86/mm.c	Mon Jan 18 14:48:18 2010 +0000
     3.3 @@ -568,10 +568,9 @@ unsigned long allocate_ondemand(unsigned
     3.4   */
     3.5  #define MAP_BATCH ((STACK_SIZE / 2) / sizeof(mmu_update_t))
     3.6  void do_map_frames(unsigned long va,
     3.7 -                   unsigned long *mfns, unsigned long n, 
     3.8 +                   const unsigned long *mfns, unsigned long n, 
     3.9                     unsigned long stride, unsigned long incr, 
    3.10 -                   domid_t id, int may_fail,
    3.11 -                   unsigned long prot)
    3.12 +                   domid_t id, int *err, unsigned long prot)
    3.13  {
    3.14      pgentry_t *pgt = NULL;
    3.15      unsigned long done = 0;
    3.16 @@ -585,12 +584,14 @@ void do_map_frames(unsigned long va,
    3.17      }
    3.18      DEBUG("va=%p n=0x%lx, mfns[0]=0x%lx stride=0x%lx incr=0x%lx prot=0x%lx\n",
    3.19            va, n, mfns[0], stride, incr, prot);
    3.20 - 
    3.21 +
    3.22 +    if ( err )
    3.23 +        memset(err, 0x00, n * sizeof(int));
    3.24      while ( done < n )
    3.25      {
    3.26          unsigned long todo;
    3.27  
    3.28 -        if ( may_fail )
    3.29 +        if ( err )
    3.30              todo = 1;
    3.31          else
    3.32              todo = n - done;
    3.33 @@ -615,8 +616,8 @@ void do_map_frames(unsigned long va,
    3.34              rc = HYPERVISOR_mmu_update(mmu_updates, todo, NULL, id);
    3.35              if ( rc < 0 )
    3.36              {
    3.37 -                if (may_fail)
    3.38 -                    mfns[done * stride] |= 0xF0000000;
    3.39 +                if (err)
    3.40 +                    err[done * stride] = rc;
    3.41                  else {
    3.42                      printk("Map %ld (%lx, ...) at %p failed: %d.\n",
    3.43                             todo, mfns[done * stride] + done * incr, va, rc);
    3.44 @@ -632,17 +633,17 @@ void do_map_frames(unsigned long va,
    3.45   * Map an array of MFNs contiguous into virtual address space. Virtual
    3.46   * addresses are allocated from the on demand area.
    3.47   */
    3.48 -void *map_frames_ex(unsigned long *mfns, unsigned long n, 
    3.49 +void *map_frames_ex(const unsigned long *mfns, unsigned long n, 
    3.50                      unsigned long stride, unsigned long incr,
    3.51                      unsigned long alignment,
    3.52 -                    domid_t id, int may_fail, unsigned long prot)
    3.53 +                    domid_t id, int *err, unsigned long prot)
    3.54  {
    3.55      unsigned long va = allocate_ondemand(n, alignment);
    3.56  
    3.57      if ( !va )
    3.58          return NULL;
    3.59  
    3.60 -    do_map_frames(va, mfns, n, stride, incr, id, may_fail, prot);
    3.61 +    do_map_frames(va, mfns, n, stride, incr, id, err, prot);
    3.62  
    3.63      return (void *)va;
    3.64  }
     4.1 --- a/extras/mini-os/include/ia64/arch_mm.h	Mon Jan 18 10:37:28 2010 +0000
     4.2 +++ b/extras/mini-os/include/ia64/arch_mm.h	Mon Jan 18 14:48:18 2010 +0000
     4.3 @@ -35,9 +35,9 @@
     4.4  #define virt_to_mfn(x)	virt_to_pfn(x)
     4.5  #define virtual_to_mfn(x)      (ia64_tpa((uint64_t)(x)) >> PAGE_SHIFT)
     4.6  
     4.7 -#define map_frames(f, n) map_frames_ex(f, n, 1, 0, 1, DOMID_SELF, 0, 0)
     4.8 +#define map_frames(f, n) map_frames_ex(f, n, 1, 0, 1, DOMID_SELF, NULL, 0)
     4.9  /* TODO */
    4.10 -#define map_zero(n, a) map_frames_ex(NULL, n, 0, 0, a, DOMID_SELF, 0, 0)
    4.11 +#define map_zero(n, a) map_frames_ex(NULL, n, 0, 0, a, DOMID_SELF, NULL, 0)
    4.12  #define do_map_zero(start, n) ASSERT(n == 0)
    4.13  
    4.14  #endif /* __ARCH_MM_H__ */
     5.1 --- a/extras/mini-os/include/mm.h	Mon Jan 18 10:37:28 2010 +0000
     5.2 +++ b/extras/mini-os/include/mm.h	Mon Jan 18 14:48:18 2010 +0000
     5.3 @@ -65,12 +65,12 @@ void arch_init_p2m(unsigned long max_pfn
     5.4  
     5.5  unsigned long allocate_ondemand(unsigned long n, unsigned long alignment);
     5.6  /* map f[i*stride]+i*increment for i in 0..n-1, aligned on alignment pages */
     5.7 -void *map_frames_ex(unsigned long *f, unsigned long n, unsigned long stride,
     5.8 +void *map_frames_ex(const unsigned long *f, unsigned long n, unsigned long stride,
     5.9  	unsigned long increment, unsigned long alignment, domid_t id,
    5.10 -	int may_fail, unsigned long prot);
    5.11 +	int *err, unsigned long prot);
    5.12  void do_map_frames(unsigned long addr,
    5.13 -        unsigned long *f, unsigned long n, unsigned long stride,
    5.14 -	unsigned long increment, domid_t id, int may_fail, unsigned long prot);
    5.15 +        const unsigned long *f, unsigned long n, unsigned long stride,
    5.16 +	unsigned long increment, domid_t id, int *err, unsigned long prot);
    5.17  int unmap_frames(unsigned long va, unsigned long num_frames);
    5.18  unsigned long alloc_contig_pages(int order, unsigned int addr_bits);
    5.19  #ifdef HAVE_LIBC
     6.1 --- a/extras/mini-os/include/x86/arch_mm.h	Mon Jan 18 10:37:28 2010 +0000
     6.2 +++ b/extras/mini-os/include/x86/arch_mm.h	Mon Jan 18 14:48:18 2010 +0000
     6.3 @@ -224,9 +224,9 @@ static __inline__ paddr_t machine_to_phy
     6.4  })
     6.5  #define virtual_to_mfn(_virt)	   pte_to_mfn(virtual_to_pte(_virt))
     6.6  
     6.7 -#define map_frames(f, n) map_frames_ex(f, n, 1, 0, 1, DOMID_SELF, 0, L1_PROT)
     6.8 -#define map_zero(n, a) map_frames_ex(&mfn_zero, n, 0, 0, a, DOMID_SELF, 0, L1_PROT_RO)
     6.9 -#define do_map_zero(start, n) do_map_frames(start, &mfn_zero, n, 0, 0, DOMID_SELF, 0, L1_PROT_RO)
    6.10 +#define map_frames(f, n) map_frames_ex(f, n, 1, 0, 1, DOMID_SELF, NULL, L1_PROT)
    6.11 +#define map_zero(n, a) map_frames_ex(&mfn_zero, n, 0, 0, a, DOMID_SELF, NULL, L1_PROT_RO)
    6.12 +#define do_map_zero(start, n) do_map_frames(start, &mfn_zero, n, 0, 0, DOMID_SELF, NULL, L1_PROT_RO)
    6.13  
    6.14  pgentry_t *need_pgt(unsigned long addr);
    6.15  int mfn_is_ram(unsigned long mfn);
     7.1 --- a/extras/mini-os/lib/sys.c	Mon Jan 18 10:37:28 2010 +0000
     7.2 +++ b/extras/mini-os/lib/sys.c	Mon Jan 18 14:48:18 2010 +0000
     7.3 @@ -1254,10 +1254,10 @@ void *mmap(void *start, size_t length, i
     7.4          return map_zero(n, 1);
     7.5      else if (files[fd].type == FTYPE_XC) {
     7.6          unsigned long zero = 0;
     7.7 -        return map_frames_ex(&zero, n, 0, 0, 1, DOMID_SELF, 0, 0);
     7.8 +        return map_frames_ex(&zero, n, 0, 0, 1, DOMID_SELF, NULL, 0);
     7.9      } else if (files[fd].type == FTYPE_MEM) {
    7.10          unsigned long first_mfn = offset >> PAGE_SHIFT;
    7.11 -        return map_frames_ex(&first_mfn, n, 0, 1, 1, DOMID_IO, 0, _PAGE_PRESENT|_PAGE_RW);
    7.12 +        return map_frames_ex(&first_mfn, n, 0, 1, 1, DOMID_IO, NULL, _PAGE_PRESENT|_PAGE_RW);
    7.13      } else ASSERT(0);
    7.14  }
    7.15  
     8.1 --- a/tools/libxc/xc_minios.c	Mon Jan 18 10:37:28 2010 +0000
     8.2 +++ b/tools/libxc/xc_minios.c	Mon Jan 18 14:48:18 2010 +0000
     8.3 @@ -44,8 +44,8 @@ int xc_interface_close(int xc_handle)
     8.4      return 0;
     8.5  }
     8.6  
     8.7 -void *xc_map_foreign_batch(int xc_handle, uint32_t dom, int prot,
     8.8 -                           xen_pfn_t *arr, int num)
     8.9 +void *xc_map_foreign_bulk(int xc_handle, uint32_t dom, int prot,
    8.10 +                          const xen_pfn_t *arr, int *err, unsigned int num)
    8.11  {
    8.12      unsigned long pt_prot = 0;
    8.13  #ifdef __ia64__
    8.14 @@ -56,7 +56,31 @@ void *xc_map_foreign_batch(int xc_handle
    8.15      if (prot & PROT_WRITE)
    8.16  	pt_prot = L1_PROT;
    8.17  #endif
    8.18 -    return map_frames_ex(arr, num, 1, 0, 1, dom, 1, pt_prot);
    8.19 +    return map_frames_ex(arr, num, 1, 0, 1, dom, err, pt_prot);    
    8.20 +}
    8.21 +
    8.22 +void *xc_map_foreign_batch(int xc_handle, uint32_t dom, int prot,
    8.23 +                           xen_pfn_t *arr, int num)
    8.24 +{
    8.25 +    unsigned long pt_prot = 0;
    8.26 +    int err[num];
    8.27 +    int i;
    8.28 +    unsigned long addr;
    8.29 +
    8.30 +#ifdef __ia64__
    8.31 +    /* TODO */
    8.32 +#else
    8.33 +    if (prot & PROT_READ)
    8.34 +	pt_prot = L1_PROT_RO;
    8.35 +    if (prot & PROT_WRITE)
    8.36 +	pt_prot = L1_PROT;
    8.37 +#endif
    8.38 +    addr = (unsigned long) map_frames_ex(arr, num, 1, 0, 1, dom, err, pt_prot);
    8.39 +    for (i = 0; i < num; i++) {
    8.40 +        if (err[i])
    8.41 +            arr[i] |= 0xF0000000;
    8.42 +    }
    8.43 +    return (void *) addr;
    8.44  }
    8.45  
    8.46  void *xc_map_foreign_range(int xc_handle, uint32_t dom,
    8.47 @@ -73,7 +97,7 @@ void *xc_map_foreign_range(int xc_handle
    8.48  	pt_prot = L1_PROT;
    8.49  #endif
    8.50      assert(!(size % getpagesize()));
    8.51 -    return map_frames_ex(&mfn, size / getpagesize(), 0, 1, 1, dom, 0, pt_prot);
    8.52 +    return map_frames_ex(&mfn, size / getpagesize(), 0, 1, 1, dom, NULL, pt_prot);
    8.53  }
    8.54  
    8.55  void *xc_map_foreign_ranges(int xc_handle, uint32_t dom,
    8.56 @@ -100,7 +124,7 @@ void *xc_map_foreign_ranges(int xc_handl
    8.57          for (j = 0; j < chunksize / PAGE_SIZE; j++)
    8.58              mfns[n++] = entries[i].mfn + j;
    8.59  
    8.60 -    ret = map_frames_ex(mfns, n, 1, 0, 1, dom, 0, pt_prot);
    8.61 +    ret = map_frames_ex(mfns, n, 1, 0, 1, dom, NULL, pt_prot);
    8.62      free(mfns);
    8.63      return ret;
    8.64  }