kvm-s390.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. /* The current code can have up to 256 pages for virtio */
  20. #define VIRTIODESCSPACE (256ul * 4096ul)
  21. typedef int (*intercept_handler_t)(struct kvm_vcpu *vcpu);
  22. /* declare vfacilities extern */
  23. extern unsigned long *vfacilities;
  24. /* negativ values are error codes, positive values for internal conditions */
  25. #define SIE_INTERCEPT_RERUNVCPU (1<<0)
  26. #define SIE_INTERCEPT_UCONTROL (1<<1)
  27. int kvm_handle_sie_intercept(struct kvm_vcpu *vcpu);
  28. #define VM_EVENT(d_kvm, d_loglevel, d_string, d_args...)\
  29. do { \
  30. debug_sprintf_event(d_kvm->arch.dbf, d_loglevel, d_string "\n", \
  31. d_args); \
  32. } while (0)
  33. #define VCPU_EVENT(d_vcpu, d_loglevel, d_string, d_args...)\
  34. do { \
  35. debug_sprintf_event(d_vcpu->kvm->arch.dbf, d_loglevel, \
  36. "%02d[%016lx-%016lx]: " d_string "\n", d_vcpu->vcpu_id, \
  37. d_vcpu->arch.sie_block->gpsw.mask, d_vcpu->arch.sie_block->gpsw.addr,\
  38. d_args); \
  39. } while (0)
  40. static inline int __cpu_is_stopped(struct kvm_vcpu *vcpu)
  41. {
  42. return atomic_read(&vcpu->arch.sie_block->cpuflags) & CPUSTAT_STOP_INT;
  43. }
  44. static inline int kvm_is_ucontrol(struct kvm *kvm)
  45. {
  46. #ifdef CONFIG_KVM_S390_UCONTROL
  47. if (kvm->arch.gmap)
  48. return 0;
  49. return 1;
  50. #else
  51. return 0;
  52. #endif
  53. }
  54. static inline void kvm_s390_set_prefix(struct kvm_vcpu *vcpu, u32 prefix)
  55. {
  56. vcpu->arch.sie_block->prefix = prefix & 0x7fffe000u;
  57. vcpu->arch.sie_block->ihcpu = 0xffff;
  58. kvm_make_request(KVM_REQ_MMU_RELOAD, vcpu);
  59. }
  60. static inline u64 kvm_s390_get_base_disp_s(struct kvm_vcpu *vcpu)
  61. {
  62. u32 base2 = vcpu->arch.sie_block->ipb >> 28;
  63. u32 disp2 = ((vcpu->arch.sie_block->ipb & 0x0fff0000) >> 16);
  64. return (base2 ? vcpu->run->s.regs.gprs[base2] : 0) + disp2;
  65. }
  66. static inline void kvm_s390_get_base_disp_sse(struct kvm_vcpu *vcpu,
  67. u64 *address1, u64 *address2)
  68. {
  69. u32 base1 = (vcpu->arch.sie_block->ipb & 0xf0000000) >> 28;
  70. u32 disp1 = (vcpu->arch.sie_block->ipb & 0x0fff0000) >> 16;
  71. u32 base2 = (vcpu->arch.sie_block->ipb & 0xf000) >> 12;
  72. u32 disp2 = vcpu->arch.sie_block->ipb & 0x0fff;
  73. *address1 = (base1 ? vcpu->run->s.regs.gprs[base1] : 0) + disp1;
  74. *address2 = (base2 ? vcpu->run->s.regs.gprs[base2] : 0) + disp2;
  75. }
  76. static inline void kvm_s390_get_regs_rre(struct kvm_vcpu *vcpu, int *r1, int *r2)
  77. {
  78. *r1 = (vcpu->arch.sie_block->ipb & 0x00f00000) >> 20;
  79. *r2 = (vcpu->arch.sie_block->ipb & 0x000f0000) >> 16;
  80. }
  81. static inline u64 kvm_s390_get_base_disp_rsy(struct kvm_vcpu *vcpu)
  82. {
  83. u32 base2 = vcpu->arch.sie_block->ipb >> 28;
  84. u32 disp2 = ((vcpu->arch.sie_block->ipb & 0x0fff0000) >> 16) +
  85. ((vcpu->arch.sie_block->ipb & 0xff00) << 4);
  86. /* The displacement is a 20bit _SIGNED_ value */
  87. if (disp2 & 0x80000)
  88. disp2+=0xfff00000;
  89. return (base2 ? vcpu->run->s.regs.gprs[base2] : 0) + (long)(int)disp2;
  90. }
  91. static inline u64 kvm_s390_get_base_disp_rs(struct kvm_vcpu *vcpu)
  92. {
  93. u32 base2 = vcpu->arch.sie_block->ipb >> 28;
  94. u32 disp2 = ((vcpu->arch.sie_block->ipb & 0x0fff0000) >> 16);
  95. return (base2 ? vcpu->run->s.regs.gprs[base2] : 0) + disp2;
  96. }
  97. /* Set the condition code in the guest program status word */
  98. static inline void kvm_s390_set_psw_cc(struct kvm_vcpu *vcpu, unsigned long cc)
  99. {
  100. vcpu->arch.sie_block->gpsw.mask &= ~(3UL << 44);
  101. vcpu->arch.sie_block->gpsw.mask |= cc << 44;
  102. }
  103. int kvm_s390_handle_wait(struct kvm_vcpu *vcpu);
  104. enum hrtimer_restart kvm_s390_idle_wakeup(struct hrtimer *timer);
  105. void kvm_s390_tasklet(unsigned long parm);
  106. void kvm_s390_deliver_pending_interrupts(struct kvm_vcpu *vcpu);
  107. void kvm_s390_deliver_pending_machine_checks(struct kvm_vcpu *vcpu);
  108. int __must_check kvm_s390_inject_vm(struct kvm *kvm,
  109. struct kvm_s390_interrupt *s390int);
  110. int __must_check kvm_s390_inject_vcpu(struct kvm_vcpu *vcpu,
  111. struct kvm_s390_interrupt *s390int);
  112. int __must_check kvm_s390_inject_program_int(struct kvm_vcpu *vcpu, u16 code);
  113. int __must_check kvm_s390_inject_sigp_stop(struct kvm_vcpu *vcpu, int action);
  114. struct kvm_s390_interrupt_info *kvm_s390_get_io_int(struct kvm *kvm,
  115. u64 cr6, u64 schid);
  116. /* implemented in priv.c */
  117. int kvm_s390_handle_b2(struct kvm_vcpu *vcpu);
  118. int kvm_s390_handle_e5(struct kvm_vcpu *vcpu);
  119. int kvm_s390_handle_01(struct kvm_vcpu *vcpu);
  120. int kvm_s390_handle_b9(struct kvm_vcpu *vcpu);
  121. int kvm_s390_handle_lpsw(struct kvm_vcpu *vcpu);
  122. int kvm_s390_handle_lctl(struct kvm_vcpu *vcpu);
  123. int kvm_s390_handle_eb(struct kvm_vcpu *vcpu);
  124. /* implemented in sigp.c */
  125. int kvm_s390_handle_sigp(struct kvm_vcpu *vcpu);
  126. /* implemented in kvm-s390.c */
  127. int kvm_s390_vcpu_store_status(struct kvm_vcpu *vcpu,
  128. unsigned long addr);
  129. void s390_vcpu_block(struct kvm_vcpu *vcpu);
  130. void s390_vcpu_unblock(struct kvm_vcpu *vcpu);
  131. void exit_sie(struct kvm_vcpu *vcpu);
  132. void exit_sie_sync(struct kvm_vcpu *vcpu);
  133. /* implemented in diag.c */
  134. int kvm_s390_handle_diag(struct kvm_vcpu *vcpu);
  135. #endif