copypage-v6.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * linux/arch/arm/mm/copypage-v6.c
  3. *
  4. * Copyright (C) 2002 Deep Blue Solutions Ltd, All Rights Reserved.
  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. #include <linux/init.h>
  11. #include <linux/spinlock.h>
  12. #include <linux/mm.h>
  13. #include <asm/page.h>
  14. #include <asm/pgtable.h>
  15. #include <asm/shmparam.h>
  16. #include <asm/tlbflush.h>
  17. #include <asm/cacheflush.h>
  18. #if SHMLBA > 16384
  19. #error FIX ME
  20. #endif
  21. #define from_address (0xffff8000)
  22. #define to_address (0xffffc000)
  23. #define TOP_PTE(x) pte_offset_kernel(top_pmd, x)
  24. static DEFINE_SPINLOCK(v6_lock);
  25. /*
  26. * Copy the user page. No aliasing to deal with so we can just
  27. * attack the kernel's existing mapping of these pages.
  28. */
  29. static void v6_copy_user_page_nonaliasing(void *kto, const void *kfrom, unsigned long vaddr)
  30. {
  31. copy_page(kto, kfrom);
  32. }
  33. /*
  34. * Clear the user page. No aliasing to deal with so we can just
  35. * attack the kernel's existing mapping of this page.
  36. */
  37. static void v6_clear_user_page_nonaliasing(void *kaddr, unsigned long vaddr)
  38. {
  39. clear_page(kaddr);
  40. }
  41. /*
  42. * Copy the page, taking account of the cache colour.
  43. */
  44. static void v6_copy_user_page_aliasing(void *kto, const void *kfrom, unsigned long vaddr)
  45. {
  46. unsigned int offset = CACHE_COLOUR(vaddr);
  47. unsigned long from, to;
  48. /*
  49. * Discard data in the kernel mapping for the new page.
  50. * FIXME: needs this MCRR to be supported.
  51. */
  52. __asm__("mcrr p15, 0, %1, %0, c6 @ 0xec401f06"
  53. :
  54. : "r" (kto),
  55. "r" ((unsigned long)kto + PAGE_SIZE - L1_CACHE_BYTES)
  56. : "cc");
  57. /*
  58. * Now copy the page using the same cache colour as the
  59. * pages ultimate destination.
  60. */
  61. spin_lock(&v6_lock);
  62. set_pte(TOP_PTE(from_address) + offset, pfn_pte(__pa(kfrom) >> PAGE_SHIFT, PAGE_KERNEL));
  63. set_pte(TOP_PTE(to_address) + offset, pfn_pte(__pa(kto) >> PAGE_SHIFT, PAGE_KERNEL));
  64. from = from_address + (offset << PAGE_SHIFT);
  65. to = to_address + (offset << PAGE_SHIFT);
  66. flush_tlb_kernel_page(from);
  67. flush_tlb_kernel_page(to);
  68. copy_page((void *)to, (void *)from);
  69. spin_unlock(&v6_lock);
  70. }
  71. /*
  72. * Clear the user page. We need to deal with the aliasing issues,
  73. * so remap the kernel page into the same cache colour as the user
  74. * page.
  75. */
  76. static void v6_clear_user_page_aliasing(void *kaddr, unsigned long vaddr)
  77. {
  78. unsigned int offset = CACHE_COLOUR(vaddr);
  79. unsigned long to = to_address + (offset << PAGE_SHIFT);
  80. /*
  81. * Discard data in the kernel mapping for the new page
  82. * FIXME: needs this MCRR to be supported.
  83. */
  84. __asm__("mcrr p15, 0, %1, %0, c6 @ 0xec401f06"
  85. :
  86. : "r" (kaddr),
  87. "r" ((unsigned long)kaddr + PAGE_SIZE - L1_CACHE_BYTES)
  88. : "cc");
  89. /*
  90. * Now clear the page using the same cache colour as
  91. * the pages ultimate destination.
  92. */
  93. spin_lock(&v6_lock);
  94. set_pte(TOP_PTE(to_address) + offset, pfn_pte(__pa(kaddr) >> PAGE_SHIFT, PAGE_KERNEL));
  95. flush_tlb_kernel_page(to);
  96. clear_page((void *)to);
  97. spin_unlock(&v6_lock);
  98. }
  99. struct cpu_user_fns v6_user_fns __initdata = {
  100. .cpu_clear_user_page = v6_clear_user_page_nonaliasing,
  101. .cpu_copy_user_page = v6_copy_user_page_nonaliasing,
  102. };
  103. static int __init v6_userpage_init(void)
  104. {
  105. if (cache_is_vipt_aliasing()) {
  106. cpu_user.cpu_clear_user_page = v6_clear_user_page_aliasing;
  107. cpu_user.cpu_copy_user_page = v6_copy_user_page_aliasing;
  108. }
  109. return 0;
  110. }
  111. core_initcall(v6_userpage_init);