1 /* 2 * Copyright 2017-2018 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 /* The CM4 subsystem local TCM start address, refer to Reference Manual for detailed information */ 20 #define FSL_MEM_M4_TCM_BEGIN 0x1FFE0000U 21 /* The CM4 subsystem local TCM end address, refer to Reference Manual for detailed information */ 22 #define FSL_MEM_M4_TCM_END 0x2001FFFFU 23 24 /* The alias start address for CM4 subsystem */ 25 #define FSL_MEM_M4_ALIAS_BEGIN 0x21000000U 26 /* The alias end address for CM4 subsystem */ 27 #define FSL_MEM_M4_ALIAS_END 0x211FFFFFU 28 /* 29 This alias allows the ROM and OCRAM to be mapped to the CM4 system address space without the need 30 to enable and configure SMMU. 31 System-level address 0x0000_0000 to 0x001F_FFFF is mapped to the CM4 system address space 0x2100_0000 to 0x211F_FFFF 32 */ 33 #define FSL_MEM_M4_ALIAS_OFFSET 0x21000000U 34 35 #define FSL_MEM_M4_TCM_OFFSET 0x15000000U 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 63 switch (direction) 64 { 65 case kMEMORY_Local2DMA: 66 { 67 if ((addr >= FSL_MEM_M4_TCM_BEGIN) && (addr <= FSL_MEM_M4_TCM_END)) 68 { 69 dest = addr + FSL_MEM_M4_TCM_OFFSET; 70 } 71 else if ((addr >= FSL_MEM_M4_ALIAS_BEGIN) && (addr <= FSL_MEM_M4_ALIAS_END)) 72 { 73 dest = addr - FSL_MEM_M4_ALIAS_OFFSET; 74 } 75 else 76 { 77 dest = addr; 78 } 79 break; 80 } 81 case kMEMORY_DMA2Local: 82 { 83 if ((addr >= (FSL_MEM_M4_TCM_BEGIN + FSL_MEM_M4_TCM_OFFSET)) && 84 (addr <= (FSL_MEM_M4_TCM_END + FSL_MEM_M4_TCM_OFFSET))) 85 { 86 dest = addr - FSL_MEM_M4_TCM_OFFSET; 87 } 88 else if (addr <= (FSL_MEM_M4_ALIAS_END - FSL_MEM_M4_ALIAS_OFFSET)) 89 { 90 dest = addr + FSL_MEM_M4_ALIAS_OFFSET; 91 } 92 else 93 { 94 dest = addr; 95 } 96 break; 97 } 98 default: 99 dest = addr; 100 break; 101 } 102 103 return dest; 104 } 105 #if defined(__cplusplus) 106 } 107 #endif /* __cplusplus */ 108 #endif /* _FSL_MEMORY_H_ */ 109