44x_tlb.h 2.4 KB

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