2017-11-08 19:47:45 +08:00
|
|
|
/*
|
2021-03-24 15:46:51 +08:00
|
|
|
* Copyright (c) 2006-2021, RT-Thread Development Team
|
2017-11-08 19:47:45 +08:00
|
|
|
*
|
2021-03-24 15:46:51 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2017-11-08 19:47:45 +08:00
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
2019-12-07 00:54:03 +08:00
|
|
|
* 2016-09-07 Urey the first version
|
2017-11-08 19:47:45 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <rtthread.h>
|
|
|
|
#include "mips.h"
|
|
|
|
|
|
|
|
extern void cache_init(rt_ubase_t cache_size, rt_ubase_t cache_line_size);
|
|
|
|
void r4k_cache_init(void)
|
|
|
|
{
|
2021-03-27 17:51:56 +08:00
|
|
|
// cache_init(dcache_size, cpu_dcache_line_size);
|
2017-11-08 19:47:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void r4k_cache_flush_all(void)
|
|
|
|
{
|
|
|
|
blast_dcache16();
|
|
|
|
blast_icache16();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void r4k_icache_flush_all(void)
|
|
|
|
{
|
|
|
|
blast_icache16();
|
|
|
|
}
|
|
|
|
|
|
|
|
void r4k_icache_flush_range(rt_ubase_t addr, rt_ubase_t size)
|
|
|
|
{
|
2021-03-27 17:51:56 +08:00
|
|
|
rt_ubase_t end, a;
|
2017-11-08 19:47:45 +08:00
|
|
|
|
|
|
|
if (size > g_mips_core.icache_size)
|
|
|
|
{
|
|
|
|
blast_icache16();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-27 17:51:56 +08:00
|
|
|
rt_ubase_t ic_lsize = g_mips_core.icache_line_size;
|
2017-11-08 19:47:45 +08:00
|
|
|
|
|
|
|
a = addr & ~(ic_lsize - 1);
|
|
|
|
end = ((addr + size) - 1) & ~(ic_lsize - 1);
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
flush_icache_line(a);
|
|
|
|
if (a == end)
|
|
|
|
break;
|
|
|
|
a += ic_lsize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void r4k_icache_lock_range(rt_ubase_t addr, rt_ubase_t size)
|
|
|
|
{
|
2021-03-27 17:51:56 +08:00
|
|
|
rt_ubase_t end, a;
|
|
|
|
rt_ubase_t ic_lsize = g_mips_core.icache_line_size;
|
2017-11-08 19:47:45 +08:00
|
|
|
|
|
|
|
a = addr & ~(ic_lsize - 1);
|
|
|
|
end = ((addr + size) - 1) & ~(ic_lsize - 1);
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
lock_icache_line(a);
|
|
|
|
if (a == end)
|
|
|
|
break;
|
|
|
|
a += ic_lsize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void r4k_dcache_inv(rt_ubase_t addr, rt_ubase_t size)
|
|
|
|
{
|
2021-03-27 17:51:56 +08:00
|
|
|
rt_ubase_t end, a;
|
2017-11-08 19:47:45 +08:00
|
|
|
rt_ubase_t dc_lsize = g_mips_core.dcache_line_size;
|
|
|
|
|
|
|
|
a = addr & ~(dc_lsize - 1);
|
|
|
|
end = ((addr + size) - 1) & ~(dc_lsize - 1);
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
invalidate_dcache_line(a);
|
|
|
|
if (a == end)
|
|
|
|
break;
|
|
|
|
a += dc_lsize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void r4k_dcache_wback_inv(rt_ubase_t addr, rt_ubase_t size)
|
|
|
|
{
|
2021-03-27 17:51:56 +08:00
|
|
|
rt_ubase_t end, a;
|
2017-11-08 19:47:45 +08:00
|
|
|
|
|
|
|
if (size >= g_mips_core.dcache_size)
|
|
|
|
{
|
|
|
|
blast_dcache16();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-27 17:51:56 +08:00
|
|
|
rt_ubase_t dc_lsize = g_mips_core.dcache_line_size;
|
2017-11-08 19:47:45 +08:00
|
|
|
|
|
|
|
a = addr & ~(dc_lsize - 1);
|
|
|
|
end = ((addr + size) - 1) & ~(dc_lsize - 1);
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
flush_dcache_line(a);
|
|
|
|
if (a == end)
|
|
|
|
break;
|
|
|
|
a += dc_lsize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define dma_cache_wback_inv(start,size) \
|
|
|
|
do { (void) (start); (void) (size); } while (0)
|
|
|
|
#define dma_cache_wback(start,size) \
|
|
|
|
do { (void) (start); (void) (size); } while (0)
|
|
|
|
#define dma_cache_inv(start,size) \
|
|
|
|
do { (void) (start); (void) (size); } while (0)
|
|
|
|
|
|
|
|
|
|
|
|
void r4k_dma_cache_sync(rt_ubase_t addr, rt_size_t size, enum dma_data_direction direction)
|
|
|
|
{
|
|
|
|
switch (direction)
|
|
|
|
{
|
|
|
|
case DMA_TO_DEVICE:
|
|
|
|
r4k_dcache_wback_inv(addr, size);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DMA_FROM_DEVICE:
|
|
|
|
r4k_dcache_wback_inv(addr, size);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DMA_BIDIRECTIONAL:
|
|
|
|
dma_cache_wback_inv(addr, size);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
RT_ASSERT(0) ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|