Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 

550 Zeilen
20 KiB

  1. /*
  2. * Copyright 2013-2016 Freescale Semiconductor, Inc.
  3. * Copyright 2016-2020 NXP
  4. * All rights reserved.
  5. *
  6. * SPDX-License-Identifier: BSD-3-Clause
  7. *
  8. */
  9. #include "fsl_ftfx_cache.h"
  10. /*******************************************************************************
  11. * Definitions
  12. ******************************************************************************/
  13. /*!
  14. * @name Flash cache and speculation control defines
  15. * @{
  16. */
  17. #if defined(MCM_PLACR_CFCC_MASK)
  18. #define FLASH_CACHE_IS_CONTROLLED_BY_MCM (1u)
  19. #else
  20. #define FLASH_CACHE_IS_CONTROLLED_BY_MCM (0u)
  21. #endif
  22. #define FLASH_CACHE_IS_CONTROLLED_BY_MSCM (0u)
  23. #if defined(FMC_PFB0CR_CINV_WAY_MASK) || defined(FMC_PFB01CR_CINV_WAY_MASK)
  24. #define FLASH_CACHE_IS_CONTROLLED_BY_FMC (1u)
  25. #else
  26. #define FLASH_CACHE_IS_CONTROLLED_BY_FMC (0u)
  27. #endif
  28. #if defined(MCM_PLACR_DFCS_MASK)
  29. #define FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_MCM (1u)
  30. #else
  31. #define FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_MCM (0u)
  32. #endif
  33. #if defined(MSCM_OCMDR_OCMC1_MASK) || defined(MSCM_OCMDR_OCM1_MASK) || defined(MSCM_OCMDR0_OCM1_MASK) || \
  34. defined(MSCM_OCMDR1_OCM1_MASK)
  35. #define FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_MSCM (1u)
  36. #else
  37. #define FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_MSCM (0u)
  38. #endif
  39. #if defined(FMC_PFB0CR_S_INV_MASK) || defined(FMC_PFB0CR_S_B_INV_MASK) || defined(FMC_PFB01CR_S_INV_MASK) || \
  40. defined(FMC_PFB01CR_S_B_INV_MASK)
  41. #define FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_FMC (1u)
  42. #else
  43. #define FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_FMC (0u)
  44. #endif
  45. #if FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_MSCM || FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_FMC || \
  46. FLASH_CACHE_IS_CONTROLLED_BY_MCM || FLASH_CACHE_IS_CONTROLLED_BY_FMC || FLASH_CACHE_IS_CONTROLLED_BY_MSCM
  47. #define FLASH_IS_CACHE_INVALIDATION_AVAILABLE (1)
  48. #else
  49. #define FLASH_IS_CACHE_INVALIDATION_AVAILABLE (0u)
  50. #endif
  51. /*@}*/
  52. /*! @brief A function pointer used to point to relocated ftfx_common_bit_operation() */
  53. typedef void (*callftfxCommonBitOperation_t)(FTFx_REG32_ACCESS_TYPE base,
  54. uint32_t bitMask,
  55. uint32_t bitShift,
  56. uint32_t bitValue);
  57. /*******************************************************************************
  58. * Prototypes
  59. ******************************************************************************/
  60. #if FLASH_CACHE_IS_CONTROLLED_BY_MCM
  61. /*! @brief Performs the cache clear to the flash by MCM.*/
  62. void mcm_flash_cache_clear(ftfx_cache_config_t *config);
  63. #endif /* FLASH_CACHE_IS_CONTROLLED_BY_MCM */
  64. #if FLASH_CACHE_IS_CONTROLLED_BY_MSCM
  65. /*! @brief Performs the cache clear to the flash by MSCM.*/
  66. void mscm_flash_cache_clear(ftfx_cache_config_t *config);
  67. #endif /* FLASH_CACHE_IS_CONTROLLED_BY_MSCM */
  68. #if FLASH_CACHE_IS_CONTROLLED_BY_FMC
  69. /*! @brief Performs the cache clear to the flash by FMC.*/
  70. void fmc_flash_cache_clear(ftfx_cache_config_t *config);
  71. #endif /* FLASH_CACHE_IS_CONTROLLED_BY_FMC */
  72. #if FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_MSCM
  73. /*! @brief Sets the prefetch speculation buffer to the flash by MSCM.*/
  74. void mscm_flash_prefetch_speculation_enable(ftfx_cache_config_t *config, bool enable);
  75. #endif /* FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_MSCM */
  76. #if FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_FMC
  77. /*! @brief Performs the prefetch speculation buffer clear to the flash by FMC.*/
  78. void fmc_flash_prefetch_speculation_clear(ftfx_cache_config_t *config);
  79. #endif /* FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_FMC */
  80. #if FTFx_DRIVER_IS_FLASH_RESIDENT
  81. static void ftfx_common_bit_operation_command_sequence(
  82. ftfx_cache_config_t *config, FTFx_REG32_ACCESS_TYPE base, uint32_t bitMask, uint32_t bitShift, uint32_t bitValue);
  83. #endif /* FTFx_DRIVER_IS_FLASH_RESIDENT */
  84. #if FTFx_DRIVER_IS_FLASH_RESIDENT && FLASH_IS_CACHE_INVALIDATION_AVAILABLE
  85. /*! @brief Copy flash_cache_clear_command() to RAM*/
  86. static void ftfx_copy_common_bit_operation_to_ram(uint32_t *ftfxCommonBitOperation);
  87. #endif /* FTFx_DRIVER_IS_FLASH_RESIDENT */
  88. /*******************************************************************************
  89. * Variables
  90. ******************************************************************************/
  91. #if FTFx_DRIVER_IS_FLASH_RESIDENT && FLASH_IS_CACHE_INVALIDATION_AVAILABLE
  92. /*!
  93. * @brief Position independent code of ftfx_common_bit_operation()
  94. *
  95. * Note1: The prototype of C function is shown as below:
  96. * @code
  97. * void ftfx_common_bit_operation(FTFx_REG32_ACCESS_TYPE base, uint32_t bitMask, uint32_t bitShift, uint32_t
  98. * bitValue)
  99. * {
  100. * if (bitMask)
  101. * {
  102. * uint32_t value = (((uint32_t)(((uint32_t)(bitValue)) << bitShift)) & bitMask);
  103. * *base = (*base & (~bitMask)) | value;
  104. * }
  105. *
  106. * __ISB();
  107. * __DSB();
  108. * }
  109. * @endcode
  110. * Note2: The binary code is generated by IAR 7.70.1
  111. */
  112. static const uint32_t s_ftfxCommonBitOperationFunctionCode[] = {
  113. 0x2900b510u, 0x6804d005u, 0x4093438cu, 0x43214019u, 0xf3bf6001u, 0xf3bf8f6fu, 0xbd108f4fu,
  114. };
  115. #if (!FTFx_DRIVER_IS_EXPORTED)
  116. /*! @brief A static buffer used to hold ftfx_common_bit_operation() */
  117. static uint32_t s_ftfxCommonBitOperation[kFTFx_CACHE_RamFuncMaxSizeInWords];
  118. #endif /* (!FTFx_DRIVER_IS_EXPORTED) */
  119. #endif /* FLASH_IS_CACHE_INVALIDATION_AVAILABLE && FTFx_DRIVER_IS_FLASH_RESIDENT */
  120. /*******************************************************************************
  121. * Code
  122. ******************************************************************************/
  123. status_t FTFx_CACHE_Init(ftfx_cache_config_t *config)
  124. {
  125. if (config == NULL)
  126. {
  127. return kStatus_FTFx_InvalidArgument;
  128. }
  129. /* copy required flash commands to RAM */
  130. #if FTFx_DRIVER_IS_FLASH_RESIDENT && FLASH_IS_CACHE_INVALIDATION_AVAILABLE
  131. if (NULL == config->bitOperFuncAddr.callFlashCommand)
  132. {
  133. #if FTFx_DRIVER_IS_EXPORTED
  134. return kStatus_FTFx_ExecuteInRamFunctionNotReady;
  135. #else
  136. config->bitOperFuncAddr.commadAddr = (uint32_t)s_ftfxCommonBitOperation;
  137. #endif /* FTFx_DRIVER_IS_EXPORTED */
  138. }
  139. ftfx_copy_common_bit_operation_to_ram((uint32_t *)config->bitOperFuncAddr.commadAddr);
  140. #endif /* FLASH_IS_CACHE_INVALIDATION_AVAILABLE && FTFx_DRIVER_IS_FLASH_RESIDENT */
  141. return kStatus_FTFx_Success;
  142. }
  143. /*!
  144. * @brief Flash Cache/Prefetch/Speculation Clear Process
  145. *
  146. * This function is used to perform the cache and prefetch speculation clear process to the flash.
  147. */
  148. status_t FTFx_CACHE_ClearCachePrefetchSpeculation(ftfx_cache_config_t *config, bool isPreProcess)
  149. {
  150. /* We pass the ftfx register address as a parameter to ftfx_common_bit_operation() instead of using
  151. * pre-processed MACROs or a global variable in ftfx_common_bit_operation()
  152. * to make sure that ftfx_common_bit_operation() will be compiled into position-independent code (PIC). */
  153. if (!isPreProcess)
  154. {
  155. #if FLASH_CACHE_IS_CONTROLLED_BY_MCM
  156. mcm_flash_cache_clear(config);
  157. #endif
  158. #if FLASH_CACHE_IS_CONTROLLED_BY_MSCM
  159. mscm_flash_cache_clear(config);
  160. #endif
  161. #if FLASH_CACHE_IS_CONTROLLED_BY_FMC
  162. fmc_flash_cache_clear(config);
  163. #endif
  164. #if FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_MSCM
  165. mscm_flash_prefetch_speculation_enable(config, true);
  166. #endif
  167. #if FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_FMC
  168. fmc_flash_prefetch_speculation_clear(config);
  169. #endif
  170. }
  171. if (isPreProcess)
  172. {
  173. #if FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_MSCM
  174. mscm_flash_prefetch_speculation_enable(config, false);
  175. #endif
  176. }
  177. return kStatus_FTFx_Success;
  178. }
  179. status_t FTFx_CACHE_PflashSetPrefetchSpeculation(ftfx_prefetch_speculation_status_t *speculationStatus)
  180. {
  181. #if FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_MCM
  182. {
  183. if (true == speculationStatus->instructionOff)
  184. {
  185. if (false == speculationStatus->dataOff)
  186. {
  187. return kStatus_FTFx_InvalidSpeculationOption;
  188. }
  189. else
  190. {
  191. MCM0_CACHE_REG |= MCM_PLACR_DFCS_MASK;
  192. }
  193. }
  194. else
  195. {
  196. MCM0_CACHE_REG &= ~MCM_PLACR_DFCS_MASK;
  197. if (false == speculationStatus->dataOff)
  198. {
  199. MCM0_CACHE_REG |= MCM_PLACR_EFDS_MASK;
  200. }
  201. else
  202. {
  203. MCM0_CACHE_REG &= ~MCM_PLACR_EFDS_MASK;
  204. }
  205. }
  206. }
  207. #elif FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_FMC
  208. {
  209. if (false == speculationStatus->instructionOff)
  210. {
  211. FMC_CACHE_REG |= FMC_CACHE_B0IPE_MASK;
  212. }
  213. else
  214. {
  215. FMC_CACHE_REG &= ~FMC_CACHE_B0IPE_MASK;
  216. }
  217. if (false == speculationStatus->dataOff)
  218. {
  219. FMC_CACHE_REG |= FMC_CACHE_B0DPE_MASK;
  220. }
  221. else
  222. {
  223. FMC_CACHE_REG &= ~FMC_CACHE_B0DPE_MASK;
  224. }
  225. /* Invalidate Prefetch Speculation Buffer */
  226. FMC_SPECULATION_INVALIDATE_REG |= FMC_SPECULATION_INVALIDATE_MASK;
  227. }
  228. #elif FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_MSCM
  229. {
  230. if (true == speculationStatus->instructionOff)
  231. {
  232. if (false == speculationStatus->dataOff)
  233. {
  234. return kStatus_FTFx_InvalidSpeculationOption;
  235. }
  236. else
  237. {
  238. MSCM_OCMDR0_REG |= MSCM_OCMDR_OCMC1_DFCS_MASK;
  239. }
  240. }
  241. else
  242. {
  243. MSCM_OCMDR0_REG &= ~MSCM_OCMDR_OCMC1_DFCS_MASK;
  244. if (false == speculationStatus->dataOff)
  245. {
  246. MSCM_OCMDR0_REG &= ~MSCM_OCMDR_OCMC1_DFDS_MASK;
  247. }
  248. else
  249. {
  250. MSCM_OCMDR0_REG |= MSCM_OCMDR_OCMC1_DFDS_MASK;
  251. }
  252. }
  253. }
  254. #endif /* FSL_FEATURE_FTFx_MCM_FLASH_CACHE_CONTROLS */
  255. return kStatus_FTFx_Success;
  256. }
  257. status_t FTFx_CACHE_PflashGetPrefetchSpeculation(ftfx_prefetch_speculation_status_t *speculationStatus)
  258. {
  259. (void)memset(speculationStatus, 0U, sizeof(ftfx_prefetch_speculation_status_t));
  260. /* Assuming that all speculation options are enabled. */
  261. speculationStatus->instructionOff = false;
  262. speculationStatus->dataOff = false;
  263. #if FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_MCM
  264. {
  265. uint32_t value = MCM0_CACHE_REG;
  266. if (0U != (value & MCM_PLACR_DFCS_MASK))
  267. {
  268. /* Speculation buffer is off. */
  269. speculationStatus->instructionOff = true;
  270. speculationStatus->dataOff = true;
  271. }
  272. else
  273. {
  274. /* Speculation buffer is on for instruction. */
  275. if (0U == (value & MCM_PLACR_EFDS_MASK))
  276. {
  277. /* Speculation buffer is off for data. */
  278. speculationStatus->dataOff = true;
  279. }
  280. }
  281. }
  282. #elif FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_FMC
  283. {
  284. uint32_t value = FMC_CACHE_REG;
  285. if (0U == (value & FMC_CACHE_B0DPE_MASK))
  286. {
  287. /* Do not prefetch in response to data references. */
  288. speculationStatus->dataOff = true;
  289. }
  290. if (0U == (value & FMC_CACHE_B0IPE_MASK))
  291. {
  292. /* Do not prefetch in response to instruction fetches. */
  293. speculationStatus->instructionOff = true;
  294. }
  295. }
  296. #elif FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_MSCM
  297. {
  298. uint32_t value = MSCM_OCMDR0_REG;
  299. if (0U != (value & MSCM_OCMDR_OCMC1_DFCS_MASK))
  300. {
  301. /* Speculation buffer is off. */
  302. speculationStatus->instructionOff = true;
  303. speculationStatus->dataOff = true;
  304. }
  305. else
  306. {
  307. /* Speculation buffer is on for instruction. */
  308. if (0U != (value & MSCM_OCMDR_OCMC1_DFDS_MASK))
  309. {
  310. /* Speculation buffer is off for data. */
  311. speculationStatus->dataOff = true;
  312. }
  313. }
  314. }
  315. #endif
  316. return kStatus_FTFx_Success;
  317. }
  318. #if FTFx_DRIVER_IS_FLASH_RESIDENT && FLASH_IS_CACHE_INVALIDATION_AVAILABLE
  319. /*! @brief Copy PIC of ftfx_common_bit_operation() to RAM */
  320. static void ftfx_copy_common_bit_operation_to_ram(uint32_t *ftfxCommonBitOperation)
  321. {
  322. assert(sizeof(s_ftfxCommonBitOperationFunctionCode) <= ((uint32_t)kFTFx_CACHE_RamFuncMaxSizeInWords * 4U));
  323. (void)memcpy(ftfxCommonBitOperation, s_ftfxCommonBitOperationFunctionCode,
  324. sizeof(s_ftfxCommonBitOperationFunctionCode));
  325. }
  326. #endif /* FTFx_DRIVER_IS_FLASH_RESIDENT && FLASH_IS_CACHE_INVALIDATION_AVAILABLE */
  327. #if FTFx_DRIVER_IS_FLASH_RESIDENT
  328. static void ftfx_common_bit_operation_command_sequence(
  329. ftfx_cache_config_t *config, FTFx_REG32_ACCESS_TYPE base, uint32_t bitMask, uint32_t bitShift, uint32_t bitValue)
  330. {
  331. uint32_t *ftfxCommonBitOperationAddr;
  332. ftfxCommonBitOperationAddr = &config->bitOperFuncAddr.commadAddr;
  333. /* Since the value of ARM function pointer is always odd, but the real start
  334. * address
  335. * of function memory should be even, that's why +1 operation exist. */
  336. *ftfxCommonBitOperationAddr += 1UL;
  337. callftfxCommonBitOperation_t ftfxCommonBitOperationCommand = config->bitOperFuncAddr.callFlashCommand;
  338. /* Workround for some devices which doesn't need this function */
  339. ftfxCommonBitOperationCommand((FTFx_REG32_ACCESS_TYPE)base, bitMask, bitShift, bitValue);
  340. *ftfxCommonBitOperationAddr -= 1UL;
  341. }
  342. #endif /*FTFx_DRIVER_IS_FLASH_RESIDENT*/
  343. #if FLASH_CACHE_IS_CONTROLLED_BY_MCM
  344. /*! @brief Performs the cache clear to the flash by MCM.*/
  345. void mcm_flash_cache_clear(ftfx_cache_config_t *config)
  346. {
  347. FTFx_REG32_ACCESS_TYPE regBase;
  348. #if defined(MCM0_CACHE_REG)
  349. regBase = (FTFx_REG32_ACCESS_TYPE)&MCM0_CACHE_REG;
  350. #elif defined(MCM1_CACHE_REG)
  351. regBase = (FTFx_REG32_ACCESS_TYPE)&MCM1_CACHE_REG;
  352. #endif
  353. #if FTFx_DRIVER_IS_FLASH_RESIDENT
  354. /* calling flash command sequence function to execute the command */
  355. ftfx_common_bit_operation_command_sequence(config, regBase, MCM_CACHE_CLEAR_MASK, MCM_CACHE_CLEAR_SHIFT, 1UL);
  356. #else /* !FTFx_DRIVER_IS_FLASH_RESIDENT */
  357. *regBase |= MCM_CACHE_CLEAR_MASK;
  358. /* Memory barriers for good measure.
  359. * All Cache, Branch predictor and TLB maintenance operations before this instruction complete */
  360. __ISB();
  361. __DSB();
  362. #endif /* FTFx_DRIVER_IS_FLASH_RESIDENT */
  363. }
  364. #endif /* FLASH_CACHE_IS_CONTROLLED_BY_MCM */
  365. #if FLASH_CACHE_IS_CONTROLLED_BY_MSCM
  366. /*! @brief Performs the cache clear to the flash by MSCM.*/
  367. void mscm_flash_cache_clear(ftfx_cache_config_t *config)
  368. {
  369. uint8_t setValue = 0x1U;
  370. /* The OCMDR[0] is always used to cache main Pflash*/
  371. /* For device with FlexNVM support, the OCMDR[1] is used to cache Dflash.
  372. * For device with secondary flash support, the OCMDR[1] is used to cache secondary Pflash. */
  373. #if FTFx_DRIVER_IS_FLASH_RESIDENT
  374. switch (config->flashMemoryIndex)
  375. {
  376. case kFLASH_MemoryIndexSecondaryFlash:
  377. /* calling flash command sequence function to execute the command */
  378. ftfx_common_bit_operation_command_sequence(config, (FTFx_REG32_ACCESS_TYPE)&MSCM_OCMDR1_REG,
  379. MSCM_CACHE_CLEAR_MASK,
  380. MSCM_CACHE_CLEAR_SHIFT, setValue);
  381. break;
  382. case kFLASH_MemoryIndexPrimaryFlash:
  383. default:
  384. /* calling flash command sequence function to execute the command */
  385. ftfx_common_bit_operation_command_sequence(config, (FTFx_REG32_ACCESS_TYPE)&MSCM_OCMDR0_REG,
  386. MSCM_CACHE_CLEAR_MASK,
  387. MSCM_CACHE_CLEAR_SHIFT, setValue);
  388. break;
  389. }
  390. #else /* !FTFx_DRIVER_IS_FLASH_RESIDENT */
  391. switch (config->flashMemoryIndex)
  392. {
  393. case kFLASH_MemoryIndexSecondaryFlash:
  394. MSCM_OCMDR1_REG = (MSCM_OCMDR1_REG & (~MSCM_CACHE_CLEAR_MASK)) | MSCM_CACHE_CLEAR(setValue);
  395. /* Each cache clear instruction should be followed by below code*/
  396. __ISB();
  397. __DSB();
  398. break;
  399. case kFLASH_MemoryIndexPrimaryFlash:
  400. default:
  401. MSCM_OCMDR0_REG = (MSCM_OCMDR0_REG & (~MSCM_CACHE_CLEAR_MASK)) | MSCM_CACHE_CLEAR(setValue);
  402. /* Memory barriers for good measure.
  403. * All Cache, Branch predictor and TLB maintenance operations before this instruction complete */
  404. __ISB();
  405. __DSB();
  406. break;
  407. }
  408. #endif /* FTFx_DRIVER_IS_FLASH_RESIDENT */
  409. }
  410. #endif /* FLASH_CACHE_IS_CONTROLLED_BY_MSCM */
  411. #if FLASH_CACHE_IS_CONTROLLED_BY_FMC
  412. /*! @brief Performs the cache clear to the flash by FMC.*/
  413. void fmc_flash_cache_clear(ftfx_cache_config_t *config)
  414. {
  415. #if FTFx_DRIVER_IS_FLASH_RESIDENT
  416. /* calling flash command sequence function to execute the command */
  417. ftfx_common_bit_operation_command_sequence(config, (FTFx_REG32_ACCESS_TYPE)&FMC_CACHE_REG,
  418. FMC_CACHE_CLEAR_MASK, FMC_CACHE_CLEAR_SHIFT, 0xFUL);
  419. #else /* !FTFx_DRIVER_IS_FLASH_RESIDENT */
  420. FMC_CACHE_REG = (FMC_CACHE_REG & (~FMC_CACHE_CLEAR_MASK)) | FMC_CACHE_CLEAR(~0);
  421. /* Memory barriers for good measure.
  422. * All Cache, Branch predictor and TLB maintenance operations before this instruction complete */
  423. __ISB();
  424. __DSB();
  425. #endif /* FTFx_DRIVER_IS_FLASH_RESIDENT */
  426. }
  427. #endif /* FLASH_CACHE_IS_CONTROLLED_BY_FMC */
  428. #if FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_MSCM
  429. /*! @brief Performs the prefetch speculation buffer clear to the flash by MSCM.*/
  430. void mscm_flash_prefetch_speculation_enable(ftfx_cache_config_t *config, bool enable)
  431. {
  432. uint8_t setValue;
  433. if (enable)
  434. {
  435. setValue = 0x0U;
  436. }
  437. else
  438. {
  439. setValue = 0x3U;
  440. }
  441. /* The OCMDR[0] is always used to prefetch main Pflash*/
  442. /* For device with FlexNVM support, the OCMDR[1] is used to prefetch Dflash.
  443. * For device with secondary flash support, the OCMDR[1] is used to prefetch secondary Pflash. */
  444. #if FTFx_DRIVER_IS_FLASH_RESIDENT
  445. switch (config->flashMemoryIndex)
  446. {
  447. case 1:
  448. /* calling flash command sequence function to execute the command */
  449. ftfx_common_bit_operation_command_sequence(config, (FTFx_REG32_ACCESS_TYPE)&MSCM_OCMDR1_REG,
  450. MSCM_SPECULATION_SET_MASK,
  451. MSCM_SPECULATION_SET_SHIFT, setValue);
  452. break;
  453. case 0:
  454. default:
  455. /* calling flash command sequence function to execute the command */
  456. ftfx_common_bit_operation_command_sequence(config, (FTFx_REG32_ACCESS_TYPE)&MSCM_OCMDR0_REG,
  457. MSCM_SPECULATION_SET_MASK,
  458. MSCM_SPECULATION_SET_SHIFT, setValue);
  459. break;
  460. }
  461. #else /* !FTFx_DRIVER_IS_FLASH_RESIDENT */
  462. switch (config->flashMemoryIndex)
  463. {
  464. case kFLASH_MemoryIndexSecondaryFlash:
  465. MSCM_OCMDR1_REG = (MSCM_OCMDR1_REG & (~MSCM_SPECULATION_SET_MASK)) | MSCM_SPECULATION_SET(setValue);
  466. /* Each cache clear instruction should be followed by below code*/
  467. __ISB();
  468. __DSB();
  469. break;
  470. case kFLASH_MemoryIndexPrimaryFlash:
  471. default:
  472. MSCM_OCMDR0_REG = (MSCM_OCMDR0_REG & (~MSCM_SPECULATION_SET_MASK)) | MSCM_SPECULATION_SET(setValue);
  473. /* Memory barriers for good measure.
  474. * All Cache, Branch predictor and TLB maintenance operations before this instruction complete */
  475. __ISB();
  476. __DSB();
  477. break;
  478. }
  479. #endif /* FTFx_DRIVER_IS_FLASH_RESIDENT */
  480. }
  481. #endif /* FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_MSCM */
  482. #if FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_FMC
  483. /*! @brief Performs the prefetch speculation buffer clear to the flash by FMC.*/
  484. void fmc_flash_prefetch_speculation_clear(ftfx_cache_config_t *config)
  485. {
  486. #if FTFx_DRIVER_IS_FLASH_RESIDENT
  487. /* calling flash command sequence function to execute the command */
  488. ftfx_common_bit_operation_command_sequence(config, (FTFx_REG32_ACCESS_TYPE)&FMC_SPECULATION_INVALIDATE_REG,
  489. FMC_SPECULATION_INVALIDATE_MASK,
  490. FMC_SPECULATION_INVALIDATE_SHIFT, 1UL);
  491. #else /* !FTFx_DRIVER_IS_FLASH_RESIDENT */
  492. FMC_SPECULATION_INVALIDATE_REG |= FMC_SPECULATION_INVALIDATE_MASK;
  493. /* Memory barriers for good measure.
  494. * All Cache, Branch predictor and TLB maintenance operations before this instruction complete */
  495. __ISB();
  496. __DSB();
  497. #endif /* FTFx_DRIVER_IS_FLASH_RESIDENT */
  498. }
  499. #endif /* FLASH_PREFETCH_SPECULATION_IS_CONTROLLED_BY_FMC */