mmu.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #ifndef __MMU_H
  2. #define __MMU_H
  3. #include <linux/const.h>
  4. #include <asm/page.h>
  5. #include <asm/hypervisor.h>
  6. #define CTX_NR_BITS 13
  7. #define TAG_CONTEXT_BITS ((_AC(1,UL) << CTX_NR_BITS) - _AC(1,UL))
  8. /* UltraSPARC-III+ and later have a feature whereby you can
  9. * select what page size the various Data-TLB instances in the
  10. * chip. In order to gracefully support this, we put the version
  11. * field in a spot outside of the areas of the context register
  12. * where this parameter is specified.
  13. */
  14. #define CTX_VERSION_SHIFT 22
  15. #define CTX_VERSION_MASK ((~0UL) << CTX_VERSION_SHIFT)
  16. #define CTX_PGSZ_8KB _AC(0x0,UL)
  17. #define CTX_PGSZ_64KB _AC(0x1,UL)
  18. #define CTX_PGSZ_512KB _AC(0x2,UL)
  19. #define CTX_PGSZ_4MB _AC(0x3,UL)
  20. #define CTX_PGSZ_BITS _AC(0x7,UL)
  21. #define CTX_PGSZ0_NUC_SHIFT 61
  22. #define CTX_PGSZ1_NUC_SHIFT 58
  23. #define CTX_PGSZ0_SHIFT 16
  24. #define CTX_PGSZ1_SHIFT 19
  25. #define CTX_PGSZ_MASK ((CTX_PGSZ_BITS << CTX_PGSZ0_SHIFT) | \
  26. (CTX_PGSZ_BITS << CTX_PGSZ1_SHIFT))
  27. #if defined(CONFIG_SPARC64_PAGE_SIZE_8KB)
  28. #define CTX_PGSZ_BASE CTX_PGSZ_8KB
  29. #elif defined(CONFIG_SPARC64_PAGE_SIZE_64KB)
  30. #define CTX_PGSZ_BASE CTX_PGSZ_64KB
  31. #elif defined(CONFIG_SPARC64_PAGE_SIZE_512KB)
  32. #define CTX_PGSZ_BASE CTX_PGSZ_512KB
  33. #elif defined(CONFIG_SPARC64_PAGE_SIZE_4MB)
  34. #define CTX_PGSZ_BASE CTX_PGSZ_4MB
  35. #else
  36. #error No page size specified in kernel configuration
  37. #endif
  38. #if defined(CONFIG_HUGETLB_PAGE_SIZE_4MB)
  39. #define CTX_PGSZ_HUGE CTX_PGSZ_4MB
  40. #elif defined(CONFIG_HUGETLB_PAGE_SIZE_512K)
  41. #define CTX_PGSZ_HUGE CTX_PGSZ_512KB
  42. #elif defined(CONFIG_HUGETLB_PAGE_SIZE_64K)
  43. #define CTX_PGSZ_HUGE CTX_PGSZ_64KB
  44. #endif
  45. #define CTX_PGSZ_KERN CTX_PGSZ_4MB
  46. /* Thus, when running on UltraSPARC-III+ and later, we use the following
  47. * PRIMARY_CONTEXT register values for the kernel context.
  48. */
  49. #define CTX_CHEETAH_PLUS_NUC \
  50. ((CTX_PGSZ_KERN << CTX_PGSZ0_NUC_SHIFT) | \
  51. (CTX_PGSZ_BASE << CTX_PGSZ1_NUC_SHIFT))
  52. #define CTX_CHEETAH_PLUS_CTX0 \
  53. ((CTX_PGSZ_KERN << CTX_PGSZ0_SHIFT) | \
  54. (CTX_PGSZ_BASE << CTX_PGSZ1_SHIFT))
  55. /* If you want "the TLB context number" use CTX_NR_MASK. If you
  56. * want "the bits I program into the context registers" use
  57. * CTX_HW_MASK.
  58. */
  59. #define CTX_NR_MASK TAG_CONTEXT_BITS
  60. #define CTX_HW_MASK (CTX_NR_MASK | CTX_PGSZ_MASK)
  61. #define CTX_FIRST_VERSION ((_AC(1,UL) << CTX_VERSION_SHIFT) + _AC(1,UL))
  62. #define CTX_VALID(__ctx) \
  63. (!(((__ctx.sparc64_ctx_val) ^ tlb_context_cache) & CTX_VERSION_MASK))
  64. #define CTX_HWBITS(__ctx) ((__ctx.sparc64_ctx_val) & CTX_HW_MASK)
  65. #define CTX_NRBITS(__ctx) ((__ctx.sparc64_ctx_val) & CTX_NR_MASK)
  66. #ifndef __ASSEMBLY__
  67. #define TSB_ENTRY_ALIGNMENT 16
  68. struct tsb {
  69. unsigned long tag;
  70. unsigned long pte;
  71. } __attribute__((aligned(TSB_ENTRY_ALIGNMENT)));
  72. extern void __tsb_insert(unsigned long ent, unsigned long tag, unsigned long pte);
  73. extern void tsb_flush(unsigned long ent, unsigned long tag);
  74. extern void tsb_init(struct tsb *tsb, unsigned long size);
  75. struct tsb_config {
  76. struct tsb *tsb;
  77. unsigned long tsb_rss_limit;
  78. unsigned long tsb_nentries;
  79. unsigned long tsb_reg_val;
  80. unsigned long tsb_map_vaddr;
  81. unsigned long tsb_map_pte;
  82. };
  83. #define MM_TSB_BASE 0
  84. #ifdef CONFIG_HUGETLB_PAGE
  85. #define MM_TSB_HUGE 1
  86. #define MM_NUM_TSBS 2
  87. #else
  88. #define MM_NUM_TSBS 1
  89. #endif
  90. typedef struct {
  91. spinlock_t lock;
  92. unsigned long sparc64_ctx_val;
  93. unsigned long huge_pte_count;
  94. struct tsb_config tsb_block[MM_NUM_TSBS];
  95. struct hv_tsb_descr tsb_descr[MM_NUM_TSBS];
  96. } mm_context_t;
  97. #endif /* !__ASSEMBLY__ */
  98. #define TSB_CONFIG_TSB 0x00
  99. #define TSB_CONFIG_RSS_LIMIT 0x08
  100. #define TSB_CONFIG_NENTRIES 0x10
  101. #define TSB_CONFIG_REG_VAL 0x18
  102. #define TSB_CONFIG_MAP_VADDR 0x20
  103. #define TSB_CONFIG_MAP_PTE 0x28
  104. #endif /* __MMU_H */