flush.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * Based on arch/arm/mm/flush.c
  3. *
  4. * Copyright (C) 1995-2002 Russell King
  5. * Copyright (C) 2012 ARM Ltd.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <linux/export.h>
  20. #include <linux/mm.h>
  21. #include <linux/pagemap.h>
  22. #include <asm/cacheflush.h>
  23. #include <asm/cachetype.h>
  24. #include <asm/tlbflush.h>
  25. #include "mm.h"
  26. void flush_cache_mm(struct mm_struct *mm)
  27. {
  28. }
  29. void flush_cache_range(struct vm_area_struct *vma, unsigned long start,
  30. unsigned long end)
  31. {
  32. if (vma->vm_flags & VM_EXEC)
  33. __flush_icache_all();
  34. }
  35. void flush_cache_page(struct vm_area_struct *vma, unsigned long user_addr,
  36. unsigned long pfn)
  37. {
  38. }
  39. static void flush_ptrace_access(struct vm_area_struct *vma, struct page *page,
  40. unsigned long uaddr, void *kaddr,
  41. unsigned long len)
  42. {
  43. if (vma->vm_flags & VM_EXEC) {
  44. unsigned long addr = (unsigned long)kaddr;
  45. if (icache_is_aliasing()) {
  46. __flush_dcache_area(kaddr, len);
  47. __flush_icache_all();
  48. } else {
  49. flush_icache_range(addr, addr + len);
  50. }
  51. }
  52. }
  53. /*
  54. * Copy user data from/to a page which is mapped into a different processes
  55. * address space. Really, we want to allow our "user space" model to handle
  56. * this.
  57. *
  58. * Note that this code needs to run on the current CPU.
  59. */
  60. void copy_to_user_page(struct vm_area_struct *vma, struct page *page,
  61. unsigned long uaddr, void *dst, const void *src,
  62. unsigned long len)
  63. {
  64. #ifdef CONFIG_SMP
  65. preempt_disable();
  66. #endif
  67. memcpy(dst, src, len);
  68. flush_ptrace_access(vma, page, uaddr, dst, len);
  69. #ifdef CONFIG_SMP
  70. preempt_enable();
  71. #endif
  72. }
  73. void __flush_dcache_page(struct page *page)
  74. {
  75. __flush_dcache_area(page_address(page), PAGE_SIZE);
  76. }
  77. void __sync_icache_dcache(pte_t pte, unsigned long addr)
  78. {
  79. unsigned long pfn;
  80. struct page *page;
  81. pfn = pte_pfn(pte);
  82. if (!pfn_valid(pfn))
  83. return;
  84. page = pfn_to_page(pfn);
  85. if (!test_and_set_bit(PG_dcache_clean, &page->flags)) {
  86. __flush_dcache_page(page);
  87. __flush_icache_all();
  88. } else if (icache_is_aivivt()) {
  89. __flush_icache_all();
  90. }
  91. }
  92. /*
  93. * Ensure cache coherency between kernel mapping and userspace mapping of this
  94. * page.
  95. */
  96. void flush_dcache_page(struct page *page)
  97. {
  98. struct address_space *mapping;
  99. /*
  100. * The zero page is never written to, so never has any dirty cache
  101. * lines, and therefore never needs to be flushed.
  102. */
  103. if (page == ZERO_PAGE(0))
  104. return;
  105. mapping = page_mapping(page);
  106. if (mapping && mapping_mapped(mapping)) {
  107. __flush_dcache_page(page);
  108. __flush_icache_all();
  109. set_bit(PG_dcache_clean, &page->flags);
  110. } else {
  111. clear_bit(PG_dcache_clean, &page->flags);
  112. }
  113. }
  114. EXPORT_SYMBOL(flush_dcache_page);
  115. /*
  116. * Additional functions defined in assembly.
  117. */
  118. EXPORT_SYMBOL(flush_cache_all);
  119. EXPORT_SYMBOL(flush_icache_range);