sci_rpc.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. /*!
  7. * Header file for the RPC implementation.
  8. */
  9. #ifndef SCI_RPC_H
  10. #define SCI_RPC_H
  11. /* Includes */
  12. #include <stdbool.h>
  13. #include <sci/sci_types.h>
  14. #include <sci/sci_ipc.h>
  15. /* Defines */
  16. #define SC_RPC_VERSION 1U
  17. #define SC_RPC_MAX_MSG 8U
  18. #define RPC_VER(MSG) ((MSG)->version)
  19. #define RPC_SIZE(MSG) ((MSG)->size)
  20. #define RPC_SVC(MSG) ((MSG)->svc)
  21. #define RPC_FUNC(MSG) ((MSG)->func)
  22. #define RPC_R8(MSG) ((MSG)->func)
  23. #define RPC_I32(MSG, IDX) ((MSG)->DATA.i32[(IDX) / 4U])
  24. #define RPC_I16(MSG, IDX) ((MSG)->DATA.i16[(IDX) / 2U])
  25. #define RPC_I8(MSG, IDX) ((MSG)->DATA.i8[(IDX)])
  26. #define RPC_U32(MSG, IDX) ((MSG)->DATA.u32[(IDX) / 4U])
  27. #define RPC_U16(MSG, IDX) ((MSG)->DATA.u16[(IDX) / 2U])
  28. #define RPC_U8(MSG, IDX) ((MSG)->DATA.u8[(IDX)])
  29. #define SC_RPC_SVC_UNKNOWN 0U
  30. #define SC_RPC_SVC_RETURN 1U
  31. #define SC_RPC_SVC_PM 2U
  32. #define SC_RPC_SVC_RM 3U
  33. #define SC_RPC_SVC_TIMER 5U
  34. #define SC_RPC_SVC_PAD 6U
  35. #define SC_RPC_SVC_MISC 7U
  36. #define SC_RPC_SVC_IRQ 8U
  37. #define SC_RPC_SVC_ABORT 9U
  38. #define SC_RPC_ASYNC_STATE_RD_START 0U
  39. #define SC_RPC_ASYNC_STATE_RD_ACTIVE 1U
  40. #define SC_RPC_ASYNC_STATE_RD_DONE 2U
  41. #define SC_RPC_ASYNC_STATE_WR_START 3U
  42. #define SC_RPC_ASYNC_STATE_WR_ACTIVE 4U
  43. #define SC_RPC_ASYNC_STATE_WR_DONE 5U
  44. #define SC_RPC_MU_GIR_SVC 0x1U
  45. #define SC_RPC_MU_GIR_DBG 0x8U
  46. /* Types */
  47. typedef uint8_t sc_rpc_svc_t;
  48. typedef struct sc_rpc_msg_s {
  49. uint8_t version;
  50. uint8_t size;
  51. uint8_t svc;
  52. uint8_t func;
  53. union {
  54. int32_t i32[(SC_RPC_MAX_MSG - 1U)];
  55. int16_t i16[(SC_RPC_MAX_MSG - 1U) * 2U];
  56. int8_t i8[(SC_RPC_MAX_MSG - 1U) * 4U];
  57. uint32_t u32[(SC_RPC_MAX_MSG - 1U)];
  58. uint16_t u16[(SC_RPC_MAX_MSG - 1U) * 2U];
  59. uint8_t u8[(SC_RPC_MAX_MSG - 1U) * 4U];
  60. } DATA;
  61. } sc_rpc_msg_t;
  62. typedef uint8_t sc_rpc_async_state_t;
  63. typedef struct sc_rpc_async_msg_s {
  64. sc_rpc_async_state_t state;
  65. uint8_t wordIdx;
  66. sc_rpc_msg_t msg;
  67. uint32_t timeStamp;
  68. } sc_rpc_async_msg_t;
  69. /* Functions */
  70. /*!
  71. * This is an internal function to send an RPC message over an IPC
  72. * channel. It is called by client-side SCFW API function shims.
  73. *
  74. * @param[in] ipc IPC handle
  75. * @param[in,out] msg handle to a message
  76. * @param[in] no_resp response flag
  77. *
  78. * If \a no_resp is SC_FALSE then this function waits for a response
  79. * and returns the result in \a msg.
  80. */
  81. void sc_call_rpc(sc_ipc_t ipc, sc_rpc_msg_t *msg, bool no_resp);
  82. /*!
  83. * This is an internal function to dispatch an RPC call that has
  84. * arrived via IPC over an MU. It is called by server-side SCFW.
  85. *
  86. * @param[in] mu MU message arrived on
  87. * @param[in,out] msg handle to a message
  88. *
  89. * The function result is returned in \a msg.
  90. */
  91. void sc_rpc_dispatch(sc_rsrc_t mu, sc_rpc_msg_t *msg);
  92. /*!
  93. * This function translates an RPC message and forwards on to the
  94. * normal RPC API. It is used only by hypervisors.
  95. *
  96. * @param[in] ipc IPC handle
  97. * @param[in,out] msg handle to a message
  98. *
  99. * This function decodes a message, calls macros to translate the
  100. * resources, pads, addresses, partitions, memory regions, etc. and
  101. * then forwards on to the hypervisors SCFW API.Return results are
  102. * translated back abd placed back into the message to be returned
  103. * to the original API.
  104. */
  105. void sc_rpc_xlate(sc_ipc_t ipc, sc_rpc_msg_t *msg);
  106. #endif /* SCI_RPC_H */