sci_misc_api.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. /*
  2. * Copyright (C) 2016 Freescale Semiconductor, Inc.
  3. * Copyright 2017-2019 NXP
  4. *
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. /*!
  8. * Header file containing the public API for the System Controller (SC)
  9. * Miscellaneous (MISC) function.
  10. *
  11. * @addtogroup MISC_SVC (SVC) Miscellaneous Service
  12. *
  13. * Module for the Miscellaneous (MISC) service.
  14. *
  15. * @{
  16. */
  17. #ifndef SC_MISC_API_H
  18. #define SC_MISC_API_H
  19. /* Includes */
  20. #include <sci/svc/rm/sci_rm_api.h>
  21. #include <sci/sci_types.h>
  22. /* Defines */
  23. /*!
  24. * @name Defines for type widths
  25. */
  26. /*@{*/
  27. #define SC_MISC_DMA_GRP_W 5U /* Width of sc_misc_dma_group_t */
  28. /*@}*/
  29. /*! Max DMA channel priority group */
  30. #define SC_MISC_DMA_GRP_MAX 31U
  31. /*!
  32. * @name Defines for sc_misc_boot_status_t
  33. */
  34. /*@{*/
  35. #define SC_MISC_BOOT_STATUS_SUCCESS 0U /* Success */
  36. #define SC_MISC_BOOT_STATUS_SECURITY 1U /* Security violation */
  37. /*@}*/
  38. /*!
  39. * @name Defines for sc_misc_seco_auth_cmd_t
  40. */
  41. /*@{*/
  42. #define SC_MISC_SECO_AUTH_SECO_FW 0U /* SECO Firmware */
  43. #define SC_MISC_SECO_AUTH_HDMI_TX_FW 1U /* HDMI TX Firmware */
  44. #define SC_MISC_SECO_AUTH_HDMI_RX_FW 2U /* HDMI RX Firmware */
  45. /*@}*/
  46. /*!
  47. * @name Defines for sc_misc_temp_t
  48. */
  49. /*@{*/
  50. #define SC_MISC_TEMP 0U /* Temp sensor */
  51. #define SC_MISC_TEMP_HIGH 1U /* Temp high alarm */
  52. #define SC_MISC_TEMP_LOW 2U /* Temp low alarm */
  53. /*@}*/
  54. /*!
  55. * @name Defines for sc_misc_seco_auth_cmd_t
  56. */
  57. /*@{*/
  58. #define SC_MISC_AUTH_CONTAINER 0U /* Authenticate container */
  59. #define SC_MISC_VERIFY_IMAGE 1U /* Verify image */
  60. #define SC_MISC_REL_CONTAINER 2U /* Release container */
  61. /*@}*/
  62. /* Types */
  63. /*!
  64. * This type is used to store a DMA channel priority group.
  65. */
  66. typedef uint8_t sc_misc_dma_group_t;
  67. /*!
  68. * This type is used report boot status.
  69. */
  70. typedef uint8_t sc_misc_boot_status_t;
  71. /*!
  72. * This type is used to issue SECO authenticate commands.
  73. */
  74. typedef uint8_t sc_misc_seco_auth_cmd_t;
  75. /*!
  76. * This type is used report boot status.
  77. */
  78. typedef uint8_t sc_misc_temp_t;
  79. /* Functions */
  80. /*!
  81. * @name Control Functions
  82. * @{
  83. */
  84. /*!
  85. * This function sets a miscellaneous control value.
  86. *
  87. * @param[in] ipc IPC handle
  88. * @param[in] resource resource the control is associated with
  89. * @param[in] ctrl control to change
  90. * @param[in] val value to apply to the control
  91. *
  92. * @return Returns an error code (SC_ERR_NONE = success).
  93. *
  94. * Return errors:
  95. * - SC_PARM if arguments out of range or invalid,
  96. * - SC_ERR_NOACCESS if caller's partition is not the resource owner or parent
  97. * of the owner
  98. *
  99. * Refer to the [Control List](@ref CONTROLS) for valid control values.
  100. */
  101. sc_err_t sc_misc_set_control(sc_ipc_t ipc, sc_rsrc_t resource,
  102. sc_ctrl_t ctrl, uint32_t val);
  103. /*!
  104. * This function gets a miscellaneous control value.
  105. *
  106. * @param[in] ipc IPC handle
  107. * @param[in] resource resource the control is associated with
  108. * @param[in] ctrl control to get
  109. * @param[out] val pointer to return the control value
  110. *
  111. * @return Returns an error code (SC_ERR_NONE = success).
  112. *
  113. * Return errors:
  114. * - SC_PARM if arguments out of range or invalid,
  115. * - SC_ERR_NOACCESS if caller's partition is not the resource owner or parent
  116. * of the owner
  117. *
  118. * Refer to the [Control List](@ref CONTROLS) for valid control values.
  119. */
  120. sc_err_t sc_misc_get_control(sc_ipc_t ipc, sc_rsrc_t resource,
  121. sc_ctrl_t ctrl, uint32_t *val);
  122. /* @} */
  123. /*!
  124. * @name DMA Functions
  125. * @{
  126. */
  127. /*!
  128. * This function configures the max DMA channel priority group for a
  129. * partition.
  130. *
  131. * @param[in] ipc IPC handle
  132. * @param[in] pt handle of partition to assign \a max
  133. * @param[in] max max priority group (0-31)
  134. *
  135. * @return Returns an error code (SC_ERR_NONE = success).
  136. *
  137. * Return errors:
  138. * - SC_PARM if arguments out of range or invalid,
  139. * - SC_ERR_NOACCESS if caller's partition is not the parent
  140. * of the affected partition
  141. *
  142. * Valid \a max range is 0-31 with 0 being the lowest and 31 the highest.
  143. * Default is the max priority group for the parent partition of \a pt.
  144. */
  145. sc_err_t sc_misc_set_max_dma_group(sc_ipc_t ipc, sc_rm_pt_t pt,
  146. sc_misc_dma_group_t max);
  147. /*!
  148. * This function configures the priority group for a DMA channel.
  149. *
  150. * @param[in] ipc IPC handle
  151. * @param[in] resource DMA channel resource
  152. * @param[in] group priority group (0-31)
  153. *
  154. * @return Returns an error code (SC_ERR_NONE = success).
  155. *
  156. * Return errors:
  157. * - SC_PARM if arguments out of range or invalid,
  158. * - SC_ERR_NOACCESS if caller's partition is not the owner or parent
  159. * of the owner of the DMA channel
  160. *
  161. * Valid \a group range is 0-31 with 0 being the lowest and 31 the highest.
  162. * The max value of \a group is limited by the partition max set using
  163. * sc_misc_set_max_dma_group().
  164. */
  165. sc_err_t sc_misc_set_dma_group(sc_ipc_t ipc, sc_rsrc_t resource,
  166. sc_misc_dma_group_t group);
  167. /* @} */
  168. /*!
  169. * @name Security Functions
  170. * @{
  171. */
  172. /*!
  173. * This function loads a SECO image.
  174. *
  175. * @param[in] ipc IPC handle
  176. * @param[in] addr_src address of image source
  177. * @param[in] addr_dst address of image destination
  178. * @param[in] len length of image to load
  179. * @param[in] fw SC_TRUE = firmware load
  180. *
  181. * @return Returns an error code (SC_ERR_NONE = success).
  182. *
  183. * Return errors codes:
  184. * - SC_ERR_PARM if word fuse index param out of range or invalid
  185. * - SC_ERR_UNAVAILABLE if SECO not available
  186. *
  187. * This is used to load images via the SECO. Examples include SECO
  188. * Firmware and IVT/CSF data used for authentication. These are usually
  189. * loaded into SECO TCM. \a addr_src is in secure memory.
  190. *
  191. * See the Security Reference Manual (SRM) for more info.
  192. */
  193. sc_err_t sc_misc_seco_image_load(sc_ipc_t ipc, sc_faddr_t addr_src,
  194. sc_faddr_t addr_dst, uint32_t len,
  195. sc_bool_t fw);
  196. /*!
  197. * This function is used to authenticate a SECO image or command.
  198. *
  199. * @param[in] ipc IPC handle
  200. * @param[in] cmd authenticate command
  201. * @param[in] addr address of/or metadata
  202. *
  203. * @return Returns an error code (SC_ERR_NONE = success).
  204. *
  205. * Return errors codes:
  206. * - SC_ERR_PARM if word fuse index param out of range or invalid
  207. * - SC_ERR_UNAVAILABLE if SECO not available
  208. *
  209. * This is used to authenticate a SECO image or issue a security
  210. * command. \a addr often points to an container. It is also
  211. * just data (or even unused) for some commands.
  212. *
  213. * See the Security Reference Manual (SRM) for more info.
  214. */
  215. sc_err_t sc_misc_seco_authenticate(sc_ipc_t ipc,
  216. sc_misc_seco_auth_cmd_t cmd,
  217. sc_faddr_t addr);
  218. /*!
  219. * This function securely writes a group of fuse words.
  220. *
  221. * @param[in] ipc IPC handle
  222. * @param[in] addr address of message block
  223. *
  224. * @return Returns and error code (SC_ERR_NONE = success).
  225. *
  226. * Return errors codes:
  227. * - SC_ERR_UNAVAILABLE if SECO not available
  228. *
  229. * Note \a addr must be a pointer to a signed message block.
  230. *
  231. * See the Security Reference Manual (SRM) for more info.
  232. */
  233. sc_err_t sc_misc_seco_fuse_write(sc_ipc_t ipc, sc_faddr_t addr);
  234. /*!
  235. * This function securely enables debug.
  236. *
  237. * @param[in] ipc IPC handle
  238. * @param[in] addr address of message block
  239. *
  240. * @return Returns and error code (SC_ERR_NONE = success).
  241. *
  242. * Return errors codes:
  243. * - SC_ERR_UNAVAILABLE if SECO not available
  244. *
  245. * Note \a addr must be a pointer to a signed message block.
  246. *
  247. * See the Security Reference Manual (SRM) for more info.
  248. */
  249. sc_err_t sc_misc_seco_enable_debug(sc_ipc_t ipc, sc_faddr_t addr);
  250. /*!
  251. * This function updates the lifecycle of the device.
  252. *
  253. * @param[in] ipc IPC handle
  254. * @param[in] lifecycle new lifecycle
  255. *
  256. * @return Returns and error code (SC_ERR_NONE = success).
  257. *
  258. * Return errors codes:
  259. * - SC_ERR_UNAVAILABLE if SECO not available
  260. *
  261. * This message is used for going from Open to NXP Closed to OEM Closed.
  262. *
  263. * See the Security Reference Manual (SRM) for more info.
  264. */
  265. sc_err_t sc_misc_seco_forward_lifecycle(sc_ipc_t ipc, uint32_t lifecycle);
  266. /*!
  267. * This function updates the lifecycle to one of the return lifecycles.
  268. *
  269. * @param[in] ipc IPC handle
  270. * @param[in] addr address of message block
  271. *
  272. * @return Returns and error code (SC_ERR_NONE = success).
  273. *
  274. * Return errors codes:
  275. * - SC_ERR_UNAVAILABLE if SECO not available
  276. *
  277. * Note \a addr must be a pointer to a signed message block.
  278. *
  279. * To switch back to NXP states (Full Field Return), message must be signed
  280. * by NXP SRK. For OEM States (Partial Field Return), must be signed by OEM
  281. * SRK.
  282. *
  283. * See the Security Reference Manual (SRM) for more info.
  284. */
  285. sc_err_t sc_misc_seco_return_lifecycle(sc_ipc_t ipc, sc_faddr_t addr);
  286. /*!
  287. * This function is used to return the SECO FW build info.
  288. *
  289. * @param[in] ipc IPC handle
  290. * @param[out] version pointer to return build number
  291. * @param[out] commit pointer to return commit ID (git SHA-1)
  292. */
  293. void sc_misc_seco_build_info(sc_ipc_t ipc, uint32_t *version, uint32_t *commit);
  294. /*!
  295. * This function is used to return SECO chip info.
  296. *
  297. * @param[in] ipc IPC handle
  298. * @param[out] lc pointer to return lifecycle
  299. * @param[out] monotonic pointer to return monotonic counter
  300. * @param[out] uid_l pointer to return UID (lower 32 bits)
  301. * @param[out] uid_h pointer to return UID (upper 32 bits)
  302. */
  303. sc_err_t sc_misc_seco_chip_info(sc_ipc_t ipc, uint16_t *lc,
  304. uint16_t *monotonic, uint32_t *uid_l,
  305. uint32_t *uid_h);
  306. /* @} */
  307. /*!
  308. * @name Debug Functions
  309. * @{
  310. */
  311. /*!
  312. * This function is used output a debug character from the SCU UART.
  313. *
  314. * @param[in] ipc IPC handle
  315. * @param[in] ch character to output
  316. */
  317. void sc_misc_debug_out(sc_ipc_t ipc, uint8_t ch);
  318. /*!
  319. * This function starts/stops emulation waveform capture.
  320. *
  321. * @param[in] ipc IPC handle
  322. * @param[in] enable flag to enable/disable capture
  323. *
  324. * @return Returns an error code (SC_ERR_NONE = success).
  325. *
  326. * Return errors:
  327. * - SC_ERR_UNAVAILABLE if not running on emulation
  328. */
  329. sc_err_t sc_misc_waveform_capture(sc_ipc_t ipc, sc_bool_t enable);
  330. /*!
  331. * This function is used to return the SCFW build info.
  332. *
  333. * @param[in] ipc IPC handle
  334. * @param[out] build pointer to return build number
  335. * @param[out] commit pointer to return commit ID (git SHA-1)
  336. */
  337. void sc_misc_build_info(sc_ipc_t ipc, uint32_t *build, uint32_t *commit);
  338. /*!
  339. * This function is used to return the device's unique ID.
  340. *
  341. * @param[in] ipc IPC handle
  342. * @param[out] id_l pointer to return lower 32-bit of ID [31:0]
  343. * @param[out] id_h pointer to return upper 32-bits of ID [63:32]
  344. */
  345. void sc_misc_unique_id(sc_ipc_t ipc, uint32_t *id_l, uint32_t *id_h);
  346. /* @} */
  347. /*!
  348. * @name Other Functions
  349. * @{
  350. */
  351. /*!
  352. * This function configures the ARI match value for PCIe/SATA resources.
  353. *
  354. * @param[in] ipc IPC handle
  355. * @param[in] resource match resource
  356. * @param[in] resource_mst PCIe/SATA master to match
  357. * @param[in] ari ARI to match
  358. * @param[in] enable enable match or not
  359. *
  360. * @return Returns an error code (SC_ERR_NONE = success).
  361. *
  362. * Return errors:
  363. * - SC_PARM if arguments out of range or invalid,
  364. * - SC_ERR_NOACCESS if caller's partition is not the owner or parent
  365. * of the owner of the resource and translation
  366. *
  367. * For PCIe, the ARI is the 16-bit value that includes the bus number,
  368. * device number, and function number. For SATA, this value includes the
  369. * FISType and PM_Port.
  370. */
  371. sc_err_t sc_misc_set_ari(sc_ipc_t ipc, sc_rsrc_t resource,
  372. sc_rsrc_t resource_mst, uint16_t ari,
  373. sc_bool_t enable);
  374. /*!
  375. * This function reports boot status.
  376. *
  377. * @param[in] ipc IPC handle
  378. * @param[in] status boot status
  379. *
  380. * This is used by SW partitions to report status of boot. This is
  381. * normally used to report a boot failure.
  382. */
  383. void sc_misc_boot_status(sc_ipc_t ipc, sc_misc_boot_status_t status);
  384. /*!
  385. * This function tells the SCFW that a CPU is done booting.
  386. *
  387. * @param[in] ipc IPC handle
  388. * @param[in] cpu CPU that is done booting
  389. *
  390. * This is called by early booting CPUs to report they are done with
  391. * initialization. After starting early CPUs, the SCFW halts the
  392. * booting process until they are done. During this time, early
  393. * CPUs can call the SCFW with lower latency as the SCFW is idle.
  394. *
  395. * @return Returns an error code (SC_ERR_NONE = success).
  396. *
  397. * Return errors:
  398. * - SC_PARM if arguments out of range or invalid,
  399. * - SC_ERR_NOACCESS if caller's partition is not the CPU owner
  400. */
  401. sc_err_t sc_misc_boot_done(sc_ipc_t ipc, sc_rsrc_t cpu);
  402. /*!
  403. * This function reads a given fuse word index.
  404. *
  405. * @param[in] ipc IPC handle
  406. * @param[in] word fuse word index
  407. * @param[out] val fuse read value
  408. *
  409. * @return Returns and error code (SC_ERR_NONE = success).
  410. *
  411. * Return errors codes:
  412. * - SC_ERR_PARM if word fuse index param out of range or invalid
  413. * - SC_ERR_NOACCESS if read operation failed
  414. * - SC_ERR_LOCKED if read operation is locked
  415. */
  416. sc_err_t sc_misc_otp_fuse_read(sc_ipc_t ipc, uint32_t word, uint32_t *val);
  417. /*!
  418. * This function writes a given fuse word index.
  419. *
  420. * @param[in] ipc IPC handle
  421. * @param[in] word fuse word index
  422. * @param[in] val fuse write value
  423. *
  424. * @return Returns and error code (SC_ERR_NONE = success).
  425. *
  426. * Return errors codes:
  427. * - SC_ERR_PARM if word fuse index param out of range or invalid
  428. * - SC_ERR_NOACCESS if write operation failed
  429. * - SC_ERR_LOCKED if write operation is locked
  430. */
  431. sc_err_t sc_misc_otp_fuse_write(sc_ipc_t ipc, uint32_t word, uint32_t val);
  432. /*!
  433. * This function sets a temp sensor alarm.
  434. *
  435. * @param[in] ipc IPC handle
  436. * @param[in] resource resource with sensor
  437. * @param[in] temp alarm to set
  438. * @param[in] celsius whole part of temp to set
  439. * @param[in] tenths fractional part of temp to set
  440. *
  441. * @return Returns and error code (SC_ERR_NONE = success).
  442. *
  443. * This function will enable the alarm interrupt if the temp requested is
  444. * not the min/max temp. This enable automatically clears when the alarm
  445. * occurs and this function has to be called again to re-enable.
  446. *
  447. * Return errors codes:
  448. * - SC_ERR_PARM if parameters invalid
  449. */
  450. sc_err_t sc_misc_set_temp(sc_ipc_t ipc, sc_rsrc_t resource,
  451. sc_misc_temp_t temp, int16_t celsius, int8_t tenths);
  452. /*!
  453. * This function gets a temp sensor value.
  454. *
  455. * @param[in] ipc IPC handle
  456. * @param[in] resource resource with sensor
  457. * @param[in] temp value to get (sensor or alarm)
  458. * @param[out] celsius whole part of temp to get
  459. * @param[out] tenths fractional part of temp to get
  460. *
  461. * @return Returns and error code (SC_ERR_NONE = success).
  462. *
  463. * Return errors codes:
  464. * - SC_ERR_PARM if parameters invalid
  465. */
  466. sc_err_t sc_misc_get_temp(sc_ipc_t ipc, sc_rsrc_t resource,
  467. sc_misc_temp_t temp, int16_t *celsius,
  468. int8_t *tenths);
  469. /*!
  470. * This function returns the boot device.
  471. *
  472. * @param[in] ipc IPC handle
  473. * @param[out] dev pointer to return boot device
  474. */
  475. void sc_misc_get_boot_dev(sc_ipc_t ipc, sc_rsrc_t *dev);
  476. /*!
  477. * This function returns the current status of the ON/OFF button.
  478. *
  479. * @param[in] ipc IPC handle
  480. * @param[out] status pointer to return button status
  481. */
  482. void sc_misc_get_button_status(sc_ipc_t ipc, sc_bool_t *status);
  483. /* @} */
  484. #endif /* SC_MISC_API_H */
  485. /**@}*/