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. #if SHMLBA > 16384
  19. #error FIX ME
  20. #endif
  21. #define from_address (0xffff8000)
  22. #define from_pgprot PAGE_KERNEL
  23. #define to_address (0xffffc000)
  24. #define to_pgprot PAGE_KERNEL
  25. #define TOP_PTE(x) pte_offset_kernel(top_pmd, x)
  26. static DEFINE_SPINLOCK(v6_lock);
  27. #define DCACHE_COLOUR(vaddr) ((vaddr & (SHMLBA - 1)) >> PAGE_SHIFT)
  28. /*
  29. * Copy the user page. No aliasing to deal with so we can just
  30. * attack the kernel's existing mapping of these pages.
  31. */
  32. void v6_copy_user_page_nonaliasing(void *kto, const void *kfrom, unsigned long vaddr)
  33. {
  34. copy_page(kto, kfrom);
  35. }
  36. /*
  37. * Clear the user page. No aliasing to deal with so we can just
  38. * attack the kernel's existing mapping of this page.
  39. */
  40. void v6_clear_user_page_nonaliasing(void *kaddr, unsigned long vaddr)
  41. {
  42. clear_page(kaddr);
  43. }
  44. /*
  45. * Copy the page, taking account of the cache colour.
  46. */
  47. void v6_copy_user_page_aliasing(void *kto, const void *kfrom, unsigned long vaddr)
  48. {
  49. unsigned int offset = DCACHE_COLOUR(vaddr);
  50. unsigned long from, to;
  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(TOP_PTE(from_address) + offset, pfn_pte(__pa(kfrom) >> PAGE_SHIFT, from_pgprot));
  66. set_pte(TOP_PTE(to_address) + offset, pfn_pte(__pa(kto) >> PAGE_SHIFT, to_pgprot));
  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. void v6_clear_user_page_aliasing(void *kaddr, unsigned long vaddr)
  80. {
  81. unsigned int offset = DCACHE_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(TOP_PTE(to_address) + offset, pfn_pte(__pa(kaddr) >> PAGE_SHIFT, to_pgprot));
  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);