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

Commit 69f29ae5 authored by Sathish Ambley's avatar Sathish Ambley Committed by Gerrit - the friendly Code Review server
Browse files

msm: ADSPRPC: Register for SMMU fault handler



When a SMMU fault occurs for a particular session, the fault is
recorded and any further invocations from user space is returned
with an error and only kernel invocations are allowed with the
remote processor to allow for the session to be torn down.

Change-Id: Ia787055ec6e278e6fafc4965237c41bfc876dea5
Signed-off-by: default avatarSathish Ambley <sathishambley@codeaurora.org>
parent 58be1b1f
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@
#define TZ_PIL_CLEAR_PROTECT_MEM_SUBSYS_ID 0x0D
#define TZ_PIL_AUTH_QDSP6_PROC 1
#define ADSP_MMAP_HEAP_ADDR 4
#define FASTRPC_ENOSUCH 39

#define RPC_TIMEOUT	(5 * HZ)
#define BALIGN		128
@@ -146,6 +147,7 @@ struct fastrpc_smmu {
	struct dma_iommu_mapping *mapping;
	int cb;
	int enabled;
	int faults;
};

struct fastrpc_session_ctx {
@@ -1171,6 +1173,10 @@ static int fastrpc_internal_invoke(struct fastrpc_file *fl, uint32_t mode,
								&ctx));
		if (err)
			goto bail;
		if (fl->sctx->smmu.faults)
			err = FASTRPC_ENOSUCH;
		if (err)
			goto bail;
		if (ctx)
			goto wait;
	}
@@ -1607,6 +1613,7 @@ static int fastrpc_session_alloc(struct fastrpc_channel_ctx *chan, int *session)
	if (err)
		goto bail;
	set_bit(idx, &chan->bitmap);
	chan->session[idx].smmu.faults = 0;
	*session = idx;
 bail:
	return err;
@@ -1810,6 +1817,21 @@ static int fastrpc_restart_notifier_cb(struct notifier_block *nb,
	return NOTIFY_DONE;
}

static int fastrpc_smmu_fault_handler(struct iommu_domain *domain,
	struct device *dev, unsigned long iova, int flags, void *token)
{
	struct fastrpc_session_ctx *sess = (struct fastrpc_session_ctx *)token;
	int err = 0;

	VERIFY(err, sess != NULL);
	if (err)
		return err;
	sess->smmu.faults++;
	dev_err(dev, "ADSPRPC context fault: iova=0x%08lx, cb = %d, faults=%d",
					iova, sess->smmu.cb, sess->smmu.faults);
	return 0;
}

static const struct file_operations fops = {
	.open = fastrpc_device_open,
	.release = fastrpc_device_release,
@@ -1864,6 +1886,8 @@ static int fastrpc_cb_probe(struct device *dev)
	iommu_domain_set_attr(sess->smmu.mapping->domain,
				DOMAIN_ATTR_COHERENT_HTW_DISABLE,
				&disable_htw);
	iommu_set_fault_handler(sess->smmu.mapping->domain,
				fastrpc_smmu_fault_handler, sess);
	VERIFY(err, !arm_iommu_attach_device(dev, sess->smmu.mapping));
	if (err)
		goto bail;