kvm_ppc.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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_PPC_H__
  20. #define __POWERPC_KVM_PPC_H__
  21. /* This file exists just so we can dereference kvm_vcpu, avoiding nested header
  22. * dependencies. */
  23. #include <linux/mutex.h>
  24. #include <linux/timer.h>
  25. #include <linux/types.h>
  26. #include <linux/kvm_types.h>
  27. #include <linux/kvm_host.h>
  28. struct kvm_tlb {
  29. struct tlbe guest_tlb[PPC44x_TLB_SIZE];
  30. struct tlbe shadow_tlb[PPC44x_TLB_SIZE];
  31. };
  32. enum emulation_result {
  33. EMULATE_DONE, /* no further processing */
  34. EMULATE_DO_MMIO, /* kvm_run filled with MMIO request */
  35. EMULATE_DO_DCR, /* kvm_run filled with DCR request */
  36. EMULATE_FAIL, /* can't emulate this instruction */
  37. };
  38. extern const unsigned char exception_priority[];
  39. extern const unsigned char priority_exception[];
  40. extern int __kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu);
  41. extern char kvmppc_handlers_start[];
  42. extern unsigned long kvmppc_handler_len;
  43. extern void kvmppc_dump_vcpu(struct kvm_vcpu *vcpu);
  44. extern int kvmppc_handle_load(struct kvm_run *run, struct kvm_vcpu *vcpu,
  45. unsigned int rt, unsigned int bytes,
  46. int is_bigendian);
  47. extern int kvmppc_handle_store(struct kvm_run *run, struct kvm_vcpu *vcpu,
  48. u32 val, unsigned int bytes, int is_bigendian);
  49. extern int kvmppc_emulate_instruction(struct kvm_run *run,
  50. struct kvm_vcpu *vcpu);
  51. extern int kvmppc_emulate_mmio(struct kvm_run *run, struct kvm_vcpu *vcpu);
  52. extern void kvmppc_mmu_map(struct kvm_vcpu *vcpu, u64 gvaddr, gfn_t gfn,
  53. u64 asid, u32 flags);
  54. extern void kvmppc_mmu_invalidate(struct kvm_vcpu *vcpu, gva_t eaddr,
  55. gva_t eend, u32 asid);
  56. extern void kvmppc_mmu_priv_switch(struct kvm_vcpu *vcpu, int usermode);
  57. extern void kvmppc_mmu_switch_pid(struct kvm_vcpu *vcpu, u32 pid);
  58. /* XXX Book E specific */
  59. extern void kvmppc_tlbe_set_modified(struct kvm_vcpu *vcpu, unsigned int i);
  60. extern void kvmppc_check_and_deliver_interrupts(struct kvm_vcpu *vcpu);
  61. static inline void kvmppc_queue_exception(struct kvm_vcpu *vcpu, int exception)
  62. {
  63. unsigned int priority = exception_priority[exception];
  64. set_bit(priority, &vcpu->arch.pending_exceptions);
  65. }
  66. static inline void kvmppc_clear_exception(struct kvm_vcpu *vcpu, int exception)
  67. {
  68. unsigned int priority = exception_priority[exception];
  69. clear_bit(priority, &vcpu->arch.pending_exceptions);
  70. }
  71. /* Helper function for "full" MSR writes. No need to call this if only EE is
  72. * changing. */
  73. static inline void kvmppc_set_msr(struct kvm_vcpu *vcpu, u32 new_msr)
  74. {
  75. if ((new_msr & MSR_PR) != (vcpu->arch.msr & MSR_PR))
  76. kvmppc_mmu_priv_switch(vcpu, new_msr & MSR_PR);
  77. vcpu->arch.msr = new_msr;
  78. if (vcpu->arch.msr & MSR_WE)
  79. kvm_vcpu_block(vcpu);
  80. }
  81. static inline void kvmppc_set_pid(struct kvm_vcpu *vcpu, u32 new_pid)
  82. {
  83. if (vcpu->arch.pid != new_pid) {
  84. vcpu->arch.pid = new_pid;
  85. vcpu->arch.swap_pid = 1;
  86. }
  87. }
  88. #endif /* __POWERPC_KVM_PPC_H__ */