pgtable.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. #ifndef _ALPHA_PGTABLE_H
  2. #define _ALPHA_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 Alpha page table tree.
  7. *
  8. * This hopefully works with any standard Alpha page-size, as defined
  9. * in <asm/page.h> (currently 8192).
  10. */
  11. #include <linux/mmzone.h>
  12. #include <asm/page.h>
  13. #include <asm/processor.h> /* For TASK_SIZE */
  14. #include <asm/machvec.h>
  15. #include <asm/setup.h>
  16. struct mm_struct;
  17. struct vm_area_struct;
  18. /* Certain architectures need to do special things when PTEs
  19. * within a page table are directly modified. Thus, the following
  20. * hook is made available.
  21. */
  22. #define set_pte(pteptr, pteval) ((*(pteptr)) = (pteval))
  23. #define set_pte_at(mm,addr,ptep,pteval) set_pte(ptep,pteval)
  24. /* PMD_SHIFT determines the size of the area a second-level page table can map */
  25. #define PMD_SHIFT (PAGE_SHIFT + (PAGE_SHIFT-3))
  26. #define PMD_SIZE (1UL << PMD_SHIFT)
  27. #define PMD_MASK (~(PMD_SIZE-1))
  28. /* PGDIR_SHIFT determines what a third-level page table entry can map */
  29. #define PGDIR_SHIFT (PAGE_SHIFT + 2*(PAGE_SHIFT-3))
  30. #define PGDIR_SIZE (1UL << PGDIR_SHIFT)
  31. #define PGDIR_MASK (~(PGDIR_SIZE-1))
  32. /*
  33. * Entries per page directory level: the Alpha is three-level, with
  34. * all levels having a one-page page table.
  35. */
  36. #define PTRS_PER_PTE (1UL << (PAGE_SHIFT-3))
  37. #define PTRS_PER_PMD (1UL << (PAGE_SHIFT-3))
  38. #define PTRS_PER_PGD (1UL << (PAGE_SHIFT-3))
  39. #define USER_PTRS_PER_PGD (TASK_SIZE / PGDIR_SIZE)
  40. #define FIRST_USER_ADDRESS 0UL
  41. /* Number of pointers that fit on a page: this will go away. */
  42. #define PTRS_PER_PAGE (1UL << (PAGE_SHIFT-3))
  43. #ifdef CONFIG_ALPHA_LARGE_VMALLOC
  44. #define VMALLOC_START 0xfffffe0000000000
  45. #else
  46. #define VMALLOC_START (-2*PGDIR_SIZE)
  47. #endif
  48. #define VMALLOC_END (-PGDIR_SIZE)
  49. /*
  50. * OSF/1 PAL-code-imposed page table bits
  51. */
  52. #define _PAGE_VALID 0x0001
  53. #define _PAGE_FOR 0x0002 /* used for page protection (fault on read) */
  54. #define _PAGE_FOW 0x0004 /* used for page protection (fault on write) */
  55. #define _PAGE_FOE 0x0008 /* used for page protection (fault on exec) */
  56. #define _PAGE_ASM 0x0010
  57. #define _PAGE_KRE 0x0100 /* xxx - see below on the "accessed" bit */
  58. #define _PAGE_URE 0x0200 /* xxx */
  59. #define _PAGE_KWE 0x1000 /* used to do the dirty bit in software */
  60. #define _PAGE_UWE 0x2000 /* used to do the dirty bit in software */
  61. /* .. and these are ours ... */
  62. #define _PAGE_DIRTY 0x20000
  63. #define _PAGE_ACCESSED 0x40000
  64. /*
  65. * NOTE! The "accessed" bit isn't necessarily exact: it can be kept exactly
  66. * by software (use the KRE/URE/KWE/UWE bits appropriately), but I'll fake it.
  67. * Under Linux/AXP, the "accessed" bit just means "read", and I'll just use
  68. * the KRE/URE bits to watch for it. That way we don't need to overload the
  69. * KWE/UWE bits with both handling dirty and accessed.
  70. *
  71. * Note that the kernel uses the accessed bit just to check whether to page
  72. * out a page or not, so it doesn't have to be exact anyway.
  73. */
  74. #define __DIRTY_BITS (_PAGE_DIRTY | _PAGE_KWE | _PAGE_UWE)
  75. #define __ACCESS_BITS (_PAGE_ACCESSED | _PAGE_KRE | _PAGE_URE)
  76. #define _PFN_MASK 0xFFFFFFFF00000000UL
  77. #define _PAGE_TABLE (_PAGE_VALID | __DIRTY_BITS | __ACCESS_BITS)
  78. #define _PAGE_CHG_MASK (_PFN_MASK | __DIRTY_BITS | __ACCESS_BITS)
  79. /*
  80. * All the normal masks have the "page accessed" bits on, as any time they are used,
  81. * the page is accessed. They are cleared only by the page-out routines
  82. */
  83. #define PAGE_NONE __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOR | _PAGE_FOW | _PAGE_FOE)
  84. #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
  85. #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
  86. #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
  87. #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
  88. #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
  89. #define _PAGE_P(x) _PAGE_NORMAL((x) | (((x) & _PAGE_FOW)?0:_PAGE_FOW))
  90. #define _PAGE_S(x) _PAGE_NORMAL(x)
  91. /*
  92. * The hardware can handle write-only mappings, but as the Alpha
  93. * architecture does byte-wide writes with a read-modify-write
  94. * sequence, it's not practical to have write-without-read privs.
  95. * Thus the "-w- -> rw-" and "-wx -> rwx" mapping here (and in
  96. * arch/alpha/mm/fault.c)
  97. */
  98. /* xwr */
  99. #define __P000 _PAGE_P(_PAGE_FOE | _PAGE_FOW | _PAGE_FOR)
  100. #define __P001 _PAGE_P(_PAGE_FOE | _PAGE_FOW)
  101. #define __P010 _PAGE_P(_PAGE_FOE)
  102. #define __P011 _PAGE_P(_PAGE_FOE)
  103. #define __P100 _PAGE_P(_PAGE_FOW | _PAGE_FOR)
  104. #define __P101 _PAGE_P(_PAGE_FOW)
  105. #define __P110 _PAGE_P(0)
  106. #define __P111 _PAGE_P(0)
  107. #define __S000 _PAGE_S(_PAGE_FOE | _PAGE_FOW | _PAGE_FOR)
  108. #define __S001 _PAGE_S(_PAGE_FOE | _PAGE_FOW)
  109. #define __S010 _PAGE_S(_PAGE_FOE)
  110. #define __S011 _PAGE_S(_PAGE_FOE)
  111. #define __S100 _PAGE_S(_PAGE_FOW | _PAGE_FOR)
  112. #define __S101 _PAGE_S(_PAGE_FOW)
  113. #define __S110 _PAGE_S(0)
  114. #define __S111 _PAGE_S(0)
  115. /*
  116. * pgprot_noncached() is only for infiniband pci support, and a real
  117. * implementation for RAM would be more complicated.
  118. */
  119. #define pgprot_noncached(prot) (prot)
  120. /*
  121. * BAD_PAGETABLE is used when we need a bogus page-table, while
  122. * BAD_PAGE is used for a bogus page.
  123. *
  124. * ZERO_PAGE is a global shared page that is always zero: used
  125. * for zero-mapped memory areas etc..
  126. */
  127. extern pte_t __bad_page(void);
  128. extern pmd_t * __bad_pagetable(void);
  129. extern unsigned long __zero_page(void);
  130. #define BAD_PAGETABLE __bad_pagetable()
  131. #define BAD_PAGE __bad_page()
  132. #define ZERO_PAGE(vaddr) (virt_to_page(ZERO_PGE))
  133. /* number of bits that fit into a memory pointer */
  134. #define BITS_PER_PTR (8*sizeof(unsigned long))
  135. /* to align the pointer to a pointer address */
  136. #define PTR_MASK (~(sizeof(void*)-1))
  137. /* sizeof(void*)==1<<SIZEOF_PTR_LOG2 */
  138. #define SIZEOF_PTR_LOG2 3
  139. /* to find an entry in a page-table */
  140. #define PAGE_PTR(address) \
  141. ((unsigned long)(address)>>(PAGE_SHIFT-SIZEOF_PTR_LOG2)&PTR_MASK&~PAGE_MASK)
  142. /*
  143. * On certain platforms whose physical address space can overlap KSEG,
  144. * namely EV6 and above, we must re-twiddle the physaddr to restore the
  145. * correct high-order bits.
  146. *
  147. * This is extremely confusing until you realize that this is actually
  148. * just working around a userspace bug. The X server was intending to
  149. * provide the physical address but instead provided the KSEG address.
  150. * Or tried to, except it's not representable.
  151. *
  152. * On Tsunami there's nothing meaningful at 0x40000000000, so this is
  153. * a safe thing to do. Come the first core logic that does put something
  154. * in this area -- memory or whathaveyou -- then this hack will have
  155. * to go away. So be prepared!
  156. */
  157. #if defined(CONFIG_ALPHA_GENERIC) && defined(USE_48_BIT_KSEG)
  158. #error "EV6-only feature in a generic kernel"
  159. #endif
  160. #if defined(CONFIG_ALPHA_GENERIC) || \
  161. (defined(CONFIG_ALPHA_EV6) && !defined(USE_48_BIT_KSEG))
  162. #define KSEG_PFN (0xc0000000000UL >> PAGE_SHIFT)
  163. #define PHYS_TWIDDLE(pfn) \
  164. ((((pfn) & KSEG_PFN) == (0x40000000000UL >> PAGE_SHIFT)) \
  165. ? ((pfn) ^= KSEG_PFN) : (pfn))
  166. #else
  167. #define PHYS_TWIDDLE(pfn) (pfn)
  168. #endif
  169. /*
  170. * Conversion functions: convert a page and protection to a page entry,
  171. * and a page entry and page directory to the page they refer to.
  172. */
  173. #ifndef CONFIG_DISCONTIGMEM
  174. #define page_to_pa(page) (((page) - mem_map) << PAGE_SHIFT)
  175. #define pte_pfn(pte) (pte_val(pte) >> 32)
  176. #define pte_page(pte) pfn_to_page(pte_pfn(pte))
  177. #define mk_pte(page, pgprot) \
  178. ({ \
  179. pte_t pte; \
  180. \
  181. pte_val(pte) = (page_to_pfn(page) << 32) | pgprot_val(pgprot); \
  182. pte; \
  183. })
  184. #endif
  185. extern inline pte_t pfn_pte(unsigned long physpfn, pgprot_t pgprot)
  186. { pte_t pte; pte_val(pte) = (PHYS_TWIDDLE(physpfn) << 32) | pgprot_val(pgprot); return pte; }
  187. extern inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
  188. { pte_val(pte) = (pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot); return pte; }
  189. extern inline void pmd_set(pmd_t * pmdp, pte_t * ptep)
  190. { pmd_val(*pmdp) = _PAGE_TABLE | ((((unsigned long) ptep) - PAGE_OFFSET) << (32-PAGE_SHIFT)); }
  191. extern inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
  192. { pgd_val(*pgdp) = _PAGE_TABLE | ((((unsigned long) pmdp) - PAGE_OFFSET) << (32-PAGE_SHIFT)); }
  193. extern inline unsigned long
  194. pmd_page_vaddr(pmd_t pmd)
  195. {
  196. return ((pmd_val(pmd) & _PFN_MASK) >> (32-PAGE_SHIFT)) + PAGE_OFFSET;
  197. }
  198. #ifndef CONFIG_DISCONTIGMEM
  199. #define pmd_page(pmd) (mem_map + ((pmd_val(pmd) & _PFN_MASK) >> 32))
  200. #define pgd_page(pgd) (mem_map + ((pgd_val(pgd) & _PFN_MASK) >> 32))
  201. #endif
  202. extern inline unsigned long pgd_page_vaddr(pgd_t pgd)
  203. { return PAGE_OFFSET + ((pgd_val(pgd) & _PFN_MASK) >> (32-PAGE_SHIFT)); }
  204. extern inline int pte_none(pte_t pte) { return !pte_val(pte); }
  205. extern inline int pte_present(pte_t pte) { return pte_val(pte) & _PAGE_VALID; }
  206. extern inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
  207. {
  208. pte_val(*ptep) = 0;
  209. }
  210. extern inline int pmd_none(pmd_t pmd) { return !pmd_val(pmd); }
  211. extern inline int pmd_bad(pmd_t pmd) { return (pmd_val(pmd) & ~_PFN_MASK) != _PAGE_TABLE; }
  212. extern inline int pmd_present(pmd_t pmd) { return pmd_val(pmd) & _PAGE_VALID; }
  213. extern inline void pmd_clear(pmd_t * pmdp) { pmd_val(*pmdp) = 0; }
  214. extern inline int pgd_none(pgd_t pgd) { return !pgd_val(pgd); }
  215. extern inline int pgd_bad(pgd_t pgd) { return (pgd_val(pgd) & ~_PFN_MASK) != _PAGE_TABLE; }
  216. extern inline int pgd_present(pgd_t pgd) { return pgd_val(pgd) & _PAGE_VALID; }
  217. extern inline void pgd_clear(pgd_t * pgdp) { pgd_val(*pgdp) = 0; }
  218. /*
  219. * The following only work if pte_present() is true.
  220. * Undefined behaviour if not..
  221. */
  222. extern inline int pte_write(pte_t pte) { return !(pte_val(pte) & _PAGE_FOW); }
  223. extern inline int pte_dirty(pte_t pte) { return pte_val(pte) & _PAGE_DIRTY; }
  224. extern inline int pte_young(pte_t pte) { return pte_val(pte) & _PAGE_ACCESSED; }
  225. extern inline int pte_special(pte_t pte) { return 0; }
  226. extern inline pte_t pte_wrprotect(pte_t pte) { pte_val(pte) |= _PAGE_FOW; return pte; }
  227. extern inline pte_t pte_mkclean(pte_t pte) { pte_val(pte) &= ~(__DIRTY_BITS); return pte; }
  228. extern inline pte_t pte_mkold(pte_t pte) { pte_val(pte) &= ~(__ACCESS_BITS); return pte; }
  229. extern inline pte_t pte_mkwrite(pte_t pte) { pte_val(pte) &= ~_PAGE_FOW; return pte; }
  230. extern inline pte_t pte_mkdirty(pte_t pte) { pte_val(pte) |= __DIRTY_BITS; return pte; }
  231. extern inline pte_t pte_mkyoung(pte_t pte) { pte_val(pte) |= __ACCESS_BITS; return pte; }
  232. extern inline pte_t pte_mkspecial(pte_t pte) { return pte; }
  233. #define PAGE_DIR_OFFSET(tsk,address) pgd_offset((tsk),(address))
  234. /* to find an entry in a kernel page-table-directory */
  235. #define pgd_offset_k(address) pgd_offset(&init_mm, (address))
  236. /* to find an entry in a page-table-directory. */
  237. #define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD-1))
  238. #define pgd_offset(mm, address) ((mm)->pgd+pgd_index(address))
  239. /*
  240. * The smp_read_barrier_depends() in the following functions are required to
  241. * order the load of *dir (the pointer in the top level page table) with any
  242. * subsequent load of the returned pmd_t *ret (ret is data dependent on *dir).
  243. *
  244. * If this ordering is not enforced, the CPU might load an older value of
  245. * *ret, which may be uninitialized data. See mm/memory.c:__pte_alloc for
  246. * more details.
  247. *
  248. * Note that we never change the mm->pgd pointer after the task is running, so
  249. * pgd_offset does not require such a barrier.
  250. */
  251. /* Find an entry in the second-level page table.. */
  252. extern inline pmd_t * pmd_offset(pgd_t * dir, unsigned long address)
  253. {
  254. pmd_t *ret = (pmd_t *) pgd_page_vaddr(*dir) + ((address >> PMD_SHIFT) & (PTRS_PER_PAGE - 1));
  255. smp_read_barrier_depends(); /* see above */
  256. return ret;
  257. }
  258. /* Find an entry in the third-level page table.. */
  259. extern inline pte_t * pte_offset_kernel(pmd_t * dir, unsigned long address)
  260. {
  261. pte_t *ret = (pte_t *) pmd_page_vaddr(*dir)
  262. + ((address >> PAGE_SHIFT) & (PTRS_PER_PAGE - 1));
  263. smp_read_barrier_depends(); /* see above */
  264. return ret;
  265. }
  266. #define pte_offset_map(dir,addr) pte_offset_kernel((dir),(addr))
  267. #define pte_unmap(pte) do { } while (0)
  268. extern pgd_t swapper_pg_dir[1024];
  269. /*
  270. * The Alpha doesn't have any external MMU info: the kernel page
  271. * tables contain all the necessary information.
  272. */
  273. extern inline void update_mmu_cache(struct vm_area_struct * vma,
  274. unsigned long address, pte_t *ptep)
  275. {
  276. }
  277. /*
  278. * Non-present pages: high 24 bits are offset, next 8 bits type,
  279. * low 32 bits zero.
  280. */
  281. extern inline pte_t mk_swap_pte(unsigned long type, unsigned long offset)
  282. { pte_t pte; pte_val(pte) = (type << 32) | (offset << 40); return pte; }
  283. #define __swp_type(x) (((x).val >> 32) & 0xff)
  284. #define __swp_offset(x) ((x).val >> 40)
  285. #define __swp_entry(type, off) ((swp_entry_t) { pte_val(mk_swap_pte((type), (off))) })
  286. #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
  287. #define __swp_entry_to_pte(x) ((pte_t) { (x).val })
  288. #ifndef CONFIG_DISCONTIGMEM
  289. #define kern_addr_valid(addr) (1)
  290. #endif
  291. #define pte_ERROR(e) \
  292. printk("%s:%d: bad pte %016lx.\n", __FILE__, __LINE__, pte_val(e))
  293. #define pmd_ERROR(e) \
  294. printk("%s:%d: bad pmd %016lx.\n", __FILE__, __LINE__, pmd_val(e))
  295. #define pgd_ERROR(e) \
  296. printk("%s:%d: bad pgd %016lx.\n", __FILE__, __LINE__, pgd_val(e))
  297. extern void paging_init(void);
  298. #include <asm-generic/pgtable.h>
  299. /*
  300. * No page table caches to initialise
  301. */
  302. #define pgtable_cache_init() do { } while (0)
  303. /* We have our own get_unmapped_area to cope with ADDR_LIMIT_32BIT. */
  304. #define HAVE_ARCH_UNMAPPED_AREA
  305. #endif /* _ALPHA_PGTABLE_H */