copypage-v6.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. #include "mm.h"
  19. #if SHMLBA > 16384
  20. #error FIX ME
  21. #endif
  22. #define from_address (0xffff8000)
  23. #define to_address (0xffffc000)
  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. struct page *page = virt_to_page(kfrom);
  49. if (test_and_clear_bit(PG_dcache_dirty, &page->flags))
  50. __flush_dcache_page(page_mapping(page), page);
  51. /*
  52. * Discard data in the kernel mapping for the new page.
  53. * FIXME: needs this MCRR to be supported.
  54. */
  55. __asm__("mcrr p15, 0, %1, %0, c6 @ 0xec401f06"
  56. :
  57. : "r" (kto),
  58. "r" ((unsigned long)kto + PAGE_SIZE - L1_CACHE_BYTES)
  59. : "cc");
  60. /*
  61. * Now copy the page using the same cache colour as the
  62. * pages ultimate destination.
  63. */
  64. spin_lock(&v6_lock);
  65. set_pte_ext(TOP_PTE(from_address) + offset, pfn_pte(__pa(kfrom) >> PAGE_SHIFT, PAGE_KERNEL), 0);
  66. set_pte_ext(TOP_PTE(to_address) + offset, pfn_pte(__pa(kto) >> PAGE_SHIFT, PAGE_KERNEL), 0);
  67. from = from_address + (offset << PAGE_SHIFT);
  68. to = to_address + (offset << PAGE_SHIFT);
  69. flush_tlb_kernel_page(from);
  70. flush_tlb_kernel_page(to);
  71. copy_page((void *)to, (void *)from);
  72. spin_unlock(&v6_lock);
  73. }
  74. /*
  75. * Clear the user page. We need to deal with the aliasing issues,
  76. * so remap the kernel page into the same cache colour as the user
  77. * page.
  78. */
  79. static void v6_clear_user_page_aliasing(void *kaddr, unsigned long vaddr)
  80. {
  81. unsigned int offset = CACHE_COLOUR(vaddr);
  82. unsigned long to = to_address + (offset << PAGE_SHIFT);
  83. /*
  84. * Discard data in the kernel mapping for the new page
  85. * FIXME: needs this MCRR to be supported.
  86. */
  87. __asm__("mcrr p15, 0, %1, %0, c6 @ 0xec401f06"
  88. :
  89. : "r" (kaddr),
  90. "r" ((unsigned long)kaddr + PAGE_SIZE - L1_CACHE_BYTES)
  91. : "cc");
  92. /*
  93. * Now clear the page using the same cache colour as
  94. * the pages ultimate destination.
  95. */
  96. spin_lock(&v6_lock);
  97. set_pte_ext(TOP_PTE(to_address) + offset, pfn_pte(__pa(kaddr) >> PAGE_SHIFT, PAGE_KERNEL), 0);
  98. flush_tlb_kernel_page(to);
  99. clear_page((void *)to);
  100. spin_unlock(&v6_lock);
  101. }
  102. struct cpu_user_fns v6_user_fns __initdata = {
  103. .cpu_clear_user_page = v6_clear_user_page_nonaliasing,
  104. .cpu_copy_user_page = v6_copy_user_page_nonaliasing,
  105. };
  106. static int __init v6_userpage_init(void)
  107. {
  108. if (cache_is_vipt_aliasing()) {
  109. cpu_user.cpu_clear_user_page = v6_clear_user_page_aliasing;
  110. cpu_user.cpu_copy_user_page = v6_copy_user_page_aliasing;
  111. }
  112. return 0;
  113. }
  114. core_initcall(v6_userpage_init);