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 | |
| 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 | |
| 26 | static 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); |
AlexeiFedorov | eaec0c4 | 2023-02-01 18:13:32 +0000 | [diff] [blame] | 33 | 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()))); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 37 | } |
| 38 | |
AlexeiFedorov | ee2fc82 | 2023-10-31 14:54:39 +0000 | [diff] [blame] | 39 | /* coverity[misra_c_2012_rule_8_4_violation:SUPPRESS] */ |
AlexeiFedorov | b0de4d5 | 2023-10-10 11:46:16 +0100 | [diff] [blame] | 40 | /* coverity[misra_c_2012_rule_8_7_violation:SUPPRESS] */ |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 41 | void 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 Sobrino | ed93259 | 2023-01-24 12:50:41 +0000 | [diff] [blame] | 51 | slot_buf_finish_warmboot_init(); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 52 | } |
| 53 | |
AlexeiFedorov | ee2fc82 | 2023-10-31 14:54:39 +0000 | [diff] [blame] | 54 | /* |
| 55 | * This function is called from rmm_entry() in head.S |
| 56 | * and should be defined with external linkage, no |
| 57 | * compatible declaration is required. |
| 58 | */ |
| 59 | /* coverity[misra_c_2012_rule_8_4_violation:SUPPRESS] */ |
AlexeiFedorov | b0de4d5 | 2023-10-10 11:46:16 +0100 | [diff] [blame] | 60 | /* coverity[misra_c_2012_rule_8_7_violation:SUPPRESS] */ |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 61 | void rmm_main(void) |
| 62 | { |
| 63 | unsigned int rmm_el3_ifc_version = rmm_el3_ifc_get_version(); |
| 64 | unsigned int manifest_version = rmm_el3_ifc_get_manifest_version(); |
| 65 | |
| 66 | /* |
| 67 | * Report project name, version, build type and |
| 68 | * commit information if it is present |
| 69 | */ |
| 70 | NOTICE("Booting %s v.%s(%s) %s Built with %s\n", |
| 71 | NAME, VERSION, RMM_BUILD_TYPE, COMMIT_INFO, |
| 72 | #ifdef __clang__ |
| 73 | VER_STRING("Clang ", __clang_major__, __clang_minor__, |
| 74 | __clang_patchlevel__) |
| 75 | #else |
| 76 | VER_STRING("GCC ", __GNUC__, __GNUC_MINOR__, |
| 77 | __GNUC_PATCHLEVEL__) |
| 78 | #endif |
| 79 | ); |
| 80 | |
| 81 | /* Report Boot Interface version */ |
| 82 | NOTICE("RMM-EL3 Interface v.%u.%u\n", |
| 83 | RMM_EL3_IFC_GET_VERS_MAJOR(rmm_el3_ifc_version), |
| 84 | RMM_EL3_IFC_GET_VERS_MINOR(rmm_el3_ifc_version)); |
| 85 | |
| 86 | /* Report Boot Manifest version */ |
| 87 | NOTICE("Boot Manifest Interface v.%u.%u\n", |
| 88 | RMM_EL3_MANIFEST_GET_VERS_MAJOR(manifest_version), |
| 89 | RMM_EL3_MANIFEST_GET_VERS_MINOR(manifest_version)); |
| 90 | |
| 91 | /* Report RMI/RSI ABI versions and build timestamp */ |
AlexeiFedorov | ddf5daf | 2023-10-10 14:28:56 +0100 | [diff] [blame] | 92 | NOTICE("RMI/RSI ABI v.%lu.%lu/%lu.%lu built: %s %s\n", |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 93 | RMI_ABI_VERSION_MAJOR, RMI_ABI_VERSION_MINOR, |
| 94 | RSI_ABI_VERSION_MAJOR, RSI_ABI_VERSION_MINOR, |
| 95 | __DATE__, __TIME__); |
| 96 | |
| 97 | rmm_warmboot_main(); |
| 98 | |
Arunachalam Ganapathy | 4f601e7 | 2023-05-22 11:49:29 +0100 | [diff] [blame] | 99 | simd_init(); |
| 100 | |
| 101 | /* Initialize the NS SIMD context for all CPUs */ |
| 102 | init_all_cpus_ns_simd_context(); |
| 103 | |
Arunachalam Ganapathy | 5111993 | 2023-03-23 12:32:49 +0000 | [diff] [blame] | 104 | #ifdef RMM_FPU_USE_AT_REL2 |
Arunachalam Ganapathy | 4f601e7 | 2023-05-22 11:49:29 +0100 | [diff] [blame] | 105 | simd_context_save(get_cpu_ns_simd_context()); |
Arunachalam Ganapathy | 5111993 | 2023-03-23 12:32:49 +0000 | [diff] [blame] | 106 | #endif |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 107 | if (attestation_init() != 0) { |
| 108 | WARN("Attestation init failed.\n"); |
| 109 | } |
Arunachalam Ganapathy | 5111993 | 2023-03-23 12:32:49 +0000 | [diff] [blame] | 110 | #ifdef RMM_FPU_USE_AT_REL2 |
| 111 | /* |
| 112 | * TODO: Do not save and restore NS state. Instead after |
| 113 | * attestation_init clear FPU state. |
| 114 | */ |
Arunachalam Ganapathy | 4f601e7 | 2023-05-22 11:49:29 +0100 | [diff] [blame] | 115 | simd_context_restore(get_cpu_ns_simd_context()); |
Arunachalam Ganapathy | 5111993 | 2023-03-23 12:32:49 +0000 | [diff] [blame] | 116 | #endif |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 117 | } |