1 /*
2 * Copyright (c) 2022 Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/ztest.h>
8 #include <zephyr/cache.h>
9 #include <adsp_memory.h>
10
ZTEST(adsp_cache,test_adsp_cache_flush_inv_all)11 ZTEST(adsp_cache, test_adsp_cache_flush_inv_all)
12 {
13 uint32_t *cached, *uncached;
14
15 cached = (uint32_t *)LP_SRAM_BASE;
16 uncached = sys_cache_uncached_ptr_get(cached);
17
18 *cached = 42;
19 *uncached = 40;
20
21 /* Just some sanity checks */
22 zassert_equal(*cached, 42, NULL);
23 zassert_equal(*uncached, 40, NULL);
24
25 sys_cache_data_flush_and_invd_all();
26
27 /* After sys_cache_data_flush_and_invd_all(), uncached should be updated */
28 zassert_equal(*cached, 42, NULL);
29 zassert_equal(*uncached, 42, NULL);
30
31 /* Flush and invalidate again, this time to check the invalidate part */
32 sys_cache_data_flush_and_invd_all();
33 *uncached = 80;
34
35 /* As cache is invalid, cached should be updated with uncached new value */
36 zassert_equal(*cached, 80, NULL);
37 zassert_equal(*uncached, 80, NULL);
38
39 *cached = 82;
40
41 /* Only cached should have changed */
42 zassert_equal(*cached, 82, NULL);
43 zassert_equal(*uncached, 80, NULL);
44
45 sys_cache_data_flush_all();
46
47 /* After sys_cache_data_flush_all(), uncached should be updated */
48 zassert_equal(*cached, 82, NULL);
49 zassert_equal(*uncached, 82, NULL);
50
51 *uncached = 100;
52
53 /* As cache is not invalid, only uncached should be updated */
54 zassert_equal(*cached, 82, NULL);
55 zassert_equal(*uncached, 100, NULL);
56
57 sys_cache_data_invd_all();
58
59 /* Now, cached should be updated */
60 zassert_equal(*cached, 100, NULL);
61 zassert_equal(*uncached, 100, NULL);
62 }
63
64 ZTEST_SUITE(adsp_cache, NULL, NULL, NULL, NULL, NULL);
65