efuse-api.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (C) 2021 Alibaba Group Holding Limited.
  4. *
  5. */
  6. #ifndef _EFUSE_API_H
  7. #define _EFUSE_API_H
  8. typedef enum {
  9. USR_DSP0_JTAG = 0,
  10. USR_DSP1_JTAG,
  11. USR_C910T_JTAG,
  12. USR_C910R_JTAG,
  13. USR_C906_JTAG,
  14. USR_E902_JTAG,
  15. USR_CHIP_DBG,
  16. USR_DFT,
  17. } efuse_dbg_type_t;
  18. typedef enum {
  19. DBG_MODE_ENABLE = 0,
  20. DBG_MODE_PWD_PROTECT,
  21. DBG_MODE_DISABLE,
  22. } efuse_dbg_mode_t;
  23. typedef enum {
  24. BROM_USBBOOT_EN= 0,
  25. BROM_USBBOOT_DIS = 0x5a5a5a5a,
  26. } brom_usbboot_st_t;
  27. typedef enum {
  28. BROM_CCT_EN= 0,
  29. BROM_CCT_DIS = 0x5a5a5a5a,
  30. } brom_cct_st_t;
  31. typedef enum {
  32. IMAGE_ENCRYPT_DIS= 0,
  33. IMAGE_ENCRYPT_EN = 0x5a5a5a5a,
  34. } img_encrypt_st_t;
  35. typedef enum {
  36. SECURE_BOOT_DIS= 0,
  37. SECURE_BOOT_EN = 0x5a5a5a5a,
  38. } sboot_st_t;
  39. enum life_cycle_e {
  40. LC_INIT = 0,
  41. LC_DEV,
  42. LC_OEM,
  43. LC_PRO,
  44. LC_RMA,
  45. LC_RIP,
  46. LC_KILL_KEY1,
  47. LC_KILL_KEY0,
  48. LC_MAX,
  49. };
  50. /**
  51. * csi_efuse_get_chipid() - Get chip id in eFuse
  52. *
  53. * @chip_id: pointer to the buffer to store chip id
  54. *
  55. * Return: 0 on success or negative code on failure
  56. */
  57. int csi_efuse_get_chipid(void *chip_id);
  58. /**
  59. * csi_efuse_get_user_dbg_mode() - Get debug mode in user area
  60. *
  61. * @type: Debug type
  62. *
  63. * @dbg_mode: pointer to the buffer store debug mode
  64. *
  65. * Return: 0 on success or negative code on failure
  66. */
  67. int csi_efuse_get_user_dbg_mode(efuse_dbg_type_t type, efuse_dbg_mode_t *dbg_mode);
  68. /**
  69. * csi_efuse_set_user_dbg_mode() - Set debug mode in user area
  70. *
  71. * @type: Debug type
  72. *
  73. * @dbg_mode: debug mode
  74. *
  75. * Return: 0 on success or negative code on failure
  76. */
  77. int csi_efuse_set_user_dbg_mode(efuse_dbg_type_t type, efuse_dbg_mode_t dbg_mode);
  78. /**
  79. * csi_efuse_get_boot_offset() - Get BL1's offset in boot media
  80. *
  81. * @offset: pointer to the buffer to store BL1's offset
  82. *
  83. * Return: 0 on success or negative code on failure
  84. */
  85. int csi_efuse_get_boot_offset(unsigned int *offset);
  86. /**
  87. * csi_efuse_set_boot_offset() - Set BL1's offset in boot media
  88. *
  89. * @offset: Offset value to be set
  90. *
  91. * Return: 0 on success or negative code on failure
  92. */
  93. int csi_efuse_set_boot_offset(unsigned int offset);
  94. /**
  95. * csi_efuse_get_boot_index() - Get BL1's index in boot media
  96. *
  97. * @index: pointer to the buffer to store BL1's index
  98. *
  99. * Return: 0 on success or negative code on failure
  100. */
  101. int csi_efuse_get_boot_index(unsigned char *index);
  102. /**
  103. * csi_efuse_set_boot_index() - Set BL1's index in boot media
  104. *
  105. * @index: index value to be set
  106. *
  107. * Return: 0 on success or negative code on failure
  108. */
  109. int csi_efuse_set_boot_index(unsigned char index);
  110. /**
  111. * csi_efuse_get_bak_boot_offset() - Get BL1's offset in boot media
  112. *
  113. * @offset: pointer to the buffer to store BL1's offset
  114. *
  115. * Return: 0 on success or negative code on failure
  116. */
  117. int csi_efuse_get_bak_boot_offset(unsigned int *offset);
  118. /**
  119. * csi_efuse_set_boot_offset() - Set BL1's offset in boot media
  120. *
  121. * @offset: Offset value to be set
  122. *
  123. * Return: 0 on success or negative code on failure
  124. */
  125. int csi_efuse_set_bak_boot_offset(unsigned int offset);
  126. /**
  127. * csi_efuse_get_bak_boot_index() - Get BL1's index in boot media
  128. *
  129. * @index: pointer to the buffer to store BL1's index
  130. *
  131. * Return: 0 on success or negative code on failure
  132. */
  133. int csi_efuse_get_bak_boot_index(unsigned char *index);
  134. /**
  135. * csi_efuse_set_bak_boot_index() - Set BL1's index in boot media
  136. *
  137. * @index: index value to be set
  138. *
  139. * Return: 0 on success or negative code on failure
  140. */
  141. int csi_efuse_set_bak_boot_index(unsigned char index);
  142. /**
  143. * csi_efuse_get_usr_brom_usb_fastboot_st() - Get bootrom USB fastboots tatus in user area
  144. *
  145. * @status: pointer to the buffer to store USB fastboot status
  146. *
  147. * Return: 0 on success or negative code on failure
  148. */
  149. int csi_efuse_get_usr_brom_usb_fastboot_st(brom_usbboot_st_t *status);
  150. /**
  151. * csi_efuse_dis_usr_brom_usb_fastboot() - Disable bootrom USB fastboot status in user area
  152. *
  153. * Return: 0 on success or negative code on failure
  154. */
  155. int csi_efuse_dis_usr_brom_usb_fastboot(void);
  156. /**
  157. * csi_efuse_get_usr_brom_cct_st() - Get bootrom CCT status in user area
  158. *
  159. * @status: pointer to the buffer to store CCT
  160. *
  161. * Return: 0 on success or negative code on failure
  162. */
  163. int csi_efuse_get_usr_brom_cct_st(brom_cct_st_t *status);
  164. /**
  165. * csi_efuse_dis_usr_brom_cct() - Disable bootrom CCT status in user area
  166. *
  167. * Return: 0 on success or negative code on failure
  168. */
  169. int csi_efuse_dis_usr_brom_cct(void);
  170. /**
  171. * csi_efuse_get_bl2_img_encrypt_st() - Get BL2 image encryption flag
  172. *
  173. * @encrypt_flag: pointer to the buffer to store BL2 encryption flag
  174. *
  175. * Return: 0 on success or negative code on failure
  176. */
  177. int csi_efuse_get_bl2_img_encrypt_st( img_encrypt_st_t *encrypt_flag);
  178. /**
  179. * csi_efuse_set_bl2_img_encrypt_st() - Set BL2 image encryption flag
  180. *
  181. * @encrypt_flag: pointer to the buffer to store BL2 encryption flag
  182. *
  183. * Return: 0 on success or negative code on failure
  184. */
  185. int csi_efuse_set_bl2_img_encrypt_st( img_encrypt_st_t encrypt_flag);
  186. /**
  187. * csi_efuse_get_bl3_img_encrypt_st() - Get BL3 image encryption flag
  188. *
  189. * @encrypt_flag: pointer to the buffer to store BL2 encryption flag
  190. *
  191. * Return: 0 on success or negative code on failure
  192. */
  193. int csi_efuse_get_bl3_img_encrypt_st( img_encrypt_st_t *encrypt_flag);
  194. /**
  195. * csi_efuse_set_bl3_img_encrypt_st() - Set BL3 image encryption flag
  196. *
  197. * @encrypt_flag: pointer to the buffer to store BL3 encryption flag
  198. *
  199. * Return: 0 on success or negative code on failure
  200. */
  201. int csi_efuse_set_bl3_img_encrypt_st( img_encrypt_st_t encrypt_flag);
  202. /**
  203. * csi_efuse_get_bl4_img_encrypt_st() - Get BL4 image encryption flag
  204. *
  205. * @encrypt_flag: pointer to the buffer to store BL4 encryption flag
  206. *
  207. * Return: 0 on success or negative code on failure
  208. */
  209. int csi_efuse_get_bl4_img_encrypt_st( img_encrypt_st_t *encrypt_flag);
  210. /**
  211. * csi_efuse_set_bl4_img_encrypt_st() - Set BL4 image encryption flag
  212. *
  213. * @encrypt_flag: pointer to the buffer to store BL4 encryption flag
  214. *
  215. * Return: 0 on success or negative code on failure
  216. */
  217. int csi_efuse_set_bl4_img_encrypt_st( img_encrypt_st_t encrypt_flag);
  218. /**
  219. * csi_efuse_get_bl1_version() - Get BL1 version
  220. *
  221. * @version: pointer to the buffer to store BL1's version in eFuse
  222. *
  223. * Return: 0 on success or negative code on failure
  224. */
  225. int csi_efuse_get_bl1_version(unsigned long long *version);
  226. /**
  227. * csi_efuse_set_bl1_version() - Set BL1 version
  228. *
  229. * @version: pointer to the buffer to store BL1's version in eFuse
  230. *
  231. * Return: 0 on success or negative code on failure
  232. */
  233. int csi_efuse_set_bl1_version(unsigned long long version);
  234. /**
  235. * csi_efuse_get_bl2_version() - Get BL2 version
  236. *
  237. * @version: pointer to the buffer to store BL2's version in eFuse
  238. *
  239. * Return: 0 on success or negative code on failure
  240. */
  241. int csi_efuse_get_bl2_version(unsigned long long *version);
  242. /**
  243. * csi_efuse_set_bl2_version() - Set BL2 version
  244. *
  245. * @version: pointer to the buffer to store BL2's version in eFuse
  246. *
  247. * Return: 0 on success or negative code on failure
  248. */
  249. int csi_efuse_set_bl2_version(unsigned long long version);
  250. /**
  251. * csi_efuse_get_secure_boot_st() - Get seucre boot flag
  252. *
  253. * @sboot_flag: A pointer to the buffer to store secure boot flag
  254. *
  255. * Return: 0 on success or negative code on failure
  256. */
  257. int csi_efuse_get_secure_boot_st(sboot_st_t *sboot_flag);
  258. /**
  259. * csi_efuse_get_hash_challenge() - Get hash challenge in eFuse
  260. *
  261. * @hash_resp: pointer to the buffer to store hash response
  262. *
  263. * Return: 0 on success or negative code on failure
  264. */
  265. int csi_efuse_get_hash_challenge(void * hash_resp);
  266. /**
  267. * csi_efuse_get_userdata_group() - Get user data in corresponding eFuse block
  268. *
  269. * @key: pointer to the buffer to store user data
  270. * @block_num: the block number in eFuse
  271. *
  272. * Return: 0 on success or negative code on failure
  273. */
  274. int csi_efuse_get_userdata_group(unsigned char *key, unsigned char block_num);
  275. /**
  276. * csi_efuse_set_userdata_group() - Set user data corresponding eFuse block
  277. *
  278. * @key: pointer to the buffer to store user data
  279. * @block_num: the block number in eFuse
  280. *
  281. * Return: 0 on success or negative code on failure
  282. */
  283. int csi_efuse_set_userdata_group(unsigned char *key, unsigned char block_num);
  284. /**
  285. * csi_efuse_read() - Read data from eFuse
  286. *
  287. * @offset: offset address
  288. * @data: Pointer to a buffer storing the data read from eFuse
  289. * @cnt: Number of bytes need to be read
  290. *
  291. * Return: number of data items read or error code
  292. */
  293. int csi_efuse_read(unsigned int offset, void *data, unsigned int cnt);
  294. /**
  295. * csi_efuse_write() - Write data to eFuse
  296. *
  297. * @offset: offset address
  298. * @data: Pointer to a buffer storing the data write to eFuse
  299. * @cnt: Number of bytes need to be write
  300. *
  301. * Return: number of data items write or error code
  302. */
  303. int csi_efuse_write(unsigned int offset, void *data, unsigned int cnt);
  304. /**
  305. * csi_dbg_enable_c910t_jtag() - Enable C910 TEE core jtag
  306. *
  307. * Return: 0 on success or negative code on failure
  308. */
  309. int csi_dbg_enable_c910t_jtag(void);
  310. /**
  311. * csi_dbg_disable_c910t_jtag() - Disable C910 TEE core jtag
  312. *
  313. * Return: 0 on success or negative code on failure
  314. */
  315. int csi_dbg_disable_c910t_jtag(void);
  316. /**
  317. * csi_efuse_get_gmac_macaddr() - Get gmac0/gmac1 mac address in eFuse
  318. * @dev_id: '0' means gmac0, '1' means gmac1
  319. * @mac: the mac address string
  320. *
  321. * Return: 0: Success others: Failed
  322. */
  323. int csi_efuse_get_gmac_macaddr(int dev_id, unsigned char *mac);
  324. /**
  325. * csi_efuse_set_gmac_macaddr() - Set gmac0/gmac1 mac address in eFuse
  326. * @dev_id: '0' means gmac0, '1' means gmac1
  327. * @mac: the mac address string
  328. *
  329. * Return: 0: Success others: Failed
  330. */
  331. int csi_efuse_set_gmac_macaddr(int dev_id, unsigned char *mac);
  332. /**
  333. * csi_efuse_update_lc_rma() - Upate efuse life cycle RMA
  334. *
  335. * Return: 0: Success others: Failed
  336. */
  337. int csi_efuse_update_lc_rma();
  338. /**
  339. * csi_efuse_update_lc_rma() - Upate efuse life cycle RIP
  340. *
  341. * Return: 0: Success others: Failed
  342. */
  343. int csi_efuse_update_lc_rip();
  344. /**
  345. * csi_efuse_get_lc_preld() - get efuse life cycle preld
  346. * @lc_name: the output name of life cycle preld
  347. * Return: 0: Success others: Failed
  348. */
  349. int csi_efuse_get_lc_preld(char *lc_name);
  350. /*
  351. * csi_efuse_update_lc(enum life_cycle_e life_cycle)
  352. * @life_cycle: the life cycle to set
  353. * Return: 0: Success others: Failed
  354. */
  355. int csi_efuse_update_lc(enum life_cycle_e life_cycle);
  356. #endif