WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-API] [PATCH 2 of 5] xc: split xc non-upstream bindings into xcext m

To: xen-devel@xxxxxxxxxxxxxxxxxxx, xen-api@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-API] [PATCH 2 of 5] xc: split xc non-upstream bindings into xcext module
From: Ian Campbell <ian.campbell@xxxxxxxxxx>
Date: Tue, 07 Dec 2010 14:33:01 +0000
Cc: Ian Campbell <ian.campbell@xxxxxxxxxx>
Delivery-date: Tue, 07 Dec 2010 06:50:58 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <patchbomb.1291732379@xxxxxxxxxxxxxxxxxxxxxx>
List-help: <mailto:xen-api-request@lists.xensource.com?subject=help>
List-id: Discussion of API issues surrounding Xen <xen-api.lists.xensource.com>
List-post: <mailto:xen-api@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-api>, <mailto:xen-api-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-api>, <mailto:xen-api-request@lists.xensource.com?subject=unsubscribe>
References: <patchbomb.1291732379@xxxxxxxxxxxxxxxxxxxxxx>
Sender: xen-api-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mercurial-patchbomb/1.5.2
# HG changeset patch
# User root@xxxxxxxxxxxxxxxxxxxxx
# Date 1291731529 18000
# Node ID cc5f6f7e18cf39cf8ed9112c52aebb9c1317f8f9
# Parent  b4ef59ed08a9a4c1387fd00cd79aec3398bca3f5
xc: split xc non-upstream bindings into xcext module.

move anything which is not provided by upstream libxc and the
associated ocaml bindings in a separate xcext library to ease
replacement of xc library by upstream version.

Some of this functionality could potentially be upstreamed straight
away but other bits rely on stuff from the XCP hypervisor patch queue.

One change of not is that Xcext.hvm_check_pvdriver expects that domid is always
an HVM domain. This matches the existing callsites (and the name) and reduces
cross talk between xc and xcext.

Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>

diff -r b4ef59ed08a9 -r cc5f6f7e18cf Makefile.in
--- a/Makefile.in       Tue Dec 07 09:18:49 2010 -0500
+++ b/Makefile.in       Tue Dec 07 09:18:49 2010 -0500
@@ -41,6 +41,7 @@ ifeq ($(HAVE_XEN),1)
        $(MAKE) -C xc
        $(MAKE) -C xb
        $(MAKE) -C xs
+       $(MAKE) -C xcext
        $(MAKE) -C xsrpc
        $(MAKE) -C eventchn
        $(MAKE) -C cpuid
@@ -81,6 +82,7 @@ ifeq ($(HAVE_XEN),1)
        $(MAKE) -C xc install
        $(MAKE) -C xb install
        $(MAKE) -C xs install
+       $(MAKE) -C xcext install
        $(MAKE) -C xsrpc install
        $(MAKE) -C eventchn install
        $(MAKE) -C cpuid install
@@ -122,6 +124,7 @@ ifeq ($(HAVE_XEN),1)
        $(MAKE) -C xs uninstall
        $(MAKE) -C xb uninstall
        $(MAKE) -C xc uninstall
+       $(MAKE) -C xcext uninstall
        $(MAKE) -C mmap uninstall
        $(MAKE) -C cpuid uninstall
        $(MAKE) -C vhd uninstall
@@ -160,6 +163,7 @@ doc:
        $(MAKE) -C xb doc
        $(MAKE) -C xc doc
        $(MAKE) -C xs doc
+       $(MAKE) -C xcext doc
        $(MAKE) -C xml-light2 doc
        $(MAKE) -C rpc-light doc
        $(MAKE) -C http-svr doc
@@ -208,6 +212,7 @@ cleanxen:
        $(MAKE) -C xc clean
        $(MAKE) -C xb clean
        $(MAKE) -C xs clean
+       $(MAKE) -C xcext clean
        $(MAKE) -C xsrpc clean
        $(MAKE) -C eventchn clean
 
diff -r b4ef59ed08a9 -r cc5f6f7e18cf cpuid/META.in
--- a/cpuid/META.in     Tue Dec 07 09:18:49 2010 -0500
+++ b/cpuid/META.in     Tue Dec 07 09:18:49 2010 -0500
@@ -1,5 +1,5 @@
 version = "@VERSION@"
 description = "Cpuid extension"
-requires = "stdext xc xen-utils"
+requires = "stdext xc xcext xen-utils"
 archive(byte) = "cpuid.cma"
 archive(native) = "cpuid.cmxa"
diff -r b4ef59ed08a9 -r cc5f6f7e18cf cpuid/Makefile
--- a/cpuid/Makefile    Tue Dec 07 09:18:49 2010 -0500
+++ b/cpuid/Makefile    Tue Dec 07 09:18:49 2010 -0500
@@ -2,7 +2,7 @@ CC = gcc
 CFLAGS = -Wall -fPIC -O2 -I/usr/lib/ocaml -I$(XEN_ROOT)/usr/include
 OCAMLC = ocamlc -g
 OCAMLOPT = ocamlopt
-INCLUDES = -I ../stdext -I ../xc -I ../xen-utils
+INCLUDES = -I ../stdext -I ../xc -I ../xcext -I ../xen-utils
 
 LDFLAGS = -cclib -L./
 
@@ -65,7 +65,7 @@ uninstall:
 
 .PHONY: doc
 doc: $(INTF)
-       python ../doc/doc.py $(DOCDIR) "cpuid" "package" "$(OBJS)" "." "stdext 
xc xen-utils" ""
+       python ../doc/doc.py $(DOCDIR) "cpuid" "package" "$(OBJS)" "." "stdext 
xc xcext xen-utils" ""
        
 clean:
        rm -f *.o *.so *.a *.cmo *.cmi *.cma *.cmx *.cmxa *.annot $(LIBS) 
$(PROGRAMS) *~ *.rej
diff -r b4ef59ed08a9 -r cc5f6f7e18cf cpuid/cpuid.ml
--- a/cpuid/cpuid.ml    Tue Dec 07 09:18:49 2010 -0500
+++ b/cpuid/cpuid.ml    Tue Dec 07 09:18:49 2010 -0500
@@ -138,7 +138,7 @@ let is_maskable manufacturer family mode
 
 let get_features_from_xen () =
        let features = 
-         try Xc.with_intf (fun xc -> Xc.get_boot_cpufeatures xc) 
+         try Xc.with_intf (fun xc -> Xcext.get_boot_cpufeatures xc) 
          with _ -> 0l, 0l, 0l, 0l, 0l, 0l, 0l, 0l 
        in
        match features with
diff -r b4ef59ed08a9 -r cc5f6f7e18cf xapi-libs.spec
--- a/xapi-libs.spec    Tue Dec 07 09:18:49 2010 -0500
+++ b/xapi-libs.spec    Tue Dec 07 09:18:49 2010 -0500
@@ -341,6 +341,14 @@ rm -rf $RPM_BUILD_ROOT
    /usr/lib/ocaml/xc/xc.cmi
    /usr/lib/ocaml/xc/xc.cmx
    /usr/lib/ocaml/xc/xc.cmxa
+   /usr/lib/ocaml/xcext/META
+   /usr/lib/ocaml/xcext/dllxcext_stubs.so
+   /usr/lib/ocaml/xcext/libxcext_stubs.a
+   /usr/lib/ocaml/xcext/xcext.a
+   /usr/lib/ocaml/xcext/xcext.cma
+   /usr/lib/ocaml/xcext/xcext.cmi
+   /usr/lib/ocaml/xcext/xcext.cmx
+   /usr/lib/ocaml/xcext/xcext.cmxa
    /usr/lib/ocaml/xs/META
    /usr/lib/ocaml/xs/queueop.cmx
    /usr/lib/ocaml/xs/xs.a
