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