pgtable.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2003 Ralf Baechle
  7. */
  8. #ifndef _ASM_PGTABLE_H
  9. #define _ASM_PGTABLE_H
  10. #ifdef CONFIG_32BIT
  11. #include <asm/pgtable-32.h>
  12. #endif
  13. #ifdef CONFIG_64BIT
  14. #include <asm/pgtable-64.h>
  15. #endif
  16. #include <asm/io.h>
  17. #include <asm/pgtable-bits.h>
  18. struct mm_struct;
  19. struct vm_area_struct;
  20. #define PAGE_NONE __pgprot(_PAGE_PRESENT | _CACHE_CACHABLE_NONCOHERENT)
  21. #define PAGE_SHARED __pgprot(_PAGE_PRESENT | _PAGE_READ | _PAGE_WRITE | \
  22. _page_cachable_default)
  23. #define PAGE_COPY __pgprot(_PAGE_PRESENT | _PAGE_READ | \
  24. _page_cachable_default)
  25. #define PAGE_READONLY __pgprot(_PAGE_PRESENT | _PAGE_READ | \
  26. _page_cachable_default)
  27. #define PAGE_KERNEL __pgprot(_PAGE_PRESENT | __READABLE | __WRITEABLE | \
  28. _PAGE_GLOBAL | _page_cachable_default)
  29. #define PAGE_USERIO __pgprot(_PAGE_PRESENT | _PAGE_READ | _PAGE_WRITE | \
  30. _page_cachable_default)
  31. #define PAGE_KERNEL_UNCACHED __pgprot(_PAGE_PRESENT | __READABLE | \
  32. __WRITEABLE | _PAGE_GLOBAL | _CACHE_UNCACHED)
  33. /*
  34. * MIPS can't do page protection for execute, and considers that the same like
  35. * read. Also, write permissions imply read permissions. This is the closest
  36. * we can get by reasonable means..
  37. */
  38. /*
  39. * Dummy values to fill the table in mmap.c
  40. * The real values will be generated at runtime
  41. */
  42. #define __P000 __pgprot(0)
  43. #define __P001 __pgprot(0)
  44. #define __P010 __pgprot(0)
  45. #define __P011 __pgprot(0)
  46. #define __P100 __pgprot(0)
  47. #define __P101 __pgprot(0)
  48. #define __P110 __pgprot(0)
  49. #define __P111 __pgprot(0)
  50. #define __S000 __pgprot(0)
  51. #define __S001 __pgprot(0)
  52. #define __S010 __pgprot(0)
  53. #define __S011 __pgprot(0)
  54. #define __S100 __pgprot(0)
  55. #define __S101 __pgprot(0)
  56. #define __S110 __pgprot(0)
  57. #define __S111 __pgprot(0)
  58. extern unsigned long _page_cachable_default;
  59. /*
  60. * ZERO_PAGE is a global shared page that is always zero; used
  61. * for zero-mapped memory areas etc..
  62. */
  63. extern unsigned long empty_zero_page;
  64. extern unsigned long zero_page_mask;
  65. #define ZERO_PAGE(vaddr) \
  66. (virt_to_page((void *)(empty_zero_page + (((unsigned long)(vaddr)) & zero_page_mask))))
  67. extern void paging_init(void);
  68. /*
  69. * Conversion functions: convert a page and protection to a page entry,
  70. * and a page entry and page directory to the page they refer to.
  71. */
  72. #define pmd_phys(pmd) virt_to_phys((void *)pmd_val(pmd))
  73. #define pmd_page(pmd) (pfn_to_page(pmd_phys(pmd) >> PAGE_SHIFT))
  74. #define pmd_page_vaddr(pmd) pmd_val(pmd)
  75. #if defined(CONFIG_64BIT_PHYS_ADDR) && defined(CONFIG_CPU_MIPS32)
  76. #define pte_none(pte) (!(((pte).pte_low | (pte).pte_high) & ~_PAGE_GLOBAL))
  77. #define pte_present(pte) ((pte).pte_low & _PAGE_PRESENT)
  78. static inline void set_pte(pte_t *ptep, pte_t pte)
  79. {
  80. ptep->pte_high = pte.pte_high;
  81. smp_wmb();
  82. ptep->pte_low = pte.pte_low;
  83. //printk("pte_high %x pte_low %x\n", ptep->pte_high, ptep->pte_low);
  84. if (pte.pte_low & _PAGE_GLOBAL) {
  85. pte_t *buddy = ptep_buddy(ptep);
  86. /*
  87. * Make sure the buddy is global too (if it's !none,
  88. * it better already be global)
  89. */
  90. if (pte_none(*buddy)) {
  91. buddy->pte_low |= _PAGE_GLOBAL;
  92. buddy->pte_high |= _PAGE_GLOBAL;
  93. }
  94. }
  95. }
  96. #define set_pte_at(mm, addr, ptep, pteval) set_pte(ptep, pteval)
  97. static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
  98. {
  99. pte_t null = __pte(0);
  100. /* Preserve global status for the pair */
  101. if (ptep_buddy(ptep)->pte_low & _PAGE_GLOBAL)
  102. null.pte_low = null.pte_high = _PAGE_GLOBAL;
  103. set_pte_at(mm, addr, ptep, null);
  104. }
  105. #else
  106. #define pte_none(pte) (!(pte_val(pte) & ~_PAGE_GLOBAL))
  107. #define pte_present(pte) (pte_val(pte) & _PAGE_PRESENT)
  108. /*
  109. * Certain architectures need to do special things when pte's
  110. * within a page table are directly modified. Thus, the following
  111. * hook is made available.
  112. */
  113. static inline void set_pte(pte_t *ptep, pte_t pteval)
  114. {
  115. *ptep = pteval;
  116. #if !defined(CONFIG_CPU_R3000) && !defined(CONFIG_CPU_TX39XX)
  117. if (pte_val(pteval) & _PAGE_GLOBAL) {
  118. pte_t *buddy = ptep_buddy(ptep);
  119. /*
  120. * Make sure the buddy is global too (if it's !none,
  121. * it better already be global)
  122. */
  123. if (pte_none(*buddy))
  124. pte_val(*buddy) = pte_val(*buddy) | _PAGE_GLOBAL;
  125. }
  126. #endif
  127. }
  128. #define set_pte_at(mm, addr, ptep, pteval) set_pte(ptep, pteval)
  129. static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
  130. {
  131. #if !defined(CONFIG_CPU_R3000) && !defined(CONFIG_CPU_TX39XX)
  132. /* Preserve global status for the pair */
  133. if (pte_val(*ptep_buddy(ptep)) & _PAGE_GLOBAL)
  134. set_pte_at(mm, addr, ptep, __pte(_PAGE_GLOBAL));
  135. else
  136. #endif
  137. set_pte_at(mm, addr, ptep, __pte(0));
  138. }
  139. #endif
  140. /*
  141. * (pmds are folded into puds so this doesn't get actually called,
  142. * but the define is needed for a generic inline function.)
  143. */
  144. #define set_pmd(pmdptr, pmdval) do { *(pmdptr) = (pmdval); } while(0)
  145. #ifdef CONFIG_64BIT
  146. /*
  147. * (puds are folded into pgds so this doesn't get actually called,
  148. * but the define is needed for a generic inline function.)
  149. */
  150. #define set_pud(pudptr, pudval) do { *(pudptr) = (pudval); } while(0)
  151. #endif
  152. #define PGD_T_LOG2 (__builtin_ffs(sizeof(pgd_t)) - 1)
  153. #define PMD_T_LOG2 (__builtin_ffs(sizeof(pmd_t)) - 1)
  154. #define PTE_T_LOG2 (__builtin_ffs(sizeof(pte_t)) - 1)
  155. /*
  156. * We used to declare this array with size but gcc 3.3 and older are not able
  157. * to find that this expression is a constant, so the size is dropped.
  158. */
  159. extern pgd_t swapper_pg_dir[];
  160. /*
  161. * The following only work if pte_present() is true.
  162. * Undefined behaviour if not..
  163. */
  164. #if defined(CONFIG_64BIT_PHYS_ADDR) && defined(CONFIG_CPU_MIPS32)
  165. static inline int pte_write(pte_t pte) { return pte.pte_low & _PAGE_WRITE; }
  166. static inline int pte_dirty(pte_t pte) { return pte.pte_low & _PAGE_MODIFIED; }
  167. static inline int pte_young(pte_t pte) { return pte.pte_low & _PAGE_ACCESSED; }
  168. static inline int pte_file(pte_t pte) { return pte.pte_low & _PAGE_FILE; }
  169. static inline pte_t pte_wrprotect(pte_t pte)
  170. {
  171. pte.pte_low &= ~(_PAGE_WRITE | _PAGE_SILENT_WRITE);
  172. pte.pte_high &= ~_PAGE_SILENT_WRITE;
  173. return pte;
  174. }
  175. static inline pte_t pte_mkclean(pte_t pte)
  176. {
  177. pte.pte_low &= ~(_PAGE_MODIFIED | _PAGE_SILENT_WRITE);
  178. pte.pte_high &= ~_PAGE_SILENT_WRITE;
  179. return pte;
  180. }
  181. static inline pte_t pte_mkold(pte_t pte)
  182. {
  183. pte.pte_low &= ~(_PAGE_ACCESSED | _PAGE_SILENT_READ);
  184. pte.pte_high &= ~_PAGE_SILENT_READ;
  185. return pte;
  186. }
  187. static inline pte_t pte_mkwrite(pte_t pte)
  188. {
  189. pte.pte_low |= _PAGE_WRITE;
  190. if (pte.pte_low & _PAGE_MODIFIED) {
  191. pte.pte_low |= _PAGE_SILENT_WRITE;
  192. pte.pte_high |= _PAGE_SILENT_WRITE;
  193. }
  194. return pte;
  195. }
  196. static inline pte_t pte_mkdirty(pte_t pte)
  197. {
  198. pte.pte_low |= _PAGE_MODIFIED;
  199. if (pte.pte_low & _PAGE_WRITE) {
  200. pte.pte_low |= _PAGE_SILENT_WRITE;
  201. pte.pte_high |= _PAGE_SILENT_WRITE;
  202. }
  203. return pte;
  204. }
  205. static inline pte_t pte_mkyoung(pte_t pte)
  206. {
  207. pte.pte_low |= _PAGE_ACCESSED;
  208. if (pte.pte_low & _PAGE_READ) {
  209. pte.pte_low |= _PAGE_SILENT_READ;
  210. pte.pte_high |= _PAGE_SILENT_READ;
  211. }
  212. return pte;
  213. }
  214. #else
  215. static inline int pte_write(pte_t pte) { return pte_val(pte) & _PAGE_WRITE; }
  216. static inline int pte_dirty(pte_t pte) { return pte_val(pte) & _PAGE_MODIFIED; }
  217. static inline int pte_young(pte_t pte) { return pte_val(pte) & _PAGE_ACCESSED; }
  218. static inline int pte_file(pte_t pte) { return pte_val(pte) & _PAGE_FILE; }
  219. static inline pte_t pte_wrprotect(pte_t pte)
  220. {
  221. pte_val(pte) &= ~(_PAGE_WRITE | _PAGE_SILENT_WRITE);
  222. return pte;
  223. }
  224. static inline pte_t pte_mkclean(pte_t pte)
  225. {
  226. pte_val(pte) &= ~(_PAGE_MODIFIED|_PAGE_SILENT_WRITE);
  227. return pte;
  228. }
  229. static inline pte_t pte_mkold(pte_t pte)
  230. {
  231. pte_val(pte) &= ~(_PAGE_ACCESSED|_PAGE_SILENT_READ);
  232. return pte;
  233. }
  234. static inline pte_t pte_mkwrite(pte_t pte)
  235. {
  236. pte_val(pte) |= _PAGE_WRITE;
  237. if (pte_val(pte) & _PAGE_MODIFIED)
  238. pte_val(pte) |= _PAGE_SILENT_WRITE;
  239. return pte;
  240. }
  241. static inline pte_t pte_mkdirty(pte_t pte)
  242. {
  243. pte_val(pte) |= _PAGE_MODIFIED;
  244. if (pte_val(pte) & _PAGE_WRITE)
  245. pte_val(pte) |= _PAGE_SILENT_WRITE;
  246. return pte;
  247. }
  248. static inline pte_t pte_mkyoung(pte_t pte)
  249. {
  250. pte_val(pte) |= _PAGE_ACCESSED;
  251. if (pte_val(pte) & _PAGE_READ)
  252. pte_val(pte) |= _PAGE_SILENT_READ;
  253. return pte;
  254. }
  255. #ifdef _PAGE_HUGE
  256. static inline int pte_huge(pte_t pte) { return pte_val(pte) & _PAGE_HUGE; }
  257. static inline pte_t pte_mkhuge(pte_t pte)
  258. {
  259. pte_val(pte) |= _PAGE_HUGE;
  260. return pte;
  261. }
  262. #endif /* _PAGE_HUGE */
  263. #endif
  264. static inline int pte_special(pte_t pte) { return 0; }
  265. static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
  266. /*
  267. * Macro to make mark a page protection value as "uncacheable". Note
  268. * that "protection" is really a misnomer here as the protection value
  269. * contains the memory attribute bits, dirty bits, and various other
  270. * bits as well.
  271. */
  272. #define pgprot_noncached pgprot_noncached
  273. static inline pgprot_t pgprot_noncached(pgprot_t _prot)
  274. {
  275. unsigned long prot = pgprot_val(_prot);
  276. prot = (prot & ~_CACHE_MASK) | _CACHE_UNCACHED;
  277. return __pgprot(prot);
  278. }
  279. /*
  280. * Conversion functions: convert a page and protection to a page entry,
  281. * and a page entry and page directory to the page they refer to.
  282. */
  283. #define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot))
  284. #if defined(CONFIG_64BIT_PHYS_ADDR) && defined(CONFIG_CPU_MIPS32)
  285. static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
  286. {
  287. pte.pte_low &= _PAGE_CHG_MASK;
  288. pte.pte_high &= ~0x3f;
  289. pte.pte_low |= pgprot_val(newprot);
  290. pte.pte_high |= pgprot_val(newprot) & 0x3f;
  291. return pte;
  292. }
  293. #else
  294. static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
  295. {
  296. return __pte((pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot));
  297. }
  298. #endif
  299. extern void __update_tlb(struct vm_area_struct *vma, unsigned long address,
  300. pte_t pte);
  301. extern void __update_cache(struct vm_area_struct *vma, unsigned long address,
  302. pte_t pte);
  303. static inline void update_mmu_cache(struct vm_area_struct *vma,
  304. unsigned long address, pte_t pte)
  305. {
  306. __update_tlb(vma, address, pte);
  307. __update_cache(vma, address, pte);
  308. }
  309. #define kern_addr_valid(addr) (1)
  310. #ifdef CONFIG_64BIT_PHYS_ADDR
  311. extern int remap_pfn_range(struct vm_area_struct *vma, unsigned long from, unsigned long pfn, unsigned long size, pgprot_t prot);
  312. static inline int io_remap_pfn_range(struct vm_area_struct *vma,
  313. unsigned long vaddr,
  314. unsigned long pfn,
  315. unsigned long size,
  316. pgprot_t prot)
  317. {
  318. phys_t phys_addr_high = fixup_bigphys_addr(pfn << PAGE_SHIFT, size);
  319. return remap_pfn_range(vma, vaddr, phys_addr_high >> PAGE_SHIFT, size, prot);
  320. }
  321. #else
  322. #define io_remap_pfn_range(vma, vaddr, pfn, size, prot) \
  323. remap_pfn_range(vma, vaddr, pfn, size, prot)
  324. #endif
  325. #include <asm-generic/pgtable.h>
  326. /*
  327. * We provide our own get_unmapped area to cope with the virtual aliasing
  328. * constraints placed on us by the cache architecture.
  329. */
  330. #define HAVE_ARCH_UNMAPPED_AREA
  331. /*
  332. * No page table caches to initialise
  333. */
  334. #define pgtable_cache_init() do { } while (0)
  335. #endif /* _ASM_PGTABLE_H */