44x_tlb.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 struct kvmppc_44x_tlbe *kvmppc_44x_dtlb_search(struct kvm_vcpu *vcpu,
  26. gva_t eaddr);
  27. extern struct kvmppc_44x_tlbe *kvmppc_44x_itlb_search(struct kvm_vcpu *vcpu,
  28. gva_t eaddr);
  29. /* TLB helper functions */
  30. static inline unsigned int get_tlb_size(const struct kvmppc_44x_tlbe *tlbe)
  31. {
  32. return (tlbe->word0 >> 4) & 0xf;
  33. }
  34. static inline gva_t get_tlb_eaddr(const struct kvmppc_44x_tlbe *tlbe)
  35. {
  36. return tlbe->word0 & 0xfffffc00;
  37. }
  38. static inline gva_t get_tlb_bytes(const struct kvmppc_44x_tlbe *tlbe)
  39. {
  40. unsigned int pgsize = get_tlb_size(tlbe);
  41. return 1 << 10 << (pgsize << 1);
  42. }
  43. static inline gva_t get_tlb_end(const struct kvmppc_44x_tlbe *tlbe)
  44. {
  45. return get_tlb_eaddr(tlbe) + get_tlb_bytes(tlbe) - 1;
  46. }
  47. static inline u64 get_tlb_raddr(const struct kvmppc_44x_tlbe *tlbe)
  48. {
  49. u64 word1 = tlbe->word1;
  50. return ((word1 & 0xf) << 32) | (word1 & 0xfffffc00);
  51. }
  52. static inline unsigned int get_tlb_tid(const struct kvmppc_44x_tlbe *tlbe)
  53. {
  54. return tlbe->tid & 0xff;
  55. }
  56. static inline unsigned int get_tlb_ts(const struct kvmppc_44x_tlbe *tlbe)
  57. {
  58. return (tlbe->word0 >> 8) & 0x1;
  59. }
  60. static inline unsigned int get_tlb_v(const struct kvmppc_44x_tlbe *tlbe)
  61. {
  62. return (tlbe->word0 >> 9) & 0x1;
  63. }
  64. static inline unsigned int get_mmucr_stid(const struct kvm_vcpu *vcpu)
  65. {
  66. return vcpu->arch.mmucr & 0xff;
  67. }
  68. static inline unsigned int get_mmucr_sts(const struct kvm_vcpu *vcpu)
  69. {
  70. return (vcpu->arch.mmucr >> 16) & 0x1;
  71. }
  72. static inline gpa_t tlb_xlate(struct kvmppc_44x_tlbe *tlbe, gva_t eaddr)
  73. {
  74. unsigned int pgmask = get_tlb_bytes(tlbe) - 1;
  75. return get_tlb_raddr(tlbe) | (eaddr & pgmask);
  76. }
  77. #endif /* __KVM_POWERPC_TLB_H__ */