Zephyr API Documentation  3.0.0
A Scalable Open Source RTOS
3.0.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
xen.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: MIT */
2
3/******************************************************************************
4 * xen.h
5 *
6 * Guest OS interface to Xen.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to
10 * deal in the Software without restriction, including without limitation the
11 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12 * sell copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
25 *
26 * Copyright (c) 2004, K A Fraser
27 */
28
29#ifndef __XEN_PUBLIC_XEN_H__
30#define __XEN_PUBLIC_XEN_H__
31
32#if defined(CONFIG_ARM64)
33#include "arch-arm.h"
34#else
35#error "Unsupported architecture"
36#endif
37
38#ifndef __ASSEMBLY__
39/* Guest handles for primitive C types. */
41__DEFINE_XEN_GUEST_HANDLE(uchar, unsigned char);
43__DEFINE_XEN_GUEST_HANDLE(uint, unsigned int);
44#if __XEN_INTERFACE_VERSION__ < 0x00040300
46__DEFINE_XEN_GUEST_HANDLE(ulong, unsigned long);
47#endif
49
53
54/* Define a variable length array (depends on compiler). */
55#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
56#define XEN_FLEX_ARRAY_DIM
57#elif defined(__GNUC__)
58#define XEN_FLEX_ARRAY_DIM 0
59#else
60#define XEN_FLEX_ARRAY_DIM 1 /* variable size */
61#endif
62
63/* Turn a plain number into a C unsigned (long (long)) constant. */
64#define __xen_mk_uint(x) x ## U
65#define __xen_mk_ulong(x) x ## UL
66#ifndef __xen_mk_ullong
67#define __xen_mk_ullong(x) x ## ULL
68#endif
69#define xen_mk_uint(x) __xen_mk_uint(x)
70#define xen_mk_ulong(x) __xen_mk_ulong(x)
71#define xen_mk_ullong(x) __xen_mk_ullong(x)
72
73#else
74
75/* In assembly code we cannot use C numeric constant suffixes. */
76#define xen_mk_uint(x) x
77#define xen_mk_ulong(x) x
78#define xen_mk_ullong(x) x
79
80#endif
81
82/*
83 * HYPERCALLS
84 */
85
86/* `incontents 100 hcalls List of hypercalls
87 * ` enum hypercall_num { // __HYPERVISOR_* => HYPERVISOR_*()
88 */
89
90#define __HYPERVISOR_set_trap_table 0
91#define __HYPERVISOR_mmu_update 1
92#define __HYPERVISOR_set_gdt 2
93#define __HYPERVISOR_stack_switch 3
94#define __HYPERVISOR_set_callbacks 4
95#define __HYPERVISOR_fpu_taskswitch 5
96
97/* compat since 0x00030101 */
98#define __HYPERVISOR_sched_op_compat 6
99#define __HYPERVISOR_platform_op 7
100#define __HYPERVISOR_set_debugreg 8
101#define __HYPERVISOR_get_debugreg 9
102#define __HYPERVISOR_update_descriptor 10
103#define __HYPERVISOR_memory_op 12
104#define __HYPERVISOR_multicall 13
105#define __HYPERVISOR_update_va_mapping 14
106#define __HYPERVISOR_set_timer_op 15
107
108/* compat since 0x00030202 */
109#define __HYPERVISOR_event_channel_op_compat 16
110#define __HYPERVISOR_xen_version 17
111#define __HYPERVISOR_console_io 18
112
113/* compat since 0x00030202 */
114#define __HYPERVISOR_physdev_op_compat 19
115#define __HYPERVISOR_grant_table_op 20
116#define __HYPERVISOR_vm_assist 21
117#define __HYPERVISOR_update_va_mapping_otherdomain 22
118
119/* x86 only */
120#define __HYPERVISOR_iret 23
121#define __HYPERVISOR_vcpu_op 24
122
123/* x86/64 only */
124#define __HYPERVISOR_set_segment_base 25
125#define __HYPERVISOR_mmuext_op 26
126#define __HYPERVISOR_xsm_op 27
127#define __HYPERVISOR_nmi_op 28
128#define __HYPERVISOR_sched_op 29
129#define __HYPERVISOR_callback_op 30
130#define __HYPERVISOR_xenoprof_op 31
131#define __HYPERVISOR_event_channel_op 32
132#define __HYPERVISOR_physdev_op 33
133#define __HYPERVISOR_hvm_op 34
134#define __HYPERVISOR_sysctl 35
135#define __HYPERVISOR_domctl 36
136#define __HYPERVISOR_kexec_op 37
137#define __HYPERVISOR_tmem_op 38
138#define __HYPERVISOR_argo_op 39
139#define __HYPERVISOR_xenpmu_op 40
140#define __HYPERVISOR_dm_op 41
141#define __HYPERVISOR_hypfs_op 42
142
143/*
144 * ` int
145 * ` HYPERVISOR_console_io(unsigned int cmd,
146 * ` unsigned int count,
147 * ` char buffer[]);
148 *
149 * @cmd: Command (see below)
150 * @count: Size of the buffer to read/write
151 * @buffer: Pointer in the guest memory
152 *
153 * List of commands:
154 *
155 * * CONSOLEIO_write: Write the buffer to Xen console.
156 * For the hardware domain, all the characters in the buffer will
157 * be written. Characters will be printed directly to the console.
158 * For all the other domains, only the printable characters will be
159 * written. Characters may be buffered until a newline (i.e '\n') is
160 * found.
161 * @return 0 on success, otherwise return an error code.
162 * * CONSOLEIO_read: Attempts to read up to @count characters from Xen
163 * console. The maximum buffer size (i.e. @count) supported is 2GB.
164 * @return the number of characters read on success, otherwise return
165 * an error code.
166 */
167#define CONSOLEIO_write 0
168#define CONSOLEIO_read 1
169
170/* Domain ids >= DOMID_FIRST_RESERVED cannot be used for ordinary domains. */
171#define DOMID_FIRST_RESERVED xen_mk_uint(0x7FF0)
172
173/* DOMID_SELF is used in certain contexts to refer to oneself. */
174#define DOMID_SELF xen_mk_uint(0x7FF0)
175
176/*
177 * DOMID_IO is used to restrict page-table updates to mapping I/O memory.
178 * Although no Foreign Domain need be specified to map I/O pages, DOMID_IO
179 * is useful to ensure that no mappings to the OS's own heap are accidentally
180 * installed. (e.g., in Linux this could cause havoc as reference counts
181 * aren't adjusted on the I/O-mapping code path).
182 * This only makes sense as HYPERVISOR_mmu_update()'s and
183 * HYPERVISOR_update_va_mapping_otherdomain()'s "foreigndom" argument. For
184 * HYPERVISOR_mmu_update() context it can be specified by any calling domain,
185 * otherwise it's only permitted if the caller is privileged.
186 */
187#define DOMID_IO xen_mk_uint(0x7FF1)
188
189/*
190 * DOMID_XEN is used to allow privileged domains to map restricted parts of
191 * Xen's heap space (e.g., the machine_to_phys table).
192 * This only makes sense as
193 * - HYPERVISOR_mmu_update()'s, HYPERVISOR_mmuext_op()'s, or
194 * HYPERVISOR_update_va_mapping_otherdomain()'s "foreigndom" argument,
195 * - with XENMAPSPACE_gmfn_foreign,
196 * and is only permitted if the caller is privileged.
197 */
198#define DOMID_XEN xen_mk_uint(0x7FF2)
199
200/*
201 * DOMID_COW is used as the owner of sharable pages.
202 */
203#define DOMID_COW xen_mk_uint(0x7FF3)
204
205/* DOMID_INVALID is used to identify pages with unknown owner. */
206#define DOMID_INVALID xen_mk_uint(0x7FF4)
207
208/* Idle domain. */
209#define DOMID_IDLE xen_mk_uint(0x7FFF)
210
211/* Mask for valid domain id values */
212#define DOMID_MASK xen_mk_uint(0x7FFF)
213
214#ifndef __ASSEMBLY__
215
217
218#if __XEN_INTERFACE_VERSION__ < 0x00040400
219/*
220 * Event channel endpoints per domain (when using the 2-level ABI):
221 * 1024 if a long is 32 bits; 4096 if a long is 64 bits.
222 */
223#define NR_EVENT_CHANNELS EVTCHN_2L_NR_CHANNELS
224#endif
225
227 /*
228 * Updates to the following values are preceded and followed by an
229 * increment of 'version'. The guest can therefore detect updates by
230 * looking for changes to 'version'. If the least-significant bit of
231 * the version number is set then an update is in progress and the
232 * guest must wait to read a consistent set of values.
233 * The correct way to interact with the version number is similar to
234 * Linux's seqlock: see the implementations of
235 * read_seqbegin/read_seqretry.
236 */
239 uint64_t tsc_timestamp; /* TSC at last update of time vals. */
240 uint64_t system_time; /* Time, in nanosecs, since boot.*/
241 /*
242 * Current system time:
243 * system_time +
244 * ((((tsc - tsc_timestamp) << tsc_shift) * tsc_to_system_mul) >> 32)
245 * CPU frequency (Hz):
246 * ((10^9 << 32) / tsc_to_system_mul) >> tsc_shift
247 */
250#if __XEN_INTERFACE_VERSION__ > 0x040600
252 uint8_t pad1[2];
253#else
255#endif
256}; /* 32 bytes */
258
259#define XEN_PVCLOCK_TSC_STABLE_BIT (1 << 0)
260#define XEN_PVCLOCK_GUEST_STOPPED (1 << 1)
261
262struct vcpu_info {
263 /*
264 * 'evtchn_upcall_pending' is written non-zero by Xen to indicate
265 * a pending notification for a particular VCPU. It is then cleared
266 * by the guest OS /before/ checking for pending work, thus avoiding
267 * a set-and-check race. Note that the mask is only accessed by Xen
268 * on the CPU that is currently hosting the VCPU. This means that the
269 * pending and mask flags can be updated by the guest without special
270 * synchronisation (i.e., no need for the x86 LOCK prefix).
271 * This may seem suboptimal because if the pending flag is set by
272 * a different CPU then an IPI may be scheduled even when the mask
273 * is set. However, note:
274 * 1. The task of 'interrupt holdoff' is covered by the per-event-
275 * channel mask bits. A 'noisy' event that is continually being
276 * triggered can be masked at source at this very precise
277 * granularity.
278 * 2. The main purpose of the per-VCPU mask is therefore to restrict
279 * reentrant execution: whether for concurrency control, or to
280 * prevent unbounded stack usage. Whatever the purpose, we expect
281 * that the mask will be asserted only for short periods at a time,
282 * and so the likelihood of a 'spurious' IPI is suitably small.
283 * The mask is read before making an event upcall to the guest: a
284 * non-zero mask therefore guarantees that the VCPU will not receive
285 * an upcall activation. The mask is cleared when the VCPU requests
286 * to block: this avoids wakeup-waiting races.
287 */
289#ifdef XEN_HAVE_PV_UPCALL_MASK
290 uint8_t evtchn_upcall_mask;
291#else /* XEN_HAVE_PV_UPCALL_MASK */
293#endif /* XEN_HAVE_PV_UPCALL_MASK */
297}; /* 64 bytes (x86) */
298#ifndef __XEN__
299typedef struct vcpu_info vcpu_info_t;
300#endif
301
302/*
303 * `incontents 200 startofday_shared Start-of-day shared data structure
304 * Xen/kernel shared data -- pointer provided in start_info.
305 *
306 * This structure is defined to be both smaller than a page, and the
307 * only data on the shared page, but may vary in actual size even within
308 * compatible Xen versions; guests should not rely on the size
309 * of this structure remaining constant.
310 */
313
314 /*
315 * A domain can create "event channels" on which it can send and receive
316 * asynchronous event notifications. There are three classes of event that
317 * are delivered by this mechanism:
318 * 1. Bi-directional inter- and intra-domain connections. Domains must
319 * arrange out-of-band to set up a connection (usually by allocating
320 * an unbound 'listener' port and avertising that via a storage service
321 * such as xenstore).
322 * 2. Physical interrupts. A domain with suitable hardware-access
323 * privileges can bind an event-channel port to a physical interrupt
324 * source.
325 * 3. Virtual interrupts ('events'). A domain can bind an event-channel
326 * port to a virtual interrupt source, such as the virtual-timer
327 * device or the emergency console.
328 *
329 * Event channels are addressed by a "port index". Each channel is
330 * associated with two bits of information:
331 * 1. PENDING -- notifies the domain that there is a pending notification
332 * to be processed. This bit is cleared by the guest.
333 * 2. MASK -- if this bit is clear then a 0->1 transition of PENDING
334 * will cause an asynchronous upcall to be scheduled. This bit is only
335 * updated by the guest. It is read-only within Xen. If a channel
336 * becomes pending while the channel is masked then the 'edge' is lost
337 * (i.e., when the channel is unmasked, the guest must manually handle
338 * pending notifications as no upcall will be scheduled by Xen).
339 *
340 * To expedite scanning of pending notifications, any 0->1 pending
341 * transition on an unmasked channel causes a corresponding bit in a
342 * per-vcpu selector word to be set. Each bit in the selector covers a
343 * 'C long' in the PENDING bitfield array.
344 */
347
348 /*
349 * Wallclock time: updated by control software or RTC emulation.
350 * Guests should base their gettimeofday() syscall on this
351 * wallclock-base value.
352 * The values of wc_sec and wc_nsec are offsets from the Unix epoch
353 * adjusted by the domain's 'time offset' (in seconds) as set either
354 * by XEN_DOMCTL_settimeoffset, or adjusted via a guest write to the
355 * emulated RTC.
356 */
357 uint32_t wc_version; /* Version counter: see vcpu_time_info_t. */
360#if !defined(__i386__)
362# define xen_wc_sec_hi wc_sec_hi
363#elif !defined(__XEN__) && !defined(__XEN_TOOLS__)
364# define xen_wc_sec_hi arch.wc_sec_hi
365#endif
366
368
369};
370#ifndef __XEN__
372#endif
373
374#endif /* !__ASSEMBLY__ */
375
376#endif /* __XEN_PUBLIC_XEN_H__ */
uint64_t xen_pfn_t
Definition: arch-arm.h:204
#define XEN_LEGACY_MAX_VCPUS
Definition: arch-arm.h:215
uint64_t xen_ulong_t
Definition: arch-arm.h:208
flags
Definition: http_parser.h:131
__UINT32_TYPE__ uint32_t
Definition: stdint.h:60
__UINT64_TYPE__ uint64_t
Definition: stdint.h:61
__UINT8_TYPE__ uint8_t
Definition: stdint.h:58
__UINT16_TYPE__ uint16_t
Definition: stdint.h:59
__INT8_TYPE__ int8_t
Definition: stdint.h:42
Definition: arch-arm.h:221
Definition: arch-arm.h:217
Definition: xen.h:311
uint32_t wc_sec_hi
Definition: xen.h:361
uint32_t wc_nsec
Definition: xen.h:359
uint32_t wc_sec
Definition: xen.h:358
xen_ulong_t evtchn_mask[sizeof(xen_ulong_t) *8]
Definition: xen.h:346
struct arch_shared_info arch
Definition: xen.h:367
xen_ulong_t evtchn_pending[sizeof(xen_ulong_t) *8]
Definition: xen.h:345
uint32_t wc_version
Definition: xen.h:357
Definition: xen.h:262
uint8_t pad0
Definition: xen.h:292
xen_ulong_t evtchn_pending_sel
Definition: xen.h:294
uint8_t evtchn_upcall_pending
Definition: xen.h:288
struct arch_vcpu_info arch
Definition: xen.h:295
vcpu_time_info_t time
Definition: xen.h:296
Definition: xen.h:226
uint32_t tsc_to_system_mul
Definition: xen.h:248
uint32_t pad0
Definition: xen.h:238
uint64_t tsc_timestamp
Definition: xen.h:239
uint32_t version
Definition: xen.h:237
int8_t pad1[3]
Definition: xen.h:254
uint64_t system_time
Definition: xen.h:240
int8_t tsc_shift
Definition: xen.h:249
DEFINE_XEN_GUEST_HANDLE(char)
uint16_t domid_t
Definition: xen.h:216