KVM: ia64: Re-organize data sturure of guests' data area
[linux-2.6/mini2440.git] / arch / ia64 / include / asm / kvm_host.h
blob678e2646a50098a917b5571a5a3574a0b27e3dc4
1 /*
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
15 * more details.
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
26 #define KVM_MEMORY_SLOTS 32
27 /* memory slots that does not exposed to userspace */
28 #define KVM_PRIVATE_MEM_SLOTS 4
30 #define KVM_COALESCED_MMIO_PAGE_OFFSET 1
32 /* define exit reasons from vmm to kvm*/
33 #define EXIT_REASON_VM_PANIC 0
34 #define EXIT_REASON_MMIO_INSTRUCTION 1
35 #define EXIT_REASON_PAL_CALL 2
36 #define EXIT_REASON_SAL_CALL 3
37 #define EXIT_REASON_SWITCH_RR6 4
38 #define EXIT_REASON_VM_DESTROY 5
39 #define EXIT_REASON_EXTERNAL_INTERRUPT 6
40 #define EXIT_REASON_IPI 7
41 #define EXIT_REASON_PTC_G 8
43 /*Define vmm address space and vm data space.*/
44 #define KVM_VMM_SIZE (__IA64_UL_CONST(16)<<20)
45 #define KVM_VMM_SHIFT 24
46 #define KVM_VMM_BASE 0xD000000000000000
47 #define VMM_SIZE (__IA64_UL_CONST(8)<<20)
50 * Define vm_buffer, used by PAL Services, base address.
51 * Note: vm_buffer is in the VMM-BLOCK, the size must be < 8M
53 #define KVM_VM_BUFFER_BASE (KVM_VMM_BASE + VMM_SIZE)
54 #define KVM_VM_BUFFER_SIZE (__IA64_UL_CONST(8)<<20)
57 * kvm guest's data area looks as follow:
59 * +----------------------+ ------- KVM_VM_DATA_SIZE
60 * | vcpu[n]'s data | | ___________________KVM_STK_OFFSET
61 * | | | / |
62 * | .......... | | /vcpu's struct&stack |
63 * | .......... | | /---------------------|---- 0
64 * | vcpu[5]'s data | | / vpd |
65 * | vcpu[4]'s data | |/-----------------------|
66 * | vcpu[3]'s data | / vtlb |
67 * | vcpu[2]'s data | /|------------------------|
68 * | vcpu[1]'s data |/ | vhpt |
69 * | vcpu[0]'s data |____________________________|
70 * +----------------------+ |
71 * | memory dirty log | |
72 * +----------------------+ |
73 * | vm's data struct | |
74 * +----------------------+ |
75 * | | |
76 * | | |
77 * | | |
78 * | | |
79 * | | |
80 * | | |
81 * | | |
82 * | vm's p2m table | |
83 * | | |
84 * | | |
85 * | | | |
86 * vm's data->| | | |
87 * +----------------------+ ------- 0
88 * To support large memory, needs to increase the size of p2m.
89 * To support more vcpus, needs to ensure it has enough space to
90 * hold vcpus' data.
93 #define KVM_VM_DATA_SHIFT 26
94 #define KVM_VM_DATA_SIZE (__IA64_UL_CONST(1) << KVM_VM_DATA_SHIFT)
95 #define KVM_VM_DATA_BASE (KVM_VMM_BASE + KVM_VM_DATA_SIZE)
97 #define KVM_P2M_BASE KVM_VM_DATA_BASE
98 #define KVM_P2M_SIZE (__IA64_UL_CONST(24) << 20)
100 #define VHPT_SHIFT 16
101 #define VHPT_SIZE (__IA64_UL_CONST(1) << VHPT_SHIFT)
102 #define VHPT_NUM_ENTRIES (__IA64_UL_CONST(1) << (VHPT_SHIFT-5))
104 #define VTLB_SHIFT 16
105 #define VTLB_SIZE (__IA64_UL_CONST(1) << VTLB_SHIFT)
106 #define VTLB_NUM_ENTRIES (1UL << (VHPT_SHIFT-5))
108 #define VPD_SHIFT 16
109 #define VPD_SIZE (__IA64_UL_CONST(1) << VPD_SHIFT)
111 #define VCPU_STRUCT_SHIFT 16
112 #define VCPU_STRUCT_SIZE (__IA64_UL_CONST(1) << VCPU_STRUCT_SHIFT)
114 #define KVM_STK_OFFSET VCPU_STRUCT_SIZE
116 #define KVM_VM_STRUCT_SHIFT 19
117 #define KVM_VM_STRUCT_SIZE (__IA64_UL_CONST(1) << KVM_VM_STRUCT_SHIFT)
119 #define KVM_MEM_DIRY_LOG_SHIFT 19
120 #define KVM_MEM_DIRTY_LOG_SIZE (__IA64_UL_CONST(1) << KVM_MEM_DIRY_LOG_SHIFT)
122 #ifndef __ASSEMBLY__
124 /*Define the max vcpus and memory for Guests.*/
125 #define KVM_MAX_VCPUS (KVM_VM_DATA_SIZE - KVM_P2M_SIZE - KVM_VM_STRUCT_SIZE -\
126 KVM_MEM_DIRTY_LOG_SIZE) / sizeof(struct kvm_vcpu_data)
127 #define KVM_MAX_MEM_SIZE (KVM_P2M_SIZE >> 3 << PAGE_SHIFT)
129 #include <linux/types.h>
130 #include <linux/mm.h>
131 #include <linux/kvm.h>
132 #include <linux/kvm_para.h>
133 #include <linux/kvm_types.h>
135 #include <asm/pal.h>
136 #include <asm/sal.h>
137 #include <asm/page.h>
139 struct kvm_vcpu_data {
140 char vcpu_vhpt[VHPT_SIZE];
141 char vcpu_vtlb[VTLB_SIZE];
142 char vcpu_vpd[VPD_SIZE];
143 char vcpu_struct[VCPU_STRUCT_SIZE];
146 struct kvm_vm_data {
147 char kvm_p2m[KVM_P2M_SIZE];
148 char kvm_vm_struct[KVM_VM_STRUCT_SIZE];
149 char kvm_mem_dirty_log[KVM_MEM_DIRTY_LOG_SIZE];
150 struct kvm_vcpu_data vcpu_data[KVM_MAX_VCPUS];
153 #define VCPU_BASE(n) KVM_VM_DATA_BASE + \
154 offsetof(struct kvm_vm_data, vcpu_data[n])
155 #define VM_BASE KVM_VM_DATA_BASE + \
156 offsetof(struct kvm_vm_data, kvm_vm_struct)
157 #define KVM_MEM_DIRTY_LOG_BASE KVM_VM_DATA_BASE + \
158 offsetof(struct kvm_vm_data, kvm_mem_dirty_log)
160 #define VHPT_BASE(n) (VCPU_BASE(n) + offsetof(struct kvm_vcpu_data, vcpu_vhpt))
161 #define VTLB_BASE(n) (VCPU_BASE(n) + offsetof(struct kvm_vcpu_data, vcpu_vtlb))
162 #define VPD_BASE(n) (VCPU_BASE(n) + offsetof(struct kvm_vcpu_data, vcpu_vpd))
163 #define VCPU_STRUCT_BASE(n) (VCPU_BASE(n) + \
164 offsetof(struct kvm_vcpu_data, vcpu_struct))
166 /*IO section definitions*/
167 #define IOREQ_READ 1
168 #define IOREQ_WRITE 0
170 #define STATE_IOREQ_NONE 0
171 #define STATE_IOREQ_READY 1
172 #define STATE_IOREQ_INPROCESS 2
173 #define STATE_IORESP_READY 3
175 /*Guest Physical address layout.*/
176 #define GPFN_MEM (0UL << 60) /* Guest pfn is normal mem */
177 #define GPFN_FRAME_BUFFER (1UL << 60) /* VGA framebuffer */
178 #define GPFN_LOW_MMIO (2UL << 60) /* Low MMIO range */
179 #define GPFN_PIB (3UL << 60) /* PIB base */
180 #define GPFN_IOSAPIC (4UL << 60) /* IOSAPIC base */
181 #define GPFN_LEGACY_IO (5UL << 60) /* Legacy I/O base */
182 #define GPFN_GFW (6UL << 60) /* Guest Firmware */
183 #define GPFN_PHYS_MMIO (7UL << 60) /* Directed MMIO Range */
185 #define GPFN_IO_MASK (7UL << 60) /* Guest pfn is I/O type */
186 #define GPFN_INV_MASK (1UL << 63) /* Guest pfn is invalid */
187 #define INVALID_MFN (~0UL)
188 #define MEM_G (1UL << 30)
189 #define MEM_M (1UL << 20)
190 #define MMIO_START (3 * MEM_G)
191 #define MMIO_SIZE (512 * MEM_M)
192 #define VGA_IO_START 0xA0000UL
193 #define VGA_IO_SIZE 0x20000
194 #define LEGACY_IO_START (MMIO_START + MMIO_SIZE)
195 #define LEGACY_IO_SIZE (64 * MEM_M)
196 #define IO_SAPIC_START 0xfec00000UL
197 #define IO_SAPIC_SIZE 0x100000
198 #define PIB_START 0xfee00000UL
199 #define PIB_SIZE 0x200000
200 #define GFW_START (4 * MEM_G - 16 * MEM_M)
201 #define GFW_SIZE (16 * MEM_M)
203 /*Deliver mode, defined for ioapic.c*/
204 #define dest_Fixed IOSAPIC_FIXED
205 #define dest_LowestPrio IOSAPIC_LOWEST_PRIORITY
207 #define NMI_VECTOR 2
208 #define ExtINT_VECTOR 0
209 #define NULL_VECTOR (-1)
210 #define IA64_SPURIOUS_INT_VECTOR 0x0f
212 #define VCPU_LID(v) (((u64)(v)->vcpu_id) << 24)
215 *Delivery mode
217 #define SAPIC_DELIV_SHIFT 8
218 #define SAPIC_FIXED 0x0
219 #define SAPIC_LOWEST_PRIORITY 0x1
220 #define SAPIC_PMI 0x2
221 #define SAPIC_NMI 0x4
222 #define SAPIC_INIT 0x5
223 #define SAPIC_EXTINT 0x7
226 * vcpu->requests bit members for arch
228 #define KVM_REQ_PTC_G 32
229 #define KVM_REQ_RESUME 33
231 #define KVM_PAGES_PER_HPAGE 1
233 struct kvm;
234 struct kvm_vcpu;
235 struct kvm_guest_debug{
238 struct kvm_mmio_req {
239 uint64_t addr; /* physical address */
240 uint64_t size; /* size in bytes */
241 uint64_t data; /* data (or paddr of data) */
242 uint8_t state:4;
243 uint8_t dir:1; /* 1=read, 0=write */
246 /*Pal data struct */
247 struct kvm_pal_call{
248 /*In area*/
249 uint64_t gr28;
250 uint64_t gr29;
251 uint64_t gr30;
252 uint64_t gr31;
253 /*Out area*/
254 struct ia64_pal_retval ret;
257 /* Sal data structure */
258 struct kvm_sal_call{
259 /*In area*/
260 uint64_t in0;
261 uint64_t in1;
262 uint64_t in2;
263 uint64_t in3;
264 uint64_t in4;
265 uint64_t in5;
266 uint64_t in6;
267 uint64_t in7;
268 struct sal_ret_values ret;
271 /*Guest change rr6*/
272 struct kvm_switch_rr6 {
273 uint64_t old_rr;
274 uint64_t new_rr;
277 union ia64_ipi_a{
278 unsigned long val;
279 struct {
280 unsigned long rv : 3;
281 unsigned long ir : 1;
282 unsigned long eid : 8;
283 unsigned long id : 8;
284 unsigned long ib_base : 44;
288 union ia64_ipi_d {
289 unsigned long val;
290 struct {
291 unsigned long vector : 8;
292 unsigned long dm : 3;
293 unsigned long ig : 53;
297 /*ipi check exit data*/
298 struct kvm_ipi_data{
299 union ia64_ipi_a addr;
300 union ia64_ipi_d data;
303 /*global purge data*/
304 struct kvm_ptc_g {
305 unsigned long vaddr;
306 unsigned long rr;
307 unsigned long ps;
308 struct kvm_vcpu *vcpu;
311 /*Exit control data */
312 struct exit_ctl_data{
313 uint32_t exit_reason;
314 uint32_t vm_status;
315 union {
316 struct kvm_mmio_req ioreq;
317 struct kvm_pal_call pal_data;
318 struct kvm_sal_call sal_data;
319 struct kvm_switch_rr6 rr_data;
320 struct kvm_ipi_data ipi_data;
321 struct kvm_ptc_g ptc_g_data;
322 } u;
325 union pte_flags {
326 unsigned long val;
327 struct {
328 unsigned long p : 1; /*0 */
329 unsigned long : 1; /* 1 */
330 unsigned long ma : 3; /* 2-4 */
331 unsigned long a : 1; /* 5 */
332 unsigned long d : 1; /* 6 */
333 unsigned long pl : 2; /* 7-8 */
334 unsigned long ar : 3; /* 9-11 */
335 unsigned long ppn : 38; /* 12-49 */
336 unsigned long : 2; /* 50-51 */
337 unsigned long ed : 1; /* 52 */
341 union ia64_pta {
342 unsigned long val;
343 struct {
344 unsigned long ve : 1;
345 unsigned long reserved0 : 1;
346 unsigned long size : 6;
347 unsigned long vf : 1;
348 unsigned long reserved1 : 6;
349 unsigned long base : 49;
353 struct thash_cb {
354 /* THASH base information */
355 struct thash_data *hash; /* hash table pointer */
356 union ia64_pta pta;
357 int num;
360 struct kvm_vcpu_stat {
363 struct kvm_vcpu_arch {
364 int launched;
365 int last_exit;
366 int last_run_cpu;
367 int vmm_tr_slot;
368 int vm_tr_slot;
370 #define KVM_MP_STATE_RUNNABLE 0
371 #define KVM_MP_STATE_UNINITIALIZED 1
372 #define KVM_MP_STATE_INIT_RECEIVED 2
373 #define KVM_MP_STATE_HALTED 3
374 int mp_state;
376 #define MAX_PTC_G_NUM 3
377 int ptc_g_count;
378 struct kvm_ptc_g ptc_g_data[MAX_PTC_G_NUM];
380 /*halt timer to wake up sleepy vcpus*/
381 struct hrtimer hlt_timer;
382 long ht_active;
384 struct kvm_lapic *apic; /* kernel irqchip context */
385 struct vpd *vpd;
387 /* Exit data for vmm_transition*/
388 struct exit_ctl_data exit_data;
390 cpumask_t cache_coherent_map;
392 unsigned long vmm_rr;
393 unsigned long host_rr6;
394 unsigned long psbits[8];
395 unsigned long cr_iipa;
396 unsigned long cr_isr;
397 unsigned long vsa_base;
398 unsigned long dirty_log_lock_pa;
399 unsigned long __gp;
400 /* TR and TC. */
401 struct thash_data itrs[NITRS];
402 struct thash_data dtrs[NDTRS];
403 /* Bit is set if there is a tr/tc for the region. */
404 unsigned char itr_regions;
405 unsigned char dtr_regions;
406 unsigned char tc_regions;
407 /* purge all */
408 unsigned long ptce_base;
409 unsigned long ptce_count[2];
410 unsigned long ptce_stride[2];
411 /* itc/itm */
412 unsigned long last_itc;
413 long itc_offset;
414 unsigned long itc_check;
415 unsigned long timer_check;
416 unsigned int timer_pending;
417 unsigned int timer_fired;
419 unsigned long vrr[8];
420 unsigned long ibr[8];
421 unsigned long dbr[8];
422 unsigned long insvc[4]; /* Interrupt in service. */
423 unsigned long xtp;
425 unsigned long metaphysical_rr0; /* from kvm_arch (so is pinned) */
426 unsigned long metaphysical_rr4; /* from kvm_arch (so is pinned) */
427 unsigned long metaphysical_saved_rr0; /* from kvm_arch */
428 unsigned long metaphysical_saved_rr4; /* from kvm_arch */
429 unsigned long fp_psr; /*used for lazy float register */
430 unsigned long saved_gp;
431 /*for phycial emulation */
432 int mode_flags;
433 struct thash_cb vtlb;
434 struct thash_cb vhpt;
435 char irq_check;
436 char irq_new_pending;
438 unsigned long opcode;
439 unsigned long cause;
440 union context host;
441 union context guest;
444 struct kvm_vm_stat {
445 u64 remote_tlb_flush;
448 struct kvm_sal_data {
449 unsigned long boot_ip;
450 unsigned long boot_gp;
453 struct kvm_arch {
454 spinlock_t dirty_log_lock;
456 unsigned long vm_base;
457 unsigned long metaphysical_rr0;
458 unsigned long metaphysical_rr4;
459 unsigned long vmm_init_rr;
461 struct kvm_ioapic *vioapic;
462 struct kvm_vm_stat stat;
463 struct kvm_sal_data rdv_sal_data;
465 struct list_head assigned_dev_head;
466 struct dmar_domain *intel_iommu_domain;
467 struct hlist_head irq_ack_notifier_list;
469 unsigned long irq_sources_bitmap;
470 unsigned long irq_states[KVM_IOAPIC_NUM_PINS];
473 union cpuid3_t {
474 u64 value;
475 struct {
476 u64 number : 8;
477 u64 revision : 8;
478 u64 model : 8;
479 u64 family : 8;
480 u64 archrev : 8;
481 u64 rv : 24;
485 struct kvm_pt_regs {
486 /* The following registers are saved by SAVE_MIN: */
487 unsigned long b6; /* scratch */
488 unsigned long b7; /* scratch */
490 unsigned long ar_csd; /* used by cmp8xchg16 (scratch) */
491 unsigned long ar_ssd; /* reserved for future use (scratch) */
493 unsigned long r8; /* scratch (return value register 0) */
494 unsigned long r9; /* scratch (return value register 1) */
495 unsigned long r10; /* scratch (return value register 2) */
496 unsigned long r11; /* scratch (return value register 3) */
498 unsigned long cr_ipsr; /* interrupted task's psr */
499 unsigned long cr_iip; /* interrupted task's instruction pointer */
500 unsigned long cr_ifs; /* interrupted task's function state */
502 unsigned long ar_unat; /* interrupted task's NaT register (preserved) */
503 unsigned long ar_pfs; /* prev function state */
504 unsigned long ar_rsc; /* RSE configuration */
505 /* The following two are valid only if cr_ipsr.cpl > 0: */
506 unsigned long ar_rnat; /* RSE NaT */
507 unsigned long ar_bspstore; /* RSE bspstore */
509 unsigned long pr; /* 64 predicate registers (1 bit each) */
510 unsigned long b0; /* return pointer (bp) */
511 unsigned long loadrs; /* size of dirty partition << 16 */
513 unsigned long r1; /* the gp pointer */
514 unsigned long r12; /* interrupted task's memory stack pointer */
515 unsigned long r13; /* thread pointer */
517 unsigned long ar_fpsr; /* floating point status (preserved) */
518 unsigned long r15; /* scratch */
520 /* The remaining registers are NOT saved for system calls. */
521 unsigned long r14; /* scratch */
522 unsigned long r2; /* scratch */
523 unsigned long r3; /* scratch */
524 unsigned long r16; /* scratch */
525 unsigned long r17; /* scratch */
526 unsigned long r18; /* scratch */
527 unsigned long r19; /* scratch */
528 unsigned long r20; /* scratch */
529 unsigned long r21; /* scratch */
530 unsigned long r22; /* scratch */
531 unsigned long r23; /* scratch */
532 unsigned long r24; /* scratch */
533 unsigned long r25; /* scratch */
534 unsigned long r26; /* scratch */
535 unsigned long r27; /* scratch */
536 unsigned long r28; /* scratch */
537 unsigned long r29; /* scratch */
538 unsigned long r30; /* scratch */
539 unsigned long r31; /* scratch */
540 unsigned long ar_ccv; /* compare/exchange value (scratch) */
543 * Floating point registers that the kernel considers scratch:
545 struct ia64_fpreg f6; /* scratch */
546 struct ia64_fpreg f7; /* scratch */
547 struct ia64_fpreg f8; /* scratch */
548 struct ia64_fpreg f9; /* scratch */
549 struct ia64_fpreg f10; /* scratch */
550 struct ia64_fpreg f11; /* scratch */
552 unsigned long r4; /* preserved */
553 unsigned long r5; /* preserved */
554 unsigned long r6; /* preserved */
555 unsigned long r7; /* preserved */
556 unsigned long eml_unat; /* used for emulating instruction */
557 unsigned long pad0; /* alignment pad */
560 static inline struct kvm_pt_regs *vcpu_regs(struct kvm_vcpu *v)
562 return (struct kvm_pt_regs *) ((unsigned long) v + KVM_STK_OFFSET) - 1;
565 typedef int kvm_vmm_entry(void);
566 typedef void kvm_tramp_entry(union context *host, union context *guest);
568 struct kvm_vmm_info{
569 struct module *module;
570 kvm_vmm_entry *vmm_entry;
571 kvm_tramp_entry *tramp_entry;
572 unsigned long vmm_ivt;
575 int kvm_highest_pending_irq(struct kvm_vcpu *vcpu);
576 int kvm_emulate_halt(struct kvm_vcpu *vcpu);
577 int kvm_pal_emul(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
578 void kvm_sal_emul(struct kvm_vcpu *vcpu);
580 static inline void kvm_inject_nmi(struct kvm_vcpu *vcpu) {}
581 #endif /* __ASSEMBLY__*/
583 #endif