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

Commit 842474f1 authored by Patrick Daly's avatar Patrick Daly
Browse files

ion: Add hibernation support for system secure heap



Free all secure buffers from pools, since hyp_assign is not
maintained across hibernation.

Change-Id: I5b92cab09ce89aa27b92a013a8a8400a34bbda28
Signed-off-by: default avatarPatrick Daly <pdaly@codeaurora.org>
parent 65e5166a
Loading
Loading
Loading
Loading
+38 −0
Original line number Original line Diff line number Diff line
@@ -343,6 +343,41 @@ static int ion_system_secure_heap_shrink(struct ion_heap *heap, gfp_t gfp_mask,
						gfp_mask, nr_to_scan);
						gfp_mask, nr_to_scan);
}
}


static int ion_system_secure_heap_pm_freeze(struct ion_heap *heap)
{
	struct ion_system_secure_heap *secure_heap;
	unsigned long count;
	long sz;
	struct shrink_control sc = {
		.gfp_mask = GFP_HIGHUSER,
	};

	secure_heap = container_of(heap, struct ion_system_secure_heap, heap);

	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;
	}

	/* Since userspace is frozen, no more requests will be queued */
	cancel_delayed_work_sync(&secure_heap->prefetch_work);

	count = heap->shrinker.count_objects(&heap->shrinker, &sc);
	sc.nr_to_scan = count;
	heap->shrinker.scan_objects(&heap->shrinker, &sc);

	count = heap->shrinker.count_objects(&heap->shrinker, &sc);
	if (count) {
		pr_err("%s: Failed to free all objects - %ld remaining",
		       __func__, count);
		return -EINVAL;
	}

	return 0;
}

static struct ion_heap_ops system_secure_heap_ops = {
static struct ion_heap_ops system_secure_heap_ops = {
	.allocate = ion_system_secure_heap_allocate,
	.allocate = ion_system_secure_heap_allocate,
	.free = ion_system_secure_heap_free,
	.free = ion_system_secure_heap_free,
@@ -350,6 +385,9 @@ static struct ion_heap_ops system_secure_heap_ops = {
	.unmap_kernel = ion_system_secure_heap_unmap_kernel,
	.unmap_kernel = ion_system_secure_heap_unmap_kernel,
	.map_user = ion_system_secure_heap_map_user,
	.map_user = ion_system_secure_heap_map_user,
	.shrink = ion_system_secure_heap_shrink,
	.shrink = ion_system_secure_heap_shrink,
	.pm = {
		.freeze = ion_system_secure_heap_pm_freeze,
	}
};
};


struct ion_heap *ion_system_secure_heap_create(struct ion_platform_heap *unused)
struct ion_heap *ion_system_secure_heap_create(struct ion_platform_heap *unused)