Add platform specific TRNG driver
Adds platform specific TRNG driver to Crypto opteesp deployment.
Fetches and builds the TZ-TRNG driver from its external
repo and includes it when the crypto/opteesp is built for
the arm/fvp/fvp_base_revc-2xaemv8a platform. Device region
information provided as external configuration data is
not yet integrated to the TRNG hardware is not yet used.
Signed-off-by: Julian Hall <julian.hall@arm.com>
Change-Id: I8a2946643a279dfcc3aff608427c85e674f0e084
diff --git a/platform/interface/device_region.h b/platform/interface/device_region.h
new file mode 100644
index 0000000..1ad1721
--- /dev/null
+++ b/platform/interface/device_region.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef TS_PLATFORM_INTERFACE_DEVICE_REGION_H
+#define TS_PLATFORM_INTERFACE_DEVICE_REGION_H
+
+#include <stddef.h>
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Defines a structure for describing a contiguous IO memory region
+ * and other configuration information about a peripheral. This may be based on
+ * buildtime or runtime configuration information e.g. from device tree.
+ */
+struct device_region
+{
+ char dev_class[16]; /**< Identifier for class of device e.g. 'trng' */
+ int dev_instance; /**< Instance of the class of device on a platform */
+ uint8_t *base_addr; /**< Base address or region */
+ size_t io_region_size; /**< Size of I/O region in bytes */
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* TS_PLATFORM_INTERFACE_DEVICE_REGION_H */
diff --git a/platform/interface/entropy.h b/platform/interface/entropy.h
deleted file mode 100644
index d81cd60..0000000
--- a/platform/interface/entropy.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#ifndef TS_PLATFORM_INTERFACE_ENTROPY_H
-#define TS_PLATFORM_INTERFACE_ENTROPY_H
-
-/*
- * Interface definintion for a platform entropy driver. A platform provider will
- * provide concrete implementations of this interface for each alternative
- * implementation supported.
- */
-#include <stddef.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
- * Virtual interface for a platform entropy driver. A platform will provide
- * one or more concrete implementations of this interface.
- */
-struct ts_plat_entropy_iface
-{
- /**
- * \brief Poll for bytes of entropy from a platform entropy source
- *
- * \param context Platform driver context
- * \param output Buffer for output
- * \param nbyte Desired number of bytes
- * \param len The number of bytes returned (could be zero)
- *
- * \return 0 if successful.
- */
- int (*poll)(void *context, unsigned char *output, size_t nbyte, size_t *len);
-};
-
-/*
- * A platform entropy driver instance.
- */
-struct ts_plat_entropy_driver
-{
- void *context; /**< Opaque driver context */
- const struct ts_plat_entropy_iface *iface; /**< Interface methods */
-};
-
-/**
- * \brief Factory method to construct a platform specific entropy driver
- *
- * \param driver Pointer to driver structure to initialize on construction.
- * \param config Driver specific configuration or NULL if none.
- *
- * \return 0 if successful.
- */
-int ts_plat_entropy_create(struct ts_plat_entropy_driver *driver, void *config);
-
-/**
- * \brief Destroy a driver constructed using the factory method
- *
- * \param driver Pointer to driver structure for constructed driver.
- */
-void ts_plat_entropy_destroy(struct ts_plat_entropy_driver *driver);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* TS_PLATFORM_INTERFACE_ENTROPY_H */
diff --git a/platform/interface/trng.h b/platform/interface/trng.h
new file mode 100644
index 0000000..9c24581
--- /dev/null
+++ b/platform/interface/trng.h
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef TS_PLATFORM_INTERFACE_TRNG_H
+#define TS_PLATFORM_INTERFACE_TRNG_H
+
+/*
+ * Interface definintion for a platform trng driver. A platform provider will
+ * provide concrete implementations of this interface for each alternative
+ * implementation supported.
+ */
+#include <stddef.h>
+#include "device_region.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Virtual interface for a platform trng driver. A platform will provide
+ * one or more concrete implementations of this interface.
+ */
+struct platform_trng_iface
+{
+ /**
+ * \brief Poll for bytes of entropy from a platform trng
+ *
+ * \param context Platform driver context
+ * \param output Buffer for output
+ * \param nbyte Desired number of bytes
+ * \param len The number of bytes returned (could be zero)
+ *
+ * \return 0 if successful.
+ */
+ int (*poll)(void *context, unsigned char *output, size_t nbyte, size_t *len);
+};
+
+/*
+ * A platform trng driver instance.
+ */
+struct platform_trng_driver
+{
+ void *context; /**< Opaque driver context */
+ const struct platform_trng_iface *iface; /**< Interface methods */
+};
+
+/**
+ * \brief Factory method to construct a platform specific trng driver
+ *
+ * \param driver Pointer to driver structure to initialize on construction.
+ * \param device_region Pointer a device region object or NULL if none.
+ *
+ * \return 0 if successful.
+ */
+int platform_trng_create(struct platform_trng_driver *driver,
+ const struct device_region *device_region);
+
+/**
+ * \brief Destroy a driver constructed using the factory method
+ *
+ * \param driver Pointer to driver structure for constructed driver.
+ */
+void platform_trng_destroy(struct platform_trng_driver *driver);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* TS_PLATFORM_INTERFACE_TRNG_H */