aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIan Campbell <ian.campbell@citrix.com>2010-12-03 09:36:47 +0000
committerIan Campbell <ian.campbell@citrix.com>2010-12-03 09:36:47 +0000
commitf32797d3310d8eb1851b07249f5270f1be1ae39a (patch)
treee7ff4931b1e93f6bdf2a0771b0bc5a1cf319fba0
parent2e04f9622fa58db6a5f4a1f8242877af25429db6 (diff)
downloadxen-f32797d3310d8eb1851b07249f5270f1be1ae39a.tar.gz
xen-f32797d3310d8eb1851b07249f5270f1be1ae39a.tar.bz2
xen-f32797d3310d8eb1851b07249f5270f1be1ae39a.zip
libxc: osdep: convert xc_map_foreign_{batch,bulk}
Signed-off-by: Ian Campbell <ian.campbell@citrix.com> Signed-off-by: Ian Jackson <ian.jackson.citrix.com>
-rw-r--r--tools/libxc/Makefile1
-rw-r--r--tools/libxc/xc_foreign_memory.c35
-rw-r--r--tools/libxc/xc_linux.c35
-rw-r--r--tools/libxc/xc_minios.c13
-rw-r--r--tools/libxc/xc_misc.c9
-rw-r--r--tools/libxc/xc_netbsd.c11
-rw-r--r--tools/libxc/xc_solaris.c13
-rw-r--r--tools/libxc/xenctrlosdep.h10
8 files changed, 96 insertions, 31 deletions
diff --git a/tools/libxc/Makefile b/tools/libxc/Makefile
index 1852408497..ff23f30c58 100644
--- a/tools/libxc/Makefile
+++ b/tools/libxc/Makefile
@@ -30,6 +30,7 @@ CTRL_SRCS-y += xc_mem_event.c
CTRL_SRCS-y += xc_mem_paging.c
CTRL_SRCS-y += xc_memshr.c
CTRL_SRCS-y += xc_hcall_buf.c
+CTRL_SRCS-y += xc_foreign_memory.c
CTRL_SRCS-y += xtl_core.c
CTRL_SRCS-y += xtl_logger_stdio.c
CTRL_SRCS-$(CONFIG_X86) += xc_pagetab.c
diff --git a/tools/libxc/xc_foreign_memory.c b/tools/libxc/xc_foreign_memory.c
new file mode 100644
index 0000000000..953f63bbaf
--- /dev/null
+++ b/tools/libxc/xc_foreign_memory.c
@@ -0,0 +1,35 @@
+/******************************************************************************
+ * xc_foreign_memory.c
+ *
+ * Functions for mapping foreign domain's memory.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "xc_private.h"
+
+void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot,
+ xen_pfn_t *arr, int num )
+{
+ return xch->ops->u.privcmd.map_foreign_batch(xch, xch->ops_handle,
+ dom, prot, arr, num);
+}
+
+void *xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot,
+ const xen_pfn_t *arr, int *err, unsigned int num)
+{
+ return xch->ops->u.privcmd.map_foreign_bulk(xch, xch->ops_handle,
+ dom, prot, arr, err, num);
+}
diff --git a/tools/libxc/xc_linux.c b/tools/libxc/xc_linux.c
index a0539cd0b5..76d4791845 100644
--- a/tools/libxc/xc_linux.c
+++ b/tools/libxc/xc_linux.c
@@ -81,7 +81,7 @@ static int linux_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h, privcmd
return ioctl(fd, IOCTL_PRIVCMD_HYPERCALL, hypercall);
}
-static int xc_map_foreign_batch_single(xc_interface *xch, uint32_t dom,
+static int xc_map_foreign_batch_single(int fd, uint32_t dom,
xen_pfn_t *mfn, unsigned long addr)
{
privcmd_mmapbatch_t ioctlx;
@@ -96,21 +96,23 @@ static int xc_map_foreign_batch_single(xc_interface *xch, uint32_t dom,
{
*mfn ^= XEN_DOMCTL_PFINFO_PAGEDTAB;
usleep(100);
- rc = ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx);
+ rc = ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx);
}
while ( (rc < 0) && (errno == ENOENT) );
return rc;
}
-void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot,
- xen_pfn_t *arr, int num)
+static void *linux_privcmd_map_foreign_batch(xc_interface *xch, xc_osdep_handle h,
+ uint32_t dom, int prot,
+ xen_pfn_t *arr, int num)
{
+ int fd = (int)h;
privcmd_mmapbatch_t ioctlx;
void *addr;
int rc;
- addr = mmap(NULL, num << PAGE_SHIFT, prot, MAP_SHARED, xch->fd, 0);
+ addr = mmap(NULL, num << PAGE_SHIFT, prot, MAP_SHARED, fd, 0);
if ( addr == MAP_FAILED )
{
PERROR("xc_map_foreign_batch: mmap failed");
@@ -122,7 +124,7 @@ void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot,
ioctlx.addr = (unsigned long)addr;
ioctlx.arr = arr;
- rc = ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx);
+ rc = ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx);
if ( (rc < 0) && (errno == ENOENT) )
{
int i;
@@ -133,7 +135,7 @@ void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot,
XEN_DOMCTL_PFINFO_PAGEDTAB )
{
unsigned long paged_addr = (unsigned long)addr + (i << PAGE_SHIFT);
- rc = xc_map_foreign_batch_single(xch, dom, &arr[i],
+ rc = xc_map_foreign_batch_single(fd, dom, &arr[i],
paged_addr);
if ( rc < 0 )
goto out;
@@ -154,16 +156,18 @@ void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot,
return addr;
}
-void *xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot,
- const xen_pfn_t *arr, int *err, unsigned int num)
+static void *linux_privcmd_map_foreign_bulk(xc_interface *xch, xc_osdep_handle h,
+ uint32_t dom, int prot,
+ const xen_pfn_t *arr, int *err, unsigned int num)
{
+ int fd = (int)h;
privcmd_mmapbatch_v2_t ioctlx;
void *addr;
unsigned int i;
int rc;
addr = mmap(NULL, (unsigned long)num << PAGE_SHIFT, prot, MAP_SHARED,
- xch->fd, 0);
+ fd, 0);
if ( addr == MAP_FAILED )
{
PERROR("xc_map_foreign_batch: mmap failed");
@@ -176,7 +180,7 @@ void *xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot,
ioctlx.arr = arr;
ioctlx.err = err;
- rc = ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH_V2, &ioctlx);
+ rc = ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH_V2, &ioctlx);
if ( rc < 0 && errno == ENOENT )
{
@@ -192,7 +196,7 @@ void *xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot,
ioctlx.err = err + i;
do {
usleep(100);
- rc = ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH_V2, &ioctlx);
+ rc = ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH_V2, &ioctlx);
} while ( rc < 0 && err[i] == -ENOENT );
}
}
@@ -216,7 +220,7 @@ void *xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot,
ioctlx.addr = (unsigned long)addr;
ioctlx.arr = pfn;
- rc = ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx);
+ rc = ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx);
rc = rc < 0 ? -errno : 0;
@@ -236,7 +240,7 @@ void *xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot,
err[i] = rc ?: -EINVAL;
continue;
}
- rc = xc_map_foreign_batch_single(xch, dom, pfn + i,
+ rc = xc_map_foreign_batch_single(fd, dom, pfn + i,
(unsigned long)addr + ((unsigned long)i<<PAGE_SHIFT));
if ( rc < 0 )
{
@@ -328,6 +332,9 @@ static struct xc_osdep_ops linux_privcmd_ops = {
.u.privcmd = {
.hypercall = &linux_privcmd_hypercall,
+
+ .map_foreign_batch = &linux_privcmd_map_foreign_batch,
+ .map_foreign_bulk = &linux_privcmd_map_foreign_bulk,
},
};
diff --git a/tools/libxc/xc_minios.c b/tools/libxc/xc_minios.c
index 076605a743..624889d193 100644
--- a/tools/libxc/xc_minios.c
+++ b/tools/libxc/xc_minios.c
@@ -93,8 +93,9 @@ static int minios_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h, privcm
return call.result;
}
-void *xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot,
- const xen_pfn_t *arr, int *err, unsigned int num)
+static void *minios_privcmd_map_foreign_bulk(xc_interface *xch, xc_osdep_handle h,
+ uint32_t dom, int prot,
+ const xen_pfn_t *arr, int *err, unsigned int num)
{
unsigned long pt_prot = 0;
#ifdef __ia64__
@@ -108,8 +109,9 @@ void *xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot,
return map_frames_ex(arr, num, 1, 0, 1, dom, err, pt_prot);
}
-void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot,
- xen_pfn_t *arr, int num)
+static void *minios_privcmd_map_foreign_batch(xc_interface *xch, xc_osdep_handle h,
+ uint32_t dom, int prot,
+ xen_pfn_t *arr, int num)
{
unsigned long pt_prot = 0;
int err[num];
@@ -185,6 +187,9 @@ static struct xc_osdep_ops minios_privcmd_ops = {
.u.privcmd = {
.hypercall = &minios_privcmd_hypercall,
+
+ .map_foreign_batch = &minios_privcmd_map_foreign_batch,
+ .map_foreign_bulk = &minios_privcmd_map_foreign_bulk,
},
};
diff --git a/tools/libxc/xc_misc.c b/tools/libxc/xc_misc.c
index 944646e28c..23398f773b 100644
--- a/tools/libxc/xc_misc.c
+++ b/tools/libxc/xc_misc.c
@@ -513,12 +513,9 @@ int xc_hvm_set_mem_type(
/* stub for all not yet converted OSes */
-void *
-#ifdef __GNUC__
-__attribute__((__weak__))
-#endif
-xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot,
- const xen_pfn_t *arr, int *err, unsigned int num)
+void *xc_map_foreign_bulk_compat(xc_interface *xch, xc_osdep_handle h,
+ uint32_t dom, int prot,
+ const xen_pfn_t *arr, int *err, unsigned int num)
{
xen_pfn_t *pfn;
unsigned int i;
diff --git a/tools/libxc/xc_netbsd.c b/tools/libxc/xc_netbsd.c
index 3c3b90d178..671ae2c3a6 100644
--- a/tools/libxc/xc_netbsd.c
+++ b/tools/libxc/xc_netbsd.c
@@ -79,9 +79,11 @@ static int netbsd_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h, privcm
return hypercall->retval;
}
-void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot,
- xen_pfn_t *arr, int num)
+static void *netbsd_privcmd_map_foreign_batch(xc_interface *xch, xc_osdep_handle h,
+ uint32_t dom, int prot,
+ xen_pfn_t *arr, int num)
{
+ int fd = (int)h;
privcmd_mmapbatch_t ioctlx;
void *addr;
addr = mmap(NULL, num*PAGE_SIZE, prot, MAP_ANON | MAP_SHARED, -1, 0);
@@ -94,7 +96,7 @@ void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot,
ioctlx.dom=dom;
ioctlx.addr=(unsigned long)addr;
ioctlx.arr=arr;
- if ( ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx) < 0 )
+ if ( ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx) < 0 )
{
int saved_errno = errno;
PERROR("xc_map_foreign_batch: ioctl failed");
@@ -178,6 +180,9 @@ static struct xc_osdep_ops netbsd_privcmd_ops = {
.u.privcmd = {
.hypercall = &netbsd_privcmd_hypercall;
+
+ .map_foreign_batch = &netbsd_privcmd_map_foreign_batch,
+ .map_foreign_bulk = &xc_map_foreign_bulk_compat,
},
};
diff --git a/tools/libxc/xc_solaris.c b/tools/libxc/xc_solaris.c
index cdcc2222c4..8152868e7c 100644
--- a/tools/libxc/xc_solaris.c
+++ b/tools/libxc/xc_solaris.c
@@ -74,12 +74,14 @@ static int solaris_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h, privc
return ioctl(fd, IOCTL_PRIVCMD_HYPERCALL, hypercall);
}
-void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot,
- xen_pfn_t *arr, int num)
+static void *solaris_privcmd_map_foreign_batch(xc_interface *xch, xc_osdep_handle h,
+ uint32_t dom, int prot,
+ xen_pfn_t *arr, int num)
{
+ int fd = (int)h;
privcmd_mmapbatch_t ioctlx;
void *addr;
- addr = mmap(NULL, num*PAGE_SIZE, prot, MAP_SHARED, xch->fd, 0);
+ addr = mmap(NULL, num*PAGE_SIZE, prot, MAP_SHARED, fd, 0);
if ( addr == MAP_FAILED )
return NULL;
@@ -87,7 +89,7 @@ void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot,
ioctlx.dom=dom;
ioctlx.addr=(unsigned long)addr;
ioctlx.arr=arr;
- if ( ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx) < 0 )
+ if ( ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx) < 0 )
{
int saved_errno = errno;
PERROR("XXXXXXXX");
@@ -168,6 +170,9 @@ static struct xc_osdep_ops solaris_privcmd_ops = {
.u.privcmd = {
.hypercall = &solaris_privcmd_hypercall;
+
+ .map_foreign_batch = &solaris_privcmd_map_foreign_batch,
+ .map_foreign_bulk = &xc_map_foreign_bulk_compat,
},
};
diff --git a/tools/libxc/xenctrlosdep.h b/tools/libxc/xenctrlosdep.h
index 59928fb7b7..204b9e87e9 100644
--- a/tools/libxc/xenctrlosdep.h
+++ b/tools/libxc/xenctrlosdep.h
@@ -63,6 +63,11 @@ struct xc_osdep_ops
union {
struct {
int (*hypercall)(xc_interface *xch, xc_osdep_handle h, privcmd_hypercall_t *hypercall);
+
+ void *(*map_foreign_batch)(xc_interface *xch, xc_osdep_handle h, uint32_t dom, int prot,
+ xen_pfn_t *arr, int num);
+ void *(*map_foreign_bulk)(xc_interface *xch, xc_osdep_handle h, uint32_t dom, int prot,
+ const xen_pfn_t *arr, int *err, unsigned int num);
} privcmd;
} u;
};
@@ -83,6 +88,11 @@ typedef struct xc_osdep_info xc_osdep_info_t;
/* All backends, including the builtin backend, must supply this structure. */
extern xc_osdep_info_t xc_osdep_info;
+/* Stub for not yet converted OSes */
+void *xc_map_foreign_bulk_compat(xc_interface *xch, xc_osdep_handle h,
+ uint32_t dom, int prot,
+ const xen_pfn_t *arr, int *err, unsigned int num);
+
#endif
/*