From nobody Mon Mar 23 19:50:52 2026 Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) (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 B6D553AEF53 for ; Mon, 23 Mar 2026 15:58:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774281503; cv=none; b=XxDaN/T9CyfCCrG2FkE2X3R916thecPN0zlcLJWgEjCsh7i7KHrjX/N+K2q2CYo9N1BTSp92+sL8oZM2skXR3ahkN4JsJvUg0RWmIc9uUG0MWigvm69gvZ0NgVMIfjt6paFgIJdly8Yindx8Qy9cVsY81YGOeaWYK/99S/lMLNc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774281503; c=relaxed/simple; bh=GThMTUYv0X2eUWVbc3FKLVom4NcwLXi5gsOn2QtDYgE=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=aBg9351WEX3LGFF2oIPUv4Ovonfl2Ec6aOZE+nlaam0vXU4UEd1pmN0AdRFzft+Ncl58Lhw/K4kMn53vi8IOWhfOgDrFGd3VeH5QJPxSRKQIzHFl3gFTJRKDa/0r/RKKOhW95wqJgEPk2/IL/mOt3ywyDDidkQXrQ2lnjCL3bss= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ldnyiJ5S; arc=none smtp.client-ip=209.85.215.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ldnyiJ5S" Received: by mail-pg1-f173.google.com with SMTP id 41be03b00d2f7-c70fb6aa323so107627a12.3 for ; Mon, 23 Mar 2026 08:58:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1774281501; x=1774886301; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=SyPHQzyI0AHwqMlFoboSet59W59Lm/9+xwH2RUG0miE=; b=ldnyiJ5Stu/vu042kfKIxHvHZ0LIO73V6BDGSpyvQ/0tglZc0WaRzBP5+wDrJ3CnBo aj8FTaZdMpGb8PUpkfzPZ7QjU712ZEp/yh8ETtQQ3RY7zM//Vhr8j7r99D9mqljlQSaa CEH1eCaIinFOH5f6w7kindf1ltN43ZZSSU6rzHH9+4+Xao1i7kWqPtzqvwEZoWBCtGOk Rmv+lYou7uTkXj7L0gpaGjGlRHS3NcrIoxvacnWtpmtSRvAZD2pxDILx20K/S49lCvqk ilP5SM4l9mj6NO3scprT9MM8MyblODpmE0mQzsCmVZcBcbjcrwekoUVR0Z6T/dcmQa8d p0Hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774281501; x=1774886301; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=SyPHQzyI0AHwqMlFoboSet59W59Lm/9+xwH2RUG0miE=; b=VGeq6I+sw3AgEJazMv1xOLw8BF8voYiflCt+nW7Lz2/HbL68FFusmdVWrfyL+NcQt6 hrK5cqqaJsEuVHwokZXvNlUgvsCI5HrAu1xO7XcKwn9CeHAncTILQa6SDNaUL3cLzqeU Tkgv78qo26zIOp1hwYRzrMwjdUrqfGIojt6gN2cSjDJ9K/CDwRchbZ1zEcx4HGi6Otcn 5mivnNwE54CKlMytoIpDqqFZZ6VSY4SZNiQYEoj7QBoPaSHjM6i130+d6P0Qb+2nXkh2 yLvPSu3zUYra8et0zznaS/lCwy5Jce8jPYbX1nTEAm5uGUX5BYjHLma44mYL9HKHZ417 BXIg== X-Forwarded-Encrypted: i=1; AJvYcCXlmeWM0jXpRuRTGvGHoC0T0k301LjqRCLJbbpBvjm47Sf33vNvOoyHxUs4cY5rRduAYt9jajNUPQcJdoE=@vger.kernel.org X-Gm-Message-State: AOJu0YxgLMyLCQMRRr0wf5908pCLXgRgd1kNLrmYeVia8OZQboUgdeMW CPh3ADzXVD77FIZz6QlC9RC0qf20E2PydkjMoWCcZeMNLeqK6QdsGi9MtJb9fg== X-Gm-Gg: ATEYQzwZbRw15+H5qfI2Fl2T0/vLIfSBx3m13lTbjy7gRC+w56PJAJhJGc0T2DRlU0K FmTZozsKfES0JM6SIOvX+hT3c3IkRgrWi/1CakiMU4xpb782UD88/LwrMjb0d634Z/ASimCnlil mj5h4/YW8szIxUE+MokS+DCOkGvSsOV+V2VcfbcUMvg7TOPQFXwxivYmJmu9jrZ1yb23bHDiwng Aqnce02eu7E5YyzXUMIwp9r9YzSIbC27HOMhUDXlB5XBCCGVKSu7u2T0P+JnQXXDwCyVtNmtRAb GQWpBfoj0sp1Usih4WMnmKD9E/eiCN9wyxDVuwWCcdjxMftQQbYP3Q7YX+gaIull0vq9/NBVk+Q lPLfSjuiHvZn/+moZUiPSz6OtICLJgzIkI6BBHZt1QOTRYOoFH8xGuaXlLjr5MaGwLCIQJZWY5B LBxyP1VYJ9eolJZGKYzJs0ThrwdRLly76V0RUBBs5p81YGSGkT6JiL22PSCngc8+5hbJtHqFQVa YmM002K9w== X-Received: by 2002:a05:6a20:a10c:b0:39b:9644:6ea4 with SMTP id adf61e73a8af0-39bce9f0e99mr11959607637.16.1774281500957; Mon, 23 Mar 2026 08:58:20 -0700 (PDT) Received: from sean-All-Series.. (1-160-195-162.dynamic-ip.hinet.net. [1.160.195.162]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c743a801701sm8487398a12.4.2026.03.23.08.58.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2026 08:58:20 -0700 (PDT) From: Sean Chang To: tjeznach@rivosinc.com, joro@8bytes.org Cc: will@kernel.org, iommu@lists.linux.dev, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Sean Chang Subject: [PATCH] iommu/riscv: Add DebugFS support for register dump Date: Mon, 23 Mar 2026 23:58:06 +0800 Message-Id: <20260323155806.97130-1-seanwascoding@gmail.com> X-Mailer: git-send-email 2.34.1 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" Add a DebugFS interface to allow users to dump the internal state of the RISC-V IOMMU hardware. This is essential for diagnosing hardware initialization issues and debugging driver-hardware communication such as Command or Fault queue stalls. The implementation exposes a "registers" file under the device's debugfs directory. It uses the standard debugfs_regset32 structure to dump core registers: * Global configuration: capabilities, fctl, ddtp * Command Queue: cqb, cqh, cqt, cqcsr * Fault Queue: fqb, fqh, fqt, fqcsr * Interrupts: ipsr, icvec Signed-off-by: Sean Chang --- drivers/iommu/riscv/Kconfig | 11 ++++++++ drivers/iommu/riscv/Makefile | 1 + drivers/iommu/riscv/debugfs.c | 53 +++++++++++++++++++++++++++++++++++ drivers/iommu/riscv/iommu.c | 3 ++ drivers/iommu/riscv/iommu.h | 12 ++++++++ 5 files changed, 80 insertions(+) create mode 100644 drivers/iommu/riscv/debugfs.c diff --git a/drivers/iommu/riscv/Kconfig b/drivers/iommu/riscv/Kconfig index b86e5ab94183..c2ba12d97e98 100644 --- a/drivers/iommu/riscv/Kconfig +++ b/drivers/iommu/riscv/Kconfig @@ -22,3 +22,14 @@ config RISCV_IOMMU_PCI def_bool y if RISCV_IOMMU && PCI_MSI help Support for the PCIe implementation of RISC-V IOMMU architecture. + +config RISCV_IOMMU_DEBUGFS + bool "RISC-V IOMMU Debugfs Support" + depends on RISCV_IOMMU + depends on IOMMU_DEBUGFS + help + Expose RISC-V IOMMU internals via debugfs. This includes + register dumps, queue status, and other hardware-specific + information useful for debugging. + + If unsure, say N. diff --git a/drivers/iommu/riscv/Makefile b/drivers/iommu/riscv/Makefile index b5929f9f23e6..9658a10d8b24 100644 --- a/drivers/iommu/riscv/Makefile +++ b/drivers/iommu/riscv/Makefile @@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only obj-y +=3D iommu.o iommu-platform.o obj-$(CONFIG_RISCV_IOMMU_PCI) +=3D iommu-pci.o +obj-$(CONFIG_RISCV_IOMMU_DEBUGFS) +=3D debugfs.o diff --git a/drivers/iommu/riscv/debugfs.c b/drivers/iommu/riscv/debugfs.c new file mode 100644 index 000000000000..52dc50a7fa20 --- /dev/null +++ b/drivers/iommu/riscv/debugfs.c @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include +#include +#include + +#include "iommu.h" + +static const struct debugfs_reg32 riscv_iommu_regs[] =3D { + /* --- Global Configuration --- */ + { .name =3D "capabilities", .offset =3D RISCV_IOMMU_REG_CAPABILITIE= S }, + { .name =3D "fctl", .offset =3D RISCV_IOMMU_REG_FCTL = }, + { .name =3D "ddtp", .offset =3D RISCV_IOMMU_REG_DDTP = }, + /* --- Command Queue --- */ + { .name =3D "cqb", .offset =3D RISCV_IOMMU_REG_CQB = }, + { .name =3D "cqh", .offset =3D RISCV_IOMMU_REG_CQH = }, + { .name =3D "cqt", .offset =3D RISCV_IOMMU_REG_CQT = }, + { .name =3D "cqcsr", .offset =3D RISCV_IOMMU_REG_CQCSR = }, + /* --- Fault Queue --- */ + { .name =3D "fqb", .offset =3D RISCV_IOMMU_REG_FQB = }, + { .name =3D "fqh", .offset =3D RISCV_IOMMU_REG_FQH = }, + { .name =3D "fqt", .offset =3D RISCV_IOMMU_REG_FQT = }, + { .name =3D "fqcsr", .offset =3D RISCV_IOMMU_REG_FQCSR = }, + /* --- Interrupts --- */ + { .name =3D "ipsr", .offset =3D RISCV_IOMMU_REG_IPSR = }, + { .name =3D "icvec", .offset =3D RISCV_IOMMU_REG_ICVEC = }, +}; + +void riscv_iommu_debugfs_init(struct riscv_iommu_device *iommu) +{ + struct debugfs_regset32 *regset; + + if (!iommu_debugfs_dir) + return; + + iommu->debugfs_dir =3D debugfs_create_dir(dev_name(iommu->dev), iommu_deb= ugfs_dir); + if (IS_ERR_OR_NULL(iommu->debugfs_dir)) + return; + + regset =3D devm_kzalloc(iommu->dev, sizeof(*regset), GFP_KERNEL); + if (!regset) + return; + + regset->regs =3D riscv_iommu_regs; + regset->nregs =3D ARRAY_SIZE(riscv_iommu_regs); + regset->base =3D iommu->reg; + + debugfs_create_regset32("registers", 0444, iommu->debugfs_dir, regset); +} + +void riscv_iommu_debugfs_remove(struct riscv_iommu_device *iommu) +{ + debugfs_remove_recursive(iommu->debugfs_dir); +} diff --git a/drivers/iommu/riscv/iommu.c b/drivers/iommu/riscv/iommu.c index 368f3cbd2d0a..a4fa0307b32a 100644 --- a/drivers/iommu/riscv/iommu.c +++ b/drivers/iommu/riscv/iommu.c @@ -1466,6 +1466,7 @@ void riscv_iommu_remove(struct riscv_iommu_device *io= mmu) riscv_iommu_iodir_set_mode(iommu, RISCV_IOMMU_DDTP_IOMMU_MODE_OFF); riscv_iommu_queue_disable(&iommu->cmdq); riscv_iommu_queue_disable(&iommu->fltq); + riscv_iommu_debugfs_remove(iommu); } =20 int riscv_iommu_init(struct riscv_iommu_device *iommu) @@ -1526,6 +1527,8 @@ int riscv_iommu_init(struct riscv_iommu_device *iommu) goto err_remove_sysfs; } =20 + riscv_iommu_debugfs_init(iommu); + return 0; =20 err_remove_sysfs: diff --git a/drivers/iommu/riscv/iommu.h b/drivers/iommu/riscv/iommu.h index 46df79dd5495..1084e4e77455 100644 --- a/drivers/iommu/riscv/iommu.h +++ b/drivers/iommu/riscv/iommu.h @@ -60,6 +60,10 @@ struct riscv_iommu_device { unsigned int ddt_mode; dma_addr_t ddt_phys; u64 *ddt_root; + +#ifdef CONFIG_RISCV_IOMMU_DEBUGFS + struct dentry *debugfs_dir; +#endif }; =20 int riscv_iommu_init(struct riscv_iommu_device *iommu); @@ -86,4 +90,12 @@ void riscv_iommu_disable(struct riscv_iommu_device *iomm= u); readx_poll_timeout(readl_relaxed, (iommu)->reg + (addr), val, cond, \ delay_us, timeout_us) =20 +#ifdef CONFIG_RISCV_IOMMU_DEBUGFS +void riscv_iommu_debugfs_init(struct riscv_iommu_device *iommu); +void riscv_iommu_debugfs_remove(struct riscv_iommu_device *iommu); +#else +static inline void riscv_iommu_debugfs_init(struct riscv_iommu_device *iom= mu) { } +static inline void riscv_iommu_debugfs_remove(struct riscv_iommu_device *i= ommu) { } +#endif + #endif --=20 2.34.1