pgtable_64.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. * Copyright 2011 Tilera Corporation. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation, version 2.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  11. * NON INFRINGEMENT. See the GNU General Public License for
  12. * more details.
  13. *
  14. */
  15. #ifndef _ASM_TILE_PGTABLE_64_H
  16. #define _ASM_TILE_PGTABLE_64_H
  17. /* The level-0 page table breaks the address space into 32-bit chunks. */
  18. #define PGDIR_SHIFT HV_LOG2_L1_SPAN
  19. #define PGDIR_SIZE HV_L1_SPAN
  20. #define PGDIR_MASK (~(PGDIR_SIZE-1))
  21. #define PTRS_PER_PGD HV_L0_ENTRIES
  22. #define PGD_INDEX(va) HV_L0_INDEX(va)
  23. #define SIZEOF_PGD HV_L0_SIZE
  24. /*
  25. * The level-1 index is defined by the huge page size. A PMD is composed
  26. * of PTRS_PER_PMD pgd_t's and is the middle level of the page table.
  27. */
  28. #define PMD_SHIFT HPAGE_SHIFT
  29. #define PMD_SIZE HPAGE_SIZE
  30. #define PMD_MASK (~(PMD_SIZE-1))
  31. #define PTRS_PER_PMD _HV_L1_ENTRIES(HPAGE_SHIFT)
  32. #define PMD_INDEX(va) _HV_L1_INDEX(va, HPAGE_SHIFT)
  33. #define SIZEOF_PMD _HV_L1_SIZE(HPAGE_SHIFT)
  34. /*
  35. * The level-2 index is defined by the difference between the huge
  36. * page size and the normal page size. A PTE is composed of
  37. * PTRS_PER_PTE pte_t's and is the bottom level of the page table.
  38. * Note that the hypervisor docs use PTE for what we call pte_t, so
  39. * this nomenclature is somewhat confusing.
  40. */
  41. #define PTRS_PER_PTE _HV_L2_ENTRIES(HPAGE_SHIFT, PAGE_SHIFT)
  42. #define PTE_INDEX(va) _HV_L2_INDEX(va, HPAGE_SHIFT, PAGE_SHIFT)
  43. #define SIZEOF_PTE _HV_L2_SIZE(HPAGE_SHIFT, PAGE_SHIFT)
  44. /*
  45. * Align the vmalloc area to an L2 page table. Omit guard pages at
  46. * the beginning and end for simplicity (particularly in the per-cpu
  47. * memory allocation code). The vmalloc code puts in an internal
  48. * guard page between each allocation.
  49. */
  50. #define _VMALLOC_END HUGE_VMAP_BASE
  51. #define VMALLOC_END _VMALLOC_END
  52. #define VMALLOC_START _VMALLOC_START
  53. #define HUGE_VMAP_END (HUGE_VMAP_BASE + PGDIR_SIZE)
  54. #ifndef __ASSEMBLY__
  55. /* We have no pud since we are a three-level page table. */
  56. #include <asm-generic/pgtable-nopud.h>
  57. /*
  58. * pmds are the same as pgds and ptes, so converting is a no-op.
  59. */
  60. #define pmd_pte(pmd) (pmd)
  61. #define pmdp_ptep(pmdp) (pmdp)
  62. #define pte_pmd(pte) (pte)
  63. #define pud_pte(pud) ((pud).pgd)
  64. static inline int pud_none(pud_t pud)
  65. {
  66. return pud_val(pud) == 0;
  67. }
  68. static inline int pud_present(pud_t pud)
  69. {
  70. return pud_val(pud) & _PAGE_PRESENT;
  71. }
  72. static inline int pud_huge_page(pud_t pud)
  73. {
  74. return pud_val(pud) & _PAGE_HUGE_PAGE;
  75. }
  76. #define pmd_ERROR(e) \
  77. pr_err("%s:%d: bad pmd 0x%016llx.\n", __FILE__, __LINE__, pmd_val(e))
  78. static inline void pud_clear(pud_t *pudp)
  79. {
  80. __pte_clear(&pudp->pgd);
  81. }
  82. static inline int pud_bad(pud_t pud)
  83. {
  84. return ((pud_val(pud) & _PAGE_ALL) != _PAGE_TABLE);
  85. }
  86. /* Return the page-table frame number (ptfn) that a pud_t points at. */
  87. #define pud_ptfn(pud) hv_pte_get_ptfn((pud).pgd)
  88. /* Return the page frame number (pfn) that a pud_t points at. */
  89. #define pud_pfn(pud) pte_pfn(pud_pte(pud))
  90. /*
  91. * A given kernel pud_t maps to a kernel pmd_t table at a specific
  92. * virtual address. Since kernel pmd_t tables can be aligned at
  93. * sub-page granularity, this macro can return non-page-aligned
  94. * pointers, despite its name.
  95. */
  96. #define pud_page_vaddr(pud) \
  97. (__va((phys_addr_t)pud_ptfn(pud) << HV_LOG2_PAGE_TABLE_ALIGN))
  98. /*
  99. * A pud_t points to a pmd_t array. Since we can have multiple per
  100. * page, we don't have a one-to-one mapping of pud_t's to pages.
  101. */
  102. #define pud_page(pud) pfn_to_page(PFN_DOWN(HV_PTFN_TO_CPA(pud_ptfn(pud))))
  103. static inline unsigned long pud_index(unsigned long address)
  104. {
  105. return (address >> PUD_SHIFT) & (PTRS_PER_PUD - 1);
  106. }
  107. #define pmd_offset(pud, address) \
  108. ((pmd_t *)pud_page_vaddr(*(pud)) + pmd_index(address))
  109. /* Normalize an address to having the correct high bits set. */
  110. #define pgd_addr_normalize pgd_addr_normalize
  111. static inline unsigned long pgd_addr_normalize(unsigned long addr)
  112. {
  113. return ((long)addr << (CHIP_WORD_SIZE() - CHIP_VA_WIDTH())) >>
  114. (CHIP_WORD_SIZE() - CHIP_VA_WIDTH());
  115. }
  116. /* We don't define any pgds for these addresses. */
  117. static inline int pgd_addr_invalid(unsigned long addr)
  118. {
  119. return addr >= KERNEL_HIGH_VADDR || addr != pgd_addr_normalize(addr);
  120. }
  121. /*
  122. * Use atomic instructions to provide atomicity against the hypervisor.
  123. */
  124. #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
  125. static inline int ptep_test_and_clear_young(struct vm_area_struct *vma,
  126. unsigned long addr, pte_t *ptep)
  127. {
  128. return (__insn_fetchand(&ptep->val, ~HV_PTE_ACCESSED) >>
  129. HV_PTE_INDEX_ACCESSED) & 0x1;
  130. }
  131. #define __HAVE_ARCH_PTEP_SET_WRPROTECT
  132. static inline void ptep_set_wrprotect(struct mm_struct *mm,
  133. unsigned long addr, pte_t *ptep)
  134. {
  135. __insn_fetchand(&ptep->val, ~HV_PTE_WRITABLE);
  136. }
  137. #define __HAVE_ARCH_PTEP_GET_AND_CLEAR
  138. static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
  139. unsigned long addr, pte_t *ptep)
  140. {
  141. return hv_pte(__insn_exch(&ptep->val, 0UL));
  142. }
  143. #endif /* __ASSEMBLY__ */
  144. #endif /* _ASM_TILE_PGTABLE_64_H */