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