aboutsummaryrefslogtreecommitdiff
path: root/KSDK_1.2.0/platform/hal/inc/fsl_lmem_cache_hal.h
blob: 927f5249d5ab778d34c0bd81e66153c94defee59 (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
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
/*
 * 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_HAL_H__)
#define __FSL_LMEM_CACHE_HAL_H__

#include "fsl_device_registers.h"
#include <stdint.h>
#include <stdbool.h>

#if FSL_FEATURE_SOC_LMEM_COUNT

/*!
 * @addtogroup local_memory_controller_cache_hal
 * @{
 */

/*! @file*/

/*******************************************************************************
 * Definitions
 ******************************************************************************/
/*! @brief Error codes for the LMEM CACHE driver. */
typedef enum _lmem_cache_status
{
    kStatus_LMEM_CACHE_Success = 0,
    kStatus_LMEM_CACHE_Busy,        /*!< CACHE busy performing an operation*/
    kStatus_LMEM_CACHE_DemoteError, /*!< CACHE region demotion error */
    kStatus_LMEM_CACHE_Error,       /*!< CACHE driver error */
} lmem_cache_status_t;

/*! @brief LMEM CACHE mode options. */
typedef enum _lmem_cache_mode {
    kCacheNonCacheable     = 0x0U, /*!< CACHE mode: non-cacheable */
    kCacheWriteThrough     = 0x2U, /*!< CACHE mode: write-through */
    kCacheWriteBack        = 0x3U, /*!< CACHE mode: write-back */
} lmem_cache_mode_t;

/*! @brief LMEM CACHE Regions. */
typedef enum _lmem_cache_region {
    kCacheRegion0   = 0U,   /*!< Cache Region 0 */
    kCacheRegion1   = 1U,   /*!< Cache Region 1 */
    kCacheRegion2   = 2U,   /*!< Cache Region 2 */
    kCacheRegion3   = 3U,   /*!< Cache Region 3 */
    kCacheRegion4   = 4U,   /*!< Cache Region 4 */
    kCacheRegion5   = 5U,   /*!< Cache Region 5 */
    kCacheRegion6   = 6U,   /*!< Cache Region 6 */
    kCacheRegion7   = 7U,   /*!< Cache Region 7 */
    kCacheRegion8   = 8U,   /*!< Cache Region 8 */
    kCacheRegion9   = 9U,   /*!< Cache Region 9 */
    kCacheRegion10  = 10U,  /*!< Cache Region 10 */
    kCacheRegion11  = 11U,  /*!< Cache Region 11 */
    kCacheRegion12  = 12U,  /*!< Cache Region 12 */
    kCacheRegion13  = 13U,  /*!< Cache Region 13 */
    kCacheRegion14  = 14U,  /*!< Cache Region 14 */
    kCacheRegion15  = 15U   /*!< Cache Region 15 */
} lmem_cache_region_t;

/*! @brief LMEM CACHE line command. */
typedef enum _lmem_cache_way {
    kCacheLineSearchReadOrWrite  = 0U,   /*!< Cache line search and read or write */
    kCacheLineInvalidate         = 1U,   /*!< Cache line invalidate */
    kCacheLinePush               = 2U,   /*!< Cache line push */
    kCacheLineClear              = 3U,   /*!< Cache line clear */
} lmem_cache_line_command_t;

/*! @brief LMEM CACHE Line Size in bytes. */
#define LMEM_CACHE_LINE_SIZE    0x10  /*!< Cache line is 32 bytes (or 4-words) */

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

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

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

/*!
 * @brief Enables or disables the Processor Code bus cache and write buffer.
 *
 * This function enables or disables the Processor Code bus cache and write buffer.
 *
 * @param base Module base pointer of type LMEM_Type.
 * @param enable Enable (true) or disable (false) the Processor Code bus cache and write buffer
 */
static inline void LMEM_HAL_SetCodeCacheEnableCmd(LMEM_Type * base, bool enable)
{
    LMEM_BWR_PCCCR_ENCACHE(base, (enable == true));
    LMEM_BWR_PCCCR_ENWRBUF(base, (enable == true));
}

/*!
 * @brief Enable or disable the Processor Code bus option to invalidate all lines.
 *
 * This function enables or disables the Processor Code bus option to invalidate all
 * lines in both WAYs.
 *
 * @param base Module base pointer of type LMEM_Type.
 * @param enable Enable (true) or disable (false) the Processor Code bus option to
 *               invalidate all lines
 */
void LMEM_HAL_SetCodeCacheInvalidateAllCmd(LMEM_Type * base, bool enable);

/*!
 * @brief Enable or disable the Processor Code bus option to push all modified lines.
 *
 * This function enables or disables the Processor Code bus option to push all modified
 * lines to both WAYs.
 *
 * @param base Module base pointer of type LMEM_Type.
 * @param enable Enable (true) or disable (false) the Processor Code bus option to push
                 all modified lines
 */
void LMEM_HAL_SetCodeCachePushAllCmd(LMEM_Type * base, bool enable);

/*!
 * @brief Enable or disable the Processor Code bus option to push and invalidate all modified
 *        lines.
 *
 * This function enables or disables the Processor Code bus option to push and invalidate all
 * modified lines.
 *
 * @param base Module base pointer of type LMEM_Type.
 * @param enable Enable (true) or disable (false) the Processor Code bus option to push
                 all modified lines
 */
void LMEM_HAL_SetCodeCacheClearAllCmd(LMEM_Type * base, bool enable);

/*!
 * @brief Initiate the Processor Code bus cache command.
 *
 * This function initiates the Processor Code bus cache command to execute
 * an invalidate command and/or push command.
 *
 * @param base Module base pointer of type LMEM_Type.
 */
static inline void LMEM_HAL_InitiateCodeCacheCommand(LMEM_Type * base)
{
    LMEM_BWR_PCCCR_GO(base, true);
}

/*!
 * @brief Returns whether or not the Processor Code bus cache command is in progress.
 *
 * This function returns the state of the Processor Code bus cache command. The
 * command is either active (in progress) or idle.
 *
 * @param base Module base pointer of type LMEM_Type.
 * @return True if the cache command is in progress or false if the command is idle
 */
static inline bool LMEM_HAL_IsCodeCacheCommandActive(LMEM_Type * base)
{
    return (bool)LMEM_RD_PCCCR_GO(base);
}


/*!
 * @brief Initiate the Processor Code bus cache line command.
 *
 * This function initiates the Processor Code bus cache line command to execute
 * a search and read or write command, an invalidate command, a push command, or
 * a clear command.
 *
 * @param base Module base pointer of type LMEM_Type.
 */
static inline void LMEM_HAL_InitiateCodeCacheLineCommand(LMEM_Type * base)
{
    LMEM_BWR_PCCLCR_LGO(base, true);
}


/*!
 * @brief Returns whether or not the Processor Code bus cache line command is in
 *        progress.
 *
 * This function returns the state of the Processor Code bus cache line command. The
 * command is either active (in progress) or idle.
 *
 * @param base Module base pointer of type LMEM_Type.
 * @return True if the cache line command is in progress or false if the command is idle
 */
static inline bool LMEM_HAL_IsCodeCacheLineCommandActive(LMEM_Type * base)
{
    return (bool)LMEM_RD_PCCLCR_LGO(base);
}

/*!
 * @brief Sets the cache line command for the Processor Code bus.
 *
 * This function sets the cache line command for the Processor Code bus. The
 * command can be search and read or write, invalidate, push, or clear.
 *
 * @param base Module base pointer of type LMEM_Type.
 * @param command The cache line command of type lmem_cache_line_command_t
 */
static inline void LMEM_HAL_SetCodeCacheLineCommand(LMEM_Type * base,
                                                    lmem_cache_line_command_t command)
{
    LMEM_BWR_PCCLCR_LCMD(base, command);
}

/*!
 * @brief Sets the physical address for cache line commands for the Processor
 *        Code bus.
 *
 * This function sets the physical address for cache line commands for the Processor
 * Code bus. The commands are specified in the CLCR[LADSEL] bits.
 *
 * @param base Module base pointer of type LMEM_Type.
 * @param addr The physical address for cache line commands
 */
static inline void LMEM_HAL_SetCodeCachePhysicalAddr(LMEM_Type * base, uint32_t addr)
{
    LMEM_WR_PCCSAR(base, (addr & LMEM_PCCSAR_PHYADDR_MASK));
}

/*!
 * @brief Sets the cache mode for a specific region for the Processor
 *        Code bus.
 *
 * This function sets the cache mode for a specific region for the Processor
 * Code bus. Note that you can only demote the cache mode.
 *
 * @param base Module base pointer of type LMEM_Type.
 * @param region The region to demote the cache mode of type lmem_cache_region_t
 * @param cacheMode The specified demoted cache mode of type lmem_cache_mode_t
 */
void LMEM_HAL_SetCodeCacheRegionMode(LMEM_Type * base, lmem_cache_region_t region,
                                     lmem_cache_mode_t cacheMode);

/*!
 * @brief Gets the current cache mode for a specific region for the Processor
 *        Code bus.
 *
 * This function gets the current cache mode for a specific region for the Processor
 * Code bus.
 *
 * @param base Module base pointer of type LMEM_Type.
 * @param region The region to obtain the cache mode of type lmem_cache_region_t
 * @return The current cache mode for the specified region
 */
uint32_t LMEM_HAL_GetCodeCacheRegionMode(LMEM_Type * base, lmem_cache_region_t region);

/*@}*/

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

/*!
 * @brief Enables or disables the Processor System bus cache and write buffer.
 *
 * This function enables or disables the Processor System bus cache and write buffer.
 *
 * @param base Module base pointer of type LMEM_Type.
 * @param enable Enable (true) or disable (false) the Processor Code bus cache and write buffer
 */
static inline void LMEM_HAL_SetSystemCacheEnableCmd(LMEM_Type * base, bool enable)
{
    LMEM_BWR_PSCCR_ENCACHE(base, (enable == true));
    LMEM_BWR_PSCCR_ENWRBUF(base, (enable == true));
}

/*!
 * @brief Enable or disable the Processor System bus option to invalidate all lines.
 *
 * This function enables or disables the Processor System bus option to invalidate all
 * lines in both WAYs.
 *
 * @param base Module base pointer of type LMEM_Type.
 * @param enable Enable (true) or disable (false) the Processor System bus option to
 *               invalidate all lines
 */
void LMEM_HAL_SetSystemCacheInvalidateAllCmd(LMEM_Type * base, bool enable);

/*!
 * @brief Enable or disable the Processor System bus option to push all modified lines.
 *
 * This function enables or disables the Processor System bus option to push all
 * modified lines to both WAYs.
 *
 * @param base Module base pointer of type LMEM_Type.
 * @param enable Enable (true) or disable (false) the Processor System bus option to
 *               push all modified lines
 */
void LMEM_HAL_SetSystemCachePushAllCmd(LMEM_Type * base, bool enable);

/*!
 * @brief Enable or disable the Processor System bus option to push and invalidate all modified
 *        lines.
 *
 * This function enables or disables the Processor System bus option to push and invalidate all
 * modified lines to both WAYs.
 *
 * @param base Module base pointer of type LMEM_Type.
 * @param enable Enable (true) or disable (false) the Processor System bus option to
 *               push all modified lines
 */
void LMEM_HAL_SetSystemCacheClearAllCmd(LMEM_Type * base, bool enable);

/*!
 * @brief Initiate the Processor System bus cache command.
 *
 * This function initiates the Processor System bus cache command to execute
 * an invalidate command and/or push command.
 *
 * @param base Module base pointer of type LMEM_Type.
 */
static inline void LMEM_HAL_InitiateSystemCacheCommand(LMEM_Type * base)
{
    LMEM_BWR_PSCCR_GO(base, true);
}

/*!
 * @brief Returns whether or not the Processor System bus cache command is in progress.
 *
 * This function returns the state of the Processor System bus cache command. The
 * command is either active (in progress) or idle.
 *
 * @param base Module base pointer of type LMEM_Type.
 * @return True if the cache command is in progress or false if the command is idle
 */
static inline bool LMEM_HAL_IsSystemCacheCommandActive(LMEM_Type * base)
{
    return (bool)LMEM_RD_PSCCR_GO(base);
}

/*!
 * @brief Initiate the Processor System bus cache line command.
 *
 * This function initiates the Processor System bus cache command to execute
 * a search and read or write command, an invalidate command, a push command, or
 * a clear command.
 *
 * @param base Module base pointer of type LMEM_Type.
 */
static inline void LMEM_HAL_InitiateSystemCacheLineCommand(LMEM_Type * base)
{
    LMEM_BWR_PSCLCR_LGO(base, true);
}

/*!
 * @brief Returns whether or not the Processor System bus cache line command is in
 *        progress.
 *
 * This function returns the state of the Processor System bus cache line command. The
 * command is either active (in progress) or idle.
 *
 * @param base Module base pointer of type LMEM_Type.
 * @return True if the cache line command is in progress or false if the command is idle
 */
static inline bool LMEM_HAL_IsSystemCacheLineCommandActive(LMEM_Type * base)
{
    return (bool)LMEM_RD_PSCLCR_LGO(base);
}

/*!
 * @brief Sets the cache line command for the Processor System bus.
 *
 * This function sets the cache line command for the Processor System bus. The
 * command can be search and read or write, invalidate, push, or clear.
 *
 * @param base Module base pointer of type LMEM_Type.
 * @param command The cache line command of type lmem_cache_line_command_t
 */
static inline void LMEM_HAL_SetSystemCacheLineCommand(LMEM_Type * base,
                                                      lmem_cache_line_command_t command)
{
    LMEM_BWR_PSCLCR_LCMD(base, command);
}

/*!
 * @brief Sets the physical address for cache line commands for the Processor
 *        System bus.
 *
 * This function sets the physical address for cache line commands for the Processor
 * System bus. The commands are specified in the CLCR[LADSEL] bits.
 *
 * @param base Module base pointer of type LMEM_Type.
 * @param addr The physical address for cache line commands
 */
static inline void LMEM_HAL_SetSystemCachePhysicalAddr(LMEM_Type * base, uint32_t addr)
{
    LMEM_WR_PSCSAR(base, (addr & LMEM_PSCSAR_PHYADDR_MASK));
}

/*!
 * @brief Sets the cache mode for a specific region for the Processor
 *        System bus.
 *
 * This function sets the cache mode for a specific region for the Processor
 * System bus. Note that you can only demote the cache mode.
 *
 * @param base Module base pointer of type LMEM_Type.
 * @param region The region to demote the cache mode of type lmem_cache_region_t
 * @param cacheMode The specified demoted cache mode of type lmem_cache_mode_t
 */
void LMEM_HAL_SetSystemCacheRegionMode(LMEM_Type * base, lmem_cache_region_t region,
                                       lmem_cache_mode_t cacheMode);

/*!
 * @brief Gets the current cache mode for a specific region for the Processor
 *        System bus.
 *
 * This function gets the current cache mode for a specific region for the Processor
 * System bus.
 *
 * @param base Module base pointer of type LMEM_Type.
 * @param region The region to obtain the cache mode of type lmem_cache_region_t
 * @return The current cache mode for the specified region
 */
uint32_t LMEM_HAL_GetSystemCacheRegionMode(LMEM_Type * base, lmem_cache_region_t region);

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

#if defined(__cplusplus)
}
#endif

/*! @}*/

#endif /* FSL_FEATURE_SOC_LMEM_COUNT */
#endif /* __FSL_LMEM_CACHE_HAL_H__*/
/*******************************************************************************
 * EOF
 ******************************************************************************/