Skip to content

Commit f3ad38d

Browse files
author
Axel Heider
committed
vm_arm: move vpci code to dedicated module
This calls vmm_pci_init() only when vpci is enabled. Signed-off-by: Axel Heider <axel.heider@hensoldt.net>
1 parent 8d7cd52 commit f3ad38d

3 files changed

Lines changed: 84 additions & 40 deletions

File tree

arm_vm_helpers.cmake

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,18 @@ 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+
${ARM_VM_PROJECT_DIR}/components/VM_Arm/src/crossvm.c
57+
)
58+
endif()
59+
5360
if(VmVirtUart)
5461
list(APPEND vm_src ${ARM_VM_PROJECT_DIR}/components/VM_Arm/src/modules/vuart_init.c)
5562
endif()

components/VM_Arm/src/main.c

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,8 @@
3838
#include <sel4vm/guest_irq_controller.h>
3939

4040
#include <sel4vmmplatsupport/drivers/virtio_con.h>
41-
42-
#include <sel4vmmplatsupport/arch/vusb.h>
43-
#include <sel4vmmplatsupport/arch/vpci.h>
4441
#include <sel4vmmplatsupport/guest_image.h>
45-
#include <sel4vmmplatsupport/drivers/pci_helper.h>
46-
#include <sel4vmmplatsupport/drivers/cross_vm_connection.h>
42+
#include <sel4vmmplatsupport/arch/vusb.h>
4743
#include <sel4vmmplatsupport/arch/guest_boot_init.h>
4844
#include <sel4vmmplatsupport/arch/guest_reboot.h>
4945
#include <sel4vmmplatsupport/arch/guest_vcpu_fault.h>
@@ -97,7 +93,6 @@ allocman_t *allocman;
9793
seL4_CPtr _fault_endpoint;
9894
irq_server_t *_irq_server;
9995

100-
vmm_pci_space_t *pci;
10196
vmm_io_port_list_t *io_ports;
10297
reboot_hooks_list_t reboot_hooks_list;
10398

@@ -687,17 +682,6 @@ extern vmm_module_t __stop__vmm_module[];
687682

688683
static int install_vm_devices(vm_t *vm, const vm_config_t *vm_config)
689684
{
690-
int err;
691-
692-
/* Install virtual devices */
693-
if (config_set(CONFIG_VM_PCI_SUPPORT)) {
694-
err = vm_install_vpci(vm, io_ports, pci);
695-
if (err) {
696-
ZF_LOGE("Failed to install VPCI device");
697-
return -1;
698-
}
699-
}
700-
701685
int max_vmm_modules = (int)(__stop__vmm_module - __start__vmm_module);
702686
int num_vmm_modules = 0;
703687
for (vmm_module_t *i = __start__vmm_module; i < __stop__vmm_module; i++) {
@@ -707,7 +691,6 @@ static int install_vm_devices(vm_t *vm, const vm_config_t *vm_config)
707691
}
708692

709693
return 0;
710-
711694
}
712695

713696
static int route_irq(int irq_num, vm_vcpu_t *vcpu, irq_server_t *irq_server)
@@ -875,22 +858,11 @@ static int vm_dtb_finalize(vm_t *vm, const vm_config_t *vm_config)
875858
assert(vm_config->generate_dtb);
876859

877860
if (config_set(CONFIG_VM_PCI_SUPPORT)) {
878-
/* Modules can add PCI devices, so the PCI device tree node can be
879-
* created only after all modules have been set up.
880-
*/
881-
int gic_offset = fdt_path_offset(fdt_ori, GIC_NODE_PATH);
882-
if (gic_offset < 0) {
883-
ZF_LOGE("Failed to find gic node from path: %s", GIC_NODE_PATH);
884-
return -1;
885-
}
886-
int gic_phandle = fdt_get_phandle(fdt_ori, gic_offset);
887-
if (0 == gic_phandle) {
888-
ZF_LOGE("Failed to find phandle in gic node");
889-
return -1;
890-
}
891-
int err = fdt_generate_vpci_node(vm, pci, gen_dtb_buf, gic_phandle);
861+
extern int vpci_update_dtb(vm_t *vm, const vm_config_t *vm_config, void *dtb,
862+
void *fdt, char const *gic_node);
863+
int err = vpci_update_dtb(vm, vm_config, gen_dtb_buf, fdt_ori, GIC_NODE_PATH);
892864
if (err) {
893-
ZF_LOGE("Couldn't generate vpci_node (%d)", err);
865+
ZF_LOGE("Couldn't generate VPCI device tree node (%d)\n", err);
894866
return -1;
895867
}
896868
}
@@ -1191,12 +1163,6 @@ static int main_continued(void)
11911163
return -1;
11921164
}
11931165

1194-
err = vmm_pci_init(&pci);
1195-
if (err) {
1196-
ZF_LOGE("Failed to initialise vmm pci");
1197-
return err;
1198-
}
1199-
12001166
err = vmm_io_port_init(&io_ports, FREE_IOPORT_START);
12011167
if (err) {
12021168
ZF_LOGE("Failed to initialise VM ioports");
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright 2023, Hensoldt Cyber
3+
*
4+
* SPDX-License-Identifier: BSD-2-Clause
5+
*/
6+
7+
#include <vmlinux.h>
8+
#include <camkes.h>
9+
10+
#include <sel4vmmplatsupport/ioports.h>
11+
#include <sel4vmmplatsupport/arch/vpci.h>
12+
#include <sel4vmmplatsupport/drivers/pci_helper.h>
13+
14+
#include <libfdt.h>
15+
16+
extern vmm_io_port_list_t *io_ports;
17+
18+
/* Can't make this static, because others uses it */
19+
vmm_pci_space_t *pci = NULL;
20+
21+
/* Various other modules can register PCI devices. Update the device tree
22+
* eventually.
23+
*/
24+
int vpci_update_dtb(vm_t *vm, const vm_config_t *vm_config, void *dtb,
25+
void *fdt, char const *gic_node)
26+
{
27+
if (!vm_config->generate_dtb) {
28+
return 0;
29+
}
30+
31+
ZF_LOGF_IF(!fdt_ori, "fdt not set");
32+
33+
int gic_offset = fdt_path_offset(fdt, gic_node);
34+
if (gic_offset < 0) {
35+
ZF_LOGE("Failed to find gic node from path: %s", gic_node);
36+
return -1;
37+
}
38+
int gic_phandle = fdt_get_phandle(fdt, gic_offset);
39+
if (0 == gic_phandle) {
40+
ZF_LOGE("Failed to find phandle in gic node (%d)", gic_phandle);
41+
return -1;
42+
}
43+
int err = fdt_generate_vpci_node(vm, pci, dtb, gic_phandle);
44+
if (err) {
45+
ZF_LOGE("Couldn't generate vpci_node (%d)", err);
46+
return -1;
47+
}
48+
49+
}
50+
51+
static void vpci_init_module(vm_t *vm, void *cookie)
52+
{
53+
int err;
54+
55+
err = vmm_pci_init(&pci);
56+
if (err) {
57+
ZF_LOGE("Failed to initialise vmm pci (%d)", err);
58+
return;
59+
}
60+
61+
ZF_LOGF_IF(!io_ports, "io_ports not set");
62+
63+
err = vm_install_vpci(vm, io_ports, pci);
64+
if (err) {
65+
ZF_LOGE("Failed to install VPCI device (%d)", err);
66+
return;
67+
}
68+
69+
}
70+
71+
DEFINE_MODULE(vpci, NULL, vpci_init_module)

0 commit comments

Comments
 (0)