From 016daf243e168eba6398598de7c6e81d7ddb1993 Mon Sep 17 00:00:00 2001 From: Sudarshan Rajagopalan Date: Mon, 26 Aug 2019 17:52:12 -0700 Subject: [PATCH] ion: msm: enable debugfs for ion heaps Add debugfs node for ion which prints out the debug_show of all the heaps within ion. Change-Id: I8499967c8f202b079b6ccbe1c31cb38ee6a51374 Signed-off-by: Sudarshan Rajagopalan [isaacm@codeaurora.org: Rework to move logic out of ION core] Signed-off-by: Isaac J. Manjarres --- drivers/staging/android/ion/heaps/msm_ion.c | 43 +++++++++++++++++++ .../staging/android/ion/heaps/msm_ion_priv.h | 4 ++ 2 files changed, 47 insertions(+) diff --git a/drivers/staging/android/ion/heaps/msm_ion.c b/drivers/staging/android/ion/heaps/msm_ion.c index b6a9145e1708..bee349fec6a7 100644 --- a/drivers/staging/android/ion/heaps/msm_ion.c +++ b/drivers/staging/android/ion/heaps/msm_ion.c @@ -4,6 +4,8 @@ */ #include +#include +#include #include #include #include @@ -95,6 +97,46 @@ static struct heap_types_info { MAKE_HEAP_TYPE_MAPPING(HYP_CMA), }; +static int msm_ion_debug_heap_show(struct seq_file *s, void *unused) +{ + struct msm_ion_heap *msm_heap = s->private; + + if (msm_heap && msm_heap->debug_show) + msm_heap->debug_show(&msm_heap->ion_heap, s, unused); + + return 0; +} + +static int msm_ion_debug_heap_open(struct inode *inode, struct file *file) +{ + return single_open(file, msm_ion_debug_heap_show, inode->i_private); +} + +static const struct file_operations msm_ion_debug_heap_fops = { + .open = msm_ion_debug_heap_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +static void msm_ion_debugfs_create_file(struct msm_ion_heap *msm_heap) +{ + char debug_name[64], buf[256]; + struct dentry *debugfs_root; + struct ion_heap *heap; + + if (msm_heap && msm_heap->debug_show && + msm_heap->ion_heap.debugfs_dir) { + heap = &msm_heap->ion_heap; + debugfs_root = heap->debugfs_dir; + scnprintf(debug_name, 64, "%s_stats", heap->name); + if (!debugfs_create_file(debug_name, 0664, debugfs_root, + msm_heap, &msm_ion_debug_heap_fops)) + pr_err("Failed to create heap debugfs at %s/%s\n", + dentry_path(debugfs_root, buf, 256), debug_name); + } +} + static struct ion_heap *ion_heap_create(struct ion_platform_heap *heap_data) { struct ion_heap *heap = NULL; @@ -451,6 +493,7 @@ static int msm_ion_probe(struct platform_device *pdev) } ion_device_add_heap(heaps[i]); + msm_ion_debugfs_create_file(to_msm_ion_heap(heaps[i])); } free_pdata(pdata); diff --git a/drivers/staging/android/ion/heaps/msm_ion_priv.h b/drivers/staging/android/ion/heaps/msm_ion_priv.h index fb2c2a6a5ad4..623329b7aef7 100644 --- a/drivers/staging/android/ion/heaps/msm_ion_priv.h +++ b/drivers/staging/android/ion/heaps/msm_ion_priv.h @@ -81,11 +81,15 @@ struct ion_platform_heap { * struct msm_ion_heap - defines an ion heap, as well as additional information * relevant to the heap. * @dev: the device structure associated with the heap + * @debug_show: called when the heap debug file is read to add any heap specific + * debug info to output * @ion_heap: ion heap * */ struct msm_ion_heap { struct device *dev; + int (*debug_show)(struct ion_heap *heap, struct seq_file *s, + void *unused); struct ion_heap ion_heap; };