* [PATCH v5 01/13] drm/panthor: De-duplicate FW memory section sync
2026-11-16 11:25 [PATCH v5 00/13] drm/panthor: Protected mode support for Mali CSF GPUs Ketil Johnsen
@ 2026-11-16 11:25 ` Ketil Johnsen
2026-11-16 11:25 ` [PATCH v5 02/13] drm/panthor: Minor scheduler refactoring Ketil Johnsen
` (11 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Ketil Johnsen @ 2026-11-16 11:25 UTC (permalink / raw)
To: Boris Brezillon, Steven Price, Liviu Dudau, Akash Goel,
Karunika Choo, Lukas Zapolskas, Chris Diamand, Maarten Lankhorst,
Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter,
Daniel Almeida, Alice Ryhl
Cc: dri-devel, linux-kernel, rust-for-linux, Ketil Johnsen
Handle the sync to device of FW memory sections inside
panthor_fw_init_section_mem() so that the callers do not have to.
This small improvement is also critical for protected FW sections,
so we avoid issuing memory transactions to protected memory from
CPU running in normal mode.
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Liviu Dudau <liviu.dudau@arm.com>
Reviewed-by: Steven Price <steven.price@arm.com>
Signed-off-by: Ketil Johnsen <ketil.johnsen@arm.com>
---
drivers/gpu/drm/panthor/panthor_fw.c | 23 +++++++----------------
1 file changed, 7 insertions(+), 16 deletions(-)
diff --git a/drivers/gpu/drm/panthor/panthor_fw.c b/drivers/gpu/drm/panthor/panthor_fw.c
index 4f1fab66a13bf..5f9f7a92c56a8 100644
--- a/drivers/gpu/drm/panthor/panthor_fw.c
+++ b/drivers/gpu/drm/panthor/panthor_fw.c
@@ -449,6 +449,7 @@ static void panthor_fw_init_section_mem(struct panthor_device *ptdev,
struct panthor_fw_section *section)
{
bool was_mapped = !!section->mem->kmap;
+ struct sg_table *sgt;
int ret;
if (!section->data.size &&
@@ -467,6 +468,12 @@ static void panthor_fw_init_section_mem(struct panthor_device *ptdev,
if (!was_mapped)
panthor_kernel_bo_vunmap(section->mem);
+
+ /* An sgt should have been requested when the kernel BO was GPU-mapped. */
+ sgt = to_panthor_bo(section->mem->obj)->dmap.sgt;
+ if (!drm_WARN_ON_ONCE(&ptdev->base, !sgt))
+ dma_sync_sgtable_for_device(ptdev->base.dev, sgt,
+ DMA_TO_DEVICE);
}
/**
@@ -639,7 +646,6 @@ static int panthor_fw_load_section_entry(struct panthor_device *ptdev,
if (section_size) {
u32 cache_mode = hdr.flags & CSF_FW_BINARY_IFACE_ENTRY_CACHE_MODE_MASK;
- struct panthor_gem_object *bo;
u32 vm_map_flags = 0;
u64 va = hdr.va.start;
@@ -676,14 +682,6 @@ static int panthor_fw_load_section_entry(struct panthor_device *ptdev,
}
panthor_fw_init_section_mem(ptdev, section);
-
- bo = to_panthor_bo(section->mem->obj);
-
- /* An sgt should have been requested when the kernel BO was GPU-mapped. */
- if (drm_WARN_ON_ONCE(&ptdev->base, !bo->dmap.sgt))
- return -EINVAL;
-
- dma_sync_sgtable_for_device(ptdev->base.dev, bo->dmap.sgt, DMA_TO_DEVICE);
}
if (hdr.va.start == CSF_MCU_SHARED_REGION_START)
@@ -738,17 +736,10 @@ panthor_reload_fw_sections(struct panthor_device *ptdev, bool full_reload)
struct panthor_fw_section *section;
list_for_each_entry(section, &ptdev->fw->sections, node) {
- struct sg_table *sgt;
-
if (!full_reload && !(section->flags & CSF_FW_BINARY_IFACE_ENTRY_WR))
continue;
panthor_fw_init_section_mem(ptdev, section);
-
- /* An sgt should have been requested when the kernel BO was GPU-mapped. */
- sgt = to_panthor_bo(section->mem->obj)->dmap.sgt;
- if (!drm_WARN_ON_ONCE(&ptdev->base, !sgt))
- dma_sync_sgtable_for_device(ptdev->base.dev, sgt, DMA_TO_DEVICE);
}
}
--
2.43.0
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH v5 02/13] drm/panthor: Minor scheduler refactoring
2026-11-16 11:25 [PATCH v5 00/13] drm/panthor: Protected mode support for Mali CSF GPUs Ketil Johnsen
2026-11-16 11:25 ` [PATCH v5 01/13] drm/panthor: De-duplicate FW memory section sync Ketil Johnsen
@ 2026-11-16 11:25 ` Ketil Johnsen
2026-11-16 11:25 ` [PATCH v5 03/13] drm/panthor: Pass drm_file instead of panthor_file Ketil Johnsen
` (10 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Ketil Johnsen @ 2026-11-16 11:25 UTC (permalink / raw)
To: Boris Brezillon, Steven Price, Liviu Dudau, Akash Goel,
Karunika Choo, Lukas Zapolskas, Chris Diamand, Maarten Lankhorst,
Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter,
Daniel Almeida, Alice Ryhl
Cc: dri-devel, linux-kernel, rust-for-linux, Florent Tomasin, Ketil Johnsen
From: Florent Tomasin <florent.tomasin@arm.com>
Refactor parts of the group scheduling logic into new helper functions.
This will simplify addition of the protected mode feature.
Remove redundant assignments of csg_slot.
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Signed-off-by: Florent Tomasin <florent.tomasin@arm.com>
Co-developed-by: Ketil Johnsen <ketil.johnsen@arm.com>
Signed-off-by: Ketil Johnsen <ketil.johnsen@arm.com>
---
v5:
- Actually handle error from csg_slot_prog_locked()
v4:
- Handle error from csg_slot_prog_locked()
v3:
- Use panthor_fw_csg_endpoint_req_update() (was rebase mistake)
- Function rename to tick_ctx_update_group_prio()
v2:
- Moved option to ding only the CSG doorbell to later patch
---
drivers/gpu/drm/panthor/panthor_sched.c | 135 +++++++++++++++---------
1 file changed, 83 insertions(+), 52 deletions(-)
diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c
index a343c5180e01e..d632fe1bf4db8 100644
--- a/drivers/gpu/drm/panthor/panthor_sched.c
+++ b/drivers/gpu/drm/panthor/panthor_sched.c
@@ -2345,12 +2345,85 @@ tick_ctx_cleanup(struct panthor_scheduler *sched,
}
}
+static void
+tick_ctx_evict_group(struct panthor_scheduler *sched,
+ struct panthor_csg_slots_upd_ctx *upd_ctx,
+ struct panthor_group *group)
+{
+ struct panthor_device *ptdev = sched->ptdev;
+
+ if (drm_WARN_ON(&ptdev->base, group->csg_id < 0))
+ return;
+
+ csgs_upd_ctx_queue_reqs(ptdev, upd_ctx, group->csg_id,
+ group_can_run(group) ?
+ CSG_STATE_SUSPEND : CSG_STATE_TERMINATE,
+ CSG_STATE_MASK);
+}
+
+static void
+tick_ctx_update_group_prio(struct panthor_scheduler *sched,
+ struct panthor_csg_slots_upd_ctx *upd_ctx,
+ struct panthor_group *group,
+ int new_csg_prio)
+{
+ struct panthor_device *ptdev = sched->ptdev;
+ struct panthor_fw_csg_iface *csg_iface;
+ struct panthor_csg_slot *csg_slot;
+
+ if (group->csg_id < 0)
+ return;
+
+ csg_iface = panthor_fw_get_csg_iface(ptdev, group->csg_id);
+ csg_slot = &sched->csg_slots[group->csg_id];
+
+ if (csg_slot->priority != new_csg_prio) {
+ panthor_fw_csg_endpoint_req_update(ptdev, csg_iface,
+ CSG_EP_REQ_PRIORITY(new_csg_prio),
+ CSG_EP_REQ_PRIORITY_MASK);
+ csgs_upd_ctx_queue_reqs(ptdev, upd_ctx, group->csg_id,
+ csg_iface->output->ack ^ CSG_ENDPOINT_CONFIG,
+ CSG_ENDPOINT_CONFIG);
+ }
+}
+
+static int
+tick_ctx_schedule_group(struct panthor_scheduler *sched,
+ struct panthor_csg_slots_upd_ctx *upd_ctx,
+ struct panthor_group *group,
+ int csg_id, int csg_prio)
+{
+ struct panthor_device *ptdev = sched->ptdev;
+ struct panthor_fw_csg_iface *csg_iface =
+ panthor_fw_get_csg_iface(ptdev, csg_id);
+ int ret;
+
+ ret = group_bind_locked(group, csg_id);
+ if (ret)
+ return ret;
+
+ ret = csg_slot_prog_locked(ptdev, csg_id, csg_prio);
+ if (ret) {
+ group_unbind_locked(group);
+ return ret;
+ }
+
+ csgs_upd_ctx_queue_reqs(ptdev, upd_ctx, csg_id,
+ group->state == PANTHOR_CS_GROUP_SUSPENDED ?
+ CSG_STATE_RESUME : CSG_STATE_START,
+ CSG_STATE_MASK);
+ csgs_upd_ctx_queue_reqs(ptdev, upd_ctx, csg_id,
+ csg_iface->output->ack ^ CSG_ENDPOINT_CONFIG,
+ CSG_ENDPOINT_CONFIG);
+
+ return 0;
+}
+
static void
tick_ctx_apply(struct panthor_scheduler *sched, struct panthor_sched_tick_ctx *ctx)
{
struct panthor_group *group, *tmp;
struct panthor_device *ptdev = sched->ptdev;
- struct panthor_csg_slot *csg_slot;
int prio, new_csg_prio = MAX_CSG_PRIO, i;
u32 free_csg_slots = 0;
struct panthor_csg_slots_upd_ctx upd_ctx;
@@ -2360,44 +2433,13 @@ tick_ctx_apply(struct panthor_scheduler *sched, struct panthor_sched_tick_ctx *c
for (prio = PANTHOR_CSG_PRIORITY_COUNT - 1; prio >= 0; prio--) {
/* Suspend or terminate evicted groups. */
- list_for_each_entry(group, &ctx->old_groups[prio], run_node) {
- bool term = !group_can_run(group);
- int csg_id = group->csg_id;
-
- if (drm_WARN_ON(&ptdev->base, csg_id < 0))
- continue;
-
- csg_slot = &sched->csg_slots[csg_id];
- csgs_upd_ctx_queue_reqs(ptdev, &upd_ctx, csg_id,
- term ? CSG_STATE_TERMINATE : CSG_STATE_SUSPEND,
- CSG_STATE_MASK);
- }
+ list_for_each_entry(group, &ctx->old_groups[prio], run_node)
+ tick_ctx_evict_group(sched, &upd_ctx, group);
/* Update priorities on already running groups. */
- list_for_each_entry(group, &ctx->groups[prio], run_node) {
- struct panthor_fw_csg_iface *csg_iface;
- int csg_id = group->csg_id;
-
- if (csg_id < 0) {
- new_csg_prio--;
- continue;
- }
-
- csg_slot = &sched->csg_slots[csg_id];
- csg_iface = panthor_fw_get_csg_iface(ptdev, csg_id);
- if (csg_slot->priority == new_csg_prio) {
- new_csg_prio--;
- continue;
- }
-
- panthor_fw_csg_endpoint_req_update(ptdev, csg_iface,
- CSG_EP_REQ_PRIORITY(new_csg_prio),
- CSG_EP_REQ_PRIORITY_MASK);
- csgs_upd_ctx_queue_reqs(ptdev, &upd_ctx, csg_id,
- csg_iface->output->ack ^ CSG_ENDPOINT_CONFIG,
- CSG_ENDPOINT_CONFIG);
- new_csg_prio--;
- }
+ list_for_each_entry(group, &ctx->groups[prio], run_node)
+ tick_ctx_update_group_prio(sched, &upd_ctx, group,
+ new_csg_prio--);
}
ret = csgs_upd_ctx_apply_locked(ptdev, &upd_ctx);
@@ -2425,34 +2467,23 @@ tick_ctx_apply(struct panthor_scheduler *sched, struct panthor_sched_tick_ctx *c
for (prio = PANTHOR_CSG_PRIORITY_COUNT - 1; prio >= 0; prio--) {
list_for_each_entry(group, &ctx->groups[prio], run_node) {
int csg_id = group->csg_id;
- struct panthor_fw_csg_iface *csg_iface;
+ int csg_prio = new_csg_prio--;
- if (csg_id >= 0) {
- new_csg_prio--;
+ if (csg_id >= 0)
continue;
- }
csg_id = ffs(free_csg_slots) - 1;
if (drm_WARN_ON(&ptdev->base, csg_id < 0))
break;
- csg_iface = panthor_fw_get_csg_iface(ptdev, csg_id);
- csg_slot = &sched->csg_slots[csg_id];
- ret = group_bind_locked(group, csg_id);
+ ret = tick_ctx_schedule_group(sched, &upd_ctx, group,
+ csg_id, csg_prio);
if (ret) {
panthor_device_schedule_reset(ptdev);
ctx->csg_upd_failed_mask |= BIT(csg_id);
return;
}
- csg_slot_prog_locked(ptdev, csg_id, new_csg_prio--);
- csgs_upd_ctx_queue_reqs(ptdev, &upd_ctx, csg_id,
- group->state == PANTHOR_CS_GROUP_SUSPENDED ?
- CSG_STATE_RESUME : CSG_STATE_START,
- CSG_STATE_MASK);
- csgs_upd_ctx_queue_reqs(ptdev, &upd_ctx, csg_id,
- csg_iface->output->ack ^ CSG_ENDPOINT_CONFIG,
- CSG_ENDPOINT_CONFIG);
free_csg_slots &= ~BIT(csg_id);
}
}
--
2.43.0
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH v5 03/13] drm/panthor: Pass drm_file instead of panthor_file
2026-11-16 11:25 [PATCH v5 00/13] drm/panthor: Protected mode support for Mali CSF GPUs Ketil Johnsen
2026-11-16 11:25 ` [PATCH v5 01/13] drm/panthor: De-duplicate FW memory section sync Ketil Johnsen
2026-11-16 11:25 ` [PATCH v5 02/13] drm/panthor: Minor scheduler refactoring Ketil Johnsen
@ 2026-11-16 11:25 ` Ketil Johnsen
2026-11-16 11:25 ` [PATCH v5 04/13] drm/panthor: Don't allocate protm_suspend_buf Ketil Johnsen
` (9 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Ketil Johnsen @ 2026-11-16 11:25 UTC (permalink / raw)
To: Boris Brezillon, Steven Price, Liviu Dudau, Akash Goel,
Karunika Choo, Lukas Zapolskas, Chris Diamand, Maarten Lankhorst,
Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter,
Daniel Almeida, Alice Ryhl
Cc: dri-devel, linux-kernel, rust-for-linux, Ketil Johnsen
From: Boris Brezillon <boris.brezillon@collabora.com>
Some sched helpers need info that are part of drm_file, and we will
soon need to call drm_gem_object_lookup() from panthor_group_create().
Let's prepare for that by passing a drm_file instead of panthor_file to
all current helpers taking a panthor_file, so we keep things consistent.
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Co-developed-by: Ketil Johnsen <ketil.johnsen@arm.com>
Signed-off-by: Ketil Johnsen <ketil.johnsen@arm.com>
---
v5:
- Updated kernel doc
v4:
- No change
v3:
- Fixed incorrect parameter passed to panthor_gpu_show_fdinfo()
v2:
- First introduction of this patch in this patch set
---
drivers/gpu/drm/panthor/panthor_drv.c | 38 +++++++++++-------------
drivers/gpu/drm/panthor/panthor_mmu.c | 17 ++++++-----
drivers/gpu/drm/panthor/panthor_mmu.h | 6 ++--
drivers/gpu/drm/panthor/panthor_sched.c | 39 +++++++++++++++----------
drivers/gpu/drm/panthor/panthor_sched.h | 23 +++++++--------
5 files changed, 63 insertions(+), 60 deletions(-)
diff --git a/drivers/gpu/drm/panthor/panthor_drv.c b/drivers/gpu/drm/panthor/panthor_drv.c
index dc8d0191aef42..7edb8d329a705 100644
--- a/drivers/gpu/drm/panthor/panthor_drv.c
+++ b/drivers/gpu/drm/panthor/panthor_drv.c
@@ -1106,7 +1106,6 @@ static int panthor_ioctl_bo_mmap_offset(struct drm_device *ddev, void *data,
static int panthor_ioctl_group_submit(struct drm_device *ddev, void *data,
struct drm_file *file)
{
- struct panthor_file *pfile = file->driver_priv;
struct drm_panthor_group_submit *args = data;
struct drm_panthor_queue_submit *jobs_args;
struct panthor_submit_ctx ctx;
@@ -1131,8 +1130,7 @@ static int panthor_ioctl_group_submit(struct drm_device *ddev, void *data,
const struct drm_panthor_queue_submit *qsubmit = &jobs_args[i];
struct drm_sched_job *job;
- job = panthor_job_create(pfile, args->group_handle, qsubmit,
- file->client_id);
+ job = panthor_job_create(file, args->group_handle, qsubmit);
if (IS_ERR(job)) {
ret = PTR_ERR(job);
goto out_cleanup_submit_ctx;
@@ -1212,19 +1210,17 @@ static int panthor_ioctl_group_submit(struct drm_device *ddev, void *data,
static int panthor_ioctl_group_destroy(struct drm_device *ddev, void *data,
struct drm_file *file)
{
- struct panthor_file *pfile = file->driver_priv;
struct drm_panthor_group_destroy *args = data;
if (args->pad)
return -EINVAL;
- return panthor_group_destroy(pfile, args->group_handle);
+ return panthor_group_destroy(file, args->group_handle);
}
static int panthor_ioctl_group_create(struct drm_device *ddev, void *data,
struct drm_file *file)
{
- struct panthor_file *pfile = file->driver_priv;
struct drm_panthor_group_create *args = data;
struct drm_panthor_queue_create *queue_args;
int ret;
@@ -1240,7 +1236,7 @@ static int panthor_ioctl_group_create(struct drm_device *ddev, void *data,
if (ret)
goto out;
- ret = panthor_group_create(pfile, args, queue_args, file->client_id);
+ ret = panthor_group_create(file, args, queue_args);
if (ret < 0)
goto out;
args->group_handle = ret;
@@ -1254,10 +1250,9 @@ static int panthor_ioctl_group_create(struct drm_device *ddev, void *data,
static int panthor_ioctl_group_get_state(struct drm_device *ddev, void *data,
struct drm_file *file)
{
- struct panthor_file *pfile = file->driver_priv;
struct drm_panthor_group_get_state *args = data;
- return panthor_group_get_state(pfile, args);
+ return panthor_group_get_state(file, args);
}
static int panthor_ioctl_tiler_heap_create(struct drm_device *ddev, void *data,
@@ -1600,6 +1595,7 @@ panthor_open(struct drm_device *ddev, struct drm_file *file)
if (!pfile)
return -ENOMEM;
+ file->driver_priv = pfile;
pfile->ptdev = ptdev;
pfile->user_mmio.offset = DRM_PANTHOR_USER_MMIO_OFFSET;
@@ -1614,19 +1610,18 @@ panthor_open(struct drm_device *ddev, struct drm_file *file)
#endif
- ret = panthor_vm_pool_create(pfile);
+ ret = panthor_vm_pool_create(file);
if (ret)
goto err_free_file;
- ret = panthor_group_pool_create(pfile);
+ ret = panthor_group_pool_create(file);
if (ret)
goto err_destroy_vm_pool;
- file->driver_priv = pfile;
return 0;
err_destroy_vm_pool:
- panthor_vm_pool_destroy(pfile);
+ panthor_vm_pool_destroy(file);
err_free_file:
kfree(pfile);
@@ -1638,8 +1633,8 @@ panthor_postclose(struct drm_device *ddev, struct drm_file *file)
{
struct panthor_file *pfile = file->driver_priv;
- panthor_group_pool_destroy(pfile);
- panthor_vm_pool_destroy(pfile);
+ panthor_group_pool_destroy(file);
+ panthor_vm_pool_destroy(file);
kfree(pfile);
}
@@ -1699,11 +1694,13 @@ static int panthor_mmap(struct file *filp, struct vm_area_struct *vma)
}
static void panthor_gpu_show_fdinfo(struct panthor_device *ptdev,
- struct panthor_file *pfile,
+ struct drm_file *file,
struct drm_printer *p)
{
+ struct panthor_file *pfile = file->driver_priv;
+
if (ptdev->profile_mask & PANTHOR_DEVICE_PROFILING_ALL)
- panthor_fdinfo_gather_group_samples(pfile);
+ panthor_fdinfo_gather_group_samples(file);
if (ptdev->profile_mask & PANTHOR_DEVICE_PROFILING_TIMESTAMP) {
#ifdef CONFIG_ARM_ARCH_TIMER
@@ -1723,11 +1720,10 @@ static void panthor_gpu_show_fdinfo(struct panthor_device *ptdev,
static void panthor_show_internal_memory_stats(struct drm_printer *p, struct drm_file *file)
{
char *drv_name = file->minor->dev->driver->name;
- struct panthor_file *pfile = file->driver_priv;
struct drm_memory_stats stats = {0};
- panthor_fdinfo_gather_group_mem_info(pfile, &stats);
- panthor_vm_heaps_sizes(pfile, &stats);
+ panthor_fdinfo_gather_group_mem_info(file, &stats);
+ panthor_vm_heaps_sizes(file, &stats);
drm_fdinfo_print_size(p, drv_name, "resident", "memory", stats.resident);
drm_fdinfo_print_size(p, drv_name, "active", "memory", stats.active);
@@ -1738,7 +1734,7 @@ static void panthor_show_fdinfo(struct drm_printer *p, struct drm_file *file)
struct drm_device *dev = file->minor->dev;
struct panthor_device *ptdev = container_of(dev, struct panthor_device, base);
- panthor_gpu_show_fdinfo(ptdev, file->driver_priv, p);
+ panthor_gpu_show_fdinfo(ptdev, file, p);
panthor_show_internal_memory_stats(p, file);
drm_show_memory_stats(p, file);
diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/panthor/panthor_mmu.c
index d1c29eec46f21..838753db95151 100644
--- a/drivers/gpu/drm/panthor/panthor_mmu.c
+++ b/drivers/gpu/drm/panthor/panthor_mmu.c
@@ -1676,15 +1676,16 @@ panthor_vm_pool_get_vm(struct panthor_vm_pool *pool, u32 handle)
/**
* panthor_vm_pool_destroy() - Destroy a VM pool.
- * @pfile: File.
+ * @file: DRM file.
*
* Destroy all VMs in the pool, and release the pool resources.
*
* Note that VMs can outlive the pool they were created from if other
* objects hold a reference to there VMs.
*/
-void panthor_vm_pool_destroy(struct panthor_file *pfile)
+void panthor_vm_pool_destroy(struct drm_file *file)
{
+ struct panthor_file *pfile = file->driver_priv;
struct panthor_vm *vm;
unsigned long i;
@@ -1702,12 +1703,13 @@ void panthor_vm_pool_destroy(struct panthor_file *pfile)
/**
* panthor_vm_pool_create() - Create a VM pool
- * @pfile: File.
+ * @file: DRM file.
*
* Return: 0 on success, a negative error code otherwise.
*/
-int panthor_vm_pool_create(struct panthor_file *pfile)
+int panthor_vm_pool_create(struct drm_file *file)
{
+ struct panthor_file *pfile = file->driver_priv;
struct panthor_gem_object *dummy;
int ret;
@@ -1728,7 +1730,7 @@ int panthor_vm_pool_create(struct panthor_file *pfile)
return 0;
err_destroy_vm_pool:
- panthor_vm_pool_destroy(pfile);
+ panthor_vm_pool_destroy(file);
return ret;
}
@@ -2141,14 +2143,15 @@ struct panthor_heap_pool *panthor_vm_get_heap_pool(struct panthor_vm *vm, bool c
/**
* panthor_vm_heaps_sizes() - Calculate size of all heap chunks across all
* heaps over all the heap pools in a VM
- * @pfile: File.
+ * @file: DRM file.
* @stats: Memory stats to be updated.
*
* Calculate all heap chunk sizes in all heap pools bound to a VM. If the VM
* is active, record the size as active as well.
*/
-void panthor_vm_heaps_sizes(struct panthor_file *pfile, struct drm_memory_stats *stats)
+void panthor_vm_heaps_sizes(struct drm_file *file, struct drm_memory_stats *stats)
{
+ struct panthor_file *pfile = file->driver_priv;
struct panthor_vm *vm;
unsigned long i;
diff --git a/drivers/gpu/drm/panthor/panthor_mmu.h b/drivers/gpu/drm/panthor/panthor_mmu.h
index abc36e7204be0..e262fe2303f6c 100644
--- a/drivers/gpu/drm/panthor/panthor_mmu.h
+++ b/drivers/gpu/drm/panthor/panthor_mmu.h
@@ -38,7 +38,7 @@ int panthor_vm_as(struct panthor_vm *vm);
struct panthor_heap_pool *
panthor_vm_get_heap_pool(struct panthor_vm *vm, bool create);
-void panthor_vm_heaps_sizes(struct panthor_file *pfile, struct drm_memory_stats *stats);
+void panthor_vm_heaps_sizes(struct drm_file *file, struct drm_memory_stats *stats);
struct panthor_vm *panthor_vm_get(struct panthor_vm *vm);
void panthor_vm_put(struct panthor_vm *vm);
@@ -64,8 +64,8 @@ void panthor_vm_add_job_fence_to_bos_resvs(struct panthor_vm *vm,
struct dma_resv *panthor_vm_resv(struct panthor_vm *vm);
struct drm_gem_object *panthor_vm_root_gem(struct panthor_vm *vm);
-void panthor_vm_pool_destroy(struct panthor_file *pfile);
-int panthor_vm_pool_create(struct panthor_file *pfile);
+void panthor_vm_pool_destroy(struct drm_file *file);
+int panthor_vm_pool_create(struct drm_file *file);
int panthor_vm_pool_create_vm(struct panthor_device *ptdev,
struct panthor_vm_pool *pool,
struct drm_panthor_vm_create *args);
diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c
index d632fe1bf4db8..c75be18d24274 100644
--- a/drivers/gpu/drm/panthor/panthor_sched.c
+++ b/drivers/gpu/drm/panthor/panthor_sched.c
@@ -3117,8 +3117,9 @@ void panthor_sched_post_reset(struct panthor_device *ptdev, bool reset_failed)
}
}
-void panthor_fdinfo_gather_group_samples(struct panthor_file *pfile)
+void panthor_fdinfo_gather_group_samples(struct drm_file *file)
{
+ struct panthor_file *pfile = file->driver_priv;
struct panthor_group_pool *gpool = pfile->groups;
struct panthor_group *group;
unsigned long i;
@@ -3654,11 +3655,11 @@ static void add_group_kbo_sizes(struct panthor_device *ptdev,
#define MAX_GROUPS_PER_POOL 128
-int panthor_group_create(struct panthor_file *pfile,
+int panthor_group_create(struct drm_file *file,
const struct drm_panthor_group_create *group_args,
- const struct drm_panthor_queue_create *queue_args,
- u64 drm_client_id)
+ const struct drm_panthor_queue_create *queue_args)
{
+ struct panthor_file *pfile = file->driver_priv;
struct panthor_device *ptdev = pfile->ptdev;
struct panthor_group_pool *gpool = pfile->groups;
struct panthor_scheduler *sched = ptdev->scheduler;
@@ -3756,7 +3757,8 @@ int panthor_group_create(struct panthor_file *pfile,
goto err_put_group;
for (i = 0; i < group_args->queues.count; i++) {
- group->queues[i] = group_create_queue(group, &queue_args[i], drm_client_id, gid, i);
+ group->queues[i] = group_create_queue(group, &queue_args[i],
+ file->client_id, gid, i);
if (IS_ERR(group->queues[i])) {
ret = PTR_ERR(group->queues[i]);
group->queues[i] = NULL;
@@ -3796,8 +3798,9 @@ int panthor_group_create(struct panthor_file *pfile,
return ret;
}
-int panthor_group_destroy(struct panthor_file *pfile, u32 group_handle)
+int panthor_group_destroy(struct drm_file *file, u32 group_handle)
{
+ struct panthor_file *pfile = file->driver_priv;
struct panthor_group_pool *gpool = pfile->groups;
struct panthor_device *ptdev = pfile->ptdev;
struct panthor_scheduler *sched = ptdev->scheduler;
@@ -3848,9 +3851,10 @@ static struct panthor_group *group_from_handle(struct panthor_group_pool *pool,
return group;
}
-int panthor_group_get_state(struct panthor_file *pfile,
+int panthor_group_get_state(struct drm_file *file,
struct drm_panthor_group_get_state *get_state)
{
+ struct panthor_file *pfile = file->driver_priv;
struct panthor_group_pool *gpool = pfile->groups;
struct panthor_device *ptdev = pfile->ptdev;
struct panthor_scheduler *sched = ptdev->scheduler;
@@ -3881,8 +3885,9 @@ int panthor_group_get_state(struct panthor_file *pfile,
return 0;
}
-int panthor_group_pool_create(struct panthor_file *pfile)
+int panthor_group_pool_create(struct drm_file *file)
{
+ struct panthor_file *pfile = file->driver_priv;
struct panthor_group_pool *gpool;
gpool = kzalloc_obj(*gpool);
@@ -3894,8 +3899,9 @@ int panthor_group_pool_create(struct panthor_file *pfile)
return 0;
}
-void panthor_group_pool_destroy(struct panthor_file *pfile)
+void panthor_group_pool_destroy(struct drm_file *file)
{
+ struct panthor_file *pfile = file->driver_priv;
struct panthor_group_pool *gpool = pfile->groups;
struct panthor_group *group;
unsigned long i;
@@ -3904,7 +3910,7 @@ void panthor_group_pool_destroy(struct panthor_file *pfile)
return;
xa_for_each(&gpool->xa, i, group)
- panthor_group_destroy(pfile, i);
+ panthor_group_destroy(file, i);
xa_destroy(&gpool->xa);
kfree(gpool);
@@ -3914,14 +3920,15 @@ void panthor_group_pool_destroy(struct panthor_file *pfile)
/**
* panthor_fdinfo_gather_group_mem_info() - Retrieve aggregate size of all private kernel BO's
* belonging to all the groups owned by an open Panthor file
- * @pfile: File.
+ * @file: DRM file.
* @stats: Memory statistics to be updated.
*
*/
void
-panthor_fdinfo_gather_group_mem_info(struct panthor_file *pfile,
+panthor_fdinfo_gather_group_mem_info(struct drm_file *file,
struct drm_memory_stats *stats)
{
+ struct panthor_file *pfile = file->driver_priv;
struct panthor_group_pool *gpool = pfile->groups;
struct panthor_group *group;
unsigned long i;
@@ -3984,11 +3991,11 @@ struct panthor_vm *panthor_job_vm(struct drm_sched_job *sched_job)
}
struct drm_sched_job *
-panthor_job_create(struct panthor_file *pfile,
+panthor_job_create(struct drm_file *file,
u16 group_handle,
- const struct drm_panthor_queue_submit *qsubmit,
- u64 drm_client_id)
+ const struct drm_panthor_queue_submit *qsubmit)
{
+ struct panthor_file *pfile = file->driver_priv;
struct panthor_group_pool *gpool = pfile->groups;
struct panthor_job *job;
u32 credits;
@@ -4059,7 +4066,7 @@ panthor_job_create(struct panthor_file *pfile,
ret = drm_sched_job_init(&job->base,
&job->group->queues[job->queue_idx]->entity,
- credits, job->group, drm_client_id);
+ credits, job->group, file->client_id);
if (ret)
goto err_put_job;
diff --git a/drivers/gpu/drm/panthor/panthor_sched.h b/drivers/gpu/drm/panthor/panthor_sched.h
index d87cbdba4d40b..c509fcb5a0c9c 100644
--- a/drivers/gpu/drm/panthor/panthor_sched.h
+++ b/drivers/gpu/drm/panthor/panthor_sched.h
@@ -16,31 +16,28 @@ struct drm_panthor_queue_create;
struct drm_panthor_group_get_state;
struct drm_panthor_queue_submit;
struct panthor_device;
-struct panthor_file;
struct panthor_group_pool;
struct panthor_job;
-int panthor_group_create(struct panthor_file *pfile,
+int panthor_group_create(struct drm_file *file,
const struct drm_panthor_group_create *group_args,
- const struct drm_panthor_queue_create *queue_args,
- u64 drm_client_id);
-int panthor_group_destroy(struct panthor_file *pfile, u32 group_handle);
-int panthor_group_get_state(struct panthor_file *pfile,
+ const struct drm_panthor_queue_create *queue_args);
+int panthor_group_destroy(struct drm_file *file, u32 group_handle);
+int panthor_group_get_state(struct drm_file *file,
struct drm_panthor_group_get_state *get_state);
struct drm_sched_job *
-panthor_job_create(struct panthor_file *pfile,
+panthor_job_create(struct drm_file *file,
u16 group_handle,
- const struct drm_panthor_queue_submit *qsubmit,
- u64 drm_client_id);
+ const struct drm_panthor_queue_submit *qsubmit);
struct drm_sched_job *panthor_job_get(struct drm_sched_job *job);
struct panthor_vm *panthor_job_vm(struct drm_sched_job *sched_job);
void panthor_job_put(struct drm_sched_job *job);
void panthor_job_update_resvs(struct drm_exec *exec, struct drm_sched_job *job);
-int panthor_group_pool_create(struct panthor_file *pfile);
-void panthor_group_pool_destroy(struct panthor_file *pfile);
-void panthor_fdinfo_gather_group_mem_info(struct panthor_file *pfile,
+int panthor_group_pool_create(struct drm_file *file);
+void panthor_group_pool_destroy(struct drm_file *file);
+void panthor_fdinfo_gather_group_mem_info(struct drm_file *pfile,
struct drm_memory_stats *stats);
int panthor_sched_init(struct panthor_device *ptdev);
@@ -54,7 +51,7 @@ void panthor_sched_report_mmu_fault(struct panthor_device *ptdev);
void panthor_sched_prepare_for_vm_destruction(struct panthor_device *ptdev);
void panthor_sched_report_fw_events(struct panthor_device *ptdev, u32 events);
-void panthor_fdinfo_gather_group_samples(struct panthor_file *pfile);
+void panthor_fdinfo_gather_group_samples(struct drm_file *file);
#ifdef CONFIG_DEBUG_FS
void panthor_sched_debugfs_init(struct drm_minor *minor);
--
2.43.0
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH v5 04/13] drm/panthor: Don't allocate protm_suspend_buf
2026-11-16 11:25 [PATCH v5 00/13] drm/panthor: Protected mode support for Mali CSF GPUs Ketil Johnsen
` (2 preceding siblings ...)
2026-11-16 11:25 ` [PATCH v5 03/13] drm/panthor: Pass drm_file instead of panthor_file Ketil Johnsen
@ 2026-11-16 11:25 ` Ketil Johnsen
2026-11-16 11:25 ` [PATCH v5 05/13] drm/panthor: Add support for entering and exiting protected mode Ketil Johnsen
` (8 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Ketil Johnsen @ 2026-11-16 11:25 UTC (permalink / raw)
To: Boris Brezillon, Steven Price, Liviu Dudau, Akash Goel,
Karunika Choo, Lukas Zapolskas, Chris Diamand, Maarten Lankhorst,
Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter,
Daniel Almeida, Alice Ryhl
Cc: dri-devel, linux-kernel, rust-for-linux, Ketil Johnsen
The PROTM suspend buffer is only needed if the group is going to
use PROTM in the first place, so let's not assume we need one until
we're being asked to.
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Steven Price <steven.price@arm.com>
Reviewed-by: Liviu Dudau <liviu.dudau@arm.com>
Signed-off-by: Ketil Johnsen <ketil.johnsen@arm.com>
---
drivers/gpu/drm/panthor/panthor_sched.c | 14 ++++----------
1 file changed, 4 insertions(+), 10 deletions(-)
diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c
index c75be18d24274..e67fd0fe20144 100644
--- a/drivers/gpu/drm/panthor/panthor_sched.c
+++ b/drivers/gpu/drm/panthor/panthor_sched.c
@@ -3641,9 +3641,11 @@ static void add_group_kbo_sizes(struct panthor_device *ptdev,
if (drm_WARN_ON(&ptdev->base, ptdev != group->ptdev))
return;
- group->fdinfo.kbo_sizes += group->suspend_buf->obj->size;
- group->fdinfo.kbo_sizes += group->protm_suspend_buf->obj->size;
group->fdinfo.kbo_sizes += group->syncobjs->obj->size;
+ group->fdinfo.kbo_sizes += group->suspend_buf->obj->size;
+
+ if (group->protm_suspend_buf)
+ group->fdinfo.kbo_sizes += group->protm_suspend_buf->obj->size;
for (i = 0; i < group->queue_count; i++) {
queue = group->queues[i];
@@ -3724,14 +3726,6 @@ int panthor_group_create(struct drm_file *file,
goto err_put_group;
}
- suspend_size = csg_iface->control->protm_suspend_size;
- group->protm_suspend_buf = panthor_fw_alloc_suspend_buf_mem(ptdev, suspend_size);
- if (IS_ERR(group->protm_suspend_buf)) {
- ret = PTR_ERR(group->protm_suspend_buf);
- group->protm_suspend_buf = NULL;
- goto err_put_group;
- }
-
group->syncobjs = panthor_kernel_bo_create(ptdev, group->vm,
group_args->queues.count *
sizeof(struct panthor_syncobj_64b),
--
2.43.0
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH v5 05/13] drm/panthor: Add support for entering and exiting protected mode
2026-11-16 11:25 [PATCH v5 00/13] drm/panthor: Protected mode support for Mali CSF GPUs Ketil Johnsen
` (3 preceding siblings ...)
2026-11-16 11:25 ` [PATCH v5 04/13] drm/panthor: Don't allocate protm_suspend_buf Ketil Johnsen
@ 2026-11-16 11:25 ` Ketil Johnsen
2026-11-16 11:25 ` [PATCH v5 06/13] drm/panthor: New function for FW section map flags Ketil Johnsen
` (7 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Ketil Johnsen @ 2026-11-16 11:25 UTC (permalink / raw)
To: Boris Brezillon, Steven Price, Liviu Dudau, Akash Goel,
Karunika Choo, Lukas Zapolskas, Chris Diamand, Maarten Lankhorst,
Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter,
Daniel Almeida, Alice Ryhl
Cc: dri-devel, linux-kernel, rust-for-linux, Florent Tomasin,
Paul Toadere, Samuel Percival, Ketil Johnsen
From: Florent Tomasin <florent.tomasin@arm.com>
This patch modifies the Panthor driver code to allow handling
of the GPU HW protected mode enter and exit.
The logic added by this patch includes:
- the mechanisms needed for entering and exiting protected mode.
- the handling of protected mode IRQs and FW interactions.
- the scheduler changes needed to decide when to enter
protected mode based on CSG scheduling.
- GPU fault handling during protected mode execution.
Note that the submission of protected mode jobs are done
from the user space.
The following is a summary of how protected mode is entered
and exited:
- When the GPU detects a protected mode job needs to be
executed, an IRQ is sent to the CPU to notify the kernel
driver that the job is blocked until the GPU has entered
protected mode. The entering of protected mode is controlled
by the kernel driver.
- The Mali Panthor CSF driver will schedule a tick and evaluate
which CS in the CSG to schedule on slot needs protected mode.
If the priority of the CSG is not sufficiently high, the
protected mode job will not progress until the CSG is
scheduled at top priority.
- The Panthor scheduler notifies the GPU that the blocked
protected jobs will soon be able to progress.
- Once all CSG and CS slots are updated, the scheduler
requests the GPU to enter protected mode and waits for
it to be acknowledged.
- If successful, all protected mode jobs will resume execution
while normal mode jobs block until the GPU exits
protected mode, or the kernel driver rotates the CSGs
and forces the GPU to exit protected mode.
- If unsuccessful, the scheduler will request a GPU reset.
- Faults during protected mode are reported GPU wide, and not as
CSG/CS errors. We allow only one CSG to run in protected mode at a
time so we know which CSG to blame for the fault.
- All faults during protected mode are handled with a GPU reset.
This sequence will continue so long the user space is
submitting protected mode jobs.
Signed-off-by: Florent Tomasin <florent.tomasin@arm.com>
Co-developed-by: Paul Toadere <paul.toadere@arm.com>
Signed-off-by: Paul Toadere <paul.toadere@arm.com>
Co-developed-by: Samuel Percival <samuel.percival@arm.com>
Signed-off-by: Samuel Percival <samuel.percival@arm.com>
Co-developed-by: Ketil Johnsen <ketil.johnsen@arm.com>
Signed-off-by: Ketil Johnsen <ketil.johnsen@arm.com>
---
v5:
- Use empty transtab trickery for "dormant" VMs during protm
instead of the "delayed update" mask in previous version.
- Ditched "try block", no need to block protm in reclaim path.
- Split remap_evicted_vma() to avoid mixed cleanup approaches.
- Take protm.lock in panthor_sched_post_reset()
- Halt processing of async VM ops for VM executing in protm.
- Minor formating fixes.
- Minor kernel doc fixes.
v4:
- Do not pick any more groups if first group requests protm.
Prevous versions allowed lower pri groups to stay on slot.
- Moved the rwsem for protm sync into scheduler.
- Added protm exit handling to start of scheduler tick.
- Scheduler will notify MMU code when it enters and exits protm.
- When in protected mode, MMU code will do "delayed updates" of VMs
which are not "running". This avoids unnecessary preemptions and
blocking during unrelated VM_BIND ops.
- Page table updates to FW VM and currently running protm VM can
not proceed before protm is exited (preempted).
- Ensure ticking during protm (so we can evaluate preemption).
- Added special protm preempt code with preempt_protm_group().
- Poll for protm enter and exit without FW event wait queue.
Protm enter simply use read_poll_timeout().
Protm exit use a custom loop as this needs to be interruptible (long waits).
- Reversed check order in panthor_gpu_protm_fault_pending()
- Do not print error message in panthor_fw_protm_exit(), leave that to caller
since it can some times be expected.
- Reintroduce disabling of GPU_IRQ_PROTM_FAULT while handling them.
- Reset protm_fault and re-enable GPU_IRQ_PROTM_FAULT after FW have re-started.
- Tweaks to tick_ctx_handle_protm_group(), take events_lock and ack everything!
- Use "protm block" with DEFINE_GUARD helpers (MMU code).
- Minor spelling/wording and naming changes.
v3:
- Rebase
- Required changes due to new IRQ handling (events_lock).
- Required changes due to memory reclaim (more places to sync with protm).
- Count number of enter and exits to and from protected mode.
- Added helper function wait_protm_enter() to check protm enter condition, using
the counters mentioned above.
- Tweaks to timeouts.
- Removed disable/enable of GPU_IRQ_PROTM_FAULT. No longer recall what issue it
was supposed to fix.
- protm_fault changed to atomic.
- Moved sync with protm out from panthor_vm_lock_region() and
panthor_vm_unlock_region().
- Avoids special dealing with as.slots_lock and GPU reset.
- Block and unblock of protm in same function, so easier to see.
- We no longer need to add panthor_vm_expand_locked_region() (different patch).
- The downside is that we might block protm mode more than necessary.
- Added panthor_sched_protm_try_block() used by memory reclaim case.
- protm_pending_queues made atomic (following the same change for fatal_queues).
- Only clear bits from protm_pending_queues when we ACK CS_PROTM_PENDING.
- Clear any pending CS_PROTM_PENDING on slot reset.
- Ack all CS_PROTM_PENDING in tick_ctx_handle_protm_group(), no matter the value
of protm_pending_queues.
- Inlined helper function panthor_sched_protm_enter().
v2:
- Heavily reworked, although conceptually similar to v1.
---
drivers/gpu/drm/panthor/panthor_device.h | 8 +
drivers/gpu/drm/panthor/panthor_fw.c | 94 ++++-
drivers/gpu/drm/panthor/panthor_fw.h | 4 +
drivers/gpu/drm/panthor/panthor_gpu.c | 49 ++-
drivers/gpu/drm/panthor/panthor_gpu.h | 4 +
drivers/gpu/drm/panthor/panthor_mmu.c | 351 +++++++++++++-----
drivers/gpu/drm/panthor/panthor_mmu.h | 5 +
drivers/gpu/drm/panthor/panthor_sched.c | 438 +++++++++++++++++++++--
drivers/gpu/drm/panthor/panthor_sched.h | 16 +
9 files changed, 847 insertions(+), 122 deletions(-)
diff --git a/drivers/gpu/drm/panthor/panthor_device.h b/drivers/gpu/drm/panthor/panthor_device.h
index b55a3f9edd414..ac779059a9397 100644
--- a/drivers/gpu/drm/panthor/panthor_device.h
+++ b/drivers/gpu/drm/panthor/panthor_device.h
@@ -336,6 +336,14 @@ struct panthor_device {
struct list_head node;
} gems;
#endif
+ /** @protm: Protected mode related data. */
+ struct {
+ /** @protm.protm_enter_count: Number of times we entered protm. */
+ atomic64_t protm_enter_count;
+
+ /** @protm.protm_exit_count: Number of times we exited protm. */
+ atomic64_t protm_exit_count;
+ } protm;
};
struct panthor_gpu_usage {
diff --git a/drivers/gpu/drm/panthor/panthor_fw.c b/drivers/gpu/drm/panthor/panthor_fw.c
index 5f9f7a92c56a8..e639ffeac7a32 100644
--- a/drivers/gpu/drm/panthor/panthor_fw.c
+++ b/drivers/gpu/drm/panthor/panthor_fw.c
@@ -1067,7 +1067,9 @@ static void panthor_fw_init_global_iface(struct panthor_device *ptdev)
GLB_CFG_PROGRESS_TIMER |
GLB_CFG_POWEROFF_TIMER |
GLB_IDLE_EN |
- GLB_IDLE;
+ GLB_IDLE |
+ GLB_PROTM_ENTER |
+ GLB_PROTM_EXIT;
if (panthor_fw_has_glb_state(ptdev))
glb_iface->input->ack_irq_mask |= GLB_STATE_MASK;
@@ -1281,6 +1283,9 @@ int panthor_fw_post_reset(struct panthor_device *ptdev)
return ret;
}
+ atomic64_set(&ptdev->protm.protm_enter_count, 0);
+ atomic64_set(&ptdev->protm.protm_exit_count, 0);
+
/* We must re-initialize the global interface even on fast-reset. */
panthor_fw_init_global_iface(ptdev);
return 0;
@@ -1476,6 +1481,93 @@ static void panthor_fw_ping_work(struct work_struct *work)
}
}
+static bool wait_protm_enter(struct panthor_device *ptdev,
+ s64 protm_session_seqno)
+{
+ return (panthor_gpu_status(ptdev) & GPU_STATUS_PROTM_ACTIVE) ||
+ (atomic64_read(&ptdev->protm.protm_exit_count) >=
+ protm_session_seqno);
+}
+
+int panthor_fw_protm_enter(struct panthor_device *ptdev)
+{
+ struct panthor_fw_global_iface *glb_iface =
+ panthor_fw_get_glb_iface(ptdev);
+ u32 acked;
+ int ret;
+ long long enter_count;
+ bool status;
+
+ /* Restart the watchdog timer, so it doesn't hit immediately
+ * after entering protected mode, since this will cause GPU
+ * to exit protected mode to respond to the ping request.
+ */
+ mod_delayed_work(ptdev->reset.wq, &ptdev->fw->watchdog.ping_work,
+ msecs_to_jiffies(PING_INTERVAL_MS));
+
+ panthor_fw_toggle_reqs(glb_iface, req, ack, GLB_PROTM_ENTER);
+ panthor_fw_ring_doorbell(ptdev, CSF_GLB_DOORBELL_ID);
+
+ ret = panthor_fw_glb_wait_acks(ptdev, GLB_PROTM_ENTER, &acked, 250);
+ if (ret) {
+ drm_err(&ptdev->base,
+ "Wait for FW protected mode acknowledge timed out");
+ return ret;
+ }
+
+ enter_count = atomic64_inc_return(&ptdev->protm.protm_enter_count);
+
+ /* Poll for the entry of protected mode.
+ * It is possible that GPU_STATUS_PROTM_ACTIVE is set and cleared
+ * before we check it below, so we must also check for GLB_PROTM_EXIT.
+ * GLB_PROTM_EXIT can not be checked directly, because this could also
+ * be handled and clear before we check below. We count number of
+ * protm enters and exits to safely handle that case.
+ */
+ ret = read_poll_timeout(wait_protm_enter, status, status, 100, 500000,
+ false, ptdev, enter_count);
+
+ if (ret) {
+ drm_err(&ptdev->base,
+ "Wait for GPU protected mode enter timed out");
+ return -ETIMEDOUT;
+ }
+
+ return 0;
+}
+
+int panthor_fw_protm_exit_wait(struct panthor_device *ptdev, u32 timeout_ms)
+{
+ unsigned long deadline = jiffies + msecs_to_jiffies(timeout_ms);
+
+ do {
+ if (!(panthor_gpu_status(ptdev) & GPU_STATUS_PROTM_ACTIVE))
+ return 0;
+
+ if (signal_pending(current))
+ return -ERESTARTSYS;
+
+ usleep_range_state(100, 200, TASK_INTERRUPTIBLE);
+ } while (!time_after_eq(jiffies, deadline));
+
+ if (!(panthor_gpu_status(ptdev) & GPU_STATUS_PROTM_ACTIVE))
+ return 0;
+
+ return -ETIMEDOUT;
+}
+
+int panthor_fw_protm_exit(struct panthor_device *ptdev, u32 timeout_ms)
+{
+ struct panthor_fw_global_iface *glb_iface =
+ panthor_fw_get_glb_iface(ptdev);
+
+ /* Send PING request to force an exit */
+ panthor_fw_toggle_reqs(glb_iface, req, ack, GLB_PING);
+ panthor_fw_ring_doorbell(ptdev, CSF_GLB_DOORBELL_ID);
+
+ return panthor_fw_protm_exit_wait(ptdev, timeout_ms);
+}
+
/**
* panthor_fw_init() - Initialize FW related data.
* @ptdev: Device.
diff --git a/drivers/gpu/drm/panthor/panthor_fw.h b/drivers/gpu/drm/panthor/panthor_fw.h
index a99a9b6f4825c..4eda8f8e714c1 100644
--- a/drivers/gpu/drm/panthor/panthor_fw.h
+++ b/drivers/gpu/drm/panthor/panthor_fw.h
@@ -529,4 +529,8 @@ static inline int panthor_fw_resume(struct panthor_device *ptdev)
int panthor_fw_init(struct panthor_device *ptdev);
void panthor_fw_unplug(struct panthor_device *ptdev);
+int panthor_fw_protm_enter(struct panthor_device *ptdev);
+int panthor_fw_protm_exit(struct panthor_device *ptdev, u32 timeout_ms);
+int panthor_fw_protm_exit_wait(struct panthor_device *ptdev, u32 timeout_ms);
+
#endif
diff --git a/drivers/gpu/drm/panthor/panthor_gpu.c b/drivers/gpu/drm/panthor/panthor_gpu.c
index b8df5663f04e4..5fcfdba08deff 100644
--- a/drivers/gpu/drm/panthor/panthor_gpu.c
+++ b/drivers/gpu/drm/panthor/panthor_gpu.c
@@ -47,6 +47,9 @@ struct panthor_gpu {
/** @cache_flush_lock: Lock to serialize cache flushes */
struct mutex cache_flush_lock;
+
+ /** @protm_fault: True if a GPU_IRQ_PROTM_FAULT has been raised */
+ atomic_t protm_fault;
};
#define GPU_INTERRUPTS_MASK \
@@ -92,6 +95,35 @@ static void panthor_gpu_irq_handler(struct panthor_irq *pirq, u32 status)
struct panthor_device *ptdev = pirq->ptdev;
struct panthor_gpu *gpu = ptdev->gpu;
+ if (status & GPU_IRQ_PROTM_FAULT) {
+ /* Make a note of this fault before we clear the interrupt.
+ * This ensures panthor_gpu_protm_fault_pending() can always
+ * give an accurate answer.
+ *
+ * There is a race we need to handle between two interrupts,
+ * this GPU_IRQ_PROTM_FAULT and JOB_INT_GLOBAL_IF with the
+ * GLB_PROTM_EXIT event.
+ *
+ * Although GPU_IRQ_PROTM_FAULT is always raised first,
+ * processing of GLB_PROTM_EXIT could still execute first.
+ * The handling of GLB_PROTM_EXIT MUST know if a
+ * GPU_IRQ_PROTM_FAULT has been raised or not, otherwise it
+ * could incorrectly think everything is fine and resume
+ * with normal scheduling to early.
+ *
+ * We still need to do fault handling (reset) here as well,
+ * because some failures during protected mode do not
+ * automatically exit protected mode (no GLB_PROTM_EXIT).
+ * This means there is a slim chance we do two GPU resets
+ * instead of just one. This is not ideal, but should be safe.
+ */
+ atomic_set(&gpu->protm_fault, 1);
+ panthor_irq_disable_events(&ptdev->gpu->irq,
+ GPU_IRQ_PROTM_FAULT);
+ drm_warn(&ptdev->base, "GPU Fault in protected mode");
+ panthor_device_schedule_reset(ptdev);
+ }
+
gpu_write(gpu->irq.iomem, INT_CLEAR, status);
if (tracepoint_enabled(gpu_power_status) && (status & GPU_POWER_INTERRUPTS_MASK))
@@ -108,8 +140,6 @@ static void panthor_gpu_irq_handler(struct panthor_irq *pirq, u32 status)
fault_status, panthor_exception_name(ptdev, fault_status & 0xFF),
address);
}
- if (status & GPU_IRQ_PROTM_FAULT)
- drm_warn(&ptdev->base, "GPU Fault in protected mode\n");
spin_lock(&ptdev->gpu->reqs_lock);
if (status & ptdev->gpu->pending_reqs) {
@@ -124,6 +154,13 @@ static irqreturn_t panthor_gpu_irq_threaded_handler(int irq, void *data)
return panthor_irq_default_threaded_handler(data, panthor_gpu_irq_handler);
}
+bool panthor_gpu_protm_fault_pending(struct panthor_device *ptdev)
+{
+ return gpu_read(ptdev->gpu->irq.iomem, INT_RAWSTAT) &
+ GPU_IRQ_PROTM_FAULT ||
+ atomic_read(&ptdev->gpu->protm_fault);
+}
+
/**
* panthor_gpu_unplug() - Called when the GPU is unplugged.
* @ptdev: Device to unplug.
@@ -431,6 +468,9 @@ int panthor_gpu_soft_reset(struct panthor_device *ptdev)
return -ETIMEDOUT;
}
+ atomic_set(&ptdev->gpu->protm_fault, 0);
+ panthor_irq_enable_events(&ptdev->gpu->irq, GPU_IRQ_PROTM_FAULT);
+
scoped_guard(spinlock, &ptdev->gpu->reqs_lock) {
ptdev->gpu->pending_reqs = 0;
}
@@ -512,3 +552,8 @@ int panthor_gpu_coherency_init(struct panthor_device *ptdev)
drm_err(&ptdev->base, "Coherency not supported by the device");
return -ENOTSUPP;
}
+
+u32 panthor_gpu_status(struct panthor_device *ptdev)
+{
+ return gpu_read(ptdev->gpu->iomem, GPU_STATUS);
+}
diff --git a/drivers/gpu/drm/panthor/panthor_gpu.h b/drivers/gpu/drm/panthor/panthor_gpu.h
index f615feb056094..00ec9a8c5d7fd 100644
--- a/drivers/gpu/drm/panthor/panthor_gpu.h
+++ b/drivers/gpu/drm/panthor/panthor_gpu.h
@@ -60,4 +60,8 @@ u64 panthor_gpu_get_cycle_count(struct panthor_device *ptdev);
int panthor_gpu_coherency_init(struct panthor_device *ptdev);
+u32 panthor_gpu_status(struct panthor_device *ptdev);
+
+bool panthor_gpu_protm_fault_pending(struct panthor_device *ptdev);
+
#endif
diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/panthor/panthor_mmu.c
index 838753db95151..47e7d570683a6 100644
--- a/drivers/gpu/drm/panthor/panthor_mmu.c
+++ b/drivers/gpu/drm/panthor/panthor_mmu.c
@@ -268,6 +268,9 @@ struct panthor_vm {
/** @root_page_table: Stores the root page table pointer. */
void *root_page_table;
+ /** @empty_transtab_offset: Offset to a root page table with no entries */
+ u32 empty_transtab_offset;
+
/**
* @op_lock: Lock used to serialize operations on a VM.
*
@@ -450,6 +453,82 @@ struct panthor_vm_bind_job {
*/
static struct kmem_cache *pt_cache;
+static void panthor_mmu_set_empty_pt(struct panthor_vm *vm)
+{
+ struct panthor_device *ptdev = vm->ptdev;
+ struct panthor_mmu *mmu = ptdev->mmu;
+ struct io_pgtable_cfg *cfg =
+ &io_pgtable_ops_to_pgtable(vm->pgtbl_ops)->cfg;
+ u32 empty_transtab_low =
+ (u32)(cfg->arm_lpae_s1_cfg.ttbr + vm->empty_transtab_offset);
+
+ guard(mutex)(&mmu->as.slots_lock);
+
+ if (vm->as.id < 0)
+ return;
+
+ gpu_write(mmu->iomem, AS_TRANSTAB(vm->as.id), empty_transtab_low);
+}
+
+static bool protm_block_timeout(struct panthor_vm *vm)
+{
+ /* Blocking of protected mode needs some explanation.
+ *
+ * GPU behavior we try to handle:
+ * - Issuing MMU/AS commands during protm will have no effect.
+ * - Exit of protm will resume normal work execution automatically.
+ *
+ * We do not want to block VM operations just because we are in protm.
+ * Process N being blocked from mapping memory just because process P
+ * is running in protm is seemingly unfair, so we want to avoid that.
+ *
+ * We also do not want to unschedule normal groups each time we enter
+ * protm. This would just add latency before these groups can resume
+ * execution after protm exit. We want GPU to resume this automatically.
+ *
+ * Combining our desires with the GPU protm limitations is challenging,
+ * but this is how we are doing it:
+ *
+ * - Before every affected MMU/AS operations, we block the scheduler/GPU
+ * from entering protm.
+ * - If the GPU is not in protm, then we proceed as normal.
+ * - If the GPU is in protm (or about to enter, or have just exited),
+ * then we proceed with additional logic. This is what we try to
+ * handle right here in this function.
+ * - Processes which execute work in protm will preempt protm (itself).
+ * Preemption is not ideal, but it mainly affects itself.
+ * - Processes which do not execute work in protm, but have an active
+ * AS, will insert an empty page table (TRANSTAB) before continuing.
+ * - Continuing will potentially issue AS commands which will be
+ * ignored, but that is fine in this case.
+ * - We use the page fault handler to restore the correct page
+ * table. We should only see this once GPU have exited protm and
+ * resumed execution of normal work.
+ * - Processes with no active AS will need no further consideration,
+ * since VM ops to these will never touch the GPU HW anyway.
+ */
+
+ enum protm_block_result res;
+
+ res = panthor_sched_protm_block_timeout(vm->ptdev, vm);
+ if (res == PROTM_BLOCK_ERROR)
+ return false;
+
+ if (res == PROTM_BLOCK_DORMANT)
+ panthor_mmu_set_empty_pt(vm);
+
+ return true;
+}
+
+static void protm_unblock(struct panthor_vm *vm)
+{
+ panthor_sched_protm_unblock(vm->ptdev);
+}
+
+/* Only cond variants can be used, hence the use of WARN_ON() here */
+DEFINE_GUARD(protm_block, struct panthor_vm*, WARN_ON(_T), protm_unblock(_T));
+DEFINE_GUARD_COND(protm_block, _timeout, protm_block_timeout(_T));
+
/**
* alloc_pt() - Custom page table allocator
* @cookie: Cookie passed at page table allocation time.
@@ -475,9 +554,10 @@ static void *alloc_pt(void *cookie, size_t size, gfp_t gfp)
drm_WARN_ON(&vm->ptdev->base, vm->op_ctx);
p = alloc_pages_node(dev_to_node(vm->ptdev->base.dev),
- gfp | __GFP_ZERO, get_order(size));
+ gfp | __GFP_ZERO, get_order(size) * 2);
page = p ? page_address(p) : NULL;
vm->root_page_table = page;
+ vm->empty_transtab_offset = size;
return page;
}
@@ -1847,6 +1927,79 @@ static void panthor_vm_unlock_region(struct panthor_vm *vm)
mutex_unlock(&ptdev->mmu->as.slots_lock);
}
+static bool handle_as_fault_locked(struct panthor_device *ptdev, u32 as)
+{
+ struct panthor_mmu *mmu = ptdev->mmu;
+ struct panthor_vm *vm = mmu->as.slots[as].vm;
+ struct io_pgtable_cfg *cfg;
+ u64 actual_transtab;
+ u32 empty_transtab_low;
+ u32 cur_transtab_low;
+ int ret;
+
+ lockdep_assert_held(&ptdev->mmu->as.slots_lock);
+
+ if (!vm)
+ return false;
+
+ cfg = &io_pgtable_ops_to_pgtable(vm->pgtbl_ops)->cfg;
+ actual_transtab = cfg->arm_lpae_s1_cfg.ttbr;
+ empty_transtab_low = (u32)(actual_transtab + vm->empty_transtab_offset);
+ cur_transtab_low = gpu_read(mmu->iomem, AS_TRANSTAB(as));
+
+ if (cur_transtab_low != empty_transtab_low)
+ return false;
+
+ gpu_write(mmu->iomem, AS_TRANSTAB(as), (u32)actual_transtab);
+ ret = as_send_cmd_and_wait(ptdev, as, AS_COMMAND_UPDATE);
+
+ return ret ? false : true;
+}
+
+static void report_unhandled_as_fault_locked(struct panthor_device *ptdev, u32 as)
+{
+ struct panthor_mmu *mmu = ptdev->mmu;
+ u64 addr;
+ u32 fault_status;
+ u32 exception_type;
+ u32 access_type;
+ u32 source_id;
+
+ lockdep_assert_held(&mmu->as.slots_lock);
+
+ fault_status = gpu_read(mmu->iomem, AS_FAULTSTATUS(as));
+ addr = gpu_read64(mmu->iomem, AS_FAULTADDRESS(as));
+
+ /* decode the fault status */
+ exception_type = fault_status & 0xFF;
+ access_type = (fault_status >> 8) & 0x3;
+ source_id = (fault_status >> 16);
+
+ mmu->as.faulty_mask |= MMU_INT_AS_FAULT(as);
+
+ /* terminal fault, print info about the fault */
+ drm_err(&ptdev->base,
+ "Unhandled Page fault in AS%d at VA 0x%016llX\n"
+ "raw fault status: 0x%X\n"
+ "decoded fault status: %s\n"
+ "exception type 0x%X: %s\n"
+ "access type 0x%X: %s\n"
+ "source id 0x%X\n",
+ as, addr, fault_status,
+ (fault_status & (1 << 10) ? "DECODER FAULT" : "SLAVE FAULT"),
+ exception_type,
+ panthor_exception_name(ptdev, exception_type),
+ access_type,
+ access_type_name(ptdev, fault_status),
+ source_id);
+
+ if (mmu->as.slots[as].vm)
+ mmu->as.slots[as].vm->unhandled_fault = true;
+
+ /* Disable the MMU to kill jobs on this AS. */
+ panthor_mmu_as_disable(ptdev, as);
+}
+
static void panthor_mmu_irq_handler(struct panthor_irq *pirq, u32 status)
{
struct panthor_device *ptdev = pirq->ptdev;
@@ -1857,55 +2010,19 @@ static void panthor_mmu_irq_handler(struct panthor_irq *pirq, u32 status)
while (status) {
u32 as = ffs(status | (status >> 16)) - 1;
u32 mask = MMU_INT_AS_FAULT(as);
- u64 addr;
- u32 fault_status;
- u32 exception_type;
- u32 access_type;
- u32 source_id;
-
- fault_status = gpu_read(mmu->iomem, AS_FAULTSTATUS(as));
- addr = gpu_read64(mmu->iomem, AS_FAULTADDRESS(as));
-
- /* decode the fault status */
- exception_type = fault_status & 0xFF;
- access_type = (fault_status >> 8) & 0x3;
- source_id = (fault_status >> 16);
-
- mutex_lock(&ptdev->mmu->as.slots_lock);
-
- ptdev->mmu->as.faulty_mask |= mask;
-
- /* terminal fault, print info about the fault */
- drm_err(&ptdev->base,
- "Unhandled Page fault in AS%d at VA 0x%016llX\n"
- "raw fault status: 0x%X\n"
- "decoded fault status: %s\n"
- "exception type 0x%X: %s\n"
- "access type 0x%X: %s\n"
- "source id 0x%X\n",
- as, addr,
- fault_status,
- (fault_status & (1 << 10) ? "DECODER FAULT" : "SLAVE FAULT"),
- exception_type, panthor_exception_name(ptdev, exception_type),
- access_type, access_type_name(ptdev, fault_status),
- source_id);
-
- /* We don't handle VM faults at the moment, so let's just clear the
- * interrupt and let the writer/reader crash.
- * Note that COMPLETED irqs are never cleared, but this is fine
- * because they are always masked.
- */
- gpu_write(mmu->irq.iomem, INT_CLEAR, mask);
- if (ptdev->mmu->as.slots[as].vm)
- ptdev->mmu->as.slots[as].vm->unhandled_fault = true;
+ mutex_lock(&mmu->as.slots_lock);
+
+ if (!handle_as_fault_locked(ptdev, as)) {
+ report_unhandled_as_fault_locked(ptdev, as);
+ has_unhandled_faults = true;
+ }
+
+ gpu_write(mmu->irq.iomem, INT_CLEAR, mask);
- /* Disable the MMU to kill jobs on this AS. */
- panthor_mmu_as_disable(ptdev, as);
- mutex_unlock(&ptdev->mmu->as.slots_lock);
+ mutex_unlock(&mmu->as.slots_lock);
status &= ~mask;
- has_unhandled_faults = true;
}
if (has_unhandled_faults)
@@ -2563,12 +2680,55 @@ static struct panthor_vma *select_evicted_vma(struct drm_gpuvm_bo *vm_bo,
return first_evicted_vma;
}
+static int remap_evicted_vma_locked(struct panthor_vm *vm,
+ struct panthor_vma *evicted_vma,
+ struct panthor_vm_op_ctx *op_ctx)
+{
+ struct panthor_gem_object *bo =
+ to_panthor_bo(evicted_vma->base.gem.obj);
+ int ret;
+
+ lockdep_assert_held(&vm->op_lock);
+
+ scoped_cond_guard(protm_block_timeout, ret = -ETIMEDOUT, vm)
+ {
+ vm->op_ctx = op_ctx;
+
+ ret = panthor_vm_lock_region(vm, evicted_vma->base.va.addr,
+ evicted_vma->base.va.range);
+ if (!ret) {
+ struct drm_gpuva_op_map map_op = {
+ .va.addr = evicted_vma->base.va.addr,
+ .va.range = evicted_vma->base.va.range,
+ .gem.obj = &bo->base,
+ .gem.offset = evicted_vma->base.gem.offset,
+ };
+ if (evicted_vma->flags &
+ DRM_PANTHOR_VM_BIND_OP_MAP_SPARSE)
+ drm_WARN_ON_ONCE(&vm->ptdev->base,
+ map_op.gem.offset !=
+ (map_op.va.addr &
+ (SZ_2M - 1)));
+
+ ret = panthor_vm_exec_map_op(vm, evicted_vma->flags,
+ &map_op);
+ if (!ret)
+ evicted_vma->evicted = false;
+
+ panthor_vm_unlock_region(vm);
+ }
+
+ vm->op_ctx = NULL;
+ }
+
+ return ret;
+}
+
static int remap_evicted_vma(struct drm_gpuvm_bo *vm_bo,
struct panthor_vma *evicted_vma,
struct panthor_vm_op_ctx *op_ctx)
{
struct panthor_vm *vm = container_of(vm_bo->vm, struct panthor_vm, base);
- struct panthor_gem_object *bo = to_panthor_bo(vm_bo->obj);
struct drm_gpuva *va;
bool found = false;
int ret;
@@ -2601,31 +2761,12 @@ static int remap_evicted_vma(struct drm_gpuvm_bo *vm_bo,
break;
}
- if (found) {
- vm->op_ctx = op_ctx;
- ret = panthor_vm_lock_region(vm, evicted_vma->base.va.addr,
- evicted_vma->base.va.range);
- if (!ret) {
- struct drm_gpuva_op_map map_op = {
- .va.addr = evicted_vma->base.va.addr,
- .va.range = evicted_vma->base.va.range,
- .gem.obj = &bo->base,
- .gem.offset = evicted_vma->base.gem.offset,
- };
- if (evicted_vma->flags & DRM_PANTHOR_VM_BIND_OP_MAP_SPARSE)
- drm_WARN_ON_ONCE(&vm->ptdev->base, map_op.gem.offset !=
- (map_op.va.addr & (SZ_2M - 1)));
-
- ret = panthor_vm_exec_map_op(vm, evicted_vma->flags, &map_op);
- if (!ret)
- evicted_vma->evicted = false;
-
- panthor_vm_unlock_region(vm);
- }
+ if (!found)
+ goto out_unlock;
- vm->op_ctx = NULL;
- }
+ ret = remap_evicted_vma_locked(vm, evicted_vma, op_ctx);
+out_unlock:
mutex_unlock(&vm->op_lock);
out_cleanup:
@@ -2716,39 +2857,42 @@ panthor_vm_exec_op(struct panthor_vm *vm, struct panthor_vm_op_ctx *op,
mutex_lock(&vm->op_lock);
vm->op_ctx = op;
- ret = panthor_vm_lock_region(vm, op->va.addr, op->va.range);
- if (ret)
- goto out;
-
- switch (op_type) {
- case DRM_PANTHOR_VM_BIND_OP_TYPE_MAP: {
- const struct drm_gpuvm_map_req map_req = {
- .map.va.addr = op->va.addr,
- .map.va.range = op->va.range,
- .map.gem.obj = op->map.vm_bo->obj,
- .map.gem.offset = op->map.bo_offset,
- };
-
- if (vm->unusable) {
- ret = -EINVAL;
+ scoped_cond_guard(protm_block_timeout, ret = -ETIMEDOUT, vm) {
+ ret = panthor_vm_lock_region(vm, op->va.addr, op->va.range);
+ if (ret)
+ goto out;
+
+ switch (op_type) {
+ case DRM_PANTHOR_VM_BIND_OP_TYPE_MAP: {
+ const struct drm_gpuvm_map_req map_req = {
+ .map.va.addr = op->va.addr,
+ .map.va.range = op->va.range,
+ .map.gem.obj = op->map.vm_bo->obj,
+ .map.gem.offset = op->map.bo_offset,
+ };
+
+ if (vm->unusable) {
+ ret = -EINVAL;
+ break;
+ }
+
+ ret = drm_gpuvm_sm_map(&vm->base, vm, &map_req);
break;
}
- ret = drm_gpuvm_sm_map(&vm->base, vm, &map_req);
- break;
- }
+ case DRM_PANTHOR_VM_BIND_OP_TYPE_UNMAP:
+ ret = drm_gpuvm_sm_unmap(&vm->base, vm, op->va.addr,
+ op->va.range);
+ break;
- case DRM_PANTHOR_VM_BIND_OP_TYPE_UNMAP:
- ret = drm_gpuvm_sm_unmap(&vm->base, vm, op->va.addr, op->va.range);
- break;
+ default:
+ ret = -EINVAL;
+ break;
+ }
- default:
- ret = -EINVAL;
- break;
+ panthor_vm_unlock_region(vm);
}
- panthor_vm_unlock_region(vm);
-
out:
if (ret && flag_vm_unusable_on_failure)
panthor_vm_declare_unusable(vm);
@@ -3558,3 +3702,18 @@ void panthor_mmu_pt_cache_fini(void)
{
kmem_cache_destroy(pt_cache);
}
+
+bool panthor_vm_for_mcu(struct panthor_vm *vm)
+{
+ return vm->for_mcu;
+}
+
+void panthor_vm_protm_enter(struct panthor_vm *vm)
+{
+ panthor_vm_stop(vm);
+}
+
+void panthor_vm_protm_exit(struct panthor_vm *vm)
+{
+ panthor_vm_start(vm);
+}
diff --git a/drivers/gpu/drm/panthor/panthor_mmu.h b/drivers/gpu/drm/panthor/panthor_mmu.h
index e262fe2303f6c..a6ff21d9a0201 100644
--- a/drivers/gpu/drm/panthor/panthor_mmu.h
+++ b/drivers/gpu/drm/panthor/panthor_mmu.h
@@ -106,6 +106,11 @@ void panthor_vm_update_resvs(struct panthor_vm *vm, struct drm_exec *exec,
int panthor_mmu_pt_cache_init(void);
void panthor_mmu_pt_cache_fini(void);
+bool panthor_vm_for_mcu(struct panthor_vm *vm);
+
+void panthor_vm_protm_enter(struct panthor_vm *vm);
+void panthor_vm_protm_exit(struct panthor_vm *vm);
+
#ifdef CONFIG_DEBUG_FS
void panthor_mmu_debugfs_init(struct drm_minor *minor);
#endif
diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c
index e67fd0fe20144..ca6aa6a55661a 100644
--- a/drivers/gpu/drm/panthor/panthor_sched.c
+++ b/drivers/gpu/drm/panthor/panthor_sched.c
@@ -307,6 +307,44 @@ struct panthor_scheduler {
*/
struct list_head stopped_groups;
} reset;
+
+ /** @protm: Protected mode related fields. */
+ struct {
+ /**
+ * @protm.lock: Lock for the protected mode state (active_group)
+ *
+ * This lock is used to manage current protected mode state,
+ * as represented by the member active_group.
+ *
+ * Knowing this state is critical for MMU operations, because:
+ * - The MMU will silently ignore commands issued when the GPU
+ * is in protected mode.
+ * - There can not be any pending MMU LOCKS in place when
+ * entering protected mode.
+ *
+ * Code which interacts with the MMU, typically by calling
+ * panthor_vm_lock_region(), should therefore ensure the
+ * scheduler is not in and will not enter protected mode first.
+ * This is done by calling panthor_sched_protm_block_timeout().
+ *
+ * Once the MMU operations have completed, call
+ * panthor_sched_protm_unblock() to tell the scheduler that
+ * it is safe to enter protected mode again.
+ */
+ struct rw_semaphore lock;
+
+ /**
+ * @protm.active_group: The active protected group.
+ *
+ * We only allow one protected group to run at the same time,
+ * as it makes it easier to handle faults in protected mode.
+ *
+ * If the active_group member is set, then the scheduler
+ * believes the GPU is in protected mode. If not set, then the
+ * GPU is for sure not in normal mode.
+ */
+ struct panthor_group *active_group;
+ } protm;
};
/**
@@ -571,6 +609,16 @@ struct panthor_group {
*/
atomic_t fatal_queues;
+ /**
+ * @protm_pending_queues: Bitmask reflecting the queues that have raised
+ * a CS_PROTM_PENDING.
+ *
+ * The GPU will set the bit associated to the queue pending protected
+ * mode when a PROT_REGION command is executing or when trying to resume
+ * previously suspended protected mode jobs.
+ */
+ atomic_t protm_pending_queues;
+
/** @tiler_oom: Mask of queues that have a tiler OOM event to process. */
atomic_t tiler_oom;
@@ -1154,8 +1202,9 @@ cs_slot_reset_locked(struct panthor_device *ptdev, u32 csg_id, u32 cs_id)
lockdep_assert_held(&ptdev->scheduler->lock);
panthor_fw_update_reqs(cs_iface, req,
- CS_STATE_STOP,
- CS_STATE_MASK);
+ CS_STATE_STOP |
+ (cs_iface->output->ack & CS_PROTM_PENDING),
+ CS_STATE_MASK | CS_PROTM_PENDING);
queue_suspend_timeout(queue);
@@ -1394,6 +1443,27 @@ csg_slot_prog_locked(struct panthor_device *ptdev, u32 csg_id, u32 priority)
return 0;
}
+static void
+cs_slot_process_protm_pending_event_locked(struct panthor_device *ptdev,
+ u32 csg_id, u32 cs_id)
+{
+ struct panthor_scheduler *sched = ptdev->scheduler;
+ struct panthor_csg_slot *csg_slot = &sched->csg_slots[csg_id];
+ struct panthor_group *group = csg_slot->group;
+
+ lockdep_assert_held(&sched->events_lock);
+
+ if (!group)
+ return;
+
+ /* Do not allow user space work to switch into protected mode, as we
+ * do not fully support this quite yet.
+ */
+ atomic_or(BIT(cs_id), &group->fatal_queues);
+
+ sched_queue_delayed_work(sched, tick, 0);
+}
+
static void
cs_slot_process_fatal_event_locked(struct panthor_device *ptdev,
u32 csg_id, u32 cs_id)
@@ -1642,6 +1712,9 @@ static bool cs_slot_process_irq_locked(struct panthor_device *ptdev,
if (events & CS_TILER_OOM)
cs_slot_process_tiler_oom_event_locked(ptdev, csg_id, cs_id);
+ if (events & CS_PROTM_PENDING)
+ cs_slot_process_protm_pending_event_locked(ptdev, csg_id, cs_id);
+
/* We don't acknowledge the TILER_OOM event since its handling is
* deferred to a separate work.
*/
@@ -1856,6 +1929,30 @@ static void sched_process_idle_event_locked(struct panthor_device *ptdev)
sched_queue_delayed_work(ptdev->scheduler, tick, 0);
}
+static void sched_process_protm_exit_event_locked(struct panthor_device *ptdev)
+{
+ struct panthor_fw_global_iface *glb_iface =
+ panthor_fw_get_glb_iface(ptdev);
+ struct panthor_scheduler *sched = ptdev->scheduler;
+
+ lockdep_assert_held(&sched->events_lock);
+
+ atomic64_inc(&ptdev->protm.protm_exit_count);
+
+ /* Acknowledge the protm exit */
+ panthor_fw_update_reqs(glb_iface, req, glb_iface->output->ack,
+ GLB_PROTM_EXIT);
+
+ /* If there are pending fault from protected mode execution, then early
+ * out here. The GPU_IRQ_PROTM_FAULT handling will trigger the propper
+ * error recovery via a GPU reset.
+ */
+ if (panthor_gpu_protm_fault_pending(ptdev))
+ return;
+
+ sched_queue_delayed_work(sched, tick, 0);
+}
+
/**
* sched_process_global_irq_locked() - Process the scheduling part of a global IRQ
* @ptdev: Device.
@@ -1871,6 +1968,9 @@ static void sched_process_global_irq_locked(struct panthor_device *ptdev)
ack = READ_ONCE(glb_iface->output->ack);
evts = (req ^ ack) & GLB_EVT_MASK;
+ if (evts & GLB_PROTM_EXIT)
+ sched_process_protm_exit_event_locked(ptdev);
+
if (evts & GLB_IDLE)
sched_process_idle_event_locked(ptdev);
}
@@ -1882,22 +1982,22 @@ static void sched_process_global_irq_locked(struct panthor_device *ptdev)
*/
void panthor_sched_report_fw_events(struct panthor_device *ptdev, u32 events)
{
+ u32 csg_events = events & ~JOB_INT_GLOBAL_IF;
+
if (!ptdev->scheduler)
return;
guard(spinlock)(&ptdev->scheduler->events_lock);
- if (events & JOB_INT_GLOBAL_IF) {
- sched_process_global_irq_locked(ptdev);
- events &= ~JOB_INT_GLOBAL_IF;
- }
-
- while (events) {
- u32 csg_id = ffs(events) - 1;
+ while (csg_events) {
+ u32 csg_id = ffs(csg_events) - 1;
sched_process_csg_irq_locked(ptdev, csg_id);
- events &= ~BIT(csg_id);
+ csg_events &= ~BIT(csg_id);
}
+
+ if (events & JOB_INT_GLOBAL_IF)
+ sched_process_global_irq_locked(ptdev);
}
/**
@@ -1983,6 +2083,66 @@ group_unbind_locked(struct panthor_group *group)
return 0;
}
+static void handle_protm_fault(struct panthor_device *ptdev)
+{
+ struct panthor_scheduler *sched = ptdev->scheduler;
+ u32 csg_id;
+ struct panthor_group *protm_group;
+
+ protm_group = sched->protm.active_group;
+
+ if (!protm_group || !panthor_gpu_protm_fault_pending(ptdev))
+ return;
+
+ atomic_set(&protm_group->fatal_queues,
+ GENMASK(protm_group->queue_count - 1, 0));
+
+ /* Different kinds of faults during protected mode can give different
+ * behavior/state.
+ * Case 1) The fault keeps the GPU in protected mode.
+ * In this case, the request to exit protected mode below will
+ * fail and we need to take some further action.
+ * Case 2) The fault do not keep the GPU in protected mode.
+ * In this case, the request to exit protected
+ * mode below will succeed, and we don't need to take any
+ * further action right here.
+ */
+ if (!panthor_fw_protm_exit(ptdev, 500))
+ return;
+
+ /* GPU failed to exit protected mode.
+ * Mark all CSGs as suspended and unbind them, so that they are
+ * unaffected by the GPU reset itself.
+ * We can not suspend the groups in this case, because we are stuck
+ * in protected mode. That is also the reason it is safe to unbind
+ * without suspending first (the groups are already "suspended").
+ * The failing protected group will be scheduled for termination.
+ */
+ for (csg_id = 0; csg_id < sched->csg_slot_count; csg_id++) {
+ struct panthor_group *group = sched->csg_slots[csg_id].group;
+
+ if (!group)
+ continue;
+
+ group_get(group);
+
+ group->state = PANTHOR_CS_GROUP_SUSPENDED;
+ group_unbind_locked(group);
+
+ drm_WARN_ON(&group->ptdev->base, !list_empty(&group->run_node));
+
+ if (group_can_run(group)) {
+ list_add(&group->run_node,
+ &sched->groups.idle[group->priority]);
+ } else {
+ list_del_init(&group->wait_node);
+ group_queue_work(group, term);
+ }
+
+ group_put(group);
+ }
+}
+
static const char *fence_get_driver_name(struct dma_fence *fence)
{
return "panthor";
@@ -2012,6 +2172,12 @@ static void csgs_upd_ctx_init(struct panthor_csg_slots_upd_ctx *ctx)
memset(ctx, 0, sizeof(*ctx));
}
+static void csgs_upd_ctx_ring_doorbell(struct panthor_csg_slots_upd_ctx *ctx,
+ u32 csg_id)
+{
+ ctx->update_mask |= BIT(csg_id);
+}
+
static void csgs_upd_ctx_queue_reqs(struct panthor_device *ptdev,
struct panthor_csg_slots_upd_ctx *ctx,
u32 csg_id, u32 value, u32 mask)
@@ -2022,7 +2188,8 @@ static void csgs_upd_ctx_queue_reqs(struct panthor_device *ptdev,
ctx->requests[csg_id].value = (ctx->requests[csg_id].value & ~mask) | (value & mask);
ctx->requests[csg_id].mask |= mask;
- ctx->update_mask |= BIT(csg_id);
+
+ csgs_upd_ctx_ring_doorbell(ctx, csg_id);
}
static int csgs_upd_ctx_apply_locked(struct panthor_device *ptdev,
@@ -2039,8 +2206,12 @@ static int csgs_upd_ctx_apply_locked(struct panthor_device *ptdev,
while (update_slots) {
struct panthor_fw_csg_iface *csg_iface;
u32 csg_id = ffs(update_slots) - 1;
+ u32 req_mask = ctx->requests[csg_id].mask;
update_slots &= ~BIT(csg_id);
+ if (!req_mask)
+ continue;
+
csg_iface = panthor_fw_get_csg_iface(ptdev, csg_id);
panthor_fw_update_reqs(csg_iface, req,
ctx->requests[csg_id].value,
@@ -2057,6 +2228,9 @@ static int csgs_upd_ctx_apply_locked(struct panthor_device *ptdev,
int ret;
update_slots &= ~BIT(csg_id);
+ if (!req_mask)
+ continue;
+
csg_iface = panthor_fw_get_csg_iface(ptdev, csg_id);
ret = panthor_fw_csg_wait_acks(ptdev, csg_id, req_mask, &acked, 100);
@@ -2093,6 +2267,7 @@ struct panthor_sched_tick_ctx {
bool immediate_tick;
bool stop_tick;
u32 csg_upd_failed_mask;
+ struct panthor_group *protm_group;
};
static bool
@@ -2134,6 +2309,13 @@ tick_ctx_pick_groups_from_list(const struct panthor_scheduler *sched,
if (!owned_by_tick_ctx)
group_get(group);
+ /* Only the first pick is allowed to request switch to protm */
+ if (ctx->group_count == 0 &&
+ atomic_read(&group->protm_pending_queues)) {
+ ctx->protm_group = group;
+ ctx->stop_tick = false;
+ }
+
ctx->group_count++;
/* If we have more than one active group with the same priority,
@@ -2292,6 +2474,55 @@ static void group_term_work(struct work_struct *work)
group_put(group);
}
+enum protm_block_result
+panthor_sched_protm_block_timeout(struct panthor_device *ptdev,
+ struct panthor_vm *vm)
+{
+ struct panthor_scheduler *sched = ptdev->scheduler;
+ int ret;
+
+ if (!sched)
+ return PROTM_BLOCK_NORMAL;
+
+ down_read(&sched->protm.lock);
+
+ if (!sched->protm.active_group)
+ return PROTM_BLOCK_NORMAL; /* All good, we are in normal mode */
+
+ /* We will only exit protected mode for the passed vm and the MCU VM.
+ * Other VMs have no active CSG work, so MMU updates can proceed,
+ * although with special caution (delayed updates)!
+ */
+ if (sched->protm.active_group->vm != vm && !panthor_vm_for_mcu(vm))
+ return PROTM_BLOCK_DORMANT; /* Specified VM can proceed, with caution. */
+
+ /* Give GPU a chance to finish ongoing protm work by itself */
+ ret = panthor_fw_protm_exit_wait(ptdev, 5);
+ if (!ret)
+ return PROTM_BLOCK_NORMAL; /* All good, we are back to normal mode */
+
+ /* We do not want this function to fail, because that can lead to
+ * innocent processes failing. That is why we wait up to 2x the job
+ * timeout for GPU to exit protm here. This shall cover the worst case
+ * where protm work hangs and we must rely on job timeout to recover.
+ */
+ ret = panthor_fw_protm_exit(ptdev, JOB_TIMEOUT_MS << 1);
+ if (ret)
+ up_read(&sched->protm.lock);
+
+ return ret ? PROTM_BLOCK_ERROR : PROTM_BLOCK_NORMAL;
+}
+
+void panthor_sched_protm_unblock(struct panthor_device *ptdev)
+{
+ struct panthor_scheduler *sched = ptdev->scheduler;
+
+ if (!sched)
+ return;
+
+ up_read(&sched->protm.lock);
+}
+
static void
tick_ctx_cleanup(struct panthor_scheduler *sched,
struct panthor_sched_tick_ctx *ctx)
@@ -2419,6 +2650,41 @@ tick_ctx_schedule_group(struct panthor_scheduler *sched,
return 0;
}
+static void
+tick_ctx_handle_protm_group(struct panthor_scheduler *sched,
+ struct panthor_csg_slots_upd_ctx *upd_ctx,
+ struct panthor_group *group)
+{
+ struct panthor_device *ptdev = sched->ptdev;
+ struct panthor_fw_csg_iface *csg_iface =
+ panthor_fw_get_csg_iface(ptdev, group->csg_id);
+ u32 q;
+
+ if (drm_WARN_ON(&ptdev->base, group->csg_id < 0))
+ return;
+
+ guard(spinlock)(&sched->events_lock);
+
+ for (q = 0; q < group->queue_count; q++) {
+ struct panthor_fw_cs_iface *cs_iface =
+ panthor_fw_get_cs_iface(ptdev, group->csg_id, q);
+
+ /* Ack any pending CS_PROTM_PENDING so it can run in protm */
+ if ((cs_iface->output->ack ^ cs_iface->input->req) &
+ CS_PROTM_PENDING)
+ panthor_fw_update_reqs(cs_iface, req,
+ cs_iface->output->ack,
+ CS_PROTM_PENDING);
+ }
+
+ panthor_fw_toggle_reqs(csg_iface, doorbell_req, doorbell_ack,
+ GENMASK(group->queue_count - 1, 0));
+
+ csgs_upd_ctx_ring_doorbell(upd_ctx, group->csg_id);
+
+ atomic_set(&group->protm_pending_queues, 0);
+}
+
static void
tick_ctx_apply(struct panthor_scheduler *sched, struct panthor_sched_tick_ctx *ctx)
{
@@ -2488,6 +2754,9 @@ tick_ctx_apply(struct panthor_scheduler *sched, struct panthor_sched_tick_ctx *c
}
}
+ if (ctx->protm_group)
+ tick_ctx_handle_protm_group(sched, &upd_ctx, ctx->protm_group);
+
ret = csgs_upd_ctx_apply_locked(ptdev, &upd_ctx);
if (ret) {
panthor_device_schedule_reset(ptdev);
@@ -2495,6 +2764,23 @@ tick_ctx_apply(struct panthor_scheduler *sched, struct panthor_sched_tick_ctx *c
return;
}
+ if (ctx->protm_group) {
+ down_write(&sched->protm.lock);
+
+ sched->protm.active_group = ctx->protm_group;
+ group_get(sched->protm.active_group);
+
+ panthor_vm_protm_enter(ctx->protm_group->vm);
+
+ ret = panthor_fw_protm_enter(ptdev);
+ if (ret) {
+ panthor_device_schedule_reset(ptdev);
+ ctx->csg_upd_failed_mask = U32_MAX;
+ }
+
+ up_write(&sched->protm.lock);
+ }
+
for (prio = PANTHOR_CSG_PRIORITY_COUNT - 1; prio >= 0; prio--) {
list_for_each_entry_safe(group, tmp, &ctx->groups[prio], run_node) {
list_del_init(&group->run_node);
@@ -2531,12 +2817,12 @@ tick_ctx_apply(struct panthor_scheduler *sched, struct panthor_sched_tick_ctx *c
}
static u64
-tick_ctx_update_resched_target(struct panthor_scheduler *sched,
- const struct panthor_sched_tick_ctx *ctx)
+tick_update_resched_target(struct panthor_scheduler *sched,
+ bool stop_tick)
{
u64 resched_target;
- if (ctx->stop_tick)
+ if (stop_tick)
goto no_tick;
resched_target = sched->last_tick + sched->tick_period;
@@ -2552,6 +2838,38 @@ tick_ctx_update_resched_target(struct panthor_scheduler *sched,
return U64_MAX;
}
+static bool preempt_protm_group(struct panthor_group *group, bool full_tick)
+{
+ struct panthor_device *ptdev = group->ptdev;
+ struct panthor_scheduler *sched = ptdev->scheduler;
+ bool groups_waiting;
+
+ /* If the protm group can not run, then preempt! */
+ if (!group_can_run(group))
+ return true;
+
+ /* If we have RT groups waiting and we are not RT, then preempt! */
+ groups_waiting =
+ !list_empty(&sched->groups.runnable[PANTHOR_CSG_PRIORITY_RT]);
+ if (groups_waiting && group->priority < PANTHOR_CSG_PRIORITY_RT)
+ return true;
+
+ /* The below conditions for preempting are only valid for full ticks */
+ if (!full_tick)
+ return false;
+
+ for (int pri = PANTHOR_CSG_PRIORITY_RT - 1;
+ pri >= sched->protm.active_group->priority; pri--) {
+ if (!list_empty(&sched->groups.runnable[pri])) {
+ groups_waiting = true;
+ break;
+ }
+ }
+
+ return groups_waiting;
+
+}
+
static void tick_work(struct work_struct *work)
{
struct panthor_scheduler *sched = container_of(work, struct panthor_scheduler,
@@ -2584,6 +2902,54 @@ static void tick_work(struct work_struct *work)
if (panthor_device_reset_is_pending(sched->ptdev))
goto out_unlock;
+ /* If we exited protm since last tick, then deal with that first */
+ if (sched->protm.active_group) {
+ bool protm = atomic64_read(&ptdev->protm.protm_exit_count) !=
+ atomic64_read(&ptdev->protm.protm_enter_count);
+ if (!protm) {
+ /* No longer in protected mode, clear active_group */
+ down_write(&sched->protm.lock);
+ panthor_vm_protm_exit(sched->protm.active_group->vm);
+ group_put(sched->protm.active_group);
+ sched->protm.active_group = NULL;
+ up_write(&sched->protm.lock);
+ }
+ }
+
+ if (sched->protm.active_group) {
+ /* A normal tick will issue CSG_STATUS_UPDATE requests in
+ * tick_ctx_init(). If we do this while running in protm, then
+ * the FW will preempt and exit protm in order to fullfill the
+ * request. That is why we do a "SW only" check for preemption
+ * in this case, so we avoid unnecessary preemption.
+ */
+ if (preempt_protm_group(sched->protm.active_group, full_tick)) {
+ /* Ensure we are fully out of protected mode first.
+ * We rely on the GLB_PROTM_EXIT (or error recovery)
+ * to get a new tick.
+ */
+ if (panthor_fw_protm_exit(ptdev, 500)) {
+ drm_warn(&ptdev->base,
+ "Failed to preempt protm");
+ panthor_device_schedule_reset(ptdev);
+ }
+ } else {
+ sched->last_tick = now;
+
+ /* We can stop ticking if this was a full tick.
+ * New work which can preempt this protm work will
+ * generate new ticks.
+ */
+ resched_delay =
+ tick_update_resched_target(sched, full_tick);
+ if (resched_delay != U64_MAX)
+ sched_queue_delayed_work(sched, tick,
+ resched_delay);
+ }
+
+ goto out_unlock;
+ }
+
tick_ctx_init(sched, &ctx);
if (ctx.csg_upd_failed_mask)
goto out_cleanup_ctx;
@@ -2635,14 +3001,30 @@ static void tick_work(struct work_struct *work)
}
}
- /* If we have free CSG slots left, pick idle groups */
- for (prio = PANTHOR_CSG_PRIORITY_COUNT - 1;
- prio >= 0 && !tick_ctx_is_full(sched, &ctx);
- prio--) {
- /* Check the old_group queue first to avoid reprogramming the slots */
- tick_ctx_pick_groups_from_list(sched, &ctx, &ctx.old_groups[prio], false, true);
- tick_ctx_pick_groups_from_list(sched, &ctx, &sched->groups.idle[prio],
- false, false);
+ if (ctx.protm_group) {
+ /* Pick only idle groups with equal or lower priority than the
+ * group triggering protected mode. Do not bother picking
+ * unscheduled idle groups.
+ */
+ for (prio = ctx.protm_group->priority;
+ prio >= 0 && !tick_ctx_is_full(sched, &ctx); prio--) {
+ tick_ctx_pick_groups_from_list(sched, &ctx,
+ &ctx.old_groups[prio],
+ false, true);
+ }
+ } else {
+ for (prio = PANTHOR_CSG_PRIORITY_COUNT - 1;
+ prio >= 0 && !tick_ctx_is_full(sched, &ctx); prio--) {
+ /* Check the old_group queue first to avoid
+ * reprogramming the slots
+ */
+ tick_ctx_pick_groups_from_list(sched, &ctx,
+ &ctx.old_groups[prio],
+ false, true);
+ tick_ctx_pick_groups_from_list(sched, &ctx,
+ &sched->groups.idle[prio],
+ false, false);
+ }
}
tick_ctx_apply(sched, &ctx);
@@ -2664,7 +3046,7 @@ static void tick_work(struct work_struct *work)
}
sched->last_tick = now;
- resched_delay = tick_ctx_update_resched_target(sched, &ctx);
+ resched_delay = tick_update_resched_target(sched, ctx.stop_tick);
if (ctx.immediate_tick)
resched_delay = 0;
@@ -3069,6 +3451,8 @@ void panthor_sched_pre_reset(struct panthor_device *ptdev)
cancel_work_sync(&sched->sync_upd_work);
cancel_delayed_work_sync(&sched->tick_work);
+ handle_protm_fault(ptdev);
+
panthor_sched_suspend(ptdev);
/* Stop all groups that might still accept jobs, so we don't get passed
@@ -3094,6 +3478,13 @@ void panthor_sched_post_reset(struct panthor_device *ptdev, bool reset_failed)
mutex_lock(&sched->reset.lock);
+ down_write(&sched->protm.lock);
+ if (sched->protm.active_group) {
+ group_put(sched->protm.active_group);
+ sched->protm.active_group = NULL;
+ }
+ up_write(&sched->protm.lock);
+
list_for_each_entry_safe(group, group_tmp, &sched->reset.stopped_groups, run_node) {
/* Consider all previously running group as terminated if the
* reset failed.
@@ -4170,6 +4561,7 @@ int panthor_sched_init(struct panthor_device *ptdev)
INIT_WORK(&sched->sync_upd_work, sync_upd_work);
spin_lock_init(&sched->events_lock);
+ init_rwsem(&sched->protm.lock);
ret = drmm_mutex_init(&ptdev->base, &sched->lock);
if (ret)
diff --git a/drivers/gpu/drm/panthor/panthor_sched.h b/drivers/gpu/drm/panthor/panthor_sched.h
index c509fcb5a0c9c..91c4277f1e551 100644
--- a/drivers/gpu/drm/panthor/panthor_sched.h
+++ b/drivers/gpu/drm/panthor/panthor_sched.h
@@ -53,6 +53,22 @@ void panthor_sched_report_fw_events(struct panthor_device *ptdev, u32 events);
void panthor_fdinfo_gather_group_samples(struct drm_file *file);
+enum protm_block_result {
+ /* GPU is currently, and will stay, in normal mode */
+ PROTM_BLOCK_NORMAL,
+
+ /* GPU might be in protected mode serving another vm */
+ PROTM_BLOCK_DORMANT,
+
+ /* GPU error */
+ PROTM_BLOCK_ERROR
+};
+
+enum protm_block_result
+panthor_sched_protm_block_timeout(struct panthor_device *ptdev,
+ struct panthor_vm *vm);
+void panthor_sched_protm_unblock(struct panthor_device *ptdev);
+
#ifdef CONFIG_DEBUG_FS
void panthor_sched_debugfs_init(struct drm_minor *minor);
#endif
--
2.43.0
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH v5 06/13] drm/panthor: New function for FW section map flags
2026-11-16 11:25 [PATCH v5 00/13] drm/panthor: Protected mode support for Mali CSF GPUs Ketil Johnsen
` (4 preceding siblings ...)
2026-11-16 11:25 ` [PATCH v5 05/13] drm/panthor: Add support for entering and exiting protected mode Ketil Johnsen
@ 2026-11-16 11:25 ` Ketil Johnsen
2026-11-16 11:25 ` [PATCH v5 07/13] drm/panthor: Keep size and VA in FW section obj Ketil Johnsen
` (6 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Ketil Johnsen @ 2026-11-16 11:25 UTC (permalink / raw)
To: Boris Brezillon, Steven Price, Liviu Dudau, Akash Goel,
Karunika Choo, Lukas Zapolskas, Chris Diamand, Maarten Lankhorst,
Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter,
Daniel Almeida, Alice Ryhl
Cc: dri-devel, linux-kernel, rust-for-linux, Ketil Johnsen
From: Boris Brezillon <boris.brezillon@collabora.com>
This refactors the VM map flags for FW sections into a new function
called section_vm_map_flags().
This comes in handly for future handling of protected FW sections
(type CSF_FW_BINARY_IFACE_ENTRY_PROT).
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Co-developed-by: Ketil Johnsen <ketil.johnsen@arm.com>
Signed-off-by: Ketil Johnsen <ketil.johnsen@arm.com>
---
v4:
- First version of this change as a separate commit
---
drivers/gpu/drm/panthor/panthor_fw.c | 44 ++++++++++++++++------------
1 file changed, 26 insertions(+), 18 deletions(-)
diff --git a/drivers/gpu/drm/panthor/panthor_fw.c b/drivers/gpu/drm/panthor/panthor_fw.c
index e639ffeac7a32..7b8c90b19f4fe 100644
--- a/drivers/gpu/drm/panthor/panthor_fw.c
+++ b/drivers/gpu/drm/panthor/panthor_fw.c
@@ -543,6 +543,31 @@ panthor_fw_alloc_suspend_buf_mem(struct panthor_device *ptdev, size_t size)
"FW suspend buffer");
}
+static u32 section_vm_map_flags(const struct panthor_fw_section *section)
+{
+ u32 cache_mode = section->flags &
+ CSF_FW_BINARY_IFACE_ENTRY_CACHE_MODE_MASK;
+ u32 vm_map_flags = 0;
+
+ if (!(section->flags & CSF_FW_BINARY_IFACE_ENTRY_WR))
+ vm_map_flags |= DRM_PANTHOR_VM_BIND_OP_MAP_READONLY;
+
+ if (!(section->flags & CSF_FW_BINARY_IFACE_ENTRY_EX))
+ vm_map_flags |= DRM_PANTHOR_VM_BIND_OP_MAP_NOEXEC;
+
+ /* TODO: CSF_FW_BINARY_IFACE_ENTRY_CACHE_MODE_*_COHERENT are mapped to
+ * non-cacheable for now. We might want to introduce a new
+ * IOMMU_xxx flag (or abuse IOMMU_MMIO, which maps to device
+ * memory and is currently not used by our driver) for
+ * AS_MEMATTR_AARCH64_SHARED memory, so we can take benefit
+ * of IO-coherent systems.
+ */
+ if (cache_mode != CSF_FW_BINARY_IFACE_ENTRY_CACHE_MODE_CACHED)
+ vm_map_flags |= DRM_PANTHOR_VM_BIND_OP_MAP_UNCACHED;
+
+ return vm_map_flags;
+}
+
static int panthor_fw_load_section_entry(struct panthor_device *ptdev,
const struct firmware *fw,
struct panthor_fw_binary_iter *iter,
@@ -645,26 +670,9 @@ static int panthor_fw_load_section_entry(struct panthor_device *ptdev,
}
if (section_size) {
- u32 cache_mode = hdr.flags & CSF_FW_BINARY_IFACE_ENTRY_CACHE_MODE_MASK;
- u32 vm_map_flags = 0;
+ u32 vm_map_flags = section_vm_map_flags(section);
u64 va = hdr.va.start;
- if (!(hdr.flags & CSF_FW_BINARY_IFACE_ENTRY_WR))
- vm_map_flags |= DRM_PANTHOR_VM_BIND_OP_MAP_READONLY;
-
- if (!(hdr.flags & CSF_FW_BINARY_IFACE_ENTRY_EX))
- vm_map_flags |= DRM_PANTHOR_VM_BIND_OP_MAP_NOEXEC;
-
- /* TODO: CSF_FW_BINARY_IFACE_ENTRY_CACHE_MODE_*_COHERENT are mapped to
- * non-cacheable for now. We might want to introduce a new
- * IOMMU_xxx flag (or abuse IOMMU_MMIO, which maps to device
- * memory and is currently not used by our driver) for
- * AS_MEMATTR_AARCH64_SHARED memory, so we can take benefit
- * of IO-coherent systems.
- */
- if (cache_mode != CSF_FW_BINARY_IFACE_ENTRY_CACHE_MODE_CACHED)
- vm_map_flags |= DRM_PANTHOR_VM_BIND_OP_MAP_UNCACHED;
-
section->mem = panthor_kernel_bo_create(ptdev, panthor_fw_vm(ptdev),
section_size,
DRM_PANTHOR_BO_NO_MMAP,
--
2.43.0
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH v5 07/13] drm/panthor: Keep size and VA in FW section obj
2026-11-16 11:25 [PATCH v5 00/13] drm/panthor: Protected mode support for Mali CSF GPUs Ketil Johnsen
` (5 preceding siblings ...)
2026-11-16 11:25 ` [PATCH v5 06/13] drm/panthor: New function for FW section map flags Ketil Johnsen
@ 2026-11-16 11:25 ` Ketil Johnsen
2026-11-16 11:25 ` [PATCH v5 08/13] drm/panthor: Refactor GEM usage flags assignment Ketil Johnsen
` (5 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Ketil Johnsen @ 2026-11-16 11:25 UTC (permalink / raw)
To: Boris Brezillon, Steven Price, Liviu Dudau, Akash Goel,
Karunika Choo, Lukas Zapolskas, Chris Diamand, Maarten Lankhorst,
Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter,
Daniel Almeida, Alice Ryhl
Cc: dri-devel, linux-kernel, rust-for-linux, Ketil Johnsen
From: Boris Brezillon <boris.brezillon@collabora.com>
Keep a copy of the FW section size and VA in the
panthor_fw_section object. We need this in the future when handling
late init of protected memory for FW sections of type
CSF_FW_BINARY_IFACE_ENTRY_PROT.
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Co-developed-by: Ketil Johnsen <ketil.johnsen@arm.com>
Signed-off-by: Ketil Johnsen <ketil.johnsen@arm.com>
---
v4:
- First version of this change as a separate commit
---
drivers/gpu/drm/panthor/panthor_fw.c | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/drivers/gpu/drm/panthor/panthor_fw.c b/drivers/gpu/drm/panthor/panthor_fw.c
index 7b8c90b19f4fe..fc07796fc9ef7 100644
--- a/drivers/gpu/drm/panthor/panthor_fw.c
+++ b/drivers/gpu/drm/panthor/panthor_fw.c
@@ -198,6 +198,12 @@ struct panthor_fw_section {
/** @size: Size of @buf in bytes. */
size_t size;
} data;
+
+ /** @size: Section size. */
+ size_t size;
+
+ /** @va: Section VA. */
+ u32 va;
};
#define CSF_MCU_SHARED_REGION_START 0x04000000ULL
@@ -669,18 +675,21 @@ static int panthor_fw_load_section_entry(struct panthor_device *ptdev,
section->name = name;
}
+ section->size = section_size;
+ section->va = hdr.va.start;
+
if (section_size) {
u32 vm_map_flags = section_vm_map_flags(section);
- u64 va = hdr.va.start;
- section->mem = panthor_kernel_bo_create(ptdev, panthor_fw_vm(ptdev),
- section_size,
- DRM_PANTHOR_BO_NO_MMAP,
- vm_map_flags, va, "FW section");
+ section->mem = panthor_kernel_bo_create(
+ ptdev, panthor_fw_vm(ptdev), section->size,
+ DRM_PANTHOR_BO_NO_MMAP, vm_map_flags, section->va,
+ "FW section");
if (IS_ERR(section->mem))
return PTR_ERR(section->mem);
- if (drm_WARN_ON(&ptdev->base, section->mem->va_node.start != hdr.va.start))
+ if (drm_WARN_ON(&ptdev->base,
+ section->mem->va_node.start != section->va))
return -EINVAL;
if (section->flags & CSF_FW_BINARY_IFACE_ENTRY_SHARED) {
--
2.43.0
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH v5 08/13] drm/panthor: Refactor GEM usage flags assignment
2026-11-16 11:25 [PATCH v5 00/13] drm/panthor: Protected mode support for Mali CSF GPUs Ketil Johnsen
` (6 preceding siblings ...)
2026-11-16 11:25 ` [PATCH v5 07/13] drm/panthor: Keep size and VA in FW section obj Ketil Johnsen
@ 2026-11-16 11:25 ` Ketil Johnsen
2026-11-16 11:25 ` [PATCH v5 09/13] drm/panthor: Create kernel BO from existing GEM Ketil Johnsen
` (4 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Ketil Johnsen @ 2026-11-16 11:25 UTC (permalink / raw)
To: Boris Brezillon, Steven Price, Liviu Dudau, Akash Goel,
Karunika Choo, Lukas Zapolskas, Chris Diamand, Maarten Lankhorst,
Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter,
Daniel Almeida, Alice Ryhl
Cc: dri-devel, linux-kernel, rust-for-linux, Ketil Johnsen
From: Boris Brezillon <boris.brezillon@collabora.com>
Changes panthor_gem_debugfs_set_usage_flags() to
panthor_gem_debugfs_add_usage_flags(). This will come in handy in a
later change when we split panthor_kernel_bo_create() to also handle
protected memory.
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Co-developed-by: Ketil Johnsen <ketil.johnsen@arm.com>
Signed-off-by: Ketil Johnsen <ketil.johnsen@arm.com>
---
v5:
- Minor formating fixes.
v4:
- First version of this change as a separate commit
---
drivers/gpu/drm/panthor/panthor_gem.c | 13 +++++++------
drivers/gpu/drm/panthor/panthor_gem.h | 2 +-
2 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/drivers/gpu/drm/panthor/panthor_gem.c b/drivers/gpu/drm/panthor/panthor_gem.c
index 22b57ab6f9291..5d0eb31746164 100644
--- a/drivers/gpu/drm/panthor/panthor_gem.c
+++ b/drivers/gpu/drm/panthor/panthor_gem.c
@@ -74,14 +74,14 @@ static void panthor_gem_debugfs_bo_rm(struct panthor_gem_object *bo)
mutex_unlock(&ptdev->gems.lock);
}
-static void panthor_gem_debugfs_set_usage_flags(struct panthor_gem_object *bo, u32 usage_flags)
+static void panthor_gem_debugfs_add_usage_flags(struct panthor_gem_object *bo, u32 usage_flags)
{
- bo->debugfs.flags = usage_flags;
- panthor_gem_debugfs_bo_add(bo);
+ atomic_or(usage_flags, &bo->debugfs.flags);
}
#else
+static void panthor_gem_debugfs_bo_add(struct panthor_gem_object *bo) {}
static void panthor_gem_debugfs_bo_rm(struct panthor_gem_object *bo) {}
-static void panthor_gem_debugfs_set_usage_flags(struct panthor_gem_object *bo, u32 usage_flags) {}
+static void panthor_gem_debugfs_add_usage_flags(struct panthor_gem_object *bo, u32 usage_flags) {}
static void panthor_gem_debugfs_bo_init(struct panthor_gem_object *bo) {}
#endif
@@ -1034,7 +1034,8 @@ panthor_gem_create(struct drm_device *dev, size_t size, uint32_t flags,
bo->base.resv = bo->exclusive_vm_root_gem->resv;
}
- panthor_gem_debugfs_set_usage_flags(bo, usage_flags);
+ panthor_gem_debugfs_add_usage_flags(bo, usage_flags);
+ panthor_gem_debugfs_bo_add(bo);
return bo;
err_put:
@@ -1647,9 +1648,9 @@ static void panthor_gem_debugfs_bo_print(struct panthor_gem_object *bo,
enum panthor_gem_reclaim_state reclaim_state = bo->reclaim_state;
unsigned int refcount = kref_read(&bo->base.refcount);
int reclaimed_count = atomic_read(&bo->reclaimed_count);
+ u32 gem_usage_flags = atomic_read(&bo->debugfs.flags);
char creator_info[32] = {};
size_t resident_size;
- u32 gem_usage_flags = bo->debugfs.flags;
u32 gem_state_flags = 0;
/* Skip BOs being destroyed. */
diff --git a/drivers/gpu/drm/panthor/panthor_gem.h b/drivers/gpu/drm/panthor/panthor_gem.h
index 5ae37d0d3646f..4da3f59693ce4 100644
--- a/drivers/gpu/drm/panthor/panthor_gem.h
+++ b/drivers/gpu/drm/panthor/panthor_gem.h
@@ -62,7 +62,7 @@ struct panthor_gem_debugfs {
} creator;
/** @flags: Combination of panthor_debugfs_gem_usage_flags flags */
- u32 flags;
+ atomic_t flags;
};
/**
--
2.43.0
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH v5 09/13] drm/panthor: Create kernel BO from existing GEM
2026-11-16 11:25 [PATCH v5 00/13] drm/panthor: Protected mode support for Mali CSF GPUs Ketil Johnsen
` (7 preceding siblings ...)
2026-11-16 11:25 ` [PATCH v5 08/13] drm/panthor: Refactor GEM usage flags assignment Ketil Johnsen
@ 2026-11-16 11:25 ` Ketil Johnsen
2026-11-16 11:25 ` [PATCH v5 10/13] drm/panthor: Use a copy of suspend buffer sizes Ketil Johnsen
` (3 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Ketil Johnsen @ 2026-11-16 11:25 UTC (permalink / raw)
To: Boris Brezillon, Steven Price, Liviu Dudau, Akash Goel,
Karunika Choo, Lukas Zapolskas, Chris Diamand, Maarten Lankhorst,
Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter,
Daniel Almeida, Alice Ryhl
Cc: dri-devel, linux-kernel, rust-for-linux, Ketil Johnsen
From: Boris Brezillon <boris.brezillon@collabora.com>
Refactors/splits existing panthor_kernel_bo_create().
Adds panthor_kernel_bo_create_from_gem() so we can create kernel BOs
from imported protected memory in future change.
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Co-developed-by: Ketil Johnsen <ketil.johnsen@arm.com>
Signed-off-by: Ketil Johnsen <ketil.johnsen@arm.com>
---
v5:
- Fixed size type for panthor_kernel_bo_create_from_gem()
- Removed unused param from panthor_gem_create()
- Minor formating tweaks
v4:
- First version of this change as a separate commit
---
drivers/gpu/drm/panthor/panthor_gem.c | 100 +++++++++++++++++---------
drivers/gpu/drm/panthor/panthor_gem.h | 7 ++
2 files changed, 73 insertions(+), 34 deletions(-)
diff --git a/drivers/gpu/drm/panthor/panthor_gem.c b/drivers/gpu/drm/panthor/panthor_gem.c
index 5d0eb31746164..6a29609580f1f 100644
--- a/drivers/gpu/drm/panthor/panthor_gem.c
+++ b/drivers/gpu/drm/panthor/panthor_gem.c
@@ -1001,7 +1001,7 @@ panthor_gem_alloc_object(u32 flags)
static struct panthor_gem_object *
panthor_gem_create(struct drm_device *dev, size_t size, uint32_t flags,
- struct panthor_vm *exclusive_vm, u32 usage_flags)
+ struct panthor_vm *exclusive_vm)
{
struct panthor_gem_object *bo;
int ret;
@@ -1034,7 +1034,6 @@ panthor_gem_create(struct drm_device *dev, size_t size, uint32_t flags,
bo->base.resv = bo->exclusive_vm_root_gem->resv;
}
- panthor_gem_debugfs_add_usage_flags(bo, usage_flags);
panthor_gem_debugfs_bo_add(bo);
return bo;
@@ -1089,7 +1088,7 @@ panthor_gem_create_with_handle(struct drm_file *file,
int ret;
struct panthor_gem_object *bo;
- bo = panthor_gem_create(ddev, *size, flags, exclusive_vm, 0);
+ bo = panthor_gem_create(ddev, *size, flags, exclusive_vm);
if (IS_ERR(bo))
return PTR_ERR(bo);
@@ -1251,17 +1250,18 @@ panthor_gem_sync(struct drm_gem_object *obj, u32 type,
void panthor_kernel_bo_destroy(struct panthor_kernel_bo *bo)
{
struct panthor_device *ptdev;
+ struct drm_gem_object *root_gem;
struct panthor_vm *vm;
if (IS_ERR_OR_NULL(bo))
return;
ptdev = container_of(bo->obj->dev, struct panthor_device, base);
+ root_gem = to_panthor_bo(bo->obj)->exclusive_vm_root_gem;
vm = bo->vm;
panthor_kernel_bo_vunmap(bo);
- drm_WARN_ON(bo->obj->dev,
- to_panthor_bo(bo->obj)->exclusive_vm_root_gem != panthor_vm_root_gem(vm));
+ drm_WARN_ON(bo->obj->dev, root_gem && (root_gem != panthor_vm_root_gem(vm)));
panthor_vm_unmap_range(vm, bo->va_node.start, bo->va_node.size);
panthor_vm_free_va(vm, &bo->va_node);
if (vm == panthor_fw_vm(ptdev))
@@ -1272,46 +1272,34 @@ void panthor_kernel_bo_destroy(struct panthor_kernel_bo *bo)
}
/**
- * panthor_kernel_bo_create() - Create and map a GEM object to a VM
+ * panthor_kernel_bo_create_from_gem() - Create kernel BO from existing GEM object
* @ptdev: Device.
* @vm: VM to map the GEM to.
- * @size: Size of the buffer object.
- * @bo_flags: Combination of drm_panthor_bo_flags flags.
+ * @bo: BO to use for our kernel BO.
* @vm_map_flags: Combination of drm_panthor_vm_bind_op_flags (only those
* that are related to map operations).
* @gpu_va: GPU address assigned when mapping to the VM.
* If gpu_va == PANTHOR_VM_KERNEL_AUTO_VA, the virtual address will be
* automatically allocated.
- * @name: Descriptive label of the BO's contents
+ * @vm_map_size: Size of the BO to map to the VM.
*
* Return: A valid pointer in case of success, an ERR_PTR() otherwise.
*/
struct panthor_kernel_bo *
-panthor_kernel_bo_create(struct panthor_device *ptdev, struct panthor_vm *vm,
- size_t size, u32 bo_flags, u32 vm_map_flags,
- u64 gpu_va, const char *name)
+panthor_kernel_bo_create_from_gem(struct panthor_device *ptdev,
+ struct panthor_vm *vm,
+ struct panthor_gem_object *bo,
+ u32 vm_map_flags, u64 gpu_va,
+ size_t vm_map_size)
{
struct panthor_kernel_bo *kbo;
- struct panthor_gem_object *bo;
- u32 debug_flags = PANTHOR_DEBUGFS_GEM_USAGE_FLAG_KERNEL;
int ret;
- if (drm_WARN_ON(&ptdev->base, !vm))
- return ERR_PTR(-EINVAL);
-
kbo = kzalloc_obj(*kbo);
if (!kbo)
return ERR_PTR(-ENOMEM);
- if (vm == panthor_fw_vm(ptdev))
- debug_flags |= PANTHOR_DEBUGFS_GEM_USAGE_FLAG_FW_MAPPED;
-
- bo = panthor_gem_create(&ptdev->base, size, bo_flags, vm, debug_flags);
- if (IS_ERR(bo)) {
- ret = PTR_ERR(bo);
- goto err_free_kbo;
- }
-
+ drm_gem_object_get(&bo->base);
kbo->obj = &bo->base;
if (vm == panthor_fw_vm(ptdev)) {
@@ -1320,24 +1308,26 @@ panthor_kernel_bo_create(struct panthor_device *ptdev, struct panthor_vm *vm,
goto err_put_obj;
}
- panthor_gem_kernel_bo_set_label(kbo, name);
-
/* The system and GPU MMU page size might differ, which becomes a
* problem for FW sections that need to be mapped at explicit address
* since our PAGE_SIZE alignment might cover a VA range that's
* expected to be used for another section.
* Make sure we never map more than we need.
*/
- size = ALIGN(size, panthor_vm_page_size(vm));
- ret = panthor_vm_alloc_va(vm, gpu_va, size, &kbo->va_node);
+ vm_map_size = ALIGN(vm_map_size, panthor_vm_page_size(vm));
+ ret = panthor_vm_alloc_va(vm, gpu_va, vm_map_size, &kbo->va_node);
if (ret)
goto err_unpin;
- ret = panthor_vm_map_bo_range(vm, bo, 0, size, kbo->va_node.start, vm_map_flags);
+ ret = panthor_vm_map_bo_range(vm, bo, 0, vm_map_size,
+ kbo->va_node.start, vm_map_flags);
if (ret)
goto err_free_va;
kbo->vm = panthor_vm_get(vm);
+ if (vm == panthor_fw_vm(ptdev))
+ panthor_gem_debugfs_add_usage_flags(bo, PANTHOR_DEBUGFS_GEM_USAGE_FLAG_FW_MAPPED);
+
return kbo;
err_free_va:
@@ -1349,12 +1339,54 @@ panthor_kernel_bo_create(struct panthor_device *ptdev, struct panthor_vm *vm,
err_put_obj:
drm_gem_object_put(&bo->base);
-
-err_free_kbo:
kfree(kbo);
return ERR_PTR(ret);
}
+/**
+ * panthor_kernel_bo_create() - Create and map a GEM object to a VM
+ * @ptdev: Device.
+ * @vm: VM to map the GEM to.
+ * @size: Size of the buffer object.
+ * @bo_flags: Combination of drm_panthor_bo_flags flags.
+ * @vm_map_flags: Combination of drm_panthor_vm_bind_op_flags (only those
+ * that are related to map operations).
+ * @gpu_va: GPU address assigned when mapping to the VM.
+ * If gpu_va == PANTHOR_VM_KERNEL_AUTO_VA, the virtual address will be
+ * automatically allocated.
+ * @name: Descriptive label of the BO's contents
+ *
+ * Return: A valid pointer in case of success, an ERR_PTR() otherwise.
+ */
+struct panthor_kernel_bo *
+panthor_kernel_bo_create(struct panthor_device *ptdev, struct panthor_vm *vm,
+ size_t size, u32 bo_flags, u32 vm_map_flags,
+ u64 gpu_va, const char *name)
+{
+ struct panthor_kernel_bo *kbo;
+ struct panthor_gem_object *bo;
+
+ if (drm_WARN_ON(&ptdev->base, !vm))
+ return ERR_PTR(-EINVAL);
+
+ bo = panthor_gem_create(&ptdev->base, size, bo_flags, vm);
+ if (IS_ERR(bo))
+ return ERR_CAST(bo);
+
+ kbo = panthor_kernel_bo_create_from_gem(ptdev, vm, bo, vm_map_flags,
+ gpu_va, size);
+ if (!IS_ERR(kbo)) {
+ panthor_gem_debugfs_add_usage_flags(bo, PANTHOR_DEBUGFS_GEM_USAGE_FLAG_KERNEL);
+ panthor_gem_kernel_bo_set_label(kbo, name);
+ }
+
+ /* panthor_kernel_bo_create_from_gem() acquires a GEM ref if the import
+ * succeeds, so we can release it unconditionally here.
+ */
+ drm_gem_object_put(&bo->base);
+ return kbo;
+}
+
/**
* panthor_dummy_bo_create() - Create a Panthor BO meant to back sparse bindings.
* @ptdev: Device.
@@ -1370,7 +1402,7 @@ panthor_dummy_bo_create(struct panthor_device *ptdev)
* make sense to pre-populate this object's page array, nor to fall back on a BO size
* of 4KiB. Sticking to a dummy object size of 2MiB lets us keep things simple for now.
*/
- return panthor_gem_create(&ptdev->base, SZ_2M, DRM_PANTHOR_BO_NO_MMAP, NULL, 0);
+ return panthor_gem_create(&ptdev->base, SZ_2M, DRM_PANTHOR_BO_NO_MMAP, NULL);
}
static bool can_swap(void)
diff --git a/drivers/gpu/drm/panthor/panthor_gem.h b/drivers/gpu/drm/panthor/panthor_gem.h
index 4da3f59693ce4..787a7aaf706d8 100644
--- a/drivers/gpu/drm/panthor/panthor_gem.h
+++ b/drivers/gpu/drm/panthor/panthor_gem.h
@@ -318,6 +318,13 @@ panthor_kernel_bo_vunmap(struct panthor_kernel_bo *bo)
}
}
+struct panthor_kernel_bo *
+panthor_kernel_bo_create_from_gem(struct panthor_device *ptdev,
+ struct panthor_vm *vm,
+ struct panthor_gem_object *bo,
+ u32 vm_map_flags, u64 gpu_va,
+ size_t vm_map_size);
+
struct panthor_kernel_bo *
panthor_kernel_bo_create(struct panthor_device *ptdev, struct panthor_vm *vm,
size_t size, u32 bo_flags, u32 vm_map_flags,
--
2.43.0
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH v5 10/13] drm/panthor: Use a copy of suspend buffer sizes
2026-11-16 11:25 [PATCH v5 00/13] drm/panthor: Protected mode support for Mali CSF GPUs Ketil Johnsen
` (8 preceding siblings ...)
2026-11-16 11:25 ` [PATCH v5 09/13] drm/panthor: Create kernel BO from existing GEM Ketil Johnsen
@ 2026-11-16 11:25 ` Ketil Johnsen
2026-11-16 11:25 ` [PATCH v5 11/13] drm/panthor: Support FW init of protm Ketil Johnsen
` (2 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Ketil Johnsen @ 2026-11-16 11:25 UTC (permalink / raw)
To: Boris Brezillon, Steven Price, Liviu Dudau, Akash Goel,
Karunika Choo, Lukas Zapolskas, Chris Diamand, Maarten Lankhorst,
Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter,
Daniel Almeida, Alice Ryhl
Cc: dri-devel, linux-kernel, rust-for-linux, Ketil Johnsen
Store the suspend buffer sizes (normal and protected) provided by FW
after FW start. Unsafe to read directly from FW as these will return
zero between FW load and FW start.
Signed-off-by: Ketil Johnsen <ketil.johnsen@arm.com>
---
v5:
- First version of this patch in this patch set.
- This change was previously in a different patch in the set.
---
drivers/gpu/drm/panthor/panthor_fw.c | 25 +++++++++++++++++++++++++
drivers/gpu/drm/panthor/panthor_fw.h | 3 +++
drivers/gpu/drm/panthor/panthor_sched.c | 6 +++---
3 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/panthor/panthor_fw.c b/drivers/gpu/drm/panthor/panthor_fw.c
index fc07796fc9ef7..b565b362f401f 100644
--- a/drivers/gpu/drm/panthor/panthor_fw.c
+++ b/drivers/gpu/drm/panthor/panthor_fw.c
@@ -255,6 +255,12 @@ struct panthor_fw {
/** @iface: FW interfaces. */
struct panthor_fw_iface iface;
+ /** @suspend_size: Size of regular suspend buffer */
+ u32 suspend_size;
+
+ /** @protm_suspend_size: Size of protected suspend buffer size */
+ u32 protm_suspend_size;
+
/** @watchdog: Collection of fields relating to the FW watchdog. */
struct {
/** @ping_work: Delayed work used to ping the FW. */
@@ -549,6 +555,16 @@ panthor_fw_alloc_suspend_buf_mem(struct panthor_device *ptdev, size_t size)
"FW suspend buffer");
}
+u32 panthor_fw_suspend_size(struct panthor_device *ptdev)
+{
+ return ptdev->fw->suspend_size;
+}
+
+u32 panthor_fw_protm_suspend_size(struct panthor_device *ptdev)
+{
+ return ptdev->fw->protm_suspend_size;
+}
+
static u32 section_vm_map_flags(const struct panthor_fw_section *section)
{
u32 cache_mode = section->flags &
@@ -985,6 +1001,15 @@ static int panthor_init_csg_iface(struct panthor_device *ptdev,
return -EINVAL;
}
+ if (!csg_idx) {
+ /* We make a copy of these sizes, as csg_iface can read these
+ * as zero during full GPU reset, between FW sections being
+ * reloaded and FW fully booted.
+ */
+ ptdev->fw->suspend_size = csg_iface->control->suspend_size;
+ ptdev->fw->protm_suspend_size = csg_iface->control->protm_suspend_size;
+ }
+
if (csg_idx > 0) {
struct panthor_fw_csg_iface *first_csg_iface =
panthor_fw_get_csg_iface(ptdev, 0);
diff --git a/drivers/gpu/drm/panthor/panthor_fw.h b/drivers/gpu/drm/panthor/panthor_fw.h
index 4eda8f8e714c1..b3bf00191a96b 100644
--- a/drivers/gpu/drm/panthor/panthor_fw.h
+++ b/drivers/gpu/drm/panthor/panthor_fw.h
@@ -511,6 +511,9 @@ panthor_fw_alloc_queue_iface_mem(struct panthor_device *ptdev,
struct panthor_kernel_bo *
panthor_fw_alloc_suspend_buf_mem(struct panthor_device *ptdev, size_t size);
+u32 panthor_fw_suspend_size(struct panthor_device *ptdev);
+u32 panthor_fw_protm_suspend_size(struct panthor_device *ptdev);
+
struct panthor_vm *panthor_fw_vm(struct panthor_device *ptdev);
void panthor_fw_pre_reset(struct panthor_device *ptdev, bool on_hang);
diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c
index ca6aa6a55661a..9c78f04d4f30a 100644
--- a/drivers/gpu/drm/panthor/panthor_sched.c
+++ b/drivers/gpu/drm/panthor/panthor_sched.c
@@ -4058,7 +4058,7 @@ int panthor_group_create(struct drm_file *file,
struct panthor_scheduler *sched = ptdev->scheduler;
struct panthor_fw_csg_iface *csg_iface = panthor_fw_get_csg_iface(ptdev, 0);
struct panthor_group *group = NULL;
- u32 gid, i, suspend_size;
+ u32 gid, i;
int ret;
if (group_args->pad)
@@ -4109,8 +4109,8 @@ int panthor_group_create(struct drm_file *file,
goto err_put_group;
}
- suspend_size = csg_iface->control->suspend_size;
- group->suspend_buf = panthor_fw_alloc_suspend_buf_mem(ptdev, suspend_size);
+ group->suspend_buf =
+ panthor_fw_alloc_suspend_buf_mem(ptdev, panthor_fw_suspend_size(ptdev));
if (IS_ERR(group->suspend_buf)) {
ret = PTR_ERR(group->suspend_buf);
group->suspend_buf = NULL;
--
2.43.0
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH v5 11/13] drm/panthor: Support FW init of protm
2026-11-16 11:25 [PATCH v5 00/13] drm/panthor: Protected mode support for Mali CSF GPUs Ketil Johnsen
` (9 preceding siblings ...)
2026-11-16 11:25 ` [PATCH v5 10/13] drm/panthor: Use a copy of suspend buffer sizes Ketil Johnsen
@ 2026-11-16 11:25 ` Ketil Johnsen
2026-11-16 11:26 ` [PATCH v5 12/13] drm/panthor: Protm support for groups Ketil Johnsen
2026-11-16 11:26 ` [PATCH v5 13/13] drm/panthor: Bump version to expose protm feature Ketil Johnsen
12 siblings, 0 replies; 14+ messages in thread
From: Ketil Johnsen @ 2026-11-16 11:25 UTC (permalink / raw)
To: Boris Brezillon, Steven Price, Liviu Dudau, Akash Goel,
Karunika Choo, Lukas Zapolskas, Chris Diamand, Maarten Lankhorst,
Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter,
Daniel Almeida, Alice Ryhl
Cc: dri-devel, linux-kernel, rust-for-linux, Ketil Johnsen
From: Boris Brezillon <boris.brezillon@collabora.com>
The Mali GPU FW needs some protected memory when executing in protected
mode. This FW memory section is assigned a VA during device init.
A user space process with the needed privileges (CAP_SYS_MODULE) must
provide a suitable memory buffer before the Mali GPU is capable of
executing in protected mode.
Adds user query of FW protm state, min FW section size and min protm
suspend buffer size.
Adds user initiated init of FW protm section.
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Co-developed-by: Ketil Johnsen <ketil.johnsen@arm.com>
Signed-off-by: Ketil Johnsen <ketil.johnsen@arm.com>
---
v5:
- Ditched the lockless approach, now using a simpler mutex.
- Handle potential races reported by Sashiko.
- Do not write to protected FW section memory (during GPU reset).
- No longer mix guard() and goto error handling in panthor_fw_protm_init()
v4:
- First version of this change as a separate commit
---
drivers/gpu/drm/panthor/panthor_drv.c | 21 +++-
drivers/gpu/drm/panthor/panthor_fw.c | 146 ++++++++++++++++++++++++--
drivers/gpu/drm/panthor/panthor_fw.h | 5 +
include/uapi/drm/panthor_drm.h | 75 +++++++++++++
4 files changed, 238 insertions(+), 9 deletions(-)
diff --git a/drivers/gpu/drm/panthor/panthor_drv.c b/drivers/gpu/drm/panthor/panthor_drv.c
index 7edb8d329a705..ffea1eef134f5 100644
--- a/drivers/gpu/drm/panthor/panthor_drv.c
+++ b/drivers/gpu/drm/panthor/panthor_drv.c
@@ -177,11 +177,13 @@ panthor_get_uobj_array(const struct drm_panthor_obj_array *in, u32 min_stride,
PANTHOR_UOBJ_DECL(struct drm_panthor_mmu_info, page_size_bitmap), \
PANTHOR_UOBJ_DECL(struct drm_panthor_timestamp_info, current_timestamp), \
PANTHOR_UOBJ_DECL(struct drm_panthor_group_priorities_info, pad), \
+ PANTHOR_UOBJ_DECL(struct drm_panthor_protm_info, pad), \
PANTHOR_UOBJ_DECL(struct drm_panthor_sync_op, timeline_value), \
PANTHOR_UOBJ_DECL(struct drm_panthor_queue_submit, syncs), \
PANTHOR_UOBJ_DECL(struct drm_panthor_queue_create, ringbuf_size), \
PANTHOR_UOBJ_DECL(struct drm_panthor_vm_bind_op, syncs), \
- PANTHOR_UOBJ_DECL(struct drm_panthor_bo_sync_op, size))
+ PANTHOR_UOBJ_DECL(struct drm_panthor_bo_sync_op, size), \
+ PANTHOR_UOBJ_DECL(struct drm_panthor_protm_init, pad))
/**
* PANTHOR_UOBJ_SET() - Copy a kernel object to a user object.
@@ -934,6 +936,8 @@ static int panthor_ioctl_dev_query(struct drm_device *ddev, void *data, struct d
struct drm_panthor_dev_query *args = data;
struct drm_panthor_timestamp_info timestamp_info;
struct drm_panthor_group_priorities_info priorities_info;
+ struct drm_panthor_protm_info protm_info;
+
int ret;
if (!args->pointer) {
@@ -958,6 +962,10 @@ static int panthor_ioctl_dev_query(struct drm_device *ddev, void *data, struct d
args->size = sizeof(ptdev->mmu_info);
return 0;
+ case DRM_PANTHOR_DEV_QUERY_PROTM_INFO:
+ args->size = sizeof(protm_info);
+ return 0;
+
default:
return -EINVAL;
}
@@ -991,6 +999,10 @@ static int panthor_ioctl_dev_query(struct drm_device *ddev, void *data, struct d
case DRM_PANTHOR_DEV_QUERY_MMU_INFO:
return PANTHOR_UOBJ_SET(args->pointer, args->size, ptdev->mmu_info);
+ case DRM_PANTHOR_DEV_QUERY_PROTM_INFO:
+ panthor_fw_query_protm_info(file, &protm_info);
+ return PANTHOR_UOBJ_SET(args->pointer, args->size, protm_info);
+
default:
return -EINVAL;
}
@@ -1584,6 +1596,12 @@ static int panthor_ioctl_bo_query_info(struct drm_device *ddev, void *data,
return 0;
}
+static int panthor_ioctl_protm_init(struct drm_device *ddev, void *data,
+ struct drm_file *file)
+{
+ return panthor_fw_protm_init(file, data);
+}
+
static int
panthor_open(struct drm_device *ddev, struct drm_file *file)
{
@@ -1660,6 +1678,7 @@ static const struct drm_ioctl_desc panthor_drm_driver_ioctls[] = {
PANTHOR_IOCTL(SET_USER_MMIO_OFFSET, set_user_mmio_offset, DRM_RENDER_ALLOW),
PANTHOR_IOCTL(BO_SYNC, bo_sync, DRM_RENDER_ALLOW),
PANTHOR_IOCTL(BO_QUERY_INFO, bo_query_info, DRM_RENDER_ALLOW),
+ PANTHOR_IOCTL(PROTM_INIT, protm_init, DRM_RENDER_ALLOW),
};
static int panthor_mmap(struct file *filp, struct vm_area_struct *vma)
diff --git a/drivers/gpu/drm/panthor/panthor_fw.c b/drivers/gpu/drm/panthor/panthor_fw.c
index b565b362f401f..af86b1844ead8 100644
--- a/drivers/gpu/drm/panthor/panthor_fw.c
+++ b/drivers/gpu/drm/panthor/panthor_fw.c
@@ -13,8 +13,10 @@
#include <linux/mutex.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
+#include <linux/capability.h>
#include <drm/drm_drv.h>
+#include <drm/drm_file.h>
#include <drm/drm_managed.h>
#include <drm/drm_print.h>
@@ -267,6 +269,18 @@ struct panthor_fw {
struct delayed_work ping_work;
} watchdog;
+ struct {
+ /** @protm.init_lock: Used to serialize protm initialization. */
+ struct mutex init_lock;
+
+ /** @protm.inited: set to true when protm.section is initialized */
+ bool inited;
+
+ /** @protm.section: The protected mode section. */
+ struct panthor_fw_section *section;
+
+ } protm;
+
/**
* @req_waitqueue: FW request waitqueue.
*
@@ -460,7 +474,7 @@ static int panthor_fw_binary_sub_iter_init(struct panthor_device *ptdev,
static void panthor_fw_init_section_mem(struct panthor_device *ptdev,
struct panthor_fw_section *section)
{
- bool was_mapped = !!section->mem->kmap;
+ bool was_mapped;
struct sg_table *sgt;
int ret;
@@ -468,6 +482,14 @@ static void panthor_fw_init_section_mem(struct panthor_device *ptdev,
!(section->flags & CSF_FW_BINARY_IFACE_ENTRY_ZERO))
return;
+ if (section->flags & CSF_FW_BINARY_IFACE_ENTRY_PROT)
+ return;
+
+ if (!section->mem)
+ return;
+
+ was_mapped = !!section->mem->kmap;
+
ret = panthor_kernel_bo_vmap(section->mem);
if (drm_WARN_ON(&ptdev->base, ret))
return;
@@ -637,12 +659,6 @@ static int panthor_fw_load_section_entry(struct panthor_device *ptdev,
return -EINVAL;
}
- if (hdr.flags & CSF_FW_BINARY_IFACE_ENTRY_PROT) {
- drm_warn(&ptdev->base,
- "Firmware protected mode entry is not supported, ignoring");
- return 0;
- }
-
if (hdr.va.start == CSF_MCU_SHARED_REGION_START &&
!(hdr.flags & CSF_FW_BINARY_IFACE_ENTRY_SHARED)) {
drm_err(&ptdev->base,
@@ -694,7 +710,22 @@ static int panthor_fw_load_section_entry(struct panthor_device *ptdev,
section->size = section_size;
section->va = hdr.va.start;
- if (section_size) {
+ if (hdr.flags & CSF_FW_BINARY_IFACE_ENTRY_PROT) {
+ guard(mutex)(&ptdev->fw->protm.init_lock);
+
+ if (ptdev->fw->protm.section) {
+ drm_err(&ptdev->base,
+ "Only one protected section supported\n");
+ return -EINVAL;
+ }
+
+ ptdev->fw->protm.section = section;
+ }
+
+ /* Defer the section->mem creation if this is a protected entry.
+ * This will be populated when DRM_IOCTL_PANTHOR_PROTM_INIT is called.
+ */
+ if (section->size && !(hdr.flags & CSF_FW_BINARY_IFACE_ENTRY_PROT)) {
u32 vm_map_flags = section_vm_map_flags(section);
section->mem = panthor_kernel_bo_create(
@@ -1610,6 +1641,101 @@ int panthor_fw_protm_exit(struct panthor_device *ptdev, u32 timeout_ms)
return panthor_fw_protm_exit_wait(ptdev, timeout_ms);
}
+int panthor_fw_protm_init(struct drm_file *file,
+ struct drm_panthor_protm_init *args)
+{
+ struct panthor_file *pfile = file->driver_priv;
+ struct panthor_device *ptdev = pfile->ptdev;
+ ssize_t vm_pgsz = panthor_vm_page_size(ptdev->fw->vm);
+ struct panthor_fw_section *protm_section;
+ struct panthor_kernel_bo *mem;
+ struct drm_gem_object *obj;
+ u32 vm_map_flags;
+ int cookie, ret = 0;
+
+ if (!capable(CAP_SYS_MODULE))
+ return -EPERM;
+
+ if (args->pad)
+ return -EINVAL;
+
+ mutex_lock(&ptdev->fw->protm.init_lock);
+
+ protm_section = ptdev->fw->protm.section;
+
+ if (!protm_section || !protm_section->size) {
+ ret = -EINVAL;
+ goto out_unlock;
+ }
+
+ if (ptdev->fw->protm.inited)
+ goto out_unlock;
+
+ if (!drm_dev_enter(&ptdev->base, &cookie)) {
+ ret = -ENODEV;
+ goto out_unlock;
+ }
+
+ obj = drm_gem_object_lookup(file,
+ args->fw_protected_sections_bo_handle);
+ if (!obj) {
+ ret = -ENOENT;
+ goto out_dev_exit;
+ }
+
+ if (obj->size < ALIGN(ptdev->fw->protm.section->size, vm_pgsz)) {
+ ret = -EINVAL;
+ goto out_gem_put;
+ }
+
+ vm_map_flags = section_vm_map_flags(protm_section);
+
+ mem = panthor_kernel_bo_create_from_gem(
+ ptdev, panthor_fw_vm(ptdev), to_panthor_bo(obj), vm_map_flags,
+ protm_section->va, protm_section->size);
+ if (IS_ERR(mem)) {
+ ret = PTR_ERR(mem);
+ goto out_gem_put;
+ }
+
+ protm_section->mem = mem;
+
+ ptdev->fw->protm.inited = true;
+
+out_gem_put:
+ drm_gem_object_put(obj);
+
+out_dev_exit:
+ drm_dev_exit(cookie);
+
+out_unlock:
+ mutex_unlock(&ptdev->fw->protm.init_lock);
+
+ return ret;
+}
+
+bool panthor_fw_protm_is_inited(struct panthor_device *ptdev)
+{
+ guard(mutex)(&ptdev->fw->protm.init_lock);
+ return ptdev->fw->protm.inited;
+}
+
+void panthor_fw_query_protm_info(struct drm_file *file,
+ struct drm_panthor_protm_info *arg)
+{
+ struct panthor_file *pfile = file->driver_priv;
+ struct panthor_device *ptdev = pfile->ptdev;
+ ssize_t vm_pgsz = panthor_vm_page_size(ptdev->fw->vm);
+
+ guard(mutex)(&ptdev->fw->protm.init_lock);
+
+ memset(arg, 0, sizeof(*arg));
+ arg->state = ptdev->fw->protm.inited ? DRM_PANTHOR_PROTM_INITIALIZED : 0;
+ arg->group_protected_suspend_buf_size = ptdev->fw->protm_suspend_size;
+ arg->fw_protected_sections_size = ALIGN(ptdev->fw->protm.section->size,
+ vm_pgsz);
+}
+
/**
* panthor_fw_init() - Initialize FW related data.
* @ptdev: Device.
@@ -1631,6 +1757,10 @@ int panthor_fw_init(struct panthor_device *ptdev)
INIT_LIST_HEAD(&fw->sections);
INIT_DELAYED_WORK(&fw->watchdog.ping_work, panthor_fw_ping_work);
+ ret = drmm_mutex_init(&ptdev->base, &fw->protm.init_lock);
+ if (ret)
+ return ret;
+
irq = platform_get_irq_byname(to_platform_device(ptdev->base.dev), "job");
if (irq <= 0)
return -ENODEV;
diff --git a/drivers/gpu/drm/panthor/panthor_fw.h b/drivers/gpu/drm/panthor/panthor_fw.h
index b3bf00191a96b..84edd25989aa4 100644
--- a/drivers/gpu/drm/panthor/panthor_fw.h
+++ b/drivers/gpu/drm/panthor/panthor_fw.h
@@ -532,6 +532,11 @@ static inline int panthor_fw_resume(struct panthor_device *ptdev)
int panthor_fw_init(struct panthor_device *ptdev);
void panthor_fw_unplug(struct panthor_device *ptdev);
+int panthor_fw_protm_init(struct drm_file *file,
+ struct drm_panthor_protm_init *args);
+bool panthor_fw_protm_is_inited(struct panthor_device *ptdev);
+void panthor_fw_query_protm_info(struct drm_file *file,
+ struct drm_panthor_protm_info *arg);
int panthor_fw_protm_enter(struct panthor_device *ptdev);
int panthor_fw_protm_exit(struct panthor_device *ptdev, u32 timeout_ms);
int panthor_fw_protm_exit_wait(struct panthor_device *ptdev, u32 timeout_ms);
diff --git a/include/uapi/drm/panthor_drm.h b/include/uapi/drm/panthor_drm.h
index a2ff0f4ec6915..d2d21e3e6bb39 100644
--- a/include/uapi/drm/panthor_drm.h
+++ b/include/uapi/drm/panthor_drm.h
@@ -154,6 +154,11 @@ enum drm_panthor_ioctl_id {
* This is useful for imported BOs.
*/
DRM_PANTHOR_BO_QUERY_INFO,
+
+ /**
+ * @DRM_PANTHOR_PROTM_INIT: Device-wide initialize of protected mode.
+ */
+ DRM_PANTHOR_PROTM_INIT,
};
/**
@@ -256,6 +261,11 @@ enum drm_panthor_dev_query_type {
/** @DRM_PANTHOR_DEV_QUERY_MMU_INFO: Query MMU information. */
DRM_PANTHOR_DEV_QUERY_MMU_INFO,
+
+ /**
+ * @DRM_PANTHOR_DEV_QUERY_PROTM_INFO: Query supported protected rendering information.
+ */
+ DRM_PANTHOR_DEV_QUERY_PROTM_INFO,
};
/**
@@ -517,6 +527,51 @@ struct drm_panthor_group_priorities_info {
__u8 pad[3];
};
+/**
+ * enum drm_panthor_protm_state_flags - Describes the state of the protected mode feature.
+ *
+ * List of GPU states which can be used by the GPU to access protected memory.
+ */
+enum drm_panthor_protm_state_flags {
+ /**
+ * @DRM_PANTHOR_PROTM_INITIALIZED: Device-wide initialization of the
+ * protected mode feature is done.
+ */
+ DRM_PANTHOR_PROTM_INITIALIZED = 1 << 0,
+};
+
+/**
+ * struct drm_panthor_protm_info - Protected mode info.
+ *
+ * Structure grouping all queryable information relating to protected mode.
+ */
+struct drm_panthor_protm_info {
+ /**
+ * @state: Combination of enum drm_panthor_protm_state_flags flags.
+ */
+ __u32 state;
+
+ /**
+ * @fw_protected_sections_size: Size of all the protected FW sections.
+ *
+ * Size of the protected buffer to pass through
+ * DRM_IOCTL_PANTHOR_PROTM_INIT.
+ */
+ __u32 fw_protected_sections_size;
+
+ /**
+ * @group_protected_suspend_buf_size: Size of the group suspend buffer.
+ *
+ * This must be used to allocate a protected BO that's big enough to use
+ * as a protected suspend buffer when a group supports protected
+ * rendering.
+ */
+ __u32 group_protected_suspend_buf_size;
+
+ /** @pad: MBZ. */
+ __u32 pad;
+};
+
/**
* struct drm_panthor_dev_query - Arguments passed to DRM_PANTHOR_IOCTL_DEV_QUERY
*/
@@ -1270,6 +1325,24 @@ struct drm_panthor_bo_query_info {
__u32 pad;
};
+/**
+ * struct drm_panthor_protm_init - Protected mode initialization arguments.
+ */
+struct drm_panthor_protm_init {
+ /**
+ * @fw_protected_sections_bo_handle: Handle of the BO to use for the FW protected
+ * sections.
+ *
+ * This BO must have been allocated from a protected DMA-BUF heap and
+ * imported in panthor. It's size must be at least
+ * drm_panthor_protm_info::fw_protected_sections_size.
+ */
+ __u32 fw_protected_sections_bo_handle;
+
+ /** @pad: MBZ. */
+ __u32 pad;
+};
+
/**
* DRM_IOCTL_PANTHOR() - Build a Panthor IOCTL number
* @__access: Access type. Must be R, W or RW.
@@ -1320,6 +1393,8 @@ enum {
DRM_IOCTL_PANTHOR(WR, BO_SYNC, bo_sync),
DRM_IOCTL_PANTHOR_BO_QUERY_INFO =
DRM_IOCTL_PANTHOR(WR, BO_QUERY_INFO, bo_query_info),
+ DRM_IOCTL_PANTHOR_PROTM_INIT =
+ DRM_IOCTL_PANTHOR(WR, PROTM_INIT, protm_init),
};
#if defined(__cplusplus)
--
2.43.0
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH v5 12/13] drm/panthor: Protm support for groups
2026-11-16 11:25 [PATCH v5 00/13] drm/panthor: Protected mode support for Mali CSF GPUs Ketil Johnsen
` (10 preceding siblings ...)
2026-11-16 11:25 ` [PATCH v5 11/13] drm/panthor: Support FW init of protm Ketil Johnsen
@ 2026-11-16 11:26 ` Ketil Johnsen
2026-11-16 11:26 ` [PATCH v5 13/13] drm/panthor: Bump version to expose protm feature Ketil Johnsen
12 siblings, 0 replies; 14+ messages in thread
From: Ketil Johnsen @ 2026-11-16 11:26 UTC (permalink / raw)
To: Boris Brezillon, Steven Price, Liviu Dudau, Akash Goel,
Karunika Choo, Lukas Zapolskas, Chris Diamand, Maarten Lankhorst,
Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter,
Daniel Almeida, Alice Ryhl
Cc: dri-devel, linux-kernel, rust-for-linux, Ketil Johnsen
From: Boris Brezillon <boris.brezillon@collabora.com>
Extends struct drm_panthor_group_create to allow user provided protm
suspend buffer. This is needed for protm execution with this group.
Make use of the user supplied suspend buffer (import).
Allow PROT_REGION instruction for groups which provided protm
suspend buffer.
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Co-developed-by: Ketil Johnsen <ketil.johnsen@arm.com>
Signed-off-by: Ketil Johnsen <ketil.johnsen@arm.com>
---
v5:
- Removed unused #define
- Minor formating changes
- Moved caching of suspend buf sizes to a separate patch
v4:
- First version of this change as a separate commit
---
drivers/gpu/drm/panthor/panthor_sched.c | 50 +++++++++++++++++++++----
include/uapi/drm/panthor_drm.h | 10 ++++-
2 files changed, 51 insertions(+), 9 deletions(-)
diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c
index 9c78f04d4f30a..02726cbcce3ca 100644
--- a/drivers/gpu/drm/panthor/panthor_sched.c
+++ b/drivers/gpu/drm/panthor/panthor_sched.c
@@ -1456,10 +1456,15 @@ cs_slot_process_protm_pending_event_locked(struct panthor_device *ptdev,
if (!group)
return;
- /* Do not allow user space work to switch into protected mode, as we
- * do not fully support this quite yet.
+ /* Do not allow user space work to switch into protected mode if we
+ * do not support protected mode on this device.
+ * User space should query (and init) this support before attempting
+ * to use such GPU instructions.
*/
- atomic_or(BIT(cs_id), &group->fatal_queues);
+ if (group->protm_suspend_buf)
+ atomic_or(BIT(cs_id), &group->protm_pending_queues);
+ else
+ atomic_or(BIT(cs_id), &group->fatal_queues);
sched_queue_delayed_work(sched, tick, 0);
}
@@ -4056,14 +4061,10 @@ int panthor_group_create(struct drm_file *file,
struct panthor_device *ptdev = pfile->ptdev;
struct panthor_group_pool *gpool = pfile->groups;
struct panthor_scheduler *sched = ptdev->scheduler;
- struct panthor_fw_csg_iface *csg_iface = panthor_fw_get_csg_iface(ptdev, 0);
struct panthor_group *group = NULL;
u32 gid, i;
int ret;
- if (group_args->pad)
- return -EINVAL;
-
if (group_args->priority >= PANTHOR_CSG_PRIORITY_COUNT)
return -EINVAL;
@@ -4117,6 +4118,41 @@ int panthor_group_create(struct drm_file *file,
goto err_put_group;
}
+ if (group_args->protected_suspend_bo_handle) {
+ struct drm_gem_object *obj;
+
+ /* Read a correct snapshot of the state */
+ if (!panthor_fw_protm_is_inited(ptdev)) {
+ ret = -EINVAL;
+ goto err_put_group;
+ }
+
+ obj = drm_gem_object_lookup(file, group_args->protected_suspend_bo_handle);
+ if (!obj) {
+ ret = -ENOENT;
+ goto err_put_group;
+ }
+
+ if (obj->size < panthor_fw_protm_suspend_size(ptdev)) {
+ drm_gem_object_put(obj);
+ ret = -EINVAL;
+ goto err_put_group;
+ }
+
+ group->protm_suspend_buf =
+ panthor_kernel_bo_create_from_gem(ptdev, panthor_fw_vm(ptdev),
+ to_panthor_bo(obj),
+ DRM_PANTHOR_VM_BIND_OP_MAP_NOEXEC,
+ PANTHOR_VM_KERNEL_AUTO_VA,
+ panthor_fw_protm_suspend_size(ptdev));
+ drm_gem_object_put(obj);
+ if (IS_ERR(group->protm_suspend_buf)) {
+ ret = PTR_ERR(group->protm_suspend_buf);
+ group->protm_suspend_buf = NULL;
+ goto err_put_group;
+ }
+ }
+
group->syncobjs = panthor_kernel_bo_create(ptdev, group->vm,
group_args->queues.count *
sizeof(struct panthor_syncobj_64b),
diff --git a/include/uapi/drm/panthor_drm.h b/include/uapi/drm/panthor_drm.h
index d2d21e3e6bb39..a0ed16041e178 100644
--- a/include/uapi/drm/panthor_drm.h
+++ b/include/uapi/drm/panthor_drm.h
@@ -956,8 +956,14 @@ struct drm_panthor_group_create {
/** @priority: Group priority (see enum drm_panthor_group_priority). */
__u8 priority;
- /** @pad: Padding field, MBZ. */
- __u32 pad;
+ /**
+ * @protected_suspend_bo_handle: BO to use as a protected suspend buffer.
+ *
+ * This BO must have been allocated from a protected DMA-BUF heap and
+ * imported in panthor. It's size must be at least
+ * drm_panthor_protm_info::group_protected_suspend_buf_size.
+ */
+ __u32 protected_suspend_bo_handle;
/**
* @compute_core_mask: Mask encoding cores that can be used for compute jobs.
--
2.43.0
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH v5 13/13] drm/panthor: Bump version to expose protm feature
2026-11-16 11:25 [PATCH v5 00/13] drm/panthor: Protected mode support for Mali CSF GPUs Ketil Johnsen
` (11 preceding siblings ...)
2026-11-16 11:26 ` [PATCH v5 12/13] drm/panthor: Protm support for groups Ketil Johnsen
@ 2026-11-16 11:26 ` Ketil Johnsen
12 siblings, 0 replies; 14+ messages in thread
From: Ketil Johnsen @ 2026-11-16 11:26 UTC (permalink / raw)
To: Boris Brezillon, Steven Price, Liviu Dudau, Akash Goel,
Karunika Choo, Lukas Zapolskas, Chris Diamand, Maarten Lankhorst,
Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter,
Daniel Almeida, Alice Ryhl
Cc: dri-devel, linux-kernel, rust-for-linux, Ketil Johnsen
Bumps version to expose previously added:
- DRM_IOCTL_PANTHOR_PROTM_INIT ioctl
- DRM_PANTHOR_DEV_QUERY_PROTM_INFO query
- drm_panthor_group_create::protected_suspend_bo_handle
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Signed-off-by: Ketil Johnsen <ketil.johnsen@arm.com>
---
v4:
- First version of this change as a separate commit
---
drivers/gpu/drm/panthor/panthor_drv.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/panthor/panthor_drv.c b/drivers/gpu/drm/panthor/panthor_drv.c
index ffea1eef134f5..e87d9d7a3fb77 100644
--- a/drivers/gpu/drm/panthor/panthor_drv.c
+++ b/drivers/gpu/drm/panthor/panthor_drv.c
@@ -1800,6 +1800,9 @@ static void panthor_debugfs_init(struct drm_minor *minor)
* - 1.8 - extends DEV_QUERY_TIMESTAMP_INFO with flags
* - 1.9 - adds DRM_PANTHOR_DEV_QUERY_MMU_INFO query
* - adds DRM_PANTHOR_VM_BIND_OP_MAP_SPARSE flag
+ * - 1.10 - adds DRM_IOCTL_PANTHOR_PROTM_INIT ioctl
+ * - adds DRM_PANTHOR_DEV_QUERY_PROTM_INFO query
+ * - adds drm_panthor_group_create::protected_suspend_bo_handle
*/
static const struct drm_driver panthor_drm_driver = {
.driver_features = DRIVER_RENDER | DRIVER_GEM | DRIVER_SYNCOBJ |
@@ -1813,7 +1816,7 @@ static const struct drm_driver panthor_drm_driver = {
.name = "panthor",
.desc = "Panthor DRM driver",
.major = 1,
- .minor = 9,
+ .minor = 10,
.gem_prime_import_sg_table = panthor_gem_prime_import_sg_table,
.gem_prime_import = panthor_gem_prime_import,
--
2.43.0
^ permalink raw reply [flat|nested] 14+ messages in thread