Commit b5c3714f authored by Daniel Vetter's avatar Daniel Vetter

drm/mm: Convert to drm_printer

Including all drivers. I thought about keeping small compat functions
to avoid having to change all drivers. But I really like the
drm_printer idea, so figured spreading it more widely is a good thing.

v2: Review from Chris:
- Natural argument order and better name for drm_mm_print.
- show_mm() macro in the selftest.

Cc: Rob Clark <robdclark@gmail.com>
Cc: Russell King <rmk+kernel@armlinux.org.uk>
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: Christian König <christian.koenig@amd.com>
Cc: Lucas Stach <l.stach@pengutronix.de>
Cc: Tomi Valkeinen <tomi.valkeinen@ti.com>
Cc: Thierry Reding <thierry.reding@gmail.com>
Cc: Jyri Sarha <jsarha@ti.com>
Reviewed-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: default avatarDaniel Vetter <daniel.vetter@intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/1483009764-8281-1-git-send-email-daniel.vetter@ffwll.ch
parent 3d387d92
...@@ -235,9 +235,10 @@ static void amdgpu_gtt_mgr_debug(struct ttm_mem_type_manager *man, ...@@ -235,9 +235,10 @@ static void amdgpu_gtt_mgr_debug(struct ttm_mem_type_manager *man,
const char *prefix) const char *prefix)
{ {
struct amdgpu_gtt_mgr *mgr = man->priv; struct amdgpu_gtt_mgr *mgr = man->priv;
struct drm_printer p = drm_debug_printer(prefix);
spin_lock(&mgr->lock); spin_lock(&mgr->lock);
drm_mm_debug_table(&mgr->mm, prefix); drm_mm_print(&mgr->mm, &p);
spin_unlock(&mgr->lock); spin_unlock(&mgr->lock);
} }
......
...@@ -1482,18 +1482,18 @@ static int amdgpu_mm_dump_table(struct seq_file *m, void *data) ...@@ -1482,18 +1482,18 @@ static int amdgpu_mm_dump_table(struct seq_file *m, void *data)
struct drm_device *dev = node->minor->dev; struct drm_device *dev = node->minor->dev;
struct amdgpu_device *adev = dev->dev_private; struct amdgpu_device *adev = dev->dev_private;
struct drm_mm *mm = (struct drm_mm *)adev->mman.bdev.man[ttm_pl].priv; struct drm_mm *mm = (struct drm_mm *)adev->mman.bdev.man[ttm_pl].priv;
int ret;
struct ttm_bo_global *glob = adev->mman.bdev.glob; struct ttm_bo_global *glob = adev->mman.bdev.glob;
struct drm_printer p = drm_seq_file_printer(m);
spin_lock(&glob->lru_lock); spin_lock(&glob->lru_lock);
ret = drm_mm_dump_table(m, mm); drm_mm_print(mm, &p);
spin_unlock(&glob->lru_lock); spin_unlock(&glob->lru_lock);
if (ttm_pl == TTM_PL_VRAM) if (ttm_pl == TTM_PL_VRAM)
seq_printf(m, "man size:%llu pages, ram usage:%lluMB, vis usage:%lluMB\n", seq_printf(m, "man size:%llu pages, ram usage:%lluMB, vis usage:%lluMB\n",
adev->mman.bdev.man[ttm_pl].size, adev->mman.bdev.man[ttm_pl].size,
(u64)atomic64_read(&adev->vram_usage) >> 20, (u64)atomic64_read(&adev->vram_usage) >> 20,
(u64)atomic64_read(&adev->vram_vis_usage) >> 20); (u64)atomic64_read(&adev->vram_vis_usage) >> 20);
return ret; return 0;
} }
static int ttm_pl_vram = TTM_PL_VRAM; static int ttm_pl_vram = TTM_PL_VRAM;
......
...@@ -207,9 +207,10 @@ static void amdgpu_vram_mgr_debug(struct ttm_mem_type_manager *man, ...@@ -207,9 +207,10 @@ static void amdgpu_vram_mgr_debug(struct ttm_mem_type_manager *man,
const char *prefix) const char *prefix)
{ {
struct amdgpu_vram_mgr *mgr = man->priv; struct amdgpu_vram_mgr *mgr = man->priv;
struct drm_printer p = drm_debug_printer(prefix);
spin_lock(&mgr->lock); spin_lock(&mgr->lock);
drm_mm_debug_table(&mgr->mm, prefix); drm_mm_print(&mgr->mm, &p);
spin_unlock(&mgr->lock); spin_unlock(&mgr->lock);
} }
......
...@@ -19,13 +19,13 @@ static int armada_debugfs_gem_linear_show(struct seq_file *m, void *data) ...@@ -19,13 +19,13 @@ static int armada_debugfs_gem_linear_show(struct seq_file *m, void *data)
struct drm_info_node *node = m->private; struct drm_info_node *node = m->private;
struct drm_device *dev = node->minor->dev; struct drm_device *dev = node->minor->dev;
struct armada_private *priv = dev->dev_private; struct armada_private *priv = dev->dev_private;
int ret; struct drm_printer p = drm_seq_file_printer(m);
mutex_lock(&priv->linear_lock); mutex_lock(&priv->linear_lock);
ret = drm_mm_dump_table(m, &priv->linear); drm_mm_dump_table(&p, &priv->linear);
mutex_unlock(&priv->linear_lock); mutex_unlock(&priv->linear_lock);
return ret; return 0;
} }
static int armada_debugfs_reg_show(struct seq_file *m, void *data) static int armada_debugfs_reg_show(struct seq_file *m, void *data)
......
...@@ -832,8 +832,7 @@ void drm_mm_takedown(struct drm_mm *mm) ...@@ -832,8 +832,7 @@ void drm_mm_takedown(struct drm_mm *mm)
} }
EXPORT_SYMBOL(drm_mm_takedown); EXPORT_SYMBOL(drm_mm_takedown);
static u64 drm_mm_debug_hole(const struct drm_mm_node *entry, static u64 drm_mm_dump_hole(struct drm_printer *p, const struct drm_mm_node *entry)
const char *prefix)
{ {
u64 hole_start, hole_end, hole_size; u64 hole_start, hole_end, hole_size;
...@@ -841,49 +840,7 @@ static u64 drm_mm_debug_hole(const struct drm_mm_node *entry, ...@@ -841,49 +840,7 @@ static u64 drm_mm_debug_hole(const struct drm_mm_node *entry,
hole_start = drm_mm_hole_node_start(entry); hole_start = drm_mm_hole_node_start(entry);
hole_end = drm_mm_hole_node_end(entry); hole_end = drm_mm_hole_node_end(entry);
hole_size = hole_end - hole_start; hole_size = hole_end - hole_start;
pr_debug("%s %#llx-%#llx: %llu: free\n", prefix, hole_start, drm_printf(p, "%#018llx-%#018llx: %llu: free\n", hole_start,
hole_end, hole_size);
return hole_size;
}
return 0;
}
/**
* drm_mm_debug_table - dump allocator state to dmesg
* @mm: drm_mm allocator to dump
* @prefix: prefix to use for dumping to dmesg
*/
void drm_mm_debug_table(const struct drm_mm *mm, const char *prefix)
{
const struct drm_mm_node *entry;
u64 total_used = 0, total_free = 0, total = 0;
total_free += drm_mm_debug_hole(&mm->head_node, prefix);
drm_mm_for_each_node(entry, mm) {
pr_debug("%s %#llx-%#llx: %llu: used\n", prefix, entry->start,
entry->start + entry->size, entry->size);
total_used += entry->size;
total_free += drm_mm_debug_hole(entry, prefix);
}
total = total_free + total_used;
pr_debug("%s total: %llu, used %llu free %llu\n", prefix, total,
total_used, total_free);
}
EXPORT_SYMBOL(drm_mm_debug_table);
#if defined(CONFIG_DEBUG_FS)
static u64 drm_mm_dump_hole(struct seq_file *m, const struct drm_mm_node *entry)
{
u64 hole_start, hole_end, hole_size;
if (entry->hole_follows) {
hole_start = drm_mm_hole_node_start(entry);
hole_end = drm_mm_hole_node_end(entry);
hole_size = hole_end - hole_start;
seq_printf(m, "%#018llx-%#018llx: %llu: free\n", hole_start,
hole_end, hole_size); hole_end, hole_size);
return hole_size; return hole_size;
} }
...@@ -892,28 +849,26 @@ static u64 drm_mm_dump_hole(struct seq_file *m, const struct drm_mm_node *entry) ...@@ -892,28 +849,26 @@ static u64 drm_mm_dump_hole(struct seq_file *m, const struct drm_mm_node *entry)
} }
/** /**
* drm_mm_dump_table - dump allocator state to a seq_file * drm_mm_print - print allocator state
* @m: seq_file to dump to * @mm: drm_mm allocator to print
* @mm: drm_mm allocator to dump * @p: DRM printer to use
*/ */
int drm_mm_dump_table(struct seq_file *m, const struct drm_mm *mm) void drm_mm_print(const struct drm_mm *mm, struct drm_printer *p)
{ {
const struct drm_mm_node *entry; const struct drm_mm_node *entry;
u64 total_used = 0, total_free = 0, total = 0; u64 total_used = 0, total_free = 0, total = 0;
total_free += drm_mm_dump_hole(m, &mm->head_node); total_free += drm_mm_dump_hole(p, &mm->head_node);
drm_mm_for_each_node(entry, mm) { drm_mm_for_each_node(entry, mm) {
seq_printf(m, "%#018llx-%#018llx: %llu: used\n", entry->start, drm_printf(p, "%#018llx-%#018llx: %llu: used\n", entry->start,
entry->start + entry->size, entry->size); entry->start + entry->size, entry->size);
total_used += entry->size; total_used += entry->size;
total_free += drm_mm_dump_hole(m, entry); total_free += drm_mm_dump_hole(p, entry);
} }
total = total_free + total_used; total = total_free + total_used;
seq_printf(m, "total: %llu, used %llu free %llu\n", total, drm_printf(p, "total: %llu, used %llu free %llu\n", total,
total_used, total_free); total_used, total_free);
return 0;
} }
EXPORT_SYMBOL(drm_mm_dump_table); EXPORT_SYMBOL(drm_mm_print);
#endif
...@@ -147,21 +147,23 @@ static int etnaviv_gem_show(struct drm_device *dev, struct seq_file *m) ...@@ -147,21 +147,23 @@ static int etnaviv_gem_show(struct drm_device *dev, struct seq_file *m)
static int etnaviv_mm_show(struct drm_device *dev, struct seq_file *m) static int etnaviv_mm_show(struct drm_device *dev, struct seq_file *m)
{ {
int ret; struct drm_printer p = drm_seq_file_printer(m);
read_lock(&dev->vma_offset_manager->vm_lock); read_lock(&dev->vma_offset_manager->vm_lock);
ret = drm_mm_dump_table(m, &dev->vma_offset_manager->vm_addr_space_mm); drm_mm_print(&dev->vma_offset_manager->vm_addr_space_mm, &p);
read_unlock(&dev->vma_offset_manager->vm_lock); read_unlock(&dev->vma_offset_manager->vm_lock);
return ret; return 0;
} }
static int etnaviv_mmu_show(struct etnaviv_gpu *gpu, struct seq_file *m) static int etnaviv_mmu_show(struct etnaviv_gpu *gpu, struct seq_file *m)
{ {
struct drm_printer p = drm_seq_file_printer(m);
seq_printf(m, "Active Objects (%s):\n", dev_name(gpu->dev)); seq_printf(m, "Active Objects (%s):\n", dev_name(gpu->dev));
mutex_lock(&gpu->mmu->lock); mutex_lock(&gpu->mmu->lock);
drm_mm_dump_table(m, &gpu->mmu->mm); drm_mm_print(&gpu->mmu->mm, &p);
mutex_unlock(&gpu->mmu->lock); mutex_unlock(&gpu->mmu->lock);
return 0; return 0;
......
...@@ -52,7 +52,11 @@ static int msm_gem_show(struct drm_device *dev, struct seq_file *m) ...@@ -52,7 +52,11 @@ static int msm_gem_show(struct drm_device *dev, struct seq_file *m)
static int msm_mm_show(struct drm_device *dev, struct seq_file *m) static int msm_mm_show(struct drm_device *dev, struct seq_file *m)
{ {
return drm_mm_dump_table(m, &dev->vma_offset_manager->vm_addr_space_mm); struct drm_printer p = drm_seq_file_printer(m);
drm_mm_print(&dev->vma_offset_manager->vm_addr_space_mm, &p);
return 0;
} }
static int msm_fb_show(struct drm_device *dev, struct seq_file *m) static int msm_fb_show(struct drm_device *dev, struct seq_file *m)
......
...@@ -50,7 +50,11 @@ static int mm_show(struct seq_file *m, void *arg) ...@@ -50,7 +50,11 @@ static int mm_show(struct seq_file *m, void *arg)
{ {
struct drm_info_node *node = (struct drm_info_node *) m->private; struct drm_info_node *node = (struct drm_info_node *) m->private;
struct drm_device *dev = node->minor->dev; struct drm_device *dev = node->minor->dev;
return drm_mm_dump_table(m, &dev->vma_offset_manager->vm_addr_space_mm); struct drm_printer p = drm_seq_file_printer(m);
drm_mm_print(&dev->vma_offset_manager->vm_addr_space_mm, &p);
return 0;
} }
#ifdef CONFIG_DRM_FBDEV_EMULATION #ifdef CONFIG_DRM_FBDEV_EMULATION
......
...@@ -463,13 +463,13 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data) ...@@ -463,13 +463,13 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
struct drm_mm *mm = (struct drm_mm *)node->info_ent->data; struct drm_mm *mm = (struct drm_mm *)node->info_ent->data;
struct drm_device *dev = node->minor->dev; struct drm_device *dev = node->minor->dev;
struct qxl_device *rdev = dev->dev_private; struct qxl_device *rdev = dev->dev_private;
int ret;
struct ttm_bo_global *glob = rdev->mman.bdev.glob; struct ttm_bo_global *glob = rdev->mman.bdev.glob;
struct drm_printer p = drm_seq_file_printer(m);
spin_lock(&glob->lru_lock); spin_lock(&glob->lru_lock);
ret = drm_mm_dump_table(m, mm); drm_mm_print(mm, &p);
spin_unlock(&glob->lru_lock); spin_unlock(&glob->lru_lock);
return ret; return 0;
} }
#endif #endif
......
...@@ -1033,13 +1033,13 @@ static int radeon_mm_dump_table(struct seq_file *m, void *data) ...@@ -1033,13 +1033,13 @@ static int radeon_mm_dump_table(struct seq_file *m, void *data)
struct drm_device *dev = node->minor->dev; struct drm_device *dev = node->minor->dev;
struct radeon_device *rdev = dev->dev_private; struct radeon_device *rdev = dev->dev_private;
struct drm_mm *mm = (struct drm_mm *)rdev->mman.bdev.man[ttm_pl].priv; struct drm_mm *mm = (struct drm_mm *)rdev->mman.bdev.man[ttm_pl].priv;
int ret;
struct ttm_bo_global *glob = rdev->mman.bdev.glob; struct ttm_bo_global *glob = rdev->mman.bdev.glob;
struct drm_printer p = drm_seq_file_printer(m);
spin_lock(&glob->lru_lock); spin_lock(&glob->lru_lock);
ret = drm_mm_dump_table(m, mm); drm_mm_print(mm, &p);
spin_unlock(&glob->lru_lock); spin_unlock(&glob->lru_lock);
return ret; return 0;
} }
static int ttm_pl_vram = TTM_PL_VRAM; static int ttm_pl_vram = TTM_PL_VRAM;
......
...@@ -194,6 +194,10 @@ static bool assert_node(struct drm_mm_node *node, struct drm_mm *mm, ...@@ -194,6 +194,10 @@ static bool assert_node(struct drm_mm_node *node, struct drm_mm *mm,
return ok; return ok;
} }
#define show_mm(mm) do { \
struct drm_printer __p = drm_debug_printer(__func__); \
drm_mm_print((mm), &__p); } while (0)
static int igt_init(void *ignored) static int igt_init(void *ignored)
{ {
const unsigned int size = 4096; const unsigned int size = 4096;
...@@ -250,7 +254,7 @@ static int igt_init(void *ignored) ...@@ -250,7 +254,7 @@ static int igt_init(void *ignored)
out: out:
if (ret) if (ret)
drm_mm_debug_table(&mm, __func__); show_mm(&mm);
drm_mm_takedown(&mm); drm_mm_takedown(&mm);
return ret; return ret;
} }
...@@ -286,7 +290,7 @@ static int igt_debug(void *ignored) ...@@ -286,7 +290,7 @@ static int igt_debug(void *ignored)
return ret; return ret;
} }
drm_mm_debug_table(&mm, __func__); show_mm(&mm);
return 0; return 0;
} }
...@@ -2031,7 +2035,7 @@ static int igt_color_evict(void *ignored) ...@@ -2031,7 +2035,7 @@ static int igt_color_evict(void *ignored)
ret = 0; ret = 0;
out: out:
if (ret) if (ret)
drm_mm_debug_table(&mm, __func__); show_mm(&mm);
drm_mm_for_each_node_safe(node, next, &mm) drm_mm_for_each_node_safe(node, next, &mm)
drm_mm_remove_node(node); drm_mm_remove_node(node);
drm_mm_takedown(&mm); drm_mm_takedown(&mm);
...@@ -2130,7 +2134,7 @@ static int igt_color_evict_range(void *ignored) ...@@ -2130,7 +2134,7 @@ static int igt_color_evict_range(void *ignored)
ret = 0; ret = 0;
out: out:
if (ret) if (ret)
drm_mm_debug_table(&mm, __func__); show_mm(&mm);
drm_mm_for_each_node_safe(node, next, &mm) drm_mm_for_each_node_safe(node, next, &mm)
drm_mm_remove_node(node); drm_mm_remove_node(node);
drm_mm_takedown(&mm); drm_mm_takedown(&mm);
......
...@@ -891,8 +891,11 @@ static int tegra_debugfs_iova(struct seq_file *s, void *data) ...@@ -891,8 +891,11 @@ static int tegra_debugfs_iova(struct seq_file *s, void *data)
struct drm_info_node *node = (struct drm_info_node *)s->private; struct drm_info_node *node = (struct drm_info_node *)s->private;
struct drm_device *drm = node->minor->dev; struct drm_device *drm = node->minor->dev;
struct tegra_drm *tegra = drm->dev_private; struct tegra_drm *tegra = drm->dev_private;
struct drm_printer p = drm_seq_file_printer(s);
return drm_mm_dump_table(s, &tegra->mm); drm_mm_print(&tegra->mm, &p);
return 0;
} }
static struct drm_info_list tegra_debugfs_list[] = { static struct drm_info_list tegra_debugfs_list[] = {
......
...@@ -507,7 +507,9 @@ static int tilcdc_mm_show(struct seq_file *m, void *arg) ...@@ -507,7 +507,9 @@ static int tilcdc_mm_show(struct seq_file *m, void *arg)
{ {
struct drm_info_node *node = (struct drm_info_node *) m->private; struct drm_info_node *node = (struct drm_info_node *) m->private;
struct drm_device *dev = node->minor->dev; struct drm_device *dev = node->minor->dev;
return drm_mm_dump_table(m, &dev->vma_offset_manager->vm_addr_space_mm); struct drm_printer p = drm_seq_file_printer(m);
drm_mm_print(&dev->vma_offset_manager->vm_addr_space_mm, &p);
return 0;
} }
static struct drm_info_list tilcdc_debugfs_list[] = { static struct drm_info_list tilcdc_debugfs_list[] = {
......
...@@ -141,9 +141,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man, ...@@ -141,9 +141,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
const char *prefix) const char *prefix)
{ {
struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv; struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv;
struct drm_printer p = drm_debug_printer(prefix);
spin_lock(&rman->lock); spin_lock(&rman->lock);
drm_mm_debug_table(&rman->mm, prefix); drm_mm_print(&rman->mm, &p);
spin_unlock(&rman->lock); spin_unlock(&rman->lock);
} }
......
...@@ -42,12 +42,10 @@ ...@@ -42,12 +42,10 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/list.h> #include <linux/list.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#ifdef CONFIG_DEBUG_FS
#include <linux/seq_file.h>
#endif
#ifdef CONFIG_DRM_DEBUG_MM #ifdef CONFIG_DRM_DEBUG_MM
#include <linux/stackdepot.h> #include <linux/stackdepot.h>
#endif #endif
#include <drm/drm_print.h>
#ifdef CONFIG_DRM_DEBUG_MM #ifdef CONFIG_DRM_DEBUG_MM
#define DRM_MM_BUG_ON(expr) BUG_ON(expr) #define DRM_MM_BUG_ON(expr) BUG_ON(expr)
...@@ -462,9 +460,6 @@ bool drm_mm_scan_remove_block(struct drm_mm_scan *scan, ...@@ -462,9 +460,6 @@ bool drm_mm_scan_remove_block(struct drm_mm_scan *scan,
struct drm_mm_node *node); struct drm_mm_node *node);
struct drm_mm_node *drm_mm_scan_color_evict(struct drm_mm_scan *scan); struct drm_mm_node *drm_mm_scan_color_evict(struct drm_mm_scan *scan);
void drm_mm_debug_table(const struct drm_mm *mm, const char *prefix); void drm_mm_print(const struct drm_mm *mm, struct drm_printer *p);
#ifdef CONFIG_DEBUG_FS
int drm_mm_dump_table(struct seq_file *m, const struct drm_mm *mm);
#endif
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment