2 * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
4 * SPDX-License-Identifier: BSD-3-Clause
8 * File containing client-side RPC functions for the RM service. These
9 * functions are ported to clients that communicate to the SC.
19 #include <sci/sci_types.h>
20 #include <sci/svc/rm/sci_rm_api.h>
21 #include <sci/sci_rpc.h>
23 #include "sci_rm_rpc.h"
31 sc_err_t
sc_rm_partition_alloc(sc_ipc_t ipc
, sc_rm_pt_t
*pt
, sc_bool_t secure
,
32 sc_bool_t isolated
, sc_bool_t restricted
,
33 sc_bool_t grant
, sc_bool_t coherent
)
38 RPC_VER(&msg
) = SC_RPC_VERSION
;
39 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_RM
;
40 RPC_FUNC(&msg
) = (uint8_t)RM_FUNC_PARTITION_ALLOC
;
41 RPC_U8(&msg
, 0U) = (uint8_t)secure
;
42 RPC_U8(&msg
, 1U) = (uint8_t)isolated
;
43 RPC_U8(&msg
, 2U) = (uint8_t)restricted
;
44 RPC_U8(&msg
, 3U) = (uint8_t)grant
;
45 RPC_U8(&msg
, 4U) = (uint8_t)coherent
;
48 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
50 result
= RPC_R8(&msg
);
52 *pt
= RPC_U8(&msg
, 0U);
55 return (sc_err_t
)result
;
58 sc_err_t
sc_rm_set_confidential(sc_ipc_t ipc
, sc_rm_pt_t pt
, sc_bool_t retro
)
63 RPC_VER(&msg
) = SC_RPC_VERSION
;
64 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_RM
;
65 RPC_FUNC(&msg
) = (uint8_t)RM_FUNC_SET_CONFIDENTIAL
;
66 RPC_U8(&msg
, 0U) = (uint8_t)pt
;
67 RPC_U8(&msg
, 1U) = (uint8_t)retro
;
70 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
72 result
= RPC_R8(&msg
);
73 return (sc_err_t
)result
;
76 sc_err_t
sc_rm_partition_free(sc_ipc_t ipc
, sc_rm_pt_t pt
)
81 RPC_VER(&msg
) = SC_RPC_VERSION
;
82 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_RM
;
83 RPC_FUNC(&msg
) = (uint8_t)RM_FUNC_PARTITION_FREE
;
84 RPC_U8(&msg
, 0U) = (uint8_t)pt
;
87 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
89 result
= RPC_R8(&msg
);
90 return (sc_err_t
)result
;
93 sc_rm_did_t
sc_rm_get_did(sc_ipc_t ipc
)
98 RPC_VER(&msg
) = SC_RPC_VERSION
;
99 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_RM
;
100 RPC_FUNC(&msg
) = (uint8_t)RM_FUNC_GET_DID
;
103 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
105 result
= RPC_R8(&msg
);
106 return (sc_rm_did_t
) result
;
109 sc_err_t
sc_rm_partition_static(sc_ipc_t ipc
, sc_rm_pt_t pt
, sc_rm_did_t did
)
114 RPC_VER(&msg
) = SC_RPC_VERSION
;
115 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_RM
;
116 RPC_FUNC(&msg
) = (uint8_t)RM_FUNC_PARTITION_STATIC
;
117 RPC_U8(&msg
, 0U) = (uint8_t)pt
;
118 RPC_U8(&msg
, 1U) = (uint8_t)did
;
121 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
123 result
= RPC_R8(&msg
);
124 return (sc_err_t
)result
;
127 sc_err_t
sc_rm_partition_lock(sc_ipc_t ipc
, sc_rm_pt_t pt
)
132 RPC_VER(&msg
) = SC_RPC_VERSION
;
133 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_RM
;
134 RPC_FUNC(&msg
) = (uint8_t)RM_FUNC_PARTITION_LOCK
;
135 RPC_U8(&msg
, 0U) = (uint8_t)pt
;
138 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
140 result
= RPC_R8(&msg
);
141 return (sc_err_t
)result
;
144 sc_err_t
sc_rm_get_partition(sc_ipc_t ipc
, sc_rm_pt_t
*pt
)
149 RPC_VER(&msg
) = SC_RPC_VERSION
;
150 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_RM
;
151 RPC_FUNC(&msg
) = (uint8_t)RM_FUNC_GET_PARTITION
;
154 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
156 result
= RPC_R8(&msg
);
158 *pt
= RPC_U8(&msg
, 0U);
161 return (sc_err_t
)result
;
164 sc_err_t
sc_rm_set_parent(sc_ipc_t ipc
, sc_rm_pt_t pt
, sc_rm_pt_t pt_parent
)
169 RPC_VER(&msg
) = SC_RPC_VERSION
;
170 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_RM
;
171 RPC_FUNC(&msg
) = (uint8_t)RM_FUNC_SET_PARENT
;
172 RPC_U8(&msg
, 0U) = (uint8_t)pt
;
173 RPC_U8(&msg
, 1U) = (uint8_t)pt_parent
;
176 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
178 result
= RPC_R8(&msg
);
179 return (sc_err_t
)result
;
182 sc_err_t
sc_rm_move_all(sc_ipc_t ipc
, sc_rm_pt_t pt_src
, sc_rm_pt_t pt_dst
,
183 sc_bool_t move_rsrc
, sc_bool_t move_pads
)
188 RPC_VER(&msg
) = SC_RPC_VERSION
;
189 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_RM
;
190 RPC_FUNC(&msg
) = (uint8_t)RM_FUNC_MOVE_ALL
;
191 RPC_U8(&msg
, 0U) = (uint8_t)pt_src
;
192 RPC_U8(&msg
, 1U) = (uint8_t)pt_dst
;
193 RPC_U8(&msg
, 2U) = (uint8_t)move_rsrc
;
194 RPC_U8(&msg
, 3U) = (uint8_t)move_pads
;
197 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
199 result
= RPC_R8(&msg
);
200 return (sc_err_t
)result
;
203 sc_err_t
sc_rm_assign_resource(sc_ipc_t ipc
, sc_rm_pt_t pt
, sc_rsrc_t resource
)
208 RPC_VER(&msg
) = SC_RPC_VERSION
;
209 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_RM
;
210 RPC_FUNC(&msg
) = (uint8_t)RM_FUNC_ASSIGN_RESOURCE
;
211 RPC_U16(&msg
, 0U) = (uint16_t)resource
;
212 RPC_U8(&msg
, 2U) = (uint8_t)pt
;
215 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
217 result
= RPC_R8(&msg
);
218 return (sc_err_t
)result
;
221 sc_err_t
sc_rm_set_resource_movable(sc_ipc_t ipc
, sc_rsrc_t resource_fst
,
222 sc_rsrc_t resource_lst
, sc_bool_t movable
)
227 RPC_VER(&msg
) = SC_RPC_VERSION
;
228 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_RM
;
229 RPC_FUNC(&msg
) = (uint8_t)RM_FUNC_SET_RESOURCE_MOVABLE
;
230 RPC_U16(&msg
, 0U) = (uint16_t)resource_fst
;
231 RPC_U16(&msg
, 2U) = (uint16_t)resource_lst
;
232 RPC_U8(&msg
, 4U) = (uint8_t)movable
;
235 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
237 result
= RPC_R8(&msg
);
238 return (sc_err_t
)result
;
241 sc_err_t
sc_rm_set_subsys_rsrc_movable(sc_ipc_t ipc
, sc_rsrc_t resource
,
247 RPC_VER(&msg
) = SC_RPC_VERSION
;
248 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_RM
;
249 RPC_FUNC(&msg
) = (uint8_t)RM_FUNC_SET_SUBSYS_RSRC_MOVABLE
;
250 RPC_U16(&msg
, 0U) = (uint16_t)resource
;
251 RPC_U8(&msg
, 2U) = (uint8_t)movable
;
254 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
256 result
= RPC_R8(&msg
);
257 return (sc_err_t
)result
;
260 sc_err_t
sc_rm_set_master_attributes(sc_ipc_t ipc
, sc_rsrc_t resource
,
261 sc_rm_spa_t sa
, sc_rm_spa_t pa
,
262 sc_bool_t smmu_bypass
)
267 RPC_VER(&msg
) = SC_RPC_VERSION
;
268 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_RM
;
269 RPC_FUNC(&msg
) = (uint8_t)RM_FUNC_SET_MASTER_ATTRIBUTES
;
270 RPC_U16(&msg
, 0U) = (uint16_t)resource
;
271 RPC_U8(&msg
, 2U) = (uint8_t)sa
;
272 RPC_U8(&msg
, 3U) = (uint8_t)pa
;
273 RPC_U8(&msg
, 4U) = (uint8_t)smmu_bypass
;
276 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
278 result
= RPC_R8(&msg
);
279 return (sc_err_t
)result
;
282 sc_err_t
sc_rm_set_master_sid(sc_ipc_t ipc
, sc_rsrc_t resource
, sc_rm_sid_t sid
)
287 RPC_VER(&msg
) = SC_RPC_VERSION
;
288 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_RM
;
289 RPC_FUNC(&msg
) = (uint8_t)RM_FUNC_SET_MASTER_SID
;
290 RPC_U16(&msg
, 0U) = (uint16_t)resource
;
291 RPC_U16(&msg
, 2U) = (uint16_t)sid
;
294 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
296 result
= RPC_R8(&msg
);
297 return (sc_err_t
)result
;
300 sc_err_t
sc_rm_set_peripheral_permissions(sc_ipc_t ipc
, sc_rsrc_t resource
,
301 sc_rm_pt_t pt
, sc_rm_perm_t perm
)
306 RPC_VER(&msg
) = SC_RPC_VERSION
;
307 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_RM
;
308 RPC_FUNC(&msg
) = (uint8_t)RM_FUNC_SET_PERIPHERAL_PERMISSIONS
;
309 RPC_U16(&msg
, 0U) = (uint16_t)resource
;
310 RPC_U8(&msg
, 2U) = (uint8_t)pt
;
311 RPC_U8(&msg
, 3U) = (uint8_t)perm
;
314 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
316 result
= RPC_R8(&msg
);
317 return (sc_err_t
)result
;
320 sc_bool_t
sc_rm_is_resource_owned(sc_ipc_t ipc
, sc_rsrc_t resource
)
325 RPC_VER(&msg
) = SC_RPC_VERSION
;
326 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_RM
;
327 RPC_FUNC(&msg
) = (uint8_t)RM_FUNC_IS_RESOURCE_OWNED
;
328 RPC_U16(&msg
, 0U) = (uint16_t)resource
;
331 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
333 result
= RPC_R8(&msg
);
334 return (sc_bool_t
)result
;
337 sc_bool_t
sc_rm_is_resource_master(sc_ipc_t ipc
, sc_rsrc_t resource
)
342 RPC_VER(&msg
) = SC_RPC_VERSION
;
343 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_RM
;
344 RPC_FUNC(&msg
) = (uint8_t)RM_FUNC_IS_RESOURCE_MASTER
;
345 RPC_U16(&msg
, 0U) = (uint16_t)resource
;
348 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
350 result
= RPC_R8(&msg
);
351 return (sc_bool_t
)result
;
354 sc_bool_t
sc_rm_is_resource_peripheral(sc_ipc_t ipc
, sc_rsrc_t resource
)
359 RPC_VER(&msg
) = SC_RPC_VERSION
;
360 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_RM
;
361 RPC_FUNC(&msg
) = (uint8_t)RM_FUNC_IS_RESOURCE_PERIPHERAL
;
362 RPC_U16(&msg
, 0U) = (uint16_t)resource
;
365 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
367 result
= RPC_R8(&msg
);
368 return (sc_bool_t
)result
;
371 sc_err_t
sc_rm_get_resource_info(sc_ipc_t ipc
, sc_rsrc_t resource
,
377 RPC_VER(&msg
) = SC_RPC_VERSION
;
378 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_RM
;
379 RPC_FUNC(&msg
) = (uint8_t)RM_FUNC_GET_RESOURCE_INFO
;
380 RPC_U16(&msg
, 0U) = (uint16_t)resource
;
383 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
386 *sid
= RPC_U16(&msg
, 0U);
389 result
= RPC_R8(&msg
);
390 return (sc_err_t
)result
;
393 sc_err_t
sc_rm_memreg_alloc(sc_ipc_t ipc
, sc_rm_mr_t
*mr
,
394 sc_faddr_t addr_start
, sc_faddr_t addr_end
)
399 RPC_VER(&msg
) = SC_RPC_VERSION
;
400 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_RM
;
401 RPC_FUNC(&msg
) = (uint8_t)RM_FUNC_MEMREG_ALLOC
;
402 RPC_U32(&msg
, 0U) = (uint32_t)(addr_start
>> 32U);
403 RPC_U32(&msg
, 4U) = (uint32_t)addr_start
;
404 RPC_U32(&msg
, 8U) = (uint32_t)(addr_end
>> 32U);
405 RPC_U32(&msg
, 12U) = (uint32_t)addr_end
;
408 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
410 result
= RPC_R8(&msg
);
412 *mr
= RPC_U8(&msg
, 0U);
415 return (sc_err_t
)result
;
418 sc_err_t
sc_rm_memreg_split(sc_ipc_t ipc
, sc_rm_mr_t mr
,
419 sc_rm_mr_t
*mr_ret
, sc_faddr_t addr_start
,
425 RPC_VER(&msg
) = SC_RPC_VERSION
;
426 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_RM
;
427 RPC_FUNC(&msg
) = (uint8_t)RM_FUNC_MEMREG_SPLIT
;
428 RPC_U32(&msg
, 0U) = (uint32_t)(addr_start
>> 32U);
429 RPC_U32(&msg
, 4U) = (uint32_t)addr_start
;
430 RPC_U32(&msg
, 8U) = (uint32_t)(addr_end
>> 32U);
431 RPC_U32(&msg
, 12U) = (uint32_t)addr_end
;
432 RPC_U8(&msg
, 16U) = (uint8_t)mr
;
435 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
437 result
= RPC_R8(&msg
);
438 if (mr_ret
!= NULL
) {
439 *mr_ret
= RPC_U8(&msg
, 0U);
442 return (sc_err_t
)result
;
445 sc_err_t
sc_rm_memreg_free(sc_ipc_t ipc
, sc_rm_mr_t mr
)
450 RPC_VER(&msg
) = SC_RPC_VERSION
;
451 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_RM
;
452 RPC_FUNC(&msg
) = (uint8_t)RM_FUNC_MEMREG_FREE
;
453 RPC_U8(&msg
, 0U) = (uint8_t)mr
;
456 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
458 result
= RPC_R8(&msg
);
459 return (sc_err_t
)result
;
462 sc_err_t
sc_rm_find_memreg(sc_ipc_t ipc
, sc_rm_mr_t
*mr
,
463 sc_faddr_t addr_start
, sc_faddr_t addr_end
)
468 RPC_VER(&msg
) = SC_RPC_VERSION
;
469 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_RM
;
470 RPC_FUNC(&msg
) = (uint8_t)RM_FUNC_FIND_MEMREG
;
471 RPC_U32(&msg
, 0U) = (uint32_t)(addr_start
>> 32U);
472 RPC_U32(&msg
, 4U) = (uint32_t)addr_start
;
473 RPC_U32(&msg
, 8U) = (uint32_t)(addr_end
>> 32U);
474 RPC_U32(&msg
, 12U) = (uint32_t)addr_end
;
477 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
479 result
= RPC_R8(&msg
);
481 *mr
= RPC_U8(&msg
, 0U);
484 return (sc_err_t
)result
;
487 sc_err_t
sc_rm_assign_memreg(sc_ipc_t ipc
, sc_rm_pt_t pt
, sc_rm_mr_t mr
)
492 RPC_VER(&msg
) = SC_RPC_VERSION
;
493 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_RM
;
494 RPC_FUNC(&msg
) = (uint8_t)RM_FUNC_ASSIGN_MEMREG
;
495 RPC_U8(&msg
, 0U) = (uint8_t)pt
;
496 RPC_U8(&msg
, 1U) = (uint8_t)mr
;
499 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
501 result
= RPC_R8(&msg
);
502 return (sc_err_t
)result
;
505 sc_err_t
sc_rm_set_memreg_permissions(sc_ipc_t ipc
, sc_rm_mr_t mr
,
506 sc_rm_pt_t pt
, sc_rm_perm_t perm
)
511 RPC_VER(&msg
) = SC_RPC_VERSION
;
512 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_RM
;
513 RPC_FUNC(&msg
) = (uint8_t)RM_FUNC_SET_MEMREG_PERMISSIONS
;
514 RPC_U8(&msg
, 0U) = (uint8_t)mr
;
515 RPC_U8(&msg
, 1U) = (uint8_t)pt
;
516 RPC_U8(&msg
, 2U) = (uint8_t)perm
;
519 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
521 result
= RPC_R8(&msg
);
522 return (sc_err_t
)result
;
525 sc_bool_t
sc_rm_is_memreg_owned(sc_ipc_t ipc
, sc_rm_mr_t mr
)
530 RPC_VER(&msg
) = SC_RPC_VERSION
;
531 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_RM
;
532 RPC_FUNC(&msg
) = (uint8_t)RM_FUNC_IS_MEMREG_OWNED
;
533 RPC_U8(&msg
, 0U) = (uint8_t)mr
;
536 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
538 result
= RPC_R8(&msg
);
539 return (sc_bool_t
)result
;
542 sc_err_t
sc_rm_get_memreg_info(sc_ipc_t ipc
, sc_rm_mr_t mr
,
543 sc_faddr_t
*addr_start
, sc_faddr_t
*addr_end
)
548 RPC_VER(&msg
) = SC_RPC_VERSION
;
549 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_RM
;
550 RPC_FUNC(&msg
) = (uint8_t)RM_FUNC_GET_MEMREG_INFO
;
551 RPC_U8(&msg
, 0U) = (uint8_t)mr
;
554 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
556 if (addr_start
!= NULL
) {
558 ((uint64_t) RPC_U32(&msg
, 0U) << 32U) | RPC_U32(&msg
, 4U);
561 if (addr_end
!= NULL
) {
563 ((uint64_t) RPC_U32(&msg
, 8U) << 32U) | RPC_U32(&msg
, 12U);
566 result
= RPC_R8(&msg
);
567 return (sc_err_t
)result
;
570 sc_err_t
sc_rm_assign_pad(sc_ipc_t ipc
, sc_rm_pt_t pt
, sc_pad_t pad
)
575 RPC_VER(&msg
) = SC_RPC_VERSION
;
576 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_RM
;
577 RPC_FUNC(&msg
) = (uint8_t)RM_FUNC_ASSIGN_PAD
;
578 RPC_U16(&msg
, 0U) = (uint16_t)pad
;
579 RPC_U8(&msg
, 2U) = (uint8_t)pt
;
582 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
584 result
= RPC_R8(&msg
);
585 return (sc_err_t
)result
;
588 sc_err_t
sc_rm_set_pad_movable(sc_ipc_t ipc
, sc_pad_t pad_fst
,
589 sc_pad_t pad_lst
, sc_bool_t movable
)
594 RPC_VER(&msg
) = SC_RPC_VERSION
;
595 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_RM
;
596 RPC_FUNC(&msg
) = (uint8_t)RM_FUNC_SET_PAD_MOVABLE
;
597 RPC_U16(&msg
, 0U) = (uint16_t)pad_fst
;
598 RPC_U16(&msg
, 2U) = (uint16_t)pad_lst
;
599 RPC_U8(&msg
, 4U) = (uint8_t)movable
;
602 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
604 result
= RPC_R8(&msg
);
605 return (sc_err_t
)result
;
608 sc_bool_t
sc_rm_is_pad_owned(sc_ipc_t ipc
, sc_pad_t pad
)
613 RPC_VER(&msg
) = SC_RPC_VERSION
;
614 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_RM
;
615 RPC_FUNC(&msg
) = (uint8_t)RM_FUNC_IS_PAD_OWNED
;
616 RPC_U8(&msg
, 0U) = (uint8_t)pad
;
619 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
621 result
= RPC_R8(&msg
);
622 return (sc_bool_t
)result
;
625 void sc_rm_dump(sc_ipc_t ipc
)
629 RPC_VER(&msg
) = SC_RPC_VERSION
;
630 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_RM
;
631 RPC_FUNC(&msg
) = (uint8_t)RM_FUNC_DUMP
;
634 sc_call_rpc(ipc
, &msg
, SC_FALSE
);