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.
19 * Copyright 2011 various Linux Kernel contributors.
20 * Copyright 2011 Joyent, Inc. All Rights Reserved.
26 /* See <sys/kvm.h> for an explanation of why this is necessary */
28 #error "The KVM Header files require GNU C extensions for compatibility."
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 */
43 uint8_t read_reg_select
;
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 */
55 #define KVM_IOAPIC_NUM_PINS 24
56 typedef struct kvm_ioapic_state
{
57 uint64_t base_address
;
66 uint8_t delivery_mode
:3;
68 uint8_t delivery_status
:1;
77 } redirtbl
[KVM_IOAPIC_NUM_PINS
];
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
;
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
];
101 typedef struct kvm_segment
{
104 unsigned short selector
;
106 unsigned char present
, dpl
, db
, s
, l
, g
, avl
;
107 unsigned char unusable
;
108 unsigned char padding
;
111 typedef struct kvm_dtable
{
113 unsigned short limit
;
114 unsigned short padding
[3];
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
;
126 unsigned long interrupt_bitmap
[(KVM_NR_INTERRUPTS
+ (64-1)) / 64];
129 /* for KVM_GET_FPU and KVM_SET_FPU */
130 typedef struct kvm_fpu
{
131 unsigned char fpr
[8][16];
134 unsigned char ftwx
; /* in fxsave format */
136 unsigned short last_opcode
;
139 unsigned char xmm
[16][16];
144 typedef struct kvm_msr_entry
{
150 /* for KVM_GET_MSRS and KVM_SET_MSRS */
151 typedef struct kvm_msrs
{
152 uint32_t nmsrs
; /* number of msrs in entries */
155 struct kvm_msr_entry entries
[100];
158 /* for KVM_GET_MSR_INDEX_LIST */
159 typedef struct kvm_msr_list
{
160 uint32_t nmsrs
; /* number of msrs in entries */
164 typedef struct kvm_cpuid_entry
{
173 /* for KVM_SET_CPUID */
174 typedef struct kvm_cpuid
{
177 struct kvm_cpuid_entry entries
[100];
180 typedef struct kvm_cpuid_entry2
{
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
{
200 struct kvm_cpuid_entry2 entries
[0];
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
;
217 int64_t count_load_time
;
218 } kvm_pit_channel_state_t
;
220 typedef struct kvm_debug_exit_arch
{
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];
243 #define KVM_PIT_FLAGS_HPET_LEGACY 0x00000001
245 typedef struct kvm_pit_state2
{
246 struct kvm_pit_channel_state channels
[3];
248 uint32_t reserved
[9];
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
{
263 unsigned char injected
;
265 unsigned char has_error_code
;
270 unsigned char injected
;
276 unsigned char injected
;
277 unsigned char pending
;
278 unsigned char masked
;
281 uint32_t sipi_vector
;
283 uint32_t reserved
[10];
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) \
295 kvm_xcall(KVM_CPUALL, func, info); \
300 * The following should provide an optimization barrier.
301 * If the system does reorder loads and stores, this needs to be changed.
304 #define smp_wmb() __asm__ __volatile__("" ::: "memory")
305 #define smp_rmb() __asm__ __volatile__("" ::: "memory")
308 #endif /* __KVM_X86_H */