kvm-s390.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /*
  2. * definition for kvm 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. * Christian Borntraeger <borntraeger@de.ibm.com>
  12. * Christian Ehrhardt <ehrhardt@de.ibm.com>
  13. */
  14. #ifndef ARCH_S390_KVM_S390_H
  15. #define ARCH_S390_KVM_S390_H
  16. #include <linux/hrtimer.h>
  17. #include <linux/kvm.h>
  18. #include <linux/kvm_host.h>
  19. typedef int (*intercept_handler_t)(struct kvm_vcpu *vcpu);
  20. /* declare vfacilities extern */
  21. extern unsigned long *vfacilities;
  22. int kvm_handle_sie_intercept(struct kvm_vcpu *vcpu);
  23. /* Transactional Memory Execution related macros */
  24. #define IS_TE_ENABLED(vcpu) ((vcpu->arch.sie_block->ecb & 0x10))
  25. #define TDB_FORMAT1 1
  26. #define IS_ITDB_VALID(vcpu) ((*(char *)vcpu->arch.sie_block->itdba == TDB_FORMAT1))
  27. #define VM_EVENT(d_kvm, d_loglevel, d_string, d_args...)\
  28. do { \
  29. debug_sprintf_event(d_kvm->arch.dbf, d_loglevel, d_string "\n", \
  30. d_args); \
  31. } while (0)
  32. #define VCPU_EVENT(d_vcpu, d_loglevel, d_string, d_args...)\
  33. do { \
  34. debug_sprintf_event(d_vcpu->kvm->arch.dbf, d_loglevel, \
  35. "%02d[%016lx-%016lx]: " d_string "\n", d_vcpu->vcpu_id, \
  36. d_vcpu->arch.sie_block->gpsw.mask, d_vcpu->arch.sie_block->gpsw.addr,\
  37. d_args); \
  38. } while (0)
  39. static inline int is_vcpu_stopped(struct kvm_vcpu *vcpu)
  40. {
  41. return atomic_read(&vcpu->arch.sie_block->cpuflags) & CPUSTAT_STOPPED;
  42. }
  43. static inline int kvm_is_ucontrol(struct kvm *kvm)
  44. {
  45. #ifdef CONFIG_KVM_S390_UCONTROL
  46. if (kvm->arch.gmap)
  47. return 0;
  48. return 1;
  49. #else
  50. return 0;
  51. #endif
  52. }
  53. #define GUEST_PREFIX_SHIFT 13
  54. static inline u32 kvm_s390_get_prefix(struct kvm_vcpu *vcpu)
  55. {
  56. return vcpu->arch.sie_block->prefix << GUEST_PREFIX_SHIFT;
  57. }
  58. static inline void kvm_s390_set_prefix(struct kvm_vcpu *vcpu, u32 prefix)
  59. {
  60. vcpu->arch.sie_block->prefix = prefix >> GUEST_PREFIX_SHIFT;
  61. kvm_make_request(KVM_REQ_TLB_FLUSH, vcpu);
  62. kvm_make_request(KVM_REQ_MMU_RELOAD, vcpu);
  63. }
  64. static inline u64 kvm_s390_get_base_disp_s(struct kvm_vcpu *vcpu)
  65. {
  66. u32 base2 = vcpu->arch.sie_block->ipb >> 28;
  67. u32 disp2 = ((vcpu->arch.sie_block->ipb & 0x0fff0000) >> 16);
  68. return (base2 ? vcpu->run->s.regs.gprs[base2] : 0) + disp2;
  69. }
  70. static inline void kvm_s390_get_base_disp_sse(struct kvm_vcpu *vcpu,
  71. u64 *address1, u64 *address2)
  72. {
  73. u32 base1 = (vcpu->arch.sie_block->ipb & 0xf0000000) >> 28;
  74. u32 disp1 = (vcpu->arch.sie_block->ipb & 0x0fff0000) >> 16;
  75. u32 base2 = (vcpu->arch.sie_block->ipb & 0xf000) >> 12;
  76. u32 disp2 = vcpu->arch.sie_block->ipb & 0x0fff;
  77. *address1 = (base1 ? vcpu->run->s.regs.gprs[base1] : 0) + disp1;
  78. *address2 = (base2 ? vcpu->run->s.regs.gprs[base2] : 0) + disp2;
  79. }
  80. static inline void kvm_s390_get_regs_rre(struct kvm_vcpu *vcpu, int *r1, int *r2)
  81. {
  82. if (r1)
  83. *r1 = (vcpu->arch.sie_block->ipb & 0x00f00000) >> 20;
  84. if (r2)
  85. *r2 = (vcpu->arch.sie_block->ipb & 0x000f0000) >> 16;
  86. }
  87. static inline u64 kvm_s390_get_base_disp_rsy(struct kvm_vcpu *vcpu)
  88. {
  89. u32 base2 = vcpu->arch.sie_block->ipb >> 28;
  90. u32 disp2 = ((vcpu->arch.sie_block->ipb & 0x0fff0000) >> 16) +
  91. ((vcpu->arch.sie_block->ipb & 0xff00) << 4);
  92. /* The displacement is a 20bit _SIGNED_ value */
  93. if (disp2 & 0x80000)
  94. disp2+=0xfff00000;
  95. return (base2 ? vcpu->run->s.regs.gprs[base2] : 0) + (long)(int)disp2;
  96. }
  97. static inline u64 kvm_s390_get_base_disp_rs(struct kvm_vcpu *vcpu)
  98. {
  99. u32 base2 = vcpu->arch.sie_block->ipb >> 28;
  100. u32 disp2 = ((vcpu->arch.sie_block->ipb & 0x0fff0000) >> 16);
  101. return (base2 ? vcpu->run->s.regs.gprs[base2] : 0) + disp2;
  102. }
  103. /* Set the condition code in the guest program status word */
  104. static inline void kvm_s390_set_psw_cc(struct kvm_vcpu *vcpu, unsigned long cc)
  105. {
  106. vcpu->arch.sie_block->gpsw.mask &= ~(3UL << 44);
  107. vcpu->arch.sie_block->gpsw.mask |= cc << 44;
  108. }
  109. /* are cpu states controlled by user space */
  110. static inline int kvm_s390_user_cpu_state_ctrl(struct kvm *kvm)
  111. {
  112. return kvm->arch.user_cpu_state_ctrl != 0;
  113. }
  114. int kvm_s390_handle_wait(struct kvm_vcpu *vcpu);
  115. void kvm_s390_vcpu_wakeup(struct kvm_vcpu *vcpu);
  116. enum hrtimer_restart kvm_s390_idle_wakeup(struct hrtimer *timer);
  117. int __must_check kvm_s390_deliver_pending_interrupts(struct kvm_vcpu *vcpu);
  118. void kvm_s390_clear_local_irqs(struct kvm_vcpu *vcpu);
  119. void kvm_s390_clear_float_irqs(struct kvm *kvm);
  120. int __must_check kvm_s390_inject_vm(struct kvm *kvm,
  121. struct kvm_s390_interrupt *s390int);
  122. int __must_check kvm_s390_inject_vcpu(struct kvm_vcpu *vcpu,
  123. struct kvm_s390_interrupt *s390int);
  124. int __must_check kvm_s390_inject_program_int(struct kvm_vcpu *vcpu, u16 code);
  125. struct kvm_s390_interrupt_info *kvm_s390_get_io_int(struct kvm *kvm,
  126. u64 cr6, u64 schid);
  127. void kvm_s390_reinject_io_int(struct kvm *kvm,
  128. struct kvm_s390_interrupt_info *inti);
  129. int kvm_s390_mask_adapter(struct kvm *kvm, unsigned int id, bool masked);
  130. /* implemented in priv.c */
  131. int is_valid_psw(psw_t *psw);
  132. int kvm_s390_handle_b2(struct kvm_vcpu *vcpu);
  133. int kvm_s390_handle_e5(struct kvm_vcpu *vcpu);
  134. int kvm_s390_handle_01(struct kvm_vcpu *vcpu);
  135. int kvm_s390_handle_b9(struct kvm_vcpu *vcpu);
  136. int kvm_s390_handle_lpsw(struct kvm_vcpu *vcpu);
  137. int kvm_s390_handle_stctl(struct kvm_vcpu *vcpu);
  138. int kvm_s390_handle_lctl(struct kvm_vcpu *vcpu);
  139. int kvm_s390_handle_eb(struct kvm_vcpu *vcpu);
  140. /* implemented in sigp.c */
  141. int kvm_s390_handle_sigp(struct kvm_vcpu *vcpu);
  142. int kvm_s390_handle_sigp_pei(struct kvm_vcpu *vcpu);
  143. /* implemented in kvm-s390.c */
  144. long kvm_arch_fault_in_page(struct kvm_vcpu *vcpu, gpa_t gpa, int writable);
  145. int kvm_s390_store_status_unloaded(struct kvm_vcpu *vcpu, unsigned long addr);
  146. int kvm_s390_vcpu_store_status(struct kvm_vcpu *vcpu, unsigned long addr);
  147. void kvm_s390_vcpu_start(struct kvm_vcpu *vcpu);
  148. void kvm_s390_vcpu_stop(struct kvm_vcpu *vcpu);
  149. void s390_vcpu_block(struct kvm_vcpu *vcpu);
  150. void s390_vcpu_unblock(struct kvm_vcpu *vcpu);
  151. void exit_sie(struct kvm_vcpu *vcpu);
  152. void exit_sie_sync(struct kvm_vcpu *vcpu);
  153. int kvm_s390_vcpu_setup_cmma(struct kvm_vcpu *vcpu);
  154. void kvm_s390_vcpu_unsetup_cmma(struct kvm_vcpu *vcpu);
  155. /* is cmma enabled */
  156. bool kvm_s390_cmma_enabled(struct kvm *kvm);
  157. int test_vfacility(unsigned long nr);
  158. /* implemented in diag.c */
  159. int kvm_s390_handle_diag(struct kvm_vcpu *vcpu);
  160. /* implemented in interrupt.c */
  161. int kvm_s390_inject_prog_irq(struct kvm_vcpu *vcpu,
  162. struct kvm_s390_pgm_info *pgm_info);
  163. /**
  164. * kvm_s390_inject_prog_cond - conditionally inject a program check
  165. * @vcpu: virtual cpu
  166. * @rc: original return/error code
  167. *
  168. * This function is supposed to be used after regular guest access functions
  169. * failed, to conditionally inject a program check to a vcpu. The typical
  170. * pattern would look like
  171. *
  172. * rc = write_guest(vcpu, addr, data, len);
  173. * if (rc)
  174. * return kvm_s390_inject_prog_cond(vcpu, rc);
  175. *
  176. * A negative return code from guest access functions implies an internal error
  177. * like e.g. out of memory. In these cases no program check should be injected
  178. * to the guest.
  179. * A positive value implies that an exception happened while accessing a guest's
  180. * memory. In this case all data belonging to the corresponding program check
  181. * has been stored in vcpu->arch.pgm and can be injected with
  182. * kvm_s390_inject_prog_irq().
  183. *
  184. * Returns: - the original @rc value if @rc was negative (internal error)
  185. * - zero if @rc was already zero
  186. * - zero or error code from injecting if @rc was positive
  187. * (program check injected to @vcpu)
  188. */
  189. static inline int kvm_s390_inject_prog_cond(struct kvm_vcpu *vcpu, int rc)
  190. {
  191. if (rc <= 0)
  192. return rc;
  193. return kvm_s390_inject_prog_irq(vcpu, &vcpu->arch.pgm);
  194. }
  195. /* implemented in interrupt.c */
  196. int kvm_cpu_has_interrupt(struct kvm_vcpu *vcpu);
  197. int psw_extint_disabled(struct kvm_vcpu *vcpu);
  198. void kvm_s390_destroy_adapters(struct kvm *kvm);
  199. int kvm_s390_si_ext_call_pending(struct kvm_vcpu *vcpu);
  200. extern struct kvm_device_ops kvm_flic_ops;
  201. /* implemented in guestdbg.c */
  202. void kvm_s390_backup_guest_per_regs(struct kvm_vcpu *vcpu);
  203. void kvm_s390_restore_guest_per_regs(struct kvm_vcpu *vcpu);
  204. void kvm_s390_patch_guest_per_regs(struct kvm_vcpu *vcpu);
  205. int kvm_s390_import_bp_data(struct kvm_vcpu *vcpu,
  206. struct kvm_guest_debug *dbg);
  207. void kvm_s390_clear_bp_data(struct kvm_vcpu *vcpu);
  208. void kvm_s390_prepare_debug_exit(struct kvm_vcpu *vcpu);
  209. void kvm_s390_handle_per_event(struct kvm_vcpu *vcpu);
  210. #endif