2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* arch/sh/mm/cache-sh4.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 1999, 2000, 2002 Niibe Yutaka
|
2009-09-09 14:06:39 +07:00
|
|
|
* Copyright (C) 2001 - 2009 Paul Mundt
|
2005-04-17 05:20:36 +07:00
|
|
|
* Copyright (C) 2003 Richard Curnow
|
2008-07-02 13:17:11 +07:00
|
|
|
* Copyright (c) 2007 STMicroelectronics (R&D) Ltd.
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU General Public
|
|
|
|
* License. See the file "COPYING" in the main directory of this archive
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/mm.h>
|
2006-11-21 09:09:41 +07:00
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/mutex.h>
|
2009-07-22 17:20:49 +07:00
|
|
|
#include <linux/fs.h>
|
2009-09-09 14:06:39 +07:00
|
|
|
#include <linux/highmem.h>
|
|
|
|
#include <asm/pgtable.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <asm/mmu_context.h>
|
2012-03-30 17:29:57 +07:00
|
|
|
#include <asm/cache_insns.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <asm/cacheflush.h>
|
|
|
|
|
2006-09-27 16:30:07 +07:00
|
|
|
/*
|
|
|
|
* The maximum number of pages we support up to when doing ranged dcache
|
|
|
|
* flushing. Anything exceeding this will simply flush the dcache in its
|
|
|
|
* entirety.
|
|
|
|
*/
|
2008-07-02 13:17:11 +07:00
|
|
|
#define MAX_ICACHE_PAGES 32
|
2006-09-27 16:30:07 +07:00
|
|
|
|
2009-10-16 12:15:38 +07:00
|
|
|
static void __flush_cache_one(unsigned long addr, unsigned long phys,
|
2006-09-27 09:29:55 +07:00
|
|
|
unsigned long exec_offset);
|
2006-09-27 12:09:26 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* Write back the range of D-cache, and purge the I-cache.
|
|
|
|
*
|
2008-07-02 13:17:11 +07:00
|
|
|
* Called from kernel/module.c:sys_init_module and routine for a.out format,
|
|
|
|
* signal handler code and kprobes code
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
2010-01-21 14:05:25 +07:00
|
|
|
static void sh4_flush_icache_range(void *args)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2009-08-21 15:23:14 +07:00
|
|
|
struct flusher_data *data = args;
|
|
|
|
unsigned long start, end;
|
2009-09-01 19:12:55 +07:00
|
|
|
unsigned long flags, v;
|
2005-04-17 05:20:36 +07:00
|
|
|
int i;
|
|
|
|
|
2009-08-21 15:23:14 +07:00
|
|
|
start = data->addr1;
|
|
|
|
end = data->addr2;
|
|
|
|
|
2009-09-09 11:19:46 +07:00
|
|
|
/* If there are too many pages then just blow away the caches */
|
|
|
|
if (((end - start) >> PAGE_SHIFT) >= MAX_ICACHE_PAGES) {
|
|
|
|
local_flush_cache_all(NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Selectively flush d-cache then invalidate the i-cache.
|
|
|
|
* This is inefficient, so only use this for small ranges.
|
|
|
|
*/
|
|
|
|
start &= ~(L1_CACHE_BYTES-1);
|
|
|
|
end += L1_CACHE_BYTES-1;
|
|
|
|
end &= ~(L1_CACHE_BYTES-1);
|
2009-09-01 19:12:55 +07:00
|
|
|
|
2009-09-09 11:19:46 +07:00
|
|
|
local_irq_save(flags);
|
|
|
|
jump_to_uncached();
|
2009-09-01 19:12:55 +07:00
|
|
|
|
2009-09-09 11:19:46 +07:00
|
|
|
for (v = start; v < end; v += L1_CACHE_BYTES) {
|
|
|
|
unsigned long icacheaddr;
|
2009-11-06 06:14:39 +07:00
|
|
|
int j, n;
|
2009-09-01 19:12:55 +07:00
|
|
|
|
2009-09-09 11:19:46 +07:00
|
|
|
__ocbwb(v);
|
2009-09-01 19:12:55 +07:00
|
|
|
|
2009-09-09 11:19:46 +07:00
|
|
|
icacheaddr = CACHE_IC_ADDRESS_ARRAY | (v &
|
|
|
|
cpu_data->icache.entry_mask);
|
2008-07-02 13:17:11 +07:00
|
|
|
|
2009-09-09 11:19:46 +07:00
|
|
|
/* Clear i-cache line valid-bit */
|
2009-11-06 06:14:39 +07:00
|
|
|
n = boot_cpu_data.icache.n_aliases;
|
2009-09-09 11:19:46 +07:00
|
|
|
for (i = 0; i < cpu_data->icache.ways; i++) {
|
2009-11-06 06:14:39 +07:00
|
|
|
for (j = 0; j < n; j++)
|
|
|
|
__raw_writel(0, icacheaddr + (j * PAGE_SIZE));
|
2009-09-09 11:19:46 +07:00
|
|
|
icacheaddr += cpu_data->icache.way_incr;
|
|
|
|
}
|
2008-07-02 13:17:11 +07:00
|
|
|
}
|
2009-09-09 11:19:46 +07:00
|
|
|
|
|
|
|
back_to_cached();
|
|
|
|
local_irq_restore(flags);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2009-10-16 12:15:38 +07:00
|
|
|
static inline void flush_cache_one(unsigned long start, unsigned long phys)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2009-09-01 19:12:55 +07:00
|
|
|
unsigned long flags, exec_offset = 0;
|
2006-09-27 16:37:30 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/*
|
2009-10-07 04:22:25 +07:00
|
|
|
* All types of SH-4 require PC to be uncached to operate on the I-cache.
|
|
|
|
* Some types of SH-4 require PC to be uncached to operate on the D-cache.
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
2007-09-21 16:05:20 +07:00
|
|
|
if ((boot_cpu_data.flags & CPU_HAS_P2_FLUSH_BUG) ||
|
2006-09-27 16:37:30 +07:00
|
|
|
(start < CACHE_OC_ADDRESS_ARRAY))
|
2009-10-07 04:22:25 +07:00
|
|
|
exec_offset = cached_to_uncached;
|
2006-09-27 16:37:30 +07:00
|
|
|
|
2009-09-01 19:12:55 +07:00
|
|
|
local_irq_save(flags);
|
2009-12-04 14:18:11 +07:00
|
|
|
__flush_cache_one(start, phys, exec_offset);
|
2009-09-01 19:12:55 +07:00
|
|
|
local_irq_restore(flags);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write back & invalidate the D-cache of the page.
|
|
|
|
* (To avoid "alias" issues)
|
|
|
|
*/
|
2009-08-27 09:31:16 +07:00
|
|
|
static void sh4_flush_dcache_page(void *arg)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2009-08-27 09:31:16 +07:00
|
|
|
struct page *page = arg;
|
2009-12-25 05:17:35 +07:00
|
|
|
unsigned long addr = (unsigned long)page_address(page);
|
2009-08-20 13:24:41 +07:00
|
|
|
#ifndef CONFIG_SMP
|
mm: fix races between swapoff and flush dcache
Thanks to commit 4b3ef9daa4fc ("mm/swap: split swap cache into 64MB
trunks"), after swapoff the address_space associated with the swap
device will be freed. So page_mapping() users which may touch the
address_space need some kind of mechanism to prevent the address_space
from being freed during accessing.
The dcache flushing functions (flush_dcache_page(), etc) in architecture
specific code may access the address_space of swap device for anonymous
pages in swap cache via page_mapping() function. But in some cases
there are no mechanisms to prevent the swap device from being swapoff,
for example,
CPU1 CPU2
__get_user_pages() swapoff()
flush_dcache_page()
mapping = page_mapping()
... exit_swap_address_space()
... kvfree(spaces)
mapping_mapped(mapping)
The address space may be accessed after being freed.
But from cachetlb.txt and Russell King, flush_dcache_page() only care
about file cache pages, for anonymous pages, flush_anon_page() should be
used. The implementation of flush_dcache_page() in all architectures
follows this too. They will check whether page_mapping() is NULL and
whether mapping_mapped() is true to determine whether to flush the
dcache immediately. And they will use interval tree (mapping->i_mmap)
to find all user space mappings. While mapping_mapped() and
mapping->i_mmap isn't used by anonymous pages in swap cache at all.
So, to fix the race between swapoff and flush dcache, __page_mapping()
is add to return the address_space for file cache pages and NULL
otherwise. All page_mapping() invoking in flush dcache functions are
replaced with page_mapping_file().
[akpm@linux-foundation.org: simplify page_mapping_file(), per Mike]
Link: http://lkml.kernel.org/r/20180305083634.15174-1-ying.huang@intel.com
Signed-off-by: "Huang, Ying" <ying.huang@intel.com>
Reviewed-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Mel Gorman <mgorman@techsingularity.net>
Cc: Dave Hansen <dave.hansen@intel.com>
Cc: Chen Liqin <liqin.linux@gmail.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Cc: "James E.J. Bottomley" <jejb@parisc-linux.org>
Cc: Guan Xuetao <gxt@mprc.pku.edu.cn>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Chris Zankel <chris@zankel.net>
Cc: Vineet Gupta <vgupta@synopsys.com>
Cc: Ley Foon Tan <lftan@altera.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Mike Rapoport <rppt@linux.vnet.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-04-06 06:24:39 +07:00
|
|
|
struct address_space *mapping = page_mapping_file(page);
|
2009-07-22 17:20:49 +07:00
|
|
|
|
|
|
|
if (mapping && !mapping_mapped(mapping))
|
2010-12-01 13:39:51 +07:00
|
|
|
clear_bit(PG_dcache_clean, &page->flags);
|
2009-07-22 17:20:49 +07:00
|
|
|
else
|
|
|
|
#endif
|
2009-12-25 05:17:35 +07:00
|
|
|
flush_cache_one(CACHE_OC_ADDRESS_ARRAY |
|
|
|
|
(addr & shm_align_mask), page_to_phys(page));
|
2006-09-27 12:05:52 +07:00
|
|
|
|
|
|
|
wmb();
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2006-09-27 16:30:07 +07:00
|
|
|
/* TODO: Selective icache invalidation through IC address array.. */
|
2010-01-21 14:05:25 +07:00
|
|
|
static void flush_icache_all(void)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2009-09-01 19:12:55 +07:00
|
|
|
unsigned long flags, ccr;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2009-09-01 19:12:55 +07:00
|
|
|
local_irq_save(flags);
|
2007-11-30 15:06:36 +07:00
|
|
|
jump_to_uncached();
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* Flush I-cache */
|
2014-03-04 06:38:33 +07:00
|
|
|
ccr = __raw_readl(SH_CCR);
|
2005-04-17 05:20:36 +07:00
|
|
|
ccr |= CCR_CACHE_ICI;
|
2014-03-04 06:38:33 +07:00
|
|
|
__raw_writel(ccr, SH_CCR);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2006-09-27 12:57:44 +07:00
|
|
|
/*
|
2007-11-30 15:06:36 +07:00
|
|
|
* back_to_cached() will take care of the barrier for us, don't add
|
2006-09-27 12:57:44 +07:00
|
|
|
* another one!
|
|
|
|
*/
|
2009-09-01 19:12:55 +07:00
|
|
|
|
2007-11-30 15:06:36 +07:00
|
|
|
back_to_cached();
|
2009-09-01 19:12:55 +07:00
|
|
|
local_irq_restore(flags);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2009-09-09 12:22:15 +07:00
|
|
|
static void flush_dcache_all(void)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2009-09-09 12:22:15 +07:00
|
|
|
unsigned long addr, end_addr, entry_offset;
|
|
|
|
|
|
|
|
end_addr = CACHE_OC_ADDRESS_ARRAY +
|
|
|
|
(current_cpu_data.dcache.sets <<
|
|
|
|
current_cpu_data.dcache.entry_shift) *
|
|
|
|
current_cpu_data.dcache.ways;
|
|
|
|
|
|
|
|
entry_offset = 1 << current_cpu_data.dcache.entry_shift;
|
|
|
|
|
|
|
|
for (addr = CACHE_OC_ADDRESS_ARRAY; addr < end_addr; ) {
|
|
|
|
__raw_writel(0, addr); addr += entry_offset;
|
|
|
|
__raw_writel(0, addr); addr += entry_offset;
|
|
|
|
__raw_writel(0, addr); addr += entry_offset;
|
|
|
|
__raw_writel(0, addr); addr += entry_offset;
|
|
|
|
__raw_writel(0, addr); addr += entry_offset;
|
|
|
|
__raw_writel(0, addr); addr += entry_offset;
|
|
|
|
__raw_writel(0, addr); addr += entry_offset;
|
|
|
|
__raw_writel(0, addr); addr += entry_offset;
|
|
|
|
}
|
2006-09-27 09:29:55 +07:00
|
|
|
}
|
|
|
|
|
2009-08-21 15:23:14 +07:00
|
|
|
static void sh4_flush_cache_all(void *unused)
|
2006-09-27 09:29:55 +07:00
|
|
|
{
|
|
|
|
flush_dcache_all();
|
2005-04-17 05:20:36 +07:00
|
|
|
flush_icache_all();
|
|
|
|
}
|
|
|
|
|
2006-09-27 16:30:07 +07:00
|
|
|
/*
|
|
|
|
* Note : (RPC) since the caches are physically tagged, the only point
|
|
|
|
* of flush_cache_mm for SH-4 is to get rid of aliases from the
|
|
|
|
* D-cache. The assumption elsewhere, e.g. flush_cache_range, is that
|
|
|
|
* lines can stay resident so long as the virtual address they were
|
|
|
|
* accessed with (hence cache set) is in accord with the physical
|
sh: sh4_flush_cache_mm() optimizations.
The i-cache flush in the case of VM_EXEC was added way back when as a
sanity measure, and in practice we only care about evicting aliases from
the d-cache. As a result, it's possible to drop the i-cache flush
completely here.
After careful profiling it's also come up that all of the work associated
with hunting down aliases and doing ranged flushing ends up generating
more overhead than simply blasting away the entire dcache, particularly
if there are many mm's that need to be iterated over. As a result of
that, just move back to flush_dcache_all() in these cases, which restores
the old behaviour, and vastly simplifies the path.
Additionally, on platforms without aliases at all, this can simply be
nopped out. Presently we have the alias check in the SH-4 specific
version, but this is true for all of the platforms, so move the check up
to a generic location. This cuts down quite a bit on superfluous cacheop
IPIs.
Signed-off-by: Paul Mundt <lethal@linux-sh.org>
2009-09-09 12:04:06 +07:00
|
|
|
* address (i.e. tag). It's no different here.
|
2006-09-27 16:30:07 +07:00
|
|
|
*
|
|
|
|
* Caller takes mm->mmap_sem.
|
|
|
|
*/
|
2009-08-21 15:23:14 +07:00
|
|
|
static void sh4_flush_cache_mm(void *arg)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2009-08-21 15:23:14 +07:00
|
|
|
struct mm_struct *mm = arg;
|
|
|
|
|
2009-08-15 00:21:16 +07:00
|
|
|
if (cpu_context(smp_processor_id(), mm) == NO_CONTEXT)
|
|
|
|
return;
|
|
|
|
|
sh: sh4_flush_cache_mm() optimizations.
The i-cache flush in the case of VM_EXEC was added way back when as a
sanity measure, and in practice we only care about evicting aliases from
the d-cache. As a result, it's possible to drop the i-cache flush
completely here.
After careful profiling it's also come up that all of the work associated
with hunting down aliases and doing ranged flushing ends up generating
more overhead than simply blasting away the entire dcache, particularly
if there are many mm's that need to be iterated over. As a result of
that, just move back to flush_dcache_all() in these cases, which restores
the old behaviour, and vastly simplifies the path.
Additionally, on platforms without aliases at all, this can simply be
nopped out. Presently we have the alias check in the SH-4 specific
version, but this is true for all of the platforms, so move the check up
to a generic location. This cuts down quite a bit on superfluous cacheop
IPIs.
Signed-off-by: Paul Mundt <lethal@linux-sh.org>
2009-09-09 12:04:06 +07:00
|
|
|
flush_dcache_all();
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write back and invalidate I/D-caches for the page.
|
|
|
|
*
|
|
|
|
* ADDR: Virtual Address (U0 address)
|
|
|
|
* PFN: Physical page number
|
|
|
|
*/
|
2009-08-21 15:23:14 +07:00
|
|
|
static void sh4_flush_cache_page(void *args)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2009-08-21 15:23:14 +07:00
|
|
|
struct flusher_data *data = args;
|
|
|
|
struct vm_area_struct *vma;
|
2009-09-09 14:06:39 +07:00
|
|
|
struct page *page;
|
2009-08-21 15:23:14 +07:00
|
|
|
unsigned long address, pfn, phys;
|
2009-09-09 14:06:39 +07:00
|
|
|
int map_coherent = 0;
|
|
|
|
pgd_t *pgd;
|
|
|
|
pud_t *pud;
|
|
|
|
pmd_t *pmd;
|
|
|
|
pte_t *pte;
|
|
|
|
void *vaddr;
|
2006-09-27 12:09:26 +07:00
|
|
|
|
2009-08-21 15:23:14 +07:00
|
|
|
vma = data->vma;
|
2009-10-16 13:14:50 +07:00
|
|
|
address = data->addr1 & PAGE_MASK;
|
2009-08-21 15:23:14 +07:00
|
|
|
pfn = data->addr2;
|
|
|
|
phys = pfn << PAGE_SHIFT;
|
2009-09-09 14:06:39 +07:00
|
|
|
page = pfn_to_page(pfn);
|
2009-08-21 15:23:14 +07:00
|
|
|
|
2009-08-15 00:21:16 +07:00
|
|
|
if (cpu_context(smp_processor_id(), vma->vm_mm) == NO_CONTEXT)
|
|
|
|
return;
|
|
|
|
|
2009-09-09 14:06:39 +07:00
|
|
|
pgd = pgd_offset(vma->vm_mm, address);
|
|
|
|
pud = pud_offset(pgd, address);
|
|
|
|
pmd = pmd_offset(pud, address);
|
|
|
|
pte = pte_offset_kernel(pmd, address);
|
|
|
|
|
|
|
|
/* If the page isn't present, there is nothing to do here. */
|
|
|
|
if (!(pte_val(*pte) & _PAGE_PRESENT))
|
|
|
|
return;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2009-09-09 14:06:39 +07:00
|
|
|
if ((vma->vm_mm == current->active_mm))
|
|
|
|
vaddr = NULL;
|
|
|
|
else {
|
2006-09-27 12:09:26 +07:00
|
|
|
/*
|
2009-09-09 14:06:39 +07:00
|
|
|
* Use kmap_coherent or kmap_atomic to do flushes for
|
|
|
|
* another ASID than the current one.
|
2006-09-27 12:09:26 +07:00
|
|
|
*/
|
2009-09-09 14:06:39 +07:00
|
|
|
map_coherent = (current_cpu_data.dcache.n_aliases &&
|
2010-12-01 13:39:51 +07:00
|
|
|
test_bit(PG_dcache_clean, &page->flags) &&
|
2016-01-16 07:53:46 +07:00
|
|
|
page_mapcount(page));
|
2009-09-09 14:06:39 +07:00
|
|
|
if (map_coherent)
|
|
|
|
vaddr = kmap_coherent(page, address);
|
|
|
|
else
|
2011-11-25 22:14:16 +07:00
|
|
|
vaddr = kmap_atomic(page);
|
2009-09-09 14:06:39 +07:00
|
|
|
|
|
|
|
address = (unsigned long)vaddr;
|
|
|
|
}
|
|
|
|
|
2009-12-08 21:23:11 +07:00
|
|
|
flush_cache_one(CACHE_OC_ADDRESS_ARRAY |
|
2009-09-09 14:06:39 +07:00
|
|
|
(address & shm_align_mask), phys);
|
|
|
|
|
|
|
|
if (vma->vm_flags & VM_EXEC)
|
|
|
|
flush_icache_all();
|
|
|
|
|
|
|
|
if (vaddr) {
|
|
|
|
if (map_coherent)
|
|
|
|
kunmap_coherent(vaddr);
|
|
|
|
else
|
2011-11-25 22:14:16 +07:00
|
|
|
kunmap_atomic(vaddr);
|
2006-09-27 12:09:26 +07:00
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write back and invalidate D-caches.
|
|
|
|
*
|
|
|
|
* START, END: Virtual Address (U0 address)
|
|
|
|
*
|
|
|
|
* NOTE: We need to flush the _physical_ page entry.
|
|
|
|
* Flushing the cache lines for U0 only isn't enough.
|
|
|
|
* We need to flush for P1 too, which may contain aliases.
|
|
|
|
*/
|
2009-08-21 15:23:14 +07:00
|
|
|
static void sh4_flush_cache_range(void *args)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2009-08-21 15:23:14 +07:00
|
|
|
struct flusher_data *data = args;
|
|
|
|
struct vm_area_struct *vma;
|
|
|
|
unsigned long start, end;
|
|
|
|
|
|
|
|
vma = data->vma;
|
|
|
|
start = data->addr1;
|
|
|
|
end = data->addr2;
|
|
|
|
|
2009-08-15 00:21:16 +07:00
|
|
|
if (cpu_context(smp_processor_id(), vma->vm_mm) == NO_CONTEXT)
|
|
|
|
return;
|
|
|
|
|
2006-09-27 12:09:26 +07:00
|
|
|
/*
|
|
|
|
* If cache is only 4k-per-way, there are never any 'aliases'. Since
|
|
|
|
* the cache is physically tagged, the data can just be left in there.
|
|
|
|
*/
|
2007-09-21 16:05:20 +07:00
|
|
|
if (boot_cpu_data.dcache.n_aliases == 0)
|
2006-09-27 12:09:26 +07:00
|
|
|
return;
|
|
|
|
|
sh: sh4_flush_cache_mm() optimizations.
The i-cache flush in the case of VM_EXEC was added way back when as a
sanity measure, and in practice we only care about evicting aliases from
the d-cache. As a result, it's possible to drop the i-cache flush
completely here.
After careful profiling it's also come up that all of the work associated
with hunting down aliases and doing ranged flushing ends up generating
more overhead than simply blasting away the entire dcache, particularly
if there are many mm's that need to be iterated over. As a result of
that, just move back to flush_dcache_all() in these cases, which restores
the old behaviour, and vastly simplifies the path.
Additionally, on platforms without aliases at all, this can simply be
nopped out. Presently we have the alias check in the SH-4 specific
version, but this is true for all of the platforms, so move the check up
to a generic location. This cuts down quite a bit on superfluous cacheop
IPIs.
Signed-off-by: Paul Mundt <lethal@linux-sh.org>
2009-09-09 12:04:06 +07:00
|
|
|
flush_dcache_all();
|
2006-09-27 12:09:26 +07:00
|
|
|
|
sh: sh4_flush_cache_mm() optimizations.
The i-cache flush in the case of VM_EXEC was added way back when as a
sanity measure, and in practice we only care about evicting aliases from
the d-cache. As a result, it's possible to drop the i-cache flush
completely here.
After careful profiling it's also come up that all of the work associated
with hunting down aliases and doing ranged flushing ends up generating
more overhead than simply blasting away the entire dcache, particularly
if there are many mm's that need to be iterated over. As a result of
that, just move back to flush_dcache_all() in these cases, which restores
the old behaviour, and vastly simplifies the path.
Additionally, on platforms without aliases at all, this can simply be
nopped out. Presently we have the alias check in the SH-4 specific
version, but this is true for all of the platforms, so move the check up
to a generic location. This cuts down quite a bit on superfluous cacheop
IPIs.
Signed-off-by: Paul Mundt <lethal@linux-sh.org>
2009-09-09 12:04:06 +07:00
|
|
|
if (vma->vm_flags & VM_EXEC)
|
2005-04-17 05:20:36 +07:00
|
|
|
flush_icache_all();
|
|
|
|
}
|
|
|
|
|
2006-09-27 12:09:26 +07:00
|
|
|
/**
|
2009-10-16 12:15:38 +07:00
|
|
|
* __flush_cache_one
|
2006-09-27 12:09:26 +07:00
|
|
|
*
|
|
|
|
* @addr: address in memory mapped cache array
|
|
|
|
* @phys: P1 address to flush (has to match tags if addr has 'A' bit
|
|
|
|
* set i.e. associative write)
|
|
|
|
* @exec_offset: set to 0x20000000 if flush has to be executed from P2
|
|
|
|
* region else 0x0
|
|
|
|
*
|
|
|
|
* The offset into the cache array implied by 'addr' selects the
|
|
|
|
* 'colour' of the virtual address range that will be flushed. The
|
|
|
|
* operation (purge/write-back) is selected by the lower 2 bits of
|
|
|
|
* 'phys'.
|
|
|
|
*/
|
2009-10-16 12:15:38 +07:00
|
|
|
static void __flush_cache_one(unsigned long addr, unsigned long phys,
|
2006-09-27 12:09:26 +07:00
|
|
|
unsigned long exec_offset)
|
|
|
|
{
|
|
|
|
int way_count;
|
|
|
|
unsigned long base_addr = addr;
|
|
|
|
struct cache_info *dcache;
|
|
|
|
unsigned long way_incr;
|
|
|
|
unsigned long a, ea, p;
|
|
|
|
unsigned long temp_pc;
|
|
|
|
|
2007-09-21 16:05:20 +07:00
|
|
|
dcache = &boot_cpu_data.dcache;
|
2006-09-27 12:09:26 +07:00
|
|
|
/* Write this way for better assembly. */
|
|
|
|
way_count = dcache->ways;
|
|
|
|
way_incr = dcache->way_incr;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Apply exec_offset (i.e. branch to P2 if required.).
|
|
|
|
*
|
|
|
|
* FIXME:
|
|
|
|
*
|
|
|
|
* If I write "=r" for the (temp_pc), it puts this in r6 hence
|
|
|
|
* trashing exec_offset before it's been added on - why? Hence
|
|
|
|
* "=&r" as a 'workaround'
|
|
|
|
*/
|
|
|
|
asm volatile("mov.l 1f, %0\n\t"
|
|
|
|
"add %1, %0\n\t"
|
|
|
|
"jmp @%0\n\t"
|
|
|
|
"nop\n\t"
|
|
|
|
".balign 4\n\t"
|
|
|
|
"1: .long 2f\n\t"
|
|
|
|
"2:\n" : "=&r" (temp_pc) : "r" (exec_offset));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We know there will be >=1 iteration, so write as do-while to avoid
|
|
|
|
* pointless nead-of-loop check for 0 iterations.
|
|
|
|
*/
|
|
|
|
do {
|
|
|
|
ea = base_addr + PAGE_SIZE;
|
|
|
|
a = base_addr;
|
|
|
|
p = phys;
|
|
|
|
|
|
|
|
do {
|
|
|
|
*(volatile unsigned long *)a = p;
|
|
|
|
/*
|
|
|
|
* Next line: intentionally not p+32, saves an add, p
|
|
|
|
* will do since only the cache tag bits need to
|
|
|
|
* match.
|
|
|
|
*/
|
|
|
|
*(volatile unsigned long *)(a+32) = p;
|
|
|
|
a += 64;
|
|
|
|
p += 64;
|
|
|
|
} while (a < ea);
|
|
|
|
|
|
|
|
base_addr += way_incr;
|
|
|
|
} while (--way_count != 0);
|
|
|
|
}
|
|
|
|
|
2009-08-15 10:29:49 +07:00
|
|
|
extern void __weak sh4__flush_region_init(void);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SH-4 has virtually indexed and physically tagged cache.
|
|
|
|
*/
|
|
|
|
void __init sh4_cache_init(void)
|
|
|
|
{
|
|
|
|
printk("PVR=%08x CVR=%08x PRR=%08x\n",
|
2010-01-26 10:58:40 +07:00
|
|
|
__raw_readl(CCN_PVR),
|
|
|
|
__raw_readl(CCN_CVR),
|
|
|
|
__raw_readl(CCN_PRR));
|
2009-08-15 10:29:49 +07:00
|
|
|
|
2009-08-21 15:23:14 +07:00
|
|
|
local_flush_icache_range = sh4_flush_icache_range;
|
|
|
|
local_flush_dcache_page = sh4_flush_dcache_page;
|
|
|
|
local_flush_cache_all = sh4_flush_cache_all;
|
|
|
|
local_flush_cache_mm = sh4_flush_cache_mm;
|
|
|
|
local_flush_cache_dup_mm = sh4_flush_cache_mm;
|
|
|
|
local_flush_cache_page = sh4_flush_cache_page;
|
|
|
|
local_flush_cache_range = sh4_flush_cache_range;
|
2009-08-15 10:29:49 +07:00
|
|
|
|
|
|
|
sh4__flush_region_init();
|
|
|
|
}
|