From 90dbea373e0dac7d633ab2fdd906f63c1121ab25 Mon Sep 17 00:00:00 2001 From: Jordan Crouse Date: Thu, 4 May 2017 13:48:21 -0600 Subject: [PATCH] ion: Add ion_dma_buf_is_secure() to query buffer type Outside clients (such as the display or GPU) may import a dmabuf and need to figure out if it is secure so that it can be handled accordingly. In an ideal world this would be part of the generic dma-buf structure but until then we can assume that the only outside source of dmabuf-ified secure buffers is Ion so add a function to directly query the status of the buffer from Ion. ion_dma_buf_is_secure() returns true if the dmabuf was created by Ion and was created from a secure heap. Change-Id: Ic0dedbad5e5a4464c6948f05bb7e0e3e94cd4cc2 Signed-off-by: Jordan Crouse --- drivers/staging/android/ion/ion.c | 24 +++++++++++++++++++++++- drivers/staging/android/ion/ion.h | 17 ++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c index 58bf3d2f52bd..4dfbdcd497b2 100644 --- a/drivers/staging/android/ion/ion.c +++ b/drivers/staging/android/ion/ion.c @@ -3,7 +3,7 @@ * drivers/staging/android/ion/ion.c * * Copyright (C) 2011 Google, Inc. - * Copyright (c) 2011-2016, The Linux Foundation. All rights reserved. + * Copyright (c) 2011-2017, The Linux Foundation. All rights reserved. * * This software is licensed under the terms of the GNU General Public * License version 2, as published by the Free Software Foundation, and @@ -1462,6 +1462,28 @@ int ion_share_dma_buf_fd(struct ion_client *client, struct ion_handle *handle) } EXPORT_SYMBOL(ion_share_dma_buf_fd); +bool ion_dma_buf_is_secure(struct dma_buf *dmabuf) +{ + struct ion_buffer *buffer; + enum ion_heap_type type; + + /* Return false if we didn't create the buffer */ + if (!dmabuf || dmabuf->ops != &dma_buf_ops) + return false; + + buffer = dmabuf->priv; + + if (!buffer || !buffer->heap) + return false; + + type = buffer->heap->type; + + return (type == (enum ion_heap_type)ION_HEAP_TYPE_SECURE_DMA || + type == (enum ion_heap_type)ION_HEAP_TYPE_SYSTEM_SECURE) ? + true : false; +} +EXPORT_SYMBOL(ion_dma_buf_is_secure); + struct ion_handle *ion_import_dma_buf(struct ion_client *client, int fd) { struct dma_buf *dmabuf; diff --git a/drivers/staging/android/ion/ion.h b/drivers/staging/android/ion/ion.h index 5f99ea16617a..73902ebafca6 100644 --- a/drivers/staging/android/ion/ion.h +++ b/drivers/staging/android/ion/ion.h @@ -2,7 +2,7 @@ * drivers/staging/android/ion/ion.h * * Copyright (C) 2011 Google, Inc. - * Copyright (c) 2011-2014, The Linux Foundation. All rights reserved. + * Copyright (c) 2011-2014,2017 The Linux Foundation. All rights reserved. * * This software is licensed under the terms of the GNU General Public * License version 2, as published by the Free Software Foundation, and @@ -209,6 +209,16 @@ int ion_share_dma_buf_fd(struct ion_client *client, struct ion_handle *handle); */ struct ion_handle *ion_import_dma_buf(struct ion_client *client, int fd); +/** + * ion_dma_buf_is_secure() - Returns true if the dma buf is secure + * dmabuf + * @dmabuf: pointer to a dma-buf + * + * Given a dma-buf pointer, return true if ion created it and it is from + * a secure heap. + */ +bool ion_dma_buf_is_secure(struct dma_buf *dmabuf); + #else static inline void ion_reserve(struct ion_platform_data *data) { @@ -272,5 +282,10 @@ static inline int ion_handle_get_flags(struct ion_client *client, return -ENODEV; } +bool ion_dma_buf_is_secure(struct dma_buf *dmabuf) +{ + return false; +} + #endif /* CONFIG_ION */ #endif /* _LINUX_ION_H */ -- 2.11.0