From nobody Tue Oct 7 00:25:06 2025 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) (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 007BF2F3C25 for ; Wed, 16 Jul 2025 10:41:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752662479; cv=none; b=D+YW1sbZOGmWZ8XatvQXKIP7Sd/4AByl1ktlO8S7FBcmPj4y1IguS/ns9H4J/7RJXyWaM4+fktN+BAubP+hq/t+9B4AJyhq6zV9yD32sYkuvcwcdsIxmY8rlv/yjOSFtprz28CJZxaa1C9rFi6FMHyGOtCgZTs5at7olbmygqBg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752662479; c=relaxed/simple; bh=yuUDmVMvgxXqB9rDPx4gcql1xgvyC39B2Fu/k0legb4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=I0sldfY9125+O3of6FYzMA2DBE3TC2egYsb0uu3x1/c0DbGc1fwvHsUlvdfzuLwBqbth2N8OwcJa5jsK3aNLiIU7wEHZCHUSadYfF2SkxfHFB0D/PHu+xPcvEb/bEY5Cupi6I1I5HqD5NNeAZcbz4fGncXbNO3S66rXyHCVGR0c= 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=aQb5cfsD; arc=none smtp.client-ip=209.85.210.176 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="aQb5cfsD" Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-74801bc6dc5so747439b3a.1 for ; Wed, 16 Jul 2025 03:41:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1752662477; x=1753267277; 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=z7cvuMytsIqdpckbaG4B9pE2XfMgVLihHPB3qJC2jIQ=; b=aQb5cfsDQvuTrsHQCumHo09VochHKLUU/NvStHLR9LeYV4p8YVQ3SYM+mk1M5RAmdE aD3zaK0N5m6Sa+JG6FmM3jQTAvZCQDwk6+iUAxhIRHL0dY2Ri/I28qF555GsPOXVWWf4 lnBQTQUGLdLHwHvdTwYVGV5tojqPAX0lFfcVd6Z+WjDSOoCYuLDKob5JtviKp16mtOnV IRtNH6/oPKJ+QVd8OXmUbHryueqHybsUs3uOORNPQ+NFM8KCX55ZMoQoWtxDtH/Mg5SS CRxrLxgmlai6Ee9vHBNyT/7hOgAxcCdhAHcqHcbty2qFUw9qBZU64C+os5X46jQUfZC8 byWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752662477; x=1753267277; 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=z7cvuMytsIqdpckbaG4B9pE2XfMgVLihHPB3qJC2jIQ=; b=bBrH+swn0Ey2vLROauhAEyUWM815s+1XHeHm7HN2b+fYc5Z+/81qiHyiX9AAkCn3X2 CP52Gu508U8v98+tV+lGEeeUrlA0PVeVAe1OOhqEdXa+Mra+hbK0eJLR+Ak2dAFZY56d qUygCMyxa9xc/7zS2MRHRYkOz4xasF9jt0fx4d5JokLWoRDZCC433mwF/+a3qrsYJOO3 Hid8hftNK2LWshPu1VV2DD04StAlDFvjV7IeUkKICvatNtmwvmC/X+kmE0onK4PNa4oZ Ls5oLD2yF0mgvQeuS+VmdWRe969kJNBOGBCKLscSA1UOPj74eMKr5LaFC/OyapdiU3B0 PNbg== X-Gm-Message-State: AOJu0YyaC4uXTa+ZX+YvdupjcHRYP6borQnzMHcfoOQ0JkBCp8yrExLT r8XUJ+OG65ye0CO+n69GFokG6wJWhh65tR8xdNYE2e2mx0eaIg2qx6CiUwEU7TqGHQvFaiixrEs 7OMVkHTY= X-Gm-Gg: ASbGncsuKaT6Abwm9DfkjFHUTm5k0unXKhPdEi20Z7fZl0DrltHkSPeK0zfNWYaWHUd hoPV0cWxqXdLR2fvdFbcKa5p9n6L8LCZYoU2XX3wayT4eabhkxpkg2tND6ve3EviFWXAOmUEOgc eYyhF3dEG0HUDB3DCL9nOwlihMBpxA6EpTzDfuE83uTtt8NQxWk4z/+j/tGhwywGqjq05asQ6qY AAyEA8qLcW1EmelEXLd+ER8nOuDSjSlmfZVFy2XflQthmEoXa+V/CqWlBs1zwf9ytKXI6p1Pzeh 3Htp0XnX33jbV6nw2v4X5/V86z8i12VEFhoZMeIrd3fbs0p+Dgywo0GGUDKKoRxqQXLb0EUlkoj FXoQs5IPY6+F/sD8IJHbn5wraPtqblbAb X-Google-Smtp-Source: AGHT+IEQo8BTjEA8dv3qComAn579iCusbeX0bf7sGC5ygFF46Xvcz6+6fNZHsSta4XexDcpmpBEqRg== X-Received: by 2002:a05:6a21:3285:b0:231:c73:7a76 with SMTP id adf61e73a8af0-237e041c1b8mr4454127637.2.1752662476512; Wed, 16 Jul 2025 03:41:16 -0700 (PDT) Received: from sunil-pc.Dlink ([106.51.195.230]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-74eb9f1af40sm13946709b3a.72.2025.07.16.03.41.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Jul 2025 03:41:15 -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 , Alexandre Ghiti , "Rafael J . Wysocki" , Len Brown , Tomasz Jeznach , Joerg Roedel , Will Deacon , Robin Murphy , Atish Kumar Patra , Anup Patel , Andrew Jones , Sunil V L , Anup Patel Subject: [PATCH v5 1/3] ACPI: RISC-V: Add support for RIMT Date: Wed, 16 Jul 2025 16:10:57 +0530 Message-ID: <20250716104059.3539482-2-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250716104059.3539482-1-sunilvl@ventanamicro.com> References: <20250716104059.3539482-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 60bba48f5479..426540c1fa3d 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -345,6 +345,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 d71ea0f4466f..67bbf3b7302d 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 7bc40c2735ac..4381803c308c 100644 --- a/drivers/acpi/Kconfig +++ b/drivers/acpi/Kconfig @@ -546,6 +546,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..bd108f624ba0 --- /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_offset; + return parent; + } + + return NULL; +} + +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); +} + +/* + * 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 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 Tue Oct 7 00:25:06 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 AB8592F4337 for ; Wed, 16 Jul 2025 10:41:23 +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=1752662485; cv=none; b=PUk3obuJkgGr2Ir5wF9MsAGRQMzS7g1JefAoVAck0LFMQnj+HvCQGnWJBh3uDhX9sB1W31oduMsj6LrIsBy9qEhkIuQO7rhwzaMZnZ/gcThfq+6rmjJAP6blpCf9yOS7UqZEFjhXYBnn/ETuQGJCUlS+yM0jEJvXqMU8pd3KzbI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752662485; c=relaxed/simple; bh=yeEgt3B7oP+kZLvu/rWotic5mkE4aCWzjFVNCBZaVhw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IgzeT0mSQ0KdYPII/8WP4w003nbikA3sB17eKc1OS6mPH9d9bvy7xSdEFv0UfmyzxhamgDWFfUYEmXZMzw8UNkTxTCqcbNdm4MYkqQeatOVlFq09BzsGdawN6pxciU/pOk/peJlVjAIT4nmuzqE+sdmcG7mhv2jwE0YiJuRnWy0= 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=NZRwvBL7; 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="NZRwvBL7" Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-748e81d37a7so3920351b3a.1 for ; Wed, 16 Jul 2025 03:41:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1752662482; x=1753267282; 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=NZRwvBL7TQCUevVXlVOVDtTEb4fXOJ0970bmPnHHjezYtwcOFyf23lbCu1M0BUwOjd c4KZvgeZtaYKGCIPa7SqZc4IoR0TNYVLA6hS/4Str8WlMLipmxs+Onzc8OYEImAivX16 rlsPJAVHgkRo/A9dRoxO6PFVs/FrDIRYFRgMGw4uXseFg5dVpGlR3qJyRkaeACbw6HWC j+SthCv7wctN/ZzgYz9xhW9nrzO1aKvoa230paMOl62wr2YoS6v9y+qnkDAOYHHAAxAH 8h+fp5h3g2/IuEuPlT0SSlc5hPBSm0oKy7NO1SgVHZhkjdBsoNWZ2W15H8vzXHzcBlfC Y0Yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752662482; x=1753267282; 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=vJ05z/brJa2hA48XZuQKjvD8C6ddLox0hDvGW/P9mWfAJjDztDEc+dTUdEXe71PSyG 65ZmU5yrm7nRVK85meKlwYQw0ayOGEbnHIIFzbueLVf5KrLMHKtJm/LfmztXc4nDiEs/ yEmHAxVg9dF1ZUfQq8ZulO+mA9Pyw6m6Zq2vSF14dzek/nFOsSfURT4YE0B3vOCiDGFs aOPemoqYB53AtXHzhn+HhR6N7VUMqXo3Ggh+0hcCzZ2baAYglYSawkHlM2VB57SoqfEs u9w/gaAIF1e81oHEXxmL/pD4kDyt0vzxROTQDo2fj/9V5chv9kUuLl85jlOzq/fQYesX wpnQ== X-Gm-Message-State: AOJu0YxM09beYGOxVShupl5IH+3xBPwdzb9ZoYsSKlFoqkaGDU7BWa9M VDRiTEdwGt39rZNypLsMojfLKTePOnw/T1b2ZfWVifptCyadDGWj1CIhasJ7ljuhvwFoADshhDa 8z9GxZ3Q= X-Gm-Gg: ASbGnctDhusYJRzb2U+58KM9/HNe3/NXKV8KZx4TvMloc1AJnvHRnBptesUy+PmNlUr LP9eWVUq4e6OdoWoiRoDTb53rG/JMlHPALu7oIfmhIAQFyPyEBCHZR9xH98gDaoEU1MB+ysNzFS 2dXAlOyCWQk4OuEP0fXgQtTlClUN+2CL3QDauc4eGOwlRffnUxg9LbKMAmqYtXNQ0LWPVSotpDK LjxTHKFMIslswNC3Pi90UQ6FuvM5F9F+JGx8vtmvtE+Jz5qFdLpau06AgVeW1qNt5LF+8ldxhs4 GMzfPkV8tlI5ZcH6P+Vncwu6LCGTQduMe/8UCtRXZx5ucK7IqxNDGA1TAIj3qxXcBnP4OG4qyIT kxkpPe08Itbe1ppfgrztkf85tPgmsRIpZ X-Google-Smtp-Source: AGHT+IEC8Wh248xbvV7SVKKzD0alSVzVgeFsgJh9ogEs3+/ngP7xonwyOrkgTHqNNgbjcXTmqAIWTg== X-Received: by 2002:a05:6a00:2387:b0:749:540:ca72 with SMTP id d2e1a72fcca58-756ea8b944bmr4580850b3a.24.1752662481956; Wed, 16 Jul 2025 03:41:21 -0700 (PDT) Received: from sunil-pc.Dlink ([106.51.195.230]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-74eb9f1af40sm13946709b3a.72.2025.07.16.03.41.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Jul 2025 03:41:21 -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 , Alexandre Ghiti , "Rafael J . Wysocki" , Len Brown , Tomasz Jeznach , Joerg Roedel , Will Deacon , Robin Murphy , Atish Kumar Patra , Anup Patel , Andrew Jones , Sunil V L , "Rafael J . Wysocki" Subject: [PATCH v5 2/3] ACPI: scan: Add support for RISC-V in acpi_iommu_configure_id() Date: Wed, 16 Jul 2025 16:10:58 +0530 Message-ID: <20250716104059.3539482-3-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250716104059.3539482-1-sunilvl@ventanamicro.com> References: <20250716104059.3539482-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 Tue Oct 7 00:25:06 2025 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (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 36F1C2F3C3D for ; Wed, 16 Jul 2025 10:41:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752662489; cv=none; b=d+xa/UQzlXhHw4nrpYzKO8fHqE2A+lnBSuakKt7QyKeabhn86MbIlPkdltZewKOFxOsuznhwLTY44fOmXmoEBwYHddQnwyRYq2czC3SoLRv7Ww29P/Wf1L9BTH5xlBAWxzzEoAiv1hFQm/LBT/HIH0M0XonAF9WZFVU8JEzw3t0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752662489; c=relaxed/simple; bh=TiMCJ1JIsrrw0j8yUw5lr7+dQqDn3hFgscmUJMRLbPk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HL63NPACYig+yJIggAm8KrN1Dt3iF3l4SpeKel5zUGqQXtfeTZUZtpfigArD9BwN4Xm1vAqWX0Qk3tR405lW7XtcMi1RljUI4lce/kkd7ozVzgbE77f+vYTciuADXDYqLqkTFozbWx8cIb/KzE+eWKgw1NrxqHjPc3Eq1KabDxE= 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=nQbrva2j; arc=none smtp.client-ip=209.85.210.171 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="nQbrva2j" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-74801bc6dc5so747551b3a.1 for ; Wed, 16 Jul 2025 03:41:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1752662487; x=1753267287; 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=BZUWpBwM0eiM3bQczAhHsGr1w4CoIgRijBa2HvAnStE=; b=nQbrva2jVKMH0EVWBryyuW8RkZH9yy+RrrLkEXAXb42ZapRnbM2HxvPFWCZH+RDUmW AR/p/QdPqzEDxFz+zzT5fN1WS+D0K9ZXVZrVaewWy+8zVmzCXGbgTlvvGL4rf/I8Nx/O WvY+z6bIgeuSujSARbtUFEP+moe5ZETbUUNcFjJS9OItXUO4vk2+lD+7Zzz1eIy7LhLy 2GldHUJHXiJ47oH0UGpza3Jkuwn0n1TkcqNOGI+JjgTHBJzqhlGcP9AFEf+3Hv5VpED4 lw6/BrJ68IrGDMBODQu3VWgyIAq7ZpfBFPAoiPHm9Wr1DEJxpa877Q8ydDPzPkaafZp2 y5EA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752662487; x=1753267287; 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=BZUWpBwM0eiM3bQczAhHsGr1w4CoIgRijBa2HvAnStE=; b=snKsyqZjAbFJzNMA2YpvK58+NYPrYkQX7sx/SCLQomgy8gX+7Usg8nvSPCbGNghHOJ Qtt3ETcJOVj8R6qsFNyhwSZezGtRImchkxhqkOY005xoBfYZO2KhhvhfBc2xDE3+3yf5 fgJubEKMgeHbMostIFMPu1Q345+YLY1litQ+TUi2MjMf8YMbTHSJJb8YS5slFPveDmg9 N5GXJPwE/ZvrWK/bHGUGQijTHSqDxVVcZQJJ5tOWhyKP7uTVpVzqWha0jTgVcORoIrhr fn0Kl1k6WcRuU2iOS3m6GCrWU98Qfizm7GrxggrjBy3cDLx2oGERhN+VfwIbLanG6lIh I7Ww== X-Gm-Message-State: AOJu0YxVe2GZoHKq42hniCdCLt1Zayw4jmWVlrHsp9O4iIUDALegK8eS lGJZoMHTbotNBFlax5eNuzrnUUSHc+A1MdFNvCzb4s6va8mT9S5bO4huZue07uMkE0TB/e99uaB Oob7Wyg0= X-Gm-Gg: ASbGnctkpoPdwCLuX1auWO+/MWhpCdKFOxmcoNlh/R9W7JAY/VSQWwawgAY/LbO8mML uy3BqnVewHLYBoivSd1fOci5Q35h5bXvmEphUk76H0muaNv5asbXEkwCv/k8GsG333qWknHi0b0 M935vcbAIsf8CNSIHi2BKFNcDjpr1qTTdPfHEmYgw0aEemI+qbXM4ChbaoJsZoOETS0rj+Qw1v6 dLHiTYwSMdxaAFyhuimt4IZOQ+Yngxr1IwC0RVvMd/mTJRxt54FK1O7TvSx9tjZH9WqK2Fx2aX3 Zg6ohrouuMw74SOy7MVtXtiLFbB3FgzL0nyJoJnNtfFVdcY8lWBxCQnQ5W6ESst+qIGOEVm4qdF XLoZU2E+tvjyK7vchZiTY5KryHJu0XNOZ X-Google-Smtp-Source: AGHT+IH/Lk91h2N/FwA9EAOD0yJlQtTfyDy3TLsMiePhmK16NWxXzdzTp0ubA0n3RaF6EsVZf8LtAg== X-Received: by 2002:a05:6a00:ad0:b0:746:195b:bf1c with SMTP id d2e1a72fcca58-75584eb932emr9392926b3a.10.1752662487002; Wed, 16 Jul 2025 03:41:27 -0700 (PDT) Received: from sunil-pc.Dlink ([106.51.195.230]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-74eb9f1af40sm13946709b3a.72.2025.07.16.03.41.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Jul 2025 03:41:26 -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 , Alexandre Ghiti , "Rafael J . Wysocki" , Len Brown , Tomasz Jeznach , Joerg Roedel , Will Deacon , Robin Murphy , Atish Kumar Patra , Anup Patel , Andrew Jones , Sunil V L Subject: [PATCH v5 3/3] iommu/riscv: Add ACPI support Date: Wed, 16 Jul 2025 16:10:59 +0530 Message-ID: <20250716104059.3539482-4-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250716104059.3539482-1-sunilvl@ventanamicro.com> References: <20250716104059.3539482-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 bb57092ca901..45a263c9e0d5 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 @@ -1651,6 +1653,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