pte-hash64-64k.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* To be include by pgtable-hash64.h only */
  2. /* Additional PTE bits (don't change without checking asm in hash_low.S) */
  3. #define _PAGE_SPECIAL 0x00000400 /* software: special page */
  4. #define _PAGE_HPTE_SUB 0x0ffff000 /* combo only: sub pages HPTE bits */
  5. #define _PAGE_HPTE_SUB0 0x08000000 /* combo only: first sub page */
  6. #define _PAGE_COMBO 0x10000000 /* this is a combo 4k page */
  7. #define _PAGE_4K_PFN 0x20000000 /* PFN is for a single 4k page */
  8. /* For 64K page, we don't have a separate _PAGE_HASHPTE bit. Instead,
  9. * we set that to be the whole sub-bits mask. The C code will only
  10. * test this, so a multi-bit mask will work. For combo pages, this
  11. * is equivalent as effectively, the old _PAGE_HASHPTE was an OR of
  12. * all the sub bits. For real 64k pages, we now have the assembly set
  13. * _PAGE_HPTE_SUB0 in addition to setting the HIDX bits which overlap
  14. * that mask. This is fine as long as the HIDX bits are never set on
  15. * a PTE that isn't hashed, which is the case today.
  16. *
  17. * A little nit is for the huge page C code, which does the hashing
  18. * in C, we need to provide which bit to use.
  19. */
  20. #define _PAGE_HASHPTE _PAGE_HPTE_SUB
  21. /* Note the full page bits must be in the same location as for normal
  22. * 4k pages as the same asssembly will be used to insert 64K pages
  23. * wether the kernel has CONFIG_PPC_64K_PAGES or not
  24. */
  25. #define _PAGE_F_SECOND 0x00008000 /* full page: hidx bits */
  26. #define _PAGE_F_GIX 0x00007000 /* full page: hidx bits */
  27. /* PTE flags to conserve for HPTE identification */
  28. #define _PAGE_HPTEFLAGS (_PAGE_BUSY | _PAGE_HASHPTE | _PAGE_COMBO)
  29. /* Shift to put page number into pte.
  30. *
  31. * That gives us a max RPN of 34 bits, which means a max of 50 bits
  32. * of addressable physical space, or 46 bits for the special 4k PFNs.
  33. */
  34. #define PTE_RPN_SHIFT (30)
  35. #ifndef __ASSEMBLY__
  36. /*
  37. * With 64K pages on hash table, we have a special PTE format that
  38. * uses a second "half" of the page table to encode sub-page information
  39. * in order to deal with 64K made of 4K HW pages. Thus we override the
  40. * generic accessors and iterators here
  41. */
  42. #define __real_pte(e,p) ((real_pte_t) { \
  43. (e), pte_val(*((p) + PTRS_PER_PTE)) })
  44. #define __rpte_to_hidx(r,index) ((pte_val((r).pte) & _PAGE_COMBO) ? \
  45. (((r).hidx >> ((index)<<2)) & 0xf) : ((pte_val((r).pte) >> 12) & 0xf))
  46. #define __rpte_to_pte(r) ((r).pte)
  47. #define __rpte_sub_valid(rpte, index) \
  48. (pte_val(rpte.pte) & (_PAGE_HPTE_SUB0 >> (index)))
  49. /* Trick: we set __end to va + 64k, which happens works for
  50. * a 16M page as well as we want only one iteration
  51. */
  52. #define pte_iterate_hashed_subpages(rpte, psize, va, index, shift) \
  53. do { \
  54. unsigned long __end = va + PAGE_SIZE; \
  55. unsigned __split = (psize == MMU_PAGE_4K || \
  56. psize == MMU_PAGE_64K_AP); \
  57. shift = mmu_psize_defs[psize].shift; \
  58. for (index = 0; va < __end; index++, va += (1L << shift)) { \
  59. if (!__split || __rpte_sub_valid(rpte, index)) do { \
  60. #define pte_iterate_hashed_end() } while(0); } } while(0)
  61. #define pte_pagesize_index(mm, addr, pte) \
  62. (((pte) & _PAGE_COMBO)? MMU_PAGE_4K: MMU_PAGE_64K)
  63. #define remap_4k_pfn(vma, addr, pfn, prot) \
  64. remap_pfn_range((vma), (addr), (pfn), PAGE_SIZE, \
  65. __pgprot(pgprot_val((prot)) | _PAGE_4K_PFN))
  66. #ifdef CONFIG_PPC_SUBPAGE_PROT
  67. /*
  68. * For the sub-page protection option, we extend the PGD with one of
  69. * these. Basically we have a 3-level tree, with the top level being
  70. * the protptrs array. To optimize speed and memory consumption when
  71. * only addresses < 4GB are being protected, pointers to the first
  72. * four pages of sub-page protection words are stored in the low_prot
  73. * array.
  74. * Each page of sub-page protection words protects 1GB (4 bytes
  75. * protects 64k). For the 3-level tree, each page of pointers then
  76. * protects 8TB.
  77. */
  78. struct subpage_prot_table {
  79. unsigned long maxaddr; /* only addresses < this are protected */
  80. unsigned int **protptrs[2];
  81. unsigned int *low_prot[4];
  82. };
  83. #undef PGD_TABLE_SIZE
  84. #define PGD_TABLE_SIZE ((sizeof(pgd_t) << PGD_INDEX_SIZE) + \
  85. sizeof(struct subpage_prot_table))
  86. #define SBP_L1_BITS (PAGE_SHIFT - 2)
  87. #define SBP_L2_BITS (PAGE_SHIFT - 3)
  88. #define SBP_L1_COUNT (1 << SBP_L1_BITS)
  89. #define SBP_L2_COUNT (1 << SBP_L2_BITS)
  90. #define SBP_L2_SHIFT (PAGE_SHIFT + SBP_L1_BITS)
  91. #define SBP_L3_SHIFT (SBP_L2_SHIFT + SBP_L2_BITS)
  92. extern void subpage_prot_free(pgd_t *pgd);
  93. static inline struct subpage_prot_table *pgd_subpage_prot(pgd_t *pgd)
  94. {
  95. return (struct subpage_prot_table *)(pgd + PTRS_PER_PGD);
  96. }
  97. #endif /* CONFIG_PPC_SUBPAGE_PROT */
  98. #endif /* __ASSEMBLY__ */