kvm_para.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License, version 2, as
  4. * published by the Free Software Foundation.
  5. *
  6. * This program is distributed in the hope that it will be useful,
  7. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. * GNU General Public License for more details.
  10. *
  11. * You should have received a copy of the GNU General Public License
  12. * along with this program; if not, write to the Free Software
  13. * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  14. *
  15. * Copyright IBM Corp. 2008
  16. *
  17. * Authors: Hollis Blanchard <hollisb@us.ibm.com>
  18. */
  19. #ifndef __POWERPC_KVM_PARA_H__
  20. #define __POWERPC_KVM_PARA_H__
  21. #include <uapi/asm/kvm_para.h>
  22. #ifdef CONFIG_KVM_GUEST
  23. #include <linux/of.h>
  24. static inline int kvm_para_available(void)
  25. {
  26. struct device_node *hyper_node;
  27. hyper_node = of_find_node_by_path("/hypervisor");
  28. if (!hyper_node)
  29. return 0;
  30. if (!of_device_is_compatible(hyper_node, "linux,kvm"))
  31. return 0;
  32. return 1;
  33. }
  34. extern unsigned long kvm_hypercall(unsigned long *in,
  35. unsigned long *out,
  36. unsigned long nr);
  37. #else
  38. static inline int kvm_para_available(void)
  39. {
  40. return 0;
  41. }
  42. static unsigned long kvm_hypercall(unsigned long *in,
  43. unsigned long *out,
  44. unsigned long nr)
  45. {
  46. return EV_UNIMPLEMENTED;
  47. }
  48. #endif
  49. static inline long kvm_hypercall0_1(unsigned int nr, unsigned long *r2)
  50. {
  51. unsigned long in[8];
  52. unsigned long out[8];
  53. unsigned long r;
  54. r = kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
  55. *r2 = out[0];
  56. return r;
  57. }
  58. static inline long kvm_hypercall0(unsigned int nr)
  59. {
  60. unsigned long in[8];
  61. unsigned long out[8];
  62. return kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
  63. }
  64. static inline long kvm_hypercall1(unsigned int nr, unsigned long p1)
  65. {
  66. unsigned long in[8];
  67. unsigned long out[8];
  68. in[0] = p1;
  69. return kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
  70. }
  71. static inline long kvm_hypercall2(unsigned int nr, unsigned long p1,
  72. unsigned long p2)
  73. {
  74. unsigned long in[8];
  75. unsigned long out[8];
  76. in[0] = p1;
  77. in[1] = p2;
  78. return kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
  79. }
  80. static inline long kvm_hypercall3(unsigned int nr, unsigned long p1,
  81. unsigned long p2, unsigned long p3)
  82. {
  83. unsigned long in[8];
  84. unsigned long out[8];
  85. in[0] = p1;
  86. in[1] = p2;
  87. in[2] = p3;
  88. return kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
  89. }
  90. static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
  91. unsigned long p2, unsigned long p3,
  92. unsigned long p4)
  93. {
  94. unsigned long in[8];
  95. unsigned long out[8];
  96. in[0] = p1;
  97. in[1] = p2;
  98. in[2] = p3;
  99. in[3] = p4;
  100. return kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
  101. }
  102. static inline unsigned int kvm_arch_para_features(void)
  103. {
  104. unsigned long r;
  105. if (!kvm_para_available())
  106. return 0;
  107. if(kvm_hypercall0_1(KVM_HC_FEATURES, &r))
  108. return 0;
  109. return r;
  110. }
  111. static inline bool kvm_check_and_clear_guest_paused(void)
  112. {
  113. return false;
  114. }
  115. #endif /* __POWERPC_KVM_PARA_H__ */