1 // SPDX-License-Identifier: GPL-2.0-or-later
2
3 #include "tst_test.h"
4 #include "lapi/syscalls.h"
5
6 #if __NR_cacheflush != __LTP__NR_INVALID_SYSCALL
7
8 #include <asm/cachectl.h>
9
10 /*
11 * m68k does not have these constants
12 */
13
14 #ifndef ICACHE
15 # define ICACHE (1<<0)
16 #endif
17
18 #ifndef DCACHE
19 # define DCACHE (1<<1)
20 #endif
21
22 #ifndef BCACHE
23 # define BCACHE (ICACHE|DCACHE)
24 #endif
25
26 #define CACHE_DESC(x) .cache = x, .desc = #x
27
28 static struct test_case_t {
29 int cache;
30 const char *desc;
31 } test_cases[] = {
32 { CACHE_DESC(ICACHE) },
33 { CACHE_DESC(DCACHE) },
34 { CACHE_DESC(BCACHE) },
35 };
36
37 static char *addr;
38
setup(void)39 static void setup(void)
40 {
41 addr = SAFE_MALLOC(getpagesize());
42 }
43
test_cacheflush(unsigned int i)44 static void test_cacheflush(unsigned int i)
45 {
46 struct test_case_t *tc = &test_cases[i];
47
48 TST_EXP_PASS(tst_syscall(__NR_cacheflush, addr, getpagesize(), tc->cache),
49 "%s", tc->desc);
50 }
51
52 static struct tst_test test = {
53 .setup = setup,
54 .test = test_cacheflush,
55 .tcnt = ARRAY_SIZE(test_cases),
56 };
57
58 #else
59 TST_TEST_TCONF("system doesn't support cacheflush()");
60 #endif
61