drm/msm: add uapi to get/set debug name
authorRob Clark <robdclark@gmail.com>
Thu, 29 Nov 2018 15:27:22 +0000 (10:27 -0500)
committerRob Clark <robdclark@gmail.com>
Tue, 11 Dec 2018 18:07:05 +0000 (13:07 -0500)
Add UAPI to get/set GEM objects' debug name.

Signed-off-by: Rob Clark <robdclark@gmail.com>
drivers/gpu/drm/msm/msm_drv.c
include/uapi/drm/msm_drm.h

index fe86c675d5b78d08bec589aa276ea3fe14a51603..c08f83c7ca5793c4126389b6aa15e96978d95f59 100644 (file)
@@ -23,6 +23,7 @@
 #include "msm_drv.h"
 #include "msm_debugfs.h"
 #include "msm_fence.h"
+#include "msm_gem.h"
 #include "msm_gpu.h"
 #include "msm_kms.h"
 
@@ -880,7 +881,8 @@ static int msm_ioctl_gem_info(struct drm_device *dev, void *data,
 {
        struct drm_msm_gem_info *args = data;
        struct drm_gem_object *obj;
-       int ret = 0;
+       struct msm_gem_object *msm_obj;
+       int i, ret = 0;
 
        if (args->pad)
                return -EINVAL;
@@ -892,6 +894,9 @@ static int msm_ioctl_gem_info(struct drm_device *dev, void *data,
                if (args->len)
                        return -EINVAL;
                break;
+       case MSM_INFO_SET_NAME:
+       case MSM_INFO_GET_NAME:
+               break;
        default:
                return -EINVAL;
        }
@@ -900,6 +905,8 @@ static int msm_ioctl_gem_info(struct drm_device *dev, void *data,
        if (!obj)
                return -ENOENT;
 
+       msm_obj = to_msm_bo(obj);
+
        switch (args->info) {
        case MSM_INFO_GET_OFFSET:
                args->value = msm_gem_mmap_offset(obj);
@@ -907,6 +914,33 @@ static int msm_ioctl_gem_info(struct drm_device *dev, void *data,
        case MSM_INFO_GET_IOVA:
                ret = msm_ioctl_gem_info_iova(dev, obj, &args->value);
                break;
+       case MSM_INFO_SET_NAME:
+               /* length check should leave room for terminating null: */
+               if (args->len >= sizeof(msm_obj->name)) {
+                       ret = -EINVAL;
+                       break;
+               }
+               ret = copy_from_user(msm_obj->name,
+                       u64_to_user_ptr(args->value), args->len);
+               msm_obj->name[args->len] = '\0';
+               for (i = 0; i < args->len; i++) {
+                       if (!isprint(msm_obj->name[i])) {
+                               msm_obj->name[i] = '\0';
+                               break;
+                       }
+               }
+               break;
+       case MSM_INFO_GET_NAME:
+               if (args->value && (args->len < strlen(msm_obj->name))) {
+                       ret = -EINVAL;
+                       break;
+               }
+               args->len = strlen(msm_obj->name);
+               if (args->value) {
+                       ret = copy_to_user(u64_to_user_ptr(args->value),
+                                       msm_obj->name, args->len);
+               }
+               break;
        }
 
        drm_gem_object_put_unlocked(obj);
index 7b372c1bcc7d27e1c784f4dd1113849669586d9f..91a16b333c69005417b9314d192b0db0eac43b19 100644 (file)
@@ -114,6 +114,8 @@ struct drm_msm_gem_new {
  */
 #define MSM_INFO_GET_OFFSET    0x00   /* get mmap() offset, returned by value */
 #define MSM_INFO_GET_IOVA      0x01   /* get iova, returned by value */
+#define MSM_INFO_SET_NAME      0x02   /* set the debug name (by pointer) */
+#define MSM_INFO_GET_NAME      0x03   /* get debug name, returned by pointer */
 
 struct drm_msm_gem_info {
        __u32 handle;         /* in */