pgtable.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. #ifndef _ASM_SCORE_PGTABLE_H
  2. #define _ASM_SCORE_PGTABLE_H
  3. #include <linux/const.h>
  4. #include <asm-generic/pgtable-nopmd.h>
  5. #include <asm/fixmap.h>
  6. #include <asm/setup.h>
  7. #include <asm/pgtable-bits.h>
  8. extern void load_pgd(unsigned long pg_dir);
  9. extern pte_t invalid_pte_table[PAGE_SIZE/sizeof(pte_t)];
  10. /* PGDIR_SHIFT determines what a third-level page table entry can map */
  11. #define PGDIR_SHIFT 22
  12. #define PGDIR_SIZE (_AC(1, UL) << PGDIR_SHIFT)
  13. #define PGDIR_MASK (~(PGDIR_SIZE - 1))
  14. /*
  15. * Entries per page directory level: we use two-level, so
  16. * we don't really have any PUD/PMD directory physically.
  17. */
  18. #define PGD_ORDER 0
  19. #define PTE_ORDER 0
  20. #define PTRS_PER_PGD 1024
  21. #define PTRS_PER_PTE 1024
  22. #define USER_PTRS_PER_PGD (0x80000000UL/PGDIR_SIZE)
  23. #define FIRST_USER_ADDRESS 0
  24. #define VMALLOC_START (0xc0000000UL)
  25. #define PKMAP_BASE (0xfd000000UL)
  26. #define VMALLOC_END (FIXADDR_START - 2*PAGE_SIZE)
  27. #define pte_ERROR(e) \
  28. printk(KERN_ERR "%s:%d: bad pte %08lx.\n", \
  29. __FILE__, __LINE__, pte_val(e))
  30. #define pgd_ERROR(e) \
  31. printk(KERN_ERR "%s:%d: bad pgd %08lx.\n", \
  32. __FILE__, __LINE__, pgd_val(e))
  33. /*
  34. * Empty pgd/pmd entries point to the invalid_pte_table.
  35. */
  36. static inline int pmd_none(pmd_t pmd)
  37. {
  38. return pmd_val(pmd) == (unsigned long) invalid_pte_table;
  39. }
  40. #define pmd_bad(pmd) (pmd_val(pmd) & ~PAGE_MASK)
  41. static inline int pmd_present(pmd_t pmd)
  42. {
  43. return pmd_val(pmd) != (unsigned long) invalid_pte_table;
  44. }
  45. static inline void pmd_clear(pmd_t *pmdp)
  46. {
  47. pmd_val(*pmdp) = ((unsigned long) invalid_pte_table);
  48. }
  49. #define pte_page(x) pfn_to_page(pte_pfn(x))
  50. #define pte_pfn(x) ((unsigned long)((x).pte >> PAGE_SHIFT))
  51. #define pfn_pte(pfn, prot) \
  52. __pte(((unsigned long long)(pfn) << PAGE_SHIFT) | pgprot_val(prot))
  53. #define __pgd_offset(address) pgd_index(address)
  54. #define __pud_offset(address) (((address) >> PUD_SHIFT) & (PTRS_PER_PUD-1))
  55. #define __pmd_offset(address) (((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1))
  56. /* to find an entry in a kernel page-table-directory */
  57. #define pgd_offset_k(address) pgd_offset(&init_mm, address)
  58. #define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD-1))
  59. /* to find an entry in a page-table-directory */
  60. #define pgd_offset(mm, addr) ((mm)->pgd + pgd_index(addr))
  61. /* Find an entry in the third-level page table.. */
  62. #define __pte_offset(address) \
  63. (((address) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1))
  64. #define pte_offset(dir, address) \
  65. ((pte_t *) pmd_page_vaddr(*(dir)) + __pte_offset(address))
  66. #define pte_offset_kernel(dir, address) \
  67. ((pte_t *) pmd_page_vaddr(*(dir)) + __pte_offset(address))
  68. #define pte_offset_map(dir, address) \
  69. ((pte_t *)page_address(pmd_page(*(dir))) + __pte_offset(address))
  70. #define pte_unmap(pte) ((void)(pte))
  71. /*
  72. * Bits 9(_PAGE_PRESENT) and 10(_PAGE_FILE)are taken,
  73. * split up 30 bits of offset into this range:
  74. */
  75. #define PTE_FILE_MAX_BITS 30
  76. #define pte_to_pgoff(_pte) \
  77. (((_pte).pte & 0x1ff) | (((_pte).pte >> 11) << 9))
  78. #define pgoff_to_pte(off) \
  79. ((pte_t) {((off) & 0x1ff) | (((off) >> 9) << 11) | _PAGE_FILE})
  80. #define __pte_to_swp_entry(pte) \
  81. ((swp_entry_t) { pte_val(pte)})
  82. #define __swp_entry_to_pte(x) ((pte_t) {(x).val})
  83. #define pmd_phys(pmd) __pa((void *)pmd_val(pmd))
  84. #define pmd_page(pmd) (pfn_to_page(pmd_phys(pmd) >> PAGE_SHIFT))
  85. #define mk_pte(page, prot) pfn_pte(page_to_pfn(page), prot)
  86. static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
  87. #define set_pte(pteptr, pteval) (*(pteptr) = pteval)
  88. #define set_pte_at(mm, addr, ptep, pteval) set_pte(ptep, pteval)
  89. #define pte_clear(mm, addr, xp) \
  90. do { set_pte_at(mm, addr, xp, __pte(0)); } while (0)
  91. #define io_remap_pfn_range(vma, vaddr, pfn, size, prot) \
  92. remap_pfn_range(vma, vaddr, pfn, size, prot)
  93. /*
  94. * The "pgd_xxx()" functions here are trivial for a folded two-level
  95. * setup: the pgd is never bad, and a pmd always exists (as it's folded
  96. * into the pgd entry)
  97. */
  98. #define pgd_present(pgd) (1)
  99. #define pgd_none(pgd) (0)
  100. #define pgd_bad(pgd) (0)
  101. #define pgd_clear(pgdp) do { } while (0)
  102. #define kern_addr_valid(addr) (1)
  103. #define pmd_page_vaddr(pmd) pmd_val(pmd)
  104. #define pte_none(pte) (!(pte_val(pte) & ~_PAGE_GLOBAL))
  105. #define pte_present(pte) (pte_val(pte) & _PAGE_PRESENT)
  106. #define PAGE_NONE __pgprot(_PAGE_PRESENT | _PAGE_CACHE)
  107. #define PAGE_SHARED __pgprot(_PAGE_PRESENT | _PAGE_READ | _PAGE_WRITE | \
  108. _PAGE_CACHE)
  109. #define PAGE_COPY __pgprot(_PAGE_PRESENT | _PAGE_READ | _PAGE_CACHE)
  110. #define PAGE_READONLY __pgprot(_PAGE_PRESENT | _PAGE_READ | _PAGE_CACHE)
  111. #define PAGE_KERNEL __pgprot(_PAGE_PRESENT | __READABLE | __WRITEABLE | \
  112. _PAGE_GLOBAL | _PAGE_CACHE)
  113. #define PAGE_KERNEL_UNCACHED __pgprot(_PAGE_PRESENT | __READABLE | \
  114. __WRITEABLE | _PAGE_GLOBAL & ~_PAGE_CACHE)
  115. #define __P000 PAGE_NONE
  116. #define __P001 PAGE_READONLY
  117. #define __P010 PAGE_COPY
  118. #define __P011 PAGE_COPY
  119. #define __P100 PAGE_READONLY
  120. #define __P101 PAGE_READONLY
  121. #define __P110 PAGE_COPY
  122. #define __P111 PAGE_COPY
  123. #define __S000 PAGE_NONE
  124. #define __S001 PAGE_READONLY
  125. #define __S010 PAGE_SHARED
  126. #define __S011 PAGE_SHARED
  127. #define __S100 PAGE_READONLY
  128. #define __S101 PAGE_READONLY
  129. #define __S110 PAGE_SHARED
  130. #define __S111 PAGE_SHARED
  131. #define pgprot_noncached pgprot_noncached
  132. static inline pgprot_t pgprot_noncached(pgprot_t _prot)
  133. {
  134. unsigned long prot = pgprot_val(_prot);
  135. prot = (prot & ~_CACHE_MASK);
  136. return __pgprot(prot);
  137. }
  138. #define __swp_type(x) ((x).val & 0x1f)
  139. #define __swp_offset(x) ((x).val >> 11)
  140. #define __swp_entry(type, offset) ((swp_entry_t){(type) | ((offset) << 11)})
  141. extern unsigned long empty_zero_page;
  142. extern unsigned long zero_page_mask;
  143. #define ZERO_PAGE(vaddr) \
  144. (virt_to_page((void *)(empty_zero_page + \
  145. (((unsigned long)(vaddr)) & zero_page_mask))))
  146. #define pgtable_cache_init() do {} while (0)
  147. #define arch_enter_lazy_cpu_mode() do {} while (0)
  148. static inline int pte_write(pte_t pte)
  149. {
  150. return pte_val(pte) & _PAGE_WRITE;
  151. }
  152. static inline int pte_dirty(pte_t pte)
  153. {
  154. return pte_val(pte) & _PAGE_MODIFIED;
  155. }
  156. static inline int pte_young(pte_t pte)
  157. {
  158. return pte_val(pte) & _PAGE_ACCESSED;
  159. }
  160. static inline int pte_file(pte_t pte)
  161. {
  162. return pte_val(pte) & _PAGE_FILE;
  163. }
  164. #define pte_special(pte) (0)
  165. static inline pte_t pte_wrprotect(pte_t pte)
  166. {
  167. pte_val(pte) &= ~(_PAGE_WRITE | _PAGE_SILENT_WRITE);
  168. return pte;
  169. }
  170. static inline pte_t pte_mkclean(pte_t pte)
  171. {
  172. pte_val(pte) &= ~(_PAGE_MODIFIED|_PAGE_SILENT_WRITE);
  173. return pte;
  174. }
  175. static inline pte_t pte_mkold(pte_t pte)
  176. {
  177. pte_val(pte) &= ~(_PAGE_ACCESSED|_PAGE_SILENT_READ);
  178. return pte;
  179. }
  180. static inline pte_t pte_mkwrite(pte_t pte)
  181. {
  182. pte_val(pte) |= _PAGE_WRITE;
  183. if (pte_val(pte) & _PAGE_MODIFIED)
  184. pte_val(pte) |= _PAGE_SILENT_WRITE;
  185. return pte;
  186. }
  187. static inline pte_t pte_mkdirty(pte_t pte)
  188. {
  189. pte_val(pte) |= _PAGE_MODIFIED;
  190. if (pte_val(pte) & _PAGE_WRITE)
  191. pte_val(pte) |= _PAGE_SILENT_WRITE;
  192. return pte;
  193. }
  194. static inline pte_t pte_mkyoung(pte_t pte)
  195. {
  196. pte_val(pte) |= _PAGE_ACCESSED;
  197. if (pte_val(pte) & _PAGE_READ)
  198. pte_val(pte) |= _PAGE_SILENT_READ;
  199. return pte;
  200. }
  201. #define set_pmd(pmdptr, pmdval) \
  202. do { *(pmdptr) = (pmdval); } while (0)
  203. #define pte_present(pte) (pte_val(pte) & _PAGE_PRESENT)
  204. extern unsigned long pgd_current;
  205. extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
  206. extern void paging_init(void);
  207. static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
  208. {
  209. return __pte((pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot));
  210. }
  211. extern void __update_tlb(struct vm_area_struct *vma,
  212. unsigned long address, pte_t pte);
  213. extern void __update_cache(struct vm_area_struct *vma,
  214. unsigned long address, pte_t pte);
  215. static inline void update_mmu_cache(struct vm_area_struct *vma,
  216. unsigned long address, pte_t *ptep)
  217. {
  218. pte_t pte = *ptep;
  219. __update_tlb(vma, address, pte);
  220. __update_cache(vma, address, pte);
  221. }
  222. #ifndef __ASSEMBLY__
  223. #include <asm-generic/pgtable.h>
  224. void setup_memory(void);
  225. #endif /* __ASSEMBLY__ */
  226. #endif /* _ASM_SCORE_PGTABLE_H */