diff options
author | Chee Hong Ang <cheehong.ang@starfivetech.com> | 2024-01-14 10:47:34 +0300 |
---|---|---|
committer | Chee Hong Ang <cheehong.ang@starfivetech.com> | 2024-01-14 10:47:34 +0300 |
commit | cbe45cb6ab205fa51d6d19bd8bbc9cb9810f952d (patch) | |
tree | 2fe7d89e0aa8b8c328d19ac62857a3114fd997fb | |
parent | a2b255b88918715173942f2c5e1f97ac9e90c877 (diff) | |
download | opensbi-starfive-v1.4-dubhe.tar.xz |
platform: generic: starfive: Add Dubhe CMO SBI extensionREL_DUBHE_MAR2024starfive-v1.4-dubhe
Add L2 cache flush and L2 cache invalidate SBI calls for Dubhe
Signed-off-by: Chee Hong Ang <cheehong.ang@starfivetech.com>
-rw-r--r-- | platform/generic/starfive/cache.h | 18 | ||||
-rw-r--r-- | platform/generic/starfive/dubhe.c | 47 | ||||
-rw-r--r-- | platform/generic/starfive/dubhe.h | 18 | ||||
-rwxr-xr-x | platform/generic/starfive/dubhe_cache.S | 83 | ||||
-rw-r--r-- | platform/generic/starfive/objects.mk | 3 |
5 files changed, 169 insertions, 0 deletions
diff --git a/platform/generic/starfive/cache.h b/platform/generic/starfive/cache.h new file mode 100644 index 0000000..a60f900 --- /dev/null +++ b/platform/generic/starfive/cache.h @@ -0,0 +1,18 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2022 StarFive Technology Co., Ltd. + * + * Author: Jun Liang Tan <junliang.tan@linux.starfivetech.com> + * + */ + +#ifndef _DUBHE_CACHE_H_ +#define _DUBHE_CACHE_H_ + +#include <sbi/sbi_types.h> + +void __sbi_dubhe_L2_flush_range(uint64_t start, uint64_t len); +void __sbi_dubhe_L2_inv_range(uint64_t start, uint64_t len); + +#endif /* _DUBHE_CACHE_H_ */ diff --git a/platform/generic/starfive/dubhe.c b/platform/generic/starfive/dubhe.c new file mode 100644 index 0000000..027d49f --- /dev/null +++ b/platform/generic/starfive/dubhe.c @@ -0,0 +1,47 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2023 StarFive Technology Co., Ltd. + * + * Author: Jun Liang Tan <junliang.tan@linux.starfivetech.com> + * + */ + +#include <cache.h> +#include <dubhe.h> +#include <platform_override.h> +#include <sbi/sbi_console.h> +#include <sbi/sbi_error.h> +#include <sbi_utils/fdt/fdt_helper.h> + +static int starfive_vendor_ext_provider(long funcid, + struct sbi_trap_regs *regs, + struct sbi_ecall_return *out, + const struct fdt_match *match) +{ + int ret = 0; + + switch (funcid) { + case SBI_EXT_STARFIVE_DUBHE_L2_FLUSH: + __sbi_dubhe_L2_flush_range(regs->a0, regs->a1); + break; + case SBI_EXT_STARFIVE_DUBHE_L2_INVALIDATE: + __sbi_dubhe_L2_inv_range(regs->a0, regs->a1); + break; + default: + sbi_printf("Unsupported vendor sbi call : %ld\n", funcid); + return SBI_EINVAL; + } + + return ret; +} + +static const struct fdt_match starfive_dubhe_match[] = { + { .compatible = "starfive,dubhe" }, + { }, +}; + +const struct platform_override starfive_dubhe = { + .match_table = starfive_dubhe_match, + .vendor_ext_provider = starfive_vendor_ext_provider, +}; diff --git a/platform/generic/starfive/dubhe.h b/platform/generic/starfive/dubhe.h new file mode 100644 index 0000000..1714cbc --- /dev/null +++ b/platform/generic/starfive/dubhe.h @@ -0,0 +1,18 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2023 StarFive Technology Co., Ltd. + * + * Author: Jun Liang Tan <junliang.tan@linux.starfivetech.com> + * + */ + +#ifndef _STARFIVE_DUBHE_H_ +#define _STARFIVE_DUBHE_H_ + +enum sbi_ext_dubhe_cmo_fid { + SBI_EXT_STARFIVE_DUBHE_L2_FLUSH = 0, + SBI_EXT_STARFIVE_DUBHE_L2_INVALIDATE, +}; + +#endif /* _STARFIVE_DUBHE_H_ */ diff --git a/platform/generic/starfive/dubhe_cache.S b/platform/generic/starfive/dubhe_cache.S new file mode 100755 index 0000000..676f3c2 --- /dev/null +++ b/platform/generic/starfive/dubhe_cache.S @@ -0,0 +1,83 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2022 StarFive Technology Co., Ltd. + * + * Author: Chee Hong Ang <cheehong.ang@linux.starfivetech.com> + * + */ + +#define DUBHE_L2_CACHELINE_SIZE 0x40 + + /* + * __sbi_dubhe_L2_inv_range(start,len) + * + * Invalidate the L2 cache within the specified region + * + * start - physical start address of region + * len - size of memory region + */ + + .align 3 + .global __sbi_dubhe_L2_inv_range +__sbi_dubhe_L2_inv_range: + beqz a1, 4f + li t0, DUBHE_L2_CACHELINE_SIZE + addi t1, t0, -1 + add a1, a1, a0 /* Compute end address */ + and t2, a0, t1 + not t3, t1 + and a0, a0, t3 + beqz t2, 1f + /* CFLUSH.L2 rs1 = a0 */ + fence rw, rw + .insn i 0x73, 0, x0, a0, -0x3C + fence rw, rw + add a0, a0, t0 +1: + and t2, a1, t1 + not t3, t1 + and a1, a1, t3 + beqz t2, 2f + /* CFLUSH.L2 rs1 = a1 */ + fence rw, rw + .insn i 0x73, 0, x0, a1, -0x3C +2: + bge a0, a1, 4f + fence rw, rw +3: + /* CDISCARD.L2 rs1 = a0 */ + .insn i 0x73, 0, x0, a0, -0x3A + add a0, a0, t0 + blt a0, a1, 3b +4: + fence rw, rw + ret + + /* + * __sbi_dubhe_L2_flush_range(start,len) + * + * Flush and invalidate the L2 cache within the specified region + * + * start - physical start address of region + * len - size of memory region + */ + + .align 3 + .global __sbi_dubhe_L2_flush_range +__sbi_dubhe_L2_flush_range: + beqz a1, 2f + li t0, DUBHE_L2_CACHELINE_SIZE + addi t1, t0, -1 + add a1, a1, a0 /* Compute end address */ + not t2, t1 + and a0, a0, t2 + fence rw, rw +1: + /* CFLUSH.L2 rs1 = a0 */ + .insn i 0x73, 0, x0, a0, -0x3C + add a0, a0, t0 + blt a0, a1, 1b +2: + fence rw, rw + ret diff --git a/platform/generic/starfive/objects.mk b/platform/generic/starfive/objects.mk index 0b900fb..8bbb31f 100644 --- a/platform/generic/starfive/objects.mk +++ b/platform/generic/starfive/objects.mk @@ -3,4 +3,7 @@ # carray-platform_override_modules-$(CONFIG_PLATFORM_STARFIVE_JH7110) += starfive_jh7110 +carray-platform_override_modules-y += starfive_dubhe platform-objs-$(CONFIG_PLATFORM_STARFIVE_JH7110) += starfive/jh7110.o +platform-objs-y += starfive/dubhe_cache.o +platform-objs-y += starfive/dubhe.o |