pgtable.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. #ifndef _PPC64_PGTABLE_H
  2. #define _PPC64_PGTABLE_H
  3. #include <asm-generic/4level-fixup.h>
  4. /*
  5. * This file contains the functions and defines necessary to modify and use
  6. * the ppc64 hashed page table.
  7. */
  8. #ifndef __ASSEMBLY__
  9. #include <linux/config.h>
  10. #include <linux/stddef.h>
  11. #include <asm/processor.h> /* For TASK_SIZE */
  12. #include <asm/mmu.h>
  13. #include <asm/page.h>
  14. #include <asm/tlbflush.h>
  15. #endif /* __ASSEMBLY__ */
  16. /* PMD_SHIFT determines what a second-level page table entry can map */
  17. #define PMD_SHIFT (PAGE_SHIFT + PAGE_SHIFT - 3)
  18. #define PMD_SIZE (1UL << PMD_SHIFT)
  19. #define PMD_MASK (~(PMD_SIZE-1))
  20. /* PGDIR_SHIFT determines what a third-level page table entry can map */
  21. #define PGDIR_SHIFT (PAGE_SHIFT + (PAGE_SHIFT - 3) + (PAGE_SHIFT - 2))
  22. #define PGDIR_SIZE (1UL << PGDIR_SHIFT)
  23. #define PGDIR_MASK (~(PGDIR_SIZE-1))
  24. /*
  25. * Entries per page directory level. The PTE level must use a 64b record
  26. * for each page table entry. The PMD and PGD level use a 32b record for
  27. * each entry by assuming that each entry is page aligned.
  28. */
  29. #define PTE_INDEX_SIZE 9
  30. #define PMD_INDEX_SIZE 10
  31. #define PGD_INDEX_SIZE 10
  32. #define PTRS_PER_PTE (1 << PTE_INDEX_SIZE)
  33. #define PTRS_PER_PMD (1 << PMD_INDEX_SIZE)
  34. #define PTRS_PER_PGD (1 << PGD_INDEX_SIZE)
  35. #define USER_PTRS_PER_PGD (1024)
  36. #define FIRST_USER_PGD_NR 0
  37. #define EADDR_SIZE (PTE_INDEX_SIZE + PMD_INDEX_SIZE + \
  38. PGD_INDEX_SIZE + PAGE_SHIFT)
  39. /*
  40. * Size of EA range mapped by our pagetables.
  41. */
  42. #define PGTABLE_EA_BITS 41
  43. #define PGTABLE_EA_MASK ((1UL<<PGTABLE_EA_BITS)-1)
  44. /*
  45. * Define the address range of the vmalloc VM area.
  46. */
  47. #define VMALLOC_START (0xD000000000000000ul)
  48. #define VMALLOC_END (VMALLOC_START + PGTABLE_EA_MASK)
  49. /*
  50. * Define the address range of the imalloc VM area.
  51. * (used for ioremap)
  52. */
  53. #define IMALLOC_START (ioremap_bot)
  54. #define IMALLOC_VMADDR(x) ((unsigned long)(x))
  55. #define PHBS_IO_BASE (0xE000000000000000ul) /* Reserve 2 gigs for PHBs */
  56. #define IMALLOC_BASE (0xE000000080000000ul)
  57. #define IMALLOC_END (IMALLOC_BASE + PGTABLE_EA_MASK)
  58. /*
  59. * Define the user address range
  60. */
  61. #define USER_START (0UL)
  62. #define USER_END (USER_START + PGTABLE_EA_MASK)
  63. /*
  64. * Bits in a linux-style PTE. These match the bits in the
  65. * (hardware-defined) PowerPC PTE as closely as possible.
  66. */
  67. #define _PAGE_PRESENT 0x0001 /* software: pte contains a translation */
  68. #define _PAGE_USER 0x0002 /* matches one of the PP bits */
  69. #define _PAGE_FILE 0x0002 /* (!present only) software: pte holds file offset */
  70. #define _PAGE_EXEC 0x0004 /* No execute on POWER4 and newer (we invert) */
  71. #define _PAGE_GUARDED 0x0008
  72. #define _PAGE_COHERENT 0x0010 /* M: enforce memory coherence (SMP systems) */
  73. #define _PAGE_NO_CACHE 0x0020 /* I: cache inhibit */
  74. #define _PAGE_WRITETHRU 0x0040 /* W: cache write-through */
  75. #define _PAGE_DIRTY 0x0080 /* C: page changed */
  76. #define _PAGE_ACCESSED 0x0100 /* R: page referenced */
  77. #define _PAGE_RW 0x0200 /* software: user write access allowed */
  78. #define _PAGE_HASHPTE 0x0400 /* software: pte has an associated HPTE */
  79. #define _PAGE_BUSY 0x0800 /* software: PTE & hash are busy */
  80. #define _PAGE_SECONDARY 0x8000 /* software: HPTE is in secondary group */
  81. #define _PAGE_GROUP_IX 0x7000 /* software: HPTE index within group */
  82. #define _PAGE_HUGE 0x10000 /* 16MB page */
  83. /* Bits 0x7000 identify the index within an HPT Group */
  84. #define _PAGE_HPTEFLAGS (_PAGE_BUSY | _PAGE_HASHPTE | _PAGE_SECONDARY | _PAGE_GROUP_IX)
  85. /* PAGE_MASK gives the right answer below, but only by accident */
  86. /* It should be preserving the high 48 bits and then specifically */
  87. /* preserving _PAGE_SECONDARY | _PAGE_GROUP_IX */
  88. #define _PAGE_CHG_MASK (PAGE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY | _PAGE_HPTEFLAGS)
  89. #define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_COHERENT)
  90. #define _PAGE_WRENABLE (_PAGE_RW | _PAGE_DIRTY)
  91. /* __pgprot defined in asm-ppc64/page.h */
  92. #define PAGE_NONE __pgprot(_PAGE_PRESENT | _PAGE_ACCESSED)
  93. #define PAGE_SHARED __pgprot(_PAGE_BASE | _PAGE_RW | _PAGE_USER)
  94. #define PAGE_SHARED_X __pgprot(_PAGE_BASE | _PAGE_RW | _PAGE_USER | _PAGE_EXEC)
  95. #define PAGE_COPY __pgprot(_PAGE_BASE | _PAGE_USER)
  96. #define PAGE_COPY_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_EXEC)
  97. #define PAGE_READONLY __pgprot(_PAGE_BASE | _PAGE_USER)
  98. #define PAGE_READONLY_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_EXEC)
  99. #define PAGE_KERNEL __pgprot(_PAGE_BASE | _PAGE_WRENABLE)
  100. #define PAGE_KERNEL_CI __pgprot(_PAGE_PRESENT | _PAGE_ACCESSED | \
  101. _PAGE_WRENABLE | _PAGE_NO_CACHE | _PAGE_GUARDED)
  102. #define PAGE_KERNEL_EXEC __pgprot(_PAGE_BASE | _PAGE_WRENABLE | _PAGE_EXEC)
  103. #define PAGE_AGP __pgprot(_PAGE_BASE | _PAGE_WRENABLE | _PAGE_NO_CACHE)
  104. #define HAVE_PAGE_AGP
  105. /*
  106. * This bit in a hardware PTE indicates that the page is *not* executable.
  107. */
  108. #define HW_NO_EXEC _PAGE_EXEC
  109. /*
  110. * POWER4 and newer have per page execute protection, older chips can only
  111. * do this on a segment (256MB) basis.
  112. *
  113. * Also, write permissions imply read permissions.
  114. * This is the closest we can get..
  115. *
  116. * Note due to the way vm flags are laid out, the bits are XWR
  117. */
  118. #define __P000 PAGE_NONE
  119. #define __P001 PAGE_READONLY
  120. #define __P010 PAGE_COPY
  121. #define __P011 PAGE_COPY
  122. #define __P100 PAGE_READONLY_X
  123. #define __P101 PAGE_READONLY_X
  124. #define __P110 PAGE_COPY_X
  125. #define __P111 PAGE_COPY_X
  126. #define __S000 PAGE_NONE
  127. #define __S001 PAGE_READONLY
  128. #define __S010 PAGE_SHARED
  129. #define __S011 PAGE_SHARED
  130. #define __S100 PAGE_READONLY_X
  131. #define __S101 PAGE_READONLY_X
  132. #define __S110 PAGE_SHARED_X
  133. #define __S111 PAGE_SHARED_X
  134. #ifndef __ASSEMBLY__
  135. /*
  136. * ZERO_PAGE is a global shared page that is always zero: used
  137. * for zero-mapped memory areas etc..
  138. */
  139. extern unsigned long empty_zero_page[PAGE_SIZE/sizeof(unsigned long)];
  140. #define ZERO_PAGE(vaddr) (virt_to_page(empty_zero_page))
  141. #endif /* __ASSEMBLY__ */
  142. /* shift to put page number into pte */
  143. #define PTE_SHIFT (17)
  144. /* We allow 2^41 bytes of real memory, so we need 29 bits in the PMD
  145. * to give the PTE page number. The bottom two bits are for flags. */
  146. #define PMD_TO_PTEPAGE_SHIFT (2)
  147. #ifdef CONFIG_HUGETLB_PAGE
  148. #ifndef __ASSEMBLY__
  149. int hash_huge_page(struct mm_struct *mm, unsigned long access,
  150. unsigned long ea, unsigned long vsid, int local);
  151. void hugetlb_mm_free_pgd(struct mm_struct *mm);
  152. #endif /* __ASSEMBLY__ */
  153. #define HAVE_ARCH_UNMAPPED_AREA
  154. #define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
  155. #else
  156. #define hash_huge_page(mm,a,ea,vsid,local) -1
  157. #define hugetlb_mm_free_pgd(mm) do {} while (0)
  158. #endif
  159. #ifndef __ASSEMBLY__
  160. /*
  161. * Conversion functions: convert a page and protection to a page entry,
  162. * and a page entry and page directory to the page they refer to.
  163. *
  164. * mk_pte takes a (struct page *) as input
  165. */
  166. #define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot))
  167. #define pfn_pte(pfn,pgprot) \
  168. ({ \
  169. pte_t pte; \
  170. pte_val(pte) = ((unsigned long)(pfn) << PTE_SHIFT) | \
  171. pgprot_val(pgprot); \
  172. pte; \
  173. })
  174. #define pte_modify(_pte, newprot) \
  175. (__pte((pte_val(_pte) & _PAGE_CHG_MASK) | pgprot_val(newprot)))
  176. #define pte_none(pte) ((pte_val(pte) & ~_PAGE_HPTEFLAGS) == 0)
  177. #define pte_present(pte) (pte_val(pte) & _PAGE_PRESENT)
  178. /* pte_clear moved to later in this file */
  179. #define pte_pfn(x) ((unsigned long)((pte_val(x) >> PTE_SHIFT)))
  180. #define pte_page(x) pfn_to_page(pte_pfn(x))
  181. #define pmd_set(pmdp, ptep) \
  182. (pmd_val(*(pmdp)) = (__ba_to_bpn(ptep) << PMD_TO_PTEPAGE_SHIFT))
  183. #define pmd_none(pmd) (!pmd_val(pmd))
  184. #define pmd_bad(pmd) (pmd_val(pmd) == 0)
  185. #define pmd_present(pmd) (pmd_val(pmd) != 0)
  186. #define pmd_clear(pmdp) (pmd_val(*(pmdp)) = 0)
  187. #define pmd_page_kernel(pmd) \
  188. (__bpn_to_ba(pmd_val(pmd) >> PMD_TO_PTEPAGE_SHIFT))
  189. #define pmd_page(pmd) virt_to_page(pmd_page_kernel(pmd))
  190. #define pgd_set(pgdp, pmdp) (pgd_val(*(pgdp)) = (__ba_to_bpn(pmdp)))
  191. #define pgd_none(pgd) (!pgd_val(pgd))
  192. #define pgd_bad(pgd) ((pgd_val(pgd)) == 0)
  193. #define pgd_present(pgd) (pgd_val(pgd) != 0UL)
  194. #define pgd_clear(pgdp) (pgd_val(*(pgdp)) = 0UL)
  195. #define pgd_page(pgd) (__bpn_to_ba(pgd_val(pgd)))
  196. /*
  197. * Find an entry in a page-table-directory. We combine the address region
  198. * (the high order N bits) and the pgd portion of the address.
  199. */
  200. /* to avoid overflow in free_pgtables we don't use PTRS_PER_PGD here */
  201. #define pgd_index(address) (((address) >> (PGDIR_SHIFT)) & 0x7ff)
  202. #define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
  203. /* Find an entry in the second-level page table.. */
  204. #define pmd_offset(dir,addr) \
  205. ((pmd_t *) pgd_page(*(dir)) + (((addr) >> PMD_SHIFT) & (PTRS_PER_PMD - 1)))
  206. /* Find an entry in the third-level page table.. */
  207. #define pte_offset_kernel(dir,addr) \
  208. ((pte_t *) pmd_page_kernel(*(dir)) + (((addr) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1)))
  209. #define pte_offset_map(dir,addr) pte_offset_kernel((dir), (addr))
  210. #define pte_offset_map_nested(dir,addr) pte_offset_kernel((dir), (addr))
  211. #define pte_unmap(pte) do { } while(0)
  212. #define pte_unmap_nested(pte) do { } while(0)
  213. /* to find an entry in a kernel page-table-directory */
  214. /* This now only contains the vmalloc pages */
  215. #define pgd_offset_k(address) pgd_offset(&init_mm, address)
  216. /* to find an entry in the ioremap page-table-directory */
  217. #define pgd_offset_i(address) (ioremap_pgd + pgd_index(address))
  218. #define pages_to_mb(x) ((x) >> (20-PAGE_SHIFT))
  219. /*
  220. * The following only work if pte_present() is true.
  221. * Undefined behaviour if not..
  222. */
  223. static inline int pte_read(pte_t pte) { return pte_val(pte) & _PAGE_USER;}
  224. static inline int pte_write(pte_t pte) { return pte_val(pte) & _PAGE_RW;}
  225. static inline int pte_exec(pte_t pte) { return pte_val(pte) & _PAGE_EXEC;}
  226. static inline int pte_dirty(pte_t pte) { return pte_val(pte) & _PAGE_DIRTY;}
  227. static inline int pte_young(pte_t pte) { return pte_val(pte) & _PAGE_ACCESSED;}
  228. static inline int pte_file(pte_t pte) { return pte_val(pte) & _PAGE_FILE;}
  229. static inline int pte_huge(pte_t pte) { return pte_val(pte) & _PAGE_HUGE;}
  230. static inline void pte_uncache(pte_t pte) { pte_val(pte) |= _PAGE_NO_CACHE; }
  231. static inline void pte_cache(pte_t pte) { pte_val(pte) &= ~_PAGE_NO_CACHE; }
  232. static inline pte_t pte_rdprotect(pte_t pte) {
  233. pte_val(pte) &= ~_PAGE_USER; return pte; }
  234. static inline pte_t pte_exprotect(pte_t pte) {
  235. pte_val(pte) &= ~_PAGE_EXEC; return pte; }
  236. static inline pte_t pte_wrprotect(pte_t pte) {
  237. pte_val(pte) &= ~(_PAGE_RW); return pte; }
  238. static inline pte_t pte_mkclean(pte_t pte) {
  239. pte_val(pte) &= ~(_PAGE_DIRTY); return pte; }
  240. static inline pte_t pte_mkold(pte_t pte) {
  241. pte_val(pte) &= ~_PAGE_ACCESSED; return pte; }
  242. static inline pte_t pte_mkread(pte_t pte) {
  243. pte_val(pte) |= _PAGE_USER; return pte; }
  244. static inline pte_t pte_mkexec(pte_t pte) {
  245. pte_val(pte) |= _PAGE_USER | _PAGE_EXEC; return pte; }
  246. static inline pte_t pte_mkwrite(pte_t pte) {
  247. pte_val(pte) |= _PAGE_RW; return pte; }
  248. static inline pte_t pte_mkdirty(pte_t pte) {
  249. pte_val(pte) |= _PAGE_DIRTY; return pte; }
  250. static inline pte_t pte_mkyoung(pte_t pte) {
  251. pte_val(pte) |= _PAGE_ACCESSED; return pte; }
  252. static inline pte_t pte_mkhuge(pte_t pte) {
  253. pte_val(pte) |= _PAGE_HUGE; return pte; }
  254. /* Atomic PTE updates */
  255. static inline unsigned long pte_update(pte_t *p, unsigned long clr)
  256. {
  257. unsigned long old, tmp;
  258. __asm__ __volatile__(
  259. "1: ldarx %0,0,%3 # pte_update\n\
  260. andi. %1,%0,%6\n\
  261. bne- 1b \n\
  262. andc %1,%0,%4 \n\
  263. stdcx. %1,0,%3 \n\
  264. bne- 1b"
  265. : "=&r" (old), "=&r" (tmp), "=m" (*p)
  266. : "r" (p), "r" (clr), "m" (*p), "i" (_PAGE_BUSY)
  267. : "cc" );
  268. return old;
  269. }
  270. /* PTE updating functions, this function puts the PTE in the
  271. * batch, doesn't actually triggers the hash flush immediately,
  272. * you need to call flush_tlb_pending() to do that.
  273. */
  274. extern void hpte_update(struct mm_struct *mm, unsigned long addr, unsigned long pte,
  275. int wrprot);
  276. static inline int __ptep_test_and_clear_young(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
  277. {
  278. unsigned long old;
  279. if ((pte_val(*ptep) & (_PAGE_ACCESSED | _PAGE_HASHPTE)) == 0)
  280. return 0;
  281. old = pte_update(ptep, _PAGE_ACCESSED);
  282. if (old & _PAGE_HASHPTE) {
  283. hpte_update(mm, addr, old, 0);
  284. flush_tlb_pending();
  285. }
  286. return (old & _PAGE_ACCESSED) != 0;
  287. }
  288. #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
  289. #define ptep_test_and_clear_young(__vma, __addr, __ptep) \
  290. ({ \
  291. int __r; \
  292. __r = __ptep_test_and_clear_young((__vma)->vm_mm, __addr, __ptep); \
  293. __r; \
  294. })
  295. /*
  296. * On RW/DIRTY bit transitions we can avoid flushing the hpte. For the
  297. * moment we always flush but we need to fix hpte_update and test if the
  298. * optimisation is worth it.
  299. */
  300. static inline int __ptep_test_and_clear_dirty(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
  301. {
  302. unsigned long old;
  303. if ((pte_val(*ptep) & _PAGE_DIRTY) == 0)
  304. return 0;
  305. old = pte_update(ptep, _PAGE_DIRTY);
  306. if (old & _PAGE_HASHPTE)
  307. hpte_update(mm, addr, old, 0);
  308. return (old & _PAGE_DIRTY) != 0;
  309. }
  310. #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_DIRTY
  311. #define ptep_test_and_clear_dirty(__vma, __addr, __ptep) \
  312. ({ \
  313. int __r; \
  314. __r = __ptep_test_and_clear_dirty((__vma)->vm_mm, __addr, __ptep); \
  315. __r; \
  316. })
  317. #define __HAVE_ARCH_PTEP_SET_WRPROTECT
  318. static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
  319. {
  320. unsigned long old;
  321. if ((pte_val(*ptep) & _PAGE_RW) == 0)
  322. return;
  323. old = pte_update(ptep, _PAGE_RW);
  324. if (old & _PAGE_HASHPTE)
  325. hpte_update(mm, addr, old, 0);
  326. }
  327. /*
  328. * We currently remove entries from the hashtable regardless of whether
  329. * the entry was young or dirty. The generic routines only flush if the
  330. * entry was young or dirty which is not good enough.
  331. *
  332. * We should be more intelligent about this but for the moment we override
  333. * these functions and force a tlb flush unconditionally
  334. */
  335. #define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
  336. #define ptep_clear_flush_young(__vma, __address, __ptep) \
  337. ({ \
  338. int __young = __ptep_test_and_clear_young((__vma)->vm_mm, __address, \
  339. __ptep); \
  340. __young; \
  341. })
  342. #define __HAVE_ARCH_PTEP_CLEAR_DIRTY_FLUSH
  343. #define ptep_clear_flush_dirty(__vma, __address, __ptep) \
  344. ({ \
  345. int __dirty = __ptep_test_and_clear_dirty((__vma)->vm_mm, __address, \
  346. __ptep); \
  347. flush_tlb_page(__vma, __address); \
  348. __dirty; \
  349. })
  350. #define __HAVE_ARCH_PTEP_GET_AND_CLEAR
  351. static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
  352. {
  353. unsigned long old = pte_update(ptep, ~0UL);
  354. if (old & _PAGE_HASHPTE)
  355. hpte_update(mm, addr, old, 0);
  356. return __pte(old);
  357. }
  358. static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t * ptep)
  359. {
  360. unsigned long old = pte_update(ptep, ~0UL);
  361. if (old & _PAGE_HASHPTE)
  362. hpte_update(mm, addr, old, 0);
  363. }
  364. /*
  365. * set_pte stores a linux PTE into the linux page table.
  366. */
  367. static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
  368. pte_t *ptep, pte_t pte)
  369. {
  370. if (pte_present(*ptep)) {
  371. pte_clear(mm, addr, ptep);
  372. flush_tlb_pending();
  373. }
  374. *ptep = __pte(pte_val(pte)) & ~_PAGE_HPTEFLAGS;
  375. }
  376. /* Set the dirty and/or accessed bits atomically in a linux PTE, this
  377. * function doesn't need to flush the hash entry
  378. */
  379. #define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
  380. static inline void __ptep_set_access_flags(pte_t *ptep, pte_t entry, int dirty)
  381. {
  382. unsigned long bits = pte_val(entry) &
  383. (_PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_RW | _PAGE_EXEC);
  384. unsigned long old, tmp;
  385. __asm__ __volatile__(
  386. "1: ldarx %0,0,%4\n\
  387. andi. %1,%0,%6\n\
  388. bne- 1b \n\
  389. or %0,%3,%0\n\
  390. stdcx. %0,0,%4\n\
  391. bne- 1b"
  392. :"=&r" (old), "=&r" (tmp), "=m" (*ptep)
  393. :"r" (bits), "r" (ptep), "m" (*ptep), "i" (_PAGE_BUSY)
  394. :"cc");
  395. }
  396. #define ptep_set_access_flags(__vma, __address, __ptep, __entry, __dirty) \
  397. do { \
  398. __ptep_set_access_flags(__ptep, __entry, __dirty); \
  399. flush_tlb_page_nohash(__vma, __address); \
  400. } while(0)
  401. /*
  402. * Macro to mark a page protection value as "uncacheable".
  403. */
  404. #define pgprot_noncached(prot) (__pgprot(pgprot_val(prot) | _PAGE_NO_CACHE | _PAGE_GUARDED))
  405. struct file;
  406. extern pgprot_t phys_mem_access_prot(struct file *file, unsigned long addr,
  407. unsigned long size, pgprot_t vma_prot);
  408. #define __HAVE_PHYS_MEM_ACCESS_PROT
  409. #define __HAVE_ARCH_PTE_SAME
  410. #define pte_same(A,B) (((pte_val(A) ^ pte_val(B)) & ~_PAGE_HPTEFLAGS) == 0)
  411. extern unsigned long ioremap_bot, ioremap_base;
  412. #define USER_PGD_PTRS (PAGE_OFFSET >> PGDIR_SHIFT)
  413. #define KERNEL_PGD_PTRS (PTRS_PER_PGD-USER_PGD_PTRS)
  414. #define pte_ERROR(e) \
  415. printk("%s:%d: bad pte %016lx.\n", __FILE__, __LINE__, pte_val(e))
  416. #define pmd_ERROR(e) \
  417. printk("%s:%d: bad pmd %08x.\n", __FILE__, __LINE__, pmd_val(e))
  418. #define pgd_ERROR(e) \
  419. printk("%s:%d: bad pgd %08x.\n", __FILE__, __LINE__, pgd_val(e))
  420. extern pgd_t swapper_pg_dir[1024];
  421. extern pgd_t ioremap_dir[1024];
  422. extern void paging_init(void);
  423. /*
  424. * Because the huge pgtables are only 2 level, they can take
  425. * at most around 4M, much less than one hugepage which the
  426. * process is presumably entitled to use. So we don't bother
  427. * freeing up the pagetables on unmap, and wait until
  428. * destroy_context() to clean up the lot.
  429. */
  430. #define hugetlb_free_pgd_range(tlb, addr, end, floor, ceiling) \
  431. do { } while (0)
  432. /*
  433. * This gets called at the end of handling a page fault, when
  434. * the kernel has put a new PTE into the page table for the process.
  435. * We use it to put a corresponding HPTE into the hash table
  436. * ahead of time, instead of waiting for the inevitable extra
  437. * hash-table miss exception.
  438. */
  439. struct vm_area_struct;
  440. extern void update_mmu_cache(struct vm_area_struct *, unsigned long, pte_t);
  441. /* Encode and de-code a swap entry */
  442. #define __swp_type(entry) (((entry).val >> 1) & 0x3f)
  443. #define __swp_offset(entry) ((entry).val >> 8)
  444. #define __swp_entry(type, offset) ((swp_entry_t) { ((type) << 1) | ((offset) << 8) })
  445. #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) >> PTE_SHIFT })
  446. #define __swp_entry_to_pte(x) ((pte_t) { (x).val << PTE_SHIFT })
  447. #define pte_to_pgoff(pte) (pte_val(pte) >> PTE_SHIFT)
  448. #define pgoff_to_pte(off) ((pte_t) {((off) << PTE_SHIFT)|_PAGE_FILE})
  449. #define PTE_FILE_MAX_BITS (BITS_PER_LONG - PTE_SHIFT)
  450. /*
  451. * kern_addr_valid is intended to indicate whether an address is a valid
  452. * kernel address. Most 32-bit archs define it as always true (like this)
  453. * but most 64-bit archs actually perform a test. What should we do here?
  454. * The only use is in fs/ncpfs/dir.c
  455. */
  456. #define kern_addr_valid(addr) (1)
  457. #define io_remap_page_range(vma, vaddr, paddr, size, prot) \
  458. remap_pfn_range(vma, vaddr, (paddr) >> PAGE_SHIFT, size, prot)
  459. #define io_remap_pfn_range(vma, vaddr, pfn, size, prot) \
  460. remap_pfn_range(vma, vaddr, pfn, size, prot)
  461. #define MK_IOSPACE_PFN(space, pfn) (pfn)
  462. #define GET_IOSPACE(pfn) 0
  463. #define GET_PFN(pfn) (pfn)
  464. void pgtable_cache_init(void);
  465. extern void hpte_init_native(void);
  466. extern void hpte_init_lpar(void);
  467. extern void hpte_init_iSeries(void);
  468. /* imalloc region types */
  469. #define IM_REGION_UNUSED 0x1
  470. #define IM_REGION_SUBSET 0x2
  471. #define IM_REGION_EXISTS 0x4
  472. #define IM_REGION_OVERLAP 0x8
  473. #define IM_REGION_SUPERSET 0x10
  474. extern struct vm_struct * im_get_free_area(unsigned long size);
  475. extern struct vm_struct * im_get_area(unsigned long v_addr, unsigned long size,
  476. int region_type);
  477. unsigned long im_free(void *addr);
  478. extern long pSeries_lpar_hpte_insert(unsigned long hpte_group,
  479. unsigned long va, unsigned long prpn,
  480. int secondary, unsigned long hpteflags,
  481. int bolted, int large);
  482. extern long native_hpte_insert(unsigned long hpte_group, unsigned long va,
  483. unsigned long prpn, int secondary,
  484. unsigned long hpteflags, int bolted, int large);
  485. /*
  486. * find_linux_pte returns the address of a linux pte for a given
  487. * effective address and directory. If not found, it returns zero.
  488. */
  489. static inline pte_t *find_linux_pte(pgd_t *pgdir, unsigned long ea)
  490. {
  491. pgd_t *pg;
  492. pmd_t *pm;
  493. pte_t *pt = NULL;
  494. pte_t pte;
  495. pg = pgdir + pgd_index(ea);
  496. if (!pgd_none(*pg)) {
  497. pm = pmd_offset(pg, ea);
  498. if (pmd_present(*pm)) {
  499. pt = pte_offset_kernel(pm, ea);
  500. pte = *pt;
  501. if (!pte_present(pte))
  502. pt = NULL;
  503. }
  504. }
  505. return pt;
  506. }
  507. #include <asm-generic/pgtable.h>
  508. #endif /* __ASSEMBLY__ */
  509. #endif /* _PPC64_PGTABLE_H */