kvm-s390.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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 __cpu_is_stopped(struct kvm_vcpu *vcpu)
  40. {
  41. return atomic_read(&vcpu->arch.sie_block->cpuflags) & CPUSTAT_STOP_INT;
  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. vcpu->arch.sie_block->ihcpu = 0xffff;
  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. int kvm_s390_handle_wait(struct kvm_vcpu *vcpu);
  110. enum hrtimer_restart kvm_s390_idle_wakeup(struct hrtimer *timer);
  111. void kvm_s390_tasklet(unsigned long parm);
  112. void kvm_s390_deliver_pending_interrupts(struct kvm_vcpu *vcpu);
  113. void kvm_s390_deliver_pending_machine_checks(struct kvm_vcpu *vcpu);
  114. void kvm_s390_clear_local_irqs(struct kvm_vcpu *vcpu);
  115. void kvm_s390_clear_float_irqs(struct kvm *kvm);
  116. int __must_check kvm_s390_inject_vm(struct kvm *kvm,
  117. struct kvm_s390_interrupt *s390int);
  118. int __must_check kvm_s390_inject_vcpu(struct kvm_vcpu *vcpu,
  119. struct kvm_s390_interrupt *s390int);
  120. int __must_check kvm_s390_inject_program_int(struct kvm_vcpu *vcpu, u16 code);
  121. struct kvm_s390_interrupt_info *kvm_s390_get_io_int(struct kvm *kvm,
  122. u64 cr6, u64 schid);
  123. void kvm_s390_reinject_io_int(struct kvm *kvm,
  124. struct kvm_s390_interrupt_info *inti);
  125. int kvm_s390_mask_adapter(struct kvm *kvm, unsigned int id, bool masked);
  126. /* implemented in priv.c */
  127. int is_valid_psw(psw_t *psw);
  128. int kvm_s390_handle_b2(struct kvm_vcpu *vcpu);
  129. int kvm_s390_handle_e5(struct kvm_vcpu *vcpu);
  130. int kvm_s390_handle_01(struct kvm_vcpu *vcpu);
  131. int kvm_s390_handle_b9(struct kvm_vcpu *vcpu);
  132. int kvm_s390_handle_lpsw(struct kvm_vcpu *vcpu);
  133. int kvm_s390_handle_stctl(struct kvm_vcpu *vcpu);
  134. int kvm_s390_handle_lctl(struct kvm_vcpu *vcpu);
  135. int kvm_s390_handle_eb(struct kvm_vcpu *vcpu);
  136. /* implemented in sigp.c */
  137. int kvm_s390_handle_sigp(struct kvm_vcpu *vcpu);
  138. int kvm_s390_handle_sigp_pei(struct kvm_vcpu *vcpu);
  139. /* implemented in kvm-s390.c */
  140. long kvm_arch_fault_in_page(struct kvm_vcpu *vcpu, gpa_t gpa, int writable);
  141. int kvm_s390_store_status_unloaded(struct kvm_vcpu *vcpu, unsigned long addr);
  142. int kvm_s390_vcpu_store_status(struct kvm_vcpu *vcpu, unsigned long addr);
  143. void kvm_s390_vcpu_start(struct kvm_vcpu *vcpu);
  144. void kvm_s390_vcpu_stop(struct kvm_vcpu *vcpu);
  145. void s390_vcpu_block(struct kvm_vcpu *vcpu);
  146. void s390_vcpu_unblock(struct kvm_vcpu *vcpu);
  147. void exit_sie(struct kvm_vcpu *vcpu);
  148. void exit_sie_sync(struct kvm_vcpu *vcpu);
  149. int kvm_s390_vcpu_setup_cmma(struct kvm_vcpu *vcpu);
  150. void kvm_s390_vcpu_unsetup_cmma(struct kvm_vcpu *vcpu);
  151. /* is cmma enabled */
  152. bool kvm_s390_cmma_enabled(struct kvm *kvm);
  153. int test_vfacility(unsigned long nr);
  154. /* implemented in diag.c */
  155. int kvm_s390_handle_diag(struct kvm_vcpu *vcpu);
  156. /* implemented in interrupt.c */
  157. int kvm_s390_inject_prog_irq(struct kvm_vcpu *vcpu,
  158. struct kvm_s390_pgm_info *pgm_info);
  159. /**
  160. * kvm_s390_inject_prog_cond - conditionally inject a program check
  161. * @vcpu: virtual cpu
  162. * @rc: original return/error code
  163. *
  164. * This function is supposed to be used after regular guest access functions
  165. * failed, to conditionally inject a program check to a vcpu. The typical
  166. * pattern would look like
  167. *
  168. * rc = write_guest(vcpu, addr, data, len);
  169. * if (rc)
  170. * return kvm_s390_inject_prog_cond(vcpu, rc);
  171. *
  172. * A negative return code from guest access functions implies an internal error
  173. * like e.g. out of memory. In these cases no program check should be injected
  174. * to the guest.
  175. * A positive value implies that an exception happened while accessing a guest's
  176. * memory. In this case all data belonging to the corresponding program check
  177. * has been stored in vcpu->arch.pgm and can be injected with
  178. * kvm_s390_inject_prog_irq().
  179. *
  180. * Returns: - the original @rc value if @rc was negative (internal error)
  181. * - zero if @rc was already zero
  182. * - zero or error code from injecting if @rc was positive
  183. * (program check injected to @vcpu)
  184. */
  185. static inline int kvm_s390_inject_prog_cond(struct kvm_vcpu *vcpu, int rc)
  186. {
  187. if (rc <= 0)
  188. return rc;
  189. return kvm_s390_inject_prog_irq(vcpu, &vcpu->arch.pgm);
  190. }
  191. /* implemented in interrupt.c */
  192. int kvm_cpu_has_interrupt(struct kvm_vcpu *vcpu);
  193. int psw_extint_disabled(struct kvm_vcpu *vcpu);
  194. void kvm_s390_destroy_adapters(struct kvm *kvm);
  195. int kvm_s390_si_ext_call_pending(struct kvm_vcpu *vcpu);
  196. /* implemented in guestdbg.c */
  197. void kvm_s390_backup_guest_per_regs(struct kvm_vcpu *vcpu);
  198. void kvm_s390_restore_guest_per_regs(struct kvm_vcpu *vcpu);
  199. void kvm_s390_patch_guest_per_regs(struct kvm_vcpu *vcpu);
  200. int kvm_s390_import_bp_data(struct kvm_vcpu *vcpu,
  201. struct kvm_guest_debug *dbg);
  202. void kvm_s390_clear_bp_data(struct kvm_vcpu *vcpu);
  203. void kvm_s390_prepare_debug_exit(struct kvm_vcpu *vcpu);
  204. void kvm_s390_handle_per_event(struct kvm_vcpu *vcpu);
  205. #endif