From bee8253d8f04c56017860386d1b2132cf4f4b7c5 Mon Sep 17 00:00:00 2001 From: Jun Liang Tan Date: Mon, 1 Aug 2022 16:03:00 +0800 Subject: platform: generic: starfive: Add platform specific Cache Maintenance Operations Add SBI call for L2 cache flush and L2 cache invalidate for Dubhe Signed-off-by: Jun Liang Tan --- platform/generic/starfive/cache.h | 18 +++++++ platform/generic/starfive/dubhe_cache.S | 84 +++++++++++++++++++++++++++++++++ platform/generic/starfive/jh8100.c | 48 +++++++++++++++++++ platform/generic/starfive/jh8100.h | 18 +++++++ platform/generic/starfive/objects.mk | 11 +++++ 5 files changed, 179 insertions(+) create mode 100644 platform/generic/starfive/cache.h create mode 100755 platform/generic/starfive/dubhe_cache.S create mode 100644 platform/generic/starfive/jh8100.c create mode 100644 platform/generic/starfive/jh8100.h create mode 100644 platform/generic/starfive/objects.mk 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 + * + */ + +#ifndef _DUBHE_CACHE_H_ +#define _DUBHE_CACHE_H_ + +#include + +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_cache.S b/platform/generic/starfive/dubhe_cache.S new file mode 100755 index 0000000..d0b3f94 --- /dev/null +++ b/platform/generic/starfive/dubhe_cache.S @@ -0,0 +1,84 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2022 StarFive Technology Co., Ltd. + * + * Author: Chee Hong Ang + * + */ + +#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 + fence rw, rw +2: + bge a0, a1, 4f +3: + /* CDISCARD.L2 rs1 = a0 */ + fence rw, rw + .insn i 0x73, 0, x0, a0, -0x3A + fence rw, rw + add a0, a0, t0 + blt a0, a1, 3b +4: + 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 +1: + /* CFLUSH.L2 rs1 = a0 */ + fence rw, rw + .insn i 0x73, 0, x0, a0, -0x3C + fence rw, rw + add a0, a0, t0 + blt a0, a1, 1b +2: + ret diff --git a/platform/generic/starfive/jh8100.c b/platform/generic/starfive/jh8100.c new file mode 100644 index 0000000..b11ffcf --- /dev/null +++ b/platform/generic/starfive/jh8100.c @@ -0,0 +1,48 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2022 StarFive Technology Co., Ltd. + * + * Author: Jun Liang Tan + * + */ + +#include +#include +#include +#include +#include + +static int starfive_vendor_ext_provider(long extid, long funcid, + const struct sbi_trap_regs *regs, + unsigned long *out_value, + struct sbi_trap_info *out_trap, + 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); + asm volatile("ebreak"); + } + + return ret; +} + +static const struct fdt_match starfive_jh8xxx_match[] = { + { .compatible = "starfive,dubhe" }, + { .compatible = "starfive,jh8100" }, + { }, +}; + +const struct platform_override starfive_jh8xxx = { + .match_table = starfive_jh8xxx_match, + .vendor_ext_provider = starfive_vendor_ext_provider, +}; diff --git a/platform/generic/starfive/jh8100.h b/platform/generic/starfive/jh8100.h new file mode 100644 index 0000000..c905f84 --- /dev/null +++ b/platform/generic/starfive/jh8100.h @@ -0,0 +1,18 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2022 StarFive Technology Co., Ltd. + * + * Author: Jun Liang Tan + * + */ + +#ifndef _STARFIVE_JH8100_H_ +#define _STARFIVE_JH8100_H_ + +enum sbi_ext_dubhe_cmo_fid { + SBI_EXT_STARFIVE_DUBHE_L2_FLUSH = 0, + SBI_EXT_STARFIVE_DUBHE_L2_INVALIDATE, +}; + +#endif /* _STARFIVE_JH8100_H_ */ diff --git a/platform/generic/starfive/objects.mk b/platform/generic/starfive/objects.mk new file mode 100644 index 0000000..0baa9f7 --- /dev/null +++ b/platform/generic/starfive/objects.mk @@ -0,0 +1,11 @@ +# +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (c) 2022 StarFive Technology Co., Ltd. +# +# Author: Jun Liang Tan +# + +carray-platform_override_modules-y += starfive_jh8xxx +platform-objs-y += starfive/dubhe_cache.o +platform-objs-y += starfive/jh8100.o -- cgit v1.2.3