xref: /openbmc/qemu/include/hw/xen/interface/vcpu.h (revision d2dfe0b5)
1 /******************************************************************************
2  * vcpu.h
3  *
4  * VCPU initialisation, query, and hotplug.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  * DEALINGS IN THE SOFTWARE.
23  *
24  * Copyright (c) 2005, Keir Fraser <keir@xensource.com>
25  */
26 
27 #ifndef __XEN_PUBLIC_VCPU_H__
28 #define __XEN_PUBLIC_VCPU_H__
29 
30 #include "xen.h"
31 
32 /*
33  * Prototype for this hypercall is:
34  *  long vcpu_op(int cmd, unsigned int vcpuid, void *extra_args)
35  * @cmd        == VCPUOP_??? (VCPU operation).
36  * @vcpuid     == VCPU to operate on.
37  * @extra_args == Operation-specific extra arguments (NULL if none).
38  */
39 
40 /*
41  * Initialise a VCPU. Each VCPU can be initialised only once. A
42  * newly-initialised VCPU will not run until it is brought up by VCPUOP_up.
43  *
44  * @extra_arg == For PV or ARM guests this is a pointer to a vcpu_guest_context
45  *               structure containing the initial state for the VCPU. For x86
46  *               HVM based guests this is a pointer to a vcpu_hvm_context
47  *               structure.
48  */
49 #define VCPUOP_initialise            0
50 
51 /*
52  * Bring up a VCPU. This makes the VCPU runnable. This operation will fail
53  * if the VCPU has not been initialised (VCPUOP_initialise).
54  */
55 #define VCPUOP_up                    1
56 
57 /*
58  * Bring down a VCPU (i.e., make it non-runnable).
59  * There are a few caveats that callers should observe:
60  *  1. This operation may return, and VCPU_is_up may return false, before the
61  *     VCPU stops running (i.e., the command is asynchronous). It is a good
62  *     idea to ensure that the VCPU has entered a non-critical loop before
63  *     bringing it down. Alternatively, this operation is guaranteed
64  *     synchronous if invoked by the VCPU itself.
65  *  2. After a VCPU is initialised, there is currently no way to drop all its
66  *     references to domain memory. Even a VCPU that is down still holds
67  *     memory references via its pagetable base pointer and GDT. It is good
68  *     practise to move a VCPU onto an 'idle' or default page table, LDT and
69  *     GDT before bringing it down.
70  */
71 #define VCPUOP_down                  2
72 
73 /* Returns 1 if the given VCPU is up. */
74 #define VCPUOP_is_up                 3
75 
76 /*
77  * Return information about the state and running time of a VCPU.
78  * @extra_arg == pointer to vcpu_runstate_info structure.
79  */
80 #define VCPUOP_get_runstate_info     4
81 struct vcpu_runstate_info {
82     /* VCPU's current state (RUNSTATE_*). */
83     int      state;
84     /* When was current state entered (system time, ns)? */
85     uint64_t state_entry_time;
86     /*
87      * Update indicator set in state_entry_time:
88      * When activated via VMASST_TYPE_runstate_update_flag, set during
89      * updates in guest memory mapped copy of vcpu_runstate_info.
90      */
91 #define XEN_RUNSTATE_UPDATE          (xen_mk_ullong(1) << 63)
92     /*
93      * Time spent in each RUNSTATE_* (ns). The sum of these times is
94      * guaranteed not to drift from system time.
95      */
96     uint64_t time[4];
97 };
98 typedef struct vcpu_runstate_info vcpu_runstate_info_t;
99 DEFINE_XEN_GUEST_HANDLE(vcpu_runstate_info_t);
100 
101 /* VCPU is currently running on a physical CPU. */
102 #define RUNSTATE_running  0
103 
104 /* VCPU is runnable, but not currently scheduled on any physical CPU. */
105 #define RUNSTATE_runnable 1
106 
107 /* VCPU is blocked (a.k.a. idle). It is therefore not runnable. */
108 #define RUNSTATE_blocked  2
109 
110 /*
111  * VCPU is not runnable, but it is not blocked.
112  * This is a 'catch all' state for things like hotplug and pauses by the
113  * system administrator (or for critical sections in the hypervisor).
114  * RUNSTATE_blocked dominates this state (it is the preferred state).
115  */
116 #define RUNSTATE_offline  3
117 
118 /*
119  * Register a shared memory area from which the guest may obtain its own
120  * runstate information without needing to execute a hypercall.
121  * Notes:
122  *  1. The registered address may be virtual or physical or guest handle,
123  *     depending on the platform. Virtual address or guest handle should be
124  *     registered on x86 systems.
125  *  2. Only one shared area may be registered per VCPU. The shared area is
126  *     updated by the hypervisor each time the VCPU is scheduled. Thus
127  *     runstate.state will always be RUNSTATE_running and
128  *     runstate.state_entry_time will indicate the system time at which the
129  *     VCPU was last scheduled to run.
130  * @extra_arg == pointer to vcpu_register_runstate_memory_area structure.
131  */
132 #define VCPUOP_register_runstate_memory_area 5
133 struct vcpu_register_runstate_memory_area {
134     union {
135         XEN_GUEST_HANDLE(vcpu_runstate_info_t) h;
136         struct vcpu_runstate_info *v;
137         uint64_t p;
138     } addr;
139 };
140 typedef struct vcpu_register_runstate_memory_area vcpu_register_runstate_memory_area_t;
141 DEFINE_XEN_GUEST_HANDLE(vcpu_register_runstate_memory_area_t);
142 
143 /*
144  * Set or stop a VCPU's periodic timer. Every VCPU has one periodic timer
145  * which can be set via these commands. Periods smaller than one millisecond
146  * may not be supported.
147  */
148 #define VCPUOP_set_periodic_timer    6 /* arg == vcpu_set_periodic_timer_t */
149 #define VCPUOP_stop_periodic_timer   7 /* arg == NULL */
150 struct vcpu_set_periodic_timer {
151     uint64_t period_ns;
152 };
153 typedef struct vcpu_set_periodic_timer vcpu_set_periodic_timer_t;
154 DEFINE_XEN_GUEST_HANDLE(vcpu_set_periodic_timer_t);
155 
156 /*
157  * Set or stop a VCPU's single-shot timer. Every VCPU has one single-shot
158  * timer which can be set via these commands.
159  */
160 #define VCPUOP_set_singleshot_timer  8 /* arg == vcpu_set_singleshot_timer_t */
161 #define VCPUOP_stop_singleshot_timer 9 /* arg == NULL */
162 struct vcpu_set_singleshot_timer {
163     uint64_t timeout_abs_ns;   /* Absolute system time value in nanoseconds. */
164     uint32_t flags;            /* VCPU_SSHOTTMR_??? */
165 };
166 typedef struct vcpu_set_singleshot_timer vcpu_set_singleshot_timer_t;
167 DEFINE_XEN_GUEST_HANDLE(vcpu_set_singleshot_timer_t);
168 
169 /* Flags to VCPUOP_set_singleshot_timer. */
170  /* Require the timeout to be in the future (return -ETIME if it's passed). */
171 #define _VCPU_SSHOTTMR_future (0)
172 #define VCPU_SSHOTTMR_future  (1U << _VCPU_SSHOTTMR_future)
173 
174 /*
175  * Register a memory location in the guest address space for the
176  * vcpu_info structure.  This allows the guest to place the vcpu_info
177  * structure in a convenient place, such as in a per-cpu data area.
178  * The pointer need not be page aligned, but the structure must not
179  * cross a page boundary.
180  *
181  * This may be called only once per vcpu.
182  */
183 #define VCPUOP_register_vcpu_info   10  /* arg == vcpu_register_vcpu_info_t */
184 struct vcpu_register_vcpu_info {
185     uint64_t mfn;    /* mfn of page to place vcpu_info */
186     uint32_t offset; /* offset within page */
187     uint32_t rsvd;   /* unused */
188 };
189 typedef struct vcpu_register_vcpu_info vcpu_register_vcpu_info_t;
190 DEFINE_XEN_GUEST_HANDLE(vcpu_register_vcpu_info_t);
191 
192 /* Send an NMI to the specified VCPU. @extra_arg == NULL. */
193 #define VCPUOP_send_nmi             11
194 
195 /*
196  * Get the physical ID information for a pinned vcpu's underlying physical
197  * processor.  The physical ID informmation is architecture-specific.
198  * On x86: id[31:0]=apic_id, id[63:32]=acpi_id.
199  * This command returns -EINVAL if it is not a valid operation for this VCPU.
200  */
201 #define VCPUOP_get_physid           12 /* arg == vcpu_get_physid_t */
202 struct vcpu_get_physid {
203     uint64_t phys_id;
204 };
205 typedef struct vcpu_get_physid vcpu_get_physid_t;
206 DEFINE_XEN_GUEST_HANDLE(vcpu_get_physid_t);
207 #define xen_vcpu_physid_to_x86_apicid(physid) ((uint32_t)(physid))
208 #define xen_vcpu_physid_to_x86_acpiid(physid) ((uint32_t)((physid) >> 32))
209 
210 /*
211  * Register a memory location to get a secondary copy of the vcpu time
212  * parameters.  The master copy still exists as part of the vcpu shared
213  * memory area, and this secondary copy is updated whenever the master copy
214  * is updated (and using the same versioning scheme for synchronisation).
215  *
216  * The intent is that this copy may be mapped (RO) into userspace so
217  * that usermode can compute system time using the time info and the
218  * tsc.  Usermode will see an array of vcpu_time_info structures, one
219  * for each vcpu, and choose the right one by an existing mechanism
220  * which allows it to get the current vcpu number (such as via a
221  * segment limit).  It can then apply the normal algorithm to compute
222  * system time from the tsc.
223  *
224  * @extra_arg == pointer to vcpu_register_time_info_memory_area structure.
225  */
226 #define VCPUOP_register_vcpu_time_memory_area   13
227 DEFINE_XEN_GUEST_HANDLE(vcpu_time_info_t);
228 struct vcpu_register_time_memory_area {
229     union {
230         XEN_GUEST_HANDLE(vcpu_time_info_t) h;
231         struct vcpu_time_info *v;
232         uint64_t p;
233     } addr;
234 };
235 typedef struct vcpu_register_time_memory_area vcpu_register_time_memory_area_t;
236 DEFINE_XEN_GUEST_HANDLE(vcpu_register_time_memory_area_t);
237 
238 #endif /* __XEN_PUBLIC_VCPU_H__ */
239 
240 /*
241  * Local variables:
242  * mode: C
243  * c-file-style: "BSD"
244  * c-basic-offset: 4
245  * tab-width: 4
246  * indent-tabs-mode: nil
247  * End:
248  */
249