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