Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / ipxe / src / include / xen / arch-x86 / xen.h
1 /******************************************************************************
2  * arch-x86/xen.h
3  *
4  * Guest OS interface to x86 Xen.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  * DEALINGS IN THE SOFTWARE.
23  *
24  * Copyright (c) 2004-2006, K A Fraser
25  */
26
27 #include "../xen.h"
28
29 #ifndef __XEN_PUBLIC_ARCH_X86_XEN_H__
30 #define __XEN_PUBLIC_ARCH_X86_XEN_H__
31
32 FILE_LICENCE ( MIT );
33
34 /* Structural guest handles introduced in 0x00030201. */
35 #if __XEN_INTERFACE_VERSION__ >= 0x00030201
36 #define ___DEFINE_XEN_GUEST_HANDLE(name, type) \
37     typedef struct { type *p; } __guest_handle_ ## name
38 #else
39 #define ___DEFINE_XEN_GUEST_HANDLE(name, type) \
40     typedef type * __guest_handle_ ## name
41 #endif
42
43 /*
44  * XEN_GUEST_HANDLE represents a guest pointer, when passed as a field
45  * in a struct in memory.
46  * XEN_GUEST_HANDLE_PARAM represent a guest pointer, when passed as an
47  * hypercall argument.
48  * XEN_GUEST_HANDLE_PARAM and XEN_GUEST_HANDLE are the same on X86 but
49  * they might not be on other architectures.
50  */
51 #define __DEFINE_XEN_GUEST_HANDLE(name, type) \
52     ___DEFINE_XEN_GUEST_HANDLE(name, type);   \
53     ___DEFINE_XEN_GUEST_HANDLE(const_##name, const type)
54 #define DEFINE_XEN_GUEST_HANDLE(name)   __DEFINE_XEN_GUEST_HANDLE(name, name)
55 #define __XEN_GUEST_HANDLE(name)        __guest_handle_ ## name
56 #define XEN_GUEST_HANDLE(name)          __XEN_GUEST_HANDLE(name)
57 #define XEN_GUEST_HANDLE_PARAM(name)    XEN_GUEST_HANDLE(name)
58 #define set_xen_guest_handle_raw(hnd, val)  do { (hnd).p = val; } while (0)
59 #ifdef __XEN_TOOLS__
60 #define get_xen_guest_handle(val, hnd)  do { val = (hnd).p; } while (0)
61 #endif
62 #define set_xen_guest_handle(hnd, val) set_xen_guest_handle_raw(hnd, val)
63
64 #if defined(__i386__)
65 #include "xen-x86_32.h"
66 #elif defined(__x86_64__)
67 #include "xen-x86_64.h"
68 #endif
69
70 #ifndef __ASSEMBLY__
71 typedef unsigned long xen_pfn_t;
72 #define PRI_xen_pfn "lx"
73 #endif
74
75 #define XEN_HAVE_PV_GUEST_ENTRY 1
76
77 #define XEN_HAVE_PV_UPCALL_MASK 1
78
79 /*
80  * `incontents 200 segdesc Segment Descriptor Tables
81  */
82 /*
83  * ` enum neg_errnoval
84  * ` HYPERVISOR_set_gdt(const xen_pfn_t frames[], unsigned int entries);
85  * `
86  */
87 /*
88  * A number of GDT entries are reserved by Xen. These are not situated at the
89  * start of the GDT because some stupid OSes export hard-coded selector values
90  * in their ABI. These hard-coded values are always near the start of the GDT,
91  * so Xen places itself out of the way, at the far end of the GDT.
92  *
93  * NB The LDT is set using the MMUEXT_SET_LDT op of HYPERVISOR_mmuext_op
94  */
95 #define FIRST_RESERVED_GDT_PAGE  14
96 #define FIRST_RESERVED_GDT_BYTE  (FIRST_RESERVED_GDT_PAGE * 4096)
97 #define FIRST_RESERVED_GDT_ENTRY (FIRST_RESERVED_GDT_BYTE / 8)
98
99
100 /*
101  * ` enum neg_errnoval
102  * ` HYPERVISOR_update_descriptor(u64 pa, u64 desc);
103  * `
104  * ` @pa   The machine physical address of the descriptor to
105  * `       update. Must be either a descriptor page or writable.
106  * ` @desc The descriptor value to update, in the same format as a
107  * `       native descriptor table entry.
108  */
109
110 /* Maximum number of virtual CPUs in legacy multi-processor guests. */
111 #define XEN_LEGACY_MAX_VCPUS 32
112
113 #ifndef __ASSEMBLY__
114
115 typedef unsigned long xen_ulong_t;
116 #define PRI_xen_ulong "lx"
117
118 /*
119  * ` enum neg_errnoval
120  * ` HYPERVISOR_stack_switch(unsigned long ss, unsigned long esp);
121  * `
122  * Sets the stack segment and pointer for the current vcpu.
123  */
124
125 /*
126  * ` enum neg_errnoval
127  * ` HYPERVISOR_set_trap_table(const struct trap_info traps[]);
128  * `
129  */
130 /*
131  * Send an array of these to HYPERVISOR_set_trap_table().
132  * Terminate the array with a sentinel entry, with traps[].address==0.
133  * The privilege level specifies which modes may enter a trap via a software
134  * interrupt. On x86/64, since rings 1 and 2 are unavailable, we allocate
135  * privilege levels as follows:
136  *  Level == 0: Noone may enter
137  *  Level == 1: Kernel may enter
138  *  Level == 2: Kernel may enter
139  *  Level == 3: Everyone may enter
140  */
141 #define TI_GET_DPL(_ti)      ((_ti)->flags & 3)
142 #define TI_GET_IF(_ti)       ((_ti)->flags & 4)
143 #define TI_SET_DPL(_ti,_dpl) ((_ti)->flags |= (_dpl))
144 #define TI_SET_IF(_ti,_if)   ((_ti)->flags |= ((!!(_if))<<2))
145 struct trap_info {
146     uint8_t       vector;  /* exception vector                              */
147     uint8_t       flags;   /* 0-3: privilege level; 4: clear event enable?  */
148     uint16_t      cs;      /* code selector                                 */
149     unsigned long address; /* code offset                                   */
150 };
151 typedef struct trap_info trap_info_t;
152 DEFINE_XEN_GUEST_HANDLE(trap_info_t);
153
154 typedef uint64_t tsc_timestamp_t; /* RDTSC timestamp */
155
156 /*
157  * The following is all CPU context. Note that the fpu_ctxt block is filled
158  * in by FXSAVE if the CPU has feature FXSR; otherwise FSAVE is used.
159  *
160  * Also note that when calling DOMCTL_setvcpucontext and VCPU_initialise
161  * for HVM and PVH guests, not all information in this structure is updated:
162  *
163  * - For HVM guests, the structures read include: fpu_ctxt (if
164  * VGCT_I387_VALID is set), flags, user_regs, debugreg[*]
165  *
166  * - PVH guests are the same as HVM guests, but additionally use ctrlreg[3] to
167  * set cr3. All other fields not used should be set to 0.
168  */
169 struct vcpu_guest_context {
170     /* FPU registers come first so they can be aligned for FXSAVE/FXRSTOR. */
171     struct { char x[512]; } fpu_ctxt;       /* User-level FPU registers     */
172 #define VGCF_I387_VALID                (1<<0)
173 #define VGCF_IN_KERNEL                 (1<<2)
174 #define _VGCF_i387_valid               0
175 #define VGCF_i387_valid                (1<<_VGCF_i387_valid)
176 #define _VGCF_in_kernel                2
177 #define VGCF_in_kernel                 (1<<_VGCF_in_kernel)
178 #define _VGCF_failsafe_disables_events 3
179 #define VGCF_failsafe_disables_events  (1<<_VGCF_failsafe_disables_events)
180 #define _VGCF_syscall_disables_events  4
181 #define VGCF_syscall_disables_events   (1<<_VGCF_syscall_disables_events)
182 #define _VGCF_online                   5
183 #define VGCF_online                    (1<<_VGCF_online)
184     unsigned long flags;                    /* VGCF_* flags                 */
185     struct cpu_user_regs user_regs;         /* User-level CPU registers     */
186     struct trap_info trap_ctxt[256];        /* Virtual IDT                  */
187     unsigned long ldt_base, ldt_ents;       /* LDT (linear address, # ents) */
188     unsigned long gdt_frames[16], gdt_ents; /* GDT (machine frames, # ents) */
189     unsigned long kernel_ss, kernel_sp;     /* Virtual TSS (only SS1/SP1)   */
190     /* NB. User pagetable on x86/64 is placed in ctrlreg[1]. */
191     unsigned long ctrlreg[8];               /* CR0-CR7 (control registers)  */
192     unsigned long debugreg[8];              /* DB0-DB7 (debug registers)    */
193 #ifdef __i386__
194     unsigned long event_callback_cs;        /* CS:EIP of event callback     */
195     unsigned long event_callback_eip;
196     unsigned long failsafe_callback_cs;     /* CS:EIP of failsafe callback  */
197     unsigned long failsafe_callback_eip;
198 #else
199     unsigned long event_callback_eip;
200     unsigned long failsafe_callback_eip;
201 #ifdef __XEN__
202     union {
203         unsigned long syscall_callback_eip;
204         struct {
205             unsigned int event_callback_cs;    /* compat CS of event cb     */
206             unsigned int failsafe_callback_cs; /* compat CS of failsafe cb  */
207         };
208     };
209 #else
210     unsigned long syscall_callback_eip;
211 #endif
212 #endif
213     unsigned long vm_assist;                /* VMASST_TYPE_* bitmap */
214 #ifdef __x86_64__
215     /* Segment base addresses. */
216     uint64_t      fs_base;
217     uint64_t      gs_base_kernel;
218     uint64_t      gs_base_user;
219 #endif
220 };
221 typedef struct vcpu_guest_context vcpu_guest_context_t;
222 DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t);
223
224 struct arch_shared_info {
225     unsigned long max_pfn;                  /* max pfn that appears in table */
226     /* Frame containing list of mfns containing list of mfns containing p2m. */
227     xen_pfn_t     pfn_to_mfn_frame_list_list;
228     unsigned long nmi_reason;
229     uint64_t pad[32];
230 };
231 typedef struct arch_shared_info arch_shared_info_t;
232
233 #endif /* !__ASSEMBLY__ */
234
235 /*
236  * ` enum neg_errnoval
237  * ` HYPERVISOR_fpu_taskswitch(int set);
238  * `
239  * Sets (if set!=0) or clears (if set==0) CR0.TS.
240  */
241
242 /*
243  * ` enum neg_errnoval
244  * ` HYPERVISOR_set_debugreg(int regno, unsigned long value);
245  *
246  * ` unsigned long
247  * ` HYPERVISOR_get_debugreg(int regno);
248  * For 0<=reg<=7, returns the debug register value.
249  * For other values of reg, returns ((unsigned long)-EINVAL).
250  * (Unfortunately, this interface is defective.)
251  */
252
253 /*
254  * Prefix forces emulation of some non-trapping instructions.
255  * Currently only CPUID.
256  */
257 #ifdef __ASSEMBLY__
258 #define XEN_EMULATE_PREFIX .byte 0x0f,0x0b,0x78,0x65,0x6e ;
259 #define XEN_CPUID          XEN_EMULATE_PREFIX cpuid
260 #else
261 #define XEN_EMULATE_PREFIX ".byte 0x0f,0x0b,0x78,0x65,0x6e ; "
262 #define XEN_CPUID          XEN_EMULATE_PREFIX "cpuid"
263 #endif
264
265 #endif /* __XEN_PUBLIC_ARCH_X86_XEN_H__ */
266
267 /*
268  * Local variables:
269  * mode: C
270  * c-file-style: "BSD"
271  * c-basic-offset: 4
272  * tab-width: 4
273  * indent-tabs-mode: nil
274  * End:
275  */