2005-04-16 15:20:36 -07:00
|
|
|
/*
|
|
|
|
* arch/sh/mm/cache-sh4.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 1999, 2000, 2002 Niibe Yutaka
|
2007-09-24 00:38:25 -07:00
|
|
|
* Copyright (C) 2001 - 2007 Paul Mundt
|
2005-04-16 15:20:36 -07:00
|
|
|
* Copyright (C) 2003 Richard Curnow
|
2008-07-01 23:17:11 -07:00
|
|
|
* Copyright (c) 2007 STMicroelectronics (R&D) Ltd.
|
2005-04-16 15: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-20 19:09:41 -07:00
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/mutex.h>
|
2009-07-22 03:20:49 -07:00
|
|
|
#include <linux/fs.h>
|
2005-04-16 15:20:36 -07:00
|
|
|
#include <asm/mmu_context.h>
|
|
|
|
#include <asm/cacheflush.h>
|
|
|
|
|
2006-09-27 02: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.
|
|
|
|
*/
|
|
|
|
#define MAX_DCACHE_PAGES 64 /* XXX: Tune for ways */
|
2008-07-01 23:17:11 -07:00
|
|
|
#define MAX_ICACHE_PAGES 32
|
2006-09-27 02:30:07 -07:00
|
|
|
|
2006-09-26 22:09:26 -07:00
|
|
|
static void __flush_cache_4096(unsigned long addr, unsigned long phys,
|
2006-09-26 19:29:55 -07:00
|
|
|
unsigned long exec_offset);
|
2006-09-26 22:09:26 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This is initialised here to ensure that it is not placed in the BSS. If
|
|
|
|
* that were to happen, note that cache_init gets called before the BSS is
|
|
|
|
* cleared, so this would get nulled out which would be hopeless.
|
|
|
|
*/
|
|
|
|
static void (*__flush_dcache_segment_fn)(unsigned long, unsigned long) =
|
|
|
|
(void (*)(unsigned long, unsigned long))0xdeadbeef;
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
/*
|
|
|
|
* Write back the range of D-cache, and purge the I-cache.
|
|
|
|
*
|
2008-07-01 23: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-16 15:20:36 -07:00
|
|
|
*/
|
2009-08-21 01:23:14 -07:00
|
|
|
static void sh4_flush_icache_range(void *args)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2009-08-21 01:23:14 -07:00
|
|
|
struct flusher_data *data = args;
|
|
|
|
unsigned long start, end;
|
2009-09-01 05:12:55 -07:00
|
|
|
unsigned long flags, v;
|
2005-04-16 15:20:36 -07:00
|
|
|
int i;
|
|
|
|
|
2009-08-21 01:23:14 -07:00
|
|
|
start = data->addr1;
|
|
|
|
end = data->addr2;
|
|
|
|
|
2009-09-08 21: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 05:12:55 -07:00
|
|
|
|
2009-09-08 21:19:46 -07:00
|
|
|
local_irq_save(flags);
|
|
|
|
jump_to_uncached();
|
2009-09-01 05:12:55 -07:00
|
|
|
|
2009-09-08 21:19:46 -07:00
|
|
|
for (v = start; v < end; v += L1_CACHE_BYTES) {
|
|
|
|
unsigned long icacheaddr;
|
2009-09-01 05:12:55 -07:00
|
|
|
|
2009-09-08 21:19:46 -07:00
|
|
|
__ocbwb(v);
|
2009-09-01 05:12:55 -07:00
|
|
|
|
2009-09-08 21:19:46 -07:00
|
|
|
icacheaddr = CACHE_IC_ADDRESS_ARRAY | (v &
|
|
|
|
cpu_data->icache.entry_mask);
|
2008-07-01 23:17:11 -07:00
|
|
|
|
2009-09-08 21:19:46 -07:00
|
|
|
/* Clear i-cache line valid-bit */
|
|
|
|
for (i = 0; i < cpu_data->icache.ways; i++) {
|
|
|
|
__raw_writel(0, icacheaddr);
|
|
|
|
icacheaddr += cpu_data->icache.way_incr;
|
|
|
|
}
|
2008-07-01 23:17:11 -07:00
|
|
|
}
|
2009-09-08 21:19:46 -07:00
|
|
|
|
|
|
|
back_to_cached();
|
|
|
|
local_irq_restore(flags);
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void flush_cache_4096(unsigned long start,
|
|
|
|
unsigned long phys)
|
|
|
|
{
|
2009-09-01 05:12:55 -07:00
|
|
|
unsigned long flags, exec_offset = 0;
|
2006-09-27 02:37:30 -07:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
/*
|
2006-09-26 22:09:26 -07:00
|
|
|
* All types of SH-4 require PC to be in P2 to operate on the I-cache.
|
|
|
|
* Some types of SH-4 require PC to be in P2 to operate on the D-cache.
|
2005-04-16 15:20:36 -07:00
|
|
|
*/
|
2007-09-21 02:05:20 -07:00
|
|
|
if ((boot_cpu_data.flags & CPU_HAS_P2_FLUSH_BUG) ||
|
2006-09-27 02:37:30 -07:00
|
|
|
(start < CACHE_OC_ADDRESS_ARRAY))
|
2006-11-26 20:06:26 -07:00
|
|
|
exec_offset = 0x20000000;
|
2006-09-27 02:37:30 -07:00
|
|
|
|
2009-09-01 05:12:55 -07:00
|
|
|
local_irq_save(flags);
|
2006-09-27 02:37:30 -07:00
|
|
|
__flush_cache_4096(start | SH_CACHE_ASSOC,
|
|
|
|
P1SEGADDR(phys), exec_offset);
|
2009-09-01 05:12:55 -07:00
|
|
|
local_irq_restore(flags);
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write back & invalidate the D-cache of the page.
|
|
|
|
* (To avoid "alias" issues)
|
|
|
|
*/
|
2009-08-26 19:31:16 -07:00
|
|
|
static void sh4_flush_dcache_page(void *arg)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2009-08-26 19:31:16 -07:00
|
|
|
struct page *page = arg;
|
2009-08-19 23:24:41 -07:00
|
|
|
#ifndef CONFIG_SMP
|
2009-07-22 03:20:49 -07:00
|
|
|
struct address_space *mapping = page_mapping(page);
|
|
|
|
|
|
|
|
if (mapping && !mapping_mapped(mapping))
|
|
|
|
set_bit(PG_dcache_dirty, &page->flags);
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
2009-09-08 22:10:28 -07:00
|
|
|
unsigned long phys = page_to_phys(page);
|
2006-09-26 22:09:26 -07:00
|
|
|
unsigned long addr = CACHE_OC_ADDRESS_ARRAY;
|
|
|
|
int i, n;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
/* Loop all the D-cache */
|
2009-09-08 22:10:28 -07:00
|
|
|
n = boot_cpu_data.dcache.way_incr >> 12;
|
2006-11-26 20:06:26 -07:00
|
|
|
for (i = 0; i < n; i++, addr += 4096)
|
2006-09-26 22:09:26 -07:00
|
|
|
flush_cache_4096(addr, phys);
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
2006-09-26 22:05:52 -07:00
|
|
|
|
|
|
|
wmb();
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
2006-09-27 02:30:07 -07:00
|
|
|
/* TODO: Selective icache invalidation through IC address array.. */
|
2008-09-05 02:00:29 -07:00
|
|
|
static void __uses_jump_to_uncached flush_icache_all(void)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2009-09-01 05:12:55 -07:00
|
|
|
unsigned long flags, ccr;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2009-09-01 05:12:55 -07:00
|
|
|
local_irq_save(flags);
|
2007-11-30 01:06:36 -07:00
|
|
|
jump_to_uncached();
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
/* Flush I-cache */
|
|
|
|
ccr = ctrl_inl(CCR);
|
|
|
|
ccr |= CCR_CACHE_ICI;
|
|
|
|
ctrl_outl(ccr, CCR);
|
|
|
|
|
2006-09-26 22:57:44 -07:00
|
|
|
/*
|
2007-11-30 01:06:36 -07:00
|
|
|
* back_to_cached() will take care of the barrier for us, don't add
|
2006-09-26 22:57:44 -07:00
|
|
|
* another one!
|
|
|
|
*/
|
2009-09-01 05:12:55 -07:00
|
|
|
|
2007-11-30 01:06:36 -07:00
|
|
|
back_to_cached();
|
2009-09-01 05:12:55 -07:00
|
|
|
local_irq_restore(flags);
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
2009-08-14 19:22:50 -07:00
|
|
|
static inline void flush_dcache_all(void)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2007-09-21 02:05:20 -07:00
|
|
|
(*__flush_dcache_segment_fn)(0UL, boot_cpu_data.dcache.way_size);
|
2006-09-26 22:05:52 -07:00
|
|
|
wmb();
|
2006-09-26 19:29:55 -07:00
|
|
|
}
|
|
|
|
|
2009-08-21 01:23:14 -07:00
|
|
|
static void sh4_flush_cache_all(void *unused)
|
2006-09-26 19:29:55 -07:00
|
|
|
{
|
|
|
|
flush_dcache_all();
|
2005-04-16 15:20:36 -07:00
|
|
|
flush_icache_all();
|
|
|
|
}
|
|
|
|
|
2006-09-27 02: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-08 22:04:06 -07:00
|
|
|
* address (i.e. tag). It's no different here.
|
2006-09-27 02:30:07 -07:00
|
|
|
*
|
|
|
|
* Caller takes mm->mmap_sem.
|
|
|
|
*/
|
2009-08-21 01:23:14 -07:00
|
|
|
static void sh4_flush_cache_mm(void *arg)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2009-08-21 01:23:14 -07:00
|
|
|
struct mm_struct *mm = arg;
|
|
|
|
|
2009-08-14 10: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-08 22:04:06 -07:00
|
|
|
flush_dcache_all();
|
2005-04-16 15: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 01:23:14 -07:00
|
|
|
static void sh4_flush_cache_page(void *args)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2009-08-21 01:23:14 -07:00
|
|
|
struct flusher_data *data = args;
|
|
|
|
struct vm_area_struct *vma;
|
|
|
|
unsigned long address, pfn, phys;
|
2006-09-26 22:09:26 -07:00
|
|
|
unsigned int alias_mask;
|
|
|
|
|
2009-08-21 01:23:14 -07:00
|
|
|
vma = data->vma;
|
|
|
|
address = data->addr1;
|
|
|
|
pfn = data->addr2;
|
|
|
|
phys = pfn << PAGE_SHIFT;
|
|
|
|
|
2009-08-14 10:21:16 -07:00
|
|
|
if (cpu_context(smp_processor_id(), vma->vm_mm) == NO_CONTEXT)
|
|
|
|
return;
|
|
|
|
|
2007-09-21 02:05:20 -07:00
|
|
|
alias_mask = boot_cpu_data.dcache.alias_mask;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
/* We only need to flush D-cache when we have alias */
|
2006-09-26 22:09:26 -07:00
|
|
|
if ((address^phys) & alias_mask) {
|
2005-04-16 15:20:36 -07:00
|
|
|
/* Loop 4K of the D-cache */
|
|
|
|
flush_cache_4096(
|
2006-09-26 22:09:26 -07:00
|
|
|
CACHE_OC_ADDRESS_ARRAY | (address & alias_mask),
|
2005-04-16 15:20:36 -07:00
|
|
|
phys);
|
|
|
|
/* Loop another 4K of the D-cache */
|
|
|
|
flush_cache_4096(
|
2006-09-26 22:09:26 -07:00
|
|
|
CACHE_OC_ADDRESS_ARRAY | (phys & alias_mask),
|
2005-04-16 15:20:36 -07:00
|
|
|
phys);
|
|
|
|
}
|
|
|
|
|
2007-09-21 02:05:20 -07:00
|
|
|
alias_mask = boot_cpu_data.icache.alias_mask;
|
2006-09-26 22:09:26 -07:00
|
|
|
if (vma->vm_flags & VM_EXEC) {
|
|
|
|
/*
|
|
|
|
* Evict entries from the portion of the cache from which code
|
|
|
|
* may have been executed at this address (virtual). There's
|
|
|
|
* no need to evict from the portion corresponding to the
|
|
|
|
* physical address as for the D-cache, because we know the
|
|
|
|
* kernel has never executed the code through its identity
|
|
|
|
* translation.
|
|
|
|
*/
|
2005-04-16 15:20:36 -07:00
|
|
|
flush_cache_4096(
|
2006-09-26 22:09:26 -07:00
|
|
|
CACHE_IC_ADDRESS_ARRAY | (address & alias_mask),
|
2005-04-16 15:20:36 -07:00
|
|
|
phys);
|
2006-09-26 22:09:26 -07:00
|
|
|
}
|
2005-04-16 15: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 01:23:14 -07:00
|
|
|
static void sh4_flush_cache_range(void *args)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2009-08-21 01: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-14 10:21:16 -07:00
|
|
|
if (cpu_context(smp_processor_id(), vma->vm_mm) == NO_CONTEXT)
|
|
|
|
return;
|
|
|
|
|
2006-09-26 22: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 02:05:20 -07:00
|
|
|
if (boot_cpu_data.dcache.n_aliases == 0)
|
2006-09-26 22: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-08 22:04:06 -07:00
|
|
|
flush_dcache_all();
|
2006-09-26 22: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-08 22:04:06 -07:00
|
|
|
if (vma->vm_flags & VM_EXEC)
|
2005-04-16 15:20:36 -07:00
|
|
|
flush_icache_all();
|
|
|
|
}
|
|
|
|
|
2006-09-26 22:09:26 -07:00
|
|
|
/**
|
|
|
|
* __flush_cache_4096
|
|
|
|
*
|
|
|
|
* @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'.
|
|
|
|
*/
|
|
|
|
static void __flush_cache_4096(unsigned long addr, unsigned long phys,
|
|
|
|
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 02:05:20 -07:00
|
|
|
dcache = &boot_cpu_data.dcache;
|
2006-09-26 22: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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Break the 1, 2 and 4 way variants of this out into separate functions to
|
|
|
|
* avoid nearly all the overhead of having the conditional stuff in the function
|
|
|
|
* bodies (+ the 1 and 2 way cases avoid saving any registers too).
|
2009-08-24 01:36:24 -07:00
|
|
|
*
|
|
|
|
* We want to eliminate unnecessary bus transactions, so this code uses
|
|
|
|
* a non-obvious technique.
|
|
|
|
*
|
|
|
|
* Loop over a cache way sized block of, one cache line at a time. For each
|
|
|
|
* line, use movca.a to cause the current cache line contents to be written
|
|
|
|
* back, but without reading anything from main memory. However this has the
|
|
|
|
* side effect that the cache is now caching that memory location. So follow
|
|
|
|
* this with a cache invalidate to mark the cache line invalid. And do all
|
|
|
|
* this with interrupts disabled, to avoid the cache line being accidently
|
|
|
|
* evicted while it is holding garbage.
|
2009-08-24 02:39:39 -07:00
|
|
|
*
|
|
|
|
* This also breaks in a number of circumstances:
|
|
|
|
* - if there are modifications to the region of memory just above
|
|
|
|
* empty_zero_page (for example because a breakpoint has been placed
|
|
|
|
* there), then these can be lost.
|
|
|
|
*
|
|
|
|
* This is because the the memory address which the cache temporarily
|
|
|
|
* caches in the above description is empty_zero_page. So the
|
|
|
|
* movca.l hits the cache (it is assumed that it misses, or at least
|
|
|
|
* isn't dirty), modifies the line and then invalidates it, losing the
|
|
|
|
* required change.
|
|
|
|
*
|
|
|
|
* - If caches are disabled or configured in write-through mode, then
|
|
|
|
* the movca.l writes garbage directly into memory.
|
2006-09-26 22:09:26 -07:00
|
|
|
*/
|
2009-08-31 21:32:48 -07:00
|
|
|
static void __flush_dcache_segment_writethrough(unsigned long start,
|
|
|
|
unsigned long extent_per_way)
|
|
|
|
{
|
|
|
|
unsigned long addr;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
addr = CACHE_OC_ADDRESS_ARRAY | (start & cpu_data->dcache.entry_mask);
|
|
|
|
|
|
|
|
while (extent_per_way) {
|
|
|
|
for (i = 0; i < cpu_data->dcache.ways; i++)
|
|
|
|
__raw_writel(0, addr + cpu_data->dcache.way_incr * i);
|
|
|
|
|
|
|
|
addr += cpu_data->dcache.linesz;
|
|
|
|
extent_per_way -= cpu_data->dcache.linesz;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-26 22:09:26 -07:00
|
|
|
static void __flush_dcache_segment_1way(unsigned long start,
|
|
|
|
unsigned long extent_per_way)
|
|
|
|
{
|
|
|
|
unsigned long orig_sr, sr_with_bl;
|
|
|
|
unsigned long base_addr;
|
|
|
|
unsigned long way_incr, linesz, way_size;
|
|
|
|
struct cache_info *dcache;
|
|
|
|
register unsigned long a0, a0e;
|
|
|
|
|
|
|
|
asm volatile("stc sr, %0" : "=r" (orig_sr));
|
|
|
|
sr_with_bl = orig_sr | (1<<28);
|
|
|
|
base_addr = ((unsigned long)&empty_zero_page[0]);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The previous code aligned base_addr to 16k, i.e. the way_size of all
|
|
|
|
* existing SH-4 D-caches. Whilst I don't see a need to have this
|
|
|
|
* aligned to any better than the cache line size (which it will be
|
|
|
|
* anyway by construction), let's align it to at least the way_size of
|
|
|
|
* any existing or conceivable SH-4 D-cache. -- RPC
|
|
|
|
*/
|
|
|
|
base_addr = ((base_addr >> 16) << 16);
|
|
|
|
base_addr |= start;
|
|
|
|
|
2007-09-21 02:05:20 -07:00
|
|
|
dcache = &boot_cpu_data.dcache;
|
2006-09-26 22:09:26 -07:00
|
|
|
linesz = dcache->linesz;
|
|
|
|
way_incr = dcache->way_incr;
|
|
|
|
way_size = dcache->way_size;
|
|
|
|
|
|
|
|
a0 = base_addr;
|
|
|
|
a0e = base_addr + extent_per_way;
|
|
|
|
do {
|
|
|
|
asm volatile("ldc %0, sr" : : "r" (sr_with_bl));
|
|
|
|
asm volatile("movca.l r0, @%0\n\t"
|
|
|
|
"ocbi @%0" : : "r" (a0));
|
|
|
|
a0 += linesz;
|
|
|
|
asm volatile("movca.l r0, @%0\n\t"
|
|
|
|
"ocbi @%0" : : "r" (a0));
|
|
|
|
a0 += linesz;
|
|
|
|
asm volatile("movca.l r0, @%0\n\t"
|
|
|
|
"ocbi @%0" : : "r" (a0));
|
|
|
|
a0 += linesz;
|
|
|
|
asm volatile("movca.l r0, @%0\n\t"
|
|
|
|
"ocbi @%0" : : "r" (a0));
|
|
|
|
asm volatile("ldc %0, sr" : : "r" (orig_sr));
|
|
|
|
a0 += linesz;
|
|
|
|
} while (a0 < a0e);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __flush_dcache_segment_2way(unsigned long start,
|
|
|
|
unsigned long extent_per_way)
|
|
|
|
{
|
|
|
|
unsigned long orig_sr, sr_with_bl;
|
|
|
|
unsigned long base_addr;
|
|
|
|
unsigned long way_incr, linesz, way_size;
|
|
|
|
struct cache_info *dcache;
|
|
|
|
register unsigned long a0, a1, a0e;
|
|
|
|
|
|
|
|
asm volatile("stc sr, %0" : "=r" (orig_sr));
|
|
|
|
sr_with_bl = orig_sr | (1<<28);
|
|
|
|
base_addr = ((unsigned long)&empty_zero_page[0]);
|
|
|
|
|
|
|
|
/* See comment under 1-way above */
|
|
|
|
base_addr = ((base_addr >> 16) << 16);
|
|
|
|
base_addr |= start;
|
|
|
|
|
2007-09-21 02:05:20 -07:00
|
|
|
dcache = &boot_cpu_data.dcache;
|
2006-09-26 22:09:26 -07:00
|
|
|
linesz = dcache->linesz;
|
|
|
|
way_incr = dcache->way_incr;
|
|
|
|
way_size = dcache->way_size;
|
|
|
|
|
|
|
|
a0 = base_addr;
|
|
|
|
a1 = a0 + way_incr;
|
|
|
|
a0e = base_addr + extent_per_way;
|
|
|
|
do {
|
|
|
|
asm volatile("ldc %0, sr" : : "r" (sr_with_bl));
|
|
|
|
asm volatile("movca.l r0, @%0\n\t"
|
|
|
|
"movca.l r0, @%1\n\t"
|
|
|
|
"ocbi @%0\n\t"
|
|
|
|
"ocbi @%1" : :
|
|
|
|
"r" (a0), "r" (a1));
|
|
|
|
a0 += linesz;
|
|
|
|
a1 += linesz;
|
|
|
|
asm volatile("movca.l r0, @%0\n\t"
|
|
|
|
"movca.l r0, @%1\n\t"
|
|
|
|
"ocbi @%0\n\t"
|
|
|
|
"ocbi @%1" : :
|
|
|
|
"r" (a0), "r" (a1));
|
|
|
|
a0 += linesz;
|
|
|
|
a1 += linesz;
|
|
|
|
asm volatile("movca.l r0, @%0\n\t"
|
|
|
|
"movca.l r0, @%1\n\t"
|
|
|
|
"ocbi @%0\n\t"
|
|
|
|
"ocbi @%1" : :
|
|
|
|
"r" (a0), "r" (a1));
|
|
|
|
a0 += linesz;
|
|
|
|
a1 += linesz;
|
|
|
|
asm volatile("movca.l r0, @%0\n\t"
|
|
|
|
"movca.l r0, @%1\n\t"
|
|
|
|
"ocbi @%0\n\t"
|
|
|
|
"ocbi @%1" : :
|
|
|
|
"r" (a0), "r" (a1));
|
|
|
|
asm volatile("ldc %0, sr" : : "r" (orig_sr));
|
|
|
|
a0 += linesz;
|
|
|
|
a1 += linesz;
|
|
|
|
} while (a0 < a0e);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __flush_dcache_segment_4way(unsigned long start,
|
|
|
|
unsigned long extent_per_way)
|
|
|
|
{
|
|
|
|
unsigned long orig_sr, sr_with_bl;
|
|
|
|
unsigned long base_addr;
|
|
|
|
unsigned long way_incr, linesz, way_size;
|
|
|
|
struct cache_info *dcache;
|
|
|
|
register unsigned long a0, a1, a2, a3, a0e;
|
|
|
|
|
|
|
|
asm volatile("stc sr, %0" : "=r" (orig_sr));
|
|
|
|
sr_with_bl = orig_sr | (1<<28);
|
|
|
|
base_addr = ((unsigned long)&empty_zero_page[0]);
|
|
|
|
|
|
|
|
/* See comment under 1-way above */
|
|
|
|
base_addr = ((base_addr >> 16) << 16);
|
|
|
|
base_addr |= start;
|
|
|
|
|
2007-09-21 02:05:20 -07:00
|
|
|
dcache = &boot_cpu_data.dcache;
|
2006-09-26 22:09:26 -07:00
|
|
|
linesz = dcache->linesz;
|
|
|
|
way_incr = dcache->way_incr;
|
|
|
|
way_size = dcache->way_size;
|
|
|
|
|
|
|
|
a0 = base_addr;
|
|
|
|
a1 = a0 + way_incr;
|
|
|
|
a2 = a1 + way_incr;
|
|
|
|
a3 = a2 + way_incr;
|
|
|
|
a0e = base_addr + extent_per_way;
|
|
|
|
do {
|
|
|
|
asm volatile("ldc %0, sr" : : "r" (sr_with_bl));
|
|
|
|
asm volatile("movca.l r0, @%0\n\t"
|
|
|
|
"movca.l r0, @%1\n\t"
|
|
|
|
"movca.l r0, @%2\n\t"
|
|
|
|
"movca.l r0, @%3\n\t"
|
|
|
|
"ocbi @%0\n\t"
|
|
|
|
"ocbi @%1\n\t"
|
|
|
|
"ocbi @%2\n\t"
|
|
|
|
"ocbi @%3\n\t" : :
|
|
|
|
"r" (a0), "r" (a1), "r" (a2), "r" (a3));
|
|
|
|
a0 += linesz;
|
|
|
|
a1 += linesz;
|
|
|
|
a2 += linesz;
|
|
|
|
a3 += linesz;
|
|
|
|
asm volatile("movca.l r0, @%0\n\t"
|
|
|
|
"movca.l r0, @%1\n\t"
|
|
|
|
"movca.l r0, @%2\n\t"
|
|
|
|
"movca.l r0, @%3\n\t"
|
|
|
|
"ocbi @%0\n\t"
|
|
|
|
"ocbi @%1\n\t"
|
|
|
|
"ocbi @%2\n\t"
|
|
|
|
"ocbi @%3\n\t" : :
|
|
|
|
"r" (a0), "r" (a1), "r" (a2), "r" (a3));
|
|
|
|
a0 += linesz;
|
|
|
|
a1 += linesz;
|
|
|
|
a2 += linesz;
|
|
|
|
a3 += linesz;
|
|
|
|
asm volatile("movca.l r0, @%0\n\t"
|
|
|
|
"movca.l r0, @%1\n\t"
|
|
|
|
"movca.l r0, @%2\n\t"
|
|
|
|
"movca.l r0, @%3\n\t"
|
|
|
|
"ocbi @%0\n\t"
|
|
|
|
"ocbi @%1\n\t"
|
|
|
|
"ocbi @%2\n\t"
|
|
|
|
"ocbi @%3\n\t" : :
|
|
|
|
"r" (a0), "r" (a1), "r" (a2), "r" (a3));
|
|
|
|
a0 += linesz;
|
|
|
|
a1 += linesz;
|
|
|
|
a2 += linesz;
|
|
|
|
a3 += linesz;
|
|
|
|
asm volatile("movca.l r0, @%0\n\t"
|
|
|
|
"movca.l r0, @%1\n\t"
|
|
|
|
"movca.l r0, @%2\n\t"
|
|
|
|
"movca.l r0, @%3\n\t"
|
|
|
|
"ocbi @%0\n\t"
|
|
|
|
"ocbi @%1\n\t"
|
|
|
|
"ocbi @%2\n\t"
|
|
|
|
"ocbi @%3\n\t" : :
|
|
|
|
"r" (a0), "r" (a1), "r" (a2), "r" (a3));
|
|
|
|
asm volatile("ldc %0, sr" : : "r" (orig_sr));
|
|
|
|
a0 += linesz;
|
|
|
|
a1 += linesz;
|
|
|
|
a2 += linesz;
|
|
|
|
a3 += linesz;
|
|
|
|
} while (a0 < a0e);
|
|
|
|
}
|
2009-08-14 20: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)
|
|
|
|
{
|
2009-08-31 21:54:14 -07:00
|
|
|
unsigned int wt_enabled = !!(__raw_readl(CCR) & CCR_CACHE_WT);
|
|
|
|
|
2009-08-14 20:29:49 -07:00
|
|
|
printk("PVR=%08x CVR=%08x PRR=%08x\n",
|
|
|
|
ctrl_inl(CCN_PVR),
|
|
|
|
ctrl_inl(CCN_CVR),
|
|
|
|
ctrl_inl(CCN_PRR));
|
|
|
|
|
2009-08-31 21:54:14 -07:00
|
|
|
if (wt_enabled)
|
|
|
|
__flush_dcache_segment_fn = __flush_dcache_segment_writethrough;
|
|
|
|
else {
|
|
|
|
switch (boot_cpu_data.dcache.ways) {
|
|
|
|
case 1:
|
|
|
|
__flush_dcache_segment_fn = __flush_dcache_segment_1way;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
__flush_dcache_segment_fn = __flush_dcache_segment_2way;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
__flush_dcache_segment_fn = __flush_dcache_segment_4way;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
panic("unknown number of cache ways\n");
|
|
|
|
break;
|
|
|
|
}
|
2009-08-14 20:29:49 -07:00
|
|
|
}
|
|
|
|
|
2009-08-21 01: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-14 20:29:49 -07:00
|
|
|
|
|
|
|
sh4__flush_region_init();
|
|
|
|
}
|