[PATCH v1 15/27] drm/panthor: Add AM_RESOURCE_GROUP support

From: Karunika Choo

Date: Tue Sep 22 2026 - 16:58:00 EST


Add resource-group probing for the arbitration device, including MMIO
resources, IRQ handling, per-AW AM message helpers, handshake
negotiation, and retry work for deferred outgoing messages.

Hook resource groups into arbitration init, teardown, and runtime PM.

Signed-off-by: Karunika Choo <karunika.choo@xxxxxxx>
---
v1:
- Updated DT structure and accompanying parsing to handle child nodes
instead of named platform resources.
- Hold runtime PM reference during message retries.
- Fix suspend resume ordering.

drivers/gpu/drm/panthor/arbitration/Makefile | 3 +-
.../panthor/arbitration/panthor_arbitration.h | 5 +
.../arbitration/panthor_arbitration_drv.c | 19 +-
.../arbitration/panthor_resource_group.c | 323 ++++++++++++++++++
.../arbitration/panthor_resource_group.h | 22 ++
5 files changed, 370 insertions(+), 2 deletions(-)
create mode 100644 drivers/gpu/drm/panthor/arbitration/panthor_resource_group.c
create mode 100644 drivers/gpu/drm/panthor/arbitration/panthor_resource_group.h

diff --git a/drivers/gpu/drm/panthor/arbitration/Makefile b/drivers/gpu/drm/panthor/arbitration/Makefile
index b0b6b2e3edf8d..2d2684321d978 100644
--- a/drivers/gpu/drm/panthor/arbitration/Makefile
+++ b/drivers/gpu/drm/panthor/arbitration/Makefile
@@ -4,7 +4,8 @@
obj-$(CONFIG_DRM_PANTHOR_ARBITRATION) += panthor_arbitration.o
panthor_arbitration-y := \
panthor_arbitration_drv.o \
- panthor_partition_control.o
+ panthor_partition_control.o \
+ panthor_resource_group.o

INCLUDES = \
-I$(src)/..
diff --git a/drivers/gpu/drm/panthor/arbitration/panthor_arbitration.h b/drivers/gpu/drm/panthor/arbitration/panthor_arbitration.h
index 26950e47852dd..dfeab1b078d06 100644
--- a/drivers/gpu/drm/panthor/arbitration/panthor_arbitration.h
+++ b/drivers/gpu/drm/panthor/arbitration/panthor_arbitration.h
@@ -9,8 +9,10 @@

struct device;
struct panthor_partition_control;
+struct panthor_resource_group;

#define AM_ARB_MAX_PC_COUNT 1
+#define AM_ARB_MAX_RG_COUNT 1
#define AM_ARB_MAX_AW_COUNT 16

/** struct panthor_arbitration_resource - Arbitration resource */
@@ -31,6 +33,9 @@ struct panthor_arbitration {

/** @pc: Pointer array to partition control data */
struct panthor_partition_control *pc[AM_ARB_MAX_PC_COUNT];
+
+ /** @rg: Pointer array to resource group data */
+ struct panthor_resource_group *rg[AM_ARB_MAX_RG_COUNT];
};

int panthor_arbitration_parse_resource(struct device *dev,
diff --git a/drivers/gpu/drm/panthor/arbitration/panthor_arbitration_drv.c b/drivers/gpu/drm/panthor/arbitration/panthor_arbitration_drv.c
index 09342245a47d1..a1068a2c78f1a 100644
--- a/drivers/gpu/drm/panthor/arbitration/panthor_arbitration_drv.c
+++ b/drivers/gpu/drm/panthor/arbitration/panthor_arbitration_drv.c
@@ -12,6 +12,7 @@

#include "panthor_arbitration.h"
#include "panthor_partition_control.h"
+#include "panthor_resource_group.h"

#define PANTHOR_PM_AUTOSUSPEND_DELAY_MS 100

@@ -55,6 +56,10 @@ static int panthor_arbitration_runtime_suspend(struct device *dev)
struct panthor_arbitration *adev = dev_get_drvdata(dev);
int ret = 0;

+ ret = panthor_resource_group_suspend(adev);
+ if (ret)
+ return ret;
+
ret = panthor_partition_control_suspend(adev);
if (ret)
return ret;
@@ -71,6 +76,10 @@ static int panthor_arbitration_runtime_resume(struct device *dev)
if (ret)
return ret;

+ ret = panthor_resource_group_resume(adev);
+ if (ret)
+ return ret;
+
return 0;
}

