2 * Based on arch/arm/mm/flush.c
4 * Copyright (C) 1995-2002 Russell King
5 * Copyright (C) 2012 ARM Ltd.
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.
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.
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/>.
20 #include <linux/export.h>
22 #include <linux/pagemap.h>
24 #include <asm/cacheflush.h>
25 #include <asm/cachetype.h>
26 #include <asm/tlbflush.h>
30 void flush_cache_mm(struct mm_struct *mm)
34 void flush_cache_range(struct vm_area_struct *vma, unsigned long start,
37 if (vma->vm_flags & VM_EXEC)
41 void flush_cache_page(struct vm_area_struct *vma, unsigned long user_addr,
46 static void flush_ptrace_access(struct vm_area_struct *vma, struct page *page,
47 unsigned long uaddr, void *kaddr,
50 if (vma->vm_flags & VM_EXEC) {
51 unsigned long addr = (unsigned long)kaddr;
52 if (icache_is_aliasing()) {
53 __flush_dcache_area(kaddr, len);
56 flush_icache_range(addr, addr + len);
62 * Copy user data from/to a page which is mapped into a different processes
63 * address space. Really, we want to allow our "user space" model to handle
66 * Note that this code needs to run on the current CPU.
68 void copy_to_user_page(struct vm_area_struct *vma, struct page *page,
69 unsigned long uaddr, void *dst, const void *src,
75 memcpy(dst, src, len);
76 flush_ptrace_access(vma, page, uaddr, dst, len);
82 void __flush_dcache_page(struct page *page)
84 __flush_dcache_area(page_address(page), PAGE_SIZE);
87 void __sync_icache_dcache(pte_t pte, unsigned long addr)
96 page = pfn_to_page(pfn);
97 if (!test_and_set_bit(PG_dcache_clean, &page->flags)) {
98 __flush_dcache_page(page);
100 } else if (icache_is_aivivt()) {
101 __flush_icache_all();
106 * Ensure cache coherency between kernel mapping and userspace mapping of this
109 void flush_dcache_page(struct page *page)
111 struct address_space *mapping;
114 * The zero page is never written to, so never has any dirty cache
115 * lines, and therefore never needs to be flushed.
117 if (page == ZERO_PAGE(0))
120 mapping = page_mapping(page);
121 if (mapping && mapping_mapped(mapping)) {
122 __flush_dcache_page(page);
123 __flush_icache_all();
124 set_bit(PG_dcache_clean, &page->flags);
126 clear_bit(PG_dcache_clean, &page->flags);
129 EXPORT_SYMBOL(flush_dcache_page);
132 * Additional functions defined in assembly.
134 EXPORT_SYMBOL(flush_cache_all);
135 EXPORT_SYMBOL(flush_icache_range);