blob: 4a30540abe7ce879e79bec78a7c6a217cdb76c06 [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
Arunachalam Ganapathyf6491212023-02-23 16:04:34 +000016
Soby Mathewb4c6df42022-11-09 11:13:29 +000017#ifdef NDEBUG
18#define RMM_BUILD_TYPE "release"
19#else
20#define RMM_BUILD_TYPE "debug"
21#endif
22
23#define VER_STRING(toolchain, major, minor, patch) \
24 toolchain __STRING(major) "." \
25 __STRING(minor) "." __STRING(patch)
26
27static void rmm_arch_init(void)
28{
29 MPAM(write_mpam2_el2(MPAM2_EL2_INIT));
30 MPAM(write_mpamhcr_el2(MPAMHCR_EL2_INIT));
31 SPE(write_pmscr_el2(PMSCR_EL2_INIT));
32
33 write_cnthctl_el2(CNTHCTL_EL2_INIT);
AlexeiFedoroveaec0c42023-02-01 18:13:32 +000034 write_vpidr_el2(read_midr_el1());
35 write_mdcr_el2(MDCR_EL2_INIT |
36 INPLACE(MDCR_EL2_HPMN,
37 EXTRACT(PMCR_EL0_N, read_pmcr_el0())));
Soby Mathewb4c6df42022-11-09 11:13:29 +000038}
39
AlexeiFedorovb0de4d52023-10-10 11:46:16 +010040/* coverity[misra_c_2012_rule_8_7_violation:SUPPRESS] */
Soby Mathewb4c6df42022-11-09 11:13:29 +000041void rmm_warmboot_main(void)
42{
43 /*
44 * Do the rest of RMM architecture init
45 */
46 rmm_arch_init();
47
48 /*
49 * Finish initializing the slot buffer mechanism
50 */
Javier Almansa Sobrinoed932592023-01-24 12:50:41 +000051 slot_buf_finish_warmboot_init();
Soby Mathewb4c6df42022-11-09 11:13:29 +000052}
53
AlexeiFedorovb0de4d52023-10-10 11:46:16 +010054/* coverity[misra_c_2012_rule_8_7_violation:SUPPRESS] */
Soby Mathewb4c6df42022-11-09 11:13:29 +000055void rmm_main(void)
56{
57 unsigned int rmm_el3_ifc_version = rmm_el3_ifc_get_version();
58 unsigned int manifest_version = rmm_el3_ifc_get_manifest_version();
59
60 /*
61 * Report project name, version, build type and
62 * commit information if it is present
63 */
64 NOTICE("Booting %s v.%s(%s) %s Built with %s\n",
65 NAME, VERSION, RMM_BUILD_TYPE, COMMIT_INFO,
66#ifdef __clang__
67 VER_STRING("Clang ", __clang_major__, __clang_minor__,
68 __clang_patchlevel__)
69#else
70 VER_STRING("GCC ", __GNUC__, __GNUC_MINOR__,
71 __GNUC_PATCHLEVEL__)
72#endif
73 );
74
75 /* Report Boot Interface version */
76 NOTICE("RMM-EL3 Interface v.%u.%u\n",
77 RMM_EL3_IFC_GET_VERS_MAJOR(rmm_el3_ifc_version),
78 RMM_EL3_IFC_GET_VERS_MINOR(rmm_el3_ifc_version));
79
80 /* Report Boot Manifest version */
81 NOTICE("Boot Manifest Interface v.%u.%u\n",
82 RMM_EL3_MANIFEST_GET_VERS_MAJOR(manifest_version),
83 RMM_EL3_MANIFEST_GET_VERS_MINOR(manifest_version));
84
85 /* Report RMI/RSI ABI versions and build timestamp */
86 NOTICE("RMI/RSI ABI v.%u.%u/%u.%u built: %s %s\n",
87 RMI_ABI_VERSION_MAJOR, RMI_ABI_VERSION_MINOR,
88 RSI_ABI_VERSION_MAJOR, RSI_ABI_VERSION_MINOR,
89 __DATE__, __TIME__);
90
91 rmm_warmboot_main();
92
Arunachalam Ganapathy4f601e72023-05-22 11:49:29 +010093 simd_init();
94
95 /* Initialize the NS SIMD context for all CPUs */
96 init_all_cpus_ns_simd_context();
97
Arunachalam Ganapathy51119932023-03-23 12:32:49 +000098#ifdef RMM_FPU_USE_AT_REL2
Arunachalam Ganapathy4f601e72023-05-22 11:49:29 +010099 simd_context_save(get_cpu_ns_simd_context());
Arunachalam Ganapathy51119932023-03-23 12:32:49 +0000100#endif
Soby Mathewb4c6df42022-11-09 11:13:29 +0000101 if (attestation_init() != 0) {
102 WARN("Attestation init failed.\n");
103 }
Arunachalam Ganapathy51119932023-03-23 12:32:49 +0000104#ifdef RMM_FPU_USE_AT_REL2
105 /*
106 * TODO: Do not save and restore NS state. Instead after
107 * attestation_init clear FPU state.
108 */
Arunachalam Ganapathy4f601e72023-05-22 11:49:29 +0100109 simd_context_restore(get_cpu_ns_simd_context());
Arunachalam Ganapathy51119932023-03-23 12:32:49 +0000110#endif
Soby Mathewb4c6df42022-11-09 11:13:29 +0000111}