-----Original Message-----
From: Nicolin Chen <nicolinc@nvidia.com>
Sent: Wednesday, April 16, 2025 5:19 AM
To: Shameerali Kolothum Thodi <shameerali.kolothum.thodi@huawei.com>
Cc: qemu-arm@nongnu.org; qemu-devel@nongnu.org;
eric.auger@redhat.com; peter.maydell@linaro.org; jgg@nvidia.com;
ddutile@redhat.com; berrange@redhat.com; nathanc@nvidia.com;
mochs@nvidia.com; smostafa@google.com; Linuxarm
<linuxarm@huawei.com>; Wangzhou (B) <wangzhou1@hisilicon.com>;
jiangkunkun <jiangkunkun@huawei.com>; Jonathan Cameron
<jonathan.cameron@huawei.com>; zhangfei.gao@linaro.org
Subject: Re: [PATCH 2/5] hw/arm/virt-acpi-build: Update IORT for multiple
smmuv3 devices
On Tue, Apr 15, 2025 at 09:11:01AM +0100, Shameer Kolothum wrote:
+static int get_smmuv3_device(Object *obj, void *opaque)
+{
+ GArray *sdev_blob = opaque;
+ int min_bus, max_bus;
+ VirtMachineState *vms;
+ PlatformBusDevice *pbus;
+ SysBusDevice *sbdev;
+ SMMUv3Device sdev;
+ hwaddr base;
+ int irq;
+ PCIBus *bus;
In a reverse christmas tree order? Or we could at least group
those similar types together.
+ vms = VIRT_MACHINE(qdev_get_machine());
+ pbus = PLATFORM_BUS_DEVICE(vms->platform_bus_dev);
+ sbdev = SYS_BUS_DEVICE(obj);
+ base = platform_bus_get_mmio_addr(pbus, sbdev, 0);
+ irq = platform_bus_get_irqn(pbus, sbdev, 0);
+
+ base += vms->memmap[VIRT_PLATFORM_BUS].base;
+ irq += vms->irqmap[VIRT_PLATFORM_BUS];
+
+ pci_bus_range(bus, &min_bus, &max_bus);
+ sdev.smmu_idmap.input_base = min_bus << 8;
+ sdev.smmu_idmap.id_count = (max_bus - min_bus + 1) << 8;
+ sdev.base = base;
+ sdev.irq = irq + ARM_SPI_BASE;
Hmm, these base/irq local variables don't look necessary.
+ g_array_append_val(sdev_blob, sdev);
+ return 0;
+}
+
/*
* Input Output Remapping Table (IORT)
* Conforms to "IO Remapping Table System Software on ARM
Platforms",
@@ -275,25 +330,42 @@ static void
build_iort(GArray *table_data, BIOSLinker *linker, VirtMachineState
*vms)
{
int i, nb_nodes, rc_mapping_count;
- size_t node_size, smmu_offset = 0;
+ size_t node_size, *smmu_offset = NULL;
AcpiIortIdMapping *idmap;
+ int num_smmus = 0;
uint32_t id = 0;
GArray *smmu_idmaps = g_array_new(false, true,
sizeof(AcpiIortIdMapping));
GArray *its_idmaps = g_array_new(false, true,
sizeof(AcpiIortIdMapping));
+ GArray *smmuv3_devices = g_array_new(false, true,
sizeof(SMMUv3Device));
AcpiTable table = { .sig = "IORT", .rev = 3, .oem_id = vms->oem_id,
.oem_table_id = vms->oem_table_id };
/* Table 2 The IORT */
acpi_table_begin(&table, table_data);
- if (vms->iommu == VIRT_IOMMU_SMMUV3) {
- AcpiIortIdMapping next_range = {0};
-
+ nb_nodes = 2; /* RC, ITS */
+ if (vms->iommu == VIRT_IOMMU_SMMUV3_DEV) {
+ object_child_foreach_recursive(object_get_root(),
+ get_smmuv3_device, smmuv3_devices);
+ /* Sort the smmuv3-devices by smmu idmap input_base */
+ g_array_sort(smmuv3_devices, smmuv3_dev_idmap_compare);
+ /* Fill smmu idmap from sorted smmuv3 devices array */
+ for (i = 0; i < smmuv3_devices->len; i++) {
+ SMMUv3Device *s = &g_array_index(smmuv3_devices,
SMMUv3Device, i);
+ g_array_append_val(smmu_idmaps, s->smmu_idmap);
+ }
+ num_smmus = smmuv3_devices->len;
+ } else if (vms->iommu == VIRT_IOMMU_SMMUV3) {
object_child_foreach_recursive(object_get_root(),
iort_host_bridges, smmu_idmaps);
/* Sort the smmu idmap by input_base */
g_array_sort(smmu_idmaps, iort_idmap_compare);
VIRT_IOMMU_SMMUV3 seems to fit the struct SMMUv3Device very well,
given that it has base, irq, and smmu_idmaps too?