pgtable-2level.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. /*
  2. * arch/arm/include/asm/pgtable-2level.h
  3. *
  4. * Copyright (C) 1995-2002 Russell King
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #ifndef _ASM_PGTABLE_2LEVEL_H
  11. #define _ASM_PGTABLE_2LEVEL_H
  12. /*
  13. * Hardware-wise, we have a two level page table structure, where the first
  14. * level has 4096 entries, and the second level has 256 entries. Each entry
  15. * is one 32-bit word. Most of the bits in the second level entry are used
  16. * by hardware, and there aren't any "accessed" and "dirty" bits.
  17. *
  18. * Linux on the other hand has a three level page table structure, which can
  19. * be wrapped to fit a two level page table structure easily - using the PGD
  20. * and PTE only. However, Linux also expects one "PTE" table per page, and
  21. * at least a "dirty" bit.
  22. *
  23. * Therefore, we tweak the implementation slightly - we tell Linux that we
  24. * have 2048 entries in the first level, each of which is 8 bytes (iow, two
  25. * hardware pointers to the second level.) The second level contains two
  26. * hardware PTE tables arranged contiguously, preceded by Linux versions
  27. * which contain the state information Linux needs. We, therefore, end up
  28. * with 512 entries in the "PTE" level.
  29. *
  30. * This leads to the page tables having the following layout:
  31. *
  32. * pgd pte
  33. * | |
  34. * +--------+
  35. * | | +------------+ +0
  36. * +- - - - + | Linux pt 0 |
  37. * | | +------------+ +1024
  38. * +--------+ +0 | Linux pt 1 |
  39. * | |-----> +------------+ +2048
  40. * +- - - - + +4 | h/w pt 0 |
  41. * | |-----> +------------+ +3072
  42. * +--------+ +8 | h/w pt 1 |
  43. * | | +------------+ +4096
  44. *
  45. * See L_PTE_xxx below for definitions of bits in the "Linux pt", and
  46. * PTE_xxx for definitions of bits appearing in the "h/w pt".
  47. *
  48. * PMD_xxx definitions refer to bits in the first level page table.
  49. *
  50. * The "dirty" bit is emulated by only granting hardware write permission
  51. * iff the page is marked "writable" and "dirty" in the Linux PTE. This
  52. * means that a write to a clean page will cause a permission fault, and
  53. * the Linux MM layer will mark the page dirty via handle_pte_fault().
  54. * For the hardware to notice the permission change, the TLB entry must
  55. * be flushed, and ptep_set_access_flags() does that for us.
  56. *
  57. * The "accessed" or "young" bit is emulated by a similar method; we only
  58. * allow accesses to the page if the "young" bit is set. Accesses to the
  59. * page will cause a fault, and handle_pte_fault() will set the young bit
  60. * for us as long as the page is marked present in the corresponding Linux
  61. * PTE entry. Again, ptep_set_access_flags() will ensure that the TLB is
  62. * up to date.
  63. *
  64. * However, when the "young" bit is cleared, we deny access to the page
  65. * by clearing the hardware PTE. Currently Linux does not flush the TLB
  66. * for us in this case, which means the TLB will retain the transation
  67. * until either the TLB entry is evicted under pressure, or a context
  68. * switch which changes the user space mapping occurs.
  69. */
  70. #ifdef CONFIG_TIMA_RKP
  71. #include <asm/tlbflush.h>
  72. #include <asm/cp15.h>
  73. #endif
  74. #define PTRS_PER_PTE 512
  75. #define PTRS_PER_PMD 1
  76. #define PTRS_PER_PGD 2048
  77. #define PTE_HWTABLE_PTRS (PTRS_PER_PTE)
  78. #define PTE_HWTABLE_OFF (PTE_HWTABLE_PTRS * sizeof(pte_t))
  79. #define PTE_HWTABLE_SIZE (PTRS_PER_PTE * sizeof(u32))
  80. /*
  81. * PMD_SHIFT determines the size of the area a second-level page table can map
  82. * PGDIR_SHIFT determines what a third-level page table entry can map
  83. */
  84. #define PMD_SHIFT 21
  85. #define PGDIR_SHIFT 21
  86. #define PMD_SIZE (1UL << PMD_SHIFT)
  87. #define PMD_MASK (~(PMD_SIZE-1))
  88. #define PGDIR_SIZE (1UL << PGDIR_SHIFT)
  89. #define PGDIR_MASK (~(PGDIR_SIZE-1))
  90. /*
  91. * section address mask and size definitions.
  92. */
  93. #define SECTION_SHIFT 20
  94. #define SECTION_SIZE (1UL << SECTION_SHIFT)
  95. #define SECTION_MASK (~(SECTION_SIZE-1))
  96. /*
  97. * ARMv6 supersection address mask and size definitions.
  98. */
  99. #define SUPERSECTION_SHIFT 24
  100. #define SUPERSECTION_SIZE (1UL << SUPERSECTION_SHIFT)
  101. #define SUPERSECTION_MASK (~(SUPERSECTION_SIZE-1))
  102. #define USER_PTRS_PER_PGD (TASK_SIZE / PGDIR_SIZE)
  103. /*
  104. * "Linux" PTE definitions.
  105. *
  106. * We keep two sets of PTEs - the hardware and the linux version.
  107. * This allows greater flexibility in the way we map the Linux bits
  108. * onto the hardware tables, and allows us to have YOUNG and DIRTY
  109. * bits.
  110. *
  111. * The PTE table pointer refers to the hardware entries; the "Linux"
  112. * entries are stored 1024 bytes below.
  113. */
  114. #define L_PTE_PRESENT (_AT(pteval_t, 1) << 0)
  115. #define L_PTE_YOUNG (_AT(pteval_t, 1) << 1)
  116. #define L_PTE_FILE (_AT(pteval_t, 1) << 2) /* only when !PRESENT */
  117. #define L_PTE_DIRTY (_AT(pteval_t, 1) << 6)
  118. #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7)
  119. #define L_PTE_USER (_AT(pteval_t, 1) << 8)
  120. #define L_PTE_XN (_AT(pteval_t, 1) << 9)
  121. #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
  122. /*
  123. * These are the memory types, defined to be compatible with
  124. * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
  125. */
  126. #define L_PTE_MT_UNCACHED (_AT(pteval_t, 0x00) << 2) /* 0000 */
  127. #define L_PTE_MT_BUFFERABLE (_AT(pteval_t, 0x01) << 2) /* 0001 */
  128. #define L_PTE_MT_WRITETHROUGH (_AT(pteval_t, 0x02) << 2) /* 0010 */
  129. #define L_PTE_MT_WRITEBACK (_AT(pteval_t, 0x03) << 2) /* 0011 */
  130. #define L_PTE_MT_MINICACHE (_AT(pteval_t, 0x06) << 2) /* 0110 (sa1100, xscale) */
  131. #define L_PTE_MT_WRITEALLOC (_AT(pteval_t, 0x07) << 2) /* 0111 */
  132. #define L_PTE_MT_DEV_SHARED (_AT(pteval_t, 0x04) << 2) /* 0100 */
  133. #define L_PTE_MT_DEV_NONSHARED (_AT(pteval_t, 0x0c) << 2) /* 1100 */
  134. #define L_PTE_MT_DEV_WC (_AT(pteval_t, 0x09) << 2) /* 1001 */
  135. #define L_PTE_MT_DEV_CACHED (_AT(pteval_t, 0x0b) << 2) /* 1011 */
  136. #define L_PTE_MT_VECTORS (_AT(pteval_t, 0x0f) << 2) /* 1111 */
  137. #define L_PTE_MT_MASK (_AT(pteval_t, 0x0f) << 2)
  138. #ifndef __ASSEMBLY__
  139. /*
  140. * The "pud_xxx()" functions here are trivial when the pmd is folded into
  141. * the pud: the pud entry is never bad, always exists, and can't be set or
  142. * cleared.
  143. */
  144. #define pud_none(pud) (0)
  145. #define pud_bad(pud) (0)
  146. #define pud_present(pud) (1)
  147. #define pud_clear(pudp) do { } while (0)
  148. #define set_pud(pud,pudp) do { } while (0)
  149. static inline pmd_t *pmd_offset(pud_t *pud, unsigned long addr)
  150. {
  151. return (pmd_t *)pud;
  152. }
  153. #define pmd_bad(pmd) (pmd_val(pmd) & 2)
  154. #ifdef CONFIG_TIMA_RKP_L1_TABLES
  155. #if __GNUC__ >= 4 && __GNUC_MINOR__ >= 6
  156. asm(".arch_extension sec");
  157. #endif
  158. #endif
  159. #ifdef CONFIG_TIMA_RKP_L1_TABLES
  160. static inline void copy_pmd(pmd_t *pmdpd, pmd_t *pmdps)
  161. {
  162. unsigned long cmd_id = 0x3f809221;
  163. unsigned long tima_wr_out;
  164. unsigned long pmd_base;
  165. cpu_dcache_clean_area(pmdpd, 8);
  166. __asm__ __volatile__ (
  167. "stmfd sp!,{r0, r8-r11}\n"
  168. "mov r11, r0\n"
  169. "mov r0, %1\n"
  170. "mov r8, %2\n"
  171. "mov r9, %3\n"
  172. "mov r10, %4\n"
  173. "mcr p15, 0, r8, c7, c14, 1\n"
  174. "add r8, r8, #4\n"
  175. "mcr p15, 0, r8, c7, c14, 1\n"
  176. "dsb\n"
  177. "smc #9\n"
  178. "sub r8, r8, #4\n"
  179. "mcr p15, 0, r8, c7, c6, 1\n"
  180. "dsb\n"
  181. "mov %0, r10\n"
  182. "add r8, r8, #4\n"
  183. "mcr p15, 0, r8, c7, c6, 1\n"
  184. "dsb\n"
  185. "mov r0, #0\n"
  186. "mcr p15, 0, r0, c8, c3, 0\n"
  187. "dsb\n"
  188. "isb\n"
  189. "pop {r0, r8-r11}\n"
  190. :"=r"(tima_wr_out):"r"(cmd_id),"r"((unsigned long)pmdpd),"r"(pmdps[0]),"r"(pmdps[1]):"r0","r8","r9","r10","r11","cc");
  191. if (pmdpd[0] != pmdps[0] || pmdpd[1] != pmdps[1]) {
  192. printk(KERN_ERR"TIMA: pmdpd[0] %lx != pmdps[0] %lx -- pmdpd[1] %lx != pmdps[1] %lx in tima_wr_out = %lx\n",
  193. (unsigned long) pmdpd[0], (unsigned long) pmdps[0], (unsigned long) pmdpd[1], (unsigned long) pmdps[1], tima_wr_out);
  194. }
  195. flush_pmd_entry(pmdpd);
  196. pmd_base = ((unsigned long)pmdpd) & (~0x3fff);
  197. tima_verify_state(pmd_base, pmdps[0], 1, 0);
  198. tima_verify_state(pmd_base + 0x1000, pmdps[0], 1, 0);
  199. tima_verify_state(pmd_base + 0x2000, pmdps[0], 1, 0);
  200. tima_verify_state(pmd_base + 0x3000, pmdps[0], 1, 0);
  201. }
  202. #else
  203. #define copy_pmd(pmdpd,pmdps) \
  204. do { \
  205. pmdpd[0] = pmdps[0]; \
  206. pmdpd[1] = pmdps[1]; \
  207. flush_pmd_entry(pmdpd); \
  208. } while (0)
  209. #endif
  210. #ifdef CONFIG_TIMA_RKP_L1_TABLES
  211. #if __GNUC__ >= 4 && __GNUC_MINOR__ >= 6
  212. asm(".arch_extension sec");
  213. #endif
  214. #endif
  215. #ifdef CONFIG_TIMA_RKP
  216. extern void cpu_v7_tima_iommu_opt(unsigned long start,
  217. unsigned long end, unsigned long pgd);
  218. #endif
  219. #ifdef CONFIG_TIMA_RKP_L1_TABLES
  220. static inline void pmd_clear(pmd_t *pmdp)
  221. {
  222. unsigned long cmd_id = 0x3f80a221;
  223. unsigned long tima_wr_out;
  224. cpu_dcache_clean_area(pmdp, 8);
  225. __asm__ __volatile__ (
  226. "stmfd sp!,{r0, r1, r11}\n"
  227. "mov r11, r0\n"
  228. "mov r0, %1\n"
  229. "mov r1, %2\n"
  230. "mcr p15, 0, r1, c7, c14, 1\n"
  231. "add r1, r1, #4\n"
  232. "mcr p15, 0, r1, c7, c14, 1\n"
  233. "dsb\n"
  234. "smc #10\n"
  235. "mcr p15, 0, r1, c7, c6, 1\n"
  236. "dsb\n"
  237. "sub r1, r1, #4\n"
  238. "mcr p15, 0, r1, c7, c6, 1\n"
  239. "dsb\n"
  240. "ldr r0, [r1]\n"
  241. "mov %0, r0\n"
  242. "mov r0, #0\n"
  243. "mcr p15, 0, r0, c8, c3, 0\n"
  244. "dsb\n"
  245. "isb\n"
  246. "pop {r0, r1, r11}\n"
  247. :"=r"(tima_wr_out):"r"(cmd_id),"r"((unsigned long)pmdp):"r0","r1","r11","cc");
  248. if (pmdp[0] != 0 || pmdp[1] != 0 || tima_wr_out!=0)
  249. printk(KERN_ERR"pmdp[0] %lx - pmdp[1] %lx in tima_wr_out = %lx\n", (unsigned long)pmdp[0], (unsigned long)pmdp[1], tima_wr_out);
  250. clean_pmd_entry(pmdp);
  251. }
  252. #else
  253. #define pmd_clear(pmdp) \
  254. do { \
  255. pmdp[0] = __pmd(0); \
  256. pmdp[1] = __pmd(0); \
  257. clean_pmd_entry(pmdp); \
  258. } while (0)
  259. #endif
  260. #ifdef CONFIG_TIMA_RKP_L2_GROUP
  261. extern int cpu_v7_timal2group_set_pte_ext(pte_t *ptep, pte_t pte, unsigned int ext,
  262. unsigned long tima_l2group_entry_ptr);
  263. extern void cpu_v7_timal2group_set_pte_commit(void *tima_l2group_entry_ptr,
  264. unsigned long tima_l2group_entries_count);
  265. #endif /* CONFIG_TIMA_RKP_L2_GROUP */
  266. /* we don't need complex calculations here as the pmd is folded into the pgd */
  267. #define pmd_addr_end(addr,end) (end)
  268. #ifdef CONFIG_TIMA_RKP_L2_TABLES
  269. static inline void set_pte_ext(pte_t *ptep,pte_t pte,unsigned int ext)
  270. {
  271. if (tima_is_pg_protected((unsigned long) ptep) == 0)
  272. cpu_set_pte_ext(ptep,pte,ext);
  273. else
  274. cpu_tima_set_pte_ext(ptep,pte,ext);
  275. }
  276. #else
  277. #define set_pte_ext(ptep,pte,ext) cpu_set_pte_ext(ptep,pte,ext)
  278. #endif
  279. #ifdef CONFIG_TIMA_RKP_LAZY_MMU
  280. #define TIMA_LAZY_MMU_CMDID 0x25
  281. #define TIMA_LAZY_MMU_START 0
  282. #define TIMA_LAZY_MMU_STOP 1
  283. #endif
  284. #endif /* __ASSEMBLY__ */
  285. #endif /* _ASM_PGTABLE_2LEVEL_H */