xref: /freebsd/sys/contrib/xen/xen.h (revision 3a9fd8242b35884921dfc4e886f284a75870a536)
1*3a9fd824SRoger Pau Monné /******************************************************************************
2*3a9fd824SRoger Pau Monné  * xen.h
3*3a9fd824SRoger Pau Monné  *
4*3a9fd824SRoger Pau Monné  * Guest OS interface to Xen.
5*3a9fd824SRoger Pau Monné  *
6*3a9fd824SRoger Pau Monné  * Permission is hereby granted, free of charge, to any person obtaining a copy
7*3a9fd824SRoger Pau Monné  * of this software and associated documentation files (the "Software"), to
8*3a9fd824SRoger Pau Monné  * deal in the Software without restriction, including without limitation the
9*3a9fd824SRoger Pau Monné  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10*3a9fd824SRoger Pau Monné  * sell copies of the Software, and to permit persons to whom the Software is
11*3a9fd824SRoger Pau Monné  * furnished to do so, subject to the following conditions:
12*3a9fd824SRoger Pau Monné  *
13*3a9fd824SRoger Pau Monné  * The above copyright notice and this permission notice shall be included in
14*3a9fd824SRoger Pau Monné  * all copies or substantial portions of the Software.
15*3a9fd824SRoger Pau Monné  *
16*3a9fd824SRoger Pau Monné  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17*3a9fd824SRoger Pau Monné  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18*3a9fd824SRoger Pau Monné  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19*3a9fd824SRoger Pau Monné  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20*3a9fd824SRoger Pau Monné  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21*3a9fd824SRoger Pau Monné  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22*3a9fd824SRoger Pau Monné  * DEALINGS IN THE SOFTWARE.
23*3a9fd824SRoger Pau Monné  *
24*3a9fd824SRoger Pau Monné  * Copyright (c) 2004, K A Fraser
25*3a9fd824SRoger Pau Monné  */
26*3a9fd824SRoger Pau Monné 
27*3a9fd824SRoger Pau Monné #ifndef __XEN_PUBLIC_XEN_H__
28*3a9fd824SRoger Pau Monné #define __XEN_PUBLIC_XEN_H__
29*3a9fd824SRoger Pau Monné 
30*3a9fd824SRoger Pau Monné #include "xen-compat.h"
31*3a9fd824SRoger Pau Monné 
32*3a9fd824SRoger Pau Monné #if defined(__i386__) || defined(__x86_64__)
33*3a9fd824SRoger Pau Monné #include "arch-x86/xen.h"
34*3a9fd824SRoger Pau Monné #elif defined(__arm__) || defined (__aarch64__)
35*3a9fd824SRoger Pau Monné #include "arch-arm.h"
36*3a9fd824SRoger Pau Monné #else
37*3a9fd824SRoger Pau Monné #error "Unsupported architecture"
38*3a9fd824SRoger Pau Monné #endif
39*3a9fd824SRoger Pau Monné 
40*3a9fd824SRoger Pau Monné #ifndef __ASSEMBLY__
41*3a9fd824SRoger Pau Monné /* Guest handles for primitive C types. */
42*3a9fd824SRoger Pau Monné DEFINE_XEN_GUEST_HANDLE(char);
43*3a9fd824SRoger Pau Monné __DEFINE_XEN_GUEST_HANDLE(uchar, unsigned char);
44*3a9fd824SRoger Pau Monné DEFINE_XEN_GUEST_HANDLE(int);
45*3a9fd824SRoger Pau Monné __DEFINE_XEN_GUEST_HANDLE(uint,  unsigned int);
46*3a9fd824SRoger Pau Monné #if __XEN_INTERFACE_VERSION__ < 0x00040300
47*3a9fd824SRoger Pau Monné DEFINE_XEN_GUEST_HANDLE(long);
48*3a9fd824SRoger Pau Monné __DEFINE_XEN_GUEST_HANDLE(ulong, unsigned long);
49*3a9fd824SRoger Pau Monné #endif
50*3a9fd824SRoger Pau Monné DEFINE_XEN_GUEST_HANDLE(void);
51*3a9fd824SRoger Pau Monné 
52*3a9fd824SRoger Pau Monné DEFINE_XEN_GUEST_HANDLE(uint64_t);
53*3a9fd824SRoger Pau Monné DEFINE_XEN_GUEST_HANDLE(xen_pfn_t);
54*3a9fd824SRoger Pau Monné DEFINE_XEN_GUEST_HANDLE(xen_ulong_t);
55*3a9fd824SRoger Pau Monné 
56*3a9fd824SRoger Pau Monné /* Define a variable length array (depends on compiler). */
57*3a9fd824SRoger Pau Monné #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
58*3a9fd824SRoger Pau Monné #define XEN_FLEX_ARRAY_DIM
59*3a9fd824SRoger Pau Monné #elif defined(__GNUC__)
60*3a9fd824SRoger Pau Monné #define XEN_FLEX_ARRAY_DIM  0
61*3a9fd824SRoger Pau Monné #else
62*3a9fd824SRoger Pau Monné #define XEN_FLEX_ARRAY_DIM  1 /* variable size */
63*3a9fd824SRoger Pau Monné #endif
64*3a9fd824SRoger Pau Monné 
65*3a9fd824SRoger Pau Monné /* Turn a plain number into a C unsigned (long (long)) constant. */
66*3a9fd824SRoger Pau Monné #define __xen_mk_uint(x)  x ## U
67*3a9fd824SRoger Pau Monné #define __xen_mk_ulong(x) x ## UL
68*3a9fd824SRoger Pau Monné #ifndef __xen_mk_ullong
69*3a9fd824SRoger Pau Monné # define __xen_mk_ullong(x) x ## ULL
70*3a9fd824SRoger Pau Monné #endif
71*3a9fd824SRoger Pau Monné #define xen_mk_uint(x)    __xen_mk_uint(x)
72*3a9fd824SRoger Pau Monné #define xen_mk_ulong(x)   __xen_mk_ulong(x)
73*3a9fd824SRoger Pau Monné #define xen_mk_ullong(x)  __xen_mk_ullong(x)
74*3a9fd824SRoger Pau Monné 
75*3a9fd824SRoger Pau Monné #else
76*3a9fd824SRoger Pau Monné 
77*3a9fd824SRoger Pau Monné /* In assembly code we cannot use C numeric constant suffixes. */
78*3a9fd824SRoger Pau Monné #define xen_mk_uint(x)   x
79*3a9fd824SRoger Pau Monné #define xen_mk_ulong(x)  x
80*3a9fd824SRoger Pau Monné #define xen_mk_ullong(x) x
81*3a9fd824SRoger Pau Monné 
82*3a9fd824SRoger Pau Monné #endif
83*3a9fd824SRoger Pau Monné 
84*3a9fd824SRoger Pau Monné /*
85*3a9fd824SRoger Pau Monné  * HYPERCALLS
86*3a9fd824SRoger Pau Monné  */
87*3a9fd824SRoger Pau Monné 
88*3a9fd824SRoger Pau Monné /* `incontents 100 hcalls List of hypercalls
89*3a9fd824SRoger Pau Monné  * ` enum hypercall_num { // __HYPERVISOR_* => HYPERVISOR_*()
90*3a9fd824SRoger Pau Monné  */
91*3a9fd824SRoger Pau Monné 
92*3a9fd824SRoger Pau Monné #define __HYPERVISOR_set_trap_table        0
93*3a9fd824SRoger Pau Monné #define __HYPERVISOR_mmu_update            1
94*3a9fd824SRoger Pau Monné #define __HYPERVISOR_set_gdt               2
95*3a9fd824SRoger Pau Monné #define __HYPERVISOR_stack_switch          3
96*3a9fd824SRoger Pau Monné #define __HYPERVISOR_set_callbacks         4
97*3a9fd824SRoger Pau Monné #define __HYPERVISOR_fpu_taskswitch        5
98*3a9fd824SRoger Pau Monné #define __HYPERVISOR_sched_op_compat       6 /* compat since 0x00030101 */
99*3a9fd824SRoger Pau Monné #define __HYPERVISOR_platform_op           7
100*3a9fd824SRoger Pau Monné #define __HYPERVISOR_set_debugreg          8
101*3a9fd824SRoger Pau Monné #define __HYPERVISOR_get_debugreg          9
102*3a9fd824SRoger Pau Monné #define __HYPERVISOR_update_descriptor    10
103*3a9fd824SRoger Pau Monné #define __HYPERVISOR_memory_op            12
104*3a9fd824SRoger Pau Monné #define __HYPERVISOR_multicall            13
105*3a9fd824SRoger Pau Monné #define __HYPERVISOR_update_va_mapping    14
106*3a9fd824SRoger Pau Monné #define __HYPERVISOR_set_timer_op         15
107*3a9fd824SRoger Pau Monné #define __HYPERVISOR_event_channel_op_compat 16 /* compat since 0x00030202 */
108*3a9fd824SRoger Pau Monné #define __HYPERVISOR_xen_version          17
109*3a9fd824SRoger Pau Monné #define __HYPERVISOR_console_io           18
110*3a9fd824SRoger Pau Monné #define __HYPERVISOR_physdev_op_compat    19 /* compat since 0x00030202 */
111*3a9fd824SRoger Pau Monné #define __HYPERVISOR_grant_table_op       20
112*3a9fd824SRoger Pau Monné #define __HYPERVISOR_vm_assist            21
113*3a9fd824SRoger Pau Monné #define __HYPERVISOR_update_va_mapping_otherdomain 22
114*3a9fd824SRoger Pau Monné #define __HYPERVISOR_iret                 23 /* x86 only */
115*3a9fd824SRoger Pau Monné #define __HYPERVISOR_vcpu_op              24
116*3a9fd824SRoger Pau Monné #define __HYPERVISOR_set_segment_base     25 /* x86/64 only */
117*3a9fd824SRoger Pau Monné #define __HYPERVISOR_mmuext_op            26
118*3a9fd824SRoger Pau Monné #define __HYPERVISOR_xsm_op               27
119*3a9fd824SRoger Pau Monné #define __HYPERVISOR_nmi_op               28
120*3a9fd824SRoger Pau Monné #define __HYPERVISOR_sched_op             29
121*3a9fd824SRoger Pau Monné #define __HYPERVISOR_callback_op          30
122*3a9fd824SRoger Pau Monné #define __HYPERVISOR_xenoprof_op          31
123*3a9fd824SRoger Pau Monné #define __HYPERVISOR_event_channel_op     32
124*3a9fd824SRoger Pau Monné #define __HYPERVISOR_physdev_op           33
125*3a9fd824SRoger Pau Monné #define __HYPERVISOR_hvm_op               34
126*3a9fd824SRoger Pau Monné #define __HYPERVISOR_sysctl               35
127*3a9fd824SRoger Pau Monné #define __HYPERVISOR_domctl               36
128*3a9fd824SRoger Pau Monné #define __HYPERVISOR_kexec_op             37
129*3a9fd824SRoger Pau Monné #define __HYPERVISOR_tmem_op              38
130*3a9fd824SRoger Pau Monné #define __HYPERVISOR_argo_op              39
131*3a9fd824SRoger Pau Monné #define __HYPERVISOR_xenpmu_op            40
132*3a9fd824SRoger Pau Monné #define __HYPERVISOR_dm_op                41
133*3a9fd824SRoger Pau Monné #define __HYPERVISOR_hypfs_op             42
134*3a9fd824SRoger Pau Monné 
135*3a9fd824SRoger Pau Monné /* Architecture-specific hypercall definitions. */
136*3a9fd824SRoger Pau Monné #define __HYPERVISOR_arch_0               48
137*3a9fd824SRoger Pau Monné #define __HYPERVISOR_arch_1               49
138*3a9fd824SRoger Pau Monné #define __HYPERVISOR_arch_2               50
139*3a9fd824SRoger Pau Monné #define __HYPERVISOR_arch_3               51
140*3a9fd824SRoger Pau Monné #define __HYPERVISOR_arch_4               52
141*3a9fd824SRoger Pau Monné #define __HYPERVISOR_arch_5               53
142*3a9fd824SRoger Pau Monné #define __HYPERVISOR_arch_6               54
143*3a9fd824SRoger Pau Monné #define __HYPERVISOR_arch_7               55
144*3a9fd824SRoger Pau Monné 
145*3a9fd824SRoger Pau Monné /* ` } */
146*3a9fd824SRoger Pau Monné 
147*3a9fd824SRoger Pau Monné /*
148*3a9fd824SRoger Pau Monné  * HYPERCALL COMPATIBILITY.
149*3a9fd824SRoger Pau Monné  */
150*3a9fd824SRoger Pau Monné 
151*3a9fd824SRoger Pau Monné /* New sched_op hypercall introduced in 0x00030101. */
152*3a9fd824SRoger Pau Monné #if __XEN_INTERFACE_VERSION__ < 0x00030101
153*3a9fd824SRoger Pau Monné #undef __HYPERVISOR_sched_op
154*3a9fd824SRoger Pau Monné #define __HYPERVISOR_sched_op __HYPERVISOR_sched_op_compat
155*3a9fd824SRoger Pau Monné #endif
156*3a9fd824SRoger Pau Monné 
157*3a9fd824SRoger Pau Monné /* New event-channel and physdev hypercalls introduced in 0x00030202. */
158*3a9fd824SRoger Pau Monné #if __XEN_INTERFACE_VERSION__ < 0x00030202
159*3a9fd824SRoger Pau Monné #undef __HYPERVISOR_event_channel_op
160*3a9fd824SRoger Pau Monné #define __HYPERVISOR_event_channel_op __HYPERVISOR_event_channel_op_compat
161*3a9fd824SRoger Pau Monné #undef __HYPERVISOR_physdev_op
162*3a9fd824SRoger Pau Monné #define __HYPERVISOR_physdev_op __HYPERVISOR_physdev_op_compat
163*3a9fd824SRoger Pau Monné #endif
164*3a9fd824SRoger Pau Monné 
165*3a9fd824SRoger Pau Monné /* New platform_op hypercall introduced in 0x00030204. */
166*3a9fd824SRoger Pau Monné #if __XEN_INTERFACE_VERSION__ < 0x00030204
167*3a9fd824SRoger Pau Monné #define __HYPERVISOR_dom0_op __HYPERVISOR_platform_op
168*3a9fd824SRoger Pau Monné #endif
169*3a9fd824SRoger Pau Monné 
170*3a9fd824SRoger Pau Monné /*
171*3a9fd824SRoger Pau Monné  * VIRTUAL INTERRUPTS
172*3a9fd824SRoger Pau Monné  *
173*3a9fd824SRoger Pau Monné  * Virtual interrupts that a guest OS may receive from Xen.
174*3a9fd824SRoger Pau Monné  *
175*3a9fd824SRoger Pau Monné  * In the side comments, 'V.' denotes a per-VCPU VIRQ while 'G.' denotes a
176*3a9fd824SRoger Pau Monné  * global VIRQ. The former can be bound once per VCPU and cannot be re-bound.
177*3a9fd824SRoger Pau Monné  * The latter can be allocated only once per guest: they must initially be
178*3a9fd824SRoger Pau Monné  * allocated to VCPU0 but can subsequently be re-bound.
179*3a9fd824SRoger Pau Monné  */
180*3a9fd824SRoger Pau Monné /* ` enum virq { */
181*3a9fd824SRoger Pau Monné #define VIRQ_TIMER      0  /* V. Timebase update, and/or requested timeout.  */
182*3a9fd824SRoger Pau Monné #define VIRQ_DEBUG      1  /* V. Request guest to dump debug info.           */
183*3a9fd824SRoger Pau Monné #define VIRQ_CONSOLE    2  /* G. (DOM0) Bytes received on emergency console. */
184*3a9fd824SRoger Pau Monné #define VIRQ_DOM_EXC    3  /* G. (DOM0) Exceptional event for some domain.   */
185*3a9fd824SRoger Pau Monné #define VIRQ_TBUF       4  /* G. (DOM0) Trace buffer has records available.  */
186*3a9fd824SRoger Pau Monné #define VIRQ_DEBUGGER   6  /* G. (DOM0) A domain has paused for debugging.   */
187*3a9fd824SRoger Pau Monné #define VIRQ_XENOPROF   7  /* V. XenOprofile interrupt: new sample available */
188*3a9fd824SRoger Pau Monné #define VIRQ_CON_RING   8  /* G. (DOM0) Bytes received on console            */
189*3a9fd824SRoger Pau Monné #define VIRQ_PCPU_STATE 9  /* G. (DOM0) PCPU state changed                   */
190*3a9fd824SRoger Pau Monné #define VIRQ_MEM_EVENT  10 /* G. (DOM0) A memory event has occurred          */
191*3a9fd824SRoger Pau Monné #define VIRQ_ARGO       11 /* G. Argo interdomain message notification       */
192*3a9fd824SRoger Pau Monné #define VIRQ_ENOMEM     12 /* G. (DOM0) Low on heap memory       */
193*3a9fd824SRoger Pau Monné #define VIRQ_XENPMU     13 /* V.  PMC interrupt                              */
194*3a9fd824SRoger Pau Monné 
195*3a9fd824SRoger Pau Monné /* Architecture-specific VIRQ definitions. */
196*3a9fd824SRoger Pau Monné #define VIRQ_ARCH_0    16
197*3a9fd824SRoger Pau Monné #define VIRQ_ARCH_1    17
198*3a9fd824SRoger Pau Monné #define VIRQ_ARCH_2    18
199*3a9fd824SRoger Pau Monné #define VIRQ_ARCH_3    19
200*3a9fd824SRoger Pau Monné #define VIRQ_ARCH_4    20
201*3a9fd824SRoger Pau Monné #define VIRQ_ARCH_5    21
202*3a9fd824SRoger Pau Monné #define VIRQ_ARCH_6    22
203*3a9fd824SRoger Pau Monné #define VIRQ_ARCH_7    23
204*3a9fd824SRoger Pau Monné /* ` } */
205*3a9fd824SRoger Pau Monné 
206*3a9fd824SRoger Pau Monné #define NR_VIRQS       24
207*3a9fd824SRoger Pau Monné 
208*3a9fd824SRoger Pau Monné /*
209*3a9fd824SRoger Pau Monné  * ` enum neg_errnoval
210*3a9fd824SRoger Pau Monné  * ` HYPERVISOR_mmu_update(const struct mmu_update reqs[],
211*3a9fd824SRoger Pau Monné  * `                       unsigned count, unsigned *done_out,
212*3a9fd824SRoger Pau Monné  * `                       unsigned foreigndom)
213*3a9fd824SRoger Pau Monné  * `
214*3a9fd824SRoger Pau Monné  * @reqs is an array of mmu_update_t structures ((ptr, val) pairs).
215*3a9fd824SRoger Pau Monné  * @count is the length of the above array.
216*3a9fd824SRoger Pau Monné  * @pdone is an output parameter indicating number of completed operations
217*3a9fd824SRoger Pau Monné  * @foreigndom[15:0]: FD, the expected owner of data pages referenced in this
218*3a9fd824SRoger Pau Monné  *                    hypercall invocation. Can be DOMID_SELF.
219*3a9fd824SRoger Pau Monné  * @foreigndom[31:16]: PFD, the expected owner of pagetable pages referenced
220*3a9fd824SRoger Pau Monné  *                     in this hypercall invocation. The value of this field
221*3a9fd824SRoger Pau Monné  *                     (x) encodes the PFD as follows:
222*3a9fd824SRoger Pau Monné  *                     x == 0 => PFD == DOMID_SELF
223*3a9fd824SRoger Pau Monné  *                     x != 0 => PFD == x - 1
224*3a9fd824SRoger Pau Monné  *
225*3a9fd824SRoger Pau Monné  * Sub-commands: ptr[1:0] specifies the appropriate MMU_* command.
226*3a9fd824SRoger Pau Monné  * -------------
227*3a9fd824SRoger Pau Monné  * ptr[1:0] == MMU_NORMAL_PT_UPDATE:
228*3a9fd824SRoger Pau Monné  * Updates an entry in a page table belonging to PFD. If updating an L1 table,
229*3a9fd824SRoger Pau Monné  * and the new table entry is valid/present, the mapped frame must belong to
230*3a9fd824SRoger Pau Monné  * FD. If attempting to map an I/O page then the caller assumes the privilege
231*3a9fd824SRoger Pau Monné  * of the FD.
232*3a9fd824SRoger Pau Monné  * FD == DOMID_IO: Permit /only/ I/O mappings, at the priv level of the caller.
233*3a9fd824SRoger Pau Monné  * FD == DOMID_XEN: Map restricted areas of Xen's heap space.
234*3a9fd824SRoger Pau Monné  * ptr[:2]  -- Machine address of the page-table entry to modify.
235*3a9fd824SRoger Pau Monné  * val      -- Value to write.
236*3a9fd824SRoger Pau Monné  *
237*3a9fd824SRoger Pau Monné  * There also certain implicit requirements when using this hypercall. The
238*3a9fd824SRoger Pau Monné  * pages that make up a pagetable must be mapped read-only in the guest.
239*3a9fd824SRoger Pau Monné  * This prevents uncontrolled guest updates to the pagetable. Xen strictly
240*3a9fd824SRoger Pau Monné  * enforces this, and will disallow any pagetable update which will end up
241*3a9fd824SRoger Pau Monné  * mapping pagetable page RW, and will disallow using any writable page as a
242*3a9fd824SRoger Pau Monné  * pagetable. In practice it means that when constructing a page table for a
243*3a9fd824SRoger Pau Monné  * process, thread, etc, we MUST be very dilligient in following these rules:
244*3a9fd824SRoger Pau Monné  *  1). Start with top-level page (PGD or in Xen language: L4). Fill out
245*3a9fd824SRoger Pau Monné  *      the entries.
246*3a9fd824SRoger Pau Monné  *  2). Keep on going, filling out the upper (PUD or L3), and middle (PMD
247*3a9fd824SRoger Pau Monné  *      or L2).
248*3a9fd824SRoger Pau Monné  *  3). Start filling out the PTE table (L1) with the PTE entries. Once
249*3a9fd824SRoger Pau Monné  *  	done, make sure to set each of those entries to RO (so writeable bit
250*3a9fd824SRoger Pau Monné  *  	is unset). Once that has been completed, set the PMD (L2) for this
251*3a9fd824SRoger Pau Monné  *  	PTE table as RO.
252*3a9fd824SRoger Pau Monné  *  4). When completed with all of the PMD (L2) entries, and all of them have
253*3a9fd824SRoger Pau Monné  *  	been set to RO, make sure to set RO the PUD (L3). Do the same
254*3a9fd824SRoger Pau Monné  *  	operation on PGD (L4) pagetable entries that have a PUD (L3) entry.
255*3a9fd824SRoger Pau Monné  *  5). Now before you can use those pages (so setting the cr3), you MUST also
256*3a9fd824SRoger Pau Monné  *      pin them so that the hypervisor can verify the entries. This is done
257*3a9fd824SRoger Pau Monné  *      via the HYPERVISOR_mmuext_op(MMUEXT_PIN_L4_TABLE, guest physical frame
258*3a9fd824SRoger Pau Monné  *      number of the PGD (L4)). And this point the HYPERVISOR_mmuext_op(
259*3a9fd824SRoger Pau Monné  *      MMUEXT_NEW_BASEPTR, guest physical frame number of the PGD (L4)) can be
260*3a9fd824SRoger Pau Monné  *      issued.
261*3a9fd824SRoger Pau Monné  * For 32-bit guests, the L4 is not used (as there is less pagetables), so
262*3a9fd824SRoger Pau Monné  * instead use L3.
263*3a9fd824SRoger Pau Monné  * At this point the pagetables can be modified using the MMU_NORMAL_PT_UPDATE
264*3a9fd824SRoger Pau Monné  * hypercall. Also if so desired the OS can also try to write to the PTE
265*3a9fd824SRoger Pau Monné  * and be trapped by the hypervisor (as the PTE entry is RO).
266*3a9fd824SRoger Pau Monné  *
267*3a9fd824SRoger Pau Monné  * To deallocate the pages, the operations are the reverse of the steps
268*3a9fd824SRoger Pau Monné  * mentioned above. The argument is MMUEXT_UNPIN_TABLE for all levels and the
269*3a9fd824SRoger Pau Monné  * pagetable MUST not be in use (meaning that the cr3 is not set to it).
270*3a9fd824SRoger Pau Monné  *
271*3a9fd824SRoger Pau Monné  * ptr[1:0] == MMU_MACHPHYS_UPDATE:
272*3a9fd824SRoger Pau Monné  * Updates an entry in the machine->pseudo-physical mapping table.
273*3a9fd824SRoger Pau Monné  * ptr[:2]  -- Machine address within the frame whose mapping to modify.
274*3a9fd824SRoger Pau Monné  *             The frame must belong to the FD, if one is specified.
275*3a9fd824SRoger Pau Monné  * val      -- Value to write into the mapping entry.
276*3a9fd824SRoger Pau Monné  *
277*3a9fd824SRoger Pau Monné  * ptr[1:0] == MMU_PT_UPDATE_PRESERVE_AD:
278*3a9fd824SRoger Pau Monné  * As MMU_NORMAL_PT_UPDATE above, but A/D bits currently in the PTE are ORed
279*3a9fd824SRoger Pau Monné  * with those in @val.
280*3a9fd824SRoger Pau Monné  *
281*3a9fd824SRoger Pau Monné  * ptr[1:0] == MMU_PT_UPDATE_NO_TRANSLATE:
282*3a9fd824SRoger Pau Monné  * As MMU_NORMAL_PT_UPDATE above, but @val is not translated though FD
283*3a9fd824SRoger Pau Monné  * page tables.
284*3a9fd824SRoger Pau Monné  *
285*3a9fd824SRoger Pau Monné  * @val is usually the machine frame number along with some attributes.
286*3a9fd824SRoger Pau Monné  * The attributes by default follow the architecture defined bits. Meaning that
287*3a9fd824SRoger Pau Monné  * if this is a X86_64 machine and four page table layout is used, the layout
288*3a9fd824SRoger Pau Monné  * of val is:
289*3a9fd824SRoger Pau Monné  *  - 63 if set means No execute (NX)
290*3a9fd824SRoger Pau Monné  *  - 46-13 the machine frame number
291*3a9fd824SRoger Pau Monné  *  - 12 available for guest
292*3a9fd824SRoger Pau Monné  *  - 11 available for guest
293*3a9fd824SRoger Pau Monné  *  - 10 available for guest
294*3a9fd824SRoger Pau Monné  *  - 9 available for guest
295*3a9fd824SRoger Pau Monné  *  - 8 global
296*3a9fd824SRoger Pau Monné  *  - 7 PAT (PSE is disabled, must use hypercall to make 4MB or 2MB pages)
297*3a9fd824SRoger Pau Monné  *  - 6 dirty
298*3a9fd824SRoger Pau Monné  *  - 5 accessed
299*3a9fd824SRoger Pau Monné  *  - 4 page cached disabled
300*3a9fd824SRoger Pau Monné  *  - 3 page write through
301*3a9fd824SRoger Pau Monné  *  - 2 userspace accessible
302*3a9fd824SRoger Pau Monné  *  - 1 writeable
303*3a9fd824SRoger Pau Monné  *  - 0 present
304*3a9fd824SRoger Pau Monné  *
305*3a9fd824SRoger Pau Monné  *  The one bits that does not fit with the default layout is the PAGE_PSE
306*3a9fd824SRoger Pau Monné  *  also called PAGE_PAT). The MMUEXT_[UN]MARK_SUPER arguments to the
307*3a9fd824SRoger Pau Monné  *  HYPERVISOR_mmuext_op serve as mechanism to set a pagetable to be 4MB
308*3a9fd824SRoger Pau Monné  *  (or 2MB) instead of using the PAGE_PSE bit.
309*3a9fd824SRoger Pau Monné  *
310*3a9fd824SRoger Pau Monné  *  The reason that the PAGE_PSE (bit 7) is not being utilized is due to Xen
311*3a9fd824SRoger Pau Monné  *  using it as the Page Attribute Table (PAT) bit - for details on it please
312*3a9fd824SRoger Pau Monné  *  refer to Intel SDM 10.12. The PAT allows to set the caching attributes of
313*3a9fd824SRoger Pau Monné  *  pages instead of using MTRRs.
314*3a9fd824SRoger Pau Monné  *
315*3a9fd824SRoger Pau Monné  *  The PAT MSR is as follows (it is a 64-bit value, each entry is 8 bits):
316*3a9fd824SRoger Pau Monné  *                    PAT4                 PAT0
317*3a9fd824SRoger Pau Monné  *  +-----+-----+----+----+----+-----+----+----+
318*3a9fd824SRoger Pau Monné  *  | UC  | UC- | WC | WB | UC | UC- | WC | WB |  <= Linux
319*3a9fd824SRoger Pau Monné  *  +-----+-----+----+----+----+-----+----+----+
320*3a9fd824SRoger Pau Monné  *  | UC  | UC- | WT | WB | UC | UC- | WT | WB |  <= BIOS (default when machine boots)
321*3a9fd824SRoger Pau Monné  *  +-----+-----+----+----+----+-----+----+----+
322*3a9fd824SRoger Pau Monné  *  | rsv | rsv | WP | WC | UC | UC- | WT | WB |  <= Xen
323*3a9fd824SRoger Pau Monné  *  +-----+-----+----+----+----+-----+----+----+
324*3a9fd824SRoger Pau Monné  *
325*3a9fd824SRoger Pau Monné  *  The lookup of this index table translates to looking up
326*3a9fd824SRoger Pau Monné  *  Bit 7, Bit 4, and Bit 3 of val entry:
327*3a9fd824SRoger Pau Monné  *
328*3a9fd824SRoger Pau Monné  *  PAT/PSE (bit 7) ... PCD (bit 4) .. PWT (bit 3).
329*3a9fd824SRoger Pau Monné  *
330*3a9fd824SRoger Pau Monné  *  If all bits are off, then we are using PAT0. If bit 3 turned on,
331*3a9fd824SRoger Pau Monné  *  then we are using PAT1, if bit 3 and bit 4, then PAT2..
332*3a9fd824SRoger Pau Monné  *
333*3a9fd824SRoger Pau Monné  *  As you can see, the Linux PAT1 translates to PAT4 under Xen. Which means
334*3a9fd824SRoger Pau Monné  *  that if a guest that follows Linux's PAT setup and would like to set Write
335*3a9fd824SRoger Pau Monné  *  Combined on pages it MUST use PAT4 entry. Meaning that Bit 7 (PAGE_PAT) is
336*3a9fd824SRoger Pau Monné  *  set. For example, under Linux it only uses PAT0, PAT1, and PAT2 for the
337*3a9fd824SRoger Pau Monné  *  caching as:
338*3a9fd824SRoger Pau Monné  *
339*3a9fd824SRoger Pau Monné  *   WB = none (so PAT0)
340*3a9fd824SRoger Pau Monné  *   WC = PWT (bit 3 on)
341*3a9fd824SRoger Pau Monné  *   UC = PWT | PCD (bit 3 and 4 are on).
342*3a9fd824SRoger Pau Monné  *
343*3a9fd824SRoger Pau Monné  * To make it work with Xen, it needs to translate the WC bit as so:
344*3a9fd824SRoger Pau Monné  *
345*3a9fd824SRoger Pau Monné  *  PWT (so bit 3 on) --> PAT (so bit 7 is on) and clear bit 3
346*3a9fd824SRoger Pau Monné  *
347*3a9fd824SRoger Pau Monné  * And to translate back it would:
348*3a9fd824SRoger Pau Monné  *
349*3a9fd824SRoger Pau Monné  * PAT (bit 7 on) --> PWT (bit 3 on) and clear bit 7.
350*3a9fd824SRoger Pau Monné  */
351*3a9fd824SRoger Pau Monné #define MMU_NORMAL_PT_UPDATE       0 /* checked '*ptr = val'. ptr is MA.      */
352*3a9fd824SRoger Pau Monné #define MMU_MACHPHYS_UPDATE        1 /* ptr = MA of frame to modify entry for */
353*3a9fd824SRoger Pau Monné #define MMU_PT_UPDATE_PRESERVE_AD  2 /* atomically: *ptr = val | (*ptr&(A|D)) */
354*3a9fd824SRoger Pau Monné #define MMU_PT_UPDATE_NO_TRANSLATE 3 /* checked '*ptr = val'. ptr is MA.      */
355*3a9fd824SRoger Pau Monné                                      /* val never translated.                 */
356*3a9fd824SRoger Pau Monné 
357*3a9fd824SRoger Pau Monné /*
358*3a9fd824SRoger Pau Monné  * MMU EXTENDED OPERATIONS
359*3a9fd824SRoger Pau Monné  *
360*3a9fd824SRoger Pau Monné  * ` enum neg_errnoval
361*3a9fd824SRoger Pau Monné  * ` HYPERVISOR_mmuext_op(mmuext_op_t uops[],
362*3a9fd824SRoger Pau Monné  * `                      unsigned int count,
363*3a9fd824SRoger Pau Monné  * `                      unsigned int *pdone,
364*3a9fd824SRoger Pau Monné  * `                      unsigned int foreigndom)
365*3a9fd824SRoger Pau Monné  */
366*3a9fd824SRoger Pau Monné /* HYPERVISOR_mmuext_op() accepts a list of mmuext_op structures.
367*3a9fd824SRoger Pau Monné  * A foreigndom (FD) can be specified (or DOMID_SELF for none).
368*3a9fd824SRoger Pau Monné  * Where the FD has some effect, it is described below.
369*3a9fd824SRoger Pau Monné  *
370*3a9fd824SRoger Pau Monné  * cmd: MMUEXT_(UN)PIN_*_TABLE
371*3a9fd824SRoger Pau Monné  * mfn: Machine frame number to be (un)pinned as a p.t. page.
372*3a9fd824SRoger Pau Monné  *      The frame must belong to the FD, if one is specified.
373*3a9fd824SRoger Pau Monné  *
374*3a9fd824SRoger Pau Monné  * cmd: MMUEXT_NEW_BASEPTR
375*3a9fd824SRoger Pau Monné  * mfn: Machine frame number of new page-table base to install in MMU.
376*3a9fd824SRoger Pau Monné  *
377*3a9fd824SRoger Pau Monné  * cmd: MMUEXT_NEW_USER_BASEPTR [x86/64 only]
378*3a9fd824SRoger Pau Monné  * mfn: Machine frame number of new page-table base to install in MMU
379*3a9fd824SRoger Pau Monné  *      when in user space.
380*3a9fd824SRoger Pau Monné  *
381*3a9fd824SRoger Pau Monné  * cmd: MMUEXT_TLB_FLUSH_LOCAL
382*3a9fd824SRoger Pau Monné  * No additional arguments. Flushes local TLB.
383*3a9fd824SRoger Pau Monné  *
384*3a9fd824SRoger Pau Monné  * cmd: MMUEXT_INVLPG_LOCAL
385*3a9fd824SRoger Pau Monné  * linear_addr: Linear address to be flushed from the local TLB.
386*3a9fd824SRoger Pau Monné  *
387*3a9fd824SRoger Pau Monné  * cmd: MMUEXT_TLB_FLUSH_MULTI
388*3a9fd824SRoger Pau Monné  * vcpumask: Pointer to bitmap of VCPUs to be flushed.
389*3a9fd824SRoger Pau Monné  *
390*3a9fd824SRoger Pau Monné  * cmd: MMUEXT_INVLPG_MULTI
391*3a9fd824SRoger Pau Monné  * linear_addr: Linear address to be flushed.
392*3a9fd824SRoger Pau Monné  * vcpumask: Pointer to bitmap of VCPUs to be flushed.
393*3a9fd824SRoger Pau Monné  *
394*3a9fd824SRoger Pau Monné  * cmd: MMUEXT_TLB_FLUSH_ALL
395*3a9fd824SRoger Pau Monné  * No additional arguments. Flushes all VCPUs' TLBs.
396*3a9fd824SRoger Pau Monné  *
397*3a9fd824SRoger Pau Monné  * cmd: MMUEXT_INVLPG_ALL
398*3a9fd824SRoger Pau Monné  * linear_addr: Linear address to be flushed from all VCPUs' TLBs.
399*3a9fd824SRoger Pau Monné  *
400*3a9fd824SRoger Pau Monné  * cmd: MMUEXT_FLUSH_CACHE
401*3a9fd824SRoger Pau Monné  * No additional arguments. Writes back and flushes cache contents.
402*3a9fd824SRoger Pau Monné  *
403*3a9fd824SRoger Pau Monné  * cmd: MMUEXT_FLUSH_CACHE_GLOBAL
404*3a9fd824SRoger Pau Monné  * No additional arguments. Writes back and flushes cache contents
405*3a9fd824SRoger Pau Monné  * on all CPUs in the system.
406*3a9fd824SRoger Pau Monné  *
407*3a9fd824SRoger Pau Monné  * cmd: MMUEXT_SET_LDT
408*3a9fd824SRoger Pau Monné  * linear_addr: Linear address of LDT base (NB. must be page-aligned).
409*3a9fd824SRoger Pau Monné  * nr_ents: Number of entries in LDT.
410*3a9fd824SRoger Pau Monné  *
411*3a9fd824SRoger Pau Monné  * cmd: MMUEXT_CLEAR_PAGE
412*3a9fd824SRoger Pau Monné  * mfn: Machine frame number to be cleared.
413*3a9fd824SRoger Pau Monné  *
414*3a9fd824SRoger Pau Monné  * cmd: MMUEXT_COPY_PAGE
415*3a9fd824SRoger Pau Monné  * mfn: Machine frame number of the destination page.
416*3a9fd824SRoger Pau Monné  * src_mfn: Machine frame number of the source page.
417*3a9fd824SRoger Pau Monné  *
418*3a9fd824SRoger Pau Monné  * cmd: MMUEXT_[UN]MARK_SUPER
419*3a9fd824SRoger Pau Monné  * mfn: Machine frame number of head of superpage to be [un]marked.
420*3a9fd824SRoger Pau Monné  */
421*3a9fd824SRoger Pau Monné /* ` enum mmuext_cmd { */
422*3a9fd824SRoger Pau Monné #define MMUEXT_PIN_L1_TABLE      0
423*3a9fd824SRoger Pau Monné #define MMUEXT_PIN_L2_TABLE      1
424*3a9fd824SRoger Pau Monné #define MMUEXT_PIN_L3_TABLE      2
425*3a9fd824SRoger Pau Monné #define MMUEXT_PIN_L4_TABLE      3
426*3a9fd824SRoger Pau Monné #define MMUEXT_UNPIN_TABLE       4
427*3a9fd824SRoger Pau Monné #define MMUEXT_NEW_BASEPTR       5
428*3a9fd824SRoger Pau Monné #define MMUEXT_TLB_FLUSH_LOCAL   6
429*3a9fd824SRoger Pau Monné #define MMUEXT_INVLPG_LOCAL      7
430*3a9fd824SRoger Pau Monné #define MMUEXT_TLB_FLUSH_MULTI   8
431*3a9fd824SRoger Pau Monné #define MMUEXT_INVLPG_MULTI      9
432*3a9fd824SRoger Pau Monné #define MMUEXT_TLB_FLUSH_ALL    10
433*3a9fd824SRoger Pau Monné #define MMUEXT_INVLPG_ALL       11
434*3a9fd824SRoger Pau Monné #define MMUEXT_FLUSH_CACHE      12
435*3a9fd824SRoger Pau Monné #define MMUEXT_SET_LDT          13
436*3a9fd824SRoger Pau Monné #define MMUEXT_NEW_USER_BASEPTR 15
437*3a9fd824SRoger Pau Monné #define MMUEXT_CLEAR_PAGE       16
438*3a9fd824SRoger Pau Monné #define MMUEXT_COPY_PAGE        17
439*3a9fd824SRoger Pau Monné #define MMUEXT_FLUSH_CACHE_GLOBAL 18
440*3a9fd824SRoger Pau Monné #define MMUEXT_MARK_SUPER       19
441*3a9fd824SRoger Pau Monné #define MMUEXT_UNMARK_SUPER     20
442*3a9fd824SRoger Pau Monné /* ` } */
443*3a9fd824SRoger Pau Monné 
444*3a9fd824SRoger Pau Monné #ifndef __ASSEMBLY__
445*3a9fd824SRoger Pau Monné struct mmuext_op {
446*3a9fd824SRoger Pau Monné     unsigned int cmd; /* => enum mmuext_cmd */
447*3a9fd824SRoger Pau Monné     union {
448*3a9fd824SRoger Pau Monné         /* [UN]PIN_TABLE, NEW_BASEPTR, NEW_USER_BASEPTR
449*3a9fd824SRoger Pau Monné          * CLEAR_PAGE, COPY_PAGE, [UN]MARK_SUPER */
450*3a9fd824SRoger Pau Monné         xen_pfn_t     mfn;
451*3a9fd824SRoger Pau Monné         /* INVLPG_LOCAL, INVLPG_ALL, SET_LDT */
452*3a9fd824SRoger Pau Monné         unsigned long linear_addr;
453*3a9fd824SRoger Pau Monné     } arg1;
454*3a9fd824SRoger Pau Monné     union {
455*3a9fd824SRoger Pau Monné         /* SET_LDT */
456*3a9fd824SRoger Pau Monné         unsigned int nr_ents;
457*3a9fd824SRoger Pau Monné         /* TLB_FLUSH_MULTI, INVLPG_MULTI */
458*3a9fd824SRoger Pau Monné #if __XEN_INTERFACE_VERSION__ >= 0x00030205
459*3a9fd824SRoger Pau Monné         XEN_GUEST_HANDLE(const_void) vcpumask;
460*3a9fd824SRoger Pau Monné #else
461*3a9fd824SRoger Pau Monné         const void *vcpumask;
462*3a9fd824SRoger Pau Monné #endif
463*3a9fd824SRoger Pau Monné         /* COPY_PAGE */
464*3a9fd824SRoger Pau Monné         xen_pfn_t src_mfn;
465*3a9fd824SRoger Pau Monné     } arg2;
466*3a9fd824SRoger Pau Monné };
467*3a9fd824SRoger Pau Monné typedef struct mmuext_op mmuext_op_t;
468*3a9fd824SRoger Pau Monné DEFINE_XEN_GUEST_HANDLE(mmuext_op_t);
469*3a9fd824SRoger Pau Monné #endif
470*3a9fd824SRoger Pau Monné 
471*3a9fd824SRoger Pau Monné /*
472*3a9fd824SRoger Pau Monné  * ` enum neg_errnoval
473*3a9fd824SRoger Pau Monné  * ` HYPERVISOR_update_va_mapping(unsigned long va, u64 val,
474*3a9fd824SRoger Pau Monné  * `                              enum uvm_flags flags)
475*3a9fd824SRoger Pau Monné  * `
476*3a9fd824SRoger Pau Monné  * ` enum neg_errnoval
477*3a9fd824SRoger Pau Monné  * ` HYPERVISOR_update_va_mapping_otherdomain(unsigned long va, u64 val,
478*3a9fd824SRoger Pau Monné  * `                                          enum uvm_flags flags,
479*3a9fd824SRoger Pau Monné  * `                                          domid_t domid)
480*3a9fd824SRoger Pau Monné  * `
481*3a9fd824SRoger Pau Monné  * ` @va: The virtual address whose mapping we want to change
482*3a9fd824SRoger Pau Monné  * ` @val: The new page table entry, must contain a machine address
483*3a9fd824SRoger Pau Monné  * ` @flags: Control TLB flushes
484*3a9fd824SRoger Pau Monné  */
485*3a9fd824SRoger Pau Monné /* These are passed as 'flags' to update_va_mapping. They can be ORed. */
486*3a9fd824SRoger Pau Monné /* When specifying UVMF_MULTI, also OR in a pointer to a CPU bitmap.   */
487*3a9fd824SRoger Pau Monné /* UVMF_LOCAL is merely UVMF_MULTI with a NULL bitmap pointer.         */
488*3a9fd824SRoger Pau Monné /* ` enum uvm_flags { */
489*3a9fd824SRoger Pau Monné #define UVMF_NONE           (xen_mk_ulong(0)<<0) /* No flushing at all.   */
490*3a9fd824SRoger Pau Monné #define UVMF_TLB_FLUSH      (xen_mk_ulong(1)<<0) /* Flush entire TLB(s).  */
491*3a9fd824SRoger Pau Monné #define UVMF_INVLPG         (xen_mk_ulong(2)<<0) /* Flush only one entry. */
492*3a9fd824SRoger Pau Monné #define UVMF_FLUSHTYPE_MASK (xen_mk_ulong(3)<<0)
493*3a9fd824SRoger Pau Monné #define UVMF_MULTI          (xen_mk_ulong(0)<<2) /* Flush subset of TLBs. */
494*3a9fd824SRoger Pau Monné #define UVMF_LOCAL          (xen_mk_ulong(0)<<2) /* Flush local TLB.      */
495*3a9fd824SRoger Pau Monné #define UVMF_ALL            (xen_mk_ulong(1)<<2) /* Flush all TLBs.       */
496*3a9fd824SRoger Pau Monné /* ` } */
497*3a9fd824SRoger Pau Monné 
498*3a9fd824SRoger Pau Monné /*
499*3a9fd824SRoger Pau Monné  * ` int
500*3a9fd824SRoger Pau Monné  * ` HYPERVISOR_console_io(unsigned int cmd,
501*3a9fd824SRoger Pau Monné  * `                       unsigned int count,
502*3a9fd824SRoger Pau Monné  * `                       char buffer[]);
503*3a9fd824SRoger Pau Monné  *
504*3a9fd824SRoger Pau Monné  * @cmd: Command (see below)
505*3a9fd824SRoger Pau Monné  * @count: Size of the buffer to read/write
506*3a9fd824SRoger Pau Monné  * @buffer: Pointer in the guest memory
507*3a9fd824SRoger Pau Monné  *
508*3a9fd824SRoger Pau Monné  * List of commands:
509*3a9fd824SRoger Pau Monné  *
510*3a9fd824SRoger Pau Monné  *  * CONSOLEIO_write: Write the buffer to Xen console.
511*3a9fd824SRoger Pau Monné  *      For the hardware domain, all the characters in the buffer will
512*3a9fd824SRoger Pau Monné  *      be written. Characters will be printed directly to the console.
513*3a9fd824SRoger Pau Monné  *      For all the other domains, only the printable characters will be
514*3a9fd824SRoger Pau Monné  *      written. Characters may be buffered until a newline (i.e '\n') is
515*3a9fd824SRoger Pau Monné  *      found.
516*3a9fd824SRoger Pau Monné  *      @return 0 on success, otherwise return an error code.
517*3a9fd824SRoger Pau Monné  *  * CONSOLEIO_read: Attempts to read up to @count characters from Xen
518*3a9fd824SRoger Pau Monné  *      console. The maximum buffer size (i.e. @count) supported is 2GB.
519*3a9fd824SRoger Pau Monné  *      @return the number of characters read on success, otherwise return
520*3a9fd824SRoger Pau Monné  *      an error code.
521*3a9fd824SRoger Pau Monné  */
522*3a9fd824SRoger Pau Monné #define CONSOLEIO_write         0
523*3a9fd824SRoger Pau Monné #define CONSOLEIO_read          1
524*3a9fd824SRoger Pau Monné 
525*3a9fd824SRoger Pau Monné /*
526*3a9fd824SRoger Pau Monné  * Commands to HYPERVISOR_vm_assist().
527*3a9fd824SRoger Pau Monné  */
528*3a9fd824SRoger Pau Monné #define VMASST_CMD_enable                0
529*3a9fd824SRoger Pau Monné #define VMASST_CMD_disable               1
530*3a9fd824SRoger Pau Monné 
531*3a9fd824SRoger Pau Monné /* x86/32 guests: simulate full 4GB segment limits. */
532*3a9fd824SRoger Pau Monné #define VMASST_TYPE_4gb_segments         0
533*3a9fd824SRoger Pau Monné 
534*3a9fd824SRoger Pau Monné /* x86/32 guests: trap (vector 15) whenever above vmassist is used. */
535*3a9fd824SRoger Pau Monné #define VMASST_TYPE_4gb_segments_notify  1
536*3a9fd824SRoger Pau Monné 
537*3a9fd824SRoger Pau Monné /*
538*3a9fd824SRoger Pau Monné  * x86 guests: support writes to bottom-level PTEs.
539*3a9fd824SRoger Pau Monné  * NB1. Page-directory entries cannot be written.
540*3a9fd824SRoger Pau Monné  * NB2. Guest must continue to remove all writable mappings of PTEs.
541*3a9fd824SRoger Pau Monné  */
542*3a9fd824SRoger Pau Monné #define VMASST_TYPE_writable_pagetables  2
543*3a9fd824SRoger Pau Monné 
544*3a9fd824SRoger Pau Monné /* x86/PAE guests: support PDPTs above 4GB. */
545*3a9fd824SRoger Pau Monné #define VMASST_TYPE_pae_extended_cr3     3
546*3a9fd824SRoger Pau Monné 
547*3a9fd824SRoger Pau Monné /*
548*3a9fd824SRoger Pau Monné  * x86 guests: Sane behaviour for virtual iopl
549*3a9fd824SRoger Pau Monné  *  - virtual iopl updated from do_iret() hypercalls.
550*3a9fd824SRoger Pau Monné  *  - virtual iopl reported in bounce frames.
551*3a9fd824SRoger Pau Monné  *  - guest kernels assumed to be level 0 for the purpose of iopl checks.
552*3a9fd824SRoger Pau Monné  */
553*3a9fd824SRoger Pau Monné #define VMASST_TYPE_architectural_iopl   4
554*3a9fd824SRoger Pau Monné 
555*3a9fd824SRoger Pau Monné /*
556*3a9fd824SRoger Pau Monné  * All guests: activate update indicator in vcpu_runstate_info
557*3a9fd824SRoger Pau Monné  * Enable setting the XEN_RUNSTATE_UPDATE flag in guest memory mapped
558*3a9fd824SRoger Pau Monné  * vcpu_runstate_info during updates of the runstate information.
559*3a9fd824SRoger Pau Monné  */
560*3a9fd824SRoger Pau Monné #define VMASST_TYPE_runstate_update_flag 5
561*3a9fd824SRoger Pau Monné 
562*3a9fd824SRoger Pau Monné /*
563*3a9fd824SRoger Pau Monné  * x86/64 guests: strictly hide M2P from user mode.
564*3a9fd824SRoger Pau Monné  * This allows the guest to control respective hypervisor behavior:
565*3a9fd824SRoger Pau Monné  * - when not set, L4 tables get created with the respective slot blank,
566*3a9fd824SRoger Pau Monné  *   and whenever the L4 table gets used as a kernel one the missing
567*3a9fd824SRoger Pau Monné  *   mapping gets inserted,
568*3a9fd824SRoger Pau Monné  * - when set, L4 tables get created with the respective slot initialized
569*3a9fd824SRoger Pau Monné  *   as before, and whenever the L4 table gets used as a user one the
570*3a9fd824SRoger Pau Monné  *   mapping gets zapped.
571*3a9fd824SRoger Pau Monné  */
572*3a9fd824SRoger Pau Monné #define VMASST_TYPE_m2p_strict           32
573*3a9fd824SRoger Pau Monné 
574*3a9fd824SRoger Pau Monné #if __XEN_INTERFACE_VERSION__ < 0x00040600
575*3a9fd824SRoger Pau Monné #define MAX_VMASST_TYPE                  3
576*3a9fd824SRoger Pau Monné #endif
577*3a9fd824SRoger Pau Monné 
578*3a9fd824SRoger Pau Monné /* Domain ids >= DOMID_FIRST_RESERVED cannot be used for ordinary domains. */
579*3a9fd824SRoger Pau Monné #define DOMID_FIRST_RESERVED xen_mk_uint(0x7FF0)
580*3a9fd824SRoger Pau Monné 
581*3a9fd824SRoger Pau Monné /* DOMID_SELF is used in certain contexts to refer to oneself. */
582*3a9fd824SRoger Pau Monné #define DOMID_SELF           xen_mk_uint(0x7FF0)
583*3a9fd824SRoger Pau Monné 
584*3a9fd824SRoger Pau Monné /*
585*3a9fd824SRoger Pau Monné  * DOMID_IO is used to restrict page-table updates to mapping I/O memory.
586*3a9fd824SRoger Pau Monné  * Although no Foreign Domain need be specified to map I/O pages, DOMID_IO
587*3a9fd824SRoger Pau Monné  * is useful to ensure that no mappings to the OS's own heap are accidentally
588*3a9fd824SRoger Pau Monné  * installed. (e.g., in Linux this could cause havoc as reference counts
589*3a9fd824SRoger Pau Monné  * aren't adjusted on the I/O-mapping code path).
590*3a9fd824SRoger Pau Monné  * This only makes sense as HYPERVISOR_mmu_update()'s and
591*3a9fd824SRoger Pau Monné  * HYPERVISOR_update_va_mapping_otherdomain()'s "foreigndom" argument. For
592*3a9fd824SRoger Pau Monné  * HYPERVISOR_mmu_update() context it can be specified by any calling domain,
593*3a9fd824SRoger Pau Monné  * otherwise it's only permitted if the caller is privileged.
594*3a9fd824SRoger Pau Monné  */
595*3a9fd824SRoger Pau Monné #define DOMID_IO             xen_mk_uint(0x7FF1)
596*3a9fd824SRoger Pau Monné 
597*3a9fd824SRoger Pau Monné /*
598*3a9fd824SRoger Pau Monné  * DOMID_XEN is used to allow privileged domains to map restricted parts of
599*3a9fd824SRoger Pau Monné  * Xen's heap space (e.g., the machine_to_phys table).
600*3a9fd824SRoger Pau Monné  * This only makes sense as
601*3a9fd824SRoger Pau Monné  * - HYPERVISOR_mmu_update()'s, HYPERVISOR_mmuext_op()'s, or
602*3a9fd824SRoger Pau Monné  *   HYPERVISOR_update_va_mapping_otherdomain()'s "foreigndom" argument,
603*3a9fd824SRoger Pau Monné  * - with XENMAPSPACE_gmfn_foreign,
604*3a9fd824SRoger Pau Monné  * and is only permitted if the caller is privileged.
605*3a9fd824SRoger Pau Monné  */
606*3a9fd824SRoger Pau Monné #define DOMID_XEN            xen_mk_uint(0x7FF2)
607*3a9fd824SRoger Pau Monné 
608*3a9fd824SRoger Pau Monné /*
609*3a9fd824SRoger Pau Monné  * DOMID_COW is used as the owner of sharable pages */
610*3a9fd824SRoger Pau Monné #define DOMID_COW            xen_mk_uint(0x7FF3)
611*3a9fd824SRoger Pau Monné 
612*3a9fd824SRoger Pau Monné /* DOMID_INVALID is used to identify pages with unknown owner. */
613*3a9fd824SRoger Pau Monné #define DOMID_INVALID        xen_mk_uint(0x7FF4)
614*3a9fd824SRoger Pau Monné 
615*3a9fd824SRoger Pau Monné /* Idle domain. */
616*3a9fd824SRoger Pau Monné #define DOMID_IDLE           xen_mk_uint(0x7FFF)
617*3a9fd824SRoger Pau Monné 
618*3a9fd824SRoger Pau Monné /* Mask for valid domain id values */
619*3a9fd824SRoger Pau Monné #define DOMID_MASK           xen_mk_uint(0x7FFF)
620*3a9fd824SRoger Pau Monné 
621*3a9fd824SRoger Pau Monné #ifndef __ASSEMBLY__
622*3a9fd824SRoger Pau Monné 
623*3a9fd824SRoger Pau Monné typedef uint16_t domid_t;
624*3a9fd824SRoger Pau Monné 
625*3a9fd824SRoger Pau Monné /*
626*3a9fd824SRoger Pau Monné  * Send an array of these to HYPERVISOR_mmu_update().
627*3a9fd824SRoger Pau Monné  * NB. The fields are natural pointer/address size for this architecture.
628*3a9fd824SRoger Pau Monné  */
629*3a9fd824SRoger Pau Monné struct mmu_update {
630*3a9fd824SRoger Pau Monné     uint64_t ptr;       /* Machine address of PTE. */
631*3a9fd824SRoger Pau Monné     uint64_t val;       /* New contents of PTE.    */
632*3a9fd824SRoger Pau Monné };
633*3a9fd824SRoger Pau Monné typedef struct mmu_update mmu_update_t;
634*3a9fd824SRoger Pau Monné DEFINE_XEN_GUEST_HANDLE(mmu_update_t);
635*3a9fd824SRoger Pau Monné 
636*3a9fd824SRoger Pau Monné /*
637*3a9fd824SRoger Pau Monné  * ` enum neg_errnoval
638*3a9fd824SRoger Pau Monné  * ` HYPERVISOR_multicall(multicall_entry_t call_list[],
639*3a9fd824SRoger Pau Monné  * `                      uint32_t nr_calls);
640*3a9fd824SRoger Pau Monné  *
641*3a9fd824SRoger Pau Monné  * NB. The fields are logically the natural register size for this
642*3a9fd824SRoger Pau Monné  * architecture. In cases where xen_ulong_t is larger than this then
643*3a9fd824SRoger Pau Monné  * any unused bits in the upper portion must be zero.
644*3a9fd824SRoger Pau Monné  */
645*3a9fd824SRoger Pau Monné struct multicall_entry {
646*3a9fd824SRoger Pau Monné     xen_ulong_t op, result;
647*3a9fd824SRoger Pau Monné     xen_ulong_t args[6];
648*3a9fd824SRoger Pau Monné };
649*3a9fd824SRoger Pau Monné typedef struct multicall_entry multicall_entry_t;
650*3a9fd824SRoger Pau Monné DEFINE_XEN_GUEST_HANDLE(multicall_entry_t);
651*3a9fd824SRoger Pau Monné 
652*3a9fd824SRoger Pau Monné #if __XEN_INTERFACE_VERSION__ < 0x00040400
653*3a9fd824SRoger Pau Monné /*
654*3a9fd824SRoger Pau Monné  * Event channel endpoints per domain (when using the 2-level ABI):
655*3a9fd824SRoger Pau Monné  *  1024 if a long is 32 bits; 4096 if a long is 64 bits.
656*3a9fd824SRoger Pau Monné  */
657*3a9fd824SRoger Pau Monné #define NR_EVENT_CHANNELS EVTCHN_2L_NR_CHANNELS
658*3a9fd824SRoger Pau Monné #endif
659*3a9fd824SRoger Pau Monné 
660*3a9fd824SRoger Pau Monné struct vcpu_time_info {
661*3a9fd824SRoger Pau Monné     /*
662*3a9fd824SRoger Pau Monné      * Updates to the following values are preceded and followed by an
663*3a9fd824SRoger Pau Monné      * increment of 'version'. The guest can therefore detect updates by
664*3a9fd824SRoger Pau Monné      * looking for changes to 'version'. If the least-significant bit of
665*3a9fd824SRoger Pau Monné      * the version number is set then an update is in progress and the guest
666*3a9fd824SRoger Pau Monné      * must wait to read a consistent set of values.
667*3a9fd824SRoger Pau Monné      * The correct way to interact with the version number is similar to
668*3a9fd824SRoger Pau Monné      * Linux's seqlock: see the implementations of read_seqbegin/read_seqretry.
669*3a9fd824SRoger Pau Monné      */
670*3a9fd824SRoger Pau Monné     uint32_t version;
671*3a9fd824SRoger Pau Monné     uint32_t pad0;
672*3a9fd824SRoger Pau Monné     uint64_t tsc_timestamp;   /* TSC at last update of time vals.  */
673*3a9fd824SRoger Pau Monné     uint64_t system_time;     /* Time, in nanosecs, since boot.    */
674*3a9fd824SRoger Pau Monné     /*
675*3a9fd824SRoger Pau Monné      * Current system time:
676*3a9fd824SRoger Pau Monné      *   system_time +
677*3a9fd824SRoger Pau Monné      *   ((((tsc - tsc_timestamp) << tsc_shift) * tsc_to_system_mul) >> 32)
678*3a9fd824SRoger Pau Monné      * CPU frequency (Hz):
679*3a9fd824SRoger Pau Monné      *   ((10^9 << 32) / tsc_to_system_mul) >> tsc_shift
680*3a9fd824SRoger Pau Monné      */
681*3a9fd824SRoger Pau Monné     uint32_t tsc_to_system_mul;
682*3a9fd824SRoger Pau Monné     int8_t   tsc_shift;
683*3a9fd824SRoger Pau Monné #if __XEN_INTERFACE_VERSION__ > 0x040600
684*3a9fd824SRoger Pau Monné     uint8_t  flags;
685*3a9fd824SRoger Pau Monné     uint8_t  pad1[2];
686*3a9fd824SRoger Pau Monné #else
687*3a9fd824SRoger Pau Monné     int8_t   pad1[3];
688*3a9fd824SRoger Pau Monné #endif
689*3a9fd824SRoger Pau Monné }; /* 32 bytes */
690*3a9fd824SRoger Pau Monné typedef struct vcpu_time_info vcpu_time_info_t;
691*3a9fd824SRoger Pau Monné 
692*3a9fd824SRoger Pau Monné #define XEN_PVCLOCK_TSC_STABLE_BIT     (1 << 0)
693*3a9fd824SRoger Pau Monné #define XEN_PVCLOCK_GUEST_STOPPED      (1 << 1)
694*3a9fd824SRoger Pau Monné 
695*3a9fd824SRoger Pau Monné struct vcpu_info {
696*3a9fd824SRoger Pau Monné     /*
697*3a9fd824SRoger Pau Monné      * 'evtchn_upcall_pending' is written non-zero by Xen to indicate
698*3a9fd824SRoger Pau Monné      * a pending notification for a particular VCPU. It is then cleared
699*3a9fd824SRoger Pau Monné      * by the guest OS /before/ checking for pending work, thus avoiding
700*3a9fd824SRoger Pau Monné      * a set-and-check race. Note that the mask is only accessed by Xen
701*3a9fd824SRoger Pau Monné      * on the CPU that is currently hosting the VCPU. This means that the
702*3a9fd824SRoger Pau Monné      * pending and mask flags can be updated by the guest without special
703*3a9fd824SRoger Pau Monné      * synchronisation (i.e., no need for the x86 LOCK prefix).
704*3a9fd824SRoger Pau Monné      * This may seem suboptimal because if the pending flag is set by
705*3a9fd824SRoger Pau Monné      * a different CPU then an IPI may be scheduled even when the mask
706*3a9fd824SRoger Pau Monné      * is set. However, note:
707*3a9fd824SRoger Pau Monné      *  1. The task of 'interrupt holdoff' is covered by the per-event-
708*3a9fd824SRoger Pau Monné      *     channel mask bits. A 'noisy' event that is continually being
709*3a9fd824SRoger Pau Monné      *     triggered can be masked at source at this very precise
710*3a9fd824SRoger Pau Monné      *     granularity.
711*3a9fd824SRoger Pau Monné      *  2. The main purpose of the per-VCPU mask is therefore to restrict
712*3a9fd824SRoger Pau Monné      *     reentrant execution: whether for concurrency control, or to
713*3a9fd824SRoger Pau Monné      *     prevent unbounded stack usage. Whatever the purpose, we expect
714*3a9fd824SRoger Pau Monné      *     that the mask will be asserted only for short periods at a time,
715*3a9fd824SRoger Pau Monné      *     and so the likelihood of a 'spurious' IPI is suitably small.
716*3a9fd824SRoger Pau Monné      * The mask is read before making an event upcall to the guest: a
717*3a9fd824SRoger Pau Monné      * non-zero mask therefore guarantees that the VCPU will not receive
718*3a9fd824SRoger Pau Monné      * an upcall activation. The mask is cleared when the VCPU requests
719*3a9fd824SRoger Pau Monné      * to block: this avoids wakeup-waiting races.
720*3a9fd824SRoger Pau Monné      */
721*3a9fd824SRoger Pau Monné     uint8_t evtchn_upcall_pending;
722*3a9fd824SRoger Pau Monné #ifdef XEN_HAVE_PV_UPCALL_MASK
723*3a9fd824SRoger Pau Monné     uint8_t evtchn_upcall_mask;
724*3a9fd824SRoger Pau Monné #else /* XEN_HAVE_PV_UPCALL_MASK */
725*3a9fd824SRoger Pau Monné     uint8_t pad0;
726*3a9fd824SRoger Pau Monné #endif /* XEN_HAVE_PV_UPCALL_MASK */
727*3a9fd824SRoger Pau Monné     xen_ulong_t evtchn_pending_sel;
728*3a9fd824SRoger Pau Monné     struct arch_vcpu_info arch;
729*3a9fd824SRoger Pau Monné     vcpu_time_info_t time;
730*3a9fd824SRoger Pau Monné }; /* 64 bytes (x86) */
731*3a9fd824SRoger Pau Monné #ifndef __XEN__
732*3a9fd824SRoger Pau Monné typedef struct vcpu_info vcpu_info_t;
733*3a9fd824SRoger Pau Monné #endif
734*3a9fd824SRoger Pau Monné 
735*3a9fd824SRoger Pau Monné /*
736*3a9fd824SRoger Pau Monné  * `incontents 200 startofday_shared Start-of-day shared data structure
737*3a9fd824SRoger Pau Monné  * Xen/kernel shared data -- pointer provided in start_info.
738*3a9fd824SRoger Pau Monné  *
739*3a9fd824SRoger Pau Monné  * This structure is defined to be both smaller than a page, and the
740*3a9fd824SRoger Pau Monné  * only data on the shared page, but may vary in actual size even within
741*3a9fd824SRoger Pau Monné  * compatible Xen versions; guests should not rely on the size
742*3a9fd824SRoger Pau Monné  * of this structure remaining constant.
743*3a9fd824SRoger Pau Monné  */
744*3a9fd824SRoger Pau Monné struct shared_info {
745*3a9fd824SRoger Pau Monné     struct vcpu_info vcpu_info[XEN_LEGACY_MAX_VCPUS];
746*3a9fd824SRoger Pau Monné 
747*3a9fd824SRoger Pau Monné     /*
748*3a9fd824SRoger Pau Monné      * A domain can create "event channels" on which it can send and receive
749*3a9fd824SRoger Pau Monné      * asynchronous event notifications. There are three classes of event that
750*3a9fd824SRoger Pau Monné      * are delivered by this mechanism:
751*3a9fd824SRoger Pau Monné      *  1. Bi-directional inter- and intra-domain connections. Domains must
752*3a9fd824SRoger Pau Monné      *     arrange out-of-band to set up a connection (usually by allocating
753*3a9fd824SRoger Pau Monné      *     an unbound 'listener' port and avertising that via a storage service
754*3a9fd824SRoger Pau Monné      *     such as xenstore).
755*3a9fd824SRoger Pau Monné      *  2. Physical interrupts. A domain with suitable hardware-access
756*3a9fd824SRoger Pau Monné      *     privileges can bind an event-channel port to a physical interrupt
757*3a9fd824SRoger Pau Monné      *     source.
758*3a9fd824SRoger Pau Monné      *  3. Virtual interrupts ('events'). A domain can bind an event-channel
759*3a9fd824SRoger Pau Monné      *     port to a virtual interrupt source, such as the virtual-timer
760*3a9fd824SRoger Pau Monné      *     device or the emergency console.
761*3a9fd824SRoger Pau Monné      *
762*3a9fd824SRoger Pau Monné      * Event channels are addressed by a "port index". Each channel is
763*3a9fd824SRoger Pau Monné      * associated with two bits of information:
764*3a9fd824SRoger Pau Monné      *  1. PENDING -- notifies the domain that there is a pending notification
765*3a9fd824SRoger Pau Monné      *     to be processed. This bit is cleared by the guest.
766*3a9fd824SRoger Pau Monné      *  2. MASK -- if this bit is clear then a 0->1 transition of PENDING
767*3a9fd824SRoger Pau Monné      *     will cause an asynchronous upcall to be scheduled. This bit is only
768*3a9fd824SRoger Pau Monné      *     updated by the guest. It is read-only within Xen. If a channel
769*3a9fd824SRoger Pau Monné      *     becomes pending while the channel is masked then the 'edge' is lost
770*3a9fd824SRoger Pau Monné      *     (i.e., when the channel is unmasked, the guest must manually handle
771*3a9fd824SRoger Pau Monné      *     pending notifications as no upcall will be scheduled by Xen).
772*3a9fd824SRoger Pau Monné      *
773*3a9fd824SRoger Pau Monné      * To expedite scanning of pending notifications, any 0->1 pending
774*3a9fd824SRoger Pau Monné      * transition on an unmasked channel causes a corresponding bit in a
775*3a9fd824SRoger Pau Monné      * per-vcpu selector word to be set. Each bit in the selector covers a
776*3a9fd824SRoger Pau Monné      * 'C long' in the PENDING bitfield array.
777*3a9fd824SRoger Pau Monné      */
778*3a9fd824SRoger Pau Monné     xen_ulong_t evtchn_pending[sizeof(xen_ulong_t) * 8];
779*3a9fd824SRoger Pau Monné     xen_ulong_t evtchn_mask[sizeof(xen_ulong_t) * 8];
780*3a9fd824SRoger Pau Monné 
781*3a9fd824SRoger Pau Monné     /*
782*3a9fd824SRoger Pau Monné      * Wallclock time: updated by control software or RTC emulation.
783*3a9fd824SRoger Pau Monné      * Guests should base their gettimeofday() syscall on this
784*3a9fd824SRoger Pau Monné      * wallclock-base value.
785*3a9fd824SRoger Pau Monné      * The values of wc_sec and wc_nsec are offsets from the Unix epoch
786*3a9fd824SRoger Pau Monné      * adjusted by the domain's 'time offset' (in seconds) as set either
787*3a9fd824SRoger Pau Monné      * by XEN_DOMCTL_settimeoffset, or adjusted via a guest write to the
788*3a9fd824SRoger Pau Monné      * emulated RTC.
789*3a9fd824SRoger Pau Monné      */
790*3a9fd824SRoger Pau Monné     uint32_t wc_version;      /* Version counter: see vcpu_time_info_t. */
791*3a9fd824SRoger Pau Monné     uint32_t wc_sec;
792*3a9fd824SRoger Pau Monné     uint32_t wc_nsec;
793*3a9fd824SRoger Pau Monné #if !defined(__i386__)
794*3a9fd824SRoger Pau Monné     uint32_t wc_sec_hi;
795*3a9fd824SRoger Pau Monné # define xen_wc_sec_hi wc_sec_hi
796*3a9fd824SRoger Pau Monné #elif !defined(__XEN__) && !defined(__XEN_TOOLS__)
797*3a9fd824SRoger Pau Monné # define xen_wc_sec_hi arch.wc_sec_hi
798*3a9fd824SRoger Pau Monné #endif
799*3a9fd824SRoger Pau Monné 
800*3a9fd824SRoger Pau Monné     struct arch_shared_info arch;
801*3a9fd824SRoger Pau Monné 
802*3a9fd824SRoger Pau Monné };
803*3a9fd824SRoger Pau Monné #ifndef __XEN__
804*3a9fd824SRoger Pau Monné typedef struct shared_info shared_info_t;
805*3a9fd824SRoger Pau Monné #endif
806*3a9fd824SRoger Pau Monné 
807*3a9fd824SRoger Pau Monné /*
808*3a9fd824SRoger Pau Monné  * `incontents 200 startofday Start-of-day memory layout
809*3a9fd824SRoger Pau Monné  *
810*3a9fd824SRoger Pau Monné  *  1. The domain is started within contiguous virtual-memory region.
811*3a9fd824SRoger Pau Monné  *  2. The contiguous region ends on an aligned 4MB boundary.
812*3a9fd824SRoger Pau Monné  *  3. This the order of bootstrap elements in the initial virtual region:
813*3a9fd824SRoger Pau Monné  *      a. relocated kernel image
814*3a9fd824SRoger Pau Monné  *      b. initial ram disk              [mod_start, mod_len]
815*3a9fd824SRoger Pau Monné  *         (may be omitted)
816*3a9fd824SRoger Pau Monné  *      c. list of allocated page frames [mfn_list, nr_pages]
817*3a9fd824SRoger Pau Monné  *         (unless relocated due to XEN_ELFNOTE_INIT_P2M)
818*3a9fd824SRoger Pau Monné  *      d. start_info_t structure        [register rSI (x86)]
819*3a9fd824SRoger Pau Monné  *         in case of dom0 this page contains the console info, too
820*3a9fd824SRoger Pau Monné  *      e. unless dom0: xenstore ring page
821*3a9fd824SRoger Pau Monné  *      f. unless dom0: console ring page
822*3a9fd824SRoger Pau Monné  *      g. bootstrap page tables         [pt_base and CR3 (x86)]
823*3a9fd824SRoger Pau Monné  *      h. bootstrap stack               [register ESP (x86)]
824*3a9fd824SRoger Pau Monné  *  4. Bootstrap elements are packed together, but each is 4kB-aligned.
825*3a9fd824SRoger Pau Monné  *  5. The list of page frames forms a contiguous 'pseudo-physical' memory
826*3a9fd824SRoger Pau Monné  *     layout for the domain. In particular, the bootstrap virtual-memory
827*3a9fd824SRoger Pau Monné  *     region is a 1:1 mapping to the first section of the pseudo-physical map.
828*3a9fd824SRoger Pau Monné  *  6. All bootstrap elements are mapped read-writable for the guest OS. The
829*3a9fd824SRoger Pau Monné  *     only exception is the bootstrap page table, which is mapped read-only.
830*3a9fd824SRoger Pau Monné  *  7. There is guaranteed to be at least 512kB padding after the final
831*3a9fd824SRoger Pau Monné  *     bootstrap element. If necessary, the bootstrap virtual region is
832*3a9fd824SRoger Pau Monné  *     extended by an extra 4MB to ensure this.
833*3a9fd824SRoger Pau Monné  *
834*3a9fd824SRoger Pau Monné  * Note: Prior to 25833:bb85bbccb1c9. ("x86/32-on-64 adjust Dom0 initial page
835*3a9fd824SRoger Pau Monné  * table layout") a bug caused the pt_base (3.g above) and cr3 to not point
836*3a9fd824SRoger Pau Monné  * to the start of the guest page tables (it was offset by two pages).
837*3a9fd824SRoger Pau Monné  * This only manifested itself on 32-on-64 dom0 kernels and not 32-on-64 domU
838*3a9fd824SRoger Pau Monné  * or 64-bit kernels of any colour. The page tables for a 32-on-64 dom0 got
839*3a9fd824SRoger Pau Monné  * allocated in the order: 'first L1','first L2', 'first L3', so the offset
840*3a9fd824SRoger Pau Monné  * to the page table base is by two pages back. The initial domain if it is
841*3a9fd824SRoger Pau Monné  * 32-bit and runs under a 64-bit hypervisor should _NOT_ use two of the
842*3a9fd824SRoger Pau Monné  * pages preceding pt_base and mark them as reserved/unused.
843*3a9fd824SRoger Pau Monné  */
844*3a9fd824SRoger Pau Monné #ifdef XEN_HAVE_PV_GUEST_ENTRY
845*3a9fd824SRoger Pau Monné struct start_info {
846*3a9fd824SRoger Pau Monné     /* THE FOLLOWING ARE FILLED IN BOTH ON INITIAL BOOT AND ON RESUME.    */
847*3a9fd824SRoger Pau Monné     char magic[32];             /* "xen-<version>-<platform>".            */
848*3a9fd824SRoger Pau Monné     unsigned long nr_pages;     /* Total pages allocated to this domain.  */
849*3a9fd824SRoger Pau Monné     unsigned long shared_info;  /* MACHINE address of shared info struct. */
850*3a9fd824SRoger Pau Monné     uint32_t flags;             /* SIF_xxx flags.                         */
851*3a9fd824SRoger Pau Monné     xen_pfn_t store_mfn;        /* MACHINE page number of shared page.    */
852*3a9fd824SRoger Pau Monné     uint32_t store_evtchn;      /* Event channel for store communication. */
853*3a9fd824SRoger Pau Monné     union {
854*3a9fd824SRoger Pau Monné         struct {
855*3a9fd824SRoger Pau Monné             xen_pfn_t mfn;      /* MACHINE page number of console page.   */
856*3a9fd824SRoger Pau Monné             uint32_t  evtchn;   /* Event channel for console page.        */
857*3a9fd824SRoger Pau Monné         } domU;
858*3a9fd824SRoger Pau Monné         struct {
859*3a9fd824SRoger Pau Monné             uint32_t info_off;  /* Offset of console_info struct.         */
860*3a9fd824SRoger Pau Monné             uint32_t info_size; /* Size of console_info struct from start.*/
861*3a9fd824SRoger Pau Monné         } dom0;
862*3a9fd824SRoger Pau Monné     } console;
863*3a9fd824SRoger Pau Monné     /* THE FOLLOWING ARE ONLY FILLED IN ON INITIAL BOOT (NOT RESUME).     */
864*3a9fd824SRoger Pau Monné     unsigned long pt_base;      /* VIRTUAL address of page directory.     */
865*3a9fd824SRoger Pau Monné     unsigned long nr_pt_frames; /* Number of bootstrap p.t. frames.       */
866*3a9fd824SRoger Pau Monné     unsigned long mfn_list;     /* VIRTUAL address of page-frame list.    */
867*3a9fd824SRoger Pau Monné     unsigned long mod_start;    /* VIRTUAL address of pre-loaded module   */
868*3a9fd824SRoger Pau Monné                                 /* (PFN of pre-loaded module if           */
869*3a9fd824SRoger Pau Monné                                 /*  SIF_MOD_START_PFN set in flags).      */
870*3a9fd824SRoger Pau Monné     unsigned long mod_len;      /* Size (bytes) of pre-loaded module.     */
871*3a9fd824SRoger Pau Monné #define MAX_GUEST_CMDLINE 1024
872*3a9fd824SRoger Pau Monné     int8_t cmd_line[MAX_GUEST_CMDLINE];
873*3a9fd824SRoger Pau Monné     /* The pfn range here covers both page table and p->m table frames.   */
874*3a9fd824SRoger Pau Monné     unsigned long first_p2m_pfn;/* 1st pfn forming initial P->M table.    */
875*3a9fd824SRoger Pau Monné     unsigned long nr_p2m_frames;/* # of pfns forming initial P->M table.  */
876*3a9fd824SRoger Pau Monné };
877*3a9fd824SRoger Pau Monné typedef struct start_info start_info_t;
878*3a9fd824SRoger Pau Monné 
879*3a9fd824SRoger Pau Monné /* New console union for dom0 introduced in 0x00030203. */
880*3a9fd824SRoger Pau Monné #if __XEN_INTERFACE_VERSION__ < 0x00030203
881*3a9fd824SRoger Pau Monné #define console_mfn    console.domU.mfn
882*3a9fd824SRoger Pau Monné #define console_evtchn console.domU.evtchn
883*3a9fd824SRoger Pau Monné #endif
884*3a9fd824SRoger Pau Monné #endif /* XEN_HAVE_PV_GUEST_ENTRY */
885*3a9fd824SRoger Pau Monné 
886*3a9fd824SRoger Pau Monné /* These flags are passed in the 'flags' field of start_info_t. */
887*3a9fd824SRoger Pau Monné #define SIF_PRIVILEGED    (1<<0)  /* Is the domain privileged? */
888*3a9fd824SRoger Pau Monné #define SIF_INITDOMAIN    (1<<1)  /* Is this the initial control domain? */
889*3a9fd824SRoger Pau Monné #define SIF_MULTIBOOT_MOD (1<<2)  /* Is mod_start a multiboot module? */
890*3a9fd824SRoger Pau Monné #define SIF_MOD_START_PFN (1<<3)  /* Is mod_start a PFN? */
891*3a9fd824SRoger Pau Monné #define SIF_VIRT_P2M_4TOOLS (1<<4) /* Do Xen tools understand a virt. mapped */
892*3a9fd824SRoger Pau Monné                                    /* P->M making the 3 level tree obsolete? */
893*3a9fd824SRoger Pau Monné #define SIF_PM_MASK       (0xFF<<8) /* reserve 1 byte for xen-pm options */
894*3a9fd824SRoger Pau Monné 
895*3a9fd824SRoger Pau Monné /*
896*3a9fd824SRoger Pau Monné  * A multiboot module is a package containing modules very similar to a
897*3a9fd824SRoger Pau Monné  * multiboot module array. The only differences are:
898*3a9fd824SRoger Pau Monné  * - the array of module descriptors is by convention simply at the beginning
899*3a9fd824SRoger Pau Monné  *   of the multiboot module,
900*3a9fd824SRoger Pau Monné  * - addresses in the module descriptors are based on the beginning of the
901*3a9fd824SRoger Pau Monné  *   multiboot module,
902*3a9fd824SRoger Pau Monné  * - the number of modules is determined by a termination descriptor that has
903*3a9fd824SRoger Pau Monné  *   mod_start == 0.
904*3a9fd824SRoger Pau Monné  *
905*3a9fd824SRoger Pau Monné  * This permits to both build it statically and reference it in a configuration
906*3a9fd824SRoger Pau Monné  * file, and let the PV guest easily rebase the addresses to virtual addresses
907*3a9fd824SRoger Pau Monné  * and at the same time count the number of modules.
908*3a9fd824SRoger Pau Monné  */
909*3a9fd824SRoger Pau Monné struct xen_multiboot_mod_list
910*3a9fd824SRoger Pau Monné {
911*3a9fd824SRoger Pau Monné     /* Address of first byte of the module */
912*3a9fd824SRoger Pau Monné     uint32_t mod_start;
913*3a9fd824SRoger Pau Monné     /* Address of last byte of the module (inclusive) */
914*3a9fd824SRoger Pau Monné     uint32_t mod_end;
915*3a9fd824SRoger Pau Monné     /* Address of zero-terminated command line */
916*3a9fd824SRoger Pau Monné     uint32_t cmdline;
917*3a9fd824SRoger Pau Monné     /* Unused, must be zero */
918*3a9fd824SRoger Pau Monné     uint32_t pad;
919*3a9fd824SRoger Pau Monné };
920*3a9fd824SRoger Pau Monné /*
921*3a9fd824SRoger Pau Monné  * `incontents 200 startofday_dom0_console Dom0_console
922*3a9fd824SRoger Pau Monné  *
923*3a9fd824SRoger Pau Monné  * The console structure in start_info.console.dom0
924*3a9fd824SRoger Pau Monné  *
925*3a9fd824SRoger Pau Monné  * This structure includes a variety of information required to
926*3a9fd824SRoger Pau Monné  * have a working VGA/VESA console.
927*3a9fd824SRoger Pau Monné  */
928*3a9fd824SRoger Pau Monné typedef struct dom0_vga_console_info {
929*3a9fd824SRoger Pau Monné     uint8_t video_type; /* DOM0_VGA_CONSOLE_??? */
930*3a9fd824SRoger Pau Monné #define XEN_VGATYPE_TEXT_MODE_3 0x03
931*3a9fd824SRoger Pau Monné #define XEN_VGATYPE_VESA_LFB    0x23
932*3a9fd824SRoger Pau Monné #define XEN_VGATYPE_EFI_LFB     0x70
933*3a9fd824SRoger Pau Monné 
934*3a9fd824SRoger Pau Monné     union {
935*3a9fd824SRoger Pau Monné         struct {
936*3a9fd824SRoger Pau Monné             /* Font height, in pixels. */
937*3a9fd824SRoger Pau Monné             uint16_t font_height;
938*3a9fd824SRoger Pau Monné             /* Cursor location (column, row). */
939*3a9fd824SRoger Pau Monné             uint16_t cursor_x, cursor_y;
940*3a9fd824SRoger Pau Monné             /* Number of rows and columns (dimensions in characters). */
941*3a9fd824SRoger Pau Monné             uint16_t rows, columns;
942*3a9fd824SRoger Pau Monné         } text_mode_3;
943*3a9fd824SRoger Pau Monné 
944*3a9fd824SRoger Pau Monné         struct {
945*3a9fd824SRoger Pau Monné             /* Width and height, in pixels. */
946*3a9fd824SRoger Pau Monné             uint16_t width, height;
947*3a9fd824SRoger Pau Monné             /* Bytes per scan line. */
948*3a9fd824SRoger Pau Monné             uint16_t bytes_per_line;
949*3a9fd824SRoger Pau Monné             /* Bits per pixel. */
950*3a9fd824SRoger Pau Monné             uint16_t bits_per_pixel;
951*3a9fd824SRoger Pau Monné             /* LFB physical address, and size (in units of 64kB). */
952*3a9fd824SRoger Pau Monné             uint32_t lfb_base;
953*3a9fd824SRoger Pau Monné             uint32_t lfb_size;
954*3a9fd824SRoger Pau Monné             /* RGB mask offsets and sizes, as defined by VBE 1.2+ */
955*3a9fd824SRoger Pau Monné             uint8_t  red_pos, red_size;
956*3a9fd824SRoger Pau Monné             uint8_t  green_pos, green_size;
957*3a9fd824SRoger Pau Monné             uint8_t  blue_pos, blue_size;
958*3a9fd824SRoger Pau Monné             uint8_t  rsvd_pos, rsvd_size;
959*3a9fd824SRoger Pau Monné #if __XEN_INTERFACE_VERSION__ >= 0x00030206
960*3a9fd824SRoger Pau Monné             /* VESA capabilities (offset 0xa, VESA command 0x4f00). */
961*3a9fd824SRoger Pau Monné             uint32_t gbl_caps;
962*3a9fd824SRoger Pau Monné             /* Mode attributes (offset 0x0, VESA command 0x4f01). */
963*3a9fd824SRoger Pau Monné             uint16_t mode_attrs;
964*3a9fd824SRoger Pau Monné             uint16_t pad;
965*3a9fd824SRoger Pau Monné #endif
966*3a9fd824SRoger Pau Monné #if __XEN_INTERFACE_VERSION__ >= 0x00040d00
967*3a9fd824SRoger Pau Monné             /* high 32 bits of lfb_base */
968*3a9fd824SRoger Pau Monné             uint32_t ext_lfb_base;
969*3a9fd824SRoger Pau Monné #endif
970*3a9fd824SRoger Pau Monné         } vesa_lfb;
971*3a9fd824SRoger Pau Monné     } u;
972*3a9fd824SRoger Pau Monné } dom0_vga_console_info_t;
973*3a9fd824SRoger Pau Monné #define xen_vga_console_info dom0_vga_console_info
974*3a9fd824SRoger Pau Monné #define xen_vga_console_info_t dom0_vga_console_info_t
975*3a9fd824SRoger Pau Monné 
976*3a9fd824SRoger Pau Monné typedef uint8_t xen_domain_handle_t[16];
977*3a9fd824SRoger Pau Monné 
978*3a9fd824SRoger Pau Monné __DEFINE_XEN_GUEST_HANDLE(uint8,  uint8_t);
979*3a9fd824SRoger Pau Monné __DEFINE_XEN_GUEST_HANDLE(uint16, uint16_t);
980*3a9fd824SRoger Pau Monné __DEFINE_XEN_GUEST_HANDLE(uint32, uint32_t);
981*3a9fd824SRoger Pau Monné __DEFINE_XEN_GUEST_HANDLE(uint64, uint64_t);
982*3a9fd824SRoger Pau Monné 
983*3a9fd824SRoger Pau Monné typedef struct {
984*3a9fd824SRoger Pau Monné     uint8_t a[16];
985*3a9fd824SRoger Pau Monné } xen_uuid_t;
986*3a9fd824SRoger Pau Monné 
987*3a9fd824SRoger Pau Monné /*
988*3a9fd824SRoger Pau Monné  * XEN_DEFINE_UUID(0x00112233, 0x4455, 0x6677, 0x8899,
989*3a9fd824SRoger Pau Monné  *                 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff)
990*3a9fd824SRoger Pau Monné  * will construct UUID 00112233-4455-6677-8899-aabbccddeeff presented as
991*3a9fd824SRoger Pau Monné  * {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88,
992*3a9fd824SRoger Pau Monné  * 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff};
993*3a9fd824SRoger Pau Monné  *
994*3a9fd824SRoger Pau Monné  * NB: This is compatible with Linux kernel and with libuuid, but it is not
995*3a9fd824SRoger Pau Monné  * compatible with Microsoft, as they use mixed-endian encoding (some
996*3a9fd824SRoger Pau Monné  * components are little-endian, some are big-endian).
997*3a9fd824SRoger Pau Monné  */
998*3a9fd824SRoger Pau Monné #define XEN_DEFINE_UUID_(a, b, c, d, e1, e2, e3, e4, e5, e6)            \
999*3a9fd824SRoger Pau Monné     {{((a) >> 24) & 0xFF, ((a) >> 16) & 0xFF,                           \
1000*3a9fd824SRoger Pau Monné       ((a) >>  8) & 0xFF, ((a) >>  0) & 0xFF,                           \
1001*3a9fd824SRoger Pau Monné       ((b) >>  8) & 0xFF, ((b) >>  0) & 0xFF,                           \
1002*3a9fd824SRoger Pau Monné       ((c) >>  8) & 0xFF, ((c) >>  0) & 0xFF,                           \
1003*3a9fd824SRoger Pau Monné       ((d) >>  8) & 0xFF, ((d) >>  0) & 0xFF,                           \
1004*3a9fd824SRoger Pau Monné                 e1, e2, e3, e4, e5, e6}}
1005*3a9fd824SRoger Pau Monné 
1006*3a9fd824SRoger Pau Monné #if defined(__STDC_VERSION__) ? __STDC_VERSION__ >= 199901L : defined(__GNUC__)
1007*3a9fd824SRoger Pau Monné #define XEN_DEFINE_UUID(a, b, c, d, e1, e2, e3, e4, e5, e6)             \
1008*3a9fd824SRoger Pau Monné     ((xen_uuid_t)XEN_DEFINE_UUID_(a, b, c, d, e1, e2, e3, e4, e5, e6))
1009*3a9fd824SRoger Pau Monné #else
1010*3a9fd824SRoger Pau Monné #define XEN_DEFINE_UUID(a, b, c, d, e1, e2, e3, e4, e5, e6)             \
1011*3a9fd824SRoger Pau Monné     XEN_DEFINE_UUID_(a, b, c, d, e1, e2, e3, e4, e5, e6)
1012*3a9fd824SRoger Pau Monné #endif /* __STDC_VERSION__ / __GNUC__ */
1013*3a9fd824SRoger Pau Monné 
1014*3a9fd824SRoger Pau Monné #endif /* !__ASSEMBLY__ */
1015*3a9fd824SRoger Pau Monné 
1016*3a9fd824SRoger Pau Monné /* Default definitions for macros used by domctl/sysctl. */
1017*3a9fd824SRoger Pau Monné #if defined(__XEN__) || defined(__XEN_TOOLS__)
1018*3a9fd824SRoger Pau Monné 
1019*3a9fd824SRoger Pau Monné #ifndef int64_aligned_t
1020*3a9fd824SRoger Pau Monné #define int64_aligned_t int64_t
1021*3a9fd824SRoger Pau Monné #endif
1022*3a9fd824SRoger Pau Monné #ifndef uint64_aligned_t
1023*3a9fd824SRoger Pau Monné #define uint64_aligned_t uint64_t
1024*3a9fd824SRoger Pau Monné #endif
1025*3a9fd824SRoger Pau Monné #ifndef XEN_GUEST_HANDLE_64
1026*3a9fd824SRoger Pau Monné #define XEN_GUEST_HANDLE_64(name) XEN_GUEST_HANDLE(name)
1027*3a9fd824SRoger Pau Monné #endif
1028*3a9fd824SRoger Pau Monné 
1029*3a9fd824SRoger Pau Monné #ifndef __ASSEMBLY__
1030*3a9fd824SRoger Pau Monné struct xenctl_bitmap {
1031*3a9fd824SRoger Pau Monné     XEN_GUEST_HANDLE_64(uint8) bitmap;
1032*3a9fd824SRoger Pau Monné     uint32_t nr_bits;
1033*3a9fd824SRoger Pau Monné };
1034*3a9fd824SRoger Pau Monné typedef struct xenctl_bitmap xenctl_bitmap_t;
1035*3a9fd824SRoger Pau Monné #endif
1036*3a9fd824SRoger Pau Monné 
1037*3a9fd824SRoger Pau Monné #endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */
1038*3a9fd824SRoger Pau Monné 
1039*3a9fd824SRoger Pau Monné #endif /* __XEN_PUBLIC_XEN_H__ */
1040*3a9fd824SRoger Pau Monné 
1041*3a9fd824SRoger Pau Monné /*
1042*3a9fd824SRoger Pau Monné  * Local variables:
1043*3a9fd824SRoger Pau Monné  * mode: C
1044*3a9fd824SRoger Pau Monné  * c-file-style: "BSD"
1045*3a9fd824SRoger Pau Monné  * c-basic-offset: 4
1046*3a9fd824SRoger Pau Monné  * tab-width: 4
1047*3a9fd824SRoger Pau Monné  * indent-tabs-mode: nil
1048*3a9fd824SRoger Pau Monné  * End:
1049*3a9fd824SRoger Pau Monné  */
1050