Skip to content

Commit 00ef35e

Browse files
author
Axel Heider
committed
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 <axel.heider@hensoldt.net>
1 parent e842e9d commit 00ef35e

3 files changed

Lines changed: 32 additions & 27 deletions

File tree

arm_vm_helpers.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ function(DeclareCAmkESARMVM init_component)
4747
${ARM_VM_PROJECT_DIR}/components/VM_Arm/src/fdt_manipulation.c
4848
${ARM_VM_PROJECT_DIR}/components/VM_Arm/src/crossvm.c
4949
${ARM_VM_PROJECT_DIR}/components/VM_Arm/src/modules/map_frame_hack.c
50-
${ARM_VM_PROJECT_DIR}/components/VM_Arm/src/modules/init_ram.c
5150
)
5251

5352
if(VmVirtUart)

components/VM_Arm/src/main.c

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,13 +662,36 @@ static void irq_handler(void *data, ps_irq_acknowledge_fn_t acknowledge_fn, void
662662
}
663663
}
664664

665+
/* Default RAM initialization. Modules can overwrite this weak function with a
666+
* custom initialization, e.g. to use memory shared with other components or
667+
* mapped on demand.
668+
*/
669+
WEAK int vm_init_ram(vm_t *vm, const vm_config_t *vm_config)
670+
{
671+
/* A VM without RAM is highly unusual and unlikely to work. But there might
672+
* be special VM configurations where modules create special RAM areas.
673+
*/
674+
if (0 == vm_config->ram.size) {
675+
ZF_LOGW("no RAM defined");
676+
return 0;
677+
}
678+
679+
int err = vm_ram_register_at(vm, vm_config->ram.base, vm_config->ram.size,
680+
vm->mem.map_one_to_one);
681+
if (err) {
682+
ZF_LOGE("RAM registration failed (%d)", err);
683+
return -1;
684+
}
685+
686+
return 0;
687+
}
665688

666689
/* Force the _vmm_module section to be created even if no modules are defined. */
667690
static USED SECTION("_vmm_module") struct {} dummy_module;
668691
extern vmm_module_t __start__vmm_module[];
669692
extern vmm_module_t __stop__vmm_module[];
670693

671-
static int install_vm_devices(vm_t *vm)
694+
static int install_vm_devices(vm_t *vm, const vm_config_t *vm_config)
672695
{
673696
int err;
674697

@@ -678,6 +701,13 @@ static int install_vm_devices(vm_t *vm)
678701
assert(!err);
679702
}
680703

704+
/* Initialize guest RAM. */
705+
err = vm_init_ram(vm, vm_config);
706+
if (err) {
707+
ZF_LOGE("Failed to initialize RAM (%d)", err);
708+
return -1;
709+
}
710+
681711
int max_vmm_modules = (int)(__stop__vmm_module - __start__vmm_module);
682712
int num_vmm_modules = 0;
683713
for (vmm_module_t *i = __start__vmm_module; i < __stop__vmm_module; i++) {
@@ -874,7 +904,7 @@ static int load_vm(vm_t *vm, const vm_config_t *vm_config)
874904
vm->mem.map_one_to_one = vm_config->map_one_to_one; /* Map memory 1:1 if configured to do so */
875905

876906
/* Install devices */
877-
err = install_vm_devices(vm);
907+
err = install_vm_devices(vm, vm_config);
878908
if (err) {
879909
printf("Error: Failed to install VM devices\n");
880910
return -1;

components/VM_Arm/src/modules/init_ram.c

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)