xref: /rk3399_ARM-atf/services/std_svc/rmmd/rmmd_private.h (revision 52e486f6a6192bd18d36cdcbc35c59092eefc810)
1 /*
2  * Copyright (c) 2021-2025, Arm Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef RMMD_PRIVATE_H
8 #define RMMD_PRIVATE_H
9 
10 #include <context.h>
11 #include <lib/psci/psci_lib.h>
12 #include <services/rmmd_svc.h>
13 
14 /*******************************************************************************
15  * Constants that allow assembler code to preserve callee-saved registers of the
16  * C runtime context while performing a security state switch.
17  ******************************************************************************/
18 #define RMMD_C_RT_CTX_X19		0x0
19 #define RMMD_C_RT_CTX_X20		0x8
20 #define RMMD_C_RT_CTX_X21		0x10
21 #define RMMD_C_RT_CTX_X22		0x18
22 #define RMMD_C_RT_CTX_X23		0x20
23 #define RMMD_C_RT_CTX_X24		0x28
24 #define RMMD_C_RT_CTX_X25		0x30
25 #define RMMD_C_RT_CTX_X26		0x38
26 #define RMMD_C_RT_CTX_X27		0x40
27 #define RMMD_C_RT_CTX_X28		0x48
28 #define RMMD_C_RT_CTX_X29		0x50
29 #define RMMD_C_RT_CTX_X30		0x58
30 
31 #define RMMD_C_RT_CTX_SIZE		0x60
32 #define RMMD_C_RT_CTX_ENTRIES		(RMMD_C_RT_CTX_SIZE >> DWORD_SHIFT)
33 
34 #ifndef __ASSEMBLER__
35 #include <stdint.h>
36 
37 /*
38  * Data structure used by the RMM dispatcher (RMMD) in EL3 to track context of
39  * the RMM at R-EL2.
40  */
41 typedef struct rmmd_rmm_context {
42 	uint64_t c_rt_ctx;
43 	uint64_t activation_token;
44 	cpu_context_t cpu_ctx;
45 } rmmd_rmm_context_t;
46 
47 /* Functions used to enter/exit the RMM synchronously */
48 uint64_t rmmd_rmm_sync_entry(rmmd_rmm_context_t *ctx);
49 __dead2 void rmmd_rmm_sync_exit(uint64_t rc);
50 
51 /* Functions implementing attestation utilities for RMM */
52 int rmmd_attest_get_platform_token(uint64_t buf_pa, uint64_t *buf_size,
53 				   uint64_t c_size,
54 				   uint64_t *remaining_len);
55 int rmmd_attest_get_signing_key(uint64_t buf_pa, uint64_t *buf_size,
56 				uint64_t ecc_curve);
57 uint64_t rmmd_el3_token_sign(void *handle, uint64_t x1, uint64_t x2,
58 				    uint64_t x3, uint64_t x4);
59 
60 /* Functions implementing IDE KM programming */
61 int rmmd_el3_ide_key_program(uint64_t ecam_address, uint64_t rp_id,
62 			     uint64_t ide_stream_info, rp_ide_key_info_t *ide_key_info_ptr,
63 			     uint64_t request_id, uint64_t cookie);
64 int rmmd_el3_ide_key_set_go(uint64_t ecam_address, uint64_t rp_id, uint64_t ide_stream_info,
65 			    uint64_t request_id, uint64_t cookie);
66 int rmmd_el3_ide_key_set_stop(uint64_t ecam_address, uint64_t rp_id, uint64_t ide_stream_info,
67 			      uint64_t request_id, uint64_t cookie);
68 int rmmd_el3_ide_km_pull_response(uint64_t ecam_address, uint64_t rp_id, uint64_t *req_resp,
69 				  uint64_t *request_id, uint64_t *cookie_ptr);
70 
71 /* Memory reservation for RMM */
72 int rmmd_reserve_memory(size_t size, uint64_t *arg);
73 
74 /* Assembly helpers */
75 uint64_t rmmd_rmm_enter(uint64_t *c_rt_ctx);
76 void __dead2 rmmd_rmm_exit(uint64_t c_rt_ctx, uint64_t ret);
77 
78 /* Reference to PM ops for the RMMD */
79 extern const spd_pm_ops_t rmmd_pm;
80 
81 #endif /* __ASSEMBLER__ */
82 
83 #endif /* RMMD_PRIVATE_H */
84