trusty: switch to use version 3 of TRUSTY_API

Version 3 of Trusty API adds support for new command
(SMC_NC_VDEV_KICK_VQ) that can be used to notify virtqueue
that new item is available. This command is a parameterized
NOP, it has to be queued using trusty_enqueue_nop API and as
such can be executed concurrently on multiple CPUs.

Change-Id: Ic979e628e780fe8b0c9de5058c897c0944006615
Signed-off-by: Michael Ryleev <gmar@google.com>
diff --git a/drivers/trusty/trusty-virtio.c b/drivers/trusty/trusty-virtio.c
index f1fa2be..920a02a 100644
--- a/drivers/trusty/trusty-virtio.c
+++ b/drivers/trusty/trusty-virtio.c
@@ -60,7 +60,8 @@
 	atomic_t		needs_kick;
 	struct fw_rsc_vdev_vring *vr_descr;
 	struct virtqueue	*vq;
-	struct trusty_vdev      *tvdev;
+	struct trusty_vdev	*tvdev;
+	struct trusty_nop	kick_nop;
 };
 
 struct trusty_vdev {
@@ -143,9 +144,14 @@
 	struct trusty_vring *tvr = vq->priv;
 	struct trusty_vdev *tvdev = tvr->tvdev;
 	struct trusty_ctx *tctx = tvdev->tctx;
+	u32 api_ver = trusty_get_api_version(tctx->dev->parent);
 
-	atomic_set(&tvr->needs_kick, 1);
-	queue_work(tctx->kick_wq, &tctx->kick_vqs);
+	if (api_ver < TRUSTY_API_VERSION_SMP_NOP) {
+		atomic_set(&tvr->needs_kick, 1);
+		queue_work(tctx->kick_wq, &tctx->kick_vqs);
+	} else {
+		trusty_enqueue_nop(tctx->dev->parent, &tvr->kick_nop);
+	}
 
 	return true;
 }
@@ -263,6 +269,9 @@
 	struct trusty_vring *tvr = &tvdev->vrings[0];
 
 	for (i = 0; i < tvdev->vring_num; i++, tvr++) {
+		/* dequeue kick_nop */
+		trusty_dequeue_nop(tvdev->tctx->dev->parent, &tvr->kick_nop);
+
 		/* delete vq */
 		if (tvr->vq) {
 			vring_del_virtqueue(tvr->vq);
@@ -416,6 +425,8 @@
 		tvr->align    = vr_descr->align;
 		tvr->elem_num = vr_descr->num;
 		tvr->notifyid = vr_descr->notifyid;
+		trusty_nop_init(&tvr->kick_nop, SMC_NC_VDEV_KICK_VQ,
+				tvdev->notifyid, tvr->notifyid);
 	}
 
 	/* register device */
diff --git a/include/linux/trusty/smcall.h b/include/linux/trusty/smcall.h
index 4e03a97e..80101df 100644
--- a/include/linux/trusty/smcall.h
+++ b/include/linux/trusty/smcall.h
@@ -131,5 +131,6 @@
 
 #define SMC_SC_VDEV_RESET	SMC_STDCALL_NR(SMC_ENTITY_TRUSTED_OS, 23)
 #define SMC_SC_VDEV_KICK_VQ	SMC_STDCALL_NR(SMC_ENTITY_TRUSTED_OS, 24)
+#define SMC_NC_VDEV_KICK_VQ	SMC_STDCALL_NR(SMC_ENTITY_TRUSTED_OS, 25)
 
 #endif /* __LINUX_TRUSTY_SMCALL_H */