TianoCore EDK2 master
Loading...
Searching...
No Matches
xen.h
1/******************************************************************************
2 * xen.h
3 *
4 * Guest OS interface to Xen.
5 *
6 * SPDX-License-Identifier: MIT
7 *
8 * Copyright (c) 2004, K A Fraser
9 */
10
11#ifndef __XEN_PUBLIC_XEN_H__
12#define __XEN_PUBLIC_XEN_H__
13
14//
15// Xen interface version used by Tianocore
16//
17#define __XEN_INTERFACE_VERSION__ 0x00040400
18
19#include "xen-compat.h"
20
21#if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)
22 #include "arch-x86/xen.h"
23#elif defined (__arm__) || defined (__aarch64__)
24 #include "arch-arm/xen.h"
25#else
26 #error "Unsupported architecture"
27#endif
28
29#ifndef __ASSEMBLY__
30/* Guest handles for primitive C types. */
31DEFINE_XEN_GUEST_HANDLE (CHAR8);
32__DEFINE_XEN_GUEST_HANDLE (uchar, UINT8);
33DEFINE_XEN_GUEST_HANDLE (INT32);
34__DEFINE_XEN_GUEST_HANDLE (uint, UINT32);
35 #if __XEN_INTERFACE_VERSION__ < 0x00040300
36DEFINE_XEN_GUEST_HANDLE (INTN);
37__DEFINE_XEN_GUEST_HANDLE (ulong, UINTN);
38 #endif
39DEFINE_XEN_GUEST_HANDLE (VOID);
40
41DEFINE_XEN_GUEST_HANDLE (UINT64);
42DEFINE_XEN_GUEST_HANDLE (xen_pfn_t);
43DEFINE_XEN_GUEST_HANDLE (xen_ulong_t);
44#endif
45
46/*
47 * HYPERCALLS
48 */
49
50/* `incontents 100 hcalls List of hypercalls
51 * ` enum hypercall_num { // __HYPERVISOR_* => HYPERVISOR_*()
52 */
53
54#define __HYPERVISOR_set_trap_table 0
55#define __HYPERVISOR_mmu_update 1
56#define __HYPERVISOR_set_gdt 2
57#define __HYPERVISOR_stack_switch 3
58#define __HYPERVISOR_set_callbacks 4
59#define __HYPERVISOR_fpu_taskswitch 5
60#define __HYPERVISOR_sched_op_compat 6/* compat since 0x00030101 */
61#define __HYPERVISOR_platform_op 7
62#define __HYPERVISOR_set_debugreg 8
63#define __HYPERVISOR_get_debugreg 9
64#define __HYPERVISOR_update_descriptor 10
65#define __HYPERVISOR_memory_op 12
66#define __HYPERVISOR_multicall 13
67#define __HYPERVISOR_update_va_mapping 14
68#define __HYPERVISOR_set_timer_op 15
69#define __HYPERVISOR_event_channel_op_compat 16/* compat since 0x00030202 */
70#define __HYPERVISOR_xen_version 17
71#define __HYPERVISOR_console_io 18
72#define __HYPERVISOR_physdev_op_compat 19/* compat since 0x00030202 */
73#define __HYPERVISOR_grant_table_op 20
74#define __HYPERVISOR_vm_assist 21
75#define __HYPERVISOR_update_va_mapping_otherdomain 22
76#define __HYPERVISOR_iret 23/* x86 only */
77#define __HYPERVISOR_vcpu_op 24
78#define __HYPERVISOR_set_segment_base 25/* x86/64 only */
79#define __HYPERVISOR_mmuext_op 26
80#define __HYPERVISOR_xsm_op 27
81#define __HYPERVISOR_nmi_op 28
82#define __HYPERVISOR_sched_op 29
83#define __HYPERVISOR_callback_op 30
84#define __HYPERVISOR_xenoprof_op 31
85#define __HYPERVISOR_event_channel_op 32
86#define __HYPERVISOR_physdev_op 33
87#define __HYPERVISOR_hvm_op 34
88#define __HYPERVISOR_sysctl 35
89#define __HYPERVISOR_domctl 36
90#define __HYPERVISOR_kexec_op 37
91#define __HYPERVISOR_tmem_op 38
92#define __HYPERVISOR_xc_reserved_op 39/* reserved for XenClient */
93
94/* Architecture-specific hypercall definitions. */
95#define __HYPERVISOR_arch_0 48
96#define __HYPERVISOR_arch_1 49
97#define __HYPERVISOR_arch_2 50
98#define __HYPERVISOR_arch_3 51
99#define __HYPERVISOR_arch_4 52
100#define __HYPERVISOR_arch_5 53
101#define __HYPERVISOR_arch_6 54
102#define __HYPERVISOR_arch_7 55
103
104/* ` } */
105
106/*
107 * HYPERCALL COMPATIBILITY.
108 */
109
110/* New sched_op hypercall introduced in 0x00030101. */
111#if __XEN_INTERFACE_VERSION__ < 0x00030101
112 #undef __HYPERVISOR_sched_op
113#define __HYPERVISOR_sched_op __HYPERVISOR_sched_op_compat
114#endif
115
116/* New event-channel and physdev hypercalls introduced in 0x00030202. */
117#if __XEN_INTERFACE_VERSION__ < 0x00030202
118 #undef __HYPERVISOR_event_channel_op
119#define __HYPERVISOR_event_channel_op __HYPERVISOR_event_channel_op_compat
120 #undef __HYPERVISOR_physdev_op
121#define __HYPERVISOR_physdev_op __HYPERVISOR_physdev_op_compat
122#endif
123
124/* New platform_op hypercall introduced in 0x00030204. */
125#if __XEN_INTERFACE_VERSION__ < 0x00030204
126#define __HYPERVISOR_dom0_op __HYPERVISOR_platform_op
127#endif
128
129#ifndef __ASSEMBLY__
130
131typedef UINT16 domid_t;
132
133/* Domain ids >= DOMID_FIRST_RESERVED cannot be used for ordinary domains. */
134#define DOMID_FIRST_RESERVED (0x7FF0U)
135
136/* DOMID_SELF is used in certain contexts to refer to oneself. */
137#define DOMID_SELF (0x7FF0U)
138
139/*
140 * DOMID_IO is used to restrict page-table updates to mapping I/O memory.
141 * Although no Foreign Domain need be specified to map I/O pages, DOMID_IO
142 * is useful to ensure that no mappings to the OS's own heap are accidentally
143 * installed. (e.g., in Linux this could cause havoc as reference counts
144 * aren't adjusted on the I/O-mapping code path).
145 * This only makes sense in MMUEXT_SET_FOREIGNDOM, but in that context can
146 * be specified by any calling domain.
147 */
148#define DOMID_IO (0x7FF1U)
149
150/*
151 * DOMID_XEN is used to allow privileged domains to map restricted parts of
152 * Xen's heap space (e.g., the machine_to_phys table).
153 * This only makes sense in MMUEXT_SET_FOREIGNDOM, and is only permitted if
154 * the caller is privileged.
155 */
156#define DOMID_XEN (0x7FF2U)
157
158/*
159 * DOMID_COW is used as the owner of sharable pages */
160#define DOMID_COW (0x7FF3U)
161
162/* DOMID_INVALID is used to identify pages with unknown owner. */
163#define DOMID_INVALID (0x7FF4U)
164
165/* Idle domain. */
166#define DOMID_IDLE (0x7FFFU)
167
168 #if __XEN_INTERFACE_VERSION__ < 0x00040400
169
170/*
171 * Event channel endpoints per domain (when using the 2-level ABI):
172 * 1024 if a INTN is 32 bits; 4096 if a INTN is 64 bits.
173 */
174#define NR_EVENT_CHANNELS EVTCHN_2L_NR_CHANNELS
175 #endif
176
178 /*
179 * Updates to the following values are preceded and followed by an
180 * increment of 'version'. The guest can therefore detect updates by
181 * looking for changes to 'version'. If the least-significant bit of
182 * the version number is set then an update is in progress and the guest
183 * must wait to read a consistent set of values.
184 * The correct way to interact with the version number is similar to
185 * Linux's seqlock: see the implementations of read_seqbegin/read_seqretry.
186 */
187 UINT32 Version;
188 UINT32 pad0;
189 UINT64 TscTimestamp; /* TSC at last update of time vals. */
190 UINT64 SystemTime; /* Time, in nanosecs, since boot. */
191
192 /*
193 * Current system time:
194 * system_time +
195 * ((((tsc - tsc_timestamp) << tsc_shift) * tsc_to_system_mul) >> 32)
196 * CPU frequency (Hz):
197 * ((10^9 << 32) / tsc_to_system_mul) >> tsc_shift
198 */
199 UINT32 TscToSystemMultiplier;
200 INT8 TscShift;
201 INT8 pad1[3];
202}; /* 32 bytes */
203
205
206struct vcpu_info {
207 /*
208 * 'evtchn_upcall_pending' is written non-zero by Xen to indicate
209 * a pending notification for a particular VCPU. It is then cleared
210 * by the guest OS /before/ checking for pending work, thus avoiding
211 * a set-and-check race. Note that the mask is only accessed by Xen
212 * on the CPU that is currently hosting the VCPU. This means that the
213 * pending and mask flags can be updated by the guest without special
214 * synchronisation (i.e., no need for the x86 LOCK prefix).
215 * This may seem suboptimal because if the pending flag is set by
216 * a different CPU then an IPI may be scheduled even when the mask
217 * is set. However, note:
218 * 1. The task of 'interrupt holdoff' is covered by the per-event-
219 * channel mask bits. A 'noisy' event that is continually being
220 * triggered can be masked at source at this very precise
221 * granularity.
222 * 2. The main purpose of the per-VCPU mask is therefore to restrict
223 * reentrant execution: whether for concurrency control, or to
224 * prevent unbounded stack usage. Whatever the purpose, we expect
225 * that the mask will be asserted only for short periods at a time,
226 * and so the likelihood of a 'spurious' IPI is suitably small.
227 * The mask is read before making an event upcall to the guest: a
228 * non-zero mask therefore guarantees that the VCPU will not receive
229 * an upcall activation. The mask is cleared when the VCPU requests
230 * to block: this avoids wakeup-waiting races.
231 */
232 UINT8 evtchn_upcall_pending;
233 #ifdef XEN_HAVE_PV_UPCALL_MASK
234 UINT8 evtchn_upcall_mask;
235 #else /* XEN_HAVE_PV_UPCALL_MASK */
236 UINT8 pad0;
237 #endif /* XEN_HAVE_PV_UPCALL_MASK */
238 xen_ulong_t evtchn_pending_sel;
239 struct arch_vcpu_info arch;
240 struct vcpu_time_info Time;
241}; /* 64 bytes (x86) */
242
243 #ifndef __XEN__
244typedef struct vcpu_info vcpu_info_t;
245 #endif
246
247/*
248 * `incontents 200 startofday_shared Start-of-day shared data structure
249 * Xen/kernel shared data -- pointer provided in start_info.
250 *
251 * This structure is defined to be both smaller than a page, and the
252 * only data on the shared page, but may vary in actual size even within
253 * compatible Xen versions; guests should not rely on the size
254 * of this structure remaining constant.
255 */
257 struct vcpu_info VcpuInfo[XEN_LEGACY_MAX_VCPUS];
258
259 /*
260 * A domain can create "event channels" on which it can send and receive
261 * asynchronous event notifications. There are three classes of event that
262 * are delivered by this mechanism:
263 * 1. Bi-directional inter- and intra-domain connections. Domains must
264 * arrange out-of-band to set up a connection (usually by allocating
265 * an unbound 'listener' port and avertising that via a storage service
266 * such as xenstore).
267 * 2. Physical interrupts. A domain with suitable hardware-access
268 * privileges can bind an event-channel port to a physical interrupt
269 * source.
270 * 3. Virtual interrupts ('events'). A domain can bind an event-channel
271 * port to a virtual interrupt source, such as the virtual-timer
272 * device or the emergency console.
273 *
274 * Event channels are addressed by a "port index". Each channel is
275 * associated with two bits of information:
276 * 1. PENDING -- notifies the domain that there is a pending notification
277 * to be processed. This bit is cleared by the guest.
278 * 2. MASK -- if this bit is clear then a 0->1 transition of PENDING
279 * will cause an asynchronous upcall to be scheduled. This bit is only
280 * updated by the guest. It is read-only within Xen. If a channel
281 * becomes pending while the channel is masked then the 'edge' is lost
282 * (i.e., when the channel is unmasked, the guest must manually handle
283 * pending notifications as no upcall will be scheduled by Xen).
284 *
285 * To expedite scanning of pending notifications, any 0->1 pending
286 * transition on an unmasked channel causes a corresponding bit in a
287 * per-vcpu selector word to be set. Each bit in the selector covers a
288 * 'C INTN' in the PENDING bitfield array.
289 */
290 xen_ulong_t evtchn_pending[sizeof (xen_ulong_t) * 8];
291 xen_ulong_t evtchn_mask[sizeof (xen_ulong_t) * 8];
292
293 /*
294 * Wallclock time: updated only by control software. Guests should base
295 * their gettimeofday() syscall on this wallclock-base value.
296 */
297 UINT32 wc_version; /* Version counter: see vcpu_time_info_t. */
298 UINT32 wc_sec; /* Secs 00:00:00 UTC, Jan 1, 1970. */
299 UINT32 wc_nsec; /* Nsecs 00:00:00 UTC, Jan 1, 1970. */
300
301 struct arch_shared_info arch;
302};
303
304 #ifndef __XEN__
305typedef struct shared_info shared_info_t;
306typedef struct shared_info XEN_SHARED_INFO;
307 #endif
308
309/* Turn a plain number into a C UINTN constant. */
310#define __mk_unsigned_long(x) x ## UL
311#define mk_unsigned_long(x) __mk_unsigned_long(x)
312
313__DEFINE_XEN_GUEST_HANDLE (uint8, UINT8);
314__DEFINE_XEN_GUEST_HANDLE (uint16, UINT16);
315__DEFINE_XEN_GUEST_HANDLE (uint32, UINT32);
316__DEFINE_XEN_GUEST_HANDLE (uint64, UINT64);
317
318#else /* __ASSEMBLY__ */
319
320/* In assembly code we cannot use C numeric constant suffixes. */
321#define mk_unsigned_long(x) x
322
323#endif /* !__ASSEMBLY__ */
324
325#endif /* __XEN_PUBLIC_XEN_H__ */
326
327/*
328 * Local variables:
329 * mode: C
330 * c-file-style: "BSD"
331 * c-basic-offset: 4
332 * tab-width: 4
333 * indent-tabs-mode: nil
334 * End:
335 */
UINT64 UINTN
INT64 INTN
Definition: xen.h:206