hpm_exip_regs.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. /*
  2. * Copyright (c) 2021-2023 HPMicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef HPM_EXIP_H
  8. #define HPM_EXIP_H
  9. typedef struct {
  10. __R uint8_t RESERVED0[3072]; /* 0x0 - 0xBFF: Reserved */
  11. __RW uint32_t CFG; /* 0xC00: Configure Register */
  12. __R uint32_t STA; /* 0xC04: Status Register */
  13. __R uint8_t RESERVED1[248]; /* 0xC08 - 0xCFF: Reserved */
  14. struct {
  15. __RW uint32_t KEY0; /* 0xD00: AES KEY */
  16. __RW uint32_t KEY1; /* 0xD04: AES KEY */
  17. __RW uint32_t KEY2; /* 0xD08: AES KEY */
  18. __RW uint32_t KEY3; /* 0xD0C: AES KEY */
  19. __RW uint32_t CTR0; /* 0xD10: AES Counter Word */
  20. __RW uint32_t CTR1; /* 0xD14: AES Counter Word */
  21. __RW uint32_t RGN_SA; /* 0xD18: AES Region Descriptor Word */
  22. __RW uint32_t RGN_EA; /* 0xD1C: AES Region Descriptor Word */
  23. __R uint8_t RESERVED0[32]; /* 0xD20 - 0xD3F: Reserved */
  24. } RGN[4];
  25. } EXIP_Type;
  26. /* Bitfield definition for register: CFG */
  27. /*
  28. * EXIPE (RW)
  29. *
  30. * Block Enable, when set to "0", this block disabled, and all the data from QSPI will pass the the read mast directly; EXIP process data as the configuration in the CR regs.
  31. */
  32. #define EXIP_CFG_EXIPE_MASK (0x80000000UL)
  33. #define EXIP_CFG_EXIPE_SHIFT (31U)
  34. #define EXIP_CFG_EXIPE_SET(x) (((uint32_t)(x) << EXIP_CFG_EXIPE_SHIFT) & EXIP_CFG_EXIPE_MASK)
  35. #define EXIP_CFG_EXIPE_GET(x) (((uint32_t)(x) & EXIP_CFG_EXIPE_MASK) >> EXIP_CFG_EXIPE_SHIFT)
  36. /*
  37. * KBS (RW)
  38. *
  39. * KeyBlob Initiate
  40. * "0", Key Blob was not initiated yet.
  41. * "1", Key Blob was properly initiated.
  42. */
  43. #define EXIP_CFG_KBS_MASK (0x40000000UL)
  44. #define EXIP_CFG_KBS_SHIFT (30U)
  45. #define EXIP_CFG_KBS_SET(x) (((uint32_t)(x) << EXIP_CFG_KBS_SHIFT) & EXIP_CFG_KBS_MASK)
  46. #define EXIP_CFG_KBS_GET(x) (((uint32_t)(x) & EXIP_CFG_KBS_MASK) >> EXIP_CFG_KBS_SHIFT)
  47. /*
  48. * KBEN (RW)
  49. *
  50. * Key Block Processing Enable.
  51. * "0", key blob processing is enabled.
  52. * "1", Key blob processing is disabled.
  53. */
  54. #define EXIP_CFG_KBEN_MASK (0x20U)
  55. #define EXIP_CFG_KBEN_SHIFT (5U)
  56. #define EXIP_CFG_KBEN_SET(x) (((uint32_t)(x) << EXIP_CFG_KBEN_SHIFT) & EXIP_CFG_KBEN_MASK)
  57. #define EXIP_CFG_KBEN_GET(x) (((uint32_t)(x) & EXIP_CFG_KBEN_MASK) >> EXIP_CFG_KBEN_SHIFT)
  58. /*
  59. * IE (RW)
  60. *
  61. * Interrupt Request Enable. This field determines if the setting of SR[KBERR] generates a system interrupt.
  62. * 0b - SR[KBERR] = 1 does not generate an interrupt request.
  63. * 1b - SR[KBERR] = 1 generates an interrupt request.
  64. */
  65. #define EXIP_CFG_IE_MASK (0x1U)
  66. #define EXIP_CFG_IE_SHIFT (0U)
  67. #define EXIP_CFG_IE_SET(x) (((uint32_t)(x) << EXIP_CFG_IE_SHIFT) & EXIP_CFG_IE_MASK)
  68. #define EXIP_CFG_IE_GET(x) (((uint32_t)(x) & EXIP_CFG_IE_MASK) >> EXIP_CFG_IE_SHIFT)
  69. /* Bitfield definition for register: STA */
  70. /*
  71. * KBC (RO)
  72. *
  73. * Key Blob Processing Done
  74. * "0", key blob was not enabled or processing not done yet.
  75. * "1", key blob processing was enabled and done.
  76. */
  77. #define EXIP_STA_KBC_MASK (0x80000000UL)
  78. #define EXIP_STA_KBC_SHIFT (31U)
  79. #define EXIP_STA_KBC_GET(x) (((uint32_t)(x) & EXIP_STA_KBC_MASK) >> EXIP_STA_KBC_SHIFT)
  80. /*
  81. * KBEN (RO)
  82. *
  83. * Key Blob Processing Enable
  84. * “0”, Key Blob processing is not enabled.
  85. * "1", Key Blob processing is enabled.
  86. */
  87. #define EXIP_STA_KBEN_MASK (0x40000000UL)
  88. #define EXIP_STA_KBEN_SHIFT (30U)
  89. #define EXIP_STA_KBEN_GET(x) (((uint32_t)(x) & EXIP_STA_KBEN_MASK) >> EXIP_STA_KBEN_SHIFT)
  90. /*
  91. * EXIPE (RO)
  92. *
  93. * Block Enable Mode.
  94. * "0", EXIP disabled and bypasses all the data by the QSPI
  95. * "1", EXIP is enabled, and processes data from the QSPI as the hw configuration bits.
  96. */
  97. #define EXIP_STA_EXIPE_MASK (0x20000000UL)
  98. #define EXIP_STA_EXIPE_SHIFT (29U)
  99. #define EXIP_STA_EXIPE_GET(x) (((uint32_t)(x) & EXIP_STA_EXIPE_MASK) >> EXIP_STA_EXIPE_SHIFT)
  100. /*
  101. * RGNE (RO)
  102. *
  103. * Context Integrity Error.
  104. * This field signals an integrity error was detected in a specific context during key blob processing as signaled by SR[KBERR] = 1. bit 19 corresponds to context 3, bit 18 to context 2, bit 17 to context 1, bit 16 to context 0.
  105. * This field is cleared if SR[KBERR] was set in response to a write asserting CR[FERR]. It is also cleared when SR[KBERR] is cleared.
  106. * 0000b - No key blob integrity error was detected for context “n”.
  107. * 0001b - A key blob integrity error was detected in context “n”.
  108. */
  109. #define EXIP_STA_RGNE_MASK (0xF0000UL)
  110. #define EXIP_STA_RGNE_SHIFT (16U)
  111. #define EXIP_STA_RGNE_GET(x) (((uint32_t)(x) & EXIP_STA_RGNE_MASK) >> EXIP_STA_RGNE_SHIFT)
  112. /*
  113. * KBERR (RO)
  114. *
  115. * Key Blob Error
  116. * This field signals that one or more errors were detected during key blob processing. SR[ERCTX] provides
  117. * the details on which contexts detected errors. This indicator can also be set by writing CR[FERR] = 1 (for
  118. * testing purposes). If CR[IRQE] = 1, then the assertion of KBERR generates an interrupt request.
  119. * "0", No key blob error detected.
  120. * "1", One or more key blob errors has been detected
  121. */
  122. #define EXIP_STA_KBERR_MASK (0x1U)
  123. #define EXIP_STA_KBERR_SHIFT (0U)
  124. #define EXIP_STA_KBERR_GET(x) (((uint32_t)(x) & EXIP_STA_KBERR_MASK) >> EXIP_STA_KBERR_SHIFT)
  125. /* Bitfield definition for register of struct array RGN: KEY0 */
  126. /*
  127. * KEY (RW)
  128. *
  129. * AES Key
  130. * The key is typically loaded as the corresponding key blob is unwrapped; alternatively, if enabled, it can be
  131. * written using the APB bus. The four consecutive little-endian memory-mapped registers
  132. * provide 128 bits of key storage.
  133. * Word0: KEY[31:0][A03, A02, A01, A00]
  134. * Word1: KEY[31:0][A07, A06, A05, A04]
  135. * Word2: KEY[31:0][A11, A10, A09, A08]
  136. * Word3: KEY[31:0][A15, A14, A13, A12]
  137. */
  138. #define EXIP_RGN_KEY0_KEY_MASK (0xFFFFFFFFUL)
  139. #define EXIP_RGN_KEY0_KEY_SHIFT (0U)
  140. #define EXIP_RGN_KEY0_KEY_SET(x) (((uint32_t)(x) << EXIP_RGN_KEY0_KEY_SHIFT) & EXIP_RGN_KEY0_KEY_MASK)
  141. #define EXIP_RGN_KEY0_KEY_GET(x) (((uint32_t)(x) & EXIP_RGN_KEY0_KEY_MASK) >> EXIP_RGN_KEY0_KEY_SHIFT)
  142. /* Bitfield definition for register of struct array RGN: KEY1 */
  143. /*
  144. * KEY (RW)
  145. *
  146. * AES Key
  147. * The key is typically loaded as the corresponding key blob is unwrapped; alternatively, if enabled, it can be
  148. * written using the APB bus. The four consecutive little-endian memory-mapped registers
  149. * provide 128 bits of key storage.
  150. * Word0: KEY[31:0][A03, A02, A01, A00]
  151. * Word1: KEY[31:0][A07, A06, A05, A04]
  152. * Word2: KEY[31:0][A11, A10, A09, A08]
  153. * Word3: KEY[31:0][A15, A14, A13, A12]
  154. */
  155. #define EXIP_RGN_KEY1_KEY_MASK (0xFFFFFFFFUL)
  156. #define EXIP_RGN_KEY1_KEY_SHIFT (0U)
  157. #define EXIP_RGN_KEY1_KEY_SET(x) (((uint32_t)(x) << EXIP_RGN_KEY1_KEY_SHIFT) & EXIP_RGN_KEY1_KEY_MASK)
  158. #define EXIP_RGN_KEY1_KEY_GET(x) (((uint32_t)(x) & EXIP_RGN_KEY1_KEY_MASK) >> EXIP_RGN_KEY1_KEY_SHIFT)
  159. /* Bitfield definition for register of struct array RGN: KEY2 */
  160. /*
  161. * KEY (RW)
  162. *
  163. * AES Key
  164. * The key is typically loaded as the corresponding key blob is unwrapped; alternatively, if enabled, it can be
  165. * written using the APB bus. The four consecutive little-endian memory-mapped registers
  166. * provide 128 bits of key storage.
  167. * Word0: KEY[31:0][A03, A02, A01, A00]
  168. * Word1: KEY[31:0][A07, A06, A05, A04]
  169. * Word2: KEY[31:0][A11, A10, A09, A08]
  170. * Word3: KEY[31:0][A15, A14, A13, A12]
  171. */
  172. #define EXIP_RGN_KEY2_KEY_MASK (0xFFFFFFFFUL)
  173. #define EXIP_RGN_KEY2_KEY_SHIFT (0U)
  174. #define EXIP_RGN_KEY2_KEY_SET(x) (((uint32_t)(x) << EXIP_RGN_KEY2_KEY_SHIFT) & EXIP_RGN_KEY2_KEY_MASK)
  175. #define EXIP_RGN_KEY2_KEY_GET(x) (((uint32_t)(x) & EXIP_RGN_KEY2_KEY_MASK) >> EXIP_RGN_KEY2_KEY_SHIFT)
  176. /* Bitfield definition for register of struct array RGN: KEY3 */
  177. /*
  178. * KEY (RW)
  179. *
  180. * AES Key
  181. * The key is typically loaded as the corresponding key blob is unwrapped; alternatively, if enabled, it can be
  182. * written using the APB bus. The four consecutive little-endian memory-mapped registers
  183. * provide 128 bits of key storage.
  184. * Word0: KEY[31:0][A03, A02, A01, A00]
  185. * Word1: KEY[31:0][A07, A06, A05, A04]
  186. * Word2: KEY[31:0][A11, A10, A09, A08]
  187. * Word3: KEY[31:0][A15, A14, A13, A12]
  188. */
  189. #define EXIP_RGN_KEY3_KEY_MASK (0xFFFFFFFFUL)
  190. #define EXIP_RGN_KEY3_KEY_SHIFT (0U)
  191. #define EXIP_RGN_KEY3_KEY_SET(x) (((uint32_t)(x) << EXIP_RGN_KEY3_KEY_SHIFT) & EXIP_RGN_KEY3_KEY_MASK)
  192. #define EXIP_RGN_KEY3_KEY_GET(x) (((uint32_t)(x) & EXIP_RGN_KEY3_KEY_MASK) >> EXIP_RGN_KEY3_KEY_SHIFT)
  193. /* Bitfield definition for register of struct array RGN: CTR0 */
  194. /*
  195. * CTR (RW)
  196. *
  197. * AES Counter
  198. * The upper 64 bits of the counter are typically loaded as the corresponding key blob is unwrapped;
  199. * alternatively, if enabled, it can be written using the slave peripheral bus. The two consecutive memorymapped registers directly provide the upper 64 bits of counter storage.
  200. * Word0: CTR[31:0][C3, C2, C1, C0]
  201. * Word1: CTR[31:0][C7, C6, C5, C4]
  202. * The third 32-bit portion of the CTR is formed by exclusive-or’ing the upper 64 bits of the counter as two
  203. * 32-bit values, while the least-significant portion of the counter is the 32-bit 0-modulo-16 byte system
  204. * address of the external flash memory.
  205. * CTR[C0...C15] = {CTR[C0...C7], CTR[C0...C3] ^ CTR[C4...C7], systemAddress[31–4], 0h}
  206. */
  207. #define EXIP_RGN_CTR0_CTR_MASK (0xFFFFFFFFUL)
  208. #define EXIP_RGN_CTR0_CTR_SHIFT (0U)
  209. #define EXIP_RGN_CTR0_CTR_SET(x) (((uint32_t)(x) << EXIP_RGN_CTR0_CTR_SHIFT) & EXIP_RGN_CTR0_CTR_MASK)
  210. #define EXIP_RGN_CTR0_CTR_GET(x) (((uint32_t)(x) & EXIP_RGN_CTR0_CTR_MASK) >> EXIP_RGN_CTR0_CTR_SHIFT)
  211. /* Bitfield definition for register of struct array RGN: CTR1 */
  212. /*
  213. * CTR (RW)
  214. *
  215. * AES Counter
  216. * The upper 64 bits of the counter are typically loaded as the corresponding key blob is unwrapped;
  217. * alternatively, if enabled, it can be written using the slave peripheral bus. The two consecutive memorymapped registers directly provide the upper 64 bits of counter storage.
  218. * Word0: CTR[31:0][C3, C2, C1, C0]
  219. * Word1: CTR[31:0][C7, C6, C5, C4]
  220. * The third 32-bit portion of the CTR is formed by exclusive-or’ing the upper 64 bits of the counter as two
  221. * 32-bit values, while the least-significant portion of the counter is the 32-bit 0-modulo-16 byte system
  222. * address of the external flash memory.
  223. * CTR[C0...C15] = {CTR[C0...C7], CTR[C0...C3] ^ CTR[C4...C7], systemAddress[31–4], 0h}
  224. */
  225. #define EXIP_RGN_CTR1_CTR_MASK (0xFFFFFFFFUL)
  226. #define EXIP_RGN_CTR1_CTR_SHIFT (0U)
  227. #define EXIP_RGN_CTR1_CTR_SET(x) (((uint32_t)(x) << EXIP_RGN_CTR1_CTR_SHIFT) & EXIP_RGN_CTR1_CTR_MASK)
  228. #define EXIP_RGN_CTR1_CTR_GET(x) (((uint32_t)(x) & EXIP_RGN_CTR1_CTR_MASK) >> EXIP_RGN_CTR1_CTR_SHIFT)
  229. /* Bitfield definition for register of struct array RGN: RGN_SA */
  230. /*
  231. * START (RW)
  232. *
  233. * Start Address
  234. * This field defines the most significant bits of the 0-modulo-1024 byte start address of the memory region
  235. * for context n.
  236. */
  237. #define EXIP_RGN_RGN_SA_START_MASK (0xFFFFFC00UL)
  238. #define EXIP_RGN_RGN_SA_START_SHIFT (10U)
  239. #define EXIP_RGN_RGN_SA_START_SET(x) (((uint32_t)(x) << EXIP_RGN_RGN_SA_START_SHIFT) & EXIP_RGN_RGN_SA_START_MASK)
  240. #define EXIP_RGN_RGN_SA_START_GET(x) (((uint32_t)(x) & EXIP_RGN_RGN_SA_START_MASK) >> EXIP_RGN_RGN_SA_START_SHIFT)
  241. /* Bitfield definition for register of struct array RGN: RGN_EA */
  242. /*
  243. * END (RW)
  244. *
  245. * End Address
  246. * This field defines the most significant bits of the 1023-modulo-1024 byte end address of the memory
  247. * region for context n.
  248. */
  249. #define EXIP_RGN_RGN_EA_END_MASK (0xFFFFFC00UL)
  250. #define EXIP_RGN_RGN_EA_END_SHIFT (10U)
  251. #define EXIP_RGN_RGN_EA_END_SET(x) (((uint32_t)(x) << EXIP_RGN_RGN_EA_END_SHIFT) & EXIP_RGN_RGN_EA_END_MASK)
  252. #define EXIP_RGN_RGN_EA_END_GET(x) (((uint32_t)(x) & EXIP_RGN_RGN_EA_END_MASK) >> EXIP_RGN_RGN_EA_END_SHIFT)
  253. /*
  254. * DECEN (RW)
  255. *
  256. * AES Decryption Enable.
  257. * For accesses hitting in a valid context, this bit indicates if the fetched data is to be decrypted or simply
  258. * bypassed.
  259. * "0" - Bypass the fetched data.
  260. * "1" - Perform the CTR-AES128 mode decryption on the fetched data
  261. */
  262. #define EXIP_RGN_RGN_EA_DECEN_MASK (0x2U)
  263. #define EXIP_RGN_RGN_EA_DECEN_SHIFT (1U)
  264. #define EXIP_RGN_RGN_EA_DECEN_SET(x) (((uint32_t)(x) << EXIP_RGN_RGN_EA_DECEN_SHIFT) & EXIP_RGN_RGN_EA_DECEN_MASK)
  265. #define EXIP_RGN_RGN_EA_DECEN_GET(x) (((uint32_t)(x) & EXIP_RGN_RGN_EA_DECEN_MASK) >> EXIP_RGN_RGN_EA_DECEN_SHIFT)
  266. /*
  267. * VALID (RW)
  268. *
  269. * Valid
  270. * This field signals if the context is valid or not.
  271. * "0" - Context is invalid.
  272. * "1" - Context is valid.
  273. */
  274. #define EXIP_RGN_RGN_EA_VALID_MASK (0x1U)
  275. #define EXIP_RGN_RGN_EA_VALID_SHIFT (0U)
  276. #define EXIP_RGN_RGN_EA_VALID_SET(x) (((uint32_t)(x) << EXIP_RGN_RGN_EA_VALID_SHIFT) & EXIP_RGN_RGN_EA_VALID_MASK)
  277. #define EXIP_RGN_RGN_EA_VALID_GET(x) (((uint32_t)(x) & EXIP_RGN_RGN_EA_VALID_MASK) >> EXIP_RGN_RGN_EA_VALID_SHIFT)
  278. /* RGN register group index macro definition */
  279. #define EXIP_RGN_0 (0UL)
  280. #define EXIP_RGN_1 (1UL)
  281. #define EXIP_RGN_2 (2UL)
  282. #define EXIP_RGN_3 (3UL)
  283. #endif /* HPM_EXIP_H */