Add tests for TRNG SMCs

This adds some tests that are valid for all TRNG implemenations.
Specifically, it tests that the Version, Features, and RND calls conform
to the spec. Note that UUID is omitted from testing as there is not a
value that it can return that's outside of the spec.

Change-Id: I68aa2673538f64d2a9401415b8d0de1fdedc3ad4
Signed-off-by: Jimmy Brisson <jimmy.brisson@arm.com>
Signed-off-by: Zelalem Aweke <zelalem.aweke@arm.com>
diff --git a/lib/trng/trng.c b/lib/trng/trng.c
new file mode 100644
index 0000000..976d26e
--- /dev/null
+++ b/lib/trng/trng.c
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2021, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <arch_helpers.h>
+#include <debug.h>
+#include <drivers/arm/arm_gic.h>
+#include <irq.h>
+#include <platform.h>
+#include <trng.h>
+#include <sgi.h>
+#include <tftf.h>
+#include <tftf_lib.h>
+
+const trng_function_t trng_functions[TRNG_NUM_CALLS] = {
+	DEFINE_TRNG_FUNC(TRNG_VERSION, true),
+	DEFINE_TRNG_FUNC(TRNG_FEATURES, true),
+	DEFINE_TRNG_FUNC(TRNG_UUID, true),
+	DEFINE_TRNG_FUNC(TRNG_RND, true),
+};
+
+int32_t tftf_trng_version(void)
+{
+	smc_args args = { SMC_TRNG_VERSION };
+	smc_ret_values ret_vals;
+
+	ret_vals = tftf_smc(&args);
+	return ret_vals.ret0;
+}
+
+
+bool tftf_trng_feature_implemented(uint32_t id)
+{
+	smc_args args = {
+		SMC_TRNG_FEATURES,
+		id,
+	};
+	smc_ret_values ret_vals;
+
+	ret_vals = tftf_smc(&args);
+	return ret_vals.ret0 == TRNG_E_SUCCESS;
+}
+
+smc_ret_values tftf_trng_uuid(void)
+{
+	smc_args args = { SMC_TRNG_UUID };
+
+	return tftf_smc(&args);
+}
+
+smc_ret_values tftf_trng_rnd(uint32_t nbits)
+{
+	smc_args args = {
+		SMC_TRNG_RND,
+		nbits,
+	};
+
+	return tftf_smc(&args);
+}