44x_tlb.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. 2007
  16. *
  17. * Authors: Hollis Blanchard <hollisb@us.ibm.com>
  18. */
  19. #ifndef __KVM_POWERPC_TLB_H__
  20. #define __KVM_POWERPC_TLB_H__
  21. #include <linux/kvm_host.h>
  22. #include <asm/mmu-44x.h>
  23. extern int kvmppc_44x_tlb_index(struct kvm_vcpu *vcpu, gva_t eaddr,
  24. unsigned int pid, unsigned int as);
  25. extern int kvmppc_44x_dtlb_index(struct kvm_vcpu *vcpu, gva_t eaddr);
  26. extern int kvmppc_44x_itlb_index(struct kvm_vcpu *vcpu, gva_t eaddr);
  27. extern int kvmppc_44x_emul_tlbsx(struct kvm_vcpu *vcpu, u8 rt, u8 ra, u8 rb,
  28. u8 rc);
  29. extern int kvmppc_44x_emul_tlbwe(struct kvm_vcpu *vcpu, u8 ra, u8 rs, u8 ws);
  30. /* TLB helper functions */
  31. static inline unsigned int get_tlb_size(const struct kvmppc_44x_tlbe *tlbe)
  32. {
  33. return (tlbe->word0 >> 4) & 0xf;
  34. }
  35. static inline gva_t get_tlb_eaddr(const struct kvmppc_44x_tlbe *tlbe)
  36. {
  37. return tlbe->word0 & 0xfffffc00;
  38. }
  39. static inline gva_t get_tlb_bytes(const struct kvmppc_44x_tlbe *tlbe)
  40. {
  41. unsigned int pgsize = get_tlb_size(tlbe);
  42. return 1 << 10 << (pgsize << 1);
  43. }
  44. static inline gva_t get_tlb_end(const struct kvmppc_44x_tlbe *tlbe)
  45. {
  46. return get_tlb_eaddr(tlbe) + get_tlb_bytes(tlbe) - 1;
  47. }
  48. static inline u64 get_tlb_raddr(const struct kvmppc_44x_tlbe *tlbe)
  49. {
  50. u64 word1 = tlbe->word1;
  51. return ((word1 & 0xf) << 32) | (word1 & 0xfffffc00);
  52. }
  53. static inline unsigned int get_tlb_tid(const struct kvmppc_44x_tlbe *tlbe)
  54. {
  55. return tlbe->tid & 0xff;
  56. }
  57. static inline unsigned int get_tlb_ts(const struct kvmppc_44x_tlbe *tlbe)
  58. {
  59. return (tlbe->word0 >> 8) & 0x1;
  60. }
  61. static inline unsigned int get_tlb_v(const struct kvmppc_44x_tlbe *tlbe)
  62. {
  63. return (tlbe->word0 >> 9) & 0x1;
  64. }
  65. static inline unsigned int get_mmucr_stid(const struct kvm_vcpu *vcpu)
  66. {
  67. return vcpu->arch.mmucr & 0xff;
  68. }
  69. static inline unsigned int get_mmucr_sts(const struct kvm_vcpu *vcpu)
  70. {
  71. return (vcpu->arch.mmucr >> 16) & 0x1;
  72. }
  73. static inline gpa_t tlb_xlate(struct kvmppc_44x_tlbe *tlbe, gva_t eaddr)
  74. {
  75. unsigned int pgmask = get_tlb_bytes(tlbe) - 1;
  76. return get_tlb_raddr(tlbe) | (eaddr & pgmask);
  77. }
  78. #endif /* __KVM_POWERPC_TLB_H__ */