• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
2  * Licensed under the Apache License, Version 2.0 (the "License");
3  * you may not use this file except in compliance with the License.
4  * You may obtain a copy of the License at
5  *
6  *	 http://www.apache.org/licenses/LICENSE-2.0
7  *
8  * Unless required by applicable law or agreed to in writing, software
9  * distributed under the License is distributed on an "AS IS" BASIS,
10  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11  * See the License for the specific language governing permissions and
12  * limitations under the License.
13  */
14 
15 #include <errno.h>
16 #include "syscall.h"
17 #include "atomic.h"
18 
19 #ifdef SYS_cacheflush
_flush_cache(void * addr,int len,int op)20 int _flush_cache(void *addr, int len, int op)
21 {
22 	return syscall(SYS_cacheflush, addr, len, op);
23 }
24 weak_alias(_flush_cache, cacheflush);
25 #endif
26 
27 #ifdef SYS_cachectl
__cachectl(void * addr,int len,int op)28 int __cachectl(void *addr, int len, int op)
29 {
30 	return syscall(SYS_cachectl, addr, len, op);
31 }
32 weak_alias(__cachectl, cachectl);
33 #endif
34 
35 #ifdef SYS_riscv_flush_icache
36 
37 #define VDSO_FLUSH_ICACHE_SYM "__vdso_flush_icache"
38 #define VDSO_FLUSH_ICACHE_VER "LINUX_4.5"
39 
40 static void *volatile vdso_func;
41 
flush_icache_init(void * start,void * end,unsigned long int flags)42 static int flush_icache_init(void *start, void *end, unsigned long int flags)
43 {
44         __get_vdso_info();
45 	void *p = __get_vdso_addr(VDSO_FLUSH_ICACHE_VER, VDSO_FLUSH_ICACHE_SYM);
46 	int (*f)(void *, void *, unsigned long int) =
47 		(int (*)(void *, void *, unsigned long int))p;
48 	a_cas_p(&vdso_func, (void *)flush_icache_init, p);
49 	return f ? f(start, end, flags) : -ENOSYS;
50 }
51 
52 static void *volatile vdso_func = (void *)flush_icache_init;
53 
__riscv_flush_icache(void * start,void * end,unsigned long int flags)54 int __riscv_flush_icache(void *start, void *end, unsigned long int flags)
55 {
56 	int (*f)(void *, void *, unsigned long int) =
57 		(int (*)(void *, void *, unsigned long int))vdso_func;
58 	if (f) {
59 		int r = f(start, end, flags);
60 		if (!r) return r;
61 		if (r != -ENOSYS) return __syscall_ret(r);
62 	}
63 }
64 weak_alias(__riscv_flush_icache, riscv_flush_icache);
65 #endif
66