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

Commit d6d8fb87 authored by Liam Mark's avatar Liam Mark
Browse files

ion: refactor ION msm changes



Refactor ION code to separate out msm specific changes to
make it easier to integrate upstream changes.

Change-Id: I9c0ab4fd982fc4395e2474bed1eb57cbba6fc716
Signed-off-by: default avatarLiam Mark <lmark@codeaurora.org>
parent 835f3675
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -3,4 +3,4 @@ obj-$(CONFIG_ION) += ion.o ion-ioctl.o ion_heap.o \
			ion_page_pool.o ion_system_heap.o \
			ion_carveout_heap.o ion_chunk_heap.o \
			ion_system_secure_heap.o ion_cma_heap.o \
			msm/
			ion_secure_util.o msm/
+0 −68
Original line number Diff line number Diff line
@@ -45,74 +45,6 @@

static struct ion_device *internal_dev;

bool is_secure_vmid_valid(int vmid)
{
	return (vmid == VMID_CP_TOUCH ||
		vmid == VMID_CP_BITSTREAM ||
		vmid == VMID_CP_PIXEL ||
		vmid == VMID_CP_NON_PIXEL ||
		vmid == VMID_CP_CAMERA ||
		vmid == VMID_CP_SEC_DISPLAY ||
		vmid == VMID_CP_APP ||
		vmid == VMID_CP_CAMERA_PREVIEW);
}

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;
	if (flags & ION_FLAG_CP_CAMERA_PREVIEW)
		return VMID_CP_CAMERA_PREVIEW;
	return -EINVAL;
}

unsigned int count_set_bits(unsigned long val)
{
	return ((unsigned int)bitmap_weight(&val, BITS_PER_LONG));
}

int populate_vm_list(unsigned long flags, unsigned int *vm_list,
		     int nelems)
{
	unsigned int itr = 0;
	int vmid;

	flags = flags & ION_FLAGS_CP_MASK;
	for_each_set_bit(itr, &flags, BITS_PER_LONG) {
		vmid = get_vmid(0x1UL << itr);
		if (vmid < 0 || !nelems)
			return -EINVAL;

		vm_list[nelems - 1] = vmid;
		nelems--;
	}
	return 0;
}

int get_vmid(unsigned long flags)
{
	int vmid;

	vmid = get_secure_vmid(flags);
	if (vmid < 0) {
		if (flags & ION_FLAG_CP_HLOS)
			vmid = VMID_HLOS;
	}
	return vmid;
}

