summaryrefslogtreecommitdiff
path: root/src/linux/cache.c
blob: 0eb051c2d4acecbce4ca780413f125369ffecf14 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <errno.h>
#include "syscall.h"
#include "atomic.h"

#ifdef SYS_cacheflush
int _flush_cache(void *addr, int len, int op)
{
	return syscall(SYS_cacheflush, addr, len, op);
}
weak_alias(_flush_cache, cacheflush);
#endif

#ifdef SYS_cachectl
int __cachectl(void *addr, int len, int op)
{
	return syscall(SYS_cachectl, addr, len, op);
}
weak_alias(__cachectl, cachectl);
#endif

#ifdef SYS_riscv_flush_icache

#define VDSO_FLUSH_ICACHE_SYM "__vdso_flush_icache"
#define VDSO_FLUSH_ICACHE_VER "LINUX_4.5"

static void *volatile vdso_func;

static int flush_icache_init(void *start, void *end, unsigned long int flags)
{
	void *p = __vdsosym(VDSO_FLUSH_ICACHE_VER, VDSO_FLUSH_ICACHE_SYM);
	int (*f)(void *, void *, unsigned long int) =
		(int (*)(void *, void *, unsigned long int))p;
	a_cas_p(&vdso_func, (void *)flush_icache_init, p);
	return f ? f(start, end, flags) : -ENOSYS;
}

static void *volatile vdso_func = (void *)flush_icache_init;

int __riscv_flush_icache(void *start, void *end, unsigned long int flags) 
{
	int (*f)(void *, void *, unsigned long int) =
		(int (*)(void *, void *, unsigned long int))vdso_func;
	if (f) {
		int r = f(start, end, flags);
		if (!r) return r;
		if (r != -ENOSYS) return __syscall_ret(r);
	}
}
weak_alias(__riscv_flush_icache, riscv_flush_icache);
#endif