Andrew Cooper
2013-Mar-13 15:59 UTC
[PATCH 2 of 4] PoC: libxc+ocaml: add interfaces to manipulate various properties of HVM guests
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1294742832 0 # Node ID b279ec057736ead1d7061f8ec8a29a8676dd56b4 # Parent 59aaebc4ef6422e5ff4a3ad54d05597e646cfc92 PoC: libxc+ocaml: add interfaces to manipulate various properties of HVM guests * set timer mode * set hpet * set vpt align * get ACPI * set/get ACPI S state (allows send s3resume) Taken from xen-api-libs.hg/xc and adjusted for upstream libxc+ocaml. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> Rebased on top of xen-unstable. Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com> diff -r 59aaebc4ef64 -r b279ec057736 tools/libxc/xc_domain.c --- a/tools/libxc/xc_domain.c +++ b/tools/libxc/xc_domain.c @@ -1530,6 +1530,38 @@ int xc_domain_set_virq_handler(xc_interf return do_domctl(xch, &domctl); } +int xc_domain_send_s3resume(xc_interface *xch, unsigned int domid) +{ + return xc_set_hvm_param(xch, domid, HVM_PARAM_ACPI_S_STATE, 0); +} + +int xc_domain_set_timer_mode(xc_interface *xch, unsigned int domid, int mode) +{ + return xc_set_hvm_param(xch, domid, + HVM_PARAM_TIMER_MODE, (unsigned long) mode); +} + +int xc_domain_set_hpet(xc_interface *xch, unsigned int domid, int hpet) +{ + return xc_set_hvm_param(xch, domid, HVM_PARAM_HPET_ENABLED, (unsigned long) hpet); +} + +int xc_domain_set_vpt_align(xc_interface *xch, unsigned int domid, int vpt_align) +{ + return xc_set_hvm_param(xch, domid, HVM_PARAM_HPET_ENABLED, (unsigned long) vpt_align); +} + +int xc_domain_get_acpi_s_state(xc_interface *xch, unsigned int domid) +{ + int ret; + unsigned long value; + + ret = xc_get_hvm_param(xch, domid, HVM_PARAM_ACPI_S_STATE, &value); + if (ret != 0) + ERROR("get acpi s-state"); + return value; +} + /* * Local variables: * mode: C diff -r 59aaebc4ef64 -r b279ec057736 tools/libxc/xenctrl.h --- a/tools/libxc/xenctrl.h +++ b/tools/libxc/xenctrl.h @@ -632,6 +632,12 @@ int xc_domain_hvm_setcontext(xc_interfac uint8_t *hvm_ctxt, uint32_t size); +int xc_domain_send_s3resume(xc_interface *xch, unsigned int domid); +int xc_domain_set_timer_mode(xc_interface *xch, unsigned int domid, int mode); +int xc_domain_set_hpet(xc_interface *xch, unsigned int domid, int hpet); +int xc_domain_set_vpt_align(xc_interface *xch, unsigned int domid, int vpt_align); +int xc_domain_get_acpi_s_state(xc_interface *xch, unsigned int domid); + /** * This function returns information about the execution context of a * particular vcpu of a domain. diff -r 59aaebc4ef64 -r b279ec057736 tools/ocaml/libs/xc/xenctrl.ml --- a/tools/ocaml/libs/xc/xenctrl.ml +++ b/tools/ocaml/libs/xc/xenctrl.ml @@ -237,6 +237,13 @@ 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" + (** check if some hvm domain got pv driver or not *) external hvm_check_pvdriver: handle -> domid -> bool = "stub_xc_hvm_check_pvdriver" diff -r 59aaebc4ef64 -r b279ec057736 tools/ocaml/libs/xc/xenctrl.mli --- a/tools/ocaml/libs/xc/xenctrl.mli +++ b/tools/ocaml/libs/xc/xenctrl.mli @@ -142,6 +142,14 @@ 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 hvm_check_pvdriver : handle -> domid -> bool = "stub_xc_hvm_check_pvdriver" external version : handle -> version = "stub_xc_version_version" diff -r 59aaebc4ef64 -r b279ec057736 tools/ocaml/libs/xc/xenctrl_stubs.c --- a/tools/ocaml/libs/xc/xenctrl_stubs.c +++ b/tools/ocaml/libs/xc/xenctrl_stubs.c @@ -1194,6 +1194,59 @@ CAMLprim value stub_xc_watchdog(value xc CAMLreturn(Val_int(ret)); } +CAMLprim value stub_xc_domain_get_acpi_s_state(value xch, value domid) +{ + CAMLparam2(xch, domid); + int ret; + + ret = xc_domain_get_acpi_s_state(_H(xch), _D(domid)); + if (ret < 0) + failwith_xc(_H(xch)); + + CAMLreturn(Val_int(ret)); +} + +CAMLprim value stub_xc_domain_send_s3resume(value xch, value domid) +{ + CAMLparam2(xch, domid); + xc_domain_send_s3resume(_H(xch), _D(domid)); + CAMLreturn(Val_unit); +} + + +CAMLprim value stub_xc_domain_set_timer_mode(value xch, value id, value mode) +{ + CAMLparam3(xch, id, mode); + int ret; + + ret = xc_domain_set_timer_mode(_H(xch), _D(id), Int_val(mode)); + if (ret < 0) + failwith_xc(_H(xch)); + CAMLreturn(Val_unit); +} + +CAMLprim value stub_xc_domain_set_hpet(value xch, value id, value mode) +{ + CAMLparam3(xch, id, mode); + int ret; + + ret = xc_domain_set_hpet(_H(xch), _D(id), Int_val(mode)); + if (ret < 0) + failwith_xc(_H(xch)); + CAMLreturn(Val_unit); +} + +CAMLprim value stub_xc_domain_set_vpt_align(value xch, value id, value mode) +{ + CAMLparam3(xch, id, mode); + int ret; + + ret = xc_domain_set_vpt_align(_H(xch), _D(id), Int_val(mode)); + if (ret < 0) + failwith_xc(_H(xch)); + CAMLreturn(Val_unit); +} + /* * Local variables: * indent-tabs-mode: t