Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 90dbea37 authored by Jordan Crouse's avatar Jordan Crouse
Browse files

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: default avatarJordan Crouse <jcrouse@codeaurora.org>
parent b2fd7c67
Loading
Loading
Loading
Loading
+23 −1
Original line number Diff line number Diff line
@@ -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;
+16 −1
Original line number Diff line number Diff line
@@ -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 */