PageRenderTime 52ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/release/src/linux/linux/include/asm-alpha/pgalloc.h

https://gitlab.com/envieidoc/advancedtomato2
C Header | 350 lines | 233 code | 51 blank | 66 comment | 24 complexity | 09e70b51141577fd4d33198df2d05fde MD5 | raw file
  1. #ifndef _ALPHA_PGALLOC_H
  2. #define _ALPHA_PGALLOC_H
  3. #include <linux/config.h>
  4. #ifndef __EXTERN_INLINE
  5. #define __EXTERN_INLINE extern inline
  6. #define __MMU_EXTERN_INLINE
  7. #endif
  8. extern void __load_new_mm_context(struct mm_struct *);
  9. /* Caches aren't brain-dead on the Alpha. */
  10. #define flush_cache_all() do { } while (0)
  11. #define flush_cache_mm(mm) do { } while (0)
  12. #define flush_cache_range(mm, start, end) do { } while (0)
  13. #define flush_cache_page(vma, vmaddr) do { } while (0)
  14. #define flush_page_to_ram(page) do { } while (0)
  15. #define flush_dcache_page(page) do { } while (0)
  16. /* Note that the following two definitions are _highly_ dependent
  17. on the contexts in which they are used in the kernel. I personally
  18. think it is criminal how loosely defined these macros are. */
  19. /* We need to flush the kernel's icache after loading modules. The
  20. only other use of this macro is in load_aout_interp which is not
  21. used on Alpha.
  22. Note that this definition should *not* be used for userspace
  23. icache flushing. While functional, it is _way_ overkill. The
  24. icache is tagged with ASNs and it suffices to allocate a new ASN
  25. for the process. */
  26. #ifndef CONFIG_SMP
  27. #define flush_icache_range(start, end) imb()
  28. #else
  29. #define flush_icache_range(start, end) smp_imb()
  30. extern void smp_imb(void);
  31. #endif
  32. /*
  33. * Use a few helper functions to hide the ugly broken ASN
  34. * numbers on early Alphas (ev4 and ev45)
  35. */
  36. __EXTERN_INLINE void
  37. ev4_flush_tlb_current(struct mm_struct *mm)
  38. {
  39. __load_new_mm_context(mm);
  40. tbiap();
  41. }
  42. __EXTERN_INLINE void
  43. ev5_flush_tlb_current(struct mm_struct *mm)
  44. {
  45. __load_new_mm_context(mm);
  46. }
  47. static inline void
  48. flush_tlb_other(struct mm_struct *mm)
  49. {
  50. long * mmc = &mm->context[smp_processor_id()];
  51. /*
  52. * Check it's not zero first to avoid cacheline ping pong when
  53. * possible.
  54. */
  55. if (*mmc)
  56. *mmc = 0;
  57. }
  58. /* We need to flush the userspace icache after setting breakpoints in
  59. ptrace.
  60. Instead of indiscriminately using imb, take advantage of the fact
  61. that icache entries are tagged with the ASN and load a new mm context. */
  62. /* ??? Ought to use this in arch/alpha/kernel/signal.c too. */
  63. #ifndef CONFIG_SMP
  64. static inline void
  65. flush_icache_user_range(struct vm_area_struct *vma, struct page *page,
  66. unsigned long addr, int len)
  67. {
  68. if (vma->vm_flags & VM_EXEC) {
  69. struct mm_struct *mm = vma->vm_mm;
  70. if (current->active_mm == mm)
  71. __load_new_mm_context(mm);
  72. else
  73. mm->context[smp_processor_id()] = 0;
  74. }
  75. }
  76. #else
  77. extern void flush_icache_user_range(struct vm_area_struct *vma,
  78. struct page *page, unsigned long addr, int len);
  79. #endif
  80. /* this is used only in do_no_page and do_swap_page */
  81. #define flush_icache_page(vma, page) flush_icache_user_range((vma), (page), 0, 0)
  82. /*
  83. * Flush just one page in the current TLB set.
  84. * We need to be very careful about the icache here, there
  85. * is no way to invalidate a specific icache page..
  86. */
  87. __EXTERN_INLINE void
  88. ev4_flush_tlb_current_page(struct mm_struct * mm,
  89. struct vm_area_struct *vma,
  90. unsigned long addr)
  91. {
  92. int tbi_flag = 2;
  93. if (vma->vm_flags & VM_EXEC) {
  94. __load_new_mm_context(mm);
  95. tbi_flag = 3;
  96. }
  97. tbi(tbi_flag, addr);
  98. }
  99. __EXTERN_INLINE void
  100. ev5_flush_tlb_current_page(struct mm_struct * mm,
  101. struct vm_area_struct *vma,
  102. unsigned long addr)
  103. {
  104. if (vma->vm_flags & VM_EXEC)
  105. __load_new_mm_context(mm);
  106. else
  107. tbi(2, addr);
  108. }
  109. #ifdef CONFIG_ALPHA_GENERIC
  110. # define flush_tlb_current alpha_mv.mv_flush_tlb_current
  111. # define flush_tlb_current_page alpha_mv.mv_flush_tlb_current_page
  112. #else
  113. # ifdef CONFIG_ALPHA_EV4
  114. # define flush_tlb_current ev4_flush_tlb_current
  115. # define flush_tlb_current_page ev4_flush_tlb_current_page
  116. # else
  117. # define flush_tlb_current ev5_flush_tlb_current
  118. # define flush_tlb_current_page ev5_flush_tlb_current_page
  119. # endif
  120. #endif
  121. #ifdef __MMU_EXTERN_INLINE
  122. #undef __EXTERN_INLINE
  123. #undef __MMU_EXTERN_INLINE
  124. #endif
  125. /*
  126. * Flush current user mapping.
  127. */
  128. static inline void flush_tlb(void)
  129. {
  130. flush_tlb_current(current->active_mm);
  131. }
  132. /*
  133. * Flush a specified range of user mapping page tables
  134. * from TLB.
  135. * Although Alpha uses VPTE caches, this can be a nop, as Alpha does
  136. * not have finegrained tlb flushing, so it will flush VPTE stuff
  137. * during next flush_tlb_range.
  138. */
  139. static inline void flush_tlb_pgtables(struct mm_struct *mm,
  140. unsigned long start, unsigned long end)
  141. {
  142. }
  143. #ifndef CONFIG_SMP
  144. /*
  145. * Flush everything (kernel mapping may also have
  146. * changed due to vmalloc/vfree)
  147. */
  148. static inline void flush_tlb_all(void)
  149. {
  150. tbia();
  151. }
  152. /*
  153. * Flush a specified user mapping
  154. */
  155. static inline void flush_tlb_mm(struct mm_struct *mm)
  156. {
  157. if (mm == current->active_mm)
  158. flush_tlb_current(mm);
  159. else
  160. flush_tlb_other(mm);
  161. }
  162. /*
  163. * Page-granular tlb flush.
  164. *
  165. * do a tbisd (type = 2) normally, and a tbis (type = 3)
  166. * if it is an executable mapping. We want to avoid the
  167. * itlb flush, because that potentially also does a
  168. * icache flush.
  169. */
  170. static inline void flush_tlb_page(struct vm_area_struct *vma,
  171. unsigned long addr)
  172. {
  173. struct mm_struct * mm = vma->vm_mm;
  174. if (mm == current->active_mm)
  175. flush_tlb_current_page(mm, vma, addr);
  176. else
  177. flush_tlb_other(mm);
  178. }
  179. /*
  180. * Flush a specified range of user mapping: on the
  181. * Alpha we flush the whole user tlb.
  182. */
  183. static inline void flush_tlb_range(struct mm_struct *mm,
  184. unsigned long start, unsigned long end)
  185. {
  186. flush_tlb_mm(mm);
  187. }
  188. #else /* CONFIG_SMP */
  189. extern void flush_tlb_all(void);
  190. extern void flush_tlb_mm(struct mm_struct *);
  191. extern void flush_tlb_page(struct vm_area_struct *, unsigned long);
  192. extern void flush_tlb_range(struct mm_struct *, unsigned long, unsigned long);
  193. #endif /* CONFIG_SMP */
  194. /*
  195. * Allocate and free page tables. The xxx_kernel() versions are
  196. * used to allocate a kernel page table - this turns on ASN bits
  197. * if any.
  198. */
  199. #ifndef CONFIG_SMP
  200. extern struct pgtable_cache_struct {
  201. unsigned long *pgd_cache;
  202. unsigned long *pmd_cache;
  203. unsigned long *pte_cache;
  204. unsigned long pgtable_cache_sz;
  205. } quicklists;
  206. #else
  207. #include <asm/smp.h>
  208. #define quicklists cpu_data[smp_processor_id()]
  209. #endif
  210. #define pgd_quicklist (quicklists.pgd_cache)
  211. #define pmd_quicklist (quicklists.pmd_cache)
  212. #define pte_quicklist (quicklists.pte_cache)
  213. #define pgtable_cache_size (quicklists.pgtable_cache_sz)
  214. #define pmd_populate(mm, pmd, pte) pmd_set(pmd, pte)
  215. #define pgd_populate(mm, pgd, pmd) pgd_set(pgd, pmd)
  216. extern pgd_t *get_pgd_slow(void);
  217. static inline pgd_t *get_pgd_fast(void)
  218. {
  219. unsigned long *ret;
  220. if ((ret = pgd_quicklist) != NULL) {
  221. pgd_quicklist = (unsigned long *)(*ret);
  222. ret[0] = 0;
  223. pgtable_cache_size--;
  224. } else
  225. ret = (unsigned long *)get_pgd_slow();
  226. return (pgd_t *)ret;
  227. }
  228. static inline void free_pgd_fast(pgd_t *pgd)
  229. {
  230. *(unsigned long *)pgd = (unsigned long) pgd_quicklist;
  231. pgd_quicklist = (unsigned long *) pgd;
  232. pgtable_cache_size++;
  233. }
  234. static inline void free_pgd_slow(pgd_t *pgd)
  235. {
  236. free_page((unsigned long)pgd);
  237. }
  238. static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
  239. {
  240. pmd_t *ret = (pmd_t *)__get_free_page(GFP_KERNEL);
  241. if (ret)
  242. clear_page(ret);
  243. return ret;
  244. }
  245. static inline pmd_t *pmd_alloc_one_fast(struct mm_struct *mm, unsigned long address)
  246. {
  247. unsigned long *ret;
  248. if ((ret = (unsigned long *)pte_quicklist) != NULL) {
  249. pte_quicklist = (unsigned long *)(*ret);
  250. ret[0] = 0;
  251. pgtable_cache_size--;
  252. }
  253. return (pmd_t *)ret;
  254. }
  255. static inline void pmd_free_fast(pmd_t *pmd)
  256. {
  257. *(unsigned long *)pmd = (unsigned long) pte_quicklist;
  258. pte_quicklist = (unsigned long *) pmd;
  259. pgtable_cache_size++;
  260. }
  261. static inline void pmd_free_slow(pmd_t *pmd)
  262. {
  263. free_page((unsigned long)pmd);
  264. }
  265. static inline pte_t *pte_alloc_one(struct mm_struct *mm, unsigned long address)
  266. {
  267. pte_t *pte = (pte_t *)__get_free_page(GFP_KERNEL);
  268. if (pte)
  269. clear_page(pte);
  270. return pte;
  271. }
  272. static inline pte_t *pte_alloc_one_fast(struct mm_struct *mm, unsigned long address)
  273. {
  274. unsigned long *ret;
  275. if ((ret = (unsigned long *)pte_quicklist) != NULL) {
  276. pte_quicklist = (unsigned long *)(*ret);
  277. ret[0] = 0;
  278. pgtable_cache_size--;
  279. }
  280. return (pte_t *)ret;
  281. }
  282. static inline void pte_free_fast(pte_t *pte)
  283. {
  284. *(unsigned long *)pte = (unsigned long) pte_quicklist;
  285. pte_quicklist = (unsigned long *) pte;
  286. pgtable_cache_size++;
  287. }
  288. static inline void pte_free_slow(pte_t *pte)
  289. {
  290. free_page((unsigned long)pte);
  291. }
  292. #define pte_free(pte) pte_free_fast(pte)
  293. #define pmd_free(pmd) pmd_free_fast(pmd)
  294. #define pgd_free(pgd) free_pgd_fast(pgd)
  295. #define pgd_alloc(mm) get_pgd_fast()
  296. extern int do_check_pgt_cache(int, int);
  297. #endif /* _ALPHA_PGALLOC_H */