[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH v15 04/11] tools: provide interface for generic resource access



Xen added a new platform_op hypercall for generic MSR access, and this
is the the tool side change to wrapper the hypercall into xc APIs.

Signed-off-by: Dongxiao Xu <dongxiao.xu@xxxxxxxxx>
Signed-off-by: Chao Peng <chao.p.peng@xxxxxxxxxxxxxxx>
Acked-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
---
 tools/libxc/Makefile      |    1 +
 tools/libxc/xc_private.h  |   21 +++++++++++
 tools/libxc/xc_resource.c |   92 +++++++++++++++++++++++++++++++++++++++++++++
 tools/libxc/xenctrl.h     |   12 ++++++
 4 files changed, 126 insertions(+)
 create mode 100644 tools/libxc/xc_resource.c

diff --git a/tools/libxc/Makefile b/tools/libxc/Makefile
index 3b04027..dde6109 100644
--- a/tools/libxc/Makefile
+++ b/tools/libxc/Makefile
@@ -34,6 +34,7 @@ CTRL_SRCS-y       += xc_foreign_memory.c
 CTRL_SRCS-y       += xc_kexec.c
 CTRL_SRCS-y       += xtl_core.c
 CTRL_SRCS-y       += xtl_logger_stdio.c
+CTRL_SRCS-y       += xc_resource.c
 CTRL_SRCS-$(CONFIG_X86) += xc_pagetab.c
 CTRL_SRCS-$(CONFIG_Linux) += xc_linux.c xc_linux_osdep.c
 CTRL_SRCS-$(CONFIG_FreeBSD) += xc_freebsd.c xc_freebsd_osdep.c
diff --git a/tools/libxc/xc_private.h b/tools/libxc/xc_private.h
index c50a7c9..3b98c57 100644
--- a/tools/libxc/xc_private.h
+++ b/tools/libxc/xc_private.h
@@ -310,6 +310,27 @@ static inline int do_sysctl(xc_interface *xch, struct 
xen_sysctl *sysctl)
     return ret;
 }
 
+static inline int do_multicall_op(xc_interface *xch,
+                                  xc_hypercall_buffer_t *call_list,
+                                  uint32_t nr_calls)
+{
+    int ret = -1;
+    DECLARE_HYPERCALL;
+    DECLARE_HYPERCALL_BUFFER_ARGUMENT(call_list);
+
+    hypercall.op     = __HYPERVISOR_multicall;
+    hypercall.arg[0] = HYPERCALL_BUFFER_AS_ARG(call_list);
+    hypercall.arg[1] = nr_calls;
+    if ( (ret = do_xen_hypercall(xch, &hypercall)) < 0 )
+    {
+        if ( errno == EACCES )
+            DPRINTF("multicall operation failed -- need to"
+                    " rebuild the user-space tool set?\n");
+    }
+
+    return ret;
+}
+
 int do_memory_op(xc_interface *xch, int cmd, void *arg, size_t len);
 
 void *xc_map_foreign_ranges(xc_interface *xch, uint32_t dom,
diff --git a/tools/libxc/xc_resource.c b/tools/libxc/xc_resource.c
new file mode 100644
index 0000000..f6d082c
--- /dev/null
+++ b/tools/libxc/xc_resource.c
@@ -0,0 +1,92 @@
+/*
+ * xc_resource.c
+ *
+ * Generic resource access API
+ *
+ * Copyright (C) 2014      Intel Corporation
+ * Author Dongxiao Xu <dongxiao.xu@xxxxxxxxx>
+ *
+ * This program 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 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program 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.
+ */
+
+#include "xc_private.h"
+
+int xc_resource_op(xc_interface *xch, uint32_t nr, xc_resource_data_t *data)
+{
+    int rc, i;
+    xc_resource_data_t *rsc_data;
+    multicall_entry_t *call;
+    DECLARE_HYPERCALL_BUFFER(multicall_entry_t, call_list);
+    DECLARE_HYPERCALL_BUFFER(struct xen_platform_op, platform_op);
+    xc_hypercall_buffer_array_t *platform_op_list;
+
+    call_list = xc_hypercall_buffer_alloc(xch, call_list, sizeof(*call_list));
+    if ( !call_list )
+    {
+        return -1;
+    }
+
+    platform_op_list = xc_hypercall_buffer_array_create(xch, nr);
+    if ( !platform_op_list ) {
+        rc = -1;
+        goto out;
+    }
+
+    for ( i = 0; i < nr; i++ ) {
+        platform_op = xc_hypercall_buffer_array_alloc(xch, platform_op_list, i,
+                        platform_op, sizeof(struct xen_platform_op));
+        if ( !platform_op ) {
+            rc = -1;
+            goto out;
+        }
+        rsc_data = data + i;
+        call = call_list + i;
+
+        call->op = __HYPERVISOR_platform_op;
+        call->args[0] = HYPERCALL_BUFFER_AS_ARG(platform_op);
+        if ( rsc_data->flags & MC_NO_PREEMPT )
+            call->flags = MC_NO_PREEMPT;
+
+        platform_op->interface_version = XENPF_INTERFACE_VERSION;
+        platform_op->cmd = XENPF_resource_op;
+        platform_op->u.resource_op.cmd = rsc_data->rsc_op.cmd;
+        platform_op->u.resource_op.cpu = rsc_data->rsc_op.cpu;
+        platform_op->u.resource_op.idx = rsc_data->rsc_op.idx;
+        platform_op->u.resource_op.val = rsc_data->rsc_op.val;
+    }
+
+    rc = do_multicall_op(xch, HYPERCALL_BUFFER(call_list), nr);
+
+    for ( i = 0; i < nr; i++ ) {
+        xc_hypercall_buffer_array_get(xch, platform_op_list, i,
+                        platform_op, sizeof(struct xen_platform_op));
+        rsc_data = data + i;
+        call = call_list + i;
+
+        rsc_data->result = call->result;
+        rsc_data->rsc_op.val = platform_op->u.resource_op.val;
+    }
+
+out:
+    xc_hypercall_buffer_free(xch, call_list);
+    xc_hypercall_buffer_array_destroy(xch, platform_op_list);
+    return rc;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/tools/libxc/xenctrl.h b/tools/libxc/xenctrl.h
index 1c5d0db..0fa0c12 100644
--- a/tools/libxc/xenctrl.h
+++ b/tools/libxc/xenctrl.h
@@ -47,6 +47,7 @@
 #include <xen/xsm/flask_op.h>
 #include <xen/tmem.h>
 #include <xen/kexec.h>
+#include <xen/platform.h>
 
 #include "xentoollog.h"
 
@@ -2643,6 +2644,17 @@ int xc_kexec_load(xc_interface *xch, uint8_t type, 
uint16_t arch,
  */
 int xc_kexec_unload(xc_interface *xch, int type);
 
+typedef xenpf_resource_op_t xc_resource_op_t;
+
+struct xc_resource_data {
+    uint64_t result;
+    uint32_t flags;
+    xc_resource_op_t rsc_op;
+};
+
+typedef struct xc_resource_data xc_resource_data_t;
+int xc_resource_op(xc_interface *xch, uint32_t nr, xc_resource_data_t *data);
+
 #endif /* XENCTRL_H */
 
 /*
-- 
1.7.9.5


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.