diff options
author | Hoegeun Kwon <hoegeun.kwon@gmail.com> | 2022-12-19 15:57:39 +0900 |
---|---|---|
committer | Jaehoon Chung <jh80.chung@samsung.com> | 2024-11-12 13:03:14 +0900 |
commit | 98cac7ec3384adcf5a903c9f713fe49ef98287d0 (patch) | |
tree | 30533799da3814c9b0dc16175b30596b155b7ce9 | |
parent | ae577c193d1cc051e7497c3bef2a296b2c40bfe4 (diff) | |
download | linux-rpi-98cac7ec3384adcf5a903c9f713fe49ef98287d0.tar.gz linux-rpi-98cac7ec3384adcf5a903c9f713fe49ef98287d0.tar.bz2 linux-rpi-98cac7ec3384adcf5a903c9f713fe49ef98287d0.zip |
drm/vc4: Add gem_info node via debugfs for vc5
The memps requires gem_info with gem_names to analyze graphics shared
memory, so this patch adds gem_info node via common helpers for
debugfs.
Let's save pid/tgid in private file data only once when gem object is
created or prime_fd is imported and use them on gem_info. This is to
solve the wrong pid problem of gem_info created as different processes
share fd of drm device node.
The prime fd created in vc4, but handled in v3d, modified to hanle
this in vc4.
Signed-off-by: Hoegeun Kwon <hoegeun.kwon@samsung.com>
[mszyprow: ported and adapted to v6.6 kernel release]
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Change-Id: I1430eadbfbdfc197f8e39f952e7f82999e249672
-rw-r--r-- | drivers/gpu/drm/vc4/vc4_debugfs.c | 73 | ||||
-rw-r--r-- | drivers/gpu/drm/vc4/vc4_drv.c | 77 | ||||
-rw-r--r-- | drivers/gpu/drm/vc4/vc4_drv.h | 9 |
3 files changed, 158 insertions, 1 deletions
diff --git a/drivers/gpu/drm/vc4/vc4_debugfs.c b/drivers/gpu/drm/vc4/vc4_debugfs.c index 8144dedf2248..b553901e7aab 100644 --- a/drivers/gpu/drm/vc4/vc4_debugfs.c +++ b/drivers/gpu/drm/vc4/vc4_debugfs.c @@ -27,6 +27,10 @@ vc4_debugfs_init(struct drm_minor *minor) if (vc4->hvs) drm_WARN_ON(drm, vc4_hvs_debugfs_init(minor)); + if (vc4->gen > VC4_GEN_4) { + drm_WARN_ON(drm, vc5_bo_debugfs_init(minor)); + } + if (vc4->v3d) { drm_WARN_ON(drm, vc4_bo_debugfs_init(minor)); drm_WARN_ON(drm, vc4_v3d_debugfs_init(minor)); @@ -51,6 +55,75 @@ static int vc4_debugfs_regset32(struct seq_file *m, void *unused) return 0; } +struct vc5_gem_info_data { + struct drm_file *filp; + struct seq_file *m; +}; + +static int vc5_gem_one_info(int id, void *ptr, void *data) +{ + + struct drm_gem_object *obj = (struct drm_gem_object *)ptr; + struct vc5_gem_info_data *gem_info_data = data; + struct vc4_file *vc4file = gem_info_data->filp->driver_priv; + struct drm_vc5_file_private *file_priv = &vc4file->priv; + + if (!obj) { + DRM_ERROR("failed to get drm_gem_object\n"); + return -EFAULT; + } + + drm_gem_object_get(obj); + + seq_printf(gem_info_data->m, + "%5d\t%5d\t%4d\t%4d\t\t%4d\t0x%08zx\t0x%x\t%4d\t%4d\t\t" + "%4d\t\t0x%p\t%6d\n", + file_priv->pid, + file_priv->tgid, + id, + kref_read(&obj->refcount) - 1, + obj->handle_count, + obj->size, + 0, + 0, + obj->dma_buf ? 1 : 0, + obj->import_attach ? 1 : 0, + obj, + obj->name); + + drm_gem_object_put(obj); + + return 0; +} + +int vc5_debugfs_gem_info(struct seq_file *m, void *data) +{ + struct drm_debugfs_entry *entry = m->private; + struct drm_device *drm_dev = entry->dev; + struct vc5_gem_info_data gem_info_data; + struct drm_file *filp; + + gem_info_data.m = m; + + seq_puts(gem_info_data.m, + "pid\ttgid\thandle\trefcount\thcount\tsize\t\tflags\t" + "pfnmap\texport_to_fd\timport_from_fd\tobj_addr\t\t" + "name\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, vc5_gem_one_info, + &gem_info_data); + spin_unlock(&filp->table_lock); + } + mutex_unlock(&drm_dev->struct_mutex); + + return 0; +} + void vc4_debugfs_add_regset32(struct drm_device *drm, const char *name, struct debugfs_regset32 *regset) diff --git a/drivers/gpu/drm/vc4/vc4_drv.c b/drivers/gpu/drm/vc4/vc4_drv.c index 220e8625402b..6e23a686b119 100644 --- a/drivers/gpu/drm/vc4/vc4_drv.c +++ b/drivers/gpu/drm/vc4/vc4_drv.c @@ -76,6 +76,41 @@ int vc4_dumb_fixup_args(struct drm_mode_create_dumb *args) return 0; } +static void vc5_gem_register_pid(struct drm_file *file_priv) +{ + struct vc4_file *vc4file = file_priv->driver_priv; + struct drm_vc5_file_private *driver_priv = &vc4file->priv; + + if (!driver_priv->pid && !driver_priv->tgid) { + driver_priv->pid = task_pid_nr(current); + driver_priv->tgid = task_tgid_nr(current); + } else { + if (driver_priv->pid != task_pid_nr(current)) + DRM_DEBUG_KMS("wrong pid: %ld, %ld\n", + (unsigned long)driver_priv->pid, + (unsigned long)task_pid_nr(current)); + if (driver_priv->tgid != task_tgid_nr(current)) + DRM_DEBUG_KMS("wrong tgid: %ld, %ld\n", + (unsigned long)driver_priv->tgid, + (unsigned long)task_tgid_nr(current)); + } +} + +int vc5_drm_gem_prime_fd_to_handle(struct drm_device *dev, + struct drm_file *file_priv, int prime_fd, + uint32_t *handle) +{ + int ret; + + ret = drm_gem_prime_fd_to_handle(dev, file_priv, prime_fd, handle); + if (ret < 0) + return ret; + + vc5_gem_register_pid(file_priv); + + return ret; +} + static int vc5_dumb_create(struct drm_file *file_priv, struct drm_device *dev, struct drm_mode_create_dumb *args) @@ -86,7 +121,11 @@ static int vc5_dumb_create(struct drm_file *file_priv, if (ret) return ret; - return drm_gem_dma_dumb_create_internal(file_priv, dev, args); + ret = drm_gem_dma_dumb_create_internal(file_priv, dev, args); + if (!ret) + vc5_gem_register_pid(file_priv); + + return ret; } static int vc4_get_param_ioctl(struct drm_device *dev, void *data, @@ -189,6 +228,27 @@ vc4_prime_import_sg_table(struct drm_device *dev, return drm_gem_dma_prime_import_sg_table(dev, attach, sgt); } +static int vc5_open(struct drm_device *dev, struct drm_file *file) +{ + struct vc4_dev *vc4 = to_vc4_dev(dev); + struct vc4_file *vc4file; + + vc4file = kzalloc(sizeof(*vc4file), GFP_KERNEL); + if (!vc4file) + return -ENOMEM; + vc4file->dev = vc4; + + file->driver_priv = vc4file; + return 0; +} + +static void vc5_close(struct drm_device *dev, struct drm_file *file) +{ + struct vc4_file *vc4file = file->driver_priv; + + kfree(vc4file); +} + DEFINE_DRM_GEM_FOPS(vc4_drm_fops); static const struct drm_ioctl_desc vc4_drm_ioctls[] = { @@ -245,6 +305,8 @@ const struct drm_driver vc5_drm_driver = { DRIVER_ATOMIC | DRIVER_GEM), + .open = vc5_open, + .postclose = vc5_close, #if defined(CONFIG_DEBUG_FS) .debugfs_init = vc4_debugfs_init, #endif @@ -252,6 +314,7 @@ const struct drm_driver vc5_drm_driver = { .dumb_create = vc5_dumb_create, .gem_prime_import_sg_table = vc4_prime_import_sg_table, + .prime_fd_to_handle = vc5_drm_gem_prime_fd_to_handle, .fops = &vc4_drm_fops, .name = DRIVER_NAME, @@ -312,6 +375,18 @@ static bool firmware_kms(void) "raspberrypi,rpi-firmware-kms-2711")); } +int vc5_bo_debugfs_init(struct drm_minor *minor) +{ + struct drm_device *drm = minor->dev; + struct vc4_dev *vc4 = to_vc4_dev(drm); + + if (vc4->gen == VC4_GEN_4) + return -ENODEV; + + drm_debugfs_add_file(drm, "gem_info", vc5_debugfs_gem_info, NULL); + return 0; +} + static int vc4_drm_bind(struct device *dev) { struct platform_device *pdev = to_platform_device(dev); diff --git a/drivers/gpu/drm/vc4/vc4_drv.h b/drivers/gpu/drm/vc4/vc4_drv.h index 0868cdbf1fce..58888727c278 100644 --- a/drivers/gpu/drm/vc4/vc4_drv.h +++ b/drivers/gpu/drm/vc4/vc4_drv.h @@ -872,6 +872,11 @@ struct vc4_exec_info { bool bin_bo_used; }; +struct drm_vc5_file_private { + pid_t pid; + pid_t tgid; +}; + /* Per-open file private data. Any driver-specific resource that has to be * released when the DRM file is closed should be placed here. */ @@ -884,6 +889,7 @@ struct vc4_file { } perfmon; bool bin_bo_used; + struct drm_vc5_file_private priv; }; static inline struct vc4_exec_info * @@ -1014,6 +1020,7 @@ void vc4_bo_dec_usecnt(struct vc4_bo *bo); void vc4_bo_add_to_purgeable_pool(struct vc4_bo *bo); void vc4_bo_remove_from_purgeable_pool(struct vc4_bo *bo); int vc4_bo_debugfs_init(struct drm_minor *minor); +int vc5_bo_debugfs_init(struct drm_minor *minor); /* vc4_crtc.c */ extern struct platform_driver vc4_crtc_driver; @@ -1186,6 +1193,8 @@ bool vc4_check_tex_size(struct vc4_exec_info *exec, struct vc4_validated_shader_info * vc4_validate_shader(struct drm_gem_dma_object *shader_obj); +int vc5_debugfs_gem_info(struct seq_file *m, void *data); + /* vc4_perfmon.c */ void vc4_perfmon_get(struct vc4_perfmon *perfmon); void vc4_perfmon_put(struct vc4_perfmon *perfmon); |