From 878cf94a7a17bf57b9cd24d256e967c9df8f3d5f Mon Sep 17 00:00:00 2001 From: "Isaac J. Manjarres" Date: Thu, 23 Jan 2020 21:55:49 -0800 Subject: [PATCH] ion: msm: Add support for querying the security state of heaps ION clients may want to know about the security state of a heap prior to allocating from it, so expose an interface for querying the security state of a heap. Change-Id: Ibf832792ffbc81b5b96b8ddbc507db5418a47928 Signed-off-by: Isaac J. Manjarres --- drivers/staging/android/ion/heaps/msm_ion.c | 15 ++++++++++++++- include/linux/msm_ion.h | 7 +++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/drivers/staging/android/ion/heaps/msm_ion.c b/drivers/staging/android/ion/heaps/msm_ion.c index ab84b2f2a5c6..a8e5ba75c804 100644 --- a/drivers/staging/android/ion/heaps/msm_ion.c +++ b/drivers/staging/android/ion/heaps/msm_ion.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Copyright (c) 2017-2019, The Linux Foundation. All rights reserved. + * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. */ #include @@ -229,6 +229,19 @@ struct device *msm_ion_heap_device_by_id(int heap_id) } EXPORT_SYMBOL(msm_ion_heap_device_by_id); +bool msm_ion_heap_is_secure(int heap_id) +{ + struct ion_heap *heap = ion_heap_by_id(heap_id); + + if (IS_ERR(heap) || !(heap->type == ION_HEAP_TYPE_SECURE_CARVEOUT || + heap->type == ION_HEAP_TYPE_SYSTEM_SECURE || + heap->type == ION_HEAP_TYPE_HYP_CMA)) + return false; + + return true; +} +EXPORT_SYMBOL(msm_ion_heap_is_secure); + int msm_ion_heap_prefetch(int heap_id, struct ion_prefetch_region *regions, int nr_regions) { diff --git a/include/linux/msm_ion.h b/include/linux/msm_ion.h index 8be7ded32e5d..76f9b24f608e 100644 --- a/include/linux/msm_ion.h +++ b/include/linux/msm_ion.h @@ -37,6 +37,8 @@ int msm_ion_heap_drain(int heap_id, struct ion_prefetch_region *regions, int get_ion_flags(u32 vmid); +bool msm_ion_heap_is_secure(int heap_id); + #else static inline struct device *msm_ion_heap_device_by_id(int heap_id) @@ -74,5 +76,10 @@ static inline int get_ion_flags(u32 vmid) return -EINVAL; } +static inline bool msm_ion_heap_is_secure(int heap_id) +{ + return false; +} + #endif /* CONFIG_ION_MSM_HEAPS */ #endif /* _MSM_ION_H */