xref: /rk3399_ARM-atf/include/services/el3_spmd_logical_sp.h (revision 66bdfd6e4e6d8e086a30397be6055dbb04846895)
1890b5088SRaghu Krishnamurthy /*
2890b5088SRaghu Krishnamurthy  * Copyright (c) 2023, ARM Limited and Contributors. All rights reserved.
3890b5088SRaghu Krishnamurthy  * SPDX-License-Identifier: BSD-3-Clause
4890b5088SRaghu Krishnamurthy  */
5890b5088SRaghu Krishnamurthy #ifndef EL3_SPMD_LOGICAL_SP_H
6890b5088SRaghu Krishnamurthy #define EL3_SPMD_LOGICAL_SP_H
7890b5088SRaghu Krishnamurthy 
8890b5088SRaghu Krishnamurthy #include <common/bl_common.h>
9890b5088SRaghu Krishnamurthy #include <lib/cassert.h>
10890b5088SRaghu Krishnamurthy #include <services/ffa_svc.h>
11890b5088SRaghu Krishnamurthy 
12890b5088SRaghu Krishnamurthy /*******************************************************************************
13890b5088SRaghu Krishnamurthy  * Structure definition, typedefs & constants for the SPMD Logical Partitions.
14890b5088SRaghu Krishnamurthy  ******************************************************************************/
15*66bdfd6eSRaghu Krishnamurthy typedef struct spmd_spm_core_context spmd_spm_core_context_t;
16890b5088SRaghu Krishnamurthy 
17890b5088SRaghu Krishnamurthy /* Prototype for SPMD logical partition initializing function. */
18890b5088SRaghu Krishnamurthy typedef int32_t (*ffa_spmd_lp_init_t)(void);
19890b5088SRaghu Krishnamurthy 
20890b5088SRaghu Krishnamurthy /* SPMD Logical Partition Descriptor. */
21890b5088SRaghu Krishnamurthy struct spmd_lp_desc {
22890b5088SRaghu Krishnamurthy 	ffa_spmd_lp_init_t init;
23890b5088SRaghu Krishnamurthy 	uint16_t sp_id;
24890b5088SRaghu Krishnamurthy 	uint32_t properties;
25890b5088SRaghu Krishnamurthy 	uint32_t uuid[4];  /* Little Endian. */
26890b5088SRaghu Krishnamurthy 	const char *debug_name;
27890b5088SRaghu Krishnamurthy };
28890b5088SRaghu Krishnamurthy 
29*66bdfd6eSRaghu Krishnamurthy struct ffa_value {
30*66bdfd6eSRaghu Krishnamurthy 	uint64_t func;
31*66bdfd6eSRaghu Krishnamurthy 	uint64_t arg1;
32*66bdfd6eSRaghu Krishnamurthy 	uint64_t arg2;
33*66bdfd6eSRaghu Krishnamurthy 	uint64_t arg3;
34*66bdfd6eSRaghu Krishnamurthy 	uint64_t arg4;
35*66bdfd6eSRaghu Krishnamurthy 	uint64_t arg5;
36*66bdfd6eSRaghu Krishnamurthy 	uint64_t arg6;
37*66bdfd6eSRaghu Krishnamurthy 	uint64_t arg7;
38*66bdfd6eSRaghu Krishnamurthy };
39*66bdfd6eSRaghu Krishnamurthy 
40890b5088SRaghu Krishnamurthy /* Convenience macro to declare a SPMD logical partition descriptor. */
41890b5088SRaghu Krishnamurthy #define DECLARE_SPMD_LOGICAL_PARTITION(_name, _init, _sp_id, _uuid, _properties) \
42890b5088SRaghu Krishnamurthy 	static const struct spmd_lp_desc __partition_desc_ ## _name	    \
43890b5088SRaghu Krishnamurthy 		__section(".spmd_lp_descs") __used = {			    \
44890b5088SRaghu Krishnamurthy 			.debug_name = #_name,				    \
45890b5088SRaghu Krishnamurthy 			.init = (_init),				    \
46890b5088SRaghu Krishnamurthy 			.sp_id = (_sp_id),				    \
47890b5088SRaghu Krishnamurthy 			.uuid = _uuid,					    \
48890b5088SRaghu Krishnamurthy 			.properties = (_properties),			    \
49890b5088SRaghu Krishnamurthy 		}
50890b5088SRaghu Krishnamurthy 
51890b5088SRaghu Krishnamurthy IMPORT_SYM(uintptr_t, __SPMD_LP_DESCS_START__,	SPMD_LP_DESCS_START);
52890b5088SRaghu Krishnamurthy IMPORT_SYM(uintptr_t, __SPMD_LP_DESCS_END__,	SPMD_LP_DESCS_END);
53890b5088SRaghu Krishnamurthy 
54890b5088SRaghu Krishnamurthy #define SPMD_LP_DESCS_COUNT ((SPMD_LP_DESCS_END - SPMD_LP_DESCS_START) \
55890b5088SRaghu Krishnamurthy 			  / sizeof(struct spmd_lp_desc))
56890b5088SRaghu Krishnamurthy CASSERT(sizeof(struct spmd_lp_desc) == 40, assert_spmd_lp_desc_size_mismatch);
57890b5088SRaghu Krishnamurthy 
58890b5088SRaghu Krishnamurthy /*
59890b5088SRaghu Krishnamurthy  * Reserve 63 IDs for SPMD Logical Partitions. Currently, 0xFFC0 to 0xFFFE
60890b5088SRaghu Krishnamurthy  * is reserved.
61890b5088SRaghu Krishnamurthy  */
62890b5088SRaghu Krishnamurthy #define SPMD_LP_ID_END		(SPMD_DIRECT_MSG_ENDPOINT_ID - 1)
63890b5088SRaghu Krishnamurthy #define SPMD_LP_ID_START	(SPMD_LP_ID_END - 62)
64890b5088SRaghu Krishnamurthy 
65890b5088SRaghu Krishnamurthy static inline bool is_spmd_lp_id(unsigned int id)
66890b5088SRaghu Krishnamurthy {
67*66bdfd6eSRaghu Krishnamurthy #if ENABLE_SPMD_LP
68890b5088SRaghu Krishnamurthy 	return (id >= SPMD_LP_ID_START && id <= SPMD_LP_ID_END);
69*66bdfd6eSRaghu Krishnamurthy #else
70*66bdfd6eSRaghu Krishnamurthy 	return false;
71*66bdfd6eSRaghu Krishnamurthy #endif
72*66bdfd6eSRaghu Krishnamurthy }
73*66bdfd6eSRaghu Krishnamurthy 
74*66bdfd6eSRaghu Krishnamurthy static inline bool is_ffa_error(struct ffa_value *retval)
75*66bdfd6eSRaghu Krishnamurthy {
76*66bdfd6eSRaghu Krishnamurthy 	return retval->func == FFA_ERROR;
77*66bdfd6eSRaghu Krishnamurthy }
78*66bdfd6eSRaghu Krishnamurthy 
79*66bdfd6eSRaghu Krishnamurthy static inline bool is_ffa_direct_msg_resp(struct ffa_value *retval)
80*66bdfd6eSRaghu Krishnamurthy {
81*66bdfd6eSRaghu Krishnamurthy 	return (retval->func == FFA_MSG_SEND_DIRECT_RESP_SMC32) ||
82*66bdfd6eSRaghu Krishnamurthy 		(retval->func == FFA_MSG_SEND_DIRECT_RESP_SMC64);
83890b5088SRaghu Krishnamurthy }
84890b5088SRaghu Krishnamurthy 
85890b5088SRaghu Krishnamurthy void spmd_logical_sp_set_spmc_initialized(void);
86890b5088SRaghu Krishnamurthy void spmc_logical_sp_set_spmc_failure(void);
87890b5088SRaghu Krishnamurthy 
88890b5088SRaghu Krishnamurthy int32_t spmd_logical_sp_init(void);
89*66bdfd6eSRaghu Krishnamurthy bool is_spmd_logical_sp_dir_req_in_progress(
90*66bdfd6eSRaghu Krishnamurthy 		spmd_spm_core_context_t *ctx);
91*66bdfd6eSRaghu Krishnamurthy 
92*66bdfd6eSRaghu Krishnamurthy bool spmd_el3_ffa_msg_direct_req(uint64_t x1,
93*66bdfd6eSRaghu Krishnamurthy 				 uint64_t x2,
94*66bdfd6eSRaghu Krishnamurthy 				 uint64_t x3,
95*66bdfd6eSRaghu Krishnamurthy 				 uint64_t x4,
96*66bdfd6eSRaghu Krishnamurthy 				 void *handle,
97*66bdfd6eSRaghu Krishnamurthy 				 struct ffa_value *retval);
98890b5088SRaghu Krishnamurthy 
99890b5088SRaghu Krishnamurthy #endif /* EL3_SPMD_LOGICAL_SP_H */
100