kvm_host.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. /*
  2. * definition for kernel virtual machines on s390
  3. *
  4. * Copyright IBM Corp. 2008, 2009
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License (version 2 only)
  8. * as published by the Free Software Foundation.
  9. *
  10. * Author(s): Carsten Otte <cotte@de.ibm.com>
  11. */
  12. #ifndef ASM_KVM_HOST_H
  13. #define ASM_KVM_HOST_H
  14. #include <linux/types.h>
  15. #include <linux/hrtimer.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/kvm_types.h>
  18. #include <linux/kvm_host.h>
  19. #include <linux/kvm.h>
  20. #include <linux/seqlock.h>
  21. #include <asm/debug.h>
  22. #include <asm/cpu.h>
  23. #include <asm/fpu/api.h>
  24. #include <asm/isc.h>
  25. #define KVM_S390_BSCA_CPU_SLOTS 64
  26. #define KVM_S390_ESCA_CPU_SLOTS 248
  27. #define KVM_MAX_VCPUS 255
  28. #define KVM_USER_MEM_SLOTS 32
  29. /*
  30. * These seem to be used for allocating ->chip in the routing table,
  31. * which we don't use. 4096 is an out-of-thin-air value. If we need
  32. * to look at ->chip later on, we'll need to revisit this.
  33. */
  34. #define KVM_NR_IRQCHIPS 1
  35. #define KVM_IRQCHIP_NUM_PINS 4096
  36. #define KVM_HALT_POLL_NS_DEFAULT 80000
  37. /* s390-specific vcpu->requests bit members */
  38. #define KVM_REQ_ENABLE_IBS 8
  39. #define KVM_REQ_DISABLE_IBS 9
  40. #define KVM_REQ_ICPT_OPEREXC 10
  41. #define SIGP_CTRL_C 0x80
  42. #define SIGP_CTRL_SCN_MASK 0x3f
  43. union bsca_sigp_ctrl {
  44. __u8 value;
  45. struct {
  46. __u8 c : 1;
  47. __u8 r : 1;
  48. __u8 scn : 6;
  49. };
  50. } __packed;
  51. union esca_sigp_ctrl {
  52. __u16 value;
  53. struct {
  54. __u8 c : 1;
  55. __u8 reserved: 7;
  56. __u8 scn;
  57. };
  58. } __packed;
  59. struct esca_entry {
  60. union esca_sigp_ctrl sigp_ctrl;
  61. __u16 reserved1[3];
  62. __u64 sda;
  63. __u64 reserved2[6];
  64. } __packed;
  65. struct bsca_entry {
  66. __u8 reserved0;
  67. union bsca_sigp_ctrl sigp_ctrl;
  68. __u16 reserved[3];
  69. __u64 sda;
  70. __u64 reserved2[2];
  71. } __attribute__((packed));
  72. union ipte_control {
  73. unsigned long val;
  74. struct {
  75. unsigned long k : 1;
  76. unsigned long kh : 31;
  77. unsigned long kg : 32;
  78. };
  79. };
  80. struct bsca_block {
  81. union ipte_control ipte_control;
  82. __u64 reserved[5];
  83. __u64 mcn;
  84. __u64 reserved2;
  85. struct bsca_entry cpu[KVM_S390_BSCA_CPU_SLOTS];
  86. } __attribute__((packed));
  87. struct esca_block {
  88. union ipte_control ipte_control;
  89. __u64 reserved1[7];
  90. __u64 mcn[4];
  91. __u64 reserved2[20];
  92. struct esca_entry cpu[KVM_S390_ESCA_CPU_SLOTS];
  93. } __packed;
  94. #define CPUSTAT_STOPPED 0x80000000
  95. #define CPUSTAT_WAIT 0x10000000
  96. #define CPUSTAT_ECALL_PEND 0x08000000
  97. #define CPUSTAT_STOP_INT 0x04000000
  98. #define CPUSTAT_IO_INT 0x02000000
  99. #define CPUSTAT_EXT_INT 0x01000000
  100. #define CPUSTAT_RUNNING 0x00800000
  101. #define CPUSTAT_RETAINED 0x00400000
  102. #define CPUSTAT_TIMING_SUB 0x00020000
  103. #define CPUSTAT_SIE_SUB 0x00010000
  104. #define CPUSTAT_RRF 0x00008000
  105. #define CPUSTAT_SLSV 0x00004000
  106. #define CPUSTAT_SLSR 0x00002000
  107. #define CPUSTAT_ZARCH 0x00000800
  108. #define CPUSTAT_MCDS 0x00000100
  109. #define CPUSTAT_SM 0x00000080
  110. #define CPUSTAT_IBS 0x00000040
  111. #define CPUSTAT_GED2 0x00000010
  112. #define CPUSTAT_G 0x00000008
  113. #define CPUSTAT_GED 0x00000004
  114. #define CPUSTAT_J 0x00000002
  115. #define CPUSTAT_P 0x00000001
  116. struct kvm_s390_sie_block {
  117. atomic_t cpuflags; /* 0x0000 */
  118. __u32 : 1; /* 0x0004 */
  119. __u32 prefix : 18;
  120. __u32 : 1;
  121. __u32 ibc : 12;
  122. __u8 reserved08[4]; /* 0x0008 */
  123. #define PROG_IN_SIE (1<<0)
  124. __u32 prog0c; /* 0x000c */
  125. __u8 reserved10[16]; /* 0x0010 */
  126. #define PROG_BLOCK_SIE (1<<0)
  127. #define PROG_REQUEST (1<<1)
  128. atomic_t prog20; /* 0x0020 */
  129. __u8 reserved24[4]; /* 0x0024 */
  130. __u64 cputm; /* 0x0028 */
  131. __u64 ckc; /* 0x0030 */
  132. __u64 epoch; /* 0x0038 */
  133. __u32 svcc; /* 0x0040 */
  134. #define LCTL_CR0 0x8000
  135. #define LCTL_CR6 0x0200
  136. #define LCTL_CR9 0x0040
  137. #define LCTL_CR10 0x0020
  138. #define LCTL_CR11 0x0010
  139. #define LCTL_CR14 0x0002
  140. __u16 lctl; /* 0x0044 */
  141. __s16 icpua; /* 0x0046 */
  142. #define ICTL_OPEREXC 0x80000000
  143. #define ICTL_PINT 0x20000000
  144. #define ICTL_LPSW 0x00400000
  145. #define ICTL_STCTL 0x00040000
  146. #define ICTL_ISKE 0x00004000
  147. #define ICTL_SSKE 0x00002000
  148. #define ICTL_RRBE 0x00001000
  149. #define ICTL_TPROT 0x00000200
  150. __u32 ictl; /* 0x0048 */
  151. __u32 eca; /* 0x004c */
  152. #define ICPT_INST 0x04
  153. #define ICPT_PROGI 0x08
  154. #define ICPT_INSTPROGI 0x0C
  155. #define ICPT_EXTINT 0x14
  156. #define ICPT_VALIDITY 0x20
  157. #define ICPT_STOP 0x28
  158. #define ICPT_OPEREXC 0x2C
  159. #define ICPT_PARTEXEC 0x38
  160. #define ICPT_IOINST 0x40
  161. __u8 icptcode; /* 0x0050 */
  162. __u8 icptstatus; /* 0x0051 */
  163. __u16 ihcpu; /* 0x0052 */
  164. __u8 reserved54[2]; /* 0x0054 */
  165. __u16 ipa; /* 0x0056 */
  166. __u32 ipb; /* 0x0058 */
  167. __u32 scaoh; /* 0x005c */
  168. #define FPF_BPBC 0x20
  169. __u8 fpf; /* 0x0060 */
  170. __u8 ecb; /* 0x0061 */
  171. __u8 ecb2; /* 0x0062 */
  172. #define ECB3_AES 0x04
  173. #define ECB3_DEA 0x08
  174. __u8 ecb3; /* 0x0063 */
  175. __u32 scaol; /* 0x0064 */
  176. __u8 reserved68[4]; /* 0x0068 */
  177. __u32 todpr; /* 0x006c */
  178. __u8 reserved70[16]; /* 0x0070 */
  179. __u64 mso; /* 0x0080 */
  180. __u64 msl; /* 0x0088 */
  181. psw_t gpsw; /* 0x0090 */
  182. __u64 gg14; /* 0x00a0 */
  183. __u64 gg15; /* 0x00a8 */
  184. __u8 reservedb0[20]; /* 0x00b0 */
  185. __u16 extcpuaddr; /* 0x00c4 */
  186. __u16 eic; /* 0x00c6 */
  187. __u32 reservedc8; /* 0x00c8 */
  188. __u16 pgmilc; /* 0x00cc */
  189. __u16 iprcc; /* 0x00ce */
  190. __u32 dxc; /* 0x00d0 */
  191. __u16 mcn; /* 0x00d4 */
  192. __u8 perc; /* 0x00d6 */
  193. __u8 peratmid; /* 0x00d7 */
  194. __u64 peraddr; /* 0x00d8 */
  195. __u8 eai; /* 0x00e0 */
  196. __u8 peraid; /* 0x00e1 */
  197. __u8 oai; /* 0x00e2 */
  198. __u8 armid; /* 0x00e3 */
  199. __u8 reservede4[4]; /* 0x00e4 */
  200. __u64 tecmc; /* 0x00e8 */
  201. __u8 reservedf0[12]; /* 0x00f0 */
  202. #define CRYCB_FORMAT1 0x00000001
  203. #define CRYCB_FORMAT2 0x00000003
  204. __u32 crycbd; /* 0x00fc */
  205. __u64 gcr[16]; /* 0x0100 */
  206. __u64 gbea; /* 0x0180 */
  207. __u8 reserved188[24]; /* 0x0188 */
  208. __u32 fac; /* 0x01a0 */
  209. __u8 reserved1a4[20]; /* 0x01a4 */
  210. __u64 cbrlo; /* 0x01b8 */
  211. __u8 reserved1c0[8]; /* 0x01c0 */
  212. __u32 ecd; /* 0x01c8 */
  213. __u8 reserved1cc[18]; /* 0x01cc */
  214. __u64 pp; /* 0x01de */
  215. __u8 reserved1e6[2]; /* 0x01e6 */
  216. __u64 itdba; /* 0x01e8 */
  217. __u64 riccbd; /* 0x01f0 */
  218. __u64 gvrd; /* 0x01f8 */
  219. } __attribute__((packed));
  220. struct kvm_s390_itdb {
  221. __u8 data[256];
  222. } __packed;
  223. struct sie_page {
  224. struct kvm_s390_sie_block sie_block;
  225. __u8 reserved200[1024]; /* 0x0200 */
  226. struct kvm_s390_itdb itdb; /* 0x0600 */
  227. __u8 reserved700[2304]; /* 0x0700 */
  228. } __packed;
  229. struct kvm_vcpu_stat {
  230. u64 exit_userspace;
  231. u64 exit_null;
  232. u64 exit_external_request;
  233. u64 exit_external_interrupt;
  234. u64 exit_stop_request;
  235. u64 exit_validity;
  236. u64 exit_instruction;
  237. u64 exit_pei;
  238. u64 halt_successful_poll;
  239. u64 halt_attempted_poll;
  240. u64 halt_poll_invalid;
  241. u64 halt_wakeup;
  242. u64 instruction_lctl;
  243. u64 instruction_lctlg;
  244. u64 instruction_stctl;
  245. u64 instruction_stctg;
  246. u64 exit_program_interruption;
  247. u64 exit_instr_and_program;
  248. u64 exit_operation_exception;
  249. u64 deliver_external_call;
  250. u64 deliver_emergency_signal;
  251. u64 deliver_service_signal;
  252. u64 deliver_virtio_interrupt;
  253. u64 deliver_stop_signal;
  254. u64 deliver_prefix_signal;
  255. u64 deliver_restart_signal;
  256. u64 deliver_program_int;
  257. u64 deliver_io_int;
  258. u64 exit_wait_state;
  259. u64 instruction_pfmf;
  260. u64 instruction_stidp;
  261. u64 instruction_spx;
  262. u64 instruction_stpx;
  263. u64 instruction_stap;
  264. u64 instruction_storage_key;
  265. u64 instruction_ipte_interlock;
  266. u64 instruction_stsch;
  267. u64 instruction_chsc;
  268. u64 instruction_stsi;
  269. u64 instruction_stfl;
  270. u64 instruction_tprot;
  271. u64 instruction_sie;
  272. u64 instruction_essa;
  273. u64 instruction_sthyi;
  274. u64 instruction_sigp_sense;
  275. u64 instruction_sigp_sense_running;
  276. u64 instruction_sigp_external_call;
  277. u64 instruction_sigp_emergency;
  278. u64 instruction_sigp_cond_emergency;
  279. u64 instruction_sigp_start;
  280. u64 instruction_sigp_stop;
  281. u64 instruction_sigp_stop_store_status;
  282. u64 instruction_sigp_store_status;
  283. u64 instruction_sigp_store_adtl_status;
  284. u64 instruction_sigp_arch;
  285. u64 instruction_sigp_prefix;
  286. u64 instruction_sigp_restart;
  287. u64 instruction_sigp_init_cpu_reset;
  288. u64 instruction_sigp_cpu_reset;
  289. u64 instruction_sigp_unknown;
  290. u64 diagnose_10;
  291. u64 diagnose_44;
  292. u64 diagnose_9c;
  293. u64 diagnose_258;
  294. u64 diagnose_308;
  295. u64 diagnose_500;
  296. };
  297. #define PGM_OPERATION 0x01
  298. #define PGM_PRIVILEGED_OP 0x02
  299. #define PGM_EXECUTE 0x03
  300. #define PGM_PROTECTION 0x04
  301. #define PGM_ADDRESSING 0x05
  302. #define PGM_SPECIFICATION 0x06
  303. #define PGM_DATA 0x07
  304. #define PGM_FIXED_POINT_OVERFLOW 0x08
  305. #define PGM_FIXED_POINT_DIVIDE 0x09
  306. #define PGM_DECIMAL_OVERFLOW 0x0a
  307. #define PGM_DECIMAL_DIVIDE 0x0b
  308. #define PGM_HFP_EXPONENT_OVERFLOW 0x0c
  309. #define PGM_HFP_EXPONENT_UNDERFLOW 0x0d
  310. #define PGM_HFP_SIGNIFICANCE 0x0e
  311. #define PGM_HFP_DIVIDE 0x0f
  312. #define PGM_SEGMENT_TRANSLATION 0x10
  313. #define PGM_PAGE_TRANSLATION 0x11
  314. #define PGM_TRANSLATION_SPEC 0x12
  315. #define PGM_SPECIAL_OPERATION 0x13
  316. #define PGM_OPERAND 0x15
  317. #define PGM_TRACE_TABEL 0x16
  318. #define PGM_VECTOR_PROCESSING 0x1b
  319. #define PGM_SPACE_SWITCH 0x1c
  320. #define PGM_HFP_SQUARE_ROOT 0x1d
  321. #define PGM_PC_TRANSLATION_SPEC 0x1f
  322. #define PGM_AFX_TRANSLATION 0x20
  323. #define PGM_ASX_TRANSLATION 0x21
  324. #define PGM_LX_TRANSLATION 0x22
  325. #define PGM_EX_TRANSLATION 0x23
  326. #define PGM_PRIMARY_AUTHORITY 0x24
  327. #define PGM_SECONDARY_AUTHORITY 0x25
  328. #define PGM_LFX_TRANSLATION 0x26
  329. #define PGM_LSX_TRANSLATION 0x27
  330. #define PGM_ALET_SPECIFICATION 0x28
  331. #define PGM_ALEN_TRANSLATION 0x29
  332. #define PGM_ALE_SEQUENCE 0x2a
  333. #define PGM_ASTE_VALIDITY 0x2b
  334. #define PGM_ASTE_SEQUENCE 0x2c
  335. #define PGM_EXTENDED_AUTHORITY 0x2d
  336. #define PGM_LSTE_SEQUENCE 0x2e
  337. #define PGM_ASTE_INSTANCE 0x2f
  338. #define PGM_STACK_FULL 0x30
  339. #define PGM_STACK_EMPTY 0x31
  340. #define PGM_STACK_SPECIFICATION 0x32
  341. #define PGM_STACK_TYPE 0x33
  342. #define PGM_STACK_OPERATION 0x34
  343. #define PGM_ASCE_TYPE 0x38
  344. #define PGM_REGION_FIRST_TRANS 0x39
  345. #define PGM_REGION_SECOND_TRANS 0x3a
  346. #define PGM_REGION_THIRD_TRANS 0x3b
  347. #define PGM_MONITOR 0x40
  348. #define PGM_PER 0x80
  349. #define PGM_CRYPTO_OPERATION 0x119
  350. /* irq types in order of priority */
  351. enum irq_types {
  352. IRQ_PEND_MCHK_EX = 0,
  353. IRQ_PEND_SVC,
  354. IRQ_PEND_PROG,
  355. IRQ_PEND_MCHK_REP,
  356. IRQ_PEND_EXT_IRQ_KEY,
  357. IRQ_PEND_EXT_MALFUNC,
  358. IRQ_PEND_EXT_EMERGENCY,
  359. IRQ_PEND_EXT_EXTERNAL,
  360. IRQ_PEND_EXT_CLOCK_COMP,
  361. IRQ_PEND_EXT_CPU_TIMER,
  362. IRQ_PEND_EXT_TIMING,
  363. IRQ_PEND_EXT_SERVICE,
  364. IRQ_PEND_EXT_HOST,
  365. IRQ_PEND_PFAULT_INIT,
  366. IRQ_PEND_PFAULT_DONE,
  367. IRQ_PEND_VIRTIO,
  368. IRQ_PEND_IO_ISC_0,
  369. IRQ_PEND_IO_ISC_1,
  370. IRQ_PEND_IO_ISC_2,
  371. IRQ_PEND_IO_ISC_3,
  372. IRQ_PEND_IO_ISC_4,
  373. IRQ_PEND_IO_ISC_5,
  374. IRQ_PEND_IO_ISC_6,
  375. IRQ_PEND_IO_ISC_7,
  376. IRQ_PEND_SIGP_STOP,
  377. IRQ_PEND_RESTART,
  378. IRQ_PEND_SET_PREFIX,
  379. IRQ_PEND_COUNT
  380. };
  381. /* We have 2M for virtio device descriptor pages. Smallest amount of
  382. * memory per page is 24 bytes (1 queue), so (2048*1024) / 24 = 87381
  383. */
  384. #define KVM_S390_MAX_VIRTIO_IRQS 87381
  385. /*
  386. * Repressible (non-floating) machine check interrupts
  387. * subclass bits in MCIC
  388. */
  389. #define MCHK_EXTD_BIT 58
  390. #define MCHK_DEGR_BIT 56
  391. #define MCHK_WARN_BIT 55
  392. #define MCHK_REP_MASK ((1UL << MCHK_DEGR_BIT) | \
  393. (1UL << MCHK_EXTD_BIT) | \
  394. (1UL << MCHK_WARN_BIT))
  395. /* Exigent machine check interrupts subclass bits in MCIC */
  396. #define MCHK_SD_BIT 63
  397. #define MCHK_PD_BIT 62
  398. #define MCHK_EX_MASK ((1UL << MCHK_SD_BIT) | (1UL << MCHK_PD_BIT))
  399. #define IRQ_PEND_EXT_MASK ((1UL << IRQ_PEND_EXT_IRQ_KEY) | \
  400. (1UL << IRQ_PEND_EXT_CLOCK_COMP) | \
  401. (1UL << IRQ_PEND_EXT_CPU_TIMER) | \
  402. (1UL << IRQ_PEND_EXT_MALFUNC) | \
  403. (1UL << IRQ_PEND_EXT_EMERGENCY) | \
  404. (1UL << IRQ_PEND_EXT_EXTERNAL) | \
  405. (1UL << IRQ_PEND_EXT_TIMING) | \
  406. (1UL << IRQ_PEND_EXT_HOST) | \
  407. (1UL << IRQ_PEND_EXT_SERVICE) | \
  408. (1UL << IRQ_PEND_VIRTIO) | \
  409. (1UL << IRQ_PEND_PFAULT_INIT) | \
  410. (1UL << IRQ_PEND_PFAULT_DONE))
  411. #define IRQ_PEND_IO_MASK ((1UL << IRQ_PEND_IO_ISC_0) | \
  412. (1UL << IRQ_PEND_IO_ISC_1) | \
  413. (1UL << IRQ_PEND_IO_ISC_2) | \
  414. (1UL << IRQ_PEND_IO_ISC_3) | \
  415. (1UL << IRQ_PEND_IO_ISC_4) | \
  416. (1UL << IRQ_PEND_IO_ISC_5) | \
  417. (1UL << IRQ_PEND_IO_ISC_6) | \
  418. (1UL << IRQ_PEND_IO_ISC_7))
  419. #define IRQ_PEND_MCHK_MASK ((1UL << IRQ_PEND_MCHK_REP) | \
  420. (1UL << IRQ_PEND_MCHK_EX))
  421. struct kvm_s390_interrupt_info {
  422. struct list_head list;
  423. u64 type;
  424. union {
  425. struct kvm_s390_io_info io;
  426. struct kvm_s390_ext_info ext;
  427. struct kvm_s390_pgm_info pgm;
  428. struct kvm_s390_emerg_info emerg;
  429. struct kvm_s390_extcall_info extcall;
  430. struct kvm_s390_prefix_info prefix;
  431. struct kvm_s390_stop_info stop;
  432. struct kvm_s390_mchk_info mchk;
  433. };
  434. };
  435. struct kvm_s390_irq_payload {
  436. struct kvm_s390_io_info io;
  437. struct kvm_s390_ext_info ext;
  438. struct kvm_s390_pgm_info pgm;
  439. struct kvm_s390_emerg_info emerg;
  440. struct kvm_s390_extcall_info extcall;
  441. struct kvm_s390_prefix_info prefix;
  442. struct kvm_s390_stop_info stop;
  443. struct kvm_s390_mchk_info mchk;
  444. };
  445. struct kvm_s390_local_interrupt {
  446. spinlock_t lock;
  447. struct kvm_s390_float_interrupt *float_int;
  448. struct swait_queue_head *wq;
  449. atomic_t *cpuflags;
  450. DECLARE_BITMAP(sigp_emerg_pending, KVM_MAX_VCPUS);
  451. struct kvm_s390_irq_payload irq;
  452. unsigned long pending_irqs;
  453. };
  454. #define FIRQ_LIST_IO_ISC_0 0
  455. #define FIRQ_LIST_IO_ISC_1 1
  456. #define FIRQ_LIST_IO_ISC_2 2
  457. #define FIRQ_LIST_IO_ISC_3 3
  458. #define FIRQ_LIST_IO_ISC_4 4
  459. #define FIRQ_LIST_IO_ISC_5 5
  460. #define FIRQ_LIST_IO_ISC_6 6
  461. #define FIRQ_LIST_IO_ISC_7 7
  462. #define FIRQ_LIST_PFAULT 8
  463. #define FIRQ_LIST_VIRTIO 9
  464. #define FIRQ_LIST_COUNT 10
  465. #define FIRQ_CNTR_IO 0
  466. #define FIRQ_CNTR_SERVICE 1
  467. #define FIRQ_CNTR_VIRTIO 2
  468. #define FIRQ_CNTR_PFAULT 3
  469. #define FIRQ_MAX_COUNT 4
  470. struct kvm_s390_float_interrupt {
  471. unsigned long pending_irqs;
  472. spinlock_t lock;
  473. struct list_head lists[FIRQ_LIST_COUNT];
  474. int counters[FIRQ_MAX_COUNT];
  475. struct kvm_s390_mchk_info mchk;
  476. struct kvm_s390_ext_info srv_signal;
  477. int next_rr_cpu;
  478. unsigned long idle_mask[BITS_TO_LONGS(KVM_MAX_VCPUS)];
  479. };
  480. struct kvm_hw_wp_info_arch {
  481. unsigned long addr;
  482. unsigned long phys_addr;
  483. int len;
  484. char *old_data;
  485. };
  486. struct kvm_hw_bp_info_arch {
  487. unsigned long addr;
  488. int len;
  489. };
  490. /*
  491. * Only the upper 16 bits of kvm_guest_debug->control are arch specific.
  492. * Further KVM_GUESTDBG flags which an be used from userspace can be found in
  493. * arch/s390/include/uapi/asm/kvm.h
  494. */
  495. #define KVM_GUESTDBG_EXIT_PENDING 0x10000000
  496. #define guestdbg_enabled(vcpu) \
  497. (vcpu->guest_debug & KVM_GUESTDBG_ENABLE)
  498. #define guestdbg_sstep_enabled(vcpu) \
  499. (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP)
  500. #define guestdbg_hw_bp_enabled(vcpu) \
  501. (vcpu->guest_debug & KVM_GUESTDBG_USE_HW_BP)
  502. #define guestdbg_exit_pending(vcpu) (guestdbg_enabled(vcpu) && \
  503. (vcpu->guest_debug & KVM_GUESTDBG_EXIT_PENDING))
  504. struct kvm_guestdbg_info_arch {
  505. unsigned long cr0;
  506. unsigned long cr9;
  507. unsigned long cr10;
  508. unsigned long cr11;
  509. struct kvm_hw_bp_info_arch *hw_bp_info;
  510. struct kvm_hw_wp_info_arch *hw_wp_info;
  511. int nr_hw_bp;
  512. int nr_hw_wp;
  513. unsigned long last_bp;
  514. };
  515. struct kvm_vcpu_arch {
  516. struct kvm_s390_sie_block *sie_block;
  517. /* if vsie is active, currently executed shadow sie control block */
  518. struct kvm_s390_sie_block *vsie_block;
  519. unsigned int host_acrs[NUM_ACRS];
  520. struct fpu host_fpregs;
  521. struct kvm_s390_local_interrupt local_int;
  522. struct hrtimer ckc_timer;
  523. struct kvm_s390_pgm_info pgm;
  524. struct gmap *gmap;
  525. /* backup location for the currently enabled gmap when scheduled out */
  526. struct gmap *enabled_gmap;
  527. struct kvm_guestdbg_info_arch guestdbg;
  528. unsigned long pfault_token;
  529. unsigned long pfault_select;
  530. unsigned long pfault_compare;
  531. bool cputm_enabled;
  532. /*
  533. * The seqcount protects updates to cputm_start and sie_block.cputm,
  534. * this way we can have non-blocking reads with consistent values.
  535. * Only the owning VCPU thread (vcpu->cpu) is allowed to change these
  536. * values and to start/stop/enable/disable cpu timer accounting.
  537. */
  538. seqcount_t cputm_seqcount;
  539. __u64 cputm_start;
  540. };
  541. struct kvm_vm_stat {
  542. ulong remote_tlb_flush;
  543. };
  544. struct kvm_arch_memory_slot {
  545. };
  546. struct s390_map_info {
  547. struct list_head list;
  548. __u64 guest_addr;
  549. __u64 addr;
  550. struct page *page;
  551. };
  552. struct s390_io_adapter {
  553. unsigned int id;
  554. int isc;
  555. bool maskable;
  556. bool masked;
  557. bool swap;
  558. struct rw_semaphore maps_lock;
  559. struct list_head maps;
  560. atomic_t nr_maps;
  561. };
  562. #define MAX_S390_IO_ADAPTERS ((MAX_ISC + 1) * 8)
  563. #define MAX_S390_ADAPTER_MAPS 256
  564. /* maximum size of facilities and facility mask is 2k bytes */
  565. #define S390_ARCH_FAC_LIST_SIZE_BYTE (1<<11)
  566. #define S390_ARCH_FAC_LIST_SIZE_U64 \
  567. (S390_ARCH_FAC_LIST_SIZE_BYTE / sizeof(u64))
  568. #define S390_ARCH_FAC_MASK_SIZE_BYTE S390_ARCH_FAC_LIST_SIZE_BYTE
  569. #define S390_ARCH_FAC_MASK_SIZE_U64 \
  570. (S390_ARCH_FAC_MASK_SIZE_BYTE / sizeof(u64))
  571. struct kvm_s390_cpu_model {
  572. /* facility mask supported by kvm & hosting machine */
  573. __u64 fac_mask[S390_ARCH_FAC_LIST_SIZE_U64];
  574. /* facility list requested by guest (in dma page) */
  575. __u64 *fac_list;
  576. u64 cpuid;
  577. unsigned short ibc;
  578. };
  579. struct kvm_s390_crypto {
  580. struct kvm_s390_crypto_cb *crycb;
  581. __u32 crycbd;
  582. __u8 aes_kw;
  583. __u8 dea_kw;
  584. };
  585. struct kvm_s390_crypto_cb {
  586. __u8 reserved00[72]; /* 0x0000 */
  587. __u8 dea_wrapping_key_mask[24]; /* 0x0048 */
  588. __u8 aes_wrapping_key_mask[32]; /* 0x0060 */
  589. __u8 reserved80[128]; /* 0x0080 */
  590. };
  591. /*
  592. * sie_page2 has to be allocated as DMA because fac_list and crycb need
  593. * 31bit addresses in the sie control block.
  594. */
  595. struct sie_page2 {
  596. __u64 fac_list[S390_ARCH_FAC_LIST_SIZE_U64]; /* 0x0000 */
  597. struct kvm_s390_crypto_cb crycb; /* 0x0800 */
  598. u8 reserved900[0x1000 - 0x900]; /* 0x0900 */
  599. } __packed;
  600. struct kvm_s390_vsie {
  601. struct mutex mutex;
  602. struct radix_tree_root addr_to_page;
  603. int page_count;
  604. int next;
  605. struct page *pages[KVM_MAX_VCPUS];
  606. };
  607. struct kvm_arch{
  608. void *sca;
  609. int use_esca;
  610. rwlock_t sca_lock;
  611. debug_info_t *dbf;
  612. struct kvm_s390_float_interrupt float_int;
  613. struct kvm_device *flic;
  614. struct gmap *gmap;
  615. unsigned long mem_limit;
  616. int css_support;
  617. int use_irqchip;
  618. int use_cmma;
  619. int user_cpu_state_ctrl;
  620. int user_sigp;
  621. int user_stsi;
  622. int user_instr0;
  623. struct s390_io_adapter *adapters[MAX_S390_IO_ADAPTERS];
  624. wait_queue_head_t ipte_wq;
  625. int ipte_lock_count;
  626. struct mutex ipte_mutex;
  627. struct ratelimit_state sthyi_limit;
  628. spinlock_t start_stop_lock;
  629. struct sie_page2 *sie_page2;
  630. struct kvm_s390_cpu_model model;
  631. struct kvm_s390_crypto crypto;
  632. struct kvm_s390_vsie vsie;
  633. u64 epoch;
  634. /* subset of available cpu features enabled by user space */
  635. DECLARE_BITMAP(cpu_feat, KVM_S390_VM_CPU_FEAT_NR_BITS);
  636. };
  637. #define KVM_HVA_ERR_BAD (-1UL)
  638. #define KVM_HVA_ERR_RO_BAD (-2UL)
  639. static inline bool kvm_is_error_hva(unsigned long addr)
  640. {
  641. return IS_ERR_VALUE(addr);
  642. }
  643. #define ASYNC_PF_PER_VCPU 64
  644. struct kvm_arch_async_pf {
  645. unsigned long pfault_token;
  646. };
  647. bool kvm_arch_can_inject_async_page_present(struct kvm_vcpu *vcpu);
  648. void kvm_arch_async_page_ready(struct kvm_vcpu *vcpu,
  649. struct kvm_async_pf *work);
  650. void kvm_arch_async_page_not_present(struct kvm_vcpu *vcpu,
  651. struct kvm_async_pf *work);
  652. void kvm_arch_async_page_present(struct kvm_vcpu *vcpu,
  653. struct kvm_async_pf *work);
  654. extern int sie64a(struct kvm_s390_sie_block *, u64 *);
  655. extern char sie_exit;
  656. static inline void kvm_arch_hardware_disable(void) {}
  657. static inline void kvm_arch_check_processor_compat(void *rtn) {}
  658. static inline void kvm_arch_sync_events(struct kvm *kvm) {}
  659. static inline void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu) {}
  660. static inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {}
  661. static inline void kvm_arch_free_memslot(struct kvm *kvm,
  662. struct kvm_memory_slot *free, struct kvm_memory_slot *dont) {}
  663. static inline void kvm_arch_memslots_updated(struct kvm *kvm, struct kvm_memslots *slots) {}
  664. static inline void kvm_arch_flush_shadow_all(struct kvm *kvm) {}
  665. static inline void kvm_arch_flush_shadow_memslot(struct kvm *kvm,
  666. struct kvm_memory_slot *slot) {}
  667. static inline void kvm_arch_vcpu_blocking(struct kvm_vcpu *vcpu) {}
  668. static inline void kvm_arch_vcpu_unblocking(struct kvm_vcpu *vcpu) {}
  669. void kvm_arch_vcpu_block_finish(struct kvm_vcpu *vcpu);
  670. #endif