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

Commit e976fc3a authored by Anuj Garg's avatar Anuj Garg
Browse files

adsprpc: Make hibernation flag channel specific



Make in_hib flag unique to each device. Earlier code uses global flag and
causes memory leaks.With hibernation restore, TZ loses its state. Avoid
hyp assign of secure buffers back to HLOS as ownership by default is
with HLOS.

Change-Id: I20dbd1bec8f1f363a9e64f7c41887446b92154f4
Signed-off-by: default avatarAnuj Garg <anujgarg@codeaurora.org>
parent 5bda9ecf
Loading
Loading
Loading
Loading
+12 −8
Original line number Diff line number Diff line
@@ -281,6 +281,7 @@ struct fastrpc_channel_ctx {
	struct mutex rpmsg_mutex;
	uint64_t sesscount;
	uint64_t ssrcount;
	int in_hib;
	void *handle;
	uint64_t prevssrcount;
	int issubsystemup;
@@ -309,7 +310,6 @@ struct fastrpc_apps {
	spinlock_t ctxlock;
	struct smq_invoke_ctx *ctxtable[FASTRPC_CTX_MAX];
	bool legacy_remote_heap;
	int in_hib;
};

struct fastrpc_mmap {
@@ -527,7 +527,7 @@ static void fastrpc_buf_free(struct fastrpc_buf *buf, int cache)
		if (fl->sctx->smmu.cb && fl->cid != SDSP_DOMAIN_ID)
			buf->phys &= ~((uint64_t)fl->sctx->smmu.cb << 32);
		vmid = fl->apps->channel[fl->cid].vmid;
		if ((vmid) && (me->in_hib == 0)) {
		if ((vmid) && (me->channel[fl->cid].in_hib == 0)) {
			int srcVM[2] = {VMID_HLOS, vmid};

			hyp_assign_phys(buf->phys, buf_page_size(buf->size),
@@ -755,7 +755,7 @@ static void fastrpc_mmap_free(struct fastrpc_mmap *map, uint32_t flags)
			sess = fl->sctx;

		vmid = fl->apps->channel[fl->cid].vmid;
		if (vmid && map->phys && me->in_hib == 0) {
		if (vmid && map->phys && (me->channel[fl->cid].in_hib == 0)) {
			int srcVM[2] = {VMID_HLOS, vmid};

			hyp_assign_phys(map->phys, buf_page_size(map->size),
@@ -2261,7 +2261,7 @@ static int fastrpc_init_process(struct fastrpc_file *fl,
	if (mem && err) {
		if (mem->flags == ADSP_MMAP_REMOTE_HEAP_ADDR
			&& me->channel[fl->cid].rhvm.vmid
			&& me->in_hib == 0)
			&& me->channel[fl->cid].in_hib == 0)
			hyp_assign_phys(mem->phys, (uint64_t)mem->size,
					me->channel[fl->cid].rhvm.vmid,
					me->channel[fl->cid].rhvm.vmcount,
@@ -2430,7 +2430,8 @@ static int fastrpc_munmap_on_dsp_rh(struct fastrpc_file *fl, uint64_t phys,
		err = scm_call2(SCM_SIP_FNID(SCM_SVC_PIL,
			TZ_PIL_CLEAR_PROTECT_MEM_SUBSYS_ID), &desc);
	} else if (flags == ADSP_MMAP_REMOTE_HEAP_ADDR) {
		if ((me->channel[fl->cid].rhvm.vmid) && (me->in_hib == 0)) {
		if ((me->channel[fl->cid].rhvm.vmid)
				&& (me->channel[fl->cid].in_hib == 0)) {
			VERIFY(err, !hyp_assign_phys(phys,
					(uint64_t)size,
					me->channel[fl->cid].rhvm.vmid,
@@ -3282,7 +3283,7 @@ static int fastrpc_channel_open(struct fastrpc_file *fl)
		me->channel[cid].prevssrcount =
					me->channel[cid].ssrcount;
	}
	me->in_hib = 0;
	me->channel[cid].in_hib = 0;
	mutex_unlock(&me->channel[cid].smd_mutex);

bail:
@@ -4184,9 +4185,12 @@ static int fastrpc_restore(struct device *dev)
	struct platform_device *ion_pdev;
	struct cma *cma;
	uint32_t val;
	int cid;

	pr_info("adsprpc: restore enter\n");
	me->in_hib = 1;
	for (cid = 0; cid < NUM_CHANNELS; cid++)
		me->channel[cid].in_hib = 1;

	if (of_device_is_compatible(dev->of_node,
					"qcom,msm-adsprpc-mem-region")) {
		me->dev = dev;
@@ -4284,7 +4288,6 @@ static int __init fastrpc_device_init(void)
	fastrpc_init(me);
	me->dev = NULL;
	me->legacy_remote_heap = 0;
	me->in_hib = 0;
	VERIFY(err, 0 == platform_driver_register(&fastrpc_driver));
	if (err)
		goto register_bail;
@@ -4328,6 +4331,7 @@ static int __init fastrpc_device_init(void)
		if (i == CDSP_DOMAIN_ID)
			me->channel[i].dev = dev;
		me->channel[i].ssrcount = 0;
		me->channel[i].in_hib = 0;
		me->channel[i].prevssrcount = 0;
		me->channel[i].issubsystemup = 1;
		me->channel[i].ramdumpenabled = 0;