From b3bc336903e9e70145348de695a90b9f93ddcda2 Mon Sep 17 00:00:00 2001 From: Jianqun Xu Date: Wed, 3 Mar 2021 17:34:53 +0800 Subject: [PATCH] staging: android: ion: add 'heaps' debug node console:/ # cat /sys/kernel/debug/ion/heaps id type name 2 0 ion_system_heap 1 1 ion_system_contig_heap 0 0 ion_secure_heap Change-Id: I0d798205573eb5a2b3177d51f784bf8c89ab7313 Signed-off-by: Jianqun Xu --- drivers/staging/android/ion/ion.c | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c index 5db9b0202d03..76178ecaa9f9 100644 --- a/drivers/staging/android/ion/ion.c +++ b/drivers/staging/android/ion/ion.c @@ -777,6 +777,34 @@ static int ion_init_sysfs(void) return 0; } +#ifdef CONFIG_DEBUG_FS +static int ion_heaps_show(struct seq_file *s, void *unused) +{ + struct ion_device *dev = internal_dev; + struct ion_heap *heap; + + down_read(&dev->lock); + seq_printf(s, "%s\t%s\t%s\n", "id", "type", "name"); + plist_for_each_entry(heap, &dev->heaps, node) { + seq_printf(s, "%u\t%u\t%s\n", heap->id, heap->type, heap->name); + } + up_read(&dev->lock); + return 0; +} + +static int ion_heaps_open(struct inode *inode, struct file *file) +{ + return single_open(file, ion_heaps_show, NULL); +} + +static const struct file_operations ion_heaps_operations = { + .open = ion_heaps_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; +#endif + static int ion_device_create(void) { struct ion_device *idev; @@ -803,6 +831,10 @@ static int ion_device_create(void) } idev->debug_root = debugfs_create_dir("ion", NULL); +#ifdef CONFIG_DEBUG_FS + debugfs_create_file("heaps", 0444, idev->debug_root, NULL, + &ion_heaps_operations); +#endif idev->buffers = RB_ROOT; mutex_init(&idev->buffer_lock); init_rwsem(&idev->lock);