RISC-V: Add ACPI support for IOMMU
Subsystems (5)
Sunil V L
maintainerv2 cover RISC-V: Add ACPI support for IOMMU
This series adds support for RISC-V IOMMU on ACPI based platforms. RISC-V IO Mapping Table (RIMT) is a new static ACPI table [1] introduced to communicate IOMMU information to the OS.
[1] - https://github.com/riscv-non-isa/riscv-acpi-rimt/releases/download/v1.0/rimt-spec.pdf
Changes since v1:
1) Rebased to v6.16-rc1.
2) Dropped ACPICA patch since it is already available in 6.16-rc1.
3) Added Rafael's ACK.
4) Fixed few issues found by bots.
Sunil V L (3):
ACPI: RISC-V: Add support for RIMT
ACPI: scan: Add support for RISC-V in acpi_iommu_configure_id() iommu/riscv: Add ACPI support
MAINTAINERS | 1 + arch/riscv/Kconfig | 1 + drivers/acpi/Kconfig | 4 + drivers/acpi/riscv/Kconfig | 7 + drivers/acpi/riscv/Makefile | 1 + drivers/acpi/riscv/init.c | 2 + drivers/acpi/riscv/init.h | 1 + drivers/acpi/riscv/rimt.c | 523 +++++++++++++++++++++++++++ drivers/acpi/scan.c | 9 +- drivers/iommu/riscv/iommu-platform.c | 17 +- drivers/iommu/riscv/iommu.c | 10 + include/linux/acpi_rimt.h | 26 ++ 12 files changed, 599 insertions(+), 3 deletions(-) create mode 100644 drivers/acpi/riscv/Kconfig create mode 100644 drivers/acpi/riscv/rimt.c create mode 100644 include/linux/acpi_rimt.h
Signature · 1 line
2.43.0
Sunil V L
maintainerPATCH v2 1/3 ACPI: RISC-V: Add support for RIMT
RISC-V IO Mapping Table (RIMT) is a static ACPI table to communicate IOMMU information to the OS. The spec is available at [1].
The changes at high level are,
a) Initialize data structures required for IOMMU/device configuration using the data from RIMT. Provide APIs required for device configuration.
b) Provide an API for IOMMU drivers to register the fwnode with RIMT data structures. This API will create a fwnode for PCIe IOMMU.
[1] - https://github.com/riscv-non-isa/riscv-acpi-rimt
--- MAINTAINERS | 1 + arch/riscv/Kconfig | 1 + drivers/acpi/Kconfig | 4 + drivers/acpi/riscv/Kconfig | 7 + drivers/acpi/riscv/Makefile | 1 + drivers/acpi/riscv/init.c | 2 + drivers/acpi/riscv/init.h | 1 + drivers/acpi/riscv/rimt.c | 523 ++++++++++++++++++++++++++++++++++++ include/linux/acpi_rimt.h | 26 ++ 9 files changed, 566 insertions(+) create mode 100644 drivers/acpi/riscv/Kconfig create mode 100644 drivers/acpi/riscv/rimt.c create mode 100644 include/linux/acpi_rimt.h
MAINTAINERS +1 -0
@@ -345,6 +345,7 @@ L: [email protected] L: [email protected] S: Maintained F: drivers/acpi/riscv/ +F: include/linux/acpi_rimt.h ACPI PCC(Platform Communication Channel) MAILBOX DRIVER M: Sudeep Holla <[email protected]>
arch/riscv/Kconfig +1 -0
@@ -16,6 +16,7 @@ config RISCV select ACPI_MCFG if (ACPI && PCI) select ACPI_PPTT if ACPI select ACPI_REDUCED_HARDWARE_ONLY if ACPI + select ACPI_RIMT if ACPI select ACPI_SPCR_TABLE if ACPI select ARCH_DMA_DEFAULT_COHERENT select ARCH_ENABLE_HUGEPAGE_MIGRATION if HUGETLB_PAGE && MIGRATION
drivers/acpi/Kconfig +4 -0
@@ -546,6 +546,10 @@ if ARM64 source "drivers/acpi/arm64/Kconfig" endif +if RISCV +source "drivers/acpi/riscv/Kconfig" +endif + config ACPI_PPTT bool
drivers/acpi/riscv/Kconfig new file +7 -0
@@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# ACPI Configuration for RISC-V +# + +config ACPI_RIMT + bool
drivers/acpi/riscv/Makefile +1 -0
@@ -2,3 +2,4 @@ obj-y += rhct.o init.o irq.o obj-$(CONFIG_ACPI_PROCESSOR_IDLE) += cpuidle.o obj-$(CONFIG_ACPI_CPPC_LIB) += cppc.o +obj-$(CONFIG_ACPI_RIMT) += rimt.o
drivers/acpi/riscv/init.c +2 -0
@@ -10,4 +10,6 @@void __init acpi_arch_init (void ) {riscv_acpi_init_gsi_mapping (); +if (IS_ENABLED (CONFIG_ACPI_RIMT )) +riscv_acpi_rimt_init (); }
drivers/acpi/riscv/init.h +1 -0
@@ -2,3 +2,4 @@#include <linux/init.h> void __init riscv_acpi_init_gsi_mapping (void ); +void __init riscv_acpi_rimt_init (void );
drivers/acpi/riscv/rimt.c new file +523 -0
523 lines not on this page · raw message
include/linux/acpi_rimt.h new file +26 -0
@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Copyright (C) 2024-2025, Ventana Micro Systems Inc. +* Author: Sunil V L <[email protected]> +*/ + +#ifndef _ACPI_RIMT_H +#define _ACPI_RIMT_H + +#ifdef CONFIG_ACPI_RIMT +int rimt_iommu_configure_id (struct device *dev,const u32 *id_in); + +int rimt_iommu_register (struct device *dev); +#else +static inline int rimt_iommu_register (struct device *dev) +{ +return -ENODEV ; +} + +static inline int rimt_iommu_configure_id (struct device *dev,const u32 *id_in) +{ +return -ENODEV ; +} +#endif + +#endif /* _ACPI_RIMT_H */
Signature · 1 line
2.43.0
Sunil V L
maintainerPATCH v2 2/3 ACPI: scan: Add support for RISC-V in acpi_iommu_configure_id()
In reply to Sunil V Lacpi_iommu_configure_id() currently supports only IORT (ARM) and VIOT. Add support for RISC-V as well.
--- drivers/acpi/scan.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/acpi/scan.c +7 -2
@@ -11,6 +11,7 @@#include <linux/kernel.h> #include <linux/acpi.h> #include <linux/acpi_iort.h> +#include <linux/acpi_rimt.h> #include <linux/acpi_viot.h> #include <linux/iommu.h> #include <linux/signal.h>
@@ -1628,8 +1629,12 @@ 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 =viot_iommu_configure (dev); +if (err && err != -EPROBE_DEFER ) { + err =rimt_iommu_configure_id (dev, id_in); +if (err && err != -EPROBE_DEFER ) + err =viot_iommu_configure (dev); + } +mutex_unlock (&iommu_probe_device_lock);return err;
Signature · 1 line
2.43.0
Sunil V L
maintainerPATCH v2 3/3 iommu/riscv: Add ACPI support
In reply to Sunil V LRISC-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
--- drivers/iommu/riscv/iommu-platform.c | 17 ++++++++++++++++- drivers/iommu/riscv/iommu.c | 10 ++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-)
drivers/iommu/riscv/iommu-platform.c +16 -1
@@ -10,6 +10,8 @@* Tomasz Jeznach <[email protected]> */ +#include <linux/acpi.h> +#include <linux/irqchip/riscv-imsic.h> #include <linux/kernel.h> #include <linux/msi.h> #include <linux/of_irq.h>
@@ -46,6 +48,7 @@ static int riscv_iommu_platform_probe(struct platform_device *pdev)enum riscv_iommu_igs_settings igs;struct device *dev = &pdev->dev;struct riscv_iommu_device *iommu =NULL ; +struct irq_domain *msi_domain;struct resource *res =NULL ;int vec, ret;
@@ -76,8 +79,13 @@ static int riscv_iommu_platform_probe(struct platform_device *pdev)switch (igs) {case RISCV_IOMMU_CAPABILITIES_IGS_BOTH :case RISCV_IOMMU_CAPABILITIES_IGS_MSI : -if (is_of_node (dev->fwnode)) +if (is_of_node (dev_fwnode (dev))) {of_msi_configure (dev,to_of_node (dev->fwnode)); + }else { + msi_domain =irq_find_matching_fwnode (imsic_acpi_get_fwnode (dev), +DOMAIN_BUS_PLATFORM_MSI ); +dev_set_msi_domain (dev, msi_domain); + }if (!dev_get_msi_domain (dev)) {dev_warn (dev,"failed to find an MSI domain\n" );
@@ -150,6 +158,12 @@ static const struct of_device_id riscv_iommu_of_match[] = { {}, }; +static const struct acpi_device_id riscv_iommu_acpi_match[] = { + {"RSCV0004" ,0 }, + {} +}; +MODULE_DEVICE_TABLE (acpi, riscv_iommu_acpi_match); +static struct platform_driver riscv_iommu_platform_driver = { .probe = riscv_iommu_platform_probe, .remove = riscv_iommu_platform_remove,
@@ -158,6 +172,7 @@ static struct platform_driver riscv_iommu_platform_driver = { .name = "riscv,iommu", .of_match_table = riscv_iommu_of_match, .suppress_bind_attrs = true, + .acpi_match_table = riscv_iommu_acpi_match, }, };
drivers/iommu/riscv/iommu.c +10 -0
@@ -12,6 +12,8 @@#define pr_fmt (fmt) "riscv-iommu: " fmt +#include <linux/acpi.h> +#include <linux/acpi_rimt.h> #include <linux/compiler.h> #include <linux/crash_dump.h> #include <linux/init.h>
@@ -1651,6 +1653,14 @@ int riscv_iommu_init(struct riscv_iommu_device *iommu) goto err_iodir_off; } +if (!acpi_disabled) { + rc =rimt_iommu_register (iommu->dev); +if (rc) { +dev_err_probe (iommu->dev, rc,"cannot register iommu with RIMT\n" ); + goto err_remove_sysfs; + } + } + rc =iommu_device_register (&iommu->iommu, &riscv_iommu_ops, iommu->dev);if (rc) {dev_err_probe (iommu->dev, rc,"cannot register iommu interface\n" );
Signature · 1 line
2.43.0