Skip to content

Commit

Permalink
vm_arm: inline init_ram module
Browse files Browse the repository at this point in the history
- inline code from the module to simplify VMM.
- define a weak function vm_init_ram() instead.
- improve comments.

Signed-off-by: Axel Heider <[email protected]>
  • Loading branch information
Axel Heider committed Jun 15, 2023
1 parent a4ad4da commit 3c51dbc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 25 deletions.
1 change: 0 additions & 1 deletion arm_vm_helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
32 changes: 32 additions & 0 deletions components/VM_Arm/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
24 changes: 0 additions & 24 deletions components/VM_Arm/src/modules/init_ram.c

This file was deleted.

0 comments on commit 3c51dbc

Please sign in to comment.