blob: ca3a03279531b1b0355e4a48e74bfa341784bf2c [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
12#include <common/bl_common.h>
13#include <common/debug.h>
14#include <drivers/arm/css/css_mhu_doorbell.h>
15#include <drivers/arm/css/scmi.h>
Madhukar Pappireddye108df22023-03-22 15:40:40 -050016#include <drivers/arm/sbsa.h>
Usama Arifa49bd492021-08-17 17:57:10 +010017#include <lib/fconf/fconf.h>
18#include <lib/fconf/fconf_dyn_cfg_getter.h>
Usama Arifbec5afd2020-04-17 16:13:39 +010019#include <plat/arm/common/plat_arm.h>
20#include <plat/common/platform.h>
21
Usama Ariff1513622021-04-09 17:07:41 +010022static scmi_channel_plat_info_t tc_scmi_plat_info[] = {
Usama Arifbec5afd2020-04-17 16:13:39 +010023 {
24 .scmi_mbx_mem = CSS_SCMI_PAYLOAD_BASE,
25 .db_reg_addr = PLAT_CSS_MHU_BASE + SENDER_REG_SET(0),
26 .db_preserve_mask = 0xfffffffe,
27 .db_modify_mask = 0x1,
28 .ring_doorbell = &mhuv2_ring_doorbell,
29 }
30};
31
32void bl31_platform_setup(void)
33{
Usama Ariff1513622021-04-09 17:07:41 +010034 tc_bl31_common_platform_setup();
Usama Arifbec5afd2020-04-17 16:13:39 +010035}
36
Tony K Nadackal1b116a82022-12-07 20:44:05 +000037scmi_channel_plat_info_t *plat_css_get_scmi_info(unsigned int channel_id)
Usama Arifbec5afd2020-04-17 16:13:39 +010038{
39
Usama Ariff1513622021-04-09 17:07:41 +010040 return &tc_scmi_plat_info[channel_id];
Usama Arifbec5afd2020-04-17 16:13:39 +010041
42}
43
44void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
45 u_register_t arg2, u_register_t arg3)
46{
47 arm_bl31_early_platform_setup((void *)arg0, arg1, arg2, (void *)arg3);
Usama Arifa49bd492021-08-17 17:57:10 +010048
49 /* Fill the properties struct with the info from the config dtb */
50 fconf_populate("FW_CONFIG", arg1);
Usama Arifbec5afd2020-04-17 16:13:39 +010051}
52
laurenw-arm4c4181c2023-05-04 14:55:37 -050053#ifdef PLATFORM_TESTS
Sandrine Bailleux27fba522023-05-05 15:44:26 +020054static __dead2 void tc_run_platform_tests(void)
Usama Arifbec5afd2020-04-17 16:13:39 +010055{
Sandrine Bailleuxf0f42fb2023-05-05 15:59:00 +020056 int tests_failed;
57
58 printf("\nStarting platform tests...\n");
Mate Toth-Pal14ba4af2022-10-21 14:24:49 +020059
Tamas Ban15b79da2023-04-21 09:31:48 +020060#ifdef PLATFORM_TEST_NV_COUNTERS
Sandrine Bailleuxf0f42fb2023-05-05 15:59:00 +020061 tests_failed = nv_counter_test();
Tamas Ban15b79da2023-04-21 09:31:48 +020062#elif PLATFORM_TEST_TFM_TESTSUITE
Sandrine Bailleuxf0f42fb2023-05-05 15:59:00 +020063 tests_failed = run_platform_tests();
laurenw-arm2ce1e352023-02-07 13:40:05 -060064#endif
Sandrine Bailleuxf0f42fb2023-05-05 15:59:00 +020065
66 printf("Platform tests %s.\n",
67 (tests_failed != 0) ? "failed" : "succeeded");
68
Sandrine Bailleuxe1da6c42023-05-05 13:59:07 +020069 /* Suspend booting, no matter the tests outcome. */
Sandrine Bailleuxf0f42fb2023-05-05 15:59:00 +020070 printf("Suspend booting...\n");
Mate Toth-Pal14ba4af2022-10-21 14:24:49 +020071 plat_error_handler(-1);
Sandrine Bailleux27fba522023-05-05 15:44:26 +020072}
73#endif
74
75void tc_bl31_common_platform_setup(void)
76{
77 arm_bl31_platform_setup();
78
79#ifdef PLATFORM_TESTS
80 tc_run_platform_tests();
laurenw-arm481ac282023-05-03 12:48:55 -050081#endif
Usama Arifbec5afd2020-04-17 16:13:39 +010082}
83
84const plat_psci_ops_t *plat_arm_psci_override_pm_ops(plat_psci_ops_t *ops)
85{
86 return css_scmi_override_pm_ops(ops);
87}
Usama Arifa49bd492021-08-17 17:57:10 +010088
89void __init bl31_plat_arch_setup(void)
90{
91 arm_bl31_plat_arch_setup();
92
93 /* HW_CONFIG was also loaded by BL2 */
94 const struct dyn_cfg_dtb_info_t *hw_config_info;
95
96 hw_config_info = FCONF_GET_PROPERTY(dyn_cfg, dtb, HW_CONFIG_ID);
97 assert(hw_config_info != NULL);
98
99 fconf_populate("HW_CONFIG", hw_config_info->config_addr);
100}
Madhukar Pappireddye108df22023-03-22 15:40:40 -0500101
Govindraj Raja436ea5e2023-05-10 14:50:36 -0500102#if defined(SPD_spmd) && (SPMC_AT_EL3 == 0)
Madhukar Pappireddye108df22023-03-22 15:40:40 -0500103void tc_bl31_plat_runtime_setup(void)
104{
105 arm_bl31_plat_runtime_setup();
106
107 /* Start secure watchdog timer. */
108 plat_arm_secure_wdt_start();
109}
110
111void bl31_plat_runtime_setup(void)
112{
113 tc_bl31_plat_runtime_setup();
114}
115
116/*
117 * Platform handler for Group0 secure interrupt.
118 */
119int plat_spmd_handle_group0_interrupt(uint32_t intid)
120{
121 /* Trusted Watchdog timer is the only source of Group0 interrupt now. */
122 if (intid == SBSA_SECURE_WDOG_INTID) {
123 INFO("Watchdog restarted\n");
124 /* Refresh the timer. */
125 plat_arm_secure_wdt_refresh();
126
127 /* Deactivate the corresponding interrupt. */
128 plat_ic_end_of_interrupt(intid);
129 return 0;
130 }
131
132 return -1;
133}
Govindraj Raja436ea5e2023-05-10 14:50:36 -0500134#endif /*defined(SPD_spmd) && (SPMC_AT_EL3 == 0)*/