misc.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #ifndef __KVM_IA64_MISC_H
  2. #define __KVM_IA64_MISC_H
  3. #include <linux/kvm_host.h>
  4. /*
  5. * misc.h
  6. * Copyright (C) 2007, Intel Corporation.
  7. * Xiantao Zhang (xiantao.zhang@intel.com)
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms and conditions of the GNU General Public License,
  11. * version 2, as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  16. * more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along with
  19. * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  20. * Place - Suite 330, Boston, MA 02111-1307 USA.
  21. *
  22. */
  23. /*
  24. *Return p2m base address at host side!
  25. */
  26. static inline uint64_t *kvm_host_get_pmt(struct kvm *kvm)
  27. {
  28. return (uint64_t *)(kvm->arch.vm_base + KVM_P2M_OFS);
  29. }
  30. static inline void kvm_set_pmt_entry(struct kvm *kvm, gfn_t gfn,
  31. u64 paddr, u64 mem_flags)
  32. {
  33. uint64_t *pmt_base = kvm_host_get_pmt(kvm);
  34. unsigned long pte;
  35. pte = PAGE_ALIGN(paddr) | mem_flags;
  36. pmt_base[gfn] = pte;
  37. }
  38. /*Function for translating host address to guest address*/
  39. static inline void *to_guest(struct kvm *kvm, void *addr)
  40. {
  41. return (void *)((unsigned long)(addr) - kvm->arch.vm_base +
  42. KVM_VM_DATA_BASE);
  43. }
  44. /*Function for translating guest address to host address*/
  45. static inline void *to_host(struct kvm *kvm, void *addr)
  46. {
  47. return (void *)((unsigned long)addr - KVM_VM_DATA_BASE
  48. + kvm->arch.vm_base);
  49. }
  50. /* Get host context of the vcpu */
  51. static inline union context *kvm_get_host_context(struct kvm_vcpu *vcpu)
  52. {
  53. union context *ctx = &vcpu->arch.host;
  54. return to_guest(vcpu->kvm, ctx);
  55. }
  56. /* Get guest context of the vcpu */
  57. static inline union context *kvm_get_guest_context(struct kvm_vcpu *vcpu)
  58. {
  59. union context *ctx = &vcpu->arch.guest;
  60. return to_guest(vcpu->kvm, ctx);
  61. }
  62. /* kvm get exit data from gvmm! */
  63. static inline struct exit_ctl_data *kvm_get_exit_data(struct kvm_vcpu *vcpu)
  64. {
  65. return &vcpu->arch.exit_data;
  66. }
  67. /*kvm get vcpu ioreq for kvm module!*/
  68. static inline struct kvm_mmio_req *kvm_get_vcpu_ioreq(struct kvm_vcpu *vcpu)
  69. {
  70. struct exit_ctl_data *p_ctl_data;
  71. if (vcpu) {
  72. p_ctl_data = kvm_get_exit_data(vcpu);
  73. if (p_ctl_data->exit_reason == EXIT_REASON_MMIO_INSTRUCTION)
  74. return &p_ctl_data->u.ioreq;
  75. }
  76. return NULL;
  77. }
  78. #endif