From: Keir Fraser Date: Mon, 18 Jan 2010 14:48:18 +0000 (+0000) Subject: minios: implement xc_map_foreign_bulk X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=42b9faaecdf81d085b5bbe776b9b9896f53b4555;p=people%2Fliuw%2Flibxenctrl-split%2Fmini-os.git 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 --- diff --git a/arch/ia64/mm.c b/arch/ia64/mm.c index b171f75..9040517 100644 --- a/arch/ia64/mm.c +++ b/arch/ia64/mm.c @@ -137,17 +137,17 @@ unsigned long allocate_ondemand(unsigned long n, unsigned long alignment) /* Helper function used in gnttab.c. */ void do_map_frames(unsigned long addr, - unsigned long *f, unsigned long n, unsigned long stride, - unsigned long increment, domid_t id, int may_fail, unsigned long prot) + const unsigned long *f, unsigned long n, unsigned long stride, + unsigned long increment, domid_t id, int *err, unsigned long prot) { /* TODO */ ASSERT(0); } void* -map_frames_ex(unsigned long* frames, unsigned long n, unsigned long stride, +map_frames_ex(const unsigned long* frames, unsigned long n, unsigned long stride, unsigned long increment, unsigned long alignment, domid_t id, - int may_fail, unsigned long prot) + int *err, unsigned long prot) { /* TODO: incomplete! */ ASSERT(n == 1 || (stride == 0 && increment == 1)); diff --git a/arch/x86/ioremap.c b/arch/x86/ioremap.c index f55d9e0..c7f8186 100644 --- a/arch/x86/ioremap.c +++ b/arch/x86/ioremap.c @@ -53,7 +53,7 @@ static void *__do_ioremap(unsigned long phys_addr, unsigned long size, } } va = (unsigned long)map_frames_ex(&mfns, num_pages, 0, 1, 1, - DOMID_IO, 0, prot); + DOMID_IO, NULL, prot); return (void *)(va + offset); mfn_invalid: diff --git a/arch/x86/mm.c b/arch/x86/mm.c index 8d688fc..cb7f037 100644 --- a/arch/x86/mm.c +++ b/arch/x86/mm.c @@ -568,10 +568,9 @@ unsigned long allocate_ondemand(unsigned long n, unsigned long alignment) */ #define MAP_BATCH ((STACK_SIZE / 2) / sizeof(mmu_update_t)) void do_map_frames(unsigned long va, - unsigned long *mfns, unsigned long n, + const unsigned long *mfns, unsigned long n, unsigned long stride, unsigned long incr, - domid_t id, int may_fail, - unsigned long prot) + domid_t id, int *err, unsigned long prot) { pgentry_t *pgt = NULL; unsigned long done = 0; @@ -585,12 +584,14 @@ void do_map_frames(unsigned long va, } DEBUG("va=%p n=0x%lx, mfns[0]=0x%lx stride=0x%lx incr=0x%lx prot=0x%lx\n", va, n, mfns[0], stride, incr, prot); - + + if ( err ) + memset(err, 0x00, n * sizeof(int)); while ( done < n ) { unsigned long todo; - if ( may_fail ) + if ( err ) todo = 1; else todo = n - done; @@ -615,8 +616,8 @@ void do_map_frames(unsigned long va, rc = HYPERVISOR_mmu_update(mmu_updates, todo, NULL, id); if ( rc < 0 ) { - if (may_fail) - mfns[done * stride] |= 0xF0000000; + if (err) + err[done * stride] = rc; else { printk("Map %ld (%lx, ...) at %p failed: %d.\n", todo, mfns[done * stride] + done * incr, va, rc); @@ -632,17 +633,17 @@ void do_map_frames(unsigned long va, * Map an array of MFNs contiguous into virtual address space. Virtual * addresses are allocated from the on demand area. */ -void *map_frames_ex(unsigned long *mfns, unsigned long n, +void *map_frames_ex(const unsigned long *mfns, unsigned long n, unsigned long stride, unsigned long incr, unsigned long alignment, - domid_t id, int may_fail, unsigned long prot) + domid_t id, int *err, unsigned long prot) { unsigned long va = allocate_ondemand(n, alignment); if ( !va ) return NULL; - do_map_frames(va, mfns, n, stride, incr, id, may_fail, prot); + do_map_frames(va, mfns, n, stride, incr, id, err, prot); return (void *)va; } diff --git a/include/ia64/arch_mm.h b/include/ia64/arch_mm.h index 5a1a1a9..8889164 100644 --- a/include/ia64/arch_mm.h +++ b/include/ia64/arch_mm.h @@ -35,9 +35,9 @@ #define virt_to_mfn(x) virt_to_pfn(x) #define virtual_to_mfn(x) (ia64_tpa((uint64_t)(x)) >> PAGE_SHIFT) -#define map_frames(f, n) map_frames_ex(f, n, 1, 0, 1, DOMID_SELF, 0, 0) +#define map_frames(f, n) map_frames_ex(f, n, 1, 0, 1, DOMID_SELF, NULL, 0) /* TODO */ -#define map_zero(n, a) map_frames_ex(NULL, n, 0, 0, a, DOMID_SELF, 0, 0) +#define map_zero(n, a) map_frames_ex(NULL, n, 0, 0, a, DOMID_SELF, NULL, 0) #define do_map_zero(start, n) ASSERT(n == 0) #endif /* __ARCH_MM_H__ */ diff --git a/include/mm.h b/include/mm.h index 18622d8..2fd43f3 100644 --- a/include/mm.h +++ b/include/mm.h @@ -65,12 +65,12 @@ void arch_init_p2m(unsigned long max_pfn_p); unsigned long allocate_ondemand(unsigned long n, unsigned long alignment); /* map f[i*stride]+i*increment for i in 0..n-1, aligned on alignment pages */ -void *map_frames_ex(unsigned long *f, unsigned long n, unsigned long stride, +void *map_frames_ex(const unsigned long *f, unsigned long n, unsigned long stride, unsigned long increment, unsigned long alignment, domid_t id, - int may_fail, unsigned long prot); + int *err, unsigned long prot); void do_map_frames(unsigned long addr, - unsigned long *f, unsigned long n, unsigned long stride, - unsigned long increment, domid_t id, int may_fail, unsigned long prot); + const unsigned long *f, unsigned long n, unsigned long stride, + unsigned long increment, domid_t id, int *err, unsigned long prot); int unmap_frames(unsigned long va, unsigned long num_frames); unsigned long alloc_contig_pages(int order, unsigned int addr_bits); #ifdef HAVE_LIBC diff --git a/include/x86/arch_mm.h b/include/x86/arch_mm.h index 786064b..a95632a 100644 --- a/include/x86/arch_mm.h +++ b/include/x86/arch_mm.h @@ -224,9 +224,9 @@ static __inline__ paddr_t machine_to_phys(maddr_t machine) }) #define virtual_to_mfn(_virt) pte_to_mfn(virtual_to_pte(_virt)) -#define map_frames(f, n) map_frames_ex(f, n, 1, 0, 1, DOMID_SELF, 0, L1_PROT) -#define map_zero(n, a) map_frames_ex(&mfn_zero, n, 0, 0, a, DOMID_SELF, 0, L1_PROT_RO) -#define do_map_zero(start, n) do_map_frames(start, &mfn_zero, n, 0, 0, DOMID_SELF, 0, L1_PROT_RO) +#define map_frames(f, n) map_frames_ex(f, n, 1, 0, 1, DOMID_SELF, NULL, L1_PROT) +#define map_zero(n, a) map_frames_ex(&mfn_zero, n, 0, 0, a, DOMID_SELF, NULL, L1_PROT_RO) +#define do_map_zero(start, n) do_map_frames(start, &mfn_zero, n, 0, 0, DOMID_SELF, NULL, L1_PROT_RO) pgentry_t *need_pgt(unsigned long addr); int mfn_is_ram(unsigned long mfn); diff --git a/lib/sys.c b/lib/sys.c index 6e12be0..9ce9954 100644 --- a/lib/sys.c +++ b/lib/sys.c @@ -1254,10 +1254,10 @@ void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset return map_zero(n, 1); else if (files[fd].type == FTYPE_XC) { unsigned long zero = 0; - return map_frames_ex(&zero, n, 0, 0, 1, DOMID_SELF, 0, 0); + return map_frames_ex(&zero, n, 0, 0, 1, DOMID_SELF, NULL, 0); } else if (files[fd].type == FTYPE_MEM) { unsigned long first_mfn = offset >> PAGE_SHIFT; - return map_frames_ex(&first_mfn, n, 0, 1, 1, DOMID_IO, 0, _PAGE_PRESENT|_PAGE_RW); + return map_frames_ex(&first_mfn, n, 0, 1, 1, DOMID_IO, NULL, _PAGE_PRESENT|_PAGE_RW); } else ASSERT(0); }