# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1263826098 0
# Node ID a56216b3f62dc002159af2cff001c4549fdd1b85
# Parent 618b3597603c133f8102a87d54c9ccc7098a984f
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@xxxxxxxxxxxxx>
---
extras/mini-os/arch/ia64/mm.c | 8 ++++----
extras/mini-os/arch/x86/ioremap.c | 2 +-
extras/mini-os/arch/x86/mm.c | 21 +++++++++++----------
extras/mini-os/include/ia64/arch_mm.h | 4 ++--
extras/mini-os/include/mm.h | 8 ++++----
extras/mini-os/include/x86/arch_mm.h | 6 +++---
extras/mini-os/lib/sys.c | 4 ++--
tools/libxc/xc_minios.c | 34 +++++++++++++++++++++++++++++-----
8 files changed, 56 insertions(+), 31 deletions(-)
diff -r 618b3597603c -r a56216b3f62d extras/mini-os/arch/ia64/mm.c
--- a/extras/mini-os/arch/ia64/mm.c Mon Jan 18 10:37:28 2010 +0000
+++ b/extras/mini-os/arch/ia64/mm.c Mon Jan 18 14:48:18 2010 +0000
@@ -137,17 +137,17 @@ unsigned long allocate_ondemand(unsigned
/* 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 -r 618b3597603c -r a56216b3f62d extras/mini-os/arch/x86/ioremap.c
--- a/extras/mini-os/arch/x86/ioremap.c Mon Jan 18 10:37:28 2010 +0000
+++ b/extras/mini-os/arch/x86/ioremap.c Mon Jan 18 14:48:18 2010 +0000
@@ -53,7 +53,7 @@ static void *__do_ioremap(unsigned long
}
}
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 -r 618b3597603c -r a56216b3f62d extras/mini-os/arch/x86/mm.c
--- a/extras/mini-os/arch/x86/mm.c Mon Jan 18 10:37:28 2010 +0000
+++ b/extras/mini-os/arch/x86/mm.c Mon Jan 18 14:48:18 2010 +0000
@@ -568,10 +568,9 @@ unsigned long allocate_ondemand(unsigned
*/
#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 -r 618b3597603c -r a56216b3f62d extras/mini-os/include/ia64/arch_mm.h
--- a/extras/mini-os/include/ia64/arch_mm.h Mon Jan 18 10:37:28 2010 +0000
+++ b/extras/mini-os/include/ia64/arch_mm.h Mon Jan 18 14:48:18 2010 +0000
@@ -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 -r 618b3597603c -r a56216b3f62d extras/mini-os/include/mm.h
--- a/extras/mini-os/include/mm.h Mon Jan 18 10:37:28 2010 +0000
+++ b/extras/mini-os/include/mm.h Mon Jan 18 14:48:18 2010 +0000
@@ -65,12 +65,12 @@ void arch_init_p2m(unsigned long max_pfn
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 -r 618b3597603c -r a56216b3f62d extras/mini-os/include/x86/arch_mm.h
--- a/extras/mini-os/include/x86/arch_mm.h Mon Jan 18 10:37:28 2010 +0000
+++ b/extras/mini-os/include/x86/arch_mm.h Mon Jan 18 14:48:18 2010 +0000
@@ -224,9 +224,9 @@ static __inline__ paddr_t machine_to_phy
})
#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 -r 618b3597603c -r a56216b3f62d extras/mini-os/lib/sys.c
--- a/extras/mini-os/lib/sys.c Mon Jan 18 10:37:28 2010 +0000
+++ b/extras/mini-os/lib/sys.c Mon Jan 18 14:48:18 2010 +0000
@@ -1254,10 +1254,10 @@ void *mmap(void *start, size_t length, i
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);
}
diff -r 618b3597603c -r a56216b3f62d tools/libxc/xc_minios.c
--- a/tools/libxc/xc_minios.c Mon Jan 18 10:37:28 2010 +0000
+++ b/tools/libxc/xc_minios.c Mon Jan 18 14:48:18 2010 +0000
@@ -44,8 +44,8 @@ int xc_interface_close(int xc_handle)
return 0;
}
-void *xc_map_foreign_batch(int xc_handle, uint32_t dom, int prot,
- xen_pfn_t *arr, int num)
+void *xc_map_foreign_bulk(int xc_handle, uint32_t dom, int prot,
+ const xen_pfn_t *arr, int *err, unsigned int num)
{
unsigned long pt_prot = 0;
#ifdef __ia64__
@@ -56,7 +56,31 @@ void *xc_map_foreign_batch(int xc_handle
if (prot & PROT_WRITE)
pt_prot = L1_PROT;
#endif
- return map_frames_ex(arr, num, 1, 0, 1, dom, 1, pt_prot);
+ return map_frames_ex(arr, num, 1, 0, 1, dom, err, pt_prot);
+}
+
+void *xc_map_foreign_batch(int xc_handle, uint32_t dom, int prot,
+ xen_pfn_t *arr, int num)
+{
+ unsigned long pt_prot = 0;
+ int err[num];
+ int i;
+ unsigned long addr;
+
+#ifdef __ia64__
+ /* TODO */
+#else
+ if (prot & PROT_READ)
+ pt_prot = L1_PROT_RO;
+ if (prot & PROT_WRITE)
+ pt_prot = L1_PROT;
+#endif
+ addr = (unsigned long) map_frames_ex(arr, num, 1, 0, 1, dom, err, pt_prot);
+ for (i = 0; i < num; i++) {
+ if (err[i])
+ arr[i] |= 0xF0000000;
+ }
+ return (void *) addr;
}
void *xc_map_foreign_range(int xc_handle, uint32_t dom,
@@ -73,7 +97,7 @@ void *xc_map_foreign_range(int xc_handle
pt_prot = L1_PROT;
#endif
assert(!(size % getpagesize()));
- return map_frames_ex(&mfn, size / getpagesize(), 0, 1, 1, dom, 0, pt_prot);
+ return map_frames_ex(&mfn, size / getpagesize(), 0, 1, 1, dom, NULL,
pt_prot);
}
void *xc_map_foreign_ranges(int xc_handle, uint32_t dom,
@@ -100,7 +124,7 @@ void *xc_map_foreign_ranges(int xc_handl
for (j = 0; j < chunksize / PAGE_SIZE; j++)
mfns[n++] = entries[i].mfn + j;
- ret = map_frames_ex(mfns, n, 1, 0, 1, dom, 0, pt_prot);
+ ret = map_frames_ex(mfns, n, 1, 0, 1, dom, NULL, pt_prot);
free(mfns);
return ret;
}
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|