Re: [PATCH drm-next v4 14/14] drm/nouveau: debugfs: implement DRM GPU VA debugfs

2023-06-13 Thread Liam R. Howlett
* Danilo Krummrich  [230606 18:32]:
> Provide the driver indirection iterating over all DRM GPU VA spaces to
> enable the common 'gpuvas' debugfs file for dumping DRM GPU VA spaces.
> 
> Signed-off-by: Danilo Krummrich 
> ---
>  drivers/gpu/drm/nouveau/nouveau_debugfs.c | 39 +++
>  1 file changed, 39 insertions(+)
> 
> diff --git a/drivers/gpu/drm/nouveau/nouveau_debugfs.c 
> b/drivers/gpu/drm/nouveau/nouveau_debugfs.c
> index 99d022a91afc..053f703f2f68 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_debugfs.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_debugfs.c
> @@ -203,6 +203,44 @@ nouveau_debugfs_pstate_open(struct inode *inode, struct 
> file *file)
>   return single_open(file, nouveau_debugfs_pstate_get, inode->i_private);
>  }
>  
> +static void
> +nouveau_debugfs_gpuva_regions(struct seq_file *m, struct nouveau_uvmm *uvmm)
> +{
> + MA_STATE(mas, >region_mt, 0, 0);
> + struct nouveau_uvma_region *reg;
> +
> + seq_puts  (m, " VA regions  | start  | range  | 
> end\n");
> + seq_puts  (m, 
> "\n");

rcu_read_lock();

> + mas_for_each(, reg, ULONG_MAX)
> + seq_printf(m, " | 0x%016llx | 0x%016llx | 
> 0x%016llx\n",
> +reg->va.addr, reg->va.range, reg->va.addr + 
> reg->va.range);

rcu_read_unlock();

> +}
> +
> +static int
> +nouveau_debugfs_gpuva(struct seq_file *m, void *data)
> +{
> + struct drm_info_node *node = (struct drm_info_node *) m->private;
> + struct nouveau_drm *drm = nouveau_drm(node->minor->dev);
> + struct nouveau_cli *cli;
> +
> + mutex_lock(>clients_lock);
> + list_for_each_entry(cli, >clients, head) {
> + struct nouveau_uvmm *uvmm = nouveau_cli_uvmm(cli);
> +
> + if (!uvmm)
> + continue;
> +
> + nouveau_uvmm_lock(uvmm);
> + drm_debugfs_gpuva_info(m, >umgr);
> + seq_puts(m, "\n");
> + nouveau_debugfs_gpuva_regions(m, uvmm);
> + nouveau_uvmm_unlock(uvmm);
> + }
> + mutex_unlock(>clients_lock);
> +
> + return 0;
> +}
> +
>  static const struct file_operations nouveau_pstate_fops = {
>   .owner = THIS_MODULE,
>   .open = nouveau_debugfs_pstate_open,
> @@ -214,6 +252,7 @@ static const struct file_operations nouveau_pstate_fops = 
> {
>  static struct drm_info_list nouveau_debugfs_list[] = {
>   { "vbios.rom",  nouveau_debugfs_vbios_image, 0, NULL },
>   { "strap_peek", nouveau_debugfs_strap_peek, 0, NULL },
> + DRM_DEBUGFS_GPUVA_INFO(nouveau_debugfs_gpuva, NULL),
>  };
>  #define NOUVEAU_DEBUGFS_ENTRIES ARRAY_SIZE(nouveau_debugfs_list)
>  
> -- 
> 2.40.1
> 


[PATCH drm-next v4 14/14] drm/nouveau: debugfs: implement DRM GPU VA debugfs

2023-06-06 Thread Danilo Krummrich
Provide the driver indirection iterating over all DRM GPU VA spaces to
enable the common 'gpuvas' debugfs file for dumping DRM GPU VA spaces.

Signed-off-by: Danilo Krummrich 
---
 drivers/gpu/drm/nouveau/nouveau_debugfs.c | 39 +++
 1 file changed, 39 insertions(+)

diff --git a/drivers/gpu/drm/nouveau/nouveau_debugfs.c 
b/drivers/gpu/drm/nouveau/nouveau_debugfs.c
index 99d022a91afc..053f703f2f68 100644
--- a/drivers/gpu/drm/nouveau/nouveau_debugfs.c
+++ b/drivers/gpu/drm/nouveau/nouveau_debugfs.c
@@ -203,6 +203,44 @@ nouveau_debugfs_pstate_open(struct inode *inode, struct 
file *file)
return single_open(file, nouveau_debugfs_pstate_get, inode->i_private);
 }
 
+static void
+nouveau_debugfs_gpuva_regions(struct seq_file *m, struct nouveau_uvmm *uvmm)
+{
+   MA_STATE(mas, >region_mt, 0, 0);
+   struct nouveau_uvma_region *reg;
+
+   seq_puts  (m, " VA regions  | start  | range  | 
end\n");
+   seq_puts  (m, 
"\n");
+   mas_for_each(, reg, ULONG_MAX)
+   seq_printf(m, " | 0x%016llx | 0x%016llx | 
0x%016llx\n",
+  reg->va.addr, reg->va.range, reg->va.addr + 
reg->va.range);
+}
+
+static int
+nouveau_debugfs_gpuva(struct seq_file *m, void *data)
+{
+   struct drm_info_node *node = (struct drm_info_node *) m->private;
+   struct nouveau_drm *drm = nouveau_drm(node->minor->dev);
+   struct nouveau_cli *cli;
+
+   mutex_lock(>clients_lock);
+   list_for_each_entry(cli, >clients, head) {
+   struct nouveau_uvmm *uvmm = nouveau_cli_uvmm(cli);
+
+   if (!uvmm)
+   continue;
+
+   nouveau_uvmm_lock(uvmm);
+   drm_debugfs_gpuva_info(m, >umgr);
+   seq_puts(m, "\n");
+   nouveau_debugfs_gpuva_regions(m, uvmm);
+   nouveau_uvmm_unlock(uvmm);
+   }
+   mutex_unlock(>clients_lock);
+
+   return 0;
+}
+
 static const struct file_operations nouveau_pstate_fops = {
.owner = THIS_MODULE,
.open = nouveau_debugfs_pstate_open,
@@ -214,6 +252,7 @@ static const struct file_operations nouveau_pstate_fops = {
 static struct drm_info_list nouveau_debugfs_list[] = {
{ "vbios.rom",  nouveau_debugfs_vbios_image, 0, NULL },
{ "strap_peek", nouveau_debugfs_strap_peek, 0, NULL },
+   DRM_DEBUGFS_GPUVA_INFO(nouveau_debugfs_gpuva, NULL),
 };
 #define NOUVEAU_DEBUGFS_ENTRIES ARRAY_SIZE(nouveau_debugfs_list)
 
-- 
2.40.1