Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:22:52

0001 /*
0002  * Copyright 2016-2021 NXP
0003  * All rights reserved.
0004  *
0005  * SPDX-License-Identifier: BSD-3-Clause
0006  */
0007 
0008 #ifndef _FSL_CACHE_H_
0009 #define _FSL_CACHE_H_
0010 
0011 #include "fsl_common.h"
0012 
0013 /*!
0014  * @addtogroup cache_lmem
0015  * @{
0016  */
0017 
0018 /*******************************************************************************
0019  * Definitions
0020  ******************************************************************************/
0021 
0022 /*! @name Driver version */
0023 /*@{*/
0024 /*! @brief cache driver version. */
0025 #define FSL_CACHE_DRIVER_VERSION (MAKE_VERSION(2, 0, 6))
0026 /*@}*/
0027 
0028 /*! @brief code bus cache line size is equal to system bus line size, so the unified I/D cache line size equals too. */
0029 #define L1CODEBUSCACHE_LINESIZE_BYTE \
0030     FSL_FEATURE_L1ICACHE_LINESIZE_BYTE /*!< The code bus CACHE line size is 16B = 128b. */
0031 #define L1SYSTEMBUSCACHE_LINESIZE_BYTE \
0032     L1CODEBUSCACHE_LINESIZE_BYTE /*!< The system bus CACHE line size is 16B = 128b. */
0033 
0034 /*******************************************************************************
0035  * API
0036  ******************************************************************************/
0037 
0038 #if defined(__cplusplus)
0039 extern "C" {
0040 #endif
0041 
0042 #if (FSL_FEATURE_SOC_LMEM_COUNT == 1)
0043 /*!
0044  * @name cache control for L1 cache (local memory controller for code/system bus cache)
0045  *@{
0046  */
0047 
0048 /*!
0049  * @brief Enables the processor code bus cache.
0050  *
0051  */
0052 void L1CACHE_EnableCodeCache(void);
0053 
0054 /*!
0055  * @brief Disables the processor code bus cache.
0056  *
0057  */
0058 void L1CACHE_DisableCodeCache(void);
0059 
0060 /*!
0061  * @brief Invalidates the processor code bus cache.
0062  *
0063  */
0064 void L1CACHE_InvalidateCodeCache(void);
0065 
0066 /*!
0067  * @brief Invalidates processor code bus cache by range.
0068  *
0069  * @param address The physical address of cache.
0070  * @param size_byte size of the memory to be invalidated.
0071  * @note Address and size should be aligned to "L1CODCACHE_LINESIZE_BYTE".
0072  * The startAddr here will be forced to align to L1CODEBUSCACHE_LINESIZE_BYTE if
0073  * startAddr is not aligned. For the size_byte, application should make sure the
0074  * alignment or make sure the right operation order if the size_byte is not aligned.
0075  */
0076 void L1CACHE_InvalidateCodeCacheByRange(uint32_t address, uint32_t size_byte);
0077 
0078 /*!
0079  * @brief Cleans the processor code bus cache.
0080  *
0081  */
0082 void L1CACHE_CleanCodeCache(void);
0083 
0084 /*!
0085  * @brief Cleans processor code bus cache by range.
0086  *
0087  * @param address The physical address of cache.
0088  * @param size_byte size of the memory to be cleaned.
0089  * @note Address and size should be aligned to "L1CODEBUSCACHE_LINESIZE_BYTE".
0090  * The startAddr here will be forced to align to L1CODEBUSCACHE_LINESIZE_BYTE if
0091  * startAddr is not aligned. For the size_byte, application should make sure the
0092  * alignment or make sure the right operation order if the size_byte is not aligned.
0093  */
0094 void L1CACHE_CleanCodeCacheByRange(uint32_t address, uint32_t size_byte);
0095 
0096 /*!
0097  * @brief Cleans and invalidates the processor code bus cache.
0098  *
0099  */
0100 void L1CACHE_CleanInvalidateCodeCache(void);
0101 
0102 /*!
0103  * @brief Cleans and invalidate processor code bus cache by range.
0104  *
0105  * @param address The physical address of cache.
0106  * @param size_byte size of the memory to be Cleaned and Invalidated.
0107  * @note Address and size should be aligned to "L1CODEBUSCACHE_LINESIZE_BYTE".
0108  * The startAddr here will be forced to align to L1CODEBUSCACHE_LINESIZE_BYTE if
0109  * startAddr is not aligned. For the size_byte, application should make sure the
0110  * alignment or make sure the right operation order if the size_byte is not aligned.
0111  */
0112 void L1CACHE_CleanInvalidateCodeCacheByRange(uint32_t address, uint32_t size_byte);
0113 
0114 /*!
0115  * @brief Enables/disables the processor code bus write buffer.
0116  *
0117  * @param enable The enable or disable flag.
0118  *       true  - enable the code bus write buffer.
0119  *       false - disable the code bus write buffer.
0120  */
0121 static inline void L1CACHE_EnableCodeCacheWriteBuffer(bool enable)
0122 {
0123     if (enable)
0124     {
0125         LMEM->PCCCR |= LMEM_PCCCR_ENWRBUF_MASK;
0126     }
0127     else
0128     {
0129         LMEM->PCCCR &= ~LMEM_PCCCR_ENWRBUF_MASK;
0130     }
0131 }
0132 
0133 #if defined(FSL_FEATURE_LMEM_HAS_SYSTEMBUS_CACHE) && FSL_FEATURE_LMEM_HAS_SYSTEMBUS_CACHE
0134 /*!
0135  * @brief Enables the processor system bus cache.
0136  *
0137  */
0138 void L1CACHE_EnableSystemCache(void);
0139 
0140 /*!
0141  * @brief Disables the processor system bus cache.
0142  *
0143  */
0144 void L1CACHE_DisableSystemCache(void);
0145 
0146 /*!
0147  * @brief Invalidates the processor system bus cache.
0148  *
0149  */
0150 void L1CACHE_InvalidateSystemCache(void);
0151 
0152 /*!
0153  * @brief Invalidates processor system bus cache by range.
0154  *
0155  * @param address The physical address of cache.
0156  * @param size_byte size of the memory to be invalidated.
0157  * @note Address and size should be aligned to "L1SYSTEMBUSCACHE_LINESIZE_BYTE".
0158  * The startAddr here will be forced to align to L1SYSTEMBUSCACHE_LINESIZE_BYTE if
0159  * startAddr is not aligned. For the size_byte, application should make sure the
0160  * alignment or make sure the right operation order if the size_byte is not aligned.
0161  */
0162 void L1CACHE_InvalidateSystemCacheByRange(uint32_t address, uint32_t size_byte);
0163 
0164 /*!
0165  * @brief Cleans the processor system bus cache.
0166  *
0167  */
0168 void L1CACHE_CleanSystemCache(void);
0169 
0170 /*!
0171  * @brief Cleans processor system bus cache by range.
0172  *
0173  * @param address The physical address of cache.
0174  * @param size_byte size of the memory to be cleaned.
0175  * @note Address and size should be aligned to "L1SYSTEMBUSCACHE_LINESIZE_BYTE".
0176  * The startAddr here will be forced to align to L1SYSTEMBUSCACHE_LINESIZE_BYTE if
0177  * startAddr is not aligned. For the size_byte, application should make sure the
0178  * alignment or make sure the right operation order if the size_byte is not aligned.
0179  */
0180 void L1CACHE_CleanSystemCacheByRange(uint32_t address, uint32_t size_byte);
0181 
0182 /*!
0183  * @brief Cleans and invalidates the processor system bus cache.
0184  *
0185  */
0186 void L1CACHE_CleanInvalidateSystemCache(void);
0187 
0188 /*!
0189  * @brief Cleans and Invalidates processor system bus cache by range.
0190  *
0191  * @param address The physical address of cache.
0192  * @param size_byte size of the memory to be Clean and Invalidated.
0193  * @note Address and size should be aligned to "L1SYSTEMBUSCACHE_LINESIZE_BYTE".
0194  * The startAddr here will be forced to align to L1SYSTEMBUSCACHE_LINESIZE_BYTE if
0195  * startAddr is not aligned. For the size_byte, application should make sure the
0196  * alignment or make sure the right operation order if the size_byte is not aligned.
0197  */
0198 void L1CACHE_CleanInvalidateSystemCacheByRange(uint32_t address, uint32_t size_byte);
0199 
0200 /*!
0201  * @brief Enables/disables the processor system bus write buffer.
0202  *
0203  * @param enable The enable or disable flag.
0204  *       true  - enable the code bus write buffer.
0205  *       false - disable the code bus write buffer.
0206  */
0207 static inline void L1CACHE_EnableSystemCacheWriteBuffer(bool enable)
0208 {
0209     if (enable)
0210     {
0211         LMEM->PSCCR |= LMEM_PSCCR_ENWRBUF_MASK;
0212     }
0213     else
0214     {
0215         LMEM->PSCCR &= ~LMEM_PSCCR_ENWRBUF_MASK;
0216     }
0217 }
0218 /*@}*/
0219 #endif /* FSL_FEATURE_LMEM_HAS_SYSTEMBUS_CACHE */
0220 
0221 /*!
0222  * @name cache control for unified L1 cache driver
0223  *@{
0224  */
0225 
0226 /*!
0227  * @brief Invalidates cortex-m4 L1 instrument cache by range.
0228  *
0229  * @param address  The start address of the memory to be invalidated.
0230  * @param size_byte  The memory size.
0231  * @note The start address and size_byte should be 16-Byte(FSL_FEATURE_L1ICACHE_LINESIZE_BYTE) aligned.
0232  */
0233 void L1CACHE_InvalidateICacheByRange(uint32_t address, uint32_t size_byte);
0234 
0235 /*!
0236  * @brief Invalidates cortex-m4 L1 data cache by range.
0237  *
0238  * @param address  The start address of the memory to be invalidated.
0239  * @param size_byte  The memory size.
0240  * @note The start address and size_byte should be 16-Byte(FSL_FEATURE_L1DCACHE_LINESIZE_BYTE) aligned.
0241  */
0242 static inline void L1CACHE_InvalidateDCacheByRange(uint32_t address, uint32_t size_byte)
0243 {
0244     L1CACHE_InvalidateICacheByRange(address, size_byte);
0245 }
0246 
0247 /*!
0248  * @brief Cleans cortex-m4 L1 data cache by range.
0249  *
0250  * @param address  The start address of the memory to be cleaned.
0251  * @param size_byte  The memory size.
0252  * @note The start address and size_byte should be 16-Byte(FSL_FEATURE_L1DCACHE_LINESIZE_BYTE) aligned.
0253  */
0254 void L1CACHE_CleanDCacheByRange(uint32_t address, uint32_t size_byte);
0255 
0256 /*!
0257  * @brief Cleans and Invalidates cortex-m4 L1 data cache by range.
0258  *
0259  * @param address  The start address of the memory to be clean and invalidated.
0260  * @param size_byte  The memory size.
0261  * @note The start address and size_byte should be 16-Byte(FSL_FEATURE_L1DCACHE_LINESIZE_BYTE) aligned.
0262  */
0263 void L1CACHE_CleanInvalidateDCacheByRange(uint32_t address, uint32_t size_byte);
0264 /*@}*/
0265 #endif /* FSL_FEATURE_SOC_LMEM_COUNT == 1 */
0266 
0267 /*!
0268  * @name Unified Cache Control for all caches
0269  *@{
0270  */
0271 
0272 /*!
0273  * @brief Invalidates instruction cache by range.
0274  *
0275  * @param address The physical address.
0276  * @param size_byte size of the memory to be invalidated.
0277  * @note Address and size should be aligned to 16-Byte due to the cache operation unit
0278  * FSL_FEATURE_L1ICACHE_LINESIZE_BYTE. The startAddr here will be forced to align to the cache line
0279  * size if startAddr is not aligned. For the size_byte, application should make sure the
0280  * alignment or make sure the right operation order if the size_byte is not aligned.
0281  */
0282 static inline void ICACHE_InvalidateByRange(uint32_t address, uint32_t size_byte)
0283 {
0284     L1CACHE_InvalidateICacheByRange(address, size_byte);
0285 }
0286 
0287 /*!
0288  * @brief Invalidates data cache by range.
0289  *
0290  * @param address The physical address.
0291  * @param size_byte size of the memory to be invalidated.
0292  * @note Address and size should be aligned to 16-Byte due to the cache operation unit
0293  * FSL_FEATURE_L1DCACHE_LINESIZE_BYTE. The startAddr here will be forced to align to the cache line
0294  * size if startAddr is not aligned. For the size_byte, application should make sure the
0295  * alignment or make sure the right operation order if the size_byte is not aligned.
0296  */
0297 static inline void DCACHE_InvalidateByRange(uint32_t address, uint32_t size_byte)
0298 {
0299     L1CACHE_InvalidateDCacheByRange(address, size_byte);
0300 }
0301 
0302 /*!
0303  * @brief Clean data cache by range.
0304  *
0305  * @param address The physical address.
0306  * @param size_byte size of the memory to be cleaned.
0307  * @note Address and size should be aligned to 16-Byte due to the cache operation unit
0308  * FSL_FEATURE_L1DCACHE_LINESIZE_BYTE. The startAddr here will be forced to align to the cache line
0309  * size if startAddr is not aligned. For the size_byte, application should make sure the
0310  * alignment or make sure the right operation order if the size_byte is not aligned.
0311  */
0312 static inline void DCACHE_CleanByRange(uint32_t address, uint32_t size_byte)
0313 {
0314     L1CACHE_CleanDCacheByRange(address, size_byte);
0315 }
0316 
0317 /*!
0318  * @brief Cleans and Invalidates data cache by range.
0319  *
0320  * @param address The physical address.
0321  * @param size_byte size of the memory to be Cleaned and Invalidated.
0322  * @note Address and size should be aligned to 16-Byte due to the cache operation unit
0323  * FSL_FEATURE_L1DCACHE_LINESIZE_BYTE. The startAddr here will be forced to align to the cache line
0324  * size if startAddr is not aligned. For the size_byte, application should make sure the
0325  * alignment or make sure the right operation order if the size_byte is not aligned.
0326  */
0327 static inline void DCACHE_CleanInvalidateByRange(uint32_t address, uint32_t size_byte)
0328 {
0329     L1CACHE_CleanInvalidateDCacheByRange(address, size_byte);
0330 }
0331 
0332 /*@}*/
0333 
0334 #if defined(__cplusplus)
0335 }
0336 #endif
0337 
0338 /*! @}*/
0339 
0340 #endif /* _FSL_CACHE_H_*/