fsl_sec.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. /*
  2. * Common internal memory map for some Freescale SoCs
  3. *
  4. * Copyright 2014 Freescale Semiconductor, Inc.
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #ifndef __FSL_SEC_H
  9. #define __FSL_SEC_H
  10. #include <common.h>
  11. #include <asm/io.h>
  12. #ifdef CONFIG_SYS_FSL_SEC_LE
  13. #define sec_in32(a) in_le32(a)
  14. #define sec_out32(a, v) out_le32(a, v)
  15. #define sec_in16(a) in_le16(a)
  16. #define sec_clrbits32 clrbits_le32
  17. #define sec_setbits32 setbits_le32
  18. #elif defined(CONFIG_SYS_FSL_SEC_BE)
  19. #define sec_in32(a) in_be32(a)
  20. #define sec_out32(a, v) out_be32(a, v)
  21. #define sec_in16(a) in_be16(a)
  22. #define sec_clrbits32 clrbits_be32
  23. #define sec_setbits32 setbits_be32
  24. #elif defined(CONFIG_SYS_FSL_HAS_SEC)
  25. #error Neither CONFIG_SYS_FSL_SEC_LE nor CONFIG_SYS_FSL_SEC_BE is defined
  26. #endif
  27. /* Security Engine Block (MS = Most Sig., LS = Least Sig.) */
  28. #if CONFIG_SYS_FSL_SEC_COMPAT >= 4
  29. /* RNG4 TRNG test registers */
  30. struct rng4tst {
  31. #define RTMCTL_PRGM 0x00010000 /* 1 -> program mode, 0 -> run mode */
  32. #define RTMCTL_SAMP_MODE_VON_NEUMANN_ES_SC 0 /* use von Neumann data in
  33. both entropy shifter and
  34. statistical checker */
  35. #define RTMCTL_SAMP_MODE_RAW_ES_SC 1 /* use raw data in both
  36. entropy shifter and
  37. statistical checker */
  38. #define RTMCTL_SAMP_MODE_VON_NEUMANN_ES_RAW_SC 2 /* use von Neumann data in
  39. entropy shifter, raw data
  40. in statistical checker */
  41. #define RTMCTL_SAMP_MODE_INVALID 3 /* invalid combination */
  42. u32 rtmctl; /* misc. control register */
  43. u32 rtscmisc; /* statistical check misc. register */
  44. u32 rtpkrrng; /* poker range register */
  45. #define RTSDCTL_ENT_DLY_MIN 3200
  46. #define RTSDCTL_ENT_DLY_MAX 12800
  47. union {
  48. u32 rtpkrmax; /* PRGM=1: poker max. limit register */
  49. u32 rtpkrsq; /* PRGM=0: poker square calc. result register */
  50. };
  51. #define RTSDCTL_ENT_DLY_SHIFT 16
  52. #define RTSDCTL_ENT_DLY_MASK (0xffff << RTSDCTL_ENT_DLY_SHIFT)
  53. u32 rtsdctl; /* seed control register */
  54. union {
  55. u32 rtsblim; /* PRGM=1: sparse bit limit register */
  56. u32 rttotsam; /* PRGM=0: total samples register */
  57. };
  58. u32 rtfreqmin; /* frequency count min. limit register */
  59. #define RTFRQMAX_DISABLE (1 << 20)
  60. union {
  61. u32 rtfreqmax; /* PRGM=1: freq. count max. limit register */
  62. u32 rtfreqcnt; /* PRGM=0: freq. count register */
  63. };
  64. u32 rsvd1[40];
  65. #define RNG_STATE0_HANDLE_INSTANTIATED 0x00000001
  66. u32 rdsta; /*RNG DRNG Status Register*/
  67. u32 rsvd2[15];
  68. };
  69. typedef struct ccsr_sec {
  70. u32 res0;
  71. u32 mcfgr; /* Master CFG Register */
  72. u8 res1[0x4];
  73. u32 scfgr;
  74. struct {
  75. u32 ms; /* Job Ring LIODN Register, MS */
  76. u32 ls; /* Job Ring LIODN Register, LS */
  77. } jrliodnr[4];
  78. u8 res2[0x2c];
  79. u32 jrstartr; /* Job Ring Start Register */
  80. struct {
  81. u32 ms; /* RTIC LIODN Register, MS */
  82. u32 ls; /* RTIC LIODN Register, LS */
  83. } rticliodnr[4];
  84. u8 res3[0x1c];
  85. u32 decorr; /* DECO Request Register */
  86. struct {
  87. u32 ms; /* DECO LIODN Register, MS */
  88. u32 ls; /* DECO LIODN Register, LS */
  89. } decoliodnr[8];
  90. u8 res4[0x40];
  91. u32 dar; /* DECO Avail Register */
  92. u32 drr; /* DECO Reset Register */
  93. u8 res5[0x4d8];
  94. struct rng4tst rng; /* RNG Registers */
  95. u8 res6[0x8a0];
  96. u32 crnr_ms; /* CHA Revision Number Register, MS */
  97. u32 crnr_ls; /* CHA Revision Number Register, LS */
  98. u32 ctpr_ms; /* Compile Time Parameters Register, MS */
  99. u32 ctpr_ls; /* Compile Time Parameters Register, LS */
  100. u8 res7[0x10];
  101. u32 far_ms; /* Fault Address Register, MS */
  102. u32 far_ls; /* Fault Address Register, LS */
  103. u32 falr; /* Fault Address LIODN Register */
  104. u32 fadr; /* Fault Address Detail Register */
  105. u8 res8[0x4];
  106. u32 csta; /* CAAM Status Register */
  107. u32 smpart; /* Secure Memory Partition Parameters */
  108. u32 smvid; /* Secure Memory Version ID */
  109. u32 rvid; /* Run Time Integrity Checking Version ID Reg.*/
  110. u32 ccbvid; /* CHA Cluster Block Version ID Register */
  111. u32 chavid_ms; /* CHA Version ID Register, MS */
  112. u32 chavid_ls; /* CHA Version ID Register, LS */
  113. u32 chanum_ms; /* CHA Number Register, MS */
  114. u32 chanum_ls; /* CHA Number Register, LS */
  115. u32 secvid_ms; /* SEC Version ID Register, MS */
  116. u32 secvid_ls; /* SEC Version ID Register, LS */
  117. u8 res9[0x6020];
  118. u32 qilcr_ms; /* Queue Interface LIODN CFG Register, MS */
  119. u32 qilcr_ls; /* Queue Interface LIODN CFG Register, LS */
  120. u8 res10[0x8fd8];
  121. } ccsr_sec_t;
  122. #define SEC_CTPR_MS_AXI_LIODN 0x08000000
  123. #define SEC_CTPR_MS_QI 0x02000000
  124. #define SEC_CTPR_MS_VIRT_EN_INCL 0x00000001
  125. #define SEC_CTPR_MS_VIRT_EN_POR 0x00000002
  126. #define SEC_RVID_MA 0x0f000000
  127. #define SEC_CHANUM_MS_JRNUM_MASK 0xf0000000
  128. #define SEC_CHANUM_MS_JRNUM_SHIFT 28
  129. #define SEC_CHANUM_MS_DECONUM_MASK 0x0f000000
  130. #define SEC_CHANUM_MS_DECONUM_SHIFT 24
  131. #define SEC_SECVID_MS_IPID_MASK 0xffff0000
  132. #define SEC_SECVID_MS_IPID_SHIFT 16
  133. #define SEC_SECVID_MS_MAJ_REV_MASK 0x0000ff00
  134. #define SEC_SECVID_MS_MAJ_REV_SHIFT 8
  135. #define SEC_CCBVID_ERA_MASK 0xff000000
  136. #define SEC_CCBVID_ERA_SHIFT 24
  137. #define SEC_SCFGR_RDBENABLE 0x00000400
  138. #define SEC_SCFGR_VIRT_EN 0x00008000
  139. #define SEC_CHAVID_LS_RNG_SHIFT 16
  140. #define SEC_CHAVID_RNG_LS_MASK 0x000f0000
  141. #define CONFIG_JRSTARTR_JR0 0x00000001
  142. struct jr_regs {
  143. #if defined(CONFIG_SYS_FSL_SEC_LE) && \
  144. !(defined(CONFIG_MX6) || defined(CONFIG_MX7))
  145. u32 irba_l;
  146. u32 irba_h;
  147. #else
  148. u32 irba_h;
  149. u32 irba_l;
  150. #endif
  151. u32 rsvd1;
  152. u32 irs;
  153. u32 rsvd2;
  154. u32 irsa;
  155. u32 rsvd3;
  156. u32 irja;
  157. #if defined(CONFIG_SYS_FSL_SEC_LE) && \
  158. !(defined(CONFIG_MX6) || defined(CONFIG_MX7))
  159. u32 orba_l;
  160. u32 orba_h;
  161. #else
  162. u32 orba_h;
  163. u32 orba_l;
  164. #endif
  165. u32 rsvd4;
  166. u32 ors;
  167. u32 rsvd5;
  168. u32 orjr;
  169. u32 rsvd6;
  170. u32 orsf;
  171. u32 rsvd7;
  172. u32 jrsta;
  173. u32 rsvd8;
  174. u32 jrint;
  175. u32 jrcfg0;
  176. u32 jrcfg1;
  177. u32 rsvd9;
  178. u32 irri;
  179. u32 rsvd10;
  180. u32 orwi;
  181. u32 rsvd11;
  182. u32 jrcr;
  183. };
  184. /*
  185. * Scatter Gather Entry - Specifies the the Scatter Gather Format
  186. * related information
  187. */
  188. struct sg_entry {
  189. #if defined(CONFIG_SYS_FSL_SEC_LE) && \
  190. !(defined(CONFIG_MX6) || defined(CONFIG_MX7))
  191. uint32_t addr_lo; /* Memory Address - lo */
  192. uint32_t addr_hi; /* Memory Address of start of buffer - hi */
  193. #else
  194. uint32_t addr_hi; /* Memory Address of start of buffer - hi */
  195. uint32_t addr_lo; /* Memory Address - lo */
  196. #endif
  197. uint32_t len_flag; /* Length of the data in the frame */
  198. #define SG_ENTRY_LENGTH_MASK 0x3FFFFFFF
  199. #define SG_ENTRY_EXTENSION_BIT 0x80000000
  200. #define SG_ENTRY_FINAL_BIT 0x40000000
  201. uint32_t bpid_offset;
  202. #define SG_ENTRY_BPID_MASK 0x00FF0000
  203. #define SG_ENTRY_BPID_SHIFT 16
  204. #define SG_ENTRY_OFFSET_MASK 0x00001FFF
  205. #define SG_ENTRY_OFFSET_SHIFT 0
  206. };
  207. #if defined(CONFIG_MX6) || defined(CONFIG_MX7)
  208. /* Job Ring Base Address */
  209. #define JR_BASE_ADDR(x) (CONFIG_SYS_FSL_SEC_ADDR + 0x1000 * (x + 1))
  210. /* Secure Memory Offset varies accross versions */
  211. #define SM_V1_OFFSET 0x0f4
  212. #define SM_V2_OFFSET 0xa00
  213. /*Secure Memory Versioning */
  214. #define SMVID_V2 0x20105
  215. #define SM_VERSION(x) (x < SMVID_V2 ? 1 : 2)
  216. #define SM_OFFSET(x) (x == 1 ? SM_V1_OFFSET : SM_V2_OFFSET)
  217. /* CAAM Job Ring 0 Registers */
  218. /* Secure Memory Partition Owner register */
  219. #define SMCSJR_PO (3 << 6)
  220. /* JR Allocation Error */
  221. #define SMCSJR_AERR (3 << 12)
  222. /* Secure memory partition 0 page 0 owner register */
  223. #define CAAM_SMPO_0 (CONFIG_SYS_FSL_SEC_ADDR + 0x1FBC)
  224. /* Secure memory command register */
  225. #define CAAM_SMCJR(v, jr) (JR_BASE_ADDR(jr) + SM_OFFSET(v) + SM_CMD(v))
  226. /* Secure memory command status register */
  227. #define CAAM_SMCSJR(v, jr) (JR_BASE_ADDR(jr) + SM_OFFSET(v) + SM_STATUS(v))
  228. /* Secure memory access permissions register */
  229. #define CAAM_SMAPJR(v, jr, y) \
  230. (JR_BASE_ADDR(jr) + SM_OFFSET(v) + SM_PERM(v) + y * 16)
  231. /* Secure memory access group 2 register */
  232. #define CAAM_SMAG2JR(v, jr, y) \
  233. (JR_BASE_ADDR(jr) + SM_OFFSET(v) + SM_GROUP2(v) + y * 16)
  234. /* Secure memory access group 1 register */
  235. #define CAAM_SMAG1JR(v, jr, y) \
  236. (JR_BASE_ADDR(jr) + SM_OFFSET(v) + SM_GROUP1(v) + y * 16)
  237. /* Commands and macros for secure memory */
  238. #define SM_CMD(v) (v == 1 ? 0x0 : 0x1E4)
  239. #define SM_STATUS(v) (v == 1 ? 0x8 : 0x1EC)
  240. #define SM_PERM(v) (v == 1 ? 0x10 : 0x4)
  241. #define SM_GROUP2(v) (v == 1 ? 0x14 : 0x8)
  242. #define SM_GROUP1(v) (v == 1 ? 0x18 : 0xC)
  243. #define CMD_PAGE_ALLOC 0x1
  244. #define CMD_PAGE_DEALLOC 0x2
  245. #define CMD_PART_DEALLOC 0x3
  246. #define CMD_INQUIRY 0x5
  247. #define CMD_COMPLETE (3 << 14)
  248. #define PAGE_AVAILABLE 0
  249. #define PAGE_OWNED (3 << 6)
  250. #define PAGE(x) (x << 16)
  251. #define PARTITION(x) (x << 8)
  252. #define PARTITION_OWNER(x) (0x3 << (x*2))
  253. /* Address of secure 4kbyte pages */
  254. #define SEC_MEM_PAGE0 CAAM_ARB_BASE_ADDR
  255. #define SEC_MEM_PAGE1 (CAAM_ARB_BASE_ADDR + 0x1000)
  256. #define SEC_MEM_PAGE2 (CAAM_ARB_BASE_ADDR + 0x2000)
  257. #define SEC_MEM_PAGE3 (CAAM_ARB_BASE_ADDR + 0x3000)
  258. #define JR_MID 2 /* Matches ROM configuration */
  259. #define KS_G1 (1 << JR_MID) /* CAAM only */
  260. #define PERM 0x0000B008 /* Clear on release, lock SMAP
  261. * lock SMAG group 1 Blob */
  262. #define BLOB_SIZE(x) (x + 32 + 16) /* Blob buffer size */
  263. /* HAB WRAPPED KEY header */
  264. #define WRP_HDR_SIZE 0x08
  265. #define HDR_TAG 0x81
  266. #define HDR_PAR 0x41
  267. /* HAB WRAPPED KEY Data */
  268. #define HAB_MOD 0x66
  269. #define HAB_ALG 0x55
  270. #define HAB_FLG 0x00
  271. /* Partition and Page IDs */
  272. #define PARTITION_1 1
  273. #define PAGE_1 1
  274. #define ERROR_IN_PAGE_ALLOC 1
  275. #define ECONSTRJDESC -1
  276. #endif
  277. /* blob_dek:
  278. * Encapsulates the src in a secure blob and stores it dst
  279. * @src: reference to the plaintext
  280. * @dst: reference to the output adrress
  281. * @len: size in bytes of src
  282. * @return: 0 on success, error otherwise
  283. */
  284. int blob_dek(const u8 *src, u8 *dst, u8 len);
  285. #if defined(CONFIG_ARCH_C29X)
  286. int sec_init_idx(uint8_t);
  287. #endif
  288. int sec_init(void);
  289. #endif
  290. #endif /* __FSL_SEC_H */