pm_rpc_clnt.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. /*
  2. * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. /*!
  7. * File containing client-side RPC functions for the PM service. These
  8. * functions are ported to clients that communicate to the SC.
  9. *
  10. * @addtogroup PM_SVC
  11. * @{
  12. */
  13. /* Includes */
  14. #include <stdlib.h>
  15. #include <sci/sci_types.h>
  16. #include <sci/svc/rm/sci_rm_api.h>
  17. #include <sci/svc/pm/sci_pm_api.h>
  18. #include <sci/sci_rpc.h>
  19. #include "sci_pm_rpc.h"
  20. /* Local Defines */
  21. /* Local Types */
  22. /* Local Functions */
  23. sc_err_t sc_pm_set_sys_power_mode(sc_ipc_t ipc, sc_pm_power_mode_t mode)
  24. {
  25. sc_rpc_msg_t msg;
  26. uint8_t result;
  27. RPC_VER(&msg) = SC_RPC_VERSION;
  28. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PM;
  29. RPC_FUNC(&msg) = (uint8_t)PM_FUNC_SET_SYS_POWER_MODE;
  30. RPC_U8(&msg, 0U) = (uint8_t)mode;
  31. RPC_SIZE(&msg) = 2U;
  32. sc_call_rpc(ipc, &msg, SC_FALSE);
  33. result = RPC_R8(&msg);
  34. return (sc_err_t)result;
  35. }
  36. sc_err_t sc_pm_set_partition_power_mode(sc_ipc_t ipc, sc_rm_pt_t pt,
  37. sc_pm_power_mode_t mode)
  38. {
  39. sc_rpc_msg_t msg;
  40. uint8_t result;
  41. RPC_VER(&msg) = SC_RPC_VERSION;
  42. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PM;
  43. RPC_FUNC(&msg) = (uint8_t)PM_FUNC_SET_PARTITION_POWER_MODE;
  44. RPC_U8(&msg, 0U) = (uint8_t)pt;
  45. RPC_U8(&msg, 1U) = (uint8_t)mode;
  46. RPC_SIZE(&msg) = 2U;
  47. sc_call_rpc(ipc, &msg, SC_FALSE);
  48. result = RPC_R8(&msg);
  49. return (sc_err_t)result;
  50. }
  51. sc_err_t sc_pm_get_sys_power_mode(sc_ipc_t ipc, sc_rm_pt_t pt,
  52. sc_pm_power_mode_t *mode)
  53. {
  54. sc_rpc_msg_t msg;
  55. uint8_t result;
  56. RPC_VER(&msg) = SC_RPC_VERSION;
  57. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PM;
  58. RPC_FUNC(&msg) = (uint8_t)PM_FUNC_GET_SYS_POWER_MODE;
  59. RPC_U8(&msg, 0U) = (uint8_t)pt;
  60. RPC_SIZE(&msg) = 2U;
  61. sc_call_rpc(ipc, &msg, SC_FALSE);
  62. result = RPC_R8(&msg);
  63. if (mode != NULL) {
  64. *mode = RPC_U8(&msg, 0U);
  65. }
  66. return (sc_err_t)result;
  67. }
  68. sc_err_t sc_pm_set_resource_power_mode(sc_ipc_t ipc, sc_rsrc_t resource,
  69. sc_pm_power_mode_t mode)
  70. {
  71. sc_rpc_msg_t msg;
  72. uint8_t result;
  73. RPC_VER(&msg) = SC_RPC_VERSION;
  74. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PM;
  75. RPC_FUNC(&msg) = (uint8_t)PM_FUNC_SET_RESOURCE_POWER_MODE;
  76. RPC_U16(&msg, 0U) = (uint16_t)resource;
  77. RPC_U8(&msg, 2U) = (uint8_t)mode;
  78. RPC_SIZE(&msg) = 2U;
  79. sc_call_rpc(ipc, &msg, SC_FALSE);
  80. result = RPC_R8(&msg);
  81. return (sc_err_t)result;
  82. }
  83. sc_err_t sc_pm_get_resource_power_mode(sc_ipc_t ipc, sc_rsrc_t resource,
  84. sc_pm_power_mode_t *mode)
  85. {
  86. sc_rpc_msg_t msg;
  87. uint8_t result;
  88. RPC_VER(&msg) = SC_RPC_VERSION;
  89. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PM;
  90. RPC_FUNC(&msg) = (uint8_t)PM_FUNC_GET_RESOURCE_POWER_MODE;
  91. RPC_U16(&msg, 0U) = (uint16_t)resource;
  92. RPC_SIZE(&msg) = 2U;
  93. sc_call_rpc(ipc, &msg, SC_FALSE);
  94. result = RPC_R8(&msg);
  95. if (mode != NULL) {
  96. *mode = RPC_U8(&msg, 0U);
  97. }
  98. return (sc_err_t)result;
  99. }
  100. sc_err_t sc_pm_req_low_power_mode(sc_ipc_t ipc, sc_rsrc_t resource,
  101. sc_pm_power_mode_t mode)
  102. {
  103. sc_rpc_msg_t msg;
  104. uint8_t result;
  105. RPC_VER(&msg) = SC_RPC_VERSION;
  106. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PM;
  107. RPC_FUNC(&msg) = (uint8_t)PM_FUNC_REQ_LOW_POWER_MODE;
  108. RPC_U16(&msg, 0U) = (uint16_t)resource;
  109. RPC_U8(&msg, 2U) = (uint8_t)mode;
  110. RPC_SIZE(&msg) = 2U;
  111. sc_call_rpc(ipc, &msg, SC_FALSE);
  112. result = RPC_R8(&msg);
  113. return (sc_err_t)result;
  114. }
  115. sc_err_t sc_pm_req_cpu_low_power_mode(sc_ipc_t ipc, sc_rsrc_t resource,
  116. sc_pm_power_mode_t mode,
  117. sc_pm_wake_src_t wake_src)
  118. {
  119. sc_rpc_msg_t msg;
  120. uint8_t result;
  121. RPC_VER(&msg) = SC_RPC_VERSION;
  122. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PM;
  123. RPC_FUNC(&msg) = (uint8_t)PM_FUNC_REQ_CPU_LOW_POWER_MODE;
  124. RPC_U16(&msg, 0U) = (uint16_t)resource;
  125. RPC_U8(&msg, 2U) = (uint8_t)mode;
  126. RPC_U8(&msg, 3U) = (uint8_t)wake_src;
  127. RPC_SIZE(&msg) = 2U;
  128. sc_call_rpc(ipc, &msg, SC_FALSE);
  129. result = RPC_R8(&msg);
  130. return (sc_err_t)result;
  131. }
  132. sc_err_t sc_pm_set_cpu_resume_addr(sc_ipc_t ipc, sc_rsrc_t resource,
  133. sc_faddr_t address)
  134. {
  135. sc_rpc_msg_t msg;
  136. uint8_t result;
  137. RPC_VER(&msg) = SC_RPC_VERSION;
  138. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PM;
  139. RPC_FUNC(&msg) = (uint8_t)PM_FUNC_SET_CPU_RESUME_ADDR;
  140. RPC_U32(&msg, 0U) = (uint32_t)(address >> 32U);
  141. RPC_U32(&msg, 4U) = (uint32_t)address;
  142. RPC_U16(&msg, 8U) = (uint16_t)resource;
  143. RPC_SIZE(&msg) = 4U;
  144. sc_call_rpc(ipc, &msg, SC_FALSE);
  145. result = RPC_R8(&msg);
  146. return (sc_err_t)result;
  147. }
  148. sc_err_t sc_pm_set_cpu_resume(sc_ipc_t ipc, sc_rsrc_t resource,
  149. sc_bool_t isPrimary, sc_faddr_t address)
  150. {
  151. sc_rpc_msg_t msg;
  152. uint8_t result;
  153. RPC_VER(&msg) = SC_RPC_VERSION;
  154. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PM;
  155. RPC_FUNC(&msg) = (uint8_t)PM_FUNC_SET_CPU_RESUME;
  156. RPC_U32(&msg, 0U) = (uint32_t)(address >> 32U);
  157. RPC_U32(&msg, 4U) = (uint32_t)address;
  158. RPC_U16(&msg, 8U) = (uint16_t)resource;
  159. RPC_U8(&msg, 10U) = (uint8_t)isPrimary;
  160. RPC_SIZE(&msg) = 4U;
  161. sc_call_rpc(ipc, &msg, SC_FALSE);
  162. result = RPC_R8(&msg);
  163. return (sc_err_t)result;
  164. }
  165. sc_err_t sc_pm_req_sys_if_power_mode(sc_ipc_t ipc, sc_rsrc_t resource,
  166. sc_pm_sys_if_t sys_if,
  167. sc_pm_power_mode_t hpm,
  168. sc_pm_power_mode_t lpm)
  169. {
  170. sc_rpc_msg_t msg;
  171. uint8_t result;
  172. RPC_VER(&msg) = SC_RPC_VERSION;
  173. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PM;
  174. RPC_FUNC(&msg) = (uint8_t)PM_FUNC_REQ_SYS_IF_POWER_MODE;
  175. RPC_U16(&msg, 0U) = (uint16_t)resource;
  176. RPC_U8(&msg, 2U) = (uint8_t)sys_if;
  177. RPC_U8(&msg, 3U) = (uint8_t)hpm;
  178. RPC_U8(&msg, 4U) = (uint8_t)lpm;
  179. RPC_SIZE(&msg) = 3U;
  180. sc_call_rpc(ipc, &msg, SC_FALSE);
  181. result = RPC_R8(&msg);
  182. return (sc_err_t)result;
  183. }
  184. sc_err_t sc_pm_set_clock_rate(sc_ipc_t ipc, sc_rsrc_t resource,
  185. sc_pm_clk_t clk, sc_pm_clock_rate_t *rate)
  186. {
  187. sc_rpc_msg_t msg;
  188. uint8_t result;
  189. RPC_VER(&msg) = SC_RPC_VERSION;
  190. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PM;
  191. RPC_FUNC(&msg) = (uint8_t)PM_FUNC_SET_CLOCK_RATE;
  192. RPC_U32(&msg, 0U) = *(uint32_t *)rate;
  193. RPC_U16(&msg, 4U) = (uint16_t)resource;
  194. RPC_U8(&msg, 6U) = (uint8_t)clk;
  195. RPC_SIZE(&msg) = 3U;
  196. sc_call_rpc(ipc, &msg, SC_FALSE);
  197. *rate = RPC_U32(&msg, 0U);
  198. result = RPC_R8(&msg);
  199. return (sc_err_t)result;
  200. }
  201. sc_err_t sc_pm_get_clock_rate(sc_ipc_t ipc, sc_rsrc_t resource,
  202. sc_pm_clk_t clk, sc_pm_clock_rate_t *rate)
  203. {
  204. sc_rpc_msg_t msg;
  205. uint8_t result;
  206. RPC_VER(&msg) = SC_RPC_VERSION;
  207. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PM;
  208. RPC_FUNC(&msg) = (uint8_t)PM_FUNC_GET_CLOCK_RATE;
  209. RPC_U16(&msg, 0U) = (uint16_t)resource;
  210. RPC_U8(&msg, 2U) = (uint8_t)clk;
  211. RPC_SIZE(&msg) = 2U;
  212. sc_call_rpc(ipc, &msg, SC_FALSE);
  213. if (rate != NULL) {
  214. *rate = RPC_U32(&msg, 0U);
  215. }
  216. result = RPC_R8(&msg);
  217. return (sc_err_t)result;
  218. }
  219. sc_err_t sc_pm_clock_enable(sc_ipc_t ipc, sc_rsrc_t resource,
  220. sc_pm_clk_t clk, sc_bool_t enable, sc_bool_t autog)
  221. {
  222. sc_rpc_msg_t msg;
  223. uint8_t result;
  224. RPC_VER(&msg) = SC_RPC_VERSION;
  225. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PM;
  226. RPC_FUNC(&msg) = (uint8_t)PM_FUNC_CLOCK_ENABLE;
  227. RPC_U16(&msg, 0U) = (uint16_t)resource;
  228. RPC_U8(&msg, 2U) = (uint8_t)clk;
  229. RPC_U8(&msg, 3U) = (uint8_t)enable;
  230. RPC_U8(&msg, 4U) = (uint8_t)autog;
  231. RPC_SIZE(&msg) = 3U;
  232. sc_call_rpc(ipc, &msg, SC_FALSE);
  233. result = RPC_R8(&msg);
  234. return (sc_err_t)result;
  235. }
  236. sc_err_t sc_pm_set_clock_parent(sc_ipc_t ipc, sc_rsrc_t resource,
  237. sc_pm_clk_t clk, sc_pm_clk_parent_t parent)
  238. {
  239. sc_rpc_msg_t msg;
  240. uint8_t result;
  241. RPC_VER(&msg) = SC_RPC_VERSION;
  242. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PM;
  243. RPC_FUNC(&msg) = (uint8_t)PM_FUNC_SET_CLOCK_PARENT;
  244. RPC_U16(&msg, 0U) = (uint16_t)resource;
  245. RPC_U8(&msg, 2U) = (uint8_t)clk;
  246. RPC_U8(&msg, 3U) = (uint8_t)parent;
  247. RPC_SIZE(&msg) = 2U;
  248. sc_call_rpc(ipc, &msg, SC_FALSE);
  249. result = RPC_R8(&msg);
  250. return (sc_err_t)result;
  251. }
  252. sc_err_t sc_pm_get_clock_parent(sc_ipc_t ipc, sc_rsrc_t resource,
  253. sc_pm_clk_t clk, sc_pm_clk_parent_t *parent)
  254. {
  255. sc_rpc_msg_t msg;
  256. uint8_t result;
  257. RPC_VER(&msg) = SC_RPC_VERSION;
  258. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PM;
  259. RPC_FUNC(&msg) = (uint8_t)PM_FUNC_GET_CLOCK_PARENT;
  260. RPC_U16(&msg, 0U) = (uint16_t)resource;
  261. RPC_U8(&msg, 2U) = (uint8_t)clk;
  262. RPC_SIZE(&msg) = 2U;
  263. sc_call_rpc(ipc, &msg, SC_FALSE);
  264. result = RPC_R8(&msg);
  265. if (parent != NULL) {
  266. *parent = RPC_U8(&msg, 0U);
  267. }
  268. return (sc_err_t)result;
  269. }
  270. sc_err_t sc_pm_reset(sc_ipc_t ipc, sc_pm_reset_type_t type)
  271. {
  272. sc_rpc_msg_t msg;
  273. uint8_t result;
  274. RPC_VER(&msg) = SC_RPC_VERSION;
  275. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PM;
  276. RPC_FUNC(&msg) = (uint8_t)PM_FUNC_RESET;
  277. RPC_U8(&msg, 0U) = (uint8_t)type;
  278. RPC_SIZE(&msg) = 2U;
  279. sc_call_rpc(ipc, &msg, SC_FALSE);
  280. result = RPC_R8(&msg);
  281. return (sc_err_t)result;
  282. }
  283. sc_err_t sc_pm_reset_reason(sc_ipc_t ipc, sc_pm_reset_reason_t *reason)
  284. {
  285. sc_rpc_msg_t msg;
  286. uint8_t result;
  287. RPC_VER(&msg) = SC_RPC_VERSION;
  288. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PM;
  289. RPC_FUNC(&msg) = (uint8_t)PM_FUNC_RESET_REASON;
  290. RPC_SIZE(&msg) = 1U;
  291. sc_call_rpc(ipc, &msg, SC_FALSE);
  292. result = RPC_R8(&msg);
  293. if (reason != NULL) {
  294. *reason = RPC_U8(&msg, 0U);
  295. }
  296. return (sc_err_t)result;
  297. }
  298. sc_err_t sc_pm_boot(sc_ipc_t ipc, sc_rm_pt_t pt,
  299. sc_rsrc_t resource_cpu, sc_faddr_t boot_addr,
  300. sc_rsrc_t resource_mu, sc_rsrc_t resource_dev)
  301. {
  302. sc_rpc_msg_t msg;
  303. uint8_t result;
  304. RPC_VER(&msg) = SC_RPC_VERSION;
  305. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PM;
  306. RPC_FUNC(&msg) = (uint8_t)PM_FUNC_BOOT;
  307. RPC_U32(&msg, 0U) = (uint32_t)(boot_addr >> 32U);
  308. RPC_U32(&msg, 4U) = (uint32_t)boot_addr;
  309. RPC_U16(&msg, 8U) = (uint16_t)resource_cpu;
  310. RPC_U16(&msg, 10U) = (uint16_t)resource_mu;
  311. RPC_U16(&msg, 12U) = (uint16_t)resource_dev;
  312. RPC_U8(&msg, 14U) = (uint8_t)pt;
  313. RPC_SIZE(&msg) = 5U;
  314. sc_call_rpc(ipc, &msg, SC_FALSE);
  315. result = RPC_R8(&msg);
  316. return (sc_err_t)result;
  317. }
  318. void sc_pm_reboot(sc_ipc_t ipc, sc_pm_reset_type_t type)
  319. {
  320. sc_rpc_msg_t msg;
  321. RPC_VER(&msg) = SC_RPC_VERSION;
  322. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PM;
  323. RPC_FUNC(&msg) = (uint8_t)PM_FUNC_REBOOT;
  324. RPC_U8(&msg, 0U) = (uint8_t)type;
  325. RPC_SIZE(&msg) = 2U;
  326. sc_call_rpc(ipc, &msg, SC_TRUE);
  327. }
  328. sc_err_t sc_pm_reboot_partition(sc_ipc_t ipc, sc_rm_pt_t pt,
  329. sc_pm_reset_type_t type)
  330. {
  331. sc_rpc_msg_t msg;
  332. uint8_t result;
  333. RPC_VER(&msg) = SC_RPC_VERSION;
  334. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PM;
  335. RPC_FUNC(&msg) = (uint8_t)PM_FUNC_REBOOT_PARTITION;
  336. RPC_U8(&msg, 0U) = (uint8_t)pt;
  337. RPC_U8(&msg, 1U) = (uint8_t)type;
  338. RPC_SIZE(&msg) = 2U;
  339. sc_call_rpc(ipc, &msg, SC_FALSE);
  340. result = RPC_R8(&msg);
  341. return (sc_err_t)result;
  342. }
  343. sc_err_t sc_pm_cpu_start(sc_ipc_t ipc, sc_rsrc_t resource, sc_bool_t enable,
  344. sc_faddr_t address)
  345. {
  346. sc_rpc_msg_t msg;
  347. uint8_t result;
  348. RPC_VER(&msg) = SC_RPC_VERSION;
  349. RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PM;
  350. RPC_FUNC(&msg) = (uint8_t)PM_FUNC_CPU_START;
  351. RPC_U32(&msg, 0U) = (uint32_t)(address >> 32U);
  352. RPC_U32(&msg, 4U) = (uint32_t)address;
  353. RPC_U16(&msg, 8U) = (uint16_t)resource;
  354. RPC_U8(&msg, 10U) = (uint8_t)enable;
  355. RPC_SIZE(&msg) = 4U;
  356. sc_call_rpc(ipc, &msg, SC_FALSE);
  357. result = RPC_R8(&msg);
  358. return (sc_err_t)result;
  359. }
  360. /**@}*/