blob: a89f2ed52bdafca73d5e558bffc5ab3c9bed85f0 [file] [log] [blame]
Soby Mathewb4c6df42022-11-09 11:13:29 +00001/*
2 * SPDX-License-Identifier: BSD-3-Clause
3 * SPDX-FileCopyrightText: Copyright TF-RMM Contributors.
4 */
5
AlexeiFedoroveaec0c42023-02-01 18:13:32 +00006#include <arch_features.h>
Soby Mathewb4c6df42022-11-09 11:13:29 +00007#include <attestation.h>
8#include <buffer.h>
9#include <debug.h>
10#include <rmm_el3_ifc.h>
Arunachalam Ganapathy4f601e72023-05-22 11:49:29 +010011#include <run.h>
Arunachalam Ganapathyf6491212023-02-23 16:04:34 +000012#include <simd.h>
Soby Mathewb4c6df42022-11-09 11:13:29 +000013#include <smc-rmi.h>
14#include <smc-rsi.h>
15
16#ifdef NDEBUG
17#define RMM_BUILD_TYPE "release"
18#else
19#define RMM_BUILD_TYPE "debug"
20#endif
21
22#define VER_STRING(toolchain, major, minor, patch) \
23 toolchain __STRING(major) "." \
24 __STRING(minor) "." __STRING(patch)
25
26static void rmm_arch_init(void)
27{
Javier Almansa Sobrinocfd32542024-10-09 19:38:56 +010028 unsigned long hcrx_el2_init = HCRX_INIT;
29
Soby Mathewb4c6df42022-11-09 11:13:29 +000030 SPE(write_pmscr_el2(PMSCR_EL2_INIT));
31
32 write_cnthctl_el2(CNTHCTL_EL2_INIT);
AlexeiFedoroveaec0c42023-02-01 18:13:32 +000033 write_vpidr_el2(read_midr_el1());
34 write_mdcr_el2(MDCR_EL2_INIT |
35 INPLACE(MDCR_EL2_HPMN,
36 EXTRACT(PMCR_EL0_N, read_pmcr_el0())));
Javier Almansa Sobrinocfd32542024-10-09 19:38:56 +010037
38 /* Enable EL1 access to sctlr2_el1 if the register is present */
39 if (is_feat_sctlr2x_present()) {
40 hcrx_el2_init |= HCRX_SCTLR2EN;
41 }
42
43 write_hcrx_el2(hcrx_el2_init);
Soby Mathewb4c6df42022-11-09 11:13:29 +000044}
45
AlexeiFedorovee2fc822023-10-31 14:54:39 +000046/* coverity[misra_c_2012_rule_8_4_violation:SUPPRESS] */
AlexeiFedorovb0de4d52023-10-10 11:46:16 +010047/* coverity[misra_c_2012_rule_8_7_violation:SUPPRESS] */
Soby Mathewb4c6df42022-11-09 11:13:29 +000048void rmm_warmboot_main(void)
49{
50 /*
51 * Do the rest of RMM architecture init
52 */
53 rmm_arch_init();
54
55 /*
56 * Finish initializing the slot buffer mechanism
57 */
Javier Almansa Sobrinoed932592023-01-24 12:50:41 +000058 slot_buf_finish_warmboot_init();
Soby Mathewb4c6df42022-11-09 11:13:29 +000059}
60
AlexeiFedorovee2fc822023-10-31 14:54:39 +000061/*
62 * This function is called from rmm_entry() in head.S
63 * and should be defined with external linkage, no
64 * compatible declaration is required.
65 */
66/* coverity[misra_c_2012_rule_8_4_violation:SUPPRESS] */
AlexeiFedorovb0de4d52023-10-10 11:46:16 +010067/* coverity[misra_c_2012_rule_8_7_violation:SUPPRESS] */
Soby Mathewb4c6df42022-11-09 11:13:29 +000068void rmm_main(void)
69{
70 unsigned int rmm_el3_ifc_version = rmm_el3_ifc_get_version();
71 unsigned int manifest_version = rmm_el3_ifc_get_manifest_version();
Arunachalam Ganapathy4003b3c2024-11-05 18:02:10 +000072 unsigned long rmi_revision = rmi_get_highest_supported_version();
73 unsigned long rsi_revision = rsi_get_highest_supported_version();
Soby Mathewb4c6df42022-11-09 11:13:29 +000074
75 /*
76 * Report project name, version, build type and
77 * commit information if it is present
78 */
Arunachalam Ganapathy4003b3c2024-11-05 18:02:10 +000079 NOTICE("Booting %s v.%s(%s) %s Built: %s %s with %s\n",
80 NAME, VERSION, RMM_BUILD_TYPE, COMMIT_INFO, __DATE__, __TIME__,
Soby Mathewb4c6df42022-11-09 11:13:29 +000081#ifdef __clang__
82 VER_STRING("Clang ", __clang_major__, __clang_minor__,
83 __clang_patchlevel__)
84#else
85 VER_STRING("GCC ", __GNUC__, __GNUC_MINOR__,
86 __GNUC_PATCHLEVEL__)
87#endif
88 );
89
90 /* Report Boot Interface version */
91 NOTICE("RMM-EL3 Interface v.%u.%u\n",
92 RMM_EL3_IFC_GET_VERS_MAJOR(rmm_el3_ifc_version),
93 RMM_EL3_IFC_GET_VERS_MINOR(rmm_el3_ifc_version));
94
95 /* Report Boot Manifest version */
96 NOTICE("Boot Manifest Interface v.%u.%u\n",
97 RMM_EL3_MANIFEST_GET_VERS_MAJOR(manifest_version),
98 RMM_EL3_MANIFEST_GET_VERS_MINOR(manifest_version));
99
Arunachalam Ganapathy4003b3c2024-11-05 18:02:10 +0000100 /* Report higher supported RMI revision */
101 NOTICE("RMI ABI revision v%lu.%lu\n",
102 RMI_ABI_VERSION_GET_MAJOR(rmi_revision),
103 RMI_ABI_VERSION_GET_MINOR(rmi_revision));
104
105 /* Report higher supported RSI revision */
106 NOTICE("RSI ABI revision v%lu.%lu\n",
107 RSI_ABI_VERSION_GET_MAJOR(rsi_revision),
108 RSI_ABI_VERSION_GET_MINOR(rsi_revision));
Soby Mathewb4c6df42022-11-09 11:13:29 +0000109
110 rmm_warmboot_main();
111
Arunachalam Ganapathy4f601e72023-05-22 11:49:29 +0100112 simd_init();
113
114 /* Initialize the NS SIMD context for all CPUs */
115 init_all_cpus_ns_simd_context();
116
Arunachalam Ganapathy51119932023-03-23 12:32:49 +0000117#ifdef RMM_FPU_USE_AT_REL2
Arunachalam Ganapathy4f601e72023-05-22 11:49:29 +0100118 simd_context_save(get_cpu_ns_simd_context());
Arunachalam Ganapathy51119932023-03-23 12:32:49 +0000119#endif
Soby Mathewb4c6df42022-11-09 11:13:29 +0000120 if (attestation_init() != 0) {
121 WARN("Attestation init failed.\n");
122 }
Arunachalam Ganapathy51119932023-03-23 12:32:49 +0000123#ifdef RMM_FPU_USE_AT_REL2
124 /*
125 * TODO: Do not save and restore NS state. Instead after
126 * attestation_init clear FPU state.
127 */
Arunachalam Ganapathy4f601e72023-05-22 11:49:29 +0100128 simd_context_restore(get_cpu_ns_simd_context());
Arunachalam Ganapathy51119932023-03-23 12:32:49 +0000129#endif
Soby Mathewb4c6df42022-11-09 11:13:29 +0000130}