pgtable.h 11 KB

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