pgtable.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  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 | (kernel_uses_smartmips_rixi ? 0 : _PAGE_READ) | \
  22. _page_cachable_default)
  23. #define PAGE_COPY __pgprot(_PAGE_PRESENT | (kernel_uses_smartmips_rixi ? 0 : _PAGE_READ) | \
  24. (kernel_uses_smartmips_rixi ? _PAGE_NO_EXEC : 0) | _page_cachable_default)
  25. #define PAGE_READONLY __pgprot(_PAGE_PRESENT | (kernel_uses_smartmips_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 | (kernel_uses_smartmips_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 is_zero_pfn is_zero_pfn
  69. static inline int is_zero_pfn(unsigned long pfn)
  70. {
  71. extern unsigned long zero_pfn;
  72. unsigned long offset_from_zero_pfn = pfn - zero_pfn;
  73. return offset_from_zero_pfn <= (zero_page_mask >> PAGE_SHIFT);
  74. }
  75. #define my_zero_pfn(addr) page_to_pfn(ZERO_PAGE(addr))
  76. extern void paging_init(void);
  77. /*
  78. * Conversion functions: convert a page and protection to a page entry,
  79. * and a page entry and page directory to the page they refer to.
  80. */
  81. #define pmd_phys(pmd) virt_to_phys((void *)pmd_val(pmd))
  82. #define pmd_page(pmd) (pfn_to_page(pmd_phys(pmd) >> PAGE_SHIFT))
  83. #define pmd_page_vaddr(pmd) pmd_val(pmd)
  84. #if defined(CONFIG_64BIT_PHYS_ADDR) && defined(CONFIG_CPU_MIPS32)
  85. #define pte_none(pte) (!(((pte).pte_low | (pte).pte_high) & ~_PAGE_GLOBAL))
  86. #define pte_present(pte) ((pte).pte_low & _PAGE_PRESENT)
  87. static inline void set_pte(pte_t *ptep, pte_t pte)
  88. {
  89. ptep->pte_high = pte.pte_high;
  90. smp_wmb();
  91. ptep->pte_low = pte.pte_low;
  92. //printk("pte_high %x pte_low %x\n", ptep->pte_high, ptep->pte_low);
  93. if (pte.pte_low & _PAGE_GLOBAL) {
  94. pte_t *buddy = ptep_buddy(ptep);
  95. /*
  96. * Make sure the buddy is global too (if it's !none,
  97. * it better already be global)
  98. */
  99. if (pte_none(*buddy)) {
  100. buddy->pte_low |= _PAGE_GLOBAL;
  101. buddy->pte_high |= _PAGE_GLOBAL;
  102. }
  103. }
  104. }
  105. #define set_pte_at(mm, addr, ptep, pteval) set_pte(ptep, pteval)
  106. static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
  107. {
  108. pte_t null = __pte(0);
  109. /* Preserve global status for the pair */
  110. if (ptep_buddy(ptep)->pte_low & _PAGE_GLOBAL)
  111. null.pte_low = null.pte_high = _PAGE_GLOBAL;
  112. set_pte_at(mm, addr, ptep, null);
  113. }
  114. #else
  115. #define pte_none(pte) (!(pte_val(pte) & ~_PAGE_GLOBAL))
  116. #define pte_present(pte) (pte_val(pte) & _PAGE_PRESENT)
  117. /*
  118. * Certain architectures need to do special things when pte's
  119. * within a page table are directly modified. Thus, the following
  120. * hook is made available.
  121. */
  122. static inline void set_pte(pte_t *ptep, pte_t pteval)
  123. {
  124. *ptep = pteval;
  125. #if !defined(CONFIG_CPU_R3000) && !defined(CONFIG_CPU_TX39XX)
  126. if (pte_val(pteval) & _PAGE_GLOBAL) {
  127. pte_t *buddy = ptep_buddy(ptep);
  128. /*
  129. * Make sure the buddy is global too (if it's !none,
  130. * it better already be global)
  131. */
  132. #ifdef CONFIG_SMP
  133. /*
  134. * For SMP, multiple CPUs can race, so we need to do
  135. * this atomically.
  136. */
  137. #ifdef CONFIG_64BIT
  138. #define LL_INSN "lld"
  139. #define SC_INSN "scd"
  140. #else /* CONFIG_32BIT */
  141. #define LL_INSN "ll"
  142. #define SC_INSN "sc"
  143. #endif
  144. unsigned long page_global = _PAGE_GLOBAL;
  145. unsigned long tmp;
  146. __asm__ __volatile__ (
  147. " .set push\n"
  148. " .set noreorder\n"
  149. "1: " LL_INSN " %[tmp], %[buddy]\n"
  150. " bnez %[tmp], 2f\n"
  151. " or %[tmp], %[tmp], %[global]\n"
  152. " " SC_INSN " %[tmp], %[buddy]\n"
  153. " beqz %[tmp], 1b\n"
  154. " nop\n"
  155. "2:\n"
  156. " .set pop"
  157. : [buddy] "+m" (buddy->pte),
  158. [tmp] "=&r" (tmp)
  159. : [global] "r" (page_global));
  160. #else /* !CONFIG_SMP */
  161. if (pte_none(*buddy))
  162. pte_val(*buddy) = pte_val(*buddy) | _PAGE_GLOBAL;
  163. #endif /* CONFIG_SMP */
  164. }
  165. #endif
  166. }
  167. #define set_pte_at(mm, addr, ptep, pteval) set_pte(ptep, pteval)
  168. static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
  169. {
  170. #if !defined(CONFIG_CPU_R3000) && !defined(CONFIG_CPU_TX39XX)
  171. /* Preserve global status for the pair */
  172. if (pte_val(*ptep_buddy(ptep)) & _PAGE_GLOBAL)
  173. set_pte_at(mm, addr, ptep, __pte(_PAGE_GLOBAL));
  174. else
  175. #endif
  176. set_pte_at(mm, addr, ptep, __pte(0));
  177. }
  178. #endif
  179. /*
  180. * (pmds are folded into puds so this doesn't get actually called,
  181. * but the define is needed for a generic inline function.)
  182. */
  183. #define set_pmd(pmdptr, pmdval) do { *(pmdptr) = (pmdval); } while(0)
  184. #ifndef __PAGETABLE_PMD_FOLDED
  185. /*
  186. * (puds are folded into pgds so this doesn't get actually called,
  187. * but the define is needed for a generic inline function.)
  188. */
  189. #define set_pud(pudptr, pudval) do { *(pudptr) = (pudval); } while(0)
  190. #endif
  191. #define PGD_T_LOG2 (__builtin_ffs(sizeof(pgd_t)) - 1)
  192. #define PMD_T_LOG2 (__builtin_ffs(sizeof(pmd_t)) - 1)
  193. #define PTE_T_LOG2 (__builtin_ffs(sizeof(pte_t)) - 1)
  194. /*
  195. * We used to declare this array with size but gcc 3.3 and older are not able
  196. * to find that this expression is a constant, so the size is dropped.
  197. */
  198. extern pgd_t swapper_pg_dir[];
  199. /*
  200. * The following only work if pte_present() is true.
  201. * Undefined behaviour if not..
  202. */
  203. #if defined(CONFIG_64BIT_PHYS_ADDR) && defined(CONFIG_CPU_MIPS32)
  204. static inline int pte_write(pte_t pte) { return pte.pte_low & _PAGE_WRITE; }
  205. static inline int pte_dirty(pte_t pte) { return pte.pte_low & _PAGE_MODIFIED; }
  206. static inline int pte_young(pte_t pte) { return pte.pte_low & _PAGE_ACCESSED; }
  207. static inline int pte_file(pte_t pte) { return pte.pte_low & _PAGE_FILE; }
  208. static inline pte_t pte_wrprotect(pte_t pte)
  209. {
  210. pte.pte_low &= ~(_PAGE_WRITE | _PAGE_SILENT_WRITE);
  211. pte.pte_high &= ~_PAGE_SILENT_WRITE;
  212. return pte;
  213. }
  214. static inline pte_t pte_mkclean(pte_t pte)
  215. {
  216. pte.pte_low &= ~(_PAGE_MODIFIED | _PAGE_SILENT_WRITE);
  217. pte.pte_high &= ~_PAGE_SILENT_WRITE;
  218. return pte;
  219. }
  220. static inline pte_t pte_mkold(pte_t pte)
  221. {
  222. pte.pte_low &= ~(_PAGE_ACCESSED | _PAGE_SILENT_READ);
  223. pte.pte_high &= ~_PAGE_SILENT_READ;
  224. return pte;
  225. }
  226. static inline pte_t pte_mkwrite(pte_t pte)
  227. {
  228. pte.pte_low |= _PAGE_WRITE;
  229. if (pte.pte_low & _PAGE_MODIFIED) {
  230. pte.pte_low |= _PAGE_SILENT_WRITE;
  231. pte.pte_high |= _PAGE_SILENT_WRITE;
  232. }
  233. return pte;
  234. }
  235. static inline pte_t pte_mkdirty(pte_t pte)
  236. {
  237. pte.pte_low |= _PAGE_MODIFIED;
  238. if (pte.pte_low & _PAGE_WRITE) {
  239. pte.pte_low |= _PAGE_SILENT_WRITE;
  240. pte.pte_high |= _PAGE_SILENT_WRITE;
  241. }
  242. return pte;
  243. }
  244. static inline pte_t pte_mkyoung(pte_t pte)
  245. {
  246. pte.pte_low |= _PAGE_ACCESSED;
  247. if (pte.pte_low & _PAGE_READ) {
  248. pte.pte_low |= _PAGE_SILENT_READ;
  249. pte.pte_high |= _PAGE_SILENT_READ;
  250. }
  251. return pte;
  252. }
  253. #else
  254. static inline int pte_write(pte_t pte) { return pte_val(pte) & _PAGE_WRITE; }
  255. static inline int pte_dirty(pte_t pte) { return pte_val(pte) & _PAGE_MODIFIED; }
  256. static inline int pte_young(pte_t pte) { return pte_val(pte) & _PAGE_ACCESSED; }
  257. static inline int pte_file(pte_t pte) { return pte_val(pte) & _PAGE_FILE; }
  258. static inline pte_t pte_wrprotect(pte_t pte)
  259. {
  260. pte_val(pte) &= ~(_PAGE_WRITE | _PAGE_SILENT_WRITE);
  261. return pte;
  262. }
  263. static inline pte_t pte_mkclean(pte_t pte)
  264. {
  265. pte_val(pte) &= ~(_PAGE_MODIFIED|_PAGE_SILENT_WRITE);
  266. return pte;
  267. }
  268. static inline pte_t pte_mkold(pte_t pte)
  269. {
  270. pte_val(pte) &= ~(_PAGE_ACCESSED|_PAGE_SILENT_READ);
  271. return pte;
  272. }
  273. static inline pte_t pte_mkwrite(pte_t pte)
  274. {
  275. pte_val(pte) |= _PAGE_WRITE;
  276. if (pte_val(pte) & _PAGE_MODIFIED)
  277. pte_val(pte) |= _PAGE_SILENT_WRITE;
  278. return pte;
  279. }
  280. static inline pte_t pte_mkdirty(pte_t pte)
  281. {
  282. pte_val(pte) |= _PAGE_MODIFIED;
  283. if (pte_val(pte) & _PAGE_WRITE)
  284. pte_val(pte) |= _PAGE_SILENT_WRITE;
  285. return pte;
  286. }
  287. static inline pte_t pte_mkyoung(pte_t pte)
  288. {
  289. pte_val(pte) |= _PAGE_ACCESSED;
  290. if (kernel_uses_smartmips_rixi) {
  291. if (!(pte_val(pte) & _PAGE_NO_READ))
  292. pte_val(pte) |= _PAGE_SILENT_READ;
  293. } else {
  294. if (pte_val(pte) & _PAGE_READ)
  295. pte_val(pte) |= _PAGE_SILENT_READ;
  296. }
  297. return pte;
  298. }
  299. #ifdef _PAGE_HUGE
  300. static inline int pte_huge(pte_t pte) { return pte_val(pte) & _PAGE_HUGE; }
  301. static inline pte_t pte_mkhuge(pte_t pte)
  302. {
  303. pte_val(pte) |= _PAGE_HUGE;
  304. return pte;
  305. }
  306. #endif /* _PAGE_HUGE */
  307. #endif
  308. static inline int pte_special(pte_t pte) { return 0; }
  309. static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
  310. /*
  311. * Macro to make mark a page protection value as "uncacheable". Note
  312. * that "protection" is really a misnomer here as the protection value
  313. * contains the memory attribute bits, dirty bits, and various other
  314. * bits as well.
  315. */
  316. #define pgprot_noncached pgprot_noncached
  317. static inline pgprot_t pgprot_noncached(pgprot_t _prot)
  318. {
  319. unsigned long prot = pgprot_val(_prot);
  320. prot = (prot & ~_CACHE_MASK) | _CACHE_UNCACHED;
  321. return __pgprot(prot);
  322. }
  323. /*
  324. * Conversion functions: convert a page and protection to a page entry,
  325. * and a page entry and page directory to the page they refer to.
  326. */
  327. #define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot))
  328. #if defined(CONFIG_64BIT_PHYS_ADDR) && defined(CONFIG_CPU_MIPS32)
  329. static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
  330. {
  331. pte.pte_low &= _PAGE_CHG_MASK;
  332. pte.pte_high &= ~0x3f;
  333. pte.pte_low |= pgprot_val(newprot);
  334. pte.pte_high |= pgprot_val(newprot) & 0x3f;
  335. return pte;
  336. }
  337. #else
  338. static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
  339. {
  340. return __pte((pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot));
  341. }
  342. #endif
  343. extern void __update_tlb(struct vm_area_struct *vma, unsigned long address,
  344. pte_t pte);
  345. extern void __update_cache(struct vm_area_struct *vma, unsigned long address,
  346. pte_t pte);
  347. static inline void update_mmu_cache(struct vm_area_struct *vma,
  348. unsigned long address, pte_t *ptep)
  349. {
  350. pte_t pte = *ptep;
  351. __update_tlb(vma, address, pte);
  352. __update_cache(vma, address, pte);
  353. }
  354. #define kern_addr_valid(addr) (1)
  355. #ifdef CONFIG_64BIT_PHYS_ADDR
  356. extern int remap_pfn_range(struct vm_area_struct *vma, unsigned long from, unsigned long pfn, unsigned long size, pgprot_t prot);
  357. static inline int io_remap_pfn_range(struct vm_area_struct *vma,
  358. unsigned long vaddr,
  359. unsigned long pfn,
  360. unsigned long size,
  361. pgprot_t prot)
  362. {
  363. phys_t phys_addr_high = fixup_bigphys_addr(pfn << PAGE_SHIFT, size);
  364. return remap_pfn_range(vma, vaddr, phys_addr_high >> PAGE_SHIFT, size, prot);
  365. }
  366. #else
  367. #define io_remap_pfn_range(vma, vaddr, pfn, size, prot) \
  368. remap_pfn_range(vma, vaddr, pfn, size, prot)
  369. #endif
  370. #include <asm-generic/pgtable.h>
  371. /*
  372. * uncached accelerated TLB map for video memory access
  373. */
  374. #ifdef CONFIG_CPU_SUPPORTS_UNCACHED_ACCELERATED
  375. #define __HAVE_PHYS_MEM_ACCESS_PROT
  376. struct file;
  377. pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
  378. unsigned long size, pgprot_t vma_prot);
  379. int phys_mem_access_prot_allowed(struct file *file, unsigned long pfn,
  380. unsigned long size, pgprot_t *vma_prot);
  381. #endif
  382. /*
  383. * We provide our own get_unmapped area to cope with the virtual aliasing
  384. * constraints placed on us by the cache architecture.
  385. */
  386. #define HAVE_ARCH_UNMAPPED_AREA
  387. #define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
  388. /*
  389. * No page table caches to initialise
  390. */
  391. #define pgtable_cache_init() do { } while (0)
  392. #endif /* _ASM_PGTABLE_H */