pgtable.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  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. #define is_zero_pfn is_zero_pfn
  68. static inline int is_zero_pfn(unsigned long pfn)
  69. {
  70. extern unsigned long zero_pfn;
  71. unsigned long offset_from_zero_pfn = pfn - zero_pfn;
  72. return offset_from_zero_pfn <= (zero_page_mask >> PAGE_SHIFT);
  73. }
  74. #define my_zero_pfn(addr) page_to_pfn(ZERO_PAGE(addr))
  75. extern void paging_init(void);
  76. /*
  77. * Conversion functions: convert a page and protection to a page entry,
  78. * and a page entry and page directory to the page they refer to.
  79. */
  80. #define pmd_phys(pmd) virt_to_phys((void *)pmd_val(pmd))
  81. #define pmd_page(pmd) (pfn_to_page(pmd_phys(pmd) >> PAGE_SHIFT))
  82. #define pmd_page_vaddr(pmd) pmd_val(pmd)
  83. #if defined(CONFIG_64BIT_PHYS_ADDR) && defined(CONFIG_CPU_MIPS32)
  84. #define pte_none(pte) (!(((pte).pte_low | (pte).pte_high) & ~_PAGE_GLOBAL))
  85. #define pte_present(pte) ((pte).pte_low & _PAGE_PRESENT)
  86. static inline void set_pte(pte_t *ptep, pte_t pte)
  87. {
  88. ptep->pte_high = pte.pte_high;
  89. smp_wmb();
  90. ptep->pte_low = pte.pte_low;
  91. //printk("pte_high %x pte_low %x\n", ptep->pte_high, ptep->pte_low);
  92. if (pte.pte_low & _PAGE_GLOBAL) {
  93. pte_t *buddy = ptep_buddy(ptep);
  94. /*
  95. * Make sure the buddy is global too (if it's !none,
  96. * it better already be global)
  97. */
  98. if (pte_none(*buddy)) {
  99. buddy->pte_low |= _PAGE_GLOBAL;
  100. buddy->pte_high |= _PAGE_GLOBAL;
  101. }
  102. }
  103. }
  104. #define set_pte_at(mm, addr, ptep, pteval) set_pte(ptep, pteval)
  105. static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
  106. {
  107. pte_t null = __pte(0);
  108. /* Preserve global status for the pair */
  109. if (ptep_buddy(ptep)->pte_low & _PAGE_GLOBAL)
  110. null.pte_low = null.pte_high = _PAGE_GLOBAL;
  111. set_pte_at(mm, addr, ptep, null);
  112. }
  113. #else
  114. #define pte_none(pte) (!(pte_val(pte) & ~_PAGE_GLOBAL))
  115. #define pte_present(pte) (pte_val(pte) & _PAGE_PRESENT)
  116. /*
  117. * Certain architectures need to do special things when pte's
  118. * within a page table are directly modified. Thus, the following
  119. * hook is made available.
  120. */
  121. static inline void set_pte(pte_t *ptep, pte_t pteval)
  122. {
  123. *ptep = pteval;
  124. #if !defined(CONFIG_CPU_R3000) && !defined(CONFIG_CPU_TX39XX)
  125. if (pte_val(pteval) & _PAGE_GLOBAL) {
  126. pte_t *buddy = ptep_buddy(ptep);
  127. /*
  128. * Make sure the buddy is global too (if it's !none,
  129. * it better already be global)
  130. */
  131. if (pte_none(*buddy))
  132. pte_val(*buddy) = pte_val(*buddy) | _PAGE_GLOBAL;
  133. }
  134. #endif
  135. }
  136. #define set_pte_at(mm, addr, ptep, pteval) set_pte(ptep, pteval)
  137. static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
  138. {
  139. #if !defined(CONFIG_CPU_R3000) && !defined(CONFIG_CPU_TX39XX)
  140. /* Preserve global status for the pair */
  141. if (pte_val(*ptep_buddy(ptep)) & _PAGE_GLOBAL)
  142. set_pte_at(mm, addr, ptep, __pte(_PAGE_GLOBAL));
  143. else
  144. #endif
  145. set_pte_at(mm, addr, ptep, __pte(0));
  146. }
  147. #endif
  148. /*
  149. * (pmds are folded into puds so this doesn't get actually called,
  150. * but the define is needed for a generic inline function.)
  151. */
  152. #define set_pmd(pmdptr, pmdval) do { *(pmdptr) = (pmdval); } while(0)
  153. #ifdef CONFIG_64BIT
  154. /*
  155. * (puds are folded into pgds so this doesn't get actually called,
  156. * but the define is needed for a generic inline function.)
  157. */
  158. #define set_pud(pudptr, pudval) do { *(pudptr) = (pudval); } while(0)
  159. #endif
  160. #define PGD_T_LOG2 (__builtin_ffs(sizeof(pgd_t)) - 1)
  161. #define PMD_T_LOG2 (__builtin_ffs(sizeof(pmd_t)) - 1)
  162. #define PTE_T_LOG2 (__builtin_ffs(sizeof(pte_t)) - 1)
  163. /*
  164. * We used to declare this array with size but gcc 3.3 and older are not able
  165. * to find that this expression is a constant, so the size is dropped.
  166. */
  167. extern pgd_t swapper_pg_dir[];
  168. /*
  169. * The following only work if pte_present() is true.
  170. * Undefined behaviour if not..
  171. */
  172. #if defined(CONFIG_64BIT_PHYS_ADDR) && defined(CONFIG_CPU_MIPS32)
  173. static inline int pte_write(pte_t pte) { return pte.pte_low & _PAGE_WRITE; }
  174. static inline int pte_dirty(pte_t pte) { return pte.pte_low & _PAGE_MODIFIED; }
  175. static inline int pte_young(pte_t pte) { return pte.pte_low & _PAGE_ACCESSED; }
  176. static inline int pte_file(pte_t pte) { return pte.pte_low & _PAGE_FILE; }
  177. static inline pte_t pte_wrprotect(pte_t pte)
  178. {
  179. pte.pte_low &= ~(_PAGE_WRITE | _PAGE_SILENT_WRITE);
  180. pte.pte_high &= ~_PAGE_SILENT_WRITE;
  181. return pte;
  182. }
  183. static inline pte_t pte_mkclean(pte_t pte)
  184. {
  185. pte.pte_low &= ~(_PAGE_MODIFIED | _PAGE_SILENT_WRITE);
  186. pte.pte_high &= ~_PAGE_SILENT_WRITE;
  187. return pte;
  188. }
  189. static inline pte_t pte_mkold(pte_t pte)
  190. {
  191. pte.pte_low &= ~(_PAGE_ACCESSED | _PAGE_SILENT_READ);
  192. pte.pte_high &= ~_PAGE_SILENT_READ;
  193. return pte;
  194. }
  195. static inline pte_t pte_mkwrite(pte_t pte)
  196. {
  197. pte.pte_low |= _PAGE_WRITE;
  198. if (pte.pte_low & _PAGE_MODIFIED) {
  199. pte.pte_low |= _PAGE_SILENT_WRITE;
  200. pte.pte_high |= _PAGE_SILENT_WRITE;
  201. }
  202. return pte;
  203. }
  204. static inline pte_t pte_mkdirty(pte_t pte)
  205. {
  206. pte.pte_low |= _PAGE_MODIFIED;
  207. if (pte.pte_low & _PAGE_WRITE) {
  208. pte.pte_low |= _PAGE_SILENT_WRITE;
  209. pte.pte_high |= _PAGE_SILENT_WRITE;
  210. }
  211. return pte;
  212. }
  213. static inline pte_t pte_mkyoung(pte_t pte)
  214. {
  215. pte.pte_low |= _PAGE_ACCESSED;
  216. if (pte.pte_low & _PAGE_READ) {
  217. pte.pte_low |= _PAGE_SILENT_READ;
  218. pte.pte_high |= _PAGE_SILENT_READ;
  219. }
  220. return pte;
  221. }
  222. #else
  223. static inline int pte_write(pte_t pte) { return pte_val(pte) & _PAGE_WRITE; }
  224. static inline int pte_dirty(pte_t pte) { return pte_val(pte) & _PAGE_MODIFIED; }
  225. static inline int pte_young(pte_t pte) { return pte_val(pte) & _PAGE_ACCESSED; }
  226. static inline int pte_file(pte_t pte) { return pte_val(pte) & _PAGE_FILE; }
  227. static inline pte_t pte_wrprotect(pte_t pte)
  228. {
  229. pte_val(pte) &= ~(_PAGE_WRITE | _PAGE_SILENT_WRITE);
  230. return pte;
  231. }
  232. static inline pte_t pte_mkclean(pte_t pte)
  233. {
  234. pte_val(pte) &= ~(_PAGE_MODIFIED|_PAGE_SILENT_WRITE);
  235. return pte;
  236. }
  237. static inline pte_t pte_mkold(pte_t pte)
  238. {
  239. pte_val(pte) &= ~(_PAGE_ACCESSED|_PAGE_SILENT_READ);
  240. return pte;
  241. }
  242. static inline pte_t pte_mkwrite(pte_t pte)
  243. {
  244. pte_val(pte) |= _PAGE_WRITE;
  245. if (pte_val(pte) & _PAGE_MODIFIED)
  246. pte_val(pte) |= _PAGE_SILENT_WRITE;
  247. return pte;
  248. }
  249. static inline pte_t pte_mkdirty(pte_t pte)
  250. {
  251. pte_val(pte) |= _PAGE_MODIFIED;
  252. if (pte_val(pte) & _PAGE_WRITE)
  253. pte_val(pte) |= _PAGE_SILENT_WRITE;
  254. return pte;
  255. }
  256. static inline pte_t pte_mkyoung(pte_t pte)
  257. {
  258. pte_val(pte) |= _PAGE_ACCESSED;
  259. if (pte_val(pte) & _PAGE_READ)
  260. pte_val(pte) |= _PAGE_SILENT_READ;
  261. return pte;
  262. }
  263. #ifdef _PAGE_HUGE
  264. static inline int pte_huge(pte_t pte) { return pte_val(pte) & _PAGE_HUGE; }
  265. static inline pte_t pte_mkhuge(pte_t pte)
  266. {
  267. pte_val(pte) |= _PAGE_HUGE;
  268. return pte;
  269. }
  270. #endif /* _PAGE_HUGE */
  271. #endif
  272. static inline int pte_special(pte_t pte) { return 0; }
  273. static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
  274. /*
  275. * Macro to make mark a page protection value as "uncacheable". Note
  276. * that "protection" is really a misnomer here as the protection value
  277. * contains the memory attribute bits, dirty bits, and various other
  278. * bits as well.
  279. */
  280. #define pgprot_noncached pgprot_noncached
  281. static inline pgprot_t pgprot_noncached(pgprot_t _prot)
  282. {
  283. unsigned long prot = pgprot_val(_prot);
  284. prot = (prot & ~_CACHE_MASK) | _CACHE_UNCACHED;
  285. return __pgprot(prot);
  286. }
  287. /*
  288. * Conversion functions: convert a page and protection to a page entry,
  289. * and a page entry and page directory to the page they refer to.
  290. */
  291. #define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot))
  292. #if defined(CONFIG_64BIT_PHYS_ADDR) && defined(CONFIG_CPU_MIPS32)
  293. static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
  294. {
  295. pte.pte_low &= _PAGE_CHG_MASK;
  296. pte.pte_high &= ~0x3f;
  297. pte.pte_low |= pgprot_val(newprot);
  298. pte.pte_high |= pgprot_val(newprot) & 0x3f;
  299. return pte;
  300. }
  301. #else
  302. static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
  303. {
  304. return __pte((pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot));
  305. }
  306. #endif
  307. extern void __update_tlb(struct vm_area_struct *vma, unsigned long address,
  308. pte_t pte);
  309. extern void __update_cache(struct vm_area_struct *vma, unsigned long address,
  310. pte_t pte);
  311. static inline void update_mmu_cache(struct vm_area_struct *vma,
  312. unsigned long address, pte_t pte)
  313. {
  314. __update_tlb(vma, address, pte);
  315. __update_cache(vma, address, pte);
  316. }
  317. #define kern_addr_valid(addr) (1)
  318. #ifdef CONFIG_64BIT_PHYS_ADDR
  319. extern int remap_pfn_range(struct vm_area_struct *vma, unsigned long from, unsigned long pfn, unsigned long size, pgprot_t prot);
  320. static inline int io_remap_pfn_range(struct vm_area_struct *vma,
  321. unsigned long vaddr,
  322. unsigned long pfn,
  323. unsigned long size,
  324. pgprot_t prot)
  325. {
  326. phys_t phys_addr_high = fixup_bigphys_addr(pfn << PAGE_SHIFT, size);
  327. return remap_pfn_range(vma, vaddr, phys_addr_high >> PAGE_SHIFT, size, prot);
  328. }
  329. #else
  330. #define io_remap_pfn_range(vma, vaddr, pfn, size, prot) \
  331. remap_pfn_range(vma, vaddr, pfn, size, prot)
  332. #endif
  333. #include <asm-generic/pgtable.h>
  334. /*
  335. * We provide our own get_unmapped area to cope with the virtual aliasing
  336. * constraints placed on us by the cache architecture.
  337. */
  338. #define HAVE_ARCH_UNMAPPED_AREA
  339. /*
  340. * No page table caches to initialise
  341. */
  342. #define pgtable_cache_init() do { } while (0)
  343. #endif /* _ASM_PGTABLE_H */