1
1
/*
2
- * Copyright 2016-2021, 2023 NXP
2
+ * Copyright 2016-2021, 2023-2024 NXP
3
3
* All rights reserved.
4
4
*
5
5
* SPDX-License-Identifier: BSD-3-Clause
@@ -27,10 +27,21 @@ static CACHE64_CTRL_Type *const s_cache64ctrlBases[] = CACHE64_CTRL_BASE_PTRS;
27
27
static CACHE64_POLSEL_Type * const s_cache64polselBases [] = CACHE64_POLSEL_BASE_PTRS ;
28
28
#endif
29
29
30
- /* Array of CACHE64 physical memory base address. */
30
+ #if (defined(CACHE64_CTRL_PHYMEM_BASE_ALIAS_COUNT ))
31
+ #define CACHE64_PHYMEM_COLUM_COUNT CACHE64_CTRL_PHYMEM_BASE_ALIAS_COUNT
32
+ /* Array of CACHE64 physical memory base address,
33
+ it is a 2D array, the row indicate cache instance,
34
+ the column indicate the alias of one instance. */
35
+ static uint32_t const s_cache64PhymemBases [FSL_FEATURE_SOC_CACHE64_CTRL_COUNT ][CACHE64_PHYMEM_COLUM_COUNT ] = CACHE64_CTRL_PHYMEM_BASES ;
36
+ /* Array of CACHE64 physical size base address,
37
+ it is a 2D array, the row indicate cache instance,
38
+ the column indicate the alias of one instance. */
39
+ static uint32_t const s_cache64PhymemSizes [FSL_FEATURE_SOC_CACHE64_CTRL_COUNT ][CACHE64_PHYMEM_COLUM_COUNT ] = CACHE64_CTRL_PHYMEM_SIZES ;
40
+ #else
41
+ #define CACHE64_PHYMEM_COLUM_COUNT 1
31
42
static uint32_t const s_cache64PhymemBases [] = CACHE64_CTRL_PHYMEM_BASES ;
32
- /* Array of CACHE64 physical memory size. */
33
43
static uint32_t const s_cache64PhymemSizes [] = CACHE64_CTRL_PHYMEM_SIZES ;
44
+ #endif
34
45
35
46
#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL ) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL )
36
47
#ifdef CACHE64_CLOCKS
@@ -39,6 +50,8 @@ static const clock_ip_name_t s_cache64Clocks[] = CACHE64_CLOCKS;
39
50
#endif
40
51
#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
41
52
53
+ volatile uint8_t g_cache64MemPhyAliasId = 0U ;
54
+
42
55
/*******************************************************************************
43
56
* Code
44
57
******************************************************************************/
@@ -55,7 +68,7 @@ uint32_t CACHE64_GetInstance(CACHE64_POLSEL_Type *base)
55
68
56
69
for (i = 0 ; i < ARRAY_SIZE (s_cache64polselBases ); i ++ )
57
70
{
58
- if (base == s_cache64polselBases [i ])
71
+ if (MSDK_REG_SECURE_ADDR ( base ) == MSDK_REG_SECURE_ADDR ( s_cache64polselBases [i ]) )
59
72
{
60
73
break ;
61
74
}
@@ -75,18 +88,28 @@ uint32_t CACHE64_GetInstance(CACHE64_POLSEL_Type *base)
75
88
*/
76
89
uint32_t CACHE64_GetInstanceByAddr (uint32_t address )
77
90
{
78
- uint32_t i ;
91
+ uint32_t i = 0UL ;
92
+ uint32_t phyMemBase [FSL_FEATURE_SOC_CACHE64_CTRL_COUNT ][CACHE64_PHYMEM_COLUM_COUNT ];
93
+ uint32_t phyMemSize [FSL_FEATURE_SOC_CACHE64_CTRL_COUNT ][CACHE64_PHYMEM_COLUM_COUNT ];
94
+ memcpy (phyMemBase , s_cache64PhymemBases , sizeof (s_cache64PhymemBases ));
95
+ memcpy (phyMemSize , s_cache64PhymemSizes , sizeof (s_cache64PhymemSizes ));
79
96
80
- for (i = 0 ; i < ARRAY_SIZE (s_cache64ctrlBases ); i ++ )
97
+ while (i < ARRAY_SIZE (s_cache64ctrlBases ))
81
98
{
82
- if (( address >= s_cache64PhymemBases [ i ]) &&
83
- ( address < ( s_cache64PhymemBases [ i ] + s_cache64PhymemSizes [ i ] - 0x01U )) )
99
+ g_cache64MemPhyAliasId = 0U ;
100
+ while ( g_cache64MemPhyAliasId < CACHE64_PHYMEM_COLUM_COUNT )
84
101
{
85
- break ;
102
+ if ((MSDK_REG_SECURE_ADDR (address ) >= MSDK_REG_SECURE_ADDR (phyMemBase [i ][g_cache64MemPhyAliasId ])) && (MSDK_REG_SECURE_ADDR (address ) < MSDK_REG_SECURE_ADDR (phyMemBase [i ][g_cache64MemPhyAliasId ] + phyMemSize [i ][g_cache64MemPhyAliasId ] - 0x01U )))
103
+ {
104
+ return i ;
105
+ }
106
+ g_cache64MemPhyAliasId ++ ;
86
107
}
108
+ i ++ ;
87
109
}
88
-
89
- return i ;
110
+
111
+ assert (false);
112
+ return 0xFFFFFFFFUL ;
90
113
}
91
114
92
115
#if (defined(FSL_FEATURE_SOC_CACHE64_POLSEL_COUNT ) && (FSL_FEATURE_SOC_CACHE64_POLSEL_COUNT > 0 ))
@@ -142,9 +165,11 @@ status_t CACHE64_Init(CACHE64_POLSEL_Type *base, const cache64_config_t *config)
142
165
*/
143
166
void CACHE64_GetDefaultConfig (cache64_config_t * config )
144
167
{
168
+ uint32_t phyMemSize [FSL_FEATURE_SOC_CACHE64_CTRL_COUNT ][CACHE64_PHYMEM_COLUM_COUNT ];
169
+ memcpy (phyMemSize , s_cache64PhymemSizes , sizeof (s_cache64PhymemSizes ));
145
170
(void )memset (config , 0 , sizeof (cache64_config_t ));
146
171
147
- config -> boundaryAddr [0 ] = s_cache64PhymemSizes [ 0 ];
172
+ config -> boundaryAddr [0 ] = phyMemSize [ 0 ][ g_cache64MemPhyAliasId ];
148
173
config -> policy [0 ] = kCACHE64_PolicyWriteBack ;
149
174
}
150
175
#endif
@@ -215,20 +240,24 @@ void CACHE64_InvalidateCacheByRange(uint32_t address, uint32_t size_byte)
215
240
{
216
241
if (size_byte > 0UL )
217
242
{
218
- uint32_t endAddr = address + size_byte - 0x01U ;
243
+ uint32_t endAddr = MSDK_REG_SECURE_ADDR ( address + size_byte - 0x01U ) ;
219
244
uint32_t pccReg = 0 ;
220
245
/* Align address to cache line size. */
221
- uint32_t startAddr = address & ~((uint32_t )CACHE64_LINESIZE_BYTE - 1U );
246
+ uint32_t startAddr = MSDK_REG_SECURE_ADDR ( address & ~((uint32_t )CACHE64_LINESIZE_BYTE - 1U ) );
222
247
uint32_t instance = CACHE64_GetInstanceByAddr (address );
223
248
uint32_t endLim ;
224
249
CACHE64_CTRL_Type * base ;
250
+ uint32_t phyMemBase [FSL_FEATURE_SOC_CACHE64_CTRL_COUNT ][CACHE64_PHYMEM_COLUM_COUNT ];
251
+ uint32_t phyMemSize [FSL_FEATURE_SOC_CACHE64_CTRL_COUNT ][CACHE64_PHYMEM_COLUM_COUNT ];
252
+ memcpy (phyMemBase , s_cache64PhymemBases , sizeof (s_cache64PhymemBases ));
253
+ memcpy (phyMemSize , s_cache64PhymemSizes , sizeof (s_cache64PhymemSizes ));
225
254
226
255
if (instance >= ARRAY_SIZE (s_cache64ctrlBases ))
227
256
{
228
257
return ;
229
258
}
230
259
base = s_cache64ctrlBases [instance ];
231
- endLim = s_cache64PhymemBases [instance ] + s_cache64PhymemSizes [instance ] - 0x01U ;
260
+ endLim = MSDK_REG_SECURE_ADDR ( phyMemBase [instance ][ g_cache64MemPhyAliasId ] + phyMemSize [instance ][ g_cache64MemPhyAliasId ] - 0x01U ) ;
232
261
endAddr = endAddr > endLim ? endLim : endAddr ;
233
262
234
263
/* Set the invalidate by line command and use the physical address. */
@@ -281,20 +310,24 @@ void CACHE64_CleanCacheByRange(uint32_t address, uint32_t size_byte)
281
310
{
282
311
if (size_byte > 0UL )
283
312
{
284
- uint32_t endAddr = address + size_byte - 0x01U ;
313
+ uint32_t endAddr = MSDK_REG_SECURE_ADDR ( address + size_byte - 0x01U ) ;
285
314
uint32_t pccReg = 0 ;
286
315
/* Align address to cache line size. */
287
- uint32_t startAddr = address & ~((uint32_t )CACHE64_LINESIZE_BYTE - 1U );
316
+ uint32_t startAddr = MSDK_REG_SECURE_ADDR ( address & ~((uint32_t )CACHE64_LINESIZE_BYTE - 1U ) );
288
317
uint32_t instance = CACHE64_GetInstanceByAddr (address );
289
318
uint32_t endLim ;
290
319
CACHE64_CTRL_Type * base ;
320
+ uint32_t phyMemBase [FSL_FEATURE_SOC_CACHE64_CTRL_COUNT ][CACHE64_PHYMEM_COLUM_COUNT ];
321
+ uint32_t phyMemSize [FSL_FEATURE_SOC_CACHE64_CTRL_COUNT ][CACHE64_PHYMEM_COLUM_COUNT ];
322
+ memcpy (phyMemBase , s_cache64PhymemBases , sizeof (s_cache64PhymemBases ));
323
+ memcpy (phyMemSize , s_cache64PhymemSizes , sizeof (s_cache64PhymemSizes ));
291
324
292
325
if (instance >= ARRAY_SIZE (s_cache64ctrlBases ))
293
326
{
294
327
return ;
295
328
}
296
329
base = s_cache64ctrlBases [instance ];
297
- endLim = s_cache64PhymemBases [instance ] + s_cache64PhymemSizes [instance ] - 0x01U ;
330
+ endLim = MSDK_REG_SECURE_ADDR ( phyMemBase [instance ][ g_cache64MemPhyAliasId ] + phyMemSize [instance ][ g_cache64MemPhyAliasId ] - 0x01U ) ;
298
331
endAddr = endAddr > endLim ? endLim : endAddr ;
299
332
300
333
/* Set the push by line command. */
@@ -349,20 +382,24 @@ void CACHE64_CleanInvalidateCacheByRange(uint32_t address, uint32_t size_byte)
349
382
{
350
383
if (size_byte > 0UL )
351
384
{
352
- uint32_t endAddr = address + size_byte - 0x01U ;
385
+ uint32_t endAddr = MSDK_REG_SECURE_ADDR ( address + size_byte - 0x01U ) ;
353
386
uint32_t pccReg = 0 ;
354
387
/* Align address to cache line size. */
355
- uint32_t startAddr = address & ~((uint32_t )CACHE64_LINESIZE_BYTE - 1U );
388
+ uint32_t startAddr = MSDK_REG_SECURE_ADDR ( address & ~((uint32_t )CACHE64_LINESIZE_BYTE - 1U ) );
356
389
uint32_t instance = CACHE64_GetInstanceByAddr (address );
357
390
uint32_t endLim ;
358
391
CACHE64_CTRL_Type * base ;
392
+ uint32_t phyMemBase [FSL_FEATURE_SOC_CACHE64_CTRL_COUNT ][CACHE64_PHYMEM_COLUM_COUNT ];
393
+ uint32_t phyMemSize [FSL_FEATURE_SOC_CACHE64_CTRL_COUNT ][CACHE64_PHYMEM_COLUM_COUNT ];
394
+ memcpy (phyMemBase , s_cache64PhymemBases , sizeof (s_cache64PhymemBases ));
395
+ memcpy (phyMemSize , s_cache64PhymemSizes , sizeof (s_cache64PhymemSizes ));
359
396
360
397
if (instance >= ARRAY_SIZE (s_cache64ctrlBases ))
361
398
{
362
399
return ;
363
400
}
364
401
base = s_cache64ctrlBases [instance ];
365
- endLim = s_cache64PhymemBases [instance ] + s_cache64PhymemSizes [instance ] - 0x01U ;
402
+ endLim = MSDK_REG_SECURE_ADDR ( phyMemBase [instance ][ g_cache64MemPhyAliasId ] + phyMemSize [instance ][ g_cache64MemPhyAliasId ] - 0x01U ) ;
366
403
endAddr = endAddr > endLim ? endLim : endAddr ;
367
404
368
405
/* Set the push by line command. */
0 commit comments