From e67ffb5aa5ab03a89305f4575ad3142486f9a306 Mon Sep 17 00:00:00 2001 From: Sughosh Ganu Date: Fri, 22 Jul 2022 21:32:04 +0530 Subject: 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 Reviewed-by: Ilias Apalodimas Signed-off-by: Ilias Apalodimas --- drivers/rng/tpm_rng.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 drivers/rng/tpm_rng.c (limited to 'drivers/rng/tpm_rng.c') 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 +#include +#include + +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, +}; -- cgit v1.2.3