Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * SPDX-License-Identifier: BSD-3-Clause |
| 3 | * SPDX-FileCopyrightText: Copyright TF-RMM Contributors. |
| 4 | */ |
| 5 | |
AlexeiFedorov | eaec0c4 | 2023-02-01 18:13:32 +0000 | [diff] [blame] | 6 | #include <arch_features.h> |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 7 | #include <attestation.h> |
| 8 | #include <buffer.h> |
| 9 | #include <debug.h> |
| 10 | #include <rmm_el3_ifc.h> |
Arunachalam Ganapathy | 4f601e7 | 2023-05-22 11:49:29 +0100 | [diff] [blame^] | 11 | #include <run.h> |
Arunachalam Ganapathy | f649121 | 2023-02-23 16:04:34 +0000 | [diff] [blame] | 12 | #include <simd.h> |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 13 | #include <smc-rmi.h> |
| 14 | #include <smc-rsi.h> |
| 15 | |
Arunachalam Ganapathy | f649121 | 2023-02-23 16:04:34 +0000 | [diff] [blame] | 16 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 17 | #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 | |
| 27 | static 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); |
AlexeiFedorov | eaec0c4 | 2023-02-01 18:13:32 +0000 | [diff] [blame] | 34 | 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 Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | void rmm_warmboot_main(void) |
| 41 | { |
| 42 | /* |
| 43 | * Do the rest of RMM architecture init |
| 44 | */ |
| 45 | rmm_arch_init(); |
| 46 | |
| 47 | /* |
| 48 | * Finish initializing the slot buffer mechanism |
| 49 | */ |
Javier Almansa Sobrino | ed93259 | 2023-01-24 12:50:41 +0000 | [diff] [blame] | 50 | slot_buf_finish_warmboot_init(); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | void rmm_main(void) |
| 54 | { |
| 55 | unsigned int rmm_el3_ifc_version = rmm_el3_ifc_get_version(); |
| 56 | unsigned int manifest_version = rmm_el3_ifc_get_manifest_version(); |
| 57 | |
| 58 | /* |
| 59 | * Report project name, version, build type and |
| 60 | * commit information if it is present |
| 61 | */ |
| 62 | NOTICE("Booting %s v.%s(%s) %s Built with %s\n", |
| 63 | NAME, VERSION, RMM_BUILD_TYPE, COMMIT_INFO, |
| 64 | #ifdef __clang__ |
| 65 | VER_STRING("Clang ", __clang_major__, __clang_minor__, |
| 66 | __clang_patchlevel__) |
| 67 | #else |
| 68 | VER_STRING("GCC ", __GNUC__, __GNUC_MINOR__, |
| 69 | __GNUC_PATCHLEVEL__) |
| 70 | #endif |
| 71 | ); |
| 72 | |
| 73 | /* Report Boot Interface version */ |
| 74 | NOTICE("RMM-EL3 Interface v.%u.%u\n", |
| 75 | RMM_EL3_IFC_GET_VERS_MAJOR(rmm_el3_ifc_version), |
| 76 | RMM_EL3_IFC_GET_VERS_MINOR(rmm_el3_ifc_version)); |
| 77 | |
| 78 | /* Report Boot Manifest version */ |
| 79 | NOTICE("Boot Manifest Interface v.%u.%u\n", |
| 80 | RMM_EL3_MANIFEST_GET_VERS_MAJOR(manifest_version), |
| 81 | RMM_EL3_MANIFEST_GET_VERS_MINOR(manifest_version)); |
| 82 | |
| 83 | /* Report RMI/RSI ABI versions and build timestamp */ |
| 84 | NOTICE("RMI/RSI ABI v.%u.%u/%u.%u built: %s %s\n", |
| 85 | RMI_ABI_VERSION_MAJOR, RMI_ABI_VERSION_MINOR, |
| 86 | RSI_ABI_VERSION_MAJOR, RSI_ABI_VERSION_MINOR, |
| 87 | __DATE__, __TIME__); |
| 88 | |
| 89 | rmm_warmboot_main(); |
| 90 | |
Arunachalam Ganapathy | 4f601e7 | 2023-05-22 11:49:29 +0100 | [diff] [blame^] | 91 | simd_init(); |
| 92 | |
| 93 | /* Initialize the NS SIMD context for all CPUs */ |
| 94 | init_all_cpus_ns_simd_context(); |
| 95 | |
Arunachalam Ganapathy | 5111993 | 2023-03-23 12:32:49 +0000 | [diff] [blame] | 96 | #ifdef RMM_FPU_USE_AT_REL2 |
Arunachalam Ganapathy | 4f601e7 | 2023-05-22 11:49:29 +0100 | [diff] [blame^] | 97 | simd_context_save(get_cpu_ns_simd_context()); |
Arunachalam Ganapathy | 5111993 | 2023-03-23 12:32:49 +0000 | [diff] [blame] | 98 | #endif |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 99 | if (attestation_init() != 0) { |
| 100 | WARN("Attestation init failed.\n"); |
| 101 | } |
Arunachalam Ganapathy | 5111993 | 2023-03-23 12:32:49 +0000 | [diff] [blame] | 102 | #ifdef RMM_FPU_USE_AT_REL2 |
| 103 | /* |
| 104 | * TODO: Do not save and restore NS state. Instead after |
| 105 | * attestation_init clear FPU state. |
| 106 | */ |
Arunachalam Ganapathy | 4f601e7 | 2023-05-22 11:49:29 +0100 | [diff] [blame^] | 107 | simd_context_restore(get_cpu_ns_simd_context()); |
Arunachalam Ganapathy | 5111993 | 2023-03-23 12:32:49 +0000 | [diff] [blame] | 108 | #endif |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 109 | } |