blob: 80e53702ea6e59794492e6b264ac2decba822ceb [file] [log] [blame]
Usama Arifbec5afd2020-04-17 16:13:39 +01001/*
laurenw-arm481ac282023-05-03 12:48:55 -05002 * Copyright (c) 2020-2023, Arm Limited and Contributors. All rights reserved.
Usama Arifbec5afd2020-04-17 16:13:39 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <assert.h>
8
9#include <libfdt.h>
Usama Ariff1513622021-04-09 17:07:41 +010010#include <tc_plat.h>
Usama Arifbec5afd2020-04-17 16:13:39 +010011
Manish V Badarkheb241efb2023-10-18 14:11:45 +010012#include <arch_helpers.h>
Usama Arifbec5afd2020-04-17 16:13:39 +010013#include <common/bl_common.h>
14#include <common/debug.h>
15#include <drivers/arm/css/css_mhu_doorbell.h>
16#include <drivers/arm/css/scmi.h>
Madhukar Pappireddye108df22023-03-22 15:40:40 -050017#include <drivers/arm/sbsa.h>
Usama Arifa49bd492021-08-17 17:57:10 +010018#include <lib/fconf/fconf.h>
19#include <lib/fconf/fconf_dyn_cfg_getter.h>
Usama Arifbec5afd2020-04-17 16:13:39 +010020#include <plat/arm/common/plat_arm.h>
21#include <plat/common/platform.h>
22
Manish V Badarkheb241efb2023-10-18 14:11:45 +010023#include <psa/crypto_platform.h>
24#include <psa/crypto_types.h>
25#include <psa/crypto_values.h>
26
27#ifdef PLATFORM_TEST_TFM_TESTSUITE
28/*
29 * We pretend using an external RNG (through MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
30 * mbedTLS config option) so we need to provide an implementation of
31 * mbedtls_psa_external_get_random(). Provide a fake one, since we do not
32 * actually use any of external RNG and this function is only needed during
33 * the execution of TF-M testsuite during exporting the public part of the
34 * delegated attestation key.
35 */
36psa_status_t mbedtls_psa_external_get_random(
37 mbedtls_psa_external_random_context_t *context,
38 uint8_t *output, size_t output_size,
39 size_t *output_length)
40{
41 for (size_t i = 0U; i < output_size; i++) {
42 output[i] = (uint8_t)(read_cntpct_el0() & 0xFFU);
43 }
44
45 *output_length = output_size;
46
47 return PSA_SUCCESS;
48}
49#endif /* PLATFORM_TEST_TFM_TESTSUITE */
50
Usama Ariff1513622021-04-09 17:07:41 +010051static scmi_channel_plat_info_t tc_scmi_plat_info[] = {
Usama Arifbec5afd2020-04-17 16:13:39 +010052 {
53 .scmi_mbx_mem = CSS_SCMI_PAYLOAD_BASE,
54 .db_reg_addr = PLAT_CSS_MHU_BASE + SENDER_REG_SET(0),
55 .db_preserve_mask = 0xfffffffe,
56 .db_modify_mask = 0x1,
57 .ring_doorbell = &mhuv2_ring_doorbell,
58 }
59};
60
61void bl31_platform_setup(void)
62{
Usama Ariff1513622021-04-09 17:07:41 +010063 tc_bl31_common_platform_setup();
Usama Arifbec5afd2020-04-17 16:13:39 +010064}
65
Tony K Nadackal1b116a82022-12-07 20:44:05 +000066scmi_channel_plat_info_t *plat_css_get_scmi_info(unsigned int channel_id)
Usama Arifbec5afd2020-04-17 16:13:39 +010067{
68
Usama Ariff1513622021-04-09 17:07:41 +010069 return &tc_scmi_plat_info[channel_id];
Usama Arifbec5afd2020-04-17 16:13:39 +010070
71}
72
73void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
74 u_register_t arg2, u_register_t arg3)
75{
76 arm_bl31_early_platform_setup((void *)arg0, arg1, arg2, (void *)arg3);
Usama Arifa49bd492021-08-17 17:57:10 +010077
78 /* Fill the properties struct with the info from the config dtb */
79 fconf_populate("FW_CONFIG", arg1);
Usama Arifbec5afd2020-04-17 16:13:39 +010080}
81
laurenw-arm4c4181c2023-05-04 14:55:37 -050082#ifdef PLATFORM_TESTS
Sandrine Bailleux27fba522023-05-05 15:44:26 +020083static __dead2 void tc_run_platform_tests(void)
Usama Arifbec5afd2020-04-17 16:13:39 +010084{
Sandrine Bailleuxf0f42fb2023-05-05 15:59:00 +020085 int tests_failed;
86
87 printf("\nStarting platform tests...\n");
Mate Toth-Pal14ba4af2022-10-21 14:24:49 +020088
Tamas Ban15b79da2023-04-21 09:31:48 +020089#ifdef PLATFORM_TEST_NV_COUNTERS
Sandrine Bailleuxf0f42fb2023-05-05 15:59:00 +020090 tests_failed = nv_counter_test();
laurenw-arm116f10c2023-06-13 16:43:39 -050091#elif PLATFORM_TEST_ROTPK
92 tests_failed = rotpk_test();
Tamas Ban15b79da2023-04-21 09:31:48 +020093#elif PLATFORM_TEST_TFM_TESTSUITE
Sandrine Bailleuxf0f42fb2023-05-05 15:59:00 +020094 tests_failed = run_platform_tests();
laurenw-arm2ce1e352023-02-07 13:40:05 -060095#endif
Sandrine Bailleuxf0f42fb2023-05-05 15:59:00 +020096
97 printf("Platform tests %s.\n",
98 (tests_failed != 0) ? "failed" : "succeeded");
99
Sandrine Bailleuxe1da6c42023-05-05 13:59:07 +0200100 /* Suspend booting, no matter the tests outcome. */
Sandrine Bailleuxf0f42fb2023-05-05 15:59:00 +0200101 printf("Suspend booting...\n");
Mate Toth-Pal14ba4af2022-10-21 14:24:49 +0200102 plat_error_handler(-1);
Sandrine Bailleux27fba522023-05-05 15:44:26 +0200103}
104#endif
105
106void tc_bl31_common_platform_setup(void)
107{
108 arm_bl31_platform_setup();
109
110#ifdef PLATFORM_TESTS
111 tc_run_platform_tests();
laurenw-arm481ac282023-05-03 12:48:55 -0500112#endif
Usama Arifbec5afd2020-04-17 16:13:39 +0100113}
114
115const plat_psci_ops_t *plat_arm_psci_override_pm_ops(plat_psci_ops_t *ops)
116{
117 return css_scmi_override_pm_ops(ops);
118}
Usama Arifa49bd492021-08-17 17:57:10 +0100119
120void __init bl31_plat_arch_setup(void)
121{
122 arm_bl31_plat_arch_setup();
123
124 /* HW_CONFIG was also loaded by BL2 */
125 const struct dyn_cfg_dtb_info_t *hw_config_info;
126
127 hw_config_info = FCONF_GET_PROPERTY(dyn_cfg, dtb, HW_CONFIG_ID);
128 assert(hw_config_info != NULL);
129
130 fconf_populate("HW_CONFIG", hw_config_info->config_addr);
131}
Madhukar Pappireddye108df22023-03-22 15:40:40 -0500132
Govindraj Raja436ea5e2023-05-10 14:50:36 -0500133#if defined(SPD_spmd) && (SPMC_AT_EL3 == 0)
Madhukar Pappireddye108df22023-03-22 15:40:40 -0500134void tc_bl31_plat_runtime_setup(void)
135{
136 arm_bl31_plat_runtime_setup();
137
138 /* Start secure watchdog timer. */
139 plat_arm_secure_wdt_start();
140}
141
142void bl31_plat_runtime_setup(void)
143{
144 tc_bl31_plat_runtime_setup();
145}
146
147/*
148 * Platform handler for Group0 secure interrupt.
149 */
150int plat_spmd_handle_group0_interrupt(uint32_t intid)
151{
152 /* Trusted Watchdog timer is the only source of Group0 interrupt now. */
153 if (intid == SBSA_SECURE_WDOG_INTID) {
Madhukar Pappireddye108df22023-03-22 15:40:40 -0500154 /* Refresh the timer. */
155 plat_arm_secure_wdt_refresh();
156
Madhukar Pappireddye108df22023-03-22 15:40:40 -0500157 return 0;
158 }
159
160 return -1;
161}
Govindraj Raja436ea5e2023-05-10 14:50:36 -0500162#endif /*defined(SPD_spmd) && (SPMC_AT_EL3 == 0)*/