pgtable.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. /*
  2. * Copyright (C) 2008-2009 Michal Simek <monstr@monstr.eu>
  3. * Copyright (C) 2008-2009 PetaLogix
  4. * Copyright (C) 2006 Atmark Techno, Inc.
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file "COPYING" in the main directory of this archive
  8. * for more details.
  9. */
  10. #ifndef _ASM_MICROBLAZE_PGTABLE_H
  11. #define _ASM_MICROBLAZE_PGTABLE_H
  12. #include <asm/setup.h>
  13. #define io_remap_pfn_range(vma, vaddr, pfn, size, prot) \
  14. remap_pfn_range(vma, vaddr, pfn, size, prot)
  15. #ifndef __ASSEMBLY__
  16. extern int mem_init_done;
  17. #endif
  18. #ifndef CONFIG_MMU
  19. #define pgd_present(pgd) (1) /* pages are always present on non MMU */
  20. #define pgd_none(pgd) (0)
  21. #define pgd_bad(pgd) (0)
  22. #define pgd_clear(pgdp)
  23. #define kern_addr_valid(addr) (1)
  24. #define pmd_offset(a, b) ((void *) 0)
  25. #define PAGE_NONE __pgprot(0) /* these mean nothing to non MMU */
  26. #define PAGE_SHARED __pgprot(0) /* these mean nothing to non MMU */
  27. #define PAGE_COPY __pgprot(0) /* these mean nothing to non MMU */
  28. #define PAGE_READONLY __pgprot(0) /* these mean nothing to non MMU */
  29. #define PAGE_KERNEL __pgprot(0) /* these mean nothing to non MMU */
  30. #define pgprot_noncached(x) (x)
  31. #define __swp_type(x) (0)
  32. #define __swp_offset(x) (0)
  33. #define __swp_entry(typ, off) ((swp_entry_t) { ((typ) | ((off) << 7)) })
  34. #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
  35. #define __swp_entry_to_pte(x) ((pte_t) { (x).val })
  36. #ifndef __ASSEMBLY__
  37. static inline int pte_file(pte_t pte) { return 0; }
  38. #endif /* __ASSEMBLY__ */
  39. #define ZERO_PAGE(vaddr) ({ BUG(); NULL; })
  40. #define swapper_pg_dir ((pgd_t *) NULL)
  41. #define pgtable_cache_init() do {} while (0)
  42. #define arch_enter_lazy_cpu_mode() do {} while (0)
  43. #define pgprot_noncached_wc(prot) prot
  44. #else /* CONFIG_MMU */
  45. #include <asm-generic/4level-fixup.h>
  46. #ifdef __KERNEL__
  47. #ifndef __ASSEMBLY__
  48. #include <linux/sched.h>
  49. #include <linux/threads.h>
  50. #include <asm/processor.h> /* For TASK_SIZE */
  51. #include <asm/mmu.h>
  52. #include <asm/page.h>
  53. #define FIRST_USER_ADDRESS 0
  54. extern unsigned long va_to_phys(unsigned long address);
  55. extern pte_t *va_to_pte(unsigned long address);
  56. /*
  57. * The following only work if pte_present() is true.
  58. * Undefined behaviour if not..
  59. */
  60. static inline int pte_special(pte_t pte) { return 0; }
  61. static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
  62. /* Start and end of the vmalloc area. */
  63. /* Make sure to map the vmalloc area above the pinned kernel memory area
  64. of 32Mb. */
  65. #define VMALLOC_START (CONFIG_KERNEL_START + \
  66. max(32 * 1024 * 1024UL, memory_size))
  67. #define VMALLOC_END ioremap_bot
  68. #endif /* __ASSEMBLY__ */
  69. /*
  70. * Macro to mark a page protection value as "uncacheable".
  71. */
  72. #define _PAGE_CACHE_CTL (_PAGE_GUARDED | _PAGE_NO_CACHE | \
  73. _PAGE_WRITETHRU)
  74. #define pgprot_noncached(prot) \
  75. (__pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) | \
  76. _PAGE_NO_CACHE | _PAGE_GUARDED))
  77. #define pgprot_noncached_wc(prot) \
  78. (__pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) | \
  79. _PAGE_NO_CACHE))
  80. /*
  81. * The MicroBlaze MMU is identical to the PPC-40x MMU, and uses a hash
  82. * table containing PTEs, together with a set of 16 segment registers, to
  83. * define the virtual to physical address mapping.
  84. *
  85. * We use the hash table as an extended TLB, i.e. a cache of currently
  86. * active mappings. We maintain a two-level page table tree, much
  87. * like that used by the i386, for the sake of the Linux memory
  88. * management code. Low-level assembler code in hashtable.S
  89. * (procedure hash_page) is responsible for extracting ptes from the
  90. * tree and putting them into the hash table when necessary, and
  91. * updating the accessed and modified bits in the page table tree.
  92. */
  93. /*
  94. * The MicroBlaze processor has a TLB architecture identical to PPC-40x. The
  95. * instruction and data sides share a unified, 64-entry, semi-associative
  96. * TLB which is maintained totally under software control. In addition, the
  97. * instruction side has a hardware-managed, 2,4, or 8-entry, fully-associative
  98. * TLB which serves as a first level to the shared TLB. These two TLBs are
  99. * known as the UTLB and ITLB, respectively (see "mmu.h" for definitions).
  100. */
  101. /*
  102. * The normal case is that PTEs are 32-bits and we have a 1-page
  103. * 1024-entry pgdir pointing to 1-page 1024-entry PTE pages. -- paulus
  104. *
  105. */
  106. /* PMD_SHIFT determines the size of the area mapped by the PTE pages */
  107. #define PMD_SHIFT (PAGE_SHIFT + PTE_SHIFT)
  108. #define PMD_SIZE (1UL << PMD_SHIFT)
  109. #define PMD_MASK (~(PMD_SIZE-1))
  110. /* PGDIR_SHIFT determines what a top-level page table entry can map */
  111. #define PGDIR_SHIFT PMD_SHIFT
  112. #define PGDIR_SIZE (1UL << PGDIR_SHIFT)
  113. #define PGDIR_MASK (~(PGDIR_SIZE-1))
  114. /*
  115. * entries per page directory level: our page-table tree is two-level, so
  116. * we don't really have any PMD directory.
  117. */
  118. #define PTRS_PER_PTE (1 << PTE_SHIFT)
  119. #define PTRS_PER_PMD 1
  120. #define PTRS_PER_PGD (1 << (32 - PGDIR_SHIFT))
  121. #define USER_PTRS_PER_PGD (TASK_SIZE / PGDIR_SIZE)
  122. #define FIRST_USER_PGD_NR 0
  123. #define USER_PGD_PTRS (PAGE_OFFSET >> PGDIR_SHIFT)
  124. #define KERNEL_PGD_PTRS (PTRS_PER_PGD-USER_PGD_PTRS)
  125. #define pte_ERROR(e) \
  126. printk(KERN_ERR "%s:%d: bad pte "PTE_FMT".\n", \
  127. __FILE__, __LINE__, pte_val(e))
  128. #define pmd_ERROR(e) \
  129. printk(KERN_ERR "%s:%d: bad pmd %08lx.\n", \
  130. __FILE__, __LINE__, pmd_val(e))
  131. #define pgd_ERROR(e) \
  132. printk(KERN_ERR "%s:%d: bad pgd %08lx.\n", \
  133. __FILE__, __LINE__, pgd_val(e))
  134. /*
  135. * Bits in a linux-style PTE. These match the bits in the
  136. * (hardware-defined) PTE as closely as possible.
  137. */
  138. /* There are several potential gotchas here. The hardware TLBLO
  139. * field looks like this:
  140. *
  141. * 0 1 2 3 4 ... 18 19 20 21 22 23 24 25 26 27 28 29 30 31
  142. * RPN..................... 0 0 EX WR ZSEL....... W I M G
  143. *
  144. * Where possible we make the Linux PTE bits match up with this
  145. *
  146. * - bits 20 and 21 must be cleared, because we use 4k pages (4xx can
  147. * support down to 1k pages), this is done in the TLBMiss exception
  148. * handler.
  149. * - We use only zones 0 (for kernel pages) and 1 (for user pages)
  150. * of the 16 available. Bit 24-26 of the TLB are cleared in the TLB
  151. * miss handler. Bit 27 is PAGE_USER, thus selecting the correct
  152. * zone.
  153. * - PRESENT *must* be in the bottom two bits because swap cache
  154. * entries use the top 30 bits. Because 4xx doesn't support SMP
  155. * anyway, M is irrelevant so we borrow it for PAGE_PRESENT. Bit 30
  156. * is cleared in the TLB miss handler before the TLB entry is loaded.
  157. * - All other bits of the PTE are loaded into TLBLO without
  158. * * modification, leaving us only the bits 20, 21, 24, 25, 26, 30 for
  159. * software PTE bits. We actually use use bits 21, 24, 25, and
  160. * 30 respectively for the software bits: ACCESSED, DIRTY, RW, and
  161. * PRESENT.
  162. */
  163. /* Definitions for MicroBlaze. */
  164. #define _PAGE_GUARDED 0x001 /* G: page is guarded from prefetch */
  165. #define _PAGE_FILE 0x001 /* when !present: nonlinear file mapping */
  166. #define _PAGE_PRESENT 0x002 /* software: PTE contains a translation */
  167. #define _PAGE_NO_CACHE 0x004 /* I: caching is inhibited */
  168. #define _PAGE_WRITETHRU 0x008 /* W: caching is write-through */
  169. #define _PAGE_USER 0x010 /* matches one of the zone permission bits */
  170. #define _PAGE_RW 0x040 /* software: Writes permitted */
  171. #define _PAGE_DIRTY 0x080 /* software: dirty page */
  172. #define _PAGE_HWWRITE 0x100 /* hardware: Dirty & RW, set in exception */
  173. #define _PAGE_HWEXEC 0x200 /* hardware: EX permission */
  174. #define _PAGE_ACCESSED 0x400 /* software: R: page referenced */
  175. #define _PMD_PRESENT PAGE_MASK
  176. /*
  177. * Some bits are unused...
  178. */
  179. #ifndef _PAGE_HASHPTE
  180. #define _PAGE_HASHPTE 0
  181. #endif
  182. #ifndef _PTE_NONE_MASK
  183. #define _PTE_NONE_MASK 0
  184. #endif
  185. #ifndef _PAGE_SHARED
  186. #define _PAGE_SHARED 0
  187. #endif
  188. #ifndef _PAGE_HWWRITE
  189. #define _PAGE_HWWRITE 0
  190. #endif
  191. #ifndef _PAGE_HWEXEC
  192. #define _PAGE_HWEXEC 0
  193. #endif
  194. #ifndef _PAGE_EXEC
  195. #define _PAGE_EXEC 0
  196. #endif
  197. #define _PAGE_CHG_MASK (PAGE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY)
  198. /*
  199. * Note: the _PAGE_COHERENT bit automatically gets set in the hardware
  200. * PTE if CONFIG_SMP is defined (hash_page does this); there is no need
  201. * to have it in the Linux PTE, and in fact the bit could be reused for
  202. * another purpose. -- paulus.
  203. */
  204. #define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED)
  205. #define _PAGE_WRENABLE (_PAGE_RW | _PAGE_DIRTY | _PAGE_HWWRITE)
  206. #define _PAGE_KERNEL \
  207. (_PAGE_BASE | _PAGE_WRENABLE | _PAGE_SHARED | _PAGE_HWEXEC)
  208. #define _PAGE_IO (_PAGE_KERNEL | _PAGE_NO_CACHE | _PAGE_GUARDED)
  209. #define PAGE_NONE __pgprot(_PAGE_BASE)
  210. #define PAGE_READONLY __pgprot(_PAGE_BASE | _PAGE_USER)
  211. #define PAGE_READONLY_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_EXEC)
  212. #define PAGE_SHARED __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW)
  213. #define PAGE_SHARED_X \
  214. __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW | _PAGE_EXEC)
  215. #define PAGE_COPY __pgprot(_PAGE_BASE | _PAGE_USER)
  216. #define PAGE_COPY_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_EXEC)
  217. #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
  218. #define PAGE_KERNEL_RO __pgprot(_PAGE_BASE | _PAGE_SHARED)
  219. #define PAGE_KERNEL_CI __pgprot(_PAGE_IO)
  220. /*
  221. * We consider execute permission the same as read.
  222. * Also, write permissions imply read permissions.
  223. */
  224. #define __P000 PAGE_NONE
  225. #define __P001 PAGE_READONLY_X
  226. #define __P010 PAGE_COPY
  227. #define __P011 PAGE_COPY_X
  228. #define __P100 PAGE_READONLY
  229. #define __P101 PAGE_READONLY_X
  230. #define __P110 PAGE_COPY
  231. #define __P111 PAGE_COPY_X
  232. #define __S000 PAGE_NONE
  233. #define __S001 PAGE_READONLY_X
  234. #define __S010 PAGE_SHARED
  235. #define __S011 PAGE_SHARED_X
  236. #define __S100 PAGE_READONLY
  237. #define __S101 PAGE_READONLY_X
  238. #define __S110 PAGE_SHARED
  239. #define __S111 PAGE_SHARED_X
  240. #ifndef __ASSEMBLY__
  241. /*
  242. * ZERO_PAGE is a global shared page that is always zero: used
  243. * for zero-mapped memory areas etc..
  244. */
  245. extern unsigned long empty_zero_page[1024];
  246. #define ZERO_PAGE(vaddr) (virt_to_page(empty_zero_page))
  247. #endif /* __ASSEMBLY__ */
  248. #define pte_none(pte) ((pte_val(pte) & ~_PTE_NONE_MASK) == 0)
  249. #define pte_present(pte) (pte_val(pte) & _PAGE_PRESENT)
  250. #define pte_clear(mm, addr, ptep) \
  251. do { set_pte_at((mm), (addr), (ptep), __pte(0)); } while (0)
  252. #define pmd_none(pmd) (!pmd_val(pmd))
  253. #define pmd_bad(pmd) ((pmd_val(pmd) & _PMD_PRESENT) == 0)
  254. #define pmd_present(pmd) ((pmd_val(pmd) & _PMD_PRESENT) != 0)
  255. #define pmd_clear(pmdp) do { pmd_val(*(pmdp)) = 0; } while (0)
  256. #define pte_page(x) (mem_map + (unsigned long) \
  257. ((pte_val(x) - memory_start) >> PAGE_SHIFT))
  258. #define PFN_SHIFT_OFFSET (PAGE_SHIFT)
  259. #define pte_pfn(x) (pte_val(x) >> PFN_SHIFT_OFFSET)
  260. #define pfn_pte(pfn, prot) \
  261. __pte(((pte_basic_t)(pfn) << PFN_SHIFT_OFFSET) | pgprot_val(prot))
  262. #ifndef __ASSEMBLY__
  263. /*
  264. * The "pgd_xxx()" functions here are trivial for a folded two-level
  265. * setup: the pgd is never bad, and a pmd always exists (as it's folded
  266. * into the pgd entry)
  267. */
  268. static inline int pgd_none(pgd_t pgd) { return 0; }
  269. static inline int pgd_bad(pgd_t pgd) { return 0; }
  270. static inline int pgd_present(pgd_t pgd) { return 1; }
  271. #define pgd_clear(xp) do { } while (0)
  272. #define pgd_page(pgd) \
  273. ((unsigned long) __va(pgd_val(pgd) & PAGE_MASK))
  274. /*
  275. * The following only work if pte_present() is true.
  276. * Undefined behaviour if not..
  277. */
  278. static inline int pte_read(pte_t pte) { return pte_val(pte) & _PAGE_USER; }
  279. static inline int pte_write(pte_t pte) { return pte_val(pte) & _PAGE_RW; }
  280. static inline int pte_exec(pte_t pte) { return pte_val(pte) & _PAGE_EXEC; }
  281. static inline int pte_dirty(pte_t pte) { return pte_val(pte) & _PAGE_DIRTY; }
  282. static inline int pte_young(pte_t pte) { return pte_val(pte) & _PAGE_ACCESSED; }
  283. static inline int pte_file(pte_t pte) { return pte_val(pte) & _PAGE_FILE; }
  284. static inline void pte_uncache(pte_t pte) { pte_val(pte) |= _PAGE_NO_CACHE; }
  285. static inline void pte_cache(pte_t pte) { pte_val(pte) &= ~_PAGE_NO_CACHE; }
  286. static inline pte_t pte_rdprotect(pte_t pte) \
  287. { pte_val(pte) &= ~_PAGE_USER; return pte; }
  288. static inline pte_t pte_wrprotect(pte_t pte) \
  289. { pte_val(pte) &= ~(_PAGE_RW | _PAGE_HWWRITE); return pte; }
  290. static inline pte_t pte_exprotect(pte_t pte) \
  291. { pte_val(pte) &= ~_PAGE_EXEC; return pte; }
  292. static inline pte_t pte_mkclean(pte_t pte) \
  293. { pte_val(pte) &= ~(_PAGE_DIRTY | _PAGE_HWWRITE); return pte; }
  294. static inline pte_t pte_mkold(pte_t pte) \
  295. { pte_val(pte) &= ~_PAGE_ACCESSED; return pte; }
  296. static inline pte_t pte_mkread(pte_t pte) \
  297. { pte_val(pte) |= _PAGE_USER; return pte; }
  298. static inline pte_t pte_mkexec(pte_t pte) \
  299. { pte_val(pte) |= _PAGE_USER | _PAGE_EXEC; return pte; }
  300. static inline pte_t pte_mkwrite(pte_t pte) \
  301. { pte_val(pte) |= _PAGE_RW; return pte; }
  302. static inline pte_t pte_mkdirty(pte_t pte) \
  303. { pte_val(pte) |= _PAGE_DIRTY; return pte; }
  304. static inline pte_t pte_mkyoung(pte_t pte) \
  305. { pte_val(pte) |= _PAGE_ACCESSED; return pte; }
  306. /*
  307. * Conversion functions: convert a page and protection to a page entry,
  308. * and a page entry and page directory to the page they refer to.
  309. */
  310. static inline pte_t mk_pte_phys(phys_addr_t physpage, pgprot_t pgprot)
  311. {
  312. pte_t pte;
  313. pte_val(pte) = physpage | pgprot_val(pgprot);
  314. return pte;
  315. }
  316. #define mk_pte(page, pgprot) \
  317. ({ \
  318. pte_t pte; \
  319. pte_val(pte) = (((page - mem_map) << PAGE_SHIFT) + memory_start) | \
  320. pgprot_val(pgprot); \
  321. pte; \
  322. })
  323. static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
  324. {
  325. pte_val(pte) = (pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot);
  326. return pte;
  327. }
  328. /*
  329. * Atomic PTE updates.
  330. *
  331. * pte_update clears and sets bit atomically, and returns
  332. * the old pte value.
  333. * The ((unsigned long)(p+1) - 4) hack is to get to the least-significant
  334. * 32 bits of the PTE regardless of whether PTEs are 32 or 64 bits.
  335. */
  336. static inline unsigned long pte_update(pte_t *p, unsigned long clr,
  337. unsigned long set)
  338. {
  339. unsigned long old, tmp, msr;
  340. __asm__ __volatile__("\
  341. msrclr %2, 0x2\n\
  342. nop\n\
  343. lw %0, %4, r0\n\
  344. andn %1, %0, %5\n\
  345. or %1, %1, %6\n\
  346. sw %1, %4, r0\n\
  347. mts rmsr, %2\n\
  348. nop"
  349. : "=&r" (old), "=&r" (tmp), "=&r" (msr), "=m" (*p)
  350. : "r" ((unsigned long)(p + 1) - 4), "r" (clr), "r" (set), "m" (*p)
  351. : "cc");
  352. return old;
  353. }
  354. /*
  355. * set_pte stores a linux PTE into the linux page table.
  356. */
  357. static inline void set_pte(struct mm_struct *mm, unsigned long addr,
  358. pte_t *ptep, pte_t pte)
  359. {
  360. *ptep = pte;
  361. }
  362. static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
  363. pte_t *ptep, pte_t pte)
  364. {
  365. *ptep = pte;
  366. }
  367. static inline int ptep_test_and_clear_young(struct mm_struct *mm,
  368. unsigned long addr, pte_t *ptep)
  369. {
  370. return (pte_update(ptep, _PAGE_ACCESSED, 0) & _PAGE_ACCESSED) != 0;
  371. }
  372. static inline int ptep_test_and_clear_dirty(struct mm_struct *mm,
  373. unsigned long addr, pte_t *ptep)
  374. {
  375. return (pte_update(ptep, \
  376. (_PAGE_DIRTY | _PAGE_HWWRITE), 0) & _PAGE_DIRTY) != 0;
  377. }
  378. static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
  379. unsigned long addr, pte_t *ptep)
  380. {
  381. return __pte(pte_update(ptep, ~_PAGE_HASHPTE, 0));
  382. }
  383. /*static inline void ptep_set_wrprotect(struct mm_struct *mm,
  384. unsigned long addr, pte_t *ptep)
  385. {
  386. pte_update(ptep, (_PAGE_RW | _PAGE_HWWRITE), 0);
  387. }*/
  388. static inline void ptep_mkdirty(struct mm_struct *mm,
  389. unsigned long addr, pte_t *ptep)
  390. {
  391. pte_update(ptep, 0, _PAGE_DIRTY);
  392. }
  393. /*#define pte_same(A,B) (((pte_val(A) ^ pte_val(B)) & ~_PAGE_HASHPTE) == 0)*/
  394. /* Convert pmd entry to page */
  395. /* our pmd entry is an effective address of pte table*/
  396. /* returns effective address of the pmd entry*/
  397. #define pmd_page_kernel(pmd) ((unsigned long) (pmd_val(pmd) & PAGE_MASK))
  398. /* returns struct *page of the pmd entry*/
  399. #define pmd_page(pmd) (pfn_to_page(__pa(pmd_val(pmd)) >> PAGE_SHIFT))
  400. /* to find an entry in a kernel page-table-directory */
  401. #define pgd_offset_k(address) pgd_offset(&init_mm, address)
  402. /* to find an entry in a page-table-directory */
  403. #define pgd_index(address) ((address) >> PGDIR_SHIFT)
  404. #define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
  405. /* Find an entry in the second-level page table.. */
  406. static inline pmd_t *pmd_offset(pgd_t *dir, unsigned long address)
  407. {
  408. return (pmd_t *) dir;
  409. }
  410. /* Find an entry in the third-level page table.. */
  411. #define pte_index(address) \
  412. (((address) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1))
  413. #define pte_offset_kernel(dir, addr) \
  414. ((pte_t *) pmd_page_kernel(*(dir)) + pte_index(addr))
  415. #define pte_offset_map(dir, addr) \
  416. ((pte_t *) kmap_atomic(pmd_page(*(dir)), KM_PTE0) + pte_index(addr))
  417. #define pte_offset_map_nested(dir, addr) \
  418. ((pte_t *) kmap_atomic(pmd_page(*(dir)), KM_PTE1) + pte_index(addr))
  419. #define pte_unmap(pte) kunmap_atomic(pte, KM_PTE0)
  420. #define pte_unmap_nested(pte) kunmap_atomic(pte, KM_PTE1)
  421. /* Encode and decode a nonlinear file mapping entry */
  422. #define PTE_FILE_MAX_BITS 29
  423. #define pte_to_pgoff(pte) (pte_val(pte) >> 3)
  424. #define pgoff_to_pte(off) ((pte_t) { ((off) << 3) | _PAGE_FILE })
  425. extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
  426. /*
  427. * When flushing the tlb entry for a page, we also need to flush the hash
  428. * table entry. flush_hash_page is assembler (for speed) in hashtable.S.
  429. */
  430. extern int flush_hash_page(unsigned context, unsigned long va, pte_t *ptep);
  431. /* Add an HPTE to the hash table */
  432. extern void add_hash_page(unsigned context, unsigned long va, pte_t *ptep);
  433. /*
  434. * Encode and decode a swap entry.
  435. * Note that the bits we use in a PTE for representing a swap entry
  436. * must not include the _PAGE_PRESENT bit, or the _PAGE_HASHPTE bit
  437. * (if used). -- paulus
  438. */
  439. #define __swp_type(entry) ((entry).val & 0x3f)
  440. #define __swp_offset(entry) ((entry).val >> 6)
  441. #define __swp_entry(type, offset) \
  442. ((swp_entry_t) { (type) | ((offset) << 6) })
  443. #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) >> 2 })
  444. #define __swp_entry_to_pte(x) ((pte_t) { (x).val << 2 })
  445. /* CONFIG_APUS */
  446. /* For virtual address to physical address conversion */
  447. extern void cache_clear(__u32 addr, int length);
  448. extern void cache_push(__u32 addr, int length);
  449. extern int mm_end_of_chunk(unsigned long addr, int len);
  450. extern unsigned long iopa(unsigned long addr);
  451. /* extern unsigned long mm_ptov(unsigned long addr) \
  452. __attribute__ ((const)); TBD */
  453. /* Values for nocacheflag and cmode */
  454. /* These are not used by the APUS kernel_map, but prevents
  455. * compilation errors.
  456. */
  457. #define IOMAP_FULL_CACHING 0
  458. #define IOMAP_NOCACHE_SER 1
  459. #define IOMAP_NOCACHE_NONSER 2
  460. #define IOMAP_NO_COPYBACK 3
  461. /*
  462. * Map some physical address range into the kernel address space.
  463. */
  464. extern unsigned long kernel_map(unsigned long paddr, unsigned long size,
  465. int nocacheflag, unsigned long *memavailp);
  466. /*
  467. * Set cache mode of (kernel space) address range.
  468. */
  469. extern void kernel_set_cachemode(unsigned long address, unsigned long size,
  470. unsigned int cmode);
  471. /* Needs to be defined here and not in linux/mm.h, as it is arch dependent */
  472. #define kern_addr_valid(addr) (1)
  473. #define io_remap_page_range remap_page_range
  474. /*
  475. * No page table caches to initialise
  476. */
  477. #define pgtable_cache_init() do { } while (0)
  478. void do_page_fault(struct pt_regs *regs, unsigned long address,
  479. unsigned long error_code);
  480. void __init io_block_mapping(unsigned long virt, phys_addr_t phys,
  481. unsigned int size, int flags);
  482. void __init adjust_total_lowmem(void);
  483. void mapin_ram(void);
  484. int map_page(unsigned long va, phys_addr_t pa, int flags);
  485. extern int mem_init_done;
  486. asmlinkage void __init mmu_init(void);
  487. void __init *early_get_page(void);
  488. #endif /* __ASSEMBLY__ */
  489. #endif /* __KERNEL__ */
  490. #endif /* CONFIG_MMU */
  491. #ifndef __ASSEMBLY__
  492. #include <asm-generic/pgtable.h>
  493. extern unsigned long ioremap_bot, ioremap_base;
  494. void *consistent_alloc(int gfp, size_t size, dma_addr_t *dma_handle);
  495. void consistent_free(void *vaddr);
  496. void consistent_sync(void *vaddr, size_t size, int direction);
  497. void consistent_sync_page(struct page *page, unsigned long offset,
  498. size_t size, int direction);
  499. void setup_memory(void);
  500. #endif /* __ASSEMBLY__ */
  501. #endif /* _ASM_MICROBLAZE_PGTABLE_H */