From: Alistair Francis <alistair23@gmail.com>
To: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Cc: qemu-devel@nongnu.org, qemu-riscv@nongnu.org,
alistair.francis@wdc.com, bmeng@tinylab.org,
liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com,
palmer@rivosinc.com, thuth@redhat.com, lvivier@redhat.com,
pbonzini@redhat.com, ajones@ventanamicro.com,
alex.bennee@linaro.org
Subject: Re: [PATCH 4/6] hw/riscv/virt.c: add virtio-iommu-pci hotplug support
Date: Thu, 15 Feb 2024 15:11:24 +1000 [thread overview]
Message-ID: <CAKmqyKNE_DAq6z3Yn8Uugdu2vqSerwh=kM-a65uW-VfRXFrbcA@mail.gmail.com> (raw)
In-Reply-To: <20240213191736.733334-5-dbarboza@ventanamicro.com>
On Wed, Feb 14, 2024 at 5:18 AM Daniel Henrique Barboza
<dbarboza@ventanamicro.com> wrote:
>
> We want to add a RISC-V 'virt' libqos machine to increase our test
> coverage. Some of the tests will try to plug a virtio-iommu-pci
> device into the board and do some tests with it.
>
> Enable virtio-iommu-pci in the 'virt' machine.
>
> Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Acked-by: Alistair Francis <alistair.francis@wdc.com>
Alistair
> ---
> hw/riscv/virt.c | 36 +++++++++++++++++++++++++++++++++++-
> 1 file changed, 35 insertions(+), 1 deletion(-)
>
> diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
> index b540f4d3da..54ad809b44 100644
> --- a/hw/riscv/virt.c
> +++ b/hw/riscv/virt.c
> @@ -53,6 +53,7 @@
> #include "hw/display/ramfb.h"
> #include "hw/acpi/aml-build.h"
> #include "qapi/qapi-visit-common.h"
> +#include "hw/virtio/virtio-iommu.h"
>
> /* KVM AIA only supports APLIC MSI. APLIC Wired is always emulated by QEMU. */
> static bool virt_use_kvm_aia(RISCVVirtState *s)
> @@ -971,6 +972,34 @@ static void create_fdt_fw_cfg(RISCVVirtState *s, const MemMapEntry *memmap)
> qemu_fdt_setprop(ms->fdt, nodename, "dma-coherent", NULL, 0);
> }
>
> +static void create_fdt_virtio_iommu(RISCVVirtState *s, uint16_t bdf)
> +{
> + const char compat[] = "virtio,pci-iommu\0pci1af4,1057";
> + void *fdt = MACHINE(s)->fdt;
> + uint32_t iommu_phandle;
> + g_autofree char *iommu_node = NULL;
> + g_autofree char *pci_node = NULL;
> +
> + pci_node = g_strdup_printf("/soc/pci@%lx",
> + (long) virt_memmap[VIRT_PCIE_ECAM].base);
> + iommu_node = g_strdup_printf("%s/virtio_iommu@%x,%x", pci_node,
> + PCI_SLOT(bdf), PCI_FUNC(bdf));
> + iommu_phandle = qemu_fdt_alloc_phandle(fdt);
> +
> + qemu_fdt_add_subnode(fdt, iommu_node);
> +
> + qemu_fdt_setprop(fdt, iommu_node, "compatible", compat, sizeof(compat));
> + qemu_fdt_setprop_sized_cells(fdt, iommu_node, "reg",
> + 1, bdf << 8, 1, 0, 1, 0,
> + 1, 0, 1, 0);
> + qemu_fdt_setprop_cell(fdt, iommu_node, "#iommu-cells", 1);
> + qemu_fdt_setprop_cell(fdt, iommu_node, "phandle", iommu_phandle);
> +
> + qemu_fdt_setprop_cells(fdt, pci_node, "iommu-map",
> + 0, iommu_phandle, 0, bdf,
> + bdf + 1, iommu_phandle, bdf + 1, 0xffff - bdf);
> +}
> +
> static void finalize_fdt(RISCVVirtState *s)
> {
> uint32_t phandle = 1, irq_mmio_phandle = 1, msi_pcie_phandle = 1;
> @@ -1680,7 +1709,8 @@ static HotplugHandler *virt_machine_get_hotplug_handler(MachineState *machine,
> {
> MachineClass *mc = MACHINE_GET_CLASS(machine);
>
> - if (device_is_dynamic_sysbus(mc, dev)) {
> + if (device_is_dynamic_sysbus(mc, dev) ||
> + object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_IOMMU_PCI)) {
> return HOTPLUG_HANDLER(machine);
> }
> return NULL;
> @@ -1699,6 +1729,10 @@ static void virt_machine_device_plug_cb(HotplugHandler *hotplug_dev,
> SYS_BUS_DEVICE(dev));
> }
> }
> +
> + if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_IOMMU_PCI)) {
> + create_fdt_virtio_iommu(s, pci_get_bdf(PCI_DEVICE(dev)));
> + }
> }
>
> static void virt_machine_class_init(ObjectClass *oc, void *data)
> --
> 2.43.0
>
>
next prev parent reply other threads:[~2024-02-15 5:12 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-13 19:17 [PATCH 0/6] libqos, riscv: libqos fixes, add riscv machine Daniel Henrique Barboza
2024-02-13 19:17 ` [PATCH 1/6] libqos/virtio.c: init all elems in qvring_indirect_desc_setup() Daniel Henrique Barboza
2024-02-15 5:02 ` Alistair Francis
2024-02-16 10:23 ` Thomas Huth
2024-02-13 19:17 ` [PATCH 2/6] libqos/virtio.c: fix 'avail_event' offset in qvring_init() Daniel Henrique Barboza
2024-02-15 5:06 ` Alistair Francis
2024-02-16 10:47 ` Thomas Huth
2024-02-13 19:17 ` [PATCH 3/6] hw/riscv/virt.c: create '/soc/pci@...' fdt node earlier Daniel Henrique Barboza
2024-02-15 5:08 ` Alistair Francis
2024-02-13 19:17 ` [PATCH 4/6] hw/riscv/virt.c: add virtio-iommu-pci hotplug support Daniel Henrique Barboza
2024-02-15 5:11 ` Alistair Francis [this message]
2024-02-13 19:17 ` [PATCH 5/6] hw/riscv/virt.c: make aclint compatible with 'qtest' accel Daniel Henrique Barboza
2024-02-15 5:14 ` Alistair Francis
2024-02-13 19:17 ` [PATCH 6/6] tests/libqos: add riscv/virt machine nodes Daniel Henrique Barboza
2024-02-15 5:35 ` Alistair Francis
2024-02-16 10:58 ` Thomas Huth
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAKmqyKNE_DAq6z3Yn8Uugdu2vqSerwh=kM-a65uW-VfRXFrbcA@mail.gmail.com' \
--to=alistair23@gmail.com \
--cc=ajones@ventanamicro.com \
--cc=alex.bennee@linaro.org \
--cc=alistair.francis@wdc.com \
--cc=bmeng@tinylab.org \
--cc=dbarboza@ventanamicro.com \
--cc=liwei1518@gmail.com \
--cc=lvivier@redhat.com \
--cc=palmer@rivosinc.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@nongnu.org \
--cc=thuth@redhat.com \
--cc=zhiwei_liu@linux.alibaba.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).