diff options
Diffstat (limited to 'arch/riscv/lib')
| -rw-r--r-- | arch/riscv/lib/Makefile | 1 | ||||
| -rw-r--r-- | arch/riscv/lib/bootm.c | 4 | ||||
| -rw-r--r-- | arch/riscv/lib/thead_cmo.c | 45 | 
3 files changed, 50 insertions, 0 deletions
| diff --git a/arch/riscv/lib/Makefile b/arch/riscv/lib/Makefile index 189b35c24d3..db8d235c699 100644 --- a/arch/riscv/lib/Makefile +++ b/arch/riscv/lib/Makefile @@ -11,6 +11,7 @@ obj-$(CONFIG_CMD_BOOTI) += bootm.o image.o  obj-$(CONFIG_CMD_GO) += boot.o  obj-y	+= cache.o  obj-$(CONFIG_SIFIVE_CACHE) += sifive_cache.o +obj-$(CONFIG_SYS_CACHE_THEAD_CMO) += thead_cmo.o  ifeq ($(CONFIG_$(PHASE_)RISCV_MMODE),y)  obj-$(CONFIG_$(PHASE_)RISCV_ACLINT) += aclint_ipi.o  obj-$(CONFIG_ANDES_PLICSW) += andes_plicsw.o diff --git a/arch/riscv/lib/bootm.c b/arch/riscv/lib/bootm.c index 9544907ab1e..c98c5e76633 100644 --- a/arch/riscv/lib/bootm.c +++ b/arch/riscv/lib/bootm.c @@ -90,6 +90,10 @@ static void boot_jump_linux(struct bootm_headers *images, int flag)  	announce_and_cleanup(fake);  	if (!fake) { +		if (images->os.arch != IH_ARCH_DEFAULT) { +			printf("Image arch not compatible with host arch.\n"); +			hang(); +		}  		if (CONFIG_IS_ENABLED(OF_LIBFDT) && images->ft_len) {  #ifdef CONFIG_SMP  			ret = smp_call_function(images->ep, diff --git a/arch/riscv/lib/thead_cmo.c b/arch/riscv/lib/thead_cmo.c new file mode 100644 index 00000000000..b8051e29e02 --- /dev/null +++ b/arch/riscv/lib/thead_cmo.c @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2024, Kongyang Liu <seashell11234455@gmail.com> + */ + +#include <cpu_func.h> + +/* + * dcache.ipa rs1 (invalidate) + * | 31 - 25 | 24 - 20 | 19 - 15 | 14 - 12 | 11 - 7 | 6 - 0 | + *   0000001    01010      rs1       000      00000  0001011 + * + * dcache.cpa rs1 (clean) + * | 31 - 25 | 24 - 20 | 19 - 15 | 14 - 12 | 11 - 7 | 6 - 0 | + *   0000001    01001      rs1       000      00000  0001011 + * + * dcache.cipa rs1 (clean then invalidate) + * | 31 - 25 | 24 - 20 | 19 - 15 | 14 - 12 | 11 - 7 | 6 - 0 | + *   0000001    01011      rs1       000      00000  0001011 + * + * sync.s + * | 31 - 25 | 24 - 20 | 19 - 15 | 14 - 12 | 11 - 7 | 6 - 0 | + *   0000000    11001     00000      000      00000  0001011 + */ +#define DCACHE_IPA_A0	".long 0x02a5000b" +#define DCACHE_CPA_A0	".long 0x0295000b" +#define DCACHE_CIPA_A0	".long 0x02b5000b" + +#define SYNC_S		".long 0x0190000b" + +void invalidate_dcache_range(unsigned long start, unsigned long end) +{ +	register unsigned long i asm("a0") = start & ~(CONFIG_SYS_CACHELINE_SIZE - 1); +	for (; i < end; i += CONFIG_SYS_CACHELINE_SIZE) +		__asm__ __volatile__(DCACHE_IPA_A0); +	__asm__ __volatile__(SYNC_S); +} + +void flush_dcache_range(unsigned long start, unsigned long end) +{ +	register unsigned long i asm("a0") = start & ~(CONFIG_SYS_CACHELINE_SIZE - 1); +	for (; i < end; i += CONFIG_SYS_CACHELINE_SIZE) +		__asm__ __volatile__(DCACHE_CPA_A0); +	__asm__ __volatile__(SYNC_S); +} | 
