pgtable.h 11 KB

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