pgtable.h 11 KB

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