Skip to content

Commit 13053c8

Browse files
author
Axel Heider
committed
vm_arm: isolate PCI dependencies
Don't compile in virtual PCI handling unless enabled. Signed-off-by: Axel Heider <axel.heider@hensoldt.net>
1 parent 14e959f commit 13053c8

2 files changed

Lines changed: 67 additions & 43 deletions

File tree

arm_vm_helpers.cmake

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,19 @@ function(DeclareCAmkESARMVM init_component)
4545
vm_src
4646
${ARM_VM_PROJECT_DIR}/components/VM_Arm/src/main.c
4747
${ARM_VM_PROJECT_DIR}/components/VM_Arm/src/fdt_manipulation.c
48-
${ARM_VM_PROJECT_DIR}/components/VM_Arm/src/crossvm.c
4948
${ARM_VM_PROJECT_DIR}/components/VM_Arm/src/modules/map_frame_hack.c
5049
${ARM_VM_PROJECT_DIR}/components/VM_Arm/src/modules/init_ram.c
5150
)
5251

52+
if(VmPCISupport)
53+
list(
54+
APPEND
55+
vm_src ${ARM_VM_PROJECT_DIR}/components/VM_Arm/src/modules/vpci.c
56+
# Currently, there the cross vm connection to built on top of PCI
57+
${ARM_VM_PROJECT_DIR}/components/VM_Arm/src/crossvm.c
58+
)
59+
endif()
60+
5361
if(VmVirtUart)
5462
list(APPEND vm_src ${ARM_VM_PROJECT_DIR}/components/VM_Arm/src/modules/vuart_init.c)
5563
endif()

components/VM_Arm/src/main.c

Lines changed: 58 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,15 @@
4040
#include <sel4vmmplatsupport/drivers/virtio_con.h>
4141

4242
#include <sel4vmmplatsupport/arch/vusb.h>
43+
44+
#ifdef CONFIG_VM_PCI_SUPPORT
4345
#include <sel4vmmplatsupport/arch/vpci.h>
44-
#include <sel4vmmplatsupport/guest_image.h>
4546
#include <sel4vmmplatsupport/drivers/pci_helper.h>
47+
/* Currently, there the cross vm connection to built on top of PCI */
4648
#include <sel4vmmplatsupport/drivers/cross_vm_connection.h>
49+
#endif
50+
51+
#include <sel4vmmplatsupport/guest_image.h>
4752
#include <sel4vmmplatsupport/arch/guest_boot_init.h>
4853
#include <sel4vmmplatsupport/arch/guest_reboot.h>
4954
#include <sel4vmmplatsupport/arch/guest_vcpu_fault.h>
@@ -96,7 +101,11 @@ allocman_t *allocman;
96101
seL4_CPtr _fault_endpoint;
97102
irq_server_t *_irq_server;
98103

99-
vmm_pci_space_t *pci;
104+
#ifdef CONFIG_VM_PCI_SUPPORT
105+
vmm_pci_space_t *pci = NULL;
106+
int gic_phandle = 0;
107+
#endif
108+
100109
vmm_io_port_list_t *io_ports;
101110
reboot_hooks_list_t reboot_hooks_list;
102111

@@ -680,19 +689,8 @@ static USED SECTION("_vmm_module") struct {} dummy_module;
680689
extern vmm_module_t __start__vmm_module[];
681690
extern vmm_module_t __stop__vmm_module[];
682691

