aboutsummaryrefslogtreecommitdiff
path: root/drivers/rng/tpm_rng.c
diff options
context:
space:
mode:
authorSughosh Ganu <sughosh.ganu@linaro.org>2022-07-22 21:32:04 +0530
committerIlias Apalodimas <ilias.apalodimas@linaro.org>2022-08-02 23:50:02 +0300
commite67ffb5aa5ab03a89305f4575ad3142486f9a306 (patch)
tree624c26edcc914c27bcdd0a8a04e4490995572d84 /drivers/rng/tpm_rng.c
parent5d98329196daaf624c39304aec1397d6363b3e72 (diff)
tpm: rng: Add driver model interface for TPM RNG device
The TPM device has a builtin random number generator(RNG) functionality. Expose the RNG functions of the TPM device to the driver model so that they can be used by the EFI_RNG_PROTOCOL if the protocol is installed. Also change the function arguments and return type of the random number functions to comply with the driver model api. Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org> Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Diffstat (limited to 'drivers/rng/tpm_rng.c')
-rw-r--r--drivers/rng/tpm_rng.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/drivers/rng/tpm_rng.c b/drivers/rng/tpm_rng.c
new file mode 100644
index 0000000000..1a5e9e2e4b
--- /dev/null
+++ b/drivers/rng/tpm_rng.c
@@ -0,0 +1,23 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2022, Linaro Limited
+ */
+
+#include <dm.h>
+#include <rng.h>
+#include <tpm_api.h>
+
+static int rng_tpm_random_read(struct udevice *dev, void *data, size_t count)
+{
+ return tpm_get_random(dev_get_parent(dev), data, count);
+}
+
+static const struct dm_rng_ops tpm_rng_ops = {
+ .read = rng_tpm_random_read,
+};
+
+U_BOOT_DRIVER(tpm_rng) = {
+ .name = "tpm-rng",
+ .id = UCLASS_RNG,
+ .ops = &tpm_rng_ops,
+};