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 #if defined(MIMX8QM_CM4_CORE0) 36 /* System level TCM memory address = CM4 subsystem local TCM address + FSL_FEATURE_TCM_OFFSET */ 37 #define FSL_MEM_M4_TCM_OFFSET 0x15000000U 38 #elif defined(MIMX8QM_CM4_CORE1) 39 /* System level TCM memory address = CM4 subsystem local TCM address + FSL_FEATURE_TCM_OFFSET */ 40 #define FSL_MEM_M4_TCM_OFFSET 0x19000000U 41 #else 42 #error "Device is not supported by this driver!" 43 #endif 44 45 typedef enum _mem_direction 46 { 47 kMEMORY_Local2DMA = 0, 48 kMEMORY_DMA2Local, 49 } mem_direction_t; 50 51 /******************************************************************************* 52 * API 53 ******************************************************************************/ 54 #if defined(__cplusplus) 55 extern "C" { 56 #endif 57 /*! 58 * @brief Convert the memory map address. 59 * 60 * This function convert the address between system mapped address and native mapped address. 61 * There maybe offset between subsystem native address and system address for some memory, 62 * this funciton convert the address to different memory map. 63 * @param addr address need to be converted. 64 * @param direction convert direction. 65 * @return the converted address 66 */ MEMORY_ConvertMemoryMapAddress(uint32_t addr,mem_direction_t direction)67static inline uint32_t MEMORY_ConvertMemoryMapAddress(uint32_t addr, mem_direction_t direction) 68 { 69 uint32_t dest; 70 71 switch (direction) 72 { 73 case kMEMORY_Local2DMA: 74 { 75 if ((addr >= FSL_MEM_M4_TCM_BEGIN) && (addr <= FSL_MEM_M4_TCM_END)) 76 { 77 dest = addr + FSL_MEM_M4_TCM_OFFSET; 78 } 79 else if ((addr >= FSL_MEM_M4_ALIAS_BEGIN) && (addr <= FSL_MEM_M4_ALIAS_END)) 80 { 81 dest = addr - FSL_MEM_M4_ALIAS_OFFSET; 82 } 83 else 84 { 85 dest = addr; 86 } 87 break; 88 } 89 case kMEMORY_DMA2Local: 90 { 91 if ((addr >= (FSL_MEM_M4_TCM_BEGIN + FSL_MEM_M4_TCM_OFFSET)) && 92 (addr <= (FSL_MEM_M4_TCM_END + FSL_MEM_M4_TCM_OFFSET))) 93 { 94 dest = addr - FSL_MEM_M4_TCM_OFFSET; 95 } 96 else if (addr <= (FSL_MEM_M4_ALIAS_END - FSL_MEM_M4_ALIAS_OFFSET)) 97 { 98 dest = addr + FSL_MEM_M4_ALIAS_OFFSET; 99 } 100 else 101 { 102 dest = addr; 103 } 104 break; 105 } 106 default: 107 dest = addr; 108 break; 109 } 110 111 return dest; 112 } 113 #if defined(__cplusplus) 114 } 115 #endif /* __cplusplus */ 116 #endif /* _FSL_MEMORY_H_ */