diff -r b4ef59ed08a9 -r cc5f6f7e18cf xc/xc.h
--- a/xc/xc.h   Tue Dec 07 09:18:49 2010 -0500
+++ b/xc/xc.h   Tue Dec 07 09:18:49 2010 -0500
@@ -31,20 +31,9 @@
 #include <xen/hvm/params.h>
 #include "xc_e820.h"
 
-#ifndef XEN_DOMCTL_get_runstate_info
-#warning "runstate info is missing"
-typedef struct {
-       int32_t state;
-       uint32_t missed_changes;
-       uint64_t state_entry_time;
-       uint64_t time[6];
-} xen_domctl_runstate_info_t;
-#endif
-
 typedef xen_domctl_getdomaininfo_t xc_domaininfo_t;
 typedef xen_domctl_getvcpuinfo_t xc_vcpuinfo_t;
 typedef xen_sysctl_physinfo_t xc_physinfo_t;
-typedef xen_domctl_runstate_info_t xc_runstate_info_t;
 
 struct xc_core_header {
        unsigned int xch_magic;
@@ -111,14 +100,11 @@ int xc_domain_memory_populate_physmap(in
                                       unsigned int extent_order,
                                       unsigned int address_bits,
                                       xen_pfn_t *extent_start);
-int xc_domain_setvmxassist(int handle, unsigned int domid, int use_vmxassist);
 int xc_domain_max_vcpus(int handle, unsigned int domid, unsigned int max);
 int xc_domain_sethandle(int handle, unsigned int domid,
                         xen_domain_handle_t dhandle);
 int xc_vcpu_getinfo(int handle, unsigned int domid, unsigned int vcpu,
                     xc_vcpuinfo_t *info);
-int xc_get_runstate_info(int handle, unsigned int domid,
-                        xc_runstate_info_t *info);
 int xc_domain_ioport_permission(int handle, unsigned int domid,
                                 unsigned int first_port, unsigned int nr_ports,
                                 unsigned int allow_access);
@@ -158,7 +144,6 @@ int xc_shadow_allocation_set(int handle,
                             uint32_t mb);
 int xc_domain_get_pfn_list(int handle, unsigned int domid,
                            xen_pfn_t *pfn_array, unsigned long max_pfns);
-int xc_hvm_check_pvdriver(int handle, unsigned int domid);
 
 int xc_domain_assign_device(int handle, unsigned int domid,
                             int domain, int bus, int slot, int func);
@@ -177,18 +162,6 @@ int xc_domain_cpuid_set(int xc, unsigned
 int xc_domain_cpuid_apply(int xc, unsigned int domid, int hvm);
 int xc_cpuid_check(uint32_t input, uint32_t optsubinput,
                    char *config[4], char *config_out[4]);
-int xc_domain_suppress_spurious_page_faults(int xc, uint32_t domid);
-
-int xc_domain_send_s3resume(int handle, unsigned int domid);
-int xc_domain_set_vpt_align(int handle, unsigned int domid, int vpt_align);
-int xc_domain_set_hpet(int handle, unsigned int domid, int hpet);
-int xc_domain_set_timer_mode(int handle, unsigned int domid, int mode);
-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))
diff -r b4ef59ed08a9 -r cc5f6f7e18cf xc/xc.ml
--- a/xc/xc.ml  Tue Dec 07 09:18:49 2010 -0500
+++ b/xc/xc.ml  Tue Dec 07 09:18:49 2010 -0500
@@ -26,18 +26,6 @@ type vcpuinfo =
        cpumap: int32;
 }
 
