blob: a91505ae791dc3865998516a4dfe949d6058e58e [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 Ganapathyf6491212023-02-23 16:04:34 +000011#include <simd.h>
Soby Mathewb4c6df42022-11-09 11:13:29 +000012#include <smc-rmi.h>
13#include <smc-rsi.h>
14
Arunachalam Ganapathyf6491212023-02-23 16:04:34 +000015
Soby Mathewb4c6df42022-11-09 11:13:29 +000016#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{
28 MPAM(write_mpam2_el2(MPAM2_EL2_INIT));
29 MPAM(write_mpamhcr_el2(MPAMHCR_EL2_INIT));
30 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())));
Arunachalam Ganapathyf6491212023-02-23 16:04:34 +000037
38 simd_init();
Soby Mathewb4c6df42022-11-09 11:13:29 +000039}
40
41void 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
54void rmm_main(void)
55{
56 unsigned int rmm_el3_ifc_version = rmm_el3_ifc_get_version();
57 unsigned int manifest_version = rmm_el3_ifc_get_manifest_version();
58
59 /*
60 * Report project name, version, build type and
61 * commit information if it is present
62 */
63 NOTICE("Booting %s v.%s(%s) %s Built with %s\n",
64 NAME, VERSION, RMM_BUILD_TYPE, COMMIT_INFO,
65#ifdef __clang__
66 VER_STRING("Clang ", __clang_major__, __clang_minor__,
67 __clang_patchlevel__)
68#else
69 VER_STRING("GCC ", __GNUC__, __GNUC_MINOR__,
70 __GNUC_PATCHLEVEL__)
71#endif
72 );
73
74 /* Report Boot Interface version */
75 NOTICE("RMM-EL3 Interface v.%u.%u\n",
76 RMM_EL3_IFC_GET_VERS_MAJOR(rmm_el3_ifc_version),
77 RMM_EL3_IFC_GET_VERS_MINOR(rmm_el3_ifc_version));
78
79 /* Report Boot Manifest version */
80 NOTICE("Boot Manifest Interface v.%u.%u\n",
81 RMM_EL3_MANIFEST_GET_VERS_MAJOR(manifest_version),
82 RMM_EL3_MANIFEST_GET_VERS_MINOR(manifest_version));
83
84 /* Report RMI/RSI ABI versions and build timestamp */
85 NOTICE("RMI/RSI ABI v.%u.%u/%u.%u built: %s %s\n",
86 RMI_ABI_VERSION_MAJOR, RMI_ABI_VERSION_MINOR,
87 RSI_ABI_VERSION_MAJOR, RSI_ABI_VERSION_MINOR,
88 __DATE__, __TIME__);
89
90 rmm_warmboot_main();
91
Arunachalam Ganapathy51119932023-03-23 12:32:49 +000092#ifdef RMM_FPU_USE_AT_REL2
93 simd_save_ns_state();
94#endif
Soby Mathewb4c6df42022-11-09 11:13:29 +000095 if (attestation_init() != 0) {
96 WARN("Attestation init failed.\n");
97 }
Arunachalam Ganapathy51119932023-03-23 12:32:49 +000098#ifdef RMM_FPU_USE_AT_REL2
99 /*
100 * TODO: Do not save and restore NS state. Instead after
101 * attestation_init clear FPU state.
102 */
103 simd_restore_ns_state();
104#endif
Soby Mathewb4c6df42022-11-09 11:13:29 +0000105}