pgtable.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. /*
  2. * This file contains the functions and defines necessary to modify and
  3. * use the SuperH page table tree.
  4. *
  5. * Copyright (C) 1999 Niibe Yutaka
  6. * Copyright (C) 2002 - 2005 Paul Mundt
  7. *
  8. * This file is subject to the terms and conditions of the GNU General
  9. * Public License. See the file "COPYING" in the main directory of this
  10. * archive for more details.
  11. */
  12. #ifndef __ASM_SH_PGTABLE_H
  13. #define __ASM_SH_PGTABLE_H
  14. #include <asm-generic/pgtable-nopmd.h>
  15. #include <asm/page.h>
  16. #define PTRS_PER_PGD 1024
  17. #ifndef __ASSEMBLY__
  18. #include <asm/addrspace.h>
  19. #include <asm/fixmap.h>
  20. extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
  21. extern void paging_init(void);
  22. /*
  23. * ZERO_PAGE is a global shared page that is always zero: used
  24. * for zero-mapped memory areas etc..
  25. */
  26. extern unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)];
  27. #define ZERO_PAGE(vaddr) (virt_to_page(empty_zero_page))
  28. #endif /* !__ASSEMBLY__ */
  29. /* traditional two-level paging structure */
  30. #define PGDIR_SHIFT 22
  31. #define PTRS_PER_PMD 1
  32. #define PTRS_PER_PTE 1024
  33. #define PMD_SIZE (1UL << PMD_SHIFT)
  34. #define PMD_MASK (~(PMD_SIZE-1))
  35. #define PGDIR_SIZE (1UL << PGDIR_SHIFT)
  36. #define PGDIR_MASK (~(PGDIR_SIZE-1))
  37. #define USER_PTRS_PER_PGD (TASK_SIZE/PGDIR_SIZE)
  38. #define FIRST_USER_ADDRESS 0
  39. #define PTE_PHYS_MASK 0x1ffff000
  40. /*
  41. * First 1MB map is used by fixed purpose.
  42. * Currently only 4-enty (16kB) is used (see arch/sh/mm/cache.c)
  43. */
  44. #define VMALLOC_START (P3SEG+0x00100000)
  45. #define VMALLOC_END (FIXADDR_START-2*PAGE_SIZE)
  46. /*
  47. * Linux PTEL encoding.
  48. *
  49. * Hardware and software bit definitions for the PTEL value:
  50. *
  51. * - Bits 0 and 7 are reserved on SH-3 (_PAGE_WT and _PAGE_SZ1 on SH-4).
  52. *
  53. * - Bit 1 is the SH-bit, but is unused on SH-3 due to an MMU bug (the
  54. * hardware PTEL value can't have the SH-bit set when MMUCR.IX is set,
  55. * which is the default in cpu-sh3/mmu_context.h:MMU_CONTROL_INIT).
  56. *
  57. * In order to keep this relatively clean, do not use these for defining
  58. * SH-3 specific flags until all of the other unused bits have been
  59. * exhausted.
  60. *
  61. * - Bit 9 is reserved by everyone and used by _PAGE_PROTNONE.
  62. *
  63. * - Bits 10 and 11 are low bits of the PPN that are reserved on >= 4K pages.
  64. * Bit 10 is used for _PAGE_ACCESSED, bit 11 remains unused.
  65. *
  66. * - Bits 31, 30, and 29 remain unused by everyone and can be used for future
  67. * software flags, although care must be taken to update _PAGE_CLEAR_FLAGS.
  68. */
  69. #define _PAGE_WT 0x001 /* WT-bit on SH-4, 0 on SH-3 */
  70. #define _PAGE_HW_SHARED 0x002 /* SH-bit : shared among processes */
  71. #define _PAGE_DIRTY 0x004 /* D-bit : page changed */
  72. #define _PAGE_CACHABLE 0x008 /* C-bit : cachable */
  73. #define _PAGE_SZ0 0x010 /* SZ0-bit : Size of page */
  74. #define _PAGE_RW 0x020 /* PR0-bit : write access allowed */
  75. #define _PAGE_USER 0x040 /* PR1-bit : user space access allowed */
  76. #define _PAGE_SZ1 0x080 /* SZ1-bit : Size of page (on SH-4) */
  77. #define _PAGE_PRESENT 0x100 /* V-bit : page is valid */
  78. #define _PAGE_PROTNONE 0x200 /* software: if not present */
  79. #define _PAGE_ACCESSED 0x400 /* software: page referenced */
  80. #define _PAGE_FILE _PAGE_WT /* software: pagecache or swap? */
  81. /* software: moves to PTEA.TC (Timing Control) */
  82. #define _PAGE_PCC_AREA5 0x00000000 /* use BSC registers for area5 */
  83. #define _PAGE_PCC_AREA6 0x80000000 /* use BSC registers for area6 */
  84. /* software: moves to PTEA.SA[2:0] (Space Attributes) */
  85. #define _PAGE_PCC_IODYN 0x00000001 /* IO space, dynamically sized bus */
  86. #define _PAGE_PCC_IO8 0x20000000 /* IO space, 8 bit bus */
  87. #define _PAGE_PCC_IO16 0x20000001 /* IO space, 16 bit bus */
  88. #define _PAGE_PCC_COM8 0x40000000 /* Common Memory space, 8 bit bus */
  89. #define _PAGE_PCC_COM16 0x40000001 /* Common Memory space, 16 bit bus */
  90. #define _PAGE_PCC_ATR8 0x60000000 /* Attribute Memory space, 8 bit bus */
  91. #define _PAGE_PCC_ATR16 0x60000001 /* Attribute Memory space, 6 bit bus */
  92. /* Mask which drops unused bits from the PTEL value */
  93. #ifdef CONFIG_CPU_SH3
  94. #define _PAGE_CLEAR_FLAGS (_PAGE_PROTNONE | _PAGE_ACCESSED| \
  95. _PAGE_FILE | _PAGE_SZ1 | \
  96. _PAGE_HW_SHARED)
  97. #else
  98. #define _PAGE_CLEAR_FLAGS (_PAGE_PROTNONE | _PAGE_ACCESSED | _PAGE_FILE)
  99. #endif
  100. #define _PAGE_FLAGS_HARDWARE_MASK (0x1fffffff & ~(_PAGE_CLEAR_FLAGS))
  101. /* Hardware flags: SZ0=1 (4k-byte) */
  102. #define _PAGE_FLAGS_HARD _PAGE_SZ0
  103. #if defined(CONFIG_HUGETLB_PAGE_SIZE_64K)
  104. #define _PAGE_SZHUGE (_PAGE_SZ1)
  105. #elif defined(CONFIG_HUGETLB_PAGE_SIZE_1MB)
  106. #define _PAGE_SZHUGE (_PAGE_SZ0 | _PAGE_SZ1)
  107. #endif
  108. #define _PAGE_TABLE (_PAGE_PRESENT | _PAGE_RW | _PAGE_USER | _PAGE_ACCESSED | _PAGE_DIRTY)
  109. #define _KERNPG_TABLE (_PAGE_PRESENT | _PAGE_RW | _PAGE_ACCESSED | _PAGE_DIRTY)
  110. #define _PAGE_CHG_MASK (PTE_MASK | _PAGE_ACCESSED | _PAGE_CACHABLE | _PAGE_DIRTY)
  111. #ifndef __ASSEMBLY__
  112. #ifdef CONFIG_MMU
  113. #define PAGE_NONE __pgprot(_PAGE_PROTNONE | _PAGE_CACHABLE |_PAGE_ACCESSED | _PAGE_FLAGS_HARD)
  114. #define PAGE_SHARED __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_USER | _PAGE_CACHABLE |_PAGE_ACCESSED | _PAGE_FLAGS_HARD)
  115. #define PAGE_COPY __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_CACHABLE | _PAGE_ACCESSED | _PAGE_FLAGS_HARD)
  116. #define PAGE_READONLY __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_CACHABLE | _PAGE_ACCESSED | _PAGE_FLAGS_HARD)
  117. #define PAGE_KERNEL __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_CACHABLE | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_HW_SHARED | _PAGE_FLAGS_HARD)
  118. #define PAGE_KERNEL_NOCACHE \
  119. __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_HW_SHARED | _PAGE_FLAGS_HARD)
  120. #define PAGE_KERNEL_RO __pgprot(_PAGE_PRESENT | _PAGE_CACHABLE | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_HW_SHARED | _PAGE_FLAGS_HARD)
  121. #define PAGE_KERNEL_PCC(slot, type) \
  122. __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_FLAGS_HARD | (slot ? _PAGE_PCC_AREA5 : _PAGE_PCC_AREA6) | (type))
  123. #else /* no mmu */
  124. #define PAGE_NONE __pgprot(0)
  125. #define PAGE_SHARED __pgprot(0)
  126. #define PAGE_COPY __pgprot(0)
  127. #define PAGE_READONLY __pgprot(0)
  128. #define PAGE_KERNEL __pgprot(0)
  129. #define PAGE_KERNEL_NOCACHE __pgprot(0)
  130. #define PAGE_KERNEL_RO __pgprot(0)
  131. #define PAGE_KERNEL_PCC __pgprot(0)
  132. #endif
  133. #endif /* __ASSEMBLY__ */
  134. /*
  135. * As i386 and MIPS, SuperH can't do page protection for execute, and
  136. * considers that the same as a read. Also, write permissions imply
  137. * read permissions. This is the closest we can get..
  138. */
  139. #define __P000 PAGE_NONE
  140. #define __P001 PAGE_READONLY
  141. #define __P010 PAGE_COPY
  142. #define __P011 PAGE_COPY
  143. #define __P100 PAGE_READONLY
  144. #define __P101 PAGE_READONLY
  145. #define __P110 PAGE_COPY
  146. #define __P111 PAGE_COPY
  147. #define __S000 PAGE_NONE
  148. #define __S001 PAGE_READONLY
  149. #define __S010 PAGE_SHARED
  150. #define __S011 PAGE_SHARED
  151. #define __S100 PAGE_READONLY
  152. #define __S101 PAGE_READONLY
  153. #define __S110 PAGE_SHARED
  154. #define __S111 PAGE_SHARED
  155. #ifndef __ASSEMBLY__
  156. /*
  157. * Certain architectures need to do special things when PTEs
  158. * within a page table are directly modified. Thus, the following
  159. * hook is made available.
  160. */
  161. #define set_pte(pteptr, pteval) (*(pteptr) = pteval)
  162. #define set_pte_at(mm,addr,ptep,pteval) set_pte(ptep,pteval)
  163. /*
  164. * (pmds are folded into pgds so this doesn't get actually called,
  165. * but the define is needed for a generic inline function.)
  166. */
  167. #define set_pmd(pmdptr, pmdval) (*(pmdptr) = pmdval)
  168. #define pte_pfn(x) ((unsigned long)(((x).pte >> PAGE_SHIFT)))
  169. #define pfn_pte(pfn, prot) __pte(((pfn) << PAGE_SHIFT) | pgprot_val(prot))
  170. #define pfn_pmd(pfn, prot) __pmd(((pfn) << PAGE_SHIFT) | pgprot_val(prot))
  171. #define pte_none(x) (!pte_val(x))
  172. #define pte_present(x) (pte_val(x) & (_PAGE_PRESENT | _PAGE_PROTNONE))
  173. #define pte_clear(mm,addr,xp) do { set_pte_at(mm, addr, xp, __pte(0)); } while (0)
  174. #define pmd_none(x) (!pmd_val(x))
  175. #define pmd_present(x) (pmd_val(x) & _PAGE_PRESENT)
  176. #define pmd_clear(xp) do { set_pmd(xp, __pmd(0)); } while (0)
  177. #define pmd_bad(x) ((pmd_val(x) & (~PAGE_MASK & ~_PAGE_USER)) != _KERNPG_TABLE)
  178. #define pages_to_mb(x) ((x) >> (20-PAGE_SHIFT))
  179. #define pte_page(x) phys_to_page(pte_val(x)&PTE_PHYS_MASK)
  180. /*
  181. * The following only work if pte_present() is true.
  182. * Undefined behaviour if not..
  183. */
  184. static inline int pte_read(pte_t pte) { return pte_val(pte) & _PAGE_USER; }
  185. static inline int pte_exec(pte_t pte) { return pte_val(pte) & _PAGE_USER; }
  186. static inline int pte_dirty(pte_t pte){ return pte_val(pte) & _PAGE_DIRTY; }
  187. static inline int pte_young(pte_t pte){ return pte_val(pte) & _PAGE_ACCESSED; }
  188. static inline int pte_file(pte_t pte) { return pte_val(pte) & _PAGE_FILE; }
  189. static inline int pte_write(pte_t pte){ return pte_val(pte) & _PAGE_RW; }
  190. static inline int pte_not_present(pte_t pte){ return !(pte_val(pte) & _PAGE_PRESENT); }
  191. static inline pte_t pte_rdprotect(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_USER)); return pte; }
  192. static inline pte_t pte_exprotect(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_USER)); return pte; }
  193. static inline pte_t pte_mkclean(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_DIRTY)); return pte; }
  194. static inline pte_t pte_mkold(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_ACCESSED)); return pte; }
  195. static inline pte_t pte_wrprotect(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_RW)); return pte; }
  196. static inline pte_t pte_mkread(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) | _PAGE_USER)); return pte; }
  197. static inline pte_t pte_mkexec(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) | _PAGE_USER)); return pte; }
  198. static inline pte_t pte_mkdirty(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) | _PAGE_DIRTY)); return pte; }
  199. static inline pte_t pte_mkyoung(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) | _PAGE_ACCESSED)); return pte; }
  200. static inline pte_t pte_mkwrite(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) | _PAGE_RW)); return pte; }
  201. #ifdef CONFIG_HUGETLB_PAGE
  202. static inline pte_t pte_mkhuge(pte_t pte) { set_pte(&pte, __pte(pte_val(pte) | _PAGE_SZHUGE)); return pte; }
  203. #endif
  204. /*
  205. * Macro and implementation to make a page protection as uncachable.
  206. */
  207. #define pgprot_noncached pgprot_noncached
  208. static inline pgprot_t pgprot_noncached(pgprot_t _prot)
  209. {
  210. unsigned long prot = pgprot_val(_prot);
  211. prot &= ~_PAGE_CACHABLE;
  212. return __pgprot(prot);
  213. }
  214. #define pgprot_writecombine(prot) __pgprot(pgprot_val(prot) & ~_PAGE_CACHABLE)
  215. /*
  216. * Conversion functions: convert a page and protection to a page entry,
  217. * and a page entry and page directory to the page they refer to.
  218. *
  219. * extern pte_t mk_pte(struct page *page, pgprot_t pgprot)
  220. */
  221. #define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot))
  222. static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
  223. { set_pte(&pte, __pte((pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot))); return pte; }
  224. #define pmd_page_vaddr(pmd) \
  225. ((unsigned long) __va(pmd_val(pmd) & PAGE_MASK))
  226. #define pmd_page(pmd) \
  227. (phys_to_page(pmd_val(pmd)))
  228. /* to find an entry in a page-table-directory. */
  229. #define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD-1))
  230. #define pgd_offset(mm, address) ((mm)->pgd+pgd_index(address))
  231. /* to find an entry in a kernel page-table-directory */
  232. #define pgd_offset_k(address) pgd_offset(&init_mm, address)
  233. /* Find an entry in the third-level page table.. */
  234. #define pte_index(address) \
  235. ((address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1))
  236. #define pte_offset_kernel(dir, address) \
  237. ((pte_t *) pmd_page_vaddr(*(dir)) + pte_index(address))
  238. #define pte_offset_map(dir, address) pte_offset_kernel(dir, address)
  239. #define pte_offset_map_nested(dir, address) pte_offset_kernel(dir, address)
  240. #define pte_unmap(pte) do { } while (0)
  241. #define pte_unmap_nested(pte) do { } while (0)
  242. #define pte_ERROR(e) \
  243. printk("%s:%d: bad pte %08lx.\n", __FILE__, __LINE__, pte_val(e))
  244. #define pgd_ERROR(e) \
  245. printk("%s:%d: bad pgd %08lx.\n", __FILE__, __LINE__, pgd_val(e))
  246. struct vm_area_struct;
  247. extern void update_mmu_cache(struct vm_area_struct * vma,
  248. unsigned long address, pte_t pte);
  249. /* Encode and de-code a swap entry */
  250. /*
  251. * NOTE: We should set ZEROs at the position of _PAGE_PRESENT
  252. * and _PAGE_PROTNONE bits
  253. */
  254. #define __swp_type(x) ((x).val & 0xff)
  255. #define __swp_offset(x) ((x).val >> 10)
  256. #define __swp_entry(type, offset) ((swp_entry_t) { (type) | ((offset) << 10) })
  257. #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) >> 1 })
  258. #define __swp_entry_to_pte(x) ((pte_t) { (x).val << 1 })
  259. /*
  260. * Encode and decode a nonlinear file mapping entry
  261. */
  262. #define PTE_FILE_MAX_BITS 29
  263. #define pte_to_pgoff(pte) (pte_val(pte) >> 1)
  264. #define pgoff_to_pte(off) ((pte_t) { ((off) << 1) | _PAGE_FILE })
  265. typedef pte_t *pte_addr_t;
  266. #define kern_addr_valid(addr) (1)
  267. #define io_remap_pfn_range(vma, vaddr, pfn, size, prot) \
  268. remap_pfn_range(vma, vaddr, pfn, size, prot)
  269. #define MK_IOSPACE_PFN(space, pfn) (pfn)
  270. #define GET_IOSPACE(pfn) 0
  271. #define GET_PFN(pfn) (pfn)
  272. struct mm_struct;
  273. /*
  274. * No page table caches to initialise
  275. */
  276. #define pgtable_cache_init() do { } while (0)
  277. #ifndef CONFIG_MMU
  278. extern unsigned int kobjsize(const void *objp);
  279. #endif /* !CONFIG_MMU */
  280. #if defined(CONFIG_CPU_SH4) || defined(CONFIG_SH7705_CACHE_32KB)
  281. #define __HAVE_ARCH_PTEP_GET_AND_CLEAR
  282. extern pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep);
  283. #endif
  284. #include <asm-generic/pgtable.h>
  285. #endif /* !__ASSEMBLY__ */
  286. #endif /* __ASM_SH_PAGE_H */