[PATCH v2 28/28] drm/panthor: Reset partitions before starting arbitration
From: Karunika Choo
Date: Tue Nov 10 2026 - 10:55:42 EST
A partition may still have an open access window when the arbiter
starts (typically from restarting the driver), while its software state
assumes no active window. Starting arbitration in this state can leave
software out of sync with the hardware.
Recover each partition to RESET before enabling its interrupts. Allow
open windows to yield, fall back to forced close if necessary, and bound
recovery attempts so failure aborts initialization.
Keep partition interrupts masked during recovery and clean up before
normal operation begins.
Signed-off-by: Karunika Choo <karunika.choo@xxxxxxx>
---
.../arbitration/panthor_partition_control.c | 54 +++++++++++++++++++
1 file changed, 54 insertions(+)
diff --git a/drivers/gpu/drm/panthor/arbitration/panthor_partition_control.c b/drivers/gpu/drm/panthor/arbitration/panthor_partition_control.c
index 3b472403f49d1..2c0f8dc0b3bfb 100644
--- a/drivers/gpu/drm/panthor/arbitration/panthor_partition_control.c
+++ b/drivers/gpu/drm/panthor/arbitration/panthor_partition_control.c
@@ -43,6 +43,7 @@
#define PART_REG_POLL_SLEEP_US 10
#define PART_STATE_TRANSITION_TIMEOUT_US 5000000
+#define PART_ENSURE_RESET_RETRY_COUNT 3
/** struct panthor_partition_cmd - Partition command data */
struct panthor_partition_cmd {
@@ -368,6 +369,54 @@ void panthor_partition_control_term(struct panthor_arbitration *adev)
}
}
+static int partition_ensure_reset(struct panthor_partition_control *pc)
+{
+ int ret = 0;
+ int count = 0;
+
+again:
+ if ((count >= PART_ENSURE_RESET_RETRY_COUNT) &&
+ (partition_state_get(pc) != PART_STATE_RESET))
+ return -ETIMEDOUT;
+
+ count++;
+
+ switch (partition_state_get(pc)) {
+ case PART_STATE_RESET:
+ /* clear any remnants of this operation */
+ gpu_write(pc->iomem, AM_PART_IRQ_CLEAR, PART_CONTROL_IRQ_MASK);
+ pc->closing = false;
+ pc->last_cmd.aw_id = AW_UNASSIGNED;
+ pc->last_cmd.cmd = 0;
+ return 0;
+ case PART_STATE_WINDOW_OPENING:
+ ret = partition_state_wait(pc, PART_STATE_WINDOW_OPEN);
+ fallthrough;
+ case PART_STATE_WINDOW_OPEN:
+ /*
+ * Window was left open likely due to arbiter restart. Send
+ * YIELD_NOW to current AW and wait for it to yield GPU access.
+ * On timeout, forcibly close the window.
+ */
+ if (!ret)
+ ret = yield_now(pc);
+ else
+ ret = window_close(pc);
+
+ /* state changed, reevaluate state */
+ if (ret == -EAGAIN) {
+ ret = 0;
+ goto again;
+ }
+ fallthrough;
+ case PART_STATE_WINDOW_CLOSED:
+ ret = partition_state_wait(pc, PART_STATE_RESET);
+ goto again;
+ }
+
+ return -EINVAL;
+}
+
static int partition_control_init(struct panthor_arbitration *adev, int i)
{
struct panthor_partition_control *pc;
@@ -407,6 +456,7 @@ static int partition_control_init(struct panthor_arbitration *adev, int i)
spin_lock_init(&pc->irq_lock);
pc->irq_suspended = true;
+ gpu_write(pc->iomem, AM_PART_IRQ_MASK, 0);
spin_lock_init(&pc->lock);
pc->current_aw = AW_UNASSIGNED;
@@ -429,6 +479,10 @@ static int partition_control_init(struct panthor_arbitration *adev, int i)
adev->pc[i] = pc;
+ ret = partition_ensure_reset(pc);
+ if (ret)
+ return ret;
+
partition_irq_resume(pc);
return 0;
--
2.43.0