xref: /titanic_50/usr/src/uts/common/xen/public/arch-x86/xen.h (revision 15db28971f91c98efb449aebf46024ac72779fa3)
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 /* Structural guest handles introduced in 0x00030201. */
33 #if __XEN_INTERFACE_VERSION__ >= 0x00030201
34 #define ___DEFINE_XEN_GUEST_HANDLE(name, type) \
35     typedef struct { type *p; } __guest_handle_ ## name
36 #else
37 #define ___DEFINE_XEN_GUEST_HANDLE(name, type) \
38     typedef type * __guest_handle_ ## name
39 #endif
40 
41 #define __DEFINE_XEN_GUEST_HANDLE(name, type) \
42     ___DEFINE_XEN_GUEST_HANDLE(name, type);   \
43     ___DEFINE_XEN_GUEST_HANDLE(const_##name, const type)
44 #define DEFINE_XEN_GUEST_HANDLE(name)   __DEFINE_XEN_GUEST_HANDLE(name, name)
45 #define __XEN_GUEST_HANDLE(name)        __guest_handle_ ## name
46 #define XEN_GUEST_HANDLE(name)          __XEN_GUEST_HANDLE(name)
47 #define set_xen_guest_handle(hnd, val)  do { (hnd).p = val; } while (0)
48 #ifdef __XEN_TOOLS__
49 #define get_xen_guest_handle(val, hnd)  do { val = (hnd).p; } while (0)
50 #endif
51 
52 #if defined(__i386__)
53 #include "xen-x86_32.h"
54 #elif defined(__x86_64__)
55 #include "xen-x86_64.h"
56 #endif
57 
58 #ifndef __ASSEMBLY__
59 typedef unsigned long xen_pfn_t;
60 #define PRI_xen_pfn "lx"
61 #endif
62 
63 /*
64  * SEGMENT DESCRIPTOR TABLES
65  */
66 /*
67  * A number of GDT entries are reserved by Xen. These are not situated at the
68  * start of the GDT because some stupid OSes export hard-coded selector values
69  * in their ABI. These hard-coded values are always near the start of the GDT,
70  * so Xen places itself out of the way, at the far end of the GDT.
71  */
72 #define FIRST_RESERVED_GDT_PAGE  14
73 #define FIRST_RESERVED_GDT_BYTE  (FIRST_RESERVED_GDT_PAGE * 4096)
74 #define FIRST_RESERVED_GDT_ENTRY (FIRST_RESERVED_GDT_BYTE / 8)
75 
76 /* Maximum number of virtual CPUs in multi-processor guests. */
77 #define MAX_VIRT_CPUS 32
78 
79 
80 /* Machine check support */
81 #include "xen-mca.h"
82 
83 #ifndef __ASSEMBLY__
84 
85 typedef unsigned long xen_ulong_t;
86 
87 /*
88  * Send an array of these to HYPERVISOR_set_trap_table().
89  * The privilege level specifies which modes may enter a trap via a software
90  * interrupt. On x86/64, since rings 1 and 2 are unavailable, we allocate
91  * privilege levels as follows:
92  *  Level == 0: Noone may enter
93  *  Level == 1: Kernel may enter
94  *  Level == 2: Kernel may enter
95  *  Level == 3: Everyone may enter
96  */
97 #define TI_GET_DPL(_ti)      ((_ti)->flags & 3)
98 #define TI_GET_IF(_ti)       ((_ti)->flags & 4)
99 #define TI_SET_DPL(_ti,_dpl) ((_ti)->flags |= (_dpl))
100 #define TI_SET_IF(_ti,_if)   ((_ti)->flags |= ((!!(_if))<<2))
101 struct trap_info {
102     uint8_t       vector;  /* exception vector                              */
103     uint8_t       flags;   /* 0-3: privilege level; 4: clear event enable?  */
104     uint16_t      cs;      /* code selector                                 */
105     unsigned long address; /* code offset                                   */
106 };
107 typedef struct trap_info trap_info_t;
108 DEFINE_XEN_GUEST_HANDLE(trap_info_t);
109 
110 typedef uint64_t tsc_timestamp_t; /* RDTSC timestamp */
111 
112 /*
113  * The following is all CPU context. Note that the fpu_ctxt block is filled
114  * in by FXSAVE if the CPU has feature FXSR; otherwise FSAVE is used.
115  */
116 struct vcpu_guest_context {
117     /* FPU registers come first so they can be aligned for FXSAVE/FXRSTOR. */
118     struct { char x[512]; } fpu_ctxt;       /* User-level FPU registers     */
119 #define VGCF_I387_VALID                (1<<0)
120 #define VGCF_IN_KERNEL                 (1<<2)
121 #define _VGCF_i387_valid               0
122 #define VGCF_i387_valid                (1<<_VGCF_i387_valid)
123 #define _VGCF_in_kernel                2
124 #define VGCF_in_kernel                 (1<<_VGCF_in_kernel)
125 #define _VGCF_failsafe_disables_events 3
126 #define VGCF_failsafe_disables_events  (1<<_VGCF_failsafe_disables_events)
127 #define _VGCF_syscall_disables_events  4
128 #define VGCF_syscall_disables_events   (1<<_VGCF_syscall_disables_events)
129 #define _VGCF_online                   5
130 #define VGCF_online                    (1<<_VGCF_online)
131     unsigned long flags;                    /* VGCF_* flags                 */
132     struct cpu_user_regs user_regs;         /* User-level CPU registers     */
133     struct trap_info trap_ctxt[256];        /* Virtual IDT                  */
134     unsigned long ldt_base, ldt_ents;       /* LDT (linear address, # ents) */
135     unsigned long gdt_frames[16], gdt_ents; /* GDT (machine frames, # ents) */
136     unsigned long kernel_ss, kernel_sp;     /* Virtual TSS (only SS1/SP1)   */
137     /* NB. User pagetable on x86/64 is placed in ctrlreg[1]. */
138     unsigned long ctrlreg[8];               /* CR0-CR7 (control registers)  */
139     unsigned long debugreg[8];              /* DB0-DB7 (debug registers)    */
140 #ifdef __i386__
141     unsigned long event_callback_cs;        /* CS:EIP of event callback     */
142     unsigned long event_callback_eip;
143     unsigned long failsafe_callback_cs;     /* CS:EIP of failsafe callback  */
144     unsigned long failsafe_callback_eip;
145 #else
146     unsigned long event_callback_eip;
147     unsigned long failsafe_callback_eip;
148 #ifdef __XEN__
149     union {
150         unsigned long syscall_callback_eip;
151         struct {
152             unsigned int event_callback_cs;    /* compat CS of event cb     */
153             unsigned int failsafe_callback_cs; /* compat CS of failsafe cb  */
154         };
155     };
156 #else
157     unsigned long syscall_callback_eip;
158 #endif
159 #endif
160     unsigned long vm_assist;                /* VMASST_TYPE_* bitmap */
161 #ifdef __x86_64__
162     /* Segment base addresses. */
163     uint64_t      fs_base;
164     uint64_t      gs_base_kernel;
165     uint64_t      gs_base_user;
166 #endif
167 };
168 typedef struct vcpu_guest_context vcpu_guest_context_t;
169 DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t);
170 
171 struct arch_shared_info {
172     unsigned long max_pfn;                  /* max pfn that appears in table */
173     /* Frame containing list of mfns containing list of mfns containing p2m. */
174     xen_pfn_t     pfn_to_mfn_frame_list_list;
175     unsigned long nmi_reason;
176     uint64_t pad[32];
177 };
178 typedef struct arch_shared_info arch_shared_info_t;
179 
180 #define	MCA_PANICDATA_MAGIC	0x5044  /* "PD" */
181 #define MCA_PANICDATA_VERS	1
182 
183 typedef struct xpv_mca_panic_data {
184 	uint16_t mpd_magic;
185 	uint16_t mpd_version;
186 	int mpd_fwdptr_offset;
187 	int mpd_revptr_offset;
188 	int mpd_dataptr_offset;
189 	void *mpd_urgent_processing;
190 	void *mpd_urgent_dangling;
191 	void *mpd_urgent_committed;
192 	void *mpd_nonurgent_processing;
193 	void *mpd_nonurgent_dangling;
194 	void *mpd_nonurgent_committed;
195 } xpv_mca_panic_data_t;
196 
197 typedef struct panic_regs panic_regs_t;
198 struct panic_info {
199 	int		pi_version;	/* panic_info format version */
200 	panic_regs_t	*pi_regs;	/* register state */
201 	void		*pi_apic;	/* local APIC address */
202 	char		*pi_panicstr;	/* panic message */
203 	void		*pi_ram_start;	/* Start of all-RAM mapping region */
204 	void		*pi_ram_end;	/* End of all-RAM mapping region */
205 	void		*pi_xen_start;	/* Start of Xen's text/heap */
206 	void		*pi_xen_end;	/* End of Xen's text/heap */
207 	void		*pi_stktop;	/* Top of current Xen stack */
208 	struct domain	*pi_domain;	/* Panicking domain */
209 	struct vcpu	*pi_vcpu;	/* Panicking vcpu */
210 	int		pi_dom0cpu;	/* cpu number - if a dom0 panic */
211 	xpv_mca_panic_data_t pi_mca;	/* Machine check error telemetry */
212 };
213 
214 struct panic_frame {
215 	unsigned long	pf_fp;
216 	unsigned long	pf_pc;
217 };
218 
219 #define PANIC_INFO_VERSION	3
220 
221 #endif /* !__ASSEMBLY__ */
222 
223 /*
224  * Prefix forces emulation of some non-trapping instructions.
225  * Currently only CPUID.
226  */
227 #ifdef __ASSEMBLY__
228 #define XEN_EMULATE_PREFIX .byte 0x0f,0x0b,0x78,0x65,0x6e ;
229 #define XEN_CPUID          XEN_EMULATE_PREFIX cpuid
230 #else
231 #define XEN_EMULATE_PREFIX ".byte 0x0f,0x0b,0x78,0x65,0x6e ; "
232 #define XEN_CPUID          XEN_EMULATE_PREFIX "cpuid"
233 #endif
234 
235 #endif /* __XEN_PUBLIC_ARCH_X86_XEN_H__ */
236 
237 /*
238  * Local variables:
239  * mode: C
240  * c-set-style: "BSD"
241  * c-basic-offset: 4
242  * tab-width: 4
243  * indent-tabs-mode: nil
244  * End:
245  */
246