aboutsummaryrefslogtreecommitdiff
path: root/KSDK_1.2.0/platform/drivers/inc/fsl_lmem_cache_driver.h
blob: 29ba348781f23c4c4ed86783005d889781199fd0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
/*
 * Copyright (c) 2013 - 2015, Freescale Semiconductor, Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * o Redistributions of source code must retain the above copyright notice, this list
 *   of conditions and the following disclaimer.
 *
 * o Redistributions in binary form must reproduce the above copyright notice, this
 *   list of conditions and the following disclaimer in the documentation and/or
 *   other materials provided with the distribution.
 *
 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
 *   contributors may be used to endorse or promote products derived from this
 *   software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
#if !defined(__FSL_LMEM_CACHE_DRIVER_H__)
#define __FSL_LMEM_CACHE_DRIVER_H__

#include "fsl_lmem_cache_hal.h"

#if FSL_FEATURE_SOC_LMEM_COUNT

/*!
 * @addtogroup local_memory_controller_cache_driver
 * @{
 */

/*******************************************************************************
 * Definitions
 ******************************************************************************/
/*! @brief Table of base addresses for the LMEM instances. */
extern LMEM_Type * const g_lmemBase[LMEM_INSTANCE_COUNT];

/*******************************************************************************
 * API
 ******************************************************************************/