@@ -103,6 +112,10 @@ static int panthor_arbitration_probe(struct platform_device *pdev)
if (ret)
goto err_term_pc;

+ ret = panthor_resource_group_init(adev);
+ if (ret)
+ goto err_term_rg;
+
ret = of_platform_populate(dev->of_node, NULL, NULL, dev);
if (ret)
goto err_depopulate;
@@ -116,7 +129,9 @@ static int panthor_arbitration_probe(struct platform_device *pdev)

err_depopulate:
of_platform_depopulate(dev);
-
+err_term_rg:
+ panthor_resource_group_cancel_work(adev);
+ panthor_resource_group_term(adev);
err_term_pc:
panthor_partition_control_term(adev);
pm_runtime_put_noidle(dev);
@@ -136,8 +151,10 @@ static void panthor_arbitration_remove(struct platform_device *pdev)
dev_warn(adev->dev, "failed to resume during remove: %d", ret);

of_platform_depopulate(adev->dev);
+ panthor_resource_group_cancel_work(adev);

if (ret >= 0) {
+ panthor_resource_group_term(adev);
panthor_partition_control_term(adev);
pm_runtime_put_noidle(adev->dev);
}
diff --git a/drivers/gpu/drm/panthor/arbitration/panthor_resource_group.c b/drivers/gpu/drm/panthor/arbitration/panthor_resource_group.c
new file mode 100644
index 0000000000000..9bdd0876dd457
--- /dev/null
+++ b/drivers/gpu/drm/panthor/arbitration/panthor_resource_group.c
@@ -0,0 +1,323 @@
+// SPDX-License-Identifier: GPL-2.0 or MIT
+/* Copyright 2026 ARM Limited. All rights reserved. */
+
+#include <linux/interrupt.h>
+#include <linux/iopoll.h>
+#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
+#include <linux/property.h>
+#include <linux/workqueue.h>
+
+#include "panthor_am_msg.h"
+#include "panthor_arbitration.h"
+#include "panthor_device_io.h"
+#include "panthor_resource_group.h"
+
+#define AM_RG_IRQ_RAWSTAT 0x80
+#define AM_RG_IRQ_CLEAR 0x84
+#define AM_RG_IRQ_MASK 0x88
+#define AM_RG_IRQ_STATUS 0x8C
+#define AM_RG_MESSAGE_MASK GENMASK(15, 0)
+
+#define AM_RG_AW_MESSAGE(n) (0x100 + (n) * 0x20)
+
+struct rg_aw_data {
+ /** @msg: Messaging data */
+ struct panthor_am_msg msg;
+};
+
+struct panthor_resource_group {
+ /** @dev: Device pointer */
+ struct device *dev;
+
+ /** @name: Resource name */
+ char *name;
+
+ /** @iomem: CPU mapping of the partition control IOMEM region */
+ void __iomem *iomem;
+
+ /** @irq: IRQ number */
+ int irq;
+
+ /** @aw_data: Data for each access window */
+ struct rg_aw_data aw_data[AM_ARB_MAX_AW_COUNT];
+
+ /** @wq: Resource group workqueue */
+ struct workqueue_struct *wq;
+
+ /** @msg_retry_work: Work to retry sending pending messages */
+ struct work_struct msg_retry_work;
+};
+
+static void rg_retry_messages(struct work_struct *work)
+{
+ struct panthor_resource_group *rg = container_of(
+ work, struct panthor_resource_group, msg_retry_work);
+ bool retry = false;
+ int ret;
+
+ ret = pm_runtime_resume_and_get(rg->dev);
+ if (ret) {
+ dev_warn(rg->dev, "Failed to resume to retry messages");
+ return;
+ }
+
+ for (u8 aw_id = 0; aw_id < AM_ARB_MAX_AW_COUNT; aw_id++) {
+ struct panthor_am_msg *msg = &rg->aw_data[aw_id].msg;
+ int ret;
+
+ ret = panthor_am_msg_retry(msg);
+ if (ret == -EBUSY || ret == -EAGAIN)
+ retry = true;
+
+ if (ret == -EINVAL)
+ dev_warn(rg->dev, "AW%u send FIFO unexpectedly empty", aw_id);
+ }
+
+ if (retry)
+ queue_work(rg->wq, &rg->msg_retry_work);
+
+ pm_runtime_put_autosuspend(rg->dev);
+}
+
+static void rg_send_msg(struct panthor_resource_group *rg, u8 aw_id,
+ u64 message)
+{
+ int ret;
+
+ ret = panthor_am_msg_send(&rg->aw_data[aw_id].msg, message);
+ if (ret == -ENOSPC)
+ dev_err(rg->dev, "AW%u send FIFO is full", aw_id);
+
+ if (ret == -EBUSY) {
+ dev_dbg(rg->dev, "AW%u has pending messages, scheduling retry work", aw_id);
+ queue_work(rg->wq, &rg->msg_retry_work);
+ }
+}
+
+static void rg_send_init_msg(struct panthor_resource_group *rg, u8 aw_id,
+ u8 ack, u8 version)
+{
+ u64 message = ARB_VM_INIT_MAKE(ack, version);
+
+ rg_send_msg(rg, aw_id, message);
+}
+
+static void rg_respond_to_handshake(struct panthor_resource_group *rg,
+ u8 aw_id, u64 message)
+{
+ struct rg_aw_data *aw_data = &rg->aw_data[aw_id];
+ bool acked = AM_MSG_ACK_GET(message);
+ u8 version = AM_MSG_VERSION_GET(message);
+ int ret;
+
+ ret = panthor_am_msg_version_validate(&aw_data->msg, version);
+ if (ret == -EOPNOTSUPP)
+ dev_warn(rg->dev,
+ "AW%u protocol version less than minimum supported (%u < %u)",
+ aw_id, version, AM_MSG_MIN_SUPPORTED_VERSION);
+
+ /* AW initiated the handshake, reply with supported version */
+ if (!acked)
+ rg_send_init_msg(rg, aw_id, 1, aw_data->msg.version);
+}
+
+static void rg_handshake_init(struct panthor_resource_group *rg)
+{
+ for (u8 aw_id = 0; aw_id < AM_ARB_MAX_AW_COUNT; aw_id++)
+ rg_send_init_msg(rg, aw_id, 0, AM_MSG_CURRENT_VERSION);
+}
+
+static void rg_handle_message(struct panthor_resource_group *rg, u8 aw_id,
+ u64 message)
+{
+ u8 msg_id = AM_MSG_ID_GET(message);
+ if (!msg_id)
+ return;
+
+ switch (msg_id) {
+ case VM_ARB_INIT:
+ rg_respond_to_handshake(rg, aw_id, message);
+ break;
+ case VM_ARB_GPU_REQUEST:
+ /* TODO: on_request */
+ break;
+ case VM_ARB_GPU_STOPPED:
+ /* TODO: on_idle */
+ break;
+ default:
+ dev_warn(rg->dev, "Invalid message (0x%llx)", message);
+ break;
+ }
+}
+
+static irqreturn_t rg_irq_raw_handler(int irq, void *data)
+{
+ struct panthor_resource_group *rg = data;
+ unsigned long message_mask;
+ u32 status;
+ u8 aw_id;
+
+ status = gpu_read(rg->iomem, AM_RG_IRQ_STATUS);
+ if (!status)
+ return IRQ_NONE;
+
+ message_mask = status;
+ for_each_set_bit(aw_id, &message_mask, AM_ARB_MAX_AW_COUNT) {
+ u64 message = panthor_am_msg_read(&rg->aw_data[aw_id].msg);
+
+ rg_handle_message(rg, aw_id, message);
+ }
+
+ gpu_write(rg->iomem, AM_RG_IRQ_CLEAR, status);
+
+ return IRQ_HANDLED;
+}
+
+static void rg_irq_suspend(struct panthor_resource_group *rg)
+{
+ gpu_write(rg->iomem, AM_RG_IRQ_MASK, 0);
+}
+
+static void rg_irq_resume(struct panthor_resource_group *rg)
+{
+ gpu_write(rg->iomem, AM_RG_IRQ_MASK, AM_RG_MESSAGE_MASK);
+}
+
+int panthor_resource_group_suspend(struct panthor_arbitration *adev)
+{
+ for (int i = 0; i < AM_ARB_MAX_RG_COUNT; i++) {
+ struct panthor_resource_group *rg = adev->rg[i];
+
+ if (!rg)
+ continue;
+
+ rg_irq_suspend(rg);
+ }
+
+ return 0;
+}
+
+int panthor_resource_group_resume(struct panthor_arbitration *adev)
+{
+ for (int i = 0; i < AM_ARB_MAX_RG_COUNT; i++) {
+ struct panthor_resource_group *rg = adev->rg[i];
+
+ if (!rg)
+ continue;
+
+ rg_irq_resume(rg);
+ }
+
+ return 0;
+}
+
+void panthor_resource_group_cancel_work(struct panthor_arbitration *adev)
+{
+ for (int i = 0; i < AM_ARB_MAX_RG_COUNT; i++) {
+ struct panthor_resource_group *rg = adev->rg[i];
+
+ if (!rg)
+ continue;
+
+ disable_work_sync(&rg->msg_retry_work);
+ }
+}
+
+void panthor_resource_group_term(struct panthor_arbitration *adev)
+{
+ for (int i = 0; i < AM_ARB_MAX_RG_COUNT; i++) {
+ struct panthor_resource_group *rg = adev->rg[i];
+
+ if (!rg)
+ continue;
+
+ rg_irq_suspend(rg);
+ }
+}
+
+static int resource_group_init(struct panthor_arbitration *adev,
+ const struct fwnode_handle *child)
+{
+ struct panthor_arbitration_resource res;
+ struct panthor_resource_group *rg;
+ struct device *dev = adev->dev;
+ struct irq_data *irqdata;
+ void __iomem *iomem;
+ u32 irq_flags = 0;
+ char *name;
+ int irq;
+ int ret;
+
+ ret = panthor_arbitration_parse_resource(dev, child, &res);
+ if (ret)
+ return ret;
+
+ if (res.id >= AM_ARB_MAX_RG_COUNT)
+ return -ENODEV;
+
+ if (adev->rg[res.id])
+ return dev_warn_probe(dev, -ENODEV, "resource-group@%llx: id (%u) already present",
+ res.res.start, res.id);
+
+ rg = devm_kzalloc(dev, sizeof(*rg), GFP_KERNEL);
+ if (!rg)
+ return -ENOMEM;
+
+ name = devm_kasprintf(dev, GFP_KERNEL, "rg%d", res.id);
+
+ iomem = devm_ioremap_resource(dev, &res.res);
+ if (IS_ERR(iomem))
+ return dev_err_probe(dev, PTR_ERR(iomem), "%s: Failed to ioremap", name);
+
+ rg->name = name;
+ rg->dev = dev;
+ rg->iomem = iomem;
+
+ rg->wq = devm_alloc_ordered_workqueue(dev, "panthor-%s-wq", 0, name);
+ if (!rg->wq)
+ return -ENOMEM;
+
+ INIT_WORK(&rg->msg_retry_work, rg_retry_messages);
+
+ for (int i = 0; i < AM_ARB_MAX_AW_COUNT; i++)
+ panthor_am_msg_init(&rg->aw_data[i].msg,
+ rg->iomem + AM_RG_AW_MESSAGE(i));
+
+ irq = fwnode_irq_get(child, 0);
+ if (irq < 0)
+ return dev_err_probe(dev, irq, "%s: Failed to get IRQ", name);
+
+ irqdata = irq_get_irq_data(irq);
+ if (irqdata)
+ irq_flags = irqd_get_trigger_type(irqdata);
+
+ ret = devm_request_irq(
+ dev, irq, rg_irq_raw_handler, irq_flags | IRQF_SHARED,
+ devm_kasprintf(dev, GFP_KERNEL, "panthor-%s-irq", name), rg);
+ if (ret)
+ return ret;
+
+ adev->rg[res.id] = rg;
+
+ rg_irq_resume(rg);
+
+ rg_handshake_init(rg);
+
+ return 0;
+}
+
+int panthor_resource_group_init(struct panthor_arbitration *adev)
+{
+ device_for_each_named_child_node_scoped(adev->dev, child, "resource-group") {
+ int ret = resource_group_init(adev, child);
+
+ if (ret == -ENODEV)
+ continue;
+
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
diff --git a/drivers/gpu/drm/panthor/arbitration/panthor_resource_group.h b/drivers/gpu/drm/panthor/arbitration/panthor_resource_group.h
new file mode 100644
index 0000000000000..ad85cd171c4a3
--- /dev/null
+++ b/drivers/gpu/drm/panthor/arbitration/panthor_resource_group.h
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0 or MIT */
+/* Copyright 2026 ARM Limited. All rights reserved. */
+
+#ifndef __PANTHOR_RESOURCE_GROUP_H__
+#define __PANTHOR_RESOURCE_GROUP_H__
+
+#include <linux/types.h>
+
+struct device;
+struct panthor_arbitration;
+
+int panthor_resource_group_init(struct panthor_arbitration *adev);
+
+void panthor_resource_group_term(struct panthor_arbitration *adev);
+
+int panthor_resource_group_suspend(struct panthor_arbitration *adev);
+
+int panthor_resource_group_resume(struct panthor_arbitration *adev);
+
+void panthor_resource_group_cancel_work(struct panthor_arbitration *adev);
+
+#endif
--
2.43.0