pgtable.h 11 KB

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