-type runstateinfo = {
-  state : int32;
-  missed_changes: int32;
-  state_entry_time : int64;
-  time0 : int64;
-  time1 : int64;
-  time2 : int64;
-  time3 : int64;
-  time4 : int64;
-  time5 : int64;
-}
-
 type domaininfo =
 {
        domid             : domid;
@@ -138,9 +126,6 @@ external _domain_sethandle: handle -> do
 let domain_sethandle handle n uuid =
        _domain_sethandle handle n (Uuid.int_array_of_uuid uuid)
 
-external domain_setvmxassist: handle -> domid -> bool -> unit
-       = "stub_xc_domain_setvmxassist"
-
 external domain_max_vcpus: handle -> domid -> int -> unit
        = "stub_xc_domain_max_vcpus"
 
@@ -168,8 +153,6 @@ external domain_getinfo: handle -> domid
 
 external domain_get_vcpuinfo: handle -> int -> int -> vcpuinfo
        = "stub_xc_vcpu_getinfo"
-external domain_get_runstate_info : handle -> int -> runstateinfo
-  = "stub_xc_get_runstate_info"
 
 external domain_ioport_permission: handle -> domid -> int -> int -> bool -> 
unit
        = "stub_xc_domain_ioport_permission"
@@ -243,23 +226,6 @@ external domain_deassign_device: handle 
 external domain_test_assign_device: handle -> domid -> (int * int * int * int) 
-> bool
        = "stub_xc_domain_test_assign_device"
 
-external domain_suppress_spurious_page_faults: handle -> domid -> unit
-       = "stub_xc_domain_suppress_spurious_page_faults"
-
-external domain_set_timer_mode: handle -> domid -> int -> unit = 
"stub_xc_domain_set_timer_mode"
-external domain_set_hpet: handle -> domid -> int -> unit = 
"stub_xc_domain_set_hpet"
-external domain_set_vpt_align: handle -> domid -> int -> unit = 
"stub_xc_domain_set_vpt_align"
-
-external domain_send_s3resume: handle -> domid -> unit = 
"stub_xc_domain_send_s3resume"
-external domain_get_acpi_s_state: handle -> domid -> int = 
"stub_xc_domain_get_acpi_s_state"
-
-external domain_trigger_power: handle -> domid -> unit = 
"stub_xc_domain_trigger_power"
-external domain_trigger_sleep: handle -> domid -> unit = 
"stub_xc_domain_trigger_sleep"
-
-(** check if some hvm domain got pv driver or not *)
-external hvm_check_pvdriver: handle -> domid -> bool
-       = "stub_xc_hvm_check_pvdriver"
-
 external version: handle -> version = "stub_xc_version_version"
 external version_compile_info: handle -> compile_info
        = "stub_xc_version_compile_info"
@@ -270,9 +236,6 @@ external version_capabilities: handle ->
 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 -r b4ef59ed08a9 -r cc5f6f7e18cf xc/xc.mli
--- a/xc/xc.mli Tue Dec 07 09:18:49 2010 -0500
+++ b/xc/xc.mli Tue Dec 07 09:18:49 2010 -0500
@@ -19,17 +19,6 @@ type vcpuinfo = {
   cputime : int64;
   cpumap : int32;
 }
-type runstateinfo = {
-  state : int32;
-  missed_changes: int32;
-  state_entry_time : int64;
-  time0 : int64;
-  time1 : int64;
-  time2 : int64;
-  time3 : int64;
-  time4 : int64;
-  time5 : int64;
-}
 type domaininfo = {
   domid : domid;
   dying : bool;
@@ -89,8 +78,6 @@ val domain_create : handle -> int32 -> d
 external _domain_sethandle : handle -> domid -> int array -> unit
   = "stub_xc_domain_sethandle"
 val domain_sethandle : handle -> domid -> 'a Uuid.t -> unit
-external domain_setvmxassist: handle -> domid -> bool -> unit
-  = "stub_xc_domain_setvmxassist"
 external domain_max_vcpus : handle -> domid -> int -> unit
   = "stub_xc_domain_max_vcpus"
 external domain_pause : handle -> domid -> unit = "stub_xc_domain_pause"
@@ -107,8 +94,6 @@ external domain_getinfo : handle -> domi
   = "stub_xc_domain_getinfo"
 external domain_get_vcpuinfo : handle -> int -> int -> vcpuinfo
   = "stub_xc_vcpu_getinfo"
-external domain_get_runstate_info : handle -> int -> runstateinfo
-  = "stub_xc_get_runstate_info"
 external domain_ioport_permission: handle -> domid -> int -> int -> bool -> 
unit
        = "stub_xc_domain_ioport_permission"
 external domain_iomem_permission: handle -> domid -> nativeint -> nativeint -> 
bool -> unit
@@ -158,21 +143,6 @@ external domain_deassign_device: handle 
 external domain_test_assign_device: handle -> domid -> (int * int * int * int) 
-> bool
        = "stub_xc_domain_test_assign_device"
 
-external domain_set_timer_mode: handle -> domid -> int -> unit = 
"stub_xc_domain_set_timer_mode"
-external domain_set_hpet: handle -> domid -> int -> unit = 
"stub_xc_domain_set_hpet"
-external domain_set_vpt_align: handle -> domid -> int -> unit = 
"stub_xc_domain_set_vpt_align"
-
-external domain_send_s3resume: handle -> domid -> unit
-  = "stub_xc_domain_send_s3resume"
-external domain_get_acpi_s_state: handle -> domid -> int = 
"stub_xc_domain_get_acpi_s_state"
-
-external domain_trigger_power: handle -> domid -> unit
-  = "stub_xc_domain_trigger_power"
-external domain_trigger_sleep: handle -> domid -> unit
-  = "stub_xc_domain_trigger_sleep"
-
-external hvm_check_pvdriver : handle -> domid -> bool
-  = "stub_xc_hvm_check_pvdriver"
 external version : handle -> version = "stub_xc_version_version"
 external version_compile_info : handle -> compile_info
   = "stub_xc_version_compile_info"
@@ -201,9 +171,6 @@ external domain_set_machine_address_size
 external domain_get_machine_address_size: handle -> domid -> int
        = "stub_xc_domain_get_machine_address_size"
 
-external domain_suppress_spurious_page_faults: handle -> domid -> unit
-       = "stub_xc_domain_suppress_spurious_page_faults"
-
 external domain_cpuid_set: handle -> domid -> bool -> (int64 * (int64 option))
                         -> string option array
                         -> string option array
@@ -212,7 +179,3 @@ external domain_cpuid_apply: handle -> d
        = "stub_xc_domain_cpuid_apply"
 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 -r b4ef59ed08a9 -r cc5f6f7e18cf xc/xc_lib.c
--- a/xc/xc_lib.c       Tue Dec 07 09:18:49 2010 -0500
+++ b/xc/xc_lib.c       Tue Dec 07 09:18:49 2010 -0500
@@ -319,29 +319,6 @@ int xc_get_hvm_param(int handle, unsigne
        return ret;
 }
 
-static int xc_set_hvm_param(int handle, unsigned int domid,
-                            int param, unsigned long value)
-{
-       struct xen_hvm_param arg = {
-               .domid = domid,
-               .index = param,
-               .value = value,
-       };
-       DECLARE_HYPERCALL2(__HYPERVISOR_hvm_op, HVMOP_set_param, (unsigned 
long) &arg);
-       int ret;
-
-       if (mlock(&arg, sizeof(arg)) == -1) {
-               xc_error_set("mlock failed: %s", strerror(errno));
-               return -1;
-       }
-
-       ret = do_xen_hypercall(handle, &hypercall);
-       if (ret)
-               xc_error_hypercall(hypercall, ret);
-       munlock(&arg, sizeof(arg));
-       return ret;
-}
-
 /*---- XC API ----*/
 int xc_domain_create(int handle, unsigned int ssidref,
                      xen_domain_handle_t dhandle,
@@ -384,29 +361,6 @@ int xc_domain_unpause(int handle, unsign
        return ret;
 }
 
-/* return 1 if hvm domain got pv driver, 0 if not. -1 is error occurs */
-int xc_hvm_check_pvdriver(int handle, unsigned int domid)
-{
-       int ret;
-       unsigned long irq = 0;
-       xc_domaininfo_t info;
-
-       ret = xc_domain_getinfolist(handle, domid, 1, &info);
-       if (ret != 1) {
-               xc_error_set("domain getinfo failed: %s", strerror(errno));
-               xc_error_dom_set(domid, "hvm_check_pvdriver");
-               return -1;
-       }
-
-       if (!info.flags & XEN_DOMINF_hvm_guest) {
-               xc_error_set("domain is not hvm");
-               xc_error_dom_set(domid, "hvm_check_pvdriver");
-               return -1;
-       }
-       xc_get_hvm_param(handle, domid, HVM_PARAM_CALLBACK_IRQ, &irq);
-       return irq;
-}
-
 static int modify_returncode_register(int handle, unsigned int domid)
 {
        int ret;
@@ -769,21 +723,6 @@ int xc_domain_memory_populate_physmap(in
        return 0;
 }
 
-int xc_domain_setvmxassist(int handle, unsigned int domid, int use_vmxassist)
-{
-       int ret = 0;
-#ifdef XEN_DOMCTL_setvmxassist
-       DECLARE_DOMCTL(XEN_DOMCTL_setvmxassist, domid);
-       domctl.u.setvmxassist.use_vmxassist = use_vmxassist;
-
-       ret = do_domctl(handle, &domctl);
-       if (ret)
-               xc_error_dom_set(domid, "setting vmxassist to %d",
-                                use_vmxassist);
-#endif
-       return ret;
-}
-
 int xc_domain_max_vcpus(int handle, unsigned int domid, unsigned int max)
 {
        int ret;
@@ -825,22 +764,6 @@ int xc_vcpu_getinfo(int handle, unsigned
        return ret;
 }
 
-int xc_get_runstate_info(int handle, unsigned int domid,
-                        xc_runstate_info_t *info)
-{
-       int ret = -EBADF;
-#ifdef XEN_DOMCTL_get_runstate_info
-       DECLARE_DOMCTL(XEN_DOMCTL_get_runstate_info, domid);
-       ret = do_domctl(handle, &domctl);
-       if (ret < 0) {
-               xc_error_dom_set(domid, "get runstate info");
-               return ret;
-       }
-       memcpy(info, &domctl.u.domain_runstate, sizeof(*info));
-#endif
-       return ret;
-}
-
 int xc_domain_ioport_permission(int handle, unsigned int domid,
                                 unsigned int first_port, unsigned int nr_ports,
                                 unsigned int allow_access)
@@ -1515,119 +1438,6 @@ out:
        return ret;
 }
 
-#ifndef HVM_PARAM_HPET_ENABLED
-#define HVM_PARAM_HPET_ENABLED 11
-#endif
-
-#ifndef HVM_PARAM_ACPI_S_STATE
-#define HVM_PARAM_ACPI_S_STATE 14
-#endif
-
-#ifndef HVM_PARAM_VPT_ALIGN
-#define HVM_PARAM_VPT_ALIGN 16
-#endif
-
-int xc_domain_send_s3resume(int handle, unsigned int domid)
-{
-       #define HVM_PARAM_ACPI_S_STATE 14
-       return xc_set_hvm_param(handle, domid, HVM_PARAM_ACPI_S_STATE, 0);
-}
-
-int xc_domain_set_timer_mode(int handle, unsigned int domid, int mode)
-{
-       return xc_set_hvm_param(handle, domid,
-                               HVM_PARAM_TIMER_MODE, (unsigned long) mode);
-}
-
-int xc_domain_set_hpet(int handle, unsigned int domid, int hpet)
-{
-       return xc_set_hvm_param(handle, domid, HVM_PARAM_HPET_ENABLED, 
(unsigned long) hpet);
-}
-
-int xc_domain_set_vpt_align(int handle, unsigned int domid, int vpt_align)
-{
-       return xc_set_hvm_param(handle, domid, HVM_PARAM_HPET_ENABLED, 
(unsigned long) vpt_align);
-}
-
-int xc_domain_get_acpi_s_state(int handle, unsigned int domid)
-{
-       int ret;
-       unsigned long value;
-
-       ret = xc_get_hvm_param(handle, domid, HVM_PARAM_ACPI_S_STATE, &value);
-       if (ret != 0)
-               xc_error_dom_set(domid, "get acpi s-state");
-       return value;
-}
-
-int xc_domain_suppress_spurious_page_faults(int xc, uint32_t domid)
-{
-       int rc = 0;
-#ifdef XEN_DOMCTL_suppress_spurious_page_faults
-       DECLARE_DOMCTL(XEN_DOMCTL_suppress_spurious_page_faults, domid);
-
-       rc = do_domctl(xc, &domctl);
-       if (rc != 0)
-               xc_error_dom_set(domid, "suppress spurious page faults");
-#endif
-       return rc;
-}
-
-int xc_domain_trigger_power(int handle, unsigned int domid)
-{
-    int ret;
-
-    DECLARE_DOMCTL(XEN_DOMCTL_sendtrigger, domid);
-    domctl.u.sendtrigger.trigger = XEN_DOMCTL_SENDTRIGGER_POWER;
-
-       ret = do_domctl(handle, &domctl);
-       if (ret != 0)
-               xc_error_set("power button failed: %s", xc_error_get());
-    return ret;
-}
-
-int xc_domain_trigger_sleep(int handle, unsigned int domid)
-{
-    int ret;
-
-    DECLARE_DOMCTL(XEN_DOMCTL_sendtrigger, domid);
-    domctl.u.sendtrigger.trigger = XEN_DOMCTL_SENDTRIGGER_SLEEP;
-
-       ret = do_domctl(handle, &domctl);
-       if (ret != 0)
-               xc_error_set("sleep button failed: %s", xc_error_get());
-    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 -r b4ef59ed08a9 -r cc5f6f7e18cf xc/xc_stubs.c
--- a/xc/xc_stubs.c     Tue Dec 07 09:18:49 2010 -0500
+++ b/xc/xc_stubs.c     Tue Dec 07 09:18:49 2010 -0500
@@ -174,20 +174,6 @@ CAMLprim value stub_xc_domain_create(val
        CAMLreturn(Val_int(domid));
 }
 
-CAMLprim value stub_xc_domain_setvmxassist(value xc_handle, value domid,
-                                           value use_vmxassist)
-{
-       CAMLparam3(xc_handle, domid, use_vmxassist);
-       int r;
-
-       r = xc_domain_setvmxassist(_H(xc_handle), _D(domid),
-                                  Bool_val(use_vmxassist));
-       if (r)
-               failwith_xc();
-
-       CAMLreturn(Val_unit);
-}
-
 CAMLprim value stub_xc_domain_max_vcpus(value xc_handle, value domid,
                                         value max_vcpus)
 {
@@ -387,41 +373,6 @@ CAMLprim value stub_xc_vcpu_getinfo(valu
        CAMLreturn(result);
 }
 
-CAMLprim value stub_xc_get_runstate_info(value xc_handle, value domid) 
-{
-       CAMLparam2(xc_handle, domid);
-       CAMLlocal1(result);
-       xc_runstate_info_t info;
-       int retval;
-       
-       int c_xc_handle = _H(xc_handle);
-       uint32_t c_domid = _D(domid);
-       retval = xc_get_runstate_info(c_xc_handle, c_domid, &info);
-       if (retval < 0)
-               failwith_xc();
-
-       /* Store 
-          0 : state (int32)
-          1 : missed_changes (int32)
-          2 : state_entry_time (int64)
-          3-8 : times (int64s)
-       */
-       result = caml_alloc_tuple(9);
-       Store_field(result, 0, caml_copy_int32(info.state));
-       Store_field(result, 1, caml_copy_int32(info.missed_changes));
-       Store_field(result, 2, caml_copy_int64(info.state_entry_time));
-       Store_field(result, 3, caml_copy_int64(info.time[0]));
-       Store_field(result, 4, caml_copy_int64(info.time[1]));
-       Store_field(result, 5, caml_copy_int64(info.time[2]));
-       Store_field(result, 6, caml_copy_int64(info.time[3]));
-       Store_field(result, 7, caml_copy_int64(info.time[4]));
-       Store_field(result, 8, caml_copy_int64(info.time[5]));
-
-       CAMLreturn(result);
-}
-
-
-
 CAMLprim value stub_xc_vcpu_context_get(value xc_handle, value domid,
                                         value cpu)
 {
@@ -697,19 +648,6 @@ CAMLprim value stub_xc_domain_get_machin
        CAMLreturn(Val_int(retval));
 }
 
-CAMLprim value stub_xc_domain_suppress_spurious_page_faults(value xc_handle,
-                                                      value domid)
-{
-       CAMLparam2(xc_handle, domid);
-       int c_xc_handle = _H(xc_handle);
-       uint32_t c_domid = _D(domid);
-
-       int retval = xc_domain_suppress_spurious_page_faults(c_xc_handle, 
c_domid);
-       if (retval)
-               failwith_xc();
-       CAMLreturn(Val_unit);
-}
-
 CAMLprim value stub_xc_domain_cpuid_set(value xc_handle, value domid,
                                         value is_hvm, value input,
                                         value config)
@@ -1080,17 +1018,6 @@ CAMLprim value stub_xc_domain_irq_permis
        CAMLreturn(Val_unit);
 }
 
-CAMLprim value stub_xc_hvm_check_pvdriver(value xc_handle, value domid)
-{
-       CAMLparam2(xc_handle, domid);
-       int ret;
-
-       ret = xc_hvm_check_pvdriver(_H(xc_handle), _D(domid));
-       if (ret < 0)
-               failwith_xc();
-       CAMLreturn(Val_bool(ret));
-}
-
 CAMLprim value stub_xc_domain_test_assign_device(value xc_handle, value domid, 
value desc)
 {
        CAMLparam3(xc_handle, domid, desc);
@@ -1156,97 +1083,6 @@ CAMLprim value stub_xc_watchdog(value ha
        CAMLreturn(Val_int(ret));
 }
 
-CAMLprim value stub_xc_domain_get_acpi_s_state(value handle, value domid)
-{
-       CAMLparam2(handle, domid);
-       int ret;
-
-       ret = xc_domain_get_acpi_s_state(_H(handle), _D(domid));
-       if (ret < 0)
-               failwith_xc();
-
-       CAMLreturn(Val_int(ret));
-}
-
-CAMLprim value stub_xc_domain_send_s3resume(value handle, value domid)
-{
-       CAMLparam2(handle, domid);
-       xc_domain_send_s3resume(_H(handle), _D(domid));
-       CAMLreturn(Val_unit);
-}
-
-
-CAMLprim value stub_xc_domain_set_timer_mode(value handle, value id, value 
mode)
-{
-       CAMLparam3(handle, id, mode);
-       int ret;
-
-       ret = xc_domain_set_timer_mode(_H(handle), _D(id), Int_val(mode));
-       if (ret < 0)
-               failwith_xc();
-       CAMLreturn(Val_unit);
-}
-
-CAMLprim value stub_xc_domain_set_hpet(value handle, value id, value mode)
-{
-       CAMLparam3(handle, id, mode);
-       int ret;
-
-       ret = xc_domain_set_hpet(_H(handle), _D(id), Int_val(mode));
-       if (ret < 0)
-               failwith_xc();
-       CAMLreturn(Val_unit);
-}
-
-CAMLprim value stub_xc_domain_set_vpt_align(value handle, value id, value mode)
-{
-       CAMLparam3(handle, id, mode);
-       int ret;
-
-       ret = xc_domain_set_vpt_align(_H(handle), _D(id), Int_val(mode));
-       if (ret < 0)
-               failwith_xc();
-       CAMLreturn(Val_unit);
-}
-
-CAMLprim value stub_xc_domain_trigger_power(value handle, value domid)
-{
-       CAMLparam2(handle, domid);
-       xc_domain_trigger_power(_H(handle), _D(domid));
-       CAMLreturn(Val_unit);
-}
-
-CAMLprim value stub_xc_domain_trigger_sleep(value handle, value domid)
-{
-       CAMLparam2(handle, domid);
-       xc_domain_trigger_sleep(_H(handle), _D(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
diff -r b4ef59ed08a9 -r cc5f6f7e18cf xcext/META.in
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/xcext/META.in     Tue Dec 07 09:18:49 2010 -0500
@@ -0,0 +1,5 @@
+version = "@VERSION@"
+description = "Xen Control Interface (extensions)"
+requires = "mmap,uuid,xc"
+archive(byte) = "xcext.cma"
+archive(native) = "xcext.cmxa"
diff -r b4ef59ed08a9 -r cc5f6f7e18cf xcext/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/xcext/Makefile    Tue Dec 07 09:18:49 2010 -0500
@@ -0,0 +1,71 @@
+CC = gcc
+CFLAGS = -Wall -fPIC -O2 -I/usr/lib/ocaml -I$(XEN_ROOT)/usr/include -I../mmap 
-I./
+OCAMLC = ocamlc -g -I ../mmap -I ../uuid -I ../xc
+OCAMLOPT = ocamlopt
+OCAMLOPTFLAGS = -g -dtypes -I ../mmap -I ../uuid -I ../xc
+
+LDFLAGS = -cclib -L./
+
+VERSION := $(shell hg parents --template "{rev}" 2>/dev/null || echo 0.0)
+
+OCAMLABI := $(shell ocamlc -version)
+OCAMLLIBDIR := $(shell ocamlc -where)
+OCAMLDESTDIR ?= $(OCAMLLIBDIR)
+
+OBJS = xcext
+INTF = xcext.cmi
+LIBS = xcext.cma xcext.cmxa
+
+DOCDIR = /myrepos/xen-api-libs.hg/doc
+
+all: $(INTF) $(LIBS) $(PROGRAMS)
+
+bins: $(PROGRAMS)
+
+libs: $(LIBS)
+
+xcext.cmxa: libxcext_stubs.a $(foreach obj,$(OBJS),$(obj).cmx)
+       $(OCAMLOPT) $(OCAMLOPTFLAGS) -a -o $@ -cclib -lxcext_stubs $(foreach 
obj,$(OBJS),$(obj).cmx)
+
+xcext.cma: $(foreach obj,$(OBJS),$(obj).cmo)
+       $(OCAMLC) -a -dllib dllxcext_stubs.so -cclib -lxcext_stubs -o $@ 
$(foreach obj,$(OBJS),$(obj).cmo)
+
+xcext_stubs.a: xcext_lib.o xcext_stubs.o
+       ocamlmklib -o xcext_stubs $+
+
+libxcext_stubs.a: xcext_lib.o xcext_stubs.o
+       ar rcs $@ $+
+       ocamlmklib -o xcext_stubs $+
+
+%.cmo: %.ml
+       $(OCAMLC) -c -o $@ $<
+
+%.cmi: %.mli
+       $(OCAMLC) -c -o $@ $<
+
+%.cmx: %.ml
+       $(OCAMLOPT) $(OCAMLOPTFLAGS) -c -o $@ $<
+
+%.o: %.c
+       $(CC) $(CFLAGS) -c -o $@ $<
+
+META: META.in
+       sed 's/@VERSION@/$(VERSION)/g' < $< > $@
+
+.PHONY: install
+install: path = $(DESTDIR)$(shell ocamlfind printconf destdir)
+install: $(LIBS) META
+       mkdir -p $(path)
+       ocamlfind install -destdir $(path) -ldconf ignore xcext META $(INTF) 
$(LIBS) *.a *.so *.cmx
+
+.PHONY: uninstall
+uninstall:
+       ocamlfind remove xcext
+
+.PHONY: doc
+doc: $(INTF)
+       python ../doc/doc.py $(DOCDIR) "xcext" "package" "$(OBJS)" "." 
"mmap,uuid" ""
+       
+clean:
+       rm -f *.o *.so *.a *.cmo *.cmi *.cma *.cmx *.cmxa *.annot $(LIBS) 
$(PROGRAMS) $(INTF) *~ *.rej *.orig
+
diff -r b4ef59ed08a9 -r cc5f6f7e18cf xcext/xcext.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/xcext/xcext.h     Tue Dec 07 09:18:49 2010 -0500
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2006-2009 Citrix Systems Inc.
+ *
+ * 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.
+ */
+
+#define __XEN_TOOLS__
+
+#include <xen/xen.h>
+#include <xen/memory.h>
+#include <xen/sysctl.h>
+#include <xen/domctl.h>
+#include <xen/sched.h>
+#include <xen/platform.h>
+#if XEN_SYSCTL_INTERFACE_VERSION < 4
+#include <xen/linux/privcmd.h>
+#else
+#include <xen/sys/privcmd.h>
+#endif
+#include <xen/version.h>
+#include <xen/foreign/x86_32.h>
+#include <xen/foreign/x86_64.h>
+#include <xen/hvm/params.h>
+
+#ifndef XEN_DOMCTL_get_runstate_info
+#warning "runstate info is missing"
+typedef struct {
+       int32_t state;
+       uint32_t missed_changes;
+       uint64_t state_entry_time;
+       uint64_t time[6];
+} xen_domctl_runstate_info_t;
+#endif
+
+typedef xen_domctl_getdomaininfo_t xc_domaininfo_t;
+typedef xen_domctl_getvcpuinfo_t xc_vcpuinfo_t;
+typedef xen_sysctl_physinfo_t xc_physinfo_t;
+typedef xen_domctl_runstate_info_t xc_runstate_info_t;
+
+char * xcext_error_get(void);
+void xcext_error_clear(void);
+
+int xcext_using_injection(void);
+
+int xcext_domain_setvmxassist(int handle, unsigned int domid, int 
use_vmxassist);
+int xcext_get_runstate_info(int handle, unsigned int domid,
+                        xc_runstate_info_t *info);
+
+int xcext_hvm_check_pvdriver(int handle, unsigned int domid);
+
+int xcext_domain_suppress_spurious_page_faults(int xc, uint32_t domid);
+
+int xcext_domain_send_s3resume(int handle, unsigned int domid);
+int xcext_domain_set_vpt_align(int handle, unsigned int domid, int vpt_align);
+int xcext_domain_set_hpet(int handle, unsigned int domid, int hpet);
+int xcext_domain_set_timer_mode(int handle, unsigned int domid, int mode);
+int xcext_domain_get_acpi_s_state(int handle, unsigned int domid);
+int xcext_domain_trigger_power(int handle, unsigned int domid);
+int xcext_domain_trigger_sleep(int handle, unsigned int domid);
+
+int xcext_get_boot_cpufeatures(int handle, uint32_t *, uint32_t *, uint32_t *,
+       uint32_t *, uint32_t *, uint32_t *, uint32_t *, uint32_t *);
diff -r b4ef59ed08a9 -r cc5f6f7e18cf xcext/xcext.ml
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/xcext/xcext.ml    Tue Dec 07 09:18:49 2010 -0500
@@ -0,0 +1,52 @@
+(*
+ * Copyright (C) 2006-2009 Citrix Systems Inc.
+ *
+ * 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.
+ *)
+
+type runstateinfo = {
+  state : int32;
+  missed_changes: int32;
+  state_entry_time : int64;
+  time0 : int64;
+  time1 : int64;
+  time2 : int64;
+  time3 : int64;
+  time4 : int64;
+  time5 : int64;
+}
+
+
+external domain_setvmxassist: Xc.handle -> Xc.domid -> bool -> unit
+       = "stub_xcext_domain_setvmxassist"
+
+external domain_get_runstate_info : Xc.handle -> int -> runstateinfo
+       = "stub_xcext_get_runstate_info"
+ 
+external domain_suppress_spurious_page_faults: Xc.handle -> Xc.domid -> unit
+       = "stub_xcext_domain_suppress_spurious_page_faults"
+
+external domain_set_timer_mode: Xc.handle -> Xc.domid -> int -> unit = 
"stub_xcext_domain_set_timer_mode"
+external domain_set_hpet: Xc.handle -> Xc.domid -> int -> unit = 
"stub_xcext_domain_set_hpet"
+external domain_set_vpt_align: Xc.handle -> Xc.domid -> int -> unit = 
"stub_xcext_domain_set_vpt_align"
+
+external domain_send_s3resume: Xc.handle -> Xc.domid -> unit = 
"stub_xcext_domain_send_s3resume"
+external domain_get_acpi_s_state: Xc.handle -> Xc.domid -> int = 
"stub_xcext_domain_get_acpi_s_state"
+
+external domain_trigger_power: Xc.handle -> Xc.domid -> unit = 
"stub_xcext_domain_trigger_power"
+external domain_trigger_sleep: Xc.handle -> Xc.domid -> unit = 
"stub_xcext_domain_trigger_sleep"
+
+(** check if some hvm domain got pv driver or not *)
+external hvm_check_pvdriver: Xc.handle -> Xc.domid -> bool
+       = "stub_xcext_hvm_check_pvdriver"
+
+external get_boot_cpufeatures: Xc.handle ->
+       (int32 * int32 * int32 * int32 * int32 * int32 * int32 * int32) = 
"stub_xcext_get_boot_cpufeatures"
diff -r b4ef59ed08a9 -r cc5f6f7e18cf xcext/xcext.mli
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/xcext/xcext.mli   Tue Dec 07 09:18:49 2010 -0500
@@ -0,0 +1,55 @@
+(*
+ * Copyright (C) 2006-2010 Citrix Systems Inc.
+ *
+ * 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.
+ *)
+
+type runstateinfo = {
+  state : int32;
+  missed_changes: int32;
+  state_entry_time : int64;
+  time0 : int64;
+  time1 : int64;
+  time2 : int64;
+  time3 : int64;
+  time4 : int64;
+  time5 : int64;
+}
+
+external domain_setvmxassist: Xc.handle -> Xc.domid -> bool -> unit
+  = "stub_xcext_domain_setvmxassist"
+
+external domain_get_runstate_info : Xc.handle -> int -> runstateinfo
+  = "stub_xcext_get_runstate_info"
+
+external domain_set_timer_mode: Xc.handle -> Xc.domid -> int -> unit = 
"stub_xcext_domain_set_timer_mode"
+external domain_set_hpet: Xc.handle -> Xc.domid -> int -> unit = 
"stub_xcext_domain_set_hpet"
+external domain_set_vpt_align: Xc.handle -> Xc.domid -> int -> unit = 
"stub_xcext_domain_set_vpt_align"
+
+external domain_send_s3resume: Xc.handle -> Xc.domid -> unit
+  = "stub_xcext_domain_send_s3resume"
+external domain_get_acpi_s_state: Xc.handle -> Xc.domid -> int
+  = "stub_xcext_domain_get_acpi_s_state"
+
+external domain_trigger_power: Xc.handle -> Xc.domid -> unit
+  = "stub_xcext_domain_trigger_power"
+external domain_trigger_sleep: Xc.handle -> Xc.domid -> unit
+  = "stub_xcext_domain_trigger_sleep"
+
+external hvm_check_pvdriver : Xc.handle -> Xc.domid -> bool
+  = "stub_xcext_hvm_check_pvdriver"
+
+external domain_suppress_spurious_page_faults: Xc.handle -> Xc.domid -> unit
+       = "stub_xcext_domain_suppress_spurious_page_faults"
+
+external get_boot_cpufeatures: Xc.handle ->
+       (int32 * int32 * int32 * int32 * int32 * int32 * int32 * int32) = 
"stub_xcext_get_boot_cpufeatures"
+
diff -r b4ef59ed08a9 -r cc5f6f7e18cf xcext/xcext_lib.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/xcext/xcext_lib.c Tue Dec 07 09:18:49 2010 -0500
@@ -0,0 +1,372 @@
+/*
+ * Copyright (C) 2006-2009 Citrix Systems Inc.
+ *
+ * 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 <stdint.h>
+#include <unistd.h>
+#include <string.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <errno.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdlib.h>
+#include <stdarg.h>
+
+#include "xcext.h"
+
+#define PAGE_SHIFT             12
+#define PAGE_SIZE               (1UL << PAGE_SHIFT)
+#define PAGE_MASK               (~(PAGE_SIZE-1))
+
+#define MIN(a, b)              (((a) < (b)) ? (a) : (b))
+
+#define DECLARE_DOMCTL(_cmd, _domain)  \
+       struct xen_domctl domctl = {    \
+               .cmd = _cmd,            \
+               .domain = _domain,      \
+               .interface_version = XEN_DOMCTL_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,                     \
+               .arg[0] = (unsigned long) _arg0,\
+               .arg[1] = (unsigned long) _arg1,\
+       }
+#define DECLARE_HYPERCALL0(_cmd)       DECLARE_HYPERCALL2(_cmd, 0, 0);
+#define DECLARE_HYPERCALL1(_cmd, _arg0)        DECLARE_HYPERCALL2(_cmd, _arg0, 
0);
+
+/*---- Errors handlings ----*/
+#ifndef WITHOUT_GOOD_ERROR
+#define ERROR_STRLEN 256
+
+static char __error_str[ERROR_STRLEN];
+
+char * xcext_error_get(void)
+{
+       return __error_str;
+}
+
+static void xcext_error_set(const char *fmt, ...)
+{
+       va_list ap;
+       char __errordup[ERROR_STRLEN];
+
+       va_start(ap, fmt);
+       vsnprintf(__errordup, ERROR_STRLEN, fmt, ap);
+       va_end(ap);
+       memcpy(__error_str, __errordup, ERROR_STRLEN);
+}
+
+static void xcext_error_dom_set(unsigned int domid, const char *fmt, ...)
+{
+       va_list ap;
+       char __errordup[ERROR_STRLEN];
+       int i;
+
+       i = snprintf(__errordup, ERROR_STRLEN, "domain %u - ", domid);
+       va_start(ap, fmt);
+       i += vsnprintf(__errordup + i, ERROR_STRLEN - i, fmt, ap);
+       va_end(ap);
+       snprintf(__errordup + i, ERROR_STRLEN - i,
+                " failed: %s", xcext_error_get());
+       memcpy(__error_str, __errordup, ERROR_STRLEN);
+}
+
+void xcext_error_clear(void)
+{
+       memset(__error_str, '\0', ERROR_STRLEN);
+}
+#else
+char * xcext_error_get(void)
+{
+       return "";
+}
+#define xcext_error_set(fmt, ...) do {} while (0)
+#define xcext_error_dom_set(id, fmt, ...) do {} while (0)
+#define xcext_error_clear() do {} while (0)
+#endif
+
+#define xcext_error_hypercall(_h, _r) \
+       xcext_error_set("hypercall %lld fail: %d: %s (ret %d)", _h.op, errno, 
errno ? strerror(errno) : strerror(-_r), _r)
+
+#define WITH_INJECTION_CAPABILITY
+#include "../xc/xc_lib_injection.c"
+
+
+/*---- Low private operations ----*/
+static int do_xen_hypercall(int handle, privcmd_hypercall_t *hypercall)
+{
+       pre_xen_hypercall(handle, hypercall);
+       return ioctl(handle, IOCTL_PRIVCMD_HYPERCALL, (unsigned long) 
hypercall);
+}
+
+static int do_domctl(int handle, struct xen_domctl *domctl)
+{
+       int ret;
+       DECLARE_HYPERCALL1(__HYPERVISOR_domctl, domctl);
+
+       if (mlock(domctl, sizeof(*domctl)) != 0) {
+               xcext_error_set("mlock failed: %s", strerror(errno));
+               return -1;
+       }
+
+       ret = do_xen_hypercall(handle, &hypercall);
+       if (ret < 0)
+               xcext_error_hypercall(hypercall, ret);
+
+       munlock(domctl, sizeof(*domctl));
+       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) {
+               xcext_error_set("mlock failed: %s", strerror(errno));
+               return -1;
+       }
+
+       ret = do_xen_hypercall(handle, &hypercall);
+       if (ret < 0)
+               xcext_error_hypercall(hypercall, ret);
+
+       munlock(platform, sizeof(*platform));
+       return ret;
+}
+
+int xcext_get_hvm_param(int handle, unsigned int domid,
+                     int param, unsigned long *value)
+{
+       struct xen_hvm_param arg = {
+               .domid = domid,
+               .index = param,
+       };
+       DECLARE_HYPERCALL2(__HYPERVISOR_hvm_op, HVMOP_get_param,
+                          (unsigned long) &arg);
+       int ret;
+
+       if (mlock(&arg, sizeof(arg)) == -1) {
+               xcext_error_set("mlock failed: %s", strerror(errno));
+               return -1;
+       }
+
+       ret = do_xen_hypercall(handle, &hypercall);
+       if (ret)
+               xcext_error_hypercall(hypercall, ret);
+       *value = arg.value;
+       munlock(&arg, sizeof(arg));
+       return ret;
+}
+
+/* return 1 if hvm domain got pv driver, 0 if not. -1 is error occurs */
+int xcext_hvm_check_pvdriver(int handle, unsigned int domid)
+{
+       int ret;
+       unsigned long irq = 0;
+
+       ret = xcext_get_hvm_param(handle, domid, HVM_PARAM_CALLBACK_IRQ, &irq);
+       if (!ret) {
+               xcext_error_dom_set(domid, "hvm_check_pvdriver");
+               return -1;
+       }
+       return irq;
+}
+
+int xcext_domain_setvmxassist(int handle, unsigned int domid, int 
use_vmxassist)
+{
+       int ret = 0;
+#ifdef XEN_DOMCTL_setvmxassist
+       DECLARE_DOMCTL(XEN_DOMCTL_setvmxassist, domid);
+       domctl.u.setvmxassist.use_vmxassist = use_vmxassist;
+
+       ret = do_domctl(handle, &domctl);
+       if (ret)
+               xcext_error_dom_set(domid, "setting vmxassist to %d",
+                                use_vmxassist);
+#endif
+       return ret;
+}
+
+
+int xcext_get_runstate_info(int handle, unsigned int domid,
+                        xc_runstate_info_t *info)
+{
+       int ret = -EBADF;
+#ifdef XEN_DOMCTL_get_runstate_info
+       DECLARE_DOMCTL(XEN_DOMCTL_get_runstate_info, domid);
+       ret = do_domctl(handle, &domctl);
+       if (ret < 0) {
+               xcext_error_dom_set(domid, "get runstate info");
+               return ret;
+       }
+       memcpy(info, &domctl.u.domain_runstate, sizeof(*info));
+#endif
+       return ret;
+}
+
+
+#ifndef HVM_PARAM_HPET_ENABLED
+#define HVM_PARAM_HPET_ENABLED 11
+#endif
+
+#ifndef HVM_PARAM_ACPI_S_STATE
+#define HVM_PARAM_ACPI_S_STATE 14
+#endif
+
+#ifndef HVM_PARAM_VPT_ALIGN
+#define HVM_PARAM_VPT_ALIGN 16
+#endif
+
+static int xcext_set_hvm_param(int handle, unsigned int domid,
+                              int param, unsigned long value)
+{
+       struct xen_hvm_param arg = {
+               .domid = domid,
+               .index = param,
+               .value = value,
+       };
+       DECLARE_HYPERCALL2(__HYPERVISOR_hvm_op, HVMOP_set_param, (unsigned 
long) &arg);
+       int ret;
+
+       if (mlock(&arg, sizeof(arg)) == -1) {
+               xcext_error_set("mlock failed: %s", strerror(errno));
+               return -1;
+       }
+
+       ret = do_xen_hypercall(handle, &hypercall);
+       if (ret)
+               xcext_error_hypercall(hypercall, ret);
+       munlock(&arg, sizeof(arg));
+       return ret;
+}
+
+int xcext_domain_send_s3resume(int handle, unsigned int domid)
+{
+       #define HVM_PARAM_ACPI_S_STATE 14
+       return xcext_set_hvm_param(handle, domid, HVM_PARAM_ACPI_S_STATE, 0);
+}
+
+int xcext_domain_set_timer_mode(int handle, unsigned int domid, int mode)
+{
+       return xcext_set_hvm_param(handle, domid,
+                               HVM_PARAM_TIMER_MODE, (unsigned long) mode);
+}
+
+int xcext_domain_set_hpet(int handle, unsigned int domid, int hpet)
+{
+       return xcext_set_hvm_param(handle, domid, HVM_PARAM_HPET_ENABLED, 
(unsigned long) hpet);
+}
+
+int xcext_domain_set_vpt_align(int handle, unsigned int domid, int vpt_align)
+{
+       return xcext_set_hvm_param(handle, domid, HVM_PARAM_HPET_ENABLED, 
(unsigned long) vpt_align);
+}
+
+int xcext_domain_get_acpi_s_state(int handle, unsigned int domid)
+{
+       int ret;
+       unsigned long value;
+
+       ret = xcext_get_hvm_param(handle, domid, HVM_PARAM_ACPI_S_STATE, 
&value);
+       if (ret != 0)
+               xcext_error_dom_set(domid, "get acpi s-state");
+       return value;
+}
+
+int xcext_domain_suppress_spurious_page_faults(int xc, uint32_t domid)
+{
+       int rc = 0;
+#ifdef XEN_DOMCTL_suppress_spurious_page_faults
+       DECLARE_DOMCTL(XEN_DOMCTL_suppress_spurious_page_faults, domid);
+
+       rc = do_domctl(xc, &domctl);
+       if (rc != 0)
+               xcext_error_dom_set(domid, "suppress spurious page faults");
+#endif
+       return rc;
+}
+
+int xcext_domain_trigger_power(int handle, unsigned int domid)
+{
+    int ret;
+
+    DECLARE_DOMCTL(XEN_DOMCTL_sendtrigger, domid);
+    domctl.u.sendtrigger.trigger = XEN_DOMCTL_SENDTRIGGER_POWER;
+
+       ret = do_domctl(handle, &domctl);
+       if (ret != 0)
+               xcext_error_set("power button failed: %s", xcext_error_get());
+    return ret;
+}
+
+int xcext_domain_trigger_sleep(int handle, unsigned int domid)
+{
+    int ret;
+
+    DECLARE_DOMCTL(XEN_DOMCTL_sendtrigger, domid);
+    domctl.u.sendtrigger.trigger = XEN_DOMCTL_SENDTRIGGER_SLEEP;
+
+       ret = do_domctl(handle, &domctl);
+       if (ret != 0)
+               xcext_error_set("sleep button failed: %s", xcext_error_get());
+    return ret;
+}
+
+int xcext_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)
+               xcext_error_set("getting boot cpu features failed: %s", 
xcext_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
+ *  c-basic-offset: 8
+ *  tab-width: 8
+ * End:
+ */
diff -r b4ef59ed08a9 -r cc5f6f7e18cf xcext/xcext_stubs.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/xcext/xcext_stubs.c       Tue Dec 07 09:18:49 2010 -0500
@@ -0,0 +1,210 @@
+/*
+ * Copyright (C) 2006-2010 Citrix Systems Inc.
+ *
+ * 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.
+ */
+
+#define _XOPEN_SOURCE 600
+#include <stdlib.h>
+
+#define CAML_NAME_SPACE
+#include <caml/alloc.h>
+#include <caml/memory.h>
+#include <caml/signals.h>
+#include <caml/fail.h>
+#include <caml/callback.h>
+
+#include <sys/mman.h>
+#include <stdint.h>
+#include <string.h>
+
+#include "xcext.h"
+
+#define _H(__h) (Int_val(__h))
+#define _D(__d) ((uint32_t)Int_val(__d))
+
+void failwith_xcext(void)
+{
+       caml_raise_with_string(*caml_named_value("xc.error"), 
xcext_error_get());
+}
+
+CAMLprim value stub_xcext_domain_setvmxassist(value xc_handle, value domid,
+                                           value use_vmxassist)
+{
+       CAMLparam3(xc_handle, domid, use_vmxassist);
+       int r;
+
+       r = xcext_domain_setvmxassist(_H(xc_handle), _D(domid),
+                                  Bool_val(use_vmxassist));
+       if (r)
+               failwith_xcext();
+
+       CAMLreturn(Val_unit);
+}
+
+CAMLprim value stub_xcext_get_runstate_info(value xc_handle, value domid) {
+
+       CAMLparam2(xc_handle, domid);
+       CAMLlocal1(result);
+       xc_runstate_info_t info;
+       int retval;
+
+       int c_xc_handle = _H(xc_handle);
+       uint32_t c_domid = _D(domid);
+       retval = xcext_get_runstate_info(c_xc_handle, c_domid, &info);
+       if (retval < 0)
+               failwith_xcext();
+
+       /* Store
+          0 : state (int32)
+          1 : missed_changes (int32)
+          2 : state_entry_time (int64)
+          3-8 : times (int64s)
+       */
+       result = caml_alloc_tuple(9);
+       Store_field(result, 0, caml_copy_int32(info.state));
+       Store_field(result, 1, caml_copy_int32(info.missed_changes));
+       Store_field(result, 2, caml_copy_int64(info.state_entry_time));
+       Store_field(result, 3, caml_copy_int64(info.time[0]));
+       Store_field(result, 4, caml_copy_int64(info.time[1]));
+       Store_field(result, 5, caml_copy_int64(info.time[2]));
+       Store_field(result, 6, caml_copy_int64(info.time[3]));
+       Store_field(result, 7, caml_copy_int64(info.time[4]));
+       Store_field(result, 8, caml_copy_int64(info.time[5]));
+
+       CAMLreturn(result);
+}
+
+CAMLprim value stub_xcext_domain_suppress_spurious_page_faults(value xc_handle,
+                                                      value domid)
+{
+       CAMLparam2(xc_handle, domid);
+       int c_xc_handle = _H(xc_handle);
+       uint32_t c_domid = _D(domid);
+
+       int retval = xcext_domain_suppress_spurious_page_faults(c_xc_handle, 
c_domid);
+       if (retval)
+               failwith_xcext();
+       CAMLreturn(Val_unit);
+}
+
+
+CAMLprim value stub_xcext_hvm_check_pvdriver(value xc_handle, value domid)
+{
+       CAMLparam2(xc_handle, domid);
+       int ret;
+
+       ret = xcext_hvm_check_pvdriver(_H(xc_handle), _D(domid));
+       if (ret < 0)
+               failwith_xcext();
+       CAMLreturn(Val_bool(ret));
+}
+
+
+CAMLprim value stub_xcext_domain_get_acpi_s_state(value handle, value domid)
+{
+       CAMLparam2(handle, domid);
+       int ret;
+
+       ret = xcext_domain_get_acpi_s_state(_H(handle), _D(domid));
+       if (ret < 0)
+               failwith_xc();
+
+       CAMLreturn(Val_int(ret));
+}
+
+
+CAMLprim value stub_xcext_domain_send_s3resume(value handle, value domid)
+{
+       CAMLparam2(handle, domid);
+       xcext_domain_send_s3resume(_H(handle), _D(domid));
+       CAMLreturn(Val_unit);
+}
+
+
+CAMLprim value stub_xcext_domain_set_timer_mode(value handle, value id, value 
mode)
+{
+       CAMLparam3(handle, id, mode);
+       int ret;
+
+       ret = xcext_domain_set_timer_mode(_H(handle), _D(id), Int_val(mode));
+       if (ret < 0)
+               failwith_xcext();
+       CAMLreturn(Val_unit);
+}
+
+CAMLprim value stub_xcext_domain_set_hpet(value handle, value id, value mode)
+{
+       CAMLparam3(handle, id, mode);
+       int ret;
+
+       ret = xcext_domain_set_hpet(_H(handle), _D(id), Int_val(mode));
+       if (ret < 0)
+               failwith_xcext();
+       CAMLreturn(Val_unit);
+}
+
+CAMLprim value stub_xcext_domain_set_vpt_align(value handle, value id, value 
mode)
+{
+       CAMLparam3(handle, id, mode);
+       int ret;
+
+       ret = xcext_domain_set_vpt_align(_H(handle), _D(id), Int_val(mode));
+       if (ret < 0)
+               failwith_xcext();
+       CAMLreturn(Val_unit);
+}
+
+CAMLprim value stub_xcext_domain_trigger_power(value handle, value domid)
+{
+       CAMLparam2(handle, domid);
+       xcext_domain_trigger_power(_H(handle), _D(domid));
+       CAMLreturn(Val_unit);
+}
+
+CAMLprim value stub_xcext_domain_trigger_sleep(value handle, value domid)
+{
+       CAMLparam2(handle, domid);
+       xcext_domain_trigger_sleep(_H(handle), _D(domid));
+       CAMLreturn(Val_unit);
+}
+
+CAMLprim value stub_xcext_get_boot_cpufeatures(value handle)
+{
+       CAMLparam1(handle);
+       CAMLlocal1(v);
+       uint32_t a, b, c, d, e, f, g, h;
+       int ret;
+
+       ret = xcext_get_boot_cpufeatures(_H(handle), &a, &b, &c, &d, &e, &f, 
&g, &h);
+       if (ret < 0)
+               failwith_xcext();
+
+       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
+ *  c-basic-offset: 8
+ *  tab-width: 8
+ * End:
+ */

_______________________________________________
xen-api mailing list
xen-api@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/mailman/listinfo/xen-api

<Prev in Thread] Current Thread [Next in Thread>