Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 

417 righe
18 KiB

  1. /*
  2. * Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc.
  3. * Copyright 2016-2020 NXP
  4. * All rights reserved.
  5. *
  6. * SPDX-License-Identifier: BSD-3-Clause
  7. */
  8. #ifndef _FSL_SYSMPU_H_
  9. #define _FSL_SYSMPU_H_
  10. #include "fsl_common.h"
  11. /*!
  12. * @addtogroup sysmpu
  13. * @{
  14. */
  15. /*******************************************************************************
  16. * Definitions
  17. ******************************************************************************/
  18. /*! @name Driver version */
  19. /*@{*/
  20. /*! @brief SYSMPU driver version 2.2.3. */
  21. #define FSL_SYSMPU_DRIVER_VERSION (MAKE_VERSION(2, 2, 3))
  22. /*@}*/
  23. /*! @brief define the start master port with read and write attributes. */
  24. #define SYSMPU_MASTER_RWATTRIBUTE_START_PORT (4U)
  25. /*! @brief SYSMPU the bit shift for masters with privilege rights: read write and execute. */
  26. #define SYSMPU_REGION_RWXRIGHTS_MASTER_SHIFT(n) ((n)*6U)
  27. /*! @brief SYSMPU masters with read, write and execute rights bit mask. */
  28. #define SYSMPU_REGION_RWXRIGHTS_MASTER_MASK(n) (0x1FUL << SYSMPU_REGION_RWXRIGHTS_MASTER_SHIFT(n))
  29. /*! @brief SYSMPU masters with read, write and execute rights bit width. */
  30. #define SYSMPU_REGION_RWXRIGHTS_MASTER_WIDTH 5U
  31. /*! @brief SYSMPU masters with read, write and execute rights priority setting. */
  32. #define SYSMPU_REGION_RWXRIGHTS_MASTER(n, x) \
  33. (((uint32_t)(((uint32_t)(x)) << SYSMPU_REGION_RWXRIGHTS_MASTER_SHIFT(n))) & SYSMPU_REGION_RWXRIGHTS_MASTER_MASK(n))
  34. /*! @brief SYSMPU masters with read, write and execute rights process enable bit shift. */
  35. #define SYSMPU_REGION_RWXRIGHTS_MASTER_PE_SHIFT(n) ((n)*6U + SYSMPU_REGION_RWXRIGHTS_MASTER_WIDTH)
  36. /*! @brief SYSMPU masters with read, write and execute rights process enable bit mask. */
  37. #define SYSMPU_REGION_RWXRIGHTS_MASTER_PE_MASK(n) (0x1UL << SYSMPU_REGION_RWXRIGHTS_MASTER_PE_SHIFT(n))
  38. /*! @brief SYSMPU masters with read, write and execute rights process enable setting. */
  39. #define SYSMPU_REGION_RWXRIGHTS_MASTER_PE(n, x) \
  40. (((uint32_t)(((uint32_t)(x)) << SYSMPU_REGION_RWXRIGHTS_MASTER_PE_SHIFT(n))) & \
  41. SYSMPU_REGION_RWXRIGHTS_MASTER_PE_MASK(n))
  42. /*! @brief SYSMPU masters with normal read write permission bit shift. */
  43. #define SYSMPU_REGION_RWRIGHTS_MASTER_SHIFT(n) (((n)-SYSMPU_MASTER_RWATTRIBUTE_START_PORT) * 2U + 24U)
  44. /*! @brief SYSMPU masters with normal read write rights bit mask. */
  45. #define SYSMPU_REGION_RWRIGHTS_MASTER_MASK(n) (0x3UL << SYSMPU_REGION_RWRIGHTS_MASTER_SHIFT(n))
  46. /*! @brief SYSMPU masters with normal read write rights priority setting. */
  47. #define SYSMPU_REGION_RWRIGHTS_MASTER(n, x) \
  48. (((uint32_t)(((uint32_t)(x)) << SYSMPU_REGION_RWRIGHTS_MASTER_SHIFT(n))) & SYSMPU_REGION_RWRIGHTS_MASTER_MASK(n))
  49. /*! @brief Describes the number of SYSMPU regions. */
  50. typedef enum _sysmpu_region_total_num
  51. {
  52. kSYSMPU_8Regions = 0x0U, /*!< SYSMPU supports 8 regions. */
  53. kSYSMPU_12Regions = 0x1U, /*!< SYSMPU supports 12 regions. */
  54. kSYSMPU_16Regions = 0x2U /*!< SYSMPU supports 16 regions. */
  55. } sysmpu_region_total_num_t;
  56. /*! @brief SYSMPU slave port number. */
  57. typedef enum _sysmpu_slave
  58. {
  59. kSYSMPU_Slave0 = 0U, /*!< SYSMPU slave port 0. */
  60. kSYSMPU_Slave1 = 1U, /*!< SYSMPU slave port 1. */
  61. kSYSMPU_Slave2 = 2U, /*!< SYSMPU slave port 2. */
  62. kSYSMPU_Slave3 = 3U, /*!< SYSMPU slave port 3. */
  63. kSYSMPU_Slave4 = 4U, /*!< SYSMPU slave port 4. */
  64. #if FSL_FEATURE_SYSMPU_SLAVE_COUNT > 5
  65. kSYSMPU_Slave5 = 5U, /*!< SYSMPU slave port 5. */
  66. #endif
  67. #if FSL_FEATURE_SYSMPU_SLAVE_COUNT > 6
  68. kSYSMPU_Slave6 = 6U, /*!< SYSMPU slave port 6. */
  69. #endif
  70. #if FSL_FEATURE_SYSMPU_SLAVE_COUNT > 7
  71. kSYSMPU_Slave7 = 7U, /*!< SYSMPU slave port 7. */
  72. #endif
  73. } sysmpu_slave_t;
  74. /*! @brief SYSMPU error access control detail. */
  75. typedef enum _sysmpu_err_access_control
  76. {
  77. kSYSMPU_NoRegionHit = 0U, /*!< No region hit error. */
  78. kSYSMPU_NoneOverlappRegion = 1U, /*!< Access single region error. */
  79. kSYSMPU_OverlappRegion = 2U /*!< Access overlapping region error. */
  80. } sysmpu_err_access_control_t;
  81. /*! @brief SYSMPU error access type. */
  82. typedef enum _sysmpu_err_access_type
  83. {
  84. kSYSMPU_ErrTypeRead = 0U, /*!< SYSMPU error access type --- read. */
  85. kSYSMPU_ErrTypeWrite = 1U /*!< SYSMPU error access type --- write. */
  86. } sysmpu_err_access_type_t;
  87. /*! @brief SYSMPU access error attributes.*/
  88. typedef enum _sysmpu_err_attributes
  89. {
  90. kSYSMPU_InstructionAccessInUserMode = 0U, /*!< Access instruction error in user mode. */
  91. kSYSMPU_DataAccessInUserMode = 1U, /*!< Access data error in user mode. */
  92. kSYSMPU_InstructionAccessInSupervisorMode = 2U, /*!< Access instruction error in supervisor mode. */
  93. kSYSMPU_DataAccessInSupervisorMode = 3U /*!< Access data error in supervisor mode. */
  94. } sysmpu_err_attributes_t;
  95. /*! @brief SYSMPU access rights in supervisor mode for bus master 0 ~ 3. */
  96. typedef enum _sysmpu_supervisor_access_rights
  97. {
  98. kSYSMPU_SupervisorReadWriteExecute = 0U, /*!< Read write and execute operations are allowed in supervisor mode. */
  99. kSYSMPU_SupervisorReadExecute = 1U, /*!< Read and execute operations are allowed in supervisor mode. */
  100. kSYSMPU_SupervisorReadWrite = 2U, /*!< Read write operations are allowed in supervisor mode. */
  101. kSYSMPU_SupervisorEqualToUsermode = 3U /*!< Access permission equal to user mode. */
  102. } sysmpu_supervisor_access_rights_t;
  103. /*! @brief SYSMPU access rights in user mode for bus master 0 ~ 3. */
  104. typedef enum _sysmpu_user_access_rights
  105. {
  106. kSYSMPU_UserNoAccessRights = 0U, /*!< No access allowed in user mode. */
  107. kSYSMPU_UserExecute = 1U, /*!< Execute operation is allowed in user mode. */
  108. kSYSMPU_UserWrite = 2U, /*!< Write operation is allowed in user mode. */
  109. kSYSMPU_UserWriteExecute = 3U, /*!< Write and execute operations are allowed in user mode. */
  110. kSYSMPU_UserRead = 4U, /*!< Read is allowed in user mode. */
  111. kSYSMPU_UserReadExecute = 5U, /*!< Read and execute operations are allowed in user mode. */
  112. kSYSMPU_UserReadWrite = 6U, /*!< Read and write operations are allowed in user mode. */
  113. kSYSMPU_UserReadWriteExecute = 7U /*!< Read write and execute operations are allowed in user mode. */
  114. } sysmpu_user_access_rights_t;
  115. /*! @brief SYSMPU hardware basic information. */
  116. typedef struct _sysmpu_hardware_info
  117. {
  118. uint8_t hardwareRevisionLevel; /*!< Specifies the SYSMPU's hardware and definition reversion level. */
  119. uint8_t slavePortsNumbers; /*!< Specifies the number of slave ports connected to SYSMPU. */
  120. sysmpu_region_total_num_t regionsNumbers; /*!< Indicates the number of region descriptors implemented. */
  121. } sysmpu_hardware_info_t;
  122. /*! @brief SYSMPU detail error access information. */
  123. typedef struct _sysmpu_access_err_info
  124. {
  125. uint32_t master; /*!< Access error master. */
  126. sysmpu_err_attributes_t attributes; /*!< Access error attributes. */
  127. sysmpu_err_access_type_t accessType; /*!< Access error type. */
  128. sysmpu_err_access_control_t accessControl; /*!< Access error control. */
  129. uint32_t address; /*!< Access error address. */
  130. #if FSL_FEATURE_SYSMPU_HAS_PROCESS_IDENTIFIER
  131. uint8_t processorIdentification; /*!< Access error processor identification. */
  132. #endif /* FSL_FEATURE_SYSMPU_HAS_PROCESS_IDENTIFIER */
  133. } sysmpu_access_err_info_t;
  134. /*! @brief SYSMPU read/write/execute rights control for bus master 0 ~ 3. */
  135. typedef struct _sysmpu_rwxrights_master_access_control
  136. {
  137. sysmpu_supervisor_access_rights_t superAccessRights; /*!< Master access rights in supervisor mode. */
  138. sysmpu_user_access_rights_t userAccessRights; /*!< Master access rights in user mode. */
  139. #if FSL_FEATURE_SYSMPU_HAS_PROCESS_IDENTIFIER
  140. bool processIdentifierEnable; /*!< Enables or disables process identifier. */
  141. #endif /* FSL_FEATURE_SYSMPU_HAS_PROCESS_IDENTIFIER */
  142. } sysmpu_rwxrights_master_access_control_t;
  143. /*! @brief SYSMPU read/write access control for bus master 4 ~ 7. */
  144. typedef struct _sysmpu_rwrights_master_access_control
  145. {
  146. bool writeEnable; /*!< Enables or disables write permission. */
  147. bool readEnable; /*!< Enables or disables read permission. */
  148. } sysmpu_rwrights_master_access_control_t;
  149. /*!
  150. * @brief SYSMPU region configuration structure.
  151. *
  152. * This structure is used to configure the regionNum region.
  153. * The accessRights1[0] ~ accessRights1[3] are used to configure the bus master
  154. * 0 ~ 3 with the privilege rights setting. The accessRights2[0] ~ accessRights2[3]
  155. * are used to configure the high master 4 ~ 7 with the normal read write permission.
  156. * The master port assignment is the chip configuration. Normally, the core is the
  157. * master 0, debugger is the master 1.
  158. * Note that the SYSMPU assigns a priority scheme where the debugger is treated as the highest
  159. * priority master followed by the core and then all the remaining masters.
  160. * SYSMPU protection does not allow writes from the core to affect the "regionNum 0" start
  161. * and end address nor the permissions associated with the debugger. It can only write
  162. * the permission fields associated with the other masters. This protection guarantees that
  163. * the debugger always has access to the entire address space and those rights can't
  164. * be changed by the core or any other bus master. Prepare
  165. * the region configuration when regionNum is 0.
  166. */
  167. typedef struct _sysmpu_region_config
  168. {
  169. uint32_t regionNum; /*!< SYSMPU region number, range form 0 ~ FSL_FEATURE_SYSMPU_DESCRIPTOR_COUNT - 1. */
  170. uint32_t startAddress; /*!< Memory region start address. Note: bit0 ~ bit4 always be marked as 0 by SYSMPU. The
  171. actual start address is 0-modulo-32 byte address. */
  172. uint32_t endAddress; /*!< Memory region end address. Note: bit0 ~ bit4 always be marked as 1 by SYSMPU. The actual
  173. end address is 31-modulo-32 byte address. */
  174. sysmpu_rwxrights_master_access_control_t
  175. accessRights1[4]; /*!< Masters with read, write and execute rights setting. */
  176. sysmpu_rwrights_master_access_control_t accessRights2[4]; /*!< Masters with normal read write rights setting. */
  177. #if FSL_FEATURE_SYSMPU_HAS_PROCESS_IDENTIFIER
  178. uint8_t processIdentifier; /*!< Process identifier used when "processIdentifierEnable" set with true. */
  179. uint8_t
  180. processIdMask; /*!< Process identifier mask. The setting bit will ignore the same bit in process identifier. */
  181. #endif /* FSL_FEATURE_SYSMPU_HAS_PROCESS_IDENTIFIER */
  182. } sysmpu_region_config_t;
  183. /*!
  184. * @brief The configuration structure for the SYSMPU initialization.
  185. *
  186. * This structure is used when calling the SYSMPU_Init function.
  187. */
  188. typedef struct _sysmpu_config
  189. {
  190. sysmpu_region_config_t regionConfig; /*!< Region access permission. */
  191. struct _sysmpu_config *next; /*!< Pointer to the next structure. */
  192. } sysmpu_config_t;
  193. /*******************************************************************************
  194. * API
  195. ******************************************************************************/
  196. #if defined(__cplusplus)
  197. extern "C" {
  198. #endif /* _cplusplus */
  199. /*!
  200. * @name Initialization and deinitialization
  201. * @{
  202. */
  203. /*!
  204. * @brief Initializes the SYSMPU with the user configuration structure.
  205. *
  206. * This function configures the SYSMPU module with the user-defined configuration.
  207. *
  208. * @param base SYSMPU peripheral base address.
  209. * @param config The pointer to the configuration structure.
  210. */
  211. void SYSMPU_Init(SYSMPU_Type *base, const sysmpu_config_t *config);
  212. /*!
  213. * @brief Deinitializes the SYSMPU regions.
  214. *
  215. * @param base SYSMPU peripheral base address.
  216. */
  217. void SYSMPU_Deinit(SYSMPU_Type *base);
  218. /* @}*/
  219. /*!
  220. * @name Basic Control Operations
  221. * @{
  222. */
  223. /*!
  224. * @brief Enables/disables the SYSMPU globally.
  225. *
  226. * Call this API to enable or disable the SYSMPU module.
  227. *
  228. * @param base SYSMPU peripheral base address.
  229. * @param enable True enable SYSMPU, false disable SYSMPU.
  230. */
  231. static inline void SYSMPU_Enable(SYSMPU_Type *base, bool enable)
  232. {
  233. if (enable)
  234. {
  235. /* Enable the SYSMPU globally. */
  236. base->CESR |= SYSMPU_CESR_VLD_MASK;
  237. }
  238. else
  239. { /* Disable the SYSMPU globally. */
  240. base->CESR &= ~SYSMPU_CESR_VLD_MASK;
  241. }
  242. }
  243. /*!
  244. * @brief Enables/disables the SYSMPU for a special region.
  245. *
  246. * When SYSMPU is enabled, call this API to disable an unused region
  247. * of an enabled SYSMPU. Call this API to minimize the power dissipation.
  248. *
  249. * @param base SYSMPU peripheral base address.
  250. * @param number SYSMPU region number.
  251. * @param enable True enable the special region SYSMPU, false disable the special region SYSMPU.
  252. */
  253. static inline void SYSMPU_RegionEnable(SYSMPU_Type *base, uint32_t number, bool enable)
  254. {
  255. if (enable)
  256. {
  257. /* Enable the #number region SYSMPU. */
  258. base->WORD[number][3] |= SYSMPU_WORD_VLD_MASK;
  259. }
  260. else
  261. { /* Disable the #number region SYSMPU. */
  262. base->WORD[number][3] &= ~SYSMPU_WORD_VLD_MASK;
  263. }
  264. }
  265. /*!
  266. * @brief Gets the SYSMPU basic hardware information.
  267. *
  268. * @param base SYSMPU peripheral base address.
  269. * @param hardwareInform The pointer to the SYSMPU hardware information structure. See "sysmpu_hardware_info_t".
  270. */
  271. void SYSMPU_GetHardwareInfo(SYSMPU_Type *base, sysmpu_hardware_info_t *hardwareInform);
  272. /*!
  273. * @brief Sets the SYSMPU region.
  274. *
  275. * Note: Due to the SYSMPU protection, the region number 0 does not allow writes from
  276. * core to affect the start and end address nor the permissions associated with
  277. * the debugger. It can only write the permission fields associated
  278. * with the other masters.
  279. *
  280. * @param base SYSMPU peripheral base address.
  281. * @param regionConfig The pointer to the SYSMPU user configuration structure. See "sysmpu_region_config_t".
  282. */
  283. void SYSMPU_SetRegionConfig(SYSMPU_Type *base, const sysmpu_region_config_t *regionConfig);
  284. /*!
  285. * @brief Sets the region start and end address.
  286. *
  287. * Memory region start address. Note: bit0 ~ bit4 is always marked as 0 by SYSMPU.
  288. * The actual start address by SYSMPU is 0-modulo-32 byte address.
  289. * Memory region end address. Note: bit0 ~ bit4 always be marked as 1 by SYSMPU.
  290. * The end address used by the SYSMPU is 31-modulo-32 byte address.
  291. * Note: Due to the SYSMPU protection, the startAddr and endAddr can't be
  292. * changed by the core when regionNum is 0.
  293. *
  294. * @param base SYSMPU peripheral base address.
  295. * @param regionNum SYSMPU region number. The range is from 0 to
  296. * FSL_FEATURE_SYSMPU_DESCRIPTOR_COUNT - 1.
  297. * @param startAddr Region start address.
  298. * @param endAddr Region end address.
  299. */
  300. void SYSMPU_SetRegionAddr(SYSMPU_Type *base, uint32_t regionNum, uint32_t startAddr, uint32_t endAddr);
  301. /*!
  302. * @brief Sets the SYSMPU region access rights for masters with read, write, and execute rights.
  303. * The SYSMPU access rights depend on two board classifications of bus masters.
  304. * The privilege rights masters and the normal rights masters.
  305. * The privilege rights masters have the read, write, and execute access rights.
  306. * Except the normal read and write rights, the execute rights are also
  307. * allowed for these masters. The privilege rights masters normally range from
  308. * bus masters 0 - 3. However, the maximum master number is device-specific.
  309. * See the "SYSMPU_PRIVILEGED_RIGHTS_MASTER_MAX_INDEX".
  310. * The normal rights masters access rights control see
  311. * "SYSMPU_SetRegionRwMasterAccessRights()".
  312. *
  313. * @param base SYSMPU peripheral base address.
  314. * @param regionNum SYSMPU region number. Should range from 0 to
  315. * FSL_FEATURE_SYSMPU_DESCRIPTOR_COUNT - 1.
  316. * @param masterNum SYSMPU bus master number. Should range from 0 to
  317. * SYSMPU_PRIVILEGED_RIGHTS_MASTER_MAX_INDEX.
  318. * @param accessRights The pointer to the SYSMPU access rights configuration. See
  319. * "sysmpu_rwxrights_master_access_control_t".
  320. */
  321. void SYSMPU_SetRegionRwxMasterAccessRights(SYSMPU_Type *base,
  322. uint32_t regionNum,
  323. uint32_t masterNum,
  324. const sysmpu_rwxrights_master_access_control_t *accessRights);
  325. #if FSL_FEATURE_SYSMPU_MASTER_COUNT > 4
  326. /*!
  327. * @brief Sets the SYSMPU region access rights for masters with read and write rights.
  328. * The SYSMPU access rights depend on two board classifications of bus masters.
  329. * The privilege rights masters and the normal rights masters.
  330. * The normal rights masters only have the read and write access permissions.
  331. * The privilege rights access control see "SYSMPU_SetRegionRwxMasterAccessRights".
  332. *
  333. * @param base SYSMPU peripheral base address.
  334. * @param regionNum SYSMPU region number. The range is from 0 to
  335. * FSL_FEATURE_SYSMPU_DESCRIPTOR_COUNT - 1.
  336. * @param masterNum SYSMPU bus master number. Should range from SYSMPU_MASTER_RWATTRIBUTE_START_PORT
  337. * to ~ FSL_FEATURE_SYSMPU_MASTER_COUNT - 1.
  338. * @param accessRights The pointer to the SYSMPU access rights configuration. See
  339. * "sysmpu_rwrights_master_access_control_t".
  340. */
  341. void SYSMPU_SetRegionRwMasterAccessRights(SYSMPU_Type *base,
  342. uint32_t regionNum,
  343. uint32_t masterNum,
  344. const sysmpu_rwrights_master_access_control_t *accessRights);
  345. #endif /* FSL_FEATURE_SYSMPU_MASTER_COUNT > 4 */
  346. /*!
  347. * @brief Gets the numbers of slave ports where errors occur.
  348. *
  349. * @param base SYSMPU peripheral base address.
  350. * @param slaveNum SYSMPU slave port number.
  351. * @return The slave ports error status.
  352. * true - error happens in this slave port.
  353. * false - error didn't happen in this slave port.
  354. */
  355. bool SYSMPU_GetSlavePortErrorStatus(SYSMPU_Type *base, sysmpu_slave_t slaveNum);
  356. /*!
  357. * @brief Gets the SYSMPU detailed error access information.
  358. *
  359. * @param base SYSMPU peripheral base address.
  360. * @param slaveNum SYSMPU slave port number.
  361. * @param errInform The pointer to the SYSMPU access error information. See "sysmpu_access_err_info_t".
  362. */
  363. void SYSMPU_GetDetailErrorAccessInfo(SYSMPU_Type *base, sysmpu_slave_t slaveNum, sysmpu_access_err_info_t *errInform);
  364. /* @} */
  365. #if defined(__cplusplus)
  366. }
  367. #endif
  368. /*! @}*/
  369. #endif /* _FSL_SYSMPU_H_ */