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 
10 #ifndef FSL_FTFX_CACHE_H
11 #define FSL_FTFX_CACHE_H
12 
13 #include "fsl_ftfx_controller.h"
14 
15 /*!
16  * @addtogroup ftfx_cache_driver
17  * @{
18  */
19 /*******************************************************************************
20  * Definitions
21  ******************************************************************************/
22 
23 /*!
24  * @brief FTFx prefetch speculation status.
25  */
26 typedef struct _flash_prefetch_speculation_status
27 {
28     bool instructionOff; /*!< Instruction speculation.*/
29     bool dataOff;        /*!< Data speculation.*/
30 } ftfx_prefetch_speculation_status_t;
31 
32 /*!
33  * @brief Constants for execute-in-RAM flash function.
34  */
35 enum _ftfx_cache_ram_func_constants
36 {
37     kFTFx_CACHE_RamFuncMaxSizeInWords = 16U, /*!< The maximum size of execute-in-RAM function.*/
38 };
39 
40 typedef union
41 {
42     uint32_t commadAddr;
43     void (*callFlashCommand)(FTFx_REG32_ACCESS_TYPE base, uint32_t bitMask, uint32_t bitShift, uint32_t bitValue);
44 } function_bit_operation_ptr_t;
45 
46 /*! @brief FTFx cache driver state information.
47  *
48  * An instance of this structure is allocated by the user of the flash driver and
49  * passed into each of the driver APIs.
50  */
51 typedef struct _ftfx_cache_config
52 {
53     uint8_t flashMemoryIndex; /*!< 0 - primary flash; 1 - secondary flash*/
54     uint8_t reserved[3];
55     function_bit_operation_ptr_t bitOperFuncAddr; /*!< An buffer point to the flash execute-in-RAM function. */
56 } ftfx_cache_config_t;
57 
58 /*******************************************************************************
59  * API
60  ******************************************************************************/
61 
62 #if defined(__cplusplus)
63 extern "C" {
64 #endif
65 
66 /*!
67  * @brief Initializes the global FTFx cache structure members.
68  *
69  * This function checks and initializes the Flash module for the other FTFx cache APIs.
70  *
71  * @param config Pointer to the storage for the driver runtime state.
72  *
73  * @retval #kStatus_FTFx_Success API was executed successfully.
74  * @retval #kStatus_FTFx_InvalidArgument An invalid argument is provided.
75  * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
76  */
77 status_t FTFx_CACHE_Init(ftfx_cache_config_t *config);
78 
79 /*!
80  * @brief Process the cache/prefetch/speculation to the flash.
81  *
82  * @param config A pointer to the storage for the driver runtime state.
83  * @param isPreProcess The possible option used to control flash cache/prefetch/speculation
84  * @retval #kStatus_FTFx_Success API was executed successfully.
85  * @retval #kStatus_FTFx_InvalidArgument Invalid argument is provided.
86  * @retval #kStatus_FTFx_ExecuteInRamFunctionNotReady Execute-in-RAM function is not available.
87  */
88 status_t FTFx_CACHE_ClearCachePrefetchSpeculation(ftfx_cache_config_t *config, bool isPreProcess);
89 
90 /*!
91  * @brief Sets the PFlash prefetch speculation to the intended speculation status.
92  *
93  * @param speculationStatus The expected protect status to set to the PFlash protection register. Each bit is
94  * @retval #kStatus_FTFx_Success API was executed successfully.
95  * @retval #kStatus_FTFx_InvalidSpeculationOption An invalid speculation option argument is provided.
96  */
97 status_t FTFx_CACHE_PflashSetPrefetchSpeculation(ftfx_prefetch_speculation_status_t *speculationStatus);
98 
99 /*!
100  * @brief Gets the PFlash prefetch speculation status.
101  *
102  * @param speculationStatus  Speculation status returned by the PFlash IP.
103  * @retval #kStatus_FTFx_Success API was executed successfully.
104  */
105 status_t FTFx_CACHE_PflashGetPrefetchSpeculation(ftfx_prefetch_speculation_status_t *speculationStatus);
106 
107 #if defined(__cplusplus)
108 }
109 #endif
110 
111 /*! @}*/
112 
113 #endif /* FSL_FTFX_CACHE_H */
114