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