Skip to content

Commit 4f66fee

Browse files
committed
drm: debugfs: provide infrastructure to dump a DRM GPU VA space
This commit adds a function to dump a DRM GPU VA space and a macro for drivers to register the struct drm_info_list 'gpuvas' entry. Most likely, most drivers might maintain one DRM GPU VA space per struct drm_file, but there might also be drivers not having a fixed relation between DRM GPU VA spaces and a DRM core infrastructure, hence we need the indirection via the driver iterating it's maintained DRM GPU VA spaces. Reviewed-by: Boris Brezillon <[email protected]> Signed-off-by: Danilo Krummrich <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent e6303f3 commit 4f66fee

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

drivers/gpu/drm/drm_debugfs.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include <drm/drm_file.h>
4040
#include <drm/drm_gem.h>
4141
#include <drm/drm_managed.h>
42+
#include <drm/drm_gpuva_mgr.h>
4243

4344
#include "drm_crtc_internal.h"
4445
#include "drm_internal.h"
@@ -175,6 +176,45 @@ static const struct file_operations drm_debugfs_fops = {
175176
.release = single_release,
176177
};
177178

179+
/**
180+
* drm_debugfs_gpuva_info - dump the given DRM GPU VA space
181+
* @m: pointer to the &seq_file to write
182+
* @mgr: the &drm_gpuva_manager representing the GPU VA space
183+
*
184+
* Dumps the GPU VA mappings of a given DRM GPU VA manager.
185+
*
186+
* For each DRM GPU VA space drivers should call this function from their
187+
* &drm_info_list's show callback.
188+
*
189+
* Returns: 0 on success, -ENODEV if the &mgr is not initialized
190+
*/
191+
int drm_debugfs_gpuva_info(struct seq_file *m,
192+
struct drm_gpuva_manager *mgr)
193+
{
194+
struct drm_gpuva *va, *kva = &mgr->kernel_alloc_node;
195+
196+
if (!mgr->name)
197+
return -ENODEV;
198+
199+
seq_printf(m, "DRM GPU VA space (%s) [0x%016llx;0x%016llx]\n",
200+
mgr->name, mgr->mm_start, mgr->mm_start + mgr->mm_range);
201+
seq_printf(m, "Kernel reserved node [0x%016llx;0x%016llx]\n",
202+
kva->va.addr, kva->va.addr + kva->va.range);
203+
seq_puts(m, "\n");
204+
seq_puts(m, " VAs | start | range | end | object | object offset\n");
205+
seq_puts(m, "-------------------------------------------------------------------------------------------------------------\n");
206+
drm_gpuva_for_each_va(va, mgr) {
207+
if (unlikely(va == kva))
208+
continue;
209+
210+
seq_printf(m, " | 0x%016llx | 0x%016llx | 0x%016llx | 0x%016llx | 0x%016llx\n",
211+
va->va.addr, va->va.range, va->va.addr + va->va.range,
212+
(u64)va->gem.obj, va->gem.offset);
213+
}
214+
215+
return 0;
216+
}
217+
EXPORT_SYMBOL(drm_debugfs_gpuva_info);
178218

179219
/**
180220
* drm_debugfs_create_files - Initialize a given set of debugfs files for DRM

include/drm/drm_debugfs.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,22 @@
3434

3535
#include <linux/types.h>
3636
#include <linux/seq_file.h>
37+
38+
#include <drm/drm_gpuva_mgr.h>
39+
40+
/**
41+
* DRM_DEBUGFS_GPUVA_INFO - &drm_info_list entry to dump a GPU VA space
42+
* @show: the &drm_info_list's show callback
43+
* @data: driver private data
44+
*
45+
* Drivers should use this macro to define a &drm_info_list entry to provide a
46+
* debugfs file for dumping the GPU VA space regions and mappings.
47+
*
48+
* For each DRM GPU VA space drivers should call drm_debugfs_gpuva_info() from
49+
* their @show callback.
50+
*/
51+
#define DRM_DEBUGFS_GPUVA_INFO(show, data) {"gpuvas", show, DRIVER_GEM_GPUVA, data}
52+
3753
/**
3854
* struct drm_info_list - debugfs info list entry
3955
*
@@ -134,6 +150,9 @@ void drm_debugfs_add_file(struct drm_device *dev, const char *name,
134150

135151
void drm_debugfs_add_files(struct drm_device *dev,
136152
const struct drm_debugfs_info *files, int count);
153+
154+
int drm_debugfs_gpuva_info(struct seq_file *m,
155+
struct drm_gpuva_manager *mgr);
137156
#else
138157
static inline void drm_debugfs_create_files(const struct drm_info_list *files,
139158
int count, struct dentry *root,
@@ -155,6 +174,12 @@ static inline void drm_debugfs_add_files(struct drm_device *dev,
155174
const struct drm_debugfs_info *files,
156175
int count)
157176
{}
177+
178+
static inline int drm_debugfs_gpuva_info(struct seq_file *m,
179+
struct drm_gpuva_manager *mgr)
180+
{
181+
return 0;
182+
}
158183
#endif
159184

160185
#endif /* _DRM_DEBUGFS_H_ */

0 commit comments

Comments
 (0)