683-
static int install_vm_devices(vm_t *vm, const vm_config_t *vm_config)
692+
static int install_vm_modules(vm_t *vm, const vm_config_t *vm_config)
684693
{
685-
int err;
686-
687-
/* Install virtual devices */
688-
if (config_set(CONFIG_VM_PCI_SUPPORT)) {
689-
err = vm_install_vpci(vm, io_ports, pci);
690-
if (err) {
691-
ZF_LOGE("Failed to install VPCI device (%d)", err);
692-
return -1;
693-
}
694-
}
695-
696694
int max_vmm_modules = (int)(__stop__vmm_module - __start__vmm_module);
697695
int num_vmm_modules = 0;
698696
for (vmm_module_t *i = __start__vmm_module; i < __stop__vmm_module; i++) {
@@ -853,6 +851,24 @@ static int vm_dtb_init(vm_t *vm, const vm_config_t *vm_config)
853851

854852
/* Now the DTB is in gen_dtb_buf and all manipulation must happen there. */
855853

854+
#ifdef CONFIG_VM_PCI_SUPPORT
855+
/* VPCI needs the GIC's phandle for the interrupt references. Thus the DTB
856+
* we generate must have a GIC node. Usually, it is built from the the node
857+
* in original DTB, thus we assume it exists here.
858+
*/
859+
int gic_offset = fdt_path_offset(gen_dtb_buf, GIC_NODE_PATH);
860+
if (gic_offset < 0) {
861+
ZF_LOGE("Failed to find gic node from path '%s' (%d)",
862+
GIC_NODE_PATH, gic_offset);
863+
return -1;
864+
}
865+
gic_phandle = fdt_get_phandle(gen_dtb_buf, gic_offset);
866+
if (0 == gic_phandle) {
867+
ZF_LOGE("Failed to find phandle in gic node");
868+
return -1;
869+
}
870+
#endif /* CONFIG_VM_PCI_SUPPORT */
871+
856872
/* generate a memory node */
857873
err = fdt_generate_memory_node(gen_dtb_buf, vm_config->ram.base,
858874
vm_config->ram.size);
@@ -868,27 +884,17 @@ static int vm_dtb_finalize(vm_t *vm, const vm_config_t *vm_config)
868884
{
869885
assert(vm_config->generate_dtb);
870886

871-
if (config_set(CONFIG_VM_PCI_SUPPORT)) {
872-
/* Modules can add PCI devices, so the PCI device tree node can be
873-
* created only after all modules have been set up.
874-
*/
875-
int gic_offset = fdt_path_offset(fdt_ori, GIC_NODE_PATH);
876-
if (gic_offset < 0) {
877-
ZF_LOGE("Failed to find gic node from path '%s' (%d)",
878-
GIC_NODE_PATH, gic_offset);
879-
return -1;
880-
}
881-
int gic_phandle = fdt_get_phandle(fdt_ori, gic_offset);
882-
if (0 == gic_phandle) {
883-
ZF_LOGE("Failed to find phandle in gic node");
884-
return -1;
885-
}
886-
int err = fdt_generate_vpci_node(vm, pci, gen_dtb_buf, gic_phandle);
887-
if (err) {
888-
ZF_LOGE("Couldn't generate vpci_node (%d)", err);
889-
return -1;
890-
}
887+
#ifdef CONFIG_VM_PCI_SUPPORT
888+
/* Modules can add PCI devices, so the PCI device tree node can be created
889+
* only after all modules have been set up.
890+
*/
891+
assert(gic_phandle > 0); /* We should never arrive here in this case. */
892+
int err = fdt_generate_vpci_node(vm, pci, gen_dtb_buf, gic_phandle);
893+
if (err) {
894+
ZF_LOGE("Couldn't generate vpci_node (%d)", err);
895+
return -1;
891896
}
897+
#endif /* CONFIG_VM_PCI_SUPPORT */
892898

893899
fdt_pack(gen_dtb_buf);
894900
return 0;
@@ -1172,12 +1178,6 @@ static int main_continued(void)
11721178
return -1;
11731179
}
11741180

1175-
err = vmm_pci_init(&pci);
1176-
if (err) {
1177-
ZF_LOGE("Failed to initialise vmm pci");
1178-
return err;
1179-
}
1180-
11811181
err = vmm_io_port_init(&io_ports, FREE_IOPORT_START);
11821182
if (err) {
11831183
ZF_LOGE("Failed to initialise VM ioports");
@@ -1258,10 +1258,26 @@ static int main_continued(void)
12581258
return -1;
12591259
}
12601260

1261+
#ifdef CONFIG_VM_PCI_SUPPORT
1262+
1263+
err = vmm_pci_init(&pci);
1264+
if (err) {
1265+
ZF_LOGE("Failed to initialise vmm pci (%d)", err);
1266+
return -1;
1267+
}
1268+
1269+
err = vm_install_vpci(vm, io_ports, pci);
1270+
if (err) {
1271+
ZF_LOGE("Failed to install VPCI device (%d)", err);
1272+
return -1;
1273+
}
1274+
1275+
#endif /* CONFIG_VM_PCI_SUPPORT */
1276+
12611277
/* Install devices */
1262-
err = install_vm_devices(&vm, &vm_config);
1278+
err = install_vm_modules(&vm, &vm_config);
12631279
if (err) {
1264-
ZF_LOGE("Error: Failed to install VM devices\n");
1280+
ZF_LOGE("Error: Failed to install VM modules\n");
12651281
seL4_DebugHalt();
12661282
return -1;
12671283
}

0 commit comments

Comments
 (0)