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 | |
| 6 | #include <arch.h> |
| 7 | #include <debug.h> |
| 8 | #include <gic.h> |
| 9 | #include <host_utils.h> |
| 10 | #include <platform_api.h> |
| 11 | #include <rmm_el3_ifc.h> |
| 12 | #include <stdint.h> |
| 13 | #include <xlat_tables.h> |
| 14 | |
| 15 | #define RMM_EL3_IFC_ABI_VERSION (RMM_EL3_IFC_SUPPORTED_VERSION) |
| 16 | #define RMM_EL3_MAX_CPUS (1U) |
| 17 | |
| 18 | /* |
| 19 | * Define and set the Boot Interface arguments. |
| 20 | */ |
| 21 | static unsigned char el3_rmm_shared_buffer[PAGE_SIZE] __aligned(PAGE_SIZE); |
| 22 | |
| 23 | /* |
| 24 | * Create a basic boot manifest. |
| 25 | */ |
| 26 | static struct rmm_core_manifest *boot_manifest = |
| 27 | (struct rmm_core_manifest *)el3_rmm_shared_buffer; |
| 28 | |
| 29 | /* |
| 30 | * Performs some initialization needed before RMM can be ran, such as |
| 31 | * setting up callbacks for sysreg access. |
| 32 | */ |
| 33 | static void setup_sysreg_and_boot_manifest(void) |
| 34 | { |
| 35 | /* |
| 36 | * Initialize ID_AA64MMFR0_EL1 with a physical address |
| 37 | * range of 48 bits (PARange bits set to 0b0101) |
| 38 | */ |
| 39 | (void)host_util_set_default_sysreg_cb("id_aa64mmfr0_el1", |
| 40 | INPLACE(ID_AA64MMFR0_EL1_PARANGE, 5UL)); |
| 41 | |
| 42 | /* |
| 43 | * Initialize ICH_VTR_EL2 with 6 preemption bits. |
| 44 | * (PREbits is equal number of preemption bits minus one) |
| 45 | */ |
| 46 | (void)host_util_set_default_sysreg_cb("ich_vtr_el2", |
| 47 | INPLACE(ICH_VTR_EL2_PRE_BITS, 5UL)); |
| 48 | |
| 49 | /* SCTLR_EL2 is reset to zero */ |
| 50 | (void)host_util_set_default_sysreg_cb("sctlr_el2", 0UL); |
| 51 | |
| 52 | /* Initialize the boot manifest */ |
| 53 | boot_manifest->version = RMM_EL3_IFC_SUPPORTED_VERSION; |
| 54 | boot_manifest->plat_data = (uintptr_t)NULL; |
| 55 | } |
| 56 | |
| 57 | /* |
| 58 | * Function to emulate the MMU enablement for the fake_host architecture. |
| 59 | */ |
| 60 | static void enable_fake_host_mmu(void) |
| 61 | { |
| 62 | write_sctlr_el2(SCTLR_EL2_WXN | SCTLR_EL2_M); |
| 63 | } |
| 64 | |
| 65 | void rmm_main(void); |
| 66 | |
| 67 | int main(int argc, char *argv[]) |
| 68 | { |
| 69 | (void)argc; |
| 70 | (void)argv; |
| 71 | |
| 72 | setup_sysreg_and_boot_manifest(); |
| 73 | |
| 74 | VERBOSE("RMM: Beginning of Fake Host execution\n"); |
| 75 | |
| 76 | plat_setup(0UL, |
| 77 | RMM_EL3_IFC_ABI_VERSION, |
| 78 | RMM_EL3_MAX_CPUS, |
| 79 | (uintptr_t)&el3_rmm_shared_buffer); |
| 80 | |
| 81 | /* |
| 82 | * Enable the MMU. This is needed as some initialization code |
| 83 | * called by rmm_main() asserts that the mmu is enabled. |
| 84 | */ |
| 85 | enable_fake_host_mmu(); |
| 86 | |
| 87 | rmm_main(); |
| 88 | |
| 89 | VERBOSE("RMM: Fake Host execution completed\n"); |
| 90 | |
| 91 | return 0; |
| 92 | } |