Specify the location of device-tree and its size, as Gunyah requires the device-tree to be parsed before VM can begin its execution.
Signed-off-by: Srivatsa Vaddagiri <quic_svadd...@quicinc.com> --- MAINTAINERS | 1 + include/sysemu/gunyah.h | 2 ++ accel/stubs/gunyah-stub.c | 5 +++++ hw/arm/virt.c | 6 ++++++ target/arm/gunyah.c | 45 +++++++++++++++++++++++++++++++++++++++ target/arm/meson.build | 3 +++ 6 files changed, 62 insertions(+) create mode 100644 target/arm/gunyah.c diff --git a/MAINTAINERS b/MAINTAINERS index d0289ded2f..c42fdc2afd 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -527,6 +527,7 @@ GUNYAH M: Srivatsa Vaddagiri <quic_svadd...@quicinc.com> S: Maintained F: accel/gunyah +F: target/arm/gunyah.c F: include/sysemu/gunyah.h F: include/sysemu/gunyah_int.h F: target/arm/arm_gicv3_gunyah.c diff --git a/include/sysemu/gunyah.h b/include/sysemu/gunyah.h index 78cb80f01e..ba4862a1a6 100644 --- a/include/sysemu/gunyah.h +++ b/include/sysemu/gunyah.h @@ -29,4 +29,6 @@ typedef struct GUNYAHState GUNYAHState; DECLARE_INSTANCE_CHECKER(GUNYAHState, GUNYAH_STATE, TYPE_GUNYAH_ACCEL) +int gunyah_arm_set_dtb(uint64_t dtb_start, uint64_t dtb_size); + #endif /* QEMU_GUNYAH_H */ diff --git a/accel/stubs/gunyah-stub.c b/accel/stubs/gunyah-stub.c index 2028fa04c7..8f6e952938 100644 --- a/accel/stubs/gunyah-stub.c +++ b/accel/stubs/gunyah-stub.c @@ -16,3 +16,8 @@ void gunyah_set_swiotlb_size(uint64_t size) { return; } + +int gunyah_arm_set_dtb(__u64 dtb_start, __u64 dtb_size) +{ + return -1; +} diff --git a/hw/arm/virt.c b/hw/arm/virt.c index bfb7f3d92e..a485388d3c 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -1738,6 +1738,12 @@ void virt_machine_done(Notifier *notifier, void *data) exit(1); } + if (gunyah_enabled()) { + if (gunyah_arm_set_dtb(info->dtb_start, vms->fdt_size)) { + exit(1); + } + } + fw_cfg_add_extra_pci_roots(vms->bus, vms->fw_cfg); virt_acpi_setup(vms); diff --git a/target/arm/gunyah.c b/target/arm/gunyah.c new file mode 100644 index 0000000000..d655cd9a79 --- /dev/null +++ b/target/arm/gunyah.c @@ -0,0 +1,45 @@ +/* + * QEMU Gunyah hypervisor support + * + * Copyright(c) 2023 Qualcomm Innovation Center, Inc. All Rights Reserved. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qemu/error-report.h" +#include "sysemu/gunyah.h" +#include "sysemu/gunyah_int.h" +#include "linux-headers/linux/gunyah.h" + +/* + * Specify location of device-tree in guest address space. + * + * @dtb_start - Guest physical address where VM's device-tree is found + * @dtb_size - Size of device-tree (and any free space after it). + * + * RM or Resource Manager VM is a trusted and privileged VM that works in + * collaboration with Gunyah hypevisor to setup resources for a VM before it can + * begin execution. One of its functions includes inspection/modification of a + * VM's device-tree before VM begins its execution. Modification can + * include specification of runtime resources allocated by hypervisor, + * details of which needs to be visible to VM. VM's device-tree is modified + * "inline" making use of "free" space that could exist at the end of device + * tree. + */ +int gunyah_arm_set_dtb(uint64_t dtb_start, uint64_t dtb_size) +{ + int ret; + struct gh_vm_dtb_config dtb; + + dtb.guest_phys_addr = dtb_start; + dtb.size = dtb_size; + + ret = gunyah_vm_ioctl(GH_VM_SET_DTB_CONFIG, &dtb); + if (ret != 0) { + error_report("GH_VM_SET_DTB_CONFIG failed: %s", strerror(errno)); + exit(1); + } + + return 0; +} diff --git a/target/arm/meson.build b/target/arm/meson.build index 2e10464dbb..951226b0a2 100644 --- a/target/arm/meson.build +++ b/target/arm/meson.build @@ -25,6 +25,9 @@ arm_system_ss.add(files( 'machine.c', 'ptw.c', )) +arm_system_ss.add(when: 'CONFIG_GUNYAH', if_true: files( + 'gunyah.c', +)) arm_user_ss = ss.source_set() -- 2.25.1