From 2b78a1e4274490ac9e6d1fefa7cb8ea7507ac253 Mon Sep 17 00:00:00 2001 From: Liam Mark Date: Thu, 2 May 2019 09:50:12 -0700 Subject: [PATCH 1/2] ion: msm: Expose ION API to query buffer VM information Allow ION clients to be able to determine the VM information associated with an ION buffer, such as the VMIDs it is assigned to as well as the VM permissions. Change-Id: Id0be0b505bc84beff373e4e2ae16b71ec4f09d43 Signed-off-by: Liam Mark [isaacm@codeaurora.org: Relocate changes to new header locations] Signed-off-by: Isaac J. Manjarres --- .../android/ion/heaps/ion_secure_util.c | 1 + include/linux/msm_ion.h | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/drivers/staging/android/ion/heaps/ion_secure_util.c b/drivers/staging/android/ion/heaps/ion_secure_util.c index 66d537713158..61e8ca0a2a30 100644 --- a/drivers/staging/android/ion/heaps/ion_secure_util.c +++ b/drivers/staging/android/ion/heaps/ion_secure_util.c @@ -90,6 +90,7 @@ int ion_populate_vm_list(unsigned long flags, unsigned int *vm_list, } return 0; } +EXPORT_SYMBOL(ion_populate_vm_list); int ion_hyp_unassign_sg(struct sg_table *sgt, int *source_vm_list, int source_nelems, bool clear_page_private) diff --git a/include/linux/msm_ion.h b/include/linux/msm_ion.h index cb2482f5fb48..b3233c394909 100644 --- a/include/linux/msm_ion.h +++ b/include/linux/msm_ion.h @@ -6,6 +6,7 @@ #ifndef _MSM_ION_H #define _MSM_ION_H +#include #include #include @@ -13,6 +14,16 @@ struct device *msm_ion_heap_device_by_id(int heap_id); +static inline unsigned int ion_get_flags_num_vm_elems(unsigned int flags) +{ + unsigned long vm_flags = flags & ION_FLAGS_CP_MASK; + + return ((unsigned int)bitmap_weight(&vm_flags, BITS_PER_LONG)); +} + +int ion_populate_vm_list(unsigned long flags, unsigned int *vm_list, + int nelems); + #else static inline struct device *msm_ion_heap_device_by_id(int heap_id) @@ -20,5 +31,16 @@ static inline struct device *msm_ion_heap_device_by_id(int heap_id) return ERR_PTR(-ENODEV); } +static inline unsigned int ion_get_flags_num_vm_elems(unsigned int flags) +{ + return 0; +} + +static inline int ion_populate_vm_list(unsigned long flags, + unsigned int *vm_list, int nelems) +{ + return -EINVAL; +} + #endif /* CONFIG_ION_MSM_HEAPS */ #endif /* _MSM_ION_H */ From 016daf243e168eba6398598de7c6e81d7ddb1993 Mon Sep 17 00:00:00 2001 From: Sudarshan Rajagopalan Date: Mon, 26 Aug 2019 17:52:12 -0700 Subject: [PATCH 2/2] 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; };