2018-11-07 01:34:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2017 Andes Technology Corporation
|
|
|
|
* Rick Chen, Andes Technology Corporation <rick@andestech.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2019-11-14 19:57:37 +00:00
|
|
|
#include <cpu_func.h>
|
2019-08-28 10:46:09 +00:00
|
|
|
#include <dm.h>
|
|
|
|
#include <dm/uclass-internal.h>
|
|
|
|
#include <cache.h>
|
2019-08-28 10:46:11 +00:00
|
|
|
#include <asm/csr.h>
|
|
|
|
|
|
|
|
#ifdef CONFIG_RISCV_NDS_CACHE
|
|
|
|
/* mcctlcommand */
|
|
|
|
#define CCTL_REG_MCCTLCOMMAND_NUM 0x7cc
|
|
|
|
|
|
|
|
/* D-cache operation */
|
|
|
|
#define CCTL_L1D_WBINVAL_ALL 6
|
|
|
|
#endif
|
2018-11-07 01:34:06 +00:00
|
|
|
|
2019-01-04 00:37:29 +00:00
|
|
|
void flush_dcache_all(void)
|
|
|
|
{
|
2019-08-28 10:46:11 +00:00
|
|
|
#ifdef CONFIG_RISCV_NDS_CACHE
|
|
|
|
csr_write(CCTL_REG_MCCTLCOMMAND_NUM, CCTL_L1D_WBINVAL_ALL);
|
|
|
|
#endif
|
2019-01-04 00:37:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void flush_dcache_range(unsigned long start, unsigned long end)
|
|
|
|
{
|
|
|
|
flush_dcache_all();
|
|
|
|
}
|
|
|
|
|
|
|
|
void invalidate_dcache_range(unsigned long start, unsigned long end)
|
|
|
|
{
|
|
|
|
flush_dcache_all();
|
|
|
|
}
|
|
|
|
|
2018-11-07 01:34:06 +00:00
|
|
|
void icache_enable(void)
|
|
|
|
{
|
2019-05-03 13:41:00 +00:00
|
|
|
#if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
|
2018-12-12 14:12:28 +00:00
|
|
|
#ifdef CONFIG_RISCV_NDS_CACHE
|
2018-11-07 01:34:06 +00:00
|
|
|
asm volatile (
|
|
|
|
"csrr t1, mcache_ctl\n\t"
|
|
|
|
"ori t0, t1, 0x1\n\t"
|
|
|
|
"csrw mcache_ctl, t0\n\t"
|
|
|
|
);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void icache_disable(void)
|
|
|
|
{
|
2019-05-03 13:41:00 +00:00
|
|
|
#if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
|
2018-12-12 14:12:28 +00:00
|
|
|
#ifdef CONFIG_RISCV_NDS_CACHE
|
2018-11-07 01:34:06 +00:00
|
|
|
asm volatile (
|
|
|
|
"fence.i\n\t"
|
|
|
|
"csrr t1, mcache_ctl\n\t"
|
|
|
|
"andi t0, t1, ~0x1\n\t"
|
|
|
|
"csrw mcache_ctl, t0\n\t"
|
|
|
|
);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void dcache_enable(void)
|
|
|
|
{
|
2019-05-03 13:41:00 +00:00
|
|
|
#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
|
2018-12-12 14:12:28 +00:00
|
|
|
#ifdef CONFIG_RISCV_NDS_CACHE
|
2019-08-28 10:46:09 +00:00
|
|
|
struct udevice *dev = NULL;
|
|
|
|
|
2018-11-07 01:34:06 +00:00
|
|
|
asm volatile (
|
|
|
|
"csrr t1, mcache_ctl\n\t"
|
|
|
|
"ori t0, t1, 0x2\n\t"
|
|
|
|
"csrw mcache_ctl, t0\n\t"
|
|
|
|
);
|
2019-08-28 10:46:09 +00:00
|
|
|
|
|
|
|
uclass_find_first_device(UCLASS_CACHE, &dev);
|
|
|
|
|
|
|
|
if (dev)
|
|
|
|
cache_enable(dev);
|
2018-11-07 01:34:06 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void dcache_disable(void)
|
|
|
|
{
|
2019-05-03 13:41:00 +00:00
|
|
|
#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
|
2018-12-12 14:12:28 +00:00
|
|
|
#ifdef CONFIG_RISCV_NDS_CACHE
|
2019-08-28 10:46:09 +00:00
|
|
|
struct udevice *dev = NULL;
|
|
|
|
|
2019-08-28 10:46:11 +00:00
|
|
|
csr_write(CCTL_REG_MCCTLCOMMAND_NUM, CCTL_L1D_WBINVAL_ALL);
|
2018-11-07 01:34:06 +00:00
|
|
|
asm volatile (
|
|
|
|
"csrr t1, mcache_ctl\n\t"
|
|
|
|
"andi t0, t1, ~0x2\n\t"
|
|
|
|
"csrw mcache_ctl, t0\n\t"
|
|
|
|
);
|
2019-08-28 10:46:09 +00:00
|
|
|
|
|
|
|
uclass_find_first_device(UCLASS_CACHE, &dev);
|
|
|
|
|
|
|
|
if (dev)
|
|
|
|
cache_disable(dev);
|
2018-11-07 01:34:06 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int icache_status(void)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
2018-12-12 14:12:28 +00:00
|
|
|
#ifdef CONFIG_RISCV_NDS_CACHE
|
2018-11-07 01:34:06 +00:00
|
|
|
asm volatile (
|
|
|
|
"csrr t1, mcache_ctl\n\t"
|
|
|
|
"andi %0, t1, 0x01\n\t"
|
|
|
|
: "=r" (ret)
|
|
|
|
:
|
|
|
|
: "memory"
|
|
|
|
);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int dcache_status(void)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
2018-12-12 14:12:28 +00:00
|
|
|
#ifdef CONFIG_RISCV_NDS_CACHE
|
2018-11-07 01:34:06 +00:00
|
|
|
asm volatile (
|
|
|
|
"csrr t1, mcache_ctl\n\t"
|
|
|
|
"andi %0, t1, 0x02\n\t"
|
|
|
|
: "=r" (ret)
|
|
|
|
:
|
|
|
|
: "memory"
|
|
|
|
);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|