drm/mm: Convert to drm_printer
authorDaniel Vetter <daniel.vetter@ffwll.ch>
Thu, 29 Dec 2016 11:09:24 +0000 (12:09 +0100)
committerDaniel Vetter <daniel.vetter@ffwll.ch>
Fri, 30 Dec 2016 11:08:28 +0000 (12:08 +0100)
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: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/1483009764-8281-1-git-send-email-daniel.vetter@ffwll.ch
15 files changed:
drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
drivers/gpu/drm/armada/armada_debugfs.c
drivers/gpu/drm/drm_mm.c
drivers/gpu/drm/etnaviv/etnaviv_drv.c
drivers/gpu/drm/msm/msm_debugfs.c
drivers/gpu/drm/omapdrm/omap_debugfs.c
drivers/gpu/drm/qxl/qxl_ttm.c
drivers/gpu/drm/radeon/radeon_ttm.c
drivers/gpu/drm/selftests/test-drm_mm.c
drivers/gpu/drm/tegra/drm.c
drivers/gpu/drm/tilcdc/tilcdc_drv.c
drivers/gpu/drm/ttm/ttm_bo_manager.c
include/drm/drm_mm.h

index 00f46b0e076ddd9c8ce9d7a98668c2f02b31c1b6..c6c125d311619c1dd2d8d76b933236bacb42d2d2 100644 (file)
@@ -235,9 +235,10 @@ static void amdgpu_gtt_mgr_debug(struct ttm_mem_type_manager *man,
                                  const char *prefix)
 {
        struct amdgpu_gtt_mgr *mgr = man->priv;
+       struct drm_printer p = drm_debug_printer(prefix);
 
        spin_lock(&mgr->lock);
-       drm_mm_debug_table(&mgr->mm, prefix);
+       drm_mm_print(&mgr->mm, &p);
        spin_unlock(&mgr->lock);
 }
 
index bc70f80260d849b9b51c3bbcc5c1135500e0dbed..88e77045bdd6daf9681c7d5beaba1943287155a0 100644 (file)
@@ -1482,18 +1482,18 @@ static int amdgpu_mm_dump_table(struct seq_file *m, void *data)
        struct drm_device *dev = node->minor->dev;
        struct amdgpu_device *adev = dev->dev_private;
        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 drm_printer p = drm_seq_file_printer(m);
 
        spin_lock(&glob->lru_lock);
-       ret = drm_mm_dump_table(m, mm);
+       drm_mm_print(mm, &p);
        spin_unlock(&glob->lru_lock);
        if (ttm_pl == TTM_PL_VRAM)
                seq_printf(m, "man size:%llu pages, ram usage:%lluMB, vis usage:%lluMB\n",
                           adev->mman.bdev.man[ttm_pl].size,
                           (u64)atomic64_read(&adev->vram_usage) >> 20,
                           (u64)atomic64_read(&adev->vram_vis_usage) >> 20);
-       return ret;
+       return 0;
 }
 
 static int ttm_pl_vram = TTM_PL_VRAM;
index d710226a0fffe2da3fcbecf9650168396adcdbeb..ac9007986c11767a93cc9643be747e50a3124d48 100644 (file)
@@ -207,9 +207,10 @@ static void amdgpu_vram_mgr_debug(struct ttm_mem_type_manager *man,
                                  const char *prefix)
 {
        struct amdgpu_vram_mgr *mgr = man->priv;
+       struct drm_printer p = drm_debug_printer(prefix);
 
        spin_lock(&mgr->lock);
-       drm_mm_debug_table(&mgr->mm, prefix);
+       drm_mm_print(&mgr->mm, &p);
        spin_unlock(&mgr->lock);
 }
 
index 90222e60d2d60e818227f4017a86495f5b983d90..0c7b915be08227a80f92377b0fe881c211b56ded 100644 (file)
@@ -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_device *dev = node->minor->dev;
        struct armada_private *priv = dev->dev_private;
-       int ret;
+       struct drm_printer p = drm_seq_file_printer(m);
 
        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);
 
-       return ret;
+       return 0;
 }
 
 static int armada_debugfs_reg_show(struct seq_file *m, void *data)
index 1a5b4eba23866ed9be744d347ce07cd277da97b6..e54aa3fa538f604d87b8956bd509e9f044de5159 100644 (file)
@@ -832,8 +832,7 @@ void drm_mm_takedown(struct drm_mm *mm)
 }
 EXPORT_SYMBOL(drm_mm_takedown);
 
