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

Commit 39aebce1 authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "ARM: dts: msm8996: Add support for secure display heap"

parents b8fafd20 ab212039
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
/* Copyright (c) 2014, The Linux Foundation. All rights reserved.
/* Copyright (c) 2014-2015, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
@@ -32,6 +32,12 @@
			qcom,ion-heap-type = "DMA";
		};

		qcom,ion-heap@10 { /* SECURE DISPLAY HEAP */
			reg = <10>;
			memory-region = <&secure_display_memory>;
			qcom,ion-heap-type = "HYP_CMA";
		};

		qcom,ion-heap@9 {
			reg = <9>;
			qcom,ion-heap-type = "SYSTEM_SECURE";
+7 −0
Original line number Diff line number Diff line
@@ -156,6 +156,13 @@
			size = <0 0x1400000>;
		};

		secure_display_memory: secure_region {
			compatible = "shared-dma-pool";
			alloc-ranges = <0 0x00000000 0 0xffffffff>;
			reusable;
			alignment = <0 0x200000>;
			size = <0 0x5c00000>;
		};
		modem_mem: modem_region@88800000 {
			compatible = "removed-dma-pool";
			no-map;
+103 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
#include <linux/msm_ion.h>

#include <asm/cacheflush.h>
#include <soc/qcom/secure_buffer.h>

#include "ion.h"
#include "ion_priv.h"
@@ -233,3 +234,105 @@ void ion_cma_heap_destroy(struct ion_heap *heap)
{
	kfree(heap);
}

static void ion_secure_cma_free(struct ion_buffer *buffer)
{
	int ret = 0;
	u32 source_vm;
	int dest_vmid;
	int dest_perms;
	struct ion_cma_buffer_info *info = buffer->priv_virt;

	source_vm = get_secure_vmid(buffer->flags);
	if (source_vm < 0) {
		pr_err("%s: Failed to get secure vmid\n", __func__);
		return;
	}
	dest_vmid = VMID_HLOS;
	dest_perms = PERM_READ | PERM_WRITE | PERM_EXEC;

	ret = hyp_assign_table(info->table, &source_vm, 1,
				&dest_vmid, &dest_perms, 1);
	if (ret) {
		pr_err("%s: Not freeing memory since assign failed\n",
							__func__);
		return;
	}

	ion_cma_free(buffer);
}

static int ion_secure_cma_allocate(struct ion_heap *heap,
			struct ion_buffer *buffer, unsigned long len,
			unsigned long align, unsigned long flags)
{
	int ret = 0;
	int source_vm;
	int dest_vm;
	int dest_perms;
	struct ion_cma_buffer_info *info;

	source_vm = VMID_HLOS;
	dest_vm = get_secure_vmid(flags);
	if (dest_vm < 0) {
		pr_err("%s: Failed to get secure vmid\n", __func__);
		return -EINVAL;
	}
	dest_perms = PERM_READ | PERM_WRITE;

	ret = ion_cma_allocate(heap, buffer, len, align, flags);
	if (ret) {
		dev_err(heap->priv, "Unable to allocate cma buffer");
		return ret;
	}

	info = buffer->priv_virt;
	ret = hyp_assign_table(info->table, &source_vm, 1,
				&dest_vm, &dest_perms, 1);
	if (ret) {
		pr_err("%s: Assign call failed\n", __func__);
		goto err;
	}
	return ret;

err:
	ion_secure_cma_free(buffer);
	return ret;
}

static struct ion_heap_ops ion_secure_cma_ops = {
	.allocate = ion_secure_cma_allocate,
	.free = ion_secure_cma_free,
	.map_dma = ion_cma_heap_map_dma,
	.unmap_dma = ion_cma_heap_unmap_dma,
	.phys = ion_cma_phys,
	.map_user = ion_cma_mmap,
	.map_kernel = ion_cma_map_kernel,
	.unmap_kernel = ion_cma_unmap_kernel,
	.print_debug = ion_cma_print_debug,
};

struct ion_heap *ion_cma_secure_heap_create(struct ion_platform_heap *data)
{
	struct ion_heap *heap;

	heap = kzalloc(sizeof(struct ion_heap), GFP_KERNEL);

	if (!heap)
		return ERR_PTR(-ENOMEM);

	heap->ops = &ion_secure_cma_ops;
	/*
	 *  set device as private heaps data, later it will be
	 * used to make the link with reserved CMA memory
	 */
	heap->priv = data->priv;
	heap->type = ION_HEAP_TYPE_HYP_CMA;
	cma_heap_has_outer_cache = data->has_outer_cache;
	return heap;
}

void ion_cma_secure_heap_destroy(struct ion_heap *heap)
{
	kfree(heap);
}
+0 −16
Original line number Diff line number Diff line
@@ -33,22 +33,6 @@ static bool is_cp_flag_present(unsigned long flags)
			ION_FLAG_CP_CAMERA);
}

