From a05b6829c8da338186d581d7f159d288deec2642 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Larumbe?= Date: Sun, 16 Mar 2025 03:53:12 +0000 Subject: [PATCH] pan/kmod: Add Panthor BO Labeling IOCTL support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implement kmod->ops->bo_label operation for Panthor kmod driver. Signed-off-by: Adrián Larumbe Reviewed-by: Boris Brezillon Part-of: --- src/panfrost/lib/kmod/panthor_kmod.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/panfrost/lib/kmod/panthor_kmod.c b/src/panfrost/lib/kmod/panthor_kmod.c index bab70f47b7a..43c8b4c1ee5 100644 --- a/src/panfrost/lib/kmod/panthor_kmod.c +++ b/src/panfrost/lib/kmod/panthor_kmod.c @@ -22,6 +22,9 @@ #include "pan_kmod_backend.h" +/* Maximum kmod BO label length, including NUL-terminator */ +#define PANTHOR_BO_LABEL_MAXLEN 4096 + const struct pan_kmod_ops panthor_kmod_ops; /* Objects used to track VAs returned through async unmaps. */ @@ -1190,6 +1193,30 @@ panthor_kmod_query_timestamp(const struct pan_kmod_dev *dev) return timestamp_info.current_timestamp; } +static void +panthor_kmod_bo_label(struct pan_kmod_dev *dev, struct pan_kmod_bo *bo, const char *label) +{ + char truncated_label[PANTHOR_BO_LABEL_MAXLEN]; + + if (!(dev->driver.version.major > 1 || dev->driver.version.minor >= 4)) + return; + + if (strnlen(label, PANTHOR_BO_LABEL_MAXLEN) == PANTHOR_BO_LABEL_MAXLEN) { + strncpy(truncated_label, label, PANTHOR_BO_LABEL_MAXLEN - 1); + truncated_label[PANTHOR_BO_LABEL_MAXLEN - 1] = '\0'; + label = truncated_label; + } + + struct drm_panthor_bo_set_label set_label = (struct drm_panthor_bo_set_label) { + .handle = bo->handle, + .label = (uint64_t)(uintptr_t)label, + }; + + int ret = pan_kmod_ioctl(dev->fd, DRM_IOCTL_PANTHOR_BO_SET_LABEL, &set_label); + if (ret) + mesa_loge("DRM_IOCTL_PANTHOR_BO_SET_LABEL failed (err=%d)", errno); +} + const struct pan_kmod_ops panthor_kmod_ops = { .dev_create = panthor_kmod_dev_create, .dev_destroy = panthor_kmod_dev_destroy, @@ -1206,4 +1233,5 @@ const struct pan_kmod_ops panthor_kmod_ops = { .vm_bind = panthor_kmod_vm_bind, .vm_query_state = panthor_kmod_vm_query_state, .query_timestamp = panthor_kmod_query_timestamp, + .bo_set_label = panthor_kmod_bo_label, };