pgtable.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  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/mm_types.h>
  11. #include <linux/mmzone.h>
  12. #ifdef CONFIG_32BIT
  13. #include <asm/pgtable-32.h>
  14. #endif
  15. #ifdef CONFIG_64BIT
  16. #include <asm/pgtable-64.h>
  17. #endif
  18. #include <asm/cmpxchg.h>
  19. #include <asm/io.h>
  20. #include <asm/pgtable-bits.h>
  21. #include <asm/cpu-features.h>
  22. struct mm_struct;
  23. struct vm_area_struct;
  24. #define PAGE_SHARED vm_get_page_prot(VM_READ|VM_WRITE|VM_SHARED)
  25. #define PAGE_KERNEL __pgprot(_PAGE_PRESENT | __READABLE | __WRITEABLE | \
  26. _PAGE_GLOBAL | _page_cachable_default)
  27. #define PAGE_KERNEL_NC __pgprot(_PAGE_PRESENT | __READABLE | __WRITEABLE | \
  28. _PAGE_GLOBAL | _CACHE_CACHABLE_NONCOHERENT)
  29. #define PAGE_KERNEL_UNCACHED __pgprot(_PAGE_PRESENT | __READABLE | \
  30. __WRITEABLE | _PAGE_GLOBAL | _CACHE_UNCACHED)
  31. /*
  32. * If _PAGE_NO_EXEC is not defined, we can't do page protection for
  33. * execute, and consider it to be the same as read. Also, write
  34. * permissions imply read permissions. This is the closest we can get
  35. * by reasonable means..
  36. */
  37. extern unsigned long _page_cachable_default;
  38. extern void __update_cache(unsigned long address, pte_t pte);
  39. /*
  40. * ZERO_PAGE is a global shared page that is always zero; used
  41. * for zero-mapped memory areas etc..
  42. */
  43. extern unsigned long empty_zero_page;
  44. extern unsigned long zero_page_mask;
  45. #define ZERO_PAGE(vaddr) \
  46. (virt_to_page((void *)(empty_zero_page + (((unsigned long)(vaddr)) & zero_page_mask))))
  47. #define __HAVE_COLOR_ZERO_PAGE
  48. extern void paging_init(void);
  49. /*
  50. * Conversion functions: convert a page and protection to a page entry,
  51. * and a page entry and page directory to the page they refer to.
  52. */
  53. #define pmd_phys(pmd) virt_to_phys((void *)pmd_val(pmd))
  54. static inline unsigned long pmd_pfn(pmd_t pmd)
  55. {
  56. return pmd_val(pmd) >> _PFN_SHIFT;
  57. }
  58. #ifndef CONFIG_MIPS_HUGE_TLB_SUPPORT
  59. #define pmd_page(pmd) (pfn_to_page(pmd_phys(pmd) >> PAGE_SHIFT))
  60. #endif /* CONFIG_MIPS_HUGE_TLB_SUPPORT */
  61. #define pmd_page_vaddr(pmd) pmd_val(pmd)
  62. #define htw_stop() \
  63. do { \
  64. unsigned long __flags; \
  65. \
  66. if (cpu_has_htw) { \
  67. local_irq_save(__flags); \
  68. if(!raw_current_cpu_data.htw_seq++) { \
  69. write_c0_pwctl(read_c0_pwctl() & \
  70. ~(1 << MIPS_PWCTL_PWEN_SHIFT)); \
  71. back_to_back_c0_hazard(); \
  72. } \
  73. local_irq_restore(__flags); \
  74. } \
  75. } while(0)
  76. #define htw_start() \
  77. do { \
  78. unsigned long __flags; \
  79. \
  80. if (cpu_has_htw) { \
  81. local_irq_save(__flags); \
  82. if (!--raw_current_cpu_data.htw_seq) { \
  83. write_c0_pwctl(read_c0_pwctl() | \
  84. (1 << MIPS_PWCTL_PWEN_SHIFT)); \
  85. back_to_back_c0_hazard(); \
  86. } \
  87. local_irq_restore(__flags); \
  88. } \
  89. } while(0)
  90. static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
  91. pte_t *ptep, pte_t pteval);
  92. #if defined(CONFIG_PHYS_ADDR_T_64BIT) && defined(CONFIG_CPU_MIPS32)
  93. #ifdef CONFIG_XPA
  94. # define pte_none(pte) (!(((pte).pte_high) & ~_PAGE_GLOBAL))
  95. #else
  96. # define pte_none(pte) (!(((pte).pte_low | (pte).pte_high) & ~_PAGE_GLOBAL))
  97. #endif
  98. #define pte_present(pte) ((pte).pte_low & _PAGE_PRESENT)
  99. #define pte_no_exec(pte) ((pte).pte_low & _PAGE_NO_EXEC)
  100. static inline void set_pte(pte_t *ptep, pte_t pte)
  101. {
  102. ptep->pte_high = pte.pte_high;
  103. smp_wmb();
  104. ptep->pte_low = pte.pte_low;
  105. #ifdef CONFIG_XPA
  106. if (pte.pte_high & _PAGE_GLOBAL) {
  107. #else
  108. if (pte.pte_low & _PAGE_GLOBAL) {
  109. #endif
  110. pte_t *buddy = ptep_buddy(ptep);
  111. /*
  112. * Make sure the buddy is global too (if it's !none,
  113. * it better already be global)
  114. */
  115. if (pte_none(*buddy)) {
  116. if (!IS_ENABLED(CONFIG_XPA))
  117. buddy->pte_low |= _PAGE_GLOBAL;
  118. buddy->pte_high |= _PAGE_GLOBAL;
  119. }
  120. }
  121. }
  122. static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
  123. {
  124. pte_t null = __pte(0);
  125. htw_stop();
  126. /* Preserve global status for the pair */
  127. if (IS_ENABLED(CONFIG_XPA)) {
  128. if (ptep_buddy(ptep)->pte_high & _PAGE_GLOBAL)
  129. null.pte_high = _PAGE_GLOBAL;
  130. } else {
  131. if (ptep_buddy(ptep)->pte_low & _PAGE_GLOBAL)
  132. null.pte_low = null.pte_high = _PAGE_GLOBAL;
  133. }
  134. set_pte_at(mm, addr, ptep, null);
  135. htw_start();
  136. }
  137. #else
  138. #define pte_none(pte) (!(pte_val(pte) & ~_PAGE_GLOBAL))
  139. #define pte_present(pte) (pte_val(pte) & _PAGE_PRESENT)
  140. #define pte_no_exec(pte) (pte_val(pte) & _PAGE_NO_EXEC)
  141. /*
  142. * Certain architectures need to do special things when pte's
  143. * within a page table are directly modified. Thus, the following
  144. * hook is made available.
  145. */
  146. static inline void set_pte(pte_t *ptep, pte_t pteval)
  147. {
  148. *ptep = pteval;
  149. #if !defined(CONFIG_CPU_R3K_TLB)
  150. if (pte_val(pteval) & _PAGE_GLOBAL) {
  151. pte_t *buddy = ptep_buddy(ptep);
  152. /*
  153. * Make sure the buddy is global too (if it's !none,
  154. * it better already be global)
  155. */
  156. # if defined(CONFIG_PHYS_ADDR_T_64BIT) && !defined(CONFIG_CPU_MIPS32)
  157. cmpxchg64(&buddy->pte, 0, _PAGE_GLOBAL);
  158. # else
  159. cmpxchg(&buddy->pte, 0, _PAGE_GLOBAL);
  160. # endif
  161. }
  162. #endif
  163. }
  164. static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
  165. {
  166. htw_stop();
  167. #if !defined(CONFIG_CPU_R3K_TLB)
  168. /* Preserve global status for the pair */
  169. if (pte_val(*ptep_buddy(ptep)) & _PAGE_GLOBAL)
  170. set_pte_at(mm, addr, ptep, __pte(_PAGE_GLOBAL));
  171. else
  172. #endif
  173. set_pte_at(mm, addr, ptep, __pte(0));
  174. htw_start();
  175. }
  176. #endif
  177. static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
  178. pte_t *ptep, pte_t pteval)
  179. {
  180. if (!pte_present(pteval))
  181. goto cache_sync_done;
  182. if (pte_present(*ptep) && (pte_pfn(*ptep) == pte_pfn(pteval)))
  183. goto cache_sync_done;
  184. __update_cache(addr, pteval);
  185. cache_sync_done:
  186. set_pte(ptep, pteval);
  187. }
  188. /*
  189. * (pmds are folded into puds so this doesn't get actually called,
  190. * but the define is needed for a generic inline function.)
  191. */
  192. #define set_pmd(pmdptr, pmdval) do { *(pmdptr) = (pmdval); } while(0)
  193. #ifndef __PAGETABLE_PMD_FOLDED
  194. /*
  195. * (puds are folded into pgds so this doesn't get actually called,
  196. * but the define is needed for a generic inline function.)
  197. */
  198. #define set_pud(pudptr, pudval) do { *(pudptr) = (pudval); } while(0)
  199. #endif
  200. #define PGD_T_LOG2 (__builtin_ffs(sizeof(pgd_t)) - 1)
  201. #define PMD_T_LOG2 (__builtin_ffs(sizeof(pmd_t)) - 1)
  202. #define PTE_T_LOG2 (__builtin_ffs(sizeof(pte_t)) - 1)
  203. /*
  204. * We used to declare this array with size but gcc 3.3 and older are not able
  205. * to find that this expression is a constant, so the size is dropped.
  206. */
  207. extern pgd_t swapper_pg_dir[];
  208. /*
  209. * Platform specific pte_special() and pte_mkspecial() definitions
  210. * are required only when ARCH_HAS_PTE_SPECIAL is enabled.
  211. */
  212. #if defined(CONFIG_ARCH_HAS_PTE_SPECIAL)
  213. #if defined(CONFIG_PHYS_ADDR_T_64BIT) && defined(CONFIG_CPU_MIPS32)
  214. static inline int pte_special(pte_t pte)
  215. {
  216. return pte.pte_low & _PAGE_SPECIAL;
  217. }
  218. static inline pte_t pte_mkspecial(pte_t pte)
  219. {
  220. pte.pte_low |= _PAGE_SPECIAL;
  221. return pte;
  222. }
  223. #else
  224. static inline int pte_special(pte_t pte)
  225. {
  226. return pte_val(pte) & _PAGE_SPECIAL;
  227. }
  228. static inline pte_t pte_mkspecial(pte_t pte)
  229. {
  230. pte_val(pte) |= _PAGE_SPECIAL;
  231. return pte;
  232. }
  233. #endif
  234. #endif /* CONFIG_ARCH_HAS_PTE_SPECIAL */
  235. /*
  236. * The following only work if pte_present() is true.
  237. * Undefined behaviour if not..
  238. */
  239. #if defined(CONFIG_PHYS_ADDR_T_64BIT) && defined(CONFIG_CPU_MIPS32)
  240. static inline int pte_write(pte_t pte) { return pte.pte_low & _PAGE_WRITE; }
  241. static inline int pte_dirty(pte_t pte) { return pte.pte_low & _PAGE_MODIFIED; }
  242. static inline int pte_young(pte_t pte) { return pte.pte_low & _PAGE_ACCESSED; }
  243. static inline pte_t pte_wrprotect(pte_t pte)
  244. {
  245. pte.pte_low &= ~_PAGE_WRITE;
  246. if (!IS_ENABLED(CONFIG_XPA))
  247. pte.pte_low &= ~_PAGE_SILENT_WRITE;
  248. pte.pte_high &= ~_PAGE_SILENT_WRITE;
  249. return pte;
  250. }
  251. static inline pte_t pte_mkclean(pte_t pte)
  252. {
  253. pte.pte_low &= ~_PAGE_MODIFIED;
  254. if (!IS_ENABLED(CONFIG_XPA))
  255. pte.pte_low &= ~_PAGE_SILENT_WRITE;
  256. pte.pte_high &= ~_PAGE_SILENT_WRITE;
  257. return pte;
  258. }
  259. static inline pte_t pte_mkold(pte_t pte)
  260. {
  261. pte.pte_low &= ~_PAGE_ACCESSED;
  262. if (!IS_ENABLED(CONFIG_XPA))
  263. pte.pte_low &= ~_PAGE_SILENT_READ;
  264. pte.pte_high &= ~_PAGE_SILENT_READ;
  265. return pte;
  266. }
  267. static inline pte_t pte_mkwrite(pte_t pte)
  268. {
  269. pte.pte_low |= _PAGE_WRITE;
  270. if (pte.pte_low & _PAGE_MODIFIED) {
  271. if (!IS_ENABLED(CONFIG_XPA))
  272. pte.pte_low |= _PAGE_SILENT_WRITE;
  273. pte.pte_high |= _PAGE_SILENT_WRITE;
  274. }
  275. return pte;
  276. }
  277. static inline pte_t pte_mkdirty(pte_t pte)
  278. {
  279. pte.pte_low |= _PAGE_MODIFIED;
  280. if (pte.pte_low & _PAGE_WRITE) {
  281. if (!IS_ENABLED(CONFIG_XPA))
  282. pte.pte_low |= _PAGE_SILENT_WRITE;
  283. pte.pte_high |= _PAGE_SILENT_WRITE;
  284. }
  285. return pte;
  286. }
  287. static inline pte_t pte_mkyoung(pte_t pte)
  288. {
  289. pte.pte_low |= _PAGE_ACCESSED;
  290. if (!(pte.pte_low & _PAGE_NO_READ)) {
  291. if (!IS_ENABLED(CONFIG_XPA))
  292. pte.pte_low |= _PAGE_SILENT_READ;
  293. pte.pte_high |= _PAGE_SILENT_READ;
  294. }
  295. return pte;
  296. }
  297. #else
  298. static inline int pte_write(pte_t pte) { return pte_val(pte) & _PAGE_WRITE; }
  299. static inline int pte_dirty(pte_t pte) { return pte_val(pte) & _PAGE_MODIFIED; }
  300. static inline int pte_young(pte_t pte) { return pte_val(pte) & _PAGE_ACCESSED; }
  301. static inline pte_t pte_wrprotect(pte_t pte)
  302. {
  303. pte_val(pte) &= ~(_PAGE_WRITE | _PAGE_SILENT_WRITE);
  304. return pte;
  305. }
  306. static inline pte_t pte_mkclean(pte_t pte)
  307. {
  308. pte_val(pte) &= ~(_PAGE_MODIFIED | _PAGE_SILENT_WRITE);
  309. return pte;
  310. }
  311. static inline pte_t pte_mkold(pte_t pte)
  312. {
  313. pte_val(pte) &= ~(_PAGE_ACCESSED | _PAGE_SILENT_READ);
  314. return pte;
  315. }
  316. static inline pte_t pte_mkwrite(pte_t pte)
  317. {
  318. pte_val(pte) |= _PAGE_WRITE;
  319. if (pte_val(pte) & _PAGE_MODIFIED)
  320. pte_val(pte) |= _PAGE_SILENT_WRITE;
  321. return pte;
  322. }
  323. static inline pte_t pte_mkdirty(pte_t pte)
  324. {
  325. pte_val(pte) |= _PAGE_MODIFIED | _PAGE_SOFT_DIRTY;
  326. if (pte_val(pte) & _PAGE_WRITE)
  327. pte_val(pte) |= _PAGE_SILENT_WRITE;
  328. return pte;
  329. }
  330. static inline pte_t pte_mkyoung(pte_t pte)
  331. {
  332. pte_val(pte) |= _PAGE_ACCESSED;
  333. if (!(pte_val(pte) & _PAGE_NO_READ))
  334. pte_val(pte) |= _PAGE_SILENT_READ;
  335. return pte;
  336. }
  337. #define pte_sw_mkyoung pte_mkyoung
  338. #ifdef CONFIG_MIPS_HUGE_TLB_SUPPORT
  339. static inline int pte_huge(pte_t pte) { return pte_val(pte) & _PAGE_HUGE; }
  340. static inline pte_t pte_mkhuge(pte_t pte)
  341. {
  342. pte_val(pte) |= _PAGE_HUGE;
  343. return pte;
  344. }
  345. #define pmd_write pmd_write
  346. static inline int pmd_write(pmd_t pmd)
  347. {
  348. return !!(pmd_val(pmd) & _PAGE_WRITE);
  349. }
  350. static inline struct page *pmd_page(pmd_t pmd)
  351. {
  352. if (pmd_val(pmd) & _PAGE_HUGE)
  353. return pfn_to_page(pmd_pfn(pmd));
  354. return pfn_to_page(pmd_phys(pmd) >> PAGE_SHIFT);
  355. }
  356. #endif /* CONFIG_MIPS_HUGE_TLB_SUPPORT */
  357. #ifdef CONFIG_HAVE_ARCH_SOFT_DIRTY
  358. static inline bool pte_soft_dirty(pte_t pte)
  359. {
  360. return pte_val(pte) & _PAGE_SOFT_DIRTY;
  361. }
  362. #define pte_swp_soft_dirty pte_soft_dirty
  363. static inline pte_t pte_mksoft_dirty(pte_t pte)
  364. {
  365. pte_val(pte) |= _PAGE_SOFT_DIRTY;
  366. return pte;
  367. }
  368. #define pte_swp_mksoft_dirty pte_mksoft_dirty
  369. static inline pte_t pte_clear_soft_dirty(pte_t pte)
  370. {
  371. pte_val(pte) &= ~(_PAGE_SOFT_DIRTY);
  372. return pte;
  373. }
  374. #define pte_swp_clear_soft_dirty pte_clear_soft_dirty
  375. #endif /* CONFIG_HAVE_ARCH_SOFT_DIRTY */
  376. #endif
  377. /*
  378. * Macro to make mark a page protection value as "uncacheable". Note
  379. * that "protection" is really a misnomer here as the protection value
  380. * contains the memory attribute bits, dirty bits, and various other
  381. * bits as well.
  382. */
  383. #define pgprot_noncached pgprot_noncached
  384. static inline pgprot_t pgprot_noncached(pgprot_t _prot)
  385. {
  386. unsigned long prot = pgprot_val(_prot);
  387. prot = (prot & ~_CACHE_MASK) | _CACHE_UNCACHED;
  388. return __pgprot(prot);
  389. }
  390. #define pgprot_writecombine pgprot_writecombine
  391. static inline pgprot_t pgprot_writecombine(pgprot_t _prot)
  392. {
  393. unsigned long prot = pgprot_val(_prot);
  394. /* cpu_data[0].writecombine is already shifted by _CACHE_SHIFT */
  395. prot = (prot & ~_CACHE_MASK) | cpu_data[0].writecombine;
  396. return __pgprot(prot);
  397. }
  398. static inline void flush_tlb_fix_spurious_fault(struct vm_area_struct *vma,
  399. unsigned long address)
  400. {
  401. }
  402. #define __HAVE_ARCH_PTE_SAME
  403. static inline int pte_same(pte_t pte_a, pte_t pte_b)
  404. {
  405. return pte_val(pte_a) == pte_val(pte_b);
  406. }
  407. #define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
  408. static inline int ptep_set_access_flags(struct vm_area_struct *vma,
  409. unsigned long address, pte_t *ptep,
  410. pte_t entry, int dirty)
  411. {
  412. if (!pte_same(*ptep, entry))
  413. set_pte_at(vma->vm_mm, address, ptep, entry);
  414. /*
  415. * update_mmu_cache will unconditionally execute, handling both
  416. * the case that the PTE changed and the spurious fault case.
  417. */
  418. return true;
  419. }
  420. /*
  421. * Conversion functions: convert a page and protection to a page entry,
  422. * and a page entry and page directory to the page they refer to.
  423. */
  424. #define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot))
  425. #if defined(CONFIG_XPA)
  426. static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
  427. {
  428. pte.pte_low &= (_PAGE_MODIFIED | _PAGE_ACCESSED | _PFNX_MASK);
  429. pte.pte_high &= (_PFN_MASK | _CACHE_MASK);
  430. pte.pte_low |= pgprot_val(newprot) & ~_PFNX_MASK;
  431. pte.pte_high |= pgprot_val(newprot) & ~(_PFN_MASK | _CACHE_MASK);
  432. return pte;
  433. }
  434. #elif defined(CONFIG_PHYS_ADDR_T_64BIT) && defined(CONFIG_CPU_MIPS32)
  435. static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
  436. {
  437. pte.pte_low &= _PAGE_CHG_MASK;
  438. pte.pte_high &= (_PFN_MASK | _CACHE_MASK);
  439. pte.pte_low |= pgprot_val(newprot);
  440. pte.pte_high |= pgprot_val(newprot) & ~(_PFN_MASK | _CACHE_MASK);
  441. return pte;
  442. }
  443. #else
  444. static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
  445. {
  446. pte_val(pte) &= _PAGE_CHG_MASK;
  447. pte_val(pte) |= pgprot_val(newprot) & ~_PAGE_CHG_MASK;
  448. if ((pte_val(pte) & _PAGE_ACCESSED) && !(pte_val(pte) & _PAGE_NO_READ))
  449. pte_val(pte) |= _PAGE_SILENT_READ;
  450. return pte;
  451. }
  452. #endif
  453. extern void __update_tlb(struct vm_area_struct *vma, unsigned long address,
  454. pte_t pte);
  455. static inline void update_mmu_cache(struct vm_area_struct *vma,
  456. unsigned long address, pte_t *ptep)
  457. {
  458. pte_t pte = *ptep;
  459. __update_tlb(vma, address, pte);
  460. }
  461. #define __HAVE_ARCH_UPDATE_MMU_TLB
  462. #define update_mmu_tlb update_mmu_cache
  463. static inline void update_mmu_cache_pmd(struct vm_area_struct *vma,
  464. unsigned long address, pmd_t *pmdp)
  465. {
  466. pte_t pte = *(pte_t *)pmdp;
  467. __update_tlb(vma, address, pte);
  468. }
  469. #define kern_addr_valid(addr) (1)
  470. /*
  471. * Allow physical addresses to be fixed up to help 36-bit peripherals.
  472. */
  473. #ifdef CONFIG_MIPS_FIXUP_BIGPHYS_ADDR
  474. phys_addr_t fixup_bigphys_addr(phys_addr_t addr, phys_addr_t size);
  475. int io_remap_pfn_range(struct vm_area_struct *vma, unsigned long vaddr,
  476. unsigned long pfn, unsigned long size, pgprot_t prot);
  477. #define io_remap_pfn_range io_remap_pfn_range
  478. #else
  479. #define fixup_bigphys_addr(addr, size) (addr)
  480. #endif /* CONFIG_MIPS_FIXUP_BIGPHYS_ADDR */
  481. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  482. /* We don't have hardware dirty/accessed bits, generic_pmdp_establish is fine.*/
  483. #define pmdp_establish generic_pmdp_establish
  484. #define has_transparent_hugepage has_transparent_hugepage
  485. extern int has_transparent_hugepage(void);
  486. static inline int pmd_trans_huge(pmd_t pmd)
  487. {
  488. return !!(pmd_val(pmd) & _PAGE_HUGE);
  489. }
  490. static inline pmd_t pmd_mkhuge(pmd_t pmd)
  491. {
  492. pmd_val(pmd) |= _PAGE_HUGE;
  493. return pmd;
  494. }
  495. extern void set_pmd_at(struct mm_struct *mm, unsigned long addr,
  496. pmd_t *pmdp, pmd_t pmd);
  497. static inline pmd_t pmd_wrprotect(pmd_t pmd)
  498. {
  499. pmd_val(pmd) &= ~(_PAGE_WRITE | _PAGE_SILENT_WRITE);
  500. return pmd;
  501. }
  502. static inline pmd_t pmd_mkwrite(pmd_t pmd)
  503. {
  504. pmd_val(pmd) |= _PAGE_WRITE;
  505. if (pmd_val(pmd) & _PAGE_MODIFIED)
  506. pmd_val(pmd) |= _PAGE_SILENT_WRITE;
  507. return pmd;
  508. }
  509. static inline int pmd_dirty(pmd_t pmd)
  510. {
  511. return !!(pmd_val(pmd) & _PAGE_MODIFIED);
  512. }
  513. static inline pmd_t pmd_mkclean(pmd_t pmd)
  514. {
  515. pmd_val(pmd) &= ~(_PAGE_MODIFIED | _PAGE_SILENT_WRITE);
  516. return pmd;
  517. }
  518. static inline pmd_t pmd_mkdirty(pmd_t pmd)
  519. {
  520. pmd_val(pmd) |= _PAGE_MODIFIED | _PAGE_SOFT_DIRTY;
  521. if (pmd_val(pmd) & _PAGE_WRITE)
  522. pmd_val(pmd) |= _PAGE_SILENT_WRITE;
  523. return pmd;
  524. }
  525. #define pmd_young pmd_young
  526. static inline int pmd_young(pmd_t pmd)
  527. {
  528. return !!(pmd_val(pmd) & _PAGE_ACCESSED);
  529. }
  530. static inline pmd_t pmd_mkold(pmd_t pmd)
  531. {
  532. pmd_val(pmd) &= ~(_PAGE_ACCESSED|_PAGE_SILENT_READ);
  533. return pmd;
  534. }
  535. static inline pmd_t pmd_mkyoung(pmd_t pmd)
  536. {
  537. pmd_val(pmd) |= _PAGE_ACCESSED;
  538. if (!(pmd_val(pmd) & _PAGE_NO_READ))
  539. pmd_val(pmd) |= _PAGE_SILENT_READ;
  540. return pmd;
  541. }
  542. #ifdef CONFIG_HAVE_ARCH_SOFT_DIRTY
  543. static inline int pmd_soft_dirty(pmd_t pmd)
  544. {
  545. return !!(pmd_val(pmd) & _PAGE_SOFT_DIRTY);
  546. }
  547. static inline pmd_t pmd_mksoft_dirty(pmd_t pmd)
  548. {
  549. pmd_val(pmd) |= _PAGE_SOFT_DIRTY;
  550. return pmd;
  551. }
  552. static inline pmd_t pmd_clear_soft_dirty(pmd_t pmd)
  553. {
  554. pmd_val(pmd) &= ~(_PAGE_SOFT_DIRTY);
  555. return pmd;
  556. }
  557. #endif /* CONFIG_HAVE_ARCH_SOFT_DIRTY */
  558. /* Extern to avoid header file madness */
  559. extern pmd_t mk_pmd(struct page *page, pgprot_t prot);
  560. static inline pmd_t pmd_modify(pmd_t pmd, pgprot_t newprot)
  561. {
  562. pmd_val(pmd) = (pmd_val(pmd) & (_PAGE_CHG_MASK | _PAGE_HUGE)) |
  563. (pgprot_val(newprot) & ~_PAGE_CHG_MASK);
  564. return pmd;
  565. }
  566. static inline pmd_t pmd_mkinvalid(pmd_t pmd)
  567. {
  568. pmd_val(pmd) &= ~(_PAGE_PRESENT | _PAGE_VALID | _PAGE_DIRTY);
  569. return pmd;
  570. }
  571. /*
  572. * The generic version pmdp_huge_get_and_clear uses a version of pmd_clear() with a
  573. * different prototype.
  574. */
  575. #define __HAVE_ARCH_PMDP_HUGE_GET_AND_CLEAR
  576. static inline pmd_t pmdp_huge_get_and_clear(struct mm_struct *mm,
  577. unsigned long address, pmd_t *pmdp)
  578. {
  579. pmd_t old = *pmdp;
  580. pmd_clear(pmdp);
  581. return old;
  582. }
  583. #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
  584. #ifdef _PAGE_HUGE
  585. #define pmd_leaf(pmd) ((pmd_val(pmd) & _PAGE_HUGE) != 0)
  586. #define pud_leaf(pud) ((pud_val(pud) & _PAGE_HUGE) != 0)
  587. #endif
  588. #define gup_fast_permitted(start, end) (!cpu_has_dc_aliases)
  589. /*
  590. * We provide our own get_unmapped area to cope with the virtual aliasing
  591. * constraints placed on us by the cache architecture.
  592. */
  593. #define HAVE_ARCH_UNMAPPED_AREA
  594. #define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
  595. #endif /* _ASM_PGTABLE_H */