From: Boris Brezillon <[email protected]> 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 <[email protected]> Co-developed-by: Ketil Johnsen <[email protected]> Signed-off-by: Ketil Johnsen <[email protected]> --- 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
