panfrost: Support JM context creation and destruction

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 <daniels@collabora.com>
Reviewed-by: Ashley Smith <ashley.smith@collabora.com>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37075>
This commit is contained in:
Boris Brezillon 2025-08-29 00:01:51 +01:00 committed by Marge Bot
parent f04dbf0bc0
commit e9aedfe508
3 changed files with 60 additions and 10 deletions

View file

@ -241,6 +241,7 @@ struct panfrost_context {
union {
struct panfrost_csf_context csf;
struct panfrost_jm_context jm;
};
struct {

View file

@ -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);
}

View file

@ -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);