[SCSI] make use of the residue value
[linux-2.6/mini2440.git] / include / asm-ia64 / kvm_host.h
blobc082c208c1f339085208686129da12a7bdf7c6a6
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
27 #include <linux/types.h>
28 #include <linux/mm.h>
29 #include <linux/kvm.h>
30 #include <linux/kvm_para.h>
31 #include <linux/kvm_types.h>
33 #include <asm/pal.h>
34 #include <asm/sal.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
42 /* define exit reasons from vmm to kvm*/
43 #define EXIT_REASON_VM_PANIC 0
44 #define EXIT_REASON_MMIO_INSTRUCTION 1
45 #define EXIT_REASON_PAL_CALL 2
46 #define EXIT_REASON_SAL_CALL 3
47 #define EXIT_REASON_SWITCH_RR6 4
48 #define EXIT_REASON_VM_DESTROY 5
49 #define EXIT_REASON_EXTERNAL_INTERRUPT 6
50 #define EXIT_REASON_IPI 7
51 #define EXIT_REASON_PTC_G 8
53 /*Define vmm address space and vm data space.*/
54 #define KVM_VMM_SIZE (16UL<<20)
55 #define KVM_VMM_SHIFT 24
56 #define KVM_VMM_BASE 0xD000000000000000UL
57 #define VMM_SIZE (8UL<<20)
60 * Define vm_buffer, used by PAL Services, base address.
61 * Note: vmbuffer is in the VMM-BLOCK, the size must be < 8M
63 #define KVM_VM_BUFFER_BASE (KVM_VMM_BASE + VMM_SIZE)
64 #define KVM_VM_BUFFER_SIZE (8UL<<20)
66 /*Define Virtual machine data layout.*/
67 #define KVM_VM_DATA_SHIFT 24
68 #define KVM_VM_DATA_SIZE (1UL << KVM_VM_DATA_SHIFT)
69 #define KVM_VM_DATA_BASE (KVM_VMM_BASE + KVM_VMM_SIZE)
72 #define KVM_P2M_BASE KVM_VM_DATA_BASE
73 #define KVM_P2M_OFS 0
74 #define KVM_P2M_SIZE (8UL << 20)
76 #define KVM_VHPT_BASE (KVM_P2M_BASE + KVM_P2M_SIZE)
77 #define KVM_VHPT_OFS KVM_P2M_SIZE
78 #define KVM_VHPT_BLOCK_SIZE (2UL << 20)
79 #define VHPT_SHIFT 18
80 #define VHPT_SIZE (1UL << VHPT_SHIFT)
81 #define VHPT_NUM_ENTRIES (1<<(VHPT_SHIFT-5))
83 #define KVM_VTLB_BASE (KVM_VHPT_BASE+KVM_VHPT_BLOCK_SIZE)
84 #define KVM_VTLB_OFS (KVM_VHPT_OFS+KVM_VHPT_BLOCK_SIZE)
85 #define KVM_VTLB_BLOCK_SIZE (1UL<<20)
86 #define VTLB_SHIFT 17
87 #define VTLB_SIZE (1UL<<VTLB_SHIFT)
88 #define VTLB_NUM_ENTRIES (1<<(VTLB_SHIFT-5))
90 #define KVM_VPD_BASE (KVM_VTLB_BASE+KVM_VTLB_BLOCK_SIZE)
91 #define KVM_VPD_OFS (KVM_VTLB_OFS+KVM_VTLB_BLOCK_SIZE)
92 #define KVM_VPD_BLOCK_SIZE (2UL<<20)
93 #define VPD_SHIFT 16
94 #define VPD_SIZE (1UL<<VPD_SHIFT)
96 #define KVM_VCPU_BASE (KVM_VPD_BASE+KVM_VPD_BLOCK_SIZE)
97 #define KVM_VCPU_OFS (KVM_VPD_OFS+KVM_VPD_BLOCK_SIZE)
98 #define KVM_VCPU_BLOCK_SIZE (2UL<<20)
99 #define VCPU_SHIFT 18
100 #define VCPU_SIZE (1UL<<VCPU_SHIFT)
101 #define MAX_VCPU_NUM KVM_VCPU_BLOCK_SIZE/VCPU_SIZE
103 #define KVM_VM_BASE (KVM_VCPU_BASE+KVM_VCPU_BLOCK_SIZE)
104 #define KVM_VM_OFS (KVM_VCPU_OFS+KVM_VCPU_BLOCK_SIZE)
105 #define KVM_VM_BLOCK_SIZE (1UL<<19)
107 #define KVM_MEM_DIRTY_LOG_BASE (KVM_VM_BASE+KVM_VM_BLOCK_SIZE)
108 #define KVM_MEM_DIRTY_LOG_OFS (KVM_VM_OFS+KVM_VM_BLOCK_SIZE)
109 #define KVM_MEM_DIRTY_LOG_SIZE (1UL<<19)
111 /* Get vpd, vhpt, tlb, vcpu, base*/
112 #define VPD_ADDR(n) (KVM_VPD_BASE+n*VPD_SIZE)
113 #define VHPT_ADDR(n) (KVM_VHPT_BASE+n*VHPT_SIZE)
114 #define VTLB_ADDR(n) (KVM_VTLB_BASE+n*VTLB_SIZE)
115 #define VCPU_ADDR(n) (KVM_VCPU_BASE+n*VCPU_SIZE)
117 /*IO section definitions*/
118 #define IOREQ_READ 1
119 #define IOREQ_WRITE 0
121 #define STATE_IOREQ_NONE 0
122 #define STATE_IOREQ_READY 1
123 #define STATE_IOREQ_INPROCESS 2
124 #define STATE_IORESP_READY 3
126 /*Guest Physical address layout.*/
127 #define GPFN_MEM (0UL << 60) /* Guest pfn is normal mem */
128 #define GPFN_FRAME_BUFFER (1UL << 60) /* VGA framebuffer */
129 #define GPFN_LOW_MMIO (2UL << 60) /* Low MMIO range */
130 #define GPFN_PIB (3UL << 60) /* PIB base */
131 #define GPFN_IOSAPIC (4UL << 60) /* IOSAPIC base */
132 #define GPFN_LEGACY_IO (5UL << 60) /* Legacy I/O base */
133 #define GPFN_GFW (6UL << 60) /* Guest Firmware */
134 #define GPFN_HIGH_MMIO (7UL << 60) /* High MMIO range */
136 #define GPFN_IO_MASK (7UL << 60) /* Guest pfn is I/O type */
137 #define GPFN_INV_MASK (1UL << 63) /* Guest pfn is invalid */
138 #define INVALID_MFN (~0UL)
139 #define MEM_G (1UL << 30)
140 #define MEM_M (1UL << 20)
141 #define MMIO_START (3 * MEM_G)
142 #define MMIO_SIZE (512 * MEM_M)
143 #define VGA_IO_START 0xA0000UL
144 #define VGA_IO_SIZE 0x20000
145 #define LEGACY_IO_START (MMIO_START + MMIO_SIZE)
146 #define LEGACY_IO_SIZE (64 * MEM_M)
147 #define IO_SAPIC_START 0xfec00000UL
148 #define IO_SAPIC_SIZE 0x100000
149 #define PIB_START 0xfee00000UL
150 #define PIB_SIZE 0x200000
151 #define GFW_START (4 * MEM_G - 16 * MEM_M)
152 #define GFW_SIZE (16 * MEM_M)
154 /*Deliver mode, defined for ioapic.c*/
155 #define dest_Fixed IOSAPIC_FIXED
156 #define dest_LowestPrio IOSAPIC_LOWEST_PRIORITY
158 #define NMI_VECTOR 2
159 #define ExtINT_VECTOR 0
160 #define NULL_VECTOR (-1)
161 #define IA64_SPURIOUS_INT_VECTOR 0x0f
163 #define VCPU_LID(v) (((u64)(v)->vcpu_id) << 24)
166 *Delivery mode
168 #define SAPIC_DELIV_SHIFT 8
169 #define SAPIC_FIXED 0x0
170 #define SAPIC_LOWEST_PRIORITY 0x1
171 #define SAPIC_PMI 0x2
172 #define SAPIC_NMI 0x4
173 #define SAPIC_INIT 0x5
174 #define SAPIC_EXTINT 0x7
177 * vcpu->requests bit members for arch
179 #define KVM_REQ_PTC_G 32
180 #define KVM_REQ_RESUME 33
182 #define KVM_PAGES_PER_HPAGE 1
184 struct kvm;
185 struct kvm_vcpu;
186 struct kvm_guest_debug{
189 struct kvm_mmio_req {
190 uint64_t addr; /* physical address */
191 uint64_t size; /* size in bytes */
192 uint64_t data; /* data (or paddr of data) */
193 uint8_t state:4;
194 uint8_t dir:1; /* 1=read, 0=write */
197 /*Pal data struct */
198 struct kvm_pal_call{
199 /*In area*/
200 uint64_t gr28;
201 uint64_t gr29;
202 uint64_t gr30;
203 uint64_t gr31;
204 /*Out area*/
205 struct ia64_pal_retval ret;
208 /* Sal data structure */
209 struct kvm_sal_call{
210 /*In area*/
211 uint64_t in0;
212 uint64_t in1;
213 uint64_t in2;
214 uint64_t in3;
215 uint64_t in4;
216 uint64_t in5;
217 uint64_t in6;
218 uint64_t in7;
219 struct sal_ret_values ret;
222 /*Guest change rr6*/
223 struct kvm_switch_rr6 {
224 uint64_t old_rr;
225 uint64_t new_rr;
228 union ia64_ipi_a{
229 unsigned long val;
230 struct {
231 unsigned long rv : 3;
232 unsigned long ir : 1;
233 unsigned long eid : 8;
234 unsigned long id : 8;
235 unsigned long ib_base : 44;
239 union ia64_ipi_d {
240 unsigned long val;
241 struct {
242 unsigned long vector : 8;
243 unsigned long dm : 3;
244 unsigned long ig : 53;
248 /*ipi check exit data*/
249 struct kvm_ipi_data{
250 union ia64_ipi_a addr;
251 union ia64_ipi_d data;
254 /*global purge data*/
255 struct kvm_ptc_g {
256 unsigned long vaddr;
257 unsigned long rr;
258 unsigned long ps;
259 struct kvm_vcpu *vcpu;
262 /*Exit control data */
263 struct exit_ctl_data{
264 uint32_t exit_reason;
265 uint32_t vm_status;
266 union {
267 struct kvm_mmio_req ioreq;
268 struct kvm_pal_call pal_data;
269 struct kvm_sal_call sal_data;
270 struct kvm_switch_rr6 rr_data;
271 struct kvm_ipi_data ipi_data;
272 struct kvm_ptc_g ptc_g_data;
273 } u;
276 union pte_flags {
277 unsigned long val;
278 struct {
279 unsigned long p : 1; /*0 */
280 unsigned long : 1; /* 1 */
281 unsigned long ma : 3; /* 2-4 */
282 unsigned long a : 1; /* 5 */
283 unsigned long d : 1; /* 6 */
284 unsigned long pl : 2; /* 7-8 */
285 unsigned long ar : 3; /* 9-11 */
286 unsigned long ppn : 38; /* 12-49 */
287 unsigned long : 2; /* 50-51 */
288 unsigned long ed : 1; /* 52 */
292 union ia64_pta {
293 unsigned long val;
294 struct {
295 unsigned long ve : 1;
296 unsigned long reserved0 : 1;
297 unsigned long size : 6;
298 unsigned long vf : 1;
299 unsigned long reserved1 : 6;
300 unsigned long base : 49;
304 struct thash_cb {
305 /* THASH base information */
306 struct thash_data *hash; /* hash table pointer */
307 union ia64_pta pta;
308 int num;
311 struct kvm_vcpu_stat {
314 struct kvm_vcpu_arch {
315 int launched;
316 int last_exit;
317 int last_run_cpu;
318 int vmm_tr_slot;
319 int vm_tr_slot;
321 #define KVM_MP_STATE_RUNNABLE 0
322 #define KVM_MP_STATE_UNINITIALIZED 1
323 #define KVM_MP_STATE_INIT_RECEIVED 2
324 #define KVM_MP_STATE_HALTED 3
325 int mp_state;
327 #define MAX_PTC_G_NUM 3
328 int ptc_g_count;
329 struct kvm_ptc_g ptc_g_data[MAX_PTC_G_NUM];
331 /*halt timer to wake up sleepy vcpus*/
332 struct hrtimer hlt_timer;
333 long ht_active;
335 struct kvm_lapic *apic; /* kernel irqchip context */
336 struct vpd *vpd;
338 /* Exit data for vmm_transition*/
339 struct exit_ctl_data exit_data;
341 cpumask_t cache_coherent_map;
343 unsigned long vmm_rr;
344 unsigned long host_rr6;
345 unsigned long psbits[8];
346 unsigned long cr_iipa;
347 unsigned long cr_isr;
348 unsigned long vsa_base;
349 unsigned long dirty_log_lock_pa;
350 unsigned long __gp;
351 /* TR and TC. */
352 struct thash_data itrs[NITRS];
353 struct thash_data dtrs[NDTRS];
354 /* Bit is set if there is a tr/tc for the region. */
355 unsigned char itr_regions;
356 unsigned char dtr_regions;
357 unsigned char tc_regions;
358 /* purge all */
359 unsigned long ptce_base;
360 unsigned long ptce_count[2];
361 unsigned long ptce_stride[2];
362 /* itc/itm */
363 unsigned long last_itc;
364 long itc_offset;
365 unsigned long itc_check;
366 unsigned long timer_check;
367 unsigned long timer_pending;
369 unsigned long vrr[8];
370 unsigned long ibr[8];
371 unsigned long dbr[8];
372 unsigned long insvc[4]; /* Interrupt in service. */
373 unsigned long xtp;
375 unsigned long metaphysical_rr0; /* from kvm_arch (so is pinned) */
376 unsigned long metaphysical_rr4; /* from kvm_arch (so is pinned) */
377 unsigned long metaphysical_saved_rr0; /* from kvm_arch */
378 unsigned long metaphysical_saved_rr4; /* from kvm_arch */
379 unsigned long fp_psr; /*used for lazy float register */
380 unsigned long saved_gp;
381 /*for phycial emulation */
382 int mode_flags;
383 struct thash_cb vtlb;
384 struct thash_cb vhpt;
385 char irq_check;
386 char irq_new_pending;
388 unsigned long opcode;
389 unsigned long cause;
390 union context host;
391 union context guest;
394 struct kvm_vm_stat {
395 u64 remote_tlb_flush;
398 struct kvm_sal_data {
399 unsigned long boot_ip;
400 unsigned long boot_gp;
403 struct kvm_arch {
404 unsigned long vm_base;
405 unsigned long metaphysical_rr0;
406 unsigned long metaphysical_rr4;
407 unsigned long vmm_init_rr;
408 unsigned long vhpt_base;
409 unsigned long vtlb_base;
410 unsigned long vpd_base;
411 spinlock_t dirty_log_lock;
412 struct kvm_ioapic *vioapic;
413 struct kvm_vm_stat stat;
414 struct kvm_sal_data rdv_sal_data;
417 union cpuid3_t {
418 u64 value;
419 struct {
420 u64 number : 8;
421 u64 revision : 8;
422 u64 model : 8;
423 u64 family : 8;
424 u64 archrev : 8;
425 u64 rv : 24;
429 struct kvm_pt_regs {
430 /* The following registers are saved by SAVE_MIN: */
431 unsigned long b6; /* scratch */
432 unsigned long b7; /* scratch */
434 unsigned long ar_csd; /* used by cmp8xchg16 (scratch) */
435 unsigned long ar_ssd; /* reserved for future use (scratch) */
437 unsigned long r8; /* scratch (return value register 0) */
438 unsigned long r9; /* scratch (return value register 1) */
439 unsigned long r10; /* scratch (return value register 2) */
440 unsigned long r11; /* scratch (return value register 3) */
442 unsigned long cr_ipsr; /* interrupted task's psr */
443 unsigned long cr_iip; /* interrupted task's instruction pointer */
444 unsigned long cr_ifs; /* interrupted task's function state */
446 unsigned long ar_unat; /* interrupted task's NaT register (preserved) */
447 unsigned long ar_pfs; /* prev function state */
448 unsigned long ar_rsc; /* RSE configuration */
449 /* The following two are valid only if cr_ipsr.cpl > 0: */
450 unsigned long ar_rnat; /* RSE NaT */
451 unsigned long ar_bspstore; /* RSE bspstore */
453 unsigned long pr; /* 64 predicate registers (1 bit each) */
454 unsigned long b0; /* return pointer (bp) */
455 unsigned long loadrs; /* size of dirty partition << 16 */
457 unsigned long r1; /* the gp pointer */
458 unsigned long r12; /* interrupted task's memory stack pointer */
459 unsigned long r13; /* thread pointer */
461 unsigned long ar_fpsr; /* floating point status (preserved) */
462 unsigned long r15; /* scratch */
464 /* The remaining registers are NOT saved for system calls. */
465 unsigned long r14; /* scratch */
466 unsigned long r2; /* scratch */
467 unsigned long r3; /* scratch */
468 unsigned long r16; /* scratch */
469 unsigned long r17; /* scratch */
470 unsigned long r18; /* scratch */
471 unsigned long r19; /* scratch */
472 unsigned long r20; /* scratch */
473 unsigned long r21; /* scratch */
474 unsigned long r22; /* scratch */
475 unsigned long r23; /* scratch */
476 unsigned long r24; /* scratch */
477 unsigned long r25; /* scratch */
478 unsigned long r26; /* scratch */
479 unsigned long r27; /* scratch */
480 unsigned long r28; /* scratch */
481 unsigned long r29; /* scratch */
482 unsigned long r30; /* scratch */
483 unsigned long r31; /* scratch */
484 unsigned long ar_ccv; /* compare/exchange value (scratch) */
487 * Floating point registers that the kernel considers scratch:
489 struct ia64_fpreg f6; /* scratch */
490 struct ia64_fpreg f7; /* scratch */
491 struct ia64_fpreg f8; /* scratch */
492 struct ia64_fpreg f9; /* scratch */
493 struct ia64_fpreg f10; /* scratch */
494 struct ia64_fpreg f11; /* scratch */
496 unsigned long r4; /* preserved */
497 unsigned long r5; /* preserved */
498 unsigned long r6; /* preserved */
499 unsigned long r7; /* preserved */
500 unsigned long eml_unat; /* used for emulating instruction */
501 unsigned long pad0; /* alignment pad */
504 static inline struct kvm_pt_regs *vcpu_regs(struct kvm_vcpu *v)
506 return (struct kvm_pt_regs *) ((unsigned long) v + IA64_STK_OFFSET) - 1;
509 typedef int kvm_vmm_entry(void);
510 typedef void kvm_tramp_entry(union context *host, union context *guest);
512 struct kvm_vmm_info{
513 struct module *module;
514 kvm_vmm_entry *vmm_entry;
515 kvm_tramp_entry *tramp_entry;
516 unsigned long vmm_ivt;
519 int kvm_highest_pending_irq(struct kvm_vcpu *vcpu);
520 int kvm_emulate_halt(struct kvm_vcpu *vcpu);
521 int kvm_pal_emul(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
522 void kvm_sal_emul(struct kvm_vcpu *vcpu);
524 #endif