![]() |
|
|||
File indexing completed on 2025-05-11 08:22:58
0001 /* 0002 * Copyright 2016-2021 NXP 0003 * All rights reserved. 0004 * 0005 * SPDX-License-Identifier: BSD-3-Clause 0006 */ 0007 #ifndef _FSL_CACHE_H_ 0008 #define _FSL_CACHE_H_ 0009 0010 #include "fsl_common.h" 0011 0012 /*! 0013 * @addtogroup cache_armv7_m7 0014 * @{ 0015 */ 0016 0017 /******************************************************************************* 0018 * Definitions 0019 ******************************************************************************/ 0020 0021 /*! @name Driver version */ 0022 /*@{*/ 0023 /*! @brief cache driver version 2.0.4. */ 0024 #define FSL_CACHE_DRIVER_VERSION (MAKE_VERSION(2, 0, 4)) 0025 /*@}*/ 0026 0027 #if defined(FSL_FEATURE_SOC_L2CACHEC_COUNT) && FSL_FEATURE_SOC_L2CACHEC_COUNT 0028 #ifndef FSL_SDK_DISBLE_L2CACHE_PRESENT 0029 #define FSL_SDK_DISBLE_L2CACHE_PRESENT 0 0030 #endif 0031 #endif /* FSL_FEATURE_SOC_L2CACHEC_COUNT */ 0032 /******************************************************************************* 0033 * Definitions 0034 ******************************************************************************/ 0035 #if defined(FSL_FEATURE_SOC_L2CACHEC_COUNT) && FSL_FEATURE_SOC_L2CACHEC_COUNT 0036 0037 /*! @brief Number of level 2 cache controller ways. */ 0038 typedef enum _l2cache_way_num 0039 { 0040 kL2CACHE_8ways = 0, /*!< 8 ways. */ 0041 #if defined(FSL_FEATURE_L2CACHE_SUPPORT_16_WAY_ASSOCIATIVITY) && FSL_FEATURE_L2CACHE_SUPPORT_16_WAY_ASSOCIATIVITY 0042 kL2CACHE_16ways /*!< 16 ways. */ 0043 #endif /* FSL_FEATURE_L2CACHE_SUPPORT_16_WAY_ASSOCIATIVITY */ 0044 } l2cache_way_num_t; 0045 0046 /*! @brief Level 2 cache controller way size. */ 0047 typedef enum _l2cache_way_size 0048 { 0049 kL2CACHE_16KBSize = 1, /*!< 16 KB way size. */ 0050 kL2CACHE_32KBSize = 2, /*!< 32 KB way size. */ 0051 kL2CACHE_64KBSize = 3, /*!< 64 KB way size. */ 0052 kL2CACHE_128KBSize = 4, /*!< 128 KB way size. */ 0053 kL2CACHE_256KBSize = 5, /*!< 256 KB way size. */ 0054 kL2CACHE_512KBSize = 6 /*!< 512 KB way size. */ 0055 } l2cache_way_size; 0056 0057 /*! @brief Level 2 cache controller replacement policy. */ 0058 typedef enum _l2cache_replacement 0059 { 0060 kL2CACHE_Pseudorandom = 0U, /*!< Peseudo-random replacement policy using an lfsr. */ 0061 kL2CACHE_Roundrobin /*!< Round-robin replacemnt policy. */ 0062 } l2cache_replacement_t; 0063 0064 /*! @brief Level 2 cache controller force write allocate options. */ 0065 typedef enum _l2cache_writealloc 0066 { 0067 kL2CACHE_UseAwcache = 0, /*!< Use AWCAHE attribute for the write allocate. */ 0068 kL2CACHE_NoWriteallocate, /*!< Force no write allocate. */ 0069 kL2CACHE_forceWriteallocate /*!< Force write allocate when write misses. */ 0070 } l2cache_writealloc_t; 0071 0072 /*! @brief Level 2 cache controller tag/data ram latency. */ 0073 typedef enum _l2cache_latency 0074 { 0075 kL2CACHE_1CycleLate = 0, /*!< 1 cycle of latency. */ 0076 kL2CACHE_2CycleLate, /*!< 2 cycle of latency. */ 0077 kL2CACHE_3CycleLate, /*!< 3 cycle of latency. */ 0078 kL2CACHE_4CycleLate, /*!< 4 cycle of latency. */ 0079 kL2CACHE_5CycleLate, /*!< 5 cycle of latency. */ 0080 kL2CACHE_6CycleLate, /*!< 6 cycle of latency. */ 0081 kL2CACHE_7CycleLate, /*!< 7 cycle of latency. */ 0082 kL2CACHE_8CycleLate /*!< 8 cycle of latency. */ 0083 } l2cache_latency_t; 0084 0085 /*! @brief Level 2 cache controller tag/data ram latency configure structure. */ 0086 typedef struct _l2cache_latency_config 0087 { 0088 l2cache_latency_t tagWriteLate; /*!< Tag write latency. */ 0089 l2cache_latency_t tagReadLate; /*!< Tag Read latency. */ 0090 l2cache_latency_t tagSetupLate; /*!< Tag setup latency. */ 0091 l2cache_latency_t dataWriteLate; /*!< Data write latency. */ 0092 l2cache_latency_t dataReadLate; /*!< Data Read latency. */ 0093 l2cache_latency_t dataSetupLate; /*!< Data setup latency. */ 0094 } L2cache_latency_config_t; 0095 0096 /*! @brief Level 2 cache controller configure structure. */ 0097 typedef struct _l2cache_config 0098 { 0099 /* ------------------------ l2 cachec basic settings ---------------------------- */ 0100 l2cache_way_num_t wayNum; /*!< The number of ways. */ 0101 l2cache_way_size waySize; /*!< The way size = Cache Ram size / wayNum. */ 0102 l2cache_replacement_t repacePolicy; /*!< Replacemnet policy. */ 0103 /* ------------------------ tag/data ram latency settings ----------------------- */ 0104 L2cache_latency_config_t *lateConfig; /*!< Tag/data latency configure. Set NUll if not required. */ 0105 /* ------------------------ Prefetch enable settings ---------------------------- */ 0106 bool istrPrefetchEnable; /*!< Instruction prefetch enable. */ 0107 bool dataPrefetchEnable; /*!< Data prefetch enable. */ 0108 /* ------------------------ Non-secure access settings -------------------------- */ 0109 bool nsLockdownEnable; /*!< None-secure lockdown enable. */ 0110 /* ------------------------ other settings -------------------------------------- */ 0111 l2cache_writealloc_t writeAlloc; /*!< Write allcoate force option. */ 0112 } l2cache_config_t; 0113 #endif /* FSL_FEATURE_SOC_L2CACHEC_COUNT */ 0114 /******************************************************************************* 0115 * API 0116 ******************************************************************************/ 0117 0118 #if defined(__cplusplus) 0119 extern "C" { 0120 #endif 0121 0122 /*! 0123 * @name Control for cortex-m7 L1 cache 0124 *@{ 0125 */ 0126 0127 /*! 0128 * @brief Enables cortex-m7 L1 instruction cache. 0129 * 0130 */ 0131 static inline void L1CACHE_EnableICache(void) 0132 { 0133 SCB_EnableICache(); 0134 } 0135 0136 /*! 0137 * @brief Disables cortex-m7 L1 instruction cache. 0138 * 0139 */ 0140 static inline void L1CACHE_DisableICache(void) 0141 { 0142 if (SCB_CCR_IC_Msk == (SCB_CCR_IC_Msk & SCB->CCR)) 0143 { 0144 SCB_DisableICache(); 0145 } 0146 } 0147 0148 /*! 0149 * @brief Invalidate cortex-m7 L1 instruction cache. 0150 * 0151 */ 0152 static inline void L1CACHE_InvalidateICache(void) 0153 { 0154 SCB_InvalidateICache(); 0155 } 0156 0157 /*! 0158 * @brief Invalidate cortex-m7 L1 instruction cache by range. 0159 * 0160 * @param address The start address of the memory to be invalidated. 0161 * @param size_byte The memory size. 0162 * @note The start address and size_byte should be 32-byte(FSL_FEATURE_L1ICACHE_LINESIZE_BYTE) aligned. 0163 * The startAddr here will be forced to align to L1 I-cache line size if 0164 * startAddr is not aligned. For the size_byte, application should make sure the 0165 * alignment or make sure the right operation order if the size_byte is not aligned. 0166 */ 0167 void L1CACHE_InvalidateICacheByRange(uint32_t address, uint32_t size_byte); 0168 0169 /*! 0170 * @brief Enables cortex-m7 L1 data cache. 0171 * 0172 */ 0173 static inline void L1CACHE_EnableDCache(void) 0174 { 0175 SCB_EnableDCache(); 0176 } 0177 0178 /*! 0179 * @brief Disables cortex-m7 L1 data cache. 0180 * 0181 */ 0182 static inline void L1CACHE_DisableDCache(void) 0183 { 0184 if (SCB_CCR_DC_Msk == (SCB_CCR_DC_Msk & SCB->CCR)) 0185 { 0186 SCB_DisableDCache(); 0187 } 0188 } 0189 0190 /*! 0191 * @brief Invalidates cortex-m7 L1 data cache. 0192 * 0193 */ 0194 static inline void L1CACHE_InvalidateDCache(void) 0195 { 0196 SCB_InvalidateDCache(); 0197 } 0198 0199 /*! 0200 * @brief Cleans cortex-m7 L1 data cache. 0201 * 0202 */ 0203 static inline void L1CACHE_CleanDCache(void) 0204 { 0205 SCB_CleanDCache(); 0206 } 0207 0208 /*! 0209 * @brief Cleans and Invalidates cortex-m7 L1 data cache. 0210 * 0211 */ 0212 static inline void L1CACHE_CleanInvalidateDCache(void) 0213 { 0214 SCB_CleanInvalidateDCache(); 0215 } 0216 0217 /*! 0218 * @brief Invalidates cortex-m7 L1 data cache by range. 0219 * 0220 * @param address The start address of the memory to be invalidated. 0221 * @param size_byte The memory size. 0222 * @note The start address and size_byte should be 32-byte(FSL_FEATURE_L1DCACHE_LINESIZE_BYTE) aligned. 0223 * The startAddr here will be forced to align to L1 D-cache line size if 0224 * startAddr is not aligned. For the size_byte, application should make sure the 0225 * alignment or make sure the right operation order if the size_byte is not aligned. 0226 */ 0227 static inline void L1CACHE_InvalidateDCacheByRange(uint32_t address, uint32_t size_byte) 0228 { 0229 SCB_InvalidateDCache_by_Addr((uint32_t *)address, (int32_t)size_byte); 0230 } 0231 0232 /*! 0233 * @brief Cleans cortex-m7 L1 data cache by range. 0234 * 0235 * @param address The start address of the memory to be cleaned. 0236 * @param size_byte The memory size. 0237 * @note The start address and size_byte should be 32-byte(FSL_FEATURE_L1DCACHE_LINESIZE_BYTE) aligned. 0238 * The startAddr here will be forced to align to L1 D-cache line size if 0239 * startAddr is not aligned. For the size_byte, application should make sure the 0240 * alignment or make sure the right operation order if the size_byte is not aligned. 0241 */ 0242 static inline void L1CACHE_CleanDCacheByRange(uint32_t address, uint32_t size_byte) 0243 { 0244 SCB_CleanDCache_by_Addr((uint32_t *)address, (int32_t)size_byte); 0245 } 0246 0247 /*! 0248 * @brief Cleans and Invalidates cortex-m7 L1 data cache by range. 0249 * 0250 * @param address The start address of the memory to be clean and invalidated. 0251 * @param size_byte The memory size. 0252 * @note The start address and size_byte should be 32-byte(FSL_FEATURE_L1DCACHE_LINESIZE_BYTE) aligned. 0253 * The startAddr here will be forced to align to L1 D-cache line size if 0254 * startAddr is not aligned. For the size_byte, application should make sure the 0255 * alignment or make sure the right operation order if the size_byte is not aligned. 0256 */ 0257 static inline void L1CACHE_CleanInvalidateDCacheByRange(uint32_t address, uint32_t size_byte) 0258 { 0259 SCB_CleanInvalidateDCache_by_Addr((uint32_t *)address, (int32_t)size_byte); 0260 } 0261 /*@}*/ 0262 0263 #if defined(FSL_FEATURE_SOC_L2CACHEC_COUNT) && FSL_FEATURE_SOC_L2CACHEC_COUNT 0264 /*! 0265 * @name Control for L2 pl310 cache 0266 *@{ 0267 */ 0268 0269 /*! 0270 * @brief Initializes the level 2 cache controller module. 0271 * 0272 * @param config Pointer to configuration structure. See "l2cache_config_t". 0273 */ 0274 void L2CACHE_Init(l2cache_config_t *config); 0275 0276 /*! 0277 * @brief Gets an available default settings for the cache controller. 0278 * 0279 * This function initializes the cache controller configuration structure with default settings. 0280 * The default values are: 0281 * @code 0282 * config->waysNum = kL2CACHE_8ways; 0283 * config->waySize = kL2CACHE_32KbSize; 0284 * config->repacePolicy = kL2CACHE_Roundrobin; 0285 * config->lateConfig = NULL; 0286 * config->istrPrefetchEnable = false; 0287 * config->dataPrefetchEnable = false; 0288 * config->nsLockdownEnable = false; 0289 * config->writeAlloc = kL2CACHE_UseAwcache; 0290 * @endcode 0291 * @param config Pointer to the configuration structure. 0292 */ 0293 void L2CACHE_GetDefaultConfig(l2cache_config_t *config); 0294 0295 /*! 0296 * @brief Enables the level 2 cache controller. 0297 * This function enables the cache controller. Must be written using a secure access. 0298 * If write with a Non-secure access will cause a DECERR response. 0299 * 0300 */ 0301 void L2CACHE_Enable(void); 0302 0303 /*! 0304 * @brief Disables the level 2 cache controller. 0305 * This function disables the cache controller. Must be written using a secure access. 0306 * If write with a Non-secure access will cause a DECERR response. 0307 * 0308 */ 0309 void L2CACHE_Disable(void); 0310 0311 /*! 0312 * @brief Invalidates the Level 2 cache. 0313 * This function invalidates all entries in cache. 0314 * 0315 */ 0316 void L2CACHE_Invalidate(void); 0317 0318 /*! 0319 * @brief Invalidates the Level 2 cache lines in the range of two physical addresses. 0320 * This function invalidates all cache lines between two physical addresses. 0321 * 0322 * @param address The start address of the memory to be invalidated. 0323 * @param size_byte The memory size. 0324 * @note The start address and size_byte should be 32-byte(FSL_FEATURE_L2CACHE_LINESIZE_BYTE) aligned. 0325 * The startAddr here will be forced to align to L2 line size if startAddr 0326 * is not aligned. For the size_byte, application should make sure the 0327 * alignment or make sure the right operation order if the size_byte is not aligned. 0328 */ 0329 void L2CACHE_InvalidateByRange(uint32_t address, uint32_t size_byte); 0330 0331 /*! 0332 * @brief Cleans the level 2 cache controller. 0333 * This function cleans all entries in the level 2 cache controller. 0334 * 0335 */ 0336 void L2CACHE_Clean(void); 0337 0338 /*! 0339 * @brief Cleans the Level 2 cache lines in the range of two physical addresses. 0340 * This function cleans all cache lines between two physical addresses. 0341 * 0342 * @param address The start address of the memory to be cleaned. 0343 * @param size_byte The memory size. 0344 * @note The start address and size_byte should be 32-byte(FSL_FEATURE_L2CACHE_LINESIZE_BYTE) aligned. 0345 * The startAddr here will be forced to align to L2 line size if startAddr 0346 * is not aligned. For the size_byte, application should make sure the 0347 * alignment or make sure the right operation order if the size_byte is not aligned. 0348 */ 0349 void L2CACHE_CleanByRange(uint32_t address, uint32_t size_byte); 0350 0351 /*! 0352 * @brief Cleans and invalidates the level 2 cache controller. 0353 * This function cleans and invalidates all entries in the level 2 cache controller. 0354 * 0355 */ 0356 void L2CACHE_CleanInvalidate(void); 0357 0358 /*! 0359 * @brief Cleans and invalidates the Level 2 cache lines in the range of two physical addresses. 0360 * This function cleans and invalidates all cache lines between two physical addresses. 0361 * 0362 * @param address The start address of the memory to be cleaned and invalidated. 0363 * @param size_byte The memory size. 0364 * @note The start address and size_byte should be 32-byte(FSL_FEATURE_L2CACHE_LINESIZE_BYTE) aligned. 0365 * The startAddr here will be forced to align to L2 line size if startAddr 0366 * is not aligned. For the size_byte, application should make sure the 0367 * alignment or make sure the right operation order if the size_byte is not aligned. 0368 */ 0369 void L2CACHE_CleanInvalidateByRange(uint32_t address, uint32_t size_byte); 0370 0371 /*! 0372 * @brief Enables or disables to lock down the data and instruction by way. 0373 * This function locks down the cached instruction/data by way and prevent the adresses from 0374 * being allocated and prevent dara from being evicted out of the level 2 cache. 0375 * But the normal cache maintenance operations that invalidate, clean or clean 0376 * and validate cache contents affect the locked-down cache lines as normal. 0377 * 0378 * @param masterId The master id, range from 0 ~ 7. 0379 * @param mask The ways to be enabled or disabled to lockdown. 0380 * each bit in value is related to each way of the cache. for example: 0381 * value: bit 0 ------ way 0. 0382 * value: bit 1 ------ way 1. 0383 * -------------------------- 0384 * value: bit 15 ------ way 15. 0385 * Note: please make sure the value setting is align with your supported ways. 0386 * @param enable True enable the lockdown, false to disable the lockdown. 0387 */ 0388 void L2CACHE_LockdownByWayEnable(uint32_t masterId, uint32_t mask, bool enable); 0389 0390 /*@}*/ 0391 #endif /* FSL_FEATURE_SOC_L2CACHEC_COUNT */ 0392 0393 /*! 0394 * @name Unified Cache Control for all caches (cortex-m7 L1 cache + l2 pl310) 0395 * Mainly used for many drivers for easy cache operation. 0396 *@{ 0397 */ 0398 0399 /*! 0400 * @brief Invalidates all instruction caches by range. 0401 * 0402 * Both cortex-m7 L1 cache line and L2 PL310 cache line length is 32-byte. 0403 * 0404 * @param address The physical address. 0405 * @param size_byte size of the memory to be invalidated. 0406 * @note address and size should be aligned to cache line size 0407 * 32-Byte due to the cache operation unit is one cache line. The startAddr here will be forced 0408 * to align to the cache line size if startAddr is not aligned. For the size_byte, application should 0409 * make sure the alignment or make sure the right operation order if the size_byte is not aligned. 0410 */ 0411 void ICACHE_InvalidateByRange(uint32_t address, uint32_t size_byte); 0412 0413 /*! 0414 * @brief Invalidates all data caches by range. 0415 * 0416 * Both cortex-m7 L1 cache line and L2 PL310 cache line length is 32-byte. 0417 * 0418 * @param address The physical address. 0419 * @param size_byte size of the memory to be invalidated. 0420 * @note address and size should be aligned to cache line size 0421 * 32-Byte due to the cache operation unit is one cache line. The startAddr here will be forced 0422 * to align to the cache line size if startAddr is not aligned. For the size_byte, application should 0423 * make sure the alignment or make sure the right operation order if the size_byte is not aligned. 0424 */ 0425 void DCACHE_InvalidateByRange(uint32_t address, uint32_t size_byte); 0426 0427 /*! 0428 * @brief Cleans all data caches by range. 0429 * 0430 * Both cortex-m7 L1 cache line and L2 PL310 cache line length is 32-byte. 0431 * 0432 * @param address The physical address. 0433 * @param size_byte size of the memory to be cleaned. 0434 * @note address and size should be aligned to cache line size 0435 * 32-Byte due to the cache operation unit is one cache line. The startAddr here will be forced 0436 * to align to the cache line size if startAddr is not aligned. For the size_byte, application should 0437 * make sure the alignment or make sure the right operation order if the size_byte is not aligned. 0438 */ 0439 void DCACHE_CleanByRange(uint32_t address, uint32_t size_byte); 0440 0441 /*! 0442 * @brief Cleans and Invalidates all data caches by range. 0443 * 0444 * Both cortex-m7 L1 cache line and L2 PL310 cache line length is 32-byte. 0445 * 0446 * @param address The physical address. 0447 * @param size_byte size of the memory to be cleaned and invalidated. 0448 * @note address and size should be aligned to cache line size 0449 * 32-Byte due to the cache operation unit is one cache line. The startAddr here will be forced 0450 * to align to the cache line size if startAddr is not aligned. For the size_byte, application should 0451 * make sure the alignment or make sure the right operation order if the size_byte is not aligned. 0452 */ 0453 void DCACHE_CleanInvalidateByRange(uint32_t address, uint32_t size_byte); 0454 0455 /*@}*/ 0456 0457 #if defined(__cplusplus) 0458 } 0459 #endif 0460 0461 /*! @}*/ 0462 0463 #endif /* _FSL_CACHE_H_*/
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |