copypage-xscale.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * linux/arch/arm/lib/copypage-xscale.S
  4. *
  5. * Copyright (C) 1995-2005 Russell King
  6. *
  7. * This handles the mini data cache, as found on SA11x0 and XScale
  8. * processors. When we copy a user page page, we map it in such a way
  9. * that accesses to this page will not touch the main data cache, but
  10. * will be cached in the mini data cache. This prevents us thrashing
  11. * the main data cache on page faults.
  12. */
  13. #include <linux/init.h>
  14. #include <linux/mm.h>
  15. #include <linux/highmem.h>
  16. #include <linux/pagemap.h>
  17. #include <asm/tlbflush.h>
  18. #include <asm/cacheflush.h>
  19. #include "mm.h"
  20. #define minicache_pgprot __pgprot(L_PTE_PRESENT | L_PTE_YOUNG | \
  21. L_PTE_MT_MINICACHE)
  22. static DEFINE_RAW_SPINLOCK(minicache_lock);
  23. /*
  24. * XScale mini-dcache optimised copy_user_highpage
  25. *
  26. * We flush the destination cache lines just before we write the data into the
  27. * corresponding address. Since the Dcache is read-allocate, this removes the
  28. * Dcache aliasing issue. The writes will be forwarded to the write buffer,
  29. * and merged as appropriate.
  30. */
  31. static void mc_copy_user_page(void *from, void *to)
  32. {
  33. int tmp;
  34. /*
  35. * Strangely enough, best performance is achieved
  36. * when prefetching destination as well. (NP)
  37. */
  38. asm volatile ("\
  39. .arch xscale \n\
  40. pld [%0, #0] \n\
  41. pld [%0, #32] \n\
  42. pld [%1, #0] \n\
  43. pld [%1, #32] \n\
  44. 1: pld [%0, #64] \n\
  45. pld [%0, #96] \n\
  46. pld [%1, #64] \n\
  47. pld [%1, #96] \n\
  48. 2: ldrd r2, r3, [%0], #8 \n\
  49. ldrd r4, r5, [%0], #8 \n\
  50. mov ip, %1 \n\
  51. strd r2, r3, [%1], #8 \n\
  52. ldrd r2, r3, [%0], #8 \n\
  53. strd r4, r5, [%1], #8 \n\
  54. ldrd r4, r5, [%0], #8 \n\
  55. strd r2, r3, [%1], #8 \n\
  56. strd r4, r5, [%1], #8 \n\
  57. mcr p15, 0, ip, c7, c10, 1 @ clean D line\n\
  58. ldrd r2, r3, [%0], #8 \n\
  59. mcr p15, 0, ip, c7, c6, 1 @ invalidate D line\n\
  60. ldrd r4, r5, [%0], #8 \n\
  61. mov ip, %1 \n\
  62. strd r2, r3, [%1], #8 \n\
  63. ldrd r2, r3, [%0], #8 \n\
  64. strd r4, r5, [%1], #8 \n\
  65. ldrd r4, r5, [%0], #8 \n\
  66. strd r2, r3, [%1], #8 \n\
  67. strd r4, r5, [%1], #8 \n\
  68. mcr p15, 0, ip, c7, c10, 1 @ clean D line\n\
  69. subs %2, %2, #1 \n\
  70. mcr p15, 0, ip, c7, c6, 1 @ invalidate D line\n\
  71. bgt 1b \n\
  72. beq 2b "
  73. : "+&r" (from), "+&r" (to), "=&r" (tmp)
  74. : "2" (PAGE_SIZE / 64 - 1)
  75. : "r2", "r3", "r4", "r5", "ip");
  76. }
  77. void xscale_mc_copy_user_highpage(struct page *to, struct page *from,
  78. unsigned long vaddr, struct vm_area_struct *vma)
  79. {
  80. void *kto = kmap_atomic(to);
  81. if (!test_and_set_bit(PG_dcache_clean, &from->flags))
  82. __flush_dcache_page(page_mapping_file(from), from);
  83. raw_spin_lock(&minicache_lock);
  84. set_top_pte(COPYPAGE_MINICACHE, mk_pte(from, minicache_pgprot));
  85. mc_copy_user_page((void *)COPYPAGE_MINICACHE, kto);
  86. raw_spin_unlock(&minicache_lock);
  87. kunmap_atomic(kto);
  88. }
  89. /*
  90. * XScale optimised clear_user_page
  91. */
  92. void
  93. xscale_mc_clear_user_highpage(struct page *page, unsigned long vaddr)
  94. {
  95. void *ptr, *kaddr = kmap_atomic(page);
  96. asm volatile("\
  97. .arch xscale \n\
  98. mov r1, %2 \n\
  99. mov r2, #0 \n\
  100. mov r3, #0 \n\
  101. 1: mov ip, %0 \n\
  102. strd r2, r3, [%0], #8 \n\
  103. strd r2, r3, [%0], #8 \n\
  104. strd r2, r3, [%0], #8 \n\
  105. strd r2, r3, [%0], #8 \n\
  106. mcr p15, 0, ip, c7, c10, 1 @ clean D line\n\
  107. subs r1, r1, #1 \n\
  108. mcr p15, 0, ip, c7, c6, 1 @ invalidate D line\n\
  109. bne 1b"
  110. : "=r" (ptr)
  111. : "0" (kaddr), "I" (PAGE_SIZE / 32)
  112. : "r1", "r2", "r3", "ip");
  113. kunmap_atomic(kaddr);
  114. }
  115. struct cpu_user_fns xscale_mc_user_fns __initdata = {
  116. .cpu_clear_user_highpage = xscale_mc_clear_user_highpage,
  117. .cpu_copy_user_highpage = xscale_mc_copy_user_highpage,
  118. };