From nobody Sat Feb 7 15:40:02 2026 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (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 E27DD1F4C8D for ; Wed, 14 May 2025 05:57:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747202262; cv=none; b=B/E00+FQ3vpI+R+J79tgtuyej0Nezes6aTo4mZrf+xrQ2lv+rlHMLGHSpzVioxzWS7erLA3nu9x3+GmpKghnDrO/TXl8q19XvVHB2hakfqHbTq1Me1dfHVkbacTbM7uwxCatZ2DsXuXvDV1hup35Mb1a6hOQPSotyGhfPtwW2vE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747202262; c=relaxed/simple; bh=P/M7n4SDTSF4DDX2hlMecwto868uMFq8eIhCBjXO3DQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gz1xPOU04hU51lEviH+I2YvDsFH4JbRAfxeOFqjRzzpk8AZLiD8h6nH2R4UMhpiGChrXaScLDCUyf9SeAWBnTRS4DaAsVJB+u+j6KKQf/Msu3ZCYoR3kEtXF5CZe1uY/JsVmdzik7ALpzTZrX5Spiat7urVSHdLVsAvd1BNr7HE= 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=Zuw+pKv4; arc=none smtp.client-ip=209.85.214.174 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="Zuw+pKv4" Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-22e45088d6eso81103715ad.0 for ; Tue, 13 May 2025 22:57:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1747202259; x=1747807059; 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=r3mv/YR2xZRmrbZBh7XLVUMsC3Lat0ehLZET0BefXjE=; b=Zuw+pKv4Ly8gLlgsHojqbhZk6mDL8LdP0XjifOF8Y25uh/hE1ZBtxMS5NdY3HCarkf HI5ZRg91KmhA+MiOktgVqTrFXE7nOYKMkDGyLmum7cQ5U4MVwopeSIQdsoGjZdWtOHw4 4t7HG0NPkYoEatVy69ocGwtpxQ0R1rbr+F6rWv2a3/iX+dLyG556oCkBS1NcU89OIsIx pZSTu8+2daOkn0jnA+yG/YoYReYndzfQDDx6aMCNuoOFLK/AyB1SZGK5dTfClO50JN8W lVieOVpx07VlriUE0aXg1qM/zE0nRq8RT+62qi8c2VwhYj0u2Lhqt4wc3/5HtBa0Uan7 3zBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747202259; x=1747807059; 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=r3mv/YR2xZRmrbZBh7XLVUMsC3Lat0ehLZET0BefXjE=; b=FycXYUTj/sAA14axlaWL6HOwLeMPi1vu/8PG/RSBY9fi/x06Dn2u2/XinV6trln39l /BIjsw5It3LwVfJfS2dr5zqaR74g2kcgry7oupdfXqmwtQi9iFidpiGeCUvUrxrIsl27 lg8GeMfEJNWDPaZRv93x0d5THO1Gx6zoUHkYubx4Iwk/7nP3qMwQSGWeo7dCWX/e1Hly MUvGdLMb0nuv2r9HoX2R8KU4h9VeUqx2yuu6MAwEfRxEZhuoOyJ042Tfnje5LwlK5kCF p2nw1mehd8694X+IKP2qBoMzZTX7vX0jRtxy28T8fRynt7hdCw86NiB7IfS87lPvLMKI u5uA== X-Gm-Message-State: AOJu0YxfML4q5FiI52UYQ6uFD0HuVPGh7r/6rFX/DBKpwP/CNfx/vv3t NOCokFEOLggIZhO09PbPv+1nDGX6gfhbYU9rcY44i7S570t50arDYgII/Z5d51Frwx7a3y3OygN hgjM= X-Gm-Gg: ASbGncvd0OcyYV43dBaEbNU5Y79aBCWr1vTfRg+7ZxUai1oHQ9vu2TYyrN0S5HG1HTb qN+WvBFwxljeYw/k08GvybvrbsCkyxjnZZiZwo8LEz5vrO56+muePRIIi1RqAl55eEF1ctPlgd5 llmCrNbgBYYy2n301V3rAMreeStV8F9vIi//ojRdfWIhzngEF+kOCAqMNZS5wLrwICdSZ/WzSi9 7ksU7LHnoXiXv6fHX6zMiMsQFSz0hBUROq6c68O63LMpPkP9LlyicHmzAN9cJ2Z/KjJJRtLmUgV YbMaTVigGP8rHi2cYF/4bH0G1FJw+2fnsL69Fqjo0S8ikVyIev2am8dtIN6loQ== X-Google-Smtp-Source: AGHT+IHE6ExFWnu/zrAvRfvX4AYC0RkEswg44e9W2VNDqbKcdiZ15MPr+ykcmRts8B4KvtHH+QD0iA== X-Received: by 2002:a17:903:41c5:b0:21f:1bd:efd4 with SMTP id d9443c01a7336-231980d04a3mr31983045ad.19.1747202259577; Tue, 13 May 2025 22:57:39 -0700 (PDT) Received: from sunil-pc.Dlink ([106.51.196.253]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-22fc8271c2dsm91721615ad.135.2025.05.13.22.57.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 May 2025 22:57:39 -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, acpica-devel@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 , Atish Kumar Patra , Anup Patel , Andrew Jones , Sunil V L Subject: [PATCH 1/4] ACPICA: actbl2: Add definitions for RIMT Date: Wed, 14 May 2025 11:27:20 +0530 Message-ID: <20250514055723.1328557-2-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250514055723.1328557-1-sunilvl@ventanamicro.com> References: <20250514055723.1328557-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" ACPICA commit 73c32bc89cad64ab19c1231a202361e917e6823c RISC-V IO Mapping Table (RIMT) is a new static table defined for RISC-V to communicate IOMMU information to the OS. The specification for RIMT is available at [1]. Add structure definitions for RIMT. [1] - https://github.com/riscv-non-isa/riscv-acpi-rimt Link: https://github.com/acpica/acpica/commit/73c32bc8 Signed-off-by: Sunil V L --- include/acpi/actbl2.h | 83 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/include/acpi/actbl2.h b/include/acpi/actbl2.h index 2e917a8f8bca..99ea8bfe47de 100644 --- a/include/acpi/actbl2.h +++ b/include/acpi/actbl2.h @@ -50,6 +50,7 @@ #define ACPI_SIG_RAS2 "RAS2" /* RAS2 Feature table */ #define ACPI_SIG_RGRT "RGRT" /* Regulatory Graphics Resource Tab= le */ #define ACPI_SIG_RHCT "RHCT" /* RISC-V Hart Capabilities Table */ +#define ACPI_SIG_RIMT "RIMT" /* RISC-V IO Mapping Table */ #define ACPI_SIG_SBST "SBST" /* Smart Battery Specification Tabl= e */ #define ACPI_SIG_SDEI "SDEI" /* Software Delegated Exception Int= erface Table */ #define ACPI_SIG_SDEV "SDEV" /* Secure Devices table */ @@ -3002,6 +3003,88 @@ struct acpi_rhct_hart_info { u32 uid; /* ACPI processor UID */ }; =20 +/*************************************************************************= ****** + * + * RIMT - RISC-V IO Remapping Table + * + * https://github.com/riscv-non-isa/riscv-acpi-rimt + * + *************************************************************************= *****/ + +struct acpi_table_rimt { + struct acpi_table_header header; /* Common ACPI table header */ + u32 num_nodes; /* Number of RIMT Nodes */ + u32 node_offset; /* Offset to RIMT Node Array */ + u32 reserved; +}; + +struct acpi_rimt_node { + u8 type; + u8 revision; + u16 length; + u16 reserved; + u16 id; + char node_data[]; +}; + +enum acpi_rimt_node_type { + ACPI_RIMT_NODE_TYPE_IOMMU =3D 0x0, + ACPI_RIMT_NODE_TYPE_PCIE_ROOT_COMPLEX =3D 0x1, + ACPI_RIMT_NODE_TYPE_PLAT_DEVICE =3D 0x2, +}; + +struct acpi_rimt_iommu { + u8 hardware_id[8]; /* Hardware ID */ + u64 base_address; /* Base Address */ + u32 flags; /* Flags */ + u32 proximity_domain; /* Proximity Domain */ + u16 pcie_segment_number; /* PCIe Segment number */ + u16 pcie_bdf; /* PCIe B/D/F */ + u16 num_interrupt_wires; /* Number of interrupt wires */ + u16 interrupt_wire_offset; /* Interrupt wire array offset */ + u64 interrupt_wire[]; /* Interrupt wire array */ +}; + +/* IOMMU Node Flags */ +#define ACPI_RIMT_IOMMU_FLAGS_PCIE (1) +#define ACPI_RIMT_IOMMU_FLAGS_PXM_VALID (1 << 1) + +/* Interrupt Wire Structure */ +struct acpi_rimt_iommu_wire_gsi { + u32 irq_num; /* Interrupt Number */ + u32 flags; /* Flags */ +}; + +/* Interrupt Wire Flags */ +#define ACPI_RIMT_GSI_LEVEL_TRIGGERRED (1) +#define ACPI_RIMT_GSI_ACTIVE_HIGH (1 << 1) + +struct acpi_rimt_id_mapping { + u32 source_id_base; /* Source ID Base */ + u32 num_ids; /* Number of IDs */ + u32 dest_id_base; /* Destination Device ID Base */ + u32 dest_offset; /* Destination IOMMU Offset */ + u32 flags; /* Flags */ +}; + +struct acpi_rimt_pcie_rc { + u32 flags; /* Flags */ + u16 reserved; /* Reserved */ + u16 pcie_segment_number; /* PCIe Segment number */ + u16 id_mapping_offset; /* ID mapping array offset */ + u16 num_id_mappings; /* Number of ID mappings */ +}; + +/* PCIe Root Complex Node Flags */ +#define ACPI_RIMT_PCIE_ATS_SUPPORTED (1) +#define ACPI_RIMT_PCIE_PRI_SUPPORTED (1 << 1) + +struct acpi_rimt_platform_device { + u16 id_mapping_offset; /* ID Mapping array offset */ + u16 num_id_mappings; /* Number of ID mappings */ + char device_name[]; /* Device Object Name */ +}; + /*************************************************************************= ****** * * SBST - Smart Battery Specification Table --=20 2.43.0 From nobody Sat Feb 7 15:40:02 2026 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (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 725371F4C8D for ; Wed, 14 May 2025 05:57:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747202268; cv=none; b=qCgmF6UB7geh+BOmZmJx6slLrNHt/KVy/5EozhJNQwrPsOtOw7JClMKUihouoAZ/IbN2kLMt33RG/acVF6kmtriO0EYX+88/7EpYvFdGCSsvylVKTPgnK3yKX8E//kkSjw7qXT1gj4dZ0vht3VLTd9aziOjfjW4bMALPvxn1oFU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747202268; c=relaxed/simple; bh=SYa325lxDvLm/c1Cfscq81MyLsybBmizSzm9EAsQTrA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qyQ0Eslw+T08yf1cadcKlr4IV534CKxM1reWgQ5lBeEuj1Pwm9MVV1mbfViVWVoVuy+3gdCGdL2Vxea0JqLSN5Gb/c9nMTQp0a4hM+alhvzBxW8gPtTSNyZci4eHLgyM4jMtu1yjWThMlMKIBEpz8X+DL4yn03UFF+oYrkLjnWI= 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=HfGOjnWK; arc=none smtp.client-ip=209.85.214.175 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="HfGOjnWK" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-22c33677183so57404885ad.2 for ; Tue, 13 May 2025 22:57:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1747202265; x=1747807065; 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=G6fvQw8ArKf8SQMhfSX9ifxELyixKcDKUav3/Y9E+jk=; b=HfGOjnWKaPT0mILGVr5vSnjpV5J+27rn+2e4U0y0e1vlBzpQwPGzqB5UqpWMbjSfMx LIABXAlXdMlpyzJY6d6/CUbzbm6yVDVru9lDVBDaHqp8p5LcfQFtRkFAp7uN/PHYxm7c iFuc3JDx8IIYoDaol6BpNdNKAc/rCo0IXjK2I/wVecrnRGB4ejPX0CVa1TZxH/4ZLKE2 KPrJGYuKCjjlCoIuwBJg63dv4X/LL13C0yo21WUfcSL/lXsz1wMpwT8J4S4YLy16QWKv 5YLXKElW1jQPxmgKgb+4RxAD9ClZP2t0pHe+5T0icGCwh6/DUIucODCRwIOvobo9P8K6 ps/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747202265; x=1747807065; 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=G6fvQw8ArKf8SQMhfSX9ifxELyixKcDKUav3/Y9E+jk=; b=CDhc1SK7uh11344MNohbDvVtiNu74ORbfHjPIX5dAJ5WehfMwCU3ojaZ1K3m1UqPgO sQEemd2ZhHRqhuXy+Jsnwri8X1xEzppwzbg1QMUgpPPNtYkckhHTN/ITe4zpFTy3NhQI 2YKXfCe45GRJX0J0NNpbdW50Eb1krpljTjKdemTOcuEfVAVnJX6yea7Qzxeb6tWdYd1k 7d6RikejK3flLsOscAWQ5XyNEW86ja+ynDku/LGCcYLc22uqf+j4NeLBDFF+RvmsXRH0 SPz/UCKjIZ7hlM+K1O8vXoPbHQIcSh2NsxrVqxamEnV2rHQKANTkBo7ZzXcodQNNLeno Y19w== X-Gm-Message-State: AOJu0Yy0F5NfP8ppXjxFCYdBZj6al0bWhQj9uARtsIo1/SjFac6iD2rA q7YuGDxQ7ay6srslTRtL0ex94HHVOWVyuP3X9saGEjb6E8LSaRReCqWCsC2lhrpOXVap3nRyhyB kunA= X-Gm-Gg: ASbGnctlE72LZiYem+9js2omNrerv0hoGbKsP5XP5u2OLE7xOk6oIGWiQ2F1QHDEDxJ z/c7CfCVqWlorxs9AT8MWEm/8zb9Ykt1Auvl6SnYWXNBDRltt0ZI4apwGrGiCxGyAJgFXfmhWDa FrNstvYAaKJILxbHy0Bj9ySeJZVOy/TD+LnuwBe01tM7Tzxe1VPEgviL0ZHW1wt8St3Ps5zkUfC vzXoPUv3xV3DfJAAExccImXoaNacUkQigdSAwZeE/Xc7YprKADnycMSqgVAMMiMsrUSy+rWpdwR DRdtwwKDJIggTt90QmL3b5XRYsBwAkX+XMKVEITqLo4l72PjLfFboQPwUPy+ZhP9An5fuzyX X-Google-Smtp-Source: AGHT+IGh1jpInp4xllExgGl3qK13hdKQFLc071qcAl9rThM2HbjJKWTTRYLMiiqAVf05hh0vJGztOg== X-Received: by 2002:a17:903:3ba4:b0:231:7fbc:19bf with SMTP id d9443c01a7336-23198115855mr26702025ad.6.1747202264881; Tue, 13 May 2025 22:57:44 -0700 (PDT) Received: from sunil-pc.Dlink ([106.51.196.253]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-22fc8271c2dsm91721615ad.135.2025.05.13.22.57.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 May 2025 22:57:44 -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, acpica-devel@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 , Atish Kumar Patra , Anup Patel , Andrew Jones , Sunil V L Subject: [PATCH 2/4] ACPI: RISC-V: Add support for RIMT Date: Wed, 14 May 2025 11:27:21 +0530 Message-ID: <20250514055723.1328557-3-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250514055723.1328557-1-sunilvl@ventanamicro.com> References: <20250514055723.1328557-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 --- MAINTAINERS | 1 + arch/riscv/Kconfig | 1 + drivers/acpi/Kconfig | 4 + drivers/acpi/riscv/Kconfig | 8 + drivers/acpi/riscv/Makefile | 1 + drivers/acpi/riscv/init.c | 2 + drivers/acpi/riscv/init.h | 1 + drivers/acpi/riscv/rimt.c | 537 ++++++++++++++++++++++++++++++++++++ include/linux/acpi_rimt.h | 21 ++ 9 files changed, 576 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 f21f1dabb5fe..de125e6db921 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 bbec87b79309..ef8357c7207d 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 7f10aa38269d..1462452784d3 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..ca089084b29f --- /dev/null +++ b/drivers/acpi/riscv/Kconfig @@ -0,0 +1,8 @@ +# 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..c429a7d0b33d --- /dev/null +++ b/drivers/acpi/riscv/rimt.c @@ -0,0 +1,537 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2024-2025, Ventana Micro Systems Inc + * Author: Sunil V L + * + */ + +#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 inline 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 inline struct fwnode_handle *rimt_get_fwnode(struct acpi_rimt_node = *node) +{ + struct rimt_fwnode *curr; + struct fwnode_handle *fwnode =3D NULL; + + 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; +} + +/** + * rimt_get_rimt_node() - Retrieve rimt_node associated with an fwnode + * + * @fwnode: fwnode associated with device to be looked-up + * + * Returns: rimt_node pointer on success, NULL on failure + */ +static inline struct acpi_rimt_node *rimt_get_rimt_node(struct fwnode_hand= le *fwnode) +{ + struct rimt_fwnode *curr; + struct acpi_rimt_node *rimt_node =3D NULL; + + spin_lock(&rimt_fwnode_lock); + list_for_each_entry(curr, &rimt_fwnode_list, list) { + if (curr->fwnode =3D=3D fwnode) { + rimt_node =3D curr->rimt_node; + break; + } + } + spin_unlock(&rimt_fwnode_lock); + + return rimt_node; +} + +static acpi_status rimt_match_node_callback(struct acpi_rimt_node *node, + void *context) +{ + struct device *dev =3D context; + acpi_status status =3D AE_NOT_FOUND; + + 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_device *adev; + struct acpi_rimt_platform_device *ncomp; + struct device *plat_dev =3D dev; + + /* + * 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 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; + struct acpi_rimt_pcie_rc *pci_node; + u32 id_mapping_offset, num_id_mapping; + 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_pcie_rc *pci_node; + struct acpi_rimt_platform_device *plat_node; + u32 id =3D id_in; + u32 id_mapping_offset, num_id_mapping; + + /* 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); + } 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; +} + +#else +int rimt_iommu_configure_id(struct device *dev, const u32 *id_in) +{ + return -ENODEV; +} +#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..9c7b2b1580e2 --- /dev/null +++ b/include/linux/acpi_rimt.h @@ -0,0 +1,21 @@ +/* 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 +int rimt_iommu_configure_id(struct device *dev, const u32 *id_in); + +#ifdef CONFIG_ACPI +int rimt_iommu_register(struct device *dev); +#else +static inline int rimt_iommu_register(struct device *dev) +{ + return -ENODEV; +} + +#endif + +#endif /* _ACPI_RIMT_H */ --=20 2.43.0 From nobody Sat Feb 7 15:40:02 2026 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.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 3581A1FBCB0 for ; Wed, 14 May 2025 05:57:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747202272; cv=none; b=azab8LwjG4okVNePA0LVBaPgLekzsL5mZH2EKwoEyX1IxfEHBAAiVO2jQtlcSCGFvLLdkIRfquOHd27HiVgg4ymUBBrQ3e/jhhJxzeBEnwKmRTdHD2g+vWrmwt07Y01Y3o1QwcZ26dTzTz4xDkTjm2NIVFHnVnyOFLGL7rmI9EA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747202272; c=relaxed/simple; bh=j10W9ERtTCLuRtXkzV2FgTmpZyoQoyxJASYgwPYwbms=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z3ZOtZ9dDAtRKzWiJ9k7J8JwSJb1On4/jpSKFKTwrPtif4tc4ZfwU47WIEO89LKUgalzVRu0u/M3skH0FGJVZJ1FHSpY4+Bxsu7GreD8QeYVNGRLK3KQSiB7EZawjy96DsUEJ1bv7brT+C4a9voBnExVRw7pjesunHjgzaHlKQ8= 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=acS4zCvn; arc=none smtp.client-ip=209.85.215.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="acS4zCvn" Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-879d2e419b9so5884373a12.2 for ; Tue, 13 May 2025 22:57:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1747202270; x=1747807070; 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=AnkjvbjcuENvVJ26saTSRizx+WjEaICu8Lhi+aJlcF8=; b=acS4zCvnlH0ZhS+mvxsQX3lGvU0SupI9o/3bFSXPS7s2zfMB+TKAsfsgHcaQCgersX iWsZMTNiGQtAVPbdoeC77/jKOB5puwghTYa9VRfTdl0WPahbA/ahAW3nfpWwUsHJH5xM 9hF0sCXL9oK2ObwGsCgDtTw7Hv4d0QYhTJLb9Ym5z8CtCC+aWhFUppGkzjkkIKC4gAcH sPRIH1cJf/+FeCDay+dSWrZTiNd1mjdENp6+JA3NXvk7ZQMN0K/BlFR9RFB+3Xq+Hoyo 8mt/a9PTHkYvV0nTU6cRPUvQ1BNA0AD/L3+SjqADEZlNwTqwMJX0gs67dZ0g2MiMzc30 FEtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747202270; x=1747807070; 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=AnkjvbjcuENvVJ26saTSRizx+WjEaICu8Lhi+aJlcF8=; b=f2bbsa75uQCOB8AN+Ocxdma7NKPgr83xfPTgxsTxxEI9Cv2ZrfysRWtcfrs+OPW6DF miW4bkVCakjBj1FrXDrboQ42ae6wUvv8W5yusWvytymVQ+FRU4wUeedTzxAOqWcRLnE0 UbXZAHQi1VqdQ6B++XLIwvJdn8+XOzWJ2btqGDJ/zA3ZEibc2txTDp35NmBrZmbekdIu +Aw2xegrEMnN1xcwiwXENAhirnlm7OfAVvfbHyvDdcvI5wkrfDLRswDXoeHZCUhL4LLA rPXirZLyeKeoUCYEyuBpF9NE528dWRGfvzaweBUQVDfqiG8+sPpSgVthu49t9OpZkCBt MExA== X-Gm-Message-State: AOJu0YztRm5m4J3Qq6we3Z5Eq3i6z5sCjRb0hRIDQ5tU0JkJkjX8mOD7 ATOVeie7VsIfKCBo8SeuAVBECcILGemNFN/uFqojszz5amRES/RqQumCR25SVnu9Wwa6BT7+Srd N6cA= X-Gm-Gg: ASbGnct+INyRkeBZpcvhjEV48H1HT5oj/AOKVAXijl6fgy822DnUGNw1BkeuvFOV13t DcEwJx1GtKwVrIE6xmFTRwtXtrDZid3cO6EVssIOmCiAIx8cOFOx4eI+dBjiK/oUyyf5dAwYILW TVH1fv48wVkmyo+wVQJiv3p/Rxa0LfHn7zDz07/RbaAoWXch2iw5tr7F9E7ApGtZ8GDSt5Qt76T cf8G9gFKp0gbnNDJArNh2CttQCfBPy3mWa/5L70YV5oQKbZpKrV/JbFW/BFTKSmR6R9MUJwxi/h 5W8yfn4hLM9EsCcqtmJFfP0z0y0ynePOEc1+fARorRCz7RrL6tBDt9jYBqe0jQ== X-Google-Smtp-Source: AGHT+IGOnxIH4YjGEW5GtZaYNs+W/C6hB2R8AaG0BsyNWrPx0B0lajN6mf6PqMko8vPxUuZYiIe5uA== X-Received: by 2002:a17:903:3ba3:b0:223:3396:15e8 with SMTP id d9443c01a7336-2319810114emr33089565ad.22.1747202270073; Tue, 13 May 2025 22:57:50 -0700 (PDT) Received: from sunil-pc.Dlink ([106.51.196.253]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-22fc8271c2dsm91721615ad.135.2025.05.13.22.57.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 May 2025 22:57:49 -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, acpica-devel@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 , Atish Kumar Patra , Anup Patel , Andrew Jones , Sunil V L Subject: [PATCH 3/4] ACPI: scan: Add support for RISC-V in acpi_iommu_configure_id() Date: Wed, 14 May 2025 11:27:22 +0530 Message-ID: <20250514055723.1328557-4-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250514055723.1328557-1-sunilvl@ventanamicro.com> References: <20250514055723.1328557-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 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index fb1fe9f3b1a3..70f57d58fd61 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,12 @@ 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 viot_iommu_configure(dev); + 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 Feb 7 15:40:02 2026 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 89D581FE47C for ; Wed, 14 May 2025 05:57:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747202278; cv=none; b=kpIR1cu6NNYP9YZBAeGkOkcmnvhZUvDLC91WrpVeBVzVtle9vUUV9cQQQFV7PlfCpwcQ5abACZTU0qQ9TMtYb1y2eYOiWw4JUdsPDyF6bsfjokPrQ3NhVyTfd7Ky/jQA2UxZdgMH6KPBh01c8k3PftR/1FxBLHFi1Tn0BLAaA/Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747202278; c=relaxed/simple; bh=Tr1XOcL/8BhgssUXkqbsbVw45YsiIW9Uliv4Chah6tw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z8frBXBprK6mfJo7hUm/XPdGx2IhAdW8Aq/CT7D6TB3zksb25XHqyHi0B3YKa3j4HHs3uO0Uv2H2PZ2UkOprLE/QlC9IwHOaBo4VF7j+4dlFctgmnNqMpRS5+F5W8au6jDT7ZLe+L1NCMor4MDGj9n8IFdlxmDZ/YfI6FiuZhGI= 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=Y93/QNry; arc=none smtp.client-ip=209.85.214.177 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="Y93/QNry" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-22e331215dbso3759625ad.1 for ; Tue, 13 May 2025 22:57:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1747202275; x=1747807075; 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=FbiDocnvP7/vIiwuy9W9uCrvaQAnUMotSiyx0gsvykM=; b=Y93/QNryKzPjggxdmU6PaxS+hRZn0l4pqNnQmI5nZQaSeu+phPrdCcCbiq62rdxFpP 9MCj7k/pF8uiFMoztkefg/bn7SpASoS6vPZ9sK2FnGKyLsaqZXT9mKmDy8zcl7bEIDPc +hkBk3BSunjNy2xmQtOpEZSQLq2IO6Odj+ykWHuYDLDHnKzoh8NxZVIrw1kCTCYwOA0M TH7yUNOSmG2UC6P3hOOrAkAzVRDlrcrojC2c26THdFG3OPaAxkNUV0PaudyMT12XmSs2 lI0to+K7CtC7aa64EG5NaXAhtsYi2fIGDxWKeDu/9q7zpA/8AbayESFob8NoyqLWIhg2 9PwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747202275; x=1747807075; 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=FbiDocnvP7/vIiwuy9W9uCrvaQAnUMotSiyx0gsvykM=; b=RDvJC51xIdwXlvlaiGvyc4BzAcPXg14OHxvZ0uxEy0cmB6bK4Z2aTYymMnzY4dFTeo bK6IoK9GbIYug4CHGU9FN5Vd4bbEwS4Jw5N8gol+yEf6yZn1BRUfOz3mkcQAb8tYPPd9 Ze3howUfuCKewDsdSmLT3EF7ai7JeihjagoxETgwmmB6MAhp8ekOUt7BERrgYWElk1vZ F1UEyzp02qcWgG5KgOoGaheNp1QrNb6dtNFwvXT+RsdKXE254q78lkfeZabVo6HVmi/B 74vPTtDbMcxMbgOhERxKb9MjH/r7xe9vrqwrZWqkCH866503Io38mAQ4CvODEj46zZRb CAVQ== X-Gm-Message-State: AOJu0YzzFnaOOJ/8p7r2iET+v/QLKX3T7pg1Fa0fgHapuMup8tkzriec Bc0B+r62BB8NSugjJtxz61M4mASDc3BRaU4CSigkuCHU/tAvt5oWnSWirSWkWrW9Jc2W7qsll1Z MIjU= X-Gm-Gg: ASbGnctAR99bOZ8Wt78i7jO3PX3jnJQVMEwI1jmoWXapULuXXS63vHXRT4I46KsnIZt 2xV+r8W+OeufnyTu1QuUi8pGBXmyiADj+wezIW8Bazcy1hedEBHh9FniTrekRwEiFmiL/E3lAyL l/C0jJEq/7XlVfd5hr5wdwNoNFk7X2Aid8MhD0ZKajigrI3VFHX/Utu+vRB7QjZYgSN86Kuo5Gi MIa1E/xBXmu/FOZNKIJf33lUAClpWp/l5dc5+E2wcBDVBYdHpjsZUpO7wgJlJEXIPZPW28MwmJI IgKEukXkegDfBtxvd50GjOHUaIc/IAMnPU196T0bO0RP5JyKXEKpAEoMetoVNQ== X-Google-Smtp-Source: AGHT+IGgGwlhXhb97hz7G/rQ5hnEoBLy0AHEplWytso8kcAajszMRL1hQAHqjtumZAwOWQTJC9TsUw== X-Received: by 2002:a17:903:32d1:b0:223:807f:7f92 with SMTP id d9443c01a7336-2317cb4f087mr83654885ad.20.1747202275325; Tue, 13 May 2025 22:57:55 -0700 (PDT) Received: from sunil-pc.Dlink ([106.51.196.253]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-22fc8271c2dsm91721615ad.135.2025.05.13.22.57.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 May 2025 22:57:54 -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, acpica-devel@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 , Atish Kumar Patra , Anup Patel , Andrew Jones , Sunil V L Subject: [PATCH 4/4] iommu/riscv: Add ACPI support Date: Wed, 14 May 2025 11:27:23 +0530 Message-ID: <20250514055723.1328557-5-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250514055723.1328557-1-sunilvl@ventanamicro.com> References: <20250514055723.1328557-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 --- 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 8f049d4a0e2c..e51af4ba54a8 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