6 #define CONFIG_X86_32 1
12 #define CONFIG_X86_64 1
16 #if defined(__i386__) || defined (__x86_64__)
42 * kvm_host.h: used for kvm module, and hold ia64-specific sections.
44 * Copyright (C) 2007, Intel Corporation.
46 * Xiantao Zhang <xiantao.zhang@intel.com>
48 * This program is free software; you can redistribute it and/or modify it
49 * under the terms and conditions of the GNU General Public License,
50 * version 2, as published by the Free Software Foundation.
52 * This program is distributed in the hope it will be useful, but WITHOUT
53 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
54 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
57 * You should have received a copy of the GNU General Public License along with
58 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
59 * Place - Suite 330, Boston, MA 02111-1307 USA.
63 #ifndef __ASM_KVM_HOST_H
64 #define __ASM_KVM_HOST_H
66 #define KVM_MEMORY_SLOTS 32
67 /* memory slots that does not exposed to userspace */
68 #define KVM_PRIVATE_MEM_SLOTS 4
70 #define KVM_COALESCED_MMIO_PAGE_OFFSET 1
72 /* define exit reasons from vmm to kvm*/
73 #define EXIT_REASON_VM_PANIC 0
74 #define EXIT_REASON_MMIO_INSTRUCTION 1
75 #define EXIT_REASON_PAL_CALL 2
76 #define EXIT_REASON_SAL_CALL 3
77 #define EXIT_REASON_SWITCH_RR6 4
78 #define EXIT_REASON_VM_DESTROY 5
79 #define EXIT_REASON_EXTERNAL_INTERRUPT 6
80 #define EXIT_REASON_IPI 7
81 #define EXIT_REASON_PTC_G 8
82 #define EXIT_REASON_DEBUG 20
84 /*Define vmm address space and vm data space.*/
85 #define KVM_VMM_SIZE (__IA64_UL_CONST(16)<<20)
86 #define KVM_VMM_SHIFT 24
87 #define KVM_VMM_BASE 0xD000000000000000
88 #define VMM_SIZE (__IA64_UL_CONST(8)<<20)
91 * Define vm_buffer, used by PAL Services, base address.
92 * Note: vm_buffer is in the VMM-BLOCK, the size must be < 8M
94 #define KVM_VM_BUFFER_BASE (KVM_VMM_BASE + VMM_SIZE)
95 #define KVM_VM_BUFFER_SIZE (__IA64_UL_CONST(8)<<20)
98 * kvm guest's data area looks as follow:
100 * +----------------------+ ------- KVM_VM_DATA_SIZE
101 * | vcpu[n]'s data | | ___________________KVM_STK_OFFSET
103 * | .......... | | /vcpu's struct&stack |
104 * | .......... | | /---------------------|---- 0
105 * | vcpu[5]'s data | | / vpd |
106 * | vcpu[4]'s data | |/-----------------------|
107 * | vcpu[3]'s data | / vtlb |
108 * | vcpu[2]'s data | /|------------------------|
109 * | vcpu[1]'s data |/ | vhpt |
110 * | vcpu[0]'s data |____________________________|
111 * +----------------------+ |
112 * | memory dirty log | |
113 * +----------------------+ |
114 * | vm's data struct | |
115 * +----------------------+ |
123 * | vm's p2m table | |
128 * +----------------------+ ------- 0
129 * To support large memory, needs to increase the size of p2m.
130 * To support more vcpus, needs to ensure it has enough space to
134 #define KVM_VM_DATA_SHIFT 26
135 #define KVM_VM_DATA_SIZE (__IA64_UL_CONST(1) << KVM_VM_DATA_SHIFT)
136 #define KVM_VM_DATA_BASE (KVM_VMM_BASE + KVM_VM_DATA_SIZE)
138 #define KVM_P2M_BASE KVM_VM_DATA_BASE
139 #define KVM_P2M_SIZE (__IA64_UL_CONST(24) << 20)
141 #define VHPT_SHIFT 16
142 #define VHPT_SIZE (__IA64_UL_CONST(1) << VHPT_SHIFT)
143 #define VHPT_NUM_ENTRIES (__IA64_UL_CONST(1) << (VHPT_SHIFT-5))
145 #define VTLB_SHIFT 16
146 #define VTLB_SIZE (__IA64_UL_CONST(1) << VTLB_SHIFT)
147 #define VTLB_NUM_ENTRIES (1UL << (VHPT_SHIFT-5))
150 #define VPD_SIZE (__IA64_UL_CONST(1) << VPD_SHIFT)
152 #define VCPU_STRUCT_SHIFT 16
153 #define VCPU_STRUCT_SIZE (__IA64_UL_CONST(1) << VCPU_STRUCT_SHIFT)
156 * This must match KVM_IA64_VCPU_STACK_{SHIFT,SIZE} arch/ia64/include/asm/kvm.h
158 #define KVM_STK_SHIFT 16
159 #define KVM_STK_OFFSET (__IA64_UL_CONST(1)<< KVM_STK_SHIFT)
161 #define KVM_VM_STRUCT_SHIFT 19
162 #define KVM_VM_STRUCT_SIZE (__IA64_UL_CONST(1) << KVM_VM_STRUCT_SHIFT)
164 #define KVM_MEM_DIRY_LOG_SHIFT 19
165 #define KVM_MEM_DIRTY_LOG_SIZE (__IA64_UL_CONST(1) << KVM_MEM_DIRY_LOG_SHIFT)
169 /*Define the max vcpus and memory for Guests.*/
170 #define KVM_MAX_VCPUS (KVM_VM_DATA_SIZE - KVM_P2M_SIZE - KVM_VM_STRUCT_SIZE -\
171 KVM_MEM_DIRTY_LOG_SIZE) / sizeof(struct kvm_vcpu_data)
172 #define KVM_MAX_MEM_SIZE (KVM_P2M_SIZE >> 3 << PAGE_SHIFT)
174 #define VMM_LOG_LEN 256
176 #include <linux/types.h>
177 #include <linux/mm.h>
178 #include <linux/kvm.h>
179 #include <linux/kvm_para.h>
180 #include <linux/kvm_types.h>
184 #include <asm/page.h>
186 struct kvm_vcpu_data
{
187 char vcpu_vhpt
[VHPT_SIZE
];
188 char vcpu_vtlb
[VTLB_SIZE
];
189 char vcpu_vpd
[VPD_SIZE
];
190 char vcpu_struct
[VCPU_STRUCT_SIZE
];
194 char kvm_p2m
[KVM_P2M_SIZE
];
195 char kvm_vm_struct
[KVM_VM_STRUCT_SIZE
];
196 char kvm_mem_dirty_log
[KVM_MEM_DIRTY_LOG_SIZE
];
197 struct kvm_vcpu_data vcpu_data
[KVM_MAX_VCPUS
];
200 #define VCPU_BASE(n) (KVM_VM_DATA_BASE + \
201 offsetof(struct kvm_vm_data, vcpu_data[n]))
202 #define KVM_VM_BASE (KVM_VM_DATA_BASE + \
203 offsetof(struct kvm_vm_data, kvm_vm_struct))
204 #define KVM_MEM_DIRTY_LOG_BASE KVM_VM_DATA_BASE + \
205 offsetof(struct kvm_vm_data, kvm_mem_dirty_log)
207 #define VHPT_BASE(n) (VCPU_BASE(n) + offsetof(struct kvm_vcpu_data, vcpu_vhpt))
208 #define VTLB_BASE(n) (VCPU_BASE(n) + offsetof(struct kvm_vcpu_data, vcpu_vtlb))
209 #define VPD_BASE(n) (VCPU_BASE(n) + offsetof(struct kvm_vcpu_data, vcpu_vpd))
210 #define VCPU_STRUCT_BASE(n) (VCPU_BASE(n) + \
211 offsetof(struct kvm_vcpu_data, vcpu_struct))
213 /*IO section definitions*/
215 #define IOREQ_WRITE 0
217 #define STATE_IOREQ_NONE 0
218 #define STATE_IOREQ_READY 1
219 #define STATE_IOREQ_INPROCESS 2
220 #define STATE_IORESP_READY 3
222 /*Guest Physical address layout.*/
223 #define GPFN_MEM (0UL << 60) /* Guest pfn is normal mem */
224 #define GPFN_FRAME_BUFFER (1UL << 60) /* VGA framebuffer */
225 #define GPFN_LOW_MMIO (2UL << 60) /* Low MMIO range */
226 #define GPFN_PIB (3UL << 60) /* PIB base */
227 #define GPFN_IOSAPIC (4UL << 60) /* IOSAPIC base */
228 #define GPFN_LEGACY_IO (5UL << 60) /* Legacy I/O base */
229 #define GPFN_GFW (6UL << 60) /* Guest Firmware */
230 #define GPFN_PHYS_MMIO (7UL << 60) /* Directed MMIO Range */
232 #define GPFN_IO_MASK (7UL << 60) /* Guest pfn is I/O type */
233 #define GPFN_INV_MASK (1UL << 63) /* Guest pfn is invalid */
234 #define INVALID_MFN (~0UL)
235 #define MEM_G (1UL << 30)
236 #define MEM_M (1UL << 20)
237 #define MMIO_START (3 * MEM_G)
238 #define MMIO_SIZE (512 * MEM_M)
239 #define VGA_IO_START 0xA0000UL
240 #define VGA_IO_SIZE 0x20000
241 #define LEGACY_IO_START (MMIO_START + MMIO_SIZE)
242 #define LEGACY_IO_SIZE (64 * MEM_M)
243 #define IO_SAPIC_START 0xfec00000UL
244 #define IO_SAPIC_SIZE 0x100000
245 #define PIB_START 0xfee00000UL
246 #define PIB_SIZE 0x200000
247 #define GFW_START (4 * MEM_G - 16 * MEM_M)
248 #define GFW_SIZE (16 * MEM_M)
250 /*Deliver mode, defined for ioapic.c*/
251 #define dest_Fixed IOSAPIC_FIXED
252 #define dest_LowestPrio IOSAPIC_LOWEST_PRIORITY
255 #define ExtINT_VECTOR 0
256 #define NULL_VECTOR (-1)
257 #define IA64_SPURIOUS_INT_VECTOR 0x0f
259 #define VCPU_LID(v) (((u64)(v)->vcpu_id) << 24)
264 #define SAPIC_DELIV_SHIFT 8
265 #define SAPIC_FIXED 0x0
266 #define SAPIC_LOWEST_PRIORITY 0x1
267 #define SAPIC_PMI 0x2
268 #define SAPIC_NMI 0x4
269 #define SAPIC_INIT 0x5
270 #define SAPIC_EXTINT 0x7
273 * vcpu->requests bit members for arch
275 #define KVM_REQ_PTC_G 32
276 #define KVM_REQ_RESUME 33
278 #define KVM_PAGES_PER_HPAGE 1
283 struct kvm_mmio_req
{
284 uint64_t addr
; /* physical address */
285 uint64_t size
; /* size in bytes */
286 uint64_t data
; /* data (or paddr of data) */
288 uint8_t dir
:1; /* 1=read, 0=write */
299 struct ia64_pal_retval ret
;
302 /* Sal data structure */
313 struct sal_ret_values ret
;
317 struct kvm_switch_rr6
{
325 unsigned long rv
: 3;
326 unsigned long ir
: 1;
327 unsigned long eid
: 8;
328 unsigned long id
: 8;
329 unsigned long ib_base
: 44;
336 unsigned long vector
: 8;
337 unsigned long dm
: 3;
338 unsigned long ig
: 53;
342 /*ipi check exit data*/
344 union ia64_ipi_a addr
;
345 union ia64_ipi_d data
;
348 /*global purge data*/
353 struct kvm_vcpu
*vcpu
;
356 /*Exit control data */
357 struct exit_ctl_data
{
358 uint32_t exit_reason
;
361 struct kvm_mmio_req ioreq
;
362 struct kvm_pal_call pal_data
;
363 struct kvm_sal_call sal_data
;
364 struct kvm_switch_rr6 rr_data
;
365 struct kvm_ipi_data ipi_data
;
366 struct kvm_ptc_g ptc_g_data
;
373 unsigned long p
: 1; /*0 */
374 unsigned long : 1; /* 1 */
375 unsigned long ma
: 3; /* 2-4 */
376 unsigned long a
: 1; /* 5 */
377 unsigned long d
: 1; /* 6 */
378 unsigned long pl
: 2; /* 7-8 */
379 unsigned long ar
: 3; /* 9-11 */
380 unsigned long ppn
: 38; /* 12-49 */
381 unsigned long : 2; /* 50-51 */
382 unsigned long ed
: 1; /* 52 */
389 unsigned long ve
: 1;
390 unsigned long reserved0
: 1;
391 unsigned long size
: 6;
392 unsigned long vf
: 1;
393 unsigned long reserved1
: 6;
394 unsigned long base
: 49;
399 /* THASH base information */
400 struct thash_data
*hash
; /* hash table pointer */
405 struct kvm_vcpu_stat
{
408 struct kvm_vcpu_arch
{
416 #define KVM_MP_STATE_RUNNABLE 0
417 #define KVM_MP_STATE_UNINITIALIZED 1
418 #define KVM_MP_STATE_INIT_RECEIVED 2
419 #define KVM_MP_STATE_HALTED 3
422 #define MAX_PTC_G_NUM 3
424 struct kvm_ptc_g ptc_g_data
[MAX_PTC_G_NUM
];
426 /*halt timer to wake up sleepy vcpus*/
427 struct hrtimer hlt_timer
;
430 struct kvm_lapic
*apic
; /* kernel irqchip context */
433 /* Exit data for vmm_transition*/
434 struct exit_ctl_data exit_data
;
436 cpumask_t cache_coherent_map
;
438 unsigned long vmm_rr
;
439 unsigned long host_rr6
;
440 unsigned long psbits
[8];
441 unsigned long cr_iipa
;
442 unsigned long cr_isr
;
443 unsigned long vsa_base
;
444 unsigned long dirty_log_lock_pa
;
447 struct thash_data itrs
[NITRS
];
448 struct thash_data dtrs
[NDTRS
];
449 /* Bit is set if there is a tr/tc for the region. */
450 unsigned char itr_regions
;
451 unsigned char dtr_regions
;
452 unsigned char tc_regions
;
454 unsigned long ptce_base
;
455 unsigned long ptce_count
[2];
456 unsigned long ptce_stride
[2];
458 unsigned long last_itc
;
460 unsigned long itc_check
;
461 unsigned long timer_check
;
462 unsigned int timer_pending
;
463 unsigned int timer_fired
;
465 unsigned long vrr
[8];
466 unsigned long ibr
[8];
467 unsigned long dbr
[8];
468 unsigned long insvc
[4]; /* Interrupt in service. */
471 unsigned long metaphysical_rr0
; /* from kvm_arch (so is pinned) */
472 unsigned long metaphysical_rr4
; /* from kvm_arch (so is pinned) */
473 unsigned long metaphysical_saved_rr0
; /* from kvm_arch */
474 unsigned long metaphysical_saved_rr4
; /* from kvm_arch */
475 unsigned long fp_psr
; /*used for lazy float register */
476 unsigned long saved_gp
;
477 /*for phycial emulation */
479 struct thash_cb vtlb
;
480 struct thash_cb vhpt
;
482 char irq_new_pending
;
484 unsigned long opcode
;
486 char log_buf
[VMM_LOG_LEN
];
492 u64 remote_tlb_flush
;
495 struct kvm_sal_data
{
496 unsigned long boot_ip
;
497 unsigned long boot_gp
;
501 spinlock_t dirty_log_lock
;
503 unsigned long vm_base
;
504 unsigned long metaphysical_rr0
;
505 unsigned long metaphysical_rr4
;
506 unsigned long vmm_init_rr
;
511 struct kvm_ioapic
*vioapic
;
512 struct kvm_vm_stat stat
;
513 struct kvm_sal_data rdv_sal_data
;
515 struct list_head assigned_dev_head
;
516 struct iommu_domain
*iommu_domain
;
517 struct hlist_head irq_ack_notifier_list
;
519 unsigned long irq_sources_bitmap
;
520 unsigned long irq_states
[KVM_IOAPIC_NUM_PINS
];
536 /* The following registers are saved by SAVE_MIN: */
537 unsigned long b6
; /* scratch */
538 unsigned long b7
; /* scratch */
540 unsigned long ar_csd
; /* used by cmp8xchg16 (scratch) */
541 unsigned long ar_ssd
; /* reserved for future use (scratch) */
543 unsigned long r8
; /* scratch (return value register 0) */
544 unsigned long r9
; /* scratch (return value register 1) */
545 unsigned long r10
; /* scratch (return value register 2) */
546 unsigned long r11
; /* scratch (return value register 3) */
548 unsigned long cr_ipsr
; /* interrupted task's psr */
549 unsigned long cr_iip
; /* interrupted task's instruction pointer */
550 unsigned long cr_ifs
; /* interrupted task's function state */
552 unsigned long ar_unat
; /* interrupted task's NaT register (preserved) */
553 unsigned long ar_pfs
; /* prev function state */
554 unsigned long ar_rsc
; /* RSE configuration */
555 /* The following two are valid only if cr_ipsr.cpl > 0: */
556 unsigned long ar_rnat
; /* RSE NaT */
557 unsigned long ar_bspstore
; /* RSE bspstore */
559 unsigned long pr
; /* 64 predicate registers (1 bit each) */
560 unsigned long b0
; /* return pointer (bp) */
561 unsigned long loadrs
; /* size of dirty partition << 16 */
563 unsigned long r1
; /* the gp pointer */
564 unsigned long r12
; /* interrupted task's memory stack pointer */
565 unsigned long r13
; /* thread pointer */
567 unsigned long ar_fpsr
; /* floating point status (preserved) */
568 unsigned long r15
; /* scratch */
570 /* The remaining registers are NOT saved for system calls. */
571 unsigned long r14
; /* scratch */
572 unsigned long r2
; /* scratch */
573 unsigned long r3
; /* scratch */
574 unsigned long r16
; /* scratch */
575 unsigned long r17
; /* scratch */
576 unsigned long r18
; /* scratch */
577 unsigned long r19
; /* scratch */
578 unsigned long r20
; /* scratch */
579 unsigned long r21
; /* scratch */
580 unsigned long r22
; /* scratch */
581 unsigned long r23
; /* scratch */
582 unsigned long r24
; /* scratch */
583 unsigned long r25
; /* scratch */
584 unsigned long r26
; /* scratch */
585 unsigned long r27
; /* scratch */
586 unsigned long r28
; /* scratch */
587 unsigned long r29
; /* scratch */
588 unsigned long r30
; /* scratch */
589 unsigned long r31
; /* scratch */
590 unsigned long ar_ccv
; /* compare/exchange value (scratch) */
593 * Floating point registers that the kernel considers scratch:
595 struct ia64_fpreg f6
; /* scratch */
596 struct ia64_fpreg f7
; /* scratch */
597 struct ia64_fpreg f8
; /* scratch */
598 struct ia64_fpreg f9
; /* scratch */
599 struct ia64_fpreg f10
; /* scratch */
600 struct ia64_fpreg f11
; /* scratch */
602 unsigned long r4
; /* preserved */
603 unsigned long r5
; /* preserved */
604 unsigned long r6
; /* preserved */
605 unsigned long r7
; /* preserved */
606 unsigned long eml_unat
; /* used for emulating instruction */
607 unsigned long pad0
; /* alignment pad */
610 static inline struct kvm_pt_regs
*vcpu_regs(struct kvm_vcpu
*v
)
612 return (struct kvm_pt_regs
*) ((unsigned long) v
+ KVM_STK_OFFSET
) - 1;
615 typedef int kvm_vmm_entry(void);
616 typedef void kvm_tramp_entry(union context
*host
, union context
*guest
);
619 struct module
*module
;
620 kvm_vmm_entry
*vmm_entry
;
621 kvm_tramp_entry
*tramp_entry
;
622 unsigned long vmm_ivt
;
623 unsigned long patch_mov_ar
;
624 unsigned long patch_mov_ar_sn2
;
627 int kvm_highest_pending_irq(struct kvm_vcpu
*vcpu
);
628 int kvm_emulate_halt(struct kvm_vcpu
*vcpu
);
629 int kvm_pal_emul(struct kvm_vcpu
*vcpu
, struct kvm_run
*kvm_run
);
630 void kvm_sal_emul(struct kvm_vcpu
*vcpu
);
632 #endif /* __ASSEMBLY__*/