copypage-v6.c 3.5 KB

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