/* SPDX-License-Identifier: MIT */1/******************************************************************************2* vcpu.h3*4* VCPU initialisation, query, and hotplug.5*6* Copyright (c) 2005, Keir Fraser <[email protected]>7*/89#ifndef __XEN_PUBLIC_VCPU_H__10#define __XEN_PUBLIC_VCPU_H__1112/*13* Prototype for this hypercall is:14* int vcpu_op(int cmd, int vcpuid, void *extra_args)15* @cmd == VCPUOP_??? (VCPU operation).16* @vcpuid == VCPU to operate on.17* @extra_args == Operation-specific extra arguments (NULL if none).18*/1920/*21* Initialise a VCPU. Each VCPU can be initialised only once. A22* newly-initialised VCPU will not run until it is brought up by VCPUOP_up.23*24* @extra_arg == pointer to vcpu_guest_context structure containing initial25* state for the VCPU.26*/27#define VCPUOP_initialise 02829/*30* Bring up a VCPU. This makes the VCPU runnable. This operation will fail31* if the VCPU has not been initialised (VCPUOP_initialise).32*/33#define VCPUOP_up 13435/*36* Bring down a VCPU (i.e., make it non-runnable).37* There are a few caveats that callers should observe:38* 1. This operation may return, and VCPU_is_up may return false, before the39* VCPU stops running (i.e., the command is asynchronous). It is a good40* idea to ensure that the VCPU has entered a non-critical loop before41* bringing it down. Alternatively, this operation is guaranteed42* synchronous if invoked by the VCPU itself.43* 2. After a VCPU is initialised, there is currently no way to drop all its44* references to domain memory. Even a VCPU that is down still holds45* memory references via its pagetable base pointer and GDT. It is good46* practise to move a VCPU onto an 'idle' or default page table, LDT and47* GDT before bringing it down.48*/49#define VCPUOP_down 25051/* Returns 1 if the given VCPU is up. */52#define VCPUOP_is_up 35354/*55* Return information about the state and running time of a VCPU.56* @extra_arg == pointer to vcpu_runstate_info structure.57*/58#define VCPUOP_get_runstate_info 459struct vcpu_runstate_info {60/* VCPU's current state (RUNSTATE_*). */61int state;62/* When was current state entered (system time, ns)? */63uint64_t state_entry_time;64/*65* Update indicator set in state_entry_time:66* When activated via VMASST_TYPE_runstate_update_flag, set during67* updates in guest memory mapped copy of vcpu_runstate_info.68*/69#define XEN_RUNSTATE_UPDATE (1ULL << 63)70/*71* Time spent in each RUNSTATE_* (ns). The sum of these times is72* guaranteed not to drift from system time.73*/74uint64_t time[4];75};76DEFINE_GUEST_HANDLE_STRUCT(vcpu_runstate_info);7778/* VCPU is currently running on a physical CPU. */79#define RUNSTATE_running 08081/* VCPU is runnable, but not currently scheduled on any physical CPU. */82#define RUNSTATE_runnable 18384/* VCPU is blocked (a.k.a. idle). It is therefore not runnable. */85#define RUNSTATE_blocked 28687/*88* VCPU is not runnable, but it is not blocked.89* This is a 'catch all' state for things like hotplug and pauses by the90* system administrator (or for critical sections in the hypervisor).91* RUNSTATE_blocked dominates this state (it is the preferred state).92*/93#define RUNSTATE_offline 39495/*96* Register a shared memory area from which the guest may obtain its own97* runstate information without needing to execute a hypercall.98* Notes:99* 1. The registered address may be virtual or physical, depending on the100* platform. The virtual address should be registered on x86 systems.101* 2. Only one shared area may be registered per VCPU. The shared area is102* updated by the hypervisor each time the VCPU is scheduled. Thus103* runstate.state will always be RUNSTATE_running and104* runstate.state_entry_time will indicate the system time at which the105* VCPU was last scheduled to run.106* @extra_arg == pointer to vcpu_register_runstate_memory_area structure.107*/108#define VCPUOP_register_runstate_memory_area 5109struct vcpu_register_runstate_memory_area {110union {111GUEST_HANDLE(vcpu_runstate_info) h;112struct vcpu_runstate_info *v;113uint64_t p;114} addr;115};116117/*118* Set or stop a VCPU's periodic timer. Every VCPU has one periodic timer119* which can be set via these commands. Periods smaller than one millisecond120* may not be supported.121*/122#define VCPUOP_set_periodic_timer 6 /* arg == vcpu_set_periodic_timer_t */123#define VCPUOP_stop_periodic_timer 7 /* arg == NULL */124struct vcpu_set_periodic_timer {125uint64_t period_ns;126};127DEFINE_GUEST_HANDLE_STRUCT(vcpu_set_periodic_timer);128129/*130* Set or stop a VCPU's single-shot timer. Every VCPU has one single-shot131* timer which can be set via these commands.132*/133#define VCPUOP_set_singleshot_timer 8 /* arg == vcpu_set_singleshot_timer_t */134#define VCPUOP_stop_singleshot_timer 9 /* arg == NULL */135struct vcpu_set_singleshot_timer {136uint64_t timeout_abs_ns;137uint32_t flags; /* VCPU_SSHOTTMR_??? */138};139DEFINE_GUEST_HANDLE_STRUCT(vcpu_set_singleshot_timer);140141/* Flags to VCPUOP_set_singleshot_timer. */142/* Require the timeout to be in the future (return -ETIME if it's passed). */143#define _VCPU_SSHOTTMR_future (0)144#define VCPU_SSHOTTMR_future (1U << _VCPU_SSHOTTMR_future)145146/*147* Register a memory location in the guest address space for the148* vcpu_info structure. This allows the guest to place the vcpu_info149* structure in a convenient place, such as in a per-cpu data area.150* The pointer need not be page aligned, but the structure must not151* cross a page boundary.152*/153#define VCPUOP_register_vcpu_info 10 /* arg == struct vcpu_info */154struct vcpu_register_vcpu_info {155uint64_t mfn; /* mfn of page to place vcpu_info */156uint32_t offset; /* offset within page */157uint32_t rsvd; /* unused */158};159DEFINE_GUEST_HANDLE_STRUCT(vcpu_register_vcpu_info);160161/* Send an NMI to the specified VCPU. @extra_arg == NULL. */162#define VCPUOP_send_nmi 11163164/*165* Get the physical ID information for a pinned vcpu's underlying physical166* processor. The physical ID informmation is architecture-specific.167* On x86: id[31:0]=apic_id, id[63:32]=acpi_id.168* This command returns -EINVAL if it is not a valid operation for this VCPU.169*/170#define VCPUOP_get_physid 12 /* arg == vcpu_get_physid_t */171struct vcpu_get_physid {172uint64_t phys_id;173};174DEFINE_GUEST_HANDLE_STRUCT(vcpu_get_physid);175#define xen_vcpu_physid_to_x86_apicid(physid) ((uint32_t)(physid))176#define xen_vcpu_physid_to_x86_acpiid(physid) ((uint32_t)((physid) >> 32))177178/*179* Register a memory location to get a secondary copy of the vcpu time180* parameters. The master copy still exists as part of the vcpu shared181* memory area, and this secondary copy is updated whenever the master copy182* is updated (and using the same versioning scheme for synchronisation).183*184* The intent is that this copy may be mapped (RO) into userspace so185* that usermode can compute system time using the time info and the186* tsc. Usermode will see an array of vcpu_time_info structures, one187* for each vcpu, and choose the right one by an existing mechanism188* which allows it to get the current vcpu number (such as via a189* segment limit). It can then apply the normal algorithm to compute190* system time from the tsc.191*192* @extra_arg == pointer to vcpu_register_time_info_memory_area structure.193*/194#define VCPUOP_register_vcpu_time_memory_area 13195DEFINE_GUEST_HANDLE_STRUCT(vcpu_time_info);196struct vcpu_register_time_memory_area {197union {198GUEST_HANDLE(vcpu_time_info) h;199struct pvclock_vcpu_time_info *v;200uint64_t p;201} addr;202};203DEFINE_GUEST_HANDLE_STRUCT(vcpu_register_time_memory_area);204205#endif /* __XEN_PUBLIC_VCPU_H__ */206207208