definitionOfLeakageHazard.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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. #ifndef __ASM_KVM_HOST_H
  23. #define __ASM_KVM_HOST_H
  24. #define KVM_MEMORY_SLOTS 32
  25. /* memory slots that does not exposed to userspace */
  26. #define KVM_PRIVATE_MEM_SLOTS 4
  27. #define KVM_COALESCED_MMIO_PAGE_OFFSET 1
  28. /* define exit reasons from vmm to kvm*/
  29. #define EXIT_REASON_VM_PANIC 0
  30. #define EXIT_REASON_MMIO_INSTRUCTION 1
  31. #define EXIT_REASON_PAL_CALL 2
  32. #define EXIT_REASON_SAL_CALL 3
  33. #define EXIT_REASON_SWITCH_RR6 4
  34. #define EXIT_REASON_VM_DESTROY 5
  35. #define EXIT_REASON_EXTERNAL_INTERRUPT 6
  36. #define EXIT_REASON_IPI 7
  37. #define EXIT_REASON_PTC_G 8
  38. #define EXIT_REASON_DEBUG 20
  39. /*Define vmm address space and vm data space.*/
  40. #define KVM_VMM_SIZE (__IA64_UL_CONST(16)<<20)
  41. #define KVM_VMM_SHIFT 24
  42. #define KVM_VMM_BASE 0xD000000000000000
  43. #define VMM_SIZE (__IA64_UL_CONST(8)<<20)
  44. /*
  45. * Define vm_buffer, used by PAL Services, base address.
  46. * Note: vm_buffer is in the VMM-BLOCK, the size must be < 8M
  47. */
  48. #define KVM_VM_BUFFER_BASE (KVM_VMM_BASE + VMM_SIZE)
  49. #define KVM_VM_BUFFER_SIZE (__IA64_UL_CONST(8)<<20)
  50. /*
  51. * kvm guest's data area looks as follow:
  52. *
  53. * +----------------------+ ------- KVM_VM_DATA_SIZE
  54. * | vcpu[n]'s data | | ___________________KVM_STK_OFFSET
  55. * | | | / |
  56. * | .......... | | /vcpu's struct&stack |
  57. * | .......... | | /---------------------|---- 0
  58. * | vcpu[5]'s data | | / vpd |
  59. * | vcpu[4]'s data | |/-----------------------|
  60. * | vcpu[3]'s data | / vtlb |
  61. * | vcpu[2]'s data | /|------------------------|
  62. * | vcpu[1]'s data |/ | vhpt |
  63. * | vcpu[0]'s data |____________________________|
  64. * +----------------------+ |
  65. * | memory dirty log | |
  66. * +----------------------+ |
  67. * | vm's data struct | |
  68. * +----------------------+ |
  69. * | | |
  70. * | | |
  71. * | | |
  72. * | | |
  73. * | | |
  74. * | | |
  75. * | | |
  76. * | vm's p2m table | |
  77. * | | |
  78. * | | |
  79. * | | | |
  80. * vm's data->| | | |
  81. * +----------------------+ ------- 0
  82. * To support large memory, needs to increase the size of p2m.
  83. * To support more vcpus, needs to ensure it has enough space to
  84. * hold vcpus' data.
  85. */
  86. #define KVM_VM_DATA_SHIFT 26
  87. #define KVM_VM_DATA_SIZE (__IA64_UL_CONST(1) << KVM_VM_DATA_SHIFT)
  88. #define KVM_VM_DATA_BASE (KVM_VMM_BASE + KVM_VM_DATA_SIZE)
  89. #define KVM_P2M_BASE KVM_VM_DATA_BASE
  90. #define KVM_P2M_SIZE (__IA64_UL_CONST(24) << 20)
  91. #define VHPT_SHIFT 16
  92. #define VHPT_SIZE (__IA64_UL_CONST(1) << VHPT_SHIFT)
  93. #define VHPT_NUM_ENTRIES (__IA64_UL_CONST(1) << (VHPT_SHIFT-5))
  94. #define VTLB_SHIFT 16
  95. #define VTLB_SIZE (__IA64_UL_CONST(1) << VTLB_SHIFT)
  96. #define VTLB_NUM_ENTRIES (1UL << (VHPT_SHIFT-5))
  97. #define VPD_SHIFT 16
  98. #define VPD_SIZE (__IA64_UL_CONST(1) << VPD_SHIFT)
  99. #define VCPU_STRUCT_SHIFT 16
  100. #define VCPU_STRUCT_SIZE (__IA64_UL_CONST(1) << VCPU_STRUCT_SHIFT)
  101. /*
  102. * This must match KVM_IA64_VCPU_STACK_{SHIFT,SIZE} arch/ia64/include/asm/kvm.h
  103. */
  104. #define KVM_STK_SHIFT 16
  105. #define KVM_STK_OFFSET (__IA64_UL_CONST(1)<< KVM_STK_SHIFT)
  106. #define KVM_VM_STRUCT_SHIFT 19
  107. #define KVM_VM_STRUCT_SIZE (__IA64_UL_CONST(1) << KVM_VM_STRUCT_SHIFT)
  108. #define KVM_MEM_DIRY_LOG_SHIFT 19
  109. #define KVM_MEM_DIRTY_LOG_SIZE (__IA64_UL_CONST(1) << KVM_MEM_DIRY_LOG_SHIFT)
  110. #ifndef __ASSEMBLY__
  111. /*Define the max vcpus and memory for Guests.*/
  112. #define KVM_MAX_VCPUS (KVM_VM_DATA_SIZE - KVM_P2M_SIZE - KVM_VM_STRUCT_SIZE -\
  113. KVM_MEM_DIRTY_LOG_SIZE) / sizeof(struct kvm_vcpu_data)
  114. #define KVM_MAX_MEM_SIZE (KVM_P2M_SIZE >> 3 << PAGE_SHIFT)
  115. #define VMM_LOG_LEN 256
  116. #include <linux/types.h>
  117. #include <linux/mm.h>
  118. #include <linux/kvm.h>
  119. #include <linux/kvm_para.h>
  120. #include <linux/kvm_types.h>
  121. #include <asm/pal.h>
  122. #include <asm/sal.h>
  123. #include <asm/page.h>
  124. struct kvm_vcpu_data {
  125. char vcpu_vhpt[VHPT_SIZE];
  126. char vcpu_vtlb[VTLB_SIZE];
  127. char vcpu_vpd[VPD_SIZE];
  128. char vcpu_struct[VCPU_STRUCT_SIZE];
  129. };
  130. struct kvm_vm_data {
  131. char kvm_p2m[KVM_P2M_SIZE];
  132. char kvm_vm_struct[KVM_VM_STRUCT_SIZE];
  133. char kvm_mem_dirty_log[KVM_MEM_DIRTY_LOG_SIZE];
  134. struct kvm_vcpu_data vcpu_data[KVM_MAX_VCPUS];
  135. };
  136. #define VCPU_BASE(n) (KVM_VM_DATA_BASE + \
  137. offsetof(struct kvm_vm_data, vcpu_data[n]))
  138. #define KVM_VM_BASE (KVM_VM_DATA_BASE + \
  139. offsetof(struct kvm_vm_data, kvm_vm_struct))
  140. #define KVM_MEM_DIRTY_LOG_BASE KVM_VM_DATA_BASE + \
  141. offsetof(struct kvm_vm_data, kvm_mem_dirty_log)
  142. #define VHPT_BASE(n) (VCPU_BASE(n) + offsetof(struct kvm_vcpu_data, vcpu_vhpt))
  143. #define VTLB_BASE(n) (VCPU_BASE(n) + offsetof(struct kvm_vcpu_data, vcpu_vtlb))
  144. #define VPD_BASE(n) (VCPU_BASE(n) + offsetof(struct kvm_vcpu_data, vcpu_vpd))
  145. #define VCPU_STRUCT_BASE(n) (VCPU_BASE(n) + \
  146. offsetof(struct kvm_vcpu_data, vcpu_struct))
  147. /*IO section definitions*/
  148. #define IOREQ_READ 1
  149. #define IOREQ_WRITE 0
  150. #define STATE_IOREQ_NONE 0
  151. #define STATE_IOREQ_READY 1
  152. #define STATE_IOREQ_INPROCESS 2
  153. #define STATE_IORESP_READY 3
  154. /*Guest Physical address layout.*/
  155. #define GPFN_MEM (0UL << 60) /* Guest pfn is normal mem */
  156. #define GPFN_FRAME_BUFFER (1UL << 60) /* VGA framebuffer */
  157. #define GPFN_LOW_MMIO (2UL << 60) /* Low MMIO range */
  158. #define GPFN_PIB (3UL << 60) /* PIB base */
  159. #define GPFN_IOSAPIC (4UL << 60) /* IOSAPIC base */
  160. #define GPFN_LEGACY_IO (5UL << 60) /* Legacy I/O base */
  161. #define GPFN_GFW (6UL << 60) /* Guest Firmware */
  162. #define GPFN_PHYS_MMIO (7UL << 60) /* Directed MMIO Range */
  163. #define GPFN_IO_MASK (7UL << 60) /* Guest pfn is I/O type */
  164. #define GPFN_INV_MASK (1UL << 63) /* Guest pfn is invalid */
  165. #define INVALID_MFN (~0UL)
  166. #define MEM_G (1UL << 30)
  167. #define MEM_M (1UL << 20)
  168. #define MMIO_START (3 * MEM_G)
  169. #define MMIO_SIZE (512 * MEM_M)
  170. #define VGA_IO_START 0xA0000UL
  171. #define VGA_IO_SIZE 0x20000
  172. #define LEGACY_IO_START (MMIO_START + MMIO_SIZE)
  173. #define LEGACY_IO_SIZE (64 * MEM_M)
  174. #define IO_SAPIC_START 0xfec00000UL
  175. #define IO_SAPIC_SIZE 0x100000
  176. #define PIB_START 0xfee00000UL
  177. #define PIB_SIZE 0x200000
  178. #define GFW_START (4 * MEM_G - 16 * MEM_M)
  179. #define GFW_SIZE (16 * MEM_M)
  180. /*Deliver mode, defined for ioapic.c*/
  181. #define dest_Fixed IOSAPIC_FIXED
  182. #define dest_LowestPrio IOSAPIC_LOWEST_PRIORITY
  183. #define NMI_VECTOR 2
  184. #define ExtINT_VECTOR 0
  185. #define NULL_VECTOR (-1)
  186. #define IA64_SPURIOUS_INT_VECTOR 0x0f
  187. #define VCPU_LID(v) (((u64)(v)->vcpu_id) << 24)
  188. /*
  189. *Delivery mode
  190. */
  191. #define SAPIC_DELIV_SHIFT 8
  192. #define SAPIC_FIXED 0x0
  193. #define SAPIC_LOWEST_PRIORITY 0x1
  194. #define SAPIC_PMI 0x2
  195. #define SAPIC_NMI 0x4
  196. #define SAPIC_INIT 0x5
  197. #define SAPIC_EXTINT 0x7
  198. /*
  199. * vcpu->requests bit members for arch
  200. */
  201. #define KVM_REQ_PTC_G 32
  202. #define KVM_REQ_RESUME 33
  203. #define KVM_HPAGE_GFN_SHIFT(x) 0
  204. #define KVM_NR_PAGE_SIZES 1
  205. #define KVM_PAGES_PER_HPAGE(x) 1
  206. struct kvm;
  207. struct kvm_vcpu;
  208. struct kvm_mmio_req {
  209. uint64_t addr; /* physical address */
  210. uint64_t size; /* size in bytes */
  211. uint64_t data; /* data (or paddr of data) */
  212. uint8_t state:4;
  213. uint8_t dir:1; /* 1=read, 0=write */
  214. };
  215. /*Pal data struct */
  216. struct kvm_pal_call{
  217. /*In area*/
  218. uint64_t gr28;
  219. uint64_t gr29;
  220. uint64_t gr30;
  221. uint64_t gr31;
  222. /*Out area*/
  223. struct ia64_pal_retval ret;
  224. };
  225. /* Sal data structure */
  226. struct kvm_sal_call{
  227. /*In area*/
  228. uint64_t in0;
  229. uint64_t in1;
  230. uint64_t in2;
  231. uint64_t in3;
  232. uint64_t in4;
  233. uint64_t in5;
  234. uint64_t in6;
  235. uint64_t in7;
  236. struct sal_ret_values ret;
  237. };
  238. /*Guest change rr6*/
  239. struct kvm_switch_rr6 {
  240. uint64_t old_rr;
  241. uint64_t new_rr;
  242. };
  243. union ia64_ipi_a{
  244. unsigned long val;
  245. struct {
  246. unsigned long rv : 3;
  247. unsigned long ir : 1;
  248. unsigned long eid : 8;
  249. unsigned long id : 8;
  250. unsigned long ib_base : 44;
  251. };
  252. };
  253. union ia64_ipi_d {
  254. unsigned long val;
  255. struct {
  256. unsigned long vector : 8;
  257. unsigned long dm : 3;
  258. unsigned long ig : 53;