kvm-s390.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. /* negativ values are error codes, positive values for internal conditions */
  23. #define SIE_INTERCEPT_RERUNVCPU (1<<0)
  24. #define SIE_INTERCEPT_UCONTROL (1<<1)
  25. int kvm_handle_sie_intercept(struct kvm_vcpu *vcpu);
  26. #define VM_EVENT(d_kvm, d_loglevel, d_string, d_args...)\
  27. do { \
  28. debug_sprintf_event(d_kvm->arch.dbf, d_loglevel, d_string "\n", \
  29. d_args); \
  30. } while (0)
  31. #define VCPU_EVENT(d_vcpu, d_loglevel, d_string, d_args...)\
  32. do { \
  33. debug_sprintf_event(d_vcpu->kvm->arch.dbf, d_loglevel, \
  34. "%02d[%016lx-%016lx]: " d_string "\n", d_vcpu->vcpu_id, \
  35. d_vcpu->arch.sie_block->gpsw.mask, d_vcpu->arch.sie_block->gpsw.addr,\
  36. d_args); \
  37. } while (0)
  38. static inline int __cpu_is_stopped(struct kvm_vcpu *vcpu)
  39. {
  40. return atomic_read(&vcpu->arch.sie_block->cpuflags) & CPUSTAT_STOP_INT;
  41. }
  42. static inline int kvm_is_ucontrol(struct kvm *kvm)
  43. {
  44. #ifdef CONFIG_KVM_S390_UCONTROL
  45. if (kvm->arch.gmap)
  46. return 0;
  47. return 1;
  48. #else
  49. return 0;
  50. #endif
  51. }
  52. static inline void kvm_s390_set_prefix(struct kvm_vcpu *vcpu, u32 prefix)
  53. {
  54. vcpu->arch.sie_block->prefix = prefix & 0x7fffe000u;
  55. vcpu->arch.sie_block->ihcpu = 0xffff;
  56. }
  57. static inline u64 kvm_s390_get_base_disp_s(struct kvm_vcpu *vcpu)
  58. {
  59. u32 base2 = vcpu->arch.sie_block->ipb >> 28;
  60. u32 disp2 = ((vcpu->arch.sie_block->ipb & 0x0fff0000) >> 16);
  61. return (base2 ? vcpu->run->s.regs.gprs[base2] : 0) + disp2;
  62. }
  63. static inline void kvm_s390_get_base_disp_sse(struct kvm_vcpu *vcpu,
  64. u64 *address1, u64 *address2)
  65. {
  66. u32 base1 = (vcpu->arch.sie_block->ipb & 0xf0000000) >> 28;
  67. u32 disp1 = (vcpu->arch.sie_block->ipb & 0x0fff0000) >> 16;
  68. u32 base2 = (vcpu->arch.sie_block->ipb & 0xf000) >> 12;
  69. u32 disp2 = vcpu->arch.sie_block->ipb & 0x0fff;
  70. *address1 = (base1 ? vcpu->run->s.regs.gprs[base1] : 0) + disp1;
  71. *address2 = (base2 ? vcpu->run->s.regs.gprs[base2] : 0) + disp2;
  72. }
  73. static inline u64 kvm_s390_get_base_disp_rsy(struct kvm_vcpu *vcpu)
  74. {
  75. u32 base2 = vcpu->arch.sie_block->ipb >> 28;
  76. u32 disp2 = ((vcpu->arch.sie_block->ipb & 0x0fff0000) >> 16) +
  77. ((vcpu->arch.sie_block->ipb & 0xff00) << 4);
  78. /* The displacement is a 20bit _SIGNED_ value */
  79. if (disp2 & 0x80000)
  80. disp2+=0xfff00000;
  81. return (base2 ? vcpu->run->s.regs.gprs[base2] : 0) + (long)(int)disp2;
  82. }
  83. static inline u64 kvm_s390_get_base_disp_rs(struct kvm_vcpu *vcpu)
  84. {
  85. u32 base2 = vcpu->arch.sie_block->ipb >> 28;
  86. u32 disp2 = ((vcpu->arch.sie_block->ipb & 0x0fff0000) >> 16);
  87. return (base2 ? vcpu->run->s.regs.gprs[base2] : 0) + disp2;
  88. }
  89. int kvm_s390_handle_wait(struct kvm_vcpu *vcpu);
  90. enum hrtimer_restart kvm_s390_idle_wakeup(struct hrtimer *timer);
  91. void kvm_s390_tasklet(unsigned long parm);
  92. void kvm_s390_deliver_pending_interrupts(struct kvm_vcpu *vcpu);
  93. void kvm_s390_deliver_pending_machine_checks(struct kvm_vcpu *vcpu);
  94. int kvm_s390_inject_vm(struct kvm *kvm,
  95. struct kvm_s390_interrupt *s390int);
  96. int kvm_s390_inject_vcpu(struct kvm_vcpu *vcpu,
  97. struct kvm_s390_interrupt *s390int);
  98. int kvm_s390_inject_program_int(struct kvm_vcpu *vcpu, u16 code);
  99. int kvm_s390_inject_sigp_stop(struct kvm_vcpu *vcpu, int action);
  100. struct kvm_s390_interrupt_info *kvm_s390_get_io_int(struct kvm *kvm,
  101. u64 cr6, u64 schid);
  102. /* implemented in priv.c */
  103. int kvm_s390_handle_b2(struct kvm_vcpu *vcpu);
  104. int kvm_s390_handle_e5(struct kvm_vcpu *vcpu);
  105. int kvm_s390_handle_01(struct kvm_vcpu *vcpu);
  106. int kvm_s390_handle_b9(struct kvm_vcpu *vcpu);
  107. int kvm_s390_handle_lpsw(struct kvm_vcpu *vcpu);
  108. int kvm_s390_handle_priv_eb(struct kvm_vcpu *vcpu);
  109. /* implemented in sigp.c */
  110. int kvm_s390_handle_sigp(struct kvm_vcpu *vcpu);
  111. /* implemented in kvm-s390.c */
  112. int kvm_s390_vcpu_store_status(struct kvm_vcpu *vcpu,
  113. unsigned long addr);
  114. /* implemented in diag.c */
  115. int kvm_s390_handle_diag(struct kvm_vcpu *vcpu);
  116. #endif