pgtable.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. #ifndef _PPC64_PGTABLE_H
  2. #define _PPC64_PGTABLE_H
  3. /*
  4. * This file contains the functions and defines necessary to modify and use
  5. * the ppc64 hashed page table.
  6. */
  7. #ifndef __ASSEMBLY__
  8. #include <linux/config.h>
  9. #include <linux/stddef.h>
  10. #include <asm/processor.h> /* For TASK_SIZE */
  11. #include <asm/mmu.h>
  12. #include <asm/page.h>
  13. #include <asm/tlbflush.h>
  14. #endif /* __ASSEMBLY__ */
  15. #include <asm-generic/pgtable-nopud.h>
  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_ADDRESS 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 pud_set(pudp, pmdp) (pud_val(*(pudp)) = (__ba_to_bpn(pmdp)))
  191. #define pud_none(pud) (!pud_val(pud))
  192. #define pud_bad(pud) ((pud_val(pud)) == 0UL)
  193. #define pud_present(pud) (pud_val(pud) != 0UL)
  194. #define pud_clear(pudp) (pud_val(*(pudp)) = 0UL)
  195. #define pud_page(pud) (__bpn_to_ba(pud_val(pud)))
  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(pudp,addr) \
  205. ((pmd_t *) pud_page(*(pudp)) + (((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)) \
  209. + (((addr) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1)))
  210. #define pte_offset_map(dir,addr) pte_offset_kernel((dir), (addr))
  211. #define pte_offset_map_nested(dir,addr) pte_offset_kernel((dir), (addr))
  212. #define pte_unmap(pte) do { } while(0)
  213. #define pte_unmap_nested(pte) do { } while(0)
  214. /* to find an entry in a kernel page-table-directory */
  215. /* This now only contains the vmalloc pages */
  216. #define pgd_offset_k(address) pgd_offset(&init_mm, address)
  217. /* to find an entry in the ioremap page-table-directory */
  218. #define pgd_offset_i(address) (ioremap_pgd + pgd_index(address))
  219. #define pages_to_mb(x) ((x) >> (20-PAGE_SHIFT))
  220. /*
  221. * The following only work if pte_present() is true.
  222. * Undefined behaviour if not..
  223. */
  224. static inline int pte_read(pte_t pte) { return pte_val(pte) & _PAGE_USER;}
  225. static inline int pte_write(pte_t pte) { return pte_val(pte) & _PAGE_RW;}
  226. static inline int pte_exec(pte_t pte) { return pte_val(pte) & _PAGE_EXEC;}
  227. static inline int pte_dirty(pte_t pte) { return pte_val(pte) & _PAGE_DIRTY;}
  228. static inline int pte_young(pte_t pte) { return pte_val(pte) & _PAGE_ACCESSED;}
  229. static inline int pte_file(pte_t pte) { return pte_val(pte) & _PAGE_FILE;}
  230. static inline int pte_huge(pte_t pte) { return pte_val(pte) & _PAGE_HUGE;}
  231. static inline void pte_uncache(pte_t pte) { pte_val(pte) |= _PAGE_NO_CACHE; }
  232. static inline void pte_cache(pte_t pte) { pte_val(pte) &= ~_PAGE_NO_CACHE; }
  233. static inline pte_t pte_rdprotect(pte_t pte) {
  234. pte_val(pte) &= ~_PAGE_USER; return pte; }
  235. static inline pte_t pte_exprotect(pte_t pte) {
  236. pte_val(pte) &= ~_PAGE_EXEC; return pte; }
  237. static inline pte_t pte_wrprotect(pte_t pte) {
  238. pte_val(pte) &= ~(_PAGE_RW); return pte; }
  239. static inline pte_t pte_mkclean(pte_t pte) {
  240. pte_val(pte) &= ~(_PAGE_DIRTY); return pte; }
  241. static inline pte_t pte_mkold(pte_t pte) {
  242. pte_val(pte) &= ~_PAGE_ACCESSED; return pte; }
  243. static inline pte_t pte_mkread(pte_t pte) {
  244. pte_val(pte) |= _PAGE_USER; return pte; }
  245. static inline pte_t pte_mkexec(pte_t pte) {
  246. pte_val(pte) |= _PAGE_USER | _PAGE_EXEC; return pte; }
  247. static inline pte_t pte_mkwrite(pte_t pte) {
  248. pte_val(pte) |= _PAGE_RW; return pte; }
  249. static inline pte_t pte_mkdirty(pte_t pte) {
  250. pte_val(pte) |= _PAGE_DIRTY; return pte; }
  251. static inline pte_t pte_mkyoung(pte_t pte) {
  252. pte_val(pte) |= _PAGE_ACCESSED; return pte; }
  253. static inline pte_t pte_mkhuge(pte_t pte) {
  254. pte_val(pte) |= _PAGE_HUGE; return pte; }
  255. /* Atomic PTE updates */
  256. static inline unsigned long pte_update(pte_t *p, unsigned long clr)
  257. {
  258. unsigned long old, tmp;
  259. __asm__ __volatile__(
  260. "1: ldarx %0,0,%3 # pte_update\n\
  261. andi. %1,%0,%6\n\
  262. bne- 1b \n\
  263. andc %1,%0,%4 \n\
  264. stdcx. %1,0,%3 \n\
  265. bne- 1b"
  266. : "=&r" (old), "=&r" (tmp), "=m" (*p)
  267. : "r" (p), "r" (clr), "m" (*p), "i" (_PAGE_BUSY)
  268. : "cc" );
  269. return old;
  270. }
  271. /* PTE updating functions, this function puts the PTE in the
  272. * batch, doesn't actually triggers the hash flush immediately,
  273. * you need to call flush_tlb_pending() to do that.
  274. */
  275. extern void hpte_update(struct mm_struct *mm, unsigned long addr, unsigned long pte,
  276. int wrprot);
  277. static inline int __ptep_test_and_clear_young(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
  278. {
  279. unsigned long old;
  280. if ((pte_val(*ptep) & (_PAGE_ACCESSED | _PAGE_HASHPTE)) == 0)
  281. return 0;
  282. old = pte_update(ptep, _PAGE_ACCESSED);
  283. if (old & _PAGE_HASHPTE) {
  284. hpte_update(mm, addr, old, 0);
  285. flush_tlb_pending();
  286. }
  287. return (old & _PAGE_ACCESSED) != 0;
  288. }
  289. #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
  290. #define ptep_test_and_clear_young(__vma, __addr, __ptep) \
  291. ({ \
  292. int __r; \
  293. __r = __ptep_test_and_clear_young((__vma)->vm_mm, __addr, __ptep); \
  294. __r; \
  295. })
  296. /*
  297. * On RW/DIRTY bit transitions we can avoid flushing the hpte. For the
  298. * moment we always flush but we need to fix hpte_update and test if the
  299. * optimisation is worth it.
  300. */
  301. static inline int __ptep_test_and_clear_dirty(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
  302. {
  303. unsigned long old;
  304. if ((pte_val(*ptep) & _PAGE_DIRTY) == 0)
  305. return 0;
  306. old = pte_update(ptep, _PAGE_DIRTY);
  307. if (old & _PAGE_HASHPTE)
  308. hpte_update(mm, addr, old, 0);
  309. return (old & _PAGE_DIRTY) != 0;
  310. }
  311. #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_DIRTY
  312. #define ptep_test_and_clear_dirty(__vma, __addr, __ptep) \
  313. ({ \
  314. int __r; \
  315. __r = __ptep_test_and_clear_dirty((__vma)->vm_mm, __addr, __ptep); \
  316. __r; \
  317. })
  318. #define __HAVE_ARCH_PTEP_SET_WRPROTECT
  319. static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
  320. {
  321. unsigned long old;
  322. if ((pte_val(*ptep) & _PAGE_RW) == 0)
  323. return;
  324. old = pte_update(ptep, _PAGE_RW);
  325. if (old & _PAGE_HASHPTE)
  326. hpte_update(mm, addr, old, 0);
  327. }
  328. /*
  329. * We currently remove entries from the hashtable regardless of whether
  330. * the entry was young or dirty. The generic routines only flush if the
  331. * entry was young or dirty which is not good enough.
  332. *
  333. * We should be more intelligent about this but for the moment we override
  334. * these functions and force a tlb flush unconditionally
  335. */
  336. #define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
  337. #define ptep_clear_flush_young(__vma, __address, __ptep) \
  338. ({ \
  339. int __young = __ptep_test_and_clear_young((__vma)->vm_mm, __address, \
  340. __ptep); \
  341. __young; \
  342. })
  343. #define __HAVE_ARCH_PTEP_CLEAR_DIRTY_FLUSH
  344. #define ptep_clear_flush_dirty(__vma, __address, __ptep) \
  345. ({ \
  346. int __dirty = __ptep_test_and_clear_dirty((__vma)->vm_mm, __address, \
  347. __ptep); \
  348. flush_tlb_page(__vma, __address); \
  349. __dirty; \
  350. })
  351. #define __HAVE_ARCH_PTEP_GET_AND_CLEAR
  352. static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
  353. {
  354. unsigned long old = pte_update(ptep, ~0UL);
  355. if (old & _PAGE_HASHPTE)
  356. hpte_update(mm, addr, old, 0);
  357. return __pte(old);
  358. }
  359. static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t * ptep)
  360. {
  361. unsigned long old = pte_update(ptep, ~0UL);
  362. if (old & _PAGE_HASHPTE)
  363. hpte_update(mm, addr, old, 0);
  364. }
  365. /*
  366. * set_pte stores a linux PTE into the linux page table.
  367. */
  368. static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
  369. pte_t *ptep, pte_t pte)
  370. {
  371. if (pte_present(*ptep)) {
  372. pte_clear(mm, addr, ptep);
  373. flush_tlb_pending();
  374. }
  375. *ptep = __pte(pte_val(pte)) & ~_PAGE_HPTEFLAGS;
  376. }
  377. /* Set the dirty and/or accessed bits atomically in a linux PTE, this
  378. * function doesn't need to flush the hash entry
  379. */
  380. #define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
  381. static inline void __ptep_set_access_flags(pte_t *ptep, pte_t entry, int dirty)
  382. {
  383. unsigned long bits = pte_val(entry) &
  384. (_PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_RW | _PAGE_EXEC);
  385. unsigned long old, tmp;
  386. __asm__ __volatile__(
  387. "1: ldarx %0,0,%4\n\
  388. andi. %1,%0,%6\n\
  389. bne- 1b \n\
  390. or %0,%3,%0\n\
  391. stdcx. %0,0,%4\n\
  392. bne- 1b"
  393. :"=&r" (old), "=&r" (tmp), "=m" (*ptep)
  394. :"r" (bits), "r" (ptep), "m" (*ptep), "i" (_PAGE_BUSY)
  395. :"cc");
  396. }
  397. #define ptep_set_access_flags(__vma, __address, __ptep, __entry, __dirty) \
  398. do { \
  399. __ptep_set_access_flags(__ptep, __entry, __dirty); \
  400. flush_tlb_page_nohash(__vma, __address); \
  401. } while(0)
  402. /*
  403. * Macro to mark a page protection value as "uncacheable".
  404. */
  405. #define pgprot_noncached(prot) (__pgprot(pgprot_val(prot) | _PAGE_NO_CACHE | _PAGE_GUARDED))
  406. struct file;
  407. extern pgprot_t phys_mem_access_prot(struct file *file, unsigned long addr,
  408. unsigned long size, pgprot_t vma_prot);
  409. #define __HAVE_PHYS_MEM_ACCESS_PROT
  410. #define __HAVE_ARCH_PTE_SAME
  411. #define pte_same(A,B) (((pte_val(A) ^ pte_val(B)) & ~_PAGE_HPTEFLAGS) == 0)
  412. extern unsigned long ioremap_bot, ioremap_base;
  413. #define USER_PGD_PTRS (PAGE_OFFSET >> PGDIR_SHIFT)
  414. #define KERNEL_PGD_PTRS (PTRS_PER_PGD-USER_PGD_PTRS)
  415. #define pte_ERROR(e) \
  416. printk("%s:%d: bad pte %016lx.\n", __FILE__, __LINE__, pte_val(e))
  417. #define pmd_ERROR(e) \
  418. printk("%s:%d: bad pmd %08x.\n", __FILE__, __LINE__, pmd_val(e))
  419. #define pgd_ERROR(e) \
  420. printk("%s:%d: bad pgd %08x.\n", __FILE__, __LINE__, pgd_val(e))
  421. extern pgd_t swapper_pg_dir[1024];
  422. extern pgd_t ioremap_dir[1024];
  423. extern void paging_init(void);
  424. /*
  425. * Because the huge pgtables are only 2 level, they can take
  426. * at most around 4M, much less than one hugepage which the
  427. * process is presumably entitled to use. So we don't bother
  428. * freeing up the pagetables on unmap, and wait until
  429. * destroy_context() to clean up the lot.
  430. */
  431. #define hugetlb_free_pgd_range(tlb, addr, end, floor, ceiling) \
  432. do { } while (0)
  433. /*
  434. * This gets called at the end of handling a page fault, when
  435. * the kernel has put a new PTE into the page table for the process.
  436. * We use it to put a corresponding HPTE into the hash table
  437. * ahead of time, instead of waiting for the inevitable extra
  438. * hash-table miss exception.
  439. */
  440. struct vm_area_struct;
  441. extern void update_mmu_cache(struct vm_area_struct *, unsigned long, pte_t);
  442. /* Encode and de-code a swap entry */
  443. #define __swp_type(entry) (((entry).val >> 1) & 0x3f)
  444. #define __swp_offset(entry) ((entry).val >> 8)
  445. #define __swp_entry(type, offset) ((swp_entry_t) { ((type) << 1) | ((offset) << 8) })
  446. #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) >> PTE_SHIFT })
  447. #define __swp_entry_to_pte(x) ((pte_t) { (x).val << PTE_SHIFT })
  448. #define pte_to_pgoff(pte) (pte_val(pte) >> PTE_SHIFT)
  449. #define pgoff_to_pte(off) ((pte_t) {((off) << PTE_SHIFT)|_PAGE_FILE})
  450. #define PTE_FILE_MAX_BITS (BITS_PER_LONG - PTE_SHIFT)
  451. /*
  452. * kern_addr_valid is intended to indicate whether an address is a valid
  453. * kernel address. Most 32-bit archs define it as always true (like this)
  454. * but most 64-bit archs actually perform a test. What should we do here?
  455. * The only use is in fs/ncpfs/dir.c
  456. */
  457. #define kern_addr_valid(addr) (1)
  458. #define io_remap_page_range(vma, vaddr, paddr, size, prot) \
  459. remap_pfn_range(vma, vaddr, (paddr) >> PAGE_SHIFT, size, prot)
  460. #define io_remap_pfn_range(vma, vaddr, pfn, size, prot) \
  461. remap_pfn_range(vma, vaddr, pfn, size, prot)
  462. #define MK_IOSPACE_PFN(space, pfn) (pfn)
  463. #define GET_IOSPACE(pfn) 0
  464. #define GET_PFN(pfn) (pfn)
  465. void pgtable_cache_init(void);
  466. extern void hpte_init_native(void);
  467. extern void hpte_init_lpar(void);
  468. extern void hpte_init_iSeries(void);
  469. /* imalloc region types */
  470. #define IM_REGION_UNUSED 0x1
  471. #define IM_REGION_SUBSET 0x2
  472. #define IM_REGION_EXISTS 0x4
  473. #define IM_REGION_OVERLAP 0x8
  474. #define IM_REGION_SUPERSET 0x10
  475. extern struct vm_struct * im_get_free_area(unsigned long size);
  476. extern struct vm_struct * im_get_area(unsigned long v_addr, unsigned long size,
  477. int region_type);
  478. unsigned long im_free(void *addr);
  479. extern long pSeries_lpar_hpte_insert(unsigned long hpte_group,
  480. unsigned long va, unsigned long prpn,
  481. int secondary, unsigned long hpteflags,
  482. int bolted, int large);
  483. extern long native_hpte_insert(unsigned long hpte_group, unsigned long va,
  484. unsigned long prpn, int secondary,
  485. unsigned long hpteflags, int bolted, int large);
  486. /*
  487. * find_linux_pte returns the address of a linux pte for a given
  488. * effective address and directory. If not found, it returns zero.
  489. */
  490. static inline pte_t *find_linux_pte(pgd_t *pgdir, unsigned long ea)
  491. {
  492. pgd_t *pg;
  493. pud_t *pu;
  494. pmd_t *pm;
  495. pte_t *pt = NULL;
  496. pte_t pte;
  497. pg = pgdir + pgd_index(ea);
  498. if (!pgd_none(*pg)) {
  499. pu = pud_offset(pg, ea);
  500. if (!pud_none(*pu)) {
  501. pm = pmd_offset(pu, ea);
  502. if (pmd_present(*pm)) {
  503. pt = pte_offset_kernel(pm, ea);
  504. pte = *pt;
  505. if (!pte_present(pte))
  506. pt = NULL;
  507. }
  508. }
  509. }
  510. return pt;
  511. }
  512. #include <asm-generic/pgtable.h>
  513. #endif /* __ASSEMBLY__ */
  514. #endif /* _PPC64_PGTABLE_H */