Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/panfrost: Add driver IOCTL for setting BO labels

Allow UM to label a BO for which it possesses a DRM handle.

Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com>
Reviewed-by: Steven Price <steven.price@arm.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Signed-off-by: Steven Price <steven.price@arm.com>
Link: https://lore.kernel.org/r/20250520174634.353267-4-adrian.larumbe@collabora.com

authored by

Adrián Larumbe and committed by
Steven Price
2f684bbb ca8b3216

+66 -1
+43 -1
drivers/gpu/drm/panfrost/panfrost_drv.c
··· 495 495 return ret; 496 496 } 497 497 498 + static int panfrost_ioctl_set_label_bo(struct drm_device *ddev, void *data, 499 + struct drm_file *file) 500 + { 501 + struct drm_panfrost_set_label_bo *args = data; 502 + struct drm_gem_object *obj; 503 + const char *label = NULL; 504 + int ret = 0; 505 + 506 + if (args->pad) 507 + return -EINVAL; 508 + 509 + obj = drm_gem_object_lookup(file, args->handle); 510 + if (!obj) 511 + return -ENOENT; 512 + 513 + if (args->label) { 514 + label = strndup_user(u64_to_user_ptr(args->label), 515 + PANFROST_BO_LABEL_MAXLEN); 516 + if (IS_ERR(label)) { 517 + ret = PTR_ERR(label); 518 + if (ret == -EINVAL) 519 + ret = -E2BIG; 520 + goto err_put_obj; 521 + } 522 + } 523 + 524 + /* 525 + * We treat passing a label of length 0 and passing a NULL label 526 + * differently, because even though they might seem conceptually 527 + * similar, future uses of the BO label might expect a different 528 + * behaviour in each case. 529 + */ 530 + panfrost_gem_set_label(obj, label); 531 + 532 + err_put_obj: 533 + drm_gem_object_put(obj); 534 + 535 + return ret; 536 + } 537 + 498 538 int panfrost_unstable_ioctl_check(void) 499 539 { 500 540 if (!unstable_ioctls) ··· 601 561 PANFROST_IOCTL(PERFCNT_ENABLE, perfcnt_enable, DRM_RENDER_ALLOW), 602 562 PANFROST_IOCTL(PERFCNT_DUMP, perfcnt_dump, DRM_RENDER_ALLOW), 603 563 PANFROST_IOCTL(MADVISE, madvise, DRM_RENDER_ALLOW), 564 + PANFROST_IOCTL(SET_LABEL_BO, set_label_bo, DRM_RENDER_ALLOW), 604 565 }; 605 566 606 567 static void panfrost_gpu_show_fdinfo(struct panfrost_device *pfdev, ··· 666 625 * - 1.2 - adds AFBC_FEATURES query 667 626 * - 1.3 - adds JD_REQ_CYCLE_COUNT job requirement for SUBMIT 668 627 * - adds SYSTEM_TIMESTAMP and SYSTEM_TIMESTAMP_FREQUENCY queries 628 + * - 1.4 - adds SET_LABEL_BO 669 629 */ 670 630 static const struct drm_driver panfrost_drm_driver = { 671 631 .driver_features = DRIVER_RENDER | DRIVER_GEM | DRIVER_SYNCOBJ, ··· 679 637 .name = "panfrost", 680 638 .desc = "panfrost DRM", 681 639 .major = 1, 682 - .minor = 3, 640 + .minor = 4, 683 641 684 642 .gem_create_object = panfrost_gem_create_object, 685 643 .gem_prime_import_sg_table = panfrost_gem_prime_import_sg_table,
+2
drivers/gpu/drm/panfrost/panfrost_gem.h
··· 9 9 10 10 struct panfrost_mmu; 11 11 12 + #define PANFROST_BO_LABEL_MAXLEN 4096 13 + 12 14 struct panfrost_gem_object { 13 15 struct drm_gem_shmem_object base; 14 16 struct sg_table *sgts;
+21
include/uapi/drm/panfrost_drm.h
··· 21 21 #define DRM_PANFROST_PERFCNT_ENABLE 0x06 22 22 #define DRM_PANFROST_PERFCNT_DUMP 0x07 23 23 #define DRM_PANFROST_MADVISE 0x08 24 + #define DRM_PANFROST_SET_LABEL_BO 0x09 24 25 25 26 #define DRM_IOCTL_PANFROST_SUBMIT DRM_IOW(DRM_COMMAND_BASE + DRM_PANFROST_SUBMIT, struct drm_panfrost_submit) 26 27 #define DRM_IOCTL_PANFROST_WAIT_BO DRM_IOW(DRM_COMMAND_BASE + DRM_PANFROST_WAIT_BO, struct drm_panfrost_wait_bo) ··· 30 29 #define DRM_IOCTL_PANFROST_GET_PARAM DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_GET_PARAM, struct drm_panfrost_get_param) 31 30 #define DRM_IOCTL_PANFROST_GET_BO_OFFSET DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_GET_BO_OFFSET, struct drm_panfrost_get_bo_offset) 32 31 #define DRM_IOCTL_PANFROST_MADVISE DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_MADVISE, struct drm_panfrost_madvise) 32 + #define DRM_IOCTL_PANFROST_SET_LABEL_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_SET_LABEL_BO, struct drm_panfrost_set_label_bo) 33 33 34 34 /* 35 35 * Unstable ioctl(s): only exposed when the unsafe unstable_ioctls module ··· 227 225 __u32 handle; /* in, GEM handle */ 228 226 __u32 madv; /* in, PANFROST_MADV_x */ 229 227 __u32 retained; /* out, whether backing store still exists */ 228 + }; 229 + 230 + /** 231 + * struct drm_panfrost_set_label_bo - ioctl argument for labelling Panfrost BOs. 232 + */ 233 + struct drm_panfrost_set_label_bo { 234 + /** @handle: Handle of the buffer object to label. */ 235 + __u32 handle; 236 + 237 + /** @pad: MBZ. */ 238 + __u32 pad; 239 + 240 + /** 241 + * @label: User pointer to a NUL-terminated string 242 + * 243 + * Length cannot be greater than 4096. 244 + * NULL is permitted and means clear the label. 245 + */ 246 + __u64 label; 230 247 }; 231 248 232 249 /* Definitions for coredump decoding in user space */