misc_rpc_clnt.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. /*
  2. * Copyright (C) 2016 Freescale Semiconductor, Inc.
  3. * Copyright 2017-2018 NXP
  4. *
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. /*!
  8. * File containing client-side RPC functions for the MISC service. These
  9. * functions are ported to clients that communicate to the SC.
  10. *
  11. * @addtogroup MISC_SVC
  12. * @{
  13. */
  14. /* Includes */
  15. #include <sci/sci_types.h>
  16. #include <sci/svc/rm/sci_rm_api.h>
  17. #include <sci/svc/misc/sci_misc_api.h>
  18. #include <sci/sci_rpc.h>
  19. #include <stdlib.h>
  20. #include "sci_misc_rpc.h"
  21. /* Local Defines */
  22. /* Local Types */
  23. /* Local Functions */
  24. sc_err_t sc_misc_set_control(sc_ipc_t ipc, sc_rsrc_t resource,
  25. sc_ctrl_t ctrl, uint32_t val)
  26. {
  27. sc_rpc_msg_t msg;
  28. uint8_t result;
  29. RPC_VER(&msg) = SC_RPC_VERSION;
  30. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
  31. RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_SET_CONTROL;
  32. RPC_U32(&msg, 0U) = (uint32_t)ctrl;
  33. RPC_U32(&msg, 4U) = (uint32_t)val;
  34. RPC_U16(&msg, 8U) = (uint16_t)resource;
  35. RPC_SIZE(&msg) = 4U;
  36. sc_call_rpc(ipc, &msg, SC_FALSE);
  37. result = RPC_R8(&msg);
  38. return (sc_err_t)result;
  39. }
  40. sc_err_t sc_misc_get_control(sc_ipc_t ipc, sc_rsrc_t resource,
  41. sc_ctrl_t ctrl, uint32_t *val)
  42. {
  43. sc_rpc_msg_t msg;
  44. uint8_t result;
  45. RPC_VER(&msg) = SC_RPC_VERSION;
  46. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
  47. RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_GET_CONTROL;
  48. RPC_U32(&msg, 0U) = (uint32_t)ctrl;
  49. RPC_U16(&msg, 4U) = (uint16_t)resource;
  50. RPC_SIZE(&msg) = 3U;
  51. sc_call_rpc(ipc, &msg, SC_FALSE);
  52. if (val != NULL)
  53. *val = RPC_U32(&msg, 0U);
  54. result = RPC_R8(&msg);
  55. return (sc_err_t)result;
  56. }
  57. sc_err_t sc_misc_set_max_dma_group(sc_ipc_t ipc, sc_rm_pt_t pt,
  58. sc_misc_dma_group_t max)
  59. {
  60. sc_rpc_msg_t msg;
  61. uint8_t result;
  62. RPC_VER(&msg) = SC_RPC_VERSION;
  63. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
  64. RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_SET_MAX_DMA_GROUP;
  65. RPC_U8(&msg, 0U) = (uint8_t)pt;
  66. RPC_U8(&msg, 1U) = (uint8_t)max;
  67. RPC_SIZE(&msg) = 2U;
  68. sc_call_rpc(ipc, &msg, SC_FALSE);
  69. result = RPC_R8(&msg);
  70. return (sc_err_t)result;
  71. }
  72. sc_err_t sc_misc_set_dma_group(sc_ipc_t ipc, sc_rsrc_t resource,
  73. sc_misc_dma_group_t group)
  74. {
  75. sc_rpc_msg_t msg;
  76. uint8_t result;
  77. RPC_VER(&msg) = SC_RPC_VERSION;
  78. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
  79. RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_SET_DMA_GROUP;
  80. RPC_U16(&msg, 0U) = (uint16_t)resource;
  81. RPC_U8(&msg, 2U) = (uint8_t)group;
  82. RPC_SIZE(&msg) = 2U;
  83. sc_call_rpc(ipc, &msg, SC_FALSE);
  84. result = RPC_R8(&msg);
  85. return (sc_err_t)result;
  86. }
  87. sc_err_t sc_misc_seco_image_load(sc_ipc_t ipc, sc_faddr_t addr_src,
  88. sc_faddr_t addr_dst, uint32_t len,
  89. sc_bool_t fw)
  90. {
  91. sc_rpc_msg_t msg;
  92. uint8_t result;
  93. RPC_VER(&msg) = SC_RPC_VERSION;
  94. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
  95. RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_SECO_IMAGE_LOAD;
  96. RPC_U32(&msg, 0U) = (uint32_t)(addr_src >> 32U);
  97. RPC_U32(&msg, 4U) = (uint32_t)addr_src;
  98. RPC_U32(&msg, 8U) = (uint32_t)(addr_dst >> 32U);
  99. RPC_U32(&msg, 12U) = (uint32_t)addr_dst;
  100. RPC_U32(&msg, 16U) = (uint32_t)len;
  101. RPC_U8(&msg, 20U) = (uint8_t)fw;
  102. RPC_SIZE(&msg) = 7U;
  103. sc_call_rpc(ipc, &msg, SC_FALSE);
  104. result = RPC_R8(&msg);
  105. return (sc_err_t)result;
  106. }
  107. sc_err_t sc_misc_seco_authenticate(sc_ipc_t ipc,
  108. sc_misc_seco_auth_cmd_t cmd, sc_faddr_t addr)
  109. {
  110. sc_rpc_msg_t msg;
  111. uint8_t result;
  112. RPC_VER(&msg) = SC_RPC_VERSION;
  113. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
  114. RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_SECO_AUTHENTICATE;
  115. RPC_U32(&msg, 0U) = (uint32_t)(addr >> 32U);
  116. RPC_U32(&msg, 4U) = (uint32_t)addr;
  117. RPC_U8(&msg, 8U) = (uint8_t)cmd;
  118. RPC_SIZE(&msg) = 4U;
  119. sc_call_rpc(ipc, &msg, SC_FALSE);
  120. result = RPC_R8(&msg);
  121. return (sc_err_t)result;
  122. }
  123. sc_err_t sc_misc_seco_fuse_write(sc_ipc_t ipc, sc_faddr_t addr)
  124. {
  125. sc_rpc_msg_t msg;
  126. uint8_t result;
  127. RPC_VER(&msg) = SC_RPC_VERSION;
  128. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
  129. RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_SECO_FUSE_WRITE;
  130. RPC_U32(&msg, 0U) = (uint32_t)(addr >> 32U);
  131. RPC_U32(&msg, 4U) = (uint32_t)addr;
  132. RPC_SIZE(&msg) = 3U;
  133. sc_call_rpc(ipc, &msg, SC_FALSE);
  134. result = RPC_R8(&msg);
  135. return (sc_err_t)result;
  136. }
  137. sc_err_t sc_misc_seco_enable_debug(sc_ipc_t ipc, sc_faddr_t addr)
  138. {
  139. sc_rpc_msg_t msg;
  140. uint8_t result;
  141. RPC_VER(&msg) = SC_RPC_VERSION;
  142. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
  143. RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_SECO_ENABLE_DEBUG;
  144. RPC_U32(&msg, 0U) = (uint32_t)(addr >> 32U);
  145. RPC_U32(&msg, 4U) = (uint32_t)addr;
  146. RPC_SIZE(&msg) = 3U;
  147. sc_call_rpc(ipc, &msg, SC_FALSE);
  148. result = RPC_R8(&msg);
  149. return (sc_err_t)result;
  150. }
  151. sc_err_t sc_misc_seco_forward_lifecycle(sc_ipc_t ipc, uint32_t lifecycle)
  152. {
  153. sc_rpc_msg_t msg;
  154. uint8_t result;
  155. RPC_VER(&msg) = SC_RPC_VERSION;
  156. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
  157. RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_SECO_FORWARD_LIFECYCLE;
  158. RPC_U32(&msg, 0U) = (uint32_t)lifecycle;
  159. RPC_SIZE(&msg) = 2U;
  160. sc_call_rpc(ipc, &msg, SC_FALSE);
  161. result = RPC_R8(&msg);
  162. return (sc_err_t)result;
  163. }
  164. sc_err_t sc_misc_seco_return_lifecycle(sc_ipc_t ipc, sc_faddr_t addr)
  165. {
  166. sc_rpc_msg_t msg;
  167. uint8_t result;
  168. RPC_VER(&msg) = SC_RPC_VERSION;
  169. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
  170. RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_SECO_RETURN_LIFECYCLE;
  171. RPC_U32(&msg, 0U) = (uint32_t)(addr >> 32U);
  172. RPC_U32(&msg, 4U) = (uint32_t)addr;
  173. RPC_SIZE(&msg) = 3U;
  174. sc_call_rpc(ipc, &msg, SC_FALSE);
  175. result = RPC_R8(&msg);
  176. return (sc_err_t)result;
  177. }
  178. void sc_misc_seco_build_info(sc_ipc_t ipc, uint32_t *version, uint32_t *commit)
  179. {
  180. sc_rpc_msg_t msg;
  181. RPC_VER(&msg) = SC_RPC_VERSION;
  182. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
  183. RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_SECO_BUILD_INFO;
  184. RPC_SIZE(&msg) = 1U;
  185. sc_call_rpc(ipc, &msg, SC_FALSE);
  186. if (version != NULL)
  187. *version = RPC_U32(&msg, 0U);
  188. if (commit != NULL)
  189. *commit = RPC_U32(&msg, 4U);
  190. }
  191. sc_err_t sc_misc_seco_chip_info(sc_ipc_t ipc, uint16_t *lc,
  192. uint16_t *monotonic, uint32_t *uid_l,
  193. uint32_t *uid_h)
  194. {
  195. sc_rpc_msg_t msg;
  196. uint8_t result;
  197. RPC_VER(&msg) = SC_RPC_VERSION;
  198. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
  199. RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_SECO_CHIP_INFO;
  200. RPC_SIZE(&msg) = 1U;
  201. sc_call_rpc(ipc, &msg, SC_FALSE);
  202. if (uid_l != NULL)
  203. *uid_l = RPC_U32(&msg, 0U);
  204. if (uid_h != NULL)
  205. *uid_h = RPC_U32(&msg, 4U);
  206. if (lc != NULL)
  207. *lc = RPC_U16(&msg, 8U);
  208. if (monotonic != NULL)
  209. *monotonic = RPC_U16(&msg, 10U);
  210. result = RPC_R8(&msg);
  211. return (sc_err_t)result;
  212. }
  213. void sc_misc_debug_out(sc_ipc_t ipc, uint8_t ch)
  214. {
  215. sc_rpc_msg_t msg;
  216. RPC_VER(&msg) = SC_RPC_VERSION;
  217. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
  218. RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_DEBUG_OUT;
  219. RPC_U8(&msg, 0U) = (uint8_t)ch;
  220. RPC_SIZE(&msg) = 2U;
  221. sc_call_rpc(ipc, &msg, SC_FALSE);
  222. }
  223. sc_err_t sc_misc_waveform_capture(sc_ipc_t ipc, sc_bool_t enable)
  224. {
  225. sc_rpc_msg_t msg;
  226. uint8_t result;
  227. RPC_VER(&msg) = SC_RPC_VERSION;
  228. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
  229. RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_WAVEFORM_CAPTURE;
  230. RPC_U8(&msg, 0U) = (uint8_t)enable;
  231. RPC_SIZE(&msg) = 2U;
  232. sc_call_rpc(ipc, &msg, SC_FALSE);
  233. result = RPC_R8(&msg);
  234. return (sc_err_t)result;
  235. }
  236. void sc_misc_build_info(sc_ipc_t ipc, uint32_t *build, uint32_t *commit)
  237. {
  238. sc_rpc_msg_t msg;
  239. RPC_VER(&msg) = SC_RPC_VERSION;
  240. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
  241. RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_BUILD_INFO;
  242. RPC_SIZE(&msg) = 1U;
  243. sc_call_rpc(ipc, &msg, SC_FALSE);
  244. if (build != NULL)
  245. *build = RPC_U32(&msg, 0U);
  246. if (commit != NULL)
  247. *commit = RPC_U32(&msg, 4U);
  248. }
  249. void sc_misc_unique_id(sc_ipc_t ipc, uint32_t *id_l, uint32_t *id_h)
  250. {
  251. sc_rpc_msg_t msg;
  252. RPC_VER(&msg) = SC_RPC_VERSION;
  253. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
  254. RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_UNIQUE_ID;
  255. RPC_SIZE(&msg) = 1U;
  256. sc_call_rpc(ipc, &msg, SC_FALSE);
  257. if (id_l != NULL)
  258. *id_l = RPC_U32(&msg, 0U);
  259. if (id_h != NULL)
  260. *id_h = RPC_U32(&msg, 4U);
  261. }
  262. sc_err_t sc_misc_set_ari(sc_ipc_t ipc, sc_rsrc_t resource,
  263. sc_rsrc_t resource_mst, uint16_t ari, sc_bool_t enable)
  264. {
  265. sc_rpc_msg_t msg;
  266. uint8_t result;
  267. RPC_VER(&msg) = SC_RPC_VERSION;
  268. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
  269. RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_SET_ARI;
  270. RPC_U16(&msg, 0U) = (uint16_t)resource;
  271. RPC_U16(&msg, 2U) = (uint16_t)resource_mst;
  272. RPC_U16(&msg, 4U) = (uint16_t)ari;
  273. RPC_U8(&msg, 6U) = (uint8_t)enable;
  274. RPC_SIZE(&msg) = 3U;
  275. sc_call_rpc(ipc, &msg, SC_FALSE);
  276. result = RPC_R8(&msg);
  277. return (sc_err_t)result;
  278. }
  279. void sc_misc_boot_status(sc_ipc_t ipc, sc_misc_boot_status_t status)
  280. {
  281. sc_rpc_msg_t msg;
  282. RPC_VER(&msg) = SC_RPC_VERSION;
  283. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
  284. RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_BOOT_STATUS;
  285. RPC_U8(&msg, 0U) = (uint8_t)status;
  286. RPC_SIZE(&msg) = 2U;
  287. sc_call_rpc(ipc, &msg, SC_TRUE);
  288. }
  289. sc_err_t sc_misc_boot_done(sc_ipc_t ipc, sc_rsrc_t cpu)
  290. {
  291. sc_rpc_msg_t msg;
  292. uint8_t result;
  293. RPC_VER(&msg) = SC_RPC_VERSION;
  294. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
  295. RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_BOOT_DONE;
  296. RPC_U16(&msg, 0U) = (uint16_t)cpu;
  297. RPC_SIZE(&msg) = 2U;
  298. sc_call_rpc(ipc, &msg, SC_FALSE);
  299. result = RPC_R8(&msg);
  300. return (sc_err_t)result;
  301. }
  302. sc_err_t sc_misc_otp_fuse_read(sc_ipc_t ipc, uint32_t word, uint32_t *val)
  303. {
  304. sc_rpc_msg_t msg;
  305. uint8_t result;
  306. RPC_VER(&msg) = SC_RPC_VERSION;
  307. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
  308. RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_OTP_FUSE_READ;
  309. RPC_U32(&msg, 0U) = (uint32_t)word;
  310. RPC_SIZE(&msg) = 2U;
  311. sc_call_rpc(ipc, &msg, SC_FALSE);
  312. if (val != NULL)
  313. *val = RPC_U32(&msg, 0U);
  314. result = RPC_R8(&msg);
  315. return (sc_err_t)result;
  316. }
  317. sc_err_t sc_misc_otp_fuse_write(sc_ipc_t ipc, uint32_t word, uint32_t val)
  318. {
  319. sc_rpc_msg_t msg;
  320. uint8_t result;
  321. RPC_VER(&msg) = SC_RPC_VERSION;
  322. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
  323. RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_OTP_FUSE_WRITE;
  324. RPC_U32(&msg, 0U) = (uint32_t)word;
  325. RPC_U32(&msg, 4U) = (uint32_t)val;
  326. RPC_SIZE(&msg) = 3U;
  327. sc_call_rpc(ipc, &msg, SC_FALSE);
  328. result = RPC_R8(&msg);
  329. return (sc_err_t)result;
  330. }
  331. sc_err_t sc_misc_set_temp(sc_ipc_t ipc, sc_rsrc_t resource,
  332. sc_misc_temp_t temp, int16_t celsius, int8_t tenths)
  333. {
  334. sc_rpc_msg_t msg;
  335. uint8_t result;
  336. RPC_VER(&msg) = SC_RPC_VERSION;
  337. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
  338. RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_SET_TEMP;
  339. RPC_U16(&msg, 0U) = (uint16_t)resource;
  340. RPC_I16(&msg, 2U) = (int16_t) celsius;
  341. RPC_U8(&msg, 4U) = (uint8_t)temp;
  342. RPC_I8(&msg, 5U) = (int8_t) tenths;
  343. RPC_SIZE(&msg) = 3U;
  344. sc_call_rpc(ipc, &msg, SC_FALSE);
  345. result = RPC_R8(&msg);
  346. return (sc_err_t)result;
  347. }
  348. sc_err_t sc_misc_get_temp(sc_ipc_t ipc, sc_rsrc_t resource,
  349. sc_misc_temp_t temp, int16_t *celsius,
  350. int8_t *tenths)
  351. {
  352. sc_rpc_msg_t msg;
  353. uint8_t result;
  354. RPC_VER(&msg) = SC_RPC_VERSION;
  355. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
  356. RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_GET_TEMP;
  357. RPC_U16(&msg, 0U) = (uint16_t)resource;
  358. RPC_U8(&msg, 2U) = (uint8_t)temp;
  359. RPC_SIZE(&msg) = 2U;
  360. sc_call_rpc(ipc, &msg, SC_FALSE);
  361. if (celsius != NULL)
  362. *celsius = RPC_I16(&msg, 0U);
  363. result = RPC_R8(&msg);
  364. if (tenths != NULL)
  365. *tenths = RPC_I8(&msg, 2U);
  366. return (sc_err_t)result;
  367. }
  368. void sc_misc_get_boot_dev(sc_ipc_t ipc, sc_rsrc_t *dev)
  369. {
  370. sc_rpc_msg_t msg;
  371. RPC_VER(&msg) = SC_RPC_VERSION;
  372. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
  373. RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_GET_BOOT_DEV;
  374. RPC_SIZE(&msg) = 1U;
  375. sc_call_rpc(ipc, &msg, SC_FALSE);
  376. if (dev != NULL)
  377. *dev = RPC_U16(&msg, 0U);
  378. }
  379. void sc_misc_get_button_status(sc_ipc_t ipc, sc_bool_t *status)
  380. {
  381. sc_rpc_msg_t msg;
  382. RPC_VER(&msg) = SC_RPC_VERSION;
  383. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_MISC;
  384. RPC_FUNC(&msg) = (uint8_t)MISC_FUNC_GET_BUTTON_STATUS;
  385. RPC_SIZE(&msg) = 1U;
  386. sc_call_rpc(ipc, &msg, SC_FALSE);
  387. if (status != NULL)
  388. *status = RPC_U8(&msg, 0U);
  389. }
  390. /**@}*/