From ef3800a95ceaa38c04a522f30d2ce058aadab9d2 Mon Sep 17 00:00:00 2001 From: Axel Heider Date: Mon, 20 Mar 2023 17:38:25 +0100 Subject: [PATCH] vm_arm: inline init_ram module - inline code from the module to simplify VMM. - define a weak function vm_init_ram() instead. - improve comments. Signed-off-by: Axel Heider --- arm_vm_helpers.cmake | 1 - components/VM_Arm/src/main.c | 32 ++++++++++++++++++++++++ components/VM_Arm/src/modules/init_ram.c | 24 ------------------ 3 files changed, 32 insertions(+), 25 deletions(-) delete mode 100644 components/VM_Arm/src/modules/init_ram.c diff --git a/arm_vm_helpers.cmake b/arm_vm_helpers.cmake index 4aea6663..e46a9af0 100644 --- a/arm_vm_helpers.cmake +++ b/arm_vm_helpers.cmake @@ -47,7 +47,6 @@ function(DeclareCAmkESARMVM init_component) ${ARM_VM_PROJECT_DIR}/components/VM_Arm/src/fdt_manipulation.c ${ARM_VM_PROJECT_DIR}/components/VM_Arm/src/crossvm.c ${ARM_VM_PROJECT_DIR}/components/VM_Arm/src/modules/map_frame_hack.c - ${ARM_VM_PROJECT_DIR}/components/VM_Arm/src/modules/init_ram.c ) if(VmVirtUart) diff --git a/components/VM_Arm/src/main.c b/components/VM_Arm/src/main.c index db9ddb81..620f0006 100644 --- a/components/VM_Arm/src/main.c +++ b/components/VM_Arm/src/main.c @@ -674,6 +674,31 @@ static void irq_handler(void *data, ps_irq_acknowledge_fn_t acknowledge_fn, void } } +/* Default RAM initialization. Modules can overwrite this weak function with a + * custom initialization, e.g. to use memory shared with other components or + * mapped on demand. + */ +WEAK int vm_init_ram(vm_t *vm, const vm_config_t *vm_config) +{ + /* A VM without RAM is highly unusual and unlikely to work. But there might + * be special VM configurations where modules create specific RAM areas. In + * this case, this weak RAM init function here should be overwritten also, + * that's why we print the warning. + */ + if (0 == vm_config->ram.size) { + ZF_LOGW("no standard RAM defined"); + return 0; + } + + int err = vm_ram_register_at(vm, vm_config->ram.base, vm_config->ram.size, + vm->mem.map_one_to_one); + if (err) { + ZF_LOGE("RAM registration failed (%d)", err); + return -1; + } + + return 0; +} /* Force the _vmm_module section to be created even if no modules are defined. */ static USED SECTION("_vmm_module") struct {} dummy_module; @@ -684,6 +709,13 @@ static int install_vm_devices(vm_t *vm, const vm_config_t *vm_config) { int err; + /* Initialize guest RAM. */ + err = vm_init_ram(vm, vm_config); + if (err) { + ZF_LOGE("Failed to initialize RAM (%d)", err); + return -1; + } + /* Install virtual devices */ if (config_set(CONFIG_VM_PCI_SUPPORT)) { err = vm_install_vpci(vm, io_ports, pci); diff --git a/components/VM_Arm/src/modules/init_ram.c b/components/VM_Arm/src/modules/init_ram.c deleted file mode 100644 index 326fc66f..00000000 --- a/components/VM_Arm/src/modules/init_ram.c +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230) - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include -#include -#include -#include -#include -#include -#include - -void WEAK init_ram_module(vm_t *vm, void *cookie) -{ - int err = vm_ram_register_at(vm, - vm_config.ram.base, - vm_config.ram.size, - vm->mem.map_one_to_one); - assert(!err); -} - -DEFINE_MODULE(init_ram, NULL, init_ram_module)