pgalloc.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /*
  2. * arch/arm/include/asm/pgalloc.h
  3. *
  4. * Copyright (C) 2000-2001 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 _ASMARM_PGALLOC_H
  11. #define _ASMARM_PGALLOC_H
  12. #include <linux/pagemap.h>
  13. #include <asm/domain.h>
  14. #include <asm/pgtable-hwdef.h>
  15. #include <asm/processor.h>
  16. #include <asm/cacheflush.h>
  17. #include <asm/tlbflush.h>
  18. #define check_pgt_cache() do { } while (0)
  19. #ifdef CONFIG_MMU
  20. #define _PAGE_USER_TABLE (PMD_TYPE_TABLE | PMD_BIT4 | PMD_DOMAIN(DOMAIN_USER))
  21. #define _PAGE_KERNEL_TABLE (PMD_TYPE_TABLE | PMD_BIT4 | PMD_DOMAIN(DOMAIN_KERNEL))
  22. #ifdef CONFIG_ARM_LPAE
  23. static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
  24. {
  25. return (pmd_t *)get_zeroed_page(GFP_KERNEL | __GFP_REPEAT);
  26. }
  27. static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
  28. {
  29. BUG_ON((unsigned long)pmd & (PAGE_SIZE-1));
  30. free_page((unsigned long)pmd);
  31. }
  32. static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
  33. {
  34. set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
  35. }
  36. #else /* !CONFIG_ARM_LPAE */
  37. /*
  38. * Since we have only two-level page tables, these are trivial
  39. */
  40. #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
  41. #define pmd_free(mm, pmd) do { } while (0)
  42. #define pud_populate(mm,pmd,pte) BUG()
  43. #endif /* CONFIG_ARM_LPAE */
  44. extern pgd_t *pgd_alloc(struct mm_struct *mm);
  45. extern void pgd_free(struct mm_struct *mm, pgd_t *pgd);
  46. #define PGALLOC_GFP (GFP_KERNEL | __GFP_NOTRACK | __GFP_REPEAT | __GFP_ZERO)
  47. static inline void clean_pte_table(pte_t *pte)
  48. {
  49. clean_dcache_area(pte + PTE_HWTABLE_PTRS, PTE_HWTABLE_SIZE);
  50. }
  51. /*
  52. * Allocate one PTE table.
  53. *
  54. * This actually allocates two hardware PTE tables, but we wrap this up
  55. * into one table thus:
  56. *
  57. * +------------+
  58. * | Linux pt 0 |
  59. * +------------+
  60. * | Linux pt 1 |
  61. * +------------+
  62. * | h/w pt 0 |
  63. * +------------+
  64. * | h/w pt 1 |
  65. * +------------+
  66. */
  67. static inline pte_t *
  68. pte_alloc_one_kernel(struct mm_struct *mm, unsigned long addr)
  69. {
  70. pte_t *pte;
  71. pte = (pte_t *)__get_free_page(PGALLOC_GFP);
  72. if (pte)
  73. clean_pte_table(pte);
  74. return pte;
  75. }
  76. static inline pgtable_t
  77. pte_alloc_one(struct mm_struct *mm, unsigned long addr)
  78. {
  79. struct page *pte;
  80. #ifdef CONFIG_HIGHPTE
  81. pte = alloc_pages(PGALLOC_GFP | __GFP_HIGHMEM, 0);
  82. #else
  83. pte = alloc_pages(PGALLOC_GFP, 0);
  84. #endif
  85. if (pte) {
  86. if (!PageHighMem(pte))
  87. clean_pte_table(page_address(pte));
  88. pgtable_page_ctor(pte);
  89. }
  90. return pte;
  91. }
  92. /*
  93. * Free one PTE table.
  94. */
  95. static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
  96. {
  97. if (pte)
  98. free_page((unsigned long)pte);
  99. }
  100. static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
  101. {
  102. pgtable_page_dtor(pte);
  103. __free_page(pte);
  104. }
  105. static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
  106. pmdval_t prot)
  107. {
  108. pmdval_t pmdval = (pte + PTE_HWTABLE_OFF) | prot;
  109. #ifdef CONFIG_TIMA_RKP_L1_TABLES
  110. unsigned long cmd_id = 0x3f809221;
  111. unsigned long tima_wr_out, pmd_base;
  112. #if __GNUC__ >= 4 && __GNUC_MINOR__ >= 6
  113. __asm__ __volatile__(".arch_extension sec");
  114. #endif
  115. clean_dcache_area(pmdp, 8);
  116. __asm__ __volatile__ (
  117. "stmfd sp!,{r0, r8-r11}\n"
  118. "mov r11, r0\n"
  119. "mov r0, %1\n"
  120. "mov r8, %2\n"
  121. "mov r9, %3\n"
  122. "mov r10, %4\n"
  123. "mcr p15, 0, r8, c7, c14, 1\n"
  124. "add r8, r8, #4\n"
  125. "mcr p15, 0, r8, c7, c14, 1\n"
  126. "dsb\n"
  127. "smc #9\n"
  128. "sub r8, r8, #4\n"
  129. "mcr p15, 0, r8, c7, c6, 1\n"
  130. "dsb\n"
  131. "mov %0, r10\n"
  132. "add r8, r8, #4\n"
  133. "mcr p15, 0, r8, c7, c6, 1\n"
  134. "dsb\n"
  135. "mov r0, #0\n"
  136. "mcr p15, 0, r0, c8, c3, 0\n"
  137. "dsb\n"
  138. "isb\n"
  139. "pop {r0, r8-r11}\n"
  140. :"=r"(tima_wr_out):"r"(cmd_id),"r"((unsigned long)pmdp),"r"(pmdval),"r"(__pmd(pmdval + 256 * sizeof(pte_t))):"r0","r8","r9","r10","r11","cc");
  141. #else
  142. pmdp[0] = __pmd(pmdval);
  143. #ifndef CONFIG_ARM_LPAE
  144. pmdp[1] = __pmd(pmdval + 256 * sizeof(pte_t));
  145. #endif
  146. #endif
  147. flush_pmd_entry(pmdp);
  148. #ifdef CONFIG_TIMA_RKP_L1_TABLES
  149. pmd_base = ((unsigned long)pmdp) & (~0x3fff);
  150. tima_verify_state(pmd_base, 0, 1, 2);
  151. tima_verify_state(pmd_base + 0x1000, 0, 1, 2);
  152. tima_verify_state(pmd_base + 0x2000, 0, 1, 2);
  153. tima_verify_state(pmd_base + 0x3000, 0, 1, 2);
  154. #endif
  155. }
  156. /*
  157. * Populate the pmdp entry with a pointer to the pte. This pmd is part
  158. * of the mm address space.
  159. *
  160. * Ensure that we always set both PMD entries.
  161. */
  162. static inline void
  163. pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
  164. {
  165. /*
  166. * The pmd must be loaded with the physical address of the PTE table
  167. */
  168. __pmd_populate(pmdp, __pa(ptep), _PAGE_KERNEL_TABLE);
  169. }
  170. static inline void
  171. pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
  172. {
  173. extern pmdval_t user_pmd_table;
  174. pmdval_t prot;
  175. if (__LINUX_ARM_ARCH__ >= 6 && !IS_ENABLED(CONFIG_ARM_LPAE))
  176. prot = user_pmd_table;
  177. else
  178. prot = _PAGE_USER_TABLE;
  179. __pmd_populate(pmdp, page_to_phys(ptep), prot);
  180. }
  181. #define pmd_pgtable(pmd) pmd_page(pmd)
  182. #endif /* CONFIG_MMU */
  183. #endif