1 /* 2 * Copyright 2023 NXP 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #ifndef _FSL_MEMORY_H_ 8 #define _FSL_MEMORY_H_ 9 10 #include "fsl_common.h" 11 12 /******************************************************************************* 13 * Definitions 14 ******************************************************************************/ 15 /* Component ID definition, used by tools. */ 16 #ifndef FSL_COMPONENT_ID 17 #define FSL_COMPONENT_ID "platform.drivers.memory" 18 #endif 19 20 /* Clear bit28 secure indicator to get physical address */ 21 #define FSL_MEM_PHY_ADDR(addr) ((addr)&0xEFFFFFFFUL) 22 23 /* The FLEXSPI AMBA PC start address, refer to Reference Manual for detailed information */ 24 #define FSL_MEM_FLEXSPI_AMBA_PC_BEGIN FSL_MEM_PHY_ADDR(FlexSPI_AMBA_PC_CACHE_BASE) 25 /* The FLEXSPI AMBA PC end address, refer to Reference Manual for detailed information */ 26 #define FSL_MEM_FLEXSPI_AMBA_PC_END (FSL_MEM_FLEXSPI_AMBA_PC_BEGIN + 0x08000000UL - 1UL) 27 28 /* The FLEXSPI AMBA PS start address */ 29 #define FSL_MEM_FLEXSPI_AMBA_PS_BEGIN FSL_MEM_PHY_ADDR(FlexSPI_AMBA_PS_NCACHE_BASE) 30 /* The FLEXSPI AMBA PS end address */ 31 #define FSL_MEM_FLEXSPI_AMBA_PS_END (FSL_MEM_FLEXSPI_AMBA_PS_BEGIN + 0x08000000UL - 1UL) 32 /* 33 This alias allows the DMA to access PC flash memory with PS address. 34 */ 35 #define FSL_MEM_FLEXSPI_AMBA_OFFSET (FlexSPI_AMBA_PS_NCACHE_BASE - FlexSPI_AMBA_PC_CACHE_BASE) 36 37 typedef enum _mem_direction 38 { 39 kMEMORY_Local2DMA = 0, 40 kMEMORY_DMA2Local, 41 } mem_direction_t; 42 43 /******************************************************************************* 44 * API 45 ******************************************************************************/ 46 #if defined(__cplusplus) 47 extern "C" { 48 #endif 49 /*! 50 * @brief Convert the memory map address. 51 * 52 * This function convert the address between system mapped address and native mapped address. 53 * There maybe offset between subsystem native address and system address for some memory, 54 * this funciton convert the address to different memory map. 55 * @param addr address need to be converted. 56 * @param direction convert direction. 57 * @return the converted address 58 */ MEMORY_ConvertMemoryMapAddress(uint32_t addr,mem_direction_t direction)59static inline uint32_t MEMORY_ConvertMemoryMapAddress(uint32_t addr, mem_direction_t direction) 60 { 61 uint32_t dest; 62 uint32_t paddr = FSL_MEM_PHY_ADDR(addr); 63 64 switch (direction) 65 { 66 case kMEMORY_Local2DMA: 67 { 68 if ((paddr >= FSL_MEM_FLEXSPI_AMBA_PC_BEGIN) && (paddr <= FSL_MEM_FLEXSPI_AMBA_PC_END)) 69 { 70 dest = addr + FSL_MEM_FLEXSPI_AMBA_OFFSET; 71 } 72 else 73 { 74 dest = addr; 75 } 76 break; 77 } 78 case kMEMORY_DMA2Local: 79 { 80 if ((paddr >= FSL_MEM_FLEXSPI_AMBA_PS_BEGIN) && (paddr <= FSL_MEM_FLEXSPI_AMBA_PS_END)) 81 { 82 dest = addr - FSL_MEM_FLEXSPI_AMBA_OFFSET; 83 } 84 else 85 { 86 dest = addr; 87 } 88 break; 89 } 90 default: 91 dest = addr; 92 break; 93 } 94 95 return dest; 96 } 97 #if defined(__cplusplus) 98 } 99 #endif /* __cplusplus */ 100 #endif /* _FSL_MEMORY_H_ */ 101