drm/exynos: add debugfs interface and gem_info node 15/219515/1 accepted/tizen/unified/20191206.121231 submit/tizen/20191206.054449
authorSeung-Woo Kim <sw0312.kim@samsung.com>
Thu, 5 Dec 2019 10:16:13 +0000 (19:16 +0900)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Thu, 5 Dec 2019 11:39:33 +0000 (20:39 +0900)
The memps requires gem_info with gem_names to analyze graphics
shared memory, so this patch adds gem_info node with debugfs
interface.

Change-Id: I467527da85978b7a07ec638139cec02ea29b6297
Signed-off-by: YoungJun Cho <yj44.cho@samsung.com>
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
drivers/gpu/drm/exynos/Makefile
drivers/gpu/drm/exynos/exynos_drm_debugfs.c [new file with mode: 0644]
drivers/gpu/drm/exynos/exynos_drm_debugfs.h [new file with mode: 0644]
drivers/gpu/drm/exynos/exynos_drm_drv.c
drivers/gpu/drm/exynos/exynos_drm_drv.h

index 3b323f1..2065e1d 100644 (file)
@@ -24,5 +24,6 @@ exynosdrm-$(CONFIG_DRM_EXYNOS_ROTATOR)        += exynos_drm_rotator.o
 exynosdrm-$(CONFIG_DRM_EXYNOS_SCALER)  += exynos_drm_scaler.o
 exynosdrm-$(CONFIG_DRM_EXYNOS_GSC)     += exynos_drm_gsc.o
 exynosdrm-$(CONFIG_DRM_EXYNOS_MIC)     += exynos_drm_mic.o
+exynosdrm-$(CONFIG_DEBUG_FS)           += exynos_drm_debugfs.o
 
 obj-$(CONFIG_DRM_EXYNOS)               += exynosdrm.o
