From e9aedfe50857f23203fd3d8e517d14e25e08209d Mon Sep 17 00:00:00 2001 From: Boris Brezillon Date: Fri, 29 Aug 2025 00:01:51 +0100 Subject: [PATCH] panfrost: Support JM context creation and destruction MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A Panfrost JM context can be created by leveraging the new Panfrost 1.5 KM IOCTLs and translating Mesa pipe resource priority levels into Panfrost-specific ones. Reviewed-by: Daniel Stone Reviewed-by: Ashley Smith Signed-off-by: Boris Brezillon Signed-off-by: Adrián Larumbe Part-of: --- src/gallium/drivers/panfrost/pan_context.h | 1 + src/gallium/drivers/panfrost/pan_jm.c | 54 +++++++++++++++++++++- src/gallium/drivers/panfrost/pan_jm.h | 15 +++--- 3 files changed, 60 insertions(+), 10 deletions(-) diff --git a/src/gallium/drivers/panfrost/pan_context.h b/src/gallium/drivers/panfrost/pan_context.h index f2562504a4b..32a52426cd4 100644 --- a/src/gallium/drivers/panfrost/pan_context.h +++ b/src/gallium/drivers/panfrost/pan_context.h @@ -241,6 +241,7 @@ struct panfrost_context { union { struct panfrost_csf_context csf; + struct panfrost_jm_context jm; }; struct { diff --git a/src/gallium/drivers/panfrost/pan_jm.c b/src/gallium/drivers/panfrost/pan_jm.c index 73953d54937..64c53823288 100644 --- a/src/gallium/drivers/panfrost/pan_jm.c +++ b/src/gallium/drivers/panfrost/pan_jm.c @@ -86,7 +86,7 @@ jm_submit_jc(struct panfrost_batch *batch, uint64_t first_job_desc, struct pipe_context *gallium = (struct pipe_context *)ctx; struct panfrost_device *dev = pan_device(gallium->screen); struct drm_panfrost_submit submit = { - 0, + .jm_ctx_handle = ctx->jm.handle, }; uint32_t in_syncs[1]; uint32_t *bo_handles; @@ -1032,3 +1032,55 @@ GENX(jm_emit_write_timestamp)(struct panfrost_batch *batch, false, 0, 0, &job, false); panfrost_batch_write_rsrc(batch, dst, MESA_SHADER_VERTEX); } + +int +GENX(jm_init_context)(struct panfrost_context *ctx) +{ + /* The default context is medium prio, so we use that one. */ + if (!(ctx->flags & + (PIPE_CONTEXT_HIGH_PRIORITY | PIPE_CONTEXT_LOW_PRIORITY))) { + ctx->jm.handle = 0; + return 0; + } + + struct panfrost_device *dev = pan_device(ctx->base.screen); + enum drm_panfrost_jm_ctx_priority prio; + + if (ctx->flags & PIPE_CONTEXT_HIGH_PRIORITY) + prio = PANFROST_JM_CTX_PRIORITY_HIGH; + else if (ctx->flags & PIPE_CONTEXT_LOW_PRIORITY) + prio = PANFROST_JM_CTX_PRIORITY_LOW; + else + prio = PANFROST_JM_CTX_PRIORITY_MEDIUM; + + struct drm_panfrost_jm_ctx_create args = { + .priority = prio, + }; + + int ret = ret = pan_kmod_ioctl(panfrost_device_fd(dev), + DRM_IOCTL_PANFROST_JM_CTX_CREATE, + &args); + if (ret) + return -1; + + ctx->jm.handle = args.handle; + return 0; +} + +void +GENX(jm_cleanup_context)(struct panfrost_context *ctx) +{ + if (!ctx->jm.handle) + return; + + struct panfrost_device *dev = pan_device(ctx->base.screen); + struct drm_panfrost_jm_ctx_destroy args = { + .handle = ctx->jm.handle, + }; + + ASSERTED int ret = pan_kmod_ioctl(panfrost_device_fd(dev), + DRM_IOCTL_PANFROST_JM_CTX_DESTROY, + &args); + + assert(!ret); +} diff --git a/src/gallium/drivers/panfrost/pan_jm.h b/src/gallium/drivers/panfrost/pan_jm.h index 3c1b1046a02..3ac2e4c1707 100644 --- a/src/gallium/drivers/panfrost/pan_jm.h +++ b/src/gallium/drivers/panfrost/pan_jm.h @@ -27,6 +27,10 @@ #include "pan_jc.h" +struct panfrost_jm_context { + uint32_t handle; +}; + struct panfrost_jm_batch { /* Job related fields. */ struct { @@ -50,16 +54,9 @@ struct pipe_draw_info; struct pipe_grid_info; struct pipe_draw_start_count_bias; -static inline int -GENX(jm_init_context)(struct panfrost_context *ctx) -{ - return 0; -} +int GENX(jm_init_context)(struct panfrost_context *ctx); -static inline void -GENX(jm_cleanup_context)(struct panfrost_context *ctx) -{ -} +void GENX(jm_cleanup_context)(struct panfrost_context *ctx); int GENX(jm_init_batch)(struct panfrost_batch *batch);