From: Bibo Mao <maobibo@loongson.cn>
To: Huacai Chen <chenhuacai@kernel.org>,
"Rafael J . Wysocki" <rafael@kernel.org>,
Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>,
Pawel Chmielewski <pawel.chmielewski@intel.com>
Cc: Len Brown <lenb@kernel.org>,
linux-kernel@vger.kernel.org, loongarch@lists.linux.dev,
linux-acpi@vger.kernel.org, acpica-devel@lists.linux.dev,
lixianglai@loongson.cn
Subject: [PATCH v4 3/4] ACPI: scan: Add support for LoongArch in acpi_iommu_configure_id()
Date: Tue, 22 Sep 2026 20:10:57 +0800 [thread overview]
Message-ID: <20260922121058.972734-4-maobibo@loongson.cn> (raw)
In-Reply-To: <20260922121058.972734-1-maobibo@loongson.cn>
acpi_iommu_configure_id() currently supports only IORT and VIOT. Add
support for IOVT as well.
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
Acked-by: Rafael J. Wysocki (Intel) <rafael@kernel.org>
---
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..827cd526a099 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>
@@ -1626,6 +1627,8 @@ static int acpi_iommu_configure_id(struct device *dev, const u32 *id_in)
err = iort_iommu_configure_id(dev, id_in);
if (err && err != -EPROBE_DEFER)
err = rimt_iommu_configure_id(dev, id_in);
+ if (err && err != -EPROBE_DEFER)
+ err = iovt_iommu_configure_id(dev, id_in);
if (err && err != -EPROBE_DEFER)
err = viot_iommu_configure(dev);
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
next prev parent reply other threads:[~2026-09-22 12:18 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-22 12:10 [PATCH v4 0/4] ACPI: LoongArch: Add IOVT table support Bibo Mao
2026-09-22 12:10 ` [PATCH v4 1/4] ACPICA: actbl2.h: Add bit constants of the Flags field in the IOVT IOMMU structure Bibo Mao
2026-09-22 12:10 ` [PATCH v4 2/4] ACPI: LoongArch: Add acpi_arch_[late]_init() Bibo Mao
2026-09-22 12:10 ` Bibo Mao [this message]
2026-09-22 12:10 ` [PATCH v4 4/4] MAINTAINERS: Add entry for drivers/acpi/loongarch Bibo Mao
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=20260922121058.972734-4-maobibo@loongson.cn \
--to=maobibo@loongson.cn \
--cc=acpica-devel@lists.linux.dev \
--cc=chenhuacai@kernel.org \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lixianglai@loongson.cn \
--cc=loongarch@lists.linux.dev \
--cc=maciej.wieczor-retman@intel.com \
--cc=pawel.chmielewski@intel.com \
--cc=rafael@kernel.org \
/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