PageRenderTime 65ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/release/src-rt/linux/linux-2.6/include/asm-avr32/pgtable.h

https://gitlab.com/envieidoc/advancedtomato2
C Header | 404 lines | 231 code | 55 blank | 118 comment | 5 complexity | 1583d4747c37fbbabda679c089281269 MD5 | raw file
  1. /*
  2. * Copyright (C) 2004-2006 Atmel Corporation
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. #ifndef __ASM_AVR32_PGTABLE_H
  9. #define __ASM_AVR32_PGTABLE_H
  10. #include <asm/addrspace.h>
  11. #ifndef __ASSEMBLY__
  12. #include <linux/sched.h>
  13. #endif /* !__ASSEMBLY__ */
  14. /*
  15. * Use two-level page tables just as the i386 (without PAE)
  16. */
  17. #include <asm/pgtable-2level.h>
  18. /*
  19. * The following code might need some cleanup when the values are
  20. * final...
  21. */
  22. #define PMD_SIZE (1UL << PMD_SHIFT)
  23. #define PMD_MASK (~(PMD_SIZE-1))
  24. #define PGDIR_SIZE (1UL << PGDIR_SHIFT)
  25. #define PGDIR_MASK (~(PGDIR_SIZE-1))
  26. #define USER_PTRS_PER_PGD (TASK_SIZE / PGDIR_SIZE)
  27. #define FIRST_USER_ADDRESS 0
  28. #define PTE_PHYS_MASK 0x1ffff000
  29. #ifndef __ASSEMBLY__
  30. extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
  31. extern void paging_init(void);
  32. /*
  33. * ZERO_PAGE is a global shared page that is always zero: used for
  34. * zero-mapped memory areas etc.
  35. */
  36. extern struct page *empty_zero_page;
  37. #define ZERO_PAGE(vaddr) (empty_zero_page)
  38. /*
  39. * Just any arbitrary offset to the start of the vmalloc VM area: the
  40. * current 8 MiB value just means that there will be a 8 MiB "hole"
  41. * after the uncached physical memory (P2 segment) until the vmalloc
  42. * area starts. That means that any out-of-bounds memory accesses will
  43. * hopefully be caught; we don't know if the end of the P1/P2 segments
  44. * are actually used for anything, but it is anyway safer to let the
  45. * MMU catch these kinds of errors than to rely on the memory bus.
  46. *
  47. * A "hole" of the same size is added to the end of the P3 segment as
  48. * well. It might seem wasteful to use 16 MiB of virtual address space
  49. * on this, but we do have 512 MiB of it...
  50. *
  51. * The vmalloc() routines leave a hole of 4 KiB between each vmalloced
  52. * area for the same reason.
  53. */
  54. #define VMALLOC_OFFSET (8 * 1024 * 1024)
  55. #define VMALLOC_START (P3SEG + VMALLOC_OFFSET)
  56. #define VMALLOC_END (P4SEG - VMALLOC_OFFSET)
  57. #endif /* !__ASSEMBLY__ */
  58. /*
  59. * Page flags. Some of these flags are not directly supported by
  60. * hardware, so we have to emulate them.
  61. */
  62. #define _TLBEHI_BIT_VALID 9
  63. #define _TLBEHI_VALID (1 << _TLBEHI_BIT_VALID)
  64. #define _PAGE_BIT_WT 0 /* W-bit : write-through */
  65. #define _PAGE_BIT_DIRTY 1 /* D-bit : page changed */
  66. #define _PAGE_BIT_SZ0 2 /* SZ0-bit : Size of page */
  67. #define _PAGE_BIT_SZ1 3 /* SZ1-bit : Size of page */
  68. #define _PAGE_BIT_EXECUTE 4 /* X-bit : execute access allowed */
  69. #define _PAGE_BIT_RW 5 /* AP0-bit : write access allowed */
  70. #define _PAGE_BIT_USER 6 /* AP1-bit : user space access allowed */
  71. #define _PAGE_BIT_BUFFER 7 /* B-bit : bufferable */
  72. #define _PAGE_BIT_GLOBAL 8 /* G-bit : global (ignore ASID) */
  73. #define _PAGE_BIT_CACHABLE 9 /* C-bit : cachable */
  74. /* If we drop support for 1K pages, we get two extra bits */
  75. #define _PAGE_BIT_PRESENT 10
  76. #define _PAGE_BIT_ACCESSED 11 /* software: page was accessed */
  77. /* The following flags are only valid when !PRESENT */
  78. #define _PAGE_BIT_FILE 0 /* software: pagecache or swap? */
  79. #define _PAGE_WT (1 << _PAGE_BIT_WT)
  80. #define _PAGE_DIRTY (1 << _PAGE_BIT_DIRTY)
  81. #define _PAGE_EXECUTE (1 << _PAGE_BIT_EXECUTE)
  82. #define _PAGE_RW (1 << _PAGE_BIT_RW)
  83. #define _PAGE_USER (1 << _PAGE_BIT_USER)
  84. #define _PAGE_BUFFER (1 << _PAGE_BIT_BUFFER)
  85. #define _PAGE_GLOBAL (1 << _PAGE_BIT_GLOBAL)
  86. #define _PAGE_CACHABLE (1 << _PAGE_BIT_CACHABLE)
  87. /* Software flags */
  88. #define _PAGE_ACCESSED (1 << _PAGE_BIT_ACCESSED)
  89. #define _PAGE_PRESENT (1 << _PAGE_BIT_PRESENT)
  90. #define _PAGE_FILE (1 << _PAGE_BIT_FILE)
  91. /*
  92. * Page types, i.e. sizes. _PAGE_TYPE_NONE corresponds to what is
  93. * usually called _PAGE_PROTNONE on other architectures.
  94. *
  95. * XXX: Find out if _PAGE_PROTNONE is equivalent with !_PAGE_USER. If
  96. * so, we can encode all possible page sizes (although we can't really
  97. * support 1K pages anyway due to the _PAGE_PRESENT and _PAGE_ACCESSED
  98. * bits)
  99. *
  100. */
  101. #define _PAGE_TYPE_MASK ((1 << _PAGE_BIT_SZ0) | (1 << _PAGE_BIT_SZ1))
  102. #define _PAGE_TYPE_NONE (0 << _PAGE_BIT_SZ0)
  103. #define _PAGE_TYPE_SMALL (1 << _PAGE_BIT_SZ0)
  104. #define _PAGE_TYPE_MEDIUM (2 << _PAGE_BIT_SZ0)
  105. #define _PAGE_TYPE_LARGE (3 << _PAGE_BIT_SZ0)
  106. /*
  107. * Mask which drop software flags. We currently can't handle more than
  108. * 512 MiB of physical memory, so we can use bits 29-31 for other
  109. * stuff. With a fixed 4K page size, we can use bits 10-11 as well as
  110. * bits 2-3 (SZ)
  111. */
  112. #define _PAGE_FLAGS_HARDWARE_MASK 0xfffff3ff
  113. #define _PAGE_FLAGS_CACHE_MASK (_PAGE_CACHABLE | _PAGE_BUFFER | _PAGE_WT)
  114. /* TODO: Check for saneness */
  115. /* User-mode page table flags (to be set in a pgd or pmd entry) */
  116. #define _PAGE_TABLE (_PAGE_PRESENT | _PAGE_TYPE_SMALL | _PAGE_RW \
  117. | _PAGE_USER | _PAGE_ACCESSED | _PAGE_DIRTY)
  118. /* Kernel-mode page table flags */
  119. #define _KERNPG_TABLE (_PAGE_PRESENT | _PAGE_TYPE_SMALL | _PAGE_RW \
  120. | _PAGE_ACCESSED | _PAGE_DIRTY)
  121. /* Flags that may be modified by software */
  122. #define _PAGE_CHG_MASK (PTE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY \
  123. | _PAGE_FLAGS_CACHE_MASK)
  124. #define _PAGE_FLAGS_READ (_PAGE_CACHABLE | _PAGE_BUFFER)
  125. #define _PAGE_FLAGS_WRITE (_PAGE_FLAGS_READ | _PAGE_RW | _PAGE_DIRTY)
  126. #define _PAGE_NORMAL(x) __pgprot((x) | _PAGE_PRESENT | _PAGE_TYPE_SMALL \
  127. | _PAGE_ACCESSED)
  128. #define PAGE_NONE (_PAGE_ACCESSED | _PAGE_TYPE_NONE)
  129. #define PAGE_READ (_PAGE_FLAGS_READ | _PAGE_USER)
  130. #define PAGE_EXEC (_PAGE_FLAGS_READ | _PAGE_EXECUTE | _PAGE_USER)
  131. #define PAGE_WRITE (_PAGE_FLAGS_WRITE | _PAGE_USER)
  132. #define PAGE_KERNEL _PAGE_NORMAL(_PAGE_FLAGS_WRITE | _PAGE_EXECUTE | _PAGE_GLOBAL)
  133. #define PAGE_KERNEL_RO _PAGE_NORMAL(_PAGE_FLAGS_READ | _PAGE_EXECUTE | _PAGE_GLOBAL)
  134. #define _PAGE_P(x) _PAGE_NORMAL((x) & ~(_PAGE_RW | _PAGE_DIRTY))
  135. #define _PAGE_S(x) _PAGE_NORMAL(x)
  136. #define PAGE_COPY _PAGE_P(PAGE_WRITE | PAGE_READ)
  137. #ifndef __ASSEMBLY__
  138. /*
  139. * The hardware supports flags for write- and execute access. Read is
  140. * always allowed if the page is loaded into the TLB, so the "-w-",
  141. * "--x" and "-wx" mappings are implemented as "rw-", "r-x" and "rwx",
  142. * respectively.
  143. *
  144. * The "---" case is handled by software; the page will simply not be
  145. * loaded into the TLB if the page type is _PAGE_TYPE_NONE.
  146. */
  147. #define __P000 __pgprot(PAGE_NONE)
  148. #define __P001 _PAGE_P(PAGE_READ)
  149. #define __P010 _PAGE_P(PAGE_WRITE)
  150. #define __P011 _PAGE_P(PAGE_WRITE | PAGE_READ)
  151. #define __P100 _PAGE_P(PAGE_EXEC)
  152. #define __P101 _PAGE_P(PAGE_EXEC | PAGE_READ)
  153. #define __P110 _PAGE_P(PAGE_EXEC | PAGE_WRITE)
  154. #define __P111 _PAGE_P(PAGE_EXEC | PAGE_WRITE | PAGE_READ)
  155. #define __S000 __pgprot(PAGE_NONE)
  156. #define __S001 _PAGE_S(PAGE_READ)
  157. #define __S010 _PAGE_S(PAGE_WRITE)
  158. #define __S011 _PAGE_S(PAGE_WRITE | PAGE_READ)
  159. #define __S100 _PAGE_S(PAGE_EXEC)
  160. #define __S101 _PAGE_S(PAGE_EXEC | PAGE_READ)
  161. #define __S110 _PAGE_S(PAGE_EXEC | PAGE_WRITE)
  162. #define __S111 _PAGE_S(PAGE_EXEC | PAGE_WRITE | PAGE_READ)
  163. #define pte_none(x) (!pte_val(x))
  164. #define pte_present(x) (pte_val(x) & _PAGE_PRESENT)
  165. #define pte_clear(mm,addr,xp) \
  166. do { \
  167. set_pte_at(mm, addr, xp, __pte(0)); \
  168. } while (0)
  169. /*
  170. * The following only work if pte_present() is true.
  171. * Undefined behaviour if not..
  172. */
  173. static inline int pte_read(pte_t pte)
  174. {
  175. return pte_val(pte) & _PAGE_USER;
  176. }
  177. static inline int pte_write(pte_t pte)
  178. {
  179. return pte_val(pte) & _PAGE_RW;
  180. }
  181. static inline int pte_exec(pte_t pte)
  182. {
  183. return pte_val(pte) & _PAGE_EXECUTE;
  184. }
  185. static inline int pte_dirty(pte_t pte)
  186. {
  187. return pte_val(pte) & _PAGE_DIRTY;
  188. }
  189. static inline int pte_young(pte_t pte)
  190. {
  191. return pte_val(pte) & _PAGE_ACCESSED;
  192. }
  193. /*
  194. * The following only work if pte_present() is not true.
  195. */
  196. static inline int pte_file(pte_t pte)
  197. {
  198. return pte_val(pte) & _PAGE_FILE;
  199. }
  200. /* Mutator functions for PTE bits */
  201. static inline pte_t pte_rdprotect(pte_t pte)
  202. {
  203. set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_USER));
  204. return pte;
  205. }
  206. static inline pte_t pte_wrprotect(pte_t pte)
  207. {
  208. set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_RW));
  209. return pte;
  210. }
  211. static inline pte_t pte_exprotect(pte_t pte)
  212. {
  213. set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_EXECUTE));
  214. return pte;
  215. }
  216. static inline pte_t pte_mkclean(pte_t pte)
  217. {
  218. set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_DIRTY));
  219. return pte;
  220. }
  221. static inline pte_t pte_mkold(pte_t pte)
  222. {
  223. set_pte(&pte, __pte(pte_val(pte) & ~_PAGE_ACCESSED));
  224. return pte;
  225. }
  226. static inline pte_t pte_mkread(pte_t pte)
  227. {
  228. set_pte(&pte, __pte(pte_val(pte) | _PAGE_USER));
  229. return pte;
  230. }
  231. static inline pte_t pte_mkwrite(pte_t pte)
  232. {
  233. set_pte(&pte, __pte(pte_val(pte) | _PAGE_RW));
  234. return pte;
  235. }
  236. static inline pte_t pte_mkexec(pte_t pte)
  237. {
  238. set_pte(&pte, __pte(pte_val(pte) | _PAGE_EXECUTE));
  239. return pte;
  240. }
  241. static inline pte_t pte_mkdirty(pte_t pte)
  242. {
  243. set_pte(&pte, __pte(pte_val(pte) | _PAGE_DIRTY));
  244. return pte;
  245. }
  246. static inline pte_t pte_mkyoung(pte_t pte)
  247. {
  248. set_pte(&pte, __pte(pte_val(pte) | _PAGE_ACCESSED));
  249. return pte;
  250. }
  251. #define pmd_none(x) (!pmd_val(x))
  252. #define pmd_present(x) (pmd_val(x) & _PAGE_PRESENT)
  253. #define pmd_clear(xp) do { set_pmd(xp, __pmd(0)); } while (0)
  254. #define pmd_bad(x) ((pmd_val(x) & (~PAGE_MASK & ~_PAGE_USER)) \
  255. != _KERNPG_TABLE)
  256. /*
  257. * Permanent address of a page. We don't support highmem, so this is
  258. * trivial.
  259. */
  260. #define pages_to_mb(x) ((x) >> (20-PAGE_SHIFT))
  261. #define pte_page(x) phys_to_page(pte_val(x) & PTE_PHYS_MASK)
  262. /*
  263. * Mark the prot value as uncacheable and unbufferable
  264. */
  265. #define pgprot_noncached(prot) \
  266. __pgprot(pgprot_val(prot) & ~(_PAGE_BUFFER | _PAGE_CACHABLE))
  267. /*
  268. * Mark the prot value as uncacheable but bufferable
  269. */
  270. #define pgprot_writecombine(prot) \
  271. __pgprot((pgprot_val(prot) & ~_PAGE_CACHABLE) | _PAGE_BUFFER)
  272. /*
  273. * Conversion functions: convert a page and protection to a page entry,
  274. * and a page entry and page directory to the page they refer to.
  275. *
  276. * extern pte_t mk_pte(struct page *page, pgprot_t pgprot)
  277. */
  278. #define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot))
  279. static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
  280. {
  281. set_pte(&pte, __pte((pte_val(pte) & _PAGE_CHG_MASK)
  282. | pgprot_val(newprot)));
  283. return pte;
  284. }
  285. #define page_pte(page) page_pte_prot(page, __pgprot(0))
  286. #define pmd_page_vaddr(pmd) \
  287. ((unsigned long) __va(pmd_val(pmd) & PAGE_MASK))
  288. #define pmd_page(pmd) (phys_to_page(pmd_val(pmd)))
  289. /* to find an entry in a page-table-directory. */
  290. #define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD-1))
  291. #define pgd_offset(mm, address) ((mm)->pgd+pgd_index(address))
  292. #define pgd_offset_current(address) \
  293. ((pgd_t *)__mfsr(SYSREG_PTBR) + pgd_index(address))
  294. /* to find an entry in a kernel page-table-directory */
  295. #define pgd_offset_k(address) pgd_offset(&init_mm, address)
  296. /* Find an entry in the third-level page table.. */
  297. #define pte_index(address) \
  298. ((address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1))
  299. #define pte_offset(dir, address) \
  300. ((pte_t *) pmd_page_vaddr(*(dir)) + pte_index(address))
  301. #define pte_offset_kernel(dir, address) \
  302. ((pte_t *) pmd_page_vaddr(*(dir)) + pte_index(address))
  303. #define pte_offset_map(dir, address) pte_offset_kernel(dir, address)
  304. #define pte_offset_map_nested(dir, address) pte_offset_kernel(dir, address)
  305. #define pte_unmap(pte) do { } while (0)
  306. #define pte_unmap_nested(pte) do { } while (0)
  307. struct vm_area_struct;
  308. extern void update_mmu_cache(struct vm_area_struct * vma,
  309. unsigned long address, pte_t pte);
  310. /*
  311. * Encode and decode a swap entry
  312. *
  313. * Constraints:
  314. * _PAGE_FILE at bit 0
  315. * _PAGE_TYPE_* at bits 2-3 (for emulating _PAGE_PROTNONE)
  316. * _PAGE_PRESENT at bit 10
  317. *
  318. * We encode the type into bits 4-9 and offset into bits 11-31. This
  319. * gives us a 21 bits offset, or 2**21 * 4K = 8G usable swap space per
  320. * device, and 64 possible types.
  321. *
  322. * NOTE: We should set ZEROs at the position of _PAGE_PRESENT
  323. * and _PAGE_PROTNONE bits
  324. */
  325. #define __swp_type(x) (((x).val >> 4) & 0x3f)
  326. #define __swp_offset(x) ((x).val >> 11)
  327. #define __swp_entry(type, offset) ((swp_entry_t) { ((type) << 4) | ((offset) << 11) })
  328. #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
  329. #define __swp_entry_to_pte(x) ((pte_t) { (x).val })
  330. /*
  331. * Encode and decode a nonlinear file mapping entry. We have to
  332. * preserve _PAGE_FILE and _PAGE_PRESENT here. _PAGE_TYPE_* isn't
  333. * necessary, since _PAGE_FILE implies !_PAGE_PROTNONE (?)
  334. */
  335. #define PTE_FILE_MAX_BITS 30
  336. #define pte_to_pgoff(pte) (((pte_val(pte) >> 1) & 0x1ff) \
  337. | ((pte_val(pte) >> 11) << 9))
  338. #define pgoff_to_pte(off) ((pte_t) { ((((off) & 0x1ff) << 1) \
  339. | (((off) >> 9) << 11) \
  340. | _PAGE_FILE) })
  341. typedef pte_t *pte_addr_t;
  342. #define kern_addr_valid(addr) (1)
  343. #define io_remap_pfn_range(vma, vaddr, pfn, size, prot) \
  344. remap_pfn_range(vma, vaddr, pfn, size, prot)
  345. /* No page table caches to initialize (?) */
  346. #define pgtable_cache_init() do { } while(0)
  347. #include <asm-generic/pgtable.h>
  348. #endif /* !__ASSEMBLY__ */
  349. #endif /* __ASM_AVR32_PGTABLE_H */