1 /*
2  * Copyright (c) 2020-2023, 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 
plat_css_get_scmi_info(unsigned int channel_id)30 scmi_channel_plat_info_t *plat_css_get_scmi_info(unsigned int channel_id)
31 {
32 	return &morello_scmi_plat_info;
33 }
34 
plat_arm_psci_override_pm_ops(plat_psci_ops_t * ops)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 
bl31_platform_setup(void)41 void bl31_platform_setup(void)
42 {
43 #ifdef TARGET_PLATFORM_SOC
44 	int ret;
45 
46 	ret = sds_init();
47 	if (ret != SDS_OK) {
48 		ERROR("SDS initialization failed. ret:%d\n", ret);
49 		panic();
50 	}
51 
52 	ret = sds_struct_read(MORELLO_SDS_PLATFORM_INFO_STRUCT_ID,
53 				MORELLO_SDS_PLATFORM_INFO_OFFSET,
54 				&plat_info,
55 				MORELLO_SDS_PLATFORM_INFO_SIZE,
56 				SDS_ACCESS_MODE_NON_CACHED);
57 	if (ret != SDS_OK) {
58 		ERROR("Error getting platform info from SDS. ret:%d\n", ret);
59 		panic();
60 	}
61 #endif
62 	arm_bl31_platform_setup();
63 }
64 
65 #ifdef TARGET_PLATFORM_SOC
66 /*****************************************************************************
67  * plat_is_smccc_feature_available() - This function checks whether SMCCC
68  *                                     feature is availabile for platform.
69  * @fid: SMCCC function id
70  *
71  * Return SMC_ARCH_CALL_SUCCESS if SMCCC feature is available and
72  * SMC_ARCH_CALL_NOT_SUPPORTED otherwise.
73  *****************************************************************************/
plat_is_smccc_feature_available(u_register_t fid)74 int32_t plat_is_smccc_feature_available(u_register_t fid)
75 {
76 	switch (fid) {
77 	case SMCCC_ARCH_SOC_ID:
78 		return SMC_ARCH_CALL_SUCCESS;
79 	default:
80 		return SMC_ARCH_CALL_NOT_SUPPORTED;
81 	}
82 }
83 
84 /* Get SOC version */
plat_get_soc_version(void)85 int32_t plat_get_soc_version(void)
86 {
87 	int ssc_version;
88 
89 	ssc_version = mmio_read_32(SSC_VERSION);
90 
91 	return (int32_t)
92 		(SOC_ID_SET_JEP_106(ARM_SOC_CONTINUATION_CODE,
93 					ARM_SOC_IDENTIFICATION_CODE) |
94 		(GET_SSC_VERSION_PART_NUM(ssc_version) & SOC_ID_IMPL_DEF_MASK));
95 }
96 
97 /* Get SOC revision */
plat_get_soc_revision(void)98 int32_t plat_get_soc_revision(void)
99 {
100 	return (int32_t)plat_info.silicon_revision;
101 }
102 #endif
103