static int get_secure_vmid(unsigned long flags)
{
	if (flags & ION_FLAG_CP_TOUCH)
		return VMID_CP_TOUCH;
	if (flags & ION_FLAG_CP_BITSTREAM)
		return VMID_CP_BITSTREAM;
	if (flags & ION_FLAG_CP_PIXEL)
		return VMID_CP_PIXEL;
	if (flags & ION_FLAG_CP_NON_PIXEL)
		return VMID_CP_NON_PIXEL;
	if (flags & ION_FLAG_CP_CAMERA)
		return VMID_CP_CAMERA;

	return -EINVAL;
}

static void ion_system_secure_heap_free(struct ion_buffer *buffer)
{
	int ret = 0;
+31 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@
#include "../ion_priv.h"
#include "ion_cp_common.h"
#include "compat_msm_ion.h"
#include <soc/qcom/secure_buffer.h>

#define ION_COMPAT_STR	"qcom,msm-ion"

@@ -109,6 +110,10 @@ static struct ion_heap_desc ion_heap_meta[] = {
	{
		.id	= ION_ADSP_HEAP_ID,
		.name	= ION_ADSP_HEAP_NAME,
	},
	{
		.id	= ION_SECURE_DISPLAY_HEAP_ID,
		.name	= ION_SECURE_DISPLAY_HEAP_NAME,
	}
};
#endif
@@ -372,6 +377,7 @@ static struct heap_types_info {
	MAKE_HEAP_TYPE_MAPPING(DMA),
	MAKE_HEAP_TYPE_MAPPING(SECURE_DMA),
	MAKE_HEAP_TYPE_MAPPING(SYSTEM_SECURE),
	MAKE_HEAP_TYPE_MAPPING(HYP_CMA),
};

static int msm_ion_get_heap_type_from_dt_node(struct device_node *node,
@@ -573,6 +579,24 @@ int ion_heap_allow_heap_secure(enum ion_heap_type type)
	return false;
}

int get_secure_vmid(unsigned long flags)
{
	if (flags & ION_FLAG_CP_TOUCH)
		return VMID_CP_TOUCH;
	if (flags & ION_FLAG_CP_BITSTREAM)
		return VMID_CP_BITSTREAM;
	if (flags & ION_FLAG_CP_PIXEL)
		return VMID_CP_PIXEL;
	if (flags & ION_FLAG_CP_NON_PIXEL)
		return VMID_CP_NON_PIXEL;
	if (flags & ION_FLAG_CP_CAMERA)
		return VMID_CP_CAMERA;
	if (flags & ION_FLAG_CP_SEC_DISPLAY)
		return VMID_CP_SEC_DISPLAY;
	if (flags & ION_FLAG_CP_APP)
		return VMID_CP_APP;
	return -EINVAL;
}
/* fix up the cases where the ioctl direction bits are incorrect */
static unsigned int msm_ion_ioctl_dir(unsigned int cmd)
{
@@ -823,6 +847,9 @@ static struct ion_heap *msm_ion_heap_create(struct ion_platform_heap *heap_data)
	case ION_HEAP_TYPE_SYSTEM_SECURE:
		heap = ion_system_secure_heap_create(heap_data);
		break;
	case ION_HEAP_TYPE_HYP_CMA:
		heap = ion_cma_secure_heap_create(heap_data);
		break;
	default:
		heap = ion_heap_create(heap_data);
	}
@@ -854,6 +881,10 @@ static void msm_ion_heap_destroy(struct ion_heap *heap)
	case ION_HEAP_TYPE_SYSTEM_SECURE:
		ion_system_secure_heap_destroy(heap);
		break;

	case ION_HEAP_TYPE_HYP_CMA:
		ion_cma_secure_heap_destroy(heap);
		break;
	default:
		ion_heap_destroy(heap);
	}
Loading