11/*
2- * Copyright 2016-2021, 2023 NXP
2+ * Copyright 2016-2021, 2023-2024 NXP
33 * All rights reserved.
44 *
55 * SPDX-License-Identifier: BSD-3-Clause
@@ -27,10 +27,21 @@ static CACHE64_CTRL_Type *const s_cache64ctrlBases[] = CACHE64_CTRL_BASE_PTRS;
2727static CACHE64_POLSEL_Type * const s_cache64polselBases [] = CACHE64_POLSEL_BASE_PTRS ;
2828#endif
2929
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
3142static uint32_t const s_cache64PhymemBases [] = CACHE64_CTRL_PHYMEM_BASES ;
32- /* Array of CACHE64 physical memory size. */
3343static uint32_t const s_cache64PhymemSizes [] = CACHE64_CTRL_PHYMEM_SIZES ;
44+ #endif
3445
3546#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL ) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL )
3647#ifdef CACHE64_CLOCKS
@@ -39,6 +50,8 @@ static const clock_ip_name_t s_cache64Clocks[] = CACHE64_CLOCKS;
3950#endif
4051#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
4152
53+ volatile uint8_t g_cache64MemPhyAliasId = 0U ;
54+
4255/*******************************************************************************
4356 * Code
4457 ******************************************************************************/
@@ -55,7 +68,7 @@ uint32_t CACHE64_GetInstance(CACHE64_POLSEL_Type *base)
5568
5669 for (i = 0 ; i < ARRAY_SIZE (s_cache64polselBases ); i ++ )
5770 {
58- if (base == s_cache64polselBases [i ])
71+ if (MSDK_REG_SECURE_ADDR ( base ) == MSDK_REG_SECURE_ADDR ( s_cache64polselBases [i ]) )
5972 {
6073 break ;
6174 }
@@ -75,18 +88,28 @@ uint32_t CACHE64_GetInstance(CACHE64_POLSEL_Type *base)
7588 */
7689uint32_t CACHE64_GetInstanceByAddr (uint32_t address )
7790{
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 ));
7996
80- for (i = 0 ; i < ARRAY_SIZE (s_cache64ctrlBases ); i ++ )
97+ while (i < ARRAY_SIZE (s_cache64ctrlBases ))
8198 {
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 )
84101 {
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 ++ ;
86107 }
108+ i ++ ;
87109 }
88-
89- return i ;
110+
111+ assert (false);
112+ return 0xFFFFFFFFUL ;
90113}
91114
92115#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)
142165 */
143166void CACHE64_GetDefaultConfig (cache64_config_t * config )
144167{
168+ uint32_t phyMemSize [FSL_FEATURE_SOC_CACHE64_CTRL_COUNT ][CACHE64_PHYMEM_COLUM_COUNT ];
169+ memcpy (phyMemSize , s_cache64PhymemSizes , sizeof (s_cache64PhymemSizes ));
145170 (void )memset (config , 0 , sizeof (cache64_config_t ));
146171
147- config -> boundaryAddr [0 ] = s_cache64PhymemSizes [ 0 ];
172+ config -> boundaryAddr [0 ] = phyMemSize [ 0 ][ g_cache64MemPhyAliasId ];
148173 config -> policy [0 ] = kCACHE64_PolicyWriteBack ;
149174}
150175#endif
@@ -215,20 +240,24 @@ void CACHE64_InvalidateCacheByRange(uint32_t address, uint32_t size_byte)
215240{
216241 if (size_byte > 0UL )
217242 {
218- uint32_t endAddr = address + size_byte - 0x01U ;
243+ uint32_t endAddr = MSDK_REG_SECURE_ADDR ( address + size_byte - 0x01U ) ;
219244 uint32_t pccReg = 0 ;
220245 /* 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 ) );
222247 uint32_t instance = CACHE64_GetInstanceByAddr (address );
223248 uint32_t endLim ;
224249 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 ));
225254
226255 if (instance >= ARRAY_SIZE (s_cache64ctrlBases ))
227256 {
228257 return ;
229258 }
230259 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 ) ;
232261 endAddr = endAddr > endLim ? endLim : endAddr ;
233262
234263 /* 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)
281310{
282311 if (size_byte > 0UL )
283312 {
284- uint32_t endAddr = address + size_byte - 0x01U ;
313+ uint32_t endAddr = MSDK_REG_SECURE_ADDR ( address + size_byte - 0x01U ) ;
285314 uint32_t pccReg = 0 ;
286315 /* 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 ) );
288317 uint32_t instance = CACHE64_GetInstanceByAddr (address );
289318 uint32_t endLim ;
290319 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 ));
291324
292325 if (instance >= ARRAY_SIZE (s_cache64ctrlBases ))
293326 {
294327 return ;
295328 }
296329 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 ) ;
298331 endAddr = endAddr > endLim ? endLim : endAddr ;
299332
300333 /* Set the push by line command. */
@@ -349,20 +382,24 @@ void CACHE64_CleanInvalidateCacheByRange(uint32_t address, uint32_t size_byte)
349382{
350383 if (size_byte > 0UL )
351384 {
352- uint32_t endAddr = address + size_byte - 0x01U ;
385+ uint32_t endAddr = MSDK_REG_SECURE_ADDR ( address + size_byte - 0x01U ) ;
353386 uint32_t pccReg = 0 ;
354387 /* 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 ) );
356389 uint32_t instance = CACHE64_GetInstanceByAddr (address );
357390 uint32_t endLim ;
358391 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 ));
359396
360397 if (instance >= ARRAY_SIZE (s_cache64ctrlBases ))
361398 {
362399 return ;
363400 }
364401 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 ) ;
366403 endAddr = endAddr > endLim ? endLim : endAddr ;
367404
368405 /* Set the push by line command. */
0 commit comments