gst-plugins-ugly1: update to 1.24.10
[oi-userland.git] / components / openindiana / qemu-kvm / illumos-kvm / kvm_x86.h
blobb90f506707887d68bafaae57b4e946ada20bb3e6
1 /*
2 * GPL HEADER START
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 * GPL HEADER END
19 * Copyright 2011 various Linux Kernel contributors.
20 * Copyright 2011 Joyent, Inc. All Rights Reserved.
23 #ifndef __KVM_X86_H
24 #define __KVM_X86_H
26 /* See <sys/kvm.h> for an explanation of why this is necessary */
27 #ifndef __GNUC__
28 #error "The KVM Header files require GNU C extensions for compatibility."
29 #endif
31 #include <sys/types.h>
33 #define KVM_NR_INTERRUPTS 256
35 /* for KVM_GET_IRQCHIP and KVM_SET_IRQCHIP */
36 typedef struct kvm_pic_state {
37 uint8_t last_irr; /* edge detection */
38 uint8_t irr; /* interrupt request register */
39 uint8_t imr; /* interrupt mask register */
40 uint8_t isr; /* interrupt service register */
41 uint8_t priority_add; /* highest irq priority */
42 uint8_t irq_base;
43 uint8_t read_reg_select;
44 uint8_t poll;
45 uint8_t special_mask;
46 uint8_t init_state;
47 uint8_t auto_eoi;
48 uint8_t rotate_on_auto_eoi;
49 uint8_t special_fully_nested_mode;
50 uint8_t init4; /* true if 4 byte init */
51 uint8_t elcr; /* PIIX edge/trigger selection */
52 uint8_t elcr_mask;
53 } kvm_pic_state_t;
55 #define KVM_IOAPIC_NUM_PINS 24
56 typedef struct kvm_ioapic_state {
57 uint64_t base_address;
58 uint32_t ioregsel;
59 uint32_t id;
60 uint32_t irr;
61 uint32_t pad;
62 union {
63 uint64_t bits;
64 struct {
65 uint8_t vector;
66 uint8_t delivery_mode:3;
67 uint8_t dest_mode:1;
68 uint8_t delivery_status:1;
69 uint8_t polarity:1;
70 uint8_t remote_irr:1;
71 uint8_t trig_mode:1;
72 uint8_t mask:1;
73 uint8_t reserve:7;
74 uint8_t reserved[4];
75 uint8_t dest_id;
76 } fields;
77 } redirtbl[KVM_IOAPIC_NUM_PINS];
78 } kvm_ioapic_state_t;
80 #define KVM_IRQCHIP_PIC_MASTER 0
81 #define KVM_IRQCHIP_PIC_SLAVE 1
82 #define KVM_IRQCHIP_IOAPIC 2
83 #define KVM_NR_IRQCHIPS 3
85 /* for KVM_GET_REGS and KVM_SET_REGS */
86 typedef struct kvm_regs {
87 /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
88 uint64_t rax, rbx, rcx, rdx;
89 uint64_t rsi, rdi, rsp, rbp;
90 uint64_t r8, r9, r10, r11;
91 uint64_t r12, r13, r14, r15;
92 uint64_t rip, rflags;
93 } kvm_regs_t;
95 /* for KVM_GET_LAPIC and KVM_SET_LAPIC */
96 #define KVM_APIC_REG_SIZE 0x400
97 typedef struct kvm_lapic_state {
98 char regs[KVM_APIC_REG_SIZE];
99 } kvm_lapic_state_t;
101 typedef struct kvm_segment {
102 uint64_t base;
103 uint32_t limit;
104 unsigned short selector;
105 unsigned char type;
106 unsigned char present, dpl, db, s, l, g, avl;
107 unsigned char unusable;
108 unsigned char padding;
109 } kvm_segment_t;
111 typedef struct kvm_dtable {
112 uint64_t base;
113 unsigned short limit;
114 unsigned short padding[3];
115 } kvm_dtable_t;
117 /* for KVM_GET_SREGS and KVM_SET_SREGS */
118 typedef struct kvm_sregs {
119 /* out (KVM_GET_SREGS) / in (KVM_SET_SREGS) */
120 struct kvm_segment cs, ds, es, fs, gs, ss;
121 struct kvm_segment tr, ldt;
122 struct kvm_dtable gdt, idt;
123 uint64_t cr0, cr2, cr3, cr4, cr8;
124 uint64_t efer;
125 uint64_t apic_base;
126 unsigned long interrupt_bitmap[(KVM_NR_INTERRUPTS + (64-1)) / 64];
127 } kvm_sregs_t;
129 /* for KVM_GET_FPU and KVM_SET_FPU */
130 typedef struct kvm_fpu {
131 unsigned char fpr[8][16];
132 unsigned short fcw;
133 unsigned short fsw;
134 unsigned char ftwx; /* in fxsave format */
135 unsigned char pad1;
136 unsigned short last_opcode;
137 uint64_t last_ip;
138 uint64_t last_dp;
139 unsigned char xmm[16][16];
140 uint32_t mxcsr;
141 uint32_t pad2;
142 } kvm_fpu_t;
144 typedef struct kvm_msr_entry {
145 uint32_t index;
146 uint32_t reserved;
147 uint64_t data;
148 } kvm_msr_entry_t;
150 /* for KVM_GET_MSRS and KVM_SET_MSRS */
151 typedef struct kvm_msrs {
152 uint32_t nmsrs; /* number of msrs in entries */
153 uint32_t pad;
155 struct kvm_msr_entry entries[100];
156 } kvm_msrs_t;
158 /* for KVM_GET_MSR_INDEX_LIST */
159 typedef struct kvm_msr_list {
160 uint32_t nmsrs; /* number of msrs in entries */
161 uint32_t indices[1];
162 } kvm_msr_list_t;
164 typedef struct kvm_cpuid_entry {
165 uint32_t function;
166 uint32_t eax;
167 uint32_t ebx;
168 uint32_t ecx;
169 uint32_t edx;
170 uint32_t padding;
171 } kvm_cpuid_entry_t;
173 /* for KVM_SET_CPUID */
174 typedef struct kvm_cpuid {
175 uint32_t nent;
176 uint32_t padding;
177 struct kvm_cpuid_entry entries[100];
178 } kvm_cpuid_t;
180 typedef struct kvm_cpuid_entry2 {
181 uint32_t function;
182 uint32_t index;
183 uint32_t flags;
184 uint32_t eax;
185 uint32_t ebx;
186 uint32_t ecx;
187 uint32_t edx;
188 uint32_t padding[3];
189 } kvm_cpuid_entry2_t;
192 #define KVM_CPUID_FLAG_SIGNIFCANT_INDEX 1
193 #define KVM_CPUID_FLAG_STATEFUL_FUNC 2
194 #define KVM_CPUID_FLAG_STATE_READ_NEXT 4
196 /* for KVM_SET_CPUID2 */
197 typedef struct kvm_cpuid2 {
198 uint32_t nent;
199 uint32_t padding;
200 struct kvm_cpuid_entry2 entries[0];
201 } kvm_cpuid2_t;
203 /* for KVM_GET_PIT and KVM_SET_PIT */
204 typedef struct kvm_pit_channel_state {
205 uint32_t count; /* can be 65536 */
206 uint16_t latched_count;
207 uint8_t count_latched;
208 uint8_t status_latched;
209 uint8_t status;
210 uint8_t read_state;
211 uint8_t write_state;
212 uint8_t write_latch;
213 uint8_t rw_mode;
214 uint8_t mode;
215 uint8_t bcd;
216 uint8_t gate;
217 int64_t count_load_time;
218 } kvm_pit_channel_state_t;
220 typedef struct kvm_debug_exit_arch {
221 uint32_t exception;
222 uint32_t pad;
223 uint64_t pc;
224 uint64_t dr6;
225 uint64_t dr7;
226 } kvm_debug_exit_arch_t;
228 #define KVM_GUESTDBG_USE_SW_BP 0x00010000
229 #define KVM_GUESTDBG_USE_HW_BP 0x00020000
230 #define KVM_GUESTDBG_INJECT_DB 0x00040000
231 #define KVM_GUESTDBG_INJECT_BP 0x00080000
233 /* for KVM_SET_GUEST_DEBUG */
234 typedef struct kvm_guest_debug_arch {
235 uint64_t debugreg[8];
236 } kvm_guest_debug_arch_t;
239 typedef struct kvm_pit_state {
240 struct kvm_pit_channel_state channels[3];
241 } kvm_pit_state_t;
243 #define KVM_PIT_FLAGS_HPET_LEGACY 0x00000001
245 typedef struct kvm_pit_state2 {
246 struct kvm_pit_channel_state channels[3];
247 uint32_t flags;
248 uint32_t reserved[9];
249 } kvm_pit_state2_t;
251 typedef struct kvm_reinject_control {
252 uint8_t pit_reinject;
253 uint8_t reserved[31];
254 } kvm_reinject_control_t;
256 /* When set in flags, include corresponding fields on KVM_SET_VCPU_EVENTS */
257 #define KVM_VCPUEVENT_VALID_NMI_PENDING 0x00000001
258 #define KVM_VCPUEVENT_VALID_SIPI_VECTOR 0x00000002
260 /* for KVM_GET/SET_VCPU_EVENTS */
261 typedef struct kvm_vcpu_events {
262 struct {
263 unsigned char injected;
264 unsigned char nr;
265 unsigned char has_error_code;
266 unsigned char pad;
267 uint32_t error_code;
268 } exception;
269 struct {
270 unsigned char injected;
271 unsigned char nr;
272 unsigned char soft;
273 unsigned char pad;
274 } interrupt;
275 struct {
276 unsigned char injected;
277 unsigned char pending;
278 unsigned char masked;
279 unsigned char pad;
280 } nmi;
281 uint32_t sipi_vector;
282 uint32_t flags;
283 uint32_t reserved[10];
284 } kvm_vcpu_events_t;
287 * The following needs to run on each cpu. Currently,
288 * wait is always 1, so we use the kvm_xcall() routine which
289 * calls xc_sync. Later, if needed, the implementation can be
290 * changed to use xc_call or xc_call_nowait.
292 #define on_each_cpu(func, info, wait) \
293 /*CSTYLED*/ \
294 ({ \
295 kvm_xcall(KVM_CPUALL, func, info); \
296 0; \
300 * The following should provide an optimization barrier.
301 * If the system does reorder loads and stores, this needs to be changed.
303 #ifdef _KERNEL
304 #define smp_wmb() __asm__ __volatile__("" ::: "memory")
305 #define smp_rmb() __asm__ __volatile__("" ::: "memory")
306 #endif
308 #endif /* __KVM_X86_H */