xref: /rk3399_ARM-atf/plat/arm/board/morello/morello_bl31_setup.c (revision 05d22c3045e2e972c2262b9ccd6c82cb7545bf83)
1 /*
2  * Copyright (c) 2020-2025, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #include <drivers/arm/css/css_mhu_doorbell.h>
8 #include <drivers/arm/css/scmi.h>
9 #include <drivers/arm/css/sds.h>
10 #include <lib/smccc.h>
11 #include <plat/arm/common/plat_arm.h>
12 #include <services/arm_arch_svc.h>
13 
14 #include "morello_def.h"
15 #include "morello_private.h"
16 #include <platform_def.h>
17 
18 #ifdef TARGET_PLATFORM_SOC
19 struct morello_plat_info plat_info;
20 #endif
21 
22 static scmi_channel_plat_info_t morello_scmi_plat_info = {
23 	.scmi_mbx_mem = MORELLO_SCMI_PAYLOAD_BASE,
24 	.db_reg_addr = PLAT_CSS_MHU_BASE + CSS_SCMI_MHU_DB_REG_OFF,
25 	.db_preserve_mask = 0xfffffffe,
26 	.db_modify_mask = 0x1,
27 	.ring_doorbell = &mhu_ring_doorbell
28 };
29 
30 scmi_channel_plat_info_t *plat_css_get_scmi_info(unsigned int channel_id)
31 {
32 	return &morello_scmi_plat_info;
33 }
34 
35 const plat_psci_ops_t *plat_arm_psci_override_pm_ops(plat_psci_ops_t *ops)
36 {
37 	ops->pwr_domain_off = morello_pwr_domain_off;
38 	return css_scmi_override_pm_ops(ops);
39 }
40 
41 void bl31_platform_setup(void)
42 {
43 #ifdef TARGET_PLATFORM_SOC
44 	int ret;
45 
46 	ret = sds_init(SDS_SCP_AP_REGION_ID);
47 	if (ret != SDS_OK) {
48 		ERROR("SDS initialization failed. ret:%d\n", ret);
49 		panic();
50 	}
51 
52 	ret = sds_struct_read(SDS_SCP_AP_REGION_ID,
53 				MORELLO_SDS_PLATFORM_INFO_STRUCT_ID,
54 				MORELLO_SDS_PLATFORM_INFO_OFFSET,
55 				&plat_info,
56 				MORELLO_SDS_PLATFORM_INFO_SIZE,
57 				SDS_ACCESS_MODE_NON_CACHED);
58 	if (ret != SDS_OK) {
59 		ERROR("Error getting platform info from SDS. ret:%d\n", ret);
60 		panic();
61 	}
62 #endif
63 	arm_bl31_platform_setup();
64 
65 	gic_set_gicr_frames(arm_gicr_base_addrs);
66 }
67 
68 #ifdef TARGET_PLATFORM_SOC
69 /*****************************************************************************
70  * plat_is_smccc_feature_available() - This function checks whether SMCCC
71  *                                     feature is availabile for platform.
72  * @fid: SMCCC function id
73  *
74  * Return SMC_ARCH_CALL_SUCCESS if SMCCC feature is available and
75  * SMC_ARCH_CALL_NOT_SUPPORTED otherwise.
76  *****************************************************************************/
77 int32_t plat_is_smccc_feature_available(u_register_t fid)
78 {
79 	switch (fid) {
80 	case SMCCC_ARCH_SOC_ID:
81 		return SMC_ARCH_CALL_SUCCESS;
82 	default:
83 		return SMC_ARCH_CALL_NOT_SUPPORTED;
84 	}
85 }
86 
87 /* Get SOC version */
88 int32_t plat_get_soc_version(void)
89 {
90 	int ssc_version;
91 
92 	ssc_version = mmio_read_32(SSC_VERSION);
93 
94 	return (int32_t)
95 		(SOC_ID_SET_JEP_106(ARM_SOC_CONTINUATION_CODE,
96 					ARM_SOC_IDENTIFICATION_CODE) |
97 		(GET_SSC_VERSION_PART_NUM(ssc_version) & SOC_ID_IMPL_DEF_MASK));
98 }
99 
100 /* Get SOC revision */
101 int32_t plat_get_soc_revision(void)
102 {
103 	return (int32_t)plat_info.silicon_revision;
104 }
105 #endif
106