2015-09-18 22:36:57 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015 Wind River Systems, Inc.
|
|
|
|
*
|
2017-01-19 02:01:01 +01:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2015-09-18 22:36:57 +02:00
|
|
|
*/
|
|
|
|
|
2018-09-14 19:43:44 +02:00
|
|
|
#ifndef ZEPHYR_INCLUDE_CACHE_H_
|
|
|
|
#define ZEPHYR_INCLUDE_CACHE_H_
|
2015-09-18 22:36:57 +02:00
|
|
|
|
2016-12-23 13:32:56 +01:00
|
|
|
#include <kernel.h>
|
2015-09-18 22:36:57 +02:00
|
|
|
|
2016-01-22 18:38:49 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2020-04-28 22:14:54 +02:00
|
|
|
void arch_dcache_flush(void *addr, size_t size);
|
|
|
|
void arch_dcache_invd(void *addr, size_t size);
|
2015-09-18 22:36:57 +02:00
|
|
|
|
2020-04-28 22:14:54 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @brief Flush d-cache lines to main memory
|
2015-10-30 22:04:00 +01:00
|
|
|
*
|
2020-04-28 22:14:54 +02:00
|
|
|
* No alignment is required for either addr or size, but since
|
|
|
|
* sys_cache_flush() iterates on the d-cache lines, a d-cache line alignment for
|
|
|
|
* both is optimal.
|
|
|
|
*
|
|
|
|
* The d-cache line size is specified either via the CONFIG_CACHE_LINE_SIZE
|
|
|
|
* kconfig option or it is detected at runtime.
|
|
|
|
*
|
|
|
|
* @param addr the pointer to start the multi-line flush
|
|
|
|
* @param size the number of bytes that are to be flushed
|
|
|
|
*
|
|
|
|
* @return N/A
|
2015-10-30 22:04:00 +01:00
|
|
|
*/
|
2020-04-28 22:14:54 +02:00
|
|
|
static inline void sys_cache_flush(void *addr, size_t size)
|
2015-10-30 22:04:00 +01:00
|
|
|
{
|
2020-04-28 22:14:54 +02:00
|
|
|
if (IS_ENABLED(CONFIG_CACHE_FLUSHING)) {
|
|
|
|
arch_dcache_flush(addr, size);
|
|
|
|
}
|
2015-10-30 22:04:00 +01:00
|
|
|
}
|
|
|
|
|
2020-04-28 22:14:54 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @brief Invalidate d-cache lines
|
|
|
|
*
|
|
|
|
* No alignment is required for either addr or size, but since
|
|
|
|
* sys_cache_invd() iterates on the d-cache lines, a d-cache line alignment for
|
|
|
|
* both is optimal.
|
|
|
|
*
|
|
|
|
* The d-cache line size is specified either via the CONFIG_CACHE_LINE_SIZE
|
|
|
|
* kconfig option or it is detected at runtime.
|
|
|
|
*
|
|
|
|
* @param addr the pointer to start address
|
|
|
|
* @param size the number of bytes that are to be invalidated
|
|
|
|
*
|
|
|
|
* @return N/A
|
|
|
|
*/
|
|
|
|
static inline void sys_cache_invd(void *addr, size_t size)
|
|
|
|
{
|
|
|
|
if (IS_ENABLED(CONFIG_CACHE_FLUSHING)) {
|
|
|
|
arch_dcache_invd(addr, size);
|
|
|
|
}
|
|
|
|
}
|
2015-09-18 22:36:57 +02:00
|
|
|
|
2020-04-28 22:14:54 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @brief Get the d-cache line size.
|
|
|
|
*
|
|
|
|
* The API is provided to get the cache line size.
|
|
|
|
*
|
|
|
|
* @return size of the cache line or 0 if the cache is not enabled.
|
|
|
|
*/
|
|
|
|
static inline size_t sys_cache_line_size_get(void)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_CACHE_FLUSHING
|
|
|
|
#ifdef CONFIG_CACHE_LINE_SIZE
|
|
|
|
return CONFIG_CACHE_LINE_SIZE;
|
2015-10-30 22:04:00 +01:00
|
|
|
#else
|
2020-04-28 22:14:54 +02:00
|
|
|
return arch_cache_line_size_get();
|
|
|
|
#endif /* CONFIG_CACHE_LINE_SIZE */
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif /* CONFIG_CACHE_FLUSHING */
|
|
|
|
}
|
2015-09-18 22:36:57 +02:00
|
|
|
|
2016-01-22 18:38:49 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-09-14 19:43:44 +02:00
|
|
|
#endif /* ZEPHYR_INCLUDE_CACHE_H_ */
|