[DEBUG] Add fake SMCCC TRNG support to QEMU & Trusty

This requires TRNG_SUPPORT=1 to build.
Change-Id: Ia99d1d9eee209fa1fcc9245176519e53ec492b90

Change-Id: Iefa5048f170c0354dbb4382f968db4d7ba9da96c
diff --git a/plat/qemu/common/qemu_fake_trng.c b/plat/qemu/common/qemu_fake_trng.c
new file mode 100644
index 0000000..cb6b342
--- /dev/null
+++ b/plat/qemu/common/qemu_fake_trng.c
@@ -0,0 +1,21 @@
+#include <stdbool.h>
+#include <stddef.h>
+#include <inttypes.h>
+#include <plat/common/plat_trng.h>
+
+struct uuid plat_trng_uuid;
+
+bool plat_get_entropy(uint64_t *out)
+{
+	static uint64_t value = 0x0123456789abcdef;
+	*out = value;
+	value = (value >> 8) | (value << 56);
+	return true;
+}
+
+void plat_entropy_setup(void)
+{
+	uint8_t *ptr = (void *)&plat_trng_uuid;
+	for (size_t i = 0; i < sizeof(plat_trng_uuid); i++)
+		*ptr = i;
+}
diff --git a/plat/qemu/qemu/platform.mk b/plat/qemu/qemu/platform.mk
index a3b353f..29d714e 100644
--- a/plat/qemu/qemu/platform.mk
+++ b/plat/qemu/qemu/platform.mk
@@ -159,6 +159,10 @@
 $(error "Incorrect GIC driver chosen for QEMU platform")
 endif
 
+ifeq (${TRNG_SUPPORT},1)
+BL31_SOURCES 		+=	${PLAT_QEMU_COMMON_PATH}/qemu_fake_trng.c
+endif
+
 ifeq (${ARM_ARCH_MAJOR},8)
 BL31_SOURCES		+=	lib/cpus/aarch64/aem_generic.S		\
 				lib/cpus/aarch64/cortex_a53.S		\
diff --git a/services/spd/trusty/shared-mem-smcall.c b/services/spd/trusty/shared-mem-smcall.c
index cc9f53e..a7d90e9 100644
--- a/services/spd/trusty/shared-mem-smcall.c
+++ b/services/spd/trusty/shared-mem-smcall.c
@@ -13,6 +13,10 @@
 #include <lib/xlat_tables/xlat_tables_v2.h>
 #include <platform_def.h>
 
+#if TRNG_SUPPORT
+#include <services/trng_svc.h>
+#endif
+
 #include "shared-mem-smcall.h"
 
 /*
@@ -972,6 +976,11 @@
 	struct trusty_shmem_client_state *client = &trusty_shmem_client_state[
 		is_caller_secure(flags)];
 
+#if TRNG_SUPPORT
+	if (is_trng_fid(smc_fid))
+		return trng_smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle, flags);
+#endif
+
 	if (((smc_fid < SMC_FC32_FFA_MIN) || (smc_fid > SMC_FC32_FFA_MAX)) &&
 	    ((smc_fid < SMC_FC64_FFA_MIN) || (smc_fid > SMC_FC64_FFA_MAX))) {
 		NOTICE("%s(0x%x) unknown smc\n", __func__, smc_fid);