#if defined(__cplusplus)
extern "C" {
#endif

/*!
 * @name Processor Code Bus Cache Control Peripheral Driver
 *@{
 */

/*!
 * @brief Invalidates the processor code bus cache.
 *
 * This function invalidates the cache both ways, which means that
 * it unconditionally clears valid bits and modifies bits of a cache entry.
 *
 * @param instance The instance number of the LMEM peripheral
 */
void LMEM_DRV_CodeCacheInvalidateAll(uint32_t instance);

/*!
 * @brief Pushes all modified lines in the processor code bus cache.
 *
 * This function pushes all modified lines in both ways (the entire cache).
 * Pushes a cache entry if it is valid and modified, then clears the modify bit. If
 * entry is not valid or not modified, leave as is. This action does not clear the valid
 * bit. A cache push is synonymous with a cache flush.
 *
 * @param instance The instance number of the LMEM peripheral
 */
void LMEM_DRV_CodeCachePushAll(uint32_t instance);

/*!
 * @brief Cears the processor code bus cache.
 *
 * This function clears the entire cache and pushes (flushes) and
 * invalidates the operation.
 * Clear - Push a cache entry if it is valid and modified, then clear the valid and
 * modify bits. If the entry is not valid or not modified, clear the valid bit.
 *
 * @param instance The instance number of the LMEM peripheral
 */
void LMEM_DRV_CodeCacheClearAll(uint32_t instance);

/*!
 * @brief Enables the processor code bus cache.
 *
 * This function enables the cache.  The function first invalidates the entire cache,
 * then enables both the cache and write buffer.
 *
 * @param instance The instance number of the LMEM peripheral
 */
void LMEM_DRV_CodeCacheEnable(uint32_t instance);

/*!
 * @brief Disables the processor code bus cache.
 *
 * This function disables the cache and write buffer.
 *
 * @param instance The instance number of the LMEM peripheral
 */
void LMEM_DRV_CodeCacheDisable(uint32_t instance);

/*!
 * @brief Invalidates a specific line in the processor code bus cache.
 *
 * This function invalidates a specific line in the cache
 * based on the physical address passed in by the user.
 * Invalidate - Unconditionally clear valid and modify bits of a cache entry
 *
 * @param instance The instance number of the LMEM peripheral
 * @param addr The physical address of the cache line
 */
void LMEM_DRV_CodeCacheInvalidateLine(uint32_t instance, uint32_t addr);

/*!
 * @brief Invalidates multiple lines in the processor code bus cache.
 *
 * This function invalidates multiple lines in the cache
 * based on the physical address and length in bytes passed in by the
 * user.  If the function detects that the length meets or exceeds half the
 * cache, then the function performs an entire cache invalidate function which is
 * more efficient than invalidating the cache line-by-line.
 * The need to check half the total amount of cache is due to the fact that the cache consists of
 * two ways and that line commands based on the physical address searches both ways.
 * Invalidate - Unconditionally clear valid and modify bits of a cache entry
 *
 * @param instance The instance number of the LMEM peripheral
 * @param addr The physical address of the cache line
 * @param length The length in bytes of the total amount of cache lines
 */
void LMEM_DRV_CodeCacheInvalidateMultiLines(uint32_t instance, uint32_t addr, uint32_t length);

/*!
 * @brief Pushes a specific modified line in the processor code bus cache.
 *
 * This function pushes a specific modified line based on the physical address passed in
 * by the user.
 * Push - Push a cache entry if it is valid and modified, then clear the modify bit. If
 * entry not valid or not modified, leave as is. This action does not clear the valid
 * bit. A cache push is synonymous with a cache flush.
 *
 * @param instance The instance number of the LMEM peripheral
 * @param addr The physical address of the cache line
 */
void LMEM_DRV_CodeCachePushLine(uint32_t instance, uint32_t addr);

/*!
 * @brief Pushes multiple modified lines in the processor code bus cache.
 *
 * This function pushes multiple modified lines in the cache
 * based on the physical address and length in bytes passed in by the
 * user.  If the function detects that the length meets or exceeds half of the
 * cache, the function performs an cache push function (which is
 * more efficient than pushing the modified lines in the cache line-by-line).
 * The need to check half the total amount of cache is due to the fact that the cache consists of
 * two ways and that line commands based on the physical address searches both ways.
 * Push - Push a cache entry if it is valid and modified, then clear the modify bit. If
 * entry not valid or not modified, leave as is. This action does not clear the valid
 * bit. A cache push is synonymous with a cache flush.
 *
 * @param instance The instance number of the LMEM peripheral
 * @param addr The physical address of the cache line
 * @param length The length in bytes of the total amount of cache lines
 */
void LMEM_DRV_CodeCachePushMultiLines(uint32_t instance, uint32_t addr, uint32_t length);

/*!
 * @brief Clears a specific line in the processor code bus cache.
 *
 * This function clears a specific line based on the physical address passed in
 * by the user.
 * Clear - Push a cache entry if it is valid and modified, then clear the valid and
 * modify bits. If entry not valid or not modified, clear the valid bit.
 *
 * @param instance The instance number of the LMEM peripheral
 * @param addr The physical address of the cache line
 */
void LMEM_DRV_CodeCacheClearLine(uint32_t instance, uint32_t addr);

/*!
 * @brief Clears multiple lines in the processor code bus cache.
 *
 * This function clears multiple lines in the cache
 * based on the physical address and length in bytes passed in by the
 * user.  If the function detects that the length meets or exceeds half the total amount of
 * cache, the function performs a cache clear function which is
 * more efficient than clearing the lines in the cache line-by-line.
 * The need to check half the total amount of cache is due to the fact that the cache consists of
 * two ways and that line commands based on the physical address searches both ways.
 * Clear - Push a cache entry if it is valid and modified, then clear the valid and
 * modify bits. If entry not valid or not modified, clear the valid bit.
 *
 * @param instance The instance number of the LMEM peripheral
 * @param addr The physical address of the cache line
 * @param length The length in bytes of the total amount of cache lines
 */
void LMEM_DRV_CodeCacheClearMultiLines(uint32_t instance, uint32_t addr, uint32_t length);

/*!
 * @brief Demotes the cache mode of a region in processor code bus cache.
 *
 * This function allows the user to demote the cache mode of a region within the device's
 * memory map. Demoting the cache mode reduces the cache function applied to a memory
 * region from write-back to write-through to non-cacheable.  The function checks to see
 * if the requested cache mode is higher than or equal to the current cache mode, and if
 * so, returns an error. After a region is demoted, its cache mode can only be raised
 * by a reset, which returns it to its default state.
 * To maintain cache coherency, changes to the cache mode should be completed while the
 * address space being changed is not being accessed or the cache is disabled. Before a
 * cache mode change, this function completes a cache clear all command to push and invalidate any
 * cache entries that may have changed.
 *
 * @param instance The instance number of the LMEM peripheral
 * @param region The desired region to demote of type lmem_cache_region_t
 * @param cacheMode The new, demoted cache mode of type lmem_cache_mode_t
 *
 * @return kStatus_LMEM_CACHE_Success The cache clear operation was successful, or
 *         kStatus_LMEM_CACHE_Busy The cache is busy performing another operation
 *         kStatus_LMEM_CACHE_Error The requested cache mode is higher than or equal to the
 *                                  current cache mode
 */
lmem_cache_status_t LMEM_DRV_CodeCacheDemoteRegion(uint32_t instance, lmem_cache_region_t region,
                                                   lmem_cache_mode_t cacheMode);

/*@}*/

#if FSL_FEATURE_LMEM_HAS_SYSTEMBUS_CACHE
/*!
 * @name Processor System Bus Cache Control Peripheral Driver
 *@{
 */

/*!
 * @brief Invalidates the processor code bus cache.
 *
 * This function invalidates the entire cache both ways.
 * Invalidate - Unconditionally clear valid and modify bits of a cache entry
 *
 * @param instance The instance number of the LMEM peripheral
 */
void LMEM_DRV_SystemCacheInvalidateAll(uint32_t instance);

/*!
 * @brief Pushes all modified lines in the  processor code bus
 *        cache.
 *
 * This function pushes all modified lines in both ways (the entire cache).
 * Push - Push a cache entry if it is valid and modified, then clear the modify bit. If
 * entry is not valid or not modified, leave as is. This action does not clear the valid
 * bit. A cache push is synonymous with a cache flush.
 *
 * @param instance The instance number of the LMEM peripheral
 */
void LMEM_DRV_SystemCachePushAll(uint32_t instance);

/*!
 * @brief Clears the entire processor code bus cache.
 *
 * This function clears the entire cache, which is a push (flush) and
 * invalidate operation.
 * Clear - Push a cache entry if it is valid and modified, then clear the valid and
 * modify bits. If entry not valid or not modified, clear the valid bit.
 *
 * @param instance The instance number of the LMEM peripheral
 */
void LMEM_DRV_SystemCacheClearAll(uint32_t instance);

/*!
 * @brief Enables the processor code bus cache.
 *
 * This function enables the cache. It first invalidates the entire cache,
 * then enables both the cache and write buffer.
 *
 * @param instance The instance number of the LMEM peripheral
 */
void LMEM_DRV_SystemCacheEnable(uint32_t instance);

/*!
 * @brief Disables the processor code bus cache.
 *
 * This function disables the cache and write buffer.
 *
 * @param instance The instance number of the LMEM peripheral
 */
void LMEM_DRV_SystemCacheDisable(uint32_t instance);

/*!
 * @brief Invalidates a specific line in the processor code bus cache.
 *
 * This function invalidates a specific line in the cache
 * based on the physical address passed in by the user.
 * Invalidate - Unconditionally clear valid and modify bits of a cache entry
 *
 * @param instance The instance number of the LMEM peripheral
 * @param addr The physical address of the cache line
 */
void LMEM_DRV_SystemCacheInvalidateLine(uint32_t instance, uint32_t addr);

/*!
 * @brief Invalidates multiple lines in the processor code bus cache.
 *
 * This function invalidates multiple lines in the cache
 * based on the physical address and length in bytes passed in by the
 * user.  If the function detects that the length meets or exceeds half of the
 * cache, the function performs an entire cache invalidate function (which is
 * more efficient than invalidating the cache line-by-line).
 * The need to check half the total amount of cache is due to the fact that the cache consists of
 * two ways and that line commands based on the physical address  searches both ways.
 * Invalidate - Unconditionally clear valid and modify bits of a cache entry
 *
 * @param instance The instance number of the LMEM peripheral
 * @param addr The physical address of the cache line
 * @param length The length in bytes of the total amount of cache lines
 */
void LMEM_DRV_SystemCacheInvalidateMultiLines(uint32_t instance, uint32_t addr, uint32_t length);

/*!
 * @brief Pushes a specific modified line in the processor code bus
 *        cache.
 *
 * This function pushes a specific modified line based on the physical address passed in
 * by the user.
 * Push - Push a cache entry if it is valid and modified, then clear the modify bit. If
 * entry not valid or not modified, leave as is. This action does not clear the valid
 * bit. A cache push is synonymous with a cache flush.
 *
 * @param instance The instance number of the LMEM peripheral
 * @param addr The physical address of the cache line
 */
void LMEM_DRV_SystemCachePushLine(uint32_t instance, uint32_t addr);

/*!
 * @brief Pushes multiple modified lines in the processor code bus cache.
 *
 * This function pushes multiple modified lines in the cache
 * based on the physical address and length in bytes passed in by the
 * user.  If the function detects that the length meets or exceeds half of the
 * cache, the function performs an entire cache push function (which is
 * more efficient than pushing the modified lines in the cache line-by-line).
 * The need to check half the total amount of cache is due to the fact that the cache consists of
 * two ways and that line commands based on the physical address searches both ways.
 * Push - Push a cache entry if it is valid and modified, then clear the modify bit. If
 * entry not valid or not modified, leave as is. This action does not clear the valid
 * bit. A cache push is synonymous with a cache flush.
 *
 * @param instance The instance number of the LMEM peripheral
 * @param addr The physical address of the cache line
 * @param length The length in bytes of the total amount of cache lines
 */
void LMEM_DRV_SystemCachePushMultiLines(uint32_t instance, uint32_t addr, uint32_t length);

/*!
 * @brief Clears a specific line in the processor code bus cache.
 *
 * This function clears a specific line based on the physical address passed in
 * by the user.
 * Clear - Push a cache entry if it is valid and modified, then clear the valid and
 * modify bits. If entry not valid or not modified, clear the valid bit.
 *
 * @param instance The instance number of the LMEM peripheral
 * @param addr The physical address of the cache line
 */
void LMEM_DRV_SystemCacheClearLine(uint32_t instance, uint32_t addr);

/*!
 * @brief Clears multiple lines in the processor code bus cache.
 *
 * This function clears multiple lines in the cache
 * based on the physical address and length in bytes passed in by the
 * user.  If the function detects that the length meets or exceeds half of the
 * cache, the function performs an entire cache clear function (which is
 * more efficient than clearing the lines in the cache line-by-line).
 * The need to check half the total amount of cache is due to the fact that the cache consists of
 * two ways and that line commands based on the physical address searches both ways.
 * Clear - Push a cache entry if it is valid and modified, then clear the valid and
 * modify bits. If entry not valid or not modified, clear the valid bit.
 *
 * @param instance The instance number of the LMEM peripheral
 * @param addr The physical address of the cache line
 * @param length The length in bytes of the total amount of cache lines
 */
void LMEM_DRV_SystemCacheClearMultiLines(uint32_t instance, uint32_t addr, uint32_t length);

/*!
 * @brief Demotes the cache mode of a region in the processor code bus cache.
 *
 * This function allows the user to demote the cache mode of a region within the device's
 * memory map. Demoting the cache mode reduces the cache function applied to a memory
 * region from write-back to write-through to non-cacheable.  The function checks to see
 * if the requested cache mode is higher than or equal to the current cache mode, and if
 * so, returns an error. After a region is demoted, its cache mode can only be raised
 * by a reset, which returns it to its default state.
 * To maintain cache coherency, changes to the cache mode should be completed while the
 * address space being changed is not being accessed or the cache is disabled. Before a
 * cache mode change, this function completes a cache clear all command to push and invalidate any
 * cache entries that may have changed.
 *
 * @param instance The instance number of the LMEM peripheral
 * @param region The desired region to demote of type lmem_cache_region_t
 * @param cacheMode The new, demoted cache mode of type lmem_cache_mode_t
 *
 * @return kStatus_LMEM_CACHE_Success The cache clear operation was successful, or
 *         kStatus_LMEM_CACHE_Busy The cache is busy performing another operation
 *         kStatus_LMEM_CACHE_Error The requested cache mode is higher than or equal to the
 *                                  current cache mode
 */
lmem_cache_status_t LMEM_DRV_SystemCacheDemoteRegion(uint32_t instance, lmem_cache_region_t region,
                                                     lmem_cache_mode_t cacheMode);

/*@}*/
#endif /* #if FSL_FEATURE_LMEM_HAS_SYSTEMBUS_CACHE */

#if defined(__cplusplus)
}
#endif

/*! @}*/

#endif /* FSL_FEATURE_SOC_LMEM_COUNT */
#endif /* __FSL_LMEM_CACHE_DRIVER_H__*/
/*******************************************************************************
 * EOF
 ******************************************************************************/