diff --git a/drivers/gpu/drm/exynos/exynos_drm_debugfs.c b/drivers/gpu/drm/exynos/exynos_drm_debugfs.c
new file mode 100644 (file)
index 0000000..375ccab
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd
+ * Author: YoungJun Cho <yj44.cho@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+*/
+
+#include <drm/drmP.h>
+
+#include <linux/debugfs.h>
+
+#include "exynos_drm_drv.h"
+#include "exynos_drm_gem.h"
+
+struct exynos_drm_debugfs_gem_info_data {
+       struct drm_file *filp;
+       struct seq_file *m;
+};
+
+static int exynos_drm_debugfs_gem_one_info(int id, void *ptr, void *data)
+{
+       struct exynos_drm_debugfs_gem_info_data *gem_info_data =
+                               (struct exynos_drm_debugfs_gem_info_data *)data;
+       struct drm_file *filp = gem_info_data->filp;
+       struct drm_exynos_file_private *file_priv = filp->driver_priv;
+       struct drm_gem_object *obj = (struct drm_gem_object *)ptr;
+       struct exynos_drm_gem *exynos_gem = to_exynos_gem(obj);
+
+       seq_printf(gem_info_data->m,
+                       "%5d\t%5d\t%4d\t%4d\t%4d\t0x%08lx\t0x%x\t%4d\t%4d\t"
+                       "%4d\t0x%p\n",
+                               pid_nr(filp->pid),
+                               file_priv->tgid,
+                               id,
+                               kref_read(&obj->refcount),
+                               obj->handle_count,
+                               exynos_gem->size,
+                               exynos_gem->flags,
+                               0,
+                               obj->dma_buf ? 1 : 0,
+                               obj->import_attach ? 1 : 0,
+                               obj);
+
+       return 0;
+}
+
+static int exynos_drm_debugfs_gem_info(struct seq_file *m, void *data)
+{
+       struct drm_info_node *node = (struct drm_info_node *)m->private;
+       struct drm_minor *minor = node->minor;
+       struct drm_device *drm_dev = minor->dev;
+       struct exynos_drm_debugfs_gem_info_data gem_info_data;
+       struct drm_file *filp;
+
+       gem_info_data.m = m;
+
+       seq_puts(m, "pid\ttgid\thandle\tref_cnt\thdl_cnt\tsize\t\tflags\t"
+                       "pfnmap\texport\timport\tobj_addr\n");
+
+       mutex_lock(&drm_dev->struct_mutex);
+       list_for_each_entry(filp, &drm_dev->filelist, lhead) {
+               gem_info_data.filp = filp;
+
+               spin_lock(&filp->table_lock);
+               idr_for_each(&filp->object_idr, exynos_drm_debugfs_gem_one_info,
+                               &gem_info_data);
+               spin_unlock(&filp->table_lock);
+       }
+       mutex_unlock(&drm_dev->struct_mutex);
+
+       return 0;
+}
+
+static struct drm_info_list exynos_drm_debugfs_list[] = {
+       {"gem_info",    exynos_drm_debugfs_gem_info,    DRIVER_GEM},
+};
+#define EXYNOS_DRM_DEBUGFS_ENTRIES     ARRAY_SIZE(exynos_drm_debugfs_list)
+
+int exynos_drm_debugfs_init(struct drm_minor *minor)
+{
+       return drm_debugfs_create_files(exynos_drm_debugfs_list,
+                                       EXYNOS_DRM_DEBUGFS_ENTRIES,
+                                       minor->debugfs_root, minor);
+}
diff --git a/drivers/gpu/drm/exynos/exynos_drm_debugfs.h b/drivers/gpu/drm/exynos/exynos_drm_debugfs.h
new file mode 100644 (file)
index 0000000..5dccc79
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2014 Samsung Electronics Co.Ltd
+ * Author: YoungJun Cho <yj44.cho@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundationr
+ */
+
+#ifndef _EXYNOS_DRM_DEBUGFS_H_
+#define _EXYNOS_DRM_DEBUGFS_H_
+
+#if defined(CONFIG_DEBUG_FS)
+extern int exynos_drm_debugfs_init(struct drm_minor *minor);
+#else
+static inline int exynos_drm_debugfs_init(struct drm_minor *minor)
+{
+       return 0;
+}
+#endif
+
+#endif /* _EXYNOS_DRM_DEBUGFS_H_ */
index 80d12ef..8c1fc20 100644 (file)
@@ -30,6 +30,7 @@
 #include "exynos_drm_vidi.h"
 #include "exynos_drm_g2d.h"
 #include "exynos_drm_iommu.h"
+#include "exynos_drm_debugfs.h"
 
 #define DRIVER_NAME    "exynos"
 #define DRIVER_DESC    "Samsung SoC DRM"
@@ -73,6 +74,10 @@ static int exynos_drm_open(struct drm_device *dev, struct drm_file *file)
        if (!file_priv)
                return -ENOMEM;
 
+#if defined(CONFIG_DEBUG_FS)
+       file_priv->tgid = task_tgid_nr(current);
+#endif
+
        file->driver_priv = file_priv;
 
        ret = exynos_drm_subdrv_open(dev, file);
@@ -149,6 +154,9 @@ static struct drm_driver exynos_drm_driver = {
        .open                   = exynos_drm_open,
        .lastclose              = exynos_drm_lastclose,
        .postclose              = exynos_drm_postclose,
+#if defined(CONFIG_DEBUG_FS)
+       .debugfs_init           = exynos_drm_debugfs_init,
+#endif
        .gem_free_object_unlocked = exynos_drm_gem_free_object,
        .gem_vm_ops             = &exynos_drm_gem_vm_ops,
        .dumb_create            = exynos_drm_gem_dumb_create,
index 309da10..1732c66 100644 (file)
@@ -187,6 +187,9 @@ struct exynos_drm_g2d_private {
 
 struct drm_exynos_file_private {
        struct exynos_drm_g2d_private   *g2d_priv;
+#if defined(CONFIG_DEBUG_FS)
+       pid_t                           tgid;
+#endif
 };
 
 /*