copypage-v6.c 3.4 KB

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