mmu.h 3.6 KB

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