-static u64 drm_mm_debug_hole(const struct drm_mm_node *entry,
-                            const char *prefix)
+static u64 drm_mm_dump_hole(struct drm_printer *p, const struct drm_mm_node *entry)
 {
        u64 hole_start, hole_end, hole_size;
 
@@ -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_end = drm_mm_hole_node_end(entry);
                hole_size = hole_end - hole_start;
-               pr_debug("%s %#llx-%#llx: %llu: free\n", prefix, 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,
+               drm_printf(p, "%#018llx-%#018llx: %llu: free\n", hole_start,
                           hole_end, 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)
 }
 
 /**
- * drm_mm_dump_table - dump allocator state to a seq_file
- * @m: seq_file to dump to
- * @mm: drm_mm allocator to dump
+ * drm_mm_print - print allocator state
+ * @mm: drm_mm allocator to print
+ * @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;
        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) {
-               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);
                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;
 
-       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);
-       return 0;
 }
-EXPORT_SYMBOL(drm_mm_dump_table);
-#endif
+EXPORT_SYMBOL(drm_mm_print);
index 30d70ed143f7ab076b05fe26e0e78a0e8c85eaa8..b92c24e07cea0c200b992411cb06cdeead7cea1e 100644 (file)
@@ -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)
 {
-       int ret;
+       struct drm_printer p = drm_seq_file_printer(m);
 
        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);
 
-       return ret;
+       return 0;
 }
 
 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));
 
        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);
 
        return 0;
index c1b40f5adb6046ddc8c074f7617cf7378f726589..387f0616e115ce039623287682c44209ef21e94d 100644 (file)
@@ -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)
 {
-       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)
index 479bf24050f8a5f11375d0aa9f077cc70ec8e751..bf65862daf62e68a62ff854c8c1ba68ad00110ba 100644 (file)
@@ -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_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
index 11761330a6b8a52ca5d5fc8b74ac7c7d23f6bf6e..1b096c5252ad731e96bacd417f4d4ee0dc2ab6cc 100644 (file)
@@ -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_device *dev = node->minor->dev;
        struct qxl_device *rdev = dev->dev_private;
-       int ret;
        struct ttm_bo_global *glob = rdev->mman.bdev.glob;
+       struct drm_printer p = drm_seq_file_printer(m);
 
        spin_lock(&glob->lru_lock);
-       ret = drm_mm_dump_table(m, mm);
+       drm_mm_print(mm, &p);
        spin_unlock(&glob->lru_lock);
-       return ret;
+       return 0;
 }
 #endif
 
index 0cf03ccbf0a72521f3d80d38d2e0ba7b4d4ba6de..1888144d0fed0ea5c977645d7c7e5c47cf26719b 100644 (file)
@@ -1033,13 +1033,13 @@ static int radeon_mm_dump_table(struct seq_file *m, void *data)
        struct drm_device *dev = node->minor->dev;
        struct radeon_device *rdev = dev->dev_private;
        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 drm_printer p = drm_seq_file_printer(m);
 
        spin_lock(&glob->lru_lock);
-       ret = drm_mm_dump_table(m, mm);
+       drm_mm_print(mm, &p);
        spin_unlock(&glob->lru_lock);
-       return ret;
+       return 0;
 }
 
 static int ttm_pl_vram = TTM_PL_VRAM;
index 2ce92f4dcfc7d6c7c39cca80bef8e53279d39a5e..6d2a5cd211f3cf2a993230d9b625b5369c47d59e 100644 (file)
@@ -194,6 +194,10 @@ static bool assert_node(struct drm_mm_node *node, struct drm_mm *mm,
        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)
 {
        const unsigned int size = 4096;
@@ -250,7 +254,7 @@ static int igt_init(void *ignored)
 
 out:
        if (ret)
-               drm_mm_debug_table(&mm, __func__);
+               show_mm(&mm);
        drm_mm_takedown(&mm);
        return ret;
 }
@@ -286,7 +290,7 @@ static int igt_debug(void *ignored)
                return ret;
        }
 
-       drm_mm_debug_table(&mm, __func__);
+       show_mm(&mm);
        return 0;
 }
 
@@ -2031,7 +2035,7 @@ static int igt_color_evict(void *ignored)
        ret = 0;
 out:
        if (ret)
-               drm_mm_debug_table(&mm, __func__);
+               show_mm(&mm);
        drm_mm_for_each_node_safe(node, next, &mm)
                drm_mm_remove_node(node);
        drm_mm_takedown(&mm);
@@ -2130,7 +2134,7 @@ static int igt_color_evict_range(void *ignored)
        ret = 0;
 out:
        if (ret)
-               drm_mm_debug_table(&mm, __func__);
+               show_mm(&mm);
        drm_mm_for_each_node_safe(node, next, &mm)
                drm_mm_remove_node(node);
        drm_mm_takedown(&mm);
index e289dbc6ad82d4fbb0424e7d97146b7011ec6d47..4d966cddcc7167a0446703b12760b82bd0909af2 100644 (file)
@@ -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_device *drm = node->minor->dev;
        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[] = {
index bd0a3bd071673788427cd02a95817476d3687716..ec15585c7a2783090e3518b0d97f07be4a1d4391 100644 (file)
@@ -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_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[] = {
index aea6a01500e11a67e944e2c1aa03f5844d454835..988c48d1cf3ea5fd66239bb37725bd5abfa4091e 100644 (file)
@@ -141,9 +141,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
                             const char *prefix)
 {
        struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv;
+       struct drm_printer p = drm_debug_printer(prefix);
 
        spin_lock(&rman->lock);
-       drm_mm_debug_table(&rman->mm, prefix);
+       drm_mm_print(&rman->mm, &p);
        spin_unlock(&rman->lock);
 }
 
index 92ec5759caaef626b22d7bd9e766596e778978dd..1383ac2328b820ff12ae7e9f1ed17823f774aba0 100644 (file)
 #include <linux/kernel.h>
 #include <linux/list.h>
 #include <linux/spinlock.h>
-#ifdef CONFIG_DEBUG_FS
-#include <linux/seq_file.h>
-#endif
 #ifdef CONFIG_DRM_DEBUG_MM
 #include <linux/stackdepot.h>
 #endif
+#include <drm/drm_print.h>
 
 #ifdef CONFIG_DRM_DEBUG_MM
 #define DRM_MM_BUG_ON(expr) BUG_ON(expr)
@@ -462,9 +460,6 @@ bool drm_mm_scan_remove_block(struct drm_mm_scan *scan,
                              struct drm_mm_node *node);
 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);
-#ifdef CONFIG_DEBUG_FS
-int drm_mm_dump_table(struct seq_file *m, const struct drm_mm *mm);
-#endif
+void drm_mm_print(const struct drm_mm *mm, struct drm_printer *p);
 
 #endif