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

Commit c6eed32e authored by Patrick Daly's avatar Patrick Daly
Browse files

ion: Add hibernation support for secure carveout heap



Call hyp_assign in pm_restore callback to restore hyp_assign permissions.

Change-Id: I7b9d016eebc3116db71379b0adb195be1942caad
Signed-off-by: default avatarPatrick Daly <pdaly@codeaurora.org>
parent 842474f1
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -186,6 +186,8 @@ struct ion_sc_entry {
	struct list_head list;
	struct ion_heap *heap;
	u32 token;
	u64 base;
	u64 size;
};

struct ion_sc_heap {
@@ -242,9 +244,39 @@ static void ion_sc_heap_free(struct ion_buffer *buffer)
	kfree(table);
}

static int ion_secure_carveout_pm_freeze(struct ion_heap *heap)
{
	long sz;

	sz = atomic_long_read(&heap->total_allocated);
	if (sz) {
		pr_err("%s: %lx bytes won't be saved across hibernation. Aborting.",
		       __func__, sz);
		return -EINVAL;
	}
	return 0;
}

static int ion_secure_carveout_pm_restore(struct ion_heap *heap)
{
	struct ion_sc_heap *manager;
	struct ion_sc_entry *child;

	manager = container_of(heap, struct ion_sc_heap, heap);

	list_for_each_entry(child, &manager->children, list)
		ion_hyp_assign_from_flags(
			child->base, child->size, child->token);
	return 0;
}

static struct ion_heap_ops ion_sc_heap_ops = {
	.allocate = ion_sc_heap_allocate,
	.free = ion_sc_heap_free,
	.pm = {
		.freeze = ion_secure_carveout_pm_freeze,
		.restore = ion_secure_carveout_pm_restore,
	}
};

static int ion_sc_get_dt_token(struct ion_sc_entry *entry,
@@ -298,6 +330,8 @@ static int ion_sc_add_child(struct ion_sc_heap *manager,
	heap_data.priv = dev;
	heap_data.base = base;
	heap_data.size = size;
	entry->base = base;
	entry->size = size;

	/* This will zero memory initially */
	entry->heap = __ion_carveout_heap_create(&heap_data, false);