xref: /OK3568_Linux_fs/kernel/include/xen/interface/xen.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /******************************************************************************
2*4882a593Smuzhiyun  * xen.h
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Guest OS interface to Xen.
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * Permission is hereby granted, free of charge, to any person obtaining a copy
7*4882a593Smuzhiyun  * of this software and associated documentation files (the "Software"), to
8*4882a593Smuzhiyun  * deal in the Software without restriction, including without limitation the
9*4882a593Smuzhiyun  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10*4882a593Smuzhiyun  * sell copies of the Software, and to permit persons to whom the Software is
11*4882a593Smuzhiyun  * furnished to do so, subject to the following conditions:
12*4882a593Smuzhiyun  *
13*4882a593Smuzhiyun  * The above copyright notice and this permission notice shall be included in
14*4882a593Smuzhiyun  * all copies or substantial portions of the Software.
15*4882a593Smuzhiyun  *
16*4882a593Smuzhiyun  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17*4882a593Smuzhiyun  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18*4882a593Smuzhiyun  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19*4882a593Smuzhiyun  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20*4882a593Smuzhiyun  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21*4882a593Smuzhiyun  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22*4882a593Smuzhiyun  * DEALINGS IN THE SOFTWARE.
23*4882a593Smuzhiyun  *
24*4882a593Smuzhiyun  * Copyright (c) 2004, K A Fraser
25*4882a593Smuzhiyun  */
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun #ifndef __XEN_PUBLIC_XEN_H__
28*4882a593Smuzhiyun #define __XEN_PUBLIC_XEN_H__
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun #include <asm/xen/interface.h>
31*4882a593Smuzhiyun 
32*4882a593Smuzhiyun /*
33*4882a593Smuzhiyun  * XEN "SYSTEM CALLS" (a.k.a. HYPERCALLS).
34*4882a593Smuzhiyun  */
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun /*
37*4882a593Smuzhiyun  * x86_32: EAX = vector; EBX, ECX, EDX, ESI, EDI = args 1, 2, 3, 4, 5.
38*4882a593Smuzhiyun  *         EAX = return value
39*4882a593Smuzhiyun  *         (argument registers may be clobbered on return)
40*4882a593Smuzhiyun  * x86_64: RAX = vector; RDI, RSI, RDX, R10, R8, R9 = args 1, 2, 3, 4, 5, 6.
41*4882a593Smuzhiyun  *         RAX = return value
42*4882a593Smuzhiyun  *         (argument registers not clobbered on return; RCX, R11 are)
43*4882a593Smuzhiyun  */
44*4882a593Smuzhiyun #define __HYPERVISOR_set_trap_table        0
45*4882a593Smuzhiyun #define __HYPERVISOR_mmu_update            1
46*4882a593Smuzhiyun #define __HYPERVISOR_set_gdt               2
47*4882a593Smuzhiyun #define __HYPERVISOR_stack_switch          3
48*4882a593Smuzhiyun #define __HYPERVISOR_set_callbacks         4
49*4882a593Smuzhiyun #define __HYPERVISOR_fpu_taskswitch        5
50*4882a593Smuzhiyun #define __HYPERVISOR_sched_op_compat       6
51*4882a593Smuzhiyun #define __HYPERVISOR_platform_op           7
52*4882a593Smuzhiyun #define __HYPERVISOR_set_debugreg          8
53*4882a593Smuzhiyun #define __HYPERVISOR_get_debugreg          9
54*4882a593Smuzhiyun #define __HYPERVISOR_update_descriptor    10
55*4882a593Smuzhiyun #define __HYPERVISOR_memory_op            12
56*4882a593Smuzhiyun #define __HYPERVISOR_multicall            13
57*4882a593Smuzhiyun #define __HYPERVISOR_update_va_mapping    14
58*4882a593Smuzhiyun #define __HYPERVISOR_set_timer_op         15
59*4882a593Smuzhiyun #define __HYPERVISOR_event_channel_op_compat 16
60*4882a593Smuzhiyun #define __HYPERVISOR_xen_version          17
61*4882a593Smuzhiyun #define __HYPERVISOR_console_io           18
62*4882a593Smuzhiyun #define __HYPERVISOR_physdev_op_compat    19
63*4882a593Smuzhiyun #define __HYPERVISOR_grant_table_op       20
64*4882a593Smuzhiyun #define __HYPERVISOR_vm_assist            21
65*4882a593Smuzhiyun #define __HYPERVISOR_update_va_mapping_otherdomain 22
66*4882a593Smuzhiyun #define __HYPERVISOR_iret                 23 /* x86 only */
67*4882a593Smuzhiyun #define __HYPERVISOR_vcpu_op              24
68*4882a593Smuzhiyun #define __HYPERVISOR_set_segment_base     25 /* x86/64 only */
69*4882a593Smuzhiyun #define __HYPERVISOR_mmuext_op            26
70*4882a593Smuzhiyun #define __HYPERVISOR_xsm_op               27
71*4882a593Smuzhiyun #define __HYPERVISOR_nmi_op               28
72*4882a593Smuzhiyun #define __HYPERVISOR_sched_op             29
73*4882a593Smuzhiyun #define __HYPERVISOR_callback_op          30
74*4882a593Smuzhiyun #define __HYPERVISOR_xenoprof_op          31
75*4882a593Smuzhiyun #define __HYPERVISOR_event_channel_op     32
76*4882a593Smuzhiyun #define __HYPERVISOR_physdev_op           33
77*4882a593Smuzhiyun #define __HYPERVISOR_hvm_op               34
78*4882a593Smuzhiyun #define __HYPERVISOR_sysctl               35
79*4882a593Smuzhiyun #define __HYPERVISOR_domctl               36
80*4882a593Smuzhiyun #define __HYPERVISOR_kexec_op             37
81*4882a593Smuzhiyun #define __HYPERVISOR_tmem_op              38
82*4882a593Smuzhiyun #define __HYPERVISOR_xc_reserved_op       39 /* reserved for XenClient */
83*4882a593Smuzhiyun #define __HYPERVISOR_xenpmu_op            40
84*4882a593Smuzhiyun #define __HYPERVISOR_dm_op                41
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun /* Architecture-specific hypercall definitions. */
87*4882a593Smuzhiyun #define __HYPERVISOR_arch_0               48
88*4882a593Smuzhiyun #define __HYPERVISOR_arch_1               49
89*4882a593Smuzhiyun #define __HYPERVISOR_arch_2               50
90*4882a593Smuzhiyun #define __HYPERVISOR_arch_3               51
91*4882a593Smuzhiyun #define __HYPERVISOR_arch_4               52
92*4882a593Smuzhiyun #define __HYPERVISOR_arch_5               53
93*4882a593Smuzhiyun #define __HYPERVISOR_arch_6               54
94*4882a593Smuzhiyun #define __HYPERVISOR_arch_7               55
95*4882a593Smuzhiyun 
96*4882a593Smuzhiyun /*
97*4882a593Smuzhiyun  * VIRTUAL INTERRUPTS
98*4882a593Smuzhiyun  *
99*4882a593Smuzhiyun  * Virtual interrupts that a guest OS may receive from Xen.
100*4882a593Smuzhiyun  * In the side comments, 'V.' denotes a per-VCPU VIRQ while 'G.' denotes a
101*4882a593Smuzhiyun  * global VIRQ. The former can be bound once per VCPU and cannot be re-bound.
102*4882a593Smuzhiyun  * The latter can be allocated only once per guest: they must initially be
103*4882a593Smuzhiyun  * allocated to VCPU0 but can subsequently be re-bound.
104*4882a593Smuzhiyun  */
105*4882a593Smuzhiyun #define VIRQ_TIMER      0  /* V. Timebase update, and/or requested timeout.  */
106*4882a593Smuzhiyun #define VIRQ_DEBUG      1  /* V. Request guest to dump debug info.           */
107*4882a593Smuzhiyun #define VIRQ_CONSOLE    2  /* G. (DOM0) Bytes received on emergency console. */
108*4882a593Smuzhiyun #define VIRQ_DOM_EXC    3  /* G. (DOM0) Exceptional event for some domain.   */
109*4882a593Smuzhiyun #define VIRQ_TBUF       4  /* G. (DOM0) Trace buffer has records available.  */
110*4882a593Smuzhiyun #define VIRQ_DEBUGGER   6  /* G. (DOM0) A domain has paused for debugging.   */
111*4882a593Smuzhiyun #define VIRQ_XENOPROF   7  /* V. XenOprofile interrupt: new sample available */
112*4882a593Smuzhiyun #define VIRQ_CON_RING   8  /* G. (DOM0) Bytes received on console            */
113*4882a593Smuzhiyun #define VIRQ_PCPU_STATE 9  /* G. (DOM0) PCPU state changed                   */
114*4882a593Smuzhiyun #define VIRQ_MEM_EVENT  10 /* G. (DOM0) A memory event has occured           */
115*4882a593Smuzhiyun #define VIRQ_XC_RESERVED 11 /* G. Reserved for XenClient                     */
116*4882a593Smuzhiyun #define VIRQ_ENOMEM     12 /* G. (DOM0) Low on heap memory       */
117*4882a593Smuzhiyun #define VIRQ_XENPMU     13  /* PMC interrupt                                 */
118*4882a593Smuzhiyun 
119*4882a593Smuzhiyun /* Architecture-specific VIRQ definitions. */
120*4882a593Smuzhiyun #define VIRQ_ARCH_0    16
121*4882a593Smuzhiyun #define VIRQ_ARCH_1    17
122*4882a593Smuzhiyun #define VIRQ_ARCH_2    18
123*4882a593Smuzhiyun #define VIRQ_ARCH_3    19
124*4882a593Smuzhiyun #define VIRQ_ARCH_4    20
125*4882a593Smuzhiyun #define VIRQ_ARCH_5    21
126*4882a593Smuzhiyun #define VIRQ_ARCH_6    22
127*4882a593Smuzhiyun #define VIRQ_ARCH_7    23
128*4882a593Smuzhiyun 
129*4882a593Smuzhiyun #define NR_VIRQS       24
130*4882a593Smuzhiyun 
131*4882a593Smuzhiyun /*
132*4882a593Smuzhiyun  * enum neg_errnoval HYPERVISOR_mmu_update(const struct mmu_update reqs[],
133*4882a593Smuzhiyun  *                                         unsigned count, unsigned *done_out,
134*4882a593Smuzhiyun  *                                         unsigned foreigndom)
135*4882a593Smuzhiyun  * @reqs is an array of mmu_update_t structures ((ptr, val) pairs).
136*4882a593Smuzhiyun  * @count is the length of the above array.
137*4882a593Smuzhiyun  * @pdone is an output parameter indicating number of completed operations
138*4882a593Smuzhiyun  * @foreigndom[15:0]: FD, the expected owner of data pages referenced in this
139*4882a593Smuzhiyun  *                    hypercall invocation. Can be DOMID_SELF.
140*4882a593Smuzhiyun  * @foreigndom[31:16]: PFD, the expected owner of pagetable pages referenced
141*4882a593Smuzhiyun  *                     in this hypercall invocation. The value of this field
142*4882a593Smuzhiyun  *                     (x) encodes the PFD as follows:
143*4882a593Smuzhiyun  *                     x == 0 => PFD == DOMID_SELF
144*4882a593Smuzhiyun  *                     x != 0 => PFD == x - 1
145*4882a593Smuzhiyun  *
146*4882a593Smuzhiyun  * Sub-commands: ptr[1:0] specifies the appropriate MMU_* command.
147*4882a593Smuzhiyun  * -------------
148*4882a593Smuzhiyun  * ptr[1:0] == MMU_NORMAL_PT_UPDATE:
149*4882a593Smuzhiyun  * Updates an entry in a page table belonging to PFD. If updating an L1 table,
150*4882a593Smuzhiyun  * and the new table entry is valid/present, the mapped frame must belong to
151*4882a593Smuzhiyun  * FD. If attempting to map an I/O page then the caller assumes the privilege
152*4882a593Smuzhiyun  * of the FD.
153*4882a593Smuzhiyun  * FD == DOMID_IO: Permit /only/ I/O mappings, at the priv level of the caller.
154*4882a593Smuzhiyun  * FD == DOMID_XEN: Map restricted areas of Xen's heap space.
155*4882a593Smuzhiyun  * ptr[:2]  -- Machine address of the page-table entry to modify.
156*4882a593Smuzhiyun  * val      -- Value to write.
157*4882a593Smuzhiyun  *
158*4882a593Smuzhiyun  * There also certain implicit requirements when using this hypercall. The
159*4882a593Smuzhiyun  * pages that make up a pagetable must be mapped read-only in the guest.
160*4882a593Smuzhiyun  * This prevents uncontrolled guest updates to the pagetable. Xen strictly
161*4882a593Smuzhiyun  * enforces this, and will disallow any pagetable update which will end up
162*4882a593Smuzhiyun  * mapping pagetable page RW, and will disallow using any writable page as a
163*4882a593Smuzhiyun  * pagetable. In practice it means that when constructing a page table for a
164*4882a593Smuzhiyun  * process, thread, etc, we MUST be very dilligient in following these rules:
165*4882a593Smuzhiyun  *  1). Start with top-level page (PGD or in Xen language: L4). Fill out
166*4882a593Smuzhiyun  *      the entries.
167*4882a593Smuzhiyun  *  2). Keep on going, filling out the upper (PUD or L3), and middle (PMD
168*4882a593Smuzhiyun  *      or L2).
169*4882a593Smuzhiyun  *  3). Start filling out the PTE table (L1) with the PTE entries. Once
170*4882a593Smuzhiyun  *      done, make sure to set each of those entries to RO (so writeable bit
171*4882a593Smuzhiyun  *      is unset). Once that has been completed, set the PMD (L2) for this
172*4882a593Smuzhiyun  *      PTE table as RO.
173*4882a593Smuzhiyun  *  4). When completed with all of the PMD (L2) entries, and all of them have
174*4882a593Smuzhiyun  *      been set to RO, make sure to set RO the PUD (L3). Do the same
175*4882a593Smuzhiyun  *      operation on PGD (L4) pagetable entries that have a PUD (L3) entry.
176*4882a593Smuzhiyun  *  5). Now before you can use those pages (so setting the cr3), you MUST also
177*4882a593Smuzhiyun  *      pin them so that the hypervisor can verify the entries. This is done
178*4882a593Smuzhiyun  *      via the HYPERVISOR_mmuext_op(MMUEXT_PIN_L4_TABLE, guest physical frame
179*4882a593Smuzhiyun  *      number of the PGD (L4)). And this point the HYPERVISOR_mmuext_op(
180*4882a593Smuzhiyun  *      MMUEXT_NEW_BASEPTR, guest physical frame number of the PGD (L4)) can be
181*4882a593Smuzhiyun  *      issued.
182*4882a593Smuzhiyun  * For 32-bit guests, the L4 is not used (as there is less pagetables), so
183*4882a593Smuzhiyun  * instead use L3.
184*4882a593Smuzhiyun  * At this point the pagetables can be modified using the MMU_NORMAL_PT_UPDATE
185*4882a593Smuzhiyun  * hypercall. Also if so desired the OS can also try to write to the PTE
186*4882a593Smuzhiyun  * and be trapped by the hypervisor (as the PTE entry is RO).
187*4882a593Smuzhiyun  *
188*4882a593Smuzhiyun  * To deallocate the pages, the operations are the reverse of the steps
189*4882a593Smuzhiyun  * mentioned above. The argument is MMUEXT_UNPIN_TABLE for all levels and the
190*4882a593Smuzhiyun  * pagetable MUST not be in use (meaning that the cr3 is not set to it).
191*4882a593Smuzhiyun  *
192*4882a593Smuzhiyun  * ptr[1:0] == MMU_MACHPHYS_UPDATE:
193*4882a593Smuzhiyun  * Updates an entry in the machine->pseudo-physical mapping table.
194*4882a593Smuzhiyun  * ptr[:2]  -- Machine address within the frame whose mapping to modify.
195*4882a593Smuzhiyun  *             The frame must belong to the FD, if one is specified.
196*4882a593Smuzhiyun  * val      -- Value to write into the mapping entry.
197*4882a593Smuzhiyun  *
198*4882a593Smuzhiyun  * ptr[1:0] == MMU_PT_UPDATE_PRESERVE_AD:
199*4882a593Smuzhiyun  * As MMU_NORMAL_PT_UPDATE above, but A/D bits currently in the PTE are ORed
200*4882a593Smuzhiyun  * with those in @val.
201*4882a593Smuzhiyun  *
202*4882a593Smuzhiyun  * @val is usually the machine frame number along with some attributes.
203*4882a593Smuzhiyun  * The attributes by default follow the architecture defined bits. Meaning that
204*4882a593Smuzhiyun  * if this is a X86_64 machine and four page table layout is used, the layout
205*4882a593Smuzhiyun  * of val is:
206*4882a593Smuzhiyun  *  - 63 if set means No execute (NX)
207*4882a593Smuzhiyun  *  - 46-13 the machine frame number
208*4882a593Smuzhiyun  *  - 12 available for guest
209*4882a593Smuzhiyun  *  - 11 available for guest
210*4882a593Smuzhiyun  *  - 10 available for guest
211*4882a593Smuzhiyun  *  - 9 available for guest
212*4882a593Smuzhiyun  *  - 8 global
213*4882a593Smuzhiyun  *  - 7 PAT (PSE is disabled, must use hypercall to make 4MB or 2MB pages)
214*4882a593Smuzhiyun  *  - 6 dirty
215*4882a593Smuzhiyun  *  - 5 accessed
216*4882a593Smuzhiyun  *  - 4 page cached disabled
217*4882a593Smuzhiyun  *  - 3 page write through
218*4882a593Smuzhiyun  *  - 2 userspace accessible
219*4882a593Smuzhiyun  *  - 1 writeable
220*4882a593Smuzhiyun  *  - 0 present
221*4882a593Smuzhiyun  *
222*4882a593Smuzhiyun  *  The one bits that does not fit with the default layout is the PAGE_PSE
223*4882a593Smuzhiyun  *  also called PAGE_PAT). The MMUEXT_[UN]MARK_SUPER arguments to the
224*4882a593Smuzhiyun  *  HYPERVISOR_mmuext_op serve as mechanism to set a pagetable to be 4MB
225*4882a593Smuzhiyun  *  (or 2MB) instead of using the PAGE_PSE bit.
226*4882a593Smuzhiyun  *
227*4882a593Smuzhiyun  *  The reason that the PAGE_PSE (bit 7) is not being utilized is due to Xen
228*4882a593Smuzhiyun  *  using it as the Page Attribute Table (PAT) bit - for details on it please
229*4882a593Smuzhiyun  *  refer to Intel SDM 10.12. The PAT allows to set the caching attributes of
230*4882a593Smuzhiyun  *  pages instead of using MTRRs.
231*4882a593Smuzhiyun  *
232*4882a593Smuzhiyun  *  The PAT MSR is as follows (it is a 64-bit value, each entry is 8 bits):
233*4882a593Smuzhiyun  *                    PAT4                 PAT0
234*4882a593Smuzhiyun  *  +-----+-----+----+----+----+-----+----+----+
235*4882a593Smuzhiyun  *  | UC  | UC- | WC | WB | UC | UC- | WC | WB |  <= Linux
236*4882a593Smuzhiyun  *  +-----+-----+----+----+----+-----+----+----+
237*4882a593Smuzhiyun  *  | UC  | UC- | WT | WB | UC | UC- | WT | WB |  <= BIOS (default when machine boots)
238*4882a593Smuzhiyun  *  +-----+-----+----+----+----+-----+----+----+
239*4882a593Smuzhiyun  *  | rsv | rsv | WP | WC | UC | UC- | WT | WB |  <= Xen
240*4882a593Smuzhiyun  *  +-----+-----+----+----+----+-----+----+----+
241*4882a593Smuzhiyun  *
242*4882a593Smuzhiyun  *  The lookup of this index table translates to looking up
243*4882a593Smuzhiyun  *  Bit 7, Bit 4, and Bit 3 of val entry:
244*4882a593Smuzhiyun  *
245*4882a593Smuzhiyun  *  PAT/PSE (bit 7) ... PCD (bit 4) .. PWT (bit 3).
246*4882a593Smuzhiyun  *
247*4882a593Smuzhiyun  *  If all bits are off, then we are using PAT0. If bit 3 turned on,
248*4882a593Smuzhiyun  *  then we are using PAT1, if bit 3 and bit 4, then PAT2..
249*4882a593Smuzhiyun  *
250*4882a593Smuzhiyun  *  As you can see, the Linux PAT1 translates to PAT4 under Xen. Which means
251*4882a593Smuzhiyun  *  that if a guest that follows Linux's PAT setup and would like to set Write
252*4882a593Smuzhiyun  *  Combined on pages it MUST use PAT4 entry. Meaning that Bit 7 (PAGE_PAT) is
253*4882a593Smuzhiyun  *  set. For example, under Linux it only uses PAT0, PAT1, and PAT2 for the
254*4882a593Smuzhiyun  *  caching as:
255*4882a593Smuzhiyun  *
256*4882a593Smuzhiyun  *   WB = none (so PAT0)
257*4882a593Smuzhiyun  *   WC = PWT (bit 3 on)
258*4882a593Smuzhiyun  *   UC = PWT | PCD (bit 3 and 4 are on).
259*4882a593Smuzhiyun  *
260*4882a593Smuzhiyun  * To make it work with Xen, it needs to translate the WC bit as so:
261*4882a593Smuzhiyun  *
262*4882a593Smuzhiyun  *  PWT (so bit 3 on) --> PAT (so bit 7 is on) and clear bit 3
263*4882a593Smuzhiyun  *
264*4882a593Smuzhiyun  * And to translate back it would:
265*4882a593Smuzhiyun  *
266*4882a593Smuzhiyun  * PAT (bit 7 on) --> PWT (bit 3 on) and clear bit 7.
267*4882a593Smuzhiyun  */
268*4882a593Smuzhiyun #define MMU_NORMAL_PT_UPDATE       0 /* checked '*ptr = val'. ptr is MA.      */
269*4882a593Smuzhiyun #define MMU_MACHPHYS_UPDATE        1 /* ptr = MA of frame to modify entry for */
270*4882a593Smuzhiyun #define MMU_PT_UPDATE_PRESERVE_AD  2 /* atomically: *ptr = val | (*ptr&(A|D)) */
271*4882a593Smuzhiyun #define MMU_PT_UPDATE_NO_TRANSLATE 3 /* checked '*ptr = val'. ptr is MA.      */
272*4882a593Smuzhiyun 
273*4882a593Smuzhiyun /*
274*4882a593Smuzhiyun  * MMU EXTENDED OPERATIONS
275*4882a593Smuzhiyun  *
276*4882a593Smuzhiyun  * enum neg_errnoval HYPERVISOR_mmuext_op(mmuext_op_t uops[],
277*4882a593Smuzhiyun  *                                        unsigned int count,
278*4882a593Smuzhiyun  *                                        unsigned int *pdone,
279*4882a593Smuzhiyun  *                                        unsigned int foreigndom)
280*4882a593Smuzhiyun  */
281*4882a593Smuzhiyun /* HYPERVISOR_mmuext_op() accepts a list of mmuext_op structures.
282*4882a593Smuzhiyun  * A foreigndom (FD) can be specified (or DOMID_SELF for none).
283*4882a593Smuzhiyun  * Where the FD has some effect, it is described below.
284*4882a593Smuzhiyun  *
285*4882a593Smuzhiyun  * cmd: MMUEXT_(UN)PIN_*_TABLE
286*4882a593Smuzhiyun  * mfn: Machine frame number to be (un)pinned as a p.t. page.
287*4882a593Smuzhiyun  *      The frame must belong to the FD, if one is specified.
288*4882a593Smuzhiyun  *
289*4882a593Smuzhiyun  * cmd: MMUEXT_NEW_BASEPTR
290*4882a593Smuzhiyun  * mfn: Machine frame number of new page-table base to install in MMU.
291*4882a593Smuzhiyun  *
292*4882a593Smuzhiyun  * cmd: MMUEXT_NEW_USER_BASEPTR [x86/64 only]
293*4882a593Smuzhiyun  * mfn: Machine frame number of new page-table base to install in MMU
294*4882a593Smuzhiyun  *      when in user space.
295*4882a593Smuzhiyun  *
296*4882a593Smuzhiyun  * cmd: MMUEXT_TLB_FLUSH_LOCAL
297*4882a593Smuzhiyun  * No additional arguments. Flushes local TLB.
298*4882a593Smuzhiyun  *
299*4882a593Smuzhiyun  * cmd: MMUEXT_INVLPG_LOCAL
300*4882a593Smuzhiyun  * linear_addr: Linear address to be flushed from the local TLB.
301*4882a593Smuzhiyun  *
302*4882a593Smuzhiyun  * cmd: MMUEXT_TLB_FLUSH_MULTI
303*4882a593Smuzhiyun  * vcpumask: Pointer to bitmap of VCPUs to be flushed.
304*4882a593Smuzhiyun  *
305*4882a593Smuzhiyun  * cmd: MMUEXT_INVLPG_MULTI
306*4882a593Smuzhiyun  * linear_addr: Linear address to be flushed.
307*4882a593Smuzhiyun  * vcpumask: Pointer to bitmap of VCPUs to be flushed.
308*4882a593Smuzhiyun  *
309*4882a593Smuzhiyun  * cmd: MMUEXT_TLB_FLUSH_ALL
310*4882a593Smuzhiyun  * No additional arguments. Flushes all VCPUs' TLBs.
311*4882a593Smuzhiyun  *
312*4882a593Smuzhiyun  * cmd: MMUEXT_INVLPG_ALL
313*4882a593Smuzhiyun  * linear_addr: Linear address to be flushed from all VCPUs' TLBs.
314*4882a593Smuzhiyun  *
315*4882a593Smuzhiyun  * cmd: MMUEXT_FLUSH_CACHE
316*4882a593Smuzhiyun  * No additional arguments. Writes back and flushes cache contents.
317*4882a593Smuzhiyun  *
318*4882a593Smuzhiyun  * cmd: MMUEXT_FLUSH_CACHE_GLOBAL
319*4882a593Smuzhiyun  * No additional arguments. Writes back and flushes cache contents
320*4882a593Smuzhiyun  * on all CPUs in the system.
321*4882a593Smuzhiyun  *
322*4882a593Smuzhiyun  * cmd: MMUEXT_SET_LDT
323*4882a593Smuzhiyun  * linear_addr: Linear address of LDT base (NB. must be page-aligned).
324*4882a593Smuzhiyun  * nr_ents: Number of entries in LDT.
325*4882a593Smuzhiyun  *
326*4882a593Smuzhiyun  * cmd: MMUEXT_CLEAR_PAGE
327*4882a593Smuzhiyun  * mfn: Machine frame number to be cleared.
328*4882a593Smuzhiyun  *
329*4882a593Smuzhiyun  * cmd: MMUEXT_COPY_PAGE
330*4882a593Smuzhiyun  * mfn: Machine frame number of the destination page.
331*4882a593Smuzhiyun  * src_mfn: Machine frame number of the source page.
332*4882a593Smuzhiyun  *
333*4882a593Smuzhiyun  * cmd: MMUEXT_[UN]MARK_SUPER
334*4882a593Smuzhiyun  * mfn: Machine frame number of head of superpage to be [un]marked.
335*4882a593Smuzhiyun  */
336*4882a593Smuzhiyun #define MMUEXT_PIN_L1_TABLE      0
337*4882a593Smuzhiyun #define MMUEXT_PIN_L2_TABLE      1
338*4882a593Smuzhiyun #define MMUEXT_PIN_L3_TABLE      2
339*4882a593Smuzhiyun #define MMUEXT_PIN_L4_TABLE      3
340*4882a593Smuzhiyun #define MMUEXT_UNPIN_TABLE       4
341*4882a593Smuzhiyun #define MMUEXT_NEW_BASEPTR       5
342*4882a593Smuzhiyun #define MMUEXT_TLB_FLUSH_LOCAL   6
343*4882a593Smuzhiyun #define MMUEXT_INVLPG_LOCAL      7
344*4882a593Smuzhiyun #define MMUEXT_TLB_FLUSH_MULTI   8
345*4882a593Smuzhiyun #define MMUEXT_INVLPG_MULTI      9
346*4882a593Smuzhiyun #define MMUEXT_TLB_FLUSH_ALL    10
347*4882a593Smuzhiyun #define MMUEXT_INVLPG_ALL       11
348*4882a593Smuzhiyun #define MMUEXT_FLUSH_CACHE      12
349*4882a593Smuzhiyun #define MMUEXT_SET_LDT          13
350*4882a593Smuzhiyun #define MMUEXT_NEW_USER_BASEPTR 15
351*4882a593Smuzhiyun #define MMUEXT_CLEAR_PAGE       16
352*4882a593Smuzhiyun #define MMUEXT_COPY_PAGE        17
353*4882a593Smuzhiyun #define MMUEXT_FLUSH_CACHE_GLOBAL 18
354*4882a593Smuzhiyun #define MMUEXT_MARK_SUPER       19
355*4882a593Smuzhiyun #define MMUEXT_UNMARK_SUPER     20
356*4882a593Smuzhiyun 
357*4882a593Smuzhiyun #ifndef __ASSEMBLY__
358*4882a593Smuzhiyun struct mmuext_op {
359*4882a593Smuzhiyun 	unsigned int cmd;
360*4882a593Smuzhiyun 	union {
361*4882a593Smuzhiyun 		/* [UN]PIN_TABLE, NEW_BASEPTR, NEW_USER_BASEPTR
362*4882a593Smuzhiyun 		 * CLEAR_PAGE, COPY_PAGE, [UN]MARK_SUPER */
363*4882a593Smuzhiyun 		xen_pfn_t mfn;
364*4882a593Smuzhiyun 		/* INVLPG_LOCAL, INVLPG_ALL, SET_LDT */
365*4882a593Smuzhiyun 		unsigned long linear_addr;
366*4882a593Smuzhiyun 	} arg1;
367*4882a593Smuzhiyun 	union {
368*4882a593Smuzhiyun 		/* SET_LDT */
369*4882a593Smuzhiyun 		unsigned int nr_ents;
370*4882a593Smuzhiyun 		/* TLB_FLUSH_MULTI, INVLPG_MULTI */
371*4882a593Smuzhiyun 		void *vcpumask;
372*4882a593Smuzhiyun 		/* COPY_PAGE */
373*4882a593Smuzhiyun 		xen_pfn_t src_mfn;
374*4882a593Smuzhiyun 	} arg2;
375*4882a593Smuzhiyun };
376*4882a593Smuzhiyun DEFINE_GUEST_HANDLE_STRUCT(mmuext_op);
377*4882a593Smuzhiyun #endif
378*4882a593Smuzhiyun 
379*4882a593Smuzhiyun /* These are passed as 'flags' to update_va_mapping. They can be ORed. */
380*4882a593Smuzhiyun /* When specifying UVMF_MULTI, also OR in a pointer to a CPU bitmap.   */
381*4882a593Smuzhiyun /* UVMF_LOCAL is merely UVMF_MULTI with a NULL bitmap pointer.         */
382*4882a593Smuzhiyun #define UVMF_NONE               (0UL<<0) /* No flushing at all.   */
383*4882a593Smuzhiyun #define UVMF_TLB_FLUSH          (1UL<<0) /* Flush entire TLB(s).  */
384*4882a593Smuzhiyun #define UVMF_INVLPG             (2UL<<0) /* Flush only one entry. */
385*4882a593Smuzhiyun #define UVMF_FLUSHTYPE_MASK     (3UL<<0)
386*4882a593Smuzhiyun #define UVMF_MULTI              (0UL<<2) /* Flush subset of TLBs. */
387*4882a593Smuzhiyun #define UVMF_LOCAL              (0UL<<2) /* Flush local TLB.      */
388*4882a593Smuzhiyun #define UVMF_ALL                (1UL<<2) /* Flush all TLBs.       */
389*4882a593Smuzhiyun 
390*4882a593Smuzhiyun /*
391*4882a593Smuzhiyun  * Commands to HYPERVISOR_console_io().
392*4882a593Smuzhiyun  */
393*4882a593Smuzhiyun #define CONSOLEIO_write         0
394*4882a593Smuzhiyun #define CONSOLEIO_read          1
395*4882a593Smuzhiyun 
396*4882a593Smuzhiyun /*
397*4882a593Smuzhiyun  * Commands to HYPERVISOR_vm_assist().
398*4882a593Smuzhiyun  */
399*4882a593Smuzhiyun #define VMASST_CMD_enable                0
400*4882a593Smuzhiyun #define VMASST_CMD_disable               1
401*4882a593Smuzhiyun 
402*4882a593Smuzhiyun /* x86/32 guests: simulate full 4GB segment limits. */
403*4882a593Smuzhiyun #define VMASST_TYPE_4gb_segments         0
404*4882a593Smuzhiyun 
405*4882a593Smuzhiyun /* x86/32 guests: trap (vector 15) whenever above vmassist is used. */
406*4882a593Smuzhiyun #define VMASST_TYPE_4gb_segments_notify  1
407*4882a593Smuzhiyun 
408*4882a593Smuzhiyun /*
409*4882a593Smuzhiyun  * x86 guests: support writes to bottom-level PTEs.
410*4882a593Smuzhiyun  * NB1. Page-directory entries cannot be written.
411*4882a593Smuzhiyun  * NB2. Guest must continue to remove all writable mappings of PTEs.
412*4882a593Smuzhiyun  */
413*4882a593Smuzhiyun #define VMASST_TYPE_writable_pagetables  2
414*4882a593Smuzhiyun 
415*4882a593Smuzhiyun /* x86/PAE guests: support PDPTs above 4GB. */
416*4882a593Smuzhiyun #define VMASST_TYPE_pae_extended_cr3     3
417*4882a593Smuzhiyun 
418*4882a593Smuzhiyun /*
419*4882a593Smuzhiyun  * x86 guests: Sane behaviour for virtual iopl
420*4882a593Smuzhiyun  *  - virtual iopl updated from do_iret() hypercalls.
421*4882a593Smuzhiyun  *  - virtual iopl reported in bounce frames.
422*4882a593Smuzhiyun  *  - guest kernels assumed to be level 0 for the purpose of iopl checks.
423*4882a593Smuzhiyun  */
424*4882a593Smuzhiyun #define VMASST_TYPE_architectural_iopl   4
425*4882a593Smuzhiyun 
426*4882a593Smuzhiyun /*
427*4882a593Smuzhiyun  * All guests: activate update indicator in vcpu_runstate_info
428*4882a593Smuzhiyun  * Enable setting the XEN_RUNSTATE_UPDATE flag in guest memory mapped
429*4882a593Smuzhiyun  * vcpu_runstate_info during updates of the runstate information.
430*4882a593Smuzhiyun  */
431*4882a593Smuzhiyun #define VMASST_TYPE_runstate_update_flag 5
432*4882a593Smuzhiyun 
433*4882a593Smuzhiyun #define MAX_VMASST_TYPE 5
434*4882a593Smuzhiyun 
435*4882a593Smuzhiyun #ifndef __ASSEMBLY__
436*4882a593Smuzhiyun 
437*4882a593Smuzhiyun typedef uint16_t domid_t;
438*4882a593Smuzhiyun 
439*4882a593Smuzhiyun /* Domain ids >= DOMID_FIRST_RESERVED cannot be used for ordinary domains. */
440*4882a593Smuzhiyun #define DOMID_FIRST_RESERVED (0x7FF0U)
441*4882a593Smuzhiyun 
442*4882a593Smuzhiyun /* DOMID_SELF is used in certain contexts to refer to oneself. */
443*4882a593Smuzhiyun #define DOMID_SELF (0x7FF0U)
444*4882a593Smuzhiyun 
445*4882a593Smuzhiyun /*
446*4882a593Smuzhiyun  * DOMID_IO is used to restrict page-table updates to mapping I/O memory.
447*4882a593Smuzhiyun  * Although no Foreign Domain need be specified to map I/O pages, DOMID_IO
448*4882a593Smuzhiyun  * is useful to ensure that no mappings to the OS's own heap are accidentally
449*4882a593Smuzhiyun  * installed. (e.g., in Linux this could cause havoc as reference counts
450*4882a593Smuzhiyun  * aren't adjusted on the I/O-mapping code path).
451*4882a593Smuzhiyun  * This only makes sense in MMUEXT_SET_FOREIGNDOM, but in that context can
452*4882a593Smuzhiyun  * be specified by any calling domain.
453*4882a593Smuzhiyun  */
454*4882a593Smuzhiyun #define DOMID_IO   (0x7FF1U)
455*4882a593Smuzhiyun 
456*4882a593Smuzhiyun /*
457*4882a593Smuzhiyun  * DOMID_XEN is used to allow privileged domains to map restricted parts of
458*4882a593Smuzhiyun  * Xen's heap space (e.g., the machine_to_phys table).
459*4882a593Smuzhiyun  * This only makes sense in MMUEXT_SET_FOREIGNDOM, and is only permitted if
460*4882a593Smuzhiyun  * the caller is privileged.
461*4882a593Smuzhiyun  */
462*4882a593Smuzhiyun #define DOMID_XEN  (0x7FF2U)
463*4882a593Smuzhiyun 
464*4882a593Smuzhiyun /* DOMID_COW is used as the owner of sharable pages */
465*4882a593Smuzhiyun #define DOMID_COW  (0x7FF3U)
466*4882a593Smuzhiyun 
467*4882a593Smuzhiyun /* DOMID_INVALID is used to identify pages with unknown owner. */
468*4882a593Smuzhiyun #define DOMID_INVALID (0x7FF4U)
469*4882a593Smuzhiyun 
470*4882a593Smuzhiyun /* Idle domain. */
471*4882a593Smuzhiyun #define DOMID_IDLE (0x7FFFU)
472*4882a593Smuzhiyun 
473*4882a593Smuzhiyun /*
474*4882a593Smuzhiyun  * Send an array of these to HYPERVISOR_mmu_update().
475*4882a593Smuzhiyun  * NB. The fields are natural pointer/address size for this architecture.
476*4882a593Smuzhiyun  */
477*4882a593Smuzhiyun struct mmu_update {
478*4882a593Smuzhiyun     uint64_t ptr;       /* Machine address of PTE. */
479*4882a593Smuzhiyun     uint64_t val;       /* New contents of PTE.    */
480*4882a593Smuzhiyun };
481*4882a593Smuzhiyun DEFINE_GUEST_HANDLE_STRUCT(mmu_update);
482*4882a593Smuzhiyun 
483*4882a593Smuzhiyun /*
484*4882a593Smuzhiyun  * Send an array of these to HYPERVISOR_multicall().
485*4882a593Smuzhiyun  * NB. The fields are logically the natural register size for this
486*4882a593Smuzhiyun  * architecture. In cases where xen_ulong_t is larger than this then
487*4882a593Smuzhiyun  * any unused bits in the upper portion must be zero.
488*4882a593Smuzhiyun  */
489*4882a593Smuzhiyun struct multicall_entry {
490*4882a593Smuzhiyun     xen_ulong_t op;
491*4882a593Smuzhiyun     xen_long_t result;
492*4882a593Smuzhiyun     xen_ulong_t args[6];
493*4882a593Smuzhiyun };
494*4882a593Smuzhiyun DEFINE_GUEST_HANDLE_STRUCT(multicall_entry);
495*4882a593Smuzhiyun 
496*4882a593Smuzhiyun struct vcpu_time_info {
497*4882a593Smuzhiyun 	/*
498*4882a593Smuzhiyun 	 * Updates to the following values are preceded and followed
499*4882a593Smuzhiyun 	 * by an increment of 'version'. The guest can therefore
500*4882a593Smuzhiyun 	 * detect updates by looking for changes to 'version'. If the
501*4882a593Smuzhiyun 	 * least-significant bit of the version number is set then an
502*4882a593Smuzhiyun 	 * update is in progress and the guest must wait to read a
503*4882a593Smuzhiyun 	 * consistent set of values.  The correct way to interact with
504*4882a593Smuzhiyun 	 * the version number is similar to Linux's seqlock: see the
505*4882a593Smuzhiyun 	 * implementations of read_seqbegin/read_seqretry.
506*4882a593Smuzhiyun 	 */
507*4882a593Smuzhiyun 	uint32_t version;
508*4882a593Smuzhiyun 	uint32_t pad0;
509*4882a593Smuzhiyun 	uint64_t tsc_timestamp;   /* TSC at last update of time vals.  */
510*4882a593Smuzhiyun 	uint64_t system_time;     /* Time, in nanosecs, since boot.    */
511*4882a593Smuzhiyun 	/*
512*4882a593Smuzhiyun 	 * Current system time:
513*4882a593Smuzhiyun 	 *   system_time + ((tsc - tsc_timestamp) << tsc_shift) * tsc_to_system_mul
514*4882a593Smuzhiyun 	 * CPU frequency (Hz):
515*4882a593Smuzhiyun 	 *   ((10^9 << 32) / tsc_to_system_mul) >> tsc_shift
516*4882a593Smuzhiyun 	 */
517*4882a593Smuzhiyun 	uint32_t tsc_to_system_mul;
518*4882a593Smuzhiyun 	int8_t   tsc_shift;
519*4882a593Smuzhiyun 	int8_t   pad1[3];
520*4882a593Smuzhiyun }; /* 32 bytes */
521*4882a593Smuzhiyun 
522*4882a593Smuzhiyun struct vcpu_info {
523*4882a593Smuzhiyun 	/*
524*4882a593Smuzhiyun 	 * 'evtchn_upcall_pending' is written non-zero by Xen to indicate
525*4882a593Smuzhiyun 	 * a pending notification for a particular VCPU. It is then cleared
526*4882a593Smuzhiyun 	 * by the guest OS /before/ checking for pending work, thus avoiding
527*4882a593Smuzhiyun 	 * a set-and-check race. Note that the mask is only accessed by Xen
528*4882a593Smuzhiyun 	 * on the CPU that is currently hosting the VCPU. This means that the
529*4882a593Smuzhiyun 	 * pending and mask flags can be updated by the guest without special
530*4882a593Smuzhiyun 	 * synchronisation (i.e., no need for the x86 LOCK prefix).
531*4882a593Smuzhiyun 	 * This may seem suboptimal because if the pending flag is set by
532*4882a593Smuzhiyun 	 * a different CPU then an IPI may be scheduled even when the mask
533*4882a593Smuzhiyun 	 * is set. However, note:
534*4882a593Smuzhiyun 	 *  1. The task of 'interrupt holdoff' is covered by the per-event-
535*4882a593Smuzhiyun 	 *     channel mask bits. A 'noisy' event that is continually being
536*4882a593Smuzhiyun 	 *     triggered can be masked at source at this very precise
537*4882a593Smuzhiyun 	 *     granularity.
538*4882a593Smuzhiyun 	 *  2. The main purpose of the per-VCPU mask is therefore to restrict
539*4882a593Smuzhiyun 	 *     reentrant execution: whether for concurrency control, or to
540*4882a593Smuzhiyun 	 *     prevent unbounded stack usage. Whatever the purpose, we expect
541*4882a593Smuzhiyun 	 *     that the mask will be asserted only for short periods at a time,
542*4882a593Smuzhiyun 	 *     and so the likelihood of a 'spurious' IPI is suitably small.
543*4882a593Smuzhiyun 	 * The mask is read before making an event upcall to the guest: a
544*4882a593Smuzhiyun 	 * non-zero mask therefore guarantees that the VCPU will not receive
545*4882a593Smuzhiyun 	 * an upcall activation. The mask is cleared when the VCPU requests
546*4882a593Smuzhiyun 	 * to block: this avoids wakeup-waiting races.
547*4882a593Smuzhiyun 	 */
548*4882a593Smuzhiyun 	uint8_t evtchn_upcall_pending;
549*4882a593Smuzhiyun 	uint8_t evtchn_upcall_mask;
550*4882a593Smuzhiyun 	xen_ulong_t evtchn_pending_sel;
551*4882a593Smuzhiyun 	struct arch_vcpu_info arch;
552*4882a593Smuzhiyun 	struct pvclock_vcpu_time_info time;
553*4882a593Smuzhiyun }; /* 64 bytes (x86) */
554*4882a593Smuzhiyun 
555*4882a593Smuzhiyun /*
556*4882a593Smuzhiyun  * Xen/kernel shared data -- pointer provided in start_info.
557*4882a593Smuzhiyun  * NB. We expect that this struct is smaller than a page.
558*4882a593Smuzhiyun  */
559*4882a593Smuzhiyun struct shared_info {
560*4882a593Smuzhiyun 	struct vcpu_info vcpu_info[MAX_VIRT_CPUS];
561*4882a593Smuzhiyun 
562*4882a593Smuzhiyun 	/*
563*4882a593Smuzhiyun 	 * A domain can create "event channels" on which it can send and receive
564*4882a593Smuzhiyun 	 * asynchronous event notifications. There are three classes of event that
565*4882a593Smuzhiyun 	 * are delivered by this mechanism:
566*4882a593Smuzhiyun 	 *  1. Bi-directional inter- and intra-domain connections. Domains must
567*4882a593Smuzhiyun 	 *     arrange out-of-band to set up a connection (usually by allocating
568*4882a593Smuzhiyun 	 *     an unbound 'listener' port and avertising that via a storage service
569*4882a593Smuzhiyun 	 *     such as xenstore).
570*4882a593Smuzhiyun 	 *  2. Physical interrupts. A domain with suitable hardware-access
571*4882a593Smuzhiyun 	 *     privileges can bind an event-channel port to a physical interrupt
572*4882a593Smuzhiyun 	 *     source.
573*4882a593Smuzhiyun 	 *  3. Virtual interrupts ('events'). A domain can bind an event-channel
574*4882a593Smuzhiyun 	 *     port to a virtual interrupt source, such as the virtual-timer
575*4882a593Smuzhiyun 	 *     device or the emergency console.
576*4882a593Smuzhiyun 	 *
577*4882a593Smuzhiyun 	 * Event channels are addressed by a "port index". Each channel is
578*4882a593Smuzhiyun 	 * associated with two bits of information:
579*4882a593Smuzhiyun 	 *  1. PENDING -- notifies the domain that there is a pending notification
580*4882a593Smuzhiyun 	 *     to be processed. This bit is cleared by the guest.
581*4882a593Smuzhiyun 	 *  2. MASK -- if this bit is clear then a 0->1 transition of PENDING
582*4882a593Smuzhiyun 	 *     will cause an asynchronous upcall to be scheduled. This bit is only
583*4882a593Smuzhiyun 	 *     updated by the guest. It is read-only within Xen. If a channel
584*4882a593Smuzhiyun 	 *     becomes pending while the channel is masked then the 'edge' is lost
585*4882a593Smuzhiyun 	 *     (i.e., when the channel is unmasked, the guest must manually handle
586*4882a593Smuzhiyun 	 *     pending notifications as no upcall will be scheduled by Xen).
587*4882a593Smuzhiyun 	 *
588*4882a593Smuzhiyun 	 * To expedite scanning of pending notifications, any 0->1 pending
589*4882a593Smuzhiyun 	 * transition on an unmasked channel causes a corresponding bit in a
590*4882a593Smuzhiyun 	 * per-vcpu selector word to be set. Each bit in the selector covers a
591*4882a593Smuzhiyun 	 * 'C long' in the PENDING bitfield array.
592*4882a593Smuzhiyun 	 */
593*4882a593Smuzhiyun 	xen_ulong_t evtchn_pending[sizeof(xen_ulong_t) * 8];
594*4882a593Smuzhiyun 	xen_ulong_t evtchn_mask[sizeof(xen_ulong_t) * 8];
595*4882a593Smuzhiyun 
596*4882a593Smuzhiyun 	/*
597*4882a593Smuzhiyun 	 * Wallclock time: updated only by control software. Guests should base
598*4882a593Smuzhiyun 	 * their gettimeofday() syscall on this wallclock-base value.
599*4882a593Smuzhiyun 	 */
600*4882a593Smuzhiyun 	struct pvclock_wall_clock wc;
601*4882a593Smuzhiyun 
602*4882a593Smuzhiyun 	struct arch_shared_info arch;
603*4882a593Smuzhiyun 
604*4882a593Smuzhiyun };
605*4882a593Smuzhiyun 
606*4882a593Smuzhiyun /*
607*4882a593Smuzhiyun  * Start-of-day memory layout
608*4882a593Smuzhiyun  *
609*4882a593Smuzhiyun  *  1. The domain is started within contiguous virtual-memory region.
610*4882a593Smuzhiyun  *  2. The contiguous region begins and ends on an aligned 4MB boundary.
611*4882a593Smuzhiyun  *  3. This the order of bootstrap elements in the initial virtual region:
612*4882a593Smuzhiyun  *      a. relocated kernel image
613*4882a593Smuzhiyun  *      b. initial ram disk              [mod_start, mod_len]
614*4882a593Smuzhiyun  *         (may be omitted)
615*4882a593Smuzhiyun  *      c. list of allocated page frames [mfn_list, nr_pages]
616*4882a593Smuzhiyun  *         (unless relocated due to XEN_ELFNOTE_INIT_P2M)
617*4882a593Smuzhiyun  *      d. start_info_t structure        [register ESI (x86)]
618*4882a593Smuzhiyun  *         in case of dom0 this page contains the console info, too
619*4882a593Smuzhiyun  *      e. unless dom0: xenstore ring page
620*4882a593Smuzhiyun  *      f. unless dom0: console ring page
621*4882a593Smuzhiyun  *      g. bootstrap page tables         [pt_base, CR3 (x86)]
622*4882a593Smuzhiyun  *      h. bootstrap stack               [register ESP (x86)]
623*4882a593Smuzhiyun  *  4. Bootstrap elements are packed together, but each is 4kB-aligned.
624*4882a593Smuzhiyun  *  5. The list of page frames forms a contiguous 'pseudo-physical' memory
625*4882a593Smuzhiyun  *     layout for the domain. In particular, the bootstrap virtual-memory
626*4882a593Smuzhiyun  *     region is a 1:1 mapping to the first section of the pseudo-physical map.
627*4882a593Smuzhiyun  *  6. All bootstrap elements are mapped read-writable for the guest OS. The
628*4882a593Smuzhiyun  *     only exception is the bootstrap page table, which is mapped read-only.
629*4882a593Smuzhiyun  *  7. There is guaranteed to be at least 512kB padding after the final
630*4882a593Smuzhiyun  *     bootstrap element. If necessary, the bootstrap virtual region is
631*4882a593Smuzhiyun  *     extended by an extra 4MB to ensure this.
632*4882a593Smuzhiyun  */
633*4882a593Smuzhiyun 
634*4882a593Smuzhiyun #define MAX_GUEST_CMDLINE 1024
635*4882a593Smuzhiyun struct start_info {
636*4882a593Smuzhiyun 	/* THE FOLLOWING ARE FILLED IN BOTH ON INITIAL BOOT AND ON RESUME.    */
637*4882a593Smuzhiyun 	char magic[32];             /* "xen-<version>-<platform>".            */
638*4882a593Smuzhiyun 	unsigned long nr_pages;     /* Total pages allocated to this domain.  */
639*4882a593Smuzhiyun 	unsigned long shared_info;  /* MACHINE address of shared info struct. */
640*4882a593Smuzhiyun 	uint32_t flags;             /* SIF_xxx flags.                         */
641*4882a593Smuzhiyun 	xen_pfn_t store_mfn;        /* MACHINE page number of shared page.    */
642*4882a593Smuzhiyun 	uint32_t store_evtchn;      /* Event channel for store communication. */
643*4882a593Smuzhiyun 	union {
644*4882a593Smuzhiyun 		struct {
645*4882a593Smuzhiyun 			xen_pfn_t mfn;      /* MACHINE page number of console page.   */
646*4882a593Smuzhiyun 			uint32_t  evtchn;   /* Event channel for console page.        */
647*4882a593Smuzhiyun 		} domU;
648*4882a593Smuzhiyun 		struct {
649*4882a593Smuzhiyun 			uint32_t info_off;  /* Offset of console_info struct.         */
650*4882a593Smuzhiyun 			uint32_t info_size; /* Size of console_info struct from start.*/
651*4882a593Smuzhiyun 		} dom0;
652*4882a593Smuzhiyun 	} console;
653*4882a593Smuzhiyun 	/* THE FOLLOWING ARE ONLY FILLED IN ON INITIAL BOOT (NOT RESUME).     */
654*4882a593Smuzhiyun 	unsigned long pt_base;      /* VIRTUAL address of page directory.     */
655*4882a593Smuzhiyun 	unsigned long nr_pt_frames; /* Number of bootstrap p.t. frames.       */
656*4882a593Smuzhiyun 	unsigned long mfn_list;     /* VIRTUAL address of page-frame list.    */
657*4882a593Smuzhiyun 	unsigned long mod_start;    /* VIRTUAL address of pre-loaded module.  */
658*4882a593Smuzhiyun 	unsigned long mod_len;      /* Size (bytes) of pre-loaded module.     */
659*4882a593Smuzhiyun 	int8_t cmd_line[MAX_GUEST_CMDLINE];
660*4882a593Smuzhiyun 	/* The pfn range here covers both page table and p->m table frames.   */
661*4882a593Smuzhiyun 	unsigned long first_p2m_pfn;/* 1st pfn forming initial P->M table.    */
662*4882a593Smuzhiyun 	unsigned long nr_p2m_frames;/* # of pfns forming initial P->M table.  */
663*4882a593Smuzhiyun };
664*4882a593Smuzhiyun 
665*4882a593Smuzhiyun /* These flags are passed in the 'flags' field of start_info_t. */
666*4882a593Smuzhiyun #define SIF_PRIVILEGED      (1<<0)  /* Is the domain privileged? */
667*4882a593Smuzhiyun #define SIF_INITDOMAIN      (1<<1)  /* Is this the initial control domain? */
668*4882a593Smuzhiyun #define SIF_MULTIBOOT_MOD   (1<<2)  /* Is mod_start a multiboot module? */
669*4882a593Smuzhiyun #define SIF_MOD_START_PFN   (1<<3)  /* Is mod_start a PFN? */
670*4882a593Smuzhiyun #define SIF_VIRT_P2M_4TOOLS (1<<4)  /* Do Xen tools understand a virt. mapped */
671*4882a593Smuzhiyun 				    /* P->M making the 3 level tree obsolete? */
672*4882a593Smuzhiyun #define SIF_PM_MASK       (0xFF<<8) /* reserve 1 byte for xen-pm options */
673*4882a593Smuzhiyun 
674*4882a593Smuzhiyun /*
675*4882a593Smuzhiyun  * A multiboot module is a package containing modules very similar to a
676*4882a593Smuzhiyun  * multiboot module array. The only differences are:
677*4882a593Smuzhiyun  * - the array of module descriptors is by convention simply at the beginning
678*4882a593Smuzhiyun  *   of the multiboot module,
679*4882a593Smuzhiyun  * - addresses in the module descriptors are based on the beginning of the
680*4882a593Smuzhiyun  *   multiboot module,
681*4882a593Smuzhiyun  * - the number of modules is determined by a termination descriptor that has
682*4882a593Smuzhiyun  *   mod_start == 0.
683*4882a593Smuzhiyun  *
684*4882a593Smuzhiyun  * This permits to both build it statically and reference it in a configuration
685*4882a593Smuzhiyun  * file, and let the PV guest easily rebase the addresses to virtual addresses
686*4882a593Smuzhiyun  * and at the same time count the number of modules.
687*4882a593Smuzhiyun  */
688*4882a593Smuzhiyun struct xen_multiboot_mod_list {
689*4882a593Smuzhiyun 	/* Address of first byte of the module */
690*4882a593Smuzhiyun 	uint32_t mod_start;
691*4882a593Smuzhiyun 	/* Address of last byte of the module (inclusive) */
692*4882a593Smuzhiyun 	uint32_t mod_end;
693*4882a593Smuzhiyun 	/* Address of zero-terminated command line */
694*4882a593Smuzhiyun 	uint32_t cmdline;
695*4882a593Smuzhiyun 	/* Unused, must be zero */
696*4882a593Smuzhiyun 	uint32_t pad;
697*4882a593Smuzhiyun };
698*4882a593Smuzhiyun /*
699*4882a593Smuzhiyun  * The console structure in start_info.console.dom0
700*4882a593Smuzhiyun  *
701*4882a593Smuzhiyun  * This structure includes a variety of information required to
702*4882a593Smuzhiyun  * have a working VGA/VESA console.
703*4882a593Smuzhiyun  */
704*4882a593Smuzhiyun struct dom0_vga_console_info {
705*4882a593Smuzhiyun 	uint8_t video_type;
706*4882a593Smuzhiyun #define XEN_VGATYPE_TEXT_MODE_3 0x03
707*4882a593Smuzhiyun #define XEN_VGATYPE_VESA_LFB    0x23
708*4882a593Smuzhiyun #define XEN_VGATYPE_EFI_LFB     0x70
709*4882a593Smuzhiyun 
710*4882a593Smuzhiyun 	union {
711*4882a593Smuzhiyun 		struct {
712*4882a593Smuzhiyun 			/* Font height, in pixels. */
713*4882a593Smuzhiyun 			uint16_t font_height;
714*4882a593Smuzhiyun 			/* Cursor location (column, row). */
715*4882a593Smuzhiyun 			uint16_t cursor_x, cursor_y;
716*4882a593Smuzhiyun 			/* Number of rows and columns (dimensions in characters). */
717*4882a593Smuzhiyun 			uint16_t rows, columns;
718*4882a593Smuzhiyun 		} text_mode_3;
719*4882a593Smuzhiyun 
720*4882a593Smuzhiyun 		struct {
721*4882a593Smuzhiyun 			/* Width and height, in pixels. */
722*4882a593Smuzhiyun 			uint16_t width, height;
723*4882a593Smuzhiyun 			/* Bytes per scan line. */
724*4882a593Smuzhiyun 			uint16_t bytes_per_line;
725*4882a593Smuzhiyun 			/* Bits per pixel. */
726*4882a593Smuzhiyun 			uint16_t bits_per_pixel;
727*4882a593Smuzhiyun 			/* LFB physical address, and size (in units of 64kB). */
728*4882a593Smuzhiyun 			uint32_t lfb_base;
729*4882a593Smuzhiyun 			uint32_t lfb_size;
730*4882a593Smuzhiyun 			/* RGB mask offsets and sizes, as defined by VBE 1.2+ */
731*4882a593Smuzhiyun 			uint8_t  red_pos, red_size;
732*4882a593Smuzhiyun 			uint8_t  green_pos, green_size;
733*4882a593Smuzhiyun 			uint8_t  blue_pos, blue_size;
734*4882a593Smuzhiyun 			uint8_t  rsvd_pos, rsvd_size;
735*4882a593Smuzhiyun 
736*4882a593Smuzhiyun 			/* VESA capabilities (offset 0xa, VESA command 0x4f00). */
737*4882a593Smuzhiyun 			uint32_t gbl_caps;
738*4882a593Smuzhiyun 			/* Mode attributes (offset 0x0, VESA command 0x4f01). */
739*4882a593Smuzhiyun 			uint16_t mode_attrs;
740*4882a593Smuzhiyun 		} vesa_lfb;
741*4882a593Smuzhiyun 	} u;
742*4882a593Smuzhiyun };
743*4882a593Smuzhiyun 
744*4882a593Smuzhiyun typedef uint64_t cpumap_t;
745*4882a593Smuzhiyun 
746*4882a593Smuzhiyun typedef uint8_t xen_domain_handle_t[16];
747*4882a593Smuzhiyun 
748*4882a593Smuzhiyun /* Turn a plain number into a C unsigned long constant. */
749*4882a593Smuzhiyun #define __mk_unsigned_long(x) x ## UL
750*4882a593Smuzhiyun #define mk_unsigned_long(x) __mk_unsigned_long(x)
751*4882a593Smuzhiyun 
752*4882a593Smuzhiyun #define TMEM_SPEC_VERSION 1
753*4882a593Smuzhiyun 
754*4882a593Smuzhiyun struct tmem_op {
755*4882a593Smuzhiyun 	uint32_t cmd;
756*4882a593Smuzhiyun 	int32_t pool_id;
757*4882a593Smuzhiyun 	union {
758*4882a593Smuzhiyun 		struct {  /* for cmd == TMEM_NEW_POOL */
759*4882a593Smuzhiyun 			uint64_t uuid[2];
760*4882a593Smuzhiyun 			uint32_t flags;
761*4882a593Smuzhiyun 		} new;
762*4882a593Smuzhiyun 		struct {
763*4882a593Smuzhiyun 			uint64_t oid[3];
764*4882a593Smuzhiyun 			uint32_t index;
765*4882a593Smuzhiyun 			uint32_t tmem_offset;
766*4882a593Smuzhiyun 			uint32_t pfn_offset;
767*4882a593Smuzhiyun 			uint32_t len;
768*4882a593Smuzhiyun 			GUEST_HANDLE(void) gmfn; /* guest machine page frame */
769*4882a593Smuzhiyun 		} gen;
770*4882a593Smuzhiyun 	} u;
771*4882a593Smuzhiyun };
772*4882a593Smuzhiyun 
773*4882a593Smuzhiyun DEFINE_GUEST_HANDLE(u64);
774*4882a593Smuzhiyun 
775*4882a593Smuzhiyun #else /* __ASSEMBLY__ */
776*4882a593Smuzhiyun 
777*4882a593Smuzhiyun /* In assembly code we cannot use C numeric constant suffixes. */
778*4882a593Smuzhiyun #define mk_unsigned_long(x) x
779*4882a593Smuzhiyun 
780*4882a593Smuzhiyun #endif /* !__ASSEMBLY__ */
781*4882a593Smuzhiyun 
782*4882a593Smuzhiyun #endif /* __XEN_PUBLIC_XEN_H__ */
783