misc.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 +
  29. offsetof(struct kvm_vm_data, kvm_p2m));
  30. }
  31. static inline void kvm_set_pmt_entry(struct kvm *kvm, gfn_t gfn,
  32. u64 paddr, u64 mem_flags)
  33. {
  34. uint64_t *pmt_base = kvm_host_get_pmt(kvm);
  35. unsigned long pte;
  36. pte = PAGE_ALIGN(paddr) | mem_flags;
  37. pmt_base[gfn] = pte;
  38. }
  39. /*Function for translating host address to guest address*/
  40. static inline void *to_guest(struct kvm *kvm, void *addr)
  41. {
  42. return (void *)((unsigned long)(addr) - kvm->arch.vm_base +
  43. KVM_VM_DATA_BASE);
  44. }
  45. /*Function for translating guest address to host address*/
  46. static inline void *to_host(struct kvm *kvm, void *addr)
  47. {
  48. return (void *)((unsigned long)addr - KVM_VM_DATA_BASE
  49. + kvm->arch.vm_base);
  50. }
  51. /* Get host context of the vcpu */
  52. static inline union context *kvm_get_host_context(struct kvm_vcpu *vcpu)
  53. {
  54. union context *ctx = &vcpu->arch.host;
  55. return to_guest(vcpu->kvm, ctx);
  56. }
  57. /* Get guest context of the vcpu */
  58. static inline union context *kvm_get_guest_context(struct kvm_vcpu *vcpu)
  59. {
  60. union context *ctx = &vcpu->arch.guest;
  61. return to_guest(vcpu->kvm, ctx);
  62. }
  63. /* kvm get exit data from gvmm! */
  64. static inline struct exit_ctl_data *kvm_get_exit_data(struct kvm_vcpu *vcpu)
  65. {
  66. return &vcpu->arch.exit_data;
  67. }
  68. /*kvm get vcpu ioreq for kvm module!*/
  69. static inline struct kvm_mmio_req *kvm_get_vcpu_ioreq(struct kvm_vcpu *vcpu)
  70. {
  71. struct exit_ctl_data *p_ctl_data;
  72. if (vcpu) {
  73. p_ctl_data = kvm_get_exit_data(vcpu);
  74. if (p_ctl_data->exit_reason == EXIT_REASON_MMIO_INSTRUCTION)
  75. return &p_ctl_data->u.ioreq;
  76. }
  77. return NULL;
  78. }
  79. #endif