se_private.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. /*
  2. * Copyright (c) 2017-2020, ARM Limited and Contributors. All rights reserved.
  3. * Copyright (c) 2017-2020, NVIDIA CORPORATION. All rights reserved.
  4. *
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. #ifndef SE_PRIVATE_H
  8. #define SE_PRIVATE_H
  9. #include <stdbool.h>
  10. #include <security_engine.h>
  11. /*
  12. * PMC registers
  13. */
  14. /* SC7 context save scratch register for T210 */
  15. #define PMC_SCRATCH43_REG_OFFSET U(0x22C)
  16. /* Secure scratch registers */
  17. #define PMC_SECURE_SCRATCH4_OFFSET 0xC0U
  18. #define PMC_SECURE_SCRATCH5_OFFSET 0xC4U
  19. #define PMC_SECURE_SCRATCH6_OFFSET 0x224U
  20. #define PMC_SECURE_SCRATCH7_OFFSET 0x228U
  21. #define PMC_SECURE_SCRATCH116_OFFSET 0xB28U
  22. #define PMC_SECURE_SCRATCH117_OFFSET 0xB2CU
  23. #define PMC_SECURE_SCRATCH120_OFFSET 0xB38U
  24. #define PMC_SECURE_SCRATCH121_OFFSET 0xB3CU
  25. #define PMC_SECURE_SCRATCH122_OFFSET 0xB40U
  26. #define PMC_SECURE_SCRATCH123_OFFSET 0xB44U
  27. /*
  28. * AHB arbitration memory write queue
  29. */
  30. #define ARAHB_MEM_WRQUE_MST_ID_OFFSET 0xFCU
  31. #define ARAHB_MST_ID_SE2_MASK (0x1U << 13)
  32. #define ARAHB_MST_ID_SE_MASK (0x1U << 14)
  33. /**
  34. * SE registers
  35. */
  36. #define TEGRA_SE_AES_KEYSLOT_COUNT 16
  37. #define SE_MAX_LAST_BLOCK_SIZE 0xFFFFF
  38. /* SE Status register */
  39. #define SE_STATUS_OFFSET 0x800U
  40. #define SE_STATUS_SHIFT 0
  41. #define SE_STATUS_IDLE \
  42. ((0U) << SE_STATUS_SHIFT)
  43. #define SE_STATUS_BUSY \
  44. ((1U) << SE_STATUS_SHIFT)
  45. #define SE_STATUS(x) \
  46. ((x) & ((0x3U) << SE_STATUS_SHIFT))
  47. #define SE_MEM_INTERFACE_SHIFT 2
  48. #define SE_MEM_INTERFACE_IDLE 0
  49. #define SE_MEM_INTERFACE_BUSY 1
  50. #define SE_MEM_INTERFACE(x) ((x) << SE_STATUS_SHIFT)
  51. /* SE register definitions */
  52. #define SE_SECURITY_REG_OFFSET 0x0
  53. #define SE_SECURITY_TZ_LOCK_SOFT_SHIFT 5
  54. #define SE_SECURE 0x0
  55. #define SE_SECURITY_TZ_LOCK_SOFT(x) ((x) << SE_SECURITY_TZ_LOCK_SOFT_SHIFT)
  56. #define SE_SEC_ENG_DIS_SHIFT 1
  57. #define SE_DISABLE_FALSE 0
  58. #define SE_DISABLE_TRUE 1
  59. #define SE_SEC_ENG_DISABLE(x)((x) << SE_SEC_ENG_DIS_SHIFT)
  60. /* SE config register */
  61. #define SE_CONFIG_REG_OFFSET 0x14U
  62. #define SE_CONFIG_ENC_ALG_SHIFT 12
  63. #define SE_CONFIG_ENC_ALG_AES_ENC \
  64. ((1U) << SE_CONFIG_ENC_ALG_SHIFT)
  65. #define SE_CONFIG_ENC_ALG_RNG \
  66. ((2U) << SE_CONFIG_ENC_ALG_SHIFT)
  67. #define SE_CONFIG_ENC_ALG_SHA \
  68. ((3U) << SE_CONFIG_ENC_ALG_SHIFT)
  69. #define SE_CONFIG_ENC_ALG_RSA \
  70. ((4U) << SE_CONFIG_ENC_ALG_SHIFT)
  71. #define SE_CONFIG_ENC_ALG_NOP \
  72. ((0U) << SE_CONFIG_ENC_ALG_SHIFT)
  73. #define SE_CONFIG_ENC_ALG(x) \
  74. ((x) & ((0xFU) << SE_CONFIG_ENC_ALG_SHIFT))
  75. #define SE_CONFIG_DEC_ALG_SHIFT 8
  76. #define SE_CONFIG_DEC_ALG_AES \
  77. ((1U) << SE_CONFIG_DEC_ALG_SHIFT)
  78. #define SE_CONFIG_DEC_ALG_NOP \
  79. ((0U) << SE_CONFIG_DEC_ALG_SHIFT)
  80. #define SE_CONFIG_DEC_ALG(x) \
  81. ((x) & ((0xFU) << SE_CONFIG_DEC_ALG_SHIFT))
  82. #define SE_CONFIG_DST_SHIFT 2
  83. #define SE_CONFIG_DST_MEMORY \
  84. ((0U) << SE_CONFIG_DST_SHIFT)
  85. #define SE_CONFIG_DST_HASHREG \
  86. ((1U) << SE_CONFIG_DST_SHIFT)
  87. #define SE_CONFIG_DST_KEYTAB \
  88. ((2U) << SE_CONFIG_DST_SHIFT)
  89. #define SE_CONFIG_DST_SRK \
  90. ((3U) << SE_CONFIG_DST_SHIFT)
  91. #define SE_CONFIG_DST_RSAREG \
  92. ((4U) << SE_CONFIG_DST_SHIFT)
  93. #define SE_CONFIG_DST(x) \
  94. ((x) & ((0x7U) << SE_CONFIG_DST_SHIFT))
  95. #define SE_CONFIG_ENC_MODE_SHIFT 24
  96. #define SE_CONFIG_ENC_MODE_KEY128 \
  97. ((0UL) << SE_CONFIG_ENC_MODE_SHIFT)
  98. #define SE_CONFIG_ENC_MODE_KEY192 \
  99. ((1UL) << SE_CONFIG_ENC_MODE_SHIFT)
  100. #define SE_CONFIG_ENC_MODE_KEY256 \
  101. ((2UL) << SE_CONFIG_ENC_MODE_SHIFT)
  102. #define SE_CONFIG_ENC_MODE_SHA1 \
  103. ((0UL) << SE_CONFIG_ENC_MODE_SHIFT)
  104. #define SE_CONFIG_ENC_MODE_SHA224 \
  105. ((4UL) << SE_CONFIG_ENC_MODE_SHIFT)
  106. #define SE_CONFIG_ENC_MODE_SHA256 \
  107. ((5UL) << SE_CONFIG_ENC_MODE_SHIFT)
  108. #define SE_CONFIG_ENC_MODE_SHA384 \
  109. ((6UL) << SE_CONFIG_ENC_MODE_SHIFT)
  110. #define SE_CONFIG_ENC_MODE_SHA512 \
  111. ((7UL) << SE_CONFIG_ENC_MODE_SHIFT)
  112. #define SE_CONFIG_ENC_MODE(x)\
  113. ((x) & ((0xFFUL) << SE_CONFIG_ENC_MODE_SHIFT))
  114. #define SE_CONFIG_DEC_MODE_SHIFT 16
  115. #define SE_CONFIG_DEC_MODE_KEY128 \
  116. ((0UL) << SE_CONFIG_DEC_MODE_SHIFT)
  117. #define SE_CONFIG_DEC_MODE_KEY192 \
  118. ((1UL) << SE_CONFIG_DEC_MODE_SHIFT)
  119. #define SE_CONFIG_DEC_MODE_KEY256 \
  120. ((2UL) << SE_CONFIG_DEC_MODE_SHIFT)
  121. #define SE_CONFIG_DEC_MODE_SHA1 \
  122. ((0UL) << SE_CONFIG_DEC_MODE_SHIFT)
  123. #define SE_CONFIG_DEC_MODE_SHA224 \
  124. ((4UL) << SE_CONFIG_DEC_MODE_SHIFT)
  125. #define SE_CONFIG_DEC_MODE_SHA256 \
  126. ((5UL) << SE_CONFIG_DEC_MODE_SHIFT)
  127. #define SE_CONFIG_DEC_MODE_SHA384 \
  128. ((6UL) << SE_CONFIG_DEC_MODE_SHIFT)
  129. #define SE_CONFIG_DEC_MODE_SHA512 \
  130. ((7UL) << SE_CONFIG_DEC_MODE_SHIFT)
  131. #define SE_CONFIG_DEC_MODE(x)\
  132. ((x) & ((0xFFUL) << SE_CONFIG_DEC_MODE_SHIFT))
  133. /* DRBG random number generator config */
  134. #define SE_RNG_CONFIG_REG_OFFSET 0x340
  135. #define DRBG_MODE_SHIFT 0
  136. #define DRBG_MODE_NORMAL \
  137. ((0U) << DRBG_MODE_SHIFT)
  138. #define DRBG_MODE_FORCE_INSTANTION \
  139. ((1U) << DRBG_MODE_SHIFT)
  140. #define DRBG_MODE_FORCE_RESEED \
  141. ((2U) << DRBG_MODE_SHIFT)
  142. #define SE_RNG_CONFIG_MODE(x) \
  143. ((x) & ((0x3U) << DRBG_MODE_SHIFT))
  144. #define DRBG_SRC_SHIFT 2
  145. #define DRBG_SRC_NONE \
  146. ((0U) << DRBG_SRC_SHIFT)
  147. #define DRBG_SRC_ENTROPY \
  148. ((1U) << DRBG_SRC_SHIFT)
  149. #define DRBG_SRC_LFSR \
  150. ((2U) << DRBG_SRC_SHIFT)
  151. #define SE_RNG_SRC_CONFIG_MODE(x) \
  152. ((x) & ((0x3U) << DRBG_SRC_SHIFT))
  153. /* DRBG random number generator entropy config */
  154. #define SE_RNG_SRC_CONFIG_REG_OFFSET 0x344U
  155. #define DRBG_RO_ENT_SRC_SHIFT 1
  156. #define DRBG_RO_ENT_SRC_ENABLE \
  157. ((1U) << DRBG_RO_ENT_SRC_SHIFT)
  158. #define DRBG_RO_ENT_SRC_DISABLE \
  159. ((0U) << DRBG_RO_ENT_SRC_SHIFT)
  160. #define SE_RNG_SRC_CONFIG_RO_ENT_SRC(x) \
  161. ((x) & ((0x1U) << DRBG_RO_ENT_SRC_SHIFT))
  162. #define DRBG_RO_ENT_SRC_LOCK_SHIFT 0
  163. #define DRBG_RO_ENT_SRC_LOCK_ENABLE \
  164. ((1U) << DRBG_RO_ENT_SRC_LOCK_SHIFT)
  165. #define DRBG_RO_ENT_SRC_LOCK_DISABLE \
  166. ((0U) << DRBG_RO_ENT_SRC_LOCK_SHIFT)
  167. #define SE_RNG_SRC_CONFIG_RO_ENT_SRC_LOCK(x) \
  168. ((x) & ((0x1U) << DRBG_RO_ENT_SRC_LOCK_SHIFT))
  169. #define DRBG_RO_ENT_IGNORE_MEM_SHIFT 12
  170. #define DRBG_RO_ENT_IGNORE_MEM_ENABLE \
  171. ((1U) << DRBG_RO_ENT_IGNORE_MEM_SHIFT)
  172. #define DRBG_RO_ENT_IGNORE_MEM_DISABLE \
  173. ((0U) << DRBG_RO_ENT_IGNORE_MEM_SHIFT)
  174. #define SE_RNG_SRC_CONFIG_RO_ENT_IGNORE_MEM(x) \
  175. ((x) & ((0x1U) << DRBG_RO_ENT_IGNORE_MEM_SHIFT))
  176. #define SE_RNG_RESEED_INTERVAL_REG_OFFSET 0x348
  177. /* SE CRYPTO */
  178. #define SE_CRYPTO_REG_OFFSET 0x304
  179. #define SE_CRYPTO_HASH_SHIFT 0
  180. #define SE_CRYPTO_HASH_DISABLE \
  181. ((0U) << SE_CRYPTO_HASH_SHIFT)
  182. #define SE_CRYPTO_HASH_ENABLE \
  183. ((1U) << SE_CRYPTO_HASH_SHIFT)
  184. #define SE_CRYPTO_XOR_POS_SHIFT 1
  185. #define SE_CRYPTO_XOR_BYPASS \
  186. ((0U) << SE_CRYPTO_XOR_POS_SHIFT)
  187. #define SE_CRYPTO_XOR_TOP \
  188. ((2U) << SE_CRYPTO_XOR_POS_SHIFT)
  189. #define SE_CRYPTO_XOR_BOTTOM \
  190. ((3U) << SE_CRYPTO_XOR_POS_SHIFT)
  191. #define SE_CRYPTO_INPUT_SEL_SHIFT 3
  192. #define SE_CRYPTO_INPUT_AHB \
  193. ((0U) << SE_CRYPTO_INPUT_SEL_SHIFT)
  194. #define SE_CRYPTO_INPUT_RANDOM \
  195. ((1U) << SE_CRYPTO_INPUT_SEL_SHIFT)
  196. #define SE_CRYPTO_INPUT_AESOUT \
  197. ((2U) << SE_CRYPTO_INPUT_SEL_SHIFT)
  198. #define SE_CRYPTO_INPUT_LNR_CTR \
  199. ((3U) << SE_CRYPTO_INPUT_SEL_SHIFT)
  200. #define SE_CRYPTO_VCTRAM_SEL_SHIFT 5
  201. #define SE_CRYPTO_VCTRAM_AHB \
  202. ((0U) << SE_CRYPTO_VCTRAM_SEL_SHIFT)
  203. #define SE_CRYPTO_VCTRAM_AESOUT \
  204. ((2U) << SE_CRYPTO_VCTRAM_SEL_SHIFT)
  205. #define SE_CRYPTO_VCTRAM_PREVAHB \
  206. ((3U) << SE_CRYPTO_VCTRAM_SEL_SHIFT)
  207. #define SE_CRYPTO_IV_SEL_SHIFT 7
  208. #define SE_CRYPTO_IV_ORIGINAL \
  209. ((0U) << SE_CRYPTO_IV_SEL_SHIFT)
  210. #define SE_CRYPTO_IV_UPDATED \
  211. ((1U) << SE_CRYPTO_IV_SEL_SHIFT)
  212. #define SE_CRYPTO_CORE_SEL_SHIFT 8
  213. #define SE_CRYPTO_CORE_DECRYPT \
  214. ((0U) << SE_CRYPTO_CORE_SEL_SHIFT)
  215. #define SE_CRYPTO_CORE_ENCRYPT \
  216. ((1U) << SE_CRYPTO_CORE_SEL_SHIFT)
  217. #define SE_CRYPTO_KEY_INDEX_SHIFT 24
  218. #define SE_CRYPTO_KEY_INDEX(x) (x << SE_CRYPTO_KEY_INDEX_SHIFT)
  219. #define SE_CRYPTO_MEMIF_AHB \
  220. ((0U) << SE_CRYPTO_MEMIF_SHIFT)
  221. #define SE_CRYPTO_MEMIF_MCCIF \
  222. ((1U) << SE_CRYPTO_MEMIF_SHIFT)
  223. #define SE_CRYPTO_MEMIF_SHIFT 31
  224. /* KEY TABLE */
  225. #define SE_KEYTABLE_REG_OFFSET 0x31C
  226. /* KEYIV PKT - key slot */
  227. #define SE_KEYTABLE_SLOT_SHIFT 4
  228. #define SE_KEYTABLE_SLOT(x) (x << SE_KEYTABLE_SLOT_SHIFT)
  229. /* KEYIV PKT - KEYIV select */
  230. #define SE_KEYIV_PKT_KEYIV_SEL_SHIFT 3
  231. #define SE_CRYPTO_KEYIV_KEY \
  232. ((0U) << SE_KEYIV_PKT_KEYIV_SEL_SHIFT)
  233. #define SE_CRYPTO_KEYIV_IVS \
  234. ((1U) << SE_KEYIV_PKT_KEYIV_SEL_SHIFT)
  235. /* KEYIV PKT - IV select */
  236. #define SE_KEYIV_PKT_IV_SEL_SHIFT 2
  237. #define SE_CRYPTO_KEYIV_IVS_OIV \
  238. ((0U) << SE_KEYIV_PKT_IV_SEL_SHIFT)
  239. #define SE_CRYPTO_KEYIV_IVS_UIV \
  240. ((1U) << SE_KEYIV_PKT_IV_SEL_SHIFT)
  241. /* KEYIV PKT - key word */
  242. #define SE_KEYIV_PKT_KEY_WORD_SHIFT 0
  243. #define SE_KEYIV_PKT_KEY_WORD(x) \
  244. ((x) << SE_KEYIV_PKT_KEY_WORD_SHIFT)
  245. /* KEYIV PKT - iv word */
  246. #define SE_KEYIV_PKT_IV_WORD_SHIFT 0
  247. #define SE_KEYIV_PKT_IV_WORD(x) \
  248. ((x) << SE_KEYIV_PKT_IV_WORD_SHIFT)
  249. /* SE OPERATION */
  250. #define SE_OPERATION_REG_OFFSET 0x8U
  251. #define SE_OPERATION_SHIFT 0
  252. #define SE_OP_ABORT \
  253. ((0x0U) << SE_OPERATION_SHIFT)
  254. #define SE_OP_START \
  255. ((0x1U) << SE_OPERATION_SHIFT)
  256. #define SE_OP_RESTART \
  257. ((0x2U) << SE_OPERATION_SHIFT)
  258. #define SE_OP_CTX_SAVE \
  259. ((0x3U) << SE_OPERATION_SHIFT)
  260. #define SE_OP_RESTART_IN \
  261. ((0x4U) << SE_OPERATION_SHIFT)
  262. #define SE_OPERATION(x) \
  263. ((x) & ((0x7U) << SE_OPERATION_SHIFT))
  264. /* SE CONTEXT */
  265. #define SE_CTX_SAVE_CONFIG_REG_OFFSET 0x70
  266. #define SE_CTX_SAVE_WORD_QUAD_SHIFT 0
  267. #define SE_CTX_SAVE_WORD_QUAD(x) \
  268. (x << SE_CTX_SAVE_WORD_QUAD_SHIFT)
  269. #define SE_CTX_SAVE_WORD_QUAD_KEYS_0_3 \
  270. ((0U) << SE_CTX_SAVE_WORD_QUAD_SHIFT)
  271. #define SE_CTX_SAVE_WORD_QUAD_KEYS_4_7 \
  272. ((1U) << SE_CTX_SAVE_WORD_QUAD_SHIFT)
  273. #define SE_CTX_SAVE_WORD_QUAD_ORIG_IV \
  274. ((2U) << SE_CTX_SAVE_WORD_QUAD_SHIFT)
  275. #define SE_CTX_SAVE_WORD_QUAD_UPD_IV \
  276. ((3U) << SE_CTX_SAVE_WORD_QUAD_SHIFT)
  277. #define SE_CTX_SAVE_KEY_INDEX_SHIFT 8
  278. #define SE_CTX_SAVE_KEY_INDEX(x) (x << SE_CTX_SAVE_KEY_INDEX_SHIFT)
  279. #define SE_CTX_SAVE_STICKY_WORD_QUAD_SHIFT 24
  280. #define SE_CTX_SAVE_STICKY_WORD_QUAD_STICKY_0_3 \
  281. ((0U) << SE_CTX_SAVE_STICKY_WORD_QUAD_SHIFT)
  282. #define SE_CTX_SAVE_STICKY_WORD_QUAD_STICKY_4_7 \
  283. ((1U) << SE_CTX_SAVE_STICKY_WORD_QUAD_SHIFT)
  284. #define SE_CTX_SAVE_STICKY_WORD_QUAD(x) \
  285. (x << SE_CTX_SAVE_STICKY_WORD_QUAD_SHIFT)
  286. #define SE_CTX_SAVE_SRC_SHIFT 29
  287. #define SE_CTX_SAVE_SRC_STICKY_BITS \
  288. ((0U) << SE_CTX_SAVE_SRC_SHIFT)
  289. #define SE_CTX_SAVE_SRC_RSA_KEYTABLE \
  290. ((1U) << SE_CTX_SAVE_SRC_SHIFT)
  291. #define SE_CTX_SAVE_SRC_AES_KEYTABLE \
  292. ((2U) << SE_CTX_SAVE_SRC_SHIFT)
  293. #define SE_CTX_SAVE_SRC_PKA1_STICKY_BITS \
  294. ((3U) << SE_CTX_SAVE_SRC_SHIFT)
  295. #define SE_CTX_SAVE_SRC_MEM \
  296. ((4U) << SE_CTX_SAVE_SRC_SHIFT)
  297. #define SE_CTX_SAVE_SRC_SRK \
  298. ((6U) << SE_CTX_SAVE_SRC_SHIFT)
  299. #define SE_CTX_SAVE_SRC_PKA1_KEYTABLE \
  300. ((7U) << SE_CTX_SAVE_SRC_SHIFT)
  301. #define SE_CTX_STICKY_WORD_QUAD_SHIFT 24
  302. #define SE_CTX_STICKY_WORD_QUAD_WORDS_0_3 \
  303. ((0U) << SE_CTX_STICKY_WORD_QUAD_SHIFT)
  304. #define SE_CTX_STICKY_WORD_QUAD_WORDS_4_7 \
  305. ((1U) << SE_CTX_STICKY_WORD_QUAD_SHIFT)
  306. #define SE_CTX_STICKY_WORD_QUAD(x) (x << SE_CTX_STICKY_WORD_QUAD_SHIFT)
  307. #define SE_CTX_SAVE_RSA_KEY_INDEX_SHIFT 16
  308. #define SE_CTX_SAVE_RSA_KEY_INDEX(x) \
  309. (x << SE_CTX_SAVE_RSA_KEY_INDEX_SHIFT)
  310. #define SE_CTX_RSA_WORD_QUAD_SHIFT 12
  311. #define SE_CTX_RSA_WORD_QUAD(x) \
  312. (x << SE_CTX_RSA_WORD_QUAD_SHIFT)
  313. #define SE_CTX_PKA1_WORD_QUAD_L_SHIFT 0
  314. #define SE_CTX_PKA1_WORD_QUAD_L_SIZE \
  315. ((true ? 4:0) - \
  316. (false ? 4:0) + 1)
  317. #define SE_CTX_PKA1_WORD_QUAD_L(x)\
  318. (((x) << SE_CTX_PKA1_WORD_QUAD_L_SHIFT) & 0x1f)
  319. #define SE_CTX_PKA1_WORD_QUAD_H_SHIFT 12
  320. #define SE_CTX_PKA1_WORD_QUAD_H(x)\
  321. ((((x) >> SE_CTX_PKA1_WORD_QUAD_L_SIZE) & 0xf) \
  322. << SE_CTX_PKA1_WORD_QUAD_H_SHIFT)
  323. #define SE_RSA_KEY_INDEX_SLOT0_EXP 0
  324. #define SE_RSA_KEY_INDEX_SLOT0_MOD 1
  325. #define SE_RSA_KEY_INDEX_SLOT1_EXP 2
  326. #define SE_RSA_KEY_INDEX_SLOT1_MOD 3
  327. /* SE_CTX_SAVE_AUTO */
  328. #define SE_CTX_SAVE_AUTO_REG_OFFSET 0x74U
  329. /* Enable */
  330. #define SE_CTX_SAVE_AUTO_ENABLE_SHIFT 0
  331. #define SE_CTX_SAVE_AUTO_DIS \
  332. ((0U) << SE_CTX_SAVE_AUTO_ENABLE_SHIFT)
  333. #define SE_CTX_SAVE_AUTO_EN \
  334. ((1U) << SE_CTX_SAVE_AUTO_ENABLE_SHIFT)
  335. #define SE_CTX_SAVE_AUTO_ENABLE(x) \
  336. ((x) & ((0x1U) << SE_CTX_SAVE_AUTO_ENABLE_SHIFT))
  337. /* Lock */
  338. #define SE_CTX_SAVE_AUTO_LOCK_SHIFT 8
  339. #define SE_CTX_SAVE_AUTO_LOCK_EN \
  340. ((1U) << SE_CTX_SAVE_AUTO_LOCK_SHIFT)
  341. #define SE_CTX_SAVE_AUTO_LOCK_DIS \
  342. ((0U) << SE_CTX_SAVE_AUTO_LOCK_SHIFT)
  343. #define SE_CTX_SAVE_AUTO_LOCK(x) \
  344. ((x) & ((0x1U) << SE_CTX_SAVE_AUTO_LOCK_SHIFT))
  345. /* Current context save number of blocks*/
  346. #define SE_CTX_SAVE_AUTO_CURR_CNT_SHIFT 16
  347. #define SE_CTX_SAVE_AUTO_CURR_CNT_MASK 0x3FFU
  348. #define SE_CTX_SAVE_GET_BLK_COUNT(x) \
  349. (((x) >> SE_CTX_SAVE_AUTO_CURR_CNT_SHIFT) & \
  350. SE_CTX_SAVE_AUTO_CURR_CNT_MASK)
  351. #define SE_CTX_SAVE_SIZE_BLOCKS_SE1 133
  352. #define SE_CTX_SAVE_SIZE_BLOCKS_SE2 646
  353. /* SE TZRAM OPERATION - only for SE1 */
  354. #define SE_TZRAM_OPERATION 0x540U
  355. #define SE_TZRAM_OP_MODE_SHIFT 1
  356. #define SE_TZRAM_OP_COMMAND_INIT 1
  357. #define SE_TZRAM_OP_COMMAND_SHIFT 0
  358. #define SE_TZRAM_OP_MODE_SAVE \
  359. ((0U) << SE_TZRAM_OP_MODE_SHIFT)
  360. #define SE_TZRAM_OP_MODE_RESTORE \
  361. ((1U) << SE_TZRAM_OP_MODE_SHIFT)
  362. #define SE_TZRAM_OP_MODE(x) \
  363. ((x) & ((0x1U) << SE_TZRAM_OP_MODE_SHIFT))
  364. #define SE_TZRAM_OP_BUSY_SHIFT 2
  365. #define SE_TZRAM_OP_BUSY_OFF \
  366. ((0U) << SE_TZRAM_OP_BUSY_SHIFT)
  367. #define SE_TZRAM_OP_BUSY_ON \
  368. ((1U) << SE_TZRAM_OP_BUSY_SHIFT)
  369. #define SE_TZRAM_OP_BUSY(x) \
  370. ((x) & ((0x1U) << SE_TZRAM_OP_BUSY_SHIFT))
  371. #define SE_TZRAM_OP_REQ_SHIFT 0
  372. #define SE_TZRAM_OP_REQ_IDLE \
  373. ((0U) << SE_TZRAM_OP_REQ_SHIFT)
  374. #define SE_TZRAM_OP_REQ_INIT \
  375. ((1U) << SE_TZRAM_OP_REQ_SHIFT)
  376. #define SE_TZRAM_OP_REQ(x) \
  377. ((x) & ((0x1U) << SE_TZRAM_OP_REQ_SHIFT))
  378. /* SE Interrupt */
  379. #define SE_INT_ENABLE_REG_OFFSET U(0xC)
  380. #define SE_INT_STATUS_REG_OFFSET 0x10U
  381. #define SE_INT_OP_DONE_SHIFT 4
  382. #define SE_INT_OP_DONE_CLEAR \
  383. ((0U) << SE_INT_OP_DONE_SHIFT)
  384. #define SE_INT_OP_DONE_ACTIVE \
  385. ((1U) << SE_INT_OP_DONE_SHIFT)
  386. #define SE_INT_OP_DONE(x) \
  387. ((x) & ((0x1U) << SE_INT_OP_DONE_SHIFT))
  388. /* SE TZRAM SECURITY */
  389. #define SE_TZRAM_SEC_REG_OFFSET 0x4
  390. #define SE_TZRAM_SEC_SETTING_SHIFT 0
  391. #define SE_TZRAM_SECURE \
  392. ((0UL) << SE_TZRAM_SEC_SETTING_SHIFT)
  393. #define SE_TZRAM_NONSECURE \
  394. ((1UL) << SE_TZRAM_SEC_SETTING_SHIFT)
  395. #define SE_TZRAM_SEC_SETTING(x) \
  396. ((x) & ((0x1UL) << SE_TZRAM_SEC_SETTING_SHIFT))
  397. /* PKA1 KEY SLOTS */
  398. #define TEGRA_SE_PKA1_KEYSLOT_COUNT 4
  399. /* SE error status */
  400. #define SE_ERR_STATUS_REG_OFFSET 0x804U
  401. #define SE_CRYPTO_KEYTABLE_DST_REG_OFFSET 0x330
  402. #define SE_CRYPTO_KEYTABLE_DST_WORD_QUAD_SHIFT 0
  403. #define SE_CRYPTO_KEYTABLE_DST_WORD_QUAD(x) \
  404. (x << SE_CRYPTO_KEYTABLE_DST_WORD_QUAD_SHIFT)
  405. #define SE_KEY_INDEX_SHIFT 8
  406. #define SE_CRYPTO_KEYTABLE_DST_KEY_INDEX(x) (x << SE_KEY_INDEX_SHIFT)
  407. /* SE linked list (LL) register */
  408. #define SE_IN_LL_ADDR_REG_OFFSET 0x18U
  409. #define SE_OUT_LL_ADDR_REG_OFFSET 0x24U
  410. #define SE_BLOCK_COUNT_REG_OFFSET 0x318U
  411. /* AES data sizes */
  412. #define TEGRA_SE_KEY_256_SIZE 32
  413. #define TEGRA_SE_KEY_192_SIZE 24
  414. #define TEGRA_SE_KEY_128_SIZE 16
  415. #define TEGRA_SE_AES_BLOCK_SIZE 16
  416. #define TEGRA_SE_AES_MIN_KEY_SIZE 16
  417. #define TEGRA_SE_AES_MAX_KEY_SIZE 32
  418. #define TEGRA_SE_AES_IV_SIZE 16
  419. #define TEGRA_SE_RNG_IV_SIZE 16
  420. #define TEGRA_SE_RNG_DT_SIZE 16
  421. #define TEGRA_SE_RNG_KEY_SIZE 16
  422. #define TEGRA_SE_RNG_SEED_SIZE (TEGRA_SE_RNG_IV_SIZE + \
  423. TEGRA_SE_RNG_KEY_SIZE + \
  424. TEGRA_SE_RNG_DT_SIZE)
  425. #define TEGRA_SE_RSA512_DIGEST_SIZE 64
  426. #define TEGRA_SE_RSA1024_DIGEST_SIZE 128
  427. #define TEGRA_SE_RSA1536_DIGEST_SIZE 192
  428. #define TEGRA_SE_RSA2048_DIGEST_SIZE 256
  429. #define SE_KEY_TABLE_ACCESS_REG_OFFSET 0x284
  430. #define SE_KEY_READ_DISABLE_SHIFT 0
  431. #define SE_CTX_BUFER_SIZE 1072
  432. #define SE_CTX_DRBG_BUFER_SIZE 2112
  433. /* SE blobs size in bytes */
  434. #define SE_CTX_SAVE_RSA_KEY_LENGTH 1024
  435. #define SE_CTX_SAVE_RANDOM_DATA_SIZE 16
  436. #define SE_CTX_SAVE_STICKY_BITS_SIZE 16
  437. #define SE2_CONTEXT_SAVE_PKA1_STICKY_BITS_LENGTH 16
  438. #define SE2_CONTEXT_SAVE_PKA1_KEYS_LENGTH 8192
  439. #define SE_CTX_KNOWN_PATTERN_SIZE 16
  440. #define SE_CTX_KNOWN_PATTERN_SIZE_WORDS (SE_CTX_KNOWN_PATTERN_SIZE/4)
  441. /* SE RSA */
  442. #define TEGRA_SE_RSA_KEYSLOT_COUNT 2
  443. #define SE_RSA_KEY_SIZE_REG_OFFSET 0x404
  444. #define SE_RSA_EXP_SIZE_REG_OFFSET 0x408
  445. #define SE_RSA_MAX_EXP_BIT_SIZE 2048
  446. #define SE_RSA_MAX_EXP_SIZE32 \
  447. (SE_RSA_MAX_EXP_BIT_SIZE >> 5)
  448. #define SE_RSA_MAX_MOD_BIT_SIZE 2048
  449. #define SE_RSA_MAX_MOD_SIZE32 \
  450. (SE_RSA_MAX_MOD_BIT_SIZE >> 5)
  451. /* SE_RSA_KEYTABLE_ADDR */
  452. #define SE_RSA_KEYTABLE_ADDR 0x420
  453. #define RSA_KEY_PKT_WORD_ADDR_SHIFT 0
  454. #define RSA_KEY_PKT_EXPMOD_SEL_SHIFT \
  455. ((6U) << RSA_KEY_PKT_WORD_ADDR_SHIFT)
  456. #define RSA_KEY_MOD \
  457. ((1U) << RSA_KEY_PKT_EXPMOD_SEL_SHIFT)
  458. #define RSA_KEY_EXP \
  459. ((0U) << RSA_KEY_PKT_EXPMOD_SEL_SHIFT)
  460. #define RSA_KEY_PKT_SLOT_SHIFT 7
  461. #define RSA_KEY_SLOT_1 \
  462. ((0U) << RSA_KEY_PKT_SLOT_SHIFT)
  463. #define RSA_KEY_SLOT_2 \
  464. ((1U) << RSA_KEY_PKT_SLOT_SHIFT)
  465. #define RSA_KEY_PKT_INPUT_MODE_SHIFT 8
  466. #define RSA_KEY_REG_INPUT \
  467. ((0U) << RSA_KEY_PKT_INPUT_MODE_SHIFT)
  468. #define RSA_KEY_DMA_INPUT \
  469. ((1U) << RSA_KEY_PKT_INPUT_MODE_SHIFT)
  470. /* SE_RSA_KEYTABLE_DATA */
  471. #define SE_RSA_KEYTABLE_DATA 0x424
  472. /* SE_RSA_CONFIG register */
  473. #define SE_RSA_CONFIG 0x400
  474. #define RSA_KEY_SLOT_SHIFT 24
  475. #define RSA_KEY_SLOT(x) \
  476. ((x) << RSA_KEY_SLOT_SHIFT)
  477. /*******************************************************************************
  478. * Structure definition
  479. ******************************************************************************/
  480. /* SE context blob */
  481. #pragma pack(push, 1)
  482. typedef struct tegra_aes_key_slot {
  483. /* 0 - 7 AES key */
  484. uint32_t key[8];
  485. /* 8 - 11 Original IV */
  486. uint32_t oiv[4];
  487. /* 12 - 15 Updated IV */
  488. uint32_t uiv[4];
  489. } tegra_se_aes_key_slot_t;
  490. #pragma pack(pop)
  491. #pragma pack(push, 1)
  492. typedef struct tegra_se_context {
  493. /* random number */
  494. unsigned char rand_data[SE_CTX_SAVE_RANDOM_DATA_SIZE];
  495. /* Sticky bits */
  496. unsigned char sticky_bits[SE_CTX_SAVE_STICKY_BITS_SIZE * 2];
  497. /* AES key slots */
  498. tegra_se_aes_key_slot_t key_slots[TEGRA_SE_AES_KEYSLOT_COUNT];
  499. /* RSA key slots */
  500. unsigned char rsa_keys[SE_CTX_SAVE_RSA_KEY_LENGTH];
  501. } tegra_se_context_t;
  502. #pragma pack(pop)
  503. /* PKA context blob */
  504. #pragma pack(push, 1)
  505. typedef struct tegra_pka_context {
  506. unsigned char sticky_bits[SE2_CONTEXT_SAVE_PKA1_STICKY_BITS_LENGTH];
  507. unsigned char pka_keys[SE2_CONTEXT_SAVE_PKA1_KEYS_LENGTH];
  508. } tegra_pka_context_t;
  509. #pragma pack(pop)
  510. /* SE context blob */
  511. #pragma pack(push, 1)
  512. typedef struct tegra_se_context_blob {
  513. /* SE context */
  514. tegra_se_context_t se_ctx;
  515. /* Known Pattern */
  516. unsigned char known_pattern[SE_CTX_KNOWN_PATTERN_SIZE];
  517. } tegra_se_context_blob_t;
  518. #pragma pack(pop)
  519. /* SE2 and PKA1 context blob */
  520. #pragma pack(push, 1)
  521. typedef struct tegra_se2_context_blob {
  522. /* SE2 context */
  523. tegra_se_context_t se_ctx;
  524. /* PKA1 context */
  525. tegra_pka_context_t pka_ctx;
  526. /* Known Pattern */
  527. unsigned char known_pattern[SE_CTX_KNOWN_PATTERN_SIZE];
  528. } tegra_se2_context_blob_t;
  529. #pragma pack(pop)
  530. /* SE AES key type 128bit, 192bit, 256bit */
  531. typedef enum {
  532. SE_AES_KEY128,
  533. SE_AES_KEY192,
  534. SE_AES_KEY256,
  535. } tegra_se_aes_key_type_t;
  536. /* SE RSA key slot */
  537. typedef struct tegra_se_rsa_key_slot {
  538. /* 0 - 63 exponent key */
  539. uint32_t exponent[SE_RSA_MAX_EXP_SIZE32];
  540. /* 64 - 127 modulus key */
  541. uint32_t modulus[SE_RSA_MAX_MOD_SIZE32];
  542. } tegra_se_rsa_key_slot_t;
  543. /*******************************************************************************
  544. * Inline functions definition
  545. ******************************************************************************/
  546. static inline uint32_t tegra_se_read_32(const tegra_se_dev_t *dev, uint32_t offset)
  547. {
  548. return mmio_read_32(dev->se_base + offset);
  549. }
  550. static inline void tegra_se_write_32(const tegra_se_dev_t *dev, uint32_t offset, uint32_t val)
  551. {
  552. mmio_write_32(dev->se_base + offset, val);
  553. }
  554. static inline uint32_t tegra_pka_read_32(tegra_pka_dev_t *dev, uint32_t offset)
  555. {
  556. return mmio_read_32(dev->pka_base + offset);
  557. }
  558. static inline void tegra_pka_write_32(tegra_pka_dev_t *dev, uint32_t offset,
  559. uint32_t val)
  560. {
  561. mmio_write_32(dev->pka_base + offset, val);
  562. }
  563. /*******************************************************************************
  564. * Prototypes
  565. ******************************************************************************/
  566. int tegra_se_start_normal_operation(const tegra_se_dev_t *, uint32_t);
  567. int tegra_se_start_ctx_save_operation(const tegra_se_dev_t *, uint32_t);
  568. #endif /* SE_PRIVATE_H */