From: Zong Li <zong.li@sifive.com>
To: tomasz.jeznach@linux.dev, joro@8bytes.org, will@kernel.org,
robin.murphy@arm.com, pjw@kernel.org, palmer@dabbelt.com,
aou@eecs.berkeley.edu, alex@ghiti.fr, mark.rutland@arm.com,
andrew.jones@oss.qualcomm.com, guoren@kernel.org,
david.laight.linux@gmail.com, zhangzhanpeng.jasper@bytedance.com,
yang.yicong@picoheart.com, iommu@lists.linux.dev,
linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
linux-perf-users@vger.kernel.org
Cc: Zong Li <zong.li@sifive.com>, Chen Pei <cp0613@linux.alibaba.com>,
Fangyu Yu <fangyu.yu@linux.alibaba.com>,
Samuel Holland <samuel.holland@sifive.com>
Subject: [PATCH RESEND v7 2/3] iommu/riscv: create a auxiliary device for HPM
Date: Fri, 28 Aug 2026 01:58:16 -0700 [thread overview]
Message-ID: <20260828085819.4076449-3-zong.li@sifive.com> (raw)
In-Reply-To: <20260828085819.4076449-1-zong.li@sifive.com>
Create an auxiliary device for HPM when the IOMMU supports a
hardware performance monitor.
Tested-by: Chen Pei <cp0613@linux.alibaba.com>
Tested-by: Fangyu Yu <fangyu.yu@linux.alibaba.com>
Reviewed-by: Guo Ren <guoren@kernel.org>
Reviewed-by: Yicong Yang <yang.yicong@picoheart.com>
Suggested-by: Samuel Holland <samuel.holland@sifive.com>
Signed-off-by: Zong Li <zong.li@sifive.com>
---
drivers/iommu/riscv/Kconfig | 1 +
drivers/iommu/riscv/iommu.c | 37 +++++++++++++++++++++++++++++++++++++
2 files changed, 38 insertions(+)
diff --git a/drivers/iommu/riscv/Kconfig b/drivers/iommu/riscv/Kconfig
index b86e5ab94183..8025bf0fb67f 100644
--- a/drivers/iommu/riscv/Kconfig
+++ b/drivers/iommu/riscv/Kconfig
@@ -10,6 +10,7 @@ config RISCV_IOMMU
select GENERIC_PT
select IOMMU_PT
select IOMMU_PT_RISCV64
+ select AUXILIARY_BUS
help
Support for implementations of the RISC-V IOMMU architecture that
complements the RISC-V MMU capabilities, providing similar address
diff --git a/drivers/iommu/riscv/iommu.c b/drivers/iommu/riscv/iommu.c
index cec3ddd7ab10..7f619971bb70 100644
--- a/drivers/iommu/riscv/iommu.c
+++ b/drivers/iommu/riscv/iommu.c
@@ -14,6 +14,7 @@
#include <linux/acpi.h>
#include <linux/acpi_rimt.h>
+#include <linux/auxiliary_bus.h>
#include <linux/compiler.h>
#include <linux/crash_dump.h>
#include <linux/init.h>
@@ -48,6 +49,9 @@
static DEFINE_IDA(riscv_iommu_pscids);
#define RISCV_IOMMU_MAX_PSCID (BIT(20) - 1)
+/* IOMMU PMU auxiliary device id allocation namespace. */
+static DEFINE_IDA(riscv_iommu_pmu_ida);
+
/* Device resource-managed allocations */
struct riscv_iommu_devres {
void *addr;
@@ -565,6 +569,36 @@ static irqreturn_t riscv_iommu_fltq_process(int irq, void *data)
return IRQ_HANDLED;
}
+/*
+ * IOMMU Hardware performance monitor
+ */
+static void riscv_iommu_pmu_id_free(void *data)
+{
+ ida_free(&riscv_iommu_pmu_ida, (unsigned long)data);
+}
+
+static int riscv_iommu_hpm_enable(struct riscv_iommu_device *iommu)
+{
+ struct auxiliary_device *auxdev;
+ int id, ret;
+
+ id = ida_alloc(&riscv_iommu_pmu_ida, GFP_KERNEL);
+ if (id < 0)
+ return id;
+
+ ret = devm_add_action_or_reset(iommu->dev, riscv_iommu_pmu_id_free,
+ (void *)(unsigned long)id);
+ if (ret)
+ return ret;
+
+ auxdev = __devm_auxiliary_device_create(iommu->dev, "riscv-iommu",
+ "pmu", iommu, id);
+ if (!auxdev)
+ return -ENODEV;
+
+ return 0;
+}
+
/* Lookup and initialize device context info structure. */
static struct riscv_iommu_dc *riscv_iommu_get_dc(struct riscv_iommu_device *iommu,
unsigned int devid)
@@ -1613,6 +1647,9 @@ int riscv_iommu_init(struct riscv_iommu_device *iommu)
goto err_remove_sysfs;
}
+ if (iommu->caps & RISCV_IOMMU_CAPABILITIES_HPM)
+ riscv_iommu_hpm_enable(iommu);
+
return 0;
err_remove_sysfs:
--
2.43.7
next prev parent reply other threads:[~2026-08-28 8:58 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-28 8:58 [PATCH RESEND v7 0/3] RISC-V IOMMU HPM support Zong Li
2026-08-28 8:58 ` [PATCH RESEND v7 1/3] drivers/perf: riscv-iommu: add risc-v iommu pmu driver Zong Li
2026-08-28 9:10 ` sashiko-bot
2026-08-28 8:58 ` Zong Li [this message]
2026-08-28 9:06 ` [PATCH RESEND v7 2/3] iommu/riscv: create a auxiliary device for HPM sashiko-bot
2026-08-28 8:58 ` [PATCH RESEND v7 3/3] drivers/perf: riscv-iommu: protect shared state with a raw spinlock Zong Li
2026-08-28 9:14 ` sashiko-bot
2026-09-02 8:07 ` Yicong Yang
2026-09-04 8:38 ` Zong Li
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260828085819.4076449-3-zong.li@sifive.com \
--to=zong.li@sifive.com \
--cc=alex@ghiti.fr \
--cc=andrew.jones@oss.qualcomm.com \
--cc=aou@eecs.berkeley.edu \
--cc=cp0613@linux.alibaba.com \
--cc=david.laight.linux@gmail.com \
--cc=fangyu.yu@linux.alibaba.com \
--cc=guoren@kernel.org \
--cc=iommu@lists.linux.dev \
--cc=joro@8bytes.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=mark.rutland@arm.com \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.org \
--cc=robin.murphy@arm.com \
--cc=samuel.holland@sifive.com \
--cc=tomasz.jeznach@linux.dev \
--cc=will@kernel.org \
--cc=yang.yicong@picoheart.com \
--cc=zhangzhanpeng.jasper@bytedance.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox