pgtable.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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_WRITE | (cpu_has_rixi ? 0 : _PAGE_READ) | \
  22. _page_cachable_default)
  23. #define PAGE_COPY __pgprot(_PAGE_PRESENT | (cpu_has_rixi ? 0 : _PAGE_READ) | \
  24. (cpu_has_rixi ? _PAGE_NO_EXEC : 0) | _page_cachable_default)
  25. #define PAGE_READONLY __pgprot(_PAGE_PRESENT | (cpu_has_rixi ? 0 : _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 | (cpu_has_rixi ? 0 : _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. * If _PAGE_NO_EXEC is not defined, we can't do page protection for
  35. * execute, and consider it to be the same as read. Also, write
  36. * permissions imply read permissions. This is the closest we can get
  37. * by reasonable means..
  38. */
  39. /*
  40. * Dummy values to fill the table in mmap.c
  41. * The real values will be generated at runtime
  42. */
  43. #define __P000 __pgprot(0)
  44. #define __P001 __pgprot(0)
  45. #define __P010 __pgprot(0)
  46. #define __P011 __pgprot(0)
  47. #define __P100 __pgprot(0)
  48. #define __P101 __pgprot(0)
  49. #define __P110 __pgprot(0)
  50. #define __P111 __pgprot(0)
  51. #define __S000 __pgprot(0)
  52. #define __S001 __pgprot(0)
  53. #define __S010 __pgprot(0)
  54. #define __S011 __pgprot(0)
  55. #define __S100 __pgprot(0)
  56. #define __S101 __pgprot(0)
  57. #define __S110 __pgprot(0)
  58. #define __S111 __pgprot(0)
  59. extern unsigned long _page_cachable_default;
  60. /*
  61. * ZERO_PAGE is a global shared page that is always zero; used
  62. * for zero-mapped memory areas etc..
  63. */
  64. extern unsigned long empty_zero_page;
  65. extern unsigned long zero_page_mask;
  66. #define ZERO_PAGE(vaddr) \
  67. (virt_to_page((void *)(empty_zero_page + (((unsigned long)(vaddr)) & zero_page_mask))))
  68. #define __HAVE_COLOR_ZERO_PAGE
  69. extern void paging_init(void);
  70. /*
  71. * Conversion functions: convert a page and protection to a page entry,
  72. * and a page entry and page directory to the page they refer to.
  73. */
  74. #define pmd_phys(pmd) virt_to_phys((void *)pmd_val(pmd))
  75. #define pmd_page(pmd) (pfn_to_page(pmd_phys(pmd) >> PAGE_SHIFT))
  76. #define pmd_page_vaddr(pmd) pmd_val(pmd)
  77. #if defined(CONFIG_64BIT_PHYS_ADDR) && defined(CONFIG_CPU_MIPS32)
  78. #define pte_none(pte) (!(((pte).pte_low | (pte).pte_high) & ~_PAGE_GLOBAL))
  79. #define pte_present(pte) ((pte).pte_low & _PAGE_PRESENT)
  80. static inline void set_pte(pte_t *ptep, pte_t pte)
  81. {
  82. ptep->pte_high = pte.pte_high;
  83. smp_wmb();
  84. ptep->pte_low = pte.pte_low;
  85. //printk("pte_high %x pte_low %x\n", ptep->pte_high, ptep->pte_low);
  86. if (pte.pte_low & _PAGE_GLOBAL) {
  87. pte_t *buddy = ptep_buddy(ptep);
  88. /*
  89. * Make sure the buddy is global too (if it's !none,
  90. * it better already be global)
  91. */
  92. if (pte_none(*buddy)) {
  93. buddy->pte_low |= _PAGE_GLOBAL;
  94. buddy->pte_high |= _PAGE_GLOBAL;
  95. }
  96. }
  97. }
  98. #define set_pte_at(mm, addr, ptep, pteval) set_pte(ptep, pteval)
  99. static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
  100. {
  101. pte_t null = __pte(0);
  102. /* Preserve global status for the pair */
  103. if (ptep_buddy(ptep)->pte_low & _PAGE_GLOBAL)
  104. null.pte_low = null.pte_high = _PAGE_GLOBAL;
  105. set_pte_at(mm, addr, ptep, null);
  106. }
  107. #else
  108. #define pte_none(pte) (!(pte_val(pte) & ~_PAGE_GLOBAL))
  109. #define pte_present(pte) (pte_val(pte) & _PAGE_PRESENT)
  110. /*
  111. * Certain architectures need to do special things when pte's
  112. * within a page table are directly modified. Thus, the following
  113. * hook is made available.
  114. */
  115. static inline void set_pte(pte_t *ptep, pte_t pteval)
  116. {
  117. *ptep = pteval;
  118. #if !defined(CONFIG_CPU_R3000) && !defined(CONFIG_CPU_TX39XX)
  119. if (pte_val(pteval) & _PAGE_GLOBAL) {
  120. pte_t *buddy = ptep_buddy(ptep);
  121. /*
  122. * Make sure the buddy is global too (if it's !none,
  123. * it better already be global)
  124. */
  125. if (pte_none(*buddy))
  126. pte_val(*buddy) = pte_val(*buddy) | _PAGE_GLOBAL;
  127. }
  128. #endif
  129. }
  130. #define set_pte_at(mm, addr, ptep, pteval) set_pte(ptep, pteval)
  131. static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
  132. {
  133. #if !defined(CONFIG_CPU_R3000) && !defined(CONFIG_CPU_TX39XX)
  134. /* Preserve global status for the pair */
  135. if (pte_val(*ptep_buddy(ptep)) & _PAGE_GLOBAL)
  136. set_pte_at(mm, addr, ptep, __pte(_PAGE_GLOBAL));
  137. else
  138. #endif
  139. set_pte_at(mm, addr, ptep, __pte(0));
  140. }
  141. #endif
  142. /*
  143. * (pmds are folded into puds so this doesn't get actually called,
  144. * but the define is needed for a generic inline function.)
  145. */
  146. #define set_pmd(pmdptr, pmdval) do { *(pmdptr) = (pmdval); } while(0)
  147. #ifndef __PAGETABLE_PMD_FOLDED
  148. /*
  149. * (puds are folded into pgds so this doesn't get actually called,
  150. * but the define is needed for a generic inline function.)
  151. */
  152. #define set_pud(pudptr, pudval) do { *(pudptr) = (pudval); } while(0)
  153. #endif
  154. #define PGD_T_LOG2 (__builtin_ffs(sizeof(pgd_t)) - 1)
  155. #define PMD_T_LOG2 (__builtin_ffs(sizeof(pmd_t)) - 1)
  156. #define PTE_T_LOG2 (__builtin_ffs(sizeof(pte_t)) - 1)
  157. /*
  158. * We used to declare this array with size but gcc 3.3 and older are not able
  159. * to find that this expression is a constant, so the size is dropped.
  160. */
  161. extern pgd_t swapper_pg_dir[];
  162. /*
  163. * The following only work if pte_present() is true.
  164. * Undefined behaviour if not..
  165. */
  166. #if defined(CONFIG_64BIT_PHYS_ADDR) && defined(CONFIG_CPU_MIPS32)
  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_mkclean(pte_t pte)
  178. {
  179. pte.pte_low &= ~(_PAGE_MODIFIED | _PAGE_SILENT_WRITE);
  180. pte.pte_high &= ~_PAGE_SILENT_WRITE;
  181. return pte;
  182. }
  183. static inline pte_t pte_mkold(pte_t pte)
  184. {
  185. pte.pte_low &= ~(_PAGE_ACCESSED | _PAGE_SILENT_READ);
  186. pte.pte_high &= ~_PAGE_SILENT_READ;
  187. return pte;
  188. }
  189. static inline pte_t pte_mkwrite(pte_t pte)
  190. {
  191. pte.pte_low |= _PAGE_WRITE;
  192. if (pte.pte_low & _PAGE_MODIFIED) {
  193. pte.pte_low |= _PAGE_SILENT_WRITE;
  194. pte.pte_high |= _PAGE_SILENT_WRITE;
  195. }
  196. return pte;
  197. }
  198. static inline pte_t pte_mkdirty(pte_t pte)
  199. {
  200. pte.pte_low |= _PAGE_MODIFIED;
  201. if (pte.pte_low & _PAGE_WRITE) {
  202. pte.pte_low |= _PAGE_SILENT_WRITE;
  203. pte.pte_high |= _PAGE_SILENT_WRITE;
  204. }
  205. return pte;
  206. }
  207. static inline pte_t pte_mkyoung(pte_t pte)
  208. {
  209. pte.pte_low |= _PAGE_ACCESSED;
  210. if (pte.pte_low & _PAGE_READ) {
  211. pte.pte_low |= _PAGE_SILENT_READ;
  212. pte.pte_high |= _PAGE_SILENT_READ;
  213. }
  214. return pte;
  215. }
  216. #else
  217. static inline int pte_write(pte_t pte) { return pte_val(pte) & _PAGE_WRITE; }
  218. static inline int pte_dirty(pte_t pte) { return pte_val(pte) & _PAGE_MODIFIED; }
  219. static inline int pte_young(pte_t pte) { return pte_val(pte) & _PAGE_ACCESSED; }
  220. static inline int pte_file(pte_t pte) { return pte_val(pte) & _PAGE_FILE; }
  221. static inline pte_t pte_wrprotect(pte_t pte)
  222. {
  223. pte_val(pte) &= ~(_PAGE_WRITE | _PAGE_SILENT_WRITE);
  224. return pte;
  225. }
  226. static inline pte_t pte_mkclean(pte_t pte)
  227. {
  228. pte_val(pte) &= ~(_PAGE_MODIFIED|_PAGE_SILENT_WRITE);
  229. return pte;
  230. }
  231. static inline pte_t pte_mkold(pte_t pte)
  232. {
  233. pte_val(pte) &= ~(_PAGE_ACCESSED|_PAGE_SILENT_READ);
  234. return pte;
  235. }
  236. static inline pte_t pte_mkwrite(pte_t pte)
  237. {
  238. pte_val(pte) |= _PAGE_WRITE;
  239. if (pte_val(pte) & _PAGE_MODIFIED)
  240. pte_val(pte) |= _PAGE_SILENT_WRITE;
  241. return pte;
  242. }
  243. static inline pte_t pte_mkdirty(pte_t pte)
  244. {
  245. pte_val(pte) |= _PAGE_MODIFIED;
  246. if (pte_val(pte) & _PAGE_WRITE)
  247. pte_val(pte) |= _PAGE_SILENT_WRITE;
  248. return pte;
  249. }
  250. static inline pte_t pte_mkyoung(pte_t pte)
  251. {
  252. pte_val(pte) |= _PAGE_ACCESSED;
  253. if (cpu_has_rixi) {
  254. if (!(pte_val(pte) & _PAGE_NO_READ))
  255. pte_val(pte) |= _PAGE_SILENT_READ;
  256. } else {
  257. if (pte_val(pte) & _PAGE_READ)
  258. pte_val(pte) |= _PAGE_SILENT_READ;
  259. }
  260. return pte;
  261. }
  262. #ifdef _PAGE_HUGE
  263. static inline int pte_huge(pte_t pte) { return pte_val(pte) & _PAGE_HUGE; }
  264. static inline pte_t pte_mkhuge(pte_t pte)
  265. {
  266. pte_val(pte) |= _PAGE_HUGE;
  267. return pte;
  268. }
  269. #endif /* _PAGE_HUGE */
  270. #endif
  271. static inline int pte_special(pte_t pte) { return 0; }
  272. static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
  273. /*
  274. * Macro to make mark a page protection value as "uncacheable". Note
  275. * that "protection" is really a misnomer here as the protection value
  276. * contains the memory attribute bits, dirty bits, and various other
  277. * bits as well.
  278. */
  279. #define pgprot_noncached pgprot_noncached
  280. static inline pgprot_t pgprot_noncached(pgprot_t _prot)
  281. {
  282. unsigned long prot = pgprot_val(_prot);
  283. prot = (prot & ~_CACHE_MASK) | _CACHE_UNCACHED;
  284. return __pgprot(prot);
  285. }
  286. /*
  287. * Conversion functions: convert a page and protection to a page entry,
  288. * and a page entry and page directory to the page they refer to.
  289. */
  290. #define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot))
  291. #if defined(CONFIG_64BIT_PHYS_ADDR) && defined(CONFIG_CPU_MIPS32)
  292. static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
  293. {
  294. pte.pte_low &= _PAGE_CHG_MASK;
  295. pte.pte_high &= ~0x3f;
  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 *ptep)
  312. {
  313. pte_t pte = *ptep;
  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. * uncached accelerated TLB map for video memory access
  336. */
  337. #ifdef CONFIG_CPU_SUPPORTS_UNCACHED_ACCELERATED
  338. #define __HAVE_PHYS_MEM_ACCESS_PROT
  339. struct file;
  340. pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
  341. unsigned long size, pgprot_t vma_prot);
  342. int phys_mem_access_prot_allowed(struct file *file, unsigned long pfn,
  343. unsigned long size, pgprot_t *vma_prot);
  344. #endif
  345. /*
  346. * We provide our own get_unmapped area to cope with the virtual aliasing
  347. * constraints placed on us by the cache architecture.
  348. */
  349. #define HAVE_ARCH_UNMAPPED_AREA
  350. #define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
  351. /*
  352. * No page table caches to initialise
  353. */
  354. #define pgtable_cache_init() do { } while (0)
  355. #endif /* _ASM_PGTABLE_H */