]> git.baikalelectronics.ru Git - uboot.git/commitdiff
tpm: rng: Add driver model interface for TPM RNG device
authorSughosh Ganu <sughosh.ganu@linaro.org>
Fri, 22 Jul 2022 16:02:04 +0000 (21:32 +0530)
committerIlias Apalodimas <ilias.apalodimas@linaro.org>
Tue, 2 Aug 2022 20:50:02 +0000 (23:50 +0300)
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>
drivers/rng/Kconfig
drivers/rng/Makefile
drivers/rng/tpm_rng.c [new file with mode: 0644]
lib/Kconfig
lib/tpm_api.c

index 21a9ff01954279abffb491a5995232871a6a9c6b..16143681da6e2c883ffb3046b28185dc5cf2c0b0 100644 (file)
@@ -74,4 +74,13 @@ config RNG_SMCCC_TRNG
          Enable random number generator for platforms that support Arm
          SMCCC TRNG interface.
 
+config TPM_RNG
+       bool "Enable random number generator on TPM device"
+       depends on TPM
+       default y
+       help
+         The TPM device has an inbuilt random number generator
+         functionality. Enable random number generator on TPM
+         devices.
+
 endif
index 2494717d7c756b5e074a996a07a47e92a067e708..78f61051acfd4c5978af6952ea3ebc1134ded9a1 100644 (file)
@@ -13,3 +13,4 @@ obj-$(CONFIG_RNG_STM32MP1) += stm32mp1_rng.o
 obj-$(CONFIG_RNG_ROCKCHIP) += rockchip_rng.o
 obj-$(CONFIG_RNG_IPROC200) += iproc_rng200.o
 obj-$(CONFIG_RNG_SMCCC_TRNG) += smccc_trng.o
+obj-$(CONFIG_TPM_RNG) += tpm_rng.o
diff --git a/drivers/rng/tpm_rng.c b/drivers/rng/tpm_rng.c
new file mode 100644 (file)
index 0000000..1a5e9e2
--- /dev/null
@@ -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,
+};
index 7dd777b56a7921175d69223d50a05704f53fb3e5..e888c29245ed61bd6e2b3d897db6571ca1467611 100644 (file)
@@ -360,6 +360,7 @@ source lib/crypt/Kconfig
 config TPM
        bool "Trusted Platform Module (TPM) Support"
        depends on DM
+       imply DM_RNG
        help
          This enables support for TPMs which can be used to provide security
          features for your board. The TPM can be connected via LPC or I2C
index 4ac4612c81ea48073a1e67280f06a57e848c01b8..032f383ca047b1f3dfa7423096d08b74236d9d44 100644 (file)
@@ -269,7 +269,7 @@ u32 tpm_get_random(struct udevice *dev, void *data, u32 count)
        if (tpm_is_v1(dev))
                return tpm1_get_random(dev, data, count);
        else if (tpm_is_v2(dev))
-               return -ENOSYS; /* not implemented yet */
-       else
-               return -ENOSYS;
+               return tpm2_get_random(dev, data, count);
+
+       return -ENOSYS;
 }