pgtable.h 17 KB

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