From 1fc49fbb07b816357cd45c2bc5d4d15fdd2ae608 Mon Sep 17 00:00:00 2001 From: Andrew Cooper Date: Wed, 29 Apr 2015 17:50:56 +0100 Subject: [PATCH] Xen ABI bits for HVM guests - HVMOP_get_param - HVM PV Console parameters - Xen CPUID leaves Signed-off-by: Andrew Cooper --- arch/x86/hypercall_page.S | 1 + include/xen/arch-x86/cpuid.h | 49 ++++++++++++++++++++++++++++++++++++ include/xen/arch-x86/xen.h | 2 ++ include/xen/hvm/hvm_op.h | 28 +++++++++++++++++++++ include/xen/hvm/params.h | 21 ++++++++++++++++ include/xen/xen.h | 7 ++++++ include/xtf/hypercall.h | 24 ++++++++++++++++++ 7 files changed, 132 insertions(+) create mode 100644 include/xen/arch-x86/cpuid.h create mode 100644 include/xen/hvm/hvm_op.h create mode 100644 include/xen/hvm/params.h diff --git a/arch/x86/hypercall_page.S b/arch/x86/hypercall_page.S index 5447bc1..81b7a2f 100644 --- a/arch/x86/hypercall_page.S +++ b/arch/x86/hypercall_page.S @@ -12,3 +12,4 @@ GLOBAL(hypercall_page) DECLARE_HYPERCALL(console_io) DECLARE_HYPERCALL(sched_op) DECLARE_HYPERCALL(event_channel_op) +DECLARE_HYPERCALL(hvm_op) diff --git a/include/xen/arch-x86/cpuid.h b/include/xen/arch-x86/cpuid.h new file mode 100644 index 0000000..048cbbe --- /dev/null +++ b/include/xen/arch-x86/cpuid.h @@ -0,0 +1,49 @@ +/* + * Xen x86 public cpuid interface + */ + +#ifndef XEN_PUBLIC_ARCH_X86_CPUID_H +#define XEN_PUBLIC_ARCH_X86_CPUID_H + +/* + * For compatibility with other hypervisor interfaces, the Xen cpuid leaves + * can be found at the first otherwise unused 0x100 aligned boundary starting + * from 0x40000000. + * + * e.g If viridian extensions are enabled for an HVM domain, the Xen cpuid + * leaves will start at 0x40000100 + */ + +#define XEN_CPUID_FIRST_LEAF 0x40000000 + +/* + * Leaf 1 (0x40000x00) + * EAX: Largest Xen-information leaf. All leaves up to an including @EAX + * are supported by the Xen host. + * EBX-EDX: "XenVMMXenVMM" signature, allowing positive identification + * of a Xen host. + */ +#define XEN_CPUID_SIGNATURE_EBX 0x566e6558 /* "XenV" */ +#define XEN_CPUID_SIGNATURE_ECX 0x65584d4d /* "MMXe" */ +#define XEN_CPUID_SIGNATURE_EDX 0x4d4d566e /* "nVMM" */ + +/* + * Leaf 3 (0x40000x02) + * EAX: Number of hypercall transfer pages. This register is always guaranteed + * to specify one hypercall page. + * EBX: Base address of Xen-specific MSRs. + * ECX: Features 1. Unused bits are set to zero. + * EDX: Features 2. Unused bits are set to zero. + */ + +#endif /* XEN_PUBLIC_ARCH_X86_CPUID_H */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/include/xen/arch-x86/xen.h b/include/xen/arch-x86/xen.h index b9e97f8..4ae3b9a 100644 --- a/include/xen/arch-x86/xen.h +++ b/include/xen/arch-x86/xen.h @@ -13,6 +13,8 @@ # error Bad architecture #endif +#include "cpuid.h" + #ifndef __ASSEMBLY__ typedef unsigned long xen_pfn_t; #endif diff --git a/include/xen/hvm/hvm_op.h b/include/xen/hvm/hvm_op.h new file mode 100644 index 0000000..8c240d8 --- /dev/null +++ b/include/xen/hvm/hvm_op.h @@ -0,0 +1,28 @@ +/* + * Xen public hvmop interface + */ + +#ifndef XEN_PUBLIC_HVM_HVM_OP_H +#define XEN_PUBLIC_HVM_HVM_OP_H + +/* Get/set subcommands: extra argument == pointer to xen_hvm_param struct. */ +#define HVMOP_set_param 0 +#define HVMOP_get_param 1 +struct xen_hvm_param { + domid_t domid; + uint32_t index; + uint64_t value; +}; +typedef struct xen_hvm_param xen_hvm_param_t; + +#endif /* XEN_PUBLIC_HVM_HVM_OP_H */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/include/xen/hvm/params.h b/include/xen/hvm/params.h new file mode 100644 index 0000000..101a5c5 --- /dev/null +++ b/include/xen/hvm/params.h @@ -0,0 +1,21 @@ +/* + * Xen public hvm paramter index + */ + +#ifndef XEN_PUBLIC_HVM_PARAMS_H +#define XEN_PUBLIC_HVM_PARAMS_H + +#define HVM_PARAM_CONSOLE_PFN 17 +#define HVM_PARAM_CONSOLE_EVTCHN 18 + +#endif /* XEN_PUBLIC_HVM_PARAMS_H */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/include/xen/xen.h b/include/xen/xen.h index d3e226f..8a2c697 100644 --- a/include/xen/xen.h +++ b/include/xen/xen.h @@ -14,6 +14,13 @@ #define __HYPERVISOR_console_io 18 #define __HYPERVISOR_sched_op 29 #define __HYPERVISOR_event_channel_op 32 +#define __HYPERVISOR_hvm_op 34 + +#ifndef __ASSEMBLY__ +typedef uint16_t domid_t; +#endif + +#define DOMID_SELF (0x7ff0U) /* Commands to HYPERVISOR_console_io */ #define CONSOLEIO_write 0 diff --git a/include/xtf/hypercall.h b/include/xtf/hypercall.h index 6aa8b68..3fc705f 100644 --- a/include/xtf/hypercall.h +++ b/include/xtf/hypercall.h @@ -26,6 +26,8 @@ extern uint8_t hypercall_page[PAGE_SIZE]; #include #include #include +#include +#include /* * Hypercall primatives, compiled for the correct bitness @@ -40,6 +42,11 @@ static inline long hypercall_event_channel_op(unsigned int cmd, void *arg) return HYPERCALL2(long, event_channel_op, cmd, arg); } +static inline long hypercall_hvm_op(unsigned int cmd, void *arg) +{ + return HYPERCALL2(long, hvm_op, cmd, arg); +} + /* * Higher level hypercall helpers */ @@ -63,6 +70,23 @@ static inline int hypercall_evtchn_send(evtchn_port_t port) return hypercall_event_channel_op(EVTCHNOP_send, &port); } +static inline int hvm_set_param(unsigned int idx, uint64_t value) +{ + xen_hvm_param_t p = { .domid = DOMID_SELF, .index = idx, .value = value }; + + return hypercall_hvm_op(HVMOP_set_param, &p); +} + +static inline int hvm_get_param(unsigned int idx, uint64_t *value) +{ + xen_hvm_param_t p = { .domid = DOMID_SELF, .index = idx }; + int rc = hypercall_hvm_op(HVMOP_get_param, &p); + + if ( rc == 0 ) + *value = p.value; + return rc; +} + #endif /* XTF_HYPERCALL_H */ /* -- 2.39.5