mmu_64.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __MMU_H
  3. #define __MMU_H
  4. #include <linux/const.h>
  5. #include <asm/page.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. #define CTX_PGSZ_BASE CTX_PGSZ_8KB
  29. #define CTX_PGSZ_HUGE CTX_PGSZ_4MB
  30. #define CTX_PGSZ_KERN CTX_PGSZ_4MB
  31. /* Thus, when running on UltraSPARC-III+ and later, we use the following
  32. * PRIMARY_CONTEXT register values for the kernel context.
  33. */
  34. #define CTX_CHEETAH_PLUS_NUC \
  35. ((CTX_PGSZ_KERN << CTX_PGSZ0_NUC_SHIFT) | \
  36. (CTX_PGSZ_BASE << CTX_PGSZ1_NUC_SHIFT))
  37. #define CTX_CHEETAH_PLUS_CTX0 \
  38. ((CTX_PGSZ_KERN << CTX_PGSZ0_SHIFT) | \
  39. (CTX_PGSZ_BASE << CTX_PGSZ1_SHIFT))
  40. /* If you want "the TLB context number" use CTX_NR_MASK. If you
  41. * want "the bits I program into the context registers" use
  42. * CTX_HW_MASK.
  43. */
  44. #define CTX_NR_MASK TAG_CONTEXT_BITS
  45. #define CTX_HW_MASK (CTX_NR_MASK | CTX_PGSZ_MASK)
  46. #define CTX_FIRST_VERSION BIT(CTX_VERSION_SHIFT)
  47. #define CTX_VALID(__ctx) \
  48. (!(((__ctx.sparc64_ctx_val) ^ tlb_context_cache) & CTX_VERSION_MASK))
  49. #define CTX_HWBITS(__ctx) ((__ctx.sparc64_ctx_val) & CTX_HW_MASK)
  50. #define CTX_NRBITS(__ctx) ((__ctx.sparc64_ctx_val) & CTX_NR_MASK)
  51. #ifndef __ASSEMBLY__
  52. #define TSB_ENTRY_ALIGNMENT 16
  53. struct tsb {
  54. unsigned long tag;
  55. unsigned long pte;
  56. } __attribute__((aligned(TSB_ENTRY_ALIGNMENT)));
  57. void __tsb_insert(unsigned long ent, unsigned long tag, unsigned long pte);
  58. void tsb_flush(unsigned long ent, unsigned long tag);
  59. void tsb_init(struct tsb *tsb, unsigned long size);
  60. struct tsb_config {
  61. struct tsb *tsb;
  62. unsigned long tsb_rss_limit;
  63. unsigned long tsb_nentries;
  64. unsigned long tsb_reg_val;
  65. unsigned long tsb_map_vaddr;
  66. unsigned long tsb_map_pte;
  67. };
  68. #define MM_TSB_BASE 0
  69. #if defined(CONFIG_HUGETLB_PAGE) || defined(CONFIG_TRANSPARENT_HUGEPAGE)
  70. #define MM_TSB_HUGE 1
  71. #define MM_NUM_TSBS 2
  72. #else
  73. #define MM_NUM_TSBS 1
  74. #endif
  75. /* ADI tags are stored when a page is swapped out and the storage for
  76. * tags is allocated dynamically. There is a tag storage descriptor
  77. * associated with each set of tag storage pages. Tag storage descriptors
  78. * are allocated dynamically. Since kernel will allocate a full page for
  79. * each tag storage descriptor, we can store up to
  80. * PAGE_SIZE/sizeof(tag storage descriptor) descriptors on that page.
  81. */
  82. typedef struct {
  83. unsigned long start; /* Start address for this tag storage */
  84. unsigned long end; /* Last address for tag storage */
  85. unsigned char *tags; /* Where the tags are */
  86. unsigned long tag_users; /* number of references to descriptor */
  87. } tag_storage_desc_t;
  88. typedef struct {
  89. spinlock_t lock;
  90. unsigned long sparc64_ctx_val;
  91. unsigned long hugetlb_pte_count;
  92. unsigned long thp_pte_count;
  93. struct tsb_config tsb_block[MM_NUM_TSBS];
  94. struct hv_tsb_descr tsb_descr[MM_NUM_TSBS];
  95. void *vdso;
  96. bool adi;
  97. tag_storage_desc_t *tag_store;
  98. spinlock_t tag_lock;
  99. } mm_context_t;
  100. #endif /* !__ASSEMBLY__ */
  101. #define TSB_CONFIG_TSB 0x00
  102. #define TSB_CONFIG_RSS_LIMIT 0x08
  103. #define TSB_CONFIG_NENTRIES 0x10
  104. #define TSB_CONFIG_REG_VAL 0x18
  105. #define TSB_CONFIG_MAP_VADDR 0x20
  106. #define TSB_CONFIG_MAP_PTE 0x28
  107. #endif /* __MMU_H */