Re: [PATCH v3 3/4] ACPI: scan: Add support for LoongArch in acpi_iommu_configure_id()
From: Huacai Chen
Date: Sat Sep 19 2026 - 21:55:28 EST
On Sun, Sep 20, 2026 at 9:24 AM Bibo Mao <maobibo@xxxxxxxxxxx> wrote:
>
>
>
> On 2026/9/19 下午10:18, Huacai Chen wrote:
> > Hi, Bibo,
> >
> > On Tue, Sep 15, 2026 at 11:34 AM Bibo Mao <maobibo@xxxxxxxxxxx> wrote:
> >>
> >> acpi_iommu_configure_id() currently supports only IORT and VIOT. Add
> >> support for IOVT as well.
> >>
> >> Signed-off-by: Bibo Mao <maobibo@xxxxxxxxxxx>
> >> Acked-by: Rafael J. Wysocki (Intel) <rafael@xxxxxxxxxx>
> >> ---
> >> drivers/acpi/loongarch/iovt.c | 61 +++++++++++++++++++++++++++++++++++
> >> drivers/acpi/scan.c | 3 ++
> >> include/linux/acpi_iovt.h | 13 ++++++++
> >> 3 files changed, 77 insertions(+)
> >> create mode 100644 include/linux/acpi_iovt.h
> >>
> >> diff --git a/drivers/acpi/loongarch/iovt.c b/drivers/acpi/loongarch/iovt.c
> >> index 302ca6a75905..df14ce48eac6 100644
> >> --- a/drivers/acpi/loongarch/iovt.c
> >> +++ b/drivers/acpi/loongarch/iovt.c
> >> @@ -1,6 +1,7 @@
> >> // SPDX-License-Identifier: GPL-2.0-only
> >>
> >> #include <linux/acpi.h>
> >> +#include <linux/acpi_iovt.h>
> >> #include <linux/pci.h>
> >> #include "init.h"
> >>
> >> @@ -217,3 +218,63 @@ void __init acpi_iovt_late_init(void)
> >> iovt_init_devices(hdr);
> >> acpi_put_table(hdr);
> >> }
> >> +
> >> +static int iovt_pci_dev_iommu_init(struct pci_dev *pdev, u16 dev_id, void *data)
> >> +{
> >> + u32 sbdf;
> >> + struct iovt_fwnode *np;
> >> + struct device *aliased_dev = data;
> >> + u32 domain = pci_domain_nr(pdev->bus);
> >> + struct iovt_device_entry *entry;
> >> + bool found = false;
> >> +
> >> + list_for_each_entry(np, &iovt_fwnode_list, list) {
> >> + if (domain != np->segment)
> >> + continue;
> >> +
> >> + /* We're not translating ourself */
> >> + if (dev_id == np->devid)
> >> + return -EINVAL;
> >> +
> >> + if (np->flag & ACPI_IOVT_IOMMU_MAGAGE_BY_SEGMENT) {
> >> + found = true;
> >> + break;
> >> + }
> >> +
> >> + list_for_each_entry(entry, &np->ep_list, list) {
> >> + if (dev_id < entry->start_devid)
> >> + continue;
> >> +
> >> + if (dev_id > entry->end_devid)
> >> + continue;
> >> +
> >> + found = true;
> >> + break;
> >> + }
> >> +
> >> + if (found)
> >> + break;
> >> + }
> >> +
> >> + if (!found)
> >> + return -ENODEV;
> >> +
> >> + sbdf = (domain << 16) + dev_id;
> >> + return acpi_iommu_fwspec_init(aliased_dev, sbdf, np->fwnode);
> >> +}
> >> +
> >> +/*
> >> + * iovt_iommu_configure_id - Set-up IOMMU configuration for a device.
> >> + *
> >> + * @dev: device to configure
> >> + * @id_in: optional input id const value pointer
> >> + *
> >> + * Returns: 0 on success, <0 on failure
> >> + */
> >> +int iovt_iommu_configure_id(struct device *dev, const u32 *id_in)
> >> +{
> >> + if (!dev_is_pci(dev))
> >> + return -ENODEV;
> >> +
> >> + return pci_for_each_dma_alias(to_pci_dev(dev), iovt_pci_dev_iommu_init, dev);
> >> +}
> >> diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
> >> index 163a3cccf197..f2f155a65ea9 100644
> >> --- a/drivers/acpi/scan.c
> >> +++ b/drivers/acpi/scan.c
> >> @@ -13,6 +13,7 @@
> >> #include <linux/kernel.h>
> >> #include <linux/acpi.h>
> >> #include <linux/acpi_iort.h>
> >> +#include <linux/acpi_iovt.h>
> >> #include <linux/acpi_rimt.h>
> >> #include <linux/acpi_viot.h>
> >> #include <linux/iommu.h>
> >> @@ -1628,6 +1629,8 @@ static int acpi_iommu_configure_id(struct device *dev, const u32 *id_in)
> >> err = rimt_iommu_configure_id(dev, id_in);
> >> if (err && err != -EPROBE_DEFER)
> >> err = viot_iommu_configure(dev);
> >> + if (err && err != -EPROBE_DEFER)
> >> + err = iovt_iommu_configure_id(dev, id_in);
> > We call our acpi_arch_late_init() before acpi_viot_init(), so I think
> > it is better to also call iovt_iommu_configure_id() before
> > viot_iommu_configure().
> Yes, it should be the same order, good catch.
>
> It is both OK for me to put acpi_arch_late_init() after
> acpi_viot_init(), or put iovt_iommu_configure_id() before
> viot_iommu_configure().
I think it is better to put iovt_iommu_configure_id() before
viot_iommu_configure().
Huacai
>
> Regards
> Bibo Mao
> >
> >
> > Huacai
> >>
> >> mutex_unlock(&iommu_probe_device_lock);
> >>
> >> diff --git a/include/linux/acpi_iovt.h b/include/linux/acpi_iovt.h
> >> new file mode 100644
> >> index 000000000000..25a846b96260
> >> --- /dev/null
> >> +++ b/include/linux/acpi_iovt.h
> >> @@ -0,0 +1,13 @@
> >> +/* SPDX-License-Identifier: GPL-2.0-only */
> >> +
> >> +#ifndef __ACPI_IOVT_H__
> >> +#define __ACPI_IOVT_H__
> >> +
> >> +#if defined(CONFIG_IOMMU_API) && defined(CONFIG_ACPI_IOVT)
> >> +int iovt_iommu_configure_id(struct device *dev, const u32 *id_in);
> >> +#else
> >> +static inline int iovt_iommu_configure_id(struct device *dev, const u32 *id_in)
> >> +{ return -ENODEV; }
> >> +#endif
> >> +
> >> +#endif
> >> --
> >> 2.39.3
> >>
>