1843e1988Sjohnlev /****************************************************************************** 2843e1988Sjohnlev * vcpu.h 3843e1988Sjohnlev * 4843e1988Sjohnlev * VCPU initialisation, query, and hotplug. 5843e1988Sjohnlev * 6843e1988Sjohnlev * Permission is hereby granted, free of charge, to any person obtaining a copy 7843e1988Sjohnlev * of this software and associated documentation files (the "Software"), to 8843e1988Sjohnlev * deal in the Software without restriction, including without limitation the 9843e1988Sjohnlev * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10843e1988Sjohnlev * sell copies of the Software, and to permit persons to whom the Software is 11843e1988Sjohnlev * furnished to do so, subject to the following conditions: 12843e1988Sjohnlev * 13843e1988Sjohnlev * The above copyright notice and this permission notice shall be included in 14843e1988Sjohnlev * all copies or substantial portions of the Software. 15843e1988Sjohnlev * 16843e1988Sjohnlev * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17843e1988Sjohnlev * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18843e1988Sjohnlev * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19843e1988Sjohnlev * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20843e1988Sjohnlev * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21843e1988Sjohnlev * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22843e1988Sjohnlev * DEALINGS IN THE SOFTWARE. 23843e1988Sjohnlev * 24843e1988Sjohnlev * Copyright (c) 2005, Keir Fraser <keir@xensource.com> 25843e1988Sjohnlev */ 26843e1988Sjohnlev 27843e1988Sjohnlev #ifndef __XEN_PUBLIC_VCPU_H__ 28843e1988Sjohnlev #define __XEN_PUBLIC_VCPU_H__ 29843e1988Sjohnlev 30843e1988Sjohnlev /* 31843e1988Sjohnlev * Prototype for this hypercall is: 32843e1988Sjohnlev * int vcpu_op(int cmd, int vcpuid, void *extra_args) 33843e1988Sjohnlev * @cmd == VCPUOP_??? (VCPU operation). 34843e1988Sjohnlev * @vcpuid == VCPU to operate on. 35843e1988Sjohnlev * @extra_args == Operation-specific extra arguments (NULL if none). 36843e1988Sjohnlev */ 37843e1988Sjohnlev 38843e1988Sjohnlev /* 39843e1988Sjohnlev * Initialise a VCPU. Each VCPU can be initialised only once. A 40843e1988Sjohnlev * newly-initialised VCPU will not run until it is brought up by VCPUOP_up. 41843e1988Sjohnlev * 42843e1988Sjohnlev * @extra_arg == pointer to vcpu_guest_context structure containing initial 43843e1988Sjohnlev * state for the VCPU. 44843e1988Sjohnlev */ 45843e1988Sjohnlev #define VCPUOP_initialise 0 46843e1988Sjohnlev 47843e1988Sjohnlev /* 48843e1988Sjohnlev * Bring up a VCPU. This makes the VCPU runnable. This operation will fail 49843e1988Sjohnlev * if the VCPU has not been initialised (VCPUOP_initialise). 50843e1988Sjohnlev */ 51843e1988Sjohnlev #define VCPUOP_up 1 52843e1988Sjohnlev 53843e1988Sjohnlev /* 54843e1988Sjohnlev * Bring down a VCPU (i.e., make it non-runnable). 55843e1988Sjohnlev * There are a few caveats that callers should observe: 56843e1988Sjohnlev * 1. This operation may return, and VCPU_is_up may return false, before the 57843e1988Sjohnlev * VCPU stops running (i.e., the command is asynchronous). It is a good 58843e1988Sjohnlev * idea to ensure that the VCPU has entered a non-critical loop before 59843e1988Sjohnlev * bringing it down. Alternatively, this operation is guaranteed 60843e1988Sjohnlev * synchronous if invoked by the VCPU itself. 61843e1988Sjohnlev * 2. After a VCPU is initialised, there is currently no way to drop all its 62843e1988Sjohnlev * references to domain memory. Even a VCPU that is down still holds 63843e1988Sjohnlev * memory references via its pagetable base pointer and GDT. It is good 64843e1988Sjohnlev * practise to move a VCPU onto an 'idle' or default page table, LDT and 65843e1988Sjohnlev * GDT before bringing it down. 66843e1988Sjohnlev */ 67843e1988Sjohnlev #define VCPUOP_down 2 68843e1988Sjohnlev 69843e1988Sjohnlev /* Returns 1 if the given VCPU is up. */ 70843e1988Sjohnlev #define VCPUOP_is_up 3 71843e1988Sjohnlev 72843e1988Sjohnlev /* 73843e1988Sjohnlev * Return information about the state and running time of a VCPU. 74843e1988Sjohnlev * @extra_arg == pointer to vcpu_runstate_info structure. 75843e1988Sjohnlev */ 76843e1988Sjohnlev #define VCPUOP_get_runstate_info 4 77843e1988Sjohnlev struct vcpu_runstate_info { 78843e1988Sjohnlev /* VCPU's current state (RUNSTATE_*). */ 79843e1988Sjohnlev int state; 80843e1988Sjohnlev /* When was current state entered (system time, ns)? */ 81843e1988Sjohnlev uint64_t state_entry_time; 82843e1988Sjohnlev /* 83843e1988Sjohnlev * Time spent in each RUNSTATE_* (ns). The sum of these times is 84843e1988Sjohnlev * guaranteed not to drift from system time. 85843e1988Sjohnlev */ 86843e1988Sjohnlev uint64_t time[4]; 87843e1988Sjohnlev }; 88843e1988Sjohnlev typedef struct vcpu_runstate_info vcpu_runstate_info_t; 89843e1988Sjohnlev DEFINE_XEN_GUEST_HANDLE(vcpu_runstate_info_t); 90843e1988Sjohnlev 91843e1988Sjohnlev /* VCPU is currently running on a physical CPU. */ 92843e1988Sjohnlev #define RUNSTATE_running 0 93843e1988Sjohnlev 94843e1988Sjohnlev /* VCPU is runnable, but not currently scheduled on any physical CPU. */ 95843e1988Sjohnlev #define RUNSTATE_runnable 1 96843e1988Sjohnlev 97843e1988Sjohnlev /* VCPU is blocked (a.k.a. idle). It is therefore not runnable. */ 98843e1988Sjohnlev #define RUNSTATE_blocked 2 99843e1988Sjohnlev 100843e1988Sjohnlev /* 101843e1988Sjohnlev * VCPU is not runnable, but it is not blocked. 102843e1988Sjohnlev * This is a 'catch all' state for things like hotplug and pauses by the 103843e1988Sjohnlev * system administrator (or for critical sections in the hypervisor). 104843e1988Sjohnlev * RUNSTATE_blocked dominates this state (it is the preferred state). 105843e1988Sjohnlev */ 106843e1988Sjohnlev #define RUNSTATE_offline 3 107843e1988Sjohnlev 108843e1988Sjohnlev /* 109843e1988Sjohnlev * Register a shared memory area from which the guest may obtain its own 110843e1988Sjohnlev * runstate information without needing to execute a hypercall. 111843e1988Sjohnlev * Notes: 112843e1988Sjohnlev * 1. The registered address may be virtual or physical or guest handle, 113843e1988Sjohnlev * depending on the platform. Virtual address or guest handle should be 114843e1988Sjohnlev * registered on x86 systems. 115843e1988Sjohnlev * 2. Only one shared area may be registered per VCPU. The shared area is 116843e1988Sjohnlev * updated by the hypervisor each time the VCPU is scheduled. Thus 117843e1988Sjohnlev * runstate.state will always be RUNSTATE_running and 118843e1988Sjohnlev * runstate.state_entry_time will indicate the system time at which the 119843e1988Sjohnlev * VCPU was last scheduled to run. 120843e1988Sjohnlev * @extra_arg == pointer to vcpu_register_runstate_memory_area structure. 121843e1988Sjohnlev */ 122843e1988Sjohnlev #define VCPUOP_register_runstate_memory_area 5 123843e1988Sjohnlev struct vcpu_register_runstate_memory_area { 124843e1988Sjohnlev union { 125843e1988Sjohnlev XEN_GUEST_HANDLE(vcpu_runstate_info_t) h; 126843e1988Sjohnlev struct vcpu_runstate_info *v; 127843e1988Sjohnlev uint64_t p; 128843e1988Sjohnlev } addr; 129843e1988Sjohnlev }; 130843e1988Sjohnlev typedef struct vcpu_register_runstate_memory_area vcpu_register_runstate_memory_area_t; 131a576ab5bSrab DEFINE_XEN_GUEST_HANDLE(vcpu_register_runstate_memory_area_t); 132a576ab5bSrab 133a576ab5bSrab /* 134a576ab5bSrab * Set or stop a VCPU's periodic timer. Every VCPU has one periodic timer 135a576ab5bSrab * which can be set via these commands. Periods smaller than one millisecond 136a576ab5bSrab * may not be supported. 137a576ab5bSrab */ 138a576ab5bSrab #define VCPUOP_set_periodic_timer 6 /* arg == vcpu_set_periodic_timer_t */ 139a576ab5bSrab #define VCPUOP_stop_periodic_timer 7 /* arg == NULL */ 140a576ab5bSrab struct vcpu_set_periodic_timer { 141a576ab5bSrab uint64_t period_ns; 142a576ab5bSrab }; 143a576ab5bSrab typedef struct vcpu_set_periodic_timer vcpu_set_periodic_timer_t; 144a576ab5bSrab DEFINE_XEN_GUEST_HANDLE(vcpu_set_periodic_timer_t); 145a576ab5bSrab 146a576ab5bSrab /* 147a576ab5bSrab * Set or stop a VCPU's single-shot timer. Every VCPU has one single-shot 148a576ab5bSrab * timer which can be set via these commands. 149a576ab5bSrab */ 150a576ab5bSrab #define VCPUOP_set_singleshot_timer 8 /* arg == vcpu_set_singleshot_timer_t */ 151a576ab5bSrab #define VCPUOP_stop_singleshot_timer 9 /* arg == NULL */ 152a576ab5bSrab struct vcpu_set_singleshot_timer { 153a576ab5bSrab uint64_t timeout_abs_ns; /* Absolute system time value in nanoseconds. */ 154a576ab5bSrab uint32_t flags; /* VCPU_SSHOTTMR_??? */ 155a576ab5bSrab }; 156a576ab5bSrab typedef struct vcpu_set_singleshot_timer vcpu_set_singleshot_timer_t; 157a576ab5bSrab DEFINE_XEN_GUEST_HANDLE(vcpu_set_singleshot_timer_t); 158a576ab5bSrab 159a576ab5bSrab /* Flags to VCPUOP_set_singleshot_timer. */ 160a576ab5bSrab /* Require the timeout to be in the future (return -ETIME if it's passed). */ 161a576ab5bSrab #define _VCPU_SSHOTTMR_future (0) 162a576ab5bSrab #define VCPU_SSHOTTMR_future (1U << _VCPU_SSHOTTMR_future) 163a576ab5bSrab 164a576ab5bSrab /* 165a576ab5bSrab * Register a memory location in the guest address space for the 166a576ab5bSrab * vcpu_info structure. This allows the guest to place the vcpu_info 167a576ab5bSrab * structure in a convenient place, such as in a per-cpu data area. 168a576ab5bSrab * The pointer need not be page aligned, but the structure must not 169a576ab5bSrab * cross a page boundary. 170a576ab5bSrab * 171a576ab5bSrab * This may be called only once per vcpu. 172a576ab5bSrab */ 173*349b53ddSStuart Maybee #define VCPUOP_register_vcpu_info 10 /* arg == vcpu_register_vcpu_info_t */ 174a576ab5bSrab struct vcpu_register_vcpu_info { 175a576ab5bSrab uint64_t mfn; /* mfn of page to place vcpu_info */ 176a576ab5bSrab uint32_t offset; /* offset within page */ 177a576ab5bSrab uint32_t rsvd; /* unused */ 178a576ab5bSrab }; 179a576ab5bSrab typedef struct vcpu_register_vcpu_info vcpu_register_vcpu_info_t; 180a576ab5bSrab DEFINE_XEN_GUEST_HANDLE(vcpu_register_vcpu_info_t); 181843e1988Sjohnlev 182*349b53ddSStuart Maybee /* Send an NMI to the specified VCPU. @extra_arg == NULL. */ 183*349b53ddSStuart Maybee #define VCPUOP_send_nmi 11 184*349b53ddSStuart Maybee 185*349b53ddSStuart Maybee /* 186*349b53ddSStuart Maybee * Get the physical ID information for a pinned vcpu's underlying physical 187*349b53ddSStuart Maybee * processor. The physical ID informmation is architecture-specific. 188*349b53ddSStuart Maybee * On x86: id[31:0]=apic_id, id[63:32]=acpi_id, and all values 0xff and 189*349b53ddSStuart Maybee * greater are reserved. 190*349b53ddSStuart Maybee * This command returns -EINVAL if it is not a valid operation for this VCPU. 191*349b53ddSStuart Maybee */ 192*349b53ddSStuart Maybee #define VCPUOP_get_physid 12 /* arg == vcpu_get_physid_t */ 193*349b53ddSStuart Maybee struct vcpu_get_physid { 194*349b53ddSStuart Maybee uint64_t phys_id; 195*349b53ddSStuart Maybee }; 196*349b53ddSStuart Maybee typedef struct vcpu_get_physid vcpu_get_physid_t; 197*349b53ddSStuart Maybee DEFINE_XEN_GUEST_HANDLE(vcpu_get_physid_t); 198*349b53ddSStuart Maybee #define xen_vcpu_physid_to_x86_apicid(physid) \ 199*349b53ddSStuart Maybee ((((uint32_t)(physid)) >= 0xff) ? 0xff : ((uint8_t)(physid))) 200*349b53ddSStuart Maybee #define xen_vcpu_physid_to_x86_acpiid(physid) \ 201*349b53ddSStuart Maybee ((((uint32_t)((physid)>>32)) >= 0xff) ? 0xff : ((uint8_t)((physid)>>32))) 202*349b53ddSStuart Maybee 203843e1988Sjohnlev #endif /* __XEN_PUBLIC_VCPU_H__ */ 204843e1988Sjohnlev 205843e1988Sjohnlev /* 206843e1988Sjohnlev * Local variables: 207843e1988Sjohnlev * mode: C 208843e1988Sjohnlev * c-set-style: "BSD" 209843e1988Sjohnlev * c-basic-offset: 4 210843e1988Sjohnlev * tab-width: 4 211843e1988Sjohnlev * indent-tabs-mode: nil 212843e1988Sjohnlev * End: 213843e1988Sjohnlev */ 214