2 * kvm_host.h: used for kvm module, and hold ia64-specific sections.
4 * Copyright (C) 2007, Intel Corporation.
6 * Xiantao Zhang <xiantao.zhang@intel.com>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms and conditions of the GNU General Public License,
10 * version 2, as published by the Free Software Foundation.
12 * This program is distributed in the hope it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19 * Place - Suite 330, Boston, MA 02111-1307 USA.
23 #ifndef __ASM_KVM_HOST_H
24 #define __ASM_KVM_HOST_H
27 #include <linux/types.h>
29 #include <linux/kvm.h>
30 #include <linux/kvm_para.h>
31 #include <linux/kvm_types.h>
36 #define KVM_MAX_VCPUS 4
37 #define KVM_MEMORY_SLOTS 32
38 /* memory slots that does not exposed to userspace */
39 #define KVM_PRIVATE_MEM_SLOTS 4
41 #define KVM_COALESCED_MMIO_PAGE_OFFSET 1
43 /* define exit reasons from vmm to kvm*/
44 #define EXIT_REASON_VM_PANIC 0
45 #define EXIT_REASON_MMIO_INSTRUCTION 1
46 #define EXIT_REASON_PAL_CALL 2
47 #define EXIT_REASON_SAL_CALL 3
48 #define EXIT_REASON_SWITCH_RR6 4
49 #define EXIT_REASON_VM_DESTROY 5
50 #define EXIT_REASON_EXTERNAL_INTERRUPT 6
51 #define EXIT_REASON_IPI 7
52 #define EXIT_REASON_PTC_G 8
54 /*Define vmm address space and vm data space.*/
55 #define KVM_VMM_SIZE (16UL<<20)
56 #define KVM_VMM_SHIFT 24
57 #define KVM_VMM_BASE 0xD000000000000000UL
58 #define VMM_SIZE (8UL<<20)
61 * Define vm_buffer, used by PAL Services, base address.
62 * Note: vmbuffer is in the VMM-BLOCK, the size must be < 8M
64 #define KVM_VM_BUFFER_BASE (KVM_VMM_BASE + VMM_SIZE)
65 #define KVM_VM_BUFFER_SIZE (8UL<<20)
67 /*Define Virtual machine data layout.*/
68 #define KVM_VM_DATA_SHIFT 24
69 #define KVM_VM_DATA_SIZE (1UL << KVM_VM_DATA_SHIFT)
70 #define KVM_VM_DATA_BASE (KVM_VMM_BASE + KVM_VMM_SIZE)
73 #define KVM_P2M_BASE KVM_VM_DATA_BASE
75 #define KVM_P2M_SIZE (8UL << 20)
77 #define KVM_VHPT_BASE (KVM_P2M_BASE + KVM_P2M_SIZE)
78 #define KVM_VHPT_OFS KVM_P2M_SIZE
79 #define KVM_VHPT_BLOCK_SIZE (2UL << 20)
81 #define VHPT_SIZE (1UL << VHPT_SHIFT)
82 #define VHPT_NUM_ENTRIES (1<<(VHPT_SHIFT-5))
84 #define KVM_VTLB_BASE (KVM_VHPT_BASE+KVM_VHPT_BLOCK_SIZE)
85 #define KVM_VTLB_OFS (KVM_VHPT_OFS+KVM_VHPT_BLOCK_SIZE)
86 #define KVM_VTLB_BLOCK_SIZE (1UL<<20)
88 #define VTLB_SIZE (1UL<<VTLB_SHIFT)
89 #define VTLB_NUM_ENTRIES (1<<(VTLB_SHIFT-5))
91 #define KVM_VPD_BASE (KVM_VTLB_BASE+KVM_VTLB_BLOCK_SIZE)
92 #define KVM_VPD_OFS (KVM_VTLB_OFS+KVM_VTLB_BLOCK_SIZE)
93 #define KVM_VPD_BLOCK_SIZE (2UL<<20)
95 #define VPD_SIZE (1UL<<VPD_SHIFT)
97 #define KVM_VCPU_BASE (KVM_VPD_BASE+KVM_VPD_BLOCK_SIZE)
98 #define KVM_VCPU_OFS (KVM_VPD_OFS+KVM_VPD_BLOCK_SIZE)
99 #define KVM_VCPU_BLOCK_SIZE (2UL<<20)
100 #define VCPU_SHIFT 18
101 #define VCPU_SIZE (1UL<<VCPU_SHIFT)
102 #define MAX_VCPU_NUM KVM_VCPU_BLOCK_SIZE/VCPU_SIZE
104 #define KVM_VM_BASE (KVM_VCPU_BASE+KVM_VCPU_BLOCK_SIZE)
105 #define KVM_VM_OFS (KVM_VCPU_OFS+KVM_VCPU_BLOCK_SIZE)
106 #define KVM_VM_BLOCK_SIZE (1UL<<19)
108 #define KVM_MEM_DIRTY_LOG_BASE (KVM_VM_BASE+KVM_VM_BLOCK_SIZE)
109 #define KVM_MEM_DIRTY_LOG_OFS (KVM_VM_OFS+KVM_VM_BLOCK_SIZE)
110 #define KVM_MEM_DIRTY_LOG_SIZE (1UL<<19)
112 /* Get vpd, vhpt, tlb, vcpu, base*/
113 #define VPD_ADDR(n) (KVM_VPD_BASE+n*VPD_SIZE)
114 #define VHPT_ADDR(n) (KVM_VHPT_BASE+n*VHPT_SIZE)
115 #define VTLB_ADDR(n) (KVM_VTLB_BASE+n*VTLB_SIZE)
116 #define VCPU_ADDR(n) (KVM_VCPU_BASE+n*VCPU_SIZE)
118 /*IO section definitions*/
120 #define IOREQ_WRITE 0
122 #define STATE_IOREQ_NONE 0
123 #define STATE_IOREQ_READY 1
124 #define STATE_IOREQ_INPROCESS 2
125 #define STATE_IORESP_READY 3
127 /*Guest Physical address layout.*/
128 #define GPFN_MEM (0UL << 60) /* Guest pfn is normal mem */
129 #define GPFN_FRAME_BUFFER (1UL << 60) /* VGA framebuffer */
130 #define GPFN_LOW_MMIO (2UL << 60) /* Low MMIO range */
131 #define GPFN_PIB (3UL << 60) /* PIB base */
132 #define GPFN_IOSAPIC (4UL << 60) /* IOSAPIC base */
133 #define GPFN_LEGACY_IO (5UL << 60) /* Legacy I/O base */
134 #define GPFN_GFW (6UL << 60) /* Guest Firmware */
135 #define GPFN_HIGH_MMIO (7UL << 60) /* High MMIO range */
137 #define GPFN_IO_MASK (7UL << 60) /* Guest pfn is I/O type */
138 #define GPFN_INV_MASK (1UL << 63) /* Guest pfn is invalid */
139 #define INVALID_MFN (~0UL)
140 #define MEM_G (1UL << 30)
141 #define MEM_M (1UL << 20)
142 #define MMIO_START (3 * MEM_G)
143 #define MMIO_SIZE (512 * MEM_M)
144 #define VGA_IO_START 0xA0000UL
145 #define VGA_IO_SIZE 0x20000
146 #define LEGACY_IO_START (MMIO_START + MMIO_SIZE)
147 #define LEGACY_IO_SIZE (64 * MEM_M)
148 #define IO_SAPIC_START 0xfec00000UL
149 #define IO_SAPIC_SIZE 0x100000
150 #define PIB_START 0xfee00000UL
151 #define PIB_SIZE 0x200000
152 #define GFW_START (4 * MEM_G - 16 * MEM_M)
153 #define GFW_SIZE (16 * MEM_M)
155 /*Deliver mode, defined for ioapic.c*/
156 #define dest_Fixed IOSAPIC_FIXED
157 #define dest_LowestPrio IOSAPIC_LOWEST_PRIORITY
160 #define ExtINT_VECTOR 0
161 #define NULL_VECTOR (-1)
162 #define IA64_SPURIOUS_INT_VECTOR 0x0f
164 #define VCPU_LID(v) (((u64)(v)->vcpu_id) << 24)
169 #define SAPIC_DELIV_SHIFT 8
170 #define SAPIC_FIXED 0x0
171 #define SAPIC_LOWEST_PRIORITY 0x1
172 #define SAPIC_PMI 0x2
173 #define SAPIC_NMI 0x4
174 #define SAPIC_INIT 0x5
175 #define SAPIC_EXTINT 0x7
178 * vcpu->requests bit members for arch
180 #define KVM_REQ_PTC_G 32
181 #define KVM_REQ_RESUME 33
183 #define KVM_PAGES_PER_HPAGE 1
187 struct kvm_guest_debug{
190 struct kvm_mmio_req {
191 uint64_t addr; /* physical address */
192 uint64_t size; /* size in bytes */
193 uint64_t data; /* data (or paddr of data) */
195 uint8_t dir:1; /* 1=read, 0=write */
206 struct ia64_pal_retval ret;
209 /* Sal data structure */
220 struct sal_ret_values ret;
224 struct kvm_switch_rr6 {
232 unsigned long rv : 3;
233 unsigned long ir : 1;
234 unsigned long eid : 8;
235 unsigned long id : 8;
236 unsigned long ib_base : 44;
243 unsigned long vector : 8;
244 unsigned long dm : 3;
245 unsigned long ig : 53;
249 /*ipi check exit data*/
251 union ia64_ipi_a addr;
252 union ia64_ipi_d data;
255 /*global purge data*/
260 struct kvm_vcpu *vcpu;
263 /*Exit control data */
264 struct exit_ctl_data{
265 uint32_t exit_reason;
268 struct kvm_mmio_req ioreq;
269 struct kvm_pal_call pal_data;
270 struct kvm_sal_call sal_data;
271 struct kvm_switch_rr6 rr_data;
272 struct kvm_ipi_data ipi_data;
273 struct kvm_ptc_g ptc_g_data;
280 unsigned long p : 1; /*0 */
281 unsigned long : 1; /* 1 */
282 unsigned long ma : 3; /* 2-4 */
283 unsigned long a : 1; /* 5 */
284 unsigned long d : 1; /* 6 */
285 unsigned long pl : 2; /* 7-8 */
286 unsigned long ar : 3; /* 9-11 */
287 unsigned long ppn : 38; /* 12-49 */
288 unsigned long : 2; /* 50-51 */
289 unsigned long ed : 1; /* 52 */
296 unsigned long ve : 1;
297 unsigned long reserved0 : 1;
298 unsigned long size : 6;
299 unsigned long vf : 1;
300 unsigned long reserved1 : 6;
301 unsigned long base : 49;
306 /* THASH base information */
307 struct thash_data *hash; /* hash table pointer */
312 struct kvm_vcpu_stat {
315 struct kvm_vcpu_arch {
322 #define KVM_MP_STATE_RUNNABLE 0
323 #define KVM_MP_STATE_UNINITIALIZED 1
324 #define KVM_MP_STATE_INIT_RECEIVED 2
325 #define KVM_MP_STATE_HALTED 3
328 #define MAX_PTC_G_NUM 3
330 struct kvm_ptc_g ptc_g_data[MAX_PTC_G_NUM];
332 /*halt timer to wake up sleepy vcpus*/
333 struct hrtimer hlt_timer;
336 struct kvm_lapic *apic; /* kernel irqchip context */
339 /* Exit data for vmm_transition*/
340 struct exit_ctl_data exit_data;
342 cpumask_t cache_coherent_map;
344 unsigned long vmm_rr;
345 unsigned long host_rr6;
346 unsigned long psbits[8];
347 unsigned long cr_iipa;
348 unsigned long cr_isr;
349 unsigned long vsa_base;
350 unsigned long dirty_log_lock_pa;
353 struct thash_data itrs[NITRS];
354 struct thash_data dtrs[NDTRS];
355 /* Bit is set if there is a tr/tc for the region. */
356 unsigned char itr_regions;
357 unsigned char dtr_regions;
358 unsigned char tc_regions;
360 unsigned long ptce_base;
361 unsigned long ptce_count[2];
362 unsigned long ptce_stride[2];
364 unsigned long last_itc;
366 unsigned long itc_check;
367 unsigned long timer_check;
368 unsigned long timer_pending;
370 unsigned long vrr[8];
371 unsigned long ibr[8];
372 unsigned long dbr[8];
373 unsigned long insvc[4]; /* Interrupt in service. */
376 unsigned long metaphysical_rr0; /* from kvm_arch (so is pinned) */
377 unsigned long metaphysical_rr4; /* from kvm_arch (so is pinned) */
378 unsigned long metaphysical_saved_rr0; /* from kvm_arch */
379 unsigned long metaphysical_saved_rr4; /* from kvm_arch */
380 unsigned long fp_psr; /*used for lazy float register */
381 unsigned long saved_gp;
382 /*for phycial emulation */
384 struct thash_cb vtlb;
385 struct thash_cb vhpt;
387 char irq_new_pending;
389 unsigned long opcode;
396 u64 remote_tlb_flush;
399 struct kvm_sal_data {
400 unsigned long boot_ip;
401 unsigned long boot_gp;
405 unsigned long vm_base;
406 unsigned long metaphysical_rr0;
407 unsigned long metaphysical_rr4;
408 unsigned long vmm_init_rr;
409 unsigned long vhpt_base;
410 unsigned long vtlb_base;
411 unsigned long vpd_base;
412 spinlock_t dirty_log_lock;
413 struct kvm_ioapic *vioapic;
414 struct kvm_vm_stat stat;
415 struct kvm_sal_data rdv_sal_data;
431 /* The following registers are saved by SAVE_MIN: */
432 unsigned long b6; /* scratch */
433 unsigned long b7; /* scratch */
435 unsigned long ar_csd; /* used by cmp8xchg16 (scratch) */
436 unsigned long ar_ssd; /* reserved for future use (scratch) */
438 unsigned long r8; /* scratch (return value register 0) */
439 unsigned long r9; /* scratch (return value register 1) */
440 unsigned long r10; /* scratch (return value register 2) */
441 unsigned long r11; /* scratch (return value register 3) */
443 unsigned long cr_ipsr; /* interrupted task's psr */
444 unsigned long cr_iip; /* interrupted task's instruction pointer */
445 unsigned long cr_ifs; /* interrupted task's function state */
447 unsigned long ar_unat; /* interrupted task's NaT register (preserved) */
448 unsigned long ar_pfs; /* prev function state */
449 unsigned long ar_rsc; /* RSE configuration */
450 /* The following two are valid only if cr_ipsr.cpl > 0: */
451 unsigned long ar_rnat; /* RSE NaT */
452 unsigned long ar_bspstore; /* RSE bspstore */
454 unsigned long pr; /* 64 predicate registers (1 bit each) */
455 unsigned long b0; /* return pointer (bp) */
456 unsigned long loadrs; /* size of dirty partition << 16 */
458 unsigned long r1; /* the gp pointer */
459 unsigned long r12; /* interrupted task's memory stack pointer */
460 unsigned long r13; /* thread pointer */
462 unsigned long ar_fpsr; /* floating point status (preserved) */
463 unsigned long r15; /* scratch */
465 /* The remaining registers are NOT saved for system calls. */
466 unsigned long r14; /* scratch */
467 unsigned long r2; /* scratch */
468 unsigned long r3; /* scratch */
469 unsigned long r16; /* scratch */
470 unsigned long r17; /* scratch */
471 unsigned long r18; /* scratch */
472 unsigned long r19; /* scratch */
473 unsigned long r20; /* scratch */
474 unsigned long r21; /* scratch */
475 unsigned long r22; /* scratch */
476 unsigned long r23; /* scratch */
477 unsigned long r24; /* scratch */
478 unsigned long r25; /* scratch */
479 unsigned long r26; /* scratch */
480 unsigned long r27; /* scratch */
481 unsigned long r28; /* scratch */
482 unsigned long r29; /* scratch */
483 unsigned long r30; /* scratch */
484 unsigned long r31; /* scratch */
485 unsigned long ar_ccv; /* compare/exchange value (scratch) */
488 * Floating point registers that the kernel considers scratch:
490 struct ia64_fpreg f6; /* scratch */
491 struct ia64_fpreg f7; /* scratch */
492 struct ia64_fpreg f8; /* scratch */
493 struct ia64_fpreg f9; /* scratch */
494 struct ia64_fpreg f10; /* scratch */
495 struct ia64_fpreg f11; /* scratch */
497 unsigned long r4; /* preserved */
498 unsigned long r5; /* preserved */
499 unsigned long r6; /* preserved */
500 unsigned long r7; /* preserved */
501 unsigned long eml_unat; /* used for emulating instruction */
502 unsigned long pad0; /* alignment pad */
505 static inline struct kvm_pt_regs *vcpu_regs(struct kvm_vcpu *v)
507 return (struct kvm_pt_regs *) ((unsigned long) v + IA64_STK_OFFSET) - 1;
510 typedef int kvm_vmm_entry(void);
511 typedef void kvm_tramp_entry(union context *host, union context *guest);
514 struct module *module;
515 kvm_vmm_entry *vmm_entry;
516 kvm_tramp_entry *tramp_entry;
517 unsigned long vmm_ivt;
520 int kvm_highest_pending_irq(struct kvm_vcpu *vcpu);
521 int kvm_emulate_halt(struct kvm_vcpu *vcpu);
522 int kvm_pal_emul(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
523 void kvm_sal_emul(struct kvm_vcpu *vcpu);
525 static inline void kvm_inject_nmi(struct kvm_vcpu *vcpu) {}