Skip to content

Commit 4f901b3

Browse files
vlsuniljoergroedel
authored andcommitted
iommu/riscv: Add ACPI support
RISC-V IO Mapping Table (RIMT) provides the information about the IOMMU to the OS in ACPI. Add support for ACPI in RISC-V IOMMU drivers by using RIMT data. The changes at high level are, a) Register the IOMMU with RIMT data structures. b) Enable probing of platform IOMMU in ACPI way using the ACPIID defined for the RISC-V IOMMU in the BRS spec [1]. Configure the MSI domain if the platform IOMMU uses MSIs. [1] - https://github.com/riscv-non-isa/riscv-brs/blob/main/acpi-id.adoc Signed-off-by: Sunil V L <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Acked-by: Will Deacon <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent cbf4fbc commit 4f901b3

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

drivers/iommu/riscv/iommu-platform.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
* Tomasz Jeznach <[email protected]>
1111
*/
1212

13+
#include <linux/acpi.h>
14+
#include <linux/irqchip/riscv-imsic.h>
1315
#include <linux/kernel.h>
1416
#include <linux/msi.h>
1517
#include <linux/of_irq.h>
@@ -46,6 +48,7 @@ static int riscv_iommu_platform_probe(struct platform_device *pdev)
4648
enum riscv_iommu_igs_settings igs;
4749
struct device *dev = &pdev->dev;
4850
struct riscv_iommu_device *iommu = NULL;
51+
struct irq_domain *msi_domain;
4952
struct resource *res = NULL;
5053
int vec, ret;
5154

@@ -76,8 +79,13 @@ static int riscv_iommu_platform_probe(struct platform_device *pdev)
7679
switch (igs) {
7780
case RISCV_IOMMU_CAPABILITIES_IGS_BOTH:
7881
case RISCV_IOMMU_CAPABILITIES_IGS_MSI:
79-
if (is_of_node(dev->fwnode))
82+
if (is_of_node(dev_fwnode(dev))) {
8083
of_msi_configure(dev, to_of_node(dev->fwnode));
84+
} else {
85+
msi_domain = irq_find_matching_fwnode(imsic_acpi_get_fwnode(dev),
86+
DOMAIN_BUS_PLATFORM_MSI);
87+
dev_set_msi_domain(dev, msi_domain);
88+
}
8189

8290
if (!dev_get_msi_domain(dev)) {
8391
dev_warn(dev, "failed to find an MSI domain\n");
@@ -150,6 +158,12 @@ static const struct of_device_id riscv_iommu_of_match[] = {
150158
{},
151159
};
152160

161+
static const struct acpi_device_id riscv_iommu_acpi_match[] = {
162+
{ "RSCV0004", 0 },
163+
{}
164+
};
165+
MODULE_DEVICE_TABLE(acpi, riscv_iommu_acpi_match);
166+
153167
static struct platform_driver riscv_iommu_platform_driver = {
154168
.probe = riscv_iommu_platform_probe,
155169
.remove = riscv_iommu_platform_remove,
@@ -158,6 +172,7 @@ static struct platform_driver riscv_iommu_platform_driver = {
158172
.name = "riscv,iommu",
159173
.of_match_table = riscv_iommu_of_match,
160174
.suppress_bind_attrs = true,
175+
.acpi_match_table = riscv_iommu_acpi_match,
161176
},
162177
};
163178

drivers/iommu/riscv/iommu.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
#define pr_fmt(fmt) "riscv-iommu: " fmt
1414

15+
#include <linux/acpi.h>
16+
#include <linux/acpi_rimt.h>
1517
#include <linux/compiler.h>
1618
#include <linux/crash_dump.h>
1719
#include <linux/init.h>
@@ -1650,6 +1652,14 @@ int riscv_iommu_init(struct riscv_iommu_device *iommu)
16501652
goto err_iodir_off;
16511653
}
16521654

1655+
if (!acpi_disabled) {
1656+
rc = rimt_iommu_register(iommu->dev);
1657+
if (rc) {
1658+
dev_err_probe(iommu->dev, rc, "cannot register iommu with RIMT\n");
1659+
goto err_remove_sysfs;
1660+
}
1661+
}
1662+
16531663
rc = iommu_device_register(&iommu->iommu, &riscv_iommu_ops, iommu->dev);
16541664
if (rc) {
16551665
dev_err_probe(iommu->dev, rc, "cannot register iommu interface\n");

0 commit comments

Comments
 (0)