|
7 | 7 | #include <zephyr/init.h>
|
8 | 8 | #include <zephyr/cache.h>
|
9 | 9 | #include <zephyr/logging/log.h>
|
10 |
| -#include "soc.h" |
| 10 | +#include <zephyr/mem_mgmt/mem_attr.h> |
| 11 | +#ifdef CONFIG_DCACHE |
| 12 | +#include <zephyr/dt-bindings/memory-attr/memory-attr-arm.h> |
| 13 | +#endif /* CONFIG_DCACHE */ |
| 14 | + |
| 15 | +#ifdef CONFIG_NOCACHE_MEMORY |
| 16 | +#include <zephyr/linker/linker-defs.h> |
| 17 | +#endif /* CONFIG_NOCACHE_MEMORY */ |
| 18 | + |
| 19 | +#include <soc.h> |
11 | 20 |
|
12 | 21 | LOG_MODULE_REGISTER(soc, CONFIG_SOC_LOG_LEVEL);
|
13 | 22 |
|
@@ -48,3 +57,25 @@ void soc_early_init_hook(void)
|
48 | 57 | /* Enable Dcache */
|
49 | 58 | sys_cache_data_enable();
|
50 | 59 | }
|
| 60 | + |
| 61 | +#if CONFIG_CACHE_MANAGEMENT |
| 62 | +bool buf_in_nocache(uintptr_t buf, size_t len_bytes) |
| 63 | +{ |
| 64 | + bool buf_within_nocache = false; |
| 65 | + |
| 66 | +#if CONFIG_NOCACHE_MEMORY |
| 67 | + /* Check if buffer is in nocache region defined by the linker */ |
| 68 | + buf_within_nocache = (buf >= ((uintptr_t)_nocache_ram_start)) && |
| 69 | + ((buf + len_bytes - 1) <= ((uintptr_t)_nocache_ram_end)); |
| 70 | + if (buf_within_nocache) { |
| 71 | + return true; |
| 72 | + } |
| 73 | +#endif /* CONFIG_NOCACHE_MEMORY */ |
| 74 | + |
| 75 | + /* Check if buffer is in nocache memory region defined in DT */ |
| 76 | + buf_within_nocache = mem_attr_check_buf((void *)buf, len_bytes, |
| 77 | + DT_MEM_ARM(ATTR_MPU_RAM_NOCACHE)) == 0; |
| 78 | + |
| 79 | + return buf_within_nocache; |
| 80 | +} |
| 81 | +#endif |
0 commit comments