From nobody Sat Oct 4 11:15:55 2025 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C92CF26B777 for ; Mon, 18 Aug 2025 04:58:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755493103; cv=none; b=uT0ZRSEDtAR0LhxwcJWaMH18Ny4s7AbmR/mPmACEqe/JpLpJqtYJtOaRsUh+LPTn0AYOmZmU1+eA7NplM5ICk5XvMogxrrnfN20jbKJw2zd8aGf2WGdxhH81dy+Z1QWDtOLl5DIp05KZuqeiJbTVeZkGz6S4gpk095GMRksKST8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755493103; c=relaxed/simple; bh=DqwfS3ad0gf3KDyo9SeRRJJ6NQGjFvfIKcQk0Ga8uCk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SdQMvR/0RA+B7XvzrSzZvccH26i6Y/n9r0Nt0WEjv2qeFimsqt25V3LB6dLEB0HFhBjNVnYWBwONLfSYKdBlY7axg5/GpHmoERknw+IvCD+Tk2eFpXRYjIYGvBsGLUDhTjtR2t/UYBlPcUNQcgLYsThBtyaONaw2pDtK9yF+YQk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=cq/lIdw0; arc=none smtp.client-ip=209.85.210.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="cq/lIdw0" Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-76e2e8aff06so2888105b3a.1 for ; Sun, 17 Aug 2025 21:58:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1755493100; x=1756097900; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9DlIkV4ZxtG8s5XzsyCiwH4iQeX9FjAJdrBCUshbU9Q=; b=cq/lIdw0BCFzLUajeAbn8LpWOEZH+/raIdlueYat8HPKoHtSjHw+ACbixfAUZ+rIVL yas2+RMxM9yQ7zGQf0U2EKn2kS5xvVftvbb3lbwVZkZZx8NdUNgwEQ1zzvRb+fKmucj4 T1jJ59j0+CN8XT5ZkeFz6iC9IVoJr/MT87IHndZrciKJCso28GN3b2leebniwiEwF+KT gaU4gmqSw3Yph7uy/LVPcFBq8b0hIt+h7tMdgpmmb+nXpkNaXzkJa+Ut3pbwBhmsTPsT /ybE6RvEd82Qzi5nbTe3KUzwSOmlmHO7NSpffepgWUD9Jog6BQUrTFMO9uEQdPsfRy0z OTuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755493100; x=1756097900; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9DlIkV4ZxtG8s5XzsyCiwH4iQeX9FjAJdrBCUshbU9Q=; b=ST3r59Z36IZ7sAiDo+26f4OoONnotzfSQgUuGdgNxYnRX9L93sLgEzZwH6D8UJfWE3 phkDGfb2FPLl1mAIY08fDLej2q6+wlbKBd7R6oxfCcIdE5C/IO/UlQkgKvDf/YQ+iRaB 1vACFNK/lNN4MYT526Rvmkn9HO2ZZI9tFq8VmuPos/IAEDT5dnc/rnUUQGGSja4gSHmC XU8BvDSSpmwPFnZiakCzeyxVZtIb7M7+I0Xl770iPI6FUWWhMBKSTlM5M+rCzZOSMTkv +B+TU+oyI831haSkRBoM+kOioPvpehcv3WXcwcFYtjXpy3Nm+IMGRtjKoV87qtWtxKFw JiqQ== X-Gm-Message-State: AOJu0YwgyZ/ERK0izGWZfWOx5qf5nfl69Yeon7/hwzZ5QrGaQidRVpZ/ kv1cHnSOmAFyyr58kaW4Xia/B25q1sShiiezNjQOiCK1//7A5a9fL6X/Bi0gMbn1Y3jacfZOY3D uMFQwpm0= X-Gm-Gg: ASbGncvb7S7UNXVeHshJq9gPfALP+ZVqOUXPjnp/XUlHXJmrUUPcX2t2V42lGHXjbhv K6PsY82MPTwYszSeaRm5sTA6w0zvtfCdqZc29IqAmEA4n3aOJ0oDnE9oi3/xR8Y903HZnB3HI2w 5dGwaan6QMUlCFqrU4398a76SH+P9sWec5brf5epO3w9UDZti6rfbrV8kAUUrwIyORdIfxKULDc CsN+T94bn+cJHbqM7YQGt6y98qN9wfhSF5uAi1cSdXWBiQuPPxXND/8a8V+LYB2cSOeBwQS5e0N vHSQtVLqsH2RJxQS7/3y27lKF4vrVt4q7Y+pj90Oy7TmRfSKcP2niYMSy6G0veVARRGllRbsjFS on8cS14KqEjLfvDYb3YaEMXdfTocaYA== X-Google-Smtp-Source: AGHT+IHxfhlia+y0KN8s6sKAWBS4FbeJPjtEyvjFir6L3X1cpsZIM26R3GcJNK41TiJcUGwjBSP0QA== X-Received: by 2002:a05:6a00:8d5:b0:747:b043:41e5 with SMTP id d2e1a72fcca58-76e447f51e8mr15667168b3a.16.1755493100411; Sun, 17 Aug 2025 21:58:20 -0700 (PDT) Received: from sunil-pc.Dlink ([106.51.199.3]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-76e4528c264sm6124047b3a.43.2025.08.17.21.58.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Aug 2025 21:58:19 -0700 (PDT) From: Sunil V L To: linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-acpi@vger.kernel.org, iommu@lists.linux.dev Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , "Rafael J . Wysocki" , Len Brown , Tomasz Jeznach , Joerg Roedel , Will Deacon , Robin Murphy , Sunil V L , Anup Patel Subject: [PATCH v6 1/3] ACPI: RISC-V: Add support for RIMT Date: Mon, 18 Aug 2025 10:28:05 +0530 Message-ID: <20250818045807.763922-2-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250818045807.763922-1-sunilvl@ventanamicro.com> References: <20250818045807.763922-1-sunilvl@ventanamicro.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: Sunil V L Reviewed-by: Anup Patel --- 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 | 520 ++++++++++++++++++++++++++++++++++++ include/linux/acpi_rimt.h | 28 ++ 9 files changed, 565 insertions(+) create mode 100644 drivers/acpi/riscv/Kconfig create mode 100644 drivers/acpi/riscv/rimt.c create mode 100644 include/linux/acpi_rimt.h diff --git a/MAINTAINERS b/MAINTAINERS index daf520a13bdf..7a4ae2929721 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -347,6 +347,7 @@ L: linux-acpi@vger.kernel.org L: linux-riscv@lists.infradead.org S: Maintained F: drivers/acpi/riscv/ +F: include/linux/acpi_rimt.h =20 ACPI PCC(Platform Communication Channel) MAILBOX DRIVER M: Sudeep Holla diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index a4b233a0659e..7563f43ec026 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -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 diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig index b594780a57d7..2cdbd08b30e4 100644 --- a/drivers/acpi/Kconfig +++ b/drivers/acpi/Kconfig @@ -547,6 +547,10 @@ if ARM64 source "drivers/acpi/arm64/Kconfig" endif =20 +if RISCV +source "drivers/acpi/riscv/Kconfig" +endif + config ACPI_PPTT bool =20 diff --git a/drivers/acpi/riscv/Kconfig b/drivers/acpi/riscv/Kconfig new file mode 100644 index 000000000000..046296a18d00 --- /dev/null +++ b/drivers/acpi/riscv/Kconfig @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# ACPI Configuration for RISC-V +# + +config ACPI_RIMT + bool diff --git a/drivers/acpi/riscv/Makefile b/drivers/acpi/riscv/Makefile index a96fdf1e2cb8..1284a076fa88 100644 --- a/drivers/acpi/riscv/Makefile +++ b/drivers/acpi/riscv/Makefile @@ -2,3 +2,4 @@ obj-y +=3D rhct.o init.o irq.o obj-$(CONFIG_ACPI_PROCESSOR_IDLE) +=3D cpuidle.o obj-$(CONFIG_ACPI_CPPC_LIB) +=3D cppc.o +obj-$(CONFIG_ACPI_RIMT) +=3D rimt.o diff --git a/drivers/acpi/riscv/init.c b/drivers/acpi/riscv/init.c index 673e4d5dd752..7c00f7995e86 100644 --- a/drivers/acpi/riscv/init.c +++ b/drivers/acpi/riscv/init.c @@ -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(); } diff --git a/drivers/acpi/riscv/init.h b/drivers/acpi/riscv/init.h index 0b9a07e4031f..1680aa2aaf23 100644 --- a/drivers/acpi/riscv/init.h +++ b/drivers/acpi/riscv/init.h @@ -2,3 +2,4 @@ #include =20 void __init riscv_acpi_init_gsi_mapping(void); +void __init riscv_acpi_rimt_init(void); diff --git a/drivers/acpi/riscv/rimt.c b/drivers/acpi/riscv/rimt.c new file mode 100644 index 000000000000..683fcfe35c31 --- /dev/null +++ b/drivers/acpi/riscv/rimt.c @@ -0,0 +1,520 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2024-2025, Ventana Micro Systems Inc + * Author: Sunil V L + * + */ + +#define pr_fmt(fmt) "ACPI: RIMT: " fmt + +#include +#include +#include +#include +#include +#include +#include "init.h" + +struct rimt_fwnode { + struct list_head list; + struct acpi_rimt_node *rimt_node; + struct fwnode_handle *fwnode; +}; + +static LIST_HEAD(rimt_fwnode_list); +static DEFINE_SPINLOCK(rimt_fwnode_lock); + +#define RIMT_TYPE_MASK(type) (1 << (type)) +#define RIMT_IOMMU_TYPE BIT(0) + +/* Root pointer to the mapped RIMT table */ +static struct acpi_table_header *rimt_table; + +/** + * rimt_set_fwnode() - Create rimt_fwnode and use it to register + * iommu data in the rimt_fwnode_list + * + * @rimt_node: RIMT table node associated with the IOMMU + * @fwnode: fwnode associated with the RIMT node + * + * Returns: 0 on success + * <0 on failure + */ +static int rimt_set_fwnode(struct acpi_rimt_node *rimt_node, + struct fwnode_handle *fwnode) +{ + struct rimt_fwnode *np; + + np =3D kzalloc(sizeof(*np), GFP_ATOMIC); + + if (WARN_ON(!np)) + return -ENOMEM; + + INIT_LIST_HEAD(&np->list); + np->rimt_node =3D rimt_node; + np->fwnode =3D fwnode; + + spin_lock(&rimt_fwnode_lock); + list_add_tail(&np->list, &rimt_fwnode_list); + spin_unlock(&rimt_fwnode_lock); + + return 0; +} + +/** + * rimt_get_fwnode() - Retrieve fwnode associated with an RIMT node + * + * @node: RIMT table node to be looked-up + * + * Returns: fwnode_handle pointer on success, NULL on failure + */ +static struct fwnode_handle *rimt_get_fwnode(struct acpi_rimt_node *node) +{ + struct fwnode_handle *fwnode =3D NULL; + struct rimt_fwnode *curr; + + spin_lock(&rimt_fwnode_lock); + list_for_each_entry(curr, &rimt_fwnode_list, list) { + if (curr->rimt_node =3D=3D node) { + fwnode =3D curr->fwnode; + break; + } + } + spin_unlock(&rimt_fwnode_lock); + + return fwnode; +} + +static acpi_status rimt_match_node_callback(struct acpi_rimt_node *node, + void *context) +{ + acpi_status status =3D AE_NOT_FOUND; + struct device *dev =3D context; + + if (node->type =3D=3D ACPI_RIMT_NODE_TYPE_IOMMU) { + struct acpi_rimt_iommu *iommu_node =3D (struct acpi_rimt_iommu *)&node->= node_data; + + if (dev_is_pci(dev)) { + struct pci_dev *pdev; + u16 bdf; + + pdev =3D to_pci_dev(dev); + bdf =3D PCI_DEVID(pdev->bus->number, pdev->devfn); + if ((pci_domain_nr(pdev->bus) =3D=3D iommu_node->pcie_segment_number) && + bdf =3D=3D iommu_node->pcie_bdf) { + status =3D AE_OK; + } else { + status =3D AE_NOT_FOUND; + } + } else { + struct platform_device *pdev =3D to_platform_device(dev); + struct resource *res; + + res =3D platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (res && res->start =3D=3D iommu_node->base_address) + status =3D AE_OK; + else + status =3D AE_NOT_FOUND; + } + } else if (node->type =3D=3D ACPI_RIMT_NODE_TYPE_PCIE_ROOT_COMPLEX) { + struct acpi_rimt_pcie_rc *pci_rc; + struct pci_bus *bus; + + bus =3D to_pci_bus(dev); + pci_rc =3D (struct acpi_rimt_pcie_rc *)node->node_data; + + /* + * It is assumed that PCI segment numbers maps one-to-one + * with root complexes. Each segment number can represent only + * one root complex. + */ + status =3D pci_rc->pcie_segment_number =3D=3D pci_domain_nr(bus) ? + AE_OK : AE_NOT_FOUND; + } else if (node->type =3D=3D ACPI_RIMT_NODE_TYPE_PLAT_DEVICE) { + struct acpi_buffer buf =3D { ACPI_ALLOCATE_BUFFER, NULL }; + struct acpi_rimt_platform_device *ncomp; + struct device *plat_dev =3D dev; + struct acpi_device *adev; + + /* + * Walk the device tree to find a device with an + * ACPI companion; there is no point in scanning + * RIMT for a device matching a platform device if + * the device does not have an ACPI companion to + * start with. + */ + do { + adev =3D ACPI_COMPANION(plat_dev); + if (adev) + break; + + plat_dev =3D plat_dev->parent; + } while (plat_dev); + + if (!adev) + return status; + + status =3D acpi_get_name(adev->handle, ACPI_FULL_PATHNAME, &buf); + if (ACPI_FAILURE(status)) { + dev_warn(plat_dev, "Can't get device full path name\n"); + return status; + } + + ncomp =3D (struct acpi_rimt_platform_device *)node->node_data; + status =3D !strcmp(ncomp->device_name, buf.pointer) ? + AE_OK : AE_NOT_FOUND; + acpi_os_free(buf.pointer); + } + + return status; +} + +static struct acpi_rimt_node *rimt_scan_node(enum acpi_rimt_node_type type, + void *context) +{ + struct acpi_rimt_node *rimt_node, *rimt_end; + struct acpi_table_rimt *rimt; + int i; + + if (!rimt_table) + return NULL; + + /* Get the first RIMT node */ + rimt =3D (struct acpi_table_rimt *)rimt_table; + rimt_node =3D ACPI_ADD_PTR(struct acpi_rimt_node, rimt, + rimt->node_offset); + rimt_end =3D ACPI_ADD_PTR(struct acpi_rimt_node, rimt_table, + rimt_table->length); + + for (i =3D 0; i < rimt->num_nodes; i++) { + if (WARN_TAINT(rimt_node >=3D rimt_end, TAINT_FIRMWARE_WORKAROUND, + "RIMT node pointer overflows, bad table!\n")) + return NULL; + + if (rimt_node->type =3D=3D type && + ACPI_SUCCESS(rimt_match_node_callback(rimt_node, context))) + return rimt_node; + + rimt_node =3D ACPI_ADD_PTR(struct acpi_rimt_node, rimt_node, + rimt_node->length); + } + + return NULL; +} + +static bool rimt_pcie_rc_supports_ats(struct acpi_rimt_node *node) +{ + struct acpi_rimt_pcie_rc *pci_rc; + + pci_rc =3D (struct acpi_rimt_pcie_rc *)node->node_data; + return pci_rc->flags & ACPI_RIMT_PCIE_ATS_SUPPORTED; +} + +static int rimt_iommu_xlate(struct device *dev, struct acpi_rimt_node *nod= e, u32 deviceid) +{ + struct fwnode_handle *rimt_fwnode; + + if (!node) + return -ENODEV; + + rimt_fwnode =3D rimt_get_fwnode(node); + + /* + * The IOMMU drivers may not be probed yet. + * Defer the IOMMU configuration + */ + if (!rimt_fwnode) + return -EPROBE_DEFER; + + return acpi_iommu_fwspec_init(dev, deviceid, rimt_fwnode); +} + +struct rimt_pci_alias_info { + struct device *dev; + struct acpi_rimt_node *node; + const struct iommu_ops *ops; +}; + +static int rimt_id_map(struct acpi_rimt_id_mapping *map, u8 type, u32 rid_= in, u32 *rid_out) +{ + if (rid_in < map->source_id_base || + (rid_in > map->source_id_base + map->num_ids)) + return -ENXIO; + + *rid_out =3D map->dest_id_base + (rid_in - map->source_id_base); + return 0; +} + +static struct acpi_rimt_node *rimt_node_get_id(struct acpi_rimt_node *node, + u32 *id_out, int index) +{ + struct acpi_rimt_platform_device *plat_node; + u32 id_mapping_offset, num_id_mapping; + struct acpi_rimt_pcie_rc *pci_node; + struct acpi_rimt_id_mapping *map; + struct acpi_rimt_node *parent; + + if (node->type =3D=3D ACPI_RIMT_NODE_TYPE_PCIE_ROOT_COMPLEX) { + pci_node =3D (struct acpi_rimt_pcie_rc *)&node->node_data; + id_mapping_offset =3D pci_node->id_mapping_offset; + num_id_mapping =3D pci_node->num_id_mappings; + } else if (node->type =3D=3D ACPI_RIMT_NODE_TYPE_PLAT_DEVICE) { + plat_node =3D (struct acpi_rimt_platform_device *)&node->node_data; + id_mapping_offset =3D plat_node->id_mapping_offset; + num_id_mapping =3D plat_node->num_id_mappings; + } else { + return NULL; + } + + if (!id_mapping_offset || !num_id_mapping || index >=3D num_id_mapping) + return NULL; + + map =3D ACPI_ADD_PTR(struct acpi_rimt_id_mapping, node, + id_mapping_offset + index * sizeof(*map)); + + /* Firmware bug! */ + if (!map->dest_offset) { + pr_err(FW_BUG "[node %p type %d] ID map has NULL parent reference\n", + node, node->type); + return NULL; + } + + parent =3D ACPI_ADD_PTR(struct acpi_rimt_node, rimt_table, map->dest_offs= et); + + if (node->type =3D=3D ACPI_RIMT_NODE_TYPE_PLAT_DEVICE || + node->type =3D=3D ACPI_RIMT_NODE_TYPE_PCIE_ROOT_COMPLEX) { + *id_out =3D map->dest_id_base; + return parent; + } + + return NULL; +} + +/* + * RISC-V supports IOMMU as a PCI device or a platform device. + * When it is a platform device, there should be a namespace device as + * well along with RIMT. To create the link between RIMT information and + * the platform device, the IOMMU driver should register itself with the + * RIMT module. This is true for PCI based IOMMU as well. + */ +int rimt_iommu_register(struct device *dev) +{ + struct fwnode_handle *rimt_fwnode; + struct acpi_rimt_node *node; + + node =3D rimt_scan_node(ACPI_RIMT_NODE_TYPE_IOMMU, dev); + if (!node) { + pr_err("Could not find IOMMU node in RIMT\n"); + return -ENODEV; + } + + if (dev_is_pci(dev)) { + rimt_fwnode =3D acpi_alloc_fwnode_static(); + if (!rimt_fwnode) + return -ENOMEM; + + rimt_fwnode->dev =3D dev; + if (!dev->fwnode) + dev->fwnode =3D rimt_fwnode; + + rimt_set_fwnode(node, rimt_fwnode); + } else { + rimt_set_fwnode(node, dev->fwnode); + } + + return 0; +} + +#ifdef CONFIG_IOMMU_API + +static struct acpi_rimt_node *rimt_node_map_id(struct acpi_rimt_node *node, + u32 id_in, u32 *id_out, + u8 type_mask) +{ + struct acpi_rimt_platform_device *plat_node; + u32 id_mapping_offset, num_id_mapping; + struct acpi_rimt_pcie_rc *pci_node; + u32 id =3D id_in; + + /* Parse the ID mapping tree to find specified node type */ + while (node) { + struct acpi_rimt_id_mapping *map; + int i, rc =3D 0; + u32 map_id =3D id; + + if (RIMT_TYPE_MASK(node->type) & type_mask) { + if (id_out) + *id_out =3D id; + return node; + } + + if (node->type =3D=3D ACPI_RIMT_NODE_TYPE_PCIE_ROOT_COMPLEX) { + pci_node =3D (struct acpi_rimt_pcie_rc *)&node->node_data; + id_mapping_offset =3D pci_node->id_mapping_offset; + num_id_mapping =3D pci_node->num_id_mappings; + } else if (node->type =3D=3D ACPI_RIMT_NODE_TYPE_PLAT_DEVICE) { + plat_node =3D (struct acpi_rimt_platform_device *)&node->node_data; + id_mapping_offset =3D plat_node->id_mapping_offset; + num_id_mapping =3D plat_node->num_id_mappings; + } else { + goto fail_map; + } + + if (!id_mapping_offset || !num_id_mapping) + goto fail_map; + + map =3D ACPI_ADD_PTR(struct acpi_rimt_id_mapping, node, + id_mapping_offset); + + /* Firmware bug! */ + if (!map->dest_offset) { + pr_err(FW_BUG "[node %p type %d] ID map has NULL parent reference\n", + node, node->type); + goto fail_map; + } + + /* Do the ID translation */ + for (i =3D 0; i < num_id_mapping; i++, map++) { + rc =3D rimt_id_map(map, node->type, map_id, &id); + if (!rc) + break; + } + + if (i =3D=3D num_id_mapping) + goto fail_map; + + node =3D ACPI_ADD_PTR(struct acpi_rimt_node, rimt_table, + rc ? 0 : map->dest_offset); + } + +fail_map: + /* Map input ID to output ID unchanged on mapping failure */ + if (id_out) + *id_out =3D id_in; + + return NULL; +} + +static struct acpi_rimt_node *rimt_node_map_platform_id(struct acpi_rimt_n= ode *node, u32 *id_out, + u8 type_mask, int index) +{ + struct acpi_rimt_node *parent; + u32 id; + + parent =3D rimt_node_get_id(node, &id, index); + if (!parent) + return NULL; + + if (!(RIMT_TYPE_MASK(parent->type) & type_mask)) + parent =3D rimt_node_map_id(parent, id, id_out, type_mask); + else + if (id_out) + *id_out =3D id; + + return parent; +} + +static int rimt_pci_iommu_init(struct pci_dev *pdev, u16 alias, void *data) +{ + struct rimt_pci_alias_info *info =3D data; + struct acpi_rimt_node *parent; + u32 deviceid; + + parent =3D rimt_node_map_id(info->node, alias, &deviceid, RIMT_IOMMU_TYPE= ); + return rimt_iommu_xlate(info->dev, parent, deviceid); +} + +static int rimt_plat_iommu_map(struct device *dev, struct acpi_rimt_node *= node) +{ + struct acpi_rimt_node *parent; + int err =3D -ENODEV, i =3D 0; + u32 deviceid =3D 0; + + do { + parent =3D rimt_node_map_platform_id(node, &deviceid, + RIMT_IOMMU_TYPE, + i++); + + if (parent) + err =3D rimt_iommu_xlate(dev, parent, deviceid); + } while (parent && !err); + + return err; +} + +static int rimt_plat_iommu_map_id(struct device *dev, + struct acpi_rimt_node *node, + const u32 *in_id) +{ + struct acpi_rimt_node *parent; + u32 deviceid; + + parent =3D rimt_node_map_id(node, *in_id, &deviceid, RIMT_IOMMU_TYPE); + if (parent) + return rimt_iommu_xlate(dev, parent, deviceid); + + return -ENODEV; +} + +/** + * rimt_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 rimt_iommu_configure_id(struct device *dev, const u32 *id_in) +{ + struct acpi_rimt_node *node; + int err =3D -ENODEV; + + if (dev_is_pci(dev)) { + struct iommu_fwspec *fwspec; + struct pci_bus *bus =3D to_pci_dev(dev)->bus; + struct rimt_pci_alias_info info =3D { .dev =3D dev }; + + node =3D rimt_scan_node(ACPI_RIMT_NODE_TYPE_PCIE_ROOT_COMPLEX, &bus->dev= ); + if (!node) + return -ENODEV; + + info.node =3D node; + err =3D pci_for_each_dma_alias(to_pci_dev(dev), + rimt_pci_iommu_init, &info); + + fwspec =3D dev_iommu_fwspec_get(dev); + if (fwspec && rimt_pcie_rc_supports_ats(node)) + fwspec->flags |=3D IOMMU_FWSPEC_PCI_RC_ATS; + } else { + node =3D rimt_scan_node(ACPI_RIMT_NODE_TYPE_PLAT_DEVICE, dev); + if (!node) + return -ENODEV; + + err =3D id_in ? rimt_plat_iommu_map_id(dev, node, id_in) : + rimt_plat_iommu_map(dev, node); + } + + return err; +} + +#endif + +void __init riscv_acpi_rimt_init(void) +{ + acpi_status status; + + /* rimt_table will be used at runtime after the rimt init, + * so we don't need to call acpi_put_table() to release + * the RIMT table mapping. + */ + status =3D acpi_get_table(ACPI_SIG_RIMT, 0, &rimt_table); + if (ACPI_FAILURE(status)) { + if (status !=3D AE_NOT_FOUND) { + const char *msg =3D acpi_format_exception(status); + + pr_err("Failed to get table, %s\n", msg); + } + + return; + } +} diff --git a/include/linux/acpi_rimt.h b/include/linux/acpi_rimt.h new file mode 100644 index 000000000000..fad3adc4d899 --- /dev/null +++ b/include/linux/acpi_rimt.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) 2024-2025, Ventana Micro Systems Inc. + * Author: Sunil V L + */ + +#ifndef _ACPI_RIMT_H +#define _ACPI_RIMT_H + +#ifdef CONFIG_ACPI_RIMT +int rimt_iommu_register(struct device *dev); +#else +static inline int rimt_iommu_register(struct device *dev) +{ + return -ENODEV; +} +#endif + +#if defined(CONFIG_IOMMU_API) && defined(CONFIG_ACPI_RIMT) +int rimt_iommu_configure_id(struct device *dev, const u32 *id_in); +#else +static inline int rimt_iommu_configure_id(struct device *dev, const u32 *i= d_in) +{ + return -ENODEV; +} +#endif + +#endif /* _ACPI_RIMT_H */ --=20 2.43.0 From nobody Sat Oct 4 11:15:55 2025 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8981726F462 for ; Mon, 18 Aug 2025 04:58:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755493108; cv=none; b=mED4EqiG6x70tsR1Y44sIOvRUIGW5Yo50ZJ3vP2L2oXA3IIFKK+2WzkP2T1AJCzOcCCnhZ+2+jCZoTmqrHFUx7XL94r+2PvOYSYXMuHCslkUfvsS2koD3sqWQd+xfvxJbX+MNhV9WjLu3cWhQ3woNt4xDg/TI2QtbCTyCgrqJlg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755493108; c=relaxed/simple; bh=yeEgt3B7oP+kZLvu/rWotic5mkE4aCWzjFVNCBZaVhw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BaB+29JKUyTPBNYb2dFJ+KTXge4Se4c485Xa46dkxETyAdb+00MtIOA38TOhcH4wmNI1Jlkp7HS7G4+Gcq7b/lkrY8rFeOWbnmrLkeIW5yBcyX/h3aASIQLaATFA+V50ANY1VPK/wsZksHgXL/IiKfOxerkoJpAfthP0kWUqHFg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=LJB1YjhS; arc=none smtp.client-ip=209.85.210.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="LJB1YjhS" Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-76e2e8aff06so2888137b3a.1 for ; Sun, 17 Aug 2025 21:58:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1755493105; x=1756097905; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YaG3DvsXq5/AKyC1GLSjgb34PJp+nqhxTUl2VKU3MC8=; b=LJB1YjhSPDi3ASqdXd9e/3LjdPdQdKuh2m3QLX0xEEkeGWoHBtjZvukIpWej28w4sz 54om+6mfqUJQRaifI5eEyVSxcDFgVlIDhblGGCXgNVhkJ3iLBK9Wzur/bpMs/7teNJG5 tw0JrDsiZ1TY0JMxtwoYgMMk+Bl3R+Q3Uj3uIEnjY6mmQn46H7s46lpI5Ffde3licWB+ 1ee6PnKl0m6sMHiKAXbiXfa3EfRhYJARKX8Ypt4r0mRWND6jfIgIkjZcehzpB5fmBLLv 6KgQsIAz8+iIIvAwLj+2DQKWjpIvX4quMFvEgKJ5bf6mPAvwMSBiqb8exMPcRLuBD/jo OI0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755493105; x=1756097905; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YaG3DvsXq5/AKyC1GLSjgb34PJp+nqhxTUl2VKU3MC8=; b=wKMSn7jaWn/xZNhAxrY2GOluB1Hf5iL7rq9RxczTdZAYY5Sg7Qzr7BZeBfs9kmkB3W 7ADzuYIWP1eR+5GVipSnCwd6NEpK+z+V8Vl38wsylZ7P2Gy8mSxvZj1Kz57xNoH6GRI+ cRKo+ly3wSs3Y3xbmpaxQdwdRTwMQ2QMgUErWoBdRzM6ldClXsAwR65ao1n1m1ZBROTf uAArmQpaxH4PQZcuevPsgpA9E5eAJnL0jdw8uXzKXfUdQID82Kt6bXy+MLZskwMbXvEg Yiv+BJfruYMT5Oy2Zs2rKfs31+6RrNKoHDdsEHujXHfU4GRufENawpUrRc94cKVsZ3RY F5Eg== X-Gm-Message-State: AOJu0Yxrts7+ruuJ4WwX9RsZB/Tbr5lcWZ/7LS7qtzGWEEhTNXzcyAMT k9PiIeGLbFdTSPfsIpBzTyAuwIX3rykXzNDdiUXMfhMTePwbTLmuB7rV8T8V+hxrAwCf6GQDeQa /xJOJKD8= X-Gm-Gg: ASbGncvqAprIrJV86mUvfEjdAlW0a5EhxnAkb0VIpWae0eQOphP+Ff6aLkGDhgyJdpx oTzwDwB76GgQiMMds+o/Wzpsnm4TUeFb24l1Mo13TepWv/nHloyfmKKlOczPzdtyDA9QyXJUwTn yAc9Hv0bv3q3SE+DUEYuNmKIT667H5NQMT/hkOMn7TV2jqH4hVAHFq1PdqAybn04evsFzCVI31k GhC6OVxQrTk3CRIDJv9h0SfpixIHdMNdA/FL5Ra2c6npRI28e6lUlbjgFxEYp1+amynOFxFDjeh JULji13ivY1TcdnjGsx4pzU0KrE9YBogySPGwmQ47uqWes5aJjTrFCRwIY+IXaG3EGy1N0C4fMT zKSZgrIQhBEmzi81hIy9ujuD8pb/W8VSkqPlKDgKd X-Google-Smtp-Source: AGHT+IEemk+BWiEUx5FojBtceZEGdoOXlJtGCjztrL0+XbJGAKrKEJt4aBwM+DlqJqMugoECLw6zgA== X-Received: by 2002:a05:6a20:5493:b0:22b:8f7f:5cb2 with SMTP id adf61e73a8af0-240d2dec932mr14433397637.8.1755493105211; Sun, 17 Aug 2025 21:58:25 -0700 (PDT) Received: from sunil-pc.Dlink ([106.51.199.3]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-76e4528c264sm6124047b3a.43.2025.08.17.21.58.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Aug 2025 21:58:24 -0700 (PDT) From: Sunil V L To: linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-acpi@vger.kernel.org, iommu@lists.linux.dev Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , "Rafael J . Wysocki" , Len Brown , Tomasz Jeznach , Joerg Roedel , Will Deacon , Robin Murphy , Sunil V L , "Rafael J . Wysocki" Subject: [PATCH v6 2/3] ACPI: scan: Add support for RISC-V in acpi_iommu_configure_id() Date: Mon, 18 Aug 2025 10:28:06 +0530 Message-ID: <20250818045807.763922-3-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250818045807.763922-1-sunilvl@ventanamicro.com> References: <20250818045807.763922-1-sunilvl@ventanamicro.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" acpi_iommu_configure_id() currently supports only IORT (ARM) and VIOT. Add support for RISC-V as well. Signed-off-by: Sunil V L Acked-by: Rafael J. Wysocki --- drivers/acpi/scan.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index fb1fe9f3b1a3..f022f32de8a4 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -1628,8 +1629,11 @@ static int acpi_iommu_configure_id(struct device *de= v, const u32 *id_in) } =20 err =3D iort_iommu_configure_id(dev, id_in); + if (err && err !=3D -EPROBE_DEFER) + err =3D rimt_iommu_configure_id(dev, id_in); if (err && err !=3D -EPROBE_DEFER) err =3D viot_iommu_configure(dev); + mutex_unlock(&iommu_probe_device_lock); =20 return err; --=20 2.43.0 From nobody Sat Oct 4 11:15:55 2025 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 246A2270EC1 for ; Mon, 18 Aug 2025 04:58:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755493112; cv=none; b=qJw6UHQIQFx0ECsP5/TBTzMk2bdhzkN4LvsI+J///RPNmhDllZWQBSXQgbob/5q2qiguDlh5kAgW5O3pO+G4U0XOr7UUqsRXlmr5I+WHdv/Y3uhz3l7FTZiWAjIXw+avs36qw70x3xIiqWbu4RorUYwt88b4Db1ZhanebqeelsM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755493112; c=relaxed/simple; bh=wOw6JV14X14ffQE6SMj0By+YxAglNmvsry080ZEuXl4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Zljhn91+UtnIBuIuJPIxs9YaDIvkaScrdn07/xnmrdC/7nwqA56e1H7seYPtsUKuiWIrdpt4R9r16AonhOv9/i1+SjngnaC9b5Z8uBP/qFCElIfa8jrcOcjJKTtNnM5uCflWTR9h/aYsgJuMfzqx6FZ+OvBx1rtFPFLq8kThlMs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=Ju2/2KRS; arc=none smtp.client-ip=209.85.210.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="Ju2/2KRS" Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-76e2eb9ae80so2714601b3a.3 for ; Sun, 17 Aug 2025 21:58:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1755493110; x=1756097910; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=NTa6xqW99KKtlVHpIkJtLfUt2l8dIJi8RFcjVe+ZZ0s=; b=Ju2/2KRSAnlsMQsTEpOG97jDqzQc6JWLd1kPDt14HHF+hoT/d8tkfqD7dl2p4wYus5 ObmgXq6ZImKnHvrl4ou9DWqQjb9s5tgeQ9aJZRfPEbMJ26HLMJmcTXbmpq78xnheHhAH wAVXcmXAW+6pLjDmsfmsQZqWAl/S9zSrtfKI146LVJt9S5zkb/ZU2zrd3kOXhDCW1y0Z pce/oeE24sV64ehI8zmDP2q/K6kgI1SYCirXlFBVn8fmxPyaK7gYd1gexocT43F9PZbc LYMLsvLC38rqBFal9+DPOhA68U98iNtGRIXb8RnfOS/tyrlRs9NfU7JQFtpJbMQIRVDE CxNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755493110; x=1756097910; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NTa6xqW99KKtlVHpIkJtLfUt2l8dIJi8RFcjVe+ZZ0s=; b=uthOcM3lm6mp/EctGIu6QMfIU+D3+4z+hRosS7waZ0BaCGjsGXRuUk303QOc1ciqmh DUva38mgU1XfUNmQR0VuB83EhCluvfN9sXClY4m2PxqFFb+tGGjk/DRdh/03tiyFmYGO BDLBFu9ZitUpIZxT3sZiApiYtjjawQjh3xhg+w7+zmWLYhbHf4NLHUeN5EZHRebDH/lh sShrQF5cNZkmehs+Jw3w3vhcfRMM/I5rj2Iir4JGsa5S61gR4vDTP6Qb/HCK2ImWanon G75TzGyOL8mhicPL0VimYVa4BezyBx1zcNSVTp+ps9coqVLHqrO+mX1oe3snsf/gBojL 2m9w== X-Gm-Message-State: AOJu0YxT94/sppUOUvvjoiliqrxBz17VYgP8lTSW3qW/+mOL1nSxcsg/ ZvQe/V+FUSdYIAChikS6W785QXC7Qfr3egajuKn3IIbyN8roBeB0Tvt0hNHITPGQoe2iJxz61h3 dbGLxw/8= X-Gm-Gg: ASbGncsElE58681aPu8ijCp7UxffMEXAH6KvTPdGma11RVxXYCAW2OXxMowne2OlcMV 19+VeBtsswo3Fr8IQI5HHIXFUKN9fpdZNEZIp7AAjd1N6lND5iux2Hqx6njYSuQmqlniAJqXv5Z qLFA1P4LiTRaz9hJMB6WZ8dGTt5NeFWekSKWoOq1G2XElGRijBvw10sPeF2DFIfO//Dc0yzRmIW P91+VDQ8QDEnNWVafO3r//S94sYD6rYmjzKQ2Co5wQW6UaIxJPG6rJZLFFR+HkH5pAvM8+IXLPM RikbJm86WNv4/rXWB+ZcRKngF50uFqbWgt4zDrDSzU3/5smZg5mtMDfCTjZc6NeOa/QLQMmDK57 Jcol4K/eQ6DT373pV6YfCJAnVGswF77Rjlbj8FYyo X-Google-Smtp-Source: AGHT+IGBQAQ9QouKj4M7l+2CqoGFg6HgZE82/OKBnQvuZfjFIYQJQta7bAXmxzrYRho/3qFml+C5sQ== X-Received: by 2002:a05:6a20:3ca1:b0:240:265f:4eb0 with SMTP id adf61e73a8af0-240d300688bmr17338262637.4.1755493109991; Sun, 17 Aug 2025 21:58:29 -0700 (PDT) Received: from sunil-pc.Dlink ([106.51.199.3]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-76e4528c264sm6124047b3a.43.2025.08.17.21.58.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Aug 2025 21:58:29 -0700 (PDT) From: Sunil V L To: linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-acpi@vger.kernel.org, iommu@lists.linux.dev Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , "Rafael J . Wysocki" , Len Brown , Tomasz Jeznach , Joerg Roedel , Will Deacon , Robin Murphy , Sunil V L , Andrew Jones Subject: [PATCH v6 3/3] iommu/riscv: Add ACPI support Date: Mon, 18 Aug 2025 10:28:07 +0530 Message-ID: <20250818045807.763922-4-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250818045807.763922-1-sunilvl@ventanamicro.com> References: <20250818045807.763922-1-sunilvl@ventanamicro.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Andrew Jones Acked-by: Will Deacon --- drivers/iommu/riscv/iommu-platform.c | 17 ++++++++++++++++- drivers/iommu/riscv/iommu.c | 10 ++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/riscv/iommu-platform.c b/drivers/iommu/riscv/iom= mu-platform.c index 725e919b97ef..83a28c83f991 100644 --- a/drivers/iommu/riscv/iommu-platform.c +++ b/drivers/iommu/riscv/iommu-platform.c @@ -10,6 +10,8 @@ * Tomasz Jeznach */ =20 +#include +#include #include #include #include @@ -46,6 +48,7 @@ static int riscv_iommu_platform_probe(struct platform_dev= ice *pdev) enum riscv_iommu_igs_settings igs; struct device *dev =3D &pdev->dev; struct riscv_iommu_device *iommu =3D NULL; + struct irq_domain *msi_domain; struct resource *res =3D NULL; int vec, ret; =20 @@ -76,8 +79,13 @@ static int riscv_iommu_platform_probe(struct platform_de= vice *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 =3D irq_find_matching_fwnode(imsic_acpi_get_fwnode(dev), + DOMAIN_BUS_PLATFORM_MSI); + dev_set_msi_domain(dev, msi_domain); + } =20 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[= ] =3D { {}, }; =20 +static const struct acpi_device_id riscv_iommu_acpi_match[] =3D { + { "RSCV0004", 0 }, + {} +}; +MODULE_DEVICE_TABLE(acpi, riscv_iommu_acpi_match); + static struct platform_driver riscv_iommu_platform_driver =3D { .probe =3D riscv_iommu_platform_probe, .remove =3D riscv_iommu_platform_remove, @@ -158,6 +172,7 @@ static struct platform_driver riscv_iommu_platform_driv= er =3D { .name =3D "riscv,iommu", .of_match_table =3D riscv_iommu_of_match, .suppress_bind_attrs =3D true, + .acpi_match_table =3D riscv_iommu_acpi_match, }, }; =20 diff --git a/drivers/iommu/riscv/iommu.c b/drivers/iommu/riscv/iommu.c index 2d0d31ba2886..7d9370aa58f0 100644 --- a/drivers/iommu/riscv/iommu.c +++ b/drivers/iommu/riscv/iommu.c @@ -12,6 +12,8 @@ =20 #define pr_fmt(fmt) "riscv-iommu: " fmt =20 +#include +#include #include #include #include @@ -1650,6 +1652,14 @@ int riscv_iommu_init(struct riscv_iommu_device *iomm= u) goto err_iodir_off; } =20 + if (!acpi_disabled) { + rc =3D rimt_iommu_register(iommu->dev); + if (rc) { + dev_err_probe(iommu->dev, rc, "cannot register iommu with RIMT\n"); + goto err_remove_sysfs; + } + } + rc =3D iommu_device_register(&iommu->iommu, &riscv_iommu_ops, iommu->dev); if (rc) { dev_err_probe(iommu->dev, rc, "cannot register iommu interface\n"); --=20 2.43.0