[RFC PATCH 12/18] drm/panthor: Add AM_RESOURCE_GROUP support

From: Karunika Choo

Date: Thu May 28 2026 - 11:25:46 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>
---
drivers/gpu/drm/panthor/arbitration/Makefile | 3 +-
.../panthor/arbitration/panthor_arbitration.h | 5 +
.../arbitration/panthor_arbitration_drv.c | 17 ++
.../arbitration/panthor_resource_group.c | 288 ++++++++++++++++++
.../arbitration/panthor_resource_group.h | 20 ++
5 files changed, 332 insertions(+), 1 deletion(-)
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 5d5b2b8d84bc..0ea5b70d524a 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 5e35ae8463c4..38c8f8674a02 100644
--- a/drivers/gpu/drm/panthor/arbitration/panthor_arbitration.h
+++ b/drivers/gpu/drm/panthor/arbitration/panthor_arbitration.h
@@ -6,8 +6,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

/**
@@ -19,6 +21,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];
};

#endif
diff --git a/drivers/gpu/drm/panthor/arbitration/panthor_arbitration_drv.c b/drivers/gpu/drm/panthor/arbitration/panthor_arbitration_drv.c
index 07a566168e6a..ac395b89b483 100644
--- a/drivers/gpu/drm/panthor/arbitration/panthor_arbitration_drv.c
+++ b/drivers/gpu/drm/panthor/arbitration/panthor_arbitration_drv.c
@@ -10,6 +10,7 @@

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

#define PANTHOR_PM_AUTOSUSPEND_DELAY_MS 100

@@ -22,6 +23,10 @@ static int panthor_arbitration_runtime_suspend(struct device *dev)
if (ret)
return ret;

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

@@ -30,6 +35,10 @@ static int panthor_arbitration_runtime_resume(struct device *dev)
struct panthor_arbitration *adev = dev_get_drvdata(dev);
int ret = 0;

+ ret = panthor_resource_group_resume(adev);
+ if (ret)
+ return ret;
+
ret = panthor_partition_control_resume(adev);
if (ret)
return ret;
@@ -66,6 +75,10 @@ static int panthor_arbitration_probe(struct platform_device *pdev)
if (ret)
goto err_out;

+ ret = panthor_resource_group_init(adev);
+ if (ret)
+ goto err_term_partition;
+
pm_runtime_set_autosuspend_delay(dev, PANTHOR_PM_AUTOSUSPEND_DELAY_MS);
pm_runtime_use_autosuspend(dev);

@@ -73,6 +86,9 @@ static int panthor_arbitration_probe(struct platform_device *pdev)

return 0;

+err_term_partition:
+ panthor_partition_control_term(adev);
+
err_out:
pm_runtime_put_noidle(dev);
return ret;
@@ -90,6 +106,7 @@ static void panthor_arbitration_remove(struct platform_device *pdev)
if (ret < 0)
goto out_suspended;

+ 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 000000000000..cd1ad0532766
--- /dev/null
+++ b/drivers/gpu/drm/panthor/arbitration/panthor_resource_group.c
@@ -0,0 +1,288 @@
+// SPDX-License-Identifier: GPL-2.0 or MIT
+/* Copyright 2026 ARM Limited. All rights reserved. */
+
+#include <linux/iopoll.h>
+#include <linux/interrupt.h>
+#include <linux/platform_device.h>
+#include <linux/pm_runtime.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;
+
+ 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 unexpectedy empty", aw_id);
+ }
+
+ if (retry)
+ queue_work(rg->wq, &rg->msg_retry_work);
+}
+
+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 == -ENOMEM)
+ 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_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);
+
+ if (!acked) {
+ /* AW initiated the handshake, reply with supported version */
+ u64 reply = ARB_VM_INIT_MAKE(1, aw_data->msg.version);
+
+ rg_send_msg(rg, aw_id, reply);
+ }
+}
+
+static void rg_handshake_init(struct panthor_resource_group *rg)
+{
+ for (u8 aw_id = 0; aw_id < AM_ARB_MAX_AW_COUNT; aw_id++) {
+ u64 message = ARB_VM_INIT_MAKE(0, AM_MSG_CURRENT_VERSION);
+
+ rg_send_msg(rg, aw_id, message);
+ }
+}
+
+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_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;
+
+ disable_work_sync(&rg->msg_retry_work);
+ rg_irq_suspend(rg);
+ }
+}
+
+static int resource_group_init(struct panthor_arbitration *adev, int i)
+{
+ struct device *dev = adev->dev;
+ struct platform_device *pdev = to_platform_device(dev);
+ struct panthor_resource_group *rg;
+ struct resource *res;
+ void __iomem *iomem;
+ char *name;
+ int ret = 0;
+ int irq;
+
+ name = devm_kasprintf(dev, GFP_KERNEL, "rg%d", i);
+
+ res = platform_get_resource_byname(pdev, IORESOURCE_MEM, name);
+ if (!res) {
+ devm_kfree(dev, name);
+ return -ENODEV;
+ }
+
+ iomem = devm_ioremap_resource(dev, res);
+ if (IS_ERR(iomem)) {
+ dev_err(dev, "%s: Failed to ioremap", name);
+ return PTR_ERR(iomem);
+ }
+
+ rg = devm_kzalloc(dev, sizeof(*rg), GFP_KERNEL);
+ if (!rg)
+ return -ENOMEM;
+
+ 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));
+
+ adev->rg[i] = rg;
+
+ irq = platform_get_irq_byname(pdev, name);
+ if (irq < 0)
+ return irq;
+
+ ret = devm_request_irq(
+ dev, irq, rg_irq_raw_handler, IRQF_SHARED,
+ devm_kasprintf(dev, GFP_KERNEL, "panthor-%s-irq", name), rg);
+ if (ret)
+ return ret;
+
+ rg_irq_resume(rg);
+
+ rg_handshake_init(rg);
+
+ return 0;
+}
+
+int panthor_resource_group_init(struct panthor_arbitration *adev)
+{
+ for (int i = 0; i < AM_ARB_MAX_RG_COUNT; i++) {
+ int ret = resource_group_init(adev, i);
+ 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 000000000000..b8633abdd8eb
--- /dev/null
+++ b/drivers/gpu/drm/panthor/arbitration/panthor_resource_group.h
@@ -0,0 +1,20 @@
+/* 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);
+
+#endif
--
2.43.0