home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / src / linux-headers-2.6.28-15 / arch / ia64 / include / asm / kvm_host.h < prev    next >
Encoding:
C/C++ Source or Header  |  2008-12-24  |  14.4 KB  |  536 lines

  1. /*
  2.  * kvm_host.h: used for kvm module, and hold ia64-specific sections.
  3.  *
  4.  * Copyright (C) 2007, Intel Corporation.
  5.  *
  6.  * Xiantao Zhang <xiantao.zhang@intel.com>
  7.  *
  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.
  11.  *
  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.
  16.  *
  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.
  20.  *
  21.  */
  22.  
  23. #ifndef __ASM_KVM_HOST_H
  24. #define __ASM_KVM_HOST_H
  25.  
  26.  
  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>
  32.  
  33. #include <asm/pal.h>
  34. #include <asm/sal.h>
  35.  
  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
  40.  
  41. #define KVM_COALESCED_MMIO_PAGE_OFFSET 1
  42.  
  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
  53.  
  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)
  59.  
  60. /*
  61.  * Define vm_buffer, used by PAL Services, base address.
  62.  * Note: vmbuffer is in the VMM-BLOCK, the size must be < 8M
  63.  */
  64. #define KVM_VM_BUFFER_BASE (KVM_VMM_BASE + VMM_SIZE)
  65. #define KVM_VM_BUFFER_SIZE (8UL<<20)
  66.  
  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)
  71.  
  72.  
  73. #define KVM_P2M_BASE    KVM_VM_DATA_BASE
  74. #define KVM_P2M_OFS     0
  75. #define KVM_P2M_SIZE    (8UL << 20)
  76.  
  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)
  80. #define VHPT_SHIFT      18
  81. #define VHPT_SIZE       (1UL << VHPT_SHIFT)
  82. #define VHPT_NUM_ENTRIES (1<<(VHPT_SHIFT-5))
  83.  
  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)
  87. #define VTLB_SHIFT      17
  88. #define VTLB_SIZE       (1UL<<VTLB_SHIFT)
  89. #define VTLB_NUM_ENTRIES (1<<(VTLB_SHIFT-5))
  90.  
  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)
  94. #define VPD_SHIFT       16
  95. #define VPD_SIZE        (1UL<<VPD_SHIFT)
  96.  
  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
  103.  
  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)
  107.  
  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)
  111.  
  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)
  117.  
  118. /*IO section definitions*/
  119. #define IOREQ_READ      1
  120. #define IOREQ_WRITE     0
  121.  
  122. #define STATE_IOREQ_NONE        0
  123. #define STATE_IOREQ_READY       1
  124. #define STATE_IOREQ_INPROCESS   2
  125. #define STATE_IORESP_READY      3
  126.  
  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_PHYS_MMIO      (7UL << 60) /* Directed MMIO Range */
  136.  
  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)
  154.  
  155. /*Deliver mode, defined for ioapic.c*/
  156. #define dest_Fixed IOSAPIC_FIXED
  157. #define dest_LowestPrio IOSAPIC_LOWEST_PRIORITY
  158.  
  159. #define NMI_VECTOR              2
  160. #define ExtINT_VECTOR               0
  161. #define NULL_VECTOR             (-1)
  162. #define IA64_SPURIOUS_INT_VECTOR        0x0f
  163.  
  164. #define VCPU_LID(v) (((u64)(v)->vcpu_id) << 24)
  165.  
  166. /*
  167.  *Delivery mode
  168.  */
  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
  176.  
  177. /*
  178.  * vcpu->requests bit members for arch
  179.  */
  180. #define KVM_REQ_PTC_G        32
  181. #define KVM_REQ_RESUME        33
  182.  
  183. #define KVM_PAGES_PER_HPAGE    1
  184.  
  185. struct kvm;
  186. struct kvm_vcpu;
  187. struct kvm_guest_debug{
  188. };
  189.  
  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)     */
  194.     uint8_t state:4;
  195.     uint8_t dir:1;          /*  1=read, 0=write             */
  196. };
  197.  
  198. /*Pal data struct */
  199. struct kvm_pal_call{
  200.     /*In area*/
  201.     uint64_t gr28;
  202.     uint64_t gr29;
  203.     uint64_t gr30;
  204.     uint64_t gr31;
  205.     /*Out area*/
  206.     struct ia64_pal_retval ret;
  207. };
  208.  
  209. /* Sal data structure */
  210. struct kvm_sal_call{
  211.     /*In area*/
  212.     uint64_t in0;
  213.     uint64_t in1;
  214.     uint64_t in2;
  215.     uint64_t in3;
  216.     uint64_t in4;
  217.     uint64_t in5;
  218.     uint64_t in6;
  219.     uint64_t in7;
  220.     struct sal_ret_values ret;
  221. };
  222.  
  223. /*Guest change rr6*/
  224. struct kvm_switch_rr6 {
  225.     uint64_t old_rr;
  226.     uint64_t new_rr;
  227. };
  228.  
  229. union ia64_ipi_a{
  230.     unsigned long val;
  231.     struct {
  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;
  237.     };
  238. };
  239.  
  240. union ia64_ipi_d {
  241.     unsigned long val;
  242.     struct {
  243.         unsigned long vector : 8;
  244.         unsigned long dm  : 3;
  245.         unsigned long ig  : 53;
  246.     };
  247. };
  248.  
  249. /*ipi check exit data*/
  250. struct kvm_ipi_data{
  251.     union ia64_ipi_a addr;
  252.     union ia64_ipi_d data;
  253. };
  254.  
  255. /*global purge data*/
  256. struct kvm_ptc_g {
  257.     unsigned long vaddr;
  258.     unsigned long rr;
  259.     unsigned long ps;
  260.     struct kvm_vcpu *vcpu;
  261. };
  262.  
  263. /*Exit control data */
  264. struct exit_ctl_data{
  265.     uint32_t exit_reason;
  266.     uint32_t vm_status;
  267.     union {
  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;
  274.     } u;
  275. };
  276.  
  277. union pte_flags {
  278.     unsigned long val;
  279.     struct {
  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    */
  290.     };
  291. };
  292.  
  293. union ia64_pta {
  294.     unsigned long val;
  295.     struct {
  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;
  302.     };
  303. };
  304.  
  305. struct thash_cb {
  306.     /* THASH base information */
  307.     struct thash_data    *hash; /* hash table pointer */
  308.     union ia64_pta        pta;
  309.     int           num;
  310. };
  311.  
  312. struct kvm_vcpu_stat {
  313. };
  314.  
  315. struct kvm_vcpu_arch {
  316.     int launched;
  317.     int last_exit;
  318.     int last_run_cpu;
  319.     int vmm_tr_slot;
  320.     int vm_tr_slot;
  321.  
  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
  326.     int mp_state;
  327.  
  328. #define MAX_PTC_G_NUM            3
  329.     int ptc_g_count;
  330.     struct kvm_ptc_g ptc_g_data[MAX_PTC_G_NUM];
  331.  
  332.     /*halt timer to wake up sleepy vcpus*/
  333.     struct hrtimer hlt_timer;
  334.     long ht_active;
  335.  
  336.     struct kvm_lapic *apic;    /* kernel irqchip context */
  337.     struct vpd *vpd;
  338.  
  339.     /* Exit data for vmm_transition*/
  340.     struct exit_ctl_data exit_data;
  341.  
  342.     cpumask_t cache_coherent_map;
  343.  
  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;
  351.     unsigned long __gp;
  352.     /* TR and TC.  */
  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;
  359.     /* purge all */
  360.     unsigned long ptce_base;
  361.     unsigned long ptce_count[2];
  362.     unsigned long ptce_stride[2];
  363.     /* itc/itm */
  364.     unsigned long last_itc;
  365.     long itc_offset;
  366.     unsigned long itc_check;
  367.     unsigned long timer_check;
  368.     unsigned int timer_pending;
  369.     unsigned int timer_fired;
  370.  
  371.     unsigned long vrr[8];
  372.     unsigned long ibr[8];
  373.     unsigned long dbr[8];
  374.     unsigned long insvc[4];        /* Interrupt in service.  */
  375.     unsigned long xtp;
  376.  
  377.     unsigned long metaphysical_rr0; /* from kvm_arch (so is pinned) */
  378.     unsigned long metaphysical_rr4;    /* from kvm_arch (so is pinned) */
  379.     unsigned long metaphysical_saved_rr0; /* from kvm_arch          */
  380.     unsigned long metaphysical_saved_rr4; /* from kvm_arch          */
  381.     unsigned long fp_psr;       /*used for lazy float register */
  382.     unsigned long saved_gp;
  383.     /*for phycial  emulation */
  384.     int mode_flags;
  385.     struct thash_cb vtlb;
  386.     struct thash_cb vhpt;
  387.     char irq_check;
  388.     char irq_new_pending;
  389.  
  390.     unsigned long opcode;
  391.     unsigned long cause;
  392.     union context host;
  393.     union context guest;
  394. };
  395.  
  396. struct kvm_vm_stat {
  397.     u64 remote_tlb_flush;
  398. };
  399.  
  400. struct kvm_sal_data {
  401.     unsigned long boot_ip;
  402.     unsigned long boot_gp;
  403. };
  404.  
  405. struct kvm_arch {
  406.     unsigned long    vm_base;
  407.     unsigned long    metaphysical_rr0;
  408.     unsigned long    metaphysical_rr4;
  409.     unsigned long    vmm_init_rr;
  410.     unsigned long    vhpt_base;
  411.     unsigned long    vtlb_base;
  412.     unsigned long     vpd_base;
  413.     spinlock_t dirty_log_lock;
  414.     struct kvm_ioapic *vioapic;
  415.     struct kvm_vm_stat stat;
  416.     struct kvm_sal_data rdv_sal_data;
  417.  
  418.     struct list_head assigned_dev_head;
  419.     struct dmar_domain *intel_iommu_domain;
  420.     struct hlist_head irq_ack_notifier_list;
  421.  
  422.     unsigned long irq_sources_bitmap;
  423.     unsigned long irq_states[KVM_IOAPIC_NUM_PINS];
  424. };
  425.  
  426. union cpuid3_t {
  427.     u64 value;
  428.     struct {
  429.         u64 number : 8;
  430.         u64 revision : 8;
  431.         u64 model : 8;
  432.         u64 family : 8;
  433.         u64 archrev : 8;
  434.         u64 rv : 24;
  435.     };
  436. };
  437.  
  438. struct kvm_pt_regs {
  439.     /* The following registers are saved by SAVE_MIN: */
  440.     unsigned long b6;  /* scratch */
  441.     unsigned long b7;  /* scratch */
  442.  
  443.     unsigned long ar_csd; /* used by cmp8xchg16 (scratch) */
  444.     unsigned long ar_ssd; /* reserved for future use (scratch) */
  445.  
  446.     unsigned long r8;  /* scratch (return value register 0) */
  447.     unsigned long r9;  /* scratch (return value register 1) */
  448.     unsigned long r10; /* scratch (return value register 2) */
  449.     unsigned long r11; /* scratch (return value register 3) */
  450.  
  451.     unsigned long cr_ipsr; /* interrupted task's psr */
  452.     unsigned long cr_iip;  /* interrupted task's instruction pointer */
  453.     unsigned long cr_ifs;  /* interrupted task's function state */
  454.  
  455.     unsigned long ar_unat; /* interrupted task's NaT register (preserved) */
  456.     unsigned long ar_pfs;  /* prev function state  */
  457.     unsigned long ar_rsc;  /* RSE configuration */
  458.     /* The following two are valid only if cr_ipsr.cpl > 0: */
  459.     unsigned long ar_rnat;  /* RSE NaT */
  460.     unsigned long ar_bspstore; /* RSE bspstore */
  461.  
  462.     unsigned long pr;  /* 64 predicate registers (1 bit each) */
  463.     unsigned long b0;  /* return pointer (bp) */
  464.     unsigned long loadrs;  /* size of dirty partition << 16 */
  465.  
  466.     unsigned long r1;  /* the gp pointer */
  467.     unsigned long r12; /* interrupted task's memory stack pointer */
  468.     unsigned long r13; /* thread pointer */
  469.  
  470.     unsigned long ar_fpsr;  /* floating point status (preserved) */
  471.     unsigned long r15;  /* scratch */
  472.  
  473.     /* The remaining registers are NOT saved for system calls.  */
  474.     unsigned long r14;  /* scratch */
  475.     unsigned long r2;  /* scratch */
  476.     unsigned long r3;  /* scratch */
  477.     unsigned long r16;  /* scratch */
  478.     unsigned long r17;  /* scratch */
  479.     unsigned long r18;  /* scratch */
  480.     unsigned long r19;  /* scratch */
  481.     unsigned long r20;  /* scratch */
  482.     unsigned long r21;  /* scratch */
  483.     unsigned long r22;  /* scratch */
  484.     unsigned long r23;  /* scratch */
  485.     unsigned long r24;  /* scratch */
  486.     unsigned long r25;  /* scratch */
  487.     unsigned long r26;  /* scratch */
  488.     unsigned long r27;  /* scratch */
  489.     unsigned long r28;  /* scratch */
  490.     unsigned long r29;  /* scratch */
  491.     unsigned long r30;  /* scratch */
  492.     unsigned long r31;  /* scratch */
  493.     unsigned long ar_ccv;  /* compare/exchange value (scratch) */
  494.  
  495.     /*
  496.      * Floating point registers that the kernel considers scratch:
  497.      */
  498.     struct ia64_fpreg f6;  /* scratch */
  499.     struct ia64_fpreg f7;  /* scratch */
  500.     struct ia64_fpreg f8;  /* scratch */
  501.     struct ia64_fpreg f9;  /* scratch */
  502.     struct ia64_fpreg f10;  /* scratch */
  503.     struct ia64_fpreg f11;  /* scratch */
  504.  
  505.     unsigned long r4;  /* preserved */
  506.     unsigned long r5;  /* preserved */
  507.     unsigned long r6;  /* preserved */
  508.     unsigned long r7;  /* preserved */
  509.     unsigned long eml_unat;    /* used for emulating instruction */
  510.     unsigned long pad0;     /* alignment pad */
  511. };
  512.  
  513. static inline struct kvm_pt_regs *vcpu_regs(struct kvm_vcpu *v)
  514. {
  515.     return (struct kvm_pt_regs *) ((unsigned long) v + IA64_STK_OFFSET) - 1;
  516. }
  517.  
  518. typedef int kvm_vmm_entry(void);
  519. typedef void kvm_tramp_entry(union context *host, union context *guest);
  520.  
  521. struct kvm_vmm_info{
  522.     struct module    *module;
  523.     kvm_vmm_entry     *vmm_entry;
  524.     kvm_tramp_entry *tramp_entry;
  525.     unsigned long     vmm_ivt;
  526. };
  527.  
  528. int kvm_highest_pending_irq(struct kvm_vcpu *vcpu);
  529. int kvm_emulate_halt(struct kvm_vcpu *vcpu);
  530. int kvm_pal_emul(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
  531. void kvm_sal_emul(struct kvm_vcpu *vcpu);
  532.  
  533. static inline void kvm_inject_nmi(struct kvm_vcpu *vcpu) {}
  534.  
  535. #endif
  536.