int ion_walk_heaps(int heap_id, enum ion_heap_type type, void *data,
		   int (*f)(struct ion_heap *heap, void *data))
{
+0 −33
Original line number Diff line number Diff line
@@ -231,24 +231,6 @@ struct ion_heap {
	int (*debug_show)(struct ion_heap *heap, struct seq_file *, void *);
};

struct pages_mem {
	struct page **pages;
	u32 size;
};

struct ion_prefetch_regions {
	unsigned int vmid;
	size_t __user *sizes;
	unsigned int nr_sizes;
};

struct ion_prefetch_data {
	int heap_id;
	unsigned long len;
	struct ion_prefetch_regions __user *regions;
	unsigned int nr_regions;
};

/**
 * ion_buffer_cached - this ion buffer is cached
 * @buffer:		buffer
@@ -257,21 +239,6 @@ struct ion_prefetch_data {
 */
bool ion_buffer_cached(struct ion_buffer *buffer);

int get_secure_vmid(unsigned long flags);
int get_vmid(unsigned long flags);
bool is_secure_vmid_valid(int vmid);
unsigned int count_set_bits(unsigned long val);
int populate_vm_list(unsigned long flags, unsigned int *vm_list, int nelems);

/**
 * Functions to help assign/unassign sg_table for System Secure Heap
 */

int ion_system_secure_heap_unassign_sg(struct sg_table *sgt, int source_vmid);
int ion_system_secure_heap_assign_sg(struct sg_table *sgt, int dest_vmid);
int ion_system_secure_heap_prefetch(struct ion_heap *heap, void *data);
int ion_system_secure_heap_drain(struct ion_heap *heap, void *data);

/**
 * ion_buffer_fault_user_mappings - fault in user mappings of this buffer
 * @buffer:		buffer
+4 −92
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@
#include <soc/qcom/secure_buffer.h>

#include "ion.h"
#include "ion_secure_util.h"

struct ion_cma_heap {
	struct ion_heap heap;
@@ -134,104 +135,15 @@ void ion_cma_heap_destroy(struct ion_heap *heap)
	kfree(cma_heap);
}

static int ion_secure_cma_unassign_buffer(struct ion_buffer *buffer)
{
	int ret = 0;
	int *source_vm_list;
	int source_nelems;
	int dest_vmid;
	int dest_perms;

	source_nelems = count_set_bits(buffer->flags & ION_FLAGS_CP_MASK);
	source_vm_list = kcalloc(source_nelems, sizeof(*source_vm_list),
				 GFP_KERNEL);
	if (!source_vm_list)
		return -ENOMEM;
	ret = populate_vm_list(buffer->flags, source_vm_list, source_nelems);
	if (ret) {
		pr_err("%s: Failed to get secure vmids\n", __func__);
		goto out_free_source;
	}

	dest_vmid = VMID_HLOS;
	dest_perms = PERM_READ | PERM_WRITE | PERM_EXEC;

	ret = hyp_assign_table(buffer->sg_table, source_vm_list, source_nelems,
			       &dest_vmid, &dest_perms, 1);
	if (ret) {
		pr_err("%s: Not freeing memory since assign failed\n",
		       __func__);
	}

out_free_source:
	kfree(source_vm_list);
	return ret;
}

static void ion_secure_cma_free(struct ion_buffer *buffer)
{
	if (ion_secure_cma_unassign_buffer(buffer))
	if (ion_hyp_unassign_sg_from_flags(buffer->sg_table, buffer->flags,
					   false))
		return;

	ion_cma_free(buffer);
}

static int ion_secure_cma_assign_buffer(
			struct ion_buffer *buffer,
			unsigned long flags)
{
	int ret = 0;
	int count;
	int source_vm;
	int *dest_vm_list = NULL;
	int *dest_perms = NULL;
	int dest_nelems;

	source_vm = VMID_HLOS;

	dest_nelems = count_set_bits(flags & ION_FLAGS_CP_MASK);
	dest_vm_list = kcalloc(dest_nelems, sizeof(*dest_vm_list), GFP_KERNEL);
	if (!dest_vm_list) {
		ret = -ENOMEM;
		goto out;
	}
	dest_perms = kcalloc(dest_nelems, sizeof(*dest_perms), GFP_KERNEL);
	if (!dest_perms) {
		ret = -ENOMEM;
		goto out_free_dest_vm;
	}
	ret = populate_vm_list(flags, dest_vm_list, dest_nelems);
	if (ret) {
		pr_err("%s: Failed to get secure vmid(s)\n", __func__);
		goto out_free_dest;
	}

	for (count = 0; count < dest_nelems; count++) {
		if (dest_vm_list[count] == VMID_CP_SEC_DISPLAY)
			dest_perms[count] = PERM_READ;
		else
			dest_perms[count] = PERM_READ | PERM_WRITE;
	}

	ret = hyp_assign_table(buffer->sg_table, &source_vm, 1,
			       dest_vm_list, dest_perms, dest_nelems);
	if (ret) {
		pr_err("%s: Assign call failed\n", __func__);
		goto out_free_dest;
	}

	kfree(dest_vm_list);
	kfree(dest_perms);
	return ret;

out_free_dest:
	kfree(dest_perms);
out_free_dest_vm:
	kfree(dest_vm_list);
out:
	return ret;
}

static int ion_secure_cma_allocate(
			struct ion_heap *heap,
			struct ion_buffer *buffer, unsigned long len,
@@ -245,7 +157,7 @@ static int ion_secure_cma_allocate(
		goto out;
	}

	ret = ion_secure_cma_assign_buffer(buffer, flags);
	ret = ion_hyp_assign_sg_from_flags(buffer->sg_table, flags, false);
	if (ret)
		goto out_free_buf;

+1 −3
Original line number Diff line number Diff line
@@ -76,9 +76,7 @@ struct page *ion_page_pool_alloc(struct ion_page_pool *pool, bool *from_pool)

	BUG_ON(!pool);

	*from_pool = true;

	if (mutex_trylock(&pool->mutex)) {
	if (*from_pool && mutex_trylock(&pool->mutex)) {
		if (pool->high_count)
			page = ion_page_pool_remove(pool, true);
		else if (pool->low_count)
Loading