Browse Source

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 <junliang.tan@linux.starfivetech.com>
Jun Liang Tan 1 year ago
parent
commit
bee8253d8f

+ 18 - 0
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_ */

+ 84 - 0
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 <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
+	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

+ 48 - 0
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 <junliang.tan@linux.starfivetech.com>
+ *
+ */
+
+#include <cache.h>
+#include <jh8100.h>
+#include <platform_override.h>
+#include <sbi/sbi_console.h>
+#include <sbi_utils/fdt/fdt_helper.h>
+
+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,
+};

+ 18 - 0
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 <junliang.tan@linux.starfivetech.com>
+ *
+ */
+
+#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_ */

+ 11 - 0
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 <junliang.tan@linux.starfivetech.com>
+#
+
+carray-platform_override_modules-y += starfive_jh8xxx
+platform-objs-y += starfive/dubhe_cache.o
+platform-objs-y += starfive/jh8100.o