1 /* Flush dcache and invalidate icache when the dcache is in writeback mode
3 * Copyright (C) 2010 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public Licence
8 * as published by the Free Software Foundation; either version
9 * 2 of the Licence, or (at your option) any later version.
11 #include <linux/module.h>
13 #include <asm/cacheflush.h>
15 #include "cache-smp.h"
18 * flush_icache_page - Flush a page from the dcache and invalidate the icache
19 * @vma: The VMA the page is part of.
20 * @page: The page to be flushed.
22 * Write a page back from the dcache and invalidate the icache so that we can
23 * run code from it that we've just written into it
25 void flush_icache_page(struct vm_area_struct
*vma
, struct page
*page
)
27 unsigned long start
= page_to_phys(page
);
30 flags
= smp_lock_cache();
32 mn10300_local_dcache_flush_page(start
);
33 mn10300_local_icache_inv_page(start
);
35 smp_cache_call(SMP_IDCACHE_INV_FLUSH_RANGE
, start
, start
+ PAGE_SIZE
);
36 smp_unlock_cache(flags
);
38 EXPORT_SYMBOL(flush_icache_page
);
41 * flush_icache_page_range - Flush dcache and invalidate icache for part of a
43 * @start: The starting virtual address of the page part.
44 * @end: The ending virtual address of the page part.
46 * Flush the dcache and invalidate the icache for part of a single page, as
47 * determined by the virtual addresses given. The page must be in the paged
50 static void flush_icache_page_range(unsigned long start
, unsigned long end
)
52 unsigned long addr
, size
, off
;
59 /* work out how much of the page to flush */
60 off
= start
& ~PAGE_MASK
;
63 /* get the physical address the page is mapped to from the page
65 pgd
= pgd_offset(current
->mm
, start
);
66 if (!pgd
|| !pgd_val(*pgd
))
69 pud
= pud_offset(pgd
, start
);
70 if (!pud
|| !pud_val(*pud
))
73 pmd
= pmd_offset(pud
, start
);
74 if (!pmd
|| !pmd_val(*pmd
))
77 ppte
= pte_offset_map(pmd
, start
);
90 addr
= page_to_phys(page
);
92 /* flush the dcache and invalidate the icache coverage on that
94 mn10300_local_dcache_flush_range2(addr
+ off
, size
);
95 mn10300_local_icache_inv_range2(addr
+ off
, size
);
96 smp_cache_call(SMP_IDCACHE_INV_FLUSH_RANGE
, start
, end
);
100 * flush_icache_range - Globally flush dcache and invalidate icache for region
101 * @start: The starting virtual address of the region.
102 * @end: The ending virtual address of the region.
104 * This is used by the kernel to globally flush some code it has just written
105 * from the dcache back to RAM and then to globally invalidate the icache over
106 * that region so that that code can be run on all CPUs in the system.
108 void flush_icache_range(unsigned long start
, unsigned long end
)
110 unsigned long start_page
, end_page
;
113 flags
= smp_lock_cache();
115 if (end
> 0x80000000UL
) {
116 /* addresses above 0xa0000000 do not go through the cache */
117 if (end
> 0xa0000000UL
) {
123 /* kernel addresses between 0x80000000 and 0x9fffffff do not
124 * require page tables, so we just map such addresses
126 start_page
= (start
>= 0x80000000UL
) ? start
: 0x80000000UL
;
127 mn10300_local_dcache_flush_range(start_page
, end
);
128 mn10300_local_icache_inv_range(start_page
, end
);
129 smp_cache_call(SMP_IDCACHE_INV_FLUSH_RANGE
, start_page
, end
);
130 if (start_page
== start
)
135 start_page
= start
& PAGE_MASK
;
136 end_page
= (end
- 1) & PAGE_MASK
;
138 if (start_page
== end_page
) {
139 /* the first and last bytes are on the same page */
140 flush_icache_page_range(start
, end
);
141 } else if (start_page
+ 1 == end_page
) {
142 /* split over two virtually contiguous pages */
143 flush_icache_page_range(start
, end_page
);
144 flush_icache_page_range(end_page
, end
);
146 /* more than 2 pages; just flush the entire cache */
147 mn10300_dcache_flush();
148 mn10300_icache_inv();
149 smp_cache_call(SMP_IDCACHE_INV_FLUSH
, 0, 0);
153 smp_unlock_cache(flags
);
155 EXPORT_SYMBOL(flush_icache_range
);