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 | { |
Javier Almansa Sobrino | cfd3254 | 2024-10-09 19:38:56 +0100 | [diff] [blame] | 28 | unsigned long hcrx_el2_init = HCRX_INIT; |
| 29 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 30 | MPAM(write_mpam2_el2(MPAM2_EL2_INIT)); |
| 31 | MPAM(write_mpamhcr_el2(MPAMHCR_EL2_INIT)); |
| 32 | SPE(write_pmscr_el2(PMSCR_EL2_INIT)); |
| 33 | |
| 34 | write_cnthctl_el2(CNTHCTL_EL2_INIT); |
AlexeiFedorov | eaec0c4 | 2023-02-01 18:13:32 +0000 | [diff] [blame] | 35 | write_vpidr_el2(read_midr_el1()); |
| 36 | write_mdcr_el2(MDCR_EL2_INIT | |
| 37 | INPLACE(MDCR_EL2_HPMN, |
| 38 | EXTRACT(PMCR_EL0_N, read_pmcr_el0()))); |
Javier Almansa Sobrino | cfd3254 | 2024-10-09 19:38:56 +0100 | [diff] [blame] | 39 | |
| 40 | /* Enable EL1 access to sctlr2_el1 if the register is present */ |
| 41 | if (is_feat_sctlr2x_present()) { |
| 42 | hcrx_el2_init |= HCRX_SCTLR2EN; |
| 43 | } |
| 44 | |
| 45 | write_hcrx_el2(hcrx_el2_init); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 46 | } |
| 47 | |
AlexeiFedorov | ee2fc82 | 2023-10-31 14:54:39 +0000 | [diff] [blame] | 48 | /* coverity[misra_c_2012_rule_8_4_violation:SUPPRESS] */ |
AlexeiFedorov | b0de4d5 | 2023-10-10 11:46:16 +0100 | [diff] [blame] | 49 | /* coverity[misra_c_2012_rule_8_7_violation:SUPPRESS] */ |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 50 | void rmm_warmboot_main(void) |
| 51 | { |
| 52 | /* |
| 53 | * Do the rest of RMM architecture init |
| 54 | */ |
| 55 | rmm_arch_init(); |
| 56 | |
| 57 | /* |
| 58 | * Finish initializing the slot buffer mechanism |
| 59 | */ |
Javier Almansa Sobrino | ed93259 | 2023-01-24 12:50:41 +0000 | [diff] [blame] | 60 | slot_buf_finish_warmboot_init(); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 61 | } |
| 62 | |
AlexeiFedorov | ee2fc82 | 2023-10-31 14:54:39 +0000 | [diff] [blame] | 63 | /* |
| 64 | * This function is called from rmm_entry() in head.S |
| 65 | * and should be defined with external linkage, no |
| 66 | * compatible declaration is required. |
| 67 | */ |
| 68 | /* coverity[misra_c_2012_rule_8_4_violation:SUPPRESS] */ |
AlexeiFedorov | b0de4d5 | 2023-10-10 11:46:16 +0100 | [diff] [blame] | 69 | /* coverity[misra_c_2012_rule_8_7_violation:SUPPRESS] */ |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 70 | void rmm_main(void) |
| 71 | { |
| 72 | unsigned int rmm_el3_ifc_version = rmm_el3_ifc_get_version(); |
| 73 | unsigned int manifest_version = rmm_el3_ifc_get_manifest_version(); |
Arunachalam Ganapathy | 4003b3c | 2024-11-05 18:02:10 +0000 | [diff] [blame^] | 74 | unsigned long rmi_revision = rmi_get_highest_supported_version(); |
| 75 | unsigned long rsi_revision = rsi_get_highest_supported_version(); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 76 | |
| 77 | /* |
| 78 | * Report project name, version, build type and |
| 79 | * commit information if it is present |
| 80 | */ |
Arunachalam Ganapathy | 4003b3c | 2024-11-05 18:02:10 +0000 | [diff] [blame^] | 81 | NOTICE("Booting %s v.%s(%s) %s Built: %s %s with %s\n", |
| 82 | NAME, VERSION, RMM_BUILD_TYPE, COMMIT_INFO, __DATE__, __TIME__, |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 83 | #ifdef __clang__ |
| 84 | VER_STRING("Clang ", __clang_major__, __clang_minor__, |
| 85 | __clang_patchlevel__) |
| 86 | #else |
| 87 | VER_STRING("GCC ", __GNUC__, __GNUC_MINOR__, |
| 88 | __GNUC_PATCHLEVEL__) |
| 89 | #endif |
| 90 | ); |
| 91 | |
| 92 | /* Report Boot Interface version */ |
| 93 | NOTICE("RMM-EL3 Interface v.%u.%u\n", |
| 94 | RMM_EL3_IFC_GET_VERS_MAJOR(rmm_el3_ifc_version), |
| 95 | RMM_EL3_IFC_GET_VERS_MINOR(rmm_el3_ifc_version)); |
| 96 | |
| 97 | /* Report Boot Manifest version */ |
| 98 | NOTICE("Boot Manifest Interface v.%u.%u\n", |
| 99 | RMM_EL3_MANIFEST_GET_VERS_MAJOR(manifest_version), |
| 100 | RMM_EL3_MANIFEST_GET_VERS_MINOR(manifest_version)); |
| 101 | |
Arunachalam Ganapathy | 4003b3c | 2024-11-05 18:02:10 +0000 | [diff] [blame^] | 102 | /* Report higher supported RMI revision */ |
| 103 | NOTICE("RMI ABI revision v%lu.%lu\n", |
| 104 | RMI_ABI_VERSION_GET_MAJOR(rmi_revision), |
| 105 | RMI_ABI_VERSION_GET_MINOR(rmi_revision)); |
| 106 | |
| 107 | /* Report higher supported RSI revision */ |
| 108 | NOTICE("RSI ABI revision v%lu.%lu\n", |
| 109 | RSI_ABI_VERSION_GET_MAJOR(rsi_revision), |
| 110 | RSI_ABI_VERSION_GET_MINOR(rsi_revision)); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 111 | |
| 112 | rmm_warmboot_main(); |
| 113 | |
Arunachalam Ganapathy | 4f601e7 | 2023-05-22 11:49:29 +0100 | [diff] [blame] | 114 | simd_init(); |
| 115 | |
| 116 | /* Initialize the NS SIMD context for all CPUs */ |
| 117 | init_all_cpus_ns_simd_context(); |
| 118 | |
Arunachalam Ganapathy | 5111993 | 2023-03-23 12:32:49 +0000 | [diff] [blame] | 119 | #ifdef RMM_FPU_USE_AT_REL2 |
Arunachalam Ganapathy | 4f601e7 | 2023-05-22 11:49:29 +0100 | [diff] [blame] | 120 | simd_context_save(get_cpu_ns_simd_context()); |
Arunachalam Ganapathy | 5111993 | 2023-03-23 12:32:49 +0000 | [diff] [blame] | 121 | #endif |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 122 | if (attestation_init() != 0) { |
| 123 | WARN("Attestation init failed.\n"); |
| 124 | } |
Arunachalam Ganapathy | 5111993 | 2023-03-23 12:32:49 +0000 | [diff] [blame] | 125 | #ifdef RMM_FPU_USE_AT_REL2 |
| 126 | /* |
| 127 | * TODO: Do not save and restore NS state. Instead after |
| 128 | * attestation_init clear FPU state. |
| 129 | */ |
Arunachalam Ganapathy | 4f601e7 | 2023-05-22 11:49:29 +0100 | [diff] [blame] | 130 | simd_context_restore(get_cpu_ns_simd_context()); |
Arunachalam Ganapathy | 5111993 | 2023-03-23 12:32:49 +0000 | [diff] [blame] | 131 | #endif |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 132 | } |