From: Vincent Hanquez Date: Wed, 17 Feb 2010 09:05:03 +0000 (+0000) Subject: CP-1634: Bindings for xc_get_boot_cpufeatures X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=790792175ac8e48c6f9fb78cc0c0b95e21c74d69;p=xcp%2Fxen-api-libs.git CP-1634: Bindings for xc_get_boot_cpufeatures Signed-off-by: Vincent Hanquez Acked-by: Rob Hoes --- diff --git a/xc/Makefile b/xc/Makefile index e95d51a..b73f0d7 100644 --- a/xc/Makefile +++ b/xc/Makefile @@ -67,5 +67,5 @@ doc: $(INTF) python ../doc/doc.py $(DOCDIR) "xc" "package" "$(OBJS)" "." "mmap,uuid" "" clean: - rm -f *.o *.so *.a *.cmo *.cmi *.cma *.cmx *.cmxa *.annot $(LIBS) $(PROGRAMS) $(INTF) + rm -f *.o *.so *.a *.cmo *.cmi *.cma *.cmx *.cmxa *.annot $(LIBS) $(PROGRAMS) $(INTF) *~ *.rej *.orig diff --git a/xc/xc.h b/xc/xc.h index a7c0f6c..6ffb52d 100644 --- a/xc/xc.h +++ b/xc/xc.h @@ -20,6 +20,7 @@ #include #include #include +#include #if XEN_SYSCTL_INTERFACE_VERSION < 4 #include #else @@ -187,6 +188,9 @@ int xc_domain_get_acpi_s_state(int handle, unsigned int domid); int xc_domain_trigger_power(int handle, unsigned int domid); int xc_domain_trigger_sleep(int handle, unsigned int domid); +int xc_get_boot_cpufeatures(int handle, uint32_t *, uint32_t *, uint32_t *, + uint32_t *, uint32_t *, uint32_t *, uint32_t *, uint32_t *); + #if XEN_SYSCTL_INTERFACE_VERSION >= 6 #define SAFEDIV(a, b) (((b) >= 0) ? (a) / (b) : (a)) #define COMPAT_FIELD_physinfo_get_nr_cpus(p) (p).nr_cpus diff --git a/xc/xc.ml b/xc/xc.ml index 4dcb801..af4c0de 100644 --- a/xc/xc.ml +++ b/xc/xc.ml @@ -270,6 +270,9 @@ external version_capabilities: handle -> string = external watchdog : handle -> int -> int32 -> int = "stub_xc_watchdog" +external get_boot_cpufeatures: handle -> + (int32 * int32 * int32 * int32 * int32 * int32 * int32 * int32) = "stub_xc_get_boot_cpufeatures" + (* core dump structure *) type core_magic = Magic_hvm | Magic_pv diff --git a/xc/xc.mli b/xc/xc.mli index 84703a2..f7ca795 100644 --- a/xc/xc.mli +++ b/xc/xc.mli @@ -213,3 +213,6 @@ external domain_cpuid_apply: handle -> domid -> bool -> unit external cpuid_check: (int64 * (int64 option)) -> string option array -> (bool * string option array) = "stub_xc_cpuid_check" +external get_boot_cpufeatures: handle -> + (int32 * int32 * int32 * int32 * int32 * int32 * int32 * int32) = "stub_xc_get_boot_cpufeatures" + diff --git a/xc/xc_lib.c b/xc/xc_lib.c index 1a0dc84..cbb3f34 100644 --- a/xc/xc_lib.c +++ b/xc/xc_lib.c @@ -46,6 +46,12 @@ .interface_version = XEN_SYSCTL_INTERFACE_VERSION, \ } +#define DECLARE_PLATFORM(_cmd) \ + struct xen_platform_op platform = { \ + .cmd = _cmd, \ + .interface_version = XENPF_INTERFACE_VERSION, \ + } + #define DECLARE_HYPERCALL2(_cmd, _arg0, _arg1) \ privcmd_hypercall_t hypercall = { \ .op = _cmd, \ @@ -206,6 +212,24 @@ static int do_sysctl(int handle, struct xen_sysctl *sysctl) return ret; } +static int do_platform(int handle, struct xen_platform_op *platform) +{ + int ret; + DECLARE_HYPERCALL1(__HYPERVISOR_platform_op, platform); + + if (mlock(platform, sizeof(*platform)) != 0) { + xc_error_set("mlock failed: %s", strerror(errno)); + return -1; + } + + ret = do_xen_hypercall(handle, &hypercall); + if (ret < 0) + xc_error_hypercall(hypercall, ret); + + munlock(platform, sizeof(*platform)); + return ret; +} + static int do_evtchnctl(int handle, int cmd, void *arg, size_t arg_size) { DECLARE_HYPERCALL2(__HYPERVISOR_event_channel_op, cmd, arg); @@ -1575,6 +1599,35 @@ int xc_domain_trigger_sleep(int handle, unsigned int domid) return ret; } +int xc_get_boot_cpufeatures(int handle, + uint32_t *base_ecx, uint32_t *base_edx, + uint32_t *ext_ecx, uint32_t *ext_edx, + uint32_t *masked_base_ecx, + uint32_t *masked_base_edx, + uint32_t *masked_ext_ecx, + uint32_t *masked_ext_edx) +{ + int ret = -EINVAL; +#ifdef XENPF_get_cpu_features + DECLARE_PLATFORM(XENPF_get_cpu_features); + + ret = do_platform(handle, &platform); + if (ret != 0) + xc_error_set("getting boot cpu features failed: %s", xc_error_get()); + else { + *base_ecx = platform.u.cpu_features.base_ecx; + *base_edx = platform.u.cpu_features.base_edx; + *ext_ecx = platform.u.cpu_features.ext_ecx; + *ext_edx = platform.u.cpu_features.ext_edx; + *masked_base_ecx = platform.u.cpu_features.masked_base_ecx; + *masked_base_edx = platform.u.cpu_features.masked_base_edx; + *masked_ext_ecx = platform.u.cpu_features.masked_ext_ecx; + *masked_ext_edx = platform.u.cpu_features.masked_ext_edx; + } +#endif + return ret; +} + /* * Local variables: * indent-tabs-mode: t diff --git a/xc/xc_stubs.c b/xc/xc_stubs.c index a5fcf05..3da39ce 100644 --- a/xc/xc_stubs.c +++ b/xc/xc_stubs.c @@ -1223,6 +1223,30 @@ CAMLprim value stub_xc_domain_trigger_sleep(value handle, value domid) CAMLreturn(Val_unit); } +CAMLprim value stub_xc_get_boot_cpufeatures(value handle) +{ + CAMLparam1(handle); + CAMLlocal1(v); + uint32_t a, b, c, d, e, f, g, h; + int ret; + + ret = xc_get_boot_cpufeatures(_H(handle), &a, &b, &c, &d, &e, &f, &g, &h); + if (ret < 0) + failwith_xc(); + + v = caml_alloc_tuple(8); + Store_field(v, 0, caml_copy_int32(a)); + Store_field(v, 1, caml_copy_int32(b)); + Store_field(v, 2, caml_copy_int32(c)); + Store_field(v, 3, caml_copy_int32(d)); + Store_field(v, 4, caml_copy_int32(e)); + Store_field(v, 5, caml_copy_int32(f)); + Store_field(v, 6, caml_copy_int32(g)); + Store_field(v, 7, caml_copy_int32(h)); + + CAMLreturn(v); +} + /* * Local variables: * indent-tabs-mode: t